-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(bpmn-snapping): move create behavior to seperate behavior
- Loading branch information
1 parent
20672f6
commit 3f42925
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { getLanesRoot } from '../util/LaneUtil'; | ||
|
||
import { is } from '../../../util/ModelUtil'; | ||
|
||
import { isAny } from '../util/ModelingUtil'; | ||
|
||
var HIGH_PRIORITY = 1500; | ||
|
||
/** | ||
* Ensure hovering participant during create and move. | ||
* | ||
* @param {ElementRegistry} elementRegistry | ||
* @param {EventBus} eventBus | ||
*/ | ||
export default function CreateBehavior(elementRegistry, eventBus) { | ||
eventBus.on([ | ||
'create.hover', | ||
'create.move', | ||
'create.end', | ||
'shape.move.hover', | ||
'shape.move.move', | ||
'shape.move.end' | ||
], HIGH_PRIORITY, function(event) { | ||
var context = event.context, | ||
shape = context.shape, | ||
hover = event.hover; | ||
|
||
if (is(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) { | ||
event.hover = getLanesRoot(hover); | ||
event.hoverGfx = elementRegistry.getGraphics(event.hover); | ||
} | ||
}); | ||
} | ||
|
||
CreateBehavior.$inject = [ | ||
'elementRegistry', | ||
'eventBus' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/spec/features/modeling/behavior/CreateBehavior.participant.bpmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_033nbwh" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.1.0"> | ||
<bpmn:collaboration id="Collaboration_1hb173f"> | ||
<bpmn:participant id="Participant_1" processRef="Process_1" /> | ||
</bpmn:collaboration> | ||
<bpmn:process id="Process_1" isExecutable="true"> | ||
<bpmn:laneSet id="LaneSet_01fnrsu"> | ||
<bpmn:lane id="Lane_1"> | ||
<bpmn:flowNodeRef>Task_1</bpmn:flowNodeRef> | ||
</bpmn:lane> | ||
<bpmn:lane id="Lane_2" /> | ||
</bpmn:laneSet> | ||
<bpmn:task id="Task_1" /> | ||
</bpmn:process> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1hb173f"> | ||
<bpmndi:BPMNShape id="Participant_00m5vpq_di" bpmnElement="Participant_1" isHorizontal="true"> | ||
<dc:Bounds x="100" y="100" width="600" height="370" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Lane_0wx2ruq_di" bpmnElement="Lane_1" isHorizontal="true"> | ||
<dc:Bounds x="130" y="100" width="570" height="250" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Lane_1guzz8c_di" bpmnElement="Lane_2" isHorizontal="true"> | ||
<dc:Bounds x="130" y="350" width="570" height="120" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Task_1dr11gk_di" bpmnElement="Task_1"> | ||
<dc:Bounds x="400" y="200" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |
93 changes: 93 additions & 0 deletions
93
test/spec/features/modeling/behavior/CreateBehaviorSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { | ||
bootstrapModeler, | ||
inject | ||
} from 'test/TestHelper'; | ||
|
||
import coreModule from 'lib/core'; | ||
import createModule from 'diagram-js/lib/features/create'; | ||
import modelingModule from 'lib/features/modeling'; | ||
import moveModule from 'diagram-js/lib/features/move'; | ||
|
||
import { createCanvasEvent as canvasEvent } from '../../../../util/MockEvents'; | ||
|
||
|
||
describe('features/modeling/behavior - create', function() { | ||
|
||
var testModules = [ | ||
coreModule, | ||
createModule, | ||
moveModule, | ||
modelingModule | ||
]; | ||
|
||
var diagramXML = require('./CreateBehavior.participant.bpmn'); | ||
|
||
beforeEach(bootstrapModeler(diagramXML, { | ||
modules: testModules | ||
})); | ||
|
||
beforeEach(inject(function(dragging) { | ||
dragging.setOptions({ manual: true }); | ||
})); | ||
|
||
var lane, | ||
laneGfx, | ||
participant; | ||
|
||
beforeEach(inject(function(elementRegistry) { | ||
participant = elementRegistry.get('Participant_1'); | ||
|
||
lane = elementRegistry.get('Lane_1'); | ||
laneGfx = elementRegistry.getGraphics(lane); | ||
})); | ||
|
||
describe('create', function() { | ||
|
||
it('should ensure hovering participant', inject( | ||
function(create, dragging, elementFactory) { | ||
|
||
// given | ||
var task = elementFactory.createShape({ type: 'bpmn:Task' }); | ||
|
||
create.start(canvasEvent({ x: 0, y: 0 }), task, true); | ||
|
||
// when | ||
dragging.hover({ element: lane, gfx: laneGfx }); | ||
|
||
dragging.move(canvasEvent({ x: 200, y: 200 })); | ||
|
||
dragging.end(); | ||
|
||
// then | ||
expect(task.parent).to.equal(participant); | ||
} | ||
)); | ||
|
||
}); | ||
|
||
|
||
describe('move', function() { | ||
|
||
it('should ensure hovering participant', inject( | ||
function(dragging, elementRegistry, move) { | ||
|
||
// given | ||
var task = elementRegistry.get('Task_1'); | ||
|
||
move.start(canvasEvent({ x: 440, y: 220 }), task, true); | ||
|
||
// when | ||
dragging.hover({ element: lane, gfx: laneGfx }); | ||
|
||
dragging.move(canvasEvent({ x: 240, y: 220 })); | ||
|
||
dragging.end(); | ||
|
||
// then | ||
expect(task.parent).to.equal(participant); | ||
} | ||
)); | ||
|
||
}); | ||
|
||
}); |