chore(Modeler): remove bpmn-moddle id-support
* Handle id tracking ourself. * Do not reinstantiate moddle on re-import (now stateless) * <3 Closes #493
This commit is contained in:
parent
31b49fd333
commit
f573a36071
|
@ -51,7 +51,7 @@
|
|||
"version": "bpmn-io/diagram-js-direct-editing"
|
||||
},
|
||||
"ids": {
|
||||
"version": "0.1.2",
|
||||
"version": "0.2.0",
|
||||
"dependencies": {
|
||||
"hat": {
|
||||
"version": "0.0.3"
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
var inherits = require('inherits');
|
||||
|
||||
var IdSupport = require('bpmn-moddle/lib/id-support'),
|
||||
Ids = require('ids');
|
||||
var Ids = require('ids');
|
||||
|
||||
var Viewer = require('./Viewer');
|
||||
|
||||
|
@ -113,11 +112,25 @@ Modeler.prototype.createDiagram = function(done) {
|
|||
Modeler.prototype.createModdle = function() {
|
||||
var moddle = Viewer.prototype.createModdle.call(this);
|
||||
|
||||
IdSupport.extend(moddle, new Ids([ 32, 36, 1 ]));
|
||||
moddle.ids = new Ids([ 32, 36, 1 ]);
|
||||
|
||||
return moddle;
|
||||
};
|
||||
|
||||
Modeler.prototype._parsedXML = function(definitions, context) {
|
||||
|
||||
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]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Modeler.prototype._interactionModules = [
|
||||
// non-modeling components
|
||||
|
|
|
@ -112,6 +112,8 @@ function Viewer(options) {
|
|||
|
||||
this.options = options = assign({}, DEFAULT_OPTIONS, options || {});
|
||||
|
||||
this.moddle = this.createModdle();
|
||||
|
||||
var parent = options.container;
|
||||
|
||||
// support jquery element
|
||||
|
@ -157,8 +159,6 @@ Viewer.prototype.importXML = function(xml, done) {
|
|||
|
||||
var self = this;
|
||||
|
||||
this.moddle = this.createModdle();
|
||||
|
||||
this.moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
|
||||
|
||||
if (err) {
|
||||
|
@ -166,6 +166,10 @@ Viewer.prototype.importXML = function(xml, done) {
|
|||
return done(err);
|
||||
}
|
||||
|
||||
if (typeof self._parsedXML === 'function') {
|
||||
self._parsedXML(definitions, context);
|
||||
}
|
||||
|
||||
var parseWarnings = context.warnings;
|
||||
|
||||
self.importDefinitions(definitions, function(err, importWarnings) {
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
"bpmn-moddle": "^0.10.4",
|
||||
"diagram-js": "^0.13.3",
|
||||
"diagram-js-direct-editing": "^0.13.0",
|
||||
"ids": "^0.1.2",
|
||||
"ids": "^0.2.0",
|
||||
"inherits": "^2.0.1",
|
||||
"lodash": "^3.0.1",
|
||||
"min-dom": "^0.2.0",
|
||||
|
|
|
@ -107,6 +107,37 @@ describe('Modeler', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('ids', function() {
|
||||
|
||||
it('should populate ids on import', function(done) {
|
||||
|
||||
// given
|
||||
var xml = require('../fixtures/bpmn/simple.bpmn');
|
||||
|
||||
var modeler = new Modeler({ container: container });
|
||||
|
||||
|
||||
// when
|
||||
modeler.importXML(xml, function(err) {
|
||||
|
||||
var moddle = modeler.get('moddle');
|
||||
var elementRegistry = modeler.get('elementRegistry');
|
||||
|
||||
var subProcess = elementRegistry.get('SubProcess_1').businessObject;
|
||||
var bpmnEdge = elementRegistry.get('SequenceFlow_3').businessObject.di;
|
||||
|
||||
// then
|
||||
expect(moddle.ids.assigned('SubProcess_1')).to.eql(subProcess);
|
||||
expect(moddle.ids.assigned('BPMNEdge_SequenceFlow_3')).to.eql(bpmnEdge);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('translate support', function() {
|
||||
|
||||
var xml = require('../fixtures/bpmn/simple.bpmn');
|
||||
|
|
Loading…
Reference in New Issue