Block Handle
A component that allows for the dragging and dropping of block nodes.
import 'prosekit/basic/style.css' import 'prosekit/basic/typography.css' import { createEditor } from 'prosekit/core' import { ProseKit } from 'prosekit/react' import { useMemo } from 'react' import BlockHandle from './block-handle' import { defineExtension } from './extension' const defaultContent = ` <h1>Heading Level 1</h1> <p>This is a paragraph under heading level 1. Markdown allows you to write text easily with simple syntax.</p> <h2>Heading Level 2</h2> <p>Here's a paragraph under heading level 2 with <strong>bold text</strong>, <em>italic text</em>, and a <a href="https://www.openai.com">link to OpenAI</a>.</p> <h3>Heading Level 3</h3> <p>This paragraph is under heading level 3. You can also include <code>inline code</code> for small snippets of code.</p> <blockquote> <p>Blockquote: This is a blockquote example.</p> <blockquote> <p>Nested Blockquote: You can nest blockquotes to represent different levels of quoted text.</p> </blockquote> </blockquote> <p>Another paragraph after the blockquote to demonstrate spacing.</p> <h3>Lists</h3> <h4>Unordered List</h4> <ul> <li>Item 1</li> <li>Item 2 <ul> <li>Subitem 2.1</li> <li>Subitem 2.2</li> </ul> </li> </ul> <h4>Ordered List</h4> <ol> <li>First item</li> <li>Second item <ol> <li>Subitem 2.1</li> <li>Subitem 2.2</li> </ol> </li> </ol> <h3>Code Block</h3> <p>You can also include code blocks:</p> <pre data-language="python"><code>def hello_world(): print("Hello, world!") </code></pre> <p>This is a paragraph after a horizontal rule.</p> ` export default function Editor() { const editor = useMemo(() => { const extension = defineExtension() return createEditor({ extension, defaultContent }) }, []) return ( <ProseKit editor={editor}> <div className='box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow flex flex-col bg-white dark:bg-gray-950 color-black dark:color-white'> <div className='relative w-full flex-1 box-border overflow-y-scroll'> <div ref={editor.mount} className='ProseMirror box-border min-h-full px-[max(4rem,_calc(50%-20rem))] py-8 outline-none outline-0 [&_span[data-mention="user"]]:text-blue-500 [&_span[data-mention="tag"]]:text-violet-500'></div> </div> <BlockHandle></BlockHandle> </div> </ProseKit> ) }
import { defineBasicExtension } from 'prosekit/basic' import { union } from 'prosekit/core' export function defineExtension() { return union([defineBasicExtension()]) } export type EditorExtension = ReturnType<typeof defineExtension>
import { BlockHandleAdd, BlockHandleDraggable, BlockHandlePopover, } from 'prosekit/react/block-handle' export default function BlockHandle() { return ( <BlockHandlePopover className='flex items-center flex-row box-border justify-center transition border-0 [&:not([data-state])]:hidden will-change-transform data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 data-[state=open]:animate-duration-150 data-[state=closed]:animate-duration-200'> <BlockHandleAdd className='flex items-center box-border justify-center h-[1.5em] w-[1.5em] hover:bg-gray-100 dark:hover:bg-gray-800 rounded text-gray-500/50 dark:text-gray-500/50 cursor-pointer'> <div className='i-lucide-plus h-5 w-5' /> </BlockHandleAdd> <BlockHandleDraggable className='flex items-center box-border justify-center h-[1.5em] w-[1.2em] hover:bg-gray-100 dark:hover:bg-gray-800 rounded text-gray-500/50 dark:text-gray-500/50 cursor-grab'> <div className='i-lucide-grip-vertical h-5 w-5' /> </BlockHandleDraggable> </BlockHandlePopover> ) }
<script setup lang="ts"> import 'prosekit/basic/style.css' import 'prosekit/basic/typography.css' import { createEditor } from 'prosekit/core' import { ProseKit } from 'prosekit/vue' import { ref, watchPostEffect, } from 'vue' import BlockHandle from './block-handle.vue' import { defineExtension } from './extension' const defaultContent = ` <h1>Heading Level 1</h1> <p>This is a paragraph under heading level 1. Markdown allows you to write text easily with simple syntax.</p> <h2>Heading Level 2</h2> <p>Here's a paragraph under heading level 2 with <strong>bold text</strong>, <em>italic text</em>, and a <a href="https://www.openai.com">link to OpenAI</a>.</p> <h3>Heading Level 3</h3> <p>This paragraph is under heading level 3. You can also include <code>inline code</code> for small snippets of code.</p> <blockquote> <p>Blockquote: This is a blockquote example.</p> <blockquote> <p>Nested Blockquote: You can nest blockquotes to represent different levels of quoted text.</p> </blockquote> </blockquote> <p>Another paragraph after the blockquote to demonstrate spacing.</p> <h3>Lists</h3> <h4>Unordered List</h4> <ul> <li>Item 1</li> <li>Item 2 <ul> <li>Subitem 2.1</li> <li>Subitem 2.2</li> </ul> </li> </ul> <h4>Ordered List</h4> <ol> <li>First item</li> <li>Second item <ol> <li>Subitem 2.1</li> <li>Subitem 2.2</li> </ol> </li> </ol> <h3>Code Block</h3> <p>You can also include code blocks:</p> <pre data-language="python"><code>def hello_world(): print("Hello, world!") </code></pre> <p>This is a paragraph after a horizontal rule.</p> ` const editor = createEditor({ extension: defineExtension(), defaultContent }) const editorRef = ref<HTMLDivElement | null>(null) watchPostEffect((onCleanup) => { editor.mount(editorRef.value) onCleanup(() => editor.unmount()) }) </script> <template> <ProseKit :editor="editor"> <div class='box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow flex flex-col bg-white dark:bg-gray-950 color-black dark:color-white'> <div class='relative w-full flex-1 box-border overflow-y-scroll'> <div ref="editorRef" spellcheck="false" class='ProseMirror box-border min-h-full px-[max(4rem,_calc(50%-20rem))] py-8 outline-none outline-0 [&_span[data-mention="user"]]:text-blue-500 [&_span[data-mention="tag"]]:text-violet-500' /> </div> <BlockHandle></BlockHandle> </div> </ProseKit> </template>
import { defineBasicExtension } from 'prosekit/basic' import { union } from 'prosekit/core' export function defineExtension() { return union([defineBasicExtension()]) } export type EditorExtension = ReturnType<typeof defineExtension>
<script setup lang="ts"> import { BlockHandleAdd, BlockHandleDraggable, BlockHandlePopover, } from 'prosekit/vue/block-handle' </script> <template> <BlockHandlePopover class='flex items-center flex-row box-border justify-center transition border-0 [&:not([data-state])]:hidden will-change-transform data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 data-[state=open]:animate-duration-150 data-[state=closed]:animate-duration-200'> <BlockHandleAdd class='flex items-center box-border justify-center h-[1.5em] w-[1.5em] hover:bg-gray-100 dark:hover:bg-gray-800 rounded text-gray-500/50 dark:text-gray-500/50 cursor-pointer'> <div class='i-lucide-plus h-5 w-5' /> </BlockHandleAdd> <BlockHandleDraggable class='flex items-center box-border justify-center h-[1.5em] w-[1.2em] hover:bg-gray-100 dark:hover:bg-gray-800 rounded text-gray-500/50 dark:text-gray-500/50 cursor-grab'> <div class='i-lucide-grip-vertical h-5 w-5' /> </BlockHandleDraggable> </BlockHandlePopover> </template>
Copy and paste the component source files linked above into your project.
The BlockHandle
consists of three parts:
BlockHandlePopover
: A popover that appears on the left side of a block when you hover over it.BlockHandleAdd
: A button that lets you insert a new block below the one you’re hovering over.BlockHandleDraggable
: A draggable component that allows to reorder a block.
You can choose to use either BlockHandleAdd
, BlockHandleDraggable
, or both components together.