bpmn-js 9.0.0-subprocesses.3 → 9.0.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/assets/bpmn-js.css +44 -7
  3. package/dist/assets/diagram-js.css +1 -1
  4. package/dist/bpmn-modeler.development.js +2424 -1130
  5. package/dist/bpmn-modeler.production.min.js +8 -8
  6. package/dist/bpmn-navigated-viewer.development.js +990 -317
  7. package/dist/bpmn-navigated-viewer.production.min.js +6 -6
  8. package/dist/bpmn-viewer.development.js +989 -316
  9. package/dist/bpmn-viewer.production.min.js +6 -6
  10. package/lib/BaseViewer.js +1 -1
  11. package/lib/draw/BpmnRenderer.js +8 -7
  12. package/lib/features/auto-resize/BpmnAutoResizeProvider.js +6 -0
  13. package/lib/features/copy-paste/BpmnCopyPaste.js +1 -0
  14. package/lib/features/di-ordering/BpmnDiOrdering.js +15 -11
  15. package/lib/features/drilldown/DrilldownBreadcrumbs.js +122 -0
  16. package/lib/features/drilldown/DrilldownCentering.js +87 -10
  17. package/lib/features/drilldown/DrilldownOverlayBehavior.js +181 -0
  18. package/lib/features/drilldown/SubprocessCompatibility.js +15 -7
  19. package/lib/features/drilldown/index.js +7 -4
  20. package/lib/features/label-editing/LabelEditingProvider.js +1 -1
  21. package/lib/features/label-editing/cmd/UpdateLabelHandler.js +29 -2
  22. package/lib/features/modeling/BpmnFactory.js +5 -1
  23. package/lib/features/modeling/BpmnUpdater.js +43 -1
  24. package/lib/features/modeling/ElementFactory.js +4 -0
  25. package/lib/features/modeling/behavior/CreateParticipantBehavior.js +59 -84
  26. package/lib/features/modeling/behavior/DropOnFlowBehavior.js +2 -2
  27. package/lib/features/modeling/behavior/GroupBehavior.js +6 -18
  28. package/lib/features/modeling/behavior/RemoveEmbeddedLabelBoundsBehavior.js +34 -0
  29. package/lib/features/modeling/behavior/SubProcessPlaneBehavior.js +557 -0
  30. package/lib/features/modeling/behavior/ToggleCollapseConnectionBehaviour.js +74 -0
  31. package/lib/features/modeling/behavior/UnclaimIdBehavior.js +3 -1
  32. package/lib/features/modeling/behavior/index.js +27 -18
  33. package/lib/features/modeling/cmd/SetColorHandler.js +23 -6
  34. package/lib/features/modeling/cmd/UpdateCanvasRootHandler.js +4 -2
  35. package/lib/features/modeling/util/ModelingUtil.js +2 -20
  36. package/lib/features/ordering/BpmnOrderingProvider.js +3 -3
  37. package/lib/features/palette/PaletteProvider.js +1 -1
  38. package/lib/features/popup-menu/ReplaceMenuProvider.js +1 -1
  39. package/lib/import/BpmnImporter.js +15 -9
  40. package/lib/import/Importer.js +130 -10
  41. package/lib/util/DrilldownUtil.js +66 -0
  42. package/lib/util/ModelUtil.js +19 -0
  43. package/package.json +2 -2
  44. package/lib/features/drilldown/DrilldownOverlays.js +0 -110
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * bpmn-js - bpmn-modeler v9.0.0-subprocesses.3
2
+ * bpmn-js - bpmn-modeler v9.0.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-11-19
11
+ * Date: 2022-02-23
12
12
  */
13
13
  (function (global, factory) {
14
14
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -564,7 +564,7 @@
564
564
  *
565
565
  * const matcher = matchPattern({ id: 1 });
566
566
  *
567
- * var element = find(elements, matcher);
567
+ * let element = find(elements, matcher);
568
568
  *
569
569
  * @param {Object} pattern
570
570
  *
@@ -600,8 +600,11 @@
600
600
  }
601
601
 
602
602
  /**
603
- * Debounce fn, calling it only once if
604
- * the given time elapsed between calls.
603
+ * Debounce fn, calling it only once if the given time
604
+ * elapsed between calls.
605
+ *
606
+ * Lodash-style the function exposes methods to `#clear`
607
+ * and `#flush` to control internal behavior.
605
608
  *
606
609
  * @param {Function} fn
607
610
  * @param {Number} timeout
@@ -614,23 +617,39 @@
614
617
  var lastThis;
615
618
  var lastNow;
616
619
 
617
- function fire() {
620
+ function fire(force) {
618
621
  var now = Date.now();
619
- var scheduledDiff = lastNow + timeout - now;
622
+ var scheduledDiff = force ? 0 : lastNow + timeout - now;
620
623
 
621
624
  if (scheduledDiff > 0) {
622
625
  return schedule(scheduledDiff);
623
626
  }
624
627
 
625
628
  fn.apply(lastThis, lastArgs);
626
- timer = lastNow = lastArgs = lastThis = undefined;
629
+ clear();
627
630
  }
628
631
 
629
632
  function schedule(timeout) {
630
633
  timer = setTimeout(fire, timeout);
631
634
  }
632
635
 
633
- return function () {
636
+ function clear() {
637
+ if (timer) {
638
+ clearTimeout(timer);
639
+ }
640
+
641
+ timer = lastNow = lastArgs = lastThis = undefined;
642
+ }
643
+
644
+ function flush() {
645
+ if (timer) {
646
+ fire(true);
647
+ }
648
+
649
+ clear();
650
+ }
651
+
652
+ function callback() {
634
653
  lastNow = Date.now();
635
654
 
636
655
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -643,7 +662,11 @@
643
662
  if (!timer) {
644
663
  schedule(timeout);
645
664
  }
646
- };
665
+ }
666
+
667
+ callback.flush = flush;
668
+ callback.cancel = clear;
669
+ return callback;
647
670
  }
648
671
  /**
649
672
  * Bind function against target <this>.
@@ -4364,7 +4387,6 @@
4364
4387
  }
4365
4388
 
4366
4389
  var BASE_LAYER = 'base';
4367
- var HIDDEN_MARKER = 'djs-element-hidden';
4368
4390
 
4369
4391
  // render plane contents behind utility layers
4370
4392
  var PLANE_LAYER_INDEX = 0;
@@ -4395,6 +4417,12 @@
4395
4417
  this._elementRegistry = elementRegistry;
4396
4418
  this._graphicsFactory = graphicsFactory;
4397
4419
 
4420
+ this._rootsIdx = 0;
4421
+
4422
+ this._layers = {};
4423
+ this._planes = [];
4424
+ this._rootElement = null;
4425
+
4398
4426
  this._init(config || {});
4399
4427
  }
4400
4428
 
@@ -4432,9 +4460,6 @@
4432
4460
 
4433
4461
  var viewport = this._viewport = createGroup(svg, 'viewport');
4434
4462
 
4435
- this._layers = {};
4436
- this._planes = {};
4437
-
4438
4463
  // debounce canvas.viewbox.changed events
4439
4464
  // for smoother diagram interaction
4440
4465
  if (config.deferUpdate !== false) {
@@ -4469,7 +4494,7 @@
4469
4494
  'shape.removed',
4470
4495
  'connection.removed',
4471
4496
  'elements.changed',
4472
- 'plane.set'
4497
+ 'root.set'
4473
4498
  ], function() {
4474
4499
  delete this._cachedViewbox;
4475
4500
  }, this);
@@ -4494,7 +4519,7 @@
4494
4519
  delete this._container;
4495
4520
  delete this._layers;
4496
4521
  delete this._planes;
4497
- delete this._activePlane;
4522
+ delete this._rootElement;
4498
4523
  delete this._viewport;
4499
4524
  };
4500
4525
 
@@ -4509,15 +4534,15 @@
4509
4534
  var type = getType(element);
4510
4535
 
4511
4536
  if (type === 'root') {
4512
- self.setRootElementForPlane(null, self.findPlane(element), true);
4537
+ self.removeRootElement(element);
4513
4538
  } else {
4514
4539
  self._removeElement(element, type);
4515
4540
  }
4516
4541
  });
4517
4542
 
4518
4543
  // remove all planes
4519
- this._activePlane = null;
4520
- this._planes = {};
4544
+ this._planes = [];
4545
+ this._rootElement = null;
4521
4546
 
4522
4547
  // force recomputation of view box
4523
4548
  delete this._cachedViewbox;
@@ -4598,140 +4623,75 @@
4598
4623
 
4599
4624
  };
4600
4625
 
4601
- /**
4602
- * Returns a plane that is used to draw elements on it.
4603
- *
4604
- * @param {string} name
4605
- *
4606
- * @return {Object} plane descriptor with { layer, rootElement, name }
4607
- */
4608
- Canvas.prototype.getPlane = function(name) {
4609
- if (!name) {
4610
- throw new Error('must specify a name');
4611
- }
4612
-
4613
- return this._planes[name];
4614
- };
4615
-
4616
- /**
4617
- * Creates a plane that is used to draw elements on it. If no
4618
- * root element is provided, an implicit root will be used.
4619
- *
4620
- * @param {string} name
4621
- * @param {Object|djs.model.Root} [rootElement] optional root element
4622
- *
4623
- * @return {Object} plane descriptor with { layer, rootElement, name }
4624
- */
4625
- Canvas.prototype.createPlane = function(name, rootElement) {
4626
- if (!name) {
4627
- throw new Error('must specify a name');
4628
- }
4629
-
4630
- if (this._planes[name]) {
4631
- throw new Error('plane ' + name + ' already exists');
4632
- }
4633
-
4634
- if (!rootElement) {
4635
- rootElement = {
4636
- id: '__implicitroot' + name,
4637
- children: [],
4638
- isImplicit: true
4639
- };
4640
- }
4641
-
4642
- var svgLayer = this.getLayer(name, PLANE_LAYER_INDEX);
4643
- classes(svgLayer).add(HIDDEN_MARKER);
4644
-
4645
- var plane = this._planes[name] = {
4646
- layer: svgLayer,
4647
- name: name,
4648
- rootElement: null
4649
- };
4650
-
4651
- this.setRootElementForPlane(rootElement, plane);
4652
-
4653
- return plane;
4654
- };
4655
-
4656
- /**
4657
- * Sets the active plane and hides the previously active plane.
4658
- *
4659
- * @param {string|Object} plane
4660
- *
4661
- * @return {Object} plane descriptor with { layer, rootElement, name }
4662
- */
4663
- Canvas.prototype.setActivePlane = function(plane) {
4664
- if (!plane) {
4665
- throw new Error('must specify a plane');
4666
- }
4667
4626
 
4668
- if (typeof plane === 'string') {
4669
- plane = this.getPlane(plane);
4670
- }
4671
-
4672
- // hide previous Plane
4673
- if (this._activePlane) {
4674
- classes(this._activePlane.layer).add(HIDDEN_MARKER);
4675
- }
4627
+ Canvas.prototype._removeLayer = function(name) {
4676
4628
 
4677
- this._activePlane = plane;
4629
+ var layer = this._layers[name];
4678
4630
 
4679
- // show current Plane
4680
- classes(plane.layer).remove(HIDDEN_MARKER);
4631
+ if (layer) {
4632
+ delete this._layers[name];
4681
4633
 
4682
- if (plane.rootElement) {
4683
- this._elementRegistry.updateGraphics(plane.rootElement, this._svg, true);
4634
+ remove$1(layer.group);
4684
4635
  }
4685
-
4686
- this._eventBus.fire('plane.set', { plane: plane });
4687
-
4688
- return plane;
4689
4636
  };
4690
4637
 
4691
4638
  /**
4692
- * Returns the currently active layer
4639
+ * Returns the currently active layer. Can be null.
4693
4640
  *
4694
- * @returns {SVGElement}
4641
+ * @returns {SVGElement|null}
4695
4642
  */
4696
-
4697
4643
  Canvas.prototype.getActiveLayer = function() {
4698
- return this.getActivePlane().layer;
4699
- };
4644
+ var plane = this._findPlaneForRoot(this.getRootElement());
4700
4645
 
4701
- /**
4702
- * Returns the currently active plane.
4703
- *
4704
- * @return {Object} plane descriptor with { layer, rootElement, name }
4705
- */
4706
- Canvas.prototype.getActivePlane = function() {
4707
- var plane = this._activePlane;
4708
4646
  if (!plane) {
4709
- plane = this.createPlane(BASE_LAYER);
4710
- this.setActivePlane(BASE_LAYER);
4647
+ return null;
4711
4648
  }
4712
4649
 
4713
- return plane;
4650
+ return plane.layer;
4714
4651
  };
4715
4652
 
4653
+
4716
4654
  /**
4717
4655
  * Returns the plane which contains the given element.
4718
4656
  *
4719
4657
  * @param {string|djs.model.Base} element
4720
4658
  *
4721
- * @return {Object} plane descriptor with { layer, rootElement, name }
4659
+ * @return {djs.model.Base} root for element
4722
4660
  */
4723
- Canvas.prototype.findPlane = function(element) {
4661
+ Canvas.prototype.findRoot = function(element) {
4724
4662
  if (typeof element === 'string') {
4725
4663
  element = this._elementRegistry.get(element);
4726
4664
  }
4727
4665
 
4728
- var root = findRoot(element);
4666
+ if (!element) {
4667
+ return;
4668
+ }
4669
+
4670
+ var plane = this._findPlaneForRoot(
4671
+ findRoot(element)
4672
+ ) || {};
4729
4673
 
4674
+ return plane.rootElement;
4675
+ };
4676
+
4677
+ /**
4678
+ * Return a list of all root elements on the diagram.
4679
+ *
4680
+ * @return {djs.model.Root[]}
4681
+ */
4682
+ Canvas.prototype.getRootElements = function() {
4683
+ return this._planes.map(function(plane) {
4684
+ return plane.rootElement;
4685
+ });
4686
+ };
4687
+
4688
+ Canvas.prototype._findPlaneForRoot = function(rootElement) {
4730
4689
  return find(this._planes, function(plane) {
4731
- return plane.rootElement === root;
4690
+ return plane.rootElement === rootElement;
4732
4691
  });
4733
4692
  };
4734
4693
 
4694
+
4735
4695
  /**
4736
4696
  * Returns the html element that encloses the
4737
4697
  * drawing canvas.
@@ -4852,95 +4812,205 @@
4852
4812
  }
4853
4813
  };
4854
4814
 
4815
+ /**
4816
+ * Returns the current root element.
4817
+ *
4818
+ * Supports two different modes for handling root elements:
4819
+ *
4820
+ * 1. if no root element has been added before, an implicit root will be added
4821
+ * and returned. This is used in applications that don't require explicit
4822
+ * root elements.
4823
+ *
4824
+ * 2. when root elements have been added before calling `getRootElement`,
4825
+ * root elements can be null. This is used for applications that want to manage
4826
+ * root elements themselves.
4827
+ *
4828
+ * @returns {Object|djs.model.Root|null} rootElement.
4829
+ */
4855
4830
  Canvas.prototype.getRootElement = function() {
4856
- var plane = this.getActivePlane();
4831
+ var rootElement = this._rootElement;
4857
4832
 
4858
- return plane.rootElement;
4833
+ // can return null if root elements are present but none was set yet
4834
+ if (rootElement || this._planes.length) {
4835
+ return rootElement;
4836
+ }
4837
+
4838
+ return this.setRootElement(this.addRootElement(null));
4859
4839
  };
4860
4840
 
4841
+ /**
4842
+ * Adds a given root element and returns it.
4843
+ *
4844
+ * @param {Object|djs.model.Root} rootElement
4845
+ *
4846
+ * @return {Object|djs.model.Root} rootElement
4847
+ */
4848
+
4849
+ Canvas.prototype.addRootElement = function(rootElement) {
4850
+ var idx = this._rootsIdx++;
4861
4851
 
4852
+ if (!rootElement) {
4853
+ rootElement = {
4854
+ id: '__implicitroot_' + idx,
4855
+ children: [],
4856
+ isImplicit: true
4857
+ };
4858
+ }
4862
4859
 
4863
- // root element handling //////////////////////
4860
+ var layerName = rootElement.layer = 'root-' + idx;
4861
+
4862
+ this._ensureValid('root', rootElement);
4863
+
4864
+ var layer = this.getLayer(layerName, PLANE_LAYER_INDEX);
4865
+
4866
+ attr(layer, 'display', 'none');
4867
+
4868
+ this._addRoot(rootElement, layer);
4869
+
4870
+ this._planes.push({
4871
+ rootElement: rootElement,
4872
+ layer: layer
4873
+ });
4874
+
4875
+ return rootElement;
4876
+ };
4864
4877
 
4865
4878
  /**
4866
- * Sets a given element as the new root element for the canvas
4867
- * and returns the new root element.
4879
+ * Removes a given rootElement and returns it.
4868
4880
  *
4869
- * @param {Object|djs.model.Root} element
4870
- * @param {boolean} [override] whether to override the current root element, if any
4881
+ * @param {djs.model.Root|String} rootElement
4871
4882
  *
4872
- * @return {Object|djs.model.Root} new root element
4883
+ * @return {Object|djs.model.Root} rootElement
4873
4884
  */
4874
- Canvas.prototype.setRootElement = function(element, override) {
4875
- var activePlane = this._activePlane;
4885
+ Canvas.prototype.removeRootElement = function(rootElement) {
4876
4886
 
4877
- if (activePlane) {
4878
- return this.setRootElementForPlane(element, activePlane, override);
4879
- } else {
4880
- var basePlane = this.createPlane(BASE_LAYER, element);
4887
+ if (typeof rootElement === 'string') {
4888
+ rootElement = this._elementRegistry.get(rootElement);
4889
+ }
4890
+
4891
+ var plane = this._findPlaneForRoot(rootElement);
4892
+
4893
+ if (!plane) {
4894
+ return;
4895
+ }
4896
+
4897
+ // hook up life-cycle events
4898
+ this._removeRoot(rootElement);
4881
4899
 
4882
- this.setActivePlane(basePlane);
4900
+ // clean up layer
4901
+ this._removeLayer(rootElement.layer);
4883
4902
 
4884
- return basePlane.rootElement;
4903
+ // clean up plane
4904
+ this._planes = this._planes.filter(function(plane) {
4905
+ return plane.rootElement !== rootElement;
4906
+ });
4907
+
4908
+ // clean up active root
4909
+ if (this._rootElement === rootElement) {
4910
+ this._rootElement = null;
4885
4911
  }
4912
+
4913
+ return rootElement;
4886
4914
  };
4887
4915
 
4888
4916
 
4917
+ // root element handling //////////////////////
4918
+
4889
4919
  /**
4890
4920
  * Sets a given element as the new root element for the canvas
4891
4921
  * and returns the new root element.
4892
4922
  *
4893
- * @param {Object|djs.model.Root} element
4894
- * @param {Object|djs.model.Root} plane
4895
- * @param {boolean} [override] whether to override the current root element, if any
4923
+ * @param {Object|djs.model.Root} rootElement
4896
4924
  *
4897
4925
  * @return {Object|djs.model.Root} new root element
4898
4926
  */
4899
- Canvas.prototype.setRootElementForPlane = function(element, plane, override) {
4927
+ Canvas.prototype.setRootElement = function(rootElement, override) {
4900
4928
 
4901
- if (typeof plane === 'string') {
4902
- plane = this.getPlane(plane);
4929
+ if (isDefined(override)) {
4930
+ throw new Error('override not supported');
4903
4931
  }
4904
4932
 
4905
- if (element) {
4906
- this._ensureValid('root', element);
4933
+ if (rootElement === this._rootElement) {
4934
+ return;
4907
4935
  }
4908
4936
 
4909
- var currentRoot = plane.rootElement,
4910
- elementRegistry = this._elementRegistry,
4911
- eventBus = this._eventBus;
4937
+ var plane;
4912
4938
 
4913
- if (currentRoot) {
4914
- if (!override) {
4915
- throw new Error('rootElement already set, need to specify override');
4916
- }
4939
+ if (!rootElement) {
4940
+ throw new Error('rootElement required');
4941
+ }
4917
4942
 
4918
- // simulate element remove event sequence
4919
- eventBus.fire('root.remove', { element: currentRoot });
4920
- eventBus.fire('root.removed', { element: currentRoot });
4943
+ plane = this._findPlaneForRoot(rootElement);
4921
4944
 
4922
- elementRegistry.remove(currentRoot);
4945
+ // give set add semantics for backwards compatibility
4946
+ if (!plane) {
4947
+ rootElement = this.addRootElement(rootElement);
4923
4948
  }
4924
4949
 
4925
- if (element) {
4926
- var gfx = plane.layer;
4950
+ this._setRoot(rootElement);
4951
+
4952
+ return rootElement;
4953
+ };
4954
+
4927
4955
 
4928
- // resemble element add event sequence
4929
- eventBus.fire('root.add', { element: element });
4956
+ Canvas.prototype._removeRoot = function(element) {
4957
+ var elementRegistry = this._elementRegistry,
4958
+ eventBus = this._eventBus;
4959
+
4960
+ // simulate element remove event sequence
4961
+ eventBus.fire('root.remove', { element: element });
4962
+ eventBus.fire('root.removed', { element: element });
4963
+
4964
+ elementRegistry.remove(element);
4965
+ };
4966
+
4967
+
4968
+ Canvas.prototype._addRoot = function(element, gfx) {
4969
+ var elementRegistry = this._elementRegistry,
4970
+ eventBus = this._eventBus;
4930
4971
 
4931
- elementRegistry.add(element, gfx);
4972
+ // resemble element add event sequence
4973
+ eventBus.fire('root.add', { element: element });
4974
+
4975
+ elementRegistry.add(element, gfx);
4976
+
4977
+ eventBus.fire('root.added', { element: element, gfx: gfx });
4978
+ };
4979
+
4980
+
4981
+ Canvas.prototype._setRoot = function(rootElement, layer) {
4982
+
4983
+ var currentRoot = this._rootElement;
4984
+
4985
+ var currentLayer;
4986
+
4987
+ if (currentRoot) {
4932
4988
 
4933
- eventBus.fire('root.added', { element: element, gfx: gfx });
4989
+ // un-associate previous root element <svg>
4990
+ this._elementRegistry.updateGraphics(currentRoot, null, true);
4934
4991
 
4935
- // associate SVG with root element when active
4936
- if (plane === this._activePlane) {
4937
- this._elementRegistry.updateGraphics(element, this._svg, true);
4992
+ // hide previous layer
4993
+ currentLayer = this._findPlaneForRoot(currentRoot).layer;
4994
+
4995
+ attr(currentLayer, 'display', 'none');
4996
+ }
4997
+
4998
+ if (rootElement) {
4999
+
5000
+ if (!layer) {
5001
+ layer = this._findPlaneForRoot(rootElement).layer;
4938
5002
  }
5003
+
5004
+ // associate element with <svg>
5005
+ this._elementRegistry.updateGraphics(rootElement, this._svg, true);
5006
+
5007
+ // show root layer
5008
+ attr(layer, 'display', null);
4939
5009
  }
4940
5010
 
4941
- plane.rootElement = element;
5011
+ this._rootElement = rootElement;
4942
5012
 
4943
- return element;
5013
+ this._eventBus.fire('root.set', { element: rootElement });
4944
5014
  };
4945
5015
 
4946
5016
  // add functionality //////////////////////
@@ -4951,7 +5021,7 @@
4951
5021
  }
4952
5022
 
4953
5023
  if (this._elementRegistry.get(element.id)) {
4954
- throw new Error('element with id ' + element.id + ' already exists');
5024
+ throw new Error('element <' + element.id + '> already exists');
4955
5025
  }
4956
5026
 
4957
5027
  var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
@@ -5241,6 +5311,7 @@
5241
5311
  innerBox,
5242
5312
  outerBox = this.getSize(),
5243
5313
  matrix,
5314
+ activeLayer,
5244
5315
  transform,
5245
5316
  scale,
5246
5317
  x, y;
@@ -5248,10 +5319,11 @@
5248
5319
  if (!box) {
5249
5320
 
5250
5321
  // compute the inner box based on the
5251
- // diagrams active plane. This allows us to exclude
5322
+ // diagrams active layer. This allows us to exclude
5252
5323
  // external components, such as overlays
5253
5324
 
5254
- innerBox = (this._activePlane && this._activePlane.layer.getBBox()) || {};
5325
+ activeLayer = this._rootElement ? this.getActiveLayer() : null;
5326
+ innerBox = activeLayer && activeLayer.getBBox() || {};
5255
5327
 
5256
5328
  transform = transform$1(viewport);
5257
5329
  matrix = transform ? transform.matrix : createMatrix();
@@ -5334,10 +5406,11 @@
5334
5406
  element = this._elementRegistry.get(element);
5335
5407
  }
5336
5408
 
5337
- // switch to correct Plane
5338
- var targetPlane = this.findPlane(element);
5339
- if (targetPlane !== this._activePlane) {
5340
- this.setActivePlane(targetPlane);
5409
+ // set to correct rootElement
5410
+ var rootElement = this.findRoot(element);
5411
+
5412
+ if (rootElement !== this.getRootElement()) {
5413
+ this.setRootElement(rootElement);
5341
5414
  }
5342
5415
 
5343
5416
  if (!padding) {
@@ -5700,7 +5773,9 @@
5700
5773
  container.gfx = gfx;
5701
5774
  }
5702
5775
 
5703
- attr(gfx, ELEMENT_ID, id);
5776
+ if (gfx) {
5777
+ attr(gfx, ELEMENT_ID, id);
5778
+ }
5704
5779
 
5705
5780
  return gfx;
5706
5781
  };
@@ -15466,6 +15541,57 @@
15466
15541
  };
15467
15542
  }
15468
15543
 
15544
+ /**
15545
+ * Is an element of the given BPMN type?
15546
+ *
15547
+ * @param {djs.model.Base|ModdleElement} element
15548
+ * @param {string} type
15549
+ *
15550
+ * @return {boolean}
15551
+ */
15552
+ function is$1(element, type) {
15553
+ var bo = getBusinessObject(element);
15554
+
15555
+ return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
15556
+ }
15557
+
15558
+
15559
+ /**
15560
+ * Return true if element has any of the given types.
15561
+ *
15562
+ * @param {djs.model.Base} element
15563
+ * @param {Array<string>} types
15564
+ *
15565
+ * @return {boolean}
15566
+ */
15567
+ function isAny(element, types) {
15568
+ return some(types, function(t) {
15569
+ return is$1(element, t);
15570
+ });
15571
+ }
15572
+
15573
+ /**
15574
+ * Return the business object for a given element.
15575
+ *
15576
+ * @param {djs.model.Base|ModdleElement} element
15577
+ *
15578
+ * @return {ModdleElement}
15579
+ */
15580
+ function getBusinessObject(element) {
15581
+ return (element && element.businessObject) || element;
15582
+ }
15583
+
15584
+ /**
15585
+ * Return the di object for a given element.
15586
+ *
15587
+ * @param {djs.model.Base} element
15588
+ *
15589
+ * @return {ModdleElement}
15590
+ */
15591
+ function getDi(element) {
15592
+ return element && element.di;
15593
+ }
15594
+
15469
15595
  /**
15470
15596
  * The importBpmnDiagram result.
15471
15597
  *
@@ -15530,18 +15656,29 @@
15530
15656
 
15531
15657
  var walker = new BpmnTreeWalker(visitor, translate);
15532
15658
 
15659
+
15660
+ bpmnDiagram = bpmnDiagram || (definitions.diagrams && definitions.diagrams[0]);
15661
+
15662
+ var diagramsToImport = getDiagramsToImport(definitions, bpmnDiagram);
15663
+
15664
+ if (!diagramsToImport) {
15665
+ throw new Error(translate('no diagram to display'));
15666
+ }
15667
+
15533
15668
  // traverse BPMN 2.0 document model,
15534
15669
  // starting at definitions
15535
- if (!bpmnDiagram && definitions.diagrams) {
15536
- for (var i = 0; i < definitions.diagrams.length; i++) {
15537
- walker.handleDefinitions(definitions, definitions.diagrams[i]);
15538
- }
15539
- } else {
15540
- walker.handleDefinitions(definitions, bpmnDiagram);
15541
- }
15670
+ forEach(diagramsToImport, function(diagram) {
15671
+ walker.handleDefinitions(definitions, diagram);
15672
+ });
15673
+
15674
+ var rootId = bpmnDiagram.plane.bpmnElement.id;
15542
15675
 
15543
- var mainDiagram = bpmnDiagram || definitions.diagrams[0];
15544
- canvas.setActivePlane(mainDiagram.plane.bpmnElement.id);
15676
+ // we do need to account for different ways we create root elements
15677
+ // each nested imported <root> do have the `_plane` suffix, while
15678
+ // the root <root> is found under the business object ID
15679
+ canvas.setRootElement(
15680
+ canvas.findRoot(rootId + '_plane') || canvas.findRoot(rootId)
15681
+ );
15545
15682
  }
15546
15683
 
15547
15684
  return new Promise(function(resolve, reject) {
@@ -15569,6 +15706,107 @@
15569
15706
  });
15570
15707
  }
15571
15708
 
15709
+ /**
15710
+ * Returns all diagrams in the same hirarchy as the requested diagram.
15711
+ * Includes all parent and sub process diagrams.
15712
+ *
15713
+ * @param {Array} definitions
15714
+ * @param {Object} bpmnDiagram
15715
+ *
15716
+ * @returns {Array<Object>}
15717
+ */
15718
+ function getDiagramsToImport(definitions, bpmnDiagram) {
15719
+ if (!bpmnDiagram) {
15720
+ return;
15721
+ }
15722
+
15723
+ var bpmnElement = bpmnDiagram.plane.bpmnElement,
15724
+ rootElement = bpmnElement;
15725
+
15726
+ if (!is$1(bpmnElement, 'bpmn:Process') && !is$1(bpmnElement, 'bpmn:Collaboration')) {
15727
+ rootElement = findRootProcess(bpmnElement);
15728
+ }
15729
+
15730
+ // in case the process is part of a collaboration, the plane references the
15731
+ // collaboration, not the process
15732
+ var collaboration;
15733
+
15734
+ if (is$1(rootElement, 'bpmn:Collaboration')) {
15735
+ collaboration = rootElement;
15736
+ } else {
15737
+ collaboration = find(definitions.rootElements, function(element) {
15738
+ if (!is$1(element, 'bpmn:Collaboration')) {
15739
+ return;
15740
+ }
15741
+
15742
+ return find(element.participants, function(participant) {
15743
+ return participant.processRef === rootElement;
15744
+ });
15745
+ });
15746
+ }
15747
+
15748
+ var rootElements = [ rootElement ];
15749
+
15750
+ // all collaboration processes can contain sub-diagrams
15751
+ if (collaboration) {
15752
+ rootElements = map$1(collaboration.participants, function(participant) {
15753
+ return participant.processRef;
15754
+ });
15755
+
15756
+ rootElements.push(collaboration);
15757
+ }
15758
+
15759
+ var allChildren = selfAndAllFlowElements(rootElements);
15760
+
15761
+ // if we have multiple diagrams referencing the same element, we
15762
+ // use the first in the file
15763
+ var diagramsToImport = [ bpmnDiagram ];
15764
+ var handledElements = [ bpmnElement ];
15765
+
15766
+ forEach(definitions.diagrams, function(diagram) {
15767
+ var businessObject = diagram.plane.bpmnElement;
15768
+
15769
+ if (
15770
+ allChildren.indexOf(businessObject) !== -1 &&
15771
+ handledElements.indexOf(businessObject) === -1
15772
+ ) {
15773
+ diagramsToImport.push(diagram);
15774
+ handledElements.push(businessObject);
15775
+ }
15776
+ });
15777
+
15778
+
15779
+ return diagramsToImport;
15780
+ }
15781
+
15782
+ function selfAndAllFlowElements(elements) {
15783
+ var result = [];
15784
+
15785
+ forEach(elements, function(element) {
15786
+ if (!element) {
15787
+ return;
15788
+ }
15789
+
15790
+ result.push(element);
15791
+
15792
+ result = result.concat(selfAndAllFlowElements(element.flowElements));
15793
+ });
15794
+
15795
+ return result;
15796
+ }
15797
+
15798
+ function findRootProcess(element) {
15799
+ var parent = element;
15800
+
15801
+ while (parent) {
15802
+ if (is$1(parent, 'bpmn:Process')) {
15803
+ return parent;
15804
+ }
15805
+
15806
+ parent = parent.$parent;
15807
+ }
15808
+ }
15809
+
15572
15810
  /**
15573
15811
  * This file must not be changed or exchanged.
15574
15812
  *
@@ -16059,7 +16297,7 @@
16059
16297
  try {
16060
16298
  var canvas = self.get('canvas');
16061
16299
 
16062
- var contentNode = canvas.getDefaultLayer(),
16300
+ var contentNode = canvas.getActiveLayer(),
16063
16301
  defsNode = query('defs', canvas._svg);
16064
16302
 
16065
16303
  var contents = innerSVG(contentNode),
@@ -16450,43 +16688,6 @@
16450
16688
  }
16451
16689
  };
16452
16690
 
16453
- /**
16454
- * Is an element of the given BPMN type?
16455
- *
16456
- * @param {djs.model.Base|ModdleElement} element
16457
- * @param {string} type
16458
- *
16459
- * @return {boolean}
16460
- */
16461
- function is$1(element, type) {
16462
- var bo = getBusinessObject(element);
16463
-
16464
- return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
16465
- }
16466
-
16467
-
16468
- /**
16469
- * Return the business object for a given element.
16470
- *
16471
- * @param {djs.model.Base|ModdleElement} element
16472
- *
16473
- * @return {ModdleElement}
16474
- */
16475
- function getBusinessObject(element) {
16476
- return (element && element.businessObject) || element;
16477
- }
16478
-
16479
- /**
16480
- * Return the di object for a given element.
16481
- *
16482
- * @param {djs.model.Base} element
16483
- *
16484
- * @return {ModdleElement}
16485
- */
16486
- function getDi(element) {
16487
- return element && element.di;
16488
- }
16489
-
16490
16691
  function isExpanded(element, di) {
16491
16692
 
16492
16693
  if (is$1(element, 'bpmn:CallActivity')) {
@@ -17076,16 +17277,16 @@
17076
17277
  return drawPath(parentGfx, path, assign({ 'data-marker': type }, attrs));
17077
17278
  }
17078
17279
 
17280
+ function renderer(type) {
17281
+ return handlers[type];
17282
+ }
17283
+
17079
17284
  function as(type) {
17080
17285
  return function(parentGfx, element) {
17081
- return handlers[type](parentGfx, element);
17286
+ return renderer(type)(parentGfx, element);
17082
17287
  };
17083
17288
  }
17084
17289
 
17085
- function renderer(type) {
17086
- return handlers[type];
17087
- }
17088
-
17089
17290
  function renderEventContent(element, parentGfx) {
17090
17291
 
17091
17292
  var event = getSemantic(element);
@@ -18566,6 +18767,7 @@
18566
18767
  // extension API, use at your own risk
18567
18768
  this._drawPath = drawPath;
18568
18769
 
18770
+ this._renderer = renderer;
18569
18771
  }
18570
18772
 
18571
18773
 
@@ -18587,7 +18789,7 @@
18587
18789
 
18588
18790
  BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
18589
18791
  var type = element.type;
18590
- var h = this.handlers[type];
18792
+ var h = this._renderer(type);
18591
18793
 
18592
18794
  /* jshint -W040 */
18593
18795
  return h(parentGfx, element);
@@ -18595,7 +18797,7 @@
18595
18797
 
18596
18798
  BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
18597
18799
  var type = element.type;
18598
- var h = this.handlers[type];
18800
+ var h = this._renderer(type);
18599
18801
 
18600
18802
  /* jshint -W040 */
18601
18803
  return h(parentGfx, element);
@@ -19754,6 +19956,13 @@
19754
19956
  return element && !!element.labelTarget;
19755
19957
  }
19756
19958
 
19959
+ /**
19960
+ * @param {ModdleElement} semantic
19961
+ * @param {ModdleElement} di
19962
+ * @param {Object} [attrs=null]
19963
+ *
19964
+ * @return {Object}
19965
+ */
19757
19966
  function elementData(semantic, di, attrs) {
19758
19967
  return assign({
19759
19968
  id: semantic.id,
@@ -19833,15 +20042,14 @@
19833
20042
  // invisible root element (process, subprocess or collaboration)
19834
20043
  if (is$1(di, 'bpmndi:BPMNPlane')) {
19835
20044
 
19836
- // add a virtual element (not being drawn)
19837
- element = this._elementFactory.createRoot(elementData(semantic, di));
20045
+ var attrs = is$1(semantic, 'bpmn:SubProcess')
20046
+ ? { id: semantic.id + '_plane' }
20047
+ : {};
19838
20048
 
19839
- // for subprocesses, the id is already defined on the collapsed shape
19840
- if (is$1(semantic, 'bpmn:SubProcess')) {
19841
- element.id = element.id + '_plane';
19842
- }
20049
+ // add a virtual element (not being drawn)
20050
+ element = this._elementFactory.createRoot(elementData(semantic, di, attrs));
19843
20051
 
19844
- this._canvas.createPlane(semantic.id, element);
20052
+ this._canvas.addRootElement(element);
19845
20053
  }
19846
20054
 
19847
20055
  // SHAPE
@@ -19877,7 +20085,7 @@
19877
20085
 
19878
20086
  // check whether data store is inside our outside of its semantic parent
19879
20087
  if (!isPointInsideBBox$1(parentElement, getMid(bounds))) {
19880
- parentElement = this._canvas.findPlane(parentElement).rootElement;
20088
+ parentElement = this._canvas.findRoot(parentElement);
19881
20089
  }
19882
20090
  }
19883
20091
 
@@ -19905,7 +20113,7 @@
19905
20113
  // are rendered correctly across different "hacks" people
19906
20114
  // love to model such as cross participant / sub process
19907
20115
  // associations
19908
- parentElement = this._canvas.findPlane(parentElement).rootElement;
20116
+ parentElement = this._canvas.findRoot(parentElement);
19909
20117
  }
19910
20118
 
19911
20119
  // insert sequence flows behind other flow nodes (cf. #727)
@@ -20171,7 +20379,7 @@
20171
20379
  return isPrimaryButton(event) || isAuxiliaryButton(event);
20172
20380
  }
20173
20381
 
20174
- var LOW_PRIORITY$m = 500;
20382
+ var LOW_PRIORITY$o = 500;
20175
20383
 
20176
20384
 
20177
20385
  /**
@@ -20366,7 +20574,7 @@
20366
20574
  eventBus.on([
20367
20575
  'shape.changed',
20368
20576
  'connection.changed'
20369
- ], LOW_PRIORITY$m, function(event) {
20577
+ ], LOW_PRIORITY$o, function(event) {
20370
20578
 
20371
20579
  var element = event.element,
20372
20580
  gfx = event.gfx;
@@ -20374,7 +20582,7 @@
20374
20582
  eventBus.fire('interactionEvents.updateHit', { element: element, gfx: gfx });
20375
20583
  });
20376
20584
 
20377
- eventBus.on('interactionEvents.createHit', LOW_PRIORITY$m, function(event) {
20585
+ eventBus.on('interactionEvents.createHit', LOW_PRIORITY$o, function(event) {
20378
20586
  var element = event.element,
20379
20587
  gfx = event.gfx;
20380
20588
 
@@ -20648,7 +20856,7 @@
20648
20856
  interactionEvents: [ 'type', InteractionEvents ]
20649
20857
  };
20650
20858
 
20651
- var LOW_PRIORITY$l = 500;
20859
+ var LOW_PRIORITY$n = 500;
20652
20860
 
20653
20861
 
20654
20862
  /**
@@ -20686,7 +20894,7 @@
20686
20894
 
20687
20895
  // A low priortity is necessary, because outlines of labels have to be updated
20688
20896
  // after the label bounds have been updated in the renderer.
20689
- eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$l, function(event) {
20897
+ eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$n, function(event) {
20690
20898
  var element = event.element,
20691
20899
  gfx = event.gfx;
20692
20900
 
@@ -20783,7 +20991,7 @@
20783
20991
  self.deselect(element);
20784
20992
  });
20785
20993
 
20786
- eventBus.on([ 'diagram.clear', 'plane.set' ], function(e) {
20994
+ eventBus.on([ 'diagram.clear', 'root.set' ], function(e) {
20787
20995
  self.select(null);
20788
20996
  });
20789
20997
  }
@@ -20836,10 +21044,12 @@
20836
21044
 
20837
21045
  var canvas = this._canvas;
20838
21046
 
21047
+ var rootElement = canvas.getRootElement();
21048
+
20839
21049
  elements = elements.filter(function(element) {
20840
- var plane = canvas.findPlane(element);
21050
+ var elementRoot = canvas.findRoot(element);
20841
21051
 
20842
- return plane === canvas.getActivePlane();
21052
+ return rootElement === elementRoot;
20843
21053
  });
20844
21054
 
20845
21055
  // selection may be cleared by passing an empty array or null
@@ -21080,7 +21290,7 @@
21080
21290
  // document wide unique overlay ids
21081
21291
  var ids$1 = new IdGenerator('ov');
21082
21292
 
21083
- var LOW_PRIORITY$k = 500;
21293
+ var LOW_PRIORITY$m = 500;
21084
21294
 
21085
21295
 
21086
21296
  /**
@@ -21310,8 +21520,7 @@
21310
21520
  *
21311
21521
  * @see Overlays#get for filter options.
21312
21522
  *
21313
- * @param {string} [id]
21314
- * @param {Object} [filter]
21523
+ * @param {string|object} [filter]
21315
21524
  */
21316
21525
  Overlays.prototype.remove = function(filter) {
21317
21526
 
@@ -21427,6 +21636,7 @@
21427
21636
  }
21428
21637
 
21429
21638
  setPosition$1(htmlContainer, left || 0, top || 0);
21639
+ this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
21430
21640
  };
21431
21641
 
21432
21642
 
@@ -21510,12 +21720,10 @@
21510
21720
  classes$1(htmlContainer).add('djs-overlay-' + overlay.type);
21511
21721
  }
21512
21722
 
21513
- var plane = this._canvas.findPlane(element);
21514
- var activePlane = this._canvas.getActivePlane();
21515
- overlay.plane = plane;
21516
- if (plane !== activePlane) {
21517
- setVisible$1(htmlContainer, false);
21518
- }
21723
+ var elementRoot = this._canvas.findRoot(element);
21724
+ var activeRoot = this._canvas.getRootElement();
21725
+
21726
+ setVisible$1(htmlContainer, elementRoot === activeRoot);
21519
21727
 
21520
21728
  overlay.htmlContainer = htmlContainer;
21521
21729
 
@@ -21531,14 +21739,14 @@
21531
21739
 
21532
21740
  Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
21533
21741
  var show = overlay.show,
21534
- plane = overlay.plane,
21742
+ rootElement = this._canvas.findRoot(overlay.element),
21535
21743
  minZoom = show && show.minZoom,
21536
21744
  maxZoom = show && show.maxZoom,
21537
21745
  htmlContainer = overlay.htmlContainer,
21538
- activePlane = this._canvas.getActivePlane(),
21746
+ activeRootElement = this._canvas.getRootElement(),
21539
21747
  visible = true;
21540
21748
 
21541
- if (plane !== activePlane) {
21749
+ if (rootElement !== activeRootElement) {
21542
21750
  visible = false;
21543
21751
  } else if (show) {
21544
21752
  if (
@@ -21649,7 +21857,7 @@
21649
21857
 
21650
21858
  // move integration
21651
21859
 
21652
- eventBus.on('element.changed', LOW_PRIORITY$k, function(e) {
21860
+ eventBus.on('element.changed', LOW_PRIORITY$m, function(e) {
21653
21861
  var element = e.element;
21654
21862
 
21655
21863
  var container = self._getOverlayContainer(element, true);
@@ -21674,10 +21882,8 @@
21674
21882
  });
21675
21883
 
21676
21884
 
21677
- eventBus.on('plane.set', function(e) {
21678
- forEach(self._overlays, function(el) {
21679
- setVisible$1(el.htmlContainer, el.plane === e.plane);
21680
- });
21885
+ eventBus.on('root.set', function() {
21886
+ self._updateOverlaysVisibilty(self._canvas.viewbox());
21681
21887
  });
21682
21888
 
21683
21889
  // clear overlays with diagram
@@ -21790,6 +21996,181 @@
21790
21996
  changeSupport: [ 'type', ChangeSupport ]
21791
21997
  };
21792
21998
 
21999
+ var DEFAULT_PRIORITY$4 = 1000;
22000
+
22001
+ /**
22002
+ * A utility that can be used to plug-in into the command execution for
22003
+ * extension and/or validation.
22004
+ *
22005
+ * @param {EventBus} eventBus
22006
+ *
22007
+ * @example
22008
+ *
22009
+ * import inherits from 'inherits';
22010
+ *
22011
+ * import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
22012
+ *
22013
+ * function CommandLogger(eventBus) {
22014
+ * CommandInterceptor.call(this, eventBus);
22015
+ *
22016
+ * this.preExecute(function(event) {
22017
+ * console.log('command pre-execute', event);
22018
+ * });
22019
+ * }
22020
+ *
22021
+ * inherits(CommandLogger, CommandInterceptor);
22022
+ *
22023
+ */
22024
+ function CommandInterceptor(eventBus) {
22025
+ this._eventBus = eventBus;
22026
+ }
22027
+
22028
+ CommandInterceptor.$inject = [ 'eventBus' ];
22029
+
22030
+ function unwrapEvent(fn, that) {
22031
+ return function(event) {
22032
+ return fn.call(that || null, event.context, event.command, event);
22033
+ };
22034
+ }
22035
+
22036
+ /**
22037
+ * Register an interceptor for a command execution
22038
+ *
22039
+ * @param {string|Array<string>} [events] list of commands to register on
22040
+ * @param {string} [hook] command hook, i.e. preExecute, executed to listen on
22041
+ * @param {number} [priority] the priority on which to hook into the execution
22042
+ * @param {Function} handlerFn interceptor to be invoked with (event)
22043
+ * @param {boolean} unwrap if true, unwrap the event and pass (context, command, event) to the
22044
+ * listener instead
22045
+ * @param {Object} [that] Pass context (`this`) to the handler function
22046
+ */
22047
+ CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
22048
+
22049
+ if (isFunction(hook) || isNumber(hook)) {
22050
+ that = unwrap;
22051
+ unwrap = handlerFn;
22052
+ handlerFn = priority;
22053
+ priority = hook;
22054
+ hook = null;
22055
+ }
22056
+
22057
+ if (isFunction(priority)) {
22058
+ that = unwrap;
22059
+ unwrap = handlerFn;
22060
+ handlerFn = priority;
22061
+ priority = DEFAULT_PRIORITY$4;
22062
+ }
22063
+
22064
+ if (isObject(unwrap)) {
22065
+ that = unwrap;
22066
+ unwrap = false;
22067
+ }
22068
+
22069
+ if (!isFunction(handlerFn)) {
22070
+ throw new Error('handlerFn must be a function');
22071
+ }
22072
+
22073
+ if (!isArray$2(events)) {
22074
+ events = [ events ];
22075
+ }
22076
+
22077
+ var eventBus = this._eventBus;
22078
+
22079
+ forEach(events, function(event) {
22080
+
22081
+ // concat commandStack(.event)?(.hook)?
22082
+ var fullEvent = [ 'commandStack', event, hook ].filter(function(e) { return e; }).join('.');
22083
+
22084
+ eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn, that) : handlerFn, that);
22085
+ });
22086
+ };
22087
+
22088
+
22089
+ var hooks = [
22090
+ 'canExecute',
22091
+ 'preExecute',
22092
+ 'preExecuted',
22093
+ 'execute',
22094
+ 'executed',
22095
+ 'postExecute',
22096
+ 'postExecuted',
22097
+ 'revert',
22098
+ 'reverted'
22099
+ ];
22100
+
22101
+ /*
22102
+ * Install hook shortcuts
22103
+ *
22104
+ * This will generate the CommandInterceptor#(preExecute|...|reverted) methods
22105
+ * which will in term forward to CommandInterceptor#on.
22106
+ */
22107
+ forEach(hooks, function(hook) {
22108
+
22109
+ /**
22110
+ * {canExecute|preExecute|preExecuted|execute|executed|postExecute|postExecuted|revert|reverted}
22111
+ *
22112
+ * A named hook for plugging into the command execution
22113
+ *
22114
+ * @param {string|Array<string>} [events] list of commands to register on
22115
+ * @param {number} [priority] the priority on which to hook into the execution
22116
+ * @param {Function} handlerFn interceptor to be invoked with (event)
22117
+ * @param {boolean} [unwrap=false] if true, unwrap the event and pass (context, command, event) to the
22118
+ * listener instead
22119
+ * @param {Object} [that] Pass context (`this`) to the handler function
22120
+ */
22121
+ CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
22122
+
22123
+ if (isFunction(events) || isNumber(events)) {
22124
+ that = unwrap;
22125
+ unwrap = handlerFn;
22126
+ handlerFn = priority;
22127
+ priority = events;
22128
+ events = null;
22129
+ }
22130
+
22131
+ this.on(events, hook, priority, handlerFn, unwrap, that);
22132
+ };
22133
+ });
22134
+
22135
+ /**
22136
+ * A modeling behavior that ensures we set the correct root element
22137
+ * as we undo and redo commands.
22138
+ *
22139
+ * @param {Canvas} canvas
22140
+ * @param {didi.Injector} injector
22141
+ */
22142
+ function RootElementsBehavior(canvas, injector) {
22143
+
22144
+ injector.invoke(CommandInterceptor, this);
22145
+
22146
+ this.executed(function(event) {
22147
+ var context = event.context;
22148
+
22149
+ if (context.rootElement) {
22150
+ canvas.setRootElement(context.rootElement);
22151
+ } else {
22152
+ context.rootElement = canvas.getRootElement();
22153
+ }
22154
+ });
22155
+
22156
+ this.revert(function(event) {
22157
+ var context = event.context;
22158
+
22159
+ if (context.rootElement) {
22160
+ canvas.setRootElement(context.rootElement);
22161
+ }
22162
+ });
22163
+ }
22164
+
22165
+ inherits$1(RootElementsBehavior, CommandInterceptor);
22166
+
22167
+ RootElementsBehavior.$inject = [ 'canvas', 'injector'];
22168
+
22169
+ var RootElementsModule = {
22170
+ __init__: [ 'rootElementsBehavior' ],
22171
+ rootElementsBehavior: [ 'type', RootElementsBehavior ]
22172
+ };
22173
+
21793
22174
  var css_escape = {exports: {}};
21794
22175
 
21795
22176
  /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
@@ -21914,39 +22295,135 @@
21914
22295
  });
21915
22296
  }
21916
22297
 
21917
- 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>';
22298
+ var planeSuffix = '_plane';
22299
+
22300
+ /**
22301
+ * Get primary shape ID for a plane.
22302
+ *
22303
+ * @param {djs.model.Base|ModdleElement} element
22304
+ *
22305
+ * @returns {String}
22306
+ */
22307
+ function getShapeIdFromPlane(element) {
22308
+ var id = element.id;
22309
+
22310
+ return removePlaneSuffix(id);
22311
+ }
22312
+
22313
+ /**
22314
+ * Get plane ID for a primary shape.
22315
+ *
22316
+ * @param {djs.model.Base|ModdleElement} element
22317
+ *
22318
+ * @returns {String}
22319
+ */
22320
+ function getPlaneIdFromShape(element) {
22321
+ var id = element.id;
22322
+
22323
+ if (is$1(element, 'bpmn:SubProcess')) {
22324
+ return addPlaneSuffix(id);
22325
+ }
22326
+
22327
+ return id;
22328
+ }
22329
+
22330
+ /**
22331
+ * Get plane ID for primary shape ID.
22332
+ *
22333
+ * @param {String} id
22334
+ *
22335
+ * @returns {String}
22336
+ */
22337
+ function toPlaneId(id) {
22338
+ return addPlaneSuffix(id);
22339
+ }
22340
+
22341
+ /**
22342
+ * Check wether element is plane.
22343
+ *
22344
+ * @param {djs.model.Base|ModdleElement} element
22345
+ *
22346
+ * @returns {Boolean}
22347
+ */
22348
+ function isPlane(element) {
22349
+ var di = getDi(element);
22350
+
22351
+ return is$1(di, 'bpmndi:BPMNPlane');
22352
+ }
22353
+
22354
+ function addPlaneSuffix(id) {
22355
+ return id + planeSuffix;
22356
+ }
22357
+
22358
+ function removePlaneSuffix(id) {
22359
+ return id.replace(new RegExp(planeSuffix + '$'), '');
22360
+ }
21918
22361
 
21919
22362
  var OPEN_CLASS = 'bjs-breadcrumbs-shown';
21920
22363
 
22364
+
21921
22365
  /**
21922
- * Adds Overlays that allow switching planes on collapsed subprocesses.
22366
+ * Adds overlays that allow switching planes on collapsed subprocesses.
21923
22367
  *
21924
22368
  * @param {eventBus} eventBus
21925
22369
  * @param {elementRegistry} elementRegistry
21926
22370
  * @param {overlays} overlays
21927
22371
  * @param {canvas} canvas
21928
22372
  */
21929
- function DrilldownOverlays(eventBus, elementRegistry, overlays, canvas) {
22373
+ function DrilldownBreadcrumbs(eventBus, elementRegistry, overlays, canvas) {
21930
22374
  var breadcrumbs = domify('<ul class="bjs-breadcrumbs"></ul>');
21931
22375
  var container = canvas.getContainer();
21932
22376
  var containerClasses = classes$1(container);
21933
22377
  container.appendChild(breadcrumbs);
21934
22378
 
21935
- function updateBreadcrumbs(plane) {
21936
- var subProcess = elementRegistry.get(plane.name);
21937
- var parents = getParentChain(subProcess);
22379
+ var boParents = [];
22380
+
22381
+ // update breadcrumbs if name or ID of the primary shape changes
22382
+ eventBus.on('element.changed', function(e) {
22383
+ var shape = e.element,
22384
+ bo = getBusinessObject(shape);
21938
22385
 
21939
- var path = parents.map(function(el) {
21940
- var title = escapeHTML(el.name || el.id);
22386
+ var isPresent = find(boParents, function(el) {
22387
+ return el === bo;
22388
+ });
22389
+
22390
+ if (!isPresent) {
22391
+ return;
22392
+ }
22393
+
22394
+ updateBreadcrumbs();
22395
+ });
22396
+
22397
+ /**
22398
+ * Updates the displayed breadcrumbs. If no element is provided, only the
22399
+ * labels are updated.
22400
+ *
22401
+ * @param {djs.model.Base} [element]
22402
+ */
22403
+ function updateBreadcrumbs(element) {
22404
+ if (element) {
22405
+ boParents = getBoParentChain(element);
22406
+ }
22407
+
22408
+ var path = boParents.map(function(parent) {
22409
+ var title = escapeHTML(parent.name || parent.id);
21941
22410
  var link = domify('<li><span class="bjs-crumb"><a title="' + title + '">' + title + '</a></span></li>');
21942
22411
 
22412
+ var parentPlane = canvas.findRoot(getPlaneIdFromShape(parent)) || canvas.findRoot(parent.id);
22413
+
22414
+ // when the root is a collaboration, the process does not have a corresponding
22415
+ // element in the elementRegisty. Instead, we search for the corresponding participant
22416
+ if (!parentPlane && is$1(parent, 'bpmn:Process')) {
22417
+ var participant = elementRegistry.find(function(element) {
22418
+ var bo = getBusinessObject(element);
22419
+ return bo && bo.processRef && bo.processRef === parent;
22420
+ });
22421
+
22422
+ parentPlane = canvas.findRoot(participant.id);
22423
+ }
22424
+
21943
22425
  link.addEventListener('click', function() {
21944
- if (canvas.getPlane(el.id)) {
21945
- canvas.setActivePlane(el.id);
21946
- } else {
21947
- var plane = canvas.findPlane(el.id);
21948
- canvas.setActivePlane(plane);
21949
- }
22426
+ canvas.setRootElement(parentPlane);
21950
22427
  });
21951
22428
 
21952
22429
  return link;
@@ -21963,50 +22440,26 @@
21963
22440
  });
21964
22441
  }
21965
22442
 
21966
- eventBus.on('plane.set', function(event) {
21967
- var plane = event.plane;
21968
-
21969
- updateBreadcrumbs(plane);
22443
+ eventBus.on('root.set', function(event) {
22444
+ updateBreadcrumbs(event.element);
21970
22445
  });
21971
22446
 
21972
- var createOverlay = function(element) {
21973
- var html = domify('<button class="bjs-drilldown">' + ARROW_DOWN_SVG + '</button>');
21974
-
21975
- html.addEventListener('click', function() {
21976
- canvas.setActivePlane(element.id);
21977
- });
21978
-
21979
- overlays.add(element, {
21980
- position: {
21981
- bottom: -7,
21982
- right: -8
21983
- },
21984
- html: html
21985
- });
21986
- };
21987
-
21988
- var addOverlays = function(elements) {
21989
- elements.forEach(function(element) {
21990
- if (is$1(element, 'bpmn:SubProcess')
21991
- && element.collapsed
21992
- && canvas.getPlane(element.id)) {
21993
- createOverlay(element);
21994
- }
21995
- });
21996
- };
21997
-
21998
- eventBus.on('import.done', function() {
21999
- addOverlays(elementRegistry.filter(function(el) {
22000
- return is$1(el, 'bpmn:SubProcess');
22001
- }));
22002
- });
22003
22447
  }
22004
22448
 
22005
- DrilldownOverlays.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
22449
+ DrilldownBreadcrumbs.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
22006
22450
 
22007
22451
 
22008
- // helpers
22009
- var getParentChain = function(child) {
22452
+ // helpers //////////
22453
+
22454
+ /**
22455
+ * Returns the parents for the element using the business object chain,
22456
+ * starting with the root element.
22457
+ *
22458
+ * @param {djs.model.Shape} child
22459
+ *
22460
+ * @returns {Array<djs.model.Shape>} parents
22461
+ */
22462
+ function getBoParentChain(child) {
22010
22463
  var bo = getBusinessObject(child);
22011
22464
 
22012
22465
  var parents = [];
@@ -22018,29 +22471,40 @@
22018
22471
  }
22019
22472
 
22020
22473
  return parents.reverse();
22021
- };
22474
+ }
22022
22475
 
22023
22476
  /**
22024
- * Move collapsed subprocesses into view when drilling down. Zoom and scroll
22025
- * are saved in a session.
22477
+ * Move collapsed subprocesses into view when drilling down.
22478
+ *
22479
+ * Zoom and scroll are saved in a session.
22026
22480
  *
22027
22481
  * @param {eventBus} eventBus
22028
22482
  * @param {canvas} canvas
22029
22483
  */
22030
22484
  function DrilldownCentering(eventBus, canvas) {
22031
- var currentPlane = 'base';
22032
- var positionMap = {};
22033
22485
 
22034
- eventBus.on('plane.set', function(event) {
22486
+ var currentRoot = null;
22487
+ var positionMap = new Map();
22488
+
22489
+ eventBus.on('root.set', function(event) {
22490
+ var newRoot = event.element;
22035
22491
  var currentViewbox = canvas.viewbox();
22036
- positionMap[currentPlane] = {
22492
+ var storedViewbox = positionMap.get(newRoot);
22493
+
22494
+ positionMap.set(currentRoot, {
22037
22495
  x: currentViewbox.x,
22038
22496
  y: currentViewbox.y,
22039
22497
  zoom: currentViewbox.scale
22040
- };
22498
+ });
22499
+
22500
+ currentRoot = newRoot;
22501
+
22502
+ // current root was replaced with a collaboration, we don't update the viewbox
22503
+ if (is$1(newRoot, 'bpmn:Collaboration') && !storedViewbox) {
22504
+ return;
22505
+ }
22041
22506
 
22042
- var planeId = event.plane.name;
22043
- var storedViewbox = positionMap[planeId] || { x: 0, y: 0, zoom: 1 };
22507
+ storedViewbox = storedViewbox || { x: 0, y: 0, zoom: 1 };
22044
22508
 
22045
22509
  var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
22046
22510
  dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
@@ -22055,14 +22519,78 @@
22055
22519
  if (storedViewbox.zoom !== currentViewbox.scale) {
22056
22520
  canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
22057
22521
  }
22522
+ });
22058
22523
 
22059
- currentPlane = planeId;
22524
+ eventBus.on('diagram.clear', function() {
22525
+ positionMap.clear();
22526
+ currentRoot = null;
22060
22527
  });
22528
+
22061
22529
  }
22062
22530
 
22063
22531
  DrilldownCentering.$inject = [ 'eventBus', 'canvas' ];
22064
22532
 
22065
- var DEFAULT_POSITION = {
22533
+
22534
+ /**
22535
+ * ES5 Map implementation. Works.
22536
+ */
22537
+ function Map() {
22538
+
22539
+ this._entries = [];
22540
+
22541
+ this.set = function(key, value) {
22542
+
22543
+ var found = false;
22544
+
22545
+ for (var k in this._entries) {
22546
+ if (this._entries[k][0] === key) {
22547
+ this._entries[k][1] = value;
22548
+
22549
+ found = true;
22550
+
22551
+ break;
22552
+ }
22553
+ }
22554
+
22555
+ if (!found) {
22556
+ this._entries.push([ key, value ]);
22557
+ }
22558
+ };
22559
+
22560
+ this.get = function(key) {
22561
+
22562
+ for (var k in this._entries) {
22563
+ if (this._entries[k][0] === key) {
22564
+ return this._entries[k][1];
22565
+ }
22566
+ }
22567
+
22568
+ return null;
22569
+ };
22570
+
22571
+ this.clear = function() {
22572
+ this._entries.length = 0;
22573
+ };
22574
+
22575
+ this.remove = function(key) {
22576
+
22577
+ var idx = -1;
22578
+
22579
+ for (var k in this._entries) {
22580
+ if (this._entries[k][0] === key) {
22581
+ idx = k;
22582
+
22583
+ break;
22584
+ }
22585
+ }
22586
+
22587
+ if (idx !== -1) {
22588
+ this._entries.splice(idx, 1);
22589
+ }
22590
+ };
22591
+ }
22592
+
22593
+ var DEFAULT_POSITION$1 = {
22066
22594
  x: 180,
22067
22595
  y: 160
22068
22596
  };
@@ -22128,6 +22656,11 @@
22128
22656
 
22129
22657
  plane.get('planeElement').forEach(function(diElement) {
22130
22658
  var bo = diElement.bpmnElement;
22659
+
22660
+ if (!bo) {
22661
+ return;
22662
+ }
22663
+
22131
22664
  var parent = bo.$parent;
22132
22665
 
22133
22666
  if (is$1(bo, 'bpmn:SubProcess') && !diElement.isExpanded) {
@@ -22143,12 +22676,21 @@
22143
22676
 
22144
22677
  var newDiagrams = [];
22145
22678
 
22679
+ // create new planes for all collapsed subprocesses, even when they are empty
22680
+ collapsedElements.forEach(function(element) {
22681
+ if (!self._processToDiagramMap[element.id]) {
22682
+ var diagram = self.createDiagram(element);
22683
+ self._processToDiagramMap[element.id] = diagram;
22684
+ newDiagrams.push(diagram);
22685
+ }
22686
+ });
22687
+
22146
22688
  elementsToMove.forEach(function(element) {
22147
22689
  var diElement = element.diElement;
22148
22690
  var parent = element.parent;
22149
22691
 
22150
22692
  // parent is expanded, get nearest collapsed parent
22151
- while (parent && !collapsedElements.includes(parent)) {
22693
+ while (parent && collapsedElements.indexOf(parent) === -1) {
22152
22694
  parent = parent.$parent;
22153
22695
  }
22154
22696
 
@@ -22158,12 +22700,6 @@
22158
22700
  }
22159
22701
 
22160
22702
  var diagram = self._processToDiagramMap[parent.id];
22161
- if (!diagram) {
22162
- diagram = self.createDiagram(parent);
22163
- self._processToDiagramMap[parent.id] = diagram;
22164
- newDiagrams.push(diagram);
22165
- }
22166
-
22167
22703
  self.moveToDiPlane(diElement, diagram.plane);
22168
22704
  });
22169
22705
 
@@ -22177,8 +22713,8 @@
22177
22713
  var planeBounds = getPlaneBounds(plane);
22178
22714
 
22179
22715
  var offset = {
22180
- x: planeBounds.x - DEFAULT_POSITION.x,
22181
- y: planeBounds.y - DEFAULT_POSITION.y
22716
+ x: planeBounds.x - DEFAULT_POSITION$1.x,
22717
+ y: planeBounds.y - DEFAULT_POSITION$1.y
22182
22718
  };
22183
22719
 
22184
22720
  elements.forEach(function(diElement) {
@@ -22252,11 +22788,187 @@
22252
22788
  return asBounds(planeTrbl);
22253
22789
  }
22254
22790
 
22791
+ var LOW_PRIORITY$l = 250;
22792
+ 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>';
22793
+
22794
+ var EMPTY_MARKER = 'bjs-drilldown-empty';
22795
+
22796
+ function DrilldownOverlayBehavior(
22797
+ canvas, eventBus, elementRegistry, overlays
22798
+ ) {
22799
+ CommandInterceptor.call(this, eventBus);
22800
+
22801
+ this._canvas = canvas;
22802
+ this._eventBus = eventBus;
22803
+ this._elementRegistry = elementRegistry;
22804
+ this._overlays = overlays;
22805
+
22806
+ var self = this;
22807
+
22808
+ this.executed('shape.toggleCollapse', LOW_PRIORITY$l, function(context) {
22809
+ var shape = context.shape;
22810
+
22811
+ // Add overlay to the collapsed shape
22812
+ if (self.canDrillDown(shape)) {
22813
+ self.addOverlay(shape);
22814
+ } else {
22815
+ self.removeOverlay(shape);
22816
+ }
22817
+ }, true);
22818
+
22819
+
22820
+ this.reverted('shape.toggleCollapse', LOW_PRIORITY$l, function(context) {
22821
+ var shape = context.shape;
22822
+
22823
+ // Add overlay to the collapsed shape
22824
+ if (self.canDrillDown(shape)) {
22825
+ self.addOverlay(shape);
22826
+ } else {
22827
+ self.removeOverlay(shape);
22828
+ }
22829
+ }, true);
22830
+
22831
+
22832
+ this.executed(['shape.create', 'shape.move', 'shape.delete'], LOW_PRIORITY$l,
22833
+ function(context) {
22834
+ var oldParent = context.oldParent,
22835
+ newParent = context.newParent || context.parent,
22836
+ shape = context.shape;
22837
+
22838
+ // Add overlay to the collapsed shape
22839
+ if (self.canDrillDown(shape)) {
22840
+ self.addOverlay(shape);
22841
+ }
22842
+
22843
+ self.updateDrilldownOverlay(oldParent);
22844
+ self.updateDrilldownOverlay(newParent);
22845
+ self.updateDrilldownOverlay(shape);
22846
+ }, true);
22847
+
22848
+
22849
+ this.reverted(['shape.create', 'shape.move', 'shape.delete'], LOW_PRIORITY$l,
22850
+ function(context) {
22851
+ var oldParent = context.oldParent,
22852
+ newParent = context.newParent || context.parent,
22853
+ shape = context.shape;
22854
+
22855
+ // Add overlay to the collapsed shape
22856
+ if (self.canDrillDown(shape)) {
22857
+ self.addOverlay(shape);
22858
+ }
22859
+
22860
+ self.updateDrilldownOverlay(oldParent);
22861
+ self.updateDrilldownOverlay(newParent);
22862
+ self.updateDrilldownOverlay(shape);
22863
+ }, true);
22864
+
22865
+
22866
+ eventBus.on('import.done', function() {
22867
+ elementRegistry.filter(function(e) {
22868
+ return self.canDrillDown(e);
22869
+ }).map(function(el) {
22870
+ self.addOverlay(el);
22871
+ });
22872
+ });
22873
+
22874
+ }
22875
+
22876
+ inherits$1(DrilldownOverlayBehavior, CommandInterceptor);
22877
+
22878
+ DrilldownOverlayBehavior.prototype.updateDrilldownOverlay = function(shape) {
22879
+ var canvas = this._canvas;
22880
+
22881
+ if (!shape) {
22882
+ return;
22883
+ }
22884
+
22885
+ var root = canvas.findRoot(shape);
22886
+ if (root) {
22887
+ this.updateOverlayVisibility(root);
22888
+ }
22889
+ };
22890
+
22891
+
22892
+ DrilldownOverlayBehavior.prototype.canDrillDown = function(element) {
22893
+ var canvas = this._canvas;
22894
+ return is$1(element, 'bpmn:SubProcess') && canvas.findRoot(getPlaneIdFromShape(element));
22895
+ };
22896
+
22897
+ /**
22898
+ * Updates visibility of the drilldown overlay. If the plane has no elements,
22899
+ * the drilldown will be only shown when the element is selected.
22900
+ *
22901
+ * @param {djs.model.Shape|djs.model.Root} element collapsed shape or root element
22902
+ */
22903
+ DrilldownOverlayBehavior.prototype.updateOverlayVisibility = function(element) {
22904
+ var overlays = this._overlays;
22905
+
22906
+ var bo = element.businessObject;
22907
+
22908
+ var overlay = overlays.get({ element: bo.id, type: 'drilldown' })[0];
22909
+
22910
+ if (!overlay) {
22911
+ return;
22912
+ }
22913
+
22914
+ var hasContent = bo && bo.flowElements && bo.flowElements.length;
22915
+ classes$1(overlay.html).toggle(EMPTY_MARKER, !hasContent);
22916
+ };
22917
+
22918
+ /**
22919
+ * Attaches a drilldown button to the given element. We assume that the plane has
22920
+ * the same id as the element.
22921
+ *
22922
+ * @param {djs.model.Shape} element collapsed shape
22923
+ */
22924
+ DrilldownOverlayBehavior.prototype.addOverlay = function(element) {
22925
+ var canvas = this._canvas;
22926
+ var overlays = this._overlays;
22927
+
22928
+ var existingOverlays = overlays.get({ element: element, type: 'drilldown' });
22929
+ if (existingOverlays.length) {
22930
+ this.removeOverlay(element);
22931
+ }
22932
+
22933
+ var button = domify('<button class="bjs-drilldown">' + ARROW_DOWN_SVG + '</button>');
22934
+
22935
+ button.addEventListener('click', function() {
22936
+ canvas.setRootElement(canvas.findRoot(getPlaneIdFromShape(element)));
22937
+ });
22938
+
22939
+ overlays.add(element, 'drilldown', {
22940
+ position: {
22941
+ bottom: -7,
22942
+ right: -8
22943
+ },
22944
+ html: button
22945
+ });
22946
+
22947
+ this.updateOverlayVisibility(element);
22948
+ };
22949
+
22950
+ DrilldownOverlayBehavior.prototype.removeOverlay = function(element) {
22951
+ var overlays = this._overlays;
22952
+
22953
+ overlays.remove({
22954
+ element: element,
22955
+ type: 'drilldown'
22956
+ });
22957
+ };
22958
+
22959
+ DrilldownOverlayBehavior.$inject = [
22960
+ 'canvas',
22961
+ 'eventBus',
22962
+ 'elementRegistry',
22963
+ 'overlays'
22964
+ ];
22965
+
22255
22966
  var DrilldownModdule = {
22256
- __depends__: [ OverlaysModule, ChangeSupportModule ],
22257
- __init__: [ 'drilldownOverlays', 'drilldownCentering', 'subprocessCompatibility'],
22258
- drilldownOverlays: [ 'type', DrilldownOverlays ],
22967
+ __depends__: [ OverlaysModule, ChangeSupportModule, RootElementsModule ],
22968
+ __init__: [ 'drilldownBreadcrumbs', 'drilldownOverlayBehavior', 'drilldownCentering', 'subprocessCompatibility'],
22969
+ drilldownBreadcrumbs: [ 'type', DrilldownBreadcrumbs ],
22259
22970
  drilldownCentering: [ 'type', DrilldownCentering ],
22971
+ drilldownOverlayBehavior: [ 'type', DrilldownOverlayBehavior ],
22260
22972
  subprocessCompatibility: [ 'type', SubprocessCompatibility ]
22261
22973
  };
22262
22974
 
@@ -22371,7 +23083,7 @@
22371
23083
 
22372
23084
  var HANDLE_MODIFIER_ATTRIBUTE = 'input-handle-modified-keys';
22373
23085
 
22374
- var DEFAULT_PRIORITY$4 = 1000;
23086
+ var DEFAULT_PRIORITY$3 = 1000;
22375
23087
 
22376
23088
  /**
22377
23089
  * A keyboard abstraction that may be activated and
@@ -22469,7 +23181,7 @@
22469
23181
  }
22470
23182
 
22471
23183
  var allowedModifiers = this._getAllowedModifiers(event.target);
22472
- return !allowedModifiers.includes(event.key);
23184
+ return allowedModifiers.indexOf(event.key) === -1;
22473
23185
  };
22474
23186
 
22475
23187
  Keyboard.prototype._getAllowedModifiers = function(element) {
@@ -22531,7 +23243,7 @@
22531
23243
  if (isFunction(priority)) {
22532
23244
  type = listener;
22533
23245
  listener = priority;
22534
- priority = DEFAULT_PRIORITY$4;
23246
+ priority = DEFAULT_PRIORITY$3;
22535
23247
  }
22536
23248
 
22537
23249
  this._eventBus.on(type || KEYDOWN_EVENT, priority, listener);
@@ -22554,7 +23266,7 @@
22554
23266
  return target && (matchesSelector(target, 'input, textarea') || target.contentEditable === 'true');
22555
23267
  }
22556
23268
 
22557
- var LOW_PRIORITY$j = 500;
23269
+ var LOW_PRIORITY$k = 500;
22558
23270
 
22559
23271
  var KEYCODE_C = 67;
22560
23272
  var KEYCODE_V = 86;
@@ -22580,7 +23292,7 @@
22580
23292
 
22581
23293
  var self = this;
22582
23294
 
22583
- eventBus.on('editorActions.init', LOW_PRIORITY$j, function(event) {
23295
+ eventBus.on('editorActions.init', LOW_PRIORITY$k, function(event) {
22584
23296
 
22585
23297
  var editorActions = event.editorActions;
22586
23298
 
@@ -26084,14 +26796,23 @@
26084
26796
  // the touch recognizer
26085
26797
  var recognizer;
26086
26798
 
26087
- function handler(type) {
26799
+ function handler(type, buttonType) {
26088
26800
 
26089
26801
  return function(event) {
26090
26802
 
26091
- interactionEvents.fire(type, event);
26803
+ var gfx = getGfx(event.target),
26804
+ element = gfx && elementRegistry.get(gfx);
26805
+
26806
+ // translate into an actual mouse click event
26807
+ if (buttonType) {
26808
+ event.srcEvent.button = buttonType;
26809
+ }
26810
+
26811
+ return interactionEvents.fire(type, event, element);
26092
26812
  };
26093
26813
  }
26094
26814
 
26815
+
26095
26816
  function getGfx(target) {
26096
26817
  var node = closest(target, 'svg, .djs-element', true);
26097
26818
  return node;
@@ -26102,10 +26823,6 @@
26102
26823
  // touch recognizer
26103
26824
  recognizer = createTouchRecognizer(svg);
26104
26825
 
26105
- recognizer.on('doubletap', handler('element.dblclick'));
26106
-
26107
- recognizer.on('tap', handler('element.click'));
26108
-
26109
26826
  function startGrabCanvas(event) {
26110
26827
 
26111
26828
  var lx = 0, ly = 0;
@@ -26173,6 +26890,9 @@
26173
26890
  recognizer.on('pinchcancel', end);
26174
26891
  }
26175
26892
 
26893
+ recognizer.on('tap', handler('element.click'));
26894
+ recognizer.on('doubletap', handler('element.dblclick', 1));
26895
+
26176
26896
  recognizer.on('panstart', startGrab);
26177
26897
  recognizer.on('press', startGrab);
26178
26898
 
@@ -26793,7 +27513,7 @@
26793
27513
  return true;
26794
27514
  }
26795
27515
 
26796
- var LOW_PRIORITY$i = 100;
27516
+ var LOW_PRIORITY$j = 100;
26797
27517
 
26798
27518
 
26799
27519
  /**
@@ -26805,7 +27525,7 @@
26805
27525
  */
26806
27526
  function AutoPlace$1(eventBus, modeling, canvas) {
26807
27527
 
26808
- eventBus.on('autoPlace', LOW_PRIORITY$i, function(context) {
27528
+ eventBus.on('autoPlace', LOW_PRIORITY$j, function(context) {
26809
27529
  var shape = context.shape,
26810
27530
  source = context.source;
26811
27531
 
@@ -26910,21 +27630,6 @@
26910
27630
  autoPlaceSelectionBehavior: [ 'type', AutoPlaceSelectionBehavior ]
26911
27631
  };
26912
27632
 
26913
- /**
26914
- * Return true if element has any of the given types.
26915
- *
26916
- * @param {djs.model.Base} element
26917
- * @param {Array<string>} types
26918
- *
26919
- * @return {boolean}
26920
- */
26921
- function isAny(element, types) {
26922
- return some(types, function(t) {
26923
- return is$1(element, t);
26924
- });
26925
- }
26926
-
26927
-
26928
27633
  /**
26929
27634
  * Return the parent of the element with any of the given types.
26930
27635
  *
@@ -27093,142 +27798,6 @@
27093
27798
  bpmnAutoPlace: [ 'type', AutoPlace ]
27094
27799
  };
27095
27800
 
27096
- var DEFAULT_PRIORITY$3 = 1000;
27097
-
27098
- /**
27099
- * A utility that can be used to plug-in into the command execution for
27100
- * extension and/or validation.
27101
- *
27102
- * @param {EventBus} eventBus
27103
- *
27104
- * @example
27105
- *
27106
- * import inherits from 'inherits';
27107
- *
27108
- * import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
27109
- *
27110
- * function CommandLogger(eventBus) {
27111
- * CommandInterceptor.call(this, eventBus);
27112
- *
27113
- * this.preExecute(function(event) {
27114
- * console.log('command pre-execute', event);
27115
- * });
27116
- * }
27117
- *
27118
- * inherits(CommandLogger, CommandInterceptor);
27119
- *
27120
- */
27121
- function CommandInterceptor(eventBus) {
27122
- this._eventBus = eventBus;
27123
- }
27124
-
27125
- CommandInterceptor.$inject = [ 'eventBus' ];
27126
-
27127
- function unwrapEvent(fn, that) {
27128
- return function(event) {
27129
- return fn.call(that || null, event.context, event.command, event);
27130
- };
27131
- }
27132
-
27133
- /**
27134
- * Register an interceptor for a command execution
27135
- *
27136
- * @param {string|Array<string>} [events] list of commands to register on
27137
- * @param {string} [hook] command hook, i.e. preExecute, executed to listen on
27138
- * @param {number} [priority] the priority on which to hook into the execution
27139
- * @param {Function} handlerFn interceptor to be invoked with (event)
27140
- * @param {boolean} unwrap if true, unwrap the event and pass (context, command, event) to the
27141
- * listener instead
27142
- * @param {Object} [that] Pass context (`this`) to the handler function
27143
- */
27144
- CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
27145
-
27146
- if (isFunction(hook) || isNumber(hook)) {
27147
- that = unwrap;
27148
- unwrap = handlerFn;
27149
- handlerFn = priority;
27150
- priority = hook;
27151
- hook = null;
27152
- }
27153
-
27154
- if (isFunction(priority)) {
27155
- that = unwrap;
27156
- unwrap = handlerFn;
27157
- handlerFn = priority;
27158
- priority = DEFAULT_PRIORITY$3;
27159
- }
27160
-
27161
- if (isObject(unwrap)) {
27162
- that = unwrap;
27163
- unwrap = false;
27164
- }
27165
-
27166
- if (!isFunction(handlerFn)) {
27167
- throw new Error('handlerFn must be a function');
27168
- }
27169
-
27170
- if (!isArray$2(events)) {
27171
- events = [ events ];
27172
- }
27173
-
27174
- var eventBus = this._eventBus;
27175
-
27176
- forEach(events, function(event) {
27177
-
27178
- // concat commandStack(.event)?(.hook)?
27179
- var fullEvent = [ 'commandStack', event, hook ].filter(function(e) { return e; }).join('.');
27180
-
27181
- eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn, that) : handlerFn, that);
27182
- });
27183
- };
27184
-
27185
-
27186
- var hooks = [
27187
- 'canExecute',
27188
- 'preExecute',
27189
- 'preExecuted',
27190
- 'execute',
27191
- 'executed',
27192
- 'postExecute',
27193
- 'postExecuted',
27194
- 'revert',
27195
- 'reverted'
27196
- ];
27197
-
27198
- /*
27199
- * Install hook shortcuts
27200
- *
27201
- * This will generate the CommandInterceptor#(preExecute|...|reverted) methods
27202
- * which will in term forward to CommandInterceptor#on.
27203
- */
27204
- forEach(hooks, function(hook) {
27205
-
27206
- /**
27207
- * {canExecute|preExecute|preExecuted|execute|executed|postExecute|postExecuted|revert|reverted}
27208
- *
27209
- * A named hook for plugging into the command execution
27210
- *
27211
- * @param {string|Array<string>} [events] list of commands to register on
27212
- * @param {number} [priority] the priority on which to hook into the execution
27213
- * @param {Function} handlerFn interceptor to be invoked with (event)
27214
- * @param {boolean} [unwrap=false] if true, unwrap the event and pass (context, command, event) to the
27215
- * listener instead
27216
- * @param {Object} [that] Pass context (`this`) to the handler function
27217
- */
27218
- CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
27219
-
27220
- if (isFunction(events) || isNumber(events)) {
27221
- that = unwrap;
27222
- unwrap = handlerFn;
27223
- handlerFn = priority;
27224
- priority = events;
27225
- events = null;
27226
- }
27227
-
27228
- this.on(events, hook, priority, handlerFn, unwrap, that);
27229
- };
27230
- });
27231
-
27232
27801
  /**
27233
27802
  * An auto resize component that takes care of expanding a parent element
27234
27803
  * if child elements are created or moved close the parents edge.
@@ -27668,6 +28237,12 @@
27668
28237
  */
27669
28238
  BpmnAutoResizeProvider.prototype.canResize = function(elements, target) {
27670
28239
 
28240
+ // do not resize plane elements:
28241
+ // root elements, collapsed sub-processes
28242
+ if (is$1(target.di, 'bpmndi:BPMNPlane')) {
28243
+ return false;
28244
+ }
28245
+
27671
28246
  if (!is$1(target, 'bpmn:Participant') && !is$1(target, 'bpmn:Lane') && !(is$1(target, 'bpmn:SubProcess'))) {
27672
28247
  return false;
27673
28248
  }
@@ -27694,7 +28269,7 @@
27694
28269
  bpmnAutoResizeProvider: [ 'type', BpmnAutoResizeProvider ]
27695
28270
  };
27696
28271
 
27697
- var HIGH_PRIORITY$j = 1500;
28272
+ var HIGH_PRIORITY$k = 1500;
27698
28273
 
27699
28274
 
27700
28275
  /**
@@ -27762,7 +28337,7 @@
27762
28337
  */
27763
28338
  eventBus.on('drag.start', function(event) {
27764
28339
 
27765
- eventBus.once('drag.move', HIGH_PRIORITY$j, function(event) {
28340
+ eventBus.once('drag.move', HIGH_PRIORITY$k, function(event) {
27766
28341
 
27767
28342
  ensureHover(event);
27768
28343
 
@@ -27793,7 +28368,7 @@
27793
28368
  hover = event.element;
27794
28369
  });
27795
28370
 
27796
- eventBus.on('element.hover', HIGH_PRIORITY$j, function(event) {
28371
+ eventBus.on('element.hover', HIGH_PRIORITY$k, function(event) {
27797
28372
 
27798
28373
  // (3) am I on an element still?
27799
28374
  if (hover) {
@@ -29467,7 +30042,7 @@
29467
30042
  MARKER_CONNECT_UPDATING$1 = 'djs-updating',
29468
30043
  MARKER_ELEMENT_HIDDEN = 'djs-element-hidden';
29469
30044
 
29470
- var HIGH_PRIORITY$i = 1100;
30045
+ var HIGH_PRIORITY$j = 1100;
29471
30046
 
29472
30047
  /**
29473
30048
  * Preview connection while moving bendpoints.
@@ -29530,7 +30105,7 @@
29530
30105
  eventBus.on([
29531
30106
  'bendpoint.move.out',
29532
30107
  'bendpoint.move.cleanup'
29533
- ], HIGH_PRIORITY$i, function(event) {
30108
+ ], HIGH_PRIORITY$j, function(event) {
29534
30109
  var context = event.context,
29535
30110
  hover = context.hover,
29536
30111
  target = context.target;
@@ -29616,7 +30191,7 @@
29616
30191
  eventBus.on([
29617
30192
  'bendpoint.move.end',
29618
30193
  'bendpoint.move.cancel'
29619
- ], HIGH_PRIORITY$i, function(event) {
30194
+ ], HIGH_PRIORITY$j, function(event) {
29620
30195
  var context = event.context,
29621
30196
  connection = context.connection,
29622
30197
  draggerGfx = context.draggerGfx,
@@ -30547,8 +31122,8 @@
30547
31122
  return hover && source && hover === source && source !== target;
30548
31123
  }
30549
31124
 
30550
- var HIGH_PRIORITY$h = 1100,
30551
- LOW_PRIORITY$h = 900;
31125
+ var HIGH_PRIORITY$i = 1100,
31126
+ LOW_PRIORITY$i = 900;
30552
31127
 
30553
31128
  var MARKER_OK$3 = 'connect-ok',
30554
31129
  MARKER_NOT_OK$3 = 'connect-not-ok';
@@ -30592,7 +31167,7 @@
30592
31167
  });
30593
31168
  });
30594
31169
 
30595
- eventBus.on('connect.hover', LOW_PRIORITY$h, function(event) {
31170
+ eventBus.on('connect.hover', LOW_PRIORITY$i, function(event) {
30596
31171
  var context = event.context,
30597
31172
  hover = event.hover,
30598
31173
  canExecute = context.canExecute;
@@ -30608,7 +31183,7 @@
30608
31183
  eventBus.on([
30609
31184
  'connect.out',
30610
31185
  'connect.cleanup'
30611
- ], HIGH_PRIORITY$h, function(event) {
31186
+ ], HIGH_PRIORITY$i, function(event) {
30612
31187
  var hover = event.hover;
30613
31188
 
30614
31189
  if (hover) {
@@ -32160,7 +32735,7 @@
32160
32735
 
32161
32736
  var PREFIX = 'create';
32162
32737
 
32163
- var HIGH_PRIORITY$g = 2000;
32738
+ var HIGH_PRIORITY$h = 2000;
32164
32739
 
32165
32740
 
32166
32741
  /**
@@ -32388,7 +32963,7 @@
32388
32963
  eventBus.on('create.init', function() {
32389
32964
  eventBus.on('elements.changed', cancel);
32390
32965
 
32391
- eventBus.once([ 'create.cancel', 'create.end' ], HIGH_PRIORITY$g, function() {
32966
+ eventBus.once([ 'create.cancel', 'create.end' ], HIGH_PRIORITY$h, function() {
32392
32967
  eventBus.off('elements.changed', cancel);
32393
32968
  });
32394
32969
  });
@@ -32427,7 +33002,11 @@
32427
33002
  }
32428
33003
  });
32429
33004
 
32430
- var bbox = getBBox(elements);
33005
+ var visibleElements = filter(elements, function(element) {
33006
+ return !element.hidden;
33007
+ });
33008
+
33009
+ var bbox = getBBox(visibleElements);
32431
33010
 
32432
33011
  // center elements around cursor
32433
33012
  forEach(elements, function(element) {
@@ -32505,7 +33084,7 @@
32505
33084
  return !!element.labelTarget;
32506
33085
  }
32507
33086
 
32508
- var LOW_PRIORITY$g = 750;
33087
+ var LOW_PRIORITY$h = 750;
32509
33088
 
32510
33089
 
32511
33090
  function CreatePreview(
@@ -32550,7 +33129,7 @@
32550
33129
  return dragGroup;
32551
33130
  }
32552
33131
 
32553
- eventBus.on('create.move', LOW_PRIORITY$g, function(event) {
33132
+ eventBus.on('create.move', LOW_PRIORITY$h, function(event) {
32554
33133
 
32555
33134
  var hover = event.hover,
32556
33135
  context = event.context,
@@ -33298,6 +33877,14 @@
33298
33877
  * @param {Array<djs.model.Base>} context.elements
33299
33878
  */
33300
33879
 
33880
+ /**
33881
+ * @typedef {Function} <copyPaste.createTree> listener
33882
+ *
33883
+ * @param {Object} context
33884
+ * @param {djs.model.Base} context.element
33885
+ * @param {Array<djs.model.Base>} context.children - Add children to be added to tree.
33886
+ */
33887
+
33301
33888
  /**
33302
33889
  * @typedef {Function} <copyPaste.elementsCopied> listener
33303
33890
  *
@@ -33766,7 +34353,19 @@
33766
34353
 
33767
34354
  addElementData(element, depth);
33768
34355
 
33769
- return element.children;
34356
+ var children = [];
34357
+
34358
+ if (element.children) {
34359
+ children = element.children.slice();
34360
+ }
34361
+
34362
+ // allow others to add children to tree
34363
+ self._eventBus.fire('copyPaste.createTree', {
34364
+ element: element,
34365
+ children: children
34366
+ });
34367
+
34368
+ return children;
33770
34369
  });
33771
34370
 
33772
34371
  elements = map$1(elementsData, function(elementData) {
@@ -33897,12 +34496,12 @@
33897
34496
  });
33898
34497
  }
33899
34498
 
33900
- var LOW_PRIORITY$f = 750;
34499
+ var LOW_PRIORITY$g = 750;
33901
34500
 
33902
34501
 
33903
34502
  function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
33904
34503
 
33905
- eventBus.on('copyPaste.copyElement', LOW_PRIORITY$f, function(context) {
34504
+ eventBus.on('copyPaste.copyElement', LOW_PRIORITY$g, function(context) {
33906
34505
  var descriptor = context.descriptor,
33907
34506
  element = context.element;
33908
34507
 
@@ -34006,6 +34605,7 @@
34006
34605
  );
34007
34606
 
34008
34607
  newDi = bpmnFactory.create(oldDi.$type);
34608
+ newDi.bpmnElement = newBusinessObject;
34009
34609
 
34010
34610
  descriptor.di = moddleCopy.copyElement(
34011
34611
  oldDi,
@@ -35644,7 +36244,7 @@
35644
36244
  return this._createEntries(element, DATA_OBJECT_REFERENCE);
35645
36245
  }
35646
36246
 
35647
- if (is$1(businessObject, 'bpmn:DataStoreReference')) {
36247
+ if (is$1(businessObject, 'bpmn:DataStoreReference') && !is$1(element.parent, 'bpmn:Collaboration')) {
35648
36248
  return this._createEntries(element, DATA_STORE_REFERENCE);
35649
36249
  }
35650
36250
 
@@ -37709,7 +38309,7 @@
37709
38309
  }
37710
38310
 
37711
38311
  var LOWER_PRIORITY = 1200;
37712
- var LOW_PRIORITY$e = 800;
38312
+ var LOW_PRIORITY$f = 800;
37713
38313
 
37714
38314
  /**
37715
38315
  * Basic grid snapping that covers connecting, creating, moving, resizing shapes, moving bendpoints
@@ -37723,7 +38323,7 @@
37723
38323
 
37724
38324
  var self = this;
37725
38325
 
37726
- eventBus.on('diagram.init', LOW_PRIORITY$e, function() {
38326
+ eventBus.on('diagram.init', LOW_PRIORITY$f, function() {
37727
38327
  self.setActive(active);
37728
38328
  });
37729
38329
 
@@ -38208,7 +38808,7 @@
38208
38808
  return newBounds;
38209
38809
  };
38210
38810
 
38211
- var HIGH_PRIORITY$f = 2000;
38811
+ var HIGH_PRIORITY$g = 2000;
38212
38812
 
38213
38813
  /**
38214
38814
  * Integrates space tool with grid snapping.
@@ -38217,7 +38817,7 @@
38217
38817
  eventBus.on([
38218
38818
  'spaceTool.move',
38219
38819
  'spaceTool.end'
38220
- ], HIGH_PRIORITY$f, function(event) {
38820
+ ], HIGH_PRIORITY$g, function(event) {
38221
38821
  var context = event.context;
38222
38822
 
38223
38823
  if (!context.initialized) {
@@ -38266,11 +38866,11 @@
38266
38866
  gridSnapping: [ 'type', GridSnapping ]
38267
38867
  };
38268
38868
 
38269
- var HIGH_PRIORITY$e = 2000;
38869
+ var HIGH_PRIORITY$f = 2000;
38270
38870
 
38271
38871
 
38272
38872
  function AutoPlaceBehavior(eventBus, gridSnapping) {
38273
- eventBus.on('autoPlace', HIGH_PRIORITY$e, function(context) {
38873
+ eventBus.on('autoPlace', HIGH_PRIORITY$f, function(context) {
38274
38874
  var source = context.source,
38275
38875
  sourceMid = getMid(source),
38276
38876
  shape = context.shape;
@@ -38356,7 +38956,7 @@
38356
38956
  'gridSnapping'
38357
38957
  ];
38358
38958
 
38359
- var HIGH_PRIORITY$d = 3000;
38959
+ var HIGH_PRIORITY$e = 3000;
38360
38960
 
38361
38961
 
38362
38962
  /**
@@ -38372,7 +38972,7 @@
38372
38972
  this.postExecuted([
38373
38973
  'connection.create',
38374
38974
  'connection.layout'
38375
- ], HIGH_PRIORITY$d, function(event) {
38975
+ ], HIGH_PRIORITY$e, function(event) {
38376
38976
  var context = event.context,
38377
38977
  connection = context.connection,
38378
38978
  hints = context.hints || {},
@@ -39200,7 +39800,7 @@
39200
39800
  var MARKER_RESIZING$1 = 'djs-resizing',
39201
39801
  MARKER_RESIZE_NOT_OK = 'resize-not-ok';
39202
39802
 
39203
- var LOW_PRIORITY$d = 500;
39803
+ var LOW_PRIORITY$e = 500;
39204
39804
 
39205
39805
 
39206
39806
  /**
@@ -39261,7 +39861,7 @@
39261
39861
  }
39262
39862
 
39263
39863
  // add and update previews
39264
- eventBus.on('resize.move', LOW_PRIORITY$d, function(event) {
39864
+ eventBus.on('resize.move', LOW_PRIORITY$e, function(event) {
39265
39865
  updateFrame(event.context);
39266
39866
  });
39267
39867
 
@@ -39576,7 +40176,7 @@
39576
40176
 
39577
40177
  function activateDirectEdit(element, force) {
39578
40178
  if (force ||
39579
- isAny(element, [ 'bpmn:Task', 'bpmn:TextAnnotation', 'bpmn:Group' ]) ||
40179
+ isAny(element, [ 'bpmn:Task', 'bpmn:TextAnnotation' ]) ||
39580
40180
  isCollapsedSubProcess(element)) {
39581
40181
 
39582
40182
  directEditing.activate(element);
@@ -40358,7 +40958,7 @@
40358
40958
  'modeling'
40359
40959
  ];
40360
40960
 
40361
- var LOW_PRIORITY$c = 500;
40961
+ var LOW_PRIORITY$d = 500;
40362
40962
 
40363
40963
 
40364
40964
  /**
@@ -40371,7 +40971,7 @@
40371
40971
 
40372
40972
  var self = this;
40373
40973
 
40374
- this.postExecuted('elements.create', LOW_PRIORITY$c, function(context) {
40974
+ this.postExecuted('elements.create', LOW_PRIORITY$d, function(context) {
40375
40975
  var elements = context.elements;
40376
40976
 
40377
40977
  elements = elements.filter(function(shape) {
@@ -40394,7 +40994,7 @@
40394
40994
  }, true);
40395
40995
 
40396
40996
 
40397
- this.preExecute('elements.move', LOW_PRIORITY$c, function(context) {
40997
+ this.preExecute('elements.move', LOW_PRIORITY$d, function(context) {
40398
40998
  var shapes = context.shapes,
40399
40999
  host = context.newHost;
40400
41000
 
@@ -40447,7 +41047,7 @@
40447
41047
  isAny(shape, [ 'bpmn:IntermediateThrowEvent', 'bpmn:IntermediateCatchEvent' ]) && !!host;
40448
41048
  }
40449
41049
 
40450
- var HIGH_PRIORITY$c = 2000;
41050
+ var HIGH_PRIORITY$d = 2000;
40451
41051
 
40452
41052
 
40453
41053
  /**
@@ -40499,7 +41099,7 @@
40499
41099
  });
40500
41100
 
40501
41101
  // copy reference to root element on replace
40502
- eventBus.on('moddleCopy.canCopyProperty', HIGH_PRIORITY$c, function(context) {
41102
+ eventBus.on('moddleCopy.canCopyProperty', HIGH_PRIORITY$d, function(context) {
40503
41103
  var parent = context.parent,
40504
41104
  property = context.property,
40505
41105
  propertyName = context.propertyName;
@@ -40520,167 +41120,6 @@
40520
41120
 
40521
41121
  inherits$1(BoundaryEventBehavior, CommandInterceptor);
40522
41122
 
40523
- var LOW_PRIORITY$b = 500;
40524
-
40525
-
40526
- /**
40527
- * Add referenced root elements (error, escalation, message, signal) if they don't exist.
40528
- * Copy referenced root elements on copy & paste.
40529
- */
40530
- function RootElementReferenceBehavior(
40531
- bpmnjs, eventBus, injector, moddleCopy, bpmnFactory
40532
- ) {
40533
- injector.invoke(CommandInterceptor, this);
40534
-
40535
- function canHaveRootElementReference(element) {
40536
- return isAny(element, [ 'bpmn:ReceiveTask', 'bpmn:SendTask' ]) ||
40537
- hasAnyEventDefinition(element, [
40538
- 'bpmn:ErrorEventDefinition',
40539
- 'bpmn:EscalationEventDefinition',
40540
- 'bpmn:MessageEventDefinition',
40541
- 'bpmn:SignalEventDefinition'
40542
- ]);
40543
- }
40544
-
40545
- function hasRootElement(rootElement) {
40546
- var definitions = bpmnjs.getDefinitions(),
40547
- rootElements = definitions.get('rootElements');
40548
-
40549
- return !!find(rootElements, matchPattern({ id: rootElement.id }));
40550
- }
40551
-
40552
- function getRootElementReferencePropertyName(eventDefinition) {
40553
- if (is$1(eventDefinition, 'bpmn:ErrorEventDefinition')) {
40554
- return 'errorRef';
40555
- } else if (is$1(eventDefinition, 'bpmn:EscalationEventDefinition')) {
40556
- return 'escalationRef';
40557
- } else if (is$1(eventDefinition, 'bpmn:MessageEventDefinition')) {
40558
- return 'messageRef';
40559
- } else if (is$1(eventDefinition, 'bpmn:SignalEventDefinition')) {
40560
- return 'signalRef';
40561
- }
40562
- }
40563
-
40564
- function getRootElement(businessObject) {
40565
- if (isAny(businessObject, [ 'bpmn:ReceiveTask', 'bpmn:SendTask' ])) {
40566
- return businessObject.get('messageRef');
40567
- }
40568
-
40569
- var eventDefinitions = businessObject.get('eventDefinitions'),
40570
- eventDefinition = eventDefinitions[ 0 ];
40571
-
40572
- return eventDefinition.get(getRootElementReferencePropertyName(eventDefinition));
40573
- }
40574
-
40575
- function setRootElement(businessObject, rootElement) {
40576
- if (isAny(businessObject, [ 'bpmn:ReceiveTask', 'bpmn:SendTask' ])) {
40577
- return businessObject.set('messageRef', rootElement);
40578
- }
40579
-
40580
- var eventDefinitions = businessObject.get('eventDefinitions'),
40581
- eventDefinition = eventDefinitions[ 0 ];
40582
-
40583
- return eventDefinition.set(getRootElementReferencePropertyName(eventDefinition), rootElement);
40584
- }
40585
-
40586
- // create shape
40587
- this.executed('shape.create', function(context) {
40588
- var shape = context.shape;
40589
-
40590
- if (!canHaveRootElementReference(shape)) {
40591
- return;
40592
- }
40593
-
40594
- var businessObject = getBusinessObject(shape),
40595
- rootElement = getRootElement(businessObject),
40596
- rootElements;
40597
-
40598
- if (rootElement && !hasRootElement(rootElement)) {
40599
- rootElements = bpmnjs.getDefinitions().get('rootElements');
40600
-
40601
- // add root element
40602
- add(rootElements, rootElement);
40603
-
40604
- context.addedRootElement = rootElement;
40605
- }
40606
- }, true);
40607
-
40608
- this.reverted('shape.create', function(context) {
40609
- var addedRootElement = context.addedRootElement;
40610
-
40611
- if (!addedRootElement) {
40612
- return;
40613
- }
40614
-
40615
- var rootElements = bpmnjs.getDefinitions().get('rootElements');
40616
-
40617
- // remove root element
40618
- remove(rootElements, addedRootElement);
40619
- }, true);
40620
-
40621
- eventBus.on('copyPaste.copyElement', function(context) {
40622
- var descriptor = context.descriptor,
40623
- element = context.element;
40624
-
40625
- if (!canHaveRootElementReference(element)) {
40626
- return;
40627
- }
40628
-
40629
- var businessObject = getBusinessObject(element),
40630
- rootElement = getRootElement(businessObject);
40631
-
40632
- if (rootElement) {
40633
- descriptor.referencedRootElement = rootElement;
40634
- }
40635
- });
40636
-
40637
- eventBus.on('copyPaste.pasteElement', LOW_PRIORITY$b, function(context) {
40638
- var descriptor = context.descriptor,
40639
- businessObject = descriptor.businessObject;
40640
-
40641
- if (!canHaveRootElementReference(businessObject)) {
40642
- return;
40643
- }
40644
-
40645
- var referencedRootElement = descriptor.referencedRootElement;
40646
-
40647
- if (!referencedRootElement) {
40648
- return;
40649
- }
40650
-
40651
- if (!hasRootElement(referencedRootElement)) {
40652
- referencedRootElement = moddleCopy.copyElement(
40653
- referencedRootElement,
40654
- bpmnFactory.create(referencedRootElement.$type)
40655
- );
40656
- }
40657
-
40658
- setRootElement(businessObject, referencedRootElement);
40659
- });
40660
- }
40661
-
40662
- RootElementReferenceBehavior.$inject = [
40663
- 'bpmnjs',
40664
- 'eventBus',
40665
- 'injector',
40666
- 'moddleCopy',
40667
- 'bpmnFactory'
40668
- ];
40669
-
40670
- inherits$1(RootElementReferenceBehavior, CommandInterceptor);
40671
-
40672
- // helpers //////////
40673
-
40674
- function hasAnyEventDefinition(element, types) {
40675
- if (!isArray$2(types)) {
40676
- types = [ types ];
40677
- }
40678
-
40679
- return some(types, function(type) {
40680
- return hasEventDefinition$2(element, type);
40681
- });
40682
- }
40683
-
40684
41123
  function CreateBehavior(injector) {
40685
41124
  injector.invoke(CommandInterceptor, this);
40686
41125
 
@@ -40701,118 +41140,6 @@
40701
41140
 
40702
41141
  inherits$1(CreateBehavior, CommandInterceptor);
40703
41142
 
40704
- var HIGH_PRIORITY$b = 1500;
40705
- var HIGHEST_PRIORITY = 2000;
40706
-
40707
-
40708
- /**
40709
- * Correct hover targets in certain situations to improve diagram interaction.
40710
- *
40711
- * @param {ElementRegistry} elementRegistry
40712
- * @param {EventBus} eventBus
40713
- * @param {Canvas} canvas
40714
- */
40715
- function FixHoverBehavior(elementRegistry, eventBus, canvas) {
40716
-
40717
- eventBus.on([
40718
- 'create.hover',
40719
- 'create.move',
40720
- 'create.out',
40721
- 'create.end',
40722
- 'shape.move.hover',
40723
- 'shape.move.move',
40724
- 'shape.move.out',
40725
- 'shape.move.end'
40726
- ], HIGH_PRIORITY$b, function(event) {
40727
- var context = event.context,
40728
- shape = context.shape || event.shape,
40729
- hover = event.hover;
40730
-
40731
- // ensure elements are not dropped onto a bpmn:Lane but onto
40732
- // the underlying bpmn:Participant
40733
- if (is$1(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
40734
- event.hover = getLanesRoot(hover);
40735
- event.hoverGfx = elementRegistry.getGraphics(event.hover);
40736
- }
40737
-
40738
- var rootElement = canvas.getRootElement();
40739
-
40740
- // ensure bpmn:Group and label elements are dropped
40741
- // always onto the root
40742
- if (hover !== rootElement && (shape.labelTarget || is$1(shape, 'bpmn:Group'))) {
40743
- event.hover = rootElement;
40744
- event.hoverGfx = elementRegistry.getGraphics(event.hover);
40745
- }
40746
- });
40747
-
40748
- eventBus.on([
40749
- 'connect.hover',
40750
- 'connect.out',
40751
- 'connect.end',
40752
- 'connect.cleanup',
40753
- 'global-connect.hover',
40754
- 'global-connect.out',
40755
- 'global-connect.end',
40756
- 'global-connect.cleanup'
40757
- ], HIGH_PRIORITY$b, function(event) {
40758
- var hover = event.hover;
40759
-
40760
- // ensure connections start/end on bpmn:Participant,
40761
- // not the underlying bpmn:Lane
40762
- if (is$1(hover, 'bpmn:Lane')) {
40763
- event.hover = getLanesRoot(hover) || hover;
40764
- event.hoverGfx = elementRegistry.getGraphics(event.hover);
40765
- }
40766
- });
40767
-
40768
-
40769
- eventBus.on([
40770
- 'bendpoint.move.hover'
40771
- ], HIGH_PRIORITY$b, function(event) {
40772
- var context = event.context,
40773
- hover = event.hover,
40774
- type = context.type;
40775
-
40776
- // ensure reconnect start/end on bpmn:Participant,
40777
- // not the underlying bpmn:Lane
40778
- if (is$1(hover, 'bpmn:Lane') && /reconnect/.test(type)) {
40779
- event.hover = getLanesRoot(hover) || hover;
40780
- event.hoverGfx = elementRegistry.getGraphics(event.hover);
40781
- }
40782
- });
40783
-
40784
-
40785
- eventBus.on([
40786
- 'connect.start'
40787
- ], HIGH_PRIORITY$b, function(event) {
40788
- var context = event.context,
40789
- start = context.start;
40790
-
40791
- // ensure connect start on bpmn:Participant,
40792
- // not the underlying bpmn:Lane
40793
- if (is$1(start, 'bpmn:Lane')) {
40794
- context.start = getLanesRoot(start) || start;
40795
- }
40796
- });
40797
-
40798
-
40799
- // allow movement of participants from lanes
40800
- eventBus.on('shape.move.start', HIGHEST_PRIORITY, function(event) {
40801
- var shape = event.shape;
40802
-
40803
- if (is$1(shape, 'bpmn:Lane')) {
40804
- event.shape = getLanesRoot(shape) || shape;
40805
- }
40806
- });
40807
-
40808
- }
40809
-
40810
- FixHoverBehavior.$inject = [
40811
- 'elementRegistry',
40812
- 'eventBus',
40813
- 'canvas'
40814
- ];
40815
-
40816
41143
  /**
40817
41144
  * BPMN specific create data object behavior
40818
41145
  */
@@ -40850,7 +41177,7 @@
40850
41177
 
40851
41178
  var PARTICIPANT_BORDER_WIDTH = 30;
40852
41179
 
40853
- var HIGH_PRIORITY$a = 2000;
41180
+ var HIGH_PRIORITY$c = 2000;
40854
41181
 
40855
41182
 
40856
41183
  /**
@@ -40863,7 +41190,7 @@
40863
41190
  eventBus.on([
40864
41191
  'create.start',
40865
41192
  'shape.move.start'
40866
- ], HIGH_PRIORITY$a, function(event) {
41193
+ ], HIGH_PRIORITY$c, function(event) {
40867
41194
  var context = event.context,
40868
41195
  shape = context.shape,
40869
41196
  rootElement = canvas.getRootElement();
@@ -40898,7 +41225,7 @@
40898
41225
  });
40899
41226
 
40900
41227
  // force hovering process when creating first participant
40901
- eventBus.on('create.start', HIGH_PRIORITY$a, function(event) {
41228
+ eventBus.on('create.start', HIGH_PRIORITY$c, function(event) {
40902
41229
  var context = event.context,
40903
41230
  shape = context.shape,
40904
41231
  rootElement = canvas.getRootElement(),
@@ -40910,7 +41237,7 @@
40910
41237
  }
40911
41238
 
40912
41239
  if (is$1(shape, 'bpmn:Participant') && is$1(rootElement, 'bpmn:Process')) {
40913
- eventBus.on('element.hover', HIGH_PRIORITY$a, ensureHoveringProcess);
41240
+ eventBus.on('element.hover', HIGH_PRIORITY$c, ensureHoveringProcess);
40914
41241
 
40915
41242
  eventBus.once('create.cleanup', function() {
40916
41243
  eventBus.off('element.hover', ensureHoveringProcess);
@@ -40918,122 +41245,97 @@
40918
41245
  }
40919
41246
  });
40920
41247
 
40921
- function ensureCollaboration(context) {
40922
- var parent = context.parent,
40923
- collaboration;
40924
-
41248
+ // turn process into collaboration when creating first participant
41249
+ function getOrCreateCollaboration() {
40925
41250
  var rootElement = canvas.getRootElement();
40926
41251
 
40927
41252
  if (is$1(rootElement, 'bpmn:Collaboration')) {
40928
- collaboration = rootElement;
40929
- } else {
40930
-
40931
- // update root element by making collaboration
40932
- collaboration = modeling.makeCollaboration();
40933
-
40934
- // re-use process when creating first participant
40935
- context.process = parent;
41253
+ return rootElement;
40936
41254
  }
40937
41255
 
40938
- context.parent = collaboration;
41256
+ return modeling.makeCollaboration();
40939
41257
  }
40940
41258
 
40941
- // turn process into collaboration before adding participant
40942
- this.preExecute('shape.create', function(context) {
40943
- var parent = context.parent,
40944
- shape = context.shape;
40945
-
40946
- if (is$1(shape, 'bpmn:Participant') && is$1(parent, 'bpmn:Process')) {
40947
- ensureCollaboration(context);
40948
- }
40949
- }, true);
40950
-
40951
- this.execute('shape.create', function(context) {
40952
- var process = context.process,
40953
- shape = context.shape;
40954
-
40955
- if (process) {
40956
- context.oldProcessRef = shape.businessObject.processRef;
40957
-
40958
- // re-use process when creating first participant
40959
- shape.businessObject.processRef = process.businessObject;
40960
- }
40961
- }, true);
41259
+ // when creating mutliple elements through `elements.create` parent must be set to collaboration
41260
+ // and passed to `shape.create` as hint
41261
+ this.preExecute('elements.create', HIGH_PRIORITY$c, function(context) {
41262
+ var elements = context.elements,
41263
+ parent = context.parent,
41264
+ participant = findParticipant(elements),
41265
+ hints;
40962
41266
 
40963
- this.revert('shape.create', function(context) {
40964
- var process = context.process,
40965
- shape = context.shape;
41267
+ if (participant && is$1(parent, 'bpmn:Process')) {
41268
+ context.parent = getOrCreateCollaboration();
40966
41269
 
40967
- if (process) {
41270
+ hints = context.hints = context.hints || {};
40968
41271
 
40969
- // re-use process when creating first participant
40970
- shape.businessObject.processRef = context.oldProcessRef;
41272
+ hints.participant = participant;
41273
+ hints.process = parent;
41274
+ hints.processRef = getBusinessObject(participant).get('processRef');
40971
41275
  }
40972
41276
  }, true);
40973
41277
 
40974
- this.postExecute('shape.create', function(context) {
40975
- var process = context.process,
41278
+ // when creating single shape through `shape.create` parent must be set to collaboration
41279
+ // unless it was already set through `elements.create`
41280
+ this.preExecute('shape.create', function(context) {
41281
+ var parent = context.parent,
40976
41282
  shape = context.shape;
40977
41283
 
40978
- if (process) {
40979
-
40980
- // move children from process to participant
40981
- var processChildren = process.children.slice();
41284
+ if (is$1(shape, 'bpmn:Participant') && is$1(parent, 'bpmn:Process')) {
41285
+ context.parent = getOrCreateCollaboration();
40982
41286
 
40983
- modeling.moveElements(processChildren, { x: 0, y: 0 }, shape);
41287
+ context.process = parent;
41288
+ context.processRef = getBusinessObject(shape).get('processRef');
40984
41289
  }
40985
-
40986
41290
  }, true);
40987
41291
 
40988
- // turn process into collaboration when creating participants
40989
- this.preExecute('elements.create', HIGH_PRIORITY$a, function(context) {
40990
- var elements = context.elements,
40991
- parent = context.parent,
40992
- participant;
40993
-
40994
- var hasParticipants = findParticipant(elements);
40995
-
40996
- if (hasParticipants && is$1(parent, 'bpmn:Process')) {
40997
- ensureCollaboration(context);
40998
-
40999
- participant = findParticipant(elements);
41292
+ // #execute necessary because #preExecute not called on CommandStack#redo
41293
+ this.execute('shape.create', function(context) {
41294
+ var hints = context.hints || {},
41295
+ process = context.process || hints.process,
41296
+ shape = context.shape,
41297
+ participant = hints.participant;
41000
41298
 
41001
- context.oldProcessRef = participant.businessObject.processRef;
41299
+ // both shape.create and elements.create must be handled
41300
+ if (process && (!participant || shape === participant)) {
41002
41301
 
41003
- // re-use process when creating first participant
41004
- participant.businessObject.processRef = parent.businessObject;
41302
+ // monkey-patch process ref
41303
+ getBusinessObject(shape).set('processRef', getBusinessObject(process));
41005
41304
  }
41006
41305
  }, true);
41007
41306
 
41008
- this.revert('elements.create', function(context) {
41009
- var elements = context.elements,
41010
- process = context.process,
41011
- participant;
41307
+ this.revert('shape.create', function(context) {
41308
+ var hints = context.hints || {},
41309
+ process = context.process || hints.process,
41310
+ processRef = context.processRef || hints.processRef,
41311
+ shape = context.shape,
41312
+ participant = hints.participant;
41012
41313
 
41013
- if (process) {
41014
- participant = findParticipant(elements);
41314
+ // both shape.create and elements.create must be handled
41315
+ if (process && (!participant || shape === participant)) {
41015
41316
 
41016
- // re-use process when creating first participant
41017
- participant.businessObject.processRef = context.oldProcessRef;
41317
+ // monkey-patch process ref
41318
+ getBusinessObject(shape).set('processRef', processRef);
41018
41319
  }
41019
41320
  }, true);
41020
41321
 
41021
- this.postExecute('elements.create', function(context) {
41022
- var elements = context.elements,
41023
- process = context.process,
41024
- participant;
41322
+ this.postExecute('shape.create', function(context) {
41323
+ var hints = context.hints || {},
41324
+ process = context.process || context.hints.process,
41325
+ shape = context.shape,
41326
+ participant = hints.participant;
41025
41327
 
41026
41328
  if (process) {
41027
- participant = findParticipant(elements);
41028
-
41029
- // move children from process to first participant
41030
- var processChildren = process.children.slice();
41329
+ var children = process.children.slice();
41031
41330
 
41032
- modeling.moveElements(processChildren, { x: 0, y: 0 }, participant);
41331
+ // both shape.create and elements.create must be handled
41332
+ if (!participant) {
41333
+ modeling.moveElements(children, { x: 0, y: 0 }, shape);
41334
+ } else if (shape === participant) {
41335
+ modeling.moveElements(children, { x: 0, y: 0 }, participant);
41336
+ }
41033
41337
  }
41034
-
41035
41338
  }, true);
41036
-
41037
41339
  }
41038
41340
 
41039
41341
  CreateParticipantBehavior.$inject = [
@@ -41460,7 +41762,7 @@
41460
41762
  }
41461
41763
  }
41462
41764
 
41463
- var LOW_PRIORITY$a = 500;
41765
+ var LOW_PRIORITY$c = 500;
41464
41766
 
41465
41767
 
41466
41768
  /**
@@ -41529,7 +41831,7 @@
41529
41831
  /**
41530
41832
  * Adjust sizes of other lanes after lane deletion
41531
41833
  */
41532
- this.postExecuted('shape.delete', LOW_PRIORITY$a, function(event) {
41834
+ this.postExecuted('shape.delete', LOW_PRIORITY$c, function(event) {
41533
41835
 
41534
41836
  var context = event.context,
41535
41837
  hints = context.hints,
@@ -41558,7 +41860,7 @@
41558
41860
 
41559
41861
  inherits$1(DeleteLaneBehavior, CommandInterceptor);
41560
41862
 
41561
- var LOW_PRIORITY$9 = 500;
41863
+ var LOW_PRIORITY$b = 500;
41562
41864
 
41563
41865
 
41564
41866
  /**
@@ -41571,7 +41873,7 @@
41571
41873
 
41572
41874
  var self = this;
41573
41875
 
41574
- this.postExecuted('elements.create', LOW_PRIORITY$9, function(context) {
41876
+ this.postExecuted('elements.create', LOW_PRIORITY$b, function(context) {
41575
41877
  var elements = context.elements;
41576
41878
 
41577
41879
  elements.filter(function(shape) {
@@ -41585,7 +41887,7 @@
41585
41887
  });
41586
41888
  }, true);
41587
41889
 
41588
- this.preExecute('elements.move', LOW_PRIORITY$9, function(context) {
41890
+ this.preExecute('elements.move', LOW_PRIORITY$b, function(context) {
41589
41891
  var shapes = context.shapes,
41590
41892
  newHost = context.newHost;
41591
41893
 
@@ -41685,12 +41987,12 @@
41685
41987
  dockingPoint = intersection.bendpoint ? waypoints[intersection.index] : mid;
41686
41988
 
41687
41989
  // if last waypointBefore is inside shape's bounds, ignore docking point
41688
- if (!isPointInsideBBox(shape, waypointsBefore[waypointsBefore.length-1])) {
41990
+ if (waypointsBefore.length === 1 || !isPointInsideBBox(shape, waypointsBefore[waypointsBefore.length-1])) {
41689
41991
  waypointsBefore.push(copy(dockingPoint));
41690
41992
  }
41691
41993
 
41692
41994
  // if first waypointAfter is inside shape's bounds, ignore docking point
41693
- if (!isPointInsideBBox(shape, waypointsAfter[0])) {
41995
+ if (waypointsAfter.length === 1 || !isPointInsideBBox(shape, waypointsAfter[0])) {
41694
41996
  waypointsAfter.unshift(copy(dockingPoint));
41695
41997
  }
41696
41998
  }
@@ -41915,7 +42217,119 @@
41915
42217
  return is$1(connection, 'bpmn:SequenceFlow');
41916
42218
  }
41917
42219
 
41918
- var HIGH_PRIORITY$9 = 2000;
42220
+ var HIGH_PRIORITY$b = 1500;
42221
+ var HIGHEST_PRIORITY = 2000;
42222
+
42223
+
42224
+ /**
42225
+ * Correct hover targets in certain situations to improve diagram interaction.
42226
+ *
42227
+ * @param {ElementRegistry} elementRegistry
42228
+ * @param {EventBus} eventBus
42229
+ * @param {Canvas} canvas
42230
+ */
42231
+ function FixHoverBehavior(elementRegistry, eventBus, canvas) {
42232
+
42233
+ eventBus.on([
42234
+ 'create.hover',
42235
+ 'create.move',
42236
+ 'create.out',
42237
+ 'create.end',
42238
+ 'shape.move.hover',
42239
+ 'shape.move.move',
42240
+ 'shape.move.out',
42241
+ 'shape.move.end'
42242
+ ], HIGH_PRIORITY$b, function(event) {
42243
+ var context = event.context,
42244
+ shape = context.shape || event.shape,
42245
+ hover = event.hover;
42246
+
42247
+ // ensure elements are not dropped onto a bpmn:Lane but onto
42248
+ // the underlying bpmn:Participant
42249
+ if (is$1(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
42250
+ event.hover = getLanesRoot(hover);
42251
+ event.hoverGfx = elementRegistry.getGraphics(event.hover);
42252
+ }
42253
+
42254
+ var rootElement = canvas.getRootElement();
42255
+
42256
+ // ensure bpmn:Group and label elements are dropped
42257
+ // always onto the root
42258
+ if (hover !== rootElement && (shape.labelTarget || is$1(shape, 'bpmn:Group'))) {
42259
+ event.hover = rootElement;
42260
+ event.hoverGfx = elementRegistry.getGraphics(event.hover);
42261
+ }
42262
+ });
42263
+
42264
+ eventBus.on([
42265
+ 'connect.hover',
42266
+ 'connect.out',
42267
+ 'connect.end',
42268
+ 'connect.cleanup',
42269
+ 'global-connect.hover',
42270
+ 'global-connect.out',
42271
+ 'global-connect.end',
42272
+ 'global-connect.cleanup'
42273
+ ], HIGH_PRIORITY$b, function(event) {
42274
+ var hover = event.hover;
42275
+
42276
+ // ensure connections start/end on bpmn:Participant,
42277
+ // not the underlying bpmn:Lane
42278
+ if (is$1(hover, 'bpmn:Lane')) {
42279
+ event.hover = getLanesRoot(hover) || hover;
42280
+ event.hoverGfx = elementRegistry.getGraphics(event.hover);
42281
+ }
42282
+ });
42283
+
42284
+
42285
+ eventBus.on([
42286
+ 'bendpoint.move.hover'
42287
+ ], HIGH_PRIORITY$b, function(event) {
42288
+ var context = event.context,
42289
+ hover = event.hover,
42290
+ type = context.type;
42291
+
42292
+ // ensure reconnect start/end on bpmn:Participant,
42293
+ // not the underlying bpmn:Lane
42294
+ if (is$1(hover, 'bpmn:Lane') && /reconnect/.test(type)) {
42295
+ event.hover = getLanesRoot(hover) || hover;
42296
+ event.hoverGfx = elementRegistry.getGraphics(event.hover);
42297
+ }
42298
+ });
42299
+
42300
+
42301
+ eventBus.on([
42302
+ 'connect.start'
42303
+ ], HIGH_PRIORITY$b, function(event) {
42304
+ var context = event.context,
42305
+ start = context.start;
42306
+
42307
+ // ensure connect start on bpmn:Participant,
42308
+ // not the underlying bpmn:Lane
42309
+ if (is$1(start, 'bpmn:Lane')) {
42310
+ context.start = getLanesRoot(start) || start;
42311
+ }
42312
+ });
42313
+
42314
+
42315
+ // allow movement of participants from lanes
42316
+ eventBus.on('shape.move.start', HIGHEST_PRIORITY, function(event) {
42317
+ var shape = event.shape;
42318
+
42319
+ if (is$1(shape, 'bpmn:Lane')) {
42320
+ event.shape = getLanesRoot(shape) || shape;
42321
+ }
42322
+ });
42323
+
42324
+ }
42325
+
42326
+ FixHoverBehavior.$inject = [
42327
+ 'elementRegistry',
42328
+ 'eventBus',
42329
+ 'canvas'
42330
+ ];
42331
+
42332
+ var HIGH_PRIORITY$a = 2000;
41919
42333
 
41920
42334
 
41921
42335
  /**
@@ -41923,7 +42337,7 @@
41923
42337
  */
41924
42338
  function GroupBehavior(
41925
42339
  bpmnFactory,
41926
- canvas,
42340
+ bpmnjs,
41927
42341
  elementRegistry,
41928
42342
  eventBus,
41929
42343
  injector,
@@ -41931,18 +42345,6 @@
41931
42345
  ) {
41932
42346
  injector.invoke(CommandInterceptor, this);
41933
42347
 
41934
- /**
41935
- * Gets process definitions
41936
- *
41937
- * @return {ModdleElement} definitions
41938
- */
41939
- function getDefinitions() {
41940
- var rootElement = canvas.getRootElement(),
41941
- businessObject = getBusinessObject(rootElement);
41942
-
41943
- return businessObject.$parent;
41944
- }
41945
-
41946
42348
  /**
41947
42349
  * Removes a referenced category value for a given group shape
41948
42350
  *
@@ -41978,7 +42380,7 @@
41978
42380
  */
41979
42381
  function removeCategory(category) {
41980
42382
 
41981
- var definitions = getDefinitions();
42383
+ var definitions = bpmnjs.getDefinitions();
41982
42384
 
41983
42385
  remove(definitions.get('rootElements'), category);
41984
42386
  }
@@ -42043,7 +42445,7 @@
42043
42445
 
42044
42446
  var businessObject = getBusinessObject(shape),
42045
42447
  categoryValueRef = businessObject.categoryValueRef,
42046
- definitions = getDefinitions(),
42448
+ definitions = bpmnjs.getDefinitions(),
42047
42449
  category = categoryValueRef ? categoryValueRef.$parent : null;
42048
42450
 
42049
42451
  add(category.get('categoryValue'), categoryValueRef);
@@ -42061,7 +42463,7 @@
42061
42463
 
42062
42464
  if (is$1(businessObject, 'bpmn:Group') && !businessObject.categoryValueRef) {
42063
42465
 
42064
- var definitions = getDefinitions(),
42466
+ var definitions = bpmnjs.getDefinitions(),
42065
42467
  categoryValue = createCategoryValue(definitions, bpmnFactory);
42066
42468
 
42067
42469
  // link the reference to the Group
@@ -42084,12 +42486,12 @@
42084
42486
  });
42085
42487
 
42086
42488
  // copy bpmn:CategoryValue when copying element
42087
- eventBus.on('moddleCopy.canCopyProperty', HIGH_PRIORITY$9, function(context) {
42489
+ eventBus.on('moddleCopy.canCopyProperty', HIGH_PRIORITY$a, function(context) {
42088
42490
  var property = context.property,
42089
42491
  categoryValue;
42090
42492
 
42091
42493
  if (is$1(property, 'bpmn:CategoryValue')) {
42092
- categoryValue = createCategoryValue(getDefinitions(), bpmnFactory);
42494
+ categoryValue = createCategoryValue(bpmnjs.getDefinitions(), bpmnFactory);
42093
42495
 
42094
42496
  // return copy of category
42095
42497
  return moddleCopy.copyElement(property, categoryValue);
@@ -42100,7 +42502,7 @@
42100
42502
 
42101
42503
  GroupBehavior.$inject = [
42102
42504
  'bpmnFactory',
42103
- 'canvas',
42505
+ 'bpmnjs',
42104
42506
  'elementRegistry',
42105
42507
  'eventBus',
42106
42508
  'injector',
@@ -43509,6 +43911,151 @@
43509
43911
  'translate'
43510
43912
  ];
43511
43913
 
43914
+ /**
43915
+ * BPMN specific behavior ensuring that bpmndi:Label's dc:Bounds are removed
43916
+ * when shape is resized.
43917
+ */
43918
+ function RemoveEmbeddedLabelBoundsBehavior(eventBus, modeling) {
43919
+ CommandInterceptor.call(this, eventBus);
43920
+
43921
+ this.preExecute('shape.resize', function(context) {
43922
+ var shape = context.shape;
43923
+
43924
+ var di = getDi(shape),
43925
+ label = di && di.get('label'),
43926
+ bounds = label && label.get('bounds');
43927
+
43928
+ if (bounds) {
43929
+ modeling.updateModdleProperties(shape, label, {
43930
+ bounds: undefined
43931
+ });
43932
+ }
43933
+ }, true);
43934
+ }
43935
+
43936
+ inherits$1(RemoveEmbeddedLabelBoundsBehavior, CommandInterceptor);
43937
+
43938
+ RemoveEmbeddedLabelBoundsBehavior.$inject = [
43939
+ 'eventBus',
43940
+ 'modeling'
43941
+ ];
43942
+
43943
+ function RemoveElementBehavior(eventBus, bpmnRules, modeling) {
43944
+
43945
+ CommandInterceptor.call(this, eventBus);
43946
+
43947
+ /**
43948
+ * Combine sequence flows when deleting an element
43949
+ * if there is one incoming and one outgoing
43950
+ * sequence flow
43951
+ */
43952
+ this.preExecute('shape.delete', function(e) {
43953
+
43954
+ var shape = e.context.shape;
43955
+
43956
+ // only handle [a] -> [shape] -> [b] patterns
43957
+ if (shape.incoming.length !== 1 || shape.outgoing.length !== 1) {
43958
+ return;
43959
+ }
43960
+
43961
+ var inConnection = shape.incoming[0],
43962
+ outConnection = shape.outgoing[0];
43963
+
43964
+ // only handle sequence flows
43965
+ if (!is$1(inConnection, 'bpmn:SequenceFlow') || !is$1(outConnection, 'bpmn:SequenceFlow')) {
43966
+ return;
43967
+ }
43968
+
43969
+ if (bpmnRules.canConnect(inConnection.source, outConnection.target, inConnection)) {
43970
+
43971
+ // compute new, combined waypoints
43972
+ var newWaypoints = getNewWaypoints(inConnection.waypoints, outConnection.waypoints);
43973
+
43974
+ modeling.reconnectEnd(inConnection, outConnection.target, newWaypoints);
43975
+ }
43976
+ });
43977
+
43978
+ }
43979
+
43980
+ inherits$1(RemoveElementBehavior, CommandInterceptor);
43981
+
43982
+ RemoveElementBehavior.$inject = [
43983
+ 'eventBus',
43984
+ 'bpmnRules',
43985
+ 'modeling'
43986
+ ];
43987
+
43988
+
43989
+ // helpers //////////////////////
43990
+
43991
+ function getDocking$1(point) {
43992
+ return point.original || point;
43993
+ }
43994
+
43995
+
43996
+ function getNewWaypoints(inWaypoints, outWaypoints) {
43997
+
43998
+ var intersection = lineIntersect(
43999
+ getDocking$1(inWaypoints[inWaypoints.length - 2]),
44000
+ getDocking$1(inWaypoints[inWaypoints.length - 1]),
44001
+ getDocking$1(outWaypoints[1]),
44002
+ getDocking$1(outWaypoints[0]));
44003
+
44004
+ if (intersection) {
44005
+ return [].concat(
44006
+ inWaypoints.slice(0, inWaypoints.length - 1),
44007
+ [ intersection ],
44008
+ outWaypoints.slice(1));
44009
+ } else {
44010
+ return [
44011
+ getDocking$1(inWaypoints[0]),
44012
+ getDocking$1(outWaypoints[outWaypoints.length - 1])
44013
+ ];
44014
+ }
44015
+ }
44016
+
44017
+ /**
44018
+ * BPMN specific remove behavior
44019
+ */
44020
+ function RemoveParticipantBehavior(eventBus, modeling) {
44021
+
44022
+ CommandInterceptor.call(this, eventBus);
44023
+
44024
+
44025
+ /**
44026
+ * morph collaboration diagram into process diagram
44027
+ * after the last participant has been removed
44028
+ */
44029
+
44030
+ this.preExecute('shape.delete', function(context) {
44031
+
44032
+ var shape = context.shape,
44033
+ parent = shape.parent;
44034
+
44035
+ // activate the behavior if the shape to be removed
44036
+ // is a participant
44037
+ if (is$1(shape, 'bpmn:Participant')) {
44038
+ context.collaborationRoot = parent;
44039
+ }
44040
+ }, true);
44041
+
44042
+ this.postExecute('shape.delete', function(context) {
44043
+
44044
+ var collaborationRoot = context.collaborationRoot;
44045
+
44046
+ if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
44047
+
44048
+ // replace empty collaboration with process diagram
44049
+ modeling.makeProcess();
44050
+ }
44051
+ }, true);
44052
+
44053
+ }
44054
+
44055
+ RemoveParticipantBehavior.$inject = [ 'eventBus', 'modeling' ];
44056
+
44057
+ inherits$1(RemoveParticipantBehavior, CommandInterceptor);
44058
+
43512
44059
  function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules, injector) {
43513
44060
 
43514
44061
  CommandInterceptor.call(this, eventBus);
@@ -43681,48 +44228,6 @@
43681
44228
  'injector'
43682
44229
  ];
43683
44230
 
43684
- /**
43685
- * BPMN specific remove behavior
43686
- */
43687
- function RemoveParticipantBehavior(eventBus, modeling) {
43688
-
43689
- CommandInterceptor.call(this, eventBus);
43690
-
43691
-
43692
- /**
43693
- * morph collaboration diagram into process diagram
43694
- * after the last participant has been removed
43695
- */
43696
-
43697
- this.preExecute('shape.delete', function(context) {
43698
-
43699
- var shape = context.shape,
43700
- parent = shape.parent;
43701
-
43702
- // activate the behavior if the shape to be removed
43703
- // is a participant
43704
- if (is$1(shape, 'bpmn:Participant')) {
43705
- context.collaborationRoot = parent;
43706
- }
43707
- }, true);
43708
-
43709
- this.postExecute('shape.delete', function(context) {
43710
-
43711
- var collaborationRoot = context.collaborationRoot;
43712
-
43713
- if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
43714
-
43715
- // replace empty collaboration with process diagram
43716
- modeling.makeProcess();
43717
- }
43718
- }, true);
43719
-
43720
- }
43721
-
43722
- RemoveParticipantBehavior.$inject = [ 'eventBus', 'modeling' ];
43723
-
43724
- inherits$1(RemoveParticipantBehavior, CommandInterceptor);
43725
-
43726
44231
  /**
43727
44232
  * BPMN-specific replace behavior.
43728
44233
  */
@@ -43840,7 +44345,7 @@
43840
44345
  'selection'
43841
44346
  ];
43842
44347
 
43843
- var HIGH_PRIORITY$8 = 1500;
44348
+ var HIGH_PRIORITY$9 = 1500;
43844
44349
 
43845
44350
  var LANE_MIN_DIMENSIONS = { width: 300, height: 60 };
43846
44351
 
@@ -43856,7 +44361,7 @@
43856
44361
  * @param {EventBus} eventBus
43857
44362
  */
43858
44363
  function ResizeBehavior(eventBus) {
43859
- eventBus.on('resize.start', HIGH_PRIORITY$8, function(event) {
44364
+ eventBus.on('resize.start', HIGH_PRIORITY$9, function(event) {
43860
44365
  var context = event.context,
43861
44366
  shape = context.shape,
43862
44367
  direction = context.direction,
@@ -44056,78 +44561,165 @@
44056
44561
  'modeling'
44057
44562
  ];
44058
44563
 
44059
- function RemoveElementBehavior(eventBus, bpmnRules, modeling) {
44060
-
44061
- CommandInterceptor.call(this, eventBus);
44062
-
44063
- /**
44064
- * Combine sequence flows when deleting an element
44065
- * if there is one incoming and one outgoing
44066
- * sequence flow
44067
- */
44068
- this.preExecute('shape.delete', function(e) {
44069
-
44070
- var shape = e.context.shape;
44071
-
44072
- // only handle [a] -> [shape] -> [b] patterns
44073
- if (shape.incoming.length !== 1 || shape.outgoing.length !== 1) {
44074
- return;
44075
- }
44076
-
44077
- var inConnection = shape.incoming[0],
44078
- outConnection = shape.outgoing[0];
44079
-
44080
- // only handle sequence flows
44081
- if (!is$1(inConnection, 'bpmn:SequenceFlow') || !is$1(outConnection, 'bpmn:SequenceFlow')) {
44082
- return;
44083
- }
44084
-
44085
- if (bpmnRules.canConnect(inConnection.source, outConnection.target, inConnection)) {
44086
-
44087
- // compute new, combined waypoints
44088
- var newWaypoints = getNewWaypoints(inConnection.waypoints, outConnection.waypoints);
44089
-
44090
- modeling.reconnectEnd(inConnection, outConnection.target, newWaypoints);
44091
- }
44092
- });
44093
-
44094
- }
44095
-
44096
- inherits$1(RemoveElementBehavior, CommandInterceptor);
44097
-
44098
- RemoveElementBehavior.$inject = [
44099
- 'eventBus',
44100
- 'bpmnRules',
44101
- 'modeling'
44102
- ];
44103
-
44104
-
44105
- // helpers //////////////////////
44106
-
44107
- function getDocking$1(point) {
44108
- return point.original || point;
44109
- }
44110
-
44111
-
44112
- function getNewWaypoints(inWaypoints, outWaypoints) {
44113
-
44114
- var intersection = lineIntersect(
44115
- getDocking$1(inWaypoints[inWaypoints.length - 2]),
44116
- getDocking$1(inWaypoints[inWaypoints.length - 1]),
44117
- getDocking$1(outWaypoints[1]),
44118
- getDocking$1(outWaypoints[0]));
44119
-
44120
- if (intersection) {
44121
- return [].concat(
44122
- inWaypoints.slice(0, inWaypoints.length - 1),
44123
- [ intersection ],
44124
- outWaypoints.slice(1));
44125
- } else {
44126
- return [
44127
- getDocking$1(inWaypoints[0]),
44128
- getDocking$1(outWaypoints[outWaypoints.length - 1])
44129
- ];
44130
- }
44564
+ var LOW_PRIORITY$a = 500;
44565
+
44566
+
44567
+ /**
44568
+ * Add referenced root elements (error, escalation, message, signal) if they don't exist.
44569
+ * Copy referenced root elements on copy & paste.
44570
+ */
44571
+ function RootElementReferenceBehavior(
44572
+ bpmnjs, eventBus, injector, moddleCopy, bpmnFactory
44573
+ ) {
44574
+ injector.invoke(CommandInterceptor, this);
44575
+
44576
+ function canHaveRootElementReference(element) {
44577
+ return isAny(element, [ 'bpmn:ReceiveTask', 'bpmn:SendTask' ]) ||
44578
+ hasAnyEventDefinition(element, [
44579
+ 'bpmn:ErrorEventDefinition',
44580
+ 'bpmn:EscalationEventDefinition',
44581
+ 'bpmn:MessageEventDefinition',
44582
+ 'bpmn:SignalEventDefinition'
44583
+ ]);
44584
+ }
44585
+
44586
+ function hasRootElement(rootElement) {
44587
+ var definitions = bpmnjs.getDefinitions(),
44588
+ rootElements = definitions.get('rootElements');
44589
+
44590
+ return !!find(rootElements, matchPattern({ id: rootElement.id }));
44591
+ }
44592
+
44593
+ function getRootElementReferencePropertyName(eventDefinition) {
44594
+ if (is$1(eventDefinition, 'bpmn:ErrorEventDefinition')) {
44595
+ return 'errorRef';
44596
+ } else if (is$1(eventDefinition, 'bpmn:EscalationEventDefinition')) {
44597
+ return 'escalationRef';
44598
+ } else if (is$1(eventDefinition, 'bpmn:MessageEventDefinition')) {
44599
+ return 'messageRef';
44600
+ } else if (is$1(eventDefinition, 'bpmn:SignalEventDefinition')) {
44601
+ return 'signalRef';
44602
+ }
44603
+ }
44604
+
44605
+ function getRootElement(businessObject) {
44606
+ if (isAny(businessObject, [ 'bpmn:ReceiveTask', 'bpmn:SendTask' ])) {
44607
+ return businessObject.get('messageRef');
44608
+ }
44609
+
44610
+ var eventDefinitions = businessObject.get('eventDefinitions'),
44611
+ eventDefinition = eventDefinitions[ 0 ];
44612
+
44613
+ return eventDefinition.get(getRootElementReferencePropertyName(eventDefinition));
44614
+ }
44615
+
44616
+ function setRootElement(businessObject, rootElement) {
44617
+ if (isAny(businessObject, [ 'bpmn:ReceiveTask', 'bpmn:SendTask' ])) {
44618
+ return businessObject.set('messageRef', rootElement);
44619
+ }
44620
+
44621
+ var eventDefinitions = businessObject.get('eventDefinitions'),
44622
+ eventDefinition = eventDefinitions[ 0 ];
44623
+
44624
+ return eventDefinition.set(getRootElementReferencePropertyName(eventDefinition), rootElement);
44625
+ }
44626
+
44627
+ // create shape
44628
+ this.executed('shape.create', function(context) {
44629
+ var shape = context.shape;
44630
+
44631
+ if (!canHaveRootElementReference(shape)) {
44632
+ return;
44633
+ }
44634
+
44635
+ var businessObject = getBusinessObject(shape),
44636
+ rootElement = getRootElement(businessObject),
44637
+ rootElements;
44638
+
44639
+ if (rootElement && !hasRootElement(rootElement)) {
44640
+ rootElements = bpmnjs.getDefinitions().get('rootElements');
44641
+
44642
+ // add root element
44643
+ add(rootElements, rootElement);
44644
+
44645
+ context.addedRootElement = rootElement;
44646
+ }
44647
+ }, true);
44648
+
44649
+ this.reverted('shape.create', function(context) {
44650
+ var addedRootElement = context.addedRootElement;
44651
+
44652
+ if (!addedRootElement) {
44653
+ return;
44654
+ }
44655
+
44656
+ var rootElements = bpmnjs.getDefinitions().get('rootElements');
44657
+
44658
+ // remove root element
44659
+ remove(rootElements, addedRootElement);
44660
+ }, true);
44661
+
44662
+ eventBus.on('copyPaste.copyElement', function(context) {
44663
+ var descriptor = context.descriptor,
44664
+ element = context.element;
44665
+
44666
+ if (!canHaveRootElementReference(element)) {
44667
+ return;
44668
+ }
44669
+
44670
+ var businessObject = getBusinessObject(element),
44671
+ rootElement = getRootElement(businessObject);
44672
+
44673
+ if (rootElement) {
44674
+ descriptor.referencedRootElement = rootElement;
44675
+ }
44676
+ });
44677
+
44678
+ eventBus.on('copyPaste.pasteElement', LOW_PRIORITY$a, function(context) {
44679
+ var descriptor = context.descriptor,
44680
+ businessObject = descriptor.businessObject;
44681
+
44682
+ if (!canHaveRootElementReference(businessObject)) {
44683
+ return;
44684
+ }
44685
+
44686
+ var referencedRootElement = descriptor.referencedRootElement;
44687
+
44688
+ if (!referencedRootElement) {
44689
+ return;
44690
+ }
44691
+
44692
+ if (!hasRootElement(referencedRootElement)) {
44693
+ referencedRootElement = moddleCopy.copyElement(
44694
+ referencedRootElement,
44695
+ bpmnFactory.create(referencedRootElement.$type)
44696
+ );
44697
+ }
44698
+
44699
+ setRootElement(businessObject, referencedRootElement);
44700
+ });
44701
+ }
44702
+
44703
+ RootElementReferenceBehavior.$inject = [
44704
+ 'bpmnjs',
44705
+ 'eventBus',
44706
+ 'injector',
44707
+ 'moddleCopy',
44708
+ 'bpmnFactory'
44709
+ ];
44710
+
44711
+ inherits$1(RootElementReferenceBehavior, CommandInterceptor);
44712
+
44713
+ // helpers //////////
44714
+
44715
+ function hasAnyEventDefinition(element, types) {
44716
+ if (!isArray$2(types)) {
44717
+ types = [ types ];
44718
+ }
44719
+
44720
+ return some(types, function(type) {
44721
+ return hasEventDefinition$2(element, type);
44722
+ });
44131
44723
  }
44132
44724
 
44133
44725
  var max$1 = Math.max;
@@ -44240,6 +44832,547 @@
44240
44832
  }
44241
44833
  }
44242
44834
 
44835
+ var LOW_PRIORITY$9 = 400;
44836
+ var HIGH_PRIORITY$8 = 600;
44837
+
44838
+ var DEFAULT_POSITION = {
44839
+ x: 180,
44840
+ y: 160
44841
+ };
44842
+
44843
+
44844
+ /**
44845
+ * Creates bpmndi:BPMNPlane elements and canvas planes when collapsed subprocesses are created.
44846
+ *
44847
+ *
44848
+ * @param {Canvas} canvas
44849
+ * @param {EventBus} eventBus
44850
+ * @param {Modeling} modeling
44851
+ * @param {ElementFactory} elementFactory
44852
+ * @param {BpmnFactory} bpmnFactory
44853
+ * @param {Bpmnjs} bpmnjs
44854
+ * @param {ElementRegistry} elementRegistry
44855
+ */
44856
+ function SubProcessPlaneBehavior(
44857
+ canvas, eventBus, modeling,
44858
+ elementFactory, bpmnFactory, bpmnjs, elementRegistry) {
44859
+
44860
+ CommandInterceptor.call(this, eventBus);
44861
+
44862
+ this._canvas = canvas;
44863
+ this._eventBus = eventBus;
44864
+ this._modeling = modeling;
44865
+ this._elementFactory = elementFactory;
44866
+ this._bpmnFactory = bpmnFactory;
44867
+ this._bpmnjs = bpmnjs;
44868
+ this._elementRegistry = elementRegistry;
44869
+
44870
+ var self = this;
44871
+
44872
+ function isCollapsedSubProcess(element) {
44873
+ return is$1(element, 'bpmn:SubProcess') && !isExpanded(element);
44874
+ }
44875
+
44876
+ function createRoot(context) {
44877
+ var shape = context.shape,
44878
+ rootElement = context.newRootElement;
44879
+
44880
+ var businessObject = getBusinessObject(shape);
44881
+
44882
+ rootElement = self._addDiagram(rootElement || businessObject);
44883
+
44884
+ context.newRootElement = canvas.addRootElement(rootElement);
44885
+ }
44886
+
44887
+ function removeRoot(context) {
44888
+ var shape = context.shape;
44889
+
44890
+ var businessObject = getBusinessObject(shape);
44891
+ self._removeDiagram(businessObject);
44892
+
44893
+ var rootElement = context.newRootElement = elementRegistry.get(getPlaneIdFromShape(businessObject));
44894
+
44895
+ canvas.removeRootElement(rootElement);
44896
+ }
44897
+
44898
+ // add plane elements for newly created sub-processes
44899
+ // this ensures we can actually drill down into the element
44900
+ this.executed('shape.create', function(context) {
44901
+ var shape = context.shape;
44902
+ if (!isCollapsedSubProcess(shape)) {
44903
+ return;
44904
+ }
44905
+
44906
+ createRoot(context);
44907
+ }, true);
44908
+
44909
+
44910
+ this.postExecuted('shape.create', function(context) {
44911
+ var shape = context.shape,
44912
+ rootElement = context.newRootElement;
44913
+
44914
+ if (!rootElement || !shape.children) {
44915
+ return;
44916
+ }
44917
+
44918
+ self._showRecursively(shape.children);
44919
+
44920
+ self._moveChildrenToShape(shape, rootElement);
44921
+ }, true);
44922
+
44923
+
44924
+ this.reverted('shape.create', function(context) {
44925
+ var shape = context.shape;
44926
+ if (!isCollapsedSubProcess(shape)) {
44927
+ return;
44928
+ }
44929
+
44930
+ removeRoot(context);
44931
+ }, true);
44932
+
44933
+
44934
+ this.preExecuted('shape.delete', function(context) {
44935
+ var shape = context.shape;
44936
+ if (!isCollapsedSubProcess(shape)) {
44937
+ return;
44938
+ }
44939
+
44940
+ var attachedRoot = elementRegistry.get(getPlaneIdFromShape(shape));
44941
+
44942
+ if (!attachedRoot) {
44943
+ return;
44944
+ }
44945
+
44946
+ modeling.removeElements(attachedRoot.children.slice());
44947
+ }, true);
44948
+
44949
+
44950
+ this.executed('shape.delete', function(context) {
44951
+ var shape = context.shape;
44952
+ if (!isCollapsedSubProcess(shape)) {
44953
+ return;
44954
+ }
44955
+ removeRoot(context);
44956
+ }, true);
44957
+
44958
+
44959
+ this.reverted('shape.delete', function(context) {
44960
+ var shape = context.shape;
44961
+ if (!isCollapsedSubProcess(shape)) {
44962
+ return;
44963
+ }
44964
+
44965
+ createRoot(context);
44966
+ }, true);
44967
+
44968
+
44969
+ this.preExecuted('shape.replace', function(context) {
44970
+ var oldShape = context.oldShape;
44971
+ var newShape = context.newShape;
44972
+
44973
+ if (!isCollapsedSubProcess(oldShape) || !isCollapsedSubProcess(newShape)) {
44974
+ return;
44975
+ }
44976
+
44977
+ // old plane could have content,
44978
+ // we remove it so it is not recursively deleted from 'shape.delete'
44979
+ context.oldRoot = canvas.removeRootElement(getPlaneIdFromShape(oldShape));
44980
+ }, true);
44981
+
44982
+
44983
+ this.postExecuted('shape.replace', function(context) {
44984
+ var newShape = context.newShape,
44985
+ source = context.oldRoot,
44986
+ target = canvas.findRoot(getPlaneIdFromShape(newShape));
44987
+
44988
+ if (!source || !target) {
44989
+ return;
44990
+ }
44991
+ var elements = source.children;
44992
+
44993
+ modeling.moveElements(elements, { x: 0, y: 0 }, target);
44994
+ }, true);
44995
+
44996
+
44997
+ // rename primary elements when the secondary element changes
44998
+ // this ensures rootElement.id = element.id + '_plane'
44999
+ this.executed('element.updateProperties', function(context) {
45000
+ var shape = context.element;
45001
+
45002
+ if (!is$1(shape, 'bpmn:SubProcess')) {
45003
+ return;
45004
+ }
45005
+
45006
+ var properties = context.properties;
45007
+ var oldProperties = context.oldProperties;
45008
+
45009
+ var oldId = oldProperties.id,
45010
+ newId = properties.id;
45011
+
45012
+ if (oldId === newId) {
45013
+ return;
45014
+ }
45015
+
45016
+ if (isPlane(shape)) {
45017
+ elementRegistry.updateId(shape, toPlaneId(newId));
45018
+ elementRegistry.updateId(oldId, newId);
45019
+
45020
+ return;
45021
+ }
45022
+
45023
+ var planeElement = elementRegistry.get(toPlaneId(oldId));
45024
+
45025
+ if (!planeElement) {
45026
+ return;
45027
+ }
45028
+
45029
+ elementRegistry.updateId(toPlaneId(oldId), toPlaneId(newId));
45030
+ }, true);
45031
+
45032
+
45033
+ this.reverted('element.updateProperties', function(context) {
45034
+ var shape = context.element;
45035
+
45036
+ if (!is$1(shape, 'bpmn:SubProcess')) {
45037
+ return;
45038
+ }
45039
+
45040
+ var properties = context.properties;
45041
+ var oldProperties = context.oldProperties;
45042
+
45043
+ var oldId = oldProperties.id,
45044
+ newId = properties.id;
45045
+
45046
+ if (oldId === newId) {
45047
+ return;
45048
+ }
45049
+
45050
+ if (isPlane(shape)) {
45051
+ elementRegistry.updateId(shape, toPlaneId(oldId));
45052
+ elementRegistry.updateId(newId, oldId);
45053
+
45054
+ return;
45055
+ }
45056
+
45057
+ var planeElement = elementRegistry.get(toPlaneId(newId));
45058
+
45059
+ if (!planeElement) {
45060
+ return;
45061
+ }
45062
+
45063
+ elementRegistry.updateId(planeElement, toPlaneId(oldId));
45064
+ }, true);
45065
+
45066
+ // re-throw element.changed to re-render primary shape if associated plane has
45067
+ // changed (e.g. bpmn:name property has changed)
45068
+ eventBus.on('element.changed', function(context) {
45069
+ var element = context.element;
45070
+
45071
+ if (!isPlane(element)) {
45072
+ return;
45073
+ }
45074
+
45075
+ var plane = element;
45076
+
45077
+ var primaryShape = elementRegistry.get(getShapeIdFromPlane(plane));
45078
+
45079
+ // do not re-throw if no associated primary shape (e.g. bpmn:Process)
45080
+ if (!primaryShape || primaryShape === plane) {
45081
+ return;
45082
+ }
45083
+
45084
+ eventBus.fire('element.changed', { element: primaryShape });
45085
+ });
45086
+
45087
+
45088
+ // create/remove plane for the subprocess
45089
+ this.executed('shape.toggleCollapse', LOW_PRIORITY$9, function(context) {
45090
+ var shape = context.shape;
45091
+
45092
+ if (!is$1(shape, 'bpmn:SubProcess')) {
45093
+ return;
45094
+ }
45095
+
45096
+ if (!isExpanded(shape)) {
45097
+ createRoot(context);
45098
+ self._showRecursively(shape.children);
45099
+ } else {
45100
+ removeRoot(context);
45101
+ }
45102
+
45103
+ }, true);
45104
+
45105
+
45106
+ // create/remove plane for the subprocess
45107
+ this.reverted('shape.toggleCollapse', LOW_PRIORITY$9, function(context) {
45108
+ var shape = context.shape;
45109
+
45110
+ if (!is$1(shape, 'bpmn:SubProcess')) {
45111
+ return;
45112
+ }
45113
+
45114
+ if (!isExpanded(shape)) {
45115
+ createRoot(context);
45116
+ self._showRecursively(shape.children);
45117
+ } else {
45118
+ removeRoot(context);
45119
+ }
45120
+
45121
+ }, true);
45122
+
45123
+ // move elements between planes
45124
+ this.postExecuted('shape.toggleCollapse', HIGH_PRIORITY$8, function(context) {
45125
+ var shape = context.shape;
45126
+
45127
+ if (!is$1(shape, 'bpmn:SubProcess')) {
45128
+ return;
45129
+ }
45130
+
45131
+ var rootElement = context.newRootElement;
45132
+
45133
+ if (!rootElement) {
45134
+ return;
45135
+ }
45136
+
45137
+ if (!isExpanded(shape)) {
45138
+
45139
+ // collapsed
45140
+ self._moveChildrenToShape(shape, rootElement);
45141
+
45142
+ } else {
45143
+ self._moveChildrenToShape(rootElement, shape);
45144
+ }
45145
+ }, true);
45146
+
45147
+
45148
+ // copy-paste ///////////
45149
+
45150
+ // add elements in plane to tree
45151
+ eventBus.on('copyPaste.createTree', function(context) {
45152
+ var element = context.element,
45153
+ children = context.children;
45154
+
45155
+ if (!isCollapsedSubProcess(element)) {
45156
+ return;
45157
+ }
45158
+
45159
+ var id = getPlaneIdFromShape(element);
45160
+ var parent = elementRegistry.get(id);
45161
+
45162
+ if (parent) {
45163
+
45164
+ // do not copy invisible root element
45165
+ children.push.apply(children, parent.children);
45166
+ }
45167
+ });
45168
+
45169
+ // set plane children as direct children of collapsed shape
45170
+ eventBus.on('copyPaste.copyElement', function(context) {
45171
+ var descriptor = context.descriptor,
45172
+ element = context.element,
45173
+ elements = context.elements;
45174
+
45175
+ var parent = element.parent;
45176
+
45177
+ var isPlane = is$1(getDi(parent), 'bpmndi:BPMNPlane');
45178
+ if (!isPlane) {
45179
+ return;
45180
+ }
45181
+
45182
+ var parentId = getShapeIdFromPlane(parent);
45183
+
45184
+ var referencedShape = find(elements, function(element) {
45185
+ return element.id === parentId;
45186
+ });
45187
+
45188
+ if (!referencedShape) {
45189
+ return;
45190
+ }
45191
+
45192
+ descriptor.parent = referencedShape.id;
45193
+ });
45194
+
45195
+ // hide children during pasting
45196
+ eventBus.on('copyPaste.pasteElement', function(context) {
45197
+ var descriptor = context.descriptor;
45198
+
45199
+ if (!descriptor.parent) {
45200
+ return;
45201
+ }
45202
+
45203
+ if (isCollapsedSubProcess(descriptor.parent) || descriptor.parent.hidden) {
45204
+ descriptor.hidden = true;
45205
+ }
45206
+ });
45207
+
45208
+ }
45209
+
45210
+ inherits$1(SubProcessPlaneBehavior, CommandInterceptor);
45211
+
45212
+ /**
45213
+ * Moves the child elements from source to target.
45214
+ *
45215
+ * If the target is a plane, the children are moved to the top left corner.
45216
+ * Otherwise, the center of the target is used.
45217
+ *
45218
+ * @param {Object|djs.model.Base} source
45219
+ * @param {Object|djs.model.Base} target
45220
+ */
45221
+ SubProcessPlaneBehavior.prototype._moveChildrenToShape = function(source, target) {
45222
+ var modeling = this._modeling;
45223
+
45224
+ var children = source.children;
45225
+ var offset;
45226
+
45227
+ if (!children) {
45228
+ return;
45229
+ }
45230
+
45231
+ // only change plane if there are no visible children, but don't move them
45232
+ var visibleChildren = children.filter(function(child) {
45233
+ return !child.hidden;
45234
+ });
45235
+
45236
+ if (!visibleChildren.length) {
45237
+ modeling.moveElements(children, { x: 0, y: 0 }, target, { autoResize: false });
45238
+ return;
45239
+ }
45240
+
45241
+ var childrenBounds = getBBox(visibleChildren);
45242
+
45243
+ // target is a plane
45244
+ if (!target.x) {
45245
+ offset = {
45246
+ x: DEFAULT_POSITION.x - childrenBounds.x,
45247
+ y: DEFAULT_POSITION.y - childrenBounds.y
45248
+ };
45249
+ }
45250
+
45251
+ // source is a plane
45252
+ else {
45253
+
45254
+ // move relative to the center of the shape
45255
+ var targetMid = getMid(target);
45256
+ var childrenMid = getMid(childrenBounds);
45257
+
45258
+ offset = {
45259
+ x: targetMid.x - childrenMid.x,
45260
+ y: targetMid.y - childrenMid.y
45261
+ };
45262
+ }
45263
+
45264
+ modeling.moveElements(children, offset, target, { autoResize: false });
45265
+ };
45266
+
45267
+ /**
45268
+ * Sets `hidden` property on all children of the given shape.
45269
+ *
45270
+ * @param {Array} elements
45271
+ * @param {Boolean} [hidden]
45272
+ * @returns {Array} all child elements
45273
+ */
45274
+ SubProcessPlaneBehavior.prototype._showRecursively = function(elements, hidden) {
45275
+ var self = this;
45276
+
45277
+ var result = [];
45278
+ elements.forEach(function(element) {
45279
+ element.hidden = !!hidden;
45280
+
45281
+ result = result.concat(element);
45282
+
45283
+ if (element.children) {
45284
+ result = result.concat(
45285
+ self._showRecursively(element.children, element.collapsed || hidden)
45286
+ );
45287
+ }
45288
+ });
45289
+
45290
+ return result;
45291
+ };
45292
+
45293
+ /**
45294
+ * Adds a given rootElement to the bpmnDi diagrams.
45295
+ *
45296
+ * @param {Object} rootElement
45297
+ * @returns {Object} planeElement
45298
+ */
45299
+ SubProcessPlaneBehavior.prototype._addDiagram = function(planeElement) {
45300
+ var bpmnjs = this._bpmnjs;
45301
+ var diagrams = bpmnjs.getDefinitions().diagrams;
45302
+
45303
+ if (!planeElement.businessObject) {
45304
+ planeElement = this._createNewDiagram(planeElement);
45305
+ }
45306
+
45307
+ diagrams.push(planeElement.di.$parent);
45308
+
45309
+ return planeElement;
45310
+ };
45311
+
45312
+
45313
+ /**
45314
+ * Creates a new plane element for the given sub process.
45315
+ *
45316
+ * @param {Object} bpmnElement
45317
+ *
45318
+ * @return {Object} new diagram element
45319
+ */
45320
+ SubProcessPlaneBehavior.prototype._createNewDiagram = function(bpmnElement) {
45321
+ var bpmnFactory = this._bpmnFactory;
45322
+ var elementFactory = this._elementFactory;
45323
+
45324
+ var diPlane = bpmnFactory.create('bpmndi:BPMNPlane', {
45325
+ bpmnElement: bpmnElement
45326
+ });
45327
+ var diDiagram = bpmnFactory.create('bpmndi:BPMNDiagram', {
45328
+ plane: diPlane
45329
+ });
45330
+ diPlane.$parent = diDiagram;
45331
+
45332
+ // add a virtual element (not being drawn),
45333
+ // a copy cat of our BpmnImporter code
45334
+ var planeElement = elementFactory.createRoot({
45335
+ id: getPlaneIdFromShape(bpmnElement),
45336
+ type: bpmnElement.$type,
45337
+ di: diPlane,
45338
+ businessObject: bpmnElement,
45339
+ collapsed: true
45340
+ });
45341
+
45342
+ return planeElement;
45343
+ };
45344
+
45345
+ /**
45346
+ * Removes the diagram for a given root element
45347
+ *
45348
+ * @param {Object} rootElement
45349
+ * @returns {Object} removed bpmndi:BPMNDiagram
45350
+ */
45351
+ SubProcessPlaneBehavior.prototype._removeDiagram = function(rootElement) {
45352
+ var bpmnjs = this._bpmnjs;
45353
+
45354
+ var diagrams = bpmnjs.getDefinitions().diagrams;
45355
+
45356
+ var removedDiagram = find(diagrams, function(diagram) {
45357
+ return diagram.plane.bpmnElement.id === rootElement.id;
45358
+ });
45359
+
45360
+ diagrams.splice(diagrams.indexOf(removedDiagram), 1);
45361
+
45362
+ return removedDiagram;
45363
+ };
45364
+
45365
+
45366
+ SubProcessPlaneBehavior.$inject = [
45367
+ 'canvas',
45368
+ 'eventBus',
45369
+ 'modeling',
45370
+ 'elementFactory',
45371
+ 'bpmnFactory',
45372
+ 'bpmnjs',
45373
+ 'elementRegistry'
45374
+ ];
45375
+
44243
45376
  /**
44244
45377
  * Add start event replacing element with expanded sub process.
44245
45378
  *
@@ -44283,6 +45416,64 @@
44283
45416
  };
44284
45417
  }
44285
45418
 
45419
+ function ToggleCollapseConnectionBehaviour(
45420
+ eventBus, modeling
45421
+ ) {
45422
+
45423
+ CommandInterceptor.call(this, eventBus);
45424
+
45425
+ this.postExecuted('shape.toggleCollapse', 1500, function(context) {
45426
+
45427
+ // var shape = context.shape;
45428
+ var shape = context.shape;
45429
+
45430
+ // only change connections when collapsing
45431
+ if (isExpanded(shape)) {
45432
+ return;
45433
+ }
45434
+
45435
+ var allChildren = selfAndAllChildren(shape);
45436
+
45437
+ allChildren.forEach(function(child) {
45438
+
45439
+ // Ensure that the connection array is not modified during iteration
45440
+ var incomingConnections = child.incoming.slice(),
45441
+ outgoingConnections = child.outgoing.slice();
45442
+
45443
+ forEach(incomingConnections, function(c) {
45444
+ handleConnection(c, true);
45445
+ });
45446
+
45447
+ forEach(outgoingConnections, function(c) {
45448
+ handleConnection(c, false);
45449
+ });
45450
+ });
45451
+
45452
+
45453
+ function handleConnection(c, incoming) {
45454
+ if (allChildren.indexOf(c.source) !== -1 && allChildren.indexOf(c.target) !== -1) {
45455
+ return;
45456
+ }
45457
+
45458
+ if (incoming) {
45459
+ modeling.reconnectEnd(c, shape, getMid(shape));
45460
+ } else {
45461
+ modeling.reconnectStart(c, shape, getMid(shape));
45462
+ }
45463
+
45464
+ }
45465
+
45466
+ }, true);
45467
+
45468
+ }
45469
+
45470
+ inherits$1(ToggleCollapseConnectionBehaviour, CommandInterceptor);
45471
+
45472
+ ToggleCollapseConnectionBehaviour.$inject = [
45473
+ 'eventBus',
45474
+ 'modeling',
45475
+ ];
45476
+
44286
45477
  var LOW_PRIORITY$8 = 500;
44287
45478
 
44288
45479
 
@@ -44459,7 +45650,9 @@
44459
45650
  var rootElement = canvas.getRootElement(),
44460
45651
  rootElementBo = rootElement.businessObject;
44461
45652
 
44462
- moddle.ids.unclaim(rootElementBo.id);
45653
+ if (is$1(rootElement, 'bpmn:Collaboration')) {
45654
+ moddle.ids.unclaim(rootElementBo.id);
45655
+ }
44463
45656
  });
44464
45657
  }
44465
45658
 
@@ -44467,6 +45660,54 @@
44467
45660
 
44468
45661
  UnclaimIdBehavior.$inject = [ 'canvas', 'injector', 'moddle', 'modeling' ];
44469
45662
 
45663
+ /**
45664
+ * A behavior that unsets the Default property of
45665
+ * sequence flow source on element delete, if the
45666
+ * removed element is the Gateway or Task's default flow.
45667
+ *
45668
+ * @param {EventBus} eventBus
45669
+ * @param {Modeling} modeling
45670
+ */
45671
+ function DeleteSequenceFlowBehavior(eventBus, modeling) {
45672
+
45673
+ CommandInterceptor.call(this, eventBus);
45674
+
45675
+
45676
+ this.preExecute('connection.delete', function(event) {
45677
+ var context = event.context,
45678
+ connection = context.connection,
45679
+ source = connection.source;
45680
+
45681
+ if (isDefaultFlow(connection, source)) {
45682
+ modeling.updateProperties(source, {
45683
+ 'default': null
45684
+ });
45685
+ }
45686
+ });
45687
+ }
45688
+
45689
+ inherits$1(DeleteSequenceFlowBehavior, CommandInterceptor);
45690
+
45691
+ DeleteSequenceFlowBehavior.$inject = [
45692
+ 'eventBus',
45693
+ 'modeling'
45694
+ ];
45695
+
45696
+
45697
+ // helpers //////////////////////
45698
+
45699
+ function isDefaultFlow(connection, source) {
45700
+
45701
+ if (!is$1(connection, 'bpmn:SequenceFlow')) {
45702
+ return false;
45703
+ }
45704
+
45705
+ var sourceBo = getBusinessObject(source),
45706
+ sequenceFlow = getBusinessObject(connection);
45707
+
45708
+ return sourceBo.get('default') === sequenceFlow;
45709
+ }
45710
+
44470
45711
  var LOW_PRIORITY$7 = 500,
44471
45712
  HIGH_PRIORITY$7 = 5000;
44472
45713
 
@@ -44618,54 +45859,6 @@
44618
45859
  };
44619
45860
  }
44620
45861
 
44621
- /**
44622
- * A behavior that unsets the Default property of
44623
- * sequence flow source on element delete, if the
44624
- * removed element is the Gateway or Task's default flow.
44625
- *
44626
- * @param {EventBus} eventBus
44627
- * @param {Modeling} modeling
44628
- */
44629
- function DeleteSequenceFlowBehavior(eventBus, modeling) {
44630
-
44631
- CommandInterceptor.call(this, eventBus);
44632
-
44633
-
44634
- this.preExecute('connection.delete', function(event) {
44635
- var context = event.context,
44636
- connection = context.connection,
44637
- source = connection.source;
44638
-
44639
- if (isDefaultFlow(connection, source)) {
44640
- modeling.updateProperties(source, {
44641
- 'default': null
44642
- });
44643
- }
44644
- });
44645
- }
44646
-
44647
- inherits$1(DeleteSequenceFlowBehavior, CommandInterceptor);
44648
-
44649
- DeleteSequenceFlowBehavior.$inject = [
44650
- 'eventBus',
44651
- 'modeling'
44652
- ];
44653
-
44654
-
44655
- // helpers //////////////////////
44656
-
44657
- function isDefaultFlow(connection, source) {
44658
-
44659
- if (!is$1(connection, 'bpmn:SequenceFlow')) {
44660
- return false;
44661
- }
44662
-
44663
- var sourceBo = getBusinessObject(source),
44664
- sequenceFlow = getBusinessObject(connection);
44665
-
44666
- return sourceBo.get('default') === sequenceFlow;
44667
- }
44668
-
44669
45862
  var BehaviorModule = {
44670
45863
  __init__: [
44671
45864
  'adaptiveLabelPositioningBehavior',
@@ -44673,17 +45866,16 @@
44673
45866
  'associationBehavior',
44674
45867
  'attachEventBehavior',
44675
45868
  'boundaryEventBehavior',
44676
- 'rootElementReferenceBehavior',
44677
45869
  'createBehavior',
44678
- 'fixHoverBehavior',
44679
45870
  'createDataObjectBehavior',
44680
45871
  'createParticipantBehavior',
44681
- 'dataStoreBehavior',
44682
45872
  'dataInputAssociationBehavior',
45873
+ 'dataStoreBehavior',
44683
45874
  'deleteLaneBehavior',
44684
45875
  'detachEventBehavior',
44685
45876
  'dropOnFlowBehavior',
44686
45877
  'eventBasedGatewayBehavior',
45878
+ 'fixHoverBehavior',
44687
45879
  'groupBehavior',
44688
45880
  'importDockingFix',
44689
45881
  'isHorizontalFix',
@@ -44691,26 +45883,28 @@
44691
45883
  'messageFlowBehavior',
44692
45884
  'modelingFeedback',
44693
45885
  'removeElementBehavior',
45886
+ 'removeEmbeddedLabelBoundsBehavior',
44694
45887
  'removeParticipantBehavior',
44695
45888
  'replaceConnectionBehavior',
44696
45889
  'replaceElementBehaviour',
44697
45890
  'resizeBehavior',
44698
45891
  'resizeLaneBehavior',
44699
- 'toggleElementCollapseBehaviour',
45892
+ 'rootElementReferenceBehavior',
44700
45893
  'spaceToolBehavior',
45894
+ 'subProcessPlaneBehavior',
44701
45895
  'subProcessStartEventBehavior',
45896
+ 'toggleCollapseConnectionBehaviour',
45897
+ 'toggleElementCollapseBehaviour',
44702
45898
  'unclaimIdBehavior',
44703
- 'unsetDefaultFlowBehavior',
44704
- 'updateFlowNodeRefsBehavior'
45899
+ 'updateFlowNodeRefsBehavior',
45900
+ 'unsetDefaultFlowBehavior'
44705
45901
  ],
44706
45902
  adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ],
44707
45903
  appendBehavior: [ 'type', AppendBehavior ],
44708
45904
  associationBehavior: [ 'type', AssociationBehavior ],
44709
45905
  attachEventBehavior: [ 'type', AttachEventBehavior ],
44710
45906
  boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
44711
- rootElementReferenceBehavior: [ 'type', RootElementReferenceBehavior ],
44712
45907
  createBehavior: [ 'type', CreateBehavior ],
44713
- fixHoverBehavior: [ 'type', FixHoverBehavior ],
44714
45908
  createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ],
44715
45909
  createParticipantBehavior: [ 'type', CreateParticipantBehavior ],
44716
45910
  dataInputAssociationBehavior: [ 'type', DataInputAssociationBehavior ],
@@ -44719,24 +45913,29 @@
44719
45913
  detachEventBehavior: [ 'type', DetachEventBehavior ],
44720
45914
  dropOnFlowBehavior: [ 'type', DropOnFlowBehavior ],
44721
45915
  eventBasedGatewayBehavior: [ 'type', EventBasedGatewayBehavior ],
45916
+ fixHoverBehavior: [ 'type', FixHoverBehavior ],
44722
45917
  groupBehavior: [ 'type', GroupBehavior ],
44723
45918
  importDockingFix: [ 'type', ImportDockingFix ],
44724
45919
  isHorizontalFix: [ 'type', IsHorizontalFix ],
44725
45920
  labelBehavior: [ 'type', LabelBehavior ],
44726
45921
  messageFlowBehavior: [ 'type', MessageFlowBehavior ],
44727
45922
  modelingFeedback: [ 'type', ModelingFeedback ],
44728
- replaceConnectionBehavior: [ 'type', ReplaceConnectionBehavior ],
45923
+ removeElementBehavior: [ 'type', RemoveElementBehavior ],
45924
+ removeEmbeddedLabelBoundsBehavior: ['type', RemoveEmbeddedLabelBoundsBehavior ],
44729
45925
  removeParticipantBehavior: [ 'type', RemoveParticipantBehavior ],
45926
+ replaceConnectionBehavior: [ 'type', ReplaceConnectionBehavior ],
44730
45927
  replaceElementBehaviour: [ 'type', ReplaceElementBehaviour ],
44731
45928
  resizeBehavior: [ 'type', ResizeBehavior ],
44732
45929
  resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
44733
- removeElementBehavior: [ 'type', RemoveElementBehavior ],
44734
- toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
45930
+ rootElementReferenceBehavior: [ 'type', RootElementReferenceBehavior ],
44735
45931
  spaceToolBehavior: [ 'type', SpaceToolBehavior ],
45932
+ subProcessPlaneBehavior: [ 'type', SubProcessPlaneBehavior ],
44736
45933
  subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ],
45934
+ toggleCollapseConnectionBehaviour: [ 'type', ToggleCollapseConnectionBehaviour ],
45935
+ toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
44737
45936
  unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
44738
- updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],
44739
- unsetDefaultFlowBehavior: [ 'type', DeleteSequenceFlowBehavior ]
45937
+ unsetDefaultFlowBehavior: [ 'type', DeleteSequenceFlowBehavior ],
45938
+ updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ]
44740
45939
  };
44741
45940
 
44742
45941
  function getBoundaryAttachment(position, targetBounds) {
@@ -45686,21 +46885,24 @@
45686
46885
  eventBus.on('saveXML.start', HIGH_PRIORITY$6, orderDi);
45687
46886
 
45688
46887
  function orderDi() {
45689
- var root = canvas.getRootElement(),
45690
- rootDi = getDi(root),
45691
- elements,
45692
- diElements;
46888
+ var rootElements = canvas.getRootElements();
45693
46889
 
45694
- elements = selfAndAllChildren([ root ], false);
46890
+ forEach(rootElements, function(root) {
46891
+ var rootDi = getDi(root),
46892
+ elements,
46893
+ diElements;
45695
46894
 
45696
- // only bpmndi:Shape and bpmndi:Edge can be direct children of bpmndi:Plane
45697
- elements = filter(elements, function(element) {
45698
- return element !== root && !element.labelTarget;
45699
- });
46895
+ elements = selfAndAllChildren([ root ], false);
46896
+
46897
+ // only bpmndi:Shape and bpmndi:Edge can be direct children of bpmndi:Plane
46898
+ elements = filter(elements, function(element) {
46899
+ return element !== root && !element.labelTarget;
46900
+ });
45700
46901
 
45701
- diElements = map$1(elements, getDi);
46902
+ diElements = map$1(elements, getDi);
45702
46903
 
45703
- rootDi.set('planeElement', diElements);
46904
+ rootDi.set('planeElement', diElements);
46905
+ });
45704
46906
  }
45705
46907
  }
45706
46908
 
@@ -45834,7 +47036,7 @@
45834
47036
  level: 9,
45835
47037
  containers: [
45836
47038
  'bpmn:Collaboration',
45837
- 'bpmn:Process'
47039
+ 'bpmn:FlowElementsContainer'
45838
47040
  ]
45839
47041
  }
45840
47042
  },
@@ -45862,7 +47064,7 @@
45862
47064
  level: 10,
45863
47065
  containers: [
45864
47066
  'bpmn:Collaboration',
45865
- 'bpmn:Process'
47067
+ 'bpmn:FlowElementsContainer'
45866
47068
  ]
45867
47069
  }
45868
47070
  },
@@ -45923,7 +47125,7 @@
45923
47125
  // render labels always on top
45924
47126
  if (element.labelTarget) {
45925
47127
  return {
45926
- parent: canvas.getRootElement(),
47128
+ parent: canvas.findRoot(element.labelTarget) || canvas.getRootElement(),
45927
47129
  index: -1
45928
47130
  };
45929
47131
  }
@@ -48407,6 +49609,10 @@
48407
49609
  };
48408
49610
 
48409
49611
  BpmnFactory.prototype._ensureId = function(element) {
49612
+ if (element.id) {
49613
+ this._model.ids.claim(element.id, element);
49614
+ return;
49615
+ }
48410
49616
 
48411
49617
  // generate semantic ids for elements
48412
49618
  // bpmn:SequenceFlow -> SequenceFlow_ID
@@ -48477,7 +49683,7 @@
48477
49683
  BpmnFactory.prototype.createDiEdge = function(semantic, attrs) {
48478
49684
  return this.create('bpmndi:BPMNEdge', assign({
48479
49685
  bpmnElement: semantic,
48480
- waypoints: this.createDiWaypoints([])
49686
+ waypoint: this.createDiWaypoints([])
48481
49687
  }, attrs));
48482
49688
  };
48483
49689
 
@@ -48805,7 +50011,18 @@
48805
50011
 
48806
50012
  BpmnUpdater.prototype.updateBounds = function(shape) {
48807
50013
 
48808
- var di = getDi(shape);
50014
+ var di = getDi(shape),
50015
+ embeddedLabelBounds = getEmbeddedLabelBounds(shape);
50016
+
50017
+ // update embedded label bounds if possible
50018
+ if (embeddedLabelBounds) {
50019
+ var embeddedLabelBoundsDelta = delta(embeddedLabelBounds, di.get('bounds'));
50020
+
50021
+ assign(embeddedLabelBounds, {
50022
+ x: shape.x + embeddedLabelBoundsDelta.x,
50023
+ y: shape.y + embeddedLabelBoundsDelta.y
50024
+ });
50025
+ }
48809
50026
 
48810
50027
  var target = (shape instanceof Label) ? this._getLabel(di) : di;
48811
50028
 
@@ -49180,6 +50397,33 @@
49180
50397
  };
49181
50398
  }
49182
50399
 
50400
+ /**
50401
+ * Return dc:Bounds of bpmndi:BPMNLabel if exists.
50402
+ *
50403
+ * @param {djs.model.shape} shape
50404
+ *
50405
+ * @returns {Object|undefined}
50406
+ */
50407
+ function getEmbeddedLabelBounds(shape) {
50408
+ if (!is$1(shape, 'bpmn:Activity')) {
50409
+ return;
50410
+ }
50411
+
50412
+ var di = getDi(shape);
50413
+
50414
+ if (!di) {
50415
+ return;
50416
+ }
50417
+
50418
+ var label = di.get('label');
50419
+
50420
+ if (!label) {
50421
+ return;
50422
+ }
50423
+
50424
+ return label.get('bounds');
50425
+ }
50426
+
49183
50427
  /**
49184
50428
  * A bpmn-aware factory for diagram-js shapes
49185
50429
  */
@@ -49266,6 +50510,10 @@
49266
50510
  applyAttribute(di, attrs, 'isExpanded');
49267
50511
  }
49268
50512
 
50513
+ if (is$1(businessObject, 'bpmn:SubProcess')) {
50514
+ attrs.collapsed = !isExpanded(businessObject, di);
50515
+ }
50516
+
49269
50517
  if (is$1(businessObject, 'bpmn:ExclusiveGateway')) {
49270
50518
  di.isMarkerVisible = true;
49271
50519
  }
@@ -49637,7 +50885,11 @@
49637
50885
  }
49638
50886
  });
49639
50887
 
49640
- var bbox = getBBox(elements);
50888
+ var visibleElements = filter(elements, function(element) {
50889
+ return !element.hidden;
50890
+ });
50891
+
50892
+ var bbox = getBBox(visibleElements);
49641
50893
 
49642
50894
  // center elements around position
49643
50895
  forEach(elements, function(element) {
@@ -52082,7 +53334,8 @@
52082
53334
  diPlane = getDi(oldRoot);
52083
53335
 
52084
53336
  // (1) replace process old <> new root
52085
- canvas.setRootElement(newRoot, true);
53337
+ canvas.setRootElement(newRoot);
53338
+ canvas.removeRootElement(oldRoot);
52086
53339
 
52087
53340
  // (2) update root elements
52088
53341
  add(bpmnDefinitions.rootElements, newRootBusinessObject);
@@ -52116,7 +53369,8 @@
52116
53369
  diPlane = getDi(newRoot);
52117
53370
 
52118
53371
  // (1) replace process old <> new root
52119
- canvas.setRootElement(oldRoot, true);
53372
+ canvas.setRootElement(oldRoot);
53373
+ canvas.removeRootElement(newRoot);
52120
53374
 
52121
53375
  // (2) update root elements
52122
53376
  remove(bpmnDefinitions.rootElements, newRootBusinessObject);
@@ -52686,12 +53940,26 @@
52686
53940
  // TODO @barmac: remove once we drop bpmn.io properties
52687
53941
  ensureLegacySupport(assignedDi);
52688
53942
 
52689
- self._commandStack.execute('element.updateProperties', {
52690
- element: element,
52691
- properties: {
52692
- di: assignedDi
52693
- }
52694
- });
53943
+ if (element.labelTarget) {
53944
+
53945
+ // set label colors as bpmndi:BPMNLabel#color
53946
+ self._commandStack.execute('element.updateModdleProperties', {
53947
+ element: element,
53948
+ moddleElement: getDi(element).label,
53949
+ properties: {
53950
+ color: di['background-color']
53951
+ }
53952
+ });
53953
+ } else {
53954
+
53955
+ // set colors bpmndi:BPMNEdge or bpmndi:BPMNShape
53956
+ self._commandStack.execute('element.updateProperties', {
53957
+ element: element,
53958
+ properties: {
53959
+ di: assignedDi
53960
+ }
53961
+ });
53962
+ }
52695
53963
  });
52696
53964
 
52697
53965
  };
@@ -52754,7 +54022,30 @@
52754
54022
  /**
52755
54023
  * A handler that updates the text of a BPMN element.
52756
54024
  */
52757
- function UpdateLabelHandler(modeling, textRenderer) {
54025
+ function UpdateLabelHandler(modeling, textRenderer, bpmnFactory) {
54026
+
54027
+ /**
54028
+ * Creates an empty `diLabel` attribute for embedded labels.
54029
+ *
54030
+ * @param {djs.model.Base} element
54031
+ * @param {string} text
54032
+ */
54033
+ function ensureInternalLabelDi(element, text) {
54034
+ if (isLabelExternal(element)) {
54035
+ return;
54036
+ }
54037
+
54038
+ var di = getDi(element);
54039
+
54040
+ if (text && !di.label) {
54041
+ di.label = bpmnFactory.create('bpmndi:BPMNLabel');
54042
+ }
54043
+
54044
+ if (!text && di.label) {
54045
+ di.label = null;
54046
+ }
54047
+ }
54048
+
52758
54049
 
52759
54050
  /**
52760
54051
  * Set the label and return the changed elements.
@@ -52773,6 +54064,8 @@
52773
54064
 
52774
54065
  setLabel(label, text);
52775
54066
 
54067
+ ensureInternalLabelDi(element, text);
54068
+
52776
54069
  return [ label, labelTarget ];
52777
54070
  }
52778
54071
 
@@ -52858,7 +54151,8 @@
52858
54151
 
52859
54152
  UpdateLabelHandler.$inject = [
52860
54153
  'modeling',
52861
- 'textRenderer'
54154
+ 'textRenderer',
54155
+ 'bpmnFactory'
52862
54156
  ];
52863
54157
 
52864
54158
 
@@ -55903,7 +57197,7 @@
55903
57197
 
55904
57198
  create.start(event, [ subProcess, startEvent ], {
55905
57199
  hints: {
55906
- autoSelect: [ startEvent ]
57200
+ autoSelect: [ subProcess ]
55907
57201
  }
55908
57202
  });
55909
57203
  }