mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Merge pull request #5218 from gonfunko/rendered_connection
Migrate core/rendered_connection.js to goog.module syntax
This commit is contained in:
@@ -10,36 +10,40 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.RenderedConnection');
|
||||
goog.module('Blockly.RenderedConnection');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
goog.require('Blockly.Connection');
|
||||
goog.require('Blockly.connectionTypes');
|
||||
goog.require('Blockly.internalConstants');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.Coordinate');
|
||||
goog.require('Blockly.utils.deprecation');
|
||||
goog.require('Blockly.utils.dom');
|
||||
goog.require('Blockly.utils.object');
|
||||
goog.require('Blockly.utils.Svg');
|
||||
|
||||
goog.requireType('Blockly.Block');
|
||||
goog.requireType('Blockly.BlockSvg');
|
||||
goog.requireType('Blockly.ConnectionDB');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const Block = goog.requireType('Blockly.Block');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const BlockSvg = goog.requireType('Blockly.BlockSvg');
|
||||
const Connection = goog.require('Blockly.Connection');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const ConnectionDB = goog.requireType('Blockly.ConnectionDB');
|
||||
const Coordinate = goog.require('Blockly.utils.Coordinate');
|
||||
const Events = goog.require('Blockly.Events');
|
||||
const Svg = goog.require('Blockly.utils.Svg');
|
||||
const connectionTypes = goog.require('Blockly.connectionTypes');
|
||||
const deprecation = goog.require('Blockly.utils.deprecation');
|
||||
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.
|
||||
* @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.
|
||||
* @extends {Blockly.Connection}
|
||||
* @extends {Connection}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.RenderedConnection = function(source, type) {
|
||||
Blockly.RenderedConnection.superClass_.constructor.call(this, source, type);
|
||||
const RenderedConnection = function(source, type) {
|
||||
RenderedConnection.superClass_.constructor.call(this, source, type);
|
||||
|
||||
/**
|
||||
* Connection database for connections of this type on the current workspace.
|
||||
* @const {!Blockly.ConnectionDB}
|
||||
* @const {!ConnectionDB}
|
||||
* @private
|
||||
*/
|
||||
this.db_ = source.workspace.connectionDBList[type];
|
||||
@@ -47,34 +51,33 @@ Blockly.RenderedConnection = function(source, type) {
|
||||
/**
|
||||
* Connection database for connections compatible with this type on the
|
||||
* current workspace.
|
||||
* @const {!Blockly.ConnectionDB}
|
||||
* @const {!ConnectionDB}
|
||||
* @private
|
||||
*/
|
||||
this.dbOpposite_ =
|
||||
source.workspace
|
||||
.connectionDBList[Blockly.internalConstants.OPPOSITE_TYPE[type]];
|
||||
source.workspace.connectionDBList[internalConstants.OPPOSITE_TYPE[type]];
|
||||
|
||||
/**
|
||||
* Workspace units, (0, 0) is top left of block.
|
||||
* @type {!Blockly.utils.Coordinate}
|
||||
* @type {!Coordinate}
|
||||
* @private
|
||||
*/
|
||||
this.offsetInBlock_ = new Blockly.utils.Coordinate(0, 0);
|
||||
this.offsetInBlock_ = new Coordinate(0, 0);
|
||||
|
||||
/**
|
||||
* Describes the state of this connection's tracked-ness.
|
||||
* @type {Blockly.RenderedConnection.TrackedState}
|
||||
* @type {RenderedConnection.TrackedState}
|
||||
* @private
|
||||
*/
|
||||
this.trackedState_ = Blockly.RenderedConnection.TrackedState.WILL_TRACK;
|
||||
this.trackedState_ = RenderedConnection.TrackedState.WILL_TRACK;
|
||||
|
||||
/**
|
||||
* Connection this connection connects to. Null if not connected.
|
||||
* @type {Blockly.RenderedConnection}
|
||||
* @type {RenderedConnection}
|
||||
*/
|
||||
this.targetConnection = null;
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection);
|
||||
object.inherits(RenderedConnection, Connection);
|
||||
|
||||
/**
|
||||
* Enum for different kinds of tracked states.
|
||||
@@ -88,7 +91,7 @@ Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection);
|
||||
* TRACKED means that this connection is currently being tracked.
|
||||
* @enum {number}
|
||||
*/
|
||||
Blockly.RenderedConnection.TrackedState = {
|
||||
RenderedConnection.TrackedState = {
|
||||
WILL_TRACK: -1,
|
||||
UNTRACKED: 0,
|
||||
TRACKED: 1
|
||||
@@ -100,65 +103,65 @@ Blockly.RenderedConnection.TrackedState = {
|
||||
* @override
|
||||
* @package
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.dispose = function() {
|
||||
Blockly.RenderedConnection.superClass_.dispose.call(this);
|
||||
if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.TRACKED) {
|
||||
RenderedConnection.prototype.dispose = function() {
|
||||
RenderedConnection.superClass_.dispose.call(this);
|
||||
if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) {
|
||||
this.db_.removeConnection(this, this.y);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the source block for this connection.
|
||||
* @return {!Blockly.BlockSvg} The source block.
|
||||
* @return {!BlockSvg} The source block.
|
||||
* @override
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.getSourceBlock = function() {
|
||||
return /** @type {!Blockly.BlockSvg} */ (
|
||||
Blockly.RenderedConnection.superClass_.getSourceBlock.call(this));
|
||||
RenderedConnection.prototype.getSourceBlock = function() {
|
||||
return /** @type {!BlockSvg} */ (
|
||||
RenderedConnection.superClass_.getSourceBlock.call(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.targetBlock = function() {
|
||||
return /** @type {Blockly.BlockSvg} */ (
|
||||
Blockly.RenderedConnection.superClass_.targetBlock.call(this));
|
||||
RenderedConnection.prototype.targetBlock = function() {
|
||||
return /** @type {BlockSvg} */ (
|
||||
RenderedConnection.superClass_.targetBlock.call(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the distance between this connection and another connection in
|
||||
* workspace units.
|
||||
* @param {!Blockly.Connection} otherConnection The other connection to measure
|
||||
* @param {!Connection} otherConnection The other connection to measure
|
||||
* the distance to.
|
||||
* @return {number} The distance between connections, in workspace units.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) {
|
||||
var xDiff = this.x - otherConnection.x;
|
||||
var yDiff = this.y - otherConnection.y;
|
||||
RenderedConnection.prototype.distanceFrom = function(otherConnection) {
|
||||
const xDiff = this.x - otherConnection.x;
|
||||
const yDiff = this.y - otherConnection.y;
|
||||
return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
||||
};
|
||||
|
||||
/**
|
||||
* Move the block(s) belonging to the connection to a point where they don't
|
||||
* visually interfere with the specified connection.
|
||||
* @param {!Blockly.Connection} staticConnection The connection to move away
|
||||
* @param {!Connection} staticConnection The connection to move away
|
||||
* from.
|
||||
* @package
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) {
|
||||
RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) {
|
||||
if (this.sourceBlock_.workspace.isDragging()) {
|
||||
// Don't move blocks around while the user is doing the same.
|
||||
return;
|
||||
}
|
||||
// Move the root block.
|
||||
var rootBlock = this.sourceBlock_.getRootBlock();
|
||||
let rootBlock = this.sourceBlock_.getRootBlock();
|
||||
if (rootBlock.isInFlyout) {
|
||||
// Don't move blocks around in a flyout.
|
||||
return;
|
||||
}
|
||||
var reverse = false;
|
||||
let reverse = false;
|
||||
if (!rootBlock.isMovable()) {
|
||||
// Can't bump an uneditable block away.
|
||||
// Check to see if the other block is movable.
|
||||
@@ -171,24 +174,21 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) {
|
||||
reverse = true;
|
||||
}
|
||||
// Raise it to the top for extra visibility.
|
||||
var selected = Blockly.selected == rootBlock;
|
||||
const selected = Blockly.selected == rootBlock;
|
||||
selected || rootBlock.addSelect();
|
||||
var dx =
|
||||
(staticConnection.x + Blockly.internalConstants.SNAP_RADIUS +
|
||||
Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) -
|
||||
let dx = (staticConnection.x + internalConstants.SNAP_RADIUS +
|
||||
Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) -
|
||||
this.x;
|
||||
var dy =
|
||||
(staticConnection.y + Blockly.internalConstants.SNAP_RADIUS +
|
||||
Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) -
|
||||
let dy = (staticConnection.y + internalConstants.SNAP_RADIUS +
|
||||
Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) -
|
||||
this.y;
|
||||
if (reverse) {
|
||||
// When reversing a bump due to an uneditable block, bump up.
|
||||
dy = -dy;
|
||||
}
|
||||
if (rootBlock.RTL) {
|
||||
dx = (staticConnection.x - Blockly.internalConstants.SNAP_RADIUS -
|
||||
Math.floor(
|
||||
Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) -
|
||||
dx = (staticConnection.x - internalConstants.SNAP_RADIUS -
|
||||
Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) -
|
||||
this.x;
|
||||
}
|
||||
rootBlock.moveBy(dx, dy);
|
||||
@@ -200,12 +200,11 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) {
|
||||
* @param {number} x New absolute x coordinate, in workspace coordinates.
|
||||
* @param {number} y New absolute y coordinate, in workspace coordinates.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.moveTo = function(x, y) {
|
||||
if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.WILL_TRACK) {
|
||||
RenderedConnection.prototype.moveTo = function(x, y) {
|
||||
if (this.trackedState_ == RenderedConnection.TrackedState.WILL_TRACK) {
|
||||
this.db_.addConnection(this, y);
|
||||
this.trackedState_ = Blockly.RenderedConnection.TrackedState.TRACKED;
|
||||
} else if (this.trackedState_ == Blockly.RenderedConnection
|
||||
.TrackedState.TRACKED) {
|
||||
this.trackedState_ = RenderedConnection.TrackedState.TRACKED;
|
||||
} else if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) {
|
||||
this.db_.removeConnection(this, this.y);
|
||||
this.db_.addConnection(this, y);
|
||||
}
|
||||
@@ -218,19 +217,19 @@ Blockly.RenderedConnection.prototype.moveTo = function(x, y) {
|
||||
* @param {number} dx Change to x coordinate, in workspace units.
|
||||
* @param {number} dy Change to y coordinate, in workspace units.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.moveBy = function(dx, dy) {
|
||||
RenderedConnection.prototype.moveBy = function(dx, dy) {
|
||||
this.moveTo(this.x + dx, this.y + dy);
|
||||
};
|
||||
|
||||
/**
|
||||
* Move this connection to the location given by its offset within the block and
|
||||
* 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.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.moveToOffset = function(blockTL) {
|
||||
this.moveTo(blockTL.x + this.offsetInBlock_.x,
|
||||
blockTL.y + this.offsetInBlock_.y);
|
||||
RenderedConnection.prototype.moveToOffset = function(blockTL) {
|
||||
this.moveTo(
|
||||
blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -238,17 +237,17 @@ Blockly.RenderedConnection.prototype.moveToOffset = function(blockTL) {
|
||||
* @param {number} x The new relative x, in workspace units.
|
||||
* @param {number} y The new relative y, in workspace units.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.setOffsetInBlock = function(x, y) {
|
||||
RenderedConnection.prototype.setOffsetInBlock = function(x, y) {
|
||||
this.offsetInBlock_.x = x;
|
||||
this.offsetInBlock_.y = y;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.getOffsetInBlock = function() {
|
||||
RenderedConnection.prototype.getOffsetInBlock = function() {
|
||||
return this.offsetInBlock_;
|
||||
};
|
||||
|
||||
@@ -256,19 +255,19 @@ Blockly.RenderedConnection.prototype.getOffsetInBlock = function() {
|
||||
* Move the blocks on either side of this connection right next to each other.
|
||||
* @package
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.tighten = function() {
|
||||
var dx = this.targetConnection.x - this.x;
|
||||
var dy = this.targetConnection.y - this.y;
|
||||
RenderedConnection.prototype.tighten = function() {
|
||||
const dx = this.targetConnection.x - this.x;
|
||||
const dy = this.targetConnection.y - this.y;
|
||||
if (dx != 0 || dy != 0) {
|
||||
var block = this.targetBlock();
|
||||
var svgRoot = block.getSvgRoot();
|
||||
const block = this.targetBlock();
|
||||
const svgRoot = block.getSvgRoot();
|
||||
if (!svgRoot) {
|
||||
throw Error('block is not rendered.');
|
||||
}
|
||||
// Workspace coordinates.
|
||||
var xy = Blockly.utils.getRelativeXY(svgRoot);
|
||||
block.getSvgRoot().setAttribute('transform',
|
||||
'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')');
|
||||
const xy = utils.getRelativeXY(svgRoot);
|
||||
block.getSvgRoot().setAttribute(
|
||||
'transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')');
|
||||
block.moveConnections(-dx, -dy);
|
||||
}
|
||||
};
|
||||
@@ -277,47 +276,44 @@ Blockly.RenderedConnection.prototype.tighten = function() {
|
||||
* Find the closest compatible connection to this connection.
|
||||
* All parameters are in workspace units.
|
||||
* @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).
|
||||
* @return {!{connection: ?Blockly.Connection, radius: number}} Contains two
|
||||
* @return {!{connection: ?Connection, radius: number}} Contains two
|
||||
* properties: 'connection' which is either another connection or null,
|
||||
* and 'radius' which is the distance.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.closest = function(maxLimit, dxy) {
|
||||
RenderedConnection.prototype.closest = function(maxLimit, dxy) {
|
||||
return this.dbOpposite_.searchForClosest(this, maxLimit, dxy);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add highlighting around this connection.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.highlight = function() {
|
||||
var steps;
|
||||
var sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_);
|
||||
var renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants();
|
||||
var shape = renderConstants.shapeFor(this);
|
||||
if (this.type == Blockly.connectionTypes.INPUT_VALUE ||
|
||||
this.type == Blockly.connectionTypes.OUTPUT_VALUE) {
|
||||
RenderedConnection.prototype.highlight = function() {
|
||||
let steps;
|
||||
const sourceBlockSvg = /** @type {!BlockSvg} */ (this.sourceBlock_);
|
||||
const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants();
|
||||
const shape = renderConstants.shapeFor(this);
|
||||
if (this.type == connectionTypes.INPUT_VALUE ||
|
||||
this.type == connectionTypes.OUTPUT_VALUE) {
|
||||
// Vertical line, puzzle tab, vertical line.
|
||||
var yLen = renderConstants.TAB_OFFSET_FROM_TOP;
|
||||
steps = Blockly.utils.svgPaths.moveBy(0, -yLen) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('v', yLen) +
|
||||
shape.pathDown +
|
||||
Blockly.utils.svgPaths.lineOnAxis('v', yLen);
|
||||
const yLen = renderConstants.TAB_OFFSET_FROM_TOP;
|
||||
steps = utils.svgPaths.moveBy(0, -yLen) +
|
||||
utils.svgPaths.lineOnAxis('v', yLen) + shape.pathDown +
|
||||
utils.svgPaths.lineOnAxis('v', yLen);
|
||||
} else {
|
||||
var xLen =
|
||||
const xLen =
|
||||
renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS;
|
||||
// Horizontal line, notch, horizontal line.
|
||||
steps = Blockly.utils.svgPaths.moveBy(-xLen, 0) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('h', xLen) +
|
||||
shape.pathLeft +
|
||||
Blockly.utils.svgPaths.lineOnAxis('h', xLen);
|
||||
steps = utils.svgPaths.moveBy(-xLen, 0) +
|
||||
utils.svgPaths.lineOnAxis('h', xLen) + shape.pathLeft +
|
||||
utils.svgPaths.lineOnAxis('h', xLen);
|
||||
}
|
||||
var xy = this.sourceBlock_.getRelativeToSurfaceXY();
|
||||
var x = this.x - xy.x;
|
||||
var y = this.y - xy.y;
|
||||
Blockly.Connection.highlightedPath_ = Blockly.utils.dom.createSvgElement(
|
||||
Blockly.utils.Svg.PATH,
|
||||
{
|
||||
const xy = this.sourceBlock_.getRelativeToSurfaceXY();
|
||||
const x = this.x - xy.x;
|
||||
const y = this.y - xy.y;
|
||||
Connection.highlightedPath_ = dom.createSvgElement(
|
||||
Svg.PATH, {
|
||||
'class': 'blocklyHighlightedConnectionPath',
|
||||
'd': steps,
|
||||
transform: 'translate(' + x + ',' + y + ')' +
|
||||
@@ -329,9 +325,9 @@ Blockly.RenderedConnection.prototype.highlight = function() {
|
||||
/**
|
||||
* Remove the highlighting around this connection.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.unhighlight = function() {
|
||||
Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_);
|
||||
delete Blockly.Connection.highlightedPath_;
|
||||
RenderedConnection.prototype.unhighlight = function() {
|
||||
dom.removeNode(Connection.highlightedPath_);
|
||||
delete Connection.highlightedPath_;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -339,11 +335,11 @@ Blockly.RenderedConnection.prototype.unhighlight = function() {
|
||||
* @param {boolean} doTracking If true, start tracking. If false, stop tracking.
|
||||
* @package
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.setTracking = function(doTracking) {
|
||||
if ((doTracking && this.trackedState_ ==
|
||||
Blockly.RenderedConnection.TrackedState.TRACKED) ||
|
||||
(!doTracking && this.trackedState_ ==
|
||||
Blockly.RenderedConnection.TrackedState.UNTRACKED)) {
|
||||
RenderedConnection.prototype.setTracking = function(doTracking) {
|
||||
if ((doTracking &&
|
||||
this.trackedState_ == RenderedConnection.TrackedState.TRACKED) ||
|
||||
(!doTracking &&
|
||||
this.trackedState_ == RenderedConnection.TrackedState.UNTRACKED)) {
|
||||
return;
|
||||
}
|
||||
if (this.sourceBlock_.isInFlyout) {
|
||||
@@ -352,13 +348,13 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) {
|
||||
}
|
||||
if (doTracking) {
|
||||
this.db_.addConnection(this, this.y);
|
||||
this.trackedState_ = Blockly.RenderedConnection.TrackedState.TRACKED;
|
||||
this.trackedState_ = RenderedConnection.TrackedState.TRACKED;
|
||||
return;
|
||||
}
|
||||
if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.TRACKED) {
|
||||
if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) {
|
||||
this.db_.removeConnection(this, this.y);
|
||||
}
|
||||
this.trackedState_ = Blockly.RenderedConnection.TrackedState.UNTRACKED;
|
||||
this.trackedState_ = RenderedConnection.TrackedState.UNTRACKED;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -369,20 +365,20 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) {
|
||||
* Also closes down-stream icons/bubbles.
|
||||
* @package
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.stopTrackingAll = function() {
|
||||
RenderedConnection.prototype.stopTrackingAll = function() {
|
||||
this.setTracking(false);
|
||||
if (this.targetConnection) {
|
||||
var blocks = this.targetBlock().getDescendants(false);
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
var block = blocks[i];
|
||||
const blocks = this.targetBlock().getDescendants(false);
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
const block = blocks[i];
|
||||
// Stop tracking connections of all children.
|
||||
var connections = block.getConnections_(true);
|
||||
for (var j = 0; j < connections.length; j++) {
|
||||
const connections = block.getConnections_(true);
|
||||
for (let j = 0; j < connections.length; j++) {
|
||||
connections[j].setTracking(false);
|
||||
}
|
||||
// Close all bubbles of all children.
|
||||
var icons = block.getIcons();
|
||||
for (var j = 0; j < icons.length; j++) {
|
||||
const icons = block.getIcons();
|
||||
for (let j = 0; j < icons.length; j++) {
|
||||
icons[j].setVisible(false);
|
||||
}
|
||||
}
|
||||
@@ -392,23 +388,23 @@ Blockly.RenderedConnection.prototype.stopTrackingAll = function() {
|
||||
/**
|
||||
* 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.
|
||||
* @return {!Array<!Blockly.Block>} List of blocks to render.
|
||||
* @return {!Array<!Block>} List of blocks to render.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.startTrackingAll = function() {
|
||||
RenderedConnection.prototype.startTrackingAll = function() {
|
||||
this.setTracking(true);
|
||||
// All blocks that are not tracked must start tracking before any
|
||||
// rendering takes place, since rendering requires knowing the dimensions
|
||||
// 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.connectionTypes.INPUT_VALUE &&
|
||||
this.type != Blockly.connectionTypes.NEXT_STATEMENT) {
|
||||
const renderList = [];
|
||||
if (this.type != connectionTypes.INPUT_VALUE &&
|
||||
this.type != connectionTypes.NEXT_STATEMENT) {
|
||||
// Only spider down.
|
||||
return renderList;
|
||||
}
|
||||
var block = this.targetBlock();
|
||||
const block = this.targetBlock();
|
||||
if (block) {
|
||||
var connections;
|
||||
let connections;
|
||||
if (block.isCollapsed()) {
|
||||
// This block should only be partially revealed since it is collapsed.
|
||||
connections = [];
|
||||
@@ -419,7 +415,7 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() {
|
||||
// Show all connections of this block.
|
||||
connections = block.getConnections_(true);
|
||||
}
|
||||
for (var i = 0; i < connections.length; i++) {
|
||||
for (let i = 0; i < connections.length; i++) {
|
||||
renderList.push.apply(renderList, connections[i].startTrackingAll());
|
||||
}
|
||||
if (!renderList.length) {
|
||||
@@ -432,62 +428,60 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* workspace units.
|
||||
* @return {boolean} True if the connection is allowed, false otherwise.
|
||||
* @deprecated July 2020
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate,
|
||||
maxRadius) {
|
||||
Blockly.utils.deprecation.warn(
|
||||
'RenderedConnection.prototype.isConnectionAllowed',
|
||||
'July 2020',
|
||||
RenderedConnection.prototype.isConnectionAllowed = function(
|
||||
candidate, maxRadius) {
|
||||
deprecation.warn(
|
||||
'RenderedConnection.prototype.isConnectionAllowed', 'July 2020',
|
||||
'July 2021',
|
||||
'Blockly.Workspace.prototype.getConnectionChecker().canConnect');
|
||||
if (this.distanceFrom(candidate) > maxRadius) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Blockly.RenderedConnection.superClass_.isConnectionAllowed.call(this,
|
||||
candidate);
|
||||
return RenderedConnection.superClass_.isConnectionAllowed.call(
|
||||
this, candidate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Behavior after a connection attempt fails.
|
||||
* Bumps this connection away from the other connection. Called when an
|
||||
* attempted connection fails.
|
||||
* @param {!Blockly.Connection} otherConnection Connection that this connection
|
||||
* @param {!Connection} otherConnection Connection that this connection
|
||||
* failed to connect to.
|
||||
* @package
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.onFailedConnect =
|
||||
function(otherConnection) {
|
||||
var block = this.getSourceBlock();
|
||||
if (Blockly.Events.recordUndo) {
|
||||
var group = Blockly.Events.getGroup();
|
||||
setTimeout(function() {
|
||||
if (!block.isDisposed() && !block.getParent()) {
|
||||
Blockly.Events.setGroup(group);
|
||||
this.bumpAwayFrom(otherConnection);
|
||||
Blockly.Events.setGroup(false);
|
||||
}
|
||||
}.bind(this), Blockly.internalConstants.BUMP_DELAY);
|
||||
RenderedConnection.prototype.onFailedConnect = function(otherConnection) {
|
||||
const block = this.getSourceBlock();
|
||||
if (Events.recordUndo) {
|
||||
const group = Events.getGroup();
|
||||
setTimeout(function() {
|
||||
if (!block.isDisposed() && !block.getParent()) {
|
||||
Events.setGroup(group);
|
||||
this.bumpAwayFrom(otherConnection);
|
||||
Events.setGroup(false);
|
||||
}
|
||||
};
|
||||
}.bind(this), internalConstants.BUMP_DELAY);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Disconnect two blocks that are connected by this connection.
|
||||
* @param {!Blockly.Block} parentBlock The superior block.
|
||||
* @param {!Blockly.Block} childBlock The inferior block.
|
||||
* @param {!Block} parentBlock The superior block.
|
||||
* @param {!Block} childBlock The inferior block.
|
||||
* @protected
|
||||
* @override
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock,
|
||||
childBlock) {
|
||||
Blockly.RenderedConnection.superClass_.disconnectInternal_.call(this,
|
||||
parentBlock, childBlock);
|
||||
RenderedConnection.prototype.disconnectInternal_ = function(
|
||||
parentBlock, childBlock) {
|
||||
RenderedConnection.superClass_.disconnectInternal_.call(
|
||||
this, parentBlock, childBlock);
|
||||
// Rerender the parent so that it may reflow.
|
||||
if (parentBlock.rendered) {
|
||||
parentBlock.render();
|
||||
@@ -506,9 +500,9 @@ Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock,
|
||||
* @protected
|
||||
* @override
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.respawnShadow_ = function() {
|
||||
Blockly.RenderedConnection.superClass_.respawnShadow_.call(this);
|
||||
var blockShadow = this.targetBlock();
|
||||
RenderedConnection.prototype.respawnShadow_ = function() {
|
||||
RenderedConnection.superClass_.respawnShadow_.call(this);
|
||||
const blockShadow = this.targetBlock();
|
||||
if (!blockShadow) {
|
||||
// This connection must not have a shadowDom_.
|
||||
return;
|
||||
@@ -516,7 +510,7 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() {
|
||||
blockShadow.initSvg();
|
||||
blockShadow.render(false);
|
||||
|
||||
var parentBlock = this.getSourceBlock();
|
||||
const parentBlock = this.getSourceBlock();
|
||||
if (parentBlock.rendered) {
|
||||
parentBlock.render();
|
||||
}
|
||||
@@ -527,27 +521,27 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() {
|
||||
* Type checking does not apply, since this function is used for bumping.
|
||||
* @param {number} maxLimit The maximum radius to another connection, in
|
||||
* workspace units.
|
||||
* @return {!Array<!Blockly.Connection>} List of connections.
|
||||
* @return {!Array<!Connection>} List of connections.
|
||||
* @package
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.neighbours = function(maxLimit) {
|
||||
RenderedConnection.prototype.neighbours = function(maxLimit) {
|
||||
return this.dbOpposite_.getNeighbours(this, maxLimit);
|
||||
};
|
||||
|
||||
/**
|
||||
* Connect two connections together. This is the connection on the superior
|
||||
* block. Rerender blocks as needed.
|
||||
* @param {!Blockly.Connection} childConnection Connection on inferior block.
|
||||
* @param {!Connection} childConnection Connection on inferior block.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
|
||||
Blockly.RenderedConnection.superClass_.connect_.call(this, childConnection);
|
||||
RenderedConnection.prototype.connect_ = function(childConnection) {
|
||||
RenderedConnection.superClass_.connect_.call(this, childConnection);
|
||||
|
||||
var parentConnection = this;
|
||||
var parentBlock = parentConnection.getSourceBlock();
|
||||
var childBlock = childConnection.getSourceBlock();
|
||||
var parentRendered = parentBlock.rendered;
|
||||
var childRendered = childBlock.rendered;
|
||||
const parentConnection = this;
|
||||
const parentBlock = parentConnection.getSourceBlock();
|
||||
const childBlock = childConnection.getSourceBlock();
|
||||
const parentRendered = parentBlock.rendered;
|
||||
const childRendered = childBlock.rendered;
|
||||
|
||||
if (parentRendered) {
|
||||
parentBlock.updateDisabled();
|
||||
@@ -556,8 +550,8 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
|
||||
childBlock.updateDisabled();
|
||||
}
|
||||
if (parentRendered && childRendered) {
|
||||
if (parentConnection.type == Blockly.connectionTypes.NEXT_STATEMENT ||
|
||||
parentConnection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) {
|
||||
if (parentConnection.type == connectionTypes.NEXT_STATEMENT ||
|
||||
parentConnection.type == 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();
|
||||
@@ -569,9 +563,9 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
|
||||
}
|
||||
|
||||
// The input the child block is connected to (if any).
|
||||
var parentInput = parentBlock.getInputWithBlock(childBlock);
|
||||
const parentInput = parentBlock.getInputWithBlock(childBlock);
|
||||
if (parentInput) {
|
||||
var visible = parentInput.isVisible();
|
||||
const visible = parentInput.isVisible();
|
||||
childBlock.getSvgRoot().style.display = visible ? 'block' : 'none';
|
||||
}
|
||||
};
|
||||
@@ -580,14 +574,17 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
|
||||
* Function to be called when this connection's compatible types have changed.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.onCheckChanged_ = function() {
|
||||
RenderedConnection.prototype.onCheckChanged_ = function() {
|
||||
// The new value type may not be compatible with the existing connection.
|
||||
if (this.isConnected() && (!this.targetConnection ||
|
||||
!this.getConnectionChecker().canConnect(
|
||||
this, this.targetConnection, false))) {
|
||||
var child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_;
|
||||
if (this.isConnected() &&
|
||||
(!this.targetConnection ||
|
||||
!this.getConnectionChecker().canConnect(
|
||||
this, this.targetConnection, false))) {
|
||||
const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_;
|
||||
child.unplug();
|
||||
// Bump away.
|
||||
this.sourceBlock_.bumpNeighbours();
|
||||
}
|
||||
};
|
||||
|
||||
exports = RenderedConnection;
|
||||
|
||||
@@ -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/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/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']);
|
||||
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/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': 'es6', 'module': 'goog'});
|
||||
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'});
|
||||
|
||||
Reference in New Issue
Block a user