From bfb43cf85946ee552a3fa775a9efbb595d4d16a7 Mon Sep 17 00:00:00 2001 From: Kamil Fogel Date: Fri, 16 Jan 2026 11:21:17 +0100 Subject: [PATCH] AF-396 There is no way to stop programmatic linking action on touch device --- .../input-events/manual-linking.service.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/ng-diagram/projects/ng-diagram/src/lib/services/input-events/manual-linking.service.ts b/packages/ng-diagram/projects/ng-diagram/src/lib/services/input-events/manual-linking.service.ts index ae9f3492f..0455fed2f 100644 --- a/packages/ng-diagram/projects/ng-diagram/src/lib/services/input-events/manual-linking.service.ts +++ b/packages/ng-diagram/projects/ng-diagram/src/lib/services/input-events/manual-linking.service.ts @@ -26,12 +26,44 @@ export class ManualLinkingService { document.addEventListener('pointermove', this.onPointerMove); document.addEventListener('click', this.onDocumentClick, true); + document.addEventListener('touchmove', this.onTouchMove, { passive: false }); + document.addEventListener('touchend', this.onTouchEnd, { passive: false }); } private onPointerMove = (event: PointerEvent) => { + if (event.pointerType === 'touch') { + return; + } this.linkingEventService.emitContinue(event as PointerInputEvent); }; + private onTouchMove = (event: TouchEvent) => { + if (event.touches.length !== 1) { + return; + } + + event.preventDefault(); + const touch = event.touches[0]; + const mockEvent = { + clientX: touch.clientX, + clientY: touch.clientY, + } as PointerInputEvent; + + this.linkingEventService.emitContinue(mockEvent); + }; + + private onTouchEnd = (event: TouchEvent) => { + event.preventDefault(); + const touch = event.changedTouches[0]; + const mockEvent = { + clientX: touch.clientX, + clientY: touch.clientY, + } as PointerInputEvent; + + this.cleanup(); + this.linkingEventService.emitEnd(mockEvent, this.node, this.portId); + }; + private onDocumentClick = (event: MouseEvent) => { this.cleanup(); this.linkingEventService.emitEnd(event as PointerInputEvent, this.node, this.portId); @@ -40,5 +72,7 @@ export class ManualLinkingService { private cleanup() { document.removeEventListener('pointermove', this.onPointerMove); document.removeEventListener('click', this.onDocumentClick, true); + document.removeEventListener('touchmove', this.onTouchMove); + document.removeEventListener('touchend', this.onTouchEnd); } }