fix(elementsSelectable): still draggable if not selectable

This commit is contained in:
moklick
2022-05-19 12:49:35 +02:00
parent 0d3439903c
commit 94321613f2
5 changed files with 10 additions and 13 deletions

View File

@@ -15,7 +15,7 @@ import ReactFlow, {
} from 'react-flow-renderer';
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 onEdgeClick = (_: MouseEvent, edge: Edge) => console.log('click', edge);
@@ -105,15 +105,12 @@ const nodeTypes = {
default: DebugNode,
};
const BasicFlow = () => {
const Subflow = () => {
const [rfInstance, setRfInstance] = useState<ReactFlowInstance | null>(null);
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
const onConnect = useCallback((connection: Connection) => {
setEdges((eds) => addEdge(connection, eds));
}, []);
const onConnect = useCallback((connection: Connection) => setEdges((eds) => addEdge(connection, eds)), [setEdges]);
const onInit = useCallback((reactFlowInstance: ReactFlowInstance) => setRfInstance(reactFlowInstance), []);
const updatePos = () => {
@@ -194,4 +191,4 @@ const BasicFlow = () => {
);
};
export default BasicFlow;
export default Subflow;

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "react-flow-renderer",
"version": "10.2.3",
"version": "10.2.4-next.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "react-flow-renderer",
"version": "10.2.3",
"version": "10.2.4-next.0",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.17.9",

View File

@@ -1,6 +1,6 @@
{
"name": "react-flow-renderer",
"version": "10.2.3",
"version": "10.2.4-next.0",
"engines": {
"node": ">=14"
},

View File

@@ -101,7 +101,7 @@ function useDrag({
}
const mousePos = getMousePosition(event);
dragItems.current = getDragItems(nodeInternals, mousePos);
dragItems.current = getDragItems(nodeInternals, mousePos, nodeId);
if (onStart && dragItems.current) {
const [currentNode, nodes] = getEventHandlerParams({

View File

@@ -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
export function getDragItems(nodeInternals: NodeInternals, mousePos: XYPosition): NodeDragItem[] {
export function getDragItems(nodeInternals: NodeInternals, mousePos: XYPosition, nodeId?: string): NodeDragItem[] {
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) => ({
id: n.id,
position: n.position,