Skip to content

Table handle

Table handles are floating controls that appear alongside the rows and columns of a table. They let users select an entire row or column and trigger table commands (insert above/below, delete, move). Use them whenever you've enabled the table extension and want users to manipulate table structure with the mouse instead of remembering keyboard commands.

'use client'

import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'

import { createEditor, type NodeJSON } from 'prosekit/core'
import { ProseKit } from 'prosekit/react'
import { useMemo } from 'react'

import { sampleContent } from '../../sample/sample-doc-table'
import { TableHandle } from '../../ui/table-handle'

import { defineExtension } from './extension'

interface EditorProps {
  initialContent?: NodeJSON
}

export default function Editor(props: EditorProps) {
  const defaultContent = props.initialContent ?? sampleContent
  const editor = useMemo(() => {
    const extension = defineExtension()
    return createEditor({ extension, defaultContent })
  }, [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-sm flex flex-col bg-[canvas] text-black dark:text-white">
        <div className="relative w-full flex-1 box-border overflow-y-auto">
          <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>
          <TableHandle />
        </div>
      </div>
    </ProseKit>
  )
}
npx shadcn@latest add @prosekit/react-ui-table-handle
TableHandleRoot                              # root component
├── TableHandleDragPreview                   # ghost row/col shown while dragging
├── TableHandleDropIndicator                 # line that previews the drop target
├── TableHandleColumnPositioner              # floating container above the active column
│   └── TableHandleColumnPopup               # container for the column trigger + menu
│       └── TableHandleColumnMenuRoot        # binds the trigger to its menu
│           ├── TableHandleColumnMenuTrigger # the visible column "grip" handle
│           └── MenuPositioner               # anchors the dropdown to the trigger
│               └── MenuPopup                # the dropdown panel
│                   └── MenuItem             # one per column action (insert / delete / …)
└── TableHandleRowPositioner                 # floating container beside the active row
    └── TableHandleRowPopup                  # container for the row trigger + menu
        └── TableHandleRowMenuRoot           # binds the trigger to its menu
            ├── TableHandleRowMenuTrigger    # the visible row "grip" handle
            └── MenuPositioner               # anchors the dropdown to the trigger
                └── MenuPopup                # the dropdown panel
                    └── MenuItem             # one per row action