55import React , { useRef , useEffect , useState } from "react" ;
66// eslint-disable-next-line import/no-extraneous-dependencies
77import PropTypes from "prop-types" ;
8+ import TextareaAutosize from "react-textarea-autosize" ;
89import CodeMirror from "react-codemirror" ;
910import { Remarkable } from "remarkable" ;
1011import { CgMathPlus , CgArrowUp , CgArrowDown , CgTrash } from "react-icons/cg" ;
1112import { BsFillCaretRightFill } from "react-icons/bs" ;
12- import { print_val , table } from "./utils" ;
13+ import { print_val } from "./utils" ;
1314import {
1415 AddCellButton ,
1516 CellButton ,
1617 CellHead ,
1718 OtherCellButtonWrapper ,
18- CellTextArea ,
1919 Output ,
20+ CellContainer ,
21+ RunContainer ,
22+ CellBodyContainer ,
2023} from "./Cell.style" ;
2124
2225require ( "codemirror/lib/codemirror.css" ) ;
@@ -34,6 +37,7 @@ export default function Cell({
3437 const refOutput = useRef ( "" ) ;
3538 const [ showMoreCellButton , setShowMoreCellButton ] = useState ( "none" ) ;
3639 useEffect ( ( ) => {
40+ console . log ( currentCell ) ;
3741 if ( currentCell === cellId ) {
3842 setShowMoreCellButton ( "flex" ) ;
3943 } else {
@@ -44,9 +48,10 @@ export default function Cell({
4448 if ( cell . type === "code" ) {
4549 const input = refCode . current . getCodeMirror ( ) . getValue ( ) ;
4650 // eslint-disable-next-line no-eval
47- let output = ( "global" , eval ) ( input ) ;
51+ let output = ( "global" , eval ) ( input ) || "" ;
4852 try {
4953 if ( Array . isArray ( output ) ) {
54+ console . log ( "output" ) ;
5055 output = print_val ( output ) ;
5156 } else if ( typeof output === "object" && output !== null ) {
5257 output = JSON . stringify ( output ) ;
@@ -57,28 +62,28 @@ export default function Cell({
5762 // retreive value from the console function
5863 console . oldLog = console . log ;
5964 console . log = function ( value ) {
60- output = value ;
6165 return value ;
6266 } ;
6367 // eslint-disable-next-line no-eval
6468 output = eval ( input ) ;
6569 if ( Array . isArray ( output ) ) {
70+ console . log ( "output" ) ;
6671 output = print_val ( output ) ;
6772 } else if ( typeof output === "object" && output !== null ) {
6873 output = JSON . stringify ( output ) ;
6974 if ( output === "{}" ) {
7075 output = "" ;
7176 }
7277 }
73- console . log ( output ) ;
74- }
75- if (
76- input . includes ( "table" ) ||
77- input . includes ( "plot" ) ||
78- input . includes ( "console.log(" )
79- ) {
80- output = table ( output ) ;
78+ console . log ( output , "helllo" ) ;
8179 }
80+ // if (
81+ // input.includes("table") ||
82+ // input.includes("plot") ||
83+ // input.includes("console.log(")
84+ // ) {
85+ // output = table(output);
86+ // }
8287 // eslint-disable-next-line no-eval
8388 const cellstate = { ...cell , input, output } ;
8489 dispatch ( { type : "CHANGE_CELL" , payload : cellstate } ) ;
@@ -153,6 +158,8 @@ export default function Cell({
153158 const showOutput = ( ) => {
154159 if ( cell . type === "text" ) {
155160 refOutput . current . style . display = "block" ;
161+ refOutput . current . style . background = "white" ;
162+ refOutput . current . style . color = "black" ;
156163 refCode . current . style . display = "none" ;
157164 }
158165 } ;
@@ -162,32 +169,21 @@ export default function Cell({
162169 } ;
163170 return (
164171 < >
165- < div
166- style = { {
167- display : "flex" ,
168- alignItems : "center" ,
169- justifyContent : "space-between" ,
170- marginTop : "20px" ,
171- } }
172- >
173- < div style = { { marginTop : "30px" } } >
172+ < CellContainer >
173+ < RunContainer >
174174 { currentCell === cellId ? (
175- < button
176- style = { {
177- background : "none" ,
178- border : "none" ,
179- } }
175+ < div
180176 onClick = { ( ) => {
181177 getCode ( ) ;
182178 } }
183179 >
184180 < BsFillCaretRightFill color = "#FFDF28" fontSize = "30px" />
185- </ button >
181+ </ div >
186182 ) : (
187183 < div > [{ cellId } ]:</ div >
188184 ) }
189- </ div >
190- < div style = { { width : "95%" } } >
185+ </ RunContainer >
186+ < CellBodyContainer >
191187 < CellHead >
192188 < div
193189 style = { {
@@ -267,18 +263,25 @@ export default function Cell({
267263 value = { cell . input }
268264 ref = { refCode }
269265 options = { {
270- tabSize : 1 ,
271- theme : "yeti" ,
272- lineNumbers : true ,
273266 mode : "javascript" ,
267+ extraKeys : { "Ctrl-Space" : "autocomplete" } ,
268+ autoCloseBrackets : true ,
269+ matchBrackets : true ,
270+ lineNumbers : true ,
271+ tabSize : 4 ,
272+ theme : "yeti" ,
273+ autocorrect : true ,
274274 } }
275275 />
276276 ) : (
277- < TextCell refText = { refCode } />
277+ < TextCell
278+ selectCell = { ( ) => setCurrentCell ( cellId ) }
279+ refText = { refCode }
280+ />
278281 ) }
279282 </ div >
280- </ div >
281- </ div >
283+ </ CellBodyContainer >
284+ </ CellContainer >
282285 < div
283286 style = { {
284287 display : "flex" ,
@@ -296,8 +299,10 @@ export default function Cell({
296299 ) ;
297300}
298301
299- function TextCell ( { refText } ) {
300- return < CellTextArea ref = { refText } > </ CellTextArea > ;
302+ function TextCell ( { refText, selectCell } ) {
303+ return (
304+ < TextareaAutosize onFocus = { selectCell } ref = { refText } > </ TextareaAutosize >
305+ ) ;
301306}
302307
303308TextCell . propTypes = {
0 commit comments