fix(elementsSelectable): still draggable if not selectable
This commit is contained in:
@@ -15,7 +15,7 @@ import ReactFlow, {
|
|||||||
} from 'react-flow-renderer';
|
} from 'react-flow-renderer';
|
||||||
import DebugNode from './DebugNode';
|
import DebugNode from './DebugNode';
|
||||||
|
|
||||||
const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node);
|
const onNodeDragStop = (_: MouseEvent, node: Node, nodes: Node[]) => console.log('drag stop', node, nodes);
|
||||||
const onNodeClick = (_: MouseEvent, node: Node) => console.log('click', node);
|
const onNodeClick = (_: MouseEvent, node: Node) => console.log('click', node);
|
||||||
const onEdgeClick = (_: MouseEvent, edge: Edge) => console.log('click', edge);
|
const onEdgeClick = (_: MouseEvent, edge: Edge) => console.log('click', edge);
|
||||||
|
|
||||||
@@ -105,15 +105,12 @@ const nodeTypes = {
|
|||||||
default: DebugNode,
|
default: DebugNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
const BasicFlow = () => {
|
const Subflow = () => {
|
||||||
const [rfInstance, setRfInstance] = useState<ReactFlowInstance | null>(null);
|
const [rfInstance, setRfInstance] = useState<ReactFlowInstance | null>(null);
|
||||||
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
|
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
|
||||||
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
||||||
|
|
||||||
const onConnect = useCallback((connection: Connection) => {
|
const onConnect = useCallback((connection: Connection) => setEdges((eds) => addEdge(connection, eds)), [setEdges]);
|
||||||
setEdges((eds) => addEdge(connection, eds));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const onInit = useCallback((reactFlowInstance: ReactFlowInstance) => setRfInstance(reactFlowInstance), []);
|
const onInit = useCallback((reactFlowInstance: ReactFlowInstance) => setRfInstance(reactFlowInstance), []);
|
||||||
|
|
||||||
const updatePos = () => {
|
const updatePos = () => {
|
||||||
@@ -194,4 +191,4 @@ const BasicFlow = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default BasicFlow;
|
export default Subflow;
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "react-flow-renderer",
|
"name": "react-flow-renderer",
|
||||||
"version": "10.2.3",
|
"version": "10.2.4-next.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "react-flow-renderer",
|
"name": "react-flow-renderer",
|
||||||
"version": "10.2.3",
|
"version": "10.2.4-next.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.17.9",
|
"@babel/runtime": "^7.17.9",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-flow-renderer",
|
"name": "react-flow-renderer",
|
||||||
"version": "10.2.3",
|
"version": "10.2.4-next.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ function useDrag({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mousePos = getMousePosition(event);
|
const mousePos = getMousePosition(event);
|
||||||
dragItems.current = getDragItems(nodeInternals, mousePos);
|
dragItems.current = getDragItems(nodeInternals, mousePos, nodeId);
|
||||||
|
|
||||||
if (onStart && dragItems.current) {
|
if (onStart && dragItems.current) {
|
||||||
const [currentNode, nodes] = getEventHandlerParams({
|
const [currentNode, nodes] = getEventHandlerParams({
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ export function selectorExistsTargetToNode(target: Element, selector: string, no
|
|||||||
}
|
}
|
||||||
|
|
||||||
// looks for all selected nodes and created a NodeDragItem for each of them
|
// looks for all selected nodes and created a NodeDragItem for each of them
|
||||||
export function getDragItems(nodeInternals: NodeInternals, mousePos: XYPosition): NodeDragItem[] {
|
export function getDragItems(nodeInternals: NodeInternals, mousePos: XYPosition, nodeId?: string): NodeDragItem[] {
|
||||||
return Array.from(nodeInternals.values())
|
return Array.from(nodeInternals.values())
|
||||||
.filter((n) => n.selected && (!n.parentNode || !isParentSelected(n, nodeInternals)))
|
.filter((n) => (n.selected || n.id === nodeId) && (!n.parentNode || !isParentSelected(n, nodeInternals)))
|
||||||
.map((n) => ({
|
.map((n) => ({
|
||||||
id: n.id,
|
id: n.id,
|
||||||
position: n.position,
|
position: n.position,
|
||||||
|
|||||||
Reference in New Issue
Block a user