feat(bpmn-js): allow custom model extensions to be passed
Related to bpmn-io/bpmn-moddle#15
This commit is contained in:
parent
04437a8354
commit
8c61906469
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
var BpmnModdle = require('bpmn-moddle'),
|
||||
IdSupport = require('bpmn-moddle/lib/id-support'),
|
||||
var IdSupport = require('bpmn-moddle/lib/id-support'),
|
||||
Ids = require('ids');
|
||||
|
||||
var Viewer = require('./Viewer');
|
||||
|
@ -44,7 +43,7 @@ Modeler.prototype.createDiagram = function(done) {
|
|||
};
|
||||
|
||||
Modeler.prototype.createModdle = function() {
|
||||
var moddle = new BpmnModdle();
|
||||
var moddle = Viewer.prototype.createModdle.call(this);
|
||||
|
||||
IdSupport.extend(moddle, new Ids([ 32, 36, 1 ]));
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ function ensureUnit(val) {
|
|||
* @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
|
||||
*/
|
||||
|
@ -128,7 +129,7 @@ Viewer.prototype.importXML = function(xml, done) {
|
|||
|
||||
var self = this;
|
||||
|
||||
this.moddle = this.createModdle();
|
||||
this.moddle = this.moddle || this.createModdle();
|
||||
|
||||
this.moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions) {
|
||||
|
||||
|
@ -158,7 +159,8 @@ Viewer.prototype.saveXML = function(options, done) {
|
|||
};
|
||||
|
||||
Viewer.prototype.createModdle = function() {
|
||||
return new BpmnModdle();
|
||||
var options = this.options;
|
||||
return options.moddle || new BpmnModdle(options.moddleExtensions);
|
||||
};
|
||||
|
||||
Viewer.prototype.saveSVG = function(options, done) {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://activiti.org/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_FVEpwO_VEeOtYvXzz5ksgw" exporter="camunda modeler" exporterVersion="2.5.0" targetNamespace="http://activiti.org/bpmn">
|
||||
<bpmn2:process id="testProcess" isExecutable="true">
|
||||
<bpmn2:startEvent id="StartEvent_1">
|
||||
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
|
||||
</bpmn2:startEvent>
|
||||
<bpmn2:sendTask id="send" name="send">
|
||||
<bpmn2:extensionElements>
|
||||
<camunda:inputOutput>
|
||||
<camunda:inputParameter name="var1">
|
||||
<camunda:map>
|
||||
<camunda:entry key="a">
|
||||
<camunda:list>
|
||||
<camunda:value>stringInListNestedInMap</camunda:value>
|
||||
<camunda:value>${ 'b' }</camunda:value>
|
||||
</camunda:list>
|
||||
</camunda:entry>
|
||||
</camunda:map>
|
||||
</camunda:inputParameter>
|
||||
<camunda:inputParameter name="var2">stringConstantValue</camunda:inputParameter>
|
||||
</camunda:inputOutput>
|
||||
</bpmn2:extensionElements>
|
||||
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
|
||||
<bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
|
||||
</bpmn2:sendTask>
|
||||
<bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="StartEvent_1" targetRef="send"/>
|
||||
<bpmn2:endEvent id="EndEvent_1">
|
||||
<bpmn2:incoming>SequenceFlow_2</bpmn2:incoming>
|
||||
</bpmn2:endEvent>
|
||||
<bpmn2:sequenceFlow id="SequenceFlow_2" name="" sourceRef="send" targetRef="EndEvent_1"/>
|
||||
</bpmn2:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="testProcess">
|
||||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
|
||||
<dc:Bounds height="36.0" width="36.0" x="128.0" y="178.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="_BPMNShape_UserTask_2" bpmnElement="send">
|
||||
<dc:Bounds height="80.0" width="100.0" x="214.0" y="156.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow_1" sourceElement="_BPMNShape_StartEvent_2" targetElement="_BPMNShape_UserTask_2">
|
||||
<di:waypoint xsi:type="dc:Point" x="164.0" y="196.0"/>
|
||||
<di:waypoint xsi:type="dc:Point" x="214.0" y="196.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNShape id="_BPMNShape_EndEvent_2" bpmnElement="EndEvent_1">
|
||||
<dc:Bounds height="36.0" width="36.0" x="364.0" y="178.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_2" bpmnElement="SequenceFlow_2" sourceElement="_BPMNShape_UserTask_2" targetElement="_BPMNShape_EndEvent_2">
|
||||
<di:waypoint xsi:type="dc:Point" x="314.0" y="196.0"/>
|
||||
<di:waypoint xsi:type="dc:Point" x="364.0" y="196.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn2:definitions>
|
|
@ -0,0 +1,224 @@
|
|||
{
|
||||
"name": "Camunda",
|
||||
"uri": "http://activiti.org/bpmn",
|
||||
"prefix": "camunda",
|
||||
"xml": {
|
||||
"tagAlias": "lowerCase"
|
||||
},
|
||||
"associations": [],
|
||||
"types": [
|
||||
{
|
||||
"name": "AsyncCapable",
|
||||
"isAbstract": true,
|
||||
"extends": [
|
||||
"bpmn:Activity",
|
||||
"bpmn:Gateway",
|
||||
"bpmn:Event"
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "asyncBefore",
|
||||
"isAttr": true,
|
||||
"type": "Boolean",
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"name": "asyncAfter",
|
||||
"isAttr": true,
|
||||
"type": "Boolean",
|
||||
"default": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Assignable",
|
||||
"extends": [ "bpmn:UserTask" ],
|
||||
"properties": [
|
||||
{
|
||||
"name": "assignee",
|
||||
"isAttr": true,
|
||||
"type": "String"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Calling",
|
||||
"extends": [ "bpmn:CallActivity" ],
|
||||
"properties": [
|
||||
{
|
||||
"name": "calledElementBinding",
|
||||
"isAttr": true,
|
||||
"type": "String"
|
||||
},
|
||||
{
|
||||
"name": "calledElementVersion",
|
||||
"isAttr": true,
|
||||
"type": "Integer"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ServiceTaskLike",
|
||||
"extends": [
|
||||
"bpmn:ServiceTask",
|
||||
"bpmn:BusinessRuleTask",
|
||||
"bpmn:SendTask",
|
||||
"bpmn:MessageEventDefinition"
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "expression",
|
||||
"isAttr": true,
|
||||
"type": "String"
|
||||
},
|
||||
{
|
||||
"name": "javaDelegate",
|
||||
"isAttr": true,
|
||||
"type": "String"
|
||||
},
|
||||
{
|
||||
"name": "delegateExpression",
|
||||
"isAttr": true,
|
||||
"type": "String"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Connector",
|
||||
"superClass": [
|
||||
"Element"
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "inputOutput",
|
||||
"type": "InputOutput"
|
||||
},
|
||||
{
|
||||
"name": "connectorId",
|
||||
"type": "String"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "InputOutput",
|
||||
"superClass": [
|
||||
"Element"
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "inputOutput",
|
||||
"type": "InputOutput"
|
||||
},
|
||||
{
|
||||
"name": "connectorId",
|
||||
"type": "String"
|
||||
},
|
||||
{
|
||||
"name": "inputParameters",
|
||||
"isMany": true,
|
||||
"type": "InputParameter"
|
||||
},
|
||||
{
|
||||
"name": "outputParameters",
|
||||
"isMany": true,
|
||||
"type": "OutputParameter"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "InputOutputParameter",
|
||||
"properties": [
|
||||
{
|
||||
"name": "name",
|
||||
"isAttr": true,
|
||||
"type": "String"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"isBody": true,
|
||||
"type": "String"
|
||||
},
|
||||
{
|
||||
"name": "definition",
|
||||
"type": "InputOutputParameterDefinition"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "InputOutputParameterDefinition",
|
||||
"isAbstract": true
|
||||
},
|
||||
{
|
||||
"name": "List",
|
||||
"superClass": [ "InputOutputParameterDefinition" ],
|
||||
"properties": [
|
||||
{
|
||||
"name": "items",
|
||||
"isMany": true,
|
||||
"type": "InputOutputParameterDefinition"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Map",
|
||||
"superClass": [ "InputOutputParameterDefinition" ],
|
||||
"properties": [
|
||||
{
|
||||
"name": "entries",
|
||||
"isMany": true,
|
||||
"type": "Entry"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Entry",
|
||||
"properties": [
|
||||
{
|
||||
"name": "key",
|
||||
"isAttr": true,
|
||||
"type": "String"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "InputOutputParameterDefinition"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Value",
|
||||
"superClass": [ "InputOutputParameterDefinition" ],
|
||||
"properties": [
|
||||
{
|
||||
"name": "value",
|
||||
"isBody": true,
|
||||
"type": "String"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Script",
|
||||
"superClass": [ "InputOutputParameterDefinition" ],
|
||||
"properties": [
|
||||
{
|
||||
"name": "scriptLanguage",
|
||||
"isAttr": true,
|
||||
"type": "String"
|
||||
},
|
||||
{
|
||||
"name": "source",
|
||||
"isBody": true,
|
||||
"type": "String"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "InputParameter",
|
||||
"superClass": [ "InputOutputParameter" ]
|
||||
},
|
||||
{
|
||||
"name": "OutputParameter",
|
||||
"superClass": [ "InputOutputParameter" ]
|
||||
}
|
||||
],
|
||||
"emumerations": [ ]
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var TestHelper = require('../TestHelper');
|
||||
require('../TestHelper');
|
||||
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
|
@ -96,9 +97,6 @@ describe('Viewer', function() {
|
|||
expect(overlays).toBeDefined();
|
||||
expect(elementRegistry).toBeDefined();
|
||||
|
||||
// given
|
||||
var subProcessShape = elementRegistry.get('SubProcess_1');
|
||||
|
||||
// when
|
||||
overlays.add('SubProcess_1', {
|
||||
position: {
|
||||
|
@ -270,6 +268,7 @@ describe('Viewer', function() {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
it('should remove outer-makers on export', function(done) {
|
||||
|
||||
// given
|
||||
|
@ -387,6 +386,48 @@ describe('Viewer', function() {
|
|||
expect(viewer.container.style.height).toBe('100px');
|
||||
});
|
||||
|
||||
|
||||
var camundaPackage = require('../fixtures/json/model/camunda');
|
||||
|
||||
it('should provide custom moddle extensions', function(done) {
|
||||
|
||||
var xml = fs.readFileSync('test/fixtures/bpmn/extension/camunda.bpmn', 'utf8');
|
||||
|
||||
// given
|
||||
viewer = new Viewer({
|
||||
container: container,
|
||||
moddleExtensions: {
|
||||
camunda: camundaPackage
|
||||
}
|
||||
});
|
||||
|
||||
// when
|
||||
viewer.importXML(xml, function(err, warnings) {
|
||||
|
||||
var elementRegistry = viewer.get('elementRegistry');
|
||||
|
||||
var taskShape = elementRegistry.get('send'),
|
||||
sendTask = taskShape.businessObject;
|
||||
|
||||
// then
|
||||
expect(sendTask).toBeDefined();
|
||||
|
||||
var extensionElements = sendTask.extensionElements;
|
||||
|
||||
// receive task should be moddle extended
|
||||
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).toBeTruthy();
|
||||
|
||||
// extension elements should provide typed element
|
||||
expect(extensionElements).toBeTruthy();
|
||||
|
||||
expect(extensionElements.values.length).toBe(1);
|
||||
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).toBeTruthy();
|
||||
|
||||
done(err);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue