Comparing version 0.13.2 to 0.13.3
@@ -8,11 +8,23 @@ 'use strict'; | ||
* A handler that updates the text of a BPMN element. | ||
* | ||
* @param {EventBus} eventBus | ||
*/ | ||
function UpdateTextHandler(eventBus) { | ||
function UpdateLabelHandler() { | ||
/** | ||
* Set the label and return the changed elements. | ||
* | ||
* Element parameter can be label itself or connection (i.e. sequence flow). | ||
* | ||
* @param {djs.model.Base} element | ||
* @param {String} text | ||
*/ | ||
function setText(element, text) { | ||
var label = LabelUtil.setLabel(element, text); | ||
eventBus.fire('element.changed', { element: label }); | ||
// external label if present | ||
var label = element.label || element; | ||
var labelTarget = element.labelTarget || element; | ||
LabelUtil.setLabel(label, text, labelTarget !== label); | ||
return [ label, labelTarget ]; | ||
} | ||
@@ -29,7 +41,2 @@ | ||
function canExecute(ctx) { | ||
return true; | ||
} | ||
// API | ||
@@ -39,9 +46,4 @@ | ||
this.revert = revert; | ||
this.canExecute = canExecute; | ||
} | ||
UpdateTextHandler.$inject = [ 'eventBus' ]; | ||
module.exports = UpdateTextHandler; | ||
module.exports = UpdateLabelHandler; |
@@ -30,3 +30,3 @@ 'use strict'; | ||
module.exports.setLabel = function(element, text) { | ||
module.exports.setLabel = function(element, text, isExternal) { | ||
var semantic = element.businessObject, | ||
@@ -39,8 +39,8 @@ attr = getLabelAttr(semantic); | ||
var label = element.label || element; | ||
// show external label if not empty | ||
if (isExternal) { | ||
element.hidden = !text; | ||
} | ||
// show label | ||
label.hidden = false; | ||
return label; | ||
return element; | ||
}; |
@@ -44,2 +44,5 @@ 'use strict'; | ||
context.oldRoot = oldRoot; | ||
// TODO(nikku): return changed elements? | ||
// return [ newRoot, oldRoot ]; | ||
}; | ||
@@ -74,2 +77,5 @@ | ||
oldRootBusinessObject.di = diPlane; | ||
// TODO(nikku): return changed elements? | ||
// return [ newRoot, oldRoot ]; | ||
}; |
@@ -156,2 +156,5 @@ 'use strict'; | ||
}); | ||
// TODO(nikku): return changed elements | ||
// return [ ... ]; | ||
}; | ||
@@ -181,2 +184,5 @@ | ||
}); | ||
// TODO(nikku): return changed elements | ||
// return [ ... ]; | ||
}; |
@@ -149,6 +149,6 @@ /** | ||
* Import and render a BPMN 2.0 diagram. | ||
* | ||
* | ||
* Once finished the viewer reports back the result to the | ||
* provided callback function with (err, warnings). | ||
* | ||
* | ||
* @param {String} xml the BPMN 2.0 xml | ||
@@ -183,7 +183,7 @@ * @param {Function} done invoked with (err, warnings=[]) | ||
* a BPMN 2.0 XML document. | ||
* | ||
* | ||
* @param {Object} [options] export options | ||
* @param {Boolean} [options.format=false] output formated XML | ||
* @param {Boolean} [options.preamble=true] output preamble | ||
* | ||
* | ||
* @param {Function} done invoked with (err, xml) | ||
@@ -208,3 +208,3 @@ */ | ||
Viewer.prototype.createModdle = function() { | ||
return new BpmnModdle(this.options.moddleExtensions); | ||
return new BpmnModdle(assign({}, this._moddleExtensions, this.options.moddleExtensions)); | ||
}; | ||
@@ -215,3 +215,3 @@ | ||
* an SVG image. | ||
* | ||
* | ||
* @param {Object} [options] | ||
@@ -252,10 +252,10 @@ * @param {Function} done invoked with (err, svgStr) | ||
* Get a named diagram service. | ||
* | ||
* | ||
* @example | ||
* | ||
* | ||
* var elementRegistry = viewer.get('elementRegistry'); | ||
* var startEventShape = elementRegistry.get('StartEvent_1'); | ||
* | ||
* | ||
* @param {String} name | ||
* | ||
* | ||
* @return {Object} diagram service instance | ||
@@ -274,11 +274,11 @@ */ | ||
* Invoke a function in the context of this viewer. | ||
* | ||
* | ||
* @example | ||
* | ||
* | ||
* viewer.invoke(function(elementRegistry) { | ||
* var startEventShape = elementRegistry.get('StartEvent_1'); | ||
* }); | ||
* | ||
* | ||
* @param {Function} fn to be invoked | ||
* | ||
* | ||
* @return {Object} the functions return value | ||
@@ -375,3 +375,3 @@ */ | ||
* Remove a previously added listener via {@link #off(event, callback)}. | ||
* | ||
* | ||
* @param {String} event | ||
@@ -391,3 +391,3 @@ * @param {Number} [priority] | ||
} | ||
listeners.push({ event: event, priority: priority, callback: callback, that: that }); | ||
@@ -409,3 +409,3 @@ | ||
diagram = this.diagram; | ||
if (callback) { | ||
@@ -420,5 +420,5 @@ filter = function(l) { | ||
} | ||
this.__listeners = (this.__listeners || []).filter(filter); | ||
if (diagram) { | ||
@@ -436,2 +436,4 @@ diagram.get('eventBus').off(event, callback); | ||
// default moddle extensions the viewer is composed of | ||
Viewer.prototype._moddleExtensions = {}; | ||
@@ -438,0 +440,0 @@ /* <project-logo> */ |
{ | ||
"name": "bpmn-js", | ||
"version": "0.13.2", | ||
"version": "0.13.3", | ||
"description": "A bpmn 2.0 toolkit and web modeler", | ||
@@ -68,3 +68,3 @@ "scripts": { | ||
"bpmn-moddle": "^0.10.4", | ||
"diagram-js": "^0.13.2", | ||
"diagram-js": "^0.13.3", | ||
"diagram-js-direct-editing": "^0.13.0", | ||
@@ -71,0 +71,0 @@ "ids": "^0.1.2", |
@@ -7,3 +7,5 @@ 'use strict'; | ||
var inherits = require('inherits'); | ||
describe('Viewer', function() { | ||
@@ -535,3 +537,3 @@ | ||
// receive task should be moddle extended | ||
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).to.exist; | ||
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).to.be.true; | ||
@@ -542,3 +544,3 @@ // extension elements should provide typed element | ||
expect(extensionElements.values.length).to.equal(1); | ||
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.exist; | ||
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true; | ||
@@ -551,2 +553,112 @@ done(err); | ||
it('should allow to add default custom moddle extensions', function(done) { | ||
// given | ||
var xml = require('../fixtures/bpmn/extension/custom.bpmn'), | ||
additionalModdleDescriptors = { | ||
custom: require('../fixtures/json/model/custom') | ||
}; | ||
function CustomViewer(options) { | ||
Viewer.call(this, options); | ||
} | ||
inherits(CustomViewer, Viewer); | ||
CustomViewer.prototype._moddleExtensions = additionalModdleDescriptors; | ||
viewer = new CustomViewer({ | ||
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).to.exist; | ||
var extensionElements = sendTask.extensionElements; | ||
// receive task should be moddle extended | ||
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).to.be.true; | ||
expect(sendTask.$instanceOf('custom:ServiceTaskGroup')).to.be.true; | ||
// extension elements should provide typed element | ||
expect(extensionElements).to.exist; | ||
expect(extensionElements.values.length).to.equal(2); | ||
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true; | ||
expect(extensionElements.values[1].$instanceOf('custom:CustomSendElement')).to.be.true; | ||
done(err); | ||
}); | ||
}); | ||
it('should allow user to override default custom moddle extensions', function(done) { | ||
// given | ||
var xml = require('../fixtures/bpmn/extension/custom-override.bpmn'), | ||
additionalModdleDescriptors = { | ||
custom: require('../fixtures/json/model/custom') | ||
}, | ||
customOverride = require('../fixtures/json/model/custom-override'); | ||
function CustomViewer(options) { | ||
Viewer.call(this, options); | ||
} | ||
inherits(CustomViewer, Viewer); | ||
CustomViewer.prototype._moddleExtensions = additionalModdleDescriptors; | ||
viewer = new CustomViewer({ | ||
container: container, | ||
moddleExtensions: { | ||
camunda: camundaPackage, | ||
custom : customOverride | ||
} | ||
}); | ||
// when | ||
viewer.importXML(xml, function(err, warnings) { | ||
var elementRegistry = viewer.get('elementRegistry'); | ||
var taskShape = elementRegistry.get('send'), | ||
sendTask = taskShape.businessObject; | ||
// then | ||
expect(sendTask).to.exist; | ||
var extensionElements = sendTask.extensionElements; | ||
// receive task should be moddle extended | ||
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).to.be.true; | ||
expect(sendTask.$instanceOf('custom:ServiceTaskGroupOverride')).to.be.true; | ||
// extension elements should provide typed element | ||
expect(extensionElements).to.exist; | ||
expect(extensionElements.values.length).to.equal(2); | ||
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true; | ||
expect(extensionElements.values[1].$instanceOf('custom:CustomSendElementOverride')).to.be.true; | ||
done(err); | ||
}); | ||
}); | ||
it('should throw error due to missing diagram', function(done) { | ||
@@ -553,0 +665,0 @@ |
1900260
325
21302
Updateddiagram-js@^0.13.3