mirror of
https://github.com/google/blockly.git
synced 2026-01-06 08:30:13 +01:00
chore: add validator and field value types (#6603)
* chore: add validator and field value types * chore/clean up unused default and unnecessary field type setting * chore: removed IRegisterableField and updated various Field instances * fix: remove unused field image validator function * chore: added pass-through constructor to field_textinput
This commit is contained in:
committed by
GitHub
parent
0532b5d1c0
commit
79f620647f
@@ -75,7 +75,7 @@ export class Input {
|
||||
* field again. Should be unique to the host block.
|
||||
* @returns The input being append to (to allow chaining).
|
||||
*/
|
||||
appendField(field: string|Field, opt_name?: string): Input {
|
||||
appendField<T>(field: string|Field<T>, opt_name?: string): Input {
|
||||
this.insertFieldAt(this.fieldRow.length, field, opt_name);
|
||||
return this;
|
||||
}
|
||||
@@ -90,7 +90,8 @@ export class Input {
|
||||
* field again. Should be unique to the host block.
|
||||
* @returns The index following the last inserted field.
|
||||
*/
|
||||
insertFieldAt(index: number, field: string|Field, opt_name?: string): number {
|
||||
insertFieldAt<T>(index: number, field: string|Field<T>, opt_name?: string):
|
||||
number {
|
||||
if (index < 0 || index > this.fieldRow.length) {
|
||||
throw Error('index ' + index + ' out of bounds.');
|
||||
}
|
||||
@@ -103,9 +104,9 @@ export class Input {
|
||||
// Generate a FieldLabel when given a plain text field.
|
||||
if (typeof field === 'string') {
|
||||
field = fieldRegistry.fromJson({
|
||||
'type': 'field_label',
|
||||
'text': field,
|
||||
}) as Field;
|
||||
type: 'field_label',
|
||||
text: field,
|
||||
})!;
|
||||
}
|
||||
|
||||
field.setSourceBlock(this.sourceBlock_);
|
||||
@@ -121,7 +122,7 @@ export class Input {
|
||||
index = this.insertFieldAt(index, field.prefixField);
|
||||
}
|
||||
// Add the field to the field row.
|
||||
this.fieldRow.splice(index, 0, field);
|
||||
this.fieldRow.splice(index, 0, field as Field);
|
||||
index++;
|
||||
if (field.suffixField) {
|
||||
// Add any suffix.
|
||||
|
||||
Reference in New Issue
Block a user