chore(bpmn-snapping): move create behavior to seperate behavior
This commit is contained in:
parent
d42d5e3448
commit
a4e160c48b
|
@ -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'
|
||||
];
|
|
@ -3,6 +3,7 @@ import AppendBehavior from './AppendBehavior';
|
|||
import AttachEventBehavior from './AttachEventBehavior';
|
||||
import BoundaryEventBehavior from './BoundaryEventBehavior';
|
||||
import CopyPasteBehavior from './CopyPasteBehavior';
|
||||
import CreateBehavior from './CreateBehavior';
|
||||
import CreateBoundaryEventBehavior from './CreateBoundaryEventBehavior';
|
||||
import CreateDataObjectBehavior from './CreateDataObjectBehavior';
|
||||
import CreateParticipantBehavior from './CreateParticipantBehavior';
|
||||
|
@ -36,6 +37,7 @@ export default {
|
|||
'attachEventBehavior',
|
||||
'boundaryEventBehavior',
|
||||
'copyPasteBehavior',
|
||||
'createBehavior',
|
||||
'createBoundaryEventBehavior',
|
||||
'createDataObjectBehavior',
|
||||
'createParticipantBehavior',
|
||||
|
@ -67,6 +69,7 @@ export default {
|
|||
attachEventBehavior: [ 'type', AttachEventBehavior ],
|
||||
boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
|
||||
copyPasteBehavior: [ 'type', CopyPasteBehavior ],
|
||||
createBehavior: [ 'type', CreateBehavior ],
|
||||
createBoundaryEventBehavior: [ 'type', CreateBoundaryEventBehavior ],
|
||||
createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ],
|
||||
createParticipantBehavior: [ 'type', CreateParticipantBehavior ],
|
||||
|
|
|
@ -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>
|
|
@ -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);
|
||||
}
|
||||
));
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue