@lark-apaas/miaoda-core 0.1.0-alpha.10 → 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.
Files changed (31) hide show
  1. package/lib/apis/hooks/useCurrentAppInfo.d.ts +1 -0
  2. package/lib/apis/hooks/useCurrentAppInfo.js +1 -0
  3. package/lib/components/AppContainer/IframeBridge.d.ts +1 -0
  4. package/lib/components/AppContainer/IframeBridge.js +38 -18
  5. package/lib/components/AppContainer/LogInterceptor.d.ts +1 -0
  6. package/lib/components/AppContainer/LogInterceptor.js +44 -0
  7. package/lib/components/AppContainer/PageHoc.js +28 -8
  8. package/lib/components/AppContainer/index.js +1 -1
  9. package/lib/components/ErrorRender/index.js +5 -5
  10. package/lib/components/NotFoundRender/index.js +3 -3
  11. package/lib/components/TopNav/TitleBar.js +2 -2
  12. package/lib/components/TopNav/TopNav.js +2 -2
  13. package/lib/components/common/LogoInfo.js +2 -2
  14. package/lib/components/theme/ThemeProvider.d.ts +2 -2
  15. package/lib/components/theme/ThemeProvider.js +3 -3
  16. package/lib/components/theme/constants.d.ts +1 -1
  17. package/lib/components/theme/constants.js +1 -2
  18. package/lib/components/theme/util.d.ts +3 -3
  19. package/lib/components/theme/util.js +2 -2
  20. package/lib/hooks/index.d.ts +1 -1
  21. package/lib/hooks/index.js +1 -1
  22. package/lib/hooks/{useAppInfo.d.ts → useCurrentAppInfo.d.ts} +1 -1
  23. package/lib/hooks/{useAppInfo.js → useCurrentAppInfo.js} +2 -2
  24. package/lib/tailwind-theme.css +4 -5
  25. package/lib/types/iframe-events.d.ts +37 -0
  26. package/lib/types/iframe-events.js +0 -0
  27. package/lib/utils/postMessage.d.ts +8 -0
  28. package/lib/utils/postMessage.js +11 -0
  29. package/package.json +3 -2
  30. package/lib/apis/hooks/useAppInfo.d.ts +0 -1
  31. 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,2 +1,3 @@
1
1
  import React from 'react';
2
+ import './LogInterceptor';
2
3
  export default function IframeBridge(): React.JSX.Element;
@@ -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
- var IframeBridge_MessageType = /*#__PURE__*/ function(MessageType) {
7
- MessageType["RouteChange"] = "RouteChange";
8
- MessageType["RouteBack"] = "RouteBack";
9
- MessageType["RouteForward"] = "RouteForward";
10
- return MessageType;
11
- }(IframeBridge_MessageType || {});
12
- function isMessageType(type) {
13
- return Object.values(IframeBridge_MessageType).includes(type);
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
- window.parent.postMessage({
43
- type: 'PreviewReady'
44
- }, getPreviewParentOrigin());
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
- window.parent.postMessage({
53
+ postMessage({
52
54
  type: 'ChildLocationChange',
53
55
  data: location
54
- }, getPreviewParentOrigin());
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: { data } } = event;
60
- const type = data?.type;
61
- if (!isMessageType(type)) return;
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 { getPreviewParentOrigin } from "../../utils/getParentOrigin.js";
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) html2canvas_pro(document.body).then((canvas)=>{
9
- const base64 = canvas.toDataURL('image/png');
10
- window.parent.postMessage({
11
- type: 'PageScreenshot',
12
- data: base64
13
- }, getPreviewParentOrigin());
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, themeMeta.borderRadius) || {
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 { getPreviewParentOrigin } from "../../utils/getParentOrigin.js";
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
- window.parent.postMessage({
24
+ postMessage({
25
25
  type: 'RenderErrorRepair',
26
26
  data: props.error
27
- }, getPreviewParentOrigin());
27
+ });
28
28
  }, [
29
29
  props
30
30
  ]);
31
31
  useEffect(()=>{
32
- if (props.error) window.parent.postMessage({
32
+ if (props.error) postMessage({
33
33
  type: 'RenderError',
34
34
  data: props.error,
35
35
  location: location
36
- }, getPreviewParentOrigin());
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 { getPreviewParentOrigin } from "../../utils/getParentOrigin.js";
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) window.parent.postMessage({
17
+ if ('production' !== process.env.NODE_ENV) postMessage({
18
18
  type: 'CreatePage',
19
19
  data: location.pathname
20
- }, getPreviewParentOrigin());
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 { useAppInfo, useCurrentUserProfile, useLogout } from "../../hooks/index.js";
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 } = useAppInfo();
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 { useAppInfo } from "../../hooks/useAppInfo.js";
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 } = useAppInfo();
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 { useAppInfo } from "../../hooks/useAppInfo.js";
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 } = useAppInfo();
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 { IThemeTokenMeta } from './util';
4
+ import { IThemeMeta } from './util';
5
5
  export interface IBaseThemeProviderProps {
6
6
  defaultTheme?: ITheme;
7
- themeMeta?: Partial<IThemeTokenMeta>;
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, themeMeta.spacing) || {
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, themeMeta.borderRadius) || {
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, themeMeta.spacing) || {
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, pixelValue?: string | number): {
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(themeSpaces, pixelValue) {
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 IThemeTokenMeta {
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<IThemeTokenMeta>): ThemeConfig;
20
- export declare function generateDarkTheme(override?: Partial<IThemeTokenMeta>): ThemeConfig;
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
  };
@@ -1,4 +1,4 @@
1
- export * from './useAppInfo';
1
+ export * from './useCurrentAppInfo';
2
2
  export * from './useCurrentUserProfile';
3
3
  export * from './useIsMobile';
4
4
  export * from './useLogout';
@@ -1,4 +1,4 @@
1
- export * from "./useAppInfo.js";
1
+ export * from "./useCurrentAppInfo.js";
2
2
  export * from "./useCurrentUserProfile.js";
3
3
  export * from "./useIsMobile.js";
4
4
  export * from "./useLogout.js";
@@ -1,4 +1,4 @@
1
- export declare const useAppInfo: () => {
1
+ export declare const useCurrentAppInfo: () => {
2
2
  appName: string;
3
3
  appLogo: string;
4
4
  name?: string;
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from "react";
2
2
  import { getAppInfo } from "../integrations/getAppInfo.js";
3
- const useAppInfo = ()=>{
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 { useAppInfo };
20
+ export { useCurrentAppInfo };
@@ -1,8 +1,5 @@
1
- @layer tailwind-base {
2
- @import "tailwindcss";
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 { 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.10",
3
+ "version": "0.1.0-alpha.11",
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.13.2",
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";