Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Rename Blockly.connectionTypes to Blockly.ConnectionType #5407

Merged
merged 14 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Tooltip = goog.require('Blockly.Tooltip');
const VariableModel = goog.requireType('Blockly.VariableModel');
/* eslint-disable-next-line no-unused-vars */
const Workspace = goog.requireType('Blockly.Workspace');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');
const constants = goog.require('Blockly.constants');
const fieldRegistry = goog.require('Blockly.fieldRegistry');
const idGenerator = goog.require('Blockly.utils.idGenerator');
Expand Down Expand Up @@ -508,7 +508,7 @@ Block.prototype.getOnlyValueConnection_ = function() {
let connection = null;
for (let i = 0; i < this.inputList.length; i++) {
const thisConnection = this.inputList[i].connection;
if (thisConnection && thisConnection.type == connectionTypes.INPUT_VALUE &&
if (thisConnection && thisConnection.type == ConnectionTypes.INPUT_VALUE &&
thisConnection.targetConnection) {
if (connection) {
return null; // More than one value input found.
Expand Down Expand Up @@ -673,7 +673,7 @@ Block.prototype.getPreviousBlock = function() {
Block.prototype.getFirstStatementConnection = function() {
for (let i = 0, input; (input = this.inputList[i]); i++) {
if (input.connection &&
input.connection.type == connectionTypes.NEXT_STATEMENT) {
input.connection.type == ConnectionTypes.NEXT_STATEMENT) {
return input.connection;
}
}
Expand Down Expand Up @@ -1171,7 +1171,7 @@ Block.prototype.setPreviousStatement = function(newBoolean, opt_check) {
'connection.');
}
this.previousConnection =
this.makeConnection_(connectionTypes.PREVIOUS_STATEMENT);
this.makeConnection_(ConnectionTypes.PREVIOUS_STATEMENT);
}
this.previousConnection.setCheck(opt_check);
} else {
Expand Down Expand Up @@ -1200,7 +1200,7 @@ Block.prototype.setNextStatement = function(newBoolean, opt_check) {
}
if (!this.nextConnection) {
this.nextConnection =
this.makeConnection_(connectionTypes.NEXT_STATEMENT);
this.makeConnection_(ConnectionTypes.NEXT_STATEMENT);
}
this.nextConnection.setCheck(opt_check);
} else {
Expand Down Expand Up @@ -1235,7 +1235,7 @@ Block.prototype.setOutput = function(newBoolean, opt_check) {
'connection.');
}
this.outputConnection =
this.makeConnection_(connectionTypes.OUTPUT_VALUE);
this.makeConnection_(ConnectionTypes.OUTPUT_VALUE);
}
this.outputConnection.setCheck(opt_check);
} else {
Expand Down
6 changes: 3 additions & 3 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Xml = goog.require('Blockly.Xml');
const blockAnimations = goog.require('Blockly.blockAnimations');
const browserEvents = goog.require('Blockly.browserEvents');
const common = goog.require('Blockly.common');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');
const constants = goog.require('Blockly.constants');
const deprecation = goog.require('Blockly.utils.deprecation');
const dom = goog.require('Blockly.utils.dom');
Expand Down Expand Up @@ -1610,8 +1610,8 @@ 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 == connectionTypes.NEXT_STATEMENT ||
sourceConnection.type == connectionTypes.INPUT_VALUE) {
if (sourceConnection.type == ConnectionTypes.NEXT_STATEMENT ||
sourceConnection.type == ConnectionTypes.INPUT_VALUE) {
const dx = targetConnection.x - sourceConnection.x;
const dy = targetConnection.y - sourceConnection.y;

Expand Down
18 changes: 9 additions & 9 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ goog.require('Blockly.browserEvents');
goog.require('Blockly.clipboard');
goog.require('Blockly.common');
goog.require('Blockly.ComponentManager');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.ConnectionTypes');
goog.require('Blockly.constants');
goog.require('Blockly.dialog');
goog.require('Blockly.DropDownDiv');
Expand Down Expand Up @@ -412,24 +412,24 @@ Blockly.ALIGN_RIGHT = Blockly.constants.ALIGN.RIGHT;
*/

/**
* @see Blockly.connectionTypes.INPUT_VALUE
* @see Blockly.ConnectionTypes.INPUT_VALUE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is one example of a lint error that needs fixing.

*/
Blockly.INPUT_VALUE = Blockly.connectionTypes.INPUT_VALUE;
Blockly.INPUT_VALUE = Blockly.ConnectionTypes.INPUT_VALUE;

/**
* @see Blockly.connectionTypes.OUTPUT_VALUE
* @see Blockly.ConnectionTypes.INPUT_VALUE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has extraneous leading and trailing spaces.

*/
Blockly.OUTPUT_VALUE = Blockly.connectionTypes.OUTPUT_VALUE;
Blockly.OUTPUT_VALUE = Blockly.ConnectionTypes.OUTPUT_VALUE

/**
* @see Blockly.connectionTypes.NEXT_STATEMENT
* @see Blockly.ConnectionTypes.NEXT_STATEMENT
*/
Blockly.NEXT_STATEMENT = Blockly.connectionTypes.NEXT_STATEMENT;
Blockly.NEXT_STATEMENT = Blockly.ConnectionTypes.NEXT_STATEMENT;

/**
* @see Blockly.connectionTypes.PREVIOUS_STATEMENT
* @see Blockly.ConnectionTypes.PREVIOUS_STATEMENT
*/
Blockly.PREVIOUS_STATEMENT = Blockly.connectionTypes.PREVIOUS_STATEMENT;
Blockly.PREVIOUS_STATEMENT = Blockly.ConnectionTypes.PREVIOUS_STATEMENT;

/**
* @see Blockly.inputTypes.DUMMY_INPUT
Expand Down
10 changes: 5 additions & 5 deletions core/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker');
/* eslint-disable-next-line no-unused-vars */
const Input = goog.requireType('Blockly.Input');
const Xml = goog.require('Blockly.Xml');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');
const deprecation = goog.require('Blockly.utils.deprecation');
/** @suppress {extraRequire} */
goog.require('Blockly.constants');
Expand Down Expand Up @@ -108,7 +108,7 @@ Connection.prototype.y = 0;
* @protected
*/
Connection.prototype.connect_ = function(childConnection) {
const INPUT = connectionTypes.INPUT_VALUE;
const INPUT = ConnectionTypes.INPUT_VALUE;
const parentConnection = this;
const parentBlock = parentConnection.getSourceBlock();
const childBlock = childConnection.getSourceBlock();
Expand Down Expand Up @@ -194,8 +194,8 @@ Connection.prototype.getSourceBlock = function() {
* @return {boolean} True if connection faces down or right.
*/
Connection.prototype.isSuperior = function() {
return this.type == connectionTypes.INPUT_VALUE ||
this.type == connectionTypes.NEXT_STATEMENT;
return this.type == ConnectionTypes.INPUT_VALUE ||
this.type == ConnectionTypes.NEXT_STATEMENT;
};

/**
Expand Down Expand Up @@ -384,7 +384,7 @@ const getConnectionForOrphanedOutput = function(startBlock, orphanBlock) {
*/
Connection.getConnectionForOrphanedConnection = function(
startBlock, orphanConnection) {
if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) {
if (orphanConnection.type === ConnectionTypes.OUTPUT_VALUE) {
return getConnectionForOrphanedOutput(
startBlock, orphanConnection.getSourceBlock());
}
Expand Down
10 changes: 5 additions & 5 deletions core/connection_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker');
/* eslint-disable-next-line no-unused-vars */
const RenderedConnection = goog.requireType('Blockly.RenderedConnection');
const common = goog.require('Blockly.common');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');
const internalConstants = goog.require('Blockly.internalConstants');
const registry = goog.require('Blockly.registry');

Expand Down Expand Up @@ -202,9 +202,9 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
}

switch (b.type) {
case connectionTypes.PREVIOUS_STATEMENT:
case ConnectionTypes.PREVIOUS_STATEMENT:
return this.canConnectToPrevious_(a, b);
case connectionTypes.OUTPUT_VALUE: {
case 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() && !b.targetBlock().isInsertionMarker()) ||
Expand All @@ -213,7 +213,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
}
break;
}
case connectionTypes.INPUT_VALUE: {
case 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.
Expand All @@ -223,7 +223,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
}
break;
}
case connectionTypes.NEXT_STATEMENT: {
case 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
Expand Down
10 changes: 5 additions & 5 deletions core/connection_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Coordinate = goog.requireType('Blockly.utils.Coordinate');
const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker');
/* eslint-disable-next-line no-unused-vars */
const RenderedConnection = goog.requireType('Blockly.RenderedConnection');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');
/** @suppress {extraRequire} */
goog.require('Blockly.constants');

Expand Down Expand Up @@ -294,10 +294,10 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dxy) {
ConnectionDB.init = function(checker) {
// Create four databases, one for each connection type.
const dbList = [];
dbList[connectionTypes.INPUT_VALUE] = new ConnectionDB(checker);
dbList[connectionTypes.OUTPUT_VALUE] = new ConnectionDB(checker);
dbList[connectionTypes.NEXT_STATEMENT] = new ConnectionDB(checker);
dbList[connectionTypes.PREVIOUS_STATEMENT] = new ConnectionDB(checker);
dbList[ConnectionTypes.INPUT_VALUE] = new ConnectionDB(checker);
dbList[ConnectionTypes.OUTPUT_VALUE] = new ConnectionDB(checker);
dbList[ConnectionTypes.NEXT_STATEMENT] = new ConnectionDB(checker);
dbList[ConnectionTypes.PREVIOUS_STATEMENT] = new ConnectionDB(checker);
return dbList;
};

Expand Down
6 changes: 3 additions & 3 deletions core/connection_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

'use strict';

goog.module('Blockly.connectionTypes');
goog.module('Blockly.ConnectionTypes');
goog.module.declareLegacyNamespace();

/**
* Enum for the type of a connection or input.
* @enum {number}
*/
const connectionTypes = {
const 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'.
Expand All @@ -29,4 +29,4 @@ const connectionTypes = {
PREVIOUS_STATEMENT: 4
};

exports = connectionTypes;
exports = ConnectionTypes;
4 changes: 2 additions & 2 deletions core/events/events_block_move.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Block = goog.requireType('Blockly.Block');
const BlockBase = goog.require('Blockly.Events.BlockBase');
const Coordinate = goog.require('Blockly.utils.Coordinate');
const Events = goog.require('Blockly.Events');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');

Expand Down Expand Up @@ -172,7 +172,7 @@ BlockMove.prototype.run = function(forward) {
if (input) {
parentConnection = input.connection;
}
} else if (connectionType == connectionTypes.PREVIOUS_STATEMENT) {
} else if (connectionType == ConnectionTypes.PREVIOUS_STATEMENT) {
parentConnection = parentBlock.nextConnection;
}
if (parentConnection) {
Expand Down
6 changes: 3 additions & 3 deletions core/input_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
goog.module('Blockly.inputTypes');
goog.module.declareLegacyNamespace();

const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');

/**
* Enum for the type of a connection or input.
* @enum {number}
*/
const inputTypes = {
// A right-facing value input. E.g. 'set item to' or 'return'.
VALUE: connectionTypes.INPUT_VALUE,
VALUE: ConnectionTypes.INPUT_VALUE,
// A down-facing block stack. E.g. 'if-do' or 'else'.
STATEMENT: connectionTypes.NEXT_STATEMENT,
STATEMENT: ConnectionTypes.NEXT_STATEMENT,
// A dummy input. Used to add field(s) with no input.
DUMMY: 5
};
Expand Down
6 changes: 3 additions & 3 deletions core/insertion_marker_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const RenderedConnection = goog.requireType('Blockly.RenderedConnection');
/* eslint-disable-next-line no-unused-vars */
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
const blockAnimations = goog.require('Blockly.blockAnimations');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');
const constants = goog.require('Blockly.constants');
const internalConstants = goog.require('Blockly.internalConstants');

Expand Down Expand Up @@ -657,7 +657,7 @@ InsertionMarkerManager.prototype.hideInsertionMarker_ = function() {
const isFirstInStatementStack =
(imConn == markerNext && !(markerPrev && markerPrev.targetConnection));

const isFirstInOutputStack = imConn.type == connectionTypes.INPUT_VALUE &&
const isFirstInOutputStack = imConn.type == 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.
Expand All @@ -666,7 +666,7 @@ InsertionMarkerManager.prototype.hideInsertionMarker_ = function() {
}
// Inside of a C-block, first statement connection.
else if (
imConn.type == connectionTypes.NEXT_STATEMENT && imConn != markerNext) {
imConn.type == ConnectionTypes.NEXT_STATEMENT && imConn != markerNext) {
const innerConnection = imConn.targetConnection;
innerConnection.getSourceBlock().unplug(false);

Expand Down
14 changes: 7 additions & 7 deletions core/internal_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
goog.module('Blockly.internalConstants');
goog.module.declareLegacyNamespace();

const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');


/**
Expand Down Expand Up @@ -163,12 +163,12 @@ exports.DRAG_FREE = DRAG_FREE;
* @const
*/
const OPPOSITE_TYPE = [];
OPPOSITE_TYPE[connectionTypes.INPUT_VALUE] = connectionTypes.OUTPUT_VALUE;
OPPOSITE_TYPE[connectionTypes.OUTPUT_VALUE] = connectionTypes.INPUT_VALUE;
OPPOSITE_TYPE[connectionTypes.NEXT_STATEMENT] =
connectionTypes.PREVIOUS_STATEMENT;
OPPOSITE_TYPE[connectionTypes.PREVIOUS_STATEMENT] =
connectionTypes.NEXT_STATEMENT;
OPPOSITE_TYPE[ConnectionTypes.INPUT_VALUE] = ConnectionTypes.OUTPUT_VALUE;
OPPOSITE_TYPE[ConnectionTypes.OUTPUT_VALUE] = ConnectionTypes.INPUT_VALUE;
OPPOSITE_TYPE[ConnectionTypes.NEXT_STATEMENT] =
ConnectionTypes.PREVIOUS_STATEMENT;
OPPOSITE_TYPE[ConnectionTypes.PREVIOUS_STATEMENT] =
ConnectionTypes.NEXT_STATEMENT;

exports.OPPOSITE_TYPE = OPPOSITE_TYPE;

Expand Down
12 changes: 6 additions & 6 deletions core/keyboard_nav/ast_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const IASTNodeLocationWithBlock = goog.requireType('Blockly.IASTNodeLocationWith
const Input = goog.requireType('Blockly.Input');
/* eslint-disable-next-line no-unused-vars */
const Workspace = goog.requireType('Blockly.Workspace');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionTypes = goog.require('Blockly.ConnectionTypes');


/**
Expand Down Expand Up @@ -155,16 +155,16 @@ ASTNode.createConnectionNode = function(connection) {
return null;
}
const type = connection.type;
if (type == connectionTypes.INPUT_VALUE) {
if (type == ConnectionTypes.INPUT_VALUE) {
return ASTNode.createInputNode(connection.getParentInput());
} else if (
type == connectionTypes.NEXT_STATEMENT && connection.getParentInput()) {
type == ConnectionTypes.NEXT_STATEMENT && connection.getParentInput()) {
return ASTNode.createInputNode(connection.getParentInput());
} else if (type == connectionTypes.NEXT_STATEMENT) {
} else if (type == ConnectionTypes.NEXT_STATEMENT) {
return new ASTNode(ASTNode.types.NEXT, connection);
} else if (type == connectionTypes.OUTPUT_VALUE) {
} else if (type == ConnectionTypes.OUTPUT_VALUE) {
return new ASTNode(ASTNode.types.OUTPUT, connection);
} else if (type == connectionTypes.PREVIOUS_STATEMENT) {
} else if (type == ConnectionTypes.PREVIOUS_STATEMENT) {
return new ASTNode(ASTNode.types.PREVIOUS, connection);
}
return null;
Expand Down
Loading