Migrate core/rendered_connection.js to named requires

This commit is contained in:
Aaron Dodson
2021-07-26 10:38:47 -07:00
parent 07b2e07ba8
commit c9225da3f3
2 changed files with 72 additions and 69 deletions

View File

@@ -13,26 +13,29 @@
goog.module('Blockly.RenderedConnection'); goog.module('Blockly.RenderedConnection');
goog.module.declareLegacyNamespace(); goog.module.declareLegacyNamespace();
goog.require('Blockly.Connection'); /* eslint-disable-next-line no-unused-vars */
goog.require('Blockly.connectionTypes'); const Block = goog.requireType('Blockly.Block');
goog.require('Blockly.internalConstants'); /* eslint-disable-next-line no-unused-vars */
goog.require('Blockly.utils'); const BlockSvg = goog.requireType('Blockly.BlockSvg');
goog.require('Blockly.utils.Coordinate'); const Connection = goog.require('Blockly.Connection');
goog.require('Blockly.utils.deprecation'); /* eslint-disable-next-line no-unused-vars */
goog.require('Blockly.utils.dom'); const ConnectionDB = goog.requireType('Blockly.ConnectionDB');
goog.require('Blockly.utils.object'); const Coordinate = goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.Svg'); const Events = goog.require('Blockly.Events');
const Svg = goog.require('Blockly.utils.Svg');
goog.requireType('Blockly.Block'); const connectionTypes = goog.require('Blockly.connectionTypes');
goog.requireType('Blockly.BlockSvg'); const deprecation = goog.require('Blockly.utils.deprecation');
goog.requireType('Blockly.ConnectionDB'); const dom = goog.require('Blockly.utils.dom');
const internalConstants = goog.require('Blockly.internalConstants');
const object = goog.require('Blockly.utils.object');
const utils = goog.require('Blockly.utils');
/** /**
* Class for a connection between blocks that may be rendered on screen. * Class for a connection between blocks that may be rendered on screen.
* @param {!Blockly.BlockSvg} source The block establishing this connection. * @param {!BlockSvg} source The block establishing this connection.
* @param {number} type The type of the connection. * @param {number} type The type of the connection.
* @extends {Blockly.Connection} * @extends {Connection}
* @constructor * @constructor
*/ */
const RenderedConnection = function(source, type) { const RenderedConnection = function(source, type) {
@@ -40,7 +43,7 @@ const RenderedConnection = function(source, type) {
/** /**
* Connection database for connections of this type on the current workspace. * Connection database for connections of this type on the current workspace.
* @const {!Blockly.ConnectionDB} * @const {!ConnectionDB}
* @private * @private
*/ */
this.db_ = source.workspace.connectionDBList[type]; this.db_ = source.workspace.connectionDBList[type];
@@ -48,19 +51,19 @@ const RenderedConnection = function(source, type) {
/** /**
* Connection database for connections compatible with this type on the * Connection database for connections compatible with this type on the
* current workspace. * current workspace.
* @const {!Blockly.ConnectionDB} * @const {!ConnectionDB}
* @private * @private
*/ */
this.dbOpposite_ = this.dbOpposite_ =
source.workspace source.workspace
.connectionDBList[Blockly.internalConstants.OPPOSITE_TYPE[type]]; .connectionDBList[internalConstants.OPPOSITE_TYPE[type]];
/** /**
* Workspace units, (0, 0) is top left of block. * Workspace units, (0, 0) is top left of block.
* @type {!Blockly.utils.Coordinate} * @type {!Coordinate}
* @private * @private
*/ */
this.offsetInBlock_ = new Blockly.utils.Coordinate(0, 0); this.offsetInBlock_ = new Coordinate(0, 0);
/** /**
* Describes the state of this connection's tracked-ness. * Describes the state of this connection's tracked-ness.
@@ -75,7 +78,7 @@ const RenderedConnection = function(source, type) {
*/ */
this.targetConnection = null; this.targetConnection = null;
}; };
Blockly.utils.object.inherits(RenderedConnection, Blockly.Connection); object.inherits(RenderedConnection, Connection);
/** /**
* Enum for different kinds of tracked states. * Enum for different kinds of tracked states.
@@ -110,28 +113,28 @@ RenderedConnection.prototype.dispose = function() {
/** /**
* Get the source block for this connection. * Get the source block for this connection.
* @return {!Blockly.BlockSvg} The source block. * @return {!BlockSvg} The source block.
* @override * @override
*/ */
RenderedConnection.prototype.getSourceBlock = function() { RenderedConnection.prototype.getSourceBlock = function() {
return /** @type {!Blockly.BlockSvg} */ ( return /** @type {!BlockSvg} */ (
RenderedConnection.superClass_.getSourceBlock.call(this)); RenderedConnection.superClass_.getSourceBlock.call(this));
}; };
/** /**
* Returns the block that this connection connects to. * Returns the block that this connection connects to.
* @return {?Blockly.BlockSvg} The connected block or null if none is connected. * @return {?BlockSvg} The connected block or null if none is connected.
* @override * @override
*/ */
RenderedConnection.prototype.targetBlock = function() { RenderedConnection.prototype.targetBlock = function() {
return /** @type {Blockly.BlockSvg} */ ( return /** @type {BlockSvg} */ (
RenderedConnection.superClass_.targetBlock.call(this)); RenderedConnection.superClass_.targetBlock.call(this));
}; };
/** /**
* Returns the distance between this connection and another connection in * Returns the distance between this connection and another connection in
* workspace units. * workspace units.
* @param {!Blockly.Connection} otherConnection The other connection to measure * @param {!Connection} otherConnection The other connection to measure
* the distance to. * the distance to.
* @return {number} The distance between connections, in workspace units. * @return {number} The distance between connections, in workspace units.
*/ */
@@ -144,7 +147,7 @@ RenderedConnection.prototype.distanceFrom = function(otherConnection) {
/** /**
* Move the block(s) belonging to the connection to a point where they don't * Move the block(s) belonging to the connection to a point where they don't
* visually interfere with the specified connection. * visually interfere with the specified connection.
* @param {!Blockly.Connection} staticConnection The connection to move away * @param {!Connection} staticConnection The connection to move away
* from. * from.
* @package * @package
*/ */
@@ -175,21 +178,21 @@ RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) {
const selected = Blockly.selected == rootBlock; const selected = Blockly.selected == rootBlock;
selected || rootBlock.addSelect(); selected || rootBlock.addSelect();
let dx = let dx =
(staticConnection.x + Blockly.internalConstants.SNAP_RADIUS + (staticConnection.x + internalConstants.SNAP_RADIUS +
Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) -
this.x; this.x;
let dy = let dy =
(staticConnection.y + Blockly.internalConstants.SNAP_RADIUS + (staticConnection.y + internalConstants.SNAP_RADIUS +
Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) -
this.y; this.y;
if (reverse) { if (reverse) {
// When reversing a bump due to an uneditable block, bump up. // When reversing a bump due to an uneditable block, bump up.
dy = -dy; dy = -dy;
} }
if (rootBlock.RTL) { if (rootBlock.RTL) {
dx = (staticConnection.x - Blockly.internalConstants.SNAP_RADIUS - dx = (staticConnection.x - internalConstants.SNAP_RADIUS -
Math.floor( Math.floor(
Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - Math.random() * internalConstants.BUMP_RANDOMNESS)) -
this.x; this.x;
} }
rootBlock.moveBy(dx, dy); rootBlock.moveBy(dx, dy);
@@ -226,7 +229,7 @@ RenderedConnection.prototype.moveBy = function(dx, dy) {
/** /**
* Move this connection to the location given by its offset within the block and * Move this connection to the location given by its offset within the block and
* the location of the block's top left corner. * the location of the block's top left corner.
* @param {!Blockly.utils.Coordinate} blockTL The location of the top left * @param {!Coordinate} blockTL The location of the top left
* corner of the block, in workspace coordinates. * corner of the block, in workspace coordinates.
*/ */
RenderedConnection.prototype.moveToOffset = function(blockTL) { RenderedConnection.prototype.moveToOffset = function(blockTL) {
@@ -246,7 +249,7 @@ RenderedConnection.prototype.setOffsetInBlock = function(x, y) {
/** /**
* Get the offset of this connection relative to the top left of its block. * Get the offset of this connection relative to the top left of its block.
* @return {!Blockly.utils.Coordinate} The offset of the connection. * @return {!Coordinate} The offset of the connection.
* @package * @package
*/ */
RenderedConnection.prototype.getOffsetInBlock = function() { RenderedConnection.prototype.getOffsetInBlock = function() {
@@ -267,7 +270,7 @@ RenderedConnection.prototype.tighten = function() {
throw Error('block is not rendered.'); throw Error('block is not rendered.');
} }
// Workspace coordinates. // Workspace coordinates.
const xy = Blockly.utils.getRelativeXY(svgRoot); const xy = utils.getRelativeXY(svgRoot);
block.getSvgRoot().setAttribute('transform', block.getSvgRoot().setAttribute('transform',
'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')');
block.moveConnections(-dx, -dy); block.moveConnections(-dx, -dy);
@@ -278,9 +281,9 @@ RenderedConnection.prototype.tighten = function() {
* Find the closest compatible connection to this connection. * Find the closest compatible connection to this connection.
* All parameters are in workspace units. * All parameters are in workspace units.
* @param {number} maxLimit The maximum radius to another connection. * @param {number} maxLimit The maximum radius to another connection.
* @param {!Blockly.utils.Coordinate} dxy Offset between this connection's location * @param {!Coordinate} dxy Offset between this connection's location
* in the database and the current location (as a result of dragging). * in the database and the current location (as a result of dragging).
* @return {!{connection: ?Blockly.Connection, radius: number}} Contains two * @return {!{connection: ?Connection, radius: number}} Contains two
* properties: 'connection' which is either another connection or null, * properties: 'connection' which is either another connection or null,
* and 'radius' which is the distance. * and 'radius' which is the distance.
*/ */
@@ -293,31 +296,31 @@ RenderedConnection.prototype.closest = function(maxLimit, dxy) {
*/ */
RenderedConnection.prototype.highlight = function() { RenderedConnection.prototype.highlight = function() {
let steps; let steps;
const sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); const sourceBlockSvg = /** @type {!BlockSvg} */ (this.sourceBlock_);
const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants();
const shape = renderConstants.shapeFor(this); const shape = renderConstants.shapeFor(this);
if (this.type == Blockly.connectionTypes.INPUT_VALUE || if (this.type == connectionTypes.INPUT_VALUE ||
this.type == Blockly.connectionTypes.OUTPUT_VALUE) { this.type == connectionTypes.OUTPUT_VALUE) {
// Vertical line, puzzle tab, vertical line. // Vertical line, puzzle tab, vertical line.
const yLen = renderConstants.TAB_OFFSET_FROM_TOP; const yLen = renderConstants.TAB_OFFSET_FROM_TOP;
steps = Blockly.utils.svgPaths.moveBy(0, -yLen) + steps = utils.svgPaths.moveBy(0, -yLen) +
Blockly.utils.svgPaths.lineOnAxis('v', yLen) + utils.svgPaths.lineOnAxis('v', yLen) +
shape.pathDown + shape.pathDown +
Blockly.utils.svgPaths.lineOnAxis('v', yLen); utils.svgPaths.lineOnAxis('v', yLen);
} else { } else {
const xLen = const xLen =
renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS;
// Horizontal line, notch, horizontal line. // Horizontal line, notch, horizontal line.
steps = Blockly.utils.svgPaths.moveBy(-xLen, 0) + steps = utils.svgPaths.moveBy(-xLen, 0) +
Blockly.utils.svgPaths.lineOnAxis('h', xLen) + utils.svgPaths.lineOnAxis('h', xLen) +
shape.pathLeft + shape.pathLeft +
Blockly.utils.svgPaths.lineOnAxis('h', xLen); utils.svgPaths.lineOnAxis('h', xLen);
} }
const xy = this.sourceBlock_.getRelativeToSurfaceXY(); const xy = this.sourceBlock_.getRelativeToSurfaceXY();
const x = this.x - xy.x; const x = this.x - xy.x;
const y = this.y - xy.y; const y = this.y - xy.y;
Blockly.Connection.highlightedPath_ = Blockly.utils.dom.createSvgElement( Connection.highlightedPath_ = dom.createSvgElement(
Blockly.utils.Svg.PATH, Svg.PATH,
{ {
'class': 'blocklyHighlightedConnectionPath', 'class': 'blocklyHighlightedConnectionPath',
'd': steps, 'd': steps,
@@ -331,8 +334,8 @@ RenderedConnection.prototype.highlight = function() {
* Remove the highlighting around this connection. * Remove the highlighting around this connection.
*/ */
RenderedConnection.prototype.unhighlight = function() { RenderedConnection.prototype.unhighlight = function() {
Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_); dom.removeNode(Connection.highlightedPath_);
delete Blockly.Connection.highlightedPath_; delete Connection.highlightedPath_;
}; };
/** /**
@@ -393,7 +396,7 @@ RenderedConnection.prototype.stopTrackingAll = function() {
/** /**
* Start tracking this connection, as well as all down-stream connections on * Start tracking this connection, as well as all down-stream connections on
* any block attached to this connection. This happens when a block is expanded. * any block attached to this connection. This happens when a block is expanded.
* @return {!Array<!Blockly.Block>} List of blocks to render. * @return {!Array<!Block>} List of blocks to render.
*/ */
RenderedConnection.prototype.startTrackingAll = function() { RenderedConnection.prototype.startTrackingAll = function() {
this.setTracking(true); this.setTracking(true);
@@ -402,8 +405,8 @@ 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.
const renderList = []; const renderList = [];
if (this.type != Blockly.connectionTypes.INPUT_VALUE && if (this.type != connectionTypes.INPUT_VALUE &&
this.type != Blockly.connectionTypes.NEXT_STATEMENT) { this.type != connectionTypes.NEXT_STATEMENT) {
// Only spider down. // Only spider down.
return renderList; return renderList;
} }
@@ -433,7 +436,7 @@ RenderedConnection.prototype.startTrackingAll = function() {
/** /**
* Check if the two connections can be dragged to connect to each other. * Check if the two connections can be dragged to connect to each other.
* @param {!Blockly.Connection} candidate A nearby connection to check. * @param {!Connection} candidate A nearby connection to check.
* @param {number=} maxRadius The maximum radius allowed for connections, in * @param {number=} maxRadius The maximum radius allowed for connections, in
* workspace units. * workspace units.
* @return {boolean} True if the connection is allowed, false otherwise. * @return {boolean} True if the connection is allowed, false otherwise.
@@ -441,7 +444,7 @@ RenderedConnection.prototype.startTrackingAll = function() {
*/ */
RenderedConnection.prototype.isConnectionAllowed = function(candidate, RenderedConnection.prototype.isConnectionAllowed = function(candidate,
maxRadius) { maxRadius) {
Blockly.utils.deprecation.warn( deprecation.warn(
'RenderedConnection.prototype.isConnectionAllowed', 'RenderedConnection.prototype.isConnectionAllowed',
'July 2020', 'July 2020',
'July 2021', 'July 2021',
@@ -458,30 +461,30 @@ RenderedConnection.prototype.isConnectionAllowed = function(candidate,
* Behavior after a connection attempt fails. * Behavior after a connection attempt fails.
* Bumps this connection away from the other connection. Called when an * Bumps this connection away from the other connection. Called when an
* attempted connection fails. * attempted connection fails.
* @param {!Blockly.Connection} otherConnection Connection that this connection * @param {!Connection} otherConnection Connection that this connection
* failed to connect to. * failed to connect to.
* @package * @package
*/ */
RenderedConnection.prototype.onFailedConnect = RenderedConnection.prototype.onFailedConnect =
function(otherConnection) { function(otherConnection) {
const block = this.getSourceBlock(); const block = this.getSourceBlock();
if (Blockly.Events.recordUndo) { if (Events.recordUndo) {
const group = Blockly.Events.getGroup(); const group = Events.getGroup();
setTimeout(function() { setTimeout(function() {
if (!block.isDisposed() && !block.getParent()) { if (!block.isDisposed() && !block.getParent()) {
Blockly.Events.setGroup(group); Events.setGroup(group);
this.bumpAwayFrom(otherConnection); this.bumpAwayFrom(otherConnection);
Blockly.Events.setGroup(false); Events.setGroup(false);
} }
}.bind(this), Blockly.internalConstants.BUMP_DELAY); }.bind(this), internalConstants.BUMP_DELAY);
} }
}; };
/** /**
* Disconnect two blocks that are connected by this connection. * Disconnect two blocks that are connected by this connection.
* @param {!Blockly.Block} parentBlock The superior block. * @param {!Block} parentBlock The superior block.
* @param {!Blockly.Block} childBlock The inferior block. * @param {!Block} childBlock The inferior block.
* @protected * @protected
* @override * @override
*/ */
@@ -528,7 +531,7 @@ RenderedConnection.prototype.respawnShadow_ = function() {
* Type checking does not apply, since this function is used for bumping. * Type checking does not apply, since this function is used for bumping.
* @param {number} maxLimit The maximum radius to another connection, in * @param {number} maxLimit The maximum radius to another connection, in
* workspace units. * workspace units.
* @return {!Array<!Blockly.Connection>} List of connections. * @return {!Array<!Connection>} List of connections.
* @package * @package
*/ */
RenderedConnection.prototype.neighbours = function(maxLimit) { RenderedConnection.prototype.neighbours = function(maxLimit) {
@@ -538,7 +541,7 @@ RenderedConnection.prototype.neighbours = function(maxLimit) {
/** /**
* Connect two connections together. This is the connection on the superior * Connect two connections together. This is the connection on the superior
* block. Rerender blocks as needed. * block. Rerender blocks as needed.
* @param {!Blockly.Connection} childConnection Connection on inferior block. * @param {!Connection} childConnection Connection on inferior block.
* @protected * @protected
*/ */
RenderedConnection.prototype.connect_ = function(childConnection) { RenderedConnection.prototype.connect_ = function(childConnection) {
@@ -557,8 +560,8 @@ RenderedConnection.prototype.connect_ = function(childConnection) {
childBlock.updateDisabled(); childBlock.updateDisabled();
} }
if (parentRendered && childRendered) { if (parentRendered && childRendered) {
if (parentConnection.type == Blockly.connectionTypes.NEXT_STATEMENT || if (parentConnection.type == connectionTypes.NEXT_STATEMENT ||
parentConnection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { parentConnection.type == 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

@@ -118,7 +118,7 @@ goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme
goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']);
goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.xml']); goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.xml']);
goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []);
goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.Events', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']);
goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'});
goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'});