diff --git a/electron/preload/webview/elements/index.ts b/electron/preload/webview/elements/index.ts index e16133e61..f64769977 100644 --- a/electron/preload/webview/elements/index.ts +++ b/electron/preload/webview/elements/index.ts @@ -1,6 +1,6 @@ -import { EditorAttributes } from "../../../../common/constants"; -import { ElementMetadata } from "../../../../common/models"; import { finder } from "./finder"; +import { EditorAttributes } from "/common/constants"; +import { ElementMetadata } from "/common/models"; export const handleMouseEvent = (e: MouseEvent): Object => { if (!e.metaKey) { diff --git a/electron/preload/webview/eventBridge.ts b/electron/preload/webview/eventBridge.ts index 400a6ba07..b192461c2 100644 --- a/electron/preload/webview/eventBridge.ts +++ b/electron/preload/webview/eventBridge.ts @@ -14,10 +14,10 @@ export class EventBridge { 'click': handleMouseEvent, 'dblclick': handleMouseEvent, 'wheel': (e: WheelEvent) => { - return {} + return { x: window.scrollX, y: window.scrollY } }, 'scroll': (e: Event) => { - return {} + return { x: window.scrollX, y: window.scrollY } }, 'dom-ready': () => { const { body } = document; diff --git a/src/lib/editor/eventHandler.ts b/src/lib/editor/eventHandler.ts index 4a6171972..335423103 100644 --- a/src/lib/editor/eventHandler.ts +++ b/src/lib/editor/eventHandler.ts @@ -37,6 +37,8 @@ export class WebviewEventHandler { console.error('No args found for mouseover event'); return; } + const scrollPosition: { x: number, y: number } = JSON.parse(e.args[0]); + overlayManager.updateScroll(scrollPosition); }, }; diff --git a/src/lib/editor/overlay/index.ts b/src/lib/editor/overlay/index.ts index bd89e7398..3a40c270d 100644 --- a/src/lib/editor/overlay/index.ts +++ b/src/lib/editor/overlay/index.ts @@ -6,6 +6,7 @@ export class OverlayManager { clickedRects: ClickRect[] parentRect: ParentRect editRect: EditRect + scrollPosition: { x: number, y: number } = { x: 0, y: 0 } constructor() { this.hoverRect = new HoverRect(); @@ -80,6 +81,14 @@ export class OverlayManager { this.removeEditRect() } + updateScroll = ({ x, y }: { x: number, y: number }) => { + this.scrollPosition = { x, y } + this.hoverRect.applyScroll(x, y) + this.clickedRects.forEach(clickRect => { + clickRect.applyScroll(x, y) + }) + } + addClickRect = (rect: DOMRect, computerStyle: CSSStyleDeclaration) => { const clickRect = new ClickRect() this.appendRectToPopover(clickRect.element) diff --git a/src/lib/editor/overlay/rect.ts b/src/lib/editor/overlay/rect.ts index 6c3c0e1d2..b7d4d8997 100644 --- a/src/lib/editor/overlay/rect.ts +++ b/src/lib/editor/overlay/rect.ts @@ -51,6 +51,11 @@ export class RectImpl implements Rect { this.rectElement.setAttribute('height', height.toString()) this.element.style.top = `${top}px` this.element.style.left = `${left}px` + this.element.style.transform = 'translate(0, 0)' + } + + applyScroll(scrollX: number, scrollY: number) { + this.element.style.transform = `translate(${-scrollX}px, ${-scrollY}px)` } } diff --git a/src/routes/project/webview/WebviewArea.tsx b/src/routes/project/webview/WebviewArea.tsx index 810884717..482ec952b 100644 --- a/src/routes/project/webview/WebviewArea.tsx +++ b/src/routes/project/webview/WebviewArea.tsx @@ -14,7 +14,7 @@ function WebviewArea() { { id: nanoid(), title: 'Desktop', - src: 'https://www.framer.com/', + src: 'https://www.github.com/', }, ]; diff --git a/tsconfig.json b/tsconfig.json index 0e47c6831..ef609f172 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,9 @@ "paths": { "@/*": [ "src/*" + ], + "/*": [ + "./*" ] }, }, diff --git a/vite.config.ts b/vite.config.ts index 5cabb063b..3708aa834 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -16,7 +16,8 @@ export default defineConfig(({ command }) => { return { resolve: { alias: { - '@': path.join(__dirname, 'src') + '@': path.join(__dirname, 'src'), + 'common': path.join(__dirname, 'common'), }, }, plugins: [