First pass at creating connectionTypes and inputTYpes

This commit is contained in:
Rachel Fenichel
2021-02-26 14:43:17 -08:00
parent a77f429ba0
commit 750b62030b
30 changed files with 301 additions and 170 deletions

View File

@@ -15,6 +15,7 @@ goog.provide('Blockly.Block');
goog.require('Blockly.ASTNode'); goog.require('Blockly.ASTNode');
goog.require('Blockly.Blocks'); goog.require('Blockly.Blocks');
goog.require('Blockly.Connection'); goog.require('Blockly.Connection');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.Events'); goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Events.BlockChange');
@@ -24,6 +25,7 @@ goog.require('Blockly.Events.BlockMove');
goog.require('Blockly.Extensions'); goog.require('Blockly.Extensions');
goog.require('Blockly.fieldRegistry'); goog.require('Blockly.fieldRegistry');
goog.require('Blockly.Input'); goog.require('Blockly.Input');
goog.require('Blockly.inputTypes');
goog.require('Blockly.Tooltip'); goog.require('Blockly.Tooltip');
goog.require('Blockly.utils'); goog.require('Blockly.utils');
goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.Coordinate');
@@ -499,7 +501,8 @@ Blockly.Block.prototype.getOnlyValueConnection_ = function() {
var connection = null; var connection = null;
for (var i = 0; i < this.inputList.length; i++) { for (var i = 0; i < this.inputList.length; i++) {
var thisConnection = this.inputList[i].connection; var thisConnection = this.inputList[i].connection;
if (thisConnection && thisConnection.type == Blockly.INPUT_VALUE && if (thisConnection &&
thisConnection.type == Blockly.connectionTypes.INPUT_VALUE &&
thisConnection.targetConnection) { thisConnection.targetConnection) {
if (connection) { if (connection) {
return null; // More than one value input found. return null; // More than one value input found.
@@ -660,7 +663,8 @@ Blockly.Block.prototype.getPreviousBlock = function() {
*/ */
Blockly.Block.prototype.getFirstStatementConnection = function() { Blockly.Block.prototype.getFirstStatementConnection = function() {
for (var i = 0, input; (input = this.inputList[i]); i++) { for (var i = 0, input; (input = this.inputList[i]); i++) {
if (input.connection && input.connection.type == Blockly.NEXT_STATEMENT) { if (input.connection &&
input.connection.type == Blockly.connectionTypes.NEXT_STATEMENT) {
return input.connection; return input.connection;
} }
} }
@@ -1140,7 +1144,7 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) {
'connection.'); 'connection.');
} }
this.previousConnection = this.previousConnection =
this.makeConnection_(Blockly.PREVIOUS_STATEMENT); this.makeConnection_(Blockly.connectionTypes.PREVIOUS_STATEMENT);
} }
this.previousConnection.setCheck(opt_check); this.previousConnection.setCheck(opt_check);
} else { } else {
@@ -1167,7 +1171,8 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) {
opt_check = null; opt_check = null;
} }
if (!this.nextConnection) { if (!this.nextConnection) {
this.nextConnection = this.makeConnection_(Blockly.NEXT_STATEMENT); this.nextConnection =
this.makeConnection_(Blockly.connectionTypes.NEXT_STATEMENT);
} }
this.nextConnection.setCheck(opt_check); this.nextConnection.setCheck(opt_check);
} else { } else {
@@ -1199,7 +1204,8 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) {
throw Error('Remove previous connection prior to adding output ' + throw Error('Remove previous connection prior to adding output ' +
'connection.'); 'connection.');
} }
this.outputConnection = this.makeConnection_(Blockly.OUTPUT_VALUE); this.outputConnection =
this.makeConnection_(Blockly.connectionTypes.OUTPUT_VALUE);
} }
this.outputConnection.setCheck(opt_check); this.outputConnection.setCheck(opt_check);
} else { } else {
@@ -1236,15 +1242,15 @@ Blockly.Block.prototype.getInputsInline = function() {
} }
// Not defined explicitly. Figure out what would look best. // Not defined explicitly. Figure out what would look best.
for (var i = 1; i < this.inputList.length; i++) { for (var i = 1; i < this.inputList.length; i++) {
if (this.inputList[i - 1].type == Blockly.DUMMY_INPUT && if (this.inputList[i - 1].type == Blockly.inputTypes.DUMMY &&
this.inputList[i].type == Blockly.DUMMY_INPUT) { this.inputList[i].type == Blockly.inputTypes.DUMMY) {
// Two dummy inputs in a row. Don't inline them. // Two dummy inputs in a row. Don't inline them.
return false; return false;
} }
} }
for (var i = 1; i < this.inputList.length; i++) { for (var i = 1; i < this.inputList.length; i++) {
if (this.inputList[i - 1].type == Blockly.INPUT_VALUE && if (this.inputList[i - 1].type == Blockly.inputTypes.VALUE &&
this.inputList[i].type == Blockly.DUMMY_INPUT) { this.inputList[i].type == Blockly.inputTypes.DUMMY) {
// Dummy input after a value input. Inline them. // Dummy input after a value input. Inline them.
return true; return true;
} }
@@ -1441,7 +1447,7 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) {
* @return {!Blockly.Input} The input object created. * @return {!Blockly.Input} The input object created.
*/ */
Blockly.Block.prototype.appendValueInput = function(name) { Blockly.Block.prototype.appendValueInput = function(name) {
return this.appendInput_(Blockly.INPUT_VALUE, name); return this.appendInput_(Blockly.inputTypes.VALUE, name);
}; };
/** /**
@@ -1451,7 +1457,7 @@ Blockly.Block.prototype.appendValueInput = function(name) {
* @return {!Blockly.Input} The input object created. * @return {!Blockly.Input} The input object created.
*/ */
Blockly.Block.prototype.appendStatementInput = function(name) { Blockly.Block.prototype.appendStatementInput = function(name) {
return this.appendInput_(Blockly.NEXT_STATEMENT, name); return this.appendInput_(Blockly.inputTypes.STATEMENT, name);
}; };
/** /**
@@ -1461,7 +1467,7 @@ Blockly.Block.prototype.appendStatementInput = function(name) {
* @return {!Blockly.Input} The input object created. * @return {!Blockly.Input} The input object created.
*/ */
Blockly.Block.prototype.appendDummyInput = function(opt_name) { Blockly.Block.prototype.appendDummyInput = function(opt_name) {
return this.appendInput_(Blockly.DUMMY_INPUT, opt_name || ''); return this.appendInput_(Blockly.inputTypes.DUMMY, opt_name || '');
}; };
/** /**
@@ -1836,8 +1842,7 @@ Blockly.Block.prototype.stringToFieldJson_ = function(str) {
/** /**
* Add a value input, statement input or local variable to this block. * Add a value input, statement input or local variable to this block.
* @param {number} type Either Blockly.INPUT_VALUE or Blockly.NEXT_STATEMENT or * @param {number} type One of Blockly.inputTypes.
* Blockly.DUMMY_INPUT.
* @param {string} name Language-neutral identifier which may used to find this * @param {string} name Language-neutral identifier which may used to find this
* input again. Should be unique to this block. * input again. Should be unique to this block.
* @return {!Blockly.Input} The input object created. * @return {!Blockly.Input} The input object created.
@@ -1845,10 +1850,11 @@ Blockly.Block.prototype.stringToFieldJson_ = function(str) {
*/ */
Blockly.Block.prototype.appendInput_ = function(type, name) { Blockly.Block.prototype.appendInput_ = function(type, name) {
var connection = null; var connection = null;
if (type == Blockly.INPUT_VALUE || type == Blockly.NEXT_STATEMENT) { if (type == Blockly.inputTypes.VALUE ||
type == Blockly.inputTypes.STATEMENT) {
connection = this.makeConnection_(type); connection = this.makeConnection_(type);
} }
if (type == Blockly.NEXT_STATEMENT) { if (type == Blockly.inputTypes.STATEMENT) {
this.statementInputCount++; this.statementInputCount++;
} }
var input = new Blockly.Input(type, name, this, connection); var input = new Blockly.Input(type, name, this, connection);
@@ -1929,7 +1935,7 @@ Blockly.Block.prototype.moveNumberedInputBefore = function(
Blockly.Block.prototype.removeInput = function(name, opt_quiet) { Blockly.Block.prototype.removeInput = function(name, opt_quiet) {
for (var i = 0, input; (input = this.inputList[i]); i++) { for (var i = 0, input; (input = this.inputList[i]); i++) {
if (input.name == name) { if (input.name == name) {
if (input.type == Blockly.NEXT_STATEMENT) { if (input.type == Blockly.inputTypes.STATEMENT) {
this.statementInputCount--; this.statementInputCount--;
} }
input.dispose(); input.dispose();

View File

@@ -17,6 +17,7 @@ goog.require('Blockly.Block');
goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockAnimations');
goog.require('Blockly.blockRendering.IPathObject'); goog.require('Blockly.blockRendering.IPathObject');
goog.require('Blockly.browserEvents'); goog.require('Blockly.browserEvents');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenu');
goog.require('Blockly.ContextMenuRegistry'); goog.require('Blockly.ContextMenuRegistry');
@@ -159,7 +160,7 @@ Blockly.BlockSvg.prototype.warningTextDb_ = null;
/** /**
* Constant for identifying rows that are to be rendered inline. * Constant for identifying rows that are to be rendered inline.
* Don't collide with Blockly.INPUT_VALUE and friends. * Don't collide with Blockly.inputTypes.
* @const * @const
*/ */
Blockly.BlockSvg.INLINE = -1; Blockly.BlockSvg.INLINE = -1;
@@ -1372,8 +1373,7 @@ Blockly.BlockSvg.prototype.moveNumberedInputBefore = function(
/** /**
* Add a value input, statement input or local variable to this block. * Add a value input, statement input or local variable to this block.
* @param {number} type Either Blockly.INPUT_VALUE or Blockly.NEXT_STATEMENT or * @param {number} type One of Blockly.inputTypes.
* Blockly.DUMMY_INPUT.
* @param {string} name Language-neutral identifier which may used to find this * @param {string} name Language-neutral identifier which may used to find this
* input again. Should be unique to this block. * input again. Should be unique to this block.
* @return {!Blockly.Input} The input object created. * @return {!Blockly.Input} The input object created.
@@ -1587,8 +1587,8 @@ Blockly.BlockSvg.prototype.positionNearConnection = function(sourceConnection,
targetConnection) { targetConnection) {
// We only need to position the new block if it's before the existing one, // We only need to position the new block if it's before the existing one,
// otherwise its position is set by the previous block. // otherwise its position is set by the previous block.
if (sourceConnection.type == Blockly.NEXT_STATEMENT || if (sourceConnection.type == Blockly.connectionTypes.NEXT_STATEMENT ||
sourceConnection.type == Blockly.INPUT_VALUE) { sourceConnection.type == Blockly.connectionTypes.INPUT_VALUE) {
var dx = targetConnection.x - sourceConnection.x; var dx = targetConnection.x - sourceConnection.x;
var dy = targetConnection.y - sourceConnection.y; var dy = targetConnection.y - sourceConnection.y;

View File

@@ -18,6 +18,7 @@ goog.provide('Blockly');
goog.require('Blockly.browserEvents'); goog.require('Blockly.browserEvents');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.Events'); goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.Events.BlockCreate');
goog.require('Blockly.Events.FinishedLoading'); goog.require('Blockly.Events.FinishedLoading');
@@ -25,6 +26,7 @@ goog.require('Blockly.Events.Ui');
goog.require('Blockly.Events.UiBase'); goog.require('Blockly.Events.UiBase');
goog.require('Blockly.Events.VarCreate'); goog.require('Blockly.Events.VarCreate');
goog.require('Blockly.inject'); goog.require('Blockly.inject');
goog.require('Blockly.inputTypes');
goog.require('Blockly.Procedures'); goog.require('Blockly.Procedures');
goog.require('Blockly.ShortcutRegistry'); goog.require('Blockly.ShortcutRegistry');
goog.require('Blockly.Tooltip'); goog.require('Blockly.Tooltip');
@@ -518,3 +520,33 @@ Blockly.ALIGN_CENTRE = Blockly.constants.ALIGN.CENTRE;
* @see Blockly.constants.ALIGN.RIGHT * @see Blockly.constants.ALIGN.RIGHT
*/ */
Blockly.ALIGN_RIGHT = Blockly.constants.ALIGN.RIGHT; Blockly.ALIGN_RIGHT = Blockly.constants.ALIGN.RIGHT;
/**
* Aliases for constants used for connection and input types.
*/
/**
* @see Blockly.connectionTypes.INPUT_VALUE
*/
Blockly.INPUT_VALUE = Blockly.connectionTypes.INPUT_VALUE;
/**
* @see Blockly.connectionTypes.OUTPUT_VALUE
*/
Blockly.OUTPUT_VALUE = Blockly.connectionTypes.OUTPUT_VALUE;
/**
* @see Blockly.connectionTypes.NEXT_STATEMENT
*/
Blockly.NEXT_STATEMENT = Blockly.connectionTypes.NEXT_STATEMENT;
/**
* @see Blockly.connectionTypes.PREVIOUS_STATEMENT
*/
Blockly.PREVIOUS_STATEMENT = Blockly.connectionTypes.PREVIOUS_STATEMENT;
/**
* @see Blockly.inputTypes.DUMMY_INPUT
*/
Blockly.DUMMY_INPUT = Blockly.inputTypes.DUMMY_INPUT;

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.Connection'); goog.provide('Blockly.Connection');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.Events'); goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockMove'); goog.require('Blockly.Events.BlockMove');
@@ -122,7 +123,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
shadowDom = /** @type {!Element} */ (Blockly.Xml.blockToDom(orphanBlock)); shadowDom = /** @type {!Element} */ (Blockly.Xml.blockToDom(orphanBlock));
orphanBlock.dispose(false); orphanBlock.dispose(false);
orphanBlock = null; orphanBlock = null;
} else if (parentConnection.type == Blockly.INPUT_VALUE) { } else if (parentConnection.type == Blockly.connectionTypes.INPUT_VALUE) {
// Value connections. // Value connections.
// If female block is already connected, disconnect and bump the male. // If female block is already connected, disconnect and bump the male.
if (!orphanBlock.outputConnection) { if (!orphanBlock.outputConnection) {
@@ -137,7 +138,8 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
orphanBlock.outputConnection.connect(connection); orphanBlock.outputConnection.connect(connection);
orphanBlock = null; orphanBlock = null;
} }
} else if (parentConnection.type == Blockly.NEXT_STATEMENT) { } else if (
parentConnection.type == Blockly.connectionTypes.NEXT_STATEMENT) {
// Statement connections. // Statement connections.
// Statement blocks may be inserted into the middle of a stack. // Statement blocks may be inserted into the middle of a stack.
// Split the stack. // Split the stack.
@@ -234,8 +236,8 @@ Blockly.Connection.prototype.getSourceBlock = function() {
* @return {boolean} True if connection faces down or right. * @return {boolean} True if connection faces down or right.
*/ */
Blockly.Connection.prototype.isSuperior = function() { Blockly.Connection.prototype.isSuperior = function() {
return this.type == Blockly.INPUT_VALUE || return this.type == Blockly.connectionTypes.INPUT_VALUE ||
this.type == Blockly.NEXT_STATEMENT; this.type == Blockly.connectionTypes.NEXT_STATEMENT;
}; };
/** /**
@@ -382,7 +384,8 @@ Blockly.Connection.singleConnection_ = function(block, orphanBlock) {
for (var i = 0; i < block.inputList.length; i++) { for (var i = 0; i < block.inputList.length; i++) {
var thisConnection = block.inputList[i].connection; var thisConnection = block.inputList[i].connection;
var typeChecker = output.getConnectionChecker(); var typeChecker = output.getConnectionChecker();
if (thisConnection && thisConnection.type == Blockly.INPUT_VALUE && if (thisConnection &&
thisConnection.type == Blockly.connectionTypes.INPUT_VALUE &&
typeChecker.canConnect(output, thisConnection, false)) { typeChecker.canConnect(output, thisConnection, false)) {
if (connection) { if (connection) {
return null; // More than one connection. return null; // More than one connection.

View File

@@ -14,6 +14,7 @@
goog.provide('Blockly.ConnectionChecker'); goog.provide('Blockly.ConnectionChecker');
goog.require('Blockly.Connection'); goog.require('Blockly.Connection');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.IConnectionChecker'); goog.require('Blockly.IConnectionChecker');
goog.require('Blockly.registry'); goog.require('Blockly.registry');
@@ -198,9 +199,9 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
} }
switch (b.type) { switch (b.type) {
case Blockly.PREVIOUS_STATEMENT: case Blockly.connectionTypes.PREVIOUS_STATEMENT:
return this.canConnectToPrevious_(a, b); return this.canConnectToPrevious_(a, b);
case Blockly.OUTPUT_VALUE: { case Blockly.connectionTypes.OUTPUT_VALUE: {
// Don't offer to connect an already connected left (male) value plug to // Don't offer to connect an already connected left (male) value plug to
// an available right (female) value plug. // an available right (female) value plug.
if ((b.isConnected() && if ((b.isConnected() &&
@@ -210,7 +211,7 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
} }
break; break;
} }
case Blockly.INPUT_VALUE: { case Blockly.connectionTypes.INPUT_VALUE: {
// Offering to connect the left (male) of a value block to an already // Offering to connect the left (male) of a value block to an already
// connected value pair is ok, we'll splice it in. // connected value pair is ok, we'll splice it in.
// However, don't offer to splice into an immovable block. // However, don't offer to splice into an immovable block.
@@ -221,7 +222,7 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
} }
break; break;
} }
case Blockly.NEXT_STATEMENT: { case Blockly.connectionTypes.NEXT_STATEMENT: {
// Don't let a block with no next connection bump other blocks out of the // Don't let a block with no next connection bump other blocks out of the
// stack. But covering up a shadow block or stack of shadow blocks is // stack. But covering up a shadow block or stack of shadow blocks is
// fine. Similarly, replacing a terminal statement with another terminal // fine. Similarly, replacing a terminal statement with another terminal

View File

@@ -14,6 +14,7 @@
goog.provide('Blockly.ConnectionDB'); goog.provide('Blockly.ConnectionDB');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.RenderedConnection'); goog.require('Blockly.RenderedConnection');
@@ -289,9 +290,13 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius,
Blockly.ConnectionDB.init = function(checker) { Blockly.ConnectionDB.init = function(checker) {
// Create four databases, one for each connection type. // Create four databases, one for each connection type.
var dbList = []; var dbList = [];
dbList[Blockly.INPUT_VALUE] = new Blockly.ConnectionDB(checker); dbList[Blockly.connectionTypes.INPUT_VALUE] =
dbList[Blockly.OUTPUT_VALUE] = new Blockly.ConnectionDB(checker); new Blockly.ConnectionDB(checker);
dbList[Blockly.NEXT_STATEMENT] = new Blockly.ConnectionDB(checker); dbList[Blockly.connectionTypes.OUTPUT_VALUE] =
dbList[Blockly.PREVIOUS_STATEMENT] = new Blockly.ConnectionDB(checker); new Blockly.ConnectionDB(checker);
dbList[Blockly.connectionTypes.NEXT_STATEMENT] =
new Blockly.ConnectionDB(checker);
dbList[Blockly.connectionTypes.PREVIOUS_STATEMENT] =
new Blockly.ConnectionDB(checker);
return dbList; return dbList;
}; };

29
core/connection_types.js Normal file
View File

@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview An enum for the possible types of connections.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.provide('Blockly.connectionTypes');
/**
* Enum for the type of a connection or input.
* @enum {number}
*/
Blockly.connectionTypes = {
// A right-facing value input. E.g. 'set item to' or 'return'.
INPUT_VALUE: 1,
// A left-facing value output. E.g. 'random fraction'.
OUTPUT_VALUE: 2,
// A down-facing block stack. E.g. 'if-do' or 'else'.
NEXT_STATEMENT: 3,
// An up-facing block stack. E.g. 'break out of loop'.
PREVIOUS_STATEMENT: 4
};

View File

@@ -12,6 +12,9 @@
goog.provide('Blockly.constants'); goog.provide('Blockly.constants');
goog.require('Blockly.connectionTypes');
/** /**
* The multiplier for scroll wheel deltas using the line delta mode. * The multiplier for scroll wheel deltas using the line delta mode.
* @type {number} * @type {number}
@@ -109,35 +112,22 @@ Blockly.SPRITE = {
// Constants below this point are not intended to be changed. // Constants below this point are not intended to be changed.
/** // /**
* ENUM for a right-facing value input. E.g. 'set item to' or 'return'. // * Enum for the type of a connection or input.
* @const // * @enum {number}
*/ // */
Blockly.INPUT_VALUE = 1; // Blockly.constants.CONNECTION_TYPE = {
// // A right-facing value input. E.g. 'set item to' or 'return'.
/** // INPUT_VALUE: 1,
* ENUM for a left-facing value output. E.g. 'random fraction'. // // A left-facing value output. E.g. 'random fraction'.
* @const // OUTPUT_VALUE: 2,
*/ // // A down-facing block stack. E.g. 'if-do' or 'else'.
Blockly.OUTPUT_VALUE = 2; // NEXT_STATEMENT: 3,
// // An up-facing block stack. E.g. 'break out of loop'.
/** // PREVIOUS_STATEMENT: 4,
* ENUM for a down-facing block stack. E.g. 'if-do' or 'else'. // // A dummy input. Used to add field(s) with no input.
* @const // DUMMY_INPUT: 5
*/ // };
Blockly.NEXT_STATEMENT = 3;
/**
* ENUM for an up-facing block stack. E.g. 'break out of loop'.
* @const
*/
Blockly.PREVIOUS_STATEMENT = 4;
/**
* ENUM for an dummy input. Used to add field(s) with no input.
* @const
*/
Blockly.DUMMY_INPUT = 5;
/** /**
* Enum for alignment of inputs. * Enum for alignment of inputs.
@@ -179,10 +169,14 @@ Blockly.DRAG_FREE = 2;
* @const * @const
*/ */
Blockly.OPPOSITE_TYPE = []; Blockly.OPPOSITE_TYPE = [];
Blockly.OPPOSITE_TYPE[Blockly.INPUT_VALUE] = Blockly.OUTPUT_VALUE; Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.INPUT_VALUE] =
Blockly.OPPOSITE_TYPE[Blockly.OUTPUT_VALUE] = Blockly.INPUT_VALUE; Blockly.connectionTypes.OUTPUT_VALUE;
Blockly.OPPOSITE_TYPE[Blockly.NEXT_STATEMENT] = Blockly.PREVIOUS_STATEMENT; Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.OUTPUT_VALUE] =
Blockly.OPPOSITE_TYPE[Blockly.PREVIOUS_STATEMENT] = Blockly.NEXT_STATEMENT; Blockly.connectionTypes.INPUT_VALUE;
Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.NEXT_STATEMENT] =
Blockly.connectionTypes.PREVIOUS_STATEMENT;
Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.PREVIOUS_STATEMENT] =
Blockly.connectionTypes.NEXT_STATEMENT;
/** /**

View File

@@ -18,6 +18,7 @@ goog.provide('Blockly.ContextMenuItems');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.Events'); goog.require('Blockly.Events');
goog.require('Blockly.inputTypes');
goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.BlockSvg');
@@ -65,7 +66,7 @@ Blockly.ContextMenuItems.registerRedo = function() {
}; };
Blockly.ContextMenuRegistry.registry.register(redoOption); Blockly.ContextMenuRegistry.registry.register(redoOption);
}; };
/** Option to clean up blocks. */ /** Option to clean up blocks. */
Blockly.ContextMenuItems.registerCleanup = function() { Blockly.ContextMenuItems.registerCleanup = function() {
/** @type {!Blockly.ContextMenuRegistry.RegistryItem} */ /** @type {!Blockly.ContextMenuRegistry.RegistryItem} */
@@ -91,7 +92,7 @@ Blockly.ContextMenuItems.registerCleanup = function() {
}; };
Blockly.ContextMenuRegistry.registry.register(cleanOption); Blockly.ContextMenuRegistry.registry.register(cleanOption);
}; };
/** /**
* Creates a callback to collapse or expand top blocks. * Creates a callback to collapse or expand top blocks.
* @param {boolean} shouldCollapse Whether a block should collapse. * @param {boolean} shouldCollapse Whether a block should collapse.
@@ -143,7 +144,7 @@ Blockly.ContextMenuItems.registerCollapse = function() {
}; };
Blockly.ContextMenuRegistry.registry.register(collapseOption); Blockly.ContextMenuRegistry.registry.register(collapseOption);
}; };
/** Option to expand all blocks. */ /** Option to expand all blocks. */
Blockly.ContextMenuItems.registerExpand = function() { Blockly.ContextMenuItems.registerExpand = function() {
/** @type {!Blockly.ContextMenuRegistry.RegistryItem} */ /** @type {!Blockly.ContextMenuRegistry.RegistryItem} */
@@ -176,7 +177,7 @@ Blockly.ContextMenuItems.registerExpand = function() {
}; };
Blockly.ContextMenuRegistry.registry.register(expandOption); Blockly.ContextMenuRegistry.registry.register(expandOption);
}; };
/** /**
* Adds a block and its children to a list of deletable blocks. * Adds a block and its children to a list of deletable blocks.
* @param {!Blockly.BlockSvg} block to delete. * @param {!Blockly.BlockSvg} block to delete.
@@ -194,7 +195,7 @@ Blockly.ContextMenuItems.addDeletableBlocks_ = function(block, deleteList) {
} }
} }
}; };
/** /**
* Constructs a list of blocks that can be deleted in the given workspace. * Constructs a list of blocks that can be deleted in the given workspace.
* @param {!Blockly.WorkspaceSvg} workspace to delete all blocks from. * @param {!Blockly.WorkspaceSvg} workspace to delete all blocks from.
@@ -209,7 +210,7 @@ Blockly.ContextMenuItems.getDeletableBlocks_ = function(workspace) {
} }
return deleteList; return deleteList;
}; };
/** Deletes the given blocks. Used to delete all blocks in the workspace. /** Deletes the given blocks. Used to delete all blocks in the workspace.
* @param {!Array.<!Blockly.BlockSvg>} deleteList list of blocks to delete. * @param {!Array.<!Blockly.BlockSvg>} deleteList list of blocks to delete.
* @param {string} eventGroup event group id with which all delete events should be associated. * @param {string} eventGroup event group id with which all delete events should be associated.
@@ -229,7 +230,7 @@ Blockly.ContextMenuItems.deleteNext_ = function(deleteList, eventGroup) {
} }
Blockly.Events.setGroup(false); Blockly.Events.setGroup(false);
}; };
/** Option to delete all blocks. */ /** Option to delete all blocks. */
Blockly.ContextMenuItems.registerDeleteAll = function() { Blockly.ContextMenuItems.registerDeleteAll = function() {
/** @type {!Blockly.ContextMenuRegistry.RegistryItem} */ /** @type {!Blockly.ContextMenuRegistry.RegistryItem} */
@@ -371,8 +372,8 @@ Blockly.ContextMenuItems.registerInline = function() {
if (!block.isInFlyout && block.isMovable() && !block.isCollapsed()) { if (!block.isInFlyout && block.isMovable() && !block.isCollapsed()) {
for (var i = 1; i < block.inputList.length; i++) { for (var i = 1; i < block.inputList.length; i++) {
// Only display this option if there are two value or dummy inputs next to each other. // Only display this option if there are two value or dummy inputs next to each other.
if (block.inputList[i - 1].type != Blockly.NEXT_STATEMENT && if (block.inputList[i - 1].type != Blockly.inputTypes.STATEMENT &&
block.inputList[i].type != Blockly.NEXT_STATEMENT) { block.inputList[i].type != Blockly.inputTypes.STATEMENT) {
return 'enabled'; return 'enabled';
} }
} }
@@ -535,4 +536,4 @@ Blockly.ContextMenuItems.registerDefaultOptions = function() {
Blockly.ContextMenuItems.registerWorkspaceOptions_(); Blockly.ContextMenuItems.registerWorkspaceOptions_();
Blockly.ContextMenuItems.registerBlockOptions_(); Blockly.ContextMenuItems.registerBlockOptions_();
}; };

View File

@@ -22,6 +22,7 @@ goog.provide('Blockly.Events.Move'); // Deprecated.
goog.require('Blockly.Events'); goog.require('Blockly.Events');
goog.require('Blockly.Events.Abstract'); goog.require('Blockly.Events.Abstract');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.registry'); goog.require('Blockly.registry');
goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.object'); goog.require('Blockly.utils.object');
@@ -550,7 +551,8 @@ Blockly.Events.Move.prototype.run = function(forward) {
if (input) { if (input) {
parentConnection = input.connection; parentConnection = input.connection;
} }
} else if (blockConnection.type == Blockly.PREVIOUS_STATEMENT) { } else if (
blockConnection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) {
parentConnection = parentBlock.nextConnection; parentConnection = parentBlock.nextConnection;
} }
if (parentConnection) { if (parentConnection) {

View File

@@ -15,6 +15,7 @@ goog.provide('Blockly.Input');
goog.require('Blockly.Connection'); goog.require('Blockly.Connection');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.fieldRegistry'); goog.require('Blockly.fieldRegistry');
goog.require('Blockly.inputTypes');
goog.requireType('Blockly.Block'); goog.requireType('Blockly.Block');
goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.BlockSvg');
@@ -33,7 +34,7 @@ goog.requireType('Blockly.RenderedConnection');
* @constructor * @constructor
*/ */
Blockly.Input = function(type, name, block, connection) { Blockly.Input = function(type, name, block, connection) {
if (type != Blockly.DUMMY_INPUT && !name) { if (type != Blockly.inputTypes.DUMMY && !name) {
throw Error('Value inputs and statement inputs must have non-empty name.'); throw Error('Value inputs and statement inputs must have non-empty name.');
} }
/** @type {number} */ /** @type {number} */

29
core/input_types.js Normal file
View File

@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview An enum for the possible types of inputs.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.provide('Blockly.inputTypes');
goog.require('Blockly.connectionTypes');
/**
* Enum for the type of a connection or input.
* @enum {number}
*/
Blockly.inputTypes = {
// A right-facing value input. E.g. 'set item to' or 'return'.
VALUE: Blockly.connectionTypes.INPUT_VALUE,
// A down-facing block stack. E.g. 'if-do' or 'else'.
STATEMENT: Blockly.connectionTypes.NEXT_STATEMENT,
// A dummy input. Used to add field(s) with no input.
DUMMY: 5
};

View File

@@ -14,6 +14,7 @@ goog.provide('Blockly.InsertionMarkerManager');
goog.require('Blockly.Block'); goog.require('Blockly.Block');
goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockAnimations');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.Events'); goog.require('Blockly.Events');
@@ -618,7 +619,8 @@ Blockly.InsertionMarkerManager.prototype.hideInsertionMarker_ = function() {
var isFirstInStatementStack = var isFirstInStatementStack =
(imConn == markerNext && !(markerPrev && markerPrev.targetConnection)); (imConn == markerNext && !(markerPrev && markerPrev.targetConnection));
var isFirstInOutputStack = imConn.type == Blockly.INPUT_VALUE && var isFirstInOutputStack =
imConn.type == Blockly.connectionTypes.INPUT_VALUE &&
!(markerOutput && markerOutput.targetConnection); !(markerOutput && markerOutput.targetConnection);
// The insertion marker is the first block in a stack. Unplug won't do // The insertion marker is the first block in a stack. Unplug won't do
// anything in that case. Instead, unplug the following block. // anything in that case. Instead, unplug the following block.
@@ -626,7 +628,9 @@ Blockly.InsertionMarkerManager.prototype.hideInsertionMarker_ = function() {
imConn.targetBlock().unplug(false); imConn.targetBlock().unplug(false);
} }
// Inside of a C-block, first statement connection. // Inside of a C-block, first statement connection.
else if (imConn.type == Blockly.NEXT_STATEMENT && imConn != markerNext) { else if (
imConn.type == Blockly.connectionTypes.NEXT_STATEMENT &&
imConn != markerNext) {
var innerConnection = imConn.targetConnection; var innerConnection = imConn.targetConnection;
innerConnection.getSourceBlock().unplug(false); innerConnection.getSourceBlock().unplug(false);

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.ASTNode'); goog.provide('Blockly.ASTNode');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.Coordinate');
@@ -147,16 +148,17 @@ Blockly.ASTNode.createConnectionNode = function(connection) {
if (!connection) { if (!connection) {
return null; return null;
} }
if (connection.type == Blockly.INPUT_VALUE) { if (connection.type == Blockly.connectionTypes.INPUT_VALUE) {
return Blockly.ASTNode.createInputNode(connection.getParentInput()); return Blockly.ASTNode.createInputNode(connection.getParentInput());
} else if (connection.type == Blockly.NEXT_STATEMENT && } else if (
connection.type == Blockly.connectionTypes.NEXT_STATEMENT &&
connection.getParentInput()) { connection.getParentInput()) {
return Blockly.ASTNode.createInputNode(connection.getParentInput()); return Blockly.ASTNode.createInputNode(connection.getParentInput());
} else if (connection.type == Blockly.NEXT_STATEMENT) { } else if (connection.type == Blockly.connectionTypes.NEXT_STATEMENT) {
return new Blockly.ASTNode(Blockly.ASTNode.types.NEXT, connection); return new Blockly.ASTNode(Blockly.ASTNode.types.NEXT, connection);
} else if (connection.type == Blockly.OUTPUT_VALUE) { } else if (connection.type == Blockly.connectionTypes.OUTPUT_VALUE) {
return new Blockly.ASTNode(Blockly.ASTNode.types.OUTPUT, connection); return new Blockly.ASTNode(Blockly.ASTNode.types.OUTPUT, connection);
} else if (connection.type == Blockly.PREVIOUS_STATEMENT) { } else if (connection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) {
return new Blockly.ASTNode(Blockly.ASTNode.types.PREVIOUS, connection); return new Blockly.ASTNode(Blockly.ASTNode.types.PREVIOUS, connection);
} }
return null; return null;

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.RenderedConnection'); goog.provide('Blockly.RenderedConnection');
goog.require('Blockly.Connection'); goog.require('Blockly.Connection');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.Events'); goog.require('Blockly.Events');
goog.require('Blockly.utils'); goog.require('Blockly.utils');
@@ -288,7 +289,8 @@ Blockly.RenderedConnection.prototype.highlight = function() {
var sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); var sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_);
var renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); var renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants();
var shape = renderConstants.shapeFor(this); var shape = renderConstants.shapeFor(this);
if (this.type == Blockly.INPUT_VALUE || this.type == Blockly.OUTPUT_VALUE) { if (this.type == Blockly.connectionTypes.INPUT_VALUE ||
this.type == Blockly.connectionTypes.OUTPUT_VALUE) {
// Vertical line, puzzle tab, vertical line. // Vertical line, puzzle tab, vertical line.
var yLen = renderConstants.TAB_OFFSET_FROM_TOP; var yLen = renderConstants.TAB_OFFSET_FROM_TOP;
steps = Blockly.utils.svgPaths.moveBy(0, -yLen) + steps = Blockly.utils.svgPaths.moveBy(0, -yLen) +
@@ -393,7 +395,8 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() {
// of lower blocks. Also, since rendering a block renders all its parents, // of lower blocks. Also, since rendering a block renders all its parents,
// we only need to render the leaf nodes. // we only need to render the leaf nodes.
var renderList = []; var renderList = [];
if (this.type != Blockly.INPUT_VALUE && this.type != Blockly.NEXT_STATEMENT) { if (this.type != Blockly.connectionTypes.INPUT_VALUE &&
this.type != Blockly.connectionTypes.NEXT_STATEMENT) {
// Only spider down. // Only spider down.
return renderList; return renderList;
} }
@@ -533,8 +536,8 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
childBlock.updateDisabled(); childBlock.updateDisabled();
} }
if (parentRendered && childRendered) { if (parentRendered && childRendered) {
if (parentConnection.type == Blockly.NEXT_STATEMENT || if (parentConnection.type == Blockly.connectionTypes.NEXT_STATEMENT ||
parentConnection.type == Blockly.PREVIOUS_STATEMENT) { parentConnection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) {
// Child block may need to square off its corners if it is in a stack. // Child block may need to square off its corners if it is in a stack.
// Rendering a child will render its parent. // Rendering a child will render its parent.
childBlock.render(); childBlock.render();

View File

@@ -12,6 +12,7 @@
goog.provide('Blockly.blockRendering.ConstantProvider'); goog.provide('Blockly.blockRendering.ConstantProvider');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.utils'); goog.require('Blockly.utils');
goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.colour');
@@ -995,11 +996,11 @@ Blockly.blockRendering.ConstantProvider.prototype.makeOutsideCorners = function(
Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function( Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function(
connection) { connection) {
switch (connection.type) { switch (connection.type) {
case Blockly.INPUT_VALUE: case Blockly.connectionTypes.INPUT_VALUE:
case Blockly.OUTPUT_VALUE: case Blockly.connectionTypes.OUTPUT_VALUE:
return this.PUZZLE_TAB; return this.PUZZLE_TAB;
case Blockly.PREVIOUS_STATEMENT: case Blockly.connectionTypes.PREVIOUS_STATEMENT:
case Blockly.NEXT_STATEMENT: case Blockly.connectionTypes.NEXT_STATEMENT:
return this.NOTCH; return this.NOTCH;
default: default:
throw Error('Unknown connection type'); throw Error('Unknown connection type');

View File

@@ -20,6 +20,7 @@ goog.require('Blockly.blockRendering.Row');
goog.require('Blockly.blockRendering.SpacerRow'); goog.require('Blockly.blockRendering.SpacerRow');
goog.require('Blockly.blockRendering.TopRow'); goog.require('Blockly.blockRendering.TopRow');
goog.require('Blockly.blockRendering.Types'); goog.require('Blockly.blockRendering.Types');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.Svg'); goog.require('Blockly.utils.Svg');
@@ -229,19 +230,19 @@ Blockly.blockRendering.Debug.prototype.drawConnection = function(conn) {
var colour; var colour;
var size; var size;
var fill; var fill;
if (conn.type == Blockly.INPUT_VALUE) { if (conn.type == Blockly.connectionTypes.INPUT_VALUE) {
size = 4; size = 4;
colour = 'magenta'; colour = 'magenta';
fill = 'none'; fill = 'none';
} else if (conn.type == Blockly.OUTPUT_VALUE) { } else if (conn.type == Blockly.connectionTypes.OUTPUT_VALUE) {
size = 2; size = 2;
colour = 'magenta'; colour = 'magenta';
fill = colour; fill = colour;
} else if (conn.type == Blockly.NEXT_STATEMENT) { } else if (conn.type == Blockly.connectionTypes.NEXT_STATEMENT) {
size = 4; size = 4;
colour = 'goldenrod'; colour = 'goldenrod';
fill = 'none'; fill = 'none';
} else if (conn.type == Blockly.PREVIOUS_STATEMENT) { } else if (conn.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) {
size = 2; size = 2;
colour = 'goldenrod'; colour = 'goldenrod';
fill = colour; fill = colour;

View File

@@ -30,6 +30,7 @@ goog.require('Blockly.blockRendering.StatementInput');
goog.require('Blockly.blockRendering.TopRow'); goog.require('Blockly.blockRendering.TopRow');
goog.require('Blockly.blockRendering.Types'); goog.require('Blockly.blockRendering.Types');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.inputTypes');
goog.requireType('Blockly.blockRendering.ConstantProvider'); goog.requireType('Blockly.blockRendering.ConstantProvider');
goog.requireType('Blockly.blockRendering.Icon'); goog.requireType('Blockly.blockRendering.Icon');
@@ -286,7 +287,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() {
} }
var precedesStatement = this.block_.inputList.length && var precedesStatement = this.block_.inputList.length &&
this.block_.inputList[0].type == Blockly.NEXT_STATEMENT; this.block_.inputList[0].type == Blockly.inputTypes.STATEMENT;
// This is the minimum height for the row. If one of its elements has a // This is the minimum height for the row. If one of its elements has a
// greater height it will be overwritten in the compute pass. // greater height it will be overwritten in the compute pass.
@@ -315,10 +316,9 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() {
Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() {
this.bottomRow.hasNextConnection = !!this.block_.nextConnection; this.bottomRow.hasNextConnection = !!this.block_.nextConnection;
var followsStatement = var followsStatement = this.block_.inputList.length &&
this.block_.inputList.length && this.block_.inputList[this.block_.inputList.length - 1].type ==
this.block_.inputList[this.block_.inputList.length - 1] Blockly.inputTypes.STATEMENT;
.type == Blockly.NEXT_STATEMENT;
// This is the minimum height for the row. If one of its elements has a // This is the minimum height for the row. If one of its elements has a
// greater height it will be overwritten in the compute pass. // greater height it will be overwritten in the compute pass.
@@ -367,19 +367,19 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() {
*/ */
Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRow) { Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRow) {
// Non-dummy inputs have visual representations onscreen. // Non-dummy inputs have visual representations onscreen.
if (this.isInline && input.type == Blockly.INPUT_VALUE) { if (this.isInline && input.type == Blockly.inputTypes.VALUE) {
activeRow.elements.push( activeRow.elements.push(
new Blockly.blockRendering.InlineInput(this.constants_, input)); new Blockly.blockRendering.InlineInput(this.constants_, input));
activeRow.hasInlineInput = true; activeRow.hasInlineInput = true;
} else if (input.type == Blockly.NEXT_STATEMENT) { } else if (input.type == Blockly.inputTypes.STATEMENT) {
activeRow.elements.push( activeRow.elements.push(
new Blockly.blockRendering.StatementInput(this.constants_, input)); new Blockly.blockRendering.StatementInput(this.constants_, input));
activeRow.hasStatement = true; activeRow.hasStatement = true;
} else if (input.type == Blockly.INPUT_VALUE) { } else if (input.type == Blockly.inputTypes.VALUE) {
activeRow.elements.push( activeRow.elements.push(
new Blockly.blockRendering.ExternalValueInput(this.constants_, input)); new Blockly.blockRendering.ExternalValueInput(this.constants_, input));
activeRow.hasExternalInput = true; activeRow.hasExternalInput = true;
} else if (input.type == Blockly.DUMMY_INPUT) { } else if (input.type == Blockly.inputTypes.DUMMY) {
// Dummy inputs have no visual representation, but the information is still // Dummy inputs have no visual representation, but the information is still
// important. // important.
activeRow.minHeight = Math.max(activeRow.minHeight, activeRow.minHeight = Math.max(activeRow.minHeight,
@@ -407,12 +407,13 @@ Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input,
return false; return false;
} }
// A statement input or an input following one always gets a new row. // A statement input or an input following one always gets a new row.
if (input.type == Blockly.NEXT_STATEMENT || if (input.type == Blockly.inputTypes.STATEMENT ||
lastInput.type == Blockly.NEXT_STATEMENT) { lastInput.type == Blockly.inputTypes.STATEMENT) {
return true; return true;
} }
// Value and dummy inputs get new row if inputs are not inlined. // Value and dummy inputs get new row if inputs are not inlined.
if (input.type == Blockly.INPUT_VALUE || input.type == Blockly.DUMMY_INPUT) { if (input.type == Blockly.inputTypes.VALUE ||
input.type == Blockly.inputTypes.DUMMY) {
return !this.isInline; return !this.isInline;
} }
return false; return false;

View File

@@ -14,6 +14,7 @@
goog.provide('Blockly.blockRendering.MarkerSvg'); goog.provide('Blockly.blockRendering.MarkerSvg');
goog.require('Blockly.ASTNode'); goog.require('Blockly.ASTNode');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.Events'); goog.require('Blockly.Events');
goog.require('Blockly.Events.MarkerMove'); goog.require('Blockly.Events.MarkerMove');
@@ -210,9 +211,10 @@ Blockly.blockRendering.MarkerSvg.prototype.showAtLocation_ = function(curNode) {
this.showWithBlock_(curNode); this.showWithBlock_(curNode);
} else if (curNode.getType() == Blockly.ASTNode.types.OUTPUT) { } else if (curNode.getType() == Blockly.ASTNode.types.OUTPUT) {
this.showWithOutput_(curNode); this.showWithOutput_(curNode);
} else if (curNodeAsConnection.type == Blockly.INPUT_VALUE) { } else if (curNodeAsConnection.type == Blockly.connectionTypes.INPUT_VALUE) {
this.showWithInput_(curNode); this.showWithInput_(curNode);
} else if (curNodeAsConnection.type == Blockly.NEXT_STATEMENT) { } else if (
curNodeAsConnection.type == Blockly.connectionTypes.NEXT_STATEMENT) {
this.showWithNext_(curNode); this.showWithNext_(curNode);
} else if (curNode.getType() == Blockly.ASTNode.types.PREVIOUS) { } else if (curNode.getType() == Blockly.ASTNode.types.PREVIOUS) {
this.showWithPrevious_(curNode); this.showWithPrevious_(curNode);

View File

@@ -19,6 +19,7 @@ goog.require('Blockly.blockRendering.IPathObject');
goog.require('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.blockRendering.MarkerSvg');
goog.require('Blockly.blockRendering.PathObject'); goog.require('Blockly.blockRendering.PathObject');
goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.RenderInfo');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.InsertionMarkerManager');
goog.require('Blockly.IRegistrable'); goog.require('Blockly.IRegistrable');
@@ -246,7 +247,9 @@ Blockly.blockRendering.Renderer.prototype.orphanCanConnectAtEnd =
function(topBlock, orphanBlock, localType) { function(topBlock, orphanBlock, localType) {
var orphanConnection = null; var orphanConnection = null;
var lastConnection = null; var lastConnection = null;
if (localType == Blockly.OUTPUT_VALUE) { // We are replacing an output. if (localType ==
Blockly.connectionTypes
.OUTPUT_VALUE) { // We are replacing an output.
orphanConnection = orphanBlock.outputConnection; orphanConnection = orphanBlock.outputConnection;
// TODO: I don't think this function necessarily has the correct logic, // TODO: I don't think this function necessarily has the correct logic,
// but for now it is being kept for behavioral backwards-compat. // but for now it is being kept for behavioral backwards-compat.
@@ -278,22 +281,22 @@ Blockly.blockRendering.Renderer.prototype.orphanCanConnectAtEnd =
* to display. * to display.
* @package * @package
*/ */
Blockly.blockRendering.Renderer.prototype.getConnectionPreviewMethod = Blockly.blockRendering.Renderer.prototype.getConnectionPreviewMethod = function(
function(closest, local, topBlock) { closest, local, topBlock) {
if (local.type == Blockly.OUTPUT_VALUE || if (local.type == Blockly.connectionTypes.OUTPUT_VALUE ||
local.type == Blockly.PREVIOUS_STATEMENT) { local.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) {
if (!closest.isConnected() || if (!closest.isConnected() ||
this.orphanCanConnectAtEnd( this.orphanCanConnectAtEnd(
topBlock, topBlock,
/** @type {!Blockly.BlockSvg} */ (closest.targetBlock()), /** @type {!Blockly.BlockSvg} */ (closest.targetBlock()),
local.type)) { local.type)) {
return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER;
}
return Blockly.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE;
}
return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER; return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER;
}; }
return Blockly.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE;
}
return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER;
};
/** /**
* Render the block. * Render the block.

View File

@@ -33,6 +33,7 @@ goog.require('Blockly.blockRendering.Types');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.geras.InlineInput'); goog.require('Blockly.geras.InlineInput');
goog.require('Blockly.geras.StatementInput'); goog.require('Blockly.geras.StatementInput');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.object'); goog.require('Blockly.utils.object');
goog.requireType('Blockly.blockRendering.Field'); goog.requireType('Blockly.blockRendering.Field');
@@ -74,10 +75,9 @@ Blockly.geras.RenderInfo.prototype.getRenderer = function() {
Blockly.geras.RenderInfo.prototype.populateBottomRow_ = function() { Blockly.geras.RenderInfo.prototype.populateBottomRow_ = function() {
Blockly.geras.RenderInfo.superClass_.populateBottomRow_.call(this); Blockly.geras.RenderInfo.superClass_.populateBottomRow_.call(this);
var followsStatement = var followsStatement = this.block_.inputList.length &&
this.block_.inputList.length && this.block_.inputList[this.block_.inputList.length - 1].type ==
this.block_.inputList[this.block_.inputList.length - 1] Blockly.inputTypes.STATEMENT;
.type == Blockly.NEXT_STATEMENT;
// The minimum height of the bottom row is smaller in Geras than in other // The minimum height of the bottom row is smaller in Geras than in other
// renderers, because the dark path adds a pixel. // renderers, because the dark path adds a pixel.
@@ -95,19 +95,19 @@ Blockly.geras.RenderInfo.prototype.populateBottomRow_ = function() {
*/ */
Blockly.geras.RenderInfo.prototype.addInput_ = function(input, activeRow) { Blockly.geras.RenderInfo.prototype.addInput_ = function(input, activeRow) {
// Non-dummy inputs have visual representations onscreen. // Non-dummy inputs have visual representations onscreen.
if (this.isInline && input.type == Blockly.INPUT_VALUE) { if (this.isInline && input.type == Blockly.inputTypes.VALUE) {
activeRow.elements.push( activeRow.elements.push(
new Blockly.geras.InlineInput(this.constants_, input)); new Blockly.geras.InlineInput(this.constants_, input));
activeRow.hasInlineInput = true; activeRow.hasInlineInput = true;
} else if (input.type == Blockly.NEXT_STATEMENT) { } else if (input.type == Blockly.inputTypes.STATEMENT) {
activeRow.elements.push( activeRow.elements.push(
new Blockly.geras.StatementInput(this.constants_, input)); new Blockly.geras.StatementInput(this.constants_, input));
activeRow.hasStatement = true; activeRow.hasStatement = true;
} else if (input.type == Blockly.INPUT_VALUE) { } else if (input.type == Blockly.inputTypes.VALUE) {
activeRow.elements.push( activeRow.elements.push(
new Blockly.blockRendering.ExternalValueInput(this.constants_, input)); new Blockly.blockRendering.ExternalValueInput(this.constants_, input));
activeRow.hasExternalInput = true; activeRow.hasExternalInput = true;
} else if (input.type == Blockly.DUMMY_INPUT) { } else if (input.type == Blockly.inputTypes.DUMMY) {
// Dummy inputs have no visual representation, but the information is still // Dummy inputs have no visual representation, but the information is still
// important. // important.
activeRow.minHeight = Math.max(activeRow.minHeight, activeRow.minHeight = Math.max(activeRow.minHeight,

View File

@@ -14,6 +14,7 @@
goog.provide('Blockly.zelos.ConstantProvider'); goog.provide('Blockly.zelos.ConstantProvider');
goog.require('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.blockRendering.ConstantProvider');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.colour');
goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.dom');
@@ -650,8 +651,8 @@ Blockly.zelos.ConstantProvider.prototype.shapeFor = function(
checks = connection.targetConnection.getCheck(); checks = connection.targetConnection.getCheck();
} }
switch (connection.type) { switch (connection.type) {
case Blockly.INPUT_VALUE: case Blockly.connectionTypes.INPUT_VALUE:
case Blockly.OUTPUT_VALUE: case Blockly.connectionTypes.OUTPUT_VALUE:
var outputShape = connection.getSourceBlock().getOutputShape(); var outputShape = connection.getSourceBlock().getOutputShape();
// If the block has an output shape set, use that instead. // If the block has an output shape set, use that instead.
if (outputShape != null) { if (outputShape != null) {
@@ -672,8 +673,8 @@ Blockly.zelos.ConstantProvider.prototype.shapeFor = function(
return this.ROUNDED; return this.ROUNDED;
} }
return this.ROUNDED; return this.ROUNDED;
case Blockly.PREVIOUS_STATEMENT: case Blockly.connectionTypes.PREVIOUS_STATEMENT:
case Blockly.NEXT_STATEMENT: case Blockly.connectionTypes.NEXT_STATEMENT:
return this.NOTCH; return this.NOTCH;
default: default:
throw Error('Unknown type'); throw Error('Unknown type');

View File

@@ -34,6 +34,7 @@ goog.require('Blockly.constants');
goog.require('Blockly.FieldImage'); goog.require('Blockly.FieldImage');
goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldLabel');
goog.require('Blockly.FieldTextInput'); goog.require('Blockly.FieldTextInput');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.object'); goog.require('Blockly.utils.object');
goog.require('Blockly.zelos.BottomRow'); goog.require('Blockly.zelos.BottomRow');
goog.require('Blockly.zelos.RightConnectionShape'); goog.require('Blockly.zelos.RightConnectionShape');
@@ -137,12 +138,13 @@ Blockly.zelos.RenderInfo.prototype.shouldStartNewRow_ = function(input,
return false; return false;
} }
// A statement input or an input following one always gets a new row. // A statement input or an input following one always gets a new row.
if (input.type == Blockly.NEXT_STATEMENT || if (input.type == Blockly.inputTypes.STATEMENT ||
lastInput.type == Blockly.NEXT_STATEMENT) { lastInput.type == Blockly.inputTypes.STATEMENT) {
return true; return true;
} }
// Value and dummy inputs get new row if inputs are not inlined. // Value and dummy inputs get new row if inputs are not inlined.
if (input.type == Blockly.INPUT_VALUE || input.type == Blockly.DUMMY_INPUT) { if (input.type == Blockly.inputTypes.VALUE ||
input.type == Blockly.inputTypes.DUMMY) {
return !this.isInline || this.isMultiRow; return !this.isInline || this.isMultiRow;
} }
return false; return false;
@@ -276,7 +278,7 @@ Blockly.zelos.RenderInfo.prototype.addInput_ = function(input, activeRow) {
// If we have two dummy inputs on the same row, one aligned left and the other // If we have two dummy inputs on the same row, one aligned left and the other
// right, keep track of the right aligned dummy input so we can add padding // right, keep track of the right aligned dummy input so we can add padding
// later. // later.
if (input.type == Blockly.DUMMY_INPUT && activeRow.hasDummyInput && if (input.type == Blockly.inputTypes.DUMMY && activeRow.hasDummyInput &&
activeRow.align == Blockly.constants.ALIGN.LEFT && activeRow.align == Blockly.constants.ALIGN.LEFT &&
input.align == Blockly.constants.ALIGN.RIGHT) { input.align == Blockly.constants.ALIGN.RIGHT) {
activeRow.rightAlignedDummyInput = input; activeRow.rightAlignedDummyInput = input;

View File

@@ -14,6 +14,7 @@ goog.provide('Blockly.zelos.Renderer');
goog.require('Blockly.blockRendering'); goog.require('Blockly.blockRendering');
goog.require('Blockly.blockRendering.Renderer'); goog.require('Blockly.blockRendering.Renderer');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.InsertionMarkerManager');
goog.require('Blockly.utils.object'); goog.require('Blockly.utils.object');
@@ -111,28 +112,29 @@ Blockly.zelos.Renderer.prototype.makePathObject = function(root, style) {
* @override * @override
*/ */
Blockly.zelos.Renderer.prototype.shouldHighlightConnection = function(conn) { Blockly.zelos.Renderer.prototype.shouldHighlightConnection = function(conn) {
return conn.type != Blockly.INPUT_VALUE && conn.type !== Blockly.OUTPUT_VALUE; return conn.type != Blockly.connectionTypes.INPUT_VALUE &&
conn.type !== Blockly.connectionTypes.OUTPUT_VALUE;
}; };
/** /**
* @override * @override
*/ */
Blockly.zelos.Renderer.prototype.getConnectionPreviewMethod = Blockly.zelos.Renderer.prototype.getConnectionPreviewMethod = function(
function(closest, local, topBlock) { closest, local, topBlock) {
if (local.type == Blockly.OUTPUT_VALUE) { if (local.type == Blockly.connectionTypes.OUTPUT_VALUE) {
if (!closest.isConnected()) { if (!closest.isConnected()) {
return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE; return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE;
} }
// TODO: Returning this is a total hack, because we don't want to show // TODO: Returning this is a total hack, because we don't want to show
// a replacement fade, we want to show an outline affect. // a replacement fade, we want to show an outline affect.
// Sadly zelos does not support showing an outline around filled // Sadly zelos does not support showing an outline around filled
// inputs, so we have to pretend like the connected block is getting // inputs, so we have to pretend like the connected block is getting
// replaced. // replaced.
return Blockly.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE; return Blockly.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE;
} }
return Blockly.zelos.Renderer.superClass_ return Blockly.zelos.Renderer.superClass_.getConnectionPreviewMethod(
.getConnectionPreviewMethod(closest, local, topBlock); closest, local, topBlock);
}; };
Blockly.blockRendering.register('zelos', Blockly.zelos.Renderer); Blockly.blockRendering.register('zelos', Blockly.zelos.Renderer);

View File

@@ -18,6 +18,7 @@ goog.provide('Blockly.Xml');
goog.require('Blockly.constants'); goog.require('Blockly.constants');
goog.require('Blockly.Events'); goog.require('Blockly.Events');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils'); goog.require('Blockly.utils');
goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.global'); goog.require('Blockly.utils.global');
@@ -201,13 +202,13 @@ Blockly.Xml.blockToDom = function(block, opt_noId) {
for (var i = 0, input; (input = block.inputList[i]); i++) { for (var i = 0, input; (input = block.inputList[i]); i++) {
var container; var container;
var empty = true; var empty = true;
if (input.type == Blockly.DUMMY_INPUT) { if (input.type == Blockly.inputTypes.DUMMY) {
continue; continue;
} else { } else {
var childBlock = input.connection.targetBlock(); var childBlock = input.connection.targetBlock();
if (input.type == Blockly.INPUT_VALUE) { if (input.type == Blockly.inputTypes.VALUE) {
container = Blockly.utils.xml.createElement('value'); container = Blockly.utils.xml.createElement('value');
} else if (input.type == Blockly.NEXT_STATEMENT) { } else if (input.type == Blockly.inputTypes.STATEMENT) {
container = Blockly.utils.xml.createElement('statement'); container = Blockly.utils.xml.createElement('statement');
} }
var shadow = input.connection.getShadowDom(); var shadow = input.connection.getShadowDom();

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.Dart'); goog.provide('Blockly.Dart');
goog.require('Blockly.Generator'); goog.require('Blockly.Generator');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.string'); goog.require('Blockly.utils.string');
@@ -219,7 +220,7 @@ Blockly.Dart.scrub_ = function(block, code, opt_thisOnly) {
// Collect comments for all value arguments. // Collect comments for all value arguments.
// Don't collect comments for nested statements. // Don't collect comments for nested statements.
for (var i = 0; i < block.inputList.length; i++) { for (var i = 0; i < block.inputList.length; i++) {
if (block.inputList[i].type == Blockly.INPUT_VALUE) { if (block.inputList[i].type == Blockly.inputTypes.VALUE) {
var childBlock = block.inputList[i].connection.targetBlock(); var childBlock = block.inputList[i].connection.targetBlock();
if (childBlock) { if (childBlock) {
comment = Blockly.Dart.allNestedComments(childBlock); comment = Blockly.Dart.allNestedComments(childBlock);

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.JavaScript'); goog.provide('Blockly.JavaScript');
goog.require('Blockly.Generator'); goog.require('Blockly.Generator');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.global'); goog.require('Blockly.utils.global');
goog.require('Blockly.utils.string'); goog.require('Blockly.utils.string');
@@ -244,7 +245,7 @@ Blockly.JavaScript.scrub_ = function(block, code, opt_thisOnly) {
// Collect comments for all value arguments. // Collect comments for all value arguments.
// Don't collect comments for nested statements. // Don't collect comments for nested statements.
for (var i = 0; i < block.inputList.length; i++) { for (var i = 0; i < block.inputList.length; i++) {
if (block.inputList[i].type == Blockly.INPUT_VALUE) { if (block.inputList[i].type == Blockly.inputTypes.VALUE) {
var childBlock = block.inputList[i].connection.targetBlock(); var childBlock = block.inputList[i].connection.targetBlock();
if (childBlock) { if (childBlock) {
comment = Blockly.JavaScript.allNestedComments(childBlock); comment = Blockly.JavaScript.allNestedComments(childBlock);

View File

@@ -14,6 +14,7 @@
goog.provide('Blockly.Lua'); goog.provide('Blockly.Lua');
goog.require('Blockly.Generator'); goog.require('Blockly.Generator');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.string'); goog.require('Blockly.utils.string');
@@ -188,7 +189,7 @@ Blockly.Lua.scrub_ = function(block, code, opt_thisOnly) {
// Collect comments for all value arguments. // Collect comments for all value arguments.
// Don't collect comments for nested statements. // Don't collect comments for nested statements.
for (var i = 0; i < block.inputList.length; i++) { for (var i = 0; i < block.inputList.length; i++) {
if (block.inputList[i].type == Blockly.INPUT_VALUE) { if (block.inputList[i].type == Blockly.inputTypes.VALUE) {
var childBlock = block.inputList[i].connection.targetBlock(); var childBlock = block.inputList[i].connection.targetBlock();
if (childBlock) { if (childBlock) {
comment = Blockly.Lua.allNestedComments(childBlock); comment = Blockly.Lua.allNestedComments(childBlock);

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.PHP'); goog.provide('Blockly.PHP');
goog.require('Blockly.Generator'); goog.require('Blockly.Generator');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.string'); goog.require('Blockly.utils.string');
@@ -244,7 +245,7 @@ Blockly.PHP.scrub_ = function(block, code, opt_thisOnly) {
// Collect comments for all value arguments. // Collect comments for all value arguments.
// Don't collect comments for nested statements. // Don't collect comments for nested statements.
for (var i = 0; i < block.inputList.length; i++) { for (var i = 0; i < block.inputList.length; i++) {
if (block.inputList[i].type == Blockly.INPUT_VALUE) { if (block.inputList[i].type == Blockly.inputTypes.VALUE) {
var childBlock = block.inputList[i].connection.targetBlock(); var childBlock = block.inputList[i].connection.targetBlock();
if (childBlock) { if (childBlock) {
comment = Blockly.PHP.allNestedComments(childBlock); comment = Blockly.PHP.allNestedComments(childBlock);

View File

@@ -13,6 +13,7 @@
goog.provide('Blockly.Python'); goog.provide('Blockly.Python');
goog.require('Blockly.Generator'); goog.require('Blockly.Generator');
goog.require('Blockly.inputTypes');
goog.require('Blockly.utils.string'); goog.require('Blockly.utils.string');
@@ -271,7 +272,7 @@ Blockly.Python.scrub_ = function(block, code, opt_thisOnly) {
// Collect comments for all value arguments. // Collect comments for all value arguments.
// Don't collect comments for nested statements. // Don't collect comments for nested statements.
for (var i = 0; i < block.inputList.length; i++) { for (var i = 0; i < block.inputList.length; i++) {
if (block.inputList[i].type == Blockly.INPUT_VALUE) { if (block.inputList[i].type == Blockly.inputTypes.VALUE) {
var childBlock = block.inputList[i].connection.targetBlock(); var childBlock = block.inputList[i].connection.targetBlock();
if (childBlock) { if (childBlock) {
comment = Blockly.Python.allNestedComments(childBlock); comment = Blockly.Python.allNestedComments(childBlock);