-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85b3681
commit 68a1396
Showing
6 changed files
with
96 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,5 +33,7 @@ export async function newNoteAction( | |
}; | ||
} | ||
|
||
console.log(result.data); | ||
|
||
throw new Error("Not implemented"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,53 @@ | ||
"use client"; | ||
|
||
import type { EditorOptions } from "@tiptap/react"; | ||
import { ButtonGroup } from "@sovoli/ui/components/button"; | ||
import type { EditorOptions, JSONContent } from "@tiptap/react"; | ||
import { useMemo, useState } from "react"; | ||
import { EditorContent, useEditor } from "@tiptap/react"; | ||
import StarterKit from "@tiptap/starter-kit"; | ||
|
||
import { MenuButtonRedo } from "./controls/MenuButtonRedo"; | ||
import { MenuButtonUndo } from "./controls/MenuButtonUndo"; | ||
import { MenuSelectHeading } from "./controls/MenuSelectHeading"; | ||
import { EditorMenu } from "./controls/EditorMenu"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
export interface EditorProps extends Partial<EditorOptions> {} | ||
export interface EditorProps extends Partial<EditorOptions> { | ||
name: string; | ||
value?: string; | ||
} | ||
|
||
export const Editor = ({ name, value, ...rest }: EditorProps) => { | ||
const jsonContent = useMemo(() => { | ||
try { | ||
return value | ||
? (JSON.parse(value) as JSONContent) | ||
: { type: "doc", content: [] }; | ||
} catch (error) { | ||
console.error("Invalid JSON content provided to the editor:", error); | ||
return { type: "doc", content: [] }; | ||
} | ||
}, [value]); | ||
|
||
const [editorValue, setEditorValue] = useState(JSON.stringify(jsonContent)); | ||
|
||
export const Editor = (props: EditorProps) => { | ||
const editor = useEditor({ | ||
immediatelyRender: true, | ||
extensions: [StarterKit], | ||
editorProps: { | ||
attributes: { | ||
class: | ||
"w-full max-w-full py-6 px-8 prose prose-base prose-blue prose-headings:scroll-mt-[80px] focus:outline-none", | ||
}, | ||
}, | ||
...props, | ||
content: jsonContent, | ||
...rest, | ||
onUpdate: ({ editor }) => { | ||
// TODO: performance issues may arise here, use debounce later | ||
setEditorValue(JSON.stringify(editor.getJSON())); | ||
}, | ||
}); | ||
|
||
if (!editor) return null; | ||
|
||
return ( | ||
<div className="w-full flex-row items-center gap-3 rounded-large border-2 border-default-200 shadow-sm focus-within:border-default-foreground hover:border-default-400 hover:focus-within:border-default-foreground"> | ||
<div className="flex flex-wrap gap-1 border-b-1 border-default-100 p-1"> | ||
<ButtonGroup variant="light"> | ||
<MenuButtonUndo editor={editor} /> | ||
<MenuButtonRedo editor={editor} /> | ||
</ButtonGroup> | ||
<MenuSelectHeading editor={editor} /> | ||
</div> | ||
<EditorMenu editor={editor} /> | ||
<EditorContent editor={editor} /> | ||
<input type="hidden" name={name} value={editorValue} /> | ||
</div> | ||
); | ||
}; |
22 changes: 22 additions & 0 deletions
22
apps/sovoli.com/src/components/Editor/controls/EditorMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Editor } from "@tiptap/core"; | ||
import { ButtonGroup } from "@sovoli/ui/components/button"; | ||
|
||
import { MenuButtonRedo } from "./MenuButtonRedo"; | ||
import { MenuButtonUndo } from "./MenuButtonUndo"; | ||
import { MenuSelectHeading } from "./MenuSelectHeading"; | ||
|
||
export interface EditorMenuProps { | ||
editor: Editor; | ||
} | ||
|
||
export const EditorMenu = ({ editor }: EditorMenuProps) => { | ||
return ( | ||
<div className="flex flex-wrap gap-1 border-b-1 border-default-100 p-1"> | ||
<ButtonGroup variant="light"> | ||
<MenuButtonUndo editor={editor} /> | ||
<MenuButtonRedo editor={editor} /> | ||
</ButtonGroup> | ||
<MenuSelectHeading editor={editor} /> | ||
</div> | ||
); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters