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-modeler v9.0.0-subprocesses.1
2
+ * bpmn-js - bpmn-modeler 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() :
@@ -4366,6 +4366,9 @@
4366
4366
  var BASE_LAYER = 'base';
4367
4367
  var HIDDEN_MARKER = 'djs-element-hidden';
4368
4368
 
4369
+ // render plane contents behind additional layers
4370
+ var PLANE_LAYER_INDEX = -10;
4371
+
4369
4372
 
4370
4373
  var REQUIRED_MODEL_ATTRS = {
4371
4374
  shape: [ 'x', 'y', 'width', 'height' ],
@@ -4464,7 +4467,8 @@
4464
4467
  'connection.added',
4465
4468
  'shape.removed',
4466
4469
  'connection.removed',
4467
- 'elements.changed'
4470
+ 'elements.changed',
4471
+ 'plane.set'
4468
4472
  ], function() {
4469
4473
  delete this._cachedViewbox;
4470
4474
  }, this);
@@ -4605,9 +4609,7 @@
4605
4609
  throw new Error('must specify a name');
4606
4610
  }
4607
4611
 
4608
- var plane = this._planes[name];
4609
-
4610
- return plane;
4612
+ return this._planes[name];
4611
4613
  };
4612
4614
 
4613
4615
  /**
@@ -4636,7 +4638,7 @@
4636
4638
  };
4637
4639
  }
4638
4640
 
4639
- var svgLayer = this.getLayer(name);
4641
+ var svgLayer = this.getLayer(name, PLANE_LAYER_INDEX);
4640
4642
  classes(svgLayer).add(HIDDEN_MARKER);
4641
4643
 
4642
4644
  var plane = this._planes[name] = {
@@ -5245,9 +5247,10 @@
5245
5247
  if (!box) {
5246
5248
 
5247
5249
  // compute the inner box based on the
5248
- // diagrams default layer. This allows us to exclude
5250
+ // diagrams active plane. This allows us to exclude
5249
5251
  // external components, such as overlays
5250
- innerBox = this.getDefaultLayer().getBBox();
5252
+
5253
+ innerBox = (this._activePlane && this._activePlane.layer.getBBox()) || {};
5251
5254
 
5252
5255
  transform = transform$1(viewport);
5253
5256
  matrix = transform ? transform.matrix : createMatrix();
@@ -5263,10 +5266,10 @@
5263
5266
  height: outerBox.height / scale,
5264
5267
  scale: scale,
5265
5268
  inner: {
5266
- width: innerBox.width,
5267
- height: innerBox.height,
5268
- x: innerBox.x,
5269
- y: innerBox.y
5269
+ width: innerBox.width || 0,
5270
+ height: innerBox.height || 0,
5271
+ x: innerBox.x || 0,
5272
+ y: innerBox.y || 0
5270
5273
  },
5271
5274
  outer: outerBox
5272
5275
  };
@@ -18150,8 +18153,6 @@
18150
18153
  stroke = attrs.stroke || getStrokeColor$1(element, defaultStrokeColor);
18151
18154
 
18152
18155
  attrs = assign({
18153
- fill: fill,
18154
- stroke: stroke,
18155
18156
  markerEnd: marker('association-end', fill, stroke)
18156
18157
  }, attrs);
18157
18158
 
@@ -18165,8 +18166,6 @@
18165
18166
 
18166
18167
 
18167
18168
  attrs = assign({
18168
- fill: fill,
18169
- stroke: stroke,
18170
18169
  markerEnd: marker('association-end', fill, stroke)
18171
18170
  }, attrs);
18172
18171
 
@@ -19839,32 +19838,6 @@
19839
19838
  });
19840
19839
  }
19841
19840
 
19842
- var PLANE_PADDING = 50;
19843
-
19844
- function getPlaneBounds(plane) {
19845
- var planeTrbl = {
19846
- top: Infinity,
19847
- right: -Infinity,
19848
- bottom: -Infinity,
19849
- left: Infinity
19850
- };
19851
-
19852
- plane.planeElement.forEach(function(element) {
19853
- if (!element.bounds) {
19854
- return;
19855
- }
19856
-
19857
- var trbl = asTRBL(element.bounds);
19858
-
19859
- planeTrbl.top = Math.min(trbl.top, planeTrbl.top);
19860
- planeTrbl.left = Math.min(trbl.left, planeTrbl.left);
19861
- planeTrbl.right = Math.max(trbl.right, planeTrbl.right);
19862
- planeTrbl.bottom = Math.max(trbl.bottom, planeTrbl.bottom);
19863
- });
19864
-
19865
- return asBounds(planeTrbl);
19866
- }
19867
-
19868
19841
  function notYetDrawn(translate, semantic, refSemantic, property) {
19869
19842
  return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
19870
19843
  element: elementToString(refSemantic),
@@ -19919,39 +19892,18 @@
19919
19892
 
19920
19893
  // ROOT ELEMENT
19921
19894
  // handle the special case that we deal with a
19922
- // invisible root element (process or collaboration)
19895
+ // invisible root element (process, subprocess or collaboration)
19923
19896
  if (is$1(di, 'bpmndi:BPMNPlane')) {
19924
19897
 
19925
- if (is$1(semantic, 'bpmn:SubProcess')) {
19926
- var plane = this._canvas.createPlane(semantic.id, element);
19927
-
19928
- // Get size of expanded element
19929
- var bounds = getPlaneBounds(di);
19930
-
19931
- var primary = this._elementRegistry.get(semantic.id);
19932
- element = this._elementFactory.createShape(elementData(semantic, di, {
19933
- collapsed: false,
19934
- hidden: false,
19935
- x: bounds.x - PLANE_PADDING,
19936
- y: bounds.y - PLANE_PADDING,
19937
- width: bounds.width + PLANE_PADDING * 2,
19938
- height: bounds.height + PLANE_PADDING * 2,
19939
- isFrame: true
19940
- }));
19941
-
19942
- element.id = element.id + '_secondary';
19943
- element.isSecondary = true;
19944
- element.primaryShape = primary;
19898
+ // add a virtual element (not being drawn)
19899
+ element = this._elementFactory.createRoot(elementData(semantic, di));
19945
19900
 
19946
- this._canvas.addShape(element, plane.rootElement);
19901
+ // for subprocesses, the id is already defined on the collapsed shape
19902
+ if (is$1(semantic, 'bpmn:SubProcess')) {
19903
+ element.id = element.id + '_plane';
19947
19904
  }
19948
- else {
19949
-
19950
- // add a virtual element (not being drawn)
19951
- element = this._elementFactory.createRoot(elementData(semantic, di));
19952
19905
 
19953
- this._canvas.createPlane(semantic.id, element);
19954
- }
19906
+ this._canvas.createPlane(semantic.id, element);
19955
19907
  }
19956
19908
 
19957
19909
  // SHAPE
@@ -19962,7 +19914,7 @@
19962
19914
 
19963
19915
  hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
19964
19916
 
19965
- bounds = di.bounds;
19917
+ var bounds = di.bounds;
19966
19918
 
19967
19919
  element = this._elementFactory.createShape(elementData(semantic, di, {
19968
19920
  collapsed: collapsed,
@@ -21900,247 +21852,6 @@
21900
21852
  changeSupport: [ 'type', ChangeSupport ]
21901
21853
  };
21902
21854
 
21903
- function SubprocessElements(eventBus, elementRegistry, canvas, elementFactory) {
21904
- var attachBoundaries = function() {
21905
- var secondaryShapes = elementRegistry.filter(function(el) {
21906
- return is$1(el, 'bpmn:SubProcess') && el.isSecondary;
21907
- });
21908
-
21909
- secondaryShapes.forEach(function(process) {
21910
-
21911
- // Add Boundary events
21912
- if (process.primaryShape && process.primaryShape.attachers) {
21913
- process.primaryShape.attachers.forEach(function(boundary) {
21914
- var bo = getBusinessObject(boundary);
21915
-
21916
- var primary = process.primaryShape;
21917
-
21918
- var relativeXPos = (boundary.x + 15 - primary.x) / primary.width;
21919
- var relativeYPos = (boundary.y + 15 - primary.y) / primary.height;
21920
-
21921
- var dx = process.x + (process.width * relativeXPos) - 15;
21922
- var dy = process.y + (process.height * relativeYPos) - 15;
21923
-
21924
- var boundaryShape = elementFactory.createShape({
21925
- id: bo.id + '_secondary',
21926
- businessObject: bo,
21927
- type: 'bpmn:BoundaryEvent',
21928
- hidden: false,
21929
- x: dx,
21930
- y: dy,
21931
- width: 30,
21932
- height: 30,
21933
- isFrame: false,
21934
- isSecondary: true,
21935
- primaryShape: boundary,
21936
- di: boundary.di
21937
- });
21938
-
21939
- canvas.addShape(boundaryShape, process.parent);
21940
-
21941
- if (!process.attachers) {
21942
- process.attachers = [];
21943
- }
21944
-
21945
- process.attachers.push(boundaryShape);
21946
- });
21947
- }
21948
- });
21949
- };
21950
-
21951
- eventBus.on('import.done', attachBoundaries);
21952
- }
21953
-
21954
-
21955
- SubprocessElements.$inject = [ 'eventBus', 'elementRegistry', 'canvas', 'elementFactory' ];
21956
-
21957
- var defaultPosition = { x: 100, y: 50 };
21958
-
21959
- function SubprocessCentering(eventBus, canvas) {
21960
- var currentPlane = 'base';
21961
- var positionMap = {};
21962
-
21963
- eventBus.on('plane.set', function(event) {
21964
-
21965
- var currentViewbox = canvas.viewbox();
21966
- positionMap[currentPlane] = {
21967
- x: currentViewbox.x,
21968
- y: currentViewbox.y,
21969
- zoom: currentViewbox.scale
21970
- };
21971
-
21972
- var planeId = event.plane.name;
21973
- var storedViewbox = positionMap[planeId];
21974
-
21975
- if (!storedViewbox) {
21976
- if (!event.plane.rootElement.isImplicit) {
21977
- storedViewbox = {
21978
- x: 0,
21979
- y: 0,
21980
- zoom: 1
21981
- };
21982
- }
21983
- else {
21984
- var currentBoundingBox = canvas.getActiveLayer().getBBox();
21985
- storedViewbox = {
21986
- x: currentBoundingBox.x - defaultPosition.x,
21987
- y: currentBoundingBox.y - defaultPosition.y,
21988
- zoom: 1
21989
- };
21990
- }
21991
- }
21992
-
21993
- var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
21994
- dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
21995
-
21996
- if (dx !== 0 || dy !== 0) {
21997
- canvas.scroll({
21998
- dx: dx,
21999
- dy: dy
22000
- });
22001
- }
22002
-
22003
- if (storedViewbox.zoom !== currentViewbox.scale) {
22004
- canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
22005
- }
22006
-
22007
- currentPlane = planeId;
22008
- });
22009
- }
22010
-
22011
- SubprocessCentering.$inject = [ 'eventBus', 'canvas' ];
22012
-
22013
- function SubprocessCompatibility(eventBus, elementRegistry, canvas, moddle, elementFactory, bpmnjs) {
22014
- this._eventBus = eventBus;
22015
- this._elementRegistry = elementRegistry;
22016
- this._canvas = canvas;
22017
- this._bpmnjs = bpmnjs;
22018
- this._moddle = moddle;
22019
- this._elementFactory = elementFactory;
22020
-
22021
- var self = this;
22022
-
22023
- eventBus.on('import.done', 1500, function() {
22024
- self._handleImport();
22025
- });
22026
- }
22027
-
22028
- SubprocessCompatibility.prototype._handleImport = function() {
22029
- var elementRegistry = this._elementRegistry;
22030
- var canvas = this._canvas;
22031
- var elementFactory = this._elementFactory;
22032
- var self = this;
22033
- var legacyProcesses = elementRegistry.filter(function(element) {
22034
- return is$1(element, 'bpmn:SubProcess') && !isExpanded(element) && element.children && element.children.length;
22035
- });
22036
-
22037
- legacyProcesses.forEach(function(oldParent) {
22038
- var bo = getBusinessObject(oldParent);
22039
-
22040
- var newDiagram = self.createDiagram(bo);
22041
-
22042
- var newParent = elementFactory.createRoot(
22043
- {
22044
- id: bo.id,
22045
- type: bo.$type,
22046
- businessObject: bo,
22047
- di: newDiagram.plane
22048
- }
22049
- );
22050
-
22051
- newParent.id = newParent.id + '_plane';
22052
-
22053
- canvas.createPlane(bo.id, newParent);
22054
-
22055
- var elementsToChange = selfAndAllChildren(oldParent).filter(function(el) {
22056
- return el !== oldParent;
22057
- });
22058
-
22059
- self.moveElementsToRoot(elementsToChange);
22060
-
22061
- elementsToChange.forEach(function(el) {
22062
- if (el.parent === oldParent) {
22063
- el.parent = newParent;
22064
- }
22065
- el.hidden = el.parent && (el.parent.hidden || el.parent.collapsed);
22066
-
22067
- self.moveToDiPlane(el, newDiagram.plane);
22068
-
22069
- self._eventBus.fire('elements.changed', { elements: [el] });
22070
- });
22071
- });
22072
-
22073
- };
22074
-
22075
- SubprocessCompatibility.prototype.moveToDiPlane = function(element, newPlane) {
22076
- var di = getDi(element);
22077
- var containingDiagram = findRootDiagram(di);
22078
-
22079
- // Remove DI from old Plane and add it to the new one
22080
- var parentPlaneElement = containingDiagram.plane.get('planeElement');
22081
- parentPlaneElement.splice(parentPlaneElement.indexOf(di), 1);
22082
- newPlane.get('planeElement').push(di);
22083
- };
22084
-
22085
- SubprocessCompatibility.prototype.moveElementsToRoot = function(elements) {
22086
- var defaultPosition = { x: 180, y: 160 },
22087
- minX = Infinity,
22088
- minY = Infinity;
22089
-
22090
- elements.forEach(function(el) {
22091
- minX = Math.min(minX, el.x || Infinity);
22092
- minY = Math.min(minY, el.y || Infinity);
22093
- });
22094
-
22095
- var xOffset = defaultPosition.x - minX;
22096
- var yOffset = defaultPosition.y - minY;
22097
-
22098
- elements.forEach(function(el) {
22099
- if (el.waypoints) {
22100
- el.waypoints.forEach(function(waypoint) {
22101
- waypoint.x = waypoint.x + xOffset;
22102
- waypoint.y = waypoint.y + yOffset;
22103
- });
22104
- } else {
22105
- el.x = el.x + xOffset;
22106
- el.y = el.y + yOffset;
22107
- }
22108
- });
22109
- };
22110
-
22111
- SubprocessCompatibility.prototype.getDefinitions = function() {
22112
- return this._bpmnjs._definitions || [];
22113
- };
22114
-
22115
- SubprocessCompatibility.prototype.getDiagrams = function() {
22116
- return this.getDefinitions().diagrams || [];
22117
- };
22118
-
22119
- SubprocessCompatibility.prototype.createDiagram = function(bo) {
22120
- var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
22121
- var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
22122
- plane: plane
22123
- });
22124
- plane.$parent = diagram;
22125
- plane.bpmnElement = bo;
22126
- diagram.$parent = this.getDefinitions();
22127
- this.getDiagrams().push(diagram);
22128
- return diagram;
22129
- };
22130
-
22131
- SubprocessCompatibility.$inject = [ 'eventBus', 'elementRegistry', 'canvas', 'moddle', 'elementFactory', 'bpmnjs' ];
22132
-
22133
-
22134
- // Util
22135
-
22136
- var findRootDiagram = function(element) {
22137
- if (is$1(element, 'bpmndi:BPMNDiagram')) {
22138
- return element;
22139
- } else {
22140
- return findRootDiagram(element.$parent);
22141
- }
22142
- };
22143
-
22144
21855
  var css_escape = {exports: {}};
22145
21856
 
22146
21857
  /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
@@ -22266,24 +21977,26 @@
22266
21977
  }
22267
21978
 
22268
21979
  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>';
22269
- 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>';
22270
21980
 
22271
- function SubprocessOverlays(eventBus, elementRegistry, overlays, canvas) {
22272
-
22273
- function createBreadcrumbs(subProcess) {
22274
- var breadcrumbs = domify('<ul class="bjs-breadcrumbs"></ul>');
22275
- var drillUp = domify('<button class="bjs-drilldown">' + ARROW_UP_SVG + '</button>');
22276
- drillUp.addEventListener('click', function() {
22277
- var plane = canvas.findPlane(getBusinessObject(subProcess).id);
22278
- canvas.setActivePlane(plane);
22279
- });
22280
-
22281
- breadcrumbs.appendChild(drillUp);
21981
+ /**
21982
+ * Adds Overlays that allow switching planes on collapsed subprocesses.
21983
+ *
21984
+ * @param {eventBus} eventBus
21985
+ * @param {elementRegistry} elementRegistry
21986
+ * @param {overlays} overlays
21987
+ * @param {canvas} canvas
21988
+ */
21989
+ function DrilldownOverlays(eventBus, elementRegistry, overlays, canvas) {
21990
+ var breadcrumbs = domify('<ul class="bjs-breadcrumbs djs-element-hidden"></ul>');
21991
+ var container = canvas.getContainer();
21992
+ container.appendChild(breadcrumbs);
22282
21993
 
21994
+ function updateBreadcrumbs(plane) {
21995
+ var subProcess = elementRegistry.get(plane.name);
22283
21996
  var parents = getParentChain(subProcess);
22284
21997
 
22285
21998
  var path = parents.map(function(el) {
22286
- var title = escapeHTML(el.name) || el.id;
21999
+ var title = escapeHTML(el.name || el.id);
22287
22000
  var link = domify('<li><span class="bjs-crumb"><a title="' + title + '">' + title + '</a></span></li>');
22288
22001
 
22289
22002
  link.addEventListener('click', function() {
@@ -22298,20 +22011,26 @@
22298
22011
  return link;
22299
22012
  });
22300
22013
 
22014
+ breadcrumbs.innerHTML = '';
22015
+
22016
+ if (path.length > 1) {
22017
+ breadcrumbs.classList.remove('djs-element-hidden');
22018
+ } else {
22019
+ breadcrumbs.classList.add('djs-element-hidden');
22020
+ }
22021
+
22301
22022
  path.forEach(function(el) {
22302
22023
  breadcrumbs.appendChild(el);
22303
22024
  });
22304
-
22305
- overlays.add(subProcess, {
22306
- position: {
22307
- top: -30,
22308
- left: -10
22309
- },
22310
- html: breadcrumbs
22311
- });
22312
22025
  }
22313
22026
 
22314
- var createDrilldown = function(element) {
22027
+ eventBus.on('plane.set', function(event) {
22028
+ var plane = event.plane;
22029
+
22030
+ updateBreadcrumbs(plane);
22031
+ });
22032
+
22033
+ var createOverlay = function(element) {
22315
22034
  var html = domify('<button class="bjs-drilldown">' + ARROW_DOWN_SVG + '</button>');
22316
22035
 
22317
22036
  html.addEventListener('click', function() {
@@ -22332,11 +22051,7 @@
22332
22051
  if (is$1(element, 'bpmn:SubProcess')
22333
22052
  && element.collapsed
22334
22053
  && canvas.getPlane(element.id)) {
22335
- createDrilldown(element);
22336
- }
22337
-
22338
- if (is$1(element, 'bpmn:SubProcess') && element.isSecondary) {
22339
- createBreadcrumbs(element);
22054
+ createOverlay(element);
22340
22055
  }
22341
22056
  });
22342
22057
  };
@@ -22348,9 +22063,10 @@
22348
22063
  });
22349
22064
  }
22350
22065
 
22351
- SubprocessOverlays.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
22066
+ DrilldownOverlays.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
22352
22067
 
22353
22068
 
22069
+ // helpers
22354
22070
  var getParentChain = function(child) {
22355
22071
  var bo = getBusinessObject(child);
22356
22072
 
@@ -22365,124 +22081,244 @@
22365
22081
  return parents.reverse();
22366
22082
  };
22367
22083
 
22368
- var FLOW_LENGTH = 50;
22369
- var HIGH_RENDER_PRIORITY = 2000;
22084
+ /**
22085
+ * Move collapsed subprocesses into view when drilling down. Zoom and scroll
22086
+ * are saved in a session.
22087
+ *
22088
+ * @param {eventBus} eventBus
22089
+ * @param {canvas} canvas
22090
+ */
22091
+ function DrilldownCentering(eventBus, canvas) {
22092
+ var currentPlane = 'base';
22093
+ var positionMap = {};
22370
22094
 
22371
- function SubprocessFlows(eventBus, config) {
22095
+ eventBus.on('plane.set', function(event) {
22096
+ var currentViewbox = canvas.viewbox();
22097
+ positionMap[currentPlane] = {
22098
+ x: currentViewbox.x,
22099
+ y: currentViewbox.y,
22100
+ zoom: currentViewbox.scale
22101
+ };
22372
22102
 
22373
- var mutedStrokeColor = (config && config.mutedStrokeColor) || '#dddddd';
22103
+ var planeId = event.plane.name;
22104
+ var storedViewbox = positionMap[planeId] || { x: 0, y: 0, zoom: 1 };
22374
22105
 
22375
- function drawFakeFlows(element, parentGfx) {
22376
- var primary = element.primaryShape;
22106
+ var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
22107
+ dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
22377
22108
 
22378
- var drawFakeConnection = function(connection, isOutgoing) {
22109
+ if (dx !== 0 || dy !== 0) {
22110
+ canvas.scroll({
22111
+ dx: dx,
22112
+ dy: dy
22113
+ });
22114
+ }
22379
22115
 
22380
- var segment;
22381
- if (isOutgoing) {
22382
- segment = connection.waypoints.slice(0, 2);
22116
+ if (storedViewbox.zoom !== currentViewbox.scale) {
22117
+ canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
22118
+ }
22383
22119
 
22384
- // Reverse order for normalizing
22385
- segment = segment.reverse();
22386
- } else {
22387
- segment = connection.waypoints.slice(connection.waypoints.length - 2);
22388
- }
22120
+ currentPlane = planeId;
22121
+ });
22122
+ }
22389
22123
 
22390
- var endpoint = segment[1];
22124
+ DrilldownCentering.$inject = [ 'eventBus', 'canvas' ];
22391
22125
 
22392
- var relativePosition = {
22393
- x: (endpoint.x - primary.x) / primary.width,
22394
- y: (endpoint.y - primary.y) / primary.height
22395
- };
22126
+ var DEFAULT_POSITION = {
22127
+ x: 180,
22128
+ y: 160
22129
+ };
22396
22130
 
22397
- var anchorPoint = {
22398
- x: endpoint.x - (element.width * relativePosition.x),
22399
- y: endpoint.y - (element.height * relativePosition.y)
22400
- };
22131
+ /**
22132
+ * Hook into `import.render.start` and create new planes for diagrams with
22133
+ * collapsed subprocesses and all dis on the same plane.
22134
+ *
22135
+ * @param {eventBus} eventBus
22136
+ * @param {moddle} moddle
22137
+ */
22138
+ function SubprocessCompatibility(eventBus, moddle) {
22139
+ this._eventBus = eventBus;
22140
+ this._moddle = moddle;
22401
22141
 
22402
- var newWaypoints = segment.map(function(el) {
22403
- return { x: el.x - anchorPoint.x, y: el.y - anchorPoint.y };
22404
- });
22142
+ var self = this;
22405
22143
 
22406
- newWaypoints[0] = normalizeLength(newWaypoints[1], newWaypoints[0], FLOW_LENGTH);
22144
+ eventBus.on('import.render.start', 1500, function(e, context) {
22145
+ self.handleImport(context.definitions);
22146
+ });
22147
+ }
22407
22148
 
22408
- var attrs = {
22409
- stroke: mutedStrokeColor
22410
- };
22149
+ SubprocessCompatibility.prototype.handleImport = function(definitions) {
22150
+ if (!definitions.diagrams) {
22151
+ return;
22152
+ }
22411
22153
 
22412
- if (isOutgoing) {
22154
+ var self = this;
22155
+ this._definitions = definitions;
22156
+ this._processToDiagramMap = {};
22413
22157
 
22414
- // Reverse order again for correct end marker position
22415
- newWaypoints = newWaypoints.reverse();
22416
- } else {
22158
+ definitions.diagrams.forEach(function(diagram) {
22159
+ if (!diagram.plane || !diagram.plane.bpmnElement) {
22160
+ return;
22161
+ }
22417
22162
 
22418
- // Remove start marker for incoming flows
22419
- attrs.markerStart = undefined;
22420
- }
22163
+ self._processToDiagramMap[diagram.plane.bpmnElement.id] = diagram;
22164
+ });
22421
22165
 
22422
- eventBus.fire('render.connection', {
22423
- type: connection.type,
22424
- gfx: parentGfx,
22425
- element: {
22426
- type: connection.type,
22427
- waypoints: newWaypoints,
22428
- di: connection.di,
22429
- businessObject: connection.businessObject
22430
- },
22431
- attrs: attrs
22432
- });
22433
- };
22166
+ var newDiagrams = [];
22167
+ definitions.diagrams.forEach(function(diagram) {
22168
+ var createdDiagrams = self.createNewDiagrams(diagram.plane);
22169
+ Array.prototype.push.apply(newDiagrams, createdDiagrams);
22170
+ });
22434
22171
 
22435
- primary.incoming && primary.incoming.forEach(function(connection) {
22436
- drawFakeConnection(connection, false);
22437
- });
22172
+ newDiagrams.forEach(function(diagram) {
22173
+ self.movePlaneElementsToOrigin(diagram.plane);
22174
+ });
22175
+ };
22438
22176
 
22439
- primary.outgoing && primary.outgoing.forEach(function(connection) {
22440
- drawFakeConnection(connection, true);
22441
- });
22442
- }
22443
22177
 
22444
- eventBus.on([ 'render.shape' ], HIGH_RENDER_PRIORITY, function(evt, context) {
22445
- var element = context.element,
22446
- visuals = context.gfx;
22178
+ /**
22179
+ * Moves all DI elements from collapsed subprocesses to a new plane.
22180
+ *
22181
+ * @param {Object} plane
22182
+ * @return {Array} new diagrams created for the collapsed subprocesses
22183
+ */
22184
+ SubprocessCompatibility.prototype.createNewDiagrams = function(plane) {
22185
+ var self = this;
22186
+
22187
+ var collapsedElements = [];
22188
+ var elementsToMove = [];
22447
22189
 
22448
- if (element.isSecondary && element.primaryShape) {
22449
- drawFakeFlows(element, visuals);
22190
+ plane.get('planeElement').forEach(function(diElement) {
22191
+ var bo = diElement.bpmnElement;
22192
+ var parent = bo.$parent;
22193
+
22194
+ if (is$1(bo, 'bpmn:SubProcess') && !diElement.isExpanded) {
22195
+ collapsedElements.push(bo);
22450
22196
  }
22451
22197
 
22198
+ if (is$1(parent, 'bpmn:SubProcess') && parent !== plane.bpmnElement) {
22199
+
22200
+ // don't change the array while we iterate over it
22201
+ elementsToMove.push({ diElement: diElement, parent: parent });
22202
+ }
22452
22203
  });
22453
22204
 
22454
- }
22205
+ var newDiagrams = [];
22455
22206
 
22456
- SubprocessFlows.$inject = [ 'eventBus', 'config' ];
22207
+ elementsToMove.forEach(function(element) {
22208
+ var diElement = element.diElement;
22209
+ var parent = element.parent;
22457
22210
 
22211
+ // parent is expanded, get nearest collapsed parent
22212
+ while (parent && !collapsedElements.includes(parent)) {
22213
+ parent = parent.$parent;
22214
+ }
22458
22215
 
22459
- // helpers
22216
+ // false positive, all parents are expanded
22217
+ if (!parent) {
22218
+ return;
22219
+ }
22460
22220
 
22461
- function normalizeLength(fixedPoint, variablePoint, length) {
22462
- var dx = fixedPoint.x - variablePoint.x,
22463
- dy = fixedPoint.y - variablePoint.y,
22464
- totalDistance = Math.abs(dx) + Math.abs(dy);
22221
+ var diagram = self._processToDiagramMap[parent.id];
22222
+ if (!diagram) {
22223
+ diagram = self.createDiagram(parent);
22224
+ self._processToDiagramMap[parent.id] = diagram;
22225
+ newDiagrams.push(diagram);
22226
+ }
22465
22227
 
22466
- dx = dx / totalDistance;
22467
- dy = dy / totalDistance;
22228
+ self.moveToDiPlane(diElement, diagram.plane);
22229
+ });
22468
22230
 
22469
- dx *= length;
22470
- dy *= length;
22231
+ return newDiagrams;
22232
+ };
22471
22233
 
22472
- return {
22473
- x: fixedPoint.x - dx,
22474
- y: fixedPoint.y - dy
22234
+ SubprocessCompatibility.prototype.movePlaneElementsToOrigin = function(plane) {
22235
+ var elements = plane.get('planeElement');
22236
+
22237
+ // get bounding box of all elements
22238
+ var planeBounds = getPlaneBounds(plane);
22239
+
22240
+ var offset = {
22241
+ x: planeBounds.x - DEFAULT_POSITION.x,
22242
+ y: planeBounds.y - DEFAULT_POSITION.y
22475
22243
  };
22244
+
22245
+ elements.forEach(function(diElement) {
22246
+ if (diElement.waypoint) {
22247
+ diElement.waypoint.forEach(function(waypoint) {
22248
+ waypoint.x = waypoint.x - offset.x;
22249
+ waypoint.y = waypoint.y - offset.y;
22250
+ });
22251
+ } else if (diElement.bounds) {
22252
+ diElement.bounds.x = diElement.bounds.x - offset.x;
22253
+ diElement.bounds.y = diElement.bounds.y - offset.y;
22254
+ }
22255
+ });
22256
+ };
22257
+
22258
+
22259
+ SubprocessCompatibility.prototype.moveToDiPlane = function(diElement, newPlane) {
22260
+ var containingDiagram = findRootDiagram(diElement);
22261
+
22262
+ // remove DI from old Plane and add it to the new one
22263
+ var parentPlaneElement = containingDiagram.plane.get('planeElement');
22264
+ parentPlaneElement.splice(parentPlaneElement.indexOf(diElement), 1);
22265
+ newPlane.get('planeElement').push(diElement);
22266
+ };
22267
+
22268
+
22269
+ SubprocessCompatibility.prototype.createDiagram = function(bo) {
22270
+ var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
22271
+ var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
22272
+ plane: plane
22273
+ });
22274
+ plane.$parent = diagram;
22275
+ plane.bpmnElement = bo;
22276
+ diagram.$parent = this._definitions;
22277
+ this._definitions.diagrams.push(diagram);
22278
+ return diagram;
22279
+ };
22280
+
22281
+ SubprocessCompatibility.$inject = [ 'eventBus', 'moddle' ];
22282
+
22283
+
22284
+ // helpers
22285
+
22286
+ function findRootDiagram(element) {
22287
+ if (is$1(element, 'bpmndi:BPMNDiagram')) {
22288
+ return element;
22289
+ } else {
22290
+ return findRootDiagram(element.$parent);
22291
+ }
22292
+ }
22293
+
22294
+ function getPlaneBounds(plane) {
22295
+ var planeTrbl = {
22296
+ top: Infinity,
22297
+ right: -Infinity,
22298
+ bottom: -Infinity,
22299
+ left: Infinity
22300
+ };
22301
+
22302
+ plane.planeElement.forEach(function(element) {
22303
+ if (!element.bounds) {
22304
+ return;
22305
+ }
22306
+
22307
+ var trbl = asTRBL(element.bounds);
22308
+
22309
+ planeTrbl.top = Math.min(trbl.top, planeTrbl.top);
22310
+ planeTrbl.left = Math.min(trbl.left, planeTrbl.left);
22311
+ });
22312
+
22313
+ return asBounds(planeTrbl);
22476
22314
  }
22477
22315
 
22478
- var SubprocessNavigationModule = {
22316
+ var DrilldownModdule = {
22479
22317
  __depends__: [ OverlaysModule, ChangeSupportModule ],
22480
- __init__: [ 'subprocessElements', 'subprocessOverlays', 'subprocessCompatibility', 'subprocessCentering', 'subprocessFlows' ],
22481
- subprocessElements: [ 'type', SubprocessElements ],
22482
- subprocessOverlays: [ 'type', SubprocessOverlays ],
22483
- subprocessCompatibility: [ 'type', SubprocessCompatibility ],
22484
- subprocessCentering: [ 'type', SubprocessCentering ],
22485
- subprocessFlows: ['type', SubprocessFlows]
22318
+ __init__: [ 'drilldownOverlays', 'drilldownCentering', 'subprocessCompatibility'],
22319
+ drilldownOverlays: [ 'type', DrilldownOverlays ],
22320
+ drilldownCentering: [ 'type', DrilldownCentering ],
22321
+ subprocessCompatibility: [ 'type', SubprocessCompatibility ]
22486
22322
  };
22487
22323
 
22488
22324
  /**
@@ -22544,7 +22380,7 @@
22544
22380
  translate,
22545
22381
  SelectionModule,
22546
22382
  OverlaysModule,
22547
- SubprocessNavigationModule
22383
+ DrilldownModdule
22548
22384
  ];
22549
22385
 
22550
22386
  // default moddle extensions the viewer is composed of