feat: 宿主页复制
This commit is contained in:
parent
f2921ae3df
commit
afccfaa822
|
|
@ -11,6 +11,8 @@ export const POST_MESSAGE_TYPES = {
|
|||
FULLSCREEN: "fullscreen",
|
||||
// 会话是否处于聊天态
|
||||
IS_CHATTING: "isChatting",
|
||||
// 请求宿主页执行复制
|
||||
COPY_TO_CLIPBOARD: "copyToClipboard",
|
||||
// 选择预定义 skill
|
||||
SELECT_SKILLS: "selectedSkills",
|
||||
// 打开 skill 选择对话框
|
||||
|
|
@ -42,6 +44,11 @@ export interface IsChattingMessage {
|
|||
isChatting: boolean;
|
||||
}
|
||||
|
||||
export interface CopyToClipboardMessage {
|
||||
type: typeof POST_MESSAGE_TYPES.COPY_TO_CLIPBOARD;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export interface SelectSkillMessage {
|
||||
type: typeof POST_MESSAGE_TYPES.SELECT_SKILLS;
|
||||
selectedSkills: SelectedSkillPayloadItem[];
|
||||
|
|
@ -106,6 +113,7 @@ export function sendToParent(
|
|||
message:
|
||||
| FullscreenMessage
|
||||
| IsChattingMessage
|
||||
| CopyToClipboardMessage
|
||||
| SelectSkillMessage
|
||||
| OpenSkillDialogMessage,
|
||||
): void {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { clsx, type ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
import { POST_MESSAGE_TYPES, sendToParent } from "@/core/iframe-messages";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
|
|
@ -18,14 +19,14 @@ export const externalLinkClassNoUnderline = "text-primary hover:underline";
|
|||
export async function copyToClipboard(text: string): Promise<void> {
|
||||
const isInIframe = window.self !== window.top;
|
||||
const message = {
|
||||
type: "copyToClipboard",
|
||||
type: POST_MESSAGE_TYPES.COPY_TO_CLIPBOARD,
|
||||
text,
|
||||
};
|
||||
} as const;
|
||||
|
||||
if (isInIframe && window.parent) {
|
||||
if (isInIframe) {
|
||||
try {
|
||||
// Request parent window to copy
|
||||
window.parent.postMessage(message, "*");
|
||||
sendToParent(message);
|
||||
console.log(
|
||||
"[copyToClipboard] iframe mode → postMessage to parent",
|
||||
message,
|
||||
|
|
|
|||
Loading…
Reference in New Issue