Skip to content

Commit

Permalink
Refactor blocks into sub-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
snickell committed May 30, 2024
1 parent ac77260 commit 14a4d3f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Lab.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
49 changes: 6 additions & 43 deletions src/blocks.ts → src/blocks/blocks.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -30,7 +24,7 @@ const your = defineBlock(
}
);

const custom = defineBlock(
export const custom = defineBlock(
"custom",
(block, generator) => {
const value = generator.valueToCode(block, "VALUE", 0);
Expand All @@ -51,7 +45,7 @@ const custom = defineBlock(
}
);

const blocks = defineBlock(
export const blocks = defineBlock(
"blocks",
(block, generator) => {
const value = generator.valueToCode(block, "VALUE", 0);
Expand All @@ -72,7 +66,7 @@ const blocks = defineBlock(
}
);

const here = defineBlock(
export const here = defineBlock(
"here",
(block, generator) => {
const value = generator.valueToCode(block, "VALUE", 0);
Expand All @@ -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,
};
7 changes: 7 additions & 0 deletions src/blocks/index.ts
Original file line number Diff line number Diff line change
@@ -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,
};
File renamed without changes.
31 changes: 31 additions & 0 deletions src/blocks/toolbox.ts
Original file line number Diff line number Diff line change
@@ -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,
]),
],
};

0 comments on commit 14a4d3f

Please sign in to comment.