bpmn-js 9.4.1 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * bpmn-js - bpmn-viewer v9.4.1
2
+ * bpmn-js - bpmn-viewer v10.0.0
3
3
  *
4
4
  * Copyright (c) 2014-present, camunda Services GmbH
5
5
  *
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Source Code: https://github.com/bpmn-io/bpmn-js
10
10
  *
11
- * Date: 2022-09-05
11
+ * Date: 2022-09-20
12
12
  */
13
13
  (function (global, factory) {
14
14
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -20922,13 +20922,13 @@
20922
20922
  *
20923
20923
  * Returns {Promise<ImportXMLResult, ImportXMLError>}
20924
20924
  */
20925
- BaseViewer.prototype.importXML = wrapForCompatibility(function importXML(xml, bpmnDiagram) {
20925
+ BaseViewer.prototype.importXML = wrapForCompatibility(async function importXML(xml, bpmnDiagram) {
20926
20926
 
20927
- var self = this;
20927
+ const self = this;
20928
20928
 
20929
20929
  function ParseCompleteEvent(data) {
20930
20930
 
20931
- var event = self.get('eventBus').createEvent(data);
20931
+ const event = self.get('eventBus').createEvent(data);
20932
20932
 
20933
20933
  // TODO(nikku): remove with future bpmn-js version
20934
20934
  Object.defineProperty(event, 'context', {
@@ -20951,54 +20951,59 @@
20951
20951
  return event;
20952
20952
  }
20953
20953
 
20954
- return new Promise(function(resolve, reject) {
20954
+ let aggregatedWarnings = [];
20955
+ try {
20955
20956
 
20956
20957
  // hook in pre-parse listeners +
20957
20958
  // allow xml manipulation
20958
- xml = self._emit('import.parse.start', { xml: xml }) || xml;
20959
-
20960
- self._moddle.fromXML(xml, 'bpmn:Definitions').then(function(result) {
20961
- var definitions = result.rootElement;
20962
- var references = result.references;
20963
- var parseWarnings = result.warnings;
20964
- var elementsById = result.elementsById;
20965
-
20966
- // hook in post parse listeners +
20967
- // allow definitions manipulation
20968
- definitions = self._emit('import.parse.complete', ParseCompleteEvent({
20969
- error: null,
20970
- definitions: definitions,
20971
- elementsById: elementsById,
20972
- references: references,
20973
- warnings: parseWarnings
20974
- })) || definitions;
20959
+ xml = this._emit('import.parse.start', { xml: xml }) || xml;
20975
20960
 
20976
- self.importDefinitions(definitions, bpmnDiagram).then(function(result) {
20977
- var allWarnings = [].concat(parseWarnings, result.warnings || []);
20961
+ let parseResult;
20962
+ try {
20963
+ parseResult = await this._moddle.fromXML(xml, 'bpmn:Definitions');
20964
+ } catch (error) {
20965
+ this._emit('import.parse.complete', {
20966
+ error
20967
+ });
20978
20968
 
20979
- self._emit('import.done', { error: null, warnings: allWarnings });
20969
+ throw error;
20970
+ }
20980
20971
 
20981
- return resolve({ warnings: allWarnings });
20982
- }).catch(function(err) {
20983
- var allWarnings = [].concat(parseWarnings, err.warnings || []);
20972
+ let definitions = parseResult.rootElement;
20973
+ const references = parseResult.references;
20974
+ const parseWarnings = parseResult.warnings;
20975
+ const elementsById = parseResult.elementsById;
20984
20976
 
20985
- self._emit('import.done', { error: err, warnings: allWarnings });
20977
+ aggregatedWarnings = aggregatedWarnings.concat(parseWarnings);
20986
20978
 
20987
- return reject(addWarningsToError(err, allWarnings));
20988
- });
20989
- }).catch(function(err) {
20979
+ // hook in post parse listeners +
20980
+ // allow definitions manipulation
20981
+ definitions = this._emit('import.parse.complete', ParseCompleteEvent({
20982
+ error: null,
20983
+ definitions: definitions,
20984
+ elementsById: elementsById,
20985
+ references: references,
20986
+ warnings: aggregatedWarnings
20987
+ })) || definitions;
20990
20988
 
20991
- self._emit('import.parse.complete', {
20992
- error: err
20993
- });
20989
+ const importResult = await this.importDefinitions(definitions, bpmnDiagram);
20994
20990
 
20995
- err = checkValidationError(err);
20991
+ aggregatedWarnings = aggregatedWarnings.concat(importResult.warnings);
20996
20992
 
20997
- self._emit('import.done', { error: err, warnings: err.warnings });
20993
+ this._emit('import.done', { error: null, warnings: aggregatedWarnings });
20998
20994
 
20999
- return reject(err);
21000
- });
21001
- });
20995
+ return { warnings: aggregatedWarnings };
20996
+ } catch (err) {
20997
+ let error = err;
20998
+ aggregatedWarnings = aggregatedWarnings.concat(error.warnings || []);
20999
+ addWarningsToError(error, aggregatedWarnings);
21000
+
21001
+ error = checkValidationError(error);
21002
+
21003
+ this._emit('import.done', { error, warnings: error.warnings });
21004
+
21005
+ throw error;
21006
+ }
21002
21007
  });
21003
21008
 
21004
21009
  /**
@@ -21037,24 +21042,11 @@
21037
21042
  *
21038
21043
  * Returns {Promise<ImportDefinitionsResult, ImportDefinitionsError>}
21039
21044
  */
21040
- BaseViewer.prototype.importDefinitions = wrapForCompatibility(function importDefinitions(definitions, bpmnDiagram) {
21045
+ BaseViewer.prototype.importDefinitions = wrapForCompatibility(async function importDefinitions(definitions, bpmnDiagram) {
21046
+ this._setDefinitions(definitions);
21047
+ const result = await this.open(bpmnDiagram);
21041
21048
 
21042
- var self = this;
21043
-
21044
- return new Promise(function(resolve, reject) {
21045
-
21046
- self._setDefinitions(definitions);
21047
-
21048
- self.open(bpmnDiagram).then(function(result) {
21049
-
21050
- var warnings = result.warnings;
21051
-
21052
- return resolve({ warnings: warnings });
21053
- }).catch(function(err) {
21054
-
21055
- return reject(err);
21056
- });
21057
- });
21049
+ return { warnings: result.warnings };
21058
21050
  });
21059
21051
 
21060
21052
  /**
@@ -21092,50 +21084,43 @@
21092
21084
  *
21093
21085
  * Returns {Promise<OpenResult, OpenError>}
21094
21086
  */
21095
- BaseViewer.prototype.open = wrapForCompatibility(function open(bpmnDiagramOrId) {
21096
-
21097
- var definitions = this._definitions;
21098
- var bpmnDiagram = bpmnDiagramOrId;
21099
-
21100
- var self = this;
21087
+ BaseViewer.prototype.open = wrapForCompatibility(async function open(bpmnDiagramOrId) {
21101
21088
 
21102
- return new Promise(function(resolve, reject) {
21103
- if (!definitions) {
21104
- var err1 = new Error('no XML imported');
21089
+ const definitions = this._definitions;
21090
+ let bpmnDiagram = bpmnDiagramOrId;
21105
21091
 
21106
- return reject(addWarningsToError(err1, []));
21107
- }
21092
+ if (!definitions) {
21093
+ const error = new Error('no XML imported');
21094
+ addWarningsToError(error, []);
21108
21095
 
21109
- if (typeof bpmnDiagramOrId === 'string') {
21110
- bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
21096
+ throw error;
21097
+ }
21111
21098
 
21112
- if (!bpmnDiagram) {
21113
- var err2 = new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found');
21099
+ if (typeof bpmnDiagramOrId === 'string') {
21100
+ bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
21114
21101
 
21115
- return reject(addWarningsToError(err2, []));
21116
- }
21117
- }
21102
+ if (!bpmnDiagram) {
21103
+ const error = new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found');
21104
+ addWarningsToError(error, []);
21118
21105
 
21119
- // clear existing rendered diagram
21120
- // catch synchronous exceptions during #clear()
21121
- try {
21122
- self.clear();
21123
- } catch (error) {
21124
-
21125
- return reject(addWarningsToError(error, []));
21106
+ throw error;
21126
21107
  }
21108
+ }
21127
21109
 
21128
- // perform graphical import
21129
- importBpmnDiagram(self, definitions, bpmnDiagram).then(function(result) {
21110
+ // clear existing rendered diagram
21111
+ // catch synchronous exceptions during #clear()
21112
+ try {
21113
+ this.clear();
21114
+ } catch (error) {
21115
+ addWarningsToError(error, []);
21130
21116
 
21131
- var warnings = result.warnings;
21117
+ throw error;
21118
+ }
21132
21119
 
21133
- return resolve({ warnings: warnings });
21134
- }).catch(function(err) {
21120
+ // perform graphical import
21121
+ const { warnings } = await importBpmnDiagram(this, definitions, bpmnDiagram);
21135
21122
 
21136
- return reject(err);
21137
- });
21138
- });
21123
+ return { warnings };
21139
21124
  });
21140
21125
 
21141
21126
  /**
@@ -21166,53 +21151,42 @@
21166
21151
  *
21167
21152
  * Returns {Promise<SaveXMLResult, Error>}
21168
21153
  */
21169
- BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options) {
21154
+ BaseViewer.prototype.saveXML = wrapForCompatibility(async function saveXML(options) {
21170
21155
 
21171
21156
  options = options || {};
21172
21157
 
21173
- var self = this;
21174
-
21175
- var definitions = this._definitions;
21176
-
21177
- return new Promise(function(resolve) {
21158
+ let definitions = this._definitions,
21159
+ error, xml;
21178
21160
 
21161
+ try {
21179
21162
  if (!definitions) {
21180
- return resolve({
21181
- error: new Error('no definitions loaded')
21182
- });
21163
+ throw new Error('no definitions loaded');
21183
21164
  }
21184
21165
 
21185
21166
  // allow to fiddle around with definitions
21186
- definitions = self._emit('saveXML.start', {
21187
- definitions: definitions
21167
+ definitions = this._emit('saveXML.start', {
21168
+ definitions
21188
21169
  }) || definitions;
21189
21170
 
21190
- self._moddle.toXML(definitions, options).then(function(result) {
21191
-
21192
- var xml = result.xml;
21171
+ const result = await this._moddle.toXML(definitions, options);
21172
+ xml = result.xml;
21193
21173
 
21194
- xml = self._emit('saveXML.serialized', {
21195
- xml: xml
21196
- }) || xml;
21197
-
21198
- return resolve({
21199
- xml: xml
21200
- });
21201
- });
21202
- }).catch(function(error) {
21203
- return { error: error };
21204
- }).then(function(result) {
21174
+ xml = this._emit('saveXML.serialized', {
21175
+ xml
21176
+ }) || xml;
21177
+ } catch (err) {
21178
+ error = err;
21179
+ }
21205
21180
 
21206
- self._emit('saveXML.done', result);
21181
+ const result = error ? { error } : { xml };
21207
21182
 
21208
- var error = result.error;
21183
+ this._emit('saveXML.done', result);
21209
21184
 
21210
- if (error) {
21211
- return Promise.reject(error);
21212
- }
21185
+ if (error) {
21186
+ throw error;
21187
+ }
21213
21188
 
21214
- return result;
21215
- });
21189
+ return result;
21216
21190
  });
21217
21191
 
21218
21192
  /**
@@ -21240,51 +21214,45 @@
21240
21214
  *
21241
21215
  * Returns {Promise<SaveSVGResult, Error>}
21242
21216
  */
21243
- BaseViewer.prototype.saveSVG = wrapForCompatibility(function saveSVG(options) {
21244
-
21245
- var self = this;
21246
-
21247
- return new Promise(function(resolve, reject) {
21217
+ BaseViewer.prototype.saveSVG = wrapForCompatibility(async function saveSVG(options = {}) {
21218
+ this._emit('saveSVG.start');
21248
21219
 
21249
- self._emit('saveSVG.start');
21220
+ let svg, err;
21250
21221
 
21251
- var svg, err;
21252
-
21253
- try {
21254
- var canvas = self.get('canvas');
21222
+ try {
21223
+ const canvas = this.get('canvas');
21255
21224
 
21256
- var contentNode = canvas.getActiveLayer(),
21225
+ const contentNode = canvas.getActiveLayer(),
21257
21226
  defsNode = query('defs', canvas._svg);
21258
21227
 
21259
- var contents = innerSVG(contentNode),
21228
+ const contents = innerSVG(contentNode),
21260
21229
  defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
21261
21230
 
21262
- var bbox = contentNode.getBBox();
21263
-
21264
- svg =
21265
- '<?xml version="1.0" encoding="utf-8"?>\n' +
21266
- '<!-- created with bpmn-js / http://bpmn.io -->\n' +
21267
- '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
21268
- '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
21269
- 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
21270
- 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
21271
- defs + contents +
21272
- '</svg>';
21273
- } catch (e) {
21274
- err = e;
21275
- }
21231
+ const bbox = contentNode.getBBox();
21232
+
21233
+ svg =
21234
+ '<?xml version="1.0" encoding="utf-8"?>\n' +
21235
+ '<!-- created with bpmn-js / http://bpmn.io -->\n' +
21236
+ '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
21237
+ '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
21238
+ 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
21239
+ 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
21240
+ defs + contents +
21241
+ '</svg>';
21242
+ } catch (e) {
21243
+ err = e;
21244
+ }
21276
21245
 
21277
- self._emit('saveSVG.done', {
21278
- error: err,
21279
- svg: svg
21280
- });
21246
+ this._emit('saveSVG.done', {
21247
+ error: err,
21248
+ svg: svg
21249
+ });
21281
21250
 
21282
- if (!err) {
21283
- return resolve({ svg: svg });
21284
- }
21251
+ if (err) {
21252
+ throw err;
21253
+ }
21285
21254
 
21286
- return reject(err);
21287
- });
21255
+ return { svg };
21288
21256
  });
21289
21257
 
21290
21258
  /**
@@ -21292,8 +21260,8 @@
21292
21260
  *
21293
21261
  * @example
21294
21262
  *
21295
- * var elementRegistry = viewer.get('elementRegistry');
21296
- * var startEventShape = elementRegistry.get('StartEvent_1');
21263
+ * const elementRegistry = viewer.get('elementRegistry');
21264
+ * const startEventShape = elementRegistry.get('StartEvent_1');
21297
21265
  *
21298
21266
  * @param {string} name
21299
21267
  *
@@ -21308,7 +21276,7 @@
21308
21276
  * @example
21309
21277
  *
21310
21278
  * viewer.invoke(function(elementRegistry) {
21311
- * var startEventShape = elementRegistry.get('StartEvent_1');
21279
+ * const startEventShape = elementRegistry.get('StartEvent_1');
21312
21280
  * });
21313
21281
  *
21314
21282
  * @param {Function} fn to be invoked
@@ -21415,8 +21383,8 @@
21415
21383
 
21416
21384
  BaseViewer.prototype.detach = function() {
21417
21385
 
21418
- var container = this._container,
21419
- parentNode = container.parentNode;
21386
+ const container = this._container,
21387
+ parentNode = container.parentNode;
21420
21388
 
21421
21389
  if (!parentNode) {
21422
21390
  return;
@@ -21429,18 +21397,18 @@
21429
21397
 
21430
21398
  BaseViewer.prototype._init = function(container, moddle, options) {
21431
21399
 
21432
- var baseModules = options.modules || this.getModules(),
21433
- additionalModules = options.additionalModules || [],
21434
- staticModules = [
21435
- {
21436
- bpmnjs: [ 'value', this ],
21437
- moddle: [ 'value', moddle ]
21438
- }
21439
- ];
21400
+ const baseModules = options.modules || this.getModules(),
21401
+ additionalModules = options.additionalModules || [],
21402
+ staticModules = [
21403
+ {
21404
+ bpmnjs: [ 'value', this ],
21405
+ moddle: [ 'value', moddle ]
21406
+ }
21407
+ ];
21440
21408
 
21441
- var diagramModules = [].concat(staticModules, baseModules, additionalModules);
21409
+ const diagramModules = [].concat(staticModules, baseModules, additionalModules);
21442
21410
 
21443
- var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
21411
+ const diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
21444
21412
  canvas: assign({}, options.canvas, { container: container }),
21445
21413
  modules: diagramModules
21446
21414
  });
@@ -21467,7 +21435,7 @@
21467
21435
 
21468
21436
  BaseViewer.prototype._createContainer = function(options) {
21469
21437
 
21470
- var container = domify('<div class="bjs-container"></div>');
21438
+ const container = domify('<div class="bjs-container"></div>');
21471
21439
 
21472
21440
  assign$1(container, {
21473
21441
  width: ensureUnit(options.width),
@@ -21479,7 +21447,7 @@
21479
21447
  };
21480
21448
 
21481
21449
  BaseViewer.prototype._createModdle = function(options) {
21482
- var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
21450
+ const moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
21483
21451
 
21484
21452
  return new simple(moddleOptions);
21485
21453
  };
@@ -21498,8 +21466,8 @@
21498
21466
  // check if we can help the user by indicating wrong BPMN 2.0 xml
21499
21467
  // (in case he or the exporting tool did not get that right)
21500
21468
 
21501
- var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
21502
- var match = pattern.exec(err.message);
21469
+ const pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
21470
+ const match = pattern.exec(err.message);
21503
21471
 
21504
21472
  if (match) {
21505
21473
  err.message =
@@ -21510,7 +21478,7 @@
21510
21478
  return err;
21511
21479
  }
21512
21480
 
21513
- var DEFAULT_OPTIONS = {
21481
+ const DEFAULT_OPTIONS = {
21514
21482
  width: '100%',
21515
21483
  height: '100%',
21516
21484
  position: 'relative'
@@ -21552,18 +21520,18 @@
21552
21520
  * @param {Element} container
21553
21521
  */
21554
21522
  function addProjectLogo(container) {
21555
- var img = BPMNIO_IMG;
21523
+ const img = BPMNIO_IMG;
21556
21524
 
21557
- var linkMarkup =
21525
+ const linkMarkup =
21558
21526
  '<a href="http://bpmn.io" ' +
21559
- 'target="_blank" ' +
21560
- 'class="bjs-powered-by" ' +
21561
- 'title="Powered by bpmn.io" ' +
21562
- '>' +
21563
- img +
21527
+ 'target="_blank" ' +
21528
+ 'class="bjs-powered-by" ' +
21529
+ 'title="Powered by bpmn.io" ' +
21530
+ '>' +
21531
+ img +
21564
21532
  '</a>';
21565
21533
 
21566
- var linkElement = domify(linkMarkup);
21534
+ const linkElement = domify(linkMarkup);
21567
21535
 
21568
21536
  assign$1(query('svg', linkElement), LOGO_STYLES);
21569
21537
  assign$1(linkElement, LINK_STYLES, {