From 6f491560adc8c0fe079c369196a9cb3eb95472be Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 1 Dec 2023 09:01:00 +0800 Subject: [PATCH] chore: split advice plugin --- .../editor/intelli/advice-extension.ts | 8 ++++++++ editor/src/components/editor/live-editor.tsx | 4 ++-- .../components/editor/side-view/side-box.tsx | 19 ------------------- 3 files changed, 10 insertions(+), 21 deletions(-) create mode 100644 editor/src/components/editor/intelli/advice-extension.ts delete mode 100644 editor/src/components/editor/side-view/side-box.tsx diff --git a/editor/src/components/editor/intelli/advice-extension.ts b/editor/src/components/editor/intelli/advice-extension.ts new file mode 100644 index 0000000..97ff174 --- /dev/null +++ b/editor/src/components/editor/intelli/advice-extension.ts @@ -0,0 +1,8 @@ +import { Extension } from "@tiptap/core"; + +const EXTENSION_NAME = "advice"; + +// https://dev.to/sereneinserenade/how-i-implemented-google-docs-like-commenting-in-tiptap-k2k +export const AdviceExtension = Extension.create({ + name: EXTENSION_NAME, +}); \ No newline at end of file diff --git a/editor/src/components/editor/live-editor.tsx b/editor/src/components/editor/live-editor.tsx index f02e863..3d8658c 100644 --- a/editor/src/components/editor/live-editor.tsx +++ b/editor/src/components/editor/live-editor.tsx @@ -21,13 +21,14 @@ import { createInlineCompletion } from "@/components/editor/inline/inline-comple import { useTranslation } from "react-i18next"; import "./editor.css" -import { SideBox } from './side-view/side-box' +import { AdviceExtension } from "@/components/editor/intelli/advice-extension"; const md = new MarkdownIt() const extensions = [ // we define all commands here CommandFunctions, + AdviceExtension, TrackChangeExtension.configure({ enabled: false, }), @@ -79,7 +80,6 @@ const LiveEditor = () => { {editor && } {editor && } - {editor && } {editor &&
{Math.abs(editor.state.selection.$from.pos - editor.state.selection.$to.pos)} selected diff --git a/editor/src/components/editor/side-view/side-box.tsx b/editor/src/components/editor/side-view/side-box.tsx deleted file mode 100644 index db53ccd..0000000 --- a/editor/src/components/editor/side-view/side-box.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { Editor, Node } from "@tiptap/core"; -import { useEffect } from "react"; - -export const SideBox = ({ editor }: { - editor: Editor -}) => { - useEffect(() => { - editor.state.doc.descendants((node) => { - // node.type.name === 'heading' - let isHeadingOne = (node.type as any)['attrs']?.['level']?.default === 1; - console.log(isHeadingOne) - }); - }, []); - - // todo: add in right side. - - return
-
-}; \ No newline at end of file