Skip to content

Commit 78d0846

Browse files
committed
fix(space-tool): move artifacts when a participant is resized by space tool
Related to camunda/camunda-modeler#4172 * test(space-tool): add some test helpers to make testing smooth
1 parent bf76668 commit 78d0846

File tree

3 files changed

+408
-53
lines changed

3 files changed

+408
-53
lines changed

lib/features/space-tool/BpmnSpaceTool.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import inherits from 'inherits-browser';
22

33
import SpaceTool from 'diagram-js/lib/features/space-tool/SpaceTool';
44

5+
import { getEnclosedElements, getBBox } from 'diagram-js/lib/util/Elements';
6+
57
import { getBusinessObject, is } from '../../util/ModelUtil';
68

79
import { isHorizontal } from '../../util/DiUtil';
10+
import { values } from 'min-dash';
811

912
/**
1013
* @typedef {import('didi').Injector} Injector
14+
* @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
1115
*
1216
* @typedef {import('../../model/Types').Shape} Shape
1317
*
@@ -17,13 +21,17 @@ import { isHorizontal } from '../../util/DiUtil';
1721

1822
/**
1923
* @param {Injector} injector
24+
* @param {Canvas} canvas
2025
*/
21-
export default function BpmnSpaceTool(injector) {
26+
export default function BpmnSpaceTool(injector, canvas) {
2227
injector.invoke(SpaceTool, this);
28+
29+
this._canvas = canvas;
2330
}
2431

2532
BpmnSpaceTool.$inject = [
26-
'injector'
33+
'injector',
34+
'canvas'
2735
];
2836

2937
inherits(BpmnSpaceTool, SpaceTool);
@@ -37,7 +45,26 @@ inherits(BpmnSpaceTool, SpaceTool);
3745
* @return {Object}
3846
*/
3947
BpmnSpaceTool.prototype.calculateAdjustments = function(elements, axis, delta, start) {
40-
var adjustments = SpaceTool.prototype.calculateAdjustments.call(this, elements, axis, delta, start);
48+
49+
var canvasRoot = this._canvas.getRootElement(),
50+
spaceRoot = elements[0] === canvasRoot ? null : elements[0],
51+
enclosedArtifacts = [];
52+
53+
// ensure
54+
if (spaceRoot) {
55+
enclosedArtifacts = values(
56+
getEnclosedElements(
57+
canvasRoot.children.filter(
58+
(child) => is(child, 'bpmn:Artifact')
59+
),
60+
getBBox(spaceRoot)
61+
)
62+
);
63+
}
64+
65+
const elementsToMove = [ ...elements, ...enclosedArtifacts ];
66+
67+
var adjustments = SpaceTool.prototype.calculateAdjustments.call(this, elementsToMove, axis, delta, start);
4168

4269
// do not resize:
4370
//
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_14kk48y" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.32.0-rc.0">
3+
<bpmn:collaboration id="COLLABORATION">
4+
<bpmn:participant id="PARTICIPANT" name="PARTICIPANT" processRef="PROCESS" />
5+
<bpmn:textAnnotation id="ANNOTATION_1">
6+
<bpmn:text>ANNOTATION_1</bpmn:text>
7+
</bpmn:textAnnotation>
8+
<bpmn:textAnnotation id="ANNOTATION_3">
9+
<bpmn:text>ANNOTATION_3</bpmn:text>
10+
</bpmn:textAnnotation>
11+
<bpmn:textAnnotation id="ANNOTATION_2">
12+
<bpmn:text>ANNOTATION_2</bpmn:text>
13+
</bpmn:textAnnotation>
14+
<bpmn:group id="GROUP_CONTAINED_PARTICIPANT" categoryValueRef="CategoryValue_1fn4md7" />
15+
<bpmn:group id="GROUP_OUTSIDE" categoryValueRef="CategoryValue_0w429b8" />
16+
<bpmn:group id="GROUP_CONTAINED_SUB" categoryValueRef="CategoryValue_0l3p581" />
17+
<bpmn:textAnnotation id="ANNOTATION_4">
18+
<bpmn:text>ANNOTATION_4</bpmn:text>
19+
</bpmn:textAnnotation>
20+
<bpmn:association id="Association_1iiawtv" associationDirection="None" sourceRef="ANNOTATION_4" targetRef="GROUP_CONTAINED_SUB" />
21+
<bpmn:association id="Association_180iz30" associationDirection="None" sourceRef="TASK" targetRef="ANNOTATION_1" />
22+
<bpmn:association id="Association_08csipe" associationDirection="None" sourceRef="TASK" targetRef="ANNOTATION_3" />
23+
<bpmn:textAnnotation id="ANNOTATION_5">
24+
<bpmn:text>ANNOTATION_5</bpmn:text>
25+
</bpmn:textAnnotation>
26+
<bpmn:group id="GROUP_OUTSIDE_SUB" categoryValueRef="CategoryValue_1rcl2uo" />
27+
</bpmn:collaboration>
28+
<bpmn:process id="PROCESS" isExecutable="false">
29+
<bpmn:laneSet id="LaneSet_04jep3i" />
30+
<bpmn:task id="TASK" name="TASK" />
31+
<bpmn:subProcess id="SUB" name="SUB" />
32+
</bpmn:process>
33+
<bpmn:category id="Category_0tto0k6">
34+
<bpmn:categoryValue id="CategoryValue_1fn4md7" value="GROUP_CONTAINED_PARTICIPANT" />
35+
</bpmn:category>
36+
<bpmn:category id="Category_002evdo">
37+
<bpmn:categoryValue id="CategoryValue_0w429b8" value="GROUP_OUTSIDE" />
38+
</bpmn:category>
39+
<bpmn:category id="Category_1u7ocho">
40+
<bpmn:categoryValue id="CategoryValue_0l3p581" value="GROUP_CONTAINED_SUB" />
41+
</bpmn:category>
42+
<bpmn:category id="Category_00robw0">
43+
<bpmn:categoryValue id="CategoryValue_1rcl2uo" value="GROUP_OUTSIDE_SUB" />
44+
</bpmn:category>
45+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
46+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="COLLABORATION">
47+
<bpmndi:BPMNShape id="Participant_0lm71nu_di" bpmnElement="PARTICIPANT" isHorizontal="true">
48+
<dc:Bounds x="160" y="130" width="900" height="420" />
49+
<bpmndi:BPMNLabel />
50+
</bpmndi:BPMNShape>
51+
<bpmndi:BPMNShape id="Activity_1g8l8sp_di" bpmnElement="TASK">
52+
<dc:Bounds x="280" y="280" width="100" height="80" />
53+
<bpmndi:BPMNLabel />
54+
</bpmndi:BPMNShape>
55+
<bpmndi:BPMNShape id="Activity_1mtvx36_di" bpmnElement="SUB" isExpanded="true">
56+
<dc:Bounds x="650" y="200" width="350" height="280" />
57+
<bpmndi:BPMNLabel />
58+
</bpmndi:BPMNShape>
59+
<bpmndi:BPMNEdge id="Association_180iz30_di" bpmnElement="Association_180iz30">
60+
<di:waypoint x="379" y="287" />
61+
<di:waypoint x="494" y="209" />
62+
</bpmndi:BPMNEdge>
63+
<bpmndi:BPMNEdge id="Association_08csipe_di" bpmnElement="Association_08csipe">
64+
<di:waypoint x="336" y="360" />
65+
<di:waypoint x="378" y="650" />
66+
</bpmndi:BPMNEdge>
67+
<bpmndi:BPMNEdge id="Association_1iiawtv_di" bpmnElement="Association_1iiawtv">
68+
<di:waypoint x="869" y="410" />
69+
<di:waypoint x="850" y="360" />
70+
</bpmndi:BPMNEdge>
71+
<bpmndi:BPMNShape id="TextAnnotation_0kurhwc_di" bpmnElement="ANNOTATION_1">
72+
<dc:Bounds x="470" y="170" width="109.99999237060547" height="39" />
73+
<bpmndi:BPMNLabel />
74+
</bpmndi:BPMNShape>
75+
<bpmndi:BPMNShape id="BPMNShape_1vsrf4d" bpmnElement="ANNOTATION_2">
76+
<dc:Bounds x="450" y="430" width="110" height="41" />
77+
<bpmndi:BPMNLabel />
78+
</bpmndi:BPMNShape>
79+
<bpmndi:BPMNShape id="Group_1q5j3c0_di" bpmnElement="GROUP_CONTAINED_PARTICIPANT">
80+
<dc:Bounds x="240" y="190" width="170" height="220" />
81+
<bpmndi:BPMNLabel>
82+
<dc:Bounds x="282" y="197" width="88" height="40" />
83+
</bpmndi:BPMNLabel>
84+
</bpmndi:BPMNShape>
85+
<bpmndi:BPMNShape id="BPMNShape_0m8gbmr" bpmnElement="GROUP_OUTSIDE">
86+
<dc:Bounds x="210" y="80" width="370" height="500" />
87+
<bpmndi:BPMNLabel>
88+
<dc:Bounds x="355" y="87" width="80" height="27" />
89+
</bpmndi:BPMNLabel>
90+
</bpmndi:BPMNShape>
91+
<bpmndi:BPMNShape id="TextAnnotation_0r40zjh_di" bpmnElement="ANNOTATION_3">
92+
<dc:Bounds x="330" y="650" width="110" height="41" />
93+
<bpmndi:BPMNLabel />
94+
</bpmndi:BPMNShape>
95+
<bpmndi:BPMNShape id="Group_0887xry_di" bpmnElement="GROUP_CONTAINED_SUB">
96+
<dc:Bounds x="690" y="240" width="200" height="120" />
97+
<bpmndi:BPMNLabel>
98+
<dc:Bounds x="748" y="247" width="85" height="27" />
99+
</bpmndi:BPMNLabel>
100+
</bpmndi:BPMNShape>
101+
<bpmndi:BPMNShape id="BPMNShape_0hnq4f9" bpmnElement="ANNOTATION_4">
102+
<dc:Bounds x="820" y="410" width="110" height="30" />
103+
<bpmndi:BPMNLabel />
104+
</bpmndi:BPMNShape>
105+
<bpmndi:BPMNShape id="Group_0m4uhit_di" bpmnElement="GROUP_OUTSIDE_SUB">
106+
<dc:Bounds x="725" y="140" width="300" height="390" />
107+
<bpmndi:BPMNLabel>
108+
<dc:Bounds x="837" y="147" width="80" height="27" />
109+
</bpmndi:BPMNLabel>
110+
</bpmndi:BPMNShape>
111+
<bpmndi:BPMNShape id="BPMNShape_0t9rdue" bpmnElement="ANNOTATION_5">
112+
<dc:Bounds x="870" y="490" width="109.99999237060547" height="25.999998092651367" />
113+
<bpmndi:BPMNLabel />
114+
</bpmndi:BPMNShape>
115+
</bpmndi:BPMNPlane>
116+
</bpmndi:BPMNDiagram>
117+
</bpmn:definitions>

0 commit comments

Comments
 (0)