From 4c93a048f25d0313bcd65a4a3bd57a5606cac4a4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:09:43 -0700 Subject: [PATCH 1/5] Migrate core/bubble_dragger.js to ES6 const/let --- core/bubble_dragger.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index e014b8738..bec5dba15 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -123,14 +123,14 @@ Blockly.BubbleDragger.prototype.startBubbleDrag = function() { * @package */ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { - var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); + const newLoc = Blockly.utils.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. @@ -155,8 +155,8 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { */ Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { if (dragTarget) { - var componentManager = this.workspace_.getComponentManager(); - var isDeleteArea = componentManager.hasCapability(dragTarget.id, + const componentManager = this.workspace_.getComponentManager(); + const isDeleteArea = componentManager.hasCapability(dragTarget.id, Blockly.ComponentManager.Capability.DELETE_AREA); if (isDeleteArea) { return (/** @type {!Blockly.IDeleteArea} */ (dragTarget)) @@ -187,13 +187,14 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( // 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 = Blockly.utils.Coordinate.sum(this.startXY_, delta); } // Move the bubble to its final location. this.draggingBubble_.moveTo(newLoc.x, newLoc.y); @@ -227,7 +228,7 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( */ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { - var event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( + const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( /** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_)); event.setOldCoordinate(this.startXY_); event.recordNew(); @@ -249,7 +250,7 @@ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { * @private */ Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { - var result = new Blockly.utils.Coordinate( + const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); if (this.workspace_.isMutator) { @@ -257,7 +258,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; From 42fd43b1c6e85e068e56e9fb806dade12139b808 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:14:47 -0700 Subject: [PATCH 2/5] Migrate core/bubble_dragger.js to goog.module --- core/bubble_dragger.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index bec5dba15..7b6f932d6 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.BubbleDragger'); +goog.module('Blockly.BubbleDragger'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Bubble'); @@ -36,7 +37,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @param {!Blockly.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} @@ -90,7 +91,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,7 +101,7 @@ Blockly.BubbleDragger.prototype.dispose = function() { * Start dragging a bubble. This includes moving it to the drag surface. * @package */ -Blockly.BubbleDragger.prototype.startBubbleDrag = function() { +BubbleDragger.prototype.startBubbleDrag = function() { if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); } @@ -122,7 +123,7 @@ Blockly.BubbleDragger.prototype.startBubbleDrag = function() { * moved from the position at the start of the drag, in pixel units. * @package */ -Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { +BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc); @@ -153,7 +154,7 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { * block. * @private */ -Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { +BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { if (dragTarget) { const componentManager = this.workspace_.getComponentManager(); const isDeleteArea = componentManager.hasCapability(dragTarget.id, @@ -171,7 +172,7 @@ 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_); }; @@ -182,7 +183,7 @@ Blockly.BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { * moved from the position at the start of the drag, in pixel units. * @package */ -Blockly.BubbleDragger.prototype.endBubbleDrag = function( +BubbleDragger.prototype.endBubbleDrag = function( e, currentDragDeltaXY) { // Make sure internal state is fresh. this.dragBubble(e, currentDragDeltaXY); @@ -226,7 +227,7 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( * 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) { const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( /** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_)); @@ -249,7 +250,7 @@ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { * workspace scale. * @private */ -Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { +BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); @@ -269,9 +270,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; diff --git a/tests/deps.js b/tests/deps.js index 89bb3d512..e038319d0 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -16,7 +16,7 @@ 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']); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], []); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); From fef2ccfcc8f7129e6a53dd138638e0eab7a24ee2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:57:43 -0700 Subject: [PATCH 3/5] Migrate core/bubble_dragger.js to named requires --- core/bubble_dragger.js | 63 +++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 7b6f932d6..fb4c4e4ef 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -13,48 +13,49 @@ 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 */ 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; @@ -69,7 +70,7 @@ const 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(); @@ -77,11 +78,11 @@ const 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; }; @@ -102,8 +103,8 @@ BubbleDragger.prototype.dispose = function() { * @package */ BubbleDragger.prototype.startBubbleDrag = function() { - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!Events.getGroup()) { + Events.setGroup(true); } this.workspace_.setResizesEnabled(false); @@ -119,13 +120,13 @@ 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 */ BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc); const oldDragTarget = this.dragTarget_; @@ -148,7 +149,7 @@ 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. @@ -158,9 +159,9 @@ BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { if (dragTarget) { const componentManager = this.workspace_.getComponentManager(); const isDeleteArea = componentManager.hasCapability(dragTarget.id, - Blockly.ComponentManager.Capability.DELETE_AREA); + ComponentManager.Capability.DELETE_AREA); if (isDeleteArea) { - return (/** @type {!Blockly.IDeleteArea} */ (dragTarget)) + return (/** @type {!IDeleteArea} */ (dragTarget)) .wouldDelete(this.draggingBubble_, false); } } @@ -179,7 +180,7 @@ BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { /** * 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 */ @@ -195,7 +196,7 @@ BubbleDragger.prototype.endBubbleDrag = function( newLoc = this.startXY_; } else { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + newLoc = Coordinate.sum(this.startXY_, delta); } // Move the bubble to its final location. this.draggingBubble_.moveTo(newLoc.x, newLoc.y); @@ -220,7 +221,7 @@ BubbleDragger.prototype.endBubbleDrag = function( } this.workspace_.setResizesEnabled(true); - Blockly.Events.setGroup(false); + Events.setGroup(false); }; /** @@ -229,11 +230,11 @@ BubbleDragger.prototype.endBubbleDrag = function( */ BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { - const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( + 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; @@ -244,14 +245,14 @@ 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 */ BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { - const result = new Blockly.utils.Coordinate( + const result = new Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); if (this.workspace_.isMutator) { From d9f024eb9e8fa599dcdb6f6988be7010ec03b6d2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:58:30 -0700 Subject: [PATCH 4/5] clang-format core/bubble_dragger.js --- core/bubble_dragger.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index fb4c4e4ef..d5cb8beae 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -158,8 +158,8 @@ BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { if (dragTarget) { const componentManager = this.workspace_.getComponentManager(); - const isDeleteArea = componentManager.hasCapability(dragTarget.id, - ComponentManager.Capability.DELETE_AREA); + const isDeleteArea = componentManager.hasCapability( + dragTarget.id, ComponentManager.Capability.DELETE_AREA); if (isDeleteArea) { return (/** @type {!IDeleteArea} */ (dragTarget)) .wouldDelete(this.draggingBubble_, false); @@ -184,8 +184,7 @@ BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { * moved from the position at the start of the drag, in pixel units. * @package */ -BubbleDragger.prototype.endBubbleDrag = function( - e, currentDragDeltaXY) { +BubbleDragger.prototype.endBubbleDrag = function(e, currentDragDeltaXY) { // Make sure internal state is fresh. this.dragBubble(e, currentDragDeltaXY); From daa0b3bfb557482579c8e30cbe61320f14c0ed27 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 09:26:17 -0700 Subject: [PATCH 5/5] Add TODO for resolving WorkspaceCommentSvg require issue --- core/bubble_dragger.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index d5cb8beae..3a6d36331 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -229,6 +229,7 @@ BubbleDragger.prototype.endBubbleDrag = function(e, currentDragDeltaXY) { */ BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { + // 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_);