feat: 宿主页复制

This commit is contained in:
肖应宇 2026-04-09 10:27:14 +08:00
parent 25c444e83d
commit cea4232813
2 changed files with 13 additions and 4 deletions

View File

@ -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 {

View File

@ -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,