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 all 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 @@ -18,6 +18,7 @@ const Blocks = goog.require('Blockly.Blocks');
/* eslint-disable-next-line no-unused-vars */
const Comment = goog.requireType('Blockly.Comment');
const Connection = goog.require('Blockly.Connection');
const ConnectionType = goog.require('Blockly.ConnectionType');
const Coordinate = goog.require('Blockly.utils.Coordinate');
const Events = goog.require('Blockly.Events');
const Extensions = goog.require('Blockly.Extensions');
Expand All @@ -37,7 +38,6 @@ const VariableModel = goog.requireType('Blockly.VariableModel');
/* eslint-disable-next-line no-unused-vars */
const Workspace = goog.requireType('Blockly.Workspace');
const common = goog.require('Blockly.common');
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 @@ -524,7 +524,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 == ConnectionType.INPUT_VALUE &&
thisConnection.targetConnection) {
if (connection) {
return null; // More than one value input found.
Expand Down Expand Up @@ -689,7 +689,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 == ConnectionType.NEXT_STATEMENT) {
return input.connection;
}
}
Expand Down Expand Up @@ -1187,7 +1187,7 @@ Block.prototype.setPreviousStatement = function(newBoolean, opt_check) {
'connection.');
}
this.previousConnection =
this.makeConnection_(connectionTypes.PREVIOUS_STATEMENT);
this.makeConnection_(ConnectionType.PREVIOUS_STATEMENT);
}
this.previousConnection.setCheck(opt_check);
} else {
Expand Down Expand Up @@ -1216,7 +1216,7 @@ Block.prototype.setNextStatement = function(newBoolean, opt_check) {
}
if (!this.nextConnection) {
this.nextConnection =
this.makeConnection_(connectionTypes.NEXT_STATEMENT);
this.makeConnection_(ConnectionType.NEXT_STATEMENT);
}
this.nextConnection.setCheck(opt_check);
} else {
Expand Down Expand Up @@ -1251,7 +1251,7 @@ Block.prototype.setOutput = function(newBoolean, opt_check) {
'connection.');
}
this.outputConnection =
this.makeConnection_(connectionTypes.OUTPUT_VALUE);
this.makeConnection_(ConnectionType.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 @@ -57,7 +57,7 @@ const blockAnimations = goog.require('Blockly.blockAnimations');
const blocks = goog.require('Blockly.serialization.blocks');
const browserEvents = goog.require('Blockly.browserEvents');
const common = goog.require('Blockly.common');
const connectionTypes = goog.require('Blockly.connectionTypes');
const ConnectionType = goog.require('Blockly.ConnectionType');
const constants = goog.require('Blockly.constants');
const dom = goog.require('Blockly.utils.dom');
const internalConstants = goog.require('Blockly.internalConstants');
Expand Down Expand Up @@ -1597,8 +1597,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 == ConnectionType.NEXT_STATEMENT ||
sourceConnection.type == ConnectionType.INPUT_VALUE) {
const dx = targetConnection.x - sourceConnection.x;
const dy = targetConnection.y - sourceConnection.y;

Expand Down
22 changes: 12 additions & 10 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const ComponentManager = goog.require('Blockly.ComponentManager');
const ConnectionChecker = goog.require('Blockly.ConnectionChecker');
const ConnectionDB = goog.require('Blockly.ConnectionDB');
const Connection = goog.require('Blockly.Connection');
const ConnectionType = goog.require('Blockly.ConnectionType');
const ContextMenu = goog.require('Blockly.ContextMenu');
const ContextMenuItems = goog.require('Blockly.ContextMenuItems');
const ContextMenuRegistry = goog.require('Blockly.ContextMenuRegistry');
Expand Down Expand Up @@ -108,7 +109,6 @@ const bumpObjects = goog.require('Blockly.bumpObjects');
const clipboard = goog.require('Blockly.clipboard');
const colour = goog.require('Blockly.utils.colour');
const common = goog.require('Blockly.common');
const connectionTypes = goog.require('Blockly.connectionTypes');
const constants = goog.require('Blockly.constants');
const deprecation = goog.require('Blockly.utils.deprecation');
const dialog = goog.require('Blockly.dialog');
Expand Down Expand Up @@ -421,24 +421,24 @@ exports.ALIGN_RIGHT = constants.ALIGN.RIGHT;
*/

/**
* @see connectionTypes.INPUT_VALUE
* @see ConnectionType.INPUT_VALUE
*/
exports.INPUT_VALUE = connectionTypes.INPUT_VALUE;
exports.INPUT_VALUE = ConnectionType.INPUT_VALUE;

/**
* @see connectionTypes.OUTPUT_VALUE
* @see ConnectionType.OUTPUT_VALUE
*/
exports.OUTPUT_VALUE = connectionTypes.OUTPUT_VALUE;
exports.OUTPUT_VALUE = ConnectionType.OUTPUT_VALUE;

/**
* @see connectionTypes.NEXT_STATEMENT
* @see ConnectionType.NEXT_STATEMENT
*/
exports.NEXT_STATEMENT = connectionTypes.NEXT_STATEMENT;
exports.NEXT_STATEMENT = ConnectionType.NEXT_STATEMENT;

/**
* @see connectionTypes.PREVIOUS_STATEMENT
* @see ConnectionType.PREVIOUS_STATEMENT
*/
exports.PREVIOUS_STATEMENT = connectionTypes.PREVIOUS_STATEMENT;
exports.PREVIOUS_STATEMENT = ConnectionType.PREVIOUS_STATEMENT;

/**
* @see inputTypes.DUMMY_INPUT
Expand Down Expand Up @@ -514,6 +514,7 @@ exports.CollapsibleToolboxCategory = CollapsibleToolboxCategory;
exports.Comment = Comment;
exports.ComponentManager = ComponentManager;
exports.Connection = Connection;
exports.ConnectionType = ConnectionType;
exports.ConnectionChecker = ConnectionChecker;
exports.ConnectionDB = ConnectionDB;
exports.ContextMenu = ContextMenu;
Expand Down Expand Up @@ -594,7 +595,8 @@ exports.browserEvents = browserEvents;
exports.bumpObjects = bumpObjects;
exports.clipboard = clipboard;
exports.common = common;
exports.connectionTypes = connectionTypes;
/** @deprecated Use Blockly.ConnectionType instead. */
exports.connectionTypes = ConnectionType;
exports.constants = constants;
exports.dialog = dialog;
exports.fieldRegistry = fieldRegistry;
Expand Down
14 changes: 7 additions & 7 deletions core/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

goog.module('Blockly.Connection');

const ConnectionType = goog.require('Blockly.ConnectionType');
const Events = goog.require('Blockly.Events');
/* eslint-disable-next-line no-unused-vars */
const IASTNodeLocationWithBlock = goog.requireType('Blockly.IASTNodeLocationWithBlock');
Expand All @@ -21,7 +22,6 @@ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker');
const Input = goog.requireType('Blockly.Input');
const Xml = goog.require('Blockly.Xml');
const blocks = goog.require('Blockly.serialization.blocks');
const connectionTypes = goog.require('Blockly.connectionTypes');
const deprecation = goog.require('Blockly.utils.deprecation');
/* eslint-disable-next-line no-unused-vars */
const {Block} = goog.requireType('Blockly.Block');
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 = ConnectionType.INPUT_VALUE;
const parentConnection = this;
const parentBlock = parentConnection.getSourceBlock();
const childBlock = childConnection.getSourceBlock();
Expand Down Expand Up @@ -193,8 +193,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 == ConnectionType.INPUT_VALUE ||
this.type == ConnectionType.NEXT_STATEMENT;
};

/**
Expand Down Expand Up @@ -386,7 +386,7 @@ const getConnectionForOrphanedOutput = function(startBlock, orphanBlock) {
*/
Connection.getConnectionForOrphanedConnection = function(
startBlock, orphanConnection) {
if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) {
if (orphanConnection.type === ConnectionType.OUTPUT_VALUE) {
return getConnectionForOrphanedOutput(
startBlock, orphanConnection.getSourceBlock());
}
Expand Down Expand Up @@ -770,14 +770,14 @@ Connection.prototype.createShadowBlock_ = function(attemptToConnect) {
if (shadowDom) {
blockShadow = Xml.domToBlock(shadowDom, parentBlock.workspace);
if (attemptToConnect) {
if (this.type == connectionTypes.INPUT_VALUE) {
if (this.type == ConnectionType.INPUT_VALUE) {
if (!blockShadow.outputConnection) {
throw new Error('Shadow block is missing an output connection');
}
if (!this.connect(blockShadow.outputConnection)) {
throw new Error('Could not connect shadow block to connection');
}
} else if (this.type == connectionTypes.NEXT_STATEMENT) {
} else if (this.type == ConnectionType.NEXT_STATEMENT) {
if (!blockShadow.previousConnection) {
throw new Error('Shadow block is missing previous connection');
}
Expand Down
10 changes: 5 additions & 5 deletions core/connection_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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 ConnectionType = goog.require('Blockly.ConnectionType');
const internalConstants = goog.require('Blockly.internalConstants');
const registry = goog.require('Blockly.registry');

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

switch (b.type) {
case connectionTypes.PREVIOUS_STATEMENT:
case ConnectionType.PREVIOUS_STATEMENT:
return this.canConnectToPrevious_(a, b);
case connectionTypes.OUTPUT_VALUE: {
case ConnectionType.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 @@ -212,7 +212,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
}
break;
}
case connectionTypes.INPUT_VALUE: {
case ConnectionType.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 @@ -222,7 +222,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
}
break;
}
case connectionTypes.NEXT_STATEMENT: {
case ConnectionType.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 @@ -20,7 +20,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 ConnectionType = goog.require('Blockly.ConnectionType');
/** @suppress {extraRequire} */
goog.require('Blockly.constants');

Expand Down Expand Up @@ -293,10 +293,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[ConnectionType.INPUT_VALUE] = new ConnectionDB(checker);
dbList[ConnectionType.OUTPUT_VALUE] = new ConnectionDB(checker);
dbList[ConnectionType.NEXT_STATEMENT] = new ConnectionDB(checker);
dbList[ConnectionType.PREVIOUS_STATEMENT] = new ConnectionDB(checker);
return dbList;
};

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

'use strict';

goog.module('Blockly.connectionTypes');
goog.module('Blockly.ConnectionType');


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

exports = connectionTypes;
exports = ConnectionType;
4 changes: 2 additions & 2 deletions core/events/events_block_move.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ goog.module.declareLegacyNamespace();
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 ConnectionType = goog.require('Blockly.ConnectionType');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
/* eslint-disable-next-line no-unused-vars */
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 == ConnectionType.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 @@ -13,17 +13,17 @@

goog.module('Blockly.inputTypes');

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

/**
* 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: ConnectionType.INPUT_VALUE,
// A down-facing block stack. E.g. 'if-do' or 'else'.
STATEMENT: connectionTypes.NEXT_STATEMENT,
STATEMENT: ConnectionType.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 @@ -13,6 +13,7 @@
goog.module('Blockly.InsertionMarkerManager');

const ComponentManager = goog.require('Blockly.ComponentManager');
const ConnectionType = goog.require('Blockly.ConnectionType');
/* eslint-disable-next-line no-unused-vars */
const Coordinate = goog.requireType('Blockly.utils.Coordinate');
const Events = goog.require('Blockly.Events');
Expand All @@ -26,7 +27,6 @@ const RenderedConnection = goog.requireType('Blockly.RenderedConnection');
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
const blockAnimations = goog.require('Blockly.blockAnimations');
const common = goog.require('Blockly.common');
const connectionTypes = goog.require('Blockly.connectionTypes');
const constants = goog.require('Blockly.constants');
const internalConstants = goog.require('Blockly.internalConstants');
/* eslint-disable-next-line no-unused-vars */
Expand Down Expand Up @@ -660,7 +660,7 @@ InsertionMarkerManager.prototype.hideInsertionMarker_ = function() {
const isFirstInStatementStack =
(imConn == markerNext && !(markerPrev && markerPrev.targetConnection));

const isFirstInOutputStack = imConn.type == connectionTypes.INPUT_VALUE &&
const isFirstInOutputStack = imConn.type == ConnectionType.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 @@ -669,7 +669,7 @@ InsertionMarkerManager.prototype.hideInsertionMarker_ = function() {
}
// Inside of a C-block, first statement connection.
else if (
imConn.type == connectionTypes.NEXT_STATEMENT && imConn != markerNext) {
imConn.type == ConnectionType.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 @@ -14,7 +14,7 @@

goog.module('Blockly.internalConstants');

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


/**
Expand Down Expand Up @@ -162,12 +162,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[ConnectionType.INPUT_VALUE] = ConnectionType.OUTPUT_VALUE;
OPPOSITE_TYPE[ConnectionType.OUTPUT_VALUE] = ConnectionType.INPUT_VALUE;
OPPOSITE_TYPE[ConnectionType.NEXT_STATEMENT] =
ConnectionType.PREVIOUS_STATEMENT;
OPPOSITE_TYPE[ConnectionType.PREVIOUS_STATEMENT] =
ConnectionType.NEXT_STATEMENT;

exports.OPPOSITE_TYPE = OPPOSITE_TYPE;

Expand Down
Loading