all files / bpmn-js/lib/features/connection-preview/ BpmnConnectionPreview.js

100% Statements 12/12
100% Branches 6/6
100% Functions 2/2
100% Lines 12/12
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                        63×   63× 63×                                   12×   12×     12×      
import inherits from 'inherits';
 
import ConnectionPreview from 'diagram-js/lib/features/connection-preview/ConnectionPreview';
 
/**
 * Shows connection preview.
 *
 * @param {didi.Injector} injector
 * @param {ElementFactory} elementFactory
 * @param {BpmnRules} bpmnRules
 */
export default function BpmnConnectionPreview(injector, elementFactory, bpmnRules) {
  injector.invoke(ConnectionPreview, this);
 
  this._elementFactory = elementFactory;
  this._bpmnRules = bpmnRules;
}
 
inherits(BpmnConnectionPreview, ConnectionPreview);
 
BpmnConnectionPreview.$inject = [
  'injector',
  'elementFactory',
  'bpmnRules'
];
 
/**
 * 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}
 */
BpmnConnectionPreview.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);
};