0.1.7 • Published 5 years ago
@kids-lab.io/node-blockly v0.1.7
Blockly for Node.js and Browser via CommonJS module
Build
Clone the repository
git clone https://github.com/YannCaron/node-blockly.git
Install npm packages
cd node-blockly
npm install
Upgrade the sub modules
npm run blockly:upgrade
Build blockly
npm run blockly:build
Build package
npm run prepublish
Install
npm i @kids-lab.io/node-blockly -S
Usage
Node.js
All generators
var Blockly = require('@kids-lab.io/node-blockly');
Or you may use standalone generators to decrease memory usage
var Blockly = require('@kids-lab.io/node-blockly/lua');
Browser
All generators
var Blockly = require('@kids-lab.io/node-blockly/browser');
Example
Node.js
var Blockly = require('@kids-lab.io/node-blockly');
var xmlText = `<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 {
var xml = Blockly.Xml.textToDom(xmlText);
}
catch (e) {
console.log(e);
return
}
var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace);
var code = Blockly.JavaScript.workspaceToCode(workspace);
console.log(code)
Compiled result
var blockly;
blockly = 'Hello Node.js!';
Browser
Internationalization
import Blockly from '@kids-lab.io/node-blockly/browser';
import en from '@kids-lab.io/node-blockly/lib/i18n/en';
Blockly.setLocale(en)
Dynamic imports also works but Blockly doesn't re-render workspace. You must re-render it manually after locale loaded