all files / Github/bpmn-js/lib/features/connect/ BpmnConnectPreview.js

100% Statements 11/11
100% Branches 6/6
100% Functions 2/2
100% Lines 11/11
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 64 65 66 67                                            61×                 61×                                                    
import inherits from 'inherits';
 
import ConnectPreview from 'diagram-js/lib/features/connect/ConnectPreview';
 
/**
 * Shows connection preview during connect.
 *
 * @param {Canvas} canvas
 * @param {BpmnRules} bpmnRules
 * @param {ElementFactory} elementFactory
 * @param {EventBus} eventBus
 * @param {GraphicsFactory} graphicsFactory
 * @param {didi.Injector} injector
 */
export default function BpmnConnectPreview(
    bpmnRules,
    canvas,
    elementFactory,
    eventBus,
    graphicsFactory,
    injector
) {
  ConnectPreview.call(
    this,
    canvas,
    elementFactory,
    eventBus,
    graphicsFactory,
    injector
  );
 
  this._bpmnRules = bpmnRules;
}
 
inherits(BpmnConnectPreview, ConnectPreview);
 
BpmnConnectPreview.$inject = [
  'bpmnRules',
  'canvas',
  'elementFactory',
  'eventBus',
  'graphicsFactory',
  'injector'
];
 
/**
 * Get connection that connect source and target once connect is finished.
 *
 * @param {Object|boolean} canConnect
 * @param {djs.model.shape} source
 * @param {djs.model.shape} target
 *
 * @returns {djs.model.connection}
 */
BpmnConnectPreview.prototype.getConnection = function(canConnect, source, target) {
  var attrs = canConnect;
 
  if (!attrs || !attrs.type) {
    attrs = this._bpmnRules.canConnect(source, target);
  }
 
  if (!attrs) {
    return;
  }
 
  return this._elementFactory.createConnection(attrs);
};