bpmn-js 13.0.2 → 13.0.3

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.
@@ -15,7 +15,7 @@ import {
15
15
 
16
16
  import {
17
17
  getLabel
18
- } from '../features/label-editing/LabelUtil';
18
+ } from '../util/LabelUtil';
19
19
 
20
20
  import { is } from '../util/ModelUtil';
21
21
 
@@ -4,7 +4,7 @@ import {
4
4
 
5
5
  import {
6
6
  getLabel
7
- } from './LabelUtil';
7
+ } from '../../util/LabelUtil';
8
8
 
9
9
  import {
10
10
  is
@@ -1,14 +1 @@
1
- /**
2
- * @param element
3
- *
4
- * @return label
5
- */
6
- export function getLabel(element: any): string;
7
- /**
8
- * @param element
9
- * @param text
10
- *
11
- * @return element
12
- */
13
- export function setLabel(element: any, text: string): any;
14
- export type DiagramElement = any;
1
+ export { getLabel, setLabel } from "../../util/LabelUtil";
@@ -1,82 +1,4 @@
1
- import { is } from '../../util/ModelUtil';
2
-
3
- /**
4
- * @typedef { import('../../model').DiagramElement } DiagramElement
5
- */
6
-
7
- function getLabelAttr(semantic) {
8
- if (
9
- is(semantic, 'bpmn:FlowElement') ||
10
- is(semantic, 'bpmn:Participant') ||
11
- is(semantic, 'bpmn:Lane') ||
12
- is(semantic, 'bpmn:SequenceFlow') ||
13
- is(semantic, 'bpmn:MessageFlow') ||
14
- is(semantic, 'bpmn:DataInput') ||
15
- is(semantic, 'bpmn:DataOutput')
16
- ) {
17
- return 'name';
18
- }
19
-
20
- if (is(semantic, 'bpmn:TextAnnotation')) {
21
- return 'text';
22
- }
23
-
24
- if (is(semantic, 'bpmn:Group')) {
25
- return 'categoryValueRef';
26
- }
27
- }
28
-
29
- function getCategoryValue(semantic) {
30
- var categoryValueRef = semantic['categoryValueRef'];
31
-
32
- if (!categoryValueRef) {
33
- return '';
34
- }
35
-
36
-
37
- return categoryValueRef.value || '';
38
- }
39
-
40
- /**
41
- * @param {DiagramElement} element
42
- *
43
- * @return {string} label
44
- */
45
- export function getLabel(element) {
46
- var semantic = element.businessObject,
47
- attr = getLabelAttr(semantic);
48
-
49
- if (attr) {
50
-
51
- if (attr === 'categoryValueRef') {
52
-
53
- return getCategoryValue(semantic);
54
- }
55
-
56
- return semantic[attr] || '';
57
- }
58
- }
59
-
60
-
61
- /**
62
- * @param {DiagramElement} element
63
- * @param {string} text
64
- *
65
- * @return {DiagramElement} element
66
- */
67
- export function setLabel(element, text) {
68
- var semantic = element.businessObject,
69
- attr = getLabelAttr(semantic);
70
-
71
- if (attr) {
72
-
73
- if (attr === 'categoryValueRef') {
74
- semantic['categoryValueRef'].value = text;
75
- } else {
76
- semantic[attr] = text;
77
- }
78
-
79
- }
80
-
81
- return element;
82
- }
1
+ export {
2
+ getLabel,
3
+ setLabel
4
+ } from '../../util/LabelUtil';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  setLabel,
3
3
  getLabel
4
- } from '../LabelUtil';
4
+ } from '../../../util/LabelUtil';
5
5
 
6
6
  import {
7
7
  getExternalLabelMid,
@@ -11,7 +11,6 @@ import {
11
11
  } from '../../../util/LabelUtil';
12
12
 
13
13
  import {
14
- getDi,
15
14
  is
16
15
  } from '../../../util/ModelUtil';
17
16
 
@@ -37,29 +36,6 @@ var NULL_DIMENSIONS = {
37
36
  */
38
37
  export default function UpdateLabelHandler(modeling, textRenderer, bpmnFactory) {
39
38
 
40
- /**
41
- * Creates an empty `diLabel` attribute for embedded labels.
42
- *
43
- * @param {Element} element
44
- * @param {string} text
45
- */
46
- function ensureInternalLabelDi(element, text) {
47
- if (isLabelExternal(element)) {
48
- return;
49
- }
50
-
51
- var di = getDi(element);
52
-
53
- if (text && !di.label) {
54
- di.label = bpmnFactory.create('bpmndi:BPMNLabel');
55
- }
56
-
57
- if (!text && di.label) {
58
- delete di.label;
59
- }
60
- }
61
-
62
-
63
39
  /**
64
40
  * Set the label and return the changed elements.
65
41
  *
@@ -77,8 +53,6 @@ export default function UpdateLabelHandler(modeling, textRenderer, bpmnFactory)
77
53
 
78
54
  setLabel(label, text, labelTarget !== label);
79
55
 
80
- ensureInternalLabelDi(element, text);
81
-
82
56
  return [ label, labelTarget ];
83
57
  }
84
58
 
@@ -140,7 +114,7 @@ export default function UpdateLabelHandler(modeling, textRenderer, bpmnFactory)
140
114
  return;
141
115
  }
142
116
 
143
- var text = getLabel(label);
117
+ var text = getLabel(element);
144
118
 
145
119
  // resize element based on label _or_ pre-defined bounds
146
120
  if (typeof newBounds === 'undefined') {
@@ -18,7 +18,11 @@ import {
18
18
 
19
19
  import { isAny } from './util/ModelingUtil';
20
20
 
21
- import { isLabel } from '../../util/LabelUtil';
21
+ import {
22
+ getLabel,
23
+ isLabel,
24
+ isLabelExternal
25
+ } from '../../util/LabelUtil';
22
26
 
23
27
  import { delta } from 'diagram-js/lib/util/PositionUtil';
24
28
 
@@ -287,6 +291,28 @@ export default function BpmnUpdater(
287
291
 
288
292
  this.executed([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
289
293
  this.reverted([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
294
+
295
+
296
+ // update BPMNLabel
297
+ this.executed('element.updateLabel', ifBpmn(updateBPMNLabel));
298
+ this.reverted('element.updateLabel', ifBpmn(updateBPMNLabel));
299
+
300
+ function updateBPMNLabel(event) {
301
+ const { element } = event.context,
302
+ label = getLabel(element);
303
+ const di = getDi(element),
304
+ diLabel = di && di.get('label');
305
+
306
+ if (isLabelExternal(element)) {
307
+ return;
308
+ }
309
+
310
+ if (label && !diLabel) {
311
+ di.set('label', bpmnFactory.create('bpmndi:BPMNLabel'));
312
+ } else if (!label && diLabel) {
313
+ di.set('label', undefined);
314
+ }
315
+ }
290
316
  }
291
317
 
292
318
  inherits(BpmnUpdater, CommandInterceptor);
@@ -787,7 +813,7 @@ function ifBpmn(fn) {
787
813
  return function(event) {
788
814
 
789
815
  var context = event.context,
790
- element = context.shape || context.connection;
816
+ element = context.shape || context.connection || context.element;
791
817
 
792
818
  if (is(element, 'bpmn:BaseElement')) {
793
819
  fn(event);
@@ -6,21 +6,16 @@ import inherits from 'inherits-browser';
6
6
 
7
7
  import {
8
8
  is,
9
- getBusinessObject,
10
- getDi
9
+ getBusinessObject
11
10
  } from '../../../util/ModelUtil';
12
11
 
13
12
  import {
14
13
  isLabelExternal,
15
- getExternalLabelMid,
14
+ getLabel,
16
15
  hasExternalLabel,
17
16
  isLabel
18
17
  } from '../../../util/LabelUtil';
19
18
 
20
- import {
21
- getLabel
22
- } from '../../label-editing/LabelUtil';
23
-
24
19
  import {
25
20
  getLabelAdjustment
26
21
  } from './util/LabelLayoutUtil';
@@ -49,11 +44,6 @@ import {
49
44
  perpendicularFoot
50
45
  } from './util/GeometricUtil';
51
46
 
52
- var DEFAULT_LABEL_DIMENSIONS = {
53
- width: 90,
54
- height: 20
55
- };
56
-
57
47
  var NAME_PROPERTY = 'name';
58
48
  var TEXT_PROPERTY = 'text';
59
49
 
@@ -86,7 +76,16 @@ export default function LabelBehavior(
86
76
  CommandInterceptor.call(this, eventBus);
87
77
 
88
78
  // update label if name property was updated
89
- this.postExecute('element.updateProperties', function(e) {
79
+ this.postExecute('element.updateProperties', onPropertyUpdate);
80
+ this.postExecute('element.updateModdleProperties', e => {
81
+ const elementBo = getBusinessObject(e.context.element);
82
+
83
+ if (elementBo === e.context.moddleElement) {
84
+ onPropertyUpdate(e);
85
+ }
86
+ });
87
+
88
+ function onPropertyUpdate(e) {
90
89
  var context = e.context,
91
90
  element = context.element,
92
91
  properties = context.properties;
@@ -110,7 +109,7 @@ export default function LabelBehavior(
110
109
 
111
110
  modeling.updateLabel(element, properties.text, newBounds);
112
111
  }
113
- });
112
+ }
114
113
 
115
114
  // create label shape after shape/connection was created
116
115
  this.postExecute([ 'shape.create', 'connection.create' ], function(e) {
@@ -121,8 +120,7 @@ export default function LabelBehavior(
121
120
  return;
122
121
  }
123
122
 
124
- var element = context.shape || context.connection,
125
- businessObject = element.businessObject;
123
+ var element = context.shape || context.connection;
126
124
 
127
125
  if (isLabel(element) || !isLabelExternal(element)) {
128
126
  return;
@@ -133,20 +131,7 @@ export default function LabelBehavior(
133
131
  return;
134
132
  }
135
133
 
136
- var labelCenter = getExternalLabelMid(element);
137
-
138
- // we don't care about x and y
139
- var labelDimensions = textRenderer.getExternalLabelBounds(
140
- DEFAULT_LABEL_DIMENSIONS,
141
- getLabel(element)
142
- );
143
-
144
- modeling.createLabel(element, labelCenter, {
145
- id: businessObject.id + '_label',
146
- businessObject: businessObject,
147
- width: labelDimensions.width,
148
- height: labelDimensions.height
149
- });
134
+ modeling.updateLabel(element, getLabel(element));
150
135
  });
151
136
 
152
137
  // update label after label shape was deleted
@@ -161,42 +146,6 @@ export default function LabelBehavior(
161
146
  }
162
147
  });
163
148
 
164
- // update di information on label creation
165
- this.postExecute([ 'label.create' ], function(event) {
166
-
167
- var context = event.context,
168
- element = context.shape,
169
- labelTarget = context.labelTarget,
170
- di;
171
-
172
- // we want to trigger on real labels only
173
- if (!labelTarget) {
174
- return;
175
- }
176
-
177
- // we want to trigger on BPMN elements only
178
- if (!is(labelTarget, 'bpmn:BaseElement')) {
179
- return;
180
- }
181
-
182
- di = getDi(labelTarget);
183
-
184
- if (!di.label) {
185
- di.label = bpmnFactory.create('bpmndi:BPMNLabel', {
186
- bounds: bpmnFactory.create('dc:Bounds')
187
- });
188
-
189
- element.di = di;
190
- }
191
-
192
- assign(di.label.bounds, {
193
- x: element.x,
194
- y: element.y,
195
- width: element.width,
196
- height: element.height
197
- });
198
- });
199
-
200
149
  function getVisibleLabelAdjustment(event) {
201
150
 
202
151
  var context = event.context,
@@ -6,7 +6,7 @@ import {
6
6
 
7
7
  import {
8
8
  getLabel
9
- } from '../label-editing/LabelUtil';
9
+ } from '../../util/LabelUtil';
10
10
 
11
11
  /**
12
12
  * @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
@@ -6,7 +6,8 @@ import { is } from '../util/ModelUtil';
6
6
 
7
7
  import {
8
8
  isLabelExternal,
9
- getExternalLabelBounds
9
+ getExternalLabelBounds,
10
+ getLabel
10
11
  } from '../util/LabelUtil';
11
12
 
12
13
  import {
@@ -17,10 +18,6 @@ import {
17
18
  isExpanded
18
19
  } from '../util/DiUtil';
19
20
 
20
- import {
21
- getLabel
22
- } from '../features/label-editing/LabelUtil';
23
-
24
21
  import {
25
22
  elementToString
26
23
  } from './Util';
@@ -61,12 +61,28 @@ export function getExternalLabelBounds(di: ModdleElement, element: Element): Rec
61
61
  */
62
62
  export function isLabel(element: Element): boolean;
63
63
 
64
+ /**
65
+ * @param element
66
+ *
67
+ * @return label
68
+ */
69
+ export function getLabel(element: any): string;
70
+
71
+ /**
72
+ * @param element
73
+ * @param text
74
+ *
75
+ * @return element
76
+ */
77
+ export function setLabel(element: any, text: string): any;
78
+
64
79
  export namespace DEFAULT_LABEL_SIZE {
65
80
  const width: number;
66
81
  const height: number;
67
82
  }
68
83
 
69
84
  export const FLOW_LABEL_INDENT: number;
85
+ export type DiagramElement = any;
70
86
  type Point = import('diagram-js/lib/util/Types').Point;
71
87
  type Rect = import('diagram-js/lib/util/Types').Rect;
72
88
  type Element = import('../model/Types').Element;
@@ -178,3 +178,85 @@ export function getExternalLabelBounds(di, element) {
178
178
  export function isLabel(element) {
179
179
  return element && !!element.labelTarget;
180
180
  }
181
+
182
+
183
+ /**
184
+ * @typedef { import('../model').DiagramElement } DiagramElement
185
+ */
186
+
187
+ function getLabelAttr(semantic) {
188
+ if (
189
+ is(semantic, 'bpmn:FlowElement') ||
190
+ is(semantic, 'bpmn:Participant') ||
191
+ is(semantic, 'bpmn:Lane') ||
192
+ is(semantic, 'bpmn:SequenceFlow') ||
193
+ is(semantic, 'bpmn:MessageFlow') ||
194
+ is(semantic, 'bpmn:DataInput') ||
195
+ is(semantic, 'bpmn:DataOutput')
196
+ ) {
197
+ return 'name';
198
+ }
199
+
200
+ if (is(semantic, 'bpmn:TextAnnotation')) {
201
+ return 'text';
202
+ }
203
+
204
+ if (is(semantic, 'bpmn:Group')) {
205
+ return 'categoryValueRef';
206
+ }
207
+ }
208
+
209
+ function getCategoryValue(semantic) {
210
+ var categoryValueRef = semantic['categoryValueRef'];
211
+
212
+ if (!categoryValueRef) {
213
+ return '';
214
+ }
215
+
216
+
217
+ return categoryValueRef.value || '';
218
+ }
219
+
220
+ /**
221
+ * @param {DiagramElement} element
222
+ *
223
+ * @return {string} label
224
+ */
225
+ export function getLabel(element) {
226
+ var semantic = element.businessObject,
227
+ attr = getLabelAttr(semantic);
228
+
229
+ if (attr) {
230
+
231
+ if (attr === 'categoryValueRef') {
232
+
233
+ return getCategoryValue(semantic);
234
+ }
235
+
236
+ return semantic[attr] || '';
237
+ }
238
+ }
239
+
240
+
241
+ /**
242
+ * @param {DiagramElement} element
243
+ * @param {string} text
244
+ *
245
+ * @return {DiagramElement} element
246
+ */
247
+ export function setLabel(element, text) {
248
+ var semantic = element.businessObject,
249
+ attr = getLabelAttr(semantic);
250
+
251
+ if (attr) {
252
+
253
+ if (attr === 'categoryValueRef') {
254
+ semantic['categoryValueRef'].value = text;
255
+ } else {
256
+ semantic[attr] = text;
257
+ }
258
+
259
+ }
260
+
261
+ return element;
262
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-js",
3
- "version": "13.0.2",
3
+ "version": "13.0.3",
4
4
  "description": "A bpmn 2.0 toolkit and web modeler",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -1 +0,0 @@
1
- data:image/svg+xml,data%3Aimage%2Fsvg%2Bxml%2C%253Csvg%2520xmlns%253D%2522http%253A%252F%252Fwww.w3.org%252F2000%252Fsvg%2522%2520width%253D%252222%2522%2520height%253D%252222%2522%2520viewBox%253D%25220%25200%25205.82%25205.82%2522%253E%253Cpath%2520d%253D%2522M1.3%25203.4c.3%25200%2520.5-.2.5-.5s-.2-.4-.5-.4c-.2%25200-.4.1-.4.4%25200%2520.3.2.5.4.5zm1.7%25200c.2%25200%2520.4-.2.4-.5s-.2-.4-.4-.4c-.3%25200-.5.1-.5.4%25200%2520.3.2.5.5.5zm1.6%25200c.2%25200%2520.4-.2.4-.5s-.2-.4-.4-.4c-.3%25200-.5.1-.5.4%25200%2520.3.2.5.5.5z%2522%252F%253E%253C%252Fsvg%253E
@@ -1 +0,0 @@
1
- data:image/svg+xml,data%3Aimage%2Fsvg%2Bxml%2C%253Csvg%2520xmlns%253D%2522http%253A%252F%252Fwww.w3.org%252F2000%252Fsvg%2522%2520viewBox%253D%25220%25200%25202048%25202048%2522%253E%253Cpath%2520d%253D%2522M2013.823%2520158.247%2520995.866%2520525.177l143.206%2520181.698L34.177%25201595.041l136.637%2520158.712%25201104.89-888.123%2520140.894%2520182.578Z%2522%252F%253E%253C%252Fsvg%253E
@@ -1 +0,0 @@
1
- data:image/svg+xml,data%3Aimage%2Fsvg%2Bxml%2C%253Csvg%2520xmlns%253D%2522http%253A%252F%252Fwww.w3.org%252F2000%252Fsvg%2522%2520viewBox%253D%25220%25200%25202048%25202048%2522%253E%253Cpath%2520d%253D%2522M2013.823%2520158.247%2520995.866%2520525.177l143.206%2520181.698L34.177%25201595.041l136.637%2520158.712%25201104.89-888.123%2520140.894%2520182.578Z%2522%252F%253E%253C%252Fsvg%253E
@@ -1 +0,0 @@
1
- data:image/svg+xml,data%3Aimage%2Fsvg%2Bxml%2C%253Csvg%2520xmlns%253D%2522http%253A%252F%252Fwww.w3.org%252F2000%252Fsvg%2522%2520width%253D%252246%2522%2520height%253D%252246%2522%2520viewBox%253D%2522-2%2520-2%25209.82%25209.82%2522%253E%253Cpath%2520d%253D%2522M1.3%25203.4c.3%25200%2520.5-.2.5-.5s-.2-.4-.5-.4c-.2%25200-.4.1-.4.4%25200%2520.3.2.5.4.5zm1.7%25200c.2%25200%2520.4-.2.4-.5s-.2-.4-.4-.4c-.3%25200-.5.1-.5.4%25200%2520.3.2.5.5.5zm1.6%25200c.2%25200%2520.4-.2.4-.5s-.2-.4-.4-.4c-.3%25200-.5.1-.5.4%25200%2520.3.2.5.5.5z%2522%252F%253E%253C%252Fsvg%253E