Skip to content

Commit

Permalink
feat(modeling): allow label and group movement everywhere, round two
Browse files Browse the repository at this point in the history
This partially reverts 0c0932d.

Closes #1076
  • Loading branch information
nikku committed Jun 14, 2019
1 parent 9497ac0 commit 91e461b
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 100 deletions.
24 changes: 19 additions & 5 deletions lib/features/modeling/behavior/FixHoverBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { isAny } from '../util/ModelingUtil';
var HIGH_PRIORITY = 1500;

/**
* Ensure we correct hover targets to improve diagram interaction
* during create and move.
* Correct hover targets in certain situations to improve diagram interaction.
*
* @param {ElementRegistry} elementRegistry
* @param {EventBus} eventBus
* @param {Canvas} canvas
*/
export default function FixHoverBehavior(elementRegistry, eventBus) {
export default function FixHoverBehavior(elementRegistry, eventBus, canvas) {

eventBus.on([
'create.hover',
'create.move',
Expand All @@ -23,17 +24,30 @@ export default function FixHoverBehavior(elementRegistry, eventBus) {
'shape.move.end'
], HIGH_PRIORITY, function(event) {
var context = event.context,
shape = context.shape,
shape = context.shape || event.shape,
hover = event.hover;

// ensure elements are not dropped onto a bpmn:Lane but onto
// the underlying bpmn:Participant
if (is(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
event.hover = getLanesRoot(hover);
event.hoverGfx = elementRegistry.getGraphics(event.hover);
}

var rootElement = canvas.getRootElement();

// ensure bpmn:Group and label elements are dropped
// always onto the root
if (hover !== rootElement && (shape.labelTarget || is(shape, 'bpmn:Group'))) {
event.hover = rootElement;
event.hoverGfx = elementRegistry.getGraphics(event.hover);
}
});

}

FixHoverBehavior.$inject = [
'elementRegistry',
'eventBus'
'eventBus',
'canvas'
];
52 changes: 13 additions & 39 deletions lib/features/rules/BpmnRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,10 @@ BpmnRules.prototype.init = function() {
shapes = context.shapes,
position = context.position;

var attach = canAttach(shapes, target, null, position);

if (attach || attach === null) {
return attach;
}

var replace = canReplace(shapes, target, position);

if (replace || replace === null) {
return replace;
}

var move = canMove(shapes, target, position);

if (move || move === null) {
return move;
}

return canInsert(shapes, target, position);
return canAttach(shapes, target, null, position) ||
canReplace(shapes, target, position) ||
canMove(shapes, target, position) ||
canInsert(shapes, target, position);
});

this.addRule('shape.create', function(context) {
Expand Down Expand Up @@ -464,11 +449,12 @@ function canConnect(source, target, connection) {
*/
function canDrop(element, target, position) {

// can move labels everywhere
if (isLabel(element)) {
return null;
// can move labels and groups everywhere
if (isLabel(element) || isGroup(element)) {
return true;
}


// disallow to create elements on collapsed pools
if (is(target, 'bpmn:Participant') && !isExpanded(target)) {
return false;
Expand Down Expand Up @@ -766,21 +752,9 @@ function canMove(elements, target) {
return true;
}

var move,
currentMove;

for (var i = 0; i < elements.length; i++) {

currentMove = canDrop(elements[i], target);

if (currentMove === false) {
return false;
}

move = move || currentMove;
}

return move;
return elements.every(function(element) {
return canDrop(element, target);
});
}

function canCreate(shape, target, source, position) {
Expand All @@ -789,8 +763,8 @@ function canCreate(shape, target, source, position) {
return false;
}

if (isLabel(target)) {
return null;
if (isLabel(target) || isGroup(target)) {
return true;
}

if (isSame(source, target)) {
Expand Down
20 changes: 20 additions & 0 deletions test/spec/features/modeling/behavior/FixHoverBehavior.group.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="4.0.0-beta.1">
<process id="Process">
<task id="Task" />
<group id="Group" categoryValueRef="CategoryValue_1heb3m9" />
</process>
<category id="Category_1g60m2v">
<categoryValue id="CategoryValue_1heb3m9" />
</category>
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Process">
<bpmndi:BPMNShape id="Task_di" bpmnElement="Task">
<omgdc:Bounds x="264" y="81" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Group_di" bpmnElement="Group">
<omgdc:Bounds x="185" y="200" width="150" height="120" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
20 changes: 20 additions & 0 deletions test/spec/features/modeling/behavior/FixHoverBehavior.label.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="4.0.0-beta.1">
<process id="Process">
<startEvent id="StartEvent" name="A" />
<task id="Task" />
</process>
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Process">
<bpmndi:BPMNShape id="StartEvent_di" bpmnElement="StartEvent">
<omgdc:Bounds x="156" y="103" width="36" height="36" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="171" y="146" width="7" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_di" bpmnElement="Task">
<omgdc:Bounds x="264" y="81" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
Loading

0 comments on commit 91e461b

Please sign in to comment.