bpmn-js 8.9.0 → 9.0.0-alpha.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 (55) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/assets/bpmn-js.css +113 -0
  3. package/dist/bpmn-modeler.development.js +2600 -991
  4. package/dist/bpmn-modeler.production.min.js +9 -8
  5. package/dist/bpmn-navigated-viewer.development.js +21240 -19985
  6. package/dist/bpmn-navigated-viewer.production.min.js +22 -20
  7. package/dist/bpmn-viewer.development.js +20441 -19186
  8. package/dist/bpmn-viewer.production.min.js +22 -20
  9. package/lib/BaseViewer.js +1 -14
  10. package/lib/Viewer.js +3 -1
  11. package/lib/draw/BpmnRenderUtil.js +6 -4
  12. package/lib/features/auto-resize/BpmnAutoResizeProvider.js +6 -0
  13. package/lib/features/context-pad/ContextPadProvider.js +1 -1
  14. package/lib/features/copy-paste/BpmnCopyPaste.js +14 -13
  15. package/lib/features/di-ordering/BpmnDiOrdering.js +16 -13
  16. package/lib/features/drilldown/DrilldownBreadcrumbs.js +122 -0
  17. package/lib/features/drilldown/DrilldownCentering.js +118 -0
  18. package/lib/features/drilldown/DrilldownOverlayBehavior.js +181 -0
  19. package/lib/features/drilldown/SubprocessCompatibility.js +196 -0
  20. package/lib/features/drilldown/index.js +17 -0
  21. package/lib/features/label-editing/LabelEditingPreview.js +3 -3
  22. package/lib/features/label-editing/cmd/UpdateLabelHandler.js +31 -3
  23. package/lib/features/modeling/BpmnFactory.js +11 -8
  24. package/lib/features/modeling/BpmnUpdater.js +35 -27
  25. package/lib/features/modeling/ElementFactory.js +64 -37
  26. package/lib/features/modeling/behavior/CreateParticipantBehavior.js +59 -84
  27. package/lib/features/modeling/behavior/DataStoreBehavior.js +3 -1
  28. package/lib/features/modeling/behavior/IsHorizontalFix.js +7 -4
  29. package/lib/features/modeling/behavior/LabelBehavior.js +8 -7
  30. package/lib/features/modeling/behavior/SubProcessPlaneBehavior.js +550 -0
  31. package/lib/features/modeling/behavior/ToggleCollapseConnectionBehaviour.js +74 -0
  32. package/lib/features/modeling/behavior/ToggleElementCollapseBehaviour.js +6 -6
  33. package/lib/features/modeling/behavior/UnclaimIdBehavior.js +3 -1
  34. package/lib/features/modeling/behavior/index.js +6 -0
  35. package/lib/features/modeling/cmd/SetColorHandler.js +4 -1
  36. package/lib/features/modeling/cmd/UpdateCanvasRootHandler.js +12 -8
  37. package/lib/features/modeling/cmd/UpdatePropertiesHandler.js +19 -12
  38. package/lib/features/modeling/cmd/UpdateSemanticParentHandler.js +5 -3
  39. package/lib/features/modeling/util/ModelingUtil.js +2 -20
  40. package/lib/features/ordering/BpmnOrderingProvider.js +1 -1
  41. package/lib/features/palette/PaletteProvider.js +3 -1
  42. package/lib/features/popup-menu/ReplaceMenuProvider.js +6 -6
  43. package/lib/features/popup-menu/util/TypeUtil.js +1 -1
  44. package/lib/features/replace/BpmnReplace.js +29 -29
  45. package/lib/import/BpmnImporter.js +33 -22
  46. package/lib/import/BpmnTreeWalker.js +19 -17
  47. package/lib/import/Importer.js +137 -6
  48. package/lib/util/CompatibilityUtil.js +21 -1
  49. package/lib/util/DiUtil.js +10 -3
  50. package/lib/util/DrilldownUtil.js +66 -0
  51. package/lib/util/LabelUtil.js +2 -3
  52. package/lib/util/ModelUtil.js +30 -0
  53. package/package.json +2 -2
  54. package/test/matchers/BoundsMatchers.js +10 -10
  55. package/test/matchers/ConnectionMatchers.js +5 -5
@@ -0,0 +1,196 @@
1
+
2
+ import { asBounds, asTRBL } from 'diagram-js/lib/layout/LayoutUtil';
3
+ import { is } from '../../util/ModelUtil';
4
+
5
+ var DEFAULT_POSITION = {
6
+ x: 180,
7
+ y: 160
8
+ };
9
+
10
+ /**
11
+ * Hook into `import.render.start` and create new planes for diagrams with
12
+ * collapsed subprocesses and all dis on the same plane.
13
+ *
14
+ * @param {eventBus} eventBus
15
+ * @param {moddle} moddle
16
+ */
17
+ export default function SubprocessCompatibility(eventBus, moddle) {
18
+ this._eventBus = eventBus;
19
+ this._moddle = moddle;
20
+
21
+ var self = this;
22
+
23
+ eventBus.on('import.render.start', 1500, function(e, context) {
24
+ self.handleImport(context.definitions);
25
+ });
26
+ }
27
+
28
+ SubprocessCompatibility.prototype.handleImport = function(definitions) {
29
+ if (!definitions.diagrams) {
30
+ return;
31
+ }
32
+
33
+ var self = this;
34
+ this._definitions = definitions;
35
+ this._processToDiagramMap = {};
36
+
37
+ definitions.diagrams.forEach(function(diagram) {
38
+ if (!diagram.plane || !diagram.plane.bpmnElement) {
39
+ return;
40
+ }
41
+
42
+ self._processToDiagramMap[diagram.plane.bpmnElement.id] = diagram;
43
+ });
44
+
45
+ var newDiagrams = [];
46
+ definitions.diagrams.forEach(function(diagram) {
47
+ var createdDiagrams = self.createNewDiagrams(diagram.plane);
48
+ Array.prototype.push.apply(newDiagrams, createdDiagrams);
49
+ });
50
+
51
+ newDiagrams.forEach(function(diagram) {
52
+ self.movePlaneElementsToOrigin(diagram.plane);
53
+ });
54
+ };
55
+
56
+
57
+ /**
58
+ * Moves all DI elements from collapsed subprocesses to a new plane.
59
+ *
60
+ * @param {Object} plane
61
+ * @return {Array} new diagrams created for the collapsed subprocesses
62
+ */
63
+ SubprocessCompatibility.prototype.createNewDiagrams = function(plane) {
64
+ var self = this;
65
+
66
+ var collapsedElements = [];
67
+ var elementsToMove = [];
68
+
69
+ plane.get('planeElement').forEach(function(diElement) {
70
+ var bo = diElement.bpmnElement;
71
+ var parent = bo.$parent;
72
+
73
+ if (is(bo, 'bpmn:SubProcess') && !diElement.isExpanded) {
74
+ collapsedElements.push(bo);
75
+ }
76
+
77
+ if (is(parent, 'bpmn:SubProcess') && parent !== plane.bpmnElement) {
78
+
79
+ // don't change the array while we iterate over it
80
+ elementsToMove.push({ diElement: diElement, parent: parent });
81
+ }
82
+ });
83
+
84
+ var newDiagrams = [];
85
+
86
+ // create new planes for all collapsed subprocesses, even when they are empty
87
+ collapsedElements.forEach(function(element) {
88
+ if (!self._processToDiagramMap[element.id]) {
89
+ var diagram = self.createDiagram(element);
90
+ self._processToDiagramMap[element.id] = diagram;
91
+ newDiagrams.push(diagram);
92
+ }
93
+ });
94
+
95
+ elementsToMove.forEach(function(element) {
96
+ var diElement = element.diElement;
97
+ var parent = element.parent;
98
+
99
+ // parent is expanded, get nearest collapsed parent
100
+ while (parent && !collapsedElements.includes(parent)) {
101
+ parent = parent.$parent;
102
+ }
103
+
104
+ // false positive, all parents are expanded
105
+ if (!parent) {
106
+ return;
107
+ }
108
+
109
+ var diagram = self._processToDiagramMap[parent.id];
110
+ self.moveToDiPlane(diElement, diagram.plane);
111
+ });
112
+
113
+ return newDiagrams;
114
+ };
115
+
116
+ SubprocessCompatibility.prototype.movePlaneElementsToOrigin = function(plane) {
117
+ var elements = plane.get('planeElement');
118
+
119
+ // get bounding box of all elements
120
+ var planeBounds = getPlaneBounds(plane);
121
+
122
+ var offset = {
123
+ x: planeBounds.x - DEFAULT_POSITION.x,
124
+ y: planeBounds.y - DEFAULT_POSITION.y
125
+ };
126
+
127
+ elements.forEach(function(diElement) {
128
+ if (diElement.waypoint) {
129
+ diElement.waypoint.forEach(function(waypoint) {
130
+ waypoint.x = waypoint.x - offset.x;
131
+ waypoint.y = waypoint.y - offset.y;
132
+ });
133
+ } else if (diElement.bounds) {
134
+ diElement.bounds.x = diElement.bounds.x - offset.x;
135
+ diElement.bounds.y = diElement.bounds.y - offset.y;
136
+ }
137
+ });
138
+ };
139
+
140
+
141
+ SubprocessCompatibility.prototype.moveToDiPlane = function(diElement, newPlane) {
142
+ var containingDiagram = findRootDiagram(diElement);
143
+
144
+ // remove DI from old Plane and add it to the new one
145
+ var parentPlaneElement = containingDiagram.plane.get('planeElement');
146
+ parentPlaneElement.splice(parentPlaneElement.indexOf(diElement), 1);
147
+ newPlane.get('planeElement').push(diElement);
148
+ };
149
+
150
+
151
+ SubprocessCompatibility.prototype.createDiagram = function(bo) {
152
+ var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
153
+ var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
154
+ plane: plane
155
+ });
156
+ plane.$parent = diagram;
157
+ plane.bpmnElement = bo;
158
+ diagram.$parent = this._definitions;
159
+ this._definitions.diagrams.push(diagram);
160
+ return diagram;
161
+ };
162
+
163
+ SubprocessCompatibility.$inject = [ 'eventBus', 'moddle' ];
164
+
165
+
166
+ // helpers
167
+
168
+ function findRootDiagram(element) {
169
+ if (is(element, 'bpmndi:BPMNDiagram')) {
170
+ return element;
171
+ } else {
172
+ return findRootDiagram(element.$parent);
173
+ }
174
+ }
175
+
176
+ function getPlaneBounds(plane) {
177
+ var planeTrbl = {
178
+ top: Infinity,
179
+ right: -Infinity,
180
+ bottom: -Infinity,
181
+ left: Infinity
182
+ };
183
+
184
+ plane.planeElement.forEach(function(element) {
185
+ if (!element.bounds) {
186
+ return;
187
+ }
188
+
189
+ var trbl = asTRBL(element.bounds);
190
+
191
+ planeTrbl.top = Math.min(trbl.top, planeTrbl.top);
192
+ planeTrbl.left = Math.min(trbl.left, planeTrbl.left);
193
+ });
194
+
195
+ return asBounds(planeTrbl);
196
+ }
@@ -0,0 +1,17 @@
1
+ import OverlaysModule from 'diagram-js/lib/features/overlays';
2
+ import ChangeSupportModule from 'diagram-js/lib/features/change-support';
3
+ import RootElementsModule from 'diagram-js/lib/features/root-elements';
4
+
5
+ import DrilldownBreadcrumbs from './DrilldownBreadcrumbs';
6
+ import DrilldownCentering from './DrilldownCentering';
7
+ import SubprocessCompatibility from './SubprocessCompatibility';
8
+ import DrilldownOverlayBehavior from './DrilldownOverlayBehavior';
9
+
10
+ export default {
11
+ __depends__: [ OverlaysModule, ChangeSupportModule, RootElementsModule ],
12
+ __init__: [ 'drilldownBreadcrumbs', 'drilldownOverlayBehavior', 'drilldownCentering', 'subprocessCompatibility'],
13
+ drilldownBreadcrumbs: [ 'type', DrilldownBreadcrumbs ],
14
+ drilldownCentering: [ 'type', DrilldownCentering ],
15
+ drilldownOverlayBehavior: [ 'type', DrilldownOverlayBehavior ],
16
+ subprocessCompatibility: [ 'type', SubprocessCompatibility ]
17
+ };
@@ -6,7 +6,7 @@ import {
6
6
  } from 'tiny-svg';
7
7
 
8
8
  import {
9
- getBusinessObject,
9
+ getDi,
10
10
  is
11
11
  } from '../../util/ModelUtil';
12
12
 
@@ -132,7 +132,7 @@ LabelEditingPreview.$inject = [
132
132
  // helpers ///////////////////
133
133
 
134
134
  function getStrokeColor(element, defaultColor) {
135
- var bo = getBusinessObject(element);
135
+ var di = getDi(element);
136
136
 
137
- return bo.di.get('stroke') || defaultColor || 'black';
137
+ return di.get('stroke') || defaultColor || 'black';
138
138
  }
@@ -11,6 +11,7 @@ import {
11
11
  } from '../../../util/LabelUtil';
12
12
 
13
13
  import {
14
+ getDi,
14
15
  is
15
16
  } from '../../../util/ModelUtil';
16
17
 
@@ -23,7 +24,30 @@ var NULL_DIMENSIONS = {
23
24
  /**
24
25
  * A handler that updates the text of a BPMN element.
25
26
  */
26
- export default function UpdateLabelHandler(modeling, textRenderer) {
27
+ export default function UpdateLabelHandler(modeling, textRenderer, bpmnFactory) {
28
+
29
+ /**
30
+ * Creates an empty `diLabel` attribute for embedded labels.
31
+ *
32
+ * @param {djs.model.Base} element
33
+ * @param {string} text
34
+ */
35
+ function ensureInternalLabelDi(element, text) {
36
+ if (isLabelExternal(element)) {
37
+ return;
38
+ }
39
+
40
+ var di = getDi(element);
41
+
42
+ if (text && !di.label) {
43
+ di.label = bpmnFactory.create('bpmndi:BPMNLabel');
44
+ }
45
+
46
+ if (!text && di.label) {
47
+ di.label = null;
48
+ }
49
+ }
50
+
27
51
 
28
52
  /**
29
53
  * Set the label and return the changed elements.
@@ -42,6 +66,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) {
42
66
 
43
67
  setLabel(label, text, labelTarget !== label);
44
68
 
69
+ ensureInternalLabelDi(element, text);
70
+
45
71
  return [ label, labelTarget ];
46
72
  }
47
73
 
@@ -67,7 +93,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) {
67
93
 
68
94
  modeling.createLabel(element, labelCenter, {
69
95
  id: businessObject.id + '_label',
70
- businessObject: businessObject
96
+ businessObject: businessObject,
97
+ di: element.di
71
98
  });
72
99
  }
73
100
  }
@@ -126,7 +153,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) {
126
153
 
127
154
  UpdateLabelHandler.$inject = [
128
155
  'modeling',
129
- 'textRenderer'
156
+ 'textRenderer',
157
+ 'bpmnFactory'
130
158
  ];
131
159
 
132
160
 
@@ -42,6 +42,10 @@ BpmnFactory.prototype._needsId = function(element) {
42
42
  };
43
43
 
44
44
  BpmnFactory.prototype._ensureId = function(element) {
45
+ if (element.id) {
46
+ this._model.ids.claim(element.id, element);
47
+ return;
48
+ }
45
49
 
46
50
  // generate semantic ids for elements
47
51
  // bpmn:SequenceFlow -> SequenceFlow_ID
@@ -83,11 +87,10 @@ BpmnFactory.prototype.createDiLabel = function() {
83
87
  };
84
88
 
85
89
 
86
- BpmnFactory.prototype.createDiShape = function(semantic, bounds, attrs) {
87
-
90
+ BpmnFactory.prototype.createDiShape = function(semantic, attrs) {
88
91
  return this.create('bpmndi:BPMNShape', assign({
89
92
  bpmnElement: semantic,
90
- bounds: this.createDiBounds(bounds)
93
+ bounds: this.createDiBounds()
91
94
  }, attrs));
92
95
  };
93
96
 
@@ -110,15 +113,15 @@ BpmnFactory.prototype.createDiWaypoint = function(point) {
110
113
  };
111
114
 
112
115
 
113
- BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) {
116
+ BpmnFactory.prototype.createDiEdge = function(semantic, attrs) {
114
117
  return this.create('bpmndi:BPMNEdge', assign({
115
118
  bpmnElement: semantic,
116
- waypoint: this.createDiWaypoints(waypoints)
119
+ waypoint: this.createDiWaypoints([])
117
120
  }, attrs));
118
121
  };
119
122
 
120
- BpmnFactory.prototype.createDiPlane = function(semantic) {
121
- return this.create('bpmndi:BPMNPlane', {
123
+ BpmnFactory.prototype.createDiPlane = function(semantic, attrs) {
124
+ return this.create('bpmndi:BPMNPlane', assign({
122
125
  bpmnElement: semantic
123
- });
126
+ }, attrs));
124
127
  };
@@ -16,6 +16,7 @@ import {
16
16
 
17
17
  import {
18
18
  getBusinessObject,
19
+ getDi,
19
20
  is
20
21
  } from '../../util/ModelUtil';
21
22
 
@@ -307,8 +308,9 @@ BpmnUpdater.prototype.updateParent = function(element, oldParent) {
307
308
  var parentShape = element.parent;
308
309
 
309
310
  var businessObject = element.businessObject,
311
+ di = getDi(element),
310
312
  parentBusinessObject = parentShape && parentShape.businessObject,
311
- parentDi = parentBusinessObject && parentBusinessObject.di;
313
+ parentDi = getDi(parentShape);
312
314
 
313
315
  if (is(element, 'bpmn:FlowNode')) {
314
316
  this.updateFlowNodeRefs(businessObject, parentBusinessObject, oldParent && oldParent.businessObject);
@@ -336,13 +338,13 @@ BpmnUpdater.prototype.updateParent = function(element, oldParent) {
336
338
  this.updateSemanticParent(businessObject.dataObjectRef, parentBusinessObject);
337
339
  }
338
340
 
339
- this.updateDiParent(businessObject.di, parentDi);
341
+ this.updateDiParent(di, parentDi);
340
342
  };
341
343
 
342
344
 
343
345
  BpmnUpdater.prototype.updateBounds = function(shape) {
344
346
 
345
- var di = shape.businessObject.di;
347
+ var di = getDi(shape);
346
348
 
347
349
  var target = (shape instanceof Label) ? this._getLabel(di) : di;
348
350
 
@@ -382,14 +384,17 @@ BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainme
382
384
 
383
385
 
384
386
  // update existing sourceElement and targetElement di information
385
- BpmnUpdater.prototype.updateDiConnection = function(di, newSource, newTarget) {
387
+ BpmnUpdater.prototype.updateDiConnection = function(connection, newSource, newTarget) {
388
+ var connectionDi = getDi(connection),
389
+ newSourceDi = getDi(newSource),
390
+ newTargetDi = getDi(newTarget);
386
391
 
387
- if (di.sourceElement && di.sourceElement.bpmnElement !== newSource) {
388
- di.sourceElement = newSource && newSource.di;
392
+ if (connectionDi.sourceElement && connectionDi.sourceElement.bpmnElement !== getBusinessObject(newSource)) {
393
+ connectionDi.sourceElement = newSource && newSourceDi;
389
394
  }
390
395
 
391
- if (di.targetElement && di.targetElement.bpmnElement !== newTarget) {
392
- di.targetElement = newTarget && newTarget.di;
396
+ if (connectionDi.targetElement && connectionDi.targetElement.bpmnElement !== getBusinessObject(newTarget)) {
397
+ connectionDi.targetElement = newTarget && newTargetDi;
393
398
  }
394
399
 
395
400
  };
@@ -614,69 +619,72 @@ BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent,
614
619
 
615
620
 
616
621
  BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
617
- connection.businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
622
+ var di = getDi(connection);
623
+
624
+ di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
618
625
  };
619
626
 
620
627
 
621
628
  BpmnUpdater.prototype.updateConnection = function(context) {
622
-
623
629
  var connection = context.connection,
624
630
  businessObject = getBusinessObject(connection),
625
- newSource = getBusinessObject(connection.source),
626
- newTarget = getBusinessObject(connection.target),
631
+ newSource = connection.source,
632
+ newSourceBo = getBusinessObject(newSource),
633
+ newTarget = connection.target,
634
+ newTargetBo = getBusinessObject(connection.target),
627
635
  visualParent;
628
636
 
629
637
  if (!is(businessObject, 'bpmn:DataAssociation')) {
630
638
 
631
639
  var inverseSet = is(businessObject, 'bpmn:SequenceFlow');
632
640
 
633
- if (businessObject.sourceRef !== newSource) {
641
+ if (businessObject.sourceRef !== newSourceBo) {
634
642
  if (inverseSet) {
635
643
  collectionRemove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
636
644
 
637
- if (newSource && newSource.get('outgoing')) {
638
- newSource.get('outgoing').push(businessObject);
645
+ if (newSourceBo && newSourceBo.get('outgoing')) {
646
+ newSourceBo.get('outgoing').push(businessObject);
639
647
  }
640
648
  }
641
649
 
642
- businessObject.sourceRef = newSource;
650
+ businessObject.sourceRef = newSourceBo;
643
651
  }
644
652
 
645
- if (businessObject.targetRef !== newTarget) {
653
+ if (businessObject.targetRef !== newTargetBo) {
646
654
  if (inverseSet) {
647
655
  collectionRemove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
648
656
 
649
- if (newTarget && newTarget.get('incoming')) {
650
- newTarget.get('incoming').push(businessObject);
657
+ if (newTargetBo && newTargetBo.get('incoming')) {
658
+ newTargetBo.get('incoming').push(businessObject);
651
659
  }
652
660
  }
653
661
 
654
- businessObject.targetRef = newTarget;
662
+ businessObject.targetRef = newTargetBo;
655
663
  }
656
664
  } else
657
665
 
658
666
  if (is(businessObject, 'bpmn:DataInputAssociation')) {
659
667
 
660
668
  // handle obnoxious isMsome sourceRef
661
- businessObject.get('sourceRef')[0] = newSource;
669
+ businessObject.get('sourceRef')[0] = newSourceBo;
662
670
 
663
- visualParent = context.parent || context.newParent || newTarget;
671
+ visualParent = context.parent || context.newParent || newTargetBo;
664
672
 
665
- this.updateSemanticParent(businessObject, newTarget, visualParent);
673
+ this.updateSemanticParent(businessObject, newTargetBo, visualParent);
666
674
  } else
667
675
 
668
676
  if (is(businessObject, 'bpmn:DataOutputAssociation')) {
669
- visualParent = context.parent || context.newParent || newSource;
677
+ visualParent = context.parent || context.newParent || newSourceBo;
670
678
 
671
- this.updateSemanticParent(businessObject, newSource, visualParent);
679
+ this.updateSemanticParent(businessObject, newSourceBo, visualParent);
672
680
 
673
681
  // targetRef = new target
674
- businessObject.targetRef = newTarget;
682
+ businessObject.targetRef = newTargetBo;
675
683
  }
676
684
 
677
685
  this.updateConnectionWaypoints(connection);
678
686
 
679
- this.updateDiConnection(businessObject.di, newSource, newTarget);
687
+ this.updateDiConnection(connection, newSource, newTarget);
680
688
  };
681
689
 
682
690