-
Notifications
You must be signed in to change notification settings - Fork 3
/
editor.tsx
70 lines (60 loc) · 1.83 KB
/
editor.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use client";
import { useTheme } from "next-themes";
import { defaultBlockSpecs } from "@blocknote/core";
import {
BlockNoteView,
getDefaultReactSlashMenuItems,
useBlockNote,
} from "@blocknote/react";
import "@blocknote/core/style.css";
import { useEdgeStore } from "@/lib/edgestore";
import { CheckBoxBlockSpec, insertCheckBoxBlock } from "@/components/blocks/checkbox";
// import { chartBlock, insertChartBlock } from "./blocks/chart";
import { insertPieChartBlock, piechartBlock } from "./blocks/PieChart";
import { guestbookBlockSpec, insertGuestBookBlock } from "./blocks/guestbook";
import { piechart } from "./blocks/PieChratComponent";
interface EditorProps {
onChange: (value: string) => void;
initialContent?: string;
editable?: boolean;
}
const Editor = ({ onChange, initialContent, editable }: EditorProps) => {
const { resolvedTheme } = useTheme();
const { edgestore } = useEdgeStore();
const handleUpload = async (file: File) => {
const response = await edgestore.publicFiles.upload({
file,
});
return response.url;
};
const editor = useBlockNote({
editable,
initialContent: initialContent ? JSON.parse(initialContent) : undefined,
onEditorContentChange: (editor) => {
onChange(JSON.stringify(editor.topLevelBlocks, null, 2));
},
uploadFile: handleUpload,
blockSpecs: {
...defaultBlockSpecs,
checkboxListItem: CheckBoxBlockSpec,
piechart: piechart,
chart: piechartBlock,
guestbook: guestbookBlockSpec,
},
slashMenuItems: [
...getDefaultReactSlashMenuItems(),
insertPieChartBlock,
insertCheckBoxBlock,
insertGuestBookBlock,
],
});
return (
<div>
<BlockNoteView
editor={editor}
theme={resolvedTheme === "dark" ? "dark" : "light"}
/>
</div>
);
};
export default Editor;