{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dnd-docs",
  "title": "Drag & Drop",
  "description": "Drag and drop blocks to reorganize content within the editor.",
  "files": [
    {
      "path": "../../content/docs/(plugins)/(functionality)/dnd.mdx",
      "content": "---\ntitle: Drag & Drop\ndescription: Drag and drop blocks to reorganize content within the editor.\ndocs:\n  - route: https://pro.platejs.org/docs/examples/dnd\n    title: Plus\n  - route: /docs/components/block-draggable\n    title: Block Draggable\n---\n\n<ComponentPreview name=\"dnd-demo\" />\n\n<PackageInfo>\n\n## Features\n\n- Drag and drop blocks for content movement and insertion within the editor.\n- Automatic scrolling when dragging blocks near viewport edges.\n- File drop support for inserting media blocks.\n- Visual drop indicators and drag handles.\n\n</PackageInfo>\n\n## Kit Usage\n\n<Steps>\n\n### Installation\n\nThe fastest way to add drag and drop functionality is with the `DndKit`, which includes the pre-configured `DndPlugin` along with React DnD setup and the [`BlockDraggable`](/docs/components/block-draggable) UI component.\n\n<ComponentSource name=\"dnd-kit\" />\n\n- [`BlockDraggable`](/docs/components/block-draggable): Renders drag handles and drop indicators for blocks.\n\n### Add Kit\n\n```tsx\nimport { createPlateEditor } from 'platejs/react';\nimport { DndKit } from '@/components/editor/plugins/dnd-kit';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    ...DndKit,\n  ],\n});\n```\n\n</Steps>\n\n## Manual Usage\n\n<Steps>\n\n### Installation\n\n```bash\nnpm install @platejs/dnd react-dnd react-dnd-html5-backend\n```\n\n### Add Plugin\n\n```tsx\nimport { DndPlugin } from '@platejs/dnd';\nimport { createPlateEditor } from 'platejs/react';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    DndPlugin,\n  ],\n});\n```\n\n### Configure Plugin\n\nConfigure drag and drop with a draggable component and DnD provider:\n\n```tsx\nimport { DndProvider } from 'react-dnd';\nimport { HTML5Backend } from 'react-dnd-html5-backend';\nimport { DndPlugin } from '@platejs/dnd';\n\nDndPlugin.configure({\n  render: {\n    aboveSlate: ({ children }) => (\n      <DndProvider backend={HTML5Backend}>{children}</DndProvider>\n    ),\n  },\n});\n```\n\n- `render.aboveNodes`: Assigns [`BlockDraggable`](/docs/components/block-draggable) to render drag handles above blocks.\n- `render.aboveSlate`: Wraps the editor with `DndProvider` and `HTML5Backend`. Remove this if you already have `DndProvider` in your React tree.\n\n### Advanced Configuration\n\nAdd automatic scrolling and file drop handling:\n\n```tsx\nimport { DndPlugin } from '@platejs/dnd';\nimport { PlaceholderPlugin } from '@platejs/media/react';\n\nDndPlugin.configure({\n  options: {\n    enableScroller: true,\n    onDropFiles: ({ dragItem, editor, target }) => {\n      editor\n        .getTransforms(PlaceholderPlugin)\n        .insert.media(dragItem.files, { at: target, nextBlock: false });\n    },\n  },\n  render: {\n    aboveNodes: BlockDraggable,\n    aboveSlate: ({ children }) => (\n      <DndProvider backend={HTML5Backend}>{children}</DndProvider>\n    ),\n  },\n});\n```\n\n- `enableScroller`: Enables automatic scrolling when dragging blocks near the viewport edges.\n- `onDropFiles`: Handles file drops by inserting them as media blocks at the target location.\n\n</Steps>\n\n## Plugins\n\n### `DndPlugin`\n\nPlugin for drag and drop functionality within the editor.\n\n<API name=\"DndPlugin\">\n<APIOptions>\n  <APIItem name=\"enableScroller\" type=\"boolean\" optional>\n    Enables automatic scrolling when dragging blocks near viewport edges.\n    - **Default:** `false`\n  </APIItem>\n  <APIItem name=\"scrollerProps\" type=\"Partial<ScrollerProps>\" optional>\n    Props for the `Scroller` component when `enableScroller` is true.\n  </APIItem>\n  <APIItem name=\"onDropFiles\" type=\"function\" optional>\n    Handler for file drop events.\n    <APISubList>\n      <APISubListItem parent=\"onDropFiles\" name=\"id\" type=\"string\">\n        ID of the target element.\n      </APISubListItem>\n      <APISubListItem parent=\"onDropFiles\" name=\"dragItem\" type=\"FileDragItemNode\">\n        Object containing the dropped files.\n      </APISubListItem>\n      <APISubListItem parent=\"onDropFiles\" name=\"editor\" type=\"PlateEditor\">\n        The editor instance.\n      </APISubListItem>\n      <APISubListItem parent=\"onDropFiles\" name=\"target\" type=\"Path\">\n        Path where files should be inserted.\n      </APISubListItem>\n    </APISubList>\n  </APIItem>\n  <APIItem name=\"dropTarget\" type=\"{ id: string | null; line: DropLineDirection }\" optional>\n    The current drop target state containing both the target element id and drop line direction.\n  </APIItem>\n</APIOptions>\n</API>\n\n## API\n\n### `focusBlockStartById`\n\nSelects the start of a block by ID and focuses the editor.\n\n<API name=\"focusBlockStartById\">\n<APIParameters>\n  <APIItem name=\"id\" type=\"string\">\n    The ID of the block to be focused.\n  </APIItem>\n</APIParameters>\n</API>\n\n### `getBlocksWithId`\n\nReturns an array of blocks that have an ID.\n\n<API name=\"getBlocksWithId\">\n<APIOptions type=\"EditorNodesOptions\">\n  The options for getting node entries.\n</APIOptions>\n\n<APIReturns type=\"NodeEntry[]\">\n  Array of blocks that have an ID.\n</APIReturns>\n</API>\n\n### `selectBlockById`\n\nSelects a block by its ID.\n\n<API name=\"selectBlockById\">\n<APIParameters>\n  <APIItem name=\"id\" type=\"string\">\n    The ID of the block to select.\n  </APIItem>\n</APIParameters>\n</API>\n\n## Hooks\n\n### `useDndNode`\n\nA custom hook that combines the `useDragNode` and `useDropNode` hooks to enable dragging and dropping of a node from the editor. It provides a default preview for the dragged node, which can be customized or disabled.\n\n<API name=\"useDndNode\">\n<APIOptions type=\"UseDndNodeOptions\">\n  <APIItem name=\"element\" type=\"TElement\">\n    The node to be dragged.\n  </APIItem>\n  <APIItem name=\"type\" type=\"string\" optional>\n    The type of drag item.\n    - **Default:** `'block'`\n  </APIItem>\n  <APIItem name=\"nodeRef\" type=\"any\">\n    The ref of the node to be dragged.\n  </APIItem>\n  <APIItem name=\"orientation\" type=\"'horizontal' | 'vertical'\" optional>\n    The orientation of drag and drop.\n    - **Default:** `'vertical'`\n  </APIItem>\n  <APIItem name=\"canDropNode\" type=\"(args: { dragEntry: NodeEntry; dragItem: DragItemNode; dropEntry: NodeEntry; editor: PlateEditor }) => boolean\" optional>\n    Callback to determine if a node can be dropped at the current location.\n  </APIItem>\n  <APIItem name=\"preview\" type=\"previewOptions\" optional>\n    The preview options for the dragged node.\n  </APIItem>\n  <APIItem name=\"drag\" type=\"dragOptions\" optional>\n    The drag options for the dragged node.\n  </APIItem>\n  <APIItem name=\"drop\" type=\"dropOptions\" optional>\n    The drop options for the dragged node.\n  </APIItem>\n  <APIItem name=\"onDropHandler\" type=\"string\" optional>\n    Handler called when the node is dropped.\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"object\">\n  <APIItem name=\"isDragging\" type=\"boolean\">\n    Whether the node is currently being dragged.\n  </APIItem>\n  <APIItem name=\"isOver\" type=\"boolean\">\n    Whether the dragged node is over a drop target.\n  </APIItem>\n  <APIItem name=\"dragRef\" type=\"ConnectDragSource\">\n    Drag reference for the draggable element.\n  </APIItem>\n</APIReturns>\n</API>\n\n### `useDragNode`\n\nA custom hook that enables dragging of a node from the editor using the `useDrag` hook from `react-dnd`.\n\n<API name=\"useDragNode\">\n<APIOptions type=\"UseDragNodeOptions\">\n  <APIItem name=\"element\" type=\"TElement\">\n    The node to be dragged.\n  </APIItem>\n  <APIItem name=\"item\" type=\"DragObject | DragObjectFactory<DragObject>\" optional>\n    Drag object or factory function that returns it.\n  </APIItem>\n</APIOptions>\n</API>\n\n### `useDraggable`\n\nA custom hook that enables draggable behavior for a given element. It provides a preview for the element, which can be customized or disabled.\n\n<API name=\"useDraggable\">\n<APIOptions type=\"object\">\n  <APIItem name=\"element\" type=\"TElement\">\n    The element to make draggable.\n  </APIItem>\n  <APIItem name=\"orientation\" type=\"'horizontal' | 'vertical'\" optional>\n    Orientation of drag and drop.\n    - **Default:** `'vertical'`\n  </APIItem>\n  <APIItem name=\"type\" type=\"string\" optional>\n    Type of drag item.\n    - **Default:** `'block'`\n  </APIItem>\n  <APIItem name=\"onDropHandler\" type=\"function\" optional>\n    Handler called when element is dropped.\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"object\">\n  <APIItem name=\"handleRef\" type=\"(element: Element | React.ReactElement | React.RefObject<any> | null) => void\">\n    Drag source connector function.\n  </APIItem>\n  <APIItem name=\"isDragging\" type=\"boolean\">\n    Whether element is being dragged.\n  </APIItem>\n  <APIItem name=\"previewRef\" type=\"React.RefObject<HTMLDivElement>\">\n    Reference to draggable element.\n  </APIItem>\n</APIReturns>\n</API>\n\n### `useDropNode`\n\nA custom hook that enables dropping a node on the editor. It uses the `useDrop` hook from `react-dnd` to handle the drop behavior.\n\n<API name=\"useDropNode\">\n<APIOptions type=\"UseDropNodeOptions\">\n  <APIItem name=\"nodeRef\" type=\"any\">\n    Reference to the node being dragged.\n  </APIItem>\n  <APIItem name=\"element\" type=\"TElement\">\n    The node to which the drop line is attached.\n  </APIItem>\n  <APIItem name=\"dropLine\" type=\"string\">\n    Current value of the drop line.\n  </APIItem>\n  <APIItem name=\"onChangeDropLine\" type=\"function\">\n    Callback when drop line changes.\n  </APIItem>\n  <APIItem name=\"onDropHandler\" type=\"object\">\n    Callback that intercepts drop handling.\n    - Returns `true` to prevent default behavior\n    - Returns `false` to run default behavior after\n  </APIItem>\n</APIOptions>\n</API>\n\n### `useDropLine`\n\nReturns the current drop line state for an element.\n\n<API name=\"useDropLine\">\n<APIOptions type=\"object\">\n  <APIItem name=\"id\" type=\"string\" optional>\n    Element ID to show drop line for.\n    - **Default:** Current element ID\n  </APIItem>\n  <APIItem name=\"orientation\" type=\"'horizontal' | 'vertical'\" optional>\n    Filter drop lines by orientation.\n    - **Default:** `'vertical'`\n  </APIItem>\n</APIOptions>\n\n<APIReturns type=\"object\">\n  <APIItem name=\"dropLine\" type=\"'top' | 'bottom' | 'left' | 'right' | ''\">\n    Current drop line direction.\n  </APIItem>\n</APIReturns>\n</API>\n",
      "type": "registry:file",
      "target": "content/docs/plate/(plugins)/(functionality)/dnd.mdx"
    }
  ],
  "type": "registry:file"
}