2023-10-13 22:31:56 -04:00
|
|
|
"use client";
|
2023-10-14 18:57:37 -04:00
|
|
|
import { useState } from "react";
|
2023-10-13 22:31:56 -04:00
|
|
|
import { useTheme } from "next-themes";
|
2023-10-14 18:57:37 -04:00
|
|
|
import { BlockNoteEditor, PartialBlock } from "@blocknote/core";
|
2023-10-13 22:31:56 -04:00
|
|
|
import { BlockNoteView, useBlockNote } from "@blocknote/react";
|
|
|
|
import "@blocknote/core/style.css";
|
|
|
|
|
|
|
|
interface EditorProps {
|
|
|
|
editable?: boolean;
|
|
|
|
}
|
|
|
|
|
2023-10-14 18:57:37 -04:00
|
|
|
const Editor = ({ editable }: EditorProps) => {
|
2023-10-13 22:31:56 -04:00
|
|
|
const { resolvedTheme } = useTheme();
|
2023-10-14 18:57:37 -04:00
|
|
|
const [content, setContent] = useState("");
|
2023-10-13 22:31:56 -04:00
|
|
|
|
|
|
|
const editor: BlockNoteEditor = useBlockNote({
|
|
|
|
editable,
|
|
|
|
onEditorContentChange: (editor) => {
|
2023-10-14 18:57:37 -04:00
|
|
|
setContent(JSON.stringify(editor.topLevelBlocks, null, 2));
|
2023-10-13 22:31:56 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2023-10-14 18:57:37 -04:00
|
|
|
<div className="">
|
2023-10-13 22:31:56 -04:00
|
|
|
<BlockNoteView
|
|
|
|
editor={editor}
|
|
|
|
theme={resolvedTheme === "dark" ? "dark" : "light"}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Editor;
|