File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 11import CodeCell from "./components/codecell"
22import runCell from "./lib/runCell"
3+ import setCellCode from "./lib/setCellCode"
34
4- export { CodeCell , runCell }
5+ export { CodeCell , runCell , setCellCode }
Original file line number Diff line number Diff line change 1+ export default function setCellCode ( cellId : string , code : string , devMode = false ) {
2+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3+ const iframe : any = document . getElementById ( `${ cellId } ` ) ;
4+ if ( ! iframe ) return console . error ( `Cell with id ${ cellId } not found` ) ;
5+ if ( iframe . contentWindow != null ) {
6+ const host = devMode ? "*" : "https://ide.betteridea.dev" ;
7+ iframe . contentWindow . postMessage ( { action : "set_code" , code } , host ) ;
8+ }
9+ }
Original file line number Diff line number Diff line change @@ -2,14 +2,22 @@ import React from 'react'
22import ReactDOM from 'react-dom/client'
33import CodeCell from "./components/codecell"
44import runCell from "./lib/runCell"
5+ import setCellCode from './lib/setCellCode'
56import "./styles/index.css"
67
8+ function onInput ( e : string ) {
9+ console . log ( e )
10+ setCellCode ( "1" , e , true )
11+ }
12+
13+
714ReactDOM . createRoot ( document . getElementById ( 'root' ) ! ) . render (
815 < React . StrictMode >
916 < div style = { { padding : "10px" , backgroundColor : "black" , height : "100vh" } } >
1017 < button onClick = { ( ) => {
1118 runCell ( "1" , true )
1219 } } > run</ button >
20+ < input type = "text" id = "code" onChange = { ( e ) => { onInput ( e . target . value ) } } />
1321 < CodeCell appName = "test-cell" cellId = "1" devMode />
1422 </ div >
1523 </ React . StrictMode > ,
You can’t perform that action at this time.
0 commit comments