+3
-1
@@ -5,4 +5,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
examples
|
examples
|
||||||
cypress
|
cypress
|
||||||
.env
|
.env
|
||||||
|
tsconfig.json
|
||||||
|
src
|
||||||
@@ -20,7 +20,7 @@ export interface GraphViewProps {
|
|||||||
onElementClick: (element: Node | Edge) => void;
|
onElementClick: (element: Node | Edge) => void;
|
||||||
onElementsRemove: (elements: Elements) => void;
|
onElementsRemove: (elements: Elements) => void;
|
||||||
onNodeDragStop: (node: Node) => void;
|
onNodeDragStop: (node: Node) => void;
|
||||||
onConnect: (conneciton: Connection) => void;
|
onConnect: (connection: Connection | Edge) => void;
|
||||||
onLoad: OnLoadFunc;
|
onLoad: OnLoadFunc;
|
||||||
onMove: () => void;
|
onMove: () => void;
|
||||||
selectionKeyCode: number;
|
selectionKeyCode: number;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
|
|||||||
onElementClick: (element: Node | Edge) => void;
|
onElementClick: (element: Node | Edge) => void;
|
||||||
onElementsRemove: (elements: Elements) => void;
|
onElementsRemove: (elements: Elements) => void;
|
||||||
onNodeDragStop: (node: Node) => void;
|
onNodeDragStop: (node: Node) => void;
|
||||||
onConnect: (connection: Connection) => void;
|
onConnect: (connection: Edge | Connection) => void;
|
||||||
onLoad: OnLoadFunc;
|
onLoad: OnLoadFunc;
|
||||||
onMove: () => void;
|
onMove: () => void;
|
||||||
nodeTypes: NodeTypesType;
|
nodeTypes: NodeTypesType;
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ export { default as EdgeText } from './components/Edges/EdgeText';
|
|||||||
export { MiniMap, Controls } from './plugins';
|
export { MiniMap, Controls } from './plugins';
|
||||||
|
|
||||||
export { isNode, isEdge, removeElements, addEdge, getOutgoers } from './utils/graph';
|
export { isNode, isEdge, removeElements, addEdge, getOutgoers } from './utils/graph';
|
||||||
|
|
||||||
|
export * from './types';
|
||||||
|
|||||||
@@ -23,11 +23,10 @@ interface ControlProps extends React.HTMLAttributes<HTMLDivElement> {
|
|||||||
showInteractive?: boolean;
|
showInteractive?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({ style, showZoom = true, showFitView = true, showInteractive = true, className }: ControlProps) => {
|
const Controls = ({ style, showZoom = true, showFitView = true, showInteractive = true, className }: ControlProps) => {
|
||||||
const mapClasses: string = classnames('react-flow__controls', className);
|
|
||||||
|
|
||||||
const setInteractive = useStoreActions((actions) => actions.setInteractive);
|
const setInteractive = useStoreActions((actions) => actions.setInteractive);
|
||||||
const { isInteractive } = useStoreState(({ isInteractive }) => ({ isInteractive }));
|
const { isInteractive } = useStoreState(({ isInteractive }) => ({ isInteractive }));
|
||||||
|
const mapClasses: string = classnames('react-flow__controls', className);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -63,3 +62,7 @@ export default ({ style, showZoom = true, showFitView = true, showInteractive =
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Controls.displayName = 'Controls';
|
||||||
|
|
||||||
|
export default Controls;
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { Node } from '../../types';
|
||||||
|
|
||||||
|
interface MiniMapNodeProps {
|
||||||
|
node: Node;
|
||||||
|
color: string;
|
||||||
|
borderRadius: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MiniMapNode = ({ node, color, borderRadius }: MiniMapNodeProps) => {
|
||||||
|
const {
|
||||||
|
position: { x, y },
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
} = node.__rg;
|
||||||
|
const { background, backgroundColor } = node.style || {};
|
||||||
|
const fill = (background || backgroundColor || color) as string;
|
||||||
|
return (
|
||||||
|
<rect
|
||||||
|
className="react-flow__minimap-node"
|
||||||
|
x={x}
|
||||||
|
y={y}
|
||||||
|
rx={borderRadius}
|
||||||
|
ry={borderRadius}
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
fill={fill}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
MiniMapNode.displayName = 'MiniMapNode';
|
||||||
|
|
||||||
|
export default MiniMapNode;
|
||||||
@@ -4,18 +4,14 @@ import classnames from 'classnames';
|
|||||||
import { useStoreState } from '../../store/hooks';
|
import { useStoreState } from '../../store/hooks';
|
||||||
import { getRectOfNodes, getBoundsofRects } from '../../utils/graph';
|
import { getRectOfNodes, getBoundsofRects } from '../../utils/graph';
|
||||||
import { Node, Rect } from '../../types';
|
import { Node, Rect } from '../../types';
|
||||||
|
import MiniMapNode from './MiniMapNode';
|
||||||
|
|
||||||
type StringFunc = (node: Node) => string;
|
type StringFunc = (node: Node) => string;
|
||||||
|
|
||||||
interface MiniMapProps extends React.HTMLAttributes<SVGSVGElement> {
|
interface MiniMapProps extends React.HTMLAttributes<SVGSVGElement> {
|
||||||
nodeColor: string | StringFunc;
|
nodeColor?: string | StringFunc;
|
||||||
nodeBorderRadius: number;
|
nodeBorderRadius?: number;
|
||||||
maskColor: string;
|
maskColor?: string;
|
||||||
}
|
|
||||||
interface MiniMapNodeProps {
|
|
||||||
node: Node;
|
|
||||||
color: string;
|
|
||||||
borderRadius: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseStyle: CSSProperties = {
|
const baseStyle: CSSProperties = {
|
||||||
@@ -27,29 +23,7 @@ const baseStyle: CSSProperties = {
|
|||||||
height: 150,
|
height: 150,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MiniMapNode = ({ node, color, borderRadius }: MiniMapNodeProps) => {
|
const MiniMap = ({
|
||||||
const {
|
|
||||||
position: { x, y },
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
} = node.__rg;
|
|
||||||
const { background, backgroundColor } = node.style || {};
|
|
||||||
const fill = (background || backgroundColor || color) as string;
|
|
||||||
return (
|
|
||||||
<rect
|
|
||||||
className="react-flow__minimap-node"
|
|
||||||
x={x}
|
|
||||||
y={y}
|
|
||||||
rx={borderRadius}
|
|
||||||
ry={borderRadius}
|
|
||||||
width={width}
|
|
||||||
height={height}
|
|
||||||
fill={fill}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ({
|
|
||||||
style = { backgroundColor: '#f8f8f8' },
|
style = { backgroundColor: '#f8f8f8' },
|
||||||
className,
|
className,
|
||||||
nodeColor = '#ddd',
|
nodeColor = '#ddd',
|
||||||
@@ -105,7 +79,7 @@ export default ({
|
|||||||
}}
|
}}
|
||||||
className={mapClasses}
|
className={mapClasses}
|
||||||
>
|
>
|
||||||
{state.nodes.map(node => (
|
{state.nodes.map((node) => (
|
||||||
<MiniMapNode key={node.id} node={node} color={nodeColorFunc(node)} borderRadius={nodeBorderRadius} />
|
<MiniMapNode key={node.id} node={node} color={nodeColorFunc(node)} borderRadius={nodeBorderRadius} />
|
||||||
))}
|
))}
|
||||||
<path
|
<path
|
||||||
@@ -118,3 +92,7 @@ export default ({
|
|||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MiniMap.displayName = 'MiniMap';
|
||||||
|
|
||||||
|
export default MiniMap;
|
||||||
|
|||||||
+20
-20
@@ -13,22 +13,11 @@ export enum Position {
|
|||||||
Bottom = 'bottom',
|
Bottom = 'bottom',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type XYPosition = {
|
export interface XYPosition {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
};
|
|
||||||
|
|
||||||
export enum GridType {
|
|
||||||
Lines = 'lines',
|
|
||||||
Dots = 'dots',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type HandleType = 'source' | 'target';
|
|
||||||
|
|
||||||
export type NodeTypesType = { [key: string]: React.ReactNode };
|
|
||||||
|
|
||||||
export type EdgeTypesType = NodeTypesType;
|
|
||||||
|
|
||||||
export interface Dimensions {
|
export interface Dimensions {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
@@ -41,12 +30,6 @@ export interface Box extends XYPosition {
|
|||||||
y2: number;
|
y2: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectionRect extends Rect {
|
|
||||||
startX: number;
|
|
||||||
startY: number;
|
|
||||||
draw: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Node {
|
export interface Node {
|
||||||
id: ElementId;
|
id: ElementId;
|
||||||
position: XYPosition;
|
position: XYPosition;
|
||||||
@@ -71,6 +54,23 @@ export interface Edge {
|
|||||||
animated?: boolean;
|
animated?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum GridType {
|
||||||
|
Lines = 'lines',
|
||||||
|
Dots = 'dots',
|
||||||
|
}
|
||||||
|
|
||||||
|
export type HandleType = 'source' | 'target';
|
||||||
|
|
||||||
|
export type NodeTypesType = { [key: string]: React.ReactNode };
|
||||||
|
|
||||||
|
export type EdgeTypesType = NodeTypesType;
|
||||||
|
|
||||||
|
export interface SelectionRect extends Rect {
|
||||||
|
startX: number;
|
||||||
|
startY: number;
|
||||||
|
draw: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EdgeProps {
|
export interface EdgeProps {
|
||||||
sourceX: number;
|
sourceX: number;
|
||||||
sourceY: number;
|
sourceY: number;
|
||||||
@@ -142,10 +142,10 @@ type OnLoadParams = {
|
|||||||
|
|
||||||
export type OnLoadFunc = (params: OnLoadParams) => void;
|
export type OnLoadFunc = (params: OnLoadParams) => void;
|
||||||
|
|
||||||
export type Connection = {
|
export interface Connection {
|
||||||
source: ElementId | null;
|
source: ElementId | null;
|
||||||
target: ElementId | null;
|
target: ElementId | null;
|
||||||
};
|
}
|
||||||
|
|
||||||
export type OnConnectFunc = (connection: Connection) => void;
|
export type OnConnectFunc = (connection: Connection) => void;
|
||||||
|
|
||||||
|
|||||||
+13
-6
@@ -1,7 +1,7 @@
|
|||||||
import { zoomIdentity } from 'd3-zoom';
|
import { zoomIdentity } from 'd3-zoom';
|
||||||
|
|
||||||
import store from '../store';
|
import store from '../store';
|
||||||
import { ElementId, Node, Edge, Elements, Transform, XYPosition, Rect, FitViewParams, Box } from '../types';
|
import { ElementId, Node, Edge, Elements, Transform, XYPosition, Rect, FitViewParams, Box, Connection } from '../types';
|
||||||
|
|
||||||
export const isEdge = (element: Node | Edge): boolean =>
|
export const isEdge = (element: Node | Edge): boolean =>
|
||||||
element.hasOwnProperty('source') && element.hasOwnProperty('target');
|
element.hasOwnProperty('source') && element.hasOwnProperty('target');
|
||||||
@@ -31,17 +31,24 @@ export const removeElements = (elementsToRemove: Elements, elements: Elements):
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getEdgeId = ({ source, target }: Edge): ElementId => `reactflow__edge-${source}-${target}`;
|
const getEdgeId = ({ source, target }: Connection): ElementId => `reactflow__edge-${source}-${target}`;
|
||||||
|
|
||||||
export const addEdge = (edgeParams: Edge, elements: Elements): Elements => {
|
export const addEdge = (edgeParams: Edge | Connection, elements: Elements): Elements => {
|
||||||
if (!edgeParams.source || !edgeParams.target) {
|
if (!edgeParams.source || !edgeParams.target) {
|
||||||
throw new Error('Can not create edge. An edge needs a source and a target');
|
throw new Error('Can not create edge. An edge needs a source and a target');
|
||||||
}
|
}
|
||||||
|
|
||||||
return elements.concat({
|
if (edgeParams.hasOwnProperty('id')) {
|
||||||
|
const edge = { ...edgeParams } as Edge;
|
||||||
|
return elements.concat(edge);
|
||||||
|
}
|
||||||
|
|
||||||
|
const edge = {
|
||||||
...edgeParams,
|
...edgeParams,
|
||||||
id: typeof edgeParams.id !== 'undefined' ? edgeParams.id : getEdgeId(edgeParams),
|
id: getEdgeId(edgeParams),
|
||||||
});
|
} as Edge;
|
||||||
|
|
||||||
|
return elements.concat(edge);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const pointToRendererPoint = (
|
export const pointToRendererPoint = (
|
||||||
|
|||||||
Reference in New Issue
Block a user