@bpmnkit/core 1.4.0 → 1.5.0
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/README.md +5 -5
- package/dist/bpmn/bpmn-builder.d.ts +34 -1
- package/dist/bpmn/bpmn-builder.js +79 -26
- package/dist/layout/semantic/bands.d.ts +10 -1
- package/dist/layout/semantic/bands.js +16 -8
- package/dist/layout/semantic/index.d.ts +3 -1
- package/dist/layout/semantic/index.js +111 -20
- package/dist/layout/semantic/place.d.ts +20 -2
- package/dist/layout/semantic/place.js +124 -7
- package/dist/layout/semantic/route.js +23 -12
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
<p>TypeScript-first BPMN 2.0 SDK — parse, build, layout, and optimize diagrams</p>
|
|
5
5
|
|
|
6
6
|
[](https://www.npmjs.com/package/@bpmnkit/core)
|
|
7
|
-
[](https://github.com/bpmnkit/
|
|
8
|
-
[](https://github.com/bpmnkit/
|
|
9
|
-
[](https://github.com/bpmnkit/
|
|
7
|
+
[](https://github.com/bpmnkit/bpmnkit/blob/main/LICENSE)
|
|
8
|
+
[](https://github.com/bpmnkit/bpmnkit)
|
|
9
|
+
[](https://github.com/bpmnkit/bpmnkit)
|
|
10
10
|
[](https://bpmnkit.com/docs/getting-started/stability#product-tiers)
|
|
11
11
|
|
|
12
|
-
[Website](https://bpmnkit.com) · [Documentation](https://bpmnkit.com/docs) · [GitHub](https://github.com/bpmnkit/
|
|
12
|
+
[Website](https://bpmnkit.com) · [Documentation](https://bpmnkit.com/docs) · [GitHub](https://github.com/bpmnkit/bpmnkit) · [Changelog](https://github.com/bpmnkit/bpmnkit/blob/main/packages/core/CHANGELOG.md)
|
|
13
13
|
</div>
|
|
14
14
|
|
|
15
15
|
> **Core tier.** Semver at 1.0: nothing breaks without a major release. See [product tiers](https://bpmnkit.com/docs/getting-started/stability#product-tiers).
|
|
@@ -414,7 +414,7 @@ const { serviceTask, problems } = applyConnectorTemplate("io.camunda.connectors.
|
|
|
414
414
|
|
|
415
415
|
## License
|
|
416
416
|
|
|
417
|
-
[MIT](https://github.com/bpmnkit/
|
|
417
|
+
[MIT](https://github.com/bpmnkit/bpmnkit/blob/main/LICENSE) © BPMN Kit — made by [u11g](https://u11g.com)
|
|
418
418
|
|
|
419
419
|
<div align="center">
|
|
420
420
|
<a href="https://bpmnkit.com"><img src="https://bpmnkit.com/favicon.svg" width="32" height="32" alt="BPMN Kit"></a>
|
|
@@ -203,6 +203,12 @@ export interface IntermediateCatchEventOptions extends ElementOptions {
|
|
|
203
203
|
correlationKey?: string;
|
|
204
204
|
/** Signal name — creates a signal catch event (aspirational). */
|
|
205
205
|
signalName?: string;
|
|
206
|
+
/**
|
|
207
|
+
* Link name — creates a link catch event, the target of the link throw event with the same
|
|
208
|
+
* name. A link catch has no incoming sequence flow: it starts a new chain, so it is never
|
|
209
|
+
* connected from the current position.
|
|
210
|
+
*/
|
|
211
|
+
linkName?: string;
|
|
206
212
|
}
|
|
207
213
|
/** Options for an intermediate throw event. */
|
|
208
214
|
export interface IntermediateThrowEventOptions extends ElementOptions {
|
|
@@ -216,6 +222,12 @@ export interface IntermediateThrowEventOptions extends ElementOptions {
|
|
|
216
222
|
compensation?: boolean;
|
|
217
223
|
/** Activity to compensate (activityRef attribute on compensateEventDefinition). */
|
|
218
224
|
activityRef?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Link name — creates a link throw event, which continues at the link catch event with the
|
|
227
|
+
* same name. A link throw has no outgoing sequence flow: nothing chains from it, and as the
|
|
228
|
+
* last element of a branch it leaves no open end to join.
|
|
229
|
+
*/
|
|
230
|
+
linkName?: string;
|
|
219
231
|
}
|
|
220
232
|
/** Options for an end event. */
|
|
221
233
|
export interface EndEventOptions extends ElementOptions {
|
|
@@ -323,6 +335,20 @@ export interface AdHocSubProcessOptions extends ElementOptions {
|
|
|
323
335
|
/** Whether still-running inner activity instances are cancelled once the completion condition is met (default true). */
|
|
324
336
|
cancelRemainingInstances?: boolean;
|
|
325
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* The root-level messages, errors, signals and escalations of one process.
|
|
340
|
+
*
|
|
341
|
+
* Every builder working on the process — the process itself, its branches and
|
|
342
|
+
* its sub-process contents at any depth — shares the same four arrays, so an
|
|
343
|
+
* event option resolves to one root definition however deeply it is nested,
|
|
344
|
+
* and that definition is the one `build()` emits.
|
|
345
|
+
*/
|
|
346
|
+
interface RootDefinitions {
|
|
347
|
+
errors: BpmnError[];
|
|
348
|
+
messages: BpmnMessage[];
|
|
349
|
+
signals: BpmnSignal[];
|
|
350
|
+
escalations: BpmnEscalation[];
|
|
351
|
+
}
|
|
326
352
|
/**
|
|
327
353
|
* Builder for a single named branch path from a gateway.
|
|
328
354
|
*
|
|
@@ -361,6 +387,7 @@ export declare class BranchBuilder {
|
|
|
361
387
|
private readonly rootEscalations;
|
|
362
388
|
/** @internal */
|
|
363
389
|
constructor(gatewayId: string, branchName: string, rootErrors?: BpmnError[], rootMessages?: BpmnMessage[], rootSignals?: BpmnSignal[], rootEscalations?: BpmnEscalation[]);
|
|
390
|
+
private roots;
|
|
364
391
|
/** Set a FEEL condition expression on this branch's outgoing sequence flow. */
|
|
365
392
|
condition(expression: string): this;
|
|
366
393
|
/** Mark this branch as the gateway's default (no-condition) flow. */
|
|
@@ -457,7 +484,10 @@ export declare class SubProcessContentBuilder {
|
|
|
457
484
|
private lastNodeId;
|
|
458
485
|
private currentGatewayId;
|
|
459
486
|
private openBranchEnds;
|
|
487
|
+
private readonly rootErrors;
|
|
460
488
|
private readonly rootMessages;
|
|
489
|
+
private readonly rootSignals;
|
|
490
|
+
private readonly rootEscalations;
|
|
461
491
|
/**
|
|
462
492
|
* Whether sequential calls chain themselves with sequence flows.
|
|
463
493
|
*
|
|
@@ -471,7 +501,8 @@ export declare class SubProcessContentBuilder {
|
|
|
471
501
|
*/
|
|
472
502
|
private readonly autoConnect;
|
|
473
503
|
/** @internal */
|
|
474
|
-
constructor(
|
|
504
|
+
constructor(roots?: RootDefinitions, autoConnect?: boolean);
|
|
505
|
+
private roots;
|
|
475
506
|
private addElement;
|
|
476
507
|
/**
|
|
477
508
|
* Add an element with no sequence-flow wiring and no cursor movement.
|
|
@@ -578,6 +609,7 @@ export declare class ProcessBuilder {
|
|
|
578
609
|
/** Flows the caller deliberately spliced, exempt from the rewiring guard. */
|
|
579
610
|
private readonly _splicedFlowIds;
|
|
580
611
|
constructor(processId: string);
|
|
612
|
+
private roots;
|
|
581
613
|
/**
|
|
582
614
|
* Continues an existing model rather than generating a new one.
|
|
583
615
|
*
|
|
@@ -934,4 +966,5 @@ export declare class DiagramBuilder {
|
|
|
934
966
|
*/
|
|
935
967
|
private buildCollaborations;
|
|
936
968
|
}
|
|
969
|
+
export {};
|
|
937
970
|
//# sourceMappingURL=bpmn-builder.d.ts.map
|
|
@@ -171,8 +171,20 @@ function buildEventDefinitions(opts, rootErrors, rootMessages, rootSignals, root
|
|
|
171
171
|
if (opts.compensation) {
|
|
172
172
|
defs.push({ type: "compensate", activityRef: opts.activityRef });
|
|
173
173
|
}
|
|
174
|
+
if (opts.linkName !== undefined) {
|
|
175
|
+
defs.push({ type: "link", name: opts.linkName });
|
|
176
|
+
}
|
|
174
177
|
return defs;
|
|
175
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* A link event pair is a "go-to" within one scope: the throw has no outgoing
|
|
181
|
+
* sequence flow and the catch no incoming one. The builders' auto-chaining has
|
|
182
|
+
* to stop at a throw and restart at a catch, or it fabricates exactly the flows
|
|
183
|
+
* that make the pair invalid.
|
|
184
|
+
*/
|
|
185
|
+
function isLinkEvent(element, type) {
|
|
186
|
+
return element.type === type && element.eventDefinitions.some((def) => def.type === "link");
|
|
187
|
+
}
|
|
176
188
|
/**
|
|
177
189
|
* Build an empty flow element.
|
|
178
190
|
*
|
|
@@ -528,9 +540,9 @@ function resolveBoundaryEventArgs(id, attachedToOrOptions, maybeOptions) {
|
|
|
528
540
|
* unlike `subProcess`, whose cursor handling differs per class, nothing here
|
|
529
541
|
* varies between them.
|
|
530
542
|
*/
|
|
531
|
-
function makeTransactionEl(id, content, options,
|
|
543
|
+
function makeTransactionEl(id, content, options, roots) {
|
|
532
544
|
const resolved = resolveSubProcessArgs(content, options);
|
|
533
|
-
const sub = new SubProcessContentBuilder(
|
|
545
|
+
const sub = new SubProcessContentBuilder(roots);
|
|
534
546
|
resolved.content(sub);
|
|
535
547
|
finalizeScope(sub._elements, sub._flows);
|
|
536
548
|
const element = makeFlowElement(id, "transaction", resolved.options);
|
|
@@ -700,6 +712,14 @@ export class BranchBuilder {
|
|
|
700
712
|
this.rootSignals = rootSignals;
|
|
701
713
|
this.rootEscalations = rootEscalations;
|
|
702
714
|
}
|
|
715
|
+
roots() {
|
|
716
|
+
return {
|
|
717
|
+
errors: this.rootErrors,
|
|
718
|
+
messages: this.rootMessages,
|
|
719
|
+
signals: this.rootSignals,
|
|
720
|
+
escalations: this.rootEscalations,
|
|
721
|
+
};
|
|
722
|
+
}
|
|
703
723
|
/** Set a FEEL condition expression on this branch's outgoing sequence flow. */
|
|
704
724
|
condition(expression) {
|
|
705
725
|
this.pendingCondition = expression;
|
|
@@ -713,6 +733,11 @@ export class BranchBuilder {
|
|
|
713
733
|
addElement(element) {
|
|
714
734
|
this._elements.push(element);
|
|
715
735
|
this._ids.add(element.id);
|
|
736
|
+
if (isLinkEvent(element, "intermediateCatchEvent")) {
|
|
737
|
+
this.isFirstElement = false;
|
|
738
|
+
this.lastNodeId = element.id;
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
716
741
|
if (this.lastNodeId) {
|
|
717
742
|
const flowId = generateId("Flow");
|
|
718
743
|
const flow = {
|
|
@@ -742,7 +767,7 @@ export class BranchBuilder {
|
|
|
742
767
|
}
|
|
743
768
|
this.openBranchEnds = [];
|
|
744
769
|
this.isFirstElement = false;
|
|
745
|
-
this.lastNodeId = element.id;
|
|
770
|
+
this.lastNodeId = isLinkEvent(element, "intermediateThrowEvent") ? undefined : element.id;
|
|
746
771
|
return this;
|
|
747
772
|
}
|
|
748
773
|
/**
|
|
@@ -964,7 +989,7 @@ export class BranchBuilder {
|
|
|
964
989
|
/** Add a sub-process (mirrors `ProcessBuilder.subProcess`). */
|
|
965
990
|
subProcess(id, content, options) {
|
|
966
991
|
const resolved = resolveSubProcessArgs(content, options);
|
|
967
|
-
const sub = new SubProcessContentBuilder(this.
|
|
992
|
+
const sub = new SubProcessContentBuilder(this.roots());
|
|
968
993
|
resolved.content(sub);
|
|
969
994
|
finalizeScope(sub._elements, sub._flows);
|
|
970
995
|
const element = makeFlowElement(id, "subProcess", resolved.options);
|
|
@@ -981,7 +1006,7 @@ export class BranchBuilder {
|
|
|
981
1006
|
}
|
|
982
1007
|
/** Add a transaction sub-process (mirrors `ProcessBuilder.transaction`). */
|
|
983
1008
|
transaction(id, content, options) {
|
|
984
|
-
return this.addElement(makeTransactionEl(id, content, options, this.
|
|
1009
|
+
return this.addElement(makeTransactionEl(id, content, options, this.roots()));
|
|
985
1010
|
}
|
|
986
1011
|
/**
|
|
987
1012
|
* Add an ad-hoc sub-process (mirrors `ProcessBuilder.adHocSubProcess`).
|
|
@@ -994,7 +1019,7 @@ export class BranchBuilder {
|
|
|
994
1019
|
adHocSubProcess(id, content, options) {
|
|
995
1020
|
const resolved = resolveSubProcessArgs(content, options);
|
|
996
1021
|
// Ad-hoc sub-process children are unordered — see SubProcessContentBuilder.autoConnect.
|
|
997
|
-
const sub = new SubProcessContentBuilder(this.
|
|
1022
|
+
const sub = new SubProcessContentBuilder(this.roots(), false);
|
|
998
1023
|
resolved.content(sub);
|
|
999
1024
|
finalizeScope(sub._elements, sub._flows);
|
|
1000
1025
|
const { extensionElements, completionCondition } = buildAdHocSubProcessExtensions(resolved.options);
|
|
@@ -1009,7 +1034,7 @@ export class BranchBuilder {
|
|
|
1009
1034
|
/** Add an event sub-process. Triggered by its start event — no incoming or outgoing sequence flows. */
|
|
1010
1035
|
eventSubProcess(id, content, options) {
|
|
1011
1036
|
const resolved = resolveSubProcessArgs(content, options);
|
|
1012
|
-
const sub = new SubProcessContentBuilder(this.
|
|
1037
|
+
const sub = new SubProcessContentBuilder(this.roots());
|
|
1013
1038
|
resolved.content(sub);
|
|
1014
1039
|
finalizeScope(sub._elements, sub._flows);
|
|
1015
1040
|
const element = makeFlowElement(id, "subProcess", resolved.options);
|
|
@@ -1096,7 +1121,10 @@ export class SubProcessContentBuilder {
|
|
|
1096
1121
|
lastNodeId;
|
|
1097
1122
|
currentGatewayId;
|
|
1098
1123
|
openBranchEnds = [];
|
|
1124
|
+
rootErrors;
|
|
1099
1125
|
rootMessages;
|
|
1126
|
+
rootSignals;
|
|
1127
|
+
rootEscalations;
|
|
1100
1128
|
/**
|
|
1101
1129
|
* Whether sequential calls chain themselves with sequence flows.
|
|
1102
1130
|
*
|
|
@@ -1110,17 +1138,28 @@ export class SubProcessContentBuilder {
|
|
|
1110
1138
|
*/
|
|
1111
1139
|
autoConnect;
|
|
1112
1140
|
/** @internal */
|
|
1113
|
-
constructor(
|
|
1114
|
-
this.
|
|
1141
|
+
constructor(roots = { errors: [], messages: [], signals: [], escalations: [] }, autoConnect = true) {
|
|
1142
|
+
this.rootErrors = roots.errors;
|
|
1143
|
+
this.rootMessages = roots.messages;
|
|
1144
|
+
this.rootSignals = roots.signals;
|
|
1145
|
+
this.rootEscalations = roots.escalations;
|
|
1115
1146
|
this.autoConnect = autoConnect;
|
|
1116
1147
|
}
|
|
1148
|
+
roots() {
|
|
1149
|
+
return {
|
|
1150
|
+
errors: this.rootErrors,
|
|
1151
|
+
messages: this.rootMessages,
|
|
1152
|
+
signals: this.rootSignals,
|
|
1153
|
+
escalations: this.rootEscalations,
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1117
1156
|
addElement(element) {
|
|
1118
1157
|
if (this._ids.has(element.id)) {
|
|
1119
1158
|
throw new Error(`Duplicate element ID "${element.id}" in sub-process`);
|
|
1120
1159
|
}
|
|
1121
1160
|
this._elements.push(element);
|
|
1122
1161
|
this._ids.add(element.id);
|
|
1123
|
-
if (this.autoConnect) {
|
|
1162
|
+
if (this.autoConnect && !isLinkEvent(element, "intermediateCatchEvent")) {
|
|
1124
1163
|
if (this.lastNodeId) {
|
|
1125
1164
|
this._flows.push({
|
|
1126
1165
|
id: generateId("Flow"),
|
|
@@ -1143,7 +1182,7 @@ export class SubProcessContentBuilder {
|
|
|
1143
1182
|
}
|
|
1144
1183
|
// The cursor still moves even when nothing is wired, so `connectTo()` after
|
|
1145
1184
|
// an activity keeps naming that activity as the flow's source.
|
|
1146
|
-
this.lastNodeId = element.id;
|
|
1185
|
+
this.lastNodeId = isLinkEvent(element, "intermediateThrowEvent") ? undefined : element.id;
|
|
1147
1186
|
return this;
|
|
1148
1187
|
}
|
|
1149
1188
|
/**
|
|
@@ -1166,7 +1205,7 @@ export class SubProcessContentBuilder {
|
|
|
1166
1205
|
startEvent(id, options) {
|
|
1167
1206
|
const el = makeFlowElement(id ?? generateId("StartEvent"), "startEvent", options);
|
|
1168
1207
|
if (el.type === "startEvent" && options) {
|
|
1169
|
-
el.eventDefinitions = buildEventDefinitions(options);
|
|
1208
|
+
el.eventDefinitions = buildEventDefinitions(options, this.rootErrors, this.rootMessages, this.rootSignals, this.rootEscalations);
|
|
1170
1209
|
if (options.isInterrupting === false)
|
|
1171
1210
|
el.isInterrupting = false;
|
|
1172
1211
|
}
|
|
@@ -1175,13 +1214,13 @@ export class SubProcessContentBuilder {
|
|
|
1175
1214
|
endEvent(id, options) {
|
|
1176
1215
|
const el = makeFlowElement(id ?? generateId("EndEvent"), "endEvent", options);
|
|
1177
1216
|
if (el.type === "endEvent" && options)
|
|
1178
|
-
el.eventDefinitions = buildEventDefinitions(options);
|
|
1217
|
+
el.eventDefinitions = buildEventDefinitions(options, this.rootErrors, this.rootMessages, this.rootSignals, this.rootEscalations);
|
|
1179
1218
|
return this.addElement(el);
|
|
1180
1219
|
}
|
|
1181
1220
|
intermediateThrowEvent(id, options) {
|
|
1182
1221
|
const el = makeFlowElement(id ?? generateId("IntermediateThrowEvent"), "intermediateThrowEvent", options);
|
|
1183
1222
|
if (el.type === "intermediateThrowEvent" && options)
|
|
1184
|
-
el.eventDefinitions = buildEventDefinitions(options);
|
|
1223
|
+
el.eventDefinitions = buildEventDefinitions(options, this.rootErrors, this.rootMessages, this.rootSignals, this.rootEscalations);
|
|
1185
1224
|
return this.addElement(el);
|
|
1186
1225
|
}
|
|
1187
1226
|
intermediateCatchEvent(id, options) {
|
|
@@ -1190,7 +1229,7 @@ export class SubProcessContentBuilder {
|
|
|
1190
1229
|
extensionElements: buildMessageSubscriptionExt(options?.correlationKey),
|
|
1191
1230
|
});
|
|
1192
1231
|
if (el.type === "intermediateCatchEvent" && options)
|
|
1193
|
-
el.eventDefinitions = buildEventDefinitions(options);
|
|
1232
|
+
el.eventDefinitions = buildEventDefinitions(options, this.rootErrors, this.rootMessages, this.rootSignals, this.rootEscalations);
|
|
1194
1233
|
return this.addElement(el);
|
|
1195
1234
|
}
|
|
1196
1235
|
// ---- Tasks ----
|
|
@@ -1291,7 +1330,7 @@ export class SubProcessContentBuilder {
|
|
|
1291
1330
|
if (!this.currentGatewayId) {
|
|
1292
1331
|
throw new Error("branch() must be called after a gateway element");
|
|
1293
1332
|
}
|
|
1294
|
-
const b = new BranchBuilder(this.currentGatewayId, name);
|
|
1333
|
+
const b = new BranchBuilder(this.currentGatewayId, name, this.rootErrors, this.rootMessages, this.rootSignals, this.rootEscalations);
|
|
1295
1334
|
callback(b);
|
|
1296
1335
|
for (const el of b._elements) {
|
|
1297
1336
|
if (this._ids.has(el.id)) {
|
|
@@ -1366,7 +1405,7 @@ export class SubProcessContentBuilder {
|
|
|
1366
1405
|
if (element.type === "boundaryEvent") {
|
|
1367
1406
|
element.attachedToRef = options.attachedTo;
|
|
1368
1407
|
element.cancelActivity = options.cancelActivity;
|
|
1369
|
-
element.eventDefinitions = buildEventDefinitions(options);
|
|
1408
|
+
element.eventDefinitions = buildEventDefinitions(options, this.rootErrors, this.rootMessages, this.rootSignals, this.rootEscalations);
|
|
1370
1409
|
}
|
|
1371
1410
|
// Push directly — no sequence flow, boundary events attach via attachedToRef
|
|
1372
1411
|
this._elements.push(element);
|
|
@@ -1409,7 +1448,7 @@ export class SubProcessContentBuilder {
|
|
|
1409
1448
|
/** Add a sub-process nested inside this sub-process's content. */
|
|
1410
1449
|
subProcess(id, content, options) {
|
|
1411
1450
|
const resolved = resolveSubProcessArgs(content, options);
|
|
1412
|
-
const sub = new SubProcessContentBuilder(this.
|
|
1451
|
+
const sub = new SubProcessContentBuilder(this.roots());
|
|
1413
1452
|
resolved.content(sub);
|
|
1414
1453
|
finalizeScope(sub._elements, sub._flows);
|
|
1415
1454
|
const element = makeFlowElement(id, "subProcess", resolved.options);
|
|
@@ -1426,7 +1465,7 @@ export class SubProcessContentBuilder {
|
|
|
1426
1465
|
}
|
|
1427
1466
|
/** Add a transaction sub-process nested inside this sub-process's content. */
|
|
1428
1467
|
transaction(id, content, options) {
|
|
1429
|
-
return this.addElement(makeTransactionEl(id, content, options, this.
|
|
1468
|
+
return this.addElement(makeTransactionEl(id, content, options, this.roots()));
|
|
1430
1469
|
}
|
|
1431
1470
|
/**
|
|
1432
1471
|
* Add an ad-hoc sub-process nested inside this sub-process's content.
|
|
@@ -1439,7 +1478,7 @@ export class SubProcessContentBuilder {
|
|
|
1439
1478
|
adHocSubProcess(id, content, options) {
|
|
1440
1479
|
const resolved = resolveSubProcessArgs(content, options);
|
|
1441
1480
|
// Ad-hoc sub-process children are unordered — see SubProcessContentBuilder.autoConnect.
|
|
1442
|
-
const sub = new SubProcessContentBuilder(this.
|
|
1481
|
+
const sub = new SubProcessContentBuilder(this.roots(), false);
|
|
1443
1482
|
resolved.content(sub);
|
|
1444
1483
|
finalizeScope(sub._elements, sub._flows);
|
|
1445
1484
|
const { extensionElements, completionCondition } = buildAdHocSubProcessExtensions(resolved.options);
|
|
@@ -1454,7 +1493,7 @@ export class SubProcessContentBuilder {
|
|
|
1454
1493
|
/** Add an event sub-process. Triggered by its start event — no incoming or outgoing sequence flows. */
|
|
1455
1494
|
eventSubProcess(id, content, options) {
|
|
1456
1495
|
const resolved = resolveSubProcessArgs(content, options);
|
|
1457
|
-
const sub = new SubProcessContentBuilder(this.
|
|
1496
|
+
const sub = new SubProcessContentBuilder(this.roots());
|
|
1458
1497
|
resolved.content(sub);
|
|
1459
1498
|
finalizeScope(sub._elements, sub._flows);
|
|
1460
1499
|
const element = makeFlowElement(id, "subProcess", resolved.options);
|
|
@@ -1515,6 +1554,14 @@ export class ProcessBuilder {
|
|
|
1515
1554
|
constructor(processId) {
|
|
1516
1555
|
this.processId = processId;
|
|
1517
1556
|
}
|
|
1557
|
+
roots() {
|
|
1558
|
+
return {
|
|
1559
|
+
errors: this.rootErrors,
|
|
1560
|
+
messages: this.rootMessages,
|
|
1561
|
+
signals: this.rootSignals,
|
|
1562
|
+
escalations: this.rootEscalations,
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1518
1565
|
/**
|
|
1519
1566
|
* Continues an existing model rather than generating a new one.
|
|
1520
1567
|
*
|
|
@@ -2117,7 +2164,7 @@ export class ProcessBuilder {
|
|
|
2117
2164
|
adHocSubProcess(id, content, options) {
|
|
2118
2165
|
const resolved = resolveSubProcessArgs(content, options);
|
|
2119
2166
|
// Ad-hoc sub-process children are unordered — see SubProcessContentBuilder.autoConnect.
|
|
2120
|
-
const sub = new SubProcessContentBuilder(this.
|
|
2167
|
+
const sub = new SubProcessContentBuilder(this.roots(), false);
|
|
2121
2168
|
resolved.content(sub);
|
|
2122
2169
|
finalizeScope(sub._elements, sub._flows);
|
|
2123
2170
|
const { extensionElements, completionCondition } = buildAdHocSubProcessExtensions(resolved.options);
|
|
@@ -2133,7 +2180,7 @@ export class ProcessBuilder {
|
|
|
2133
2180
|
/** Add a sub-process (aspirational). */
|
|
2134
2181
|
subProcess(id, content, options) {
|
|
2135
2182
|
const resolved = resolveSubProcessArgs(content, options);
|
|
2136
|
-
const sub = new SubProcessContentBuilder(this.
|
|
2183
|
+
const sub = new SubProcessContentBuilder(this.roots());
|
|
2137
2184
|
resolved.content(sub);
|
|
2138
2185
|
finalizeScope(sub._elements, sub._flows);
|
|
2139
2186
|
const element = makeFlowElement(id, "subProcess", resolved.options);
|
|
@@ -2151,13 +2198,13 @@ export class ProcessBuilder {
|
|
|
2151
2198
|
}
|
|
2152
2199
|
/** Add a transaction sub-process — a sub-process with atomic semantics. */
|
|
2153
2200
|
transaction(id, content, options) {
|
|
2154
|
-
this.addFlowElement(makeTransactionEl(id, content, options, this.
|
|
2201
|
+
this.addFlowElement(makeTransactionEl(id, content, options, this.roots()));
|
|
2155
2202
|
return this;
|
|
2156
2203
|
}
|
|
2157
2204
|
/** Add an event sub-process. Triggered by its start event — no incoming or outgoing sequence flows. */
|
|
2158
2205
|
eventSubProcess(id, content, options) {
|
|
2159
2206
|
const resolved = resolveSubProcessArgs(content, options);
|
|
2160
|
-
const sub = new SubProcessContentBuilder(this.
|
|
2207
|
+
const sub = new SubProcessContentBuilder(this.roots());
|
|
2161
2208
|
resolved.content(sub);
|
|
2162
2209
|
finalizeScope(sub._elements, sub._flows);
|
|
2163
2210
|
const element = makeFlowElement(id, "subProcess", resolved.options);
|
|
@@ -2425,6 +2472,12 @@ export class ProcessBuilder {
|
|
|
2425
2472
|
// Do NOT connect open branch ends — handler is outside normal flow
|
|
2426
2473
|
return;
|
|
2427
2474
|
}
|
|
2475
|
+
// A link catch starts a new chain; open branch ends wait for the next element.
|
|
2476
|
+
if (isLinkEvent(element, "intermediateCatchEvent")) {
|
|
2477
|
+
this._savedMainFlowId = undefined;
|
|
2478
|
+
this.lastNodeId = element.id;
|
|
2479
|
+
return;
|
|
2480
|
+
}
|
|
2428
2481
|
if (this.lastNodeId) {
|
|
2429
2482
|
const flowId = generateId("Flow");
|
|
2430
2483
|
this.sequenceFlows.push({
|
|
@@ -2450,7 +2503,7 @@ export class ProcessBuilder {
|
|
|
2450
2503
|
// Clear any saved compensation cursor — a normal element advancing the cursor
|
|
2451
2504
|
// means the compensation boundary/handler pattern has been interrupted.
|
|
2452
2505
|
this._savedMainFlowId = undefined;
|
|
2453
|
-
this.lastNodeId = element.id;
|
|
2506
|
+
this.lastNodeId = isLinkEvent(element, "intermediateThrowEvent") ? undefined : element.id;
|
|
2454
2507
|
}
|
|
2455
2508
|
}
|
|
2456
2509
|
// ---------------------------------------------------------------------------
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BpmnBoundaryEvent } from "../../bpmn/bpmn-model.js";
|
|
1
2
|
import type { SemanticGraph } from "./graph.js";
|
|
2
3
|
/**
|
|
3
4
|
* Vertical narrative roles for one process scope.
|
|
@@ -15,5 +16,13 @@ export interface BandLayout {
|
|
|
15
16
|
/** Flow ids that continue the spine and should be routed as one segment. */
|
|
16
17
|
straightFlows: Set<string>;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Escalation handlers read as "upward" exceptions; everything else reads downward.
|
|
21
|
+
* A titled host sends every handler down: its title is centred on the top border,
|
|
22
|
+
* so nothing docks there. Placement docks the event on the same side.
|
|
23
|
+
*/
|
|
24
|
+
export declare function boundarySide(event: BpmnBoundaryEvent, hostTitled: boolean): 1 | -1;
|
|
25
|
+
export declare function assignBands(graph: SemanticGraph,
|
|
26
|
+
/** Hosts whose title is drawn along their top border; see {@link boundarySide}. */
|
|
27
|
+
titled?: ReadonlySet<string>): BandLayout;
|
|
19
28
|
//# sourceMappingURL=bands.d.ts.map
|
|
@@ -5,11 +5,19 @@ function isDefaultFlow(source, flow) {
|
|
|
5
5
|
const gateway = source;
|
|
6
6
|
return gateway.default !== undefined && gateway.default === flow.id;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Escalation handlers read as "upward" exceptions; everything else reads downward.
|
|
10
|
+
* A titled host sends every handler down: its title is centred on the top border,
|
|
11
|
+
* so nothing docks there. Placement docks the event on the same side.
|
|
12
|
+
*/
|
|
13
|
+
export function boundarySide(event, hostTitled) {
|
|
14
|
+
if (hostTitled)
|
|
15
|
+
return 1;
|
|
10
16
|
return event.eventDefinitions.some((d) => d.type === "escalation") ? -1 : 1;
|
|
11
17
|
}
|
|
12
|
-
export function assignBands(graph
|
|
18
|
+
export function assignBands(graph,
|
|
19
|
+
/** Hosts whose title is drawn along their top border; see {@link boundarySide}. */
|
|
20
|
+
titled = new Set()) {
|
|
13
21
|
const bands = new Map();
|
|
14
22
|
const spine = new Set();
|
|
15
23
|
const straightFlows = new Set();
|
|
@@ -33,7 +41,7 @@ export function assignBands(graph) {
|
|
|
33
41
|
const source = sources[i];
|
|
34
42
|
if (!source)
|
|
35
43
|
continue;
|
|
36
|
-
for (const branch of branchesFrom(graph, source, assigned)) {
|
|
44
|
+
for (const branch of branchesFrom(graph, source, assigned, titled)) {
|
|
37
45
|
branches.push(branch);
|
|
38
46
|
for (const id of branch.nodes) {
|
|
39
47
|
assigned.add(id);
|
|
@@ -214,7 +222,7 @@ function traceSpine(graph, start, spine, straightFlows) {
|
|
|
214
222
|
* Collect the alternatives leaving one node: its non-spine sequence flows plus
|
|
215
223
|
* the handler paths of any boundary event attached to it.
|
|
216
224
|
*/
|
|
217
|
-
function branchesFrom(graph, source, assigned) {
|
|
225
|
+
function branchesFrom(graph, source, assigned, titled) {
|
|
218
226
|
const out = [];
|
|
219
227
|
const node = graph.byId.get(source.id);
|
|
220
228
|
const alternatives = (graph.outgoing.get(source.id) ?? []).filter((f) => !graph.backEdges.has(f.id) && !assigned.has(f.targetRef));
|
|
@@ -227,7 +235,7 @@ function branchesFrom(graph, source, assigned) {
|
|
|
227
235
|
const flow = alternatives[i];
|
|
228
236
|
if (!flow)
|
|
229
237
|
continue;
|
|
230
|
-
const handler = handlerSideOf(graph, source.id, flow);
|
|
238
|
+
const handler = handlerSideOf(graph, source.id, flow, titled);
|
|
231
239
|
let side;
|
|
232
240
|
if (handler !== undefined)
|
|
233
241
|
side = handler;
|
|
@@ -243,11 +251,11 @@ function branchesFrom(graph, source, assigned) {
|
|
|
243
251
|
return out;
|
|
244
252
|
}
|
|
245
253
|
/** The side a flow inherits when it leaves a boundary event of this host. */
|
|
246
|
-
function handlerSideOf(graph, hostId, flow) {
|
|
254
|
+
function handlerSideOf(graph, hostId, flow, titled) {
|
|
247
255
|
if (flow.sourceRef === hostId)
|
|
248
256
|
return undefined;
|
|
249
257
|
const event = (graph.attachers.get(hostId) ?? []).find((e) => e.id === flow.sourceRef);
|
|
250
|
-
return event ? boundarySide(event) : undefined;
|
|
258
|
+
return event ? boundarySide(event, titled.has(hostId)) : undefined;
|
|
251
259
|
}
|
|
252
260
|
/**
|
|
253
261
|
* Follow a branch forward until it rejoins placed flow or runs out.
|
|
@@ -8,6 +8,8 @@ import type { LayoutResult } from "../types.js";
|
|
|
8
8
|
export declare function semanticLayoutProcess(process: BpmnProcess, collapsed?: ReadonlySet<string>): LayoutResult;
|
|
9
9
|
export declare function semanticLayout(flowElements: BpmnFlowElement[], sequenceFlows: BpmnSequenceFlow[], laneSet?: BpmnLaneSet,
|
|
10
10
|
/** Sub-processes drawn collapsed: their contents go on a plane of their own. */
|
|
11
|
-
collapsed?: ReadonlySet<string
|
|
11
|
+
collapsed?: ReadonlySet<string>,
|
|
12
|
+
/** True for the contents of an expanded sub-process; see `place`'s `packLoose`. */
|
|
13
|
+
inContainer?: boolean): LayoutResult;
|
|
12
14
|
export type { Placement } from "./place.js";
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -2,7 +2,7 @@ import { placeEdgeLabels } from "../grid/edge-labels.js";
|
|
|
2
2
|
import { LABEL_CHAR_WIDTH, LABEL_HEIGHT, LABEL_MIN_WIDTH, SUBPROCESS_PADDING } from "../types.js";
|
|
3
3
|
import { assignBands } from "./bands.js";
|
|
4
4
|
import { buildSemanticGraph } from "./graph.js";
|
|
5
|
-
import { place, sizeOf } from "./place.js";
|
|
5
|
+
import { externalLabelWidth, place, sizeOf } from "./place.js";
|
|
6
6
|
import { routeFlows } from "./route.js";
|
|
7
7
|
/** Padding between an expanded sub-process border and its children. */
|
|
8
8
|
const SUB_PADDING = SUBPROCESS_PADDING;
|
|
@@ -11,18 +11,6 @@ const TITLE_BAND = 28;
|
|
|
11
11
|
/** Gap between an event or gateway and its external label. */
|
|
12
12
|
const LABEL_OFFSET = 4;
|
|
13
13
|
const CONTAINER_TYPES = new Set(["subProcess", "adHocSubProcess", "eventSubProcess", "transaction"]);
|
|
14
|
-
const EXTERNAL_LABEL_TYPES = new Set([
|
|
15
|
-
"startEvent",
|
|
16
|
-
"endEvent",
|
|
17
|
-
"intermediateThrowEvent",
|
|
18
|
-
"intermediateCatchEvent",
|
|
19
|
-
"boundaryEvent",
|
|
20
|
-
"exclusiveGateway",
|
|
21
|
-
"parallelGateway",
|
|
22
|
-
"inclusiveGateway",
|
|
23
|
-
"eventBasedGateway",
|
|
24
|
-
"complexGateway",
|
|
25
|
-
]);
|
|
26
14
|
/**
|
|
27
15
|
* Lay out a process the way the BPMN reads: ranks carry the flow left to right,
|
|
28
16
|
* semantic bands carry branch meaning up and down, and lane membership wins over
|
|
@@ -33,11 +21,12 @@ export function semanticLayoutProcess(process, collapsed) {
|
|
|
33
21
|
}
|
|
34
22
|
export function semanticLayout(flowElements, sequenceFlows, laneSet,
|
|
35
23
|
/** Sub-processes drawn collapsed: their contents go on a plane of their own. */
|
|
36
|
-
collapsed = new Set()
|
|
24
|
+
collapsed = new Set(),
|
|
25
|
+
/** True for the contents of an expanded sub-process; see `place`'s `packLoose`. */
|
|
26
|
+
inContainer = false) {
|
|
37
27
|
if (flowElements.length === 0)
|
|
38
28
|
return { nodes: [], edges: [] };
|
|
39
29
|
const graph = buildSemanticGraph(flowElements, sequenceFlows);
|
|
40
|
-
const bandLayout = assignBands(graph);
|
|
41
30
|
// Children first: an expanded sub-process is sized by what it contains, while
|
|
42
31
|
// a collapsed one stays activity-sized and its contents move to their own plane.
|
|
43
32
|
const childResults = new Map();
|
|
@@ -60,7 +49,11 @@ collapsed = new Set()) {
|
|
|
60
49
|
sizes.set(el.id, child.size);
|
|
61
50
|
}
|
|
62
51
|
}
|
|
63
|
-
|
|
52
|
+
// A named expanded sub-process draws its title along its top border.
|
|
53
|
+
const titled = new Set([...childResults.keys()].filter((id) => graph.byId.get(id)?.name !== undefined));
|
|
54
|
+
const bandLayout = assignBands(graph, titled);
|
|
55
|
+
const { bounds, lanes, gutterX } = place(graph, bandLayout, sizes, laneSet, inContainer, titled);
|
|
56
|
+
const besideStem = boundaryLabels(graph, bounds);
|
|
64
57
|
const nodes = [];
|
|
65
58
|
for (const el of flowElements) {
|
|
66
59
|
const b = bounds.get(el.id);
|
|
@@ -76,7 +69,7 @@ collapsed = new Set()) {
|
|
|
76
69
|
};
|
|
77
70
|
if (el.name) {
|
|
78
71
|
node.label = el.name;
|
|
79
|
-
const labelBounds = externalLabel(el.type, el.name, b);
|
|
72
|
+
const labelBounds = besideStem.get(el.id) ?? externalLabel(el.type, el.name, b);
|
|
80
73
|
if (labelBounds)
|
|
81
74
|
node.labelBounds = labelBounds;
|
|
82
75
|
}
|
|
@@ -126,7 +119,10 @@ function childLayoutOf(el, collapsed) {
|
|
|
126
119
|
const container = el;
|
|
127
120
|
if (!container.flowElements || container.flowElements.length === 0)
|
|
128
121
|
return null;
|
|
129
|
-
const result = semanticLayout(container.flowElements, container.sequenceFlows ?? [], container.laneSet, collapsed
|
|
122
|
+
const result = semanticLayout(container.flowElements, container.sequenceFlows ?? [], container.laneSet, collapsed,
|
|
123
|
+
// A collapsed container's contents go on a plane of their own, laid out
|
|
124
|
+
// like any top-level scope.
|
|
125
|
+
!collapsed.has(el.id));
|
|
130
126
|
const extent = extentOf(result);
|
|
131
127
|
if (!extent)
|
|
132
128
|
return null;
|
|
@@ -166,11 +162,106 @@ function extentOf(result) {
|
|
|
166
162
|
function shift(b, dx, dy) {
|
|
167
163
|
return { x: b.x + dx, y: b.y + dy, width: b.width, height: b.height };
|
|
168
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Labels for named boundary events, beside the event's exit stem rather than
|
|
167
|
+
* centred on it.
|
|
168
|
+
*
|
|
169
|
+
* A boundary event's flows leave its outward side at the centre, so a label
|
|
170
|
+
* centred below (or above) the event is crossed by its own exit edge. Labels
|
|
171
|
+
* sit on the outward side, outside the host, in the gaps between the stems of
|
|
172
|
+
* the events docked on that border: each gap holds at most one label, and the
|
|
173
|
+
* gaps beyond the first and last stem are unbounded. A label takes the gap on
|
|
174
|
+
* its left if it fits there, else the one on its right. When neither fits, it
|
|
175
|
+
* goes beyond the outermost stem on its nearer side, past the labels already
|
|
176
|
+
* there. Every label stays on one line in the one row next to the host:
|
|
177
|
+
* routing does not see labels, and anything farther out would reach the turn
|
|
178
|
+
* a route takes just past a stem.
|
|
179
|
+
*/
|
|
180
|
+
function boundaryLabels(graph, bounds) {
|
|
181
|
+
const labels = new Map();
|
|
182
|
+
for (const [hostId, events] of graph.attachers) {
|
|
183
|
+
const host = bounds.get(hostId);
|
|
184
|
+
if (!host)
|
|
185
|
+
continue;
|
|
186
|
+
const docked = events
|
|
187
|
+
.map((event) => ({ event, b: bounds.get(event.id) }))
|
|
188
|
+
.filter((d) => d.b !== undefined);
|
|
189
|
+
for (const onTop of [true, false]) {
|
|
190
|
+
// Same side test the router uses to pick the exit direction.
|
|
191
|
+
const side = docked
|
|
192
|
+
.filter(({ b }) => b.y + b.height / 2 <= host.y + 1 === onTop)
|
|
193
|
+
.sort((p, q) => p.b.x - q.b.x);
|
|
194
|
+
const stems = side.map(({ b }) => b.x + b.width / 2);
|
|
195
|
+
/** How far labels beyond the first / last stem already reach. */
|
|
196
|
+
const outer = {
|
|
197
|
+
left: (stems[0] ?? 0) - LABEL_OFFSET,
|
|
198
|
+
right: (stems[stems.length - 1] ?? 0) + LABEL_OFFSET,
|
|
199
|
+
};
|
|
200
|
+
/** Labels that fit no gap, placed past the outer labels once those are known. */
|
|
201
|
+
const spill = { left: [], right: [] };
|
|
202
|
+
const place = (b, x, width) => ({
|
|
203
|
+
x,
|
|
204
|
+
y: onTop ? b.y - LABEL_OFFSET - LABEL_HEIGHT : b.y + b.height + LABEL_OFFSET,
|
|
205
|
+
width,
|
|
206
|
+
height: LABEL_HEIGHT,
|
|
207
|
+
});
|
|
208
|
+
let leftGapTaken = false;
|
|
209
|
+
side.forEach(({ event, b }, i) => {
|
|
210
|
+
const stem = stems[i];
|
|
211
|
+
const name = event.name;
|
|
212
|
+
if (!name) {
|
|
213
|
+
leftGapTaken = false;
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const previous = stems[i - 1] ?? Number.NEGATIVE_INFINITY;
|
|
217
|
+
const next = stems[i + 1] ?? Number.POSITIVE_INFINITY;
|
|
218
|
+
const leftRoom = leftGapTaken ? 0 : stem - previous - 2 * LABEL_OFFSET;
|
|
219
|
+
const rightRoom = next - stem - 2 * LABEL_OFFSET;
|
|
220
|
+
const full = Math.max(name.length * LABEL_CHAR_WIDTH, LABEL_MIN_WIDTH);
|
|
221
|
+
leftGapTaken = false;
|
|
222
|
+
if (leftRoom >= full) {
|
|
223
|
+
const x = stem - LABEL_OFFSET - full;
|
|
224
|
+
if (i === 0)
|
|
225
|
+
outer.left = x - LABEL_OFFSET;
|
|
226
|
+
labels.set(event.id, place(b, x, full));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (rightRoom >= full) {
|
|
230
|
+
if (i === side.length - 1)
|
|
231
|
+
outer.right = stem + 2 * LABEL_OFFSET + full;
|
|
232
|
+
labels.set(event.id, place(b, stem + LABEL_OFFSET, full));
|
|
233
|
+
leftGapTaken = true;
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
// Neither gap holds it: beyond the outermost stem no stem crosses it.
|
|
237
|
+
if (i < side.length / 2) {
|
|
238
|
+
spill.left.push(() => {
|
|
239
|
+
outer.left -= full;
|
|
240
|
+
labels.set(event.id, place(b, outer.left, full));
|
|
241
|
+
outer.left -= LABEL_OFFSET;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
spill.right.push(() => {
|
|
246
|
+
labels.set(event.id, place(b, outer.right, full));
|
|
247
|
+
outer.right += full + LABEL_OFFSET;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
// Nearest stems first, so the order outward matches the order of the events.
|
|
252
|
+
for (const put of spill.left.reverse())
|
|
253
|
+
put();
|
|
254
|
+
for (const put of spill.right)
|
|
255
|
+
put();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return labels;
|
|
259
|
+
}
|
|
169
260
|
/** Events and gateways carry their name outside the shape; activities do not. */
|
|
170
261
|
function externalLabel(type, name, bounds) {
|
|
171
|
-
|
|
262
|
+
const width = externalLabelWidth(type, name);
|
|
263
|
+
if (width === undefined)
|
|
172
264
|
return undefined;
|
|
173
|
-
const width = Math.max(name.length * LABEL_CHAR_WIDTH, LABEL_MIN_WIDTH);
|
|
174
265
|
return {
|
|
175
266
|
x: bounds.x + bounds.width / 2 - width / 2,
|
|
176
267
|
y: bounds.y + bounds.height + LABEL_OFFSET,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BpmnFlowElement, BpmnLaneSet } from "../../bpmn/bpmn-model.js";
|
|
2
2
|
import type { Bounds } from "../types.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type BandLayout } from "./bands.js";
|
|
4
4
|
import type { SemanticGraph } from "./graph.js";
|
|
5
5
|
/** Geometry constants. Layout may add space beyond these; it never takes any back. */
|
|
6
6
|
export declare const H_GAP = 100;
|
|
@@ -8,6 +8,11 @@ export declare const V_GAP = 80;
|
|
|
8
8
|
export declare const COMPONENT_GAP = 80;
|
|
9
9
|
export declare const LANE_PADDING = 40;
|
|
10
10
|
export declare const BOUNDARY_SIZE = 36;
|
|
11
|
+
/**
|
|
12
|
+
* Width of the label an event or gateway carries centred below its shape;
|
|
13
|
+
* undefined for types whose name sits inside the shape.
|
|
14
|
+
*/
|
|
15
|
+
export declare function externalLabelWidth(type: string, name: string): number | undefined;
|
|
11
16
|
export interface Placement {
|
|
12
17
|
/** Absolute bounds per flow node, boundary events included. */
|
|
13
18
|
bounds: Map<string, Bounds>;
|
|
@@ -36,5 +41,18 @@ export declare function sizeOf(el: BpmnFlowElement, childExtent?: Bounds): {
|
|
|
36
41
|
export declare function place(graph: SemanticGraph, bandLayout: BandLayout, sizes: Map<string, {
|
|
37
42
|
width: number;
|
|
38
43
|
height: number;
|
|
39
|
-
}>, laneSet: BpmnLaneSet | undefined
|
|
44
|
+
}>, laneSet: BpmnLaneSet | undefined,
|
|
45
|
+
/**
|
|
46
|
+
* Pack nodes that have no sequence flow at all into a wrapped grid rather
|
|
47
|
+
* than one row each. Set for the inside of an expanded sub-process, where
|
|
48
|
+
* such nodes are an unordered set (the tools of an ad-hoc sub-process) and a
|
|
49
|
+
* single column would both imply an order and grow the container into a
|
|
50
|
+
* tall strip.
|
|
51
|
+
*/
|
|
52
|
+
packLoose?: boolean,
|
|
53
|
+
/**
|
|
54
|
+
* Hosts whose title is drawn along their top border — named expanded
|
|
55
|
+
* sub-processes. Boundary events stay off that border.
|
|
56
|
+
*/
|
|
57
|
+
titled?: ReadonlySet<string>): Placement;
|
|
40
58
|
//# sourceMappingURL=place.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ELEMENT_SIZES } from "../types.js";
|
|
1
|
+
import { ELEMENT_SIZES, LABEL_CHAR_WIDTH, LABEL_MIN_WIDTH } from "../types.js";
|
|
2
|
+
import { boundarySide } from "./bands.js";
|
|
2
3
|
/** Geometry constants. Layout may add space beyond these; it never takes any back. */
|
|
3
4
|
export const H_GAP = 100;
|
|
4
5
|
export const V_GAP = 80;
|
|
@@ -6,6 +7,27 @@ export const COMPONENT_GAP = 80;
|
|
|
6
7
|
export const LANE_PADDING = 40;
|
|
7
8
|
export const BOUNDARY_SIZE = 36;
|
|
8
9
|
const DEFAULT_SIZE = { width: 100, height: 80 };
|
|
10
|
+
const EXTERNAL_LABEL_TYPES = new Set([
|
|
11
|
+
"startEvent",
|
|
12
|
+
"endEvent",
|
|
13
|
+
"intermediateThrowEvent",
|
|
14
|
+
"intermediateCatchEvent",
|
|
15
|
+
"boundaryEvent",
|
|
16
|
+
"exclusiveGateway",
|
|
17
|
+
"parallelGateway",
|
|
18
|
+
"inclusiveGateway",
|
|
19
|
+
"eventBasedGateway",
|
|
20
|
+
"complexGateway",
|
|
21
|
+
]);
|
|
22
|
+
/**
|
|
23
|
+
* Width of the label an event or gateway carries centred below its shape;
|
|
24
|
+
* undefined for types whose name sits inside the shape.
|
|
25
|
+
*/
|
|
26
|
+
export function externalLabelWidth(type, name) {
|
|
27
|
+
if (!EXTERNAL_LABEL_TYPES.has(type))
|
|
28
|
+
return undefined;
|
|
29
|
+
return Math.max(name.length * LABEL_CHAR_WIDTH, LABEL_MIN_WIDTH);
|
|
30
|
+
}
|
|
9
31
|
export function sizeOf(el, childExtent) {
|
|
10
32
|
if (childExtent)
|
|
11
33
|
return { width: childExtent.width, height: childExtent.height };
|
|
@@ -18,7 +40,20 @@ export function sizeOf(el, childExtent) {
|
|
|
18
40
|
* their tallest. Nodes are centred in both, so any two nodes sharing a band
|
|
19
41
|
* share a centre line and the spine routes as one straight segment.
|
|
20
42
|
*/
|
|
21
|
-
export function place(graph, bandLayout, sizes, laneSet
|
|
43
|
+
export function place(graph, bandLayout, sizes, laneSet,
|
|
44
|
+
/**
|
|
45
|
+
* Pack nodes that have no sequence flow at all into a wrapped grid rather
|
|
46
|
+
* than one row each. Set for the inside of an expanded sub-process, where
|
|
47
|
+
* such nodes are an unordered set (the tools of an ad-hoc sub-process) and a
|
|
48
|
+
* single column would both imply an order and grow the container into a
|
|
49
|
+
* tall strip.
|
|
50
|
+
*/
|
|
51
|
+
packLoose = false,
|
|
52
|
+
/**
|
|
53
|
+
* Hosts whose title is drawn along their top border — named expanded
|
|
54
|
+
* sub-processes. Boundary events stay off that border.
|
|
55
|
+
*/
|
|
56
|
+
titled = new Set()) {
|
|
22
57
|
const bounds = new Map();
|
|
23
58
|
const componentOf = new Map();
|
|
24
59
|
for (let i = 0; i < graph.components.length; i++) {
|
|
@@ -41,11 +76,19 @@ export function place(graph, bandLayout, sizes, laneSet) {
|
|
|
41
76
|
x += (colWidth.get(rank) ?? 0) + H_GAP;
|
|
42
77
|
}
|
|
43
78
|
// ── Rows: one per band, laid out per component then stacked ──
|
|
79
|
+
const loose = packLoose ? looseNodes(graph) : [];
|
|
80
|
+
const looseSet = new Set(loose);
|
|
44
81
|
let cursorY = 0;
|
|
45
82
|
for (let component = 0; component < graph.components.length; component++) {
|
|
46
83
|
const members = (graph.components[component] ?? []).filter((id) => graph.byId.has(id));
|
|
47
84
|
if (members.length === 0)
|
|
48
85
|
continue;
|
|
86
|
+
if (members.length === 1 && looseSet.has(members[0])) {
|
|
87
|
+
// The whole grid takes the place of the first loose node; the rest are in it.
|
|
88
|
+
if (members[0] === loose[0])
|
|
89
|
+
cursorY = placeGrid(graph, loose, sizes, cursorY, bounds);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
49
92
|
const rowHeight = new Map();
|
|
50
93
|
for (const id of members) {
|
|
51
94
|
const band = bandLayout.bands.get(id) ?? 0;
|
|
@@ -75,9 +118,55 @@ export function place(graph, bandLayout, sizes, laneSet) {
|
|
|
75
118
|
}
|
|
76
119
|
separateSameCell(graph, bandLayout, bounds);
|
|
77
120
|
const lanes = laneSet ? applyLanes(graph, laneSet, bounds) : [];
|
|
78
|
-
dockBoundaryEvents(graph, bounds);
|
|
121
|
+
dockBoundaryEvents(graph, bounds, titled);
|
|
79
122
|
return { bounds, lanes, gutterX };
|
|
80
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Nodes with no incoming or outgoing flow, in declaration order — only when
|
|
126
|
+
* there are at least two of them, since one has nothing to be packed with.
|
|
127
|
+
*/
|
|
128
|
+
function looseNodes(graph) {
|
|
129
|
+
const loose = graph.components
|
|
130
|
+
.filter((members) => members.length === 1)
|
|
131
|
+
.map((members) => members[0])
|
|
132
|
+
// A one-node component can still loop on itself; that node has flow.
|
|
133
|
+
.filter((id) => graph.byId.has(id) &&
|
|
134
|
+
(graph.outgoing.get(id) ?? []).length === 0 &&
|
|
135
|
+
(graph.incoming.get(id) ?? []).length === 0);
|
|
136
|
+
return loose.length >= 2 ? loose : [];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Place `ids` row by row in `ceil(sqrt(n))` columns of equal cells, starting at
|
|
140
|
+
* `top`, so the set grows roughly square. Returns the cursor for whatever is
|
|
141
|
+
* stacked below.
|
|
142
|
+
*/
|
|
143
|
+
function placeGrid(graph, ids, sizes, top, bounds) {
|
|
144
|
+
const columns = Math.ceil(Math.sqrt(ids.length));
|
|
145
|
+
let cellWidth = 0;
|
|
146
|
+
let cellHeight = 0;
|
|
147
|
+
for (const id of ids) {
|
|
148
|
+
const size = sizes.get(id) ?? DEFAULT_SIZE;
|
|
149
|
+
// An event's or gateway's label is centred below it and can be wider than the
|
|
150
|
+
// shape; the cell holds it so neighbouring columns' labels never meet.
|
|
151
|
+
const el = graph.byId.get(id);
|
|
152
|
+
const label = el?.name ? externalLabelWidth(el.type, el.name) : undefined;
|
|
153
|
+
cellWidth = Math.max(cellWidth, size.width, label ?? 0);
|
|
154
|
+
cellHeight = Math.max(cellHeight, size.height);
|
|
155
|
+
}
|
|
156
|
+
ids.forEach((id, i) => {
|
|
157
|
+
const size = sizes.get(id) ?? DEFAULT_SIZE;
|
|
158
|
+
const column = i % columns;
|
|
159
|
+
const row = Math.floor(i / columns);
|
|
160
|
+
bounds.set(id, {
|
|
161
|
+
x: column * (cellWidth + H_GAP) + (cellWidth - size.width) / 2,
|
|
162
|
+
y: top + row * (cellHeight + V_GAP) + (cellHeight - size.height) / 2,
|
|
163
|
+
width: size.width,
|
|
164
|
+
height: size.height,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
const rows = Math.ceil(ids.length / columns);
|
|
168
|
+
return top + rows * (cellHeight + V_GAP) - V_GAP + COMPONENT_GAP;
|
|
169
|
+
}
|
|
81
170
|
/**
|
|
82
171
|
* Two nodes can land in the same rank and band — a parallel split whose
|
|
83
172
|
* branches were compacted onto one band, for instance. Push the later ones
|
|
@@ -223,16 +312,19 @@ function laneTree(laneSet) {
|
|
|
223
312
|
/**
|
|
224
313
|
* Dock boundary events on their host's edge — escalation on top, everything
|
|
225
314
|
* else on the bottom — spread along it. Events sharing a side are ordered by
|
|
226
|
-
* how far their handler
|
|
315
|
+
* how far out from that border their handler ended up, then how far it runs —
|
|
316
|
+
* farthest first, so outer slots serve outer paths and the routes nest.
|
|
317
|
+
* The side comes from {@link boundarySide}, the rule that also placed the
|
|
318
|
+
* handler's band, so a handler is never routed around its own host.
|
|
227
319
|
*/
|
|
228
|
-
function dockBoundaryEvents(graph, bounds) {
|
|
320
|
+
function dockBoundaryEvents(graph, bounds, titled) {
|
|
229
321
|
for (const [hostId, events] of graph.attachers) {
|
|
230
322
|
const host = bounds.get(hostId);
|
|
231
323
|
if (!host)
|
|
232
324
|
continue;
|
|
233
325
|
const sides = new Map();
|
|
234
326
|
for (const event of events) {
|
|
235
|
-
const side = event.
|
|
327
|
+
const side = boundarySide(event, titled.has(hostId)) === -1 ? "top" : "bottom";
|
|
236
328
|
const list = sides.get(side);
|
|
237
329
|
if (list)
|
|
238
330
|
list.push(event);
|
|
@@ -240,7 +332,9 @@ function dockBoundaryEvents(graph, bounds) {
|
|
|
240
332
|
sides.set(side, [event]);
|
|
241
333
|
}
|
|
242
334
|
for (const [side, list] of sides) {
|
|
243
|
-
const ordered = [...list].sort((a, b) =>
|
|
335
|
+
const ordered = [...list].sort((a, b) => handlerDepth(graph, bounds, hostId, host, side, b.id) -
|
|
336
|
+
handlerDepth(graph, bounds, hostId, host, side, a.id) ||
|
|
337
|
+
handlerReach(graph, b.id) - handlerReach(graph, a.id));
|
|
244
338
|
const n = ordered.length;
|
|
245
339
|
for (let i = 0; i < n; i++) {
|
|
246
340
|
const event = ordered[i];
|
|
@@ -256,6 +350,29 @@ function dockBoundaryEvents(graph, bounds) {
|
|
|
256
350
|
}
|
|
257
351
|
}
|
|
258
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* How far out from the docked border the handler of a boundary event sits,
|
|
355
|
+
* measured on the final positions (after lanes, which can reorder handlers
|
|
356
|
+
* against their bands). Negative when the handler lies behind the border.
|
|
357
|
+
*
|
|
358
|
+
* Each handler leaves its event straight out and turns toward its target, so
|
|
359
|
+
* the event docked outermost has to serve the farthest handler; otherwise its
|
|
360
|
+
* turn cuts across the stems of the events docked inside it.
|
|
361
|
+
*/
|
|
362
|
+
function handlerDepth(graph, bounds, hostId, host, side, eventId) {
|
|
363
|
+
let depth = Number.NEGATIVE_INFINITY;
|
|
364
|
+
// Flows out of a boundary event are keyed by its host (see graph.ts).
|
|
365
|
+
for (const flow of graph.outgoing.get(hostId) ?? []) {
|
|
366
|
+
if (flow.sourceRef !== eventId)
|
|
367
|
+
continue;
|
|
368
|
+
const target = bounds.get(flow.targetRef);
|
|
369
|
+
if (!target)
|
|
370
|
+
continue;
|
|
371
|
+
const centre = target.y + target.height / 2;
|
|
372
|
+
depth = Math.max(depth, side === "top" ? host.y - centre : centre - (host.y + host.height));
|
|
373
|
+
}
|
|
374
|
+
return Number.isFinite(depth) ? depth : 0;
|
|
375
|
+
}
|
|
259
376
|
/** How far the handler of a boundary event runs, in ranks. */
|
|
260
377
|
function handlerReach(graph, eventId) {
|
|
261
378
|
let reach = 0;
|
|
@@ -94,7 +94,7 @@ export function routeFlows(graph, flows, bounds, bandLayout, gutterX) {
|
|
|
94
94
|
const direct = isBackEdge
|
|
95
95
|
? []
|
|
96
96
|
: fromBoundary
|
|
97
|
-
? fromBoundaryCandidates(ctx, source, target, targetRank)
|
|
97
|
+
? fromBoundaryCandidates(ctx, source, bounds.get(hostOf(graph, flow.sourceRef)), target, targetRank)
|
|
98
98
|
: forwardCandidates(ctx, source, target, sourceRank, targetRank);
|
|
99
99
|
const clear = pick(direct, ctx, flow.sourceRef, flow.targetRef);
|
|
100
100
|
if (clear && clear.crossings <= CROSSING_TOLERANCE) {
|
|
@@ -335,14 +335,22 @@ function forwardCandidates(ctx, source, target, sourceRank, targetRank) {
|
|
|
335
335
|
}
|
|
336
336
|
return candidates;
|
|
337
337
|
}
|
|
338
|
-
/**
|
|
339
|
-
|
|
338
|
+
/**
|
|
339
|
+
* A boundary event leaves through its outward side, never into its host.
|
|
340
|
+
*
|
|
341
|
+
* The side is where the event is docked, not where the target lies: lanes can
|
|
342
|
+
* put a handler above a host whose event sits on its bottom border. A target
|
|
343
|
+
* behind the docked side is reached around the stem, not straight at it.
|
|
344
|
+
*/
|
|
345
|
+
function fromBoundaryCandidates(ctx, source, host, target, targetRank) {
|
|
340
346
|
const from = centre(source);
|
|
341
347
|
const to = centre(target);
|
|
342
|
-
|
|
348
|
+
// Same side test as searchRoute and the label placement.
|
|
349
|
+
const down = host === undefined ? to.y >= from.y : from.y > host.y + 1;
|
|
343
350
|
const exitY = down ? source.y + source.height : source.y;
|
|
344
351
|
const stem = down ? exitY + BOUNDARY_STEM : exitY - BOUNDARY_STEM;
|
|
345
|
-
|
|
352
|
+
const ahead = down ? to.y >= exitY : to.y <= exitY;
|
|
353
|
+
if (ahead && Math.abs(from.x - to.x) < 1) {
|
|
346
354
|
return [
|
|
347
355
|
[
|
|
348
356
|
{ x: from.x, y: exitY },
|
|
@@ -352,19 +360,22 @@ function fromBoundaryCandidates(ctx, source, target, targetRank) {
|
|
|
352
360
|
}
|
|
353
361
|
if (target.x >= from.x) {
|
|
354
362
|
const gutter = ctx.gutterX.get(targetRank ?? 0) ?? target.x - H_GAP / 2;
|
|
363
|
+
const around = [
|
|
364
|
+
{ x: from.x, y: exitY },
|
|
365
|
+
{ x: from.x, y: stem },
|
|
366
|
+
{ x: gutter, y: stem },
|
|
367
|
+
{ x: gutter, y: to.y },
|
|
368
|
+
{ x: target.x, y: to.y },
|
|
369
|
+
];
|
|
370
|
+
if (!ahead)
|
|
371
|
+
return [around];
|
|
355
372
|
return [
|
|
356
373
|
[
|
|
357
374
|
{ x: from.x, y: exitY },
|
|
358
375
|
{ x: from.x, y: to.y },
|
|
359
376
|
{ x: target.x, y: to.y },
|
|
360
377
|
],
|
|
361
|
-
|
|
362
|
-
{ x: from.x, y: exitY },
|
|
363
|
-
{ x: from.x, y: stem },
|
|
364
|
-
{ x: gutter, y: stem },
|
|
365
|
-
{ x: gutter, y: to.y },
|
|
366
|
-
{ x: target.x, y: to.y },
|
|
367
|
-
],
|
|
378
|
+
around,
|
|
368
379
|
];
|
|
369
380
|
}
|
|
370
381
|
return [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bpmnkit/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"node": ">=20"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@bpmnkit/feel": "^1.1.
|
|
31
|
+
"@bpmnkit/feel": "^1.1.1"
|
|
32
32
|
},
|
|
33
33
|
"description": "TypeScript-first BPMN 2.0 SDK — parse, build, layout, and optimize diagrams",
|
|
34
34
|
"keywords": [
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"repository": {
|
|
46
46
|
"type": "git",
|
|
47
|
-
"url": "https://github.com/bpmnkit/
|
|
47
|
+
"url": "https://github.com/bpmnkit/bpmnkit"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://bpmnkit.com",
|
|
50
50
|
"bugs": {
|
|
51
|
-
"url": "https://github.com/bpmnkit/
|
|
51
|
+
"url": "https://github.com/bpmnkit/bpmnkit/issues"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|