Strict types in input (#3912)

* Strict types in input.js
This commit is contained in:
Sam El-Husseini
2020-05-21 17:57:13 -07:00
committed by GitHub
parent e3babee1f3
commit b84d25fe2d
3 changed files with 28 additions and 7 deletions

View File

@@ -109,19 +109,21 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) {
field.name = opt_name;
field.setVisible(this.isVisible());
if (field.prefixField) {
var fieldDropdown = /** @type {Blockly.FieldDropdown} */ (field);
if (fieldDropdown.prefixField) {
// Add any prefix.
index = this.insertFieldAt(index, field.prefixField);
index = this.insertFieldAt(index, fieldDropdown.prefixField);
}
// Add the field to the field row.
this.fieldRow.splice(index, 0, field);
++index;
if (field.suffixField) {
if (fieldDropdown.suffixField) {
// Add any suffix.
index = this.insertFieldAt(index, field.suffixField);
index = this.insertFieldAt(index, fieldDropdown.suffixField);
}
if (this.sourceBlock_.rendered) {
this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_);
this.sourceBlock_.render();
// Adding a field will cause the block to change shape.
this.sourceBlock_.bumpNeighbours();
@@ -140,6 +142,7 @@ Blockly.Input.prototype.removeField = function(name) {
field.dispose();
this.fieldRow.splice(i, 1);
if (this.sourceBlock_.rendered) {
this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_);
this.sourceBlock_.render();
// Removing a field will cause the block to change shape.
this.sourceBlock_.bumpNeighbours();
@@ -162,7 +165,7 @@ Blockly.Input.prototype.isVisible = function() {
* Sets whether this input is visible or not.
* Should only be used to collapse/uncollapse a block.
* @param {boolean} visible True if visible.
* @return {!Array.<!Blockly.Block>} List of blocks to render.
* @return {!Array.<!Blockly.BlockSvg>} List of blocks to render.
* @package
*/
Blockly.Input.prototype.setVisible = function(visible) {
@@ -179,6 +182,8 @@ Blockly.Input.prototype.setVisible = function(visible) {
field.setVisible(visible);
}
if (this.connection) {
this.connection =
/** @type {!Blockly.RenderedConnection} */ (this.connection);
// Has a connection.
if (visible) {
renderList = this.connection.startTrackingAll();
@@ -226,6 +231,7 @@ Blockly.Input.prototype.setCheck = function(check) {
Blockly.Input.prototype.setAlign = function(align) {
this.align = align;
if (this.sourceBlock_.rendered) {
this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_);
this.sourceBlock_.render();
}
return this;