-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathregister-style-definitions.ts
More file actions
106 lines (98 loc) · 4.42 KB
/
register-style-definitions.ts
File metadata and controls
106 lines (98 loc) · 4.42 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
99
100
101
102
103
104
105
106
/*
Copyright 2025 Bonitasoft S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import type { mxAbstractCanvas2D, mxCell, mxPoint, mxShape } from 'mxgraph';
import { ShapeBpmnElementKind } from '../../../model/bpmn/internal';
import { mxCellRenderer, mxMarker } from '../initializer';
import {
BusinessRuleTaskShape,
CallActivityShape,
ManualTaskShape,
ReceiveTaskShape,
ScriptTaskShape,
SendTaskShape,
ServiceTaskShape,
SubProcessShape,
TaskShape,
UserTaskShape,
} from '../shape/activity-shapes';
import { BpmnConnector } from '../shape/edges';
import { EndEventShape, EventShape, IntermediateEventShape, ThrowIntermediateEventShape } from '../shape/event-shapes';
import { MessageFlowIconShape } from '../shape/flow-shapes';
import { ComplexGatewayShape, EventBasedGatewayShape, ExclusiveGatewayShape, InclusiveGatewayShape, ParallelGatewayShape } from '../shape/gateway-shapes';
import { TextAnnotationShape } from '../shape/text-annotation-shapes';
import { BpmnStyleIdentifier, MarkerIdentifier } from '../style';
export const registerShapes = (): void => {
// Inspired by the default shapes registration done in maxGraph
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- required by the signature of registerShape
const shapesToRegister: [string, new (...arguments_: any) => mxShape][] = [
// events
[ShapeBpmnElementKind.EVENT_END, EndEventShape],
[ShapeBpmnElementKind.EVENT_START, EventShape],
[ShapeBpmnElementKind.EVENT_INTERMEDIATE_THROW, ThrowIntermediateEventShape],
[ShapeBpmnElementKind.EVENT_INTERMEDIATE_CATCH, IntermediateEventShape],
[ShapeBpmnElementKind.EVENT_BOUNDARY, IntermediateEventShape],
// gateways
[ShapeBpmnElementKind.GATEWAY_COMPLEX, ComplexGatewayShape],
[ShapeBpmnElementKind.GATEWAY_EVENT_BASED, EventBasedGatewayShape],
[ShapeBpmnElementKind.GATEWAY_EXCLUSIVE, ExclusiveGatewayShape],
[ShapeBpmnElementKind.GATEWAY_INCLUSIVE, InclusiveGatewayShape],
[ShapeBpmnElementKind.GATEWAY_PARALLEL, ParallelGatewayShape],
// activities
[ShapeBpmnElementKind.SUB_PROCESS, SubProcessShape],
[ShapeBpmnElementKind.CALL_ACTIVITY, CallActivityShape],
// tasks
[ShapeBpmnElementKind.TASK, TaskShape],
[ShapeBpmnElementKind.TASK_SERVICE, ServiceTaskShape],
[ShapeBpmnElementKind.TASK_USER, UserTaskShape],
[ShapeBpmnElementKind.TASK_RECEIVE, ReceiveTaskShape],
[ShapeBpmnElementKind.TASK_SEND, SendTaskShape],
[ShapeBpmnElementKind.TASK_MANUAL, ManualTaskShape],
[ShapeBpmnElementKind.TASK_SCRIPT, ScriptTaskShape],
[ShapeBpmnElementKind.TASK_BUSINESS_RULE, BusinessRuleTaskShape],
// artifacts
[ShapeBpmnElementKind.TEXT_ANNOTATION, TextAnnotationShape],
// shapes for flows
[BpmnStyleIdentifier.EDGE, BpmnConnector],
[BpmnStyleIdentifier.MESSAGE_FLOW_ICON, MessageFlowIconShape],
];
for (const [shapeName, shapeClass] of shapesToRegister) {
mxCellRenderer.registerShape(shapeName, shapeClass);
}
};
// This implementation is adapted from the draw.io BPMN 'dash' marker
// https://github.com/jgraph/drawio/blob/f539f1ff362e76127dcc7e68b5a9d83dd7d4965c/src/main/webapp/js/mxgraph/Shapes.js#L2796
// prefix parameter name - common practice to acknowledge the fact that some parameter is unused (e.g. in TypeScript compiler)
const dashMarkerFactory = (
c: mxAbstractCanvas2D,
_shape: mxShape,
_type: string,
pe: mxPoint,
unitX: number,
unitY: number,
size: number,
_source: mxCell,
strokewidth: number,
// eslint-disable-next-line unicorn/consistent-function-scoping -- Code from mxGraph example
): (() => void) => {
const nx = unitX * (size + strokewidth + 4);
const ny = unitY * (size + strokewidth + 4);
return function () {
c.begin();
c.moveTo(pe.x - nx / 2 - ny / 2, pe.y - ny / 2 + nx / 2);
c.lineTo(pe.x + ny / 2 - (3 * nx) / 2, pe.y - (3 * ny) / 2 - nx / 2);
c.stroke();
};
};
export const registerEdgeMarkers = (): void => {
mxMarker.addMarker(MarkerIdentifier.ARROW_DASH, dashMarkerFactory);
};