bpmn-js 18.13.2 → 18.15.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.
@@ -149,8 +149,7 @@ export default function LabelEditingProvider(
149
149
 
150
150
  function activateDirectEdit(element, force) {
151
151
  if (force ||
152
- isAny(element, [ 'bpmn:Task', 'bpmn:TextAnnotation', 'bpmn:Participant' ]) ||
153
- isCollapsedSubProcess(element)) {
152
+ isAny(element, [ 'bpmn:Activity', 'bpmn:Event', 'bpmn:TextAnnotation', 'bpmn:Participant' ])) {
154
153
 
155
154
  directEditing.activate(element);
156
155
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A behavior that ensures that visually enclosed artifacts are affected
3
+ * by container element behavior:
4
+ *
5
+ * * removed when the container is removed
6
+ * * moved when the container is moved
7
+ *
8
+ */
9
+ export default class ArtifactBehavior extends CommandInterceptor {
10
+ /**
11
+ * @param injector
12
+ * @param eventBus
13
+ * @param canvas
14
+ * @param modeling
15
+ */
16
+ constructor(injector: Injector, eventBus: EventBus, canvas: Canvas, modeling: Modeling);
17
+ }
18
+
19
+ type EventBus = import("diagram-js/lib/core/EventBus").default;
20
+ type Canvas = import("diagram-js/lib/core/Canvas").default;
21
+ type Modeling = import("../Modeling").default;
22
+ type Injector = import("didi").Injector;
23
+ type Element = import("../../../model/Types").Element;
24
+ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
@@ -0,0 +1,120 @@
1
+ import inherits from 'inherits-browser';
2
+
3
+ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
4
+
5
+ import { getBBox, getEnclosedElements } from 'diagram-js/lib/util/Elements';
6
+
7
+ import {
8
+ is
9
+ } from '../../../util/ModelUtil';
10
+
11
+ import { filter, forEach, values } from 'min-dash';
12
+
13
+
14
+ /**
15
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
16
+ * @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
17
+ * @typedef {import('../Modeling').default} Modeling
18
+ * @typedef {import('didi').Injector} Injector
19
+ *
20
+ * @typedef {import('../../../model/Types').Element} Element
21
+ */
22
+
23
+ var HIGH_PRIORITY = 1500;
24
+
25
+ /**
26
+ * A behavior that ensures that visually enclosed artifacts are affected
27
+ * by container element behavior:
28
+ *
29
+ * * removed when the container is removed
30
+ * * moved when the container is moved
31
+ *
32
+ * @param {Injector} injector
33
+ * @param {EventBus} eventBus
34
+ * @param {Canvas} canvas
35
+ * @param {Modeling} modeling
36
+ */
37
+ export default function ArtifactBehavior(
38
+ injector,
39
+ eventBus,
40
+ canvas,
41
+ modeling
42
+ ) {
43
+ injector.invoke(CommandInterceptor, this);
44
+
45
+ // enclosed artifacts are deleted with a container element
46
+ this.preExecute('elements.delete', HIGH_PRIORITY, function(event) {
47
+ var context = event.context,
48
+ elements = context.elements;
49
+
50
+ var enclosedArtifacts = getEnclosedArtifacts(elements);
51
+
52
+ if (enclosedArtifacts.length) {
53
+ modeling.removeElements(enclosedArtifacts);
54
+ }
55
+ });
56
+
57
+ // enclosed artifacts are moved with container element
58
+ eventBus.on('shape.move.start', function(event) {
59
+
60
+ var shapes = event.context.shapes;
61
+
62
+ var enclosedArtifacts = getEnclosedArtifacts(shapes);
63
+
64
+ if (enclosedArtifacts.length) {
65
+ event.context.shapes = shapes.concat(enclosedArtifacts);
66
+ }
67
+ });
68
+
69
+
70
+ /**
71
+ * @param { Element[] } elements
72
+ *
73
+ * @return { Element[] }
74
+ */
75
+ function getEnclosedArtifacts(elements) {
76
+
77
+ var containerElements = filter(
78
+ elements, e => is(e, 'bpmn:Participant') || is(e, 'bpmn:SubProcess')
79
+ );
80
+
81
+ if (!containerElements.length) {
82
+ return [];
83
+ }
84
+
85
+ var canvasRoot = canvas.getRootElement();
86
+
87
+ // artifacts that still need to be checked for being enclosed
88
+ var remainingArtifacts = new Set(canvasRoot.children.filter(
89
+ (child) => is(child, 'bpmn:Artifact')
90
+ ));
91
+
92
+ // artifacts that are definitely enclosed
93
+ var enclosedArtifacts = new Set();
94
+
95
+ // we need to verify for all container elements, all artifacts <m:n>
96
+ forEach(containerElements, containerElement => {
97
+ const newEnclosedArtifacts = new Set(values(
98
+ getEnclosedElements(
99
+ Array.from(remainingArtifacts),
100
+ getBBox(containerElement)
101
+ )
102
+ ));
103
+
104
+ enclosedArtifacts = enclosedArtifacts.union(newEnclosedArtifacts);
105
+ remainingArtifacts = remainingArtifacts.difference(newEnclosedArtifacts);
106
+ });
107
+
108
+ return Array.from(enclosedArtifacts);
109
+ }
110
+
111
+ }
112
+
113
+ inherits(ArtifactBehavior, CommandInterceptor);
114
+
115
+ ArtifactBehavior.$inject = [
116
+ 'injector',
117
+ 'eventBus',
118
+ 'canvas',
119
+ 'modeling'
120
+ ];
@@ -3,6 +3,7 @@ declare const _default: {
3
3
  appendBehavior: (string | typeof AppendBehavior)[];
4
4
  associationBehavior: (string | typeof AssociationBehavior)[];
5
5
  attachEventBehavior: (string | typeof AttachEventBehavior)[];
6
+ artifactBehavior: (string | typeof ArtifactBehavior)[];
6
7
  boundaryEventBehavior: (string | typeof BoundaryEventBehavior)[];
7
8
  compensateBoundaryEventBehaviour: (string | typeof CompensateBoundaryEventBehavior)[];
8
9
  createBehavior: (string | typeof CreateBehavior)[];
@@ -46,6 +47,7 @@ import AdaptiveLabelPositioningBehavior from './AdaptiveLabelPositioningBehavior
46
47
  import AppendBehavior from './AppendBehavior';
47
48
  import AssociationBehavior from './AssociationBehavior';
48
49
  import AttachEventBehavior from './AttachEventBehavior';
50
+ import ArtifactBehavior from './ArtifactBehavior';
49
51
  import BoundaryEventBehavior from './BoundaryEventBehavior';
50
52
  import CompensateBoundaryEventBehavior from './CompensateBoundaryEventBehavior';
51
53
  import CreateBehavior from './CreateBehavior';
@@ -1,5 +1,6 @@
1
1
  import AdaptiveLabelPositioningBehavior from './AdaptiveLabelPositioningBehavior';
2
2
  import AppendBehavior from './AppendBehavior';
3
+ import ArtifactBehavior from './ArtifactBehavior';
3
4
  import AssociationBehavior from './AssociationBehavior';
4
5
  import AttachEventBehavior from './AttachEventBehavior';
5
6
  import BoundaryEventBehavior from './BoundaryEventBehavior';
@@ -47,6 +48,7 @@ export default {
47
48
  __init__: [
48
49
  'adaptiveLabelPositioningBehavior',
49
50
  'appendBehavior',
51
+ 'artifactBehavior',
50
52
  'associationBehavior',
51
53
  'attachEventBehavior',
52
54
  'boundaryEventBehavior',
@@ -91,6 +93,7 @@ export default {
91
93
  appendBehavior: [ 'type', AppendBehavior ],
92
94
  associationBehavior: [ 'type', AssociationBehavior ],
93
95
  attachEventBehavior: [ 'type', AttachEventBehavior ],
96
+ artifactBehavior: [ 'type', ArtifactBehavior ],
94
97
  boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
95
98
  compensateBoundaryEventBehaviour: [ 'type', CompensateBoundaryEventBehavior ],
96
99
  createBehavior: [ 'type', CreateBehavior ],
@@ -1,162 +1,169 @@
1
- import {
2
- assign,
3
- forEach,
4
- isString,
5
- pick
6
- } from 'min-dash';
7
-
8
- import {
9
- getDi,
10
- isAny
11
- } from '../../../util/ModelUtil';
12
-
13
- import {
14
- isLabel
15
- } from '../../../util/LabelUtil';
16
-
17
- import { isConnection } from 'diagram-js/lib/util/ModelUtil';
18
-
19
- /**
20
- * @typedef {import('diagram-js/lib/command/CommandHandler').default} CommandHandler
21
- *
22
- * @typedef {import('diagram-js/lib/command/CommandStack').default} CommandStack
23
- *
24
- * @typedef {import('../../../model/Types').ModdleElement} ModdleElement
25
- */
26
-
27
- var DEFAULT_COLORS = {
28
- fill: undefined,
29
- stroke: undefined
30
- };
31
-
32
- /**
33
- * @implements {CommandHandler}
34
- *
35
- * @param {CommandStack} commandStack
36
- */
37
- export default function SetColorHandler(commandStack) {
38
- this._commandStack = commandStack;
39
-
40
- this._normalizeColor = function(color) {
41
-
42
- // Remove color for falsy values.
43
- if (!color) {
44
- return undefined;
45
- }
46
-
47
- if (isString(color)) {
48
- var hexColor = colorToHex(color);
49
-
50
- if (hexColor) {
51
- return hexColor;
52
- }
53
- }
54
-
55
- throw new Error(`invalid color value: ${ color }`);
56
- };
57
- }
58
-
59
- SetColorHandler.$inject = [
60
- 'commandStack'
61
- ];
62
-
63
-
64
- SetColorHandler.prototype.postExecute = function(context) {
65
- var elements = context.elements,
66
- colors = context.colors || DEFAULT_COLORS;
67
-
68
- var self = this;
69
-
70
- var di = {};
71
-
72
- if ('fill' in colors) {
73
- assign(di, {
74
- 'background-color': this._normalizeColor(colors.fill) });
75
- }
76
-
77
- if ('stroke' in colors) {
78
- assign(di, {
79
- 'border-color': this._normalizeColor(colors.stroke) });
80
- }
81
-
82
- forEach(elements, function(element) {
83
- var assignedDi = isConnection(element) ? pick(di, [ 'border-color' ]) : di,
84
- elementDi = getDi(element);
85
-
86
- // TODO @barmac: remove once we drop bpmn.io properties
87
- ensureLegacySupport(assignedDi);
88
-
89
- if (isLabel(element)) {
90
-
91
- // set label colors as bpmndi:BPMNLabel#color
92
- self._commandStack.execute('element.updateModdleProperties', {
93
- element: element,
94
- moddleElement: elementDi.label,
95
- properties: {
96
- color: di['border-color']
97
- }
98
- });
99
- } else {
100
-
101
- // ignore non-compliant di
102
- if (!isAny(elementDi, [ 'bpmndi:BPMNEdge', 'bpmndi:BPMNShape' ])) {
103
- return;
104
- }
105
-
106
- // set colors bpmndi:BPMNEdge or bpmndi:BPMNShape
107
- self._commandStack.execute('element.updateProperties', {
108
- element: element,
109
- properties: {
110
- di: assignedDi
111
- }
112
- });
113
- }
114
- });
115
-
116
- };
117
-
118
- /**
119
- * Convert color from rgb(a)/hsl to hex. Returns `null` for unknown color names
120
- * and for colors with alpha less than 1.0. This depends on `<canvas>`
121
- * serialization of the `context.fillStyle`.
122
- * Cf. https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fillstyle
123
- *
124
- * @example
125
- *
126
- * ```javascript
127
- * colorToHex('fuchsia'); // "#ff00ff"
128
- *
129
- * colorToHex('rgba(1, 2, 3, 0.4)'); // null
130
- * ```
131
- *
132
- * @param {string} color
133
- *
134
- * @return {string|null}
135
- */
136
- function colorToHex(color) {
137
- var context = document.createElement('canvas').getContext('2d');
138
-
139
- // (0) Start with transparent to account for browser default values.
140
- context.fillStyle = 'transparent';
141
-
142
- // (1) Assign color so that it's serialized.
143
- context.fillStyle = color;
144
-
145
- // (2) Return null for non-hex serialization result.
146
- return /^#[0-9a-fA-F]{6}$/.test(context.fillStyle) ? context.fillStyle : null;
147
- }
148
-
149
- /**
150
- * Add legacy properties if required.
151
- *
152
- * @param {ModdleElement} di
153
- */
154
- function ensureLegacySupport(di) {
155
- if ('border-color' in di) {
156
- di.stroke = di['border-color'];
157
- }
158
-
159
- if ('background-color' in di) {
160
- di.fill = di['background-color'];
161
- }
162
- }
1
+ import {
2
+ assign,
3
+ forEach,
4
+ isString,
5
+ pick
6
+ } from 'min-dash';
7
+
8
+ import {
9
+ getDi,
10
+ is,
11
+ isAny
12
+ } from '../../../util/ModelUtil';
13
+
14
+ import {
15
+ isLabel
16
+ } from '../../../util/LabelUtil';
17
+
18
+ import { isConnection } from 'diagram-js/lib/util/ModelUtil';
19
+
20
+ /**
21
+ * @typedef {import('diagram-js/lib/command/CommandHandler').default} CommandHandler
22
+ *
23
+ * @typedef {import('diagram-js/lib/command/CommandStack').default} CommandStack
24
+ *
25
+ * @typedef {import('../../../model/Types').ModdleElement} ModdleElement
26
+ */
27
+
28
+ var DEFAULT_COLORS = {
29
+ fill: undefined,
30
+ stroke: undefined
31
+ };
32
+
33
+ /**
34
+ * @implements {CommandHandler}
35
+ *
36
+ * @param {CommandStack} commandStack
37
+ */
38
+ export default function SetColorHandler(commandStack) {
39
+ this._commandStack = commandStack;
40
+
41
+ this._normalizeColor = function(color) {
42
+
43
+ // Remove color for falsy values.
44
+ if (!color) {
45
+ return undefined;
46
+ }
47
+
48
+ if (isString(color)) {
49
+ var hexColor = colorToHex(color);
50
+
51
+ if (hexColor) {
52
+ return hexColor;
53
+ }
54
+ }
55
+
56
+ throw new Error(`invalid color value: ${ color }`);
57
+ };
58
+ }
59
+
60
+ SetColorHandler.$inject = [
61
+ 'commandStack'
62
+ ];
63
+
64
+
65
+ SetColorHandler.prototype.postExecute = function(context) {
66
+ var elements = context.elements,
67
+ colors = context.colors || DEFAULT_COLORS;
68
+
69
+ var self = this;
70
+
71
+ var di = {};
72
+
73
+ if ('fill' in colors) {
74
+ assign(di, {
75
+ 'background-color': this._normalizeColor(colors.fill)
76
+ });
77
+ }
78
+
79
+ if ('stroke' in colors) {
80
+ assign(di, {
81
+ 'border-color': this._normalizeColor(colors.stroke)
82
+ });
83
+ }
84
+
85
+ forEach(elements, function(element) {
86
+ var assignedDi = isConnection(element) ? pick(di, [ 'border-color' ]) : di,
87
+ elementDi = getDi(element);
88
+
89
+ // TODO @barmac: remove once we drop bpmn.io properties
90
+ ensureLegacySupport(assignedDi);
91
+
92
+ if (isLabel(element)) {
93
+
94
+ if (!elementDi || !is(elementDi.label, 'bpmndi:BPMNLabel')) {
95
+ return;
96
+ }
97
+
98
+ // set label colors as bpmndi:BPMNLabel#color
99
+ self._commandStack.execute('element.updateModdleProperties', {
100
+ element: element,
101
+ moddleElement: elementDi.label,
102
+ properties: {
103
+ color: di['border-color']
104
+ }
105
+ });
106
+ } else {
107
+
108
+ // ignore non-compliant di
109
+ if (!isAny(elementDi, [ 'bpmndi:BPMNEdge', 'bpmndi:BPMNShape' ])) {
110
+ return;
111
+ }
112
+
113
+ // set colors bpmndi:BPMNEdge or bpmndi:BPMNShape
114
+ self._commandStack.execute('element.updateProperties', {
115
+ element: element,
116
+ properties: {
117
+ di: assignedDi
118
+ }
119
+ });
120
+ }
121
+ });
122
+
123
+ };
124
+
125
+ /**
126
+ * Convert color from rgb(a)/hsl to hex. Returns `null` for unknown color names
127
+ * and for colors with alpha less than 1.0. This depends on `<canvas>`
128
+ * serialization of the `context.fillStyle`.
129
+ * Cf. https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fillstyle
130
+ *
131
+ * @example
132
+ *
133
+ * ```javascript
134
+ * colorToHex('fuchsia'); // "#ff00ff"
135
+ *
136
+ * colorToHex('rgba(1, 2, 3, 0.4)'); // null
137
+ * ```
138
+ *
139
+ * @param {string} color
140
+ *
141
+ * @return {string|null}
142
+ */
143
+ function colorToHex(color) {
144
+ var context = document.createElement('canvas').getContext('2d');
145
+
146
+ // (0) Start with transparent to account for browser default values.
147
+ context.fillStyle = 'transparent';
148
+
149
+ // (1) Assign color so that it's serialized.
150
+ context.fillStyle = color;
151
+
152
+ // (2) Return null for non-hex serialization result.
153
+ return /^#[0-9a-fA-F]{6}$/.test(context.fillStyle) ? context.fillStyle : null;
154
+ }
155
+
156
+ /**
157
+ * Add legacy properties if required.
158
+ *
159
+ * @param {ModdleElement} di
160
+ */
161
+ function ensureLegacySupport(di) {
162
+ if ('border-color' in di) {
163
+ di.stroke = di['border-color'];
164
+ }
165
+
166
+ if ('background-color' in di) {
167
+ di.fill = di['background-color'];
168
+ }
169
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-js",
3
- "version": "18.13.2",
3
+ "version": "18.15.0",
4
4
  "description": "A bpmn 2.0 toolkit and web modeler",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -63,25 +63,25 @@
63
63
  "*.css"
64
64
  ],
65
65
  "devDependencies": {
66
- "@babel/core": "^7.28.5",
66
+ "@babel/core": "^7.29.0",
67
67
  "@bpmn-io/a11y": "^0.1.0",
68
- "@rollup/plugin-commonjs": "^29.0.0",
68
+ "@rollup/plugin-commonjs": "^29.0.2",
69
69
  "@rollup/plugin-json": "^6.1.0",
70
70
  "@rollup/plugin-node-resolve": "^16.0.3",
71
71
  "@rollup/plugin-replace": "^6.0.3",
72
72
  "@rollup/plugin-terser": "^1.0.0",
73
- "babel-loader": "^10.0.0",
74
- "babel-plugin-istanbul": "^7.0.1",
73
+ "babel-loader": "^10.1.1",
74
+ "babel-plugin-istanbul": "^8.0.0",
75
75
  "bio-dts": "^0.11.0",
76
76
  "bpmn-font": "^0.12.1",
77
77
  "camunda-bpmn-moddle": "^4.0.1",
78
78
  "chai": "4.1.2",
79
79
  "chai-match": "^1.1.1",
80
- "cpy": "^13.0.0",
81
- "cross-env": "^10.0.0",
80
+ "cpy": "^13.2.1",
81
+ "cross-env": "^10.1.0",
82
82
  "del": "^8.0.0",
83
83
  "del-cli": "^7.0.0",
84
- "eslint": "^9.39.2",
84
+ "eslint": "^9.39.4",
85
85
  "eslint-plugin-bpmn-io": "^2.2.0",
86
86
  "execa": "^9.0.0",
87
87
  "file-drops": "^0.7.0",
@@ -98,25 +98,25 @@
98
98
  "mocha": "^10.8.2",
99
99
  "mocha-test-container-support": "0.2.0",
100
100
  "npm-run-all2": "^8.0.4",
101
- "puppeteer": "~24.36.0",
101
+ "puppeteer": "^24.42.0",
102
102
  "remark-cli": "^12.0.1",
103
103
  "remark-preset-bpmn-io": "^0.4.0",
104
- "rollup": "^4.55.1",
105
- "rollup-plugin-license": "^3.6.0",
104
+ "rollup": "^4.60.2",
105
+ "rollup-plugin-license": "^3.7.1",
106
106
  "sinon": "^17.0.1",
107
107
  "sinon-chai": "^3.7.0",
108
108
  "ts-expect": "^1.3.0",
109
109
  "typescript": "^5.9.3",
110
- "webpack": "^5.104.1"
110
+ "webpack": "^5.106.2"
111
111
  },
112
112
  "dependencies": {
113
113
  "bpmn-moddle": "^10.0.0",
114
- "diagram-js": "^15.10.0",
114
+ "diagram-js": "^15.13.0",
115
115
  "diagram-js-direct-editing": "^3.3.0",
116
- "ids": "^3.0.0",
116
+ "ids": "^3.0.2",
117
117
  "inherits-browser": "^0.1.0",
118
118
  "min-dash": "^5.0.0",
119
- "min-dom": "^5.2.0",
119
+ "min-dom": "^5.3.0",
120
120
  "tiny-svg": "^4.1.4"
121
121
  },
122
122
  "remarkConfig": {