@aranzatech/diagrams-bpmn 0.2.0 → 0.2.2
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.
- package/CHANGELOG.md +1 -1
- package/dist/catalog-DIBySQqA.d.ts +9 -0
- package/dist/catalog-m8fHIiKH.d.cts +9 -0
- package/dist/{chunk-MF2WE3OM.js → chunk-33AR3PXF.js} +36 -8
- package/dist/chunk-33AR3PXF.js.map +1 -0
- package/dist/{chunk-3AFZDIMQ.js → chunk-ECTJRD7Z.js} +3 -3
- package/dist/{chunk-3AFZDIMQ.js.map → chunk-ECTJRD7Z.js.map} +1 -1
- package/dist/{chunk-S3GGEEA5.js → chunk-H3YMTGFG.js} +50 -32
- package/dist/chunk-H3YMTGFG.js.map +1 -0
- package/dist/chunk-KALSGH4D.js +36 -0
- package/dist/chunk-KALSGH4D.js.map +1 -0
- package/dist/{chunk-DNR5WBQH.js → chunk-L5Z22RLX.js} +81 -20
- package/dist/chunk-L5Z22RLX.js.map +1 -0
- package/dist/{chunk-57LA2WSJ.js → chunk-QOGZITWB.js} +10 -6
- package/dist/chunk-QOGZITWB.js.map +1 -0
- package/dist/{chunk-5GRCJ5X6.js → chunk-RLAJNRF2.js} +3 -3
- package/dist/{chunk-5GRCJ5X6.js.map → chunk-RLAJNRF2.js.map} +1 -1
- package/dist/chunk-YQTIODXH.js +532 -0
- package/dist/chunk-YQTIODXH.js.map +1 -0
- package/dist/chunk-ZFGQVLHB.js +226 -0
- package/dist/chunk-ZFGQVLHB.js.map +1 -0
- package/dist/edges/index.cjs +1 -1
- package/dist/edges/index.cjs.map +1 -1
- package/dist/edges/index.js +2 -2
- package/dist/elements/index.cjs +81 -17
- package/dist/elements/index.cjs.map +1 -1
- package/dist/elements/index.d.cts +4 -6
- package/dist/elements/index.d.ts +4 -6
- package/dist/elements/index.js +2 -2
- package/dist/index.cjs +697 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +9 -8
- package/dist/modeling/index.cjs +383 -36
- package/dist/modeling/index.cjs.map +1 -1
- package/dist/modeling/index.d.cts +61 -3
- package/dist/modeling/index.d.ts +61 -3
- package/dist/modeling/index.js +3 -3
- package/dist/nodes/index.cjs +62 -32
- package/dist/nodes/index.cjs.map +1 -1
- package/dist/nodes/index.js +2 -2
- package/dist/simulation/index.cjs +8 -4
- package/dist/simulation/index.cjs.map +1 -1
- package/dist/simulation/index.js +1 -1
- package/dist/{types-hj621ZRJ.d.ts → types-BxjCV2oX.d.ts} +1 -1
- package/dist/{types-BKA0GZz5.d.cts → types-DznxZxpV.d.cts} +11 -1
- package/dist/{types-BKA0GZz5.d.ts → types-DznxZxpV.d.ts} +11 -1
- package/dist/{types-CCkHqtC_.d.cts → types-vVi5T7qj.d.cts} +1 -1
- package/dist/validation/index.cjs +848 -0
- package/dist/validation/index.cjs.map +1 -0
- package/dist/validation/index.d.cts +25 -0
- package/dist/validation/index.d.ts +25 -0
- package/dist/validation/index.js +5 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/xml/index.cjs +74 -22
- package/dist/xml/index.cjs.map +1 -1
- package/dist/xml/index.d.cts +2 -2
- package/dist/xml/index.d.ts +2 -2
- package/dist/xml/index.js +2 -2
- package/package.json +8 -3
- package/dist/chunk-23B2IGK5.js +0 -24
- package/dist/chunk-23B2IGK5.js.map +0 -1
- package/dist/chunk-57LA2WSJ.js.map +0 -1
- package/dist/chunk-DNR5WBQH.js.map +0 -1
- package/dist/chunk-G5S4ASP3.js +0 -277
- package/dist/chunk-G5S4ASP3.js.map +0 -1
- package/dist/chunk-MF2WE3OM.js.map +0 -1
- package/dist/chunk-S3GGEEA5.js.map +0 -1
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import { acceptsBoundaryEvents, getHandlePolicy, isEventType, isGatewayType, isDataType } from './chunk-RLAJNRF2.js';
|
|
2
|
+
import { isBpmnElementResizable, BPMN_ELEMENT_CATALOG, getBpmnElementSize } from './chunk-L5Z22RLX.js';
|
|
3
|
+
import { createModelingRules, getNode, getOutgoingEdges, getIncomingEdges, patchNode, resizeNode, addNode, connectNodes, reparentNode, replaceNode, patchEdge, removeElements, copyElements, pasteElements, setSelection, createSelectionState, normalizeDiagramState, executeCommand, executeCommands } from '@aranzatech/diagrams-core';
|
|
4
|
+
import { createDiagramDocument, serializeDiagram, parseDiagramDocument, deserializeDiagram } from '@aranzatech/diagrams-core/serialization';
|
|
5
|
+
|
|
6
|
+
function createBpmnNode(options) {
|
|
7
|
+
const size = getBpmnElementSize(options.elementType);
|
|
8
|
+
const meta = BPMN_ELEMENT_CATALOG[options.elementType];
|
|
9
|
+
const orientation = options.data?.orientation ?? meta.orientation;
|
|
10
|
+
const dragHandle = getBpmnDragHandleSelector(options.elementType);
|
|
11
|
+
return {
|
|
12
|
+
id: options.id,
|
|
13
|
+
type: options.elementType,
|
|
14
|
+
position: options.position,
|
|
15
|
+
data: {
|
|
16
|
+
elementType: options.elementType,
|
|
17
|
+
orientation,
|
|
18
|
+
...options.label ? { label: options.label } : {},
|
|
19
|
+
...options.data ?? {}
|
|
20
|
+
},
|
|
21
|
+
width: options.width ?? size.width,
|
|
22
|
+
height: options.height ?? size.height,
|
|
23
|
+
...options.parentId ? { parentId: options.parentId } : {},
|
|
24
|
+
...dragHandle ? { dragHandle } : {}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var BPMN_POOL_LANE_LAYOUT = {
|
|
28
|
+
poolHeaderSize: 30,
|
|
29
|
+
laneHeaderSize: 24,
|
|
30
|
+
laneGap: 0
|
|
31
|
+
};
|
|
32
|
+
function getBpmnDragHandleSelector(elementType) {
|
|
33
|
+
if (elementType === "Pool") return ".pool-drag-handle";
|
|
34
|
+
if (elementType === "Lane") return ".lane-drag-handle";
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
var BPMN_SELECTION_STYLE = {
|
|
38
|
+
nodeOutline: "#2563eb",
|
|
39
|
+
edgeStroke: "#2563eb",
|
|
40
|
+
handleFill: "#ffffff",
|
|
41
|
+
handleStroke: "#2563eb",
|
|
42
|
+
resizeHandleSize: 8,
|
|
43
|
+
routingPointRadius: 5
|
|
44
|
+
};
|
|
45
|
+
var BPMN_ROUTABLE_EDGE_TYPES = [
|
|
46
|
+
"sequenceFlow",
|
|
47
|
+
"messageFlow",
|
|
48
|
+
"association",
|
|
49
|
+
"dataAssociation",
|
|
50
|
+
"conversationLink"
|
|
51
|
+
];
|
|
52
|
+
var BPMN_EDGE_CONNECTION_RULES = {
|
|
53
|
+
sequenceFlow: {
|
|
54
|
+
edgeType: "sequenceFlow",
|
|
55
|
+
sourceCategories: ["flowNode"],
|
|
56
|
+
targetCategories: ["flowNode"],
|
|
57
|
+
allowSameParent: true,
|
|
58
|
+
allowDifferentParent: false
|
|
59
|
+
},
|
|
60
|
+
messageFlow: {
|
|
61
|
+
edgeType: "messageFlow",
|
|
62
|
+
sourceCategories: ["flowNode"],
|
|
63
|
+
targetCategories: ["flowNode"],
|
|
64
|
+
allowSameParent: false,
|
|
65
|
+
allowDifferentParent: true
|
|
66
|
+
},
|
|
67
|
+
association: {
|
|
68
|
+
edgeType: "association",
|
|
69
|
+
sourceCategories: ["flowNode", "artifact", "data"],
|
|
70
|
+
targetCategories: ["flowNode", "artifact", "data"],
|
|
71
|
+
allowSameParent: true,
|
|
72
|
+
allowDifferentParent: true
|
|
73
|
+
},
|
|
74
|
+
dataAssociation: {
|
|
75
|
+
edgeType: "dataAssociation",
|
|
76
|
+
sourceCategories: ["flowNode", "data"],
|
|
77
|
+
targetCategories: ["flowNode", "data"],
|
|
78
|
+
allowSameParent: true,
|
|
79
|
+
allowDifferentParent: true
|
|
80
|
+
},
|
|
81
|
+
conversationLink: {
|
|
82
|
+
edgeType: "conversationLink",
|
|
83
|
+
sourceCategories: ["conversation", "flowNode"],
|
|
84
|
+
targetCategories: ["conversation", "flowNode"],
|
|
85
|
+
allowSameParent: true,
|
|
86
|
+
allowDifferentParent: true
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
function inferBpmnEdgeType(state, sourceId, targetId) {
|
|
90
|
+
const source = getNode(state, sourceId);
|
|
91
|
+
const target = getNode(state, targetId);
|
|
92
|
+
if (!source || !target) return "sequenceFlow";
|
|
93
|
+
if (isDataType(source.data.elementType) || isDataType(target.data.elementType)) {
|
|
94
|
+
return "dataAssociation";
|
|
95
|
+
}
|
|
96
|
+
if (source.data.elementType === "Annotation" || target.data.elementType === "Annotation" || source.data.elementType === "Group" || target.data.elementType === "Group") {
|
|
97
|
+
return "association";
|
|
98
|
+
}
|
|
99
|
+
if (source.data.elementType === "Conversation" || source.data.elementType === "SubConversation" || source.data.elementType === "CallConversation" || target.data.elementType === "Conversation" || target.data.elementType === "SubConversation" || target.data.elementType === "CallConversation") {
|
|
100
|
+
return "conversationLink";
|
|
101
|
+
}
|
|
102
|
+
if (source.parentId && target.parentId && source.parentId !== target.parentId) {
|
|
103
|
+
return "messageFlow";
|
|
104
|
+
}
|
|
105
|
+
return "sequenceFlow";
|
|
106
|
+
}
|
|
107
|
+
function canUseSequenceFlow(type) {
|
|
108
|
+
const meta = BPMN_ELEMENT_CATALOG[type];
|
|
109
|
+
return meta.handlePolicy !== "none" && !isDataType(type) && type !== "Annotation" && type !== "Group" && meta.category !== "conversation";
|
|
110
|
+
}
|
|
111
|
+
function matchesConnectionCategory(type, categories) {
|
|
112
|
+
return categories.some((category) => {
|
|
113
|
+
if (category === type) return true;
|
|
114
|
+
if (category === "flowNode") return canUseSequenceFlow(type);
|
|
115
|
+
if (category === "data") return isDataType(type);
|
|
116
|
+
if (category === "artifact") return type === "Annotation" || type === "Group";
|
|
117
|
+
if (category === "conversation") return BPMN_ELEMENT_CATALOG[type].category === "conversation";
|
|
118
|
+
return false;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function isBpmnEdgeRoutingEditable(edgeType) {
|
|
122
|
+
return BPMN_ROUTABLE_EDGE_TYPES.includes(edgeType);
|
|
123
|
+
}
|
|
124
|
+
function isBpmnProcessNode(type) {
|
|
125
|
+
return isEventType(type) || isGatewayType(type) || type.includes("Task") || type === "CallActivity" || type === "SubProcess" || type === "Transaction" || type === "EventSubProcess" || type === "AdHocSubProcess";
|
|
126
|
+
}
|
|
127
|
+
function canContainBpmnElement(parentType, childType) {
|
|
128
|
+
if (!parentType) return true;
|
|
129
|
+
if (parentType === "Pool") {
|
|
130
|
+
return childType === "Lane" || isBpmnProcessNode(childType) ? true : "Pools can contain lanes or BPMN process nodes.";
|
|
131
|
+
}
|
|
132
|
+
if (parentType === "Lane") {
|
|
133
|
+
return isBpmnProcessNode(childType) ? true : "Lanes can only contain BPMN process nodes.";
|
|
134
|
+
}
|
|
135
|
+
if (parentType === "SubProcess" || parentType === "Transaction" || parentType === "EventSubProcess" || parentType === "AdHocSubProcess") {
|
|
136
|
+
return isBpmnProcessNode(childType) ? true : "Subprocesses can only contain BPMN process nodes.";
|
|
137
|
+
}
|
|
138
|
+
return `${parentType} cannot contain BPMN child elements.`;
|
|
139
|
+
}
|
|
140
|
+
function getDirectBpmnChildren(state, parentId) {
|
|
141
|
+
return state.nodes.filter((node) => node.parentId === parentId);
|
|
142
|
+
}
|
|
143
|
+
function getBpmnPoolLanes(state, poolId) {
|
|
144
|
+
return getDirectBpmnChildren(state, poolId).filter(
|
|
145
|
+
(node) => node.data.elementType === "Lane"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
function getNodeDimension(node, axis) {
|
|
149
|
+
return node[axis] ?? node.measured?.[axis] ?? getBpmnElementSize(node.data.elementType)[axis];
|
|
150
|
+
}
|
|
151
|
+
function resolvePoolLaneDirection(pool) {
|
|
152
|
+
return pool.data.orientation === "vertical" ? "horizontal" : "vertical";
|
|
153
|
+
}
|
|
154
|
+
function getBpmnLaneIndexAtPosition(state, poolId, position) {
|
|
155
|
+
const pool = getNode(state, poolId);
|
|
156
|
+
if (!pool) return 0;
|
|
157
|
+
const lanes = getBpmnPoolLanes(state, poolId);
|
|
158
|
+
const direction = resolvePoolLaneDirection(pool);
|
|
159
|
+
const axis = direction === "vertical" ? "y" : "x";
|
|
160
|
+
const sizeKey = direction === "vertical" ? "height" : "width";
|
|
161
|
+
for (let index = 0; index < lanes.length; index += 1) {
|
|
162
|
+
const lane = lanes[index];
|
|
163
|
+
const midpoint = lane.position[axis] + getNodeDimension(lane, sizeKey) / 2;
|
|
164
|
+
if (position[axis] < midpoint) return index;
|
|
165
|
+
}
|
|
166
|
+
return lanes.length;
|
|
167
|
+
}
|
|
168
|
+
function sortBpmnLanes(state, poolId, laneId, index) {
|
|
169
|
+
const lanes = getBpmnPoolLanes(state, poolId);
|
|
170
|
+
const currentIndex = lanes.findIndex((lane) => lane.id === laneId);
|
|
171
|
+
if (currentIndex < 0) return state;
|
|
172
|
+
const orderedIds = lanes.map((lane) => lane.id);
|
|
173
|
+
const [moved] = orderedIds.splice(currentIndex, 1);
|
|
174
|
+
orderedIds.splice(Math.max(0, Math.min(index, orderedIds.length)), 0, moved);
|
|
175
|
+
const order = new Map(orderedIds.map((id, laneIndex) => [id, laneIndex]));
|
|
176
|
+
return {
|
|
177
|
+
...state,
|
|
178
|
+
nodes: [...state.nodes].sort((a, b) => {
|
|
179
|
+
const aOrder = order.get(a.id);
|
|
180
|
+
const bOrder = order.get(b.id);
|
|
181
|
+
if (aOrder === void 0 && bOrder === void 0) return 0;
|
|
182
|
+
if (aOrder === void 0) return -1;
|
|
183
|
+
if (bOrder === void 0) return 1;
|
|
184
|
+
return aOrder - bOrder;
|
|
185
|
+
})
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function layoutBpmnPoolLanes(state, poolId) {
|
|
189
|
+
const pool = getNode(state, poolId);
|
|
190
|
+
if (!pool) return state;
|
|
191
|
+
const poolSize = getBpmnElementSize("Pool");
|
|
192
|
+
const direction = resolvePoolLaneDirection(pool);
|
|
193
|
+
const lanes = getBpmnPoolLanes(state, poolId);
|
|
194
|
+
let cursor = direction === "vertical" ? BPMN_POOL_LANE_LAYOUT.poolHeaderSize : 0;
|
|
195
|
+
let next = state;
|
|
196
|
+
for (const lane of lanes) {
|
|
197
|
+
const laneSize = getBpmnElementSize("Lane");
|
|
198
|
+
const width = direction === "vertical" ? Math.max(poolSize.minWidth - BPMN_POOL_LANE_LAYOUT.poolHeaderSize, lane.width ?? laneSize.width) : lane.width ?? laneSize.width;
|
|
199
|
+
const height = direction === "vertical" ? lane.height ?? laneSize.height : Math.max(poolSize.minHeight - BPMN_POOL_LANE_LAYOUT.poolHeaderSize, lane.height ?? laneSize.height);
|
|
200
|
+
next = patchNode(next, lane.id, {
|
|
201
|
+
position: direction === "vertical" ? { x: BPMN_POOL_LANE_LAYOUT.poolHeaderSize, y: cursor } : { x: cursor, y: BPMN_POOL_LANE_LAYOUT.poolHeaderSize },
|
|
202
|
+
width,
|
|
203
|
+
height,
|
|
204
|
+
data: { orientation: pool.data.orientation ?? "horizontal" }
|
|
205
|
+
});
|
|
206
|
+
cursor += (direction === "vertical" ? height : width) + BPMN_POOL_LANE_LAYOUT.laneGap;
|
|
207
|
+
}
|
|
208
|
+
const minWidth = direction === "vertical" ? poolSize.minWidth : Math.max(poolSize.minWidth, cursor);
|
|
209
|
+
const minHeight = direction === "vertical" ? Math.max(poolSize.minHeight, cursor) : poolSize.minHeight;
|
|
210
|
+
return resizeNode(next, poolId, { width: minWidth, height: minHeight });
|
|
211
|
+
}
|
|
212
|
+
function reorderBpmnLane(state, options) {
|
|
213
|
+
return layoutBpmnPoolLanes(
|
|
214
|
+
sortBpmnLanes(state, options.poolId, options.laneId, options.index),
|
|
215
|
+
options.poolId
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
function validateBpmnConnectionForEdgeType(state, edgeType, source, target) {
|
|
219
|
+
const rule = BPMN_EDGE_CONNECTION_RULES[edgeType];
|
|
220
|
+
if (!matchesConnectionCategory(source.data.elementType, rule.sourceCategories)) {
|
|
221
|
+
return `${edgeType} cannot start from ${source.data.elementType}.`;
|
|
222
|
+
}
|
|
223
|
+
if (!matchesConnectionCategory(target.data.elementType, rule.targetCategories)) {
|
|
224
|
+
return `${edgeType} cannot target ${target.data.elementType}.`;
|
|
225
|
+
}
|
|
226
|
+
const sameParent = (source.parentId ?? null) === (target.parentId ?? null);
|
|
227
|
+
if (sameParent && rule.allowSameParent === false) {
|
|
228
|
+
return `${edgeType} must connect BPMN elements in different participants/scopes.`;
|
|
229
|
+
}
|
|
230
|
+
if (!sameParent && rule.allowDifferentParent === false) {
|
|
231
|
+
return `${edgeType} must stay inside the same BPMN participant/scope.`;
|
|
232
|
+
}
|
|
233
|
+
if (edgeType === "sequenceFlow") {
|
|
234
|
+
if (source.data.elementType === "EndEvent") return "End events cannot have outgoing sequence flows.";
|
|
235
|
+
if (target.data.elementType === "StartEvent") return "Start events cannot have incoming sequence flows.";
|
|
236
|
+
return validateEdgeCardinality(state, edgeType, source, target);
|
|
237
|
+
}
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
function validateEdgeCardinality(state, edgeType, source, target) {
|
|
241
|
+
if (edgeType !== "sequenceFlow") return true;
|
|
242
|
+
const sourceMax = BPMN_ELEMENT_CATALOG[source.data.elementType].maxOutgoing;
|
|
243
|
+
const targetMax = BPMN_ELEMENT_CATALOG[target.data.elementType].maxIncoming;
|
|
244
|
+
const outgoing = getOutgoingEdges(state, source.id).filter(
|
|
245
|
+
(edge) => edge.data?.edgeType === "sequenceFlow"
|
|
246
|
+
);
|
|
247
|
+
const incoming = getIncomingEdges(state, target.id).filter(
|
|
248
|
+
(edge) => edge.data?.edgeType === "sequenceFlow"
|
|
249
|
+
);
|
|
250
|
+
if (sourceMax !== void 0 && outgoing.length >= sourceMax) {
|
|
251
|
+
return `${source.data.elementType} cannot have more than ${sourceMax} outgoing sequence flow(s).`;
|
|
252
|
+
}
|
|
253
|
+
if (targetMax !== void 0 && incoming.length >= targetMax) {
|
|
254
|
+
return `${target.data.elementType} cannot have more than ${targetMax} incoming sequence flow(s).`;
|
|
255
|
+
}
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
var bpmnConnectionValidators = [
|
|
259
|
+
({ state, source, target }) => {
|
|
260
|
+
if (source.id === target.id) return "BPMN self-connections are not allowed.";
|
|
261
|
+
const edgeType = inferBpmnEdgeType(state, source.id, target.id);
|
|
262
|
+
if (getHandlePolicy(source.data.elementType) === "none" || getHandlePolicy(target.data.elementType) === "none") {
|
|
263
|
+
return "Elements without BPMN connection handles cannot be directly connected.";
|
|
264
|
+
}
|
|
265
|
+
if (edgeType === "sequenceFlow") {
|
|
266
|
+
return validateBpmnConnectionForEdgeType(state, edgeType, source, target);
|
|
267
|
+
}
|
|
268
|
+
return validateBpmnConnectionForEdgeType(state, edgeType, source, target);
|
|
269
|
+
}
|
|
270
|
+
];
|
|
271
|
+
var BPMN_MODELING_RULES = createModelingRules({
|
|
272
|
+
connect: [
|
|
273
|
+
({ state, source, target }) => {
|
|
274
|
+
if (!source || !target) return false;
|
|
275
|
+
for (const validator of bpmnConnectionValidators) {
|
|
276
|
+
const result = validator({
|
|
277
|
+
state,
|
|
278
|
+
source,
|
|
279
|
+
target,
|
|
280
|
+
existingEdges: state.edges
|
|
281
|
+
});
|
|
282
|
+
if (result !== true) return result;
|
|
283
|
+
}
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
],
|
|
287
|
+
drop: [
|
|
288
|
+
({ node, parent }) => {
|
|
289
|
+
if (!node || !parent) return true;
|
|
290
|
+
if (node.data.elementType === "BoundaryEvent") {
|
|
291
|
+
return acceptsBoundaryEvents(parent.data.elementType) ? true : "Boundary events can only be attached to tasks or subprocesses.";
|
|
292
|
+
}
|
|
293
|
+
return canContainBpmnElement(parent.data.elementType, node.data.elementType);
|
|
294
|
+
}
|
|
295
|
+
],
|
|
296
|
+
reparent: [
|
|
297
|
+
({ node, parent }) => {
|
|
298
|
+
if (!node || !parent) return true;
|
|
299
|
+
if (node.data.elementType === "BoundaryEvent") {
|
|
300
|
+
return acceptsBoundaryEvents(parent.data.elementType) ? true : "Boundary events can only be reparented to tasks or subprocesses.";
|
|
301
|
+
}
|
|
302
|
+
return canContainBpmnElement(parent?.data.elementType, node.data.elementType);
|
|
303
|
+
}
|
|
304
|
+
],
|
|
305
|
+
delete: [() => true],
|
|
306
|
+
resize: [
|
|
307
|
+
({ node }) => !node || isBpmnElementResizable(node.data.elementType) ? true : `${node.data.elementType} is not resizable in BPMN.`
|
|
308
|
+
]
|
|
309
|
+
});
|
|
310
|
+
function createBpmnNodeCommand(options) {
|
|
311
|
+
return {
|
|
312
|
+
id: `bpmn.createNode.${options.id}`,
|
|
313
|
+
label: `Create ${options.elementType}`,
|
|
314
|
+
execute: (state) => addNode(state, createBpmnNode(options))
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function connectBpmnCommand(options) {
|
|
318
|
+
return {
|
|
319
|
+
id: `bpmn.connect.${options.id ?? `${options.source}-${options.target}`}`,
|
|
320
|
+
label: "Connect BPMN elements",
|
|
321
|
+
execute: (state) => {
|
|
322
|
+
const edgeType = options.edgeType ?? inferBpmnEdgeType(state, options.source, options.target);
|
|
323
|
+
const source = getNode(state, options.source);
|
|
324
|
+
const target = getNode(state, options.target);
|
|
325
|
+
if (!source) throw new Error(`Source node "${options.source}" does not exist.`);
|
|
326
|
+
if (!target) throw new Error(`Target node "${options.target}" does not exist.`);
|
|
327
|
+
const validation = validateBpmnConnectionForEdgeType(state, edgeType, source, target);
|
|
328
|
+
if (validation !== true) throw new Error(validation);
|
|
329
|
+
return connectNodes(
|
|
330
|
+
state,
|
|
331
|
+
{
|
|
332
|
+
source: options.source,
|
|
333
|
+
target: options.target,
|
|
334
|
+
type: edgeType,
|
|
335
|
+
...options.sourceHandle !== void 0 ? { sourceHandle: options.sourceHandle } : {},
|
|
336
|
+
...options.targetHandle !== void 0 ? { targetHandle: options.targetHandle } : {},
|
|
337
|
+
...options.id ? { id: options.id } : {},
|
|
338
|
+
data: {
|
|
339
|
+
edgeType,
|
|
340
|
+
...options.label ? { label: options.label } : {},
|
|
341
|
+
...options.data ?? {}
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
[]
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function attachBoundaryEventCommand(boundaryId, hostId) {
|
|
350
|
+
return {
|
|
351
|
+
id: `bpmn.attachBoundary.${boundaryId}.${hostId}`,
|
|
352
|
+
label: "Attach boundary event",
|
|
353
|
+
execute: (state) => {
|
|
354
|
+
const host = getNode(state, hostId);
|
|
355
|
+
if (!host || !acceptsBoundaryEvents(host.data.elementType)) {
|
|
356
|
+
throw new Error(`Element "${hostId}" cannot host boundary events.`);
|
|
357
|
+
}
|
|
358
|
+
const boundary = getNode(state, boundaryId);
|
|
359
|
+
if (!boundary || boundary.data.elementType !== "BoundaryEvent") {
|
|
360
|
+
throw new Error(`Element "${boundaryId}" is not a boundary event.`);
|
|
361
|
+
}
|
|
362
|
+
const reparented = reparentNode(state, boundaryId, { parentId: hostId });
|
|
363
|
+
return patchNode(reparented, boundaryId, {
|
|
364
|
+
data: { attachedToRef: hostId }
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function replaceBpmnNodeCommand(options) {
|
|
370
|
+
return {
|
|
371
|
+
id: `bpmn.replaceNode.${options.id}.${options.elementType}`,
|
|
372
|
+
label: `Replace with ${options.elementType}`,
|
|
373
|
+
execute: (state) => {
|
|
374
|
+
const current = getNode(state, options.id);
|
|
375
|
+
if (!current) throw new Error(`Element "${options.id}" does not exist.`);
|
|
376
|
+
const meta = BPMN_ELEMENT_CATALOG[options.elementType];
|
|
377
|
+
return replaceNode(state, options.id, {
|
|
378
|
+
...current,
|
|
379
|
+
type: options.elementType,
|
|
380
|
+
width: options.width ?? current.width ?? meta.defaultWidth,
|
|
381
|
+
height: options.height ?? current.height ?? meta.defaultHeight,
|
|
382
|
+
data: {
|
|
383
|
+
...current.data,
|
|
384
|
+
elementType: options.elementType,
|
|
385
|
+
...options.label ? { label: options.label } : {},
|
|
386
|
+
...options.data ?? {}
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function reparentBpmnNodeCommand(options) {
|
|
393
|
+
return {
|
|
394
|
+
id: `bpmn.reparent.${options.id}.${options.parentId ?? "root"}`,
|
|
395
|
+
label: "Reparent BPMN element",
|
|
396
|
+
execute: (state) => {
|
|
397
|
+
const node = getNode(state, options.id);
|
|
398
|
+
const parent = options.parentId ? getNode(state, options.parentId) : void 0;
|
|
399
|
+
if (!node) throw new Error(`Element "${options.id}" does not exist.`);
|
|
400
|
+
if (parent && node.data.elementType === "BoundaryEvent" && !acceptsBoundaryEvents(parent.data.elementType)) {
|
|
401
|
+
throw new Error("Boundary events can only be reparented to tasks or subprocesses.");
|
|
402
|
+
}
|
|
403
|
+
const containment = canContainBpmnElement(parent?.data.elementType, node.data.elementType);
|
|
404
|
+
if (containment !== true) throw new Error(containment);
|
|
405
|
+
const reparented = reparentNode(state, options.id, {
|
|
406
|
+
...options.parentId !== void 0 ? { parentId: options.parentId } : {},
|
|
407
|
+
...options.position ? { position: options.position } : {}
|
|
408
|
+
});
|
|
409
|
+
return parent?.data.elementType === "Pool" && node.data.elementType === "Lane" ? layoutBpmnPoolLanes(reparented, parent.id) : reparented;
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function resizeBpmnNodeCommand(options) {
|
|
414
|
+
return {
|
|
415
|
+
id: `bpmn.resize.${options.id}`,
|
|
416
|
+
label: "Resize BPMN element",
|
|
417
|
+
execute: (state) => {
|
|
418
|
+
const node = getNode(state, options.id);
|
|
419
|
+
if (!node) throw new Error(`Element "${options.id}" does not exist.`);
|
|
420
|
+
const size = getBpmnElementSize(node.data.elementType);
|
|
421
|
+
if (!size.resizable) {
|
|
422
|
+
throw new Error(`${node.data.elementType} is not resizable in BPMN.`);
|
|
423
|
+
}
|
|
424
|
+
return resizeNode(state, options.id, {
|
|
425
|
+
width: options.width === void 0 ? void 0 : Math.max(size.minWidth, options.width),
|
|
426
|
+
height: options.height === void 0 ? void 0 : Math.max(size.minHeight, options.height)
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
function reorderBpmnLaneCommand(options) {
|
|
432
|
+
return {
|
|
433
|
+
id: `bpmn.reorderLane.${options.poolId}.${options.laneId}`,
|
|
434
|
+
label: "Reorder BPMN lane",
|
|
435
|
+
execute: (state) => {
|
|
436
|
+
const pool = getNode(state, options.poolId);
|
|
437
|
+
const lane = getNode(state, options.laneId);
|
|
438
|
+
if (!pool || pool.data.elementType !== "Pool") {
|
|
439
|
+
throw new Error(`Element "${options.poolId}" is not a pool.`);
|
|
440
|
+
}
|
|
441
|
+
if (!lane || lane.data.elementType !== "Lane" || lane.parentId !== options.poolId) {
|
|
442
|
+
throw new Error(`Element "${options.laneId}" is not a lane in pool "${options.poolId}".`);
|
|
443
|
+
}
|
|
444
|
+
return reorderBpmnLane(state, options);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function moveBpmnLaneCommand(options) {
|
|
449
|
+
return {
|
|
450
|
+
id: `bpmn.moveLane.${options.poolId}.${options.laneId}`,
|
|
451
|
+
label: "Move BPMN lane",
|
|
452
|
+
execute: (state) => reorderBpmnLane(state, {
|
|
453
|
+
poolId: options.poolId,
|
|
454
|
+
laneId: options.laneId,
|
|
455
|
+
index: getBpmnLaneIndexAtPosition(state, options.poolId, options.position)
|
|
456
|
+
})
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function routeBpmnEdgeCommand(options) {
|
|
460
|
+
return {
|
|
461
|
+
id: `bpmn.routeEdge.${options.id}`,
|
|
462
|
+
label: "Route BPMN edge",
|
|
463
|
+
execute: (state) => {
|
|
464
|
+
const edge = state.edges.find((item) => item.id === options.id);
|
|
465
|
+
if (!edge) throw new Error(`Edge "${options.id}" does not exist.`);
|
|
466
|
+
const edgeType = edge.data?.edgeType;
|
|
467
|
+
if (!edgeType || !isBpmnEdgeRoutingEditable(edgeType)) {
|
|
468
|
+
throw new Error(`${edgeType ?? "edge"} routing points cannot be edited.`);
|
|
469
|
+
}
|
|
470
|
+
return patchEdge(state, options.id, {
|
|
471
|
+
data: { routingPoints: options.routingPoints }
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function deleteBpmnElementsCommand(ids) {
|
|
477
|
+
return {
|
|
478
|
+
id: `bpmn.delete.${ids.join(".")}`,
|
|
479
|
+
label: "Delete BPMN elements",
|
|
480
|
+
execute: (state) => removeElements(state, ids)
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
function copyBpmnElements(state, selection) {
|
|
484
|
+
return copyElements(state, selection);
|
|
485
|
+
}
|
|
486
|
+
function pasteBpmnElementsCommand(clipboard, options = {}) {
|
|
487
|
+
return {
|
|
488
|
+
id: "bpmn.paste",
|
|
489
|
+
label: "Paste BPMN elements",
|
|
490
|
+
execute: (state) => pasteElements(state, clipboard, options)
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function selectBpmnElementsCommand(selection) {
|
|
494
|
+
return {
|
|
495
|
+
id: "bpmn.select",
|
|
496
|
+
label: "Select BPMN elements",
|
|
497
|
+
execute: (state) => setSelection(state, createSelectionState(selection.nodeIds, selection.edgeIds))
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function createBpmnDiagramDocument(state, options = {}) {
|
|
501
|
+
return createDiagramDocument(normalizeDiagramState(state), {
|
|
502
|
+
...options,
|
|
503
|
+
diagramType: "bpmn"
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
function serializeBpmnDiagram(state, options = {}) {
|
|
507
|
+
return serializeDiagram(normalizeDiagramState(state), {
|
|
508
|
+
...options,
|
|
509
|
+
diagramType: "bpmn"
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
function parseBpmnDiagramDocument(json) {
|
|
513
|
+
const document = parseDiagramDocument(json);
|
|
514
|
+
if (document.diagramType && document.diagramType !== "bpmn") {
|
|
515
|
+
throw new Error(`Expected a BPMN diagram document, received "${document.diagramType}".`);
|
|
516
|
+
}
|
|
517
|
+
return document;
|
|
518
|
+
}
|
|
519
|
+
function deserializeBpmnDiagram(json) {
|
|
520
|
+
const document = parseBpmnDiagramDocument(json);
|
|
521
|
+
return deserializeDiagram(JSON.stringify(document));
|
|
522
|
+
}
|
|
523
|
+
function runBpmnCommand(stack, command) {
|
|
524
|
+
return executeCommand(stack, command);
|
|
525
|
+
}
|
|
526
|
+
function runBpmnCommands(stack, commands, options = {}) {
|
|
527
|
+
return executeCommands(stack, commands, options);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export { BPMN_EDGE_CONNECTION_RULES, BPMN_MODELING_RULES, BPMN_POOL_LANE_LAYOUT, BPMN_ROUTABLE_EDGE_TYPES, BPMN_SELECTION_STYLE, attachBoundaryEventCommand, bpmnConnectionValidators, canContainBpmnElement, connectBpmnCommand, copyBpmnElements, createBpmnDiagramDocument, createBpmnNode, createBpmnNodeCommand, deleteBpmnElementsCommand, deserializeBpmnDiagram, getBpmnDragHandleSelector, getBpmnLaneIndexAtPosition, getBpmnPoolLanes, inferBpmnEdgeType, isBpmnEdgeRoutingEditable, isBpmnProcessNode, layoutBpmnPoolLanes, moveBpmnLaneCommand, parseBpmnDiagramDocument, pasteBpmnElementsCommand, reorderBpmnLane, reorderBpmnLaneCommand, reparentBpmnNodeCommand, replaceBpmnNodeCommand, resizeBpmnNodeCommand, routeBpmnEdgeCommand, runBpmnCommand, runBpmnCommands, selectBpmnElementsCommand, serializeBpmnDiagram, validateBpmnConnectionForEdgeType };
|
|
531
|
+
//# sourceMappingURL=chunk-YQTIODXH.js.map
|
|
532
|
+
//# sourceMappingURL=chunk-YQTIODXH.js.map
|
|
@@ -0,0 +1 @@
|
|
|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AiB,qBAAA,CAAsB,KAAK,CAAA,EAAG;AAAA,IACpD,GAAG,OAAA;AAAA,IACH,WAAA,EAAa;AAAA,GACd,CAAA;AACH;AAEO,SAAS,yBAAyB,IAAA,EAAmC;AAC1E,EAAA,MAAM,QAAA,GAAW,qBAA6C,IAAI,CAAA;AAClE,EAAA,IAAI,QAAA,CAAS,WAAA,IAAe,QAAA,CAAS,WAAA,KAAgB,MAAA,EAAQ;AAC3D,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,4CAAA,EAA+C,QAAA,CAAS,WAAW,CAAA,EAAA,CAAI,CAAA;AAAA,EACzF;AACA,EAAA,OAAO,QAAA;AACT;AAEO,SAAS,uBAAuB,IAAA,EAAgC;AACrE,EAAA,MAAM,QAAA,GAAW,yBAAyB,IAAI,CAAA;AAC9C,EAAA,OAAO,kBAAA,CAA2C,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAC,CAAA;AAC5E;AAEO,SAAS,cAAA,CACd,OACA,OAAA,EAC2C;AAC3C,EAAA,OAAO,cAAA,CAAe,OAAO,OAAO,CAAA;AACtC;AAEO,SAAS,eAAA,CACd,KAAA,EACA,QAAA,EACA,OAAA,GAA2C,EAAC,EACD;AAC3C,EAAA,OAAO,eAAA,CAAgB,KAAA,EAAO,QAAA,EAAU,OAAO,CAAA;AACjD","file":"chunk-YQTIODXH.js","sourcesContent":["import {\n addNode,\n connectNodes,\n copyElements,\n createModelingRules,\n createSelectionState,\n executeCommand,\n executeCommands,\n getNode,\n getOutgoingEdges,\n getIncomingEdges,\n normalizeDiagramState,\n pasteElements,\n patchEdge,\n patchNode,\n removeElements,\n replaceNode,\n reparentNode,\n resizeNode,\n setSelection,\n type CommandStackState,\n type ClipboardState,\n type ConnectionValidator,\n type DiagramCommand,\n type DiagramState,\n type ModelingRules,\n type SelectionState,\n} from \"@aranzatech/diagrams-core\";\nimport {\n createDiagramDocument,\n deserializeDiagram,\n parseDiagramDocument,\n serializeDiagram,\n type CreateDiagramDocumentOptions,\n type DiagramDocument,\n} from \"@aranzatech/diagrams-core/serialization\";\nimport {\n BPMN_ELEMENT_CATALOG,\n getBpmnElementSize,\n isBpmnElementResizable,\n} from \"../elements/catalog\";\nimport {\n acceptsBoundaryEvents,\n getHandlePolicy,\n isDataType,\n isEventType,\n isGatewayType,\n} from \"../elements/guards\";\nimport type { BpmnElementType, BpmnEdgeData, BpmnEdgeType, BpmnNodeData } from \"../elements/types\";\nimport type { BpmnRFEdge, BpmnRFNode } from \"../xml/types\";\n\nexport { getBpmnElementSize, isBpmnElementResizable } from \"../elements/catalog\";\n\nexport type BpmnDiagramState = DiagramState<BpmnRFNode, BpmnRFEdge>;\nexport type BpmnClipboardState = ClipboardState<BpmnRFNode, BpmnRFEdge>;\nexport type BpmnDiagramDocument = DiagramDocument<BpmnRFNode, BpmnRFEdge>;\n\nexport interface CreateBpmnNodeOptions {\n id: string;\n elementType: BpmnElementType;\n position: { x: number; y: number };\n label?: string;\n parentId?: string;\n width?: number;\n height?: number;\n data?: Partial<BpmnNodeData>;\n}\n\nexport interface ConnectBpmnOptions {\n id?: string;\n source: string;\n target: string;\n edgeType?: BpmnEdgeType;\n label?: string;\n sourceHandle?: string | null;\n targetHandle?: string | null;\n data?: Partial<BpmnEdgeData>;\n}\n\nexport interface ReplaceBpmnNodeOptions {\n id: string;\n elementType: BpmnElementType;\n label?: string;\n data?: Partial<BpmnNodeData>;\n width?: number;\n height?: number;\n}\n\nexport interface ReparentBpmnNodeOptions {\n id: string;\n parentId?: string;\n position?: { x: number; y: number };\n}\n\nexport interface ResizeBpmnNodeOptions {\n id: string;\n width?: number;\n height?: number;\n}\n\nexport interface ReorderBpmnLaneOptions {\n poolId: string;\n laneId: string;\n index: number;\n}\n\nexport interface MoveBpmnLaneOptions {\n poolId: string;\n laneId: string;\n position: { x: number; y: number };\n}\n\nexport interface RouteBpmnEdgeOptions {\n id: string;\n routingPoints: Array<{ x: number; y: number }>;\n}\n\nexport interface PasteBpmnOptions {\n offset?: { x: number; y: number };\n position?: { x: number; y: number };\n}\n\nexport function createBpmnNode(options: CreateBpmnNodeOptions): BpmnRFNode {\n const size = getBpmnElementSize(options.elementType);\n const meta = BPMN_ELEMENT_CATALOG[options.elementType];\n const orientation = options.data?.orientation ?? meta.orientation;\n const dragHandle = getBpmnDragHandleSelector(options.elementType);\n return {\n id: options.id,\n type: options.elementType,\n position: options.position,\n data: {\n elementType: options.elementType,\n orientation,\n ...(options.label ? { label: options.label } : {}),\n ...(options.data ?? {}),\n },\n width: options.width ?? size.width,\n height: options.height ?? size.height,\n ...(options.parentId ? { parentId: options.parentId } : {}),\n ...(dragHandle ? { dragHandle } : {}),\n };\n}\n\nexport const BPMN_POOL_LANE_LAYOUT = {\n poolHeaderSize: 30,\n laneHeaderSize: 24,\n laneGap: 0,\n} as const;\n\nexport function getBpmnDragHandleSelector(\n elementType: BpmnElementType,\n): string | undefined {\n if (elementType === \"Pool\") return \".pool-drag-handle\";\n if (elementType === \"Lane\") return \".lane-drag-handle\";\n return undefined;\n}\n\nexport const BPMN_SELECTION_STYLE = {\n nodeOutline: \"#2563eb\",\n edgeStroke: \"#2563eb\",\n handleFill: \"#ffffff\",\n handleStroke: \"#2563eb\",\n resizeHandleSize: 8,\n routingPointRadius: 5,\n} as const;\n\nexport const BPMN_ROUTABLE_EDGE_TYPES = [\n \"sequenceFlow\",\n \"messageFlow\",\n \"association\",\n \"dataAssociation\",\n \"conversationLink\",\n] satisfies BpmnEdgeType[];\n\nexport interface BpmnConnectionRule {\n edgeType: BpmnEdgeType;\n sourceCategories: Array<BpmnRFNode[\"data\"][\"elementType\"] | \"flowNode\" | \"data\" | \"artifact\" | \"conversation\">;\n targetCategories: Array<BpmnRFNode[\"data\"][\"elementType\"] | \"flowNode\" | \"data\" | \"artifact\" | \"conversation\">;\n allowSameParent?: boolean;\n allowDifferentParent?: boolean;\n}\n\nexport const BPMN_EDGE_CONNECTION_RULES: Record<BpmnEdgeType, BpmnConnectionRule> = {\n sequenceFlow: {\n edgeType: \"sequenceFlow\",\n sourceCategories: [\"flowNode\"],\n targetCategories: [\"flowNode\"],\n allowSameParent: true,\n allowDifferentParent: false,\n },\n messageFlow: {\n edgeType: \"messageFlow\",\n sourceCategories: [\"flowNode\"],\n targetCategories: [\"flowNode\"],\n allowSameParent: false,\n allowDifferentParent: true,\n },\n association: {\n edgeType: \"association\",\n sourceCategories: [\"flowNode\", \"artifact\", \"data\"],\n targetCategories: [\"flowNode\", \"artifact\", \"data\"],\n allowSameParent: true,\n allowDifferentParent: true,\n },\n dataAssociation: {\n edgeType: \"dataAssociation\",\n sourceCategories: [\"flowNode\", \"data\"],\n targetCategories: [\"flowNode\", \"data\"],\n allowSameParent: true,\n allowDifferentParent: true,\n },\n conversationLink: {\n edgeType: \"conversationLink\",\n sourceCategories: [\"conversation\", \"flowNode\"],\n targetCategories: [\"conversation\", \"flowNode\"],\n allowSameParent: true,\n allowDifferentParent: true,\n },\n};\n\nexport function inferBpmnEdgeType(\n state: BpmnDiagramState,\n sourceId: string,\n targetId: string,\n): BpmnEdgeType {\n const source = getNode(state, sourceId);\n const target = getNode(state, targetId);\n if (!source || !target) return \"sequenceFlow\";\n\n if (isDataType(source.data.elementType) || isDataType(target.data.elementType)) {\n return \"dataAssociation\";\n }\n if (\n source.data.elementType === \"Annotation\" ||\n target.data.elementType === \"Annotation\" ||\n source.data.elementType === \"Group\" ||\n target.data.elementType === \"Group\"\n ) {\n return \"association\";\n }\n if (\n source.data.elementType === \"Conversation\" ||\n source.data.elementType === \"SubConversation\" ||\n source.data.elementType === \"CallConversation\" ||\n target.data.elementType === \"Conversation\" ||\n target.data.elementType === \"SubConversation\" ||\n target.data.elementType === \"CallConversation\"\n ) {\n return \"conversationLink\";\n }\n if (source.parentId && target.parentId && source.parentId !== target.parentId) {\n return \"messageFlow\";\n }\n return \"sequenceFlow\";\n}\n\nfunction canUseSequenceFlow(type: BpmnElementType): boolean {\n const meta = BPMN_ELEMENT_CATALOG[type];\n return (\n meta.handlePolicy !== \"none\" &&\n !isDataType(type) &&\n type !== \"Annotation\" &&\n type !== \"Group\" &&\n meta.category !== \"conversation\"\n );\n}\n\nfunction matchesConnectionCategory(\n type: BpmnElementType,\n categories: BpmnConnectionRule[\"sourceCategories\"],\n): boolean {\n return categories.some((category) => {\n if (category === type) return true;\n if (category === \"flowNode\") return canUseSequenceFlow(type);\n if (category === \"data\") return isDataType(type);\n if (category === \"artifact\") return type === \"Annotation\" || type === \"Group\";\n if (category === \"conversation\") return BPMN_ELEMENT_CATALOG[type].category === \"conversation\";\n return false;\n });\n}\n\nexport function isBpmnEdgeRoutingEditable(edgeType: BpmnEdgeType): boolean {\n return BPMN_ROUTABLE_EDGE_TYPES.includes(edgeType);\n}\n\nexport function isBpmnProcessNode(type: BpmnElementType): boolean {\n return (\n isEventType(type) ||\n isGatewayType(type) ||\n type.includes(\"Task\") ||\n type === \"CallActivity\" ||\n type === \"SubProcess\" ||\n type === \"Transaction\" ||\n type === \"EventSubProcess\" ||\n type === \"AdHocSubProcess\"\n );\n}\n\nexport function canContainBpmnElement(\n parentType: BpmnElementType | undefined,\n childType: BpmnElementType,\n): true | string {\n if (!parentType) return true;\n if (parentType === \"Pool\") {\n return childType === \"Lane\" || isBpmnProcessNode(childType)\n ? true\n : \"Pools can contain lanes or BPMN process nodes.\";\n }\n if (parentType === \"Lane\") {\n return isBpmnProcessNode(childType)\n ? true\n : \"Lanes can only contain BPMN process nodes.\";\n }\n if (\n parentType === \"SubProcess\" ||\n parentType === \"Transaction\" ||\n parentType === \"EventSubProcess\" ||\n parentType === \"AdHocSubProcess\"\n ) {\n return isBpmnProcessNode(childType)\n ? true\n : \"Subprocesses can only contain BPMN process nodes.\";\n }\n return `${parentType} cannot contain BPMN child elements.`;\n}\n\nfunction getDirectBpmnChildren(\n state: BpmnDiagramState,\n parentId: string,\n): BpmnRFNode[] {\n return state.nodes.filter((node) => node.parentId === parentId);\n}\n\nexport function getBpmnPoolLanes(\n state: BpmnDiagramState,\n poolId: string,\n): BpmnRFNode[] {\n return getDirectBpmnChildren(state, poolId).filter(\n (node) => node.data.elementType === \"Lane\",\n );\n}\n\nfunction getNodeDimension(node: BpmnRFNode, axis: \"width\" | \"height\"): number {\n return node[axis] ?? node.measured?.[axis] ?? getBpmnElementSize(node.data.elementType)[axis];\n}\n\nfunction resolvePoolLaneDirection(pool: BpmnRFNode): \"horizontal\" | \"vertical\" {\n return pool.data.orientation === \"vertical\" ? \"horizontal\" : \"vertical\";\n}\n\nexport function getBpmnLaneIndexAtPosition(\n state: BpmnDiagramState,\n poolId: string,\n position: { x: number; y: number },\n): number {\n const pool = getNode(state, poolId);\n if (!pool) return 0;\n const lanes = getBpmnPoolLanes(state, poolId);\n const direction = resolvePoolLaneDirection(pool);\n const axis = direction === \"vertical\" ? \"y\" : \"x\";\n const sizeKey = direction === \"vertical\" ? \"height\" : \"width\";\n\n for (let index = 0; index < lanes.length; index += 1) {\n const lane = lanes[index];\n const midpoint = lane.position[axis] + getNodeDimension(lane, sizeKey) / 2;\n if (position[axis] < midpoint) return index;\n }\n return lanes.length;\n}\n\nfunction sortBpmnLanes(\n state: BpmnDiagramState,\n poolId: string,\n laneId: string,\n index: number,\n): BpmnDiagramState {\n const lanes = getBpmnPoolLanes(state, poolId);\n const currentIndex = lanes.findIndex((lane) => lane.id === laneId);\n if (currentIndex < 0) return state;\n\n const orderedIds = lanes.map((lane) => lane.id);\n const [moved] = orderedIds.splice(currentIndex, 1);\n orderedIds.splice(Math.max(0, Math.min(index, orderedIds.length)), 0, moved);\n const order = new Map(orderedIds.map((id, laneIndex) => [id, laneIndex]));\n\n return {\n ...state,\n nodes: [...state.nodes].sort((a, b) => {\n const aOrder = order.get(a.id);\n const bOrder = order.get(b.id);\n if (aOrder === undefined && bOrder === undefined) return 0;\n if (aOrder === undefined) return -1;\n if (bOrder === undefined) return 1;\n return aOrder - bOrder;\n }),\n };\n}\n\nexport function layoutBpmnPoolLanes(\n state: BpmnDiagramState,\n poolId: string,\n): BpmnDiagramState {\n const pool = getNode(state, poolId);\n if (!pool) return state;\n const poolSize = getBpmnElementSize(\"Pool\");\n const direction = resolvePoolLaneDirection(pool);\n const lanes = getBpmnPoolLanes(state, poolId);\n let cursor = direction === \"vertical\" ? BPMN_POOL_LANE_LAYOUT.poolHeaderSize : 0;\n\n let next = state;\n for (const lane of lanes) {\n const laneSize = getBpmnElementSize(\"Lane\");\n const width =\n direction === \"vertical\"\n ? Math.max(poolSize.minWidth - BPMN_POOL_LANE_LAYOUT.poolHeaderSize, lane.width ?? laneSize.width)\n : lane.width ?? laneSize.width;\n const height =\n direction === \"vertical\"\n ? lane.height ?? laneSize.height\n : Math.max(poolSize.minHeight - BPMN_POOL_LANE_LAYOUT.poolHeaderSize, lane.height ?? laneSize.height);\n next = patchNode(next, lane.id, {\n position: direction === \"vertical\" ? { x: BPMN_POOL_LANE_LAYOUT.poolHeaderSize, y: cursor } : { x: cursor, y: BPMN_POOL_LANE_LAYOUT.poolHeaderSize },\n width,\n height,\n data: { orientation: pool.data.orientation ?? \"horizontal\" },\n });\n cursor += (direction === \"vertical\" ? height : width) + BPMN_POOL_LANE_LAYOUT.laneGap;\n }\n\n const minWidth =\n direction === \"vertical\"\n ? poolSize.minWidth\n : Math.max(poolSize.minWidth, cursor);\n const minHeight =\n direction === \"vertical\"\n ? Math.max(poolSize.minHeight, cursor)\n : poolSize.minHeight;\n return resizeNode(next, poolId, { width: minWidth, height: minHeight } as Parameters<typeof resizeNode<BpmnRFNode, BpmnRFEdge>>[2]);\n}\n\nexport function reorderBpmnLane(\n state: BpmnDiagramState,\n options: ReorderBpmnLaneOptions,\n): BpmnDiagramState {\n return layoutBpmnPoolLanes(\n sortBpmnLanes(state, options.poolId, options.laneId, options.index),\n options.poolId,\n );\n}\n\nexport function validateBpmnConnectionForEdgeType(\n state: BpmnDiagramState,\n edgeType: BpmnEdgeType,\n source: BpmnRFNode,\n target: BpmnRFNode,\n): true | string {\n const rule = BPMN_EDGE_CONNECTION_RULES[edgeType];\n if (!matchesConnectionCategory(source.data.elementType, rule.sourceCategories)) {\n return `${edgeType} cannot start from ${source.data.elementType}.`;\n }\n if (!matchesConnectionCategory(target.data.elementType, rule.targetCategories)) {\n return `${edgeType} cannot target ${target.data.elementType}.`;\n }\n const sameParent = (source.parentId ?? null) === (target.parentId ?? null);\n if (sameParent && rule.allowSameParent === false) {\n return `${edgeType} must connect BPMN elements in different participants/scopes.`;\n }\n if (!sameParent && rule.allowDifferentParent === false) {\n return `${edgeType} must stay inside the same BPMN participant/scope.`;\n }\n if (edgeType === \"sequenceFlow\") {\n if (source.data.elementType === \"EndEvent\") return \"End events cannot have outgoing sequence flows.\";\n if (target.data.elementType === \"StartEvent\") return \"Start events cannot have incoming sequence flows.\";\n return validateEdgeCardinality(state, edgeType, source, target);\n }\n return true;\n}\n\nfunction validateEdgeCardinality(\n state: BpmnDiagramState,\n edgeType: BpmnEdgeType,\n source: BpmnRFNode,\n target: BpmnRFNode,\n): true | string {\n if (edgeType !== \"sequenceFlow\") return true;\n\n const sourceMax = BPMN_ELEMENT_CATALOG[source.data.elementType].maxOutgoing;\n const targetMax = BPMN_ELEMENT_CATALOG[target.data.elementType].maxIncoming;\n const outgoing = getOutgoingEdges(state, source.id).filter(\n (edge) => edge.data?.edgeType === \"sequenceFlow\",\n );\n const incoming = getIncomingEdges(state, target.id).filter(\n (edge) => edge.data?.edgeType === \"sequenceFlow\",\n );\n\n if (sourceMax !== undefined && outgoing.length >= sourceMax) {\n return `${source.data.elementType} cannot have more than ${sourceMax} outgoing sequence flow(s).`;\n }\n if (targetMax !== undefined && incoming.length >= targetMax) {\n return `${target.data.elementType} cannot have more than ${targetMax} incoming sequence flow(s).`;\n }\n return true;\n}\n\nexport const bpmnConnectionValidators: Array<\n ConnectionValidator<BpmnRFNode, BpmnRFEdge>\n> = [\n ({ state, source, target }) => {\n if (source.id === target.id) return \"BPMN self-connections are not allowed.\";\n const edgeType = inferBpmnEdgeType(state, source.id, target.id);\n\n if (getHandlePolicy(source.data.elementType) === \"none\" || getHandlePolicy(target.data.elementType) === \"none\") {\n return \"Elements without BPMN connection handles cannot be directly connected.\";\n }\n\n if (edgeType === \"sequenceFlow\") {\n return validateBpmnConnectionForEdgeType(state, edgeType, source, target);\n }\n\n return validateBpmnConnectionForEdgeType(state, edgeType, source, target);\n },\n];\n\nexport const BPMN_MODELING_RULES: ModelingRules<BpmnRFNode, BpmnRFEdge> =\n createModelingRules({\n connect: [\n ({ state, source, target }) => {\n if (!source || !target) return false;\n for (const validator of bpmnConnectionValidators) {\n const result = validator({\n state,\n source,\n target,\n existingEdges: state.edges,\n });\n if (result !== true) return result;\n }\n return true;\n },\n ],\n drop: [\n ({ node, parent }) => {\n if (!node || !parent) return true;\n if (node.data.elementType === \"BoundaryEvent\") {\n return acceptsBoundaryEvents(parent.data.elementType)\n ? true\n : \"Boundary events can only be attached to tasks or subprocesses.\";\n }\n return canContainBpmnElement(parent.data.elementType, node.data.elementType);\n },\n ],\n reparent: [\n ({ node, parent }) => {\n if (!node || !parent) return true;\n if (node.data.elementType === \"BoundaryEvent\") {\n return acceptsBoundaryEvents(parent.data.elementType)\n ? true\n : \"Boundary events can only be reparented to tasks or subprocesses.\";\n }\n return canContainBpmnElement(parent?.data.elementType, node.data.elementType);\n },\n ],\n delete: [() => true],\n resize: [\n ({ node }) =>\n !node || isBpmnElementResizable(node.data.elementType)\n ? true\n : `${node.data.elementType} is not resizable in BPMN.`,\n ],\n });\n\nexport function createBpmnNodeCommand(\n options: CreateBpmnNodeOptions,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.createNode.${options.id}`,\n label: `Create ${options.elementType}`,\n execute: (state) => addNode(state, createBpmnNode(options)),\n };\n}\n\nexport function connectBpmnCommand(\n options: ConnectBpmnOptions,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.connect.${options.id ?? `${options.source}-${options.target}`}`,\n label: \"Connect BPMN elements\",\n execute: (state) => {\n const edgeType = options.edgeType ?? inferBpmnEdgeType(state, options.source, options.target);\n const source = getNode(state, options.source);\n const target = getNode(state, options.target);\n if (!source) throw new Error(`Source node \"${options.source}\" does not exist.`);\n if (!target) throw new Error(`Target node \"${options.target}\" does not exist.`);\n const validation = validateBpmnConnectionForEdgeType(state, edgeType, source, target);\n if (validation !== true) throw new Error(validation);\n return connectNodes(\n state,\n {\n source: options.source,\n target: options.target,\n type: edgeType,\n ...(options.sourceHandle !== undefined\n ? { sourceHandle: options.sourceHandle }\n : {}),\n ...(options.targetHandle !== undefined\n ? { targetHandle: options.targetHandle }\n : {}),\n ...(options.id ? { id: options.id } : {}),\n data: {\n edgeType,\n ...(options.label ? { label: options.label } : {}),\n ...(options.data ?? {}),\n },\n },\n [],\n );\n },\n };\n}\n\nexport function attachBoundaryEventCommand(\n boundaryId: string,\n hostId: string,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.attachBoundary.${boundaryId}.${hostId}`,\n label: \"Attach boundary event\",\n execute: (state) => {\n const host = getNode(state, hostId);\n if (!host || !acceptsBoundaryEvents(host.data.elementType)) {\n throw new Error(`Element \"${hostId}\" cannot host boundary events.`);\n }\n const boundary = getNode(state, boundaryId);\n if (!boundary || boundary.data.elementType !== \"BoundaryEvent\") {\n throw new Error(`Element \"${boundaryId}\" is not a boundary event.`);\n }\n const reparented = reparentNode(state, boundaryId, { parentId: hostId });\n return patchNode(reparented, boundaryId, {\n data: { attachedToRef: hostId },\n });\n },\n };\n}\n\nexport function replaceBpmnNodeCommand(\n options: ReplaceBpmnNodeOptions,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.replaceNode.${options.id}.${options.elementType}`,\n label: `Replace with ${options.elementType}`,\n execute: (state) => {\n const current = getNode(state, options.id);\n if (!current) throw new Error(`Element \"${options.id}\" does not exist.`);\n const meta = BPMN_ELEMENT_CATALOG[options.elementType];\n return replaceNode(state, options.id, {\n ...current,\n type: options.elementType,\n width: options.width ?? current.width ?? meta.defaultWidth,\n height: options.height ?? current.height ?? meta.defaultHeight,\n data: {\n ...current.data,\n elementType: options.elementType,\n ...(options.label ? { label: options.label } : {}),\n ...(options.data ?? {}),\n },\n });\n },\n };\n}\n\nexport function reparentBpmnNodeCommand(\n options: ReparentBpmnNodeOptions,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.reparent.${options.id}.${options.parentId ?? \"root\"}`,\n label: \"Reparent BPMN element\",\n execute: (state) => {\n const node = getNode(state, options.id);\n const parent = options.parentId ? getNode(state, options.parentId) : undefined;\n if (!node) throw new Error(`Element \"${options.id}\" does not exist.`);\n if (parent && node.data.elementType === \"BoundaryEvent\" && !acceptsBoundaryEvents(parent.data.elementType)) {\n throw new Error(\"Boundary events can only be reparented to tasks or subprocesses.\");\n }\n const containment = canContainBpmnElement(parent?.data.elementType, node.data.elementType);\n if (containment !== true) throw new Error(containment);\n const reparented = reparentNode(state, options.id, {\n ...(options.parentId !== undefined ? { parentId: options.parentId } : {}),\n ...(options.position ? { position: options.position } : {}),\n });\n return parent?.data.elementType === \"Pool\" && node.data.elementType === \"Lane\"\n ? layoutBpmnPoolLanes(reparented, parent.id)\n : reparented;\n },\n };\n}\n\nexport function resizeBpmnNodeCommand(\n options: ResizeBpmnNodeOptions,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.resize.${options.id}`,\n label: \"Resize BPMN element\",\n execute: (state) => {\n const node = getNode(state, options.id);\n if (!node) throw new Error(`Element \"${options.id}\" does not exist.`);\n const size = getBpmnElementSize(node.data.elementType);\n if (!size.resizable) {\n throw new Error(`${node.data.elementType} is not resizable in BPMN.`);\n }\n return resizeNode(state, options.id, {\n width:\n options.width === undefined\n ? undefined\n : Math.max(size.minWidth, options.width),\n height:\n options.height === undefined\n ? undefined\n : Math.max(size.minHeight, options.height),\n } as Parameters<typeof resizeNode<BpmnRFNode, BpmnRFEdge>>[2]);\n },\n };\n}\n\nexport function reorderBpmnLaneCommand(\n options: ReorderBpmnLaneOptions,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.reorderLane.${options.poolId}.${options.laneId}`,\n label: \"Reorder BPMN lane\",\n execute: (state) => {\n const pool = getNode(state, options.poolId);\n const lane = getNode(state, options.laneId);\n if (!pool || pool.data.elementType !== \"Pool\") {\n throw new Error(`Element \"${options.poolId}\" is not a pool.`);\n }\n if (!lane || lane.data.elementType !== \"Lane\" || lane.parentId !== options.poolId) {\n throw new Error(`Element \"${options.laneId}\" is not a lane in pool \"${options.poolId}\".`);\n }\n return reorderBpmnLane(state, options);\n },\n };\n}\n\nexport function moveBpmnLaneCommand(\n options: MoveBpmnLaneOptions,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.moveLane.${options.poolId}.${options.laneId}`,\n label: \"Move BPMN lane\",\n execute: (state) =>\n reorderBpmnLane(state, {\n poolId: options.poolId,\n laneId: options.laneId,\n index: getBpmnLaneIndexAtPosition(state, options.poolId, options.position),\n }),\n };\n}\n\nexport function routeBpmnEdgeCommand(\n options: RouteBpmnEdgeOptions,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.routeEdge.${options.id}`,\n label: \"Route BPMN edge\",\n execute: (state) => {\n const edge = state.edges.find((item) => item.id === options.id);\n if (!edge) throw new Error(`Edge \"${options.id}\" does not exist.`);\n const edgeType = edge.data?.edgeType;\n if (!edgeType || !isBpmnEdgeRoutingEditable(edgeType)) {\n throw new Error(`${edgeType ?? \"edge\"} routing points cannot be edited.`);\n }\n return patchEdge(state, options.id, {\n data: { routingPoints: options.routingPoints },\n } as Parameters<typeof patchEdge<BpmnRFNode, BpmnRFEdge>>[2]);\n },\n };\n}\n\nexport function deleteBpmnElementsCommand(\n ids: string[],\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: `bpmn.delete.${ids.join(\".\")}`,\n label: \"Delete BPMN elements\",\n execute: (state) => removeElements(state, ids),\n };\n}\n\nexport function copyBpmnElements(\n state: BpmnDiagramState,\n selection?: SelectionState,\n): BpmnClipboardState {\n return copyElements(state, selection);\n}\n\nexport function pasteBpmnElementsCommand(\n clipboard: BpmnClipboardState,\n options: PasteBpmnOptions = {},\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: \"bpmn.paste\",\n label: \"Paste BPMN elements\",\n execute: (state) => pasteElements(state, clipboard, options),\n };\n}\n\nexport function selectBpmnElementsCommand(\n selection: SelectionState,\n): DiagramCommand<BpmnRFNode, BpmnRFEdge> {\n return {\n id: \"bpmn.select\",\n label: \"Select BPMN elements\",\n execute: (state) => setSelection(state, createSelectionState(selection.nodeIds, selection.edgeIds)),\n };\n}\n\nexport function createBpmnDiagramDocument(\n state: BpmnDiagramState,\n options: Omit<CreateDiagramDocumentOptions, \"diagramType\"> = {},\n): BpmnDiagramDocument {\n return createDiagramDocument(normalizeDiagramState(state), {\n ...options,\n diagramType: \"bpmn\",\n });\n}\n\nexport function serializeBpmnDiagram(\n state: BpmnDiagramState,\n options: Omit<CreateDiagramDocumentOptions, \"diagramType\"> = {},\n): string {\n return serializeDiagram(normalizeDiagramState(state), {\n ...options,\n diagramType: \"bpmn\",\n });\n}\n\nexport function parseBpmnDiagramDocument(json: string): BpmnDiagramDocument {\n const document = parseDiagramDocument<BpmnRFNode, BpmnRFEdge>(json);\n if (document.diagramType && document.diagramType !== \"bpmn\") {\n throw new Error(`Expected a BPMN diagram document, received \"${document.diagramType}\".`);\n }\n return document;\n}\n\nexport function deserializeBpmnDiagram(json: string): BpmnDiagramState {\n const document = parseBpmnDiagramDocument(json);\n return deserializeDiagram<BpmnRFNode, BpmnRFEdge>(JSON.stringify(document));\n}\n\nexport function runBpmnCommand(\n stack: CommandStackState<BpmnRFNode, BpmnRFEdge>,\n command: DiagramCommand<BpmnRFNode, BpmnRFEdge>,\n): CommandStackState<BpmnRFNode, BpmnRFEdge> {\n return executeCommand(stack, command);\n}\n\nexport function runBpmnCommands(\n stack: CommandStackState<BpmnRFNode, BpmnRFEdge>,\n commands: Array<DiagramCommand<BpmnRFNode, BpmnRFEdge>>,\n options: { id?: string; label?: string } = {},\n): CommandStackState<BpmnRFNode, BpmnRFEdge> {\n return executeCommands(stack, commands, options);\n}\n"]}
|