@lark-apaas/client-toolkit 1.2.3 → 1.2.4-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.
|
@@ -3,8 +3,7 @@ import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
|
3
3
|
import { useLocation, useNavigate } from "react-router-dom";
|
|
4
4
|
import { connectToParent } from "penpal";
|
|
5
5
|
import { useUpdatingRef } from "../../hooks/useUpdatingRef.js";
|
|
6
|
-
import { submitPostMessage } from "../../utils/postMessage.js";
|
|
7
|
-
import { getPreviewParentOrigin } from "../../utils/getParentOrigin.js";
|
|
6
|
+
import { resolveParentOrigin, submitPostMessage } from "../../utils/postMessage.js";
|
|
8
7
|
import { childApi } from "./utils/childApi.js";
|
|
9
8
|
import "./utils/listenHot.js";
|
|
10
9
|
var IframeBridge_RouteMessageType = /*#__PURE__*/ function(RouteMessageType) {
|
|
@@ -21,8 +20,10 @@ async function connectParent() {
|
|
|
21
20
|
type: 'PreviewReady',
|
|
22
21
|
data: {}
|
|
23
22
|
});
|
|
23
|
+
const parentOrigin = resolveParentOrigin();
|
|
24
|
+
if (!parentOrigin) return;
|
|
24
25
|
const connection = connectToParent({
|
|
25
|
-
parentOrigin
|
|
26
|
+
parentOrigin,
|
|
26
27
|
methods: {
|
|
27
28
|
...childApi
|
|
28
29
|
}
|
|
@@ -35,13 +36,13 @@ function IframeBridge() {
|
|
|
35
36
|
const navigate = useNavigate();
|
|
36
37
|
const navigateRef = useUpdatingRef(navigate);
|
|
37
38
|
const isActive = useRef(false);
|
|
38
|
-
const historyBack = useCallback(()=>{
|
|
39
|
+
const historyBack = useCallback((_payload)=>{
|
|
39
40
|
navigateRef.current(-1);
|
|
40
41
|
isActive.current = true;
|
|
41
42
|
}, [
|
|
42
43
|
navigateRef
|
|
43
44
|
]);
|
|
44
|
-
const historyForward = useCallback(()=>{
|
|
45
|
+
const historyForward = useCallback((_payload)=>{
|
|
45
46
|
navigateRef.current(1);
|
|
46
47
|
isActive.current = true;
|
|
47
48
|
}, [
|
|
@@ -69,8 +70,8 @@ function IframeBridge() {
|
|
|
69
70
|
location
|
|
70
71
|
]);
|
|
71
72
|
const handleMessage = useCallback((event)=>{
|
|
72
|
-
const
|
|
73
|
-
if (isRouteMessageType(data
|
|
73
|
+
const data = event.data ?? {};
|
|
74
|
+
if ('string' == typeof data.type && isRouteMessageType(data.type)) operatorMessage[data.type](data.data);
|
|
74
75
|
}, [
|
|
75
76
|
operatorMessage
|
|
76
77
|
]);
|
|
@@ -1,6 +1 @@
|
|
|
1
1
|
export declare function getEnv(): 'BOE' | 'PRE' | 'ONLINE';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
* 获取预览环境父级域名
|
|
5
|
-
*/
|
|
6
|
-
export declare function getPreviewParentOrigin(): "https://force.feishu.cn" | "https://force.feishu-pre.cn" | "https://force.feishu-boe.cn" | "https://miaoda.feishu.cn" | "https://miaoda.feishu-pre.cn" | "https://miaoda.feishu-boe.cn";
|
|
@@ -4,13 +4,4 @@ function getEnv() {
|
|
|
4
4
|
if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'PRE';
|
|
5
5
|
return 'BOE';
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
const { origin } = window.location;
|
|
9
|
-
if (origin.includes('force.feishuapp.net')) return 'https://force.feishu.cn';
|
|
10
|
-
if (origin.includes('force-pre.feishuapp.net')) return 'https://force.feishu-pre.cn';
|
|
11
|
-
if (origin.includes('force.byted.org')) return 'https://force.feishu-boe.cn';
|
|
12
|
-
if (origin.includes('feishuapp.cn') || origin.includes('miaoda.feishuapp.net')) return 'https://miaoda.feishu.cn';
|
|
13
|
-
if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
|
|
14
|
-
return 'https://miaoda.feishu-boe.cn';
|
|
15
|
-
}
|
|
16
|
-
export { getEnv, getPreviewParentOrigin };
|
|
7
|
+
export { getEnv };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IncomingMessage, OutgoingMessage } from '../types/iframe-events';
|
|
2
|
+
export declare function resolveParentOrigin(): string;
|
|
2
3
|
export declare function submitPostMessage<T extends OutgoingMessage>(message: T, targetOrigin?: string): void;
|
|
3
|
-
export declare function submitSlardarEvent(event:
|
|
4
|
+
export declare function submitSlardarEvent(event: unknown): void;
|
|
4
5
|
export declare function isOutgoingMessage<T extends OutgoingMessage['type']>(msg: OutgoingMessage, type: T): msg is Extract<OutgoingMessage, {
|
|
5
6
|
type: T;
|
|
6
7
|
}>;
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
function getEnvOrigin() {
|
|
2
|
+
return 'undefined' != typeof process ? process.env?.FORCE_FRAMEWORK_DOMAIN_MAIN : void 0;
|
|
3
|
+
}
|
|
4
|
+
function getLegacyParentOrigin() {
|
|
5
|
+
const { origin } = window.location;
|
|
6
|
+
if (origin.includes('force.feishuapp.net')) return 'https://force.feishu.cn';
|
|
7
|
+
if (origin.includes('force-pre.feishuapp.net')) return 'https://force.feishu-pre.cn';
|
|
8
|
+
if (origin.includes('force.byted.org')) return 'https://force.feishu-boe.cn';
|
|
9
|
+
if (origin.includes('feishuapp.cn') || origin.includes('miaoda.feishuapp.net')) return 'https://miaoda.feishu.cn';
|
|
10
|
+
if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
|
|
11
|
+
return 'https://miaoda.feishu-boe.cn';
|
|
12
|
+
}
|
|
13
|
+
function resolveParentOrigin() {
|
|
14
|
+
return getEnvOrigin() ?? getLegacyParentOrigin();
|
|
15
|
+
}
|
|
2
16
|
function submitPostMessage(message, targetOrigin) {
|
|
3
17
|
try {
|
|
4
|
-
|
|
18
|
+
const parentOrigin = resolveParentOrigin();
|
|
19
|
+
const origin = targetOrigin ?? parentOrigin;
|
|
20
|
+
if (!origin) return;
|
|
21
|
+
window.parent.postMessage(message, origin);
|
|
5
22
|
} catch (e) {
|
|
6
23
|
console.error('postMessage error', e);
|
|
7
24
|
}
|
|
8
25
|
}
|
|
9
26
|
function submitSlardarEvent(event) {
|
|
10
|
-
const slardar = window
|
|
11
|
-
if (
|
|
27
|
+
const slardar = window.KSlardarWeb;
|
|
28
|
+
if ('function' == typeof slardar) slardar('sendEvent', event);
|
|
12
29
|
else console.warn('hmr listen function not found');
|
|
13
30
|
}
|
|
14
31
|
function isOutgoingMessage(msg, type) {
|
|
@@ -17,4 +34,4 @@ function isOutgoingMessage(msg, type) {
|
|
|
17
34
|
function isIncomingMessage(msg, type) {
|
|
18
35
|
return msg.type === type;
|
|
19
36
|
}
|
|
20
|
-
export { isIncomingMessage, isOutgoingMessage, submitPostMessage, submitSlardarEvent };
|
|
37
|
+
export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage, submitSlardarEvent };
|
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.4-alpha.0",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -156,5 +156,6 @@
|
|
|
156
156
|
"react-dom": ">=16.14.0",
|
|
157
157
|
"react-router-dom": ">=6.26.2",
|
|
158
158
|
"styled-jsx": ">=5.0.0"
|
|
159
|
-
}
|
|
159
|
+
},
|
|
160
|
+
"gitHead": "28506f3a156791edda1f6b56946b781cea9aca8a"
|
|
160
161
|
}
|