2016-01-12 07:47:25 +00:00
|
|
|
/**
|
|
|
|
* The code in the <project-logo></project-logo> area
|
|
|
|
* must not be changed.
|
|
|
|
*
|
|
|
|
* @see http://bpmn.io/license for more information.
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
assign,
|
|
|
|
isNumber,
|
|
|
|
omit
|
|
|
|
} from 'min-dash';
|
2015-02-05 08:24:27 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
domify,
|
|
|
|
query as domQuery,
|
|
|
|
remove as domRemove
|
|
|
|
} from 'min-dom';
|
2015-02-02 13:46:21 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
innerSVG
|
|
|
|
} from 'tiny-svg';
|
2016-09-14 06:18:56 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import Diagram from 'diagram-js';
|
|
|
|
import BpmnModdle from 'bpmn-moddle';
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2014-04-09 08:50:20 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
importBpmnDiagram
|
|
|
|
} from './import/Importer';
|
2014-04-09 08:50:20 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import CoreModule from './core';
|
|
|
|
import TranslateModule from 'diagram-js/lib/i18n/translate';
|
|
|
|
import SelectionModule from 'diagram-js/lib/features/selection';
|
|
|
|
import OveraysModule from 'diagram-js/lib/features/overlays';
|
2014-03-26 16:45:04 +00:00
|
|
|
|
|
|
|
|
2014-06-30 17:04:40 +00:00
|
|
|
function checkValidationError(err) {
|
|
|
|
|
|
|
|
// check if we can help the user by indicating wrong BPMN 2.0 xml
|
|
|
|
// (in case he or the exporting tool did not get that right)
|
|
|
|
|
|
|
|
var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
|
|
|
|
var match = pattern.exec(err.message);
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
err.message =
|
|
|
|
'unparsable content <' + match[1] + '> detected; ' +
|
|
|
|
'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
var DEFAULT_OPTIONS = {
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
2017-01-27 09:09:34 +00:00
|
|
|
position: 'relative'
|
2014-12-18 08:45:45 +00:00
|
|
|
};
|
|
|
|
|
2015-02-05 08:24:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure the passed argument is a proper unit (defaulting to px)
|
|
|
|
*/
|
|
|
|
function ensureUnit(val) {
|
|
|
|
return val + (isNumber(val) ? 'px' : '');
|
|
|
|
}
|
|
|
|
|
2014-04-08 13:23:52 +00:00
|
|
|
/**
|
2015-01-10 11:04:26 +00:00
|
|
|
* A viewer for BPMN 2.0 diagrams.
|
2014-04-25 14:14:36 +00:00
|
|
|
*
|
2015-01-10 11:04:26 +00:00
|
|
|
* Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
|
|
|
|
* additional features.
|
2014-08-01 05:55:47 +00:00
|
|
|
*
|
2015-05-04 12:49:48 +00:00
|
|
|
*
|
|
|
|
* ## Extending the Viewer
|
|
|
|
*
|
|
|
|
* 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 bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
|
|
|
|
* bpmnViewer.importXML(...);
|
|
|
|
* ```
|
|
|
|
*
|
2014-04-08 13:23:52 +00:00
|
|
|
* @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
|
2015-02-12 14:50:23 +00:00
|
|
|
* @param {Object} [options.moddleExtensions] extension packages to provide
|
2014-08-01 05:55:47 +00:00
|
|
|
* @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 Viewer(options) {
|
2014-12-18 08:45:45 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
options = assign({}, DEFAULT_OPTIONS, options);
|
2014-04-08 13:23:52 +00:00
|
|
|
|
2017-11-20 13:48:38 +00:00
|
|
|
this._moddle = this._createModdle(options);
|
2016-03-16 16:11:38 +00:00
|
|
|
|
2017-11-20 13:48:38 +00:00
|
|
|
this._container = this._createContainer(options);
|
2014-04-08 13:23:52 +00:00
|
|
|
|
2016-01-12 07:47:25 +00:00
|
|
|
/* <project-logo> */
|
2014-04-04 16:48:37 +00:00
|
|
|
|
2017-11-20 13:48:38 +00:00
|
|
|
addProjectLogo(this._container);
|
2014-05-06 12:32:54 +00:00
|
|
|
|
|
|
|
/* </project-logo> */
|
2016-03-16 22:11:05 +00:00
|
|
|
|
2017-11-20 13:48:38 +00:00
|
|
|
this._init(this._container, this._moddle, options);
|
2014-03-18 16:01:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
inherits(Viewer, Diagram);
|
|
|
|
|
2016-01-12 07:47:25 +00:00
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
2016-03-17 08:39:43 +00:00
|
|
|
* Parse and render a BPMN 2.0 diagram.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* Once finished the viewer reports back the result to the
|
|
|
|
* provided callback function with (err, warnings).
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-03-17 08:39:43 +00:00
|
|
|
* ## Life-Cycle Events
|
|
|
|
*
|
|
|
|
* During import the viewer will fire life-cycle events:
|
|
|
|
*
|
|
|
|
* * import.parse.start (about to read model from xml)
|
|
|
|
* * import.parse.complete (model read; may have worked or not)
|
|
|
|
* * import.render.start (graphical import start)
|
|
|
|
* * import.render.complete (graphical import finished)
|
|
|
|
* * import.done (everything done)
|
|
|
|
*
|
|
|
|
* You can use these events to hook into the life-cycle.
|
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {String} xml the BPMN 2.0 xml
|
2016-03-17 09:42:14 +00:00
|
|
|
* @param {Function} [done] invoked with (err, warnings=[])
|
2016-02-11 16:20:41 +00:00
|
|
|
*/
|
2014-03-21 20:10:01 +00:00
|
|
|
Viewer.prototype.importXML = function(xml, done) {
|
|
|
|
|
2016-03-17 09:42:14 +00:00
|
|
|
// done is optional
|
|
|
|
done = done || function() {};
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
var self = this;
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
// hook in pre-parse listeners +
|
|
|
|
// allow xml manipulation
|
|
|
|
xml = this._emit('import.parse.start', { xml: xml }) || xml;
|
|
|
|
|
2017-11-20 13:48:38 +00:00
|
|
|
this._moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
|
2014-06-30 17:04:40 +00:00
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
// hook in post parse listeners +
|
|
|
|
// allow definitions manipulation
|
|
|
|
definitions = self._emit('import.parse.complete', {
|
|
|
|
error: err,
|
|
|
|
definitions: definitions,
|
|
|
|
context: context
|
|
|
|
}) || definitions;
|
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
var parseWarnings = context.warnings;
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
if (err) {
|
2014-06-30 17:04:40 +00:00
|
|
|
err = checkValidationError(err);
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
self._emit('import.done', { error: err, warnings: parseWarnings });
|
2016-03-17 08:39:43 +00:00
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
return done(err, parseWarnings);
|
2016-03-16 16:11:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
self.importDefinitions(definitions, function(err, importWarnings) {
|
2016-03-17 08:39:43 +00:00
|
|
|
var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
|
|
|
|
|
|
|
self._emit('import.done', { error: err, warnings: allWarnings });
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2015-11-24 11:53:18 +00:00
|
|
|
done(err, allWarnings);
|
2015-02-17 09:55:28 +00:00
|
|
|
});
|
2014-03-21 20:10:01 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
|
|
|
* Export the currently displayed BPMN 2.0 diagram as
|
|
|
|
* a BPMN 2.0 XML document.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {Object} [options] export options
|
|
|
|
* @param {Boolean} [options.format=false] output formated XML
|
|
|
|
* @param {Boolean} [options.preamble=true] output preamble
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {Function} done invoked with (err, xml)
|
|
|
|
*/
|
2014-03-24 10:02:58 +00:00
|
|
|
Viewer.prototype.saveXML = function(options, done) {
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
done = options;
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
2017-11-20 13:48:38 +00:00
|
|
|
var definitions = this._definitions;
|
2014-03-24 10:02:58 +00:00
|
|
|
|
|
|
|
if (!definitions) {
|
|
|
|
return done(new Error('no definitions loaded'));
|
|
|
|
}
|
|
|
|
|
2017-11-20 13:48:38 +00:00
|
|
|
this._moddle.toXML(definitions, options, done);
|
2014-03-24 10:02:58 +00:00
|
|
|
};
|
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
|
|
|
* Export the currently displayed BPMN 2.0 diagram as
|
|
|
|
* an SVG image.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {Function} done invoked with (err, svgStr)
|
|
|
|
*/
|
2014-03-24 10:02:58 +00:00
|
|
|
Viewer.prototype.saveSVG = function(options, done) {
|
2014-08-17 17:08:52 +00:00
|
|
|
|
2014-03-24 10:02:58 +00:00
|
|
|
if (!done) {
|
|
|
|
done = options;
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
var svg, err;
|
2014-08-17 17:08:52 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
try {
|
|
|
|
var canvas = this.get('canvas');
|
|
|
|
|
|
|
|
var contentNode = canvas.getDefaultLayer(),
|
|
|
|
defsNode = domQuery('defs', canvas._svg);
|
2014-08-17 17:08:52 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
var contents = innerSVG(contentNode),
|
|
|
|
defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
|
2014-03-24 10:02:58 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
var bbox = contentNode.getBBox();
|
2014-03-24 10:02:58 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
svg =
|
|
|
|
'<?xml version="1.0" encoding="utf-8"?>\n' +
|
|
|
|
'<!-- created with bpmn-js / http://bpmn.io -->\n' +
|
|
|
|
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
|
|
|
|
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
|
|
|
|
'width="' + bbox.width + '" height="' + bbox.height + '" ' +
|
|
|
|
'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
|
|
|
|
defs + contents +
|
|
|
|
'</svg>';
|
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
2014-03-24 10:02:58 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
done(err, svg);
|
2014-03-24 10:02:58 +00:00
|
|
|
};
|
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
|
|
|
* Get a named diagram service.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @example
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* var elementRegistry = viewer.get('elementRegistry');
|
|
|
|
* var startEventShape = elementRegistry.get('StartEvent_1');
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {String} name
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @return {Object} diagram service instance
|
2016-03-16 22:11:05 +00:00
|
|
|
*
|
|
|
|
* @method Viewer#get
|
2016-02-11 16:20:41 +00:00
|
|
|
*/
|
2014-04-04 16:48:37 +00:00
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
|
|
|
* Invoke a function in the context of this viewer.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @example
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* viewer.invoke(function(elementRegistry) {
|
|
|
|
* var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
* });
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {Function} fn to be invoked
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @return {Object} the functions return value
|
2016-03-16 22:11:05 +00:00
|
|
|
*
|
|
|
|
* @method Viewer#invoke
|
2016-02-11 16:20:41 +00:00
|
|
|
*/
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
/**
|
|
|
|
* Remove all drawn elements from the viewer.
|
|
|
|
*
|
|
|
|
* After calling this method the viewer can still
|
|
|
|
* be reused for opening another diagram.
|
|
|
|
*
|
|
|
|
* @method Viewer#clear
|
|
|
|
*/
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2014-08-01 05:47:36 +00:00
|
|
|
Viewer.prototype.importDefinitions = function(definitions, done) {
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
// catch synchronous exceptions during #clear()
|
2014-08-01 05:47:36 +00:00
|
|
|
try {
|
2017-11-20 13:48:38 +00:00
|
|
|
if (this._definitions) {
|
2016-03-16 22:11:05 +00:00
|
|
|
// clear existing rendered diagram
|
2014-08-01 05:47:36 +00:00
|
|
|
this.clear();
|
|
|
|
}
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
// update definitions
|
2017-11-20 13:48:38 +00:00
|
|
|
this._definitions = definitions;
|
2014-08-01 05:47:36 +00:00
|
|
|
} catch (e) {
|
2017-12-04 21:27:32 +00:00
|
|
|
return done(e);
|
2014-08-01 05:47:36 +00:00
|
|
|
}
|
2017-11-28 12:24:36 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
// perform graphical import
|
|
|
|
return importBpmnDiagram(this, definitions, done);
|
2014-08-01 05:47:36 +00:00
|
|
|
};
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
Viewer.prototype.getModules = function() {
|
|
|
|
return this._modules;
|
|
|
|
};
|
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
/**
|
2016-03-16 22:11:05 +00:00
|
|
|
* Destroy the viewer instance and remove all its
|
|
|
|
* remainders from the document tree.
|
2014-12-18 08:45:45 +00:00
|
|
|
*/
|
|
|
|
Viewer.prototype.destroy = function() {
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
// diagram destroy
|
|
|
|
Diagram.prototype.destroy.call(this);
|
|
|
|
|
|
|
|
// dom detach
|
2017-11-20 13:48:38 +00:00
|
|
|
domRemove(this._container);
|
2014-12-18 08:45:45 +00:00
|
|
|
};
|
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
/**
|
2016-03-16 22:11:05 +00:00
|
|
|
* Register an event listener
|
2014-06-24 13:50:51 +00:00
|
|
|
*
|
2016-02-16 09:31:12 +00:00
|
|
|
* Remove a previously added listener via {@link #off(event, callback)}.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2014-06-24 13:50:51 +00:00
|
|
|
* @param {String} event
|
2016-02-16 09:31:12 +00:00
|
|
|
* @param {Number} [priority]
|
|
|
|
* @param {Function} callback
|
|
|
|
* @param {Object} [that]
|
2014-06-24 13:50:51 +00:00
|
|
|
*/
|
2016-03-16 22:11:05 +00:00
|
|
|
Viewer.prototype.on = function(event, priority, callback, target) {
|
|
|
|
return this.get('eventBus').on(event, priority, callback, target);
|
2016-02-16 09:31:12 +00:00
|
|
|
};
|
2014-04-25 14:14:36 +00:00
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
/**
|
2016-03-16 22:11:05 +00:00
|
|
|
* De-register an event listener
|
2016-02-16 09:31:12 +00:00
|
|
|
*
|
|
|
|
* @param {String} event
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
Viewer.prototype.off = function(event, callback) {
|
2016-03-16 22:11:05 +00:00
|
|
|
this.get('eventBus').off(event, callback);
|
|
|
|
};
|
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
Viewer.prototype.attachTo = function(parentNode) {
|
|
|
|
|
|
|
|
if (!parentNode) {
|
|
|
|
throw new Error('parentNode required');
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we detach from the
|
|
|
|
// previous, old parent
|
|
|
|
this.detach();
|
|
|
|
|
|
|
|
// unwrap jQuery if provided
|
2017-02-17 17:44:01 +00:00
|
|
|
if (parentNode.get && parentNode.constructor.prototype.jquery) {
|
2017-01-27 09:09:34 +00:00
|
|
|
parentNode = parentNode.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof parentNode === 'string') {
|
|
|
|
parentNode = domQuery(parentNode);
|
|
|
|
}
|
|
|
|
|
2017-11-20 13:48:38 +00:00
|
|
|
parentNode.appendChild(this._container);
|
2017-01-27 09:09:34 +00:00
|
|
|
|
|
|
|
this._emit('attach', {});
|
2017-12-07 10:58:41 +00:00
|
|
|
|
|
|
|
this.get('canvas').resized();
|
2017-01-27 09:09:34 +00:00
|
|
|
};
|
|
|
|
|
2017-11-23 08:48:21 +00:00
|
|
|
Viewer.prototype.getDefinitions = function() {
|
|
|
|
return this._definitions;
|
|
|
|
};
|
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
Viewer.prototype.detach = function() {
|
|
|
|
|
|
|
|
var container = this._container,
|
|
|
|
parentNode = container.parentNode;
|
|
|
|
|
|
|
|
if (!parentNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._emit('detach', {});
|
|
|
|
|
|
|
|
parentNode.removeChild(container);
|
|
|
|
};
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
Viewer.prototype._init = function(container, moddle, options) {
|
|
|
|
|
|
|
|
var baseModules = options.modules || this.getModules(),
|
|
|
|
additionalModules = options.additionalModules || [],
|
|
|
|
staticModules = [
|
|
|
|
{
|
|
|
|
bpmnjs: [ 'value', this ],
|
|
|
|
moddle: [ 'value', moddle ]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var diagramModules = [].concat(staticModules, baseModules, additionalModules);
|
2018-03-22 09:22:37 +00:00
|
|
|
|
|
|
|
var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
|
2016-03-16 22:11:05 +00:00
|
|
|
canvas: assign({}, options.canvas, { container: container }),
|
|
|
|
modules: diagramModules
|
|
|
|
});
|
|
|
|
|
|
|
|
// invoke diagram constructor
|
|
|
|
Diagram.call(this, diagramOptions);
|
2017-01-27 09:09:34 +00:00
|
|
|
|
|
|
|
if (options && options.container) {
|
|
|
|
this.attachTo(options.container);
|
|
|
|
}
|
2016-03-16 22:11:05 +00:00
|
|
|
};
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
/**
|
|
|
|
* Emit an event on the underlying {@link EventBus}
|
|
|
|
*
|
|
|
|
* @param {String} type
|
|
|
|
* @param {Object} event
|
|
|
|
*
|
|
|
|
* @return {Object} event processing result (if any)
|
|
|
|
*/
|
|
|
|
Viewer.prototype._emit = function(type, event) {
|
|
|
|
return this.get('eventBus').fire(type, event);
|
|
|
|
};
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
Viewer.prototype._createContainer = function(options) {
|
2016-02-18 00:16:10 +00:00
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
var container = domify('<div class="bjs-container"></div>');
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
assign(container.style, {
|
|
|
|
width: ensureUnit(options.width),
|
|
|
|
height: ensureUnit(options.height),
|
|
|
|
position: options.position
|
|
|
|
});
|
|
|
|
|
|
|
|
return container;
|
|
|
|
};
|
|
|
|
|
|
|
|
Viewer.prototype._createModdle = function(options) {
|
|
|
|
var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
|
|
|
|
|
|
|
|
return new BpmnModdle(moddleOptions);
|
2014-03-26 16:45:04 +00:00
|
|
|
};
|
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
// modules the viewer is composed of
|
2014-06-17 09:19:31 +00:00
|
|
|
Viewer.prototype._modules = [
|
2018-04-02 19:01:53 +00:00
|
|
|
CoreModule,
|
|
|
|
TranslateModule,
|
|
|
|
SelectionModule,
|
|
|
|
OveraysModule
|
2014-06-11 12:41:55 +00:00
|
|
|
];
|
|
|
|
|
2016-02-18 00:16:10 +00:00
|
|
|
// default moddle extensions the viewer is composed of
|
|
|
|
Viewer.prototype._moddleExtensions = {};
|
2016-01-12 07:47:25 +00:00
|
|
|
|
|
|
|
/* <project-logo> */
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
open as openPoweredBy,
|
|
|
|
BPMNIO_IMG
|
|
|
|
} from './util/PoweredByUtil';
|
|
|
|
|
|
|
|
import {
|
|
|
|
event as domEvent
|
|
|
|
} from 'min-dom';
|
2016-01-12 07:47:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the project logo to the diagram container as
|
|
|
|
* required by the bpmn.io license.
|
|
|
|
*
|
|
|
|
* @see http://bpmn.io/license
|
|
|
|
*
|
|
|
|
* @param {Element} container
|
|
|
|
*/
|
|
|
|
function addProjectLogo(container) {
|
2018-04-02 19:01:53 +00:00
|
|
|
var img = BPMNIO_IMG;
|
2016-01-12 07:47:25 +00:00
|
|
|
|
|
|
|
var linkMarkup =
|
|
|
|
'<a href="http://bpmn.io" ' +
|
|
|
|
'target="_blank" ' +
|
|
|
|
'class="bjs-powered-by" ' +
|
|
|
|
'title="Powered by bpmn.io" ' +
|
|
|
|
'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' +
|
2018-01-02 12:33:45 +00:00
|
|
|
img +
|
2016-01-12 07:47:25 +00:00
|
|
|
'</a>';
|
|
|
|
|
|
|
|
var linkElement = domify(linkMarkup);
|
|
|
|
|
|
|
|
container.appendChild(linkElement);
|
|
|
|
|
|
|
|
domEvent.bind(linkElement, 'click', function(event) {
|
2018-04-02 19:01:53 +00:00
|
|
|
openPoweredBy();
|
2016-01-12 07:47:25 +00:00
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
/* </project-logo> */
|