如要建立自訂輸入內容,您必須將 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);