File tree Expand file tree Collapse file tree 2 files changed +53
-15
lines changed Expand file tree Collapse file tree 2 files changed +53
-15
lines changed Original file line number Diff line number Diff line change 173
173
],
174
174
"example_path" : " https://github.com/githubnext/blocks-tutorial/blob/main/queries.json"
175
175
},
176
+ {
177
+ "type" : " file" ,
178
+ "id" : " processing-block" ,
179
+ "title" : " Processing block" ,
180
+ "description" : " Run your p5.js sketches" ,
181
+ "entry" : " /src/blocks/file-blocks/processing.tsx" ,
182
+ "extensions" : [
183
+ " js"
184
+ ],
185
+ "example_path" : " https://github.com/githubnext/blocks-tutorial/blob/main/processing-sketch.js"
186
+ },
176
187
{
177
188
"type" : " folder" ,
178
189
"id" : " minimap-block" ,
Original file line number Diff line number Diff line change 1
- import { createRef , useEffect } from "react" ;
2
1
import { FileBlockProps } from "@githubnext/utils" ;
3
- import p5 from "p5 " ;
2
+ import { SandpackPreview , SandpackProvider } from "@codesandbox/sandpack-react " ;
4
3
5
4
export default function ( props : FileBlockProps ) {
6
5
const { content } = props ;
7
6
8
- const p5Ref = createRef < HTMLDivElement > ( ) ;
9
-
10
- useEffect ( ( ) => {
11
- if ( p5Ref . current ) {
12
- try {
13
- new p5 ( eval ( content ) , p5Ref . current ) ;
14
- } catch ( e ) {
15
- // console.log(e);
16
- }
17
- }
18
- } , [ p5Ref . current , content ] ) ;
19
-
20
- return < div ref = { p5Ref } > </ div > ;
7
+ return (
8
+ < div
9
+ style = { {
10
+ width : "100%" ,
11
+ height : "100%" ,
12
+ } }
13
+ >
14
+ < SandpackProvider
15
+ externalResources = { [ 'https://cdn.jsdelivr.net/npm/p5@1.4.1/lib/p5.js' ] }
16
+ customSetup = { {
17
+ files : {
18
+ "/src/index.js" : {
19
+ code : content ,
20
+ } ,
21
+ "/index.html" : {
22
+ code : `<!DOCTYPE html>
23
+ <html>
24
+ <head>
25
+ <meta charset="UTF-8" />
26
+ </head>
27
+ <body>
28
+ <main></main>
29
+ <script src="src/index.js"></script>
30
+ </body>
31
+ </html>`
32
+ }
33
+ } ,
34
+ dependencies : { } ,
35
+ entry : "/src/index.js" ,
36
+ main : "/src/index.js" ,
37
+ environment : "static" ,
38
+ } }
39
+ autorun
40
+ >
41
+ < SandpackPreview
42
+ showOpenInCodeSandbox = { false }
43
+ showRefreshButton = { false }
44
+ />
45
+ </ SandpackProvider >
46
+ </ div >
47
+ ) ;
21
48
}
You can’t perform that action at this time.
0 commit comments