@lark-apaas/client-toolkit 1.2.7 → 1.2.8-alpha.0
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/components/AppContainer/index.d.ts +1 -1
- package/lib/components/AppContainer/index.js +2 -44
- package/lib/runtime/axios.d.ts +5 -0
- package/lib/runtime/axios.js +2 -0
- package/lib/runtime/dayjs.d.ts +5 -0
- package/lib/runtime/dayjs.js +2 -0
- package/lib/runtime/index.d.ts +23 -0
- package/lib/runtime/index.js +12 -0
- package/lib/runtime/observable.d.ts +5 -0
- package/lib/runtime/observable.js +2 -0
- package/lib/runtime/server-log.d.ts +5 -0
- package/lib/runtime/server-log.js +41 -0
- package/lib/runtime/styles.d.ts +5 -0
- package/lib/runtime/styles.js +1 -0
- package/package.json +6 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect,
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
3
|
import { ConfigProvider } from "antd";
|
|
4
4
|
import { MiaodaInspector } from "@lark-apaas/miaoda-inspector";
|
|
5
5
|
import zh_CN from "antd/locale/zh_CN";
|
|
@@ -8,21 +8,14 @@ import { defaultUIConfig } from "../theme/ui-config.js";
|
|
|
8
8
|
import { Toaster } from "./sonner.js";
|
|
9
9
|
import { PageHoc } from "./PageHoc.js";
|
|
10
10
|
import { findValueByPixel, generateTailwindRadiusToken, themeColorTokenMap, themeMetaOptions } from "../theme/index.js";
|
|
11
|
-
import { registerDayjsPlugins } from "./dayjsPlugins.js";
|
|
12
|
-
import "../../index.css";
|
|
13
|
-
import { initAxiosConfig } from "../../utils/axiosConfig.js";
|
|
14
11
|
import { reportTeaEvent } from "./utils/tea.js";
|
|
15
12
|
import { useAppInfo } from "../../hooks/index.js";
|
|
16
13
|
import { TrackKey } from "../../types/tea.js";
|
|
17
14
|
import safety from "./safety.js";
|
|
18
15
|
import { getAppId } from "../../utils/getAppId.js";
|
|
19
|
-
import { ServerLogSSEClient } from "../../server-log/index.js";
|
|
20
16
|
import QueryProvider from "../QueryProvider/index.js";
|
|
21
|
-
import { initObservable } from "./utils/observable.js";
|
|
22
17
|
import { AuthProvider } from "@lark-apaas/auth-sdk";
|
|
23
|
-
|
|
24
|
-
initAxiosConfig();
|
|
25
|
-
initObservable();
|
|
18
|
+
import "../../runtime/index.js";
|
|
26
19
|
const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
|
|
27
20
|
const readCssVarColor = (varName, fallback)=>{
|
|
28
21
|
try {
|
|
@@ -36,7 +29,6 @@ const readCssVarColor = (varName, fallback)=>{
|
|
|
36
29
|
const App = (props)=>{
|
|
37
30
|
const { themeMeta = {}, enableAuth } = props;
|
|
38
31
|
useAppInfo();
|
|
39
|
-
const serverLogClientRef = useRef(null);
|
|
40
32
|
const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
|
|
41
33
|
rem: '0.625'
|
|
42
34
|
};
|
|
@@ -48,40 +40,6 @@ const App = (props)=>{
|
|
|
48
40
|
borderRadius: radiusToken
|
|
49
41
|
}
|
|
50
42
|
};
|
|
51
|
-
useEffect(()=>{
|
|
52
|
-
if ('production' !== process.env.NODE_ENV && window.parent !== window) {
|
|
53
|
-
try {
|
|
54
|
-
const backendUrl = window.location.origin;
|
|
55
|
-
serverLogClientRef.current = new ServerLogSSEClient({
|
|
56
|
-
serverUrl: backendUrl,
|
|
57
|
-
sseEndpoint: '/dev/logs/server-logs/stream',
|
|
58
|
-
debug: true
|
|
59
|
-
});
|
|
60
|
-
serverLogClientRef.current.start();
|
|
61
|
-
console.log('[AppContainer] Server log SSE client started');
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.error('[AppContainer] Failed to start server log SSE client:', error);
|
|
64
|
-
}
|
|
65
|
-
const handleVisibilityChange = ()=>{
|
|
66
|
-
if (!serverLogClientRef.current) return;
|
|
67
|
-
if (document.hidden) {
|
|
68
|
-
serverLogClientRef.current.pause();
|
|
69
|
-
console.log('[AppContainer] Tab hidden, SSE paused');
|
|
70
|
-
} else {
|
|
71
|
-
serverLogClientRef.current.resume();
|
|
72
|
-
console.log('[AppContainer] Tab visible, SSE resumed');
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
76
|
-
return ()=>{
|
|
77
|
-
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
78
|
-
if (serverLogClientRef.current) {
|
|
79
|
-
serverLogClientRef.current.stop();
|
|
80
|
-
console.log('[AppContainer] Server log SSE client stopped');
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}, []);
|
|
85
43
|
useEffect(()=>{
|
|
86
44
|
if (isMiaodaPreview) fetch(`${location.origin}/ai/api/feida_preview/csrf`).then(()=>{
|
|
87
45
|
setTimeout(()=>{
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client Toolkit Runtime
|
|
3
|
+
*
|
|
4
|
+
* 全局初始化逻辑,通过 rspack-plugin 自动注入到用户入口之前
|
|
5
|
+
* 无论用户是否使用 AppContainer,这些基础能力始终可用
|
|
6
|
+
*
|
|
7
|
+
* 执行顺序:
|
|
8
|
+
* 1. 全局样式
|
|
9
|
+
* 2. Dayjs 插件注册
|
|
10
|
+
* 3. Axios 配置
|
|
11
|
+
* 4. 可观测初始化
|
|
12
|
+
* 5. Server Log SSE (开发环境)
|
|
13
|
+
*
|
|
14
|
+
* 兼容性说明:
|
|
15
|
+
* - 使用 __FULLSTACK_RUNTIME_INITIALIZED__ 标志位防止重复初始化
|
|
16
|
+
* - 旧版 AppContainer 和新版 runtime 可以共存
|
|
17
|
+
*/
|
|
18
|
+
import './styles';
|
|
19
|
+
declare global {
|
|
20
|
+
interface Window {
|
|
21
|
+
__FULLSTACK_RUNTIME_INITIALIZED__?: boolean;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./styles.js";
|
|
2
|
+
import { registerDayjsPlugins } from "./dayjs.js";
|
|
3
|
+
import { initAxiosConfig } from "./axios.js";
|
|
4
|
+
import { initObservable } from "./observable.js";
|
|
5
|
+
import { initServerLog } from "./server-log.js";
|
|
6
|
+
if (!window.__FULLSTACK_RUNTIME_INITIALIZED__) {
|
|
7
|
+
window.__FULLSTACK_RUNTIME_INITIALIZED__ = true;
|
|
8
|
+
registerDayjsPlugins();
|
|
9
|
+
initAxiosConfig();
|
|
10
|
+
initObservable();
|
|
11
|
+
if ('production' !== process.env.NODE_ENV) initServerLog();
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ServerLogSSEClient } from "../server-log/index.js";
|
|
2
|
+
let client = null;
|
|
3
|
+
function initServerLog() {
|
|
4
|
+
if (window.parent === window) return;
|
|
5
|
+
try {
|
|
6
|
+
const backendUrl = window.location.origin;
|
|
7
|
+
client = new ServerLogSSEClient({
|
|
8
|
+
serverUrl: backendUrl,
|
|
9
|
+
sseEndpoint: '/dev/logs/server-logs/stream',
|
|
10
|
+
debug: true
|
|
11
|
+
});
|
|
12
|
+
client.start();
|
|
13
|
+
console.log('[Runtime] Server log SSE client started');
|
|
14
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
15
|
+
window.addEventListener('beforeunload', cleanup);
|
|
16
|
+
window.addEventListener('unload', cleanup);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error('[Runtime] Failed to start server log SSE client:', error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function handleVisibilityChange() {
|
|
22
|
+
if (!client) return;
|
|
23
|
+
if (document.hidden) {
|
|
24
|
+
client.pause();
|
|
25
|
+
console.log('[Runtime] Tab hidden, SSE paused');
|
|
26
|
+
} else {
|
|
27
|
+
client.resume();
|
|
28
|
+
console.log('[Runtime] Tab visible, SSE resumed');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function cleanup() {
|
|
32
|
+
if (client) {
|
|
33
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
34
|
+
window.removeEventListener('beforeunload', cleanup);
|
|
35
|
+
window.removeEventListener('unload', cleanup);
|
|
36
|
+
client.stop();
|
|
37
|
+
client = null;
|
|
38
|
+
console.log('[Runtime] Server log SSE client stopped');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export { initServerLog };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../index.css";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8-alpha.0",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"require": "./lib/index.js",
|
|
16
16
|
"types": "./lib/index.d.ts"
|
|
17
17
|
},
|
|
18
|
+
"./runtime": {
|
|
19
|
+
"import": "./lib/runtime/index.js",
|
|
20
|
+
"require": "./lib/runtime/index.js",
|
|
21
|
+
"types": "./lib/runtime/index.d.ts"
|
|
22
|
+
},
|
|
18
23
|
"./antd-table": {
|
|
19
24
|
"import": "./lib/antd-table.js",
|
|
20
25
|
"require": "./lib/antd-table.js",
|