创建新的输入类型

如需创建自定义输入,您需要创建 Input 的子类或其任一子类。

class MyInput extends Blockly.inputs.Input {

  // The constructor should always take in a name and a block to be compatible
  // with JSON block definitions.
  constructor(name, block) {
    super(name, block);
    // etc...
  }
}

(可选)创建连接

如果您希望输入具有连接,则应通过调用 makeConnection 方法在构造函数中创建连接。

constructor(name, block) {
  super(name, block);

  this.connection = this.makeConnection(ConnectionType.INPUT_VALUE);
}

注册输入

如需在 JSON 块定义中使用自定义输入,您需要注册该输入并将其与字符串相关联。

class MyInput extends Blockly.inputs.Input {}

Blockly.registry.register(Blockly.registry.Type.INPUT, 'my_input', MyInput);