@@ -18,9 +18,7 @@ interface CodeBlockProps {
1818 code : string
1919 result : { [ key : string ] : string }
2020 githubRepo : string | undefined
21- editable : boolean
2221 showLineNumbers : boolean
23- readonly : boolean
2422 langVersion ?: string
2523 tool ?: string
2624 prefix ?: string
@@ -32,66 +30,22 @@ interface CodeBlockProps {
3230
3331function RunButton ( props : {
3432 onClick : ( ) => Promise < void >
35- runFinished : boolean
3633} ) {
37- const { onClick, runFinished } = props
38- const text = "Run"
34+ const { onClick } = props
3935 return (
4036 < button className = "button button--primary" onClick = { onClick } >
41- { runFinished ? text : "Running..." }
37+ Run
4238 </ button >
4339 )
4440}
4541
46- function Output ( props : {
47- language : string
48- result : { [ key : string ] : string | Array < string > }
49- codeChanged : boolean
50- statusCodes : { [ key : string ] : string }
51- } ) {
52- const { language, result, codeChanged, statusCodes } = props
53- const success = result . status === statusCodes . success
54- const timeout = result . status === statusCodes . timeout
55- const emptyOutput = result . output === ""
56-
57- if ( emptyOutput ) return null
58-
59- const regularOutput = (
60- < pre className = { codeChanged ? styles . outdated : "" } >
61- { success ? (
62- ""
63- ) : timeout ? (
64- < span style = { { color : "red" } } >
65- { `--${ language } timeout--` }
66- </ span >
67- ) : (
68- < span style = { { color : "red" } } >
69- < b > Script contains one or more errors: </ b >
70- < br />
71- </ span >
72- ) }
73- { success ? result . output : ! timeout && result . error }
74- </ pre >
75- )
76-
77- return (
78- < div >
79- < b > Output{ codeChanged ? " (outdated)" : "" } :</ b >
80- < br />
81- { regularOutput }
82- </ div >
83- )
84- }
85-
8642function CustomCodeEditor ( props : {
8743 id : string
8844 input : string
8945 showLineNumbers ?: boolean
9046 language ?: string
91- editable ?: boolean
9247 onChange ?: ( code : string ) => void
9348 githubRepo : string | undefined
94- readonly : boolean
9549 prefix ?: string
9650 sandbox ?: {
9751 files : Record < string , { content : string } >
@@ -102,10 +56,8 @@ function CustomCodeEditor(props: {
10256 input,
10357 language,
10458 showLineNumbers,
105- editable,
10659 githubRepo,
10760 onChange,
108- readonly,
10961 sandbox,
11062 prefix,
11163 } = props
@@ -119,7 +71,6 @@ function CustomCodeEditor(props: {
11971 < Container
12072 as = "div"
12173 className = { clsx (
122- editable ? styles . editable : "" ,
12374 codeBlockContainerStyles . codeBlockContainer ,
12475 ThemeClassNames . common . codeBlock ,
12576 language && `language-${ language } `
@@ -128,13 +79,13 @@ function CustomCodeEditor(props: {
12879 < CodeEditor
12980 code = { input }
13081 theme = { prismTheme }
131- disabled = { ! editable }
82+ disabled = { false }
13283 key = { String ( isBrowser ) }
13384 className = { codeBlockContentStyles . codeBlockContent }
13485 onChange = { onChange }
13586 language = { language }
13687 prism = { Prism }
137- readonly = { readonly }
88+ readonly = { true }
13889 showLineNumbers = { showLineNumbers }
13990 sandbox = { sandbox }
14091 prefix = { prefix }
@@ -154,18 +105,12 @@ export default function CustomCodeBlock(props: { input: CodeBlockProps }) {
154105 code,
155106 result,
156107 githubRepo,
157- editable,
158108 showLineNumbers,
159- readonly,
160109 sandbox,
161110 prefix,
162111 } = input
163- const [ currCode , setCurrCode ] = useState ( code )
112+ const currCode = code
164113 const [ outputRendered , setOutputRendered ] = useState ( false )
165- const [ runFinished , setRunFinished ] = useState ( true )
166- const [ output , setOutput ] = useState ( result )
167- const [ lastSnippet , setLastSnippet ] = useState ( code )
168- const codeChanged = lastSnippet !== currCode
169114 const { setSource } = useContext ( DevToolsContext )
170115 const clientConfig = {
171116 ts : input => {
@@ -176,7 +121,6 @@ export default function CustomCodeBlock(props: { input: CodeBlockProps }) {
176121
177122 // bypassing server-side rendering
178123 const onDidClickRun = async ( ) => {
179- setRunFinished ( false )
180124 const newResult = { ...result }
181125 let errorMsg : string
182126
@@ -216,50 +160,29 @@ export default function CustomCodeBlock(props: { input: CodeBlockProps }) {
216160 newResult . status = `${ lang } -web-failed`
217161 throw new Error ( errorMsg )
218162 } finally {
219- setLastSnippet ( input )
220- setOutput ( newResult )
221- setRunFinished ( true )
222163 if ( ! outputRendered ) {
223164 setOutputRendered ( true ) // hack for the playground editor
224165 }
225166 }
226167 }
227168
228- const onDidChangeCode = ( code : string ) => {
229- setCurrCode ( code )
230- }
231-
232169 return (
233170 < div >
234171 < CustomCodeEditor
235172 input = { code }
236173 id = { result . hash }
237174 showLineNumbers = { showLineNumbers }
238- onChange = { onDidChangeCode }
239- editable = { editable || outputRendered }
240175 language = { highlight }
241176 githubRepo = { githubRepo }
242- readonly = { readonly }
243177 sandbox = { sandbox }
244178 prefix = { prefix }
245179 />
246180 < >
247181 < div className = { styles . buttons } >
248182 < RunButton
249183 onClick = { onDidClickRun }
250- runFinished = { runFinished }
251184 />
252185 </ div >
253- { outputRendered ? (
254- < Output
255- language = { lang }
256- codeChanged = { codeChanged }
257- result = { output }
258- statusCodes = { statusCodes }
259- />
260- ) : (
261- < div />
262- ) }
263186 </ >
264187 </ div >
265188 )
0 commit comments