From 7e55f8c07fb637e383f82610a548bcc402f446e5 Mon Sep 17 00:00:00 2001 From: moklick Date: Thu, 5 Nov 2020 14:36:26 +0100 Subject: [PATCH] fix(nodes): always drag draggable node even if not selected --- src/components/Nodes/wrapNode.tsx | 2 ++ src/store/index.ts | 4 ++-- src/types/index.ts | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Nodes/wrapNode.tsx b/src/components/Nodes/wrapNode.tsx index 2b01850b..11f9dda1 100644 --- a/src/components/Nodes/wrapNode.tsx +++ b/src/components/Nodes/wrapNode.tsx @@ -124,6 +124,7 @@ export default (NodeComponent: ComponentType) => { const onDrag = useCallback( (_, data) => { updateNodePosDiff({ + id, diff: { x: data.deltaX, y: data.deltaY, @@ -148,6 +149,7 @@ export default (NodeComponent: ComponentType) => { } updateNodePosDiff({ + id: node.id, isDragging: false, }); diff --git a/src/store/index.ts b/src/store/index.ts index e9a93bd9..36417d4f 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -263,9 +263,9 @@ export const storeModel: StoreModel = { }); }), - updateNodePosDiff: action((state, { diff = null, isDragging = true }) => { + updateNodePosDiff: action((state, { id = null, diff = null, isDragging = true }) => { state.elements.forEach((n) => { - if (isNode(n) && state.selectedElements?.find((sNode) => sNode.id === n.id)) { + if (isNode(n) && (id === n.id || state.selectedElements?.find((sNode) => sNode.id === n.id))) { if (diff) { n.__rf.position = { x: n.__rf.position.x + diff.x, diff --git a/src/types/index.ts b/src/types/index.ts index 12ae1d54..583d9391 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -308,6 +308,7 @@ export type NodePosUpdate = { }; export type NodeDiffUpdate = { + id?: ElementId; diff?: XYPosition; isDragging?: boolean; };