Skip to content

Repository files navigation

Blockly for Node.js and Browser via CommonJS module

Build

Supports JavaScript, PHP, Dart, Lua and Python generators.

Live demo with async locales

Install

yarn add node-blockly

Usage

Node.js

All generators

varBlockly=require('node-blockly');

Or you may use standalone generators to decrease memory usage

varBlockly=require('node-blockly/lua');

Browser

All generators

varBlockly=require('node-blockly/browser');

Example

Node.js

varBlockly=require('node-blockly');varxmlText=`<xml xmlns="http://www.w3.org/1999/xhtml"> <block type="variables_set"> <field name="VAR">blockly</field> <value name="VALUE"> <block type="text"> <field name="TEXT">Hello Node.js!</field> </block> </value> </block> </xml>`;try{varxml=Blockly.Xml.textToDom(xmlText);}catch(e){console.log(e);return}varworkspace=newBlockly.Workspace();Blockly.Xml.domToWorkspace(xml,workspace);varcode=Blockly.JavaScript.workspaceToCode(workspace);console.log(code)

Compiled result

varblockly;blockly='Hello Node.js!';

Browser

Live demo (source)

Internationalization

importBlocklyfrom'node-blockly/browser';importDefrom'node-blockly/lib/i18n/de';Blockly.setLocale(De)

Dynamic imports also works but Blockly doesn't re-render workspace. You must re-render it manually after locale loaded

About

Blockly for Node.js and Browser via CommonJS module

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages