import { useRef } from "react"; import { Image as KonvaImage } from "react-konva"; import Konva from "konva"; import useImage from "use-image"; import type { ShapeProps } from "./types"; const ImageObject = ({ obj, isSelected, onSelect, onUpdate, draggable, }: ShapeProps) => { const [image] = useImage(obj.imageUrl || ""); const shapeRef = useRef(null); // Transformer is managed in EditorCanvas for multi-select support if (!image) return null; return ( { // فقط وقتی mask اعمال نشده onClick handler را فعال کن if (shapeRef.current) { onSelect(obj.id, shapeRef.current, e); } } : undefined} onDragEnd={(e) => { const node = e.target; onUpdate(obj.id, { x: node.x(), y: node.y(), }); }} onTransformEnd={() => { const node = shapeRef.current; if (!node) return; const scaleX = node.scaleX(); const scaleY = node.scaleY(); node.scaleX(1); node.scaleY(1); onUpdate(obj.id, { x: node.x(), y: node.y(), rotation: node.rotation(), width: Math.max(5, (obj.width || image.width) * scaleX), height: Math.max(5, (obj.height || image.height) * scaleY), }); }} /> ); }; export default ImageObject;