@@ -2,12 +2,15 @@ import { useClasser } from "@code-hike/classer";
22import  *  as  React  from  "react" ; 
33
44import  {  useSandpack  }  from  "../../hooks/useSandpack" ; 
5- import  {  getType ,  ConsoleData  }  from  "./utils" ; 
65import  {  RefreshIcon  }  from  "../../icons" ; 
76import  {  CodeEditor  }  from  "../CodeEditor" ; 
87
8+ import  type  {  ConsoleData  }  from  "./utils" ; 
9+ import  {  getType  }  from  "./utils" ; 
10+ 
911const  MAX_MESSAGE_COUNT  =  100 ; 
1012
13+ // TODO: consume clientid 
1114export  const  SandpackConsole : React . FC < {  clientId ?: string  } >  =  ( { 
1215  clientId, 
1316} )  =>  { 
@@ -20,7 +23,6 @@ export const SandpackConsole: React.FC<{ clientId?: string }> = ({
2023  React . useEffect ( ( )  =>  { 
2124    const  unsubscribe  =  listen ( ( message )  =>  { 
2225      if  ( message . type  ===  "console"  &&  message . codesandbox )  { 
23-         console . log ( message ) ; 
2426        setLogs ( ( prev )  =>  { 
2527          const  messages  =  [ ...prev ,  ...message . log ] ; 
2628          messages . slice ( Math . max ( 0 ,  messages . length  -  MAX_MESSAGE_COUNT ) ) ; 
@@ -41,7 +43,7 @@ export const SandpackConsole: React.FC<{ clientId?: string }> = ({
4143
4244  return  ( 
4345    < div  className = { c ( "console" ) } > 
44-       < div  className = { c ( "console-scroll" ) }   ref = { wrapperRef } > 
46+       < div  ref = { wrapperRef }   className = { c ( "console-scroll" ) } > 
4547        { logs . map ( ( {  data,  id,  method } )  =>  { 
4648          return  ( 
4749            < p 
@@ -58,11 +60,11 @@ export const SandpackConsole: React.FC<{ clientId?: string }> = ({
5860                  const  children  =  JSON . stringify ( msg ) ; 
5961
6062                  return  ( 
61-                     < span  className = { c ( "console-span" ) }   key = { `${ msg } ${ index }  } > 
63+                     < span  key = { `${ msg } ${ index }  }   className = { c ( "console-span" ) } > 
6264                      < CodeEditor 
63-                         initMode = "user-visible" 
64-                         fileType = "js" 
6565                        code = { children } 
66+                         fileType = "js" 
67+                         initMode = "user-visible" 
6668                        readOnly 
6769                      /> 
6870                    </ span > 
@@ -74,7 +76,7 @@ export const SandpackConsole: React.FC<{ clientId?: string }> = ({
7476        } ) } 
7577      </ div > 
7678
77-       < button  className = { c ( "console-clean" ) }  onClick = { ( )  =>  setLogs ( [ ] ) } > 
79+       < button  className = { c ( "console-clean" ) }  onClick = { ( ) :  void =>  setLogs ( [ ] ) } > 
7880        < RefreshIcon  /> 
7981      </ button > 
8082    </ div > 
0 commit comments