diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index c059b8c70..109bfe89c 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,15 @@ # @vue-flow/core +## 1.42.4 + +### Patch Changes + +- [#1794](https://github.com/bcakmakoglu/vue-flow/pull/1794) [`e0bb46e`](https://github.com/bcakmakoglu/vue-flow/commit/e0bb46e9ee6c67737e40d154bbd8eae5cdde0cce) Thanks [@bcakmakoglu](https://github.com/bcakmakoglu)! - Use null as fallback id for edge source handle + +- [#1796](https://github.com/bcakmakoglu/vue-flow/pull/1796) [`978b896`](https://github.com/bcakmakoglu/vue-flow/commit/978b8966468737897b6b63fd1ff38d2eee7772d9) Thanks [@bcakmakoglu](https://github.com/bcakmakoglu)! - Remove edgelookup update when updating connection lookup as edge lookup is computed already + +- [#1796](https://github.com/bcakmakoglu/vue-flow/pull/1796) [`a6a3000`](https://github.com/bcakmakoglu/vue-flow/commit/a6a30008ead042f01b3dd7e82cc015cbfd4f65a2) Thanks [@bcakmakoglu](https://github.com/bcakmakoglu)! - Reset drag items on drag end + ## 1.42.3 ### Patch Changes diff --git a/packages/core/package.json b/packages/core/package.json index dd379c73a..f6b800f5b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@vue-flow/core", - "version": "1.42.3", + "version": "1.42.4", "private": false, "license": "MIT", "author": "Burak Cakmakoglu<78412429+bcakmakoglu@users.noreply.github.com>", diff --git a/packages/core/src/components/Edges/EdgeWrapper.ts b/packages/core/src/components/Edges/EdgeWrapper.ts index 95bb3960f..10d466ba7 100644 --- a/packages/core/src/components/Edges/EdgeWrapper.ts +++ b/packages/core/src/components/Edges/EdgeWrapper.ts @@ -313,7 +313,7 @@ const EdgeWrapper = defineComponent({ updating.value = true nodeId.value = isSourceHandle ? edge.value.target : edge.value.source - handleId.value = (isSourceHandle ? edge.value.targetHandle : edge.value.sourceHandle) ?? '' + handleId.value = (isSourceHandle ? edge.value.targetHandle : edge.value.sourceHandle) ?? null edgeUpdaterType.value = isSourceHandle ? 'target' : 'source' diff --git a/packages/core/src/composables/useDrag.ts b/packages/core/src/composables/useDrag.ts index 65f9fbfb3..2caf0e546 100644 --- a/packages/core/src/composables/useDrag.ts +++ b/packages/core/src/composables/useDrag.ts @@ -12,7 +12,6 @@ import { getEventPosition, handleNodeClick, hasSelector, - isUseDragEvent, snapPosition, } from '../utils' import { useGetPointerPosition, useVueFlow } from '.' @@ -226,8 +225,10 @@ export function useDrag(params: UseDragParams) { } const eventEnd = (event: UseDragEvent) => { - if (!isUseDragEvent(event) && !dragStarted && !dragging.value && !multiSelectionActive.value) { - const evt = event as MouseTouchEvent + let isClick = false + + if (!dragStarted && !dragging.value && !multiSelectionActive.value) { + const evt = event.sourceEvent as MouseTouchEvent const pointerPos = getPointerPosition(evt) @@ -238,19 +239,11 @@ export function useDrag(params: UseDragParams) { // dispatch a click event if the node was attempted to be dragged but the threshold was not exceeded if (distance !== 0 && distance <= nodeDragThreshold.value) { onClick?.(evt) + isClick = true } - - return } - dragging.value = false - autoPanStarted = false - dragStarted = false - lastPos = { x: undefined, y: undefined } - - cancelAnimationFrame(autoPanId) - - if (dragItems.length) { + if (dragItems.length && !isClick) { updateNodePositions(dragItems, false, false) const [currentNode, nodes] = getEventHandlerParams({ @@ -261,6 +254,14 @@ export function useDrag(params: UseDragParams) { onStop({ event: event.sourceEvent, node: currentNode, nodes }) } + + dragItems = [] + dragging.value = false + autoPanStarted = false + dragStarted = false + lastPos = { x: undefined, y: undefined } + + cancelAnimationFrame(autoPanId) } watch([() => toValue(disabled), el], ([isDisabled, nodeEl], _, onCleanup) => { diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index 882aac2ef..ccf853546 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -509,7 +509,13 @@ export function useActions(state: State, nodeLookup: ComputedRef, ed } const updateEdge: Actions['updateEdge'] = (oldEdge, newConnection, shouldReplaceId = true) => { - const prevEdge = findEdge(oldEdge.id)! + const prevEdge = findEdge(oldEdge.id) + + if (!prevEdge) { + return false + } + + const prevEdgeIndex = state.edges.indexOf(prevEdge) const newEdge = updateEdgeAction(oldEdge, newConnection, prevEdge, shouldReplaceId, state.hooks.error.trigger) @@ -525,7 +531,7 @@ export function useActions(state: State, nodeLookup: ComputedRef, ed state.edges, ) - state.edges.splice(state.edges.indexOf(prevEdge), 1, validEdge) + state.edges = state.edges.map((edge, index) => (index === prevEdgeIndex ? validEdge : edge)) updateConnectionLookup(state.connectionLookup, edgeLookup.value, [validEdge]) diff --git a/packages/core/src/utils/store.ts b/packages/core/src/utils/store.ts index eb8f28312..349c98dee 100644 --- a/packages/core/src/utils/store.ts +++ b/packages/core/src/utils/store.ts @@ -165,7 +165,6 @@ function addConnectionToLookup( export function updateConnectionLookup(connectionLookup: ConnectionLookup, edgeLookup: EdgeLookup, edges: GraphEdge[]) { connectionLookup.clear() - edgeLookup.clear() for (const edge of edges) { const { source: sourceNode, target: targetNode, sourceHandle = null, targetHandle = null } = edge @@ -176,8 +175,6 @@ export function updateConnectionLookup(connectionLookup: ConnectionLookup, edgeL addConnectionToLookup('source', connection, targetKey, connectionLookup, sourceNode, sourceHandle) addConnectionToLookup('target', connection, sourceKey, connectionLookup, targetNode, targetHandle) - - edgeLookup.set(edge.id, edge) } }