Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core,nodes,edges): allow pointer events if mouse evt listeners exist #1618

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-rules-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---

Allow node/edge pointer events if mouse event listeners (like `nodeClick` or `edgeClick`) exists.
25 changes: 13 additions & 12 deletions packages/core/src/components/Edges/EdgeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ const EdgeWrapper = defineComponent({
elementsSelectable,
edgesUpdatable,
edgesFocusable,
hooks,
} = useVueFlow()

const edge = computed(() => findEdge(props.id)!)

const hooks = useEdgeHooks(edge.value, emits)
const { emit, on } = useEdgeHooks(edge.value, emits)

const slots = inject(Slots)

Expand Down Expand Up @@ -188,7 +189,7 @@ const EdgeWrapper = defineComponent({
updating: mouseOver.value,
selected: edge.value.selected,
animated: edge.value.animated,
inactive: !isSelectable.value,
inactive: !isSelectable.value && !hooks.value.edgeClick.hasListeners(),
},
],
'onClick': onEdgeClick,
Expand Down Expand Up @@ -226,7 +227,7 @@ const EdgeWrapper = defineComponent({
labelBgPadding: edge.value.labelBgPadding,
labelBgBorderRadius: edge.value.labelBgBorderRadius,
data: edge.value.data,
events: { ...edge.value.events, ...hooks.on },
events: { ...edge.value.events, ...on },
style: edgeStyle.value,
markerStart: `url('#${getMarkerId(edge.value.markerStart, vueFlowId)}')`,
markerEnd: `url('#${getMarkerId(edge.value.markerEnd, vueFlowId)}')`,
Expand Down Expand Up @@ -296,11 +297,11 @@ const EdgeWrapper = defineComponent({
}

function onEdgeUpdate(event: MouseTouchEvent, connection: Connection) {
hooks.emit.update({ event, edge: edge.value, connection })
emit.update({ event, edge: edge.value, connection })
}

function onEdgeUpdateEnd(event: MouseTouchEvent) {
hooks.emit.updateEnd({ event, edge: edge.value })
emit.updateEnd({ event, edge: edge.value })
updating.value = false
}

Expand All @@ -316,7 +317,7 @@ const EdgeWrapper = defineComponent({

edgeUpdaterType.value = isSourceHandle ? 'target' : 'source'

hooks.emit.updateStart({ event, edge: edge.value })
emit.updateStart({ event, edge: edge.value })

handlePointerDown(event)
}
Expand All @@ -336,27 +337,27 @@ const EdgeWrapper = defineComponent({
}
}

hooks.emit.click(data)
emit.click(data)
}

function onEdgeContextMenu(event: MouseEvent) {
hooks.emit.contextMenu({ event, edge: edge.value })
emit.contextMenu({ event, edge: edge.value })
}

function onDoubleClick(event: MouseEvent) {
hooks.emit.doubleClick({ event, edge: edge.value })
emit.doubleClick({ event, edge: edge.value })
}

function onEdgeMouseEnter(event: MouseEvent) {
hooks.emit.mouseEnter({ event, edge: edge.value })
emit.mouseEnter({ event, edge: edge.value })
}

function onEdgeMouseMove(event: MouseEvent) {
hooks.emit.mouseMove({ event, edge: edge.value })
emit.mouseMove({ event, edge: edge.value })
}

function onEdgeMouseLeave(event: MouseEvent) {
hooks.emit.mouseLeave({ event, edge: edge.value })
emit.mouseLeave({ event, edge: edge.value })
}

function onEdgeUpdaterSourceMouseDown(event: MouseEvent) {
Expand Down
18 changes: 15 additions & 3 deletions packages/core/src/components/Nodes/NodeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const NodeWrapper = defineComponent({
elementsSelectable,
nodesConnectable,
nodesFocusable,
hooks,
} = useVueFlow()

const nodeElement = ref<HTMLDivElement | null>(null)
Expand All @@ -74,6 +75,8 @@ const NodeWrapper = defineComponent({

const { node, parentNode } = useNode(props.id)

const { emit, on } = useNodeHooks(node, emits)

const isDraggable = toRef(() => (typeof node.draggable === 'undefined' ? nodesDraggable.value : node.draggable))

const isSelectable = toRef(() => (typeof node.selectable === 'undefined' ? elementsSelectable.value : node.selectable))
Expand All @@ -82,6 +85,17 @@ const NodeWrapper = defineComponent({

const isFocusable = toRef(() => (typeof node.focusable === 'undefined' ? nodesFocusable.value : node.focusable))

const hasPointerEvents = toRef(
() =>
isSelectable.value ||
isDraggable.value ||
hooks.value.nodeClick.hasListeners() ||
hooks.value.nodeDoubleClick.hasListeners() ||
hooks.value.nodeMouseEnter.hasListeners() ||
hooks.value.nodeMouseMove.hasListeners() ||
hooks.value.nodeMouseLeave.hasListeners(),
)

const isInit = toRef(() => !!node.dimensions.width && !!node.dimensions.height)

const nodeCmp = computed(() => {
Expand Down Expand Up @@ -112,8 +126,6 @@ const NodeWrapper = defineComponent({
return false
})

const { emit, on } = useNodeHooks(node, emits)

const dragging = useDrag({
id: props.id,
el: nodeElement,
Expand Down Expand Up @@ -266,7 +278,7 @@ const NodeWrapper = defineComponent({
visibility: isInit.value ? 'visible' : 'hidden',
zIndex: node.computedPosition.z ?? zIndex.value,
transform: `translate(${node.computedPosition.x}px,${node.computedPosition.y}px)`,
pointerEvents: isSelectable.value || isDraggable.value ? 'all' : 'none',
pointerEvents: hasPointerEvents.value ? 'all' : 'none',
...getStyle.value,
},
'tabIndex': isFocusable.value ? 0 : undefined,
Expand Down
Loading