From 46e00f6ac99f8a82a65fd7d2e6beee124c7d6e3c Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:58:23 -0700 Subject: [PATCH 1/7] Migrate core/block_drag_surface.js to ES6 const/let --- core/block_drag_surface.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index b2a2cda0f..f1db819e8 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -134,8 +134,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. - var fixedX = x.toFixed(0); - var fixedY = y.toFixed(0); + const fixedX = x.toFixed(0); + const fixedY = y.toFixed(0); this.childSurfaceXY_.x = parseInt(fixedX, 10); this.childSurfaceXY_.y = parseInt(fixedY, 10); @@ -150,8 +150,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( * @private */ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { - var x = this.surfaceXY_.x; - var y = this.surfaceXY_.y; + let x = this.surfaceXY_.x; + let y = this.surfaceXY_.y; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. x = x.toFixed(0); @@ -168,8 +168,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { * @param {number} deltaY Vertical offset in pixel units. */ Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { - var x = this.surfaceXY_.x + deltaX; - var y = this.surfaceXY_.y + deltaY; + const x = this.surfaceXY_.x + deltaX; + const y = this.surfaceXY_.y + deltaY; this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); this.translateSurfaceInternal_(); }; @@ -194,7 +194,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { * @return {!Blockly.utils.Coordinate} Current translation of the surface. */ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { - var xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); + const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ + (this.SVG_)); return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); }; From 4689c30634227e2d6da1294ea2475b5be2555d36 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:02:05 -0700 Subject: [PATCH 2/7] Migrate core/block_drag_surface.js to goog.module --- core/block_drag_surface.js | 46 +++++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index f1db819e8..f5bb42aea 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -15,7 +15,9 @@ 'use strict'; -goog.provide('Blockly.BlockDragSurfaceSvg'); +goog.module('Blockly.BlockDragSurfaceSvg'); +goog.module.declareLegacyNamespace(); + goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -28,7 +30,7 @@ goog.require('Blockly.utils.Svg'); * @param {!Element} container Containing element. * @constructor */ -Blockly.BlockDragSurfaceSvg = function(container) { +const BlockDragSurfaceSvg = function(container) { /** * @type {!Element} * @private @@ -38,11 +40,11 @@ Blockly.BlockDragSurfaceSvg = function(container) { }; /** - * The SVG drag surface. Set once by Blockly.BlockDragSurfaceSvg.createDom. + * The SVG drag surface. Set once by BlockDragSurfaceSvg.createDom. * @type {?SVGElement} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null; +BlockDragSurfaceSvg.prototype.SVG_ = null; /** * This is where blocks live while they are being dragged if the drag surface @@ -50,14 +52,14 @@ Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null; * @type {?SVGElement} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.dragGroup_ = null; +BlockDragSurfaceSvg.prototype.dragGroup_ = null; /** * Containing HTML element; parent of the workspace and the drag surface. * @type {?Element} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.container_ = null; +BlockDragSurfaceSvg.prototype.container_ = null; /** * Cached value for the scale of the drag surface. @@ -65,7 +67,7 @@ Blockly.BlockDragSurfaceSvg.prototype.container_ = null; * @type {number} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.scale_ = 1; +BlockDragSurfaceSvg.prototype.scale_ = 1; /** * Cached value for the translation of the drag surface. @@ -74,7 +76,7 @@ Blockly.BlockDragSurfaceSvg.prototype.scale_ = 1; * @type {?Blockly.utils.Coordinate} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.surfaceXY_ = null; +BlockDragSurfaceSvg.prototype.surfaceXY_ = null; /** * Cached value for the translation of the child drag surface in pixel units. @@ -83,13 +85,13 @@ Blockly.BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * @type {!Blockly.utils.Coordinate} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.childSurfaceXY_ = +BlockDragSurfaceSvg.prototype.childSurfaceXY_ = new Blockly.utils.Coordinate(0, 0); /** * Create the drag surface and inject it into the container. */ -Blockly.BlockDragSurfaceSvg.prototype.createDom = function() { +BlockDragSurfaceSvg.prototype.createDom = function() { if (this.SVG_) { return; // Already created. } @@ -112,7 +114,7 @@ Blockly.BlockDragSurfaceSvg.prototype.createDom = function() { * @param {!SVGElement} blocks Block or group of blocks to place on the drag * surface. */ -Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { +BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { if (this.dragGroup_.childNodes.length) { throw Error('Already dragging a block.'); } @@ -129,7 +131,7 @@ Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { * @param {number} y Y translation in pixel coordinates. * @param {number} scale Scale of the group. */ -Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( +BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( x, y, scale) { this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering @@ -149,7 +151,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( * Translate the drag surface's SVG based on its internal state. * @private */ -Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { +BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { let x = this.surfaceXY_.x; let y = this.surfaceXY_.y; // This is a work-around to prevent a the blocks from rendering @@ -167,7 +169,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { * @param {number} deltaX Horizontal offset in pixel units. * @param {number} deltaY Vertical offset in pixel units. */ -Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { +BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { const x = this.surfaceXY_.x + deltaX; const y = this.surfaceXY_.y + deltaY; this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); @@ -182,7 +184,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { * @param {number} x X translation for the entire surface. * @param {number} y Y translation for the entire surface. */ -Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { +BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { this.surfaceXY_ = new Blockly.utils.Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); @@ -193,7 +195,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { * Use this when finishing a drag to return blocks to the correct position. * @return {!Blockly.utils.Coordinate} Current translation of the surface. */ -Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { +BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); @@ -204,7 +206,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { * BlockSvg.getRelativeToSurfaceXY). * @return {?SVGElement} Drag surface group element. */ -Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() { +BlockDragSurfaceSvg.prototype.getGroup = function() { return this.dragGroup_; }; @@ -212,7 +214,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() { * Returns the SVG drag surface. * @returns {?SVGElement} The SVG drag surface. */ -Blockly.BlockDragSurfaceSvg.prototype.getSvgRoot = function() { +BlockDragSurfaceSvg.prototype.getSvgRoot = function() { return this.SVG_; }; @@ -221,7 +223,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getSvgRoot = function() { * for BlockSvg.getRelativeToSurfaceXY). * @return {?Element} Drag surface block DOM element, or null if no blocks exist. */ -Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { +BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { return /** @type {Element} */ (this.dragGroup_.firstChild); }; @@ -231,7 +233,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { * moved. * @return {!Blockly.utils.Coordinate} The amount the workspace has been moved. */ -Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() { +BlockDragSurfaceSvg.prototype.getWsTranslation = function() { // Returning a copy so the coordinate can not be changed outside this class. return this.childSurfaceXY_.clone(); }; @@ -245,7 +247,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() { * to, or null if the blocks should be removed from this surface without * being moved to a different surface. */ -Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { +BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { if (opt_newSurface) { // appendChild removes the node from this.dragGroup_ opt_newSurface.appendChild(this.getCurrentBlock()); @@ -258,3 +260,5 @@ Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { } this.surfaceXY_ = null; }; + +exports = BlockDragSurfaceSvg; diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..2edd38475 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -9,7 +9,7 @@ goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Bl goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); From 18996f3aac825b35a4b79c26c813d32c98017076 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:10:57 -0700 Subject: [PATCH 3/7] Migrate core/block_drag_surface.js named requires --- core/block_drag_surface.js | 43 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index f5bb42aea..7b573fcfd 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -18,10 +18,10 @@ goog.module('Blockly.BlockDragSurfaceSvg'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const {G, SVG} = goog.require('Blockly.utils.Svg'); +const {getRelativeXY} = goog.require('Blockly.utils'); +const {createSvgElement, HTML_NS, setCssTransform, SVG_NS, XLINK_NS} = goog.require('Blockly.utils.dom'); /** @@ -73,7 +73,7 @@ BlockDragSurfaceSvg.prototype.scale_ = 1; * Cached value for the translation of the drag surface. * This translation is in pixel units, because the scale is applied to the * drag group rather than the top-level SVG. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @private */ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; @@ -82,11 +82,11 @@ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * Cached value for the translation of the child drag surface in pixel units. * Since the child drag surface tracks the translation of the workspace this is * ultimately the translation of the workspace. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ BlockDragSurfaceSvg.prototype.childSurfaceXY_ = - new Blockly.utils.Coordinate(0, 0); + new Coordinate(0, 0); /** * Create the drag surface and inject it into the container. @@ -95,17 +95,17 @@ BlockDragSurfaceSvg.prototype.createDom = function() { if (this.SVG_) { return; // Already created. } - this.SVG_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.SVG, { - 'xmlns': Blockly.utils.dom.SVG_NS, - 'xmlns:html': Blockly.utils.dom.HTML_NS, - 'xmlns:xlink': Blockly.utils.dom.XLINK_NS, + this.SVG_ = createSvgElement( + SVG, { + 'xmlns': SVG_NS, + 'xmlns:html': HTML_NS, + 'xmlns:xlink': XLINK_NS, 'version': '1.1', 'class': 'blocklyBlockDragSurface' }, this.container_); this.dragGroup_ = - Blockly.utils.dom.createSvgElement(Blockly.utils.Svg.G, {}, this.SVG_); + createSvgElement(G, {}, this.SVG_); }; /** @@ -121,7 +121,7 @@ BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { // appendChild removes the blocks from the previous parent this.dragGroup_.appendChild(blocks); this.SVG_.style.display = 'block'; - this.surfaceXY_ = new Blockly.utils.Coordinate(0, 0); + this.surfaceXY_ = new Coordinate(0, 0); }; /** @@ -160,7 +160,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { y = y.toFixed(0); this.SVG_.style.display = 'block'; - Blockly.utils.dom.setCssTransform( + setCssTransform( this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); }; @@ -172,7 +172,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { const x = this.surfaceXY_.x + deltaX; const y = this.surfaceXY_.y + deltaY; - this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); + this.surfaceXY_ = new Coordinate(x, y); this.translateSurfaceInternal_(); }; @@ -186,19 +186,18 @@ BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { */ BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { this.surfaceXY_ = - new Blockly.utils.Coordinate(x * this.scale_, y * this.scale_); + new Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); }; /** * Reports the surface translation in scaled workspace coordinates. * Use this when finishing a drag to return blocks to the correct position. - * @return {!Blockly.utils.Coordinate} Current translation of the surface. + * @return {!Coordinate} Current translation of the surface. */ BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { - const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ - (this.SVG_)); - return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); + const xy = getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); + return new Coordinate(xy.x / this.scale_, xy.y / this.scale_); }; /** @@ -231,7 +230,7 @@ BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { * Gets the translation of the child block surface * This surface is in charge of keeping track of how much the workspace has * moved. - * @return {!Blockly.utils.Coordinate} The amount the workspace has been moved. + * @return {!Coordinate} The amount the workspace has been moved. */ BlockDragSurfaceSvg.prototype.getWsTranslation = function() { // Returning a copy so the coordinate can not be changed outside this class. From 5a834a9ec9874a501ff7fe8eb46778668a147c16 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:11:19 -0700 Subject: [PATCH 4/7] clang-format core/block_drag_surface.js --- core/block_drag_surface.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 7b573fcfd..69b7a5ca5 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -85,8 +85,7 @@ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * @type {!Coordinate} * @private */ -BlockDragSurfaceSvg.prototype.childSurfaceXY_ = - new Coordinate(0, 0); +BlockDragSurfaceSvg.prototype.childSurfaceXY_ = new Coordinate(0, 0); /** * Create the drag surface and inject it into the container. @@ -104,8 +103,7 @@ BlockDragSurfaceSvg.prototype.createDom = function() { 'class': 'blocklyBlockDragSurface' }, this.container_); - this.dragGroup_ = - createSvgElement(G, {}, this.SVG_); + this.dragGroup_ = createSvgElement(G, {}, this.SVG_); }; /** @@ -131,8 +129,7 @@ BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { * @param {number} y Y translation in pixel coordinates. * @param {number} scale Scale of the group. */ -BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( - x, y, scale) { +BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function(x, y, scale) { this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. @@ -160,8 +157,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { y = y.toFixed(0); this.SVG_.style.display = 'block'; - setCssTransform( - this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); + setCssTransform(this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); }; /** @@ -185,8 +181,7 @@ BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { * @param {number} y Y translation for the entire surface. */ BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { - this.surfaceXY_ = - new Coordinate(x * this.scale_, y * this.scale_); + this.surfaceXY_ = new Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); }; @@ -220,7 +215,8 @@ BlockDragSurfaceSvg.prototype.getSvgRoot = function() { /** * Get the current blocks on the drag surface, if any (primarily * for BlockSvg.getRelativeToSurfaceXY). - * @return {?Element} Drag surface block DOM element, or null if no blocks exist. + * @return {?Element} Drag surface block DOM element, or null if no blocks + * exist. */ BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { return /** @type {Element} */ (this.dragGroup_.firstChild); From 81b16abb92d4a89e0c40ecce8aa4cb7126e324a8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 16:54:21 -0700 Subject: [PATCH 5/7] Migrate core/utils/metrics.js to goog.module --- core/utils/metrics.js | 49 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/core/utils/metrics.js b/core/utils/metrics.js index 226ef0734..55cadfae9 100644 --- a/core/utils/metrics.js +++ b/core/utils/metrics.js @@ -14,139 +14,142 @@ * @name Blockly.utils.Metrics * @namespace */ -goog.provide('Blockly.utils.Metrics'); +goog.module('Blockly.utils.Metrics'); +goog.module.declareLegacyNamespace(); /** * @record */ -Blockly.utils.Metrics = function() {}; +const Metrics = function() {}; /** * Height of the visible portion of the workspace. * @type {number} */ -Blockly.utils.Metrics.prototype.viewHeight; +Metrics.prototype.viewHeight; /** * Width of the visible portion of the workspace. * @type {number} */ -Blockly.utils.Metrics.prototype.viewWidth; +Metrics.prototype.viewWidth; /** * Height of the content. * @type {number} */ -Blockly.utils.Metrics.prototype.contentHeight; +Metrics.prototype.contentHeight; /** * Width of the content. * @type {number} */ -Blockly.utils.Metrics.prototype.contentWidth; +Metrics.prototype.contentWidth; /** * Height of the scroll area. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollHeight; +Metrics.prototype.scrollHeight; /** * Width of the scroll area. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollWidth; +Metrics.prototype.scrollWidth; /** * Top-edge of the visible portion of the workspace, relative to the workspace * origin. * @type {number} */ -Blockly.utils.Metrics.prototype.viewTop; +Metrics.prototype.viewTop; /** * Left-edge of the visible portion of the workspace, relative to the workspace * origin. * @type {number} */ -Blockly.utils.Metrics.prototype.viewLeft; +Metrics.prototype.viewLeft; /** * Top-edge of the content, relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.contentTop; +Metrics.prototype.contentTop; /** * Left-edge of the content relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.contentLeft; +Metrics.prototype.contentLeft; /** * Top-edge of the scroll area, relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollTop; +Metrics.prototype.scrollTop; /** * Left-edge of the scroll area relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollLeft; +Metrics.prototype.scrollLeft; /** * Top-edge of the visible portion of the workspace, relative to the blocklyDiv. * @type {number} */ -Blockly.utils.Metrics.prototype.absoluteTop; +Metrics.prototype.absoluteTop; /** * Left-edge of the visible portion of the workspace, relative to the * blocklyDiv. * @type {number} */ -Blockly.utils.Metrics.prototype.absoluteLeft; +Metrics.prototype.absoluteLeft; /** * Height of the Blockly div (the view + the toolbox, simple of otherwise). * @type {number} */ -Blockly.utils.Metrics.prototype.svgHeight; +Metrics.prototype.svgHeight; /** * Width of the Blockly div (the view + the toolbox, simple or otherwise). * @type {number} */ -Blockly.utils.Metrics.prototype.svgWidth; +Metrics.prototype.svgWidth; /** * Width of the toolbox, if it exists. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxWidth; +Metrics.prototype.toolboxWidth; /** * Height of the toolbox, if it exists. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxHeight; +Metrics.prototype.toolboxHeight; /** * Top, bottom, left or right. Use TOOLBOX_AT constants to compare. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxPosition; +Metrics.prototype.toolboxPosition; /** * Width of the flyout if it is always open. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.flyoutWidth; +Metrics.prototype.flyoutWidth; /** * Height of the flyout if it is always open. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.flyoutHeight; +Metrics.prototype.flyoutHeight; + +exports = Metrics; diff --git a/tests/deps.js b/tests/deps.js index 2edd38475..d1a516942 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -178,7 +178,7 @@ goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); +goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); From d8c45411300199db80218f4488f4a156a3f81f49 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:16:05 -0700 Subject: [PATCH 6/7] Migrate core/blocks.js to goog.module --- core/blocks.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/blocks.js b/core/blocks.js index 5f0d96b21..fadc62959 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -14,10 +14,13 @@ * A mapping of block type names to block prototype objects. * @name Blockly.Blocks */ -goog.provide('Blockly.Blocks'); +goog.module('Blockly.Blocks'); +goog.module.declareLegacyNamespace(); /** * A mapping of block type names to block prototype objects. * @type {!Object} */ -Blockly.Blocks = Object.create(null); +const Blocks = Object.create(null); + +exports = Blocks; diff --git a/tests/deps.js b/tests/deps.js index d1a516942..89bb3d512 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -13,7 +13,7 @@ goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfac goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], []); +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']); From 99f822665565d72b635bc59292f25d91d5bf9d37 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 15 Jul 2021 18:15:52 -0700 Subject: [PATCH 7/7] Update Blockly.Blocks type annotation --- core/blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/blocks.js b/core/blocks.js index fadc62959..37c2105ce 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -19,7 +19,7 @@ goog.module.declareLegacyNamespace(); /** * A mapping of block type names to block prototype objects. - * @type {!Object} + * @type {!Object} */ const Blocks = Object.create(null);