@@ -26,17 +26,15 @@ function CodeEditor(props: {
2626 theme : PrismTheme
2727 showLineNumbers : boolean
2828 readonly : boolean
29+ prefix ?: string
2930 sandbox ?: {
3031 files : Record < string , { content : string } >
3132 main ?: string
3233 }
3334} ) {
34- const { code, language, sandbox } = props
35- // const [disabled, setDisabled] = useState(props.disabled);
36- const [ allowUndo , setAllowUndo ] = useState ( false )
37- const [ tmpCode , setTmpCode ] = useState ( "" )
38- const [ hasFocus , setHasFocus ] = useState ( false )
39-
35+ const { code, sandbox, prefix } = props
36+ const prefixedCode =
37+ ! prefix || code . indexOf ( prefix ) > - 1 ? code : prefix + "\n\n" + code
4038 useEffect ( ( ) => {
4139 if ( props . onChange ) {
4240 props . onChange ( code )
@@ -52,11 +50,6 @@ function CodeEditor(props: {
5250 range . collapse ( true )
5351 selectObj . addRange ( range )
5452 }
55- setHasFocus ( true )
56- }
57-
58- const handleBlur = ( ) => {
59- setHasFocus ( false )
6053 }
6154
6255 return (
@@ -111,7 +104,6 @@ function CodeEditor(props: {
111104 } }
112105 spellCheck = "false"
113106 onFocus = { handleFocus }
114- onBlur = { handleBlur }
115107 >
116108 < code
117109 className = { clsx (
@@ -148,14 +140,14 @@ function CodeEditor(props: {
148140 < div className = { codeBlockContentStyles . buttonGroup } >
149141 < CopyButton
150142 className = { codeBlockContentStyles . codeButton }
151- code = { code }
143+ code = { prefixedCode }
152144 />
153145 { sandbox && (
154146 < CodeSandboxButton
155147 className = { codeBlockContentStyles . codeButton }
156148 files = { {
157149 ...sandbox . files ,
158- [ sandbox . main ] : { content : code } ,
150+ [ sandbox . main ] : { content : prefixedCode } ,
159151 } }
160152 startFile = { sandbox . main }
161153 />
0 commit comments