From e74a20d923c3b4a5bf70b8bf7da264918b4612a6 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 25 Jan 2023 19:30:23 +0100 Subject: [PATCH] feat(core): implement connection radius Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- packages/core/src/auto-imports.d.ts | 12 +- .../core/src/components/Edges/EdgeWrapper.ts | 10 +- .../core/src/components/Handle/Handle.vue | 9 +- packages/core/src/composables/useHandle.ts | 455 ++++++------------ packages/core/src/store/state.ts | 1 + packages/core/src/types/handle.ts | 8 + packages/core/src/types/store.ts | 1 + packages/core/src/utils/graph.ts | 6 + packages/core/src/utils/handle.ts | 163 +++++++ 9 files changed, 344 insertions(+), 321 deletions(-) create mode 100644 packages/core/src/utils/handle.ts diff --git a/packages/core/src/auto-imports.d.ts b/packages/core/src/auto-imports.d.ts index 28db556c..f8c013b5 100644 --- a/packages/core/src/auto-imports.d.ts +++ b/packages/core/src/auto-imports.d.ts @@ -29,7 +29,7 @@ declare global { const autoResetRef: typeof import('@vueuse/core')['autoResetRef'] const boxToRect: typeof import('./utils/graph')['boxToRect'] const calcNextPosition: typeof import('./utils/drag')['calcNextPosition'] - const checkElementBelowIsValid: typeof import('./composables/useHandle')['checkElementBelowIsValid'] + const checkElementBelowIsValid: typeof import('./composables/useHandleDepr')['checkElementBelowIsValid'] const clamp: typeof import('./utils/graph')['clamp'] const clampPosition: typeof import('./utils/graph')['clampPosition'] const computed: typeof import('vue')['computed'] @@ -66,6 +66,7 @@ declare global { const getBezierEdgeCenter: typeof import('./components/Edges/utils/general')['getBezierEdgeCenter'] const getBezierPath: typeof import('./components/Edges/utils/bezier')['getBezierPath'] const getBoundsofRects: typeof import('./utils/graph')['getBoundsofRects'] + const getClosestHandle: typeof import('./utils/handle')['getClosestHandle'] const getConnectedEdges: typeof import('./utils/graph')['getConnectedEdges'] const getCurrentInstance: typeof import('vue')['getCurrentInstance'] const getCurrentScope: typeof import('vue')['getCurrentScope'] @@ -74,10 +75,14 @@ declare global { const getEdgeId: typeof import('./utils/graph')['getEdgeId'] const getEdgePositions: typeof import('./utils/edge')['getEdgePositions'] const getEventHandlerParams: typeof import('./utils/drag')['getEventHandlerParams'] + const getEventPosition: typeof import('./utils/handle')['getEventPosition'] const getExtent: typeof import('./utils/drag')['getExtent'] const getHandle: typeof import('./utils/edge')['getHandle'] const getHandleBounds: typeof import('./utils/node')['getHandleBounds'] + const getHandleLookup: typeof import('./utils/handle')['getHandleLookup'] const getHandlePosition: typeof import('./utils/edge')['getHandlePosition'] + const getHandleType: typeof import('./utils/handle')['getHandleType'] + const getHandles: typeof import('./utils/handle')['getHandles'] const getHostForElement: typeof import('./utils/graph')['getHostForElement'] const getIncomers: typeof import('./utils/graph')['getIncomers'] const getMarkerId: typeof import('./utils/graph')['getMarkerId'] @@ -106,6 +111,7 @@ declare global { const isGraphEdge: typeof import('./utils/graph')['isGraphEdge'] const isGraphNode: typeof import('./utils/graph')['isGraphNode'] const isInputDOMNode: typeof import('./composables/useKeyPress')['isInputDOMNode'] + const isMouseEvent: typeof import('./utils/handle')['isMouseEvent'] const isNode: typeof import('./utils/graph')['isNode'] const isParentSelected: typeof import('./utils/graph')['isParentSelected'] const isProxy: typeof import('vue')['isProxy'] @@ -113,6 +119,7 @@ declare global { const isReadonly: typeof import('vue')['isReadonly'] const isRect: typeof import('./utils/graph')['isRect'] const isRef: typeof import('vue')['isRef'] + const isValidHandle: typeof import('./utils/handle')['isValidHandle'] const makeDestructurable: typeof import('@vueuse/core')['makeDestructurable'] const markRaw: typeof import('vue')['markRaw'] const nextTick: typeof import('vue')['nextTick'] @@ -153,6 +160,8 @@ declare global { const refDefault: typeof import('@vueuse/core')['refDefault'] const refThrottled: typeof import('@vueuse/core')['refThrottled'] const refWithControl: typeof import('@vueuse/core')['refWithControl'] + const rendererPointToPoint: typeof import('./utils/graph')['rendererPointToPoint'] + const resetRecentHandle: typeof import('./utils/handle')['resetRecentHandle'] const resolveComponent: typeof import('vue')['resolveComponent'] const resolveDirective: typeof import('vue')['resolveDirective'] const resolveRef: typeof import('@vueuse/core')['resolveRef'] @@ -249,6 +258,7 @@ declare global { const useGetPointerPosition: typeof import('./composables/useGetPointerPosition')['useGetPointerPosition'] const useGetters: typeof import('./store/getters')['useGetters'] const useHandle: typeof import('./composables/useHandle')['default'] + const useHandleDepr: typeof import('./composables/useHandleDepr')['default'] const useHooks: typeof import('./store/hooks')['useHooks'] const useIdle: typeof import('@vueuse/core')['useIdle'] const useImage: typeof import('@vueuse/core')['useImage'] diff --git a/packages/core/src/components/Edges/EdgeWrapper.ts b/packages/core/src/components/Edges/EdgeWrapper.ts index 45ec4468..1ee0d9bc 100644 --- a/packages/core/src/components/Edges/EdgeWrapper.ts +++ b/packages/core/src/components/Edges/EdgeWrapper.ts @@ -43,7 +43,7 @@ const EdgeWrapper = defineComponent({ const type = ref('source') - const elementEdgeUpdaterType = ref('source') + const edgeUpdaterType = ref('source') const mouseEvent = ref() @@ -70,12 +70,12 @@ const EdgeWrapper = defineComponent({ updating = false } - const { onMouseDown } = useHandle({ + const { handlePointerDown } = useHandle({ nodeId, handleId, type, isValidConnection: undefined, - elementEdgeUpdaterType, + edgeUpdaterType, onEdgeUpdate, onEdgeUpdateEnd, }) @@ -84,12 +84,12 @@ const EdgeWrapper = defineComponent({ nodeId.value = isSourceHandle ? edge.target : edge.source handleId.value = (isSourceHandle ? edge.targetHandle : edge.sourceHandle) ?? '' type.value = isSourceHandle ? 'target' : 'source' - elementEdgeUpdaterType.value = type.value + edgeUpdaterType.value = type.value mouseEvent.value = event hooks.emit.updateStart({ event, edge }) - onMouseDown(event) + handlePointerDown(event) } const onEdgeClick = (event: MouseEvent) => { diff --git a/packages/core/src/components/Handle/Handle.vue b/packages/core/src/components/Handle/Handle.vue index bd1f8b8a..8e418494 100644 --- a/packages/core/src/components/Handle/Handle.vue +++ b/packages/core/src/components/Handle/Handle.vue @@ -15,7 +15,7 @@ const handle = ref() const handleId = $computed(() => id ?? `${nodeId}__handle-${position}`) -const { onMouseDown, onTouchStart, onClick } = useHandle({ +const { handlePointerDown, handleClick } = useHandle({ nodeId, handleId, isValidConnection, @@ -80,6 +80,7 @@ export default {