Merge branch 'goog_module' into comment

This commit is contained in:
Aaron Dodson
2021-07-19 13:55:27 -07:00
committed by GitHub
17 changed files with 467 additions and 378 deletions

View File

@@ -10,50 +10,52 @@
*/
'use strict';
goog.provide('Blockly.BubbleDragger');
goog.module('Blockly.BubbleDragger');
goog.module.declareLegacyNamespace();
const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg');
const ComponentManager = goog.require('Blockly.ComponentManager');
const Coordinate = goog.require('Blockly.utils.Coordinate');
const Events = goog.require('Blockly.Events');
const IBubble = goog.requireType('Blockly.IBubble');
const IDeleteArea = goog.requireType('Blockly.IDeleteArea');
const IDragTarget = goog.requireType('Blockly.IDragTarget');
const utils = goog.require('Blockly.utils');
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
/** @suppress {extraRequire} */
goog.require('Blockly.Bubble');
goog.require('Blockly.ComponentManager');
/** @suppress {extraRequire} */
goog.require('Blockly.constants');
goog.require('Blockly.Events');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.CommentMove');
goog.require('Blockly.utils');
goog.require('Blockly.utils.Coordinate');
goog.requireType('Blockly.BlockDragSurfaceSvg');
goog.requireType('Blockly.IBubble');
goog.requireType('Blockly.WorkspaceSvg');
/**
* Class for a bubble dragger. It moves things on the bubble canvas around the
* workspace when they are being dragged by a mouse or touch. These can be
* block comments, mutators, warnings, or workspace comments.
* @param {!Blockly.IBubble} bubble The item on the bubble canvas to drag.
* @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on.
* @param {!IBubble} bubble The item on the bubble canvas to drag.
* @param {!WorkspaceSvg} workspace The workspace to drag on.
* @constructor
*/
Blockly.BubbleDragger = function(bubble, workspace) {
const BubbleDragger = function(bubble, workspace) {
/**
* The item on the bubble canvas that is being dragged.
* @type {!Blockly.IBubble}
* @type {!IBubble}
* @private
*/
this.draggingBubble_ = bubble;
/**
* The workspace on which the bubble is being dragged.
* @type {!Blockly.WorkspaceSvg}
* @type {!WorkspaceSvg}
* @private
*/
this.workspace_ = workspace;
/**
* Which drag target the mouse pointer is over, if any.
* @type {?Blockly.IDragTarget}
* @type {?IDragTarget}
* @private
*/
this.dragTarget_ = null;
@@ -68,7 +70,7 @@ Blockly.BubbleDragger = function(bubble, workspace) {
/**
* The location of the top left corner of the dragging bubble's body at the
* beginning of the drag, in workspace coordinates.
* @type {!Blockly.utils.Coordinate}
* @type {!Coordinate}
* @private
*/
this.startXY_ = this.draggingBubble_.getRelativeToSurfaceXY();
@@ -76,11 +78,11 @@ Blockly.BubbleDragger = function(bubble, workspace) {
/**
* The drag surface to move bubbles to during a drag, or null if none should
* be used. Block dragging and bubble dragging use the same surface.
* @type {Blockly.BlockDragSurfaceSvg}
* @type {BlockDragSurfaceSvg}
* @private
*/
this.dragSurface_ =
Blockly.utils.is3dSupported() && !!workspace.getBlockDragSurface() ?
utils.is3dSupported() && !!workspace.getBlockDragSurface() ?
workspace.getBlockDragSurface() :
null;
};
@@ -90,7 +92,7 @@ Blockly.BubbleDragger = function(bubble, workspace) {
* @package
* @suppress {checkTypes}
*/
Blockly.BubbleDragger.prototype.dispose = function() {
BubbleDragger.prototype.dispose = function() {
this.draggingBubble_ = null;
this.workspace_ = null;
this.dragSurface_ = null;
@@ -100,9 +102,9 @@ Blockly.BubbleDragger.prototype.dispose = function() {
* Start dragging a bubble. This includes moving it to the drag surface.
* @package
*/
Blockly.BubbleDragger.prototype.startBubbleDrag = function() {
if (!Blockly.Events.getGroup()) {
Blockly.Events.setGroup(true);
BubbleDragger.prototype.startBubbleDrag = function() {
if (!Events.getGroup()) {
Events.setGroup(true);
}
this.workspace_.setResizesEnabled(false);
@@ -118,19 +120,19 @@ Blockly.BubbleDragger.prototype.startBubbleDrag = function() {
* Execute a step of bubble dragging, based on the given event. Update the
* display accordingly.
* @param {!Event} e The most recent move event.
* @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has
* @param {!Coordinate} currentDragDeltaXY How far the pointer has
* moved from the position at the start of the drag, in pixel units.
* @package
*/
Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) {
var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta);
BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) {
const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
const newLoc = Coordinate.sum(this.startXY_, delta);
this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc);
var oldDragTarget = this.dragTarget_;
const oldDragTarget = this.dragTarget_;
this.dragTarget_ = this.workspace_.getDragTarget(e);
var oldWouldDeleteBubble = this.wouldDeleteBubble_;
const oldWouldDeleteBubble = this.wouldDeleteBubble_;
this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_);
if (oldWouldDeleteBubble != this.wouldDeleteBubble_) {
// Prevent unnecessary add/remove class calls.
@@ -147,19 +149,19 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) {
/**
* Whether ending the drag would delete the bubble.
* @param {?Blockly.IDragTarget} dragTarget The drag target that the bubblee is
* @param {?IDragTarget} dragTarget The drag target that the bubblee is
* currently over.
* @return {boolean} Whether dropping the bubble immediately would delete the
* block.
* @private
*/
Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) {
BubbleDragger.prototype.shouldDelete_ = function(dragTarget) {
if (dragTarget) {
var componentManager = this.workspace_.getComponentManager();
var isDeleteArea = componentManager.hasCapability(dragTarget.id,
Blockly.ComponentManager.Capability.DELETE_AREA);
const componentManager = this.workspace_.getComponentManager();
const isDeleteArea = componentManager.hasCapability(
dragTarget.id, ComponentManager.Capability.DELETE_AREA);
if (isDeleteArea) {
return (/** @type {!Blockly.IDeleteArea} */ (dragTarget))
return (/** @type {!IDeleteArea} */ (dragTarget))
.wouldDelete(this.draggingBubble_, false);
}
}
@@ -171,29 +173,29 @@ Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) {
* dragging bubble would be deleted if released immediately.
* @private
*/
Blockly.BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() {
BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() {
this.draggingBubble_.setDeleteStyle(this.wouldDeleteBubble_);
};
/**
* Finish a bubble drag and put the bubble back on the workspace.
* @param {!Event} e The mouseup/touchend event.
* @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has
* @param {!Coordinate} currentDragDeltaXY How far the pointer has
* moved from the position at the start of the drag, in pixel units.
* @package
*/
Blockly.BubbleDragger.prototype.endBubbleDrag = function(
e, currentDragDeltaXY) {
BubbleDragger.prototype.endBubbleDrag = function(e, currentDragDeltaXY) {
// Make sure internal state is fresh.
this.dragBubble(e, currentDragDeltaXY);
var preventMove = this.dragTarget_ &&
const preventMove = this.dragTarget_ &&
this.dragTarget_.shouldPreventMove(this.draggingBubble_);
let newLoc;
if (preventMove) {
var newLoc = this.startXY_;
newLoc = this.startXY_;
} else {
var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta);
const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
newLoc = Coordinate.sum(this.startXY_, delta);
}
// Move the bubble to its final location.
this.draggingBubble_.moveTo(newLoc.x, newLoc.y);
@@ -218,20 +220,21 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function(
}
this.workspace_.setResizesEnabled(true);
Blockly.Events.setGroup(false);
Events.setGroup(false);
};
/**
* Fire a move event at the end of a bubble drag.
* @private
*/
Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() {
BubbleDragger.prototype.fireMoveEvent_ = function() {
if (this.draggingBubble_.isComment) {
var event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(
// TODO (adodson): Resolve build errors when requiring WorkspaceCommentSvg.
const event = new (Events.get(Events.COMMENT_MOVE))(
/** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_));
event.setOldCoordinate(this.startXY_);
event.recordNew();
Blockly.Events.fire(event);
Events.fire(event);
}
// TODO (fenichel): move events for comments.
return;
@@ -242,14 +245,14 @@ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() {
* correction for mutator workspaces.
* This function does not consider differing origins. It simply scales the
* input's x and y values.
* @param {!Blockly.utils.Coordinate} pixelCoord A coordinate with x and y
* @param {!Coordinate} pixelCoord A coordinate with x and y
* values in CSS pixel units.
* @return {!Blockly.utils.Coordinate} The input coordinate divided by the
* @return {!Coordinate} The input coordinate divided by the
* workspace scale.
* @private
*/
Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) {
var result = new Blockly.utils.Coordinate(
BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) {
const result = new Coordinate(
pixelCoord.x / this.workspace_.scale,
pixelCoord.y / this.workspace_.scale);
if (this.workspace_.isMutator) {
@@ -257,7 +260,7 @@ Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) {
// oddities in our rendering optimizations. The actual scale is the same as
// the scale on the parent workspace.
// Fix that for dragging.
var mainScale = this.workspace_.options.parentWorkspace.scale;
const mainScale = this.workspace_.options.parentWorkspace.scale;
result.scale(1 / mainScale);
}
return result;
@@ -268,9 +271,11 @@ Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) {
* drag surface to preserve the apparent location of the bubble.
* @private
*/
Blockly.BubbleDragger.prototype.moveToDragSurface_ = function() {
BubbleDragger.prototype.moveToDragSurface_ = function() {
this.draggingBubble_.moveTo(0, 0);
this.dragSurface_.translateSurface(this.startXY_.x, this.startXY_.y);
// Execute the move on the top-level SVG component.
this.dragSurface_.setBlocksAndShow(this.draggingBubble_.getSvgRoot());
};
exports = BubbleDragger;

View File

@@ -5,37 +5,36 @@
*/
/**
* @fileoverview An object that encapsulates logic for checking whether a potential
* connection is safe and valid.
* @fileoverview An object that encapsulates logic for checking whether a
* potential connection is safe and valid.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.provide('Blockly.ConnectionChecker');
goog.module('Blockly.ConnectionChecker');
goog.module.declareLegacyNamespace();
goog.require('Blockly.Connection');
goog.require('Blockly.connectionTypes');
const Connection = goog.require('Blockly.Connection');
const IConnectionChecker = goog.require('Blockly.IConnectionChecker');
const RenderedConnection = goog.requireType('Blockly.RenderedConnection');
const connectionTypes = goog.require('Blockly.connectionTypes');
const registry = goog.require('Blockly.registry');
/** @suppress {extraRequire} */
goog.require('Blockly.constants');
goog.require('Blockly.IConnectionChecker');
goog.require('Blockly.registry');
goog.requireType('Blockly.RenderedConnection');
/**
* Class for connection type checking logic.
* @implements {Blockly.IConnectionChecker}
* @implements {IConnectionChecker}
* @constructor
*/
Blockly.ConnectionChecker = function() {
};
const ConnectionChecker = function() {};
/**
* Check whether the current connection can connect with the target
* connection.
* @param {Blockly.Connection} a Connection to check compatibility with.
* @param {Blockly.Connection} b Connection to check compatibility with.
* @param {Connection} a Connection to check compatibility with.
* @param {Connection} b Connection to check compatibility with.
* @param {boolean} isDragging True if the connection is being made by dragging
* a block.
* @param {number=} opt_distance The max allowable distance between the
@@ -43,80 +42,80 @@ Blockly.ConnectionChecker = function() {
* @return {boolean} Whether the connection is legal.
* @public
*/
Blockly.ConnectionChecker.prototype.canConnect = function(a, b,
isDragging, opt_distance) {
ConnectionChecker.prototype.canConnect = function(
a, b, isDragging, opt_distance) {
return this.canConnectWithReason(a, b, isDragging, opt_distance) ==
Blockly.Connection.CAN_CONNECT;
Connection.CAN_CONNECT;
};
/**
* Checks whether the current connection can connect with the target
* connection, and return an error code if there are problems.
* @param {Blockly.Connection} a Connection to check compatibility with.
* @param {Blockly.Connection} b Connection to check compatibility with.
* @param {Connection} a Connection to check compatibility with.
* @param {Connection} b Connection to check compatibility with.
* @param {boolean} isDragging True if the connection is being made by dragging
* a block.
* @param {number=} opt_distance The max allowable distance between the
* connections for drag checks.
* @return {number} Blockly.Connection.CAN_CONNECT if the connection is legal,
* @return {number} Connection.CAN_CONNECT if the connection is legal,
* an error code otherwise.
* @public
*/
Blockly.ConnectionChecker.prototype.canConnectWithReason = function(
ConnectionChecker.prototype.canConnectWithReason = function(
a, b, isDragging, opt_distance) {
var safety = this.doSafetyChecks(a, b);
if (safety != Blockly.Connection.CAN_CONNECT) {
const safety = this.doSafetyChecks(a, b);
if (safety != Connection.CAN_CONNECT) {
return safety;
}
// If the safety checks passed, both connections are non-null.
var connOne = /** @type {!Blockly.Connection} **/ (a);
var connTwo = /** @type {!Blockly.Connection} **/ (b);
const connOne = /** @type {!Connection} **/ (a);
const connTwo = /** @type {!Connection} **/ (b);
if (!this.doTypeChecks(connOne, connTwo)) {
return Blockly.Connection.REASON_CHECKS_FAILED;
return Connection.REASON_CHECKS_FAILED;
}
if (isDragging &&
!this.doDragChecks(
/** @type {!Blockly.RenderedConnection} **/ (a),
/** @type {!Blockly.RenderedConnection} **/ (b),
opt_distance || 0)) {
return Blockly.Connection.REASON_DRAG_CHECKS_FAILED;
/** @type {!RenderedConnection} **/ (a),
/** @type {!RenderedConnection} **/ (b), opt_distance || 0)) {
return Connection.REASON_DRAG_CHECKS_FAILED;
}
return Blockly.Connection.CAN_CONNECT;
return Connection.CAN_CONNECT;
};
/**
* Helper method that translates a connection error code into a string.
* @param {number} errorCode The error code.
* @param {Blockly.Connection} a One of the two connections being checked.
* @param {Blockly.Connection} b The second of the two connections being
* @param {Connection} a One of the two connections being checked.
* @param {Connection} b The second of the two connections being
* checked.
* @return {string} A developer-readable error string.
* @public
*/
Blockly.ConnectionChecker.prototype.getErrorMessage = function(errorCode,
a, b) {
ConnectionChecker.prototype.getErrorMessage = function(errorCode, a, b) {
switch (errorCode) {
case Blockly.Connection.REASON_SELF_CONNECTION:
case Connection.REASON_SELF_CONNECTION:
return 'Attempted to connect a block to itself.';
case Blockly.Connection.REASON_DIFFERENT_WORKSPACES:
case Connection.REASON_DIFFERENT_WORKSPACES:
// Usually this means one block has been deleted.
return 'Blocks not on same workspace.';
case Blockly.Connection.REASON_WRONG_TYPE:
case Connection.REASON_WRONG_TYPE:
return 'Attempt to connect incompatible types.';
case Blockly.Connection.REASON_TARGET_NULL:
case Connection.REASON_TARGET_NULL:
return 'Target connection is null.';
case Blockly.Connection.REASON_CHECKS_FAILED:
var connOne = /** @type {!Blockly.Connection} **/ (a);
var connTwo = /** @type {!Blockly.Connection} **/ (b);
var msg = 'Connection checks failed. ';
msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + connTwo.getCheck();
case Connection.REASON_CHECKS_FAILED: {
const connOne = /** @type {!Connection} **/ (a);
const connTwo = /** @type {!Connection} **/ (b);
let msg = 'Connection checks failed. ';
msg += connOne + ' expected ' + connOne.getCheck() + ', found ' +
connTwo.getCheck();
return msg;
case Blockly.Connection.REASON_SHADOW_PARENT:
}
case Connection.REASON_SHADOW_PARENT:
return 'Connecting non-shadow to shadow block.';
case Blockly.Connection.REASON_DRAG_CHECKS_FAILED:
case Connection.REASON_DRAG_CHECKS_FAILED:
return 'Drag checks failed.';
default:
return 'Unknown connection failure: this should never happen!';
@@ -126,53 +125,54 @@ Blockly.ConnectionChecker.prototype.getErrorMessage = function(errorCode,
/**
* Check that connecting the given connections is safe, meaning that it would
* not break any of Blockly's basic assumptions (e.g. no self connections).
* @param {Blockly.Connection} a The first of the connections to check.
* @param {Blockly.Connection} b The second of the connections to check.
* @param {Connection} a The first of the connections to check.
* @param {Connection} b The second of the connections to check.
* @return {number} An enum with the reason this connection is safe or unsafe.
* @public
*/
Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) {
ConnectionChecker.prototype.doSafetyChecks = function(a, b) {
if (!a || !b) {
return Blockly.Connection.REASON_TARGET_NULL;
return Connection.REASON_TARGET_NULL;
}
let blockA, blockB;
if (a.isSuperior()) {
var blockA = a.getSourceBlock();
var blockB = b.getSourceBlock();
blockA = a.getSourceBlock();
blockB = b.getSourceBlock();
} else {
var blockB = a.getSourceBlock();
var blockA = b.getSourceBlock();
blockB = a.getSourceBlock();
blockA = b.getSourceBlock();
}
if (blockA == blockB) {
return Blockly.Connection.REASON_SELF_CONNECTION;
return Connection.REASON_SELF_CONNECTION;
} else if (b.type != Blockly.OPPOSITE_TYPE[a.type]) {
return Blockly.Connection.REASON_WRONG_TYPE;
return Connection.REASON_WRONG_TYPE;
} else if (blockA.workspace !== blockB.workspace) {
return Blockly.Connection.REASON_DIFFERENT_WORKSPACES;
return Connection.REASON_DIFFERENT_WORKSPACES;
} else if (blockA.isShadow() && !blockB.isShadow()) {
return Blockly.Connection.REASON_SHADOW_PARENT;
return Connection.REASON_SHADOW_PARENT;
}
return Blockly.Connection.CAN_CONNECT;
return Connection.CAN_CONNECT;
};
/**
* Check whether this connection is compatible with another connection with
* respect to the value type system. E.g. square_root("Hello") is not
* compatible.
* @param {!Blockly.Connection} a Connection to compare.
* @param {!Blockly.Connection} b Connection to compare against.
* @param {!Connection} a Connection to compare.
* @param {!Connection} b Connection to compare against.
* @return {boolean} True if the connections share a type.
* @public
*/
Blockly.ConnectionChecker.prototype.doTypeChecks = function(a, b) {
var checkArrayOne = a.getCheck();
var checkArrayTwo = b.getCheck();
ConnectionChecker.prototype.doTypeChecks = function(a, b) {
const checkArrayOne = a.getCheck();
const checkArrayTwo = b.getCheck();
if (!checkArrayOne || !checkArrayTwo) {
// One or both sides are promiscuous enough that anything will fit.
return true;
}
// Find any intersection in the check lists.
for (var i = 0; i < checkArrayOne.length; i++) {
for (let i = 0; i < checkArrayOne.length; i++) {
if (checkArrayTwo.indexOf(checkArrayOne[i]) != -1) {
return true;
}
@@ -183,13 +183,13 @@ Blockly.ConnectionChecker.prototype.doTypeChecks = function(a, b) {
/**
* Check whether this connection can be made by dragging.
* @param {!Blockly.RenderedConnection} a Connection to compare.
* @param {!Blockly.RenderedConnection} b Connection to compare against.
* @param {!RenderedConnection} a Connection to compare.
* @param {!RenderedConnection} b Connection to compare against.
* @param {number} distance The maximum allowable distance between connections.
* @return {boolean} True if the connection is allowed during a drag.
* @public
*/
Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
if (a.distanceFrom(b) > distance) {
return false;
}
@@ -200,38 +200,34 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
}
switch (b.type) {
case Blockly.connectionTypes.PREVIOUS_STATEMENT:
case connectionTypes.PREVIOUS_STATEMENT:
return this.canConnectToPrevious_(a, b);
case Blockly.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()) ||
if ((b.isConnected() && !b.targetBlock().isInsertionMarker()) ||
a.isConnected()) {
return false;
}
break;
}
case Blockly.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.
if (b.isConnected() &&
!b.targetBlock().isMovable() &&
if (b.isConnected() && !b.targetBlock().isMovable() &&
!b.targetBlock().isShadow()) {
return false;
}
break;
}
case Blockly.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
// statement is allowed.
if (b.isConnected() &&
!a.getSourceBlock().nextConnection &&
!b.targetBlock().isShadow() &&
b.targetBlock().nextConnection) {
if (b.isConnected() && !a.getSourceBlock().nextConnection &&
!b.targetBlock().isShadow() && b.targetBlock().nextConnection) {
return false;
}
break;
@@ -251,14 +247,14 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) {
/**
* Helper function for drag checking.
* @param {!Blockly.Connection} a The connection to check, which must be a
* @param {!Connection} a The connection to check, which must be a
* statement input or next connection.
* @param {!Blockly.Connection} b A nearby connection to check, which
* @param {!Connection} b A nearby connection to check, which
* must be a previous connection.
* @return {boolean} True if the connection is allowed, false otherwise.
* @protected
*/
Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) {
ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) {
if (a.targetConnection) {
// This connection is already occupied.
// A next connection will never disconnect itself mid-drag.
@@ -274,7 +270,7 @@ Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) {
return true;
}
var targetBlock = b.targetBlock();
const targetBlock = b.targetBlock();
// If it is connected to a real block, game over.
if (!targetBlock.isInsertionMarker()) {
return false;
@@ -285,5 +281,7 @@ Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) {
return !targetBlock.getPreviousBlock();
};
Blockly.registry.register(Blockly.registry.Type.CONNECTION_CHECKER,
Blockly.registry.DEFAULT, Blockly.ConnectionChecker);
registry.register(
registry.Type.CONNECTION_CHECKER, registry.DEFAULT, ConnectionChecker);
exports = ConnectionChecker;

View File

@@ -1,75 +0,0 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview AST Node and keyboard navigation interfaces.
* @author samelh@google.com (Sam El-Husseini)
*/
'use strict';
goog.provide('Blockly.IASTNodeLocation');
goog.provide('Blockly.IASTNodeLocationSvg');
goog.provide('Blockly.IASTNodeLocationWithBlock');
goog.provide('Blockly.IKeyboardAccessible');
goog.requireType('Blockly.Block');
goog.requireType('Blockly.ShortcutRegistry');
/**
* An AST node location interface.
* @interface
*/
Blockly.IASTNodeLocation = function() {};
/**
* An AST node location SVG interface.
* @interface
* @extends {Blockly.IASTNodeLocation}
*/
Blockly.IASTNodeLocationSvg = function() {};
/**
* Add the marker SVG to this node's SVG group.
* @param {SVGElement} markerSvg The SVG root of the marker to be added to the
* SVG group.
*/
Blockly.IASTNodeLocationSvg.prototype.setMarkerSvg;
/**
* Add the cursor SVG to this node's SVG group.
* @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the
* SVG group.
*/
Blockly.IASTNodeLocationSvg.prototype.setCursorSvg;
/**
* An AST node location that has an associated block.
* @interface
* @extends {Blockly.IASTNodeLocation}
*/
Blockly.IASTNodeLocationWithBlock = function() {};
/**
* Get the source block associated with this node.
* @return {Blockly.Block} The source block.
*/
Blockly.IASTNodeLocationWithBlock.prototype.getSourceBlock;
/**
* An interface for an object that handles keyboard shortcuts.
* @interface
*/
Blockly.IKeyboardAccessible = function() {};
/**
* Handles the given keyboard shortcut.
* @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled.
* @return {boolean} True if the shortcut has been handled, false otherwise.
*/
Blockly.IKeyboardAccessible.prototype.onShortcut;

View File

@@ -0,0 +1,23 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview The interface for an AST node location.
* @author samelh@google.com (Sam El-Husseini)
*/
'use strict';
goog.module('Blockly.IASTNodeLocation');
goog.module.declareLegacyNamespace();
/**
* An AST node location interface.
* @interface
*/
const IASTNodeLocation = function() {};
exports = IASTNodeLocation;

View File

@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview The interface for an AST node location SVG.
* @author samelh@google.com (Sam El-Husseini)
*/
'use strict';
goog.module('Blockly.IASTNodeLocationSvg');
goog.module.declareLegacyNamespace();
const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation');
/**
* An AST node location SVG interface.
* @interface
* @extends {IASTNodeLocation}
*/
const IASTNodeLocationSvg = function() {};
/**
* Add the marker SVG to this node's SVG group.
* @param {SVGElement} markerSvg The SVG root of the marker to be added to the
* SVG group.
*/
IASTNodeLocationSvg.prototype.setMarkerSvg;
/**
* Add the cursor SVG to this node's SVG group.
* @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the
* SVG group.
*/
IASTNodeLocationSvg.prototype.setCursorSvg;
exports = IASTNodeLocationSvg;

View File

@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview The interface for an AST node location that has an associated
* block.
* @author samelh@google.com (Sam El-Husseini)
*/
'use strict';
goog.module('Blockly.IASTNodeLocationWithBlock');
goog.module.declareLegacyNamespace();
const Block = goog.requireType('Blockly.Block');
const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation');
/**
* An AST node location that has an associated block.
* @interface
* @extends {IASTNodeLocation}
*/
const IASTNodeLocationWithBlock = function() {};
/**
* Get the source block associated with this node.
* @return {Block} The source block.
*/
IASTNodeLocationWithBlock.prototype.getSourceBlock;
exports = IASTNodeLocationWithBlock;

View File

@@ -11,35 +11,35 @@
'use strict';
goog.provide('Blockly.IBubble');
goog.module('Blockly.IBubble');
goog.module.declareLegacyNamespace();
goog.require('Blockly.IContextMenu');
goog.require('Blockly.IDraggable');
goog.requireType('Blockly.BlockDragSurfaceSvg');
goog.requireType('Blockly.utils.Coordinate');
const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg');
const Coordinate = goog.requireType('Blockly.utils.Coordinate');
const IContextMenu = goog.require('Blockly.IContextMenu');
const IDraggable = goog.require('Blockly.IDraggable');
/**
* A bubble interface.
* @interface
* @extends {Blockly.IDraggable}
* @extends {Blockly.IContextMenu}
* @extends {IDraggable}
* @extends {IContextMenu}
*/
Blockly.IBubble = function() {};
const IBubble = function() {};
/**
* Return the coordinates of the top-left corner of this bubble's body relative
* to the drawing surface's origin (0,0), in workspace units.
* @return {!Blockly.utils.Coordinate} Object with .x and .y properties.
* @return {!Coordinate} Object with .x and .y properties.
*/
Blockly.IBubble.prototype.getRelativeToSurfaceXY;
IBubble.prototype.getRelativeToSurfaceXY;
/**
* Return the root node of the bubble's SVG group.
* @return {!SVGElement} The root SVG node of the bubble's group.
*/
Blockly.IBubble.prototype.getSvgRoot;
IBubble.prototype.getSvgRoot;
/**
* Set whether auto-layout of this bubble is enabled. The first time a bubble
@@ -48,39 +48,41 @@ Blockly.IBubble.prototype.getSvgRoot;
* @param {boolean} enable True if auto-layout should be enabled, false
* otherwise.
*/
Blockly.IBubble.prototype.setAutoLayout;
IBubble.prototype.setAutoLayout;
/**
* Triggers a move callback if one exists at the end of a drag.
* @param {boolean} adding True if adding, false if removing.
*/
Blockly.IBubble.prototype.setDragging;
IBubble.prototype.setDragging;
/**
* Move this bubble during a drag, taking into account whether or not there is
* a drag surface.
* @param {Blockly.BlockDragSurfaceSvg} dragSurface The surface that carries
* @param {?BlockDragSurfaceSvg} dragSurface The surface that carries
* rendered items during a drag, or null if no drag surface is in use.
* @param {!Blockly.utils.Coordinate} newLoc The location to translate to, in
* @param {!Coordinate} newLoc The location to translate to, in
* workspace coordinates.
*/
Blockly.IBubble.prototype.moveDuringDrag;
IBubble.prototype.moveDuringDrag;
/**
* Move the bubble to the specified location in workspace coordinates.
* @param {number} x The x position to move to.
* @param {number} y The y position to move to.
*/
Blockly.IBubble.prototype.moveTo;
IBubble.prototype.moveTo;
/**
* Update the style of this bubble when it is dragged over a delete area.
* @param {boolean} enable True if the bubble is about to be deleted, false
* otherwise.
*/
Blockly.IBubble.prototype.setDeleteStyle;
IBubble.prototype.setDeleteStyle;
/**
* Dispose of this bubble.
*/
Blockly.IBubble.prototype.dispose;
IBubble.prototype.dispose;
exports = IBubble;

View File

@@ -11,16 +11,19 @@
'use strict';
goog.provide('Blockly.IContextMenu');
goog.module('Blockly.IContextMenu');
goog.module.declareLegacyNamespace();
/**
* @interface
*/
Blockly.IContextMenu = function() {};
const IContextMenu = function() {};
/**
* Show the context menu for this object.
* @param {!Event} e Mouse event.
*/
Blockly.IContextMenu.prototype.showContextMenu;
IContextMenu.prototype.showContextMenu;
exports = IContextMenu;

View File

@@ -11,30 +11,33 @@
'use strict';
goog.provide('Blockly.ICopyable');
goog.module('Blockly.ICopyable');
goog.module.declareLegacyNamespace();
goog.requireType('Blockly.ISelectable');
goog.requireType('Blockly.WorkspaceSvg');
const ISelectable = goog.requireType('Blockly.ISelectable');
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
/**
* @extends {Blockly.ISelectable}
* @extends {ISelectable}
* @interface
*/
Blockly.ICopyable = function() {};
const ICopyable = function() {};
/**
* Encode for copying.
* @return {?Blockly.ICopyable.CopyData} Copy metadata.
* @return {?ICopyable.CopyData} Copy metadata.
*/
Blockly.ICopyable.prototype.toCopyData;
ICopyable.prototype.toCopyData;
/**
* Copy Metadata.
* @typedef {{
* xml:!Element,
* source:Blockly.WorkspaceSvg,
* source:WorkspaceSvg,
* typeCounts:?Object
* }}
*/
Blockly.ICopyable.CopyData;
ICopyable.CopyData;
exports = ICopyable;

View File

@@ -12,67 +12,70 @@
'use strict';
goog.provide('Blockly.IDragTarget');
goog.module('Blockly.IDragTarget');
goog.module.declareLegacyNamespace();
goog.require('Blockly.IComponent');
const IComponent = goog.require('Blockly.IComponent');
const IDraggable = goog.requireType('Blockly.IDraggable');
const Rect = goog.requireType('Blockly.utils.Rect');
goog.requireType('Blockly.IDraggable');
goog.requireType('Blockly.utils.Rect');
/**
* Interface for a component with custom behaviour when a block or bubble is
* dragged over or dropped on top of it.
* @extends {Blockly.IComponent}
* @extends {IComponent}
* @interface
*/
Blockly.IDragTarget = function() {};
const IDragTarget = function() {};
/**
* Returns the bounding rectangle of the drag target area in pixel units
* relative to viewport.
* @return {?Blockly.utils.Rect} The component's bounding box. Null if drag
* @return {?Rect} The component's bounding box. Null if drag
* target area should be ignored.
*/
Blockly.IDragTarget.prototype.getClientRect;
IDragTarget.prototype.getClientRect;
/**
* Handles when a cursor with a block or bubble enters this drag target.
* @param {!Blockly.IDraggable} dragElement The block or bubble currently being
* @param {!IDraggable} dragElement The block or bubble currently being
* dragged.
*/
Blockly.IDragTarget.prototype.onDragEnter;
IDragTarget.prototype.onDragEnter;
/**
* Handles when a cursor with a block or bubble is dragged over this drag
* target.
* @param {!Blockly.IDraggable} dragElement The block or bubble currently being
* @param {!IDraggable} dragElement The block or bubble currently being
* dragged.
*/
Blockly.IDragTarget.prototype.onDragOver;
IDragTarget.prototype.onDragOver;
/**
* Handles when a cursor with a block or bubble exits this drag target.
* @param {!Blockly.IDraggable} dragElement The block or bubble currently being
* @param {!IDraggable} dragElement The block or bubble currently being
* dragged.
*/
Blockly.IDragTarget.prototype.onDragExit;
IDragTarget.prototype.onDragExit;
/**
* Handles when a block or bubble is dropped on this component.
* Should not handle delete here.
* @param {!Blockly.IDraggable} dragElement The block or bubble currently being
* @param {!IDraggable} dragElement The block or bubble currently being
* dragged.
*/
Blockly.IDragTarget.prototype.onDrop;
IDragTarget.prototype.onDrop;
/**
* Returns whether the provided block or bubble should not be moved after being
* dropped on this component. If true, the element will return to where it was
* when the drag started.
* @param {!Blockly.IDraggable} dragElement The block or bubble currently being
* @param {!IDraggable} dragElement The block or bubble currently being
* dragged.
* @return {boolean} Whether the block or bubble provided should be returned to
* drag start.
*/
Blockly.IDragTarget.prototype.shouldPreventMove;
IDragTarget.prototype.shouldPreventMove;
exports = IDragTarget;

View File

@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview The interface for objects that handle keyboard shortcuts.
* @author samelh@google.com (Sam El-Husseini)
*/
'use strict';
goog.module('Blockly.IKeyboardAccessible');
goog.module.declareLegacyNamespace();
const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry');
/**
* An interface for an object that handles keyboard shortcuts.
* @interface
*/
const IKeyboardAccessible = function() {};
/**
* Handles the given keyboard shortcut.
* @param {!KeyboardShortcut} shortcut The shortcut to be handled.
* @return {boolean} True if the shortcut has been handled, false otherwise.
*/
IKeyboardAccessible.prototype.onShortcut;
exports = IKeyboardAccessible;

View File

@@ -11,17 +11,20 @@
'use strict';
goog.provide('Blockly.IMovable');
goog.module('Blockly.IMovable');
goog.module.declareLegacyNamespace();
/**
* The interface for an object that is movable.
* @interface
*/
Blockly.IMovable = function() {};
const IMovable = function() {};
/**
* Get whether this is movable or not.
* @return {boolean} True if movable.
*/
Blockly.IMovable.prototype.isMovable;
IMovable.prototype.isMovable;
exports = IMovable;

View File

@@ -11,33 +11,35 @@
'use strict';
goog.provide('Blockly.IPositionable');
goog.module('Blockly.IPositionable');
goog.module.declareLegacyNamespace();
goog.require('Blockly.IComponent');
goog.requireType('Blockly.MetricsManager');
goog.requireType('Blockly.utils.Rect');
const IComponent = goog.require('Blockly.IComponent');
const Rect = goog.requireType('Blockly.utils.Rect');
const {UiMetrics} = goog.requireType('Blockly.MetricsManager');
/**
* Interface for a component that is positioned on top of the workspace.
* @extends {Blockly.IComponent}
* @extends {IComponent}
* @interface
*/
Blockly.IPositionable = function() {};
const IPositionable = function() {};
/**
* Positions the element. Called when the window is resized.
* @param {!Blockly.MetricsManager.UiMetrics} metrics The workspace metrics.
* @param {!Array<!Blockly.utils.Rect>} savedPositions List of rectangles that
* @param {!UiMetrics} metrics The workspace metrics.
* @param {!Array<!Rect>} savedPositions List of rectangles that
* are already on the workspace.
*/
Blockly.IPositionable.prototype.position;
IPositionable.prototype.position;
/**
* Returns the bounding rectangle of the UI element in pixel units relative to
* the Blockly injection div.
* @return {?Blockly.utils.Rect} The UI elementss bounding box. Null if
* @return {?Rect} The UI elementss bounding box. Null if
* bounding box should be ignored by other UI elements.
*/
Blockly.IPositionable.prototype.getBoundingRectangle;
IPositionable.prototype.getBoundingRectangle;
exports = IPositionable;

View File

@@ -11,7 +11,8 @@
'use strict';
goog.provide('Blockly.ISelectable');
goog.module('Blockly.ISelectable');
goog.module.declareLegacyNamespace();
goog.requireType('Blockly.IDeletable');
goog.requireType('Blockly.IMovable');
@@ -23,21 +24,23 @@ goog.requireType('Blockly.IMovable');
* @extends {Blockly.IMovable}
* @interface
*/
Blockly.ISelectable = function() {};
const ISelectable = function() {};
/**
* @type {string}
*/
Blockly.ISelectable.prototype.id;
ISelectable.prototype.id;
/**
* Select this. Highlight it visually.
* @return {void}
*/
Blockly.ISelectable.prototype.select;
ISelectable.prototype.select;
/**
* Unselect this. Unhighlight it visually.
* @return {void}
*/
Blockly.ISelectable.prototype.unselect;
ISelectable.prototype.unselect;
exports = ISelectable;

View File

@@ -11,23 +11,26 @@
'use strict';
goog.provide('Blockly.IStyleable');
goog.module('Blockly.IStyleable');
goog.module.declareLegacyNamespace();
/**
* Interface for an object that a style can be added to.
* @interface
*/
Blockly.IStyleable = function() {};
const IStyleable = function() {};
/**
* Adds a style on the toolbox. Usually used to change the cursor.
* @param {string} style The name of the class to add.
*/
Blockly.IStyleable.prototype.addStyle;
IStyleable.prototype.addStyle;
/**
* Removes a style from the toolbox. Usually used to change the cursor.
* @param {string} style The name of the class to remove.
*/
Blockly.IStyleable.prototype.removeStyle;
IStyleable.prototype.removeStyle;
exports = IStyleable;

View File

@@ -16,54 +16,55 @@
* @name Blockly.utils.style
* @namespace
*/
goog.provide('Blockly.utils.style');
goog.module('Blockly.utils.style');
goog.module.declareLegacyNamespace();
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.Size');
const Coordinate = goog.require('Blockly.utils.Coordinate');
const Size = goog.require('Blockly.utils.Size');
/**
* Gets the height and width of an element.
* Similar to Closure's goog.style.getSize
* @param {!Element} element Element to get size of.
* @return {!Blockly.utils.Size} Object with width/height properties.
* @return {!Size} Object with width/height properties.
*/
Blockly.utils.style.getSize = function(element) {
if (Blockly.utils.style.getStyle_(element, 'display') != 'none') {
return Blockly.utils.style.getSizeWithDisplay_(element);
function getSize(element) {
if (getStyle(element, 'display') != 'none') {
return getSizeWithDisplay(element);
}
// Evaluate size with a temporary element.
var style = element.style;
var originalDisplay = style.display;
var originalVisibility = style.visibility;
var originalPosition = style.position;
const style = element.style;
const originalDisplay = style.display;
const originalVisibility = style.visibility;
const originalPosition = style.position;
style.visibility = 'hidden';
style.position = 'absolute';
style.display = 'inline';
var offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth;
var offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight;
const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth;
const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight;
style.display = originalDisplay;
style.position = originalPosition;
style.visibility = originalVisibility;
return new Blockly.utils.Size(offsetWidth, offsetHeight);
};
return new Size(offsetWidth, offsetHeight);
}
exports.getSize = getSize;
/**
* Gets the height and width of an element when the display is not none.
* @param {!Element} element Element to get size of.
* @return {!Blockly.utils.Size} Object with width/height properties.
* @private
* @return {!Size} Object with width/height properties.
*/
Blockly.utils.style.getSizeWithDisplay_ = function(element) {
var offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth;
var offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight;
return new Blockly.utils.Size(offsetWidth, offsetHeight);
};
function getSizeWithDisplay(element) {
const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth;
const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight;
return new Size(offsetWidth, offsetHeight);
}
/**
* Cross-browser pseudo get computed style. It returns the computed style where
@@ -77,13 +78,11 @@ Blockly.utils.style.getSizeWithDisplay_ = function(element) {
* @param {!Element} element Element to get style of.
* @param {string} style Property to get (must be camelCase, not CSS-style).
* @return {string} Style value.
* @private
*/
Blockly.utils.style.getStyle_ = function(element, style) {
return Blockly.utils.style.getComputedStyle(element, style) ||
Blockly.utils.style.getCascadedStyle(element, style) ||
function getStyle(element, style) {
return getComputedStyle(element, style) || getCascadedStyle(element, style) ||
(element.style && element.style[style]);
};
}
/**
* Retrieves a computed style value of a node. It returns empty string if the
@@ -97,9 +96,9 @@ Blockly.utils.style.getStyle_ = function(element, style) {
* @param {string} property Property to get (camel-case).
* @return {string} Style value.
*/
Blockly.utils.style.getComputedStyle = function(element, property) {
function getComputedStyle(element, property) {
if (document.defaultView && document.defaultView.getComputedStyle) {
var styles = document.defaultView.getComputedStyle(element, null);
const styles = document.defaultView.getComputedStyle(element, null);
if (styles) {
// element.style[..] is undefined for browser specific styles
// as 'filter'.
@@ -108,7 +107,8 @@ Blockly.utils.style.getComputedStyle = function(element, property) {
}
return '';
};
}
exports.getComputedStyle = getComputedStyle;
/**
* Gets the cascaded style value of a node, or null if the value cannot be
@@ -120,45 +120,48 @@ Blockly.utils.style.getComputedStyle = function(element, property) {
* @param {string} style Property to get (camel-case).
* @return {string} Style value.
*/
Blockly.utils.style.getCascadedStyle = function(element, style) {
function getCascadedStyle(element, style) {
return /** @type {string} */ (
element.currentStyle ? element.currentStyle[style] : null);
};
}
exports.getCascadedStyle = getCascadedStyle;
/**
* Returns a Coordinate object relative to the top-left of the HTML document.
* Similar to Closure's goog.style.getPageOffset
* @param {!Element} el Element to get the page offset for.
* @return {!Blockly.utils.Coordinate} The page offset.
* @return {!Coordinate} The page offset.
*/
Blockly.utils.style.getPageOffset = function(el) {
var pos = new Blockly.utils.Coordinate(0, 0);
var box = el.getBoundingClientRect();
var documentElement = document.documentElement;
function getPageOffset(el) {
const pos = new Coordinate(0, 0);
const box = el.getBoundingClientRect();
const documentElement = document.documentElement;
// Must add the scroll coordinates in to get the absolute page offset
// of element since getBoundingClientRect returns relative coordinates to
// the viewport.
var scrollCoord = new Blockly.utils.Coordinate(
const scrollCoord = new Coordinate(
window.pageXOffset || documentElement.scrollLeft,
window.pageYOffset || documentElement.scrollTop);
pos.x = box.left + scrollCoord.x;
pos.y = box.top + scrollCoord.y;
return pos;
};
}
exports.getPageOffset = getPageOffset;
/**
* Calculates the viewport coordinates relative to the document.
* Similar to Closure's goog.style.getViewportPageOffset
* @return {!Blockly.utils.Coordinate} The page offset of the viewport.
* @return {!Coordinate} The page offset of the viewport.
*/
Blockly.utils.style.getViewportPageOffset = function() {
var body = document.body;
var documentElement = document.documentElement;
var scrollLeft = body.scrollLeft || documentElement.scrollLeft;
var scrollTop = body.scrollTop || documentElement.scrollTop;
return new Blockly.utils.Coordinate(scrollLeft, scrollTop);
};
function getViewportPageOffset() {
const body = document.body;
const documentElement = document.documentElement;
const scrollLeft = body.scrollLeft || documentElement.scrollLeft;
const scrollTop = body.scrollTop || documentElement.scrollTop;
return new Coordinate(scrollLeft, scrollTop);
}
exports.getViewportPageOffset = getViewportPageOffset;
/**
* Shows or hides an element from the page. Hiding the element is done by
@@ -172,9 +175,10 @@ Blockly.utils.style.getViewportPageOffset = function() {
* @param {*} isShown True to render the element in its default style,
* false to disable rendering the element.
*/
Blockly.utils.style.setElementShown = function(el, isShown) {
function setElementShown(el, isShown) {
el.style.display = isShown ? '' : 'none';
};
}
exports.setElementShown = setElementShown;
/**
* Returns true if the element is using right to left (RTL) direction.
@@ -183,9 +187,10 @@ Blockly.utils.style.setElementShown = function(el, isShown) {
* @param {!Element} el The element to test.
* @return {boolean} True for right to left, false for left to right.
*/
Blockly.utils.style.isRightToLeft = function(el) {
return 'rtl' == Blockly.utils.style.getStyle_(el, 'direction');
};
function isRightToLeft(el) {
return 'rtl' == getStyle(el, 'direction');
}
exports.isRightToLeft = isRightToLeft;
/**
* Gets the computed border widths (on all sides) in pixels
@@ -193,11 +198,11 @@ Blockly.utils.style.isRightToLeft = function(el) {
* @param {!Element} element The element to get the border widths for.
* @return {!Object} The computed border widths.
*/
Blockly.utils.style.getBorderBox = function(element) {
var left = Blockly.utils.style.getComputedStyle(element, 'borderLeftWidth');
var right = Blockly.utils.style.getComputedStyle(element, 'borderRightWidth');
var top = Blockly.utils.style.getComputedStyle(element, 'borderTopWidth');
var bottom = Blockly.utils.style.getComputedStyle(element, 'borderBottomWidth');
function getBorderBox(element) {
const left = getComputedStyle(element, 'borderLeftWidth');
const right = getComputedStyle(element, 'borderRightWidth');
const top = getComputedStyle(element, 'borderTopWidth');
const bottom = getComputedStyle(element, 'borderBottomWidth');
return {
top: parseFloat(top),
@@ -205,7 +210,8 @@ Blockly.utils.style.getBorderBox = function(element) {
bottom: parseFloat(bottom),
left: parseFloat(left)
};
};
}
exports.getBorderBox = getBorderBox;
/**
* Changes the scroll position of `container` with the minimum amount so
@@ -220,14 +226,12 @@ Blockly.utils.style.getBorderBox = function(element) {
* @param {boolean=} opt_center Whether to center the element in the container.
* Defaults to false.
*/
Blockly.utils.style.scrollIntoContainerView = function(
element, container, opt_center) {
var offset =
Blockly.utils.style.getContainerOffsetToScrollInto(element,
container, opt_center);
function scrollIntoContainerView(element, container, opt_center) {
const offset = getContainerOffsetToScrollInto(element, container, opt_center);
container.scrollLeft = offset.x;
container.scrollTop = offset.y;
};
}
exports.scrollIntoContainerView = scrollIntoContainerView;
/**
* Calculate the scroll position of `container` with the minimum amount so
@@ -241,27 +245,26 @@ Blockly.utils.style.scrollIntoContainerView = function(
* document scroll element will be used.
* @param {boolean=} opt_center Whether to center the element in the container.
* Defaults to false.
* @return {!Blockly.utils.Coordinate} The new scroll position of the container,
* @return {!Coordinate} The new scroll position of the container,
* in form of goog.math.Coordinate(scrollLeft, scrollTop).
*/
Blockly.utils.style.getContainerOffsetToScrollInto = function(
element, container, opt_center) {
function getContainerOffsetToScrollInto(element, container, opt_center) {
// Absolute position of the element's border's top left corner.
var elementPos = Blockly.utils.style.getPageOffset(element);
const elementPos = getPageOffset(element);
// Absolute position of the container's border's top left corner.
var containerPos = Blockly.utils.style.getPageOffset(container);
var containerBorder = Blockly.utils.style.getBorderBox(container);
const containerPos = getPageOffset(container);
const containerBorder = getBorderBox(container);
// Relative pos. of the element's border box to the container's content box.
var relX = elementPos.x - containerPos.x - containerBorder.left;
var relY = elementPos.y - containerPos.y - containerBorder.top;
const relX = elementPos.x - containerPos.x - containerBorder.left;
const relY = elementPos.y - containerPos.y - containerBorder.top;
// How much the element can move in the container, i.e. the difference between
// the element's bottom-right-most and top-left-most position where it's
// fully visible.
var elementSize = Blockly.utils.style.getSizeWithDisplay_(element);
var spaceX = container.clientWidth - elementSize.width;
var spaceY = container.clientHeight - elementSize.height;
var scrollLeft = container.scrollLeft;
var scrollTop = container.scrollTop;
const elementSize = getSizeWithDisplay(element);
const spaceX = container.clientWidth - elementSize.width;
const spaceY = container.clientHeight - elementSize.height;
let scrollLeft = container.scrollLeft;
let scrollTop = container.scrollTop;
if (opt_center) {
// All browsers round non-integer scroll positions down.
scrollLeft += relX - spaceX / 2;
@@ -277,5 +280,6 @@ Blockly.utils.style.getContainerOffsetToScrollInto = function(
scrollLeft += Math.min(relX, Math.max(relX - spaceX, 0));
scrollTop += Math.min(relY, Math.max(relY - spaceY, 0));
}
return new Blockly.utils.Coordinate(scrollLeft, scrollTop);
};
return new Coordinate(scrollLeft, scrollTop);
}
exports.getContainerOffsetToScrollInto = getContainerOffsetToScrollInto;

View File

@@ -16,11 +16,11 @@ goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentMana
goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']);
goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']);
goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']);
goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']);
goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']);
goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']);
goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']);
@@ -73,27 +73,30 @@ goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDr
goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'});
goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']);
goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'});
goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []);
goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']);
goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']);
goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []);
goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []);
goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []);
goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']);
goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []);
goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []);
goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], []);
goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent']);
goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []);
goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []);
goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []);
goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], []);
goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], []);
goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []);
goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'});
@@ -183,7 +186,7 @@ goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {
goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []);
goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []);
goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']);
goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []);
goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']);