all files / Github/bpmn-js/lib/features/modeling/behavior/ ResizeLaneBehavior.js

100% Statements 17/17
90% Branches 9/10
100% Functions 3/3
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                                      1128× 10× 10×   10×                   1128× 10× 10× 10× 10×   10×                                
import { is } from '../../../util/ModelUtil';
 
import {
  roundBounds
} from 'diagram-js/lib/layout/LayoutUtil';
 
import {
  hasPrimaryModifier
} from 'diagram-js/lib/util/Mouse';
 
var SLIGHTLY_HIGHER_PRIORITY = 1001;
 
 
/**
 * Invoke {@link Modeling#resizeLane} instead of
 * {@link Modeling#resizeShape} when resizing a Lane
 * or Participant shape.
 */
export default function ResizeLaneBehavior(eventBus, modeling) {
 
  eventBus.on('resize.start', SLIGHTLY_HIGHER_PRIORITY + 500, function(event) {
    var context = event.context,
        shape = context.shape;
 
    if (is(shape, 'bpmn:Lane') || is(shape, 'bpmn:Participant')) {
 
      // should we resize the opposite lane(s) in
      // order to compensate for the resize operation?
      context.balanced = !hasPrimaryModifier(event);
    }
  });
 
  /**
   * Intercept resize end and call resize lane function instead.
   */
  eventBus.on('resize.end', SLIGHTLY_HIGHER_PRIORITY, function(event) {
    var context = event.context,
        shape = context.shape,
        canExecute = context.canExecute,
        newBounds = context.newBounds;
 
    if (is(shape, 'bpmn:Lane') || is(shape, 'bpmn:Participant')) {
 
      Eif (canExecute) {
        // ensure we have actual pixel values for new bounds
        // (important when zoom level was > 1 during move)
        newBounds = roundBounds(newBounds);
 
        // perform the actual resize
        modeling.resizeLane(shape, newBounds, context.balanced);
      }
 
      // stop propagation
      return false;
    }
  });
}
 
ResizeLaneBehavior.$inject = [
  'eventBus',
  'modeling'
];