chore(Viewer): type BPMNDiagram arg where possible
This commit is contained in:
parent
3f0583ad5f
commit
daee95743d
|
@ -70,15 +70,14 @@ function ensureUnit(val) {
|
|||
|
||||
|
||||
/**
|
||||
*
|
||||
* Find BPMNDiagram in definitions by ID
|
||||
*
|
||||
* @param {ModdleElement} definitions
|
||||
* @param {ModdleElement<Definitions>} definitions
|
||||
* @param {String} diagramId
|
||||
*
|
||||
* @return {Diagram|null}
|
||||
* @return {ModdleElement<BPMNDiagram>|null}
|
||||
*/
|
||||
function findDiagram(definitions, diagramId) {
|
||||
function findBPMNDiagram(definitions, diagramId) {
|
||||
if (!diagramId) {
|
||||
return null;
|
||||
}
|
||||
|
@ -174,14 +173,14 @@ inherits(Viewer, Diagram);
|
|||
* You can use these events to hook into the life-cycle.
|
||||
*
|
||||
* @param {String} xml the BPMN 2.0 xml
|
||||
* @param {String} [diagramId] id of the diagram to render (if not provided, the first one will be rendered)
|
||||
* @param {ModdleElement<BPMNDiagram>|String} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
|
||||
* @param {Function} [done] invoked with (err, warnings=[])
|
||||
*/
|
||||
Viewer.prototype.importXML = function(xml, diagramId, done) {
|
||||
Viewer.prototype.importXML = function(xml, bpmnDiagram, done) {
|
||||
|
||||
if (isFunction(diagramId)) {
|
||||
done = diagramId;
|
||||
diagramId = null;
|
||||
if (isFunction(bpmnDiagram)) {
|
||||
done = bpmnDiagram;
|
||||
bpmnDiagram = null;
|
||||
}
|
||||
|
||||
// done is optional
|
||||
|
@ -215,7 +214,7 @@ Viewer.prototype.importXML = function(xml, diagramId, done) {
|
|||
|
||||
self._setDefinitions(definitions);
|
||||
|
||||
self.open(diagramId, function(err, importWarnings) {
|
||||
self.open(bpmnDiagram, function(err, importWarnings) {
|
||||
var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
||||
|
||||
self._emit('import.done', { error: err, warnings: allWarnings });
|
||||
|
@ -240,17 +239,18 @@ Viewer.prototype.importXML = function(xml, diagramId, done) {
|
|||
*
|
||||
* You can use these events to hook into the life-cycle.
|
||||
*
|
||||
* @param {String|Diagram} [diagram] id or the diagram to open
|
||||
* @param {String|ModdleElement<BPMNDiagram>} [bpmnDiagramOrId] id or the diagram to open
|
||||
* @param {Function} [done] invoked with (err, warnings=[])
|
||||
*/
|
||||
Viewer.prototype.open = function(diagram, done) {
|
||||
Viewer.prototype.open = function(bpmnDiagramOrId, done) {
|
||||
|
||||
if (isFunction(diagram)) {
|
||||
done = diagram;
|
||||
diagram = null;
|
||||
if (isFunction(bpmnDiagramOrId)) {
|
||||
done = bpmnDiagramOrId;
|
||||
bpmnDiagramOrId = null;
|
||||
}
|
||||
|
||||
var definitions = this._definitions;
|
||||
var bpmnDiagram = bpmnDiagramOrId;
|
||||
|
||||
// done is optional
|
||||
done = done || function() {};
|
||||
|
@ -259,24 +259,24 @@ Viewer.prototype.open = function(diagram, done) {
|
|||
return done(new Error('no XML imported'));
|
||||
}
|
||||
|
||||
if (typeof diagram === 'string') {
|
||||
diagram = findDiagram(definitions, diagram);
|
||||
if (typeof bpmnDiagramOrId === 'string') {
|
||||
bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
|
||||
|
||||
if (!diagram) {
|
||||
return done(new Error('no diagram to display'));
|
||||
if (!bpmnDiagram) {
|
||||
return done(new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found'));
|
||||
}
|
||||
}
|
||||
|
||||
// clear existing rendered diagram
|
||||
// catch synchronous exceptions during #clear()
|
||||
try {
|
||||
// clear existing rendered diagram
|
||||
this.clear();
|
||||
} catch (error) {
|
||||
return done(error);
|
||||
}
|
||||
|
||||
// perform graphical import
|
||||
return importBpmnDiagram(this, definitions, diagram, done);
|
||||
return importBpmnDiagram(this, definitions, bpmnDiagram, done);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,17 +9,17 @@ import {
|
|||
*
|
||||
* Errors and warnings are reported through the specified callback.
|
||||
*
|
||||
* @param {Diagram} diagram
|
||||
* @param {ModdleElement} definitions
|
||||
* @param {ModdleElement} [selectedDiagram] the BPMNDiagram element selected to be rendered
|
||||
* @param {djs.Diagram} diagram
|
||||
* @param {ModdleElement<Definitions>} definitions
|
||||
* @param {ModdleElement<BPMNDiagram>} [bpmnDiagram] the diagram to be rendered
|
||||
* (if not provided, the first one will be rendered)
|
||||
* @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done
|
||||
*/
|
||||
export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) {
|
||||
export function importBpmnDiagram(diagram, definitions, bpmnDiagram, done) {
|
||||
|
||||
if (isFunction(selectedDiagram)) {
|
||||
done = selectedDiagram;
|
||||
selectedDiagram = null;
|
||||
if (isFunction(bpmnDiagram)) {
|
||||
done = bpmnDiagram;
|
||||
bpmnDiagram = null;
|
||||
}
|
||||
|
||||
var importer,
|
||||
|
@ -33,10 +33,10 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) {
|
|||
* Walk the diagram semantically, importing (=drawing)
|
||||
* all elements you encounter.
|
||||
*
|
||||
* @param {ModdleElement} definitions
|
||||
* @param {ModdleElement} selectedDiagram
|
||||
* @param {ModdleElement<Definitions>} definitions
|
||||
* @param {ModdleElement<BPMNDiagram>} bpmnDiagram
|
||||
*/
|
||||
function render(definitions, selectedDiagram) {
|
||||
function render(definitions, bpmnDiagram) {
|
||||
|
||||
var visitor = {
|
||||
|
||||
|
@ -57,7 +57,7 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) {
|
|||
|
||||
// traverse BPMN 2.0 document model,
|
||||
// starting at definitions
|
||||
walker.handleDefinitions(definitions, selectedDiagram);
|
||||
walker.handleDefinitions(definitions, bpmnDiagram);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -67,7 +67,7 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) {
|
|||
|
||||
eventBus.fire('import.render.start', { definitions: definitions });
|
||||
|
||||
render(definitions, selectedDiagram);
|
||||
render(definitions, bpmnDiagram);
|
||||
|
||||
eventBus.fire('import.render.complete', {
|
||||
error: error,
|
||||
|
|
Loading…
Reference in New Issue