node-blockly
TypeScript icon, indicating that this package has built-in type declarations

1.2.8 • Public • Published

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

var Blockly = require('node-blockly');

Or you may use standalone generators to decrease memory usage

var Blockly = require('node-blockly/lua');

Browser

All generators

var Blockly = require('node-blockly/browser');

Example

Node.js

var Blockly = require('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

Live demo (source)

Internationalization

import Blockly from 'node-blockly/browser';
import De from '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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.873latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.873
1.2.70
1.2.61
1.2.50
1.2.40
1.2.30
1.2.20
1.1.21
1.1.10
1.1.00
1.0.400
1.0.390
1.0.380
1.0.370
1.0.360
1.0.350
1.0.340
1.0.330
1.0.320
1.0.310
1.0.300
1.0.2913
1.0.280
1.0.270
1.0.261
1.0.250
1.0.240
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.1639
1.0.150
1.0.14108
1.0.130
1.0.120
1.0.110
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i node-blockly

Weekly Downloads

236

Version

1.2.8

License

ISC

Unpacked Size

5.22 MB

Total Files

107

Last publish

Collaborators

  • mo4islona