Fix 11 warnings related to block_svg (#3276)

* Fix 11 warnings related to block_svg
This commit is contained in:
Sam El-Husseini
2019-10-17 16:30:48 -05:00
committed by GitHub
parent e07a3f03a9
commit a5a4e5161c
6 changed files with 42 additions and 25 deletions

View File

@@ -97,6 +97,9 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
/** @type {boolean} */
this.rendered = false;
/** @type {!Blockly.WorkspaceSvg} */
this.workspace = workspace;
/**
* Whether to move the block to the drag surface when it is dragged.
* True if it should move, false if it should be translated directly.
@@ -104,7 +107,7 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
* @private
*/
this.useDragSurface_ =
Blockly.utils.is3dSupported() && !!workspace.blockDragSurface_;
Blockly.utils.is3dSupported() && !!workspace.getBlockDragSurface();
Blockly.Tooltip.bindMouseEvents(this.svgPath_);
Blockly.BlockSvg.superClass_.constructor.call(this,
@@ -254,14 +257,15 @@ Blockly.BlockSvg.prototype.initSvg = function() {
}
this.updateColour();
this.updateMovable();
if (!this.workspace.options.readOnly && !this.eventsInit_) {
var svg = this.getSvgRoot();
if (!this.workspace.options.readOnly && !this.eventsInit_ && svg) {
Blockly.bindEventWithChecks_(
this.getSvgRoot(), 'mousedown', this, this.onMouseDown_);
svg, 'mousedown', this, this.onMouseDown_);
}
this.eventsInit_ = true;
if (!this.getSvgRoot().parentNode) {
this.workspace.getCanvas().appendChild(this.getSvgRoot());
if (!svg.parentNode) {
this.workspace.getCanvas().appendChild(svg);
}
};
@@ -355,7 +359,7 @@ Blockly.BlockSvg.prototype.getIcons = function() {
/**
* Set parent of this block to be a new block or null.
* @param {Blockly.BlockSvg} newParent New parent block.
* @param {Blockly.Block} newParent New parent block.
* @override
*/
Blockly.BlockSvg.prototype.setParent = function(newParent) {
@@ -405,7 +409,7 @@ Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() {
var y = 0;
var dragSurfaceGroup = this.useDragSurface_ ?
this.workspace.blockDragSurface_.getGroup() : null;
this.workspace.getBlockDragSurface().getGroup() : null;
var element = this.getSvgRoot();
if (element) {
@@ -417,9 +421,9 @@ Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() {
// If this element is the current element on the drag surface, include
// the translation of the drag surface itself.
if (this.useDragSurface_ &&
this.workspace.blockDragSurface_.getCurrentBlock() == element) {
this.workspace.getBlockDragSurface().getCurrentBlock() == element) {
var surfaceTranslation =
this.workspace.blockDragSurface_.getSurfaceTranslation();
this.workspace.getBlockDragSurface().getSurfaceTranslation();
x += surfaceTranslation.x;
y += surfaceTranslation.y;
}
@@ -480,9 +484,12 @@ Blockly.BlockSvg.prototype.moveToDragSurface_ = function() {
// This is in workspace coordinates.
var xy = this.getRelativeToSurfaceXY();
this.clearTransformAttributes_();
this.workspace.blockDragSurface_.translateSurface(xy.x, xy.y);
this.workspace.getBlockDragSurface().translateSurface(xy.x, xy.y);
// Execute the move on the top-level SVG component
this.workspace.blockDragSurface_.setBlocksAndShow(this.getSvgRoot());
var svg = this.getSvgRoot();
if (svg) {
this.workspace.getBlockDragSurface().setBlocksAndShow(svg);
}
};
/**
@@ -508,7 +515,7 @@ Blockly.BlockSvg.prototype.moveOffDragSurface_ = function(newXY) {
}
// Translate to current position, turning off 3d.
this.translate(newXY.x, newXY.y);
this.workspace.blockDragSurface_.clearAndHide(this.workspace.getCanvas());
this.workspace.getBlockDragSurface().clearAndHide(this.workspace.getCanvas());
};
/**
@@ -521,7 +528,7 @@ Blockly.BlockSvg.prototype.moveOffDragSurface_ = function(newXY) {
*/
Blockly.BlockSvg.prototype.moveDuringDrag = function(newLoc) {
if (this.useDragSurface_) {
this.workspace.blockDragSurface_.translateSurface(newLoc.x, newLoc.y);
this.workspace.getBlockDragSurface().translateSurface(newLoc.x, newLoc.y);
} else {
this.svgGroup_.translate_ = 'translate(' + newLoc.x + ',' + newLoc.y + ')';
this.svgGroup_.setAttribute('transform',
@@ -680,7 +687,7 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
*/
Blockly.BlockSvg.prototype.tab = function(start, forward) {
var list = this.createTabList_();
var i = list.indexOf(start);
var i = start != null ? list.indexOf(start) : -1;
if (i == -1) {
// No start location, start at the beginning or end.
i = forward ? -1 : list.length;
@@ -693,7 +700,7 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) {
parent.tab(this, forward);
}
} else if (target instanceof Blockly.Field) {
target.showEditor_();
target.showEditor();
} else {
target.tab(null, forward);
}
@@ -701,7 +708,7 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) {
/**
* Create an ordered list of all text fields and connected inputs.
* @return {!Array.<!Blockly.FieldTextInput|!Blockly.Input>} The ordered list.
* @return {!Array.<!Blockly.Field|!Blockly.Block>} The ordered list.
* @private
*/
Blockly.BlockSvg.prototype.createTabList_ = function() {
@@ -1033,7 +1040,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
for (var i = 0; i < icons.length; i++) {
icons[i].dispose();
}
Blockly.BlockSvg.superClass_.dispose.call(this, healStack);
Blockly.BlockSvg.superClass_.dispose.call(this, !!healStack);
Blockly.utils.dom.removeNode(this.svgGroup_);
blockWorkspace.resizeContents();
@@ -1101,7 +1108,7 @@ Blockly.BlockSvg.prototype.setBorderColour_ = function() {
* @private
*/
Blockly.BlockSvg.prototype.setShadowColour_ = function() {
var shadowColour = this.getColourShadow();
var shadowColour = this.getColourShadow() || '';
this.svgPathLight_.style.display = 'none';
this.svgPathDark_.setAttribute('fill', shadowColour);

View File

@@ -252,22 +252,22 @@ Blockly.Comment.prototype.createEditableBubble_ = function() {
/**
* Show a non-editable bubble.
* @private
* @suppress {checkTypes} Suppress `this` type mismatch.
*/
Blockly.Comment.prototype.createNonEditableBubble_ = function() {
// TODO (#2917): It would be great if the comment could support line breaks.
Blockly.Warning.prototype.createBubble.call(
/** @type {Blockly.Warning} */ (this));
Blockly.Warning.prototype.createBubble.call(this);
};
/**
* Dispose of the bubble.
* @private
* @suppress {checkTypes} Suppress `this` type mismatch.
*/
Blockly.Comment.prototype.disposeBubble_ = function() {
if (this.paragraphElement_) {
// We're using the warning UI so we have to let it dispose.
Blockly.Warning.prototype.disposeBubble.call(
/** @type {Blockly.Warning} */ (this));
Blockly.Warning.prototype.disposeBubble.call(this);
return;
}

View File

@@ -612,6 +612,16 @@ Blockly.Field.prototype.render_ = function() {
}
};
/**
* Show an editor when the field is clicked only if the field is clickable.
* @package
*/
Blockly.Field.prototype.showEditor = function() {
if (this.isClickable()) {
this.showEditor_();
}
};
/**
* Updates the width of the field. Redirects to updateSize_().
* @deprecated May 2019 Use Blockly.Field.updateSize_() to force an update

View File

@@ -723,7 +723,7 @@ Blockly.Gesture.prototype.doBubbleClick_ = function() {
* @private
*/
Blockly.Gesture.prototype.doFieldClick_ = function() {
this.startField_.showEditor_();
this.startField_.showEditor();
this.bringBlockToFront_();
};

View File

@@ -924,7 +924,7 @@ Blockly.navigation.handleEnterForWS_ = function() {
var curNode = cursor.getCurNode();
var nodeType = curNode.getType();
if (nodeType == Blockly.ASTNode.types.FIELD) {
curNode.getLocation().showEditor_();
curNode.getLocation().showEditor();
} else if (curNode.isConnection() ||
nodeType == Blockly.ASTNode.types.WORKSPACE) {
Blockly.navigation.markAtCursor_();

View File

@@ -533,7 +533,7 @@ Blockly.WorkspaceSvg.prototype.isVisible = function() {
* The origin (0,0) is the top-left corner of the Blockly SVG.
* @param {!Element} element Element to find the coordinates of.
* @return {!Blockly.utils.Coordinate} Object with .x and .y properties.
* @private
* @package
*/
Blockly.WorkspaceSvg.prototype.getSvgXY = function(element) {
var x = 0;