-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathExpectedDiElements.ts
More file actions
83 lines (71 loc) · 2.12 KB
/
Copy pathExpectedDiElements.ts
File metadata and controls
83 lines (71 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { flattenLanes } from '../process/placement/LanePlacement.js';
import {
isSupportedVisualConnection,
isSupportedVisualElement
} from './Predicates.js';
import {
isBpmnElement,
isBpmnType,
type BpmnElement
} from './Types.js';
export function getExpectedDiElements(root: BpmnElement): Set<BpmnElement> {
const elements = new Set<BpmnElement>();
const scopes = new Set<BpmnElement>();
const addIfExpected = (element: BpmnElement) => {
if (
isSupportedVisualElement(element) ||
isSupportedVisualConnection(element)
) {
elements.add(element);
}
};
const collectScope = (scope: BpmnElement) => {
if (scopes.has(scope)) {
return;
}
if (
!isBpmnType(scope, 'bpmn:Process') &&
!isBpmnType(scope, 'bpmn:SubProcess')
) {
return;
}
scopes.add(scope);
flattenLanes(scope.laneSets || [])
.filter(isBpmnElement)
.forEach(addIfExpected);
for (const element of scope.flowElements || []) {
addIfExpected(element);
const dataInputAssociations = 'dataInputAssociations' in element &&
Array.isArray(element.dataInputAssociations)
? element.dataInputAssociations
: [];
const dataOutputAssociations = 'dataOutputAssociations' in element &&
Array.isArray(element.dataOutputAssociations)
? element.dataOutputAssociations
: [];
for (const association of [
...(dataInputAssociations || []),
...(dataOutputAssociations || [])
].filter(isBpmnElement)) {
addIfExpected(association);
}
if (isBpmnType(element, 'bpmn:SubProcess')) {
collectScope(element);
}
}
(scope.artifacts || []).forEach(addIfExpected);
};
if (isBpmnType(root, 'bpmn:Collaboration')) {
(root.participants || []).forEach(addIfExpected);
(root.messageFlows || []).forEach(addIfExpected);
(root.artifacts || []).forEach(addIfExpected);
for (const participant of root.participants || []) {
if (participant.processRef) {
collectScope(participant.processRef);
}
}
} else {
collectScope(root);
}
return elements;
}