blockly-fluid 1.0.17 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +73 -1
  2. package/index.js +3 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,76 @@
1
- # Blockly Dynamic Blocks Proxy 🎛️✨
1
+ # Blockly, but fluid
2
+
3
+ If you've ever used Blockly before, you'd know what kind of pain it is to use. Especially crafting your own blocks. You're not alone. Blockly Fluid is the DX-focused adapter of defining blocks with their own generators.
4
+
5
+ ## Installation
6
+
7
+ ### Node.js/Deno/Bun
8
+
9
+ ```sh
10
+ $ npm install blockly-fluid
11
+ ```
12
+
13
+ #### ESM
14
+
15
+ ```js
16
+ import BlocklyFluid from "blockly-fluid";
17
+ ```
18
+
19
+ #### CommonJS
20
+
21
+ ```js
22
+ const BlockyFluid = require("blockly-fluid");
23
+ ```
24
+
25
+ ### Browser
26
+
27
+ ```js
28
+ import BlockyFluid from "https://esm.sh/blockly-fluid";
29
+ ```
30
+
31
+ ## Initialization
32
+
33
+ You have to provide your own Blockly instance since there isn't a reliable way to import Blockly in every environment.
34
+
35
+ ```js
36
+ const Blocks = BlocklyFluid(Blockly, options);
37
+ ```
38
+
39
+ ### Options
40
+
41
+ All options are **optional**, Blockly Fluid tries to never force specifying specific information and assumes defaults by default.
42
+
43
+ ```js
44
+ {
45
+ generator: Blockly.JavaScript /*
46
+ This is the fallback generator. It will be used for the "generator" property of a block's definition.
47
+ */,
48
+ generators: {
49
+ JavaScript: Blockly.JavaScript // etc.
50
+ },
51
+ translate: (text) => mySuperCoolTranslationLogic(text) // translates labels, default values & tooltips
52
+ }
53
+ ```
54
+
55
+ ## Make My Block
56
+
57
+ ```js
58
+ Blocks["block-name"] = {
59
+ hat: false /*
60
+ default: false,
61
+ purpose:
62
+ - creates a round shape on top of the block
63
+ - great for event blocks
64
+ */,
65
+ layout: ["wait", "SECONDS", "seconds"] /*
66
+ default: [],
67
+ purpose:
68
+ - specifies the parts of a block in chronological order
69
+ - if the value is found to be the name of an input, field or statement, it will be inserted
70
+ - otherwise, the text will be inserted as a label
71
+ */
72
+ }
73
+ ```
2
74
 
3
75
  A flexible **Proxy wrapper** for Blockly blocks that lets you define **dynamic inputs, layouts, fields, and shadows** with ease! Perfect for creating modular, reusable blocks that can adapt at runtime.
4
76
 
package/index.js CHANGED
@@ -107,7 +107,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
107
107
  this.setOutput(true, (output === true) ? null : (([String, Number, Boolean, Array, Object].includes(output)) ? output.name : output));
108
108
  };
109
109
 
110
- this.setColour((color != null) ? ((typeof color === "function") ? color() : color) : (((toolbox) => toolbox.contents || toolbox.contents_)(Blockly.getMainWorkspace().getToolbox()).find((category) => category.toolboxItemDef_.contents?.some((block) => block.type === name))?.toolboxItemDef_?.colour || "#000000"));
110
+ this.setColour((color != null) ? ((typeof color === "function") ? color() : color) : (((toolbox) => toolbox.contents_ || toolbox.contents.values())(Blockly.getMainWorkspace().getToolbox()).find((category) => category.toolboxItemDef_.contents?.some((block) => block.type === name))?.toolboxItemDef_?.colour || "#000000"));
111
111
  this.setInputsInline((typeof inline === "function") ? inline() : inline);
112
112
  this.setDeletable((typeof deletable === "function") ? deletable() : deletable);
113
113
  this.setTooltip(translate((typeof tooltip === "function") ? tooltip() : tooltip));
@@ -183,7 +183,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
183
183
  code,
184
184
  languageGenerator.ORDER_NONE
185
185
  ];
186
- })(blockGenerator({
186
+ })((typeof blockGenerator === "function") ? blockGenerator({
187
187
  ...block.inputList.reduce((accumulator, input) => ({
188
188
  ...accumulator,
189
189
  ...Object.fromEntries(input.fieldRow.filter((field) => field.name).map((field) => [
@@ -201,7 +201,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
201
201
  })[input.type] || (() => null))()
202
202
  } : {}
203
203
  }), {}),
204
- }, languageGenerator)));
204
+ }, languageGenerator) : blockGenerator));
205
205
  });
206
206
 
207
207
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockly-fluid",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "A flexible proxy wrapper for Blockly blocks.",
5
5
  "main": "index.js",
6
6
  "scripts": {