Skip to content

Commit 5930fa0

Browse files
committed
Update for Blocks public beta
1 parent b1a707e commit 5930fa0

20 files changed

+46053
-9993
lines changed

.eslintrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
"standard",
55
"standard-react",
66
"plugin:prettier/recommended",
7-
"prettier/standard",
8-
"prettier/react",
97
"plugin:@typescript-eslint/eslint-recommended"
108
],
119
"env": {

.idea/watcherTasks.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,78 @@
1010
npm install --save react-blocks-editor
1111
```
1212

13-
## Usage
13+
## Quick Start
1414

1515
```tsx
1616
import React from 'react'
17+
import ReactDOM from 'react-dom'
1718
import BlocksEditor from 'react-blocks-editor'
1819

19-
const MyEditor = () => {
20-
const options = {
21-
menu: 'hidden' // default: undefined
20+
ReactDOM.render(
21+
<BlocksEditor />,
22+
document.getElementById('root'),
23+
)
24+
```
25+
26+
## Advanced Usage
27+
28+
```tsx
29+
import React from 'react'
30+
import { BlocksEditor, EditorState } from 'react-blocks-editor'
31+
32+
const App = () => {
33+
34+
// Called whenever the user changes (or manually saves) the editor state
35+
const handleSave = (state: EditorState) => {
36+
console.log('Editor state:', state)
2237
}
2338

2439
return (
25-
<BlocksEditor style={{ width: '100%', height: 400 }} options={options}>
40+
<BlocksEditor
41+
style={{ height: '100vh' }}
42+
options={{
43+
theme: 'dark',
44+
menu: 'hidden',
45+
tutorial: 'hello-world'
46+
}}
47+
onSave={handleSave}>
48+
2649
{({ loadState }) => {
27-
console.log('Loaded iframe.')
50+
console.log('Loaded editor iframe.')
2851

52+
// Load a specific project state (.blocks JSON format).
2953
loadState({
3054
name: 'Project name',
3155
description: 'Project description',
32-
nodes: [{...}]
56+
nodes: {
57+
// Text block
58+
'message': {
59+
type: 'LiteralText',
60+
position: [0, 0],
61+
data: {
62+
value: 'Hello world!'
63+
},
64+
outputs: {
65+
value: [{
66+
// Reference to 'motoko' node and 'value' input socket
67+
node: 'motoko',
68+
input: 'input'
69+
}]
70+
}
71+
},
72+
// Motoko compiler block
73+
'motoko': {
74+
type: 'CompileMotoko',
75+
position: [250, 0]
76+
}
77+
}
3378
})
3479
}}
3580
</BlocksEditor>
3681
)
3782
}
83+
84+
export default App
3885
```
3986

4087
---

example/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This example was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
It is linked to the react-blocks-editor package in the parent directory for development purposes.
4+
5+
You can run `npm install` and then `npm start` to test your package.

0 commit comments

Comments
 (0)