fix: can select line and move to another place

This commit is contained in:
hamid zarghami
2025-11-26 16:12:53 +03:30
parent 56bfdbfe2e
commit 2f60ef806e
@@ -13,14 +13,21 @@ const LineShape = ({ obj, isSelected, transformerRef, onSelect, onUpdate, dragga
} }
}, [isSelected, transformerRef]); }, [isSelected, transformerRef]);
const startX = obj.x;
const startY = obj.y;
const endX = obj.width || 0;
const endY = obj.height || 0;
return ( return (
<Line <Line
ref={shapeRef} ref={shapeRef}
x={obj.x} x={startX}
y={obj.y} y={startY}
points={[0, 0, (obj.width || 0) - obj.x, (obj.height || 0) - obj.y]} points={[0, 0, endX - startX, endY - startY]}
stroke={isSelected ? "#3b82f6" : obj.stroke || "#000000"} stroke={isSelected ? "#3b82f6" : obj.stroke || "#000000"}
strokeWidth={isSelected ? 3 : (obj.strokeWidth ?? 0)} strokeWidth={isSelected ? 3 : (obj.strokeWidth ?? 2)}
hitStrokeWidth={20}
perfectDrawEnabled={false}
rotation={obj.rotation || 0} rotation={obj.rotation || 0}
draggable={draggable} draggable={draggable}
onClick={() => { onClick={() => {
@@ -30,9 +37,39 @@ const LineShape = ({ obj, isSelected, transformerRef, onSelect, onUpdate, dragga
}} }}
onDragEnd={(e) => { onDragEnd={(e) => {
const node = e.target; const node = e.target;
const newX = node.x();
const newY = node.y();
const dx = endX - startX;
const dy = endY - startY;
onUpdate(obj.id, { onUpdate(obj.id, {
x: node.x(), x: newX,
y: node.y(), y: newY,
width: newX + dx,
height: newY + dy,
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
node.scaleX(1);
node.scaleY(1);
const newX = node.x();
const newY = node.y();
const dx = (endX - startX) * scaleX;
const dy = (endY - startY) * scaleY;
onUpdate(obj.id, {
x: newX,
y: newY,
rotation: node.rotation(),
width: newX + dx,
height: newY + dy,
}); });
}} }}
/> />