Skip to main content

@blockly/disable-top-blocks

Built with Blockly​

A Blockly plugin that shows the 'disable' context menu option only on non-orphan blocks. This is useful in conjunction with the Blockly.Events.disableOrphans event handler (which you must set up yourself).

Installation​

Yarn​

yarn add @blockly/disable-top-blocks

npm​

npm install @blockly/disable-top-blocks --save

Usage​

import * as Blockly from 'blockly';
import {DisableTopBlocks} from '@blockly/disable-top-blocks';

// Inject Blockly.
const workspace = Blockly.inject('blocklyDiv', {};

// Add the disableOrphans event handler. This is not done automatically by
// the plugin and should be handled by your application.
workspace.addChangeListener(Blockly.Events.disableOrphans);

// The plugin must be initialized before it has any effect.
const disableTopBlocksPlugin = new DisableTopBlocks();
disableTopBlocksPlugin.init();

API​

  • init initializes the plugin and modifies the behavior of the 'disable' context menu item.
  • dispose restores the original behavior of the context menu. This is never required to be called, but can be if you want to programmatically disable the effects of the plugin.

License​

Apache 2.0

A Blockly plugin that shows the 'disable' context menu option only on non-orphan blocks.

Classes​

ClassDescription
DisableTopBlocksThis plugin changes the logic of the enable/disable context menu item. It is enabled for all blocks except top-level blocks that have output or previous connections. In other words, the option is disabled for orphan blocks. Using this plugin allows users to disable valid non-orphan blocks, but not re-enable blocks that have been automatically disabled by disableOrphans.