react-cosmos-diagram 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -0
- package/dist/esm/components/ConnectionEdge/ConnectionPath.d.ts +4 -1
- package/dist/esm/components/ConnectionEdge/ConnectionPath.d.ts.map +1 -1
- package/dist/esm/components/ConnectionEdge/index.d.ts +4 -1
- package/dist/esm/components/ConnectionEdge/index.d.ts.map +1 -1
- package/dist/esm/components/ConnectionEdge/type.d.ts +22 -0
- package/dist/esm/components/ConnectionEdge/type.d.ts.map +1 -0
- package/dist/esm/components/Edges/EdgeWrapper/type.d.ts +1 -1
- package/dist/esm/components/Edges/EdgeWrapper/type.d.ts.map +1 -1
- package/dist/esm/container/EdgeRenderer/index.d.ts +2 -3
- package/dist/esm/container/EdgeRenderer/index.d.ts.map +1 -1
- package/dist/esm/container/ReactDiagram/DiagramView.d.ts +1 -1
- package/dist/esm/container/ReactDiagram/DiagramView.d.ts.map +1 -1
- package/dist/esm/container/ReactDiagram/index.d.ts +4 -0
- package/dist/esm/container/ReactDiagram/index.d.ts.map +1 -1
- package/dist/esm/index.d.ts +4 -6
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +125 -89
- package/dist/esm/types/core.d.ts +6 -2
- package/dist/esm/types/core.d.ts.map +1 -1
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/utils/graph.d.ts +1 -1
- package/dist/esm/utils/graph.d.ts.map +1 -1
- package/dist/style.css +33 -1
- package/dist/umd/components/ConnectionEdge/ConnectionPath.d.ts +4 -1
- package/dist/umd/components/ConnectionEdge/ConnectionPath.d.ts.map +1 -1
- package/dist/umd/components/ConnectionEdge/index.d.ts +4 -1
- package/dist/umd/components/ConnectionEdge/index.d.ts.map +1 -1
- package/dist/umd/components/ConnectionEdge/type.d.ts +22 -0
- package/dist/umd/components/ConnectionEdge/type.d.ts.map +1 -0
- package/dist/umd/components/Edges/EdgeWrapper/type.d.ts +1 -1
- package/dist/umd/components/Edges/EdgeWrapper/type.d.ts.map +1 -1
- package/dist/umd/container/EdgeRenderer/index.d.ts +2 -3
- package/dist/umd/container/EdgeRenderer/index.d.ts.map +1 -1
- package/dist/umd/container/ReactDiagram/DiagramView.d.ts +1 -1
- package/dist/umd/container/ReactDiagram/DiagramView.d.ts.map +1 -1
- package/dist/umd/container/ReactDiagram/index.d.ts +4 -0
- package/dist/umd/container/ReactDiagram/index.d.ts.map +1 -1
- package/dist/umd/index.d.ts +4 -6
- package/dist/umd/index.d.ts.map +1 -1
- package/dist/umd/index.js +2 -2
- package/dist/umd/types/core.d.ts +6 -2
- package/dist/umd/types/core.d.ts.map +1 -1
- package/dist/umd/types/index.d.ts +1 -0
- package/dist/umd/types/index.d.ts.map +1 -1
- package/dist/umd/utils/graph.d.ts +1 -1
- package/dist/umd/utils/graph.d.ts.map +1 -1
- package/package.json +2 -3
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
## Installation
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npm install react-cosmos-diagram
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
## Core characteristics
|
|
8
|
+
|
|
9
|
+
- Easy zooming and panning, single and multiple selection of graph elements and keyboard shortcuts are supported natively
|
|
10
|
+
- Customizable support for nodes, ports, and edges
|
|
11
|
+
- Written in [Typescript](https://www.typescriptlang.org/)
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import { useCallback, useRef } from 'react';
|
|
17
|
+
|
|
18
|
+
import ReactDiagram, {
|
|
19
|
+
useNodesState,
|
|
20
|
+
useEdgesState,
|
|
21
|
+
addEdge,
|
|
22
|
+
updateEdge,
|
|
23
|
+
Connection,
|
|
24
|
+
Edge,
|
|
25
|
+
MarkerType,
|
|
26
|
+
} from 'react-cosmos-diagram';
|
|
27
|
+
|
|
28
|
+
import 'react-cosmos-diagram/styles/style.css';
|
|
29
|
+
|
|
30
|
+
const initialNodes = [
|
|
31
|
+
{
|
|
32
|
+
id: '1',
|
|
33
|
+
width: 200,
|
|
34
|
+
height: 100,
|
|
35
|
+
data: { label: 'Node1' },
|
|
36
|
+
position: { x: 100, y: 100 },
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: '2',
|
|
40
|
+
data: { label: 'Node2' },
|
|
41
|
+
position: { x: 300, y: 50 },
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: '3',
|
|
45
|
+
data: { label: 'Node3' },
|
|
46
|
+
position: { x: 10, y: 10 },
|
|
47
|
+
parentNode: '1',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: '4',
|
|
51
|
+
data: { label: 'Node4' },
|
|
52
|
+
position: { x: 650, y: 100 },
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const initialEdges = [
|
|
57
|
+
{
|
|
58
|
+
id: 'e-1-2',
|
|
59
|
+
type: 'bezier',
|
|
60
|
+
source: '1',
|
|
61
|
+
target: '2',
|
|
62
|
+
markerStart: {
|
|
63
|
+
type: MarkerType.Arrow,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'e-2-3',
|
|
68
|
+
source: '2',
|
|
69
|
+
target: '3',
|
|
70
|
+
markerEnd: {
|
|
71
|
+
type: MarkerType.Arrow,
|
|
72
|
+
},
|
|
73
|
+
type: 'step',
|
|
74
|
+
label: 'label',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'e-3-4',
|
|
78
|
+
type: 'c',
|
|
79
|
+
source: '3',
|
|
80
|
+
target: '4',
|
|
81
|
+
markerEnd: {
|
|
82
|
+
type: MarkerType.Arrow,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
function Diagram() {
|
|
88
|
+
const edgeConnected = useRef(true);
|
|
89
|
+
|
|
90
|
+
const [nodes, _setNodes, onNodesChange] = useNodesState(initialNodes);
|
|
91
|
+
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
|
92
|
+
|
|
93
|
+
const onConnect = useCallback(
|
|
94
|
+
(params: Connection) => setEdges((edges) => addEdge({ ...params }, edges)),
|
|
95
|
+
[],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const onEdgeUpdateStart = useCallback(() => {
|
|
99
|
+
edgeConnected.current = false;
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
const onEdgeUpdateEnd = useCallback((_e: any, edge: Edge) => {
|
|
103
|
+
if (!edgeConnected.current) {
|
|
104
|
+
setEdges((edges) => edges.filter((e) => e.id !== edge.id));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
edgeConnected.current = true;
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
const onEdgeUpdate = useCallback(
|
|
111
|
+
(originEdge: Edge, newConnection: Connection) => {
|
|
112
|
+
edgeConnected.current = true;
|
|
113
|
+
setEdges((edges) => updateEdge(originEdge, newConnection, edges));
|
|
114
|
+
},
|
|
115
|
+
[],
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<ReactDiagram
|
|
120
|
+
nodes={nodes}
|
|
121
|
+
edges={edges}
|
|
122
|
+
onNodesChange={onNodesChange}
|
|
123
|
+
onEdgesChange={onEdgesChange}
|
|
124
|
+
onConnect={onConnect}
|
|
125
|
+
onEdgeUpdateStart={onEdgeUpdateStart}
|
|
126
|
+
onEdgeUpdateEnd={onEdgeUpdateEnd}
|
|
127
|
+
onEdgeUpdate={onEdgeUpdate}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default Diagram;
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Credits
|
|
137
|
+
|
|
138
|
+
Under the hood, React Cosmos Diagram depends on these great libraries:
|
|
139
|
+
|
|
140
|
+
- [d3-zoom](https://github.com/d3/d3-zoom) - used for zoom, pan and drag interactions with the graph canvas
|
|
141
|
+
- [d3-drag](https://github.com/d3/d3-drag) - used for making the nodes draggable
|
|
142
|
+
- [zustand](https://github.com/pmndrs/zustand) - internal state management
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
React Cosmos Diagram is [MIT licensed](https://github.com/taehunlim/react-diagram/blob/main/LICENSE).
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
2
|
import { PortType } from '../Port/type';
|
|
3
|
+
import { ConnectionEdgeComponent, ConnectionEdgeType } from './type';
|
|
3
4
|
type ConnectionPathProps = {
|
|
4
5
|
style?: CSSProperties;
|
|
5
6
|
nodeId: string;
|
|
6
7
|
portType: PortType;
|
|
8
|
+
type?: ConnectionEdgeType;
|
|
9
|
+
Component?: ConnectionEdgeComponent;
|
|
7
10
|
};
|
|
8
|
-
declare function ConnectionPath({ style, nodeId, portType }: ConnectionPathProps): import("react/jsx-runtime").JSX.Element | null;
|
|
11
|
+
declare function ConnectionPath({ style, nodeId, portType, type, Component, }: ConnectionPathProps): import("react/jsx-runtime").JSX.Element | null;
|
|
9
12
|
declare namespace ConnectionPath {
|
|
10
13
|
var displayName: string;
|
|
11
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionPath.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/components/ConnectionEdge/ConnectionPath.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ConnectionPath.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/components/ConnectionEdge/ConnectionPath.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,OAAO,CAAC;AAanD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAErE,KAAK,mBAAmB,GAAG;IACxB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,SAAS,CAAC,EAAE,uBAAuB,CAAC;CACtC,CAAC;AASF,iBAAS,cAAc,CAAC,EACrB,KAAK,EACL,MAAM,EACN,QAAQ,EACR,IAAkC,EAClC,SAAS,GACX,EAAE,mBAAmB,kDAoFrB;kBA1FQ,cAAc;;;AA8FvB,eAAe,cAAc,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
|
+
import { ConnectionEdgeComponent, ConnectionEdgeType } from './type';
|
|
2
3
|
type ConnectionEdgeProps = {
|
|
3
4
|
containerStyle?: CSSProperties;
|
|
4
5
|
style?: CSSProperties;
|
|
6
|
+
type?: ConnectionEdgeType;
|
|
7
|
+
component?: ConnectionEdgeComponent;
|
|
5
8
|
};
|
|
6
|
-
declare function ConnectionEdge({ containerStyle, style }: ConnectionEdgeProps): import("react/jsx-runtime").JSX.Element | null;
|
|
9
|
+
declare function ConnectionEdge({ containerStyle, style, type, component, }: ConnectionEdgeProps): import("react/jsx-runtime").JSX.Element | null;
|
|
7
10
|
export default ConnectionEdge;
|
|
8
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/components/ConnectionEdge/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/components/ConnectionEdge/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAQtC,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAErE,KAAK,mBAAmB,GAAG;IACxB,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,SAAS,CAAC,EAAE,uBAAuB,CAAC;CACtC,CAAC;AAQF,iBAAS,cAAc,CAAC,EACrB,cAAc,EACd,KAAK,EACL,IAAI,EACJ,SAAS,GACX,EAAE,mBAAmB,kDAkDrB;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentType, CSSProperties } from 'react';
|
|
2
|
+
import { Node, Position } from '../../types';
|
|
3
|
+
import { PortElement } from '../Port/type';
|
|
4
|
+
export declare enum ConnectionEdgeType {
|
|
5
|
+
Straight = "straight",
|
|
6
|
+
Bezier = "bezier",
|
|
7
|
+
Step = "step"
|
|
8
|
+
}
|
|
9
|
+
export type ConnectionEdgeComponentProps = {
|
|
10
|
+
connectionEdgeStyle?: CSSProperties;
|
|
11
|
+
connectionEdgeType: ConnectionEdgeType;
|
|
12
|
+
fromNode?: Node;
|
|
13
|
+
fromPort?: PortElement;
|
|
14
|
+
fromX: number;
|
|
15
|
+
fromY: number;
|
|
16
|
+
toX: number;
|
|
17
|
+
toY: number;
|
|
18
|
+
fromPosition: Position;
|
|
19
|
+
toPosition: Position;
|
|
20
|
+
};
|
|
21
|
+
export type ConnectionEdgeComponent = ComponentType<ConnectionEdgeComponentProps>;
|
|
22
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/components/ConnectionEdge/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,oBAAY,kBAAkB;IAC3B,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,IAAI,SAAS;CACf;AAED,MAAM,MAAM,4BAA4B,GAAG;IACxC,mBAAmB,CAAC,EAAE,aAAa,CAAC;IACpC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,QAAQ,CAAC;IACvB,UAAU,EAAE,QAAQ,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAChC,aAAa,CAAC,4BAA4B,CAAC,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { Position, Connection } from '../../../types';
|
|
|
3
3
|
import { PortType } from '../../Port/type';
|
|
4
4
|
import { Edge } from '../type';
|
|
5
5
|
export type EdgeMouseHandler = (event: ReactMouseEvent, edge: Edge) => void;
|
|
6
|
-
export type OnEdgeUpdateFunc<T = any> = (
|
|
6
|
+
export type OnEdgeUpdateFunc<T = any> = (originEdge: Edge<T>, newConnection: Connection) => void;
|
|
7
7
|
export type WrapEdgeProps<T = any> = Edge<T> & {
|
|
8
8
|
sourceX: number;
|
|
9
9
|
sourceY: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../react-diagram/packages/src/components/Edges/EdgeWrapper/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;AAE5E,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,GAAG,IAAI,CACrC,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../react-diagram/packages/src/components/Edges/EdgeWrapper/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;AAE5E,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,GAAG,IAAI,CACrC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,EACnB,aAAa,EAAE,UAAU,KACvB,IAAI,CAAC;AAEV,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,QAAQ,CAAC;IACzB,cAAc,EAAE,QAAQ,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;IAErB,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,aAAa,CAAC,EAAE,gBAAgB,CAAC;IACjC,aAAa,CAAC,EAAE,gBAAgB,CAAC;IACjC,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAEhC,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,iBAAiB,CAAC,EAAE,CACjB,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,KAChB,IAAI,CAAC;IACV,eAAe,CAAC,EAAE,CACf,KAAK,EAAE,UAAU,GAAG,UAAU,EAC9B,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,KAChB,IAAI,CAAC;CACZ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { ReactDiagramState } from '../../components/ReactDiagramProvider/type';
|
|
3
3
|
import { ReactDiagramProps } from '../../types';
|
|
4
4
|
import { EdgeTypesWrapped } from './type';
|
|
@@ -6,9 +6,8 @@ type GraphViewEdgeProps = Pick<ReactDiagramState, 'rfId'> & Pick<ReactDiagramPro
|
|
|
6
6
|
type RequiredProps = Required<Pick<ReactDiagramProps, 'noPanClassName'>>;
|
|
7
7
|
type EdgeRendererProps = GraphViewEdgeProps & RequiredProps & {
|
|
8
8
|
edgeTypes: EdgeTypesWrapped;
|
|
9
|
-
children: ReactNode;
|
|
10
9
|
};
|
|
11
|
-
declare function EdgeRenderer({ rfId, edgeTypes,
|
|
10
|
+
declare function EdgeRenderer({ rfId, edgeTypes, noPanClassName, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd, }: EdgeRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
12
11
|
declare namespace EdgeRenderer {
|
|
13
12
|
var displayName: string;
|
|
14
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/container/EdgeRenderer/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/container/EdgeRenderer/index.tsx"],"names":[],"mappings":";AAYA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAY,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAE1C,KAAK,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,GACtD,IAAI,CACD,iBAAiB,EACf,aAAa,GACb,mBAAmB,GACnB,mBAAmB,GACnB,kBAAkB,GAClB,iBAAiB,GACjB,kBAAkB,GAClB,cAAc,GACd,mBAAmB,GACnB,iBAAiB,CACrB,CAAC;AAEL,KAAK,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEzE,KAAK,iBAAiB,GAAG,kBAAkB,GACxC,aAAa,GAAG;IACb,SAAS,EAAE,gBAAgB,CAAC;CAC9B,CAAC;AAUL,iBAAS,YAAY,CAAC,EACnB,IAAI,EACJ,SAAS,EACT,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,eAAe,GACjB,EAAE,iBAAiB,2CA6InB;kBA1JQ,YAAY;;;;AA8JrB,wBAAkC"}
|
|
@@ -8,7 +8,7 @@ export type DiagramViewProps = ReactDiagramCommonProps & Required<Pick<ReactDiag
|
|
|
8
8
|
edgeTypes: EdgeTypesWrapped;
|
|
9
9
|
rfId: string;
|
|
10
10
|
};
|
|
11
|
-
declare function DiagramView({ rfId, noPanClassName, panning, defaultViewport, multiSelectionKeyCode, onMove, onMoveStart, onMoveEnd, onlyRenderVisibleElements, disableKeyboardA11y, noDragClassName, nodeOrigin, nodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave, edgeTypes, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd, }: DiagramViewProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare function DiagramView({ rfId, noPanClassName, panning, defaultViewport, multiSelectionKeyCode, onMove, onMoveStart, onMoveEnd, onlyRenderVisibleElements, disableKeyboardA11y, noDragClassName, nodeOrigin, nodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave, edgeTypes, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd, connectionEdgeContainerStyle, connectionEdgeStyle, connectionEdgeType, connectionEdgeComponent, }: DiagramViewProps): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
declare namespace DiagramView {
|
|
13
13
|
var displayName: string;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagramView.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/container/ReactDiagram/DiagramView.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACvC,iBAAiB,EACjB,OAAO,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,CAC/C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,uBAAuB,GACnD,QAAQ,CACL,IAAI,CACD,iBAAiB,EACf,SAAS,GACT,iBAAiB,GACjB,2BAA2B,GAC3B,qBAAqB,GACrB,iBAAiB,GACjB,gBAAgB,GAChB,YAAY,CAChB,CACH,GAAG;IACD,SAAS,EAAE,gBAAgB,CAAC;IAC5B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;CACf,CAAC;AAEL,iBAAS,WAAW,CAAC,EAClB,IAAI,EAIJ,cAAc,EACd,OAAO,EAEP,eAAe,EAEf,qBAAqB,EAErB,MAAM,EACN,WAAW,EACX,SAAS,EAGT,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAGhB,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,eAAe,
|
|
1
|
+
{"version":3,"file":"DiagramView.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/container/ReactDiagram/DiagramView.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACvC,iBAAiB,EACjB,OAAO,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,CAC/C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,uBAAuB,GACnD,QAAQ,CACL,IAAI,CACD,iBAAiB,EACf,SAAS,GACT,iBAAiB,GACjB,2BAA2B,GAC3B,qBAAqB,GACrB,iBAAiB,GACjB,gBAAgB,GAChB,YAAY,CAChB,CACH,GAAG;IACD,SAAS,EAAE,gBAAgB,CAAC;IAC5B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;CACf,CAAC;AAEL,iBAAS,WAAW,CAAC,EAClB,IAAI,EAIJ,cAAc,EACd,OAAO,EAEP,eAAe,EAEf,qBAAqB,EAErB,MAAM,EACN,WAAW,EACX,SAAS,EAGT,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAGhB,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,eAAe,EAGf,4BAA4B,EAC5B,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,GACzB,EAAE,gBAAgB,2CAgDlB;kBA9FQ,WAAW;;;;AAkGpB,wBAAiC"}
|
|
@@ -14,6 +14,10 @@ declare const ReactDiagram: import("react").ForwardRefExoticComponent<import("re
|
|
|
14
14
|
nodeTypes?: NodeTypes | undefined;
|
|
15
15
|
edges?: import("../../types").Edge<any>[] | undefined;
|
|
16
16
|
edgeTypes?: EdgeTypes | undefined;
|
|
17
|
+
connectionEdgeContainerStyle?: import("react").CSSProperties | undefined;
|
|
18
|
+
connectionEdgeStyle?: import("react").CSSProperties | undefined;
|
|
19
|
+
connectionEdgeType?: import("../../types").ConnectionEdgeType | undefined;
|
|
20
|
+
connectionEdgeComponent?: import("../../types").ConnectionEdgeComponent | undefined;
|
|
17
21
|
onNodesChange?: import("../../types").OnNodesChange | undefined;
|
|
18
22
|
onNodeClick?: import("../../components/Node/NodeWrapper/type").NodeMouseHandler | undefined;
|
|
19
23
|
onNodeDoubleClick?: import("../../components/Node/NodeWrapper/type").NodeMouseHandler | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/container/ReactDiagram/index.tsx"],"names":[],"mappings":";AAeA,OAAO,EAA0C,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAazD,QAAA,MAAM,YAAY
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../react-diagram/packages/src/container/ReactDiagram/index.tsx"],"names":[],"mappings":";AAeA,OAAO,EAA0C,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAazD,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kDAyIjB,CAAC;AAIF,eAAe,YAAY,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import ReactDiagram from './container/ReactDiagram';
|
|
2
2
|
export { default as ReactDiagramProvider } from './components/ReactDiagramProvider';
|
|
3
3
|
export { default as Port } from './components/Port';
|
|
4
4
|
export { default as BaseEdge } from './components/Edges/BaseEdge';
|
|
5
5
|
export { default as StepEdge, getStepPath } from './components/Edges/StepEdge';
|
|
6
|
+
export { default as BezierEdge, getBezierPath, } from './components/Edges/BezierEdge';
|
|
6
7
|
export * from './hooks/useNodesEdgesState';
|
|
7
|
-
export { useStore, useStoreApi } from './hooks/useStore';
|
|
8
|
-
export { default as useGetPointerPosition } from './hooks/useGetPointerPosition';
|
|
9
|
-
export { useNodeId } from './contexts/NodeIdContext';
|
|
10
8
|
export { internalsSymbol, rectToBox, boxToRect, clamp } from './utils';
|
|
11
|
-
export { isNode, isEdge, addEdge, updateEdge,
|
|
12
|
-
export { applyNodeChanges, applyEdgeChanges } from './utils/changes';
|
|
9
|
+
export { isNode, isEdge, addEdge, updateEdge, } from './utils/graph';
|
|
13
10
|
export * from './types';
|
|
11
|
+
export default ReactDiagram;
|
|
14
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["react-diagram/packages/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["react-diagram/packages/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EACJ,OAAO,IAAI,UAAU,EACrB,aAAa,GACf,MAAM,+BAA+B,CAAC;AAEvC,cAAc,4BAA4B,CAAC;AAK3C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,UAAU,GAEZ,MAAM,eAAe,CAAC;AAGvB,cAAc,SAAS,CAAC;AACxB,eAAe,YAAY,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -401,8 +401,8 @@ const addEdge = (edgeParams, edges) => {
|
|
|
401
401
|
};
|
|
402
402
|
return edges.concat(edge);
|
|
403
403
|
};
|
|
404
|
-
const updateEdge = (
|
|
405
|
-
const { id: oldEdgeId, ...rest } =
|
|
404
|
+
const updateEdge = (originEdge, newConnection, edges, options = { shouldReplaceId: true }) => {
|
|
405
|
+
const { id: oldEdgeId, ...rest } = originEdge;
|
|
406
406
|
if (!newConnection.source || !newConnection.target)
|
|
407
407
|
devWarn('020');
|
|
408
408
|
const foundEdge = edges.find((e) => e.id === oldEdgeId);
|
|
@@ -737,6 +737,13 @@ var MarkerType;
|
|
|
737
737
|
MarkerType["Arrow"] = "arrow";
|
|
738
738
|
})(MarkerType || (MarkerType = {}));
|
|
739
739
|
|
|
740
|
+
var ConnectionEdgeType;
|
|
741
|
+
(function (ConnectionEdgeType) {
|
|
742
|
+
ConnectionEdgeType["Straight"] = "straight";
|
|
743
|
+
ConnectionEdgeType["Bezier"] = "bezier";
|
|
744
|
+
ConnectionEdgeType["Step"] = "step";
|
|
745
|
+
})(ConnectionEdgeType || (ConnectionEdgeType = {}));
|
|
746
|
+
|
|
740
747
|
const selector$3 = (s) => ({
|
|
741
748
|
nodesDraggable: s.nodesDraggable,
|
|
742
749
|
elementsSelectable: s.elementsSelectable,
|
|
@@ -1533,77 +1540,77 @@ const selector$2 = (s) => ({
|
|
|
1533
1540
|
nodeInternals: s.nodeInternals,
|
|
1534
1541
|
onError: s.onError,
|
|
1535
1542
|
});
|
|
1536
|
-
function EdgeRenderer({ rfId, edgeTypes,
|
|
1543
|
+
function EdgeRenderer({ rfId, edgeTypes, noPanClassName, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd, }) {
|
|
1537
1544
|
const { edges, width, height, nodeInternals } = useStore(selector$2, shallow);
|
|
1538
|
-
return (jsxs(
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1545
|
+
return (jsxs("svg", { width: width || '100vw', height: height || '100vh', className: "react-diagram__edges react-diagram__container", children: [jsx(MarkerComponent$1, { defaultColor: "#000000", rfId: rfId }), jsx("g", { children: edges.map((edge) => {
|
|
1546
|
+
const { data, type,
|
|
1547
|
+
// elProps
|
|
1548
|
+
id, className, style, ariaLabel,
|
|
1549
|
+
// sourceAndTargetIds
|
|
1550
|
+
source, sourcePort, target, targetPort,
|
|
1551
|
+
// marker
|
|
1552
|
+
markerEnd, markerStart,
|
|
1553
|
+
// labelProps
|
|
1554
|
+
label, labelStyle, labelShowBg, labelBgStyle, labelBgPadding, labelBgBorderRadius, } = edge;
|
|
1555
|
+
const [sourceNodeRect, sourcePortBounds, sourceIsValid] = getNodeData(nodeInternals.get(source));
|
|
1556
|
+
const [targetNodeRect, targetPortBounds, targetIsValid] = getNodeData(nodeInternals.get(target));
|
|
1557
|
+
if (!sourceIsValid || !targetIsValid) {
|
|
1558
|
+
return null;
|
|
1559
|
+
}
|
|
1560
|
+
const edgeType = type || 'straight';
|
|
1561
|
+
const EdgeComponent = edgeTypes[edgeType] || edgeTypes.default;
|
|
1562
|
+
const targetNodePorts = targetPortBounds.target;
|
|
1563
|
+
const sourcePortInfo = getPort(sourcePortBounds.source, sourcePort);
|
|
1564
|
+
const targetPortInfo = getPort(targetNodePorts, targetPort);
|
|
1565
|
+
const sourcePosition = sourcePortInfo?.position || Position.Bottom;
|
|
1566
|
+
const targetPosition = targetPortInfo?.position || Position.Top;
|
|
1567
|
+
const isFocusable = !!edge.focusable;
|
|
1568
|
+
if (!sourcePortInfo || !targetPortInfo) {
|
|
1569
|
+
return null;
|
|
1570
|
+
}
|
|
1571
|
+
const elProps = {
|
|
1572
|
+
id,
|
|
1573
|
+
className: cc([className, noPanClassName]),
|
|
1574
|
+
style,
|
|
1575
|
+
ariaLabel,
|
|
1576
|
+
};
|
|
1577
|
+
const sourceAndTargetIds = {
|
|
1578
|
+
source,
|
|
1579
|
+
sourcePort,
|
|
1580
|
+
target,
|
|
1581
|
+
targetPort,
|
|
1582
|
+
};
|
|
1583
|
+
const marker = {
|
|
1584
|
+
markerEnd,
|
|
1585
|
+
markerStart,
|
|
1586
|
+
};
|
|
1587
|
+
const labelProps = {
|
|
1588
|
+
label,
|
|
1589
|
+
labelStyle,
|
|
1590
|
+
labelShowBg,
|
|
1591
|
+
labelBgStyle,
|
|
1592
|
+
labelBgPadding,
|
|
1593
|
+
labelBgBorderRadius,
|
|
1594
|
+
};
|
|
1595
|
+
const edgePositions = getEdgePositions(sourceNodeRect, sourcePortInfo, sourcePosition, targetNodeRect, targetPortInfo, targetPosition);
|
|
1596
|
+
const position = {
|
|
1597
|
+
...edgePositions,
|
|
1598
|
+
sourcePosition,
|
|
1599
|
+
targetPosition,
|
|
1600
|
+
};
|
|
1601
|
+
const events = {
|
|
1602
|
+
onClick: onEdgeClick,
|
|
1603
|
+
onDoubleClick: onEdgeDoubleClick,
|
|
1604
|
+
onContextMenu: onEdgeContextMenu,
|
|
1605
|
+
onMouseEnter: onEdgeMouseEnter,
|
|
1606
|
+
onMouseMove: onEdgeMouseMove,
|
|
1607
|
+
onMouseLeave: onEdgeMouseLeave,
|
|
1608
|
+
onEdgeUpdate,
|
|
1609
|
+
onEdgeUpdateStart,
|
|
1610
|
+
onEdgeUpdateEnd,
|
|
1611
|
+
};
|
|
1612
|
+
return (jsx(EdgeComponent, { ...elProps, ...sourceAndTargetIds, ...marker, ...labelProps, ...position, ...events, rfId: rfId, type: edgeType, data: data, isFocusable: isFocusable }, id));
|
|
1613
|
+
}) })] }));
|
|
1607
1614
|
}
|
|
1608
1615
|
EdgeRenderer.displayName = 'EdgeRenderer';
|
|
1609
1616
|
var EdgeRenderer$1 = memo(EdgeRenderer);
|
|
@@ -1614,7 +1621,7 @@ const oppositePosition = {
|
|
|
1614
1621
|
[Position.Top]: Position.Bottom,
|
|
1615
1622
|
[Position.Bottom]: Position.Top,
|
|
1616
1623
|
};
|
|
1617
|
-
function ConnectionPath({ style, nodeId, portType }) {
|
|
1624
|
+
function ConnectionPath({ style, nodeId, portType, type = ConnectionEdgeType.Straight, Component, }) {
|
|
1618
1625
|
const { fromNode, toX, toY } = useStore(useCallback((s) => ({
|
|
1619
1626
|
fromNode: s.nodeInternals.get(nodeId),
|
|
1620
1627
|
toX: (s.connectionPosition.x - s.transform[0]) / s.transform[2],
|
|
@@ -1639,9 +1646,10 @@ function ConnectionPath({ style, nodeId, portType }) {
|
|
|
1639
1646
|
if (!fromPosition || !toPosition) {
|
|
1640
1647
|
return null;
|
|
1641
1648
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1649
|
+
if (Component) {
|
|
1650
|
+
return (jsx(Component, { connectionEdgeType: type, connectionEdgeStyle: style, fromNode: fromNode, fromPort: fromPort, fromX: fromX, fromY: fromY, toX: toX, toY: toY, fromPosition: fromPosition, toPosition: toPosition }));
|
|
1651
|
+
}
|
|
1652
|
+
let d = '';
|
|
1645
1653
|
const pathParams = {
|
|
1646
1654
|
sourceX: fromX,
|
|
1647
1655
|
sourceY: fromY,
|
|
@@ -1650,25 +1658,51 @@ function ConnectionPath({ style, nodeId, portType }) {
|
|
|
1650
1658
|
targetY: toY,
|
|
1651
1659
|
targetPosition: toPosition,
|
|
1652
1660
|
};
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1661
|
+
if (type === ConnectionEdgeType.Bezier) {
|
|
1662
|
+
[d] = getBezierPath(pathParams);
|
|
1663
|
+
}
|
|
1664
|
+
else if (type === ConnectionEdgeType.Step) {
|
|
1665
|
+
[d] = getStepPath({
|
|
1666
|
+
...pathParams,
|
|
1667
|
+
borderRadius: 0,
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
else {
|
|
1671
|
+
d = `M${fromX},${fromY} ${toX},${toY}`;
|
|
1672
|
+
}
|
|
1673
|
+
return (jsx("path", { d: d, fill: "none", className: "react-diagram__connection-path", style: style }));
|
|
1658
1674
|
}
|
|
1659
1675
|
ConnectionPath.displayName = 'ConnectionPath';
|
|
1660
1676
|
|
|
1661
1677
|
const selector$1 = (s) => ({
|
|
1678
|
+
edges: s.edges,
|
|
1662
1679
|
nodeId: s.connectionNodeId,
|
|
1663
1680
|
portType: s.connectionPortType,
|
|
1664
1681
|
});
|
|
1665
|
-
function ConnectionEdge({ containerStyle, style }) {
|
|
1666
|
-
const { nodeId, portType } = useStore(selector$1, shallow);
|
|
1682
|
+
function ConnectionEdge({ containerStyle, style, type, component, }) {
|
|
1683
|
+
const { nodeId, portType, edges } = useStore(selector$1, shallow);
|
|
1667
1684
|
const isValid = !!(nodeId && portType);
|
|
1668
1685
|
if (!isValid) {
|
|
1669
1686
|
return null;
|
|
1670
1687
|
}
|
|
1671
|
-
|
|
1688
|
+
const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
1689
|
+
const getConnectionEdgeType = (edgeType = '') => {
|
|
1690
|
+
let connectionEdgeType = '';
|
|
1691
|
+
if (type) {
|
|
1692
|
+
connectionEdgeType = type;
|
|
1693
|
+
}
|
|
1694
|
+
else if (Object.keys(ConnectionEdgeType).includes(capitalizeFirstLetter(edgeType))) {
|
|
1695
|
+
connectionEdgeType = edgeType;
|
|
1696
|
+
}
|
|
1697
|
+
else {
|
|
1698
|
+
connectionEdgeType = 'straight';
|
|
1699
|
+
}
|
|
1700
|
+
return connectionEdgeType;
|
|
1701
|
+
};
|
|
1702
|
+
const currentEdgeType = edges.find((edge) => edge[portType] === nodeId)
|
|
1703
|
+
?.type;
|
|
1704
|
+
const edgeType = getConnectionEdgeType(currentEdgeType);
|
|
1705
|
+
return (jsx("svg", { style: containerStyle, className: "react-diagram__container react-diagram__edges react-diagram__connection-line", children: jsx("g", { className: "react-diagram__connection", children: jsx(ConnectionPath, { style: style, nodeId: nodeId, portType: portType, type: edgeType, Component: component }) }) }));
|
|
1672
1706
|
}
|
|
1673
1707
|
|
|
1674
1708
|
function DiagramView({ rfId,
|
|
@@ -1677,8 +1711,10 @@ noPanClassName, panning, defaultViewport, multiSelectionKeyCode, onMove, onMoveS
|
|
|
1677
1711
|
// NodeRenderer props
|
|
1678
1712
|
onlyRenderVisibleElements, disableKeyboardA11y, noDragClassName, nodeOrigin, nodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave,
|
|
1679
1713
|
// EdgeRenderer props
|
|
1680
|
-
edgeTypes, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd,
|
|
1681
|
-
|
|
1714
|
+
edgeTypes, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd,
|
|
1715
|
+
// ConnectionLineWrapper
|
|
1716
|
+
connectionEdgeContainerStyle, connectionEdgeStyle, connectionEdgeType, connectionEdgeComponent, }) {
|
|
1717
|
+
return (jsxs(DiagramRenderer$1, { multiSelectionKeyCode: multiSelectionKeyCode, noPanClassName: noPanClassName, panning: panning, defaultViewport: defaultViewport, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd, children: [jsx(NodeRenderer$1, { rfId: rfId, nodeTypes: nodeTypes, onlyRenderVisibleElements: onlyRenderVisibleElements, disableKeyboardA11y: disableKeyboardA11y, nodeOrigin: nodeOrigin, noDragClassName: noDragClassName, noPanClassName: noPanClassName, onNodeClick: onNodeClick, onNodeDoubleClick: onNodeDoubleClick, onNodeContextMenu: onNodeContextMenu, onNodeMouseEnter: onNodeMouseEnter, onNodeMouseMove: onNodeMouseMove, onNodeMouseLeave: onNodeMouseLeave }), jsx(EdgeRenderer$1, { rfId: rfId, edgeTypes: edgeTypes, noPanClassName: noPanClassName, onEdgeClick: onEdgeClick, onEdgeDoubleClick: onEdgeDoubleClick, onEdgeContextMenu: onEdgeContextMenu, onEdgeMouseEnter: onEdgeMouseEnter, onEdgeMouseMove: onEdgeMouseMove, onEdgeMouseLeave: onEdgeMouseLeave, onEdgeUpdate: onEdgeUpdate, onEdgeUpdateStart: onEdgeUpdateStart, onEdgeUpdateEnd: onEdgeUpdateEnd }), jsx(ConnectionEdge, { containerStyle: connectionEdgeContainerStyle, style: connectionEdgeStyle, type: connectionEdgeType, component: connectionEdgeComponent })] }));
|
|
1682
1718
|
}
|
|
1683
1719
|
DiagramView.displayName = 'DiagramView';
|
|
1684
1720
|
var DiagramView$1 = memo(DiagramView);
|
|
@@ -2558,13 +2594,13 @@ const defaultEdgeTypes = {
|
|
|
2558
2594
|
};
|
|
2559
2595
|
const ReactDiagram = forwardRef(({ id,
|
|
2560
2596
|
// DiagramView props
|
|
2561
|
-
panning = true, minZoom, maxZoom, translateExtent, nodeExtent, defaultViewport = initViewport, multiSelectionKeyCode, onlyRenderVisibleElements = false, disableKeyboardA11y = false, noDragClassName = 'nodrag', noPanClassName = 'nopan', nodeOrigin = initNodeOrigin, nodeTypes = defaultNodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave, edgeTypes = defaultEdgeTypes, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd, onMove, onMoveStart, onMoveEnd,
|
|
2597
|
+
panning = true, minZoom, maxZoom, translateExtent, nodeExtent, defaultViewport = initViewport, multiSelectionKeyCode, onlyRenderVisibleElements = false, disableKeyboardA11y = false, noDragClassName = 'nodrag', noPanClassName = 'nopan', nodeOrigin = initNodeOrigin, nodeTypes = defaultNodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave, edgeTypes = defaultEdgeTypes, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd, onMove, onMoveStart, onMoveEnd, connectionEdgeContainerStyle, connectionEdgeStyle, connectionEdgeType, connectionEdgeComponent,
|
|
2562
2598
|
// StoreUpdater props
|
|
2563
2599
|
nodes, edges, nodesDraggable, elevateNodesOnSelect, autoPanOnNodeDrag, autoPanOnConnect, onNodesChange, onNodeDrag, onNodeDragStart, onNodeDragEnd, onEdgesChange, onConnect, onConnectStart, onConnectEnd, onError, }, ref) => {
|
|
2564
2600
|
const rfId = id || '1';
|
|
2565
2601
|
const nodeTypesWrapped = useNodeOrEdgeTypes(nodeTypes, createNodeTypes);
|
|
2566
2602
|
const edgeTypesWrapped = useNodeOrEdgeTypes(edgeTypes, createEdgeTypes);
|
|
2567
|
-
return (jsx("div", { ref: ref, className: "react-diagram", children: jsxs(Wrapper, { children: [jsx(DiagramView$1, { rfId: rfId, panning: panning, defaultViewport: defaultViewport, multiSelectionKeyCode: multiSelectionKeyCode, onlyRenderVisibleElements: onlyRenderVisibleElements, disableKeyboardA11y: disableKeyboardA11y, noDragClassName: noDragClassName, noPanClassName: noPanClassName, nodeOrigin: nodeOrigin, nodeTypes: nodeTypesWrapped, edgeTypes: edgeTypesWrapped, onNodeClick: onNodeClick, onNodeDoubleClick: onNodeDoubleClick, onNodeContextMenu: onNodeContextMenu, onNodeMouseEnter: onNodeMouseEnter, onNodeMouseMove: onNodeMouseMove, onNodeMouseLeave: onNodeMouseLeave, onEdgeClick: onEdgeClick, onEdgeDoubleClick: onEdgeDoubleClick, onEdgeContextMenu: onEdgeContextMenu, onEdgeMouseEnter: onEdgeMouseEnter, onEdgeMouseMove: onEdgeMouseMove, onEdgeMouseLeave: onEdgeMouseLeave, onEdgeUpdate: onEdgeUpdate, onEdgeUpdateStart: onEdgeUpdateStart, onEdgeUpdateEnd: onEdgeUpdateEnd, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd }), jsx(StoreUpdater, { rfId: rfId, nodes: nodes, edges: edges, nodesDraggable: nodesDraggable, elevateNodesOnSelect: elevateNodesOnSelect, autoPanOnNodeDrag: autoPanOnNodeDrag, autoPanOnConnect: autoPanOnConnect, nodeExtent: nodeExtent, translateExtent: translateExtent, minZoom: minZoom, maxZoom: maxZoom, onNodesChange: onNodesChange, onNodeDrag: onNodeDrag, onNodeDragStart: onNodeDragStart, onNodeDragEnd: onNodeDragEnd, onEdgesChange: onEdgesChange, onConnect: onConnect, onConnectStart: onConnectStart, onConnectEnd: onConnectEnd, onError: onError })] }) }));
|
|
2603
|
+
return (jsx("div", { ref: ref, className: "react-diagram", children: jsxs(Wrapper, { children: [jsx(DiagramView$1, { rfId: rfId, panning: panning, defaultViewport: defaultViewport, multiSelectionKeyCode: multiSelectionKeyCode, onlyRenderVisibleElements: onlyRenderVisibleElements, disableKeyboardA11y: disableKeyboardA11y, noDragClassName: noDragClassName, noPanClassName: noPanClassName, nodeOrigin: nodeOrigin, nodeTypes: nodeTypesWrapped, edgeTypes: edgeTypesWrapped, connectionEdgeContainerStyle: connectionEdgeContainerStyle, connectionEdgeStyle: connectionEdgeStyle, connectionEdgeType: connectionEdgeType, connectionEdgeComponent: connectionEdgeComponent, onNodeClick: onNodeClick, onNodeDoubleClick: onNodeDoubleClick, onNodeContextMenu: onNodeContextMenu, onNodeMouseEnter: onNodeMouseEnter, onNodeMouseMove: onNodeMouseMove, onNodeMouseLeave: onNodeMouseLeave, onEdgeClick: onEdgeClick, onEdgeDoubleClick: onEdgeDoubleClick, onEdgeContextMenu: onEdgeContextMenu, onEdgeMouseEnter: onEdgeMouseEnter, onEdgeMouseMove: onEdgeMouseMove, onEdgeMouseLeave: onEdgeMouseLeave, onEdgeUpdate: onEdgeUpdate, onEdgeUpdateStart: onEdgeUpdateStart, onEdgeUpdateEnd: onEdgeUpdateEnd, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd }), jsx(StoreUpdater, { rfId: rfId, nodes: nodes, edges: edges, nodesDraggable: nodesDraggable, elevateNodesOnSelect: elevateNodesOnSelect, autoPanOnNodeDrag: autoPanOnNodeDrag, autoPanOnConnect: autoPanOnConnect, nodeExtent: nodeExtent, translateExtent: translateExtent, minZoom: minZoom, maxZoom: maxZoom, onNodesChange: onNodesChange, onNodeDrag: onNodeDrag, onNodeDragStart: onNodeDragStart, onNodeDragEnd: onNodeDragEnd, onEdgesChange: onEdgesChange, onConnect: onConnect, onConnectStart: onConnectStart, onConnectEnd: onConnectEnd, onError: onError })] }) }));
|
|
2568
2604
|
});
|
|
2569
2605
|
ReactDiagram.displayName = 'ReactDiagram';
|
|
2570
2606
|
|
|
@@ -2578,4 +2614,4 @@ function createUseItemsState(applyChanges) {
|
|
|
2578
2614
|
const useNodesState = createUseItemsState(applyNodeChanges);
|
|
2579
2615
|
const useEdgesState = createUseItemsState(applyEdgeChanges);
|
|
2580
2616
|
|
|
2581
|
-
export { BaseEdge, MarkerType, Port$1 as Port, Position,
|
|
2617
|
+
export { BaseEdge, BezierEdge, ConnectionEdgeType, MarkerType, Port$1 as Port, Position, ReactDiagramProvider, StepEdge, addEdge, boxToRect, clamp, ReactDiagram as default, getBezierPath, getStepPath, internalsSymbol, isEdge, isNode, rectToBox, updateEdge, useEdgesState, useNodesState };
|