@pega/cosmos-react-build 2.0.0-dev.18.0 → 2.0.0-dev.21.1

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.
Files changed (133) hide show
  1. package/lib/components/AppHeader/AppHeader.js +3 -3
  2. package/lib/components/AppHeader/AppHeader.js.map +1 -1
  3. package/lib/components/AppShell/AppShell.d.ts.map +1 -1
  4. package/lib/components/AppShell/AppShell.js +44 -47
  5. package/lib/components/AppShell/AppShell.js.map +1 -1
  6. package/lib/components/AppShell/AppShell.styles.d.ts.map +1 -1
  7. package/lib/components/AppShell/AppShell.styles.js +22 -18
  8. package/lib/components/AppShell/AppShell.styles.js.map +1 -1
  9. package/lib/components/AppShell/AppShell.types.d.ts +14 -9
  10. package/lib/components/AppShell/AppShell.types.d.ts.map +1 -1
  11. package/lib/components/AppShell/AppShell.types.js.map +1 -1
  12. package/lib/components/AppShell/AppShellContext.d.ts.map +1 -1
  13. package/lib/components/AppShell/AppShellContext.js +5 -3
  14. package/lib/components/AppShell/AppShellContext.js.map +1 -1
  15. package/lib/components/FlowModeller/FlowModeller.d.ts +6 -5
  16. package/lib/components/FlowModeller/FlowModeller.d.ts.map +1 -1
  17. package/lib/components/FlowModeller/FlowModeller.js +184 -61
  18. package/lib/components/FlowModeller/FlowModeller.js.map +1 -1
  19. package/lib/components/FlowModeller/Node/Node.types.d.ts +26 -16
  20. package/lib/components/FlowModeller/Node/Node.types.d.ts.map +1 -1
  21. package/lib/components/FlowModeller/Node/Node.types.js +27 -1
  22. package/lib/components/FlowModeller/Node/Node.types.js.map +1 -1
  23. package/lib/components/FlowModeller/Node/NodeTemplate.styles.d.ts +10 -5
  24. package/lib/components/FlowModeller/Node/NodeTemplate.styles.d.ts.map +1 -1
  25. package/lib/components/FlowModeller/Node/NodeTemplate.styles.js +38 -31
  26. package/lib/components/FlowModeller/Node/NodeTemplate.styles.js.map +1 -1
  27. package/lib/components/FlowModeller/Node/NodeTemplates.d.ts +1 -4
  28. package/lib/components/FlowModeller/Node/NodeTemplates.d.ts.map +1 -1
  29. package/lib/components/FlowModeller/Node/NodeTemplates.js +25 -19
  30. package/lib/components/FlowModeller/Node/NodeTemplates.js.map +1 -1
  31. package/lib/components/FlowModeller/NodeLibrary.d.ts +12 -0
  32. package/lib/components/FlowModeller/NodeLibrary.d.ts.map +1 -0
  33. package/lib/components/FlowModeller/NodeLibrary.js +49 -0
  34. package/lib/components/FlowModeller/NodeLibrary.js.map +1 -0
  35. package/lib/components/FlowModeller/Renderer/AddNode.d.ts +10 -0
  36. package/lib/components/FlowModeller/Renderer/AddNode.d.ts.map +1 -0
  37. package/lib/components/FlowModeller/Renderer/AddNode.js +42 -0
  38. package/lib/components/FlowModeller/Renderer/AddNode.js.map +1 -0
  39. package/lib/components/FlowModeller/Renderer/Connector.d.ts +5 -0
  40. package/lib/components/FlowModeller/Renderer/Connector.d.ts.map +1 -0
  41. package/lib/components/FlowModeller/Renderer/Connector.js +50 -0
  42. package/lib/components/FlowModeller/Renderer/Connector.js.map +1 -0
  43. package/lib/components/FlowModeller/Renderer/ConnectorsContainer.d.ts +12 -0
  44. package/lib/components/FlowModeller/Renderer/ConnectorsContainer.d.ts.map +1 -0
  45. package/lib/components/FlowModeller/Renderer/ConnectorsContainer.js +15 -0
  46. package/lib/components/FlowModeller/Renderer/ConnectorsContainer.js.map +1 -0
  47. package/lib/components/FlowModeller/Renderer/Node.d.ts +5 -0
  48. package/lib/components/FlowModeller/Renderer/Node.d.ts.map +1 -0
  49. package/lib/components/FlowModeller/Renderer/Node.js +18 -0
  50. package/lib/components/FlowModeller/Renderer/Node.js.map +1 -0
  51. package/lib/components/FlowModeller/Renderer/NodesContainer.d.ts +8 -0
  52. package/lib/components/FlowModeller/Renderer/NodesContainer.d.ts.map +1 -0
  53. package/lib/components/FlowModeller/Renderer/NodesContainer.js +15 -0
  54. package/lib/components/FlowModeller/Renderer/NodesContainer.js.map +1 -0
  55. package/lib/components/FlowModeller/Renderer/Renderer.d.ts +5 -0
  56. package/lib/components/FlowModeller/Renderer/Renderer.d.ts.map +1 -0
  57. package/lib/components/FlowModeller/Renderer/Renderer.js +17 -0
  58. package/lib/components/FlowModeller/Renderer/Renderer.js.map +1 -0
  59. package/lib/components/FlowModeller/Renderer/Renderer.types.d.ts +18 -0
  60. package/lib/components/FlowModeller/Renderer/Renderer.types.d.ts.map +1 -0
  61. package/lib/components/FlowModeller/Renderer/Renderer.types.js +2 -0
  62. package/lib/components/FlowModeller/Renderer/Renderer.types.js.map +1 -0
  63. package/lib/components/FlowModeller/Renderer/Utils/Graph.d.ts +51 -0
  64. package/lib/components/FlowModeller/Renderer/Utils/Graph.d.ts.map +1 -0
  65. package/lib/components/FlowModeller/Renderer/Utils/Graph.js +247 -0
  66. package/lib/components/FlowModeller/Renderer/Utils/Graph.js.map +1 -0
  67. package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.d.ts +35 -0
  68. package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.d.ts.map +1 -0
  69. package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.js +104 -0
  70. package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.js.map +1 -0
  71. package/lib/components/FlowModeller/helper.d.ts +22 -0
  72. package/lib/components/FlowModeller/helper.d.ts.map +1 -0
  73. package/lib/components/FlowModeller/helper.js +97 -0
  74. package/lib/components/FlowModeller/helper.js.map +1 -0
  75. package/lib/components/LifeCycle/Category.js +5 -5
  76. package/lib/components/LifeCycle/Category.js.map +1 -1
  77. package/lib/components/LifeCycle/LifeCycle.js +5 -5
  78. package/lib/components/LifeCycle/LifeCycle.js.map +1 -1
  79. package/lib/components/LifeCycle/LifeCycleList.js +2 -2
  80. package/lib/components/LifeCycle/LifeCycleList.js.map +1 -1
  81. package/lib/components/LifeCycle/Stage.d.ts +3 -1
  82. package/lib/components/LifeCycle/Stage.d.ts.map +1 -1
  83. package/lib/components/LifeCycle/Stage.js +9 -2
  84. package/lib/components/LifeCycle/Stage.js.map +1 -1
  85. package/lib/components/LifeCycle/Step.d.ts +4 -1
  86. package/lib/components/LifeCycle/Step.d.ts.map +1 -1
  87. package/lib/components/LifeCycle/Step.js +12 -2
  88. package/lib/components/LifeCycle/Step.js.map +1 -1
  89. package/lib/components/LifeCycle/Task.d.ts +3 -1
  90. package/lib/components/LifeCycle/Task.d.ts.map +1 -1
  91. package/lib/components/LifeCycle/Task.js +14 -5
  92. package/lib/components/LifeCycle/Task.js.map +1 -1
  93. package/lib/components/PageTemplates/GalleryPage.d.ts +23 -0
  94. package/lib/components/PageTemplates/GalleryPage.d.ts.map +1 -0
  95. package/lib/components/PageTemplates/GalleryPage.js +23 -0
  96. package/lib/components/PageTemplates/GalleryPage.js.map +1 -0
  97. package/lib/components/PageTemplates/GalleryPage.styles.d.ts +9 -0
  98. package/lib/components/PageTemplates/GalleryPage.styles.d.ts.map +1 -0
  99. package/lib/components/PageTemplates/GalleryPage.styles.js +70 -0
  100. package/lib/components/PageTemplates/GalleryPage.styles.js.map +1 -0
  101. package/lib/components/PageTemplates/PageTemplates.d.ts +10 -3
  102. package/lib/components/PageTemplates/PageTemplates.d.ts.map +1 -1
  103. package/lib/components/PageTemplates/PageTemplates.js +48 -8
  104. package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
  105. package/lib/components/PageTemplates/index.d.ts +2 -0
  106. package/lib/components/PageTemplates/index.d.ts.map +1 -1
  107. package/lib/components/PageTemplates/index.js +1 -0
  108. package/lib/components/PageTemplates/index.js.map +1 -1
  109. package/lib/components/SummaryCard/SummaryCard.d.ts +16 -0
  110. package/lib/components/SummaryCard/SummaryCard.d.ts.map +1 -0
  111. package/lib/components/SummaryCard/SummaryCard.js +31 -0
  112. package/lib/components/SummaryCard/SummaryCard.js.map +1 -0
  113. package/lib/components/SummaryCard/index.d.ts +3 -0
  114. package/lib/components/SummaryCard/index.d.ts.map +1 -0
  115. package/lib/components/SummaryCard/index.js +3 -0
  116. package/lib/components/SummaryCard/index.js.map +1 -0
  117. package/lib/components/Visual/Visual.d.ts +17 -0
  118. package/lib/components/Visual/Visual.d.ts.map +1 -0
  119. package/lib/components/Visual/Visual.js +28 -0
  120. package/lib/components/Visual/Visual.js.map +1 -0
  121. package/lib/components/Visual/index.d.ts +3 -0
  122. package/lib/components/Visual/index.d.ts.map +1 -0
  123. package/lib/components/Visual/index.js +3 -0
  124. package/lib/components/Visual/index.js.map +1 -0
  125. package/lib/index.d.ts +2 -0
  126. package/lib/index.d.ts.map +1 -1
  127. package/lib/index.js +2 -0
  128. package/lib/index.js.map +1 -1
  129. package/package.json +5 -4
  130. package/lib/components/FlowModeller/Connector.d.ts +0 -30
  131. package/lib/components/FlowModeller/Connector.d.ts.map +0 -1
  132. package/lib/components/FlowModeller/Connector.js +0 -89
  133. package/lib/components/FlowModeller/Connector.js.map +0 -1
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import styled, { css } from 'styled-components';
3
+ import { Flex } from '@pega/cosmos-react-core';
4
+ const StyledNodeWrapper = styled.div(({ dimensions, position }) => {
5
+ return css `
6
+ position: absolute;
7
+ top: 0;
8
+ left: 0;
9
+ width: ${dimensions.width}px;
10
+ height: ${dimensions.height}px;
11
+ transform: translate(${position.x}px, ${position.y}px);
12
+ `;
13
+ });
14
+ const Node = ({ children, ...restprops }) => {
15
+ return (_jsx(Flex, { as: StyledNodeWrapper, ...restprops, container: { justify: 'center' }, children: _jsx("div", { children: children }, void 0) }, void 0));
16
+ };
17
+ export default Node;
18
+ //# sourceMappingURL=Node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Node.js","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Renderer/Node.tsx"],"names":[],"mappings":";AACA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAI/C,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAGjC,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC9B,OAAO,GAAG,CAAA;;;;aAIC,UAAU,CAAC,KAAK;cACf,UAAU,CAAC,MAAM;2BACJ,QAAQ,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC;GACnD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,IAAI,GAA0B,CAAC,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE;IACjE,OAAO,CACL,KAAC,IAAI,IAAC,EAAE,EAAE,iBAAiB,KAAM,SAAS,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,YAC1E,wBAAM,QAAQ,WAAO,WAChB,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,IAAI,CAAC","sourcesContent":["import { FC } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { Flex } from '@pega/cosmos-react-core';\n\nimport { RendererNodeProps } from './Renderer.types';\n\nconst StyledNodeWrapper = styled.div<{\n dimensions: RendererNodeProps['dimensions'];\n position: RendererNodeProps['position'];\n}>(({ dimensions, position }) => {\n return css`\n position: absolute;\n top: 0;\n left: 0;\n width: ${dimensions.width}px;\n height: ${dimensions.height}px;\n transform: translate(${position.x}px, ${position.y}px);\n `;\n});\n\nconst Node: FC<RendererNodeProps> = ({ children, ...restprops }) => {\n return (\n <Flex as={StyledNodeWrapper} {...restprops} container={{ justify: 'center' }}>\n <div>{children}</div>\n </Flex>\n );\n};\n\nexport default Node;\n"]}
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import { RendererNodeProps } from './Renderer.types';
3
+ export interface NodesContainerProps {
4
+ items: RendererNodeProps[];
5
+ }
6
+ declare const NodesContainer: FC<NodesContainerProps>;
7
+ export default NodesContainer;
8
+ //# sourceMappingURL=NodesContainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodesContainer.d.ts","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Renderer/NodesContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAI3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAQrD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B;AAED,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CAQ3C,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import styled from 'styled-components';
3
+ import Node from './Node';
4
+ const StyledNodeContainer = styled.div `
5
+ position: absolute;
6
+ top: 0;
7
+ left: 0;
8
+ `;
9
+ const NodesContainer = ({ items }) => {
10
+ return (_jsx(StyledNodeContainer, { children: items.map(item => {
11
+ return _jsx(Node, { ...item }, item.id);
12
+ }) }, void 0));
13
+ };
14
+ export default NodesContainer;
15
+ //# sourceMappingURL=NodesContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodesContainer.js","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Renderer/NodesContainer.tsx"],"names":[],"mappings":";AACA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,IAAI,MAAM,QAAQ,CAAC;AAG1B,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;CAIrC,CAAC;AAMF,MAAM,cAAc,GAA4B,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC5D,OAAO,CACL,KAAC,mBAAmB,cACjB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAChB,OAAO,KAAC,IAAI,OAAmB,IAAI,IAAjB,IAAI,CAAC,EAAE,CAAc,CAAC;QAC1C,CAAC,CAAC,WACkB,CACvB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { FC } from 'react';\nimport styled from 'styled-components';\n\nimport Node from './Node';\nimport { RendererNodeProps } from './Renderer.types';\n\nconst StyledNodeContainer = styled.div`\n position: absolute;\n top: 0;\n left: 0;\n`;\n\nexport interface NodesContainerProps {\n items: RendererNodeProps[];\n}\n\nconst NodesContainer: FC<NodesContainerProps> = ({ items }) => {\n return (\n <StyledNodeContainer>\n {items.map(item => {\n return <Node key={item.id} {...item} />;\n })}\n </StyledNodeContainer>\n );\n};\n\nexport default NodesContainer;\n"]}
@@ -0,0 +1,5 @@
1
+ import { FC } from 'react';
2
+ import { RendererProps } from './Renderer.types';
3
+ declare const Renderer: FC<RendererProps>;
4
+ export default Renderer;
5
+ //# sourceMappingURL=Renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Renderer.d.ts","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Renderer/Renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAI3B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAUjD,QAAA,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAU/B,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styled from 'styled-components';
3
+ import ConnectorsContainer from './ConnectorsContainer';
4
+ import NodesContainer from './NodesContainer';
5
+ import GraphLayout from './Utils/GraphLayout';
6
+ const StyledWrapper = styled.div `
7
+ position: relative;
8
+ width: 100%;
9
+ height: 100%;
10
+ `;
11
+ const Renderer = ({ graphData }) => {
12
+ // apply the plotted positions
13
+ const graphDimensions = GraphLayout.plot(graphData);
14
+ return (_jsxs(StyledWrapper, { children: [_jsx(ConnectorsContainer, { items: graphData.connectors, dimensions: graphDimensions }, void 0), _jsx(NodesContainer, { items: graphData.nodes }, void 0)] }, void 0));
15
+ };
16
+ export default Renderer;
17
+ //# sourceMappingURL=Renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Renderer.js","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Renderer/Renderer.tsx"],"names":[],"mappings":";AACA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAE9C,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAA;;;;CAI/B,CAAC;AAEF,MAAM,QAAQ,GAAsB,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;IACpD,8BAA8B;IAC9B,MAAM,eAAe,GAAG,WAAW,CAAC,IAAI,CAA6B,SAAS,CAAC,CAAC;IAEhF,OAAO,CACL,MAAC,aAAa,eACZ,KAAC,mBAAmB,IAAC,KAAK,EAAE,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,WAAI,EACjF,KAAC,cAAc,IAAC,KAAK,EAAE,SAAS,CAAC,KAAK,WAAI,YAC5B,CACjB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { FC } from 'react';\nimport styled from 'styled-components';\n\nimport ConnectorsContainer from './ConnectorsContainer';\nimport { RendererProps } from './Renderer.types';\nimport NodesContainer from './NodesContainer';\nimport GraphLayout from './Utils/GraphLayout';\n\nconst StyledWrapper = styled.div`\n position: relative;\n width: 100%;\n height: 100%;\n`;\n\nconst Renderer: FC<RendererProps> = ({ graphData }) => {\n // apply the plotted positions\n const graphDimensions = GraphLayout.plot<RendererProps['graphData']>(graphData);\n\n return (\n <StyledWrapper>\n <ConnectorsContainer items={graphData.connectors} dimensions={graphDimensions} />\n <NodesContainer items={graphData.nodes} />\n </StyledWrapper>\n );\n};\n\nexport default Renderer;\n"]}
@@ -0,0 +1,18 @@
1
+ import { ReactNode } from 'react';
2
+ import { GraphData } from './Utils/Graph';
3
+ import { PlottedGraphConnector, PlottedGraphNode } from './Utils/GraphLayout';
4
+ export interface AddNodeHandlerParams {
5
+ refType: 'node' | 'connector';
6
+ refId: string;
7
+ }
8
+ export interface RendererNodeProps extends PlottedGraphNode {
9
+ children: ReactNode;
10
+ }
11
+ export interface RendererConnectorProps extends PlottedGraphConnector {
12
+ children?: ReactNode;
13
+ }
14
+ export interface RendererProps {
15
+ graphData: GraphData<RendererNodeProps, RendererConnectorProps>;
16
+ disableAutoLayout?: boolean;
17
+ }
18
+ //# sourceMappingURL=Renderer.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Renderer.types.d.ts","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Renderer/Renderer.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,GAAG,WAAW,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,sBAAuB,SAAQ,qBAAqB;IACnE,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,SAAS,CAAC,iBAAiB,EAAE,sBAAsB,CAAC,CAAC;IAChE,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Renderer.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Renderer.types.js","sourceRoot":"","sources":["../../../../src/components/FlowModeller/Renderer/Renderer.types.ts"],"names":[],"mappings":"","sourcesContent":["import { ReactNode } from 'react';\n\nimport { GraphData } from './Utils/Graph';\nimport { PlottedGraphConnector, PlottedGraphNode } from './Utils/GraphLayout';\n\nexport interface AddNodeHandlerParams {\n refType: 'node' | 'connector';\n refId: string;\n}\n\nexport interface RendererNodeProps extends PlottedGraphNode {\n children: ReactNode;\n}\n\nexport interface RendererConnectorProps extends PlottedGraphConnector {\n children?: ReactNode;\n}\n\nexport interface RendererProps {\n graphData: GraphData<RendererNodeProps, RendererConnectorProps>;\n disableAutoLayout?: boolean;\n}\n"]}
@@ -0,0 +1,51 @@
1
+ export interface ConnectorProps<T = unknown> {
2
+ id: string;
3
+ fromNodeId: string;
4
+ toNodeId: string;
5
+ label?: string;
6
+ data?: T;
7
+ }
8
+ export interface Node<T = unknown> {
9
+ id: string;
10
+ data?: T;
11
+ }
12
+ export interface GraphData<T extends Node, U extends ConnectorProps> {
13
+ nodes: T[];
14
+ connectors: U[];
15
+ }
16
+ export declare class DirectedGraph<T extends Node = Node, U extends ConnectorProps = ConnectorProps, D1 = unknown, // Can be any here.. because nodeData is optional and each node may need to carry its own Data type.
17
+ D2 = unknown> {
18
+ private nodes;
19
+ private connectors;
20
+ private nodeData;
21
+ private connectorData;
22
+ private inConnectors;
23
+ private prevNodesCount;
24
+ private outConnectors;
25
+ private nextNodesCount;
26
+ private nodeCount;
27
+ private connectorsCount;
28
+ constructor(graphData?: GraphData<T, U>);
29
+ getGraphData(): GraphData<T, U>;
30
+ getNodeCount(): number;
31
+ getNodes(): T[];
32
+ addNode(node: T, data?: D1): DirectedGraph;
33
+ getNode(nodeId: string): T;
34
+ hasNode(nodeId: string): boolean;
35
+ deleteNode(nodeId: string, ignoreConnectors?: boolean): DirectedGraph<T, U>;
36
+ getPrevNodes(nodeId: string): T[];
37
+ getNextNodes(nodeId: string): T[];
38
+ getPrevNodesCount(nodeId: string): number;
39
+ getNextNodesCount(nodeId: string): number;
40
+ isLeaf(nodeId: string): boolean;
41
+ getConnectorsCount(): number;
42
+ getConnectors(): U[];
43
+ addConnector(connector: U, data?: D2): DirectedGraph<T, U>;
44
+ hasConnector(id: string): boolean;
45
+ getConnector(id: string): U;
46
+ removeConnector(id: string): DirectedGraph<T, U>;
47
+ getInConnectors(toNodeId: string, fromNodeId?: string): ConnectorProps[];
48
+ getOutConnectors(fromNodeId: string, toNodeId?: string): ConnectorProps[];
49
+ getAllNodeConnectors(nodeId: string): ConnectorProps<unknown>[] | undefined;
50
+ }
51
+ //# sourceMappingURL=Graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/Graph.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,IAAI,CAAC,CAAC,GAAG,OAAO;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,cAAc;IACjE,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,UAAU,EAAE,CAAC,EAAE,CAAC;CACjB;AAED,qBAAa,aAAa,CACxB,CAAC,SAAS,IAAI,GAAG,IAAI,EACrB,CAAC,SAAS,cAAc,GAAG,cAAc,EACzC,EAAE,GAAG,OAAO,EAAE,oGAAoG;AAClH,EAAE,GAAG,OAAO;IAEZ,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,CAAC,UAAU,CAAyB;IAG3C,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,aAAa,CAAoC;IAEzD,OAAO,CAAC,YAAY,CAAyC;IAC7D,OAAO,CAAC,cAAc,CAA8C;IAEpE,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,cAAc,CAA8C;IAEpE,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MAAM,GAAG,cAAc,EAAE;IAkBzE,oBAAoB,CAAC,MAAM,EAAE,MAAM;CAOpC"}
@@ -0,0 +1,247 @@
1
+ export class DirectedGraph {
2
+ constructor(graphData = { nodes: [], connectors: [] }) {
3
+ Object.defineProperty(this, "nodes", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: {}
8
+ });
9
+ Object.defineProperty(this, "connectors", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: {}
14
+ });
15
+ // additional way to maintain related data - for cases where Graph is used for indirect purposes
16
+ Object.defineProperty(this, "nodeData", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: {}
21
+ });
22
+ Object.defineProperty(this, "connectorData", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: {}
27
+ });
28
+ Object.defineProperty(this, "inConnectors", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: {}
33
+ }); // we are maintaining connector reference instead of id, to avoid iterations later on.
34
+ Object.defineProperty(this, "prevNodesCount", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: {}
39
+ });
40
+ Object.defineProperty(this, "outConnectors", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: {}
45
+ }); // we are maintaining connector reference instead of id, to avoid iterations later on
46
+ Object.defineProperty(this, "nextNodesCount", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: {}
51
+ });
52
+ Object.defineProperty(this, "nodeCount", {
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true,
56
+ value: 0
57
+ });
58
+ Object.defineProperty(this, "connectorsCount", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: 0
63
+ });
64
+ // Not necessary to clone, as this class never modifies any nodes
65
+ graphData.nodes.forEach(item => this.addNode(item));
66
+ // copy/clone, connectors properties 'fromNodeId' and 'toNodeId' values may get modified by this class
67
+ graphData.connectors.forEach(item => this.addConnector(JSON.parse(JSON.stringify(item))));
68
+ }
69
+ getGraphData() {
70
+ return {
71
+ nodes: this.getNodes(),
72
+ connectors: this.getConnectors()
73
+ };
74
+ }
75
+ getNodeCount() {
76
+ return this.nodeCount;
77
+ }
78
+ getNodes() {
79
+ return Object.values(this.nodes);
80
+ }
81
+ addNode(node, data) {
82
+ if (this.nodes[node.id] !== undefined) {
83
+ this.nodes[node.id] = node;
84
+ this.nodeData[node.id] = data;
85
+ }
86
+ else {
87
+ this.nodes[node.id] = node;
88
+ this.nodeData[node.id] = data;
89
+ this.inConnectors[node.id] = {};
90
+ this.prevNodesCount[node.id] = {};
91
+ this.outConnectors[node.id] = {};
92
+ this.nextNodesCount[node.id] = {};
93
+ this.nodeCount += 1;
94
+ }
95
+ return this;
96
+ }
97
+ getNode(nodeId) {
98
+ return this.nodes[nodeId];
99
+ }
100
+ hasNode(nodeId) {
101
+ return this.nodes[nodeId] !== undefined;
102
+ }
103
+ deleteNode(nodeId, ignoreConnectors = false) {
104
+ if (this.hasNode(nodeId)) {
105
+ delete this.nodes[nodeId];
106
+ delete this.nodeData[nodeId];
107
+ if (ignoreConnectors !== true) {
108
+ const removeConnector = (id) => this.removeConnector(id);
109
+ // IMP NOTE its the responsibility of the callee to make sure that the connectors are cleanly reassigned, or else all attached connectors will be deleted
110
+ Object.keys(this.inConnectors[nodeId]).forEach(removeConnector);
111
+ delete this.inConnectors[nodeId];
112
+ delete this.prevNodesCount[nodeId];
113
+ Object.keys(this.outConnectors[nodeId]).forEach(removeConnector);
114
+ delete this.outConnectors[nodeId];
115
+ delete this.nextNodesCount[nodeId];
116
+ }
117
+ this.nodeCount += 1;
118
+ }
119
+ return this;
120
+ }
121
+ getPrevNodes(nodeId) {
122
+ return this.prevNodesCount[nodeId]
123
+ ? Object.keys(this.prevNodesCount[nodeId]).map(id => this.getNode(id))
124
+ : [];
125
+ }
126
+ getNextNodes(nodeId) {
127
+ return this.nextNodesCount[nodeId]
128
+ ? Object.keys(this.nextNodesCount[nodeId]).map(id => this.getNode(id))
129
+ : [];
130
+ }
131
+ getPrevNodesCount(nodeId) {
132
+ return (this.prevNodesCount[nodeId] ? Object.values(this.prevNodesCount[nodeId]) : []).reduce((prev, current) => prev + current, 0);
133
+ }
134
+ getNextNodesCount(nodeId) {
135
+ return (this.nextNodesCount[nodeId] ? Object.values(this.nextNodesCount[nodeId]) : []).reduce((prev, current) => prev + current, 0);
136
+ }
137
+ isLeaf(nodeId) {
138
+ return this.getNextNodes(nodeId).length === 0;
139
+ }
140
+ // -- Connectors
141
+ getConnectorsCount() {
142
+ return this.connectorsCount;
143
+ }
144
+ getConnectors() {
145
+ return Object.values(this.connectors);
146
+ }
147
+ addConnector(connector, data) {
148
+ if (this.connectors[connector.id] !== undefined) {
149
+ // update the map
150
+ this.connectors[connector.id] = connector;
151
+ this.connectorData[connector.id] = data;
152
+ return this;
153
+ }
154
+ const id = connector.id;
155
+ const fromNodeId = connector.fromNodeId;
156
+ const toNodeId = connector.toNodeId;
157
+ // check if nodes with given ids exist
158
+ if (this.nodes[fromNodeId] === undefined || this.nodes[toNodeId] === undefined) {
159
+ throw new Error(`One or more nodes does not exist, cannot add connector ${fromNodeId}-${toNodeId}`);
160
+ }
161
+ // add it to the map
162
+ this.connectors[id] = connector;
163
+ this.connectorData[id] = data;
164
+ // update prev nodes count
165
+ if (this.prevNodesCount[toNodeId][fromNodeId]) {
166
+ this.prevNodesCount[toNodeId][fromNodeId] += 1;
167
+ }
168
+ else {
169
+ this.prevNodesCount[toNodeId][fromNodeId] = 1;
170
+ }
171
+ // update next nodes count
172
+ if (this.nextNodesCount[fromNodeId][toNodeId]) {
173
+ this.nextNodesCount[fromNodeId][toNodeId] += 1;
174
+ }
175
+ else {
176
+ this.nextNodesCount[fromNodeId][toNodeId] = 1;
177
+ }
178
+ // update in and out connectors for both the nodes
179
+ this.inConnectors[toNodeId][id] = connector;
180
+ this.outConnectors[fromNodeId][id] = connector;
181
+ // increment total connectors count
182
+ this.connectorsCount += 1;
183
+ return this;
184
+ }
185
+ hasConnector(id) {
186
+ return this.connectors[id] !== undefined;
187
+ }
188
+ getConnector(id) {
189
+ return this.connectors[id];
190
+ }
191
+ removeConnector(id) {
192
+ const connector = this.connectors[id];
193
+ if (connector !== undefined) {
194
+ const fromNodeId = connector.fromNodeId;
195
+ const toNodeId = connector.toNodeId;
196
+ delete this.connectors[id];
197
+ delete this.connectorData[id];
198
+ // update prev nodes count
199
+ this.prevNodesCount[toNodeId][fromNodeId] -= 1;
200
+ if (this.prevNodesCount[toNodeId][fromNodeId] === 0) {
201
+ delete this.prevNodesCount[toNodeId][fromNodeId];
202
+ }
203
+ // update next nodes count
204
+ this.nextNodesCount[fromNodeId][toNodeId] -= 1;
205
+ if (this.nextNodesCount[fromNodeId][toNodeId] === 0) {
206
+ delete this.nextNodesCount[fromNodeId][toNodeId];
207
+ }
208
+ delete this.inConnectors[toNodeId][id];
209
+ delete this.outConnectors[fromNodeId][id];
210
+ this.connectorsCount -= 1;
211
+ }
212
+ return this;
213
+ }
214
+ getInConnectors(toNodeId, fromNodeId) {
215
+ const allInConnectors = this.inConnectors[toNodeId];
216
+ if (allInConnectors) {
217
+ const connectorValues = Object.values(allInConnectors);
218
+ if (fromNodeId === undefined) {
219
+ return connectorValues;
220
+ }
221
+ return connectorValues.filter(connector => {
222
+ return connector.fromNodeId === fromNodeId;
223
+ });
224
+ }
225
+ return [];
226
+ }
227
+ getOutConnectors(fromNodeId, toNodeId) {
228
+ const allOutConnectors = this.outConnectors[fromNodeId];
229
+ if (allOutConnectors) {
230
+ const connectorValues = Object.values(allOutConnectors);
231
+ if (toNodeId === undefined) {
232
+ return connectorValues;
233
+ }
234
+ return connectorValues.filter(connector => {
235
+ return connector.toNodeId === toNodeId;
236
+ });
237
+ }
238
+ return [];
239
+ }
240
+ getAllNodeConnectors(nodeId) {
241
+ const inConnectors = this.getInConnectors(nodeId);
242
+ if (inConnectors) {
243
+ return inConnectors.concat(this.getOutConnectors(nodeId));
244
+ }
245
+ }
246
+ }
247
+ //# sourceMappingURL=Graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/Graph.ts"],"names":[],"mappings":"AAkBA,MAAM,OAAO,aAAa;IAsBxB,YAAY,YAA6B,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;QAhBtE;;;;mBAAmC,EAAE;WAAC;QACtC;;;;mBAAwC,EAAE;WAAC;QAE3C,gGAAgG;QAChG;;;;mBAAiD,EAAE;WAAC;QACpD;;;;mBAAsD,EAAE;WAAC;QAEzD;;;;mBAA0D,EAAE;WAAC,CAAC,sFAAsF;QACpJ;;;;mBAAiE,EAAE;WAAC;QAEpE;;;;mBAA2D,EAAE;WAAC,CAAC,qFAAqF;QACpJ;;;;mBAAiE,EAAE;WAAC;QAEpE;;;;mBAAoB,CAAC;WAAC;QACtB;;;;mBAA0B,CAAC;WAAC;QAG1B,iEAAiE;QACjE,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,sGAAsG;QACtG,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5F,CAAC;IAED,YAAY;QACV,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE;YACtB,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE;SACjC,CAAC;IACJ,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,QAAQ;QACN,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC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Id: string;\n label?: string;\n data?: T;\n}\n\nexport interface Node<T = unknown> {\n id: string;\n data?: T;\n}\n\nexport interface GraphData<T extends Node, U extends ConnectorProps> {\n nodes: T[];\n connectors: U[];\n}\n\nexport class DirectedGraph<\n T extends Node = Node,\n U extends ConnectorProps = ConnectorProps,\n D1 = unknown, // Can be any here.. because nodeData is optional and each node may need to carry its own Data type.\n D2 = unknown // Can be any here.. because connectorData is optional and each connector may need to carry its own Data type.\n> {\n private nodes: Record<string, T> = {};\n private connectors: Record<string, U> = {};\n\n // additional way to maintain related data - for cases where Graph is used for indirect purposes\n private nodeData: Record<string, D1 | unknown> = {};\n private connectorData: Record<string, D2 | unknown> = {};\n\n private inConnectors: Record<string, Record<string, U>> = {}; // we are maintaining connector reference instead of id, to avoid iterations later on.\n private prevNodesCount: Record<string, Record<string, number>> = {};\n\n private outConnectors: Record<string, Record<string, U>> = {}; // we are maintaining connector reference instead of id, to avoid iterations later on\n private nextNodesCount: Record<string, Record<string, number>> = {};\n\n private nodeCount = 0;\n private connectorsCount = 0;\n\n constructor(graphData: GraphData<T, U> = { nodes: [], connectors: [] }) {\n // Not necessary to clone, as this class never modifies any nodes\n graphData.nodes.forEach(item => this.addNode(item));\n // copy/clone, connectors properties 'fromNodeId' and 'toNodeId' values may get modified by this class\n graphData.connectors.forEach(item => this.addConnector(JSON.parse(JSON.stringify(item))));\n }\n\n getGraphData(): GraphData<T, U> {\n return {\n nodes: this.getNodes(),\n connectors: this.getConnectors()\n };\n }\n\n getNodeCount(): number {\n return this.nodeCount;\n }\n\n getNodes() {\n return Object.values(this.nodes);\n }\n\n addNode(node: T, data?: D1): DirectedGraph {\n if (this.nodes[node.id] !== undefined) {\n this.nodes[node.id] = node;\n this.nodeData[node.id] = data;\n } else {\n this.nodes[node.id] = node;\n this.nodeData[node.id] = data;\n\n this.inConnectors[node.id] = {};\n this.prevNodesCount[node.id] = {};\n\n this.outConnectors[node.id] = {};\n this.nextNodesCount[node.id] = {};\n\n this.nodeCount += 1;\n }\n\n return this;\n }\n\n getNode(nodeId: string): T {\n return this.nodes[nodeId];\n }\n\n hasNode(nodeId: string): boolean {\n return this.nodes[nodeId] !== undefined;\n }\n\n deleteNode(nodeId: string, ignoreConnectors = false): DirectedGraph<T, U> {\n if (this.hasNode(nodeId)) {\n delete this.nodes[nodeId];\n delete this.nodeData[nodeId];\n\n if (ignoreConnectors !== true) {\n const removeConnector = (id: string) => this.removeConnector(id);\n\n // IMP NOTE its the responsibility of the callee to make sure that the connectors are cleanly reassigned, or else all attached connectors will be deleted\n\n Object.keys(this.inConnectors[nodeId]).forEach(removeConnector);\n delete this.inConnectors[nodeId];\n delete this.prevNodesCount[nodeId];\n\n Object.keys(this.outConnectors[nodeId]).forEach(removeConnector);\n delete this.outConnectors[nodeId];\n delete this.nextNodesCount[nodeId];\n }\n\n this.nodeCount += 1;\n }\n\n return this;\n }\n\n getPrevNodes(nodeId: string): T[] {\n return this.prevNodesCount[nodeId]\n ? Object.keys(this.prevNodesCount[nodeId]).map(id => this.getNode(id))\n : [];\n }\n\n getNextNodes(nodeId: string): T[] {\n return this.nextNodesCount[nodeId]\n ? Object.keys(this.nextNodesCount[nodeId]).map(id => this.getNode(id))\n : [];\n }\n\n getPrevNodesCount(nodeId: string): number {\n return (this.prevNodesCount[nodeId] ? Object.values(this.prevNodesCount[nodeId]) : []).reduce(\n (prev, current) => prev + current,\n 0\n );\n }\n\n getNextNodesCount(nodeId: string): number {\n return (this.nextNodesCount[nodeId] ? Object.values(this.nextNodesCount[nodeId]) : []).reduce(\n (prev, current) => prev + current,\n 0\n );\n }\n\n isLeaf(nodeId: string): boolean {\n return this.getNextNodes(nodeId).length === 0;\n }\n\n // -- Connectors\n getConnectorsCount(): number {\n return this.connectorsCount;\n }\n\n getConnectors() {\n return Object.values(this.connectors);\n }\n\n addConnector(connector: U, data?: D2): DirectedGraph<T, U> {\n if (this.connectors[connector.id] !== undefined) {\n // update the map\n this.connectors[connector.id] = connector;\n this.connectorData[connector.id] = data;\n\n return this;\n }\n\n const id = connector.id;\n const fromNodeId = connector.fromNodeId;\n const toNodeId = connector.toNodeId;\n\n // check if nodes with given ids exist\n if (this.nodes[fromNodeId] === undefined || this.nodes[toNodeId] === undefined) {\n throw new Error(\n `One or more nodes does not exist, cannot add connector ${fromNodeId}-${toNodeId}`\n );\n }\n\n // add it to the map\n this.connectors[id] = connector;\n this.connectorData[id] = data;\n\n // update prev nodes count\n if (this.prevNodesCount[toNodeId][fromNodeId]) {\n this.prevNodesCount[toNodeId][fromNodeId] += 1;\n } else {\n this.prevNodesCount[toNodeId][fromNodeId] = 1;\n }\n\n // update next nodes count\n if (this.nextNodesCount[fromNodeId][toNodeId]) {\n this.nextNodesCount[fromNodeId][toNodeId] += 1;\n } else {\n this.nextNodesCount[fromNodeId][toNodeId] = 1;\n }\n\n // update in and out connectors for both the nodes\n this.inConnectors[toNodeId][id] = connector;\n this.outConnectors[fromNodeId][id] = connector;\n\n // increment total connectors count\n this.connectorsCount += 1;\n\n return this;\n }\n\n hasConnector(id: string): boolean {\n return this.connectors[id] !== undefined;\n }\n\n getConnector(id: string): U {\n return this.connectors[id];\n }\n\n removeConnector(id: string): DirectedGraph<T, U> {\n const connector = this.connectors[id];\n\n if (connector !== undefined) {\n const fromNodeId = connector.fromNodeId;\n const toNodeId = connector.toNodeId;\n\n delete this.connectors[id];\n delete this.connectorData[id];\n\n // update prev nodes count\n this.prevNodesCount[toNodeId][fromNodeId] -= 1;\n if (this.prevNodesCount[toNodeId][fromNodeId] === 0) {\n delete this.prevNodesCount[toNodeId][fromNodeId];\n }\n\n // update next nodes count\n this.nextNodesCount[fromNodeId][toNodeId] -= 1;\n if (this.nextNodesCount[fromNodeId][toNodeId] === 0) {\n delete this.nextNodesCount[fromNodeId][toNodeId];\n }\n\n delete this.inConnectors[toNodeId][id];\n delete this.outConnectors[fromNodeId][id];\n\n this.connectorsCount -= 1;\n }\n\n return this;\n }\n\n getInConnectors(toNodeId: string, fromNodeId?: string): ConnectorProps[] {\n const allInConnectors = this.inConnectors[toNodeId];\n\n if (allInConnectors) {\n const connectorValues = Object.values(allInConnectors);\n\n if (fromNodeId === undefined) {\n return connectorValues;\n }\n\n return connectorValues.filter(connector => {\n return connector.fromNodeId === fromNodeId;\n });\n }\n\n return [];\n }\n\n getOutConnectors(fromNodeId: string, toNodeId?: string): ConnectorProps[] {\n const allOutConnectors = this.outConnectors[fromNodeId];\n\n if (allOutConnectors) {\n const connectorValues = Object.values(allOutConnectors);\n\n if (toNodeId === undefined) {\n return connectorValues;\n }\n\n return connectorValues.filter(connector => {\n return connector.toNodeId === toNodeId;\n });\n }\n\n return [];\n }\n\n getAllNodeConnectors(nodeId: string) {\n const inConnectors = this.getInConnectors(nodeId);\n\n if (inConnectors) {\n return inConnectors.concat(this.getOutConnectors(nodeId));\n }\n }\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { ConnectorProps, GraphData, Node } from './Graph';
2
+ export interface PlottedGraphNode<T = any> extends Node<T> {
3
+ dimensions: {
4
+ width: number;
5
+ height: number;
6
+ };
7
+ position: {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ }
12
+ export interface PlottedGraphConnector<T = any> extends ConnectorProps<T> {
13
+ points: {
14
+ x: number;
15
+ y: number;
16
+ }[];
17
+ labelLayout?: {
18
+ value: any;
19
+ width: number;
20
+ height: number;
21
+ x: number;
22
+ y: number;
23
+ };
24
+ }
25
+ export declare enum GraphLayoutDirection {
26
+ LeftToRight = "LR",
27
+ TopToBottom = "TB"
28
+ }
29
+ export default class GraphLayout {
30
+ static plot<T extends GraphData<PlottedGraphNode, PlottedGraphConnector>>(graphData: T, direction?: GraphLayoutDirection): {
31
+ width: number;
32
+ height: number;
33
+ };
34
+ }
35
+ //# sourceMappingURL=GraphLayout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphLayout.d.ts","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/GraphLayout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE1D,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,IAAI,CAAC,CAAC,CAAC;IACxD,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,EAAE;QACR,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IACvE,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnC,WAAW,CAAC,EAAE;QACZ,KAAK,EAAE,GAAG,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;CACH;AAED,oBAAY,oBAAoB;IAC9B,WAAW,OAAO;IAClB,WAAW,OAAO;CACnB;AAKD,MAAM,CAAC,OAAO,OAAO,WAAW;IAE9B,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,SAAS,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,EACtE,SAAS,EAAE,CAAC,EACZ,SAAS,GAAE,oBAAuD;;;;CA8GrE"}
@@ -0,0 +1,104 @@
1
+ import dagre from 'dagre';
2
+ export var GraphLayoutDirection;
3
+ (function (GraphLayoutDirection) {
4
+ GraphLayoutDirection["LeftToRight"] = "LR";
5
+ GraphLayoutDirection["TopToBottom"] = "TB";
6
+ })(GraphLayoutDirection || (GraphLayoutDirection = {}));
7
+ const DEFAULT_GRAPH_WIDTH = 2000;
8
+ const DEFAULT_GRAPH_HEIGHT = 2000;
9
+ export default class GraphLayout {
10
+ // Using Dagre layouting
11
+ static plot(graphData, direction = GraphLayoutDirection.TopToBottom) {
12
+ const dagreGraph = new dagre.graphlib.Graph();
13
+ dagreGraph.setDefaultEdgeLabel(() => ({}));
14
+ const defaultNodeWidth = 280;
15
+ const defaultNodeHeight = 112;
16
+ dagreGraph.setGraph({
17
+ rankdir: direction,
18
+ ranksep: 10,
19
+ edgesep: defaultNodeWidth / 2,
20
+ nodesep: 40,
21
+ // cspell:disable-next
22
+ marginx: 200,
23
+ // cspell:disable-next
24
+ marginy: 50
25
+ });
26
+ graphData.nodes.forEach(node => {
27
+ dagreGraph.setNode(node.id, {
28
+ width: node.dimensions.width ? node.dimensions.width : defaultNodeWidth,
29
+ height: node.dimensions.height ? node.dimensions.height : defaultNodeHeight
30
+ });
31
+ });
32
+ graphData.connectors.forEach(con => {
33
+ dagreGraph.setEdge(con.fromNodeId, con.toNodeId, {
34
+ weight: 1,
35
+ minlen: 1,
36
+ label: con.data?.label,
37
+ width: 200,
38
+ height: 60,
39
+ // cspell:disable-next
40
+ lablepos: 'c',
41
+ labeloffset: 0
42
+ });
43
+ });
44
+ dagre.layout(dagreGraph, {});
45
+ graphData.nodes.forEach(el => {
46
+ const node = dagreGraph.node(el.id);
47
+ el.position.x = node.x - el.dimensions.width / 2;
48
+ el.position.y = node.y - el.dimensions.height / 2;
49
+ });
50
+ graphData.connectors.forEach(con => {
51
+ const edge = dagreGraph.edge(con.fromNodeId, con.toNodeId);
52
+ con.labelLayout = {
53
+ value: edge.label,
54
+ x: edge.x,
55
+ y: edge.y - 10,
56
+ width: edge.width,
57
+ height: edge.height
58
+ };
59
+ const lastIndex = edge.points.length - 1;
60
+ let firstPoint = edge.points[0];
61
+ const secondPoint = edge.points[1];
62
+ let lastPoint = edge.points[lastIndex];
63
+ const secondLastPoint = edge.points[lastIndex - 1];
64
+ const fromNode = dagreGraph.node(con.fromNodeId);
65
+ const toNode = dagreGraph.node(con.toNodeId);
66
+ firstPoint =
67
+ firstPoint.x !== secondPoint.x
68
+ ? {
69
+ ...edge.points[0],
70
+ x: fromNode.x,
71
+ y: edge.points[1].y
72
+ }
73
+ : firstPoint;
74
+ lastPoint =
75
+ lastPoint.x !== secondLastPoint.x
76
+ ? {
77
+ ...edge.points[lastIndex],
78
+ x: toNode.x,
79
+ y: edge.points[lastIndex - 1].y
80
+ }
81
+ : lastPoint;
82
+ con.points = [
83
+ { x: fromNode.x, y: fromNode.y + fromNode.height / 2 },
84
+ firstPoint,
85
+ ...edge.points.slice(1, lastIndex),
86
+ lastPoint,
87
+ { x: toNode.x, y: toNode.y }
88
+ ];
89
+ });
90
+ const width = dagreGraph.graph().width;
91
+ const height = dagreGraph.graph().height;
92
+ if (width !== undefined && height !== undefined) {
93
+ return {
94
+ width: Number.isFinite(width) ? width : DEFAULT_GRAPH_WIDTH,
95
+ height: Number.isFinite(height) ? height : DEFAULT_GRAPH_HEIGHT
96
+ };
97
+ }
98
+ return {
99
+ width: DEFAULT_GRAPH_WIDTH,
100
+ height: DEFAULT_GRAPH_HEIGHT
101
+ };
102
+ }
103
+ }
104
+ //# sourceMappingURL=GraphLayout.js.map
@@ -0,0 +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,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AAK,SAAS,EAAE;YAC/C,OAAO;gBACL,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,mBAAmB;gBAC3D,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB;aAChE,CAAC;SACH;QAED,OAAO;YACL,KAAK,EAAE,mBAAmB;YAC1B,MAAM,EAAE,oBAAoB;SAC7B,CAAC;IACJ,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();\n\n dagreGraph.setDefaultEdgeLabel(() => ({}));\n\n const defaultNodeWidth = 280;\n const defaultNodeHeight = 112;\n\n dagreGraph.setGraph({\n rankdir: direction,\n ranksep: 10,\n edgesep: defaultNodeWidth / 2,\n nodesep: 40,\n // cspell:disable-next\n marginx: 200,\n // cspell:disable-next\n marginy: 50\n });\n\n graphData.nodes.forEach(node => {\n dagreGraph.setNode(node.id, {\n width: node.dimensions.width ? node.dimensions.width : defaultNodeWidth,\n height: node.dimensions.height ? node.dimensions.height : defaultNodeHeight\n });\n });\n\n graphData.connectors.forEach(con => {\n dagreGraph.setEdge(con.fromNodeId, con.toNodeId, {\n weight: 1,\n minlen: 1,\n label: con.data?.label,\n width: 200,\n height: 60,\n // cspell:disable-next\n lablepos: 'c',\n labeloffset: 0\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 => {\n const edge = dagreGraph.edge(con.fromNodeId, con.toNodeId);\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,\n ...edge.points.slice(1, 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"]}