@lark-apaas/miaoda-core 0.1.0-alpha.2 → 0.1.0-alpha.21
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/dataloom.d.ts +1 -1
- package/lib/apis/dataloom.js +2 -2
- package/lib/apis/hooks/useAppInfo.d.ts +1 -0
- package/lib/apis/hooks/useAppInfo.js +1 -0
- package/lib/components/AppContainer/IframeBridge.d.ts +1 -0
- package/lib/components/AppContainer/IframeBridge.js +31 -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/childApi.d.ts +5 -0
- package/lib/components/AppContainer/childApi.js +20 -0
- 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/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/TitleBar.js +6 -3
- package/lib/components/TopNav/TopNav.d.ts +1 -1
- package/lib/components/TopNav/TopNav.js +2 -2
- package/lib/components/User/UserDisplay.d.ts +1 -1
- package/lib/components/User/UserSelect.js +2 -1
- package/lib/components/User/UserWithAvatar.d.ts +1 -1
- package/lib/components/common/LogoInfo.js +2 -2
- package/lib/components/common/UserAvatarLayout.d.ts +1 -1
- 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 +2 -1
- package/lib/components/theme/ui-config.d.ts +1 -49
- package/lib/components/theme/ui-config.js +1 -757
- 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/{useCurrentAppInfo.d.ts → useAppInfo.d.ts} +1 -1
- package/lib/hooks/{useCurrentAppInfo.js → useAppInfo.js} +6 -5
- package/lib/hooks/useCurrentUserProfile.js +34 -2
- package/lib/hooks/useLogout.js +14 -0
- package/lib/index.css +1 -0
- package/lib/inspector.dev.css +10 -0
- package/lib/integrations/dataloom.d.ts +2 -1
- package/lib/integrations/dataloom.js +22 -8
- package/lib/integrations/generateImage.js +17 -2
- package/lib/integrations/generateTextStream.d.ts +0 -5
- package/lib/integrations/generateTextStream.js +24 -9
- package/lib/integrations/getAppInfo.d.ts +1 -1
- package/lib/integrations/getAppInfo.js +12 -2
- package/lib/tailwind-theme.css +1 -101
- package/lib/theme-layer.css +3 -0
- package/lib/types/common.d.ts +0 -7
- package/lib/types/iframe-events.d.ts +45 -0
- package/lib/types/iframe-events.js +0 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/utils/getAppId.d.ts +1 -6
- package/lib/utils/getAppId.js +4 -2
- package/lib/utils/getCsrfToken.d.ts +5 -0
- package/lib/utils/getCsrfToken.js +10 -0
- package/lib/utils/getInitialInfo.d.ts +20 -0
- package/lib/utils/getInitialInfo.js +32 -0
- package/lib/utils/getParentOrigin.js +2 -2
- package/lib/utils/getUserProfile.js +7 -1
- package/lib/utils/postMessage.d.ts +8 -0
- package/lib/utils/postMessage.js +11 -0
- package/lib/utils/utils.d.ts +8 -0
- package/lib/utils/utils.js +8 -1
- package/package.json +9 -7
- package/lib/apis/hooks/useCurrentAppInfo.d.ts +0 -1
- package/lib/apis/hooks/useCurrentAppInfo.js +0 -1
package/lib/apis/dataloom.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export {
|
1
|
+
export { getDataloom } from '../integrations/dataloom';
|
package/lib/apis/dataloom.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import {
|
2
|
-
export {
|
1
|
+
import { getDataloom } from "../integrations/dataloom.js";
|
2
|
+
export { getDataloom };
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from '../../hooks/useAppInfo';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "../../hooks/useAppInfo.js";
|
@@ -1,16 +1,29 @@
|
|
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 {
|
4
|
+
import { connectToParent } from "penpal";
|
5
5
|
import { useUpdatingRef } from "../../hooks/useUpdatingRef.js";
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
import { postMessage } from "../../utils/postMessage.js";
|
7
|
+
import { getPreviewParentOrigin } from "../../utils/getParentOrigin.js";
|
8
|
+
import { childApi } from "./childApi.js";
|
9
|
+
import "./LogInterceptor.js";
|
10
|
+
var IframeBridge_RouteMessageType = /*#__PURE__*/ function(RouteMessageType) {
|
11
|
+
RouteMessageType["RouteChange"] = "RouteChange";
|
12
|
+
RouteMessageType["RouteBack"] = "RouteBack";
|
13
|
+
RouteMessageType["RouteForward"] = "RouteForward";
|
14
|
+
return RouteMessageType;
|
15
|
+
}(IframeBridge_RouteMessageType || {});
|
16
|
+
function isRouteMessageType(type) {
|
17
|
+
return Object.values(IframeBridge_RouteMessageType).includes(type);
|
18
|
+
}
|
19
|
+
async function connectParent() {
|
20
|
+
const connection = connectToParent({
|
21
|
+
parentOrigin: getPreviewParentOrigin(),
|
22
|
+
methods: {
|
23
|
+
...childApi
|
24
|
+
}
|
25
|
+
});
|
26
|
+
await connection.promise;
|
14
27
|
}
|
15
28
|
function IframeBridge() {
|
16
29
|
const location = useLocation();
|
@@ -39,27 +52,27 @@ function IframeBridge() {
|
|
39
52
|
navigateRef
|
40
53
|
]);
|
41
54
|
useEffect(()=>{
|
42
|
-
|
43
|
-
type: 'PreviewReady'
|
44
|
-
|
55
|
+
postMessage({
|
56
|
+
type: 'PreviewReady',
|
57
|
+
data: {}
|
58
|
+
});
|
59
|
+
connectParent();
|
45
60
|
}, []);
|
46
61
|
useEffect(()=>{
|
47
62
|
if (isActive.current) {
|
48
63
|
isActive.current = false;
|
49
64
|
return;
|
50
65
|
}
|
51
|
-
|
66
|
+
postMessage({
|
52
67
|
type: 'ChildLocationChange',
|
53
68
|
data: location
|
54
|
-
}
|
69
|
+
});
|
55
70
|
}, [
|
56
71
|
location
|
57
72
|
]);
|
58
73
|
const handleMessage = useCallback((event)=>{
|
59
|
-
const { data
|
60
|
-
|
61
|
-
if (!isMessageType(type)) return;
|
62
|
-
operatorMessage[type](data?.data);
|
74
|
+
const { data } = event;
|
75
|
+
if (isRouteMessageType(data?.type)) operatorMessage[data?.type](data?.data);
|
63
76
|
}, [
|
64
77
|
operatorMessage
|
65
78
|
]);
|
@@ -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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { normalizeBasePath } from "../../utils/utils.js";
|
2
|
+
async function getRoutes() {
|
3
|
+
let routes = [
|
4
|
+
{
|
5
|
+
path: '/'
|
6
|
+
}
|
7
|
+
];
|
8
|
+
try {
|
9
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
10
|
+
const res = await fetch(`${basePath}/routes.json`);
|
11
|
+
routes = await res.json();
|
12
|
+
} catch (error) {
|
13
|
+
console.warn('get routes.json error', error);
|
14
|
+
}
|
15
|
+
return routes;
|
16
|
+
}
|
17
|
+
const childApi = {
|
18
|
+
getRoutes
|
19
|
+
};
|
20
|
+
export { childApi };
|
@@ -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(
|
16
|
+
const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
|
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", {
|
@@ -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 {};
|
@@ -2,8 +2,8 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
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
|
-
import { clsxWithTw } from "../../utils/utils.js";
|
6
|
-
import {
|
5
|
+
import { clsxWithTw, isSparkRuntime } from "../../utils/utils.js";
|
6
|
+
import { useAppInfo, 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 } = useAppInfo();
|
21
21
|
const { name: userName, avatar: userAvatar } = useCurrentUserProfile();
|
22
22
|
const { handlerLogout } = useLogout();
|
23
23
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
@@ -90,6 +90,9 @@ const TitleBar = ({ navList, className })=>{
|
|
90
90
|
children: userName
|
91
91
|
}),
|
92
92
|
/*#__PURE__*/ jsx("img", {
|
93
|
+
onClick: ()=>{
|
94
|
+
if (isSparkRuntime()) location.href = '/suda/user?brand=1';
|
95
|
+
},
|
93
96
|
src: userAvatar,
|
94
97
|
alt: "avatar",
|
95
98
|
className: "w-8 h-8 rounded-full ml-2"
|
@@ -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;
|
@@ -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 { useAppInfo } from "../../hooks/useAppInfo.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 } = useAppInfo();
|
13
13
|
const { avatar: userAvatar } = useCurrentUserProfile();
|
14
14
|
return /*#__PURE__*/ jsxs("header", {
|
15
15
|
ref: navRef,
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
2
2
|
import type { IUserProfile } from '../../apis/udt-types';
|
3
3
|
export interface UserDisplayProps {
|
4
4
|
users: IUserProfile[];
|
5
|
-
size
|
5
|
+
size?: 'small' | 'medium' | 'large';
|
6
6
|
className?: string;
|
7
7
|
style?: React.CSSProperties;
|
8
8
|
}
|
@@ -3,7 +3,7 @@ import { useMemo, useRef, useState } from "react";
|
|
3
3
|
import { Avatar, Select, Spin } from "antd";
|
4
4
|
import { LoaderCircle } from "lucide-react";
|
5
5
|
import { debounce } from "lodash";
|
6
|
-
import {
|
6
|
+
import { getDataloom } from "../../integrations/dataloom.js";
|
7
7
|
import "./UserSelect.css";
|
8
8
|
import { UserWithAvatar } from "./UserWithAvatar.js";
|
9
9
|
const mapValueToOptions = (value)=>{
|
@@ -57,6 +57,7 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
|
|
57
57
|
const fetchRef = useRef(0);
|
58
58
|
const fetchUsers = async (search)=>{
|
59
59
|
try {
|
60
|
+
const dataloom = await getDataloom();
|
60
61
|
const { data } = await dataloom.service.user.search({
|
61
62
|
name: search,
|
62
63
|
pageSize: 20
|
@@ -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;
|
@@ -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 { useAppInfo } from "../../hooks/useAppInfo.js";
|
5
5
|
import { clsxWithTw } from "../../utils/utils.js";
|
6
6
|
function LogoInfo({ className, logoClassName }) {
|
7
|
-
const { name, avatar } =
|
7
|
+
const { name, avatar } = useAppInfo();
|
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 { IThemeTokenMeta } from './util';
|
5
5
|
export interface IBaseThemeProviderProps {
|
6
6
|
defaultTheme?: ITheme;
|
7
|
-
themeMeta?: Partial<
|
7
|
+
themeMeta?: Partial<IThemeTokenMeta>;
|
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(
|
25
|
+
const { rem } = findValueByPixel(themeMetaOptions.themeSpaces, themeMeta.spacing) || {
|
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(
|
31
|
+
const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
|
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(
|
47
|
+
const res = findValueByPixel(themeMetaOptions.themeSpaces, themeMeta.spacing) || {
|
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(
|
44
|
+
export declare function findValueByPixel(themeSpaces: typeof themeMetaOptions.themeSpaces | typeof themeMetaOptions.themeRadius, pixelValue?: string | number): {
|
45
45
|
pixel: string;
|
46
46
|
rem: string;
|
47
47
|
};
|
@@ -550,7 +550,8 @@ 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(
|
553
|
+
function findValueByPixel(themeSpaces, pixelValue) {
|
554
|
+
if (!pixelValue) return;
|
554
555
|
return themeSpaces.options.find((option)=>option.value.pixel === pixelValue)?.value;
|
555
556
|
}
|
556
557
|
export { findValueByPixel, getKeyByColor, themeColorTokenMap, themeMetaOptions, themeTailwindRadius };
|
@@ -1,49 +1 @@
|
|
1
|
-
export
|
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 {};
|
1
|
+
export { defaultUIConfig, type UIComponentConfig, } from '@lark-apaas/miaoda-inspector';
|