Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BlockNoteを布教するぜ

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for imaimai17468 imaimai17468
August 07, 2024
47

 BlockNoteを布教するぜ

BlockNoteを紹介するためのスライドです

Avatar for imaimai17468

imaimai17468

August 07, 2024
Tweet

Transcript

  1. 必要なのはこれだけ! import "@blocknote/core/fonts/inter.css"; import { useCreateBlockNote } from "@blocknote/react"; import

    { BlockNoteView } from "@blocknote/mantine"; import "@blocknote/mantine/style.css"; export default function App() { const editor = useCreateBlockNote(); return <BlockNoteView editor={editor} />; } 12
  2. (前置き) 型構造は複雑 type Block = { id: string; type: string;

    props: Record<string, boolean | number | string>; content: InlineContent[] | TableContent | undefined; children: Block[]; }; children: Block[] : 無限入れ子 15
  3. 入出力が簡単! Markdown / HTMLで入力・出力できます! const editor = useCreateBlockNote(); // INPUT:

    in first rendering (ex. useEffect) const blocks = await editor.tryParseMarkdownToBlocks(e.target.value); editor.replaceBlocks(editor.document, blocks); // OUTPUT: Markdown export handler const [markdown, setMarkdown] = useState<string>(); const onChange = async () => { const markdown = await editor.blocksToMarkdownLossy(editor.document); setMarkdown(markdown); }; return <BlockNoteView editor={editor} onChange={onChange} /> 17