refactor(props): cleanup
This commit is contained in:
@@ -216,7 +216,7 @@ const EdgeRenderer = (props: EdgeRendererProps) => {
|
|||||||
const width = useStoreState((state) => state.width);
|
const width = useStoreState((state) => state.width);
|
||||||
const height = useStoreState((state) => state.height);
|
const height = useStoreState((state) => state.height);
|
||||||
|
|
||||||
const { connectionLineStyle, connectionLineType, arrowHeadColor, connectionLineComponent } = props;
|
const { connectionLineType, arrowHeadColor, connectionLineStyle, connectionLineComponent } = props;
|
||||||
|
|
||||||
if (!width) {
|
if (!width) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ export interface GraphViewProps {
|
|||||||
connectionLineStyle?: CSSProperties;
|
connectionLineStyle?: CSSProperties;
|
||||||
connectionLineComponent?: ConnectionLineComponent;
|
connectionLineComponent?: ConnectionLineComponent;
|
||||||
deleteKeyCode: number;
|
deleteKeyCode: number;
|
||||||
snapToGrid?: boolean;
|
snapToGrid: boolean;
|
||||||
snapGrid?: [number, number];
|
snapGrid: [number, number];
|
||||||
onlyRenderVisibleNodes: boolean;
|
onlyRenderVisibleNodes: boolean;
|
||||||
nodesDraggable?: boolean;
|
nodesDraggable?: boolean;
|
||||||
nodesConnectable?: boolean;
|
nodesConnectable?: boolean;
|
||||||
@@ -69,8 +69,8 @@ export interface GraphViewProps {
|
|||||||
selectNodesOnDrag?: boolean;
|
selectNodesOnDrag?: boolean;
|
||||||
minZoom?: number;
|
minZoom?: number;
|
||||||
maxZoom?: number;
|
maxZoom?: number;
|
||||||
defaultZoom?: number;
|
defaultZoom: number;
|
||||||
defaultPosition?: [number, number];
|
defaultPosition: [number, number];
|
||||||
translateExtent?: TranslateExtent;
|
translateExtent?: TranslateExtent;
|
||||||
arrowHeadColor: string;
|
arrowHeadColor: string;
|
||||||
markerEndId?: string;
|
markerEndId?: string;
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ interface NodeRendererProps {
|
|||||||
onNodeContextMenu?: (event: MouseEvent, node: Node) => void;
|
onNodeContextMenu?: (event: MouseEvent, node: Node) => void;
|
||||||
onNodeDragStart?: (event: MouseEvent, node: Node) => void;
|
onNodeDragStart?: (event: MouseEvent, node: Node) => void;
|
||||||
onNodeDragStop?: (event: MouseEvent, node: Node) => void;
|
onNodeDragStop?: (event: MouseEvent, node: Node) => void;
|
||||||
onlyRenderVisibleNodes?: boolean;
|
onlyRenderVisibleNodes: boolean;
|
||||||
snapToGrid?: boolean;
|
snapToGrid: boolean;
|
||||||
snapGrid?: [number, number];
|
snapGrid: [number, number];
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderNode(
|
function renderNode(
|
||||||
@@ -75,7 +75,7 @@ function renderNode(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const NodeRenderer = ({ onlyRenderVisibleNodes = true, ...props }: NodeRendererProps) => {
|
const NodeRenderer = (props: NodeRendererProps) => {
|
||||||
const nodes = useStoreState((s) => s.nodes);
|
const nodes = useStoreState((s) => s.nodes);
|
||||||
const transform = useStoreState((s) => s.transform);
|
const transform = useStoreState((s) => s.transform);
|
||||||
const selectedElements = useStoreState((s) => s.selectedElements);
|
const selectedElements = useStoreState((s) => s.selectedElements);
|
||||||
@@ -88,7 +88,7 @@ const NodeRenderer = ({ onlyRenderVisibleNodes = true, ...props }: NodeRendererP
|
|||||||
transform: `translate(${transform[0]}px,${transform[1]}px) scale(${transform[2]})`,
|
transform: `translate(${transform[0]}px,${transform[1]}px) scale(${transform[2]})`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderNodes = onlyRenderVisibleNodes ? getNodesInside(nodes, viewportBox, transform, true) : nodes;
|
const renderNodes = props.onlyRenderVisibleNodes ? getNodesInside(nodes, viewportBox, transform, true) : nodes;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="react-flow__nodes" style={transformStyle}>
|
<div className="react-flow__nodes" style={transformStyle}>
|
||||||
|
|||||||
@@ -97,18 +97,16 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
|
|||||||
translateExtent?: TranslateExtent;
|
translateExtent?: TranslateExtent;
|
||||||
arrowHeadColor?: string;
|
arrowHeadColor?: string;
|
||||||
markerEndId?: string;
|
markerEndId?: string;
|
||||||
zoomOnScroll: boolean;
|
zoomOnScroll?: boolean;
|
||||||
zoomOnDoubleClick?: boolean;
|
zoomOnDoubleClick?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReactFlow = ({
|
const ReactFlow = ({
|
||||||
style,
|
|
||||||
onElementClick,
|
|
||||||
elements = [],
|
elements = [],
|
||||||
className,
|
className,
|
||||||
children,
|
|
||||||
nodeTypes = defaultNodeTypes,
|
nodeTypes = defaultNodeTypes,
|
||||||
edgeTypes = defaultEdgeTypes,
|
edgeTypes = defaultEdgeTypes,
|
||||||
|
onElementClick,
|
||||||
onLoad,
|
onLoad,
|
||||||
onMove,
|
onMove,
|
||||||
onMoveStart,
|
onMoveStart,
|
||||||
@@ -134,13 +132,13 @@ const ReactFlow = ({
|
|||||||
connectionLineComponent,
|
connectionLineComponent,
|
||||||
deleteKeyCode = 8,
|
deleteKeyCode = 8,
|
||||||
selectionKeyCode = 16,
|
selectionKeyCode = 16,
|
||||||
snapToGrid,
|
snapToGrid = false,
|
||||||
snapGrid,
|
snapGrid = [15, 15],
|
||||||
onlyRenderVisibleNodes = true,
|
onlyRenderVisibleNodes = true,
|
||||||
|
selectNodesOnDrag = true,
|
||||||
nodesDraggable,
|
nodesDraggable,
|
||||||
nodesConnectable,
|
nodesConnectable,
|
||||||
elementsSelectable,
|
elementsSelectable,
|
||||||
selectNodesOnDrag = true,
|
|
||||||
minZoom,
|
minZoom,
|
||||||
maxZoom,
|
maxZoom,
|
||||||
defaultZoom = 1,
|
defaultZoom = 1,
|
||||||
@@ -154,13 +152,15 @@ const ReactFlow = ({
|
|||||||
onPaneClick,
|
onPaneClick,
|
||||||
onPaneScroll,
|
onPaneScroll,
|
||||||
onPaneContextMenu,
|
onPaneContextMenu,
|
||||||
|
children,
|
||||||
|
...rest
|
||||||
}: ReactFlowProps) => {
|
}: ReactFlowProps) => {
|
||||||
const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), [nodeTypes]);
|
const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []);
|
||||||
const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), [edgeTypes]);
|
const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []);
|
||||||
const reactFlowClasses = cc(['react-flow', className]);
|
const reactFlowClasses = cc(['react-flow', className]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={style} className={reactFlowClasses}>
|
<div {...rest} className={reactFlowClasses}>
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<GraphView
|
<GraphView
|
||||||
onLoad={onLoad}
|
onLoad={onLoad}
|
||||||
|
|||||||
+2
-1
@@ -426,7 +426,8 @@ export const storeModel: StoreModel = {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
setSnapGrid: action((state, snapGrid) => {
|
setSnapGrid: action((state, snapGrid) => {
|
||||||
state.snapGrid = snapGrid;
|
state.snapGrid[0] = snapGrid[0];
|
||||||
|
state.snapGrid[1] = snapGrid[1];
|
||||||
}),
|
}),
|
||||||
|
|
||||||
setInteractive: action((state, isInteractive) => {
|
setInteractive: action((state, isInteractive) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user