Skip to content

Commit dd7418f

Browse files
committed
[frontend] small refactor
1 parent 9c08818 commit dd7418f

File tree

10 files changed

+62
-49
lines changed

10 files changed

+62
-49
lines changed

frontend/src/browser.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createState, type Stateful } from "dreamland/core";
2-
import { ThemeVars, type Theme } from "./ui/theme";
3-
import { Tabs, Tab } from "./tabs";
4-
import { IconButton, Omnibox } from "./Omnibox";
2+
import { ThemeVars, type Theme } from "./theme";
3+
import { Tabs, Tab } from "./components/TabStrip";
4+
import { Omnibox } from "./components/Omnibox";
55
import { scramjet } from "./main";
66
import iconAdd from "@ktibow/iconset-ion/add";
7-
import { popTab, pushTab, Shell } from "./Shell";
8-
import { createMenu } from "./Menu";
7+
import { popTab, pushTab, Shell } from "./components/Shell";
8+
import { createMenu } from "./components/Menu";
99

1010
// let a = createState({
1111
// b: createState({
File renamed without changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { IconifyIcon } from "@iconify/types";
2+
import type { Component } from "dreamland/core";
3+
import { Icon } from "./Icon";
4+
5+
export const IconButton: Component<{
6+
icon: IconifyIcon;
7+
click?: (e: MouseEvent) => void;
8+
}> = function (cx) {
9+
return (
10+
<button on:click={(e) => this.click?.(e)}>
11+
<Icon icon={this.icon} />
12+
</button>
13+
);
14+
};
15+
IconButton.css = `
16+
:scope {
17+
padding: 0.4em;
18+
display: flex;
19+
outline: none;
20+
border: none;
21+
font-size: 1.25em;
22+
background: inerhit
23+
# background: var(--aboutbrowser-toolbar-bg);
24+
cursor: pointer;
25+
}
26+
`;

frontend/src/Menu.tsx renamed to frontend/src/components/Menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Component, DLElement } from "dreamland/core";
2-
import { browser } from "./main";
2+
import { browser } from "../main";
33

44
export const Menu: Component<{
55
x: number;

frontend/src/Omnibox.tsx renamed to frontend/src/components/Omnibox.tsx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import type { Component } from "dreamland/core";
2-
import { Icon } from "./ui/Icon";
3-
import type { IconifyIcon } from "@iconify/types";
42
import iconBack from "@ktibow/iconset-ion/arrow-back";
53
import iconForwards from "@ktibow/iconset-ion/arrow-forward";
64
import iconRefresh from "@ktibow/iconset-ion/refresh";
@@ -10,7 +8,8 @@ import iconShield from "@ktibow/iconset-ion/shield-outline";
108
import iconStar from "@ktibow/iconset-ion/star-outline";
119
import iconSearch from "@ktibow/iconset-ion/search";
1210
import { createMenu } from "./Menu";
13-
import { browser, client } from "./main";
11+
import { browser, client } from "../main";
12+
import { IconButton } from "./IconButton";
1413

1514
export const Spacer: Component = function (cx) {
1615
return <div></div>;
@@ -208,29 +207,6 @@ UrlInput.css = `
208207
}
209208
`;
210209

211-
export const IconButton: Component<{
212-
icon: IconifyIcon;
213-
click?: (e: MouseEvent) => void;
214-
}> = function (cx) {
215-
return (
216-
<button on:click={(e) => this.click?.(e)}>
217-
<Icon icon={this.icon} />
218-
</button>
219-
);
220-
};
221-
IconButton.css = `
222-
:scope {
223-
padding: 0.4em;
224-
display: flex;
225-
outline: none;
226-
border: none;
227-
font-size: 1.25em;
228-
background: inerhit
229-
# background: var(--aboutbrowser-toolbar-bg);
230-
cursor: pointer;
231-
}
232-
`;
233-
234210
export const Omnibox: Component<{
235211
value: string;
236212
navigate: (url: string) => void;

frontend/src/Shell.tsx renamed to frontend/src/components/Shell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Component } from "dreamland/core";
2-
import type { Tab } from "./tabs";
3-
import { browser } from "./main";
2+
import type { Tab } from "./TabStrip";
3+
import { browser } from "../main";
44

55
export let pushTab: (tab: Tab) => void;
66
export let popTab: (tab: Tab) => void;

frontend/src/tabs.tsx renamed to frontend/src/components/TabStrip.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
type ComponentInstance,
77
type Stateful,
88
} from "dreamland/core";
9-
import { Icon } from "./ui/Icon";
10-
import { IconButton } from "./Omnibox";
11-
import { memoize } from "./memoize";
9+
import { Icon } from "./Icon";
10+
import { memoize } from "../memoize";
11+
import { IconButton } from "./IconButton";
1212

1313
export const DragTab: Component<{
1414
active: boolean;
@@ -339,12 +339,6 @@ export const Tabs: Component<
339339
const root = getTabFromIndex(tab.id);
340340
const dragroot = root.querySelector(".dragroot") as HTMLElement;
341341

342-
let lifetimeOffset = tab.pos - tab.startdragpos;
343-
if (Math.abs(lifetimeOffset) < 20) {
344-
// TODO: arbitrary magic
345-
if (this.activetab != tab) this.activetab = tab;
346-
}
347-
348342
dragroot.style.width = "";
349343
dragroot.style.position = "unset";
350344
tab.dragoffset = -1;
@@ -368,6 +362,8 @@ export const Tabs: Component<
368362
if (tab.dragoffset < 0) throw new Error("dragoffset must be positive");
369363

370364
calcDragPos(e, tab);
365+
366+
if (this.activetab != tab) this.activetab = tab;
371367
};
372368

373369
const transitionend = () => {
@@ -393,11 +389,6 @@ export const Tabs: Component<
393389
icon={use(tab.icon)}
394390
active={use(this.activetab).map((x) => x === tab)}
395391
mousedown={(e) => mouseDown(e, tab)}
396-
click={() => {
397-
if (this.activetab !== tab) {
398-
this.activetab = tab;
399-
}
400-
}}
401392
destroy={() => {
402393
this.destroyTab(tab);
403394
}}

frontend/src/delegate.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type Delegate<T> = {
2+
listen: (callback: (value: T) => void) => void;
3+
(value: T): void;
4+
};
5+
6+
export function createDelegate<T>(): Delegate<T> {
7+
let listeners: Array<(value: T) => void> = [];
8+
9+
const delegate = (value: T) => {
10+
for (const listener of listeners) {
11+
listener(value);
12+
}
13+
};
14+
15+
delegate.listen = (callback: (value: T) => void) => {
16+
listeners.push(callback);
17+
};
18+
19+
return delegate;
20+
}

frontend/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "./style.css";
22

33
import { createBrowser } from "./browser";
4-
import { createMenu } from "./Menu";
4+
import { createMenu } from "./components/Menu";
55
let app = document.getElementById("app")!;
66
import { BareMuxConnection, BareClient } from "@mercuryworkshop/bare-mux";
77

File renamed without changes.

0 commit comments

Comments
 (0)