"use client"; import { useState } from "react"; import { MDXEditor, toolbarPlugin, headingsPlugin, listsPlugin, quotePlugin, thematicBreakPlugin, markdownShortcutPlugin, BoldItalicUnderlineToggles, ListsToggle, BoldItalicUnderlineTogglesProps, MDXEditorProps, UndoRedo, InsertImage, CreateLink } from "@mdxeditor/editor"; import DOMPurify from "isomorphic-dompurify"; import { Button } from "@/components/ui/button"; import useApiMutation from "@/hooks/use-api"; export default function Editor() { const [blogContent, setBlogContent] = useState(""); const [cursor, setCursor] = useState<{ line: number; column: number }>({ line: 0, column: 0, }); const getCursorPosition = (newText: string) => { const cursorPos = newText.length; const lines = newText.substring(0, cursorPos).split("\n"); const line = lines.length; // Current line number const column = lines[lines.length - 1].length + 1; // Current column number setCursor({ line, column }); }; const sanitized = DOMPurify.sanitize(blogContent); const propsa: BoldItalicUnderlineTogglesProps = { options: ["Bold", "Italic", "Underline"] } const mdxEditorProps: MDXEditorProps = {} const { trigger, isMutating: loading, isSuccess, } = useApiMutation( "/blog/new", undefined, "POST", false, true, ); return (
(
), }), ]} onChange={setBlogContent} onBlur={() => getCursorPosition(blogContent)} markdown="ok" />
Line: {cursor.line}; Column: {cursor.column}
); }