新增工具箱

工具箱包含您用來編寫程式的區塊。封鎖條件可以是 拖曳到工作區

如需進一步瞭解工具箱的外觀,請參閱視覺元素 詞彙解釋

基本定義

工具箱定義可指定工具箱包含哪些區塊,以及 順序。工具箱的大部分外觀和樣式是透過其他方式指定 管理基礎架構

建議您使用 JSON 定義工具箱。

這個程式碼片段定義了包含兩個區塊的彈出式工具箱:

const toolbox = {
  // There are two kinds of toolboxes. The simpler one is a flyout toolbox.
  kind: 'flyoutToolbox',
  // The contents is the blocks and other items that exist in your toolbox.
  contents: [
    {
      kind: 'block',
      type: 'controls_if'
    },
    {
      kind: 'block',
      type: 'controls_whileUntil'
    }
    // You can add more blocks to this array.
  ]
};

// The toolbox gets passed to the configuration struct during injection.
const workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});

如要進一步瞭解如何定義和設定工具箱,請參閱 工具箱總覽

如要進一步瞭解插入,請參閱 建立工作區