@lark-apaas/miaoda-core 0.1.0-alpha.1 → 0.1.0-alpha.11
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/lib/components/AppContainer/IframeBridge.d.ts +1 -0
- package/lib/components/AppContainer/IframeBridge.js +38 -18
- package/lib/components/AppContainer/LogInterceptor.d.ts +1 -0
- package/lib/components/AppContainer/LogInterceptor.js +44 -0
- package/lib/components/AppContainer/PageHoc.js +28 -8
- package/lib/components/ErrorRender/index.js +5 -5
- package/lib/components/NotFoundRender/index.js +3 -3
- package/lib/components/SidebarNav/DrawerNav.d.ts +1 -1
- package/lib/components/SidebarNav/DropdownNav.d.ts +1 -1
- package/lib/components/SidebarNav/Sidebar.d.ts +1 -1
- package/lib/components/TopNav/BottomNav.d.ts +1 -1
- package/lib/components/TopNav/TopNav.d.ts +1 -1
- package/lib/components/User/UserWithAvatar.d.ts +1 -1
- package/lib/components/common/UserAvatarLayout.d.ts +1 -1
- package/lib/types/iframe-events.d.ts +37 -0
- package/lib/types/iframe-events.js +0 -0
- package/lib/utils/postMessage.d.ts +8 -0
- package/lib/utils/postMessage.js +11 -0
- package/package.json +20 -21
@@ -1,16 +1,17 @@
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
2
2
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
3
3
|
import { useLocation, useNavigate } from "react-router-dom";
|
4
|
-
import { getPreviewParentOrigin } from "../../utils/getParentOrigin.js";
|
5
4
|
import { useUpdatingRef } from "../../hooks/useUpdatingRef.js";
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
import { isIncomingMessage, postMessage } from "../../utils/postMessage.js";
|
6
|
+
import "./LogInterceptor.js";
|
7
|
+
var IframeBridge_RouteMessageType = /*#__PURE__*/ function(RouteMessageType) {
|
8
|
+
RouteMessageType["RouteChange"] = "RouteChange";
|
9
|
+
RouteMessageType["RouteBack"] = "RouteBack";
|
10
|
+
RouteMessageType["RouteForward"] = "RouteForward";
|
11
|
+
return RouteMessageType;
|
12
|
+
}(IframeBridge_RouteMessageType || {});
|
13
|
+
function isRouteMessageType(type) {
|
14
|
+
return Object.values(IframeBridge_RouteMessageType).includes(type);
|
14
15
|
}
|
15
16
|
function IframeBridge() {
|
16
17
|
const location = useLocation();
|
@@ -39,27 +40,46 @@ function IframeBridge() {
|
|
39
40
|
navigateRef
|
40
41
|
]);
|
41
42
|
useEffect(()=>{
|
42
|
-
|
43
|
-
type: 'PreviewReady'
|
44
|
-
|
43
|
+
postMessage({
|
44
|
+
type: 'PreviewReady',
|
45
|
+
data: {}
|
46
|
+
});
|
45
47
|
}, []);
|
46
48
|
useEffect(()=>{
|
47
49
|
if (isActive.current) {
|
48
50
|
isActive.current = false;
|
49
51
|
return;
|
50
52
|
}
|
51
|
-
|
53
|
+
postMessage({
|
52
54
|
type: 'ChildLocationChange',
|
53
55
|
data: location
|
54
|
-
}
|
56
|
+
});
|
55
57
|
}, [
|
56
58
|
location
|
57
59
|
]);
|
60
|
+
const handleGetRoutes = useUpdatingRef(async ()=>{
|
61
|
+
let routes = [
|
62
|
+
{
|
63
|
+
path: '/'
|
64
|
+
}
|
65
|
+
];
|
66
|
+
try {
|
67
|
+
const res = await fetch('/routes.json');
|
68
|
+
routes = await res.json();
|
69
|
+
} catch (error) {
|
70
|
+
console.warn('get routes.json error', error);
|
71
|
+
}
|
72
|
+
postMessage({
|
73
|
+
type: 'UpdateRoutes',
|
74
|
+
data: {
|
75
|
+
routes
|
76
|
+
}
|
77
|
+
});
|
78
|
+
});
|
58
79
|
const handleMessage = useCallback((event)=>{
|
59
|
-
const { data
|
60
|
-
|
61
|
-
if (
|
62
|
-
operatorMessage[type](data?.data);
|
80
|
+
const { data } = event;
|
81
|
+
if (isRouteMessageType(data?.type)) operatorMessage[data?.type](data?.data);
|
82
|
+
else if (isIncomingMessage(data, 'GetRoutes')) handleGetRoutes.current();
|
63
83
|
}, [
|
64
84
|
operatorMessage
|
65
85
|
]);
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { postMessage } from "../../utils/postMessage.js";
|
2
|
+
const PROXY_CONSOLE_METHOD = [
|
3
|
+
'log',
|
4
|
+
'info',
|
5
|
+
'warn',
|
6
|
+
'error'
|
7
|
+
];
|
8
|
+
const LOG_FILTER_PREFIX = [
|
9
|
+
'[Dataloom]',
|
10
|
+
'[MiaoDa]'
|
11
|
+
];
|
12
|
+
const initHandleError = ()=>{
|
13
|
+
window.onerror = (message, source, lineno, colno, error)=>{
|
14
|
+
const errorList = [];
|
15
|
+
if (error) errorList.push(error);
|
16
|
+
else {
|
17
|
+
if ('string' == typeof message && [
|
18
|
+
'Script error.'
|
19
|
+
].includes(message)) return;
|
20
|
+
if (message) errorList.push(message);
|
21
|
+
else if (source) errorList.push(source);
|
22
|
+
}
|
23
|
+
console.error('[MiaoDa]', ...errorList);
|
24
|
+
};
|
25
|
+
};
|
26
|
+
const initLogInterceptor = ()=>{
|
27
|
+
PROXY_CONSOLE_METHOD.forEach((method)=>{
|
28
|
+
const originalMethod = window.console[method];
|
29
|
+
window.console[method] = (...args)=>{
|
30
|
+
originalMethod(...args);
|
31
|
+
const log = args[0];
|
32
|
+
if ('string' == typeof log && LOG_FILTER_PREFIX.some((prefix)=>log.startsWith(prefix))) postMessage({
|
33
|
+
type: 'Console',
|
34
|
+
method,
|
35
|
+
data: args
|
36
|
+
});
|
37
|
+
};
|
38
|
+
});
|
39
|
+
};
|
40
|
+
function init() {
|
41
|
+
initHandleError();
|
42
|
+
initLogInterceptor();
|
43
|
+
}
|
44
|
+
'production' !== process.env.NODE_ENV && init();
|
@@ -1,17 +1,37 @@
|
|
1
1
|
import { Fragment, jsx } from "react/jsx-runtime";
|
2
2
|
import { useEffect } from "react";
|
3
3
|
import html2canvas_pro from "html2canvas-pro";
|
4
|
-
import {
|
4
|
+
import { postMessage } from "../../utils/postMessage.js";
|
5
5
|
function PageHoc(props) {
|
6
6
|
const { children } = props;
|
7
7
|
useEffect(()=>{
|
8
|
-
if ('production' !== process.env.NODE_ENV)
|
9
|
-
const
|
10
|
-
window.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
if ('production' !== process.env.NODE_ENV) setTimeout(()=>{
|
9
|
+
const viewportWidth = window.innerWidth;
|
10
|
+
const viewportHeight = window.innerHeight;
|
11
|
+
const devicePixelRatio = window.devicePixelRatio || 1;
|
12
|
+
const captureWidth = Math.min(viewportWidth, document.documentElement.scrollWidth);
|
13
|
+
const captureHeight = Math.min(viewportHeight, document.documentElement.scrollHeight);
|
14
|
+
html2canvas_pro(document.body, {
|
15
|
+
width: captureWidth,
|
16
|
+
height: captureHeight,
|
17
|
+
scrollX: window.scrollX,
|
18
|
+
scrollY: window.scrollY,
|
19
|
+
useCORS: true,
|
20
|
+
allowTaint: true,
|
21
|
+
backgroundColor: '#ffffff',
|
22
|
+
scale: devicePixelRatio,
|
23
|
+
windowWidth: viewportWidth,
|
24
|
+
windowHeight: viewportHeight
|
25
|
+
}).then((canvas)=>{
|
26
|
+
const base64 = canvas.toDataURL('image/png');
|
27
|
+
postMessage({
|
28
|
+
type: 'PageScreenshot',
|
29
|
+
data: base64
|
30
|
+
});
|
31
|
+
}).catch((error)=>{
|
32
|
+
console.error('截图失败:', error);
|
33
|
+
});
|
34
|
+
}, 1000);
|
15
35
|
}, []);
|
16
36
|
return /*#__PURE__*/ jsx(Fragment, {
|
17
37
|
children: children
|
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect } from "react";
|
3
3
|
import { useLocation } from "react-router-dom";
|
4
4
|
import { Button } from "antd";
|
5
|
-
import {
|
5
|
+
import { postMessage } from "../../utils/postMessage.js";
|
6
6
|
import { copyToClipboard } from "../../utils/copyToClipboard.js";
|
7
7
|
const RenderError = (props)=>{
|
8
8
|
const { error } = props;
|
@@ -21,19 +21,19 @@ const RenderError = (props)=>{
|
|
21
21
|
error
|
22
22
|
]);
|
23
23
|
const onClickRepair = useCallback(()=>{
|
24
|
-
|
24
|
+
postMessage({
|
25
25
|
type: 'RenderErrorRepair',
|
26
26
|
data: props.error
|
27
|
-
}
|
27
|
+
});
|
28
28
|
}, [
|
29
29
|
props
|
30
30
|
]);
|
31
31
|
useEffect(()=>{
|
32
|
-
if (props.error)
|
32
|
+
if (props.error) postMessage({
|
33
33
|
type: 'RenderError',
|
34
34
|
data: props.error,
|
35
35
|
location: location
|
36
|
-
}
|
36
|
+
});
|
37
37
|
}, [
|
38
38
|
props.error,
|
39
39
|
location
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
2
2
|
import { useLocation, useNavigate } from "react-router-dom";
|
3
3
|
import { useEffect } from "react";
|
4
|
-
import {
|
4
|
+
import { postMessage } from "../../utils/postMessage.js";
|
5
5
|
import { useUpdatingRef } from "../../hooks/useUpdatingRef.js";
|
6
6
|
import { logger } from "../../logger/index.js";
|
7
7
|
const NotFound = ()=>{
|
@@ -14,10 +14,10 @@ const NotFound = ()=>{
|
|
14
14
|
location.pathname
|
15
15
|
]);
|
16
16
|
const onClick = ()=>{
|
17
|
-
if ('production' !== process.env.NODE_ENV)
|
17
|
+
if ('production' !== process.env.NODE_ENV) postMessage({
|
18
18
|
type: 'CreatePage',
|
19
19
|
data: location.pathname
|
20
|
-
}
|
20
|
+
});
|
21
21
|
else navigateRef.current('/');
|
22
22
|
};
|
23
23
|
return /*#__PURE__*/ jsxs("div", {
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { BaseNavProps } from '../../types';
|
3
|
-
export default function DrawerNav({ navList, className, activeClassName }: BaseNavProps): React.JSX.Element;
|
3
|
+
export default function DrawerNav({ navList, className, activeClassName, }: BaseNavProps): React.JSX.Element;
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { BaseNavProps } from '../../types';
|
3
|
-
export default function DropdownNav({ navList, className, activeClassName }: BaseNavProps): React.JSX.Element;
|
3
|
+
export default function DropdownNav({ navList, className, activeClassName, }: BaseNavProps): React.JSX.Element;
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { NavProps } from '../../types';
|
3
|
-
export default function SidebarNav({ activeClassName, className, navList }: NavProps): React.JSX.Element;
|
3
|
+
export default function SidebarNav({ activeClassName, className, navList, }: NavProps): React.JSX.Element;
|
@@ -8,5 +8,5 @@ interface BottomNavProps extends BaseNavProps {
|
|
8
8
|
navList: NavItemProps[];
|
9
9
|
maxBottomItems?: number;
|
10
10
|
}
|
11
|
-
export declare function BottomNav({ navList, className, maxBottomItems }: BottomNavProps): React.JSX.Element;
|
11
|
+
export declare function BottomNav({ navList, className, maxBottomItems, }: BottomNavProps): React.JSX.Element;
|
12
12
|
export {};
|
@@ -7,4 +7,4 @@ import { BaseNavProps } from '../../types';
|
|
7
7
|
export interface TopNavProps extends BaseNavProps {
|
8
8
|
align?: 'left' | 'center' | 'right';
|
9
9
|
}
|
10
|
-
export declare function TopNav({ navList, align, className, activeClassName }: TopNavProps): React.JSX.Element;
|
10
|
+
export declare function TopNav({ navList, align, className, activeClassName, }: TopNavProps): React.JSX.Element;
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import type { UserWithAvatarProps } from './type';
|
3
|
-
export declare function UserWithAvatar({ data, size, mode, className }: UserWithAvatarProps): React.JSX.Element;
|
3
|
+
export declare function UserWithAvatar({ data, size, mode, className, }: UserWithAvatarProps): React.JSX.Element;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
export interface IframeMessage<T = unknown> {
|
2
|
+
type: string;
|
3
|
+
data: T;
|
4
|
+
}
|
5
|
+
export interface PreviewReadyMessage extends IframeMessage<Record<string, never>> {
|
6
|
+
type: 'PreviewReady';
|
7
|
+
}
|
8
|
+
export interface ConsoleMessage extends IframeMessage<Record<string, any>> {
|
9
|
+
method: string;
|
10
|
+
type: 'Console';
|
11
|
+
}
|
12
|
+
export interface ChildLocationChangeMessage extends IframeMessage<any> {
|
13
|
+
type: 'ChildLocationChange';
|
14
|
+
}
|
15
|
+
export interface CreatePageMessage extends IframeMessage<string> {
|
16
|
+
type: 'CreatePage';
|
17
|
+
}
|
18
|
+
export interface RenderErrorMessage extends IframeMessage<any> {
|
19
|
+
type: 'RenderError';
|
20
|
+
location?: any;
|
21
|
+
}
|
22
|
+
export interface RenderErrorRepairMessage extends IframeMessage<any> {
|
23
|
+
type: 'RenderErrorRepair';
|
24
|
+
}
|
25
|
+
export interface PageScreenshotMessage extends IframeMessage<string> {
|
26
|
+
type: 'PageScreenshot';
|
27
|
+
}
|
28
|
+
export interface UpdateRoutesMessage extends IframeMessage<{
|
29
|
+
routes: any[];
|
30
|
+
}> {
|
31
|
+
type: 'UpdateRoutes';
|
32
|
+
}
|
33
|
+
export type OutgoingMessage = PreviewReadyMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | UpdateRoutesMessage;
|
34
|
+
export interface GetRoutesMessage extends IframeMessage<Record<string, never>> {
|
35
|
+
type: 'GetRoutes';
|
36
|
+
}
|
37
|
+
export type IncomingMessage = GetRoutesMessage;
|
File without changes
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { IncomingMessage, OutgoingMessage } from '../types/iframe-events';
|
2
|
+
export declare function postMessage<T extends OutgoingMessage>(message: T, targetOrigin?: string): void;
|
3
|
+
export declare function isOutgoingMessage<T extends OutgoingMessage['type']>(msg: OutgoingMessage, type: T): msg is Extract<OutgoingMessage, {
|
4
|
+
type: T;
|
5
|
+
}>;
|
6
|
+
export declare function isIncomingMessage<T extends IncomingMessage['type']>(msg: IncomingMessage, type: T): msg is Extract<IncomingMessage, {
|
7
|
+
type: T;
|
8
|
+
}>;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { getPreviewParentOrigin } from "./getParentOrigin.js";
|
2
|
+
function postMessage(message, targetOrigin) {
|
3
|
+
window.parent.postMessage(message, targetOrigin ?? getPreviewParentOrigin());
|
4
|
+
}
|
5
|
+
function isOutgoingMessage(msg, type) {
|
6
|
+
return msg.type === type;
|
7
|
+
}
|
8
|
+
function isIncomingMessage(msg, type) {
|
9
|
+
return msg.type === type;
|
10
|
+
}
|
11
|
+
export { isIncomingMessage, isOutgoingMessage, postMessage };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lark-apaas/miaoda-core",
|
3
|
-
"version": "0.1.0-alpha.
|
3
|
+
"version": "0.1.0-alpha.11",
|
4
4
|
"types": "./lib/index.d.ts",
|
5
5
|
"main": "./lib/index.js",
|
6
6
|
"files": [
|
@@ -56,25 +56,9 @@
|
|
56
56
|
"types": "./lib/apis/utils/*.d.ts"
|
57
57
|
}
|
58
58
|
},
|
59
|
-
"scripts": {
|
60
|
-
"tsc": "tsc --declaration",
|
61
|
-
"build": "rslib build",
|
62
|
-
"build:storybook": "storybook build",
|
63
|
-
"bump": "changeset version",
|
64
|
-
"change": "changeset",
|
65
|
-
"check": "biome check --write",
|
66
|
-
"dev": "rslib build --watch",
|
67
|
-
"format": "biome format --write",
|
68
|
-
"storybook": "storybook dev",
|
69
|
-
"test": "echo 0",
|
70
|
-
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
|
71
|
-
"lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
|
72
|
-
"prepublishOnly": "npm run build"
|
73
|
-
},
|
74
59
|
"dependencies": {
|
75
60
|
"@ant-design/colors": "^7.2.1",
|
76
61
|
"@ant-design/cssinjs": "^1.24.0",
|
77
|
-
"@lark-apaas/miaoda-inspector": "workspace:*",
|
78
62
|
"@data-loom/js": "0.2.3",
|
79
63
|
"clsx": "~2.0.1",
|
80
64
|
"dayjs": "^1.11.13",
|
@@ -84,7 +68,8 @@
|
|
84
68
|
"sonner": "~2.0.0",
|
85
69
|
"tailwind-merge": "~2.0.0",
|
86
70
|
"tailwind-variants": "0.3.1",
|
87
|
-
"tailwindcss-animate": "^1.0.7"
|
71
|
+
"tailwindcss-animate": "^1.0.7",
|
72
|
+
"@lark-apaas/miaoda-inspector": "0.1.0-alpha.5"
|
88
73
|
},
|
89
74
|
"devDependencies": {
|
90
75
|
"@biomejs/biome": "2.0.6",
|
@@ -105,10 +90,11 @@
|
|
105
90
|
"@types/node": "^22.10.2",
|
106
91
|
"@types/react": "^18.3.23",
|
107
92
|
"@types/react-dom": "^18.3.7",
|
93
|
+
"typescript-eslint": "^8.41.0",
|
108
94
|
"antd": "^5.26.6",
|
109
95
|
"eslint": "^8.57.0",
|
110
96
|
"jsdom": "^26.1.0",
|
111
|
-
"lucide-react": "
|
97
|
+
"lucide-react": "npm:@lark-apaas/lucide-react@0.1.0-alpha.5",
|
112
98
|
"react": "^18.3.1",
|
113
99
|
"react-dom": "^18.3.1",
|
114
100
|
"react-router-dom": "^6.26.2",
|
@@ -122,9 +108,22 @@
|
|
122
108
|
},
|
123
109
|
"peerDependencies": {
|
124
110
|
"antd": ">=5.26.6",
|
125
|
-
"lucide-react": "^0.541.0",
|
126
111
|
"react": ">=16.14.0",
|
127
112
|
"react-dom": ">=16.14.0",
|
128
113
|
"react-router-dom": ">=6.26.2"
|
114
|
+
},
|
115
|
+
"scripts": {
|
116
|
+
"tsc": "tsc --declaration",
|
117
|
+
"build": "rslib build",
|
118
|
+
"build:storybook": "storybook build",
|
119
|
+
"bump": "changeset version",
|
120
|
+
"change": "changeset",
|
121
|
+
"check": "biome check --write",
|
122
|
+
"dev": "rslib build --watch",
|
123
|
+
"format": "biome format --write",
|
124
|
+
"storybook": "storybook dev",
|
125
|
+
"test": "echo 0",
|
126
|
+
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
|
127
|
+
"lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix"
|
129
128
|
}
|
130
|
-
}
|
129
|
+
}
|