feat(core): add option to avoid replacing edge id when updating
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -426,7 +426,8 @@ export function useActions(state: State, getters: ComputedGetters): Actions {
|
|||||||
state.hooks.edgesChange.trigger(changes)
|
state.hooks.edgesChange.trigger(changes)
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateEdge: Actions['updateEdge'] = (oldEdge, newConnection) => updateEdgeAction(oldEdge, newConnection, state.edges)
|
const updateEdge: Actions['updateEdge'] = (oldEdge, newConnection, shouldReplaceId = true) =>
|
||||||
|
updateEdgeAction(oldEdge, newConnection, state.edges, shouldReplaceId)
|
||||||
|
|
||||||
const applyNodeChanges: Actions['applyNodeChanges'] = (changes) => applyChanges(changes, state.nodes)
|
const applyNodeChanges: Actions['applyNodeChanges'] = (changes) => applyChanges(changes, state.nodes)
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ export type RemoveEdges = (edges: (Edge[] | string[]) | ((edges: GraphEdge[]) =>
|
|||||||
|
|
||||||
export type AddEdges = (edgesOrConnections: (Edge | Connection)[] | ((edges: GraphEdge[]) => (Edge | Connection)[])) => void
|
export type AddEdges = (edgesOrConnections: (Edge | Connection)[] | ((edges: GraphEdge[]) => (Edge | Connection)[])) => void
|
||||||
|
|
||||||
export type UpdateEdge = (oldEdge: GraphEdge, newConnection: Connection) => GraphEdge | false
|
export type UpdateEdge = (oldEdge: GraphEdge, newConnection: Connection, shouldReplaceId: boolean) => GraphEdge | false
|
||||||
|
|
||||||
export type SetState = (
|
export type SetState = (
|
||||||
state:
|
state:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export function addEdgeToStore(edgeParams: Edge | Connection, edges: Edge[]) {
|
|||||||
return edge
|
return edge
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateEdgeAction(edge: GraphEdge, newConnection: Connection, edges: GraphEdge[]) {
|
export function updateEdgeAction(edge: GraphEdge, newConnection: Connection, edges: GraphEdge[], shouldReplaceId: boolean) {
|
||||||
if (!newConnection.source || !newConnection.target) {
|
if (!newConnection.source || !newConnection.target) {
|
||||||
warn("Can't create new edge. An edge needs a source and a target.")
|
warn("Can't create new edge. An edge needs a source and a target.")
|
||||||
return false
|
return false
|
||||||
@@ -35,9 +35,11 @@ export function updateEdgeAction(edge: GraphEdge, newConnection: Connection, edg
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { id, ...rest } = edge
|
||||||
|
|
||||||
const newEdge = {
|
const newEdge = {
|
||||||
...edge,
|
...rest,
|
||||||
id: getEdgeId(newConnection),
|
id: shouldReplaceId ? getEdgeId(newConnection) : id,
|
||||||
source: newConnection.source,
|
source: newConnection.source,
|
||||||
target: newConnection.target,
|
target: newConnection.target,
|
||||||
sourceHandle: newConnection.sourceHandle,
|
sourceHandle: newConnection.sourceHandle,
|
||||||
|
|||||||
Reference in New Issue
Block a user