@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
@@ -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 IThemeTokenMeta {
|
5
5
|
/**
|
6
6
|
* 品牌色
|
7
7
|
*/
|
@@ -16,5 +16,5 @@ export interface IThemeMeta {
|
|
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<IThemeTokenMeta>): ThemeConfig;
|
20
|
+
export declare function generateDarkTheme(override?: Partial<IThemeTokenMeta>): 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),
|
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),
|
184
184
|
...generateSpacingToken(override)
|
185
185
|
}
|
186
186
|
};
|
package/lib/hooks/index.d.ts
CHANGED
package/lib/hooks/index.js
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import { useEffect, useState } from "react";
|
2
2
|
import { getAppInfo } from "../integrations/getAppInfo.js";
|
3
|
-
const
|
4
|
-
const [appInfo, setAppInfo] = useState(
|
3
|
+
const useAppInfo = ()=>{
|
4
|
+
const [appInfo, setAppInfo] = useState({});
|
5
5
|
useEffect(()=>{
|
6
|
-
const handleMetaInfoChanged = ()=>{
|
7
|
-
setAppInfo(getAppInfo());
|
6
|
+
const handleMetaInfoChanged = async ()=>{
|
7
|
+
setAppInfo(await getAppInfo());
|
8
8
|
};
|
9
|
+
handleMetaInfoChanged();
|
9
10
|
window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
10
11
|
return ()=>{
|
11
12
|
window.removeEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
@@ -17,4 +18,4 @@ const useCurrentAppInfo = ()=>{
|
|
17
18
|
appLogo: appInfo.avatar
|
18
19
|
};
|
19
20
|
};
|
20
|
-
export {
|
21
|
+
export { useAppInfo };
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import { useEffect, useState } from "react";
|
2
2
|
import { logger } from "../logger/index.js";
|
3
3
|
import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
|
4
|
+
import { getDataloom } from "../integrations/dataloom.js";
|
5
|
+
import { isSparkRuntime } from "../utils/utils.js";
|
4
6
|
function getCompatibilityUserProfile() {
|
5
7
|
const userInfo = getCurrentUserProfile();
|
6
8
|
return {
|
@@ -12,8 +14,38 @@ function getCompatibilityUserProfile() {
|
|
12
14
|
const useCurrentUserProfile = ()=>{
|
13
15
|
const [userInfo, setUserInfo] = useState(()=>getCompatibilityUserProfile());
|
14
16
|
useEffect(()=>{
|
15
|
-
|
16
|
-
|
17
|
+
let handleMetaInfoChanged;
|
18
|
+
if (isSparkRuntime()) {
|
19
|
+
(async ()=>{
|
20
|
+
const dataloom = await getDataloom();
|
21
|
+
const result = await dataloom.service.session.getUserInfo();
|
22
|
+
const userInfo = result?.data?.user_info;
|
23
|
+
setUserInfo({
|
24
|
+
user_id: userInfo?.user_id?.toString(),
|
25
|
+
email: userInfo?.email,
|
26
|
+
name: userInfo?.name?.[0]?.text,
|
27
|
+
avatar: userInfo?.avatar?.image?.large,
|
28
|
+
userName: userInfo?.name?.[0]?.text,
|
29
|
+
userAvatar: userInfo?.avatar?.image?.large
|
30
|
+
});
|
31
|
+
})();
|
32
|
+
handleMetaInfoChanged = async ()=>{
|
33
|
+
const dataloom = await getDataloom();
|
34
|
+
const result = await dataloom.service.session.getUserInfo();
|
35
|
+
const userInfo = result?.data?.user_info;
|
36
|
+
const newUserInfo = {
|
37
|
+
user_id: userInfo?.user_id?.toString(),
|
38
|
+
email: userInfo?.email,
|
39
|
+
name: userInfo?.name?.[0]?.text,
|
40
|
+
avatar: userInfo?.avatar?.image?.large,
|
41
|
+
userName: userInfo?.name?.[0]?.text,
|
42
|
+
userAvatar: userInfo?.avatar?.image?.large
|
43
|
+
};
|
44
|
+
logger.info('MiaoDaMetaInfoChanged', newUserInfo);
|
45
|
+
setUserInfo(newUserInfo);
|
46
|
+
};
|
47
|
+
} else handleMetaInfoChanged = ()=>{
|
48
|
+
logger.info('MiaoDaMetaInfoChanged', getCompatibilityUserProfile());
|
17
49
|
setUserInfo(getCompatibilityUserProfile());
|
18
50
|
};
|
19
51
|
window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
|
package/lib/hooks/useLogout.js
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
import { useState } from "react";
|
2
|
+
import { getDataloom } from "../integrations/dataloom.js";
|
3
|
+
import { isSparkRuntime } from "../utils/utils.js";
|
2
4
|
function useLogout() {
|
3
5
|
const [isLoading, setIsLoading] = useState(false);
|
4
6
|
async function handlerLogout() {
|
5
7
|
if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
|
8
|
+
if (isSparkRuntime()) {
|
9
|
+
setIsLoading(true);
|
10
|
+
try {
|
11
|
+
const dataloom = await getDataloom();
|
12
|
+
await dataloom.service.session.signOut();
|
13
|
+
} catch (error) {
|
14
|
+
console.error('登出失败', error);
|
15
|
+
} finally{
|
16
|
+
setIsLoading(false);
|
17
|
+
}
|
18
|
+
return;
|
19
|
+
}
|
6
20
|
setIsLoading(true);
|
7
21
|
try {
|
8
22
|
await fetch('/ai/api/ui/page/logout', {
|
package/lib/index.css
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
@source inline("text-{xs,sm,base,lg,xl,2xl,3xl,4xl,5xl,6xl,7xl,8xl,9xl}");
|
2
|
+
|
3
|
+
@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}");
|
4
|
+
|
5
|
+
@source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}");
|
6
|
+
|
7
|
+
@source inline("{bg,text,border}-neutral-{00,1000}");
|
8
|
+
|
9
|
+
@source inline("rounded-{none,sm,md,lg,xl,full}");
|
10
|
+
|
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
/** 获取dataloom实例 */
|
2
|
+
export declare function getDataloom(): Promise<import("@data-loom/js").DataloomClient<any, "public", any>>;
|
@@ -1,18 +1,32 @@
|
|
1
1
|
import { splitWorkspaceUrl } from "../utils/url.js";
|
2
2
|
import { createClient } from "@data-loom/js";
|
3
|
-
|
4
|
-
|
5
|
-
const DATALOOM_CLIENT_URL = window[PAT_URL_NAMESPACE];
|
6
|
-
const DATALOOM_PAT = window[PAT_TOKEN_NAMESPACE];
|
3
|
+
import { getAppId } from "../utils/getAppId.js";
|
4
|
+
import { getInitialInfo } from "../utils/getInitialInfo.js";
|
7
5
|
const createDataLoomClient = (url, pat)=>{
|
8
|
-
if (!url
|
6
|
+
if (!url) return null;
|
9
7
|
const { baseUrl, workspace } = splitWorkspaceUrl(url);
|
8
|
+
const appId = getAppId(window.location.pathname);
|
10
9
|
return createClient(baseUrl, pat, workspace, {
|
11
10
|
global: {
|
12
11
|
enablePostgresBuilderLog: 'production' !== process.env.NODE_ENV,
|
13
|
-
requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0
|
12
|
+
requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
|
13
|
+
brandName: 'miaoda',
|
14
|
+
appId,
|
15
|
+
onError: (error, dataloomInstance)=>{
|
16
|
+
if (error?.status === 401) {
|
17
|
+
if (error?.code === 'k_ident_013001') dataloomInstance.service.session.redirectToLogin();
|
18
|
+
}
|
19
|
+
}
|
14
20
|
}
|
15
21
|
});
|
16
22
|
};
|
17
|
-
|
18
|
-
|
23
|
+
let dataloom = null;
|
24
|
+
async function getDataloom() {
|
25
|
+
if (dataloom) return dataloom;
|
26
|
+
const info = await getInitialInfo();
|
27
|
+
const DATALOOM_CLIENT_URL = info?.app_runtime_extra?.url;
|
28
|
+
const DATALOOM_PAT = info?.app_runtime_extra?.token;
|
29
|
+
dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
|
30
|
+
return dataloom;
|
31
|
+
}
|
32
|
+
export { getDataloom };
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { getAppId } from "../utils/getAppId.js";
|
2
|
+
import { getCsrfToken } from "../utils/getCsrfToken.js";
|
2
3
|
import { getEnvPath } from "../utils/getEnvPath.js";
|
4
|
+
import { isSparkRuntime } from "../utils/utils.js";
|
3
5
|
async function generateImage(prompt, size = '1024x1024', headers = {}) {
|
4
6
|
const appId = getAppId(window.location.pathname);
|
5
7
|
if (!appId) return {
|
@@ -18,13 +20,26 @@ async function generateImage(prompt, size = '1024x1024', headers = {}) {
|
|
18
20
|
'x-lgw-csrf-token': window.lgw_csrf_token,
|
19
21
|
...window.CSRF_HEADERS || {}
|
20
22
|
};
|
23
|
+
if (isSparkRuntime()) {
|
24
|
+
mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
|
25
|
+
const response = await fetch(`${window.location.origin}/spark/b/${appId}/text2image`, {
|
26
|
+
method: 'POST',
|
27
|
+
headers: mergedHeaders,
|
28
|
+
credentials: 'include',
|
29
|
+
body: JSON.stringify({
|
30
|
+
prompt,
|
31
|
+
size
|
32
|
+
})
|
33
|
+
});
|
34
|
+
return await response.json();
|
35
|
+
}
|
21
36
|
const response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text2image`, {
|
22
37
|
method: 'POST',
|
23
38
|
headers: mergedHeaders,
|
24
39
|
credentials: 'include',
|
25
40
|
body: JSON.stringify({
|
26
|
-
prompt
|
27
|
-
size
|
41
|
+
prompt,
|
42
|
+
size
|
28
43
|
})
|
29
44
|
});
|
30
45
|
return await response.json();
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { getAppId } from "../utils/getAppId.js";
|
2
|
+
import { getCsrfToken } from "../utils/getCsrfToken.js";
|
2
3
|
import { getEnvPath } from "../utils/getEnvPath.js";
|
4
|
+
import { isSparkRuntime } from "../utils/utils.js";
|
3
5
|
async function generateTextStream(options, onChunk) {
|
4
6
|
const { text, thinking_type = 'disabled', headers = {} } = options;
|
5
7
|
const appId = getAppId(window.location.pathname);
|
@@ -10,16 +12,29 @@ async function generateTextStream(options, onChunk) {
|
|
10
12
|
error: 'appId is required'
|
11
13
|
};
|
12
14
|
try {
|
13
|
-
const
|
15
|
+
const mergedHeaders = {
|
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
|
+
let response;
|
24
|
+
if (isSparkRuntime()) {
|
25
|
+
mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
|
26
|
+
response = await fetch(`${window.location.origin}/spark/b/${appId}/text/generate`, {
|
27
|
+
method: 'POST',
|
28
|
+
headers: mergedHeaders,
|
29
|
+
credentials: 'include',
|
30
|
+
body: JSON.stringify({
|
31
|
+
text,
|
32
|
+
thinking_type
|
33
|
+
})
|
34
|
+
});
|
35
|
+
} else response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text/generate`, {
|
14
36
|
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
|
-
},
|
37
|
+
headers: mergedHeaders,
|
23
38
|
credentials: 'include',
|
24
39
|
body: JSON.stringify({
|
25
40
|
text,
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import { AppInfoPayload } from '../types/common';
|
2
|
-
export declare function getAppInfo(): AppInfoPayload
|
2
|
+
export declare function getAppInfo(): Promise<AppInfoPayload>;
|
@@ -1,4 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { getInitialInfo } from "../utils/getInitialInfo.js";
|
2
|
+
import { isSparkRuntime } from "../utils/utils.js";
|
3
|
+
async function getAppInfo() {
|
4
|
+
let appInfo = window._appInfo;
|
5
|
+
if (!appInfo && isSparkRuntime()) {
|
6
|
+
const info = (await getInitialInfo()).app_info;
|
7
|
+
appInfo = {
|
8
|
+
name: info?.app_name || '',
|
9
|
+
avatar: info?.app_avatar || ''
|
10
|
+
};
|
11
|
+
}
|
12
|
+
return appInfo ?? {};
|
3
13
|
}
|
4
14
|
export { getAppInfo };
|
package/lib/tailwind-theme.css
CHANGED
@@ -1,39 +1,7 @@
|
|
1
|
-
@import "
|
2
|
-
@layer theme;
|
1
|
+
@import "@/inspector.dev.css";
|
3
2
|
|
4
3
|
@layer base {
|
5
4
|
:root {
|
6
|
-
--color-background: #fff;
|
7
|
-
--color-foreground: #1f2329;
|
8
|
-
--color-card: #fff;
|
9
|
-
--color-card-foreground: #1f2329;
|
10
|
-
--color-popover: #fff;
|
11
|
-
--color-popover-foreground: #1f2329;
|
12
|
-
--color-primary: #1456f0;
|
13
|
-
--color-primary-foreground: #f8f9fa;
|
14
|
-
--color-secondary: #f2f3f5;
|
15
|
-
--color-secondary-foreground: #1f2329;
|
16
|
-
--color-muted: #f2f3f5;
|
17
|
-
--color-muted-foreground: #8f959e;
|
18
|
-
--color-accent: #f2f3f5;
|
19
|
-
--color-accent-foreground: #1f2329;
|
20
|
-
--color-destructive: #f54a45;
|
21
|
-
--color-border: #dee0e3;
|
22
|
-
--color-input: #dee0e3;
|
23
|
-
--color-ring: #d0d3d6;
|
24
|
-
--color-chart-1: #3370eb;
|
25
|
-
--color-chart-2: #1bcebf;
|
26
|
-
--color-chart-3: #ffc60a;
|
27
|
-
--color-chart-4: #ed6d0c;
|
28
|
-
--color-chart-5: #dca1e4;
|
29
|
-
--color-sidebar: #fafafa;
|
30
|
-
--color-sidebar-foreground: #1f2329;
|
31
|
-
--color-sidebar-primary: #373c43;
|
32
|
-
--color-sidebar-primary-foreground: #f8f9fa;
|
33
|
-
--color-sidebar-accent: #f2f3f5;
|
34
|
-
--color-sidebar-accent-foreground: #1f2329;
|
35
|
-
--color-sidebar-border: #dee0e3;
|
36
|
-
--color-sidebar-ring: #d0d3d6;
|
37
5
|
--color-blue-50: #f0f4ff;
|
38
6
|
--color-blue-100: #e0e9ff;
|
39
7
|
--color-blue-200: #c2d4ff;
|
@@ -197,53 +165,9 @@
|
|
197
165
|
--bgTextSelection: 20, 86, 240, .3;
|
198
166
|
--lineDividerDefault: 31, 35, 41, .15;
|
199
167
|
--lineDividerModule: 31, 35, 41, .15;
|
200
|
-
--font-sans: "Geist", "Geist Fallback", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
201
|
-
--font-serif: "Geist", "Geist Fallback", ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
|
202
|
-
--font-mono: Source Code Pro, monospace;
|
203
|
-
--radius: .5rem;
|
204
|
-
--shadow-2xs: 0px 6px 12px 0px #1f232903;
|
205
|
-
--shadow-xs: 0px 6px 12px 0px #1f232903;
|
206
|
-
--shadow-sm: 0px 6px 12px 0px #1f232908, 0px 1px 2px -1px #1f232908;
|
207
|
-
--shadow: 0px 6px 12px 0px #1f232908, 0px 1px 2px -1px #1f232908;
|
208
|
-
--shadow-md: 0px 6px 12px 0px #1f232908, 0px 2px 4px -1px #1f232908;
|
209
|
-
--shadow-lg: 0px 6px 12px 0px #1f232908, 0px 4px 6px -1px #1f232908;
|
210
|
-
--shadow-xl: 0px 6px 12px 0px #1f232908, 0px 8px 10px -1px #1f232908;
|
211
|
-
--shadow-2xl: 0px 6px 12px 0px #1f232912;
|
212
|
-
--spacing: .3rem;
|
213
168
|
}
|
214
169
|
|
215
170
|
.dark {
|
216
|
-
--color-background: #0a0a0a;
|
217
|
-
--color-foreground: #ebebeb;
|
218
|
-
--color-card: #1a1a1a;
|
219
|
-
--color-card-foreground: #ebebeb;
|
220
|
-
--color-popover: #1a1a1a;
|
221
|
-
--color-popover-foreground: #ebebeb;
|
222
|
-
--color-primary: #336df4;
|
223
|
-
--color-primary-foreground: #ebebeb;
|
224
|
-
--color-secondary: #27272a;
|
225
|
-
--color-secondary-foreground: #fafafa;
|
226
|
-
--color-muted: #1a1a1a;
|
227
|
-
--color-muted-foreground: #9f9fa9;
|
228
|
-
--color-accent: #373737;
|
229
|
-
--color-accent-foreground: #fafafa;
|
230
|
-
--color-destructive: #f05b56;
|
231
|
-
--color-border: #ebebeb26;
|
232
|
-
--color-input: #ebebeb26;
|
233
|
-
--color-ring: #505050;
|
234
|
-
--color-chart-1: #336df4;
|
235
|
-
--color-chart-2: #00bc7d;
|
236
|
-
--color-chart-3: #fe9a00;
|
237
|
-
--color-chart-4: #ad46ff;
|
238
|
-
--color-chart-5: #ff2056;
|
239
|
-
--color-sidebar: #18181b;
|
240
|
-
--color-sidebar-foreground: #ebebeb;
|
241
|
-
--color-sidebar-primary: #336df4;
|
242
|
-
--color-sidebar-primary-foreground: #fafafa;
|
243
|
-
--color-sidebar-accent: #27272a;
|
244
|
-
--color-sidebar-accent-foreground: #fafafa;
|
245
|
-
--color-sidebar-border: #ffffff1a;
|
246
|
-
--color-sidebar-ring: #71717b;
|
247
171
|
--color-blue-50: #152340;
|
248
172
|
--color-blue-100: #173166;
|
249
173
|
--color-blue-200: #194294;
|
@@ -406,30 +330,6 @@
|
|
406
330
|
--bgTextSelection: 117, 164, 255, .3;
|
407
331
|
--lineDividerDefault: 207, 207, 207, .15;
|
408
332
|
--lineDividerModule: 0, 0, 0, 1;
|
409
|
-
--shadow-2xs: 0 1px 3px 0px #0000000d;
|
410
|
-
--shadow-xs: 0 1px 3px 0px #0000000d;
|
411
|
-
--shadow-sm: 0 1px 3px 0px #0000001a, 0 1px 2px -1px #0000001a;
|
412
|
-
--shadow: 0 1px 3px 0px #0000001a, 0 1px 2px -1px #0000001a;
|
413
|
-
--shadow-md: 0 1px 3px 0px #0000001a, 0 2px 4px -1px #0000001a;
|
414
|
-
--shadow-lg: 0 1px 3px 0px #0000001a, 0 4px 6px -1px #0000001a;
|
415
|
-
--shadow-xl: 0 1px 3px 0px #0000001a, 0 8px 10px -1px #0000001a;
|
416
|
-
--shadow-2xl: 0 1px 3px 0px #00000040;
|
417
333
|
}
|
418
334
|
}
|
419
335
|
|
420
|
-
@layer components, utilities;
|
421
|
-
|
422
|
-
@source inline("text-{xs,sm,base,lg,xl,2xl,3xl,4xl,5xl,6xl,7xl,8xl,9xl}");
|
423
|
-
|
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}");
|
425
|
-
|
426
|
-
@source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}");
|
427
|
-
|
428
|
-
@source inline("{bg,text,border}-neutral-{00,1000}");
|
429
|
-
|
430
|
-
@source inline("rounded-{none,sm,md,lg,xl,full}");
|
431
|
-
|
432
|
-
@theme {
|
433
|
-
--color-background: var(--color-background) ; --color-foreground: var(--color-foreground) ; --color-card: var(--color-card) ; --color-card-foreground: var(--color-card-foreground) ; --color-popover: var(--color-popover) ; --color-popover-foreground: var(--color-popover-foreground) ; --color-primary: var(--color-primary) ; --color-primary-foreground: var(--color-primary-foreground) ; --color-secondary: var(--color-secondary) ; --color-secondary-foreground: var(--color-secondary-foreground) ; --color-muted: var(--color-muted) ; --color-muted-foreground: var(--color-muted-foreground) ; --color-accent: var(--color-accent) ; --color-accent-foreground: var(--color-accent-foreground) ; --color-destructive: var(--color-destructive) ; --color-border: var(--color-border) ; --color-input: var(--color-input) ; --color-ring: var(--color-ring) ; --color-chart-1: var(--color-chart-1) ; --color-chart-2: var(--color-chart-2) ; --color-chart-3: var(--color-chart-3) ; --color-chart-4: var(--color-chart-4) ; --color-chart-5: var(--color-chart-5) ; --color-sidebar: var(--color-sidebar) ; --color-sidebar-foreground: var(--color-sidebar-foreground) ; --color-sidebar-primary: var(--color-sidebar-primary) ; --color-sidebar-primary-foreground: var(--color-sidebar-primary-foreground) ; --color-sidebar-accent: var(--color-sidebar-accent) ; --color-sidebar-accent-foreground: var(--color-sidebar-accent-foreground) ; --color-sidebar-border: var(--color-sidebar-border) ; --color-sidebar-ring: var(--color-sidebar-ring) ; --color-crm-blue: #3b82f6; --color-crm-lightBlue: #93c5fd; --color-crm-darkBlue: #1e40af; --color-crm-gray: #6b7280; --color-crm-lightGray: #e5e7eb; --color-crm-darkGray: #374151; --font-sans: var(--font-sans) ; --font-mono: var(--font-mono) ; --font-serif: var(--font-serif) ; --radius-sm: calc(var(--radius) - 4px) ; --radius: var(--radius) ; --radius-md: calc(var(--radius) - 2px) ; --radius-lg: var(--radius) ; --radius-xl: calc(var(--radius) + 4px) ; --shadow-2xs: var(--shadow-2xs) ; --shadow-xs: var(--shadow-xs) ; --shadow-sm: var(--shadow-sm) ; --shadow: var(--shadow) ; --shadow-md: var(--shadow-md) ; --shadow-lg: var(--shadow-lg) ; --shadow-xl: var(--shadow-xl) ; --shadow-2xl: var(--shadow-2xl) ;
|
434
|
-
}
|
435
|
-
|
package/lib/types/common.d.ts
CHANGED
@@ -0,0 +1,45 @@
|
|
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 interface HmrMessage extends IframeMessage<Record<string, never>> {
|
34
|
+
type: 'Hmr';
|
35
|
+
}
|
36
|
+
export type OutgoingMessage = PreviewReadyMessage | HmrMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | UpdateRoutesMessage;
|
37
|
+
export interface GetRoutesMessage extends IframeMessage<Record<string, never>> {
|
38
|
+
type: 'GetRoutes';
|
39
|
+
}
|
40
|
+
export type IncomingMessage = GetRoutesMessage;
|
41
|
+
export interface ParentApi {
|
42
|
+
}
|
43
|
+
export interface ChildApi {
|
44
|
+
getRoutes: () => Promise<any[]>;
|
45
|
+
}
|
File without changes
|
package/lib/types/index.d.ts
CHANGED
package/lib/utils/getAppId.d.ts
CHANGED
@@ -1,11 +1,6 @@
|
|
1
|
-
declare global {
|
2
|
-
interface Window {
|
3
|
-
MIAODA_APP_ID?: string;
|
4
|
-
}
|
5
|
-
}
|
6
1
|
/**
|
7
2
|
* 提取固定前缀后的第一个目录名
|
8
3
|
* @param {string} path - 输入路径字符串
|
9
4
|
* @returns {string|null} - 提取的目录名或null
|
10
5
|
*/
|
11
|
-
export declare function getAppId(path: string): string;
|
6
|
+
export declare function getAppId(path: string): string | null;
|
package/lib/utils/getAppId.js
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
function getAppId(path) {
|
2
2
|
if (window.MIAODA_APP_ID) return window.MIAODA_APP_ID;
|
3
|
-
|
3
|
+
let prefix;
|
4
|
+
prefix = path.includes('/ai/feida/runtime/') ? '/ai/feida/runtime/' : path.includes('/spark/r/') ? '/spark/r/' : '/ai/miaoda/';
|
4
5
|
if (!path.startsWith(prefix)) return null;
|
5
6
|
const remainder = path.substring(prefix.length);
|
6
7
|
const nextSlashIndex = remainder.indexOf('/');
|
7
|
-
|
8
|
+
if (-1 === nextSlashIndex) return remainder;
|
9
|
+
return remainder.substring(0, nextSlashIndex);
|
8
10
|
}
|
9
11
|
export { getAppId };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
function getCsrfToken() {
|
2
|
+
const cookieName = 'suda-csrf-token';
|
3
|
+
const cookies = document.cookie.split('; ');
|
4
|
+
for (const cookie of cookies){
|
5
|
+
const [name, value] = cookie.split('=');
|
6
|
+
if (name === cookieName) return decodeURIComponent(value);
|
7
|
+
}
|
8
|
+
return window.csrfToken ?? null;
|
9
|
+
}
|
10
|
+
export { getCsrfToken };
|
@@ -0,0 +1,20 @@
|
|
1
|
+
interface AppRuntimeExtra {
|
2
|
+
token?: string;
|
3
|
+
url?: string;
|
4
|
+
bucket?: BucketConfig;
|
5
|
+
}
|
6
|
+
interface AppRuntimePublished {
|
7
|
+
app_name?: string;
|
8
|
+
css_urls?: string[];
|
9
|
+
js_urls?: string[];
|
10
|
+
app_avatar?: string;
|
11
|
+
}
|
12
|
+
interface BucketConfig {
|
13
|
+
default_bucket_id?: string;
|
14
|
+
}
|
15
|
+
/** 获取应用初始化信息(仅全栈沙箱模式下使用) */
|
16
|
+
export declare function getInitialInfo(): Promise<{
|
17
|
+
app_info?: AppRuntimePublished;
|
18
|
+
app_runtime_extra?: AppRuntimeExtra;
|
19
|
+
}>;
|
20
|
+
export {};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { getAppId } from "./getAppId.js";
|
2
|
+
import { getCsrfToken } from "./getCsrfToken.js";
|
3
|
+
async function getAppPublished() {
|
4
|
+
try {
|
5
|
+
const headers = {
|
6
|
+
'Content-Type': 'application/json',
|
7
|
+
'X-Kunlun-Token': window.token,
|
8
|
+
'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
|
9
|
+
'X-Suda-Csrf-Token': getCsrfToken()
|
10
|
+
};
|
11
|
+
const appId = getAppId(window.location.pathname) || window.appId;
|
12
|
+
const url = `${window.location.origin}/spark/b/${appId}/get_published`;
|
13
|
+
const response = await fetch(url, {
|
14
|
+
method: 'GET',
|
15
|
+
headers,
|
16
|
+
credentials: 'include'
|
17
|
+
});
|
18
|
+
const res = await response.json();
|
19
|
+
if (0 === res.code) return res.data;
|
20
|
+
console.error('Error fetching published app info:', res);
|
21
|
+
} catch (error) {
|
22
|
+
console.error('Error fetching published app info:', error);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
let initialInfo;
|
26
|
+
async function getInitialInfo() {
|
27
|
+
if (initialInfo) return initialInfo;
|
28
|
+
initialInfo = await getAppPublished();
|
29
|
+
if (initialInfo) window._bucket_id = initialInfo.app_runtime_extra?.bucket?.default_bucket_id;
|
30
|
+
return initialInfo;
|
31
|
+
}
|
32
|
+
export { getInitialInfo };
|
@@ -1,7 +1,7 @@
|
|
1
1
|
function getPreviewParentOrigin() {
|
2
2
|
const { origin } = window.location;
|
3
|
-
if (origin.includes('feishuapp.
|
4
|
-
if (origin.includes('
|
3
|
+
if (origin.includes('miaoda.feishuapp.net')) return 'https://miaoda.feishu.cn';
|
4
|
+
if (origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
|
5
5
|
return 'https://miaoda.feishu-boe.cn';
|
6
6
|
}
|
7
7
|
export { getPreviewParentOrigin };
|