import React from "react"; import { Block, Value, Field, Shadow, Category } from "../"; import { getColour } from "../helpers/colour"; import "@blockly/block-plus-minus"; import { TypedVariableModal } from "@blockly/plugin-typed-variable-modal"; import * as Blockly from "blockly/core"; class Toolbox extends React.Component { componentDidUpdate() { this.props.workspace.registerToolboxCategoryCallback( "CREATE_TYPED_VARIABLE", this.createFlyout ); const typedVarModal = new TypedVariableModal( this.props.workspace, "callbackName", [ ["SHORT_NUMBER", "char"], ["NUMBER", "int"], ["DECIMAL", "float"], ["TEXT", "String"], ["ARRAY", "Array"], ["CHARACTER", "char"], ["BOOLEAN", "boolean"], ["NULL", "void"], ["UNDEF", "undefined"], ] ); typedVarModal.init(); } createFlyout(workspace) { let xmlList = []; // Add your button and give it a callback name. const button = document.createElement("button"); button.setAttribute("text", "Create Typed Variable"); button.setAttribute("callbackKey", "callbackName"); xmlList.push(button); // This gets all the variables that the user creates and adds them to the // flyout. const blockList = Blockly.VariablesDynamic.flyoutCategoryBlocks(workspace); xmlList = xmlList.concat(blockList); return xmlList; } render() { return ( {/* */} 1 30 0 0 100 50 0 1 0 0 Title Unit Title Unit 0 15 0 50 5 0 15 0 0 0 0 0 0 0 latitude longitude altitude pDOP fixType {/* */} 10 1 10 1 1000 100 1 1 100 1 100 220 100 {/* this block is the initial block of the workspace; not necessary to display, because it can only be used once anyway */} ); } } export default Toolbox;