使用程序區塊
使用外掛程式
如要使用程序區塊,建議您透過
@blockly/block-shareable-procedures 外掛程式。
如要瞭解外掛程式區塊和內建區塊之間的差異,請參閱
簡介。
安裝
紗線:
shell
yarn add @blockly/block-shareable-procedures
NPM:
shell
npm install @blockly/block-shareable-procedures
用量
import Blockly from 'blockly';
import {blocks, unregisterProcedureBlocks} '@blockly/block-shareable-procedures';
unregisterProcedureBlocks();
Blockly.common.defineBlocks(blocks);
這會定義名稱與舊版資料表相同的程序區塊
內建程序區塊因此,如果您要載入先前儲存的 JSON 或 XML
原本的程序區塊,將繼續正確載入。
定義模塊後 (外掛程式或舊版都可以)
時,必須提供給使用者。這需要
要使用類別樣式工具箱,因為系統已填入程序類別
動態,但尖端工具箱不支援這項功能。
您可以在工具箱中新增動態類別,如下所示:
{
"kind": "categoryToolbox",
"contents": [
{
"kind": "category",
"name": "Functions",
"custom": "PROCEDURE"
}
]
};
<xml id="toolbox" style="display: none">
<category name="Functions" custom="PROCEDURE">
</xml>
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-09-09 (世界標準時間)。
[null,null,["上次更新時間:2024-09-09 (世界標準時間)。"],[[["Leverage the `@blockly/block-shareable-procedures` plugin for utilizing procedure blocks within Blockly, ensuring compatibility and enhanced functionality."],["Install the plugin effortlessly using either Yarn (`yarn add @blockly/block-shareable-procedures`) or NPM (`npm install @blockly/block-shareable-procedures`) based on your preference."],["Integrate the plugin into your project by importing necessary modules, unregistering existing procedure blocks, and defining new ones with shared functionalities, maintaining backward compatibility with older saved files."],["Incorporate the procedure blocks into your toolbox by utilizing a category style toolbox with a dynamic \"Functions\" category, allowing users easy access to these essential blocks."]]],["The `@blockly/block-shareable-procedures` plugin is recommended for using procedure blocks. Installation is done via Yarn or NPM. Usage involves importing `Blockly` and the plugin's `blocks`, then using the `unregisterProcedureBlocks()` and `Blockly.common.defineBlocks(blocks)` methods. This defines procedure blocks that maintain compatibility with legacy blocks. To make the blocks accessible, add a \"Functions\" category with the custom attribute \"PROCEDURE\" to your category-style toolbox, which is compatible with the dynamic procedure category.\n"]]