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