Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1076 group movement everywhere #1080

Merged
merged 3 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions lib/features/modeling/behavior/CreateBehavior.js

This file was deleted.

99 changes: 99 additions & 0 deletions lib/features/modeling/behavior/FixHoverBehavior.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { getLanesRoot } from '../util/LaneUtil';

import { is } from '../../../util/ModelUtil';

import { isAny } from '../util/ModelingUtil';

var HIGH_PRIORITY = 1500;

/**
* 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, canvas) {

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 || 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);
}
});


eventBus.on([
'connect.hover',
'global-connect.hover'
], HIGH_PRIORITY, function(event) {
var hover = event.hover;

// ensure connections start/end on bpmn:Participant,
// not the underlying bpmn:Lane
if (is(hover, 'bpmn:Lane')) {
event.hover = getLanesRoot(hover) || hover;
event.hoverGfx = elementRegistry.getGraphics(event.hover);
}
});


eventBus.on([
'bendpoint.move.hover'
], HIGH_PRIORITY, function(event) {
var context = event.context,
type = context.type,
hover = event.hover;

// ensure reconnect start/end on bpmn:Participant,
// not the underlying bpmn:Lane
if (is(hover, 'bpmn:Lane') && /reconnect/.test(type)) {
event.hover = getLanesRoot(hover) || hover;
event.hoverGfx = elementRegistry.getGraphics(event.hover);
}
});


eventBus.on([
'connect.start'
], HIGH_PRIORITY, function(event) {

var context = event.context,
source = context.source;

// ensure connect start on bpmn:Participant,
// not the underlying bpmn:Lane
if (is(source, 'bpmn:Lane')) {
context.source = getLanesRoot(source) || source;
}
});

}

FixHoverBehavior.$inject = [
'elementRegistry',
'eventBus',
'canvas'
];
6 changes: 3 additions & 3 deletions lib/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AppendBehavior from './AppendBehavior';
import AttachEventBehavior from './AttachEventBehavior';
import BoundaryEventBehavior from './BoundaryEventBehavior';
import CopyPasteBehavior from './CopyPasteBehavior';
import CreateBehavior from './CreateBehavior';
import FixHoverBehavior from './FixHoverBehavior';
import CreateBoundaryEventBehavior from './CreateBoundaryEventBehavior';
import CreateDataObjectBehavior from './CreateDataObjectBehavior';
import CreateParticipantBehavior from './CreateParticipantBehavior';
Expand Down Expand Up @@ -37,7 +37,7 @@ export default {
'attachEventBehavior',
'boundaryEventBehavior',
'copyPasteBehavior',
'createBehavior',
'fixHoverBehavior',
'createBoundaryEventBehavior',
'createDataObjectBehavior',
'createParticipantBehavior',
Expand Down Expand Up @@ -69,7 +69,7 @@ export default {
attachEventBehavior: [ 'type', AttachEventBehavior ],
boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
copyPasteBehavior: [ 'type', CopyPasteBehavior ],
createBehavior: [ 'type', CreateBehavior ],
fixHoverBehavior: [ 'type', FixHoverBehavior ],
createBoundaryEventBehavior: [ 'type', CreateBoundaryEventBehavior ],
createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ],
createParticipantBehavior: [ 'type', CreateParticipantBehavior ],
Expand Down
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
93 changes: 0 additions & 93 deletions test/spec/features/modeling/behavior/CreateBehaviorSpec.js

This file was deleted.

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