Skip to content

Commit 3f54c3f

Browse files
committed
[frontend] resizable devtools & bump dreamland
1 parent 4774859 commit 3f54c3f

File tree

5 files changed

+70
-11
lines changed

5 files changed

+70
-11
lines changed

frontend/src/Tab.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export class Tab extends StatefulClass {
3333

3434
internalpage: HTMLElement | null;
3535

36+
devtoolsOpen: boolean = true;
37+
devtoolsWidth = 200;
38+
3639
constructor(public url: URL = new URL("puter://newtab")) {
3740
super(createState(Object.create(Tab.prototype)));
3841

@@ -256,6 +259,12 @@ function pageContextItems(client: ScramjetClient, tab: Tab, e: MouseEvent) {
256259
console.log("Bookmarking", tab.title, tab.url);
257260
},
258261
},
262+
{
263+
label: "Inspect",
264+
action: () => {
265+
tab.devtoolsOpen = !tab.devtoolsOpen;
266+
},
267+
},
259268
];
260269
}
261270

frontend/src/browser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Shell } from "./components/Shell";
88
import { createMenu } from "./components/Menu";
99
import { StatefulClass } from "./StatefulClass";
1010
import { Tab } from "./Tab";
11-
import { createDelegate } from "dreamland/utils";
11+
import { createDelegate } from "dreamland/core";
1212

1313
export const pushTab = createDelegate<Tab>();
1414
export const popTab = createDelegate<Tab>();

frontend/src/components/Omnibox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import iconSearch from "@ktibow/iconset-ion/search";
1010
import { createMenu, setContextMenu } from "./Menu";
1111
import { browser, client } from "../main";
1212
import { IconButton } from "./IconButton";
13-
import { createDelegate, type Delegate } from "dreamland/utils";
13+
import { createDelegate, type Delegate } from "dreamland/core";
1414

1515
export const Spacer: Component = function (cx) {
1616
return <div></div>;

frontend/src/components/Shell.tsx

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,46 @@ export const Shell: Component<{
1010
}> = function (cx) {
1111
pushTab.listen((tab) => {
1212
tab.frame.frame.classList.add(cx.id);
13-
let devtoolsFrame: HTMLIFrameElement = <iframe class={cx.id}></iframe>;
13+
let devtoolsFrame: HTMLIFrameElement = (
14+
<iframe class:unfocus={use(browser.unfocusframes)}></iframe>
15+
);
16+
let mouseMoveListen = (e: MouseEvent) => {
17+
tab.devtoolsWidth = window.innerWidth - e.clientX;
18+
};
1419
cx.root.appendChild(
1520
<div
16-
class={`container ${cx.id}`}
21+
class="container"
1722
data-tab={tab.id}
1823
class:active={use(this.activetab).map((t) => t === tab)}
1924
class:showframe={use(tab.internalpage).map((t) => !t)}
2025
>
21-
{use(tab.internalpage)}
22-
{tab.frame.frame}
23-
<div class={`devtools ${cx.id}`}>{devtoolsFrame}</div>
26+
<div
27+
class="mainframecontainer"
28+
class:unfocus={use(browser.unfocusframes)}
29+
>
30+
{use(tab.internalpage)}
31+
{tab.frame.frame}
32+
</div>
33+
<div
34+
class="devtools"
35+
class:active={use(tab.devtoolsOpen)}
36+
style={use`width: ${tab.devtoolsWidth}px`}
37+
>
38+
<div
39+
on:mousedown={(e: MouseEvent) => {
40+
browser.unfocusframes = true;
41+
document.body.style.cursor = "ew-resize";
42+
window.addEventListener("mousemove", mouseMoveListen);
43+
window.addEventListener("mouseup", () => {
44+
browser.unfocusframes = false;
45+
window.removeEventListener("mousemove", mouseMoveListen);
46+
document.body.style.cursor = "";
47+
});
48+
}}
49+
class="divider"
50+
></div>
51+
{devtoolsFrame}
52+
</div>
2453
</div>
2554
);
2655
tab.devtoolsFrame = devtoolsFrame;
@@ -42,7 +71,7 @@ export const Shell: Component<{
4271
tab.screenshot = canvas.toDataURL();
4372
});
4473

45-
return <div class:unfocus={use(browser.unfocusframes)}></div>;
74+
return <div></div>;
4675
};
4776
Shell.style = css`
4877
:scope {
@@ -60,11 +89,32 @@ Shell.style = css`
6089
display: flex;
6190
}
6291
.container .devtools {
63-
display: block;
92+
position: relative;
93+
display: none;
6494
width: 20em;
6595
}
96+
.container .devtools.active {
97+
display: flex;
98+
}
99+
100+
.mainframecontainer {
101+
display: flex;
102+
flex: 1;
103+
}
104+
105+
.divider {
106+
position: absolute;
107+
top: 0;
108+
left: -5px;
109+
width: 5px;
110+
/* background: #ccc; */
111+
border-right: 1px solid #ccc;
112+
height: 100%;
113+
cursor: ew-resize;
114+
}
115+
66116
iframe {
67-
width: 100%;
117+
flex: 1;
68118
height: 100%;
69119
border: none;
70120
display: none;

0 commit comments

Comments
 (0)