| import { useEditor, EditorContent } from "@tiptap/react"; | |
| import StarterKit from "@tiptap/starter-kit"; | |
| import ImageExtension from "@tiptap/extension-image"; | |
| import Placeholder from "@tiptap/extension-placeholder"; | |
| import Table from "@tiptap/extension-table"; | |
| import TableRow from "@tiptap/extension-table-row"; | |
| import TableCell from "@tiptap/extension-table-cell"; | |
| import TableHeader from "@tiptap/extension-table-header"; | |
| import CodeBlock from "@tiptap/extension-code-block"; | |
| import Link from "@tiptap/extension-link"; | |
| import Underline from "@tiptap/extension-underline"; | |
| import TaskList from "@tiptap/extension-task-list"; | |
| import TaskItem from "@tiptap/extension-task-item"; | |
| import Highlight from "@tiptap/extension-highlight"; | |
| import { Button } from "../../../components/ui/Button"; | |
| import { | |
| Bold, | |
| Italic, | |
| Underline as UnderlineIcon, | |
| Strikethrough, | |
| Code, | |
| Quote, | |
| List, | |
| ListOrdered, | |
| Link as LinkIcon, | |
| Image as ImageIcon, | |
| Table2, | |
| Heading1, | |
| Heading2, | |
| Heading3, | |
| Undo, | |
| Redo, | |
| Highlighter, | |
| } from "lucide-react"; | |
| interface RichNoteEditorProps { | |
| content: string; | |
| onChange: (html: string) => void; | |
| placeholder?: string; | |
| } | |
| export default function RichNoteEditor({ | |
| content, | |
| onChange, | |
| placeholder, | |
| }: RichNoteEditorProps) { | |
| const editor = useEditor({ | |
| extensions: [ | |
| StarterKit.configure({ | |
| codeBlock: false, | |
| }), | |
| Placeholder.configure({ | |
| placeholder: placeholder || "Write something amazing...", | |
| }), | |
| ImageExtension, | |
| Table.configure({ resizable: true }), | |
| TableRow, | |
| TableCell, | |
| TableHeader, | |
| CodeBlock, | |
| Link.configure({ openOnClick: false }), | |
| Underline, | |
| TaskList, | |
| TaskItem, | |
| Highlight, | |
| ], | |
| content, | |
| onUpdate: ({ editor }) => { | |
| onChange(editor.getHTML()); | |
| }, | |
| }); | |
| if (!editor) return null; | |
| const addImage = () => { | |
| const url = window.prompt("Image URL"); | |
| if (url) editor.chain().focus().setImage({ src: url }).run(); | |
| }; | |
| const addLink = () => { | |
| const url = window.prompt("Link URL"); | |
| if (url) editor.chain().focus().setLink({ href: url }).run(); | |
| }; | |
| const ToolbarButton = ({ | |
| active, | |
| onClick, | |
| children, | |
| }: { | |
| active?: boolean; | |
| onClick: () => void; | |
| children: React.ReactNode; | |
| }) => ( | |
| <button | |
| type="button" | |
| onClick={onClick} | |
| className={`p-2 rounded-lg transition-colors ${active ? "bg-neon-blue/20 text-neon-blue" : "text-slate-400 hover:bg-white/10 hover:text-white"}`} | |
| > | |
| {children} | |
| </button> | |
| ); | |
| return ( | |
| <div className="glass border border-white/10 rounded-2xl overflow-hidden"> | |
| {/* Toolbar */} | |
| <div className="flex flex-wrap items-center gap-1 p-2 border-b border-white/5 bg-cyber-800 sticky top-0 z-10"> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleBold().run()} | |
| active={editor.isActive("bold")} | |
| > | |
| <Bold size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleItalic().run()} | |
| active={editor.isActive("italic")} | |
| > | |
| <Italic size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleUnderline().run()} | |
| active={editor.isActive("underline")} | |
| > | |
| <UnderlineIcon size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleStrike().run()} | |
| active={editor.isActive("strike")} | |
| > | |
| <Strikethrough size={16} /> | |
| </ToolbarButton> | |
| <div className="w-px h-5 bg-white/10 mx-1" /> | |
| <ToolbarButton | |
| onClick={() => | |
| editor.chain().focus().toggleHeading({ level: 1 }).run() | |
| } | |
| active={editor.isActive("heading", { level: 1 })} | |
| > | |
| <Heading1 size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => | |
| editor.chain().focus().toggleHeading({ level: 2 }).run() | |
| } | |
| active={editor.isActive("heading", { level: 2 })} | |
| > | |
| <Heading2 size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => | |
| editor.chain().focus().toggleHeading({ level: 3 }).run() | |
| } | |
| active={editor.isActive("heading", { level: 3 })} | |
| > | |
| <Heading3 size={16} /> | |
| </ToolbarButton> | |
| <div className="w-px h-5 bg-white/10 mx-1" /> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleBulletList().run()} | |
| active={editor.isActive("bulletList")} | |
| > | |
| <List size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleOrderedList().run()} | |
| active={editor.isActive("orderedList")} | |
| > | |
| <ListOrdered size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleTaskList().run()} | |
| active={editor.isActive("taskList")} | |
| > | |
| <List size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleBlockquote().run()} | |
| active={editor.isActive("blockquote")} | |
| > | |
| <Quote size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleCodeBlock().run()} | |
| active={editor.isActive("codeBlock")} | |
| > | |
| <Code size={16} /> | |
| </ToolbarButton> | |
| <div className="w-px h-5 bg-white/10 mx-1" /> | |
| <ToolbarButton onClick={addLink} active={editor.isActive("link")}> | |
| <LinkIcon size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton onClick={addImage}> | |
| <ImageIcon size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => | |
| editor | |
| .chain() | |
| .focus() | |
| .insertTable({ rows: 3, cols: 3, withHeaderRow: true }) | |
| .run() | |
| } | |
| > | |
| <Table2 size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton | |
| onClick={() => editor.chain().focus().toggleHighlight().run()} | |
| active={editor.isActive("highlight")} | |
| > | |
| <Highlighter size={16} /> | |
| </ToolbarButton> | |
| <div className="flex-1" /> | |
| <ToolbarButton onClick={() => editor.chain().focus().undo().run()}> | |
| <Undo size={16} /> | |
| </ToolbarButton> | |
| <ToolbarButton onClick={() => editor.chain().focus().redo().run()}> | |
| <Redo size={16} /> | |
| </ToolbarButton> | |
| </div> | |
| {/* Editor */} | |
| <EditorContent | |
| editor={editor} | |
| className="prose prose-invert max-w-none p-6 min-h-[300px] focus:outline-none" | |
| /> | |
| </div> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 6.82 kB
- Xet hash:
- a9444926a877c1dfb6e4c2188d6c5b05b8805d3044b48a117c5d36fad97fb98f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.