diff --git a/src/Lab.tsx b/src/Lab.tsx index 00c2de8..e214c5e 100644 --- a/src/Lab.tsx +++ b/src/Lab.tsx @@ -1,5 +1,5 @@ import {CodeOrg, BlockWorkspace, Header} from 'libprotolab/layout/CodeOrg' -import {blocklyOptions} from './blocks' +import {blocklyOptions} from './blocks/' import {save, load, run} from 'libprotolab/blockly/workspace' export const LAB_NAME = "Protolab" diff --git a/src/blocks.ts b/src/blocks/blocks.ts similarity index 60% rename from src/blocks.ts rename to src/blocks/blocks.ts index 56e46fc..1f6488e 100644 --- a/src/blocks.ts +++ b/src/blocks/blocks.ts @@ -1,14 +1,8 @@ -import { defineBlock, BlocklyOptions, ToolboxDefinition } from "libprotolab/blockly"; +import { defineBlock } from "libprotolab/blockly"; -import { - includeStockCategories, - StockCategory, -} from "libprotolab/blockly/stockBlocks"; -import { getLabName } from "libprotolab/lab-name"; +import "./pool-style-blocks"; -import './pool-style-blocks' - -const your = defineBlock( +export const your = defineBlock( "your", (block, generator) => { const value = generator.valueToCode(block, "VALUE", 0); @@ -30,7 +24,7 @@ const your = defineBlock( } ); -const custom = defineBlock( +export const custom = defineBlock( "custom", (block, generator) => { const value = generator.valueToCode(block, "VALUE", 0); @@ -51,7 +45,7 @@ const custom = defineBlock( } ); -const blocks = defineBlock( +export const blocks = defineBlock( "blocks", (block, generator) => { const value = generator.valueToCode(block, "VALUE", 0); @@ -72,7 +66,7 @@ const blocks = defineBlock( } ); -const here = defineBlock( +export const here = defineBlock( "here", (block, generator) => { const value = generator.valueToCode(block, "VALUE", 0); @@ -92,34 +86,3 @@ const here = defineBlock( tooltip: "Returns number of letters in the provided text.", } ); - -export const toolbox: ToolboxDefinition = { - kind: "categoryToolbox", - contents: [ - { - kind: "category", - name: getLabName(), - categorystyle: "logic_category", - contents: [ - your, - custom, - blocks, - here, - ], - }, - ...includeStockCategories([ - StockCategory.Logic, - StockCategory.Loops, - StockCategory.Math, - StockCategory.Text, - StockCategory.Lists, - StockCategory.Variables, - StockCategory.Functions, - ]), - ], -}; - -// For options, see: https://developers.google.com/blockly/reference/js/blockly.blocklyoptions_interface -export const blocklyOptions: BlocklyOptions = { - toolbox, -}; diff --git a/src/blocks/index.ts b/src/blocks/index.ts new file mode 100644 index 0000000..647b498 --- /dev/null +++ b/src/blocks/index.ts @@ -0,0 +1,7 @@ +import {BlocklyOptions} from "libprotolab/blockly"; +import {toolbox} from "./toolbox"; + +// For options, see: https://developers.google.com/blockly/reference/js/blockly.blocklyoptions_interface +export const blocklyOptions: BlocklyOptions = { + toolbox, +}; diff --git a/src/pool-style-blocks.ts b/src/blocks/pool-style-blocks.ts similarity index 100% rename from src/pool-style-blocks.ts rename to src/blocks/pool-style-blocks.ts diff --git a/src/blocks/toolbox.ts b/src/blocks/toolbox.ts new file mode 100644 index 0000000..dd9c172 --- /dev/null +++ b/src/blocks/toolbox.ts @@ -0,0 +1,31 @@ +import { your, custom, blocks, here } from "./blocks"; + +import { ToolboxDefinition } from "libprotolab/blockly"; +import { + includeStockCategories, + StockCategory, +} from "libprotolab/blockly/stockBlocks"; +import { getLabName } from "libprotolab/lab-name"; + +export const toolbox: ToolboxDefinition = { + kind: "categoryToolbox", + contents: [ + { + kind: "category", + name: getLabName(), + categorystyle: "logic_category", + contents: [your, custom, blocks, here], + }, + // You can add/remove specific stock block categories here + // or remove this line to disable all stock blocks + ...includeStockCategories([ + StockCategory.Logic, + StockCategory.Loops, + StockCategory.Math, + StockCategory.Text, + StockCategory.Lists, + StockCategory.Variables, + StockCategory.Functions, + ]), + ], +};