From 1941e857e3564b6aa9ad323b607d66559ef1fe5b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:51:58 -0700 Subject: [PATCH 1/4] Migrate core/grid.js to ES6 const/let --- core/grid.js | 10 +++++----- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/grid.js b/core/grid.js index 56171ef50..b01d59dbd 100644 --- a/core/grid.js +++ b/core/grid.js @@ -125,14 +125,14 @@ Blockly.Grid.prototype.getPatternId = function() { Blockly.Grid.prototype.update = function(scale) { this.scale_ = scale; // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. - var safeSpacing = (this.spacing_ * scale) || 100; + const safeSpacing = (this.spacing_ * scale) || 100; this.gridPattern_.setAttribute('width', safeSpacing); this.gridPattern_.setAttribute('height', safeSpacing); - var half = Math.floor(this.spacing_ / 2) + 0.5; - var start = half - this.length_ / 2; - var end = half + this.length_ / 2; + let half = Math.floor(this.spacing_ / 2) + 0.5; + let start = half - this.length_ / 2; + let end = half + this.length_ / 2; half *= scale; start *= scale; @@ -197,7 +197,7 @@ Blockly.Grid.createDom = function(rnd, gridOptions, defs) { */ - var gridPattern = Blockly.utils.dom.createSvgElement( + const gridPattern = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATTERN, { 'id': 'blocklyGridPattern' + rnd, diff --git a/tests/deps.js b/tests/deps.js index f62333982..25dd37c2e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -67,7 +67,7 @@ goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); From 4c7ac8dd382cd2cc8d2dd46c4e9eabf7af86def4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:54:43 -0700 Subject: [PATCH 2/4] Migrate core/grid.js to goog.module --- core/grid.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/grid.js b/core/grid.js index b01d59dbd..48189fe69 100644 --- a/core/grid.js +++ b/core/grid.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Grid'); +goog.module('Blockly.Grid'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); @@ -27,7 +28,7 @@ goog.require('Blockly.utils.userAgent'); * https://developers.google.com/blockly/guides/configure/web/grid * @constructor */ -Blockly.Grid = function(pattern, options) { +const Grid = function(pattern, options) { /** * The grid's SVG pattern, created during injection. * @type {!SVGElement} @@ -78,14 +79,14 @@ Blockly.Grid = function(pattern, options) { * @type {number} * @private */ -Blockly.Grid.prototype.scale_ = 1; +Grid.prototype.scale_ = 1; /** * Dispose of this grid and unlink from the DOM. * @package * @suppress {checkTypes} */ -Blockly.Grid.prototype.dispose = function() { +Grid.prototype.dispose = function() { this.gridPattern_ = null; }; @@ -94,7 +95,7 @@ Blockly.Grid.prototype.dispose = function() { * @return {boolean} True if blocks should snap, false otherwise. * @package */ -Blockly.Grid.prototype.shouldSnap = function() { +Grid.prototype.shouldSnap = function() { return this.snapToGrid_; }; @@ -103,7 +104,7 @@ Blockly.Grid.prototype.shouldSnap = function() { * @return {number} The spacing of the grid points. * @package */ -Blockly.Grid.prototype.getSpacing = function() { +Grid.prototype.getSpacing = function() { return this.spacing_; }; @@ -113,7 +114,7 @@ Blockly.Grid.prototype.getSpacing = function() { * @return {string} The pattern ID. * @package */ -Blockly.Grid.prototype.getPatternId = function() { +Grid.prototype.getPatternId = function() { return this.gridPattern_.id; }; @@ -122,7 +123,7 @@ Blockly.Grid.prototype.getPatternId = function() { * @param {number} scale The new workspace scale. * @package */ -Blockly.Grid.prototype.update = function(scale) { +Grid.prototype.update = function(scale) { this.scale_ = scale; // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. const safeSpacing = (this.spacing_ * scale) || 100; @@ -153,7 +154,7 @@ Blockly.Grid.prototype.update = function(scale) { * @param {number} y2 The new y end position of the line (in px). * @private */ -Blockly.Grid.prototype.setLineAttributes_ = function(line, width, +Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) { if (line) { line.setAttribute('stroke-width', width); @@ -171,7 +172,7 @@ Blockly.Grid.prototype.setLineAttributes_ = function(line, width, * @param {number} y The new y position of the grid (in px). * @package */ -Blockly.Grid.prototype.moveTo = function(x, y) { +Grid.prototype.moveTo = function(x, y) { this.gridPattern_.setAttribute('x', x); this.gridPattern_.setAttribute('y', y); @@ -190,7 +191,7 @@ Blockly.Grid.prototype.moveTo = function(x, y) { * @return {!SVGElement} The SVG element for the grid pattern. * @package */ -Blockly.Grid.createDom = function(rnd, gridOptions, defs) { +Grid.createDom = function(rnd, gridOptions, defs) { /* @@ -220,3 +221,5 @@ Blockly.Grid.createDom = function(rnd, gridOptions, defs) { } return gridPattern; }; + +exports = Grid; diff --git a/tests/deps.js b/tests/deps.js index 25dd37c2e..f6a0972e2 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -67,7 +67,7 @@ goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6'}); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); From 25cb8773cd0627fe8c6066a5bf6c2198f2de5cac Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:59:42 -0700 Subject: [PATCH 3/4] Migrate core/grid.js to named requires --- core/grid.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/grid.js b/core/grid.js index 48189fe69..b93a39fa1 100644 --- a/core/grid.js +++ b/core/grid.js @@ -14,9 +14,9 @@ goog.module('Blockly.Grid'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); +const userAgent = goog.require('Blockly.utils.userAgent'); /** @@ -176,7 +176,7 @@ Grid.prototype.moveTo = function(x, y) { this.gridPattern_.setAttribute('x', x); this.gridPattern_.setAttribute('y', y); - if (Blockly.utils.userAgent.IE || Blockly.utils.userAgent.EDGE) { + if (userAgent.IE || userAgent.EDGE) { // IE/Edge doesn't notice that the x/y offsets have changed. // Force an update. this.update(this.scale_); @@ -198,26 +198,26 @@ Grid.createDom = function(rnd, gridOptions, defs) { */ - const gridPattern = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATTERN, + const gridPattern = dom.createSvgElement( + Svg.PATTERN, { 'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse' }, defs); if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, + dom.createSvgElement( + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, + dom.createSvgElement( + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } // x1, y1, x1, x2 properties will be set later in update. } else { // Edge 16 doesn't handle empty patterns - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, {}, gridPattern); + dom.createSvgElement( + Svg.LINE, {}, gridPattern); } return gridPattern; }; From d36abd2b338117eb4ca248346926bdc5f36e7c2f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:00:09 -0700 Subject: [PATCH 4/4] clang-format core/grid.js --- core/grid.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/core/grid.js b/core/grid.js index b93a39fa1..1a1d5f2a3 100644 --- a/core/grid.js +++ b/core/grid.js @@ -62,8 +62,8 @@ const Grid = function(pattern, options) { * @type {SVGElement} * @private */ - this.line2_ = this.line1_ && - (/** @type {SVGElement} */ (this.line1_.nextSibling)); + this.line2_ = + this.line1_ && (/** @type {SVGElement} */ (this.line1_.nextSibling)); /** * Whether blocks should snap to the grid. @@ -154,8 +154,7 @@ Grid.prototype.update = function(scale) { * @param {number} y2 The new y end position of the line (in px). * @private */ -Grid.prototype.setLineAttributes_ = function(line, width, - x1, x2, y1, y2) { +Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) { if (line) { line.setAttribute('stroke-width', width); line.setAttribute('x1', x1); @@ -200,24 +199,19 @@ Grid.createDom = function(rnd, gridOptions, defs) { */ const gridPattern = dom.createSvgElement( Svg.PATTERN, - { - 'id': 'blocklyGridPattern' + rnd, - 'patternUnits': 'userSpaceOnUse' - }, defs); + {'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse'}, + defs); if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { dom.createSvgElement( - Svg.LINE, - {'stroke': gridOptions['colour']}, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { dom.createSvgElement( - Svg.LINE, - {'stroke': gridOptions['colour']}, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } // x1, y1, x1, x2 properties will be set later in update. } else { // Edge 16 doesn't handle empty patterns - dom.createSvgElement( - Svg.LINE, {}, gridPattern); + dom.createSvgElement(Svg.LINE, {}, gridPattern); } return gridPattern; };