feat(props): add connectOnClick
This commit is contained in:
@@ -19,6 +19,7 @@ const selector = (s: ReactFlowState) => ({
|
|||||||
onConnectEnd: s.onConnectEnd,
|
onConnectEnd: s.onConnectEnd,
|
||||||
connectionMode: s.connectionMode,
|
connectionMode: s.connectionMode,
|
||||||
connectionStartHandle: s.connectionStartHandle,
|
connectionStartHandle: s.connectionStartHandle,
|
||||||
|
connectOnClick: s.connectOnClick,
|
||||||
});
|
});
|
||||||
|
|
||||||
const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
|
const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
|
||||||
@@ -38,8 +39,15 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
|
|||||||
) => {
|
) => {
|
||||||
const store = useStoreApi();
|
const store = useStoreApi();
|
||||||
const nodeId = useContext(NodeIdContext) as string;
|
const nodeId = useContext(NodeIdContext) as string;
|
||||||
const { onConnectAction, onConnectStart, onConnectStop, onConnectEnd, connectionMode, connectionStartHandle } =
|
const {
|
||||||
useStore(selector, shallow);
|
onConnectAction,
|
||||||
|
onConnectStart,
|
||||||
|
onConnectStop,
|
||||||
|
onConnectEnd,
|
||||||
|
connectionMode,
|
||||||
|
connectionStartHandle,
|
||||||
|
connectOnClick,
|
||||||
|
} = useStore(selector, shallow);
|
||||||
|
|
||||||
const handleId = id || null;
|
const handleId = id || null;
|
||||||
const isTarget = type === 'target';
|
const isTarget = type === 'target';
|
||||||
@@ -147,7 +155,7 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
|
|||||||
data-handlepos={position}
|
data-handlepos={position}
|
||||||
className={handleClasses}
|
className={handleClasses}
|
||||||
onMouseDown={onMouseDownHandler}
|
onMouseDown={onMouseDownHandler}
|
||||||
onClick={onClick}
|
onClick={connectOnClick ? onClick : undefined}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ interface StoreUpdaterProps {
|
|||||||
snapGrid?: SnapGrid;
|
snapGrid?: SnapGrid;
|
||||||
translateExtent?: CoordinateExtent;
|
translateExtent?: CoordinateExtent;
|
||||||
fitViewOnInit: boolean;
|
fitViewOnInit: boolean;
|
||||||
|
connectOnClick: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selector = (s: ReactFlowState) => ({
|
const selector = (s: ReactFlowState) => ({
|
||||||
@@ -87,6 +88,7 @@ const StoreUpdater = ({
|
|||||||
snapToGrid,
|
snapToGrid,
|
||||||
translateExtent,
|
translateExtent,
|
||||||
fitViewOnInit,
|
fitViewOnInit,
|
||||||
|
connectOnClick,
|
||||||
}: StoreUpdaterProps) => {
|
}: StoreUpdaterProps) => {
|
||||||
const { setNodes, setEdges, setMinZoom, setMaxZoom, setTranslateExtent, setNodeExtent, reset } = useStore(
|
const { setNodes, setEdges, setMinZoom, setMaxZoom, setTranslateExtent, setNodeExtent, reset } = useStore(
|
||||||
selector,
|
selector,
|
||||||
@@ -120,6 +122,7 @@ const StoreUpdater = ({
|
|||||||
useDirectStoreUpdater('snapGrid', snapGrid, store.setState);
|
useDirectStoreUpdater('snapGrid', snapGrid, store.setState);
|
||||||
useDirectStoreUpdater('onNodesChange', onNodesChange, store.setState);
|
useDirectStoreUpdater('onNodesChange', onNodesChange, store.setState);
|
||||||
useDirectStoreUpdater('onEdgesChange', onEdgesChange, store.setState);
|
useDirectStoreUpdater('onEdgesChange', onEdgesChange, store.setState);
|
||||||
|
useDirectStoreUpdater('connectOnClick', connectOnClick, store.setState);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
|
|||||||
noWheelClassName?: string;
|
noWheelClassName?: string;
|
||||||
noPanClassName?: string;
|
noPanClassName?: string;
|
||||||
fitViewOnInit?: boolean;
|
fitViewOnInit?: boolean;
|
||||||
|
connectOnClick?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ReactFlowRefType = HTMLDivElement;
|
export type ReactFlowRefType = HTMLDivElement;
|
||||||
@@ -221,6 +222,7 @@ const ReactFlow: FunctionComponent<ReactFlowProps> = forwardRef<ReactFlowRefType
|
|||||||
noWheelClassName = 'nowheel',
|
noWheelClassName = 'nowheel',
|
||||||
noPanClassName = 'nopan',
|
noPanClassName = 'nopan',
|
||||||
fitViewOnInit = false,
|
fitViewOnInit = false,
|
||||||
|
connectOnClick = true,
|
||||||
...rest
|
...rest
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
@@ -309,6 +311,7 @@ const ReactFlow: FunctionComponent<ReactFlowProps> = forwardRef<ReactFlowRefType
|
|||||||
connectionMode={connectionMode}
|
connectionMode={connectionMode}
|
||||||
translateExtent={translateExtent}
|
translateExtent={translateExtent}
|
||||||
fitViewOnInit={fitViewOnInit}
|
fitViewOnInit={fitViewOnInit}
|
||||||
|
connectOnClick={connectOnClick}
|
||||||
/>
|
/>
|
||||||
{onSelectionChange && <SelectionListener onSelectionChange={onSelectionChange} />}
|
{onSelectionChange && <SelectionListener onSelectionChange={onSelectionChange} />}
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ const initialState: ReactFlowStore = {
|
|||||||
fitViewOnInitDone: false,
|
fitViewOnInitDone: false,
|
||||||
|
|
||||||
connectionStartHandle: null,
|
connectionStartHandle: null,
|
||||||
|
connectOnClick: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default initialState;
|
export default initialState;
|
||||||
|
|||||||
@@ -184,6 +184,8 @@ export type ReactFlowStore = {
|
|||||||
onConnectStart?: OnConnectStart;
|
onConnectStart?: OnConnectStart;
|
||||||
onConnectStop?: OnConnectStop;
|
onConnectStop?: OnConnectStop;
|
||||||
onConnectEnd?: OnConnectEnd;
|
onConnectEnd?: OnConnectEnd;
|
||||||
|
|
||||||
|
connectOnClick: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ReactFlowActions = {
|
export type ReactFlowActions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user