@lark-apaas/miaoda-inspector 0.1.0-alpha.1 → 0.1.0-alpha.2
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.js → Inspector.mjs} +50 -55
- package/dist/es/Inspector/{Overlay.js → Overlay.mjs} +157 -125
- package/dist/es/Inspector/hooks/use-effect-event.mjs +17 -0
- package/dist/es/Inspector/hooks/use-layout-effect.mjs +9 -0
- package/dist/es/Inspector/hooks/{use-mouse.js → use-mouse.mjs} +8 -4
- package/dist/es/Inspector/index.mjs +5 -0
- package/dist/es/Inspector/utils/fiber.mjs +70 -0
- package/dist/es/Inspector/utils/highlight.mjs +78 -0
- package/dist/es/Inspector/utils/inspect.mjs +131 -0
- package/dist/es/Inspector/utils/{overlay.js → overlay.mjs} +7 -2
- package/dist/es/MiaodaInspector/MiaodaInspector.mjs +427 -0
- package/dist/es/MiaodaInspector/index.mjs +5 -0
- package/dist/es/chunk-I4E63NIC.mjs +24 -0
- package/dist/es/config/{ui-config.js → ui-config.mjs} +66 -286
- package/dist/es/global.d.mjs +0 -0
- package/dist/es/index.mjs +7 -0
- package/dist/es/types/iframe-events.mjs +0 -0
- package/dist/es/types/index.mjs +27 -0
- package/dist/es/utils/{config-mapper.js → config-mapper.mjs} +14 -56
- package/dist/es/utils/{css.js → css.mjs} +5 -1
- package/dist/es/utils/index.mjs +37 -0
- package/dist/es/utils/origin.mjs +26 -0
- package/dist/es/utils/style-calculator.mjs +177 -0
- package/dist/lib/Inspector/Inspector.js +99 -104
- package/dist/lib/Inspector/Overlay.js +172 -143
- package/dist/lib/Inspector/hooks/index.js +19 -19
- package/dist/lib/Inspector/hooks/use-effect-event.js +26 -15
- package/dist/lib/Inspector/hooks/use-layout-effect.js +25 -10
- package/dist/lib/Inspector/hooks/use-mouse.js +27 -14
- package/dist/lib/Inspector/index.js +21 -8
- package/dist/lib/Inspector/utils/fiber.js +49 -55
- package/dist/lib/Inspector/utils/highlight.js +44 -31
- package/dist/lib/Inspector/utils/index.js +19 -19
- package/dist/lib/Inspector/utils/inspect.js +62 -72
- package/dist/lib/Inspector/utils/overlay.js +20 -15
- package/dist/lib/MiaodaInspector/MiaodaInspector.js +265 -266
- package/dist/lib/MiaodaInspector/index.js +21 -8
- package/dist/lib/config/ui-config.js +81 -292
- package/dist/lib/global.d.js +1 -0
- package/dist/lib/index.js +22 -17
- package/dist/lib/types/iframe-events.js +15 -3
- package/dist/lib/types/index.js +30 -43
- package/dist/lib/utils/config-mapper.js +41 -69
- package/dist/lib/utils/css.js +33 -15
- package/dist/lib/utils/index.js +36 -57
- package/dist/lib/utils/origin.js +23 -22
- package/dist/lib/utils/style-calculator.js +113 -110
- package/dist/types/Inspector/Inspector.d.ts +95 -92
- package/dist/types/Inspector/Overlay.d.ts +61 -58
- package/dist/types/Inspector/hooks/index.d.ts +4 -3
- package/dist/types/Inspector/hooks/use-effect-event.d.ts +3 -1
- package/dist/types/Inspector/hooks/use-layout-effect.d.ts +5 -2
- package/dist/types/Inspector/hooks/use-mouse.d.ts +9 -8
- package/dist/types/Inspector/index.d.ts +4 -1
- package/dist/types/Inspector/utils/fiber.d.ts +12 -10
- package/dist/types/Inspector/utils/highlight.d.ts +7 -5
- package/dist/types/Inspector/utils/index.d.ts +4 -3
- package/dist/types/Inspector/utils/inspect.d.ts +45 -42
- package/dist/types/Inspector/utils/overlay.d.ts +24 -22
- package/dist/types/MiaodaInspector/MiaodaInspector.d.ts +42 -41
- package/dist/types/MiaodaInspector/index.d.ts +3 -1
- package/dist/types/config/ui-config.d.ts +42 -41
- package/dist/types/global.d.d.ts +17 -0
- package/dist/types/index.d.ts +5 -4
- package/dist/types/types/iframe-events.d.ts +133 -130
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/utils/config-mapper.d.ts +14 -11
- package/dist/types/utils/css.d.ts +5 -2
- package/dist/types/utils/index.d.ts +7 -3
- package/dist/types/utils/origin.d.ts +12 -8
- package/dist/types/utils/style-calculator.d.ts +20 -17
- package/package.json +13 -13
- package/dist/es/Inspector/hooks/use-effect-event.js +0 -15
- package/dist/es/Inspector/hooks/use-layout-effect.js +0 -3
- package/dist/es/Inspector/index.js +0 -1
- package/dist/es/Inspector/utils/fiber.js +0 -61
- package/dist/es/Inspector/utils/highlight.js +0 -74
- package/dist/es/Inspector/utils/inspect.js +0 -119
- package/dist/es/MiaodaInspector/MiaodaInspector.js +0 -397
- package/dist/es/MiaodaInspector/index.js +0 -1
- package/dist/es/index.js +0 -2
- package/dist/es/types/iframe-events.js +0 -1
- package/dist/es/types/index.js +0 -1
- package/dist/es/utils/index.js +0 -3
- package/dist/es/utils/origin.js +0 -19
- package/dist/es/utils/style-calculator.js +0 -158
- /package/dist/es/Inspector/hooks/{index.js → index.mjs} +0 -0
- /package/dist/es/Inspector/utils/{index.js → index.mjs} +0 -0
|
@@ -1,118 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (key in obj) {
|
|
20
|
-
Object.defineProperty(obj, key, {
|
|
21
|
-
value,
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
obj[key] = value;
|
|
28
|
-
}
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
32
|
-
if (typeof WeakMap !== "function")
|
|
33
|
-
return null;
|
|
34
|
-
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
35
|
-
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
36
|
-
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
37
|
-
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
38
|
-
})(nodeInterop);
|
|
39
|
-
}
|
|
40
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
41
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
42
|
-
return obj;
|
|
43
|
-
}
|
|
44
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
45
|
-
return {
|
|
46
|
-
default: obj
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
50
|
-
if (cache && cache.has(obj)) {
|
|
51
|
-
return cache.get(obj);
|
|
52
|
-
}
|
|
53
|
-
var newObj = {};
|
|
54
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
55
|
-
for (var key in obj) {
|
|
56
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
-
if (desc && (desc.get || desc.set)) {
|
|
59
|
-
Object.defineProperty(newObj, key, desc);
|
|
60
|
-
} else {
|
|
61
|
-
newObj[key] = obj[key];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
newObj.default = obj;
|
|
66
|
-
if (cache) {
|
|
67
|
-
cache.set(obj, newObj);
|
|
68
|
-
}
|
|
69
|
-
return newObj;
|
|
70
|
-
}
|
|
71
|
-
function _object_spread(target) {
|
|
72
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
73
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
74
|
-
var ownKeys2 = Object.keys(source);
|
|
75
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
76
|
-
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
77
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
78
|
-
}));
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
79
19
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
keys.push.apply(keys, symbols);
|
|
96
|
-
}
|
|
97
|
-
return keys;
|
|
98
|
-
}
|
|
99
|
-
function _object_spread_props(target, source) {
|
|
100
|
-
source = source != null ? source : {};
|
|
101
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
102
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
103
|
-
} else {
|
|
104
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
105
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
106
|
-
});
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
107
32
|
}
|
|
108
|
-
return
|
|
109
|
-
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var MiaodaInspector_exports = {};
|
|
37
|
+
__export(MiaodaInspector_exports, {
|
|
38
|
+
MiaodaInspector: () => MiaodaInspector
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(MiaodaInspector_exports);
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
var import_react = require("react");
|
|
43
|
+
var import_Inspector = require("../Inspector");
|
|
44
|
+
var import_Overlay = require("../Inspector/Overlay");
|
|
45
|
+
var import_utils = require("../utils");
|
|
46
|
+
var import_MiaodaInspector = require("./MiaodaInspector.css");
|
|
47
|
+
var import_config_mapper = require("../utils/config-mapper");
|
|
110
48
|
function safeClassName(el) {
|
|
111
|
-
const cn = el
|
|
49
|
+
const cn = el == null ? void 0 : el.className;
|
|
112
50
|
if (typeof cn === "string") {
|
|
113
51
|
return cn;
|
|
114
52
|
}
|
|
115
|
-
if (typeof (cn
|
|
53
|
+
if (typeof (cn == null ? void 0 : cn.baseVal) === "string") {
|
|
116
54
|
return cn.baseVal;
|
|
117
55
|
}
|
|
118
56
|
return "";
|
|
@@ -126,7 +64,9 @@ function analyzeTextOnlyNode(element, componentName, canUseNewInspector) {
|
|
|
126
64
|
}
|
|
127
65
|
try {
|
|
128
66
|
const childNodes = Array.from(element.childNodes);
|
|
129
|
-
const textNodes = childNodes.filter(
|
|
67
|
+
const textNodes = childNodes.filter(
|
|
68
|
+
(node) => node.nodeType === Node.TEXT_NODE
|
|
69
|
+
);
|
|
130
70
|
const hasOnlyText = childNodes.length > 0 && textNodes.length === childNodes.length;
|
|
131
71
|
return {
|
|
132
72
|
hasOnlyTextNodes: hasOnlyText,
|
|
@@ -141,7 +81,7 @@ function analyzeTextOnlyNode(element, componentName, canUseNewInspector) {
|
|
|
141
81
|
};
|
|
142
82
|
}
|
|
143
83
|
const getElementCoordinates = (element) => {
|
|
144
|
-
const boundingClientRect = element
|
|
84
|
+
const boundingClientRect = element == null ? void 0 : element.getBoundingClientRect();
|
|
145
85
|
const computedStyle = element ? window.getComputedStyle(element) : null;
|
|
146
86
|
const marginLeft = computedStyle ? parseFloat(computedStyle.marginLeft) || 0 : 0;
|
|
147
87
|
const marginRight = computedStyle ? parseFloat(computedStyle.marginRight) || 0 : 0;
|
|
@@ -167,139 +107,140 @@ function elementInfoToKey(relativePath, lineNumber, columnNumber) {
|
|
|
167
107
|
return `${relativePath}_${lineNumber}_${columnNumber}`;
|
|
168
108
|
}
|
|
169
109
|
const enableInner = (() => {
|
|
170
|
-
|
|
171
|
-
return ((_localStorage = localStorage) === null || _localStorage === void 0 ? void 0 : _localStorage.getItem("miaoda-inspector-inner")) === "true";
|
|
110
|
+
return (localStorage == null ? void 0 : localStorage.getItem("miaoda-inspector-inner")) === "true";
|
|
172
111
|
})();
|
|
173
112
|
function MiaodaInspector(props) {
|
|
174
|
-
const [_active, setActive] = (0,
|
|
175
|
-
const [inBody, setInBody] = (0,
|
|
113
|
+
const [_active, setActive] = (0, import_react.useState)(false);
|
|
114
|
+
const [inBody, setInBody] = (0, import_react.useState)(true);
|
|
176
115
|
const active = (_active || enableInner) && inBody;
|
|
177
|
-
const canUseNewInspector = (0,
|
|
178
|
-
const clickOverlayRef = (0,
|
|
116
|
+
const canUseNewInspector = (0, import_react.useRef)(false);
|
|
117
|
+
const clickOverlayRef = (0, import_react.useRef)(null);
|
|
179
118
|
const defaultUIConfig = props.theme.themeToken;
|
|
180
|
-
const styleConfigs = (0,
|
|
181
|
-
const mouseleave = (0,
|
|
119
|
+
const styleConfigs = (0, import_config_mapper.getAllStyleConfigs)(defaultUIConfig);
|
|
120
|
+
const mouseleave = (0, import_react.useCallback)(() => {
|
|
182
121
|
setInBody(false);
|
|
183
122
|
}, []);
|
|
184
|
-
const mouseenter = (0,
|
|
123
|
+
const mouseenter = (0, import_react.useCallback)(() => {
|
|
185
124
|
setInBody(true);
|
|
186
125
|
}, []);
|
|
187
|
-
const handleMessage = (0,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const {
|
|
191
|
-
if (
|
|
192
|
-
|
|
193
|
-
if (inspectorActive
|
|
194
|
-
|
|
195
|
-
(
|
|
196
|
-
|
|
126
|
+
const handleMessage = (0, import_react.useCallback)(
|
|
127
|
+
(event) => {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
const { data } = event;
|
|
130
|
+
if ((0, import_utils.isIncomingMessage)(data, "InitConfig")) {
|
|
131
|
+
const { inspectorActive, userToken, appId, inspectorVersion } = data.data;
|
|
132
|
+
if (inspectorActive !== void 0) {
|
|
133
|
+
setActive(inspectorActive);
|
|
134
|
+
if (inspectorActive === false) {
|
|
135
|
+
(_a = clickOverlayRef.current) == null ? void 0 : _a.remove();
|
|
136
|
+
clickOverlayRef.current = null;
|
|
137
|
+
}
|
|
197
138
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
selectedElement.
|
|
139
|
+
if (userToken !== void 0) {
|
|
140
|
+
window.MIAODA_BUILTIN_TTT = userToken;
|
|
141
|
+
}
|
|
142
|
+
if (appId !== void 0) {
|
|
143
|
+
window.MIAODA_APP_ID = appId;
|
|
144
|
+
}
|
|
145
|
+
(0, import_utils.postMessage)({
|
|
146
|
+
type: "InspectorUIConfig",
|
|
147
|
+
data: defaultUIConfig
|
|
148
|
+
});
|
|
149
|
+
if (inspectorVersion === "2") {
|
|
150
|
+
canUseNewInspector.current = true;
|
|
151
|
+
}
|
|
152
|
+
} else if ((0, import_utils.isIncomingMessage)(data, "ClearSelected")) {
|
|
153
|
+
const { keepModifications = false } = data.data;
|
|
154
|
+
(_b = clickOverlayRef.current) == null ? void 0 : _b.remove();
|
|
155
|
+
clickOverlayRef.current = null;
|
|
156
|
+
if (canUseNewInspector.current && !keepModifications) {
|
|
157
|
+
for (const [_, selectedElement] of selectedElementMap.entries()) {
|
|
158
|
+
if (selectedElement.element) {
|
|
159
|
+
if (selectedElement.originalState.textContent) {
|
|
160
|
+
selectedElement.element.textContent = selectedElement.originalState.textContent;
|
|
161
|
+
}
|
|
162
|
+
if (selectedElement.originalState.className && !(selectedElement.element instanceof SVGElement)) {
|
|
163
|
+
selectedElement.element.className = selectedElement.originalState.className;
|
|
164
|
+
}
|
|
222
165
|
}
|
|
223
|
-
if (selectedElement.
|
|
224
|
-
selectedElement.
|
|
166
|
+
if (selectedElement.dispose) {
|
|
167
|
+
selectedElement.dispose();
|
|
225
168
|
}
|
|
226
169
|
}
|
|
227
|
-
|
|
228
|
-
selectedElement.dispose();
|
|
229
|
-
}
|
|
170
|
+
selectedElementMap.clear();
|
|
230
171
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (selectedElement && selectedElement.element) {
|
|
237
|
-
selectedElement.element.textContent = textContent;
|
|
238
|
-
}
|
|
239
|
-
} else if ((0, _utils.isIncomingMessage)(data, "EditStyle")) {
|
|
240
|
-
const { elementId, styles } = data.data;
|
|
241
|
-
const selectedElement = selectedElementMap.get(elementId);
|
|
242
|
-
if (selectedElement && selectedElement.element) {
|
|
243
|
-
const { element } = selectedElement;
|
|
244
|
-
for (const [property] of Object.entries(styles)) {
|
|
245
|
-
if (!(property in selectedElement.originalState.styles)) {
|
|
246
|
-
selectedElement.originalState.styles[property] = element.style.getPropertyValue(property);
|
|
247
|
-
}
|
|
172
|
+
} else if ((0, import_utils.isIncomingMessage)(data, "EditText")) {
|
|
173
|
+
const { elementId, textContent } = data.data;
|
|
174
|
+
const selectedElement = selectedElementMap.get(elementId);
|
|
175
|
+
if (selectedElement && selectedElement.element) {
|
|
176
|
+
selectedElement.element.textContent = textContent;
|
|
248
177
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
for (const [property
|
|
255
|
-
if (
|
|
256
|
-
element.style.
|
|
257
|
-
} else {
|
|
258
|
-
element.style.removeProperty(property);
|
|
178
|
+
} else if ((0, import_utils.isIncomingMessage)(data, "EditStyle")) {
|
|
179
|
+
const { elementId, styles } = data.data;
|
|
180
|
+
const selectedElement = selectedElementMap.get(elementId);
|
|
181
|
+
if (selectedElement && selectedElement.element) {
|
|
182
|
+
const { element } = selectedElement;
|
|
183
|
+
for (const [property] of Object.entries(styles)) {
|
|
184
|
+
if (!(property in selectedElement.originalState.styles)) {
|
|
185
|
+
selectedElement.originalState.styles[property] = element.style.getPropertyValue(property);
|
|
259
186
|
}
|
|
260
187
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
styleDispose();
|
|
264
|
-
if (existingDispose) {
|
|
265
|
-
existingDispose();
|
|
188
|
+
for (const [property, value] of Object.entries(styles)) {
|
|
189
|
+
element.style.setProperty(property, value);
|
|
266
190
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
191
|
+
const existingDispose = selectedElement.dispose;
|
|
192
|
+
const styleDispose = () => {
|
|
193
|
+
for (const [property, value] of Object.entries(
|
|
194
|
+
selectedElement.originalState.styles
|
|
195
|
+
)) {
|
|
196
|
+
if (value) {
|
|
197
|
+
element.style.setProperty(property, value);
|
|
198
|
+
} else {
|
|
199
|
+
element.style.removeProperty(property);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
selectedElement.dispose = () => {
|
|
204
|
+
styleDispose();
|
|
205
|
+
if (existingDispose) {
|
|
206
|
+
existingDispose();
|
|
207
|
+
}
|
|
208
|
+
};
|
|
276
209
|
}
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
210
|
+
} else if ((0, import_utils.isIncomingMessage)(data, "EditClassName")) {
|
|
211
|
+
const { elementId, className } = data.data;
|
|
212
|
+
const selectedElement = selectedElementMap.get(elementId);
|
|
213
|
+
if (selectedElement && selectedElement.element) {
|
|
214
|
+
const { element } = selectedElement;
|
|
215
|
+
if (selectedElement.originalState.className === void 0) {
|
|
216
|
+
selectedElement.originalState.className = safeClassName(element);
|
|
282
217
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
classDispose()
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
218
|
+
element.className = (0, import_utils.cx)(element.className, className);
|
|
219
|
+
const existingDispose = selectedElement.dispose;
|
|
220
|
+
const classDispose = () => {
|
|
221
|
+
if (selectedElement.originalState.className) {
|
|
222
|
+
element.className = selectedElement.originalState.className;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
selectedElement.dispose = () => {
|
|
226
|
+
classDispose();
|
|
227
|
+
if (existingDispose) {
|
|
228
|
+
existingDispose();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
290
232
|
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
(0, _react.useEffect)(() => {
|
|
233
|
+
},
|
|
234
|
+
[defaultUIConfig]
|
|
235
|
+
);
|
|
236
|
+
(0, import_react.useEffect)(() => {
|
|
296
237
|
document.body.addEventListener("mouseleave", mouseleave, false);
|
|
297
238
|
document.body.addEventListener("mouseenter", mouseenter, false);
|
|
298
239
|
const handleScroll = () => {
|
|
299
|
-
var
|
|
300
|
-
(
|
|
240
|
+
var _a;
|
|
241
|
+
(_a = clickOverlayRef.current) == null ? void 0 : _a.remove();
|
|
301
242
|
clickOverlayRef.current = null;
|
|
302
|
-
(0,
|
|
243
|
+
(0, import_utils.postMessage)({
|
|
303
244
|
type: "PageScroll",
|
|
304
245
|
data: {}
|
|
305
246
|
});
|
|
@@ -311,37 +252,95 @@ function MiaodaInspector(props) {
|
|
|
311
252
|
window.removeEventListener("scroll", handleScroll, true);
|
|
312
253
|
};
|
|
313
254
|
}, []);
|
|
314
|
-
(0,
|
|
255
|
+
(0, import_react.useEffect)(() => {
|
|
315
256
|
window.addEventListener("message", handleMessage);
|
|
316
257
|
return () => {
|
|
317
258
|
window.removeEventListener("message", handleMessage);
|
|
318
259
|
};
|
|
319
260
|
}, []);
|
|
320
|
-
(0,
|
|
321
|
-
(0,
|
|
261
|
+
(0, import_react.useEffect)(() => {
|
|
262
|
+
(0, import_utils.postMessage)({
|
|
322
263
|
type: "PageMounted",
|
|
323
264
|
data: {
|
|
324
|
-
version: "0.1.0",
|
|
265
|
+
version: "0.1.0-alpha.1",
|
|
325
266
|
theme: props.theme
|
|
326
267
|
}
|
|
327
268
|
});
|
|
328
269
|
}, []);
|
|
329
|
-
const selectInspectorElement = (0,
|
|
330
|
-
var
|
|
270
|
+
const selectInspectorElement = (0, import_react.useCallback)((params) => {
|
|
271
|
+
var _a, _b;
|
|
331
272
|
const { codeInfo, element, name, title } = params;
|
|
332
273
|
const coords = getElementCoordinates(element);
|
|
333
|
-
const textInfo = analyzeTextOnlyNode(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const
|
|
274
|
+
const textInfo = analyzeTextOnlyNode(
|
|
275
|
+
element,
|
|
276
|
+
name,
|
|
277
|
+
canUseNewInspector.current
|
|
278
|
+
);
|
|
279
|
+
const fontSizeInfo = (0, import_utils.calculateFontSizeInfo)(
|
|
280
|
+
element,
|
|
281
|
+
name,
|
|
282
|
+
canUseNewInspector.current,
|
|
283
|
+
styleConfigs
|
|
284
|
+
);
|
|
285
|
+
const fontWeightInfo = (0, import_utils.calculateFontWeightInfo)(
|
|
286
|
+
element,
|
|
287
|
+
name,
|
|
288
|
+
canUseNewInspector.current,
|
|
289
|
+
styleConfigs
|
|
290
|
+
);
|
|
291
|
+
const borderRadiusInfo = (0, import_utils.calculateBorderRadiusInfo)(
|
|
292
|
+
element,
|
|
293
|
+
name,
|
|
294
|
+
canUseNewInspector.current,
|
|
295
|
+
styleConfigs
|
|
296
|
+
);
|
|
297
|
+
const borderWidthInfo = (0, import_utils.calculateBorderWidthInfo)(
|
|
298
|
+
element,
|
|
299
|
+
name,
|
|
300
|
+
canUseNewInspector.current,
|
|
301
|
+
styleConfigs
|
|
302
|
+
);
|
|
303
|
+
const textAlignInfo = (0, import_utils.calculateTextAlignInfo)(
|
|
304
|
+
element,
|
|
305
|
+
name,
|
|
306
|
+
canUseNewInspector.current,
|
|
307
|
+
styleConfigs
|
|
308
|
+
);
|
|
309
|
+
const paddingInfo = (0, import_utils.calculatePaddingInfo)(
|
|
310
|
+
element,
|
|
311
|
+
name,
|
|
312
|
+
canUseNewInspector.current,
|
|
313
|
+
styleConfigs
|
|
314
|
+
);
|
|
315
|
+
const marginInfo = (0, import_utils.calculateMarginInfo)(
|
|
316
|
+
element,
|
|
317
|
+
name,
|
|
318
|
+
canUseNewInspector.current,
|
|
319
|
+
styleConfigs
|
|
320
|
+
);
|
|
321
|
+
const colorInfo = (0, import_utils.calculateColorInfo)(
|
|
322
|
+
element,
|
|
323
|
+
name,
|
|
324
|
+
canUseNewInspector.current,
|
|
325
|
+
styleConfigs
|
|
326
|
+
);
|
|
327
|
+
const backgroundColorInfo = (0, import_utils.calculateBackgroundColorInfo)(
|
|
328
|
+
element,
|
|
329
|
+
name,
|
|
330
|
+
canUseNewInspector.current,
|
|
331
|
+
styleConfigs
|
|
332
|
+
);
|
|
333
|
+
const borderColorInfo = (0, import_utils.calculateBorderColorInfo)(
|
|
334
|
+
element,
|
|
335
|
+
name,
|
|
336
|
+
canUseNewInspector.current,
|
|
337
|
+
styleConfigs
|
|
338
|
+
);
|
|
339
|
+
const id = elementInfoToKey(
|
|
340
|
+
codeInfo.relativePath,
|
|
341
|
+
codeInfo.lineNumber,
|
|
342
|
+
codeInfo.columnNumber
|
|
343
|
+
);
|
|
345
344
|
const selectElement = selectedElementMap.has(id);
|
|
346
345
|
if (!selectElement) {
|
|
347
346
|
selectedElementMap.set(id, {
|
|
@@ -358,7 +357,7 @@ function MiaodaInspector(props) {
|
|
|
358
357
|
element.setAttribute("contenteditable", "true");
|
|
359
358
|
element.focus();
|
|
360
359
|
const TextUpdate = () => {
|
|
361
|
-
(0,
|
|
360
|
+
(0, import_utils.postMessage)({
|
|
362
361
|
type: "TextUpdate",
|
|
363
362
|
data: {
|
|
364
363
|
elementId: id,
|
|
@@ -373,21 +372,20 @@ function MiaodaInspector(props) {
|
|
|
373
372
|
element.addEventListener("input", TextUpdate);
|
|
374
373
|
const _selectElement = selectedElementMap.get(id);
|
|
375
374
|
if (_selectElement) {
|
|
376
|
-
selectedElementMap.set(id,
|
|
375
|
+
selectedElementMap.set(id, __spreadProps(__spreadValues({}, _selectElement), {
|
|
377
376
|
dispose
|
|
378
377
|
}));
|
|
379
378
|
}
|
|
380
379
|
}
|
|
381
|
-
|
|
382
|
-
(0, _utils.postMessage)({
|
|
380
|
+
(0, import_utils.postMessage)({
|
|
383
381
|
type: "SelectInspectorElement",
|
|
384
|
-
data:
|
|
382
|
+
data: __spreadProps(__spreadValues({}, codeInfo), {
|
|
385
383
|
// 移除打头的 /
|
|
386
384
|
relativePath: codeInfo.relativePath,
|
|
387
|
-
tagName: element
|
|
385
|
+
tagName: element == null ? void 0 : element.tagName,
|
|
388
386
|
componentName: name,
|
|
389
387
|
className: safeClassName(element),
|
|
390
|
-
id: (
|
|
388
|
+
id: (_a = element == null ? void 0 : element.id) != null ? _a : "",
|
|
391
389
|
x: coords.left,
|
|
392
390
|
y: coords.top,
|
|
393
391
|
width: coords.width,
|
|
@@ -411,13 +409,13 @@ function MiaodaInspector(props) {
|
|
|
411
409
|
metadata: codeInfo.metadata
|
|
412
410
|
})
|
|
413
411
|
});
|
|
414
|
-
(
|
|
412
|
+
(_b = clickOverlayRef.current) == null ? void 0 : _b.remove();
|
|
415
413
|
clickOverlayRef.current = null;
|
|
416
|
-
const clickOverlay = new
|
|
414
|
+
const clickOverlay = new import_Overlay.ClickOverlay(() => {
|
|
417
415
|
const _coords = getElementCoordinates(element);
|
|
418
|
-
(0,
|
|
416
|
+
(0, import_utils.postMessage)({
|
|
419
417
|
type: "ElementResize",
|
|
420
|
-
data:
|
|
418
|
+
data: __spreadValues({
|
|
421
419
|
elementId: id
|
|
422
420
|
}, _coords)
|
|
423
421
|
});
|
|
@@ -425,23 +423,24 @@ function MiaodaInspector(props) {
|
|
|
425
423
|
clickOverlayRef.current = clickOverlay;
|
|
426
424
|
clickOverlay.highlight(element, title);
|
|
427
425
|
}, []);
|
|
428
|
-
const handleCodeInfo = (0,
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
name,
|
|
433
|
-
|
|
434
|
-
]
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
426
|
+
const handleCodeInfo = (0, import_react.useCallback)(
|
|
427
|
+
(name, info) => {
|
|
428
|
+
var _a;
|
|
429
|
+
const relativePath = (info == null ? void 0 : info.startsWith(props.cwd)) ? info.replace(props.cwd, "") : info;
|
|
430
|
+
return [name, (_a = relativePath == null ? void 0 : relativePath.replace(/^\//, "")) != null ? _a : ""];
|
|
431
|
+
},
|
|
432
|
+
[props.cwd]
|
|
433
|
+
);
|
|
434
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
435
|
+
import_Inspector.Inspector,
|
|
436
|
+
{
|
|
437
|
+
disable: false,
|
|
438
|
+
active,
|
|
439
|
+
onClickElement: selectInspectorElement,
|
|
440
|
+
handleCodeInfo,
|
|
441
|
+
onActiveChange: (newActive) => {
|
|
442
|
+
setActive(newActive);
|
|
443
|
+
}
|
|
445
444
|
}
|
|
446
|
-
|
|
445
|
+
);
|
|
447
446
|
}
|