@lark-apaas/client-toolkit 1.2.51-alpha.5 → 1.2.51-alpha.7
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 +0 -3
- package/lib/apis/components/UniversalLink.js +3 -42
- package/lib/components/AppContainer/safety.js +47 -0
- package/lib/locales/messages.js +4 -0
- package/lib/types/iframe-events.d.ts +1 -12
- package/lib/utils/postMessage.js +4 -5
- package/package.json +1 -1
|
@@ -8,8 +8,5 @@ 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
|
-
* 避免浏览器安全策略限制导致链接无法正常打开。
|
|
14
11
|
*/
|
|
15
12
|
export declare const UniversalLink: React.ForwardRefExoticComponent<UniversalLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
@@ -1,62 +1,23 @@
|
|
|
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";
|
|
6
4
|
function isInternalRoute(to) {
|
|
7
5
|
return !to.startsWith('#') && !to.startsWith('http://') && !to.startsWith('https://') && !to.startsWith('//');
|
|
8
6
|
}
|
|
9
7
|
function isExternalLink(to) {
|
|
10
8
|
return to.startsWith('http://') || to.startsWith('https://') || to.startsWith('//');
|
|
11
9
|
}
|
|
12
|
-
const
|
|
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
|
-
}
|
|
10
|
+
const UniversalLink_UniversalLink = /*#__PURE__*/ react.forwardRef(function({ to, ...props }, ref) {
|
|
48
11
|
if (isInternalRoute(to)) return /*#__PURE__*/ jsx(Link, {
|
|
49
12
|
to: to,
|
|
50
13
|
ref: ref,
|
|
51
|
-
...props
|
|
52
|
-
onClick: onClick
|
|
14
|
+
...props
|
|
53
15
|
});
|
|
54
16
|
return /*#__PURE__*/ jsx("a", {
|
|
55
17
|
href: to,
|
|
56
18
|
ref: ref,
|
|
57
19
|
...props,
|
|
58
|
-
|
|
59
|
-
...isExternal && {
|
|
20
|
+
...isExternalLink(to) && {
|
|
60
21
|
target: props.target ?? '_blank',
|
|
61
22
|
rel: props.rel ?? 'noopener noreferrer'
|
|
62
23
|
}
|
|
@@ -2,12 +2,29 @@ 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";
|
|
5
6
|
import { getCsrfToken } from "../../utils/getCsrfToken.js";
|
|
6
7
|
import { isNewPathEnabled } from "../../utils/apiPath.js";
|
|
7
8
|
import { useIsMobile } from "../../hooks/index.js";
|
|
8
9
|
import { X } from "lucide-react";
|
|
9
10
|
import { Sheet, SheetContent, SheetTrigger } from "../ui/drawer.js";
|
|
10
11
|
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
|
+
};
|
|
11
28
|
const Component = ()=>{
|
|
12
29
|
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
|
|
13
30
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
@@ -129,6 +146,21 @@ const Component = ()=>{
|
|
|
129
146
|
children: t('safety.ai.disclaimer')
|
|
130
147
|
})
|
|
131
148
|
]
|
|
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
|
+
]
|
|
132
164
|
})
|
|
133
165
|
]
|
|
134
166
|
}),
|
|
@@ -248,6 +280,21 @@ const Component = ()=>{
|
|
|
248
280
|
children: t('safety.ai.disclaimer')
|
|
249
281
|
})
|
|
250
282
|
]
|
|
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
|
+
]
|
|
251
298
|
})
|
|
252
299
|
]
|
|
253
300
|
}),
|
package/lib/locales/messages.js
CHANGED
|
@@ -23,6 +23,10 @@ const messages_messages = {
|
|
|
23
23
|
zh: '了解更多',
|
|
24
24
|
en: 'Learn more'
|
|
25
25
|
},
|
|
26
|
+
'safety.report': {
|
|
27
|
+
zh: '投诉与举报',
|
|
28
|
+
en: 'Report'
|
|
29
|
+
},
|
|
26
30
|
'safety.cover.pc': {
|
|
27
31
|
zh: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/logo/miaodacover.png',
|
|
28
32
|
en: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/LMfspH/ljhwZthlaukjlkulzlp/logo/miaodacover-weben.png'
|
|
@@ -46,18 +46,7 @@ export interface DevServerMessage extends IframeMessage<{
|
|
|
46
46
|
}> {
|
|
47
47
|
type: 'DevServerMessage';
|
|
48
48
|
}
|
|
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;
|
|
49
|
+
export type OutgoingMessage = PreviewReadyMessage | HmrMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | DevServerMessage | UpdateRoutesMessage;
|
|
61
50
|
export interface GetRoutesMessage extends IframeMessage<Record<string, never>> {
|
|
62
51
|
type: 'GetRoutes';
|
|
63
52
|
}
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -23,23 +23,22 @@ 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$/;
|
|
27
26
|
function resolveParentOrigin() {
|
|
28
|
-
const paramOrigin = getParentOriginFromParams();
|
|
29
|
-
if (paramOrigin) return paramOrigin;
|
|
30
27
|
try {
|
|
31
28
|
if (document.referrer) {
|
|
32
29
|
const referrerOrigin = new URL(document.referrer).origin;
|
|
33
|
-
if (
|
|
30
|
+
if (referrerOrigin.startsWith('http://localhost') || referrerOrigin.startsWith('http://127.0.0.1')) return referrerOrigin;
|
|
34
31
|
}
|
|
35
32
|
} catch {}
|
|
33
|
+
const paramOrigin = getParentOriginFromParams();
|
|
34
|
+
if (paramOrigin) return paramOrigin;
|
|
36
35
|
return process.env?.FORCE_FRAMEWORK_DOMAIN_MAIN ?? getLegacyParentOrigin();
|
|
37
36
|
}
|
|
38
37
|
function submitPostMessage(message, targetOrigin) {
|
|
39
38
|
try {
|
|
40
39
|
const parentOrigin = resolveParentOrigin();
|
|
41
40
|
const origin = targetOrigin ?? parentOrigin;
|
|
42
|
-
if (!origin) return
|
|
41
|
+
if (!origin) return;
|
|
43
42
|
window.parent.postMessage(message, origin);
|
|
44
43
|
} catch (e) {
|
|
45
44
|
console.error('postMessage error', e);
|