@lark-apaas/client-toolkit 1.2.28-alpha.71 → 1.2.28-alpha.72
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
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";
|
|
@@ -10,33 +10,20 @@ import { reportTeaEvent } from "./utils/tea.js";
|
|
|
10
10
|
import { useAppInfo } from "../../hooks/index.js";
|
|
11
11
|
import { TrackKey } from "../../types/tea.js";
|
|
12
12
|
import { slardar } from "@lark-apaas/internal-slardar";
|
|
13
|
+
import safety from "./safety.js";
|
|
13
14
|
import { getAppId } from "../../utils/getAppId.js";
|
|
14
15
|
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
15
16
|
import QueryProvider from "../QueryProvider/index.js";
|
|
16
17
|
import { AuthProvider } from "@lark-apaas/auth-sdk";
|
|
17
18
|
import "../../runtime/index.js";
|
|
18
|
-
const Safety = /*#__PURE__*/ react.lazy(()=>import("./safety.js"));
|
|
19
19
|
const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
|
|
20
|
-
const
|
|
20
|
+
const readCssVarColor = (varName, fallback)=>{
|
|
21
21
|
try {
|
|
22
|
-
if ('undefined' == typeof document) return
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
background: read('--background'),
|
|
27
|
-
destructive: read('--destructive'),
|
|
28
|
-
primary: read('--primary'),
|
|
29
|
-
foreground: read('--foreground'),
|
|
30
|
-
warning: read('--warning'),
|
|
31
|
-
success: read('--success'),
|
|
32
|
-
muted: read('--muted'),
|
|
33
|
-
mutedForeground: read('--muted-foreground'),
|
|
34
|
-
border: read('--border'),
|
|
35
|
-
popover: read('--popover'),
|
|
36
|
-
accent: read('--accent')
|
|
37
|
-
};
|
|
22
|
+
if ('undefined' == typeof document) return fallback;
|
|
23
|
+
const value = getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
|
|
24
|
+
return value || fallback;
|
|
38
25
|
} catch {
|
|
39
|
-
return
|
|
26
|
+
return fallback;
|
|
40
27
|
}
|
|
41
28
|
};
|
|
42
29
|
const appFlags = process.env.APP_FLAGS || {};
|
|
@@ -82,17 +69,13 @@ const App = (props)=>{
|
|
|
82
69
|
}, []);
|
|
83
70
|
const appId = getAppId();
|
|
84
71
|
const permissionApiUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/permissions/roles` : `/spark/app/${appId}/runtime/api/v1/permissions/roles`;
|
|
85
|
-
|
|
72
|
+
return /*#__PURE__*/ jsxs(AuthProvider, {
|
|
73
|
+
config: {
|
|
86
74
|
enable: enableAuth,
|
|
87
75
|
permissionApi: {
|
|
88
76
|
url: permissionApiUrl
|
|
89
77
|
}
|
|
90
|
-
}
|
|
91
|
-
enableAuth,
|
|
92
|
-
permissionApiUrl
|
|
93
|
-
]);
|
|
94
|
-
return /*#__PURE__*/ jsxs(AuthProvider, {
|
|
95
|
-
config: authConfig,
|
|
78
|
+
},
|
|
96
79
|
children: [
|
|
97
80
|
!disableToaster && true !== appFlags.customToaster && /*#__PURE__*/ jsx(Toaster, {}),
|
|
98
81
|
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {}),
|
|
@@ -105,7 +88,19 @@ const App = (props)=>{
|
|
|
105
88
|
};
|
|
106
89
|
const AppContainer_AppContainer = (props)=>{
|
|
107
90
|
const { children } = props;
|
|
108
|
-
const [cssColors, setCssColors] = useState(
|
|
91
|
+
const [cssColors, setCssColors] = useState(()=>({
|
|
92
|
+
background: readCssVarColor('--background'),
|
|
93
|
+
destructive: readCssVarColor('--destructive'),
|
|
94
|
+
primary: readCssVarColor('--primary'),
|
|
95
|
+
foreground: readCssVarColor('--foreground'),
|
|
96
|
+
warning: readCssVarColor('--warning'),
|
|
97
|
+
success: readCssVarColor('--success'),
|
|
98
|
+
muted: readCssVarColor('--muted'),
|
|
99
|
+
mutedForeground: readCssVarColor('--muted-foreground'),
|
|
100
|
+
border: readCssVarColor('--border'),
|
|
101
|
+
popover: readCssVarColor('--popover'),
|
|
102
|
+
accent: readCssVarColor('--accent')
|
|
103
|
+
}));
|
|
109
104
|
useEffect(()=>{
|
|
110
105
|
if ('production' === process.env.NODE_ENV) return ()=>{};
|
|
111
106
|
const observer = new MutationObserver((mutations)=>{
|
|
@@ -124,7 +119,19 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
124
119
|
const maxRetries = 10;
|
|
125
120
|
const retryDelay = 400;
|
|
126
121
|
const updateColors = ()=>{
|
|
127
|
-
const newColors =
|
|
122
|
+
const newColors = {
|
|
123
|
+
background: readCssVarColor('--background'),
|
|
124
|
+
destructive: readCssVarColor('--destructive'),
|
|
125
|
+
primary: readCssVarColor('--primary'),
|
|
126
|
+
foreground: readCssVarColor('--foreground'),
|
|
127
|
+
warning: readCssVarColor('--warning'),
|
|
128
|
+
success: readCssVarColor('--success'),
|
|
129
|
+
muted: readCssVarColor('--muted'),
|
|
130
|
+
mutedForeground: readCssVarColor('--muted-foreground'),
|
|
131
|
+
border: readCssVarColor('--border'),
|
|
132
|
+
popover: readCssVarColor('--popover'),
|
|
133
|
+
accent: readCssVarColor('--accent')
|
|
134
|
+
};
|
|
128
135
|
setCssColors((currentColors)=>{
|
|
129
136
|
if (JSON.stringify(currentColors) !== JSON.stringify(newColors)) {
|
|
130
137
|
retryCount = 0;
|
|
@@ -196,10 +203,7 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
196
203
|
};
|
|
197
204
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
198
205
|
children: [
|
|
199
|
-
/*#__PURE__*/ jsx(
|
|
200
|
-
fallback: null,
|
|
201
|
-
children: /*#__PURE__*/ jsx(Safety, {})
|
|
202
|
-
}),
|
|
206
|
+
/*#__PURE__*/ jsx(safety, {}),
|
|
203
207
|
/*#__PURE__*/ jsx(QueryProvider, {
|
|
204
208
|
children: /*#__PURE__*/ jsx(ConfigProvider, {
|
|
205
209
|
locale: zh_CN,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js";
|
|
4
|
+
import { getCsrfToken } from "../../utils/getCsrfToken.js";
|
|
4
5
|
import { getAppId } from "../../utils/getAppId.js";
|
|
6
|
+
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
5
7
|
import { useIsMobile } from "../../hooks/index.js";
|
|
6
8
|
import { X } from "lucide-react";
|
|
7
9
|
import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
|
|
@@ -11,11 +13,35 @@ const Component = ()=>{
|
|
|
11
13
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
12
14
|
const [open, setOpen] = useState(false);
|
|
13
15
|
const isMobile = useIsMobile();
|
|
16
|
+
const [userinfo, setUserinfo] = useState(null);
|
|
17
|
+
const [isInternetVisible, setIsInternetVisible] = useState(false);
|
|
18
|
+
const [showBadge, setShowBadge] = useState(true);
|
|
19
|
+
const [badgeLoaded, setBadgeLoaded] = useState(false);
|
|
14
20
|
const timeoutRef = useRef(null);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
useEffect(()=>{
|
|
22
|
+
const appId = getAppId();
|
|
23
|
+
const csrfHeaders = {
|
|
24
|
+
'X-Suda-Csrf-Token': getCsrfToken()
|
|
25
|
+
};
|
|
26
|
+
const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
|
|
27
|
+
fetch(tenantInfoUrl, {
|
|
28
|
+
headers: csrfHeaders
|
|
29
|
+
}).then((res)=>res.json()).then((data)=>{
|
|
30
|
+
setUserinfo(data?.data?.tenant_info);
|
|
31
|
+
setIsInternetVisible(data?.data?.is_internet_visible);
|
|
32
|
+
}).catch(()=>{});
|
|
33
|
+
const getPublishedUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/get_published` : `/spark/b/${appId}/get_published`;
|
|
34
|
+
fetch(getPublishedUrl, {
|
|
35
|
+
headers: csrfHeaders
|
|
36
|
+
}).then((res)=>res.json()).then((data)=>{
|
|
37
|
+
const badge = data?.data?.app_info?.show_badge;
|
|
38
|
+
setShowBadge(false !== badge);
|
|
39
|
+
}).catch(()=>{
|
|
40
|
+
setShowBadge(true);
|
|
41
|
+
}).finally(()=>{
|
|
42
|
+
setBadgeLoaded(true);
|
|
43
|
+
});
|
|
44
|
+
}, []);
|
|
19
45
|
useEffect(()=>{
|
|
20
46
|
if (isMobile) {
|
|
21
47
|
const link = document.createElement('link');
|
|
@@ -28,6 +54,7 @@ const Component = ()=>{
|
|
|
28
54
|
isMobile
|
|
29
55
|
]);
|
|
30
56
|
if ('production' !== process.env.NODE_ENV) return null;
|
|
57
|
+
if (!badgeLoaded) return null;
|
|
31
58
|
if (!showBadge) return null;
|
|
32
59
|
if (!visible) return null;
|
|
33
60
|
if (isMobile) return /*#__PURE__*/ jsxs(Sheet, {
|
|
@@ -87,7 +114,7 @@ const Component = ()=>{
|
|
|
87
114
|
/*#__PURE__*/ jsx("p", {
|
|
88
115
|
className: "shrink-0 min-w-[96px] m-0! text-[#646A73] text-sm",
|
|
89
116
|
children: t('safety.tenant.operated', {
|
|
90
|
-
name:
|
|
117
|
+
name: userinfo?.name ?? ''
|
|
91
118
|
})
|
|
92
119
|
})
|
|
93
120
|
]
|
|
@@ -206,7 +233,7 @@ const Component = ()=>{
|
|
|
206
233
|
/*#__PURE__*/ jsx("p", {
|
|
207
234
|
className: "shrink-0 min-w-[96px] m-0! text-[#a6a6a6]",
|
|
208
235
|
children: t('safety.tenant.operated', {
|
|
209
|
-
name:
|
|
236
|
+
name: userinfo?.name ?? ''
|
|
210
237
|
})
|
|
211
238
|
})
|
|
212
239
|
]
|
|
@@ -24,24 +24,10 @@ async function getAppPublished() {
|
|
|
24
24
|
console.error('Error fetching published app info:', error);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function getPreloadedInfo() {
|
|
28
|
-
try {
|
|
29
|
-
const platformData = window.__platform__?.appPublished;
|
|
30
|
-
if (platformData && 'object' == typeof platformData) return platformData;
|
|
31
|
-
} catch {}
|
|
32
|
-
}
|
|
33
27
|
let initialInfo;
|
|
34
28
|
let pendingPromise = null;
|
|
35
29
|
function getInitialInfo(refresh = false) {
|
|
36
30
|
if (initialInfo && !refresh) return Promise.resolve(initialInfo);
|
|
37
|
-
if (!initialInfo && !refresh) {
|
|
38
|
-
const preloaded = getPreloadedInfo();
|
|
39
|
-
if (preloaded) {
|
|
40
|
-
initialInfo = preloaded;
|
|
41
|
-
if (initialInfo) window._bucket_id = initialInfo.app_runtime_extra?.bucket?.default_bucket_id;
|
|
42
|
-
return Promise.resolve(initialInfo);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
31
|
if (pendingPromise && !refresh) return pendingPromise;
|
|
46
32
|
pendingPromise = getAppPublished().then((info)=>{
|
|
47
33
|
initialInfo = info;
|