@@ -14,49 +14,64 @@ import {
1414 makeVirtualFileSystem ,
1515 makeWebAccessFileSystem ,
1616 SyncFileSystem ,
17- getItemName
17+ getItemName ,
1818} from "../src/index" ;
1919import "uno.css" ;
2020
21- const FsFile = ( props : { fs : SyncFileSystem | AsyncFileSystem , path : string } ) => {
21+ const FsFile = ( props : { fs : SyncFileSystem | AsyncFileSystem ; path : string } ) => {
2222 const [ open , setOpen ] = createSignal ( false ) ;
23- const content = createMemo ( ( prev ) => prev || open ( ) ? props . fs . readFile ( props . path ) : undefined ) ;
23+ const content = createMemo ( prev => ( prev || open ( ) ? props . fs . readFile ( props . path ) : undefined ) ) ;
2424 const setContent = ( data : string ) => props . fs . writeFile ( props . path , data ) ;
25- return < div >
26- < p >
27- < button onClick = { ( ) => setOpen ( ! open ( ) ) } > { open ( ) ? "-" : "+" } </ button >
28- { getItemName ( props . path ) }
29- </ p >
30- < Show when = { open ( ) } >
31- < textarea value = { content ( ) } onInput = { ( ev ) => setContent ( ev . currentTarget . value ) } />
32- </ Show >
33- </ div >
34- }
25+ return (
26+ < div >
27+ < p >
28+ < button onClick = { ( ) => setOpen ( ! open ( ) ) } > { open ( ) ? "-" : "+" } </ button >
29+ { getItemName ( props . path ) }
30+ </ p >
31+ < Show when = { open ( ) } >
32+ < textarea value = { content ( ) } onInput = { ev => setContent ( ev . currentTarget . value ) } />
33+ </ Show >
34+ </ div >
35+ ) ;
36+ } ;
3537
36- const FsDir = ( props : { fs : SyncFileSystem | AsyncFileSystem , path : string } ) => {
38+ const FsDir = ( props : { fs : SyncFileSystem | AsyncFileSystem ; path : string } ) => {
3739 const [ open , setOpen ] = createSignal ( props . path === "/" ) ;
3840 const [ name , setName ] = createSignal ( "" ) ;
3941 const list = ( ) => open ( ) && props . fs . readdir ( props . path ) ;
4042 return (
4143 < >
42- < div > < button onClick = { ( ) => setOpen ( ! open ( ) ) } > { open ( ) ? "-" : "+" } </ button > { getItemName ( props . path ) || "/" } < input onInput = { ( ev ) => setName ( ev . currentTarget . value ) } />
44+ < div >
45+ < button onClick = { ( ) => setOpen ( ! open ( ) ) } > { open ( ) ? "-" : "+" } </ button > { " " }
46+ { getItemName ( props . path ) || "/" } < input onInput = { ev => setName ( ev . currentTarget . value ) } />
4347 < Show when = { name ( ) !== "" } >
44- < button onClick = { ( ) => props . fs . writeFile ( `${ props . path === "/" ? "" : props . path } /${ name ( ) } ` , "" ) } >
48+ < button
49+ onClick = { ( ) =>
50+ props . fs . writeFile ( `${ props . path === "/" ? "" : props . path } /${ name ( ) } ` , "" )
51+ }
52+ >
4553 New File
4654 </ button >
47- < button onClick = { ( ) => props . fs . mkdir ( `${ props . path === "/" ? "" : props . path } /${ name ( ) } ` ) } >
55+ < button
56+ onClick = { ( ) => props . fs . mkdir ( `${ props . path === "/" ? "" : props . path } /${ name ( ) } ` ) }
57+ >
4858 New Dir
4959 </ button >
5060 </ Show >
5161 </ div >
5262 < Show when = { list ( ) !== undefined } >
5363 < ul >
5464 < For each = { list ( ) ! } >
55- { ( item ) => (
65+ { item => (
5666 < li >
5767 < Show
5868 when = { props . fs . getType ( item ) === "dir" }
59- fallback = { < FsFile fs = { props . fs } path = { `${ props . path === "/" ? "" : props . path } /${ item } ` } /> }
69+ fallback = {
70+ < FsFile
71+ fs = { props . fs }
72+ path = { `${ props . path === "/" ? "" : props . path } /${ item } ` }
73+ />
74+ }
6075 >
6176 < FsDir fs = { props . fs } path = { item } />
6277 </ Show >
@@ -70,27 +85,43 @@ const FsDir = (props: { fs: SyncFileSystem | AsyncFileSystem, path: string }) =>
7085} ;
7186
7287const App : Component = ( ) => {
73- const ofs = makeVirtualFileSystem ( {
74- src : { "index.ts" : "console.log(0);\n" } ,
75- } , localStorage ) ;
88+ const ofs = makeVirtualFileSystem (
89+ {
90+ src : { "index.ts" : "console.log(0);\n" } ,
91+ } ,
92+ localStorage ,
93+ ) ;
7694 const vfs = createFileSystem ( ofs ) ;
7795 const [ startAfs , setStartAfs ] = createSignal ( false ) ;
78- const [ afs ] = createResource ( startAfs , async ( ) => createFileSystem ( makeWebAccessFileSystem ( { mode : "readwrite" } ) ) )
96+ const [ afs ] = createResource ( startAfs , async ( ) =>
97+ createFileSystem ( makeWebAccessFileSystem ( { mode : "readwrite" } ) ) ,
98+ ) ;
7999 return (
80- < div class = "p-24 box-border w-full min-h-screen flex flex-col justify -center items -center space-y-4 bg-gray-800 text-white" >
100+ < div class = "box-border flex min-h-screen w-full flex-col items -center justify -center space-y-4 bg-gray-800 p-24 text-white" >
81101 < div class = "wrapper-v" >
82102 < div >
83- < ErrorBoundary fallback = { ( err , reset ) => < div > Error: { err } < button onClick = { reset } > reset</ button > </ div > } >
103+ < ErrorBoundary
104+ fallback = { ( err , reset ) => (
105+ < div >
106+ Error: { err } < button onClick = { reset } > reset</ button >
107+ </ div >
108+ ) }
109+ >
84110 < h4 > FileSystem primitive</ h4 >
85111 < p > Object virtual file system (localStorage persistence)</ p >
86112 < FsDir fs = { vfs } path = "/" />
87- < Show when = { ! afs . loading && ! afs . error && afs ( ) } fallback = {
88- < button disabled = { afs . loading } onClick = { ( ) => setStartAfs ( true ) } >
89- Request directory access
90- </ button >
91- } >
113+ < Show
114+ when = { ! afs . loading && ! afs . error && afs ( ) }
115+ fallback = {
116+ < button disabled = { afs . loading } onClick = { ( ) => setStartAfs ( true ) } >
117+ Request directory access
118+ </ button >
119+ }
120+ >
92121 < p > Web Filesystem Access file system</ p >
93- < p > < em > Warning!</ em > This can overwrite or delete actual files!</ p >
122+ < p >
123+ < em > Warning!</ em > This can overwrite or delete actual files!
124+ </ p >
94125 < FsDir fs = { afs ( ) ! } path = "/" />
95126 </ Show >
96127 </ ErrorBoundary >
0 commit comments