Feature: Draggable edge
This commit is contained in:
@@ -32,6 +32,7 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
|
||||
elementsSelectable,
|
||||
markerEndId,
|
||||
isHidden,
|
||||
onEitherEndOfEdgePress,
|
||||
}: WrapEdgeProps) => {
|
||||
const setSelectedElements = useStoreActions((actions) => actions.setSelectedElements);
|
||||
|
||||
@@ -63,12 +64,53 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
|
||||
[elementsSelectable, id, source, target, type, data, onClick]
|
||||
);
|
||||
|
||||
const handleEitherEndOfEdgePress = useCallback(
|
||||
(event: React.MouseEvent<SVGGElement, MouseEvent>, isEdgeHeader?: boolean): void => {
|
||||
if (elementsSelectable) {
|
||||
setSelectedElements({ id, source, target });
|
||||
}
|
||||
|
||||
const edgeElement: Edge = { id, source, target, type };
|
||||
|
||||
if (typeof data !== 'undefined') {
|
||||
edgeElement.data = data;
|
||||
}
|
||||
|
||||
onEitherEndOfEdgePress(event, edgeElement, isEdgeHeader);
|
||||
},
|
||||
[elementsSelectable, id, source, target, type, data, onEitherEndOfEdgePress]
|
||||
);
|
||||
|
||||
const handleEdgeHeaderPress = useCallback(
|
||||
(event: React.MouseEvent<SVGGElement, MouseEvent>): void => {
|
||||
handleEitherEndOfEdgePress(event, true);
|
||||
},
|
||||
[handleEitherEndOfEdgePress],
|
||||
);
|
||||
|
||||
const handleEdgeFooterPress = useCallback(
|
||||
(event: React.MouseEvent<SVGGElement, MouseEvent>): void => {
|
||||
handleEitherEndOfEdgePress(event);
|
||||
},
|
||||
[handleEitherEndOfEdgePress],
|
||||
);
|
||||
|
||||
if (isHidden) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<g className={edgeClasses} onClick={onEdgeClick} style={edgeGroupStyle}>
|
||||
<g onMouseDown={handleEdgeFooterPress}>
|
||||
<circle
|
||||
className="move-handler"
|
||||
cx={sourceX}
|
||||
cy={sourceY}
|
||||
r="12"
|
||||
stroke="transparent"
|
||||
fill="transparent"
|
||||
/>
|
||||
</g>
|
||||
<EdgeComponent
|
||||
id={id}
|
||||
source={source}
|
||||
@@ -92,6 +134,16 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
|
||||
targetPosition={targetPosition}
|
||||
markerEndId={markerEndId}
|
||||
/>
|
||||
<g onMouseDown={handleEdgeHeaderPress}>
|
||||
<circle
|
||||
className="move-handler"
|
||||
cx={targetX}
|
||||
cy={targetY}
|
||||
r="12"
|
||||
stroke="transparent"
|
||||
fill="transparent"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from '../../types';
|
||||
|
||||
type ValidConnectionFunc = (connection: Connection) => boolean;
|
||||
type SetSourceIdFunc = (params: SetConnectionId) => void;
|
||||
export type SetSourceIdFunc = (params: SetConnectionId) => void;
|
||||
|
||||
interface BaseHandleProps {
|
||||
type: HandleType;
|
||||
@@ -40,7 +40,7 @@ type Result = {
|
||||
isHoveringHandle: boolean;
|
||||
};
|
||||
|
||||
function onMouseDown(
|
||||
export function onMouseDown(
|
||||
event: ReactMouseEvent,
|
||||
nodeId: ElementId,
|
||||
setConnectionNodeId: SetSourceIdFunc,
|
||||
@@ -67,7 +67,7 @@ function onMouseDown(
|
||||
y: event.clientY - containerBounds.top,
|
||||
});
|
||||
setConnectionNodeId({ connectionNodeId: nodeId, connectionHandleType: handleType });
|
||||
|
||||
|
||||
if (onConnectStart) {
|
||||
onConnectStart(event, { nodeId, handleType });
|
||||
}
|
||||
@@ -136,7 +136,7 @@ function onMouseDown(
|
||||
|
||||
function onMouseUp(event: MouseEvent) {
|
||||
const { connection, isValid } = checkElementBelowIsValid(event);
|
||||
|
||||
|
||||
if (onConnectStop) {
|
||||
onConnectStop(event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user