@lark-apaas/client-toolkit 1.2.28-alpha.72 → 1.2.28-alpha.74
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 { useEffect, useState } from "react";
|
|
2
|
+
import react, { Suspense, useEffect, useMemo, 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,20 +10,33 @@ 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";
|
|
14
13
|
import { getAppId } from "../../utils/getAppId.js";
|
|
15
14
|
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
16
15
|
import QueryProvider from "../QueryProvider/index.js";
|
|
17
16
|
import { AuthProvider } from "@lark-apaas/auth-sdk";
|
|
18
17
|
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 readAllCssVarColors = ()=>{
|
|
21
21
|
try {
|
|
22
|
-
if ('undefined' == typeof document) return
|
|
23
|
-
const
|
|
24
|
-
|
|
22
|
+
if ('undefined' == typeof document) return {};
|
|
23
|
+
const styles = getComputedStyle(document.documentElement);
|
|
24
|
+
const read = (name)=>styles.getPropertyValue(name).trim() || void 0;
|
|
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
|
+
};
|
|
25
38
|
} catch {
|
|
26
|
-
return
|
|
39
|
+
return {};
|
|
27
40
|
}
|
|
28
41
|
};
|
|
29
42
|
const appFlags = process.env.APP_FLAGS || {};
|
|
@@ -69,13 +82,17 @@ const App = (props)=>{
|
|
|
69
82
|
}, []);
|
|
70
83
|
const appId = getAppId();
|
|
71
84
|
const permissionApiUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/permissions/roles` : `/spark/app/${appId}/runtime/api/v1/permissions/roles`;
|
|
72
|
-
|
|
73
|
-
config: {
|
|
85
|
+
const authConfig = useMemo(()=>({
|
|
74
86
|
enable: enableAuth,
|
|
75
87
|
permissionApi: {
|
|
76
88
|
url: permissionApiUrl
|
|
77
89
|
}
|
|
78
|
-
},
|
|
90
|
+
}), [
|
|
91
|
+
enableAuth,
|
|
92
|
+
permissionApiUrl
|
|
93
|
+
]);
|
|
94
|
+
return /*#__PURE__*/ jsxs(AuthProvider, {
|
|
95
|
+
config: authConfig,
|
|
79
96
|
children: [
|
|
80
97
|
!disableToaster && true !== appFlags.customToaster && /*#__PURE__*/ jsx(Toaster, {}),
|
|
81
98
|
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {}),
|
|
@@ -88,19 +105,7 @@ const App = (props)=>{
|
|
|
88
105
|
};
|
|
89
106
|
const AppContainer_AppContainer = (props)=>{
|
|
90
107
|
const { children } = props;
|
|
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
|
-
}));
|
|
108
|
+
const [cssColors, setCssColors] = useState(readAllCssVarColors);
|
|
104
109
|
useEffect(()=>{
|
|
105
110
|
if ('production' === process.env.NODE_ENV) return ()=>{};
|
|
106
111
|
const observer = new MutationObserver((mutations)=>{
|
|
@@ -119,19 +124,7 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
119
124
|
const maxRetries = 10;
|
|
120
125
|
const retryDelay = 400;
|
|
121
126
|
const updateColors = ()=>{
|
|
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
|
-
};
|
|
127
|
+
const newColors = readAllCssVarColors();
|
|
135
128
|
setCssColors((currentColors)=>{
|
|
136
129
|
if (JSON.stringify(currentColors) !== JSON.stringify(newColors)) {
|
|
137
130
|
retryCount = 0;
|
|
@@ -203,7 +196,10 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
203
196
|
};
|
|
204
197
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
205
198
|
children: [
|
|
206
|
-
/*#__PURE__*/ jsx(
|
|
199
|
+
/*#__PURE__*/ jsx(Suspense, {
|
|
200
|
+
fallback: null,
|
|
201
|
+
children: /*#__PURE__*/ jsx(Safety, {})
|
|
202
|
+
}),
|
|
207
203
|
/*#__PURE__*/ jsx(QueryProvider, {
|
|
208
204
|
children: /*#__PURE__*/ jsx(ConfigProvider, {
|
|
209
205
|
locale: zh_CN,
|
|
@@ -1,9 +1,7 @@
|
|
|
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";
|
|
5
4
|
import { getAppId } from "../../utils/getAppId.js";
|
|
6
|
-
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
7
5
|
import { useIsMobile } from "../../hooks/index.js";
|
|
8
6
|
import { X } from "lucide-react";
|
|
9
7
|
import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
|
|
@@ -13,35 +11,11 @@ const Component = ()=>{
|
|
|
13
11
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
14
12
|
const [open, setOpen] = useState(false);
|
|
15
13
|
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);
|
|
20
14
|
const timeoutRef = useRef(null);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
}, []);
|
|
15
|
+
const platformData = window.__platform__ ?? {};
|
|
16
|
+
const tenantName = platformData.tenantName ?? '';
|
|
17
|
+
const isInternetVisible = platformData.isInternetVisible ?? false;
|
|
18
|
+
const showBadge = false !== platformData.showBadge;
|
|
45
19
|
useEffect(()=>{
|
|
46
20
|
if (isMobile) {
|
|
47
21
|
const link = document.createElement('link');
|
|
@@ -54,7 +28,6 @@ const Component = ()=>{
|
|
|
54
28
|
isMobile
|
|
55
29
|
]);
|
|
56
30
|
if ('production' !== process.env.NODE_ENV) return null;
|
|
57
|
-
if (!badgeLoaded) return null;
|
|
58
31
|
if (!showBadge) return null;
|
|
59
32
|
if (!visible) return null;
|
|
60
33
|
if (isMobile) return /*#__PURE__*/ jsxs(Sheet, {
|
|
@@ -114,7 +87,7 @@ const Component = ()=>{
|
|
|
114
87
|
/*#__PURE__*/ jsx("p", {
|
|
115
88
|
className: "shrink-0 min-w-[96px] m-0! text-[#646A73] text-sm",
|
|
116
89
|
children: t('safety.tenant.operated', {
|
|
117
|
-
name:
|
|
90
|
+
name: tenantName
|
|
118
91
|
})
|
|
119
92
|
})
|
|
120
93
|
]
|
|
@@ -233,7 +206,7 @@ const Component = ()=>{
|
|
|
233
206
|
/*#__PURE__*/ jsx("p", {
|
|
234
207
|
className: "shrink-0 min-w-[96px] m-0! text-[#a6a6a6]",
|
|
235
208
|
children: t('safety.tenant.operated', {
|
|
236
|
-
name:
|
|
209
|
+
name: tenantName
|
|
237
210
|
})
|
|
238
211
|
})
|
|
239
212
|
]
|
|
@@ -24,10 +24,24 @@ 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
|
+
}
|
|
27
33
|
let initialInfo;
|
|
28
34
|
let pendingPromise = null;
|
|
29
35
|
function getInitialInfo(refresh = false) {
|
|
30
36
|
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
|
+
}
|
|
31
45
|
if (pendingPromise && !refresh) return pendingPromise;
|
|
32
46
|
pendingPromise = getAppPublished().then((info)=>{
|
|
33
47
|
initialInfo = info;
|