Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | import type { Edge, Node } from '@vue-flow/core'
import { defineStore } from 'pinia'
interface WorkflowState {
nodes: Node[]
edges: Edge[]
hasUnsavedChanges: boolean
currentWorkflowId: string | null
currentWorkflowName: string
}
export const useWorkflowStore = defineStore('workflow', {
state: (): WorkflowState => ({
nodes: [],
edges: [],
hasUnsavedChanges: false,
currentWorkflowId: null,
currentWorkflowName: 'Untitled Workflow',
}),
getters: {
hasNodes(): boolean {
return this.nodes.length > 0
},
},
actions: {
addNode(node: Node) {
this.nodes.push(node)
this.hasUnsavedChanges = true
},
removeNode(nodeId: string) {
this.nodes = this.nodes.filter((n) => n.id !== nodeId)
this.edges = this.edges.filter((e) => e.source !== nodeId && e.target !== nodeId)
this.hasUnsavedChanges = true
},
addEdge(edge: Edge) {
this.edges.push(edge)
this.hasUnsavedChanges = true
},
removeEdge(edgeId: string) {
this.edges = this.edges.filter((e) => e.id !== edgeId)
this.hasUnsavedChanges = true
},
clearCanvas() {
this.nodes = []
this.edges = []
this.hasUnsavedChanges = false
this.currentWorkflowId = null
this.currentWorkflowName = 'Untitled Workflow'
},
updateNodeData(nodeId: string, data: any, markDirty = true) {
const node = this.nodes.find((n) => n.id === nodeId)
if (node) {
node.data = { ...node.data, ...data }
if (markDirty) {
this.hasUnsavedChanges = true
}
}
},
loadWorkflow(nodes: Node[], edges: Edge[]) {
this.nodes = nodes || []
this.edges = edges || []
this.hasUnsavedChanges = false
},
markAsSaved() {
this.hasUnsavedChanges = false
},
markAsDirty() {
this.hasUnsavedChanges = true
},
setWorkflowMetadata(id: string | null, name: string) {
this.currentWorkflowId = id
this.currentWorkflowName = name
},
},
})
|