2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2015-03-23 14:15:32 +00:00
|
|
|
|
2019-12-01 14:18:09 +00:00
|
|
|
import BaseModeler from './BaseModeler';
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import Viewer from './Viewer';
|
|
|
|
import NavigatedViewer from './NavigatedViewer';
|
|
|
|
|
2018-10-26 22:54:31 +00:00
|
|
|
import KeyboardMoveModule from 'diagram-js/lib/navigation/keyboard-move';
|
2018-04-02 19:01:53 +00:00
|
|
|
import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas';
|
|
|
|
import TouchModule from 'diagram-js/lib/navigation/touch';
|
|
|
|
import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll';
|
|
|
|
|
2018-10-26 22:54:31 +00:00
|
|
|
import AlignElementsModule from 'diagram-js/lib/features/align-elements';
|
|
|
|
import AutoPlaceModule from './features/auto-place';
|
|
|
|
import AutoResizeModule from './features/auto-resize';
|
2018-04-02 19:01:53 +00:00
|
|
|
import AutoScrollModule from 'diagram-js/lib/features/auto-scroll';
|
|
|
|
import BendpointsModule from 'diagram-js/lib/features/bendpoints';
|
2019-05-13 14:09:14 +00:00
|
|
|
import ConnectModule from 'diagram-js/lib/features/connect';
|
2019-05-17 11:11:17 +00:00
|
|
|
import ConnectionPreviewModule from 'diagram-js/lib/features/connection-preview';
|
2018-04-02 19:01:53 +00:00
|
|
|
import ContextPadModule from './features/context-pad';
|
2018-11-06 12:39:50 +00:00
|
|
|
import CopyPasteModule from './features/copy-paste';
|
2019-05-13 14:09:14 +00:00
|
|
|
import CreateModule from 'diagram-js/lib/features/create';
|
2018-10-26 22:54:31 +00:00
|
|
|
import DistributeElementsModule from './features/distribute-elements';
|
|
|
|
import EditorActionsModule from './features/editor-actions';
|
2019-04-26 18:06:49 +00:00
|
|
|
import GridSnappingModule from './features/grid-snapping';
|
2019-06-14 13:29:00 +00:00
|
|
|
import InteractionEventsModule from './features/interaction-events';
|
2018-04-02 19:01:53 +00:00
|
|
|
import KeyboardModule from './features/keyboard';
|
2018-10-26 23:10:21 +00:00
|
|
|
import KeyboardMoveSelectionModule from 'diagram-js/lib/features/keyboard-move-selection';
|
2018-04-02 19:01:53 +00:00
|
|
|
import LabelEditingModule from './features/label-editing';
|
|
|
|
import ModelingModule from './features/modeling';
|
2018-10-26 22:54:31 +00:00
|
|
|
import MoveModule from 'diagram-js/lib/features/move';
|
2018-04-02 19:01:53 +00:00
|
|
|
import PaletteModule from './features/palette';
|
|
|
|
import ReplacePreviewModule from './features/replace-preview';
|
2018-10-26 22:54:31 +00:00
|
|
|
import ResizeModule from 'diagram-js/lib/features/resize';
|
2018-04-02 19:01:53 +00:00
|
|
|
import SnappingModule from './features/snapping';
|
2018-10-26 22:54:31 +00:00
|
|
|
import SearchModule from './features/search';
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
import {
|
|
|
|
wrapForCompatibility
|
|
|
|
} from './util/CompatibilityUtil';
|
2016-05-12 11:15:32 +00:00
|
|
|
|
2015-11-11 10:31:58 +00:00
|
|
|
var initialDiagram =
|
2014-06-24 13:50:51 +00:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>' +
|
|
|
|
'<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
|
|
|
'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
|
|
|
|
'xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" ' +
|
|
|
|
'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" ' +
|
|
|
|
'targetNamespace="http://bpmn.io/schema/bpmn" ' +
|
|
|
|
'id="Definitions_1">' +
|
|
|
|
'<bpmn:process id="Process_1" isExecutable="false">' +
|
|
|
|
'<bpmn:startEvent id="StartEvent_1"/>' +
|
|
|
|
'</bpmn:process>' +
|
|
|
|
'<bpmndi:BPMNDiagram id="BPMNDiagram_1">' +
|
|
|
|
'<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">' +
|
|
|
|
'<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">' +
|
|
|
|
'<dc:Bounds height="36.0" width="36.0" x="173.0" y="102.0"/>' +
|
|
|
|
'</bpmndi:BPMNShape>' +
|
|
|
|
'</bpmndi:BPMNPlane>' +
|
|
|
|
'</bpmndi:BPMNDiagram>' +
|
|
|
|
'</bpmn:definitions>';
|
2014-03-20 15:18:23 +00:00
|
|
|
|
2015-05-04 12:52:10 +00:00
|
|
|
|
2014-04-08 13:23:52 +00:00
|
|
|
/**
|
|
|
|
* A modeler for BPMN 2.0 diagrams.
|
2014-06-11 12:41:55 +00:00
|
|
|
*
|
2014-08-01 05:55:47 +00:00
|
|
|
*
|
2015-05-04 12:52:10 +00:00
|
|
|
* ## Extending the Modeler
|
|
|
|
*
|
|
|
|
* In order to extend the viewer pass extension modules to bootstrap via the
|
|
|
|
* `additionalModules` option. An extension module is an object that exposes
|
|
|
|
* named services.
|
|
|
|
*
|
|
|
|
* The following example depicts the integration of a simple
|
|
|
|
* logging component that integrates with interaction events:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
*
|
|
|
|
* // logging component
|
|
|
|
* function InteractionLogger(eventBus) {
|
|
|
|
* eventBus.on('element.hover', function(event) {
|
|
|
|
* console.log()
|
|
|
|
* })
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* InteractionLogger.$inject = [ 'eventBus' ]; // minification save
|
|
|
|
*
|
|
|
|
* // extension module
|
|
|
|
* var extensionModule = {
|
|
|
|
* __init__: [ 'interactionLogger' ],
|
|
|
|
* interactionLogger: [ 'type', InteractionLogger ]
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* // extend the viewer
|
|
|
|
* var bpmnModeler = new Modeler({ additionalModules: [ extensionModule ] });
|
|
|
|
* bpmnModeler.importXML(...);
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ## Customizing / Replacing Components
|
|
|
|
*
|
|
|
|
* You can replace individual diagram components by redefining them in override modules.
|
|
|
|
* This works for all components, including those defined in the core.
|
|
|
|
*
|
|
|
|
* Pass in override modules via the `options.additionalModules` flag like this:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* function CustomContextPadProvider(contextPad) {
|
|
|
|
*
|
|
|
|
* contextPad.registerProvider(this);
|
|
|
|
*
|
|
|
|
* this.getContextPadEntries = function(element) {
|
|
|
|
* // no entries, effectively disable the context pad
|
|
|
|
* return {};
|
|
|
|
* };
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* CustomContextPadProvider.$inject = [ 'contextPad' ];
|
|
|
|
*
|
|
|
|
* var overrideModule = {
|
|
|
|
* contextPadProvider: [ 'type', CustomContextPadProvider ]
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* var bpmnModeler = new Modeler({ additionalModules: [ overrideModule ]});
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @param {Object} [options] configuration options to pass to the viewer
|
|
|
|
* @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
|
2020-04-06 08:25:03 +00:00
|
|
|
* @param {string|number} [options.width] the width of the viewer
|
|
|
|
* @param {string|number} [options.height] the height of the viewer
|
2015-05-04 12:52:10 +00:00
|
|
|
* @param {Object} [options.moddleExtensions] extension packages to provide
|
|
|
|
* @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
|
|
|
|
* @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
|
2014-04-08 13:23:52 +00:00
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function Modeler(options) {
|
2019-12-01 14:18:09 +00:00
|
|
|
BaseModeler.call(this, options);
|
2014-03-18 16:01:24 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 14:18:09 +00:00
|
|
|
inherits(Modeler, BaseModeler);
|
|
|
|
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
Modeler.Viewer = Viewer;
|
|
|
|
Modeler.NavigatedViewer = NavigatedViewer;
|
2016-05-12 11:15:32 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
/**
|
|
|
|
* The createDiagram result.
|
|
|
|
*
|
|
|
|
* @typedef {Object} CreateDiagramResult
|
|
|
|
*
|
|
|
|
* @property {Array<string>} warnings
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The createDiagram error.
|
|
|
|
*
|
|
|
|
* @typedef {Error} CreateDiagramError
|
|
|
|
*
|
|
|
|
* @property {Array<string>} warnings
|
|
|
|
*/
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
/**
|
|
|
|
* Create a new diagram to start modeling.
|
|
|
|
*
|
2020-04-29 09:02:42 +00:00
|
|
|
* Returns {Promise<CreateDiagramResult, CreateDiagramError>}
|
2016-03-17 08:39:43 +00:00
|
|
|
*/
|
2020-04-29 09:02:42 +00:00
|
|
|
Modeler.prototype.createDiagram = wrapForCompatibility(function createDiagram() {
|
|
|
|
return this.importXML(initialDiagram);
|
|
|
|
});
|
2014-06-24 13:50:51 +00:00
|
|
|
|
2016-03-16 16:11:38 +00:00
|
|
|
|
2014-08-08 12:42:50 +00:00
|
|
|
Modeler.prototype._interactionModules = [
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2014-08-06 12:40:34 +00:00
|
|
|
// non-modeling components
|
2018-10-26 22:54:31 +00:00
|
|
|
KeyboardMoveModule,
|
2018-04-02 19:01:53 +00:00
|
|
|
MoveCanvasModule,
|
|
|
|
TouchModule,
|
|
|
|
ZoomScrollModule
|
2014-08-08 12:42:50 +00:00
|
|
|
];
|
2014-08-06 12:40:34 +00:00
|
|
|
|
2014-08-08 12:42:50 +00:00
|
|
|
Modeler.prototype._modelingModules = [
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2014-08-06 12:40:34 +00:00
|
|
|
// modeling components
|
2018-10-26 22:54:31 +00:00
|
|
|
AlignElementsModule,
|
|
|
|
AutoPlaceModule,
|
2018-04-02 19:01:53 +00:00
|
|
|
AutoScrollModule,
|
|
|
|
AutoResizeModule,
|
2018-10-26 22:54:31 +00:00
|
|
|
BendpointsModule,
|
2019-05-09 12:24:05 +00:00
|
|
|
ConnectModule,
|
2019-05-13 14:09:14 +00:00
|
|
|
ConnectionPreviewModule,
|
2018-04-02 19:01:53 +00:00
|
|
|
ContextPadModule,
|
2018-10-26 22:54:31 +00:00
|
|
|
CopyPasteModule,
|
2019-05-09 12:24:12 +00:00
|
|
|
CreateModule,
|
2018-10-26 22:54:31 +00:00
|
|
|
DistributeElementsModule,
|
|
|
|
EditorActionsModule,
|
2019-04-26 18:06:49 +00:00
|
|
|
GridSnappingModule,
|
2019-06-14 13:29:00 +00:00
|
|
|
InteractionEventsModule,
|
2018-04-02 19:01:53 +00:00
|
|
|
KeyboardModule,
|
2018-10-26 23:10:21 +00:00
|
|
|
KeyboardMoveSelectionModule,
|
2018-04-02 19:01:53 +00:00
|
|
|
LabelEditingModule,
|
|
|
|
ModelingModule,
|
2018-10-26 22:54:31 +00:00
|
|
|
MoveModule,
|
2018-04-02 19:01:53 +00:00
|
|
|
PaletteModule,
|
|
|
|
ReplacePreviewModule,
|
2018-10-26 22:54:31 +00:00
|
|
|
ResizeModule,
|
|
|
|
SnappingModule,
|
|
|
|
SearchModule
|
2014-08-08 12:42:50 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
// modules the modeler is composed of
|
|
|
|
//
|
|
|
|
// - viewer modules
|
|
|
|
// - interaction modules
|
|
|
|
// - modeling modules
|
|
|
|
|
|
|
|
Modeler.prototype._modules = [].concat(
|
2019-12-01 14:18:09 +00:00
|
|
|
Viewer.prototype._modules,
|
2014-08-08 12:42:50 +00:00
|
|
|
Modeler.prototype._interactionModules,
|
2019-12-01 14:18:09 +00:00
|
|
|
Modeler.prototype._modelingModules
|
|
|
|
);
|