From c068a3b6f9dcd304278bd5aa87a0d66460d698df Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:26:04 -0700 Subject: [PATCH 1/3] Migrate core/renderers/common/path_object.js to goog.module --- core/renderers/common/path_object.js | 39 +++++++++++++++------------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index e81b8e0e2..c6de3c492 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.blockRendering.PathObject'); +goog.module('Blockly.blockRendering.PathObject'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.blockRendering.IPathObject'); @@ -35,7 +36,7 @@ goog.requireType('Blockly.Connection'); * @implements {Blockly.blockRendering.IPathObject} * @package */ -Blockly.blockRendering.PathObject = function(root, style, constants) { +const PathObject = function(root, style, constants) { /** * The renderer's constant provider. * @type {!Blockly.blockRendering.ConstantProvider} @@ -83,7 +84,7 @@ Blockly.blockRendering.PathObject = function(root, style, constants) { * @param {string} pathString The path. * @package */ -Blockly.blockRendering.PathObject.prototype.setPath = function(pathString) { +PathObject.prototype.setPath = function(pathString) { this.svgPath.setAttribute('d', pathString); }; @@ -91,7 +92,7 @@ Blockly.blockRendering.PathObject.prototype.setPath = function(pathString) { * Flip the SVG paths in RTL. * @package */ -Blockly.blockRendering.PathObject.prototype.flipRTL = function() { +PathObject.prototype.flipRTL = function() { // Mirror the block's path. this.svgPath.setAttribute('transform', 'scale(-1 1)'); }; @@ -102,7 +103,7 @@ Blockly.blockRendering.PathObject.prototype.flipRTL = function() { * block SVG group. * @package */ -Blockly.blockRendering.PathObject.prototype.setCursorSvg = function(cursorSvg) { +PathObject.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg = null; return; @@ -118,7 +119,7 @@ Blockly.blockRendering.PathObject.prototype.setCursorSvg = function(cursorSvg) { * block SVG group. * @package */ -Blockly.blockRendering.PathObject.prototype.setMarkerSvg = function(markerSvg) { +PathObject.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg = null; return; @@ -138,7 +139,7 @@ Blockly.blockRendering.PathObject.prototype.setMarkerSvg = function(markerSvg) { * @param {!Blockly.Block} block The source block. * @package */ -Blockly.blockRendering.PathObject.prototype.applyColour = function(block) { +PathObject.prototype.applyColour = function(block) { this.svgPath.setAttribute('stroke', this.style.colourTertiary); this.svgPath.setAttribute('fill', this.style.colourPrimary); @@ -151,7 +152,7 @@ Blockly.blockRendering.PathObject.prototype.applyColour = function(block) { * @param {!Blockly.Theme.BlockStyle} blockStyle The block style to use. * @package */ -Blockly.blockRendering.PathObject.prototype.setStyle = function(blockStyle) { +PathObject.prototype.setStyle = function(blockStyle) { this.style = blockStyle; }; @@ -162,7 +163,7 @@ Blockly.blockRendering.PathObject.prototype.setStyle = function(blockStyle) { * be removed. * @protected */ -Blockly.blockRendering.PathObject.prototype.setClass_ = function( +PathObject.prototype.setClass_ = function( className, add) { if (add) { Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgRoot), @@ -179,7 +180,7 @@ Blockly.blockRendering.PathObject.prototype.setClass_ = function( * @param {boolean} enable True if highlighted. * @package */ -Blockly.blockRendering.PathObject.prototype.updateHighlighted = function( +PathObject.prototype.updateHighlighted = function( enable) { if (enable) { this.svgPath.setAttribute('filter', @@ -194,7 +195,7 @@ Blockly.blockRendering.PathObject.prototype.updateHighlighted = function( * @param {boolean} shadow True if the block is a shadow block. * @protected */ -Blockly.blockRendering.PathObject.prototype.updateShadow_ = function(shadow) { +PathObject.prototype.updateShadow_ = function(shadow) { if (shadow) { this.svgPath.setAttribute('stroke', 'none'); this.svgPath.setAttribute('fill', this.style.colourSecondary); @@ -206,7 +207,7 @@ Blockly.blockRendering.PathObject.prototype.updateShadow_ = function(shadow) { * @param {boolean} disabled True if disabled. * @protected */ -Blockly.blockRendering.PathObject.prototype.updateDisabled_ = function( +PathObject.prototype.updateDisabled_ = function( disabled) { this.setClass_('blocklyDisabled', disabled); if (disabled) { @@ -220,7 +221,7 @@ Blockly.blockRendering.PathObject.prototype.updateDisabled_ = function( * @param {boolean} enable True if selection is enabled, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateSelected = function(enable) { +PathObject.prototype.updateSelected = function(enable) { this.setClass_('blocklySelected', enable); }; @@ -230,7 +231,7 @@ Blockly.blockRendering.PathObject.prototype.updateSelected = function(enable) { * area, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateDraggingDelete = function( +PathObject.prototype.updateDraggingDelete = function( enable) { this.setClass_('blocklyDraggingDelete', enable); }; @@ -241,7 +242,7 @@ Blockly.blockRendering.PathObject.prototype.updateDraggingDelete = function( * otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateInsertionMarker = function( +PathObject.prototype.updateInsertionMarker = function( enable) { this.setClass_('blocklyInsertionMarker', enable); }; @@ -251,7 +252,7 @@ Blockly.blockRendering.PathObject.prototype.updateInsertionMarker = function( * @param {boolean} enable True if the block is movable, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateMovable = function(enable) { +PathObject.prototype.updateMovable = function(enable) { this.setClass_('blocklyDraggable', enable); }; @@ -262,7 +263,7 @@ Blockly.blockRendering.PathObject.prototype.updateMovable = function(enable) { * @param {boolean} enable True if styling should be added. * @package */ -Blockly.blockRendering.PathObject.prototype.updateReplacementFade = +PathObject.prototype.updateReplacementFade = function(enable) { /* eslint-disable indent */ this.setClass_('blocklyReplaceable', enable); @@ -275,8 +276,10 @@ Blockly.blockRendering.PathObject.prototype.updateReplacementFade = * @param {boolean} _enable True if styling should be added. * @package */ -Blockly.blockRendering.PathObject.prototype.updateShapeForInputHighlight = +PathObject.prototype.updateShapeForInputHighlight = function(_conn, _enable) { /* eslint-disable indent */ // NOP }; /* eslint-enable indent */ + +exports = PathObject; diff --git a/tests/deps.js b/tests/deps.js index 805416071..aa69691cb 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -126,7 +126,7 @@ goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRende goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); From cf3d22c4901b65894ce6a63151140139079173f2 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:39:02 -0700 Subject: [PATCH 2/3] Migrate core/renderers/common/path_object.js named requires --- core/renderers/common/path_object.js | 44 +++++++++++++++------------- tests/deps.js | 2 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index c6de3c492..bb3cca63a 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -14,32 +14,36 @@ goog.module('Blockly.blockRendering.PathObject'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockRendering.ConstantProvider'); -goog.require('Blockly.blockRendering.IPathObject'); -goog.require('Blockly.Theme'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ +const IPathObject = goog.require('Blockly.blockRendering.IPathObject'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +const dom = goog.require('Blockly.utils.dom'); /** * An object that handles creating and setting each of the SVG elements * used by the renderer. * @param {!SVGElement} root The root SVG element. - * @param {!Blockly.Theme.BlockStyle} style The style object to use for + * @param {!Theme.BlockStyle} style The style object to use for * colouring. - * @param {!Blockly.blockRendering.ConstantProvider} constants The renderer's + * @param {!ConstantProvider} constants The renderer's * constants. * @constructor - * @implements {Blockly.blockRendering.IPathObject} + * @implements {IPathObject} * @package */ const PathObject = function(root, style, constants) { /** * The renderer's constant provider. - * @type {!Blockly.blockRendering.ConstantProvider} + * @type {!ConstantProvider} * @package */ this.constants = constants; @@ -51,13 +55,13 @@ const PathObject = function(root, style, constants) { * @type {!SVGElement} * @package */ - this.svgPath = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + this.svgPath = dom.createSvgElement( + Svg.PATH, {'class': 'blocklyPath'}, this.svgRoot); /** * The style object to use when colouring block paths. - * @type {!Blockly.Theme.BlockStyle} + * @type {!Theme.BlockStyle} * @package */ this.style = style; @@ -136,7 +140,7 @@ PathObject.prototype.setMarkerSvg = function(markerSvg) { /** * Apply the stored colours to the block's path, taking into account whether * the paths belong to a shadow block. - * @param {!Blockly.Block} block The source block. + * @param {!Block} block The source block. * @package */ PathObject.prototype.applyColour = function(block) { @@ -149,7 +153,7 @@ PathObject.prototype.applyColour = function(block) { /** * Set the style. - * @param {!Blockly.Theme.BlockStyle} blockStyle The block style to use. + * @param {!Theme.BlockStyle} blockStyle The block style to use. * @package */ PathObject.prototype.setStyle = function(blockStyle) { @@ -166,10 +170,10 @@ PathObject.prototype.setStyle = function(blockStyle) { PathObject.prototype.setClass_ = function( className, add) { if (add) { - Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgRoot), + dom.addClass(/** @type {!Element} */ (this.svgRoot), className); } else { - Blockly.utils.dom.removeClass(/** @type {!Element} */ (this.svgRoot), + dom.removeClass(/** @type {!Element} */ (this.svgRoot), className); } }; @@ -272,7 +276,7 @@ PathObject.prototype.updateReplacementFade = /** * Add or remove styling that shows that if the dragging block is dropped, this * block will be connected to the input. - * @param {Blockly.Connection} _conn The connection on the input to highlight. + * @param {Connection} _conn The connection on the input to highlight. * @param {boolean} _enable True if styling should be added. * @package */ diff --git a/tests/deps.js b/tests/deps.js index aa69691cb..8d394ea2f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -126,7 +126,7 @@ goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRende goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); From 55207a2e7fd152412d0a41740e5dfdc17201a705 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:41:29 -0700 Subject: [PATCH 3/3] clang-format core/renderers/common/path_object.js --- core/renderers/common/path_object.js | 46 ++++++++++------------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index bb3cca63a..7b1f6af9d 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -55,9 +55,8 @@ const PathObject = function(root, style, constants) { * @type {!SVGElement} * @package */ - this.svgPath = dom.createSvgElement( - Svg.PATH, - {'class': 'blocklyPath'}, this.svgRoot); + this.svgPath = + dom.createSvgElement(Svg.PATH, {'class': 'blocklyPath'}, this.svgRoot); /** * The style object to use when colouring block paths. @@ -167,14 +166,11 @@ PathObject.prototype.setStyle = function(blockStyle) { * be removed. * @protected */ -PathObject.prototype.setClass_ = function( - className, add) { +PathObject.prototype.setClass_ = function(className, add) { if (add) { - dom.addClass(/** @type {!Element} */ (this.svgRoot), - className); + dom.addClass(/** @type {!Element} */ (this.svgRoot), className); } else { - dom.removeClass(/** @type {!Element} */ (this.svgRoot), - className); + dom.removeClass(/** @type {!Element} */ (this.svgRoot), className); } }; @@ -184,11 +180,10 @@ PathObject.prototype.setClass_ = function( * @param {boolean} enable True if highlighted. * @package */ -PathObject.prototype.updateHighlighted = function( - enable) { +PathObject.prototype.updateHighlighted = function(enable) { if (enable) { - this.svgPath.setAttribute('filter', - 'url(#' + this.constants.embossFilterId + ')'); + this.svgPath.setAttribute( + 'filter', 'url(#' + this.constants.embossFilterId + ')'); } else { this.svgPath.setAttribute('filter', 'none'); } @@ -211,12 +206,11 @@ PathObject.prototype.updateShadow_ = function(shadow) { * @param {boolean} disabled True if disabled. * @protected */ -PathObject.prototype.updateDisabled_ = function( - disabled) { +PathObject.prototype.updateDisabled_ = function(disabled) { this.setClass_('blocklyDisabled', disabled); if (disabled) { - this.svgPath.setAttribute('fill', - 'url(#' + this.constants.disabledPatternId + ')'); + this.svgPath.setAttribute( + 'fill', 'url(#' + this.constants.disabledPatternId + ')'); } }; @@ -235,8 +229,7 @@ PathObject.prototype.updateSelected = function(enable) { * area, false otherwise. * @package */ -PathObject.prototype.updateDraggingDelete = function( - enable) { +PathObject.prototype.updateDraggingDelete = function(enable) { this.setClass_('blocklyDraggingDelete', enable); }; @@ -246,8 +239,7 @@ PathObject.prototype.updateDraggingDelete = function( * otherwise. * @package */ -PathObject.prototype.updateInsertionMarker = function( - enable) { +PathObject.prototype.updateInsertionMarker = function(enable) { this.setClass_('blocklyInsertionMarker', enable); }; @@ -267,11 +259,9 @@ PathObject.prototype.updateMovable = function(enable) { * @param {boolean} enable True if styling should be added. * @package */ -PathObject.prototype.updateReplacementFade = - function(enable) { - /* eslint-disable indent */ +PathObject.prototype.updateReplacementFade = function(enable) { this.setClass_('blocklyReplaceable', enable); -}; /* eslint-enable indent */ +}; /** * Add or remove styling that shows that if the dragging block is dropped, this @@ -280,10 +270,8 @@ PathObject.prototype.updateReplacementFade = * @param {boolean} _enable True if styling should be added. * @package */ -PathObject.prototype.updateShapeForInputHighlight = - function(_conn, _enable) { - /* eslint-disable indent */ +PathObject.prototype.updateShapeForInputHighlight = function(_conn, _enable) { // NOP -}; /* eslint-enable indent */ +}; exports = PathObject;