調査アンケート: Blockly のご利用体験についてお聞かせください
アンケートを開始
既存のフィールドを拡張する
既存のフィールドを拡張するには、組み込みフィールド(例:
FieldTextInput
、FieldColour
など)を作成し、必要に応じて一部を変更します。
変更可能なフィールドは次のとおりです。
新しいコンバージョン アクションを
カスタム フィールド
組み込みフィールドからの動作が不要な場合は、Field
をサブクラス化する必要があります。
一般的な拡張機能
ほとんどのカスタム フィールドは、次の 3 つのタイプのいずれかを拡張します。
- テキスト入力: ユーザーがフィールドに入力できるようにするには、
FieldTextInput
。
- 数値: 数値を保存する場合は、
FieldNumber
を拡張する必要があります。
- プルダウン: プルダウンを作成するものの、別のモデルを格納する場合
デフォルトの文字列または画像モデルよりも高い場合は、
FieldDropdown
を拡張する必要があります。
- 注意:
FieldDropdown
を拡張する前に、プルダウン フィールドの
カスタマイズ オプションではニーズを満たすことができません。
状況によっては、別のフィールド タイプを拡張することが必要な場合があります。対象
例 FieldLabelSerializable
は FieldLabel
を拡張します。
Subclassing
import * as Blockly from 'blockly';
export class MyCustomTextField extends Blockly.FieldTextInput {
constructor(value, validator, config) {
super(value, validator, config);
}
}
フィールドのサブクラスのコンストラクタは、
カスタムフィールドを作成するサブコンストラクタの署名は、
通常はスーパーコンストラクタのシグネチャと一致します。
JSON と登録
また、フィールドは 1 回登録する必要があります。
Blockly.fieldRegistry.register('my_custom_text_field', MyCustomTextField);
クラスで fromJson
の実装を提供し、
JSON 形式:
static fromJson(options) {
const value = Blockly.utils.parsing.replaceMessageReferences(options.value);
return new MySubclassName(value);
}
フィールドの登録の詳細については、JSON と登録をご覧ください。
セクションをご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-09-08 UTC。
[null,null,["最終更新日 2024-09-08 UTC。"],[[["To extend an existing Blockly field, subclass a built-in field like `FieldTextInput` or `FieldColour` and modify its editor, on-block display, or displayed text."],["For custom fields with unique behaviors, subclass the base `Field` class instead of extending an existing field."],["Common field extensions involve customizing text input (`FieldTextInput`), numbers (`FieldNumber`), or dropdowns (`FieldDropdown`) to meet specific needs."],["When subclassing, ensure your constructor matches the super-constructor's signature and register the field with `Blockly.fieldRegistry.register`."],["Implement the `fromJson` method in your custom field class to enable compatibility with the Blockly JSON format for serialization and deserialization."]]],["To extend an existing field, subclass a built-in field like `FieldTextInput` or `FieldColour`, modifying its editor, on-block display, or text. For unique fields, subclass `Field`. Common extensions include `FieldTextInput`, `FieldNumber`, and `FieldDropdown`. Subclass constructors should mirror the super-constructor's signature. Register the field using `Blockly.fieldRegistry.register()` and implement `fromJson` for JSON compatibility. Extending different fields such as `FieldLabelSerializable` is also possible.\n"]]