blob: 5b4a60ceb73565dd05fc8d6ea1341d53993b94f7 (
plain) (
blame)
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
|
"use client";
import { defaultEditorContent } from "./lib/content";
import { EditorContent, EditorRoot, type JSONContent } from "novel";
import { ImageResizer } from "novel/extensions";
import { useEffect, useState } from "react";
import { defaultExtensions } from "./components/extensions";
import { slashCommand } from "./components/slash-command";
import { Updates } from "./lib/debouncedsave";
import { editorProps } from "./lib/editorprops";
import EditorCommands from "./components/editorcommands";
import Aigenerate from "./components/aigenerate";
import { useMotionValueEvent, useScroll } from "framer-motion";
import Topbar from "./components/topbar";
const Editor = () => {
const [initialContent, setInitialContent] = useState<null | JSONContent>(
null
);
const [saveStatus, setSaveStatus] = useState("Saved");
const [charsCount, setCharsCount] = useState();
const [visible, setVisible] = useState(true);
useEffect(() => {
const content = window.localStorage.getItem("novel-content");
if (content) setInitialContent(JSON.parse(content));
else setInitialContent(defaultEditorContent);
}, []);
if (!initialContent) return null;
return (
<div className="relative w-full max-w-screen-xl">
<Topbar charsCount={charsCount} saveStatus={saveStatus} />
<EditorRoot>
<EditorContent
initialContent={initialContent}
extensions={[...defaultExtensions, slashCommand]}
className="min-h-[55vh] mt-[8vh] w-full max-w-screen-xl bg-[#171B1F] mb-[40vh]"
editorProps={editorProps}
onUpdate={({ editor }) => {
Updates({ editor, setCharsCount, setSaveStatus });
}}
slotAfter={<ImageResizer />}
>
<EditorCommands />
<Aigenerate />
</EditorContent>
</EditorRoot>
</div>
);
};
export default Editor;
|