@lark-apaas/client-toolkit 1.2.51-alpha.3 → 1.2.51-alpha.5
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/apis/components/UniversalLink.d.ts +3 -0
- package/lib/apis/components/UniversalLink.js +42 -3
- package/lib/components/AppContainer/safety.js +0 -47
- package/lib/locales/messages.js +0 -4
- package/lib/types/iframe-events.d.ts +12 -1
- package/lib/utils/postMessage.js +5 -4
- package/package.json +1 -1
|
@@ -8,5 +8,8 @@ export interface UniversalLinkProps extends Omit<React.AnchorHTMLAttributes<HTML
|
|
|
8
8
|
* - 内部路由(/dashboard)→ react-router Link
|
|
9
9
|
* - Hash 锚点(#section)→ <a>
|
|
10
10
|
* - 外链(https://...)→ <a target="_blank">
|
|
11
|
+
*
|
|
12
|
+
* 预览态(iframe 内)时,通过 postMessage 通知父页面处理链接跳转,
|
|
13
|
+
* 避免浏览器安全策略限制导致链接无法正常打开。
|
|
11
14
|
*/
|
|
12
15
|
export declare const UniversalLink: React.ForwardRefExoticComponent<UniversalLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
@@ -1,23 +1,62 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import react from "react";
|
|
3
3
|
import { Link } from "react-router-dom";
|
|
4
|
+
import { isPreview } from "../../utils/utils.js";
|
|
5
|
+
import { submitPostMessage } from "../../utils/postMessage.js";
|
|
4
6
|
function isInternalRoute(to) {
|
|
5
7
|
return !to.startsWith('#') && !to.startsWith('http://') && !to.startsWith('https://') && !to.startsWith('//');
|
|
6
8
|
}
|
|
7
9
|
function isExternalLink(to) {
|
|
8
10
|
return to.startsWith('http://') || to.startsWith('https://') || to.startsWith('//');
|
|
9
11
|
}
|
|
10
|
-
const
|
|
12
|
+
const MIAODA_PARENT_ORIGIN_RE = /^https:\/\/(miaoda|force)\.feishu(-pre|-boe|-staging)?\.cn$/;
|
|
13
|
+
function isIframeUnderMiaoda() {
|
|
14
|
+
if ('undefined' == typeof window) return false;
|
|
15
|
+
if (window.parent === window) return false;
|
|
16
|
+
try {
|
|
17
|
+
if (!document.referrer) return false;
|
|
18
|
+
const refOrigin = new URL(document.referrer).origin;
|
|
19
|
+
return MIAODA_PARENT_ORIGIN_RE.test(refOrigin);
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const UniversalLink_UniversalLink = /*#__PURE__*/ react.forwardRef(function({ to, onClick, ...props }, ref) {
|
|
25
|
+
const isExternal = isExternalLink(to);
|
|
26
|
+
const preview = (isPreview() || isIframeUnderMiaoda()) && isExternal;
|
|
27
|
+
if (preview) {
|
|
28
|
+
const handlePreviewClick = (e)=>{
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
onClick?.(e);
|
|
31
|
+
submitPostMessage({
|
|
32
|
+
type: 'OpenIframeLink',
|
|
33
|
+
data: {
|
|
34
|
+
href: to,
|
|
35
|
+
external: true
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return /*#__PURE__*/ jsx("a", {
|
|
40
|
+
href: to,
|
|
41
|
+
ref: ref,
|
|
42
|
+
...props,
|
|
43
|
+
onClick: handlePreviewClick,
|
|
44
|
+
target: props.target ?? '_blank',
|
|
45
|
+
rel: props.rel ?? 'noopener noreferrer'
|
|
46
|
+
});
|
|
47
|
+
}
|
|
11
48
|
if (isInternalRoute(to)) return /*#__PURE__*/ jsx(Link, {
|
|
12
49
|
to: to,
|
|
13
50
|
ref: ref,
|
|
14
|
-
...props
|
|
51
|
+
...props,
|
|
52
|
+
onClick: onClick
|
|
15
53
|
});
|
|
16
54
|
return /*#__PURE__*/ jsx("a", {
|
|
17
55
|
href: to,
|
|
18
56
|
ref: ref,
|
|
19
57
|
...props,
|
|
20
|
-
|
|
58
|
+
onClick: onClick,
|
|
59
|
+
...isExternal && {
|
|
21
60
|
target: props.target ?? '_blank',
|
|
22
61
|
rel: props.rel ?? 'noopener noreferrer'
|
|
23
62
|
}
|
|
@@ -2,29 +2,12 @@ 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
4
|
import { getAppId } from "../../utils/getAppId.js";
|
|
5
|
-
import { getEnv } from "../../utils/getParentOrigin.js";
|
|
6
5
|
import { getCsrfToken } from "../../utils/getCsrfToken.js";
|
|
7
6
|
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
8
7
|
import { useIsMobile } from "../../hooks/index.js";
|
|
9
8
|
import { X } from "lucide-react";
|
|
10
9
|
import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
|
|
11
10
|
import { t } from "../../locales/index.js";
|
|
12
|
-
const ICON_FEEDBACK_URL = 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/miaoda-ui/icon_feedback_outlined.png';
|
|
13
|
-
const REPORT_DOMAIN = {
|
|
14
|
-
BOE: 'tns.feishu-boe.cn',
|
|
15
|
-
PRE: 'tns.feishu-pre.cn',
|
|
16
|
-
ONLINE: 'tns.feishu.cn'
|
|
17
|
-
};
|
|
18
|
-
const openReport = ()=>{
|
|
19
|
-
const params = JSON.stringify({
|
|
20
|
-
scene: 'miaoda_app_report',
|
|
21
|
-
entity_id: getAppId() ?? '',
|
|
22
|
-
entity_type: 'miaoda_app',
|
|
23
|
-
extra: ''
|
|
24
|
-
});
|
|
25
|
-
const url = `https://${REPORT_DOMAIN[getEnv()]}/cust/lark_report/?type=common¶ms=${encodeURIComponent(params)}&lang=zh-CN`;
|
|
26
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
27
|
-
};
|
|
28
11
|
const Component = ()=>{
|
|
29
12
|
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
|
|
30
13
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
@@ -146,21 +129,6 @@ const Component = ()=>{
|
|
|
146
129
|
children: t('safety.ai.disclaimer')
|
|
147
130
|
})
|
|
148
131
|
]
|
|
149
|
-
}),
|
|
150
|
-
/*#__PURE__*/ jsxs("div", {
|
|
151
|
-
className: "self-stretch shrink-0 flex items-center gap-x-[6px] cursor-pointer",
|
|
152
|
-
"data-custom-element": "safety-report",
|
|
153
|
-
onClick: openReport,
|
|
154
|
-
children: [
|
|
155
|
-
/*#__PURE__*/ jsx("img", {
|
|
156
|
-
src: ICON_FEEDBACK_URL,
|
|
157
|
-
className: "shrink-0 w-[14px] h-[14px]"
|
|
158
|
-
}),
|
|
159
|
-
/*#__PURE__*/ jsx("p", {
|
|
160
|
-
className: "shrink-0 m-0! text-[#646A73] text-sm underline underline-offset-2",
|
|
161
|
-
children: t('safety.report')
|
|
162
|
-
})
|
|
163
|
-
]
|
|
164
132
|
})
|
|
165
133
|
]
|
|
166
134
|
}),
|
|
@@ -280,21 +248,6 @@ const Component = ()=>{
|
|
|
280
248
|
children: t('safety.ai.disclaimer')
|
|
281
249
|
})
|
|
282
250
|
]
|
|
283
|
-
}),
|
|
284
|
-
/*#__PURE__*/ jsxs("div", {
|
|
285
|
-
className: "self-stretch shrink-0 flex items-center gap-x-[6px] cursor-pointer",
|
|
286
|
-
"data-custom-element": "safety-report",
|
|
287
|
-
onClick: openReport,
|
|
288
|
-
children: [
|
|
289
|
-
/*#__PURE__*/ jsx("img", {
|
|
290
|
-
src: ICON_FEEDBACK_URL,
|
|
291
|
-
className: "shrink-0 w-[12px] h-[12px]"
|
|
292
|
-
}),
|
|
293
|
-
/*#__PURE__*/ jsx("p", {
|
|
294
|
-
className: "shrink-0 m-0! text-[#a6a6a6] underline underline-offset-2",
|
|
295
|
-
children: t('safety.report')
|
|
296
|
-
})
|
|
297
|
-
]
|
|
298
251
|
})
|
|
299
252
|
]
|
|
300
253
|
}),
|
package/lib/locales/messages.js
CHANGED
|
@@ -23,10 +23,6 @@ const messages_messages = {
|
|
|
23
23
|
zh: '了解更多',
|
|
24
24
|
en: 'Learn more'
|
|
25
25
|
},
|
|
26
|
-
'safety.report': {
|
|
27
|
-
zh: '投诉与举报',
|
|
28
|
-
en: 'Report'
|
|
29
|
-
},
|
|
30
26
|
'safety.cover.pc': {
|
|
31
27
|
zh: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/logo/miaodacover.png',
|
|
32
28
|
en: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/logo/miaodacover-weben.png'
|
|
@@ -46,7 +46,18 @@ export interface DevServerMessage extends IframeMessage<{
|
|
|
46
46
|
}> {
|
|
47
47
|
type: 'DevServerMessage';
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* 预览态下链接点击通知父页面处理。
|
|
51
|
+
* iframe 内直接跳转可能被浏览器安全策略拦截,
|
|
52
|
+
* 通过 postMessage 让父页面在新标签页或外壳中打开链接。
|
|
53
|
+
*/
|
|
54
|
+
export interface OpenIframeLinkMessage extends IframeMessage<{
|
|
55
|
+
href: string;
|
|
56
|
+
external: boolean;
|
|
57
|
+
}> {
|
|
58
|
+
type: 'OpenIframeLink';
|
|
59
|
+
}
|
|
60
|
+
export type OutgoingMessage = PreviewReadyMessage | HmrMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | DevServerMessage | UpdateRoutesMessage | OpenIframeLinkMessage;
|
|
50
61
|
export interface GetRoutesMessage extends IframeMessage<Record<string, never>> {
|
|
51
62
|
type: 'GetRoutes';
|
|
52
63
|
}
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -23,22 +23,23 @@ function getLegacyParentOrigin() {
|
|
|
23
23
|
if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
|
|
24
24
|
return 'https://miaoda.feishu-boe.cn';
|
|
25
25
|
}
|
|
26
|
+
const MIAODA_PARENT_ORIGIN_RE = /^https:\/\/(miaoda|force)\.feishu(-pre|-boe|-staging)?\.cn$/;
|
|
26
27
|
function resolveParentOrigin() {
|
|
28
|
+
const paramOrigin = getParentOriginFromParams();
|
|
29
|
+
if (paramOrigin) return paramOrigin;
|
|
27
30
|
try {
|
|
28
31
|
if (document.referrer) {
|
|
29
32
|
const referrerOrigin = new URL(document.referrer).origin;
|
|
30
|
-
if (referrerOrigin.startsWith('http://localhost') || referrerOrigin.startsWith('http://127.0.0.1')) return referrerOrigin;
|
|
33
|
+
if (MIAODA_PARENT_ORIGIN_RE.test(referrerOrigin) || referrerOrigin.startsWith('http://localhost') || referrerOrigin.startsWith('http://127.0.0.1')) return referrerOrigin;
|
|
31
34
|
}
|
|
32
35
|
} catch {}
|
|
33
|
-
const paramOrigin = getParentOriginFromParams();
|
|
34
|
-
if (paramOrigin) return paramOrigin;
|
|
35
36
|
return process.env?.FORCE_FRAMEWORK_DOMAIN_MAIN ?? getLegacyParentOrigin();
|
|
36
37
|
}
|
|
37
38
|
function submitPostMessage(message, targetOrigin) {
|
|
38
39
|
try {
|
|
39
40
|
const parentOrigin = resolveParentOrigin();
|
|
40
41
|
const origin = targetOrigin ?? parentOrigin;
|
|
41
|
-
if (!origin) return;
|
|
42
|
+
if (!origin) return void console.error('postMessage skipped: cannot resolve parent origin');
|
|
42
43
|
window.parent.postMessage(message, origin);
|
|
43
44
|
} catch (e) {
|
|
44
45
|
console.error('postMessage error', e);
|