bpmn-js 8.7.3 → 8.8.3

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 v8.7.3
2
+ * bpmn-js - bpmn-viewer v8.8.3
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: 2021-08-27
11
+ * Date: 2021-12-03
12
12
  */
13
13
  (function (global, factory) {
14
14
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -389,13 +389,14 @@
389
389
  eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) {
390
390
  var type = evt.type,
391
391
  element = context.element,
392
- visuals = context.gfx;
392
+ visuals = context.gfx,
393
+ attrs = context.attrs;
393
394
 
394
395
  if (self.canRender(element)) {
395
396
  if (type === 'render.shape') {
396
- return self.drawShape(visuals, element);
397
+ return self.drawShape(visuals, element, attrs);
397
398
  } else {
398
- return self.drawConnection(visuals, element);
399
+ return self.drawConnection(visuals, element, attrs);
399
400
  }
400
401
  }
401
402
  });
@@ -4978,8 +4979,8 @@
4978
4979
 
4979
4980
  // helpers //////////////////////
4980
4981
 
4981
- // copied from https://github.com/adobe-webplatform/Snap.svg/blob/master/src/svg.js
4982
- var tokenRegex = /\{([^}]+)\}/g,
4982
+ // copied and adjusted from https://github.com/adobe-webplatform/Snap.svg/blob/master/src/svg.js
4983
+ var tokenRegex = /\{([^{}]+)\}/g,
4983
4984
  objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g; // matches .xxxxx or ["xxxxx"] to run over object properties
4984
4985
 
4985
4986
  function replacer(all, key, obj) {
@@ -6279,9 +6280,10 @@
6279
6280
  *
6280
6281
  * @param {EventBus} eventBus the event bus
6281
6282
  */
6282
- function Selection(eventBus) {
6283
+ function Selection(eventBus, canvas) {
6283
6284
 
6284
6285
  this._eventBus = eventBus;
6286
+ this._canvas = canvas;
6285
6287
 
6286
6288
  this._selectedElements = [];
6287
6289
 
@@ -6292,12 +6294,12 @@
6292
6294
  self.deselect(element);
6293
6295
  });
6294
6296
 
6295
- eventBus.on([ 'diagram.clear' ], function(e) {
6297
+ eventBus.on([ 'diagram.clear', 'plane.set' ], function(e) {
6296
6298
  self.select(null);
6297
6299
  });
6298
6300
  }
6299
6301
 
6300
- Selection.$inject = [ 'eventBus' ];
6302
+ Selection.$inject = [ 'eventBus', 'canvas' ];
6301
6303
 
6302
6304
 
6303
6305
  Selection.prototype.deselect = function(element) {
@@ -6343,6 +6345,14 @@
6343
6345
  elements = elements ? [ elements ] : [];
6344
6346
  }
6345
6347
 
6348
+ var canvas = this._canvas;
6349
+
6350
+ elements = elements.filter(function(element) {
6351
+ var plane = canvas.findPlane(element);
6352
+
6353
+ return plane === canvas.getActivePlane();
6354
+ });
6355
+
6346
6356
  // selection may be cleared by passing an empty array or null
6347
6357
  // to the method
6348
6358
  if (add) {
@@ -7011,6 +7021,13 @@
7011
7021
  classes(htmlContainer).add('djs-overlay-' + overlay.type);
7012
7022
  }
7013
7023
 
7024
+ var plane = this._canvas.findPlane(element);
7025
+ var activePlane = this._canvas.getActivePlane();
7026
+ overlay.plane = plane;
7027
+ if (plane !== activePlane) {
7028
+ setVisible(htmlContainer, false);
7029
+ }
7030
+
7014
7031
  overlay.htmlContainer = htmlContainer;
7015
7032
 
7016
7033
  overlayContainer.overlays.push(overlay);
@@ -7025,22 +7042,26 @@
7025
7042
 
7026
7043
  Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
7027
7044
  var show = overlay.show,
7045
+ plane = overlay.plane,
7028
7046
  minZoom = show && show.minZoom,
7029
7047
  maxZoom = show && show.maxZoom,
7030
7048
  htmlContainer = overlay.htmlContainer,
7049
+ activePlane = this._canvas.getActivePlane(),
7031
7050
  visible = true;
7032
7051
 
7033
- if (show) {
7052
+ if (plane !== activePlane) {
7053
+ visible = false;
7054
+ } else if (show) {
7034
7055
  if (
7035
7056
  (isDefined(minZoom) && minZoom > viewbox.scale) ||
7036
7057
  (isDefined(maxZoom) && maxZoom < viewbox.scale)
7037
7058
  ) {
7038
7059
  visible = false;
7039
7060
  }
7040
-
7041
- setVisible(htmlContainer, visible);
7042
7061
  }
7043
7062
 
7063
+ setVisible(htmlContainer, visible);
7064
+
7044
7065
  this._updateOverlayScale(overlay, viewbox);
7045
7066
  };
7046
7067
 
@@ -7164,6 +7185,12 @@
7164
7185
  });
7165
7186
 
7166
7187
 
7188
+ eventBus.on('plane.set', function(e) {
7189
+ forEach(self._overlays, function(el) {
7190
+ setVisible(el.htmlContainer, el.plane === e.plane);
7191
+ });
7192
+ });
7193
+
7167
7194
  // clear overlays with diagram
7168
7195
 
7169
7196
  eventBus.on('diagram.clear', this.clear, this);
@@ -7567,7 +7594,7 @@
7567
7594
  return true;
7568
7595
  };
7569
7596
 
7570
- DefaultRenderer.prototype.drawShape = function drawShape(visuals, element) {
7597
+ DefaultRenderer.prototype.drawShape = function drawShape(visuals, element, attrs) {
7571
7598
  var rect = create$1('rect');
7572
7599
 
7573
7600
  attr$1(rect, {
@@ -7578,9 +7605,9 @@
7578
7605
  });
7579
7606
 
7580
7607
  if (isFrameElement(element)) {
7581
- attr$1(rect, this.FRAME_STYLE);
7608
+ attr$1(rect, assign({}, this.FRAME_STYLE, attrs || {}));
7582
7609
  } else {
7583
- attr$1(rect, this.SHAPE_STYLE);
7610
+ attr$1(rect, assign({}, this.SHAPE_STYLE, attrs || {}));
7584
7611
  }
7585
7612
 
7586
7613
  append(visuals, rect);
@@ -7588,9 +7615,9 @@
7588
7615
  return rect;
7589
7616
  };
7590
7617
 
7591
- DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection) {
7618
+ DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection, attrs) {
7592
7619
 
7593
- var line = createLine(connection.waypoints, this.CONNECTION_STYLE);
7620
+ var line = createLine(connection.waypoints, assign({}, this.CONNECTION_STYLE, attrs || {}));
7594
7621
  append(visuals, line);
7595
7622
 
7596
7623
  return line;
@@ -7789,6 +7816,14 @@
7789
7816
  return isNumber(number) ? number + 'px' : number;
7790
7817
  }
7791
7818
 
7819
+ function findRoot(element) {
7820
+ while (element.parent) {
7821
+ element = element.parent;
7822
+ }
7823
+
7824
+ return element;
7825
+ }
7826
+
7792
7827
  /**
7793
7828
  * Creates a HTML container element for a SVG element with
7794
7829
  * the given configuration
@@ -7834,6 +7869,11 @@
7834
7869
  }
7835
7870
 
7836
7871
  var BASE_LAYER = 'base';
7872
+ var HIDDEN_MARKER = 'djs-element-hidden';
7873
+
7874
+ // render plane contents behind utility layers
7875
+ var PLANE_LAYER_INDEX = 0;
7876
+ var UTILITY_LAYER_INDEX = 1;
7837
7877
 
7838
7878
 
7839
7879
  var REQUIRED_MODEL_ATTRS = {
@@ -7870,23 +7910,23 @@
7870
7910
  'elementRegistry'
7871
7911
  ];
7872
7912
 
7913
+ /**
7914
+ * Creates a <svg> element that is wrapped into a <div>.
7915
+ * This way we are always able to correctly figure out the size of the svg element
7916
+ * by querying the parent node.
7917
+
7918
+ * (It is not possible to get the size of a svg element cross browser @ 2014-04-01)
7873
7919
 
7920
+ * <div class="djs-container" style="width: {desired-width}, height: {desired-height}">
7921
+ * <svg width="100%" height="100%">
7922
+ * ...
7923
+ * </svg>
7924
+ * </div>
7925
+ */
7874
7926
  Canvas.prototype._init = function(config) {
7875
7927
 
7876
7928
  var eventBus = this._eventBus;
7877
7929
 
7878
- // Creates a <svg> element that is wrapped into a <div>.
7879
- // This way we are always able to correctly figure out the size of the svg element
7880
- // by querying the parent node.
7881
- //
7882
- // (It is not possible to get the size of a svg element cross browser @ 2014-04-01)
7883
- //
7884
- // <div class="djs-container" style="width: {desired-width}, height: {desired-height}">
7885
- // <svg width="100%" height="100%">
7886
- // ...
7887
- // </svg>
7888
- // </div>
7889
-
7890
7930
  // html container
7891
7931
  var container = this._container = createContainer(config);
7892
7932
 
@@ -7898,6 +7938,7 @@
7898
7938
  var viewport = this._viewport = createGroup(svg, 'viewport');
7899
7939
 
7900
7940
  this._layers = {};
7941
+ this._planes = {};
7901
7942
 
7902
7943
  // debounce canvas.viewbox.changed events
7903
7944
  // for smoother diagram interaction
@@ -7932,7 +7973,8 @@
7932
7973
  'connection.added',
7933
7974
  'shape.removed',
7934
7975
  'connection.removed',
7935
- 'elements.changed'
7976
+ 'elements.changed',
7977
+ 'plane.set'
7936
7978
  ], function() {
7937
7979
  delete this._cachedViewbox;
7938
7980
  }, this);
@@ -7956,7 +7998,8 @@
7956
7998
  delete this._svg;
7957
7999
  delete this._container;
7958
8000
  delete this._layers;
7959
- delete this._rootElement;
8001
+ delete this._planes;
8002
+ delete this._activePlane;
7960
8003
  delete this._viewport;
7961
8004
  };
7962
8005
 
@@ -7971,12 +8014,16 @@
7971
8014
  var type = getType(element);
7972
8015
 
7973
8016
  if (type === 'root') {
7974
- self.setRootElement(null, true);
8017
+ self.setRootElementForPlane(null, self.findPlane(element), true);
7975
8018
  } else {
7976
8019
  self._removeElement(element, type);
7977
8020
  }
7978
8021
  });
7979
8022
 
8023
+ // remove all planes
8024
+ this._activePlane = null;
8025
+ this._planes = {};
8026
+
7980
8027
  // force recomputation of view box
7981
8028
  delete this._cachedViewbox;
7982
8029
  };
@@ -7988,7 +8035,7 @@
7988
8035
  * @returns {SVGElement}
7989
8036
  */
7990
8037
  Canvas.prototype.getDefaultLayer = function() {
7991
- return this.getLayer(BASE_LAYER, 0);
8038
+ return this.getLayer(BASE_LAYER, PLANE_LAYER_INDEX);
7992
8039
  };
7993
8040
 
7994
8041
  /**
@@ -8037,8 +8084,8 @@
8037
8084
  */
8038
8085
  Canvas.prototype._createLayer = function(name, index) {
8039
8086
 
8040
- if (!index) {
8041
- index = 0;
8087
+ if (typeof index === 'undefined') {
8088
+ index = UTILITY_LAYER_INDEX;
8042
8089
  }
8043
8090
 
8044
8091
  var childIndex = reduce(this._layers, function(childIndex, layer) {
@@ -8056,6 +8103,140 @@
8056
8103
 
8057
8104
  };
8058
8105
 
8106
+ /**
8107
+ * Returns a plane that is used to draw elements on it.
8108
+ *
8109
+ * @param {string} name
8110
+ *
8111
+ * @return {Object} plane descriptor with { layer, rootElement, name }
8112
+ */
8113
+ Canvas.prototype.getPlane = function(name) {
8114
+ if (!name) {
8115
+ throw new Error('must specify a name');
8116
+ }
8117
+
8118
+ return this._planes[name];
8119
+ };
8120
+
8121
+ /**
8122
+ * Creates a plane that is used to draw elements on it. If no
8123
+ * root element is provided, an implicit root will be used.
8124
+ *
8125
+ * @param {string} name
8126
+ * @param {Object|djs.model.Root} [rootElement] optional root element
8127
+ *
8128
+ * @return {Object} plane descriptor with { layer, rootElement, name }
8129
+ */
8130
+ Canvas.prototype.createPlane = function(name, rootElement) {
8131
+ if (!name) {
8132
+ throw new Error('must specify a name');
8133
+ }
8134
+
8135
+ if (this._planes[name]) {
8136
+ throw new Error('plane ' + name + ' already exists');
8137
+ }
8138
+
8139
+ if (!rootElement) {
8140
+ rootElement = {
8141
+ id: '__implicitroot' + name,
8142
+ children: [],
8143
+ isImplicit: true
8144
+ };
8145
+ }
8146
+
8147
+ var svgLayer = this.getLayer(name, PLANE_LAYER_INDEX);
8148
+ classes$1(svgLayer).add(HIDDEN_MARKER);
8149
+
8150
+ var plane = this._planes[name] = {
8151
+ layer: svgLayer,
8152
+ name: name,
8153
+ rootElement: null
8154
+ };
8155
+
8156
+ this.setRootElementForPlane(rootElement, plane);
8157
+
8158
+ return plane;
8159
+ };
8160
+
8161
+ /**
8162
+ * Sets the active plane and hides the previously active plane.
8163
+ *
8164
+ * @param {string|Object} plane
8165
+ *
8166
+ * @return {Object} plane descriptor with { layer, rootElement, name }
8167
+ */
8168
+ Canvas.prototype.setActivePlane = function(plane) {
8169
+ if (!plane) {
8170
+ throw new Error('must specify a plane');
8171
+ }
8172
+
8173
+ if (typeof plane === 'string') {
8174
+ plane = this.getPlane(plane);
8175
+ }
8176
+
8177
+ // hide previous Plane
8178
+ if (this._activePlane) {
8179
+ classes$1(this._activePlane.layer).add(HIDDEN_MARKER);
8180
+ }
8181
+
8182
+ this._activePlane = plane;
8183
+
8184
+ // show current Plane
8185
+ classes$1(plane.layer).remove(HIDDEN_MARKER);
8186
+
8187
+ if (plane.rootElement) {
8188
+ this._elementRegistry.updateGraphics(plane.rootElement, this._svg, true);
8189
+ }
8190
+
8191
+ this._eventBus.fire('plane.set', { plane: plane });
8192
+
8193
+ return plane;
8194
+ };
8195
+
8196
+ /**
8197
+ * Returns the currently active layer
8198
+ *
8199
+ * @returns {SVGElement}
8200
+ */
8201
+
8202
+ Canvas.prototype.getActiveLayer = function() {
8203
+ return this.getActivePlane().layer;
8204
+ };
8205
+
8206
+ /**
8207
+ * Returns the currently active plane.
8208
+ *
8209
+ * @return {Object} plane descriptor with { layer, rootElement, name }
8210
+ */
8211
+ Canvas.prototype.getActivePlane = function() {
8212
+ var plane = this._activePlane;
8213
+ if (!plane) {
8214
+ plane = this.createPlane(BASE_LAYER);
8215
+ this.setActivePlane(BASE_LAYER);
8216
+ }
8217
+
8218
+ return plane;
8219
+ };
8220
+
8221
+ /**
8222
+ * Returns the plane which contains the given element.
8223
+ *
8224
+ * @param {string|djs.model.Base} element
8225
+ *
8226
+ * @return {Object} plane descriptor with { layer, rootElement, name }
8227
+ */
8228
+ Canvas.prototype.findPlane = function(element) {
8229
+ if (typeof element === 'string') {
8230
+ element = this._elementRegistry.get(element);
8231
+ }
8232
+
8233
+ var root = findRoot(element);
8234
+
8235
+ return find(this._planes, function(plane) {
8236
+ return plane.rootElement === root;
8237
+ });
8238
+ };
8239
+
8059
8240
  /**
8060
8241
  * Returns the html element that encloses the
8061
8242
  * drawing canvas.
@@ -8177,11 +8358,9 @@
8177
8358
  };
8178
8359
 
8179
8360
  Canvas.prototype.getRootElement = function() {
8180
- if (!this._rootElement) {
8181
- this.setRootElement({ id: '__implicitroot', children: [] });
8182
- }
8361
+ var plane = this.getActivePlane();
8183
8362
 
8184
- return this._rootElement;
8363
+ return plane.rootElement;
8185
8364
  };
8186
8365
 
8187
8366
 
@@ -8198,12 +8377,41 @@
8198
8377
  * @return {Object|djs.model.Root} new root element
8199
8378
  */
8200
8379
  Canvas.prototype.setRootElement = function(element, override) {
8380
+ var activePlane = this._activePlane;
8381
+
8382
+ if (activePlane) {
8383
+ return this.setRootElementForPlane(element, activePlane, override);
8384
+ } else {
8385
+ var basePlane = this.createPlane(BASE_LAYER, element);
8386
+
8387
+ this.setActivePlane(basePlane);
8388
+
8389
+ return basePlane.rootElement;
8390
+ }
8391
+ };
8392
+
8393
+
8394
+ /**
8395
+ * Sets a given element as the new root element for the canvas
8396
+ * and returns the new root element.
8397
+ *
8398
+ * @param {Object|djs.model.Root} element
8399
+ * @param {Object|djs.model.Root} plane
8400
+ * @param {boolean} [override] whether to override the current root element, if any
8401
+ *
8402
+ * @return {Object|djs.model.Root} new root element
8403
+ */
8404
+ Canvas.prototype.setRootElementForPlane = function(element, plane, override) {
8405
+
8406
+ if (typeof plane === 'string') {
8407
+ plane = this.getPlane(plane);
8408
+ }
8201
8409
 
8202
8410
  if (element) {
8203
8411
  this._ensureValid('root', element);
8204
8412
  }
8205
8413
 
8206
- var currentRoot = this._rootElement,
8414
+ var currentRoot = plane.rootElement,
8207
8415
  elementRegistry = this._elementRegistry,
8208
8416
  eventBus = this._eventBus;
8209
8417
 
@@ -8220,23 +8428,26 @@
8220
8428
  }
8221
8429
 
8222
8430
  if (element) {
8223
- var gfx = this.getDefaultLayer();
8431
+ var gfx = plane.layer;
8224
8432
 
8225
8433
  // resemble element add event sequence
8226
8434
  eventBus.fire('root.add', { element: element });
8227
8435
 
8228
- elementRegistry.add(element, gfx, this._svg);
8436
+ elementRegistry.add(element, gfx);
8229
8437
 
8230
8438
  eventBus.fire('root.added', { element: element, gfx: gfx });
8439
+
8440
+ // associate SVG with root element when active
8441
+ if (plane === this._activePlane) {
8442
+ this._elementRegistry.updateGraphics(element, this._svg, true);
8443
+ }
8231
8444
  }
8232
8445
 
8233
- this._rootElement = element;
8446
+ plane.rootElement = element;
8234
8447
 
8235
8448
  return element;
8236
8449
  };
8237
8450
 
8238
-
8239
-
8240
8451
  // add functionality //////////////////////
8241
8452
 
8242
8453
  Canvas.prototype._ensureValid = function(type, element) {
@@ -8542,9 +8753,10 @@
8542
8753
  if (!box) {
8543
8754
 
8544
8755
  // compute the inner box based on the
8545
- // diagrams default layer. This allows us to exclude
8756
+ // diagrams active plane. This allows us to exclude
8546
8757
  // external components, such as overlays
8547
- innerBox = this.getDefaultLayer().getBBox();
8758
+
8759
+ innerBox = (this._activePlane && this._activePlane.layer.getBBox()) || {};
8548
8760
 
8549
8761
  transform = transform$1(viewport);
8550
8762
  matrix = transform ? transform.matrix : createMatrix();
@@ -8560,10 +8772,10 @@
8560
8772
  height: outerBox.height / scale,
8561
8773
  scale: scale,
8562
8774
  inner: {
8563
- width: innerBox.width,
8564
- height: innerBox.height,
8565
- x: innerBox.x,
8566
- y: innerBox.y
8775
+ width: innerBox.width || 0,
8776
+ height: innerBox.height || 0,
8777
+ x: innerBox.x || 0,
8778
+ y: innerBox.y || 0
8567
8779
  },
8568
8780
  outer: outerBox
8569
8781
  };
@@ -8622,6 +8834,13 @@
8622
8834
  */
8623
8835
  Canvas.prototype.scrollToElement = function(element, padding) {
8624
8836
  var defaultPadding = 100;
8837
+
8838
+ // switch to correct Plane
8839
+ var targetPlane = this.findPlane(element);
8840
+ if (targetPlane !== this._activePlane) {
8841
+ this.setActivePlane(targetPlane);
8842
+ }
8843
+
8625
8844
  if (!padding) {
8626
8845
  padding = {};
8627
8846
  }
@@ -8642,7 +8861,7 @@
8642
8861
  zoom = this.zoom(),
8643
8862
  dx, dy;
8644
8863
 
8645
- // Shrink viewboxBounds with padding
8864
+ // shrink viewboxBounds with padding
8646
8865
  viewboxBounds.y += padding.top / zoom;
8647
8866
  viewboxBounds.x += padding.left / zoom;
8648
8867
  viewboxBounds.width -= (padding.right + padding.left) / zoom;
@@ -8964,6 +9183,29 @@
8964
9183
  this.add(element, gfx, secondaryGfx);
8965
9184
  };
8966
9185
 
9186
+ /**
9187
+ * Update the graphics of an element
9188
+ *
9189
+ * @param {djs.model.Base} element
9190
+ * @param {SVGElement} gfx
9191
+ * @param {boolean} [secondary=false] whether to update the secondary connected element
9192
+ */
9193
+ ElementRegistry.prototype.updateGraphics = function(filter, gfx, secondary) {
9194
+ var id = filter.id || filter;
9195
+
9196
+ var container = this._elements[id];
9197
+
9198
+ if (secondary) {
9199
+ container.secondaryGfx = gfx;
9200
+ } else {
9201
+ container.gfx = gfx;
9202
+ }
9203
+
9204
+ attr$1(gfx, ELEMENT_ID, id);
9205
+
9206
+ return gfx;
9207
+ };
9208
+
8967
9209
  /**
8968
9210
  * Return the model element for a given id or graphics.
8969
9211
  *
@@ -10071,12 +10313,11 @@
10071
10313
  if (returnValue === false) {
10072
10314
  event.preventDefault();
10073
10315
  }
10074
- } catch (e) {
10075
- if (!this.handleError(e)) {
10076
- console.error('unhandled error in event listener');
10077
- console.error(e.stack);
10316
+ } catch (error) {
10317
+ if (!this.handleError(error)) {
10318
+ console.error('unhandled error in event listener', error);
10078
10319
 
10079
- throw e;
10320
+ throw error;
10080
10321
  }
10081
10322
  }
10082
10323