refactor(frontend): 在工件与技能 hook 内嵌 iframe 消息常量

This commit is contained in:
肖应宇 2026-03-29 00:58:31 +08:00
parent 91e094066e
commit 49ff9411e9
2 changed files with 30 additions and 7 deletions

View File

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

View File

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