feat(snapping): lanes only snap to themselves

This commit is contained in:
Philipp Fromme 2020-03-31 12:02:23 +02:00 committed by Philipp
parent 573ddd4921
commit 621df3a730
2 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,55 @@
import inherits from 'inherits';
import ResizeSnapping from 'diagram-js/lib/features/snapping/ResizeSnapping';
import { is } from '../../util/ModelUtil';
import {
bottomLeft,
bottomRight,
topLeft,
topRight
} from 'diagram-js/lib/features/snapping/SnapUtil';
export default function BpmnResizeSnapping(injector) {
injector.invoke(ResizeSnapping, this);
}
inherits(BpmnResizeSnapping, ResizeSnapping);
BpmnResizeSnapping.$inject = [ 'injector' ];
BpmnResizeSnapping.prototype.addSnapTargetPoints = function(snapPoints, shape, target, direction) {
if (is(shape, 'bpmn:Lane')) {
return addLaneSnapPoints(shape, direction, snapPoints);
}
return ResizeSnapping.prototype.addSnapTargetPoints.call(this, snapPoints, shape, target, direction);
};
// helpers //////////
/**
* Add snap points when resizing lane. Lanes only snap to themselves.
*
* @param {djs.model.shape} lane
* @param {string} direction
* @param {Object} snapPoints
*
* @returns {Object}
*/
function addLaneSnapPoints(lane, direction, snapPoints) {
if (direction === 'nw' || direction === 'n' || direction === 'w') {
snapPoints.add('corner', topLeft(lane));
} else if (direction === 'se' || direction === 's' || direction === 'e') {
snapPoints.add('corner', bottomRight(lane));
} else if (direction === 'ne') {
snapPoints.add('corner', topRight(lane));
} else if (direction === 'sw') {
snapPoints.add('corner', bottomLeft(lane));
}
return snapPoints;
}

View File

@ -1,5 +1,6 @@
import BpmnConnectSnapping from './BpmnConnectSnapping';
import BpmnCreateMoveSnapping from './BpmnCreateMoveSnapping';
import BpmnResizeSnapping from './BpmnResizeSnapping';
import SnappingModule from 'diagram-js/lib/features/snapping';
export default {
@ -9,5 +10,6 @@ export default {
'createMoveSnapping'
],
connectSnapping: [ 'type', BpmnConnectSnapping ],
createMoveSnapping: [ 'type', BpmnCreateMoveSnapping ]
createMoveSnapping: [ 'type', BpmnCreateMoveSnapping ],
resizeSnapping: [ 'type', BpmnResizeSnapping ]
};