4
4
< script src ="https://unpkg.com/@babel/standalone@7.17.x/babel.min.js " crossorigin > </ script >
5
5
< script src ="https://unpkg.com/react@17.x/umd/react.development.js " crossorigin > </ script >
6
6
< script src ="https://unpkg.com/react-dom@17.x/umd/react-dom.development.js " crossorigin > </ script >
7
- < script src ="https://unpkg.com/@uiw/codepen-require-polyfill/index.js " crossorigin > </ script >
8
7
< title > Run Web</ title >
9
8
< meta name ="description " content ="Online Code Editor for Rapid Web Development. " />
10
9
< meta name ="keywords " content ="react,component,js,css,html,preview,editor " />
11
10
</ head >
12
11
< body >
13
12
< a href ="https://uiwjs.github.io/react-run-web "> @uiw/react-run-web</ a >
14
13
< div id ="container " style ="padding: 24px "> </ div >
14
+ < script >
15
+ window . require = function ( module ) {
16
+ if ( ! module ) {
17
+ throw new Error ( `this is a fake require only use for import ${ module } ` ) ;
18
+ }
19
+ if ( window . CM && window . CM [ module ] ) {
20
+ return window . CM [ module ] ;
21
+ }
22
+ return window [ module ] ;
23
+ } ;
24
+ </ script >
15
25
< script src ="https://unpkg.com/@uiw/react-run-web/dist/run-web.min.js "> </ script >
16
26
< script type ="text/babel ">
17
27
import RunWeb from '@uiw/react-run-web' ;
26
36
}
27
37
ReactDOM . render ( < Demo /> , document . getElementById ( 'container' ) ) ;
28
38
</ script >
39
+ < div id ="code "> </ div >
40
+ < script src ="https://codemirror.net/6/codemirror.js "> </ script >
41
+ < script src ="https://unpkg.com/@uiw/react-codemirror/dist/codemirror.min.js "> </ script >
42
+ < script type ="text/babel ">
43
+ import CodeMirror from '@uiw/codemirror' ;
44
+ import { javascript } from '@codemirror/lang-javascript' ;
45
+
46
+ const code = `import RunWeb from '@uiw/react-run-web';\n
47
+ const Demo = () => {
48
+ return (
49
+ <RunWeb
50
+ css="div {color:red;}"
51
+ js="console.log('hello world!')"
52
+ html="<div>hello world!</div>"
53
+ />
54
+ );
55
+ }` ;
56
+
57
+ const Demo = ( ) => {
58
+ return (
59
+ < div >
60
+ < CodeMirror
61
+ value = { code }
62
+ editable = { false }
63
+ height = "200px"
64
+ extensions = { [ javascript ( { jsx : true } ) ] }
65
+ onChange = { ( value , viewUpdate ) => {
66
+ console . log ( 'value:' , value ) ;
67
+ } }
68
+ />
69
+ </ div >
70
+ ) ;
71
+ } ;
72
+
73
+ ReactDOM . render ( < Demo /> , document . getElementById ( 'code' ) ) ;
74
+ </ script >
29
75
</ body >
30
76
</ html >
0 commit comments