@lark-apaas/client-toolkit 1.2.17 → 1.2.18-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/lib/components/AppContainer/index.d.ts +5 -1
- package/lib/components/AppContainer/index.js +6 -25
- package/lib/components/theme/index.d.ts +0 -1
- package/lib/components/theme/index.js +0 -1
- package/lib/components/theme/util.d.ts +0 -2
- package/lib/components/theme/util.js +0 -108
- package/lib/integrations/services/types.d.ts +1 -0
- package/lib/runtime/index.d.ts +1 -0
- package/lib/runtime/index.js +1 -0
- package/lib/runtime/react-devtools-hook.d.ts +19 -0
- package/lib/runtime/react-devtools-hook.js +20 -0
- package/lib/utils/postMessage.js +18 -0
- package/package.json +2 -2
- package/lib/components/theme/ui-config.d.ts +0 -1
- package/lib/components/theme/ui-config.js +0 -2
|
@@ -4,7 +4,11 @@ import '../../runtime';
|
|
|
4
4
|
interface IBaseAuthProviderProps {
|
|
5
5
|
enableAuth?: boolean;
|
|
6
6
|
}
|
|
7
|
+
interface IToasterProps {
|
|
8
|
+
/** 禁用内建 Toaster 组件,默认 false */
|
|
9
|
+
disableToaster?: boolean;
|
|
10
|
+
}
|
|
7
11
|
declare const AppContainer: React.FC<{
|
|
8
12
|
children: React.ReactNode;
|
|
9
|
-
} & IBaseThemeProviderProps & IBaseAuthProviderProps>;
|
|
13
|
+
} & IBaseThemeProviderProps & IBaseAuthProviderProps & IToasterProps>;
|
|
10
14
|
export default AppContainer;
|
|
@@ -4,10 +4,8 @@ import { ConfigProvider } from "antd";
|
|
|
4
4
|
import { MiaodaInspector } from "@lark-apaas/miaoda-inspector";
|
|
5
5
|
import zh_CN from "antd/locale/zh_CN";
|
|
6
6
|
import IframeBridge from "./IframeBridge.js";
|
|
7
|
-
import { defaultUIConfig } from "../theme/ui-config.js";
|
|
8
7
|
import { Toaster } from "./sonner.js";
|
|
9
8
|
import { PageHoc } from "./PageHoc.js";
|
|
10
|
-
import { findValueByPixel, generateTailwindRadiusToken, themeColorTokenMap, themeMetaOptions } from "../theme/index.js";
|
|
11
9
|
import { reportTeaEvent } from "./utils/tea.js";
|
|
12
10
|
import { useAppInfo } from "../../hooks/index.js";
|
|
13
11
|
import { TrackKey } from "../../types/tea.js";
|
|
@@ -26,20 +24,10 @@ const readCssVarColor = (varName, fallback)=>{
|
|
|
26
24
|
return fallback;
|
|
27
25
|
}
|
|
28
26
|
};
|
|
27
|
+
const appFlags = process.env.APP_FLAGS || {};
|
|
29
28
|
const App = (props)=>{
|
|
30
|
-
const {
|
|
29
|
+
const { enableAuth, disableToaster = false } = props;
|
|
31
30
|
useAppInfo();
|
|
32
|
-
const { rem } = findValueByPixel(themeMetaOptions.themeRadius, themeMeta.borderRadius) || {
|
|
33
|
-
rem: '0.625'
|
|
34
|
-
};
|
|
35
|
-
const radiusToken = generateTailwindRadiusToken(Number(rem));
|
|
36
|
-
const themeToken = {
|
|
37
|
-
...defaultUIConfig,
|
|
38
|
-
common: {
|
|
39
|
-
...defaultUIConfig.common,
|
|
40
|
-
borderRadius: radiusToken
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
31
|
useEffect(()=>{
|
|
44
32
|
if (isMiaodaPreview) fetch(`${location.origin}/ai/api/feida_preview/csrf`).then(()=>{
|
|
45
33
|
setTimeout(()=>{
|
|
@@ -63,15 +51,8 @@ const App = (props)=>{
|
|
|
63
51
|
enable: enableAuth
|
|
64
52
|
},
|
|
65
53
|
children: [
|
|
66
|
-
/*#__PURE__*/ jsx(Toaster, {}),
|
|
67
|
-
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {
|
|
68
|
-
theme: {
|
|
69
|
-
themeMetaOptions: themeMetaOptions,
|
|
70
|
-
themeColorTokenMap: themeColorTokenMap,
|
|
71
|
-
themeToken
|
|
72
|
-
},
|
|
73
|
-
cwd: process.env.CWD || ''
|
|
74
|
-
}),
|
|
54
|
+
!disableToaster && true !== appFlags.customToaster && /*#__PURE__*/ jsx(Toaster, {}),
|
|
55
|
+
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(MiaodaInspector, {}),
|
|
75
56
|
'production' !== process.env.NODE_ENV && /*#__PURE__*/ jsx(IframeBridge, {}),
|
|
76
57
|
/*#__PURE__*/ jsx(PageHoc, {
|
|
77
58
|
children: props.children
|
|
@@ -80,7 +61,7 @@ const App = (props)=>{
|
|
|
80
61
|
});
|
|
81
62
|
};
|
|
82
63
|
const AppContainer_AppContainer = (props)=>{
|
|
83
|
-
const { children
|
|
64
|
+
const { children } = props;
|
|
84
65
|
const [cssColors, setCssColors] = useState(()=>({
|
|
85
66
|
background: readCssVarColor('--background'),
|
|
86
67
|
destructive: readCssVarColor('--destructive'),
|
|
@@ -208,8 +189,8 @@ const AppContainer_AppContainer = (props)=>{
|
|
|
208
189
|
}
|
|
209
190
|
},
|
|
210
191
|
children: /*#__PURE__*/ jsx(App, {
|
|
211
|
-
themeMeta: props.themeMeta,
|
|
212
192
|
enableAuth: props.enableAuth,
|
|
193
|
+
disableToaster: props.disableToaster,
|
|
213
194
|
children: children
|
|
214
195
|
})
|
|
215
196
|
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ITheme } from "../../types";
|
|
2
|
-
import { UIComponentConfig } from "./ui-config";
|
|
3
2
|
export interface IBaseThemeProviderProps {
|
|
4
3
|
defaultTheme?: ITheme;
|
|
5
4
|
themeMeta?: Partial<IThemeTokenMeta>;
|
|
@@ -18,4 +17,3 @@ export interface IThemeTokenMeta {
|
|
|
18
17
|
*/
|
|
19
18
|
spacing: number;
|
|
20
19
|
}
|
|
21
|
-
export declare const generateTailwindRadiusToken: (radiusRemValue: number) => UIComponentConfig;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const generateTailwindRadiusToken = (radiusRemValue)=>{
|
|
2
|
-
try {
|
|
3
|
-
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
4
|
-
const radiusPx = radiusRemValue * rootFontSize;
|
|
5
|
-
const tempElement = document.createElement('div');
|
|
6
|
-
tempElement.style.position = 'absolute';
|
|
7
|
-
tempElement.style.visibility = 'hidden';
|
|
8
|
-
document.body.appendChild(tempElement);
|
|
9
|
-
tempElement.style.borderRadius = `${radiusPx}px`;
|
|
10
|
-
const computed = getComputedStyle(tempElement).borderRadius;
|
|
11
|
-
document.body.removeChild(tempElement);
|
|
12
|
-
if (computed && 'auto' !== computed && 'initial' !== computed) return {
|
|
13
|
-
type: 'select',
|
|
14
|
-
options: [
|
|
15
|
-
{
|
|
16
|
-
value: 'rounded-none',
|
|
17
|
-
label: 'none(0px)',
|
|
18
|
-
rawValue: '0'
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
value: 'rounded-sm',
|
|
22
|
-
label: `sm (${Math.max(0, radiusPx - 4)}px)`,
|
|
23
|
-
rawValue: `${Math.max(0, radiusPx - 4)}`
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
value: 'rounded',
|
|
27
|
-
label: 's (4px)',
|
|
28
|
-
rawValue: '4'
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
value: 'rounded-md',
|
|
32
|
-
label: `m (${Math.max(0, radiusPx - 2)}px)`,
|
|
33
|
-
rawValue: `${Math.max(0, radiusPx - 2)}`
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
value: 'rounded-lg',
|
|
37
|
-
label: `l (${radiusPx}px)`,
|
|
38
|
-
rawValue: `${radiusPx}`
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
value: 'rounded-xl',
|
|
42
|
-
label: `xl (${radiusPx + 4}px)`,
|
|
43
|
-
rawValue: `${radiusPx + 4}`
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
value: 'rounded-2xl',
|
|
47
|
-
label: '2xl (16px)',
|
|
48
|
-
rawValue: '16'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
value: 'rounded-full',
|
|
52
|
-
label: 'Full',
|
|
53
|
-
rawValue: '9999'
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
};
|
|
57
|
-
throw new Error('Browser calculation validation failed');
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.warn('Failed to get computed values from browser, falling back to default calculation:', error);
|
|
60
|
-
const radiusPx = 16 * radiusRemValue;
|
|
61
|
-
return {
|
|
62
|
-
type: 'select',
|
|
63
|
-
options: [
|
|
64
|
-
{
|
|
65
|
-
value: 'rounded-none',
|
|
66
|
-
label: 'none(0px)',
|
|
67
|
-
rawValue: '0'
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
value: 'rounded-sm',
|
|
71
|
-
label: `sm (${Math.max(0, radiusPx - 4)}px)`,
|
|
72
|
-
rawValue: `${Math.max(0, radiusPx - 4)}`
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
value: 'rounded',
|
|
76
|
-
label: 's (4px)',
|
|
77
|
-
rawValue: '4'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
value: 'rounded-md',
|
|
81
|
-
label: `m (${Math.max(0, radiusPx - 2)}px)`,
|
|
82
|
-
rawValue: `${Math.max(0, radiusPx - 2)}`
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
value: 'rounded-lg',
|
|
86
|
-
label: `l (${radiusPx}px)`,
|
|
87
|
-
rawValue: `${radiusPx}`
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
value: 'rounded-xl',
|
|
91
|
-
label: `xl (${radiusPx + 4}px)`,
|
|
92
|
-
rawValue: `${radiusPx + 4}`
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
value: 'rounded-2xl',
|
|
96
|
-
label: '2xl (16px)',
|
|
97
|
-
rawValue: '16'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
value: 'rounded-full',
|
|
101
|
-
label: 'Full',
|
|
102
|
-
rawValue: '9999'
|
|
103
|
-
}
|
|
104
|
-
]
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
export { generateTailwindRadiusToken };
|
package/lib/runtime/index.d.ts
CHANGED
package/lib/runtime/index.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inject minimal __REACT_DEVTOOLS_GLOBAL_HOOK__ before React loads.
|
|
3
|
+
* React checks for this hook during module initialization and registers its
|
|
4
|
+
* renderer via hook.inject(). This gives us access to renderer.overrideProps()
|
|
5
|
+
* for live component prop modification in the inspector.
|
|
6
|
+
*
|
|
7
|
+
* Must execute before React's module-level code runs.
|
|
8
|
+
*
|
|
9
|
+
* When react-refresh-runtime runs first (as an rspack runtime module),
|
|
10
|
+
* it may create __REACT_DEVTOOLS_GLOBAL_HOOK__ with an inject() that
|
|
11
|
+
* doesn't populate the renderers Map. We patch the existing hook to
|
|
12
|
+
* ensure renderers are always tracked.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
declare global {
|
|
16
|
+
interface Window {
|
|
17
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__?: any;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
if ('undefined' != typeof window && 'production' !== process.env.NODE_ENV) if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
2
|
+
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
3
|
+
if (!(hook.renderers instanceof Map)) hook.renderers = new Map();
|
|
4
|
+
const originalInject = 'function' == typeof hook.inject ? hook.inject.bind(hook) : null;
|
|
5
|
+
hook.inject = function(renderer) {
|
|
6
|
+
const id = originalInject ? originalInject(renderer) : hook.renderers.size + 1;
|
|
7
|
+
if (null != id && !hook.renderers.has(id)) hook.renderers.set(id, renderer);
|
|
8
|
+
return id;
|
|
9
|
+
};
|
|
10
|
+
} else window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
|
|
11
|
+
renderers: new Map(),
|
|
12
|
+
supportsFiber: true,
|
|
13
|
+
inject (renderer) {
|
|
14
|
+
const id = this.renderers.size + 1;
|
|
15
|
+
this.renderers.set(id, renderer);
|
|
16
|
+
return id;
|
|
17
|
+
},
|
|
18
|
+
onCommitFiberRoot () {},
|
|
19
|
+
onCommitFiberUnmount () {}
|
|
20
|
+
};
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
const PARENT_ORIGIN_KEY = '__parentOrigin';
|
|
2
|
+
function getParentOriginFromParams() {
|
|
3
|
+
try {
|
|
4
|
+
const params = new URLSearchParams(window.location.search);
|
|
5
|
+
const origin = params.get(PARENT_ORIGIN_KEY);
|
|
6
|
+
if (origin) {
|
|
7
|
+
sessionStorage.setItem(PARENT_ORIGIN_KEY, origin);
|
|
8
|
+
return origin;
|
|
9
|
+
}
|
|
10
|
+
} catch {}
|
|
11
|
+
try {
|
|
12
|
+
return sessionStorage.getItem(PARENT_ORIGIN_KEY) || void 0;
|
|
13
|
+
} catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
1
17
|
function getLegacyParentOrigin() {
|
|
2
18
|
const { origin } = window.location;
|
|
3
19
|
if (origin.includes('force.feishuapp.net')) return 'https://force.feishu.cn';
|
|
@@ -8,6 +24,8 @@ function getLegacyParentOrigin() {
|
|
|
8
24
|
return 'https://miaoda.feishu-boe.cn';
|
|
9
25
|
}
|
|
10
26
|
function resolveParentOrigin() {
|
|
27
|
+
const paramOrigin = getParentOriginFromParams();
|
|
28
|
+
if (paramOrigin) return paramOrigin;
|
|
11
29
|
return process.env?.FORCE_FRAMEWORK_DOMAIN_MAIN ?? getLegacyParentOrigin();
|
|
12
30
|
}
|
|
13
31
|
function submitPostMessage(message, targetOrigin) {
|
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.18-alpha.1",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"@data-loom/js": "0.4.7",
|
|
97
97
|
"@lark-apaas/auth-sdk": "^0.1.0",
|
|
98
98
|
"@lark-apaas/client-capability": "^0.1.4",
|
|
99
|
-
"@lark-apaas/miaoda-inspector": "
|
|
99
|
+
"@lark-apaas/miaoda-inspector": "1.0.14-alpha.21",
|
|
100
100
|
"@lark-apaas/observable-web": "^1.0.1",
|
|
101
101
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
102
102
|
"@radix-ui/react-popover": "^1.1.15",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { defaultUIConfig, type UIComponentConfig, } from '@lark-apaas/miaoda-inspector';
|