Spaces:
Running
Running
Commit ·
78167bc
1
Parent(s): d7ddf0b
fix: dynamically calculate and lock image aspect ratio on load and enable keepAspectRatio on NodeResizer
Browse files46 unmodified lines47484950515219 unmodified lines72737475767715 unmodified lines9394959697989946 unmodified linesupdateNodeInternals(id);}, [id, localSize, updateNodeInternals]);useEffect(() => {if (!selected) {setLocalSize({19 unmodified linesisVisible={selected}minWidth={50}minHeight={50}onResize={(e, params) => {setLocalSize({ width: params.width, height: params.height });}}15 unmodified lines<imgsrc={imageUrl}alt="Canvas Asset"className="w-full h-full object-contain pointer-events-none"/>) : (<div className="w-full h-full min-h-[100px] bg-secondary/5 flex flex-col items-center justify-center gap-2 p-4 text-center border-2 border-dashed border-primary/10">46 unmodified lines474849505152535455565758596061626364656667686919 unmodified lines8990919293949515 unmodified lines11111211311411511611711846 unmodified linesupdateNodeInternals(id);}, [id, localSize, updateNodeInternals]);const handleImageLoad = (e) => {const { naturalWidth, naturalHeight } = e.target;if (naturalWidth && naturalHeight) {const ratio = naturalWidth / naturalHeight;// Only set initial size if data.height is 'auto' or not set in pixelsif (!data.height || data.height === 'auto') {const initialWidth = data.width || 300;const calculatedHeight = Math.round(initialWidth / ratio);setLocalSize({ width: initialWidth, height: calculatedHeight });if (data.updateNodeData) {data.updateNodeData(id, { width: initialWidth, height: calculatedHeight });}}}};useEffect(() => {if (!selected) {setLocalSize({19 unmodified linesisVisible={selected}minWidth={50}minHeight={50}keepAspectRatio={true}onResize={(e, params) => {setLocalSize({ width: params.width, height: params.height });}}15 unmodified lines<imgsrc={imageUrl}alt="Canvas Asset"onLoad={handleImageLoad}className="w-full h-full object-cover pointer-events-none select-none rounded-lg"/>) : (<div className="w-full h-full min-h-[100px] bg-secondary/5 flex flex-col items-center justify-center gap-2 p-4 text-center border-2 border-dashed border-primary/10">
src/features/canvas/components/nodes/ImageNode.jsx+20-1