feat: added undo and redo functionality
This commit is contained in:
committed by
JobvAlewijk
parent
608bd54617
commit
5e22ed8806
@@ -64,8 +64,8 @@ function DraggableNode({ className, children, nodeType, onDrop }: DraggableNodeP
|
||||
* @param nodeType - The type of node to create (from `NodeTypes`).
|
||||
* @param position - The XY position in the flow canvas where the node will appear.
|
||||
*/
|
||||
function addNode(nodeType: keyof typeof NodeTypes, position: XYPosition) {
|
||||
const { nodes, setNodes } = useFlowStore.getState();
|
||||
function addNodeToFlow(nodeType: keyof typeof NodeTypes, position: XYPosition) {
|
||||
const { nodes, addNode } = useFlowStore.getState();
|
||||
|
||||
// Load any predefined data for this node type.
|
||||
const defaultData = NodeDefaults[nodeType] ?? {}
|
||||
@@ -90,7 +90,7 @@ function addNode(nodeType: keyof typeof NodeTypes, position: XYPosition) {
|
||||
position,
|
||||
data: {...defaultData}
|
||||
}
|
||||
setNodes([...nodes, newNode]);
|
||||
addNode(newNode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +125,7 @@ export function DndToolbar() {
|
||||
|
||||
if (isInFlow) {
|
||||
const position = screenToFlowPosition(screenPosition);
|
||||
addNode(nodeType, position);
|
||||
addNodeToFlow(nodeType, position);
|
||||
}
|
||||
},
|
||||
[screenToFlowPosition],
|
||||
|
||||
Reference in New Issue
Block a user