fix(bpmn-connect-preview): override #getConnection

This commit is contained in:
Philipp Fromme 2019-05-09 14:24:05 +02:00 committed by merge-me[bot]
parent 48fcececbf
commit 1958b2e81b
3 changed files with 77 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import AutoPlaceModule from './features/auto-place';
import AutoResizeModule from './features/auto-resize'; import AutoResizeModule from './features/auto-resize';
import AutoScrollModule from 'diagram-js/lib/features/auto-scroll'; import AutoScrollModule from 'diagram-js/lib/features/auto-scroll';
import BendpointsModule from 'diagram-js/lib/features/bendpoints'; import BendpointsModule from 'diagram-js/lib/features/bendpoints';
import ConnectModule from './features/connect';
import ContextPadModule from './features/context-pad'; import ContextPadModule from './features/context-pad';
import CopyPasteModule from './features/copy-paste'; import CopyPasteModule from './features/copy-paste';
import DistributeElementsModule from './features/distribute-elements'; import DistributeElementsModule from './features/distribute-elements';
@ -207,6 +208,7 @@ Modeler.prototype._modelingModules = [
AutoScrollModule, AutoScrollModule,
AutoResizeModule, AutoResizeModule,
BendpointsModule, BendpointsModule,
ConnectModule,
ContextPadModule, ContextPadModule,
CopyPasteModule, CopyPasteModule,
DistributeElementsModule, DistributeElementsModule,

View File

@ -0,0 +1,67 @@
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);
};

View File

@ -0,0 +1,8 @@
import BpmnConnectPreview from './BpmnConnectPreview';
import ConnectModule from 'diagram-js/lib/features/connect';
export default {
__depends__: [ ConnectModule ],
__init__: [ 'connectPreview' ],
connectPreview: [ 'type', BpmnConnectPreview ]
};