@lark-apaas/miaoda-inspector 0.1.0-alpha.1
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/LICENSE +13 -0
- package/README.md +1 -0
- package/dist/es/Inspector/Inspector.js +179 -0
- package/dist/es/Inspector/Overlay.js +400 -0
- package/dist/es/Inspector/hooks/index.js +3 -0
- package/dist/es/Inspector/hooks/use-effect-event.js +15 -0
- package/dist/es/Inspector/hooks/use-layout-effect.js +3 -0
- package/dist/es/Inspector/hooks/use-mouse.js +22 -0
- package/dist/es/Inspector/index.js +1 -0
- package/dist/es/Inspector/utils/fiber.js +61 -0
- package/dist/es/Inspector/utils/highlight.js +74 -0
- package/dist/es/Inspector/utils/index.js +3 -0
- package/dist/es/Inspector/utils/inspect.js +119 -0
- package/dist/es/Inspector/utils/overlay.js +20 -0
- package/dist/es/MiaodaInspector/MiaodaInspector.css +46 -0
- package/dist/es/MiaodaInspector/MiaodaInspector.js +397 -0
- package/dist/es/MiaodaInspector/index.js +1 -0
- package/dist/es/config/ui-config.js +787 -0
- package/dist/es/index.js +2 -0
- package/dist/es/types/iframe-events.js +1 -0
- package/dist/es/types/index.js +1 -0
- package/dist/es/utils/config-mapper.js +163 -0
- package/dist/es/utils/css.js +5 -0
- package/dist/es/utils/index.js +3 -0
- package/dist/es/utils/origin.js +19 -0
- package/dist/es/utils/style-calculator.js +158 -0
- package/dist/lib/Inspector/Inspector.js +203 -0
- package/dist/lib/Inspector/Overlay.js +419 -0
- package/dist/lib/Inspector/hooks/index.js +20 -0
- package/dist/lib/Inspector/hooks/use-effect-event.js +25 -0
- package/dist/lib/Inspector/hooks/use-layout-effect.js +13 -0
- package/dist/lib/Inspector/hooks/use-mouse.js +32 -0
- package/dist/lib/Inspector/index.js +11 -0
- package/dist/lib/Inspector/utils/fiber.js +95 -0
- package/dist/lib/Inspector/utils/highlight.js +84 -0
- package/dist/lib/Inspector/utils/index.js +20 -0
- package/dist/lib/Inspector/utils/inspect.js +153 -0
- package/dist/lib/Inspector/utils/overlay.js +39 -0
- package/dist/lib/MiaodaInspector/MiaodaInspector.css +46 -0
- package/dist/lib/MiaodaInspector/MiaodaInspector.js +447 -0
- package/dist/lib/MiaodaInspector/index.js +11 -0
- package/dist/lib/config/ui-config.js +797 -0
- package/dist/lib/index.js +21 -0
- package/dist/lib/types/iframe-events.js +4 -0
- package/dist/lib/types/index.js +47 -0
- package/dist/lib/utils/config-mapper.js +182 -0
- package/dist/lib/utils/css.js +20 -0
- package/dist/lib/utils/index.js +61 -0
- package/dist/lib/utils/origin.js +44 -0
- package/dist/lib/utils/style-calculator.js +207 -0
- package/dist/types/Inspector/Inspector.d.ts +102 -0
- package/dist/types/Inspector/Overlay.d.ts +71 -0
- package/dist/types/Inspector/hooks/index.d.ts +3 -0
- package/dist/types/Inspector/hooks/use-effect-event.d.ts +9 -0
- package/dist/types/Inspector/hooks/use-layout-effect.d.ts +2 -0
- package/dist/types/Inspector/hooks/use-mouse.d.ts +9 -0
- package/dist/types/Inspector/index.d.ts +1 -0
- package/dist/types/Inspector/utils/fiber.d.ts +34 -0
- package/dist/types/Inspector/utils/highlight.d.ts +8 -0
- package/dist/types/Inspector/utils/index.d.ts +3 -0
- package/dist/types/Inspector/utils/inspect.d.ts +110 -0
- package/dist/types/Inspector/utils/overlay.d.ts +30 -0
- package/dist/types/MiaodaInspector/MiaodaInspector.d.ts +47 -0
- package/dist/types/MiaodaInspector/index.d.ts +1 -0
- package/dist/types/config/ui-config.d.ts +49 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/types/iframe-events.d.ts +155 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/utils/config-mapper.d.ts +12 -0
- package/dist/types/utils/css.d.ts +2 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/origin.d.ts +9 -0
- package/dist/types/utils/style-calculator.d.ts +19 -0
- package/package.json +48 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mirror from https://github.com/facebook/react/blob/v16.13.1/packages/react-devtools-shared/src/backend/views/utils.js
|
|
3
|
+
*/
|
|
4
|
+
import { type Rect, type BoxSizing } from './utils';
|
|
5
|
+
interface Box {
|
|
6
|
+
top: number;
|
|
7
|
+
left: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
declare class OverlayRect {
|
|
12
|
+
node: HTMLElement;
|
|
13
|
+
border: HTMLElement;
|
|
14
|
+
padding: HTMLElement;
|
|
15
|
+
content: HTMLElement;
|
|
16
|
+
constructor(doc: Document, container: HTMLElement);
|
|
17
|
+
remove(): void;
|
|
18
|
+
update(box: Rect, dims: BoxSizing): void;
|
|
19
|
+
}
|
|
20
|
+
declare class ClickOverlayRect {
|
|
21
|
+
node: HTMLElement;
|
|
22
|
+
border: HTMLElement;
|
|
23
|
+
constructor(doc: Document, container: HTMLElement);
|
|
24
|
+
remove(): void;
|
|
25
|
+
update(box: Rect, dims: BoxSizing): void;
|
|
26
|
+
}
|
|
27
|
+
declare class OverlayTip {
|
|
28
|
+
tip: HTMLElement;
|
|
29
|
+
nameSpan: HTMLElement;
|
|
30
|
+
titleDiv: HTMLElement;
|
|
31
|
+
constructor(doc: Document, container: HTMLElement);
|
|
32
|
+
remove(): void;
|
|
33
|
+
updateText(name: string): void;
|
|
34
|
+
updatePosition(dims: Box, bounds: Box): void;
|
|
35
|
+
invisible(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare class Overlay {
|
|
38
|
+
window: Window;
|
|
39
|
+
tipBoundsWindow: Window;
|
|
40
|
+
container: HTMLElement;
|
|
41
|
+
tip: OverlayTip;
|
|
42
|
+
rects: Array<OverlayRect>;
|
|
43
|
+
removeCallback: (this: Overlay) => void;
|
|
44
|
+
handleCodeInfo?: (name: string, info?: string) => [string, string];
|
|
45
|
+
resizeObserver: ResizeObserver;
|
|
46
|
+
currentElements?: HTMLElement[];
|
|
47
|
+
currentName?: string;
|
|
48
|
+
constructor(handleCodeInfo?: (name: string, info?: string) => [string, string]);
|
|
49
|
+
remove(): void;
|
|
50
|
+
setRemoveCallback(callback: () => void): void;
|
|
51
|
+
inspect(nodes: Array<HTMLElement>, name?: string, info?: string): void;
|
|
52
|
+
updatePositions(nodes: Array<HTMLElement>, name?: string, info?: string): void;
|
|
53
|
+
clearRect(): void;
|
|
54
|
+
}
|
|
55
|
+
export declare class ClickOverlay {
|
|
56
|
+
window: Window;
|
|
57
|
+
container: HTMLElement;
|
|
58
|
+
rect: ClickOverlayRect | null;
|
|
59
|
+
tip: OverlayTip;
|
|
60
|
+
tipBoundsWindow: Window;
|
|
61
|
+
resizeObserver: ResizeObserver;
|
|
62
|
+
currentElement: HTMLElement | null;
|
|
63
|
+
currentName: string | undefined;
|
|
64
|
+
positionUpdate?: () => void;
|
|
65
|
+
constructor(positionUpdate?: () => void);
|
|
66
|
+
remove(): void;
|
|
67
|
+
highlight(element: HTMLElement, name?: string): void;
|
|
68
|
+
updatePosition(element: HTMLElement): void;
|
|
69
|
+
clearRect(): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple but not robust implement of React18 experimental hook `useEffectEvent`,
|
|
3
|
+
* to keep compatible with other React versions.
|
|
4
|
+
*
|
|
5
|
+
* for some more robust implements, you can see:
|
|
6
|
+
* - `useEvent` in https://github.com/scottrippey/react-use-event-hook
|
|
7
|
+
* - `useMemoizedFn` in https://github.com/alibaba/hooks
|
|
8
|
+
*/
|
|
9
|
+
export declare const useEffectEvent: <T extends (...args: any[]) => any>(callback?: T | undefined) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Inspector } from './Inspector';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Fiber } from 'react-reconciler';
|
|
2
|
+
/**
|
|
3
|
+
* only native html tag fiber's type will be string,
|
|
4
|
+
* all the others (component / functional component / context) type will be function or object
|
|
5
|
+
*/
|
|
6
|
+
export declare const isNativeTagFiber: (fiber?: Fiber) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* react fiber symbol types see:
|
|
9
|
+
* https://github.com/facebook/react/blob/v17.0.0/packages/shared/ReactSymbols.js#L39-L58
|
|
10
|
+
*/
|
|
11
|
+
export declare const isReactSymbolFiber: (fiber?: Fiber) => boolean;
|
|
12
|
+
export declare const isForwardRef: (fiber?: Fiber) => boolean;
|
|
13
|
+
type FiberHTMLElement = HTMLElement & {
|
|
14
|
+
[fiberKey: string]: Fiber | undefined;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* https://stackoverflow.com/questions/29321742/react-getting-a-component-from-a-dom-element-for-debugging
|
|
18
|
+
*/
|
|
19
|
+
export declare const getElementFiber: (element: FiberHTMLElement) => Fiber | undefined;
|
|
20
|
+
export declare const getElementFiberUpward: (element: HTMLElement | null) => Fiber | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* find first parent of native html tag or react component,
|
|
23
|
+
* skip react Provider / Context / ForwardRef / Fragment etc.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getDirectParentFiber: (child: Fiber) => Fiber | null;
|
|
26
|
+
/**
|
|
27
|
+
* The displayName property is not guaranteed to be a string.
|
|
28
|
+
* It's only safe to use for our purposes if it's a string.
|
|
29
|
+
* github.com/facebook/react-devtools/issues/803
|
|
30
|
+
*
|
|
31
|
+
* https://github.com/facebook/react/blob/v17.0.0/packages/react-devtools-shared/src/utils.js#L90-L112
|
|
32
|
+
*/
|
|
33
|
+
export declare const getFiberName: (fiber?: Fiber) => string | undefined;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mirror from https://github.com/facebook/react/blob/v16.13.1/packages/react-devtools-shared/src/backend/views/Highlighter/index.js
|
|
3
|
+
*/
|
|
4
|
+
export type StopFunction = () => void;
|
|
5
|
+
export declare function setupHighlighter(handlers: {
|
|
6
|
+
onPointerOver?: (element: HTMLElement) => void;
|
|
7
|
+
onClick?: (element: HTMLElement) => void;
|
|
8
|
+
}): StopFunction;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Fiber } from 'react-reconciler';
|
|
2
|
+
export interface CodeInfo {
|
|
3
|
+
name?: string;
|
|
4
|
+
lineNumber: string;
|
|
5
|
+
columnNumber: string;
|
|
6
|
+
/**
|
|
7
|
+
* code source file relative path to dev-server cwd(current working directory)
|
|
8
|
+
* need use with `react-dev-inspector/plugins/babel`
|
|
9
|
+
*/
|
|
10
|
+
relativePath?: string;
|
|
11
|
+
/**
|
|
12
|
+
* code source file absolute path
|
|
13
|
+
* just need use with `@babel/plugin-transform-react-jsx-source` which auto set by most framework
|
|
14
|
+
*/
|
|
15
|
+
absolutePath?: string;
|
|
16
|
+
/**
|
|
17
|
+
* metadata information from babel plugin
|
|
18
|
+
*/
|
|
19
|
+
metadata?: {
|
|
20
|
+
elementStart: number;
|
|
21
|
+
elementEnd: number;
|
|
22
|
+
tagStart: number;
|
|
23
|
+
tagEnd: number;
|
|
24
|
+
classNameLiteral: boolean;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* props that injected into react nodes
|
|
29
|
+
*
|
|
30
|
+
* like <div data-inspector-line="2" data-inspector-column="3" data-inspector-relative-path="xxx/ooo" />
|
|
31
|
+
* this props will be record in fiber
|
|
32
|
+
*/
|
|
33
|
+
export interface CodeDataAttribute {
|
|
34
|
+
'data-miaoda-line': string;
|
|
35
|
+
'data-miaoda-column': string;
|
|
36
|
+
'data-miaoda-relative-path': string;
|
|
37
|
+
'data-miaoda-component-name'?: string;
|
|
38
|
+
'data-miaoda-metadata'?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* react fiber property `_debugSource` created by `@babel/plugin-transform-react-jsx-source`
|
|
42
|
+
* https://github.com/babel/babel/blob/v7.16.4/packages/babel-plugin-transform-react-jsx-source/src/index.js
|
|
43
|
+
*
|
|
44
|
+
* and injected `__source` property used by `React.createElement`, then pass to `ReactElement`
|
|
45
|
+
* https://github.com/facebook/react/blob/v18.0.0/packages/react/src/ReactElement.js#L189
|
|
46
|
+
* https://github.com/facebook/react/blob/v18.0.0/packages/react/src/ReactElement.js#L389
|
|
47
|
+
* https://github.com/facebook/react/blob/v18.0.0/packages/react/src/ReactElement.js#L447
|
|
48
|
+
*
|
|
49
|
+
* finally, used by `createFiberFromElement` to become a fiber property `_debugSource`.
|
|
50
|
+
* https://github.com/facebook/react/blob/v18.0.0/packages/react-reconciler/src/ReactFiber.new.js#L648-L649
|
|
51
|
+
*/
|
|
52
|
+
export declare const getCodeInfoFromDebugSource: (fiber?: Fiber) => CodeInfo | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* code location data-attribute props inject by `react-dev-inspector/plugins/babel`
|
|
55
|
+
*/
|
|
56
|
+
export declare const getCodeInfoFromProps: (fiber?: Fiber) => CodeInfo | undefined;
|
|
57
|
+
export declare const getCodeInfoFromFiber: (fiber?: Fiber) => CodeInfo | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* give a `base` dom fiber,
|
|
60
|
+
* and will try to get the human friendly react component `reference` fiber from it;
|
|
61
|
+
*
|
|
62
|
+
* rules and examples see below:
|
|
63
|
+
* *******************************************************
|
|
64
|
+
*
|
|
65
|
+
* if parent is html native tag, `reference` is considered to be as same as `base`
|
|
66
|
+
*
|
|
67
|
+
* div div
|
|
68
|
+
* └─ h1 └─ h1 (<--base) <--reference
|
|
69
|
+
* └─ span (<--base) <--reference └─ span
|
|
70
|
+
*
|
|
71
|
+
* *******************************************************
|
|
72
|
+
*
|
|
73
|
+
* if parent is NOT html native tag,
|
|
74
|
+
* and parent ONLY have one child (the `base` itself),
|
|
75
|
+
* then `reference` is considered to be the parent.
|
|
76
|
+
*
|
|
77
|
+
* Title <--reference Title
|
|
78
|
+
* └─ h1 (<--base) └─ h1 (<--base) <--reference
|
|
79
|
+
* └─ span └─ span
|
|
80
|
+
* └─ div
|
|
81
|
+
*
|
|
82
|
+
* *******************************************************
|
|
83
|
+
*
|
|
84
|
+
* while follow the last one,
|
|
85
|
+
* "parent" is considered to skip continuous Provider/Customer/ForwardRef components
|
|
86
|
+
*
|
|
87
|
+
* Title <- reference Title <- reference
|
|
88
|
+
* └─ TitleName [ForwardRef] └─ TitleName [ForwardRef]
|
|
89
|
+
* └─ Context.Customer └─ Context.Customer
|
|
90
|
+
* └─ Context.Customer └─ Context.Customer
|
|
91
|
+
* └─ h1 (<- base) └─ h1 (<- base)
|
|
92
|
+
* └─ span └─ span
|
|
93
|
+
* └─ div
|
|
94
|
+
*
|
|
95
|
+
* Title
|
|
96
|
+
* └─ TitleName [ForwardRef]
|
|
97
|
+
* └─ Context.Customer
|
|
98
|
+
* └─ Context.Customer
|
|
99
|
+
* └─ h1 (<- base) <- reference
|
|
100
|
+
* └─ span
|
|
101
|
+
* └─ div
|
|
102
|
+
*/
|
|
103
|
+
export declare const getReferenceFiber: (baseFiber?: Fiber) => Fiber | undefined;
|
|
104
|
+
export declare const getElementCodeInfo: (element: HTMLElement) => CodeInfo | undefined;
|
|
105
|
+
export declare const getNamedFiber: (baseFiber?: Fiber) => Fiber | undefined;
|
|
106
|
+
export declare const getElementInspect: (element: HTMLElement) => {
|
|
107
|
+
fiber?: Fiber | undefined;
|
|
108
|
+
name?: string | undefined;
|
|
109
|
+
title: string;
|
|
110
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mirror from https://github.com/facebook/react/blob/v16.13.1/packages/react-devtools-shared/src/backend/views/Highlighter/Overlay.js
|
|
3
|
+
*
|
|
4
|
+
* remove all process for iframe, because iframe only need to think in chrome extension app,
|
|
5
|
+
* which will deal multiple levels of nesting iframe.
|
|
6
|
+
*/
|
|
7
|
+
export interface Rect {
|
|
8
|
+
bottom: number;
|
|
9
|
+
height: number;
|
|
10
|
+
left: number;
|
|
11
|
+
right: number;
|
|
12
|
+
top: number;
|
|
13
|
+
width: number;
|
|
14
|
+
}
|
|
15
|
+
export interface BoxSizing {
|
|
16
|
+
borderTop: number;
|
|
17
|
+
borderBottom: number;
|
|
18
|
+
borderLeft: number;
|
|
19
|
+
borderRight: number;
|
|
20
|
+
paddingTop: number;
|
|
21
|
+
paddingBottom: number;
|
|
22
|
+
paddingLeft: number;
|
|
23
|
+
paddingRight: number;
|
|
24
|
+
marginTop: number;
|
|
25
|
+
marginBottom: number;
|
|
26
|
+
marginLeft: number;
|
|
27
|
+
marginRight: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function getNestedBoundingClientRect(node: HTMLElement, boundaryWindow: Window | HTMLElement): Rect;
|
|
30
|
+
export declare function getElementDimensions(domElement: Element): BoxSizing;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type InspectorUIConfig } from '../config/ui-config';
|
|
3
|
+
import './MiaodaInspector.css';
|
|
4
|
+
interface IThemeMeta {
|
|
5
|
+
themeColors: {
|
|
6
|
+
title: string;
|
|
7
|
+
options: {
|
|
8
|
+
value: string;
|
|
9
|
+
color: string;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
themeRadius: {
|
|
13
|
+
title: string;
|
|
14
|
+
options: {
|
|
15
|
+
value: {
|
|
16
|
+
pixel: string;
|
|
17
|
+
rem: string;
|
|
18
|
+
};
|
|
19
|
+
iconUrl: string;
|
|
20
|
+
size: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
themeSpaces: {
|
|
24
|
+
title: string;
|
|
25
|
+
options: {
|
|
26
|
+
value: {
|
|
27
|
+
pixel: string;
|
|
28
|
+
rem: string;
|
|
29
|
+
};
|
|
30
|
+
iconUrl: string;
|
|
31
|
+
size: string;
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
interface MiaodaInspectorProps {
|
|
36
|
+
cwd: string;
|
|
37
|
+
theme: {
|
|
38
|
+
themeColorTokenMap: {
|
|
39
|
+
light: Record<string, string>;
|
|
40
|
+
dark: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
themeMetaOptions: Omit<IThemeMeta, 'colorPrimary' | 'borderRadius' | 'spacing'>;
|
|
43
|
+
themeToken: InspectorUIConfig;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare function MiaodaInspector(props: MiaodaInspectorProps): React.JSX.Element;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MiaodaInspector } from './MiaodaInspector';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface SelectOption {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
rawValue: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SelectUIConfig {
|
|
7
|
+
type: 'select';
|
|
8
|
+
options: SelectOption[];
|
|
9
|
+
}
|
|
10
|
+
export interface SpacingUIConfig {
|
|
11
|
+
type: 'spacing';
|
|
12
|
+
options: SelectOption[];
|
|
13
|
+
}
|
|
14
|
+
interface Color {
|
|
15
|
+
label: string;
|
|
16
|
+
value: string;
|
|
17
|
+
type?: 'tailwind' | 'style';
|
|
18
|
+
rawValue?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ColorPickerUIConfig {
|
|
21
|
+
type: 'color-picker';
|
|
22
|
+
recommendColors: {
|
|
23
|
+
title: string;
|
|
24
|
+
options: Color[];
|
|
25
|
+
}[];
|
|
26
|
+
}
|
|
27
|
+
export interface IconPickerUIConfig {
|
|
28
|
+
type: 'icon-picker';
|
|
29
|
+
}
|
|
30
|
+
export type UIComponentConfig = SelectUIConfig | ColorPickerUIConfig | IconPickerUIConfig | SpacingUIConfig;
|
|
31
|
+
export interface InspectorUIConfig {
|
|
32
|
+
version: string;
|
|
33
|
+
common: {
|
|
34
|
+
fontSize: UIComponentConfig;
|
|
35
|
+
fontWeight: UIComponentConfig;
|
|
36
|
+
borderRadius: UIComponentConfig;
|
|
37
|
+
borderWidth: UIComponentConfig;
|
|
38
|
+
textAlign: UIComponentConfig;
|
|
39
|
+
padding: UIComponentConfig;
|
|
40
|
+
margin: UIComponentConfig;
|
|
41
|
+
color: UIComponentConfig;
|
|
42
|
+
borderColor: UIComponentConfig;
|
|
43
|
+
backgroundColor: UIComponentConfig;
|
|
44
|
+
};
|
|
45
|
+
components?: Record<string, Record<string, UIComponentConfig>>;
|
|
46
|
+
tokens: Record<string, string>;
|
|
47
|
+
}
|
|
48
|
+
export declare const defaultUIConfig: InspectorUIConfig;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { MiaodaInspector } from './MiaodaInspector';
|
|
2
|
+
export type { InitConfigMessage, ClearSelectedMessage, EditTextMessage, EditStyleMessage, EditClassNameMessage, PageMountedMessage, TextUpdateMessage, SelectInspectorElementMessage, InspectorInfo, IncomingMessage } from './types';
|
|
3
|
+
export { isOutgoingMessage } from './utils';
|
|
4
|
+
export type { InspectorUIConfig } from './config/ui-config';
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { type InspectorUIConfig } from '../config/ui-config';
|
|
2
|
+
/**
|
|
3
|
+
* Iframe message event types for inspector communication
|
|
4
|
+
*/
|
|
5
|
+
export interface IframeMessage<T = unknown> {
|
|
6
|
+
type: string;
|
|
7
|
+
data: T;
|
|
8
|
+
}
|
|
9
|
+
export interface EditClassNameMessage extends IframeMessage<{
|
|
10
|
+
elementId: string;
|
|
11
|
+
className: string;
|
|
12
|
+
}> {
|
|
13
|
+
type: 'EditClassName';
|
|
14
|
+
}
|
|
15
|
+
export type IncomingMessage = InitConfigMessage | ClearSelectedMessage | EditTextMessage | EditStyleMessage | EditClassNameMessage;
|
|
16
|
+
export interface InitConfigMessage extends IframeMessage<{
|
|
17
|
+
inspectorActive?: boolean;
|
|
18
|
+
userToken?: string;
|
|
19
|
+
appId?: string;
|
|
20
|
+
inspectorVersion?: string;
|
|
21
|
+
}> {
|
|
22
|
+
type: 'InitConfig';
|
|
23
|
+
}
|
|
24
|
+
export interface ClearSelectedMessage extends IframeMessage<{
|
|
25
|
+
keepModifications?: boolean;
|
|
26
|
+
}> {
|
|
27
|
+
type: 'ClearSelected';
|
|
28
|
+
}
|
|
29
|
+
export interface EditTextMessage extends IframeMessage<{
|
|
30
|
+
elementId: string;
|
|
31
|
+
textContent: string;
|
|
32
|
+
}> {
|
|
33
|
+
type: 'EditText';
|
|
34
|
+
}
|
|
35
|
+
export interface EditStyleMessage extends IframeMessage<{
|
|
36
|
+
elementId: string;
|
|
37
|
+
styles: Record<string, string>;
|
|
38
|
+
}> {
|
|
39
|
+
type: 'EditStyle';
|
|
40
|
+
}
|
|
41
|
+
export interface PageMountedMessage extends IframeMessage<{
|
|
42
|
+
version?: string;
|
|
43
|
+
}> {
|
|
44
|
+
type: 'PageMounted';
|
|
45
|
+
}
|
|
46
|
+
export interface TextUpdateMessage extends IframeMessage<{
|
|
47
|
+
elementId: string;
|
|
48
|
+
textContent: string | null;
|
|
49
|
+
}> {
|
|
50
|
+
type: 'TextUpdate';
|
|
51
|
+
}
|
|
52
|
+
export interface PageScrollMessage extends IframeMessage<Record<string, never>> {
|
|
53
|
+
type: 'PageScroll';
|
|
54
|
+
}
|
|
55
|
+
export interface ElementResizeMessage extends IframeMessage<{
|
|
56
|
+
elementId: string;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
top: number;
|
|
60
|
+
left: number;
|
|
61
|
+
right: number;
|
|
62
|
+
bottom: number;
|
|
63
|
+
}> {
|
|
64
|
+
type: 'ElementResize';
|
|
65
|
+
}
|
|
66
|
+
export interface InspectorInfo {
|
|
67
|
+
columnNumber: string;
|
|
68
|
+
lineNumber: string;
|
|
69
|
+
relativePath: string;
|
|
70
|
+
tagName: string;
|
|
71
|
+
componentName: string;
|
|
72
|
+
className: string;
|
|
73
|
+
x?: number;
|
|
74
|
+
y?: number;
|
|
75
|
+
top?: number;
|
|
76
|
+
bottom?: number;
|
|
77
|
+
right?: number;
|
|
78
|
+
left?: number;
|
|
79
|
+
width?: number;
|
|
80
|
+
height?: number;
|
|
81
|
+
textContent?: string;
|
|
82
|
+
elementId: string;
|
|
83
|
+
fontSize?: {
|
|
84
|
+
value: string;
|
|
85
|
+
inherited: boolean;
|
|
86
|
+
tailwindClassName: string;
|
|
87
|
+
};
|
|
88
|
+
fontWeight?: {
|
|
89
|
+
value: string;
|
|
90
|
+
inherited: boolean;
|
|
91
|
+
tailwindClassName: string;
|
|
92
|
+
};
|
|
93
|
+
borderRadius?: {
|
|
94
|
+
value: string;
|
|
95
|
+
inherited: boolean;
|
|
96
|
+
tailwindClassName: string;
|
|
97
|
+
};
|
|
98
|
+
borderWidth?: {
|
|
99
|
+
value: string;
|
|
100
|
+
inherited: boolean;
|
|
101
|
+
tailwindClassName: string;
|
|
102
|
+
};
|
|
103
|
+
textAlign?: {
|
|
104
|
+
value: string;
|
|
105
|
+
inherited: boolean;
|
|
106
|
+
tailwindClassName: string;
|
|
107
|
+
};
|
|
108
|
+
padding?: {
|
|
109
|
+
value: string;
|
|
110
|
+
inherited: boolean;
|
|
111
|
+
tailwindClassName: string;
|
|
112
|
+
};
|
|
113
|
+
margin?: {
|
|
114
|
+
value: string;
|
|
115
|
+
inherited: boolean;
|
|
116
|
+
tailwindClassName: string;
|
|
117
|
+
};
|
|
118
|
+
color?: {
|
|
119
|
+
value: string;
|
|
120
|
+
inherited: boolean;
|
|
121
|
+
tailwindClassName: string;
|
|
122
|
+
};
|
|
123
|
+
backgroundColor?: {
|
|
124
|
+
value: string;
|
|
125
|
+
inherited: boolean;
|
|
126
|
+
tailwindClassName: string;
|
|
127
|
+
};
|
|
128
|
+
borderColor?: {
|
|
129
|
+
value: string;
|
|
130
|
+
inherited: boolean;
|
|
131
|
+
tailwindClassName: string;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* metadata information from babel plugin
|
|
135
|
+
*/
|
|
136
|
+
metadata?: {
|
|
137
|
+
elementStart: number;
|
|
138
|
+
elementEnd: number;
|
|
139
|
+
tagStart: number;
|
|
140
|
+
tagEnd: number;
|
|
141
|
+
classNameLiteral: boolean;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export interface SelectInspectorElementMessage extends IframeMessage<InspectorInfo> {
|
|
145
|
+
type: 'SelectInspectorElement';
|
|
146
|
+
}
|
|
147
|
+
export interface InspectorUIConfigMessage extends IframeMessage<InspectorUIConfig> {
|
|
148
|
+
type: 'InspectorUIConfig';
|
|
149
|
+
}
|
|
150
|
+
export type OutgoingMessage = PageMountedMessage | TextUpdateMessage | PageScrollMessage | ElementResizeMessage | SelectInspectorElementMessage | InspectorUIConfigMessage;
|
|
151
|
+
declare global {
|
|
152
|
+
interface WindowEventMap {
|
|
153
|
+
message: MessageEvent<IframeMessage>;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InitConfigMessage, ClearSelectedMessage, EditTextMessage, EditStyleMessage, EditClassNameMessage, OutgoingMessage, PageMountedMessage, TextUpdateMessage, SelectInspectorElementMessage, IncomingMessage, InspectorInfo } from './iframe-events';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InspectorUIConfig } from '../config/ui-config';
|
|
2
|
+
export interface StyleCalculationConfig {
|
|
3
|
+
cssProperty: string;
|
|
4
|
+
tailwindPrefix: string;
|
|
5
|
+
map: Record<string | number, string>;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
transformValue?: (value: string) => string | number;
|
|
8
|
+
tolerance?: number;
|
|
9
|
+
skipTailwind?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function getStyleCalculationConfig(config: InspectorUIConfig, propertyName: keyof InspectorUIConfig['common']): StyleCalculationConfig;
|
|
12
|
+
export declare function getAllStyleConfigs(config: InspectorUIConfig): Record<string, StyleCalculationConfig>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { getPreviewParentOrigin, postMessage, isIncomingMessage, isOutgoingMessage } from './origin';
|
|
2
|
+
export { cx } from './css';
|
|
3
|
+
export { calculateFontSizeInfo, calculateFontWeightInfo, calculateBorderRadiusInfo, calculateBorderWidthInfo, calculateTextAlignInfo, calculatePaddingInfo, calculateMarginInfo, calculateColorInfo, calculateBackgroundColorInfo, calculateBorderColorInfo } from './style-calculator';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type OutgoingMessage, type IncomingMessage } from '../types';
|
|
2
|
+
export declare function getPreviewParentOrigin(): string;
|
|
3
|
+
export declare function postMessage<T extends OutgoingMessage>(message: T, targetOrigin?: string): void;
|
|
4
|
+
export declare function isOutgoingMessage<T extends OutgoingMessage['type']>(msg: OutgoingMessage, type: T): msg is Extract<OutgoingMessage, {
|
|
5
|
+
type: T;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function isIncomingMessage<T extends IncomingMessage['type']>(msg: IncomingMessage, type: T): msg is Extract<IncomingMessage, {
|
|
8
|
+
type: T;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StyleCalculationConfig } from './config-mapper';
|
|
2
|
+
interface StyleCalculationResult {
|
|
3
|
+
value: string;
|
|
4
|
+
inherited: boolean;
|
|
5
|
+
tailwindClassName: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function rgbaToHex(rgba: string): string;
|
|
8
|
+
export declare function calculateStyle(styleName: string, element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>): StyleCalculationResult | null;
|
|
9
|
+
export declare const calculateFontSizeInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
10
|
+
export declare const calculateFontWeightInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
11
|
+
export declare const calculateBorderRadiusInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
12
|
+
export declare const calculateBorderWidthInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
13
|
+
export declare const calculateTextAlignInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
14
|
+
export declare const calculatePaddingInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
15
|
+
export declare const calculateMarginInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
16
|
+
export declare const calculateColorInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
17
|
+
export declare const calculateBackgroundColorInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
18
|
+
export declare const calculateBorderColorInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
|
|
19
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lark-apaas/miaoda-inspector",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Inspector for Lark Apaas",
|
|
5
|
+
"sideEffects": [
|
|
6
|
+
"*.css"
|
|
7
|
+
],
|
|
8
|
+
"main": "./dist/lib",
|
|
9
|
+
"module": "./dist/es",
|
|
10
|
+
"types": "./dist/types",
|
|
11
|
+
"files": [
|
|
12
|
+
"README.md",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "edenx build --tsconfig tsconfig.build.json",
|
|
20
|
+
"check-type": "rush check-type",
|
|
21
|
+
"lint": "eslint . --quiet",
|
|
22
|
+
"start": "rush storybook",
|
|
23
|
+
"test": "vitest",
|
|
24
|
+
"test:cov": "vitest run --coverage",
|
|
25
|
+
"test:update": "vitest run -u"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"clsx": "~2.0.0",
|
|
29
|
+
"hotkeys-js": "^3.8.1",
|
|
30
|
+
"picocolors": "1.0.0",
|
|
31
|
+
"react-dev-utils": "12.0.1",
|
|
32
|
+
"tailwind-merge": "~2.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react-reconciler": ">=0.26.6",
|
|
36
|
+
"@edenx/module-tools": "~1.35.1",
|
|
37
|
+
"@testing-library/react": "^12",
|
|
38
|
+
"@testing-library/react-hooks": "^8",
|
|
39
|
+
"@types/node": "^18.17.18",
|
|
40
|
+
"@types/react": "^17",
|
|
41
|
+
"eslint": "^8",
|
|
42
|
+
"react": "^18",
|
|
43
|
+
"typescript": "^4"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": ">=16.8.0"
|
|
47
|
+
}
|
|
48
|
+
}
|