返回 presentation-ai
media-file-node.tsx
根目录 / src / components / plate / ui / media-file-node.tsx
1 "use client";
2
3 import { useMediaState } from "@platejs/media/react";
4 import { ResizableProvider } from "@platejs/resizable";
5 import { FileUp } from "lucide-react";
6 import { type TFileElement } from "platejs";
7 import {
8 PlateElement,
9 useReadOnly,
10 withHOC,
11 type PlateElementProps,
12 } from "platejs/react";
13
14 import { Caption, CaptionTextarea } from "./caption";
15
16 export const FileElement = withHOC(
17 ResizableProvider,
18 function FileElement(props: PlateElementProps<TFileElement>) {
19 const readOnly = useReadOnly();
20 const { name, unsafeUrl } = useMediaState();
21
22 return (
23 <PlateElement className="my-px rounded-sm" {...props}>
24 <a
25 className="group relative m-0 flex cursor-pointer items-center rounded px-0.5 py-0.75 hover:bg-muted"
26 contentEditable={false}
27 download={name}
28 href={unsafeUrl}
29 rel="noopener noreferrer"
30 role="button"
31 target="_blank"
32 >
33 <div className="flex items-center gap-1 p-1">
34 <FileUp className="size-5" />
35 <div>{name}</div>
36 </div>
37
38 <Caption align="left">
39 <CaptionTextarea
40 className="text-left"
41 readOnly={readOnly}
42 placeholder="Write a caption..."
43 />
44 </Caption>
45 </a>
46 {props.children}
47 </PlateElement>
48 );
49 },
50 );
51
51 lines Plain Text