chore(editor-actions): make dependencies optional
* Treat features as optional dependencies and register action only if feature exists * Explicitly add features to the Modeler and NavigatedViewer types
This commit is contained in:
parent
b60feba531
commit
645265ad7e
|
@ -6,24 +6,29 @@ import Viewer from './Viewer';
|
||||||
|
|
||||||
import NavigatedViewer from './NavigatedViewer';
|
import NavigatedViewer from './NavigatedViewer';
|
||||||
|
|
||||||
|
import KeyboardMoveModule from 'diagram-js/lib/navigation/keyboard-move';
|
||||||
import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas';
|
import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas';
|
||||||
import TouchModule from 'diagram-js/lib/navigation/touch';
|
import TouchModule from 'diagram-js/lib/navigation/touch';
|
||||||
import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll';
|
import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll';
|
||||||
|
|
||||||
|
import AlignElementsModule from 'diagram-js/lib/features/align-elements';
|
||||||
|
import AutoPlaceModule from './features/auto-place';
|
||||||
|
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 MoveModule from 'diagram-js/lib/features/move';
|
|
||||||
import ResizeModule from 'diagram-js/lib/features/resize';
|
|
||||||
import AutoResizeModule from './features/auto-resize';
|
|
||||||
import AutoPlaceModule from './features/auto-place';
|
|
||||||
import EditorActionsModule from './features/editor-actions';
|
|
||||||
import ContextPadModule from './features/context-pad';
|
import ContextPadModule from './features/context-pad';
|
||||||
|
import CopyPasteModule from 'diagram-js/lib/features/copy-paste';
|
||||||
|
import DistributeElementsModule from './features/distribute-elements';
|
||||||
|
import EditorActionsModule from './features/editor-actions';
|
||||||
import KeyboardModule from './features/keyboard';
|
import KeyboardModule from './features/keyboard';
|
||||||
import LabelEditingModule from './features/label-editing';
|
import LabelEditingModule from './features/label-editing';
|
||||||
import ModelingModule from './features/modeling';
|
import ModelingModule from './features/modeling';
|
||||||
|
import MoveModule from 'diagram-js/lib/features/move';
|
||||||
import PaletteModule from './features/palette';
|
import PaletteModule from './features/palette';
|
||||||
import ReplacePreviewModule from './features/replace-preview';
|
import ReplacePreviewModule from './features/replace-preview';
|
||||||
|
import ResizeModule from 'diagram-js/lib/features/resize';
|
||||||
import SnappingModule from './features/snapping';
|
import SnappingModule from './features/snapping';
|
||||||
|
import SearchModule from './features/search';
|
||||||
|
|
||||||
|
|
||||||
var initialDiagram =
|
var initialDiagram =
|
||||||
|
@ -187,6 +192,7 @@ Modeler.prototype._collectIds = function(definitions, context) {
|
||||||
|
|
||||||
Modeler.prototype._interactionModules = [
|
Modeler.prototype._interactionModules = [
|
||||||
// non-modeling components
|
// non-modeling components
|
||||||
|
KeyboardMoveModule,
|
||||||
MoveCanvasModule,
|
MoveCanvasModule,
|
||||||
TouchModule,
|
TouchModule,
|
||||||
ZoomScrollModule
|
ZoomScrollModule
|
||||||
|
@ -194,20 +200,24 @@ Modeler.prototype._interactionModules = [
|
||||||
|
|
||||||
Modeler.prototype._modelingModules = [
|
Modeler.prototype._modelingModules = [
|
||||||
// modeling components
|
// modeling components
|
||||||
AutoScrollModule,
|
AlignElementsModule,
|
||||||
BendpointsModule,
|
|
||||||
MoveModule,
|
|
||||||
ResizeModule,
|
|
||||||
AutoResizeModule,
|
|
||||||
AutoPlaceModule,
|
AutoPlaceModule,
|
||||||
EditorActionsModule,
|
AutoScrollModule,
|
||||||
|
AutoResizeModule,
|
||||||
|
BendpointsModule,
|
||||||
ContextPadModule,
|
ContextPadModule,
|
||||||
|
CopyPasteModule,
|
||||||
|
DistributeElementsModule,
|
||||||
|
EditorActionsModule,
|
||||||
KeyboardModule,
|
KeyboardModule,
|
||||||
LabelEditingModule,
|
LabelEditingModule,
|
||||||
ModelingModule,
|
ModelingModule,
|
||||||
|
MoveModule,
|
||||||
PaletteModule,
|
PaletteModule,
|
||||||
ReplacePreviewModule,
|
ReplacePreviewModule,
|
||||||
SnappingModule
|
ResizeModule,
|
||||||
|
SnappingModule,
|
||||||
|
SearchModule
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import inherits from 'inherits';
|
||||||
|
|
||||||
import Viewer from './Viewer';
|
import Viewer from './Viewer';
|
||||||
|
|
||||||
|
import KeyboardMoveModule from 'diagram-js/lib/navigation/keyboard-move';
|
||||||
import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas';
|
import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas';
|
||||||
import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll';
|
import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll';
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ export default function NavigatedViewer(options) {
|
||||||
inherits(NavigatedViewer, Viewer);
|
inherits(NavigatedViewer, Viewer);
|
||||||
|
|
||||||
NavigatedViewer.prototype._navigationModules = [
|
NavigatedViewer.prototype._navigationModules = [
|
||||||
|
KeyboardMoveModule,
|
||||||
MoveCanvasModule,
|
MoveCanvasModule,
|
||||||
ZoomScrollModule
|
ZoomScrollModule
|
||||||
];
|
];
|
||||||
|
|
|
@ -13,18 +13,49 @@ import {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers and executes BPMN specific editor actions.
|
* Registers and executes BPMN specific editor actions.
|
||||||
|
*
|
||||||
|
* @param {Injector} injector
|
||||||
*/
|
*/
|
||||||
export default function BpmnEditorActions(
|
export default function BpmnEditorActions(injector) {
|
||||||
injector, canvas, elementRegistry,
|
|
||||||
selection, spaceTool, lassoTool,
|
|
||||||
handTool, globalConnect, distributeElements,
|
|
||||||
alignElements, directEditing, searchPad,
|
|
||||||
modeling) {
|
|
||||||
|
|
||||||
injector.invoke(EditorActions, this);
|
injector.invoke(EditorActions, this);
|
||||||
|
}
|
||||||
|
|
||||||
this.register({
|
inherits(BpmnEditorActions, EditorActions);
|
||||||
selectElements: function() {
|
|
||||||
|
BpmnEditorActions.$inject = [
|
||||||
|
'injector'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register default actions.
|
||||||
|
*
|
||||||
|
* @param {Injector} injector
|
||||||
|
*/
|
||||||
|
BpmnEditorActions.prototype._registerDefaultActions = function(injector) {
|
||||||
|
|
||||||
|
// (0) invoke super method
|
||||||
|
|
||||||
|
EditorActions.prototype._registerDefaultActions.call(this, injector);
|
||||||
|
|
||||||
|
// (1) retrieve optional components to integrate with
|
||||||
|
|
||||||
|
var canvas = injector.get('canvas', false);
|
||||||
|
var elementRegistry = injector.get('elementRegistry', false);
|
||||||
|
var selection = injector.get('selection', false);
|
||||||
|
var spaceTool = injector.get('spaceTool', false);
|
||||||
|
var lassoTool = injector.get('lassoTool', false);
|
||||||
|
var handTool = injector.get('handTool', false);
|
||||||
|
var globalConnect = injector.get('globalConnect', false);
|
||||||
|
var distributeElements = injector.get('distributeElements', false);
|
||||||
|
var alignElements = injector.get('alignElements', false);
|
||||||
|
var directEditing = injector.get('directEditing', false);
|
||||||
|
var searchPad = injector.get('searchPad', false);
|
||||||
|
var modeling = injector.get('modeling', false);
|
||||||
|
|
||||||
|
// (2) check components and register actions
|
||||||
|
|
||||||
|
if (canvas && elementRegistry && selection) {
|
||||||
|
this._registerAction('selectElements', function() {
|
||||||
// select all elements except for the invisible
|
// select all elements except for the invisible
|
||||||
// root element
|
// root element
|
||||||
var rootElement = canvas.getRootElement();
|
var rootElement = canvas.getRootElement();
|
||||||
|
@ -36,28 +67,46 @@ export default function BpmnEditorActions(
|
||||||
selection.select(elements);
|
selection.select(elements);
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
},
|
});
|
||||||
spaceTool: function() {
|
}
|
||||||
|
|
||||||
|
if (spaceTool) {
|
||||||
|
this._registerAction('spaceTool', function() {
|
||||||
spaceTool.toggle();
|
spaceTool.toggle();
|
||||||
},
|
});
|
||||||
lassoTool: function() {
|
}
|
||||||
|
|
||||||
|
if (lassoTool) {
|
||||||
|
this._registerAction('lassoTool', function() {
|
||||||
lassoTool.toggle();
|
lassoTool.toggle();
|
||||||
},
|
});
|
||||||
handTool: function() {
|
}
|
||||||
|
|
||||||
|
if (handTool) {
|
||||||
|
this._registerAction('handTool', function() {
|
||||||
handTool.toggle();
|
handTool.toggle();
|
||||||
},
|
});
|
||||||
globalConnectTool: function() {
|
}
|
||||||
|
|
||||||
|
if (globalConnect) {
|
||||||
|
this._registerAction('globalConnectTool', function() {
|
||||||
globalConnect.toggle();
|
globalConnect.toggle();
|
||||||
},
|
});
|
||||||
distributeElements: function(opts) {
|
}
|
||||||
|
|
||||||
|
if (selection && distributeElements) {
|
||||||
|
this._registerAction('distributeElements', function(opts) {
|
||||||
var currentSelection = selection.get(),
|
var currentSelection = selection.get(),
|
||||||
type = opts.type;
|
type = opts.type;
|
||||||
|
|
||||||
if (currentSelection.length) {
|
if (currentSelection.length) {
|
||||||
distributeElements.trigger(currentSelection, type);
|
distributeElements.trigger(currentSelection, type);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
alignElements: function(opts) {
|
}
|
||||||
|
|
||||||
|
if (selection && alignElements) {
|
||||||
|
this._registerAction('alignElements', function(opts) {
|
||||||
var currentSelection = selection.get(),
|
var currentSelection = selection.get(),
|
||||||
aligneableElements = [],
|
aligneableElements = [],
|
||||||
type = opts.type;
|
type = opts.type;
|
||||||
|
@ -69,25 +118,37 @@ export default function BpmnEditorActions(
|
||||||
|
|
||||||
alignElements.trigger(aligneableElements, type);
|
alignElements.trigger(aligneableElements, type);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
setColor: function(opts) {
|
}
|
||||||
|
|
||||||
|
if (selection && modeling) {
|
||||||
|
this._registerAction('setColor', function(opts) {
|
||||||
var currentSelection = selection.get();
|
var currentSelection = selection.get();
|
||||||
|
|
||||||
if (currentSelection.length) {
|
if (currentSelection.length) {
|
||||||
modeling.setColor(currentSelection, opts);
|
modeling.setColor(currentSelection, opts);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
directEditing: function() {
|
}
|
||||||
|
|
||||||
|
if (selection && directEditing) {
|
||||||
|
this._registerAction('directEditing', function() {
|
||||||
var currentSelection = selection.get();
|
var currentSelection = selection.get();
|
||||||
|
|
||||||
if (currentSelection.length) {
|
if (currentSelection.length) {
|
||||||
directEditing.activate(currentSelection[0]);
|
directEditing.activate(currentSelection[0]);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
find: function() {
|
}
|
||||||
|
|
||||||
|
if (searchPad) {
|
||||||
|
this._registerAction('find', function() {
|
||||||
searchPad.toggle();
|
searchPad.toggle();
|
||||||
},
|
});
|
||||||
moveToOrigin: function() {
|
}
|
||||||
|
|
||||||
|
if (canvas && modeling) {
|
||||||
|
this._registerAction('moveToOrigin', function() {
|
||||||
var rootElement = canvas.getRootElement(),
|
var rootElement = canvas.getRootElement(),
|
||||||
boundingBox,
|
boundingBox,
|
||||||
elements;
|
elements;
|
||||||
|
@ -104,25 +165,12 @@ export default function BpmnEditorActions(
|
||||||
|
|
||||||
boundingBox = getBBox(elements);
|
boundingBox = getBBox(elements);
|
||||||
|
|
||||||
modeling.moveElements(elements, { x: -boundingBox.x, y: -boundingBox.y }, rootElement);
|
modeling.moveElements(
|
||||||
}
|
elements,
|
||||||
|
{ x: -boundingBox.x, y: -boundingBox.y },
|
||||||
|
rootElement
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(BpmnEditorActions, EditorActions);
|
};
|
||||||
|
|
||||||
BpmnEditorActions.$inject = [
|
|
||||||
'injector',
|
|
||||||
'canvas',
|
|
||||||
'elementRegistry',
|
|
||||||
'selection',
|
|
||||||
'spaceTool',
|
|
||||||
'lassoTool',
|
|
||||||
'handTool',
|
|
||||||
'globalConnect',
|
|
||||||
'distributeElements',
|
|
||||||
'alignElements',
|
|
||||||
'directEditing',
|
|
||||||
'searchPad',
|
|
||||||
'modeling'
|
|
||||||
];
|
|
|
@ -1,29 +1,10 @@
|
||||||
import AlignElementsModule from 'diagram-js/lib/features/align-elements';
|
|
||||||
import EditorActionsModule from 'diagram-js/lib/features/editor-actions';
|
import EditorActionsModule from 'diagram-js/lib/features/editor-actions';
|
||||||
import HandToolModule from 'diagram-js/lib/features/hand-tool';
|
|
||||||
import LassoToolModule from 'diagram-js/lib/features/lasso-tool';
|
|
||||||
import SpaceToolModule from 'diagram-js/lib/features/space-tool';
|
|
||||||
import GlobalConnectModule from 'diagram-js/lib/features/global-connect';
|
|
||||||
import DirectEditingModule from 'diagram-js-direct-editing';
|
|
||||||
|
|
||||||
import CopyPasteModule from '../copy-paste';
|
|
||||||
import DistributeElementsModule from '../distribute-elements';
|
|
||||||
import SearchModule from '../search';
|
|
||||||
|
|
||||||
import BpmnEditorActions from './BpmnEditorActions';
|
import BpmnEditorActions from './BpmnEditorActions';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
__depends__: [
|
__depends__: [
|
||||||
AlignElementsModule,
|
EditorActionsModule
|
||||||
EditorActionsModule,
|
|
||||||
HandToolModule,
|
|
||||||
LassoToolModule,
|
|
||||||
SpaceToolModule,
|
|
||||||
DirectEditingModule,
|
|
||||||
GlobalConnectModule,
|
|
||||||
CopyPasteModule,
|
|
||||||
DistributeElementsModule,
|
|
||||||
SearchModule
|
|
||||||
],
|
],
|
||||||
editorActions: [ 'type', BpmnEditorActions ]
|
editorActions: [ 'type', BpmnEditorActions ]
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue