trust-module-frontend/src/Components/TreeChart/FlowChartComponents/useNodeHandlers.jsx

24 lines
760 B
JavaScript

import { useCallback } from 'react';
export const useNodeHandlers = (debouncedSetNodePositions) => {
const onNodeDrag = useCallback((event, node) => {
// Фиксируем позицию сразу при перемещении
node.position = {
x: Math.round(node.position.x),
y: Math.round(node.position.y)
};
}, []);
const onNodeDragStop = useCallback((event, node) => {
node.position = {
x: Math.round(node.position.x),
y: Math.round(node.position.y)
};
debouncedSetNodePositions(prev => ({
...prev,
[node.id]: node.position
}));
}, [debouncedSetNodePositions]);
return { onNodeDrag, onNodeDragStop };
};