@dnd-kit/core. This system handles dragging components from the sidebar, reordering nodes on the canvas, and managing the layer tree hierarchy.
Architecture
The drag-and-drop implementation is centered around a single<DragDropProvider> that wraps the editor. This provider manages the global drag state and coordinates interactions between different drag sources (sidebar, canvas, layers) and drop targets.
Key Components
- DragDropProvider: The context provider that manages
activeId,activeData, andoverId. It handles allonDragEndlogic to determine if a node should be created (sidebar drop) or moved (reorder). - Draggable: Elements that can be dragged (Sidebar items, Canvas nodes, Layer tree items).
- Droppable: Areas where items can be dropped (Canvas nodes, Drop indicators).
Usage
Setup
TheEmailEditor component already includes the DragDropProvider, so you don’t need to wrap it yourself. Just use the component as usual:
Custom Layouts
If you are building a custom editor layout and dragging items fromEditorSidebar or other sources, you must wrap your application in DragDropProvider manually.
Drag Sources
There are three primary drag sources:- Sidebar Items: New components waiting to be added.
- Type:
sidebar-component - Action: Creates a new node on drop.
- Type:
- Canvas Nodes: Existing nodes on the visualization canvas.
- Type:
canvas-node - Action: Moves the node to a new position.
- Type:
- Layer Nodes: Existing nodes in the layer tree.
- Type:
layer-node - Action: Moves the node to a new position.
- Type:
Drop Targets
Items can be dropped in two ways:- On a Node: Dropping directly onto a component (e.g., a Container or Text block).
- If the target accepts children (like a Container), the item is inserted as the first child.
- If the target does not accept children (like a Text block), the item is inserted after the target.
- On a Drop Indicator: Thin lines that appear between nodes to indicate precise insertion points.
