Testing blocknote for doc

This commit is contained in:
2025-11-11 21:46:22 +01:00
parent 5dc7a1fcbf
commit 2c935d4a83
5 changed files with 3032 additions and 8 deletions
+2 -1
View File
@@ -3,6 +3,7 @@
import { Workspace } from "@/hooks/workspace";
import { Task } from "@/lib/types";
import TaskView from "./view/TaskView";
import DocView from "./view/Doc";
const id = (prefix = "t") =>
`${prefix}_${Math.random().toString(36).slice(2, 9)}`;
@@ -33,6 +34,6 @@ export default function Router({ workspace }: { workspace: Workspace }) {
/>
);
case "doc":
return entity.doc;
return <DocView doc={entity.doc} setDoc={entity.setDoc} />;
}
}
+35
View File
@@ -0,0 +1,35 @@
import { SetState } from "@/lib/types";
import { useCreateBlockNote } from "@blocknote/react";
import { BlockNoteView } from "@blocknote/shadcn";
import { useEffect } from "react";
export default function DocView({
doc,
setDoc,
}: {
doc: string;
setDoc: SetState<string>;
}) {
const editor = useCreateBlockNote();
useEffect(() => {
if (editor && doc) {
editor.tryParseMarkdownToBlocks(doc);
}
}, [editor]);
return (
<BlockNoteView
defaultValue={doc}
editor={editor}
shadCNComponents={{}}
className="w-full h-svh px-6 mt-4"
onChange={async () => {
if (editor) {
console.log(editor.blocksToMarkdownLossy(editor.document));
setDoc(editor.blocksToMarkdownLossy(editor.document));
}
}}
/>
);
}