Skip to content
GitHubDiscord

Block Handle

Block handle components enable users to interact with, reorder, and insert blocks in your editor through drag-and-drop operations.

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 { DEFAULT_DRAG_AND_DROP_CONTENT } from './default-content-drag-and-drop'
import DropIndicator from './drop-indicator'
import { defineExtension } from './extension'

export default function Editor() {
  const editor = useMemo(() => {
    const extension = defineExtension()
    return createEditor({ extension, defaultContent: DEFAULT_DRAG_AND_DROP_CONTENT })
  }, [])

  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-sm 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-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
          <BlockHandle />
          <DropIndicator />
        </div>
      </div>
    </ProseKit>
  )
}

The block handle system provides two main capabilities:

  • Block manipulation: Add new blocks or drag existing blocks to reorder content
  • Visual feedback: Show users exactly where content will be placed during drag operations

The BlockHandle consists of three main components:

  • BlockHandlePopover: A popover container that appears on the left side when hovering over a block
  • BlockHandleAdd: An add button (+) that inserts a new block below the current one
  • BlockHandleDraggable: A drag handle (⋮⋮) that allows users to reorder blocks by dragging

You can use BlockHandleAdd, BlockHandleDraggable, or both together depending on your needs.

The DropIndicator provides visual feedback during drag-and-drop operations by showing a horizontal line where the dragged content will be inserted. It automatically appears when dragging and disappears when the drag operation completes.

Copy and paste the component source files linked above into your project.