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-viewer v9.0.0-subprocesses.1
2
+ * bpmn-js - bpmn-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,
@@ -6239,97 +6188,6 @@
6239
6188
  interactionEvents: [ 'type', InteractionEvents ]
6240
6189
  };
6241
6190
 
6242
- /**
6243
- * Adds an element to a collection and returns true if the
6244
- * element was added.
6245
- *
6246
- * @param {Array<Object>} elements
6247
- * @param {Object} e
6248
- * @param {boolean} unique
6249
- */
6250
- function add$1(elements, e, unique) {
6251
- var canAdd = !unique || elements.indexOf(e) === -1;
6252
-
6253
- if (canAdd) {
6254
- elements.push(e);
6255
- }
6256
-
6257
- return canAdd;
6258
- }
6259
-
6260
-
6261
- /**
6262
- * Iterate over each element in a collection, calling the iterator function `fn`
6263
- * with (element, index, recursionDepth).
6264
- *
6265
- * Recurse into all elements that are returned by `fn`.
6266
- *
6267
- * @param {Object|Array<Object>} elements
6268
- * @param {Function} fn iterator function called with (element, index, recursionDepth)
6269
- * @param {number} [depth] maximum recursion depth
6270
- */
6271
- function eachElement(elements, fn, depth) {
6272
-
6273
- depth = depth || 0;
6274
-
6275
- if (!isArray$1(elements)) {
6276
- elements = [ elements ];
6277
- }
6278
-
6279
- forEach(elements, function(s, i) {
6280
- var filter = fn(s, i, depth);
6281
-
6282
- if (isArray$1(filter) && filter.length) {
6283
- eachElement(filter, fn, depth + 1);
6284
- }
6285
- });
6286
- }
6287
-
6288
-
6289
- /**
6290
- * Collects self + child elements up to a given depth from a list of elements.
6291
- *
6292
- * @param {djs.model.Base|Array<djs.model.Base>} elements the elements to select the children from
6293
- * @param {boolean} unique whether to return a unique result set (no duplicates)
6294
- * @param {number} maxDepth the depth to search through or -1 for infinite
6295
- *
6296
- * @return {Array<djs.model.Base>} found elements
6297
- */
6298
- function selfAndChildren(elements, unique, maxDepth) {
6299
- var result = [],
6300
- processedChildren = [];
6301
-
6302
- eachElement(elements, function(element, i, depth) {
6303
- add$1(result, element, unique);
6304
-
6305
- var children = element.children;
6306
-
6307
- // max traversal depth not reached yet
6308
- if (maxDepth === -1 || depth < maxDepth) {
6309
-
6310
- // children exist && children not yet processed
6311
- if (children && add$1(processedChildren, children, unique)) {
6312
- return children;
6313
- }
6314
- }
6315
- });
6316
-
6317
- return result;
6318
- }
6319
-
6320
-
6321
- /**
6322
- * Return self + ALL children for a number of elements
6323
- *
6324
- * @param {Array<djs.model.Base>} elements to query
6325
- * @param {boolean} allowDuplicates to allow duplicates in the result set
6326
- *
6327
- * @return {Array<djs.model.Base>} the collected elements
6328
- */
6329
- function selfAndAllChildren(elements, allowDuplicates) {
6330
- return selfAndChildren(elements, !allowDuplicates, -1);
6331
- }
6332
-
6333
6191
  /**
6334
6192
  * Returns the surrounding bbox for all elements in
6335
6193
  * the array or the element primitive.
@@ -7546,247 +7404,6 @@
7546
7404
  changeSupport: [ 'type', ChangeSupport ]
7547
7405
  };
7548
7406
 
7549
- function SubprocessElements(eventBus, elementRegistry, canvas, elementFactory) {
7550
- var attachBoundaries = function() {
7551
- var secondaryShapes = elementRegistry.filter(function(el) {
7552
- return is$1(el, 'bpmn:SubProcess') && el.isSecondary;
7553
- });
7554
-
7555
- secondaryShapes.forEach(function(process) {
7556
-
7557
- // Add Boundary events
7558
- if (process.primaryShape && process.primaryShape.attachers) {
7559
- process.primaryShape.attachers.forEach(function(boundary) {
7560
- var bo = getBusinessObject(boundary);
7561
-
7562
- var primary = process.primaryShape;
7563
-
7564
- var relativeXPos = (boundary.x + 15 - primary.x) / primary.width;
7565
- var relativeYPos = (boundary.y + 15 - primary.y) / primary.height;
7566
-
7567
- var dx = process.x + (process.width * relativeXPos) - 15;
7568
- var dy = process.y + (process.height * relativeYPos) - 15;
7569
-
7570
- var boundaryShape = elementFactory.createShape({
7571
- id: bo.id + '_secondary',
7572
- businessObject: bo,
7573
- type: 'bpmn:BoundaryEvent',
7574
- hidden: false,
7575
- x: dx,
7576
- y: dy,
7577
- width: 30,
7578
- height: 30,
7579
- isFrame: false,
7580
- isSecondary: true,
7581
- primaryShape: boundary,
7582
- di: boundary.di
7583
- });
7584
-
7585
- canvas.addShape(boundaryShape, process.parent);
7586
-
7587
- if (!process.attachers) {
7588
- process.attachers = [];
7589
- }
7590
-
7591
- process.attachers.push(boundaryShape);
7592
- });
7593
- }
7594
- });
7595
- };
7596
-
7597
- eventBus.on('import.done', attachBoundaries);
7598
- }
7599
-
7600
-
7601
- SubprocessElements.$inject = [ 'eventBus', 'elementRegistry', 'canvas', 'elementFactory' ];
7602
-
7603
- var defaultPosition = { x: 100, y: 50 };
7604
-
7605
- function SubprocessCentering(eventBus, canvas) {
7606
- var currentPlane = 'base';
7607
- var positionMap = {};
7608
-
7609
- eventBus.on('plane.set', function(event) {
7610
-
7611
- var currentViewbox = canvas.viewbox();
7612
- positionMap[currentPlane] = {
7613
- x: currentViewbox.x,
7614
- y: currentViewbox.y,
7615
- zoom: currentViewbox.scale
7616
- };
7617
-
7618
- var planeId = event.plane.name;
7619
- var storedViewbox = positionMap[planeId];
7620
-
7621
- if (!storedViewbox) {
7622
- if (!event.plane.rootElement.isImplicit) {
7623
- storedViewbox = {
7624
- x: 0,
7625
- y: 0,
7626
- zoom: 1
7627
- };
7628
- }
7629
- else {
7630
- var currentBoundingBox = canvas.getActiveLayer().getBBox();
7631
- storedViewbox = {
7632
- x: currentBoundingBox.x - defaultPosition.x,
7633
- y: currentBoundingBox.y - defaultPosition.y,
7634
- zoom: 1
7635
- };
7636
- }
7637
- }
7638
-
7639
- var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
7640
- dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
7641
-
7642
- if (dx !== 0 || dy !== 0) {
7643
- canvas.scroll({
7644
- dx: dx,
7645
- dy: dy
7646
- });
7647
- }
7648
-
7649
- if (storedViewbox.zoom !== currentViewbox.scale) {
7650
- canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
7651
- }
7652
-
7653
- currentPlane = planeId;
7654
- });
7655
- }
7656
-
7657
- SubprocessCentering.$inject = [ 'eventBus', 'canvas' ];
7658
-
7659
- function SubprocessCompatibility(eventBus, elementRegistry, canvas, moddle, elementFactory, bpmnjs) {
7660
- this._eventBus = eventBus;
7661
- this._elementRegistry = elementRegistry;
7662
- this._canvas = canvas;
7663
- this._bpmnjs = bpmnjs;
7664
- this._moddle = moddle;
7665
- this._elementFactory = elementFactory;
7666
-
7667
- var self = this;
7668
-
7669
- eventBus.on('import.done', 1500, function() {
7670
- self._handleImport();
7671
- });
7672
- }
7673
-
7674
- SubprocessCompatibility.prototype._handleImport = function() {
7675
- var elementRegistry = this._elementRegistry;
7676
- var canvas = this._canvas;
7677
- var elementFactory = this._elementFactory;
7678
- var self = this;
7679
- var legacyProcesses = elementRegistry.filter(function(element) {
7680
- return is$1(element, 'bpmn:SubProcess') && !isExpanded(element) && element.children && element.children.length;
7681
- });
7682
-
7683
- legacyProcesses.forEach(function(oldParent) {
7684
- var bo = getBusinessObject(oldParent);
7685
-
7686
- var newDiagram = self.createDiagram(bo);
7687
-
7688
- var newParent = elementFactory.createRoot(
7689
- {
7690
- id: bo.id,
7691
- type: bo.$type,
7692
- businessObject: bo,
7693
- di: newDiagram.plane
7694
- }
7695
- );
7696
-
7697
- newParent.id = newParent.id + '_plane';
7698
-
7699
- canvas.createPlane(bo.id, newParent);
7700
-
7701
- var elementsToChange = selfAndAllChildren(oldParent).filter(function(el) {
7702
- return el !== oldParent;
7703
- });
7704
-
7705
- self.moveElementsToRoot(elementsToChange);
7706
-
7707
- elementsToChange.forEach(function(el) {
7708
- if (el.parent === oldParent) {
7709
- el.parent = newParent;
7710
- }
7711
- el.hidden = el.parent && (el.parent.hidden || el.parent.collapsed);
7712
-
7713
- self.moveToDiPlane(el, newDiagram.plane);
7714
-
7715
- self._eventBus.fire('elements.changed', { elements: [el] });
7716
- });
7717
- });
7718
-
7719
- };
7720
-
7721
- SubprocessCompatibility.prototype.moveToDiPlane = function(element, newPlane) {
7722
- var di = getDi(element);
7723
- var containingDiagram = findRootDiagram(di);
7724
-
7725
- // Remove DI from old Plane and add it to the new one
7726
- var parentPlaneElement = containingDiagram.plane.get('planeElement');
7727
- parentPlaneElement.splice(parentPlaneElement.indexOf(di), 1);
7728
- newPlane.get('planeElement').push(di);
7729
- };
7730
-
7731
- SubprocessCompatibility.prototype.moveElementsToRoot = function(elements) {
7732
- var defaultPosition = { x: 180, y: 160 },
7733
- minX = Infinity,
7734
- minY = Infinity;
7735
-
7736
- elements.forEach(function(el) {
7737
- minX = Math.min(minX, el.x || Infinity);
7738
- minY = Math.min(minY, el.y || Infinity);
7739
- });
7740
-
7741
- var xOffset = defaultPosition.x - minX;
7742
- var yOffset = defaultPosition.y - minY;
7743
-
7744
- elements.forEach(function(el) {
7745
- if (el.waypoints) {
7746
- el.waypoints.forEach(function(waypoint) {
7747
- waypoint.x = waypoint.x + xOffset;
7748
- waypoint.y = waypoint.y + yOffset;
7749
- });
7750
- } else {
7751
- el.x = el.x + xOffset;
7752
- el.y = el.y + yOffset;
7753
- }
7754
- });
7755
- };
7756
-
7757
- SubprocessCompatibility.prototype.getDefinitions = function() {
7758
- return this._bpmnjs._definitions || [];
7759
- };
7760
-
7761
- SubprocessCompatibility.prototype.getDiagrams = function() {
7762
- return this.getDefinitions().diagrams || [];
7763
- };
7764
-
7765
- SubprocessCompatibility.prototype.createDiagram = function(bo) {
7766
- var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
7767
- var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
7768
- plane: plane
7769
- });
7770
- plane.$parent = diagram;
7771
- plane.bpmnElement = bo;
7772
- diagram.$parent = this.getDefinitions();
7773
- this.getDiagrams().push(diagram);
7774
- return diagram;
7775
- };
7776
-
7777
- SubprocessCompatibility.$inject = [ 'eventBus', 'elementRegistry', 'canvas', 'moddle', 'elementFactory', 'bpmnjs' ];
7778
-
7779
-
7780
- // Util
7781
-
7782
- var findRootDiagram = function(element) {
7783
- if (is$1(element, 'bpmndi:BPMNDiagram')) {
7784
- return element;
7785
- } else {
7786
- return findRootDiagram(element.$parent);
7787
- }
7788
- };
7789
-
7790
7407
  var css_escape = {exports: {}};
7791
7408
 
7792
7409
  /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
@@ -7910,24 +7527,26 @@
7910
7527
  }
7911
7528
 
7912
7529
  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>';
7913
- 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>';
7914
7530
 
7915
- function SubprocessOverlays(eventBus, elementRegistry, overlays, canvas) {
7916
-
7917
- function createBreadcrumbs(subProcess) {
7918
- var breadcrumbs = domify('<ul class="bjs-breadcrumbs"></ul>');
7919
- var drillUp = domify('<button class="bjs-drilldown">' + ARROW_UP_SVG + '</button>');
7920
- drillUp.addEventListener('click', function() {
7921
- var plane = canvas.findPlane(getBusinessObject(subProcess).id);
7922
- canvas.setActivePlane(plane);
7923
- });
7924
-
7925
- breadcrumbs.appendChild(drillUp);
7531
+ /**
7532
+ * Adds Overlays that allow switching planes on collapsed subprocesses.
7533
+ *
7534
+ * @param {eventBus} eventBus
7535
+ * @param {elementRegistry} elementRegistry
7536
+ * @param {overlays} overlays
7537
+ * @param {canvas} canvas
7538
+ */
7539
+ function DrilldownOverlays(eventBus, elementRegistry, overlays, canvas) {
7540
+ var breadcrumbs = domify('<ul class="bjs-breadcrumbs djs-element-hidden"></ul>');
7541
+ var container = canvas.getContainer();
7542
+ container.appendChild(breadcrumbs);
7926
7543
 
7544
+ function updateBreadcrumbs(plane) {
7545
+ var subProcess = elementRegistry.get(plane.name);
7927
7546
  var parents = getParentChain(subProcess);
7928
7547
 
7929
7548
  var path = parents.map(function(el) {
7930
- var title = escapeHTML(el.name) || el.id;
7549
+ var title = escapeHTML(el.name || el.id);
7931
7550
  var link = domify('<li><span class="bjs-crumb"><a title="' + title + '">' + title + '</a></span></li>');
7932
7551
 
7933
7552
  link.addEventListener('click', function() {
@@ -7942,20 +7561,26 @@
7942
7561
  return link;
7943
7562
  });
7944
7563
 
7564
+ breadcrumbs.innerHTML = '';
7565
+
7566
+ if (path.length > 1) {
7567
+ breadcrumbs.classList.remove('djs-element-hidden');
7568
+ } else {
7569
+ breadcrumbs.classList.add('djs-element-hidden');
7570
+ }
7571
+
7945
7572
  path.forEach(function(el) {
7946
7573
  breadcrumbs.appendChild(el);
7947
7574
  });
7948
-
7949
- overlays.add(subProcess, {
7950
- position: {
7951
- top: -30,
7952
- left: -10
7953
- },
7954
- html: breadcrumbs
7955
- });
7956
7575
  }
7957
7576
 
7958
- var createDrilldown = function(element) {
7577
+ eventBus.on('plane.set', function(event) {
7578
+ var plane = event.plane;
7579
+
7580
+ updateBreadcrumbs(plane);
7581
+ });
7582
+
7583
+ var createOverlay = function(element) {
7959
7584
  var html = domify('<button class="bjs-drilldown">' + ARROW_DOWN_SVG + '</button>');
7960
7585
 
7961
7586
  html.addEventListener('click', function() {
@@ -7976,11 +7601,7 @@
7976
7601
  if (is$1(element, 'bpmn:SubProcess')
7977
7602
  && element.collapsed
7978
7603
  && canvas.getPlane(element.id)) {
7979
- createDrilldown(element);
7980
- }
7981
-
7982
- if (is$1(element, 'bpmn:SubProcess') && element.isSecondary) {
7983
- createBreadcrumbs(element);
7604
+ createOverlay(element);
7984
7605
  }
7985
7606
  });
7986
7607
  };
@@ -7992,9 +7613,10 @@
7992
7613
  });
7993
7614
  }
7994
7615
 
7995
- SubprocessOverlays.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
7616
+ DrilldownOverlays.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
7996
7617
 
7997
7618
 
7619
+ // helpers
7998
7620
  var getParentChain = function(child) {
7999
7621
  var bo = getBusinessObject(child);
8000
7622
 
@@ -8009,124 +7631,244 @@
8009
7631
  return parents.reverse();
8010
7632
  };
8011
7633
 
8012
- var FLOW_LENGTH = 50;
8013
- var HIGH_RENDER_PRIORITY = 2000;
7634
+ /**
7635
+ * Move collapsed subprocesses into view when drilling down. Zoom and scroll
7636
+ * are saved in a session.
7637
+ *
7638
+ * @param {eventBus} eventBus
7639
+ * @param {canvas} canvas
7640
+ */
7641
+ function DrilldownCentering(eventBus, canvas) {
7642
+ var currentPlane = 'base';
7643
+ var positionMap = {};
8014
7644
 
8015
- function SubprocessFlows(eventBus, config) {
7645
+ eventBus.on('plane.set', function(event) {
7646
+ var currentViewbox = canvas.viewbox();
7647
+ positionMap[currentPlane] = {
7648
+ x: currentViewbox.x,
7649
+ y: currentViewbox.y,
7650
+ zoom: currentViewbox.scale
7651
+ };
8016
7652
 
8017
- var mutedStrokeColor = (config && config.mutedStrokeColor) || '#dddddd';
7653
+ var planeId = event.plane.name;
7654
+ var storedViewbox = positionMap[planeId] || { x: 0, y: 0, zoom: 1 };
8018
7655
 
8019
- function drawFakeFlows(element, parentGfx) {
8020
- var primary = element.primaryShape;
7656
+ var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
7657
+ dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
8021
7658
 
8022
- var drawFakeConnection = function(connection, isOutgoing) {
7659
+ if (dx !== 0 || dy !== 0) {
7660
+ canvas.scroll({
7661
+ dx: dx,
7662
+ dy: dy
7663
+ });
7664
+ }
8023
7665
 
8024
- var segment;
8025
- if (isOutgoing) {
8026
- segment = connection.waypoints.slice(0, 2);
7666
+ if (storedViewbox.zoom !== currentViewbox.scale) {
7667
+ canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
7668
+ }
8027
7669
 
8028
- // Reverse order for normalizing
8029
- segment = segment.reverse();
8030
- } else {
8031
- segment = connection.waypoints.slice(connection.waypoints.length - 2);
8032
- }
7670
+ currentPlane = planeId;
7671
+ });
7672
+ }
8033
7673
 
8034
- var endpoint = segment[1];
7674
+ DrilldownCentering.$inject = [ 'eventBus', 'canvas' ];
8035
7675
 
8036
- var relativePosition = {
8037
- x: (endpoint.x - primary.x) / primary.width,
8038
- y: (endpoint.y - primary.y) / primary.height
8039
- };
7676
+ var DEFAULT_POSITION = {
7677
+ x: 180,
7678
+ y: 160
7679
+ };
8040
7680
 
8041
- var anchorPoint = {
8042
- x: endpoint.x - (element.width * relativePosition.x),
8043
- y: endpoint.y - (element.height * relativePosition.y)
8044
- };
7681
+ /**
7682
+ * Hook into `import.render.start` and create new planes for diagrams with
7683
+ * collapsed subprocesses and all dis on the same plane.
7684
+ *
7685
+ * @param {eventBus} eventBus
7686
+ * @param {moddle} moddle
7687
+ */
7688
+ function SubprocessCompatibility(eventBus, moddle) {
7689
+ this._eventBus = eventBus;
7690
+ this._moddle = moddle;
8045
7691
 
8046
- var newWaypoints = segment.map(function(el) {
8047
- return { x: el.x - anchorPoint.x, y: el.y - anchorPoint.y };
8048
- });
7692
+ var self = this;
8049
7693
 
8050
- newWaypoints[0] = normalizeLength(newWaypoints[1], newWaypoints[0], FLOW_LENGTH);
7694
+ eventBus.on('import.render.start', 1500, function(e, context) {
7695
+ self.handleImport(context.definitions);
7696
+ });
7697
+ }
8051
7698
 
8052
- var attrs = {
8053
- stroke: mutedStrokeColor
8054
- };
7699
+ SubprocessCompatibility.prototype.handleImport = function(definitions) {
7700
+ if (!definitions.diagrams) {
7701
+ return;
7702
+ }
8055
7703
 
8056
- if (isOutgoing) {
7704
+ var self = this;
7705
+ this._definitions = definitions;
7706
+ this._processToDiagramMap = {};
8057
7707
 
8058
- // Reverse order again for correct end marker position
8059
- newWaypoints = newWaypoints.reverse();
8060
- } else {
7708
+ definitions.diagrams.forEach(function(diagram) {
7709
+ if (!diagram.plane || !diagram.plane.bpmnElement) {
7710
+ return;
7711
+ }
8061
7712
 
8062
- // Remove start marker for incoming flows
8063
- attrs.markerStart = undefined;
8064
- }
7713
+ self._processToDiagramMap[diagram.plane.bpmnElement.id] = diagram;
7714
+ });
8065
7715
 
8066
- eventBus.fire('render.connection', {
8067
- type: connection.type,
8068
- gfx: parentGfx,
8069
- element: {
8070
- type: connection.type,
8071
- waypoints: newWaypoints,
8072
- di: connection.di,
8073
- businessObject: connection.businessObject
8074
- },
8075
- attrs: attrs
8076
- });
8077
- };
7716
+ var newDiagrams = [];
7717
+ definitions.diagrams.forEach(function(diagram) {
7718
+ var createdDiagrams = self.createNewDiagrams(diagram.plane);
7719
+ Array.prototype.push.apply(newDiagrams, createdDiagrams);
7720
+ });
8078
7721
 
8079
- primary.incoming && primary.incoming.forEach(function(connection) {
8080
- drawFakeConnection(connection, false);
8081
- });
7722
+ newDiagrams.forEach(function(diagram) {
7723
+ self.movePlaneElementsToOrigin(diagram.plane);
7724
+ });
7725
+ };
8082
7726
 
8083
- primary.outgoing && primary.outgoing.forEach(function(connection) {
8084
- drawFakeConnection(connection, true);
8085
- });
8086
- }
8087
7727
 
8088
- eventBus.on([ 'render.shape' ], HIGH_RENDER_PRIORITY, function(evt, context) {
8089
- var element = context.element,
8090
- visuals = context.gfx;
7728
+ /**
7729
+ * Moves all DI elements from collapsed subprocesses to a new plane.
7730
+ *
7731
+ * @param {Object} plane
7732
+ * @return {Array} new diagrams created for the collapsed subprocesses
7733
+ */
7734
+ SubprocessCompatibility.prototype.createNewDiagrams = function(plane) {
7735
+ var self = this;
7736
+
7737
+ var collapsedElements = [];
7738
+ var elementsToMove = [];
8091
7739
 
8092
- if (element.isSecondary && element.primaryShape) {
8093
- drawFakeFlows(element, visuals);
7740
+ plane.get('planeElement').forEach(function(diElement) {
7741
+ var bo = diElement.bpmnElement;
7742
+ var parent = bo.$parent;
7743
+
7744
+ if (is$1(bo, 'bpmn:SubProcess') && !diElement.isExpanded) {
7745
+ collapsedElements.push(bo);
8094
7746
  }
8095
7747
 
7748
+ if (is$1(parent, 'bpmn:SubProcess') && parent !== plane.bpmnElement) {
7749
+
7750
+ // don't change the array while we iterate over it
7751
+ elementsToMove.push({ diElement: diElement, parent: parent });
7752
+ }
8096
7753
  });
8097
7754
 
8098
- }
7755
+ var newDiagrams = [];
8099
7756
 
8100
- SubprocessFlows.$inject = [ 'eventBus', 'config' ];
7757
+ elementsToMove.forEach(function(element) {
7758
+ var diElement = element.diElement;
7759
+ var parent = element.parent;
8101
7760
 
7761
+ // parent is expanded, get nearest collapsed parent
7762
+ while (parent && !collapsedElements.includes(parent)) {
7763
+ parent = parent.$parent;
7764
+ }
8102
7765
 
8103
- // helpers
7766
+ // false positive, all parents are expanded
7767
+ if (!parent) {
7768
+ return;
7769
+ }
8104
7770
 
8105
- function normalizeLength(fixedPoint, variablePoint, length) {
8106
- var dx = fixedPoint.x - variablePoint.x,
8107
- dy = fixedPoint.y - variablePoint.y,
8108
- totalDistance = Math.abs(dx) + Math.abs(dy);
7771
+ var diagram = self._processToDiagramMap[parent.id];
7772
+ if (!diagram) {
7773
+ diagram = self.createDiagram(parent);
7774
+ self._processToDiagramMap[parent.id] = diagram;
7775
+ newDiagrams.push(diagram);
7776
+ }
8109
7777
 
8110
- dx = dx / totalDistance;
8111
- dy = dy / totalDistance;
7778
+ self.moveToDiPlane(diElement, diagram.plane);
7779
+ });
8112
7780
 
8113
- dx *= length;
8114
- dy *= length;
7781
+ return newDiagrams;
7782
+ };
8115
7783
 
8116
- return {
8117
- x: fixedPoint.x - dx,
8118
- y: fixedPoint.y - dy
7784
+ SubprocessCompatibility.prototype.movePlaneElementsToOrigin = function(plane) {
7785
+ var elements = plane.get('planeElement');
7786
+
7787
+ // get bounding box of all elements
7788
+ var planeBounds = getPlaneBounds(plane);
7789
+
7790
+ var offset = {
7791
+ x: planeBounds.x - DEFAULT_POSITION.x,
7792
+ y: planeBounds.y - DEFAULT_POSITION.y
7793
+ };
7794
+
7795
+ elements.forEach(function(diElement) {
7796
+ if (diElement.waypoint) {
7797
+ diElement.waypoint.forEach(function(waypoint) {
7798
+ waypoint.x = waypoint.x - offset.x;
7799
+ waypoint.y = waypoint.y - offset.y;
7800
+ });
7801
+ } else if (diElement.bounds) {
7802
+ diElement.bounds.x = diElement.bounds.x - offset.x;
7803
+ diElement.bounds.y = diElement.bounds.y - offset.y;
7804
+ }
7805
+ });
7806
+ };
7807
+
7808
+
7809
+ SubprocessCompatibility.prototype.moveToDiPlane = function(diElement, newPlane) {
7810
+ var containingDiagram = findRootDiagram(diElement);
7811
+
7812
+ // remove DI from old Plane and add it to the new one
7813
+ var parentPlaneElement = containingDiagram.plane.get('planeElement');
7814
+ parentPlaneElement.splice(parentPlaneElement.indexOf(diElement), 1);
7815
+ newPlane.get('planeElement').push(diElement);
7816
+ };
7817
+
7818
+
7819
+ SubprocessCompatibility.prototype.createDiagram = function(bo) {
7820
+ var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
7821
+ var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
7822
+ plane: plane
7823
+ });
7824
+ plane.$parent = diagram;
7825
+ plane.bpmnElement = bo;
7826
+ diagram.$parent = this._definitions;
7827
+ this._definitions.diagrams.push(diagram);
7828
+ return diagram;
7829
+ };
7830
+
7831
+ SubprocessCompatibility.$inject = [ 'eventBus', 'moddle' ];
7832
+
7833
+
7834
+ // helpers
7835
+
7836
+ function findRootDiagram(element) {
7837
+ if (is$1(element, 'bpmndi:BPMNDiagram')) {
7838
+ return element;
7839
+ } else {
7840
+ return findRootDiagram(element.$parent);
7841
+ }
7842
+ }
7843
+
7844
+ function getPlaneBounds(plane) {
7845
+ var planeTrbl = {
7846
+ top: Infinity,
7847
+ right: -Infinity,
7848
+ bottom: -Infinity,
7849
+ left: Infinity
8119
7850
  };
7851
+
7852
+ plane.planeElement.forEach(function(element) {
7853
+ if (!element.bounds) {
7854
+ return;
7855
+ }
7856
+
7857
+ var trbl = asTRBL(element.bounds);
7858
+
7859
+ planeTrbl.top = Math.min(trbl.top, planeTrbl.top);
7860
+ planeTrbl.left = Math.min(trbl.left, planeTrbl.left);
7861
+ });
7862
+
7863
+ return asBounds(planeTrbl);
8120
7864
  }
8121
7865
 
8122
- var SubprocessNavigationModule = {
7866
+ var DrilldownModdule = {
8123
7867
  __depends__: [ OverlaysModule, ChangeSupportModule ],
8124
- __init__: [ 'subprocessElements', 'subprocessOverlays', 'subprocessCompatibility', 'subprocessCentering', 'subprocessFlows' ],
8125
- subprocessElements: [ 'type', SubprocessElements ],
8126
- subprocessOverlays: [ 'type', SubprocessOverlays ],
8127
- subprocessCompatibility: [ 'type', SubprocessCompatibility ],
8128
- subprocessCentering: [ 'type', SubprocessCentering ],
8129
- subprocessFlows: ['type', SubprocessFlows]
7868
+ __init__: [ 'drilldownOverlays', 'drilldownCentering', 'subprocessCompatibility'],
7869
+ drilldownOverlays: [ 'type', DrilldownOverlays ],
7870
+ drilldownCentering: [ 'type', DrilldownCentering ],
7871
+ subprocessCompatibility: [ 'type', SubprocessCompatibility ]
8130
7872
  };
8131
7873
 
8132
7874
  var CLASS_PATTERN = /^class /;
@@ -8768,6 +8510,9 @@
8768
8510
  var BASE_LAYER = 'base';
8769
8511
  var HIDDEN_MARKER = 'djs-element-hidden';
8770
8512
 
8513
+ // render plane contents behind additional layers
8514
+ var PLANE_LAYER_INDEX = -10;
8515
+
8771
8516
 
8772
8517
  var REQUIRED_MODEL_ATTRS = {
8773
8518
  shape: [ 'x', 'y', 'width', 'height' ],
@@ -8866,7 +8611,8 @@
8866
8611
  'connection.added',
8867
8612
  'shape.removed',
8868
8613
  'connection.removed',
8869
- 'elements.changed'
8614
+ 'elements.changed',
8615
+ 'plane.set'
8870
8616
  ], function() {
8871
8617
  delete this._cachedViewbox;
8872
8618
  }, this);
@@ -9007,9 +8753,7 @@
9007
8753
  throw new Error('must specify a name');
9008
8754
  }
9009
8755
 
9010
- var plane = this._planes[name];
9011
-
9012
- return plane;
8756
+ return this._planes[name];
9013
8757
  };
9014
8758
 
9015
8759
  /**
@@ -9038,7 +8782,7 @@
9038
8782
  };
9039
8783
  }
9040
8784
 
9041
- var svgLayer = this.getLayer(name);
8785
+ var svgLayer = this.getLayer(name, PLANE_LAYER_INDEX);
9042
8786
  classes$1(svgLayer).add(HIDDEN_MARKER);
9043
8787
 
9044
8788
  var plane = this._planes[name] = {
@@ -9647,9 +9391,10 @@
9647
9391
  if (!box) {
9648
9392
 
9649
9393
  // compute the inner box based on the
9650
- // diagrams default layer. This allows us to exclude
9394
+ // diagrams active plane. This allows us to exclude
9651
9395
  // external components, such as overlays
9652
- innerBox = this.getDefaultLayer().getBBox();
9396
+
9397
+ innerBox = (this._activePlane && this._activePlane.layer.getBBox()) || {};
9653
9398
 
9654
9399
  transform = transform$1(viewport);
9655
9400
  matrix = transform ? transform.matrix : createMatrix();
@@ -9665,10 +9410,10 @@
9665
9410
  height: outerBox.height / scale,
9666
9411
  scale: scale,
9667
9412
  inner: {
9668
- width: innerBox.width,
9669
- height: innerBox.height,
9670
- x: innerBox.x,
9671
- y: innerBox.y
9413
+ width: innerBox.width || 0,
9414
+ height: innerBox.height || 0,
9415
+ x: innerBox.x || 0,
9416
+ y: innerBox.y || 0
9672
9417
  },
9673
9418
  outer: outerBox
9674
9419
  };
@@ -20782,7 +20527,7 @@
20782
20527
  TranslateModule,
20783
20528
  SelectionModule,
20784
20529
  OverlaysModule,
20785
- SubprocessNavigationModule
20530
+ DrilldownModdule
20786
20531
  ];
20787
20532
 
20788
20533
  // default moddle extensions the viewer is composed of