@lark-apaas/client-toolkit 1.2.51-alpha.9 → 1.2.51-beta.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.
|
@@ -2,28 +2,28 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import react from "react";
|
|
3
3
|
import { Link } from "react-router-dom";
|
|
4
4
|
import { isPreview } from "../../utils/utils.js";
|
|
5
|
-
import { submitPostMessage } from "../../utils/postMessage.js";
|
|
5
|
+
import { getParentOriginFromParams, submitPostMessage } from "../../utils/postMessage.js";
|
|
6
6
|
function isInternalRoute(to) {
|
|
7
7
|
return !to.startsWith('#') && !to.startsWith('http://') && !to.startsWith('https://') && !to.startsWith('//');
|
|
8
8
|
}
|
|
9
9
|
function isExternalLink(to) {
|
|
10
10
|
return to.startsWith('http://') || to.startsWith('https://') || to.startsWith('//');
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
function isIframeUnderMiaoda() {
|
|
12
|
+
function isIframeUnderMainHost() {
|
|
14
13
|
if ('undefined' == typeof window) return false;
|
|
15
14
|
if (window.parent === window) return false;
|
|
15
|
+
if (getParentOriginFromParams()) return true;
|
|
16
|
+
const envOrigin = process.env.FORCE_FRAMEWORK_DOMAIN_MAIN;
|
|
17
|
+
if (!envOrigin || !document.referrer) return false;
|
|
16
18
|
try {
|
|
17
|
-
|
|
18
|
-
const refOrigin = new URL(document.referrer).origin;
|
|
19
|
-
return MIAODA_PARENT_ORIGIN_RE.test(refOrigin);
|
|
19
|
+
return new URL(document.referrer).origin === envOrigin;
|
|
20
20
|
} catch {
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
const UniversalLink_UniversalLink = /*#__PURE__*/ react.forwardRef(function({ to, onClick, ...props }, ref) {
|
|
25
25
|
const isExternal = isExternalLink(to);
|
|
26
|
-
const preview = (isPreview() ||
|
|
26
|
+
const preview = (isPreview() || isIframeUnderMainHost()) && isExternal;
|
|
27
27
|
if (preview) {
|
|
28
28
|
const handlePreviewClick = (e)=>{
|
|
29
29
|
e.preventDefault();
|
|
@@ -2,12 +2,32 @@ 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 appId = getAppId();
|
|
20
|
+
if (!appId) return;
|
|
21
|
+
const params = JSON.stringify({
|
|
22
|
+
scene: 'miaoda_app_report',
|
|
23
|
+
entity_id: appId,
|
|
24
|
+
entity_type: 'miaoda_app',
|
|
25
|
+
extra: ''
|
|
26
|
+
});
|
|
27
|
+
const domain = REPORT_DOMAIN[getEnv()] ?? REPORT_DOMAIN.ONLINE;
|
|
28
|
+
const url = `https://${domain}/cust/lark_report/?type=common¶ms=${encodeURIComponent(params)}&lang=zh-CN`;
|
|
29
|
+
window.open(url, '_blank', 'noopener,noreferrer');
|
|
30
|
+
};
|
|
11
31
|
const Component = ()=>{
|
|
12
32
|
const HasClosedKey = `miaoda-creatByMiaoda-has-closed-${getAppId()}`;
|
|
13
33
|
const [visible, setVisible] = useState(!window.localStorage?.getItem(HasClosedKey));
|
|
@@ -129,6 +149,21 @@ const Component = ()=>{
|
|
|
129
149
|
children: t('safety.ai.disclaimer')
|
|
130
150
|
})
|
|
131
151
|
]
|
|
152
|
+
}),
|
|
153
|
+
/*#__PURE__*/ jsxs("div", {
|
|
154
|
+
className: "self-stretch shrink-0 flex items-center gap-x-[6px] cursor-pointer",
|
|
155
|
+
"data-custom-element": "safety-report",
|
|
156
|
+
onClick: openReport,
|
|
157
|
+
children: [
|
|
158
|
+
/*#__PURE__*/ jsx("img", {
|
|
159
|
+
src: ICON_FEEDBACK_URL,
|
|
160
|
+
className: "shrink-0 w-[14px] h-[14px]"
|
|
161
|
+
}),
|
|
162
|
+
/*#__PURE__*/ jsx("p", {
|
|
163
|
+
className: "shrink-0 m-0! text-[#646A73] text-sm underline underline-offset-2",
|
|
164
|
+
children: t('safety.report')
|
|
165
|
+
})
|
|
166
|
+
]
|
|
132
167
|
})
|
|
133
168
|
]
|
|
134
169
|
}),
|
|
@@ -248,6 +283,21 @@ const Component = ()=>{
|
|
|
248
283
|
children: t('safety.ai.disclaimer')
|
|
249
284
|
})
|
|
250
285
|
]
|
|
286
|
+
}),
|
|
287
|
+
/*#__PURE__*/ jsxs("div", {
|
|
288
|
+
className: "self-stretch shrink-0 flex items-center gap-x-[6px] cursor-pointer",
|
|
289
|
+
"data-custom-element": "safety-report",
|
|
290
|
+
onClick: openReport,
|
|
291
|
+
children: [
|
|
292
|
+
/*#__PURE__*/ jsx("img", {
|
|
293
|
+
src: ICON_FEEDBACK_URL,
|
|
294
|
+
className: "shrink-0 w-[12px] h-[12px]"
|
|
295
|
+
}),
|
|
296
|
+
/*#__PURE__*/ jsx("p", {
|
|
297
|
+
className: "shrink-0 m-0! text-[#a6a6a6] underline underline-offset-2",
|
|
298
|
+
children: t('safety.report')
|
|
299
|
+
})
|
|
300
|
+
]
|
|
251
301
|
})
|
|
252
302
|
]
|
|
253
303
|
}),
|
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'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IncomingMessage, OutgoingMessage } from '../types/iframe-events';
|
|
2
|
+
export declare function getParentOriginFromParams(): string | undefined;
|
|
2
3
|
export declare function resolveParentOrigin(): string;
|
|
3
4
|
export declare function submitPostMessage<T extends OutgoingMessage>(message: T, targetOrigin?: string): void;
|
|
4
5
|
export declare function isOutgoingMessage<T extends OutgoingMessage['type']>(msg: OutgoingMessage, type: T): msg is Extract<OutgoingMessage, {
|
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);
|
|
@@ -51,4 +50,4 @@ function isOutgoingMessage(msg, type) {
|
|
|
51
50
|
function isIncomingMessage(msg, type) {
|
|
52
51
|
return msg.type === type;
|
|
53
52
|
}
|
|
54
|
-
export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage };
|
|
53
|
+
export { getParentOriginFromParams, isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage };
|