all files / Github/bpmn-js/lib/features/create/ BpmnCreateConnectPreview.js

81.82% Statements 9/11
66.67% Branches 4/6
100% Functions 2/2
81.82% Lines 9/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 CreateConnectPreview from 'diagram-js/lib/features/create/CreateConnectPreview';
 
/**
 * Shows connection preview during create.
 *
 * @param {Canvas} canvas
 * @param {BpmnRules} bpmnRules
 * @param {ElementFactory} elementFactory
 * @param {EventBus} eventBus
 * @param {GraphicsFactory} graphicsFactory
 * @param {didi.Injector} injector
 */
export default function BpmnCreateConnectPreview(
    bpmnRules,
    canvas,
    elementFactory,
    eventBus,
    graphicsFactory,
    injector
) {
  CreateConnectPreview.call(
    this,
    canvas,
    elementFactory,
    eventBus,
    graphicsFactory,
    injector
  );
 
  this._bpmnRules = bpmnRules;
}
 
inherits(BpmnCreateConnectPreview, CreateConnectPreview);
 
BpmnCreateConnectPreview.$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}
 */
BpmnCreateConnectPreview.prototype.getConnection = function(canConnect, source, target) {
  var attrs = canConnect;
 
  Iif (!attrs || !attrs.type) {
    attrs = this._bpmnRules.canConnect(source, target);
  }
 
  Iif (!attrs) {
    return;
  }
 
  return this._elementFactory.createConnection(attrs);
};