Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
correct outline position
Oleg Isonen1bd962691238
diff --git a/app/designer/designer.tsx b/app/designer/designer.tsxindex 00cb5a028f..e460272852 100644--- a/app/designer/designer.tsx+++ b/app/designer/designer.tsx@@ -8,7 +8,6 @@ import { Box, Flex, Grid, type CSS } from "~/shared/design-system";import interStyles from "~/shared/font-faces/inter.css";import { SidebarLeft } from "./features/sidebar-left";import { Inspector } from "./features/inspector";-import { CanvasIframe } from "./shared/canvas-iframe";import { useSelectedInstanceData, useSyncStatus } from "./shared/nano-states";import { Topbar } from "./features/topbar";import designerStyles from "./designer.css";@@ -18,7 +17,11 @@ import {useUpdateCanvasWidth,useSubscribeBreakpoints,} from "./features/breakpoints";-import { useReadCanvasRect, Workspace } from "./features/workspace";+import {+ useReadCanvasRect,+ Workspace,+ CanvasIframe,+} from "./features/workspace";import { usePublishShortcuts } from "./shared/shortcuts";import { type SyncStatus } from "~/shared/sync";import { useIsPreviewMode, useRootInstance } from "~/shared/nano-states";diff --git a/app/designer/shared/canvas-iframe/canvas-iframe.tsx b/app/designer/features/workspace/canvas-iframe.tsxsimilarity index 100%rename from app/designer/shared/canvas-iframe/canvas-iframe.tsxrename to app/designer/features/workspace/canvas-iframe.tsxdiff --git a/app/designer/features/workspace/canvas-tools/canvas-tools.tsx b/app/designer/features/workspace/canvas-tools/canvas-tools.tsxindex 00ea349431..6269cb8418 100644--- a/app/designer/features/workspace/canvas-tools/canvas-tools.tsx+++ b/app/designer/features/workspace/canvas-tools/canvas-tools.tsx@@ -1,7 +1,5 @@import { useSubscribe } from "@webstudio-is/sdk";-import { useZoom } from "~/designer/shared/nano-states";import { Box } from "~/shared/design-system";-import { useMeasure } from "~/shared/dom-hooks";import { useSelectedInstanceRect } from "~/shared/nano-states";import { SelectedInstanceOutline } from "./outlines";@@ -19,16 +17,15 @@ const toolsStyle = {right: 0,bottom: 0,left: 0,- //border: "2px solid red",pointerEvents: "none",+ overflow: "hidden",};export const CanvasTools = () => {useLink();- const [toolsRef, toolsRect] = useMeasure();return (- <Box css={toolsStyle} ref={toolsRef} data-test>- <SelectedInstanceOutline toolsRect={toolsRect} />+ <Box css={toolsStyle}>+ <SelectedInstanceOutline /></Box>);};diff --git a/app/designer/features/workspace/canvas-tools/outlines.tsx b/app/designer/features/workspace/canvas-tools/outlines.tsxindex 952884e924..5f44b016e4 100644--- a/app/designer/features/workspace/canvas-tools/outlines.tsx+++ b/app/designer/features/workspace/canvas-tools/outlines.tsx@@ -1,4 +1,4 @@-import { useCanvasRect, useZoom } from "~/designer/shared/nano-states";+import { useMemo } from "react";import { styled } from "~/shared/design-system";import { useSelectedInstanceRect } from "~/shared/nano-states";@@ -64,37 +64,20 @@ const Label = styled(});-type SelectedInstanceOutlineProps = {- toolsRect: Omit<DOMRect, "toJSON">;-};--export const SelectedInstanceOutline = ({- toolsRect,-}: SelectedInstanceOutlineProps) => {- const [instanceRect] = useSelectedInstanceRect();- const [canvasRect] = useCanvasRect();- const [zoom] = useZoom();- console.log("canvasRect", canvasRect);- if (- canvasRect === undefined ||- instanceRect === undefined ||- toolsRect === undefined- ) {- return null;- }+export const SelectedInstanceOutline = () => {+ const [rect] = useSelectedInstanceRect();- let style;- console.log("zoom", zoom);- const top =- (canvasRect.top - toolsRect.top + instanceRect.top) * (zoom / 100);- const left = canvasRect.left - toolsRect.left + instanceRect.left;+ const style = useMemo(() => {+ if (rect === undefined) return;+ return {+ top: rect.top,+ left: rect.left,+ width: rect.width,+ height: rect.height,+ };+ }, [rect]);- style = {- top,- left,- width: instanceRect.width,- height: instanceRect.height,- };+ if (style === undefined) return null;return <Outline state="selected" style={style} />;};diff --git a/app/designer/features/workspace/index.ts b/app/designer/features/workspace/index.tsindex 8050a4467d..202eb336a2 100644--- a/app/designer/features/workspace/index.ts+++ b/app/designer/features/workspace/index.ts@@ -1,2 +1,3 @@export * from "./workspace";export * from "./use-read-canvas-rect";+export * from "./canvas-iframe";diff --git a/app/designer/features/workspace/workspace.tsx b/app/designer/features/workspace/workspace.tsxindex 5f3d1937bd..9a72f65c35 100644--- a/app/designer/features/workspace/workspace.tsx+++ b/app/designer/features/workspace/workspace.tsx@@ -2,6 +2,25 @@ import { Box, Flex } from "~/shared/design-system";import { useCanvasWidth, useZoom } from "~/designer/shared/nano-states";import { CanvasTools } from "./canvas-tools";+const workspaceStyle = {+ flexGrow: 1,+ background: "$gray8",+ overflow: "auto",+ scrollbarGutter: "stable",+};++const zoomStyle = {+ transformStyle: "preserve-3d",+ transition: "transform 200ms ease-out",+ height: "100%",+ width: "100%",+};++const canvasContainerStyle = {+ position: "relative",+ height: "100%",+};+type WorkspaceProps = {children: JSX.Element;onTransitionEnd: () => void;@@ -11,32 +30,18 @@ export const Workspace = ({ children, onTransitionEnd }: WorkspaceProps) => {const [zoom] = useZoom();const [canvasWidth] = useCanvasWidth();return (- <Box- css={{- flexGrow: 1,- background: "$gray8",- overflow: "auto",- scrollbarGutter: "stable",- }}- >+ <Box css={workspaceStyle}><Flexdirection="column"align="center"- css={{- transformStyle: "preserve-3d",- transition: "transform 200ms ease-out",- height: "100%",- width: "100%",- }}- style={{- transform: `scale(${zoom / 100})`,- }}+ css={zoomStyle}+ style={{ transform: `scale(${zoom / 100})` }}onTransitionEnd={onTransitionEnd}>- <div style={{ width: canvasWidth, height: "100%" }}>+ <Box css={canvasContainerStyle} style={{ width: canvasWidth }}>{children}<CanvasTools />- </div>+ </Box></Flex></Box>);diff --git a/app/designer/shared/canvas-iframe/index.ts b/app/designer/shared/canvas-iframe/index.tsdeleted file mode 100644index c9935a225b..0000000000--- a/app/designer/shared/canvas-iframe/index.ts+++ /dev/null@@ -1 +0,0 @@-export { CanvasIframe } from "./canvas-iframe";