bpmn-js 9.0.0-subprocesses.1 → 9.0.0-subprocesses.2

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-navigated-viewer v9.0.0-subprocesses.1
2
+ * bpmn-js - bpmn-navigated-viewer v9.0.0-subprocesses.2
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-10-26
11
+ * Date: 2021-11-05
12
12
  */
13
13
  (function (global, factory) {
14
14
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -3612,8 +3612,6 @@
3612
3612
  stroke = attrs.stroke || getStrokeColor(element, defaultStrokeColor);
3613
3613
 
3614
3614
  attrs = assign({
3615
- fill: fill,
3616
- stroke: stroke,
3617
3615
  markerEnd: marker('association-end', fill, stroke)
3618
3616
  }, attrs);
3619
3617
 
@@ -3627,8 +3625,6 @@
3627
3625
 
3628
3626
 
3629
3627
  attrs = assign({
3630
- fill: fill,
3631
- stroke: stroke,
3632
3628
  markerEnd: marker('association-end', fill, stroke)
3633
3629
  }, attrs);
3634
3630
 
@@ -5352,32 +5348,6 @@
5352
5348
  });
5353
5349
  }
5354
5350
 
5355
- var PLANE_PADDING = 50;
5356
-
5357
- function getPlaneBounds(plane) {
5358
- var planeTrbl = {
5359
- top: Infinity,
5360
- right: -Infinity,
5361
- bottom: -Infinity,
5362
- left: Infinity
5363
- };
5364
-
5365
- plane.planeElement.forEach(function(element) {
5366
- if (!element.bounds) {
5367
- return;
5368
- }
5369
-
5370
- var trbl = asTRBL(element.bounds);
5371
-
5372
- planeTrbl.top = Math.min(trbl.top, planeTrbl.top);
5373
- planeTrbl.left = Math.min(trbl.left, planeTrbl.left);
5374
- planeTrbl.right = Math.max(trbl.right, planeTrbl.right);
5375
- planeTrbl.bottom = Math.max(trbl.bottom, planeTrbl.bottom);
5376
- });
5377
-
5378
- return asBounds(planeTrbl);
5379
- }
5380
-
5381
5351
  function notYetDrawn(translate, semantic, refSemantic, property) {
5382
5352
  return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
5383
5353
  element: elementToString(refSemantic),
@@ -5432,39 +5402,18 @@
5432
5402
 
5433
5403
  // ROOT ELEMENT
5434
5404
  // handle the special case that we deal with a
5435
- // invisible root element (process or collaboration)
5405
+ // invisible root element (process, subprocess or collaboration)
5436
5406
  if (is$1(di, 'bpmndi:BPMNPlane')) {
5437
5407
 
5438
- if (is$1(semantic, 'bpmn:SubProcess')) {
5439
- var plane = this._canvas.createPlane(semantic.id, element);
5440
-
5441
- // Get size of expanded element
5442
- var bounds = getPlaneBounds(di);
5443
-
5444
- var primary = this._elementRegistry.get(semantic.id);
5445
- element = this._elementFactory.createShape(elementData(semantic, di, {
5446
- collapsed: false,
5447
- hidden: false,
5448
- x: bounds.x - PLANE_PADDING,
5449
- y: bounds.y - PLANE_PADDING,
5450
- width: bounds.width + PLANE_PADDING * 2,
5451
- height: bounds.height + PLANE_PADDING * 2,
5452
- isFrame: true
5453
- }));
5454
-
5455
- element.id = element.id + '_secondary';
5456
- element.isSecondary = true;
5457
- element.primaryShape = primary;
5408
+ // add a virtual element (not being drawn)
5409
+ element = this._elementFactory.createRoot(elementData(semantic, di));
5458
5410
 
5459
- this._canvas.addShape(element, plane.rootElement);
5411
+ // for subprocesses, the id is already defined on the collapsed shape
5412
+ if (is$1(semantic, 'bpmn:SubProcess')) {
5413
+ element.id = element.id + '_plane';
5460
5414
  }
5461
- else {
5462
5415
 
5463
- // add a virtual element (not being drawn)
5464
- element = this._elementFactory.createRoot(elementData(semantic, di));
5465
-
5466
- this._canvas.createPlane(semantic.id, element);
5467
- }
5416
+ this._canvas.createPlane(semantic.id, element);
5468
5417
  }
5469
5418
 
5470
5419
  // SHAPE
@@ -5475,7 +5424,7 @@
5475
5424
 
5476
5425
  hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
5477
5426
 
5478
- bounds = di.bounds;
5427
+ var bounds = di.bounds;
5479
5428
 
5480
5429
  element = this._elementFactory.createShape(elementData(semantic, di, {
5481
5430
  collapsed: collapsed,
@@ -6256,97 +6205,6 @@
6256
6205
  interactionEvents: [ 'type', InteractionEvents ]
6257
6206
  };
6258
6207
 
6259
- /**
6260
- * Adds an element to a collection and returns true if the
6261
- * element was added.
6262
- *
6263
- * @param {Array<Object>} elements
6264
- * @param {Object} e
6265
- * @param {boolean} unique
6266
- */
6267
- function add$1(elements, e, unique) {
6268
- var canAdd = !unique || elements.indexOf(e) === -1;
6269
-
6270
- if (canAdd) {
6271
- elements.push(e);
6272
- }
6273
-
6274
- return canAdd;
6275
- }
6276
-
6277
-
6278
- /**
6279
- * Iterate over each element in a collection, calling the iterator function `fn`
6280
- * with (element, index, recursionDepth).
6281
- *
6282
- * Recurse into all elements that are returned by `fn`.
6283
- *
6284
- * @param {Object|Array<Object>} elements
6285
- * @param {Function} fn iterator function called with (element, index, recursionDepth)
6286
- * @param {number} [depth] maximum recursion depth
6287
- */
6288
- function eachElement(elements, fn, depth) {
6289
-
6290
- depth = depth || 0;
6291
-
6292
- if (!isArray$1(elements)) {
6293
- elements = [ elements ];
6294
- }
6295
-
6296
- forEach(elements, function(s, i) {
6297
- var filter = fn(s, i, depth);
6298
-
6299
- if (isArray$1(filter) && filter.length) {
6300
- eachElement(filter, fn, depth + 1);
6301
- }
6302
- });
6303
- }
6304
-
6305
-
6306
- /**
6307
- * Collects self + child elements up to a given depth from a list of elements.
6308
- *
6309
- * @param {djs.model.Base|Array<djs.model.Base>} elements the elements to select the children from
6310
- * @param {boolean} unique whether to return a unique result set (no duplicates)
6311
- * @param {number} maxDepth the depth to search through or -1 for infinite
6312
- *
6313
- * @return {Array<djs.model.Base>} found elements
6314
- */
6315
- function selfAndChildren(elements, unique, maxDepth) {
6316
- var result = [],
6317
- processedChildren = [];
6318
-
6319
- eachElement(elements, function(element, i, depth) {
6320
- add$1(result, element, unique);
6321
-
6322
- var children = element.children;
6323
-
6324
- // max traversal depth not reached yet
6325
- if (maxDepth === -1 || depth < maxDepth) {
6326
-
6327
- // children exist && children not yet processed
6328
- if (children && add$1(processedChildren, children, unique)) {
6329
- return children;
6330
- }
6331
- }
6332
- });
6333
-
6334
- return result;
6335
- }
6336
-
6337
-
6338
- /**
6339
- * Return self + ALL children for a number of elements
6340
- *
6341
- * @param {Array<djs.model.Base>} elements to query
6342
- * @param {boolean} allowDuplicates to allow duplicates in the result set
6343
- *
6344
- * @return {Array<djs.model.Base>} the collected elements
6345
- */
6346
- function selfAndAllChildren(elements, allowDuplicates) {
6347
- return selfAndChildren(elements, !allowDuplicates, -1);
6348
- }
6349
-
6350
6208
  /**
6351
6209
  * Returns the surrounding bbox for all elements in
6352
6210
  * the array or the element primitive.
@@ -7563,247 +7421,6 @@
7563
7421
  changeSupport: [ 'type', ChangeSupport ]
7564
7422
  };
7565
7423
 
7566
- function SubprocessElements(eventBus, elementRegistry, canvas, elementFactory) {
7567
- var attachBoundaries = function() {
7568
- var secondaryShapes = elementRegistry.filter(function(el) {
7569
- return is$1(el, 'bpmn:SubProcess') && el.isSecondary;
7570
- });
7571
-
7572
- secondaryShapes.forEach(function(process) {
7573
-
7574
- // Add Boundary events
7575
- if (process.primaryShape && process.primaryShape.attachers) {
7576
- process.primaryShape.attachers.forEach(function(boundary) {
7577
- var bo = getBusinessObject(boundary);
7578
-
7579
- var primary = process.primaryShape;
7580
-
7581
- var relativeXPos = (boundary.x + 15 - primary.x) / primary.width;
7582
- var relativeYPos = (boundary.y + 15 - primary.y) / primary.height;
7583
-
7584
- var dx = process.x + (process.width * relativeXPos) - 15;
7585
- var dy = process.y + (process.height * relativeYPos) - 15;
7586
-
7587
- var boundaryShape = elementFactory.createShape({
7588
- id: bo.id + '_secondary',
7589
- businessObject: bo,
7590
- type: 'bpmn:BoundaryEvent',
7591
- hidden: false,
7592
- x: dx,
7593
- y: dy,
7594
- width: 30,
7595
- height: 30,
7596
- isFrame: false,
7597
- isSecondary: true,
7598
- primaryShape: boundary,
7599
- di: boundary.di
7600
- });
7601
-
7602
- canvas.addShape(boundaryShape, process.parent);
7603
-
7604
- if (!process.attachers) {
7605
- process.attachers = [];
7606
- }
7607
-
7608
- process.attachers.push(boundaryShape);
7609
- });
7610
- }
7611
- });
7612
- };
7613
-
7614
- eventBus.on('import.done', attachBoundaries);
7615
- }
7616
-
7617
-
7618
- SubprocessElements.$inject = [ 'eventBus', 'elementRegistry', 'canvas', 'elementFactory' ];
7619
-
7620
- var defaultPosition = { x: 100, y: 50 };
7621
-
7622
- function SubprocessCentering(eventBus, canvas) {
7623
- var currentPlane = 'base';
7624
- var positionMap = {};
7625
-
7626
- eventBus.on('plane.set', function(event) {
7627
-
7628
- var currentViewbox = canvas.viewbox();
7629
- positionMap[currentPlane] = {
7630
- x: currentViewbox.x,
7631
- y: currentViewbox.y,
7632
- zoom: currentViewbox.scale
7633
- };
7634
-
7635
- var planeId = event.plane.name;
7636
- var storedViewbox = positionMap[planeId];
7637
-
7638
- if (!storedViewbox) {
7639
- if (!event.plane.rootElement.isImplicit) {
7640
- storedViewbox = {
7641
- x: 0,
7642
- y: 0,
7643
- zoom: 1
7644
- };
7645
- }
7646
- else {
7647
- var currentBoundingBox = canvas.getActiveLayer().getBBox();
7648
- storedViewbox = {
7649
- x: currentBoundingBox.x - defaultPosition.x,
7650
- y: currentBoundingBox.y - defaultPosition.y,
7651
- zoom: 1
7652
- };
7653
- }
7654
- }
7655
-
7656
- var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
7657
- dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
7658
-
7659
- if (dx !== 0 || dy !== 0) {
7660
- canvas.scroll({
7661
- dx: dx,
7662
- dy: dy
7663
- });
7664
- }
7665
-
7666
- if (storedViewbox.zoom !== currentViewbox.scale) {
7667
- canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
7668
- }
7669
-
7670
- currentPlane = planeId;
7671
- });
7672
- }
7673
-
7674
- SubprocessCentering.$inject = [ 'eventBus', 'canvas' ];
7675
-
7676
- function SubprocessCompatibility(eventBus, elementRegistry, canvas, moddle, elementFactory, bpmnjs) {
7677
- this._eventBus = eventBus;
7678
- this._elementRegistry = elementRegistry;
7679
- this._canvas = canvas;
7680
- this._bpmnjs = bpmnjs;
7681
- this._moddle = moddle;
7682
- this._elementFactory = elementFactory;
7683
-
7684
- var self = this;
7685
-
7686
- eventBus.on('import.done', 1500, function() {
7687
- self._handleImport();
7688
- });
7689
- }
7690
-
7691
- SubprocessCompatibility.prototype._handleImport = function() {
7692
- var elementRegistry = this._elementRegistry;
7693
- var canvas = this._canvas;
7694
- var elementFactory = this._elementFactory;
7695
- var self = this;
7696
- var legacyProcesses = elementRegistry.filter(function(element) {
7697
- return is$1(element, 'bpmn:SubProcess') && !isExpanded(element) && element.children && element.children.length;
7698
- });
7699
-
7700
- legacyProcesses.forEach(function(oldParent) {
7701
- var bo = getBusinessObject(oldParent);
7702
-
7703
- var newDiagram = self.createDiagram(bo);
7704
-
7705
- var newParent = elementFactory.createRoot(
7706
- {
7707
- id: bo.id,
7708
- type: bo.$type,
7709
- businessObject: bo,
7710
- di: newDiagram.plane
7711
- }
7712
- );
7713
-
7714
- newParent.id = newParent.id + '_plane';
7715
-
7716
- canvas.createPlane(bo.id, newParent);
7717
-
7718
- var elementsToChange = selfAndAllChildren(oldParent).filter(function(el) {
7719
- return el !== oldParent;
7720
- });
7721
-
7722
- self.moveElementsToRoot(elementsToChange);
7723
-
7724
- elementsToChange.forEach(function(el) {
7725
- if (el.parent === oldParent) {
7726
- el.parent = newParent;
7727
- }
7728
- el.hidden = el.parent && (el.parent.hidden || el.parent.collapsed);
7729
-
7730
- self.moveToDiPlane(el, newDiagram.plane);
7731
-
7732
- self._eventBus.fire('elements.changed', { elements: [el] });
7733
- });
7734
- });
7735
-
7736
- };
7737
-
7738
- SubprocessCompatibility.prototype.moveToDiPlane = function(element, newPlane) {
7739
- var di = getDi(element);
7740
- var containingDiagram = findRootDiagram(di);
7741
-
7742
- // Remove DI from old Plane and add it to the new one
7743
- var parentPlaneElement = containingDiagram.plane.get('planeElement');
7744
- parentPlaneElement.splice(parentPlaneElement.indexOf(di), 1);
7745
- newPlane.get('planeElement').push(di);
7746
- };
7747
-
7748
- SubprocessCompatibility.prototype.moveElementsToRoot = function(elements) {
7749
- var defaultPosition = { x: 180, y: 160 },
7750
- minX = Infinity,
7751
- minY = Infinity;
7752
-
7753
- elements.forEach(function(el) {
7754
- minX = Math.min(minX, el.x || Infinity);
7755
- minY = Math.min(minY, el.y || Infinity);
7756
- });
7757
-
7758
- var xOffset = defaultPosition.x - minX;
7759
- var yOffset = defaultPosition.y - minY;
7760
-
7761
- elements.forEach(function(el) {
7762
- if (el.waypoints) {
7763
- el.waypoints.forEach(function(waypoint) {
7764
- waypoint.x = waypoint.x + xOffset;
7765
- waypoint.y = waypoint.y + yOffset;
7766
- });
7767
- } else {
7768
- el.x = el.x + xOffset;
7769
- el.y = el.y + yOffset;
7770
- }
7771
- });
7772
- };
7773
-
7774
- SubprocessCompatibility.prototype.getDefinitions = function() {
7775
- return this._bpmnjs._definitions || [];
7776
- };
7777
-
7778
- SubprocessCompatibility.prototype.getDiagrams = function() {
7779
- return this.getDefinitions().diagrams || [];
7780
- };
7781
-
7782
- SubprocessCompatibility.prototype.createDiagram = function(bo) {
7783
- var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
7784
- var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
7785
- plane: plane
7786
- });
7787
- plane.$parent = diagram;
7788
- plane.bpmnElement = bo;
7789
- diagram.$parent = this.getDefinitions();
7790
- this.getDiagrams().push(diagram);
7791
- return diagram;
7792
- };
7793
-
7794
- SubprocessCompatibility.$inject = [ 'eventBus', 'elementRegistry', 'canvas', 'moddle', 'elementFactory', 'bpmnjs' ];
7795
-
7796
-
7797
- // Util
7798
-
7799
- var findRootDiagram = function(element) {
7800
- if (is$1(element, 'bpmndi:BPMNDiagram')) {
7801
- return element;
7802
- } else {
7803
- return findRootDiagram(element.$parent);
7804
- }
7805
- };
7806
-
7807
7424
  var css_escape = {exports: {}};
7808
7425
 
7809
7426
  /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
@@ -7927,24 +7544,26 @@
7927
7544
  }
7928
7545
 
7929
7546
  var ARROW_DOWN_SVG = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.81801948,3.50735931 L10.4996894,9.1896894 L10.5,4 L12,4 L12,12 L4,12 L4,10.5 L9.6896894,10.4996894 L3.75735931,4.56801948 C3.46446609,4.27512627 3.46446609,3.80025253 3.75735931,3.50735931 C4.05025253,3.21446609 4.52512627,3.21446609 4.81801948,3.50735931 Z"/></svg>';
7930
- var ARROW_UP_SVG = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M11.1819805,12.4926407 L5.5003106,6.8103106 L5.5,12 L4,12 L4,4 L12,4 L12,5.5 L6.3103106,5.5003106 L12.2426407,11.4319805 C12.5355339,11.7248737 12.5355339,12.1997475 12.2426407,12.4926407 C11.9497475,12.7855339 11.4748737,12.7855339 11.1819805,12.4926407 Z"/></svg>';
7931
7547
 
7932
- function SubprocessOverlays(eventBus, elementRegistry, overlays, canvas) {
7933
-
7934
- function createBreadcrumbs(subProcess) {
7935
- var breadcrumbs = domify('<ul class="bjs-breadcrumbs"></ul>');
7936
- var drillUp = domify('<button class="bjs-drilldown">' + ARROW_UP_SVG + '</button>');
7937
- drillUp.addEventListener('click', function() {
7938
- var plane = canvas.findPlane(getBusinessObject(subProcess).id);
7939
- canvas.setActivePlane(plane);
7940
- });
7941
-
7942
- breadcrumbs.appendChild(drillUp);
7548
+ /**
7549
+ * Adds Overlays that allow switching planes on collapsed subprocesses.
7550
+ *
7551
+ * @param {eventBus} eventBus
7552
+ * @param {elementRegistry} elementRegistry
7553
+ * @param {overlays} overlays
7554
+ * @param {canvas} canvas
7555
+ */
7556
+ function DrilldownOverlays(eventBus, elementRegistry, overlays, canvas) {
7557
+ var breadcrumbs = domify('<ul class="bjs-breadcrumbs djs-element-hidden"></ul>');
7558
+ var container = canvas.getContainer();
7559
+ container.appendChild(breadcrumbs);
7943
7560
 
7561
+ function updateBreadcrumbs(plane) {
7562
+ var subProcess = elementRegistry.get(plane.name);
7944
7563
  var parents = getParentChain(subProcess);
7945
7564
 
7946
7565
  var path = parents.map(function(el) {
7947
- var title = escapeHTML(el.name) || el.id;
7566
+ var title = escapeHTML(el.name || el.id);
7948
7567
  var link = domify('<li><span class="bjs-crumb"><a title="' + title + '">' + title + '</a></span></li>');
7949
7568
 
7950
7569
  link.addEventListener('click', function() {
@@ -7959,20 +7578,26 @@
7959
7578
  return link;
7960
7579
  });
7961
7580
 
7581
+ breadcrumbs.innerHTML = '';
7582
+
7583
+ if (path.length > 1) {
7584
+ breadcrumbs.classList.remove('djs-element-hidden');
7585
+ } else {
7586
+ breadcrumbs.classList.add('djs-element-hidden');
7587
+ }
7588
+
7962
7589
  path.forEach(function(el) {
7963
7590
  breadcrumbs.appendChild(el);
7964
7591
  });
7965
-
7966
- overlays.add(subProcess, {
7967
- position: {
7968
- top: -30,
7969
- left: -10
7970
- },
7971
- html: breadcrumbs
7972
- });
7973
7592
  }
7974
7593
 
7975
- var createDrilldown = function(element) {
7594
+ eventBus.on('plane.set', function(event) {
7595
+ var plane = event.plane;
7596
+
7597
+ updateBreadcrumbs(plane);
7598
+ });
7599
+
7600
+ var createOverlay = function(element) {
7976
7601
  var html = domify('<button class="bjs-drilldown">' + ARROW_DOWN_SVG + '</button>');
7977
7602
 
7978
7603
  html.addEventListener('click', function() {
@@ -7993,11 +7618,7 @@
7993
7618
  if (is$1(element, 'bpmn:SubProcess')
7994
7619
  && element.collapsed
7995
7620
  && canvas.getPlane(element.id)) {
7996
- createDrilldown(element);
7997
- }
7998
-
7999
- if (is$1(element, 'bpmn:SubProcess') && element.isSecondary) {
8000
- createBreadcrumbs(element);
7621
+ createOverlay(element);
8001
7622
  }
8002
7623
  });
8003
7624
  };
@@ -8009,9 +7630,10 @@
8009
7630
  });
8010
7631
  }
8011
7632
 
8012
- SubprocessOverlays.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
7633
+ DrilldownOverlays.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
8013
7634
 
8014
7635
 
7636
+ // helpers
8015
7637
  var getParentChain = function(child) {
8016
7638
  var bo = getBusinessObject(child);
8017
7639
 
@@ -8026,124 +7648,244 @@
8026
7648
  return parents.reverse();
8027
7649
  };
8028
7650
 
8029
- var FLOW_LENGTH = 50;
8030
- var HIGH_RENDER_PRIORITY = 2000;
7651
+ /**
7652
+ * Move collapsed subprocesses into view when drilling down. Zoom and scroll
7653
+ * are saved in a session.
7654
+ *
7655
+ * @param {eventBus} eventBus
7656
+ * @param {canvas} canvas
7657
+ */
7658
+ function DrilldownCentering(eventBus, canvas) {
7659
+ var currentPlane = 'base';
7660
+ var positionMap = {};
8031
7661
 
8032
- function SubprocessFlows(eventBus, config) {
7662
+ eventBus.on('plane.set', function(event) {
7663
+ var currentViewbox = canvas.viewbox();
7664
+ positionMap[currentPlane] = {
7665
+ x: currentViewbox.x,
7666
+ y: currentViewbox.y,
7667
+ zoom: currentViewbox.scale
7668
+ };
8033
7669
 
8034
- var mutedStrokeColor = (config && config.mutedStrokeColor) || '#dddddd';
7670
+ var planeId = event.plane.name;
7671
+ var storedViewbox = positionMap[planeId] || { x: 0, y: 0, zoom: 1 };
8035
7672
 
8036
- function drawFakeFlows(element, parentGfx) {
8037
- var primary = element.primaryShape;
7673
+ var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
7674
+ dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
8038
7675
 
8039
- var drawFakeConnection = function(connection, isOutgoing) {
7676
+ if (dx !== 0 || dy !== 0) {
7677
+ canvas.scroll({
7678
+ dx: dx,
7679
+ dy: dy
7680
+ });
7681
+ }
8040
7682
 
8041
- var segment;
8042
- if (isOutgoing) {
8043
- segment = connection.waypoints.slice(0, 2);
7683
+ if (storedViewbox.zoom !== currentViewbox.scale) {
7684
+ canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
7685
+ }
8044
7686
 
8045
- // Reverse order for normalizing
8046
- segment = segment.reverse();
8047
- } else {
8048
- segment = connection.waypoints.slice(connection.waypoints.length - 2);
8049
- }
7687
+ currentPlane = planeId;
7688
+ });
7689
+ }
8050
7690
 
8051
- var endpoint = segment[1];
7691
+ DrilldownCentering.$inject = [ 'eventBus', 'canvas' ];
8052
7692
 
8053
- var relativePosition = {
8054
- x: (endpoint.x - primary.x) / primary.width,
8055
- y: (endpoint.y - primary.y) / primary.height
8056
- };
7693
+ var DEFAULT_POSITION = {
7694
+ x: 180,
7695
+ y: 160
7696
+ };
8057
7697
 
8058
- var anchorPoint = {
8059
- x: endpoint.x - (element.width * relativePosition.x),
8060
- y: endpoint.y - (element.height * relativePosition.y)
8061
- };
7698
+ /**
7699
+ * Hook into `import.render.start` and create new planes for diagrams with
7700
+ * collapsed subprocesses and all dis on the same plane.
7701
+ *
7702
+ * @param {eventBus} eventBus
7703
+ * @param {moddle} moddle
7704
+ */
7705
+ function SubprocessCompatibility(eventBus, moddle) {
7706
+ this._eventBus = eventBus;
7707
+ this._moddle = moddle;
8062
7708
 
8063
- var newWaypoints = segment.map(function(el) {
8064
- return { x: el.x - anchorPoint.x, y: el.y - anchorPoint.y };
8065
- });
7709
+ var self = this;
8066
7710
 
8067
- newWaypoints[0] = normalizeLength(newWaypoints[1], newWaypoints[0], FLOW_LENGTH);
7711
+ eventBus.on('import.render.start', 1500, function(e, context) {
7712
+ self.handleImport(context.definitions);
7713
+ });
7714
+ }
8068
7715
 
8069
- var attrs = {
8070
- stroke: mutedStrokeColor
8071
- };
7716
+ SubprocessCompatibility.prototype.handleImport = function(definitions) {
7717
+ if (!definitions.diagrams) {
7718
+ return;
7719
+ }
8072
7720
 
8073
- if (isOutgoing) {
7721
+ var self = this;
7722
+ this._definitions = definitions;
7723
+ this._processToDiagramMap = {};
8074
7724
 
8075
- // Reverse order again for correct end marker position
8076
- newWaypoints = newWaypoints.reverse();
8077
- } else {
7725
+ definitions.diagrams.forEach(function(diagram) {
7726
+ if (!diagram.plane || !diagram.plane.bpmnElement) {
7727
+ return;
7728
+ }
8078
7729
 
8079
- // Remove start marker for incoming flows
8080
- attrs.markerStart = undefined;
8081
- }
7730
+ self._processToDiagramMap[diagram.plane.bpmnElement.id] = diagram;
7731
+ });
8082
7732
 
8083
- eventBus.fire('render.connection', {
8084
- type: connection.type,
8085
- gfx: parentGfx,
8086
- element: {
8087
- type: connection.type,
8088
- waypoints: newWaypoints,
8089
- di: connection.di,
8090
- businessObject: connection.businessObject
8091
- },
8092
- attrs: attrs
8093
- });
8094
- };
7733
+ var newDiagrams = [];
7734
+ definitions.diagrams.forEach(function(diagram) {
7735
+ var createdDiagrams = self.createNewDiagrams(diagram.plane);
7736
+ Array.prototype.push.apply(newDiagrams, createdDiagrams);
7737
+ });
8095
7738
 
8096
- primary.incoming && primary.incoming.forEach(function(connection) {
8097
- drawFakeConnection(connection, false);
8098
- });
7739
+ newDiagrams.forEach(function(diagram) {
7740
+ self.movePlaneElementsToOrigin(diagram.plane);
7741
+ });
7742
+ };
8099
7743
 
8100
- primary.outgoing && primary.outgoing.forEach(function(connection) {
8101
- drawFakeConnection(connection, true);
8102
- });
8103
- }
8104
7744
 
8105
- eventBus.on([ 'render.shape' ], HIGH_RENDER_PRIORITY, function(evt, context) {
8106
- var element = context.element,
8107
- visuals = context.gfx;
7745
+ /**
7746
+ * Moves all DI elements from collapsed subprocesses to a new plane.
7747
+ *
7748
+ * @param {Object} plane
7749
+ * @return {Array} new diagrams created for the collapsed subprocesses
7750
+ */
7751
+ SubprocessCompatibility.prototype.createNewDiagrams = function(plane) {
7752
+ var self = this;
7753
+
7754
+ var collapsedElements = [];
7755
+ var elementsToMove = [];
8108
7756
 
8109
- if (element.isSecondary && element.primaryShape) {
8110
- drawFakeFlows(element, visuals);
7757
+ plane.get('planeElement').forEach(function(diElement) {
7758
+ var bo = diElement.bpmnElement;
7759
+ var parent = bo.$parent;
7760
+
7761
+ if (is$1(bo, 'bpmn:SubProcess') && !diElement.isExpanded) {
7762
+ collapsedElements.push(bo);
8111
7763
  }
8112
7764
 
7765
+ if (is$1(parent, 'bpmn:SubProcess') && parent !== plane.bpmnElement) {
7766
+
7767
+ // don't change the array while we iterate over it
7768
+ elementsToMove.push({ diElement: diElement, parent: parent });
7769
+ }
8113
7770
  });
8114
7771
 
8115
- }
7772
+ var newDiagrams = [];
8116
7773
 
8117
- SubprocessFlows.$inject = [ 'eventBus', 'config' ];
7774
+ elementsToMove.forEach(function(element) {
7775
+ var diElement = element.diElement;
7776
+ var parent = element.parent;
8118
7777
 
7778
+ // parent is expanded, get nearest collapsed parent
7779
+ while (parent && !collapsedElements.includes(parent)) {
7780
+ parent = parent.$parent;
7781
+ }
8119
7782
 
8120
- // helpers
7783
+ // false positive, all parents are expanded
7784
+ if (!parent) {
7785
+ return;
7786
+ }
8121
7787
 
8122
- function normalizeLength(fixedPoint, variablePoint, length) {
8123
- var dx = fixedPoint.x - variablePoint.x,
8124
- dy = fixedPoint.y - variablePoint.y,
8125
- totalDistance = Math.abs(dx) + Math.abs(dy);
7788
+ var diagram = self._processToDiagramMap[parent.id];
7789
+ if (!diagram) {
7790
+ diagram = self.createDiagram(parent);
7791
+ self._processToDiagramMap[parent.id] = diagram;
7792
+ newDiagrams.push(diagram);
7793
+ }
8126
7794
 
8127
- dx = dx / totalDistance;
8128
- dy = dy / totalDistance;
7795
+ self.moveToDiPlane(diElement, diagram.plane);
7796
+ });
8129
7797
 
8130
- dx *= length;
8131
- dy *= length;
7798
+ return newDiagrams;
7799
+ };
8132
7800
 
8133
- return {
8134
- x: fixedPoint.x - dx,
8135
- y: fixedPoint.y - dy
7801
+ SubprocessCompatibility.prototype.movePlaneElementsToOrigin = function(plane) {
7802
+ var elements = plane.get('planeElement');
7803
+
7804
+ // get bounding box of all elements
7805
+ var planeBounds = getPlaneBounds(plane);
7806
+
7807
+ var offset = {
7808
+ x: planeBounds.x - DEFAULT_POSITION.x,
7809
+ y: planeBounds.y - DEFAULT_POSITION.y
7810
+ };
7811
+
7812
+ elements.forEach(function(diElement) {
7813
+ if (diElement.waypoint) {
7814
+ diElement.waypoint.forEach(function(waypoint) {
7815
+ waypoint.x = waypoint.x - offset.x;
7816
+ waypoint.y = waypoint.y - offset.y;
7817
+ });
7818
+ } else if (diElement.bounds) {
7819
+ diElement.bounds.x = diElement.bounds.x - offset.x;
7820
+ diElement.bounds.y = diElement.bounds.y - offset.y;
7821
+ }
7822
+ });
7823
+ };
7824
+
7825
+
7826
+ SubprocessCompatibility.prototype.moveToDiPlane = function(diElement, newPlane) {
7827
+ var containingDiagram = findRootDiagram(diElement);
7828
+
7829
+ // remove DI from old Plane and add it to the new one
7830
+ var parentPlaneElement = containingDiagram.plane.get('planeElement');
7831
+ parentPlaneElement.splice(parentPlaneElement.indexOf(diElement), 1);
7832
+ newPlane.get('planeElement').push(diElement);
7833
+ };
7834
+
7835
+
7836
+ SubprocessCompatibility.prototype.createDiagram = function(bo) {
7837
+ var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
7838
+ var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
7839
+ plane: plane
7840
+ });
7841
+ plane.$parent = diagram;
7842
+ plane.bpmnElement = bo;
7843
+ diagram.$parent = this._definitions;
7844
+ this._definitions.diagrams.push(diagram);
7845
+ return diagram;
7846
+ };
7847
+
7848
+ SubprocessCompatibility.$inject = [ 'eventBus', 'moddle' ];
7849
+
7850
+
7851
+ // helpers
7852
+
7853
+ function findRootDiagram(element) {
7854
+ if (is$1(element, 'bpmndi:BPMNDiagram')) {
7855
+ return element;
7856
+ } else {
7857
+ return findRootDiagram(element.$parent);
7858
+ }
7859
+ }
7860
+
7861
+ function getPlaneBounds(plane) {
7862
+ var planeTrbl = {
7863
+ top: Infinity,
7864
+ right: -Infinity,
7865
+ bottom: -Infinity,
7866
+ left: Infinity
8136
7867
  };
7868
+
7869
+ plane.planeElement.forEach(function(element) {
7870
+ if (!element.bounds) {
7871
+ return;
7872
+ }
7873
+
7874
+ var trbl = asTRBL(element.bounds);
7875
+
7876
+ planeTrbl.top = Math.min(trbl.top, planeTrbl.top);
7877
+ planeTrbl.left = Math.min(trbl.left, planeTrbl.left);
7878
+ });
7879
+
7880
+ return asBounds(planeTrbl);
8137
7881
  }
8138
7882
 
8139
- var SubprocessNavigationModule = {
7883
+ var DrilldownModdule = {
8140
7884
  __depends__: [ OverlaysModule, ChangeSupportModule ],
8141
- __init__: [ 'subprocessElements', 'subprocessOverlays', 'subprocessCompatibility', 'subprocessCentering', 'subprocessFlows' ],
8142
- subprocessElements: [ 'type', SubprocessElements ],
8143
- subprocessOverlays: [ 'type', SubprocessOverlays ],
8144
- subprocessCompatibility: [ 'type', SubprocessCompatibility ],
8145
- subprocessCentering: [ 'type', SubprocessCentering ],
8146
- subprocessFlows: ['type', SubprocessFlows]
7885
+ __init__: [ 'drilldownOverlays', 'drilldownCentering', 'subprocessCompatibility'],
7886
+ drilldownOverlays: [ 'type', DrilldownOverlays ],
7887
+ drilldownCentering: [ 'type', DrilldownCentering ],
7888
+ subprocessCompatibility: [ 'type', SubprocessCompatibility ]
8147
7889
  };
8148
7890
 
8149
7891
  var CLASS_PATTERN = /^class /;
@@ -8785,6 +8527,9 @@
8785
8527
  var BASE_LAYER = 'base';
8786
8528
  var HIDDEN_MARKER = 'djs-element-hidden';
8787
8529
 
8530
+ // render plane contents behind additional layers
8531
+ var PLANE_LAYER_INDEX = -10;
8532
+
8788
8533
 
8789
8534
  var REQUIRED_MODEL_ATTRS = {
8790
8535
  shape: [ 'x', 'y', 'width', 'height' ],
@@ -8883,7 +8628,8 @@
8883
8628
  'connection.added',
8884
8629
  'shape.removed',
8885
8630
  'connection.removed',
8886
- 'elements.changed'
8631
+ 'elements.changed',
8632
+ 'plane.set'
8887
8633
  ], function() {
8888
8634
  delete this._cachedViewbox;
8889
8635
  }, this);
@@ -9024,9 +8770,7 @@
9024
8770
  throw new Error('must specify a name');
9025
8771
  }
9026
8772
 
9027
- var plane = this._planes[name];
9028
-
9029
- return plane;
8773
+ return this._planes[name];
9030
8774
  };
9031
8775
 
9032
8776
  /**
@@ -9055,7 +8799,7 @@
9055
8799
  };
9056
8800
  }
9057
8801
 
9058
- var svgLayer = this.getLayer(name);
8802
+ var svgLayer = this.getLayer(name, PLANE_LAYER_INDEX);
9059
8803
  classes$1(svgLayer).add(HIDDEN_MARKER);
9060
8804
 
9061
8805
  var plane = this._planes[name] = {
@@ -9664,9 +9408,10 @@
9664
9408
  if (!box) {
9665
9409
 
9666
9410
  // compute the inner box based on the
9667
- // diagrams default layer. This allows us to exclude
9411
+ // diagrams active plane. This allows us to exclude
9668
9412
  // external components, such as overlays
9669
- innerBox = this.getDefaultLayer().getBBox();
9413
+
9414
+ innerBox = (this._activePlane && this._activePlane.layer.getBBox()) || {};
9670
9415
 
9671
9416
  transform = transform$1(viewport);
9672
9417
  matrix = transform ? transform.matrix : createMatrix();
@@ -9682,10 +9427,10 @@
9682
9427
  height: outerBox.height / scale,
9683
9428
  scale: scale,
9684
9429
  inner: {
9685
- width: innerBox.width,
9686
- height: innerBox.height,
9687
- x: innerBox.x,
9688
- y: innerBox.y
9430
+ width: innerBox.width || 0,
9431
+ height: innerBox.height || 0,
9432
+ x: innerBox.x || 0,
9433
+ y: innerBox.y || 0
9689
9434
  },
9690
9435
  outer: outerBox
9691
9436
  };
@@ -20799,7 +20544,7 @@
20799
20544
  TranslateModule,
20800
20545
  SelectionModule,
20801
20546
  OverlaysModule,
20802
- SubprocessNavigationModule
20547
+ DrilldownModdule
20803
20548
  ];
20804
20549
 
20805
20550
  // default moddle extensions the viewer is composed of