feat: undo/redo for workflow editor (#3927)

Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
Pascal M
2024-06-26 08:37:12 +02:00
committed by GitHub
parent d0fe56a98e
commit af9448e6f2
38 changed files with 2049 additions and 778 deletions

View File

@@ -12,7 +12,7 @@ import {
useStore,
useWorkflowStore,
} from './store'
import { useNodesInteractions } from './hooks'
import { WorkflowHistoryEvent, useNodesInteractions, useWorkflowHistory } from './hooks'
import { CUSTOM_NODE } from './constants'
import CustomNode from './nodes'
import CustomNoteNode from './note-node'
@@ -26,6 +26,7 @@ const CandidateNode = () => {
const mousePosition = useStore(s => s.mousePosition)
const { zoom } = useViewport()
const { handleNodeSelect } = useNodesInteractions()
const { saveStateToHistory } = useWorkflowHistory()
useEventListener('click', (e) => {
const { candidateNode, mousePosition } = workflowStore.getState()
@@ -53,6 +54,11 @@ const CandidateNode = () => {
})
})
setNodes(newNodes)
if (candidateNode.type === CUSTOM_NOTE_NODE)
saveStateToHistory(WorkflowHistoryEvent.NoteAdd)
else
saveStateToHistory(WorkflowHistoryEvent.NodeAdd)
workflowStore.setState({ candidateNode: undefined })
if (candidateNode.type === CUSTOM_NOTE_NODE)