Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
fix select and edit bug
Abi Raja0e920ff46293
diff --git a/frontend/src/components/preview/PreviewComponent.tsx b/frontend/src/components/preview/PreviewComponent.tsxindex 593f5809..0049500d 100644--- a/frontend/src/components/preview/PreviewComponent.tsx+++ b/frontend/src/components/preview/PreviewComponent.tsx@@ -18,6 +18,7 @@ function PreviewComponent({ code, device, doUpdate }: Props) {// Select and edit functionalityconst [clickEvent, setClickEvent] = useState<MouseEvent | null>(null);+ const [scale, setScale] = useState(1);// Add scaling logicuseEffect(() => {@@ -28,12 +29,14 @@ function PreviewComponent({ code, device, doUpdate }: Props) {const viewportWidth = wrapper.clientWidth;const baseWidth = device === "desktop" ? 1440 : 375;- const scale = Math.min(1, viewportWidth / baseWidth);+ const scaleValue = Math.min(1, viewportWidth / baseWidth);- iframe.style.transform = `scale(${scale})`;+ setScale(scaleValue);++ iframe.style.transform = `scale(${scaleValue})`;iframe.style.transformOrigin = "top left";// Adjust wrapper height to account for scaling- wrapper.style.height = `${iframe.offsetHeight * scale}px`;+ wrapper.style.height = `${iframe.offsetHeight * scaleValue}px`;};updateScale();@@ -80,6 +83,7 @@ function PreviewComponent({ code, device, doUpdate }: Props) {event={clickEvent}iframeRef={iframeRef}doUpdate={doUpdate}+ scale={scale}/></div></div>diff --git a/frontend/src/components/select-and-edit/EditPopup.tsx b/frontend/src/components/select-and-edit/EditPopup.tsxindex aab67443..d995448f 100644--- a/frontend/src/components/select-and-edit/EditPopup.tsx+++ b/frontend/src/components/select-and-edit/EditPopup.tsx@@ -9,12 +9,14 @@ interface EditPopupProps {event: MouseEvent | null;iframeRef: React.RefObject<HTMLIFrameElement>;doUpdate: (updateInstruction: string, selectedElement?: HTMLElement) => void;+ scale: number;}const EditPopup: React.FC<EditPopupProps> = ({event,iframeRef,doUpdate,+ scale,}) => {// App stateconst { inSelectAndEditMode } = useAppStore();@@ -92,7 +94,8 @@ const EditPopup: React.FC<EditPopupProps> = ({const adjustedCoordinates = getAdjustedCoordinates(event.clientX,event.clientY,- iframeRef.current?.getBoundingClientRect()+ iframeRef.current?.getBoundingClientRect(),+ scale);// Show the popup at the click position@@ -104,7 +107,7 @@ const EditPopup: React.FC<EditPopupProps> = ({// Focus the textareatextareaRef.current?.focus();- }, [event, iframeRef]);+ }, [event, iframeRef, scale]);// Focus the textarea when the popup is visible (we can't do this only when handling the click event// because the textarea is not rendered yet)diff --git a/frontend/src/components/select-and-edit/utils.ts b/frontend/src/components/select-and-edit/utils.tsindex 9462778b..8beae6b5 100644--- a/frontend/src/components/select-and-edit/utils.ts+++ b/frontend/src/components/select-and-edit/utils.ts@@ -13,10 +13,13 @@ export function addHighlight(element: HTMLElement) {export function getAdjustedCoordinates(x: number,y: number,- rect: DOMRect | undefined+ rect: DOMRect | undefined,+ scale: number) {const offsetX = rect ? rect.left : 0;const offsetY = rect ? rect.top : 0;-- return { x: x + offsetX, y: y + offsetY };+ return {+ x: offsetX + x * scale,+ y: offsetY + y * scale,+ };}