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.
@@ -1,139 +1,207 @@
1
- import { forEach } from 'min-dash';
2
-
3
- import { is } from '../../../util/ModelUtil';
4
-
5
- import { isExpanded } from '../../../util/DiUtil';
6
-
7
- import {
8
- GROUP_MIN_DIMENSIONS,
9
- LANE_MIN_DIMENSIONS,
10
- PARTICIPANT_MIN_DIMENSIONS,
11
- SUB_PROCESS_MIN_DIMENSIONS,
12
- TEXT_ANNOTATION_MIN_DIMENSIONS
13
- } from './ResizeBehavior';
14
-
15
- import { getChildLanes } from '../util/LaneUtil';
16
-
17
- /**
18
- * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
19
- *
20
- * @typedef {import('../../../model/Types').Shape} Shape
21
- */
22
-
23
- var max = Math.max;
24
-
25
- /**
26
- * @param {EventBus} eventBus
27
- */
28
- export default function SpaceToolBehavior(eventBus) {
29
- eventBus.on('spaceTool.getMinDimensions', function(context) {
30
- var shapes = context.shapes,
31
- axis = context.axis,
32
- start = context.start,
33
- minDimensions = {};
34
-
35
- forEach(shapes, function(shape) {
36
- var id = shape.id;
37
-
38
- if (is(shape, 'bpmn:Participant')) {
39
-
40
- if (isHorizontal(axis)) {
41
- minDimensions[ id ] = PARTICIPANT_MIN_DIMENSIONS;
42
- } else {
43
- minDimensions[ id ] = {
44
- width: PARTICIPANT_MIN_DIMENSIONS.width,
45
- height: getParticipantMinHeight(shape, start)
46
- };
47
- }
48
-
49
- }
50
-
51
- if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
52
- minDimensions[ id ] = SUB_PROCESS_MIN_DIMENSIONS;
53
- }
54
-
55
- if (is(shape, 'bpmn:TextAnnotation')) {
56
- minDimensions[ id ] = TEXT_ANNOTATION_MIN_DIMENSIONS;
57
- }
58
-
59
- if (is(shape, 'bpmn:Group')) {
60
- minDimensions[ id ] = GROUP_MIN_DIMENSIONS;
61
- }
62
- });
63
-
64
- return minDimensions;
65
- });
66
- }
67
-
68
- SpaceToolBehavior.$inject = [ 'eventBus' ];
69
-
70
-
71
- // helpers //////////
72
- function isHorizontal(axis) {
73
- return axis === 'x';
74
- }
75
-
76
- /**
77
- * Get minimum height for participant taking lanes into account.
78
- *
79
- * @param {Shape} participant
80
- * @param {number} start
81
- *
82
- * @return {number}
83
- */
84
- function getParticipantMinHeight(participant, start) {
85
- var lanesMinHeight;
86
-
87
- if (!hasChildLanes(participant)) {
88
- return PARTICIPANT_MIN_DIMENSIONS.height;
89
- }
90
-
91
- lanesMinHeight = getLanesMinHeight(participant, start);
92
-
93
- return max(PARTICIPANT_MIN_DIMENSIONS.height, lanesMinHeight);
94
- }
95
-
96
- function hasChildLanes(element) {
97
- return !!getChildLanes(element).length;
98
- }
99
-
100
- function getLanesMinHeight(participant, resizeStart) {
101
- var lanes = getChildLanes(participant),
102
- resizedLane;
103
-
104
- // find the nested lane which is currently resized
105
- resizedLane = findResizedLane(lanes, resizeStart);
106
-
107
- // resized lane cannot shrink below the minimum height
108
- // but remaining lanes' dimensions are kept intact
109
- return participant.height - resizedLane.height + LANE_MIN_DIMENSIONS.height;
110
- }
111
-
112
- /**
113
- * Find nested lane which is currently resized.
114
- *
115
- * @param {Shape[]} lanes
116
- * @param {number} resizeStart
117
- *
118
- * @return {Shape}
119
- */
120
- function findResizedLane(lanes, resizeStart) {
121
- var i, lane, childLanes;
122
-
123
- for (i = 0; i < lanes.length; i++) {
124
- lane = lanes[i];
125
-
126
- // resizing current lane or a lane nested
127
- if (resizeStart >= lane.y && resizeStart <= lane.y + lane.height) {
128
- childLanes = getChildLanes(lane);
129
-
130
- // a nested lane is resized
131
- if (childLanes.length) {
132
- return findResizedLane(childLanes, resizeStart);
133
- }
134
-
135
- // current lane is the resized one
136
- return lane;
137
- }
138
- }
139
- }
1
+ import { forEach } from 'min-dash';
2
+
3
+ import { is } from '../../../util/ModelUtil';
4
+
5
+ import {
6
+ isExpanded,
7
+ isHorizontal
8
+ } from '../../../util/DiUtil';
9
+
10
+ import {
11
+ GROUP_MIN_DIMENSIONS,
12
+ LANE_MIN_DIMENSIONS,
13
+ VERTICAL_LANE_MIN_DIMENSIONS,
14
+ PARTICIPANT_MIN_DIMENSIONS,
15
+ VERTICAL_PARTICIPANT_MIN_DIMENSIONS,
16
+ SUB_PROCESS_MIN_DIMENSIONS,
17
+ TEXT_ANNOTATION_MIN_DIMENSIONS
18
+ } from './ResizeBehavior';
19
+
20
+ import { getChildLanes } from '../util/LaneUtil';
21
+
22
+ /**
23
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
24
+ *
25
+ * @typedef {import('../../../model/Types').Shape} Shape
26
+ */
27
+
28
+ var max = Math.max;
29
+
30
+ /**
31
+ * @param {EventBus} eventBus
32
+ */
33
+ export default function SpaceToolBehavior(eventBus) {
34
+ eventBus.on('spaceTool.getMinDimensions', function(context) {
35
+ var shapes = context.shapes,
36
+ axis = context.axis,
37
+ start = context.start,
38
+ minDimensions = {};
39
+
40
+ forEach(shapes, function(shape) {
41
+ var id = shape.id;
42
+
43
+ if (is(shape, 'bpmn:Participant')) {
44
+ minDimensions[ id ] = getParticipantMinDimensions(shape, axis, start);
45
+ }
46
+
47
+ if (is(shape, 'bpmn:Lane')) {
48
+ minDimensions[ id ] = isHorizontal(shape) ? LANE_MIN_DIMENSIONS : VERTICAL_LANE_MIN_DIMENSIONS;
49
+ }
50
+
51
+ if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
52
+ minDimensions[ id ] = SUB_PROCESS_MIN_DIMENSIONS;
53
+ }
54
+
55
+ if (is(shape, 'bpmn:TextAnnotation')) {
56
+ minDimensions[ id ] = TEXT_ANNOTATION_MIN_DIMENSIONS;
57
+ }
58
+
59
+ if (is(shape, 'bpmn:Group')) {
60
+ minDimensions[ id ] = GROUP_MIN_DIMENSIONS;
61
+ }
62
+ });
63
+
64
+ return minDimensions;
65
+ });
66
+ }
67
+
68
+ SpaceToolBehavior.$inject = [ 'eventBus' ];
69
+
70
+
71
+ // helpers //////////
72
+ function isHorizontalAxis(axis) {
73
+ return axis === 'x';
74
+ }
75
+
76
+ /**
77
+ * Get minimum dimensions for participant taking lanes into account.
78
+ *
79
+ * @param {Shape} participant
80
+ * @param {Axis} axis
81
+ * @param {number} start
82
+ *
83
+ * @return {number}
84
+ */
85
+ function getParticipantMinDimensions(participant, axis, start) {
86
+ var isHorizontalLane = isHorizontal(participant);
87
+
88
+ if (!hasChildLanes(participant)) {
89
+ return isHorizontalLane ? PARTICIPANT_MIN_DIMENSIONS : VERTICAL_PARTICIPANT_MIN_DIMENSIONS;
90
+ }
91
+
92
+ var isHorizontalResize = isHorizontalAxis(axis);
93
+ var minDimensions = {};
94
+
95
+ if (isHorizontalResize) {
96
+ if (isHorizontalLane) {
97
+ minDimensions = PARTICIPANT_MIN_DIMENSIONS;
98
+ } else {
99
+ minDimensions = {
100
+ width: getParticipantMinWidth(participant, start, isHorizontalResize),
101
+ height: VERTICAL_PARTICIPANT_MIN_DIMENSIONS.height
102
+ };
103
+ }
104
+
105
+ } else {
106
+ if (isHorizontalLane) {
107
+ minDimensions = {
108
+ width: PARTICIPANT_MIN_DIMENSIONS.width,
109
+ height: getParticipantMinHeight(participant, start, isHorizontalResize)
110
+ };
111
+ } else {
112
+ minDimensions = VERTICAL_PARTICIPANT_MIN_DIMENSIONS;
113
+ }
114
+ }
115
+
116
+ return minDimensions;
117
+ }
118
+
119
+ /**
120
+ * Get minimum height for participant taking lanes into account.
121
+ *
122
+ * @param {Shape} participant
123
+ * @param {number} start
124
+ * @param {boolean} isHorizontalResize
125
+ *
126
+ * @return {number}
127
+ */
128
+ function getParticipantMinHeight(participant, start, isHorizontalResize) {
129
+ var lanesMinHeight;
130
+ lanesMinHeight = getLanesMinHeight(participant, start, isHorizontalResize);
131
+ return max(PARTICIPANT_MIN_DIMENSIONS.height, lanesMinHeight);
132
+ }
133
+
134
+ /**
135
+ * Get minimum width for participant taking lanes into account.
136
+ *
137
+ * @param {Shape} participant
138
+ * @param {number} start
139
+ * @param {boolean} isHorizontalResize
140
+ *
141
+ * @return {number}
142
+ */
143
+ function getParticipantMinWidth(participant, start, isHorizontalResize) {
144
+ var lanesMinWidth;
145
+ lanesMinWidth = getLanesMinWidth(participant, start, isHorizontalResize);
146
+ return max(VERTICAL_PARTICIPANT_MIN_DIMENSIONS.width, lanesMinWidth);
147
+ }
148
+
149
+ function hasChildLanes(element) {
150
+ return !!getChildLanes(element).length;
151
+ }
152
+
153
+ function getLanesMinHeight(participant, resizeStart, isHorizontalResize) {
154
+ var lanes = getChildLanes(participant),
155
+ resizedLane;
156
+
157
+ // find the nested lane which is currently resized
158
+ resizedLane = findResizedLane(lanes, resizeStart, isHorizontalResize);
159
+
160
+ // resized lane cannot shrink below the minimum height
161
+ // but remaining lanes' dimensions are kept intact
162
+ return participant.height - resizedLane.height + LANE_MIN_DIMENSIONS.height;
163
+ }
164
+
165
+ function getLanesMinWidth(participant, resizeStart, isHorizontalResize) {
166
+ var lanes = getChildLanes(participant),
167
+ resizedLane;
168
+
169
+ // find the nested lane which is currently resized
170
+ resizedLane = findResizedLane(lanes, resizeStart, isHorizontalResize);
171
+
172
+ // resized lane cannot shrink below the minimum width
173
+ // but remaining lanes' dimensions are kept intact
174
+ return participant.width - resizedLane.width + VERTICAL_LANE_MIN_DIMENSIONS.width;
175
+ }
176
+
177
+ /**
178
+ * Find nested lane which is currently resized.
179
+ *
180
+ * @param {Shape[]} lanes
181
+ * @param {number} resizeStart
182
+ * @param {boolean} isHorizontalResize
183
+ *
184
+ * @return {Shape}
185
+ */
186
+ function findResizedLane(lanes, resizeStart, isHorizontalResize) {
187
+ var i, lane, childLanes;
188
+
189
+ for (i = 0; i < lanes.length; i++) {
190
+ lane = lanes[i];
191
+
192
+ // resizing current lane or a lane nested
193
+ if (!isHorizontalResize && resizeStart >= lane.y && resizeStart <= lane.y + lane.height ||
194
+ isHorizontalResize && resizeStart >= lane.x && resizeStart <= lane.x + lane.width) {
195
+
196
+ childLanes = getChildLanes(lane);
197
+
198
+ // a nested lane is resized
199
+ if (childLanes.length) {
200
+ return findResizedLane(childLanes, resizeStart, isHorizontalResize);
201
+ }
202
+
203
+ // current lane is the resized one
204
+ return lane;
205
+ }
206
+ }
207
+ }
@@ -0,0 +1,6 @@
1
+ export default class TextAnnotationBehavior extends CommandInterceptor {
2
+ constructor(eventBus: any);
3
+ }
4
+
5
+ type EventBus = import('diagram-js/lib/core/EventBus').default;
6
+ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
@@ -0,0 +1,43 @@
1
+ import inherits from 'inherits-browser';
2
+
3
+ import { is } from '../../../util/ModelUtil';
4
+
5
+ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
6
+
7
+ /**
8
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
9
+ */
10
+
11
+ export default function TextAnnotationBehavior(eventBus) {
12
+
13
+ CommandInterceptor.call(this, eventBus);
14
+
15
+ // On Append, TextAnnotations will be created on the Root.
16
+ // The default for connections will create the connection in the parent of
17
+ // the source element, so we overwrite the parent here.
18
+ this.preExecute('connection.create', function(context) {
19
+ const { target } = context;
20
+
21
+ if (!is(target, 'bpmn:TextAnnotation')) {
22
+ return;
23
+ }
24
+
25
+ context.parent = target.parent;
26
+ }, true);
27
+
28
+ this.preExecute([ 'shape.create', 'shape.resize', 'elements.move' ], function(context) {
29
+ const shapes = context.shapes || [ context.shape ];
30
+
31
+ if (shapes.length === 1 && is(shapes[0], 'bpmn:TextAnnotation')) {
32
+ context.hints = context.hints || {};
33
+
34
+ context.hints.autoResize = false;
35
+ }
36
+ }, true);
37
+ }
38
+
39
+ inherits(TextAnnotationBehavior, CommandInterceptor);
40
+
41
+ TextAnnotationBehavior.$inject = [
42
+ 'eventBus'
43
+ ];
@@ -32,6 +32,7 @@ import RootElementReferenceBehavior from './RootElementReferenceBehavior';
32
32
  import SpaceToolBehavior from './SpaceToolBehavior';
33
33
  import SubProcessPlaneBehavior from './SubProcessPlaneBehavior';
34
34
  import SubProcessStartEventBehavior from './SubProcessStartEventBehavior';
35
+ import TextAnnotationBehavior from './TextAnnotationBehavior';
35
36
  import ToggleCollapseConnectionBehaviour from './ToggleCollapseConnectionBehaviour';
36
37
  import ToggleElementCollapseBehaviour from './ToggleElementCollapseBehaviour';
37
38
  import UnclaimIdBehavior from './UnclaimIdBehavior';
@@ -77,6 +78,7 @@ export default {
77
78
  'spaceToolBehavior',
78
79
  'subProcessPlaneBehavior',
79
80
  'subProcessStartEventBehavior',
81
+ 'textAnnotationBehavior',
80
82
  'toggleCollapseConnectionBehaviour',
81
83
  'toggleElementCollapseBehaviour',
82
84
  'unclaimIdBehavior',
@@ -117,6 +119,7 @@ export default {
117
119
  spaceToolBehavior: [ 'type', SpaceToolBehavior ],
118
120
  subProcessPlaneBehavior: [ 'type', SubProcessPlaneBehavior ],
119
121
  subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ],
122
+ textAnnotationBehavior: [ 'type', TextAnnotationBehavior ],
120
123
  toggleCollapseConnectionBehaviour: [ 'type', ToggleCollapseConnectionBehaviour ],
121
124
  toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
122
125
  unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
@@ -4,6 +4,10 @@ import {
4
4
  getParent
5
5
  } from './ModelingUtil';
6
6
 
7
+ import {
8
+ isHorizontal
9
+ } from '../../../util/DiUtil';
10
+
7
11
  import {
8
12
  asTRBL
9
13
  } from 'diagram-js/lib/layout/LayoutUtil';
@@ -111,16 +115,18 @@ export function computeLanesResize(shape, newBounds) {
111
115
  trblResize = getTRBLResize(shape, newBounds),
112
116
  resizeNeeded = [];
113
117
 
118
+ var isHorizontalLane = isHorizontal(shape);
119
+
114
120
  allLanes.forEach(function(other) {
115
121
 
116
122
  if (other === shape) {
117
123
  return;
118
124
  }
119
125
 
120
- var topResize = 0,
121
- rightResize = trblResize.right,
122
- bottomResize = 0,
123
- leftResize = trblResize.left;
126
+ var topResize = isHorizontalLane ? 0 : trblResize.top,
127
+ rightResize = isHorizontalLane ? trblResize.right : 0,
128
+ bottomResize = isHorizontalLane ? 0 : trblResize.bottom,
129
+ leftResize = isHorizontalLane ? trblResize.left : 0;
124
130
 
125
131
  var otherTrbl = asTRBL(other);
126
132
 
@@ -134,6 +140,16 @@ export function computeLanesResize(shape, newBounds) {
134
140
  }
135
141
  }
136
142
 
143
+ if (trblResize.left) {
144
+ if (abs(otherTrbl.right - shapeTrbl.left) < 10) {
145
+ rightResize = shapeNewTrbl.left - otherTrbl.right;
146
+ }
147
+
148
+ if (abs(otherTrbl.left - shapeTrbl.left) < 5) {
149
+ leftResize = shapeNewTrbl.left - otherTrbl.left;
150
+ }
151
+ }
152
+
137
153
  if (trblResize.bottom) {
138
154
  if (abs(otherTrbl.top - shapeTrbl.bottom) < 10) {
139
155
  topResize = shapeNewTrbl.bottom - otherTrbl.top;
@@ -144,6 +160,16 @@ export function computeLanesResize(shape, newBounds) {
144
160
  }
145
161
  }
146
162
 
163
+ if (trblResize.right) {
164
+ if (abs(otherTrbl.left - shapeTrbl.right) < 10) {
165
+ leftResize = shapeNewTrbl.right - otherTrbl.left;
166
+ }
167
+
168
+ if (abs(otherTrbl.right - shapeTrbl.right) < 5) {
169
+ rightResize = shapeNewTrbl.right - otherTrbl.right;
170
+ }
171
+ }
172
+
147
173
  if (topResize || rightResize || bottomResize || leftResize) {
148
174
 
149
175
  resizeNeeded.push({
@@ -3,6 +3,7 @@ import inherits from 'inherits-browser';
3
3
  import OrderingProvider from 'diagram-js/lib/features/ordering/OrderingProvider';
4
4
 
5
5
  import {
6
+ is,
6
7
  isAny
7
8
  } from '../modeling/util/ModelingUtil';
8
9
 
@@ -54,6 +55,12 @@ export default function BpmnOrderingProvider(eventBus, canvas, translate) {
54
55
  ]
55
56
  }
56
57
  },
58
+ {
59
+ type: 'bpmn:TextAnnotation',
60
+ order: {
61
+ level: 9
62
+ }
63
+ },
57
64
  {
58
65
  type: 'bpmn:MessageFlow', order: {
59
66
  level: 9,
@@ -136,8 +143,8 @@ export default function BpmnOrderingProvider(eventBus, canvas, translate) {
136
143
 
137
144
  this.getOrdering = function(element, newParent) {
138
145
 
139
- // render labels always on top
140
- if (element.labelTarget) {
146
+ // render labels and text annotations always on top
147
+ if (element.labelTarget || is(element, 'bpmn:TextAnnotation')) {
141
148
  return {
142
149
  parent: canvas.findRoot(newParent) || canvas.getRootElement(),
143
150
  index: -1
@@ -2,8 +2,6 @@ import {
2
2
  assign
3
3
  } from 'min-dash';
4
4
 
5
- import { getDi } from '../../util/ModelUtil';
6
-
7
5
  /**
8
6
  * @typedef {import('diagram-js/lib/features/palette/Palette').default} Palette
9
7
  * @typedef {import('diagram-js/lib/features/create/Create').default} Create
@@ -75,12 +73,6 @@ PaletteProvider.prototype.getPaletteEntries = function() {
75
73
 
76
74
  function createListener(event) {
77
75
  var shape = elementFactory.createShape(assign({ type: type }, options));
78
-
79
- if (options) {
80
- var di = getDi(shape);
81
- di.isExpanded = options.isExpanded;
82
- }
83
-
84
76
  create.start(event, shape);
85
77
  }
86
78
 
@@ -180,7 +172,8 @@ PaletteProvider.prototype.getPaletteEntries = function() {
180
172
  ),
181
173
  'create.exclusive-gateway': createAction(
182
174
  'bpmn:ExclusiveGateway', 'gateway', 'bpmn-icon-gateway-none',
183
- translate('Create gateway')
175
+ translate('Create gateway'),
176
+ { isMarkerVisible: true }
184
177
  ),
185
178
  'create.task': createAction(
186
179
  'bpmn:Task', 'activity', 'bpmn-icon-task',
@@ -162,6 +162,10 @@ export default function BpmnReplace(
162
162
 
163
163
  newElement.di = {};
164
164
 
165
+ if (type === 'bpmn:ExclusiveGateway') {
166
+ newElement.di.isMarkerVisible = true;
167
+ }
168
+
165
169
  // colors will be set to DI
166
170
  copyProperties(element.di, newElement.di, [
167
171
  'fill',
@@ -984,11 +984,11 @@ function canResize(shape, newBounds) {
984
984
  }
985
985
 
986
986
  if (is(shape, 'bpmn:Lane')) {
987
- return !newBounds || (newBounds.width >= 130 && newBounds.height >= 60);
987
+ return true;
988
988
  }
989
989
 
990
990
  if (is(shape, 'bpmn:Participant')) {
991
- return !newBounds || (newBounds.width >= 250 && newBounds.height >= 50);
991
+ return true;
992
992
  }
993
993
 
994
994
  if (isTextAnnotation(shape)) {
@@ -4,6 +4,8 @@ import SpaceTool from 'diagram-js/lib/features/space-tool/SpaceTool';
4
4
 
5
5
  import { getBusinessObject, is } from '../../util/ModelUtil';
6
6
 
7
+ import { isHorizontal } from '../../util/DiUtil';
8
+
7
9
  /**
8
10
  * @typedef {import('didi').Injector} Injector
9
11
  *
@@ -40,15 +42,18 @@ BpmnSpaceTool.prototype.calculateAdjustments = function(elements, axis, delta, s
40
42
  // do not resize:
41
43
  //
42
44
  // * text annotations (horizontally/vertically)
43
- // * empty pools (vertically)
45
+ // * empty horizontal pools (vertically)
46
+ // * empty vertical pools (horizontally)
44
47
  adjustments.resizingShapes = adjustments.resizingShapes.filter(function(shape) {
45
48
 
46
49
  if (is(shape, 'bpmn:TextAnnotation')) {
47
50
  return false;
48
51
  }
49
52
 
50
- if (axis === 'y' && isCollapsedPool(shape)) {
51
- return false;
53
+ if (isCollapsedPool(shape)) {
54
+ if (axis === 'y' && isHorizontal(shape) || axis === 'x' && !isHorizontal(shape)) {
55
+ return false;
56
+ }
52
57
  }
53
58
 
54
59
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-js",
3
- "version": "16.3.2",
3
+ "version": "16.4.0",
4
4
  "description": "A bpmn 2.0 toolkit and web modeler",
5
5
  "main": "index.js",
6
6
  "files": [