Skip to content

Commit c015d5a

Browse files
authored
Merge pull request #16 from githubnext/ia/processing
Re-add processing block
2 parents 08a6112 + 0ca083d commit c015d5a

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@
173173
],
174174
"example_path": "https://github.com/githubnext/blocks-tutorial/blob/main/queries.json"
175175
},
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+
},
176187
{
177188
"type": "folder",
178189
"id": "minimap-block",

src/blocks/file-blocks/processing.tsx

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
1-
import { createRef, useEffect } from "react";
21
import { FileBlockProps } from "@githubnext/utils";
3-
import p5 from "p5";
2+
import { SandpackPreview, SandpackProvider } from "@codesandbox/sandpack-react";
43

54
export default function (props: FileBlockProps) {
65
const { content } = props;
76

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+
);
2148
}

0 commit comments

Comments
 (0)