-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathPredicates.ts
More file actions
98 lines (85 loc) · 2.95 KB
/
Copy pathPredicates.ts
File metadata and controls
98 lines (85 loc) · 2.95 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {
isBpmndiType,
isBpmnType,
type BpmnElement,
type BpmnTypeName
} from './Types.js';
export function isArtifact(element: BpmnElement): boolean {
return isBpmnType(element, 'bpmn:TextAnnotation') ||
isBpmnType(element, 'bpmn:DataObjectReference') ||
isBpmnType(element, 'bpmn:DataStoreReference') ||
isBpmnType(element, 'bpmn:Group');
}
export function isExteriorArtifact(element: BpmnElement): boolean {
return isBpmnType(element, 'bpmn:TextAnnotation') ||
isBpmnType(element, 'bpmn:DataStoreReference');
}
export function isExternalLabelOwner(element: BpmnElement): boolean {
return isBpmnType(element, 'bpmn:Event') ||
isBpmnType(element, 'bpmn:Gateway') ||
isBpmnType(element, 'bpmn:DataStoreReference') ||
isBpmnType(element, 'bpmn:DataObjectReference') ||
isBpmnType(element, 'bpmn:SequenceFlow') ||
isBpmnType(element, 'bpmn:MessageFlow') ||
isBpmnType(element, 'bpmn:Group');
}
export function getExternalLabelText(element: BpmnElement): string {
if (isBpmnType(element, 'bpmn:Group')) {
return element.categoryValueRef?.value || '';
}
return 'name' in element && typeof element.name === 'string'
? element.name
: '';
}
export function hasSubProcessLabel(element: BpmnElement): boolean {
return isBpmnType(element, 'bpmn:SubProcess') && !!element.name?.trim();
}
export function hasEventDefinition(
event: BpmnElement,
type: BpmnTypeName
): boolean {
const eventWithDefinitions = isBpmnType(event, 'bpmn:CatchEvent')
? event
: isBpmnType(event, 'bpmn:ThrowEvent')
? event
: null;
return !!eventWithDefinitions &&
(eventWithDefinitions.eventDefinitions || []).some(definition => {
return isBpmnType(definition, type);
});
}
export function isSupportedVisualElement(element: BpmnElement): boolean {
return isBpmnType(element, 'bpmn:Activity') ||
isBpmnType(element, 'bpmn:Event') ||
(isBpmnType(element, 'bpmn:Gateway') &&
!isBpmnType(element, 'bpmn:ComplexGateway')) ||
isArtifact(element) ||
isBpmnType(element, 'bpmn:Participant') ||
isBpmnType(element, 'bpmn:Lane');
}
export function isSupportedVisualConnection(element: BpmnElement): boolean {
return isBpmnType(element, 'bpmn:SequenceFlow') ||
isBpmnType(element, 'bpmn:MessageFlow') ||
isBpmnType(element, 'bpmn:Association') ||
isBpmnType(element, 'bpmn:DataAssociation');
}
export function getExpandedIds(
definitions: BpmnElement,
root: BpmnElement
): Set<string> {
if (!isBpmnType(definitions, 'bpmn:Definitions')) {
return new Set();
}
const diagram = (definitions.diagrams || []).find(candidate => candidate.plane?.bpmnElement === root);
const ids = new Set<string>();
for (const element of diagram?.plane?.planeElement || []) {
if (
isBpmndiType(element, 'bpmndi:BPMNShape') &&
element.isExpanded === true &&
typeof element.bpmnElement?.id === 'string'
) {
ids.add(element.bpmnElement.id);
}
}
return ids;
}