Drag & Drop
components/demo.tsx
'use client';
import React from 'react';
import { Plate } from '@udecode/plate/react';
import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';
import { DEMO_VALUES } from './values/demo-values';
export default function Demo({ id }: { id: string }) {
const editor = useCreateEditor({
plugins: [...editorPlugins],
value: DEMO_VALUES[id],
});
return (
<Plate editor={editor}>
<EditorContainer variant="demo">
<Editor />
</EditorContainer>
</Plate>
);
}
Installation
npm install @udecode/plate-dnd @udecode/plate-node-id react-dnd react-dnd-html5-backend
Usage
import { DndPlugin } from '@udecode/plate-dnd';
import { NodeIdPlugin } from '@udecode/plate-node-id';
const plugins = [
// ...otherPlugins,
NodeIdPlugin,
DndPlugin,
];
Then, wrap your plugin components with Draggable.
Plugins
DndPlugin
API
focusBlockStartById
getBlocksWithId
selectBlockById
Components
withDraggable
DndScroller
Hooks
useDndNode
- Default:
'block'
- Default:
'vertical'
The ID of the node to be dragged.
The type of drag item.
The ref of the node to be dragged.
The orientation of drag and drop.
Callback to determine if a node can be dropped.
The preview options for the dragged node.
The drag options for the dragged node.
The drop options for the dragged node.
Handler called when the node is dropped.