@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.
Files changed (37) hide show
  1. package/dist/es/Inspector/Inspector.mjs +4 -22
  2. package/dist/es/Inspector/Overlay.mjs +58 -32
  3. package/dist/es/Inspector/utils/inspect.mjs +80 -1
  4. package/dist/es/MiaodaInspector/MiaodaInspector.mjs +332 -173
  5. package/dist/es/config/ui-config.mjs +138 -136
  6. package/dist/es/index.mjs +2 -0
  7. package/dist/es/types/feature.mjs +0 -0
  8. package/dist/es/types/index.mjs +4 -0
  9. package/dist/es/utils/config-mapper.mjs +1 -3
  10. package/dist/es/utils/element-guards.mjs +36 -0
  11. package/dist/es/utils/index.mjs +1 -6
  12. package/dist/es/utils/style-calculator.mjs +17 -60
  13. package/dist/lib/Inspector/Inspector.js +4 -23
  14. package/dist/lib/Inspector/Overlay.js +57 -28
  15. package/dist/lib/Inspector/utils/inspect.js +90 -1
  16. package/dist/lib/MiaodaInspector/MiaodaInspector.js +337 -183
  17. package/dist/lib/config/ui-config.js +138 -136
  18. package/dist/lib/index.js +2 -0
  19. package/dist/lib/types/feature.js +16 -0
  20. package/dist/lib/types/index.js +3 -0
  21. package/dist/lib/utils/config-mapper.js +1 -3
  22. package/dist/lib/utils/element-guards.js +55 -0
  23. package/dist/lib/utils/style-calculator.js +17 -60
  24. package/dist/types/Inspector/Inspector.d.ts +8 -1
  25. package/dist/types/Inspector/Overlay.d.ts +9 -2
  26. package/dist/types/Inspector/utils/index.d.ts +1 -1
  27. package/dist/types/Inspector/utils/inspect.d.ts +8 -1
  28. package/dist/types/config/ui-config.d.ts +26 -3
  29. package/dist/types/global.d.d.ts +6 -0
  30. package/dist/types/index.d.ts +2 -1
  31. package/dist/types/types/feature.d.ts +6 -0
  32. package/dist/types/types/iframe-events.d.ts +44 -2
  33. package/dist/types/types/index.d.ts +2 -1
  34. package/dist/types/utils/element-guards.d.ts +7 -0
  35. package/dist/types/utils/index.d.ts +1 -0
  36. package/dist/types/utils/origin.d.ts +1 -0
  37. package/package.json +1 -1
@@ -42,9 +42,11 @@ var import_jsx_runtime = require("react/jsx-runtime");
42
42
  var import_react = require("react");
43
43
  var import_Inspector = require("../Inspector");
44
44
  var import_Overlay = require("../Inspector/Overlay");
45
- var import_utils = require("../utils");
45
+ var import_utils = require("../Inspector/utils");
46
+ var import_utils2 = require("../utils");
46
47
  var import_MiaodaInspector = require("./MiaodaInspector.css");
47
48
  var import_config_mapper = require("../utils/config-mapper");
49
+ var import_element_guards = require("../utils/element-guards");
48
50
  function safeClassName(el) {
49
51
  const cn = el == null ? void 0 : el.className;
50
52
  if (typeof cn === "string") {
@@ -56,7 +58,13 @@ function safeClassName(el) {
56
58
  return "";
57
59
  }
58
60
  function analyzeTextOnlyNode(element, componentName, canUseNewInspector) {
59
- if (!element || componentName && componentName[0] === componentName[0].toUpperCase() || !canUseNewInspector || element instanceof SVGElement) {
61
+ if (!element || !canUseNewInspector || element instanceof SVGElement) {
62
+ return {
63
+ hasOnlyTextNodes: false,
64
+ textContent: null
65
+ };
66
+ }
67
+ if (!(0, import_element_guards.isNativeElementName)(componentName) && !(0, import_element_guards.isAntdText)(element, componentName)) {
60
68
  return {
61
69
  hasOnlyTextNodes: false,
62
70
  textContent: null
@@ -64,9 +72,7 @@ function analyzeTextOnlyNode(element, componentName, canUseNewInspector) {
64
72
  }
65
73
  try {
66
74
  const childNodes = Array.from(element.childNodes);
67
- const textNodes = childNodes.filter(
68
- (node) => node.nodeType === Node.TEXT_NODE
69
- );
75
+ const textNodes = childNodes.filter((node) => node.nodeType === Node.TEXT_NODE);
70
76
  const hasOnlyText = childNodes.length > 0 && textNodes.length === childNodes.length;
71
77
  return {
72
78
  hasOnlyTextNodes: hasOnlyText,
@@ -102,6 +108,23 @@ const getElementCoordinates = (element) => {
102
108
  bottom: adjustedBottom
103
109
  };
104
110
  };
111
+ const extractImageInfo = (element) => {
112
+ if (!element) {
113
+ return void 0;
114
+ }
115
+ if (element instanceof HTMLImageElement) {
116
+ const url = element.currentSrc || element.src || element.getAttribute("src") || void 0;
117
+ return {
118
+ type: "img",
119
+ url,
120
+ attribute: "src",
121
+ alt: element.alt || void 0,
122
+ width: element.naturalWidth || void 0,
123
+ height: element.naturalHeight || void 0
124
+ };
125
+ }
126
+ return void 0;
127
+ };
105
128
  const selectedElementMap = /* @__PURE__ */ new Map();
106
129
  function elementInfoToKey(relativePath, lineNumber, columnNumber) {
107
130
  return `${relativePath}_${lineNumber}_${columnNumber}`;
@@ -123,11 +146,200 @@ function MiaodaInspector(props) {
123
146
  const mouseenter = (0, import_react.useCallback)(() => {
124
147
  setInBody(true);
125
148
  }, []);
149
+ const updateClickOverlay = (0, import_react.useCallback)((element, title, id) => {
150
+ var _a;
151
+ (_a = clickOverlayRef.current) == null ? void 0 : _a.remove();
152
+ clickOverlayRef.current = null;
153
+ const clickOverlay = new import_Overlay.ClickOverlay({
154
+ positionUpdate: () => {
155
+ var _a2;
156
+ const el = ((_a2 = selectedElementMap.get(id)) == null ? void 0 : _a2.element) || element;
157
+ const _coords = getElementCoordinates(el);
158
+ (0, import_utils2.postMessage)({
159
+ type: "ElementResize",
160
+ data: __spreadValues({
161
+ elementId: id
162
+ }, _coords)
163
+ });
164
+ },
165
+ onElementRebind: (newEl) => {
166
+ const _selected = selectedElementMap.get(id);
167
+ if (_selected) {
168
+ _selected.element = newEl;
169
+ }
170
+ const _coords = getElementCoordinates(newEl);
171
+ (0, import_utils2.postMessage)({
172
+ type: "ElementResize",
173
+ data: __spreadValues({
174
+ elementId: id
175
+ }, _coords)
176
+ });
177
+ }
178
+ });
179
+ clickOverlayRef.current = clickOverlay;
180
+ clickOverlay.highlight(element, title, id);
181
+ }, []);
182
+ const selectInspectorElement = (0, import_react.useCallback)((params) => {
183
+ var _a, _b, _c, _d;
184
+ const { codeInfo, element, name, title, componentProps } = params;
185
+ const coords = getElementCoordinates(element);
186
+ const textInfo = analyzeTextOnlyNode(element, name, canUseNewInspector.current);
187
+ const fontSizeInfo = (0, import_utils2.calculateFontSizeInfo)(element, name, canUseNewInspector.current, styleConfigs);
188
+ const fontWeightInfo = (0, import_utils2.calculateFontWeightInfo)(element, name, canUseNewInspector.current, styleConfigs);
189
+ const borderRadiusInfo = (0, import_utils2.calculateBorderRadiusInfo)(
190
+ element,
191
+ name,
192
+ canUseNewInspector.current,
193
+ styleConfigs
194
+ );
195
+ const borderWidthInfo = (0, import_utils2.calculateBorderWidthInfo)(element, name, canUseNewInspector.current, styleConfigs);
196
+ const textAlignInfo = (0, import_utils2.calculateTextAlignInfo)(element, name, canUseNewInspector.current, styleConfigs);
197
+ const paddingInfo = (0, import_utils2.calculatePaddingInfo)(element, name, canUseNewInspector.current, styleConfigs);
198
+ const marginInfo = (0, import_utils2.calculateMarginInfo)(element, name, canUseNewInspector.current, styleConfigs);
199
+ const colorInfo = (0, import_utils2.calculateColorInfo)(element, name, canUseNewInspector.current, styleConfigs);
200
+ const borderColorInfo = (0, import_utils2.calculateBorderColorInfo)(element, name, canUseNewInspector.current, styleConfigs);
201
+ const backgroundColorInfo = (0, import_utils2.calculateBackgroundColorInfo)(
202
+ element,
203
+ name,
204
+ canUseNewInspector.current,
205
+ styleConfigs
206
+ );
207
+ const imageInfo = extractImageInfo(element);
208
+ const dataMiaodaId = element.getAttribute("data-miaoda-id");
209
+ const id = dataMiaodaId || elementInfoToKey(codeInfo.relativePath, codeInfo.lineNumber, codeInfo.columnNumber);
210
+ const selectElement = selectedElementMap.has(id);
211
+ if (!selectElement) {
212
+ const originalState = {
213
+ textContent: textInfo.textContent,
214
+ styles: {},
215
+ attributes: {},
216
+ className: safeClassName(element)
217
+ };
218
+ if (element instanceof HTMLImageElement) {
219
+ originalState.attributes.src = (_b = (_a = element.getAttribute("src")) != null ? _a : element.currentSrc) != null ? _b : null;
220
+ }
221
+ selectedElementMap.set(id, {
222
+ elementId: id,
223
+ element,
224
+ title,
225
+ originalState
226
+ });
227
+ }
228
+ const importSourceAttr = element.getAttribute("data-miaoda-import-source");
229
+ const isAntdComponent = importSourceAttr === "antd" && window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__ && window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__.setProps;
230
+ const isNativeTagImage = (imageInfo == null ? void 0 : imageInfo.type) === "img" && !isAntdComponent;
231
+ const nativeTagComponentProps = isNativeTagImage ? {
232
+ src: {
233
+ url: (_c = imageInfo == null ? void 0 : imageInfo.url) != null ? _c : "",
234
+ source: "url",
235
+ meta: {
236
+ origin: "img",
237
+ width: imageInfo == null ? void 0 : imageInfo.width,
238
+ height: imageInfo == null ? void 0 : imageInfo.height
239
+ }
240
+ }
241
+ } : void 0;
242
+ const importSource = importSourceAttr != null ? importSourceAttr : isNativeTagImage ? "nativeTag" : void 0;
243
+ if (textInfo.hasOnlyTextNodes && canUseNewInspector.current) {
244
+ element.setAttribute("contenteditable", "true");
245
+ element.focus();
246
+ const TextUpdate = () => {
247
+ (0, import_utils2.postMessage)({
248
+ type: "TextUpdate",
249
+ data: {
250
+ elementId: id,
251
+ textContent: element.textContent
252
+ }
253
+ });
254
+ };
255
+ const dispose = () => {
256
+ element.removeAttribute("contenteditable");
257
+ element.removeEventListener("input", TextUpdate);
258
+ };
259
+ element.addEventListener("input", TextUpdate);
260
+ const _selectElement = selectedElementMap.get(id);
261
+ if (_selectElement) {
262
+ selectedElementMap.set(id, __spreadProps(__spreadValues({}, _selectElement), {
263
+ dispose
264
+ }));
265
+ }
266
+ }
267
+ (0, import_utils2.postMessage)({
268
+ type: "SelectInspectorElement",
269
+ data: __spreadProps(__spreadValues({}, codeInfo), {
270
+ // 移除打头的 /
271
+ relativePath: codeInfo.relativePath,
272
+ tagName: element == null ? void 0 : element.tagName,
273
+ componentName: name,
274
+ className: safeClassName(element),
275
+ id: (_d = element == null ? void 0 : element.id) != null ? _d : "",
276
+ x: coords.left,
277
+ y: coords.top,
278
+ width: coords.width,
279
+ height: coords.height,
280
+ top: coords.top,
281
+ right: coords.right,
282
+ bottom: coords.bottom,
283
+ left: coords.left,
284
+ elementId: id,
285
+ textContent: textInfo.hasOnlyTextNodes ? textInfo.textContent : null,
286
+ fontSize: fontSizeInfo,
287
+ fontWeight: fontWeightInfo,
288
+ borderRadius: borderRadiusInfo,
289
+ borderWidth: borderWidthInfo,
290
+ textAlign: textAlignInfo,
291
+ padding: paddingInfo,
292
+ margin: marginInfo,
293
+ color: colorInfo,
294
+ backgroundColor: backgroundColorInfo,
295
+ borderColor: borderColorInfo,
296
+ metadata: codeInfo.metadata,
297
+ importSource,
298
+ componentProps: isAntdComponent ? componentProps : nativeTagComponentProps
299
+ })
300
+ });
301
+ updateClickOverlay(element, title, id);
302
+ }, []);
303
+ const selectParent = (0, import_react.useCallback)(
304
+ (elementId) => {
305
+ const selectedElement = selectedElementMap.get(elementId);
306
+ if (!selectedElement || !selectedElement.element) {
307
+ return;
308
+ }
309
+ const htmlElementParent = selectedElement.element.parentElement;
310
+ if (!htmlElementParent) {
311
+ return;
312
+ }
313
+ const targetElement = (0, import_utils.getParentElement)(htmlElementParent);
314
+ if (!targetElement) {
315
+ return;
316
+ }
317
+ const codeInfo = (0, import_utils.getElementCodeInfo)(targetElement);
318
+ const { fiber, name, title } = (0, import_utils.getElementInspect)(targetElement);
319
+ selectInspectorElement({
320
+ element: targetElement,
321
+ fiber,
322
+ codeInfo,
323
+ name,
324
+ title,
325
+ componentProps: (0, import_utils.extractPropsFromFiber)(fiber)
326
+ });
327
+ },
328
+ [selectInspectorElement]
329
+ );
330
+ const handleCodeInfo = (0, import_react.useCallback)(
331
+ (name, info) => {
332
+ var _a;
333
+ const relativePath = (info == null ? void 0 : info.startsWith(props.cwd)) ? info.replace(props.cwd, "") : info;
334
+ return [name, (_a = relativePath == null ? void 0 : relativePath.replace(/^\//, "")) != null ? _a : ""];
335
+ },
336
+ [props.cwd]
337
+ );
126
338
  const handleMessage = (0, import_react.useCallback)(
127
339
  (event) => {
128
340
  var _a, _b;
129
341
  const { data } = event;
130
- if ((0, import_utils.isIncomingMessage)(data, "InitConfig")) {
342
+ if ((0, import_utils2.isIncomingMessage)(data, "InitConfig")) {
131
343
  const { inspectorActive, userToken, appId, inspectorVersion } = data.data;
132
344
  if (inspectorActive !== void 0) {
133
345
  setActive(inspectorActive);
@@ -142,14 +354,14 @@ function MiaodaInspector(props) {
142
354
  if (appId !== void 0) {
143
355
  window.MIAODA_APP_ID = appId;
144
356
  }
145
- (0, import_utils.postMessage)({
357
+ (0, import_utils2.postMessage)({
146
358
  type: "InspectorUIConfig",
147
359
  data: defaultUIConfig
148
360
  });
149
361
  if (inspectorVersion === "2") {
150
362
  canUseNewInspector.current = true;
151
363
  }
152
- } else if ((0, import_utils.isIncomingMessage)(data, "ClearSelected")) {
364
+ } else if ((0, import_utils2.isIncomingMessage)(data, "ClearSelected")) {
153
365
  const { keepModifications = false } = data.data;
154
366
  (_b = clickOverlayRef.current) == null ? void 0 : _b.remove();
155
367
  clickOverlayRef.current = null;
@@ -169,13 +381,13 @@ function MiaodaInspector(props) {
169
381
  }
170
382
  selectedElementMap.clear();
171
383
  }
172
- } else if ((0, import_utils.isIncomingMessage)(data, "EditText")) {
384
+ } else if ((0, import_utils2.isIncomingMessage)(data, "EditText")) {
173
385
  const { elementId, textContent } = data.data;
174
386
  const selectedElement = selectedElementMap.get(elementId);
175
387
  if (selectedElement && selectedElement.element) {
176
388
  selectedElement.element.textContent = textContent;
177
389
  }
178
- } else if ((0, import_utils.isIncomingMessage)(data, "EditStyle")) {
390
+ } else if ((0, import_utils2.isIncomingMessage)(data, "EditStyle")) {
179
391
  const { elementId, styles } = data.data;
180
392
  const selectedElement = selectedElementMap.get(elementId);
181
393
  if (selectedElement && selectedElement.element) {
@@ -190,9 +402,7 @@ function MiaodaInspector(props) {
190
402
  }
191
403
  const existingDispose = selectedElement.dispose;
192
404
  const styleDispose = () => {
193
- for (const [property, value] of Object.entries(
194
- selectedElement.originalState.styles
195
- )) {
405
+ for (const [property, value] of Object.entries(selectedElement.originalState.styles)) {
196
406
  if (value) {
197
407
  element.style.setProperty(property, value);
198
408
  } else {
@@ -207,7 +417,7 @@ function MiaodaInspector(props) {
207
417
  }
208
418
  };
209
419
  }
210
- } else if ((0, import_utils.isIncomingMessage)(data, "EditClassName")) {
420
+ } else if ((0, import_utils2.isIncomingMessage)(data, "EditClassName")) {
211
421
  const { elementId, className } = data.data;
212
422
  const selectedElement = selectedElementMap.get(elementId);
213
423
  if (selectedElement && selectedElement.element) {
@@ -215,7 +425,7 @@ function MiaodaInspector(props) {
215
425
  if (selectedElement.originalState.className === void 0) {
216
426
  selectedElement.originalState.className = safeClassName(element);
217
427
  }
218
- element.className = (0, import_utils.cx)(element.className, className);
428
+ element.className = (0, import_utils2.cx)(element.className, className);
219
429
  const existingDispose = selectedElement.dispose;
220
430
  const classDispose = () => {
221
431
  if (selectedElement.originalState.className) {
@@ -229,9 +439,114 @@ function MiaodaInspector(props) {
229
439
  }
230
440
  };
231
441
  }
442
+ } else if ((0, import_utils2.isIncomingMessage)(data, "EditProps")) {
443
+ const { elementId, props: _props } = data.data;
444
+ const selectedElement = selectedElementMap.get(elementId);
445
+ if (selectedElement && selectedElement.element) {
446
+ const { element } = selectedElement;
447
+ if (window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__ && window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__.setProps) {
448
+ window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__.setProps(elementId, _props);
449
+ } else {
450
+ Object.entries(_props).forEach(([key, value]) => {
451
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
452
+ element.setAttribute(`data-${key}`, String(value));
453
+ }
454
+ });
455
+ }
456
+ const existingDispose = selectedElement.dispose;
457
+ const propsDispose = () => {
458
+ if (window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__) {
459
+ Object.keys(_props).forEach((key) => {
460
+ element.removeAttribute(`data-${key}`);
461
+ });
462
+ }
463
+ };
464
+ selectedElement.dispose = () => {
465
+ propsDispose();
466
+ if (existingDispose) {
467
+ existingDispose();
468
+ }
469
+ };
470
+ }
471
+ } else if ((0, import_utils2.isIncomingMessage)(data, "EditIconProps")) {
472
+ const { elementId, prop, value } = data.data;
473
+ const selectedElement = selectedElementMap.get(elementId);
474
+ if (selectedElement && selectedElement.element) {
475
+ if (window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__ && typeof window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__.setIconProps === "function") {
476
+ window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__.setIconProps(elementId, prop, value);
477
+ } else {
478
+ const { element } = selectedElement;
479
+ if (value) {
480
+ element.setAttribute(`data-${prop}`, String(value));
481
+ } else {
482
+ element.removeAttribute(`data-${prop}`);
483
+ }
484
+ }
485
+ const existingDispose = selectedElement.dispose;
486
+ const iconDispose = () => {
487
+ if (window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__ && typeof window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__.setIconProps === "function") {
488
+ window.__MIAODA_DEVTOOLS_GLOBAL_HOOK__.setIconProps(elementId, prop, void 0);
489
+ } else if (selectedElement.element) {
490
+ selectedElement.element.removeAttribute(`data-${prop}`);
491
+ }
492
+ };
493
+ selectedElement.dispose = () => {
494
+ iconDispose();
495
+ if (existingDispose) {
496
+ existingDispose();
497
+ }
498
+ };
499
+ }
500
+ } else if ((0, import_utils2.isIncomingMessage)(data, "ReverseSelect")) {
501
+ const { elementId } = data.data;
502
+ const selectedElement = selectedElementMap.get(elementId);
503
+ if (selectedElement && selectedElement.element) {
504
+ updateClickOverlay(selectedElement.element, selectedElement.title, selectedElement.elementId);
505
+ }
506
+ } else if ((0, import_utils2.isIncomingMessage)(data, "SelectParent")) {
507
+ const { elementId } = data.data;
508
+ selectParent(elementId);
509
+ } else if ((0, import_utils2.isIncomingMessage)(data, "EditAttributes")) {
510
+ const { elementId, attributes } = data.data;
511
+ const selectedElement = selectedElementMap.get(elementId);
512
+ if (selectedElement && selectedElement.element) {
513
+ const { element, originalState } = selectedElement;
514
+ const recordedAttributes = originalState.attributes;
515
+ Object.entries(attributes).forEach(([attr, value]) => {
516
+ if (!(attr in recordedAttributes)) {
517
+ recordedAttributes[attr] = element.getAttribute(attr);
518
+ }
519
+ if (value === null || value === void 0 || value === "") {
520
+ element.removeAttribute(attr);
521
+ } else {
522
+ element.setAttribute(attr, value);
523
+ }
524
+ });
525
+ originalState.attributes = recordedAttributes;
526
+ const existingDispose = selectedElement.dispose;
527
+ const attributeDispose = () => {
528
+ if (!selectedElement.element) {
529
+ return;
530
+ }
531
+ Object.entries(selectedElement.originalState.attributes).forEach(([attr, value]) => {
532
+ var _a2, _b2;
533
+ if (value === null || value === void 0 || value === "") {
534
+ (_a2 = selectedElement.element) == null ? void 0 : _a2.removeAttribute(attr);
535
+ } else {
536
+ (_b2 = selectedElement.element) == null ? void 0 : _b2.setAttribute(attr, value);
537
+ }
538
+ });
539
+ };
540
+ selectedElement.dispose = () => {
541
+ attributeDispose();
542
+ if (existingDispose) {
543
+ existingDispose();
544
+ }
545
+ };
546
+ }
232
547
  }
233
548
  },
234
- [defaultUIConfig]
549
+ [updateClickOverlay, selectParent, defaultUIConfig]
235
550
  );
236
551
  (0, import_react.useEffect)(() => {
237
552
  document.body.addEventListener("mouseleave", mouseleave, false);
@@ -240,7 +555,7 @@ function MiaodaInspector(props) {
240
555
  var _a;
241
556
  (_a = clickOverlayRef.current) == null ? void 0 : _a.remove();
242
557
  clickOverlayRef.current = null;
243
- (0, import_utils.postMessage)({
558
+ (0, import_utils2.postMessage)({
244
559
  type: "PageScroll",
245
560
  data: {}
246
561
  });
@@ -259,178 +574,17 @@ function MiaodaInspector(props) {
259
574
  };
260
575
  }, []);
261
576
  (0, import_react.useEffect)(() => {
262
- (0, import_utils.postMessage)({
577
+ (0, import_utils2.postMessage)({
263
578
  type: "PageMounted",
264
579
  data: {
265
- version: "0.1.0-alpha.4",
266
- theme: props.theme
267
- }
268
- });
269
- }, []);
270
- const selectInspectorElement = (0, import_react.useCallback)((params) => {
271
- var _a, _b;
272
- const { codeInfo, element, name, title } = params;
273
- const coords = getElementCoordinates(element);
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
- );
344
- const selectElement = selectedElementMap.has(id);
345
- if (!selectElement) {
346
- selectedElementMap.set(id, {
347
- elementId: id,
348
- element,
349
- originalState: {
350
- textContent: textInfo.textContent,
351
- className: safeClassName(element),
352
- styles: {}
580
+ version: "0.1.0-alpha.6",
581
+ feature: {
582
+ selectParent: true,
583
+ reverseSelect: true
353
584
  }
354
- });
355
- }
356
- if (textInfo.hasOnlyTextNodes && canUseNewInspector.current) {
357
- element.setAttribute("contenteditable", "true");
358
- element.focus();
359
- const TextUpdate = () => {
360
- (0, import_utils.postMessage)({
361
- type: "TextUpdate",
362
- data: {
363
- elementId: id,
364
- textContent: element.textContent
365
- }
366
- });
367
- };
368
- const dispose = () => {
369
- element.removeAttribute("contenteditable");
370
- element.removeEventListener("input", TextUpdate);
371
- };
372
- element.addEventListener("input", TextUpdate);
373
- const _selectElement = selectedElementMap.get(id);
374
- if (_selectElement) {
375
- selectedElementMap.set(id, __spreadProps(__spreadValues({}, _selectElement), {
376
- dispose
377
- }));
378
585
  }
379
- }
380
- (0, import_utils.postMessage)({
381
- type: "SelectInspectorElement",
382
- data: __spreadProps(__spreadValues({}, codeInfo), {
383
- // 移除打头的 /
384
- relativePath: codeInfo.relativePath,
385
- tagName: element == null ? void 0 : element.tagName,
386
- componentName: name,
387
- className: safeClassName(element),
388
- id: (_a = element == null ? void 0 : element.id) != null ? _a : "",
389
- x: coords.left,
390
- y: coords.top,
391
- width: coords.width,
392
- height: coords.height,
393
- top: coords.top,
394
- right: coords.right,
395
- bottom: coords.bottom,
396
- left: coords.left,
397
- elementId: id,
398
- textContent: textInfo.hasOnlyTextNodes ? textInfo.textContent : null,
399
- fontSize: fontSizeInfo,
400
- fontWeight: fontWeightInfo,
401
- borderRadius: borderRadiusInfo,
402
- borderWidth: borderWidthInfo,
403
- textAlign: textAlignInfo,
404
- padding: paddingInfo,
405
- margin: marginInfo,
406
- color: colorInfo,
407
- backgroundColor: backgroundColorInfo,
408
- borderColor: borderColorInfo,
409
- metadata: codeInfo.metadata
410
- })
411
586
  });
412
- (_b = clickOverlayRef.current) == null ? void 0 : _b.remove();
413
- clickOverlayRef.current = null;
414
- const clickOverlay = new import_Overlay.ClickOverlay(() => {
415
- const _coords = getElementCoordinates(element);
416
- (0, import_utils.postMessage)({
417
- type: "ElementResize",
418
- data: __spreadValues({
419
- elementId: id
420
- }, _coords)
421
- });
422
- });
423
- clickOverlayRef.current = clickOverlay;
424
- clickOverlay.highlight(element, title);
425
587
  }, []);
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
588
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
435
589
  import_Inspector.Inspector,
436
590
  {