@bpmnkit/core 1.15.0 → 1.17.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/builder-reference.md +2 -1
- package/dist/bpmn/auto-layout.d.ts +0 -8
- package/dist/bpmn/auto-layout.js +605 -98
- package/dist/bpmn/bpmn-builder.d.ts +120 -14
- package/dist/bpmn/bpmn-builder.js +411 -152
- package/dist/bpmn/bpmn-model.d.ts +15 -0
- package/dist/bpmn/bpmn-parser.js +32 -6
- package/dist/bpmn/bpmn-serializer.js +9 -2
- package/dist/bpmn/compact-stream.d.ts +7 -0
- package/dist/bpmn/compact-stream.js +7 -0
- package/dist/bpmn/compact.d.ts +124 -9
- package/dist/bpmn/compact.js +295 -27
- package/dist/bpmn/full-operations.d.ts +19 -0
- package/dist/bpmn/full-operations.js +191 -7
- package/dist/bpmn/make-room.js +114 -0
- package/dist/bpmn/place-new-shapes.js +4 -2
- package/dist/bpmn/preserving-writer.d.ts +1 -1
- package/dist/bpmn/preserving-writer.js +1 -1
- package/dist/bpmn/process-delta.d.ts +32 -1
- package/dist/bpmn/process-delta.js +62 -1
- package/dist/bpmn/process-text-writer.d.ts +18 -7
- package/dist/bpmn/process-text-writer.js +105 -22
- package/dist/bpmn/process-text.d.ts +27 -1
- package/dist/bpmn/process-text.js +350 -2
- package/dist/bpmn/swimlanes.d.ts +178 -0
- package/dist/bpmn/swimlanes.js +774 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3 -2
- package/dist/layout/collaboration/crossings.d.ts +13 -0
- package/dist/layout/collaboration/crossings.js +37 -0
- package/dist/layout/collaboration/docked-labels.d.ts +21 -0
- package/dist/layout/collaboration/docked-labels.js +65 -0
- package/dist/layout/collaboration/message-tracks.d.ts +20 -0
- package/dist/layout/collaboration/message-tracks.js +78 -0
- package/dist/layout/collaboration/stack-crossings.d.ts +38 -0
- package/dist/layout/collaboration/stack-crossings.js +155 -0
- package/dist/layout/grid/edge-labels.js +21 -10
- package/dist/layout/layered/coords.d.ts +13 -0
- package/dist/layout/layered/coords.js +211 -0
- package/dist/layout/layered/index.d.ts +21 -0
- package/dist/layout/layered/index.js +288 -0
- package/dist/layout/layered/layers.d.ts +60 -0
- package/dist/layout/layered/layers.js +374 -0
- package/dist/layout/layered/route.d.ts +66 -0
- package/dist/layout/layered/route.js +369 -0
- package/dist/layout/layout-engine.d.ts +6 -2
- package/dist/layout/layout-engine.js +4 -2
- package/dist/layout/semantic/bands.js +8 -2
- package/dist/layout/semantic/graph.d.ts +33 -1
- package/dist/layout/semantic/graph.js +200 -4
- package/dist/layout/semantic/index.d.ts +8 -2
- package/dist/layout/semantic/index.js +114 -14
- package/dist/layout/semantic/lanes.d.ts +40 -0
- package/dist/layout/semantic/lanes.js +198 -0
- package/dist/layout/semantic/place.d.ts +46 -2
- package/dist/layout/semantic/place.js +248 -30
- package/dist/layout/semantic/route.js +35 -2
- package/dist/layout/types.d.ts +0 -8
- package/dist/xml/xml-patch.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertBpmnDefinitions, assertCompactDiagram } from "./argument-guards.js";
|
|
2
|
-
import { buildFlowElement, compactify, defaultFlows, makeEventDef, } from "./compact.js";
|
|
2
|
+
import { buildFlowElement, compactify, compactifyLanes, compactifyMessageFlow, compactifyParticipant, defaultFlows, executability, expandCollaborations, fillLanes, isPooled, makeEventDef, withLanes, } from "./compact.js";
|
|
3
3
|
import { assignEventDefinitionIds } from "./stable-ids.js";
|
|
4
|
+
import { allLanes, collaborationProblems, documentIdList, poolLanedProcesses, pruneLaneRefs, } from "./swimlanes.js";
|
|
4
5
|
import { assertZeebePlacement, bpmnElementName, ensureZeebeExtension, isZeebePlacementAllowed, zeebeExtensionsToXmlElements, } from "./zeebe-extensions.js";
|
|
5
6
|
/** Thrown by {@link applyBpmnOperations} in strict mode. */
|
|
6
7
|
export class OperationError extends Error {
|
|
@@ -617,16 +618,23 @@ export function applyBpmnOperations(definitions, operations, options = {}) {
|
|
|
617
618
|
const draft = structuredClone(definitions);
|
|
618
619
|
const problems = [];
|
|
619
620
|
let applied = 0;
|
|
621
|
+
const inserted = [];
|
|
620
622
|
operations.forEach((operation, index) => {
|
|
621
623
|
const reason = applyOne(draft, operation);
|
|
622
|
-
if (reason
|
|
623
|
-
applied++;
|
|
624
|
-
else
|
|
624
|
+
if (reason !== undefined)
|
|
625
625
|
problems.push({ index, operation, reason });
|
|
626
|
+
else {
|
|
627
|
+
applied++;
|
|
628
|
+
if (operation.op === "insert")
|
|
629
|
+
inserted.push(operation.element.id);
|
|
630
|
+
}
|
|
626
631
|
});
|
|
627
632
|
if ((options.strict ?? true) && problems.length > 0) {
|
|
628
633
|
throw new OperationError(problems);
|
|
629
634
|
}
|
|
635
|
+
// After every operation rather than at the insert, so the flows a batch adds
|
|
636
|
+
// next to a new node decide its lane.
|
|
637
|
+
draft.processes = draft.processes.map((process) => fillLanes(process, inserted));
|
|
630
638
|
return { definitions: draft, applied, problems };
|
|
631
639
|
}
|
|
632
640
|
function applyOne(definitions, operation) {
|
|
@@ -652,6 +660,11 @@ function applyOne(definitions, operation) {
|
|
|
652
660
|
// A flow to or from a removed element would dangle.
|
|
653
661
|
found.container.sequenceFlows = found.container.sequenceFlows.filter((flow) => flow.sourceRef !== operation.id && flow.targetRef !== operation.id);
|
|
654
662
|
recomputeRefs(found.container);
|
|
663
|
+
// A lane ref or a message flow naming the removed node would dangle too.
|
|
664
|
+
definitions.processes = definitions.processes.map((process) => process === found.container ? pruneLaneRefs(process) : process);
|
|
665
|
+
for (const collaboration of definitions.collaborations) {
|
|
666
|
+
collaboration.messageFlows = collaboration.messageFlows.filter((flow) => flow.sourceRef !== operation.id && flow.targetRef !== operation.id);
|
|
667
|
+
}
|
|
655
668
|
return undefined;
|
|
656
669
|
}
|
|
657
670
|
case "insert": {
|
|
@@ -762,20 +775,44 @@ function recomputeRefs(container) {
|
|
|
762
775
|
* a multi-process document means "this is how that process should look", not
|
|
763
776
|
* "delete the others".
|
|
764
777
|
*
|
|
778
|
+
* Lanes, pools and executability follow the same rule: a key the compact leaves
|
|
779
|
+
* out leaves that part of the model alone. A process's `lanes` rebuilds its
|
|
780
|
+
* membership (an empty list removes the lane set), keeping the attributes and
|
|
781
|
+
* extensions of every lane whose id survives; members that are not top-level
|
|
782
|
+
* flow nodes are dropped and unlisted nodes are placed as {@link expand} places
|
|
783
|
+
* them. `participants` and `messageFlows` replace those of the first
|
|
784
|
+
* collaboration, keeping what the compact form does not carry (`messageRef`,
|
|
785
|
+
* extensions, foreign attributes) on every id that survives. A lane, pool or
|
|
786
|
+
* message flow listed without a `name` has none, as {@link compactify} writes
|
|
787
|
+
* it, so a compact edit can remove a name. A laned process
|
|
788
|
+
* without a pool then gets one. A process the compact adds gets the
|
|
789
|
+
* `isExecutable` {@link expand} would give it, so a keyless partner pool is
|
|
790
|
+
* not executable. Without the keys, a deleted node still leaves
|
|
791
|
+
* its lanes and message flows, and an inserted one joins its predecessor's lane.
|
|
792
|
+
*
|
|
765
793
|
* @param definitions - The model to update. Never mutated.
|
|
766
794
|
* @param compact - The intended topology.
|
|
767
795
|
* @param options - `strict` (default `true`) throws instead of returning problems.
|
|
768
796
|
* @returns The updated model, plus what applied and what did not.
|
|
797
|
+
* @throws Error, in either mode, when the result would carry an id used twice
|
|
798
|
+
* or a collaboration problem (a dangling message end or process reference, a
|
|
799
|
+
* message inside one pool) that `definitions` did not already have: the
|
|
800
|
+
* input is invalid, as {@link expand} would find it.
|
|
769
801
|
*/
|
|
770
802
|
export function reconcileCompact(definitions, compact, options = {}) {
|
|
771
803
|
assertBpmnDefinitions(definitions, "reconcileCompact");
|
|
772
804
|
assertCompactDiagram(compact, "reconcileCompact");
|
|
773
805
|
const draft = structuredClone(definitions);
|
|
774
|
-
|
|
806
|
+
// A new process gets the executability expand would give it: Flowable deploys
|
|
807
|
+
// a process with no isExecutable, so a keyless partner pool must say false.
|
|
808
|
+
// poolLanedProcesses cannot, as it only marks the pools it creates itself.
|
|
809
|
+
const executable = executability(compact, isPooled(compact));
|
|
810
|
+
compact.processes.forEach((compactProcess, index) => {
|
|
775
811
|
if (!draft.processes.some((process) => process.id === compactProcess.id)) {
|
|
776
812
|
draft.processes.push({
|
|
777
813
|
id: compactProcess.id,
|
|
778
814
|
name: compactProcess.name,
|
|
815
|
+
...(executable[index] === false ? { isExecutable: false } : {}),
|
|
779
816
|
extensionElements: [],
|
|
780
817
|
flowElements: [],
|
|
781
818
|
sequenceFlows: [],
|
|
@@ -785,10 +822,157 @@ export function reconcileCompact(definitions, compact, options = {}) {
|
|
|
785
822
|
unknownAttributes: {},
|
|
786
823
|
});
|
|
787
824
|
}
|
|
788
|
-
}
|
|
825
|
+
});
|
|
789
826
|
const result = applyBpmnOperations(draft, operationsForCompact(draft, compact), options);
|
|
790
827
|
reconcileDefaultFlows(result.definitions, compact);
|
|
791
|
-
|
|
828
|
+
const reconciled = reconcilePools(result.definitions, compact);
|
|
829
|
+
const broken = newStructureProblems(definitions, reconciled);
|
|
830
|
+
if (broken.length > 0) {
|
|
831
|
+
throw new Error(`reconcileCompact: invalid CompactDiagram — ${broken.join("; ")}`);
|
|
832
|
+
}
|
|
833
|
+
return { ...result, definitions: reconciled };
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* What `after` gets wrong that `before` did not: {@link collaborationProblems}
|
|
837
|
+
* and ids used twice across the document. The pool and lane keys are merged in
|
|
838
|
+
* after the operations, so nothing else checks that their ids and references
|
|
839
|
+
* hold. A problem the input already had is the caller's document, not this edit.
|
|
840
|
+
*/
|
|
841
|
+
function newStructureProblems(before, after) {
|
|
842
|
+
const had = new Set(collaborationProblems(before));
|
|
843
|
+
const found = collaborationProblems(after).filter((problem) => !had.has(problem));
|
|
844
|
+
// Counted rather than compared as messages, so a new clash on an id the
|
|
845
|
+
// input already used twice is still caught.
|
|
846
|
+
const wasUsed = idCounts(before);
|
|
847
|
+
for (const [id, count] of idCounts(after)) {
|
|
848
|
+
if (count > 1 && count > (wasUsed.get(id) ?? 0))
|
|
849
|
+
found.push(`Duplicate element ID "${id}"`);
|
|
850
|
+
}
|
|
851
|
+
return [...new Set(found)];
|
|
852
|
+
}
|
|
853
|
+
/** How many times each id is used in the document ({@link documentIdList}). */
|
|
854
|
+
function idCounts(definitions) {
|
|
855
|
+
const counts = new Map();
|
|
856
|
+
for (const id of documentIdList(definitions))
|
|
857
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
858
|
+
return counts;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Applies the `executable`, `lanes`, `participants` and `messageFlows` keys
|
|
862
|
+
* `compact` carries. A key that says what the model already says changes
|
|
863
|
+
* nothing, so reconciling `compactify(defs)` onto `defs` stays a no-op.
|
|
864
|
+
*/
|
|
865
|
+
function reconcilePools(definitions, compact) {
|
|
866
|
+
const wanted = new Map(compact.processes.map((process) => [process.id, process]));
|
|
867
|
+
let changed = false;
|
|
868
|
+
const processes = definitions.processes.map((process) => {
|
|
869
|
+
const compactProcess = wanted.get(process.id);
|
|
870
|
+
let next = process;
|
|
871
|
+
const executable = compactProcess?.executable;
|
|
872
|
+
// An absent attribute already means executable (Flowable), so `true` leaves it absent.
|
|
873
|
+
if (executable !== undefined && executable !== (next.isExecutable !== false)) {
|
|
874
|
+
next = { ...next, isExecutable: executable };
|
|
875
|
+
}
|
|
876
|
+
const lanes = compactProcess?.lanes;
|
|
877
|
+
if (lanes !== undefined && !sameJson(compactifyLanes(next), lanes)) {
|
|
878
|
+
next = relane(next, lanes);
|
|
879
|
+
changed = true;
|
|
880
|
+
}
|
|
881
|
+
return next;
|
|
882
|
+
});
|
|
883
|
+
const first = definitions.collaborations[0];
|
|
884
|
+
const poolsChanged = (compact.participants !== undefined &&
|
|
885
|
+
!sameJson(first?.participants.map(compactifyParticipant) ?? [], compact.participants)) ||
|
|
886
|
+
(compact.messageFlows !== undefined &&
|
|
887
|
+
!sameJson(first?.messageFlows.map(compactifyMessageFlow) ?? [], compact.messageFlows));
|
|
888
|
+
if (!changed && !poolsChanged)
|
|
889
|
+
return { ...definitions, processes };
|
|
890
|
+
return poolLanedProcesses({
|
|
891
|
+
...definitions,
|
|
892
|
+
processes,
|
|
893
|
+
collaborations: poolsChanged
|
|
894
|
+
? reconcileCollaborations({ ...definitions, processes }, compact)
|
|
895
|
+
: definitions.collaborations,
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
/** Equal as JSON: key order counts, so a reordered but equal input reads as a change, which is safe. */
|
|
899
|
+
function sameJson(a, b) {
|
|
900
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
901
|
+
}
|
|
902
|
+
/** `process` with the membership `lanes` describes, keeping what each surviving lane carries. */
|
|
903
|
+
function relane(process, lanes) {
|
|
904
|
+
const { laneSet: previous, ...bare } = process;
|
|
905
|
+
if (lanes.length === 0)
|
|
906
|
+
return bare;
|
|
907
|
+
const rebuilt = pruneLaneRefs(withLanes(bare, lanes)).laneSet;
|
|
908
|
+
if (rebuilt === undefined)
|
|
909
|
+
return bare;
|
|
910
|
+
const before = new Map(allLanes(previous).map((lane) => [lane.id, lane]));
|
|
911
|
+
// `rebuilt` comes from buildLaneSet, which refuses a looping tree, so this terminates.
|
|
912
|
+
const mergeSet = (built, old) => ({
|
|
913
|
+
...built,
|
|
914
|
+
...old,
|
|
915
|
+
lanes: built.lanes.map(mergeLane),
|
|
916
|
+
});
|
|
917
|
+
const mergeLane = (built) => {
|
|
918
|
+
const old = before.get(built.id);
|
|
919
|
+
// The compact lane states its name the way compactify writes it: none when it has none.
|
|
920
|
+
const { childLaneSet: _oldChildren, name: _oldName, ...kept } = old ?? { unknownAttributes: {} };
|
|
921
|
+
const lane = { ...kept, id: built.id, flowNodeRefs: built.flowNodeRefs };
|
|
922
|
+
if (built.name)
|
|
923
|
+
lane.name = built.name;
|
|
924
|
+
if (built.childLaneSet !== undefined) {
|
|
925
|
+
lane.childLaneSet = mergeSet(built.childLaneSet, old?.childLaneSet);
|
|
926
|
+
}
|
|
927
|
+
return lane;
|
|
928
|
+
};
|
|
929
|
+
return { ...bare, laneSet: mergeSet(rebuilt, previous) };
|
|
930
|
+
}
|
|
931
|
+
/** The collaborations once the compact's `participants` and `messageFlows` keys are applied. */
|
|
932
|
+
function reconcileCollaborations(definitions, compact) {
|
|
933
|
+
if (compact.participants === undefined && compact.messageFlows === undefined) {
|
|
934
|
+
return definitions.collaborations;
|
|
935
|
+
}
|
|
936
|
+
const [first, ...rest] = definitions.collaborations;
|
|
937
|
+
if (first === undefined)
|
|
938
|
+
return expandCollaborations(compact, documentIds(definitions, compact));
|
|
939
|
+
return [
|
|
940
|
+
{
|
|
941
|
+
...first,
|
|
942
|
+
participants: compact.participants?.map((participant) => mergeParticipant(first.participants.find((p) => p.id === participant.id), participant)) ?? first.participants,
|
|
943
|
+
messageFlows: compact.messageFlows?.map((flow) => mergeMessageFlow(first.messageFlows.find((f) => f.id === flow.id), flow)) ?? first.messageFlows,
|
|
944
|
+
},
|
|
945
|
+
...rest,
|
|
946
|
+
];
|
|
947
|
+
}
|
|
948
|
+
function mergeParticipant(old, wanted) {
|
|
949
|
+
const { processRef: _oldRef, name: _oldName, ...kept } = old ?? { unknownAttributes: {} };
|
|
950
|
+
const participant = { ...kept, id: wanted.id };
|
|
951
|
+
if (wanted.name)
|
|
952
|
+
participant.name = wanted.name;
|
|
953
|
+
if (wanted.processId !== undefined)
|
|
954
|
+
participant.processRef = wanted.processId;
|
|
955
|
+
return participant;
|
|
956
|
+
}
|
|
957
|
+
function mergeMessageFlow(old, wanted) {
|
|
958
|
+
const { name: _oldName, ...kept } = old ?? { unknownAttributes: {} };
|
|
959
|
+
const flow = {
|
|
960
|
+
...kept,
|
|
961
|
+
id: wanted.id,
|
|
962
|
+
sourceRef: wanted.source,
|
|
963
|
+
targetRef: wanted.target,
|
|
964
|
+
};
|
|
965
|
+
if (wanted.name)
|
|
966
|
+
flow.name = wanted.name;
|
|
967
|
+
return flow;
|
|
968
|
+
}
|
|
969
|
+
/** Ids a new collaboration must not take: every process, element, flow and lane, and the compact's pool ids. */
|
|
970
|
+
function documentIds(definitions, compact) {
|
|
971
|
+
const ids = new Set(documentIdList(definitions));
|
|
972
|
+
for (const item of [...(compact.participants ?? []), ...(compact.messageFlows ?? [])]) {
|
|
973
|
+
ids.add(item.id);
|
|
974
|
+
}
|
|
975
|
+
return ids;
|
|
792
976
|
}
|
|
793
977
|
/**
|
|
794
978
|
* Brings each gateway's `bpmn:default` in line with the flow the compact input
|
package/dist/bpmn/make-room.js
CHANGED
|
@@ -49,6 +49,9 @@ export function makeRoom(input) {
|
|
|
49
49
|
containers.add(el.id);
|
|
50
50
|
}
|
|
51
51
|
const anchors = [];
|
|
52
|
+
// Drawn nodes the new path flows into that sit at or left of its anchor, as
|
|
53
|
+
// a lane hand-over column leaves them: they and what follows move right of the path.
|
|
54
|
+
const stragglers = [];
|
|
52
55
|
for (const process of defs.processes) {
|
|
53
56
|
for (const scope of scopes(process.flowElements, process.sequenceFlows)) {
|
|
54
57
|
const byId = new Map(scope.elements.map((e) => [e.id, e]));
|
|
@@ -111,6 +114,18 @@ export function makeRoom(input) {
|
|
|
111
114
|
if (b.y + b.height > top && b.y < bottom)
|
|
112
115
|
nextX = Math.min(nextX, b.x);
|
|
113
116
|
}
|
|
117
|
+
const downstream = reachableDrawn(scope, chain, el.id, byId, shapeOf);
|
|
118
|
+
if (downstream.some((id) => {
|
|
119
|
+
const b = shapeOf.get(id)?.bounds;
|
|
120
|
+
return b !== undefined && b.x < x0 && !containers.has(id);
|
|
121
|
+
}))
|
|
122
|
+
stragglers.push({
|
|
123
|
+
shape,
|
|
124
|
+
after: el.id,
|
|
125
|
+
need,
|
|
126
|
+
down: downstream,
|
|
127
|
+
column: soleExit(scope, chain, shape, byId, shapeOf, downstream),
|
|
128
|
+
});
|
|
114
129
|
const dx = Math.max(0, need + GAP - (nextX - x0));
|
|
115
130
|
if (dx === 0)
|
|
116
131
|
continue;
|
|
@@ -146,6 +161,105 @@ export function makeRoom(input) {
|
|
|
146
161
|
}
|
|
147
162
|
result.shifted.push({ after, dx });
|
|
148
163
|
}
|
|
164
|
+
// Per insertion point, after the global shifts: left-over successors clear the new path.
|
|
165
|
+
for (const { shape, after, need, down, column } of stragglers) {
|
|
166
|
+
const x0 = shape.bounds.x + shape.bounds.width;
|
|
167
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
168
|
+
for (const id of down) {
|
|
169
|
+
const b = shapeOf.get(id)?.bounds;
|
|
170
|
+
if (b && b.x < x0 && !containers.has(id))
|
|
171
|
+
minX = Math.min(minX, b.x);
|
|
172
|
+
}
|
|
173
|
+
const target = column ? shapeOf.get(column.id)?.bounds : undefined;
|
|
174
|
+
const stacked = column && target ? column.centre - (target.x + target.width / 2) : 0;
|
|
175
|
+
const dx = stacked > 0 ? stacked : x0 + need + GAP - minX;
|
|
176
|
+
if (!Number.isFinite(minX) || dx <= 0)
|
|
177
|
+
continue;
|
|
178
|
+
const moved = new Set(down);
|
|
179
|
+
for (const id of down) {
|
|
180
|
+
const s = shapeOf.get(id);
|
|
181
|
+
if (!s)
|
|
182
|
+
continue;
|
|
183
|
+
s.bounds.x += dx;
|
|
184
|
+
if (s.label?.bounds)
|
|
185
|
+
s.label.bounds.x += dx;
|
|
186
|
+
}
|
|
187
|
+
for (const edge of defs.diagrams.flatMap((d) => d.plane.edges)) {
|
|
188
|
+
const flow = defs.processes
|
|
189
|
+
.flatMap((p) => p.sequenceFlows)
|
|
190
|
+
.find((f) => f.id === edge.bpmnElement);
|
|
191
|
+
if (flow && moved.has(flow.sourceRef) && moved.has(flow.targetRef)) {
|
|
192
|
+
for (const p of edge.waypoints)
|
|
193
|
+
p.x += dx;
|
|
194
|
+
if (edge.label?.bounds)
|
|
195
|
+
edge.label.bounds.x += dx;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Pools and lanes grow to hold them.
|
|
199
|
+
for (const s of shapes) {
|
|
200
|
+
const b = s.bounds;
|
|
201
|
+
if (containers.has(s.bpmnElement) &&
|
|
202
|
+
b.x < x0 &&
|
|
203
|
+
b.x + b.width < x0 + dx + 100 &&
|
|
204
|
+
b.x + b.width > x0)
|
|
205
|
+
b.width += dx;
|
|
206
|
+
}
|
|
207
|
+
result.shifted.push({ after, dx });
|
|
208
|
+
}
|
|
149
209
|
return result;
|
|
150
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* A one-node new path whose only exit is a drawn node in another row (a
|
|
213
|
+
* lane hand-over): that node goes under the new node, so the flow stays
|
|
214
|
+
* vertical, as the engine lays such hand-overs out.
|
|
215
|
+
*/
|
|
216
|
+
function soleExit(scope, chain, anchor, byId, shapeOf, downstream) {
|
|
217
|
+
if (chain.size !== 1)
|
|
218
|
+
return undefined;
|
|
219
|
+
const [only] = [...chain];
|
|
220
|
+
const node = only === undefined ? undefined : byId.get(only);
|
|
221
|
+
const exits = scope.flows.filter((f) => f.sourceRef === only && !chain.has(f.targetRef));
|
|
222
|
+
const exit = exits.length === 1 ? exits[0]?.targetRef : undefined;
|
|
223
|
+
const b = exit === undefined || !downstream.includes(exit) ? undefined : shapeOf.get(exit)?.bounds;
|
|
224
|
+
if (!node || !b)
|
|
225
|
+
return undefined;
|
|
226
|
+
const a = anchor.bounds;
|
|
227
|
+
if (b.y < a.y + a.height && b.y + b.height > a.y)
|
|
228
|
+
return undefined;
|
|
229
|
+
return { id: exit, centre: a.x + a.width + GAP + sizeOf(node).width / 2 };
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Drawn nodes reached from a new chain's exits, leaving out the ones that
|
|
233
|
+
* lead back into the anchor (a loop's upstream half does not follow the path).
|
|
234
|
+
*/
|
|
235
|
+
function reachableDrawn(scope, chain, anchor, byId, shapeOf) {
|
|
236
|
+
const upstream = new Set([anchor]);
|
|
237
|
+
for (let grew = true; grew;) {
|
|
238
|
+
grew = false;
|
|
239
|
+
for (const f of scope.flows)
|
|
240
|
+
if (upstream.has(f.targetRef) && !upstream.has(f.sourceRef)) {
|
|
241
|
+
upstream.add(f.sourceRef);
|
|
242
|
+
grew = true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const out = [];
|
|
246
|
+
const seen = new Set();
|
|
247
|
+
const queue = scope.flows
|
|
248
|
+
.filter((f) => chain.has(f.sourceRef) && !chain.has(f.targetRef))
|
|
249
|
+
.map((f) => f.targetRef);
|
|
250
|
+
while (queue.length > 0) {
|
|
251
|
+
const id = queue.shift() ?? "";
|
|
252
|
+
if (seen.has(id) || upstream.has(id) || chain.has(id))
|
|
253
|
+
continue;
|
|
254
|
+
seen.add(id);
|
|
255
|
+
if (byId.get(id)?.type === "boundaryEvent")
|
|
256
|
+
continue;
|
|
257
|
+
if (shapeOf.has(id))
|
|
258
|
+
out.push(id);
|
|
259
|
+
for (const f of scope.flows)
|
|
260
|
+
if (f.sourceRef === id)
|
|
261
|
+
queue.push(f.targetRef);
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
151
265
|
//# sourceMappingURL=make-room.js.map
|
|
@@ -1153,8 +1153,10 @@ class Placer {
|
|
|
1153
1153
|
return false;
|
|
1154
1154
|
if (!own)
|
|
1155
1155
|
return true;
|
|
1156
|
-
// Ancestors of the box (its pool, its parent lane) contain it.
|
|
1157
|
-
|
|
1156
|
+
// Ancestors of the box (its pool, its parent lane) contain it. A laned pool can
|
|
1157
|
+
// end half a pixel inside its lanes (the engine rounds lane widths up), so allow 1 px.
|
|
1158
|
+
const b = shape.bounds;
|
|
1159
|
+
return !contains({ x: b.x - 1, y: b.y - 1, width: b.width + 2, height: b.height + 2 }, own);
|
|
1158
1160
|
})
|
|
1159
1161
|
.map((shape) => shape.bounds);
|
|
1160
1162
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* a file written by another tool comes back reshuffled even when nothing
|
|
17
17
|
* changed. Keeping the original order is therefore worth more than keeping the
|
|
18
18
|
* indentation. The same goes for an attribute set to its schema default:
|
|
19
|
-
* `
|
|
19
|
+
* `isSequential="false"` disappears from a file that said it out loud.
|
|
20
20
|
*
|
|
21
21
|
* Neither is safe to assume in general, so neither is assumed. Each strategy is
|
|
22
22
|
* tried, the result is **parsed back and compared against a plain write**, and
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* a file written by another tool comes back reshuffled even when nothing
|
|
17
17
|
* changed. Keeping the original order is therefore worth more than keeping the
|
|
18
18
|
* indentation. The same goes for an attribute set to its schema default:
|
|
19
|
-
* `
|
|
19
|
+
* `isSequential="false"` disappears from a file that said it out loud.
|
|
20
20
|
*
|
|
21
21
|
* Neither is safe to assume in general, so neither is assumed. Each strategy is
|
|
22
22
|
* tried, the result is **parsed back and compared against a plain write**, and
|
|
@@ -29,7 +29,7 @@ export declare const FIXED_KINDS: Readonly<Record<string, BpmnElementType>>;
|
|
|
29
29
|
* after {@link PROCESS_TEXT_GUIDE}. A test parses its example and expects no
|
|
30
30
|
* problems.
|
|
31
31
|
*/
|
|
32
|
-
export declare const PROCESS_DELTA_GUIDE = "Change script \u2014 write only what changes, one line each:\na > new[kind Name] > b add nodes and flows; an existing node is written by its id only\na >(Label: condition) b add a flow; restating an existing flow with a new label changes it\nx[kind Name] an existing id declared again changes its kind or name\nx[user Name | form=f in.a=b] form and in./out. mappings (FEEL; write a = 1 with spaces) go after the bar\n- a > b remove the flow from a to b\n- x remove node x and its flows\n@2 x y feedback item 2 is answered by the changes to x and y\nRules:\n- Use the ids of the diagram you were given. Never repeat a line that changes nothing.\n- A new node written between two connected nodes (a > new > b) replaces the flow a > b.\n- Removing a node with one way in and one way out joins the two.\n- End with one @ line for each feedback item you answered.\n\nExample:\ncheck > second[user Second approval] > pay\nreview[user Review application]\n- notify\n@1 second\n@2 review";
|
|
32
|
+
export declare const PROCESS_DELTA_GUIDE = "Change script \u2014 write only what changes, one line each:\na > new[kind Name] > b add nodes and flows; an existing node is written by its id only\na >(Label: condition) b add a flow; restating an existing flow with a new label changes it\nx[kind Name] an existing id declared again changes its kind or name\nx[user Name | form=f in.a=b] form and in./out. mappings (FEEL; write a = 1 with spaces) go after the bar\n- a > b remove the flow from a to b\n- x remove node x and its flows\nlane sales: a, b move a and b into lane sales; lane ops[Operations]: c adds or renames a lane\npool bank[Bank] add or rename a partner pool; msg pay >(Payment) bank sends it a message\n- msg pay > bank remove that message\n@2 x y feedback item 2 is answered by the changes to x and y\nRules:\n- Use the ids of the diagram you were given. Never repeat a line that changes nothing.\n- A new node written between two connected nodes (a > new > b) replaces the flow a > b.\n- Removing a node with one way in and one way out joins the two.\n- End with one @ line for each feedback item you answered.\n\nExample:\ncheck > second[user Second approval] > pay\nreview[user Review application]\n- notify\n@1 second\n@2 review";
|
|
33
33
|
/** A node the script declares: a new one, or a change to an existing one. */
|
|
34
34
|
export interface DeltaNode {
|
|
35
35
|
/** The id as written. */
|
|
@@ -119,6 +119,37 @@ export interface ProcessDelta {
|
|
|
119
119
|
text: string;
|
|
120
120
|
line: number;
|
|
121
121
|
}[];
|
|
122
|
+
/**
|
|
123
|
+
* `lane` lines, in the order written; a lane written twice appears twice. An
|
|
124
|
+
* absent `name` keeps an existing lane's name, and a new lane is named from its
|
|
125
|
+
* id. `nodes` move into the lane and may be empty: the line then only renames
|
|
126
|
+
* or adds the lane.
|
|
127
|
+
*/
|
|
128
|
+
lanes: {
|
|
129
|
+
id: string;
|
|
130
|
+
name?: string;
|
|
131
|
+
nodes: string[];
|
|
132
|
+
line: number;
|
|
133
|
+
}[];
|
|
134
|
+
/** `pool` lines: a partner pool added, or an existing one renamed. */
|
|
135
|
+
pools: {
|
|
136
|
+
id: string;
|
|
137
|
+
name?: string;
|
|
138
|
+
line: number;
|
|
139
|
+
}[];
|
|
140
|
+
/** `msg` lines: message flows between a node and a pool, label as written. */
|
|
141
|
+
messageFlows: {
|
|
142
|
+
from: string;
|
|
143
|
+
to: string;
|
|
144
|
+
name?: string;
|
|
145
|
+
line: number;
|
|
146
|
+
}[];
|
|
147
|
+
/** `- msg a > b` lines. */
|
|
148
|
+
removedMessageFlows: {
|
|
149
|
+
from: string;
|
|
150
|
+
to: string;
|
|
151
|
+
line: number;
|
|
152
|
+
}[];
|
|
122
153
|
/** Lines, or parts of lines, that were left out. */
|
|
123
154
|
problems: ProcessTextProblem[];
|
|
124
155
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* @packageDocumentation
|
|
17
17
|
*/
|
|
18
18
|
import { CONNECTOR_LINE, parseConnectorLine } from "./connector-line.js";
|
|
19
|
-
import { DOC_LINE, NOTE_LINE, TRIGGERS, cycle, duration, edgeLabel, kindOf, splitFeel, splitMappings, tokenizePath, } from "./process-text.js";
|
|
19
|
+
import { DOC_LINE, LANE_LINE, MESSAGE_LINE, NOTE_LINE, POOL_LINE, TRIGGERS, cycle, duration, edgeLabel, kindOf, splitFeel, splitMappings, tokenizePath, } from "./process-text.js";
|
|
20
20
|
/**
|
|
21
21
|
* Kind words the writer uses for element types the line format cannot create.
|
|
22
22
|
* A script may restate them on an existing node; it cannot declare a new one.
|
|
@@ -38,6 +38,9 @@ x[kind Name] an existing id declared again changes its kind or name
|
|
|
38
38
|
x[user Name | form=f in.a=b] form and in./out. mappings (FEEL; write a = 1 with spaces) go after the bar
|
|
39
39
|
- a > b remove the flow from a to b
|
|
40
40
|
- x remove node x and its flows
|
|
41
|
+
lane sales: a, b move a and b into lane sales; lane ops[Operations]: c adds or renames a lane
|
|
42
|
+
pool bank[Bank] add or rename a partner pool; msg pay >(Payment) bank sends it a message
|
|
43
|
+
- msg pay > bank remove that message
|
|
41
44
|
@2 x y feedback item 2 is answered by the changes to x and y
|
|
42
45
|
Rules:
|
|
43
46
|
- Use the ids of the diagram you were given. Never repeat a line that changes nothing.
|
|
@@ -58,6 +61,46 @@ review[user Review application]
|
|
|
58
61
|
const ID_LIST = /^[A-Za-z_][\w.-]*(\s*,\s*[A-Za-z_][\w.-]*)*$/;
|
|
59
62
|
/** A line that ends in an arrow: the path goes on below, as in the line format. */
|
|
60
63
|
const DANGLING = /\s*-{0,2}>\s*(\([^()]*\))?\s*$/;
|
|
64
|
+
const ID = /^[A-Za-z_][\w.-]*$/;
|
|
65
|
+
/**
|
|
66
|
+
* Reads a `lane`, `pool` or `msg` line into `delta`. Returns whether the line was
|
|
67
|
+
* one, so the caller does not read it as a path.
|
|
68
|
+
*/
|
|
69
|
+
function readSwimlaneLine(line, n, delta) {
|
|
70
|
+
const lane = LANE_LINE.exec(line);
|
|
71
|
+
if (lane) {
|
|
72
|
+
const id = lane[1];
|
|
73
|
+
const name = lane[2]?.trim();
|
|
74
|
+
const nodes = [];
|
|
75
|
+
for (const word of (lane[3] ?? "").split(/[\s,]+/).filter(Boolean)) {
|
|
76
|
+
if (ID.test(word))
|
|
77
|
+
nodes.push(word);
|
|
78
|
+
else
|
|
79
|
+
delta.problems.push({ line: n, message: `lane ${id}: "${word}" is not an id; left out` });
|
|
80
|
+
}
|
|
81
|
+
// A bare, empty lane line changes nothing; it is more likely prose than a lane.
|
|
82
|
+
if (!name && nodes.length === 0) {
|
|
83
|
+
delta.problems.push({ line: n, message: `lane ${id}: names nothing to change; ignored` });
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
delta.lanes.push({ id, ...(name ? { name } : {}), nodes, line: n });
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
const pool = POOL_LINE.exec(line);
|
|
90
|
+
if (pool) {
|
|
91
|
+
const name = pool[2]?.trim();
|
|
92
|
+
delta.pools.push({ id: pool[1], ...(name ? { name } : {}), line: n });
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
const message = MESSAGE_LINE.exec(line);
|
|
96
|
+
if (message) {
|
|
97
|
+
const name = message[2]?.trim();
|
|
98
|
+
const flow = { from: message[1], to: message[3] };
|
|
99
|
+
delta.messageFlows.push({ ...flow, ...(name ? { name } : {}), line: n });
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
61
104
|
/** Reads one declaration's bracket text. */
|
|
62
105
|
function readSpec(id, spec, line, problems) {
|
|
63
106
|
const node = { id, line };
|
|
@@ -152,6 +195,10 @@ export function parseProcessDelta(text) {
|
|
|
152
195
|
connectors: [],
|
|
153
196
|
notes: [],
|
|
154
197
|
docs: [],
|
|
198
|
+
lanes: [],
|
|
199
|
+
pools: [],
|
|
200
|
+
messageFlows: [],
|
|
201
|
+
removedMessageFlows: [],
|
|
155
202
|
problems: [],
|
|
156
203
|
};
|
|
157
204
|
const declared = new Map();
|
|
@@ -215,6 +262,18 @@ export function parseProcessDelta(text) {
|
|
|
215
262
|
});
|
|
216
263
|
};
|
|
217
264
|
const removal = (rest, n) => {
|
|
265
|
+
const message = MESSAGE_LINE.exec(rest);
|
|
266
|
+
if (message) {
|
|
267
|
+
delta.removedMessageFlows.push({
|
|
268
|
+
from: message[1],
|
|
269
|
+
to: message[3],
|
|
270
|
+
line: n,
|
|
271
|
+
});
|
|
272
|
+
if (message[2] !== undefined) {
|
|
273
|
+
delta.problems.push({ line: n, message: "a removal names ids only; ignored the label" });
|
|
274
|
+
}
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
218
277
|
if (ID_LIST.test(rest) && !rest.includes(">")) {
|
|
219
278
|
for (const id of rest.split(/[\s,]+/).filter(Boolean)) {
|
|
220
279
|
delta.removedNodes.push({ id, line: n });
|
|
@@ -291,6 +350,8 @@ export function parseProcessDelta(text) {
|
|
|
291
350
|
delta.docs.push({ id: doc[1], text, line: n });
|
|
292
351
|
return;
|
|
293
352
|
}
|
|
353
|
+
if (readSwimlaneLine(line, n, delta))
|
|
354
|
+
return;
|
|
294
355
|
// `- x` removes; `-> x` is an arrow a model wrote at the start of a line.
|
|
295
356
|
const removed = /^-(?![->])\s*(.*)$/.exec(line);
|
|
296
357
|
if (removed) {
|
|
@@ -4,13 +4,20 @@
|
|
|
4
4
|
* ({@link PROCESS_DELTA_GUIDE}) that names its nodes by id.
|
|
5
5
|
*
|
|
6
6
|
* Written ids are short aliases: a Modeler id such as `Activity_0x9k2lm` costs
|
|
7
|
-
* several tokens and tells the model nothing, so each node
|
|
8
|
-
* name-derived alias (`review_application`) and the map back to
|
|
9
|
-
* returned beside the text. An id that is already short and
|
|
7
|
+
* several tokens and tells the model nothing, so each node, lane and pool is
|
|
8
|
+
* written under a name-derived alias (`review_application`) and the map back to
|
|
9
|
+
* the real id is returned beside the text. An id that is already short and
|
|
10
|
+
* readable is kept.
|
|
10
11
|
*
|
|
11
|
-
* Only what the format can express is written
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Only what the format can express is written, for one process: the
|
|
13
|
+
* {@link primaryProcess} (the executable one, which need not come first in a
|
|
14
|
+
* Modeler collaboration). That is its flow nodes, sequence flows, the tasks of
|
|
15
|
+
* an ad-hoc sub-process, documentation, notes and connectors; its leaf lanes;
|
|
16
|
+
* every other pool of the first collaboration, as a black box; and the message
|
|
17
|
+
* flows between one of its top-level nodes and such a pool. Data objects, event
|
|
18
|
+
* sub-processes, the inside of any other sub-process, parent lanes of nested
|
|
19
|
+
* lanes, the content of other pools, and messages that touch the process's own
|
|
20
|
+
* pool or a node of another pool are left out. A script cannot name what it was
|
|
14
21
|
* never shown, so those parts cannot be changed by it either.
|
|
15
22
|
*
|
|
16
23
|
* @packageDocumentation
|
|
@@ -43,8 +50,12 @@ export declare function writableName(name: string): string;
|
|
|
43
50
|
export declare function writableLabel(name: string): string;
|
|
44
51
|
/** A FEEL condition without its leading `=`, on one line. */
|
|
45
52
|
export declare function writableCondition(condition: string): string;
|
|
53
|
+
/** A message label as a `msg` line writes it: raw like a note, so colons stay, but a parenthesis would end it. */
|
|
54
|
+
export declare function writableMessageLabel(name: string): string;
|
|
46
55
|
/**
|
|
47
|
-
* Writes the
|
|
56
|
+
* Writes the {@link primaryProcess} of `definitions` in the line format, with
|
|
57
|
+
* its leaf lanes, the other pools and their messages (see the module comment
|
|
58
|
+
* for what is left out).
|
|
48
59
|
*
|
|
49
60
|
* Paths start at the start events and follow the flows; each flow is written
|
|
50
61
|
* once and each node is declared where it first appears. A boundary event
|