@pega/cosmos-react-build 2.0.0-rc.2 → 2.0.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/lib/components/FlowModeller/{Renderer/AddNode.d.ts → AddNode.d.ts} +6 -0
- package/lib/components/FlowModeller/AddNode.d.ts.map +1 -0
- package/lib/components/FlowModeller/AddNode.js +62 -0
- package/lib/components/FlowModeller/AddNode.js.map +1 -0
- package/lib/components/FlowModeller/FlowModeller.d.ts +2 -2
- package/lib/components/FlowModeller/FlowModeller.d.ts.map +1 -1
- package/lib/components/FlowModeller/FlowModeller.js +96 -107
- package/lib/components/FlowModeller/FlowModeller.js.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.d.ts +4 -8
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.d.ts.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.js +10 -10
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.js.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplates.d.ts.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplates.js +12 -3
- package/lib/components/FlowModeller/Node/NodeTemplates.js.map +1 -1
- package/lib/components/FlowModeller/NodeLibrary.d.ts +2 -1
- package/lib/components/FlowModeller/NodeLibrary.d.ts.map +1 -1
- package/lib/components/FlowModeller/NodeLibrary.js +10 -8
- package/lib/components/FlowModeller/NodeLibrary.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Connectors.d.ts +13 -0
- package/lib/components/FlowModeller/Renderer/Connectors.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/{Connector.js → Connectors.js} +13 -16
- package/lib/components/FlowModeller/Renderer/Connectors.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Nodes.d.ts +9 -0
- package/lib/components/FlowModeller/Renderer/Nodes.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/Nodes.js +25 -0
- package/lib/components/FlowModeller/Renderer/Nodes.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Renderer.js +4 -4
- package/lib/components/FlowModeller/Renderer/Renderer.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Renderer.types.d.ts +4 -4
- package/lib/components/FlowModeller/Renderer/Renderer.types.d.ts.map +1 -1
- package/lib/components/FlowModeller/Renderer/Renderer.types.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/Graph.d.ts +6 -3
- package/lib/components/FlowModeller/Renderer/Utils/Graph.d.ts.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/Graph.js +55 -0
- package/lib/components/FlowModeller/Renderer/Utils/Graph.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.d.ts.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.js +18 -15
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/GraphTraversal.d.ts +24 -0
- package/lib/components/FlowModeller/Renderer/Utils/GraphTraversal.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/Utils/GraphTraversal.js +152 -0
- package/lib/components/FlowModeller/Renderer/Utils/GraphTraversal.js.map +1 -0
- package/lib/components/FlowModeller/Utils/AddNodeUtils.d.ts +16 -0
- package/lib/components/FlowModeller/Utils/AddNodeUtils.d.ts.map +1 -0
- package/lib/components/FlowModeller/Utils/AddNodeUtils.js +118 -0
- package/lib/components/FlowModeller/Utils/AddNodeUtils.js.map +1 -0
- package/lib/components/FlowModeller/helper.d.ts +1 -0
- package/lib/components/FlowModeller/helper.d.ts.map +1 -1
- package/lib/components/FlowModeller/helper.js +38 -7
- package/lib/components/FlowModeller/helper.js.map +1 -1
- package/lib/components/FlowModeller/index.d.ts +8 -1
- package/lib/components/FlowModeller/index.d.ts.map +1 -1
- package/lib/components/FlowModeller/index.js +6 -0
- package/lib/components/FlowModeller/index.js.map +1 -1
- package/lib/components/LifeCycle/Stage.d.ts.map +1 -1
- package/lib/components/LifeCycle/Stage.js +0 -4
- package/lib/components/LifeCycle/Stage.js.map +1 -1
- package/lib/components/LifeCycle/index.d.ts +1 -1
- package/lib/components/LifeCycle/index.d.ts.map +1 -1
- package/lib/components/LifeCycle/index.js.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.d.ts.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.js +21 -1
- package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
- package/lib/components/Workbench/ConfigurationPanel.d.ts +5 -0
- package/lib/components/Workbench/ConfigurationPanel.d.ts.map +1 -0
- package/lib/components/Workbench/ConfigurationPanel.js +21 -0
- package/lib/components/Workbench/ConfigurationPanel.js.map +1 -0
- package/lib/components/Workbench/Toolbar.d.ts +14 -0
- package/lib/components/Workbench/Toolbar.d.ts.map +1 -0
- package/lib/components/Workbench/Toolbar.js +14 -0
- package/lib/components/Workbench/Toolbar.js.map +1 -0
- package/lib/components/Workbench/UtilityPanel.d.ts +7 -0
- package/lib/components/Workbench/UtilityPanel.d.ts.map +1 -0
- package/lib/components/Workbench/UtilityPanel.js +12 -0
- package/lib/components/Workbench/UtilityPanel.js.map +1 -0
- package/lib/components/Workbench/Workbench.d.ts +6 -0
- package/lib/components/Workbench/Workbench.d.ts.map +1 -0
- package/lib/components/Workbench/Workbench.js +24 -0
- package/lib/components/Workbench/Workbench.js.map +1 -0
- package/lib/components/Workbench/Workbench.styles.d.ts +10 -0
- package/lib/components/Workbench/Workbench.styles.d.ts.map +1 -0
- package/lib/components/Workbench/Workbench.styles.js +72 -0
- package/lib/components/Workbench/Workbench.styles.js.map +1 -0
- package/lib/components/Workbench/Workbench.types.d.ts +49 -0
- package/lib/components/Workbench/Workbench.types.d.ts.map +1 -0
- package/lib/components/Workbench/Workbench.types.js +2 -0
- package/lib/components/Workbench/Workbench.types.js.map +1 -0
- package/lib/components/Workbench/index.d.ts +2 -0
- package/lib/components/Workbench/index.d.ts.map +1 -0
- package/lib/components/Workbench/index.js +2 -0
- package/lib/components/Workbench/index.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/lib/components/FlowModeller/Renderer/AddNode.d.ts.map +0 -1
- package/lib/components/FlowModeller/Renderer/AddNode.js +0 -42
- package/lib/components/FlowModeller/Renderer/AddNode.js.map +0 -1
- package/lib/components/FlowModeller/Renderer/Connector.d.ts +0 -5
- package/lib/components/FlowModeller/Renderer/Connector.d.ts.map +0 -1
- package/lib/components/FlowModeller/Renderer/Connector.js.map +0 -1
- package/lib/components/FlowModeller/Renderer/ConnectorsContainer.d.ts +0 -12
- package/lib/components/FlowModeller/Renderer/ConnectorsContainer.d.ts.map +0 -1
- package/lib/components/FlowModeller/Renderer/ConnectorsContainer.js +0 -15
- package/lib/components/FlowModeller/Renderer/ConnectorsContainer.js.map +0 -1
- package/lib/components/FlowModeller/Renderer/Node.d.ts +0 -5
- package/lib/components/FlowModeller/Renderer/Node.d.ts.map +0 -1
- package/lib/components/FlowModeller/Renderer/Node.js +0 -18
- package/lib/components/FlowModeller/Renderer/Node.js.map +0 -1
- package/lib/components/FlowModeller/Renderer/NodesContainer.d.ts +0 -8
- package/lib/components/FlowModeller/Renderer/NodesContainer.d.ts.map +0 -1
- package/lib/components/FlowModeller/Renderer/NodesContainer.js +0 -15
- package/lib/components/FlowModeller/Renderer/NodesContainer.js.map +0 -1
|
@@ -9,37 +9,39 @@ const DEFAULT_GRAPH_HEIGHT = 2000;
|
|
|
9
9
|
export default class GraphLayout {
|
|
10
10
|
// Using Dagre layouting
|
|
11
11
|
static plot(graphData, direction = GraphLayoutDirection.TopToBottom) {
|
|
12
|
-
const dagreGraph = new dagre.graphlib.Graph();
|
|
12
|
+
const dagreGraph = new dagre.graphlib.Graph({ multigraph: true });
|
|
13
13
|
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
|
14
14
|
const defaultNodeWidth = 280;
|
|
15
15
|
const defaultNodeHeight = 112;
|
|
16
16
|
dagreGraph.setGraph({
|
|
17
17
|
rankdir: direction,
|
|
18
|
-
ranksep:
|
|
18
|
+
ranksep: 20,
|
|
19
19
|
edgesep: defaultNodeWidth / 2,
|
|
20
|
-
nodesep:
|
|
20
|
+
nodesep: 20,
|
|
21
21
|
// cspell:disable-next
|
|
22
22
|
marginx: 200,
|
|
23
23
|
// cspell:disable-next
|
|
24
24
|
marginy: 50
|
|
25
25
|
});
|
|
26
26
|
graphData.nodes.forEach(node => {
|
|
27
|
+
const height = node.dimensions.height === 0 ? 0 : node.dimensions.height || defaultNodeHeight;
|
|
28
|
+
const width = node.dimensions.width === 0 ? 0 : node.dimensions.width || defaultNodeWidth;
|
|
27
29
|
dagreGraph.setNode(node.id, {
|
|
28
|
-
width
|
|
29
|
-
height
|
|
30
|
+
width,
|
|
31
|
+
height
|
|
30
32
|
});
|
|
31
33
|
});
|
|
32
|
-
graphData.connectors.forEach(con => {
|
|
34
|
+
graphData.connectors.forEach((con, index) => {
|
|
33
35
|
dagreGraph.setEdge(con.fromNodeId, con.toNodeId, {
|
|
34
36
|
weight: 1,
|
|
35
|
-
minlen:
|
|
36
|
-
label: con.data?.label,
|
|
37
|
-
width:
|
|
38
|
-
height:
|
|
37
|
+
minlen: 2,
|
|
38
|
+
label: con.data?.label || '',
|
|
39
|
+
width: 250,
|
|
40
|
+
height: con.data?.label ? 90 : 40,
|
|
39
41
|
// cspell:disable-next
|
|
40
42
|
lablepos: 'c',
|
|
41
43
|
labeloffset: 0
|
|
42
|
-
});
|
|
44
|
+
}, index.toString());
|
|
43
45
|
});
|
|
44
46
|
dagre.layout(dagreGraph, {});
|
|
45
47
|
graphData.nodes.forEach(el => {
|
|
@@ -47,8 +49,8 @@ export default class GraphLayout {
|
|
|
47
49
|
el.position.x = node.x - el.dimensions.width / 2;
|
|
48
50
|
el.position.y = node.y - el.dimensions.height / 2;
|
|
49
51
|
});
|
|
50
|
-
graphData.connectors.forEach(con => {
|
|
51
|
-
const edge = dagreGraph.edge(con.fromNodeId, con.toNodeId);
|
|
52
|
+
graphData.connectors.forEach((con, index) => {
|
|
53
|
+
const edge = dagreGraph.edge(con.fromNodeId, con.toNodeId, index.toString());
|
|
52
54
|
con.labelLayout = {
|
|
53
55
|
value: edge.label,
|
|
54
56
|
x: edge.x,
|
|
@@ -81,8 +83,9 @@ export default class GraphLayout {
|
|
|
81
83
|
: lastPoint;
|
|
82
84
|
con.points = [
|
|
83
85
|
{ x: fromNode.x, y: fromNode.y + fromNode.height / 2 },
|
|
84
|
-
firstPoint,
|
|
85
|
-
...
|
|
86
|
+
{ ...firstPoint, y: firstPoint.y + 10 },
|
|
87
|
+
{ ...secondPoint, y: secondPoint.y + 10 },
|
|
88
|
+
...edge.points.slice(2, lastIndex),
|
|
86
89
|
lastPoint,
|
|
87
90
|
{ x: toNode.x, y: toNode.y }
|
|
88
91
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphLayout.js","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/GraphLayout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA0B1B,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,0CAAkB,CAAA;IAClB,0CAAkB,CAAA;AACpB,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B;AAED,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACjC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,wBAAwB;IACxB,MAAM,CAAC,IAAI,CACT,SAAY,EACZ,YAAkC,oBAAoB,CAAC,WAAW;QAElE,MAAM,UAAU,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"GraphLayout.js","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/GraphLayout.ts"],"names":[],"m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J,CAAC;CACF","sourcesContent":["import dagre from 'dagre';\n\nimport { ConnectorProps, GraphData, Node } from './Graph';\n\nexport interface PlottedGraphNode<T = any> extends Node<T> {\n dimensions: {\n width: number;\n height: number;\n };\n position: {\n x: number;\n y: number;\n };\n}\n\nexport interface PlottedGraphConnector<T = any> extends ConnectorProps<T> {\n points: { x: number; y: number }[];\n labelLayout?: {\n value: any;\n width: number;\n height: number;\n x: number;\n y: number;\n };\n}\n\nexport enum GraphLayoutDirection {\n LeftToRight = 'LR',\n TopToBottom = 'TB'\n}\n\nconst DEFAULT_GRAPH_WIDTH = 2000;\nconst DEFAULT_GRAPH_HEIGHT = 2000;\n\nexport default class GraphLayout {\n // Using Dagre layouting\n static plot<T extends GraphData<PlottedGraphNode, PlottedGraphConnector>>(\n graphData: T,\n direction: GraphLayoutDirection = GraphLayoutDirection.TopToBottom\n ) {\n const dagreGraph = new dagre.graphlib.Graph({ multigraph: true });\n\n dagreGraph.setDefaultEdgeLabel(() => ({}));\n\n const defaultNodeWidth = 280;\n const defaultNodeHeight = 112;\n\n dagreGraph.setGraph({\n rankdir: direction,\n ranksep: 20,\n edgesep: defaultNodeWidth / 2,\n nodesep: 20,\n // cspell:disable-next\n marginx: 200,\n // cspell:disable-next\n marginy: 50\n });\n\n graphData.nodes.forEach(node => {\n const height = node.dimensions.height === 0 ? 0 : node.dimensions.height || defaultNodeHeight;\n const width = node.dimensions.width === 0 ? 0 : node.dimensions.width || defaultNodeWidth;\n dagreGraph.setNode(node.id, {\n width,\n height\n });\n });\n\n graphData.connectors.forEach((con, index) => {\n dagreGraph.setEdge(\n con.fromNodeId,\n con.toNodeId,\n {\n weight: 1,\n minlen: 2,\n label: con.data?.label || '',\n width: 250,\n height: con.data?.label ? 90 : 40,\n // cspell:disable-next\n lablepos: 'c',\n labeloffset: 0\n },\n index.toString()\n );\n });\n\n dagre.layout(dagreGraph, {});\n\n graphData.nodes.forEach(el => {\n const node = dagreGraph.node(el.id);\n el.position.x = node.x - el.dimensions.width / 2;\n el.position.y = node.y - el.dimensions.height / 2;\n });\n\n graphData.connectors.forEach((con, index) => {\n const edge = dagreGraph.edge(con.fromNodeId, con.toNodeId, index.toString());\n\n con.labelLayout = {\n value: edge.label,\n x: edge.x,\n y: edge.y - 10,\n width: edge.width,\n height: edge.height\n };\n\n const lastIndex = edge.points.length - 1;\n let firstPoint = edge.points[0];\n const secondPoint = edge.points[1];\n let lastPoint = edge.points[lastIndex];\n const secondLastPoint = edge.points[lastIndex - 1];\n\n const fromNode = dagreGraph.node(con.fromNodeId);\n const toNode = dagreGraph.node(con.toNodeId);\n\n firstPoint =\n firstPoint.x !== secondPoint.x\n ? {\n ...edge.points[0],\n x: fromNode.x,\n y: edge.points[1].y\n }\n : firstPoint;\n\n lastPoint =\n lastPoint.x !== secondLastPoint.x\n ? {\n ...edge.points[lastIndex],\n x: toNode.x,\n y: edge.points[lastIndex - 1].y\n }\n : lastPoint;\n\n con.points = [\n { x: fromNode.x, y: fromNode.y + fromNode.height / 2 },\n { ...firstPoint, y: firstPoint.y + 10 },\n { ...secondPoint, y: secondPoint.y + 10 },\n ...edge.points.slice(2, lastIndex),\n lastPoint,\n { x: toNode.x, y: toNode.y }\n ];\n });\n\n const width = dagreGraph.graph().width;\n const height = dagreGraph.graph().height;\n\n if (width !== undefined && height !== undefined) {\n return {\n width: Number.isFinite(width) ? width : DEFAULT_GRAPH_WIDTH,\n height: Number.isFinite(height) ? height : DEFAULT_GRAPH_HEIGHT\n };\n }\n\n return {\n width: DEFAULT_GRAPH_WIDTH,\n height: DEFAULT_GRAPH_HEIGHT\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DirectedGraph, GraphData } from './Graph';
|
|
2
|
+
interface NestedArray<T> extends Array<T | NestedArray<T>> {
|
|
3
|
+
}
|
|
4
|
+
interface ConvergenceData {
|
|
5
|
+
nodeId: string;
|
|
6
|
+
connectors: NestedArray<string>;
|
|
7
|
+
paths?: NestedArray<ConvergenceData>;
|
|
8
|
+
}
|
|
9
|
+
export default class GraphTraversal {
|
|
10
|
+
static bfs(gd: GraphData, src?: string): string[];
|
|
11
|
+
static dfs(gd: GraphData, src?: string): string[];
|
|
12
|
+
static findRootNode(graph: DirectedGraph): string | false;
|
|
13
|
+
/**
|
|
14
|
+
* Given the graphData and the source node with morethan one branch, It calculates the convergence node, involved connectors and paths
|
|
15
|
+
* Assuming, goTo is not supported
|
|
16
|
+
*
|
|
17
|
+
* @param gd graphData to process on
|
|
18
|
+
* @param src id of the source node. This needs to be a node with multiple branches
|
|
19
|
+
* @returns id of the destination node or null if not found
|
|
20
|
+
*/
|
|
21
|
+
static getConvergenceData(gd: GraphData, src: string): ConvergenceData | false;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=GraphTraversal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphTraversal.d.ts","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/GraphTraversal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAQ,MAAM,SAAS,CAAC;AAEzD,UAAU,WAAW,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;CAAG;AAE7D,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;CACtC;AAED,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAqCjD,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAyCjD,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,GAAG,KAAK;IAYzD;;;;;;;OAOG;IAEH,MAAM,CAAC,kBAAkB,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,KAAK;CAsF/E"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { DirectedGraph } from './Graph';
|
|
2
|
+
export default class GraphTraversal {
|
|
3
|
+
static bfs(gd, src) {
|
|
4
|
+
const graph = new DirectedGraph(gd);
|
|
5
|
+
if (!src) {
|
|
6
|
+
const rootNodeId = GraphTraversal.findRootNode(graph);
|
|
7
|
+
if (!rootNodeId) {
|
|
8
|
+
throw Error('Invalid graph, cannot find root node.');
|
|
9
|
+
}
|
|
10
|
+
src = rootNodeId;
|
|
11
|
+
}
|
|
12
|
+
const queue = [src];
|
|
13
|
+
const result = [];
|
|
14
|
+
const map = {
|
|
15
|
+
src
|
|
16
|
+
}; // needed for duplicate comparision
|
|
17
|
+
while (queue.length > 0) {
|
|
18
|
+
const source = queue.shift();
|
|
19
|
+
if (source !== undefined) {
|
|
20
|
+
result.push(source);
|
|
21
|
+
const nextNodes = graph.getNextNodes(source);
|
|
22
|
+
nextNodes.forEach((node) => {
|
|
23
|
+
if (!map[node.id]) {
|
|
24
|
+
queue.push(node.id);
|
|
25
|
+
map[node.id] = node.id;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
static dfs(gd, src) {
|
|
33
|
+
const graph = new DirectedGraph(gd);
|
|
34
|
+
// finding the start node automatically
|
|
35
|
+
if (!src) {
|
|
36
|
+
const rootNodeId = GraphTraversal.findRootNode(graph);
|
|
37
|
+
if (!rootNodeId) {
|
|
38
|
+
throw Error('Invalid graph, cannot find root node.');
|
|
39
|
+
}
|
|
40
|
+
src = rootNodeId;
|
|
41
|
+
}
|
|
42
|
+
const stack = [src];
|
|
43
|
+
const result = [];
|
|
44
|
+
const map = {
|
|
45
|
+
src
|
|
46
|
+
}; // needed for duplicate comparision
|
|
47
|
+
while (stack.length > 0) {
|
|
48
|
+
const source = stack.pop();
|
|
49
|
+
if (source !== undefined) {
|
|
50
|
+
result.push(source);
|
|
51
|
+
const nextNodes = graph.getNextNodes(source);
|
|
52
|
+
nextNodes.forEach(node => {
|
|
53
|
+
if (map[node.id] === undefined) {
|
|
54
|
+
stack.push(node.id);
|
|
55
|
+
map[node.id] = node.id;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
// Assuming the given graph has no unconnected nodes and the graph is not cyclic(if start node have in-connectors(ie., cyclic), this will fail).
|
|
63
|
+
// - returns first encountered node with no in-connectors as a rootnode, if more than one exists
|
|
64
|
+
static findRootNode(graph) {
|
|
65
|
+
const nodes = graph.getNodes();
|
|
66
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
67
|
+
if (graph.getPrevNodesCount(nodes[i].id) === 0) {
|
|
68
|
+
return nodes[i].id;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Given the graphData and the source node with morethan one branch, It calculates the convergence node, involved connectors and paths
|
|
75
|
+
* Assuming, goTo is not supported
|
|
76
|
+
*
|
|
77
|
+
* @param gd graphData to process on
|
|
78
|
+
* @param src id of the source node. This needs to be a node with multiple branches
|
|
79
|
+
* @returns id of the destination node or null if not found
|
|
80
|
+
*/
|
|
81
|
+
// TODO-OPTIMIZE Memoize, for a given GraphData
|
|
82
|
+
static getConvergenceData(gd, src) {
|
|
83
|
+
const graph = new DirectedGraph(gd);
|
|
84
|
+
// return false, if there is no node with given source node id
|
|
85
|
+
if (graph.getNode(src) !== undefined && graph.getNextNodesCount(src) < 2) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
// traverse the nodes -- and record the paths of each connector
|
|
89
|
+
const path = []; // array of path-arrays
|
|
90
|
+
const initialConnectors = graph.getOutConnectors(src);
|
|
91
|
+
// iterate the initial set of connectors
|
|
92
|
+
initialConnectors.forEach((item, index) => {
|
|
93
|
+
path[index] = [];
|
|
94
|
+
let currentConnector = item;
|
|
95
|
+
// traverse through each connector and push the encountered nodes
|
|
96
|
+
while (currentConnector && currentConnector.toNodeId !== undefined) {
|
|
97
|
+
path[index].push({
|
|
98
|
+
nodeId: currentConnector.toNodeId,
|
|
99
|
+
connectors: [currentConnector.id]
|
|
100
|
+
});
|
|
101
|
+
const inConnectors = graph.getInConnectors(currentConnector.toNodeId);
|
|
102
|
+
// if this node has multiple in connectors, that means this is a join [IMP TODO NOTE until we support goTo option]
|
|
103
|
+
if (inConnectors.length > 1) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let outConnectors = graph.getOutConnectors(currentConnector.toNodeId);
|
|
107
|
+
let newCurrentNodeId = currentConnector.toNodeId;
|
|
108
|
+
// check if this node has multiple branches and call recursively
|
|
109
|
+
while (outConnectors.length > 1) {
|
|
110
|
+
const result = GraphTraversal.getConvergenceData(gd, newCurrentNodeId);
|
|
111
|
+
// handle resultNodeId val as false use case: just cancel futher processing and return false
|
|
112
|
+
if (result === false) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
// add result node to the path
|
|
116
|
+
path[index].push(result);
|
|
117
|
+
// handle, resultNode as destination shape of alternate connector too
|
|
118
|
+
const tempInConnectors = graph.getInConnectors(result.nodeId);
|
|
119
|
+
// if this node has multiple in connectors and more than expected count, that means this is a join [IMP TODO NOTE until we support goTo option]
|
|
120
|
+
if (tempInConnectors.length > outConnectors.length) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// handle, resultNode as decision shape
|
|
124
|
+
outConnectors = graph.getOutConnectors(result.nodeId);
|
|
125
|
+
newCurrentNodeId = result.nodeId;
|
|
126
|
+
}
|
|
127
|
+
// else if out connectors is 1
|
|
128
|
+
currentConnector = outConnectors[0];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
// validate and return false if no convergence node found
|
|
132
|
+
for (let i = 1; i < path.length; i += 1) {
|
|
133
|
+
if (path[i][path[i].length - 1].nodeId !== path[i - 1][path[i - 1].length - 1].nodeId) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const result = {
|
|
138
|
+
nodeId: path[0][path[0].length - 1].nodeId,
|
|
139
|
+
connectors: [],
|
|
140
|
+
paths: []
|
|
141
|
+
};
|
|
142
|
+
for (let i = 0; i < path.length; i += 1) {
|
|
143
|
+
const current = path[i];
|
|
144
|
+
result.connectors.push(current[current.length - 1].connectors);
|
|
145
|
+
if (result.paths !== undefined) {
|
|
146
|
+
result.paths[i] = current;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=GraphTraversal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphTraversal.js","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/GraphTraversal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,SAAS,CAAC;AAUzD,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,MAAM,CAAC,GAAG,CAAC,EAAa,EAAE,GAAY;QACpC,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC;QAEpC,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,UAAU,GAAG,cAAc,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAEtD,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,KAAK,CAAC,uCAAuC,CAAC,CAAC;aACtD;YAED,GAAG,GAAG,UAAU,CAAC;SAClB;QAED,MAAM,KAAK,GAAa,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,MAAM,GA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AAC,CAAC,CAAC,UAAU,CAAC,CAAC;YAE/D,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE;gBAC9B,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;aAC3B;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { DirectedGraph, GraphData, Node } from './Graph';\n\ninterface NestedArray<T> extends Array<T | NestedArray<T>> {}\n\ninterface ConvergenceData {\n nodeId: string;\n connectors: NestedArray<string>;\n paths?: NestedArray<ConvergenceData>;\n}\n\nexport default class GraphTraversal {\n static bfs(gd: GraphData, src?: string): string[] {\n const graph = new DirectedGraph(gd);\n\n if (!src) {\n const rootNodeId = GraphTraversal.findRootNode(graph);\n\n if (!rootNodeId) {\n throw Error('Invalid graph, cannot find root node.');\n }\n\n src = rootNodeId;\n }\n\n const queue: string[] = [src];\n const result: string[] = [];\n const map: Record<string, string> = {\n src\n }; // needed for duplicate comparision\n\n while (queue.length > 0) {\n const source = queue.shift();\n if (source !== undefined) {\n result.push(source);\n\n const nextNodes = graph.getNextNodes(source);\n nextNodes.forEach((node: Node) => {\n if (!map[node.id]) {\n queue.push(node.id);\n map[node.id] = node.id;\n }\n });\n }\n }\n\n return result;\n }\n\n static dfs(gd: GraphData, src?: string): string[] {\n const graph = new DirectedGraph(gd);\n\n // finding the start node automatically\n if (!src) {\n const rootNodeId = GraphTraversal.findRootNode(graph);\n\n if (!rootNodeId) {\n throw Error('Invalid graph, cannot find root node.');\n }\n\n src = rootNodeId;\n }\n\n const stack: string[] = [src];\n const result: string[] = [];\n const map: Record<string, string> = {\n src\n }; // needed for duplicate comparision\n\n while (stack.length > 0) {\n const source = stack.pop();\n if (source !== undefined) {\n result.push(source);\n\n const nextNodes = graph.getNextNodes(source);\n\n nextNodes.forEach(node => {\n if (map[node.id] === undefined) {\n stack.push(node.id);\n map[node.id] = node.id;\n }\n });\n }\n }\n\n return result;\n }\n\n // Assuming the given graph has no unconnected nodes and the graph is not cyclic(if start node have in-connectors(ie., cyclic), this will fail).\n // - returns first encountered node with no in-connectors as a rootnode, if more than one exists\n static findRootNode(graph: DirectedGraph): string | false {\n const nodes = graph.getNodes();\n\n for (let i = 0; i < nodes.length; i += 1) {\n if (graph.getPrevNodesCount(nodes[i].id) === 0) {\n return nodes[i].id;\n }\n }\n\n return false;\n }\n\n /**\n * Given the graphData and the source node with morethan one branch, It calculates the convergence node, involved connectors and paths\n * Assuming, goTo is not supported\n *\n * @param gd graphData to process on\n * @param src id of the source node. This needs to be a node with multiple branches\n * @returns id of the destination node or null if not found\n */\n // TODO-OPTIMIZE Memoize, for a given GraphData\n static getConvergenceData(gd: GraphData, src: string): ConvergenceData | false {\n const graph = new DirectedGraph(gd);\n\n // return false, if there is no node with given source node id\n if (graph.getNode(src) !== undefined && graph.getNextNodesCount(src) < 2) {\n return false;\n }\n\n // traverse the nodes -- and record the paths of each connector\n const path: ConvergenceData[][] = []; // array of path-arrays\n const initialConnectors = graph.getOutConnectors(src);\n\n // iterate the initial set of connectors\n initialConnectors.forEach((item, index) => {\n path[index] = [];\n\n let currentConnector = item;\n // traverse through each connector and push the encountered nodes\n while (currentConnector && currentConnector.toNodeId !== undefined) {\n path[index].push({\n nodeId: currentConnector.toNodeId,\n connectors: [currentConnector.id]\n });\n\n const inConnectors = graph.getInConnectors(currentConnector.toNodeId);\n // if this node has multiple in connectors, that means this is a join [IMP TODO NOTE until we support goTo option]\n if (inConnectors.length > 1) {\n return;\n }\n\n let outConnectors = graph.getOutConnectors(currentConnector.toNodeId);\n\n let newCurrentNodeId = currentConnector.toNodeId;\n // check if this node has multiple branches and call recursively\n while (outConnectors.length > 1) {\n const result = GraphTraversal.getConvergenceData(gd, newCurrentNodeId);\n\n // handle resultNodeId val as false use case: just cancel futher processing and return false\n if (result === false) {\n return false;\n }\n\n // add result node to the path\n path[index].push(result);\n\n // handle, resultNode as destination shape of alternate connector too\n const tempInConnectors = graph.getInConnectors(result.nodeId);\n // if this node has multiple in connectors and more than expected count, that means this is a join [IMP TODO NOTE until we support goTo option]\n if (tempInConnectors.length > outConnectors.length) {\n return;\n }\n\n // handle, resultNode as decision shape\n outConnectors = graph.getOutConnectors(result.nodeId);\n newCurrentNodeId = result.nodeId;\n }\n\n // else if out connectors is 1\n currentConnector = outConnectors[0];\n }\n });\n\n // validate and return false if no convergence node found\n for (let i = 1; i < path.length; i += 1) {\n if (path[i][path[i].length - 1].nodeId !== path[i - 1][path[i - 1].length - 1].nodeId) {\n return false;\n }\n }\n\n const result: ConvergenceData = {\n nodeId: path[0][path[0].length - 1].nodeId,\n connectors: [],\n paths: []\n };\n\n for (let i = 0; i < path.length; i += 1) {\n const current = path[i];\n result.connectors.push(current[current.length - 1].connectors);\n\n if (result.paths !== undefined) {\n result.paths[i] = current;\n }\n }\n\n return result;\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AddNodeHandlerParams, RendererConnectorProps, RendererNodeProps } from '../Renderer/Renderer.types';
|
|
2
|
+
import { ConnectorProps, DirectedGraph, GraphData, Node } from '../Renderer/Utils/Graph';
|
|
3
|
+
export interface PlaceHolderNode extends RendererNodeProps {
|
|
4
|
+
realConnectors: string[];
|
|
5
|
+
}
|
|
6
|
+
export interface PlaceHolderConnector extends RendererConnectorProps {
|
|
7
|
+
realConnectors: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const isPlaceHolderNode: (node: PlaceHolderNode | Node) => node is PlaceHolderNode;
|
|
10
|
+
export declare const isPlaceHolderConnector: (connector: PlaceHolderConnector | ConnectorProps) => connector is PlaceHolderConnector;
|
|
11
|
+
declare const PlaceHolderHelper: {
|
|
12
|
+
insertAtConnectorsMerge: (graph: DirectedGraph, getNewPHNodeCB: (addNodeMeta: AddNodeHandlerParams) => RendererNodeProps, getNewPHConnectorCB: (fromNode: string, toNode: string, addNodeMeta: AddNodeHandlerParams) => RendererConnectorProps) => void;
|
|
13
|
+
injectPlaceholderNodes: (graphData: GraphData<RendererNodeProps, RendererConnectorProps>, onGetNewNode: (metaData: AddNodeHandlerParams) => RendererNodeProps, onGetNewConnector: (fromNodeId: string, toNodeId: string, metaData: AddNodeHandlerParams) => RendererConnectorProps) => GraphData<RendererNodeProps, RendererConnectorProps>;
|
|
14
|
+
};
|
|
15
|
+
export default PlaceHolderHelper;
|
|
16
|
+
//# sourceMappingURL=AddNodeUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddNodeUtils.d.ts","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Utils/AddNodeUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAGzF,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AACD,MAAM,WAAW,oBAAqB,SAAQ,sBAAsB;IAClE,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAGD,eAAO,MAAM,iBAAiB,SAAU,eAAe,GAAG,IAAI,4BAE7D,CAAC;AAGF,eAAO,MAAM,sBAAsB,cACtB,oBAAoB,GAAG,cAAc,sCAGjD,CAAC;AAEF,QAAA,MAAM,iBAAiB;qCAEZ,aAAa,gCACU,oBAAoB,KAAK,iBAAiB,kCAE5D,MAAM,UACR,MAAM,eACD,oBAAoB,KAC9B,sBAAsB;wCAgEhB,UAAU,iBAAiB,EAAE,sBAAsB,CAAC,2BACtC,oBAAoB,KAAK,iBAAiB,kCAErD,MAAM,YACR,MAAM,YACN,oBAAoB,KAC3B,sBAAsB;CA6D9B,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { DirectedGraph } from '../Renderer/Utils/Graph';
|
|
2
|
+
import GraphTraversal from '../Renderer/Utils/GraphTraversal';
|
|
3
|
+
// type-guard PlaceHolderNode
|
|
4
|
+
export const isPlaceHolderNode = (node) => {
|
|
5
|
+
return node.realConnectors !== undefined;
|
|
6
|
+
};
|
|
7
|
+
// type-guard PlaceHolderConnector
|
|
8
|
+
export const isPlaceHolderConnector = (connector) => {
|
|
9
|
+
return connector.realConnectors !== undefined;
|
|
10
|
+
};
|
|
11
|
+
const PlaceHolderHelper = {
|
|
12
|
+
insertAtConnectorsMerge: (graph, getNewPHNodeCB, getNewPHConnectorCB) => {
|
|
13
|
+
const gd = graph.getGraphData();
|
|
14
|
+
// process the graph and find the first node automatically. We can find it easily by iterating and finding the node with no in-connectors
|
|
15
|
+
const bfs = GraphTraversal.bfs(gd);
|
|
16
|
+
bfs.reverse().forEach(nodeId => {
|
|
17
|
+
const node = graph.getNode(nodeId);
|
|
18
|
+
// get the node's convergence data
|
|
19
|
+
const result = GraphTraversal.getConvergenceData(graph.getGraphData(), node.id);
|
|
20
|
+
// if node has more than one out-connector and has convergence data
|
|
21
|
+
if (result !== false) {
|
|
22
|
+
// iterate over the resultant connectors
|
|
23
|
+
for (let i = 0; i < result.connectors.length; i += 1) {
|
|
24
|
+
const connectorsToUpdate = result.connectors[i];
|
|
25
|
+
if (typeof connectorsToUpdate !== 'string' && connectorsToUpdate.length > 1) {
|
|
26
|
+
let refConnectorIdsArray = [];
|
|
27
|
+
connectorsToUpdate.forEach(itrConId => {
|
|
28
|
+
let conId = itrConId;
|
|
29
|
+
if (Array.isArray(conId)) {
|
|
30
|
+
conId = itrConId[0];
|
|
31
|
+
}
|
|
32
|
+
const connector = graph.getConnector(conId);
|
|
33
|
+
if (isPlaceHolderConnector(connector)) {
|
|
34
|
+
refConnectorIdsArray = [...refConnectorIdsArray, ...connector.realConnectors];
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
refConnectorIdsArray.push(conId);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const addNodeMeta = {
|
|
41
|
+
refType: 'connector',
|
|
42
|
+
refId: refConnectorIdsArray
|
|
43
|
+
};
|
|
44
|
+
const newNode = getNewPHNodeCB(addNodeMeta);
|
|
45
|
+
const newPNode = {
|
|
46
|
+
...newNode,
|
|
47
|
+
realConnectors: refConnectorIdsArray
|
|
48
|
+
};
|
|
49
|
+
graph.addNode(newPNode);
|
|
50
|
+
connectorsToUpdate.forEach(item => {
|
|
51
|
+
graph.setConnector(item, {
|
|
52
|
+
toNodeId: newNode.id
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
const newConnector = getNewPHConnectorCB(newNode.id, result.nodeId, addNodeMeta);
|
|
56
|
+
const newPConnector = {
|
|
57
|
+
...newConnector,
|
|
58
|
+
realConnectors: refConnectorIdsArray
|
|
59
|
+
};
|
|
60
|
+
graph.addConnector(newPConnector);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
injectPlaceholderNodes: (graphData, onGetNewNode, onGetNewConnector) => {
|
|
67
|
+
// gets GraphData<RendererNodeProps, RendererConnectorProps>
|
|
68
|
+
const targetGraph = new DirectedGraph(graphData);
|
|
69
|
+
// insert placeholder-nodes at connector convergence point for nodes with multiple out connectors.
|
|
70
|
+
PlaceHolderHelper.insertAtConnectorsMerge(targetGraph, onGetNewNode, onGetNewConnector);
|
|
71
|
+
// iterate all nodes with more than one in-connectors and insert addNode before current one.
|
|
72
|
+
targetGraph.getNodes().forEach(node => {
|
|
73
|
+
// should not add a node before a placeholder node
|
|
74
|
+
if (isPlaceHolderNode(node)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (targetGraph.getPrevNodesCount(node.id) > 1) {
|
|
78
|
+
let refConnectorIdsArray = [];
|
|
79
|
+
// connect all in-connectors to a new node and create a new connector that connects from new node to the actual toNodeId.
|
|
80
|
+
targetGraph.getInConnectors(node.id).forEach(con => {
|
|
81
|
+
const connector = targetGraph.getConnector(con.id);
|
|
82
|
+
if (isPlaceHolderConnector(connector)) {
|
|
83
|
+
refConnectorIdsArray = [...refConnectorIdsArray, ...connector.realConnectors];
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
refConnectorIdsArray.push(con.id);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const metaData = {
|
|
90
|
+
refType: 'connector',
|
|
91
|
+
refId: refConnectorIdsArray
|
|
92
|
+
};
|
|
93
|
+
// create a new placeholder node
|
|
94
|
+
const newNode = onGetNewNode(metaData);
|
|
95
|
+
const placeHolderNode = {
|
|
96
|
+
...newNode,
|
|
97
|
+
realConnectors: refConnectorIdsArray
|
|
98
|
+
};
|
|
99
|
+
targetGraph.addNode(placeHolderNode);
|
|
100
|
+
// connect all in-connectors to a new node and create a new connector that connects from new node to the actual toNodeId.
|
|
101
|
+
targetGraph.getInConnectors(node.id).forEach(con => {
|
|
102
|
+
targetGraph.setConnector(con.id, {
|
|
103
|
+
toNodeId: placeHolderNode.id
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
const newConnector = onGetNewConnector(placeHolderNode.id, node.id, metaData);
|
|
107
|
+
const placeholderConnector = {
|
|
108
|
+
...newConnector,
|
|
109
|
+
realConnectors: refConnectorIdsArray
|
|
110
|
+
};
|
|
111
|
+
targetGraph.addConnector(placeholderConnector);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return targetGraph.getGraphData();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
export default PlaceHolderHelper;
|
|
118
|
+
//# sourceMappingURL=AddNodeUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddNodeUtils.js","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Utils/AddNodeUtils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,aAAa,EAAmB,MAAM,yBAAyB,CAAC;AACzF,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAS9D,6BAA6B;AAC7B,MAAM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CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;oBACjD,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,EAAE;wBAC/B,QAAQ,EAAE,eAAe,CAAC,EAAE;qBAC7B,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBAEH,MAAM,YAAY,GAAG,iBAAiB,CAAC,eAAe,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;gBAC9E,MAAM,oBAAoB,GAAyB;oBACjD,GAAG,YAAY;oBACf,cAAc,EAAE,oBAAoB;iBACrC,CAAC;gBAEF,WAAW,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;aAChD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC","sourcesContent":["import { AddNodeProps } from '../AddNode';\nimport {\n AddNodeHandlerParams,\n RendererConnectorProps,\n RendererNodeProps\n} from '../Renderer/Renderer.types';\nimport { ConnectorProps, DirectedGraph, GraphData, Node } from '../Renderer/Utils/Graph';\nimport GraphTraversal from '../Renderer/Utils/GraphTraversal';\n\nexport interface PlaceHolderNode extends RendererNodeProps {\n realConnectors: string[];\n}\nexport interface PlaceHolderConnector extends RendererConnectorProps {\n realConnectors: string[];\n}\n\n// type-guard PlaceHolderNode\nexport const isPlaceHolderNode = (node: PlaceHolderNode | Node): node is PlaceHolderNode => {\n return (node as PlaceHolderNode).realConnectors !== undefined;\n};\n\n// type-guard PlaceHolderConnector\nexport const isPlaceHolderConnector = (\n connector: PlaceHolderConnector | ConnectorProps\n): connector is PlaceHolderConnector => {\n return (connector as PlaceHolderConnector).realConnectors !== undefined;\n};\n\nconst PlaceHolderHelper = {\n insertAtConnectorsMerge: (\n graph: DirectedGraph,\n getNewPHNodeCB: (addNodeMeta: AddNodeHandlerParams) => RendererNodeProps,\n getNewPHConnectorCB: (\n fromNode: string,\n toNode: string,\n addNodeMeta: AddNodeHandlerParams\n ) => RendererConnectorProps\n ) => {\n const gd = graph.getGraphData();\n\n // process the graph and find the first node automatically. We can find it easily by iterating and finding the node with no in-connectors\n const bfs = GraphTraversal.bfs(gd);\n bfs.reverse().forEach(nodeId => {\n const node = graph.getNode(nodeId);\n\n // get the node's convergence data\n const result = GraphTraversal.getConvergenceData(graph.getGraphData(), node.id);\n\n // if node has more than one out-connector and has convergence data\n if (result !== false) {\n // iterate over the resultant connectors\n for (let i = 0; i < result.connectors.length; i += 1) {\n const connectorsToUpdate = result.connectors[i];\n\n if (typeof connectorsToUpdate !== 'string' && connectorsToUpdate.length > 1) {\n let refConnectorIdsArray: string[] = [];\n\n connectorsToUpdate.forEach(itrConId => {\n let conId = itrConId;\n if (Array.isArray(conId)) {\n conId = itrConId[0] as string;\n }\n\n const connector = graph.getConnector(conId);\n if (isPlaceHolderConnector(connector)) {\n refConnectorIdsArray = [...refConnectorIdsArray, ...connector.realConnectors];\n } else {\n refConnectorIdsArray.push(conId);\n }\n });\n\n const addNodeMeta: AddNodeHandlerParams = {\n refType: 'connector',\n refId: refConnectorIdsArray\n };\n const newNode = getNewPHNodeCB(addNodeMeta);\n const newPNode: PlaceHolderNode = {\n ...newNode,\n realConnectors: refConnectorIdsArray\n };\n graph.addNode(newPNode);\n\n connectorsToUpdate.forEach(item => {\n graph.setConnector(item as string, {\n toNodeId: newNode.id\n });\n });\n\n const newConnector = getNewPHConnectorCB(newNode.id, result.nodeId, addNodeMeta);\n const newPConnector: PlaceHolderConnector = {\n ...newConnector,\n realConnectors: refConnectorIdsArray\n };\n graph.addConnector(newPConnector);\n }\n }\n }\n });\n },\n injectPlaceholderNodes: (\n graphData: GraphData<RendererNodeProps, RendererConnectorProps>,\n onGetNewNode: (metaData: AddNodeHandlerParams) => RendererNodeProps,\n onGetNewConnector: (\n fromNodeId: string,\n toNodeId: string,\n metaData: AddNodeHandlerParams\n ) => RendererConnectorProps\n ) => {\n // gets GraphData<RendererNodeProps, RendererConnectorProps>\n const targetGraph = new DirectedGraph(graphData);\n\n // insert placeholder-nodes at connector convergence point for nodes with multiple out connectors.\n PlaceHolderHelper.insertAtConnectorsMerge(targetGraph, onGetNewNode, onGetNewConnector);\n\n // iterate all nodes with more than one in-connectors and insert addNode before current one.\n targetGraph.getNodes().forEach(node => {\n // should not add a node before a placeholder node\n if (isPlaceHolderNode(node)) {\n return;\n }\n\n if (targetGraph.getPrevNodesCount(node.id) > 1) {\n let refConnectorIdsArray: string[] = [];\n\n // connect all in-connectors to a new node and create a new connector that connects from new node to the actual toNodeId.\n targetGraph.getInConnectors(node.id).forEach(con => {\n const connector = targetGraph.getConnector(con.id);\n if (isPlaceHolderConnector(connector)) {\n refConnectorIdsArray = [...refConnectorIdsArray, ...connector.realConnectors];\n } else {\n refConnectorIdsArray.push(con.id);\n }\n });\n\n const metaData: AddNodeHandlerParams = {\n refType: 'connector',\n refId: refConnectorIdsArray\n };\n\n // create a new placeholder node\n const newNode: AddNodeProps = onGetNewNode(metaData);\n const placeHolderNode: PlaceHolderNode = {\n ...newNode,\n realConnectors: refConnectorIdsArray\n };\n\n targetGraph.addNode(placeHolderNode);\n\n // connect all in-connectors to a new node and create a new connector that connects from new node to the actual toNodeId.\n targetGraph.getInConnectors(node.id).forEach(con => {\n targetGraph.setConnector(con.id, {\n toNodeId: placeHolderNode.id\n });\n });\n\n const newConnector = onGetNewConnector(placeHolderNode.id, node.id, metaData);\n const placeholderConnector: PlaceHolderConnector = {\n ...newConnector,\n realConnectors: refConnectorIdsArray\n };\n\n targetGraph.addConnector(placeholderConnector);\n }\n });\n\n return targetGraph.getGraphData();\n }\n};\n\nexport default PlaceHolderHelper;\n"]}
|
|
@@ -14,6 +14,7 @@ export interface AddHelperParams {
|
|
|
14
14
|
getNewConnector?: (fromNodeId: string, toNodeId: string) => ConnectorProps;
|
|
15
15
|
}
|
|
16
16
|
declare const helpers: {
|
|
17
|
+
addBranch(graphData: NodeDataType, nodeId: string, label?: string | undefined, getNewConnector?: AddHelperParams['getNewConnector']): GraphData<NodeProps, ConnectorProps<unknown>>;
|
|
17
18
|
deleteNode(graphData: NodeDataType, nodeId: string): GraphData<NodeProps, ConnectorProps<unknown>> | null;
|
|
18
19
|
deleteConnector: (graphData: NodeDataType, connector: ConnectorProps) => GraphData<NodeProps, ConnectorProps<unknown>> | null;
|
|
19
20
|
addNode: ({ graphData, nodeType, metaData, getNewNode, getNewConnector, connectorsCount }: AddHelperParams) => GraphData<NodeProps, ConnectorProps<unknown>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/components/FlowModeller/helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,SAAS,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAiB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/components/FlowModeller/helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,SAAS,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAiB,MAAM,mBAAmB,CAAC;AAGvE,UAAU,YAAY;IACpB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,UAAU,EAAE,cAAc,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAChD,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,SAAS,CAAC;IAC7B,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,cAAc,CAAC;CAC5E;AAED,QAAA,MAAM,OAAO;yBAEE,YAAY,UACf,MAAM,gDAEI,eAAe,CAAC,iBAAiB,CAAC;0BAwBhC,YAAY,UAAU,MAAM;iCAsBrB,YAAY,aAAa,cAAc;+FAqCjE,eAAe;CA+DnB,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import { createUID } from '@pega/cosmos-react-core';
|
|
2
2
|
import { DirectedGraph } from './Renderer/Utils/Graph';
|
|
3
3
|
import { STOP_NODETYPE } from './Node/Node.types';
|
|
4
|
+
import GraphTraversal from './Renderer/Utils/GraphTraversal';
|
|
4
5
|
const helpers = {
|
|
6
|
+
addBranch(graphData, nodeId, label, getNewConnector) {
|
|
7
|
+
const graph = new DirectedGraph(graphData);
|
|
8
|
+
const convergeData = GraphTraversal.getConvergenceData(graphData, nodeId);
|
|
9
|
+
if (convergeData) {
|
|
10
|
+
const newConnector = getNewConnector
|
|
11
|
+
? getNewConnector(nodeId, convergeData.nodeId)
|
|
12
|
+
: {
|
|
13
|
+
id: createUID(),
|
|
14
|
+
fromNodeId: nodeId,
|
|
15
|
+
toNodeId: convergeData.nodeId,
|
|
16
|
+
label: label || ''
|
|
17
|
+
};
|
|
18
|
+
graph.addConnector(newConnector);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw new Error('Invalid node, either the node does not exist or it does not support branches');
|
|
22
|
+
}
|
|
23
|
+
return graph.getGraphData();
|
|
24
|
+
},
|
|
5
25
|
deleteNode(graphData, nodeId) {
|
|
6
26
|
const graph = new DirectedGraph(graphData);
|
|
7
27
|
const outConnectors = graph.getOutConnectors(nodeId);
|
|
@@ -10,7 +30,9 @@ const helpers = {
|
|
|
10
30
|
}
|
|
11
31
|
const inConnectors = graph.getInConnectors(nodeId);
|
|
12
32
|
inConnectors.forEach(con => {
|
|
13
|
-
con.
|
|
33
|
+
graph.setConnector(con.id, {
|
|
34
|
+
toNodeId: outConnectors[0].toNodeId
|
|
35
|
+
});
|
|
14
36
|
});
|
|
15
37
|
graph.removeConnector(outConnectors[0].id);
|
|
16
38
|
graph.deleteNode(nodeId, true);
|
|
@@ -58,17 +80,26 @@ const helpers = {
|
|
|
58
80
|
graph.addNode(newNode);
|
|
59
81
|
let toNodeId = '';
|
|
60
82
|
if (metaData.refType === 'connector') {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
if (!Array.isArray(metaData.refId)) {
|
|
84
|
+
metaData.refId = [metaData.refId];
|
|
85
|
+
}
|
|
86
|
+
metaData.refId.forEach(conId => {
|
|
87
|
+
const refConnector = graph.getConnector(conId);
|
|
88
|
+
// backup current connectors toNodeId
|
|
89
|
+
toNodeId = refConnector.toNodeId;
|
|
90
|
+
// update the actual connector
|
|
91
|
+
graph.setConnector(conId, {
|
|
92
|
+
toNodeId: newNode.id
|
|
93
|
+
});
|
|
94
|
+
});
|
|
66
95
|
}
|
|
67
96
|
else if (metaData.refType === 'node') {
|
|
68
97
|
toNodeId = metaData.refId;
|
|
69
98
|
// iterate and update all in-connectors to point to the new node
|
|
70
99
|
graph.getInConnectors(metaData.refId).forEach(con => {
|
|
71
|
-
con.
|
|
100
|
+
graph.setConnector(con.id, {
|
|
101
|
+
toNodeId: newNode.id
|
|
102
|
+
});
|
|
72
103
|
});
|
|
73
104
|
}
|
|
74
105
|
let minConnectors = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/components/FlowModeller/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAA6B,MAAM,wBAAwB,CAAC;AAElF,OAAO,EAAuB,aAAa,EAAE,MAAM,mBAAmB,CA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C,YAAY,CAAC,CAAC;SAClC;QACD,+BAA+B;QAC/B,OAAO,KAAK,CAAC,YAAY,EAAE,CAAC;IAC9B,CAAC;CACF,CAAC;AAEF,eAAe,OAAO,CAAC","sourcesContent":["import { createUID } from '@pega/cosmos-react-core';\n\nimport { DirectedGraph, GraphData, ConnectorProps } from './Renderer/Utils/Graph';\nimport { AddNodeHandlerParams } from './Renderer/Renderer.types';\nimport { NodeProps, NodeType, STOP_NODETYPE } from './Node/Node.types';\nimport GraphTraversal from './Renderer/Utils/GraphTraversal';\n\ninterface NodeDataType {\n nodes: NodeProps[];\n connectors: ConnectorProps[];\n}\n\nexport interface AddHelperParams {\n nodeType: NodeType;\n graphData: GraphData<NodeProps, ConnectorProps>;\n metaData: AddNodeHandlerParams;\n connectorsCount?: number;\n getNewNode?: () => NodeProps;\n getNewConnector?: (fromNodeId: string, toNodeId: string) => ConnectorProps;\n}\n\nconst helpers = {\n addBranch(\n graphData: NodeDataType,\n nodeId: string,\n label?: string,\n getNewConnector?: AddHelperParams['getNewConnector']\n ) {\n const graph = new DirectedGraph<NodeProps, ConnectorProps>(graphData);\n const convergeData = GraphTraversal.getConvergenceData(graphData, nodeId);\n\n if (convergeData) {\n const newConnector = getNewConnector\n ? getNewConnector(nodeId, convergeData.nodeId)\n : {\n id: createUID(),\n fromNodeId: nodeId,\n toNodeId: convergeData.nodeId,\n label: label || ''\n };\n\n graph.addConnector(newConnector);\n } else {\n throw new Error(\n 'Invalid node, either the node does not exist or it does not support branches'\n );\n }\n\n return graph.getGraphData();\n },\n deleteNode(graphData: NodeDataType, nodeId: string) {\n const graph = new DirectedGraph<NodeProps, ConnectorProps>(graphData);\n const outConnectors = graph.getOutConnectors(nodeId);\n\n if (outConnectors.length > 1) {\n return null;\n }\n\n const inConnectors = graph.getInConnectors(nodeId);\n\n inConnectors.forEach(con => {\n graph.setConnector(con.id, {\n toNodeId: outConnectors[0].toNodeId\n });\n });\n\n graph.removeConnector(outConnectors[0].id);\n\n graph.deleteNode(nodeId, true);\n\n return graph.getGraphData();\n },\n deleteConnector: (graphData: NodeDataType, connector: ConnectorProps) => {\n const graph = new DirectedGraph<NodeProps, ConnectorProps>(graphData);\n const nodeId = connector.fromNodeId;\n const outConnectors = graph.getOutConnectors(nodeId);\n const toNode = graph.getNode(connector.toNodeId);\n const inConnectors = graph.getInConnectors(connector.toNodeId);\n let isRemoved = false;\n if (inConnectors.length >= 2) {\n graph.removeConnector(connector.id);\n isRemoved = true;\n }\n if (toNode.type.id === STOP_NODETYPE.id && outConnectors.length > 1 && !isRemoved) {\n graph.removeConnector(connector.id);\n isRemoved = true;\n }\n\n if (outConnectors.length > 1 && !isRemoved) {\n outConnectors.forEach(item => {\n if (connector.toNodeId === item.toNodeId && item.id !== connector.id) {\n // Connector without any node\n graph.removeConnector(connector.id);\n isRemoved = true;\n }\n });\n }\n if (isRemoved) {\n return graph.getGraphData();\n }\n return null;\n },\n addNode: ({\n graphData,\n nodeType,\n metaData,\n getNewNode,\n getNewConnector,\n connectorsCount\n }: AddHelperParams) => {\n const graph = new DirectedGraph(graphData);\n\n const newNode = getNewNode\n ? getNewNode()\n : {\n ...nodeType.defaults.node,\n id: createUID(),\n type: nodeType\n };\n\n // add new node\n graph.addNode(newNode);\n\n let toNodeId = '';\n if (metaData.refType === 'connector') {\n if (!Array.isArray(metaData.refId)) {\n metaData.refId = [metaData.refId];\n }\n\n metaData.refId.forEach(conId => {\n const refConnector = graph.getConnector(conId);\n\n // backup current connectors toNodeId\n toNodeId = refConnector.toNodeId;\n\n // update the actual connector\n graph.setConnector(conId, {\n toNodeId: newNode.id\n });\n });\n } else if (metaData.refType === 'node') {\n toNodeId = metaData.refId as string;\n\n // iterate and update all in-connectors to point to the new node\n graph.getInConnectors(metaData.refId as string).forEach(con => {\n graph.setConnector(con.id, {\n toNodeId: newNode.id\n });\n });\n }\n\n let minConnectors = 1;\n if (connectorsCount !== undefined) {\n minConnectors = connectorsCount;\n } else {\n minConnectors = nodeType.minConnectors !== undefined ? nodeType.minConnectors : 1;\n }\n\n for (let i = 0; i < minConnectors; i += 1) {\n const newConnector = getNewConnector\n ? getNewConnector(newNode.id, toNodeId)\n : {\n id: createUID(),\n fromNodeId: newNode.id,\n toNodeId,\n label: nodeType.defaults?.connector[i].label\n };\n graph.addConnector(newConnector);\n }\n // return the updated graphData\n return graph.getGraphData();\n }\n};\n\nexport default helpers;\n"]}
|