all files / diagram-js/lib/features/create/ CreateConnectPreview.js

100% Statements 17/17
100% Branches 8/8
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                   156×   156× 41× 41× 41× 41× 41×     41× 38×                         156× 18×                  
var LOW_PRIORITY = 740;
 
 
/**
 * Shows connection preview during create.
 *
 * @param {EventBus} eventBus
 * @param {ConnectionPreview} connectionPreview
 */
export default function CreateConnectPreview(injector, eventBus) {
  var connectionPreview = injector.get('connectionPreview', false);
 
  eventBus.on('create.move', LOW_PRIORITY, function(event) {
    var context = event.context,
        source = context.source,
        shape = context.shape,
        canExecute = context.canExecute,
        canConnect = canExecute && canExecute.connect;
 
    // don't draw connection preview if not appending a shape
    if (!connectionPreview || !source) {
      return;
    }
 
    // place shape's center on cursor
    shape.x = Math.round(event.x - shape.width / 2);
    shape.y = Math.round(event.y - shape.height / 2);
 
    connectionPreview.drawPreview(context, canConnect, {
      source: source,
      target: shape,
      waypoints: [],
      noNoop: true
    });
  });
 
 
  eventBus.on('create.cleanup', function(event) {
    if (connectionPreview) {
      connectionPreview.cleanUp(event.context);
    }
  });
 
}
 
CreateConnectPreview.$inject = [
  'injector',
  'eventBus'
];