研究调查问卷:请告诉我们您使用 Blockly 的体验
开始调查问卷
使用过程块
使用插件
要使用过程块,我们建议使用
@blockly/block-shareable-procedures 插件。
如需了解插件块和内置块之间的区别,请参阅
概览。
安装
Yarn:
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);
这将定义与旧版同名的过程块
内置过程块因此,如果您要加载已保存的
旧过程块仍可继续正常加载。
在定义块之后(插件块或旧版块)
内置插件),您需要向用户提供它们。这需要
您要使用类别样式工具箱,因为手术类别是填充的
动态呈现,而浮出工具箱则不支持。
您可以按如下方式向工具箱添加动态类别:
{
"kind": "categoryToolbox",
"contents": [
{
"kind": "category",
"name": "Functions",
"custom": "PROCEDURE"
}
]
};
<xml id="toolbox" style="display: none">
<category name="Functions" custom="PROCEDURE">
</xml>
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-09-09。
[null,null,["最后更新时间 (UTC):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"]]