"use client"; import { createReactBlockSpec } from "@blocknote/react"; import { RiFileTextFill } from "react-icons/ri"; import { useRouter } from "next/navigation"; const normalizeTitle = (value?: string | null) => { if (!value || !value.trim()) { return "未命名页面"; } return value; }; const PageReferenceContent = ({ pageId, title, asChildPage, }: { pageId: string; title: string; asChildPage: boolean; }) => { const router = useRouter(); // 说明:Convex 迁移阶段,直接使用 block props 里的 title,不做实时订阅/拉取。 // 页面引用的标题会由编辑器同步更新 block.props.title。 const resolvedTitle = normalizeTitle(title); const navigate = () => { if (pageId) { router.push(`/documents/${pageId}`); } }; return (
{ if ((event.key === "Enter" || event.key === " ") && pageId) { event.preventDefault(); navigate(); } }} className="group mt-2 inline-flex items-center gap-1.5 rounded-[3px] px-1.5 py-0.5 text-[#37352F] hover:bg-[rgba(55,53,47,0.08)] transition-colors duration-150" style={{ fontFamily: "Inter, system-ui, sans-serif" }} > {resolvedTitle}
); }; export const pageReferenceBlock = createReactBlockSpec( { type: "pageReference", propSchema: { pageId: { default: "" }, title: { default: "未命名页面" }, asChildPage: { default: false }, }, content: "none", }, () => ({ render: ({ block }) => ( ), }), )();