@@ -4,6 +4,17 @@ import { Tabs, Tab } from "./tabs";
44import { IconButton , Omnibox } from "./Omnibox" ;
55import { scramjet } from "./main" ;
66import iconAdd from "@ktibow/iconset-material-symbols/add" ;
7+ import { popTab , pushTab , Shell } from "./Shell" ;
8+
9+ // let a = createState({
10+ // b: createState({
11+ // c: "test",
12+ // }),
13+ // });
14+ // use(a.b.c).listen((v) => {
15+ // console.log("a.b.c changed to", v);
16+ // });
17+ // a.b.c = "test2";
718
819class StatefulClass {
920 constructor ( state : Stateful < any > ) {
@@ -16,7 +27,7 @@ export class Browser extends StatefulClass {
1627
1728 theme : Theme ;
1829 tabs : Tab [ ] = [ ] ;
19- activetab : number ;
30+ activetab : Tab ;
2031
2132 constructor ( state : Stateful < any > ) {
2233 super ( state ) ;
@@ -47,23 +58,51 @@ export class Browser extends StatefulClass {
4758 newTab ( title : string ) {
4859 let frame = scramjet . createFrame ( ) ;
4960 let tab = new Tab ( title , frame ) ;
61+ frame . go ( "https://google.com" ) ;
62+ frame . addEventListener ( "navigate" , ( e ) => {
63+ console . error ( e ) ;
64+ tab . url = frame . client . url . href ;
65+ } ) ;
66+ frame . frame . addEventListener ( "load" , ( e ) => {
67+ tab . url = frame . client . url . href ;
68+ } ) ;
69+ use ( tab . url ) . listen ( ( ) => {
70+ this . activetab = this . activetab ;
71+ } ) ;
72+ pushTab ( tab ) ;
5073 this . tabs = [ ...this . tabs , tab ] ;
74+ this . activetab = tab ;
5175 return tab ;
5276 }
5377
78+ destroyTab ( tab : Tab ) {
79+ this . tabs = this . tabs . filter ( ( t ) => t !== tab ) ;
80+ console . log ( this . tabs ) ;
81+ if ( this . activetab === tab ) {
82+ this . activetab = this . tabs [ 0 ] || this . newTab ( "New Tab" ) ;
83+ }
84+ console . log ( this . tabs ) ;
85+
86+ console . log ( this . activetab ) ;
87+ popTab ( tab ) ;
88+ }
89+
5490 build ( ) : HTMLElement {
91+ let shell = < Shell tabs = { use ( this . tabs ) } activetab = { use ( this . activetab ) } /> ;
92+
5593 let tab = this . newTab ( "title" ) ;
56- this . activetab = tab . id ;
94+ this . activetab = tab ;
5795 if ( this . built ) throw new Error ( "already built" ) ;
5896 this . built = true ;
5997
6098 return (
6199 < div >
62100 < ThemeVars colors = { use ( this . theme ) } />
63- < div style = "display: flex" >
101+ < div style = "display: flex; align-items: center; background: var(--aboutbrowser-frame-bg) " >
64102 < Tabs
65103 tabs = { use ( this . tabs ) . bind ( ) }
66104 activetab = { use ( this . activetab ) . bind ( ) }
105+ destroyTab = { ( tab ) => this . destroyTab ( tab ) }
67106 />
68107 < IconButton
69108 icon = { iconAdd }
@@ -72,7 +111,8 @@ export class Browser extends StatefulClass {
72111 } }
73112 > </ IconButton >
74113 </ div >
75- < Omnibox />
114+ < Omnibox value = { use ( this . activetab . url ) } />
115+ { shell }
76116 </ div >
77117 ) ;
78118 }
0 commit comments