feat(flow): export apply changes utilities for options api

This commit is contained in:
Braks
2022-04-04 21:42:48 +02:00
parent 4b0ac0a9b8
commit d95a83349b
4 changed files with 48 additions and 23 deletions
+11 -2
View File
@@ -18,6 +18,7 @@ import {
XYPosition,
XYZPosition,
Getters,
DefaultEdgeOptions,
} from '~/types'
import { useWindow } from '~/composables'
@@ -139,7 +140,11 @@ export const connectionExists = (edge: Edge, elements: Elements) =>
(el.targetHandle === edge.targetHandle || (!el.targetHandle && !edge.targetHandle)),
)
export const addEdge = (edgeParams: Edge | Connection, elements: Elements) => {
/**
* Intended for options API
* In composition API you can access utilities from `useVueFlow`
*/
export const addEdge = (edgeParams: Edge | Connection, elements: Elements, defaults?: DefaultEdgeOptions) => {
if (!edgeParams.source || !edgeParams.target) {
console.warn("Can't create edge. An edge needs a source and a target.")
return elements
@@ -154,12 +159,16 @@ export const addEdge = (edgeParams: Edge | Connection, elements: Elements) => {
id: getEdgeId(edgeParams),
} as Edge
}
edge = parseEdge(edge)
edge = parseEdge(edge, defaults)
if (connectionExists(edge, elements)) return elements
elements.push(edge)
return [...elements, edge]
}
/**
* Intended for options API
* In composition API you can access utilities from `useVueFlow`
*/
export const updateEdge = (oldEdge: Edge, newConnection: Connection, elements: Elements) => {
if (!newConnection.source || !newConnection.target) {
console.warn("Can't create new edge. An edge needs a source and a target.")