@@ -25,15 +25,21 @@ const PythonRunner = () => {
2525
2626 const [ senseHatEnabled , setSenseHatEnabled ] = useState ( false ) ;
2727
28+ const getInput = ( ) => {
29+ const pageInput = document . getElementById ( "input" )
30+ const webComponentInput = document . querySelector ( 'editor-wc' ) ? document . querySelector ( 'editor-wc' ) . shadowRoot . getElementById ( "input" ) : null ;
31+ return pageInput || webComponentInput
32+ }
33+
2834 useEffect ( ( ) => {
2935 if ( codeRunTriggered ) {
3036 runCode ( ) ;
3137 }
3238 } , [ codeRunTriggered ] ) ;
3339
3440 useEffect ( ( ) => {
35- if ( codeRunStopped && document . getElementById ( "input" ) ) {
36- const input = document . getElementById ( "input" )
41+ if ( codeRunStopped && getInput ( ) ) {
42+ const input = getInput ( )
3743 input . removeAttribute ( "id" )
3844 input . removeAttribute ( "contentEditable" )
3945 dispatch ( setError ( "Execution interrupted" ) ) ;
@@ -44,8 +50,8 @@ const PythonRunner = () => {
4450 useEffect ( ( ) => {
4551 if ( ! drawTriggered && p5Output . current && p5Output . current . innerHTML !== '' ) {
4652 Sk . p5 . stop ( ) ;
47- if ( document . getElementById ( "input" ) ) {
48- const input = document . getElementById ( "input" )
53+ if ( getInput ( ) ) {
54+ const input = getInput ( )
4955 input . removeAttribute ( "id" )
5056 input . removeAttribute ( "contentEditable" )
5157 }
@@ -189,7 +195,7 @@ const PythonRunner = () => {
189195 const outputPane = output . current ;
190196 outputPane . appendChild ( inputSpan ( ) ) ;
191197
192- const input = document . getElementById ( "input" ) || document . querySelector ( 'editor-wc' ) . shadowRoot . getElementById ( "input" )
198+ const input = getInput ( )
193199 input . focus ( ) ;
194200
195201 return new Promise ( function ( resolve , reject ) {
@@ -252,9 +258,10 @@ const PythonRunner = () => {
252258 } ,
253259 ) . catch ( err => {
254260 const message = err . message || err . toString ( ) ;
261+ console . log ( message )
255262 dispatch ( setError ( message ) ) ;
256- if ( document . getElementById ( "input" ) ) {
257- const input = document . getElementById ( "input" ) || document . querySelector ( 'editor-wc' ) . shadowRoot . getElementById ( "input" )
263+ if ( getInput ( ) ) {
264+ const input = getInput ( )
258265 input . removeAttribute ( "id" )
259266 input . removeAttribute ( "contentEditable" )
260267 }
@@ -274,9 +281,9 @@ const PythonRunner = () => {
274281 return ;
275282 }
276283
277- const inputBox = document . getElementById ( "input" ) || document . querySelector ( 'editor-wc' ) . shadowRoot . getElementById ( "input" ) ;
284+ const inputBox = getInput ( ) ;
278285 if ( inputBox && e . target !== inputBox ) {
279- const input = document . getElementById ( "input" ) || document . querySelector ( 'editor-wc' ) . shadowRoot . getElementById ( "input" )
286+ const input = getInput ( )
280287 const selection = window . getSelection ( ) ;
281288 selection . removeAllRanges ( ) ;
282289
0 commit comments