2014-06-11 12:41:55 +00:00
|
|
|
'use strict';
|
2014-03-20 15:18:23 +00:00
|
|
|
|
2015-03-23 14:15:32 +00:00
|
|
|
var inherits = require('inherits');
|
|
|
|
|
2016-03-16 16:11:38 +00:00
|
|
|
var Ids = require('ids');
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2014-06-11 12:41:55 +00:00
|
|
|
var Viewer = require('./Viewer');
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2016-05-12 11:15:32 +00:00
|
|
|
var NavigatedViewer = require('./NavigatedViewer');
|
|
|
|
|
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.
|
|
|
|
* @param {String|Number} [options.width] the width of the viewer
|
|
|
|
* @param {String|Number} [options.height] the height of the viewer
|
|
|
|
* @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
|
|
|
*/
|
2014-04-04 16:48:37 +00:00
|
|
|
function Modeler(options) {
|
|
|
|
Viewer.call(this, options);
|
2016-03-17 08:39:43 +00:00
|
|
|
|
|
|
|
// hook ID collection into the modeler
|
|
|
|
this.on('import.parse.complete', function(event) {
|
|
|
|
if (!event.error) {
|
|
|
|
this._collectIds(event.definitions, event.context);
|
|
|
|
}
|
|
|
|
}, this);
|
2016-03-18 12:10:07 +00:00
|
|
|
|
|
|
|
this.on('diagram.destroy', function() {
|
2017-11-20 13:48:38 +00:00
|
|
|
this.get('moddle').ids.clear();
|
2016-03-18 12:10:07 +00:00
|
|
|
}, this);
|
2014-03-18 16:01:24 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 14:15:32 +00:00
|
|
|
inherits(Modeler, Viewer);
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
module.exports = Modeler;
|
|
|
|
|
2016-05-12 11:15:32 +00:00
|
|
|
module.exports.Viewer = Viewer;
|
|
|
|
|
|
|
|
module.exports.NavigatedViewer = NavigatedViewer;
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
/**
|
|
|
|
* Create a new diagram to start modeling.
|
|
|
|
*
|
2016-03-17 09:42:14 +00:00
|
|
|
* @param {Function} [done]
|
2016-03-17 08:39:43 +00:00
|
|
|
*/
|
2015-11-11 10:31:58 +00:00
|
|
|
Modeler.prototype.createDiagram = function(done) {
|
|
|
|
return this.importXML(initialDiagram, done);
|
2014-06-24 13:50:51 +00:00
|
|
|
};
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
/**
|
|
|
|
* Create a moddle instance, attaching ids to it.
|
|
|
|
*
|
|
|
|
* @param {Object} options
|
|
|
|
*/
|
2016-03-16 22:11:05 +00:00
|
|
|
Modeler.prototype._createModdle = function(options) {
|
|
|
|
var moddle = Viewer.prototype._createModdle.call(this, options);
|
2014-08-04 14:34:37 +00:00
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
// attach ids to moddle to be able to track
|
|
|
|
// and validated ids in the BPMN 2.0 XML document
|
|
|
|
// tree
|
2016-03-16 16:11:38 +00:00
|
|
|
moddle.ids = new Ids([ 32, 36, 1 ]);
|
2014-08-04 14:34:37 +00:00
|
|
|
|
|
|
|
return moddle;
|
|
|
|
};
|
2014-06-24 13:50:51 +00:00
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
/**
|
|
|
|
* Collect ids processed during parsing of the
|
|
|
|
* definitions object.
|
|
|
|
*
|
|
|
|
* @param {ModdleElement} definitions
|
|
|
|
* @param {Context} context
|
|
|
|
*/
|
|
|
|
Modeler.prototype._collectIds = function(definitions, context) {
|
2016-03-16 16:11:38 +00:00
|
|
|
|
|
|
|
var moddle = definitions.$model,
|
|
|
|
ids = moddle.ids,
|
|
|
|
id;
|
|
|
|
|
|
|
|
// remove references from previous import
|
|
|
|
ids.clear();
|
|
|
|
|
|
|
|
for (id in context.elementsById) {
|
|
|
|
ids.claim(id, context.elementsById[id]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-08 12:42:50 +00:00
|
|
|
|
|
|
|
Modeler.prototype._interactionModules = [
|
2014-08-06 12:40:34 +00:00
|
|
|
// non-modeling components
|
2014-08-27 13:43:18 +00:00
|
|
|
require('diagram-js/lib/navigation/movecanvas'),
|
2016-04-27 13:39:41 +00:00
|
|
|
require('diagram-js/lib/navigation/touch'),
|
2016-06-21 13:18:29 +00:00
|
|
|
require('diagram-js/lib/navigation/zoomscroll')
|
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 = [
|
2014-08-06 12:40:34 +00:00
|
|
|
// modeling components
|
2016-06-21 13:18:29 +00:00
|
|
|
require('diagram-js/lib/features/auto-scroll'),
|
2015-01-14 17:48:06 +00:00
|
|
|
require('diagram-js/lib/features/bendpoints'),
|
2016-06-21 13:18:29 +00:00
|
|
|
require('diagram-js/lib/features/move'),
|
2014-10-10 07:06:21 +00:00
|
|
|
require('diagram-js/lib/features/resize'),
|
2016-06-21 13:18:29 +00:00
|
|
|
require('./features/auto-resize'),
|
|
|
|
require('./features/editor-actions'),
|
|
|
|
require('./features/context-pad'),
|
2015-05-06 15:36:46 +00:00
|
|
|
require('./features/keyboard'),
|
2016-06-21 13:18:29 +00:00
|
|
|
require('./features/label-editing'),
|
2014-08-27 13:43:18 +00:00
|
|
|
require('./features/modeling'),
|
2015-08-17 14:43:15 +00:00
|
|
|
require('./features/palette'),
|
2016-06-21 13:18:29 +00:00
|
|
|
require('./features/replace-preview'),
|
2017-01-11 14:22:32 +00:00
|
|
|
require('./features/snapping')
|
2014-08-08 12:42:50 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
// modules the modeler is composed of
|
|
|
|
//
|
|
|
|
// - viewer modules
|
|
|
|
// - interaction modules
|
|
|
|
// - modeling modules
|
|
|
|
|
|
|
|
Modeler.prototype._modules = [].concat(
|
|
|
|
Modeler.prototype._modules,
|
|
|
|
Modeler.prototype._interactionModules,
|
2016-04-20 15:31:42 +00:00
|
|
|
Modeler.prototype._modelingModules);
|