From 750b62030b0b8d5d83bfa6f9aa7955105e2f1536 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 26 Feb 2021 14:43:17 -0800 Subject: [PATCH] First pass at creating connectionTypes and inputTYpes --- core/block.js | 40 +++++++++++-------- core/block_svg.js | 10 ++--- core/blockly.js | 32 +++++++++++++++ core/connection.js | 13 ++++--- core/connection_checker.js | 9 +++-- core/connection_db.js | 13 +++++-- core/connection_types.js | 29 ++++++++++++++ core/constants.js | 60 +++++++++++++---------------- core/contextmenu_items.js | 21 +++++----- core/events/block_events.js | 4 +- core/input.js | 3 +- core/input_types.js | 29 ++++++++++++++ core/insertion_marker_manager.js | 8 +++- core/keyboard_nav/ast_node.js | 12 +++--- core/rendered_connection.js | 11 ++++-- core/renderers/common/constants.js | 9 +++-- core/renderers/common/debugger.js | 9 +++-- core/renderers/common/info.js | 25 ++++++------ core/renderers/common/marker_svg.js | 6 ++- core/renderers/common/renderer.js | 35 +++++++++-------- core/renderers/geras/info.js | 16 ++++---- core/renderers/zelos/constants.js | 9 +++-- core/renderers/zelos/info.js | 10 +++-- core/renderers/zelos/renderer.js | 36 +++++++++-------- core/xml.js | 7 ++-- generators/dart.js | 3 +- generators/javascript.js | 3 +- generators/lua.js | 3 +- generators/php.js | 3 +- generators/python.js | 3 +- 30 files changed, 301 insertions(+), 170 deletions(-) create mode 100644 core/connection_types.js create mode 100644 core/input_types.js diff --git a/core/block.js b/core/block.js index 368e29dc5..e09bde0e5 100644 --- a/core/block.js +++ b/core/block.js @@ -15,6 +15,7 @@ goog.provide('Blockly.Block'); goog.require('Blockly.ASTNode'); goog.require('Blockly.Blocks'); goog.require('Blockly.Connection'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockChange'); @@ -24,6 +25,7 @@ goog.require('Blockly.Events.BlockMove'); goog.require('Blockly.Extensions'); goog.require('Blockly.fieldRegistry'); goog.require('Blockly.Input'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.Tooltip'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); @@ -499,7 +501,8 @@ Blockly.Block.prototype.getOnlyValueConnection_ = function() { var connection = null; for (var i = 0; i < this.inputList.length; i++) { var thisConnection = this.inputList[i].connection; - if (thisConnection && thisConnection.type == Blockly.INPUT_VALUE && + if (thisConnection && + thisConnection.type == Blockly.connectionTypes.INPUT_VALUE && thisConnection.targetConnection) { if (connection) { return null; // More than one value input found. @@ -660,7 +663,8 @@ Blockly.Block.prototype.getPreviousBlock = function() { */ Blockly.Block.prototype.getFirstStatementConnection = function() { 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; } } @@ -1140,7 +1144,7 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) { 'connection.'); } this.previousConnection = - this.makeConnection_(Blockly.PREVIOUS_STATEMENT); + this.makeConnection_(Blockly.connectionTypes.PREVIOUS_STATEMENT); } this.previousConnection.setCheck(opt_check); } else { @@ -1167,7 +1171,8 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) { opt_check = null; } if (!this.nextConnection) { - this.nextConnection = this.makeConnection_(Blockly.NEXT_STATEMENT); + this.nextConnection = + this.makeConnection_(Blockly.connectionTypes.NEXT_STATEMENT); } this.nextConnection.setCheck(opt_check); } else { @@ -1199,7 +1204,8 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) { throw Error('Remove previous connection prior to adding output ' + 'connection.'); } - this.outputConnection = this.makeConnection_(Blockly.OUTPUT_VALUE); + this.outputConnection = + this.makeConnection_(Blockly.connectionTypes.OUTPUT_VALUE); } this.outputConnection.setCheck(opt_check); } else { @@ -1236,15 +1242,15 @@ Blockly.Block.prototype.getInputsInline = function() { } // Not defined explicitly. Figure out what would look best. for (var i = 1; i < this.inputList.length; i++) { - if (this.inputList[i - 1].type == Blockly.DUMMY_INPUT && - this.inputList[i].type == Blockly.DUMMY_INPUT) { + if (this.inputList[i - 1].type == Blockly.inputTypes.DUMMY && + this.inputList[i].type == Blockly.inputTypes.DUMMY) { // Two dummy inputs in a row. Don't inline them. return false; } } for (var i = 1; i < this.inputList.length; i++) { - if (this.inputList[i - 1].type == Blockly.INPUT_VALUE && - this.inputList[i].type == Blockly.DUMMY_INPUT) { + if (this.inputList[i - 1].type == Blockly.inputTypes.VALUE && + this.inputList[i].type == Blockly.inputTypes.DUMMY) { // Dummy input after a value input. Inline them. return true; } @@ -1441,7 +1447,7 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { * @return {!Blockly.Input} The input object created. */ 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. */ 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. */ 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. - * @param {number} type Either Blockly.INPUT_VALUE or Blockly.NEXT_STATEMENT or - * Blockly.DUMMY_INPUT. + * @param {number} type One of Blockly.inputTypes. * @param {string} name Language-neutral identifier which may used to find this * input again. Should be unique to this block. * @return {!Blockly.Input} The input object created. @@ -1845,10 +1850,11 @@ Blockly.Block.prototype.stringToFieldJson_ = function(str) { */ Blockly.Block.prototype.appendInput_ = function(type, name) { 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); } - if (type == Blockly.NEXT_STATEMENT) { + if (type == Blockly.inputTypes.STATEMENT) { this.statementInputCount++; } 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) { for (var i = 0, input; (input = this.inputList[i]); i++) { if (input.name == name) { - if (input.type == Blockly.NEXT_STATEMENT) { + if (input.type == Blockly.inputTypes.STATEMENT) { this.statementInputCount--; } input.dispose(); diff --git a/core/block_svg.js b/core/block_svg.js index 1aacd4801..b2a386d91 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -17,6 +17,7 @@ goog.require('Blockly.Block'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockRendering.IPathObject'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenuRegistry'); @@ -159,7 +160,7 @@ Blockly.BlockSvg.prototype.warningTextDb_ = null; /** * 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 */ 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. - * @param {number} type Either Blockly.INPUT_VALUE or Blockly.NEXT_STATEMENT or - * Blockly.DUMMY_INPUT. + * @param {number} type One of Blockly.inputTypes. * @param {string} name Language-neutral identifier which may used to find this * input again. Should be unique to this block. * @return {!Blockly.Input} The input object created. @@ -1587,8 +1587,8 @@ Blockly.BlockSvg.prototype.positionNearConnection = function(sourceConnection, targetConnection) { // We only need to position the new block if it's before the existing one, // otherwise its position is set by the previous block. - if (sourceConnection.type == Blockly.NEXT_STATEMENT || - sourceConnection.type == Blockly.INPUT_VALUE) { + if (sourceConnection.type == Blockly.connectionTypes.NEXT_STATEMENT || + sourceConnection.type == Blockly.connectionTypes.INPUT_VALUE) { var dx = targetConnection.x - sourceConnection.x; var dy = targetConnection.y - sourceConnection.y; diff --git a/core/blockly.js b/core/blockly.js index 55bfa2f55..5c691b612 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -18,6 +18,7 @@ goog.provide('Blockly'); goog.require('Blockly.browserEvents'); goog.require('Blockly.constants'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.Events.FinishedLoading'); @@ -25,6 +26,7 @@ goog.require('Blockly.Events.Ui'); goog.require('Blockly.Events.UiBase'); goog.require('Blockly.Events.VarCreate'); goog.require('Blockly.inject'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.Procedures'); goog.require('Blockly.ShortcutRegistry'); goog.require('Blockly.Tooltip'); @@ -518,3 +520,33 @@ Blockly.ALIGN_CENTRE = Blockly.constants.ALIGN.CENTRE; * @see 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; diff --git a/core/connection.js b/core/connection.js index 988f48b34..ff16066df 100644 --- a/core/connection.js +++ b/core/connection.js @@ -12,6 +12,7 @@ goog.provide('Blockly.Connection'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockMove'); @@ -122,7 +123,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { shadowDom = /** @type {!Element} */ (Blockly.Xml.blockToDom(orphanBlock)); orphanBlock.dispose(false); orphanBlock = null; - } else if (parentConnection.type == Blockly.INPUT_VALUE) { + } else if (parentConnection.type == Blockly.connectionTypes.INPUT_VALUE) { // Value connections. // If female block is already connected, disconnect and bump the male. if (!orphanBlock.outputConnection) { @@ -137,7 +138,8 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { orphanBlock.outputConnection.connect(connection); orphanBlock = null; } - } else if (parentConnection.type == Blockly.NEXT_STATEMENT) { + } else if ( + parentConnection.type == Blockly.connectionTypes.NEXT_STATEMENT) { // Statement connections. // Statement blocks may be inserted into the middle of a stack. // Split the stack. @@ -234,8 +236,8 @@ Blockly.Connection.prototype.getSourceBlock = function() { * @return {boolean} True if connection faces down or right. */ Blockly.Connection.prototype.isSuperior = function() { - return this.type == Blockly.INPUT_VALUE || - this.type == Blockly.NEXT_STATEMENT; + return this.type == Blockly.connectionTypes.INPUT_VALUE || + 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++) { var thisConnection = block.inputList[i].connection; var typeChecker = output.getConnectionChecker(); - if (thisConnection && thisConnection.type == Blockly.INPUT_VALUE && + if (thisConnection && + thisConnection.type == Blockly.connectionTypes.INPUT_VALUE && typeChecker.canConnect(output, thisConnection, false)) { if (connection) { return null; // More than one connection. diff --git a/core/connection_checker.js b/core/connection_checker.js index e59db419e..a69c5706b 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -14,6 +14,7 @@ goog.provide('Blockly.ConnectionChecker'); goog.require('Blockly.Connection'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.IConnectionChecker'); goog.require('Blockly.registry'); @@ -198,9 +199,9 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } switch (b.type) { - case Blockly.PREVIOUS_STATEMENT: + case Blockly.connectionTypes.PREVIOUS_STATEMENT: 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 // an available right (female) value plug. if ((b.isConnected() && @@ -210,7 +211,7 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } break; } - case Blockly.INPUT_VALUE: { + case Blockly.connectionTypes.INPUT_VALUE: { // Offering to connect the left (male) of a value block to an already // connected value pair is ok, we'll splice it in. // However, don't offer to splice into an immovable block. @@ -221,7 +222,7 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } 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 // stack. But covering up a shadow block or stack of shadow blocks is // fine. Similarly, replacing a terminal statement with another terminal diff --git a/core/connection_db.js b/core/connection_db.js index 027c7fe34..0ce206f57 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -14,6 +14,7 @@ goog.provide('Blockly.ConnectionDB'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.RenderedConnection'); @@ -289,9 +290,13 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, Blockly.ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. var dbList = []; - dbList[Blockly.INPUT_VALUE] = new Blockly.ConnectionDB(checker); - dbList[Blockly.OUTPUT_VALUE] = new Blockly.ConnectionDB(checker); - dbList[Blockly.NEXT_STATEMENT] = new Blockly.ConnectionDB(checker); - dbList[Blockly.PREVIOUS_STATEMENT] = new Blockly.ConnectionDB(checker); + dbList[Blockly.connectionTypes.INPUT_VALUE] = + new Blockly.ConnectionDB(checker); + dbList[Blockly.connectionTypes.OUTPUT_VALUE] = + new Blockly.ConnectionDB(checker); + dbList[Blockly.connectionTypes.NEXT_STATEMENT] = + new Blockly.ConnectionDB(checker); + dbList[Blockly.connectionTypes.PREVIOUS_STATEMENT] = + new Blockly.ConnectionDB(checker); return dbList; }; diff --git a/core/connection_types.js b/core/connection_types.js new file mode 100644 index 000000000..b2116812b --- /dev/null +++ b/core/connection_types.js @@ -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 +}; diff --git a/core/constants.js b/core/constants.js index 4c91693b4..00ab949f2 100644 --- a/core/constants.js +++ b/core/constants.js @@ -12,6 +12,9 @@ goog.provide('Blockly.constants'); +goog.require('Blockly.connectionTypes'); + + /** * The multiplier for scroll wheel deltas using the line delta mode. * @type {number} @@ -109,35 +112,22 @@ Blockly.SPRITE = { // Constants below this point are not intended to be changed. -/** - * ENUM for a right-facing value input. E.g. 'set item to' or 'return'. - * @const - */ -Blockly.INPUT_VALUE = 1; - -/** - * ENUM for a left-facing value output. E.g. 'random fraction'. - * @const - */ -Blockly.OUTPUT_VALUE = 2; - -/** - * ENUM for a down-facing block stack. E.g. 'if-do' or 'else'. - * @const - */ -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 the type of a connection or input. +// * @enum {number} +// */ +// Blockly.constants.CONNECTION_TYPE = { +// // 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, +// // A dummy input. Used to add field(s) with no input. +// DUMMY_INPUT: 5 +// }; /** * Enum for alignment of inputs. @@ -179,10 +169,14 @@ Blockly.DRAG_FREE = 2; * @const */ Blockly.OPPOSITE_TYPE = []; -Blockly.OPPOSITE_TYPE[Blockly.INPUT_VALUE] = Blockly.OUTPUT_VALUE; -Blockly.OPPOSITE_TYPE[Blockly.OUTPUT_VALUE] = Blockly.INPUT_VALUE; -Blockly.OPPOSITE_TYPE[Blockly.NEXT_STATEMENT] = Blockly.PREVIOUS_STATEMENT; -Blockly.OPPOSITE_TYPE[Blockly.PREVIOUS_STATEMENT] = Blockly.NEXT_STATEMENT; +Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.INPUT_VALUE] = + Blockly.connectionTypes.OUTPUT_VALUE; +Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.OUTPUT_VALUE] = + 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; /** diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index 6d5c54e27..9800c3476 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -18,6 +18,7 @@ goog.provide('Blockly.ContextMenuItems'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); +goog.require('Blockly.inputTypes'); goog.requireType('Blockly.BlockSvg'); @@ -65,7 +66,7 @@ Blockly.ContextMenuItems.registerRedo = function() { }; Blockly.ContextMenuRegistry.registry.register(redoOption); }; - + /** Option to clean up blocks. */ Blockly.ContextMenuItems.registerCleanup = function() { /** @type {!Blockly.ContextMenuRegistry.RegistryItem} */ @@ -91,7 +92,7 @@ Blockly.ContextMenuItems.registerCleanup = function() { }; Blockly.ContextMenuRegistry.registry.register(cleanOption); }; - + /** * Creates a callback to collapse or expand top blocks. * @param {boolean} shouldCollapse Whether a block should collapse. @@ -143,7 +144,7 @@ Blockly.ContextMenuItems.registerCollapse = function() { }; Blockly.ContextMenuRegistry.registry.register(collapseOption); }; - + /** Option to expand all blocks. */ Blockly.ContextMenuItems.registerExpand = function() { /** @type {!Blockly.ContextMenuRegistry.RegistryItem} */ @@ -176,7 +177,7 @@ Blockly.ContextMenuItems.registerExpand = function() { }; Blockly.ContextMenuRegistry.registry.register(expandOption); }; - + /** * Adds a block and its children to a list of deletable blocks. * @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. * @param {!Blockly.WorkspaceSvg} workspace to delete all blocks from. @@ -209,7 +210,7 @@ Blockly.ContextMenuItems.getDeletableBlocks_ = function(workspace) { } return deleteList; }; - + /** Deletes the given blocks. Used to delete all blocks in the workspace. * @param {!Array.} deleteList list of blocks to delete. * @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); }; - + /** Option to delete all blocks. */ Blockly.ContextMenuItems.registerDeleteAll = function() { /** @type {!Blockly.ContextMenuRegistry.RegistryItem} */ @@ -371,8 +372,8 @@ Blockly.ContextMenuItems.registerInline = function() { if (!block.isInFlyout && block.isMovable() && !block.isCollapsed()) { 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. - if (block.inputList[i - 1].type != Blockly.NEXT_STATEMENT && - block.inputList[i].type != Blockly.NEXT_STATEMENT) { + if (block.inputList[i - 1].type != Blockly.inputTypes.STATEMENT && + block.inputList[i].type != Blockly.inputTypes.STATEMENT) { return 'enabled'; } } @@ -535,4 +536,4 @@ Blockly.ContextMenuItems.registerDefaultOptions = function() { Blockly.ContextMenuItems.registerWorkspaceOptions_(); Blockly.ContextMenuItems.registerBlockOptions_(); }; - + diff --git a/core/events/block_events.js b/core/events/block_events.js index cbc608f3e..52fc5d53d 100644 --- a/core/events/block_events.js +++ b/core/events/block_events.js @@ -22,6 +22,7 @@ goog.provide('Blockly.Events.Move'); // Deprecated. goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.registry'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.object'); @@ -550,7 +551,8 @@ Blockly.Events.Move.prototype.run = function(forward) { if (input) { parentConnection = input.connection; } - } else if (blockConnection.type == Blockly.PREVIOUS_STATEMENT) { + } else if ( + blockConnection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { parentConnection = parentBlock.nextConnection; } if (parentConnection) { diff --git a/core/input.js b/core/input.js index 098471046..c43a591d3 100644 --- a/core/input.js +++ b/core/input.js @@ -15,6 +15,7 @@ goog.provide('Blockly.Input'); goog.require('Blockly.Connection'); goog.require('Blockly.constants'); goog.require('Blockly.fieldRegistry'); +goog.require('Blockly.inputTypes'); goog.requireType('Blockly.Block'); goog.requireType('Blockly.BlockSvg'); @@ -33,7 +34,7 @@ goog.requireType('Blockly.RenderedConnection'); * @constructor */ 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.'); } /** @type {number} */ diff --git a/core/input_types.js b/core/input_types.js new file mode 100644 index 000000000..a58706358 --- /dev/null +++ b/core/input_types.js @@ -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 +}; diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index 490e88ef3..76bd389a6 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -14,6 +14,7 @@ goog.provide('Blockly.InsertionMarkerManager'); goog.require('Blockly.Block'); goog.require('Blockly.blockAnimations'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); @@ -618,7 +619,8 @@ Blockly.InsertionMarkerManager.prototype.hideInsertionMarker_ = function() { var isFirstInStatementStack = (imConn == markerNext && !(markerPrev && markerPrev.targetConnection)); - var isFirstInOutputStack = imConn.type == Blockly.INPUT_VALUE && + var isFirstInOutputStack = + imConn.type == Blockly.connectionTypes.INPUT_VALUE && !(markerOutput && markerOutput.targetConnection); // The insertion marker is the first block in a stack. Unplug won't do // anything in that case. Instead, unplug the following block. @@ -626,7 +628,9 @@ Blockly.InsertionMarkerManager.prototype.hideInsertionMarker_ = function() { imConn.targetBlock().unplug(false); } // 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; innerConnection.getSourceBlock().unplug(false); diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 29a61546a..e2abf643c 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -12,6 +12,7 @@ goog.provide('Blockly.ASTNode'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.utils.Coordinate'); @@ -147,16 +148,17 @@ Blockly.ASTNode.createConnectionNode = function(connection) { if (!connection) { return null; } - if (connection.type == Blockly.INPUT_VALUE) { + if (connection.type == Blockly.connectionTypes.INPUT_VALUE) { return Blockly.ASTNode.createInputNode(connection.getParentInput()); - } else if (connection.type == Blockly.NEXT_STATEMENT && + } else if ( + connection.type == Blockly.connectionTypes.NEXT_STATEMENT && 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); - } else if (connection.type == Blockly.OUTPUT_VALUE) { + } else if (connection.type == Blockly.connectionTypes.OUTPUT_VALUE) { 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 null; diff --git a/core/rendered_connection.js b/core/rendered_connection.js index d01dc4bba..56d1240a3 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -13,6 +13,7 @@ goog.provide('Blockly.RenderedConnection'); goog.require('Blockly.Connection'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.utils'); @@ -288,7 +289,8 @@ Blockly.RenderedConnection.prototype.highlight = function() { var sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); var renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); 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. var yLen = renderConstants.TAB_OFFSET_FROM_TOP; 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, // we only need to render the leaf nodes. 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. return renderList; } @@ -533,8 +536,8 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { childBlock.updateDisabled(); } if (parentRendered && childRendered) { - if (parentConnection.type == Blockly.NEXT_STATEMENT || - parentConnection.type == Blockly.PREVIOUS_STATEMENT) { + if (parentConnection.type == Blockly.connectionTypes.NEXT_STATEMENT || + parentConnection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { // Child block may need to square off its corners if it is in a stack. // Rendering a child will render its parent. childBlock.render(); diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index aeb2af08e..004c284df 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -12,6 +12,7 @@ goog.provide('Blockly.blockRendering.ConstantProvider'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.colour'); @@ -995,11 +996,11 @@ Blockly.blockRendering.ConstantProvider.prototype.makeOutsideCorners = function( Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function( connection) { switch (connection.type) { - case Blockly.INPUT_VALUE: - case Blockly.OUTPUT_VALUE: + case Blockly.connectionTypes.INPUT_VALUE: + case Blockly.connectionTypes.OUTPUT_VALUE: return this.PUZZLE_TAB; - case Blockly.PREVIOUS_STATEMENT: - case Blockly.NEXT_STATEMENT: + case Blockly.connectionTypes.PREVIOUS_STATEMENT: + case Blockly.connectionTypes.NEXT_STATEMENT: return this.NOTCH; default: throw Error('Unknown connection type'); diff --git a/core/renderers/common/debugger.js b/core/renderers/common/debugger.js index 3cdb49745..21cda9439 100644 --- a/core/renderers/common/debugger.js +++ b/core/renderers/common/debugger.js @@ -20,6 +20,7 @@ goog.require('Blockly.blockRendering.Row'); goog.require('Blockly.blockRendering.SpacerRow'); goog.require('Blockly.blockRendering.TopRow'); goog.require('Blockly.blockRendering.Types'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); @@ -229,19 +230,19 @@ Blockly.blockRendering.Debug.prototype.drawConnection = function(conn) { var colour; var size; var fill; - if (conn.type == Blockly.INPUT_VALUE) { + if (conn.type == Blockly.connectionTypes.INPUT_VALUE) { size = 4; colour = 'magenta'; fill = 'none'; - } else if (conn.type == Blockly.OUTPUT_VALUE) { + } else if (conn.type == Blockly.connectionTypes.OUTPUT_VALUE) { size = 2; colour = 'magenta'; fill = colour; - } else if (conn.type == Blockly.NEXT_STATEMENT) { + } else if (conn.type == Blockly.connectionTypes.NEXT_STATEMENT) { size = 4; colour = 'goldenrod'; fill = 'none'; - } else if (conn.type == Blockly.PREVIOUS_STATEMENT) { + } else if (conn.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { size = 2; colour = 'goldenrod'; fill = colour; diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index b98c0cf36..69f76507c 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -30,6 +30,7 @@ goog.require('Blockly.blockRendering.StatementInput'); goog.require('Blockly.blockRendering.TopRow'); goog.require('Blockly.blockRendering.Types'); goog.require('Blockly.constants'); +goog.require('Blockly.inputTypes'); goog.requireType('Blockly.blockRendering.ConstantProvider'); goog.requireType('Blockly.blockRendering.Icon'); @@ -286,7 +287,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { } 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 // 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() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; - var followsStatement = - this.block_.inputList.length && - this.block_.inputList[this.block_.inputList.length - 1] - .type == Blockly.NEXT_STATEMENT; + var followsStatement = this.block_.inputList.length && + this.block_.inputList[this.block_.inputList.length - 1].type == + Blockly.inputTypes.STATEMENT; // 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. @@ -367,19 +367,19 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { */ Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRow) { // 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( new Blockly.blockRendering.InlineInput(this.constants_, input)); activeRow.hasInlineInput = true; - } else if (input.type == Blockly.NEXT_STATEMENT) { + } else if (input.type == Blockly.inputTypes.STATEMENT) { activeRow.elements.push( new Blockly.blockRendering.StatementInput(this.constants_, input)); activeRow.hasStatement = true; - } else if (input.type == Blockly.INPUT_VALUE) { + } else if (input.type == Blockly.inputTypes.VALUE) { activeRow.elements.push( new Blockly.blockRendering.ExternalValueInput(this.constants_, input)); 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 // important. activeRow.minHeight = Math.max(activeRow.minHeight, @@ -407,12 +407,13 @@ Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, return false; } // A statement input or an input following one always gets a new row. - if (input.type == Blockly.NEXT_STATEMENT || - lastInput.type == Blockly.NEXT_STATEMENT) { + if (input.type == Blockly.inputTypes.STATEMENT || + lastInput.type == Blockly.inputTypes.STATEMENT) { return true; } // 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 false; diff --git a/core/renderers/common/marker_svg.js b/core/renderers/common/marker_svg.js index 8cee6f5e5..33bcf6a19 100644 --- a/core/renderers/common/marker_svg.js +++ b/core/renderers/common/marker_svg.js @@ -14,6 +14,7 @@ goog.provide('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.ASTNode'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.Events.MarkerMove'); @@ -210,9 +211,10 @@ Blockly.blockRendering.MarkerSvg.prototype.showAtLocation_ = function(curNode) { this.showWithBlock_(curNode); } else if (curNode.getType() == Blockly.ASTNode.types.OUTPUT) { this.showWithOutput_(curNode); - } else if (curNodeAsConnection.type == Blockly.INPUT_VALUE) { + } else if (curNodeAsConnection.type == Blockly.connectionTypes.INPUT_VALUE) { this.showWithInput_(curNode); - } else if (curNodeAsConnection.type == Blockly.NEXT_STATEMENT) { + } else if ( + curNodeAsConnection.type == Blockly.connectionTypes.NEXT_STATEMENT) { this.showWithNext_(curNode); } else if (curNode.getType() == Blockly.ASTNode.types.PREVIOUS) { this.showWithPrevious_(curNode); diff --git a/core/renderers/common/renderer.js b/core/renderers/common/renderer.js index 1461b836f..9a3b8e094 100644 --- a/core/renderers/common/renderer.js +++ b/core/renderers/common/renderer.js @@ -19,6 +19,7 @@ goog.require('Blockly.blockRendering.IPathObject'); goog.require('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.blockRendering.PathObject'); goog.require('Blockly.blockRendering.RenderInfo'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.IRegistrable'); @@ -246,7 +247,9 @@ Blockly.blockRendering.Renderer.prototype.orphanCanConnectAtEnd = function(topBlock, orphanBlock, localType) { var orphanConnection = 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; // TODO: I don't think this function necessarily has the correct logic, // but for now it is being kept for behavioral backwards-compat. @@ -278,22 +281,22 @@ Blockly.blockRendering.Renderer.prototype.orphanCanConnectAtEnd = * to display. * @package */ -Blockly.blockRendering.Renderer.prototype.getConnectionPreviewMethod = - function(closest, local, topBlock) { - if (local.type == Blockly.OUTPUT_VALUE || - local.type == Blockly.PREVIOUS_STATEMENT) { - if (!closest.isConnected() || - this.orphanCanConnectAtEnd( - topBlock, - /** @type {!Blockly.BlockSvg} */ (closest.targetBlock()), - local.type)) { - return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER; - } - return Blockly.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE; - } - +Blockly.blockRendering.Renderer.prototype.getConnectionPreviewMethod = function( + closest, local, topBlock) { + if (local.type == Blockly.connectionTypes.OUTPUT_VALUE || + local.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { + if (!closest.isConnected() || + this.orphanCanConnectAtEnd( + topBlock, + /** @type {!Blockly.BlockSvg} */ (closest.targetBlock()), + local.type)) { return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER; - }; + } + return Blockly.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE; + } + + return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER; +}; /** * Render the block. diff --git a/core/renderers/geras/info.js b/core/renderers/geras/info.js index 5b5fadc97..6b8a3ecf4 100644 --- a/core/renderers/geras/info.js +++ b/core/renderers/geras/info.js @@ -33,6 +33,7 @@ goog.require('Blockly.blockRendering.Types'); goog.require('Blockly.constants'); goog.require('Blockly.geras.InlineInput'); goog.require('Blockly.geras.StatementInput'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.utils.object'); goog.requireType('Blockly.blockRendering.Field'); @@ -74,10 +75,9 @@ Blockly.geras.RenderInfo.prototype.getRenderer = function() { Blockly.geras.RenderInfo.prototype.populateBottomRow_ = function() { Blockly.geras.RenderInfo.superClass_.populateBottomRow_.call(this); - var followsStatement = - this.block_.inputList.length && - this.block_.inputList[this.block_.inputList.length - 1] - .type == Blockly.NEXT_STATEMENT; + var followsStatement = this.block_.inputList.length && + this.block_.inputList[this.block_.inputList.length - 1].type == + Blockly.inputTypes.STATEMENT; // The minimum height of the bottom row is smaller in Geras than in other // 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) { // 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( new Blockly.geras.InlineInput(this.constants_, input)); activeRow.hasInlineInput = true; - } else if (input.type == Blockly.NEXT_STATEMENT) { + } else if (input.type == Blockly.inputTypes.STATEMENT) { activeRow.elements.push( new Blockly.geras.StatementInput(this.constants_, input)); activeRow.hasStatement = true; - } else if (input.type == Blockly.INPUT_VALUE) { + } else if (input.type == Blockly.inputTypes.VALUE) { activeRow.elements.push( new Blockly.blockRendering.ExternalValueInput(this.constants_, input)); 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 // important. activeRow.minHeight = Math.max(activeRow.minHeight, diff --git a/core/renderers/zelos/constants.js b/core/renderers/zelos/constants.js index 8da04559c..44d6f9ace 100644 --- a/core/renderers/zelos/constants.js +++ b/core/renderers/zelos/constants.js @@ -14,6 +14,7 @@ goog.provide('Blockly.zelos.ConstantProvider'); goog.require('Blockly.blockRendering.ConstantProvider'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.dom'); @@ -650,8 +651,8 @@ Blockly.zelos.ConstantProvider.prototype.shapeFor = function( checks = connection.targetConnection.getCheck(); } switch (connection.type) { - case Blockly.INPUT_VALUE: - case Blockly.OUTPUT_VALUE: + case Blockly.connectionTypes.INPUT_VALUE: + case Blockly.connectionTypes.OUTPUT_VALUE: var outputShape = connection.getSourceBlock().getOutputShape(); // If the block has an output shape set, use that instead. if (outputShape != null) { @@ -672,8 +673,8 @@ Blockly.zelos.ConstantProvider.prototype.shapeFor = function( return this.ROUNDED; } return this.ROUNDED; - case Blockly.PREVIOUS_STATEMENT: - case Blockly.NEXT_STATEMENT: + case Blockly.connectionTypes.PREVIOUS_STATEMENT: + case Blockly.connectionTypes.NEXT_STATEMENT: return this.NOTCH; default: throw Error('Unknown type'); diff --git a/core/renderers/zelos/info.js b/core/renderers/zelos/info.js index 0ced02658..3c76443ca 100644 --- a/core/renderers/zelos/info.js +++ b/core/renderers/zelos/info.js @@ -34,6 +34,7 @@ goog.require('Blockly.constants'); goog.require('Blockly.FieldImage'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.utils.object'); goog.require('Blockly.zelos.BottomRow'); goog.require('Blockly.zelos.RightConnectionShape'); @@ -137,12 +138,13 @@ Blockly.zelos.RenderInfo.prototype.shouldStartNewRow_ = function(input, return false; } // A statement input or an input following one always gets a new row. - if (input.type == Blockly.NEXT_STATEMENT || - lastInput.type == Blockly.NEXT_STATEMENT) { + if (input.type == Blockly.inputTypes.STATEMENT || + lastInput.type == Blockly.inputTypes.STATEMENT) { return true; } // 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 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 // right, keep track of the right aligned dummy input so we can add padding // later. - if (input.type == Blockly.DUMMY_INPUT && activeRow.hasDummyInput && + if (input.type == Blockly.inputTypes.DUMMY && activeRow.hasDummyInput && activeRow.align == Blockly.constants.ALIGN.LEFT && input.align == Blockly.constants.ALIGN.RIGHT) { activeRow.rightAlignedDummyInput = input; diff --git a/core/renderers/zelos/renderer.js b/core/renderers/zelos/renderer.js index 7e948c15a..74ca3620b 100644 --- a/core/renderers/zelos/renderer.js +++ b/core/renderers/zelos/renderer.js @@ -14,6 +14,7 @@ goog.provide('Blockly.zelos.Renderer'); goog.require('Blockly.blockRendering'); goog.require('Blockly.blockRendering.Renderer'); +goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.utils.object'); @@ -111,28 +112,29 @@ Blockly.zelos.Renderer.prototype.makePathObject = function(root, style) { * @override */ 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 */ -Blockly.zelos.Renderer.prototype.getConnectionPreviewMethod = - function(closest, local, topBlock) { - if (local.type == Blockly.OUTPUT_VALUE) { - if (!closest.isConnected()) { - return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE; - } - // TODO: Returning this is a total hack, because we don't want to show - // a replacement fade, we want to show an outline affect. - // Sadly zelos does not support showing an outline around filled - // inputs, so we have to pretend like the connected block is getting - // replaced. - return Blockly.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE; - } +Blockly.zelos.Renderer.prototype.getConnectionPreviewMethod = function( + closest, local, topBlock) { + if (local.type == Blockly.connectionTypes.OUTPUT_VALUE) { + if (!closest.isConnected()) { + return Blockly.InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE; + } + // TODO: Returning this is a total hack, because we don't want to show + // a replacement fade, we want to show an outline affect. + // Sadly zelos does not support showing an outline around filled + // inputs, so we have to pretend like the connected block is getting + // replaced. + return Blockly.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE; + } - return Blockly.zelos.Renderer.superClass_ - .getConnectionPreviewMethod(closest, local, topBlock); - }; + return Blockly.zelos.Renderer.superClass_.getConnectionPreviewMethod( + closest, local, topBlock); +}; Blockly.blockRendering.register('zelos', Blockly.zelos.Renderer); diff --git a/core/xml.js b/core/xml.js index 1f58eae82..5b30d0b9d 100644 --- a/core/xml.js +++ b/core/xml.js @@ -18,6 +18,7 @@ goog.provide('Blockly.Xml'); goog.require('Blockly.constants'); goog.require('Blockly.Events'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.utils'); goog.require('Blockly.utils.dom'); 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++) { var container; var empty = true; - if (input.type == Blockly.DUMMY_INPUT) { + if (input.type == Blockly.inputTypes.DUMMY) { continue; } else { var childBlock = input.connection.targetBlock(); - if (input.type == Blockly.INPUT_VALUE) { + if (input.type == Blockly.inputTypes.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'); } var shadow = input.connection.getShadowDom(); diff --git a/generators/dart.js b/generators/dart.js index a801a0655..1eb3a706a 100644 --- a/generators/dart.js +++ b/generators/dart.js @@ -13,6 +13,7 @@ goog.provide('Blockly.Dart'); goog.require('Blockly.Generator'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.utils.string'); @@ -219,7 +220,7 @@ Blockly.Dart.scrub_ = function(block, code, opt_thisOnly) { // Collect comments for all value arguments. // Don't collect comments for nested statements. 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(); if (childBlock) { comment = Blockly.Dart.allNestedComments(childBlock); diff --git a/generators/javascript.js b/generators/javascript.js index 368a35a6d..7bedb4831 100644 --- a/generators/javascript.js +++ b/generators/javascript.js @@ -13,6 +13,7 @@ goog.provide('Blockly.JavaScript'); goog.require('Blockly.Generator'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.string'); @@ -244,7 +245,7 @@ Blockly.JavaScript.scrub_ = function(block, code, opt_thisOnly) { // Collect comments for all value arguments. // Don't collect comments for nested statements. 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(); if (childBlock) { comment = Blockly.JavaScript.allNestedComments(childBlock); diff --git a/generators/lua.js b/generators/lua.js index 75a6b7b8b..da3e750d0 100644 --- a/generators/lua.js +++ b/generators/lua.js @@ -14,6 +14,7 @@ goog.provide('Blockly.Lua'); goog.require('Blockly.Generator'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.utils.string'); @@ -188,7 +189,7 @@ Blockly.Lua.scrub_ = function(block, code, opt_thisOnly) { // Collect comments for all value arguments. // Don't collect comments for nested statements. 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(); if (childBlock) { comment = Blockly.Lua.allNestedComments(childBlock); diff --git a/generators/php.js b/generators/php.js index 326cc8ecd..8cab5c231 100644 --- a/generators/php.js +++ b/generators/php.js @@ -13,6 +13,7 @@ goog.provide('Blockly.PHP'); goog.require('Blockly.Generator'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.utils.string'); @@ -244,7 +245,7 @@ Blockly.PHP.scrub_ = function(block, code, opt_thisOnly) { // Collect comments for all value arguments. // Don't collect comments for nested statements. 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(); if (childBlock) { comment = Blockly.PHP.allNestedComments(childBlock); diff --git a/generators/python.js b/generators/python.js index 9844b9501..707c948e7 100644 --- a/generators/python.js +++ b/generators/python.js @@ -13,6 +13,7 @@ goog.provide('Blockly.Python'); goog.require('Blockly.Generator'); +goog.require('Blockly.inputTypes'); goog.require('Blockly.utils.string'); @@ -271,7 +272,7 @@ Blockly.Python.scrub_ = function(block, code, opt_thisOnly) { // Collect comments for all value arguments. // Don't collect comments for nested statements. 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(); if (childBlock) { comment = Blockly.Python.allNestedComments(childBlock);