import React from "react"; import { createReactInlineContentSpec } from "@blocknote/react"; import { handleFileUrl } from "../index"; /** * 自定义「文件链接」行内节点: * - basePath(基础文件地址)等字段持久化在文档数据里,回显时可直接读取 * - href 存动态部分(路径 + 查询参数),最终地址 = basePath + href * - content: "none" * * 注意:内置的链接 hover 工具栏只认内置 link 类型, * fileLink 的点击行为在 render 里自行处理(新窗口打开)。 */ const FileLink = createReactInlineContentSpec( { type: "fileLink", propSchema: { href: { default: "" }, // 动态部分:路径 + 查询参数 basePath: { default: "" }, // 基础文件地址(持久化存储) label: { default: "" }, fileName: { default: "" }, }, content: "none", }, { render: ({ inlineContent }) => { const { href, basePath, label, fileName } = inlineContent.props; const temUrl = basePath ? handleFileUrl(basePath) : href; return ( { // 编辑器内点击 → 新窗口打开(与内置链接行为一致) e.preventDefault(); window.open(temUrl, "_blank", "noopener"); }} > {label || fileName || "文件"} ); } } ); export default FileLink;