@lark-apaas/miaoda-core 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 +8 -0
- package/lib/apis/components/AppContainer.d.ts +1 -0
- package/lib/apis/components/AppContainer.js +2 -0
- package/lib/apis/components/ErrorRender.d.ts +1 -0
- package/lib/apis/components/ErrorRender.js +2 -0
- package/lib/apis/components/NotFoundRender.d.ts +1 -0
- package/lib/apis/components/NotFoundRender.js +2 -0
- package/lib/apis/components/SidebarNav.d.ts +1 -0
- package/lib/apis/components/SidebarNav.js +2 -0
- package/lib/apis/components/TopNav.d.ts +1 -0
- package/lib/apis/components/TopNav.js +2 -0
- package/lib/apis/components/User.d.ts +1 -0
- package/lib/apis/components/User.js +1 -0
- package/lib/apis/components/Welcome.d.ts +1 -0
- package/lib/apis/components/Welcome.js +2 -0
- package/lib/apis/constants/img-resources/avatar.d.ts +11 -0
- package/lib/apis/constants/img-resources/avatar.js +12 -0
- package/lib/apis/constants/img-resources/banner.d.ts +24 -0
- package/lib/apis/constants/img-resources/banner.js +25 -0
- package/lib/apis/constants/img-resources/cover.d.ts +36 -0
- package/lib/apis/constants/img-resources/cover.js +37 -0
- package/lib/apis/dataloom.d.ts +1 -0
- package/lib/apis/dataloom.js +2 -0
- package/lib/apis/hooks/useCurrentAppInfo.d.ts +1 -0
- package/lib/apis/hooks/useCurrentAppInfo.js +1 -0
- package/lib/apis/hooks/useCurrentUserProfile.d.ts +1 -0
- package/lib/apis/hooks/useCurrentUserProfile.js +1 -0
- package/lib/apis/logger.d.ts +1 -0
- package/lib/apis/logger.js +1 -0
- package/lib/apis/tools/generateImage.d.ts +1 -0
- package/lib/apis/tools/generateImage.js +1 -0
- package/lib/apis/tools/generateTextStream.d.ts +1 -0
- package/lib/apis/tools/generateTextStream.js +1 -0
- package/lib/apis/tools/getAppInfo.d.ts +1 -0
- package/lib/apis/tools/getAppInfo.js +1 -0
- package/lib/apis/tools/getCurrentUserProfile.d.ts +1 -0
- package/lib/apis/tools/getCurrentUserProfile.js +1 -0
- package/lib/apis/tools/storage.d.ts +1 -0
- package/lib/apis/tools/storage.js +4 -0
- package/lib/apis/udt-types.d.ts +16 -0
- package/lib/apis/udt-types.js +0 -0
- package/lib/apis/utils/registerChinaMap.d.ts +1 -0
- package/lib/apis/utils/registerChinaMap.js +103319 -0
- package/lib/components/AppContainer/IframeBridge.d.ts +2 -0
- package/lib/components/AppContainer/IframeBridge.js +80 -0
- package/lib/components/AppContainer/PageHoc.d.ts +4 -0
- package/lib/components/AppContainer/PageHoc.js +20 -0
- package/lib/components/AppContainer/dayjsPlugins.d.ts +1 -0
- package/lib/components/AppContainer/dayjsPlugins.js +69 -0
- package/lib/components/AppContainer/index.d.ts +7 -0
- package/lib/components/AppContainer/index.js +65 -0
- package/lib/components/AppContainer/sonner.css +101 -0
- package/lib/components/AppContainer/sonner.d.ts +8 -0
- package/lib/components/AppContainer/sonner.js +26 -0
- package/lib/components/ErrorRender/index.d.ts +5 -0
- package/lib/components/ErrorRender/index.js +79 -0
- package/lib/components/NotFoundRender/index.d.ts +3 -0
- package/lib/components/NotFoundRender/index.js +59 -0
- package/lib/components/SidebarNav/DrawerNav.d.ts +3 -0
- package/lib/components/SidebarNav/DrawerNav.js +64 -0
- package/lib/components/SidebarNav/DropdownNav.d.ts +3 -0
- package/lib/components/SidebarNav/DropdownNav.js +40 -0
- package/lib/components/SidebarNav/Sidebar.d.ts +3 -0
- package/lib/components/SidebarNav/Sidebar.js +33 -0
- package/lib/components/SidebarNav/index.d.ts +5 -0
- package/lib/components/SidebarNav/index.js +61 -0
- package/lib/components/TopNav/BottomNav.d.ts +12 -0
- package/lib/components/TopNav/BottomNav.js +81 -0
- package/lib/components/TopNav/TitleBar.d.ts +10 -0
- package/lib/components/TopNav/TitleBar.js +127 -0
- package/lib/components/TopNav/TopNav.d.ts +10 -0
- package/lib/components/TopNav/TopNav.js +86 -0
- package/lib/components/TopNav/index.d.ts +12 -0
- package/lib/components/TopNav/index.js +65 -0
- package/lib/components/User/UserDisplay.d.ts +9 -0
- package/lib/components/User/UserDisplay.js +39 -0
- package/lib/components/User/UserProfile/UserProfile.css +34 -0
- package/lib/components/User/UserProfile/UserProfile.d.ts +6 -0
- package/lib/components/User/UserProfile/UserProfile.js +41 -0
- package/lib/components/User/UserProfile/UserProfileContainer.d.ts +4 -0
- package/lib/components/User/UserProfile/UserProfileContainer.js +8 -0
- package/lib/components/User/UserProfile/UserProfileSkeleton.d.ts +3 -0
- package/lib/components/User/UserProfile/UserProfileSkeleton.js +36 -0
- package/lib/components/User/UserProfile/UserProfileUI.d.ts +8 -0
- package/lib/components/User/UserProfile/UserProfileUI.js +113 -0
- package/lib/components/User/UserProfile/index.d.ts +1 -0
- package/lib/components/User/UserProfile/index.js +2 -0
- package/lib/components/User/UserProfile/type.d.ts +8 -0
- package/lib/components/User/UserProfile/type.js +0 -0
- package/lib/components/User/UserProfile/utils.d.ts +5 -0
- package/lib/components/User/UserProfile/utils.js +26 -0
- package/lib/components/User/UserSelect.css +11 -0
- package/lib/components/User/UserSelect.d.ts +11 -0
- package/lib/components/User/UserSelect.js +171 -0
- package/lib/components/User/UserWithAvatar.d.ts +3 -0
- package/lib/components/User/UserWithAvatar.js +41 -0
- package/lib/components/User/index.d.ts +7 -0
- package/lib/components/User/index.js +5 -0
- package/lib/components/User/type.d.ts +13 -0
- package/lib/components/User/type.js +0 -0
- package/lib/components/Welcome/index.d.ts +3 -0
- package/lib/components/Welcome/index.js +33 -0
- package/lib/components/common/LogoInfo.d.ts +5 -0
- package/lib/components/common/LogoInfo.js +30 -0
- package/lib/components/common/NavItem.d.ts +20 -0
- package/lib/components/common/NavItem.js +112 -0
- package/lib/components/common/NavMenu.d.ts +9 -0
- package/lib/components/common/NavMenu.js +50 -0
- package/lib/components/common/UserAvatarLayout.d.ts +4 -0
- package/lib/components/common/UserAvatarLayout.js +41 -0
- package/lib/components/common/UserAvatarMenu.d.ts +4 -0
- package/lib/components/common/UserAvatarMenu.js +58 -0
- package/lib/components/common/index.d.ts +9 -0
- package/lib/components/common/index.js +10 -0
- package/lib/components/index.d.ts +9 -0
- package/lib/components/index.js +7 -0
- package/lib/components/theme/ThemeProvider.d.ts +20 -0
- package/lib/components/theme/ThemeProvider.js +75 -0
- package/lib/components/theme/constants.d.ts +48 -0
- package/lib/components/theme/constants.js +556 -0
- package/lib/components/theme/index.d.ts +4 -0
- package/lib/components/theme/index.js +5 -0
- package/lib/components/theme/miaoDarkTheme.d.ts +2 -0
- package/lib/components/theme/miaoDarkTheme.js +310 -0
- package/lib/components/theme/miaoLightTheme.d.ts +2 -0
- package/lib/components/theme/miaoLightTheme.js +296 -0
- package/lib/components/theme/ui-config.d.ts +49 -0
- package/lib/components/theme/ui-config.js +758 -0
- package/lib/components/theme/util.d.ts +20 -0
- package/lib/components/theme/util.js +188 -0
- package/lib/hooks/index.d.ts +5 -0
- package/lib/hooks/index.js +5 -0
- package/lib/hooks/useCurrentAppInfo.d.ts +6 -0
- package/lib/hooks/useCurrentAppInfo.js +20 -0
- package/lib/hooks/useCurrentUserProfile.d.ts +12 -0
- package/lib/hooks/useCurrentUserProfile.js +26 -0
- package/lib/hooks/useIsMobile.d.ts +1 -0
- package/lib/hooks/useIsMobile.js +20 -0
- package/lib/hooks/useLogout.d.ts +4 -0
- package/lib/hooks/useLogout.js +23 -0
- package/lib/hooks/useTheme.d.ts +4 -0
- package/lib/hooks/useTheme.js +8 -0
- package/lib/hooks/useUpdatingRef.d.ts +1 -0
- package/lib/hooks/useUpdatingRef.js +7 -0
- package/lib/index.css +3 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +5 -0
- package/lib/integrations/dataloom.d.ts +1 -0
- package/lib/integrations/dataloom.js +18 -0
- package/lib/integrations/generateImage.d.ts +1 -0
- package/lib/integrations/generateImage.js +32 -0
- package/lib/integrations/generateTextStream.d.ts +26 -0
- package/lib/integrations/generateTextStream.js +83 -0
- package/lib/integrations/getAppInfo.d.ts +2 -0
- package/lib/integrations/getAppInfo.js +4 -0
- package/lib/integrations/getCurrentUserProfile.d.ts +6 -0
- package/lib/integrations/getCurrentUserProfile.js +5 -0
- package/lib/logger/index.d.ts +6 -0
- package/lib/logger/index.js +54 -0
- package/lib/override.css +29 -0
- package/lib/tailwind-theme.css +435 -0
- package/lib/types/common.d.ts +11 -0
- package/lib/types/common.js +0 -0
- package/lib/types/index.d.ts +40 -0
- package/lib/types/index.js +0 -0
- package/lib/utils/copyToClipboard.d.ts +6 -0
- package/lib/utils/copyToClipboard.js +32 -0
- package/lib/utils/getAppId.d.ts +11 -0
- package/lib/utils/getAppId.js +9 -0
- package/lib/utils/getEnvPath.d.ts +4 -0
- package/lib/utils/getEnvPath.js +4 -0
- package/lib/utils/getParentOrigin.d.ts +5 -0
- package/lib/utils/getParentOrigin.js +7 -0
- package/lib/utils/getUserProfile.d.ts +47 -0
- package/lib/utils/getUserProfile.js +33 -0
- package/lib/utils/url.d.ts +8 -0
- package/lib/utils/url.js +22 -0
- package/lib/utils/utils.d.ts +11 -0
- package/lib/utils/utils.js +9 -0
- package/package.json +130 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ThemeConfig } from 'antd';
|
|
2
|
+
import { UIComponentConfig } from './ui-config';
|
|
3
|
+
export type IThemeMode = 'dark' | 'light' | 'system';
|
|
4
|
+
export interface IThemeMeta {
|
|
5
|
+
/**
|
|
6
|
+
* 品牌色
|
|
7
|
+
*/
|
|
8
|
+
colorPrimary: string;
|
|
9
|
+
/**
|
|
10
|
+
* 边框圆角
|
|
11
|
+
*/
|
|
12
|
+
borderRadius: number;
|
|
13
|
+
/**
|
|
14
|
+
* 疏密度(间距)
|
|
15
|
+
*/
|
|
16
|
+
spacing: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const generateTailwindRadiusToken: (radiusRemValue: number) => UIComponentConfig;
|
|
19
|
+
export declare function generateLightTheme(override?: Partial<IThemeMeta>): ThemeConfig;
|
|
20
|
+
export declare function generateDarkTheme(override?: Partial<IThemeMeta>): ThemeConfig;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { generate } from "@ant-design/colors";
|
|
2
|
+
import { defaultDarkTheme } from "./miaoDarkTheme.js";
|
|
3
|
+
import { defaultLightTheme } from "./miaoLightTheme.js";
|
|
4
|
+
const generateColorPalettes = (baseColor, mode)=>{
|
|
5
|
+
const colors = generate(baseColor, {
|
|
6
|
+
theme: mode
|
|
7
|
+
});
|
|
8
|
+
return {
|
|
9
|
+
1: colors[0],
|
|
10
|
+
2: colors[1],
|
|
11
|
+
3: colors[2],
|
|
12
|
+
4: colors[3],
|
|
13
|
+
5: colors[6],
|
|
14
|
+
6: colors[5],
|
|
15
|
+
7: colors[4],
|
|
16
|
+
8: colors[6],
|
|
17
|
+
9: colors[5],
|
|
18
|
+
10: colors[4]
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
function generateColorPrimaryToken(colorPrimary, mode = 'light') {
|
|
22
|
+
const primaryColors = generateColorPalettes(colorPrimary, 'dark' === mode ? 'dark' : 'default');
|
|
23
|
+
return {
|
|
24
|
+
colorPrimaryBg: primaryColors[1],
|
|
25
|
+
colorPrimaryBgHover: primaryColors[2],
|
|
26
|
+
colorPrimaryBorder: primaryColors[3],
|
|
27
|
+
colorPrimaryBorderHover: primaryColors[4],
|
|
28
|
+
colorPrimaryHover: primaryColors[5],
|
|
29
|
+
colorPrimary: primaryColors[6],
|
|
30
|
+
colorPrimaryActive: primaryColors[7],
|
|
31
|
+
colorPrimaryTextHover: primaryColors[8],
|
|
32
|
+
colorPrimaryText: primaryColors[9],
|
|
33
|
+
colorPrimaryTextActive: primaryColors[10]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const generateBorderRadiusTokenSyncTailwind = (radiusBase)=>({
|
|
37
|
+
borderRadius: radiusBase,
|
|
38
|
+
borderRadiusXS: radiusBase - 4,
|
|
39
|
+
borderRadiusSM: radiusBase - 2,
|
|
40
|
+
borderRadiusLG: radiusBase + 2,
|
|
41
|
+
borderRadiusOuter: radiusBase + 4
|
|
42
|
+
});
|
|
43
|
+
const generateSpacingToken = (token)=>{
|
|
44
|
+
const { sizeUnit, sizeStep } = token;
|
|
45
|
+
return {
|
|
46
|
+
sizeXXL: sizeUnit * (sizeStep + 8),
|
|
47
|
+
sizeXL: sizeUnit * (sizeStep + 4),
|
|
48
|
+
sizeLG: sizeUnit * (sizeStep + 2),
|
|
49
|
+
sizeMD: sizeUnit * (sizeStep + 1),
|
|
50
|
+
sizeMS: sizeUnit * sizeStep,
|
|
51
|
+
size: sizeUnit * sizeStep,
|
|
52
|
+
sizeSM: sizeUnit * (sizeStep - 1),
|
|
53
|
+
sizeXS: sizeUnit * (sizeStep - 2),
|
|
54
|
+
sizeXXS: sizeUnit * (sizeStep - 3)
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const generateTailwindRadiusToken = (radiusRemValue)=>{
|
|
58
|
+
try {
|
|
59
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
60
|
+
const radiusPx = radiusRemValue * rootFontSize;
|
|
61
|
+
const tempElement = document.createElement('div');
|
|
62
|
+
tempElement.style.position = 'absolute';
|
|
63
|
+
tempElement.style.visibility = 'hidden';
|
|
64
|
+
document.body.appendChild(tempElement);
|
|
65
|
+
tempElement.style.borderRadius = `${radiusPx}px`;
|
|
66
|
+
const computed = getComputedStyle(tempElement).borderRadius;
|
|
67
|
+
document.body.removeChild(tempElement);
|
|
68
|
+
if (computed && 'auto' !== computed && 'initial' !== computed) return {
|
|
69
|
+
type: 'select',
|
|
70
|
+
options: [
|
|
71
|
+
{
|
|
72
|
+
value: 'rounded-none',
|
|
73
|
+
label: 'none(0px)',
|
|
74
|
+
rawValue: '0'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
value: 'rounded-sm',
|
|
78
|
+
label: `sm (${Math.max(0, radiusPx - 4)}px)`,
|
|
79
|
+
rawValue: `${Math.max(0, radiusPx - 4)}`
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: 'rounded',
|
|
83
|
+
label: 's (4px)',
|
|
84
|
+
rawValue: '4'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
value: 'rounded-md',
|
|
88
|
+
label: `m (${Math.max(0, radiusPx - 2)}px)`,
|
|
89
|
+
rawValue: `${Math.max(0, radiusPx - 2)}`
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
value: 'rounded-lg',
|
|
93
|
+
label: `l (${radiusPx}px)`,
|
|
94
|
+
rawValue: `${radiusPx}`
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
value: 'rounded-xl',
|
|
98
|
+
label: `xl (${radiusPx + 4}px)`,
|
|
99
|
+
rawValue: `${radiusPx + 4}`
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
value: 'rounded-2xl',
|
|
103
|
+
label: '2xl (16px)',
|
|
104
|
+
rawValue: '16'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
value: 'rounded-full',
|
|
108
|
+
label: 'Full',
|
|
109
|
+
rawValue: '9999'
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
};
|
|
113
|
+
throw new Error('Browser calculation validation failed');
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.warn('Failed to get computed values from browser, falling back to default calculation:', error);
|
|
116
|
+
const radiusPx = 16 * radiusRemValue;
|
|
117
|
+
return {
|
|
118
|
+
type: 'select',
|
|
119
|
+
options: [
|
|
120
|
+
{
|
|
121
|
+
value: 'rounded-none',
|
|
122
|
+
label: 'none(0px)',
|
|
123
|
+
rawValue: '0'
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
value: 'rounded-sm',
|
|
127
|
+
label: `sm (${Math.max(0, radiusPx - 4)}px)`,
|
|
128
|
+
rawValue: `${Math.max(0, radiusPx - 4)}`
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
value: 'rounded',
|
|
132
|
+
label: 's (4px)',
|
|
133
|
+
rawValue: '4'
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
value: 'rounded-md',
|
|
137
|
+
label: `m (${Math.max(0, radiusPx - 2)}px)`,
|
|
138
|
+
rawValue: `${Math.max(0, radiusPx - 2)}`
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
value: 'rounded-lg',
|
|
142
|
+
label: `l (${radiusPx}px)`,
|
|
143
|
+
rawValue: `${radiusPx}`
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
value: 'rounded-xl',
|
|
147
|
+
label: `xl (${radiusPx + 4}px)`,
|
|
148
|
+
rawValue: `${radiusPx + 4}`
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
value: 'rounded-2xl',
|
|
152
|
+
label: '2xl (16px)',
|
|
153
|
+
rawValue: '16'
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
value: 'rounded-full',
|
|
157
|
+
label: 'Full',
|
|
158
|
+
rawValue: '9999'
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const lightColorPrimary = '#1456f0';
|
|
165
|
+
const darkColorPrimary = '#336df4';
|
|
166
|
+
function generateLightTheme(override) {
|
|
167
|
+
return {
|
|
168
|
+
...defaultLightTheme,
|
|
169
|
+
token: {
|
|
170
|
+
...defaultLightTheme.token,
|
|
171
|
+
...generateColorPrimaryToken(override?.colorPrimary || lightColorPrimary, 'light'),
|
|
172
|
+
...generateBorderRadiusTokenSyncTailwind(override?.borderRadius || 4),
|
|
173
|
+
...generateSpacingToken(override)
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function generateDarkTheme(override) {
|
|
178
|
+
return {
|
|
179
|
+
...defaultDarkTheme,
|
|
180
|
+
token: {
|
|
181
|
+
...defaultDarkTheme.token,
|
|
182
|
+
...generateColorPrimaryToken(override?.colorPrimary || darkColorPrimary, 'dark'),
|
|
183
|
+
...generateBorderRadiusTokenSyncTailwind(override?.borderRadius || 4),
|
|
184
|
+
...generateSpacingToken(override)
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export { generateDarkTheme, generateLightTheme, generateTailwindRadiusToken };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { getAppInfo } from "../integrations/getAppInfo.js";
|
|
3
|
+
const useCurrentAppInfo = ()=>{
|
|
4
|
+
const [appInfo, setAppInfo] = useState(()=>getAppInfo());
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
const handleMetaInfoChanged = ()=>{
|
|
7
|
+
setAppInfo(getAppInfo());
|
|
8
|
+
};
|
|
9
|
+
window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
|
10
|
+
return ()=>{
|
|
11
|
+
window.removeEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
|
12
|
+
};
|
|
13
|
+
}, []);
|
|
14
|
+
return {
|
|
15
|
+
...appInfo,
|
|
16
|
+
appName: appInfo.name,
|
|
17
|
+
appLogo: appInfo.avatar
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export { useCurrentAppInfo };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IUserProfile } from '../apis/udt-types';
|
|
2
|
+
export interface ICompatibilityUserProfile extends IUserProfile {
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated please use `name`
|
|
5
|
+
*/
|
|
6
|
+
userName: string;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated please use `avatar`
|
|
9
|
+
*/
|
|
10
|
+
userAvatar: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const useCurrentUserProfile: () => ICompatibilityUserProfile;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { logger } from "../logger/index.js";
|
|
3
|
+
import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
|
|
4
|
+
function getCompatibilityUserProfile() {
|
|
5
|
+
const userInfo = getCurrentUserProfile();
|
|
6
|
+
return {
|
|
7
|
+
...userInfo,
|
|
8
|
+
userName: userInfo.name,
|
|
9
|
+
userAvatar: userInfo.avatar
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const useCurrentUserProfile = ()=>{
|
|
13
|
+
const [userInfo, setUserInfo] = useState(()=>getCompatibilityUserProfile());
|
|
14
|
+
useEffect(()=>{
|
|
15
|
+
const handleMetaInfoChanged = ()=>{
|
|
16
|
+
logger.info('MiaoDaMetaInfoChanged', getCurrentUserProfile());
|
|
17
|
+
setUserInfo(getCompatibilityUserProfile());
|
|
18
|
+
};
|
|
19
|
+
window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
|
20
|
+
return ()=>{
|
|
21
|
+
window.removeEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
|
22
|
+
};
|
|
23
|
+
}, []);
|
|
24
|
+
return userInfo;
|
|
25
|
+
};
|
|
26
|
+
export { useCurrentUserProfile };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsMobile(): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import react from "react";
|
|
2
|
+
import { debounce } from "lodash";
|
|
3
|
+
const MOBILE_BREAKPOINT = 768;
|
|
4
|
+
function useIsMobile() {
|
|
5
|
+
const [isMobile, setIsMobile] = react.useState(window.innerWidth < MOBILE_BREAKPOINT);
|
|
6
|
+
react.useEffect(()=>{
|
|
7
|
+
const handleResize = ()=>{
|
|
8
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
9
|
+
};
|
|
10
|
+
const debouncedHandleResize = debounce(handleResize, 200);
|
|
11
|
+
window.addEventListener('resize', debouncedHandleResize);
|
|
12
|
+
handleResize();
|
|
13
|
+
return ()=>{
|
|
14
|
+
window.removeEventListener('resize', debouncedHandleResize);
|
|
15
|
+
debouncedHandleResize.cancel();
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
return isMobile;
|
|
19
|
+
}
|
|
20
|
+
export { useIsMobile };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
function useLogout() {
|
|
3
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
4
|
+
async function handlerLogout() {
|
|
5
|
+
if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
|
|
6
|
+
setIsLoading(true);
|
|
7
|
+
try {
|
|
8
|
+
await fetch('/ai/api/ui/page/logout', {
|
|
9
|
+
method: 'GET'
|
|
10
|
+
});
|
|
11
|
+
window.location.reload();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.error('登出失败', error);
|
|
14
|
+
} finally{
|
|
15
|
+
setIsLoading(false);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
handlerLogout,
|
|
20
|
+
isLoading
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export { useLogout };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { ThemeProviderContext } from "../components/theme/index.js";
|
|
3
|
+
const useTheme = ()=>{
|
|
4
|
+
const context = useContext(ThemeProviderContext);
|
|
5
|
+
if (void 0 === context) throw new Error('useTheme 必须在 ThemeProvider 内使用');
|
|
6
|
+
return context;
|
|
7
|
+
};
|
|
8
|
+
export { useTheme };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useUpdatingRef<T>(value: T): import("react").MutableRefObject<T>;
|
package/lib/index.css
ADDED
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const dataloom: import("@data-loom/js").DataloomClient<any, "public", any>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { splitWorkspaceUrl } from "../utils/url.js";
|
|
2
|
+
import { createClient } from "@data-loom/js";
|
|
3
|
+
const PAT_URL_NAMESPACE = 'FEISUDA_UUU';
|
|
4
|
+
const PAT_TOKEN_NAMESPACE = 'FEISUDA_TTT';
|
|
5
|
+
const DATALOOM_CLIENT_URL = window[PAT_URL_NAMESPACE];
|
|
6
|
+
const DATALOOM_PAT = window[PAT_TOKEN_NAMESPACE];
|
|
7
|
+
const createDataLoomClient = (url, pat)=>{
|
|
8
|
+
if (!url || !pat) return null;
|
|
9
|
+
const { baseUrl, workspace } = splitWorkspaceUrl(url);
|
|
10
|
+
return createClient(baseUrl, pat, workspace, {
|
|
11
|
+
global: {
|
|
12
|
+
enablePostgresBuilderLog: 'production' !== process.env.NODE_ENV,
|
|
13
|
+
requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
|
|
18
|
+
export { dataloom };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateImage(prompt: string, size?: string, headers?: Record<string, string>): Promise<any>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getAppId } from "../utils/getAppId.js";
|
|
2
|
+
import { getEnvPath } from "../utils/getEnvPath.js";
|
|
3
|
+
async function generateImage(prompt, size = '1024x1024', headers = {}) {
|
|
4
|
+
const appId = getAppId(window.location.pathname);
|
|
5
|
+
if (!appId) return {
|
|
6
|
+
code: 1,
|
|
7
|
+
msg: 'appId is required',
|
|
8
|
+
data: {}
|
|
9
|
+
};
|
|
10
|
+
const defaultHeaders = {
|
|
11
|
+
'Content-Type': 'application/json'
|
|
12
|
+
};
|
|
13
|
+
const mergedHeaders = {
|
|
14
|
+
...defaultHeaders,
|
|
15
|
+
...headers,
|
|
16
|
+
'X-Kunlun-Token': window.token,
|
|
17
|
+
'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
|
|
18
|
+
'x-lgw-csrf-token': window.lgw_csrf_token,
|
|
19
|
+
...window.CSRF_HEADERS || {}
|
|
20
|
+
};
|
|
21
|
+
const response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text2image`, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
headers: mergedHeaders,
|
|
24
|
+
credentials: 'include',
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
prompt: prompt,
|
|
27
|
+
size: size
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
return await response.json();
|
|
31
|
+
}
|
|
32
|
+
export { generateImage };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
token?: string;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
interface GenerateTextOptions {
|
|
7
|
+
text: string;
|
|
8
|
+
thinking_type?: 'enabled' | 'disabled';
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
interface GenerateTextResult {
|
|
12
|
+
content: string;
|
|
13
|
+
reasoning_content: string;
|
|
14
|
+
success: boolean;
|
|
15
|
+
error?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 文生文 - 流式版本
|
|
19
|
+
* 支持实时接收生成内容的回调
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateTextStream(options: GenerateTextOptions, onChunk?: (chunk: {
|
|
22
|
+
content: string;
|
|
23
|
+
reasoning_content: string;
|
|
24
|
+
finished: boolean;
|
|
25
|
+
}) => void): Promise<GenerateTextResult>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { getAppId } from "../utils/getAppId.js";
|
|
2
|
+
import { getEnvPath } from "../utils/getEnvPath.js";
|
|
3
|
+
async function generateTextStream(options, onChunk) {
|
|
4
|
+
const { text, thinking_type = 'disabled', headers = {} } = options;
|
|
5
|
+
const appId = getAppId(window.location.pathname);
|
|
6
|
+
if (!appId) return {
|
|
7
|
+
content: '',
|
|
8
|
+
reasoning_content: '',
|
|
9
|
+
success: false,
|
|
10
|
+
error: 'appId is required'
|
|
11
|
+
};
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text/generate`, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
...headers,
|
|
18
|
+
'X-Kunlun-Token': window.token,
|
|
19
|
+
'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
|
|
20
|
+
'x-lgw-csrf-token': window.lgw_csrf_token,
|
|
21
|
+
...window.CSRF_HEADERS || {}
|
|
22
|
+
},
|
|
23
|
+
credentials: 'include',
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
text,
|
|
26
|
+
thinking_type
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
30
|
+
const reader = response.body?.getReader();
|
|
31
|
+
if (!reader) throw new Error('无法获取响应流');
|
|
32
|
+
let fullContent = '';
|
|
33
|
+
let fullReasoningContent = '';
|
|
34
|
+
const decoder = new TextDecoder();
|
|
35
|
+
while(true){
|
|
36
|
+
const { done, value } = await reader.read();
|
|
37
|
+
if (done) break;
|
|
38
|
+
const chunk = decoder.decode(value, {
|
|
39
|
+
stream: true
|
|
40
|
+
});
|
|
41
|
+
const lines = chunk.split('\n').filter((line)=>line.trim());
|
|
42
|
+
for (const line of lines)if (line.startsWith('data: ')) {
|
|
43
|
+
const jsonStr = line.slice(6);
|
|
44
|
+
try {
|
|
45
|
+
const data = JSON.parse(jsonStr);
|
|
46
|
+
if (0 !== data.code) return {
|
|
47
|
+
content: '',
|
|
48
|
+
reasoning_content: '',
|
|
49
|
+
success: false,
|
|
50
|
+
error: data.msg || '生成失败'
|
|
51
|
+
};
|
|
52
|
+
if (data.data.content) fullContent += data.data.content;
|
|
53
|
+
if (data.data.reasoning_content) fullReasoningContent += data.data.reasoning_content;
|
|
54
|
+
if (onChunk) onChunk({
|
|
55
|
+
content: data.data.content || '',
|
|
56
|
+
reasoning_content: data.data.reasoning_content || '',
|
|
57
|
+
finished: data.finished
|
|
58
|
+
});
|
|
59
|
+
if (data.finished) return {
|
|
60
|
+
content: fullContent,
|
|
61
|
+
reasoning_content: fullReasoningContent,
|
|
62
|
+
success: true
|
|
63
|
+
};
|
|
64
|
+
} catch (parseError) {
|
|
65
|
+
console.error(`解析JSON失败: ${jsonStr}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
content: fullContent,
|
|
71
|
+
reasoning_content: fullReasoningContent,
|
|
72
|
+
success: true
|
|
73
|
+
};
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return {
|
|
76
|
+
content: '',
|
|
77
|
+
reasoning_content: '',
|
|
78
|
+
success: false,
|
|
79
|
+
error: error instanceof Error ? error.message : '未知错误'
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export { generateTextStream };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const LOG_LEVELS = [
|
|
2
|
+
'debug',
|
|
3
|
+
'info',
|
|
4
|
+
'warn',
|
|
5
|
+
'error'
|
|
6
|
+
];
|
|
7
|
+
const defaultConfig = {
|
|
8
|
+
showLevel: false,
|
|
9
|
+
showTimestamp: false,
|
|
10
|
+
level: 'info',
|
|
11
|
+
prefix: ''
|
|
12
|
+
};
|
|
13
|
+
let config = {
|
|
14
|
+
...defaultConfig
|
|
15
|
+
};
|
|
16
|
+
function configureLogger(options) {
|
|
17
|
+
config = {
|
|
18
|
+
...defaultConfig,
|
|
19
|
+
...options
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function getLogLevel() {
|
|
23
|
+
return config.level;
|
|
24
|
+
}
|
|
25
|
+
function shouldLog(level) {
|
|
26
|
+
return LOG_LEVELS.indexOf(level) >= LOG_LEVELS.indexOf(getLogLevel());
|
|
27
|
+
}
|
|
28
|
+
function getFormattedPrefix(level) {
|
|
29
|
+
const parts = [];
|
|
30
|
+
if (config.prefix) parts.push(`[${config.prefix}]`);
|
|
31
|
+
if (config.showLevel) parts.push(`[${level.toUpperCase()}]`);
|
|
32
|
+
return parts;
|
|
33
|
+
}
|
|
34
|
+
configureLogger({
|
|
35
|
+
showLevel: true,
|
|
36
|
+
showTimestamp: false,
|
|
37
|
+
level: 'development' === process.env.NODE_ENV ? 'debug' : 'error',
|
|
38
|
+
prefix: 'MiaoDa'
|
|
39
|
+
});
|
|
40
|
+
const logger = {
|
|
41
|
+
debug (message, ...args) {
|
|
42
|
+
if (shouldLog('debug')) console.log(...getFormattedPrefix('debug'), message, ...args);
|
|
43
|
+
},
|
|
44
|
+
info (message, ...args) {
|
|
45
|
+
if (shouldLog('info')) console.log(...getFormattedPrefix('info'), message, ...args);
|
|
46
|
+
},
|
|
47
|
+
warn (message, ...args) {
|
|
48
|
+
if (shouldLog('warn')) console.log(...getFormattedPrefix('warn'), message, ...args);
|
|
49
|
+
},
|
|
50
|
+
error (message, ...args) {
|
|
51
|
+
if (shouldLog('error')) console.error(...getFormattedPrefix('error'), message, ...args);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export { logger };
|