feat: added undo and redo functionality

This commit is contained in:
Gerla, J. (Justin)
2025-12-07 15:21:59 +00:00
committed by JobvAlewijk
parent 608bd54617
commit 5e22ed8806
9 changed files with 490 additions and 51 deletions

View File

@@ -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],