feat(frontend): artifact 文件卡片支持右键引用

This commit is contained in:
肖应宇 2026-04-16 15:18:14 +08:00
parent 4dbe930775
commit 3d5006af48
1 changed files with 86 additions and 62 deletions

View File

@ -10,9 +10,16 @@ import {
CardHeader, CardHeader,
CardTitle, CardTitle,
} from "@/components/ui/card"; } from "@/components/ui/card";
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuTrigger,
} from "@/components/ui/context-menu";
import { urlOfArtifact } from "@/core/artifacts/utils"; import { urlOfArtifact } from "@/core/artifacts/utils";
import { useI18n } from "@/core/i18n/hooks"; import { useI18n } from "@/core/i18n/hooks";
import { installSkill } from "@/core/skills/api"; import { installSkill } from "@/core/skills/api";
import { dispatchMentionReference } from "@/core/threads/reference-events";
import { import {
getFileExtensionDisplayName, getFileExtensionDisplayName,
getFileIcon, getFileIcon,
@ -78,8 +85,9 @@ export function ArtifactFileList({
data-testid="artifact-file-list" data-testid="artifact-file-list"
> >
{files.map((file) => ( {files.map((file) => (
<ContextMenu key={file}>
<ContextMenuTrigger asChild>
<Card <Card
key={file}
className="relative cursor-pointer p-4" className="relative cursor-pointer p-4"
data-testid="artifact-file-card" data-testid="artifact-file-card"
onClick={() => handleClick(file)} onClick={() => handleClick(file)}
@ -124,9 +132,9 @@ export function ArtifactFileList({
target="_blank" target="_blank"
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
> >
<Button variant="ghost" <Button
variant="ghost"
className="h-full! text-[var(--muted-foreground)]! hover:bg-transparent! hover:text-[#333333]!" className="h-full! text-[var(--muted-foreground)]! hover:bg-transparent! hover:text-[#333333]!"
> >
<DownloadIcon className="size-4" /> <DownloadIcon className="size-4" />
{t.common.download} {t.common.download}
@ -141,6 +149,22 @@ export function ArtifactFileList({
</CardAction> </CardAction>
</CardHeader> </CardHeader>
</Card> </Card>
</ContextMenuTrigger>
<ContextMenuContent className="min-w-[120px] p-1">
<ContextMenuItem
onSelect={() => {
dispatchMentionReference({
threadId,
filename: getFileName(file),
path: file,
ref_source: "artifact",
});
}}
>
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
))} ))}
</ul> </ul>
); );