
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
react-blockly-drawer
Advanced tools
A React component to play with Blockly.
A React component to play with Blockly.
$ npm install react-blockly-drawer node-blockly --save
import React from 'react';
import ReactDOM from 'react-dom';
import Blockly from 'node-blockly/browser';
import BlocklyDrawer, { Block, Category } from 'react-blockly-drawer';
const helloWorld = {
name: 'HelloWorld',
category: 'Demo',
block: {
init: function () {
this.jsonInit({
message0: 'Hello %1',
args0: [
{
type: 'field_input',
name: 'NAME',
check: 'String',
},
],
output: 'String',
colour: 160,
tooltip: 'Says Hello',
});
},
},
generator: (block) => {
const message = `'${block.getFieldValue('NAME')}'` || '\'\'';
const code = `console.log('Hello ${message}')`;
return [code, Blockly.JavaScript.ORDER_MEMBER];
},
};
ReactDOM.render(
<BlocklyDrawer
tools={[helloWorld]}
onChange={(code, workspace) => {
console.log(code, workspace);
}}
language={Blockly.JavaScript}
appearance={
{
categories: {
Demo: {
colour: '270'
},
},
}
}
>
<Category name="Variables" custom="VARIABLE" />
<Category name="Values">
<Block type="math_number" />
<Block type="text" />
</Category>
</BlocklyDrawer>,
document.getElementById('root')
);
onChange: function (code, workspaceXML) {}Event listener to the workspace change. Two arguments are passed to this callback:
code is the generated code of your created program (see the property
language);workspaceXML is an XML text that corresponds to the content of the workspace.language: object [optional]A language generator, either one of the languages described in the
Blockly documentation on code generation or
a custom object with method workspaceToCode. Default generator is
Blockly.Javascript. If language is set to null, no code is generated and
the first argument passed to the onChange function, code will be null.
children: node(s)Blockly predefined blocks/tools can be passed as children of this component. For example, the following content could be passed.
<Category name="Variables" custom="VARIABLE" />
<Category name="Values">
<Block type="math_number" />
<Block type="text" />
</Category>
workspaceXML: string [optional]Workspace XML initial content. It is no necessary to pass it if you want a new/empty workspace.
injectOptions: object [optional]Options for the workspace. See blocklyDocumentation for details.
appearance: object [optional]Options for styling.
In order to style the block categories an object containing the categories
property should be passed. This property categories is an object that has
the categories names as keys and the values contain the styling properties for that block category.
For example:
{
categories: {
Demo: {
colour: '270'
},
},
}
This way the category Demo is colored.
See blocklyDocumentation for block categories styling. for details.
className: stringComponent's class
style: objectComponent's style
tools: array [optional]An array of your custom block/tools. Each item should have the following properties:
name: stringIt is the name of the block/tool.
category: stringThe category where this block/tool is going to be inside of.
block: objectBlock's definition as it is done in Blockly.
generator: functionGenerator's definition as it is done in Blockly.
For example:
{
name: 'HelloWorld',
category: 'Demo',
block: {
init: function () {
this.jsonInit({
message0: 'Hello %1',
args0: [
{
type: 'field_input',
name: 'NAME',
check: 'String',
},
],
output: 'String',
colour: 160,
tooltip: 'Says Hello',
});
},
},
generator: (block) => {
const message = `'${block.getFieldValue('NAME')}'` || '\'\'';
const code = `console.log('Hello ${message}')`;
return [code, Blockly.JavaScript.ORDER_MEMBER];
},
}
git clone git@github.com:xvicmanx/react-blockly-drawer.git
npm test
npm run build
See CONTRIBUTING.md
Feel free to make any suggestion to improve this component.
FAQs
A React component to play with blockly.
We found that react-blockly-drawer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.