@aranzatech/diagrams-bpmn 0.3.3 → 0.3.4
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/dist/layout/index.cjs +29 -2
- package/dist/layout/index.cjs.map +1 -1
- package/dist/layout/index.js +29 -2
- package/dist/layout/index.js.map +1 -1
- package/package.json +1 -1
package/dist/layout/index.cjs
CHANGED
|
@@ -1691,6 +1691,33 @@ function nodeRect(node, byId, cache) {
|
|
|
1691
1691
|
function rectContainsRect(outer, inner) {
|
|
1692
1692
|
return inner.x >= outer.x && inner.y >= outer.y && inner.x + inner.width <= outer.x + outer.width && inner.y + inner.height <= outer.y + outer.height;
|
|
1693
1693
|
}
|
|
1694
|
+
function sortNodesParentFirst(nodes) {
|
|
1695
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
1696
|
+
const memo = /* @__PURE__ */ new Map();
|
|
1697
|
+
const depthOf = (node) => {
|
|
1698
|
+
const cached = memo.get(node.id);
|
|
1699
|
+
if (cached != null) return cached;
|
|
1700
|
+
if (!node.parentId) {
|
|
1701
|
+
memo.set(node.id, 0);
|
|
1702
|
+
return 0;
|
|
1703
|
+
}
|
|
1704
|
+
const parent = byId.get(node.parentId);
|
|
1705
|
+
const depth = parent ? depthOf(parent) + 1 : 0;
|
|
1706
|
+
memo.set(node.id, depth);
|
|
1707
|
+
return depth;
|
|
1708
|
+
};
|
|
1709
|
+
return [...nodes].sort((a, b) => {
|
|
1710
|
+
const depthDiff = depthOf(a) - depthOf(b);
|
|
1711
|
+
if (depthDiff !== 0) return depthDiff;
|
|
1712
|
+
const ay = a.position?.y ?? 0;
|
|
1713
|
+
const by = b.position?.y ?? 0;
|
|
1714
|
+
if (ay !== by) return ay - by;
|
|
1715
|
+
const ax = a.position?.x ?? 0;
|
|
1716
|
+
const bx = b.position?.x ?? 0;
|
|
1717
|
+
if (ax !== bx) return ax - bx;
|
|
1718
|
+
return a.id.localeCompare(b.id);
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1694
1721
|
function gapMidX(sAbs, sW, tAbs, tW) {
|
|
1695
1722
|
const leftRightEdge = Math.min(sAbs.x + sW, tAbs.x + tW);
|
|
1696
1723
|
const rightLeftEdge = Math.max(sAbs.x, tAbs.x);
|
|
@@ -1964,7 +1991,7 @@ async function bpmnCustomLayout(nodes, edges) {
|
|
|
1964
1991
|
const { bpmnElkLayout: bpmnElkLayout2 } = await Promise.resolve().then(() => (init_elk(), elk_exports));
|
|
1965
1992
|
const elkResult = await bpmnElkLayout2(nodes.filter((n) => !LAYOUT_ARTIFACT_TYPES.has(n.data.elementType)), edges);
|
|
1966
1993
|
const posArtifacts = positionArtifacts(artifacts, elkResult.nodes, edges, nodes);
|
|
1967
|
-
return { nodes: [...elkResult.nodes, ...posArtifacts], edges: elkResult.edges };
|
|
1994
|
+
return { nodes: sortNodesParentFirst([...elkResult.nodes, ...posArtifacts]), edges: elkResult.edges };
|
|
1968
1995
|
}
|
|
1969
1996
|
const poolIds = new Set(pools.map((p) => p.id));
|
|
1970
1997
|
const allLaneIds = new Set(lanes.map((l) => l.id));
|
|
@@ -2035,7 +2062,7 @@ async function bpmnCustomLayout(nodes, edges) {
|
|
|
2035
2062
|
const routedEdges = routeEdges(edges, resultNodes, allBackEdgeIds, allLaneIds, poolIds);
|
|
2036
2063
|
const positionedArtifacts = positionArtifacts(artifacts, resultNodes, edges, nodes);
|
|
2037
2064
|
return {
|
|
2038
|
-
nodes: [...resultNodes, ...positionedArtifacts],
|
|
2065
|
+
nodes: sortNodesParentFirst([...resultNodes, ...positionedArtifacts]),
|
|
2039
2066
|
edges: routedEdges
|
|
2040
2067
|
};
|
|
2041
2068
|
}
|