mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-11 17:44:12 +00:00
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
|
* Find BPMNDiagram in definitions by ID
|
||||||
*
|
*
|
||||||
* @param {ModdleElement} definitions
|
* @param {ModdleElement<Definitions>} definitions
|
||||||
* @param {String} diagramId
|
* @param {String} diagramId
|
||||||
*
|
*
|
||||||
* @return {Diagram|null}
|
* @return {ModdleElement<BPMNDiagram>|null}
|
||||||
*/
|
*/
|
||||||
function findDiagram(definitions, diagramId) {
|
function findBPMNDiagram(definitions, diagramId) {
|
||||||
if (!diagramId) {
|
if (!diagramId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -174,14 +173,14 @@ inherits(Viewer, Diagram);
|
|||||||
* You can use these events to hook into the life-cycle.
|
* You can use these events to hook into the life-cycle.
|
||||||
*
|
*
|
||||||
* @param {String} xml the BPMN 2.0 xml
|
* @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=[])
|
* @param {Function} [done] invoked with (err, warnings=[])
|
||||||
*/
|
*/
|
||||||
Viewer.prototype.importXML = function(xml, diagramId, done) {
|
Viewer.prototype.importXML = function(xml, bpmnDiagram, done) {
|
||||||
|
|
||||||
if (isFunction(diagramId)) {
|
if (isFunction(bpmnDiagram)) {
|
||||||
done = diagramId;
|
done = bpmnDiagram;
|
||||||
diagramId = null;
|
bpmnDiagram = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// done is optional
|
// done is optional
|
||||||
@ -215,7 +214,7 @@ Viewer.prototype.importXML = function(xml, diagramId, done) {
|
|||||||
|
|
||||||
self._setDefinitions(definitions);
|
self._setDefinitions(definitions);
|
||||||
|
|
||||||
self.open(diagramId, function(err, importWarnings) {
|
self.open(bpmnDiagram, function(err, importWarnings) {
|
||||||
var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
||||||
|
|
||||||
self._emit('import.done', { error: err, warnings: allWarnings });
|
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.
|
* 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=[])
|
* @param {Function} [done] invoked with (err, warnings=[])
|
||||||
*/
|
*/
|
||||||
Viewer.prototype.open = function(diagram, done) {
|
Viewer.prototype.open = function(bpmnDiagramOrId, done) {
|
||||||
|
|
||||||
if (isFunction(diagram)) {
|
if (isFunction(bpmnDiagramOrId)) {
|
||||||
done = diagram;
|
done = bpmnDiagramOrId;
|
||||||
diagram = null;
|
bpmnDiagramOrId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var definitions = this._definitions;
|
var definitions = this._definitions;
|
||||||
|
var bpmnDiagram = bpmnDiagramOrId;
|
||||||
|
|
||||||
// done is optional
|
// done is optional
|
||||||
done = done || function() {};
|
done = done || function() {};
|
||||||
@ -259,24 +259,24 @@ Viewer.prototype.open = function(diagram, done) {
|
|||||||
return done(new Error('no XML imported'));
|
return done(new Error('no XML imported'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof diagram === 'string') {
|
if (typeof bpmnDiagramOrId === 'string') {
|
||||||
diagram = findDiagram(definitions, diagram);
|
bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
|
||||||
|
|
||||||
if (!diagram) {
|
if (!bpmnDiagram) {
|
||||||
return done(new Error('no diagram to display'));
|
return done(new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear existing rendered diagram
|
||||||
// catch synchronous exceptions during #clear()
|
// catch synchronous exceptions during #clear()
|
||||||
try {
|
try {
|
||||||
// clear existing rendered diagram
|
|
||||||
this.clear();
|
this.clear();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return done(error);
|
return done(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform graphical import
|
// 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.
|
* Errors and warnings are reported through the specified callback.
|
||||||
*
|
*
|
||||||
* @param {Diagram} diagram
|
* @param {djs.Diagram} diagram
|
||||||
* @param {ModdleElement} definitions
|
* @param {ModdleElement<Definitions>} definitions
|
||||||
* @param {ModdleElement} [selectedDiagram] the BPMNDiagram element selected to be rendered
|
* @param {ModdleElement<BPMNDiagram>} [bpmnDiagram] the diagram to be rendered
|
||||||
* (if not provided, the first one will 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
|
* @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)) {
|
if (isFunction(bpmnDiagram)) {
|
||||||
done = selectedDiagram;
|
done = bpmnDiagram;
|
||||||
selectedDiagram = null;
|
bpmnDiagram = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var importer,
|
var importer,
|
||||||
@ -33,10 +33,10 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) {
|
|||||||
* Walk the diagram semantically, importing (=drawing)
|
* Walk the diagram semantically, importing (=drawing)
|
||||||
* all elements you encounter.
|
* all elements you encounter.
|
||||||
*
|
*
|
||||||
* @param {ModdleElement} definitions
|
* @param {ModdleElement<Definitions>} definitions
|
||||||
* @param {ModdleElement} selectedDiagram
|
* @param {ModdleElement<BPMNDiagram>} bpmnDiagram
|
||||||
*/
|
*/
|
||||||
function render(definitions, selectedDiagram) {
|
function render(definitions, bpmnDiagram) {
|
||||||
|
|
||||||
var visitor = {
|
var visitor = {
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) {
|
|||||||
|
|
||||||
// traverse BPMN 2.0 document model,
|
// traverse BPMN 2.0 document model,
|
||||||
// starting at definitions
|
// starting at definitions
|
||||||
walker.handleDefinitions(definitions, selectedDiagram);
|
walker.handleDefinitions(definitions, bpmnDiagram);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -67,7 +67,7 @@ export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) {
|
|||||||
|
|
||||||
eventBus.fire('import.render.start', { definitions: definitions });
|
eventBus.fire('import.render.start', { definitions: definitions });
|
||||||
|
|
||||||
render(definitions, selectedDiagram);
|
render(definitions, bpmnDiagram);
|
||||||
|
|
||||||
eventBus.fire('import.render.complete', {
|
eventBus.fire('import.render.complete', {
|
||||||
error: error,
|
error: error,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user