bpmn-js 16.3.2 → 16.4.0

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.
@@ -8,6 +8,10 @@ import {
8
8
  getChildLanes
9
9
  } from '../util/LaneUtil';
10
10
 
11
+ import {
12
+ isHorizontal
13
+ } from '../../../util/DiUtil';
14
+
11
15
  import {
12
16
  eachElement
13
17
  } from 'diagram-js/lib/util/Elements';
@@ -32,18 +36,29 @@ export default function DeleteLaneBehavior(eventBus, spaceTool) {
32
36
 
33
37
 
34
38
  function compensateLaneDelete(shape, oldParent) {
39
+ var isHorizontalLane = isHorizontal(shape);
35
40
 
36
41
  var siblings = getChildLanes(oldParent);
37
42
 
38
43
  var topAffected = [];
39
44
  var bottomAffected = [];
45
+ var leftAffected = [];
46
+ var rightAffected = [];
40
47
 
41
48
  eachElement(siblings, function(element) {
42
49
 
43
- if (element.y > shape.y) {
44
- bottomAffected.push(element);
50
+ if (isHorizontalLane) {
51
+ if (element.y > shape.y) {
52
+ bottomAffected.push(element);
53
+ } else {
54
+ topAffected.push(element);
55
+ }
45
56
  } else {
46
- topAffected.push(element);
57
+ if (element.x > shape.x) {
58
+ rightAffected.push(element);
59
+ } else {
60
+ leftAffected.push(element);
61
+ }
47
62
  }
48
63
 
49
64
  return element.children;
@@ -55,14 +70,24 @@ export default function DeleteLaneBehavior(eventBus, spaceTool) {
55
70
 
56
71
  var offset;
57
72
 
58
- if (bottomAffected.length && topAffected.length) {
59
- offset = shape.height / 2;
73
+ if (isHorizontalLane) {
74
+ if (bottomAffected.length && topAffected.length) {
75
+ offset = shape.height / 2;
76
+ } else {
77
+ offset = shape.height;
78
+ }
60
79
  } else {
61
- offset = shape.height;
80
+ if (rightAffected.length && leftAffected.length) {
81
+ offset = shape.width / 2;
82
+ } else {
83
+ offset = shape.width;
84
+ }
62
85
  }
63
86
 
64
87
  var topAdjustments,
65
- bottomAdjustments;
88
+ bottomAdjustments,
89
+ leftAdjustments,
90
+ rightAdjustments;
66
91
 
67
92
  if (topAffected.length) {
68
93
  topAdjustments = spaceTool.calculateAdjustments(
@@ -83,6 +108,26 @@ export default function DeleteLaneBehavior(eventBus, spaceTool) {
83
108
  bottomAdjustments.resizingShapes,
84
109
  { x: 0, y: -offset }, 'n');
85
110
  }
111
+
112
+ if (leftAffected.length) {
113
+ leftAdjustments = spaceTool.calculateAdjustments(
114
+ leftAffected, 'x', offset, shape.x - 10);
115
+
116
+ spaceTool.makeSpace(
117
+ leftAdjustments.movingShapes,
118
+ leftAdjustments.resizingShapes,
119
+ { x: offset, y: 0 }, 'e');
120
+ }
121
+
122
+ if (rightAffected.length) {
123
+ rightAdjustments = spaceTool.calculateAdjustments(
124
+ rightAffected, 'x', -offset, shape.x + shape.width + 10);
125
+
126
+ spaceTool.makeSpace(
127
+ rightAdjustments.movingShapes,
128
+ rightAdjustments.resizingShapes,
129
+ { x: -offset, y: 0 }, 'w');
130
+ }
86
131
  }
87
132
 
88
133
 
@@ -1,8 +1,6 @@
1
1
  import { getLanesRoot } from '../util/LaneUtil';
2
2
 
3
- import { is } from '../../../util/ModelUtil';
4
-
5
- import { isAny } from '../util/ModelingUtil';
3
+ import { is, isAny } from '../../../util/ModelUtil';
6
4
 
7
5
  /**
8
6
  * @typedef {import('diagram-js/lib/core/ElementRegistry').default} ElementRegistry
@@ -48,7 +46,7 @@ export default function FixHoverBehavior(elementRegistry, eventBus, canvas) {
48
46
 
49
47
  // ensure bpmn:Group and label elements are dropped
50
48
  // always onto the root
51
- if (hover !== rootElement && (shape.labelTarget || is(shape, 'bpmn:Group'))) {
49
+ if (hover !== rootElement && (shape.labelTarget || isAny(shape, [ 'bpmn:Group', 'bpmn:TextAnnotation' ]))) {
52
50
  event.hover = rootElement;
53
51
  event.hoverGfx = elementRegistry.getGraphics(event.hover);
54
52
  }
@@ -20,11 +20,21 @@ export const GROUP_MIN_DIMENSIONS: Dimensions;
20
20
  */
21
21
  export const LANE_MIN_DIMENSIONS: Dimensions;
22
22
 
23
+ /**
24
+ * @type {Dimensions}
25
+ */
26
+ export const VERTICAL_LANE_MIN_DIMENSIONS: Dimensions;
27
+
23
28
  /**
24
29
  * @type {Dimensions}
25
30
  */
26
31
  export const PARTICIPANT_MIN_DIMENSIONS: Dimensions;
27
32
 
33
+ /**
34
+ * @type {Dimensions}
35
+ */
36
+ export const VERTICAL_PARTICIPANT_MIN_DIMENSIONS: Dimensions;
37
+
28
38
  /**
29
39
  * @type {Dimensions}
30
40
  */
@@ -1,211 +1,263 @@
1
- import { is } from '../../../util/ModelUtil';
2
-
3
- import { isExpanded } from '../../../util/DiUtil';
4
-
5
- import {
6
- asTRBL
7
- } from 'diagram-js/lib/layout/LayoutUtil';
8
-
9
- import {
10
- collectLanes,
11
- getLanesRoot
12
- } from '../util/LaneUtil';
13
-
14
- var HIGH_PRIORITY = 1500;
15
-
16
- /**
17
- * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
18
- *
19
- * @typedef {import('../../../model/Types').Shape} Shape
20
- *
21
- * @typedef {import('diagram-js/lib/util/Types').Dimensions} Dimensions
22
- * @typedef {import('diagram-js/lib/util/Types').Direction} Direction
23
- * @typedef {import('diagram-js/lib/util/Types').RectTRBL} RectTRBL
24
- */
25
-
26
- /**
27
- * @type {Dimensions}
28
- */
29
- export var GROUP_MIN_DIMENSIONS = { width: 140, height: 120 };
30
-
31
- /**
32
- * @type {Dimensions}
33
- */
34
- export var LANE_MIN_DIMENSIONS = { width: 300, height: 60 };
35
-
36
- /**
37
- * @type {Dimensions}
38
- */
39
- export var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 };
40
-
41
- /**
42
- * @type {Dimensions}
43
- */
44
- export var SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 };
45
-
46
- /**
47
- * @type {Dimensions}
48
- */
49
- export var TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
50
-
51
- /**
52
- * Set minimum bounds/resize constraints on resize.
53
- *
54
- * @param {EventBus} eventBus
55
- */
56
- export default function ResizeBehavior(eventBus) {
57
- eventBus.on('resize.start', HIGH_PRIORITY, function(event) {
58
- var context = event.context,
59
- shape = context.shape,
60
- direction = context.direction,
61
- balanced = context.balanced;
62
-
63
- if (is(shape, 'bpmn:Lane') || is(shape, 'bpmn:Participant')) {
64
- context.resizeConstraints = getParticipantResizeConstraints(shape, direction, balanced);
65
- }
66
-
67
- if (is(shape, 'bpmn:Participant')) {
68
- context.minDimensions = PARTICIPANT_MIN_DIMENSIONS;
69
- }
70
-
71
- if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
72
- context.minDimensions = SUB_PROCESS_MIN_DIMENSIONS;
73
- }
74
-
75
- if (is(shape, 'bpmn:TextAnnotation')) {
76
- context.minDimensions = TEXT_ANNOTATION_MIN_DIMENSIONS;
77
- }
78
- });
79
- }
80
-
81
- ResizeBehavior.$inject = [ 'eventBus' ];
82
-
83
-
84
- var abs = Math.abs,
85
- min = Math.min,
86
- max = Math.max;
87
-
88
-
89
- function addToTrbl(trbl, attr, value, choice) {
90
- var current = trbl[attr];
91
-
92
- // make sure to set the value if it does not exist
93
- // or apply the correct value by comparing against
94
- // choice(value, currentValue)
95
- trbl[attr] = current === undefined ? value : choice(value, current);
96
- }
97
-
98
- function addMin(trbl, attr, value) {
99
- return addToTrbl(trbl, attr, value, min);
100
- }
101
-
102
- function addMax(trbl, attr, value) {
103
- return addToTrbl(trbl, attr, value, max);
104
- }
105
-
106
- var LANE_RIGHT_PADDING = 20,
107
- LANE_LEFT_PADDING = 50,
108
- LANE_TOP_PADDING = 20,
109
- LANE_BOTTOM_PADDING = 20;
110
-
111
- /**
112
- * @param {Shape} laneShape
113
- * @param {Direction} resizeDirection
114
- * @param {boolean} [balanced=false]
115
- *
116
- * @return { {
117
- * min: RectTRBL;
118
- * max: RectTRBL;
119
- * } }
120
- */
121
- export function getParticipantResizeConstraints(laneShape, resizeDirection, balanced) {
122
- var lanesRoot = getLanesRoot(laneShape);
123
-
124
- var isFirst = true,
125
- isLast = true;
126
-
127
- // max top/bottom size for lanes
128
- var allLanes = collectLanes(lanesRoot, [ lanesRoot ]);
129
-
130
- var laneTrbl = asTRBL(laneShape);
131
-
132
- var maxTrbl = {},
133
- minTrbl = {};
134
-
135
- if (/e/.test(resizeDirection)) {
136
- minTrbl.right = laneTrbl.left + LANE_MIN_DIMENSIONS.width;
137
- } else
138
- if (/w/.test(resizeDirection)) {
139
- minTrbl.left = laneTrbl.right - LANE_MIN_DIMENSIONS.width;
140
- }
141
-
142
- allLanes.forEach(function(other) {
143
-
144
- var otherTrbl = asTRBL(other);
145
-
146
- if (/n/.test(resizeDirection)) {
147
-
148
- if (otherTrbl.top < (laneTrbl.top - 10)) {
149
- isFirst = false;
150
- }
151
-
152
- // max top size (based on next element)
153
- if (balanced && abs(laneTrbl.top - otherTrbl.bottom) < 10) {
154
- addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_DIMENSIONS.height);
155
- }
156
-
157
- // min top size (based on self or nested element)
158
- if (abs(laneTrbl.top - otherTrbl.top) < 5) {
159
- addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_DIMENSIONS.height);
160
- }
161
- }
162
-
163
- if (/s/.test(resizeDirection)) {
164
-
165
- if (otherTrbl.bottom > (laneTrbl.bottom + 10)) {
166
- isLast = false;
167
- }
168
-
169
- // max bottom size (based on previous element)
170
- if (balanced && abs(laneTrbl.bottom - otherTrbl.top) < 10) {
171
- addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_DIMENSIONS.height);
172
- }
173
-
174
- // min bottom size (based on self or nested element)
175
- if (abs(laneTrbl.bottom - otherTrbl.bottom) < 5) {
176
- addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_DIMENSIONS.height);
177
- }
178
- }
179
- });
180
-
181
- // max top/bottom/left/right size based on flow nodes
182
- var flowElements = lanesRoot.children.filter(function(s) {
183
- return !s.hidden && !s.waypoints && (is(s, 'bpmn:FlowElement') || is(s, 'bpmn:Artifact'));
184
- });
185
-
186
- flowElements.forEach(function(flowElement) {
187
-
188
- var flowElementTrbl = asTRBL(flowElement);
189
-
190
- if (isFirst && /n/.test(resizeDirection)) {
191
- addMin(minTrbl, 'top', flowElementTrbl.top - LANE_TOP_PADDING);
192
- }
193
-
194
- if (/e/.test(resizeDirection)) {
195
- addMax(minTrbl, 'right', flowElementTrbl.right + LANE_RIGHT_PADDING);
196
- }
197
-
198
- if (isLast && /s/.test(resizeDirection)) {
199
- addMax(minTrbl, 'bottom', flowElementTrbl.bottom + LANE_BOTTOM_PADDING);
200
- }
201
-
202
- if (/w/.test(resizeDirection)) {
203
- addMin(minTrbl, 'left', flowElementTrbl.left - LANE_LEFT_PADDING);
204
- }
205
- });
206
-
207
- return {
208
- min: minTrbl,
209
- max: maxTrbl
210
- };
1
+ import { is } from '../../../util/ModelUtil';
2
+
3
+ import {
4
+ isExpanded,
5
+ isHorizontal
6
+ } from '../../../util/DiUtil';
7
+
8
+ import {
9
+ asTRBL
10
+ } from 'diagram-js/lib/layout/LayoutUtil';
11
+
12
+ import {
13
+ collectLanes,
14
+ getLanesRoot
15
+ } from '../util/LaneUtil';
16
+
17
+ var HIGH_PRIORITY = 1500;
18
+
19
+ /**
20
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
21
+ *
22
+ * @typedef {import('../../../model/Types').Shape} Shape
23
+ *
24
+ * @typedef {import('diagram-js/lib/util/Types').Dimensions} Dimensions
25
+ * @typedef {import('diagram-js/lib/util/Types').Direction} Direction
26
+ * @typedef {import('diagram-js/lib/util/Types').RectTRBL} RectTRBL
27
+ */
28
+
29
+ /**
30
+ * @type {Dimensions}
31
+ */
32
+ export var GROUP_MIN_DIMENSIONS = { width: 140, height: 120 };
33
+
34
+ /**
35
+ * @type {Dimensions}
36
+ */
37
+ export var LANE_MIN_DIMENSIONS = { width: 300, height: 60 };
38
+
39
+ /**
40
+ * @type {Dimensions}
41
+ */
42
+ export var VERTICAL_LANE_MIN_DIMENSIONS = { width: 60, height: 300 };
43
+
44
+ /**
45
+ * @type {Dimensions}
46
+ */
47
+ export var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 };
48
+
49
+ /**
50
+ * @type {Dimensions}
51
+ */
52
+ export var VERTICAL_PARTICIPANT_MIN_DIMENSIONS = { width: 150, height: 300 };
53
+
54
+ /**
55
+ * @type {Dimensions}
56
+ */
57
+ export var SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 };
58
+
59
+ /**
60
+ * @type {Dimensions}
61
+ */
62
+ export var TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
63
+
64
+ /**
65
+ * Set minimum bounds/resize constraints on resize.
66
+ *
67
+ * @param {EventBus} eventBus
68
+ */
69
+ export default function ResizeBehavior(eventBus) {
70
+ eventBus.on('resize.start', HIGH_PRIORITY, function(event) {
71
+ var context = event.context,
72
+ shape = context.shape,
73
+ direction = context.direction,
74
+ balanced = context.balanced;
75
+
76
+ if (is(shape, 'bpmn:Lane') || is(shape, 'bpmn:Participant')) {
77
+ context.resizeConstraints = getParticipantResizeConstraints(shape, direction, balanced);
78
+ }
79
+
80
+ if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
81
+ context.minDimensions = SUB_PROCESS_MIN_DIMENSIONS;
82
+ }
83
+
84
+ if (is(shape, 'bpmn:TextAnnotation')) {
85
+ context.minDimensions = TEXT_ANNOTATION_MIN_DIMENSIONS;
86
+ }
87
+ });
88
+ }
89
+
90
+ ResizeBehavior.$inject = [ 'eventBus' ];
91
+
92
+
93
+ var abs = Math.abs,
94
+ min = Math.min,
95
+ max = Math.max;
96
+
97
+
98
+ function addToTrbl(trbl, attr, value, choice) {
99
+ var current = trbl[attr];
100
+
101
+ // make sure to set the value if it does not exist
102
+ // or apply the correct value by comparing against
103
+ // choice(value, currentValue)
104
+ trbl[attr] = current === undefined ? value : choice(value, current);
105
+ }
106
+
107
+ function addMin(trbl, attr, value) {
108
+ return addToTrbl(trbl, attr, value, min);
109
+ }
110
+
111
+ function addMax(trbl, attr, value) {
112
+ return addToTrbl(trbl, attr, value, max);
113
+ }
114
+
115
+ var LANE_PADDING = { top: 20, left: 50, right: 20, bottom: 20 },
116
+ VERTICAL_LANE_PADDING = { top: 50, left: 20, right: 20, bottom: 20 };
117
+
118
+ /**
119
+ * @param {Shape} laneShape
120
+ * @param {Direction} resizeDirection
121
+ * @param {boolean} [balanced=false]
122
+ *
123
+ * @return { {
124
+ * min: RectTRBL;
125
+ * max: RectTRBL;
126
+ * } }
127
+ */
128
+ export function getParticipantResizeConstraints(laneShape, resizeDirection, balanced) {
129
+ var lanesRoot = getLanesRoot(laneShape);
130
+
131
+ var isFirst = true,
132
+ isLast = true;
133
+
134
+ var allLanes = collectLanes(lanesRoot, [ lanesRoot ]);
135
+
136
+ var laneTrbl = asTRBL(laneShape);
137
+
138
+ var maxTrbl = {},
139
+ minTrbl = {};
140
+
141
+ var isHorizontalLane = isHorizontal(laneShape);
142
+
143
+ var minDimensions = isHorizontalLane ? LANE_MIN_DIMENSIONS : VERTICAL_LANE_MIN_DIMENSIONS;
144
+
145
+ if (/n/.test(resizeDirection)) {
146
+ minTrbl.top = laneTrbl.bottom - minDimensions.height;
147
+ } else
148
+ if (/e/.test(resizeDirection)) {
149
+ minTrbl.right = laneTrbl.left + minDimensions.width;
150
+ } else
151
+ if (/s/.test(resizeDirection)) {
152
+ minTrbl.bottom = laneTrbl.top + minDimensions.height;
153
+ } else
154
+ if (/w/.test(resizeDirection)) {
155
+ minTrbl.left = laneTrbl.right - minDimensions.width;
156
+ }
157
+
158
+ // min/max size based on related lanes
159
+ allLanes.forEach(function(other) {
160
+
161
+ var otherTrbl = asTRBL(other);
162
+
163
+ if (/n/.test(resizeDirection)) {
164
+ if (isHorizontalLane && otherTrbl.top < (laneTrbl.top - 10)) {
165
+ isFirst = false;
166
+ }
167
+
168
+ // max top size (based on next element)
169
+ if (balanced && abs(laneTrbl.top - otherTrbl.bottom) < 10) {
170
+ addMax(maxTrbl, 'top', otherTrbl.top + minDimensions.height);
171
+ }
172
+
173
+ // min top size (based on self or nested element)
174
+ if (abs(laneTrbl.top - otherTrbl.top) < 5) {
175
+ addMin(minTrbl, 'top', otherTrbl.bottom - minDimensions.height);
176
+ }
177
+ }
178
+
179
+ if (/e/.test(resizeDirection)) {
180
+
181
+ if (!isHorizontalLane && otherTrbl.right > (laneTrbl.right + 10)) {
182
+ isLast = false;
183
+ }
184
+
185
+ // max right size (based on previous element)
186
+ if (balanced && abs(laneTrbl.right - otherTrbl.left) < 10) {
187
+ addMin(maxTrbl, 'right', otherTrbl.right - minDimensions.width);
188
+ }
189
+
190
+ // min right size (based on self or nested element)
191
+ if (abs(laneTrbl.right - otherTrbl.right) < 5) {
192
+ addMax(minTrbl, 'right', otherTrbl.left + minDimensions.width);
193
+ }
194
+ }
195
+
196
+ if (/s/.test(resizeDirection)) {
197
+
198
+ if (isHorizontalLane && otherTrbl.bottom > (laneTrbl.bottom + 10)) {
199
+ isLast = false;
200
+ }
201
+
202
+ // max bottom size (based on previous element)
203
+ if (balanced && abs(laneTrbl.bottom - otherTrbl.top) < 10) {
204
+ addMin(maxTrbl, 'bottom', otherTrbl.bottom - minDimensions.height);
205
+ }
206
+
207
+ // min bottom size (based on self or nested element)
208
+ if (abs(laneTrbl.bottom - otherTrbl.bottom) < 5) {
209
+ addMax(minTrbl, 'bottom', otherTrbl.top + minDimensions.height);
210
+ }
211
+ }
212
+
213
+ if (/w/.test(resizeDirection)) {
214
+
215
+ if (!isHorizontalLane && otherTrbl.left < (laneTrbl.left - 10)) {
216
+ isFirst = false;
217
+ }
218
+
219
+ // max left size (based on next element)
220
+ if (balanced && abs(laneTrbl.left - otherTrbl.right) < 10) {
221
+ addMax(maxTrbl, 'left', otherTrbl.left + minDimensions.width);
222
+ }
223
+
224
+ // min left size (based on self or nested element)
225
+ if (abs(laneTrbl.left - otherTrbl.left) < 5) {
226
+ addMin(minTrbl, 'left', otherTrbl.right - minDimensions.width);
227
+ }
228
+ }
229
+ });
230
+
231
+ // max top/bottom/left/right size based on flow nodes
232
+ var flowElements = lanesRoot.children.filter(function(s) {
233
+ return !s.hidden && !s.waypoints && (is(s, 'bpmn:FlowElement') || is(s, 'bpmn:Artifact'));
234
+ });
235
+
236
+ var padding = isHorizontalLane ? LANE_PADDING : VERTICAL_LANE_PADDING;
237
+
238
+ flowElements.forEach(function(flowElement) {
239
+
240
+ var flowElementTrbl = asTRBL(flowElement);
241
+
242
+ if (isFirst && /n/.test(resizeDirection)) {
243
+ addMin(minTrbl, 'top', flowElementTrbl.top - padding.top);
244
+ }
245
+
246
+ if (isLast && /e/.test(resizeDirection)) {
247
+ addMax(minTrbl, 'right', flowElementTrbl.right + padding.right);
248
+ }
249
+
250
+ if (isLast && /s/.test(resizeDirection)) {
251
+ addMax(minTrbl, 'bottom', flowElementTrbl.bottom + padding.bottom);
252
+ }
253
+
254
+ if (isFirst && /w/.test(resizeDirection)) {
255
+ addMin(minTrbl, 'left', flowElementTrbl.left - padding.left);
256
+ }
257
+ });
258
+
259
+ return {
260
+ min: minTrbl,
261
+ max: maxTrbl
262
+ };
211
263
  }