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

0.5.0 • Public • Published

better-blockly

A fully typesafe builder utility for defining Blockly blocks and implementaions in the same place with a focus on DX and type saftey.

Usage

// src/blocks/std.ts

import { createBlockBuilder } from "better-blockly";

// you can also just roll your own base generator 
import pythonGenerator from "blockly/python"; 

const block = createBlockBuilder({
  generator: pythonGenerator,
  customTypes: ["event"],
});

block("something_did_happen")
  .hue(40)
  .outputs("event")
  .content((view) =>
    view
      .text("Something")
      .dropdown("THING", ["Awesome", "Epic"])
      .text("just happened"),
  )
  .impl((block) => `Events.${block.fields.THING}Thing`);

block("wait_for_event")
  .hue(120)
  .extern()
  .slot("target", {
    allow: "event",
    content: (view) => view.text("Wait"),
  })
  .impl((block) => `thread.wait_for_event(${block.resolve("target")})`);

then, in your application make sure to just import 'src/blocks/std.ts'; to load the blocks and voila!

This bit of blockly resolves to "thread.wait_for_event(Events.AwesomeThing)"

Readme

Keywords

Package Sidebar

Install

npm i better-blockly

Weekly Downloads

1

Version

0.5.0

License

MIT

Unpacked Size

289 kB

Total Files

46

Last publish

Collaborators

  • erwijet