Skip to content

Commit ed334a9

Browse files
committed
Working frame
1 parent 3a31fb4 commit ed334a9

File tree

7 files changed

+67
-21
lines changed

7 files changed

+67
-21
lines changed

apps/web/src/app/project/[id]/_components/canvas/frames/gesture.tsx renamed to apps/web/src/app/project/[id]/_components/canvas/frame/gesture.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,15 @@ export const GestureScreen = observer(() => {
179179
}, [editorEngine.state.editorMode, isResizing]);
180180

181181
const handleMouseOut = () => {
182-
setHovered(false);
183182
editorEngine.elements.clearHoveredElement();
184183
editorEngine.overlay.state.updateHoverRect(null);
185184
}
186185

187-
const setHovered = (hovered: boolean) => {
188-
return;
189-
}
190186
return (
191187
<RightClickMenu>
192188
<div
193189
className={gestureScreenClassName}
194190
onClick={handleClick}
195-
onMouseOver={() => setHovered(true)}
196191
onMouseOut={handleMouseOut}
197192
onMouseLeave={handleMouseUp}
198193
onMouseMove={throttledMouseMove}

apps/web/src/app/project/[id]/_components/canvas/frames/frame/index.tsx renamed to apps/web/src/app/project/[id]/_components/canvas/frame/index.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { FrameType, type Frame, type WebFrame } from "@onlook/models";
22
import { observer } from "mobx-react-lite";
3-
import { GestureScreen } from '../gesture';
4-
import { ResizeHandles } from '../resize-handles';
5-
import { WebFrameComponent } from "./web";
3+
import { GestureScreen } from './gesture';
4+
import { ResizeHandles } from './resize-handles';
5+
import { TopBar } from "./top-bar";
6+
import { WebFrameComponent } from "./web-frame";
67

78
export const FrameView = observer(
89
({
@@ -15,19 +16,8 @@ export const FrameView = observer(
1516
className="flex flex-col fixed"
1617
style={{ transform: `translate(${frame.position.x}px, ${frame.position.y}px)` }}
1718
>
18-
{/* <BrowserControls
19-
webviewRef={domReady ? webviewRef : null}
20-
webviewSrc={webviewSrc}
21-
setWebviewSrc={setWebviewSrc}
22-
selected={selected}
23-
hovered={hovered}
24-
setHovered={setHovered}
25-
setDarkmode={setDarkmode}
26-
settings={settings}
27-
startMove={startMove}
28-
domState={domState}
29-
webviewSize={webviewSize}
30-
/> */}
19+
<TopBar frame={frame}>
20+
</TopBar>
3121
<div className="relative">
3222
<ResizeHandles frame={frame} />
3323
{frame.type === FrameType.WEB && <WebFrameComponent frame={frame as WebFrame} />}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useEditorEngine } from '@/components/store';
2+
import type { Frame } from '@onlook/models';
3+
import { observer } from 'mobx-react-lite';
4+
5+
export const TopBar = observer(
6+
({
7+
frame,
8+
children
9+
}: {
10+
frame: Frame;
11+
children?: React.ReactNode;
12+
}) => {
13+
const editorEngine = useEditorEngine();
14+
15+
const startMove = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
16+
e.preventDefault();
17+
e.stopPropagation();
18+
19+
const startX = e.clientX;
20+
const startY = e.clientY;
21+
const startPositionX = frame.position.x;
22+
const startPositionY = frame.position.y;
23+
24+
const handleMove = (e: MouseEvent) => {
25+
const scale = editorEngine.canvas.scale;
26+
const deltaX = (e.clientX - startX) / scale;
27+
const deltaY = (e.clientY - startY) / scale;
28+
29+
frame.position = {
30+
x: startPositionX + deltaX,
31+
y: startPositionY + deltaY,
32+
};
33+
};
34+
35+
const endMove = (e: MouseEvent) => {
36+
e.preventDefault();
37+
e.stopPropagation();
38+
39+
window.removeEventListener('mousemove', handleMove);
40+
window.removeEventListener('mouseup', endMove);
41+
};
42+
43+
window.addEventListener('mousemove', handleMove);
44+
window.addEventListener('mouseup', endMove);
45+
};
46+
47+
return (
48+
<div
49+
className='rounded bg-foreground-primary/10 hover:shadow h-6 m-auto flex flex-row items-center backdrop-blur-sm overflow-hidden relative shadow-sm border-input text-foreground'
50+
style={{
51+
transform: `scale(${1 / editorEngine.canvas.scale})`,
52+
width: `${frame.dimension.width * editorEngine.canvas.scale}px`,
53+
marginBottom: `${20 / editorEngine.canvas.scale}px`,
54+
}}
55+
onMouseDown={startMove}
56+
>
57+
{children}
58+
</div>
59+
);
60+
},
61+
);

0 commit comments

Comments
 (0)