From 78e72222c1e82c55b04ff7a836cfec50f06e8479 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 13:48:22 -0700 Subject: [PATCH 01/36] Migrate core/utils/style.js to ES6 const/let --- core/utils/style.js | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index 1c169453d..cdb22139c 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -34,17 +34,17 @@ Blockly.utils.style.getSize = function(element) { } // Evaluate size with a temporary element. - var style = element.style; - var originalDisplay = style.display; - var originalVisibility = style.visibility; - var originalPosition = style.position; + const style = element.style; + const originalDisplay = style.display; + const originalVisibility = style.visibility; + const originalPosition = style.position; style.visibility = 'hidden'; style.position = 'absolute'; style.display = 'inline'; - var offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; - var offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; + const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; + const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; style.display = originalDisplay; style.position = originalPosition; @@ -60,8 +60,8 @@ Blockly.utils.style.getSize = function(element) { * @private */ Blockly.utils.style.getSizeWithDisplay_ = function(element) { - var offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; - var offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; + const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; + const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; return new Blockly.utils.Size(offsetWidth, offsetHeight); }; @@ -99,7 +99,7 @@ Blockly.utils.style.getStyle_ = function(element, style) { */ Blockly.utils.style.getComputedStyle = function(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { - var styles = document.defaultView.getComputedStyle(element, null); + const styles = document.defaultView.getComputedStyle(element, null); if (styles) { // element.style[..] is undefined for browser specific styles // as 'filter'. @@ -132,13 +132,13 @@ Blockly.utils.style.getCascadedStyle = function(element, style) { * @return {!Blockly.utils.Coordinate} The page offset. */ Blockly.utils.style.getPageOffset = function(el) { - var pos = new Blockly.utils.Coordinate(0, 0); - var box = el.getBoundingClientRect(); - var documentElement = document.documentElement; + const pos = new Blockly.utils.Coordinate(0, 0); + const box = el.getBoundingClientRect(); + const documentElement = document.documentElement; // Must add the scroll coordinates in to get the absolute page offset // of element since getBoundingClientRect returns relative coordinates to // the viewport. - var scrollCoord = new Blockly.utils.Coordinate( + const scrollCoord = new Blockly.utils.Coordinate( window.pageXOffset || documentElement.scrollLeft, window.pageYOffset || documentElement.scrollTop); pos.x = box.left + scrollCoord.x; @@ -153,10 +153,10 @@ Blockly.utils.style.getPageOffset = function(el) { * @return {!Blockly.utils.Coordinate} The page offset of the viewport. */ Blockly.utils.style.getViewportPageOffset = function() { - var body = document.body; - var documentElement = document.documentElement; - var scrollLeft = body.scrollLeft || documentElement.scrollLeft; - var scrollTop = body.scrollTop || documentElement.scrollTop; + const body = document.body; + const documentElement = document.documentElement; + const scrollLeft = body.scrollLeft || documentElement.scrollLeft; + const scrollTop = body.scrollTop || documentElement.scrollTop; return new Blockly.utils.Coordinate(scrollLeft, scrollTop); }; @@ -194,10 +194,10 @@ Blockly.utils.style.isRightToLeft = function(el) { * @return {!Object} The computed border widths. */ Blockly.utils.style.getBorderBox = function(element) { - var left = Blockly.utils.style.getComputedStyle(element, 'borderLeftWidth'); - var right = Blockly.utils.style.getComputedStyle(element, 'borderRightWidth'); - var top = Blockly.utils.style.getComputedStyle(element, 'borderTopWidth'); - var bottom = Blockly.utils.style.getComputedStyle(element, 'borderBottomWidth'); + const left = Blockly.utils.style.getComputedStyle(element, 'borderLeftWidth'); + const right = Blockly.utils.style.getComputedStyle(element, 'borderRightWidth'); + const top = Blockly.utils.style.getComputedStyle(element, 'borderTopWidth'); + const bottom = Blockly.utils.style.getComputedStyle(element, 'borderBottomWidth'); return { top: parseFloat(top), @@ -222,7 +222,7 @@ Blockly.utils.style.getBorderBox = function(element) { */ Blockly.utils.style.scrollIntoContainerView = function( element, container, opt_center) { - var offset = + const offset = Blockly.utils.style.getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; @@ -247,21 +247,21 @@ Blockly.utils.style.scrollIntoContainerView = function( Blockly.utils.style.getContainerOffsetToScrollInto = function( element, container, opt_center) { // Absolute position of the element's border's top left corner. - var elementPos = Blockly.utils.style.getPageOffset(element); + const elementPos = Blockly.utils.style.getPageOffset(element); // Absolute position of the container's border's top left corner. - var containerPos = Blockly.utils.style.getPageOffset(container); - var containerBorder = Blockly.utils.style.getBorderBox(container); + const containerPos = Blockly.utils.style.getPageOffset(container); + const containerBorder = Blockly.utils.style.getBorderBox(container); // Relative pos. of the element's border box to the container's content box. - var relX = elementPos.x - containerPos.x - containerBorder.left; - var relY = elementPos.y - containerPos.y - containerBorder.top; + const relX = elementPos.x - containerPos.x - containerBorder.left; + const relY = elementPos.y - containerPos.y - containerBorder.top; // How much the element can move in the container, i.e. the difference between // the element's bottom-right-most and top-left-most position where it's // fully visible. - var elementSize = Blockly.utils.style.getSizeWithDisplay_(element); - var spaceX = container.clientWidth - elementSize.width; - var spaceY = container.clientHeight - elementSize.height; - var scrollLeft = container.scrollLeft; - var scrollTop = container.scrollTop; + const elementSize = Blockly.utils.style.getSizeWithDisplay_(element); + const spaceX = container.clientWidth - elementSize.width; + const spaceY = container.clientHeight - elementSize.height; + let scrollLeft = container.scrollLeft; + let scrollTop = container.scrollTop; if (opt_center) { // All browsers round non-integer scroll positions down. scrollLeft += relX - spaceX / 2; From 656f4fc9d680fa9e5b4b577942d03900c858ef2a Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 13:58:05 -0700 Subject: [PATCH 02/36] Migrate core/utils/style.js to goog.module --- core/utils/style.js | 68 +++++++++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index cdb22139c..9447db11a 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -16,7 +16,8 @@ * @name Blockly.utils.style * @namespace */ -goog.provide('Blockly.utils.style'); +goog.module('Blockly.utils.style'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.Size'); @@ -28,9 +29,9 @@ goog.require('Blockly.utils.Size'); * @param {!Element} element Element to get size of. * @return {!Blockly.utils.Size} Object with width/height properties. */ -Blockly.utils.style.getSize = function(element) { - if (Blockly.utils.style.getStyle_(element, 'display') != 'none') { - return Blockly.utils.style.getSizeWithDisplay_(element); +const getSize = function(element) { + if (getStyle(element, 'display') != 'none') { + return getSizeWithDisplay(element); } // Evaluate size with a temporary element. @@ -59,7 +60,7 @@ Blockly.utils.style.getSize = function(element) { * @return {!Blockly.utils.Size} Object with width/height properties. * @private */ -Blockly.utils.style.getSizeWithDisplay_ = function(element) { +const getSizeWithDisplay = function(element) { const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; return new Blockly.utils.Size(offsetWidth, offsetHeight); @@ -79,9 +80,9 @@ Blockly.utils.style.getSizeWithDisplay_ = function(element) { * @return {string} Style value. * @private */ -Blockly.utils.style.getStyle_ = function(element, style) { - return Blockly.utils.style.getComputedStyle(element, style) || - Blockly.utils.style.getCascadedStyle(element, style) || +const getStyle = function(element, style) { + return getComputedStyle(element, style) || + getCascadedStyle(element, style) || (element.style && element.style[style]); }; @@ -97,7 +98,7 @@ Blockly.utils.style.getStyle_ = function(element, style) { * @param {string} property Property to get (camel-case). * @return {string} Style value. */ -Blockly.utils.style.getComputedStyle = function(element, property) { +const getComputedStyle = function(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { const styles = document.defaultView.getComputedStyle(element, null); if (styles) { @@ -120,7 +121,7 @@ Blockly.utils.style.getComputedStyle = function(element, property) { * @param {string} style Property to get (camel-case). * @return {string} Style value. */ -Blockly.utils.style.getCascadedStyle = function(element, style) { +const getCascadedStyle = function(element, style) { return /** @type {string} */ ( element.currentStyle ? element.currentStyle[style] : null); }; @@ -131,7 +132,7 @@ Blockly.utils.style.getCascadedStyle = function(element, style) { * @param {!Element} el Element to get the page offset for. * @return {!Blockly.utils.Coordinate} The page offset. */ -Blockly.utils.style.getPageOffset = function(el) { +const getPageOffset = function(el) { const pos = new Blockly.utils.Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; @@ -152,7 +153,7 @@ Blockly.utils.style.getPageOffset = function(el) { * Similar to Closure's goog.style.getViewportPageOffset * @return {!Blockly.utils.Coordinate} The page offset of the viewport. */ -Blockly.utils.style.getViewportPageOffset = function() { +const getViewportPageOffset = function() { const body = document.body; const documentElement = document.documentElement; const scrollLeft = body.scrollLeft || documentElement.scrollLeft; @@ -172,7 +173,7 @@ Blockly.utils.style.getViewportPageOffset = function() { * @param {*} isShown True to render the element in its default style, * false to disable rendering the element. */ -Blockly.utils.style.setElementShown = function(el, isShown) { +const setElementShown = function(el, isShown) { el.style.display = isShown ? '' : 'none'; }; @@ -183,8 +184,8 @@ Blockly.utils.style.setElementShown = function(el, isShown) { * @param {!Element} el The element to test. * @return {boolean} True for right to left, false for left to right. */ -Blockly.utils.style.isRightToLeft = function(el) { - return 'rtl' == Blockly.utils.style.getStyle_(el, 'direction'); +const isRightToLeft = function(el) { + return 'rtl' == getStyle(el, 'direction'); }; /** @@ -193,11 +194,11 @@ Blockly.utils.style.isRightToLeft = function(el) { * @param {!Element} element The element to get the border widths for. * @return {!Object} The computed border widths. */ -Blockly.utils.style.getBorderBox = function(element) { - const left = Blockly.utils.style.getComputedStyle(element, 'borderLeftWidth'); - const right = Blockly.utils.style.getComputedStyle(element, 'borderRightWidth'); - const top = Blockly.utils.style.getComputedStyle(element, 'borderTopWidth'); - const bottom = Blockly.utils.style.getComputedStyle(element, 'borderBottomWidth'); +const getBorderBox = function(element) { + const left = getComputedStyle(element, 'borderLeftWidth'); + const right = getComputedStyle(element, 'borderRightWidth'); + const top = getComputedStyle(element, 'borderTopWidth'); + const bottom = getComputedStyle(element, 'borderBottomWidth'); return { top: parseFloat(top), @@ -220,10 +221,10 @@ Blockly.utils.style.getBorderBox = function(element) { * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -Blockly.utils.style.scrollIntoContainerView = function( +const scrollIntoContainerView = function( element, container, opt_center) { const offset = - Blockly.utils.style.getContainerOffsetToScrollInto(element, + getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; @@ -244,20 +245,20 @@ Blockly.utils.style.scrollIntoContainerView = function( * @return {!Blockly.utils.Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ -Blockly.utils.style.getContainerOffsetToScrollInto = function( +const getContainerOffsetToScrollInto = function( element, container, opt_center) { // Absolute position of the element's border's top left corner. - const elementPos = Blockly.utils.style.getPageOffset(element); + const elementPos = getPageOffset(element); // Absolute position of the container's border's top left corner. - const containerPos = Blockly.utils.style.getPageOffset(container); - const containerBorder = Blockly.utils.style.getBorderBox(container); + const containerPos = getPageOffset(container); + const containerBorder = getBorderBox(container); // Relative pos. of the element's border box to the container's content box. const relX = elementPos.x - containerPos.x - containerBorder.left; const relY = elementPos.y - containerPos.y - containerBorder.top; // How much the element can move in the container, i.e. the difference between // the element's bottom-right-most and top-left-most position where it's // fully visible. - const elementSize = Blockly.utils.style.getSizeWithDisplay_(element); + const elementSize = getSizeWithDisplay(element); const spaceX = container.clientWidth - elementSize.width; const spaceY = container.clientHeight - elementSize.height; let scrollLeft = container.scrollLeft; @@ -279,3 +280,16 @@ Blockly.utils.style.getContainerOffsetToScrollInto = function( } return new Blockly.utils.Coordinate(scrollLeft, scrollTop); }; + +exports = { + getSize, + getComputedStyle, + getCascadedStyle, + getPageOffset, + getViewportPageOffset, + setElementShown, + isRightToLeft, + getBorderBox, + scrollIntoContainerView, + getContainerOffsetToScrollInto, +}; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..fafe772f1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -183,7 +183,7 @@ goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); -goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); +goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); From 55ac3741b7ec070315f44d97a604b048db2df43e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:10:42 -0700 Subject: [PATCH 03/36] Migrate core/utils/style.js to named requires --- core/utils/style.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index 9447db11a..90cfa1d9a 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -19,15 +19,15 @@ goog.module('Blockly.utils.style'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.Size'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Size = goog.require('Blockly.utils.Size'); /** * Gets the height and width of an element. * Similar to Closure's goog.style.getSize * @param {!Element} element Element to get size of. - * @return {!Blockly.utils.Size} Object with width/height properties. + * @return {!Size} Object with width/height properties. */ const getSize = function(element) { if (getStyle(element, 'display') != 'none') { @@ -51,19 +51,19 @@ const getSize = function(element) { style.position = originalPosition; style.visibility = originalVisibility; - return new Blockly.utils.Size(offsetWidth, offsetHeight); + return new Size(offsetWidth, offsetHeight); }; /** * Gets the height and width of an element when the display is not none. * @param {!Element} element Element to get size of. - * @return {!Blockly.utils.Size} Object with width/height properties. + * @return {!Size} Object with width/height properties. * @private */ const getSizeWithDisplay = function(element) { const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; - return new Blockly.utils.Size(offsetWidth, offsetHeight); + return new Size(offsetWidth, offsetHeight); }; /** @@ -130,16 +130,16 @@ const getCascadedStyle = function(element, style) { * Returns a Coordinate object relative to the top-left of the HTML document. * Similar to Closure's goog.style.getPageOffset * @param {!Element} el Element to get the page offset for. - * @return {!Blockly.utils.Coordinate} The page offset. + * @return {!Coordinate} The page offset. */ const getPageOffset = function(el) { - const pos = new Blockly.utils.Coordinate(0, 0); + const pos = new Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; // Must add the scroll coordinates in to get the absolute page offset // of element since getBoundingClientRect returns relative coordinates to // the viewport. - const scrollCoord = new Blockly.utils.Coordinate( + const scrollCoord = new Coordinate( window.pageXOffset || documentElement.scrollLeft, window.pageYOffset || documentElement.scrollTop); pos.x = box.left + scrollCoord.x; @@ -151,14 +151,14 @@ const getPageOffset = function(el) { /** * Calculates the viewport coordinates relative to the document. * Similar to Closure's goog.style.getViewportPageOffset - * @return {!Blockly.utils.Coordinate} The page offset of the viewport. + * @return {!Coordinate} The page offset of the viewport. */ const getViewportPageOffset = function() { const body = document.body; const documentElement = document.documentElement; const scrollLeft = body.scrollLeft || documentElement.scrollLeft; const scrollTop = body.scrollTop || documentElement.scrollTop; - return new Blockly.utils.Coordinate(scrollLeft, scrollTop); + return new Coordinate(scrollLeft, scrollTop); }; /** @@ -242,7 +242,7 @@ const scrollIntoContainerView = function( * document scroll element will be used. * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. - * @return {!Blockly.utils.Coordinate} The new scroll position of the container, + * @return {!Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ const getContainerOffsetToScrollInto = function( @@ -278,7 +278,7 @@ const getContainerOffsetToScrollInto = function( scrollLeft += Math.min(relX, Math.max(relX - spaceX, 0)); scrollTop += Math.min(relY, Math.max(relY - spaceY, 0)); } - return new Blockly.utils.Coordinate(scrollLeft, scrollTop); + return new Coordinate(scrollLeft, scrollTop); }; exports = { From 46a3462026e158f5821207bd32bc1f3836371b87 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:11:25 -0700 Subject: [PATCH 04/36] clang-format core/utils/style.js --- core/utils/style.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index 90cfa1d9a..028b746b8 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -81,8 +81,7 @@ const getSizeWithDisplay = function(element) { * @private */ const getStyle = function(element, style) { - return getComputedStyle(element, style) || - getCascadedStyle(element, style) || + return getComputedStyle(element, style) || getCascadedStyle(element, style) || (element.style && element.style[style]); }; @@ -221,11 +220,8 @@ const getBorderBox = function(element) { * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -const scrollIntoContainerView = function( - element, container, opt_center) { - const offset = - getContainerOffsetToScrollInto(element, - container, opt_center); +const scrollIntoContainerView = function(element, container, opt_center) { + const offset = getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; }; From 4c93a048f25d0313bcd65a4a3bd57a5606cac4a4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:09:43 -0700 Subject: [PATCH 05/36] 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 06/36] 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 07/36] 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 08/36] 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 29c560dfbb225d702f95a30a9560baca65a4e457 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:26:36 -0700 Subject: [PATCH 09/36] Migrate core/connection_checker.js to ES6 const/let --- core/connection_checker.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 004d5e3f3..d0e4576c2 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -64,14 +64,14 @@ Blockly.ConnectionChecker.prototype.canConnect = function(a, b, */ Blockly.ConnectionChecker.prototype.canConnectWithReason = function( a, b, isDragging, opt_distance) { - var safety = this.doSafetyChecks(a, b); + const safety = this.doSafetyChecks(a, b); if (safety != Blockly.Connection.CAN_CONNECT) { return safety; } // If the safety checks passed, both connections are non-null. - var connOne = /** @type {!Blockly.Connection} **/ (a); - var connTwo = /** @type {!Blockly.Connection} **/ (b); + const connOne = /** @type {!Blockly.Connection} **/ (a); + const connTwo = /** @type {!Blockly.Connection} **/ (b); if (!this.doTypeChecks(connOne, connTwo)) { return Blockly.Connection.REASON_CHECKS_FAILED; } @@ -108,12 +108,13 @@ Blockly.ConnectionChecker.prototype.getErrorMessage = function(errorCode, return 'Attempt to connect incompatible types.'; case Blockly.Connection.REASON_TARGET_NULL: return 'Target connection is null.'; - case Blockly.Connection.REASON_CHECKS_FAILED: - var connOne = /** @type {!Blockly.Connection} **/ (a); - var connTwo = /** @type {!Blockly.Connection} **/ (b); - var msg = 'Connection checks failed. '; + case Blockly.Connection.REASON_CHECKS_FAILED: { + const connOne = /** @type {!Blockly.Connection} **/ (a); + const connTwo = /** @type {!Blockly.Connection} **/ (b); + let msg = 'Connection checks failed. '; msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + connTwo.getCheck(); return msg; + } case Blockly.Connection.REASON_SHADOW_PARENT: return 'Connecting non-shadow to shadow block.'; case Blockly.Connection.REASON_DRAG_CHECKS_FAILED: @@ -135,12 +136,13 @@ Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) { if (!a || !b) { return Blockly.Connection.REASON_TARGET_NULL; } + let blockA, blockB; if (a.isSuperior()) { - var blockA = a.getSourceBlock(); - var blockB = b.getSourceBlock(); + blockA = a.getSourceBlock(); + blockB = b.getSourceBlock(); } else { - var blockB = a.getSourceBlock(); - var blockA = b.getSourceBlock(); + blockB = a.getSourceBlock(); + blockA = b.getSourceBlock(); } if (blockA == blockB) { return Blockly.Connection.REASON_SELF_CONNECTION; @@ -164,15 +166,15 @@ Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) { * @public */ Blockly.ConnectionChecker.prototype.doTypeChecks = function(a, b) { - var checkArrayOne = a.getCheck(); - var checkArrayTwo = b.getCheck(); + const checkArrayOne = a.getCheck(); + const checkArrayTwo = b.getCheck(); if (!checkArrayOne || !checkArrayTwo) { // One or both sides are promiscuous enough that anything will fit. return true; } // Find any intersection in the check lists. - for (var i = 0; i < checkArrayOne.length; i++) { + for (let i = 0; i < checkArrayOne.length; i++) { if (checkArrayTwo.indexOf(checkArrayOne[i]) != -1) { return true; } @@ -274,7 +276,7 @@ Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { return true; } - var targetBlock = b.targetBlock(); + const targetBlock = b.targetBlock(); // If it is connected to a real block, game over. if (!targetBlock.isInsertionMarker()) { return false; From 50793c20cb507eceb5385c4e9f298a8702824798 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:30:16 -0700 Subject: [PATCH 10/36] Migrate core/connection_checker.js to goog.module --- core/connection_checker.js | 23 +++++++++++++---------- tests/deps.js | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index d0e4576c2..c4086a141 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.ConnectionChecker'); +goog.module('Blockly.ConnectionChecker'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Connection'); goog.require('Blockly.connectionTypes'); @@ -28,7 +29,7 @@ goog.requireType('Blockly.RenderedConnection'); * @implements {Blockly.IConnectionChecker} * @constructor */ -Blockly.ConnectionChecker = function() { +const ConnectionChecker = function() { }; /** @@ -43,7 +44,7 @@ Blockly.ConnectionChecker = function() { * @return {boolean} Whether the connection is legal. * @public */ -Blockly.ConnectionChecker.prototype.canConnect = function(a, b, +ConnectionChecker.prototype.canConnect = function(a, b, isDragging, opt_distance) { return this.canConnectWithReason(a, b, isDragging, opt_distance) == Blockly.Connection.CAN_CONNECT; @@ -62,7 +63,7 @@ Blockly.ConnectionChecker.prototype.canConnect = function(a, b, * an error code otherwise. * @public */ -Blockly.ConnectionChecker.prototype.canConnectWithReason = function( +ConnectionChecker.prototype.canConnectWithReason = function( a, b, isDragging, opt_distance) { const safety = this.doSafetyChecks(a, b); if (safety != Blockly.Connection.CAN_CONNECT) { @@ -96,7 +97,7 @@ Blockly.ConnectionChecker.prototype.canConnectWithReason = function( * @return {string} A developer-readable error string. * @public */ -Blockly.ConnectionChecker.prototype.getErrorMessage = function(errorCode, +ConnectionChecker.prototype.getErrorMessage = function(errorCode, a, b) { switch (errorCode) { case Blockly.Connection.REASON_SELF_CONNECTION: @@ -132,7 +133,7 @@ Blockly.ConnectionChecker.prototype.getErrorMessage = function(errorCode, * @return {number} An enum with the reason this connection is safe or unsafe. * @public */ -Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) { +ConnectionChecker.prototype.doSafetyChecks = function(a, b) { if (!a || !b) { return Blockly.Connection.REASON_TARGET_NULL; } @@ -165,7 +166,7 @@ Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) { * @return {boolean} True if the connections share a type. * @public */ -Blockly.ConnectionChecker.prototype.doTypeChecks = function(a, b) { +ConnectionChecker.prototype.doTypeChecks = function(a, b) { const checkArrayOne = a.getCheck(); const checkArrayTwo = b.getCheck(); @@ -191,7 +192,7 @@ Blockly.ConnectionChecker.prototype.doTypeChecks = function(a, b) { * @return {boolean} True if the connection is allowed during a drag. * @public */ -Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { +ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { if (a.distanceFrom(b) > distance) { return false; } @@ -260,7 +261,7 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { * @return {boolean} True if the connection is allowed, false otherwise. * @protected */ -Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { +ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { if (a.targetConnection) { // This connection is already occupied. // A next connection will never disconnect itself mid-drag. @@ -288,4 +289,6 @@ Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { }; Blockly.registry.register(Blockly.registry.Type.CONNECTION_CHECKER, - Blockly.registry.DEFAULT, Blockly.ConnectionChecker); + Blockly.registry.DEFAULT, ConnectionChecker); + +exports = ConnectionChecker; diff --git a/tests/deps.js b/tests/deps.js index 5f5f93d89..328c3bee3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -20,7 +20,7 @@ goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], [' 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'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); -goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); +goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); From 35cc70c52801cc5d68f27a64877943515ca0a686 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:56:16 -0700 Subject: [PATCH 11/36] Migrate core/interfaces/i_copyable.js to goog.module --- core/interfaces/i_copyable.js | 13 ++++++++----- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/interfaces/i_copyable.js b/core/interfaces/i_copyable.js index 4aeac9776..db3381fae 100644 --- a/core/interfaces/i_copyable.js +++ b/core/interfaces/i_copyable.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.ICopyable'); +goog.module('Blockly.ICopyable'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.ISelectable'); goog.requireType('Blockly.WorkspaceSvg'); @@ -21,13 +22,13 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.ISelectable} * @interface */ -Blockly.ICopyable = function() {}; +const ICopyable = function() {}; /** * Encode for copying. - * @return {?Blockly.ICopyable.CopyData} Copy metadata. + * @return {?ICopyable.CopyData} Copy metadata. */ -Blockly.ICopyable.prototype.toCopyData; +ICopyable.prototype.toCopyData; /** * Copy Metadata. @@ -37,4 +38,6 @@ Blockly.ICopyable.prototype.toCopyData; * typeCounts:?Object * }} */ -Blockly.ICopyable.CopyData; +ICopyable.CopyData; + +exports = ICopyable; diff --git a/tests/deps.js b/tests/deps.js index 5f5f93d89..230083d23 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -81,7 +81,7 @@ goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['B goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); -goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []); +goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); From fb512f8b8ecb0221bc8556c9d97d0cf697b5577c Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:57:09 -0700 Subject: [PATCH 12/36] Migrate core/interfaces/i_copyable.js named requires --- core/interfaces/i_copyable.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_copyable.js b/core/interfaces/i_copyable.js index db3381fae..07556eb23 100644 --- a/core/interfaces/i_copyable.js +++ b/core/interfaces/i_copyable.js @@ -14,12 +14,12 @@ goog.module('Blockly.ICopyable'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.ISelectable'); -goog.requireType('Blockly.WorkspaceSvg'); +const ISelectable = goog.requireType('Blockly.ISelectable'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** - * @extends {Blockly.ISelectable} + * @extends {ISelectable} * @interface */ const ICopyable = function() {}; @@ -34,7 +34,7 @@ ICopyable.prototype.toCopyData; * Copy Metadata. * @typedef {{ * xml:!Element, - * source:Blockly.WorkspaceSvg, + * source:WorkspaceSvg, * typeCounts:?Object * }} */ From e23560343ed0d9ab3fc80ae4bd908fd23e12d576 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:45:35 -0700 Subject: [PATCH 13/36] Migrate core/connection_checker.js to named requires --- core/connection_checker.js | 103 ++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index c4086a141..4c350fc9c 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -14,19 +14,18 @@ goog.module('Blockly.ConnectionChecker'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Connection'); -goog.require('Blockly.connectionTypes'); +const Connection = goog.require('Blockly.Connection'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); +const registry = goog.require('Blockly.registry'); +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.IConnectionChecker'); -goog.require('Blockly.registry'); - -goog.requireType('Blockly.RenderedConnection'); /** * Class for connection type checking logic. - * @implements {Blockly.IConnectionChecker} + * @implements {IConnectionChecker} * @constructor */ const ConnectionChecker = function() { @@ -35,8 +34,8 @@ const ConnectionChecker = function() { /** * Check whether the current connection can connect with the target * connection. - * @param {Blockly.Connection} a Connection to check compatibility with. - * @param {Blockly.Connection} b Connection to check compatibility with. + * @param {Connection} a Connection to check compatibility with. + * @param {Connection} b Connection to check compatibility with. * @param {boolean} isDragging True if the connection is being made by dragging * a block. * @param {number=} opt_distance The max allowable distance between the @@ -47,52 +46,52 @@ const ConnectionChecker = function() { ConnectionChecker.prototype.canConnect = function(a, b, isDragging, opt_distance) { return this.canConnectWithReason(a, b, isDragging, opt_distance) == - Blockly.Connection.CAN_CONNECT; + Connection.CAN_CONNECT; }; /** * Checks whether the current connection can connect with the target * connection, and return an error code if there are problems. - * @param {Blockly.Connection} a Connection to check compatibility with. - * @param {Blockly.Connection} b Connection to check compatibility with. + * @param {Connection} a Connection to check compatibility with. + * @param {Connection} b Connection to check compatibility with. * @param {boolean} isDragging True if the connection is being made by dragging * a block. * @param {number=} opt_distance The max allowable distance between the * connections for drag checks. - * @return {number} Blockly.Connection.CAN_CONNECT if the connection is legal, + * @return {number} Connection.CAN_CONNECT if the connection is legal, * an error code otherwise. * @public */ ConnectionChecker.prototype.canConnectWithReason = function( a, b, isDragging, opt_distance) { const safety = this.doSafetyChecks(a, b); - if (safety != Blockly.Connection.CAN_CONNECT) { + if (safety != Connection.CAN_CONNECT) { return safety; } // If the safety checks passed, both connections are non-null. - const connOne = /** @type {!Blockly.Connection} **/ (a); - const connTwo = /** @type {!Blockly.Connection} **/ (b); + const connOne = /** @type {!Connection} **/ (a); + const connTwo = /** @type {!Connection} **/ (b); if (!this.doTypeChecks(connOne, connTwo)) { - return Blockly.Connection.REASON_CHECKS_FAILED; + return Connection.REASON_CHECKS_FAILED; } if (isDragging && !this.doDragChecks( - /** @type {!Blockly.RenderedConnection} **/ (a), - /** @type {!Blockly.RenderedConnection} **/ (b), + /** @type {!RenderedConnection} **/ (a), + /** @type {!RenderedConnection} **/ (b), opt_distance || 0)) { - return Blockly.Connection.REASON_DRAG_CHECKS_FAILED; + return Connection.REASON_DRAG_CHECKS_FAILED; } - return Blockly.Connection.CAN_CONNECT; + return Connection.CAN_CONNECT; }; /** * Helper method that translates a connection error code into a string. * @param {number} errorCode The error code. - * @param {Blockly.Connection} a One of the two connections being checked. - * @param {Blockly.Connection} b The second of the two connections being + * @param {Connection} a One of the two connections being checked. + * @param {Connection} b The second of the two connections being * checked. * @return {string} A developer-readable error string. * @public @@ -100,25 +99,25 @@ ConnectionChecker.prototype.canConnectWithReason = function( ConnectionChecker.prototype.getErrorMessage = function(errorCode, a, b) { switch (errorCode) { - case Blockly.Connection.REASON_SELF_CONNECTION: + case Connection.REASON_SELF_CONNECTION: return 'Attempted to connect a block to itself.'; - case Blockly.Connection.REASON_DIFFERENT_WORKSPACES: + case Connection.REASON_DIFFERENT_WORKSPACES: // Usually this means one block has been deleted. return 'Blocks not on same workspace.'; - case Blockly.Connection.REASON_WRONG_TYPE: + case Connection.REASON_WRONG_TYPE: return 'Attempt to connect incompatible types.'; - case Blockly.Connection.REASON_TARGET_NULL: + case Connection.REASON_TARGET_NULL: return 'Target connection is null.'; - case Blockly.Connection.REASON_CHECKS_FAILED: { - const connOne = /** @type {!Blockly.Connection} **/ (a); - const connTwo = /** @type {!Blockly.Connection} **/ (b); + case Connection.REASON_CHECKS_FAILED: { + const connOne = /** @type {!Connection} **/ (a); + const connTwo = /** @type {!Connection} **/ (b); let msg = 'Connection checks failed. '; msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + connTwo.getCheck(); return msg; } - case Blockly.Connection.REASON_SHADOW_PARENT: + case Connection.REASON_SHADOW_PARENT: return 'Connecting non-shadow to shadow block.'; - case Blockly.Connection.REASON_DRAG_CHECKS_FAILED: + case Connection.REASON_DRAG_CHECKS_FAILED: return 'Drag checks failed.'; default: return 'Unknown connection failure: this should never happen!'; @@ -128,14 +127,14 @@ ConnectionChecker.prototype.getErrorMessage = function(errorCode, /** * Check that connecting the given connections is safe, meaning that it would * not break any of Blockly's basic assumptions (e.g. no self connections). - * @param {Blockly.Connection} a The first of the connections to check. - * @param {Blockly.Connection} b The second of the connections to check. + * @param {Connection} a The first of the connections to check. + * @param {Connection} b The second of the connections to check. * @return {number} An enum with the reason this connection is safe or unsafe. * @public */ ConnectionChecker.prototype.doSafetyChecks = function(a, b) { if (!a || !b) { - return Blockly.Connection.REASON_TARGET_NULL; + return Connection.REASON_TARGET_NULL; } let blockA, blockB; if (a.isSuperior()) { @@ -146,23 +145,23 @@ ConnectionChecker.prototype.doSafetyChecks = function(a, b) { blockA = b.getSourceBlock(); } if (blockA == blockB) { - return Blockly.Connection.REASON_SELF_CONNECTION; + return Connection.REASON_SELF_CONNECTION; } else if (b.type != Blockly.OPPOSITE_TYPE[a.type]) { - return Blockly.Connection.REASON_WRONG_TYPE; + return Connection.REASON_WRONG_TYPE; } else if (blockA.workspace !== blockB.workspace) { - return Blockly.Connection.REASON_DIFFERENT_WORKSPACES; + return Connection.REASON_DIFFERENT_WORKSPACES; } else if (blockA.isShadow() && !blockB.isShadow()) { - return Blockly.Connection.REASON_SHADOW_PARENT; + return Connection.REASON_SHADOW_PARENT; } - return Blockly.Connection.CAN_CONNECT; + return Connection.CAN_CONNECT; }; /** * Check whether this connection is compatible with another connection with * respect to the value type system. E.g. square_root("Hello") is not * compatible. - * @param {!Blockly.Connection} a Connection to compare. - * @param {!Blockly.Connection} b Connection to compare against. + * @param {!Connection} a Connection to compare. + * @param {!Connection} b Connection to compare against. * @return {boolean} True if the connections share a type. * @public */ @@ -186,8 +185,8 @@ ConnectionChecker.prototype.doTypeChecks = function(a, b) { /** * Check whether this connection can be made by dragging. - * @param {!Blockly.RenderedConnection} a Connection to compare. - * @param {!Blockly.RenderedConnection} b Connection to compare against. + * @param {!RenderedConnection} a Connection to compare. + * @param {!RenderedConnection} b Connection to compare against. * @param {number} distance The maximum allowable distance between connections. * @return {boolean} True if the connection is allowed during a drag. * @public @@ -203,9 +202,9 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } switch (b.type) { - case Blockly.connectionTypes.PREVIOUS_STATEMENT: + case connectionTypes.PREVIOUS_STATEMENT: return this.canConnectToPrevious_(a, b); - case Blockly.connectionTypes.OUTPUT_VALUE: { + case connectionTypes.OUTPUT_VALUE: { // Don't offer to connect an already connected left (male) value plug to // an available right (female) value plug. if ((b.isConnected() && @@ -215,7 +214,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } break; } - case Blockly.connectionTypes.INPUT_VALUE: { + case connectionTypes.INPUT_VALUE: { // Offering to connect the left (male) of a value block to an already // connected value pair is ok, we'll splice it in. // However, don't offer to splice into an immovable block. @@ -226,7 +225,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } break; } - case Blockly.connectionTypes.NEXT_STATEMENT: { + case connectionTypes.NEXT_STATEMENT: { // Don't let a block with no next connection bump other blocks out of the // stack. But covering up a shadow block or stack of shadow blocks is // fine. Similarly, replacing a terminal statement with another terminal @@ -254,9 +253,9 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { /** * Helper function for drag checking. - * @param {!Blockly.Connection} a The connection to check, which must be a + * @param {!Connection} a The connection to check, which must be a * statement input or next connection. - * @param {!Blockly.Connection} b A nearby connection to check, which + * @param {!Connection} b A nearby connection to check, which * must be a previous connection. * @return {boolean} True if the connection is allowed, false otherwise. * @protected @@ -288,7 +287,7 @@ ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { return !targetBlock.getPreviousBlock(); }; -Blockly.registry.register(Blockly.registry.Type.CONNECTION_CHECKER, - Blockly.registry.DEFAULT, ConnectionChecker); +registry.register(registry.Type.CONNECTION_CHECKER, + registry.DEFAULT, ConnectionChecker); exports = ConnectionChecker; From 5b9505802e4aea4e403cb1ef4fcc1adbd6a92f67 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:46:07 -0700 Subject: [PATCH 14/36] clang-format core/connection_checker.js --- core/connection_checker.js | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 4c350fc9c..3a405edcb 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -5,8 +5,8 @@ */ /** - * @fileoverview An object that encapsulates logic for checking whether a potential - * connection is safe and valid. + * @fileoverview An object that encapsulates logic for checking whether a + * potential connection is safe and valid. * @author fenichel@google.com (Rachel Fenichel) */ 'use strict'; @@ -28,8 +28,7 @@ goog.require('Blockly.constants'); * @implements {IConnectionChecker} * @constructor */ -const ConnectionChecker = function() { -}; +const ConnectionChecker = function() {}; /** * Check whether the current connection can connect with the target @@ -43,8 +42,8 @@ const ConnectionChecker = function() { * @return {boolean} Whether the connection is legal. * @public */ -ConnectionChecker.prototype.canConnect = function(a, b, - isDragging, opt_distance) { +ConnectionChecker.prototype.canConnect = function( + a, b, isDragging, opt_distance) { return this.canConnectWithReason(a, b, isDragging, opt_distance) == Connection.CAN_CONNECT; }; @@ -79,8 +78,7 @@ ConnectionChecker.prototype.canConnectWithReason = function( if (isDragging && !this.doDragChecks( /** @type {!RenderedConnection} **/ (a), - /** @type {!RenderedConnection} **/ (b), - opt_distance || 0)) { + /** @type {!RenderedConnection} **/ (b), opt_distance || 0)) { return Connection.REASON_DRAG_CHECKS_FAILED; } @@ -96,8 +94,7 @@ ConnectionChecker.prototype.canConnectWithReason = function( * @return {string} A developer-readable error string. * @public */ -ConnectionChecker.prototype.getErrorMessage = function(errorCode, - a, b) { +ConnectionChecker.prototype.getErrorMessage = function(errorCode, a, b) { switch (errorCode) { case Connection.REASON_SELF_CONNECTION: return 'Attempted to connect a block to itself.'; @@ -112,7 +109,8 @@ ConnectionChecker.prototype.getErrorMessage = function(errorCode, const connOne = /** @type {!Connection} **/ (a); const connTwo = /** @type {!Connection} **/ (b); let msg = 'Connection checks failed. '; - msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + connTwo.getCheck(); + msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + + connTwo.getCheck(); return msg; } case Connection.REASON_SHADOW_PARENT: @@ -207,8 +205,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { case connectionTypes.OUTPUT_VALUE: { // Don't offer to connect an already connected left (male) value plug to // an available right (female) value plug. - if ((b.isConnected() && - !b.targetBlock().isInsertionMarker()) || + if ((b.isConnected() && !b.targetBlock().isInsertionMarker()) || a.isConnected()) { return false; } @@ -218,8 +215,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { // Offering to connect the left (male) of a value block to an already // connected value pair is ok, we'll splice it in. // However, don't offer to splice into an immovable block. - if (b.isConnected() && - !b.targetBlock().isMovable() && + if (b.isConnected() && !b.targetBlock().isMovable() && !b.targetBlock().isShadow()) { return false; } @@ -230,10 +226,8 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { // stack. But covering up a shadow block or stack of shadow blocks is // fine. Similarly, replacing a terminal statement with another terminal // statement is allowed. - if (b.isConnected() && - !a.getSourceBlock().nextConnection && - !b.targetBlock().isShadow() && - b.targetBlock().nextConnection) { + if (b.isConnected() && !a.getSourceBlock().nextConnection && + !b.targetBlock().isShadow() && b.targetBlock().nextConnection) { return false; } break; @@ -287,7 +281,7 @@ ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { return !targetBlock.getPreviousBlock(); }; -registry.register(registry.Type.CONNECTION_CHECKER, - registry.DEFAULT, ConnectionChecker); +registry.register( + registry.Type.CONNECTION_CHECKER, registry.DEFAULT, ConnectionChecker); exports = ConnectionChecker; From dbf6308f03e6db01eb77022c7891879665dea9f9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:36:34 -0700 Subject: [PATCH 15/36] Migrate core/interfaces/i_movable.js to goog.module --- core/interfaces/i_movable.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_movable.js b/core/interfaces/i_movable.js index bc0c3bf9f..25a92d6bb 100644 --- a/core/interfaces/i_movable.js +++ b/core/interfaces/i_movable.js @@ -11,17 +11,20 @@ 'use strict'; -goog.provide('Blockly.IMovable'); +goog.module('Blockly.IMovable'); +goog.module.declareLegacyNamespace(); /** * The interface for an object that is movable. * @interface */ -Blockly.IMovable = function() {}; +const IMovable = function() {}; /** * Get whether this is movable or not. * @return {boolean} True if movable. */ -Blockly.IMovable.prototype.isMovable; +IMovable.prototype.isMovable; + +exports = IMovable; diff --git a/tests/deps.js b/tests/deps.js index 230083d23..3ce0457fb 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -88,7 +88,7 @@ goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarg goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); -goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], []); +goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); From b990eb08a3021f9cdc71f3325e31774507ee0b75 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 16:15:15 -0700 Subject: [PATCH 16/36] Migrate core/interfaces/i_styleable.js to goog.module --- core/interfaces/i_styleable.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_styleable.js b/core/interfaces/i_styleable.js index 944ee9d65..14dea3ce1 100644 --- a/core/interfaces/i_styleable.js +++ b/core/interfaces/i_styleable.js @@ -11,23 +11,26 @@ 'use strict'; -goog.provide('Blockly.IStyleable'); +goog.module('Blockly.IStyleable'); +goog.module.declareLegacyNamespace(); /** * Interface for an object that a style can be added to. * @interface */ -Blockly.IStyleable = function() {}; +const IStyleable = function() {}; /** * Adds a style on the toolbox. Usually used to change the cursor. * @param {string} style The name of the class to add. */ -Blockly.IStyleable.prototype.addStyle; +IStyleable.prototype.addStyle; /** * Removes a style from the toolbox. Usually used to change the cursor. * @param {string} style The name of the class to remove. */ -Blockly.IStyleable.prototype.removeStyle; +IStyleable.prototype.removeStyle; + +exports = IStyleable; diff --git a/tests/deps.js b/tests/deps.js index 3ce0457fb..c9ef15a2f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -93,7 +93,7 @@ goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositio goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []); -goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], []); +goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], []); goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); From bbdf5730f6aec7af34be3582d80e39e088ba61b8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 08:10:47 -0700 Subject: [PATCH 17/36] Reordered core/connection_checker.js requires --- core/connection_checker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 3a405edcb..4bd7bd4e2 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -15,10 +15,10 @@ goog.module('Blockly.ConnectionChecker'); goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); -const connectionTypes = goog.require('Blockly.connectionTypes'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); -const registry = goog.require('Blockly.registry'); const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const registry = goog.require('Blockly.registry'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); From 11b47aab2537c1ad8b26eb815f357717729e9bff Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:39:35 -0700 Subject: [PATCH 18/36] Migrate core/interfaces/i_positionable.js to goog.module --- core/interfaces/i_positionable.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_positionable.js b/core/interfaces/i_positionable.js index 356510c81..3ab5b88f4 100644 --- a/core/interfaces/i_positionable.js +++ b/core/interfaces/i_positionable.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IPositionable'); +goog.module('Blockly.IPositionable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IComponent'); @@ -24,7 +25,7 @@ goog.requireType('Blockly.utils.Rect'); * @extends {Blockly.IComponent} * @interface */ -Blockly.IPositionable = function() {}; +const IPositionable = function() {}; /** * Positions the element. Called when the window is resized. @@ -32,7 +33,7 @@ Blockly.IPositionable = function() {}; * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ -Blockly.IPositionable.prototype.position; +IPositionable.prototype.position; /** * Returns the bounding rectangle of the UI element in pixel units relative to @@ -40,4 +41,6 @@ Blockly.IPositionable.prototype.position; * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ -Blockly.IPositionable.prototype.getBoundingRectangle; +IPositionable.prototype.getBoundingRectangle; + +exports = IPositionable; diff --git a/tests/deps.js b/tests/deps.js index e8a2a7f06..56cbcce9e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -89,7 +89,7 @@ goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable' goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []); From 282cd26edeaeca7c71fe70863f1283f6e5178c9b Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:41:40 -0700 Subject: [PATCH 19/36] Migrate core/interfaces/i_positionable.js named requires --- core/interfaces/i_positionable.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/interfaces/i_positionable.js b/core/interfaces/i_positionable.js index 3ab5b88f4..ed324196b 100644 --- a/core/interfaces/i_positionable.js +++ b/core/interfaces/i_positionable.js @@ -14,23 +14,22 @@ goog.module('Blockly.IPositionable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IComponent'); - -goog.requireType('Blockly.MetricsManager'); -goog.requireType('Blockly.utils.Rect'); +const IComponent = goog.require('Blockly.IComponent'); +const Rect = goog.requireType('Blockly.utils.Rect'); +const {UiMetrics} = goog.requireType('Blockly.MetricsManager'); /** * Interface for a component that is positioned on top of the workspace. - * @extends {Blockly.IComponent} + * @extends {IComponent} * @interface */ const IPositionable = function() {}; /** * Positions the element. Called when the window is resized. - * @param {!Blockly.MetricsManager.UiMetrics} metrics The workspace metrics. - * @param {!Array} savedPositions List of rectangles that + * @param {!UiMetrics} metrics The workspace metrics. + * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ IPositionable.prototype.position; @@ -38,7 +37,7 @@ IPositionable.prototype.position; /** * Returns the bounding rectangle of the UI element in pixel units relative to * the Blockly injection div. - * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if + * @return {?Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ IPositionable.prototype.getBoundingRectangle; From f723d1d3842cac4caa4dd75c253f4455db1b8079 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:09:04 -0700 Subject: [PATCH 20/36] Migrate core/interfaces/i_drag_target.js to goog.module --- core/interfaces/i_drag_target.js | 19 +++++++++++-------- tests/deps.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/interfaces/i_drag_target.js b/core/interfaces/i_drag_target.js index 0af765d57..ada85a8e3 100644 --- a/core/interfaces/i_drag_target.js +++ b/core/interfaces/i_drag_target.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IDragTarget'); +goog.module('Blockly.IDragTarget'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IComponent'); @@ -25,7 +26,7 @@ goog.requireType('Blockly.utils.Rect'); * @extends {Blockly.IComponent} * @interface */ -Blockly.IDragTarget = function() {}; +const IDragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units @@ -33,14 +34,14 @@ Blockly.IDragTarget = function() {}; * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.IDragTarget.prototype.getClientRect; +IDragTarget.prototype.getClientRect; /** * Handles when a cursor with a block or bubble enters this drag target. * @param {!Blockly.IDraggable} dragElement The block or bubble currently being * dragged. */ -Blockly.IDragTarget.prototype.onDragEnter; +IDragTarget.prototype.onDragEnter; /** * Handles when a cursor with a block or bubble is dragged over this drag @@ -48,7 +49,7 @@ Blockly.IDragTarget.prototype.onDragEnter; * @param {!Blockly.IDraggable} dragElement The block or bubble currently being * dragged. */ -Blockly.IDragTarget.prototype.onDragOver; +IDragTarget.prototype.onDragOver; /** @@ -56,7 +57,7 @@ Blockly.IDragTarget.prototype.onDragOver; * @param {!Blockly.IDraggable} dragElement The block or bubble currently being * dragged. */ -Blockly.IDragTarget.prototype.onDragExit; +IDragTarget.prototype.onDragExit; /** * Handles when a block or bubble is dropped on this component. @@ -64,7 +65,7 @@ Blockly.IDragTarget.prototype.onDragExit; * @param {!Blockly.IDraggable} dragElement The block or bubble currently being * dragged. */ -Blockly.IDragTarget.prototype.onDrop; +IDragTarget.prototype.onDrop; /** * Returns whether the provided block or bubble should not be moved after being @@ -75,4 +76,6 @@ Blockly.IDragTarget.prototype.onDrop; * @return {boolean} Whether the block or bubble provided should be returned to * drag start. */ -Blockly.IDragTarget.prototype.shouldPreventMove; +IDragTarget.prototype.shouldPreventMove; + +exports = IDragTarget; diff --git a/tests/deps.js b/tests/deps.js index 56cbcce9e..7a562a115 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -84,7 +84,7 @@ goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextM goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); From cc324d53e59cf0f9145643e7e12583065dcebb3b Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:20:23 -0700 Subject: [PATCH 21/36] Migrate core/interfaces/i_drag_target.js named requires --- core/interfaces/i_drag_target.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/interfaces/i_drag_target.js b/core/interfaces/i_drag_target.js index ada85a8e3..803bcbc74 100644 --- a/core/interfaces/i_drag_target.js +++ b/core/interfaces/i_drag_target.js @@ -15,15 +15,15 @@ goog.module('Blockly.IDragTarget'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IComponent'); +const IComponent = goog.require('Blockly.IComponent'); +const IDraggable = goog.requireType('Blockly.IDraggable'); +const Rect = goog.requireType('Blockly.utils.Rect'); -goog.requireType('Blockly.IDraggable'); -goog.requireType('Blockly.utils.Rect'); /** * Interface for a component with custom behaviour when a block or bubble is * dragged over or dropped on top of it. - * @extends {Blockly.IComponent} + * @extends {IComponent} * @interface */ const IDragTarget = function() {}; @@ -31,14 +31,14 @@ const IDragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag + * @return {?Rect} The component's bounding box. Null if drag * target area should be ignored. */ IDragTarget.prototype.getClientRect; /** * Handles when a cursor with a block or bubble enters this drag target. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. */ IDragTarget.prototype.onDragEnter; @@ -46,7 +46,7 @@ IDragTarget.prototype.onDragEnter; /** * Handles when a cursor with a block or bubble is dragged over this drag * target. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. */ IDragTarget.prototype.onDragOver; @@ -54,7 +54,7 @@ IDragTarget.prototype.onDragOver; /** * Handles when a cursor with a block or bubble exits this drag target. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. */ IDragTarget.prototype.onDragExit; @@ -62,7 +62,7 @@ IDragTarget.prototype.onDragExit; /** * Handles when a block or bubble is dropped on this component. * Should not handle delete here. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. */ IDragTarget.prototype.onDrop; @@ -71,7 +71,7 @@ IDragTarget.prototype.onDrop; * Returns whether the provided block or bubble should not be moved after being * dropped on this component. If true, the element will return to where it was * when the drag started. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. * @return {boolean} Whether the block or bubble provided should be returned to * drag start. From daa0b3bfb557482579c8e30cbe61320f14c0ed27 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 09:26:17 -0700 Subject: [PATCH 22/36] 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_); From 9b5a9192124d4952e3591535584957d2875b1ab9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 09:41:58 -0700 Subject: [PATCH 23/36] Convert core/utils/styles.js to inline export style --- core/utils/style.js | 74 +++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index 028b746b8..1fcfbdd62 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -29,7 +29,7 @@ const Size = goog.require('Blockly.utils.Size'); * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. */ -const getSize = function(element) { +function getSize(element) { if (getStyle(element, 'display') != 'none') { return getSizeWithDisplay(element); } @@ -52,19 +52,19 @@ const getSize = function(element) { style.visibility = originalVisibility; return new Size(offsetWidth, offsetHeight); -}; +} +exports.getSize = getSize; /** * Gets the height and width of an element when the display is not none. * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. - * @private */ -const getSizeWithDisplay = function(element) { +function getSizeWithDisplay(element) { const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; return new Size(offsetWidth, offsetHeight); -}; +} /** * Cross-browser pseudo get computed style. It returns the computed style where @@ -78,12 +78,11 @@ const getSizeWithDisplay = function(element) { * @param {!Element} element Element to get style of. * @param {string} style Property to get (must be camelCase, not CSS-style). * @return {string} Style value. - * @private */ -const getStyle = function(element, style) { +function getStyle(element, style) { return getComputedStyle(element, style) || getCascadedStyle(element, style) || (element.style && element.style[style]); -}; +} /** * Retrieves a computed style value of a node. It returns empty string if the @@ -97,7 +96,7 @@ const getStyle = function(element, style) { * @param {string} property Property to get (camel-case). * @return {string} Style value. */ -const getComputedStyle = function(element, property) { +function getComputedStyle(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { const styles = document.defaultView.getComputedStyle(element, null); if (styles) { @@ -108,7 +107,8 @@ const getComputedStyle = function(element, property) { } return ''; -}; +} +exports.getComputedStyle = getComputedStyle; /** * Gets the cascaded style value of a node, or null if the value cannot be @@ -120,10 +120,11 @@ const getComputedStyle = function(element, property) { * @param {string} style Property to get (camel-case). * @return {string} Style value. */ -const getCascadedStyle = function(element, style) { +function getCascadedStyle(element, style) { return /** @type {string} */ ( element.currentStyle ? element.currentStyle[style] : null); -}; +} +exports.getCascadedStyle = getCascadedStyle; /** * Returns a Coordinate object relative to the top-left of the HTML document. @@ -131,7 +132,7 @@ const getCascadedStyle = function(element, style) { * @param {!Element} el Element to get the page offset for. * @return {!Coordinate} The page offset. */ -const getPageOffset = function(el) { +function getPageOffset(el) { const pos = new Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; @@ -145,20 +146,22 @@ const getPageOffset = function(el) { pos.y = box.top + scrollCoord.y; return pos; -}; +} +exports.getPageOffset = getPageOffset; /** * Calculates the viewport coordinates relative to the document. * Similar to Closure's goog.style.getViewportPageOffset * @return {!Coordinate} The page offset of the viewport. */ -const getViewportPageOffset = function() { +function getViewportPageOffset() { const body = document.body; const documentElement = document.documentElement; const scrollLeft = body.scrollLeft || documentElement.scrollLeft; const scrollTop = body.scrollTop || documentElement.scrollTop; return new Coordinate(scrollLeft, scrollTop); -}; +} +exports.getViewportPageOffset = getViewportPageOffset; /** * Shows or hides an element from the page. Hiding the element is done by @@ -172,9 +175,10 @@ const getViewportPageOffset = function() { * @param {*} isShown True to render the element in its default style, * false to disable rendering the element. */ -const setElementShown = function(el, isShown) { +function setElementShown(el, isShown) { el.style.display = isShown ? '' : 'none'; -}; +} +exports.setElementShown = setElementShown; /** * Returns true if the element is using right to left (RTL) direction. @@ -183,9 +187,10 @@ const setElementShown = function(el, isShown) { * @param {!Element} el The element to test. * @return {boolean} True for right to left, false for left to right. */ -const isRightToLeft = function(el) { +function isRightToLeft(el) { return 'rtl' == getStyle(el, 'direction'); -}; +} +exports.isRightToLeft = isRightToLeft; /** * Gets the computed border widths (on all sides) in pixels @@ -193,7 +198,7 @@ const isRightToLeft = function(el) { * @param {!Element} element The element to get the border widths for. * @return {!Object} The computed border widths. */ -const getBorderBox = function(element) { +function getBorderBox(element) { const left = getComputedStyle(element, 'borderLeftWidth'); const right = getComputedStyle(element, 'borderRightWidth'); const top = getComputedStyle(element, 'borderTopWidth'); @@ -205,7 +210,8 @@ const getBorderBox = function(element) { bottom: parseFloat(bottom), left: parseFloat(left) }; -}; +} +exports.getBorderBox = getBorderBox; /** * Changes the scroll position of `container` with the minimum amount so @@ -220,11 +226,12 @@ const getBorderBox = function(element) { * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -const scrollIntoContainerView = function(element, container, opt_center) { +function scrollIntoContainerView(element, container, opt_center) { const offset = getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; -}; +} +exports.scrollIntoContainerView = scrollIntoContainerView; /** * Calculate the scroll position of `container` with the minimum amount so @@ -241,8 +248,7 @@ const scrollIntoContainerView = function(element, container, opt_center) { * @return {!Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ -const getContainerOffsetToScrollInto = function( - element, container, opt_center) { +function getContainerOffsetToScrollInto(element, container, opt_center) { // Absolute position of the element's border's top left corner. const elementPos = getPageOffset(element); // Absolute position of the container's border's top left corner. @@ -275,17 +281,5 @@ const getContainerOffsetToScrollInto = function( scrollTop += Math.min(relY, Math.max(relY - spaceY, 0)); } return new Coordinate(scrollLeft, scrollTop); -}; - -exports = { - getSize, - getComputedStyle, - getCascadedStyle, - getPageOffset, - getViewportPageOffset, - setElementShown, - isRightToLeft, - getBorderBox, - scrollIntoContainerView, - getContainerOffsetToScrollInto, -}; +} +exports.getContainerOffsetToScrollInto = getContainerOffsetToScrollInto; From 30f27606c8d01b69260a79fb30e159f65d16b36e Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:12:44 -0700 Subject: [PATCH 24/36] Migrate core/interfaces/i_bubble.js to goog.module --- core/interfaces/i_bubble.js | 23 +++++++++++++---------- tests/deps.js | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index 7fae99edf..487d2a8a8 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IBubble'); +goog.module('Blockly.IBubble'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IContextMenu'); goog.require('Blockly.IDraggable'); @@ -26,20 +27,20 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.IDraggable} * @extends {Blockly.IContextMenu} */ -Blockly.IBubble = function() {}; +const IBubble = function() {}; /** * Return the coordinates of the top-left corner of this bubble's body relative * to the drawing surface's origin (0,0), in workspace units. * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. */ -Blockly.IBubble.prototype.getRelativeToSurfaceXY; +IBubble.prototype.getRelativeToSurfaceXY; /** * Return the root node of the bubble's SVG group. * @return {!SVGElement} The root SVG node of the bubble's group. */ -Blockly.IBubble.prototype.getSvgRoot; +IBubble.prototype.getSvgRoot; /** * Set whether auto-layout of this bubble is enabled. The first time a bubble @@ -48,13 +49,13 @@ Blockly.IBubble.prototype.getSvgRoot; * @param {boolean} enable True if auto-layout should be enabled, false * otherwise. */ -Blockly.IBubble.prototype.setAutoLayout; +IBubble.prototype.setAutoLayout; /** * Triggers a move callback if one exists at the end of a drag. * @param {boolean} adding True if adding, false if removing. */ -Blockly.IBubble.prototype.setDragging; +IBubble.prototype.setDragging; /** * Move this bubble during a drag, taking into account whether or not there is @@ -64,23 +65,25 @@ Blockly.IBubble.prototype.setDragging; * @param {!Blockly.utils.Coordinate} newLoc The location to translate to, in * workspace coordinates. */ -Blockly.IBubble.prototype.moveDuringDrag; +IBubble.prototype.moveDuringDrag; /** * Move the bubble to the specified location in workspace coordinates. * @param {number} x The x position to move to. * @param {number} y The y position to move to. */ -Blockly.IBubble.prototype.moveTo; +IBubble.prototype.moveTo; /** * Update the style of this bubble when it is dragged over a delete area. * @param {boolean} enable True if the bubble is about to be deleted, false * otherwise. */ -Blockly.IBubble.prototype.setDeleteStyle; +IBubble.prototype.setDeleteStyle; /** * Dispose of this bubble. */ -Blockly.IBubble.prototype.dispose; +IBubble.prototype.dispose; + +exports = IBubble; diff --git a/tests/deps.js b/tests/deps.js index cdeae73f4..8ce3faaae 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -77,7 +77,7 @@ goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNod goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']); +goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); From 2c80b90dab65941610882aeebe598016724a2baa Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:17:08 -0700 Subject: [PATCH 25/36] Migrate core/interfaces/i_bubble.js named requires --- core/interfaces/i_bubble.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index 487d2a8a8..08e339a19 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -14,25 +14,24 @@ goog.module('Blockly.IBubble'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IContextMenu'); -goog.require('Blockly.IDraggable'); - -goog.requireType('Blockly.BlockDragSurfaceSvg'); -goog.requireType('Blockly.utils.Coordinate'); +const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const IContextMenu = goog.require('Blockly.IContextMenu'); +const IDraggable = goog.require('Blockly.IDraggable'); /** * A bubble interface. * @interface - * @extends {Blockly.IDraggable} - * @extends {Blockly.IContextMenu} + * @extends {IDraggable} + * @extends {IContextMenu} */ const IBubble = function() {}; /** * Return the coordinates of the top-left corner of this bubble's body relative * to the drawing surface's origin (0,0), in workspace units. - * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. + * @return {!Coordinate} Object with .x and .y properties. */ IBubble.prototype.getRelativeToSurfaceXY; @@ -60,9 +59,9 @@ IBubble.prototype.setDragging; /** * Move this bubble during a drag, taking into account whether or not there is * a drag surface. - * @param {Blockly.BlockDragSurfaceSvg} dragSurface The surface that carries + * @param {BlockDragSurfaceSvg} dragSurface The surface that carries * rendered items during a drag, or null if no drag surface is in use. - * @param {!Blockly.utils.Coordinate} newLoc The location to translate to, in + * @param {!Coordinate} newLoc The location to translate to, in * workspace coordinates. */ IBubble.prototype.moveDuringDrag; From bac62dc9be141d4c2433a02235d1be57d7d12868 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 09:26:39 -0700 Subject: [PATCH 26/36] Update jsdoc annotation in core/interfaces/i_bubble.js --- core/interfaces/i_bubble.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index 08e339a19..e41a1bf25 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -59,7 +59,7 @@ IBubble.prototype.setDragging; /** * Move this bubble during a drag, taking into account whether or not there is * a drag surface. - * @param {BlockDragSurfaceSvg} dragSurface The surface that carries + * @param {?BlockDragSurfaceSvg} dragSurface The surface that carries * rendered items during a drag, or null if no drag surface is in use. * @param {!Coordinate} newLoc The location to translate to, in * workspace coordinates. From 456969767b4f9d29abf4e9709407d7fed0df892c Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 16:03:50 -0700 Subject: [PATCH 27/36] Migrate core/interfaces/i_selectable.js to goog.module --- core/interfaces/i_selectable.js | 13 ++++++++----- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/interfaces/i_selectable.js b/core/interfaces/i_selectable.js index e3d817fde..d3355f9ab 100644 --- a/core/interfaces/i_selectable.js +++ b/core/interfaces/i_selectable.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.ISelectable'); +goog.module('Blockly.ISelectable'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.IDeletable'); goog.requireType('Blockly.IMovable'); @@ -23,21 +24,23 @@ goog.requireType('Blockly.IMovable'); * @extends {Blockly.IMovable} * @interface */ -Blockly.ISelectable = function() {}; +const ISelectable = function() {}; /** * @type {string} */ -Blockly.ISelectable.prototype.id; +ISelectable.prototype.id; /** * Select this. Highlight it visually. * @return {void} */ -Blockly.ISelectable.prototype.select; +ISelectable.prototype.select; /** * Unselect this. Unhighlight it visually. * @return {void} */ -Blockly.ISelectable.prototype.unselect; +ISelectable.prototype.unselect; + +exports = ISelectable; diff --git a/tests/deps.js b/tests/deps.js index 8ce3faaae..33396a17b 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -92,7 +92,7 @@ goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [ goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); -goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []); +goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], []); goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); From e722097c1bac2e658e5dedbfa9c2b9c0df66cef3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:21:47 -0700 Subject: [PATCH 28/36] Break up interfaces in core/i_accessibility.js into separate files --- core/interfaces/i_accessibility.js | 75 ------------------- core/interfaces/i_ast_node_location.js | 20 +++++ core/interfaces/i_ast_node_location_svg.js | 38 ++++++++++ .../i_ast_node_location_with_block.js | 32 ++++++++ core/interfaces/i_keyboard_accessible.js | 30 ++++++++ 5 files changed, 120 insertions(+), 75 deletions(-) delete mode 100644 core/interfaces/i_accessibility.js create mode 100644 core/interfaces/i_ast_node_location.js create mode 100644 core/interfaces/i_ast_node_location_svg.js create mode 100644 core/interfaces/i_ast_node_location_with_block.js create mode 100644 core/interfaces/i_keyboard_accessible.js diff --git a/core/interfaces/i_accessibility.js b/core/interfaces/i_accessibility.js deleted file mode 100644 index 30d724959..000000000 --- a/core/interfaces/i_accessibility.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @license - * Copyright 2020 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @fileoverview AST Node and keyboard navigation interfaces. - * @author samelh@google.com (Sam El-Husseini) - */ - -'use strict'; - -goog.provide('Blockly.IASTNodeLocation'); -goog.provide('Blockly.IASTNodeLocationSvg'); -goog.provide('Blockly.IASTNodeLocationWithBlock'); -goog.provide('Blockly.IKeyboardAccessible'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.ShortcutRegistry'); - - -/** - * An AST node location interface. - * @interface - */ -Blockly.IASTNodeLocation = function() {}; - -/** - * An AST node location SVG interface. - * @interface - * @extends {Blockly.IASTNodeLocation} - */ -Blockly.IASTNodeLocationSvg = function() {}; - -/** - * Add the marker SVG to this node's SVG group. - * @param {SVGElement} markerSvg The SVG root of the marker to be added to the - * SVG group. - */ -Blockly.IASTNodeLocationSvg.prototype.setMarkerSvg; - -/** - * Add the cursor SVG to this node's SVG group. - * @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the - * SVG group. - */ -Blockly.IASTNodeLocationSvg.prototype.setCursorSvg; - -/** - * An AST node location that has an associated block. - * @interface - * @extends {Blockly.IASTNodeLocation} - */ -Blockly.IASTNodeLocationWithBlock = function() {}; - -/** - * Get the source block associated with this node. - * @return {Blockly.Block} The source block. - */ -Blockly.IASTNodeLocationWithBlock.prototype.getSourceBlock; - - -/** - * An interface for an object that handles keyboard shortcuts. - * @interface - */ -Blockly.IKeyboardAccessible = function() {}; - -/** - * Handles the given keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled. - * @return {boolean} True if the shortcut has been handled, false otherwise. - */ -Blockly.IKeyboardAccessible.prototype.onShortcut; diff --git a/core/interfaces/i_ast_node_location.js b/core/interfaces/i_ast_node_location.js new file mode 100644 index 000000000..8d3d8cb97 --- /dev/null +++ b/core/interfaces/i_ast_node_location.js @@ -0,0 +1,20 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for an AST node location. + * @author samelh@google.com (Sam El-Husseini) + */ + +'use strict'; + +goog.provide('Blockly.IASTNodeLocation'); + +/** + * An AST node location interface. + * @interface + */ +Blockly.IASTNodeLocation = function() {}; diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js new file mode 100644 index 000000000..7711289b1 --- /dev/null +++ b/core/interfaces/i_ast_node_location_svg.js @@ -0,0 +1,38 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for an AST node location SVG. + * @author samelh@google.com (Sam El-Husseini) + */ + +'use strict'; + +goog.provide('Blockly.IASTNodeLocationSvg'); + +goog.require('Blockly.IASTNodeLocation'); + + +/** + * An AST node location SVG interface. + * @interface + * @extends {Blockly.IASTNodeLocation} + */ +Blockly.IASTNodeLocationSvg = function() {}; + +/** + * Add the marker SVG to this node's SVG group. + * @param {SVGElement} markerSvg The SVG root of the marker to be added to the + * SVG group. + */ +Blockly.IASTNodeLocationSvg.prototype.setMarkerSvg; + +/** + * Add the cursor SVG to this node's SVG group. + * @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the + * SVG group. + */ +Blockly.IASTNodeLocationSvg.prototype.setCursorSvg; diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js new file mode 100644 index 000000000..612ef0e73 --- /dev/null +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -0,0 +1,32 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for an AST node location that has an associated + * block. + * @author samelh@google.com (Sam El-Husseini) + */ + +'use strict'; + +goog.provide('Blockly.IASTNodeLocationWithBlock'); + +goog.require('Blockly.IASTNodeLocation'); +goog.requireType('Blockly.Block'); + + +/** + * An AST node location that has an associated block. + * @interface + * @extends {Blockly.IASTNodeLocation} + */ +Blockly.IASTNodeLocationWithBlock = function() {}; + +/** + * Get the source block associated with this node. + * @return {Blockly.Block} The source block. + */ +Blockly.IASTNodeLocationWithBlock.prototype.getSourceBlock; diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js new file mode 100644 index 000000000..5807e47bf --- /dev/null +++ b/core/interfaces/i_keyboard_accessible.js @@ -0,0 +1,30 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for objects that handle keyboard shortcuts. + * @author samelh@google.com (Sam El-Husseini) + */ + +'use strict'; + +goog.provide('Blockly.IKeyboardAccessible'); + +goog.requireType('Blockly.ShortcutRegistry'); + + +/** + * An interface for an object that handles keyboard shortcuts. + * @interface + */ +Blockly.IKeyboardAccessible = function() {}; + +/** + * Handles the given keyboard shortcut. + * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled. + * @return {boolean} True if the shortcut has been handled, false otherwise. + */ +Blockly.IKeyboardAccessible.prototype.onShortcut; From 81b067f83acce2898372771d25cdc08b76f0d148 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:41:41 -0700 Subject: [PATCH 29/36] Migrate core/interfaces/i_ast_node_location.js to goog.module --- core/interfaces/i_ast_node_location.js | 7 +++++-- tests/deps.js | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/interfaces/i_ast_node_location.js b/core/interfaces/i_ast_node_location.js index 8d3d8cb97..0ebec8ebd 100644 --- a/core/interfaces/i_ast_node_location.js +++ b/core/interfaces/i_ast_node_location.js @@ -11,10 +11,13 @@ 'use strict'; -goog.provide('Blockly.IASTNodeLocation'); +goog.module('Blockly.IASTNodeLocation'); +goog.module.declareLegacyNamespace(); /** * An AST node location interface. * @interface */ -Blockly.IASTNodeLocation = function() {}; +const IASTNodeLocation = function() {}; + +exports = IASTNodeLocation; diff --git a/tests/deps.js b/tests/deps.js index 33396a17b..274980325 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -73,7 +73,9 @@ goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDr goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); -goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); +goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation']); +goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation']); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); @@ -87,6 +89,7 @@ goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteAr goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); +goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); From 1c72055e4f798cd98d4c2d8ddf304092f2a67835 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:42:08 -0700 Subject: [PATCH 30/36] Migrate core/interfaces/i_ast_node_location_svg.js to goog.module --- core/interfaces/i_ast_node_location_svg.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js index 7711289b1..cf7c1e1cf 100644 --- a/core/interfaces/i_ast_node_location_svg.js +++ b/core/interfaces/i_ast_node_location_svg.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IASTNodeLocationSvg'); +goog.module('Blockly.IASTNodeLocationSvg'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IASTNodeLocation'); @@ -21,18 +22,20 @@ goog.require('Blockly.IASTNodeLocation'); * @interface * @extends {Blockly.IASTNodeLocation} */ -Blockly.IASTNodeLocationSvg = function() {}; +const IASTNodeLocationSvg = function() {}; /** * Add the marker SVG to this node's SVG group. * @param {SVGElement} markerSvg The SVG root of the marker to be added to the * SVG group. */ -Blockly.IASTNodeLocationSvg.prototype.setMarkerSvg; +IASTNodeLocationSvg.prototype.setMarkerSvg; /** * Add the cursor SVG to this node's SVG group. * @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the * SVG group. */ -Blockly.IASTNodeLocationSvg.prototype.setCursorSvg; +IASTNodeLocationSvg.prototype.setCursorSvg; + +exports = IASTNodeLocationSvg; diff --git a/tests/deps.js b/tests/deps.js index 274980325..d2f153f3c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -74,7 +74,7 @@ goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connectio goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation']); +goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation']); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); From cdea0789dd79a06b0b06fd9e410d28cd838063af Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:42:37 -0700 Subject: [PATCH 31/36] Migrate core/interfaces/i_ast_node_location_svg.js named requires --- core/interfaces/i_ast_node_location_svg.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js index cf7c1e1cf..5b58d4abc 100644 --- a/core/interfaces/i_ast_node_location_svg.js +++ b/core/interfaces/i_ast_node_location_svg.js @@ -14,13 +14,13 @@ goog.module('Blockly.IASTNodeLocationSvg'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IASTNodeLocation'); +const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); /** * An AST node location SVG interface. * @interface - * @extends {Blockly.IASTNodeLocation} + * @extends {IASTNodeLocation} */ const IASTNodeLocationSvg = function() {}; From 794e4554fe3b7f191d12787b7060ea28021e2bc8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:43:03 -0700 Subject: [PATCH 32/36] Migrate core/interfaces/i_ast_node_location_with_block.js to goog.module --- core/interfaces/i_ast_node_location_with_block.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js index 612ef0e73..85606e546 100644 --- a/core/interfaces/i_ast_node_location_with_block.js +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IASTNodeLocationWithBlock'); +goog.module('Blockly.IASTNodeLocationWithBlock'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IASTNodeLocation'); goog.requireType('Blockly.Block'); @@ -23,10 +24,12 @@ goog.requireType('Blockly.Block'); * @interface * @extends {Blockly.IASTNodeLocation} */ -Blockly.IASTNodeLocationWithBlock = function() {}; +const IASTNodeLocationWithBlock = function() {}; /** * Get the source block associated with this node. * @return {Blockly.Block} The source block. */ -Blockly.IASTNodeLocationWithBlock.prototype.getSourceBlock; +IASTNodeLocationWithBlock.prototype.getSourceBlock; + +exports = IASTNodeLocationWithBlock; diff --git a/tests/deps.js b/tests/deps.js index d2f153f3c..9346e750f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -75,7 +75,7 @@ goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockl goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation']); +goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); From 04ef2705d169aead800b17336fb85c7569765d16 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:43:27 -0700 Subject: [PATCH 33/36] Migrate core/interfaces/i_ast_node_location_with_block.js named requires --- core/interfaces/i_ast_node_location_with_block.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js index 85606e546..58da7a902 100644 --- a/core/interfaces/i_ast_node_location_with_block.js +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -15,20 +15,20 @@ goog.module('Blockly.IASTNodeLocationWithBlock'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IASTNodeLocation'); -goog.requireType('Blockly.Block'); +const Block = goog.requireType('Blockly.Block'); +const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); /** * An AST node location that has an associated block. * @interface - * @extends {Blockly.IASTNodeLocation} + * @extends {IASTNodeLocation} */ const IASTNodeLocationWithBlock = function() {}; /** * Get the source block associated with this node. - * @return {Blockly.Block} The source block. + * @return {Block} The source block. */ IASTNodeLocationWithBlock.prototype.getSourceBlock; From 3d174ae058ddb2bea96b942d95b5bc4329931ada Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:32:12 -0700 Subject: [PATCH 34/36] Migrate core/interfaces/i_keyboard_accessible.js to goog.module --- core/interfaces/i_keyboard_accessible.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 5807e47bf..3720ddc08 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IKeyboardAccessible'); +goog.module('Blockly.IKeyboardAccessible'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.ShortcutRegistry'); @@ -20,11 +21,13 @@ goog.requireType('Blockly.ShortcutRegistry'); * An interface for an object that handles keyboard shortcuts. * @interface */ -Blockly.IKeyboardAccessible = function() {}; +const IKeyboardAccessible = function() {}; /** * Handles the given keyboard shortcut. * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled. * @return {boolean} True if the shortcut has been handled, false otherwise. */ -Blockly.IKeyboardAccessible.prototype.onShortcut; +IKeyboardAccessible.prototype.onShortcut; + +exports = IKeyboardAccessible; diff --git a/tests/deps.js b/tests/deps.js index 9346e750f..188e4ed43 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -89,7 +89,7 @@ goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteAr goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); -goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], []); +goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); From 94e36dba319bb1580b3e16a1f9496f5f54377740 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:32:21 -0700 Subject: [PATCH 35/36] Migrate core/interfaces/i_keyboard_accessible.js named requires --- core/interfaces/i_keyboard_accessible.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 3720ddc08..8f21153da 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -14,7 +14,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.ShortcutRegistry'); +const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); /** @@ -25,7 +25,7 @@ const IKeyboardAccessible = function() {}; /** * Handles the given keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled. + * @param {!KeyboardShortcut} shortcut The shortcut to be handled. * @return {boolean} True if the shortcut has been handled, false otherwise. */ IKeyboardAccessible.prototype.onShortcut; From bdede7c1ab5bbef39421c90db0ab5d5aceb8a734 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:41:13 -0700 Subject: [PATCH 36/36] Migrate core/interfaces/i_contextmenu.js to goog.module --- core/interfaces/i_contextmenu.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_contextmenu.js b/core/interfaces/i_contextmenu.js index fcc406b05..79117d5ed 100644 --- a/core/interfaces/i_contextmenu.js +++ b/core/interfaces/i_contextmenu.js @@ -11,16 +11,19 @@ 'use strict'; -goog.provide('Blockly.IContextMenu'); +goog.module('Blockly.IContextMenu'); +goog.module.declareLegacyNamespace(); /** * @interface */ -Blockly.IContextMenu = function() {}; +const IContextMenu = function() {}; /** * Show the context menu for this object. * @param {!Event} e Mouse event. */ -Blockly.IContextMenu.prototype.showContextMenu; +IContextMenu.prototype.showContextMenu; + +exports = IContextMenu; diff --git a/tests/deps.js b/tests/deps.js index 188e4ed43..455f21cc6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -82,7 +82,7 @@ goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoun goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); -goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); +goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'});