From 0b136b225efa1f304adf73fda09c3cd68e563628 Mon Sep 17 00:00:00 2001 From: Adam Thometz Date: Mon, 7 Oct 2024 07:20:03 -0400 Subject: [PATCH 1/3] changed target check in canMove to check for undefined to allow prevention of moving beyond border --- lib/features/rules/BpmnRules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index 42979c92c9..dcd51685af 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -928,7 +928,7 @@ function canMove(elements, target) { } // allow default move check to start move operation - if (!target) { + if (target === undefined) { return true; } From 925bcc7076f344fb9bcb51772370e6a7e36f1638 Mon Sep 17 00:00:00 2001 From: Adam Thometz Date: Mon, 7 Oct 2024 07:20:03 -0400 Subject: [PATCH 2/3] fix(feature/snapping): changed target check in canMove to check for undefined to prevent element from moving beyond border --- lib/features/rules/BpmnRules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index 42979c92c9..dcd51685af 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -928,7 +928,7 @@ function canMove(elements, target) { } // allow default move check to start move operation - if (!target) { + if (target === undefined) { return true; } From f416dcde8a4006e5248e00c848add3a1a8c5a9f2 Mon Sep 17 00:00:00 2001 From: Adam Thometz Date: Tue, 8 Oct 2024 15:24:26 -0400 Subject: [PATCH 3/3] fix(feature/snapping) added test --- .../snapping/BpmnCreateMoveSnappingSpec.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/spec/features/snapping/BpmnCreateMoveSnappingSpec.js b/test/spec/features/snapping/BpmnCreateMoveSnappingSpec.js index 900e3bfdbc..375c264bee 100644 --- a/test/spec/features/snapping/BpmnCreateMoveSnappingSpec.js +++ b/test/spec/features/snapping/BpmnCreateMoveSnappingSpec.js @@ -715,6 +715,38 @@ describe('features/snapping - BpmnCreateMoveSnapping', function() { }); + describe('dragging elements', function() { + var diagramXML = require('./BpmnCreateMoveSnapping.process.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { + modules: testModules + })); + + it('should limit movement when attempting to drag outside the viewport', inject(function(elementRegistry, move, dragging, canvas) { + + var task = elementRegistry.get('Task_1'); + var viewbox = canvas.viewbox(); + var initialX = task.x; + var initialY = task.y; + + // when + move.start(canvasEvent({ x: task.x + task.width / 2, y: task.y + task.height / 2 }), task); + + // Attempt to move far outside the viewport + var farAwayX = viewbox.x + viewbox.width * 2; + var farAwayY = viewbox.y + viewbox.height * 2; + dragging.move(canvasEvent({ x: farAwayX, y: farAwayY })); + + dragging.end(); + + // then + expect(task.x).to.be.above(initialX, 'Task should have moved right'); + expect(task.y).to.be.above(initialY, 'Task should have moved down'); + expect(task.x).to.be.below(farAwayX, 'Task should not have moved as far right as attempted'); + expect(task.y).to.be.below(farAwayY, 'Task should not have moved as far down as attempted'); + })); + }); + }); // helpers //////////