From 49ff9411e96fe67556d5f962c2f99defc3a1661f Mon Sep 17 00:00:00 2001 From: MT-Fire <798521692@qq.com> Date: Sun, 29 Mar 2026 00:58:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor(frontend):=20=E5=9C=A8=E5=B7=A5?= =?UTF-8?q?=E4=BB=B6=E4=B8=8E=E6=8A=80=E8=83=BD=20hook=20=E5=86=85?= =?UTF-8?q?=E5=B5=8C=20iframe=20=E6=B6=88=E6=81=AF=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../artifacts/artifact-file-detail.tsx | 11 +++++++- frontend/src/hooks/use-iframe-skill.ts | 26 ++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/workspace/artifacts/artifact-file-detail.tsx b/frontend/src/components/workspace/artifacts/artifact-file-detail.tsx index 64e5cbe2..8423617a 100644 --- a/frontend/src/components/workspace/artifacts/artifact-file-detail.tsx +++ b/frontend/src/components/workspace/artifacts/artifact-file-detail.tsx @@ -29,7 +29,6 @@ import { CodeEditor } from "@/components/workspace/code-editor"; import { useArtifactContent } from "@/core/artifacts/hooks"; import { urlOfArtifact } from "@/core/artifacts/utils"; import { useI18n } from "@/core/i18n/hooks"; -import { POST_MESSAGE_TYPES, sendToParent } from "@/core/iframe-messages"; import { installSkill } from "@/core/skills/api"; import { streamdownPlugins } from "@/core/streamdown"; import { checkCodeFile, getFileName } from "@/core/utils/files"; @@ -40,6 +39,16 @@ import { CitationLink } from "../citations/citation-link"; import { useArtifacts } from "./context"; +const POST_MESSAGE_TYPES = { + FULLSCREEN: "fullscreen", +} as const; + +function sendToParent(message: unknown): void { + if (window.parent !== window) { + window.parent.postMessage(message, "*"); + } +} + export function ArtifactFileDetail({ className, filepath: filepathFromProps, diff --git a/frontend/src/hooks/use-iframe-skill.ts b/frontend/src/hooks/use-iframe-skill.ts index 63cd5cee..8e381a70 100644 --- a/frontend/src/hooks/use-iframe-skill.ts +++ b/frontend/src/hooks/use-iframe-skill.ts @@ -1,12 +1,26 @@ import { useSearchParams } from "next/navigation"; import { useState, useEffect, useCallback } from "react"; -import { - POST_MESSAGE_TYPES, - RECEIVE_MESSAGE_TYPES, - sendToParent, - type SelectedSkillMessage, -} from "@/core/iframe-messages"; +const POST_MESSAGE_TYPES = { + SELECT_SKILL: "selectSkill", + OPEN_SKILL_DIALOG: "openSkillDialog", +} as const; + +const RECEIVE_MESSAGE_TYPES = { + SELECTED_SKILL: "selectedSkill", +} as const; + +type SelectedSkillMessage = { + type: typeof RECEIVE_MESSAGE_TYPES.SELECTED_SKILL; + id: string | number; + title: string; +}; + +function sendToParent(message: unknown): void { + if (window.parent !== window) { + window.parent.postMessage(message, "*"); + } +} // Skill 数据类型 interface SkillData {