@lark-apaas/miaoda-core 0.1.0-alpha.10 → 0.1.0-alpha.12
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/apis/hooks/useCurrentAppInfo.d.ts +1 -0
- package/lib/apis/hooks/useCurrentAppInfo.js +1 -0
- package/lib/components/AppContainer/IframeBridge.d.ts +1 -0
- package/lib/components/AppContainer/IframeBridge.js +40 -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/AppContainer/index.js +1 -1
- package/lib/components/ErrorRender/index.js +5 -5
- package/lib/components/NotFoundRender/index.js +3 -3
- package/lib/components/TopNav/TitleBar.js +2 -2
- package/lib/components/TopNav/TopNav.js +2 -2
- package/lib/components/common/LogoInfo.js +2 -2
- package/lib/components/theme/ThemeProvider.d.ts +2 -2
- package/lib/components/theme/ThemeProvider.js +3 -3
- package/lib/components/theme/constants.d.ts +1 -1
- package/lib/components/theme/constants.js +1 -2
- package/lib/components/theme/util.d.ts +3 -3
- package/lib/components/theme/util.js +2 -2
- package/lib/hooks/index.d.ts +1 -1
- package/lib/hooks/index.js +1 -1
- package/lib/hooks/{useAppInfo.d.ts → useCurrentAppInfo.d.ts} +1 -1
- package/lib/hooks/{useAppInfo.js → useCurrentAppInfo.js} +2 -2
- package/lib/tailwind-theme.css +4 -5
- 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/lib/utils/utils.d.ts +6 -0
- package/lib/utils/utils.js +5 -1
- package/package.json +3 -2
- package/lib/apis/hooks/useAppInfo.d.ts +0 -1
- package/lib/apis/hooks/useAppInfo.js +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
export * from '../../hooks/useCurrentAppInfo';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "../../hooks/useCurrentAppInfo.js";
|
@@ -1,16 +1,18 @@
|
|
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
|
-
return
|
5
|
+
import { isIncomingMessage, postMessage } from "../../utils/postMessage.js";
|
6
|
+
import { normalizeBasePath } from "../../utils/utils.js";
|
7
|
+
import "./LogInterceptor.js";
|
8
|
+
var IframeBridge_RouteMessageType = /*#__PURE__*/ function(RouteMessageType) {
|
9
|
+
RouteMessageType["RouteChange"] = "RouteChange";
|
10
|
+
RouteMessageType["RouteBack"] = "RouteBack";
|
11
|
+
RouteMessageType["RouteForward"] = "RouteForward";
|
12
|
+
return RouteMessageType;
|
13
|
+
}(IframeBridge_RouteMessageType || {});
|
14
|
+
function isRouteMessageType(type) {
|
15
|
+
return Object.values(IframeBridge_RouteMessageType).includes(type);
|
14
16
|
}
|
15
17
|
function IframeBridge() {
|
16
18
|
const location = useLocation();
|
@@ -39,27 +41,47 @@ function IframeBridge() {
|
|
39
41
|
navigateRef
|
40
42
|
]);
|
41
43
|
useEffect(()=>{
|
42
|
-
|
43
|
-
type: 'PreviewReady'
|
44
|
-
|
44
|
+
postMessage({
|
45
|
+
type: 'PreviewReady',
|
46
|
+
data: {}
|
47
|
+
});
|
45
48
|
}, []);
|
46
49
|
useEffect(()=>{
|
47
50
|
if (isActive.current) {
|
48
51
|
isActive.current = false;
|
49
52
|
return;
|
50
53
|
}
|
51
|
-
|
54
|
+
postMessage({
|
52
55
|
type: 'ChildLocationChange',
|
53
56
|
data: location
|
54
|
-
}
|
57
|
+
});
|
55
58
|
}, [
|
56
59
|
location
|
57
60
|
]);
|
61
|
+
const handleGetRoutes = useUpdatingRef(async ()=>{
|
62
|
+
let routes = [
|
63
|
+
{
|
64
|
+
path: '/'
|
65
|
+
}
|
66
|
+
];
|
67
|
+
try {
|
68
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
69
|
+
const res = await fetch(`${basePath}/routes.json`);
|
70
|
+
routes = await res.json();
|
71
|
+
} catch (error) {
|
72
|
+
console.warn('get routes.json error', error);
|
73
|
+
}
|
74
|
+
postMessage({
|
75
|
+
type: 'UpdateRoutes',
|
76
|
+
data: {
|
77
|
+
routes
|
78
|
+
}
|
79
|
+
});
|
80
|
+
});
|
58
81
|
const handleMessage = useCallback((event)=>{
|
59
|
-
const { data
|
60
|
-
|
61
|
-
if (
|
62
|
-
operatorMessage[type](data?.data);
|
82
|
+
const { data } = event;
|
83
|
+
if (isRouteMessageType(data?.type)) operatorMessage[data?.type](data?.data);
|
84
|
+
else if (isIncomingMessage(data, 'GetRoutes')) handleGetRoutes.current();
|
63
85
|
}, [
|
64
86
|
operatorMessage
|
65
87
|
]);
|
@@ -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
|
@@ -13,7 +13,7 @@ registerDayjsPlugins();
|
|
13
13
|
const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
|
14
14
|
const App = (props)=>{
|
15
15
|
const { themeMeta = {} } = props;
|
16
|
-
const { rem } = findValueByPixel(themeMetaOptions.themeRadius
|
16
|
+
const { rem } = findValueByPixel(`${themeMeta.borderRadius}`, themeMetaOptions.themeRadius) || {
|
17
17
|
rem: '0.625'
|
18
18
|
};
|
19
19
|
const radiusToken = generateTailwindRadiusToken(Number(rem));
|
@@ -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", {
|
@@ -3,7 +3,7 @@ import { useMemo, useState } from "react";
|
|
3
3
|
import { Link, matchPath, useLocation } from "react-router-dom";
|
4
4
|
import { LogOut, MoreHorizontal, X } from "lucide-react";
|
5
5
|
import { clsxWithTw } from "../../utils/utils.js";
|
6
|
-
import {
|
6
|
+
import { useCurrentAppInfo, useCurrentUserProfile, useLogout } from "../../hooks/index.js";
|
7
7
|
import { DropdownThemeClass, MaskThemeClass, TopHeaderThemeClass } from "../common/index.js";
|
8
8
|
const TitleBar = ({ navList, className })=>{
|
9
9
|
const { pathname } = useLocation();
|
@@ -17,7 +17,7 @@ const TitleBar = ({ navList, className })=>{
|
|
17
17
|
navList,
|
18
18
|
pathname
|
19
19
|
]);
|
20
|
-
const { appName, appLogo } =
|
20
|
+
const { appName, appLogo } = useCurrentAppInfo();
|
21
21
|
const { name: userName, avatar: userAvatar } = useCurrentUserProfile();
|
22
22
|
const { handlerLogout } = useLogout();
|
23
23
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
@@ -3,13 +3,13 @@ import { useRef, useState } from "react";
|
|
3
3
|
import { Menu, X } from "lucide-react";
|
4
4
|
import { Link } from "react-router-dom";
|
5
5
|
import { clsxWithTw } from "../../utils/utils.js";
|
6
|
-
import {
|
6
|
+
import { useCurrentAppInfo } from "../../hooks/useCurrentAppInfo.js";
|
7
7
|
import { useCurrentUserProfile } from "../../hooks/useCurrentUserProfile.js";
|
8
8
|
import { DropdownThemeClass, NavMenu, TopHeaderThemeClass, UserAvatarMenu } from "../common/index.js";
|
9
9
|
function TopNav({ navList = [], align = 'left', className, activeClassName }) {
|
10
10
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
11
11
|
const navRef = useRef(null);
|
12
|
-
const { appName, appLogo } =
|
12
|
+
const { appName, appLogo } = useCurrentAppInfo();
|
13
13
|
const { avatar: userAvatar } = useCurrentUserProfile();
|
14
14
|
return /*#__PURE__*/ jsxs("header", {
|
15
15
|
ref: navRef,
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
2
2
|
import "react";
|
3
3
|
import { Link } from "react-router-dom";
|
4
|
-
import {
|
4
|
+
import { useCurrentAppInfo } from "../../hooks/useCurrentAppInfo.js";
|
5
5
|
import { clsxWithTw } from "../../utils/utils.js";
|
6
6
|
function LogoInfo({ className, logoClassName }) {
|
7
|
-
const { name, avatar } =
|
7
|
+
const { name, avatar } = useCurrentAppInfo();
|
8
8
|
return /*#__PURE__*/ jsx("div", {
|
9
9
|
className: clsxWithTw('overflow-hidden text-ellipsis whitespace-nowrap', className),
|
10
10
|
children: /*#__PURE__*/ jsxs(Link, {
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { type ReactNode } from 'react';
|
3
3
|
import type { ITheme } from '../../types';
|
4
|
-
import {
|
4
|
+
import { IThemeMeta } from './util';
|
5
5
|
export interface IBaseThemeProviderProps {
|
6
6
|
defaultTheme?: ITheme;
|
7
|
-
themeMeta?: Partial<
|
7
|
+
themeMeta?: Partial<IThemeMeta>;
|
8
8
|
}
|
9
9
|
interface ThemeProviderProps extends IBaseThemeProviderProps {
|
10
10
|
children: ReactNode;
|
@@ -22,13 +22,13 @@ function ThemeProvider({ children, defaultTheme = 'light', themeMeta = {}, enabl
|
|
22
22
|
useEffect(()=>{
|
23
23
|
const root = window.document.documentElement;
|
24
24
|
if (void 0 !== themeMeta.spacing) {
|
25
|
-
const { rem } = findValueByPixel(themeMetaOptions.themeSpaces
|
25
|
+
const { rem } = findValueByPixel(`${themeMeta.spacing}`, themeMetaOptions.themeSpaces) || {
|
26
26
|
rem: '0.25'
|
27
27
|
};
|
28
28
|
root.style.setProperty('--spacing', `${rem}rem`);
|
29
29
|
}
|
30
30
|
if (void 0 !== themeMeta.borderRadius) {
|
31
|
-
const { rem } = findValueByPixel(themeMetaOptions.themeRadius
|
31
|
+
const { rem } = findValueByPixel(`${themeMeta.borderRadius}`, themeMetaOptions.themeRadius) || {
|
32
32
|
rem: '0.625'
|
33
33
|
};
|
34
34
|
root.style.setProperty('--radius', `${rem}rem`);
|
@@ -44,7 +44,7 @@ function ThemeProvider({ children, defaultTheme = 'light', themeMeta = {}, enabl
|
|
44
44
|
}
|
45
45
|
};
|
46
46
|
const antdTheme = useMemo(()=>{
|
47
|
-
const res = findValueByPixel(themeMetaOptions.themeSpaces
|
47
|
+
const res = findValueByPixel(`${themeMeta.spacing}`, themeMetaOptions.themeSpaces) || {
|
48
48
|
pixel: '36',
|
49
49
|
rem: '0.25',
|
50
50
|
size: {
|
@@ -41,7 +41,7 @@ type ThemeColorTokenMap = {
|
|
41
41
|
};
|
42
42
|
export declare const themeColorTokenMap: ThemeColorTokenMap;
|
43
43
|
export declare function getKeyByColor(colorValue: string, theme: keyof ThemeColorTokenMap): string;
|
44
|
-
export declare function findValueByPixel(themeSpaces: typeof themeMetaOptions.themeSpaces | typeof themeMetaOptions.themeRadius
|
44
|
+
export declare function findValueByPixel(pixelValue: string, themeSpaces: typeof themeMetaOptions.themeSpaces | typeof themeMetaOptions.themeRadius): {
|
45
45
|
pixel: string;
|
46
46
|
rem: string;
|
47
47
|
};
|
@@ -550,8 +550,7 @@ function getKeyByColor(colorValue, theme) {
|
|
550
550
|
const colorMap = themeColorTokenMap[theme];
|
551
551
|
return Object.keys(colorMap).find((key)=>colorMap[key] === colorValue) || '';
|
552
552
|
}
|
553
|
-
function findValueByPixel(
|
554
|
-
if (!pixelValue) return;
|
553
|
+
function findValueByPixel(pixelValue, themeSpaces) {
|
555
554
|
return themeSpaces.options.find((option)=>option.value.pixel === pixelValue)?.value;
|
556
555
|
}
|
557
556
|
export { findValueByPixel, getKeyByColor, themeColorTokenMap, themeMetaOptions, themeTailwindRadius };
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { type ThemeConfig } from 'antd';
|
2
2
|
import { UIComponentConfig } from './ui-config';
|
3
3
|
export type IThemeMode = 'dark' | 'light' | 'system';
|
4
|
-
export interface
|
4
|
+
export interface IThemeMeta {
|
5
5
|
/**
|
6
6
|
* 品牌色
|
7
7
|
*/
|
@@ -16,5 +16,5 @@ export interface IThemeTokenMeta {
|
|
16
16
|
spacing: number;
|
17
17
|
}
|
18
18
|
export declare const generateTailwindRadiusToken: (radiusRemValue: number) => UIComponentConfig;
|
19
|
-
export declare function generateLightTheme(override?: Partial<
|
20
|
-
export declare function generateDarkTheme(override?: Partial<
|
19
|
+
export declare function generateLightTheme(override?: Partial<IThemeMeta>): ThemeConfig;
|
20
|
+
export declare function generateDarkTheme(override?: Partial<IThemeMeta>): ThemeConfig;
|
@@ -169,7 +169,7 @@ function generateLightTheme(override) {
|
|
169
169
|
token: {
|
170
170
|
...defaultLightTheme.token,
|
171
171
|
...generateColorPrimaryToken(override?.colorPrimary || lightColorPrimary, 'light'),
|
172
|
-
...generateBorderRadiusTokenSyncTailwind(override?.borderRadius),
|
172
|
+
...generateBorderRadiusTokenSyncTailwind(override?.borderRadius || 4),
|
173
173
|
...generateSpacingToken(override)
|
174
174
|
}
|
175
175
|
};
|
@@ -180,7 +180,7 @@ function generateDarkTheme(override) {
|
|
180
180
|
token: {
|
181
181
|
...defaultDarkTheme.token,
|
182
182
|
...generateColorPrimaryToken(override?.colorPrimary || darkColorPrimary, 'dark'),
|
183
|
-
...generateBorderRadiusTokenSyncTailwind(override?.borderRadius),
|
183
|
+
...generateBorderRadiusTokenSyncTailwind(override?.borderRadius || 4),
|
184
184
|
...generateSpacingToken(override)
|
185
185
|
}
|
186
186
|
};
|
package/lib/hooks/index.d.ts
CHANGED
package/lib/hooks/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { useEffect, useState } from "react";
|
2
2
|
import { getAppInfo } from "../integrations/getAppInfo.js";
|
3
|
-
const
|
3
|
+
const useCurrentAppInfo = ()=>{
|
4
4
|
const [appInfo, setAppInfo] = useState(()=>getAppInfo());
|
5
5
|
useEffect(()=>{
|
6
6
|
const handleMetaInfoChanged = ()=>{
|
@@ -17,4 +17,4 @@ const useAppInfo = ()=>{
|
|
17
17
|
appLogo: appInfo.avatar
|
18
18
|
};
|
19
19
|
};
|
20
|
-
export {
|
20
|
+
export { useCurrentAppInfo };
|
package/lib/tailwind-theme.css
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
@
|
2
|
-
|
3
|
-
}
|
4
|
-
|
5
|
-
@layer antd;
|
1
|
+
@import "tailwindcss";
|
2
|
+
@layer theme;
|
6
3
|
|
7
4
|
@layer base {
|
8
5
|
:root {
|
@@ -420,6 +417,8 @@
|
|
420
417
|
}
|
421
418
|
}
|
422
419
|
|
420
|
+
@layer components, utilities;
|
421
|
+
|
423
422
|
@source inline("text-{xs,sm,base,lg,xl,2xl,3xl,4xl,5xl,6xl,7xl,8xl,9xl}");
|
424
423
|
|
425
424
|
@source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}-{50,{100..900..100},950}");
|
@@ -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 type { 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/lib/utils/utils.d.ts
CHANGED
@@ -9,3 +9,9 @@ export declare function clsxWithTw(...inputs: ClassValue[]): string;
|
|
9
9
|
* 当前是否是预览态
|
10
10
|
*/
|
11
11
|
export declare function isPreview(): boolean;
|
12
|
+
/**
|
13
|
+
* @internal
|
14
|
+
* 标准化基础路径,确保路径格式一致
|
15
|
+
* 移除末尾的斜杠,确保路径不以斜杠结尾
|
16
|
+
*/
|
17
|
+
export declare function normalizeBasePath(basePath?: string): string;
|
package/lib/utils/utils.js
CHANGED
@@ -6,4 +6,8 @@ function clsxWithTw(...inputs) {
|
|
6
6
|
function isPreview() {
|
7
7
|
return window.IS_MIAODA_PREVIEW;
|
8
8
|
}
|
9
|
-
|
9
|
+
function normalizeBasePath(basePath) {
|
10
|
+
if (!basePath || '/' === basePath) return '';
|
11
|
+
return basePath.replace(/\/+$/, '');
|
12
|
+
}
|
13
|
+
export { clsxWithTw, isPreview, normalizeBasePath };
|
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.12",
|
4
4
|
"types": "./lib/index.d.ts",
|
5
5
|
"main": "./lib/index.js",
|
6
6
|
"files": [
|
@@ -76,7 +76,7 @@
|
|
76
76
|
"@changesets/cli": "^2.29.5",
|
77
77
|
"@rsbuild/core": "~1.4.13",
|
78
78
|
"@rsbuild/plugin-react": "^1.3.4",
|
79
|
-
"@rslib/core": "^0.
|
79
|
+
"@rslib/core": "^0.12.0",
|
80
80
|
"@storybook/addon-essentials": "^8.6.14",
|
81
81
|
"@storybook/addon-interactions": "^8.6.14",
|
82
82
|
"@storybook/addon-links": "^8.6.14",
|
@@ -90,6 +90,7 @@
|
|
90
90
|
"@types/node": "^22.10.2",
|
91
91
|
"@types/react": "^18.3.23",
|
92
92
|
"@types/react-dom": "^18.3.7",
|
93
|
+
"typescript-eslint": "^8.41.0",
|
93
94
|
"antd": "^5.26.6",
|
94
95
|
"eslint": "^8.57.0",
|
95
96
|
"jsdom": "^26.1.0",
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from '../../hooks/useAppInfo';
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from "../../hooks/useAppInfo.js";
|