@@ -88,7 +88,9 @@ const BasicFlow = () => <ReactFlow elements={elements} />;
|
|||||||
- `snapToGrid`: default: `false`
|
- `snapToGrid`: default: `false`
|
||||||
- `snapGrid`: [x, y] array - default: `[16, 16]`
|
- `snapGrid`: [x, y] array - default: `[16, 16]`
|
||||||
- `onlyRenderVisibleNodes`: default: `true`
|
- `onlyRenderVisibleNodes`: default: `true`
|
||||||
- `isInteractive`: default: `true`. If the graph is not interactive you can't drag any nodes
|
- `nodesDraggable`: default: `true`
|
||||||
|
- `nodesConnectable`: default: `true`
|
||||||
|
- `elementsSelectable`: default: `true`
|
||||||
- `selectNodesOnDrag`: default: `true`
|
- `selectNodesOnDrag`: default: `true`
|
||||||
- `minZoom`: default: `0.5`
|
- `minZoom`: default: `0.5`
|
||||||
- `maxZoom`: default: `2`
|
- `maxZoom`: default: `2`
|
||||||
@@ -511,7 +513,7 @@ You can find all examples in the [example](example) folder or check out the live
|
|||||||
- [provider](https://react-flow.netlify.app/provider)
|
- [provider](https://react-flow.netlify.app/provider)
|
||||||
- [edges](https://react-flow.netlify.app/edges)
|
- [edges](https://react-flow.netlify.app/edges)
|
||||||
- [empty](https://react-flow.netlify.app/empty)
|
- [empty](https://react-flow.netlify.app/empty)
|
||||||
- [inactive](https://react-flow.netlify.app/inactive)
|
- [interaction](https://react-flow.netlify.app/interaction)
|
||||||
- [provider](https://react-flow.netlify.app/provider)
|
- [provider](https://react-flow.netlify.app/provider)
|
||||||
|
|
||||||
# Development
|
# Development
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
describe('Inactive Graph Rendering', () => {
|
describe('Interaction Graph Rendering', () => {
|
||||||
it('renders a graph', () => {
|
it('renders a graph', () => {
|
||||||
cy.visit('/inactive');
|
cy.visit('/interaction');
|
||||||
|
|
||||||
cy.get('.react-flow__renderer');
|
cy.get('.react-flow__renderer');
|
||||||
cy.get('.react-flow__node').should('have.length', 4);
|
cy.get('.react-flow__node').should('have.length', 4);
|
||||||
@@ -20,12 +20,24 @@ describe('Inactive Graph Rendering', () => {
|
|||||||
|
|
||||||
it('tries to do a selection', () => {
|
it('tries to do a selection', () => {
|
||||||
cy.get('body').type('{shift}', { release: false }).get('.react-flow__selectionpane').should('not.exist');
|
cy.get('body').type('{shift}', { release: false }).get('.react-flow__selectionpane').should('not.exist');
|
||||||
|
|
||||||
cy.get('body').type('{shift}', { release: true });
|
cy.get('body').type('{shift}', { release: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toggles interactive mode', () => {
|
it('toggles draggable mode', () => {
|
||||||
cy.get('.react-flow__interactive').click();
|
cy.get('.react-flow__draggable').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('drags a node', () => {
|
||||||
|
const styleBeforeDrag = Cypress.$('.react-flow__node:first').css('transform');
|
||||||
|
|
||||||
|
cy.drag('.react-flow__node:first', { x: 325, y: 100 }).then(($el) => {
|
||||||
|
const styleAfterDrag = $el.css('transform');
|
||||||
|
expect(styleBeforeDrag).to.not.equal(styleAfterDrag);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toggles selectable mode', () => {
|
||||||
|
cy.get('.react-flow__selectable').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('selects a node by click', () => {
|
it('selects a node by click', () => {
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
|
|
||||||
import ReactFlow, { MiniMap, Controls } from 'react-flow-renderer';
|
|
||||||
|
|
||||||
const initialElements = [
|
|
||||||
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
|
|
||||||
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
|
|
||||||
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 } },
|
|
||||||
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 } },
|
|
||||||
{ id: 'e1-2', source: '1', target: '2', animated: true },
|
|
||||||
{ id: 'e1-3', source: '1', target: '3' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const InactiveFlow = () => {
|
|
||||||
const [isInteractive, setIsInteractive] = useState(false);
|
|
||||||
const onToggleInteractive = (evt) => {
|
|
||||||
setIsInteractive(evt.target.checked);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ReactFlow
|
|
||||||
elements={initialElements}
|
|
||||||
isInteractive={isInteractive}
|
|
||||||
>
|
|
||||||
<MiniMap />
|
|
||||||
<Controls />
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ position: 'absolute', left: 10, top: 10, zIndex: 4 }}
|
|
||||||
>
|
|
||||||
<label>
|
|
||||||
interactive
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={isInteractive}
|
|
||||||
onChange={onToggleInteractive}
|
|
||||||
className="react-flow__interactive"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</ReactFlow>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default InactiveFlow;
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
|
import ReactFlow, { addEdge, MiniMap, Controls } from 'react-flow-renderer';
|
||||||
|
|
||||||
|
const initialElements = [
|
||||||
|
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
|
||||||
|
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
|
||||||
|
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 } },
|
||||||
|
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 } },
|
||||||
|
{ id: 'e1-2', source: '1', target: '2', animated: true },
|
||||||
|
{ id: 'e1-3', source: '1', target: '3' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const InteractionFlow = () => {
|
||||||
|
const [elements, setElements] = useState(initialElements);
|
||||||
|
const onConnect = (params) => setElements((els) => addEdge(params, els));
|
||||||
|
|
||||||
|
const [isSelectable, setIsSelectable] = useState(false);
|
||||||
|
const [isDraggable, setIsDraggable] = useState(false);
|
||||||
|
const [isConnectable, setIsConnectable] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ReactFlow
|
||||||
|
elements={elements}
|
||||||
|
elementsSelectable={isSelectable}
|
||||||
|
nodesConnectable={isConnectable}
|
||||||
|
nodesDraggable={isDraggable}
|
||||||
|
onConnect={onConnect}
|
||||||
|
>
|
||||||
|
<MiniMap />
|
||||||
|
<Controls />
|
||||||
|
|
||||||
|
<div style={{ position: 'absolute', left: 10, top: 10, zIndex: 4 }}>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="draggable">
|
||||||
|
draggable
|
||||||
|
<input
|
||||||
|
id="draggable"
|
||||||
|
type="checkbox"
|
||||||
|
checked={isDraggable}
|
||||||
|
onChange={(evt) => setIsDraggable(evt.target.checked)}
|
||||||
|
className="react-flow__draggable"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="connectable">
|
||||||
|
connectable
|
||||||
|
<input
|
||||||
|
id="connectable"
|
||||||
|
type="checkbox"
|
||||||
|
checked={isConnectable}
|
||||||
|
onChange={(evt) => setIsConnectable(evt.target.checked)}
|
||||||
|
className="react-flow__connectable"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="selectable">
|
||||||
|
selectable
|
||||||
|
<input
|
||||||
|
id="selectable"
|
||||||
|
type="checkbox"
|
||||||
|
checked={isSelectable}
|
||||||
|
onChange={(evt) => setIsSelectable(evt.target.checked)}
|
||||||
|
className="react-flow__selectable"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ReactFlow>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InteractionFlow;
|
||||||
@@ -6,7 +6,7 @@ import Overview from './Overview';
|
|||||||
import Basic from './Basic';
|
import Basic from './Basic';
|
||||||
import CustomNode from './CustomNode';
|
import CustomNode from './CustomNode';
|
||||||
import Stress from './Stress';
|
import Stress from './Stress';
|
||||||
import Inactive from './Inactive';
|
import Interaction from './Interaction';
|
||||||
import Empty from './Empty';
|
import Empty from './Empty';
|
||||||
import Edges from './Edges';
|
import Edges from './Edges';
|
||||||
import Validation from './Validation';
|
import Validation from './Validation';
|
||||||
@@ -60,8 +60,9 @@ const routes = [
|
|||||||
component: Empty,
|
component: Empty,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/inactive',
|
path: '/interaction',
|
||||||
component: Inactive,
|
component: Interaction,
|
||||||
|
label: 'Interaction',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const Controls = ({ style, showZoom = true, showFitView = true, showInteractive
|
|||||||
const zoomIn = useStoreActions((actions) => actions.zoomIn);
|
const zoomIn = useStoreActions((actions) => actions.zoomIn);
|
||||||
const zoomOut = useStoreActions((actions) => actions.zoomOut);
|
const zoomOut = useStoreActions((actions) => actions.zoomOut);
|
||||||
|
|
||||||
const isInteractive = useStoreState((s) => s.isInteractive);
|
const isInteractive = useStoreState((s) => s.nodesDraggable && s.nodesConnectable && s.elementsSelectable);
|
||||||
const mapClasses = classnames('react-flow__controls', className);
|
const mapClasses = classnames('react-flow__controls', className);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ interface ConnectionLineProps {
|
|||||||
connectionLineType: ConnectionLineType;
|
connectionLineType: ConnectionLineType;
|
||||||
nodes: Node[];
|
nodes: Node[];
|
||||||
transform: Transform;
|
transform: Transform;
|
||||||
isInteractive: boolean;
|
isConnectable: boolean;
|
||||||
connectionLineStyle?: CSSProperties;
|
connectionLineStyle?: CSSProperties;
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ export default ({
|
|||||||
nodes = [],
|
nodes = [],
|
||||||
className,
|
className,
|
||||||
transform,
|
transform,
|
||||||
isInteractive,
|
isConnectable,
|
||||||
}: ConnectionLineProps) => {
|
}: ConnectionLineProps) => {
|
||||||
const [sourceNode, setSourceNode] = useState<Node | null>(null);
|
const [sourceNode, setSourceNode] = useState<Node | null>(null);
|
||||||
const hasHandleId = connectionNodeId.includes('__');
|
const hasHandleId = connectionNodeId.includes('__');
|
||||||
@@ -39,7 +39,7 @@ export default ({
|
|||||||
setSourceNode(nextSourceNode);
|
setSourceNode(nextSourceNode);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!sourceNode || !isInteractive) {
|
if (!sourceNode || !isConnectable) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ interface EdgeWrapperProps {
|
|||||||
onClick?: (edge: Edge) => void;
|
onClick?: (edge: Edge) => void;
|
||||||
animated?: boolean;
|
animated?: boolean;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
isInteractive: boolean;
|
elementsSelectable: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (EdgeComponent: ComponentType<EdgeCompProps>) => {
|
export default (EdgeComponent: ComponentType<EdgeCompProps>) => {
|
||||||
@@ -30,7 +30,7 @@ export default (EdgeComponent: ComponentType<EdgeCompProps>) => {
|
|||||||
animated,
|
animated,
|
||||||
selected,
|
selected,
|
||||||
onClick,
|
onClick,
|
||||||
isInteractive,
|
elementsSelectable,
|
||||||
label,
|
label,
|
||||||
labelStyle,
|
labelStyle,
|
||||||
labelShowBg,
|
labelShowBg,
|
||||||
@@ -41,10 +41,10 @@ export default (EdgeComponent: ComponentType<EdgeCompProps>) => {
|
|||||||
const setSelectedElements = useStoreActions((a) => a.setSelectedElements);
|
const setSelectedElements = useStoreActions((a) => a.setSelectedElements);
|
||||||
const edgeClasses = cx('react-flow__edge', `react-flow__edge-${type}`, className, { selected, animated });
|
const edgeClasses = cx('react-flow__edge', `react-flow__edge-${type}`, className, { selected, animated });
|
||||||
const edgeGroupStyle: CSSProperties = {
|
const edgeGroupStyle: CSSProperties = {
|
||||||
pointerEvents: isInteractive ? 'all' : 'none',
|
pointerEvents: elementsSelectable ? 'all' : 'none',
|
||||||
};
|
};
|
||||||
const onEdgeClick = (): void => {
|
const onEdgeClick = (): void => {
|
||||||
if (!isInteractive) {
|
if (!elementsSelectable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { memo, useContext } from 'react';
|
import React, { memo, useContext } from 'react';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
|
||||||
import { useStoreActions, useStoreState } from '../../store/hooks';
|
import { useStoreActions, useStoreState } from '../../store/hooks';
|
||||||
import BaseHandle from './BaseHandle';
|
import BaseHandle from './BaseHandle';
|
||||||
@@ -12,6 +13,7 @@ const Handle = memo(
|
|||||||
position = Position.Top,
|
position = Position.Top,
|
||||||
onConnect = () => {},
|
onConnect = () => {},
|
||||||
isValidConnection = () => true,
|
isValidConnection = () => true,
|
||||||
|
isConnectable = true,
|
||||||
style,
|
style,
|
||||||
className,
|
className,
|
||||||
id,
|
id,
|
||||||
@@ -24,9 +26,12 @@ const Handle = memo(
|
|||||||
onConnectAction(params);
|
onConnectAction(params);
|
||||||
onConnect(params);
|
onConnect(params);
|
||||||
};
|
};
|
||||||
|
const handleClasses = classnames(className, { connectable: isConnectable });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseHandle
|
<BaseHandle
|
||||||
|
className={handleClasses}
|
||||||
|
id={id}
|
||||||
nodeId={nodeId}
|
nodeId={nodeId}
|
||||||
setPosition={setPosition}
|
setPosition={setPosition}
|
||||||
setConnectionNodeId={setConnectionNodeId}
|
setConnectionNodeId={setConnectionNodeId}
|
||||||
@@ -35,8 +40,6 @@ const Handle = memo(
|
|||||||
position={position}
|
position={position}
|
||||||
isValidConnection={isValidConnection}
|
isValidConnection={isValidConnection}
|
||||||
style={style}
|
style={style}
|
||||||
className={className}
|
|
||||||
id={id}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,15 @@ import React, { memo } from 'react';
|
|||||||
import Handle from '../../components/Handle';
|
import Handle from '../../components/Handle';
|
||||||
import { NodeProps, Position } from '../../types';
|
import { NodeProps, Position } from '../../types';
|
||||||
|
|
||||||
const DefaultNode = memo(({ data, targetPosition = Position.Top, sourcePosition = Position.Bottom }: NodeProps) => (
|
const DefaultNode = memo(
|
||||||
<>
|
({ data, isConnectable, targetPosition = Position.Top, sourcePosition = Position.Bottom }: NodeProps) => (
|
||||||
<Handle type="target" position={targetPosition} />
|
<>
|
||||||
{data.label}
|
<Handle type="target" position={targetPosition} isConnectable={isConnectable} />
|
||||||
<Handle type="source" position={sourcePosition} />
|
{data.label}
|
||||||
</>
|
<Handle type="source" position={sourcePosition} isConnectable={isConnectable} />
|
||||||
));
|
</>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
DefaultNode.displayName = 'DefaultNode';
|
DefaultNode.displayName = 'DefaultNode';
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import React, { memo } from 'react';
|
|||||||
import Handle from '../../components/Handle';
|
import Handle from '../../components/Handle';
|
||||||
import { NodeProps, Position } from '../../types';
|
import { NodeProps, Position } from '../../types';
|
||||||
|
|
||||||
const InputNode = memo(({ data, sourcePosition = Position.Bottom }: NodeProps) => (
|
const InputNode = memo(({ data, isConnectable, sourcePosition = Position.Bottom }: NodeProps) => (
|
||||||
<>
|
<>
|
||||||
{data.label}
|
{data.label}
|
||||||
<Handle type="source" position={sourcePosition} />
|
<Handle type="source" position={sourcePosition} isConnectable={isConnectable} />
|
||||||
</>
|
</>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import React, { memo } from 'react';
|
|||||||
import Handle from '../../components/Handle';
|
import Handle from '../../components/Handle';
|
||||||
import { NodeProps, Position } from '../../types';
|
import { NodeProps, Position } from '../../types';
|
||||||
|
|
||||||
const OutputNode = memo(({ data, targetPosition = Position.Top }: NodeProps) => (
|
const OutputNode = memo(({ data, isConnectable, targetPosition = Position.Top }: NodeProps) => (
|
||||||
<>
|
<>
|
||||||
<Handle type="target" position={targetPosition} />
|
<Handle type="target" position={targetPosition} isConnectable={isConnectable} />
|
||||||
{data.label}
|
{data.label}
|
||||||
</>
|
</>
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
import React, { useEffect, useRef, useState, memo, ComponentType, CSSProperties, useMemo, MouseEvent } from 'react';
|
import React, {
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
memo,
|
||||||
|
ComponentType,
|
||||||
|
CSSProperties,
|
||||||
|
useMemo,
|
||||||
|
MouseEvent,
|
||||||
|
useCallback,
|
||||||
|
} from 'react';
|
||||||
import { DraggableCore } from 'react-draggable';
|
import { DraggableCore } from 'react-draggable';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import { ResizeObserver } from 'resize-observer';
|
import { ResizeObserver } from 'resize-observer';
|
||||||
@@ -28,6 +38,7 @@ interface OnDragStartParams {
|
|||||||
type: string;
|
type: string;
|
||||||
data: any;
|
data: any;
|
||||||
selectNodesOnDrag: boolean;
|
selectNodesOnDrag: boolean;
|
||||||
|
isSelectable: boolean;
|
||||||
setOffset: (pos: XYPosition) => void;
|
setOffset: (pos: XYPosition) => void;
|
||||||
transform: Transform;
|
transform: Transform;
|
||||||
position: XYPosition;
|
position: XYPosition;
|
||||||
@@ -46,6 +57,7 @@ const onStart = ({
|
|||||||
transform,
|
transform,
|
||||||
position,
|
position,
|
||||||
setSelectedElements,
|
setSelectedElements,
|
||||||
|
isSelectable,
|
||||||
}: OnDragStartParams): false | void => {
|
}: OnDragStartParams): false | void => {
|
||||||
const startEvt = getMouseEvent(evt);
|
const startEvt = getMouseEvent(evt);
|
||||||
|
|
||||||
@@ -64,7 +76,7 @@ const onStart = ({
|
|||||||
onNodeDragStart(node);
|
onNodeDragStart(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectNodesOnDrag) {
|
if (selectNodesOnDrag && isSelectable) {
|
||||||
setSelectedElements({ id, type } as Node);
|
setSelectedElements({ id, type } as Node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -104,6 +116,7 @@ interface OnDragStopParams {
|
|||||||
position: XYPosition;
|
position: XYPosition;
|
||||||
data: any;
|
data: any;
|
||||||
selectNodesOnDrag: boolean;
|
selectNodesOnDrag: boolean;
|
||||||
|
isSelectable: boolean;
|
||||||
setSelectedElements: (elms: Elements | Node | Edge) => void;
|
setSelectedElements: (elms: Elements | Node | Edge) => void;
|
||||||
onNodeDragStop?: (node: Node) => void;
|
onNodeDragStop?: (node: Node) => void;
|
||||||
onClick?: (node: Node) => void;
|
onClick?: (node: Node) => void;
|
||||||
@@ -117,6 +130,7 @@ const onStop = ({
|
|||||||
isDragging,
|
isDragging,
|
||||||
setDragging,
|
setDragging,
|
||||||
selectNodesOnDrag,
|
selectNodesOnDrag,
|
||||||
|
isSelectable,
|
||||||
onNodeDragStop,
|
onNodeDragStop,
|
||||||
onClick,
|
onClick,
|
||||||
setSelectedElements,
|
setSelectedElements,
|
||||||
@@ -127,8 +141,7 @@ const onStop = ({
|
|||||||
position,
|
position,
|
||||||
data,
|
data,
|
||||||
} as Node;
|
} as Node;
|
||||||
|
if (!isDragging && isSelectable) {
|
||||||
if (!isDragging) {
|
|
||||||
if (!selectNodesOnDrag) {
|
if (!selectNodesOnDrag) {
|
||||||
setSelectedElements({ id, type } as Node);
|
setSelectedElements({ id, type } as Node);
|
||||||
}
|
}
|
||||||
@@ -164,7 +177,9 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
onNodeDragStop,
|
onNodeDragStop,
|
||||||
style,
|
style,
|
||||||
className,
|
className,
|
||||||
isInteractive,
|
isDraggable,
|
||||||
|
isSelectable,
|
||||||
|
isConnectable,
|
||||||
selectNodesOnDrag,
|
selectNodesOnDrag,
|
||||||
sourcePosition,
|
sourcePosition,
|
||||||
targetPosition,
|
targetPosition,
|
||||||
@@ -177,7 +192,10 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
||||||
const [isDragging, setDragging] = useState(false);
|
const [isDragging, setDragging] = useState(false);
|
||||||
const position = { x: xPos, y: yPos };
|
const position = { x: xPos, y: yPos };
|
||||||
const nodeClasses = cx('react-flow__node', `react-flow__node-${type}`, className, { selected });
|
const nodeClasses = cx('react-flow__node', `react-flow__node-${type}`, className, {
|
||||||
|
selected,
|
||||||
|
selectable: isSelectable,
|
||||||
|
});
|
||||||
const node = { id, type, position, data };
|
const node = { id, type, position, data };
|
||||||
const onMouseEnterHandler = useMemo(() => {
|
const onMouseEnterHandler = useMemo(() => {
|
||||||
if (!onMouseEnter || isDragging) {
|
if (!onMouseEnter || isDragging) {
|
||||||
@@ -211,10 +229,18 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
return (evt: MouseEvent) => onContextMenu(evt, node);
|
return (evt: MouseEvent) => onContextMenu(evt, node);
|
||||||
}, [onContextMenu]);
|
}, [onContextMenu]);
|
||||||
|
|
||||||
|
const onSelectNodeHandler = useCallback(() => {
|
||||||
|
if (!isDraggable && isSelectable) {
|
||||||
|
setSelectedElements({ id, type } as Node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return noop;
|
||||||
|
}, [isSelectable, isDraggable, id, type]);
|
||||||
|
|
||||||
const nodeStyle: CSSProperties = {
|
const nodeStyle: CSSProperties = {
|
||||||
zIndex: selected ? 10 : 3,
|
zIndex: selected ? 10 : 3,
|
||||||
transform: `translate(${xPos}px,${yPos}px)`,
|
transform: `translate(${xPos}px,${yPos}px)`,
|
||||||
pointerEvents: isInteractive ? 'all' : 'none',
|
pointerEvents: isSelectable || isDraggable ? 'all' : 'none',
|
||||||
...style,
|
...style,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -246,6 +272,7 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
onStart({
|
onStart({
|
||||||
evt: evt as MouseEvent,
|
evt: evt as MouseEvent,
|
||||||
selectNodesOnDrag,
|
selectNodesOnDrag,
|
||||||
|
isSelectable,
|
||||||
onNodeDragStart,
|
onNodeDragStart,
|
||||||
id,
|
id,
|
||||||
type,
|
type,
|
||||||
@@ -261,6 +288,7 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
onStop({
|
onStop({
|
||||||
onNodeDragStop,
|
onNodeDragStop,
|
||||||
selectNodesOnDrag,
|
selectNodesOnDrag,
|
||||||
|
isSelectable,
|
||||||
onClick,
|
onClick,
|
||||||
isDragging,
|
isDragging,
|
||||||
setDragging,
|
setDragging,
|
||||||
@@ -272,7 +300,7 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
scale={transform[2]}
|
scale={transform[2]}
|
||||||
disabled={!isInteractive}
|
disabled={!isDraggable}
|
||||||
cancel=".nodrag"
|
cancel=".nodrag"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -283,6 +311,7 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
onMouseMove={onMouseMoveHandler}
|
onMouseMove={onMouseMoveHandler}
|
||||||
onMouseLeave={onMouseLeaveHandler}
|
onMouseLeave={onMouseLeaveHandler}
|
||||||
onContextMenu={onContextMenuHandler}
|
onContextMenu={onContextMenuHandler}
|
||||||
|
onClick={onSelectNodeHandler}
|
||||||
>
|
>
|
||||||
<Provider value={id}>
|
<Provider value={id}>
|
||||||
<NodeComponent
|
<NodeComponent
|
||||||
@@ -290,6 +319,7 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
data={data}
|
data={data}
|
||||||
type={type}
|
type={type}
|
||||||
selected={selected}
|
selected={selected}
|
||||||
|
isConnectable={isConnectable}
|
||||||
sourcePosition={sourcePosition}
|
sourcePosition={sourcePosition}
|
||||||
targetPosition={targetPosition}
|
targetPosition={targetPosition}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { useStoreActions, useStoreState } from '../../store/hooks';
|
|||||||
import { XYPosition } from '../../types';
|
import { XYPosition } from '../../types';
|
||||||
|
|
||||||
type UserSelectionProps = {
|
type UserSelectionProps = {
|
||||||
isInteractive: boolean;
|
|
||||||
selectionKeyPressed: boolean;
|
selectionKeyPressed: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -45,8 +44,9 @@ const SelectionRect = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(({ isInteractive, selectionKeyPressed }: UserSelectionProps) => {
|
export default memo(({ selectionKeyPressed }: UserSelectionProps) => {
|
||||||
const selectionActive = useStoreState((s) => s.selectionActive);
|
const selectionActive = useStoreState((s) => s.selectionActive);
|
||||||
|
const elementsSelectable = useStoreState((s) => s.elementsSelectable);
|
||||||
|
|
||||||
const setUserSelection = useStoreActions((a) => a.setUserSelection);
|
const setUserSelection = useStoreActions((a) => a.setUserSelection);
|
||||||
const updateUserSelection = useStoreActions((a) => a.updateUserSelection);
|
const updateUserSelection = useStoreActions((a) => a.updateUserSelection);
|
||||||
@@ -59,7 +59,7 @@ export default memo(({ isInteractive, selectionKeyPressed }: UserSelectionProps)
|
|||||||
}
|
}
|
||||||
}, [selectionKeyPressed]);
|
}, [selectionKeyPressed]);
|
||||||
|
|
||||||
if (!isInteractive || !renderUserSelectionPane) {
|
if (!elementsSelectable || !renderUserSelectionPane) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ function renderEdge(
|
|||||||
props: EdgeRendererProps,
|
props: EdgeRendererProps,
|
||||||
nodes: Node[],
|
nodes: Node[],
|
||||||
selectedElements: Elements | null,
|
selectedElements: Elements | null,
|
||||||
isInteractive: boolean
|
elementsSelectable: boolean
|
||||||
) {
|
) {
|
||||||
const [sourceId, sourceHandleId] = edge.source.split('__');
|
const [sourceId, sourceHandleId] = edge.source.split('__');
|
||||||
const [targetId, targetHandleId] = edge.target.split('__');
|
const [targetId, targetHandleId] = edge.target.split('__');
|
||||||
@@ -181,7 +181,7 @@ function renderEdge(
|
|||||||
targetY={targetY}
|
targetY={targetY}
|
||||||
sourcePosition={sourcePosition}
|
sourcePosition={sourcePosition}
|
||||||
targetPosition={targetPosition}
|
targetPosition={targetPosition}
|
||||||
isInteractive={isInteractive}
|
elementsSelectable={elementsSelectable}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,8 @@ const EdgeRenderer = memo((props: EdgeRendererProps) => {
|
|||||||
const connectionHandleType = useStoreState((s) => s.connectionHandleType);
|
const connectionHandleType = useStoreState((s) => s.connectionHandleType);
|
||||||
const connectionPosition = useStoreState((s) => s.connectionPosition);
|
const connectionPosition = useStoreState((s) => s.connectionPosition);
|
||||||
const selectedElements = useStoreState((s) => s.selectedElements);
|
const selectedElements = useStoreState((s) => s.selectedElements);
|
||||||
const isInteractive = useStoreState((s) => s.isInteractive);
|
const nodesConnectable = useStoreState((s) => s.nodesConnectable);
|
||||||
|
const elementsSelectable = useStoreState((s) => s.elementsSelectable);
|
||||||
|
|
||||||
const { width, height, connectionLineStyle, connectionLineType } = props;
|
const { width, height, connectionLineStyle, connectionLineType } = props;
|
||||||
|
|
||||||
@@ -208,7 +209,7 @@ const EdgeRenderer = memo((props: EdgeRendererProps) => {
|
|||||||
return (
|
return (
|
||||||
<svg width={width} height={height} className="react-flow__edges">
|
<svg width={width} height={height} className="react-flow__edges">
|
||||||
<g transform={transformStyle}>
|
<g transform={transformStyle}>
|
||||||
{edges.map((e: Edge) => renderEdge(e, props, nodes, selectedElements, isInteractive))}
|
{edges.map((e: Edge) => renderEdge(e, props, nodes, selectedElements, elementsSelectable))}
|
||||||
{renderConnectionLine && (
|
{renderConnectionLine && (
|
||||||
<ConnectionLine
|
<ConnectionLine
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
@@ -219,7 +220,7 @@ const EdgeRenderer = memo((props: EdgeRendererProps) => {
|
|||||||
transform={[tX, tY, tScale]}
|
transform={[tX, tY, tScale]}
|
||||||
connectionLineStyle={connectionLineStyle}
|
connectionLineStyle={connectionLineStyle}
|
||||||
connectionLineType={connectionLineType}
|
connectionLineType={connectionLineType}
|
||||||
isInteractive={isInteractive}
|
isConnectable={nodesConnectable}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</g>
|
</g>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, { useEffect, useRef, memo, CSSProperties, MouseEvent } from 'react';
|
import React, { useEffect, useRef, memo, CSSProperties, MouseEvent } from 'react';
|
||||||
import classnames from 'classnames';
|
|
||||||
import { ResizeObserver } from 'resize-observer';
|
import { ResizeObserver } from 'resize-observer';
|
||||||
|
|
||||||
import { useStoreState, useStoreActions } from '../../store/hooks';
|
import { useStoreState, useStoreActions } from '../../store/hooks';
|
||||||
@@ -46,7 +45,9 @@ export interface GraphViewProps {
|
|||||||
snapToGrid: boolean;
|
snapToGrid: boolean;
|
||||||
snapGrid: [number, number];
|
snapGrid: [number, number];
|
||||||
onlyRenderVisibleNodes: boolean;
|
onlyRenderVisibleNodes: boolean;
|
||||||
isInteractive: boolean;
|
nodesDraggable: boolean;
|
||||||
|
nodesConnectable: boolean;
|
||||||
|
elementsSelectable: boolean;
|
||||||
selectNodesOnDrag: boolean;
|
selectNodesOnDrag: boolean;
|
||||||
minZoom: number;
|
minZoom: number;
|
||||||
maxZoom: number;
|
maxZoom: number;
|
||||||
@@ -76,7 +77,9 @@ const GraphView = memo(
|
|||||||
snapToGrid,
|
snapToGrid,
|
||||||
snapGrid,
|
snapGrid,
|
||||||
onlyRenderVisibleNodes,
|
onlyRenderVisibleNodes,
|
||||||
isInteractive,
|
nodesDraggable,
|
||||||
|
nodesConnectable,
|
||||||
|
elementsSelectable,
|
||||||
selectNodesOnDrag,
|
selectNodesOnDrag,
|
||||||
minZoom,
|
minZoom,
|
||||||
maxZoom,
|
maxZoom,
|
||||||
@@ -92,14 +95,15 @@ const GraphView = memo(
|
|||||||
const setNodesSelection = useStoreActions((actions) => actions.setNodesSelection);
|
const setNodesSelection = useStoreActions((actions) => actions.setNodesSelection);
|
||||||
const setOnConnect = useStoreActions((a) => a.setOnConnect);
|
const setOnConnect = useStoreActions((a) => a.setOnConnect);
|
||||||
const setSnapGrid = useStoreActions((actions) => actions.setSnapGrid);
|
const setSnapGrid = useStoreActions((actions) => actions.setSnapGrid);
|
||||||
const setInteractive = useStoreActions((actions) => actions.setInteractive);
|
const setNodesDraggable = useStoreActions((actions) => actions.setNodesDraggable);
|
||||||
|
const setNodesConnectable = useStoreActions((actions) => actions.setNodesConnectable);
|
||||||
|
const setElementsSelectable = useStoreActions((actions) => actions.setElementsSelectable);
|
||||||
const updateTransform = useStoreActions((actions) => actions.updateTransform);
|
const updateTransform = useStoreActions((actions) => actions.updateTransform);
|
||||||
const setMinMaxZoom = useStoreActions((actions) => actions.setMinMaxZoom);
|
const setMinMaxZoom = useStoreActions((actions) => actions.setMinMaxZoom);
|
||||||
const fitView = useStoreActions((actions) => actions.fitView);
|
const fitView = useStoreActions((actions) => actions.fitView);
|
||||||
const zoom = useStoreActions((actions) => actions.zoom);
|
const zoom = useStoreActions((actions) => actions.zoom);
|
||||||
|
|
||||||
const selectionKeyPressed = useKeyPress(selectionKeyCode);
|
const selectionKeyPressed = useKeyPress(selectionKeyCode);
|
||||||
const rendererClasses = classnames('react-flow__renderer', { 'is-interactive': isInteractive });
|
|
||||||
|
|
||||||
const onZoomPaneClick = () => setNodesSelection({ isActive: false });
|
const onZoomPaneClick = () => setNodesSelection({ isActive: false });
|
||||||
|
|
||||||
@@ -169,8 +173,16 @@ const GraphView = memo(
|
|||||||
}, [snapToGrid]);
|
}, [snapToGrid]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInteractive(isInteractive);
|
setNodesDraggable(nodesDraggable);
|
||||||
}, [isInteractive]);
|
}, [nodesDraggable]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setNodesConnectable(nodesConnectable);
|
||||||
|
}, [nodesConnectable]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setElementsSelectable(elementsSelectable);
|
||||||
|
}, [elementsSelectable]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMinMaxZoom({ minZoom, maxZoom });
|
setMinMaxZoom({ minZoom, maxZoom });
|
||||||
@@ -180,7 +192,7 @@ const GraphView = memo(
|
|||||||
useElementUpdater(elements);
|
useElementUpdater(elements);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={rendererClasses} ref={rendererNode}>
|
<div className="react-flow__renderer" ref={rendererNode}>
|
||||||
<NodeRenderer
|
<NodeRenderer
|
||||||
nodeTypes={nodeTypes}
|
nodeTypes={nodeTypes}
|
||||||
onElementClick={onElementClick}
|
onElementClick={onElementClick}
|
||||||
@@ -201,7 +213,7 @@ const GraphView = memo(
|
|||||||
connectionLineType={connectionLineType}
|
connectionLineType={connectionLineType}
|
||||||
connectionLineStyle={connectionLineStyle}
|
connectionLineStyle={connectionLineStyle}
|
||||||
/>
|
/>
|
||||||
<UserSelection selectionKeyPressed={selectionKeyPressed} isInteractive={isInteractive} />
|
<UserSelection selectionKeyPressed={selectionKeyPressed} />
|
||||||
{nodesSelectionActive && <NodesSelection />}
|
{nodesSelectionActive && <NodesSelection />}
|
||||||
<div className="react-flow__zoompane" onClick={onZoomPaneClick} ref={zoomPane} />
|
<div className="react-flow__zoompane" onClick={onZoomPaneClick} ref={zoomPane} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ function renderNode(
|
|||||||
props: NodeRendererProps,
|
props: NodeRendererProps,
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
selectedElements: Elements | null,
|
selectedElements: Elements | null,
|
||||||
isInteractive: boolean
|
nodesDraggable: boolean,
|
||||||
|
nodesConnectable: boolean,
|
||||||
|
elementsSelectable: boolean
|
||||||
) {
|
) {
|
||||||
const nodeType = node.type || 'default';
|
const nodeType = node.type || 'default';
|
||||||
const NodeComponent = (props.nodeTypes[nodeType] || props.nodeTypes.default) as ComponentType<WrapNodeProps>;
|
const NodeComponent = (props.nodeTypes[nodeType] || props.nodeTypes.default) as ComponentType<WrapNodeProps>;
|
||||||
@@ -51,7 +53,9 @@ function renderNode(
|
|||||||
selected={isSelected}
|
selected={isSelected}
|
||||||
style={node.style}
|
style={node.style}
|
||||||
className={node.className}
|
className={node.className}
|
||||||
isInteractive={isInteractive}
|
isDraggable={nodesDraggable}
|
||||||
|
isSelectable={elementsSelectable}
|
||||||
|
isConnectable={nodesConnectable}
|
||||||
sourcePosition={node.sourcePosition}
|
sourcePosition={node.sourcePosition}
|
||||||
targetPosition={node.targetPosition}
|
targetPosition={node.targetPosition}
|
||||||
selectNodesOnDrag={props.selectNodesOnDrag}
|
selectNodesOnDrag={props.selectNodesOnDrag}
|
||||||
@@ -65,7 +69,10 @@ const NodeRenderer = memo(({ onlyRenderVisibleNodes = true, ...props }: NodeRend
|
|||||||
const selectedElements = useStoreState((s) => s.selectedElements);
|
const selectedElements = useStoreState((s) => s.selectedElements);
|
||||||
const width = useStoreState((s) => s.width);
|
const width = useStoreState((s) => s.width);
|
||||||
const height = useStoreState((s) => s.height);
|
const height = useStoreState((s) => s.height);
|
||||||
const isInteractive = useStoreState((s) => s.isInteractive);
|
const nodesDraggable = useStoreState((s) => s.nodesDraggable);
|
||||||
|
const nodesConnectable = useStoreState((s) => s.nodesConnectable);
|
||||||
|
const elementsSelectable = useStoreState((s) => s.elementsSelectable);
|
||||||
|
|
||||||
const [tX, tY, tScale] = transform;
|
const [tX, tY, tScale] = transform;
|
||||||
const transformStyle = {
|
const transformStyle = {
|
||||||
transform: `translate(${tX}px,${tY}px) scale(${tScale})`,
|
transform: `translate(${tX}px,${tY}px) scale(${tScale})`,
|
||||||
@@ -77,7 +84,9 @@ const NodeRenderer = memo(({ onlyRenderVisibleNodes = true, ...props }: NodeRend
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="react-flow__nodes" style={transformStyle}>
|
<div className="react-flow__nodes" style={transformStyle}>
|
||||||
{renderNodes.map((node) => renderNode(node, props, transform, selectedElements, isInteractive))}
|
{renderNodes.map((node) =>
|
||||||
|
renderNode(node, props, transform, selectedElements, nodesDraggable, nodesConnectable, elementsSelectable)
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
|
|||||||
snapToGrid: boolean;
|
snapToGrid: boolean;
|
||||||
snapGrid: [number, number];
|
snapGrid: [number, number];
|
||||||
onlyRenderVisibleNodes: boolean;
|
onlyRenderVisibleNodes: boolean;
|
||||||
isInteractive: boolean;
|
nodesDraggable: boolean;
|
||||||
|
nodesConnectable: boolean;
|
||||||
|
elementsSelectable: boolean;
|
||||||
selectNodesOnDrag: boolean;
|
selectNodesOnDrag: boolean;
|
||||||
minZoom: number;
|
minZoom: number;
|
||||||
maxZoom: number;
|
maxZoom: number;
|
||||||
@@ -89,7 +91,9 @@ const ReactFlow = ({
|
|||||||
snapToGrid,
|
snapToGrid,
|
||||||
snapGrid,
|
snapGrid,
|
||||||
onlyRenderVisibleNodes,
|
onlyRenderVisibleNodes,
|
||||||
isInteractive,
|
nodesDraggable,
|
||||||
|
nodesConnectable,
|
||||||
|
elementsSelectable,
|
||||||
selectNodesOnDrag,
|
selectNodesOnDrag,
|
||||||
minZoom,
|
minZoom,
|
||||||
maxZoom,
|
maxZoom,
|
||||||
@@ -123,7 +127,9 @@ const ReactFlow = ({
|
|||||||
snapToGrid={snapToGrid}
|
snapToGrid={snapToGrid}
|
||||||
snapGrid={snapGrid}
|
snapGrid={snapGrid}
|
||||||
onlyRenderVisibleNodes={onlyRenderVisibleNodes}
|
onlyRenderVisibleNodes={onlyRenderVisibleNodes}
|
||||||
isInteractive={isInteractive}
|
nodesDraggable={nodesDraggable}
|
||||||
|
nodesConnectable={nodesConnectable}
|
||||||
|
elementsSelectable={elementsSelectable}
|
||||||
selectNodesOnDrag={selectNodesOnDrag}
|
selectNodesOnDrag={selectNodesOnDrag}
|
||||||
minZoom={minZoom}
|
minZoom={minZoom}
|
||||||
maxZoom={maxZoom}
|
maxZoom={maxZoom}
|
||||||
@@ -156,7 +162,9 @@ ReactFlow.defaultProps = {
|
|||||||
snapToGrid: false,
|
snapToGrid: false,
|
||||||
snapGrid: [16, 16],
|
snapGrid: [16, 16],
|
||||||
onlyRenderVisibleNodes: true,
|
onlyRenderVisibleNodes: true,
|
||||||
isInteractive: true,
|
nodesDraggable: true,
|
||||||
|
nodesConnectable: true,
|
||||||
|
elementsSelectable: true,
|
||||||
selectNodesOnDrag: true,
|
selectNodesOnDrag: true,
|
||||||
minZoom: 0.5,
|
minZoom: 0.5,
|
||||||
maxZoom: 2,
|
maxZoom: 2,
|
||||||
|
|||||||
+24
-3
@@ -79,7 +79,9 @@ export interface StoreModel {
|
|||||||
snapToGrid: boolean;
|
snapToGrid: boolean;
|
||||||
snapGrid: [number, number];
|
snapGrid: [number, number];
|
||||||
|
|
||||||
isInteractive: boolean;
|
nodesDraggable: boolean;
|
||||||
|
nodesConnectable: boolean;
|
||||||
|
elementsSelectable: boolean;
|
||||||
|
|
||||||
reactFlowVersion: string;
|
reactFlowVersion: string;
|
||||||
|
|
||||||
@@ -116,6 +118,9 @@ export interface StoreModel {
|
|||||||
setConnectionNodeId: Action<StoreModel, SetConnectionId>;
|
setConnectionNodeId: Action<StoreModel, SetConnectionId>;
|
||||||
|
|
||||||
setInteractive: Action<StoreModel, boolean>;
|
setInteractive: Action<StoreModel, boolean>;
|
||||||
|
setNodesDraggable: Action<StoreModel, boolean>;
|
||||||
|
setNodesConnectable: Action<StoreModel, boolean>;
|
||||||
|
setElementsSelectable: Action<StoreModel, boolean>;
|
||||||
|
|
||||||
setUserSelection: Action<StoreModel, XYPosition>;
|
setUserSelection: Action<StoreModel, XYPosition>;
|
||||||
updateUserSelection: Action<StoreModel, XYPosition>;
|
updateUserSelection: Action<StoreModel, XYPosition>;
|
||||||
@@ -162,7 +167,9 @@ export const storeModel: StoreModel = {
|
|||||||
snapGrid: [16, 16],
|
snapGrid: [16, 16],
|
||||||
snapToGrid: false,
|
snapToGrid: false,
|
||||||
|
|
||||||
isInteractive: true,
|
nodesDraggable: true,
|
||||||
|
nodesConnectable: true,
|
||||||
|
elementsSelectable: true,
|
||||||
|
|
||||||
reactFlowVersion: typeof __REACT_FLOW_VERSION__ !== 'undefined' ? __REACT_FLOW_VERSION__ : '-',
|
reactFlowVersion: typeof __REACT_FLOW_VERSION__ !== 'undefined' ? __REACT_FLOW_VERSION__ : '-',
|
||||||
|
|
||||||
@@ -373,7 +380,21 @@ export const storeModel: StoreModel = {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
setInteractive: action((state, isInteractive) => {
|
setInteractive: action((state, isInteractive) => {
|
||||||
state.isInteractive = isInteractive;
|
state.nodesDraggable = isInteractive;
|
||||||
|
state.nodesConnectable = isInteractive;
|
||||||
|
state.elementsSelectable = isInteractive;
|
||||||
|
}),
|
||||||
|
|
||||||
|
setNodesDraggable: action((state, nodesDraggable) => {
|
||||||
|
state.nodesDraggable = nodesDraggable;
|
||||||
|
}),
|
||||||
|
|
||||||
|
setNodesConnectable: action((state, nodesConnectable) => {
|
||||||
|
state.nodesConnectable = nodesConnectable;
|
||||||
|
}),
|
||||||
|
|
||||||
|
setElementsSelectable: action((state, elementsSelectable) => {
|
||||||
|
state.elementsSelectable = elementsSelectable;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
fitView: action((state, payload = { padding: 0.1 }) => {
|
fitView: action((state, payload = { padding: 0.1 }) => {
|
||||||
|
|||||||
+10
-1
@@ -112,7 +112,11 @@
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #222;
|
color: #222;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-flow__node-default.selectable,
|
||||||
|
.react-flow__node-input.selectable,
|
||||||
|
.react-flow__node-output.selectable {
|
||||||
&.selected,
|
&.selected,
|
||||||
&.selected:hover {
|
&.selected:hover {
|
||||||
box-shadow: 0 0 0 2px #555;
|
box-shadow: 0 0 0 2px #555;
|
||||||
@@ -158,7 +162,12 @@
|
|||||||
width: 10px;
|
width: 10px;
|
||||||
height: 8px;
|
height: 8px;
|
||||||
background: rgba(255, 255, 255, 0.4);
|
background: rgba(255, 255, 255, 0.4);
|
||||||
cursor: crosshair;
|
pointer-events: none;
|
||||||
|
|
||||||
|
&.connectable {
|
||||||
|
pointer-events: all;
|
||||||
|
cursor: crosshair;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.react-flow__handle-bottom {
|
.react-flow__handle-bottom {
|
||||||
|
|||||||
+6
-1
@@ -94,6 +94,7 @@ export interface NodeProps {
|
|||||||
type: string;
|
type: string;
|
||||||
data: any;
|
data: any;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
|
isConnectable: boolean;
|
||||||
targetPosition?: Position;
|
targetPosition?: Position;
|
||||||
sourcePosition?: Position;
|
sourcePosition?: Position;
|
||||||
}
|
}
|
||||||
@@ -102,6 +103,7 @@ export interface NodeComponentProps {
|
|||||||
id: ElementId;
|
id: ElementId;
|
||||||
type: string;
|
type: string;
|
||||||
data: any;
|
data: any;
|
||||||
|
isConnectable: boolean;
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
transform?: Transform;
|
transform?: Transform;
|
||||||
xPos?: number;
|
xPos?: number;
|
||||||
@@ -126,7 +128,9 @@ export interface WrapNodeProps {
|
|||||||
transform: Transform;
|
transform: Transform;
|
||||||
xPos: number;
|
xPos: number;
|
||||||
yPos: number;
|
yPos: number;
|
||||||
isInteractive: boolean;
|
isSelectable: boolean;
|
||||||
|
isDraggable: boolean;
|
||||||
|
isConnectable: boolean;
|
||||||
selectNodesOnDrag: boolean;
|
selectNodesOnDrag: boolean;
|
||||||
onClick?: (node: Node) => void;
|
onClick?: (node: Node) => void;
|
||||||
onMouseEnter?: (evt: MouseEvent, node: Node) => void;
|
onMouseEnter?: (evt: MouseEvent, node: Node) => void;
|
||||||
@@ -182,6 +186,7 @@ export interface HandleElement extends XYPosition, Dimensions {
|
|||||||
export interface HandleProps {
|
export interface HandleProps {
|
||||||
type: HandleType;
|
type: HandleType;
|
||||||
position: Position;
|
position: Position;
|
||||||
|
isConnectable?: boolean;
|
||||||
onConnect?: OnConnectFunc;
|
onConnect?: OnConnectFunc;
|
||||||
isValidConnection?: (connection: Connection) => boolean;
|
isValidConnection?: (connection: Connection) => boolean;
|
||||||
id?: string;
|
id?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user