* chore: Clean up NPM package module wrappers
- Slightly improve documentation for each file based on helpful
explanations given by @samelhusseini.
- Removed redundant code---e.g., loading `javascript_compressed.js`
creates and sets Blockly.JavaScript as a side effect, so there is
no need to set `Blockly.JavaScript = BlocklyJavaScript` in
`dist/javascript.js` (generated from `scripts/package/javascript.js`).
- Remove possibly harmful code---e.g., `Blockly.Msg` is initialised
with a null-prototype object in `blockly_compressed.js` and that
initial object should under no circumstances be replaced.
- Remvoe downright misleading code---e.g., `dist/blocks.js` previously
_appeared_ to replace Blockly.Blocks with an empty object, but in
fact the `Blockly` name referred at that point to the exports object
from `blocks_compressed.js`, which would randomly get a useless
`{}`-valued `.Blocks` property tacked on to it; similarly, code in
`dist/browser.js` (generated from `scripts/package/browser/index.js`)
appeared to copy definitions from `BlocklyBlocks` to `Blockly.Blocks`,
but the former would always be (the aforementioned) empty object,
making this code ineffective.
* chore: Improve chunk definition / UMD generation
Make several improvements to the chunks global and chunkWrapper
function:
- Document chunk definition format (and improve the names of
of the documented properties).
- Replace the chunk `.namespace` property with two others:
- `.exports` names the variable/property to be returned by the
factory function, and which will be set on the global object if
the module is loaded in a browser.
- `.importAs` names the parameter that this chunk's exports value
is to be passed to the factory function of other chunks which
depend on this one. (This needs to be different because e.g.
`Blockly.blocks` is not a valid parameter name.)
- Change the definition for the blocks chunk to export Blockly.Blocks
(i.e., the block definition dictionary) as blocks_compressed.js
did previous to PR #5721 (chunked compilation), rather than the
(empty and soon to vanish) Blockly.blocks namespace object.
This is a win for backwards compatibility, though it does mean that
if we want to expose the `loopTypes` export from `blocks/loops.js`
we will need to find a different way to do so.
Blockly
Google's Blockly is a web-based, visual programming editor. Users can drag blocks together to build programs. All code is free and open source.
The source for this module is in the Blockly repo.
Installation
You can install this package either via npm or unpkg.
npm
npm install blockly
unpkg
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
Example Usage
import Blockly from 'blockly';
Blockly.inject('blocklyDiv', {
...
})
Samples
For samples on how to integrate Blockly into your project, view the list of samples at blockly-samples.
Importing Blockly
When you import Blockly with import * as Blockly from 'blockly'; you'll get the default modules:
Blockly core, Blockly built-in blocks, the JavaScript generator and the English lang files.
If you need more flexibility, you'll want to define your imports more carefully:
Blockly Core
import * as Blockly from 'blockly/core';
Blockly built in blocks
import 'blockly/blocks';
Blockly Generators
If your application needs to generate code from the Blockly blocks, you'll want to include a generator.
import 'blockly/python';
to include the Python generator, you can also import blockly/javascript, blockly/php, blockly/dart and blockly/lua.
Blockly Languages
import * as Fr from 'blockly/msg/fr';
Blockly.setLocale(Fr);
To import the French lang files. Once you've imported the specific lang module, you'll also want to set the locale in Blockly.
For a full list of supported Blockly locales, see: https://github.com/google/blockly/tree/master/msg/js
License
Apache 2.0