From 78e72222c1e82c55b04ff7a836cfec50f06e8479 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 13:48:22 -0700 Subject: [PATCH 001/313] 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 002/313] 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 003/313] 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 004/313] 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 72a07613120361d3ecc9425dd2e5127f7bd40016 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:43:15 -0700 Subject: [PATCH 005/313] Migrate core/utils/svg_paths.js to goog.module --- core/utils/svg_paths.js | 30 +++++++++++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index e123dca28..d380d45f6 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -15,7 +15,8 @@ * @name Blockly.utils.svgPaths * @namespace */ -goog.provide('Blockly.utils.svgPaths'); +goog.module('Blockly.utils.svgPaths'); +goog.module.declareLegacyNamespace(); /** @@ -28,7 +29,7 @@ goog.provide('Blockly.utils.svgPaths'); * @return {string} A string of the format ' x,y ' * @public */ -Blockly.utils.svgPaths.point = function(x, y) { +const point = function(x, y) { return ' ' + x + ',' + y + ' '; }; @@ -45,7 +46,7 @@ Blockly.utils.svgPaths.point = function(x, y) { * documentation for exact format. * @public */ -Blockly.utils.svgPaths.curve = function(command, points) { +const curve = function(command, points) { return ' ' + command + points.join(''); }; @@ -59,7 +60,7 @@ Blockly.utils.svgPaths.curve = function(command, points) { * @return {string} A string of the format ' M x,y ' * @public */ -Blockly.utils.svgPaths.moveTo = function(x, y) { +const moveTo = function(x, y) { return ' M ' + x + ',' + y + ' '; }; @@ -73,7 +74,7 @@ Blockly.utils.svgPaths.moveTo = function(x, y) { * @return {string} A string of the format ' m dx,dy ' * @public */ -Blockly.utils.svgPaths.moveBy = function(dx, dy) { +const moveBy = function(dx, dy) { return ' m ' + dx + ',' + dy + ' '; }; @@ -87,7 +88,7 @@ Blockly.utils.svgPaths.moveBy = function(dx, dy) { * @return {string} A string of the format ' l dx,dy ' * @public */ -Blockly.utils.svgPaths.lineTo = function(dx, dy) { +const lineTo = function(dx, dy) { return ' l ' + dx + ',' + dy + ' '; }; @@ -102,7 +103,7 @@ Blockly.utils.svgPaths.lineTo = function(dx, dy) { * @return {string} A string of the format ' l (dx,dy)+ ' * @public */ -Blockly.utils.svgPaths.line = function(points) { +const line = function(points) { return ' l' + points.join(''); }; @@ -119,7 +120,7 @@ Blockly.utils.svgPaths.line = function(points) { * @return {string} A string of the format ' command val ' * @public */ -Blockly.utils.svgPaths.lineOnAxis = function(command, val) { +const lineOnAxis = function(command, val) { return ' ' + command + ' ' + val + ' '; }; @@ -137,6 +138,17 @@ Blockly.utils.svgPaths.lineOnAxis = function(command, val) { * @return {string} A string of the format 'command radius radius flags point' * @public */ -Blockly.utils.svgPaths.arc = function(command, flags, radius, point) { +const arc = function(command, flags, radius, point) { return command + ' ' + radius + ' ' + radius + ' ' + flags + point; }; + +exports = { + point, + curve, + moveTo, + moveBy, + lineTo, + line, + lineOnAxis, + arc, +}; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..1c324ff68 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -185,7 +185,7 @@ 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/svg.js', ['Blockly.utils.Svg'], []); -goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); +goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); From 916b49a2e5d4a757dbf4d6504af1713edfee32ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:44:17 -0700 Subject: [PATCH 006/313] clang-format core/utils/svg_paths.js --- core/utils/svg_paths.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index d380d45f6..02602e4ac 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -39,9 +39,9 @@ const point = function(x, y) { * These coordinates are unitless and hence in the user coordinate system. * @param {string} command The command to use. * Should be one of: c, C, s, S, q, Q. - * @param {!Array} points An array containing all of the points to pass to the - * curve command, in order. The points are represented as strings of the - * format ' x, y '. + * @param {!Array} points An array containing all of the points to pass + * to the curve command, in order. The points are represented as strings of + * the format ' x, y '. * @return {string} A string defining one or more Bezier curves. See the MDN * documentation for exact format. * @public From 38324a1f637d20f87ca9090e0e1172bc2f4fbaf7 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 14 Jul 2021 15:59:30 -0700 Subject: [PATCH 007/313] Updates eslint rules to work while converting to goog.module (#5063) --- .eslintrc.json | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9d74291da..28766db11 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,29 +2,6 @@ "rules": { "curly": ["error"], "eol-last": ["error"], - // Blockly/Google use 2-space indents. - // Blockly/Google uses +4 space indents for line continuations. - // Ignore default rules for ternary expressions. - "indent": [ - "error", 2, - { - "SwitchCase": 1, - "MemberExpression": 2, - "ObjectExpression": 1, - "FunctionDeclaration": { - "body": 1, - "parameters": 2 - }, - "FunctionExpression": { - "body": 1, - "parameters": 2 - }, - "CallExpression": { - "arguments": 2 - }, - "ignoredNodes": ["ConditionalExpression"] - } - ], "keyword-spacing": ["error"], "linebreak-style": ["error", "unix"], "max-len": [ @@ -39,7 +16,7 @@ ], "no-trailing-spaces": ["error", { "skipBlankLines": true }], "no-unused-vars": [ - "error", + "warn", { "args": "after-used", // Ignore vars starting with an underscore. @@ -48,7 +25,6 @@ "argsIgnorePattern": "^_" } ], - "no-use-before-define": ["error"], // Blockly uses for exporting symbols. no-self-assign added in eslint 5. "no-self-assign": ["off"], // Blockly uses single quotes except for JSON blobs, which must use double quotes. From 466a0db8099d34dba282c8c2d55549753ca6a610 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 13:56:18 -0700 Subject: [PATCH 008/313] Migrate core/utils/rect.js to goog.module --- core/utils/rect.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/utils/rect.js b/core/utils/rect.js index 128ec4eae..318cf1d0d 100644 --- a/core/utils/rect.js +++ b/core/utils/rect.js @@ -16,7 +16,8 @@ * @name Blockly.utils.Rect * @namespace */ -goog.provide('Blockly.utils.Rect'); +goog.module('Blockly.utils.Rect'); +goog.module.declareLegacyNamespace(); /** @@ -28,7 +29,7 @@ goog.provide('Blockly.utils.Rect'); * @struct * @constructor */ -Blockly.utils.Rect = function(top, bottom, left, right) { +const Rect = function(top, bottom, left, right) { /** @type {number} */ this.top = top; @@ -49,7 +50,7 @@ Blockly.utils.Rect = function(top, bottom, left, right) { * @param {number} y The y coordinate to test for containment. * @return {boolean} Whether this rectangle contains given coordinate. */ -Blockly.utils.Rect.prototype.contains = function(x, y) { +Rect.prototype.contains = function(x, y) { return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom; }; @@ -60,7 +61,9 @@ Blockly.utils.Rect.prototype.contains = function(x, y) { * intersection with. * @return {boolean} Whether this rectangle intersects the provided rectangle. */ -Blockly.utils.Rect.prototype.intersects = function(other) { +Rect.prototype.intersects = function(other) { return !(this.left > other.right || this.right < other.left || this.top > other.bottom || this.bottom < other.top); }; + +exports = Rect; diff --git a/tests/deps.js b/tests/deps.js index 4e222cf85..b98f68ecd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -180,7 +180,7 @@ goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); +goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); 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']); From de2cff80fdec4a262048bbb401b95d6e90163e80 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 16:11:11 -0700 Subject: [PATCH 009/313] clang-format core/utils/rect.js --- core/utils/rect.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/utils/rect.js b/core/utils/rect.js index 318cf1d0d..85ade5388 100644 --- a/core/utils/rect.js +++ b/core/utils/rect.js @@ -62,7 +62,8 @@ Rect.prototype.contains = function(x, y) { * @return {boolean} Whether this rectangle intersects the provided rectangle. */ Rect.prototype.intersects = function(other) { - return !(this.left > other.right || this.right < other.left || + return !( + this.left > other.right || this.right < other.left || this.top > other.bottom || this.bottom < other.top); }; From 426c741e90f9134e013f5b37742c8dde6d6b1d11 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 17:03:33 -0700 Subject: [PATCH 010/313] Migrate core/utils/colour.js to ES6 const/let --- core/utils/colour.js | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index b64b81eb5..12c9a9998 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -32,7 +32,7 @@ goog.provide('Blockly.utils.colour'); */ Blockly.utils.colour.parse = function(str) { str = String(str).toLowerCase().trim(); - var hex = Blockly.utils.colour.names[str]; + let hex = Blockly.utils.colour.names[str]; if (hex) { // e.g. 'red' return hex; @@ -47,12 +47,12 @@ Blockly.utils.colour.parse = function(str) { // e.g. '#0f8' return ['#', hex[1], hex[1], hex[2], hex[2], hex[3], hex[3]].join(''); } - var rgb = str.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/); + const rgb = str.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/); if (rgb) { // e.g. 'rgb(0, 128, 255)' - var r = Number(rgb[1]); - var g = Number(rgb[2]); - var b = Number(rgb[3]); + const r = Number(rgb[1]); + const g = Number(rgb[2]); + const b = Number(rgb[3]); if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) { return Blockly.utils.colour.rgbToHex(r, g, b); } @@ -68,7 +68,7 @@ Blockly.utils.colour.parse = function(str) { * @return {string} Hex representation of the colour. */ Blockly.utils.colour.rgbToHex = function(r, g, b) { - var rgb = (r << 16) | (g << 8) | b; + const rgb = (r << 16) | (g << 8) | b; if (r < 0x10) { return '#' + (0x1000000 | rgb).toString(16).substr(1); } @@ -82,15 +82,15 @@ Blockly.utils.colour.rgbToHex = function(r, g, b) { * @return {!Array} RGB representation of the colour. */ Blockly.utils.colour.hexToRgb = function(colour) { - var hex = Blockly.utils.colour.parse(colour); + const hex = Blockly.utils.colour.parse(colour); if (!hex) { return [0, 0, 0]; } - var rgb = parseInt(hex.substr(1), 16); - var r = rgb >> 16; - var g = (rgb >> 8) & 255; - var b = rgb & 255; + const rgb = parseInt(hex.substr(1), 16); + const r = rgb >> 16; + const g = (rgb >> 8) & 255; + const b = rgb & 255; return [r, g, b]; }; @@ -103,19 +103,19 @@ Blockly.utils.colour.hexToRgb = function(colour) { * @return {string} Hex representation of the colour. */ Blockly.utils.colour.hsvToHex = function(h, s, v) { - var red = 0; - var green = 0; - var blue = 0; + let red = 0; + let green = 0; + let blue = 0; if (s == 0) { red = v; green = v; blue = v; } else { - var sextant = Math.floor(h / 60); - var remainder = (h / 60) - sextant; - var val1 = v * (1 - s); - var val2 = v * (1 - (s * remainder)); - var val3 = v * (1 - (s * (1 - remainder))); + const sextant = Math.floor(h / 60); + const remainder = (h / 60) - sextant; + const val1 = v * (1 - s); + const val2 = v * (1 - (s * remainder)); + const val3 = v * (1 - (s * (1 - remainder))); switch (sextant) { case 1: red = val2; @@ -164,19 +164,19 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { * @return {?string} Combined colour represented in hex. */ Blockly.utils.colour.blend = function(colour1, colour2, factor) { - var hex1 = Blockly.utils.colour.parse(colour1); + const hex1 = Blockly.utils.colour.parse(colour1); if (!hex1) { return null; } - var hex2 = Blockly.utils.colour.parse(colour2); + const hex2 = Blockly.utils.colour.parse(colour2); if (!hex2) { return null; } - var rgb1 = Blockly.utils.colour.hexToRgb(hex1); - var rgb2 = Blockly.utils.colour.hexToRgb(hex2); - var r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); - var g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); - var b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); + const rgb1 = Blockly.utils.colour.hexToRgb(hex1); + const rgb2 = Blockly.utils.colour.hexToRgb(hex2); + const r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); + const g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); + const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); return Blockly.utils.colour.rgbToHex(r, g, b); }; From 8abfa3d888f81136d6cc337a154aea7e0a7b0477 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:53:16 -0700 Subject: [PATCH 011/313] Migrate core/utils/colour.js to goog.module --- core/utils/colour.js | 35 +++++++++++++++++++---------------- tests/deps.js | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index 12c9a9998..dffd193f3 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -16,7 +16,8 @@ * @name Blockly.utils.colour * @namespace */ -goog.provide('Blockly.utils.colour'); +goog.module('Blockly.utils.colour'); +goog.module.declareLegacyNamespace(); /** @@ -30,9 +31,9 @@ goog.provide('Blockly.utils.colour'); * @return {?string} A string containing a hex representation of the colour, * or null if can't be parsed. */ -Blockly.utils.colour.parse = function(str) { +const parse = function(str) { str = String(str).toLowerCase().trim(); - let hex = Blockly.utils.colour.names[str]; + let hex = names[str]; if (hex) { // e.g. 'red' return hex; @@ -54,7 +55,7 @@ Blockly.utils.colour.parse = function(str) { const g = Number(rgb[2]); const b = Number(rgb[3]); if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) { - return Blockly.utils.colour.rgbToHex(r, g, b); + return rgbToHex(r, g, b); } } return null; @@ -67,7 +68,7 @@ Blockly.utils.colour.parse = function(str) { * @param {number} b Amount of blue, int between 0 and 255. * @return {string} Hex representation of the colour. */ -Blockly.utils.colour.rgbToHex = function(r, g, b) { +const rgbToHex = function(r, g, b) { const rgb = (r << 16) | (g << 8) | b; if (r < 0x10) { return '#' + (0x1000000 | rgb).toString(16).substr(1); @@ -81,8 +82,8 @@ Blockly.utils.colour.rgbToHex = function(r, g, b) { * colour format ('#ff0000', 'red', '0xff000', etc). * @return {!Array} RGB representation of the colour. */ -Blockly.utils.colour.hexToRgb = function(colour) { - const hex = Blockly.utils.colour.parse(colour); +const hexToRgb = function(colour) { + const hex = parse(colour); if (!hex) { return [0, 0, 0]; } @@ -102,7 +103,7 @@ Blockly.utils.colour.hexToRgb = function(colour) { * @param {number} v Brightness in [0, 255]. * @return {string} Hex representation of the colour. */ -Blockly.utils.colour.hsvToHex = function(h, s, v) { +const hsvToHex = function(h, s, v) { let red = 0; let green = 0; let blue = 0; @@ -150,7 +151,7 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { break; } } - return Blockly.utils.colour.rgbToHex( + return rgbToHex( Math.floor(red), Math.floor(green), Math.floor(blue)); }; @@ -163,21 +164,21 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { * Values should be in the range [0, 1]. * @return {?string} Combined colour represented in hex. */ -Blockly.utils.colour.blend = function(colour1, colour2, factor) { - const hex1 = Blockly.utils.colour.parse(colour1); +const blend = function(colour1, colour2, factor) { + const hex1 = parse(colour1); if (!hex1) { return null; } - const hex2 = Blockly.utils.colour.parse(colour2); + const hex2 = parse(colour2); if (!hex2) { return null; } - const rgb1 = Blockly.utils.colour.hexToRgb(hex1); - const rgb2 = Blockly.utils.colour.hexToRgb(hex2); + const rgb1 = hexToRgb(hex1); + const rgb2 = hexToRgb(hex2); const r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); const g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); - return Blockly.utils.colour.rgbToHex(r, g, b); + return rgbToHex(r, g, b); }; /** @@ -188,7 +189,7 @@ Blockly.utils.colour.blend = function(colour1, colour2, factor) { * * @type {!Object} */ -Blockly.utils.colour.names = { +const names = { 'aqua': '#00ffff', 'black': '#000000', 'blue': '#0000ff', @@ -206,3 +207,5 @@ Blockly.utils.colour.names = { 'white': '#ffffff', 'yellow': '#ffff00' }; + +exports = {parse, rgbToHex, hexToRgb, hsvToHex, blend, names}; diff --git a/tests/deps.js b/tests/deps.js index b98f68ecd..e83f61c67 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -170,7 +170,7 @@ goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Bl goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); -goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); +goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); From f63bf29b7689b0ed92cfa2fb70f1be9b79fda2b8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:53:21 -0700 Subject: [PATCH 012/313] clang-format core/utils/colour.js --- core/utils/colour.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index dffd193f3..7b2c978f4 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -151,8 +151,7 @@ const hsvToHex = function(h, s, v) { break; } } - return rgbToHex( - Math.floor(red), Math.floor(green), Math.floor(blue)); + return rgbToHex(Math.floor(red), Math.floor(green), Math.floor(blue)); }; /** @@ -208,4 +207,11 @@ const names = { 'yellow': '#ffff00' }; -exports = {parse, rgbToHex, hexToRgb, hsvToHex, blend, names}; +exports = { + parse, + rgbToHex, + hexToRgb, + hsvToHex, + blend, + names +}; From f0d905dde0371a98f84eb3515d97f609e96b86ff Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 14 Jul 2021 14:18:05 -0700 Subject: [PATCH 013/313] Migrate core/utils/toolbox.js to ES6 const/let --- core/utils/toolbox.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index e9a9d2b2a..cbca92843 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -206,7 +206,7 @@ Blockly.utils.toolbox.convertToolboxDefToJson = function(toolboxDef) { toolboxDef = Blockly.utils.toolbox.convertToToolboxJson_(toolboxDef); } - var toolboxJson = /** @type {Blockly.utils.toolbox.ToolboxInfo} */ (toolboxDef); + const toolboxJson = /** @type {Blockly.utils.toolbox.ToolboxInfo} */ (toolboxDef); Blockly.utils.toolbox.validateToolbox_(toolboxJson); return toolboxJson; }; @@ -219,8 +219,8 @@ Blockly.utils.toolbox.convertToolboxDefToJson = function(toolboxDef) { * @private */ Blockly.utils.toolbox.validateToolbox_ = function(toolboxJson) { - var toolboxKind = toolboxJson['kind']; - var toolboxContents = toolboxJson['contents']; + const toolboxKind = toolboxJson['kind']; + const toolboxContents = toolboxJson['contents']; if (toolboxKind) { if (toolboxKind != Blockly.utils.toolbox.FLYOUT_TOOLBOX_KIND && @@ -274,12 +274,12 @@ Blockly.utils.toolbox.hasCategories = function(toolboxJson) { return false; } - var toolboxKind = toolboxJson['kind']; + let toolboxKind = toolboxJson['kind']; if (toolboxKind) { return toolboxKind == Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND; } - var categories = toolboxJson['contents'].filter(function(item) { + const categories = toolboxJson['contents'].filter(function (item) { return item['kind'].toUpperCase() == 'CATEGORY'; }); return !!categories.length; @@ -297,7 +297,7 @@ Blockly.utils.toolbox.isCategoryCollapsible = function(categoryInfo) { return false; } - var categories = categoryInfo['contents'].filter(function(item) { + const categories = categoryInfo['contents'].filter(function(item) { return item['kind'].toUpperCase() == 'CATEGORY'; }); return !!categories.length; @@ -311,9 +311,9 @@ Blockly.utils.toolbox.isCategoryCollapsible = function(categoryInfo) { * @private */ Blockly.utils.toolbox.convertToToolboxJson_ = function(toolboxDef) { - var contents = Blockly.utils.toolbox.xmlToJsonArray_( + const contents = Blockly.utils.toolbox.xmlToJsonArray_( /** @type {!Node|!Array} */ (toolboxDef)); - var toolboxJson = {'contents': contents}; + const toolboxJson = {'contents': contents}; if (toolboxDef instanceof Node) { Blockly.utils.toolbox.addAttributes_(toolboxDef, toolboxJson); } @@ -330,19 +330,19 @@ Blockly.utils.toolbox.convertToToolboxJson_ = function(toolboxDef) { * @private */ Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { - var arr = []; + const arr = []; // If it is a node it will have children. - var childNodes = toolboxDef.childNodes; + let childNodes = toolboxDef.childNodes; if (!childNodes) { // Otherwise the toolboxDef is an array or collection. childNodes = toolboxDef; } - for (var i = 0, child; (child = childNodes[i]); i++) { + for (let i = 0, child; (child = childNodes[i]); i++) { if (!child.tagName) { continue; } - var obj = {}; - var tagName = child.tagName.toUpperCase(); + const obj = {}; + const tagName = child.tagName.toUpperCase(); obj['kind'] = tagName; // Store the XML for a block. @@ -367,8 +367,8 @@ Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { * @private */ Blockly.utils.toolbox.addAttributes_ = function(node, obj) { - for (var j = 0; j < node.attributes.length; j++) { - var attr = node.attributes[j]; + for (let j = 0; j < node.attributes.length; j++) { + const attr = node.attributes[j]; if (attr.nodeName.indexOf('css-') > -1) { obj['cssconfig'] = obj['cssconfig'] || {}; obj['cssconfig'][attr.nodeName.replace('css-', '')] = attr.value; From d3cc70eb37e367e9707b5757d58e4c4c2e3a4759 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 15 Jul 2021 12:56:01 -0700 Subject: [PATCH 014/313] Migrate core/utils/toolbox.js to goog.module --- core/utils/toolbox.js | 140 +++++++++++++++++++++--------------------- tests/deps.js | 9 +-- 2 files changed, 76 insertions(+), 73 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index cbca92843..51ffdc7eb 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -14,7 +14,8 @@ * @name Blockly.utils.toolbox * @namespace */ -goog.provide('Blockly.utils.toolbox'); +goog.module('Blockly.utils.toolbox'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); @@ -34,7 +35,7 @@ goog.requireType('Blockly.ToolboxSeparator'); * disabled: (string|boolean|undefined) * }} */ -Blockly.utils.toolbox.BlockInfo; +let BlockInfo; /** * The information needed to create a separator in the toolbox. @@ -45,7 +46,7 @@ Blockly.utils.toolbox.BlockInfo; * cssconfig:(!Blockly.ToolboxSeparator.CssConfig|undefined) * }} */ -Blockly.utils.toolbox.SeparatorInfo; +let SeparatorInfo; /** * The information needed to create a button in the toolbox. @@ -55,7 +56,7 @@ Blockly.utils.toolbox.SeparatorInfo; * callbackkey:string * }} */ -Blockly.utils.toolbox.ButtonInfo; +let ButtonInfo; /** * The information needed to create a label in the toolbox. @@ -65,21 +66,21 @@ Blockly.utils.toolbox.ButtonInfo; * id:(string|undefined) * }} */ -Blockly.utils.toolbox.LabelInfo; +let LabelInfo; /** * The information needed to create either a button or a label in the flyout. - * @typedef {Blockly.utils.toolbox.ButtonInfo| - * Blockly.utils.toolbox.LabelInfo} + * @typedef {ButtonInfo| + * LabelInfo} */ -Blockly.utils.toolbox.ButtonOrLabelInfo; +let ButtonOrLabelInfo; /** * The information needed to create a category in the toolbox. * @typedef {{ * kind:string, * name:string, - * contents:!Array, + * contents:!Array, * id:(string|undefined), * categorystyle:(string|undefined), * colour:(string|undefined), @@ -87,7 +88,7 @@ Blockly.utils.toolbox.ButtonOrLabelInfo; * hidden:(string|undefined) * }} */ -Blockly.utils.toolbox.StaticCategoryInfo; +let StaticCategoryInfo; /** * The information needed to create a custom category. @@ -101,65 +102,65 @@ Blockly.utils.toolbox.StaticCategoryInfo; * hidden:(string|undefined) * }} */ -Blockly.utils.toolbox.DynamicCategoryInfo; +let DynamicCategoryInfo; /** * The information needed to create either a dynamic or static category. - * @typedef {Blockly.utils.toolbox.StaticCategoryInfo| - * Blockly.utils.toolbox.DynamicCategoryInfo} + * @typedef {StaticCategoryInfo| + * DynamicCategoryInfo} */ -Blockly.utils.toolbox.CategoryInfo; +let CategoryInfo; /** * Any information that can be used to create an item in the toolbox. - * @typedef {Blockly.utils.toolbox.FlyoutItemInfo| - * Blockly.utils.toolbox.StaticCategoryInfo} + * @typedef {FlyoutItemInfo| + * StaticCategoryInfo} */ -Blockly.utils.toolbox.ToolboxItemInfo; +let ToolboxItemInfo; /** * All the different types that can be displayed in a flyout. - * @typedef {Blockly.utils.toolbox.BlockInfo| - * Blockly.utils.toolbox.SeparatorInfo| - * Blockly.utils.toolbox.ButtonInfo| - * Blockly.utils.toolbox.LabelInfo| - * Blockly.utils.toolbox.DynamicCategoryInfo} + * @typedef {BlockInfo| + * SeparatorInfo| + * ButtonInfo| + * LabelInfo| + * DynamicCategoryInfo} */ -Blockly.utils.toolbox.FlyoutItemInfo; +let FlyoutItemInfo; /** * The JSON definition of a toolbox. * @typedef {{ * kind:(string|undefined), - * contents:!Array + * contents:!Array * }} */ -Blockly.utils.toolbox.ToolboxInfo; +let ToolboxInfo; /** * An array holding flyout items. * @typedef { - * Array + * Array * } */ -Blockly.utils.toolbox.FlyoutItemInfoArray; +let FlyoutItemInfoArray; /** * All of the different types that can create a toolbox. * @typedef {Node| - * Blockly.utils.toolbox.ToolboxInfo| + * ToolboxInfo| * string} */ -Blockly.utils.toolbox.ToolboxDefinition; +let ToolboxDefinition; /** * All of the different types that can be used to show items in a flyout. - * @typedef {Blockly.utils.toolbox.FlyoutItemInfoArray| + * @typedef {FlyoutItemInfoArray| * NodeList| - * Blockly.utils.toolbox.ToolboxInfo| + * ToolboxInfo| * Array} */ -Blockly.utils.toolbox.FlyoutDefinition; +let FlyoutDefinition; /** * The name used to identify a toolbox that has category like items. @@ -168,20 +169,20 @@ Blockly.utils.toolbox.FlyoutDefinition; * 'category'. * @const {string} */ -Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND = 'categoryToolbox'; +const CATEGORY_TOOLBOX_KIND = 'categoryToolbox'; /** * The name used to identify a toolbox that has no categories and is displayed * as a simple flyout displaying blocks, buttons, or labels. * @const {string} */ -Blockly.utils.toolbox.FLYOUT_TOOLBOX_KIND = 'flyoutToolbox'; +const FLYOUT_TOOLBOX_KIND = 'flyoutToolbox'; /** * Position of the toolbox and/or flyout relative to the workspace. * @enum {number} */ -Blockly.utils.toolbox.Position = { +const Position = { TOP: 0, BOTTOM: 1, LEFT: 2, @@ -190,45 +191,45 @@ Blockly.utils.toolbox.Position = { /** * Converts the toolbox definition into toolbox JSON. - * @param {?Blockly.utils.toolbox.ToolboxDefinition} toolboxDef The definition + * @param {?ToolboxDefinition} toolboxDef The definition * of the toolbox in one of its many forms. - * @return {?Blockly.utils.toolbox.ToolboxInfo} Object holding information + * @return {?ToolboxInfo} Object holding information * for creating a toolbox. * @package */ -Blockly.utils.toolbox.convertToolboxDefToJson = function(toolboxDef) { +const convertToolboxDefToJson = function(toolboxDef) { if (!toolboxDef) { return null; } if (toolboxDef instanceof Element || typeof toolboxDef == 'string') { - toolboxDef = Blockly.utils.toolbox.parseToolboxTree(toolboxDef); - toolboxDef = Blockly.utils.toolbox.convertToToolboxJson_(toolboxDef); + toolboxDef = parseToolboxTree(toolboxDef); + toolboxDef = convertToToolboxJson(toolboxDef); } - const toolboxJson = /** @type {Blockly.utils.toolbox.ToolboxInfo} */ (toolboxDef); - Blockly.utils.toolbox.validateToolbox_(toolboxJson); + const toolboxJson = /** @type {ToolboxInfo} */ (toolboxDef); + validateToolbox(toolboxJson); return toolboxJson; }; /** * Validates the toolbox JSON fields have been set correctly. - * @param {!Blockly.utils.toolbox.ToolboxInfo} toolboxJson Object holding + * @param {!ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @throws {Error} if the toolbox is not the correct format. * @private */ -Blockly.utils.toolbox.validateToolbox_ = function(toolboxJson) { +const validateToolbox = function(toolboxJson) { const toolboxKind = toolboxJson['kind']; const toolboxContents = toolboxJson['contents']; if (toolboxKind) { - if (toolboxKind != Blockly.utils.toolbox.FLYOUT_TOOLBOX_KIND && - toolboxKind != Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND) { + if (toolboxKind != FLYOUT_TOOLBOX_KIND && + toolboxKind != CATEGORY_TOOLBOX_KIND) { throw Error('Invalid toolbox kind ' + toolboxKind + '.' + ' Please supply either ' + - Blockly.utils.toolbox.FLYOUT_TOOLBOX_KIND + ' or ' + - Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND); + FLYOUT_TOOLBOX_KIND + ' or ' + + CATEGORY_TOOLBOX_KIND); } } if (!toolboxContents) { @@ -238,12 +239,12 @@ Blockly.utils.toolbox.validateToolbox_ = function(toolboxJson) { /** * Converts the flyout definition into a list of flyout items. - * @param {?Blockly.utils.toolbox.FlyoutDefinition} flyoutDef The definition of + * @param {?FlyoutDefinition} flyoutDef The definition of * the flyout in one of its many forms. - * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray} A list of flyout items. + * @return {!FlyoutItemInfoArray} A list of flyout items. * @package */ -Blockly.utils.toolbox.convertFlyoutDefToJsonArray = function(flyoutDef) { +const convertFlyoutDefToJsonArray = function(flyoutDef) { if (!flyoutDef) { return []; } @@ -258,25 +259,24 @@ Blockly.utils.toolbox.convertFlyoutDefToJsonArray = function(flyoutDef) { return flyoutDef; } - return Blockly.utils.toolbox.xmlToJsonArray_( - /** @type {!Array|!NodeList} */ (flyoutDef)); + return xmlToJsonArray(/** @type {!Array|!NodeList} */ (flyoutDef)); }; /** * Whether or not the toolbox definition has categories. - * @param {?Blockly.utils.toolbox.ToolboxInfo} toolboxJson Object holding + * @param {?ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @return {boolean} True if the toolbox has categories. * @package */ -Blockly.utils.toolbox.hasCategories = function(toolboxJson) { +const hasCategories = function(toolboxJson) { if (!toolboxJson) { return false; } let toolboxKind = toolboxJson['kind']; if (toolboxKind) { - return toolboxKind == Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND; + return toolboxKind == CATEGORY_TOOLBOX_KIND; } const categories = toolboxJson['contents'].filter(function (item) { @@ -287,12 +287,12 @@ Blockly.utils.toolbox.hasCategories = function(toolboxJson) { /** * Whether or not the category is collapsible. - * @param {!Blockly.utils.toolbox.CategoryInfo} categoryInfo Object holing + * @param {!CategoryInfo} categoryInfo Object holing * information for creating a category. * @return {boolean} True if the category has subcategories. * @package */ -Blockly.utils.toolbox.isCategoryCollapsible = function(categoryInfo) { +const isCategoryCollapsible = function(categoryInfo) { if (!categoryInfo || !categoryInfo['contents']) { return false; } @@ -306,16 +306,16 @@ Blockly.utils.toolbox.isCategoryCollapsible = function(categoryInfo) { /** * Parses the provided toolbox definition into a consistent format. * @param {Node} toolboxDef The definition of the toolbox in one of its many forms. - * @return {!Blockly.utils.toolbox.ToolboxInfo} Object holding information + * @return {!ToolboxInfo} Object holding information * for creating a toolbox. * @private */ -Blockly.utils.toolbox.convertToToolboxJson_ = function(toolboxDef) { - const contents = Blockly.utils.toolbox.xmlToJsonArray_( +const convertToToolboxJson = function(toolboxDef) { + const contents = xmlToJsonArray( /** @type {!Node|!Array} */ (toolboxDef)); const toolboxJson = {'contents': contents}; if (toolboxDef instanceof Node) { - Blockly.utils.toolbox.addAttributes_(toolboxDef, toolboxJson); + addAttributes(toolboxDef, toolboxJson); } return toolboxJson; }; @@ -324,12 +324,12 @@ Blockly.utils.toolbox.convertToToolboxJson_ = function(toolboxDef) { * Converts the xml for a toolbox to JSON. * @param {!Node|!Array|!NodeList} toolboxDef The * definition of the toolbox in one of its many forms. - * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray| - * !Array} A list of objects in + * @return {!FlyoutItemInfoArray| + * !Array} A list of objects in * the toolbox. * @private */ -Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { +const xmlToJsonArray = function(toolboxDef) { const arr = []; // If it is a node it will have children. let childNodes = toolboxDef.childNodes; @@ -350,11 +350,11 @@ Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { obj['blockxml'] = child; } else if (child.childNodes && child.childNodes.length > 0) { // Get the contents of a category - obj['contents'] = Blockly.utils.toolbox.xmlToJsonArray_(child); + obj['contents'] = xmlToJsonArray(child); } // Add XML attributes to object - Blockly.utils.toolbox.addAttributes_(child, obj); + addAttributes(child, obj); arr.push(obj); } return arr; @@ -366,7 +366,7 @@ Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { * @param {!Object} obj The object to copy the attributes to. * @private */ -Blockly.utils.toolbox.addAttributes_ = function(node, obj) { +const addAttributes = function(node, obj) { for (let j = 0; j < node.attributes.length; j++) { const attr = node.attributes[j]; if (attr.nodeName.indexOf('css-') > -1) { @@ -384,7 +384,7 @@ Blockly.utils.toolbox.addAttributes_ = function(node, obj) { * of same. * @return {?Node} DOM tree of blocks, or null. */ -Blockly.utils.toolbox.parseToolboxTree = function(toolboxDef) { +const parseToolboxTree = function(toolboxDef) { if (toolboxDef) { if (typeof toolboxDef != 'string') { if (Blockly.utils.userAgent.IE && toolboxDef.outerHTML) { @@ -408,3 +408,5 @@ Blockly.utils.toolbox.parseToolboxTree = function(toolboxDef) { } return toolboxDef; }; + +exports = {BlockInfo, SeparatorInfo, ButtonInfo, LabelInfo, ButtonOrLabelInfo, StaticCategoryInfo, DynamicCategoryInfo, CategoryInfo, ToolboxItemInfo, FlyoutItemInfo, ToolboxInfo, FlyoutItemInfoArray, ToolboxDefinition, FlyoutDefinition, Position, convertToolboxDefToJson, convertFlyoutDefToJsonArray, hasCategories, isCategoryCollapsible, parseToolboxTree} diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..0654ec508 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -4,6 +4,7 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Co goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); +goog.addDependency('../../blocks/test_blocks.js', ['Blockly.TestBlocks'], ['Blockly', 'Blockly.Blocks'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -170,7 +171,7 @@ goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Bl goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); -goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); @@ -180,13 +181,13 @@ goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/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/svg.js', ['Blockly.utils.Svg'], []); -goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); +goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); From 2ab3bfd4cbd51ef1357b6271efb3debcea313c67 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 15 Jul 2021 11:29:50 -0700 Subject: [PATCH 015/313] Migrate core/utils/toolbox.js named requires --- core/utils/toolbox.js | 19 +++++++++---------- tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index 51ffdc7eb..40e9fe78b 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -17,12 +17,11 @@ goog.module('Blockly.utils.toolbox'); goog.module.declareLegacyNamespace(); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -goog.require('Blockly.Xml'); +const {IE} = goog.require('Blockly.utils.userAgent'); +const {textToDom} = goog.require('Blockly.Xml'); -goog.requireType('Blockly.ToolboxCategory'); -goog.requireType('Blockly.ToolboxSeparator'); +const {CssConfig: CategoryCssConfig} = goog.requireType('Blockly.ToolboxCategory'); +const {CssConfig: SeparatorCssConfig} = goog.requireType('Blockly.ToolboxSeparator'); /** @@ -43,7 +42,7 @@ let BlockInfo; * kind:string, * id:(string|undefined), * gap:(number|undefined), - * cssconfig:(!Blockly.ToolboxSeparator.CssConfig|undefined) + * cssconfig:(!SeparatorCssConfig|undefined) * }} */ let SeparatorInfo; @@ -84,7 +83,7 @@ let ButtonOrLabelInfo; * id:(string|undefined), * categorystyle:(string|undefined), * colour:(string|undefined), - * cssconfig:(!Blockly.ToolboxCategory.CssConfig|undefined), + * cssconfig:(!CategoryCssConfig|undefined), * hidden:(string|undefined) * }} */ @@ -98,7 +97,7 @@ let StaticCategoryInfo; * id:(string|undefined), * categorystyle:(string|undefined), * colour:(string|undefined), - * cssconfig:(!Blockly.ToolboxCategory.CssConfig|undefined), + * cssconfig:(!CategoryCssConfig|undefined), * hidden:(string|undefined) * }} */ @@ -387,7 +386,7 @@ const addAttributes = function(node, obj) { const parseToolboxTree = function(toolboxDef) { if (toolboxDef) { if (typeof toolboxDef != 'string') { - if (Blockly.utils.userAgent.IE && toolboxDef.outerHTML) { + if (IE && toolboxDef.outerHTML) { // In this case the tree will not have been properly built by the // browser. The HTML will be contained in the element, but it will // not have the proper DOM structure since the browser doesn't support @@ -398,7 +397,7 @@ const parseToolboxTree = function(toolboxDef) { } } if (typeof toolboxDef == 'string') { - toolboxDef = Blockly.Xml.textToDom(toolboxDef); + toolboxDef = textToDom(toolboxDef); if (toolboxDef.nodeName.toLowerCase() != 'xml') { throw TypeError('Toolbox should be an document.'); } diff --git a/tests/deps.js b/tests/deps.js index 0654ec508..81507d9de 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -187,7 +187,7 @@ 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/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'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); From fe9273ad5c60a53130a18e6e6806a788893e01b2 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 15 Jul 2021 13:00:45 -0700 Subject: [PATCH 016/313] clang-format core/utils/toolbox.js --- core/utils/toolbox.js | 38 ++++++++++++++++++++++++++++++-------- tests/deps.js | 6 +++--- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index 40e9fe78b..ec050d178 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -224,11 +224,11 @@ const validateToolbox = function(toolboxJson) { if (toolboxKind) { if (toolboxKind != FLYOUT_TOOLBOX_KIND && - toolboxKind != CATEGORY_TOOLBOX_KIND) { - throw Error('Invalid toolbox kind ' + toolboxKind + '.' + - ' Please supply either ' + - FLYOUT_TOOLBOX_KIND + ' or ' + - CATEGORY_TOOLBOX_KIND); + toolboxKind != CATEGORY_TOOLBOX_KIND) { + throw Error( + 'Invalid toolbox kind ' + toolboxKind + '.' + + ' Please supply either ' + FLYOUT_TOOLBOX_KIND + ' or ' + + CATEGORY_TOOLBOX_KIND); } } if (!toolboxContents) { @@ -278,7 +278,7 @@ const hasCategories = function(toolboxJson) { return toolboxKind == CATEGORY_TOOLBOX_KIND; } - const categories = toolboxJson['contents'].filter(function (item) { + const categories = toolboxJson['contents'].filter(function(item) { return item['kind'].toUpperCase() == 'CATEGORY'; }); return !!categories.length; @@ -304,7 +304,8 @@ const isCategoryCollapsible = function(categoryInfo) { /** * Parses the provided toolbox definition into a consistent format. - * @param {Node} toolboxDef The definition of the toolbox in one of its many forms. + * @param {Node} toolboxDef The definition of the toolbox in one of its many + * forms. * @return {!ToolboxInfo} Object holding information * for creating a toolbox. * @private @@ -408,4 +409,25 @@ const parseToolboxTree = function(toolboxDef) { return toolboxDef; }; -exports = {BlockInfo, SeparatorInfo, ButtonInfo, LabelInfo, ButtonOrLabelInfo, StaticCategoryInfo, DynamicCategoryInfo, CategoryInfo, ToolboxItemInfo, FlyoutItemInfo, ToolboxInfo, FlyoutItemInfoArray, ToolboxDefinition, FlyoutDefinition, Position, convertToolboxDefToJson, convertFlyoutDefToJsonArray, hasCategories, isCategoryCollapsible, parseToolboxTree} +exports = { + BlockInfo, + SeparatorInfo, + ButtonInfo, + LabelInfo, + ButtonOrLabelInfo, + StaticCategoryInfo, + DynamicCategoryInfo, + CategoryInfo, + ToolboxItemInfo, + FlyoutItemInfo, + ToolboxInfo, + FlyoutItemInfoArray, + ToolboxDefinition, + FlyoutDefinition, + Position, + convertToolboxDefToJson, + convertFlyoutDefToJsonArray, + hasCategories, + isCategoryCollapsible, + parseToolboxTree +} diff --git a/tests/deps.js b/tests/deps.js index 81507d9de..3d4531cf1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -171,7 +171,7 @@ goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Bl goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); -goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); +goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); @@ -181,12 +181,12 @@ goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); +goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); 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/svg.js', ['Blockly.utils.Svg'], []); -goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); +goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); From b43b19c7a336b59b93986b29cfbb3406a76f8040 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 15 Jul 2021 14:38:16 -0700 Subject: [PATCH 017/313] Migrate core/renderers/common/drawer.js to ES6 const/let --- core/renderers/common/drawer.js | 120 ++++++++++++++++---------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index f91b97d7a..0d3a5bab9 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -90,7 +90,7 @@ Blockly.blockRendering.Drawer.prototype.recordSizeOnBlock_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.hideHiddenIcons_ = function() { - for (var i = 0, iconInfo; (iconInfo = this.info_.hiddenIcons[i]); i++) { + for (let i = 0, iconInfo; (iconInfo = this.info_.hiddenIcons[i]); i++) { iconInfo.icon.iconGroup_.setAttribute('display', 'none'); } }; @@ -101,8 +101,8 @@ Blockly.blockRendering.Drawer.prototype.hideHiddenIcons_ = function() { */ Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { this.drawTop_(); - for (var r = 1; r < this.info_.rows.length - 1; r++) { - var row = this.info_.rows[r]; + for (let r = 1; r < this.info_.rows.length - 1; r++) { + const row = this.info_.rows[r]; if (row.hasJaggedEdge) { this.drawJaggedEdge_(row); } else if (row.hasStatement) { @@ -124,13 +124,13 @@ Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { - var topRow = this.info_.topRow; - var elements = topRow.elements; + const topRow = this.info_.topRow; + const elements = topRow.elements; this.positionPreviousConnection_(); this.outlinePath_ += Blockly.utils.svgPaths.moveBy(topRow.xPos, this.info_.startY); - for (var i = 0, elem; (elem = elements[i]); i++) { + for (let i = 0, elem; (elem = elements[i]); i++) { if (Blockly.blockRendering.Types.isLeftRoundedCorner(elem)) { this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topLeft; @@ -155,8 +155,7 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) { - var remainder = - row.height - this.constants_.JAGGED_TEETH.height; + const remainder = row.height - this.constants_.JAGGED_TEETH.height; this.outlinePath_ += this.constants_.JAGGED_TEETH.path + Blockly.utils.svgPaths.lineOnAxis('v', remainder); }; @@ -169,10 +168,10 @@ Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) { * @protected */ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { - var input = row.getLastInput(); + const input = row.getLastInput(); this.positionExternalValueConnection_(row); - var pathDown = (typeof input.shape.pathDown == "function") ? + const pathDown = (typeof input.shape.pathDown == 'function') ? input.shape.pathDown(input.height) : input.shape.pathDown; @@ -190,18 +189,16 @@ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { * @protected */ Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) { - var input = row.getLastInput(); + const input = row.getLastInput(); // Where to start drawing the notch, which is on the right side in LTR. - var x = input.xPos + input.notchOffset + input.shape.width; + const x = input.xPos + input.notchOffset + input.shape.width; - var innerTopLeftCorner = - input.shape.pathRight + - Blockly.utils.svgPaths.lineOnAxis('h', - -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + + const innerTopLeftCorner = input.shape.pathRight + + Blockly.utils.svgPaths.lineOnAxis( + 'h', -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + this.constants_.INSIDE_CORNERS.pathTop; - var innerHeight = - row.height - (2 * this.constants_.INSIDE_CORNERS.height); + const innerHeight = row.height - (2 * this.constants_.INSIDE_CORNERS.height); this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('H', x) + innerTopLeftCorner + @@ -231,13 +228,13 @@ Blockly.blockRendering.Drawer.prototype.drawRightSideRow_ = function(row) { * @protected */ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { - var bottomRow = this.info_.bottomRow; - var elems = bottomRow.elements; + const bottomRow = this.info_.bottomRow; + const elems = bottomRow.elements; this.positionNextConnection_(); - var rightCornerYOffset = 0; - var outlinePath = ''; - for (var i = elems.length - 1, elem; (elem = elems[i]); i--) { + let rightCornerYOffset = 0; + let outlinePath = ''; + for (let i = elems.length - 1, elem; (elem = elems[i]); i--) { if (Blockly.blockRendering.Types.isNextConnection(elem)) { outlinePath += elem.shape.pathRight; } else if (Blockly.blockRendering.Types.isLeftSquareCorner(elem)) { @@ -263,13 +260,13 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { - var outputConnection = this.info_.outputConnection; + const outputConnection = this.info_.outputConnection; this.positionOutputConnection_(); if (outputConnection) { - var tabBottom = outputConnection.connectionOffsetY + - outputConnection.height; - var pathUp = (typeof outputConnection.shape.pathUp == "function") ? + const tabBottom = + outputConnection.connectionOffsetY + outputConnection.height; + const pathUp = (typeof outputConnection.shape.pathUp == 'function') ? outputConnection.shape.pathUp(outputConnection.height) : outputConnection.shape.pathUp; @@ -289,8 +286,8 @@ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() { - for (var i = 0, row; (row = this.info_.rows[i]); i++) { - for (var j = 0, elem; (elem = row.elements[j]); j++) { + for (let i = 0, row; (row = this.info_.rows[i]); i++) { + for (let j = 0, elem; (elem = row.elements[j]); j++) { if (Blockly.blockRendering.Types.isInlineInput(elem)) { this.drawInlineInput_( /** @type {!Blockly.blockRendering.InlineInput} */ (elem)); @@ -311,15 +308,16 @@ Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) { + let svgGroup; if (Blockly.blockRendering.Types.isField(fieldInfo)) { - var svgGroup = fieldInfo.field.getSvgRoot(); + svgGroup = fieldInfo.field.getSvgRoot(); } else if (Blockly.blockRendering.Types.isIcon(fieldInfo)) { - var svgGroup = fieldInfo.icon.iconGroup_; + svgGroup = fieldInfo.icon.iconGroup_; } - var yPos = fieldInfo.centerline - fieldInfo.height / 2; - var xPos = fieldInfo.xPos; - var scale = ''; + const yPos = fieldInfo.centerline - fieldInfo.height / 2; + let xPos = fieldInfo.xPos; + let scale = ''; if (this.info_.RTL) { xPos = -(xPos + fieldInfo.width); if (fieldInfo.flipRtl) { @@ -350,13 +348,13 @@ Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) { * @protected */ Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { - var width = input.width; - var height = input.height; - var yPos = input.centerline - height / 2; + const width = input.width; + const height = input.height; + const yPos = input.centerline - height / 2; - var connectionTop = input.connectionOffsetY; - var connectionBottom = input.connectionHeight + connectionTop; - var connectionRight = input.xPos + input.connectionWidth; + const connectionTop = input.connectionOffsetY; + const connectionBottom = input.connectionHeight + connectionTop; + const connectionRight = input.xPos + input.connectionWidth; this.inlinePath_ += Blockly.utils.svgPaths.moveTo(connectionRight, yPos) + Blockly.utils.svgPaths.lineOnAxis('v', connectionTop) + @@ -377,12 +375,13 @@ Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { * the input that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = function(input) { - var yPos = input.centerline - input.height / 2; +Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = + function(input) { + const yPos = input.centerline - input.height / 2; // Move the connection. if (input.connectionModel) { // xPos already contains info about startX - var connX = input.xPos + input.connectionWidth + input.connectionOffsetX; + let connX = input.xPos + input.connectionWidth + input.connectionOffsetX; if (this.info_.RTL) { connX *= -1; } @@ -398,10 +397,11 @@ Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = functio * @param {!Blockly.blockRendering.Row} row The row that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = function(row) { - var input = row.getLastInput(); +Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = + function(row) { + const input = row.getLastInput(); if (input.connectionModel) { - var connX = row.xPos + row.statementEdge + input.notchOffset; + let connX = row.xPos + row.statementEdge + input.notchOffset; if (this.info_.RTL) { connX *= -1; } @@ -416,10 +416,11 @@ Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = func * @param {!Blockly.blockRendering.Row} row The row that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = function(row) { - var input = row.getLastInput(); +Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = + function(row) { + const input = row.getLastInput(); if (input.connectionModel) { - var connX = row.xPos + row.width; + let connX = row.xPos + row.width; if (this.info_.RTL) { connX *= -1; } @@ -431,11 +432,12 @@ Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = funct * Position the previous connection on a block. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = function() { - var topRow = this.info_.topRow; +Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = + function() { + const topRow = this.info_.topRow; if (topRow.connection) { - var x = topRow.xPos + topRow.notchOffset; - var connX = (this.info_.RTL ? -x : x); + const x = topRow.xPos + topRow.notchOffset; + const connX = (this.info_.RTL ? -x : x); topRow.connection.connectionModel.setOffsetInBlock(connX, 0); } }; @@ -445,12 +447,12 @@ Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = function() * @protected */ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { - var bottomRow = this.info_.bottomRow; + const bottomRow = this.info_.bottomRow; if (bottomRow.connection) { - var connInfo = bottomRow.connection; - var x = connInfo.xPos; // Already contains info about startX. - var connX = (this.info_.RTL ? -x : x); + const connInfo = bottomRow.connection; + const x = connInfo.xPos; // Already contains info about startX. + const connX = (this.info_.RTL ? -x : x); connInfo.connectionModel.setOffsetInBlock(connX, bottomRow.baseline); } }; @@ -461,8 +463,8 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { */ Blockly.blockRendering.Drawer.prototype.positionOutputConnection_ = function() { if (this.info_.outputConnection) { - var x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; - var connX = this.info_.RTL ? -x : x; + const x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; + const connX = this.info_.RTL ? -x : x; this.block_.outputConnection.setOffsetInBlock(connX, this.info_.outputConnection.connectionOffsetY); } From 66c959b4a3e6ca3ad8884303f9a9a4aed85af801 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 14:57:23 -0700 Subject: [PATCH 018/313] Migrate core/block_animations.js to ES6 const/let --- core/block_animations.js | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 82e2516b1..54b776d98 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -38,13 +38,13 @@ Blockly.blockAnimations.disconnectGroup_ = null; * @package */ Blockly.blockAnimations.disposeUiEffect = function(block) { - var workspace = block.workspace; - var svgGroup = block.getSvgRoot(); + const workspace = block.workspace; + const svgGroup = block.getSvgRoot(); workspace.getAudioManager().play('delete'); - var xy = workspace.getSvgXY(svgGroup); + const xy = workspace.getSvgXY(svgGroup); // Deeply clone the current block. - var clone = svgGroup.cloneNode(true); + const clone = svgGroup.cloneNode(true); clone.translateX_ = xy.x; clone.translateY_ = xy.y; clone.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')'); @@ -67,15 +67,15 @@ Blockly.blockAnimations.disposeUiEffect = function(block) { */ Blockly.blockAnimations.disposeUiStep_ = function(clone, rtl, start, workspaceScale) { - var ms = new Date - start; - var percent = ms / 150; + const ms = new Date - start; + const percent = ms / 150; if (percent > 1) { Blockly.utils.dom.removeNode(clone); } else { - var x = clone.translateX_ + + const x = clone.translateX_ + (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; - var y = clone.translateY_ + clone.bBox_.height * workspaceScale * percent; - var scale = (1 - percent) * workspaceScale; + const y = clone.translateY_ + clone.bBox_.height * workspaceScale * percent; + const scale = (1 - percent) * workspaceScale; clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' + ' scale(' + scale + ')'); setTimeout(Blockly.blockAnimations.disposeUiStep_, 10, clone, rtl, start, @@ -89,14 +89,14 @@ Blockly.blockAnimations.disposeUiStep_ = function(clone, rtl, start, * @package */ Blockly.blockAnimations.connectionUiEffect = function(block) { - var workspace = block.workspace; - var scale = workspace.scale; + const workspace = block.workspace; + const scale = workspace.scale; workspace.getAudioManager().play('click'); if (scale < 1) { return; // Too small to care about visual effects. } // Determine the absolute coordinates of the inferior block. - var xy = workspace.getSvgXY(block.getSvgRoot()); + const xy = workspace.getSvgXY(block.getSvgRoot()); // Offset the coordinates based on the two connection types, fix scale. if (block.outputConnection) { xy.x += (block.RTL ? 3 : -3) * scale; @@ -105,7 +105,7 @@ Blockly.blockAnimations.connectionUiEffect = function(block) { xy.x += (block.RTL ? -23 : 23) * scale; xy.y += 3 * scale; } - var ripple = Blockly.utils.dom.createSvgElement( + const ripple = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CIRCLE, { 'cx': xy.x, @@ -128,8 +128,8 @@ Blockly.blockAnimations.connectionUiEffect = function(block) { * @private */ Blockly.blockAnimations.connectionUiStep_ = function(ripple, start, scale) { - var ms = new Date - start; - var percent = ms / 150; + const ms = new Date - start; + const percent = ms / 150; if (percent > 1) { Blockly.utils.dom.removeNode(ripple); } else { @@ -151,10 +151,10 @@ Blockly.blockAnimations.disconnectUiEffect = function(block) { return; // Too small to care about visual effects. } // Horizontal distance for bottom of block to wiggle. - var DISPLACEMENT = 10; + const DISPLACEMENT = 10; // Scale magnitude of skew to height of block. - var height = block.getHeightWidth().height; - var magnitude = Math.atan(DISPLACEMENT / height) / Math.PI * 180; + const height = block.getHeightWidth().height; + let magnitude = Math.atan(DISPLACEMENT / height) / Math.PI * 180; if (!block.RTL) { magnitude *= -1; } @@ -170,16 +170,16 @@ Blockly.blockAnimations.disconnectUiEffect = function(block) { * @private */ Blockly.blockAnimations.disconnectUiStep_ = function(group, magnitude, start) { - var DURATION = 200; // Milliseconds. - var WIGGLES = 3; // Half oscillations. + const DURATION = 200; // Milliseconds. + const WIGGLES = 3; // Half oscillations. - var ms = new Date - start; - var percent = ms / DURATION; + const ms = new Date - start; + const percent = ms / DURATION; if (percent > 1) { group.skew_ = ''; } else { - var skew = Math.round( + const skew = Math.round( Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude); group.skew_ = 'skewX(' + skew + ')'; Blockly.blockAnimations.disconnectGroup_ = group; @@ -197,7 +197,7 @@ Blockly.blockAnimations.disconnectUiStep_ = function(group, magnitude, start) { Blockly.blockAnimations.disconnectUiStop = function() { if (Blockly.blockAnimations.disconnectGroup_) { clearTimeout(Blockly.blockAnimations.disconnectPid_); - var group = Blockly.blockAnimations.disconnectGroup_; + const group = Blockly.blockAnimations.disconnectGroup_; group.skew_ = ''; group.setAttribute('transform', group.translate_); Blockly.blockAnimations.disconnectGroup_ = null; From ab0b03c4725c895e70cf6ecd35616562f5070985 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 15:29:35 -0700 Subject: [PATCH 019/313] Migrate core/block_animations.js to goog.module --- core/block_animations.js | 79 ++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 54b776d98..e6a7cf4f2 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockAnimations'); +goog.module('Blockly.blockAnimations'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); @@ -21,23 +22,20 @@ goog.requireType('Blockly.BlockSvg'); /** * PID of disconnect UI animation. There can only be one at a time. * @type {number} - * @private */ -Blockly.blockAnimations.disconnectPid_ = 0; +let disconnectPid = 0; /** * SVG group of wobbling block. There can only be one at a time. * @type {Element} - * @private */ -Blockly.blockAnimations.disconnectGroup_ = null; +let disconnectGroup = null; /** * Play some UI effects (sound, animation) when disposing of a block. * @param {!Blockly.BlockSvg} block The block being disposed of. - * @package */ -Blockly.blockAnimations.disposeUiEffect = function(block) { +function disposeUiEffect(block) { const workspace = block.workspace; const svgGroup = block.getSvgRoot(); workspace.getAudioManager().play('delete'); @@ -51,9 +49,11 @@ Blockly.blockAnimations.disposeUiEffect = function(block) { workspace.getParentSvg().appendChild(clone); clone.bBox_ = clone.getBBox(); // Start the animation. - Blockly.blockAnimations.disposeUiStep_(clone, workspace.RTL, new Date, + disposeUiStep(clone, workspace.RTL, new Date, workspace.scale); -}; +} +/** @package */ +exports.disposeUiEffect = disposeUiEffect; /** * Animate a cloned block and eventually dispose of it. @@ -63,9 +63,8 @@ Blockly.blockAnimations.disposeUiEffect = function(block) { * @param {boolean} rtl True if RTL, false if LTR. * @param {!Date} start Date of animation's start. * @param {number} workspaceScale Scale of workspace. - * @private */ -Blockly.blockAnimations.disposeUiStep_ = function(clone, rtl, start, +function disposeUiStep(clone, rtl, start, workspaceScale) { const ms = new Date - start; const percent = ms / 150; @@ -78,17 +77,16 @@ Blockly.blockAnimations.disposeUiStep_ = function(clone, rtl, start, const scale = (1 - percent) * workspaceScale; clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' + ' scale(' + scale + ')'); - setTimeout(Blockly.blockAnimations.disposeUiStep_, 10, clone, rtl, start, + setTimeout(disposeUiStep, 10, clone, rtl, start, workspaceScale); } -}; +} /** * Play some UI effects (sound, ripple) after a connection has been established. * @param {!Blockly.BlockSvg} block The block being connected. - * @package */ -Blockly.blockAnimations.connectionUiEffect = function(block) { +function connectionUiEffect(block) { const workspace = block.workspace; const scale = workspace.scale; workspace.getAudioManager().play('click'); @@ -117,17 +115,18 @@ Blockly.blockAnimations.connectionUiEffect = function(block) { }, workspace.getParentSvg()); // Start the animation. - Blockly.blockAnimations.connectionUiStep_(ripple, new Date, scale); -}; + connectionUiStep(ripple, new Date, scale); +} +/** @package */ +exports.connectionUiEffect = connectionUiEffect; /** * Expand a ripple around a connection. * @param {!SVGElement} ripple Element to animate. * @param {!Date} start Date of animation's start. * @param {number} scale Scale of workspace. - * @private */ -Blockly.blockAnimations.connectionUiStep_ = function(ripple, start, scale) { +function connectionUiStep(ripple, start, scale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -135,17 +134,16 @@ Blockly.blockAnimations.connectionUiStep_ = function(ripple, start, scale) { } else { ripple.setAttribute('r', percent * 25 * scale); ripple.style.opacity = 1 - percent; - Blockly.blockAnimations.disconnectPid_ = setTimeout( - Blockly.blockAnimations.connectionUiStep_, 10, ripple, start, scale); + disconnectPid = setTimeout( + connectionUiStep, 10, ripple, start, scale); } -}; +} /** * Play some UI effects (sound, animation) when disconnecting a block. * @param {!Blockly.BlockSvg} block The block being disconnected. - * @package */ -Blockly.blockAnimations.disconnectUiEffect = function(block) { +function disconnectUiEffect(block) { block.workspace.getAudioManager().play('disconnect'); if (block.workspace.scale < 1) { return; // Too small to care about visual effects. @@ -159,17 +157,19 @@ Blockly.blockAnimations.disconnectUiEffect = function(block) { magnitude *= -1; } // Start the animation. - Blockly.blockAnimations.disconnectUiStep_( + disconnectUiStep( block.getSvgRoot(), magnitude, new Date); -}; +} +/** @package */ +exports.disconnectUiEffect = disconnectUiEffect; + /** * Animate a brief wiggle of a disconnected block. * @param {!SVGElement} group SVG element to animate. * @param {number} magnitude Maximum degrees skew (reversed for RTL). * @param {!Date} start Date of animation's start. - * @private */ -Blockly.blockAnimations.disconnectUiStep_ = function(group, magnitude, start) { +function disconnectUiStep(group, magnitude, start) { const DURATION = 200; // Milliseconds. const WIGGLES = 3; // Half oscillations. @@ -182,24 +182,25 @@ Blockly.blockAnimations.disconnectUiStep_ = function(group, magnitude, start) { const skew = Math.round( Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude); group.skew_ = 'skewX(' + skew + ')'; - Blockly.blockAnimations.disconnectGroup_ = group; - Blockly.blockAnimations.disconnectPid_ = - setTimeout(Blockly.blockAnimations.disconnectUiStep_, 10, group, + disconnectGroup = group; + disconnectPid = + setTimeout(disconnectUiStep, 10, group, magnitude, start); } group.setAttribute('transform', group.translate_ + group.skew_); -}; +} /** * Stop the disconnect UI animation immediately. - * @package */ -Blockly.blockAnimations.disconnectUiStop = function() { - if (Blockly.blockAnimations.disconnectGroup_) { - clearTimeout(Blockly.blockAnimations.disconnectPid_); - const group = Blockly.blockAnimations.disconnectGroup_; +function disconnectUiStop() { + if (disconnectGroup) { + clearTimeout(disconnectPid); + const group = disconnectGroup; group.skew_ = ''; group.setAttribute('transform', group.translate_); - Blockly.blockAnimations.disconnectGroup_ = null; + disconnectGroup = null; } -}; +} +/** @package */ +exports.disconnectUiStop = disconnectUiStop; diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..f1a4cd48c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -8,7 +8,7 @@ goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Con goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); -goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); From 5f025f4d03c64fc8af4ea339fde9a7345a8168bf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 15:32:40 -0700 Subject: [PATCH 020/313] Migrate core/block_animations.js to named requires --- core/block_animations.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index e6a7cf4f2..c973bd097 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -13,10 +13,10 @@ goog.module('Blockly.blockAnimations'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); +const Svg = goog.require('Blockly.utils.Svg'); -goog.requireType('Blockly.BlockSvg'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); /** @@ -33,7 +33,7 @@ let disconnectGroup = null; /** * Play some UI effects (sound, animation) when disposing of a block. - * @param {!Blockly.BlockSvg} block The block being disposed of. + * @param {!BlockSvg} block The block being disposed of. */ function disposeUiEffect(block) { const workspace = block.workspace; @@ -69,7 +69,7 @@ function disposeUiStep(clone, rtl, start, const ms = new Date - start; const percent = ms / 150; if (percent > 1) { - Blockly.utils.dom.removeNode(clone); + dom.removeNode(clone); } else { const x = clone.translateX_ + (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; @@ -84,7 +84,7 @@ function disposeUiStep(clone, rtl, start, /** * Play some UI effects (sound, ripple) after a connection has been established. - * @param {!Blockly.BlockSvg} block The block being connected. + * @param {!BlockSvg} block The block being connected. */ function connectionUiEffect(block) { const workspace = block.workspace; @@ -103,8 +103,8 @@ function connectionUiEffect(block) { xy.x += (block.RTL ? -23 : 23) * scale; xy.y += 3 * scale; } - const ripple = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, + const ripple = dom.createSvgElement( + Svg.CIRCLE, { 'cx': xy.x, 'cy': xy.y, @@ -130,7 +130,7 @@ function connectionUiStep(ripple, start, scale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { - Blockly.utils.dom.removeNode(ripple); + dom.removeNode(ripple); } else { ripple.setAttribute('r', percent * 25 * scale); ripple.style.opacity = 1 - percent; @@ -141,7 +141,7 @@ function connectionUiStep(ripple, start, scale) { /** * Play some UI effects (sound, animation) when disconnecting a block. - * @param {!Blockly.BlockSvg} block The block being disconnected. + * @param {!BlockSvg} block The block being disconnected. */ function disconnectUiEffect(block) { block.workspace.getAudioManager().play('disconnect'); From f93ed6086978fef5619970d74889c6ed8b20f844 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 15:33:59 -0700 Subject: [PATCH 021/313] clang-format core/block_animations.js --- core/block_animations.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index c973bd097..86b4b44b5 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -13,11 +13,10 @@ goog.module('Blockly.blockAnimations'); goog.module.declareLegacyNamespace(); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); const dom = goog.require('Blockly.utils.dom'); const Svg = goog.require('Blockly.utils.Svg'); -const BlockSvg = goog.requireType('Blockly.BlockSvg'); - /** * PID of disconnect UI animation. There can only be one at a time. @@ -49,8 +48,7 @@ function disposeUiEffect(block) { workspace.getParentSvg().appendChild(clone); clone.bBox_ = clone.getBBox(); // Start the animation. - disposeUiStep(clone, workspace.RTL, new Date, - workspace.scale); + disposeUiStep(clone, workspace.RTL, new Date, workspace.scale); } /** @package */ exports.disposeUiEffect = disposeUiEffect; @@ -64,8 +62,7 @@ exports.disposeUiEffect = disposeUiEffect; * @param {!Date} start Date of animation's start. * @param {number} workspaceScale Scale of workspace. */ -function disposeUiStep(clone, rtl, start, - workspaceScale) { +function disposeUiStep(clone, rtl, start, workspaceScale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -75,10 +72,11 @@ function disposeUiStep(clone, rtl, start, (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; const y = clone.translateY_ + clone.bBox_.height * workspaceScale * percent; const scale = (1 - percent) * workspaceScale; - clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' + - ' scale(' + scale + ')'); - setTimeout(disposeUiStep, 10, clone, rtl, start, - workspaceScale); + clone.setAttribute( + 'transform', + 'translate(' + x + ',' + y + ')' + + ' scale(' + scale + ')'); + setTimeout(disposeUiStep, 10, clone, rtl, start, workspaceScale); } } @@ -104,8 +102,7 @@ function connectionUiEffect(block) { xy.y += 3 * scale; } const ripple = dom.createSvgElement( - Svg.CIRCLE, - { + Svg.CIRCLE, { 'cx': xy.x, 'cy': xy.y, 'r': 0, @@ -134,8 +131,7 @@ function connectionUiStep(ripple, start, scale) { } else { ripple.setAttribute('r', percent * 25 * scale); ripple.style.opacity = 1 - percent; - disconnectPid = setTimeout( - connectionUiStep, 10, ripple, start, scale); + disconnectPid = setTimeout(connectionUiStep, 10, ripple, start, scale); } } @@ -157,8 +153,7 @@ function disconnectUiEffect(block) { magnitude *= -1; } // Start the animation. - disconnectUiStep( - block.getSvgRoot(), magnitude, new Date); + disconnectUiStep(block.getSvgRoot(), magnitude, new Date); } /** @package */ exports.disconnectUiEffect = disconnectUiEffect; @@ -171,7 +166,7 @@ exports.disconnectUiEffect = disconnectUiEffect; */ function disconnectUiStep(group, magnitude, start) { const DURATION = 200; // Milliseconds. - const WIGGLES = 3; // Half oscillations. + const WIGGLES = 3; // Half oscillations. const ms = new Date - start; const percent = ms / DURATION; @@ -183,9 +178,7 @@ function disconnectUiStep(group, magnitude, start) { Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude); group.skew_ = 'skewX(' + skew + ')'; disconnectGroup = group; - disconnectPid = - setTimeout(disconnectUiStep, 10, group, - magnitude, start); + disconnectPid = setTimeout(disconnectUiStep, 10, group, magnitude, start); } group.setAttribute('transform', group.translate_ + group.skew_); } From 46e00f6ac99f8a82a65fd7d2e6beee124c7d6e3c Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:58:23 -0700 Subject: [PATCH 022/313] Migrate core/block_drag_surface.js to ES6 const/let --- core/block_drag_surface.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index b2a2cda0f..f1db819e8 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -134,8 +134,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. - var fixedX = x.toFixed(0); - var fixedY = y.toFixed(0); + const fixedX = x.toFixed(0); + const fixedY = y.toFixed(0); this.childSurfaceXY_.x = parseInt(fixedX, 10); this.childSurfaceXY_.y = parseInt(fixedY, 10); @@ -150,8 +150,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( * @private */ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { - var x = this.surfaceXY_.x; - var y = this.surfaceXY_.y; + let x = this.surfaceXY_.x; + let y = this.surfaceXY_.y; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. x = x.toFixed(0); @@ -168,8 +168,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { * @param {number} deltaY Vertical offset in pixel units. */ Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { - var x = this.surfaceXY_.x + deltaX; - var y = this.surfaceXY_.y + deltaY; + const x = this.surfaceXY_.x + deltaX; + const y = this.surfaceXY_.y + deltaY; this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); this.translateSurfaceInternal_(); }; @@ -194,7 +194,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { * @return {!Blockly.utils.Coordinate} Current translation of the surface. */ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { - var xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); + const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ + (this.SVG_)); return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); }; From 4689c30634227e2d6da1294ea2475b5be2555d36 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:02:05 -0700 Subject: [PATCH 023/313] Migrate core/block_drag_surface.js to goog.module --- core/block_drag_surface.js | 46 +++++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index f1db819e8..f5bb42aea 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -15,7 +15,9 @@ 'use strict'; -goog.provide('Blockly.BlockDragSurfaceSvg'); +goog.module('Blockly.BlockDragSurfaceSvg'); +goog.module.declareLegacyNamespace(); + goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -28,7 +30,7 @@ goog.require('Blockly.utils.Svg'); * @param {!Element} container Containing element. * @constructor */ -Blockly.BlockDragSurfaceSvg = function(container) { +const BlockDragSurfaceSvg = function(container) { /** * @type {!Element} * @private @@ -38,11 +40,11 @@ Blockly.BlockDragSurfaceSvg = function(container) { }; /** - * The SVG drag surface. Set once by Blockly.BlockDragSurfaceSvg.createDom. + * The SVG drag surface. Set once by BlockDragSurfaceSvg.createDom. * @type {?SVGElement} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null; +BlockDragSurfaceSvg.prototype.SVG_ = null; /** * This is where blocks live while they are being dragged if the drag surface @@ -50,14 +52,14 @@ Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null; * @type {?SVGElement} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.dragGroup_ = null; +BlockDragSurfaceSvg.prototype.dragGroup_ = null; /** * Containing HTML element; parent of the workspace and the drag surface. * @type {?Element} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.container_ = null; +BlockDragSurfaceSvg.prototype.container_ = null; /** * Cached value for the scale of the drag surface. @@ -65,7 +67,7 @@ Blockly.BlockDragSurfaceSvg.prototype.container_ = null; * @type {number} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.scale_ = 1; +BlockDragSurfaceSvg.prototype.scale_ = 1; /** * Cached value for the translation of the drag surface. @@ -74,7 +76,7 @@ Blockly.BlockDragSurfaceSvg.prototype.scale_ = 1; * @type {?Blockly.utils.Coordinate} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.surfaceXY_ = null; +BlockDragSurfaceSvg.prototype.surfaceXY_ = null; /** * Cached value for the translation of the child drag surface in pixel units. @@ -83,13 +85,13 @@ Blockly.BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * @type {!Blockly.utils.Coordinate} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.childSurfaceXY_ = +BlockDragSurfaceSvg.prototype.childSurfaceXY_ = new Blockly.utils.Coordinate(0, 0); /** * Create the drag surface and inject it into the container. */ -Blockly.BlockDragSurfaceSvg.prototype.createDom = function() { +BlockDragSurfaceSvg.prototype.createDom = function() { if (this.SVG_) { return; // Already created. } @@ -112,7 +114,7 @@ Blockly.BlockDragSurfaceSvg.prototype.createDom = function() { * @param {!SVGElement} blocks Block or group of blocks to place on the drag * surface. */ -Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { +BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { if (this.dragGroup_.childNodes.length) { throw Error('Already dragging a block.'); } @@ -129,7 +131,7 @@ Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { * @param {number} y Y translation in pixel coordinates. * @param {number} scale Scale of the group. */ -Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( +BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( x, y, scale) { this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering @@ -149,7 +151,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( * Translate the drag surface's SVG based on its internal state. * @private */ -Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { +BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { let x = this.surfaceXY_.x; let y = this.surfaceXY_.y; // This is a work-around to prevent a the blocks from rendering @@ -167,7 +169,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { * @param {number} deltaX Horizontal offset in pixel units. * @param {number} deltaY Vertical offset in pixel units. */ -Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { +BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { const x = this.surfaceXY_.x + deltaX; const y = this.surfaceXY_.y + deltaY; this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); @@ -182,7 +184,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { * @param {number} x X translation for the entire surface. * @param {number} y Y translation for the entire surface. */ -Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { +BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { this.surfaceXY_ = new Blockly.utils.Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); @@ -193,7 +195,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { * Use this when finishing a drag to return blocks to the correct position. * @return {!Blockly.utils.Coordinate} Current translation of the surface. */ -Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { +BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); @@ -204,7 +206,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { * BlockSvg.getRelativeToSurfaceXY). * @return {?SVGElement} Drag surface group element. */ -Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() { +BlockDragSurfaceSvg.prototype.getGroup = function() { return this.dragGroup_; }; @@ -212,7 +214,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() { * Returns the SVG drag surface. * @returns {?SVGElement} The SVG drag surface. */ -Blockly.BlockDragSurfaceSvg.prototype.getSvgRoot = function() { +BlockDragSurfaceSvg.prototype.getSvgRoot = function() { return this.SVG_; }; @@ -221,7 +223,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getSvgRoot = function() { * for BlockSvg.getRelativeToSurfaceXY). * @return {?Element} Drag surface block DOM element, or null if no blocks exist. */ -Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { +BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { return /** @type {Element} */ (this.dragGroup_.firstChild); }; @@ -231,7 +233,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { * moved. * @return {!Blockly.utils.Coordinate} The amount the workspace has been moved. */ -Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() { +BlockDragSurfaceSvg.prototype.getWsTranslation = function() { // Returning a copy so the coordinate can not be changed outside this class. return this.childSurfaceXY_.clone(); }; @@ -245,7 +247,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() { * to, or null if the blocks should be removed from this surface without * being moved to a different surface. */ -Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { +BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { if (opt_newSurface) { // appendChild removes the node from this.dragGroup_ opt_newSurface.appendChild(this.getCurrentBlock()); @@ -258,3 +260,5 @@ Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { } this.surfaceXY_ = null; }; + +exports = BlockDragSurfaceSvg; diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..2edd38475 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -9,7 +9,7 @@ goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Bl goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); From 18996f3aac825b35a4b79c26c813d32c98017076 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:10:57 -0700 Subject: [PATCH 024/313] Migrate core/block_drag_surface.js named requires --- core/block_drag_surface.js | 43 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index f5bb42aea..7b573fcfd 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -18,10 +18,10 @@ goog.module('Blockly.BlockDragSurfaceSvg'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const {G, SVG} = goog.require('Blockly.utils.Svg'); +const {getRelativeXY} = goog.require('Blockly.utils'); +const {createSvgElement, HTML_NS, setCssTransform, SVG_NS, XLINK_NS} = goog.require('Blockly.utils.dom'); /** @@ -73,7 +73,7 @@ BlockDragSurfaceSvg.prototype.scale_ = 1; * Cached value for the translation of the drag surface. * This translation is in pixel units, because the scale is applied to the * drag group rather than the top-level SVG. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @private */ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; @@ -82,11 +82,11 @@ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * Cached value for the translation of the child drag surface in pixel units. * Since the child drag surface tracks the translation of the workspace this is * ultimately the translation of the workspace. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ BlockDragSurfaceSvg.prototype.childSurfaceXY_ = - new Blockly.utils.Coordinate(0, 0); + new Coordinate(0, 0); /** * Create the drag surface and inject it into the container. @@ -95,17 +95,17 @@ BlockDragSurfaceSvg.prototype.createDom = function() { if (this.SVG_) { return; // Already created. } - this.SVG_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.SVG, { - 'xmlns': Blockly.utils.dom.SVG_NS, - 'xmlns:html': Blockly.utils.dom.HTML_NS, - 'xmlns:xlink': Blockly.utils.dom.XLINK_NS, + this.SVG_ = createSvgElement( + SVG, { + 'xmlns': SVG_NS, + 'xmlns:html': HTML_NS, + 'xmlns:xlink': XLINK_NS, 'version': '1.1', 'class': 'blocklyBlockDragSurface' }, this.container_); this.dragGroup_ = - Blockly.utils.dom.createSvgElement(Blockly.utils.Svg.G, {}, this.SVG_); + createSvgElement(G, {}, this.SVG_); }; /** @@ -121,7 +121,7 @@ BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { // appendChild removes the blocks from the previous parent this.dragGroup_.appendChild(blocks); this.SVG_.style.display = 'block'; - this.surfaceXY_ = new Blockly.utils.Coordinate(0, 0); + this.surfaceXY_ = new Coordinate(0, 0); }; /** @@ -160,7 +160,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { y = y.toFixed(0); this.SVG_.style.display = 'block'; - Blockly.utils.dom.setCssTransform( + setCssTransform( this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); }; @@ -172,7 +172,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { const x = this.surfaceXY_.x + deltaX; const y = this.surfaceXY_.y + deltaY; - this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); + this.surfaceXY_ = new Coordinate(x, y); this.translateSurfaceInternal_(); }; @@ -186,19 +186,18 @@ BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { */ BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { this.surfaceXY_ = - new Blockly.utils.Coordinate(x * this.scale_, y * this.scale_); + new Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); }; /** * Reports the surface translation in scaled workspace coordinates. * Use this when finishing a drag to return blocks to the correct position. - * @return {!Blockly.utils.Coordinate} Current translation of the surface. + * @return {!Coordinate} Current translation of the surface. */ BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { - const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ - (this.SVG_)); - return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); + const xy = getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); + return new Coordinate(xy.x / this.scale_, xy.y / this.scale_); }; /** @@ -231,7 +230,7 @@ BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { * Gets the translation of the child block surface * This surface is in charge of keeping track of how much the workspace has * moved. - * @return {!Blockly.utils.Coordinate} The amount the workspace has been moved. + * @return {!Coordinate} The amount the workspace has been moved. */ BlockDragSurfaceSvg.prototype.getWsTranslation = function() { // Returning a copy so the coordinate can not be changed outside this class. From 5a834a9ec9874a501ff7fe8eb46778668a147c16 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:11:19 -0700 Subject: [PATCH 025/313] clang-format core/block_drag_surface.js --- core/block_drag_surface.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 7b573fcfd..69b7a5ca5 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -85,8 +85,7 @@ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * @type {!Coordinate} * @private */ -BlockDragSurfaceSvg.prototype.childSurfaceXY_ = - new Coordinate(0, 0); +BlockDragSurfaceSvg.prototype.childSurfaceXY_ = new Coordinate(0, 0); /** * Create the drag surface and inject it into the container. @@ -104,8 +103,7 @@ BlockDragSurfaceSvg.prototype.createDom = function() { 'class': 'blocklyBlockDragSurface' }, this.container_); - this.dragGroup_ = - createSvgElement(G, {}, this.SVG_); + this.dragGroup_ = createSvgElement(G, {}, this.SVG_); }; /** @@ -131,8 +129,7 @@ BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { * @param {number} y Y translation in pixel coordinates. * @param {number} scale Scale of the group. */ -BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( - x, y, scale) { +BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function(x, y, scale) { this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. @@ -160,8 +157,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { y = y.toFixed(0); this.SVG_.style.display = 'block'; - setCssTransform( - this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); + setCssTransform(this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); }; /** @@ -185,8 +181,7 @@ BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { * @param {number} y Y translation for the entire surface. */ BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { - this.surfaceXY_ = - new Coordinate(x * this.scale_, y * this.scale_); + this.surfaceXY_ = new Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); }; @@ -220,7 +215,8 @@ BlockDragSurfaceSvg.prototype.getSvgRoot = function() { /** * Get the current blocks on the drag surface, if any (primarily * for BlockSvg.getRelativeToSurfaceXY). - * @return {?Element} Drag surface block DOM element, or null if no blocks exist. + * @return {?Element} Drag surface block DOM element, or null if no blocks + * exist. */ BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { return /** @type {Element} */ (this.dragGroup_.firstChild); From 81b16abb92d4a89e0c40ecce8aa4cb7126e324a8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 16:54:21 -0700 Subject: [PATCH 026/313] Migrate core/utils/metrics.js to goog.module --- core/utils/metrics.js | 49 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/core/utils/metrics.js b/core/utils/metrics.js index 226ef0734..55cadfae9 100644 --- a/core/utils/metrics.js +++ b/core/utils/metrics.js @@ -14,139 +14,142 @@ * @name Blockly.utils.Metrics * @namespace */ -goog.provide('Blockly.utils.Metrics'); +goog.module('Blockly.utils.Metrics'); +goog.module.declareLegacyNamespace(); /** * @record */ -Blockly.utils.Metrics = function() {}; +const Metrics = function() {}; /** * Height of the visible portion of the workspace. * @type {number} */ -Blockly.utils.Metrics.prototype.viewHeight; +Metrics.prototype.viewHeight; /** * Width of the visible portion of the workspace. * @type {number} */ -Blockly.utils.Metrics.prototype.viewWidth; +Metrics.prototype.viewWidth; /** * Height of the content. * @type {number} */ -Blockly.utils.Metrics.prototype.contentHeight; +Metrics.prototype.contentHeight; /** * Width of the content. * @type {number} */ -Blockly.utils.Metrics.prototype.contentWidth; +Metrics.prototype.contentWidth; /** * Height of the scroll area. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollHeight; +Metrics.prototype.scrollHeight; /** * Width of the scroll area. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollWidth; +Metrics.prototype.scrollWidth; /** * Top-edge of the visible portion of the workspace, relative to the workspace * origin. * @type {number} */ -Blockly.utils.Metrics.prototype.viewTop; +Metrics.prototype.viewTop; /** * Left-edge of the visible portion of the workspace, relative to the workspace * origin. * @type {number} */ -Blockly.utils.Metrics.prototype.viewLeft; +Metrics.prototype.viewLeft; /** * Top-edge of the content, relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.contentTop; +Metrics.prototype.contentTop; /** * Left-edge of the content relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.contentLeft; +Metrics.prototype.contentLeft; /** * Top-edge of the scroll area, relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollTop; +Metrics.prototype.scrollTop; /** * Left-edge of the scroll area relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollLeft; +Metrics.prototype.scrollLeft; /** * Top-edge of the visible portion of the workspace, relative to the blocklyDiv. * @type {number} */ -Blockly.utils.Metrics.prototype.absoluteTop; +Metrics.prototype.absoluteTop; /** * Left-edge of the visible portion of the workspace, relative to the * blocklyDiv. * @type {number} */ -Blockly.utils.Metrics.prototype.absoluteLeft; +Metrics.prototype.absoluteLeft; /** * Height of the Blockly div (the view + the toolbox, simple of otherwise). * @type {number} */ -Blockly.utils.Metrics.prototype.svgHeight; +Metrics.prototype.svgHeight; /** * Width of the Blockly div (the view + the toolbox, simple or otherwise). * @type {number} */ -Blockly.utils.Metrics.prototype.svgWidth; +Metrics.prototype.svgWidth; /** * Width of the toolbox, if it exists. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxWidth; +Metrics.prototype.toolboxWidth; /** * Height of the toolbox, if it exists. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxHeight; +Metrics.prototype.toolboxHeight; /** * Top, bottom, left or right. Use TOOLBOX_AT constants to compare. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxPosition; +Metrics.prototype.toolboxPosition; /** * Width of the flyout if it is always open. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.flyoutWidth; +Metrics.prototype.flyoutWidth; /** * Height of the flyout if it is always open. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.flyoutHeight; +Metrics.prototype.flyoutHeight; + +exports = Metrics; diff --git a/tests/deps.js b/tests/deps.js index 2edd38475..d1a516942 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -178,7 +178,7 @@ goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); +goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); From d8c45411300199db80218f4488f4a156a3f81f49 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:16:05 -0700 Subject: [PATCH 027/313] Migrate core/blocks.js to goog.module --- core/blocks.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/blocks.js b/core/blocks.js index 5f0d96b21..fadc62959 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -14,10 +14,13 @@ * A mapping of block type names to block prototype objects. * @name Blockly.Blocks */ -goog.provide('Blockly.Blocks'); +goog.module('Blockly.Blocks'); +goog.module.declareLegacyNamespace(); /** * A mapping of block type names to block prototype objects. * @type {!Object} */ -Blockly.Blocks = Object.create(null); +const Blocks = Object.create(null); + +exports = Blocks; diff --git a/tests/deps.js b/tests/deps.js index d1a516942..89bb3d512 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -13,7 +13,7 @@ goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfac goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], []); +goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); From 99f822665565d72b635bc59292f25d91d5bf9d37 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 15 Jul 2021 18:15:52 -0700 Subject: [PATCH 028/313] Update Blockly.Blocks type annotation --- core/blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/blocks.js b/core/blocks.js index fadc62959..37c2105ce 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -19,7 +19,7 @@ goog.module.declareLegacyNamespace(); /** * A mapping of block type names to block prototype objects. - * @type {!Object} + * @type {!Object} */ const Blocks = Object.create(null); From 4c93a048f25d0313bcd65a4a3bd57a5606cac4a4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:09:43 -0700 Subject: [PATCH 029/313] 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 030/313] 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 94685bd8be3450bb746e232c6a408b4b83978cf5 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 09:52:32 -0700 Subject: [PATCH 031/313] Migrate core/renderers/common/drawer.js to goog.module --- core/renderers/common/drawer.js | 51 ++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 0d3a5bab9..4eca204a3 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockRendering.Drawer'); +goog.module('Blockly.blockRendering.Drawer'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Row'); @@ -32,7 +33,7 @@ goog.requireType('Blockly.BlockSvg'); * @package * @constructor */ -Blockly.blockRendering.Drawer = function(block, info) { +const Drawer = function(block, info) { this.block_ = block; this.info_ = info; this.topLeft_ = block.getRelativeToSurfaceXY(); @@ -57,7 +58,7 @@ Blockly.blockRendering.Drawer = function(block, info) { * required. * @package */ -Blockly.blockRendering.Drawer.prototype.draw = function() { +Drawer.prototype.draw = function() { this.hideHiddenIcons_(); this.drawOutline_(); this.drawInternals_(); @@ -78,7 +79,7 @@ Blockly.blockRendering.Drawer.prototype.draw = function() { * render. Anything that needs to be kept around should be set in this function. * @protected */ -Blockly.blockRendering.Drawer.prototype.recordSizeOnBlock_ = function() { +Drawer.prototype.recordSizeOnBlock_ = function() { // This is used when the block is reporting its size to anyone else. // The dark path adds to the size of the block in both X and Y. this.block_.height = this.info_.height; @@ -89,7 +90,7 @@ Blockly.blockRendering.Drawer.prototype.recordSizeOnBlock_ = function() { * Hide icons that were marked as hidden. * @protected */ -Blockly.blockRendering.Drawer.prototype.hideHiddenIcons_ = function() { +Drawer.prototype.hideHiddenIcons_ = function() { for (let i = 0, iconInfo; (iconInfo = this.info_.hiddenIcons[i]); i++) { iconInfo.icon.iconGroup_.setAttribute('display', 'none'); } @@ -99,7 +100,7 @@ Blockly.blockRendering.Drawer.prototype.hideHiddenIcons_ = function() { * Create the outline of the block. This is a single continuous path. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { +Drawer.prototype.drawOutline_ = function() { this.drawTop_(); for (let r = 1; r < this.info_.rows.length - 1; r++) { const row = this.info_.rows[r]; @@ -123,7 +124,7 @@ Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { * details such as hats and rounded corners. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { +Drawer.prototype.drawTop_ = function() { const topRow = this.info_.topRow; const elements = topRow.elements; @@ -154,7 +155,7 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { * @param {!Blockly.blockRendering.Row} row The row to draw the side of. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) { +Drawer.prototype.drawJaggedEdge_ = function(row) { const remainder = row.height - this.constants_.JAGGED_TEETH.height; this.outlinePath_ += this.constants_.JAGGED_TEETH.path + Blockly.utils.svgPaths.lineOnAxis('v', remainder); @@ -167,7 +168,7 @@ Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) { * belongs to. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { +Drawer.prototype.drawValueInput_ = function(row) { const input = row.getLastInput(); this.positionExternalValueConnection_(row); @@ -188,7 +189,7 @@ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { * belongs to. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) { +Drawer.prototype.drawStatementInput_ = function(row) { const input = row.getLastInput(); // Where to start drawing the notch, which is on the right side in LTR. const x = input.xPos + input.notchOffset + input.shape.width; @@ -216,7 +217,7 @@ Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) { * side of. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawRightSideRow_ = function(row) { +Drawer.prototype.drawRightSideRow_ = function(row) { this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('V', row.yPos + row.height); }; @@ -227,7 +228,7 @@ Blockly.blockRendering.Drawer.prototype.drawRightSideRow_ = function(row) { * for the next connection. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { +Drawer.prototype.drawBottom_ = function() { const bottomRow = this.info_.bottomRow; const elems = bottomRow.elements; this.positionNextConnection_(); @@ -259,7 +260,7 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { * connection * @protected */ -Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { +Drawer.prototype.drawLeft_ = function() { const outputConnection = this.info_.outputConnection; this.positionOutputConnection_(); @@ -285,7 +286,7 @@ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { * not depend on the outer path for placement. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() { +Drawer.prototype.drawInternals_ = function() { for (let i = 0, row; (row = this.info_.rows[i]); i++) { for (let j = 0, elem; (elem = row.elements[j]); j++) { if (Blockly.blockRendering.Types.isInlineInput(elem)) { @@ -307,7 +308,7 @@ Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() { * The rendering information for the field or icon. * @protected */ -Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) { +Drawer.prototype.layoutField_ = function(fieldInfo) { let svgGroup; if (Blockly.blockRendering.Types.isField(fieldInfo)) { svgGroup = fieldInfo.field.getSvgRoot(); @@ -347,7 +348,7 @@ Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) { * input to render. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { +Drawer.prototype.drawInlineInput_ = function(input) { const width = input.width; const height = input.height; const yPos = input.centerline - height / 2; @@ -375,8 +376,7 @@ Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { * the input that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = - function(input) { +Drawer.prototype.positionInlineInputConnection_ = function(input) { const yPos = input.centerline - input.height / 2; // Move the connection. if (input.connectionModel) { @@ -397,8 +397,7 @@ Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = * @param {!Blockly.blockRendering.Row} row The row that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = - function(row) { +Drawer.prototype.positionStatementInputConnection_ = function(row) { const input = row.getLastInput(); if (input.connectionModel) { let connX = row.xPos + row.statementEdge + input.notchOffset; @@ -416,8 +415,7 @@ Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = * @param {!Blockly.blockRendering.Row} row The row that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = - function(row) { +Drawer.prototype.positionExternalValueConnection_ = function(row) { const input = row.getLastInput(); if (input.connectionModel) { let connX = row.xPos + row.width; @@ -432,8 +430,7 @@ Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = * Position the previous connection on a block. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = - function() { +Drawer.prototype.positionPreviousConnection_ = function() { const topRow = this.info_.topRow; if (topRow.connection) { const x = topRow.xPos + topRow.notchOffset; @@ -446,7 +443,7 @@ Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = * Position the next connection on a block. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { +Drawer.prototype.positionNextConnection_ = function() { const bottomRow = this.info_.bottomRow; if (bottomRow.connection) { @@ -461,7 +458,7 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { * Position the output connection on a block. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionOutputConnection_ = function() { +Drawer.prototype.positionOutputConnection_ = function() { if (this.info_.outputConnection) { const x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; const connX = this.info_.RTL ? -x : x; @@ -469,3 +466,5 @@ Blockly.blockRendering.Drawer.prototype.positionOutputConnection_ = function() { this.info_.outputConnection.connectionOffsetY); } }; + +exports = Drawer; diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..7cade6c4e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -116,7 +116,7 @@ goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnec goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); +goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From fef2ccfcc8f7129e6a53dd138638e0eab7a24ee2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:57:43 -0700 Subject: [PATCH 032/313] 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 033/313] 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 6dcc24901c021c903d51191c2348da88a86e35d5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 15:37:05 -0700 Subject: [PATCH 034/313] Migrate core/extensions.js to ES6 const/let --- core/extensions.js | 53 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index 0a2c146ad..4871d4622 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -84,7 +84,7 @@ Blockly.Extensions.registerMixin = function(name, mixinObj) { */ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { - var errorPrefix = 'Error when registering mutator "' + name + '": '; + const errorPrefix = 'Error when registering mutator "' + name + '": '; // Sanity check the mixin object before registering it. Blockly.Extensions.checkHasFunction_( @@ -92,7 +92,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, Blockly.Extensions.checkHasFunction_( errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); - var hasMutatorDialog = + const hasMutatorDialog = Blockly.Extensions.checkMutatorDialog_(mixinObj, errorPrefix); if (opt_helperFn && (typeof opt_helperFn != 'function')) { @@ -138,22 +138,23 @@ Blockly.Extensions.unregister = function(name) { * @throws {Error} if the extension is not found. */ Blockly.Extensions.apply = function(name, block, isMutator) { - var extensionFn = Blockly.Extensions.ALL_[name]; + const extensionFn = Blockly.Extensions.ALL_[name]; if (typeof extensionFn != 'function') { throw Error('Error: Extension "' + name + '" not found.'); } + let mutatorProperties; if (isMutator) { // Fail early if the block already has mutation properties. Blockly.Extensions.checkNoMutatorProperties_(name, block); } else { // Record the old properties so we can make sure they don't change after // applying the extension. - var mutatorProperties = Blockly.Extensions.getMutatorProperties_(block); + mutatorProperties = Blockly.Extensions.getMutatorProperties_(block); } extensionFn.apply(block); if (isMutator) { - var errorPrefix = 'Error after applying mutator "' + name + '": '; + const errorPrefix = 'Error after applying mutator "' + name + '": '; Blockly.Extensions.checkBlockHasMutatorProperties_(errorPrefix, block); } else { if (!Blockly.Extensions.mutatorPropertiesMatch_( @@ -194,7 +195,7 @@ Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func, * @private */ Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) { - var properties = Blockly.Extensions.getMutatorProperties_(block); + const properties = Blockly.Extensions.getMutatorProperties_(block); if (properties.length) { throw Error('Error: tried to apply mutation "' + mutationName + '" to a block that already has mutator functions.' + @@ -215,8 +216,8 @@ Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) { * @private */ Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) { - var hasCompose = object.compose !== undefined; - var hasDecompose = object.decompose !== undefined; + const hasCompose = object.compose !== undefined; + const hasDecompose = object.decompose !== undefined; if (hasCompose && hasDecompose) { if (typeof object.compose != 'function') { @@ -261,7 +262,7 @@ Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, * @private */ Blockly.Extensions.getMutatorProperties_ = function(block) { - var result = []; + const result = []; // List each function explicitly by reference to allow for renaming // during compilation. if (block.domToMutation !== undefined) { @@ -289,11 +290,11 @@ Blockly.Extensions.getMutatorProperties_ = function(block) { * @private */ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { - var newProperties = Blockly.Extensions.getMutatorProperties_(block); + const newProperties = Blockly.Extensions.getMutatorProperties_(block); if (newProperties.length != oldProperties.length) { return false; } - for (var i = 0; i < newProperties.length; i++) { + for (let i = 0; i < newProperties.length; i++) { if (oldProperties[i] != newProperties[i]) { return false; } @@ -323,7 +324,7 @@ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, lookupTable) { // List of block types already validated, to minimize duplicate warnings. - var blockTypesChecked = []; + const blockTypesChecked = []; // Check the tooltip string messages for invalid references. // Wait for load, in case Blockly.Msg is not yet populated. @@ -331,7 +332,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, // document object, in which case skip the validation. if (typeof document == 'object') { // Relies on document.readyState Blockly.utils.runAfterPageLoad(function() { - for (var key in lookupTable) { + for (let key in lookupTable) { // Will print warnings if reference is missing. Blockly.utils.checkMessageReferences(lookupTable[key]); } @@ -342,20 +343,20 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, * The actual extension. * @this {Blockly.Block} */ - var extensionFn = function() { + const extensionFn = function () { if (this.type && blockTypesChecked.indexOf(this.type) == -1) { Blockly.Extensions.checkDropdownOptionsInTable_( this, dropdownName, lookupTable); blockTypesChecked.push(this.type); } - this.setTooltip(function() { - var value = String(this.getFieldValue(dropdownName)); - var tooltip = lookupTable[value]; + this.setTooltip(function () { + const value = String(this.getFieldValue(dropdownName)); + let tooltip = lookupTable[value]; if (tooltip == null) { if (blockTypesChecked.indexOf(this.type) == -1) { // Warn for missing values on generated tooltips. - var warning = 'No tooltip mapping for value ' + value + + let warning = 'No tooltip mapping for value ' + value + ' of field ' + dropdownName; if (this.type != null) { warning += (' of block type ' + this.type); @@ -382,11 +383,11 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName, lookupTable) { // Validate all dropdown options have values. - var dropdown = block.getField(dropdownName); + const dropdown = block.getField(dropdownName); if (!dropdown.isOptionListDynamic()) { - var options = dropdown.getOptions(); - for (var i = 0; i < options.length; ++i) { - var optionKey = options[i][1]; // label, then value + const options = dropdown.getOptions(); + for (let i = 0; i < options.length; ++i) { + const optionKey = options[i][1]; // label, then value if (lookupTable[optionKey] == null) { console.warn('No tooltip mapping for value ' + optionKey + ' of field ' + dropdownName + ' of block type ' + block.type); @@ -421,9 +422,9 @@ Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate, * The actual extension. * @this {Blockly.Block} */ - var extensionFn = function() { - this.setTooltip(function() { - var field = this.getField(fieldName); + const extensionFn = function () { + this.setTooltip(function () { + const field = this.getField(fieldName); return Blockly.utils.replaceMessageReferences(msgTemplate) .replace('%1', field ? field.getText() : ''); }.bind(this)); @@ -442,7 +443,7 @@ Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate, Blockly.Extensions.extensionParentTooltip_ = function() { this.tooltipWhenNotConnected_ = this.tooltip; this.setTooltip(function() { - var parent = this.getParent(); + const parent = this.getParent(); return (parent && parent.getInputsInline() && parent.tooltip) || this.tooltipWhenNotConnected_; }.bind(this)); From fed47362cd7fe77bd1cff3e7a3ddaf1786492ceb Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 15:45:22 -0700 Subject: [PATCH 035/313] Migrate core/extensions.js to goog.module --- core/extensions.js | 81 ++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index 4871d4622..8a287e33a 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -17,7 +17,8 @@ * @name Blockly.Extensions * @namespace */ -goog.provide('Blockly.Extensions'); +goog.module('Blockly.Extensions'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils'); @@ -28,7 +29,7 @@ goog.requireType('Blockly.Block'); * The set of all registered extensions, keyed by extension name/id. * @private */ -Blockly.Extensions.ALL_ = Object.create(null); +const ALL = Object.create(null); /** * Registers a new extension function. Extensions are functions that help @@ -40,17 +41,17 @@ Blockly.Extensions.ALL_ = Object.create(null); * @throws {Error} if the extension name is empty, the extension is already * registered, or extensionFn is not a function. */ -Blockly.Extensions.register = function(name, initFn) { +const register = function(name, initFn) { if ((typeof name != 'string') || (name.trim() == '')) { throw Error('Error: Invalid extension name "' + name + '"'); } - if (Blockly.Extensions.ALL_[name]) { + if (ALL[name]) { throw Error('Error: Extension "' + name + '" is already registered.'); } if (typeof initFn != 'function') { throw Error('Error: Extension "' + name + '" must be a function'); } - Blockly.Extensions.ALL_[name] = initFn; + ALL[name] = initFn; }; /** @@ -60,11 +61,11 @@ Blockly.Extensions.register = function(name, initFn) { * @throws {Error} if the extension name is empty or the extension is already * registered. */ -Blockly.Extensions.registerMixin = function(name, mixinObj) { +const registerMixin = function(name, mixinObj) { if (!mixinObj || typeof mixinObj != 'object') { throw Error('Error: Mixin "' + name + '" must be a object'); } - Blockly.Extensions.register(name, function() { + register(name, function() { this.mixin(mixinObj); }); }; @@ -82,25 +83,25 @@ Blockly.Extensions.registerMixin = function(name, mixinObj) { * flyout of the mutator dialog. * @throws {Error} if the mutation is invalid or can't be applied to the block. */ -Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, +const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { const errorPrefix = 'Error when registering mutator "' + name + '": '; // Sanity check the mixin object before registering it. - Blockly.Extensions.checkHasFunction_( + checkHasFunction( errorPrefix, mixinObj.domToMutation, 'domToMutation'); - Blockly.Extensions.checkHasFunction_( + checkHasFunction( errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); const hasMutatorDialog = - Blockly.Extensions.checkMutatorDialog_(mixinObj, errorPrefix); + checkMutatorDialog(mixinObj, errorPrefix); if (opt_helperFn && (typeof opt_helperFn != 'function')) { throw Error('Extension "' + name + '" is not a function'); } // Sanity checks passed. - Blockly.Extensions.register(name, function() { + register(name, function() { if (hasMutatorDialog) { if (!Blockly.Mutator) { throw Error(errorPrefix + 'Missing require for Blockly.Mutator'); @@ -120,9 +121,9 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, * Unregisters the extension registered with the given name. * @param {string} name The name of the extension to unregister. */ -Blockly.Extensions.unregister = function(name) { - if (Blockly.Extensions.ALL_[name]) { - delete Blockly.Extensions.ALL_[name]; +const unregister = function(name) { + if (ALL[name]) { + delete ALL[name]; } else { console.warn('No extension mapping for name "' + name + '" found to unregister'); @@ -137,27 +138,27 @@ Blockly.Extensions.unregister = function(name) { * @param {boolean} isMutator True if this extension defines a mutator. * @throws {Error} if the extension is not found. */ -Blockly.Extensions.apply = function(name, block, isMutator) { - const extensionFn = Blockly.Extensions.ALL_[name]; +const apply = function(name, block, isMutator) { + const extensionFn = ALL[name]; if (typeof extensionFn != 'function') { throw Error('Error: Extension "' + name + '" not found.'); } let mutatorProperties; if (isMutator) { // Fail early if the block already has mutation properties. - Blockly.Extensions.checkNoMutatorProperties_(name, block); + checkNoMutatorProperties(name, block); } else { // Record the old properties so we can make sure they don't change after // applying the extension. - mutatorProperties = Blockly.Extensions.getMutatorProperties_(block); + mutatorProperties = getMutatorProperties(block); } extensionFn.apply(block); if (isMutator) { const errorPrefix = 'Error after applying mutator "' + name + '": '; - Blockly.Extensions.checkBlockHasMutatorProperties_(errorPrefix, block); + checkBlockHasMutatorProperties(errorPrefix, block); } else { - if (!Blockly.Extensions.mutatorPropertiesMatch_( + if (!mutatorPropertiesMatch( /** @type {!Array} */ (mutatorProperties), block)) { throw Error('Error when applying extension "' + name + '": ' + 'mutation properties changed when applying a non-mutator extension.'); @@ -173,7 +174,7 @@ Blockly.Extensions.apply = function(name, block, isMutator) { * @throws {Error} if the property does not exist or is not a function. * @private */ -Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func, +const checkHasFunction = function(errorPrefix, func, propertyName) { if (!func) { throw Error(errorPrefix + @@ -194,8 +195,8 @@ Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func, * @throws {Error} if any of the properties already exist on the block. * @private */ -Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) { - const properties = Blockly.Extensions.getMutatorProperties_(block); +const checkNoMutatorProperties = function(mutationName, block) { + const properties = getMutatorProperties(block); if (properties.length) { throw Error('Error: tried to apply mutation "' + mutationName + '" to a block that already has mutator functions.' + @@ -215,7 +216,7 @@ Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) { * @throws {Error} if the object has only one of the functions. * @private */ -Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) { +const checkMutatorDialog = function(object, errorPrefix) { const hasCompose = object.compose !== undefined; const hasDecompose = object.decompose !== undefined; @@ -240,7 +241,7 @@ Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) { * @param {!Blockly.Block} block The block to inspect. * @private */ -Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, +const checkBlockHasMutatorProperties = function(errorPrefix, block) { if (typeof block.domToMutation != 'function') { throw Error(errorPrefix + 'Applying a mutator didn\'t add "domToMutation"'); @@ -251,7 +252,7 @@ Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, // A block with a mutator isn't required to have a mutation dialog, but // it should still have both or neither of compose and decompose. - Blockly.Extensions.checkMutatorDialog_(block, errorPrefix); + checkMutatorDialog(block, errorPrefix); }; /** @@ -261,7 +262,7 @@ Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, * should be functions, but may be anything other than undefined. * @private */ -Blockly.Extensions.getMutatorProperties_ = function(block) { +const getMutatorProperties = function(block) { const result = []; // List each function explicitly by reference to allow for renaming // during compilation. @@ -289,8 +290,8 @@ Blockly.Extensions.getMutatorProperties_ = function(block) { * @return {boolean} True if the property lists match. * @private */ -Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { - const newProperties = Blockly.Extensions.getMutatorProperties_(block); +const mutatorPropertiesMatch = function(oldProperties, block) { + const newProperties = getMutatorProperties(block); if (newProperties.length != oldProperties.length) { return false; } @@ -321,7 +322,7 @@ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { * tooltip text. * @return {!Function} The extension function. */ -Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, +const buildTooltipForDropdown = function(dropdownName, lookupTable) { // List of block types already validated, to minimize duplicate warnings. const blockTypesChecked = []; @@ -345,7 +346,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, */ const extensionFn = function () { if (this.type && blockTypesChecked.indexOf(this.type) == -1) { - Blockly.Extensions.checkDropdownOptionsInTable_( + checkDropdownOptionsInTable( this, dropdownName, lookupTable); blockTypesChecked.push(this.type); } @@ -380,7 +381,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, * @param {!Object} lookupTable The string lookup table * @private */ -Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName, +const checkDropdownOptionsInTable = function(block, dropdownName, lookupTable) { // Validate all dropdown options have values. const dropdown = block.getField(dropdownName); @@ -405,7 +406,7 @@ Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName, * @param {string} fieldName The field with the replacement text. * @return {!Function} The extension function. */ -Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate, +const buildTooltipWithFieldText = function(msgTemplate, fieldName) { // Check the tooltip string messages for invalid references. // Wait for load, in case Blockly.Msg is not yet populated. @@ -440,13 +441,15 @@ Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate, * @this {Blockly.Block} * @private */ -Blockly.Extensions.extensionParentTooltip_ = function() { - this.tooltipWhenNotConnected_ = this.tooltip; +const extensionParentTooltip = function() { + this.tooltipWhenNotConnected = this.tooltip; this.setTooltip(function() { const parent = this.getParent(); return (parent && parent.getInputsInline() && parent.tooltip) || - this.tooltipWhenNotConnected_; + this.tooltipWhenNotConnected; }.bind(this)); }; -Blockly.Extensions.register('parent_tooltip_when_inline', - Blockly.Extensions.extensionParentTooltip_); +register('parent_tooltip_when_inline', + extensionParentTooltip); + +exports = {ALL_: ALL, register, registerMixin, registerMutator, unregister, apply, buildTooltipForDropdown, buildTooltipWithFieldText}; diff --git a/tests/deps.js b/tests/deps.js index 89bb3d512..5c46df3f6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -47,7 +47,7 @@ goog.addDependency('../../core/events/ui_events.js', ['Blockly.Events.Ui', 'Bloc goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarBase', 'Blockly.Events.VarCreate', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object']); goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); -goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils']); +goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); From 0bd678fe556db1c68f961abd65a6453ad112b6a1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 15:54:37 -0700 Subject: [PATCH 036/313] Migrate core/extensions.js named requires --- core/extensions.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index 8a287e33a..c382c615c 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -20,9 +20,8 @@ goog.module('Blockly.Extensions'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils'); - -goog.requireType('Blockly.Block'); +const Block = goog.requireType('Blockly.Block'); +const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goog.require('Blockly.utils'); /** @@ -134,7 +133,7 @@ const unregister = function(name) { * Applies an extension method to a block. This should only be called during * block construction. * @param {string} name The name of the extension. - * @param {!Blockly.Block} block The block to apply the named extension to. + * @param {!Block} block The block to apply the named extension to. * @param {boolean} isMutator True if this extension defines a mutator. * @throws {Error} if the extension is not found. */ @@ -191,7 +190,7 @@ const checkHasFunction = function(errorPrefix, func, * extension to a block, to make sure we are not overwriting properties. * @param {string} mutationName The name of the mutation to reference in error * messages. - * @param {!Blockly.Block} block The block to check. + * @param {!Block} block The block to check. * @throws {Error} if any of the properties already exist on the block. * @private */ @@ -238,7 +237,7 @@ const checkMutatorDialog = function(object, errorPrefix) { * Check that a block has required mutator properties. This should be called * after applying a mutation extension. * @param {string} errorPrefix The string to prepend to any error message. - * @param {!Blockly.Block} block The block to inspect. + * @param {!Block} block The block to inspect. * @private */ const checkBlockHasMutatorProperties = function(errorPrefix, @@ -257,7 +256,7 @@ const checkBlockHasMutatorProperties = function(errorPrefix, /** * Get a list of values of mutator properties on the given block. - * @param {!Blockly.Block} block The block to inspect. + * @param {!Block} block The block to inspect. * @return {!Array} A list with all of the defined properties, which * should be functions, but may be anything other than undefined. * @private @@ -286,7 +285,7 @@ const getMutatorProperties = function(block) { * properties. This should be called after applying a non-mutator extension, * to verify that the extension didn't change properties it shouldn't. * @param {!Array} oldProperties The old values to compare to. - * @param {!Blockly.Block} block The block to inspect for new values. + * @param {!Block} block The block to inspect for new values. * @return {boolean} True if the property lists match. * @private */ @@ -332,17 +331,17 @@ const buildTooltipForDropdown = function(dropdownName, // runAfterPageLoad() does not run in a Node.js environment due to lack of // document object, in which case skip the validation. if (typeof document == 'object') { // Relies on document.readyState - Blockly.utils.runAfterPageLoad(function() { + runAfterPageLoad(function() { for (let key in lookupTable) { // Will print warnings if reference is missing. - Blockly.utils.checkMessageReferences(lookupTable[key]); + checkMessageReferences(lookupTable[key]); } }); } /** * The actual extension. - * @this {Blockly.Block} + * @this {Block} */ const extensionFn = function () { if (this.type && blockTypesChecked.indexOf(this.type) == -1) { @@ -365,7 +364,7 @@ const buildTooltipForDropdown = function(dropdownName, console.warn(warning + '.'); } } else { - tooltip = Blockly.utils.replaceMessageReferences(tooltip); + tooltip = replaceMessageReferences(tooltip); } return tooltip; }.bind(this)); @@ -376,7 +375,7 @@ const buildTooltipForDropdown = function(dropdownName, /** * Checks all options keys are present in the provided string lookup table. * Emits console warnings when they are not. - * @param {!Blockly.Block} block The block containing the dropdown + * @param {!Block} block The block containing the dropdown * @param {string} dropdownName The name of the dropdown * @param {!Object} lookupTable The string lookup table * @private @@ -413,20 +412,20 @@ const buildTooltipWithFieldText = function(msgTemplate, // runAfterPageLoad() does not run in a Node.js environment due to lack of // document object, in which case skip the validation. if (typeof document == 'object') { // Relies on document.readyState - Blockly.utils.runAfterPageLoad(function() { + runAfterPageLoad(function() { // Will print warnings if reference is missing. - Blockly.utils.checkMessageReferences(msgTemplate); + checkMessageReferences(msgTemplate); }); } /** * The actual extension. - * @this {Blockly.Block} + * @this {Block} */ const extensionFn = function () { this.setTooltip(function () { const field = this.getField(fieldName); - return Blockly.utils.replaceMessageReferences(msgTemplate) + return replaceMessageReferences(msgTemplate) .replace('%1', field ? field.getText() : ''); }.bind(this)); }; @@ -438,7 +437,7 @@ const buildTooltipWithFieldText = function(msgTemplate, * uses the tooltip text at the time this extension is initialized. This takes * advantage of the fact that all other values from JSON are initialized before * extensions. - * @this {Blockly.Block} + * @this {Block} * @private */ const extensionParentTooltip = function() { From 9ba9627ed164f8719d3ce54e4766c55b28d8b907 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:03:56 -0700 Subject: [PATCH 037/313] clang-format core/extensions.js --- core/extensions.js | 86 ++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index c382c615c..50eb8a70b 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -82,18 +82,14 @@ const registerMixin = function(name, mixinObj) { * flyout of the mutator dialog. * @throws {Error} if the mutation is invalid or can't be applied to the block. */ -const registerMutator = function(name, mixinObj, opt_helperFn, - opt_blockList) { +const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { const errorPrefix = 'Error when registering mutator "' + name + '": '; // Sanity check the mixin object before registering it. - checkHasFunction( - errorPrefix, mixinObj.domToMutation, 'domToMutation'); - checkHasFunction( - errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); + checkHasFunction(errorPrefix, mixinObj.domToMutation, 'domToMutation'); + checkHasFunction(errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); - const hasMutatorDialog = - checkMutatorDialog(mixinObj, errorPrefix); + const hasMutatorDialog = checkMutatorDialog(mixinObj, errorPrefix); if (opt_helperFn && (typeof opt_helperFn != 'function')) { throw Error('Extension "' + name + '" is not a function'); @@ -124,8 +120,8 @@ const unregister = function(name) { if (ALL[name]) { delete ALL[name]; } else { - console.warn('No extension mapping for name "' + name + - '" found to unregister'); + console.warn( + 'No extension mapping for name "' + name + '" found to unregister'); } }; @@ -158,8 +154,9 @@ const apply = function(name, block, isMutator) { checkBlockHasMutatorProperties(errorPrefix, block); } else { if (!mutatorPropertiesMatch( - /** @type {!Array} */ (mutatorProperties), block)) { - throw Error('Error when applying extension "' + name + '": ' + + /** @type {!Array} */ (mutatorProperties), block)) { + throw Error( + 'Error when applying extension "' + name + '": ' + 'mutation properties changed when applying a non-mutator extension.'); } } @@ -173,14 +170,14 @@ const apply = function(name, block, isMutator) { * @throws {Error} if the property does not exist or is not a function. * @private */ -const checkHasFunction = function(errorPrefix, func, - propertyName) { +const checkHasFunction = function(errorPrefix, func, propertyName) { if (!func) { - throw Error(errorPrefix + - 'missing required property "' + propertyName + '"'); + throw Error( + errorPrefix + 'missing required property "' + propertyName + '"'); } else if (typeof func != 'function') { - throw Error(errorPrefix + - '" required property "' + propertyName + '" must be a function'); + throw Error( + errorPrefix + '" required property "' + propertyName + + '" must be a function'); } }; @@ -197,7 +194,8 @@ const checkHasFunction = function(errorPrefix, func, const checkNoMutatorProperties = function(mutationName, block) { const properties = getMutatorProperties(block); if (properties.length) { - throw Error('Error: tried to apply mutation "' + mutationName + + throw Error( + 'Error: tried to apply mutation "' + mutationName + '" to a block that already has mutator functions.' + ' Block id: ' + block.id); } @@ -229,8 +227,8 @@ const checkMutatorDialog = function(object, errorPrefix) { } else if (!hasCompose && !hasDecompose) { return false; } - throw Error(errorPrefix + - 'Must have both or neither of "compose" and "decompose"'); + throw Error( + errorPrefix + 'Must have both or neither of "compose" and "decompose"'); }; /** @@ -240,8 +238,7 @@ const checkMutatorDialog = function(object, errorPrefix) { * @param {!Block} block The block to inspect. * @private */ -const checkBlockHasMutatorProperties = function(errorPrefix, - block) { +const checkBlockHasMutatorProperties = function(errorPrefix, block) { if (typeof block.domToMutation != 'function') { throw Error(errorPrefix + 'Applying a mutator didn\'t add "domToMutation"'); } @@ -321,8 +318,7 @@ const mutatorPropertiesMatch = function(oldProperties, block) { * tooltip text. * @return {!Function} The extension function. */ -const buildTooltipForDropdown = function(dropdownName, - lookupTable) { +const buildTooltipForDropdown = function(dropdownName, lookupTable) { // List of block types already validated, to minimize duplicate warnings. const blockTypesChecked = []; @@ -343,21 +339,20 @@ const buildTooltipForDropdown = function(dropdownName, * The actual extension. * @this {Block} */ - const extensionFn = function () { + const extensionFn = function() { if (this.type && blockTypesChecked.indexOf(this.type) == -1) { - checkDropdownOptionsInTable( - this, dropdownName, lookupTable); + checkDropdownOptionsInTable(this, dropdownName, lookupTable); blockTypesChecked.push(this.type); } - this.setTooltip(function () { + this.setTooltip(function() { const value = String(this.getFieldValue(dropdownName)); let tooltip = lookupTable[value]; if (tooltip == null) { if (blockTypesChecked.indexOf(this.type) == -1) { // Warn for missing values on generated tooltips. - let warning = 'No tooltip mapping for value ' + value + - ' of field ' + dropdownName; + let warning = 'No tooltip mapping for value ' + value + ' of field ' + + dropdownName; if (this.type != null) { warning += (' of block type ' + this.type); } @@ -380,8 +375,7 @@ const buildTooltipForDropdown = function(dropdownName, * @param {!Object} lookupTable The string lookup table * @private */ -const checkDropdownOptionsInTable = function(block, dropdownName, - lookupTable) { +const checkDropdownOptionsInTable = function(block, dropdownName, lookupTable) { // Validate all dropdown options have values. const dropdown = block.getField(dropdownName); if (!dropdown.isOptionListDynamic()) { @@ -389,8 +383,9 @@ const checkDropdownOptionsInTable = function(block, dropdownName, for (let i = 0; i < options.length; ++i) { const optionKey = options[i][1]; // label, then value if (lookupTable[optionKey] == null) { - console.warn('No tooltip mapping for value ' + optionKey + - ' of field ' + dropdownName + ' of block type ' + block.type); + console.warn( + 'No tooltip mapping for value ' + optionKey + ' of field ' + + dropdownName + ' of block type ' + block.type); } } } @@ -405,8 +400,7 @@ const checkDropdownOptionsInTable = function(block, dropdownName, * @param {string} fieldName The field with the replacement text. * @return {!Function} The extension function. */ -const buildTooltipWithFieldText = function(msgTemplate, - fieldName) { +const buildTooltipWithFieldText = function(msgTemplate, fieldName) { // Check the tooltip string messages for invalid references. // Wait for load, in case Blockly.Msg is not yet populated. // runAfterPageLoad() does not run in a Node.js environment due to lack of @@ -422,8 +416,8 @@ const buildTooltipWithFieldText = function(msgTemplate, * The actual extension. * @this {Block} */ - const extensionFn = function () { - this.setTooltip(function () { + const extensionFn = function() { + this.setTooltip(function() { const field = this.getField(fieldName); return replaceMessageReferences(msgTemplate) .replace('%1', field ? field.getText() : ''); @@ -448,7 +442,15 @@ const extensionParentTooltip = function() { this.tooltipWhenNotConnected; }.bind(this)); }; -register('parent_tooltip_when_inline', - extensionParentTooltip); +register('parent_tooltip_when_inline', extensionParentTooltip); -exports = {ALL_: ALL, register, registerMixin, registerMutator, unregister, apply, buildTooltipForDropdown, buildTooltipWithFieldText}; +exports = { + ALL_: ALL, + register, + registerMixin, + registerMutator, + unregister, + apply, + buildTooltipForDropdown, + buildTooltipWithFieldText +}; From fa9a175296d40c8db1e9d4e4fd7b2300321b57cc Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 15 Jul 2021 12:30:09 -0700 Subject: [PATCH 038/313] Update name of private property --- core/extensions.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index 50eb8a70b..c73737c43 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -28,7 +28,7 @@ const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goo * The set of all registered extensions, keyed by extension name/id. * @private */ -const ALL = Object.create(null); +const allExtensions = Object.create(null); /** * Registers a new extension function. Extensions are functions that help @@ -44,13 +44,13 @@ const register = function(name, initFn) { if ((typeof name != 'string') || (name.trim() == '')) { throw Error('Error: Invalid extension name "' + name + '"'); } - if (ALL[name]) { + if (allExtensions[name]) { throw Error('Error: Extension "' + name + '" is already registered.'); } if (typeof initFn != 'function') { throw Error('Error: Extension "' + name + '" must be a function'); } - ALL[name] = initFn; + allExtensions[name] = initFn; }; /** @@ -117,8 +117,8 @@ const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { * @param {string} name The name of the extension to unregister. */ const unregister = function(name) { - if (ALL[name]) { - delete ALL[name]; + if (allExtensions[name]) { + delete allExtensions[name]; } else { console.warn( 'No extension mapping for name "' + name + '" found to unregister'); @@ -134,7 +134,7 @@ const unregister = function(name) { * @throws {Error} if the extension is not found. */ const apply = function(name, block, isMutator) { - const extensionFn = ALL[name]; + const extensionFn = allExtensions[name]; if (typeof extensionFn != 'function') { throw Error('Error: Extension "' + name + '" not found.'); } @@ -445,7 +445,7 @@ const extensionParentTooltip = function() { register('parent_tooltip_when_inline', extensionParentTooltip); exports = { - ALL_: ALL, + ALL_: allExtensions, register, registerMixin, registerMutator, From 80d953d5b964eb45576854ff5a80e93dc18a93b9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:29:55 -0700 Subject: [PATCH 039/313] Migrate core/css.js to ES6 const/let --- core/css.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/css.js b/core/css.js index 9f6037d7b..a72088a7f 100644 --- a/core/css.js +++ b/core/css.js @@ -55,19 +55,19 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { return; } Blockly.Css.injected_ = true; - var text = Blockly.Css.CONTENT.join('\n'); + let text = Blockly.Css.CONTENT.join('\n'); Blockly.Css.CONTENT.length = 0; // Garbage collect CSS content. if (!hasCss) { return; } // Strip off any trailing slash (either Unix or Windows). - var mediaPath = pathToMedia.replace(/[\\/]$/, ''); + const mediaPath = pathToMedia.replace(/[\\/]$/, ''); text = text.replace(/<<>>/g, mediaPath); // Inject CSS tag at start of head. - var cssNode = document.createElement('style'); + const cssNode = document.createElement('style'); cssNode.id = 'blockly-common-style'; - var cssTextNode = document.createTextNode(text); + const cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); document.head.insertBefore(cssNode, document.head.firstChild); }; From 902112be3d88493261435b2c786b274d261fcccb Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 10:00:56 -0700 Subject: [PATCH 040/313] Use ES6 template strings in core/css.js --- core/css.js | 766 ++++++++++++++++++++++++++-------------------------- 1 file changed, 384 insertions(+), 382 deletions(-) diff --git a/core/css.js b/core/css.js index a72088a7f..b63c7ed8e 100644 --- a/core/css.js +++ b/core/css.js @@ -76,477 +76,479 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { * Array making up the CSS content for Blockly. */ Blockly.Css.CONTENT = [ - /* eslint-disable indent */ - '.blocklySvg {', - 'background-color: #fff;', - 'outline: none;', - 'overflow: hidden;', /* IE overflows by default. */ - 'position: absolute;', - 'display: block;', - '}', +`.blocklySvg { + background-color: #fff; + outline: none; + overflow: hidden; /* IE overflows by default. */ + position: absolute; + display: block; +}`, - '.blocklyWidgetDiv {', - 'display: none;', - 'position: absolute;', - 'z-index: 99999;', /* big value for bootstrap3 compatibility */ - '}', +`.blocklyWidgetDiv { + display: none; + position: absolute; + z-index: 99999; /* big value for bootstrap3 compatibility */ +}`, - '.injectionDiv {', - 'height: 100%;', - 'position: relative;', - 'overflow: hidden;', /* So blocks in drag surface disappear at edges */ - 'touch-action: none;', - '}', +`.injectionDiv { + height: 100%; + position: relative; + overflow: hidden; /* So blocks in drag surface disappear at edges */ + touch-action: none; +}`, - '.blocklyNonSelectable {', - 'user-select: none;', - '-ms-user-select: none;', - '-webkit-user-select: none;', - '}', +`.blocklyNonSelectable { + user-select: none; + -ms-user-select: none; + -webkit-user-select: none; +}`, + +`.blocklyWsDragSurface { + display: none; + position: absolute; + top: 0; + left: 0; +}`, - '.blocklyWsDragSurface {', - 'display: none;', - 'position: absolute;', - 'top: 0;', - 'left: 0;', - '}', /* Added as a separate rule with multiple classes to make it more specific than a bootstrap rule that selects svg:root. See issue #1275 for context. */ - '.blocklyWsDragSurface.blocklyOverflowVisible {', - 'overflow: visible;', - '}', +`.blocklyWsDragSurface.blocklyOverflowVisible { + overflow: visible; +}`, - '.blocklyBlockDragSurface {', - 'display: none;', - 'position: absolute;', - 'top: 0;', - 'left: 0;', - 'right: 0;', - 'bottom: 0;', - 'overflow: visible !important;', - 'z-index: 50;', /* Display below toolbox, but above everything else. */ - '}', +`.blocklyBlockDragSurface { + display: none; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + overflow: visible !important; + z-index: 50;', /* Display below toolbox, but above everything else. */ +}`, - '.blocklyBlockCanvas.blocklyCanvasTransitioning,', - '.blocklyBubbleCanvas.blocklyCanvasTransitioning {', - 'transition: transform .5s;', - '}', +`.blocklyBlockCanvas.blocklyCanvasTransitioning, +.blocklyBubbleCanvas.blocklyCanvasTransitioning { + transition: transform .5s; +}`, - '.blocklyTooltipDiv {', - 'background-color: #ffffc7;', - 'border: 1px solid #ddc;', - 'box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15);', - 'color: #000;', - 'display: none;', - 'font: 9pt sans-serif;', - 'opacity: .9;', - 'padding: 2px;', - 'position: absolute;', - 'z-index: 100000;', /* big value for bootstrap3 compatibility */ - '}', +`.blocklyTooltipDiv { + background-color: #ffffc7; + border: 1px solid #ddc; + box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15); + color: #000; + display: none; + font: 9pt sans-serif; + opacity: .9; + padding: 2px; + position: absolute; + z-index: 100000;', /* big value for bootstrap3 compatibility */ +}`, - '.blocklyDropDownDiv {', - 'position: absolute;', - 'left: 0;', - 'top: 0;', - 'z-index: 1000;', - 'display: none;', - 'border: 1px solid;', - 'border-color: #dadce0;', - 'background-color: #fff;', - 'border-radius: 2px;', - 'padding: 4px;', - 'box-shadow: 0 0 3px 1px rgba(0,0,0,.3);', - '}', +`.blocklyDropDownDiv { + position: absolute; + left: 0; + top: 0; + z-index: 1000; + display: none; + border: 1px solid; + border-color: #dadce0; + background-color: #fff; + border-radius: 2px; + padding: 4px; + box-shadow: 0 0 3px 1px rgba(0,0,0,.3); +}`, - '.blocklyDropDownDiv.blocklyFocused {', - 'box-shadow: 0 0 6px 1px rgba(0,0,0,.3);', - '}', +`.blocklyDropDownDiv.blocklyFocused { + box-shadow: 0 0 6px 1px rgba(0,0,0,.3); +}`, - '.blocklyDropDownContent {', - 'max-height: 300px;', // @todo: spec for maximum height. - 'overflow: auto;', - 'overflow-x: hidden;', - 'position: relative;', - '}', +`.blocklyDropDownContent { + max-height: 300px;', // @todo: spec for maximum height. + overflow: auto; + overflow-x: hidden; + position: relative; +}`, - '.blocklyDropDownArrow {', - 'position: absolute;', - 'left: 0;', - 'top: 0;', - 'width: 16px;', - 'height: 16px;', - 'z-index: -1;', - 'background-color: inherit;', - 'border-color: inherit;', - '}', +`.blocklyDropDownArrow { + position: absolute; + left: 0; + top: 0; + width: 16px; + height: 16px; + z-index: -1; + background-color: inherit; + border-color: inherit; +}`, - '.blocklyDropDownButton {', - 'display: inline-block;', - 'float: left;', - 'padding: 0;', - 'margin: 4px;', - 'border-radius: 4px;', - 'outline: none;', - 'border: 1px solid;', - 'transition: box-shadow .1s;', - 'cursor: pointer;', - '}', +`.blocklyDropDownButton { + display: inline-block; + float: left; + padding: 0; + margin: 4px; + border-radius: 4px; + outline: none; + border: 1px solid; + transition: box-shadow .1s; + cursor: pointer; +}`, - '.blocklyArrowTop {', - 'border-top: 1px solid;', - 'border-left: 1px solid;', - 'border-top-left-radius: 4px;', - 'border-color: inherit;', - '}', +`.blocklyArrowTop { + border-top: 1px solid; + border-left: 1px solid; + border-top-left-radius: 4px; + border-color: inherit; +}`, - '.blocklyArrowBottom {', - 'border-bottom: 1px solid;', - 'border-right: 1px solid;', - 'border-bottom-right-radius: 4px;', - 'border-color: inherit;', - '}', +`.blocklyArrowBottom { + border-bottom: 1px solid; + border-right: 1px solid; + border-bottom-right-radius: 4px; + border-color: inherit; +}`, - '.blocklyResizeSE {', - 'cursor: se-resize;', - 'fill: #aaa;', - '}', +`.blocklyResizeSE { + cursor: se-resize; + fill: #aaa; +}`, - '.blocklyResizeSW {', - 'cursor: sw-resize;', - 'fill: #aaa;', - '}', +`.blocklyResizeSW { + cursor: sw-resize; + fill: #aaa; +}`, - '.blocklyResizeLine {', - 'stroke: #515A5A;', - 'stroke-width: 1;', - '}', +`.blocklyResizeLine { + stroke: #515A5A; + stroke-width: 1; +}`, - '.blocklyHighlightedConnectionPath {', - 'fill: none;', - 'stroke: #fc3;', - 'stroke-width: 4px;', - '}', +`.blocklyHighlightedConnectionPath { + fill: none; + stroke: #fc3; + stroke-width: 4px; +}`, - '.blocklyPathLight {', - 'fill: none;', - 'stroke-linecap: round;', - 'stroke-width: 1;', - '}', +`.blocklyPathLight { + fill: none; + stroke-linecap: round; + stroke-width: 1; +}`, - '.blocklySelected>.blocklyPathLight {', - 'display: none;', - '}', +`.blocklySelected>.blocklyPathLight { + display: none; +}`, - '.blocklyDraggable {', - /* backup for browsers (e.g. IE11) that don't support grab */ - 'cursor: url("<<>>/handopen.cur"), auto;', - 'cursor: grab;', - 'cursor: -webkit-grab;', - '}', +`.blocklyDraggable { + /* backup for browsers (e.g. IE11) that don't support grab */ + cursor: url("<<>>/handopen.cur"), auto; + cursor: grab; + cursor: -webkit-grab; +}`, + + /* backup for browsers (e.g. IE11) that don't support grabbing */ +`.blocklyDragging { + /* backup for browsers (e.g. IE11) that don't support grabbing */ + cursor: url("<<>>/handclosed.cur"), auto; + cursor: grabbing; + cursor: -webkit-grabbing; +}`, - '.blocklyDragging {', - /* backup for browsers (e.g. IE11) that don't support grabbing */ - 'cursor: url("<<>>/handclosed.cur"), auto;', - 'cursor: grabbing;', - 'cursor: -webkit-grabbing;', - '}', /* Changes cursor on mouse down. Not effective in Firefox because of - https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */ - '.blocklyDraggable:active {', - /* backup for browsers (e.g. IE11) that don't support grabbing */ - 'cursor: url("<<>>/handclosed.cur"), auto;', - 'cursor: grabbing;', - 'cursor: -webkit-grabbing;', - '}', + https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */ +`.blocklyDraggable:active { + /* backup for browsers (e.g. IE11) that don't support grabbing */ + cursor: url("<<>>/handclosed.cur"), auto; + cursor: grabbing; + cursor: -webkit-grabbing; +}`, + /* Change the cursor on the whole drag surface in case the mouse gets ahead of block during a drag. This way the cursor is still a closed hand. */ - '.blocklyBlockDragSurface .blocklyDraggable {', - /* backup for browsers (e.g. IE11) that don't support grabbing */ - 'cursor: url("<<>>/handclosed.cur"), auto;', - 'cursor: grabbing;', - 'cursor: -webkit-grabbing;', - '}', +`.blocklyBlockDragSurface .blocklyDraggable { + /* backup for browsers (e.g. IE11) that don't support grabbing */ + cursor: url("<<>>/handclosed.cur"), auto; + cursor: grabbing; + cursor: -webkit-grabbing; +}`, - '.blocklyDragging.blocklyDraggingDelete {', - 'cursor: url("<<>>/handdelete.cur"), auto;', - '}', +`.blocklyDragging.blocklyDraggingDelete { + cursor: url("<<>>/handdelete.cur"), auto; +}`, - '.blocklyDragging>.blocklyPath,', - '.blocklyDragging>.blocklyPathLight {', - 'fill-opacity: .8;', - 'stroke-opacity: .8;', - '}', +`.blocklyDragging>.blocklyPath, +.blocklyDragging>.blocklyPathLight { + fill-opacity: .8; + stroke-opacity: .8; +}`, - '.blocklyDragging>.blocklyPathDark {', - 'display: none;', - '}', +`.blocklyDragging>.blocklyPathDark { + display: none; +}`, - '.blocklyDisabled>.blocklyPath {', - 'fill-opacity: .5;', - 'stroke-opacity: .5;', - '}', +`.blocklyDisabled>.blocklyPath { + fill-opacity: .5; + stroke-opacity: .5; +}`, - '.blocklyDisabled>.blocklyPathLight,', - '.blocklyDisabled>.blocklyPathDark {', - 'display: none;', - '}', +`.blocklyDisabled>.blocklyPathLight, +.blocklyDisabled>.blocklyPathDark { + display: none; +}`, - '.blocklyInsertionMarker>.blocklyPath,', - '.blocklyInsertionMarker>.blocklyPathLight,', - '.blocklyInsertionMarker>.blocklyPathDark {', - 'fill-opacity: .2;', - 'stroke: none;', - '}', +`.blocklyInsertionMarker>.blocklyPath, +.blocklyInsertionMarker>.blocklyPathLight, +.blocklyInsertionMarker>.blocklyPathDark { + fill-opacity: .2; + stroke: none; +}`, - '.blocklyMultilineText {', - 'font-family: monospace;', - '}', +`.blocklyMultilineText { + font-family: monospace; +}`, - '.blocklyNonEditableText>text {', - 'pointer-events: none;', - '}', +`.blocklyNonEditableText>text { + pointer-events: none; +}`, - '.blocklyFlyout {', - 'position: absolute;', - 'z-index: 20;', - '}', +`.blocklyFlyout { + position: absolute; + z-index: 20; +}`, - '.blocklyText text {', - 'cursor: default;', - '}', +`.blocklyText text { + cursor: default; +}`, /* Don't allow users to select text. It gets annoying when trying to drag a block and selected text moves instead. */ - '.blocklySvg text,', - '.blocklyBlockDragSurface text {', - 'user-select: none;', - '-ms-user-select: none;', - '-webkit-user-select: none;', - 'cursor: inherit;', - '}', +`.blocklySvg text, +.blocklyBlockDragSurface text { + user-select: none; + -ms-user-select: none; + -webkit-user-select: none; + cursor: inherit; +}`, - '.blocklyHidden {', - 'display: none;', - '}', +`.blocklyHidden { + display: none; +}`, - '.blocklyFieldDropdown:not(.blocklyHidden) {', - 'display: block;', - '}', +`.blocklyFieldDropdown:not(.blocklyHidden) { + display: block; +}`, - '.blocklyIconGroup {', - 'cursor: default;', - '}', +`.blocklyIconGroup { + cursor: default; +}`, - '.blocklyIconGroup:not(:hover),', - '.blocklyIconGroupReadonly {', - 'opacity: .6;', - '}', +`.blocklyIconGroup:not(:hover), +.blocklyIconGroupReadonly { + opacity: .6; +}`, - '.blocklyIconShape {', - 'fill: #00f;', - 'stroke: #fff;', - 'stroke-width: 1px;', - '}', +`.blocklyIconShape { + fill: #00f; + stroke: #fff; + stroke-width: 1px; +}`, - '.blocklyIconSymbol {', - 'fill: #fff;', - '}', +`.blocklyIconSymbol { + fill: #fff; +}`, - '.blocklyMinimalBody {', - 'margin: 0;', - 'padding: 0;', - '}', +`.blocklyMinimalBody { + margin: 0; + padding: 0; +}`, - '.blocklyHtmlInput {', - 'border: none;', - 'border-radius: 4px;', - 'height: 100%;', - 'margin: 0;', - 'outline: none;', - 'padding: 0;', - 'width: 100%;', - 'text-align: center;', - 'display: block;', - 'box-sizing: border-box;', - '}', +`.blocklyHtmlInput { + border: none; + border-radius: 4px; + height: 100%; + margin: 0; + outline: none; + padding: 0; + width: 100%; + text-align: center; + display: block; + box-sizing: border-box; +}`, /* Edge and IE introduce a close icon when the input value is longer than a certain length. This affects our sizing calculations of the text input. Hiding the close icon to avoid that. */ - '.blocklyHtmlInput::-ms-clear {', - 'display: none;', - '}', +`.blocklyHtmlInput::-ms-clear { + display: none; +}`, - '.blocklyMainBackground {', - 'stroke-width: 1;', - 'stroke: #c6c6c6;', /* Equates to #ddd due to border being off-pixel. */ - '}', +`.blocklyMainBackground { + stroke-width: 1; + stroke: #c6c6c6;', /* Equates to #ddd due to border being off-pixel. */ +}`, - '.blocklyMutatorBackground {', - 'fill: #fff;', - 'stroke: #ddd;', - 'stroke-width: 1;', - '}', +`.blocklyMutatorBackground { + fill: #fff; + stroke: #ddd; + stroke-width: 1; +}`, - '.blocklyFlyoutBackground {', - 'fill: #ddd;', - 'fill-opacity: .8;', - '}', +`.blocklyFlyoutBackground { + fill: #ddd; + fill-opacity: .8; +}`, - '.blocklyMainWorkspaceScrollbar {', - 'z-index: 20;', - '}', +`.blocklyMainWorkspaceScrollbar { + z-index: 20; +}`, - '.blocklyFlyoutScrollbar {', - 'z-index: 30;', - '}', +`.blocklyFlyoutScrollbar { + z-index: 30; +}`, - '.blocklyScrollbarHorizontal,', - '.blocklyScrollbarVertical {', - 'position: absolute;', - 'outline: none;', - '}', +`.blocklyScrollbarHorizontal, +.blocklyScrollbarVertical { + position: absolute; + outline: none; +}`, - '.blocklyScrollbarBackground {', - 'opacity: 0;', - '}', +`.blocklyScrollbarBackground { + opacity: 0; +}`, - '.blocklyScrollbarHandle {', - 'fill: #ccc;', - '}', +`.blocklyScrollbarHandle { + fill: #ccc; +}`, - '.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,', - '.blocklyScrollbarHandle:hover {', - 'fill: #bbb;', - '}', +`.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, +.blocklyScrollbarHandle:hover { + fill: #bbb; +}`, /* Darken flyout scrollbars due to being on a grey background. */ /* By contrast, workspace scrollbars are on a white background. */ - '.blocklyFlyout .blocklyScrollbarHandle {', - 'fill: #bbb;', - '}', +`.blocklyFlyout .blocklyScrollbarHandle { + fill: #bbb; +}`, - '.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,', - '.blocklyFlyout .blocklyScrollbarHandle:hover {', - 'fill: #aaa;', - '}', +`.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, +.blocklyFlyout .blocklyScrollbarHandle:hover { + fill: #aaa; +}`, - '.blocklyInvalidInput {', - 'background: #faa;', - '}', +`.blocklyInvalidInput { + background: #faa; +}`, - '.blocklyVerticalMarker {', - 'stroke-width: 3px;', - 'fill: rgba(255,255,255,.5);', - 'pointer-events: none;', - '}', +`.blocklyVerticalMarker { + stroke-width: 3px; + fill: rgba(255,255,255,.5); + pointer-events: none; +}`, - '.blocklyComputeCanvas {', - 'position: absolute;', - 'width: 0;', - 'height: 0;', - '}', +`.blocklyComputeCanvas { + position: absolute; + width: 0; + height: 0; +}`, - '.blocklyNoPointerEvents {', - 'pointer-events: none;', - '}', +`.blocklyNoPointerEvents { + pointer-events: none; +}`, - '.blocklyContextMenu {', - 'border-radius: 4px;', - 'max-height: 100%;', - '}', +`.blocklyContextMenu { + border-radius: 4px; + max-height: 100%; +}`, - '.blocklyDropdownMenu {', - 'border-radius: 2px;', - 'padding: 0 !important;', - '}', +`.blocklyDropdownMenu { + border-radius: 2px; + padding: 0 !important; +}`, - '.blocklyDropdownMenu .blocklyMenuItem {', - /* 28px on the left for icon or checkbox. */ - 'padding-left: 28px;', - '}', +`.blocklyDropdownMenu .blocklyMenuItem { + /* 28px on the left for icon or checkbox. */ + padding-left: 28px; +}`, /* BiDi override for the resting state. */ - '.blocklyDropdownMenu .blocklyMenuItemRtl {', - /* Flip left/right padding for BiDi. */ - 'padding-left: 5px;', - 'padding-right: 28px;', - '}', +`.blocklyDropdownMenu .blocklyMenuItemRtl { + /* Flip left/right padding for BiDi. */ + padding-left: 5px; + padding-right: 28px; +}`, - '.blocklyWidgetDiv .blocklyMenu {', - 'background: #fff;', - 'border: 1px solid transparent;', - 'box-shadow: 0 0 3px 1px rgba(0,0,0,.3);', - 'font: normal 13px Arial, sans-serif;', - 'margin: 0;', - 'outline: none;', - 'padding: 4px 0;', - 'position: absolute;', - 'overflow-y: auto;', - 'overflow-x: hidden;', - 'max-height: 100%;', - 'z-index: 20000;', /* Arbitrary, but some apps depend on it... */ - '}', +`.blocklyWidgetDiv .blocklyMenu { + background: #fff; + border: 1px solid transparent; + box-shadow: 0 0 3px 1px rgba(0,0,0,.3); + font: normal 13px Arial, sans-serif; + margin: 0; + outline: none; + padding: 4px 0; + position: absolute; + overflow-y: auto; + overflow-x: hidden; + max-height: 100%; + z-index: 20000;', /* Arbitrary, but some apps depend on it... */ +}`, - '.blocklyWidgetDiv .blocklyMenu.blocklyFocused {', - 'box-shadow: 0 0 6px 1px rgba(0,0,0,.3);', - '}', +`.blocklyWidgetDiv .blocklyMenu.blocklyFocused { + box-shadow: 0 0 6px 1px rgba(0,0,0,.3); +}`, - '.blocklyDropDownDiv .blocklyMenu {', - 'background: inherit;', /* Compatibility with gapi, reset from goog-menu */ - 'border: inherit;', /* Compatibility with gapi, reset from goog-menu */ - 'font: normal 13px "Helvetica Neue", Helvetica, sans-serif;', - 'outline: none;', - 'position: relative;', /* Compatibility with gapi, reset from goog-menu */ - 'z-index: 20000;', /* Arbitrary, but some apps depend on it... */ - '}', +`.blocklyDropDownDiv .blocklyMenu { + background: inherit;', /* Compatibility with gapi, reset from goog-menu */ + border: inherit;', /* Compatibility with gapi, reset from goog-menu */ + font: normal 13px "Helvetica Neue", Helvetica, sans-serif; + outline: none; + position: relative;', /* Compatibility with gapi, reset from goog-menu */ + z-index: 20000;', /* Arbitrary, but some apps depend on it... */ +}`, /* State: resting. */ - '.blocklyMenuItem {', - 'border: none;', - 'color: #000;', - 'cursor: pointer;', - 'list-style: none;', - 'margin: 0;', - /* 7em on the right for shortcut. */ - 'min-width: 7em;', - 'padding: 6px 15px;', - 'white-space: nowrap;', - '}', +`.blocklyMenuItem { + border: none; + color: #000; + cursor: pointer; + list-style: none; + margin: 0; + /* 7em on the right for shortcut. */ + min-width: 7em; + padding: 6px 15px; + white-space: nowrap; +}`, /* State: disabled. */ - '.blocklyMenuItemDisabled {', - 'color: #ccc;', - 'cursor: inherit;', - '}', +`.blocklyMenuItemDisabled { + color: #ccc; + cursor: inherit; +}`, /* State: hover. */ - '.blocklyMenuItemHighlight {', - 'background-color: rgba(0,0,0,.1);', - '}', +`.blocklyMenuItemHighlight { + background-color: rgba(0,0,0,.1); +}`, /* State: selected/checked. */ - '.blocklyMenuItemCheckbox {', - 'height: 16px;', - 'position: absolute;', - 'width: 16px;', - '}', +`.blocklyMenuItemCheckbox { + height: 16px; + position: absolute; + width: 16px; +}`, - '.blocklyMenuItemSelected .blocklyMenuItemCheckbox {', - 'background: url(<<>>/sprites.png) no-repeat -48px -16px;', - 'float: left;', - 'margin-left: -24px;', - 'position: static;', /* Scroll with the menu. */ - '}', +`.blocklyMenuItemSelected .blocklyMenuItemCheckbox { + background: url(<<>>/sprites.png) no-repeat -48px -16px; + float: left; + margin-left: -24px; + position: static;', /* Scroll with the menu. */ +}`, - '.blocklyMenuItemRtl .blocklyMenuItemCheckbox {', - 'float: right;', - 'margin-right: -24px;', - '}', - /* eslint-enable indent */ +`.blocklyMenuItemRtl .blocklyMenuItemCheckbox { + float: right; + margin-right: -24px; +}`, ]; From 7c23985d30493cc1f60399ffbcce111444da3f11 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 10:04:38 -0700 Subject: [PATCH 041/313] Migrate core/css.js to goog.module --- core/css.js | 27 +++++++++++++++------------ tests/deps.js | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/css.js b/core/css.js index b63c7ed8e..02d3db4bf 100644 --- a/core/css.js +++ b/core/css.js @@ -14,7 +14,8 @@ * @name Blockly.Css * @namespace */ -goog.provide('Blockly.Css'); +goog.module('Blockly.Css'); +goog.module.declareLegacyNamespace(); /** @@ -22,7 +23,7 @@ goog.provide('Blockly.Css'); * @type {boolean} * @private */ -Blockly.Css.injected_ = false; +let injected = false; /** * Add some CSS to the blob that will be injected later. Allows optional @@ -30,12 +31,12 @@ Blockly.Css.injected_ = false; * The provided array of CSS will be destroyed by this function. * @param {!Array} cssArray Array of CSS strings. */ -Blockly.Css.register = function(cssArray) { - if (Blockly.Css.injected_) { +const register = function(cssArray) { + if (injected) { throw Error('CSS already injected'); } - // Concatenate cssArray onto Blockly.Css.CONTENT. - Array.prototype.push.apply(Blockly.Css.CONTENT, cssArray); + // Concatenate cssArray onto CONTENT. + Array.prototype.push.apply(CONTENT, cssArray); cssArray.length = 0; // Garbage collect provided CSS content. }; @@ -49,14 +50,14 @@ Blockly.Css.register = function(cssArray) { * (providing CSS becomes the document's responsibility). * @param {string} pathToMedia Path from page to the Blockly media directory. */ -Blockly.Css.inject = function(hasCss, pathToMedia) { +const inject = function(hasCss, pathToMedia) { // Only inject the CSS once. - if (Blockly.Css.injected_) { + if (injected) { return; } - Blockly.Css.injected_ = true; - let text = Blockly.Css.CONTENT.join('\n'); - Blockly.Css.CONTENT.length = 0; // Garbage collect CSS content. + injected = true; + let text = CONTENT.join('\n'); + CONTENT.length = 0; // Garbage collect CSS content. if (!hasCss) { return; } @@ -75,7 +76,7 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { /** * Array making up the CSS content for Blockly. */ -Blockly.Css.CONTENT = [ +const CONTENT = [ `.blocklySvg { background-color: #fff; outline: none; @@ -552,3 +553,5 @@ Blockly.Css.CONTENT = [ margin-right: -24px; }`, ]; + +exports = {register, inject, CONTENT}; diff --git a/tests/deps.js b/tests/deps.js index 5c46df3f6..a44954c4f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -27,7 +27,7 @@ goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.c goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); -goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es5'}); +goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); From 7aae731a521b91c32bc102d55d9461f18becb3dd Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 10:05:00 -0700 Subject: [PATCH 042/313] clang-format core/css.js --- core/css.js | 154 +++++++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 75 deletions(-) diff --git a/core/css.js b/core/css.js index 02d3db4bf..52228b4fb 100644 --- a/core/css.js +++ b/core/css.js @@ -77,7 +77,7 @@ const inject = function(hasCss, pathToMedia) { * Array making up the CSS content for Blockly. */ const CONTENT = [ -`.blocklySvg { + `.blocklySvg { background-color: #fff; outline: none; overflow: hidden; /* IE overflows by default. */ @@ -85,26 +85,26 @@ const CONTENT = [ display: block; }`, -`.blocklyWidgetDiv { + `.blocklyWidgetDiv { display: none; position: absolute; z-index: 99999; /* big value for bootstrap3 compatibility */ }`, -`.injectionDiv { + `.injectionDiv { height: 100%; position: relative; overflow: hidden; /* So blocks in drag surface disappear at edges */ touch-action: none; }`, -`.blocklyNonSelectable { + `.blocklyNonSelectable { user-select: none; -ms-user-select: none; -webkit-user-select: none; }`, -`.blocklyWsDragSurface { + `.blocklyWsDragSurface { display: none; position: absolute; top: 0; @@ -114,11 +114,11 @@ const CONTENT = [ /* Added as a separate rule with multiple classes to make it more specific than a bootstrap rule that selects svg:root. See issue #1275 for context. */ -`.blocklyWsDragSurface.blocklyOverflowVisible { + `.blocklyWsDragSurface.blocklyOverflowVisible { overflow: visible; }`, -`.blocklyBlockDragSurface { + `.blocklyBlockDragSurface { display: none; position: absolute; top: 0; @@ -129,12 +129,12 @@ const CONTENT = [ z-index: 50;', /* Display below toolbox, but above everything else. */ }`, -`.blocklyBlockCanvas.blocklyCanvasTransitioning, + `.blocklyBlockCanvas.blocklyCanvasTransitioning, .blocklyBubbleCanvas.blocklyCanvasTransitioning { transition: transform .5s; }`, -`.blocklyTooltipDiv { + `.blocklyTooltipDiv { background-color: #ffffc7; border: 1px solid #ddc; box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15); @@ -147,7 +147,7 @@ const CONTENT = [ z-index: 100000;', /* big value for bootstrap3 compatibility */ }`, -`.blocklyDropDownDiv { + `.blocklyDropDownDiv { position: absolute; left: 0; top: 0; @@ -161,18 +161,18 @@ const CONTENT = [ box-shadow: 0 0 3px 1px rgba(0,0,0,.3); }`, -`.blocklyDropDownDiv.blocklyFocused { + `.blocklyDropDownDiv.blocklyFocused { box-shadow: 0 0 6px 1px rgba(0,0,0,.3); }`, -`.blocklyDropDownContent { + `.blocklyDropDownContent { max-height: 300px;', // @todo: spec for maximum height. overflow: auto; overflow-x: hidden; position: relative; }`, -`.blocklyDropDownArrow { + `.blocklyDropDownArrow { position: absolute; left: 0; top: 0; @@ -183,7 +183,7 @@ const CONTENT = [ border-color: inherit; }`, -`.blocklyDropDownButton { + `.blocklyDropDownButton { display: inline-block; float: left; padding: 0; @@ -195,52 +195,52 @@ const CONTENT = [ cursor: pointer; }`, -`.blocklyArrowTop { + `.blocklyArrowTop { border-top: 1px solid; border-left: 1px solid; border-top-left-radius: 4px; border-color: inherit; }`, -`.blocklyArrowBottom { + `.blocklyArrowBottom { border-bottom: 1px solid; border-right: 1px solid; border-bottom-right-radius: 4px; border-color: inherit; }`, -`.blocklyResizeSE { + `.blocklyResizeSE { cursor: se-resize; fill: #aaa; }`, -`.blocklyResizeSW { + `.blocklyResizeSW { cursor: sw-resize; fill: #aaa; }`, -`.blocklyResizeLine { + `.blocklyResizeLine { stroke: #515A5A; stroke-width: 1; }`, -`.blocklyHighlightedConnectionPath { + `.blocklyHighlightedConnectionPath { fill: none; stroke: #fc3; stroke-width: 4px; }`, -`.blocklyPathLight { + `.blocklyPathLight { fill: none; stroke-linecap: round; stroke-width: 1; }`, -`.blocklySelected>.blocklyPathLight { + `.blocklySelected>.blocklyPathLight { display: none; }`, -`.blocklyDraggable { + `.blocklyDraggable { /* backup for browsers (e.g. IE11) that don't support grab */ cursor: url("<<>>/handopen.cur"), auto; cursor: grab; @@ -248,7 +248,7 @@ const CONTENT = [ }`, /* backup for browsers (e.g. IE11) that don't support grabbing */ -`.blocklyDragging { + `.blocklyDragging { /* backup for browsers (e.g. IE11) that don't support grabbing */ cursor: url("<<>>/handclosed.cur"), auto; cursor: grabbing; @@ -257,7 +257,7 @@ const CONTENT = [ /* Changes cursor on mouse down. Not effective in Firefox because of https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */ -`.blocklyDraggable:active { + `.blocklyDraggable:active { /* backup for browsers (e.g. IE11) that don't support grabbing */ cursor: url("<<>>/handclosed.cur"), auto; cursor: grabbing; @@ -267,58 +267,58 @@ const CONTENT = [ /* Change the cursor on the whole drag surface in case the mouse gets ahead of block during a drag. This way the cursor is still a closed hand. */ -`.blocklyBlockDragSurface .blocklyDraggable { + `.blocklyBlockDragSurface .blocklyDraggable { /* backup for browsers (e.g. IE11) that don't support grabbing */ cursor: url("<<>>/handclosed.cur"), auto; cursor: grabbing; cursor: -webkit-grabbing; }`, -`.blocklyDragging.blocklyDraggingDelete { + `.blocklyDragging.blocklyDraggingDelete { cursor: url("<<>>/handdelete.cur"), auto; }`, -`.blocklyDragging>.blocklyPath, + `.blocklyDragging>.blocklyPath, .blocklyDragging>.blocklyPathLight { fill-opacity: .8; stroke-opacity: .8; }`, -`.blocklyDragging>.blocklyPathDark { + `.blocklyDragging>.blocklyPathDark { display: none; }`, -`.blocklyDisabled>.blocklyPath { + `.blocklyDisabled>.blocklyPath { fill-opacity: .5; stroke-opacity: .5; }`, -`.blocklyDisabled>.blocklyPathLight, + `.blocklyDisabled>.blocklyPathLight, .blocklyDisabled>.blocklyPathDark { display: none; }`, -`.blocklyInsertionMarker>.blocklyPath, + `.blocklyInsertionMarker>.blocklyPath, .blocklyInsertionMarker>.blocklyPathLight, .blocklyInsertionMarker>.blocklyPathDark { fill-opacity: .2; stroke: none; }`, -`.blocklyMultilineText { + `.blocklyMultilineText { font-family: monospace; }`, -`.blocklyNonEditableText>text { + `.blocklyNonEditableText>text { pointer-events: none; }`, -`.blocklyFlyout { + `.blocklyFlyout { position: absolute; z-index: 20; }`, -`.blocklyText text { + `.blocklyText text { cursor: default; }`, @@ -326,7 +326,7 @@ const CONTENT = [ Don't allow users to select text. It gets annoying when trying to drag a block and selected text moves instead. */ -`.blocklySvg text, + `.blocklySvg text, .blocklyBlockDragSurface text { user-select: none; -ms-user-select: none; @@ -334,39 +334,39 @@ const CONTENT = [ cursor: inherit; }`, -`.blocklyHidden { + `.blocklyHidden { display: none; }`, -`.blocklyFieldDropdown:not(.blocklyHidden) { + `.blocklyFieldDropdown:not(.blocklyHidden) { display: block; }`, -`.blocklyIconGroup { + `.blocklyIconGroup { cursor: default; }`, -`.blocklyIconGroup:not(:hover), + `.blocklyIconGroup:not(:hover), .blocklyIconGroupReadonly { opacity: .6; }`, -`.blocklyIconShape { + `.blocklyIconShape { fill: #00f; stroke: #fff; stroke-width: 1px; }`, -`.blocklyIconSymbol { + `.blocklyIconSymbol { fill: #fff; }`, -`.blocklyMinimalBody { + `.blocklyMinimalBody { margin: 0; padding: 0; }`, -`.blocklyHtmlInput { + `.blocklyHtmlInput { border: none; border-radius: 4px; height: 100%; @@ -382,107 +382,107 @@ const CONTENT = [ /* Edge and IE introduce a close icon when the input value is longer than a certain length. This affects our sizing calculations of the text input. Hiding the close icon to avoid that. */ -`.blocklyHtmlInput::-ms-clear { + `.blocklyHtmlInput::-ms-clear { display: none; }`, -`.blocklyMainBackground { + `.blocklyMainBackground { stroke-width: 1; stroke: #c6c6c6;', /* Equates to #ddd due to border being off-pixel. */ }`, -`.blocklyMutatorBackground { + `.blocklyMutatorBackground { fill: #fff; stroke: #ddd; stroke-width: 1; }`, -`.blocklyFlyoutBackground { + `.blocklyFlyoutBackground { fill: #ddd; fill-opacity: .8; }`, -`.blocklyMainWorkspaceScrollbar { + `.blocklyMainWorkspaceScrollbar { z-index: 20; }`, -`.blocklyFlyoutScrollbar { + `.blocklyFlyoutScrollbar { z-index: 30; }`, -`.blocklyScrollbarHorizontal, + `.blocklyScrollbarHorizontal, .blocklyScrollbarVertical { position: absolute; outline: none; }`, -`.blocklyScrollbarBackground { + `.blocklyScrollbarBackground { opacity: 0; }`, -`.blocklyScrollbarHandle { + `.blocklyScrollbarHandle { fill: #ccc; }`, -`.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, + `.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, .blocklyScrollbarHandle:hover { fill: #bbb; }`, /* Darken flyout scrollbars due to being on a grey background. */ /* By contrast, workspace scrollbars are on a white background. */ -`.blocklyFlyout .blocklyScrollbarHandle { + `.blocklyFlyout .blocklyScrollbarHandle { fill: #bbb; }`, -`.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, + `.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, .blocklyFlyout .blocklyScrollbarHandle:hover { fill: #aaa; }`, -`.blocklyInvalidInput { + `.blocklyInvalidInput { background: #faa; }`, -`.blocklyVerticalMarker { + `.blocklyVerticalMarker { stroke-width: 3px; fill: rgba(255,255,255,.5); pointer-events: none; }`, -`.blocklyComputeCanvas { + `.blocklyComputeCanvas { position: absolute; width: 0; height: 0; }`, -`.blocklyNoPointerEvents { + `.blocklyNoPointerEvents { pointer-events: none; }`, -`.blocklyContextMenu { + `.blocklyContextMenu { border-radius: 4px; max-height: 100%; }`, -`.blocklyDropdownMenu { + `.blocklyDropdownMenu { border-radius: 2px; padding: 0 !important; }`, -`.blocklyDropdownMenu .blocklyMenuItem { + `.blocklyDropdownMenu .blocklyMenuItem { /* 28px on the left for icon or checkbox. */ padding-left: 28px; }`, /* BiDi override for the resting state. */ -`.blocklyDropdownMenu .blocklyMenuItemRtl { + `.blocklyDropdownMenu .blocklyMenuItemRtl { /* Flip left/right padding for BiDi. */ padding-left: 5px; padding-right: 28px; }`, -`.blocklyWidgetDiv .blocklyMenu { + `.blocklyWidgetDiv .blocklyMenu { background: #fff; border: 1px solid transparent; box-shadow: 0 0 3px 1px rgba(0,0,0,.3); @@ -497,11 +497,11 @@ const CONTENT = [ z-index: 20000;', /* Arbitrary, but some apps depend on it... */ }`, -`.blocklyWidgetDiv .blocklyMenu.blocklyFocused { + `.blocklyWidgetDiv .blocklyMenu.blocklyFocused { box-shadow: 0 0 6px 1px rgba(0,0,0,.3); }`, -`.blocklyDropDownDiv .blocklyMenu { + `.blocklyDropDownDiv .blocklyMenu { background: inherit;', /* Compatibility with gapi, reset from goog-menu */ border: inherit;', /* Compatibility with gapi, reset from goog-menu */ font: normal 13px "Helvetica Neue", Helvetica, sans-serif; @@ -511,7 +511,7 @@ const CONTENT = [ }`, /* State: resting. */ -`.blocklyMenuItem { + `.blocklyMenuItem { border: none; color: #000; cursor: pointer; @@ -524,34 +524,38 @@ const CONTENT = [ }`, /* State: disabled. */ -`.blocklyMenuItemDisabled { + `.blocklyMenuItemDisabled { color: #ccc; cursor: inherit; }`, /* State: hover. */ -`.blocklyMenuItemHighlight { + `.blocklyMenuItemHighlight { background-color: rgba(0,0,0,.1); }`, /* State: selected/checked. */ -`.blocklyMenuItemCheckbox { + `.blocklyMenuItemCheckbox { height: 16px; position: absolute; width: 16px; }`, -`.blocklyMenuItemSelected .blocklyMenuItemCheckbox { + `.blocklyMenuItemSelected .blocklyMenuItemCheckbox { background: url(<<>>/sprites.png) no-repeat -48px -16px; float: left; margin-left: -24px; position: static;', /* Scroll with the menu. */ }`, -`.blocklyMenuItemRtl .blocklyMenuItemCheckbox { + `.blocklyMenuItemRtl .blocklyMenuItemCheckbox { float: right; margin-right: -24px; }`, ]; -exports = {register, inject, CONTENT}; +exports = { + register, + inject, + CONTENT +}; From f80764e1537232c0903d7ba0b7694f2219fde92c Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 10:51:14 -0700 Subject: [PATCH 043/313] Migrate core/renderers/common/drawer.js to named requires --- core/renderers/common/drawer.js | 130 +++++++++++++++----------------- 1 file changed, 60 insertions(+), 70 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 4eca204a3..30018aae1 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,22 +13,22 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockRendering.RenderInfo'); -goog.require('Blockly.blockRendering.Row'); -goog.require('Blockly.blockRendering.Types'); -goog.require('Blockly.utils.svgPaths'); +const RenderInfo = goog.require('Blockly.blockRendering.RenderInfo'); +const Row = goog.require('Blockly.blockRendering.Row'); +const Types = goog.require('Blockly.blockRendering.Types'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.blockRendering.Field'); -goog.requireType('Blockly.blockRendering.Icon'); -goog.requireType('Blockly.blockRendering.InlineInput'); -goog.requireType('Blockly.BlockSvg'); +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +const Field = goog.requireType('Blockly.blockRendering.Field'); +const Icon = goog.requireType('Blockly.blockRendering.Icon'); +const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); /** * An object that draws a block based on the given rendering information. - * @param {!Blockly.BlockSvg} block The block to render. - * @param {!Blockly.blockRendering.RenderInfo} info An object containing all + * @param {!BlockSvg} block The block to render. + * @param {!RenderInfo} info An object containing all * information needed to render this block. * @package * @constructor @@ -42,7 +42,7 @@ const Drawer = function(block, info) { /** * The renderer's constant provider. - * @type {!Blockly.blockRendering.ConstantProvider} + * @type {!ConstantProvider} * @protected */ this.constants_ = info.getRenderer().getConstants(); @@ -129,42 +129,41 @@ Drawer.prototype.drawTop_ = function() { const elements = topRow.elements; this.positionPreviousConnection_(); - this.outlinePath_ += - Blockly.utils.svgPaths.moveBy(topRow.xPos, this.info_.startY); + this.outlinePath_ += svgPaths.moveBy(topRow.xPos, this.info_.startY); for (let i = 0, elem; (elem = elements[i]); i++) { - if (Blockly.blockRendering.Types.isLeftRoundedCorner(elem)) { + if (Types.isLeftRoundedCorner(elem)) { this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topLeft; - } else if (Blockly.blockRendering.Types.isRightRoundedCorner(elem)) { + } else if (Types.isRightRoundedCorner(elem)) { this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topRight; - } else if (Blockly.blockRendering.Types.isPreviousConnection(elem)) { + } else if (Types.isPreviousConnection(elem)) { this.outlinePath_ += elem.shape.pathLeft; - } else if (Blockly.blockRendering.Types.isHat(elem)) { + } else if (Types.isHat(elem)) { this.outlinePath_ += this.constants_.START_HAT.path; - } else if (Blockly.blockRendering.Types.isSpacer(elem)) { - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('h', elem.width); + } else if (Types.isSpacer(elem)) { + this.outlinePath_ += svgPaths.lineOnAxis('h', elem.width); } // No branch for a square corner, because it's a no-op. } - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('v', topRow.height); + this.outlinePath_ += svgPaths.lineOnAxis('v', topRow.height); }; /** * Add steps for the jagged edge of a row on a collapsed block. - * @param {!Blockly.blockRendering.Row} row The row to draw the side of. + * @param {!Row} row The row to draw the side of. * @protected */ Drawer.prototype.drawJaggedEdge_ = function(row) { const remainder = row.height - this.constants_.JAGGED_TEETH.height; - this.outlinePath_ += this.constants_.JAGGED_TEETH.path + - Blockly.utils.svgPaths.lineOnAxis('v', remainder); + this.outlinePath_ += + this.constants_.JAGGED_TEETH.path + svgPaths.lineOnAxis('v', remainder); }; /** * Add steps for an external value input, rendered as a notch in the side * of the block. - * @param {!Blockly.blockRendering.Row} row The row that this input + * @param {!Row} row The row that this input * belongs to. * @protected */ @@ -176,16 +175,14 @@ Drawer.prototype.drawValueInput_ = function(row) { input.shape.pathDown(input.height) : input.shape.pathDown; - this.outlinePath_ += - Blockly.utils.svgPaths.lineOnAxis('H', input.xPos + input.width) + - pathDown + - Blockly.utils.svgPaths.lineOnAxis('v', row.height - input.connectionHeight); + this.outlinePath_ += svgPaths.lineOnAxis('H', input.xPos + input.width) + + pathDown + svgPaths.lineOnAxis('v', row.height - input.connectionHeight); }; /** * Add steps for a statement input. - * @param {!Blockly.blockRendering.Row} row The row that this input + * @param {!Row} row The row that this input * belongs to. * @protected */ @@ -195,17 +192,16 @@ Drawer.prototype.drawStatementInput_ = function(row) { const x = input.xPos + input.notchOffset + input.shape.width; const innerTopLeftCorner = input.shape.pathRight + - Blockly.utils.svgPaths.lineOnAxis( + svgPaths.lineOnAxis( 'h', -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + this.constants_.INSIDE_CORNERS.pathTop; const innerHeight = row.height - (2 * this.constants_.INSIDE_CORNERS.height); - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('H', x) + - innerTopLeftCorner + - Blockly.utils.svgPaths.lineOnAxis('v', innerHeight) + + this.outlinePath_ += svgPaths.lineOnAxis('H', x) + innerTopLeftCorner + + svgPaths.lineOnAxis('v', innerHeight) + this.constants_.INSIDE_CORNERS.pathBottom + - Blockly.utils.svgPaths.lineOnAxis('H', row.xPos + row.width); + svgPaths.lineOnAxis('H', row.xPos + row.width); this.positionStatementInputConnection_(row); }; @@ -213,13 +209,12 @@ Drawer.prototype.drawStatementInput_ = function(row) { /** * Add steps for the right side of a row that does not have value or * statement input connections. - * @param {!Blockly.blockRendering.Row} row The row to draw the + * @param {!Row} row The row to draw the * side of. * @protected */ Drawer.prototype.drawRightSideRow_ = function(row) { - this.outlinePath_ += - Blockly.utils.svgPaths.lineOnAxis('V', row.yPos + row.height); + this.outlinePath_ += svgPaths.lineOnAxis('V', row.yPos + row.height); }; @@ -236,22 +231,22 @@ Drawer.prototype.drawBottom_ = function() { let rightCornerYOffset = 0; let outlinePath = ''; for (let i = elems.length - 1, elem; (elem = elems[i]); i--) { - if (Blockly.blockRendering.Types.isNextConnection(elem)) { + if (Types.isNextConnection(elem)) { outlinePath += elem.shape.pathRight; - } else if (Blockly.blockRendering.Types.isLeftSquareCorner(elem)) { - outlinePath += Blockly.utils.svgPaths.lineOnAxis('H', bottomRow.xPos); - } else if (Blockly.blockRendering.Types.isLeftRoundedCorner(elem)) { + } else if (Types.isLeftSquareCorner(elem)) { + outlinePath += svgPaths.lineOnAxis('H', bottomRow.xPos); + } else if (Types.isLeftRoundedCorner(elem)) { outlinePath += this.constants_.OUTSIDE_CORNERS.bottomLeft; - } else if (Blockly.blockRendering.Types.isRightRoundedCorner(elem)) { + } else if (Types.isRightRoundedCorner(elem)) { outlinePath += this.constants_.OUTSIDE_CORNERS.bottomRight; rightCornerYOffset = this.constants_.OUTSIDE_CORNERS.rightHeight; - } else if (Blockly.blockRendering.Types.isSpacer(elem)) { - outlinePath += Blockly.utils.svgPaths.lineOnAxis('h', elem.width * -1); + } else if (Types.isSpacer(elem)) { + outlinePath += svgPaths.lineOnAxis('h', elem.width * -1); } } - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('V', - bottomRow.baseline - rightCornerYOffset); + this.outlinePath_ += + svgPaths.lineOnAxis('V', bottomRow.baseline - rightCornerYOffset); this.outlinePath_ += outlinePath; }; @@ -272,9 +267,7 @@ Drawer.prototype.drawLeft_ = function() { outputConnection.shape.pathUp; // Draw a line up to the bottom of the tab. - this.outlinePath_ += - Blockly.utils.svgPaths.lineOnAxis('V', tabBottom) + - pathUp; + this.outlinePath_ += svgPaths.lineOnAxis('V', tabBottom) + pathUp; } // Close off the path. This draws a vertical line up to the start of the // block's path, which may be either a rounded or a sharp corner. @@ -289,13 +282,12 @@ Drawer.prototype.drawLeft_ = function() { Drawer.prototype.drawInternals_ = function() { for (let i = 0, row; (row = this.info_.rows[i]); i++) { for (let j = 0, elem; (elem = row.elements[j]); j++) { - if (Blockly.blockRendering.Types.isInlineInput(elem)) { + if (Types.isInlineInput(elem)) { this.drawInlineInput_( - /** @type {!Blockly.blockRendering.InlineInput} */ (elem)); - } else if (Blockly.blockRendering.Types.isIcon(elem) || - Blockly.blockRendering.Types.isField(elem)) { + /** @type {!InlineInput} */ (elem)); + } else if (Types.isIcon(elem) || Types.isField(elem)) { this.layoutField_( - /** @type {!Blockly.blockRendering.Field|!Blockly.blockRendering.Icon} */ + /** @type {!Field|!Icon} */ (elem)); } } @@ -304,15 +296,15 @@ Drawer.prototype.drawInternals_ = function() { /** * Push a field or icon's new position to its SVG root. - * @param {!Blockly.blockRendering.Icon|!Blockly.blockRendering.Field} fieldInfo + * @param {!Icon|!Field} fieldInfo * The rendering information for the field or icon. * @protected */ Drawer.prototype.layoutField_ = function(fieldInfo) { let svgGroup; - if (Blockly.blockRendering.Types.isField(fieldInfo)) { + if (Types.isField(fieldInfo)) { svgGroup = fieldInfo.field.getSvgRoot(); - } else if (Blockly.blockRendering.Types.isIcon(fieldInfo)) { + } else if (Types.isIcon(fieldInfo)) { svgGroup = fieldInfo.icon.iconGroup_; } @@ -326,7 +318,7 @@ Drawer.prototype.layoutField_ = function(fieldInfo) { scale = 'scale(-1 1)'; } } - if (Blockly.blockRendering.Types.isIcon(fieldInfo)) { + if (Types.isIcon(fieldInfo)) { svgGroup.setAttribute('display', 'block'); svgGroup.setAttribute('transform', 'translate(' + xPos + ',' + yPos + ')'); fieldInfo.icon.computeIconLocation(); @@ -344,7 +336,7 @@ Drawer.prototype.layoutField_ = function(fieldInfo) { /** * Add steps for an inline input. - * @param {!Blockly.blockRendering.InlineInput} input The information about the + * @param {!InlineInput} input The information about the * input to render. * @protected */ @@ -357,13 +349,11 @@ Drawer.prototype.drawInlineInput_ = function(input) { const connectionBottom = input.connectionHeight + connectionTop; const connectionRight = input.xPos + input.connectionWidth; - this.inlinePath_ += Blockly.utils.svgPaths.moveTo(connectionRight, yPos) + - Blockly.utils.svgPaths.lineOnAxis('v', connectionTop) + - input.shape.pathDown + - Blockly.utils.svgPaths.lineOnAxis('v', height - connectionBottom) + - Blockly.utils.svgPaths.lineOnAxis('h', width - input.connectionWidth) + - Blockly.utils.svgPaths.lineOnAxis('v', -height) + - 'z'; + this.inlinePath_ += svgPaths.moveTo(connectionRight, yPos) + + svgPaths.lineOnAxis('v', connectionTop) + input.shape.pathDown + + svgPaths.lineOnAxis('v', height - connectionBottom) + + svgPaths.lineOnAxis('h', width - input.connectionWidth) + + svgPaths.lineOnAxis('v', -height) + 'z'; this.positionInlineInputConnection_(input); }; @@ -372,7 +362,7 @@ Drawer.prototype.drawInlineInput_ = function(input) { * Position the connection on an inline value input, taking into account * RTL and the small gap between the parent block and child block which lets the * parent block's dark path show through. - * @param {Blockly.blockRendering.InlineInput} input The information about + * @param {InlineInput} input The information about * the input that the connection is on. * @protected */ @@ -394,7 +384,7 @@ Drawer.prototype.positionInlineInputConnection_ = function(input) { * Position the connection on a statement input, taking into account * RTL and the small gap between the parent block and child block which lets the * parent block's dark path show through. - * @param {!Blockly.blockRendering.Row} row The row that the connection is on. + * @param {!Row} row The row that the connection is on. * @protected */ Drawer.prototype.positionStatementInputConnection_ = function(row) { @@ -412,7 +402,7 @@ Drawer.prototype.positionStatementInputConnection_ = function(row) { * Position the connection on an external value input, taking into account * RTL and the small gap between the parent block and child block which lets the * parent block's dark path show through. - * @param {!Blockly.blockRendering.Row} row The row that the connection is on. + * @param {!Row} row The row that the connection is on. * @protected */ Drawer.prototype.positionExternalValueConnection_ = function(row) { From 7e74017342561048ece8520c9a1f0d316e69eb5d Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 15 Jul 2021 16:12:10 -0700 Subject: [PATCH 044/313] Migrate core/connection_types.js to goog.module --- core/connection_types.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/connection_types.js b/core/connection_types.js index b2116812b..569ffc442 100644 --- a/core/connection_types.js +++ b/core/connection_types.js @@ -11,13 +11,14 @@ 'use strict'; -goog.provide('Blockly.connectionTypes'); +goog.module('Blockly.connectionTypes'); +goog.module.declareLegacyNamespace(); /** * Enum for the type of a connection or input. * @enum {number} */ -Blockly.connectionTypes = { +const connectionTypes = { // A right-facing value input. E.g. 'set item to' or 'return'. INPUT_VALUE: 1, // A left-facing value output. E.g. 'random fraction'. @@ -27,3 +28,5 @@ Blockly.connectionTypes = { // An up-facing block stack. E.g. 'break out of loop'. PREVIOUS_STATEMENT: 4 }; + +exports = connectionTypes; diff --git a/tests/deps.js b/tests/deps.js index a44954c4f..2e7e55bf8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -22,7 +22,7 @@ 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']); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); -goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], []); +goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); From d2142a2e9ff17dd8f530e1fa8d97fbb967abc9f7 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 11:00:50 -0700 Subject: [PATCH 045/313] Clang-format core/renderers/common/drawer.js and remove unused require --- core/renderers/common/drawer.js | 25 ++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 30018aae1..a0181bf8f 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,7 +13,6 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); -const RenderInfo = goog.require('Blockly.blockRendering.RenderInfo'); const Row = goog.require('Blockly.blockRendering.Row'); const Types = goog.require('Blockly.blockRendering.Types'); const svgPaths = goog.require('Blockly.utils.svgPaths'); @@ -22,6 +21,7 @@ const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvid const Field = goog.requireType('Blockly.blockRendering.Field'); const Icon = goog.requireType('Blockly.blockRendering.Icon'); const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); +const RenderInfo = goog.requireType('Blockly.blockRendering.RenderInfo'); const BlockSvg = goog.requireType('Blockly.BlockSvg'); @@ -132,11 +132,9 @@ Drawer.prototype.drawTop_ = function() { this.outlinePath_ += svgPaths.moveBy(topRow.xPos, this.info_.startY); for (let i = 0, elem; (elem = elements[i]); i++) { if (Types.isLeftRoundedCorner(elem)) { - this.outlinePath_ += - this.constants_.OUTSIDE_CORNERS.topLeft; + this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topLeft; } else if (Types.isRightRoundedCorner(elem)) { - this.outlinePath_ += - this.constants_.OUTSIDE_CORNERS.topRight; + this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topRight; } else if (Types.isPreviousConnection(elem)) { this.outlinePath_ += elem.shape.pathLeft; } else if (Types.isHat(elem)) { @@ -163,8 +161,7 @@ Drawer.prototype.drawJaggedEdge_ = function(row) { /** * Add steps for an external value input, rendered as a notch in the side * of the block. - * @param {!Row} row The row that this input - * belongs to. + * @param {!Row} row The row that this input belongs to. * @protected */ Drawer.prototype.drawValueInput_ = function(row) { @@ -182,8 +179,7 @@ Drawer.prototype.drawValueInput_ = function(row) { /** * Add steps for a statement input. - * @param {!Row} row The row that this input - * belongs to. + * @param {!Row} row The row that this input belongs to. * @protected */ Drawer.prototype.drawStatementInput_ = function(row) { @@ -209,8 +205,7 @@ Drawer.prototype.drawStatementInput_ = function(row) { /** * Add steps for the right side of a row that does not have value or * statement input connections. - * @param {!Row} row The row to draw the - * side of. + * @param {!Row} row The row to draw the side of. * @protected */ Drawer.prototype.drawRightSideRow_ = function(row) { @@ -375,8 +370,8 @@ Drawer.prototype.positionInlineInputConnection_ = function(input) { if (this.info_.RTL) { connX *= -1; } - input.connectionModel.setOffsetInBlock(connX, - yPos + input.connectionOffsetY); + input.connectionModel.setOffsetInBlock( + connX, yPos + input.connectionOffsetY); } }; @@ -452,8 +447,8 @@ Drawer.prototype.positionOutputConnection_ = function() { if (this.info_.outputConnection) { const x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; const connX = this.info_.RTL ? -x : x; - this.block_.outputConnection.setOffsetInBlock(connX, - this.info_.outputConnection.connectionOffsetY); + this.block_.outputConnection.setOffsetInBlock( + connX, this.info_.outputConnection.connectionOffsetY); } }; diff --git a/tests/deps.js b/tests/deps.js index 7cade6c4e..b0183d469 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -116,7 +116,7 @@ goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnec goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 8f5da9c41d6cedf9c334406e565b960218fb1605 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 10:55:04 -0700 Subject: [PATCH 046/313] Migrate core/component_manager.js to ES6 const/let --- core/component_manager.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/component_manager.js b/core/component_manager.js index d8b215504..5d50dcf91 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -62,16 +62,16 @@ Blockly.ComponentManager.ComponentDatum; Blockly.ComponentManager.prototype.addComponent = function( componentInfo, opt_allowOverrides) { // Don't throw an error if opt_allowOverrides is true. - var id = componentInfo.component.id; + const id = componentInfo.component.id; if (!opt_allowOverrides && this.componentData_[id]) { throw Error( 'Plugin "' + id + '" with capabilities "' + this.componentData_[id].capabilities + '" already added.'); } this.componentData_[id] = componentInfo; - var stringCapabilities = []; - for (var i = 0; i < componentInfo.capabilities.length; i++) { - var capability = String(componentInfo.capabilities[i]).toLowerCase(); + const stringCapabilities = []; + for (let i = 0; i < componentInfo.capabilities.length; i++) { + const capability = String(componentInfo.capabilities[i]).toLowerCase(); stringCapabilities.push(capability); if (this.capabilityToComponentIds_[capability] === undefined) { this.capabilityToComponentIds_[capability] = [id]; @@ -87,12 +87,12 @@ Blockly.ComponentManager.prototype.addComponent = function( * @param {string} id The ID of the component to remove. */ Blockly.ComponentManager.prototype.removeComponent = function(id) { - var componentInfo = this.componentData_[id]; + const componentInfo = this.componentData_[id]; if (!componentInfo) { return; } - for (var i = 0; i < componentInfo.capabilities.length; i++) { - var capability = String(componentInfo.capabilities[i]).toLowerCase(); + for (let i = 0; i < componentInfo.capabilities.length; i++) { + const capability = String(componentInfo.capabilities[i]).toLowerCase(); this.capabilityToComponentIds_[capability].splice( this.capabilityToComponentIds_[capability].indexOf(id), 1); } @@ -178,14 +178,14 @@ Blockly.ComponentManager.prototype.getComponent = function(id) { */ Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) { capability = String(capability).toLowerCase(); - var componentIds = this.capabilityToComponentIds_[capability]; + const componentIds = this.capabilityToComponentIds_[capability]; if (!componentIds) { return []; } - var components = []; + const components = []; if (sorted) { - var componentDataList = []; - var componentData = this.componentData_; + const componentDataList = []; + const componentData = this.componentData_; componentIds.forEach(function(id) { componentDataList.push(componentData[id]); }); @@ -196,7 +196,7 @@ Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) components.push(ComponentDatum.component); }); } else { - var componentData = this.componentData_; + const componentData = this.componentData_; componentIds.forEach(function(id) { components.push(componentData[id].component); }); From 85b8ffce8ba56d04992850a68c8f8744d7adffec Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:06:05 -0700 Subject: [PATCH 047/313] Migrate core/component_manager.js to goog.module --- core/component_manager.js | 65 ++++++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/core/component_manager.js b/core/component_manager.js index 5d50dcf91..fbf66d544 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.ComponentManager'); +goog.module('Blockly.ComponentManager'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.IAutoHideable'); goog.requireType('Blockly.IComponent'); @@ -24,10 +25,10 @@ goog.requireType('Blockly.IPositionable'); * Manager for all items registered with the workspace. * @constructor */ -Blockly.ComponentManager = function() { +const ComponentManager = function() { /** * A map of the components registered with the workspace, mapped to id. - * @type {!Object} + * @type {!Object} * @private */ this.componentData_ = Object.create(null); @@ -45,21 +46,21 @@ Blockly.ComponentManager = function() { * @typedef {{ * component: !Blockly.IComponent, * capabilities: ( - * !Array> + * !Array> * ), * weight: number * }} */ -Blockly.ComponentManager.ComponentDatum; +ComponentManager.ComponentDatum; /** * Adds a component. - * @param {!Blockly.ComponentManager.ComponentDatum} componentInfo The data for + * @param {!ComponentManager.ComponentDatum} componentInfo The data for * the component to register. * @param {boolean=} opt_allowOverrides True to prevent an error when overriding * an already registered item. */ -Blockly.ComponentManager.prototype.addComponent = function( +ComponentManager.prototype.addComponent = function( componentInfo, opt_allowOverrides) { // Don't throw an error if opt_allowOverrides is true. const id = componentInfo.component.id; @@ -86,7 +87,7 @@ Blockly.ComponentManager.prototype.addComponent = function( * Removes a component. * @param {string} id The ID of the component to remove. */ -Blockly.ComponentManager.prototype.removeComponent = function(id) { +ComponentManager.prototype.removeComponent = function(id) { const componentInfo = this.componentData_[id]; if (!componentInfo) { return; @@ -102,11 +103,11 @@ Blockly.ComponentManager.prototype.removeComponent = function(id) { /** * Adds a capability to a existing registered component. * @param {string} id The ID of the component to add the capability to. - * @param {string|!Blockly.ComponentManager.Capability} capability The + * @param {string|!ComponentManager.Capability} capability The * capability to add. * @template T */ -Blockly.ComponentManager.prototype.addCapability = function(id, capability) { +ComponentManager.prototype.addCapability = function(id, capability) { if (!this.getComponent(id)) { throw Error('Cannot add capability, "' + capability + '". Plugin "' + id + '" has not been added to the ComponentManager'); @@ -124,11 +125,11 @@ Blockly.ComponentManager.prototype.addCapability = function(id, capability) { /** * Removes a capability from an existing registered component. * @param {string} id The ID of the component to remove the capability from. - * @param {string|!Blockly.ComponentManager.Capability} capability The + * @param {string|!ComponentManager.Capability} capability The * capability to remove. * @template T */ -Blockly.ComponentManager.prototype.removeCapability = function(id, capability) { +ComponentManager.prototype.removeCapability = function(id, capability) { if (!this.getComponent(id)) { throw Error('Cannot remove capability, "' + capability + '". Plugin "' + id + '" has not been added to the ComponentManager'); @@ -148,12 +149,12 @@ Blockly.ComponentManager.prototype.removeCapability = function(id, capability) { /** * Returns whether the component with this id has the specified capability. * @param {string} id The ID of the component to check. - * @param {string|!Blockly.ComponentManager.Capability} capability The + * @param {string|!ComponentManager.Capability} capability The * capability to check for. * @return {boolean} Whether the component has the capability. * @template T */ -Blockly.ComponentManager.prototype.hasCapability = function(id, capability) { +ComponentManager.prototype.hasCapability = function(id, capability) { capability = String(capability).toLowerCase(); return this.componentData_[id].capabilities.indexOf(capability) !== -1; }; @@ -164,19 +165,19 @@ Blockly.ComponentManager.prototype.hasCapability = function(id, capability) { * @return {!Blockly.IComponent|undefined} The component with the given name * or undefined if not found. */ -Blockly.ComponentManager.prototype.getComponent = function(id) { +ComponentManager.prototype.getComponent = function(id) { return this.componentData_[id] && this.componentData_[id].component; }; /** * Gets all the components with the specified capability. - * @param {string|!Blockly.ComponentManager.Capability + * @param {string|!ComponentManager.Capability * } capability The capability of the component. * @param {boolean} sorted Whether to return list ordered by weights. * @return {!Array} The components that match the specified capability. * @template T */ -Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) { +ComponentManager.prototype.getComponents = function(capability, sorted) { capability = String(capability).toLowerCase(); const componentIds = this.capabilityToComponentIds_[capability]; if (!componentIds) { @@ -210,7 +211,7 @@ Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) * @constructor * @template T */ -Blockly.ComponentManager.Capability = function(name) { +ComponentManager.Capability = function(name) { /** * @type {string} * @private @@ -223,22 +224,24 @@ Blockly.ComponentManager.Capability = function(name) { * @return {string} The name. * @override */ -Blockly.ComponentManager.Capability.prototype.toString = function() { +ComponentManager.Capability.prototype.toString = function() { return this.name_; }; -/** @type {!Blockly.ComponentManager.Capability} */ -Blockly.ComponentManager.Capability.POSITIONABLE = - new Blockly.ComponentManager.Capability('positionable'); +/** @type {!ComponentManager.Capability} */ +ComponentManager.Capability.POSITIONABLE = + new ComponentManager.Capability('positionable'); -/** @type {!Blockly.ComponentManager.Capability} */ -Blockly.ComponentManager.Capability.DRAG_TARGET = - new Blockly.ComponentManager.Capability('drag_target'); +/** @type {!ComponentManager.Capability} */ +ComponentManager.Capability.DRAG_TARGET = + new ComponentManager.Capability('drag_target'); -/** @type {!Blockly.ComponentManager.Capability} */ -Blockly.ComponentManager.Capability.DELETE_AREA = - new Blockly.ComponentManager.Capability('delete_area'); +/** @type {!ComponentManager.Capability} */ +ComponentManager.Capability.DELETE_AREA = + new ComponentManager.Capability('delete_area'); -/** @type {!Blockly.ComponentManager.Capability} */ -Blockly.ComponentManager.Capability.AUTOHIDEABLE = - new Blockly.ComponentManager.Capability('autohideable'); +/** @type {!ComponentManager.Capability} */ +ComponentManager.Capability.AUTOHIDEABLE = + new ComponentManager.Capability('autohideable'); + +exports = ComponentManager; diff --git a/tests/deps.js b/tests/deps.js index 7baee6eb9..052655acd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -18,7 +18,7 @@ goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], [' 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/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/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_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); From 3c5479e0009333190e9db8acb24f470796cf0dd1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:07:34 -0700 Subject: [PATCH 048/313] Migrate core/component_manager.js named requires --- core/component_manager.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/component_manager.js b/core/component_manager.js index fbf66d544..cbc4baa60 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -14,11 +14,11 @@ goog.module('Blockly.ComponentManager'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.IAutoHideable'); -goog.requireType('Blockly.IComponent'); -goog.requireType('Blockly.IDeleteArea'); -goog.requireType('Blockly.IDragTarget'); -goog.requireType('Blockly.IPositionable'); +const IAutoHideable = goog.requireType('Blockly.IAutoHideable'); +const IComponent = goog.requireType('Blockly.IComponent'); +const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const IPositionable = goog.requireType('Blockly.IPositionable'); /** @@ -44,9 +44,9 @@ const ComponentManager = function() { /** * An object storing component information. * @typedef {{ - * component: !Blockly.IComponent, + * component: !IComponent, * capabilities: ( - * !Array> + * !Array> * ), * weight: number * }} @@ -162,7 +162,7 @@ ComponentManager.prototype.hasCapability = function(id, capability) { /** * Gets the component with the given ID. * @param {string} id The ID of the component to get. - * @return {!Blockly.IComponent|undefined} The component with the given name + * @return {!IComponent|undefined} The component with the given name * or undefined if not found. */ ComponentManager.prototype.getComponent = function(id) { @@ -228,19 +228,19 @@ ComponentManager.Capability.prototype.toString = function() { return this.name_; }; -/** @type {!ComponentManager.Capability} */ +/** @type {!ComponentManager.Capability} */ ComponentManager.Capability.POSITIONABLE = new ComponentManager.Capability('positionable'); -/** @type {!ComponentManager.Capability} */ +/** @type {!ComponentManager.Capability} */ ComponentManager.Capability.DRAG_TARGET = new ComponentManager.Capability('drag_target'); -/** @type {!ComponentManager.Capability} */ +/** @type {!ComponentManager.Capability} */ ComponentManager.Capability.DELETE_AREA = new ComponentManager.Capability('delete_area'); -/** @type {!ComponentManager.Capability} */ +/** @type {!ComponentManager.Capability} */ ComponentManager.Capability.AUTOHIDEABLE = new ComponentManager.Capability('autohideable'); From 81658d78ce82fcb2babb21a9d3cc19ea50183357 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:07:37 -0700 Subject: [PATCH 049/313] clang-format core/component_manager.js --- core/component_manager.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/component_manager.js b/core/component_manager.js index cbc4baa60..31b661e8a 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -109,12 +109,13 @@ ComponentManager.prototype.removeComponent = function(id) { */ ComponentManager.prototype.addCapability = function(id, capability) { if (!this.getComponent(id)) { - throw Error('Cannot add capability, "' + capability + '". Plugin "' + - id + '" has not been added to the ComponentManager'); + throw Error( + 'Cannot add capability, "' + capability + '". Plugin "' + id + + '" has not been added to the ComponentManager'); } if (this.hasCapability(id, capability)) { - console.warn('Plugin "' + id + 'already has capability "' + - capability + '"'); + console.warn( + 'Plugin "' + id + 'already has capability "' + capability + '"'); return; } capability = String(capability).toLowerCase(); @@ -131,12 +132,14 @@ ComponentManager.prototype.addCapability = function(id, capability) { */ ComponentManager.prototype.removeCapability = function(id, capability) { if (!this.getComponent(id)) { - throw Error('Cannot remove capability, "' + capability + '". Plugin "' + - id + '" has not been added to the ComponentManager'); + throw Error( + 'Cannot remove capability, "' + capability + '". Plugin "' + id + + '" has not been added to the ComponentManager'); } if (!this.hasCapability(id, capability)) { - console.warn('Plugin "' + id + 'doesn\'t have capability "' + - capability + '" to remove'); + console.warn( + 'Plugin "' + id + 'doesn\'t have capability "' + capability + + '" to remove'); return; } capability = String(capability).toLowerCase(); From a9e60851ef87625f915a1fe33da6cb5b909f313a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 11:49:35 -0700 Subject: [PATCH 050/313] Auto-tag and add milestones for cleanup PRs For new pull requests against the goog_module branch, adds the 'type: cleanup' label and sets the milestone to q3 2021 release. Based on [this PR](https://github.com/eclipse-theia/theia/pull/8631/files). --- .github/workflows/tag_module_cleanup.yml | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/tag_module_cleanup.yml diff --git a/.github/workflows/tag_module_cleanup.yml b/.github/workflows/tag_module_cleanup.yml new file mode 100644 index 000000000..8ee344066 --- /dev/null +++ b/.github/workflows/tag_module_cleanup.yml @@ -0,0 +1,34 @@ +# For new pull requests against the goog_module branch, adds the 'type: cleanup' +# label and sets the milestone to q3 2021 release. + +name: Tag module cleanup + +# Trigger on pull requests against goog_module branch only +on: + pull_request: + branches: + - goog_module + +jobs: + tag-module-cleanup: + + # Add the type: cleanup label + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@a3e7071 + with: + script: | + // 2021 q3 release milestone. + // https://github.com/google/blockly/milestone/18 + const milestoneNumber = 18; + // Note that pull requests are accessed through the issues API. + const issuesUpdateParams = { + owner: context.repo.owner, + repo: context.repo.repo, + // Adds the milestone + milestone: milestoneNumber, + issue_number: context.issue.number, + // Sets the labels + labels: ['type: cleanup'] + } + await github.issues.update(issuesUpdateParams) From 05f8c27302718a89136532b57d18e87557542bcb Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 11:52:38 -0700 Subject: [PATCH 051/313] Use full commit hash. --- .github/workflows/tag_module_cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tag_module_cleanup.yml b/.github/workflows/tag_module_cleanup.yml index 8ee344066..2b14426ad 100644 --- a/.github/workflows/tag_module_cleanup.yml +++ b/.github/workflows/tag_module_cleanup.yml @@ -15,7 +15,7 @@ jobs: # Add the type: cleanup label runs-on: ubuntu-latest steps: - - uses: actions/github-script@a3e7071 + - uses: actions/github-script@a3e7071a34d7e1f219a8a4de9a5e0a34d1ee1293 with: script: | // 2021 q3 release milestone. From fb7bba34916a184761f365d92fbcbbe984f67acc Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 15:56:05 -0700 Subject: [PATCH 052/313] Migrate core/utils/coordinate.js to ES6 const/let --- core/utils/coordinate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/coordinate.js b/core/utils/coordinate.js index edf513b28..da50f2623 100644 --- a/core/utils/coordinate.js +++ b/core/utils/coordinate.js @@ -63,8 +63,8 @@ Blockly.utils.Coordinate.equals = function(a, b) { * @return {number} The distance between `a` and `b`. */ Blockly.utils.Coordinate.distance = function(a, b) { - var dx = a.x - b.x; - var dy = a.y - b.y; + const dx = a.x - b.x; + const dy = a.y - b.y; return Math.sqrt(dx * dx + dy * dy); }; From 972f3022ed29dc52f3ebe3d4194d8ae3f396ebd1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 18:37:28 -0700 Subject: [PATCH 053/313] Migrate core/utils/coordinate.js to goog.module --- core/utils/coordinate.js | 62 +++++++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/core/utils/coordinate.js b/core/utils/coordinate.js index da50f2623..ca5a248d3 100644 --- a/core/utils/coordinate.js +++ b/core/utils/coordinate.js @@ -16,8 +16,8 @@ * @name Blockly.utils.Coordinate * @namespace */ -goog.provide('Blockly.utils.Coordinate'); - +goog.module('Blockly.utils.Coordinate'); +goog.module.declareLegacyNamespace(); /** * Class for representing coordinates and positions. @@ -26,7 +26,7 @@ goog.provide('Blockly.utils.Coordinate'); * @struct * @constructor */ -Blockly.utils.Coordinate = function(x, y) { +const Coordinate = function(x, y) { /** * X-value * @type {number} @@ -42,11 +42,11 @@ Blockly.utils.Coordinate = function(x, y) { /** * Compares coordinates for equality. - * @param {?Blockly.utils.Coordinate} a A Coordinate. - * @param {?Blockly.utils.Coordinate} b A Coordinate. + * @param {?Coordinate} a A Coordinate. + * @param {?Coordinate} b A Coordinate. * @return {boolean} True iff the coordinates are equal, or if both are null. */ -Blockly.utils.Coordinate.equals = function(a, b) { +Coordinate.equals = function(a, b) { if (a == b) { return true; } @@ -58,11 +58,11 @@ Blockly.utils.Coordinate.equals = function(a, b) { /** * Returns the distance between two coordinates. - * @param {!Blockly.utils.Coordinate} a A Coordinate. - * @param {!Blockly.utils.Coordinate} b A Coordinate. + * @param {!Coordinate} a A Coordinate. + * @param {!Coordinate} b A Coordinate. * @return {number} The distance between `a` and `b`. */ -Blockly.utils.Coordinate.distance = function(a, b) { +Coordinate.distance = function(a, b) { const dx = a.x - b.x; const dy = a.y - b.y; return Math.sqrt(dx * dx + dy * dy); @@ -70,50 +70,50 @@ Blockly.utils.Coordinate.distance = function(a, b) { /** * Returns the magnitude of a coordinate. - * @param {!Blockly.utils.Coordinate} a A Coordinate. + * @param {!Coordinate} a A Coordinate. * @return {number} The distance between the origin and `a`. */ -Blockly.utils.Coordinate.magnitude = function(a) { +Coordinate.magnitude = function(a) { return Math.sqrt(a.x * a.x + a.y * a.y); }; /** * Returns the difference between two coordinates as a new - * Blockly.utils.Coordinate. - * @param {!Blockly.utils.Coordinate|!SVGPoint} a An x/y coordinate. - * @param {!Blockly.utils.Coordinate|!SVGPoint} b An x/y coordinate. - * @return {!Blockly.utils.Coordinate} A Coordinate representing the difference + * Coordinate. + * @param {!Coordinate|!SVGPoint} a An x/y coordinate. + * @param {!Coordinate|!SVGPoint} b An x/y coordinate. + * @return {!Coordinate} A Coordinate representing the difference * between `a` and `b`. */ -Blockly.utils.Coordinate.difference = function(a, b) { - return new Blockly.utils.Coordinate(a.x - b.x, a.y - b.y); +Coordinate.difference = function(a, b) { + return new Coordinate(a.x - b.x, a.y - b.y); }; /** - * Returns the sum of two coordinates as a new Blockly.utils.Coordinate. - * @param {!Blockly.utils.Coordinate|!SVGPoint} a An x/y coordinate. - * @param {!Blockly.utils.Coordinate|!SVGPoint} b An x/y coordinate. - * @return {!Blockly.utils.Coordinate} A Coordinate representing the sum of + * Returns the sum of two coordinates as a new Coordinate. + * @param {!Coordinate|!SVGPoint} a An x/y coordinate. + * @param {!Coordinate|!SVGPoint} b An x/y coordinate. + * @return {!Coordinate} A Coordinate representing the sum of * the two coordinates. */ -Blockly.utils.Coordinate.sum = function(a, b) { - return new Blockly.utils.Coordinate(a.x + b.x, a.y + b.y); +Coordinate.sum = function(a, b) { + return new Coordinate(a.x + b.x, a.y + b.y); }; /** * Creates a new copy of this coordinate. - * @return {!Blockly.utils.Coordinate} A copy of this coordinate. + * @return {!Coordinate} A copy of this coordinate. */ -Blockly.utils.Coordinate.prototype.clone = function() { - return new Blockly.utils.Coordinate(this.x, this.y); +Coordinate.prototype.clone = function() { + return new Coordinate(this.x, this.y); }; /** * Scales this coordinate by the given scale factor. * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Blockly.utils.Coordinate} This coordinate after scaling. + * @return {!Coordinate} This coordinate after scaling. */ -Blockly.utils.Coordinate.prototype.scale = function(s) { +Coordinate.prototype.scale = function(s) { this.x *= s; this.y *= s; return this; @@ -124,10 +124,12 @@ Blockly.utils.Coordinate.prototype.scale = function(s) { * respectively. * @param {number} tx The value to translate x by. * @param {number} ty The value to translate y by. - * @return {!Blockly.utils.Coordinate} This coordinate after translating. + * @return {!Coordinate} This coordinate after translating. */ -Blockly.utils.Coordinate.prototype.translate = function(tx, ty) { +Coordinate.prototype.translate = function(tx, ty) { this.x += tx; this.y += ty; return this; }; + +exports = Coordinate; diff --git a/tests/deps.js b/tests/deps.js index 052655acd..c9321eaf9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -171,7 +171,7 @@ goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.Com goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); +goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); From 19e86ed5dbca92be79e9d6de17454922b5e7d22c Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:52:13 -0700 Subject: [PATCH 054/313] Migrate core/interfaces/i_block_dragger.js to goog.module --- core/interfaces/i_block_dragger.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/interfaces/i_block_dragger.js b/core/interfaces/i_block_dragger.js index ec7b79ac6..2276c7459 100644 --- a/core/interfaces/i_block_dragger.js +++ b/core/interfaces/i_block_dragger.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IBlockDragger'); +goog.module('Blockly.IBlockDragger'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.utils.Coordinate'); @@ -21,7 +22,7 @@ goog.requireType('Blockly.utils.Coordinate'); * A block dragger interface. * @interface */ -Blockly.IBlockDragger = function() {}; +const IBlockDragger = function() {}; /** * Start dragging a block. This includes moving it to the drag surface. @@ -30,7 +31,7 @@ Blockly.IBlockDragger = function() {}; * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. */ -Blockly.IBlockDragger.prototype.startDrag; +IBlockDragger.prototype.startDrag; /** * Execute a step of block dragging, based on the given event. Update the @@ -39,7 +40,7 @@ Blockly.IBlockDragger.prototype.startDrag; * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. */ -Blockly.IBlockDragger.prototype.drag; +IBlockDragger.prototype.drag; /** * Finish a block drag and put the block back on the workspace. @@ -47,7 +48,7 @@ Blockly.IBlockDragger.prototype.drag; * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. */ -Blockly.IBlockDragger.prototype.endDrag; +IBlockDragger.prototype.endDrag; /** * Get a list of the insertion markers that currently exist. Drags have 0, 1, @@ -55,4 +56,6 @@ Blockly.IBlockDragger.prototype.endDrag; * @return {!Array.} A possibly empty list of insertion * marker blocks. */ -Blockly.IBlockDragger.prototype.getInsertionMarkers; +IBlockDragger.prototype.getInsertionMarkers; + +exports = IBlockDragger; diff --git a/tests/deps.js b/tests/deps.js index c9321eaf9..5a06dd4ae 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_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); -goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], []); +goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], []); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], []); From 88525f5ab4aeb0d4ddef54b2f7aba6b67c42eab0 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:54:26 -0700 Subject: [PATCH 055/313] Migrate core/interfaces/i_block_dragger.js named requires --- core/interfaces/i_block_dragger.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/interfaces/i_block_dragger.js b/core/interfaces/i_block_dragger.js index 2276c7459..ebfc820ba 100644 --- a/core/interfaces/i_block_dragger.js +++ b/core/interfaces/i_block_dragger.js @@ -14,8 +14,8 @@ goog.module('Blockly.IBlockDragger'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.utils.Coordinate'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); /** @@ -26,7 +26,7 @@ const IBlockDragger = function() {}; /** * Start dragging a block. This includes moving it to the drag surface. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. @@ -37,7 +37,7 @@ IBlockDragger.prototype.startDrag; * Execute a step of block 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. */ IBlockDragger.prototype.drag; @@ -45,7 +45,7 @@ IBlockDragger.prototype.drag; /** * Finish a block drag and put the block 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. */ IBlockDragger.prototype.endDrag; @@ -53,7 +53,7 @@ IBlockDragger.prototype.endDrag; /** * Get a list of the insertion markers that currently exist. Drags have 0, 1, * or 2 insertion markers. - * @return {!Array.} A possibly empty list of insertion + * @return {!Array.} A possibly empty list of insertion * marker blocks. */ IBlockDragger.prototype.getInsertionMarkers; From e922d2a831ea76bcf1c2ddc10f3ad3f2ce8e12a9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:05:21 -0700 Subject: [PATCH 056/313] Migrate core/interfaces/i_bounded_element.js to goog.module --- core/interfaces/i_bounded_element.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_bounded_element.js b/core/interfaces/i_bounded_element.js index bc5ffeee6..fdbeb5b99 100644 --- a/core/interfaces/i_bounded_element.js +++ b/core/interfaces/i_bounded_element.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IBoundedElement'); +goog.module('Blockly.IBoundedElement'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.utils.Rect'); @@ -20,7 +21,7 @@ goog.requireType('Blockly.utils.Rect'); * A bounded element interface. * @interface */ -Blockly.IBoundedElement = function() {}; +const IBoundedElement = function() {}; /** * Returns the coordinates of a bounded element describing the dimensions of the @@ -28,11 +29,13 @@ Blockly.IBoundedElement = function() {}; * Coordinate system: workspace coordinates. * @return {!Blockly.utils.Rect} Object with coordinates of the bounded element. */ -Blockly.IBoundedElement.prototype.getBoundingRectangle; +IBoundedElement.prototype.getBoundingRectangle; /** * Move the element by a relative offset. * @param {number} dx Horizontal offset in workspace units. * @param {number} dy Vertical offset in workspace units. */ -Blockly.IBoundedElement.prototype.moveBy; +IBoundedElement.prototype.moveBy; + +exports = IBoundedElement; diff --git a/tests/deps.js b/tests/deps.js index 5a06dd4ae..ac9153ec9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -76,7 +76,7 @@ goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.Insertion goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); 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'], []); +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_component.js', ['Blockly.IComponent'], []); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); From bfc801ed9f9baa9ff37894dea9ecf88a7fdb2cd1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:05:45 -0700 Subject: [PATCH 057/313] Migrate core/interfaces/i_bounded_element.js named requires --- core/interfaces/i_bounded_element.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_bounded_element.js b/core/interfaces/i_bounded_element.js index fdbeb5b99..461d52ca1 100644 --- a/core/interfaces/i_bounded_element.js +++ b/core/interfaces/i_bounded_element.js @@ -14,7 +14,7 @@ goog.module('Blockly.IBoundedElement'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.utils.Rect'); +const Rect = goog.requireType('Blockly.utils.Rect'); /** @@ -27,7 +27,7 @@ const IBoundedElement = function() {}; * Returns the coordinates of a bounded element describing the dimensions of the * element. * Coordinate system: workspace coordinates. - * @return {!Blockly.utils.Rect} Object with coordinates of the bounded element. + * @return {!Rect} Object with coordinates of the bounded element. */ IBoundedElement.prototype.getBoundingRectangle; From 4ab9380434d6a435c65a8adcf46d48d5e90fd5f6 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:33:07 -0700 Subject: [PATCH 058/313] Migrate core/interfaces/i_component.js to goog.module --- core/interfaces/i_component.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_component.js b/core/interfaces/i_component.js index efb195966..d1acc592f 100644 --- a/core/interfaces/i_component.js +++ b/core/interfaces/i_component.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IComponent'); +goog.module('Blockly.IComponent'); +goog.module.declareLegacyNamespace(); /** @@ -20,11 +21,13 @@ goog.provide('Blockly.IComponent'); * ComponentManager. * @interface */ -Blockly.IComponent = function() {}; +const IComponent = function() {}; /** * The unique id for this component that is used to register with the * ComponentManager. * @type {string} */ -Blockly.IComponent.id; +IComponent.id; + +exports = IComponent; diff --git a/tests/deps.js b/tests/deps.js index ac9153ec9..ed2af0dc9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -78,7 +78,7 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid 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_component.js', ['Blockly.IComponent'], []); +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'], []); From 218046495f052fb7400f7afb736e52bfa0626618 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 13:12:05 -0700 Subject: [PATCH 059/313] Sort requires --- core/renderers/common/drawer.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index a0181bf8f..9504695a2 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,16 +13,15 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); -const Row = goog.require('Blockly.blockRendering.Row'); -const Types = goog.require('Blockly.blockRendering.Types'); -const svgPaths = goog.require('Blockly.utils.svgPaths'); - +const BlockSvg = goog.requireType('Blockly.BlockSvg'); const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); const Field = goog.requireType('Blockly.blockRendering.Field'); const Icon = goog.requireType('Blockly.blockRendering.Icon'); const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); const RenderInfo = goog.requireType('Blockly.blockRendering.RenderInfo'); -const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Row = goog.require('Blockly.blockRendering.Row'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); +const Types = goog.require('Blockly.blockRendering.Types'); /** From a2d12a1536a1cf223bab1ba40a4f1027b41c5263 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:00:31 -0700 Subject: [PATCH 060/313] Migrate core/interfaces/i_deletable.js to goog.module --- core/interfaces/i_deletable.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_deletable.js b/core/interfaces/i_deletable.js index 8e8524863..ff24023d9 100644 --- a/core/interfaces/i_deletable.js +++ b/core/interfaces/i_deletable.js @@ -11,17 +11,20 @@ 'use strict'; -goog.provide('Blockly.IDeletable'); +goog.module('Blockly.IDeletable'); +goog.module.declareLegacyNamespace(); /** * The interface for an object that can be deleted. * @interface */ -Blockly.IDeletable = function() {}; +const IDeletable = function() {}; /** * Get whether this object is deletable or not. * @return {boolean} True if deletable. */ -Blockly.IDeletable.prototype.isDeletable; +IDeletable.prototype.isDeletable; + +exports = IDeletable; diff --git a/tests/deps.js b/tests/deps.js index ed2af0dc9..5ab286fc5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -82,7 +82,7 @@ goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent' 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_deletable.js', ['Blockly.IDeletable'], []); +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']); goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable']); From fa158d143ec4f74a759557b232ae9d959401e122 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:48:33 -0700 Subject: [PATCH 061/313] Migrate core/connection.js to ES6 const/let --- core/connection.js | 82 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/core/connection.js b/core/connection.js index 27526c711..23d2193bd 100644 --- a/core/connection.js +++ b/core/connection.js @@ -104,10 +104,10 @@ Blockly.Connection.prototype.y = 0; * @protected */ Blockly.Connection.prototype.connect_ = function(childConnection) { - var INPUT = Blockly.connectionTypes.INPUT_VALUE; - var parentConnection = this; - var parentBlock = parentConnection.getSourceBlock(); - var childBlock = childConnection.getSourceBlock(); + const INPUT = Blockly.connectionTypes.INPUT_VALUE; + const parentConnection = this; + const parentBlock = parentConnection.getSourceBlock(); + const childBlock = childConnection.getSourceBlock(); // Make sure the childConnection is available. if (childConnection.isConnected()) { @@ -115,11 +115,11 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { } // Make sure the parentConnection is available. - var orphan; + let orphan; if (parentConnection.isConnected()) { - var shadowDom = parentConnection.getShadowDom(true); + const shadowDom = parentConnection.getShadowDom(true); parentConnection.shadowDom_ = null; // Set to null so it doesn't respawn. - var target = parentConnection.targetBlock(); + const target = parentConnection.targetBlock(); if (target.isShadow()) { target.dispose(false); } else { @@ -130,7 +130,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { } // Connect the new connection to the parent. - var event; + let event; if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } @@ -143,9 +143,9 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { // Deal with the orphan if it exists. if (orphan) { - var orphanConnection = parentConnection.type === INPUT ? + const orphanConnection = parentConnection.type === INPUT ? orphan.outputConnection : orphan.previousConnection; - var connection = Blockly.Connection.getConnectionForOrphanedConnection( + const connection = Blockly.Connection.getConnectionForOrphanedConnection( childBlock, /** @type {!Blockly.Connection} */ (orphanConnection)); if (connection) { orphanConnection.connect(connection); @@ -167,7 +167,7 @@ Blockly.Connection.prototype.dispose = function() { // Destroy the attached shadow block & its children (if it exists). this.setShadowDom(null); - var targetBlock = this.targetBlock(); + const targetBlock = this.targetBlock(); if (targetBlock) { // Disconnect the attached normal block. targetBlock.unplug(); @@ -236,8 +236,8 @@ Blockly.Connection.prototype.checkConnection = function(target) { 'July 2020', 'July 2021', 'the workspace\'s connection checker'); - var checker = this.getConnectionChecker(); - var reason = checker.canConnectWithReason(this, target, false); + const checker = this.getConnectionChecker(); + const reason = checker.canConnectWithReason(this, target, false); if (reason != Blockly.Connection.CAN_CONNECT) { throw new Error(checker.getErrorMessage(reason, this, target)); } @@ -290,9 +290,9 @@ Blockly.Connection.prototype.connect = function(otherConnection) { return; } - var checker = this.getConnectionChecker(); + const checker = this.getConnectionChecker(); if (checker.canConnect(this, otherConnection, false)) { - var eventGroup = Blockly.Events.getGroup(); + const eventGroup = Blockly.Events.getGroup(); if (!eventGroup) { Blockly.Events.setGroup(true); } @@ -336,12 +336,12 @@ Blockly.Connection.connectReciprocally_ = function(first, second) { * @private */ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { - var foundConnection = null; - var output = orphanBlock.outputConnection; - var typeChecker = output.getConnectionChecker(); + let foundConnection = null; + const output = orphanBlock.outputConnection; + const typeChecker = output.getConnectionChecker(); - for (var i = 0, input; (input = block.inputList[i]); i++) { - var connection = input.connection; + for (let i = 0, input; (input = block.inputList[i]); i++) { + const connection = input.connection; if (connection && typeChecker.canConnect(output, connection, false)) { if (foundConnection) { return null; // More than one connection. @@ -366,8 +366,8 @@ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { */ Blockly.Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { - var newBlock = startBlock; - var connection; + let newBlock = startBlock; + let connection; while ((connection = Blockly.Connection.getSingleConnection_( /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); @@ -395,8 +395,8 @@ Blockly.Connection.getConnectionForOrphanedConnection = startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. - var connection = startBlock.lastConnectionInStack(true); - var checker = orphanConnection.getConnectionChecker(); + const connection = startBlock.lastConnectionInStack(true); + const checker = orphanConnection.getConnectionChecker(); if (connection && checker.canConnect(orphanConnection, connection, false)) { return connection; @@ -408,14 +408,14 @@ Blockly.Connection.getConnectionForOrphanedConnection = * Disconnect this connection. */ Blockly.Connection.prototype.disconnect = function() { - var otherConnection = this.targetConnection; + const otherConnection = this.targetConnection; if (!otherConnection) { throw Error('Source connection not connected.'); } if (otherConnection.targetConnection != this) { throw Error('Target connection not connected to source connection.'); } - var parentBlock, childBlock, parentConnection; + let parentBlock, childBlock, parentConnection; if (this.isSuperior()) { // Superior block. parentBlock = this.sourceBlock_; @@ -428,7 +428,7 @@ Blockly.Connection.prototype.disconnect = function() { parentConnection = otherConnection; } - var eventGroup = Blockly.Events.getGroup(); + const eventGroup = Blockly.Events.getGroup(); if (!eventGroup) { Blockly.Events.setGroup(true); } @@ -450,11 +450,11 @@ Blockly.Connection.prototype.disconnect = function() { */ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { - var event; + let event; if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } - var otherConnection = this.targetConnection; + const otherConnection = this.targetConnection; otherConnection.targetConnection = null; this.targetConnection = null; childBlock.setParent(null); @@ -469,10 +469,10 @@ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, * @protected */ Blockly.Connection.prototype.respawnShadow_ = function() { - var parentBlock = this.getSourceBlock(); - var shadow = this.getShadowDom(); + const parentBlock = this.getSourceBlock(); + const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { - var blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); + const blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); if (blockShadow.outputConnection) { this.connect(blockShadow.outputConnection); } else if (blockShadow.previousConnection) { @@ -540,7 +540,7 @@ Blockly.Connection.prototype.onCheckChanged_ = function() { if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( this, this.targetConnection, false))) { - var child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; + const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child.unplug(); } }; @@ -582,7 +582,7 @@ Blockly.Connection.prototype.getCheck = function() { */ Blockly.Connection.prototype.setShadowDom = function(shadow) { this.shadowDom_ = shadow; - var target = this.targetBlock(); + const target = this.targetBlock(); if (!target) { this.respawnShadow_(); } else if (target.isShadow()) { @@ -630,9 +630,9 @@ Blockly.Connection.prototype.neighbours = function(_maxLimit) { * @package */ Blockly.Connection.prototype.getParentInput = function() { - var parentInput = null; - var inputs = this.sourceBlock_.inputList; - for (var i = 0; i < inputs.length; i++) { + let parentInput = null; + const inputs = this.sourceBlock_.inputList; + for (let i = 0; i < inputs.length; i++) { if (inputs[i].connection === this) { parentInput = inputs[i]; break; @@ -647,11 +647,11 @@ Blockly.Connection.prototype.getParentInput = function() { * @return {string} The description. */ Blockly.Connection.prototype.toString = function() { - var block = this.sourceBlock_; + const block = this.sourceBlock_; if (!block) { return 'Orphan Connection'; } - var msg; + let msg; if (block.outputConnection == this) { msg = 'Output Connection of '; } else if (block.previousConnection == this) { @@ -659,8 +659,8 @@ Blockly.Connection.prototype.toString = function() { } else if (block.nextConnection == this) { msg = 'Next Connection of '; } else { - var parentInput = null; - for (var i = 0, input; (input = block.inputList[i]); i++) { + let parentInput = null; + for (let i = 0, input; (input = block.inputList[i]); i++) { if (input.connection == this) { parentInput = input; break; From fc62fed33c94564449d521644bc0d44dbca739f9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:55:08 -0700 Subject: [PATCH 062/313] Migrate core/connection.js to goog.module --- core/connection.js | 141 +++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 73 insertions(+), 70 deletions(-) diff --git a/core/connection.js b/core/connection.js index 23d2193bd..be9a08eb9 100644 --- a/core/connection.js +++ b/core/connection.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Connection'); +goog.module('Blockly.Connection'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ @@ -34,7 +35,7 @@ goog.requireType('Blockly.Input'); * @constructor * @implements {Blockly.IASTNodeLocationWithBlock} */ -Blockly.Connection = function(source, type) { +const Connection = function(source, type) { /** * @type {!Blockly.Block} * @protected @@ -47,63 +48,63 @@ Blockly.Connection = function(source, type) { /** * Constants for checking whether two connections are compatible. */ -Blockly.Connection.CAN_CONNECT = 0; -Blockly.Connection.REASON_SELF_CONNECTION = 1; -Blockly.Connection.REASON_WRONG_TYPE = 2; -Blockly.Connection.REASON_TARGET_NULL = 3; -Blockly.Connection.REASON_CHECKS_FAILED = 4; -Blockly.Connection.REASON_DIFFERENT_WORKSPACES = 5; -Blockly.Connection.REASON_SHADOW_PARENT = 6; -Blockly.Connection.REASON_DRAG_CHECKS_FAILED = 7; +Connection.CAN_CONNECT = 0; +Connection.REASON_SELF_CONNECTION = 1; +Connection.REASON_WRONG_TYPE = 2; +Connection.REASON_TARGET_NULL = 3; +Connection.REASON_CHECKS_FAILED = 4; +Connection.REASON_DIFFERENT_WORKSPACES = 5; +Connection.REASON_SHADOW_PARENT = 6; +Connection.REASON_DRAG_CHECKS_FAILED = 7; /** * Connection this connection connects to. Null if not connected. - * @type {Blockly.Connection} + * @type {Connection} */ -Blockly.Connection.prototype.targetConnection = null; +Connection.prototype.targetConnection = null; /** * Has this connection been disposed of? * @type {boolean} * @package */ -Blockly.Connection.prototype.disposed = false; +Connection.prototype.disposed = false; /** * List of compatible value types. Null if all types are compatible. * @type {Array} * @private */ -Blockly.Connection.prototype.check_ = null; +Connection.prototype.check_ = null; /** * DOM representation of a shadow block, or null if none. * @type {Element} * @private */ -Blockly.Connection.prototype.shadowDom_ = null; +Connection.prototype.shadowDom_ = null; /** * Horizontal location of this connection. * @type {number} * @package */ -Blockly.Connection.prototype.x = 0; +Connection.prototype.x = 0; /** * Vertical location of this connection. * @type {number} * @package */ -Blockly.Connection.prototype.y = 0; +Connection.prototype.y = 0; /** * Connect two connections together. This is the connection on the superior * block. - * @param {!Blockly.Connection} childConnection Connection on inferior block. + * @param {!Connection} childConnection Connection on inferior block. * @protected */ -Blockly.Connection.prototype.connect_ = function(childConnection) { +Connection.prototype.connect_ = function(childConnection) { const INPUT = Blockly.connectionTypes.INPUT_VALUE; const parentConnection = this; const parentBlock = parentConnection.getSourceBlock(); @@ -134,7 +135,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } - Blockly.Connection.connectReciprocally_(parentConnection, childConnection); + Connection.connectReciprocally_(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); @@ -145,8 +146,8 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { if (orphan) { const orphanConnection = parentConnection.type === INPUT ? orphan.outputConnection : orphan.previousConnection; - const connection = Blockly.Connection.getConnectionForOrphanedConnection( - childBlock, /** @type {!Blockly.Connection} */ (orphanConnection)); + const connection = Connection.getConnectionForOrphanedConnection( + childBlock, /** @type {!Connection} */ (orphanConnection)); if (connection) { orphanConnection.connect(connection); } else { @@ -160,7 +161,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { * Dispose of this connection and deal with connected blocks. * @package */ -Blockly.Connection.prototype.dispose = function() { +Connection.prototype.dispose = function() { // isConnected returns true for shadows and non-shadows. if (this.isConnected()) { @@ -181,7 +182,7 @@ Blockly.Connection.prototype.dispose = function() { * Get the source block for this connection. * @return {!Blockly.Block} The source block. */ -Blockly.Connection.prototype.getSourceBlock = function() { +Connection.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -189,7 +190,7 @@ Blockly.Connection.prototype.getSourceBlock = function() { * Does the connection belong to a superior block (higher in the source stack)? * @return {boolean} True if connection faces down or right. */ -Blockly.Connection.prototype.isSuperior = function() { +Connection.prototype.isSuperior = function() { return this.type == Blockly.connectionTypes.INPUT_VALUE || this.type == Blockly.connectionTypes.NEXT_STATEMENT; }; @@ -198,20 +199,20 @@ Blockly.Connection.prototype.isSuperior = function() { * Is the connection connected? * @return {boolean} True if connection is connected to another connection. */ -Blockly.Connection.prototype.isConnected = function() { +Connection.prototype.isConnected = function() { return !!this.targetConnection; }; /** * Checks whether the current connection can connect with the target * connection. - * @param {Blockly.Connection} target Connection to check compatibility with. - * @return {number} Blockly.Connection.CAN_CONNECT if the connection is legal, + * @param {Connection} target Connection to check compatibility with. + * @return {number} Connection.CAN_CONNECT if the connection is legal, * an error code otherwise. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.canConnectWithReason = function(target) { +Connection.prototype.canConnectWithReason = function(target) { Blockly.utils.deprecation.warn( 'Connection.prototype.canConnectWithReason', 'July 2020', @@ -224,13 +225,13 @@ Blockly.Connection.prototype.canConnectWithReason = function(target) { /** * Checks whether the current connection and target connection are compatible * and throws an exception if they are not. - * @param {Blockly.Connection} target The connection to check compatibility + * @param {Connection} target The connection to check compatibility * with. * @package * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.checkConnection = function(target) { +Connection.prototype.checkConnection = function(target) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkConnection', 'July 2020', @@ -238,7 +239,7 @@ Blockly.Connection.prototype.checkConnection = function(target) { 'the workspace\'s connection checker'); const checker = this.getConnectionChecker(); const reason = checker.canConnectWithReason(this, target, false); - if (reason != Blockly.Connection.CAN_CONNECT) { + if (reason != Connection.CAN_CONNECT) { throw new Error(checker.getErrorMessage(reason, this, target)); } }; @@ -249,18 +250,18 @@ Blockly.Connection.prototype.checkConnection = function(target) { * source block's workspace. * @package */ -Blockly.Connection.prototype.getConnectionChecker = function() { +Connection.prototype.getConnectionChecker = function() { return this.sourceBlock_.workspace.connectionChecker; }; /** * Check if the two connections can be dragged to connect to each other. - * @param {!Blockly.Connection} candidate A nearby connection to check. + * @param {!Connection} candidate A nearby connection to check. * @return {boolean} True if the connection is allowed, false otherwise. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.isConnectionAllowed = function(candidate) { +Connection.prototype.isConnectionAllowed = function(candidate) { Blockly.utils.deprecation.warn( 'Connection.prototype.isConnectionAllowed', 'July 2020', @@ -272,19 +273,19 @@ Blockly.Connection.prototype.isConnectionAllowed = function(candidate) { /** * Called when an attempted connection fails. NOP by default (i.e. for headless * workspaces). - * @param {!Blockly.Connection} _otherConnection Connection that this connection + * @param {!Connection} _otherConnection Connection that this connection * failed to connect to. * @package */ -Blockly.Connection.prototype.onFailedConnect = function(_otherConnection) { +Connection.prototype.onFailedConnect = function(_otherConnection) { // NOP }; /** * Connect this connection to another connection. - * @param {!Blockly.Connection} otherConnection Connection to connect to. + * @param {!Connection} otherConnection Connection to connect to. */ -Blockly.Connection.prototype.connect = function(otherConnection) { +Connection.prototype.connect = function(otherConnection) { if (this.targetConnection == otherConnection) { // Already connected together. NOP. return; @@ -312,11 +313,11 @@ Blockly.Connection.prototype.connect = function(otherConnection) { /** * Update two connections to target each other. - * @param {Blockly.Connection} first The first connection to update. - * @param {Blockly.Connection} second The second connection to update. + * @param {Connection} first The first connection to update. + * @param {Connection} second The second connection to update. * @private */ -Blockly.Connection.connectReciprocally_ = function(first, second) { +Connection.connectReciprocally_ = function(first, second) { if (!first || !second) { throw Error('Cannot connect null connections.'); } @@ -331,11 +332,11 @@ Blockly.Connection.connectReciprocally_ = function(first, second) { * connections, this returns null. * @param {!Blockly.Block} block The superior block. * @param {!Blockly.Block} orphanBlock The inferior block. - * @return {?Blockly.Connection} The suitable connection point on 'block', + * @return {?Connection} The suitable connection point on 'block', * or null. * @private */ -Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { +Connection.getSingleConnection_ = function(block, orphanBlock) { let foundConnection = null; const output = orphanBlock.outputConnection; const typeChecker = output.getConnectionChecker(); @@ -360,15 +361,15 @@ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { * Terminates early for shadow blocks. * @param {!Blockly.Block} startBlock The block on which to start the search. * @param {!Blockly.Block} orphanBlock The block that is looking for a home. - * @return {?Blockly.Connection} The suitable connection point on the chain + * @return {?Connection} The suitable connection point on the chain * of blocks, or null. * @private */ -Blockly.Connection.getConnectionForOrphanedOutput_ = +Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { let newBlock = startBlock; let connection; - while ((connection = Blockly.Connection.getSingleConnection_( + while ((connection = Connection.getSingleConnection_( /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { @@ -383,15 +384,15 @@ Blockly.Connection.getConnectionForOrphanedOutput_ = * the given connection. This includes compatible connection types and * connection checks. * @param {!Blockly.Block} startBlock The block on which to start the search. - * @param {!Blockly.Connection} orphanConnection The connection that is looking + * @param {!Connection} orphanConnection The connection that is looking * for a home. - * @return {?Blockly.Connection} The suitable connection point on the chain of + * @return {?Connection} The suitable connection point on the chain of * blocks, or null. */ -Blockly.Connection.getConnectionForOrphanedConnection = +Connection.getConnectionForOrphanedConnection = function(startBlock, orphanConnection) { if (orphanConnection.type === Blockly.connectionTypes.OUTPUT_VALUE) { - return Blockly.Connection.getConnectionForOrphanedOutput_( + return Connection.getConnectionForOrphanedOutput_( startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. @@ -407,7 +408,7 @@ Blockly.Connection.getConnectionForOrphanedConnection = /** * Disconnect this connection. */ -Blockly.Connection.prototype.disconnect = function() { +Connection.prototype.disconnect = function() { const otherConnection = this.targetConnection; if (!otherConnection) { throw Error('Source connection not connected.'); @@ -448,7 +449,7 @@ Blockly.Connection.prototype.disconnect = function() { * @param {!Blockly.Block} childBlock The inferior block. * @protected */ -Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, +Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; if (Blockly.Events.isEnabled()) { @@ -468,7 +469,7 @@ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, * Respawn the shadow block if there was one connected to the this connection. * @protected */ -Blockly.Connection.prototype.respawnShadow_ = function() { +Connection.prototype.respawnShadow_ = function() { const parentBlock = this.getSourceBlock(); const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { @@ -487,7 +488,7 @@ Blockly.Connection.prototype.respawnShadow_ = function() { * Returns the block that this connection connects to. * @return {?Blockly.Block} The connected block or null if none is connected. */ -Blockly.Connection.prototype.targetBlock = function() { +Connection.prototype.targetBlock = function() { if (this.isConnected()) { return this.targetConnection.getSourceBlock(); } @@ -497,12 +498,12 @@ Blockly.Connection.prototype.targetBlock = function() { /** * Is this connection compatible with another connection with respect to the * value type system. E.g. square_root("Hello") is not compatible. - * @param {!Blockly.Connection} otherConnection Connection to compare against. + * @param {!Connection} otherConnection Connection to compare against. * @return {boolean} True if the connections share a type. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.checkType = function(otherConnection) { +Connection.prototype.checkType = function(otherConnection) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkType', 'October 2019', @@ -515,14 +516,14 @@ Blockly.Connection.prototype.checkType = function(otherConnection) { /** * Is this connection compatible with another connection with respect to the * value type system. E.g. square_root("Hello") is not compatible. - * @param {!Blockly.Connection} otherConnection Connection to compare against. + * @param {!Connection} otherConnection Connection to compare against. * @return {boolean} True if the connections share a type. * @private * @deprecated October 2019. Will be deleted January 2021. Use the workspace's * connectionChecker instead. * @suppress {unusedPrivateMembers} */ -Blockly.Connection.prototype.checkType_ = function(otherConnection) { +Connection.prototype.checkType_ = function(otherConnection) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkType_', 'October 2019', @@ -535,7 +536,7 @@ Blockly.Connection.prototype.checkType_ = function(otherConnection) { * Function to be called when this connection's compatible types have changed. * @protected */ -Blockly.Connection.prototype.onCheckChanged_ = function() { +Connection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( @@ -549,10 +550,10 @@ Blockly.Connection.prototype.onCheckChanged_ = function() { * Change a connection's compatibility. * @param {?(string|!Array)} check Compatible value type or list of * value types. Null if all types are compatible. - * @return {!Blockly.Connection} The connection being modified + * @return {!Connection} The connection being modified * (to allow chaining). */ -Blockly.Connection.prototype.setCheck = function(check) { +Connection.prototype.setCheck = function(check) { if (check) { // Ensure that check is in an array. if (!Array.isArray(check)) { @@ -572,7 +573,7 @@ Blockly.Connection.prototype.setCheck = function(check) { * Null if all types are compatible. * @public */ -Blockly.Connection.prototype.getCheck = function() { +Connection.prototype.getCheck = function() { return this.check_; }; @@ -580,7 +581,7 @@ Blockly.Connection.prototype.getCheck = function() { * Changes the connection's shadow block. * @param {?Element} shadow DOM representation of a block or null. */ -Blockly.Connection.prototype.setShadowDom = function(shadow) { +Connection.prototype.setShadowDom = function(shadow) { this.shadowDom_ = shadow; const target = this.targetBlock(); if (!target) { @@ -600,7 +601,7 @@ Blockly.Connection.prototype.setShadowDom = function(shadow) { * shadowDom is just returned. * @return {?Element} Shadow DOM representation of a block or null. */ -Blockly.Connection.prototype.getShadowDom = function(returnCurrent) { +Connection.prototype.getShadowDom = function(returnCurrent) { return (returnCurrent && this.targetBlock().isShadow()) ? /** @type {!Element} */ (Blockly.Xml.blockToDom( /** @type {!Blockly.Block} */ (this.targetBlock()))) : @@ -616,10 +617,10 @@ Blockly.Connection.prototype.getShadowDom = function(returnCurrent) { * {@link Blockly.RenderedConnection} overrides this behavior with a list * computed from the rendered positioning. * @param {number} _maxLimit The maximum radius to another connection. - * @return {!Array} List of connections. + * @return {!Array} List of connections. * @package */ -Blockly.Connection.prototype.neighbours = function(_maxLimit) { +Connection.prototype.neighbours = function(_maxLimit) { return []; }; @@ -629,7 +630,7 @@ Blockly.Connection.prototype.neighbours = function(_maxLimit) { * no parent exists. * @package */ -Blockly.Connection.prototype.getParentInput = function() { +Connection.prototype.getParentInput = function() { let parentInput = null; const inputs = this.sourceBlock_.inputList; for (let i = 0; i < inputs.length; i++) { @@ -646,7 +647,7 @@ Blockly.Connection.prototype.getParentInput = function() { * (English only). Intended to on be used in console logs and errors. * @return {string} The description. */ -Blockly.Connection.prototype.toString = function() { +Connection.prototype.toString = function() { const block = this.sourceBlock_; if (!block) { return 'Orphan Connection'; @@ -675,3 +676,5 @@ Blockly.Connection.prototype.toString = function() { } return msg + block.toDevString(); }; + +exports = Connection; diff --git a/tests/deps.js b/tests/deps.js index ed2af0dc9..b435a26ba 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -19,7 +19,7 @@ goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble 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/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.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); 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'}); From 8c0304ece883d9adc77b3f1c9445cf057aa8b50a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 14:02:44 -0700 Subject: [PATCH 063/313] Use pull request target trigger for tagging cleanup --- .github/workflows/tag_module_cleanup.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tag_module_cleanup.yml b/.github/workflows/tag_module_cleanup.yml index 2b14426ad..94e7ec692 100644 --- a/.github/workflows/tag_module_cleanup.yml +++ b/.github/workflows/tag_module_cleanup.yml @@ -4,8 +4,9 @@ name: Tag module cleanup # Trigger on pull requests against goog_module branch only +# Uses pull_request_target to get write permissions so that it can write labels. on: - pull_request: + pull_request_target: branches: - goog_module From 210fcea19889f19c008899e3f89a1837d76a8174 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:13:40 -0700 Subject: [PATCH 064/313] Migrate core/connection.js to named requires --- core/connection.js | 95 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/core/connection.js b/core/connection.js index be9a08eb9..0c7f54605 100644 --- a/core/connection.js +++ b/core/connection.js @@ -13,31 +13,30 @@ goog.module('Blockly.Connection'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const Block = goog.requireType('Blockly.Block'); +const deprecation = goog.require('Blockly.utils.deprecation'); +const Events = goog.require('Blockly.Events'); +const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +const Input = goog.requireType('Blockly.Input'); +const Xml = goog.require('Blockly.Xml'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -goog.require('Blockly.IASTNodeLocationWithBlock'); -goog.require('Blockly.utils.deprecation'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.IConnectionChecker'); -goog.requireType('Blockly.Input'); /** * Class for a connection between blocks. - * @param {!Blockly.Block} source The block establishing this connection. + * @param {!Block} source The block establishing this connection. * @param {number} type The type of the connection. * @constructor - * @implements {Blockly.IASTNodeLocationWithBlock} + * @implements {IASTNodeLocationWithBlock} */ const Connection = function(source, type) { /** - * @type {!Blockly.Block} + * @type {!Block} * @protected */ this.sourceBlock_ = source; @@ -105,7 +104,7 @@ Connection.prototype.y = 0; * @protected */ Connection.prototype.connect_ = function(childConnection) { - const INPUT = Blockly.connectionTypes.INPUT_VALUE; + const INPUT = connectionTypes.INPUT_VALUE; const parentConnection = this; const parentBlock = parentConnection.getSourceBlock(); const childBlock = childConnection.getSourceBlock(); @@ -132,14 +131,14 @@ Connection.prototype.connect_ = function(childConnection) { // Connect the new connection to the parent. let event; - if (Blockly.Events.isEnabled()) { - event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); + if (Events.isEnabled()) { + event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } Connection.connectReciprocally_(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); } // Deal with the orphan if it exists. @@ -180,7 +179,7 @@ Connection.prototype.dispose = function() { /** * Get the source block for this connection. - * @return {!Blockly.Block} The source block. + * @return {!Block} The source block. */ Connection.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -191,8 +190,8 @@ Connection.prototype.getSourceBlock = function() { * @return {boolean} True if connection faces down or right. */ Connection.prototype.isSuperior = function() { - return this.type == Blockly.connectionTypes.INPUT_VALUE || - this.type == Blockly.connectionTypes.NEXT_STATEMENT; + return this.type == connectionTypes.INPUT_VALUE || + this.type == connectionTypes.NEXT_STATEMENT; }; /** @@ -213,7 +212,7 @@ Connection.prototype.isConnected = function() { * connectionChecker instead. */ Connection.prototype.canConnectWithReason = function(target) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.canConnectWithReason', 'July 2020', 'July 2021', @@ -232,7 +231,7 @@ Connection.prototype.canConnectWithReason = function(target) { * connectionChecker instead. */ Connection.prototype.checkConnection = function(target) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkConnection', 'July 2020', 'July 2021', @@ -246,7 +245,7 @@ Connection.prototype.checkConnection = function(target) { /** * Get the workspace's connection type checker object. - * @return {!Blockly.IConnectionChecker} The connection type checker for the + * @return {!IConnectionChecker} The connection type checker for the * source block's workspace. * @package */ @@ -262,7 +261,7 @@ Connection.prototype.getConnectionChecker = function() { * connectionChecker instead. */ Connection.prototype.isConnectionAllowed = function(candidate) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', @@ -293,9 +292,9 @@ Connection.prototype.connect = function(otherConnection) { const checker = this.getConnectionChecker(); if (checker.canConnect(this, otherConnection, false)) { - const eventGroup = Blockly.Events.getGroup(); + const eventGroup = Events.getGroup(); if (!eventGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } // Determine which block is superior (higher in the source stack). if (this.isSuperior()) { @@ -306,7 +305,7 @@ Connection.prototype.connect = function(otherConnection) { otherConnection.connect_(this); } if (!eventGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } } }; @@ -330,8 +329,8 @@ Connection.connectReciprocally_ = function(first, second) { * block, if one can be found. If the block has multiple compatible connections * (even if they are filled) this returns null. If the block has no compatible * connections, this returns null. - * @param {!Blockly.Block} block The superior block. - * @param {!Blockly.Block} orphanBlock The inferior block. + * @param {!Block} block The superior block. + * @param {!Block} orphanBlock The inferior block. * @return {?Connection} The suitable connection point on 'block', * or null. * @private @@ -359,8 +358,8 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * are zero or multiple eligible connections, returns null. Otherwise * returns the only input on the last block in the chain. * Terminates early for shadow blocks. - * @param {!Blockly.Block} startBlock The block on which to start the search. - * @param {!Blockly.Block} orphanBlock The block that is looking for a home. + * @param {!Block} startBlock The block on which to start the search. + * @param {!Block} orphanBlock The block that is looking for a home. * @return {?Connection} The suitable connection point on the chain * of blocks, or null. * @private @@ -370,7 +369,7 @@ Connection.getConnectionForOrphanedOutput_ = let newBlock = startBlock; let connection; while ((connection = Connection.getSingleConnection_( - /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { + /** @type {!Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { return connection; @@ -383,7 +382,7 @@ Connection.getConnectionForOrphanedOutput_ = * Returns the connection (starting at the startBlock) which will accept * the given connection. This includes compatible connection types and * connection checks. - * @param {!Blockly.Block} startBlock The block on which to start the search. + * @param {!Block} startBlock The block on which to start the search. * @param {!Connection} orphanConnection The connection that is looking * for a home. * @return {?Connection} The suitable connection point on the chain of @@ -391,7 +390,7 @@ Connection.getConnectionForOrphanedOutput_ = */ Connection.getConnectionForOrphanedConnection = function(startBlock, orphanConnection) { - if (orphanConnection.type === Blockly.connectionTypes.OUTPUT_VALUE) { + if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { return Connection.getConnectionForOrphanedOutput_( startBlock, orphanConnection.getSourceBlock()); } @@ -429,9 +428,9 @@ Connection.prototype.disconnect = function() { parentConnection = otherConnection; } - const eventGroup = Blockly.Events.getGroup(); + const eventGroup = Events.getGroup(); if (!eventGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } this.disconnectInternal_(parentBlock, childBlock); if (!childBlock.isShadow()) { @@ -439,21 +438,21 @@ Connection.prototype.disconnect = function() { parentConnection.respawnShadow_(); } if (!eventGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } }; /** * Disconnect two blocks that are connected by this connection. - * @param {!Blockly.Block} parentBlock The superior block. - * @param {!Blockly.Block} childBlock The inferior block. + * @param {!Block} parentBlock The superior block. + * @param {!Block} childBlock The inferior block. * @protected */ Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; - if (Blockly.Events.isEnabled()) { - event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); + if (Events.isEnabled()) { + event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } const otherConnection = this.targetConnection; otherConnection.targetConnection = null; @@ -461,7 +460,7 @@ Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock.setParent(null); if (event) { event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); } }; @@ -473,7 +472,7 @@ Connection.prototype.respawnShadow_ = function() { const parentBlock = this.getSourceBlock(); const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { - const blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); + const blockShadow = Xml.domToBlock(shadow, parentBlock.workspace); if (blockShadow.outputConnection) { this.connect(blockShadow.outputConnection); } else if (blockShadow.previousConnection) { @@ -486,7 +485,7 @@ Connection.prototype.respawnShadow_ = function() { /** * Returns the block that this connection connects to. - * @return {?Blockly.Block} The connected block or null if none is connected. + * @return {?Block} The connected block or null if none is connected. */ Connection.prototype.targetBlock = function() { if (this.isConnected()) { @@ -504,7 +503,7 @@ Connection.prototype.targetBlock = function() { * connectionChecker instead. */ Connection.prototype.checkType = function(otherConnection) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkType', 'October 2019', 'January 2021', @@ -524,7 +523,7 @@ Connection.prototype.checkType = function(otherConnection) { * @suppress {unusedPrivateMembers} */ Connection.prototype.checkType_ = function(otherConnection) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkType_', 'October 2019', 'January 2021', @@ -603,8 +602,8 @@ Connection.prototype.setShadowDom = function(shadow) { */ Connection.prototype.getShadowDom = function(returnCurrent) { return (returnCurrent && this.targetBlock().isShadow()) ? - /** @type {!Element} */ (Blockly.Xml.blockToDom( - /** @type {!Blockly.Block} */ (this.targetBlock()))) : + /** @type {!Element} */ (Xml.blockToDom( + /** @type {!Block} */ (this.targetBlock()))) : this.shadowDom_; }; @@ -626,7 +625,7 @@ Connection.prototype.neighbours = function(_maxLimit) { /** * Get the parent input of a connection. - * @return {?Blockly.Input} The input that the connection belongs to or null if + * @return {?Input} The input that the connection belongs to or null if * no parent exists. * @package */ From cae985369dbc913006ee91bda183f8da84375538 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:05:36 -0700 Subject: [PATCH 065/313] Migrate core/interfaces/i_delete_area.js to goog.module --- core/interfaces/i_delete_area.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_delete_area.js b/core/interfaces/i_delete_area.js index 31f53350e..923c0bd7c 100644 --- a/core/interfaces/i_delete_area.js +++ b/core/interfaces/i_delete_area.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IDeleteArea'); +goog.module('Blockly.IDeleteArea'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IDragTarget'); @@ -25,7 +26,7 @@ goog.requireType('Blockly.IDraggable'); * @extends {Blockly.IDragTarget} * @interface */ -Blockly.IDeleteArea = function() {}; +const IDeleteArea = function() {}; /** * Returns whether the provided block or bubble would be deleted if dropped on @@ -39,4 +40,6 @@ Blockly.IDeleteArea = function() {}; * @return {boolean} Whether the element provided would be deleted if dropped on * this area. */ -Blockly.IDeleteArea.prototype.wouldDelete; +IDeleteArea.prototype.wouldDelete; + +exports = IDeleteArea; diff --git a/tests/deps.js b/tests/deps.js index c23b3f10c..234dbe062 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -83,7 +83,7 @@ goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IC goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []); 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']); +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_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable']); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); From 98e6020baf1e8d4904bb3c4a751e3cb030e80e34 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:06:35 -0700 Subject: [PATCH 066/313] Migrate core/interfaces/i_delete_area.js named requires --- core/interfaces/i_delete_area.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_delete_area.js b/core/interfaces/i_delete_area.js index 923c0bd7c..5c5cbd380 100644 --- a/core/interfaces/i_delete_area.js +++ b/core/interfaces/i_delete_area.js @@ -15,15 +15,14 @@ goog.module('Blockly.IDeleteArea'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IDragTarget'); - -goog.requireType('Blockly.IDraggable'); +const IDraggable = goog.requireType('Blockly.IDraggable'); +const IDragTarget = goog.require('Blockly.IDragTarget'); /** * Interface for a component that can delete a block or bubble that is dropped * on top of it. - * @extends {Blockly.IDragTarget} + * @extends {IDragTarget} * @interface */ const IDeleteArea = function() {}; @@ -33,7 +32,7 @@ const IDeleteArea = function() {}; * this area. * This method should check if the element is deletable and is always called * before onDragEnter/onDragOver/onDragExit. - * @param {!Blockly.IDraggable} element The block or bubble currently being + * @param {!IDraggable} element The block or bubble currently being * dragged. * @param {boolean} couldConnect Whether the element could could connect to * another. From 9806fc13f97819ba76ad077b8d0e5f2fc63dd0e5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:32:10 -0700 Subject: [PATCH 067/313] Migrate core/interfaces/i_draggable.js to goog.module --- core/interfaces/i_draggable.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/interfaces/i_draggable.js b/core/interfaces/i_draggable.js index f140555a1..cb77f3dce 100644 --- a/core/interfaces/i_draggable.js +++ b/core/interfaces/i_draggable.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IDraggable'); +goog.module('Blockly.IDraggable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IDeletable'); @@ -21,4 +22,6 @@ goog.require('Blockly.IDeletable'); * @extends {Blockly.IDeletable} * @interface */ -Blockly.IDraggable = function() {}; +const IDraggable = function() {}; + +exports = IDraggable; diff --git a/tests/deps.js b/tests/deps.js index 234dbe062..5f5f93d89 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -85,7 +85,7 @@ goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], 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_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable']); +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'], []); From 1b15437e2fb296688b3750fca6f1aa1f906a5848 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:32:40 -0700 Subject: [PATCH 068/313] Migrate core/interfaces/i_draggable.js named requires --- core/interfaces/i_draggable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_draggable.js b/core/interfaces/i_draggable.js index cb77f3dce..81303a24b 100644 --- a/core/interfaces/i_draggable.js +++ b/core/interfaces/i_draggable.js @@ -14,12 +14,12 @@ goog.module('Blockly.IDraggable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IDeletable'); +const IDeletable = goog.require('Blockly.IDeletable'); /** * The interface for an object that can be dragged. - * @extends {Blockly.IDeletable} + * @extends {IDeletable} * @interface */ const IDraggable = function() {}; From 1e81334c15cffda802a0d44f27ffc993052483a8 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 14:15:25 -0700 Subject: [PATCH 069/313] Migrate core/renderers/common/info.js to ES6 const/let --- core/renderers/common/info.js | 108 +++++++++++++++++----------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index f3eac053a..9c5d62a9a 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -205,13 +205,13 @@ Blockly.blockRendering.RenderInfo.prototype.measure = function() { Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); - var activeRow = new Blockly.blockRendering.InputRow(this.constants_); + let activeRow = new Blockly.blockRendering.InputRow(this.constants_); this.inputRows.push(activeRow); // Icons always go on the first row, before anything else. - var icons = this.block_.getIcons(); - for (var i = 0, icon; (icon = icons[i]); i++) { - var iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); + const icons = this.block_.getIcons(); + for (let i = 0, icon; (icon = icons[i]); i++) { + const iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); if (this.isCollapsed && icon.collapseHidden) { this.hiddenIcons.push(iconInfo); } else { @@ -219,10 +219,10 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { } } - var lastInput = null; + let lastInput = null; // Loop across all of the inputs on the block, creating objects for anything // that needs to be rendered and breaking the block up into visual rows. - for (var i = 0, input; (input = this.block_.inputList[i]); i++) { + for (let i = 0, input; (input = this.block_.inputList[i]); i++) { if (!input.isVisible()) { continue; } @@ -234,7 +234,7 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { } // All of the fields in an input go on the same row. - for (var j = 0, field; (field = input.fieldRow[j]); j++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { activeRow.elements.push( new Blockly.blockRendering.Field(this.constants_, field, input)); } @@ -260,17 +260,18 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { * @package */ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { - var hasPrevious = !!this.block_.previousConnection; - var hasHat = (this.block_.hat ? - this.block_.hat === 'cap' : this.constants_.ADD_START_HATS) && + const hasPrevious = !!this.block_.previousConnection; + const hasHat = (this.block_.hat ? this.block_.hat === 'cap' : + this.constants_.ADD_START_HATS) && !this.outputConnection && !hasPrevious; - var cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : Blockly.blockRendering.RoundCorner; + let cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? + Blockly.blockRendering.SquareCorner : + Blockly.blockRendering.RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_)); if (hasHat) { - var hat = new Blockly.blockRendering.Hat(this.constants_); + const hat = new Blockly.blockRendering.Hat(this.constants_); this.topRow.elements.push(hat); this.topRow.capline = hat.ascenderHeight; } else if (hasPrevious) { @@ -282,7 +283,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { this.topRow.elements.push(this.topRow.connection); } - var precedesStatement = this.block_.inputList.length && + const precedesStatement = this.block_.inputList.length && this.block_.inputList[0].type == Blockly.inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a @@ -306,7 +307,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; - var followsStatement = this.block_.inputList.length && + const followsStatement = this.block_.inputList.length && this.block_.inputList[this.block_.inputList.length - 1].type == Blockly.inputTypes.STATEMENT; @@ -319,7 +320,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.minHeight = this.constants_.BOTTOM_ROW_MIN_HEIGHT; } - var leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); + const leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); if (leftSquareCorner) { this.bottomRow.elements.push( @@ -336,7 +337,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.elements.push(this.bottomRow.connection); } - var rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); + const rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); if (rightSquareCorner) { this.bottomRow.elements.push( @@ -414,8 +415,8 @@ Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, * @protected */ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { - for (var i = 0, row; (row = this.rows[i]); i++) { - var oldElems = row.elements; + for (let i = 0, row; (row = this.rows[i]); i++) { + const oldElems = row.elements; row.elements = []; // No spacing needed before the corner on the top row or the bottom row. if (row.startsWithElemSpacer()) { @@ -426,9 +427,9 @@ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { if (!oldElems.length) { continue; } - for (var e = 0; e < oldElems.length - 1; e++) { + for (let e = 0; e < oldElems.length - 1; e++) { row.elements.push(oldElems[e]); - var spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); + const spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); row.elements.push( new Blockly.blockRendering.InRowSpacer(this.constants_, spacing)); } @@ -496,15 +497,15 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne */ // TODO: More cleanup. Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { - var widestStatementRowFields = 0; - var blockWidth = 0; - var widestRowWithConnectedBlocks = 0; - for (var i = 0, row; (row = this.rows[i]); i++) { + let widestStatementRowFields = 0; + let blockWidth = 0; + let widestRowWithConnectedBlocks = 0; + for (let i = 0, row; (row = this.rows[i]); i++) { row.measure(); blockWidth = Math.max(blockWidth, row.width); if (row.hasStatement) { - var statementInput = row.getLastInput(); - var innerWidth = row.width - statementInput.width; + const statementInput = row.getLastInput(); + const innerWidth = row.width - statementInput.width; widestStatementRowFields = Math.max(widestStatementRowFields, innerWidth); } widestRowWithConnectedBlocks = @@ -514,7 +515,7 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { this.statementEdge = widestStatementRowFields; this.width = blockWidth; - for (var i = 0, row; (row = this.rows[i]); i++) { + for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { row.statementEdge = this.statementEdge; } @@ -536,14 +537,14 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { * @protected */ Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { - for (var i = 0, row; (row = this.rows[i]); i++) { + for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( /** @type {!Blockly.blockRendering.InputRow} */ (row)); } else { - var currentWidth = row.width; - var desiredWidth = this.getDesiredRowWidth_(row); - var missingSpace = desiredWidth - currentWidth; + const currentWidth = row.width; + const desiredWidth = this.getDesiredRowWidth_(row); + const missingSpace = desiredWidth - currentWidth; if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } @@ -573,10 +574,10 @@ Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( * @param {number} missingSpace How much padding to add. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row, - missingSpace) { - var firstSpacer = row.getFirstSpacer(); - var lastSpacer = row.getLastSpacer(); +Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( + row, missingSpace) { + const firstSpacer = row.getFirstSpacer(); + const lastSpacer = row.getLastSpacer(); if (row.hasExternalInput || row.hasStatement) { row.widthWithConnectedBlocks += missingSpace; } @@ -606,11 +607,11 @@ Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row, * @protected */ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { - var statementInput = row.getLastInput(); - var currentWidth = row.width - statementInput.width; - var desiredWidth = this.statementEdge; + const statementInput = row.getLastInput(); + let currentWidth = row.width - statementInput.width; + let desiredWidth = this.statementEdge; // Add padding before the statement input. - var missingSpace = desiredWidth - currentWidth; + const missingSpace = desiredWidth - currentWidth; if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } @@ -630,10 +631,10 @@ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { * @protected */ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { - var oldRows = this.rows; + const oldRows = this.rows; this.rows = []; - for (var r = 0; r < oldRows.length; r++) { + for (let r = 0; r < oldRows.length; r++) { this.rows.push(oldRows[r]); if (r != oldRows.length - 1) { this.rows.push(this.makeSpacerRow_(oldRows[r], oldRows[r + 1])); @@ -648,11 +649,12 @@ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { - var height = this.getSpacerRowHeight_(prev, next); - var width = this.getSpacerRowWidth_(prev, next); - var spacer = new Blockly.blockRendering.SpacerRow( - this.constants_, height, width); +Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( + prev, next) { + const height = this.getSpacerRowHeight_(prev, next); + const width = this.getSpacerRowWidth_(prev, next); + const spacer = + new Blockly.blockRendering.SpacerRow(this.constants_, height, width); if (prev.hasStatement) { spacer.followsStatement = true; } @@ -703,7 +705,7 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, return row.yPos + elem.height / 2; } if (Blockly.blockRendering.Types.isBottomRow(row)) { - var baseline = row.yPos + row.height - row.descenderHeight; + const baseline = row.yPos + row.height - row.descenderHeight; if (Blockly.blockRendering.Types.isNextConnection(elem)) { return baseline + elem.height / 2; } @@ -726,8 +728,8 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, */ Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( row) { - var xCursor = row.xPos; - for (var j = 0, elem; (elem = row.elements[j]); j++) { + let xCursor = row.xPos; + for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. if (Blockly.blockRendering.Types.isSpacer(elem)) { elem.height = row.height; @@ -747,9 +749,9 @@ Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { // Performance note: this could be combined with the draw pass, if the time // that this takes is excessive. But it shouldn't be, because it only // accesses and sets properties that already exist on the objects. - var widestRowWithConnectedBlocks = 0; - var yCursor = 0; - for (var i = 0, row; (row = this.rows[i]); i++) { + let widestRowWithConnectedBlocks = 0; + let yCursor = 0; + for (let i = 0, row; (row = this.rows[i]); i++) { row.yPos = yCursor; row.xPos = this.startX; yCursor += row.height; From bdd0353549c57936601e884fcaffc5c4e209db70 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:16:06 -0700 Subject: [PATCH 070/313] clang-format core/connection.js --- core/connection.js | 95 ++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 54 deletions(-) diff --git a/core/connection.js b/core/connection.js index 0c7f54605..0b26e9ace 100644 --- a/core/connection.js +++ b/core/connection.js @@ -144,7 +144,8 @@ Connection.prototype.connect_ = function(childConnection) { // Deal with the orphan if it exists. if (orphan) { const orphanConnection = parentConnection.type === INPUT ? - orphan.outputConnection : orphan.previousConnection; + orphan.outputConnection : + orphan.previousConnection; const connection = Connection.getConnectionForOrphanedConnection( childBlock, /** @type {!Connection} */ (orphanConnection)); if (connection) { @@ -161,7 +162,6 @@ Connection.prototype.connect_ = function(childConnection) { * @package */ Connection.prototype.dispose = function() { - // isConnected returns true for shadows and non-shadows. if (this.isConnected()) { // Destroy the attached shadow block & its children (if it exists). @@ -213,12 +213,9 @@ Connection.prototype.isConnected = function() { */ Connection.prototype.canConnectWithReason = function(target) { deprecation.warn( - 'Connection.prototype.canConnectWithReason', - 'July 2020', - 'July 2021', + 'Connection.prototype.canConnectWithReason', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); - return this.getConnectionChecker().canConnectWithReason( - this, target, false); + return this.getConnectionChecker().canConnectWithReason(this, target, false); }; /** @@ -232,9 +229,7 @@ Connection.prototype.canConnectWithReason = function(target) { */ Connection.prototype.checkConnection = function(target) { deprecation.warn( - 'Connection.prototype.checkConnection', - 'July 2020', - 'July 2021', + 'Connection.prototype.checkConnection', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); const checker = this.getConnectionChecker(); const reason = checker.canConnectWithReason(this, target, false); @@ -262,9 +257,7 @@ Connection.prototype.getConnectionChecker = function() { */ Connection.prototype.isConnectionAllowed = function(candidate) { deprecation.warn( - 'Connection.prototype.isConnectionAllowed', - 'July 2020', - 'July 2021', + 'Connection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); return this.getConnectionChecker().canConnect(this, candidate, true); }; @@ -364,19 +357,19 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * of blocks, or null. * @private */ -Connection.getConnectionForOrphanedOutput_ = - function(startBlock, orphanBlock) { - let newBlock = startBlock; - let connection; - while ((connection = Connection.getSingleConnection_( - /** @type {!Block} */ (newBlock), orphanBlock))) { - newBlock = connection.targetBlock(); - if (!newBlock || newBlock.isShadow()) { - return connection; - } - } - return null; - }; +Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { + let newBlock = startBlock; + let connection; + while ( + (connection = Connection.getSingleConnection_( + /** @type {!Block} */ (newBlock), orphanBlock))) { + newBlock = connection.targetBlock(); + if (!newBlock || newBlock.isShadow()) { + return connection; + } + } + return null; +}; /** * Returns the connection (starting at the startBlock) which will accept @@ -388,21 +381,20 @@ Connection.getConnectionForOrphanedOutput_ = * @return {?Connection} The suitable connection point on the chain of * blocks, or null. */ -Connection.getConnectionForOrphanedConnection = - function(startBlock, orphanConnection) { - if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { - return Connection.getConnectionForOrphanedOutput_( - startBlock, orphanConnection.getSourceBlock()); - } - // Otherwise we're dealing with a stack. - const connection = startBlock.lastConnectionInStack(true); - const checker = orphanConnection.getConnectionChecker(); - if (connection && - checker.canConnect(orphanConnection, connection, false)) { - return connection; - } - return null; - }; +Connection.getConnectionForOrphanedConnection = function( + startBlock, orphanConnection) { + if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { + return Connection.getConnectionForOrphanedOutput_( + startBlock, orphanConnection.getSourceBlock()); + } + // Otherwise we're dealing with a stack. + const connection = startBlock.lastConnectionInStack(true); + const checker = orphanConnection.getConnectionChecker(); + if (connection && checker.canConnect(orphanConnection, connection, false)) { + return connection; + } + return null; +}; /** * Disconnect this connection. @@ -448,8 +440,7 @@ Connection.prototype.disconnect = function() { * @param {!Block} childBlock The inferior block. * @protected */ -Connection.prototype.disconnectInternal_ = function(parentBlock, - childBlock) { +Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; if (Events.isEnabled()) { event = new (Events.get(Events.BLOCK_MOVE))(childBlock); @@ -504,12 +495,9 @@ Connection.prototype.targetBlock = function() { */ Connection.prototype.checkType = function(otherConnection) { deprecation.warn( - 'Connection.prototype.checkType', - 'October 2019', - 'January 2021', + 'Connection.prototype.checkType', 'October 2019', 'January 2021', 'the workspace\'s connection checker'); - return this.getConnectionChecker().canConnect(this, otherConnection, - false); + return this.getConnectionChecker().canConnect(this, otherConnection, false); }; /** @@ -524,9 +512,7 @@ Connection.prototype.checkType = function(otherConnection) { */ Connection.prototype.checkType_ = function(otherConnection) { deprecation.warn( - 'Connection.prototype.checkType_', - 'October 2019', - 'January 2021', + 'Connection.prototype.checkType_', 'October 2019', 'January 2021', 'the workspace\'s connection checker'); return this.checkType(otherConnection); }; @@ -537,9 +523,10 @@ Connection.prototype.checkType_ = function(otherConnection) { */ Connection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. - if (this.isConnected() && (!this.targetConnection || - !this.getConnectionChecker().canConnect( - this, this.targetConnection, false))) { + if (this.isConnected() && + (!this.targetConnection || + !this.getConnectionChecker().canConnect( + this, this.targetConnection, false))) { const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child.unplug(); } From 29c560dfbb225d702f95a30a9560baca65a4e457 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:26:36 -0700 Subject: [PATCH 071/313] 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 072/313] 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 073/313] 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 074/313] 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 20079a64aa66b87ca2ee8026801178fb4178ebb3 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 14:38:01 -0700 Subject: [PATCH 075/313] Migrate core/renderers/common/info.js to goog.module --- core/renderers/common/info.js | 56 ++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 9c5d62a9a..6efc4692f 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockRendering.RenderInfo'); +goog.module('Blockly.blockRendering.RenderInfo'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockRendering.BottomRow'); goog.require('Blockly.blockRendering.ExternalValueInput'); @@ -55,7 +56,7 @@ goog.requireType('Blockly.RenderedConnection'); * @constructor * @package */ -Blockly.blockRendering.RenderInfo = function(renderer, block) { +const RenderInfo = function(renderer, block) { this.block_ = block; /** @@ -174,7 +175,7 @@ Blockly.blockRendering.RenderInfo = function(renderer, block) { * @return {!Blockly.blockRendering.Renderer} The block renderer in use. * @package */ -Blockly.blockRendering.RenderInfo.prototype.getRenderer = function() { +RenderInfo.prototype.getRenderer = function() { return this.renderer_; }; @@ -188,7 +189,7 @@ Blockly.blockRendering.RenderInfo.prototype.getRenderer = function() { * * @package */ -Blockly.blockRendering.RenderInfo.prototype.measure = function() { +RenderInfo.prototype.measure = function() { this.createRows_(); this.addElemSpacing_(); this.addRowSpacing_(); @@ -202,7 +203,7 @@ Blockly.blockRendering.RenderInfo.prototype.measure = function() { * block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { +RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); let activeRow = new Blockly.blockRendering.InputRow(this.constants_); @@ -259,7 +260,7 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { * Create all non-spacer elements that belong on the top row. * @package */ -Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { +RenderInfo.prototype.populateTopRow_ = function() { const hasPrevious = !!this.block_.previousConnection; const hasHat = (this.block_.hat ? this.block_.hat === 'cap' : this.constants_.ADD_START_HATS) && @@ -304,7 +305,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { * Create all non-spacer elements that belong on the bottom row. * @package */ -Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { +RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; const followsStatement = this.block_.inputList.length && @@ -356,7 +357,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { * populated. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRow) { +RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. if (this.isInline && input.type == Blockly.inputTypes.VALUE) { activeRow.elements.push( @@ -391,7 +392,7 @@ Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRo * @return {boolean} True if the next input should be rendered on a new row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { +RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { // If this is the first input, just add to the existing row. // That row is either empty or has some icons in it. if (!lastInput) { @@ -414,7 +415,7 @@ Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, * Add horizontal spacing between and around elements within each row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { +RenderInfo.prototype.addElemSpacing_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { const oldElems = row.elements; row.elements = []; @@ -453,7 +454,7 @@ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { * @return {number} The size of the spacing between the two elements. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { +RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Statement input padding. if (next && Blockly.blockRendering.Types.isStatementInput(next)) { @@ -496,7 +497,7 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne * @protected */ // TODO: More cleanup. -Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { +RenderInfo.prototype.computeBounds_ = function() { let widestStatementRowFields = 0; let blockWidth = 0; let widestRowWithConnectedBlocks = 0; @@ -536,7 +537,7 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { * the sizes of all rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { +RenderInfo.prototype.alignRowElements_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( @@ -561,8 +562,7 @@ Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { * @return {number} The desired width of the input row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( - _row) { +RenderInfo.prototype.getDesiredRowWidth_ = function(_row) { return this.width - this.startX; }; @@ -574,8 +574,7 @@ Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( * @param {number} missingSpace How much padding to add. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( - row, missingSpace) { +RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { const firstSpacer = row.getFirstSpacer(); const lastSpacer = row.getLastSpacer(); if (row.hasExternalInput || row.hasStatement) { @@ -606,7 +605,7 @@ Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( * @param {!Blockly.blockRendering.InputRow} row The statement row to resize. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { +RenderInfo.prototype.alignStatementRow_ = function(row) { const statementInput = row.getLastInput(); let currentWidth = row.width - statementInput.width; let desiredWidth = this.statementEdge; @@ -630,7 +629,7 @@ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { * Add spacers between rows and set their sizes. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { +RenderInfo.prototype.addRowSpacing_ = function() { const oldRows = this.rows; this.rows = []; @@ -649,8 +648,7 @@ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( - prev, next) { +RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { const height = this.getSpacerRowHeight_(prev, next); const width = this.getSpacerRowWidth_(prev, next); const spacer = @@ -671,8 +669,7 @@ Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( * @return {number} The desired width of the spacer row between these two rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getSpacerRowWidth_ = function( - _prev, _next) { +RenderInfo.prototype.getSpacerRowWidth_ = function(_prev, _next) { return this.width - this.startX; }; @@ -683,8 +680,7 @@ Blockly.blockRendering.RenderInfo.prototype.getSpacerRowWidth_ = function( * @return {number} The desired height of the spacer row between these two rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getSpacerRowHeight_ = function( - _prev, _next) { +RenderInfo.prototype.getSpacerRowHeight_ = function(_prev, _next) { return this.constants_.MEDIUM_PADDING; }; @@ -699,8 +695,7 @@ Blockly.blockRendering.RenderInfo.prototype.getSpacerRowHeight_ = function( * from the top left of the block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, - elem) { +RenderInfo.prototype.getElemCenterline_ = function(row, elem) { if (Blockly.blockRendering.Types.isSpacer(elem)) { return row.yPos + elem.height / 2; } @@ -726,8 +721,7 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, * @param {!Blockly.blockRendering.Row} row The row containing the elements. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( - row) { +RenderInfo.prototype.recordElemPositions_ = function(row) { let xCursor = row.xPos; for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. @@ -745,7 +739,7 @@ Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( * store the y position of each row, and record the height of the full block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { +RenderInfo.prototype.finalize_ = function() { // Performance note: this could be combined with the draw pass, if the time // that this takes is excessive. But it shouldn't be, because it only // accesses and sets properties that already exist on the objects. @@ -774,3 +768,5 @@ Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { this.startY = this.topRow.capline; this.bottomRow.baseline = yCursor - this.bottomRow.descenderHeight; }; + +exports = RenderInfo; diff --git a/tests/deps.js b/tests/deps.js index 5a06dd4ae..8baeee5ab 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); From e23560343ed0d9ab3fc80ae4bd908fd23e12d576 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:45:35 -0700 Subject: [PATCH 076/313] 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 077/313] 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 f38a4519878a0e6c70218af505c4aaf5a01eaef7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:11:19 -0700 Subject: [PATCH 078/313] Migrate core/comment.js to ES6 const/let --- core/comment.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/comment.js b/core/comment.js index 7917b2ec5..5e867d9df 100644 --- a/core/comment.js +++ b/core/comment.js @@ -152,13 +152,13 @@ Blockly.Comment.prototype.createEditor_ = function() { {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, null); - var body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); + const body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); body.className = 'blocklyMinimalBody'; this.textarea_ = document.createElementNS( Blockly.utils.dom.HTML_NS, 'textarea'); - var textarea = this.textarea_; + const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); textarea.value = this.model_.text; @@ -228,10 +228,10 @@ Blockly.Comment.prototype.onBubbleResize_ = function() { * @private */ Blockly.Comment.prototype.resizeTextarea_ = function() { - var size = this.model_.size; - var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; - var widthMinusBorder = size.width - doubleBorderWidth; - var heightMinusBorder = size.height - doubleBorderWidth; + const size = this.model_.size; + const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const widthMinusBorder = size.width - doubleBorderWidth; + const heightMinusBorder = size.height - doubleBorderWidth; this.foreignObject_.setAttribute('width', widthMinusBorder); this.foreignObject_.setAttribute('height', heightMinusBorder); this.textarea_.style.width = (widthMinusBorder - 4) + 'px'; From 530964e03b83a26f0e6880040bc73dcdad8dabed Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:15:42 -0700 Subject: [PATCH 079/313] Migrate core/comment.js to goog.module --- core/comment.js | 43 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/core/comment.js b/core/comment.js index 5e867d9df..1e585d63c 100644 --- a/core/comment.js +++ b/core/comment.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Comment'); +goog.module('Blockly.Comment'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.Bubble'); @@ -41,8 +42,8 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.Icon} * @constructor */ -Blockly.Comment = function(block) { - Blockly.Comment.superClass_.constructor.call(this, block); +const Comment = function(block) { + Comment.superClass_.constructor.call(this, block); /** * The model for this comment. @@ -92,14 +93,14 @@ Blockly.Comment = function(block) { this.createIcon(); }; -Blockly.utils.object.inherits(Blockly.Comment, Blockly.Icon); +Blockly.utils.object.inherits(Comment, Blockly.Icon); /** * Draw the comment icon. * @param {!Element} group The icon group. * @protected */ -Blockly.Comment.prototype.drawIcon_ = function(group) { +Comment.prototype.drawIcon_ = function(group) { // Circle. Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CIRCLE, @@ -134,7 +135,7 @@ Blockly.Comment.prototype.drawIcon_ = function(group) { * @return {!SVGElement} The top-level node of the editor. * @private */ -Blockly.Comment.prototype.createEditor_ = function() { +Comment.prototype.createEditor_ = function() { /* Create the editor. Here's the markup that will be generated in * editable mode: @@ -200,8 +201,8 @@ Blockly.Comment.prototype.createEditor_ = function() { * Add or remove editability of the comment. * @override */ -Blockly.Comment.prototype.updateEditable = function() { - Blockly.Comment.superClass_.updateEditable.call(this); +Comment.prototype.updateEditable = function() { + Comment.superClass_.updateEditable.call(this); if (this.isVisible()) { // Recreate the bubble with the correct UI. this.disposeBubble_(); @@ -214,7 +215,7 @@ Blockly.Comment.prototype.updateEditable = function() { * Resize the text area accordingly. * @private */ -Blockly.Comment.prototype.onBubbleResize_ = function() { +Comment.prototype.onBubbleResize_ = function() { if (!this.isVisible()) { return; } @@ -227,7 +228,7 @@ Blockly.Comment.prototype.onBubbleResize_ = function() { * the size of the bubble). * @private */ -Blockly.Comment.prototype.resizeTextarea_ = function() { +Comment.prototype.resizeTextarea_ = function() { const size = this.model_.size; const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; const widthMinusBorder = size.width - doubleBorderWidth; @@ -242,7 +243,7 @@ Blockly.Comment.prototype.resizeTextarea_ = function() { * Show or hide the comment bubble. * @param {boolean} visible True if the bubble should be visible. */ -Blockly.Comment.prototype.setVisible = function(visible) { +Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } @@ -260,7 +261,7 @@ Blockly.Comment.prototype.setVisible = function(visible) { * Show the bubble. Handles deciding if it should be editable or not. * @private */ -Blockly.Comment.prototype.createBubble_ = function() { +Comment.prototype.createBubble_ = function() { if (!this.block_.isEditable() || Blockly.utils.userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 @@ -275,7 +276,7 @@ Blockly.Comment.prototype.createBubble_ = function() { * Show an editable bubble. * @private */ -Blockly.Comment.prototype.createEditableBubble_ = function() { +Comment.prototype.createEditableBubble_ = function() { this.bubble_ = new Blockly.Bubble( /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, @@ -292,7 +293,7 @@ Blockly.Comment.prototype.createEditableBubble_ = function() { * @private * @suppress {checkTypes} Suppress `this` type mismatch. */ -Blockly.Comment.prototype.createNonEditableBubble_ = function() { +Comment.prototype.createNonEditableBubble_ = function() { // TODO (#2917): It would be great if the comment could support line breaks. this.paragraphElement_ = Blockly.Bubble.textToDom(this.block_.getCommentText()); this.bubble_ = Blockly.Bubble.createNonEditableBubble( @@ -306,7 +307,7 @@ Blockly.Comment.prototype.createNonEditableBubble_ = function() { * @private * @suppress {checkTypes} Suppress `this` type mismatch. */ -Blockly.Comment.prototype.disposeBubble_ = function() { +Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { Blockly.browserEvents.unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; @@ -338,7 +339,7 @@ Blockly.Comment.prototype.disposeBubble_ = function() { * @param {!Event} _e Mouse up event. * @private */ -Blockly.Comment.prototype.startEdit_ = function(_e) { +Comment.prototype.startEdit_ = function(_e) { if (this.bubble_.promote()) { // Since the act of moving this node within the DOM causes a loss of focus, // we need to reapply the focus. @@ -352,7 +353,7 @@ Blockly.Comment.prototype.startEdit_ = function(_e) { * Get the dimensions of this comment's bubble. * @return {Blockly.utils.Size} Object with width and height properties. */ -Blockly.Comment.prototype.getBubbleSize = function() { +Comment.prototype.getBubbleSize = function() { return this.model_.size; }; @@ -361,7 +362,7 @@ Blockly.Comment.prototype.getBubbleSize = function() { * @param {number} width Width of the bubble. * @param {number} height Height of the bubble. */ -Blockly.Comment.prototype.setBubbleSize = function(width, height) { +Comment.prototype.setBubbleSize = function(width, height) { if (this.bubble_) { this.bubble_.setBubbleSize(width, height); } else { @@ -374,7 +375,7 @@ Blockly.Comment.prototype.setBubbleSize = function(width, height) { * Update the comment's view to match the model. * @package */ -Blockly.Comment.prototype.updateText = function() { +Comment.prototype.updateText = function() { if (this.textarea_) { this.textarea_.value = this.model_.text; } else if (this.paragraphElement_) { @@ -390,7 +391,7 @@ Blockly.Comment.prototype.updateText = function() { * If you want to receive a comment "delete" event (newValue: null), then this * should not be called directly. Instead call block.setCommentText(null); */ -Blockly.Comment.prototype.dispose = function() { +Comment.prototype.dispose = function() { this.block_.comment = null; Blockly.Icon.prototype.dispose.call(this); }; @@ -412,3 +413,5 @@ Blockly.Css.register([ '}' /* eslint-enable indent */ ]); + +exports = Comment; diff --git a/tests/deps.js b/tests/deps.js index 5f5f93d89..f04468cf7 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -17,7 +17,7 @@ goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6 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/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/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'], {'lang': 'es6', 'module': 'goog'}); 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']); From 30a6948a9a30a04ad60de79831d56a3a0ea79e82 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:37:05 -0700 Subject: [PATCH 080/313] Migrate core/comment.js to named requires --- core/comment.js | 116 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/core/comment.js b/core/comment.js index 1e585d63c..18615d669 100644 --- a/core/comment.js +++ b/core/comment.js @@ -13,33 +13,33 @@ goog.module('Blockly.Comment'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.Bubble'); -goog.require('Blockly.Css'); -goog.require('Blockly.Events'); +const Block = goog.requireType('Blockly.Block'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const Bubble = goog.require('Blockly.Bubble'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const Css = goog.require('Blockly.Css'); +const dom = goog.require('Blockly.utils.dom'); +const Events = goog.require('Blockly.Events'); +const Icon = goog.require('Blockly.Icon'); +const Size = goog.requireType('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const utilsObject = goog.require('Blockly.utils.object'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {CommentModel} = goog.requireType('Blockly.Block'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BubbleOpen'); -goog.require('Blockly.Icon'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Warning'); -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.utils.Size'); -goog.requireType('Blockly.WorkspaceSvg'); - /** * Class for a comment. - * @param {!Blockly.Block} block The block associated with this comment. - * @extends {Blockly.Icon} + * @param {!Block} block The block associated with this comment. + * @extends {Icon} * @constructor */ const Comment = function(block) { @@ -47,7 +47,7 @@ const Comment = function(block) { /** * The model for this comment. - * @type {!Blockly.Block.CommentModel} + * @type {!CommentModel} * @private */ this.model_ = block.commentModel; @@ -65,35 +65,35 @@ const Comment = function(block) { /** * Mouse up event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onMouseUpWrapper_ = null; /** * Wheel event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onWheelWrapper_ = null; /** * Change event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onChangeWrapper_ = null; /** * Input event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onInputWrapper_ = null; this.createIcon(); }; -Blockly.utils.object.inherits(Comment, Blockly.Icon); +utilsObject.inherits(Comment, Icon); /** * Draw the comment icon. @@ -102,15 +102,15 @@ Blockly.utils.object.inherits(Comment, Blockly.Icon); */ Comment.prototype.drawIcon_ = function(group) { // Circle. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, + dom.createSvgElement( + Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + @@ -118,8 +118,8 @@ Comment.prototype.drawIcon_ = function(group) { '-1.201,0.998 -1.201,1.528 -1.204,2.19z'}, group); // Dot of question mark. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', @@ -148,17 +148,17 @@ Comment.prototype.createEditor_ = function() { * For non-editable mode see Warning.textToDom_. */ - this.foreignObject_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FOREIGNOBJECT, - {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, + this.foreignObject_ = dom.createSvgElement( + Svg.FOREIGNOBJECT, + {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); - const body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); - body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); + const body = document.createElementNS(dom.HTML_NS, 'body'); + body.setAttribute('xmlns', dom.HTML_NS); body.className = 'blocklyMinimalBody'; this.textarea_ = document.createElementNS( - Blockly.utils.dom.HTML_NS, 'textarea'); + dom.HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -171,23 +171,23 @@ Comment.prototype.createEditor_ = function() { // Ideally this would be hooked to the focus event for the comment. // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. - this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseUpWrapper_ = browserEvents.conditionalBind( textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = Blockly.browserEvents.conditionalBind( + this.onWheelWrapper_ = browserEvents.conditionalBind( textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - this.onChangeWrapper_ = Blockly.browserEvents.conditionalBind( + this.onChangeWrapper_ = browserEvents.conditionalBind( textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire( + new (Events.get(Events.BLOCK_CHANGE))( this.block_, 'comment', null, this.cachedText_, this.model_.text)); } }); - this.onInputWrapper_ = Blockly.browserEvents.conditionalBind( + this.onInputWrapper_ = browserEvents.conditionalBind( textarea, 'input', this, function(_e) { this.model_.text = textarea.value; }); @@ -230,7 +230,7 @@ Comment.prototype.onBubbleResize_ = function() { */ Comment.prototype.resizeTextarea_ = function() { const size = this.model_.size; - const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const doubleBorderWidth = 2 * Bubble.BORDER_WIDTH; const widthMinusBorder = size.width - doubleBorderWidth; const heightMinusBorder = size.height - doubleBorderWidth; this.foreignObject_.setAttribute('width', widthMinusBorder); @@ -247,7 +247,7 @@ Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + Events.fire(new (Events.get(Events.BUBBLE_OPEN))( this.block_, visible, 'comment')); this.model_.pinned = visible; if (visible) { @@ -262,7 +262,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || Blockly.utils.userAgent.IE) { + if (!this.block_.isEditable() || userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable. @@ -277,10 +277,10 @@ Comment.prototype.createBubble_ = function() { * @private */ Comment.prototype.createEditableBubble_ = function() { - this.bubble_ = new Blockly.Bubble( - /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), + this.bubble_ = new Bubble( + /** @type {!WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_), + /** @type {!Coordinate} */ (this.iconXY_), this.model_.size.width, this.model_.size.height); // Expose this comment's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); @@ -295,10 +295,10 @@ Comment.prototype.createEditableBubble_ = function() { */ Comment.prototype.createNonEditableBubble_ = function() { // TODO (#2917): It would be great if the comment could support line breaks. - this.paragraphElement_ = Blockly.Bubble.textToDom(this.block_.getCommentText()); - this.bubble_ = Blockly.Bubble.createNonEditableBubble( - this.paragraphElement_, /** @type {!Blockly.BlockSvg} */ (this.block_), - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_)); + this.paragraphElement_ = Bubble.textToDom(this.block_.getCommentText()); + this.bubble_ = Bubble.createNonEditableBubble( + this.paragraphElement_, /** @type {!BlockSvg} */ (this.block_), + /** @type {!Coordinate} */ (this.iconXY_)); this.applyColour(); }; @@ -309,19 +309,19 @@ Comment.prototype.createNonEditableBubble_ = function() { */ Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(this.onMouseUpWrapper_); + browserEvents.unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; } if (this.onWheelWrapper_) { - Blockly.browserEvents.unbind(this.onWheelWrapper_); + browserEvents.unbind(this.onWheelWrapper_); this.onWheelWrapper_ = null; } if (this.onChangeWrapper_) { - Blockly.browserEvents.unbind(this.onChangeWrapper_); + browserEvents.unbind(this.onChangeWrapper_); this.onChangeWrapper_ = null; } if (this.onInputWrapper_) { - Blockly.browserEvents.unbind(this.onInputWrapper_); + browserEvents.unbind(this.onInputWrapper_); this.onInputWrapper_ = null; } this.bubble_.dispose(); @@ -351,7 +351,7 @@ Comment.prototype.startEdit_ = function(_e) { /** * Get the dimensions of this comment's bubble. - * @return {Blockly.utils.Size} Object with width and height properties. + * @return {Size} Object with width and height properties. */ Comment.prototype.getBubbleSize = function() { return this.model_.size; @@ -393,13 +393,13 @@ Comment.prototype.updateText = function() { */ Comment.prototype.dispose = function() { this.block_.comment = null; - Blockly.Icon.prototype.dispose.call(this); + Icon.prototype.dispose.call(this); }; /** * CSS for block comment. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyCommentTextarea {', 'background-color: #fef49c;', From d1ae27eb6071981e60751fa44244790e15c9bfa1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:38:00 -0700 Subject: [PATCH 081/313] clang-format core/comment.js --- core/comment.js | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/core/comment.js b/core/comment.js index 18615d669..fe0c940a6 100644 --- a/core/comment.js +++ b/core/comment.js @@ -103,24 +103,22 @@ utilsObject.inherits(Comment, Icon); Comment.prototype.drawIcon_ = function(group) { // Circle. dom.createSvgElement( - Svg.CIRCLE, - {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, + Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + - '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' + - '-1.201,0.998 -1.201,1.528 -1.204,2.19z'}, + '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' + + '-1.201,0.998 -1.201,1.528 -1.204,2.19z' + }, group); // Dot of question mark. dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', 'y': '10.78', @@ -149,16 +147,14 @@ Comment.prototype.createEditor_ = function() { */ this.foreignObject_ = dom.createSvgElement( - Svg.FOREIGNOBJECT, - {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, + Svg.FOREIGNOBJECT, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); const body = document.createElementNS(dom.HTML_NS, 'body'); body.setAttribute('xmlns', dom.HTML_NS); body.className = 'blocklyMinimalBody'; - this.textarea_ = document.createElementNS( - dom.HTML_NS, 'textarea'); + this.textarea_ = document.createElementNS(dom.HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -174,21 +170,20 @@ Comment.prototype.createEditor_ = function() { this.onMouseUpWrapper_ = browserEvents.conditionalBind( textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = browserEvents.conditionalBind( - textarea, 'wheel', this, function(e) { + this.onWheelWrapper_ = + browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - this.onChangeWrapper_ = browserEvents.conditionalBind( - textarea, 'change', this, function(_e) { + this.onChangeWrapper_ = + browserEvents.conditionalBind(textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { - Events.fire( - new (Events.get(Events.BLOCK_CHANGE))( - this.block_, 'comment', null, this.cachedText_, - this.model_.text)); + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( + this.block_, 'comment', null, this.cachedText_, + this.model_.text)); } }); - this.onInputWrapper_ = browserEvents.conditionalBind( - textarea, 'input', this, function(_e) { + this.onInputWrapper_ = + browserEvents.conditionalBind(textarea, 'input', this, function(_e) { this.model_.text = textarea.value; }); @@ -247,8 +242,8 @@ Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Events.fire(new (Events.get(Events.BUBBLE_OPEN))( - this.block_, visible, 'comment')); + Events.fire( + new (Events.get(Events.BUBBLE_OPEN))(this.block_, visible, 'comment')); this.model_.pinned = visible; if (visible) { this.createBubble_(); @@ -280,8 +275,8 @@ Comment.prototype.createEditableBubble_ = function() { this.bubble_ = new Bubble( /** @type {!WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, - /** @type {!Coordinate} */ (this.iconXY_), - this.model_.size.width, this.model_.size.height); + /** @type {!Coordinate} */ (this.iconXY_), this.model_.size.width, + this.model_.size.height); // Expose this comment's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerResizeEvent(this.onBubbleResize_.bind(this)); From b3877ffbb9e720351bb2e3aa27982584233fffe1 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 15:13:41 -0700 Subject: [PATCH 082/313] Migrate core/renderers/common/info.js to named requires --- core/renderers/common/info.js | 249 ++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 118 insertions(+), 133 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 6efc4692f..3c5e70ee4 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -13,35 +13,34 @@ goog.module('Blockly.blockRendering.RenderInfo'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockRendering.BottomRow'); -goog.require('Blockly.blockRendering.ExternalValueInput'); -goog.require('Blockly.blockRendering.Field'); -goog.require('Blockly.blockRendering.Hat'); -goog.require('Blockly.blockRendering.InlineInput'); -goog.require('Blockly.blockRendering.InputRow'); -goog.require('Blockly.blockRendering.InRowSpacer'); -goog.require('Blockly.blockRendering.JaggedEdge'); -goog.require('Blockly.blockRendering.Measurable'); -goog.require('Blockly.blockRendering.NextConnection'); -goog.require('Blockly.blockRendering.OutputConnection'); -goog.require('Blockly.blockRendering.PreviousConnection'); -goog.require('Blockly.blockRendering.RoundCorner'); -goog.require('Blockly.blockRendering.Row'); -goog.require('Blockly.blockRendering.SpacerRow'); -goog.require('Blockly.blockRendering.SquareCorner'); -goog.require('Blockly.blockRendering.StatementInput'); -goog.require('Blockly.blockRendering.TopRow'); -goog.require('Blockly.blockRendering.Types'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const BottomRow = goog.require('Blockly.blockRendering.BottomRow'); +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +const ExternalValueInput = goog.require('Blockly.blockRendering.ExternalValueInput'); +const Field = goog.require('Blockly.blockRendering.Field'); +const Hat = goog.require('Blockly.blockRendering.Hat'); +const Icon = goog.require('Blockly.blockRendering.Icon'); +const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); +const Input = goog.requireType('Blockly.Input'); +const InputRow = goog.require('Blockly.blockRendering.InputRow'); +const inputTypes = goog.require('Blockly.inputTypes'); +const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); +const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); +const Measurable = goog.require('Blockly.blockRendering.Measurable'); +const NextConnection = goog.require('Blockly.blockRendering.NextConnection'); +const OutputConnection = goog.require('Blockly.blockRendering.OutputConnection'); +const PreviousConnection = goog.require('Blockly.blockRendering.PreviousConnection'); +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const Renderer = goog.requireType('Blockly.blockRendering.Renderer'); +const RoundCorner = goog.require('Blockly.blockRendering.RoundCorner'); +const Row = goog.require('Blockly.blockRendering.Row'); +const SpacerRow = goog.require('Blockly.blockRendering.SpacerRow'); +const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); +const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); +const TopRow = goog.require('Blockly.blockRendering.TopRow'); +const Types = goog.require('Blockly.blockRendering.Types'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -goog.require('Blockly.inputTypes'); - -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.blockRendering.Icon'); -goog.requireType('Blockly.blockRendering.Renderer'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Input'); -goog.requireType('Blockly.RenderedConnection'); +const blocklyConstants = goog.require('Blockly.constants'); /** @@ -51,8 +50,8 @@ goog.requireType('Blockly.RenderedConnection'); * may choose to rerender when getSize() is called). However, calling it * repeatedly may be expensive. * - * @param {!Blockly.blockRendering.Renderer} renderer The renderer in use. - * @param {!Blockly.BlockSvg} block The block to measure. + * @param {!Renderer} renderer The renderer in use. + * @param {!BlockSvg} block The block to measure. * @constructor * @package */ @@ -61,14 +60,14 @@ const RenderInfo = function(renderer, block) { /** * The block renderer in use. - * @type {!Blockly.blockRendering.Renderer} + * @type {!Renderer} * @protected */ this.renderer_ = renderer; /** * The renderer's constant provider. - * @type {!Blockly.blockRendering.ConstantProvider} + * @type {!ConstantProvider} * @protected */ this.constants_ = this.renderer_.getConstants(); @@ -76,12 +75,13 @@ const RenderInfo = function(renderer, block) { /** * A measurable representing the output connection if the block has one. * Otherwise null. - * @type {Blockly.blockRendering.OutputConnection} + * @type {OutputConnection} */ - this.outputConnection = !block.outputConnection ? null : - new Blockly.blockRendering.OutputConnection( + this.outputConnection = !block.outputConnection ? + null : + new OutputConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */(block.outputConnection)); + /** @type {RenderedConnection} */ (block.outputConnection)); /** * Whether the block should be rendered as a single line, either because it's @@ -136,33 +136,33 @@ const RenderInfo = function(renderer, block) { /** * An array of Row objects containing sizing information. - * @type {!Array} + * @type {!Array} */ this.rows = []; /** * An array of input rows on the block. - * @type {!Array} + * @type {!Array} */ this.inputRows = []; /** * An array of measurable objects containing hidden icons. - * @type {!Array} + * @type {!Array} */ this.hiddenIcons = []; /** * An object with rendering information about the top row of the block. - * @type {!Blockly.blockRendering.TopRow} + * @type {!TopRow} */ - this.topRow = new Blockly.blockRendering.TopRow(this.constants_); + this.topRow = new TopRow(this.constants_); /** * An object with rendering information about the bottom row of the block. - * @type {!Blockly.blockRendering.BottomRow} + * @type {!BottomRow} */ - this.bottomRow = new Blockly.blockRendering.BottomRow(this.constants_); + this.bottomRow = new BottomRow(this.constants_); // The position of the start point for drawing, relative to the block's // location. @@ -172,7 +172,7 @@ const RenderInfo = function(renderer, block) { /** * Get the block renderer in use. - * @return {!Blockly.blockRendering.Renderer} The block renderer in use. + * @return {!Renderer} The block renderer in use. * @package */ RenderInfo.prototype.getRenderer = function() { @@ -206,13 +206,13 @@ RenderInfo.prototype.measure = function() { RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); - let activeRow = new Blockly.blockRendering.InputRow(this.constants_); + let activeRow = new InputRow(this.constants_); this.inputRows.push(activeRow); // Icons always go on the first row, before anything else. const icons = this.block_.getIcons(); for (let i = 0, icon; (icon = icons[i]); i++) { - const iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); + const iconInfo = new Icon(this.constants_, icon); if (this.isCollapsed && icon.collapseHidden) { this.hiddenIcons.push(iconInfo); } else { @@ -230,14 +230,13 @@ RenderInfo.prototype.createRows_ = function() { if (this.shouldStartNewRow_(input, lastInput)) { // Finish this row and create a new one. this.rows.push(activeRow); - activeRow = new Blockly.blockRendering.InputRow(this.constants_); + activeRow = new InputRow(this.constants_); this.inputRows.push(activeRow); } // All of the fields in an input go on the same row. for (let j = 0, field; (field = input.fieldRow[j]); j++) { - activeRow.elements.push( - new Blockly.blockRendering.Field(this.constants_, field, input)); + activeRow.elements.push(new Field(this.constants_, field, input)); } this.addInput_(input, activeRow); lastInput = input; @@ -245,8 +244,7 @@ RenderInfo.prototype.createRows_ = function() { if (this.isCollapsed) { activeRow.hasJaggedEdge = true; - activeRow.elements.push( - new Blockly.blockRendering.JaggedEdge(this.constants_)); + activeRow.elements.push(new JaggedEdge(this.constants_)); } if (activeRow.elements.length || activeRow.hasDummyInput) { @@ -266,26 +264,25 @@ RenderInfo.prototype.populateTopRow_ = function() { this.constants_.ADD_START_HATS) && !this.outputConnection && !hasPrevious; - let cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : - Blockly.blockRendering.RoundCorner; + let cornerClass = + this.topRow.hasLeftSquareCorner(this.block_) ? SquareCorner : RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_)); if (hasHat) { - const hat = new Blockly.blockRendering.Hat(this.constants_); + const hat = new Hat(this.constants_); this.topRow.elements.push(hat); this.topRow.capline = hat.ascenderHeight; } else if (hasPrevious) { this.topRow.hasPreviousConnection = true; - this.topRow.connection = new Blockly.blockRendering.PreviousConnection( + this.topRow.connection = new PreviousConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */ + /** @type {RenderedConnection} */ (this.block_.previousConnection)); this.topRow.elements.push(this.topRow.connection); } const precedesStatement = this.block_.inputList.length && - this.block_.inputList[0].type == Blockly.inputTypes.STATEMENT; + this.block_.inputList[0].type == inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -296,8 +293,8 @@ RenderInfo.prototype.populateTopRow_ = function() { this.topRow.minHeight = this.constants_.TOP_ROW_MIN_HEIGHT; } - cornerClass = this.topRow.hasRightSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : Blockly.blockRendering.RoundCorner; + cornerClass = this.topRow.hasRightSquareCorner(this.block_) ? SquareCorner : + RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_, 'right')); }; @@ -310,7 +307,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { const followsStatement = this.block_.inputList.length && this.block_.inputList[this.block_.inputList.length - 1].type == - Blockly.inputTypes.STATEMENT; + inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -324,54 +321,47 @@ RenderInfo.prototype.populateBottomRow_ = function() { const leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); if (leftSquareCorner) { - this.bottomRow.elements.push( - new Blockly.blockRendering.SquareCorner(this.constants_)); + this.bottomRow.elements.push(new SquareCorner(this.constants_)); } else { - this.bottomRow.elements.push( - new Blockly.blockRendering.RoundCorner(this.constants_)); + this.bottomRow.elements.push(new RoundCorner(this.constants_)); } if (this.bottomRow.hasNextConnection) { - this.bottomRow.connection = new Blockly.blockRendering.NextConnection( + this.bottomRow.connection = new NextConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */ (this.block_.nextConnection)); + /** @type {RenderedConnection} */ (this.block_.nextConnection)); this.bottomRow.elements.push(this.bottomRow.connection); } const rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); if (rightSquareCorner) { - this.bottomRow.elements.push( - new Blockly.blockRendering.SquareCorner(this.constants_, 'right')); + this.bottomRow.elements.push(new SquareCorner(this.constants_, 'right')); } else { - this.bottomRow.elements.push( - new Blockly.blockRendering.RoundCorner(this.constants_, 'right')); + this.bottomRow.elements.push(new RoundCorner(this.constants_, 'right')); } }; /** * Add an input element to the active row, if needed, and record the type of the * input on the row. - * @param {!Blockly.Input} input The input to record information about. - * @param {!Blockly.blockRendering.Row} activeRow The row that is currently being + * @param {!Input} input The input to record information about. + * @param {!Row} activeRow The row that is currently being * populated. * @protected */ RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. - if (this.isInline && input.type == Blockly.inputTypes.VALUE) { - activeRow.elements.push( - new Blockly.blockRendering.InlineInput(this.constants_, input)); + if (this.isInline && input.type == inputTypes.VALUE) { + activeRow.elements.push(new InlineInput(this.constants_, input)); activeRow.hasInlineInput = true; - } else if (input.type == Blockly.inputTypes.STATEMENT) { - activeRow.elements.push( - new Blockly.blockRendering.StatementInput(this.constants_, input)); + } else if (input.type == inputTypes.STATEMENT) { + activeRow.elements.push(new StatementInput(this.constants_, input)); activeRow.hasStatement = true; - } else if (input.type == Blockly.inputTypes.VALUE) { - activeRow.elements.push( - new Blockly.blockRendering.ExternalValueInput(this.constants_, input)); + } else if (input.type == inputTypes.VALUE) { + activeRow.elements.push(new ExternalValueInput(this.constants_, input)); activeRow.hasExternalInput = true; - } else if (input.type == Blockly.inputTypes.DUMMY) { + } else if (input.type == inputTypes.DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. activeRow.minHeight = Math.max(activeRow.minHeight, @@ -387,8 +377,8 @@ RenderInfo.prototype.addInput_ = function(input, activeRow) { /** * Decide whether to start a new row between the two Blockly.Inputs. - * @param {!Blockly.Input} input The first input to consider - * @param {Blockly.Input} lastInput The input that follows. + * @param {!Input} input The first input to consider + * @param {Input} lastInput The input that follows. * @return {boolean} True if the next input should be rendered on a new row. * @protected */ @@ -399,13 +389,12 @@ RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { return false; } // A statement input or an input following one always gets a new row. - if (input.type == Blockly.inputTypes.STATEMENT || - lastInput.type == Blockly.inputTypes.STATEMENT) { + if (input.type == inputTypes.STATEMENT || + lastInput.type == inputTypes.STATEMENT) { return true; } // Value and dummy inputs get new row if inputs are not inlined. - if (input.type == Blockly.inputTypes.VALUE || - input.type == Blockly.inputTypes.DUMMY) { + if (input.type == inputTypes.VALUE || input.type == inputTypes.DUMMY) { return !this.isInline; } return false; @@ -422,7 +411,7 @@ RenderInfo.prototype.addElemSpacing_ = function() { // No spacing needed before the corner on the top row or the bottom row. if (row.startsWithElemSpacer()) { // There's a spacer before the first element in the row. - row.elements.push(new Blockly.blockRendering.InRowSpacer( + row.elements.push(new InRowSpacer( this.constants_, this.getInRowSpacing_(null, oldElems[0]))); } if (!oldElems.length) { @@ -431,13 +420,12 @@ RenderInfo.prototype.addElemSpacing_ = function() { for (let e = 0; e < oldElems.length - 1; e++) { row.elements.push(oldElems[e]); const spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); - row.elements.push( - new Blockly.blockRendering.InRowSpacer(this.constants_, spacing)); + row.elements.push(new InRowSpacer(this.constants_, spacing)); } row.elements.push(oldElems[oldElems.length - 1]); if (row.endsWithElemSpacer()) { // There's a spacer after the last element in the row. - row.elements.push(new Blockly.blockRendering.InRowSpacer( + row.elements.push(new InRowSpacer( this.constants_, this.getInRowSpacing_(oldElems[oldElems.length - 1], null))); } @@ -448,42 +436,40 @@ RenderInfo.prototype.addElemSpacing_ = function() { * Calculate the width of a spacer element in a row based on the previous and * next elements in that row. For instance, extra padding is added between two * editable fields. - * @param {Blockly.blockRendering.Measurable} prev The element before the + * @param {Measurable} prev The element before the * spacer. - * @param {Blockly.blockRendering.Measurable} next The element after the spacer. + * @param {Measurable} next The element after the spacer. * @return {number} The size of the spacing between the two elements. * @protected */ RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Statement input padding. - if (next && Blockly.blockRendering.Types.isStatementInput(next)) { + if (next && Types.isStatementInput(next)) { return this.constants_.STATEMENT_INPUT_PADDING_LEFT; } } // Between inputs and the end of the row. - if (prev && Blockly.blockRendering.Types.isInput(prev) && !next) { - if (Blockly.blockRendering.Types.isExternalInput(prev)) { + if (prev && Types.isInput(prev) && !next) { + if (Types.isExternalInput(prev)) { return this.constants_.NO_PADDING; - } else if (Blockly.blockRendering.Types.isInlineInput(prev)) { + } else if (Types.isInlineInput(prev)) { return this.constants_.LARGE_PADDING; - } else if (Blockly.blockRendering.Types.isStatementInput(prev)) { + } else if (Types.isStatementInput(prev)) { return this.constants_.NO_PADDING; } } // Spacing between a square corner and a previous or next connection - if (prev && Blockly.blockRendering.Types.isLeftSquareCorner(prev) && next) { - if (Blockly.blockRendering.Types.isPreviousConnection(next) || - Blockly.blockRendering.Types.isNextConnection(next)) { + if (prev && Types.isLeftSquareCorner(prev) && next) { + if (Types.isPreviousConnection(next) || Types.isNextConnection(next)) { return next.notchOffset; } } // Spacing between a rounded corner and a previous or next connection. - if (prev && Blockly.blockRendering.Types.isLeftRoundedCorner(prev) && next) { - if (Blockly.blockRendering.Types.isPreviousConnection(next) || - Blockly.blockRendering.Types.isNextConnection(next)) { + if (prev && Types.isLeftRoundedCorner(prev) && next) { + if (Types.isPreviousConnection(next) || Types.isNextConnection(next)) { return next.notchOffset - this.constants_.CORNER_RADIUS; } } @@ -541,7 +527,7 @@ RenderInfo.prototype.alignRowElements_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( - /** @type {!Blockly.blockRendering.InputRow} */ (row)); + /** @type {!InputRow} */ (row)); } else { const currentWidth = row.width; const desiredWidth = this.getDesiredRowWidth_(row); @@ -549,7 +535,7 @@ RenderInfo.prototype.alignRowElements_ = function() { if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } - if (Blockly.blockRendering.Types.isTopOrBottomRow(row)) { + if (Types.isTopOrBottomRow(row)) { row.widthWithConnectedBlocks = row.width; } } @@ -558,7 +544,7 @@ RenderInfo.prototype.alignRowElements_ = function() { /** * Calculate the desired width of an input row. - * @param {!Blockly.blockRendering.Row} _row The input row. + * @param {!Row} _row The input row. * @return {number} The desired width of the input row. * @protected */ @@ -570,7 +556,7 @@ RenderInfo.prototype.getDesiredRowWidth_ = function(_row) { * Modify the given row to add the given amount of padding around its fields. * The exact location of the padding is based on the alignment property of the * last input in the field. - * @param {Blockly.blockRendering.Row} row The row to add padding to. + * @param {Row} row The row to add padding to. * @param {number} missingSpace How much padding to add. * @protected */ @@ -582,14 +568,14 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { } // Decide where the extra padding goes. - if (row.align == Blockly.constants.ALIGN.LEFT) { + if (row.align == blocklyConstants.ALIGN.LEFT) { // Add padding to the end of the row. lastSpacer.width += missingSpace; - } else if (row.align == Blockly.constants.ALIGN.CENTRE) { + } else if (row.align == blocklyConstants.ALIGN.CENTRE) { // Split the padding between the beginning and end of the row. firstSpacer.width += missingSpace / 2; lastSpacer.width += missingSpace / 2; - } else if (row.align == Blockly.constants.ALIGN.RIGHT) { + } else if (row.align == blocklyConstants.ALIGN.RIGHT) { // Add padding at the beginning of the row. firstSpacer.width += missingSpace; } else { @@ -602,7 +588,7 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { /** * Align the elements of a statement row based on computed bounds. * Unlike other types of rows, statement rows add space in multiple places. - * @param {!Blockly.blockRendering.InputRow} row The statement row to resize. + * @param {!InputRow} row The statement row to resize. * @protected */ RenderInfo.prototype.alignStatementRow_ = function(row) { @@ -643,16 +629,15 @@ RenderInfo.prototype.addRowSpacing_ = function() { /** * Create a spacer row to go between prev and next, and set its size. - * @param {!Blockly.blockRendering.Row} prev The previous row. - * @param {!Blockly.blockRendering.Row} next The next row. - * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. + * @param {!Row} prev The previous row. + * @param {!Row} next The next row. + * @return {!SpacerRow} The newly created spacer row. * @protected */ RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { const height = this.getSpacerRowHeight_(prev, next); const width = this.getSpacerRowWidth_(prev, next); - const spacer = - new Blockly.blockRendering.SpacerRow(this.constants_, height, width); + const spacer = new SpacerRow(this.constants_, height, width); if (prev.hasStatement) { spacer.followsStatement = true; } @@ -664,8 +649,8 @@ RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { /** * Calculate the width of a spacer row. - * @param {!Blockly.blockRendering.Row} _prev The row before the spacer. - * @param {!Blockly.blockRendering.Row} _next The row after the spacer. + * @param {!Row} _prev The row before the spacer. + * @param {!Row} _next The row after the spacer. * @return {number} The desired width of the spacer row between these two rows. * @protected */ @@ -675,8 +660,8 @@ RenderInfo.prototype.getSpacerRowWidth_ = function(_prev, _next) { /** * Calculate the height of a spacer row. - * @param {!Blockly.blockRendering.Row} _prev The row before the spacer. - * @param {!Blockly.blockRendering.Row} _next The row after the spacer. + * @param {!Row} _prev The row before the spacer. + * @param {!Row} _next The row after the spacer. * @return {number} The desired height of the spacer row between these two rows. * @protected */ @@ -689,25 +674,25 @@ RenderInfo.prototype.getSpacerRowHeight_ = function(_prev, _next) { * This base implementation puts the centerline at the middle of the row * vertically, with no special cases. You will likely need extra logic to * handle (at minimum) top and bottom rows. - * @param {!Blockly.blockRendering.Row} row The row containing the element. - * @param {!Blockly.blockRendering.Measurable} elem The element to place. + * @param {!Row} row The row containing the element. + * @param {!Measurable} elem The element to place. * @return {number} The desired centerline of the given element, as an offset * from the top left of the block. * @protected */ RenderInfo.prototype.getElemCenterline_ = function(row, elem) { - if (Blockly.blockRendering.Types.isSpacer(elem)) { + if (Types.isSpacer(elem)) { return row.yPos + elem.height / 2; } - if (Blockly.blockRendering.Types.isBottomRow(row)) { + if (Types.isBottomRow(row)) { const baseline = row.yPos + row.height - row.descenderHeight; - if (Blockly.blockRendering.Types.isNextConnection(elem)) { + if (Types.isNextConnection(elem)) { return baseline + elem.height / 2; } return baseline - elem.height / 2; } - if (Blockly.blockRendering.Types.isTopRow(row)) { - if (Blockly.blockRendering.Types.isHat(elem)) { + if (Types.isTopRow(row)) { + if (Types.isHat(elem)) { return row.capline - elem.height / 2; } return row.capline + elem.height / 2; @@ -718,14 +703,14 @@ RenderInfo.prototype.getElemCenterline_ = function(row, elem) { /** * Record final position information on elements on the given row, for use in * drawing. At minimum this records xPos and centerline on each element. - * @param {!Blockly.blockRendering.Row} row The row containing the elements. + * @param {!Row} row The row containing the elements. * @protected */ RenderInfo.prototype.recordElemPositions_ = function(row) { let xCursor = row.xPos; for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. - if (Blockly.blockRendering.Types.isSpacer(elem)) { + if (Types.isSpacer(elem)) { elem.height = row.height; } elem.xPos = xCursor; diff --git a/tests/deps.js b/tests/deps.js index 8baeee5ab..f2de1b0f9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); From f7a5d809bc3e37fd736aa29c7c35a47791c569d0 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 15:14:32 -0700 Subject: [PATCH 083/313] clang-format core/renderers/common/info.js --- core/renderers/common/info.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 3c5e70ee4..146ca5cdd 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -313,7 +313,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { // greater height it will be overwritten in the compute pass. if (followsStatement) { this.bottomRow.minHeight = - this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT; + this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT; } else { this.bottomRow.minHeight = this.constants_.BOTTOM_ROW_MIN_HEIGHT; } @@ -364,10 +364,11 @@ RenderInfo.prototype.addInput_ = function(input, activeRow) { } else if (input.type == inputTypes.DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. - activeRow.minHeight = Math.max(activeRow.minHeight, + activeRow.minHeight = Math.max( + activeRow.minHeight, input.getSourceBlock() && input.getSourceBlock().isShadow() ? - this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT : - this.constants_.DUMMY_INPUT_MIN_HEIGHT); + this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT : + this.constants_.DUMMY_INPUT_MIN_HEIGHT); activeRow.hasDummyInput = true; } if (activeRow.align == null) { @@ -478,8 +479,8 @@ RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { }; /** - * Figure out where the right edge of the block and right edge of statement inputs - * should be placed. + * Figure out where the right edge of the block and right edge of statement + * inputs should be placed. * @protected */ // TODO: More cleanup. @@ -607,8 +608,8 @@ RenderInfo.prototype.alignStatementRow_ = function(row) { statementInput.width += (desiredWidth - currentWidth); statementInput.height = Math.max(statementInput.height, row.height); row.width += (desiredWidth - currentWidth); - row.widthWithConnectedBlocks = Math.max(row.width, - this.statementEdge + row.connectedBlockWidths); + row.widthWithConnectedBlocks = + Math.max(row.width, this.statementEdge + row.connectedBlockWidths); }; /** @@ -742,9 +743,9 @@ RenderInfo.prototype.finalize_ = function() { if (this.outputConnection && this.block_.nextConnection && this.block_.nextConnection.isConnected()) { // Include width of connected block in value to stack width measurement. - widestRowWithConnectedBlocks = - Math.max(widestRowWithConnectedBlocks, - this.block_.nextConnection.targetBlock().getHeightWidth().width); + widestRowWithConnectedBlocks = Math.max( + widestRowWithConnectedBlocks, + this.block_.nextConnection.targetBlock().getHeightWidth().width); } this.widthWithChildren = widestRowWithConnectedBlocks + this.startX; From dbf6308f03e6db01eb77022c7891879665dea9f9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:36:34 -0700 Subject: [PATCH 084/313] 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 085/313] 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 086/313] 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 c6112df77a17f8e130c43cd1959e3391cea41fdf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 09:16:29 -0700 Subject: [PATCH 087/313] Switch some requires in core/comment.js to destructuring --- core/comment.js | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/core/comment.js b/core/comment.js index fe0c940a6..de947fa5f 100644 --- a/core/comment.js +++ b/core/comment.js @@ -15,19 +15,17 @@ goog.module.declareLegacyNamespace(); const Block = goog.requireType('Blockly.Block'); const BlockSvg = goog.requireType('Blockly.BlockSvg'); -const browserEvents = goog.require('Blockly.browserEvents'); const Bubble = goog.require('Blockly.Bubble'); const Coordinate = goog.requireType('Blockly.utils.Coordinate'); -const Css = goog.require('Blockly.Css'); -const dom = goog.require('Blockly.utils.dom'); const Events = goog.require('Blockly.Events'); const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); -const userAgent = goog.require('Blockly.utils.userAgent'); -const utilsObject = goog.require('Blockly.utils.object'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const {CommentModel} = goog.requireType('Blockly.Block'); +const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); +const {dom, userAgent, object: utilsObject} = goog.require('Blockly.utils'); +const {register} = goog.require('Blockly.Css'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -65,28 +63,28 @@ const Comment = function(block) { /** * Mouse up event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onMouseUpWrapper_ = null; /** * Wheel event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onWheelWrapper_ = null; /** * Change event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onChangeWrapper_ = null; /** * Input event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onInputWrapper_ = null; @@ -167,25 +165,23 @@ Comment.prototype.createEditor_ = function() { // Ideally this would be hooked to the focus event for the comment. // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. - this.onMouseUpWrapper_ = browserEvents.conditionalBind( - textarea, 'mouseup', this, this.startEdit_, true, true); + this.onMouseUpWrapper_ = + conditionalBind(textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = - browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { - e.stopPropagation(); - }); + this.onWheelWrapper_ = conditionalBind(textarea, 'wheel', this, function(e) { + e.stopPropagation(); + }); this.onChangeWrapper_ = - browserEvents.conditionalBind(textarea, 'change', this, function(_e) { + conditionalBind(textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this.block_, 'comment', null, this.cachedText_, this.model_.text)); } }); - this.onInputWrapper_ = - browserEvents.conditionalBind(textarea, 'input', this, function(_e) { - this.model_.text = textarea.value; - }); + this.onInputWrapper_ = conditionalBind(textarea, 'input', this, function(_e) { + this.model_.text = textarea.value; + }); setTimeout(textarea.focus.bind(textarea), 0); @@ -304,19 +300,19 @@ Comment.prototype.createNonEditableBubble_ = function() { */ Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { - browserEvents.unbind(this.onMouseUpWrapper_); + unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; } if (this.onWheelWrapper_) { - browserEvents.unbind(this.onWheelWrapper_); + unbind(this.onWheelWrapper_); this.onWheelWrapper_ = null; } if (this.onChangeWrapper_) { - browserEvents.unbind(this.onChangeWrapper_); + unbind(this.onChangeWrapper_); this.onChangeWrapper_ = null; } if (this.onInputWrapper_) { - browserEvents.unbind(this.onInputWrapper_); + unbind(this.onInputWrapper_); this.onInputWrapper_ = null; } this.bubble_.dispose(); @@ -394,7 +390,7 @@ Comment.prototype.dispose = function() { /** * CSS for block comment. See css.js for use. */ -Css.register([ +register([ /* eslint-disable indent */ '.blocklyCommentTextarea {', 'background-color: #fef49c;', From 11b47aab2537c1ad8b26eb815f357717729e9bff Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:39:35 -0700 Subject: [PATCH 088/313] 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 089/313] 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 090/313] 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 091/313] 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 092/313] 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 093/313] 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 094/313] 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 095/313] 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 096/313] 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 097/313] 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 098/313] 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 099/313] 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 100/313] 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 101/313] 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 102/313] 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 103/313] 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 104/313] 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 105/313] 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 106/313] 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'}); From f77d5f12647fcfa3c9d262cd32187a4539bf1886 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 10:49:20 -0700 Subject: [PATCH 107/313] Migrate core/connection_db.js to ES6 const/let --- core/connection_db.js | 52 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/core/connection_db.js b/core/connection_db.js index 4b2615725..b6d990af1 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -56,7 +56,7 @@ Blockly.ConnectionDB = function(checker) { * @package */ Blockly.ConnectionDB.prototype.addConnection = function(connection, yPos) { - var index = this.calculateIndexForYPos_(yPos); + const index = this.calculateIndexForYPos_(yPos); this.connections_.splice(index, 0, connection); }; @@ -76,7 +76,7 @@ Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { return -1; } - var bestGuess = this.calculateIndexForYPos_(yPos); + const bestGuess = this.calculateIndexForYPos_(yPos); if (bestGuess >= this.connections_.length) { // Not in list return -1; @@ -84,7 +84,7 @@ Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { yPos = conn.y; // Walk forward and back on the y axis looking for the connection. - var pointer = bestGuess; + let pointer = bestGuess; while (pointer >= 0 && this.connections_[pointer].y == yPos) { if (this.connections_[pointer] == conn) { return pointer; @@ -114,10 +114,10 @@ Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { if (!this.connections_.length) { return 0; } - var pointerMin = 0; - var pointerMax = this.connections_.length; + let pointerMin = 0; + let pointerMax = this.connections_.length; while (pointerMin < pointerMax) { - var pointerMid = Math.floor((pointerMin + pointerMax) / 2); + const pointerMid = Math.floor((pointerMin + pointerMax) / 2); if (this.connections_[pointerMid].y < yPos) { pointerMin = pointerMid + 1; } else if (this.connections_[pointerMid].y > yPos) { @@ -137,7 +137,7 @@ Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { * @throws {Error} If the connection cannot be found in the database. */ Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) { - var index = this.findIndexOfConnection_(connection, yPos); + const index = this.findIndexOfConnection_(connection, yPos); if (index == -1) { throw Error('Unable to find connection in connectionDB.'); } @@ -153,14 +153,14 @@ Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) { * @return {!Array} List of connections. */ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { - var db = this.connections_; - var currentX = connection.x; - var currentY = connection.y; + const db = this.connections_; + const currentX = connection.x; + const currentY = connection.y; // Binary search to find the closest y location. - var pointerMin = 0; - var pointerMax = db.length - 2; - var pointerMid = pointerMax; + let pointerMin = 0; + let pointerMax = db.length - 2; + let pointerMid = pointerMax; while (pointerMin < pointerMid) { if (db[pointerMid].y < currentY) { pointerMin = pointerMid; @@ -170,7 +170,7 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { pointerMid = Math.floor((pointerMin + pointerMax) / 2); } - var neighbours = []; + const neighbours = []; /** * Computes if the current connection is within the allowed radius of another * connection. @@ -180,9 +180,9 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { * the other connection is less than the allowed radius. */ function checkConnection_(yIndex) { - var dx = currentX - db[yIndex].x; - var dy = currentY - db[yIndex].y; - var r = Math.sqrt(dx * dx + dy * dy); + const dx = currentX - db[yIndex].x; + const dy = currentY - db[yIndex].y; + const r = Math.sqrt(dx * dx + dy * dy); if (r <= maxRadius) { neighbours.push(db[yIndex]); } @@ -237,8 +237,8 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, } // Stash the values of x and y from before the drag. - var baseY = conn.y; - var baseX = conn.x; + const baseY = conn.y; + const baseX = conn.x; conn.x = baseX + dxy.x; conn.y = baseY + dxy.y; @@ -246,14 +246,14 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, // calculateIndexForYPos_ finds an index for insertion, which is always // after any block with the same y index. We want to search both forward // and back, so search on both sides of the index. - var closestIndex = this.calculateIndexForYPos_(conn.y); + const closestIndex = this.calculateIndexForYPos_(conn.y); - var bestConnection = null; - var bestRadius = maxRadius; - var temp; + let bestConnection = null; + let bestRadius = maxRadius; + let temp; // Walk forward and back on the y axis looking for the closest x,y point. - var pointerMin = closestIndex - 1; + let pointerMin = closestIndex - 1; while (pointerMin >= 0 && this.isInYRange_(pointerMin, conn.y, maxRadius)) { temp = this.connections_[pointerMin]; if (this.connectionChecker_.canConnect(conn, temp, true, bestRadius)) { @@ -263,7 +263,7 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, pointerMin--; } - var pointerMax = closestIndex; + let pointerMax = closestIndex; while (pointerMax < this.connections_.length && this.isInYRange_(pointerMax, conn.y, maxRadius)) { temp = this.connections_[pointerMax]; @@ -290,7 +290,7 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, */ Blockly.ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. - var dbList = []; + const dbList = []; dbList[Blockly.connectionTypes.INPUT_VALUE] = new Blockly.ConnectionDB(checker); dbList[Blockly.connectionTypes.OUTPUT_VALUE] = From a87b2b0bfa8cb88cc8dec88362b9c0ee4b05a888 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 10:53:42 -0700 Subject: [PATCH 108/313] Migrate core/connection_db.js to goog.module --- core/connection_db.js | 33 ++++++++++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/connection_db.js b/core/connection_db.js index b6d990af1..81782397b 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.ConnectionDB'); +goog.module('Blockly.ConnectionDB'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ @@ -32,7 +33,7 @@ goog.requireType('Blockly.utils.Coordinate'); * drag. * @constructor */ -Blockly.ConnectionDB = function(checker) { +const ConnectionDB = function(checker) { /** * Array of connections sorted by y position in workspace units. * @type {!Array} @@ -55,7 +56,7 @@ Blockly.ConnectionDB = function(checker) { * connection. * @package */ -Blockly.ConnectionDB.prototype.addConnection = function(connection, yPos) { +ConnectionDB.prototype.addConnection = function(connection, yPos) { const index = this.calculateIndexForYPos_(yPos); this.connections_.splice(index, 0, connection); }; @@ -71,7 +72,7 @@ Blockly.ConnectionDB.prototype.addConnection = function(connection, yPos) { * not found. * @private */ -Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { +ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { if (!this.connections_.length) { return -1; } @@ -110,7 +111,7 @@ Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { * @return {number} The candidate index. * @private */ -Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { +ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { if (!this.connections_.length) { return 0; } @@ -136,7 +137,7 @@ Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { * @param {number} yPos The y position used to find the index of the connection. * @throws {Error} If the connection cannot be found in the database. */ -Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) { +ConnectionDB.prototype.removeConnection = function(connection, yPos) { const index = this.findIndexOfConnection_(connection, yPos); if (index == -1) { throw Error('Unable to find connection in connectionDB.'); @@ -152,7 +153,7 @@ Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) { * @param {number} maxRadius The maximum radius to another connection. * @return {!Array} List of connections. */ -Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { +ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { const db = this.connections_; const currentX = connection.x; const currentY = connection.y; @@ -213,7 +214,7 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { * @return {boolean} True if connection is in range. * @private */ -Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { +ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { return (Math.abs(this.connections_[index].y - baseY) <= maxRadius); }; @@ -229,7 +230,7 @@ Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { * Contains two properties: 'connection' which is either another * connection or null, and 'radius' which is the distance. */ -Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, +ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dxy) { if (!this.connections_.length) { // Don't bother. @@ -286,18 +287,20 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, * Initialize a set of connection DBs for a workspace. * @param {!Blockly.IConnectionChecker} checker The workspace's * connection checker, used to decide if connections are valid during a drag. - * @return {!Array} Array of databases. + * @return {!Array} Array of databases. */ -Blockly.ConnectionDB.init = function(checker) { +ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. const dbList = []; dbList[Blockly.connectionTypes.INPUT_VALUE] = - new Blockly.ConnectionDB(checker); + new ConnectionDB(checker); dbList[Blockly.connectionTypes.OUTPUT_VALUE] = - new Blockly.ConnectionDB(checker); + new ConnectionDB(checker); dbList[Blockly.connectionTypes.NEXT_STATEMENT] = - new Blockly.ConnectionDB(checker); + new ConnectionDB(checker); dbList[Blockly.connectionTypes.PREVIOUS_STATEMENT] = - new Blockly.ConnectionDB(checker); + new ConnectionDB(checker); return dbList; }; + +exports = ConnectionDB; diff --git a/tests/deps.js b/tests/deps.js index cdeae73f4..7531e34ae 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -21,7 +21,7 @@ goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubbl 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'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); +goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); From acd7e5596898e39097a7a91faf2760226137ba25 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 10:59:08 -0700 Subject: [PATCH 109/313] Migrate core/connection_db.js to named requires --- core/connection_db.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/core/connection_db.js b/core/connection_db.js index 81782397b..0493cf077 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -15,20 +15,19 @@ goog.module('Blockly.ConnectionDB'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +const RenderedConnection = goog.require('Blockly.RenderedConnection'); +const connectionTypes = goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.RenderedConnection'); - -goog.requireType('Blockly.IConnectionChecker'); -goog.requireType('Blockly.utils.Coordinate'); /** * Database of connections. * Connections are stored in order of their vertical component. This way * connections in an area may be looked up quickly using a binary search. - * @param {!Blockly.IConnectionChecker} checker The workspace's + * @param {!IConnectionChecker} checker The workspace's * connection type checker, used to decide if connections are valid during a * drag. * @constructor @@ -36,14 +35,14 @@ goog.requireType('Blockly.utils.Coordinate'); const ConnectionDB = function(checker) { /** * Array of connections sorted by y position in workspace units. - * @type {!Array} + * @type {!Array} * @private */ this.connections_ = []; /** * The workspace's connection type checker, used to decide if connections are * valid during a drag. - * @type {!Blockly.IConnectionChecker} + * @type {!IConnectionChecker} * @private */ this.connectionChecker_ = checker; @@ -51,7 +50,7 @@ const ConnectionDB = function(checker) { /** * Add a connection to the database. Should not already exist in the database. - * @param {!Blockly.RenderedConnection} connection The connection to be added. + * @param {!RenderedConnection} connection The connection to be added. * @param {number} yPos The y position used to decide where to insert the * connection. * @package @@ -66,7 +65,7 @@ ConnectionDB.prototype.addConnection = function(connection, yPos) { * * Starts by doing a binary search to find the approximate location, then * linearly searches nearby for the exact connection. - * @param {!Blockly.RenderedConnection} conn The connection to find. + * @param {!RenderedConnection} conn The connection to find. * @param {number} yPos The y position used to find the index of the connection. * @return {number} The index of the connection, or -1 if the connection was * not found. @@ -133,7 +132,7 @@ ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { /** * Remove a connection from the database. Must already exist in DB. - * @param {!Blockly.RenderedConnection} connection The connection to be removed. + * @param {!RenderedConnection} connection The connection to be removed. * @param {number} yPos The y position used to find the index of the connection. * @throws {Error} If the connection cannot be found in the database. */ @@ -148,10 +147,10 @@ ConnectionDB.prototype.removeConnection = function(connection, yPos) { /** * Find all nearby connections to the given connection. * Type checking does not apply, since this function is used for bumping. - * @param {!Blockly.RenderedConnection} connection The connection whose + * @param {!RenderedConnection} connection The connection whose * neighbours should be returned. * @param {number} maxRadius The maximum radius to another connection. - * @return {!Array} List of connections. + * @return {!Array} List of connections. */ ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { const db = this.connections_; @@ -220,13 +219,13 @@ ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { /** * Find the closest compatible connection to this connection. - * @param {!Blockly.RenderedConnection} conn The connection searching for a compatible + * @param {!RenderedConnection} conn The connection searching for a compatible * mate. * @param {number} maxRadius The maximum radius to another connection. - * @param {!Blockly.utils.Coordinate} dxy Offset between this connection's + * @param {!Coordinate} dxy Offset between this connection's * location in the database and the current location (as a result of * dragging). - * @return {!{connection: Blockly.RenderedConnection, radius: number}} + * @return {!{connection: RenderedConnection, radius: number}} * Contains two properties: 'connection' which is either another * connection or null, and 'radius' which is the distance. */ @@ -285,20 +284,20 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, /** * Initialize a set of connection DBs for a workspace. - * @param {!Blockly.IConnectionChecker} checker The workspace's + * @param {!IConnectionChecker} checker The workspace's * connection checker, used to decide if connections are valid during a drag. * @return {!Array} Array of databases. */ ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. const dbList = []; - dbList[Blockly.connectionTypes.INPUT_VALUE] = + dbList[connectionTypes.INPUT_VALUE] = new ConnectionDB(checker); - dbList[Blockly.connectionTypes.OUTPUT_VALUE] = + dbList[connectionTypes.OUTPUT_VALUE] = new ConnectionDB(checker); - dbList[Blockly.connectionTypes.NEXT_STATEMENT] = + dbList[connectionTypes.NEXT_STATEMENT] = new ConnectionDB(checker); - dbList[Blockly.connectionTypes.PREVIOUS_STATEMENT] = + dbList[connectionTypes.PREVIOUS_STATEMENT] = new ConnectionDB(checker); return dbList; }; From f2ca65944763ac76339eadb708d0caca8db447cc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 10:59:44 -0700 Subject: [PATCH 110/313] clang-format core/connection_db.js --- core/connection_db.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/core/connection_db.js b/core/connection_db.js index 0493cf077..abc47beb3 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -229,8 +229,7 @@ ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { * Contains two properties: 'connection' which is either another * connection or null, and 'radius' which is the distance. */ -ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, - dxy) { +ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dxy) { if (!this.connections_.length) { // Don't bother. return {connection: null, radius: maxRadius}; @@ -265,7 +264,7 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, let pointerMax = closestIndex; while (pointerMax < this.connections_.length && - this.isInYRange_(pointerMax, conn.y, maxRadius)) { + this.isInYRange_(pointerMax, conn.y, maxRadius)) { temp = this.connections_[pointerMax]; if (this.connectionChecker_.canConnect(conn, temp, true, bestRadius)) { bestConnection = temp; @@ -285,20 +284,17 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, /** * Initialize a set of connection DBs for a workspace. * @param {!IConnectionChecker} checker The workspace's - * connection checker, used to decide if connections are valid during a drag. + * connection checker, used to decide if connections are valid during a + * drag. * @return {!Array} Array of databases. */ ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. const dbList = []; - dbList[connectionTypes.INPUT_VALUE] = - new ConnectionDB(checker); - dbList[connectionTypes.OUTPUT_VALUE] = - new ConnectionDB(checker); - dbList[connectionTypes.NEXT_STATEMENT] = - new ConnectionDB(checker); - dbList[connectionTypes.PREVIOUS_STATEMENT] = - new ConnectionDB(checker); + dbList[connectionTypes.INPUT_VALUE] = new ConnectionDB(checker); + dbList[connectionTypes.OUTPUT_VALUE] = new ConnectionDB(checker); + dbList[connectionTypes.NEXT_STATEMENT] = new ConnectionDB(checker); + dbList[connectionTypes.PREVIOUS_STATEMENT] = new ConnectionDB(checker); return dbList; }; From 8afef7f59861c0b0af34f99dee6e36aa0fd19607 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 19 Jul 2021 13:29:45 -0700 Subject: [PATCH 111/313] Destructure some requires --- core/renderers/common/info.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 146ca5cdd..1cc61af85 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -23,7 +23,6 @@ const Icon = goog.require('Blockly.blockRendering.Icon'); const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); const Input = goog.requireType('Blockly.Input'); const InputRow = goog.require('Blockly.blockRendering.InputRow'); -const inputTypes = goog.require('Blockly.inputTypes'); const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); const Measurable = goog.require('Blockly.blockRendering.Measurable'); @@ -39,8 +38,9 @@ const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); const TopRow = goog.require('Blockly.blockRendering.TopRow'); const Types = goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -const blocklyConstants = goog.require('Blockly.constants'); +const {ALIGN} = goog.require('Blockly.constants'); +const {VALUE, STATEMENT, DUMMY} = goog.require('Blockly.inputTypes'); + /** @@ -282,7 +282,7 @@ RenderInfo.prototype.populateTopRow_ = function() { } const precedesStatement = this.block_.inputList.length && - this.block_.inputList[0].type == inputTypes.STATEMENT; + this.block_.inputList[0].type == STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -306,8 +306,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; const followsStatement = this.block_.inputList.length && - this.block_.inputList[this.block_.inputList.length - 1].type == - inputTypes.STATEMENT; + this.block_.inputList[this.block_.inputList.length - 1].type == STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -352,16 +351,16 @@ RenderInfo.prototype.populateBottomRow_ = function() { */ RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. - if (this.isInline && input.type == inputTypes.VALUE) { + if (this.isInline && input.type == VALUE) { activeRow.elements.push(new InlineInput(this.constants_, input)); activeRow.hasInlineInput = true; - } else if (input.type == inputTypes.STATEMENT) { + } else if (input.type == STATEMENT) { activeRow.elements.push(new StatementInput(this.constants_, input)); activeRow.hasStatement = true; - } else if (input.type == inputTypes.VALUE) { + } else if (input.type == VALUE) { activeRow.elements.push(new ExternalValueInput(this.constants_, input)); activeRow.hasExternalInput = true; - } else if (input.type == inputTypes.DUMMY) { + } else if (input.type == DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. activeRow.minHeight = Math.max( @@ -390,12 +389,11 @@ RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { return false; } // A statement input or an input following one always gets a new row. - if (input.type == inputTypes.STATEMENT || - lastInput.type == inputTypes.STATEMENT) { + if (input.type == STATEMENT || lastInput.type == STATEMENT) { return true; } // Value and dummy inputs get new row if inputs are not inlined. - if (input.type == inputTypes.VALUE || input.type == inputTypes.DUMMY) { + if (input.type == VALUE || input.type == DUMMY) { return !this.isInline; } return false; @@ -569,14 +567,14 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { } // Decide where the extra padding goes. - if (row.align == blocklyConstants.ALIGN.LEFT) { + if (row.align == ALIGN.LEFT) { // Add padding to the end of the row. lastSpacer.width += missingSpace; - } else if (row.align == blocklyConstants.ALIGN.CENTRE) { + } else if (row.align == ALIGN.CENTRE) { // Split the padding between the beginning and end of the row. firstSpacer.width += missingSpace / 2; lastSpacer.width += missingSpace / 2; - } else if (row.align == blocklyConstants.ALIGN.RIGHT) { + } else if (row.align == ALIGN.RIGHT) { // Add padding at the beginning of the row. firstSpacer.width += missingSpace; } else { From 268a83d054a0c62e6a67a0b5062c037237cb1dda Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Mon, 19 Jul 2021 13:40:05 -0700 Subject: [PATCH 112/313] Address PR comments --- core/utils/toolbox.js | 8 ++++---- tests/deps.js | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index ec050d178..aab51d826 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -17,7 +17,7 @@ goog.module('Blockly.utils.toolbox'); goog.module.declareLegacyNamespace(); -const {IE} = goog.require('Blockly.utils.userAgent'); +const userAgent = goog.require('Blockly.utils.userAgent'); const {textToDom} = goog.require('Blockly.Xml'); const {CssConfig: CategoryCssConfig} = goog.requireType('Blockly.ToolboxCategory'); @@ -273,7 +273,7 @@ const hasCategories = function(toolboxJson) { return false; } - let toolboxKind = toolboxJson['kind']; + const toolboxKind = toolboxJson['kind']; if (toolboxKind) { return toolboxKind == CATEGORY_TOOLBOX_KIND; } @@ -387,7 +387,7 @@ const addAttributes = function(node, obj) { const parseToolboxTree = function(toolboxDef) { if (toolboxDef) { if (typeof toolboxDef != 'string') { - if (IE && toolboxDef.outerHTML) { + if (userAgent.IE && toolboxDef.outerHTML) { // In this case the tree will not have been properly built by the // browser. The HTML will be contained in the element, but it will // not have the proper DOM structure since the browser doesn't support @@ -430,4 +430,4 @@ exports = { hasCategories, isCategoryCollapsible, parseToolboxTree -} +}; diff --git a/tests/deps.js b/tests/deps.js index 3d4531cf1..00ce56da3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -4,7 +4,6 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Co goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); -goog.addDependency('../../blocks/test_blocks.js', ['Blockly.TestBlocks'], ['Blockly', 'Blockly.Blocks'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); From ac1fb9a4ddd628d630ce0a049371f15b42884623 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 13:53:47 -0700 Subject: [PATCH 113/313] Revise imports in core/comment.js --- core/comment.js | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/core/comment.js b/core/comment.js index de947fa5f..7caf61614 100644 --- a/core/comment.js +++ b/core/comment.js @@ -22,10 +22,11 @@ const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); -const {CommentModel} = goog.requireType('Blockly.Block'); const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); -const {dom, userAgent, object: utilsObject} = goog.require('Blockly.utils'); +const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); const {register} = goog.require('Blockly.Css'); +const {IE} = goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -45,7 +46,7 @@ const Comment = function(block) { /** * The model for this comment. - * @type {!CommentModel} + * @type {!Block.CommentModel} * @private */ this.model_ = block.commentModel; @@ -91,7 +92,7 @@ const Comment = function(block) { this.createIcon(); }; -utilsObject.inherits(Comment, Icon); +inherits(Comment, Icon); /** * Draw the comment icon. @@ -100,13 +101,13 @@ utilsObject.inherits(Comment, Icon); */ Comment.prototype.drawIcon_ = function(group) { // Circle. - dom.createSvgElement( + createSvgElement( Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. - dom.createSvgElement( + createSvgElement( Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + @@ -115,7 +116,7 @@ Comment.prototype.drawIcon_ = function(group) { }, group); // Dot of question mark. - dom.createSvgElement( + createSvgElement( Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', @@ -144,15 +145,15 @@ Comment.prototype.createEditor_ = function() { * For non-editable mode see Warning.textToDom_. */ - this.foreignObject_ = dom.createSvgElement( + this.foreignObject_ = createSvgElement( Svg.FOREIGNOBJECT, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); - const body = document.createElementNS(dom.HTML_NS, 'body'); - body.setAttribute('xmlns', dom.HTML_NS); + const body = document.createElementNS(HTML_NS, 'body'); + body.setAttribute('xmlns', HTML_NS); body.className = 'blocklyMinimalBody'; - this.textarea_ = document.createElementNS(dom.HTML_NS, 'textarea'); + this.textarea_ = document.createElementNS(HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -253,7 +254,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || userAgent.IE) { + if (!this.block_.isEditable() || IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable. @@ -392,16 +393,9 @@ Comment.prototype.dispose = function() { */ register([ /* eslint-disable indent */ - '.blocklyCommentTextarea {', - 'background-color: #fef49c;', - 'border: 0;', - 'outline: 0;', - 'margin: 0;', - 'padding: 3px;', - 'resize: none;', - 'display: block;', - 'text-overflow: hidden;', - '}' + '.blocklyCommentTextarea {', 'background-color: #fef49c;', 'border: 0;', + 'outline: 0;', 'margin: 0;', 'padding: 3px;', 'resize: none;', + 'display: block;', 'text-overflow: hidden;', '}' /* eslint-enable indent */ ]); From a8cba441e7d2a7766b4b5941a2519ce0e45e61af Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 14:33:15 -0700 Subject: [PATCH 114/313] Fix comment indentation in core/connection_db.js --- core/connection_db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/connection_db.js b/core/connection_db.js index abc47beb3..49bccb504 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -285,7 +285,7 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dxy) { * Initialize a set of connection DBs for a workspace. * @param {!IConnectionChecker} checker The workspace's * connection checker, used to decide if connections are valid during a - * drag. + * drag. * @return {!Array} Array of databases. */ ConnectionDB.init = function(checker) { From 583e321647b14f58501c2773177e516601fd57ed Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:38:22 -0700 Subject: [PATCH 115/313] Migrate core/interfaces/i_flyout.js to goog.module --- core/interfaces/i_flyout.js | 55 +++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/interfaces/i_flyout.js b/core/interfaces/i_flyout.js index b819c3347..7a05fb9da 100644 --- a/core/interfaces/i_flyout.js +++ b/core/interfaces/i_flyout.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IFlyout'); +goog.module('Blockly.IFlyout'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.IRegistrable'); @@ -26,45 +27,45 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.IRegistrable} * @interface */ -Blockly.IFlyout = function() {}; +const IFlyout = function() {}; /** * Whether the flyout is laid out horizontally or not. * @type {boolean} */ -Blockly.IFlyout.prototype.horizontalLayout; +IFlyout.prototype.horizontalLayout; /** * Is RTL vs LTR. * @type {boolean} */ -Blockly.IFlyout.prototype.RTL; +IFlyout.prototype.RTL; /** * The target workspace * @type {?Blockly.WorkspaceSvg} */ -Blockly.IFlyout.prototype.targetWorkspace; +IFlyout.prototype.targetWorkspace; /** * Margin around the edges of the blocks in the flyout. * @type {number} * @const */ -Blockly.IFlyout.prototype.MARGIN; +IFlyout.prototype.MARGIN; /** * Does the flyout automatically close when a block is created? * @type {boolean} */ -Blockly.IFlyout.prototype.autoClose; +IFlyout.prototype.autoClose; /** * Corner radius of the flyout background. * @type {number} * @const */ -Blockly.IFlyout.prototype.CORNER_RADIUS; +IFlyout.prototype.CORNER_RADIUS; /** * Creates the flyout's DOM. Only needs to be called once. The flyout can @@ -76,62 +77,62 @@ Blockly.IFlyout.prototype.CORNER_RADIUS; * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ -Blockly.IFlyout.prototype.createDom; +IFlyout.prototype.createDom; /** * Initializes the flyout. * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ -Blockly.IFlyout.prototype.init; +IFlyout.prototype.init; /** * Dispose of this flyout. * Unlink from all DOM elements to prevent memory leaks. */ -Blockly.IFlyout.prototype.dispose; +IFlyout.prototype.dispose; /** * Get the width of the flyout. * @return {number} The width of the flyout. */ -Blockly.IFlyout.prototype.getWidth; +IFlyout.prototype.getWidth; /** * Get the height of the flyout. * @return {number} The width of the flyout. */ -Blockly.IFlyout.prototype.getHeight; +IFlyout.prototype.getHeight; /** * Get the workspace inside the flyout. * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. */ -Blockly.IFlyout.prototype.getWorkspace; +IFlyout.prototype.getWorkspace; /** * Is the flyout visible? * @return {boolean} True if visible. */ -Blockly.IFlyout.prototype.isVisible; +IFlyout.prototype.isVisible; /** * Set whether the flyout is visible. A value of true does not necessarily mean * that the flyout is shown. It could be hidden because its container is hidden. * @param {boolean} visible True if visible. */ -Blockly.IFlyout.prototype.setVisible; +IFlyout.prototype.setVisible; /** * Set whether this flyout's container is visible. * @param {boolean} visible Whether the container is visible. */ -Blockly.IFlyout.prototype.setContainerVisible; +IFlyout.prototype.setContainerVisible; /** * Hide and empty the flyout. */ -Blockly.IFlyout.prototype.hide; +IFlyout.prototype.hide; /** * Show and populate the flyout. @@ -139,7 +140,7 @@ Blockly.IFlyout.prototype.hide; * display in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ -Blockly.IFlyout.prototype.show; +IFlyout.prototype.show; /** * Create a copy of this block on the workspace. @@ -147,36 +148,36 @@ Blockly.IFlyout.prototype.show; * @return {!Blockly.BlockSvg} The newly created block. * @throws {Error} if something went wrong with deserialization. */ -Blockly.IFlyout.prototype.createBlock; +IFlyout.prototype.createBlock; /** * Reflow blocks and their mats. */ -Blockly.IFlyout.prototype.reflow; +IFlyout.prototype.reflow; /** * @return {boolean} True if this flyout may be scrolled with a scrollbar or by * dragging. */ -Blockly.IFlyout.prototype.isScrollable; +IFlyout.prototype.isScrollable; /** * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.IFlyout.prototype.getX; +IFlyout.prototype.getX; /** * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.IFlyout.prototype.getY; +IFlyout.prototype.getY; /** * Position the flyout. * @return {void} */ -Blockly.IFlyout.prototype.position; +IFlyout.prototype.position; /** * Determine if a drag delta is toward the workspace, based on the position @@ -186,4 +187,6 @@ Blockly.IFlyout.prototype.position; * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. */ -Blockly.IFlyout.prototype.isDragTowardWorkspace; +IFlyout.prototype.isDragTowardWorkspace; + +exports = IFlyout; diff --git a/tests/deps.js b/tests/deps.js index b4d64e1fa..3163a584c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -88,7 +88,7 @@ goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable' 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'], {'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_flyout.js', ['Blockly.IFlyout'], [], {'lang': 'es6', 'module': 'goog'}); 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'}); From d55ce5922441f0926915ebb2a0f7e20f6e4eb0eb Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:09:04 -0700 Subject: [PATCH 116/313] Migrate core/interfaces/i_flyout.js named requires --- core/interfaces/i_flyout.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/interfaces/i_flyout.js b/core/interfaces/i_flyout.js index 7a05fb9da..b9b1c8e15 100644 --- a/core/interfaces/i_flyout.js +++ b/core/interfaces/i_flyout.js @@ -14,17 +14,17 @@ goog.module('Blockly.IFlyout'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.IRegistrable'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.utils.Svg'); -goog.requireType('Blockly.utils.toolbox'); -goog.requireType('Blockly.WorkspaceSvg'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const IRegistrable = goog.require('Blockly.IRegistrable'); +const Svg = goog.requireType('Blockly.utils.Svg'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {FlyoutDefinition} = goog.requireType('Blockly.utils.toolbox'); /** * Interface for a flyout. - * @extends {Blockly.IRegistrable} + * @extends {IRegistrable} * @interface */ const IFlyout = function() {}; @@ -43,7 +43,7 @@ IFlyout.prototype.RTL; /** * The target workspace - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} */ IFlyout.prototype.targetWorkspace; @@ -72,8 +72,8 @@ IFlyout.prototype.CORNER_RADIUS; * either exist as its own svg element or be a g element nested inside a * separate svg element. * @param {string| - * !Blockly.utils.Svg| - * !Blockly.utils.Svg} tagName The type of tag to + * !Svg| + * !Svg} tagName The type of tag to * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ @@ -81,7 +81,7 @@ IFlyout.prototype.createDom; /** * Initializes the flyout. - * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to + * @param {!WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ IFlyout.prototype.init; @@ -106,7 +106,7 @@ IFlyout.prototype.getHeight; /** * Get the workspace inside the flyout. - * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. + * @return {!WorkspaceSvg} The workspace inside the flyout. */ IFlyout.prototype.getWorkspace; @@ -136,7 +136,7 @@ IFlyout.prototype.hide; /** * Show and populate the flyout. - * @param {!Blockly.utils.toolbox.FlyoutDefinition|string} flyoutDef Contents to + * @param {!FlyoutDefinition|string} flyoutDef Contents to * display in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ @@ -144,8 +144,8 @@ IFlyout.prototype.show; /** * Create a copy of this block on the workspace. - * @param {!Blockly.BlockSvg} originalBlock The block to copy from the flyout. - * @return {!Blockly.BlockSvg} The newly created block. + * @param {!BlockSvg} originalBlock The block to copy from the flyout. + * @return {!BlockSvg} The newly created block. * @throws {Error} if something went wrong with deserialization. */ IFlyout.prototype.createBlock; @@ -183,7 +183,7 @@ IFlyout.prototype.position; * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. */ From c72805b48a9fb4c9204e39fd5d9649b69402d23b Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 16:18:09 -0700 Subject: [PATCH 117/313] Migrate core/interfaces/i_toolbox.js to goog.module --- core/interfaces/i_toolbox.js | 39 +++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/interfaces/i_toolbox.js b/core/interfaces/i_toolbox.js index 208be48cc..b530a10f4 100644 --- a/core/interfaces/i_toolbox.js +++ b/core/interfaces/i_toolbox.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IToolbox'); +goog.module('Blockly.IToolbox'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.IFlyout'); goog.requireType('Blockly.IRegistrable'); @@ -25,76 +26,76 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.IRegistrable} * @interface */ -Blockly.IToolbox = function() {}; +const IToolbox = function() {}; /** * Initializes the toolbox. * @return {void} */ -Blockly.IToolbox.prototype.init; +IToolbox.prototype.init; /** * Fills the toolbox with new toolbox items and removes any old contents. * @param {!Blockly.utils.toolbox.ToolboxInfo} toolboxDef Object holding information * for creating a toolbox. */ -Blockly.IToolbox.prototype.render; +IToolbox.prototype.render; /** * Gets the width of the toolbox. * @return {number} The width of the toolbox. */ -Blockly.IToolbox.prototype.getWidth; +IToolbox.prototype.getWidth; /** * Gets the height of the toolbox. * @return {number} The width of the toolbox. */ -Blockly.IToolbox.prototype.getHeight; +IToolbox.prototype.getHeight; /** * Gets the toolbox flyout. * @return {?Blockly.IFlyout} The toolbox flyout. */ -Blockly.IToolbox.prototype.getFlyout; +IToolbox.prototype.getFlyout; /** * Gets the workspace for the toolbox. * @return {!Blockly.WorkspaceSvg} The parent workspace for the toolbox. */ -Blockly.IToolbox.prototype.getWorkspace; +IToolbox.prototype.getWorkspace; /** * Gets whether or not the toolbox is horizontal. * @return {boolean} True if the toolbox is horizontal, false if the toolbox is * vertical. */ -Blockly.IToolbox.prototype.isHorizontal; +IToolbox.prototype.isHorizontal; /** * Positions the toolbox based on whether it is a horizontal toolbox and whether * the workspace is in rtl. * @return {void} */ -Blockly.IToolbox.prototype.position; +IToolbox.prototype.position; /** * Handles resizing the toolbox when a toolbox item resizes. * @return {void} */ -Blockly.IToolbox.prototype.handleToolboxItemResize; +IToolbox.prototype.handleToolboxItemResize; /** * Unhighlights any previously selected item. * @return {void} */ -Blockly.IToolbox.prototype.clearSelection; +IToolbox.prototype.clearSelection; /** * Updates the category colours and background colour of selected categories. * @return {void} */ -Blockly.IToolbox.prototype.refreshTheme; +IToolbox.prototype.refreshTheme; /** * Updates the flyout's content without closing it. Should be used in response @@ -102,30 +103,32 @@ Blockly.IToolbox.prototype.refreshTheme; * procedures. * @return {void} */ -Blockly.IToolbox.prototype.refreshSelection; +IToolbox.prototype.refreshSelection; /** * Sets the visibility of the toolbox. * @param {boolean} isVisible True if toolbox should be visible. */ -Blockly.IToolbox.prototype.setVisible; +IToolbox.prototype.setVisible; /** * Selects the toolbox item by it's position in the list of toolbox items. * @param {number} position The position of the item to select. * @return {void} */ -Blockly.IToolbox.prototype.selectItemByPosition; +IToolbox.prototype.selectItemByPosition; /** * Gets the selected item. * @return {?Blockly.IToolboxItem} The selected item, or null if no item is * currently selected. */ -Blockly.IToolbox.prototype.getSelectedItem; +IToolbox.prototype.getSelectedItem; /** * Disposes of this toolbox. * @return {void} */ -Blockly.IToolbox.prototype.dispose; +IToolbox.prototype.dispose; + +exports = IToolbox; diff --git a/tests/deps.js b/tests/deps.js index 3163a584c..fe97eefd7 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -97,7 +97,7 @@ goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistra goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); 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.js', ['Blockly.IToolbox'], [], {'lang': 'es6', 'module': 'goog'}); 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'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es5'}); From 867c6cb140f37957b2ab5a3753e259462237ece4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 16:26:08 -0700 Subject: [PATCH 118/313] Migrate core/interfaces/i_toolbox.js named requires --- core/interfaces/i_toolbox.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/interfaces/i_toolbox.js b/core/interfaces/i_toolbox.js index b530a10f4..5ecd0a69f 100644 --- a/core/interfaces/i_toolbox.js +++ b/core/interfaces/i_toolbox.js @@ -14,16 +14,16 @@ goog.module('Blockly.IToolbox'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.IFlyout'); -goog.requireType('Blockly.IRegistrable'); -goog.requireType('Blockly.IToolboxItem'); -goog.requireType('Blockly.utils.toolbox'); -goog.requireType('Blockly.WorkspaceSvg'); +const IFlyout = goog.requireType('Blockly.IFlyout'); +const IRegistrable = goog.require('Blockly.IRegistrable'); +const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {ToolboxInfo} = goog.requireType('Blockly.utils.toolbox'); /** * Interface for a toolbox. - * @extends {Blockly.IRegistrable} + * @extends {IRegistrable} * @interface */ const IToolbox = function() {}; @@ -36,7 +36,7 @@ IToolbox.prototype.init; /** * Fills the toolbox with new toolbox items and removes any old contents. - * @param {!Blockly.utils.toolbox.ToolboxInfo} toolboxDef Object holding information + * @param {!ToolboxInfo} toolboxDef Object holding information * for creating a toolbox. */ IToolbox.prototype.render; @@ -55,13 +55,13 @@ IToolbox.prototype.getHeight; /** * Gets the toolbox flyout. - * @return {?Blockly.IFlyout} The toolbox flyout. + * @return {?IFlyout} The toolbox flyout. */ IToolbox.prototype.getFlyout; /** * Gets the workspace for the toolbox. - * @return {!Blockly.WorkspaceSvg} The parent workspace for the toolbox. + * @return {!WorkspaceSvg} The parent workspace for the toolbox. */ IToolbox.prototype.getWorkspace; @@ -120,7 +120,7 @@ IToolbox.prototype.selectItemByPosition; /** * Gets the selected item. - * @return {?Blockly.IToolboxItem} The selected item, or null if no item is + * @return {?IToolboxItem} The selected item, or null if no item is * currently selected. */ IToolbox.prototype.getSelectedItem; From e43c82d9bb3d71b72f7d42d81f2994a8f15253f9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:03:40 -0700 Subject: [PATCH 119/313] Migrate core/interfaces/i_autohideable.js to goog.module --- core/interfaces/i_autohideable.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_autohideable.js b/core/interfaces/i_autohideable.js index ff976c549..7b1613405 100644 --- a/core/interfaces/i_autohideable.js +++ b/core/interfaces/i_autohideable.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IAutoHideable'); +goog.module('Blockly.IAutoHideable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IComponent'); @@ -22,11 +23,13 @@ goog.require('Blockly.IComponent'); * @extends {Blockly.IComponent} * @interface */ -Blockly.IAutoHideable = function() {}; +const IAutoHideable = function() {}; /** * Hides the component. Called in Blockly.hideChaff. * @param {boolean} onlyClosePopups Whether only popups should be closed. * Flyouts should not be closed if this is true. */ -Blockly.IAutoHideable.prototype.autoHide; +IAutoHideable.prototype.autoHide; + +exports = IAutoHideable; diff --git a/tests/deps.js b/tests/deps.js index fe97eefd7..c3788886c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -76,7 +76,7 @@ goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.Insertion 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'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); 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'], {'lang': 'es6', 'module': 'goog'}); From 514f744a6f348f14f1cce37d72356b2eeb062885 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:08:54 -0700 Subject: [PATCH 120/313] Migrate core/interfaces/i_autohideable.js named requires --- core/interfaces/i_autohideable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_autohideable.js b/core/interfaces/i_autohideable.js index 7b1613405..bf11adc01 100644 --- a/core/interfaces/i_autohideable.js +++ b/core/interfaces/i_autohideable.js @@ -15,12 +15,12 @@ goog.module('Blockly.IAutoHideable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IComponent'); +const IComponent = goog.require('Blockly.IComponent'); /** * Interface for a component that can be automatically hidden. - * @extends {Blockly.IComponent} + * @extends {IComponent} * @interface */ const IAutoHideable = function() {}; From ff591b0e732395085f89fc5e1d0d7c100a455317 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 19 Jul 2021 21:26:53 -0700 Subject: [PATCH 121/313] Alphabetize --- core/renderers/common/info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 1cc61af85..73e02dfff 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -39,7 +39,7 @@ const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); const TopRow = goog.require('Blockly.blockRendering.TopRow'); const Types = goog.require('Blockly.blockRendering.Types'); const {ALIGN} = goog.require('Blockly.constants'); -const {VALUE, STATEMENT, DUMMY} = goog.require('Blockly.inputTypes'); +const {DUMMY, STATEMENT, VALUE} = goog.require('Blockly.inputTypes'); From d9625b1cafd3b94afa0ced4061527d2ad406e04b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 20 Jul 2021 09:38:06 -0700 Subject: [PATCH 122/313] Require userAgent module instead of destructuring in core/comment.js --- core/comment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/comment.js b/core/comment.js index 7caf61614..7f4085faf 100644 --- a/core/comment.js +++ b/core/comment.js @@ -22,11 +22,11 @@ const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const userAgent = goog.require('Blockly.utils.userAgent'); const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); const {inherits} = goog.require('Blockly.utils.object'); const {register} = goog.require('Blockly.Css'); -const {IE} = goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -254,7 +254,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || IE) { + if (!this.block_.isEditable() || userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable. From 09b020e62fbc22d4866543581aae61d2528bd4c2 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 16:02:02 -0700 Subject: [PATCH 123/313] Migrate core/keyboard_nav/basic_cursor.js to ES6 const/let --- core/keyboard_nav/basic_cursor.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index e38031321..89a61cf09 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -43,11 +43,11 @@ Blockly.BasicCursor.registrationName = 'basicCursor'; * @override */ Blockly.BasicCursor.prototype.next = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = this.getNextNode_(curNode, this.validNode_); + const newNode = this.getNextNode_(curNode, this.validNode_); if (newNode) { this.setCurNode(newNode); @@ -74,11 +74,11 @@ Blockly.BasicCursor.prototype.in = function() { * @override */ Blockly.BasicCursor.prototype.prev = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = this.getPreviousNode_(curNode, this.validNode_); + const newNode = this.getPreviousNode_(curNode, this.validNode_); if (newNode) { this.setCurNode(newNode); @@ -112,13 +112,13 @@ Blockly.BasicCursor.prototype.getNextNode_ = function(node, isValid) { if (!node) { return null; } - var newNode = node.in() || node.next(); + const newNode = node.in() || node.next(); if (isValid(newNode)) { return newNode; } else if (newNode) { return this.getNextNode_(newNode, isValid); } - var siblingOrParent = this.findSiblingOrParent_(node.out()); + const siblingOrParent = this.findSiblingOrParent_(node.out()); if (isValid(siblingOrParent)) { return siblingOrParent; } else if (siblingOrParent) { @@ -142,7 +142,7 @@ Blockly.BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { if (!node) { return null; } - var newNode = node.prev(); + let newNode = node.prev(); if (newNode) { newNode = this.getRightMostChild_(newNode); @@ -165,8 +165,8 @@ Blockly.BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { * @protected */ Blockly.BasicCursor.prototype.validNode_ = function(node) { - var isValid = false; - var type = node && node.getType(); + let isValid = false; + const type = node && node.getType(); if (type == Blockly.ASTNode.types.OUTPUT || type == Blockly.ASTNode.types.INPUT || type == Blockly.ASTNode.types.FIELD || @@ -189,7 +189,7 @@ Blockly.BasicCursor.prototype.findSiblingOrParent_ = function(node) { if (!node) { return null; } - var nextNode = node.next(); + const nextNode = node.next(); if (nextNode) { return nextNode; } @@ -208,7 +208,7 @@ Blockly.BasicCursor.prototype.getRightMostChild_ = function(node) { if (!node.in()) { return node; } - var newNode = node.in(); + let newNode = node.in(); while (newNode.next()) { newNode = newNode.next(); } From 29cfb470aa21db332ca01ec3822a5df47350b1a4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 16:17:53 -0700 Subject: [PATCH 124/313] Migrate core/keyboard_nav/basic_cursor.js to goog.module --- core/keyboard_nav/basic_cursor.js | 35 +++++++++++++++++-------------- tests/deps.js | 6 +++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index 89a61cf09..63df6a03f 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.BasicCursor'); +goog.module('Blockly.BasicCursor'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); goog.require('Blockly.Cursor'); @@ -25,16 +26,16 @@ goog.require('Blockly.registry'); * @constructor * @extends {Blockly.Cursor} */ -Blockly.BasicCursor = function() { - Blockly.BasicCursor.superClass_.constructor.call(this); +const BasicCursor = function() { + BasicCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(Blockly.BasicCursor, Blockly.Cursor); +Blockly.utils.object.inherits(BasicCursor, Blockly.Cursor); /** * Name used for registering a basic cursor. * @const {string} */ -Blockly.BasicCursor.registrationName = 'basicCursor'; +BasicCursor.registrationName = 'basicCursor'; /** * Find the next node in the pre order traversal. @@ -42,7 +43,7 @@ Blockly.BasicCursor.registrationName = 'basicCursor'; * not set or there is no next value. * @override */ -Blockly.BasicCursor.prototype.next = function() { +BasicCursor.prototype.next = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -63,7 +64,7 @@ Blockly.BasicCursor.prototype.next = function() { * not set or there is no next value. * @override */ -Blockly.BasicCursor.prototype.in = function() { +BasicCursor.prototype.in = function() { return this.next(); }; @@ -73,7 +74,7 @@ Blockly.BasicCursor.prototype.in = function() { * is not set or there is no previous value. * @override */ -Blockly.BasicCursor.prototype.prev = function() { +BasicCursor.prototype.prev = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -94,7 +95,7 @@ Blockly.BasicCursor.prototype.prev = function() { * not set or there is no previous value. * @override */ -Blockly.BasicCursor.prototype.out = function() { +BasicCursor.prototype.out = function() { return this.prev(); }; @@ -108,7 +109,7 @@ Blockly.BasicCursor.prototype.out = function() { * @return {Blockly.ASTNode} The next node in the traversal. * @protected */ -Blockly.BasicCursor.prototype.getNextNode_ = function(node, isValid) { +BasicCursor.prototype.getNextNode_ = function(node, isValid) { if (!node) { return null; } @@ -138,7 +139,7 @@ Blockly.BasicCursor.prototype.getNextNode_ = function(node, isValid) { * previous node exists. * @protected */ -Blockly.BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { +BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { if (!node) { return null; } @@ -164,7 +165,7 @@ Blockly.BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { * @return {boolean} True if the node should be visited, false otherwise. * @protected */ -Blockly.BasicCursor.prototype.validNode_ = function(node) { +BasicCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); if (type == Blockly.ASTNode.types.OUTPUT || @@ -185,7 +186,7 @@ Blockly.BasicCursor.prototype.validNode_ = function(node) { * valid parents. * @private */ -Blockly.BasicCursor.prototype.findSiblingOrParent_ = function(node) { +BasicCursor.prototype.findSiblingOrParent_ = function(node) { if (!node) { return null; } @@ -204,7 +205,7 @@ Blockly.BasicCursor.prototype.findSiblingOrParent_ = function(node) { * if no child exists. * @private */ -Blockly.BasicCursor.prototype.getRightMostChild_ = function(node) { +BasicCursor.prototype.getRightMostChild_ = function(node) { if (!node.in()) { return node; } @@ -216,5 +217,7 @@ Blockly.BasicCursor.prototype.getRightMostChild_ = function(node) { }; Blockly.registry.register( - Blockly.registry.Type.CURSOR, Blockly.BasicCursor.registrationName, - Blockly.BasicCursor); + Blockly.registry.Type.CURSOR, BasicCursor.registrationName, + BasicCursor); + +exports = BasicCursor; diff --git a/tests/deps.js b/tests/deps.js index dfbcfe352..74512fae5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -88,7 +88,7 @@ goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable' 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'], {'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'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); 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'}); @@ -97,10 +97,10 @@ goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistra goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); 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'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); 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'}); -goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); From 4a3d67abebdf3e0b79728ae8b7d382c13d968e93 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 18:00:30 -0700 Subject: [PATCH 125/313] Migrate core/keyboard_nav/basic_cursor.js named requires --- core/keyboard_nav/basic_cursor.js | 57 ++++++++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index 63df6a03f..9260fa62a 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -14,9 +14,10 @@ goog.module('Blockly.BasicCursor'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); -goog.require('Blockly.Cursor'); -goog.require('Blockly.registry'); +const ASTNode = goog.require('Blockly.ASTNode'); +const Cursor = goog.require('Blockly.Cursor'); +const {register, Type} = goog.require('Blockly.registry'); +const {inherits} = goog.require('Blockly.utils.object'); /** @@ -24,12 +25,12 @@ goog.require('Blockly.registry'); * This will allow the user to get to all nodes in the AST by hitting next or * previous. * @constructor - * @extends {Blockly.Cursor} + * @extends {Cursor} */ const BasicCursor = function() { BasicCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(BasicCursor, Blockly.Cursor); +inherits(BasicCursor, Cursor); /** * Name used for registering a basic cursor. @@ -39,7 +40,7 @@ BasicCursor.registrationName = 'basicCursor'; /** * Find the next node in the pre order traversal. - * @return {Blockly.ASTNode} The next node, or null if the current node is + * @return {?ASTNode} The next node, or null if the current node is * not set or there is no next value. * @override */ @@ -60,7 +61,7 @@ BasicCursor.prototype.next = function() { * For a basic cursor we only have the ability to go next and previous, so * in will also allow the user to get to the next node in the pre order * traversal. - * @return {Blockly.ASTNode} The next node, or null if the current node is + * @return {?ASTNode} The next node, or null if the current node is * not set or there is no next value. * @override */ @@ -70,7 +71,7 @@ BasicCursor.prototype.in = function() { /** * Find the previous node in the pre order traversal. - * @return {Blockly.ASTNode} The previous node, or null if the current node + * @return {?ASTNode} The previous node, or null if the current node * is not set or there is no previous value. * @override */ @@ -91,7 +92,7 @@ BasicCursor.prototype.prev = function() { * For a basic cursor we only have the ability to go next and previous, so * out will allow the user to get to the previous node in the pre order * traversal. - * @return {Blockly.ASTNode} The previous node, or null if the current node is + * @return {?ASTNode} The previous node, or null if the current node is * not set or there is no previous value. * @override */ @@ -103,10 +104,10 @@ BasicCursor.prototype.out = function() { * Uses pre order traversal to navigate the Blockly AST. This will allow * a user to easily navigate the entire Blockly AST without having to go in * and out levels on the tree. - * @param {Blockly.ASTNode} node The current position in the AST. - * @param {!function(Blockly.ASTNode) : boolean} isValid A function true/false + * @param {?ASTNode} node The current position in the AST. + * @param {!function(ASTNode) : boolean} isValid A function true/false * depending on whether the given node should be traversed. - * @return {Blockly.ASTNode} The next node in the traversal. + * @return {?ASTNode} The next node in the traversal. * @protected */ BasicCursor.prototype.getNextNode_ = function(node, isValid) { @@ -132,10 +133,10 @@ BasicCursor.prototype.getNextNode_ = function(node, isValid) { * Reverses the pre order traversal in order to find the previous node. This * will allow a user to easily navigate the entire Blockly AST without having to * go in and out levels on the tree. - * @param {Blockly.ASTNode} node The current position in the AST. - * @param {!function(Blockly.ASTNode) : boolean} isValid A function true/false + * @param {?ASTNode} node The current position in the AST. + * @param {!function(ASTNode) : boolean} isValid A function true/false * depending on whether the given node should be traversed. - * @return {Blockly.ASTNode} The previous node in the traversal or null if no + * @return {?ASTNode} The previous node in the traversal or null if no * previous node exists. * @protected */ @@ -161,19 +162,19 @@ BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { /** * Decides what nodes to traverse and which ones to skip. Currently, it * skips output, stack and workspace nodes. - * @param {Blockly.ASTNode} node The AST node to check whether it is valid. + * @param {?ASTNode} node The AST node to check whether it is valid. * @return {boolean} True if the node should be visited, false otherwise. * @protected */ BasicCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); - if (type == Blockly.ASTNode.types.OUTPUT || - type == Blockly.ASTNode.types.INPUT || - type == Blockly.ASTNode.types.FIELD || - type == Blockly.ASTNode.types.NEXT || - type == Blockly.ASTNode.types.PREVIOUS || - type == Blockly.ASTNode.types.WORKSPACE) { + if (type == ASTNode.types.OUTPUT || + type == ASTNode.types.INPUT || + type == ASTNode.types.FIELD || + type == ASTNode.types.NEXT || + type == ASTNode.types.PREVIOUS || + type == ASTNode.types.WORKSPACE) { isValid = true; } return isValid; @@ -181,8 +182,8 @@ BasicCursor.prototype.validNode_ = function(node) { /** * From the given node find either the next valid sibling or parent. - * @param {Blockly.ASTNode} node The current position in the AST. - * @return {Blockly.ASTNode} The parent AST node or null if there are no + * @param {?ASTNode} node The current position in the AST. + * @return {?ASTNode} The parent AST node or null if there are no * valid parents. * @private */ @@ -200,8 +201,8 @@ BasicCursor.prototype.findSiblingOrParent_ = function(node) { /** * Get the right most child of a node. - * @param {Blockly.ASTNode} node The node to find the right most child of. - * @return {Blockly.ASTNode} The right most child of the given node, or the node + * @param {?ASTNode} node The node to find the right most child of. + * @return {?ASTNode} The right most child of the given node, or the node * if no child exists. * @private */ @@ -216,8 +217,8 @@ BasicCursor.prototype.getRightMostChild_ = function(node) { return this.getRightMostChild_(newNode); }; -Blockly.registry.register( - Blockly.registry.Type.CURSOR, BasicCursor.registrationName, +register( + Type.CURSOR, BasicCursor.registrationName, BasicCursor); exports = BasicCursor; diff --git a/tests/deps.js b/tests/deps.js index 74512fae5..0b641086e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -100,7 +100,7 @@ goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable' goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); 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'}); -goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); From 2ef8b2c86b2e55bb8e51115ed89b46cf0f04f42d Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 18:02:39 -0700 Subject: [PATCH 126/313] clang-format core/keyboard_nav/basic_cursor.js --- core/keyboard_nav/basic_cursor.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index 9260fa62a..e9780e119 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -169,12 +169,9 @@ BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { BasicCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); - if (type == ASTNode.types.OUTPUT || - type == ASTNode.types.INPUT || - type == ASTNode.types.FIELD || - type == ASTNode.types.NEXT || - type == ASTNode.types.PREVIOUS || - type == ASTNode.types.WORKSPACE) { + if (type == ASTNode.types.OUTPUT || type == ASTNode.types.INPUT || + type == ASTNode.types.FIELD || type == ASTNode.types.NEXT || + type == ASTNode.types.PREVIOUS || type == ASTNode.types.WORKSPACE) { isValid = true; } return isValid; @@ -217,8 +214,6 @@ BasicCursor.prototype.getRightMostChild_ = function(node) { return this.getRightMostChild_(newNode); }; -register( - Type.CURSOR, BasicCursor.registrationName, - BasicCursor); +register(Type.CURSOR, BasicCursor.registrationName, BasicCursor); exports = BasicCursor; From da960d5973912c660d802b2d3c4850b58d25b0ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 20 Jul 2021 10:49:21 -0700 Subject: [PATCH 127/313] Convert private static functions to module-internal functions in core/connection.js --- core/connection.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/connection.js b/core/connection.js index 0b26e9ace..553938825 100644 --- a/core/connection.js +++ b/core/connection.js @@ -134,7 +134,7 @@ Connection.prototype.connect_ = function(childConnection) { if (Events.isEnabled()) { event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } - Connection.connectReciprocally_(parentConnection, childConnection); + connectReciprocally(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); @@ -307,9 +307,8 @@ Connection.prototype.connect = function(otherConnection) { * Update two connections to target each other. * @param {Connection} first The first connection to update. * @param {Connection} second The second connection to update. - * @private */ -Connection.connectReciprocally_ = function(first, second) { +const connectReciprocally = function(first, second) { if (!first || !second) { throw Error('Cannot connect null connections.'); } @@ -326,9 +325,8 @@ Connection.connectReciprocally_ = function(first, second) { * @param {!Block} orphanBlock The inferior block. * @return {?Connection} The suitable connection point on 'block', * or null. - * @private */ -Connection.getSingleConnection_ = function(block, orphanBlock) { +const getSingleConnection = function(block, orphanBlock) { let foundConnection = null; const output = orphanBlock.outputConnection; const typeChecker = output.getConnectionChecker(); @@ -355,13 +353,12 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * @param {!Block} orphanBlock The block that is looking for a home. * @return {?Connection} The suitable connection point on the chain * of blocks, or null. - * @private */ -Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { +const getConnectionForOrphanedOutput = function(startBlock, orphanBlock) { let newBlock = startBlock; let connection; while ( - (connection = Connection.getSingleConnection_( + (connection = getSingleConnection( /** @type {!Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { @@ -384,7 +381,7 @@ Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { Connection.getConnectionForOrphanedConnection = function( startBlock, orphanConnection) { if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { - return Connection.getConnectionForOrphanedOutput_( + return getConnectionForOrphanedOutput( startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. From 77aaab0e1f0496115cebedc5c81307ab4e78982b Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:35:32 -0700 Subject: [PATCH 128/313] Migrate core/interfaces/i_connection_checker.js to goog.module --- core/interfaces/i_connection_checker.js | 19 +++++++++++-------- tests/deps.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/interfaces/i_connection_checker.js b/core/interfaces/i_connection_checker.js index 4b6120da1..527dec4c5 100644 --- a/core/interfaces/i_connection_checker.js +++ b/core/interfaces/i_connection_checker.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.IConnectionChecker'); +goog.module('Blockly.IConnectionChecker'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.Connection'); goog.requireType('Blockly.RenderedConnection'); @@ -21,7 +22,7 @@ goog.requireType('Blockly.RenderedConnection'); * Class for connection type checking logic. * @interface */ -Blockly.IConnectionChecker = function() {}; +const IConnectionChecker = function() {}; /** * Check whether the current connection can connect with the target @@ -35,7 +36,7 @@ Blockly.IConnectionChecker = function() {}; * @return {boolean} Whether the connection is legal. * @public */ -Blockly.IConnectionChecker.prototype.canConnect; +IConnectionChecker.prototype.canConnect; /** * Checks whether the current connection can connect with the target @@ -50,7 +51,7 @@ Blockly.IConnectionChecker.prototype.canConnect; * an error code otherwise. * @public */ -Blockly.IConnectionChecker.prototype.canConnectWithReason; +IConnectionChecker.prototype.canConnectWithReason; /** * Helper method that translates a connection error code into a string. @@ -61,7 +62,7 @@ Blockly.IConnectionChecker.prototype.canConnectWithReason; * @return {string} A developer-readable error string. * @public */ -Blockly.IConnectionChecker.prototype.getErrorMessage; +IConnectionChecker.prototype.getErrorMessage; /** * Check that connecting the given connections is safe, meaning that it would @@ -71,7 +72,7 @@ Blockly.IConnectionChecker.prototype.getErrorMessage; * @return {number} An enum with the reason this connection is safe or unsafe. * @public */ -Blockly.IConnectionChecker.prototype.doSafetyChecks; +IConnectionChecker.prototype.doSafetyChecks; /** * Check whether this connection is compatible with another connection with @@ -82,7 +83,7 @@ Blockly.IConnectionChecker.prototype.doSafetyChecks; * @return {boolean} True if the connections share a type. * @public */ -Blockly.IConnectionChecker.prototype.doTypeChecks; +IConnectionChecker.prototype.doTypeChecks; /** * Check whether this connection can be made by dragging. @@ -92,4 +93,6 @@ Blockly.IConnectionChecker.prototype.doTypeChecks; * @return {boolean} True if the connection is allowed during a drag. * @public */ -Blockly.IConnectionChecker.prototype.doDragChecks; +IConnectionChecker.prototype.doDragChecks; + +exports = IConnectionChecker; diff --git a/tests/deps.js b/tests/deps.js index 0b641086e..aa3fc9275 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -81,7 +81,7 @@ goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockD 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'], {'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_connection_checker.js', ['Blockly.IConnectionChecker'], [], {'lang': 'es6', 'module': 'goog'}); 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'}); From 9eee8869256cd8637e56d528f097ebf35cf80829 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:37:10 -0700 Subject: [PATCH 129/313] Migrate core/interfaces/i_connection_checker.js named requires --- core/interfaces/i_connection_checker.js | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/interfaces/i_connection_checker.js b/core/interfaces/i_connection_checker.js index 527dec4c5..03693604c 100644 --- a/core/interfaces/i_connection_checker.js +++ b/core/interfaces/i_connection_checker.js @@ -14,8 +14,8 @@ goog.module('Blockly.IConnectionChecker'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.Connection'); -goog.requireType('Blockly.RenderedConnection'); +const Connection = goog.requireType('Blockly.Connection'); +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); /** @@ -27,8 +27,8 @@ const IConnectionChecker = 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 @@ -41,13 +41,13 @@ IConnectionChecker.prototype.canConnect; /** * 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 */ @@ -56,8 +56,8 @@ IConnectionChecker.prototype.canConnectWithReason; /** * 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 @@ -67,8 +67,8 @@ IConnectionChecker.prototype.getErrorMessage; /** * 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 */ @@ -78,8 +78,8 @@ IConnectionChecker.prototype.doSafetyChecks; * 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 */ @@ -87,8 +87,8 @@ IConnectionChecker.prototype.doTypeChecks; /** * 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 From 317a2e6f53d46e07c6eca16c18be07a295612ae5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:17:10 -0700 Subject: [PATCH 130/313] Migrate core/keyboard_nav/cursor.js to ES6 const/let --- core/keyboard_nav/cursor.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index 882be726a..c73d49046 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -42,12 +42,12 @@ Blockly.utils.object.inherits(Blockly.Cursor, Blockly.Marker); * @public */ Blockly.Cursor.prototype.next = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = curNode.next(); + let newNode = curNode.next(); while (newNode && newNode.next() && (newNode.getType() == Blockly.ASTNode.types.NEXT || newNode.getType() == Blockly.ASTNode.types.BLOCK)) { @@ -67,7 +67,7 @@ Blockly.Cursor.prototype.next = function() { * @public */ Blockly.Cursor.prototype.in = function() { - var curNode = this.getCurNode(); + let curNode = this.getCurNode(); if (!curNode) { return null; } @@ -77,7 +77,7 @@ Blockly.Cursor.prototype.in = function() { curNode.getType() == Blockly.ASTNode.types.OUTPUT) { curNode = curNode.next(); } - var newNode = curNode.in(); + const newNode = curNode.in(); if (newNode) { this.setCurNode(newNode); @@ -92,11 +92,11 @@ Blockly.Cursor.prototype.in = function() { * @public */ Blockly.Cursor.prototype.prev = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = curNode.prev(); + let newNode = curNode.prev(); while (newNode && newNode.prev() && (newNode.getType() == Blockly.ASTNode.types.NEXT || @@ -117,11 +117,11 @@ Blockly.Cursor.prototype.prev = function() { * @public */ Blockly.Cursor.prototype.out = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = curNode.out(); + let newNode = curNode.out(); if (newNode && newNode.getType() == Blockly.ASTNode.types.BLOCK) { newNode = newNode.prev() || newNode; From e50c60bfdbaf92af822cb1dcb819a90c4c057d43 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:17:18 -0700 Subject: [PATCH 131/313] Migrate core/keyboard_nav/cursor.js to goog.module --- core/keyboard_nav/cursor.js | 21 ++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index c73d49046..87375108a 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Cursor'); +goog.module('Blockly.Cursor'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); goog.require('Blockly.Marker'); @@ -25,15 +26,15 @@ goog.require('Blockly.utils.object'); * @constructor * @extends {Blockly.Marker} */ -Blockly.Cursor = function() { - Blockly.Cursor.superClass_.constructor.call(this); +const Cursor = function() { + Cursor.superClass_.constructor.call(this); /** * @override */ this.type = 'cursor'; }; -Blockly.utils.object.inherits(Blockly.Cursor, Blockly.Marker); +Blockly.utils.object.inherits(Cursor, Blockly.Marker); /** * Find the next connection, field, or block. @@ -41,7 +42,7 @@ Blockly.utils.object.inherits(Blockly.Cursor, Blockly.Marker); * not set or there is no next value. * @public */ -Blockly.Cursor.prototype.next = function() { +Cursor.prototype.next = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -66,7 +67,7 @@ Blockly.Cursor.prototype.next = function() { * not set or there is no in value. * @public */ -Blockly.Cursor.prototype.in = function() { +Cursor.prototype.in = function() { let curNode = this.getCurNode(); if (!curNode) { return null; @@ -91,7 +92,7 @@ Blockly.Cursor.prototype.in = function() { * is not set or there is no previous value. * @public */ -Blockly.Cursor.prototype.prev = function() { +Cursor.prototype.prev = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -116,7 +117,7 @@ Blockly.Cursor.prototype.prev = function() { * not set or there is no out value. * @public */ -Blockly.Cursor.prototype.out = function() { +Cursor.prototype.out = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -134,4 +135,6 @@ Blockly.Cursor.prototype.out = function() { }; Blockly.registry.register( - Blockly.registry.Type.CURSOR, Blockly.registry.DEFAULT, Blockly.Cursor); + Blockly.registry.Type.CURSOR, Blockly.registry.DEFAULT, Cursor); + +exports = Cursor; diff --git a/tests/deps.js b/tests/deps.js index aa3fc9275..6128287ca 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -101,7 +101,7 @@ 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'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); From c9f2a92ace5497c6dd70cdd7c8037e770a921fde Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 15:01:12 -0700 Subject: [PATCH 132/313] Migrate core/keyboard_nav/cursor.js named requires --- core/keyboard_nav/cursor.js | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index 87375108a..de3d97498 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -14,17 +14,17 @@ goog.module('Blockly.Cursor'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); -goog.require('Blockly.Marker'); -goog.require('Blockly.registry'); -goog.require('Blockly.utils.object'); +const ASTNode = goog.require('Blockly.ASTNode'); +const Marker = goog.require('Blockly.Marker'); +const {DEFAULT, register, Type} = goog.require('Blockly.registry'); +const {inherits} = goog.require('Blockly.utils.object'); /** * Class for a cursor. * A cursor controls how a user navigates the Blockly AST. * @constructor - * @extends {Blockly.Marker} + * @extends {Marker} */ const Cursor = function() { Cursor.superClass_.constructor.call(this); @@ -34,11 +34,11 @@ const Cursor = function() { */ this.type = 'cursor'; }; -Blockly.utils.object.inherits(Cursor, Blockly.Marker); +inherits(Cursor, Marker); /** * Find the next connection, field, or block. - * @return {Blockly.ASTNode} The next element, or null if the current node is + * @return {ASTNode} The next element, or null if the current node is * not set or there is no next value. * @public */ @@ -50,8 +50,8 @@ Cursor.prototype.next = function() { let newNode = curNode.next(); while (newNode && newNode.next() && - (newNode.getType() == Blockly.ASTNode.types.NEXT || - newNode.getType() == Blockly.ASTNode.types.BLOCK)) { + (newNode.getType() == ASTNode.types.NEXT || + newNode.getType() == ASTNode.types.BLOCK)) { newNode = newNode.next(); } @@ -63,7 +63,7 @@ Cursor.prototype.next = function() { /** * Find the in connection or field. - * @return {Blockly.ASTNode} The in element, or null if the current node is + * @return {ASTNode} The in element, or null if the current node is * not set or there is no in value. * @public */ @@ -74,8 +74,8 @@ Cursor.prototype.in = function() { } // If we are on a previous or output connection, go to the block level before // performing next operation. - if (curNode.getType() == Blockly.ASTNode.types.PREVIOUS || - curNode.getType() == Blockly.ASTNode.types.OUTPUT) { + if (curNode.getType() == ASTNode.types.PREVIOUS || + curNode.getType() == ASTNode.types.OUTPUT) { curNode = curNode.next(); } const newNode = curNode.in(); @@ -88,7 +88,7 @@ Cursor.prototype.in = function() { /** * Find the previous connection, field, or block. - * @return {Blockly.ASTNode} The previous element, or null if the current node + * @return {ASTNode} The previous element, or null if the current node * is not set or there is no previous value. * @public */ @@ -100,8 +100,8 @@ Cursor.prototype.prev = function() { let newNode = curNode.prev(); while (newNode && newNode.prev() && - (newNode.getType() == Blockly.ASTNode.types.NEXT || - newNode.getType() == Blockly.ASTNode.types.BLOCK)) { + (newNode.getType() == ASTNode.types.NEXT || + newNode.getType() == ASTNode.types.BLOCK)) { newNode = newNode.prev(); } @@ -113,7 +113,7 @@ Cursor.prototype.prev = function() { /** * Find the out connection, field, or block. - * @return {Blockly.ASTNode} The out element, or null if the current node is + * @return {ASTNode} The out element, or null if the current node is * not set or there is no out value. * @public */ @@ -124,7 +124,7 @@ Cursor.prototype.out = function() { } let newNode = curNode.out(); - if (newNode && newNode.getType() == Blockly.ASTNode.types.BLOCK) { + if (newNode && newNode.getType() == ASTNode.types.BLOCK) { newNode = newNode.prev() || newNode; } @@ -134,7 +134,6 @@ Cursor.prototype.out = function() { return newNode; }; -Blockly.registry.register( - Blockly.registry.Type.CURSOR, Blockly.registry.DEFAULT, Cursor); +register(Type.CURSOR, DEFAULT, Cursor); exports = Cursor; From d101e591de50f7e74f9ed288cdc5dc555e9c2bfe Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Tue, 20 Jul 2021 13:06:39 -0700 Subject: [PATCH 133/313] Removes unnecessary test --- tests/mocha/workspace_svg_test.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/mocha/workspace_svg_test.js b/tests/mocha/workspace_svg_test.js index 339a19a98..d79707d08 100644 --- a/tests/mocha/workspace_svg_test.js +++ b/tests/mocha/workspace_svg_test.js @@ -112,11 +112,6 @@ suite('WorkspaceSvg', function() { this.workspace.updateToolbox({'contents': []}); }.bind(this), 'Existing toolbox has categories. Can\'t change mode.'); }); - test('Passing in string as toolboxdef', function() { - var parseToolboxFake = sinon.spy(Blockly.utils.toolbox, 'parseToolboxTree'); - this.workspace.updateToolbox(''); - sinon.assert.calledOnce(parseToolboxFake); - }); }); suite('addTopBlock', function() { From 5f5b4370250dd3784ed83feb97e7e24528c2113d Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 12:06:50 -0700 Subject: [PATCH 134/313] Add script for partially automating goog.module conversion steps --- scripts/goog_module/convert-file.sh | 281 ++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100755 scripts/goog_module/convert-file.sh diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh new file mode 100755 index 000000000..aae6a9191 --- /dev/null +++ b/scripts/goog_module/convert-file.sh @@ -0,0 +1,281 @@ +#!/bin/bash + +####################################### +# Logging functions +####################################### +COLOR_NONE="\033[0m" +GREEN="\033[0;32m" +BLUE="\033[0;34m" +ORANGE="\033[0;33m" +RED="\033[0;31m" +success() { + echo -e "${GREEN}[SUCCESS]:${COLOR_NONE} $*" >&2 +} +inf() { + echo -e "${BLUE}[INFO]:${COLOR_NONE} $*" >&2 +} +warn() { + echo -e "${ORANGE}[WARN]:${COLOR_NONE} $*" >&2 +} +err() { + echo -e "${RED}[ERROR]:${COLOR_NONE} $*" >&2 +} +####################################### +# Checks whether the provided filepath exists. +# Arguments: +# The filepath to check for existence. +####################################### +verify-filepath() { + if [[ ! -f "$1" ]]; then + err "File $1 does not exist" + return 1 + fi +} +####################################### +# Creates a commit with a message based on the specified step and file. +# Arguments: +# Which conversion step this message is for. +# The filepath of the file being converted. +####################################### +commit-step() { + local step="$1" + local filepath="$2" + if [ -z "${step}" ]; then + err "Missing argument (1-4)" + return 1 + fi + if [ -z "${filepath}" ]; then + err "Missing argument filepath" + return 1 + fi + verify-filepath "${filepath}" + if [[ $? -eq 1 ]]; then return 1; fi + + local message='' + case $1 in + 1) + message="Migrate ${filepath} to ES6 const/let" + ;; + 2) + message="Migrate ${filepath} to goog.module" + ;; + 3) + message="Migrate ${filepath} named requires" + ;; + 4) + message="clang-format ${filepath}" + ;; + *) + err 'INVALID ARGUMENT' + return 1 + ;; + esac + git add . + if [[ -z $(git status --porcelain) ]]; then + success "Nothing to commit" + return 0 + fi + git commit -m "${message}" + success "created commit with message: \"${message}\"" +} +####################################### +# Runs step 2 of the automated conversion. +# Arguments: +# The filepath of the file being converted. +####################################### +step2 () { + local filepath="$1" + if [ -z "${filepath}" ]; then + err "Missing argument filepath" + return 1 + fi + + inf "Verifying single goog.provide declarations..." + local provide_count=$(grep -o 'goog.provide' ${filepath} | wc -l) + if [[ "${provide_count}" -gt "1" ]]; then + err "Cannot convert file with multiple provides. Please split the file first." + return 1 + elif [[ "${provide_count}" -eq "0" ]]; then + err "Cannot convert file without a provide." + return 1 + fi + + inf "Updating goog.provide declaration..." + perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/g' "${filepath}" + + + inf "Extracting module name..." + local module_name=$(grep -oP "(?<=^goog\.module\(\')([^\')]+)" "${filepath}") + if [[ -z "${module_name}" ]]; then + err "Could not extract module name" + return 1 + fi + inf "Extracted module name \"${module_name}\"" + + if [[ $(grep "${module_name} = " "${filepath}") ]]; then + local class_name=$(echo "${module_name}" | grep -oP "(\w+)$") + inf "Found class \"${class_name}\" in file." + inf "Updating class declaration..." + perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" + inf 'Updating class properties...' + perl -pi -e 's/^'"${module_name}"'((\.\w+)+) =/'"${class_name}"'\1 =/g' "${filepath}" + + inf "Updating local references to class..." + perl -pi -e 's/'"${module_name}"'([^'\''])/'"${class_name}"'\1/g' "${filepath}" + + inf "Appending class export to end of file..." + echo "" >> "${filepath}" + echo "exports = ${class_name};" >> "${filepath}" + + npm run build:deps + + success "Completed automated conversion to goog.module. Please manually review before committing." + return 0 + fi + + # No top level class. + inf 'Updating top-level property declarations...' + perl -pi -e 's/^'"${module_name}"'\.([^ ]+) =/const \1 =/g' "${filepath}" + inf "Updating local references to module..." + perl -pi -e 's/'"${module_name}"'\.([^ ]+)/\1/g' "${filepath}" + + npm run build:deps + success "Completed automation for step 3. Please manually review and add exports for non-private top-level functions." + +} +####################################### +# Runs step 3 of the automated conversion. +# Arguments: +# The filepath of the file being converted. +####################################### +step3() { + local filepath="$1" + if [ -z "${filepath}" ]; then + err "Missing argument filepath" + return 1 + fi + + local requires=$(grep -E -o '^goog.require(|Type)\('\''(.*)'\''\)' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') + + # Process each require + echo "${requires}" | while read -r require ; do + local usages=$(grep -Pe ''"${require}"'(?!'\'')' "${filepath}" | wc -l) + if [[ "${usages}" -eq "0" ]]; then + warn "Unused require \"${require}\"" + continue + fi + + local direct_access_count=$(grep -Pe ''"${require}"'[^\.'\'']' "${filepath}" | wc -l) + local prop_access_count=$(grep -Pe ''"${require}"'\.(?!prototype)' "${filepath}" | wc -l) + if [[ "${direct_access_count}" -eq "0" && "${prop_access_count}" -gt "0" ]]; then + local deconstructed=$(grep -Pe ''"${require}"'\.(?!prototype)' "${filepath}" | perl -pe 's/'"${require}"'\.([^\(\[,\.]+).*/\1/g') + local deconstructed_comma=$(echo "${deconstructed}" | perl -zpe 's/\s+/, /g' | perl 's/, $//') + inf "Deconstructing ${require} into \"${deconstructed_comma}\"" + + inf "Updating require declaration for ${require}..." + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" + + echo "${deconstructed}" | while read -r require_prop ; do + inf "Updating references of ${require}.${require_prop} to ${require_prop}..." + perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''])/'"${require_prop}"'\1/g' "${filepath}" + done + continue + fi + + local require_name=$(echo "${require}" | perl -pe 's/(\w+\.)+(\w+)/\2/g') + inf "Updating require declaration for ${require}..." + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" + + inf "Updating references of ${require} to ${require_name}..." + perl -pi -e 's/'"${require}"'([^'\''])/'"${require_name}"'\1/g' "${filepath}" + done + + local missing_requires=$(grep -Pe '(?|-s |-f] " + echo " -h Display help" + echo " -c Create a commit for the specified step [2-4]" + echo " -s Run the specified step [1-4]" +} + +if [ "$1" = "" ]; then + help +else + command="$1" + shift + case $command in + -h) help $@;; + -c) commit-step $@;; + -s) run-step $@;; + *) help;; + esac +fi From 89e4151810c08500d04cbd984a9f5a04e02e76e2 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 14:48:11 -0700 Subject: [PATCH 135/313] Update commands to be OSX compatible --- scripts/goog_module/convert-file.sh | 33 ++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index aae6a9191..6673106ee 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -159,6 +159,7 @@ step3() { # Process each require echo "${requires}" | while read -r require ; do + inf "Processing require \"${require}\"" local usages=$(grep -Pe ''"${require}"'(?!'\'')' "${filepath}" | wc -l) if [[ "${usages}" -eq "0" ]]; then warn "Unused require \"${require}\"" @@ -166,18 +167,26 @@ step3() { fi local direct_access_count=$(grep -Pe ''"${require}"'[^\.'\'']' "${filepath}" | wc -l) - local prop_access_count=$(grep -Pe ''"${require}"'\.(?!prototype)' "${filepath}" | wc -l) - if [[ "${direct_access_count}" -eq "0" && "${prop_access_count}" -gt "0" ]]; then - local deconstructed=$(grep -Pe ''"${require}"'\.(?!prototype)' "${filepath}" | perl -pe 's/'"${require}"'\.([^\(\[,\.]+).*/\1/g') - local deconstructed_comma=$(echo "${deconstructed}" | perl -zpe 's/\s+/, /g' | perl 's/, $//') - inf "Deconstructing ${require} into \"${deconstructed_comma}\"" + local properties_accessed=$(grep -Po '(?<='"${require}"'\.)(?!prototype)\w+' "${filepath}" | tr ' ' '\n' | sort -u) + # Detect overlap (ex: Blockly.utils and Blockly.utils.dom) + local overlap=$(echo "${requires}"| grep -Po "(?<=${require}\.)\w+") + if [[ ! -z "${overlap}" ]]; then + while read -r overlap_prop ; do + properties_accessed=$(echo "$properties_accessed" | perl -pe 's/'"${overlap_prop}"'//g') + done <<<"${overlap}" + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) + fi + + if [[ "${direct_access_count}" -eq "0" && ! -z "${properties_accessed}" ]]; then + local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') + inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"" inf "Updating require declaration for ${require}..." - perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - echo "${deconstructed}" | while read -r require_prop ; do + echo "${properties_accessed}" | while read -r require_prop ; do inf "Updating references of ${require}.${require_prop} to ${require_prop}..." - perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''])/'"${require_prop}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" done continue fi @@ -187,13 +196,13 @@ step3() { perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" inf "Updating references of ${require} to ${require_name}..." - perl -pi -e 's/'"${require}"'([^'\''])/'"${require_name}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'([^'\''\w])/'"${require_name}"'\1/g' "${filepath}" done - local missing_requires=$(grep -Pe '(? Date: Tue, 20 Jul 2021 15:11:51 -0700 Subject: [PATCH 136/313] Update grep calls --- scripts/goog_module/convert-file.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 6673106ee..f7adee01e 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -105,7 +105,7 @@ step2 () { inf "Extracting module name..." - local module_name=$(grep -oP "(?<=^goog\.module\(\')([^\')]+)" "${filepath}") + local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") if [[ -z "${module_name}" ]]; then err "Could not extract module name" return 1 @@ -113,7 +113,7 @@ step2 () { inf "Extracted module name \"${module_name}\"" if [[ $(grep "${module_name} = " "${filepath}") ]]; then - local class_name=$(echo "${module_name}" | grep -oP "(\w+)$") + local class_name=$(echo "${module_name}" | grep -E -o "(\w+)$") inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" @@ -160,16 +160,17 @@ step3() { # Process each require echo "${requires}" | while read -r require ; do inf "Processing require \"${require}\"" - local usages=$(grep -Pe ''"${require}"'(?!'\'')' "${filepath}" | wc -l) + local usages=$(perl -nle'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) + if [[ "${usages}" -eq "0" ]]; then warn "Unused require \"${require}\"" continue fi - local direct_access_count=$(grep -Pe ''"${require}"'[^\.'\'']' "${filepath}" | wc -l) - local properties_accessed=$(grep -Po '(?<='"${require}"'\.)(?!prototype)\w+' "${filepath}" | tr ' ' '\n' | sort -u) + local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) + local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) # Detect overlap (ex: Blockly.utils and Blockly.utils.dom) - local overlap=$(echo "${requires}"| grep -Po "(?<=${require}\.)\w+") + local overlap=$(echo "${requires}"| perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ ! -z "${overlap}" ]]; then while read -r overlap_prop ; do properties_accessed=$(echo "$properties_accessed" | perl -pe 's/'"${overlap_prop}"'//g') From edfb87fd6150b4b14c65f5f769e405b543d099c3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 15:37:50 -0700 Subject: [PATCH 137/313] Update more grep calls --- scripts/goog_module/convert-file.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index f7adee01e..9b62892b5 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -113,7 +113,7 @@ step2 () { inf "Extracted module name \"${module_name}\"" if [[ $(grep "${module_name} = " "${filepath}") ]]; then - local class_name=$(echo "${module_name}" | grep -E -o "(\w+)$") + local class_name=$(echo "${module_name}" | perl -nle'print $& while m{(\w+)$}g') inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" @@ -155,7 +155,7 @@ step3() { return 1 fi - local requires=$(grep -E -o '^goog.require(|Type)\('\''(.*)'\''\)' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') + local requires=$(perl -nle'print $& while m{^goog.require(|Type)\('\''(.*)'\''\)}g' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') # Process each require echo "${requires}" | while read -r require ; do @@ -200,7 +200,7 @@ step3() { perl -pi -e 's/'"${require}"'([^'\''\w])/'"${require_name}"'\1/g' "${filepath}" done - local missing_requires=$(grep -Po '(? Date: Thu, 24 Jun 2021 20:24:53 +0000 Subject: [PATCH 138/313] Bump google-closure-compiler from 20210505.0.0 to 20210601.0.0 Bumps [google-closure-compiler](https://github.com/google/closure-compiler-npm) from 20210505.0.0 to 20210601.0.0. - [Release notes](https://github.com/google/closure-compiler-npm/releases) - [Commits](https://github.com/google/closure-compiler-npm/compare/v20210505.0.0...v20210601.0.0) --- updated-dependencies: - dependency-name: google-closure-compiler dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package-lock.json | 38 +++++++++++++++++++------------------- package.json | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index d70d69a71..bc2e15371 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16916,45 +16916,45 @@ } }, "google-closure-compiler": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler/-/google-closure-compiler-20210505.0.0.tgz", - "integrity": "sha512-moeYaj4S6YTdOOvjv1ZLdUld/2YXw7q1GqUUHJJd+rE/uViyesozg8yKQZWcB3tvurhb+qEvFFet8CYoeaQHng==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler/-/google-closure-compiler-20210601.0.0.tgz", + "integrity": "sha512-lzzEoG2VTB7uUjnWnMyeZMU163w69HJpM27yh8Up9Ha5McHZeESjt3NRwU8cWMbCRdY06nFbRCDIVCRcadHCiw==", "dev": true, "requires": { "chalk": "2.x", - "google-closure-compiler-java": "^20210505.0.0", - "google-closure-compiler-linux": "^20210505.0.0", - "google-closure-compiler-osx": "^20210505.0.0", - "google-closure-compiler-windows": "^20210505.0.0", + "google-closure-compiler-java": "^20210601.0.0", + "google-closure-compiler-linux": "^20210601.0.0", + "google-closure-compiler-osx": "^20210601.0.0", + "google-closure-compiler-windows": "^20210601.0.0", "minimist": "1.x", "vinyl": "2.x", "vinyl-sourcemaps-apply": "^0.2.0" } }, "google-closure-compiler-java": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler-java/-/google-closure-compiler-java-20210505.0.0.tgz", - "integrity": "sha512-h+DfQAaaCLFmmtasOS8eyh0M4D+JInTJfEP4byV5R1cnMninpGGLHOG3PNgLLzkXkIO/fu4ILEcVzoGmgJEoMA==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler-java/-/google-closure-compiler-java-20210601.0.0.tgz", + "integrity": "sha512-bH6nIwOmp4qDWvlbXx5/DE3XA2aDGQoCpmRYZJGONY1Sy6Xfbq0ioXRHH9eBDP9hxhCJ5Sd/K89A0NZ8Nz9RJA==", "dev": true }, "google-closure-compiler-linux": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler-linux/-/google-closure-compiler-linux-20210505.0.0.tgz", - "integrity": "sha512-ADN2kFfIR1NiR24kLYb4YkX4MeXDJaT5OfRQEkiuIdZMtd28oEkm80LxCGuC7ftKEixoMm3f9/OG01B4U+xsnA==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler-linux/-/google-closure-compiler-linux-20210601.0.0.tgz", + "integrity": "sha512-rnEQt7zz/1P1SfPhJiHQpfCgMPrsVVyEgDs09h67xn6+LXa9L0RP+hrJDEHqSWwjDPz0BkfUUv6zkqZvp1h/lw==", "dev": true, "optional": true }, "google-closure-compiler-osx": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20210505.0.0.tgz", - "integrity": "sha512-JTwdh23aD2pwRU4QZjujxp/+rGfhex3utNWEdUDRMNpUGstUK7XPCDG8jNBtUpyuRiXFnpZa90qButqRgotQBA==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20210601.0.0.tgz", + "integrity": "sha512-A5r4s/WthR2iLMM0mxsluw8EW2AcOomC5ri/H6FjzpMq0RVEnLTgaGYdXolUAfEzH/7XtJJT2+JkYk3HSLCtrg==", "dev": true, "optional": true }, "google-closure-compiler-windows": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler-windows/-/google-closure-compiler-windows-20210505.0.0.tgz", - "integrity": "sha512-bKTbg/f4ak72OggEMaH/7oExqOO9dS+TxwGhoovYOt/YaVR/8MDfGdxsOhqoiboiFwYysTPz8bwINjYQK6AwnA==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler-windows/-/google-closure-compiler-windows-20210601.0.0.tgz", + "integrity": "sha512-6r94bPShnB0XXh9+5/qXGDHJN2PQGhF9yJPcgBZj+FAZlQGzlYkT0pkyp+loZT3lG+YRbjD28Lgo7xMcY4xgkA==", "dev": true, "optional": true }, diff --git a/package.json b/package.json index dda2766d2..969a07cba 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "clang-format": "^1.5.0", "concurrently": "^6.0.0", "eslint": "^7.28.0", - "google-closure-compiler": "^20210505.0.0", + "google-closure-compiler": "^20210601.0.0", "google-closure-deps": "^20210601.0.0", "gulp": "^4.0.2", "gulp-concat": "^2.6.1", From ce078a013941b466ebe6982d61798a9ccf3ac688 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Jul 2021 15:59:05 +0000 Subject: [PATCH 139/313] Bump typescript from 4.3.2 to 4.3.5 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.3.2 to 4.3.5. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v4.3.2...v4.3.5) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index bc2e15371..899eb7600 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21533,9 +21533,9 @@ "dev": true }, "typescript": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.2.tgz", - "integrity": "sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", + "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", "dev": true }, "typescript-closure-tools": { From 8d3c39212b370c54f2262d5e4955632c2b3455cb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 12 Jul 2021 13:37:25 -0700 Subject: [PATCH 140/313] Added script and workflow to automatically update build artifact sizes in check_metadata.sh --- .github/workflows/update_metadata.yml | 39 +++++++++++++++++++++++++++ tests/scripts/update_metadata.sh | 31 +++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/update_metadata.yml create mode 100755 tests/scripts/update_metadata.sh diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml new file mode 100644 index 000000000..5b5e401fa --- /dev/null +++ b/.github/workflows/update_metadata.yml @@ -0,0 +1,39 @@ +# This workflow updates the check_metadata.sh script, which compares the current +# size of build artifacts against their size in the previous version of Blockly. + +name: Update Metadata + +on: [workflow_dispatch] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node-version: [16.x] + + steps: + - name: Check Out Blockly + uses: actions/checkout@v2 + with: + ref: 'develop' + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Update Metadata + run: source ./tests/scripts/update_metadata.sh + + - name: Create Pull Request + uses: peter-evans/create-pull-request@9825ae65b1cb54b543b938503728b432a0176d29 + with: + commit-message: Updated build artifact sizes in check_metadata.sh + delete-branch: true + title: Updated build artifact sizes in check_metadata.sh + + - name: View Pull Request + run: echo "View Pull Request - ${{ steps.cpr.outputs.pull-request-url }}" \ No newline at end of file diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh new file mode 100755 index 000000000..cfd2f43d0 --- /dev/null +++ b/tests/scripts/update_metadata.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Determines the size of generated files and updates check_metadata.sh to +# reflect the new values. + +blockly_size=$(wc -c < "blockly_compressed.js") +blocks_size=$(wc -c < "blocks_compressed.js") +blockly_gz_size=$(wc -c < "blockly_compressed.js.gz") +blocks_gz_size=$(wc -c < "blocks_compressed.js.gz") +quarter=$(date "+Q%q %Y") +version=$(npx -c 'echo "$npm_package_version"') + +replacement="# ${quarter}\t${version}\t${blockly_size}\n" +replacement+="readonly BLOCKLY_SIZE_EXPECTED=${blockly_size}" +sed -ri "s/readonly BLOCKLY_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blocks_size}\n" +replacement+="readonly BLOCKS_SIZE_EXPECTED=${blocks_size}" +sed -ri "s/readonly BLOCKS_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blockly_gz_size}\n" +replacement+="readonly BLOCKLY_GZ_SIZE_EXPECTED=${blockly_gz_size}" +sed -ri "s/readonly BLOCKLY_GZ_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blocks_gz_size}\n" +replacement+="readonly BLOCKS_GZ_SIZE_EXPECTED=${blocks_gz_size}" +sed -ri "s/readonly BLOCKS_GZ_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh \ No newline at end of file From eddc5f676b2901277d5227fa21ed927f2fb08aa3 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 13 Jul 2021 08:43:52 -0700 Subject: [PATCH 141/313] Calculate metadata size from freshly-built and gzipped Blockly. --- .github/workflows/update_metadata.yml | 29 +++++++++++++++++---------- tests/scripts/update_metadata.sh | 8 ++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml index 5b5e401fa..7b83b5a03 100644 --- a/.github/workflows/update_metadata.yml +++ b/.github/workflows/update_metadata.yml @@ -6,13 +6,8 @@ name: Update Metadata on: [workflow_dispatch] jobs: - build: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ubuntu-latest] - node-version: [16.x] + update-metadata: + runs-on: ubuntu-latest steps: - name: Check Out Blockly @@ -20,10 +15,22 @@ jobs: with: ref: 'develop' - - name: Use Node.js ${{ matrix.node-version }} + - name: Use Node.js 16.x uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node-version }} + node-version: 16.x + + - name: Build Blockly + run: npm run build:compressed + + - name: Build Blockly blocks + run: npm run build:blocks + + - name: Gzip Blockly + run: gzip -k build/blockly_compressed.js + + - name: Gzip Blockly blocks + run: gzip -k build/blocks_compressed.js - name: Update Metadata run: source ./tests/scripts/update_metadata.sh @@ -31,9 +38,9 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@9825ae65b1cb54b543b938503728b432a0176d29 with: - commit-message: Updated build artifact sizes in check_metadata.sh + commit-message: Update build artifact sizes in check_metadata.sh delete-branch: true - title: Updated build artifact sizes in check_metadata.sh + title: Update build artifact sizes in check_metadata.sh - name: View Pull Request run: echo "View Pull Request - ${{ steps.cpr.outputs.pull-request-url }}" \ No newline at end of file diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh index cfd2f43d0..d0dac71e7 100755 --- a/tests/scripts/update_metadata.sh +++ b/tests/scripts/update_metadata.sh @@ -3,10 +3,10 @@ # Determines the size of generated files and updates check_metadata.sh to # reflect the new values. -blockly_size=$(wc -c < "blockly_compressed.js") -blocks_size=$(wc -c < "blocks_compressed.js") -blockly_gz_size=$(wc -c < "blockly_compressed.js.gz") -blocks_gz_size=$(wc -c < "blocks_compressed.js.gz") +blockly_size=$(wc -c < "build/blockly_compressed.js") +blocks_size=$(wc -c < "build/blocks_compressed.js") +blockly_gz_size=$(wc -c < "build/blockly_compressed.js.gz") +blocks_gz_size=$(wc -c < "build/blocks_compressed.js.gz") quarter=$(date "+Q%q %Y") version=$(npx -c 'echo "$npm_package_version"') From 78a5d98c20bf64876295c1b5ac6d4f849219569c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 10:58:08 -0700 Subject: [PATCH 142/313] Gzip build output files in update_metadata.sh instead of update_metadata.yml. --- .github/workflows/update_metadata.yml | 6 ------ tests/scripts/update_metadata.sh | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml index 7b83b5a03..82a36230f 100644 --- a/.github/workflows/update_metadata.yml +++ b/.github/workflows/update_metadata.yml @@ -26,12 +26,6 @@ jobs: - name: Build Blockly blocks run: npm run build:blocks - - name: Gzip Blockly - run: gzip -k build/blockly_compressed.js - - - name: Gzip Blockly blocks - run: gzip -k build/blocks_compressed.js - - name: Update Metadata run: source ./tests/scripts/update_metadata.sh diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh index d0dac71e7..d3b97f3ab 100755 --- a/tests/scripts/update_metadata.sh +++ b/tests/scripts/update_metadata.sh @@ -3,6 +3,9 @@ # Determines the size of generated files and updates check_metadata.sh to # reflect the new values. +gzip -k build/blockly_compressed.js +gzip -k build/blocks_compressed.js + blockly_size=$(wc -c < "build/blockly_compressed.js") blocks_size=$(wc -c < "build/blocks_compressed.js") blockly_gz_size=$(wc -c < "build/blockly_compressed.js.gz") From 926b14b15ee53f185959f5867a0811e110236a19 Mon Sep 17 00:00:00 2001 From: hpnrep6 Date: Fri, 16 Jul 2021 13:42:09 -0400 Subject: [PATCH 143/313] Fix code in code demo executing twice on mobile (#5037) * Prevent code from executing twice on touchscreens --- demos/code/code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/demos/code/code.js b/demos/code/code.js index 0c2765325..2377203a2 100644 --- a/demos/code/code.js +++ b/demos/code/code.js @@ -549,8 +549,14 @@ Code.initLanguage = function() { /** * Execute the user's code. * Just a quick and dirty eval. Catch infinite loops. + * @param {Event} event Event created from listener bound to the function. */ -Code.runJS = function() { +Code.runJS = function(event) { + // Prevent code from being executed twice on touchscreens. + if (event.type == 'touchend') { + event.preventDefault(); + } + Blockly.JavaScript.INFINITE_LOOP_TRAP = 'checkTimeout();\n'; var timeouts = 0; var checkTimeout = function() { From 3aa6b476aafc790c583dfd23826ff446119e2fcb Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Mon, 19 Jul 2021 15:59:27 +0100 Subject: [PATCH 144/313] Ignore public/ directory; always serve repository root By default http-server will serve ./public if it exists. We want it to always serve the repository root, so configure the start script to specify that explicitly, so that the existence of a public/ directory will not break things. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 969a07cba..6026bc4ec 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "publish:beta": "gulp publishBeta", "recompile": "gulp recompile", "release": "gulp gitCreateRC", - "start": "http-server -o /tests/playground.html", + "start": "http-server ./ -o /tests/playground.html", "test": "tests/run_all_tests.sh", "test:generators": "tests/scripts/run_generators.sh", "test:compile:advanced": "gulp buildAdvancedCompilationTest", From 50a66c024d6b0107e620ea6ed78e56c07cce4bfd Mon Sep 17 00:00:00 2001 From: jschanker Date: Mon, 19 Jul 2021 21:02:20 -0400 Subject: [PATCH 145/313] Permit single field disabling (#4932) (#4941) * Permit single field disabling (https://github.com/google/blockly/issues/4932) * Permit single field disabling (#4932) * Fixed lint error (moved && to end of line and adjusted line breaks accordingly) * Added XML Field (De)Serialization * Call parent method in FieldDropdown's fromXml * Added protected helper methods to handle serialization/deserialization of enabled property/attribute of fields * Minor changes to annotations to account for field disabling and 4 spaces per line break per style guide * Revert "Added XML Field (De)Serialization" This reverts commit 1964e866b6ab5c1615522f0a7a634a7ea9a9004b. * Comment style changes * Comment reversions * Indentation fix * Indentation reversion --- core/field.js | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/core/field.js b/core/field.js index c343359da..f5f027c45 100644 --- a/core/field.js +++ b/core/field.js @@ -203,6 +203,13 @@ Blockly.Field.prototype.isDirty_ = true; */ Blockly.Field.prototype.visible_ = true; +/** + * Can the field value be changed using the editor on an editable block? + * @type {boolean} + * @protected + */ +Blockly.Field.prototype.enabled_ = true; + /** * The element the click handler is bound to. * @type {Element} @@ -393,8 +400,8 @@ Blockly.Field.prototype.bindEvents_ = function() { }; /** - * Sets the field's value based on the given XML element. Should only be - * called by Blockly.Xml. + * Sets the field's value based on the given XML element. Should only be called + * by Blockly.Xml. * @param {!Element} fieldElement The element containing info about the * field's state. * @package @@ -441,7 +448,7 @@ Blockly.Field.prototype.updateEditable = function() { if (!this.EDITABLE || !group) { return; } - if (this.sourceBlock_.isEditable()) { + if (this.enabled_ && this.sourceBlock_.isEditable()) { Blockly.utils.dom.addClass(group, 'blocklyEditableText'); Blockly.utils.dom.removeClass(group, 'blocklyNonEditableText'); group.style.cursor = this.CURSOR; @@ -452,23 +459,45 @@ Blockly.Field.prototype.updateEditable = function() { } }; +/** + * Set whether this field's value can be changed using the editor when the + * source block is editable. + * @param {boolean} enabled True if enabled. + */ +Blockly.Field.prototype.setEnabled = function(enabled) { + this.enabled_ = enabled; + this.updateEditable(); +}; + +/** + * Check whether this field's value can be changed using the editor when the + * source block is editable. + * @return {boolean} Whether this field is enabled. + */ +Blockly.Field.prototype.isEnabled = function() { + return this.enabled_; +}; + /** * Check whether this field defines the showEditor_ function. * @return {boolean} Whether this field is clickable. */ Blockly.Field.prototype.isClickable = function() { - return !!this.sourceBlock_ && this.sourceBlock_.isEditable() && - !!this.showEditor_ && (typeof this.showEditor_ === 'function'); + return this.enabled_ && !!this.sourceBlock_ && + this.sourceBlock_.isEditable() && !!this.showEditor_ && + (typeof this.showEditor_ === 'function'); }; /** * Check whether this field is currently editable. Some fields are never * EDITABLE (e.g. text labels). Other fields may be EDITABLE but may exist on - * non-editable blocks. - * @return {boolean} Whether this field is editable and on an editable block + * non-editable blocks or be currently disabled. + * @return {boolean} Whether this field is currently enabled, editable and on + * an editable block. */ Blockly.Field.prototype.isCurrentlyEditable = function() { - return this.EDITABLE && !!this.sourceBlock_ && this.sourceBlock_.isEditable(); + return this.enabled_ && this.EDITABLE && !!this.sourceBlock_ && + this.sourceBlock_.isEditable(); }; /** From e9a16684455c790e98ae99c5321d71ca745c92d5 Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Mon, 19 Jul 2021 18:14:23 -0700 Subject: [PATCH 146/313] Only lint once in CI (#5128) --- .github/workflows/build.yml | 16 ++++++++++++++++ tests/run_all_tests.sh | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f00730990..9a7d2b859 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,3 +41,19 @@ jobs: env: CI: true + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js 16.x + uses: actions/setup-node@v1 + with: + node-version: 16.x + + - name: Npm Install + run: npm install + + - name: Lint + run: npm run lint diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh index f6c7c0f8c..ccb18cf9c 100755 --- a/tests/run_all_tests.sh +++ b/tests/run_all_tests.sh @@ -49,7 +49,10 @@ run_test_command () { } # Lint the codebase. -run_test_command "eslint" "eslint ." +# Skip for CI environments, because linting is run separately. +if [ -z $CI ]; then + run_test_command "eslint" "eslint ." +fi # Run the full usual build process. run_test_command "build" "npm run build" From 6b10f9545c7e18d806bc8926a7d612e61e0e8712 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 15:11:14 -0700 Subject: [PATCH 147/313] Migrate core/interfaces/i_registrable.js to goog.module --- core/interfaces/i_registrable.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/interfaces/i_registrable.js b/core/interfaces/i_registrable.js index f7b8ca719..5698ad313 100644 --- a/core/interfaces/i_registrable.js +++ b/core/interfaces/i_registrable.js @@ -12,11 +12,14 @@ 'use strict'; -goog.provide('Blockly.IRegistrable'); +goog.module('Blockly.IRegistrable'); +goog.module.declareLegacyNamespace(); /** * The interface for a Blockly component that can be registered. * @interface */ -Blockly.IRegistrable = function() {}; +const IRegistrable = function() {}; + +exports = IRegistrable; diff --git a/tests/deps.js b/tests/deps.js index 95ce972c7..aa7cf5039 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -93,7 +93,7 @@ goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.I 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'}); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); +goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); 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'}); From 599385891a896e9f6f4b18442076f5ba8ce3db5f Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:08:27 -0700 Subject: [PATCH 148/313] Break up interfaces in core/i_toolbox_item.js into separate files --- core/interfaces/i_collapsible_toolbox_item.js | 45 +++++++++++ core/interfaces/i_selectable_toolbox_item.js | 65 ++++++++++++++++ core/interfaces/i_toolbox_item.js | 76 ------------------- 3 files changed, 110 insertions(+), 76 deletions(-) create mode 100644 core/interfaces/i_collapsible_toolbox_item.js create mode 100644 core/interfaces/i_selectable_toolbox_item.js diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js new file mode 100644 index 000000000..c92008358 --- /dev/null +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -0,0 +1,45 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for a collapsible toolbox item. + * @author kozbial@google.com (Monica Kozbial) + */ + +'use strict'; + +goog.provide('Blockly.ICollapsibleToolboxItem'); + +goog.require('Blockly.IToolboxItem'); +goog.requireType('Blockly.utils.toolbox'); + + +/** + * Interface for an item in the toolbox that can be collapsed. + * @extends {Blockly.ISelectableToolboxItem} + * @interface + */ +Blockly.ICollapsibleToolboxItem = function() {}; + +/** + * Gets any children toolbox items. (ex. Gets the subcategories) + * @return {!Array} The child toolbox items. + */ +Blockly.ICollapsibleToolboxItem.prototype.getChildToolboxItems; + +/** + * Whether the toolbox item is expanded to show its child subcategories. + * @return {boolean} True if the toolbox item shows its children, false if it + * is collapsed. + * @public + */ +Blockly.ICollapsibleToolboxItem.prototype.isExpanded; + +/** + * Toggles whether or not the toolbox item is expanded. + * @public + */ +Blockly.ICollapsibleToolboxItem.prototype.toggleExpanded; diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js new file mode 100644 index 000000000..fb7b8558f --- /dev/null +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -0,0 +1,65 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for a selectable toolbox item. + * @author aschmiedt@google.com (Abby Schmiedt) + */ + +'use strict'; + +goog.provide('Blockly.ISelectableToolboxItem'); + +goog.require('Blockly.IToolboxItem'); +goog.requireType('Blockly.utils.toolbox'); + + +/** + * Interface for an item in the toolbox that can be selected. + * @extends {Blockly.IToolboxItem} + * @interface + */ +Blockly.ISelectableToolboxItem = function() {}; + +/** + * Gets the name of the toolbox item. Used for emitting events. + * @return {string} The name of the toolbox item. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.getName; + +/** + * Gets the contents of the toolbox item. These are items that are meant to be + * displayed in the flyout. + * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray|string} The definition + * of items to be displayed in the flyout. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.getContents; + +/** + * Sets the current toolbox item as selected. + * @param {boolean} _isSelected True if this category is selected, false + * otherwise. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.setSelected; + +/** + * Gets the HTML element that is clickable. + * The parent toolbox element receives clicks. The parent toolbox will add an ID + * to this element so it can pass the onClick event to the correct toolboxItem. + * @return {!Element} The HTML element that receives clicks. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.getClickTarget; + +/** + * Handles when the toolbox item is clicked. + * @param {!Event} _e Click event to handle. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.onClick; diff --git a/core/interfaces/i_toolbox_item.js b/core/interfaces/i_toolbox_item.js index afd6191f7..ce646d376 100644 --- a/core/interfaces/i_toolbox_item.js +++ b/core/interfaces/i_toolbox_item.js @@ -11,8 +11,6 @@ 'use strict'; -goog.provide('Blockly.ICollapsibleToolboxItem'); -goog.provide('Blockly.ISelectableToolboxItem'); goog.provide('Blockly.IToolboxItem'); goog.requireType('Blockly.utils.toolbox'); @@ -81,77 +79,3 @@ Blockly.IToolboxItem.prototype.isCollapsible; * @public */ Blockly.IToolboxItem.prototype.dispose; - -/** - * Interface for an item in the toolbox that can be selected. - * @extends {Blockly.IToolboxItem} - * @interface - */ -Blockly.ISelectableToolboxItem = function() {}; - -/** - * Gets the name of the toolbox item. Used for emitting events. - * @return {string} The name of the toolbox item. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.getName; - -/** - * Gets the contents of the toolbox item. These are items that are meant to be - * displayed in the flyout. - * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray|string} The definition - * of items to be displayed in the flyout. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.getContents; - -/** - * Sets the current toolbox item as selected. - * @param {boolean} _isSelected True if this category is selected, false - * otherwise. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.setSelected; - -/** - * Gets the HTML element that is clickable. - * The parent toolbox element receives clicks. The parent toolbox will add an ID - * to this element so it can pass the onClick event to the correct toolboxItem. - * @return {!Element} The HTML element that receives clicks. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.getClickTarget; - -/** - * Handles when the toolbox item is clicked. - * @param {!Event} _e Click event to handle. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.onClick; - -/** - * Interface for an item in the toolbox that can be collapsed. - * @extends {Blockly.ISelectableToolboxItem} - * @interface - */ -Blockly.ICollapsibleToolboxItem = function() {}; - -/** - * Gets any children toolbox items. (ex. Gets the subcategories) - * @return {!Array} The child toolbox items. - */ -Blockly.ICollapsibleToolboxItem.prototype.getChildToolboxItems; - -/** - * Whether the toolbox item is expanded to show its child subcategories. - * @return {boolean} True if the toolbox item shows its children, false if it - * is collapsed. - * @public - */ -Blockly.ICollapsibleToolboxItem.prototype.isExpanded; - -/** - * Toggles whether or not the toolbox item is expanded. - * @public - */ -Blockly.ICollapsibleToolboxItem.prototype.toggleExpanded; From 1b09c8d8b736257d5829c9629c3dcc7e771f0290 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:09:51 -0700 Subject: [PATCH 149/313] Migrate core/interfaces/i_collapsible_toolbox_item.js, core/interfaces/i_selectable_toolbox_item.js, and core/interfaces/i_toolbox_item.js to goog.module --- core/interfaces/i_collapsible_toolbox_item.js | 17 +++++++------ core/interfaces/i_selectable_toolbox_item.js | 17 +++++++------ core/interfaces/i_toolbox_item.js | 25 ++++++++++--------- tests/deps.js | 4 ++- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js index c92008358..3af4d2692 100644 --- a/core/interfaces/i_collapsible_toolbox_item.js +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -11,10 +11,11 @@ 'use strict'; -goog.provide('Blockly.ICollapsibleToolboxItem'); +goog.module('Blockly.ICollapsibleToolboxItem'); +goog.module.declareLegacyNamespace(); -goog.require('Blockly.IToolboxItem'); -goog.requireType('Blockly.utils.toolbox'); +goog.require('Blockly.ISelectableToolboxItem'); +goog.requireType('Blockly.IToolboxItem'); /** @@ -22,13 +23,13 @@ goog.requireType('Blockly.utils.toolbox'); * @extends {Blockly.ISelectableToolboxItem} * @interface */ -Blockly.ICollapsibleToolboxItem = function() {}; +const ICollapsibleToolboxItem = function() {}; /** * Gets any children toolbox items. (ex. Gets the subcategories) * @return {!Array} The child toolbox items. */ -Blockly.ICollapsibleToolboxItem.prototype.getChildToolboxItems; +ICollapsibleToolboxItem.prototype.getChildToolboxItems; /** * Whether the toolbox item is expanded to show its child subcategories. @@ -36,10 +37,12 @@ Blockly.ICollapsibleToolboxItem.prototype.getChildToolboxItems; * is collapsed. * @public */ -Blockly.ICollapsibleToolboxItem.prototype.isExpanded; +ICollapsibleToolboxItem.prototype.isExpanded; /** * Toggles whether or not the toolbox item is expanded. * @public */ -Blockly.ICollapsibleToolboxItem.prototype.toggleExpanded; +ICollapsibleToolboxItem.prototype.toggleExpanded; + +exports = ICollapsibleToolboxItem; diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js index fb7b8558f..535f65401 100644 --- a/core/interfaces/i_selectable_toolbox_item.js +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.ISelectableToolboxItem'); +goog.module('Blockly.ISelectableToolboxItem'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IToolboxItem'); goog.requireType('Blockly.utils.toolbox'); @@ -22,14 +23,14 @@ goog.requireType('Blockly.utils.toolbox'); * @extends {Blockly.IToolboxItem} * @interface */ -Blockly.ISelectableToolboxItem = function() {}; +const ISelectableToolboxItem = function() {}; /** * Gets the name of the toolbox item. Used for emitting events. * @return {string} The name of the toolbox item. * @public */ -Blockly.ISelectableToolboxItem.prototype.getName; +ISelectableToolboxItem.prototype.getName; /** * Gets the contents of the toolbox item. These are items that are meant to be @@ -38,7 +39,7 @@ Blockly.ISelectableToolboxItem.prototype.getName; * of items to be displayed in the flyout. * @public */ -Blockly.ISelectableToolboxItem.prototype.getContents; +ISelectableToolboxItem.prototype.getContents; /** * Sets the current toolbox item as selected. @@ -46,7 +47,7 @@ Blockly.ISelectableToolboxItem.prototype.getContents; * otherwise. * @public */ -Blockly.ISelectableToolboxItem.prototype.setSelected; +ISelectableToolboxItem.prototype.setSelected; /** * Gets the HTML element that is clickable. @@ -55,11 +56,13 @@ Blockly.ISelectableToolboxItem.prototype.setSelected; * @return {!Element} The HTML element that receives clicks. * @public */ -Blockly.ISelectableToolboxItem.prototype.getClickTarget; +ISelectableToolboxItem.prototype.getClickTarget; /** * Handles when the toolbox item is clicked. * @param {!Event} _e Click event to handle. * @public */ -Blockly.ISelectableToolboxItem.prototype.onClick; +ISelectableToolboxItem.prototype.onClick; + +exports = ISelectableToolboxItem; diff --git a/core/interfaces/i_toolbox_item.js b/core/interfaces/i_toolbox_item.js index ce646d376..061b7ae27 100644 --- a/core/interfaces/i_toolbox_item.js +++ b/core/interfaces/i_toolbox_item.js @@ -11,16 +11,15 @@ 'use strict'; -goog.provide('Blockly.IToolboxItem'); - -goog.requireType('Blockly.utils.toolbox'); +goog.module('Blockly.IToolboxItem'); +goog.module.declareLegacyNamespace(); /** * Interface for an item in the toolbox. * @interface */ -Blockly.IToolboxItem = function() {}; +const IToolboxItem = function() {}; /** * Initializes the toolbox item. @@ -29,21 +28,21 @@ Blockly.IToolboxItem = function() {}; * @return {void} * @public */ -Blockly.IToolboxItem.prototype.init; +IToolboxItem.prototype.init; /** * Gets the div for the toolbox item. * @return {?Element} The div for the toolbox item. * @public */ -Blockly.IToolboxItem.prototype.getDiv; +IToolboxItem.prototype.getDiv; /** * Gets a unique identifier for this toolbox item. * @return {string} The ID for the toolbox item. * @public */ -Blockly.IToolboxItem.prototype.getId; +IToolboxItem.prototype.getId; /** * Gets the parent if the toolbox item is nested. @@ -51,31 +50,33 @@ Blockly.IToolboxItem.prototype.getId; * this toolbox item is not nested. * @public */ -Blockly.IToolboxItem.prototype.getParent; +IToolboxItem.prototype.getParent; /** * Gets the nested level of the category. * @return {number} The nested level of the category. * @package */ -Blockly.IToolboxItem.prototype.getLevel; +IToolboxItem.prototype.getLevel; /** * Whether the toolbox item is selectable. * @return {boolean} True if the toolbox item can be selected. * @public */ -Blockly.IToolboxItem.prototype.isSelectable; +IToolboxItem.prototype.isSelectable; /** * Whether the toolbox item is collapsible. * @return {boolean} True if the toolbox item is collapsible. * @public */ -Blockly.IToolboxItem.prototype.isCollapsible; +IToolboxItem.prototype.isCollapsible; /** * Dispose of this toolbox item. No-op by default. * @public */ -Blockly.IToolboxItem.prototype.dispose; +IToolboxItem.prototype.dispose; + +exports = IToolboxItem; diff --git a/tests/deps.js b/tests/deps.js index aa7cf5039..979c58c74 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -80,6 +80,7 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid 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'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_collapsible_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem'], ['Blockly.ISelectableToolboxItem'], {'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'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); @@ -96,9 +97,10 @@ goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositio goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'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'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From 3c77ff1fb2d6096a00d21f99fe71a5df48b2e750 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:19:08 -0700 Subject: [PATCH 150/313] Migrate core/interfaces/i_collapsible_toolbox_item.js, core/interfaces/i_selectable_toolbox_item.js, and core/interfaces/i_toolbox_item.js named requires --- core/interfaces/i_collapsible_toolbox_item.js | 8 ++++---- core/interfaces/i_selectable_toolbox_item.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js index 3af4d2692..732c7aab7 100644 --- a/core/interfaces/i_collapsible_toolbox_item.js +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -14,20 +14,20 @@ goog.module('Blockly.ICollapsibleToolboxItem'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ISelectableToolboxItem'); -goog.requireType('Blockly.IToolboxItem'); +const ISelectableToolboxItem = goog.require('Blockly.ISelectableToolboxItem'); +const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); /** * Interface for an item in the toolbox that can be collapsed. - * @extends {Blockly.ISelectableToolboxItem} + * @extends {ISelectableToolboxItem} * @interface */ const ICollapsibleToolboxItem = function() {}; /** * Gets any children toolbox items. (ex. Gets the subcategories) - * @return {!Array} The child toolbox items. + * @return {!Array} The child toolbox items. */ ICollapsibleToolboxItem.prototype.getChildToolboxItems; diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js index 535f65401..2addc7b9e 100644 --- a/core/interfaces/i_selectable_toolbox_item.js +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -14,13 +14,13 @@ goog.module('Blockly.ISelectableToolboxItem'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IToolboxItem'); -goog.requireType('Blockly.utils.toolbox'); +const IToolboxItem = goog.require('Blockly.IToolboxItem'); +const {FlyoutItemInfoArray} = goog.requireType('Blockly.utils.toolbox'); /** * Interface for an item in the toolbox that can be selected. - * @extends {Blockly.IToolboxItem} + * @extends {IToolboxItem} * @interface */ const ISelectableToolboxItem = function() {}; @@ -35,7 +35,7 @@ ISelectableToolboxItem.prototype.getName; /** * Gets the contents of the toolbox item. These are items that are meant to be * displayed in the flyout. - * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray|string} The definition + * @return {!FlyoutItemInfoArray|string} The definition * of items to be displayed in the flyout. * @public */ From b2ed132ebb1f5d3bd118c4085472ad1d9f14f06b Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:52:52 -0700 Subject: [PATCH 151/313] Fix bug where script was incorrectly reporting missing requires --- scripts/goog_module/convert-file.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 9b62892b5..35d3f3377 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -201,12 +201,12 @@ step3() { done local missing_requires=$(perl -nle'print $& while m{(? Date: Tue, 20 Jul 2021 17:54:09 -0700 Subject: [PATCH 152/313] Fix bugs caused by Blockly being a require --- scripts/goog_module/convert-file.sh | 31 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 35d3f3377..5fc37fe19 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -155,6 +155,14 @@ step3() { return 1 fi + inf "Extracting module name..." + local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") + if [[ -z "${module_name}" ]]; then + err "Could not extract module name" + return 1 + fi + inf "Extracted module name \"${module_name}\"" + local requires=$(perl -nle'print $& while m{^goog.require(|Type)\('\''(.*)'\''\)}g' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') # Process each require @@ -169,14 +177,21 @@ step3() { local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) - # Detect overlap (ex: Blockly.utils and Blockly.utils.dom) - local overlap=$(echo "${requires}"| perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ ! -z "${overlap}" ]]; then - while read -r overlap_prop ; do - properties_accessed=$(echo "$properties_accessed" | perl -pe 's/'"${overlap_prop}"'//g') - done <<<"${overlap}" - properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) + # Detect requires overlap + # (ex: Blockly.utils require and Blockly.utils.dom also in requires) + local requires_overlap=$(echo "${requires}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + if [[ ! -z "${requires_overlap}" ]]; then + while read -r requires_overlap_prop ; do + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') + done <<<"${requires_overlap}" fi + # Detect module name overlap + # (ex: Blockly require and Blockly.ContextMenuItems module being converted) + local module_overlap=$(echo "${module_name}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + if [[ ! -z "${module_overlap}" ]]; then + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') + fi + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) if [[ "${direct_access_count}" -eq "0" && ! -z "${properties_accessed}" ]]; then local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') @@ -185,7 +200,7 @@ step3() { inf "Updating require declaration for ${require}..." perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - echo "${properties_accessed}" | while read -r require_prop ; do + for require_prop in $(echo "${properties_accessed}"); do inf "Updating references of ${require}.${require_prop} to ${require_prop}..." perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" done From 5e3209b6f5dfccc2ca5ee076a50c045ec225a9fc Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 17:57:37 -0700 Subject: [PATCH 153/313] Remove extra logging line --- scripts/goog_module/convert-file.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 5fc37fe19..7a440b8b9 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -217,7 +217,6 @@ step3() { local missing_requires=$(perl -nle'print $& while m{(? Date: Tue, 20 Jul 2021 18:16:37 -0700 Subject: [PATCH 154/313] fix formatting and help --- scripts/goog_module/convert-file.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 7a440b8b9..79ceeed42 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -141,7 +141,6 @@ step2 () { npm run build:deps success "Completed automation for step 3. Please manually review and add exports for non-private top-level functions." - } ####################################### # Runs step 3 of the automated conversion. @@ -285,7 +284,7 @@ function help { echo " 3. Rewrite goog.requires statements and add missing requires (often skipped for simple files)" echo " 4. Run clang-format on the whole file" echo "" - echo "Usage: $0 [-h|-c |-s |-f] " + echo "Usage: $0 [-h|-c |-s ] " echo " -h Display help" echo " -c Create a commit for the specified step [2-4]" echo " -s Run the specified step [1-4]" From 8d6f2626cda8703c1b4a01139cc721f76e854bae Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 19:01:01 -0700 Subject: [PATCH 155/313] Remove command to add missing nullability modifiers --- scripts/goog_module/convert-file.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 79ceeed42..1861ad7f3 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -219,9 +219,6 @@ step3() { err "Missing requires for: ${missing_requires} Please manually fix." fi - inf "Add missing nullability modifiers..." - perl -pi -e 's/@(param|return) \{([A-Z])/@\1 \{?\2/g' "${filepath}" - success "Completed automation for step 3. Please manually review and reorder requires." } ####################################### From 0e6258ca1a78f384944977c29e5c3e3bcf0ba748 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:17:13 -0700 Subject: [PATCH 156/313] Migrated to inline exports --- core/block_animations.js | 31 +++++----- core/block_drag_surface.js | 2 +- core/bubble_dragger.js | 11 +++- core/comment.js | 6 ++ core/component_manager.js | 5 ++ core/connection.js | 8 ++- core/connection_checker.js | 2 + core/connection_db.js | 3 + core/css.js | 9 +-- core/extensions.js | 20 +++--- core/interfaces/i_ast_node_location_svg.js | 1 + .../i_ast_node_location_with_block.js | 2 + core/interfaces/i_autohideable.js | 1 + core/interfaces/i_block_dragger.js | 2 + core/interfaces/i_bounded_element.js | 1 + core/interfaces/i_bubble.js | 4 ++ core/interfaces/i_connection_checker.js | 2 + core/interfaces/i_copyable.js | 2 + core/interfaces/i_delete_area.js | 2 + core/interfaces/i_drag_target.js | 3 + core/interfaces/i_draggable.js | 1 + core/interfaces/i_flyout.js | 6 ++ core/interfaces/i_keyboard_accessible.js | 1 + core/interfaces/i_positionable.js | 3 + core/interfaces/i_toolbox.js | 5 ++ core/renderers/common/drawer.js | 9 ++- core/utils/colour.js | 15 ++--- core/utils/deprecation.js | 5 +- core/utils/idgenerator.js | 4 +- core/utils/math.js | 9 +-- core/utils/object.js | 11 ++-- core/utils/style.js | 48 +++++++-------- core/utils/svg_paths.js | 27 +++----- core/utils/toolbox.js | 61 ++++++++----------- 34 files changed, 178 insertions(+), 144 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 86b4b44b5..27926002e 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -13,9 +13,10 @@ goog.module('Blockly.blockAnimations'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); -const dom = goog.require('Blockly.utils.dom'); const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); /** @@ -34,7 +35,7 @@ let disconnectGroup = null; * Play some UI effects (sound, animation) when disposing of a block. * @param {!BlockSvg} block The block being disposed of. */ -function disposeUiEffect(block) { +const disposeUiEffect = function(block) { const workspace = block.workspace; const svgGroup = block.getSvgRoot(); workspace.getAudioManager().play('delete'); @@ -49,7 +50,7 @@ function disposeUiEffect(block) { clone.bBox_ = clone.getBBox(); // Start the animation. disposeUiStep(clone, workspace.RTL, new Date, workspace.scale); -} +}; /** @package */ exports.disposeUiEffect = disposeUiEffect; @@ -62,7 +63,7 @@ exports.disposeUiEffect = disposeUiEffect; * @param {!Date} start Date of animation's start. * @param {number} workspaceScale Scale of workspace. */ -function disposeUiStep(clone, rtl, start, workspaceScale) { +const disposeUiStep = function(clone, rtl, start, workspaceScale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -78,13 +79,13 @@ function disposeUiStep(clone, rtl, start, workspaceScale) { ' scale(' + scale + ')'); setTimeout(disposeUiStep, 10, clone, rtl, start, workspaceScale); } -} +}; /** * Play some UI effects (sound, ripple) after a connection has been established. * @param {!BlockSvg} block The block being connected. */ -function connectionUiEffect(block) { +const connectionUiEffect = function(block) { const workspace = block.workspace; const scale = workspace.scale; workspace.getAudioManager().play('click'); @@ -113,7 +114,7 @@ function connectionUiEffect(block) { workspace.getParentSvg()); // Start the animation. connectionUiStep(ripple, new Date, scale); -} +}; /** @package */ exports.connectionUiEffect = connectionUiEffect; @@ -123,7 +124,7 @@ exports.connectionUiEffect = connectionUiEffect; * @param {!Date} start Date of animation's start. * @param {number} scale Scale of workspace. */ -function connectionUiStep(ripple, start, scale) { +const connectionUiStep = function(ripple, start, scale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -133,13 +134,13 @@ function connectionUiStep(ripple, start, scale) { ripple.style.opacity = 1 - percent; disconnectPid = setTimeout(connectionUiStep, 10, ripple, start, scale); } -} +}; /** * Play some UI effects (sound, animation) when disconnecting a block. * @param {!BlockSvg} block The block being disconnected. */ -function disconnectUiEffect(block) { +const disconnectUiEffect = function(block) { block.workspace.getAudioManager().play('disconnect'); if (block.workspace.scale < 1) { return; // Too small to care about visual effects. @@ -154,7 +155,7 @@ function disconnectUiEffect(block) { } // Start the animation. disconnectUiStep(block.getSvgRoot(), magnitude, new Date); -} +}; /** @package */ exports.disconnectUiEffect = disconnectUiEffect; @@ -164,7 +165,7 @@ exports.disconnectUiEffect = disconnectUiEffect; * @param {number} magnitude Maximum degrees skew (reversed for RTL). * @param {!Date} start Date of animation's start. */ -function disconnectUiStep(group, magnitude, start) { +const disconnectUiStep = function(group, magnitude, start) { const DURATION = 200; // Milliseconds. const WIGGLES = 3; // Half oscillations. @@ -181,12 +182,12 @@ function disconnectUiStep(group, magnitude, start) { disconnectPid = setTimeout(disconnectUiStep, 10, group, magnitude, start); } group.setAttribute('transform', group.translate_ + group.skew_); -} +}; /** * Stop the disconnect UI animation immediately. */ -function disconnectUiStop() { +const disconnectUiStop = function() { if (disconnectGroup) { clearTimeout(disconnectPid); const group = disconnectGroup; @@ -194,6 +195,6 @@ function disconnectUiStop() { group.setAttribute('transform', group.translate_); disconnectGroup = null; } -} +}; /** @package */ exports.disconnectUiStop = disconnectUiStop; diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 69b7a5ca5..2b911ef09 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -20,8 +20,8 @@ goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); const {G, SVG} = goog.require('Blockly.utils.Svg'); -const {getRelativeXY} = goog.require('Blockly.utils'); const {createSvgElement, HTML_NS, setCssTransform, SVG_NS, XLINK_NS} = goog.require('Blockly.utils.dom'); +const {getRelativeXY} = goog.require('Blockly.utils'); /** diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 3a6d36331..d06c2fdc0 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -13,21 +13,26 @@ goog.module('Blockly.BubbleDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ 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'); +/* eslint-disable-next-line no-unused-vars */ const IBubble = goog.requireType('Blockly.IBubble'); +/* eslint-disable-next-line no-unused-vars */ const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); -const utils = goog.require('Blockly.utils'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Bubble'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -/** @suppress {extraRequire} */ goog.require('Blockly.Events.CommentMove'); +/** @suppress {extraRequire} */ +goog.require('Blockly.constants'); /** diff --git a/core/comment.js b/core/comment.js index 7f4085faf..99d81e89c 100644 --- a/core/comment.js +++ b/core/comment.js @@ -13,16 +13,22 @@ goog.module('Blockly.Comment'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const Bubble = goog.require('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); const Events = goog.require('Blockly.Events'); const Icon = goog.require('Blockly.Icon'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const userAgent = goog.require('Blockly.utils.userAgent'); +/* eslint-disable-next-line no-unused-vars */ const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); const {inherits} = goog.require('Blockly.utils.object'); diff --git a/core/component_manager.js b/core/component_manager.js index 31b661e8a..ad2370bd6 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -14,10 +14,15 @@ goog.module('Blockly.ComponentManager'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IAutoHideable = goog.requireType('Blockly.IAutoHideable'); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.requireType('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); +/* eslint-disable-next-line no-unused-vars */ const IPositionable = goog.requireType('Blockly.IPositionable'); diff --git a/core/connection.js b/core/connection.js index 553938825..f272b59e0 100644 --- a/core/connection.js +++ b/core/connection.js @@ -13,14 +13,18 @@ goog.module('Blockly.Connection'); goog.module.declareLegacyNamespace(); -const connectionTypes = goog.require('Blockly.connectionTypes'); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); -const deprecation = goog.require('Blockly.utils.deprecation'); const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const Input = goog.requireType('Blockly.Input'); const Xml = goog.require('Blockly.Xml'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const deprecation = goog.require('Blockly.utils.deprecation'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); /** @suppress {extraRequire} */ diff --git a/core/connection_checker.js b/core/connection_checker.js index 4bd7bd4e2..12c6418db 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -15,7 +15,9 @@ goog.module('Blockly.ConnectionChecker'); goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); diff --git a/core/connection_db.js b/core/connection_db.js index 49bccb504..d3bc0507d 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -15,8 +15,11 @@ goog.module('Blockly.ConnectionDB'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.require('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ diff --git a/core/css.js b/core/css.js index 52228b4fb..6f34e6c0d 100644 --- a/core/css.js +++ b/core/css.js @@ -39,6 +39,7 @@ const register = function(cssArray) { Array.prototype.push.apply(CONTENT, cssArray); cssArray.length = 0; // Garbage collect provided CSS content. }; +exports.register = register; /** * Inject the CSS into the DOM. This is preferable over using a regular CSS @@ -72,6 +73,7 @@ const inject = function(hasCss, pathToMedia) { cssNode.appendChild(cssTextNode); document.head.insertBefore(cssNode, document.head.firstChild); }; +exports.inject = inject; /** * Array making up the CSS content for Blockly. @@ -553,9 +555,4 @@ const CONTENT = [ margin-right: -24px; }`, ]; - -exports = { - register, - inject, - CONTENT -}; +exports.CONTENT = CONTENT; diff --git a/core/extensions.js b/core/extensions.js index c73737c43..3f20777aa 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -20,6 +20,7 @@ goog.module('Blockly.Extensions'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goog.require('Blockly.utils'); @@ -29,6 +30,7 @@ const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goo * @private */ const allExtensions = Object.create(null); +exports.ALL_ = allExtensions; /** * Registers a new extension function. Extensions are functions that help @@ -52,6 +54,7 @@ const register = function(name, initFn) { } allExtensions[name] = initFn; }; +exports.register = register; /** * Registers a new extension function that adds all key/value of mixinObj. @@ -68,6 +71,7 @@ const registerMixin = function(name, mixinObj) { this.mixin(mixinObj); }); }; +exports.registerMixin = registerMixin; /** * Registers a new extension function that adds a mutator to the block. @@ -111,6 +115,7 @@ const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { } }); }; +exports.registerMutator = registerMutator; /** * Unregisters the extension registered with the given name. @@ -124,6 +129,7 @@ const unregister = function(name) { 'No extension mapping for name "' + name + '" found to unregister'); } }; +exports.unregister = unregister; /** * Applies an extension method to a block. This should only be called during @@ -161,6 +167,7 @@ const apply = function(name, block, isMutator) { } } }; +exports.apply = apply; /** * Check that the given value is a function. @@ -366,6 +373,7 @@ const buildTooltipForDropdown = function(dropdownName, lookupTable) { }; return extensionFn; }; +exports.buildTooltipForDropdown = buildTooltipForDropdown; /** * Checks all options keys are present in the provided string lookup table. @@ -425,6 +433,7 @@ const buildTooltipWithFieldText = function(msgTemplate, fieldName) { }; return extensionFn; }; +exports.buildTooltipWithFieldText = buildTooltipWithFieldText; /** * Configures the tooltip to mimic the parent block when connected. Otherwise, @@ -443,14 +452,3 @@ const extensionParentTooltip = function() { }.bind(this)); }; register('parent_tooltip_when_inline', extensionParentTooltip); - -exports = { - ALL_: allExtensions, - register, - registerMixin, - registerMutator, - unregister, - apply, - buildTooltipForDropdown, - buildTooltipWithFieldText -}; diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js index 5b58d4abc..526fbffa3 100644 --- a/core/interfaces/i_ast_node_location_svg.js +++ b/core/interfaces/i_ast_node_location_svg.js @@ -14,6 +14,7 @@ goog.module('Blockly.IASTNodeLocationSvg'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js index 58da7a902..002db0ad8 100644 --- a/core/interfaces/i_ast_node_location_with_block.js +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -15,7 +15,9 @@ goog.module('Blockly.IASTNodeLocationWithBlock'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); diff --git a/core/interfaces/i_autohideable.js b/core/interfaces/i_autohideable.js index bf11adc01..0ccbf310a 100644 --- a/core/interfaces/i_autohideable.js +++ b/core/interfaces/i_autohideable.js @@ -15,6 +15,7 @@ goog.module('Blockly.IAutoHideable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); diff --git a/core/interfaces/i_block_dragger.js b/core/interfaces/i_block_dragger.js index ebfc820ba..b87cd9865 100644 --- a/core/interfaces/i_block_dragger.js +++ b/core/interfaces/i_block_dragger.js @@ -14,7 +14,9 @@ goog.module('Blockly.IBlockDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); diff --git a/core/interfaces/i_bounded_element.js b/core/interfaces/i_bounded_element.js index 461d52ca1..f2c84633e 100644 --- a/core/interfaces/i_bounded_element.js +++ b/core/interfaces/i_bounded_element.js @@ -14,6 +14,7 @@ goog.module('Blockly.IBoundedElement'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index e41a1bf25..b6e9736d7 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -14,9 +14,13 @@ goog.module('Blockly.IBubble'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IContextMenu = goog.require('Blockly.IContextMenu'); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.require('Blockly.IDraggable'); diff --git a/core/interfaces/i_connection_checker.js b/core/interfaces/i_connection_checker.js index 03693604c..d0eb21e24 100644 --- a/core/interfaces/i_connection_checker.js +++ b/core/interfaces/i_connection_checker.js @@ -14,7 +14,9 @@ goog.module('Blockly.IConnectionChecker'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Connection = goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); diff --git a/core/interfaces/i_copyable.js b/core/interfaces/i_copyable.js index 07556eb23..87b776600 100644 --- a/core/interfaces/i_copyable.js +++ b/core/interfaces/i_copyable.js @@ -14,7 +14,9 @@ goog.module('Blockly.ICopyable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const ISelectable = goog.requireType('Blockly.ISelectable'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); diff --git a/core/interfaces/i_delete_area.js b/core/interfaces/i_delete_area.js index 5c5cbd380..845d7dddb 100644 --- a/core/interfaces/i_delete_area.js +++ b/core/interfaces/i_delete_area.js @@ -15,7 +15,9 @@ goog.module('Blockly.IDeleteArea'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.require('Blockly.IDragTarget'); diff --git a/core/interfaces/i_drag_target.js b/core/interfaces/i_drag_target.js index 803bcbc74..6b777781d 100644 --- a/core/interfaces/i_drag_target.js +++ b/core/interfaces/i_drag_target.js @@ -15,8 +15,11 @@ goog.module('Blockly.IDragTarget'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); diff --git a/core/interfaces/i_draggable.js b/core/interfaces/i_draggable.js index 81303a24b..5d7e17d53 100644 --- a/core/interfaces/i_draggable.js +++ b/core/interfaces/i_draggable.js @@ -14,6 +14,7 @@ goog.module('Blockly.IDraggable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IDeletable = goog.require('Blockly.IDeletable'); diff --git a/core/interfaces/i_flyout.js b/core/interfaces/i_flyout.js index b9b1c8e15..23c76dd0b 100644 --- a/core/interfaces/i_flyout.js +++ b/core/interfaces/i_flyout.js @@ -14,11 +14,17 @@ goog.module('Blockly.IFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ const Svg = goog.requireType('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const {FlyoutDefinition} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 8f21153da..8243e67d1 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -14,6 +14,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); diff --git a/core/interfaces/i_positionable.js b/core/interfaces/i_positionable.js index ed324196b..1fe773add 100644 --- a/core/interfaces/i_positionable.js +++ b/core/interfaces/i_positionable.js @@ -14,8 +14,11 @@ goog.module('Blockly.IPositionable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ const {UiMetrics} = goog.requireType('Blockly.MetricsManager'); diff --git a/core/interfaces/i_toolbox.js b/core/interfaces/i_toolbox.js index 5ecd0a69f..0c7e7deb3 100644 --- a/core/interfaces/i_toolbox.js +++ b/core/interfaces/i_toolbox.js @@ -14,10 +14,15 @@ goog.module('Blockly.IToolbox'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IFlyout = goog.requireType('Blockly.IFlyout'); +/* eslint-disable-next-line no-unused-vars */ const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const {ToolboxInfo} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 9504695a2..2dde92d3f 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,15 +13,22 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.blockRendering.Field'); +/* eslint-disable-next-line no-unused-vars */ const Icon = goog.requireType('Blockly.blockRendering.Icon'); +/* eslint-disable-next-line no-unused-vars */ const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); +/* eslint-disable-next-line no-unused-vars */ const RenderInfo = goog.requireType('Blockly.blockRendering.RenderInfo'); +/* eslint-disable-next-line no-unused-vars */ const Row = goog.require('Blockly.blockRendering.Row'); -const svgPaths = goog.require('Blockly.utils.svgPaths'); const Types = goog.require('Blockly.blockRendering.Types'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); /** diff --git a/core/utils/colour.js b/core/utils/colour.js index 7b2c978f4..29ba0187c 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -60,6 +60,7 @@ const parse = function(str) { } return null; }; +exports.parse = parse; /** * Converts a colour from RGB to hex representation. @@ -75,6 +76,7 @@ const rgbToHex = function(r, g, b) { } return '#' + rgb.toString(16); }; +exports.rgbToHex = rgbToHex; /** * Converts a colour to RGB. @@ -95,6 +97,7 @@ const hexToRgb = function(colour) { return [r, g, b]; }; +exports.hexToRgb = hexToRgb; /** * Converts an HSV triplet to hex representation. @@ -153,6 +156,7 @@ const hsvToHex = function(h, s, v) { } return rgbToHex(Math.floor(red), Math.floor(green), Math.floor(blue)); }; +exports.hsvToHex = hsvToHex; /** * Blend two colours together, using the specified factor to indicate the @@ -179,6 +183,7 @@ const blend = function(colour1, colour2, factor) { const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); return rgbToHex(r, g, b); }; +exports.blend = blend; /** * A map that contains the 16 basic colour keywords as defined by W3C: @@ -206,12 +211,4 @@ const names = { 'white': '#ffffff', 'yellow': '#ffff00' }; - -exports = { - parse, - rgbToHex, - hexToRgb, - hsvToHex, - blend, - names -}; +exports.names = names; diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index ad798b1ab..870294172 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -28,7 +28,6 @@ goog.module.declareLegacyNamespace(); * deprecation date. * @param {string=} opt_use The name of a function or property to use instead, * if any. - * @package */ const warn = function(name, deprecationDate, deletionDate, opt_use) { let msg = name + ' was deprecated on ' + deprecationDate + @@ -38,5 +37,5 @@ const warn = function(name, deprecationDate, deletionDate, opt_use) { } console.warn(msg); }; - -exports = {warn}; +/** @package */ +exports.warn = warn; diff --git a/core/utils/idgenerator.js b/core/utils/idgenerator.js index 6ad7bcf55..537dfde2b 100644 --- a/core/utils/idgenerator.js +++ b/core/utils/idgenerator.js @@ -23,7 +23,6 @@ goog.module.declareLegacyNamespace(); /** * Next unique ID to use. * @type {number} - * @private */ let nextId = 0; @@ -36,5 +35,4 @@ let nextId = 0; const getNextUniqueId = function() { return 'blockly-' + (nextId++).toString(36); }; - -exports = {getNextUniqueId}; +exports.getNextUniqueId = getNextUniqueId; diff --git a/core/utils/math.js b/core/utils/math.js index dade91c21..9b717d065 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -29,6 +29,7 @@ goog.module.declareLegacyNamespace(); const toRadians = function(angleDegrees) { return angleDegrees * Math.PI / 180; }; +exports.toRadians = toRadians; /** * Converts radians to degrees. @@ -39,6 +40,7 @@ const toRadians = function(angleDegrees) { const toDegrees = function(angleRadians) { return angleRadians * 180 / Math.PI; }; +exports.toDegrees = toDegrees; /** * Clamp the provided number between the lower bound and the upper bound. @@ -55,9 +57,4 @@ const clamp = function(lowerBound, number, upperBound) { } return Math.max(lowerBound, Math.min(number, upperBound)); }; - -exports = { - toRadians, - toDegrees, - clamp -}; +exports.clamp = clamp; diff --git a/core/utils/object.js b/core/utils/object.js index dae55ec51..3507d33ab 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -40,6 +40,7 @@ const inherits = function(childCtor, parentCtor) { // Alternatively, one could use this instead: // Object.setPrototypeOf(childCtor.prototype, parentCtor.prototype); }; +exports.inherits = inherits; /** * Copies all the members of a source object to a target object. @@ -51,6 +52,7 @@ const mixin = function(target, source) { target[x] = source[x]; } }; +exports.mixin = mixin; /** * Complete a deep merge of all members of a source object with a target object. @@ -68,6 +70,7 @@ const deepMerge = function(target, source) { } return target; }; +exports.deepMerge = deepMerge; /** * Returns an array of a given object's own enumerable property values. @@ -83,10 +86,4 @@ const values = function(obj) { return obj[e]; }); }; - -exports = { - inherits, - mixin, - deepMerge, - values, -}; +exports.values = values; diff --git a/core/utils/style.js b/core/utils/style.js index 1fcfbdd62..0fbd22093 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. */ -function getSize(element) { +const getSize = function(element) { if (getStyle(element, 'display') != 'none') { return getSizeWithDisplay(element); } @@ -52,7 +52,7 @@ function getSize(element) { style.visibility = originalVisibility; return new Size(offsetWidth, offsetHeight); -} +}; exports.getSize = getSize; /** @@ -60,11 +60,11 @@ exports.getSize = getSize; * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. */ -function getSizeWithDisplay(element) { +const getSizeWithDisplay = function(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 @@ -79,10 +79,10 @@ function getSizeWithDisplay(element) { * @param {string} style Property to get (must be camelCase, not CSS-style). * @return {string} Style value. */ -function getStyle(element, style) { +const getStyle = function(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 @@ -96,7 +96,7 @@ function getStyle(element, style) { * @param {string} property Property to get (camel-case). * @return {string} Style value. */ -function getComputedStyle(element, property) { +const getComputedStyle = function(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { const styles = document.defaultView.getComputedStyle(element, null); if (styles) { @@ -107,7 +107,7 @@ function getComputedStyle(element, property) { } return ''; -} +}; exports.getComputedStyle = getComputedStyle; /** @@ -120,10 +120,10 @@ exports.getComputedStyle = getComputedStyle; * @param {string} style Property to get (camel-case). * @return {string} Style value. */ -function getCascadedStyle(element, style) { +const getCascadedStyle = function(element, style) { return /** @type {string} */ ( element.currentStyle ? element.currentStyle[style] : null); -} +}; exports.getCascadedStyle = getCascadedStyle; /** @@ -132,7 +132,7 @@ exports.getCascadedStyle = getCascadedStyle; * @param {!Element} el Element to get the page offset for. * @return {!Coordinate} The page offset. */ -function getPageOffset(el) { +const getPageOffset = function(el) { const pos = new Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; @@ -146,7 +146,7 @@ function getPageOffset(el) { pos.y = box.top + scrollCoord.y; return pos; -} +}; exports.getPageOffset = getPageOffset; /** @@ -154,13 +154,13 @@ exports.getPageOffset = getPageOffset; * Similar to Closure's goog.style.getViewportPageOffset * @return {!Coordinate} The page offset of the viewport. */ -function getViewportPageOffset() { +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 Coordinate(scrollLeft, scrollTop); -} +}; exports.getViewportPageOffset = getViewportPageOffset; /** @@ -175,9 +175,9 @@ exports.getViewportPageOffset = getViewportPageOffset; * @param {*} isShown True to render the element in its default style, * false to disable rendering the element. */ -function setElementShown(el, isShown) { +const setElementShown = function(el, isShown) { el.style.display = isShown ? '' : 'none'; -} +}; exports.setElementShown = setElementShown; /** @@ -187,9 +187,9 @@ exports.setElementShown = setElementShown; * @param {!Element} el The element to test. * @return {boolean} True for right to left, false for left to right. */ -function isRightToLeft(el) { +const isRightToLeft = function(el) { return 'rtl' == getStyle(el, 'direction'); -} +}; exports.isRightToLeft = isRightToLeft; /** @@ -198,7 +198,7 @@ exports.isRightToLeft = isRightToLeft; * @param {!Element} element The element to get the border widths for. * @return {!Object} The computed border widths. */ -function getBorderBox(element) { +const getBorderBox = function(element) { const left = getComputedStyle(element, 'borderLeftWidth'); const right = getComputedStyle(element, 'borderRightWidth'); const top = getComputedStyle(element, 'borderTopWidth'); @@ -210,7 +210,7 @@ function getBorderBox(element) { bottom: parseFloat(bottom), left: parseFloat(left) }; -} +}; exports.getBorderBox = getBorderBox; /** @@ -226,11 +226,11 @@ exports.getBorderBox = getBorderBox; * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -function scrollIntoContainerView(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; -} +}; exports.scrollIntoContainerView = scrollIntoContainerView; /** @@ -248,7 +248,7 @@ exports.scrollIntoContainerView = scrollIntoContainerView; * @return {!Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ -function getContainerOffsetToScrollInto(element, container, opt_center) { +const getContainerOffsetToScrollInto = function(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. @@ -281,5 +281,5 @@ function getContainerOffsetToScrollInto(element, container, opt_center) { scrollTop += Math.min(relY, Math.max(relY - spaceY, 0)); } return new Coordinate(scrollLeft, scrollTop); -} +}; exports.getContainerOffsetToScrollInto = getContainerOffsetToScrollInto; diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index 02602e4ac..7286e8bc6 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -27,11 +27,11 @@ goog.module.declareLegacyNamespace(); * @param {number} x The x coordinate. * @param {number} y The y coordinate. * @return {string} A string of the format ' x,y ' - * @public */ const point = function(x, y) { return ' ' + x + ',' + y + ' '; }; +exports.point = point; /** * Draw a cubic or quadratic curve. See @@ -44,11 +44,11 @@ const point = function(x, y) { * the format ' x, y '. * @return {string} A string defining one or more Bezier curves. See the MDN * documentation for exact format. - * @public */ const curve = function(command, points) { return ' ' + command + points.join(''); }; +exports.curve = curve; /** * Move the cursor to the given position without drawing a line. @@ -58,11 +58,11 @@ const curve = function(command, points) { * @param {number} x The absolute x coordinate. * @param {number} y The absolute y coordinate. * @return {string} A string of the format ' M x,y ' - * @public */ const moveTo = function(x, y) { return ' M ' + x + ',' + y + ' '; }; +exports.moveTo = moveTo; /** * Move the cursor to the given position without drawing a line. @@ -72,11 +72,11 @@ const moveTo = function(x, y) { * @param {number} dx The relative x coordinate. * @param {number} dy The relative y coordinate. * @return {string} A string of the format ' m dx,dy ' - * @public */ const moveBy = function(dx, dy) { return ' m ' + dx + ',' + dy + ' '; }; +exports.moveBy = moveBy; /** * Draw a line from the current point to the end point, which is the current @@ -86,11 +86,11 @@ const moveBy = function(dx, dy) { * @param {number} dx The relative x coordinate. * @param {number} dy The relative y coordinate. * @return {string} A string of the format ' l dx,dy ' - * @public */ const lineTo = function(dx, dy) { return ' l ' + dx + ',' + dy + ' '; }; +exports.lineTo = lineTo; /** * Draw multiple lines connecting all of the given points in order. This is @@ -101,11 +101,11 @@ const lineTo = function(dx, dy) { * draw lines to, in order. The points are represented as strings of the * format ' dx,dy '. * @return {string} A string of the format ' l (dx,dy)+ ' - * @public */ const line = function(points) { return ' l' + points.join(''); }; +exports.line = line; /** * Draw a horizontal or vertical line. @@ -118,11 +118,11 @@ const line = function(points) { * @param {number} val The coordinate to pass to the command. It may be * absolute or relative. * @return {string} A string of the format ' command val ' - * @public */ const lineOnAxis = function(command, val) { return ' ' + command + ' ' + val + ' '; }; +exports.lineOnAxis = lineOnAxis; /** * Draw an elliptical arc curve. @@ -136,19 +136,8 @@ const lineOnAxis = function(command, val) { * specified either in absolute or relative coordinates depending on the * command. * @return {string} A string of the format 'command radius radius flags point' - * @public */ const arc = function(command, flags, radius, point) { return command + ' ' + radius + ' ' + radius + ' ' + flags + point; }; - -exports = { - point, - curve, - moveTo, - moveBy, - lineTo, - line, - lineOnAxis, - arc, -}; +exports.arc = arc; diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index aab51d826..6dabc1fd5 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -18,11 +18,11 @@ goog.module('Blockly.utils.toolbox'); goog.module.declareLegacyNamespace(); const userAgent = goog.require('Blockly.utils.userAgent'); -const {textToDom} = goog.require('Blockly.Xml'); - +/* eslint-disable-next-line no-unused-vars */ const {CssConfig: CategoryCssConfig} = goog.requireType('Blockly.ToolboxCategory'); +/* eslint-disable-next-line no-unused-vars */ const {CssConfig: SeparatorCssConfig} = goog.requireType('Blockly.ToolboxSeparator'); - +const {textToDom} = goog.require('Blockly.Xml'); /** * The information needed to create a block in the toolbox. @@ -35,6 +35,7 @@ const {CssConfig: SeparatorCssConfig} = goog.requireType('Blockly.ToolboxSeparat * }} */ let BlockInfo; +exports.BlockInfo = BlockInfo; /** * The information needed to create a separator in the toolbox. @@ -46,6 +47,7 @@ let BlockInfo; * }} */ let SeparatorInfo; +exports.SeparatorInfo = SeparatorInfo; /** * The information needed to create a button in the toolbox. @@ -56,6 +58,7 @@ let SeparatorInfo; * }} */ let ButtonInfo; +exports.ButtonInfo = ButtonInfo; /** * The information needed to create a label in the toolbox. @@ -66,6 +69,7 @@ let ButtonInfo; * }} */ let LabelInfo; +exports.LabelInfo = LabelInfo; /** * The information needed to create either a button or a label in the flyout. @@ -73,6 +77,7 @@ let LabelInfo; * LabelInfo} */ let ButtonOrLabelInfo; +exports.ButtonOrLabelInfo = ButtonOrLabelInfo; /** * The information needed to create a category in the toolbox. @@ -88,6 +93,7 @@ let ButtonOrLabelInfo; * }} */ let StaticCategoryInfo; +exports.StaticCategoryInfo = StaticCategoryInfo; /** * The information needed to create a custom category. @@ -102,6 +108,7 @@ let StaticCategoryInfo; * }} */ let DynamicCategoryInfo; +exports.DynamicCategoryInfo = DynamicCategoryInfo; /** * The information needed to create either a dynamic or static category. @@ -109,6 +116,7 @@ let DynamicCategoryInfo; * DynamicCategoryInfo} */ let CategoryInfo; +exports.CategoryInfo = CategoryInfo; /** * Any information that can be used to create an item in the toolbox. @@ -116,6 +124,7 @@ let CategoryInfo; * StaticCategoryInfo} */ let ToolboxItemInfo; +exports.ToolboxItemInfo = ToolboxItemInfo; /** * All the different types that can be displayed in a flyout. @@ -126,6 +135,7 @@ let ToolboxItemInfo; * DynamicCategoryInfo} */ let FlyoutItemInfo; +exports.FlyoutItemInfo = FlyoutItemInfo; /** * The JSON definition of a toolbox. @@ -135,6 +145,7 @@ let FlyoutItemInfo; * }} */ let ToolboxInfo; +exports.ToolboxInfo = ToolboxInfo; /** * An array holding flyout items. @@ -143,6 +154,7 @@ let ToolboxInfo; * } */ let FlyoutItemInfoArray; +exports.FlyoutItemInfoArray = FlyoutItemInfoArray; /** * All of the different types that can create a toolbox. @@ -151,6 +163,7 @@ let FlyoutItemInfoArray; * string} */ let ToolboxDefinition; +exports.ToolboxDefinition = ToolboxDefinition; /** * All of the different types that can be used to show items in a flyout. @@ -160,6 +173,7 @@ let ToolboxDefinition; * Array} */ let FlyoutDefinition; +exports.FlyoutDefinition = FlyoutDefinition; /** * The name used to identify a toolbox that has category like items. @@ -187,6 +201,7 @@ const Position = { LEFT: 2, RIGHT: 3 }; +exports.Position = Position; /** * Converts the toolbox definition into toolbox JSON. @@ -194,7 +209,6 @@ const Position = { * of the toolbox in one of its many forms. * @return {?ToolboxInfo} Object holding information * for creating a toolbox. - * @package */ const convertToolboxDefToJson = function(toolboxDef) { if (!toolboxDef) { @@ -210,13 +224,14 @@ const convertToolboxDefToJson = function(toolboxDef) { validateToolbox(toolboxJson); return toolboxJson; }; +/** @package */ +exports.convertToolboxDefToJson = convertToolboxDefToJson; /** * Validates the toolbox JSON fields have been set correctly. * @param {!ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @throws {Error} if the toolbox is not the correct format. - * @private */ const validateToolbox = function(toolboxJson) { const toolboxKind = toolboxJson['kind']; @@ -241,7 +256,6 @@ const validateToolbox = function(toolboxJson) { * @param {?FlyoutDefinition} flyoutDef The definition of * the flyout in one of its many forms. * @return {!FlyoutItemInfoArray} A list of flyout items. - * @package */ const convertFlyoutDefToJsonArray = function(flyoutDef) { if (!flyoutDef) { @@ -260,13 +274,14 @@ const convertFlyoutDefToJsonArray = function(flyoutDef) { return xmlToJsonArray(/** @type {!Array|!NodeList} */ (flyoutDef)); }; +/** @package */ +exports.convertFlyoutDefToJsonArray = convertFlyoutDefToJsonArray; /** * Whether or not the toolbox definition has categories. * @param {?ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @return {boolean} True if the toolbox has categories. - * @package */ const hasCategories = function(toolboxJson) { if (!toolboxJson) { @@ -283,13 +298,14 @@ const hasCategories = function(toolboxJson) { }); return !!categories.length; }; +/** @package */ +exports.hasCategories = hasCategories; /** * Whether or not the category is collapsible. * @param {!CategoryInfo} categoryInfo Object holing * information for creating a category. * @return {boolean} True if the category has subcategories. - * @package */ const isCategoryCollapsible = function(categoryInfo) { if (!categoryInfo || !categoryInfo['contents']) { @@ -301,6 +317,8 @@ const isCategoryCollapsible = function(categoryInfo) { }); return !!categories.length; }; +/** @package */ +exports.isCategoryCollapsible = isCategoryCollapsible; /** * Parses the provided toolbox definition into a consistent format. @@ -308,7 +326,6 @@ const isCategoryCollapsible = function(categoryInfo) { * forms. * @return {!ToolboxInfo} Object holding information * for creating a toolbox. - * @private */ const convertToToolboxJson = function(toolboxDef) { const contents = xmlToJsonArray( @@ -327,7 +344,6 @@ const convertToToolboxJson = function(toolboxDef) { * @return {!FlyoutItemInfoArray| * !Array} A list of objects in * the toolbox. - * @private */ const xmlToJsonArray = function(toolboxDef) { const arr = []; @@ -364,7 +380,6 @@ const xmlToJsonArray = function(toolboxDef) { * Adds the attributes on the node to the given object. * @param {!Node} node The node to copy the attributes from. * @param {!Object} obj The object to copy the attributes to. - * @private */ const addAttributes = function(node, obj) { for (let j = 0; j < node.attributes.length; j++) { @@ -408,26 +423,4 @@ const parseToolboxTree = function(toolboxDef) { } return toolboxDef; }; - -exports = { - BlockInfo, - SeparatorInfo, - ButtonInfo, - LabelInfo, - ButtonOrLabelInfo, - StaticCategoryInfo, - DynamicCategoryInfo, - CategoryInfo, - ToolboxItemInfo, - FlyoutItemInfo, - ToolboxInfo, - FlyoutItemInfoArray, - ToolboxDefinition, - FlyoutDefinition, - Position, - convertToolboxDefToJson, - convertFlyoutDefToJsonArray, - hasCategories, - isCategoryCollapsible, - parseToolboxTree -}; +exports.parseToolboxTree = parseToolboxTree; From 94bdd1850582ef4332c76f3f9c486fba9c48367b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:23:17 -0700 Subject: [PATCH 157/313] Migrate core/field_number.js to ES6 const/let --- core/field_number.js | 10 +++++----- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index 369a161f8..d45c790cd 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -225,14 +225,14 @@ Blockly.FieldNumber.prototype.setPrecision = function(precision) { */ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { this.precision_ = Number(precision) || 0; - var precisionString = String(this.precision_); + let precisionString = String(this.precision_); if (precisionString.indexOf('e') != -1) { // String() is fast. But it turns .0000001 into '1e-7'. // Use the much slower toLocaleString to access all the digits. precisionString = this.precision_.toLocaleString('en-US', {maximumFractionDigits: 20}); } - var decimalIndex = precisionString.indexOf('.'); + const decimalIndex = precisionString.indexOf('.'); if (decimalIndex == -1) { // If the precision is 0 (float) allow any number of decimals, // otherwise allow none. @@ -265,7 +265,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { return null; } // Clean up text. - var newValue = String(opt_newValue); + let newValue = String(opt_newValue); // TODO: Handle cases like 'ten', '1.203,14', etc. // 'O' is sometimes mistaken for '0' by inexperienced users. newValue = newValue.replace(/O/ig, '0'); @@ -275,7 +275,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { newValue = newValue.replace(/infinity/i, 'Infinity'); // Clean up number. - var n = Number(newValue || 0); + let n = Number(newValue || 0); if (isNaN(n)) { // Invalid number. return null; @@ -300,7 +300,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { * @override */ Blockly.FieldNumber.prototype.widgetCreate_ = function() { - var htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); + const htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); // Set the accessibility state if (this.min_ > -Infinity) { diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..5485014dd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -57,7 +57,7 @@ goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockl goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); +goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); From 0a1311c9b5002d8edd568eb24f8e203743b699f2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:26:41 -0700 Subject: [PATCH 158/313] Migrate core/field_number.js to goog.module --- core/field_number.js | 51 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index d45c790cd..67900f344 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldNumber'); +goog.module('Blockly.FieldNumber'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.fieldRegistry'); goog.require('Blockly.FieldTextInput'); @@ -34,7 +35,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.FieldTextInput} * @constructor */ -Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, +const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, opt_validator, opt_config) { /** @@ -66,31 +67,31 @@ Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, */ this.decimalPlaces_ = null; - Blockly.FieldNumber.superClass_.constructor.call( + FieldNumber.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); if (!opt_config) { // Only do one kind of configuration or the other. this.setConstraints(opt_min, opt_max, opt_precision); } }; -Blockly.utils.object.inherits(Blockly.FieldNumber, Blockly.FieldTextInput); +Blockly.utils.object.inherits(FieldNumber, Blockly.FieldTextInput); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldNumber.prototype.DEFAULT_VALUE = 0; +FieldNumber.prototype.DEFAULT_VALUE = 0; /** * Construct a FieldNumber from a JSON arg object. * @param {!Object} options A JSON object with options (value, min, max, and * precision). - * @return {!Blockly.FieldNumber} The new field instance. + * @return {!FieldNumber} The new field instance. * @package * @nocollapse */ -Blockly.FieldNumber.fromJson = function(options) { +FieldNumber.fromJson = function(options) { // `this` might be a subclass of FieldNumber if that class doesn't override // the static fromJson method. return new this(options['value'], @@ -102,7 +103,7 @@ Blockly.FieldNumber.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldNumber.prototype.SERIALIZABLE = true; +FieldNumber.prototype.SERIALIZABLE = true; /** * Configure the field based on the given map of options. @@ -110,8 +111,8 @@ Blockly.FieldNumber.prototype.SERIALIZABLE = true; * @protected * @override */ -Blockly.FieldNumber.prototype.configure_ = function(config) { - Blockly.FieldNumber.superClass_.configure_.call(this, config); +FieldNumber.prototype.configure_ = function(config) { + FieldNumber.superClass_.configure_.call(this, config); this.setMinInternal_(config['min']); this.setMaxInternal_(config['max']); this.setPrecisionInternal_(config['precision']); @@ -128,7 +129,7 @@ Blockly.FieldNumber.prototype.configure_ = function(config) { * @param {?(number|string|undefined)} max Maximum value. * @param {?(number|string|undefined)} precision Precision for value. */ -Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) { +FieldNumber.prototype.setConstraints = function(min, max, precision) { this.setMinInternal_(min); this.setMaxInternal_(max); this.setPrecisionInternal_(precision); @@ -139,7 +140,7 @@ Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) { * Sets the minimum value this field can contain. Updates the value to reflect. * @param {?(number|string|undefined)} min Minimum value. */ -Blockly.FieldNumber.prototype.setMin = function(min) { +FieldNumber.prototype.setMin = function(min) { this.setMinInternal_(min); this.setValue(this.getValue()); }; @@ -150,7 +151,7 @@ Blockly.FieldNumber.prototype.setMin = function(min) { * @param {?(number|string|undefined)} min Minimum value. * @private */ -Blockly.FieldNumber.prototype.setMinInternal_ = function(min) { +FieldNumber.prototype.setMinInternal_ = function(min) { if (min == null) { this.min_ = -Infinity; } else { @@ -166,7 +167,7 @@ Blockly.FieldNumber.prototype.setMinInternal_ = function(min) { * -Infinity. * @return {number} The current minimum value this field can contain. */ -Blockly.FieldNumber.prototype.getMin = function() { +FieldNumber.prototype.getMin = function() { return this.min_; }; @@ -174,7 +175,7 @@ Blockly.FieldNumber.prototype.getMin = function() { * Sets the maximum value this field can contain. Updates the value to reflect. * @param {?(number|string|undefined)} max Maximum value. */ -Blockly.FieldNumber.prototype.setMax = function(max) { +FieldNumber.prototype.setMax = function(max) { this.setMaxInternal_(max); this.setValue(this.getValue()); }; @@ -185,7 +186,7 @@ Blockly.FieldNumber.prototype.setMax = function(max) { * @param {?(number|string|undefined)} max Maximum value. * @private */ -Blockly.FieldNumber.prototype.setMaxInternal_ = function(max) { +FieldNumber.prototype.setMaxInternal_ = function(max) { if (max == null) { this.max_ = Infinity; } else { @@ -201,7 +202,7 @@ Blockly.FieldNumber.prototype.setMaxInternal_ = function(max) { * Infinity. * @return {number} The current maximum value this field can contain. */ -Blockly.FieldNumber.prototype.getMax = function() { +FieldNumber.prototype.getMax = function() { return this.max_; }; @@ -211,7 +212,7 @@ Blockly.FieldNumber.prototype.getMax = function() { * @param {?(number|string|undefined)} precision The number to which the * field's value is rounded. */ -Blockly.FieldNumber.prototype.setPrecision = function(precision) { +FieldNumber.prototype.setPrecision = function(precision) { this.setPrecisionInternal_(precision); this.setValue(this.getValue()); }; @@ -223,7 +224,7 @@ Blockly.FieldNumber.prototype.setPrecision = function(precision) { * field's value is rounded. * @private */ -Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { +FieldNumber.prototype.setPrecisionInternal_ = function(precision) { this.precision_ = Number(precision) || 0; let precisionString = String(this.precision_); if (precisionString.indexOf('e') != -1) { @@ -248,7 +249,7 @@ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { * the value is not rounded. * @return {number} The number to which this field's value is rounded. */ -Blockly.FieldNumber.prototype.getPrecision = function() { +FieldNumber.prototype.getPrecision = function() { return this.precision_; }; @@ -260,7 +261,7 @@ Blockly.FieldNumber.prototype.getPrecision = function() { * @protected * @override */ -Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { +FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null) { return null; } @@ -299,8 +300,8 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { * @protected * @override */ -Blockly.FieldNumber.prototype.widgetCreate_ = function() { - const htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); +FieldNumber.prototype.widgetCreate_ = function() { + const htmlInput = FieldNumber.superClass_.widgetCreate_.call(this); // Set the accessibility state if (this.min_ > -Infinity) { @@ -314,4 +315,6 @@ Blockly.FieldNumber.prototype.widgetCreate_ = function() { return htmlInput; }; -Blockly.fieldRegistry.register('field_number', Blockly.FieldNumber); +Blockly.fieldRegistry.register('field_number', FieldNumber); + +exports = FieldNumber; diff --git a/tests/deps.js b/tests/deps.js index 5485014dd..80ddf87c8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -57,7 +57,7 @@ goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockl goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6'}); +goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); From 25fc34925f194c3c703cb9b4c7945e34950f1b34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:31:39 -0700 Subject: [PATCH 159/313] Migrate core/field_number.js to named requires --- core/field_number.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index 67900f344..e8d628572 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -13,10 +13,10 @@ goog.module('Blockly.FieldNumber'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.object'); +const FieldTextInput = goog.require('Blockly.FieldTextInput'); +const aria = goog.require('Blockly.utils.aria'); +const {inherits} = goog.require('Blockly.utils.object'); +const {register} = goog.require('Blockly.fieldRegistry'); /** @@ -32,7 +32,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldTextInput} + * @extends {FieldTextInput} * @constructor */ const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, @@ -74,7 +74,7 @@ const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, this.setConstraints(opt_min, opt_max, opt_precision); } }; -Blockly.utils.object.inherits(FieldNumber, Blockly.FieldTextInput); +inherits(FieldNumber, FieldTextInput); /** * The default value for this field. @@ -305,16 +305,16 @@ FieldNumber.prototype.widgetCreate_ = function() { // Set the accessibility state if (this.min_ > -Infinity) { - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.VALUEMIN, this.min_); + aria.setState(htmlInput, + aria.State.VALUEMIN, this.min_); } if (this.max_ < Infinity) { - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.VALUEMAX, this.max_); + aria.setState(htmlInput, + aria.State.VALUEMAX, this.max_); } return htmlInput; }; -Blockly.fieldRegistry.register('field_number', FieldNumber); +register('field_number', FieldNumber); exports = FieldNumber; From e15470bbd0f7ca74e0452dba8606fe2344e1539b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:32:09 -0700 Subject: [PATCH 160/313] clang-format core/field_number.js --- core/field_number.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index e8d628572..8389f477f 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -30,14 +30,14 @@ const {register} = goog.require('Blockly.fieldRegistry'); * changes to the field's value. Takes in a number & returns a validated * number, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} * for a list of properties this parameter supports. * @extends {FieldTextInput} * @constructor */ -const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, - opt_validator, opt_config) { - +const FieldNumber = function( + opt_value, opt_min, opt_max, opt_precision, opt_validator, opt_config) { /** * The minimum value this number field can contain. * @type {number} @@ -94,8 +94,8 @@ FieldNumber.prototype.DEFAULT_VALUE = 0; FieldNumber.fromJson = function(options) { // `this` might be a subclass of FieldNumber if that class doesn't override // the static fromJson method. - return new this(options['value'], - undefined, undefined, undefined, undefined, options); + return new this( + options['value'], undefined, undefined, undefined, undefined, options); }; /** @@ -305,12 +305,10 @@ FieldNumber.prototype.widgetCreate_ = function() { // Set the accessibility state if (this.min_ > -Infinity) { - aria.setState(htmlInput, - aria.State.VALUEMIN, this.min_); + aria.setState(htmlInput, aria.State.VALUEMIN, this.min_); } if (this.max_ < Infinity) { - aria.setState(htmlInput, - aria.State.VALUEMAX, this.max_); + aria.setState(htmlInput, aria.State.VALUEMAX, this.max_); } return htmlInput; }; From 7a050d021db8d56f2c64a139678c7659ff739e23 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:43:46 -0700 Subject: [PATCH 161/313] Migrate core/field_checkbox.js to goog.module --- core/field_checkbox.js | 55 ++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 207b29f7f..df3509239 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldCheckbox'); +goog.module('Blockly.FieldCheckbox'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); @@ -34,7 +35,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldCheckbox = function(opt_value, opt_validator, opt_config) { +const FieldCheckbox = function(opt_value, opt_validator, opt_config) { /** * Character for the check mark. Used to apply a different check mark * character to individual fields. @@ -43,26 +44,26 @@ Blockly.FieldCheckbox = function(opt_value, opt_validator, opt_config) { */ this.checkChar_ = null; - Blockly.FieldCheckbox.superClass_.constructor.call( + FieldCheckbox.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); }; -Blockly.utils.object.inherits(Blockly.FieldCheckbox, Blockly.Field); +Blockly.utils.object.inherits(FieldCheckbox, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldCheckbox.prototype.DEFAULT_VALUE = false; +FieldCheckbox.prototype.DEFAULT_VALUE = false; /** * Construct a FieldCheckbox from a JSON arg object. * @param {!Object} options A JSON object with options (checked). - * @return {!Blockly.FieldCheckbox} The new field instance. + * @return {!FieldCheckbox} The new field instance. * @package * @nocollapse */ -Blockly.FieldCheckbox.fromJson = function(options) { +FieldCheckbox.fromJson = function(options) { // `this` might be a subclass of FieldCheckbox if that class doesn't override // the static fromJson method. return new this(options['checked'], undefined, options); @@ -73,19 +74,19 @@ Blockly.FieldCheckbox.fromJson = function(options) { * @type {string} * @const */ -Blockly.FieldCheckbox.CHECK_CHAR = '\u2713'; +FieldCheckbox.CHECK_CHAR = '\u2713'; /** * Serializable fields are saved by the XML renderer, non-serializable fields * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldCheckbox.prototype.SERIALIZABLE = true; +FieldCheckbox.prototype.SERIALIZABLE = true; /** * Mouse cursor style when over the hotspot that initiates editability. */ -Blockly.FieldCheckbox.prototype.CURSOR = 'default'; +FieldCheckbox.prototype.CURSOR = 'default'; /** * Configure the field based on the given map of options. @@ -93,8 +94,8 @@ Blockly.FieldCheckbox.prototype.CURSOR = 'default'; * @protected * @override */ -Blockly.FieldCheckbox.prototype.configure_ = function(config) { - Blockly.FieldCheckbox.superClass_.configure_.call(this, config); +FieldCheckbox.prototype.configure_ = function(config) { + FieldCheckbox.superClass_.configure_.call(this, config); if (config['checkCharacter']) { this.checkChar_ = config['checkCharacter']; } @@ -104,8 +105,8 @@ Blockly.FieldCheckbox.prototype.configure_ = function(config) { * Create the block UI for this checkbox. * @package */ -Blockly.FieldCheckbox.prototype.initView = function() { - Blockly.FieldCheckbox.superClass_.initView.call(this); +FieldCheckbox.prototype.initView = function() { + FieldCheckbox.superClass_.initView.call(this); Blockly.utils.dom.addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); @@ -115,7 +116,7 @@ Blockly.FieldCheckbox.prototype.initView = function() { /** * @override */ -Blockly.FieldCheckbox.prototype.render_ = function() { +FieldCheckbox.prototype.render_ = function() { if (this.textContent_) { this.textContent_.nodeValue = this.getDisplayText_(); } @@ -125,8 +126,8 @@ Blockly.FieldCheckbox.prototype.render_ = function() { /** * @override */ -Blockly.FieldCheckbox.prototype.getDisplayText_ = function() { - return this.checkChar_ || Blockly.FieldCheckbox.CHECK_CHAR; +FieldCheckbox.prototype.getDisplayText_ = function() { + return this.checkChar_ || FieldCheckbox.CHECK_CHAR; }; /** @@ -134,7 +135,7 @@ Blockly.FieldCheckbox.prototype.getDisplayText_ = function() { * @param {?string} character The character to use for the check mark, or * null to use the default. */ -Blockly.FieldCheckbox.prototype.setCheckCharacter = function(character) { +FieldCheckbox.prototype.setCheckCharacter = function(character) { this.checkChar_ = character; this.forceRerender(); }; @@ -143,7 +144,7 @@ Blockly.FieldCheckbox.prototype.setCheckCharacter = function(character) { * Toggle the state of the checkbox on click. * @protected */ -Blockly.FieldCheckbox.prototype.showEditor_ = function() { +FieldCheckbox.prototype.showEditor_ = function() { this.setValue(!this.value_); }; @@ -153,7 +154,7 @@ Blockly.FieldCheckbox.prototype.showEditor_ = function() { * @return {?string} A valid value ('TRUE' or 'FALSE), or null if invalid. * @protected */ -Blockly.FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { +FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === true || opt_newValue === 'TRUE') { return 'TRUE'; } @@ -169,7 +170,7 @@ Blockly.FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { * that this is a either 'TRUE' or 'FALSE'. * @protected */ -Blockly.FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { +FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { this.value_ = this.convertValueToBool_(newValue); // Update visual. if (this.textElement_) { @@ -181,7 +182,7 @@ Blockly.FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { * Get the value of this field, either 'TRUE' or 'FALSE'. * @return {string} The value of this field. */ -Blockly.FieldCheckbox.prototype.getValue = function() { +FieldCheckbox.prototype.getValue = function() { return this.value_ ? 'TRUE' : 'FALSE'; }; @@ -189,7 +190,7 @@ Blockly.FieldCheckbox.prototype.getValue = function() { * Get the boolean value of this field. * @return {boolean} The boolean value of this field. */ -Blockly.FieldCheckbox.prototype.getValueBoolean = function() { +FieldCheckbox.prototype.getValueBoolean = function() { return /** @type {boolean} */ (this.value_); }; @@ -198,7 +199,7 @@ Blockly.FieldCheckbox.prototype.getValueBoolean = function() { * @return {string} Text representing the value of this field * ('true' or 'false'). */ -Blockly.FieldCheckbox.prototype.getText = function() { +FieldCheckbox.prototype.getText = function() { return String(this.convertValueToBool_(this.value_)); }; @@ -211,7 +212,7 @@ Blockly.FieldCheckbox.prototype.getText = function() { * @return {boolean} The converted value. * @private */ -Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) { +FieldCheckbox.prototype.convertValueToBool_ = function(value) { if (typeof value == 'string') { return value == 'TRUE'; } else { @@ -219,4 +220,6 @@ Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -Blockly.fieldRegistry.register('field_checkbox', Blockly.FieldCheckbox); +Blockly.fieldRegistry.register('field_checkbox', FieldCheckbox); + +exports = FieldCheckbox; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..d6e6163f8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -50,7 +50,7 @@ goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.Co goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); From 29135ec920d974b1eb170b44f59b19a6194de19d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:47:44 -0700 Subject: [PATCH 162/313] Migrate core/field_checkbox.js to named requires --- core/field_checkbox.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index df3509239..9100aa8d3 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -13,12 +13,12 @@ goog.module('Blockly.FieldCheckbox'); goog.module.declareLegacyNamespace(); +const Field = goog.require('Blockly.Field'); +const {addClass} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {register} = goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); /** @@ -32,7 +32,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldCheckbox = function(opt_value, opt_validator, opt_config) { @@ -47,7 +47,7 @@ const FieldCheckbox = function(opt_value, opt_validator, opt_config) { FieldCheckbox.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); }; -Blockly.utils.object.inherits(FieldCheckbox, Blockly.Field); +inherits(FieldCheckbox, Field); /** * The default value for this field. @@ -108,7 +108,7 @@ FieldCheckbox.prototype.configure_ = function(config) { FieldCheckbox.prototype.initView = function() { FieldCheckbox.superClass_.initView.call(this); - Blockly.utils.dom.addClass( + addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); this.textElement_.style.display = this.value_ ? 'block' : 'none'; }; @@ -220,6 +220,6 @@ FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -Blockly.fieldRegistry.register('field_checkbox', FieldCheckbox); +register('field_checkbox', FieldCheckbox); exports = FieldCheckbox; From 5bc41ac960588334e0af831754f58a92ae264ab4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:48:43 -0700 Subject: [PATCH 163/313] clang-format core/field_checkbox.js --- core/field_checkbox.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 9100aa8d3..3cbe8d07f 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -30,7 +30,8 @@ goog.require('Blockly.Events.BlockChange'); * returns a validated value ('TRUE' or 'FALSE'), or null to abort the * change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor From 9d6cbe96d3df420984b23f2fb02ea57722691962 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:45:30 -0700 Subject: [PATCH 164/313] Migrate core/keyboard_nav/tab_navigate_cursor.js to ES6 const/let --- core/keyboard_nav/tab_navigate_cursor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 7d43a79f8..b339520c0 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -37,10 +37,10 @@ Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); * @override */ Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { - var isValid = false; - var type = node && node.getType(); + let isValid = false; + const type = node && node.getType(); if (node) { - var location = /** @type {Blockly.Field} */ (node.getLocation()); + const location = /** @type {Blockly.Field} */ (node.getLocation()); if (type == Blockly.ASTNode.types.FIELD && location && location.isTabNavigable() && location.isClickable()) { isValid = true; From f282c573239970143e4d92eb6933cff82086e914 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:45:55 -0700 Subject: [PATCH 165/313] Migrate core/keyboard_nav/tab_navigate_cursor.js to goog.module --- core/keyboard_nav/tab_navigate_cursor.js | 13 ++++++++----- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index b339520c0..ad2bb45ba 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.TabNavigateCursor'); +goog.module('Blockly.TabNavigateCursor'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); goog.require('Blockly.BasicCursor'); @@ -25,10 +26,10 @@ goog.requireType('Blockly.Field'); * @constructor * @extends {Blockly.BasicCursor} */ -Blockly.TabNavigateCursor = function() { - Blockly.TabNavigateCursor.superClass_.constructor.call(this); +const TabNavigateCursor = function() { + TabNavigateCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); +Blockly.utils.object.inherits(TabNavigateCursor, Blockly.BasicCursor); /** * Skip all nodes except for tab navigable fields. @@ -36,7 +37,7 @@ Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); * @return {boolean} True if the node should be visited, false otherwise. * @override */ -Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { +TabNavigateCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); if (node) { @@ -48,3 +49,5 @@ Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { } return isValid; }; + +exports = TabNavigateCursor; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..0c03cecf3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -105,7 +105,7 @@ goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], [ goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); From 9a6a92bf52d748bd36c82250e9c023a0084e550e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:47:25 -0700 Subject: [PATCH 166/313] Migrate core/keyboard_nav/tab_navigate_cursor.js named requires --- core/keyboard_nav/tab_navigate_cursor.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index ad2bb45ba..37f90fe37 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -14,26 +14,25 @@ goog.module('Blockly.TabNavigateCursor'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); -goog.require('Blockly.BasicCursor'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Field'); +const ASTNode = goog.require('Blockly.ASTNode'); +const BasicCursor = goog.require('Blockly.BasicCursor'); +const Field = goog.requireType('Blockly.Field'); +const {inherits} = goog.require('Blockly.utils.object'); /** * A cursor for navigating between tab navigable fields. * @constructor - * @extends {Blockly.BasicCursor} + * @extends {BasicCursor} */ const TabNavigateCursor = function() { TabNavigateCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(TabNavigateCursor, Blockly.BasicCursor); +inherits(TabNavigateCursor, BasicCursor); /** * Skip all nodes except for tab navigable fields. - * @param {Blockly.ASTNode} node The AST node to check whether it is valid. + * @param {?ASTNode} node The AST node to check whether it is valid. * @return {boolean} True if the node should be visited, false otherwise. * @override */ @@ -41,8 +40,8 @@ TabNavigateCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); if (node) { - const location = /** @type {Blockly.Field} */ (node.getLocation()); - if (type == Blockly.ASTNode.types.FIELD && + const location = /** @type {Field} */ (node.getLocation()); + if (type == ASTNode.types.FIELD && location && location.isTabNavigable() && location.isClickable()) { isValid = true; } From ecec6daf80e9b7910393e371223b3824855f180b Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:47:41 -0700 Subject: [PATCH 167/313] clang-format core/keyboard_nav/tab_navigate_cursor.js --- core/keyboard_nav/tab_navigate_cursor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 37f90fe37..3b82267a1 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -41,8 +41,8 @@ TabNavigateCursor.prototype.validNode_ = function(node) { const type = node && node.getType(); if (node) { const location = /** @type {Field} */ (node.getLocation()); - if (type == ASTNode.types.FIELD && - location && location.isTabNavigable() && location.isClickable()) { + if (type == ASTNode.types.FIELD && location && location.isTabNavigable() && + location.isClickable()) { isValid = true; } } From b2a68532d2870fe75ce0198c1c66913ca32391ba Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 10:48:56 -0700 Subject: [PATCH 168/313] Migrate core/delete_area.js to ES6 const/let --- core/delete_area.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/delete_area.js b/core/delete_area.js index 384136a05..8a9f4ec6d 100644 --- a/core/delete_area.js +++ b/core/delete_area.js @@ -55,8 +55,8 @@ Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget); */ Blockly.DeleteArea.prototype.wouldDelete = function(element, couldConnect) { if (element instanceof Blockly.BlockSvg) { - var block = /** @type {Blockly.BlockSvg} */ (element); - var couldDeleteBlock = !block.getParent() && block.isDeletable(); + const block = /** @type {Blockly.BlockSvg} */ (element); + const couldDeleteBlock = !block.getParent() && block.isDeletable(); this.updateWouldDelete_(couldDeleteBlock && !couldConnect); } else { this.updateWouldDelete_(element.isDeletable()); From 7219b83093311b52366226142cc6f5d9866e1033 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 10:52:35 -0700 Subject: [PATCH 169/313] Migrate core/delete_area.js to goog.module --- core/delete_area.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/delete_area.js b/core/delete_area.js index 8a9f4ec6d..64605dee0 100644 --- a/core/delete_area.js +++ b/core/delete_area.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.DeleteArea'); +goog.module('Blockly.DeleteArea'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.BlockSvg'); goog.require('Blockly.DragTarget'); @@ -27,8 +28,8 @@ goog.requireType('Blockly.IDraggable'); * @implements {Blockly.IDeleteArea} * @constructor */ -Blockly.DeleteArea = function() { - Blockly.DeleteArea.superClass_.constructor.call(this); +const DeleteArea = function() { + DeleteArea.superClass_.constructor.call(this); /** * Whether the last block or bubble dragged over this delete area would be @@ -39,7 +40,7 @@ Blockly.DeleteArea = function() { */ this.wouldDelete_ = false; }; -Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget); +Blockly.utils.object.inherits(DeleteArea, Blockly.DragTarget); /** * Returns whether the provided block or bubble would be deleted if dropped on @@ -53,7 +54,7 @@ Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget); * @return {boolean} Whether the element provided would be deleted if dropped on * this area. */ -Blockly.DeleteArea.prototype.wouldDelete = function(element, couldConnect) { +DeleteArea.prototype.wouldDelete = function(element, couldConnect) { if (element instanceof Blockly.BlockSvg) { const block = /** @type {Blockly.BlockSvg} */ (element); const couldDeleteBlock = !block.getParent() && block.isDeletable(); @@ -69,6 +70,8 @@ Blockly.DeleteArea.prototype.wouldDelete = function(element, couldConnect) { * @param {boolean} wouldDelete The new value for the wouldDelete state. * @protected */ -Blockly.DeleteArea.prototype.updateWouldDelete_ = function(wouldDelete) { +DeleteArea.prototype.updateWouldDelete_ = function(wouldDelete) { this.wouldDelete_ = wouldDelete; }; + +exports = DeleteArea; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..3486a6137 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -28,7 +28,7 @@ goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Block goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); +goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); From ff34d8c37e414c5c029db760920760b5e4e8db88 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 10:57:20 -0700 Subject: [PATCH 170/313] Migrate core/delete_area.js to named requires --- core/delete_area.js | 24 +++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/delete_area.js b/core/delete_area.js index 64605dee0..55eb61a34 100644 --- a/core/delete_area.js +++ b/core/delete_area.js @@ -15,17 +15,19 @@ goog.module('Blockly.DeleteArea'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.BlockSvg'); -goog.require('Blockly.DragTarget'); -goog.require('Blockly.IDeleteArea'); - -goog.requireType('Blockly.IDraggable'); +const BlockSvg = goog.require('Blockly.BlockSvg'); +const DragTarget = goog.require('Blockly.DragTarget'); +/* eslint-disable-next-line no-unused-vars */ +const IDeleteArea = goog.require('Blockly.IDeleteArea'); +/* eslint-disable-next-line no-unused-vars */ +const IDraggable = goog.requireType('Blockly.IDraggable'); +const {inherits} = goog.require('Blockly.utils.object'); /** * Abstract class for a component that can delete a block or bubble that is * dropped on top of it. - * @extends {Blockly.DragTarget} - * @implements {Blockly.IDeleteArea} + * @extends {DragTarget} + * @implements {IDeleteArea} * @constructor */ const DeleteArea = function() { @@ -40,14 +42,14 @@ const DeleteArea = function() { */ this.wouldDelete_ = false; }; -Blockly.utils.object.inherits(DeleteArea, Blockly.DragTarget); +inherits(DeleteArea, DragTarget); /** * Returns whether the provided block or bubble would be deleted if dropped on * this area. * This method should check if the element is deletable and is always called * before onDragEnter/onDragOver/onDragExit. - * @param {!Blockly.IDraggable} element The block or bubble currently being + * @param {!IDraggable} element The block or bubble currently being * dragged. * @param {boolean} couldConnect Whether the element could could connect to * another. @@ -55,8 +57,8 @@ Blockly.utils.object.inherits(DeleteArea, Blockly.DragTarget); * this area. */ DeleteArea.prototype.wouldDelete = function(element, couldConnect) { - if (element instanceof Blockly.BlockSvg) { - const block = /** @type {Blockly.BlockSvg} */ (element); + if (element instanceof BlockSvg) { + const block = /** @type {BlockSvg} */ (element); const couldDeleteBlock = !block.getParent() && block.isDeletable(); this.updateWouldDelete_(couldDeleteBlock && !couldConnect); } else { diff --git a/tests/deps.js b/tests/deps.js index 3486a6137..aabe7c944 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -28,7 +28,7 @@ goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Block goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); From 0dc01b16188564b949b90512133d59c4eabb7c40 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:02:32 -0700 Subject: [PATCH 171/313] Migrate core/drag_target.js to goog.module --- core/drag_target.js | 19 +++++++++++-------- tests/deps.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/drag_target.js b/core/drag_target.js index 438bf6a31..91d46c5ca 100644 --- a/core/drag_target.js +++ b/core/drag_target.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.DragTarget'); +goog.module('Blockly.DragTarget'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IDragTarget'); @@ -26,7 +27,7 @@ goog.requireType('Blockly.utils.Rect'); * @implements {Blockly.IDragTarget} * @constructor */ -Blockly.DragTarget = function() {}; +const DragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units @@ -34,14 +35,14 @@ Blockly.DragTarget = function() {}; * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.DragTarget.prototype.getClientRect; +DragTarget.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.DragTarget.prototype.onDragEnter = function(_dragElement) { +DragTarget.prototype.onDragEnter = function(_dragElement) { // no-op }; @@ -51,7 +52,7 @@ Blockly.DragTarget.prototype.onDragEnter = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDragOver = function(_dragElement) { +DragTarget.prototype.onDragOver = function(_dragElement) { // no-op }; @@ -60,7 +61,7 @@ Blockly.DragTarget.prototype.onDragOver = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDragExit = function(_dragElement) { +DragTarget.prototype.onDragExit = function(_dragElement) { // no-op }; @@ -70,7 +71,7 @@ Blockly.DragTarget.prototype.onDragExit = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDrop = function(_dragElement) { +DragTarget.prototype.onDrop = function(_dragElement) { // no-op }; @@ -83,6 +84,8 @@ Blockly.DragTarget.prototype.onDrop = function(_dragElement) { * @return {boolean} Whether the block or bubble provided should be returned to * drag start. */ -Blockly.DragTarget.prototype.shouldPreventMove = function(_dragElement) { +DragTarget.prototype.shouldPreventMove = function(_dragElement) { return false; }; + +exports = DragTarget; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..74b561fe4 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); From b1b5358b678041ac0603fc59f93c4829e0554735 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:06:53 -0700 Subject: [PATCH 172/313] Migrate core/drag_target.js to named requires --- core/drag_target.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/drag_target.js b/core/drag_target.js index 91d46c5ca..18e29b40a 100644 --- a/core/drag_target.js +++ b/core/drag_target.js @@ -15,16 +15,18 @@ goog.module('Blockly.DragTarget'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IDragTarget'); - -goog.requireType('Blockly.IDraggable'); -goog.requireType('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ +const IDragTarget = goog.require('Blockly.IDragTarget'); +/* eslint-disable-next-line no-unused-vars */ +const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ +const Rect = goog.requireType('Blockly.utils.Rect'); /** * Abstract class for a component with custom behaviour when a block or bubble * is dragged over or dropped on top of it. - * @implements {Blockly.IDragTarget} + * @implements {IDragTarget} * @constructor */ const DragTarget = function() {}; @@ -32,14 +34,14 @@ const DragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units * relative to the Blockly injection div. - * @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. */ DragTarget.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. */ DragTarget.prototype.onDragEnter = function(_dragElement) { @@ -49,7 +51,7 @@ DragTarget.prototype.onDragEnter = function(_dragElement) { /** * 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. */ DragTarget.prototype.onDragOver = function(_dragElement) { @@ -58,7 +60,7 @@ DragTarget.prototype.onDragOver = function(_dragElement) { /** * 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. */ DragTarget.prototype.onDragExit = function(_dragElement) { @@ -68,7 +70,7 @@ DragTarget.prototype.onDragExit = function(_dragElement) { /** * 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. */ DragTarget.prototype.onDrop = function(_dragElement) { @@ -79,7 +81,7 @@ DragTarget.prototype.onDrop = function(_dragElement) { * 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 a57399704f5be6af807040bc12190f8e00f576f0 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:15:25 -0700 Subject: [PATCH 173/313] Migrate core/field.js to ES6 const/let --- core/field.js | 79 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/core/field.js b/core/field.js index f5f027c45..ed15cd494 100644 --- a/core/field.js +++ b/core/field.js @@ -267,7 +267,7 @@ Blockly.Field.prototype.SERIALIZABLE = false; * @protected */ Blockly.Field.prototype.configure_ = function(config) { - var tooltip = config['tooltip']; + let tooltip = config['tooltip']; if (typeof tooltip == 'string') { tooltip = Blockly.utils.replaceMessageReferences( config['tooltip']); @@ -325,7 +325,7 @@ Blockly.Field.prototype.init = function() { if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } - var sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); + const sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); sourceBlockSvg.getSvgRoot().appendChild(this.fieldGroup_); this.initView(); this.updateEditable(); @@ -444,7 +444,7 @@ Blockly.Field.prototype.dispose = function() { * Add or remove the UI indicating if this field is editable or not. */ Blockly.Field.prototype.updateEditable = function() { - var group = this.fieldGroup_; + const group = this.fieldGroup_; if (!this.EDITABLE || !group) { return; } @@ -506,7 +506,7 @@ Blockly.Field.prototype.isCurrentlyEditable = function() { * @return {boolean} Whether this field should be serialized or not. */ Blockly.Field.prototype.isSerializable = function() { - var isSerializable = false; + let isSerializable = false; if (this.name) { if (this.SERIALIZABLE) { isSerializable = true; @@ -539,7 +539,7 @@ Blockly.Field.prototype.setVisible = function(visible) { return; } this.visible_ = visible; - var root = this.getSvgRoot(); + const root = this.getSvgRoot(); if (root) { root.style.display = visible ? 'block' : 'none'; } @@ -622,13 +622,13 @@ Blockly.Field.prototype.showEditor = function(opt_e) { * @protected */ Blockly.Field.prototype.updateSize_ = function(opt_margin) { - var constants = this.getConstants(); - var xOffset = opt_margin != undefined ? opt_margin : + const constants = this.getConstants(); + const xOffset = opt_margin != undefined ? opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); - var totalWidth = xOffset * 2; - var totalHeight = constants.FIELD_TEXT_HEIGHT; + let totalWidth = xOffset * 2; + let totalHeight = constants.FIELD_TEXT_HEIGHT; - var contentWidth = 0; + let contentWidth = 0; if (this.textElement_) { contentWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, constants.FIELD_TEXT_FONTSIZE, @@ -658,8 +658,8 @@ Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { if (!this.textElement_) { return; } - var constants = this.getConstants(); - var halfHeight = this.size_.height / 2; + const constants = this.getConstants(); + const halfHeight = this.size_.height / 2; this.textElement_.setAttribute('x', this.sourceBlock_.RTL ? this.size_.width - contentWidth - xOffset : xOffset); @@ -717,15 +717,16 @@ Blockly.Field.prototype.getSize = function() { * @package */ Blockly.Field.prototype.getScaledBBox = function() { + let scaledWidth, scaledHeight, xy; if (!this.borderRect_) { // Browsers are inconsistent in what they return for a bounding box. // - Webkit / Blink: fill-box / object bounding box // - Gecko / Triden / EdgeHTML: stroke-box - var bBox = this.sourceBlock_.getHeightWidth(); - var scale = this.sourceBlock_.workspace.scale; - var xy = this.getAbsoluteXY_(); - var scaledWidth = bBox.width * scale; - var scaledHeight = bBox.height * scale; + const bBox = this.sourceBlock_.getHeightWidth(); + const scale = this.sourceBlock_.workspace.scale; + xy = this.getAbsoluteXY_(); + scaledWidth = bBox.width * scale; + scaledHeight = bBox.height * scale; if (Blockly.utils.userAgent.GECKO) { xy.x += 1.5 * scale; @@ -741,10 +742,10 @@ Blockly.Field.prototype.getScaledBBox = function() { scaledHeight += 1 * scale; } } else { - var bBox = this.borderRect_.getBoundingClientRect(); - var xy = Blockly.utils.style.getPageOffset(this.borderRect_); - var scaledWidth = bBox.width; - var scaledHeight = bBox.height; + const bBox = this.borderRect_.getBoundingClientRect(); + xy = Blockly.utils.style.getPageOffset(this.borderRect_); + scaledWidth = bBox.width; + scaledHeight = bBox.height; } return new Blockly.utils.Rect( xy.y, @@ -761,7 +762,7 @@ Blockly.Field.prototype.getScaledBBox = function() { * @protected */ Blockly.Field.prototype.getDisplayText_ = function() { - var text = this.getText(); + let text = this.getText(); if (!text) { // Prevent the field from disappearing if empty. return Blockly.Field.NBSP; @@ -785,7 +786,7 @@ Blockly.Field.prototype.getDisplayText_ = function() { */ Blockly.Field.prototype.getText = function() { if (this.getText_) { - var text = this.getText_.call(this); + const text = this.getText_.call(this); if (text !== null) { return String(text); } @@ -828,14 +829,14 @@ Blockly.Field.prototype.forceRerender = function() { * @param {*} newValue New value. */ Blockly.Field.prototype.setValue = function(newValue) { - var doLogging = false; + const doLogging = false; if (newValue === null) { doLogging && console.log('null, return'); // Not a valid value to check. return; } - var validatedValue = this.doClassValidation_(newValue); + let validatedValue = this.doClassValidation_(newValue); // Class validators might accidentally forget to return, we'll ignore that. newValue = this.processValidation_(newValue, validatedValue); if (newValue instanceof Error) { @@ -843,7 +844,7 @@ Blockly.Field.prototype.setValue = function(newValue) { return; } - var localValidator = this.getValidator(); + const localValidator = this.getValidator(); if (localValidator) { validatedValue = localValidator.call(this, newValue); // Local validators might accidentally forget to return, we'll ignore that. @@ -853,12 +854,12 @@ Blockly.Field.prototype.setValue = function(newValue) { return; } } - var source = this.sourceBlock_; + const source = this.sourceBlock_; if (source && source.disposed) { doLogging && console.log('source disposed, return'); return; } - var oldValue = this.getValue(); + const oldValue = this.getValue(); if (oldValue === newValue) { doLogging && console.log('same, doValueUpdate_, return'); this.doValueUpdate_(newValue); @@ -951,7 +952,7 @@ Blockly.Field.prototype.onMouseDown_ = function(e) { if (!this.sourceBlock_ || !this.sourceBlock_.workspace) { return; } - var gesture = this.sourceBlock_.workspace.getGesture(e); + const gesture = this.sourceBlock_.workspace.getGesture(e); if (gesture) { gesture.setStartField(this); } @@ -968,7 +969,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { if (!newTip && newTip !== '') { // If null or undefined. newTip = this.sourceBlock_; } - var clickTarget = this.getClickTarget_(); + const clickTarget = this.getClickTarget_(); if (clickTarget) { clickTarget.tooltip = newTip; } else { @@ -982,7 +983,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { * @return {string} The tooltip text for this field. */ Blockly.Field.prototype.getTooltip = function() { - var clickTarget = this.getClickTarget_(); + const clickTarget = this.getClickTarget_(); if (clickTarget) { return Blockly.Tooltip.getTooltipOfObject(clickTarget); } @@ -1030,14 +1031,14 @@ Blockly.Field.prototype.referencesVariables = function() { * @package */ Blockly.Field.prototype.getParentInput = function() { - var parentInput = null; - var block = this.sourceBlock_; - var inputs = block.inputList; + let parentInput = null; + const block = this.sourceBlock_; + const inputs = block.inputList; - for (var idx = 0; idx < block.inputList.length; idx++) { - var input = inputs[idx]; - var fieldRows = input.fieldRow; - for (var j = 0; j < fieldRows.length; j++) { + for (let idx = 0; idx < block.inputList.length; idx++) { + const input = inputs[idx]; + const fieldRows = input.fieldRow; + for (let j = 0; j < fieldRows.length; j++) { if (fieldRows[j] === this) { parentInput = input; break; @@ -1110,7 +1111,7 @@ Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { * @protected */ Blockly.Field.prototype.updateMarkers_ = function() { - var workspace = + const workspace = /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); From 91721f7d163092940d6cb8941889d8a6045acee2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:18:41 -0700 Subject: [PATCH 174/313] Migrate core/field.js to goog.module --- core/field.js | 151 +++++++++++++++++++++++++------------------------- tests/deps.js | 2 +- 2 files changed, 78 insertions(+), 75 deletions(-) diff --git a/core/field.js b/core/field.js index ed15cd494..d9db11cbd 100644 --- a/core/field.js +++ b/core/field.js @@ -7,12 +7,13 @@ /** * @fileoverview Field. Used for editable titles, variables, etc. * This is an abstract class that defines the UI on the block. Actual - * instances would be Blockly.FieldTextInput, Blockly.FieldDropdown, etc. + * instances would be FieldTextInput, FieldDropdown, etc. * @author fraser@google.com (Neil Fraser) */ 'use strict'; -goog.provide('Blockly.Field'); +goog.module('Blockly.Field'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.DropDownDiv'); @@ -61,7 +62,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @implements {Blockly.IKeyboardAccessible} * @implements {Blockly.IRegistrable} */ -Blockly.Field = function(value, opt_validator, opt_config) { +const Field = function(value, opt_validator, opt_config) { /** * A generic value possessed by the field. * Should generally be non-null, only null when the field is created. @@ -160,62 +161,62 @@ Blockly.Field = function(value, opt_validator, opt_config) { * @type {*} * @protected */ -Blockly.Field.prototype.DEFAULT_VALUE = null; +Field.prototype.DEFAULT_VALUE = null; /** * Name of field. Unique within each block. * Static labels are usually unnamed. * @type {string|undefined} */ -Blockly.Field.prototype.name = undefined; +Field.prototype.name = undefined; /** * Has this field been disposed of? * @type {boolean} * @package */ -Blockly.Field.prototype.disposed = false; +Field.prototype.disposed = false; /** * Maximum characters of text to display before adding an ellipsis. * @type {number} */ -Blockly.Field.prototype.maxDisplayLength = 50; +Field.prototype.maxDisplayLength = 50; /** * Block this field is attached to. Starts as null, then set in init. * @type {Blockly.Block} * @protected */ -Blockly.Field.prototype.sourceBlock_ = null; +Field.prototype.sourceBlock_ = null; /** * Does this block need to be re-rendered? * @type {boolean} * @protected */ -Blockly.Field.prototype.isDirty_ = true; +Field.prototype.isDirty_ = true; /** * Is the field visible, or hidden due to the block being collapsed? * @type {boolean} * @protected */ -Blockly.Field.prototype.visible_ = true; +Field.prototype.visible_ = true; /** * Can the field value be changed using the editor on an editable block? * @type {boolean} * @protected */ -Blockly.Field.prototype.enabled_ = true; +Field.prototype.enabled_ = true; /** * The element the click handler is bound to. * @type {Element} * @protected */ -Blockly.Field.prototype.clickTarget_ = null; +Field.prototype.clickTarget_ = null; /** * A developer hook to override the returned text of this field. @@ -225,7 +226,7 @@ Blockly.Field.prototype.clickTarget_ = null; * @return {?string} Current text. Return null to resort to a string cast. * @protected */ -Blockly.Field.prototype.getText_; +Field.prototype.getText_; /** * An optional method that can be defined to show an editor when the field is @@ -236,20 +237,20 @@ Blockly.Field.prototype.getText_; * @return {void} * @protected */ -Blockly.Field.prototype.showEditor_; +Field.prototype.showEditor_; /** * Non-breaking space. * @const */ -Blockly.Field.NBSP = '\u00A0'; +Field.NBSP = '\u00A0'; /** * Editable fields usually show some sort of UI indicating they are editable. * They will also be saved by the XML renderer. * @type {boolean} */ -Blockly.Field.prototype.EDITABLE = true; +Field.prototype.EDITABLE = true; /** * Serializable fields are saved by the XML renderer, non-serializable fields @@ -257,7 +258,7 @@ Blockly.Field.prototype.EDITABLE = true; * case by default so that SERIALIZABLE is backwards compatible. * @type {boolean} */ -Blockly.Field.prototype.SERIALIZABLE = false; +Field.prototype.SERIALIZABLE = false; /** * Process the configuration map passed to the field. @@ -266,7 +267,7 @@ Blockly.Field.prototype.SERIALIZABLE = false; * parameter supports. * @protected */ -Blockly.Field.prototype.configure_ = function(config) { +Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { tooltip = Blockly.utils.replaceMessageReferences( @@ -282,7 +283,7 @@ Blockly.Field.prototype.configure_ = function(config) { * Attach this field to a block. * @param {!Blockly.Block} block The block containing this field. */ -Blockly.Field.prototype.setSourceBlock = function(block) { +Field.prototype.setSourceBlock = function(block) { if (this.sourceBlock_) { throw Error('Field already bound to a block'); } @@ -294,7 +295,7 @@ Blockly.Field.prototype.setSourceBlock = function(block) { * @return {?Blockly.blockRendering.ConstantProvider} The renderer constant * provider. */ -Blockly.Field.prototype.getConstants = function() { +Field.prototype.getConstants = function() { if (!this.constants_ && this.sourceBlock_ && this.sourceBlock_.workspace && this.sourceBlock_.workspace.rendered) { this.constants_ = this.sourceBlock_.workspace.getRenderer().getConstants(); @@ -306,7 +307,7 @@ Blockly.Field.prototype.getConstants = function() { * Get the block this field is attached to. * @return {Blockly.Block} The block containing this field. */ -Blockly.Field.prototype.getSourceBlock = function() { +Field.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -315,7 +316,7 @@ Blockly.Field.prototype.getSourceBlock = function() { * methods initModel and initView rather than this method. * @package */ -Blockly.Field.prototype.init = function() { +Field.prototype.init = function() { if (this.fieldGroup_) { // Field has already been initialized once. return; @@ -338,7 +339,7 @@ Blockly.Field.prototype.init = function() { * Create the block UI for this field. * @package */ -Blockly.Field.prototype.initView = function() { +Field.prototype.initView = function() { this.createBorderRect_(); this.createTextElement_(); }; @@ -348,7 +349,7 @@ Blockly.Field.prototype.initView = function() { * No-op by default. * @package */ -Blockly.Field.prototype.initModel = function() { +Field.prototype.initModel = function() { }; /** @@ -357,7 +358,7 @@ Blockly.Field.prototype.initModel = function() { * separate function to call. * @protected */ -Blockly.Field.prototype.createBorderRect_ = function() { +Field.prototype.createBorderRect_ = function() { this.borderRect_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'rx': this.getConstants().FIELD_BORDER_RECT_RADIUS, @@ -376,7 +377,7 @@ Blockly.Field.prototype.createBorderRect_ = function() { * function to call. * @protected */ -Blockly.Field.prototype.createTextElement_ = function() { +Field.prototype.createTextElement_ = function() { this.textElement_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': 'blocklyText', @@ -393,7 +394,7 @@ Blockly.Field.prototype.createTextElement_ = function() { * custom input handling. * @protected */ -Blockly.Field.prototype.bindEvents_ = function() { +Field.prototype.bindEvents_ = function() { Blockly.Tooltip.bindMouseEvents(this.getClickTarget_()); this.mouseDownWrapper_ = Blockly.browserEvents.conditionalBind( this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); @@ -406,7 +407,7 @@ Blockly.Field.prototype.bindEvents_ = function() { * field's state. * @package */ -Blockly.Field.prototype.fromXml = function(fieldElement) { +Field.prototype.fromXml = function(fieldElement) { this.setValue(fieldElement.textContent); }; @@ -417,7 +418,7 @@ Blockly.Field.prototype.fromXml = function(fieldElement) { * @return {!Element} The element containing info about the field's state. * @package */ -Blockly.Field.prototype.toXml = function(fieldElement) { +Field.prototype.toXml = function(fieldElement) { fieldElement.textContent = this.getValue(); return fieldElement; }; @@ -426,7 +427,7 @@ Blockly.Field.prototype.toXml = function(fieldElement) { * Dispose of all DOM objects and events belonging to this editable field. * @package */ -Blockly.Field.prototype.dispose = function() { +Field.prototype.dispose = function() { Blockly.DropDownDiv.hideIfOwner(this); Blockly.WidgetDiv.hideIfOwner(this); Blockly.Tooltip.unbindMouseEvents(this.getClickTarget_()); @@ -443,7 +444,7 @@ Blockly.Field.prototype.dispose = function() { /** * Add or remove the UI indicating if this field is editable or not. */ -Blockly.Field.prototype.updateEditable = function() { +Field.prototype.updateEditable = function() { const group = this.fieldGroup_; if (!this.EDITABLE || !group) { return; @@ -464,7 +465,7 @@ Blockly.Field.prototype.updateEditable = function() { * source block is editable. * @param {boolean} enabled True if enabled. */ -Blockly.Field.prototype.setEnabled = function(enabled) { +Field.prototype.setEnabled = function(enabled) { this.enabled_ = enabled; this.updateEditable(); }; @@ -474,7 +475,7 @@ Blockly.Field.prototype.setEnabled = function(enabled) { * source block is editable. * @return {boolean} Whether this field is enabled. */ -Blockly.Field.prototype.isEnabled = function() { +Field.prototype.isEnabled = function() { return this.enabled_; }; @@ -482,7 +483,7 @@ Blockly.Field.prototype.isEnabled = function() { * Check whether this field defines the showEditor_ function. * @return {boolean} Whether this field is clickable. */ -Blockly.Field.prototype.isClickable = function() { +Field.prototype.isClickable = function() { return this.enabled_ && !!this.sourceBlock_ && this.sourceBlock_.isEditable() && !!this.showEditor_ && (typeof this.showEditor_ === 'function'); @@ -495,7 +496,7 @@ Blockly.Field.prototype.isClickable = function() { * @return {boolean} Whether this field is currently enabled, editable and on * an editable block. */ -Blockly.Field.prototype.isCurrentlyEditable = function() { +Field.prototype.isCurrentlyEditable = function() { return this.enabled_ && this.EDITABLE && !!this.sourceBlock_ && this.sourceBlock_.isEditable(); }; @@ -505,7 +506,7 @@ Blockly.Field.prototype.isCurrentlyEditable = function() { * Handles the logic for backwards compatibility and incongruous states. * @return {boolean} Whether this field should be serialized or not. */ -Blockly.Field.prototype.isSerializable = function() { +Field.prototype.isSerializable = function() { let isSerializable = false; if (this.name) { if (this.SERIALIZABLE) { @@ -524,7 +525,7 @@ Blockly.Field.prototype.isSerializable = function() { * Gets whether this editable field is visible or not. * @return {boolean} True if visible. */ -Blockly.Field.prototype.isVisible = function() { +Field.prototype.isVisible = function() { return this.visible_; }; @@ -534,7 +535,7 @@ Blockly.Field.prototype.isVisible = function() { * @param {boolean} visible True if visible. * @package */ -Blockly.Field.prototype.setVisible = function(visible) { +Field.prototype.setVisible = function(visible) { if (this.visible_ == visible) { return; } @@ -560,7 +561,7 @@ Blockly.Field.prototype.setVisible = function(visible) { * @param {Function} handler The validator function * or null to clear a previous validator. */ -Blockly.Field.prototype.setValidator = function(handler) { +Field.prototype.setValidator = function(handler) { this.validator_ = handler; }; @@ -568,7 +569,7 @@ Blockly.Field.prototype.setValidator = function(handler) { * Gets the validation function for editable fields, or null if not set. * @return {?Function} Validation function, or null. */ -Blockly.Field.prototype.getValidator = function() { +Field.prototype.getValidator = function() { return this.validator_; }; @@ -577,7 +578,7 @@ Blockly.Field.prototype.getValidator = function() { * Used for measuring the size and for positioning. * @return {!SVGGElement} The group element. */ -Blockly.Field.prototype.getSvgRoot = function() { +Field.prototype.getSvgRoot = function() { return /** @type {!SVGGElement} */ (this.fieldGroup_); }; @@ -586,7 +587,7 @@ Blockly.Field.prototype.getSvgRoot = function() { * called by BlockSvg.applyColour(). * @package */ -Blockly.Field.prototype.applyColour = function() { +Field.prototype.applyColour = function() { // Non-abstract sub-classes may wish to implement this. See FieldDropdown. }; @@ -597,7 +598,7 @@ Blockly.Field.prototype.applyColour = function() { * done here, and should be triggered by getSize(). * @protected */ -Blockly.Field.prototype.render_ = function() { +Field.prototype.render_ = function() { if (this.textContent_) { this.textContent_.nodeValue = this.getDisplayText_(); } @@ -610,7 +611,7 @@ Blockly.Field.prototype.render_ = function() { * or undefined if triggered programmatically. * @package */ -Blockly.Field.prototype.showEditor = function(opt_e) { +Field.prototype.showEditor = function(opt_e) { if (this.isClickable()) { this.showEditor_(opt_e); } @@ -621,7 +622,7 @@ Blockly.Field.prototype.showEditor = function(opt_e) { * @param {number=} opt_margin margin to use when positioning the text element. * @protected */ -Blockly.Field.prototype.updateSize_ = function(opt_margin) { +Field.prototype.updateSize_ = function(opt_margin) { const constants = this.getConstants(); const xOffset = opt_margin != undefined ? opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); @@ -654,7 +655,7 @@ Blockly.Field.prototype.updateSize_ = function(opt_margin) { * @param {number} contentWidth The content width. * @protected */ -Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { +Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { if (!this.textElement_) { return; } @@ -672,7 +673,7 @@ Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { * Position a field's border rect after a size change. * @protected */ -Blockly.Field.prototype.positionBorderRect_ = function() { +Field.prototype.positionBorderRect_ = function() { if (!this.borderRect_) { return; } @@ -691,7 +692,7 @@ Blockly.Field.prototype.positionBorderRect_ = function() { * This should *in general* be the only place render_ gets called from. * @return {!Blockly.utils.Size} Height and width. */ -Blockly.Field.prototype.getSize = function() { +Field.prototype.getSize = function() { if (!this.isVisible()) { return new Blockly.utils.Size(0, 0); } @@ -716,7 +717,7 @@ Blockly.Field.prototype.getSize = function() { * pixels relative to the top left corner of the page (window coordinates). * @package */ -Blockly.Field.prototype.getScaledBBox = function() { +Field.prototype.getScaledBBox = function() { let scaledWidth, scaledHeight, xy; if (!this.borderRect_) { // Browsers are inconsistent in what they return for a bounding box. @@ -761,18 +762,18 @@ Blockly.Field.prototype.getScaledBBox = function() { * @return {string} Text to display. * @protected */ -Blockly.Field.prototype.getDisplayText_ = function() { +Field.prototype.getDisplayText_ = function() { let text = this.getText(); if (!text) { // Prevent the field from disappearing if empty. - return Blockly.Field.NBSP; + return Field.NBSP; } if (text.length > this.maxDisplayLength) { // Truncate displayed string and add an ellipsis ('...'). text = text.substring(0, this.maxDisplayLength - 2) + '\u2026'; } // Replace whitespace with non-breaking spaces so the text doesn't collapse. - text = text.replace(/\s/g, Blockly.Field.NBSP); + text = text.replace(/\s/g, Field.NBSP); if (this.sourceBlock_ && this.sourceBlock_.RTL) { // The SVG is LTR, force text to be RTL. text += '\u200F'; @@ -784,7 +785,7 @@ Blockly.Field.prototype.getDisplayText_ = function() { * Get the text from this field. * @return {string} Current text. */ -Blockly.Field.prototype.getText = function() { +Field.prototype.getText = function() { if (this.getText_) { const text = this.getText_.call(this); if (text !== null) { @@ -801,7 +802,7 @@ Blockly.Field.prototype.getText = function() { * already been recorded. * @package */ -Blockly.Field.prototype.markDirty = function() { +Field.prototype.markDirty = function() { this.isDirty_ = true; this.constants_ = null; }; @@ -813,7 +814,7 @@ Blockly.Field.prototype.markDirty = function() { * already been recorded. * @package */ -Blockly.Field.prototype.forceRerender = function() { +Field.prototype.forceRerender = function() { this.isDirty_ = true; if (this.sourceBlock_ && this.sourceBlock_.rendered) { this.sourceBlock_.render(); @@ -828,7 +829,7 @@ Blockly.Field.prototype.forceRerender = function() { * than this method. * @param {*} newValue New value. */ -Blockly.Field.prototype.setValue = function(newValue) { +Field.prototype.setValue = function(newValue) { const doLogging = false; if (newValue === null) { doLogging && console.log('null, return'); @@ -884,7 +885,7 @@ Blockly.Field.prototype.setValue = function(newValue) { * @return {*} New value, or an Error object. * @private */ -Blockly.Field.prototype.processValidation_ = function(newValue, +Field.prototype.processValidation_ = function(newValue, validatedValue) { if (validatedValue === null) { this.doValueInvalid_(newValue); @@ -903,7 +904,7 @@ Blockly.Field.prototype.processValidation_ = function(newValue, * Get the current value of the field. * @return {*} Current value. */ -Blockly.Field.prototype.getValue = function() { +Field.prototype.getValue = function() { return this.value_; }; @@ -914,7 +915,7 @@ Blockly.Field.prototype.getValue = function() { * @return {*} The validated value, same as input by default. * @protected */ -Blockly.Field.prototype.doClassValidation_ = function(opt_newValue) { +Field.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -927,7 +928,7 @@ Blockly.Field.prototype.doClassValidation_ = function(opt_newValue) { * @param {*} newValue The value to be saved. * @protected */ -Blockly.Field.prototype.doValueUpdate_ = function(newValue) { +Field.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; this.isDirty_ = true; }; @@ -939,7 +940,7 @@ Blockly.Field.prototype.doValueUpdate_ = function(newValue) { * @param {*} _invalidValue The input value that was determined to be invalid. * @protected */ -Blockly.Field.prototype.doValueInvalid_ = function(_invalidValue) { +Field.prototype.doValueInvalid_ = function(_invalidValue) { // NOP }; @@ -948,7 +949,7 @@ Blockly.Field.prototype.doValueInvalid_ = function(_invalidValue) { * @param {!Event} e Mouse down event. * @protected */ -Blockly.Field.prototype.onMouseDown_ = function(e) { +Field.prototype.onMouseDown_ = function(e) { if (!this.sourceBlock_ || !this.sourceBlock_.workspace) { return; } @@ -965,7 +966,7 @@ Blockly.Field.prototype.onMouseDown_ = function(e) { * parent object whose tooltip will be used, or null to display the tooltip * of the parent block. To not display a tooltip pass the empty string. */ -Blockly.Field.prototype.setTooltip = function(newTip) { +Field.prototype.setTooltip = function(newTip) { if (!newTip && newTip !== '') { // If null or undefined. newTip = this.sourceBlock_; } @@ -982,7 +983,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { * Returns the tooltip text for this field. * @return {string} The tooltip text for this field. */ -Blockly.Field.prototype.getTooltip = function() { +Field.prototype.getTooltip = function() { const clickTarget = this.getClickTarget_(); if (clickTarget) { return Blockly.Tooltip.getTooltipOfObject(clickTarget); @@ -998,7 +999,7 @@ Blockly.Field.prototype.getTooltip = function() { * @return {!Element} Element to bind click handler to. * @protected */ -Blockly.Field.prototype.getClickTarget_ = function() { +Field.prototype.getClickTarget_ = function() { return this.clickTarget_ || this.getSvgRoot(); }; @@ -1008,7 +1009,7 @@ Blockly.Field.prototype.getClickTarget_ = function() { * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. * @protected */ -Blockly.Field.prototype.getAbsoluteXY_ = function() { +Field.prototype.getAbsoluteXY_ = function() { return Blockly.utils.style.getPageOffset( /** @type {!SVGRectElement} */ (this.getClickTarget_())); }; @@ -1020,7 +1021,7 @@ Blockly.Field.prototype.getAbsoluteXY_ = function() { * @return {boolean} True if this field has any variable references. * @package */ -Blockly.Field.prototype.referencesVariables = function() { +Field.prototype.referencesVariables = function() { return false; }; @@ -1030,7 +1031,7 @@ Blockly.Field.prototype.referencesVariables = function() { * @return {Blockly.Input} The input that the field belongs to. * @package */ -Blockly.Field.prototype.getParentInput = function() { +Field.prototype.getParentInput = function() { let parentInput = null; const block = this.sourceBlock_; const inputs = block.inputList; @@ -1052,7 +1053,7 @@ Blockly.Field.prototype.getParentInput = function() { * Returns whether or not we should flip the field in RTL. * @return {boolean} True if we should flip in RTL. */ -Blockly.Field.prototype.getFlipRtl = function() { +Field.prototype.getFlipRtl = function() { return false; }; @@ -1060,7 +1061,7 @@ Blockly.Field.prototype.getFlipRtl = function() { * Returns whether or not the field is tab navigable. * @return {boolean} True if the field is tab navigable. */ -Blockly.Field.prototype.isTabNavigable = function() { +Field.prototype.isTabNavigable = function() { return false; }; @@ -1070,7 +1071,7 @@ Blockly.Field.prototype.isTabNavigable = function() { * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ -Blockly.Field.prototype.onShortcut = function(_shortcut) { +Field.prototype.onShortcut = function(_shortcut) { return false; }; @@ -1080,7 +1081,7 @@ Blockly.Field.prototype.onShortcut = function(_shortcut) { * field group. * @package */ -Blockly.Field.prototype.setCursorSvg = function(cursorSvg) { +Field.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg_ = null; return; @@ -1096,7 +1097,7 @@ Blockly.Field.prototype.setCursorSvg = function(cursorSvg) { * field group. * @package */ -Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { +Field.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg_ = null; return; @@ -1110,7 +1111,7 @@ Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { * Redraw any attached marker or cursor svgs if needed. * @protected */ -Blockly.Field.prototype.updateMarkers_ = function() { +Field.prototype.updateMarkers_ = function() { const workspace = /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { @@ -1121,3 +1122,5 @@ Blockly.Field.prototype.updateMarkers_ = function() { workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw(); } }; + +exports = Field; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..8d3cef438 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -48,7 +48,7 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); From 00a74e9d37dbc74dd6b479714b8c7a9ca655320c Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:26:28 -0700 Subject: [PATCH 175/313] Migrate core/interfaces/i_registrable_field.js to goog.module --- core/interfaces/i_registrable_field.js | 12 ++++++++---- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 1d49edad2..180599bdb 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -11,21 +11,25 @@ 'use strict'; -goog.provide('Blockly.IRegistrableField'); +goog.module('Blockly.IRegistrableField'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.Field'); + /** * A registrable field. * Note: We are not using an interface here as we are interested in defining the * static methods of a field rather than the instance methods. * @typedef {{ - * fromJson:Blockly.IRegistrableField.fromJson + * fromJson:IRegistrableField.fromJson * }} */ -Blockly.IRegistrableField; +let IRegistrableField; /** * @typedef {function(!Object): Blockly.Field} */ -Blockly.IRegistrableField.fromJson; +IRegistrableField.fromJson; + +exports = IRegistrableField; diff --git a/tests/deps.js b/tests/deps.js index 9a0ae6896..fb0b9793c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -95,7 +95,7 @@ goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetr 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'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); From 7d946afb4ea7f00f8111444dd828b6c3400122f7 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:26:43 -0700 Subject: [PATCH 176/313] Migrate core/interfaces/i_registrable_field.js named requires --- core/interfaces/i_registrable_field.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 180599bdb..2c8c005bd 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -14,7 +14,7 @@ goog.module('Blockly.IRegistrableField'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.Field'); +const Field = goog.requireType('Blockly.Field'); /** @@ -28,7 +28,7 @@ goog.requireType('Blockly.Field'); let IRegistrableField; /** - * @typedef {function(!Object): Blockly.Field} + * @typedef {function(!Object): Field} */ IRegistrableField.fromJson; From a3ae4f30162f500619325c44f211179a9369cdee Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:41:48 -0700 Subject: [PATCH 177/313] Migrate core/field.js to named requires --- core/field.js | 163 +++++++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 76 deletions(-) diff --git a/core/field.js b/core/field.js index d9db11cbd..37352c64e 100644 --- a/core/field.js +++ b/core/field.js @@ -15,35 +15,46 @@ goog.module('Blockly.Field'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const IASTNodeLocationSvg = goog.require('Blockly.IASTNodeLocationSvg'); +/* eslint-disable-next-line no-unused-vars */ +const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +/* eslint-disable-next-line no-unused-vars */ +const IKeyboardAccessible = goog.require('Blockly.IKeyboardAccessible'); +/* eslint-disable-next-line no-unused-vars */ +const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ +const Input = goog.requireType('Blockly.Input'); +const MarkerManager = goog.require('Blockly.MarkerManager'); +const Rect = goog.require('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ +const ShortcutRegistry = goog.requireType('Blockly.ShortcutRegistry'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const Tooltip = goog.require('Blockly.Tooltip'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {addClass, createSvgElement, getFastTextWidth, removeClass, removeNode} = goog.require('Blockly.utils.dom'); +/* eslint-disable-next-line no-unused-vars */ +const {conditionalBind, unbind, Data} = goog.require('Blockly.browserEvents'); +const {getPageOffset} = goog.require('Blockly.utils.style'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Gesture'); -goog.require('Blockly.IASTNodeLocationSvg'); -goog.require('Blockly.IASTNodeLocationWithBlock'); -goog.require('Blockly.IKeyboardAccessible'); -goog.require('Blockly.IRegistrable'); -goog.require('Blockly.MarkerManager'); -goog.require('Blockly.Tooltip'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.style'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Input'); -goog.requireType('Blockly.ShortcutRegistry'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -57,10 +68,10 @@ goog.requireType('Blockly.WorkspaceSvg'); * parameter supports. * @constructor * @abstract - * @implements {Blockly.IASTNodeLocationSvg} - * @implements {Blockly.IASTNodeLocationWithBlock} - * @implements {Blockly.IKeyboardAccessible} - * @implements {Blockly.IRegistrable} + * @implements {IASTNodeLocationSvg} + * @implements {IASTNodeLocationWithBlock} + * @implements {IKeyboardAccessible} + * @implements {IRegistrable} */ const Field = function(value, opt_validator, opt_config) { /** @@ -81,17 +92,17 @@ const Field = function(value, opt_validator, opt_config) { /** * Used to cache the field's tooltip value if setTooltip is called when the * field is not yet initialized. Is *not* guaranteed to be accurate. - * @type {?Blockly.Tooltip.TipInfo} + * @type {?Tooltip.TipInfo} * @private */ this.tooltip_ = null; /** * The size of the area rendered by the field. - * @type {!Blockly.utils.Size} + * @type {!Size} * @protected */ - this.size_ = new Blockly.utils.Size(0, 0); + this.size_ = new Size(0, 0); /** * Holds the cursors svg element when the cursor is attached to the field. @@ -139,14 +150,14 @@ const Field = function(value, opt_validator, opt_config) { /** * Mouse down event listener data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseDownWrapper_ = null; /** * Constants associated with the source block's renderer. - * @type {Blockly.blockRendering.ConstantProvider} + * @type {ConstantProvider} * @protected */ this.constants_ = null; @@ -185,7 +196,7 @@ Field.prototype.maxDisplayLength = 50; /** * Block this field is attached to. Starts as null, then set in init. - * @type {Blockly.Block} + * @type {Block} * @protected */ Field.prototype.sourceBlock_ = null; @@ -270,7 +281,7 @@ Field.prototype.SERIALIZABLE = false; Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { - tooltip = Blockly.utils.replaceMessageReferences( + tooltip = replaceMessageReferences( config['tooltip']); } tooltip && this.setTooltip(tooltip); @@ -281,7 +292,7 @@ Field.prototype.configure_ = function(config) { /** * Attach this field to a block. - * @param {!Blockly.Block} block The block containing this field. + * @param {!Block} block The block containing this field. */ Field.prototype.setSourceBlock = function(block) { if (this.sourceBlock_) { @@ -292,7 +303,7 @@ Field.prototype.setSourceBlock = function(block) { /** * Get the renderer constant provider. - * @return {?Blockly.blockRendering.ConstantProvider} The renderer constant + * @return {?ConstantProvider} The renderer constant * provider. */ Field.prototype.getConstants = function() { @@ -305,7 +316,7 @@ Field.prototype.getConstants = function() { /** * Get the block this field is attached to. - * @return {Blockly.Block} The block containing this field. + * @return {Block} The block containing this field. */ Field.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -321,12 +332,12 @@ Field.prototype.init = function() { // Field has already been initialized once. return; } - this.fieldGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, {}, null); + this.fieldGroup_ = createSvgElement( + Svg.G, {}, null); if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } - const sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); + const sourceBlockSvg = /** @type {!BlockSvg} **/ (this.sourceBlock_); sourceBlockSvg.getSvgRoot().appendChild(this.fieldGroup_); this.initView(); this.updateEditable(); @@ -359,8 +370,8 @@ Field.prototype.initModel = function() { * @protected */ Field.prototype.createBorderRect_ = function() { - this.borderRect_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, { + this.borderRect_ = createSvgElement( + Svg.RECT, { 'rx': this.getConstants().FIELD_BORDER_RECT_RADIUS, 'ry': this.getConstants().FIELD_BORDER_RECT_RADIUS, 'x': 0, @@ -378,8 +389,8 @@ Field.prototype.createBorderRect_ = function() { * @protected */ Field.prototype.createTextElement_ = function() { - this.textElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, { + this.textElement_ = createSvgElement( + Svg.TEXT, { 'class': 'blocklyText', }, this.fieldGroup_); if (this.getConstants().FIELD_TEXT_BASELINE_CENTER) { @@ -395,8 +406,8 @@ Field.prototype.createTextElement_ = function() { * @protected */ Field.prototype.bindEvents_ = function() { - Blockly.Tooltip.bindMouseEvents(this.getClickTarget_()); - this.mouseDownWrapper_ = Blockly.browserEvents.conditionalBind( + Tooltip.bindMouseEvents(this.getClickTarget_()); + this.mouseDownWrapper_ = conditionalBind( this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); }; @@ -428,15 +439,15 @@ Field.prototype.toXml = function(fieldElement) { * @package */ Field.prototype.dispose = function() { - Blockly.DropDownDiv.hideIfOwner(this); - Blockly.WidgetDiv.hideIfOwner(this); - Blockly.Tooltip.unbindMouseEvents(this.getClickTarget_()); + DropDownDiv.hideIfOwner(this); + WidgetDiv.hideIfOwner(this); + Tooltip.unbindMouseEvents(this.getClickTarget_()); if (this.mouseDownWrapper_) { - Blockly.browserEvents.unbind(this.mouseDownWrapper_); + unbind(this.mouseDownWrapper_); } - Blockly.utils.dom.removeNode(this.fieldGroup_); + removeNode(this.fieldGroup_); this.disposed = true; }; @@ -450,12 +461,12 @@ Field.prototype.updateEditable = function() { return; } if (this.enabled_ && this.sourceBlock_.isEditable()) { - Blockly.utils.dom.addClass(group, 'blocklyEditableText'); - Blockly.utils.dom.removeClass(group, 'blocklyNonEditableText'); + addClass(group, 'blocklyEditableText'); + removeClass(group, 'blocklyNonEditableText'); group.style.cursor = this.CURSOR; } else { - Blockly.utils.dom.addClass(group, 'blocklyNonEditableText'); - Blockly.utils.dom.removeClass(group, 'blocklyEditableText'); + addClass(group, 'blocklyNonEditableText'); + removeClass(group, 'blocklyEditableText'); group.style.cursor = ''; } }; @@ -631,7 +642,7 @@ Field.prototype.updateSize_ = function(opt_margin) { let contentWidth = 0; if (this.textElement_) { - contentWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + contentWidth = getFastTextWidth(this.textElement_, constants.FIELD_TEXT_FONTSIZE, constants.FIELD_TEXT_FONTWEIGHT, constants.FIELD_TEXT_FONTFAMILY); @@ -690,11 +701,11 @@ Field.prototype.positionBorderRect_ = function() { * Returns the height and width of the field. * * This should *in general* be the only place render_ gets called from. - * @return {!Blockly.utils.Size} Height and width. + * @return {!Size} Height and width. */ Field.prototype.getSize = function() { if (!this.isVisible()) { - return new Blockly.utils.Size(0, 0); + return new Size(0, 0); } if (this.isDirty_) { @@ -713,7 +724,7 @@ Field.prototype.getSize = function() { /** * Returns the bounding box of the rendered field, accounting for workspace * scaling. - * @return {!Blockly.utils.Rect} An object with top, bottom, left, and right in + * @return {!Rect} An object with top, bottom, left, and right in * pixels relative to the top left corner of the page (window coordinates). * @package */ @@ -729,13 +740,13 @@ Field.prototype.getScaledBBox = function() { scaledWidth = bBox.width * scale; scaledHeight = bBox.height * scale; - if (Blockly.utils.userAgent.GECKO) { + if (userAgent.GECKO) { xy.x += 1.5 * scale; xy.y += 1.5 * scale; scaledWidth += 1 * scale; scaledHeight += 1 * scale; } else { - if (!Blockly.utils.userAgent.EDGE && !Blockly.utils.userAgent.IE) { + if (!userAgent.EDGE && !userAgent.IE) { xy.x -= 0.5 * scale; xy.y -= 0.5 * scale; } @@ -744,11 +755,11 @@ Field.prototype.getScaledBBox = function() { } } else { const bBox = this.borderRect_.getBoundingClientRect(); - xy = Blockly.utils.style.getPageOffset(this.borderRect_); + xy = getPageOffset(this.borderRect_); scaledWidth = bBox.width; scaledHeight = bBox.height; } - return new Blockly.utils.Rect( + return new Rect( xy.y, xy.y + scaledHeight, xy.x, @@ -867,8 +878,8 @@ Field.prototype.setValue = function(newValue) { return; } - if (source && Blockly.Events.isEnabled()) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + if (source && Events.isEnabled()) { + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( source, 'field', this.name || null, oldValue, newValue)); } this.doValueUpdate_(newValue); @@ -961,7 +972,7 @@ Field.prototype.onMouseDown_ = function(e) { /** * Sets the tooltip for this field. - * @param {?Blockly.Tooltip.TipInfo} newTip The + * @param {?Tooltip.TipInfo} newTip The * text for the tooltip, a function that returns the text for the tooltip, a * parent object whose tooltip will be used, or null to display the tooltip * of the parent block. To not display a tooltip pass the empty string. @@ -986,10 +997,10 @@ Field.prototype.setTooltip = function(newTip) { Field.prototype.getTooltip = function() { const clickTarget = this.getClickTarget_(); if (clickTarget) { - return Blockly.Tooltip.getTooltipOfObject(clickTarget); + return Tooltip.getTooltipOfObject(clickTarget); } // Field has not been initialized yet. Return stashed this.tooltip_ value. - return Blockly.Tooltip.getTooltipOfObject({tooltip: this.tooltip_}); + return Tooltip.getTooltipOfObject({tooltip: this.tooltip_}); }; /** @@ -1006,11 +1017,11 @@ Field.prototype.getClickTarget_ = function() { /** * Return the absolute coordinates of the top-left corner of this field. * The origin (0,0) is the top-left corner of the page body. - * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. + * @return {!Coordinate} Object with .x and .y properties. * @protected */ Field.prototype.getAbsoluteXY_ = function() { - return Blockly.utils.style.getPageOffset( + return getPageOffset( /** @type {!SVGRectElement} */ (this.getClickTarget_())); }; @@ -1028,7 +1039,7 @@ Field.prototype.referencesVariables = function() { /** * Search through the list of inputs and their fields in order to find the * parent input of a field. - * @return {Blockly.Input} The input that the field belongs to. + * @return {Input} The input that the field belongs to. * @package */ Field.prototype.getParentInput = function() { @@ -1067,7 +1078,7 @@ Field.prototype.isTabNavigable = function() { /** * Handles the given keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ @@ -1113,13 +1124,13 @@ Field.prototype.setMarkerSvg = function(markerSvg) { */ Field.prototype.updateMarkers_ = function() { const workspace = - /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); + /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); } if (workspace.keyboardAccessibilityMode && this.markerSvg_) { // TODO(#4592): Update all markers on the field. - workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw(); + workspace.getMarker(MarkerManager.LOCAL_MARKER).draw(); } }; From edcfc04da15db66184f8ace8f3f2ce026b7c31c2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:45:32 -0700 Subject: [PATCH 178/313] clang-format core/field.js --- core/field.js | 74 +++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/core/field.js b/core/field.js index 37352c64e..926e62008 100644 --- a/core/field.js +++ b/core/field.js @@ -281,8 +281,7 @@ Field.prototype.SERIALIZABLE = false; Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { - tooltip = replaceMessageReferences( - config['tooltip']); + tooltip = replaceMessageReferences(config['tooltip']); } tooltip && this.setTooltip(tooltip); @@ -332,8 +331,7 @@ Field.prototype.init = function() { // Field has already been initialized once. return; } - this.fieldGroup_ = createSvgElement( - Svg.G, {}, null); + this.fieldGroup_ = createSvgElement(Svg.G, {}, null); if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } @@ -360,8 +358,7 @@ Field.prototype.initView = function() { * No-op by default. * @package */ -Field.prototype.initModel = function() { -}; +Field.prototype.initModel = function() {}; /** * Create a field border rect element. Not to be overridden by subclasses. @@ -379,7 +376,8 @@ Field.prototype.createBorderRect_ = function() { 'height': this.size_.height, 'width': this.size_.width, 'class': 'blocklyFieldRect' - }, this.fieldGroup_); + }, + this.fieldGroup_); }; /** @@ -392,7 +390,8 @@ Field.prototype.createTextElement_ = function() { this.textElement_ = createSvgElement( Svg.TEXT, { 'class': 'blocklyText', - }, this.fieldGroup_); + }, + this.fieldGroup_); if (this.getConstants().FIELD_TEXT_BASELINE_CENTER) { this.textElement_.setAttribute('dominant-baseline', 'central'); } @@ -523,9 +522,10 @@ Field.prototype.isSerializable = function() { if (this.SERIALIZABLE) { isSerializable = true; } else if (this.EDITABLE) { - console.warn('Detected an editable field that was not serializable.' + - ' Please define SERIALIZABLE property as true on all editable custom' + - ' fields. Proceeding with serialization.'); + console.warn( + 'Detected an editable field that was not serializable.' + + ' Please define SERIALIZABLE property as true on all editable custom' + + ' fields. Proceeding with serialization.'); isSerializable = true; } } @@ -635,17 +635,17 @@ Field.prototype.showEditor = function(opt_e) { */ Field.prototype.updateSize_ = function(opt_margin) { const constants = this.getConstants(); - const xOffset = opt_margin != undefined ? opt_margin : + const xOffset = opt_margin != undefined ? + opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); let totalWidth = xOffset * 2; let totalHeight = constants.FIELD_TEXT_HEIGHT; let contentWidth = 0; if (this.textElement_) { - contentWidth = getFastTextWidth(this.textElement_, - constants.FIELD_TEXT_FONTSIZE, - constants.FIELD_TEXT_FONTWEIGHT, - constants.FIELD_TEXT_FONTFAMILY); + contentWidth = getFastTextWidth( + this.textElement_, constants.FIELD_TEXT_FONTSIZE, + constants.FIELD_TEXT_FONTWEIGHT, constants.FIELD_TEXT_FONTFAMILY); totalWidth += contentWidth; } if (this.borderRect_) { @@ -673,11 +673,15 @@ Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { const constants = this.getConstants(); const halfHeight = this.size_.height / 2; - this.textElement_.setAttribute('x', this.sourceBlock_.RTL ? - this.size_.width - contentWidth - xOffset : xOffset); - this.textElement_.setAttribute('y', constants.FIELD_TEXT_BASELINE_CENTER ? - halfHeight : halfHeight - constants.FIELD_TEXT_HEIGHT / 2 + - constants.FIELD_TEXT_BASELINE); + this.textElement_.setAttribute( + 'x', + this.sourceBlock_.RTL ? this.size_.width - contentWidth - xOffset : + xOffset); + this.textElement_.setAttribute( + 'y', + constants.FIELD_TEXT_BASELINE_CENTER ? halfHeight : + halfHeight - + constants.FIELD_TEXT_HEIGHT / 2 + constants.FIELD_TEXT_BASELINE); }; /** @@ -690,10 +694,10 @@ Field.prototype.positionBorderRect_ = function() { } this.borderRect_.setAttribute('width', this.size_.width); this.borderRect_.setAttribute('height', this.size_.height); - this.borderRect_.setAttribute('rx', - this.getConstants().FIELD_BORDER_RECT_RADIUS); - this.borderRect_.setAttribute('ry', - this.getConstants().FIELD_BORDER_RECT_RADIUS); + this.borderRect_.setAttribute( + 'rx', this.getConstants().FIELD_BORDER_RECT_RADIUS); + this.borderRect_.setAttribute( + 'ry', this.getConstants().FIELD_BORDER_RECT_RADIUS); }; @@ -714,8 +718,9 @@ Field.prototype.getSize = function() { } else if (this.visible_ && this.size_.width == 0) { // If the field is not visible the width will be 0 as well, one of the // problems with the old system. - console.warn('Deprecated use of setting size_.width to 0 to rerender a' + - ' field. Set field.isDirty_ to true instead.'); + console.warn( + 'Deprecated use of setting size_.width to 0 to rerender a' + + ' field. Set field.isDirty_ to true instead.'); this.render_(); } return this.size_; @@ -759,12 +764,7 @@ Field.prototype.getScaledBBox = function() { scaledWidth = bBox.width; scaledHeight = bBox.height; } - return new Rect( - xy.y, - xy.y + scaledHeight, - xy.x, - xy.x + scaledWidth - ); + return new Rect(xy.y, xy.y + scaledHeight, xy.x, xy.x + scaledWidth); }; /** @@ -896,8 +896,7 @@ Field.prototype.setValue = function(newValue) { * @return {*} New value, or an Error object. * @private */ -Field.prototype.processValidation_ = function(newValue, - validatedValue) { +Field.prototype.processValidation_ = function(newValue, validatedValue) { if (validatedValue === null) { this.doValueInvalid_(newValue); if (this.isDirty_) { @@ -1078,7 +1077,8 @@ Field.prototype.isTabNavigable = function() { /** * Handles the given keyboard shortcut. - * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be + * handled. * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ @@ -1124,7 +1124,7 @@ Field.prototype.setMarkerSvg = function(markerSvg) { */ Field.prototype.updateMarkers_ = function() { const workspace = - /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); + /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); } From 5f305041a9de4108a00535060cb1df3b54a8aa34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 12:57:19 -0700 Subject: [PATCH 179/313] Migrate core/field_colour.js to ES6 const/let --- core/field_colour.js | 58 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 17d593f0e..632bf6965 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -233,7 +233,7 @@ Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { * @return {string} Text representing the value of this field. */ Blockly.FieldColour.prototype.getText = function() { - var colour = /** @type {string} */ (this.value_); + let colour = /** @type {string} */ (this.value_); // Try to use #rgb format if possible, rather than #rrggbb. if (/^#(.)\1(.)\2(.)\3$/.test(colour)) { colour = '#' + colour[1] + colour[3] + colour[5]; @@ -339,8 +339,8 @@ Blockly.FieldColour.prototype.showEditor_ = function() { * @private */ Blockly.FieldColour.prototype.onClick_ = function(e) { - var cell = /** @type {!Element} */ (e.target); - var colour = cell && cell.label; + const cell = /** @type {!Element} */ (e.target); + const colour = cell && cell.label; if (colour !== null) { this.setValue(colour); Blockly.DropDownDiv.hideIfOwner(this); @@ -354,7 +354,7 @@ Blockly.FieldColour.prototype.onClick_ = function(e) { * @private */ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { - var handled = false; + let handled = false; if (e.keyCode === Blockly.utils.KeyCodes.UP) { this.moveHighlightBy_(0, -1); handled = true; @@ -369,9 +369,9 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { handled = true; } else if (e.keyCode === Blockly.utils.KeyCodes.ENTER) { // Select the highlighted colour. - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { - var colour = highlighted && highlighted.label; + const colour = highlighted && highlighted.label; if (colour !== null) { this.setValue(colour); } @@ -391,12 +391,12 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { * @private */ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { - var colours = this.colours_ || Blockly.FieldColour.COLOURS; - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const colours = this.colours_ || Blockly.FieldColour.COLOURS; + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; // Get the current x and y coordinates - var x = this.highlightedIndex_ % columns; - var y = Math.floor(this.highlightedIndex_ / columns); + let x = this.highlightedIndex_ % columns; + let y = Math.floor(this.highlightedIndex_ / columns); // Add the offset x += dx; @@ -434,8 +434,8 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } // Move the highlight to the new coordinates. - var cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); - var index = (y * columns) + x; + const cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); + const index = (y * columns) + x; this.setHighlightedCell_(cell, index); }; @@ -445,8 +445,8 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { * @private */ Blockly.FieldColour.prototype.onMouseMove_ = function(e) { - var cell = /** @type {!Element} */ (e.target); - var index = cell && Number(cell.getAttribute('data-index')); + const cell = /** @type {!Element} */ (e.target); + const index = cell && Number(cell.getAttribute('data-index')); if (index !== null && index !== this.highlightedIndex_) { this.setHighlightedCell_(cell, index); } @@ -467,7 +467,7 @@ Blockly.FieldColour.prototype.onMouseEnter_ = function() { */ Blockly.FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); } @@ -479,14 +479,14 @@ Blockly.FieldColour.prototype.onMouseLeave_ = function() { * @private */ Blockly.FieldColour.prototype.getHighlighted_ = function() { - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; - var x = this.highlightedIndex_ % columns; - var y = Math.floor(this.highlightedIndex_ / columns); - var row = this.picker_.childNodes[y]; + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const x = this.highlightedIndex_ % columns; + const y = Math.floor(this.highlightedIndex_ / columns); + const row = this.picker_.childNodes[y]; if (!row) { return null; } - var col = /** @type {HTMLElement} */ (row.childNodes[x]); + const col = /** @type {HTMLElement} */ (row.childNodes[x]); return col; }; @@ -498,7 +498,7 @@ Blockly.FieldColour.prototype.getHighlighted_ = function() { */ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); } @@ -517,12 +517,12 @@ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { * @private */ Blockly.FieldColour.prototype.dropdownCreate_ = function() { - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; - var colours = this.colours_ || Blockly.FieldColour.COLOURS; - var titles = this.titles_ || Blockly.FieldColour.TITLES; - var selectedColour = this.getValue(); + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const colours = this.colours_ || Blockly.FieldColour.COLOURS; + const titles = this.titles_ || Blockly.FieldColour.TITLES; + const selectedColour = this.getValue(); // Create the palette. - var table = document.createElement('table'); + const table = document.createElement('table'); table.className = 'blocklyColourTable'; table.tabIndex = 0; table.dir = 'ltr'; @@ -532,14 +532,14 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { Math.floor(colours.length / columns)); Blockly.utils.aria.setState(table, Blockly.utils.aria.State.COLCOUNT, columns); - var row; - for (var i = 0; i < colours.length; i++) { + let row; + for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { row = document.createElement('tr'); Blockly.utils.aria.setRole(row, Blockly.utils.aria.Role.ROW); table.appendChild(row); } - var cell = document.createElement('td'); + const cell = document.createElement('td'); row.appendChild(cell); cell.label = colours[i]; // This becomes the value, if clicked. cell.title = titles[i] || colours[i]; From 03e1725f3244bfbedc9934b2ca339f73cbfcb646 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:00:05 -0700 Subject: [PATCH 180/313] Migrate core/field_colour.js to goog.module --- core/field_colour.js | 99 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 632bf6965..9d342150c 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldColour'); +goog.module('Blockly.FieldColour'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); @@ -41,8 +42,8 @@ goog.require('Blockly.utils.Size'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldColour = function(opt_value, opt_validator, opt_config) { - Blockly.FieldColour.superClass_.constructor.call( +const FieldColour = function(opt_value, opt_validator, opt_config) { + FieldColour.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); /** @@ -94,16 +95,16 @@ Blockly.FieldColour = function(opt_value, opt_validator, opt_config) { */ this.onKeyDownWrapper_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldColour, Blockly.Field); +Blockly.utils.object.inherits(FieldColour, Blockly.Field); /** * Construct a FieldColour from a JSON arg object. * @param {!Object} options A JSON object with options (colour). - * @return {!Blockly.FieldColour} The new field instance. + * @return {!FieldColour} The new field instance. * @package * @nocollapse */ -Blockly.FieldColour.fromJson = function(options) { +FieldColour.fromJson = function(options) { // `this` might be a subclass of FieldColour if that class doesn't override // the static fromJson method. return new this(options['colour'], undefined, options); @@ -114,12 +115,12 @@ Blockly.FieldColour.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldColour.prototype.SERIALIZABLE = true; +FieldColour.prototype.SERIALIZABLE = true; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldColour.prototype.CURSOR = 'default'; +FieldColour.prototype.CURSOR = 'default'; /** * Used to tell if the field needs to be rendered the next time the block is @@ -128,21 +129,21 @@ Blockly.FieldColour.prototype.CURSOR = 'default'; * @type {boolean} * @protected */ -Blockly.FieldColour.prototype.isDirty_ = false; +FieldColour.prototype.isDirty_ = false; /** * Array of colours used by this field. If null, use the global list. * @type {Array} * @private */ -Blockly.FieldColour.prototype.colours_ = null; +FieldColour.prototype.colours_ = null; /** * Array of colour tooltips used by this field. If null, use the global list. * @type {Array} * @private */ -Blockly.FieldColour.prototype.titles_ = null; +FieldColour.prototype.titles_ = null; /** * Number of colour columns used by this field. If 0, use the global setting. @@ -150,7 +151,7 @@ Blockly.FieldColour.prototype.titles_ = null; * @type {number} * @private */ -Blockly.FieldColour.prototype.columns_ = 0; +FieldColour.prototype.columns_ = 0; /** * Configure the field based on the given map of options. @@ -158,8 +159,8 @@ Blockly.FieldColour.prototype.columns_ = 0; * @protected * @override */ -Blockly.FieldColour.prototype.configure_ = function(config) { - Blockly.FieldColour.superClass_.configure_.call(this, config); +FieldColour.prototype.configure_ = function(config) { + FieldColour.superClass_.configure_.call(this, config); if (config['colourOptions']) { this.colours_ = config['colourOptions']; this.titles_ = config['colourTitles']; @@ -173,7 +174,7 @@ Blockly.FieldColour.prototype.configure_ = function(config) { * Create the block UI for this colour field. * @package */ -Blockly.FieldColour.prototype.initView = function() { +FieldColour.prototype.initView = function() { this.size_ = new Blockly.utils.Size( this.getConstants().FIELD_COLOUR_DEFAULT_WIDTH, this.getConstants().FIELD_COLOUR_DEFAULT_HEIGHT); @@ -188,7 +189,7 @@ Blockly.FieldColour.prototype.initView = function() { /** * @override */ -Blockly.FieldColour.prototype.applyColour = function() { +FieldColour.prototype.applyColour = function() { if (!this.getConstants().FIELD_COLOUR_FULL_BLOCK) { if (this.borderRect_) { this.borderRect_.style.fill = /** @type {string} */ (this.getValue()); @@ -205,7 +206,7 @@ Blockly.FieldColour.prototype.applyColour = function() { * @return {?string} A valid colour, or null if invalid. * @protected */ -Blockly.FieldColour.prototype.doClassValidation_ = function(opt_newValue) { +FieldColour.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } @@ -218,7 +219,7 @@ Blockly.FieldColour.prototype.doClassValidation_ = function(opt_newValue) { * that this is a colour in '#rrggbb' format. * @protected */ -Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { +FieldColour.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.borderRect_) { this.borderRect_.style.fill = /** @type {string} */ (newValue); @@ -232,7 +233,7 @@ Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { * Get the text for this field. Used when the block is collapsed. * @return {string} Text representing the value of this field. */ -Blockly.FieldColour.prototype.getText = function() { +FieldColour.prototype.getText = function() { let colour = /** @type {string} */ (this.value_); // Try to use #rgb format if possible, rather than #rrggbb. if (/^#(.)\1(.)\2(.)\3$/.test(colour)) { @@ -247,7 +248,7 @@ Blockly.FieldColour.prototype.getText = function() { * All colour pickers use this unless overridden with setColours. * @type {!Array} */ -Blockly.FieldColour.COLOURS = [ +FieldColour.COLOURS = [ // grays '#ffffff', '#cccccc', '#c0c0c0', '#999999', '#666666', '#333333', '#000000', // reds @@ -275,7 +276,7 @@ Blockly.FieldColour.COLOURS = [ * @type {*} * @protected */ -Blockly.FieldColour.prototype.DEFAULT_VALUE = Blockly.FieldColour.COLOURS[0]; +FieldColour.prototype.DEFAULT_VALUE = FieldColour.COLOURS[0]; /** * An array of tooltip strings for the palette. If not the same length as @@ -283,23 +284,23 @@ Blockly.FieldColour.prototype.DEFAULT_VALUE = Blockly.FieldColour.COLOURS[0]; * All colour pickers use this unless overridden with setColours. * @type {!Array} */ -Blockly.FieldColour.TITLES = []; +FieldColour.TITLES = []; /** * Number of columns in the palette. * All colour pickers use this unless overridden with setColumns. */ -Blockly.FieldColour.COLUMNS = 7; +FieldColour.COLUMNS = 7; /** * Set a custom colour grid for this field. * @param {Array} colours Array of colours for this block, - * or null to use default (Blockly.FieldColour.COLOURS). + * or null to use default (FieldColour.COLOURS). * @param {Array=} opt_titles Optional array of colour tooltips, - * or null to use default (Blockly.FieldColour.TITLES). - * @return {!Blockly.FieldColour} Returns itself (for method chaining). + * or null to use default (FieldColour.TITLES). + * @return {!FieldColour} Returns itself (for method chaining). */ -Blockly.FieldColour.prototype.setColours = function(colours, opt_titles) { +FieldColour.prototype.setColours = function(colours, opt_titles) { this.colours_ = colours; if (opt_titles) { this.titles_ = opt_titles; @@ -310,10 +311,10 @@ Blockly.FieldColour.prototype.setColours = function(colours, opt_titles) { /** * Set a custom grid size for this field. * @param {number} columns Number of columns for this block, - * or 0 to use default (Blockly.FieldColour.COLUMNS). - * @return {!Blockly.FieldColour} Returns itself (for method chaining). + * or 0 to use default (FieldColour.COLUMNS). + * @return {!FieldColour} Returns itself (for method chaining). */ -Blockly.FieldColour.prototype.setColumns = function(columns) { +FieldColour.prototype.setColumns = function(columns) { this.columns_ = columns; return this; }; @@ -322,7 +323,7 @@ Blockly.FieldColour.prototype.setColumns = function(columns) { * Create and show the colour field's editor. * @protected */ -Blockly.FieldColour.prototype.showEditor_ = function() { +FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); Blockly.DropDownDiv.getContentDiv().appendChild(this.picker_); @@ -338,7 +339,7 @@ Blockly.FieldColour.prototype.showEditor_ = function() { * @param {!MouseEvent} e Mouse event. * @private */ -Blockly.FieldColour.prototype.onClick_ = function(e) { +FieldColour.prototype.onClick_ = function(e) { const cell = /** @type {!Element} */ (e.target); const colour = cell && cell.label; if (colour !== null) { @@ -353,7 +354,7 @@ Blockly.FieldColour.prototype.onClick_ = function(e) { * @param {!KeyboardEvent} e Keyboard event. * @private */ -Blockly.FieldColour.prototype.onKeyDown_ = function(e) { +FieldColour.prototype.onKeyDown_ = function(e) { let handled = false; if (e.keyCode === Blockly.utils.KeyCodes.UP) { this.moveHighlightBy_(0, -1); @@ -390,9 +391,9 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { * @param {number} dy Change of y * @private */ -Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { - const colours = this.colours_ || Blockly.FieldColour.COLOURS; - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; +FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { + const colours = this.colours_ || FieldColour.COLOURS; + const columns = this.columns_ || FieldColour.COLUMNS; // Get the current x and y coordinates let x = this.highlightedIndex_ % columns; @@ -444,7 +445,7 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { * @param {!MouseEvent} e Mouse event. * @private */ -Blockly.FieldColour.prototype.onMouseMove_ = function(e) { +FieldColour.prototype.onMouseMove_ = function(e) { const cell = /** @type {!Element} */ (e.target); const index = cell && Number(cell.getAttribute('data-index')); if (index !== null && index !== this.highlightedIndex_) { @@ -456,7 +457,7 @@ Blockly.FieldColour.prototype.onMouseMove_ = function(e) { * Handle a mouse enter event. Focus the picker. * @private */ -Blockly.FieldColour.prototype.onMouseEnter_ = function() { +FieldColour.prototype.onMouseEnter_ = function() { this.picker_.focus({preventScroll:true}); }; @@ -465,7 +466,7 @@ Blockly.FieldColour.prototype.onMouseEnter_ = function() { * the currently highlighted colour. * @private */ -Blockly.FieldColour.prototype.onMouseLeave_ = function() { +FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); const highlighted = this.getHighlighted_(); if (highlighted) { @@ -478,8 +479,8 @@ Blockly.FieldColour.prototype.onMouseLeave_ = function() { * @return {?HTMLElement} Highlighted item (null if none). * @private */ -Blockly.FieldColour.prototype.getHighlighted_ = function() { - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; +FieldColour.prototype.getHighlighted_ = function() { + const columns = this.columns_ || FieldColour.COLUMNS; const x = this.highlightedIndex_ % columns; const y = Math.floor(this.highlightedIndex_ / columns); const row = this.picker_.childNodes[y]; @@ -496,7 +497,7 @@ Blockly.FieldColour.prototype.getHighlighted_ = function() { * @param {number} index the index of the new cell * @private */ -Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { +FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. const highlighted = this.getHighlighted_(); if (highlighted) { @@ -516,10 +517,10 @@ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { * Create a colour picker dropdown editor. * @private */ -Blockly.FieldColour.prototype.dropdownCreate_ = function() { - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; - const colours = this.colours_ || Blockly.FieldColour.COLOURS; - const titles = this.titles_ || Blockly.FieldColour.TITLES; +FieldColour.prototype.dropdownCreate_ = function() { + const columns = this.columns_ || FieldColour.COLUMNS; + const colours = this.colours_ || FieldColour.COLOURS; + const titles = this.titles_ || FieldColour.TITLES; const selectedColour = this.getValue(); // Create the palette. const table = document.createElement('table'); @@ -576,7 +577,7 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { * Disposes of events and DOM-references belonging to the colour editor. * @private */ -Blockly.FieldColour.prototype.dropdownDispose_ = function() { +FieldColour.prototype.dropdownDispose_ = function() { if (this.onClickWrapper_) { Blockly.browserEvents.unbind(this.onClickWrapper_); this.onClickWrapper_ = null; @@ -637,4 +638,6 @@ Blockly.Css.register([ /* eslint-enable indent */ ]); -Blockly.fieldRegistry.register('field_colour', Blockly.FieldColour); +Blockly.fieldRegistry.register('field_colour', FieldColour); + +exports = FieldColour; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..0e33cec9b 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -51,7 +51,7 @@ goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); From ba30031d366e2b7f9af77f1be01c433487d76842 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:13:31 -0700 Subject: [PATCH 181/313] Migrate core/field_colour.js to named requires --- core/field_colour.js | 119 ++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 9d342150c..879c340bc 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -13,20 +13,21 @@ goog.module('Blockly.FieldColour'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.Css'); -goog.require('Blockly.DropDownDiv'); +const Css = goog.require('Blockly.Css'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Field = goog.require('Blockly.Field'); +const IdGenerator = goog.require('Blockly.utils.IdGenerator'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Size = goog.require('Blockly.utils.Size'); +const aria = goog.require('Blockly.utils.aria'); +const colour = goog.require('Blockly.utils.colour'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {addClass, removeClass} = goog.require('Blockly.utils.dom'); +/* eslint-disable-next-line no-unused-vars */ +const {conditionalBind, unbind, Data} = goog.require('Blockly.browserEvents'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.colour'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.IdGenerator'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); /** @@ -35,11 +36,11 @@ goog.require('Blockly.utils.Size'); * '#rrggbb' format. Defaults to the first value in the default colour array. * @param {Function=} opt_validator A function that is called to validate * changes to the field's value. Takes in a colour string & returns a - * validated colour string ('#rrggbb' format), or null to abort the change. + * validated colour string ('#rrggbb' format), or null to abort the change.Blockly. * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldColour = function(opt_value, opt_validator, opt_config) { @@ -62,40 +63,40 @@ const FieldColour = function(opt_value, opt_validator, opt_config) { /** * Mouse click event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onClickWrapper_ = null; /** * Mouse move event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseMoveWrapper_ = null; /** * Mouse enter event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseEnterWrapper_ = null; /** * Mouse leave event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseLeaveWrapper_ = null; /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onKeyDownWrapper_ = null; }; -Blockly.utils.object.inherits(FieldColour, Blockly.Field); +inherits(FieldColour, Field); /** * Construct a FieldColour from a JSON arg object. @@ -175,7 +176,7 @@ FieldColour.prototype.configure_ = function(config) { * @package */ FieldColour.prototype.initView = function() { - this.size_ = new Blockly.utils.Size( + this.size_ = new Size( this.getConstants().FIELD_COLOUR_DEFAULT_WIDTH, this.getConstants().FIELD_COLOUR_DEFAULT_HEIGHT); if (!this.getConstants().FIELD_COLOUR_FULL_BLOCK) { @@ -210,7 +211,7 @@ FieldColour.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } - return Blockly.utils.colour.parse(opt_newValue); + return colour.parse(opt_newValue); }; /** @@ -325,9 +326,9 @@ FieldColour.prototype.setColumns = function(columns) { */ FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); - Blockly.DropDownDiv.getContentDiv().appendChild(this.picker_); + DropDownDiv.getContentDiv().appendChild(this.picker_); - Blockly.DropDownDiv.showPositionedByField( + DropDownDiv.showPositionedByField( this, this.dropdownDispose_.bind(this)); // Focus so we can start receiving keyboard events. @@ -344,7 +345,7 @@ FieldColour.prototype.onClick_ = function(e) { const colour = cell && cell.label; if (colour !== null) { this.setValue(colour); - Blockly.DropDownDiv.hideIfOwner(this); + DropDownDiv.hideIfOwner(this); } }; @@ -356,19 +357,19 @@ FieldColour.prototype.onClick_ = function(e) { */ FieldColour.prototype.onKeyDown_ = function(e) { let handled = false; - if (e.keyCode === Blockly.utils.KeyCodes.UP) { + if (e.keyCode === KeyCodes.UP) { this.moveHighlightBy_(0, -1); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.DOWN) { + } else if (e.keyCode === KeyCodes.DOWN) { this.moveHighlightBy_(0, 1); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.LEFT) { + } else if (e.keyCode === KeyCodes.LEFT) { this.moveHighlightBy_(-1, 0); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.RIGHT) { + } else if (e.keyCode === KeyCodes.RIGHT) { this.moveHighlightBy_(1, 0); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.ENTER) { + } else if (e.keyCode === KeyCodes.ENTER) { // Select the highlighted colour. const highlighted = this.getHighlighted_(); if (highlighted) { @@ -377,7 +378,7 @@ FieldColour.prototype.onKeyDown_ = function(e) { this.setValue(colour); } } - Blockly.DropDownDiv.hideWithoutAnimation(); + DropDownDiv.hideWithoutAnimation(); handled = true; } if (handled) { @@ -470,7 +471,7 @@ FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); const highlighted = this.getHighlighted_(); if (highlighted) { - Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); + removeClass(highlighted, 'blocklyColourHighlighted'); } }; @@ -501,16 +502,16 @@ FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. const highlighted = this.getHighlighted_(); if (highlighted) { - Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); + removeClass(highlighted, 'blocklyColourHighlighted'); } // Highlight new item. - Blockly.utils.dom.addClass(cell, 'blocklyColourHighlighted'); + addClass(cell, 'blocklyColourHighlighted'); // Set new highlighted index. this.highlightedIndex_ = index; // Update accessibility roles. - Blockly.utils.aria.setState(/** @type {!Element} */ (this.picker_), - Blockly.utils.aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); + aria.setState(/** @type {!Element} */ (this.picker_), + aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); }; /** @@ -527,30 +528,30 @@ FieldColour.prototype.dropdownCreate_ = function() { table.className = 'blocklyColourTable'; table.tabIndex = 0; table.dir = 'ltr'; - Blockly.utils.aria.setRole(table, Blockly.utils.aria.Role.GRID); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.EXPANDED, true); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.ROWCOUNT, + aria.setRole(table, aria.Role.GRID); + aria.setState(table, aria.State.EXPANDED, true); + aria.setState(table, aria.State.ROWCOUNT, Math.floor(colours.length / columns)); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.COLCOUNT, + aria.setState(table, aria.State.COLCOUNT, columns); let row; for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { row = document.createElement('tr'); - Blockly.utils.aria.setRole(row, Blockly.utils.aria.Role.ROW); + aria.setRole(row, aria.Role.ROW); table.appendChild(row); } const cell = document.createElement('td'); row.appendChild(cell); cell.label = colours[i]; // This becomes the value, if clicked. cell.title = titles[i] || colours[i]; - cell.id = Blockly.utils.IdGenerator.getNextUniqueId(); + cell.id = IdGenerator.getNextUniqueId(); cell.setAttribute('data-index', i); - Blockly.utils.aria.setRole(cell, Blockly.utils.aria.Role.GRIDCELL); - Blockly.utils.aria.setState(cell, - Blockly.utils.aria.State.LABEL, colours[i]); - Blockly.utils.aria.setState(cell, - Blockly.utils.aria.State.SELECTED, colours[i] == selectedColour); + aria.setRole(cell, aria.Role.GRIDCELL); + aria.setState(cell, + aria.State.LABEL, colours[i]); + aria.setState(cell, + aria.State.SELECTED, colours[i] == selectedColour); cell.style.backgroundColor = colours[i]; if (colours[i] == selectedColour) { cell.className = 'blocklyColourSelected'; @@ -559,15 +560,15 @@ FieldColour.prototype.dropdownCreate_ = function() { } // Configure event handler on the table to listen for any event in a cell. - this.onClickWrapper_ = Blockly.browserEvents.conditionalBind( + this.onClickWrapper_ = conditionalBind( table, 'click', this, this.onClick_, true); - this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseMoveWrapper_ = conditionalBind( table, 'mousemove', this, this.onMouseMove_, true); - this.onMouseEnterWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseEnterWrapper_ = conditionalBind( table, 'mouseenter', this, this.onMouseEnter_, true); - this.onMouseLeaveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseLeaveWrapper_ = conditionalBind( table, 'mouseleave', this, this.onMouseLeave_, true); - this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownWrapper_ = conditionalBind( table, 'keydown', this, this.onKeyDown_); this.picker_ = table; @@ -579,23 +580,23 @@ FieldColour.prototype.dropdownCreate_ = function() { */ FieldColour.prototype.dropdownDispose_ = function() { if (this.onClickWrapper_) { - Blockly.browserEvents.unbind(this.onClickWrapper_); + unbind(this.onClickWrapper_); this.onClickWrapper_ = null; } if (this.onMouseMoveWrapper_) { - Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); + unbind(this.onMouseMoveWrapper_); this.onMouseMoveWrapper_ = null; } if (this.onMouseEnterWrapper_) { - Blockly.browserEvents.unbind(this.onMouseEnterWrapper_); + unbind(this.onMouseEnterWrapper_); this.onMouseEnterWrapper_ = null; } if (this.onMouseLeaveWrapper_) { - Blockly.browserEvents.unbind(this.onMouseLeaveWrapper_); + unbind(this.onMouseLeaveWrapper_); this.onMouseLeaveWrapper_ = null; } if (this.onKeyDownWrapper_) { - Blockly.browserEvents.unbind(this.onKeyDownWrapper_); + unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; } this.picker_ = null; @@ -605,7 +606,7 @@ FieldColour.prototype.dropdownDispose_ = function() { /** * CSS for colour picker. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyColourTable {', 'border-collapse: collapse;', @@ -638,6 +639,6 @@ Blockly.Css.register([ /* eslint-enable indent */ ]); -Blockly.fieldRegistry.register('field_colour', FieldColour); +fieldRegistry.register('field_colour', FieldColour); exports = FieldColour; From 595f3c0802ce404b8d8987c747278acc1c1c339d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:17:10 -0700 Subject: [PATCH 182/313] clang-format core/field_colour.js --- core/field_colour.js | 57 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 879c340bc..a3dc0bf72 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -36,9 +36,11 @@ goog.require('Blockly.Events.BlockChange'); * '#rrggbb' format. Defaults to the first value in the default colour array. * @param {Function=} opt_validator A function that is called to validate * changes to the field's value. Takes in a colour string & returns a - * validated colour string ('#rrggbb' format), or null to abort the change.Blockly. + * validated colour string ('#rrggbb' format), or null to abort the + * change.Blockly. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -328,11 +330,10 @@ FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); DropDownDiv.getContentDiv().appendChild(this.picker_); - DropDownDiv.showPositionedByField( - this, this.dropdownDispose_.bind(this)); + DropDownDiv.showPositionedByField(this, this.dropdownDispose_.bind(this)); // Focus so we can start receiving keyboard events. - this.picker_.focus({preventScroll:true}); + this.picker_.focus({preventScroll: true}); }; /** @@ -416,8 +417,7 @@ FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } else if (dx > 0) { // Move right one grid cell, even in RTL. // Loop to the start of the next row, if there's room. - if (x > columns - 1 && - y < Math.floor(colours.length / columns) - 1) { + if (x > columns - 1 && y < Math.floor(colours.length / columns) - 1) { x = 0; y++; } else if (x > columns - 1) { @@ -436,7 +436,8 @@ FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } // Move the highlight to the new coordinates. - const cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); + const cell = + /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); const index = (y * columns) + x; this.setHighlightedCell_(cell, index); }; @@ -459,7 +460,7 @@ FieldColour.prototype.onMouseMove_ = function(e) { * @private */ FieldColour.prototype.onMouseEnter_ = function() { - this.picker_.focus({preventScroll:true}); + this.picker_.focus({preventScroll: true}); }; /** @@ -510,8 +511,9 @@ FieldColour.prototype.setHighlightedCell_ = function(cell, index) { this.highlightedIndex_ = index; // Update accessibility roles. - aria.setState(/** @type {!Element} */ (this.picker_), - aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); + aria.setState( + /** @type {!Element} */ (this.picker_), aria.State.ACTIVEDESCENDANT, + cell.getAttribute('id')); }; /** @@ -530,10 +532,9 @@ FieldColour.prototype.dropdownCreate_ = function() { table.dir = 'ltr'; aria.setRole(table, aria.Role.GRID); aria.setState(table, aria.State.EXPANDED, true); - aria.setState(table, aria.State.ROWCOUNT, - Math.floor(colours.length / columns)); - aria.setState(table, aria.State.COLCOUNT, - columns); + aria.setState( + table, aria.State.ROWCOUNT, Math.floor(colours.length / columns)); + aria.setState(table, aria.State.COLCOUNT, columns); let row; for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { @@ -548,10 +549,8 @@ FieldColour.prototype.dropdownCreate_ = function() { cell.id = IdGenerator.getNextUniqueId(); cell.setAttribute('data-index', i); aria.setRole(cell, aria.Role.GRIDCELL); - aria.setState(cell, - aria.State.LABEL, colours[i]); - aria.setState(cell, - aria.State.SELECTED, colours[i] == selectedColour); + aria.setState(cell, aria.State.LABEL, colours[i]); + aria.setState(cell, aria.State.SELECTED, colours[i] == selectedColour); cell.style.backgroundColor = colours[i]; if (colours[i] == selectedColour) { cell.className = 'blocklyColourSelected'; @@ -560,16 +559,16 @@ FieldColour.prototype.dropdownCreate_ = function() { } // Configure event handler on the table to listen for any event in a cell. - this.onClickWrapper_ = conditionalBind( - table, 'click', this, this.onClick_, true); - this.onMouseMoveWrapper_ = conditionalBind( - table, 'mousemove', this, this.onMouseMove_, true); - this.onMouseEnterWrapper_ = conditionalBind( - table, 'mouseenter', this, this.onMouseEnter_, true); - this.onMouseLeaveWrapper_ = conditionalBind( - table, 'mouseleave', this, this.onMouseLeave_, true); - this.onKeyDownWrapper_ = conditionalBind( - table, 'keydown', this, this.onKeyDown_); + this.onClickWrapper_ = + conditionalBind(table, 'click', this, this.onClick_, true); + this.onMouseMoveWrapper_ = + conditionalBind(table, 'mousemove', this, this.onMouseMove_, true); + this.onMouseEnterWrapper_ = + conditionalBind(table, 'mouseenter', this, this.onMouseEnter_, true); + this.onMouseLeaveWrapper_ = + conditionalBind(table, 'mouseleave', this, this.onMouseLeave_, true); + this.onKeyDownWrapper_ = + conditionalBind(table, 'keydown', this, this.onKeyDown_); this.picker_ = table; }; From 0d248583c8e542cf979a1e4e14117a4b94113bb1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:26:52 -0700 Subject: [PATCH 183/313] Migrate core/field_dropdown.js to ES6 const/let --- core/field_dropdown.js | 102 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 5dad752d8..c1554928d 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -299,14 +299,14 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { } // Element gets created in render. this.menu_.render(Blockly.DropDownDiv.getContentDiv()); - var menuElement = /** @type {!Element} */ (this.menu_.getElement()); + const menuElement = /** @type {!Element} */ (this.menu_.getElement()); Blockly.utils.dom.addClass(menuElement, 'blocklyDropdownMenu'); if (this.getConstants().FIELD_DROPDOWN_COLOURED_DIV) { - var primaryColour = (this.sourceBlock_.isShadow()) ? + const primaryColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().getColour() : this.sourceBlock_.getColour(); - var borderColour = (this.sourceBlock_.isShadow()) ? + const borderColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; Blockly.DropDownDiv.setColour(primaryColour, borderColour); @@ -332,23 +332,23 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { * @private */ Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { - var menu = new Blockly.Menu(); + const menu = new Blockly.Menu(); menu.setRole(Blockly.utils.aria.Role.LISTBOX); this.menu_ = menu; - var options = this.getOptions(false); + const options = this.getOptions(false); this.selectedMenuItem_ = null; - for (var i = 0; i < options.length; i++) { - var content = options[i][0]; // Human-readable text or image. - var value = options[i][1]; // Language-neutral value. + for (let i = 0; i < options.length; i++) { + let content = options[i][0]; // Human-readable text or image. + const value = options[i][1]; // Language-neutral value. if (typeof content == 'object') { // An image, not text. - var image = new Image(content['width'], content['height']); + const image = new Image(content['width'], content['height']); image.src = content['src']; image.alt = content['alt'] || ''; content = image; } - var menuItem = new Blockly.MenuItem(content, value); + const menuItem = new Blockly.MenuItem(content, value); menuItem.setRole(Blockly.utils.aria.Role.OPTION); menuItem.setRightToLeft(this.sourceBlock_.RTL); menuItem.setCheckable(true); @@ -400,15 +400,15 @@ Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { * @private */ Blockly.FieldDropdown.prototype.trimOptions_ = function() { - var options = this.menuGenerator_; + const options = this.menuGenerator_; if (!Array.isArray(options)) { return; } - var hasImages = false; + let hasImages = false; // Localize label text and image alt text. - for (var i = 0; i < options.length; i++) { - var label = options[i][0]; + for (let i = 0; i < options.length; i++) { + const label = options[i][0]; if (typeof label == 'string') { options[i][0] = Blockly.utils.replaceMessageReferences(label); } else { @@ -421,13 +421,13 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { if (hasImages || options.length < 2) { return; // Do nothing if too few items or at least one label is an image. } - var strings = []; - for (var i = 0; i < options.length; i++) { + const strings = []; + for (let i = 0; i < options.length; i++) { strings.push(options[i][0]); } - var shortest = Blockly.utils.string.shortestStringLength(strings); - var prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); - var suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); + const shortest = Blockly.utils.string.shortestStringLength(strings); + const prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); + const suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); if (!prefixLength && !suffixLength) { return; } @@ -457,11 +457,11 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { */ Blockly.FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { - var newOptions = []; + const newOptions = []; // Remove the prefix and suffix from the options. - for (var i = 0; i < options.length; i++) { - var text = options[i][0]; - var value = options[i][1]; + for (let i = 0; i < options.length; i++) { + let text = options[i][0]; + const value = options[i][1]; text = text.substring(prefixLength, text.length - suffixLength); newOptions[i] = [text, value]; } @@ -502,9 +502,9 @@ Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { * @protected */ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { - var isValueValid = false; - var options = this.getOptions(true); - for (var i = 0, option; (option = options[i]); i++) { + let isValueValid = false; + const options = this.getOptions(true); + for (let i = 0, option; (option = options[i]); i++) { // Options are tuples of human-readable text and language-neutral values. if (option[1] == opt_newValue) { isValueValid = true; @@ -530,8 +530,8 @@ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { */ Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { Blockly.FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); - var options = this.getOptions(true); - for (var i = 0, option; (option = options[i]); i++) { + const options = this.getOptions(true); + for (let i = 0, option; (option = options[i]); i++) { if (option[1] == this.value_) { this.selectedOption_ = option; } @@ -573,7 +573,7 @@ Blockly.FieldDropdown.prototype.render_ = function() { this.imageElement_.style.display = 'none'; // Show correct element. - var option = this.selectedOption_ && this.selectedOption_[0]; + const option = this.selectedOption_ && this.selectedOption_[0]; if (option && typeof option == 'object') { this.renderSelectedImage_( /** @type {!Blockly.FieldDropdown.ImageProperties} */ (option)); @@ -597,16 +597,16 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); - var imageHeight = Number(imageJson.height); - var imageWidth = Number(imageJson.width); + const imageHeight = Number(imageJson.height); + const imageWidth = Number(imageJson.width); // Height and width include the border rect. - var hasBorder = !!this.borderRect_; - var height = Math.max( + const hasBorder = !!this.borderRect_; + const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, imageHeight + Blockly.FieldDropdown.IMAGE_Y_PADDING); - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var arrowWidth = 0; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + let arrowWidth = 0; if (this.svgArrow_) { arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); @@ -620,9 +620,9 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.size_.width = imageWidth + arrowWidth + xPadding * 2; this.size_.height = height; - var arrowX = 0; + let arrowX = 0; if (this.sourceBlock_.RTL) { - var imageX = xPadding + arrowWidth; + const imageX = xPadding + arrowWidth; this.imageElement_.setAttribute('x', imageX); } else { arrowX = imageWidth + arrowWidth; @@ -646,16 +646,16 @@ Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { this.textElement_.setAttribute('text-anchor', 'start'); // Height and width include the border rect. - var hasBorder = !!this.borderRect_; - var height = Math.max( + const hasBorder = !!this.borderRect_; + const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - var textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + const textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var arrowWidth = 0; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + let arrowWidth = 0; if (this.svgArrow_) { arrowWidth = this.positionSVGArrow_(textWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); @@ -677,11 +677,11 @@ Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { if (!this.svgArrow_) { return 0; } - var hasBorder = !!this.borderRect_; - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; - var svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; - var arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; + const hasBorder = !!this.borderRect_; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; + const svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; + const arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; this.svgArrow_.setAttribute('transform', 'translate(' + arrowX + ',' + y + ')'); return svgArrowSize + textPadding; @@ -699,7 +699,7 @@ Blockly.FieldDropdown.prototype.getText_ = function() { if (!this.selectedOption_) { return null; } - var option = this.selectedOption_[0]; + const option = this.selectedOption_[0]; if (typeof option == 'object') { return option['alt']; } @@ -719,9 +719,9 @@ Blockly.FieldDropdown.validateOptions_ = function(options) { if (!options.length) { throw TypeError('FieldDropdown options must not be an empty array.'); } - var foundError = false; - for (var i = 0; i < options.length; ++i) { - var tuple = options[i]; + let foundError = false; + for (let i = 0; i < options.length; ++i) { + const tuple = options[i]; if (!Array.isArray(tuple)) { foundError = true; console.error( From 5f213b48a691992489b6de9df8560637aad2a712 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:30:06 -0700 Subject: [PATCH 184/313] Migrate core/field_dropdown.js to goog.module --- core/field_dropdown.js | 101 +++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index c1554928d..be6c38e98 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldDropdown'); +goog.module('Blockly.FieldDropdown'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.Field'); @@ -44,16 +45,16 @@ goog.require('Blockly.utils.userAgent'); * @constructor * @throws {TypeError} If `menuGenerator` options are incorrectly structured. */ -Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { +const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { if (typeof menuGenerator != 'function') { - Blockly.FieldDropdown.validateOptions_(menuGenerator); + FieldDropdown.validateOptions_(menuGenerator); } /** * An array of options for a dropdown list, * or a function which generates these options. * @type {(!Array| - * !function(this:Blockly.FieldDropdown): !Array)} + * !function(this:FieldDropdown): !Array)} * @protected */ this.menuGenerator_ = menuGenerator; @@ -90,7 +91,7 @@ Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { this.selectedOption_ = this.getOptions(false)[0]; // Call parent's constructor. - Blockly.FieldDropdown.superClass_.constructor.call( + FieldDropdown.superClass_.constructor.call( this, this.selectedOption_[1], opt_validator, opt_config); /** @@ -128,7 +129,7 @@ Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { */ this.svgArrow_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldDropdown, Blockly.Field); +Blockly.utils.object.inherits(FieldDropdown, Blockly.Field); /** * Dropdown image properties. @@ -139,16 +140,16 @@ Blockly.utils.object.inherits(Blockly.FieldDropdown, Blockly.Field); * height:number * }} */ -Blockly.FieldDropdown.ImageProperties; +FieldDropdown.ImageProperties; /** * Construct a FieldDropdown from a JSON arg object. * @param {!Object} options A JSON object with options (options). - * @return {!Blockly.FieldDropdown} The new field instance. + * @return {!FieldDropdown} The new field instance. * @package * @nocollapse */ -Blockly.FieldDropdown.fromJson = function(options) { +FieldDropdown.fromJson = function(options) { // `this` might be a subclass of FieldDropdown if that class doesn't override // the static fromJson method. return new this(options['options'], undefined, options); @@ -161,7 +162,7 @@ Blockly.FieldDropdown.fromJson = function(options) { * field's state. * @package */ -Blockly.FieldDropdown.prototype.fromXml = function(fieldElement) { +FieldDropdown.prototype.fromXml = function(fieldElement) { if (this.isOptionListDynamic()) { this.getOptions(false); } @@ -173,17 +174,17 @@ Blockly.FieldDropdown.prototype.fromXml = function(fieldElement) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldDropdown.prototype.SERIALIZABLE = true; +FieldDropdown.prototype.SERIALIZABLE = true; /** * Horizontal distance that a checkmark overhangs the dropdown. */ -Blockly.FieldDropdown.CHECKMARK_OVERHANG = 25; +FieldDropdown.CHECKMARK_OVERHANG = 25; /** * Maximum height of the dropdown menu, as a percentage of the viewport height. */ -Blockly.FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; +FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; /** * The y offset from the top of the field to the top of the image, if an image @@ -192,7 +193,7 @@ Blockly.FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; * @const * @private */ -Blockly.FieldDropdown.IMAGE_Y_OFFSET = 5; +FieldDropdown.IMAGE_Y_OFFSET = 5; /** * The total vertical padding above and below an image. @@ -200,25 +201,25 @@ Blockly.FieldDropdown.IMAGE_Y_OFFSET = 5; * @const * @private */ -Blockly.FieldDropdown.IMAGE_Y_PADDING = - Blockly.FieldDropdown.IMAGE_Y_OFFSET * 2; +FieldDropdown.IMAGE_Y_PADDING = + FieldDropdown.IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "▾", so use "▼" instead. */ -Blockly.FieldDropdown.ARROW_CHAR = +FieldDropdown.ARROW_CHAR = Blockly.utils.userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldDropdown.prototype.CURSOR = 'default'; +FieldDropdown.prototype.CURSOR = 'default'; /** * Create the block UI for this dropdown. * @package */ -Blockly.FieldDropdown.prototype.initView = function() { +FieldDropdown.prototype.initView = function() { if (this.shouldAddBorderRect_()) { this.createBorderRect_(); } else { @@ -245,7 +246,7 @@ Blockly.FieldDropdown.prototype.initView = function() { * @return {boolean} True if the dropdown field should add a border rect. * @protected */ -Blockly.FieldDropdown.prototype.shouldAddBorderRect_ = function() { +FieldDropdown.prototype.shouldAddBorderRect_ = function() { return !this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || (this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW && !this.sourceBlock_.isShadow()); @@ -255,13 +256,13 @@ Blockly.FieldDropdown.prototype.shouldAddBorderRect_ = function() { * Create a tspan based arrow. * @protected */ -Blockly.FieldDropdown.prototype.createTextArrow_ = function() { +FieldDropdown.prototype.createTextArrow_ = function() { this.arrow_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( this.sourceBlock_.RTL ? - Blockly.FieldDropdown.ARROW_CHAR + ' ' : - ' ' + Blockly.FieldDropdown.ARROW_CHAR)); + FieldDropdown.ARROW_CHAR + ' ' : + ' ' + FieldDropdown.ARROW_CHAR)); if (this.sourceBlock_.RTL) { this.textElement_.insertBefore(this.arrow_, this.textContent_); } else { @@ -273,7 +274,7 @@ Blockly.FieldDropdown.prototype.createTextArrow_ = function() { * Create an SVG based arrow. * @protected */ -Blockly.FieldDropdown.prototype.createSVGArrow_ = function() { +FieldDropdown.prototype.createSVGArrow_ = function() { this.svgArrow_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', @@ -289,7 +290,7 @@ Blockly.FieldDropdown.prototype.createSVGArrow_ = function() { * or undefined if triggered programmatically. * @protected */ -Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { +FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { this.menu_.openingCoords = @@ -331,7 +332,7 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { * Create the dropdown editor. * @private */ -Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { +FieldDropdown.prototype.dropdownCreate_ = function() { const menu = new Blockly.Menu(); menu.setRole(Blockly.utils.aria.Role.LISTBOX); this.menu_ = menu; @@ -365,7 +366,7 @@ Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { * Disposes of events and DOM-references belonging to the dropdown editor. * @private */ -Blockly.FieldDropdown.prototype.dropdownDispose_ = function() { +FieldDropdown.prototype.dropdownDispose_ = function() { if (this.menu_) { this.menu_.dispose(); } @@ -379,7 +380,7 @@ Blockly.FieldDropdown.prototype.dropdownDispose_ = function() { * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. * @private */ -Blockly.FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { +FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { Blockly.DropDownDiv.hideIfOwner(this, true); this.onItemSelected_(/** @type {!Blockly.Menu} */ (this.menu_), menuItem); }; @@ -390,7 +391,7 @@ Blockly.FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. * @protected */ -Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { +FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { this.setValue(menuItem.getValue()); }; @@ -399,7 +400,7 @@ Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { * Create prefix and/or suffix labels. * @private */ -Blockly.FieldDropdown.prototype.trimOptions_ = function() { +FieldDropdown.prototype.trimOptions_ = function() { const options = this.menuGenerator_; if (!Array.isArray(options)) { return; @@ -442,7 +443,7 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { this.suffixField = strings[0].substr(1 - suffixLength); } - this.menuGenerator_ = Blockly.FieldDropdown.applyTrim_(options, prefixLength, + this.menuGenerator_ = FieldDropdown.applyTrim_(options, prefixLength, suffixLength); }; @@ -455,7 +456,7 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { * @param {number} suffixLength The length of the common suffix * @return {!Array} A new array with all of the option text trimmed. */ -Blockly.FieldDropdown.applyTrim_ = function(options, +FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { const newOptions = []; // Remove the prefix and suffix from the options. @@ -472,7 +473,7 @@ Blockly.FieldDropdown.applyTrim_ = function(options, * @return {boolean} True if the option list is generated by a function. * Otherwise false. */ -Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { +FieldDropdown.prototype.isOptionListDynamic = function() { return typeof this.menuGenerator_ == 'function'; }; @@ -484,11 +485,11 @@ Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { * (human-readable text or image, language-neutral name). * @throws {TypeError} If generated options are incorrectly structured. */ -Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { +FieldDropdown.prototype.getOptions = function(opt_useCache) { if (this.isOptionListDynamic()) { if (!this.generatedOptions_ || !opt_useCache) { this.generatedOptions_ = this.menuGenerator_.call(this); - Blockly.FieldDropdown.validateOptions_(this.generatedOptions_); + FieldDropdown.validateOptions_(this.generatedOptions_); } return this.generatedOptions_; } @@ -501,7 +502,7 @@ Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { * @return {?string} A valid language-neutral option, or null if invalid. * @protected */ -Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { +FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { let isValueValid = false; const options = this.getOptions(true); for (let i = 0, option; (option = options[i]); i++) { @@ -528,8 +529,8 @@ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { * that this is one of the valid dropdown options. * @protected */ -Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { - Blockly.FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); +FieldDropdown.prototype.doValueUpdate_ = function(newValue) { + FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); const options = this.getOptions(true); for (let i = 0, option; (option = options[i]); i++) { if (option[1] == this.value_) { @@ -542,7 +543,7 @@ Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { * Updates the dropdown arrow to match the colour/style of the block. * @package */ -Blockly.FieldDropdown.prototype.applyColour = function() { +FieldDropdown.prototype.applyColour = function() { if (this.borderRect_) { this.borderRect_.setAttribute('stroke', this.sourceBlock_.style.colourTertiary); @@ -567,7 +568,7 @@ Blockly.FieldDropdown.prototype.applyColour = function() { * Draws the border with the correct width. * @protected */ -Blockly.FieldDropdown.prototype.render_ = function() { +FieldDropdown.prototype.render_ = function() { // Hide both elements. this.textContent_.nodeValue = ''; this.imageElement_.style.display = 'none'; @@ -576,7 +577,7 @@ Blockly.FieldDropdown.prototype.render_ = function() { const option = this.selectedOption_ && this.selectedOption_[0]; if (option && typeof option == 'object') { this.renderSelectedImage_( - /** @type {!Blockly.FieldDropdown.ImageProperties} */ (option)); + /** @type {!FieldDropdown.ImageProperties} */ (option)); } else { this.renderSelectedText_(); } @@ -586,11 +587,11 @@ Blockly.FieldDropdown.prototype.render_ = function() { /** * Renders the selected option, which must be an image. - * @param {!Blockly.FieldDropdown.ImageProperties} imageJson Selected + * @param {!FieldDropdown.ImageProperties} imageJson Selected * option that must be an image. * @private */ -Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { +FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; this.imageElement_.setAttributeNS( Blockly.utils.dom.XLINK_NS, 'xlink:href', imageJson.src); @@ -604,7 +605,7 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const hasBorder = !!this.borderRect_; const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, - imageHeight + Blockly.FieldDropdown.IMAGE_Y_PADDING); + imageHeight + FieldDropdown.IMAGE_Y_PADDING); const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { @@ -638,7 +639,7 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { * Renders the selected option, which must be text. * @private */ -Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { +FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); Blockly.utils.dom.addClass(/** @type {!Element} */ (this.textElement_), @@ -673,7 +674,7 @@ Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { * @return {number} Amount of space the arrow is taking up, in px. * @private */ -Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { +FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { if (!this.svgArrow_) { return 0; } @@ -695,7 +696,7 @@ Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { * @protected * @override */ -Blockly.FieldDropdown.prototype.getText_ = function() { +FieldDropdown.prototype.getText_ = function() { if (!this.selectedOption_) { return null; } @@ -712,7 +713,7 @@ Blockly.FieldDropdown.prototype.getText_ = function() { * @throws {TypeError} If proposed options are incorrectly structured. * @private */ -Blockly.FieldDropdown.validateOptions_ = function(options) { +FieldDropdown.validateOptions_ = function(options) { if (!Array.isArray(options)) { throw TypeError('FieldDropdown options must be an array.'); } @@ -747,4 +748,6 @@ Blockly.FieldDropdown.validateOptions_ = function(options) { } }; -Blockly.fieldRegistry.register('field_dropdown', Blockly.FieldDropdown); +Blockly.fieldRegistry.register('field_dropdown', FieldDropdown); + +exports = FieldDropdown; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..65e09fda9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -52,7 +52,7 @@ goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownD goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); From 393cdf1fa4d5a94a083755b4037e5beac28f2f6a Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:18:05 -0700 Subject: [PATCH 185/313] Switch from destructuring to normal imports in core/field_checkbox.js --- core/field_checkbox.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 3cbe8d07f..d2ce60eaa 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -14,9 +14,9 @@ goog.module('Blockly.FieldCheckbox'); goog.module.declareLegacyNamespace(); const Field = goog.require('Blockly.Field'); -const {addClass} = goog.require('Blockly.utils.dom'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); const {inherits} = goog.require('Blockly.utils.object'); -const {register} = goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); @@ -109,7 +109,7 @@ FieldCheckbox.prototype.configure_ = function(config) { FieldCheckbox.prototype.initView = function() { FieldCheckbox.superClass_.initView.call(this); - addClass( + dom.addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); this.textElement_.style.display = this.value_ ? 'block' : 'none'; }; @@ -221,6 +221,6 @@ FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -register('field_checkbox', FieldCheckbox); +fieldRegistry.register('field_checkbox', FieldCheckbox); exports = FieldCheckbox; From 36bb605bbc9f362a2bbf435048c420bf763ef397 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:53:44 -0700 Subject: [PATCH 186/313] Migrate core/field_dropdown.js to named requires --- core/field_dropdown.js | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index be6c38e98..5a5234c90 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -15,19 +15,19 @@ goog.module('Blockly.FieldDropdown'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.Menu'); -goog.require('Blockly.MenuItem'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.string'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Field = goog.require('Blockly.Field'); +const Menu = goog.require('Blockly.Menu'); +const MenuItem = goog.require('Blockly.MenuItem'); +const Svg = goog.require('Blockly.utils.Svg'); +const aria = goog.require('Blockly.utils.aria'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {commonWordPrefix, commonWordSuffix, shortestStringLength} = goog.require('Blockly.utils.string'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -41,7 +41,7 @@ goog.require('Blockly.utils.userAgent'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor * @throws {TypeError} If `menuGenerator` options are incorrectly structured. */ @@ -96,14 +96,14 @@ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { /** * A reference to the currently selected menu item. - * @type {?Blockly.MenuItem} + * @type {?MenuItem} * @private */ this.selectedMenuItem_ = null; /** * The dropdown menu. - * @type {?Blockly.Menu} + * @type {?Menu} * @protected */ this.menu_ = null; @@ -129,7 +129,7 @@ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { */ this.svgArrow_ = null; }; -Blockly.utils.object.inherits(FieldDropdown, Blockly.Field); +inherits(FieldDropdown, Field); /** * Dropdown image properties. @@ -208,7 +208,7 @@ FieldDropdown.IMAGE_Y_PADDING = * Android can't (in 2014) display "▾", so use "▼" instead. */ FieldDropdown.ARROW_CHAR = - Blockly.utils.userAgent.ANDROID ? '\u25BC' : '\u25BE'; + userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. @@ -227,8 +227,8 @@ FieldDropdown.prototype.initView = function() { } this.createTextElement_(); - this.imageElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, {}, this.fieldGroup_); + this.imageElement_ = dom.createSvgElement( + Svg.IMAGE, {}, this.fieldGroup_); if (this.getConstants().FIELD_DROPDOWN_SVG_ARROW) { this.createSVGArrow_(); @@ -237,7 +237,7 @@ FieldDropdown.prototype.initView = function() { } if (this.borderRect_) { - Blockly.utils.dom.addClass(this.borderRect_, 'blocklyDropdownRect'); + dom.addClass(this.borderRect_, 'blocklyDropdownRect'); } }; @@ -257,8 +257,8 @@ FieldDropdown.prototype.shouldAddBorderRect_ = function() { * @protected */ FieldDropdown.prototype.createTextArrow_ = function() { - this.arrow_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TSPAN, {}, this.textElement_); + this.arrow_ = dom.createSvgElement( + Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + ' ' : @@ -275,12 +275,12 @@ FieldDropdown.prototype.createTextArrow_ = function() { * @protected */ FieldDropdown.prototype.createSVGArrow_ = function() { - this.svgArrow_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { + this.svgArrow_ = dom.createSvgElement( + Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', 'width': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px' }, this.fieldGroup_); - this.svgArrow_.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.svgArrow_.setAttributeNS(dom.XLINK_NS, 'xlink:href', this.getConstants().FIELD_DROPDOWN_SVG_ARROW_DATAURI); }; @@ -294,14 +294,14 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { this.menu_.openingCoords = - new Blockly.utils.Coordinate(opt_e.clientX, opt_e.clientY); + new Coordinate(opt_e.clientX, opt_e.clientY); } else { this.menu_.openingCoords = null; } // Element gets created in render. - this.menu_.render(Blockly.DropDownDiv.getContentDiv()); + this.menu_.render(DropDownDiv.getContentDiv()); const menuElement = /** @type {!Element} */ (this.menu_.getElement()); - Blockly.utils.dom.addClass(menuElement, 'blocklyDropdownMenu'); + dom.addClass(menuElement, 'blocklyDropdownMenu'); if (this.getConstants().FIELD_DROPDOWN_COLOURED_DIV) { const primaryColour = (this.sourceBlock_.isShadow()) ? @@ -310,10 +310,10 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { const borderColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; - Blockly.DropDownDiv.setColour(primaryColour, borderColour); + DropDownDiv.setColour(primaryColour, borderColour); } - Blockly.DropDownDiv.showPositionedByField( + DropDownDiv.showPositionedByField( this, this.dropdownDispose_.bind(this)); // Focusing needs to be handled after the menu is rendered and positioned. @@ -333,8 +333,8 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { * @private */ FieldDropdown.prototype.dropdownCreate_ = function() { - const menu = new Blockly.Menu(); - menu.setRole(Blockly.utils.aria.Role.LISTBOX); + const menu = new Menu(); + menu.setRole(aria.Role.LISTBOX); this.menu_ = menu; const options = this.getOptions(false); @@ -349,8 +349,8 @@ FieldDropdown.prototype.dropdownCreate_ = function() { image.alt = content['alt'] || ''; content = image; } - const menuItem = new Blockly.MenuItem(content, value); - menuItem.setRole(Blockly.utils.aria.Role.OPTION); + const menuItem = new MenuItem(content, value); + menuItem.setRole(aria.Role.OPTION); menuItem.setRightToLeft(this.sourceBlock_.RTL); menuItem.setCheckable(true); menu.addChild(menuItem); @@ -377,18 +377,18 @@ FieldDropdown.prototype.dropdownDispose_ = function() { /** * Handle an action in the dropdown menu. - * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. + * @param {!MenuItem} menuItem The MenuItem selected within menu. * @private */ FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { - Blockly.DropDownDiv.hideIfOwner(this, true); - this.onItemSelected_(/** @type {!Blockly.Menu} */ (this.menu_), menuItem); + DropDownDiv.hideIfOwner(this, true); + this.onItemSelected_(/** @type {!Menu} */ (this.menu_), menuItem); }; /** * Handle the selection of an item in the dropdown menu. - * @param {!Blockly.Menu} menu The Menu component clicked. - * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. + * @param {!Menu} menu The Menu component clicked. + * @param {!MenuItem} menuItem The MenuItem selected within menu. * @protected */ FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { @@ -411,10 +411,10 @@ FieldDropdown.prototype.trimOptions_ = function() { for (let i = 0; i < options.length; i++) { const label = options[i][0]; if (typeof label == 'string') { - options[i][0] = Blockly.utils.replaceMessageReferences(label); + options[i][0] = replaceMessageReferences(label); } else { if (label.alt != null) { - options[i][0].alt = Blockly.utils.replaceMessageReferences(label.alt); + options[i][0].alt = replaceMessageReferences(label.alt); } hasImages = true; } @@ -426,9 +426,9 @@ FieldDropdown.prototype.trimOptions_ = function() { for (let i = 0; i < options.length; i++) { strings.push(options[i][0]); } - const shortest = Blockly.utils.string.shortestStringLength(strings); - const prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); - const suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); + const shortest = shortestStringLength(strings); + const prefixLength = commonWordPrefix(strings, shortest); + const suffixLength = commonWordSuffix(strings, shortest); if (!prefixLength && !suffixLength) { return; } @@ -594,7 +594,7 @@ FieldDropdown.prototype.render_ = function() { FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; this.imageElement_.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', imageJson.src); + dom.XLINK_NS, 'xlink:href', imageJson.src); this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); @@ -612,7 +612,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } else { - arrowWidth = Blockly.utils.dom.getFastTextWidth( + arrowWidth = dom.getFastTextWidth( /** @type {!SVGTSpanElement} */ (this.arrow_), this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, @@ -642,7 +642,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); - Blockly.utils.dom.addClass(/** @type {!Element} */ (this.textElement_), + dom.addClass(/** @type {!Element} */ (this.textElement_), 'blocklyDropdownText'); this.textElement_.setAttribute('text-anchor', 'start'); @@ -651,7 +651,7 @@ FieldDropdown.prototype.renderSelectedText_ = function() { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - const textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + const textWidth = dom.getFastTextWidth(this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); @@ -748,6 +748,6 @@ FieldDropdown.validateOptions_ = function(options) { } }; -Blockly.fieldRegistry.register('field_dropdown', FieldDropdown); +fieldRegistry.register('field_dropdown', FieldDropdown); exports = FieldDropdown; From 740e4651b178dfbcbe6ab07930896ee3ccf10834 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:56:32 -0700 Subject: [PATCH 187/313] clang-format core/field_dropdown.js --- core/field_dropdown.js | 118 +++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 5a5234c90..79b6ea404 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -39,7 +39,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * option & returns a validated language-neutral dropdown option, or null to * abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -134,12 +135,12 @@ inherits(FieldDropdown, Field); /** * Dropdown image properties. * @typedef {{ - * src:string, - * alt:string, - * width:number, - * height:number - * }} - */ + * src:string, + * alt:string, + * width:number, + * height:number + * }} + */ FieldDropdown.ImageProperties; /** @@ -201,14 +202,12 @@ FieldDropdown.IMAGE_Y_OFFSET = 5; * @const * @private */ -FieldDropdown.IMAGE_Y_PADDING = - FieldDropdown.IMAGE_Y_OFFSET * 2; +FieldDropdown.IMAGE_Y_PADDING = FieldDropdown.IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "▾", so use "▼" instead. */ -FieldDropdown.ARROW_CHAR = - userAgent.ANDROID ? '\u25BC' : '\u25BE'; +FieldDropdown.ARROW_CHAR = userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. @@ -227,8 +226,7 @@ FieldDropdown.prototype.initView = function() { } this.createTextElement_(); - this.imageElement_ = dom.createSvgElement( - Svg.IMAGE, {}, this.fieldGroup_); + this.imageElement_ = dom.createSvgElement(Svg.IMAGE, {}, this.fieldGroup_); if (this.getConstants().FIELD_DROPDOWN_SVG_ARROW) { this.createSVGArrow_(); @@ -249,7 +247,7 @@ FieldDropdown.prototype.initView = function() { FieldDropdown.prototype.shouldAddBorderRect_ = function() { return !this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || (this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW && - !this.sourceBlock_.isShadow()); + !this.sourceBlock_.isShadow()); }; /** @@ -257,12 +255,10 @@ FieldDropdown.prototype.shouldAddBorderRect_ = function() { * @protected */ FieldDropdown.prototype.createTextArrow_ = function() { - this.arrow_ = dom.createSvgElement( - Svg.TSPAN, {}, this.textElement_); + this.arrow_ = dom.createSvgElement(Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( - this.sourceBlock_.RTL ? - FieldDropdown.ARROW_CHAR + ' ' : - ' ' + FieldDropdown.ARROW_CHAR)); + this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + ' ' : + ' ' + FieldDropdown.ARROW_CHAR)); if (this.sourceBlock_.RTL) { this.textElement_.insertBefore(this.arrow_, this.textContent_); } else { @@ -279,8 +275,10 @@ FieldDropdown.prototype.createSVGArrow_ = function() { Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', 'width': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px' - }, this.fieldGroup_); - this.svgArrow_.setAttributeNS(dom.XLINK_NS, 'xlink:href', + }, + this.fieldGroup_); + this.svgArrow_.setAttributeNS( + dom.XLINK_NS, 'xlink:href', this.getConstants().FIELD_DROPDOWN_SVG_ARROW_DATAURI); }; @@ -293,8 +291,7 @@ FieldDropdown.prototype.createSVGArrow_ = function() { FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { - this.menu_.openingCoords = - new Coordinate(opt_e.clientX, opt_e.clientY); + this.menu_.openingCoords = new Coordinate(opt_e.clientX, opt_e.clientY); } else { this.menu_.openingCoords = null; } @@ -313,8 +310,7 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { DropDownDiv.setColour(primaryColour, borderColour); } - DropDownDiv.showPositionedByField( - this, this.dropdownDispose_.bind(this)); + DropDownDiv.showPositionedByField(this, this.dropdownDispose_.bind(this)); // Focusing needs to be handled after the menu is rendered and positioned. // Otherwise it will cause a page scroll to get the misplaced menu in @@ -341,7 +337,7 @@ FieldDropdown.prototype.dropdownCreate_ = function() { this.selectedMenuItem_ = null; for (let i = 0; i < options.length; i++) { let content = options[i][0]; // Human-readable text or image. - const value = options[i][1]; // Language-neutral value. + const value = options[i][1]; // Language-neutral value. if (typeof content == 'object') { // An image, not text. const image = new Image(content['width'], content['height']); @@ -443,8 +439,8 @@ FieldDropdown.prototype.trimOptions_ = function() { this.suffixField = strings[0].substr(1 - suffixLength); } - this.menuGenerator_ = FieldDropdown.applyTrim_(options, prefixLength, - suffixLength); + this.menuGenerator_ = + FieldDropdown.applyTrim_(options, prefixLength, suffixLength); }; /** @@ -456,8 +452,7 @@ FieldDropdown.prototype.trimOptions_ = function() { * @param {number} suffixLength The length of the common suffix * @return {!Array} A new array with all of the option text trimmed. */ -FieldDropdown.applyTrim_ = function(options, - prefixLength, suffixLength) { +FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { const newOptions = []; // Remove the prefix and suffix from the options. for (let i = 0; i < options.length; i++) { @@ -514,9 +509,10 @@ FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { } if (!isValueValid) { if (this.sourceBlock_) { - console.warn('Cannot set the dropdown\'s value to an unavailable option.' + - ' Block type: ' + this.sourceBlock_.type + ', Field name: ' + this.name + - ', Value: ' + opt_newValue); + console.warn( + 'Cannot set the dropdown\'s value to an unavailable option.' + + ' Block type: ' + this.sourceBlock_.type + + ', Field name: ' + this.name + ', Value: ' + opt_newValue); } return null; } @@ -545,11 +541,11 @@ FieldDropdown.prototype.doValueUpdate_ = function(newValue) { */ FieldDropdown.prototype.applyColour = function() { if (this.borderRect_) { - this.borderRect_.setAttribute('stroke', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'stroke', this.sourceBlock_.style.colourTertiary); if (this.menu_) { - this.borderRect_.setAttribute('fill', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'fill', this.sourceBlock_.style.colourTertiary); } else { this.borderRect_.setAttribute('fill', 'transparent'); } @@ -593,8 +589,7 @@ FieldDropdown.prototype.render_ = function() { */ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; - this.imageElement_.setAttributeNS( - dom.XLINK_NS, 'xlink:href', imageJson.src); + this.imageElement_.setAttributeNS(dom.XLINK_NS, 'xlink:href', imageJson.src); this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); @@ -606,11 +601,13 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, imageHeight + FieldDropdown.IMAGE_Y_PADDING); - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { - arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); + arrowWidth = this.positionSVGArrow_( + imageWidth + xPadding, + height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } else { arrowWidth = dom.getFastTextWidth( /** @type {!SVGTSpanElement} */ (this.arrow_), @@ -642,8 +639,8 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); - dom.addClass(/** @type {!Element} */ (this.textElement_), - 'blocklyDropdownText'); + dom.addClass( + /** @type {!Element} */ (this.textElement_), 'blocklyDropdownText'); this.textElement_.setAttribute('text-anchor', 'start'); // Height and width include the border rect. @@ -651,15 +648,17 @@ FieldDropdown.prototype.renderSelectedText_ = function() { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - const textWidth = dom.getFastTextWidth(this.textElement_, - this.getConstants().FIELD_TEXT_FONTSIZE, + const textWidth = dom.getFastTextWidth( + this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { - arrowWidth = this.positionSVGArrow_(textWidth + xPadding, height / 2 - - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); + arrowWidth = this.positionSVGArrow_( + textWidth + xPadding, + height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } this.size_.width = textWidth + arrowWidth + xPadding * 2; this.size_.height = height; @@ -679,12 +678,13 @@ FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { return 0; } const hasBorder = !!this.borderRect_; - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; const textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; const svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; const arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; - this.svgArrow_.setAttribute('transform', - 'translate(' + arrowX + ',' + y + ')'); + this.svgArrow_.setAttribute( + 'transform', 'translate(' + arrowX + ',' + y + ')'); return svgArrowSize + textPadding; }; @@ -727,19 +727,21 @@ FieldDropdown.validateOptions_ = function(options) { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option must be an ' + - 'array. Found: ', tuple); + 'array. Found: ', + tuple); } else if (typeof tuple[1] != 'string') { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option id must be ' + - 'a string. Found ' + tuple[1] + ' in: ', tuple); - } else if (tuple[0] && - (typeof tuple[0] != 'string') && - (typeof tuple[0].src != 'string')) { + 'a string. Found ' + tuple[1] + ' in: ', + tuple); + } else if ( + tuple[0] && (typeof tuple[0] != 'string') && + (typeof tuple[0].src != 'string')) { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option must have a ' + - 'string label or image description. Found' + tuple[0] + ' in: ', + 'string label or image description. Found' + tuple[0] + ' in: ', tuple); } } From 5e3940195f8c718d812a4c5b7d0b64a8f7fd6a7c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 15:02:35 -0700 Subject: [PATCH 188/313] Migrate private static fields/functions in core/field_dropdown.js to module-internal --- core/field_dropdown.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 79b6ea404..ddb5a4e18 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -48,7 +48,7 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); */ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { if (typeof menuGenerator != 'function') { - FieldDropdown.validateOptions_(menuGenerator); + validateOptions(menuGenerator); } /** @@ -192,17 +192,15 @@ FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; * is selected. * @type {number} * @const - * @private */ -FieldDropdown.IMAGE_Y_OFFSET = 5; +const IMAGE_Y_OFFSET = 5; /** * The total vertical padding above and below an image. * @type {number} * @const - * @private */ -FieldDropdown.IMAGE_Y_PADDING = FieldDropdown.IMAGE_Y_OFFSET * 2; +const IMAGE_Y_PADDING = IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "▾", so use "▼" instead. @@ -484,7 +482,7 @@ FieldDropdown.prototype.getOptions = function(opt_useCache) { if (this.isOptionListDynamic()) { if (!this.generatedOptions_ || !opt_useCache) { this.generatedOptions_ = this.menuGenerator_.call(this); - FieldDropdown.validateOptions_(this.generatedOptions_); + validateOptions(this.generatedOptions_); } return this.generatedOptions_; } @@ -600,7 +598,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const hasBorder = !!this.borderRect_; const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, - imageHeight + FieldDropdown.IMAGE_Y_PADDING); + imageHeight + IMAGE_Y_PADDING); const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; @@ -711,9 +709,8 @@ FieldDropdown.prototype.getText_ = function() { * Validates the data structure to be processed as an options list. * @param {?} options The proposed dropdown options. * @throws {TypeError} If proposed options are incorrectly structured. - * @private */ -FieldDropdown.validateOptions_ = function(options) { +const validateOptions = function(options) { if (!Array.isArray(options)) { throw TypeError('FieldDropdown options must be an array.'); } From c15f1e4767798f1b8230fc07f9ae7d89e669e634 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:17:00 -0700 Subject: [PATCH 189/313] Move constants to internal_constants.js and add aliases --- core/blockly.js | 36 ++++++ core/constants.js | 189 ++------------------------------ core/internal_constants.js | 217 +++++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+), 181 deletions(-) create mode 100644 core/internal_constants.js diff --git a/core/blockly.js b/core/blockly.js index 92716e4d1..554e02c8d 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -35,6 +35,7 @@ goog.require('Blockly.Events.VarCreate'); /** @suppress {extraRequire} */ goog.require('Blockly.inject'); goog.require('Blockly.inputTypes'); +goog.require('Blockly.internalConstants'); /** @suppress {extraRequire} */ goog.require('Blockly.Procedures'); goog.require('Blockly.ShortcutRegistry'); @@ -596,3 +597,38 @@ Blockly.TOOLBOX_AT_LEFT = Blockly.utils.toolbox.Position.LEFT; * @see Blockly.utils.toolbox.Position.RIGHT */ Blockly.TOOLBOX_AT_RIGHT = Blockly.utils.toolbox.Position.RIGHT; + +// Aliases to allow external code to access these values for legacy reasons. +Blockly.LINE_MODE_MULTIPLIER = Blockly.internalConstants.LINE_MODE_MULTIPLIER; +Blockly.PAGE_MODE_MULTIPLIER = Blockly.internalConstants.PAGE_MODE_MULTIPLIER; +Blockly.DRAG_RADIUS = Blockly.internalConstants.DRAG_RADIUS; +Blockly.FLYOUT_DRAG_RADIUS = Blockly.internalConstants.FLYOUT_DRAG_RADIUS; +Blockly.SNAP_RADIUS = Blockly.internalConstants.SNAP_RADIUS; +Blockly.CONNECTING_SNAP_RADIUS = + Blockly.internalConstants.CONNECTING_SNAP_RADIUS; +Blockly.CURRENT_CONNECTION_PREFERENCE = + Blockly.internalConstants.CURRENT_CONNECTION_PREFERENCE; +Blockly.BUMP_DELAY = Blockly.internalConstants.BUMP_DELAY; +Blockly.BUMP_RANDOMNESS = Blockly.internalConstants.BUMP_RANDOMNESS; +Blockly.COLLAPSE_CHARS = Blockly.internalConstants.COLLAPSE_CHARS; +Blockly.LONGPRESS = Blockly.internalConstants.LONGPRESS; +Blockly.SOUND_LIMIT = Blockly.internalConstants.SOUND_LIMIT; +Blockly.DRAG_STACK = Blockly.internalConstants.DRAG_STACK; +Blockly.HSV_SATURATION = Blockly.internalConstants.HSV_SATURATION; +Blockly.HSV_VALUE = Blockly.internalConstants.HSV_VALUE; +Blockly.SPRITE = Blockly.internalConstants.SPRITE; +Blockly.DRAG_NONE = Blockly.internalConstants.DRAG_NONE; +Blockly.DRAG_STICKY = Blockly.internalConstants.DRAG_STICKY; +Blockly.DRAG_BEGIN = Blockly.internalConstants.DRAG_BEGIN; +Blockly.DRAG_FREE = Blockly.internalConstants.DRAG_FREE; +Blockly.OPPOSITE_TYPE = Blockly.internalConstants.OPPOSITE_TYPE; +Blockly.VARIABLE_CATEGORY_NAME = + Blockly.internalConstants.VARIABLE_CATEGORY_NAME; +Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME = + Blockly.internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME; +Blockly.PROCEDURE_CATEGORY_NAME = + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME; +Blockly.RENAME_VARIABLE_ID = Blockly.internalConstants.RENAME_VARIABLE_ID; +Blockly.DELETE_VARIABLE_ID = Blockly.internalConstants.DELETE_VARIABLE_ID; +Blockly.COLLAPSED_INPUT_NAME = Blockly.constants.COLLAPSED_INPUT_NAME; +Blockly.COLLAPSED_FIELD_NAME = Blockly.constants.COLLAPSED_FIELD_NAME; diff --git a/core/constants.js b/core/constants.js index 1d19fb8d5..727e42a1f 100644 --- a/core/constants.js +++ b/core/constants.js @@ -10,204 +10,31 @@ */ 'use strict'; -goog.provide('Blockly.constants'); +goog.module('Blockly.constants'); +goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); - - -/** - * The multiplier for scroll wheel deltas using the line delta mode. - * @type {number} - */ -Blockly.LINE_MODE_MULTIPLIER = 40; - -/** - * The multiplier for scroll wheel deltas using the page delta mode. - * @type {number} - */ -Blockly.PAGE_MODE_MULTIPLIER = 125; - -/** - * Number of pixels the mouse must move before a drag starts. - */ -Blockly.DRAG_RADIUS = 5; - -/** - * Number of pixels the mouse must move before a drag/scroll starts from the - * flyout. Because the drag-intention is determined when this is reached, it is - * larger than Blockly.DRAG_RADIUS so that the drag-direction is clearer. - */ -Blockly.FLYOUT_DRAG_RADIUS = 10; - -/** - * Maximum misalignment between connections for them to snap together. - */ -Blockly.SNAP_RADIUS = 28; - -/** - * Maximum misalignment between connections for them to snap together, - * when a connection is already highlighted. - */ -Blockly.CONNECTING_SNAP_RADIUS = Blockly.SNAP_RADIUS; - -/** - * How much to prefer staying connected to the current connection over moving to - * a new connection. The current previewed connection is considered to be this - * much closer to the matching connection on the block than it actually is. - */ -Blockly.CURRENT_CONNECTION_PREFERENCE = 8; - -/** - * Delay in ms between trigger and bumping unconnected block out of alignment. - */ -Blockly.BUMP_DELAY = 250; - -/** - * Maximum randomness in workspace units for bumping a block. - */ -Blockly.BUMP_RANDOMNESS = 10; - -/** - * Number of characters to truncate a collapsed block to. - */ -Blockly.COLLAPSE_CHARS = 30; - -/** - * Length in ms for a touch to become a long press. - */ -Blockly.LONGPRESS = 750; - -/** - * Prevent a sound from playing if another sound preceded it within this many - * milliseconds. - */ -Blockly.SOUND_LIMIT = 100; - -/** - * When dragging a block out of a stack, split the stack in two (true), or drag - * out the block healing the stack (false). - */ -Blockly.DRAG_STACK = true; - -/** - * The richness of block colours, regardless of the hue. - * Must be in the range of 0 (inclusive) to 1 (exclusive). - */ -Blockly.HSV_SATURATION = 0.45; - -/** - * The intensity of block colours, regardless of the hue. - * Must be in the range of 0 (inclusive) to 1 (exclusive). - */ -Blockly.HSV_VALUE = 0.65; - -/** - * Sprited icons and images. - */ -Blockly.SPRITE = { - width: 96, - height: 124, - url: 'sprites.png' -}; - -// Constants below this point are not intended to be changed. /** * Enum for alignment of inputs. * @enum {number} */ -Blockly.constants.ALIGN = { +const ALIGN = { LEFT: -1, CENTRE: 0, RIGHT: 1 }; - -/** - * ENUM for no drag operation. - * @const - */ -Blockly.DRAG_NONE = 0; - -/** - * ENUM for inside the sticky DRAG_RADIUS. - * @const - */ -Blockly.DRAG_STICKY = 1; - -/** - * ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between - * clicks and drags. - * @const - */ -Blockly.DRAG_BEGIN = 1; - -/** - * ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). - * @const - */ -Blockly.DRAG_FREE = 2; - -/** - * Lookup table for determining the opposite type of a connection. - * @const - */ -Blockly.OPPOSITE_TYPE = []; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.INPUT_VALUE] = - Blockly.connectionTypes.OUTPUT_VALUE; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.OUTPUT_VALUE] = - Blockly.connectionTypes.INPUT_VALUE; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.NEXT_STATEMENT] = - Blockly.connectionTypes.PREVIOUS_STATEMENT; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.PREVIOUS_STATEMENT] = - Blockly.connectionTypes.NEXT_STATEMENT; - -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * variable blocks. - * @const {string} - */ -Blockly.VARIABLE_CATEGORY_NAME = 'VARIABLE'; -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * variable blocks. - * @const {string} - */ -Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME = 'VARIABLE_DYNAMIC'; - -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * procedure blocks. - * @const {string} - */ -Blockly.PROCEDURE_CATEGORY_NAME = 'PROCEDURE'; - -/** - * String for use in the dropdown created in field_variable. - * This string indicates that this option in the dropdown is 'Rename - * variable...' and if selected, should trigger the prompt to rename a variable. - * @const {string} - */ -Blockly.RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID'; - -/** - * String for use in the dropdown created in field_variable. - * This string indicates that this option in the dropdown is 'Delete the "%1" - * variable' and if selected, should trigger the prompt to delete a variable. - * @const {string} - */ -Blockly.DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID'; +exports.ALIGN = ALIGN; /** * The language-neutral ID given to the collapsed input. * @const {string} */ -Blockly.constants.COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT'; +const COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT'; +exports.COLLAPSED_INPUT_NAME = COLLAPSED_INPUT_NAME; /** * The language-neutral ID given to the collapsed field. * @const {string} */ -Blockly.constants.COLLAPSED_FIELD_NAME = '_TEMP_COLLAPSED_FIELD'; +const COLLAPSED_FIELD_NAME = '_TEMP_COLLAPSED_FIELD'; +exports.COLLAPSED_FIELD_NAME = COLLAPSED_FIELD_NAME; diff --git a/core/internal_constants.js b/core/internal_constants.js new file mode 100644 index 000000000..b5a8cd568 --- /dev/null +++ b/core/internal_constants.js @@ -0,0 +1,217 @@ +/** + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Module that provides constants for use inside Blockly. Do not + * use these constants outside of the core library. + * @author fenichel@google.com (Rachel Fenichel) + */ +'use strict'; + +goog.module('Blockly.internalConstants'); +goog.module.declareLegacyNamespace(); + +const connectionTypes = goog.require('Blockly.connectionTypes'); + + +/** + * The multiplier for scroll wheel deltas using the line delta mode. + * @type {number} + */ +const LINE_MODE_MULTIPLIER = 40; +exports.LINE_MODE_MULTIPLIER = LINE_MODE_MULTIPLIER; + +/** + * The multiplier for scroll wheel deltas using the page delta mode. + * @type {number} + */ +const PAGE_MODE_MULTIPLIER = 125; +exports.PAGE_MODE_MULTIPLIER = PAGE_MODE_MULTIPLIER; + +/** + * Number of pixels the mouse must move before a drag starts. + */ +const DRAG_RADIUS = 5; +exports.DRAG_RADIUS = DRAG_RADIUS; + +/** + * Number of pixels the mouse must move before a drag/scroll starts from the + * flyout. Because the drag-intention is determined when this is reached, it is + * larger than DRAG_RADIUS so that the drag-direction is clearer. + */ +const FLYOUT_DRAG_RADIUS = 10; +exports.FLYOUT_DRAG_RADIUS = FLYOUT_DRAG_RADIUS; + +/** + * Maximum misalignment between connections for them to snap together. + */ +const SNAP_RADIUS = 28; +exports.SNAP_RADIUS = SNAP_RADIUS; + +/** + * Maximum misalignment between connections for them to snap together, + * when a connection is already highlighted. + */ +const CONNECTING_SNAP_RADIUS = SNAP_RADIUS; +exports.CONNECTING_SNAP_RADIUS = CONNECTING_SNAP_RADIUS; + +/** + * How much to prefer staying connected to the current connection over moving to + * a new connection. The current previewed connection is considered to be this + * much closer to the matching connection on the block than it actually is. + */ +const CURRENT_CONNECTION_PREFERENCE = 8; +exports.CURRENT_CONNECTION_PREFERENCE = CURRENT_CONNECTION_PREFERENCE; + +/** + * Delay in ms between trigger and bumping unconnected block out of alignment. + */ +const BUMP_DELAY = 250; +exports.BUMP_DELAY = BUMP_DELAY; + +/** + * Maximum randomness in workspace units for bumping a block. + */ +const BUMP_RANDOMNESS = 10; +exports.BUMP_RANDOMNESS = BUMP_RANDOMNESS; + +/** + * Number of characters to truncate a collapsed block to. + */ +const COLLAPSE_CHARS = 30; +exports.COLLAPSE_CHARS = COLLAPSE_CHARS; + +/** + * Length in ms for a touch to become a long press. + */ +const LONGPRESS = 750; +exports.LONGPRESS = LONGPRESS; + +/** + * Prevent a sound from playing if another sound preceded it within this many + * milliseconds. + */ +const SOUND_LIMIT = 100; +exports.SOUND_LIMIT = SOUND_LIMIT; + +/** + * When dragging a block out of a stack, split the stack in two (true), or drag + * out the block healing the stack (false). + */ +const DRAG_STACK = true; +exports.DRAG_STACK = DRAG_STACK; + +/** + * The richness of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + */ +const HSV_SATURATION = 0.45; +exports.HSV_SATURATION = HSV_SATURATION; + +/** + * The intensity of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + */ +const HSV_VALUE = 0.65; +exports.HSV_VALUE = HSV_VALUE; + +/** + * Sprited icons and images. + */ +const SPRITE = { + width: 96, + height: 124, + url: 'sprites.png' +}; +exports.SPRITE = SPRITE; + +/** + * ENUM for no drag operation. + * @const + */ +const DRAG_NONE = 0; +exports.DRAG_NONE = DRAG_NONE; + +/** + * ENUM for inside the sticky DRAG_RADIUS. + * @const + */ +const DRAG_STICKY = 1; +exports.DRAG_STICKY = DRAG_STICKY; + +/** + * ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between + * clicks and drags. + * @const + */ +const DRAG_BEGIN = 1; +exports.DRAG_BEGIN = DRAG_BEGIN; + +/** + * ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). + * @const + */ +const DRAG_FREE = 2; +exports.DRAG_FREE = DRAG_FREE; + +/** + * Lookup table for determining the opposite type of a connection. + * @const + */ +const OPPOSITE_TYPE = []; +OPPOSITE_TYPE[connectionTypes.INPUT_VALUE] = connectionTypes.OUTPUT_VALUE; +OPPOSITE_TYPE[connectionTypes.OUTPUT_VALUE] = connectionTypes.INPUT_VALUE; +OPPOSITE_TYPE[connectionTypes.NEXT_STATEMENT] = + connectionTypes.PREVIOUS_STATEMENT; +OPPOSITE_TYPE[connectionTypes.PREVIOUS_STATEMENT] = + connectionTypes.NEXT_STATEMENT; + +exports.OPPOSITE_TYPE = OPPOSITE_TYPE; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * variable blocks. + * @const {string} + */ +const VARIABLE_CATEGORY_NAME = 'VARIABLE'; +exports.VARIABLE_CATEGORY_NAME = VARIABLE_CATEGORY_NAME; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * variable blocks. + * @const {string} + */ +const VARIABLE_DYNAMIC_CATEGORY_NAME = 'VARIABLE_DYNAMIC'; +exports.VARIABLE_DYNAMIC_CATEGORY_NAME = VARIABLE_DYNAMIC_CATEGORY_NAME; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * procedure blocks. + * @const {string} + */ +const PROCEDURE_CATEGORY_NAME = 'PROCEDURE'; +exports.PROCEDURE_CATEGORY_NAME = PROCEDURE_CATEGORY_NAME; + +/** + * String for use in the dropdown created in field_variable. + * This string indicates that this option in the dropdown is 'Rename + * variable...' and if selected, should trigger the prompt to rename a variable. + * @const {string} + */ +const RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID'; +exports.RENAME_VARIABLE_ID = RENAME_VARIABLE_ID; + +/** + * String for use in the dropdown created in field_variable. + * This string indicates that this option in the dropdown is 'Delete the "%1" + * variable' and if selected, should trigger the prompt to delete a variable. + * @const {string} + */ +const DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID'; +exports.DELETE_VARIABLE_ID = DELETE_VARIABLE_ID; From 324c3c038f81dad7ce7c321c97cc4b4b3a8ab12e Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:17:19 -0700 Subject: [PATCH 190/313] Rebuild --- tests/deps.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/deps.js b/tests/deps.js index 52ca3e4f3..d7e7ec201 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -12,7 +12,7 @@ goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'] goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); 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']); @@ -23,7 +23,7 @@ goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly 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'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); +goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); @@ -100,7 +100,12 @@ goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectabl goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'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'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); +<<<<<<< HEAD goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); +======= +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); +>>>>>>> 3a5ddf4d (Rebuild) goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From cc7a263fb3842ca6a2bc800288eca2d4474bfba0 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:48:56 -0700 Subject: [PATCH 191/313] Replace references to SPRITE and SOUND_LIMIT with internalConstants versions --- core/trashcan.js | 29 +++++++++++++++-------------- core/workspace_audio.js | 5 ++--- core/zoom_controls.js | 40 ++++++++++++++++++++++------------------ tests/deps.js | 6 +++--- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index 831a26ba4..619299b21 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -14,13 +14,12 @@ goog.provide('Blockly.Trashcan'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.DeleteArea'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.TrashcanOpen'); goog.require('Blockly.IAutoHideable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.IPositionable'); goog.require('Blockly.Options'); goog.require('Blockly.registry'); @@ -316,17 +315,18 @@ Blockly.Trashcan.prototype.createDom = function() { }, clip); var body = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, 'x': -this.SPRITE_LEFT_, - 'height': Blockly.SPRITE.height, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -this.SPRITE_TOP_, 'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')' }, this.svgGroup_); - body.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + body.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, @@ -336,17 +336,18 @@ Blockly.Trashcan.prototype.createDom = function() { Blockly.utils.Svg.RECT, {'width': this.WIDTH_, 'height': this.LID_HEIGHT_}, clip); this.svgLid_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, 'x': -this.SPRITE_LEFT_, - 'height': Blockly.SPRITE.height, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -this.SPRITE_TOP_, 'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')' }, this.svgGroup_); - this.svgLid_.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + this.svgLid_.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // bindEventWithChecks_ quashes events too aggressively. See: // https://groups.google.com/forum/#!topic/blockly/QF4yB9Wx00s diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 954b8f892..378c19287 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -13,8 +13,7 @@ goog.provide('Blockly.WorkspaceAudio'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.userAgent'); @@ -135,7 +134,7 @@ Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { // Don't play one sound on top of another. var now = new Date; if (this.lastSound_ != null && - now - this.lastSound_ < Blockly.SOUND_LIMIT) { + now - this.lastSound_ < Blockly.internalConstants.SOUND_LIMIT) { return; } this.lastSound_ = now; diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 96ff41ac4..6ecf8b041 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -21,6 +21,7 @@ goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); goog.require('Blockly.IPositionable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Touch'); goog.require('Blockly.uiPosition'); goog.require('Blockly.utils'); @@ -337,17 +338,18 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { }, clip); var zoomoutSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'x': -64, 'y': -92, 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')' }, this.zoomOutGroup_); - zoomoutSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoomoutSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach listener. this.onZoomOutWrapper_ = Blockly.browserEvents.conditionalBind( @@ -388,17 +390,18 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { }, clip); var zoominSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'x': -32, 'y': -92, 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')' }, this.zoomInGroup_); - zoominSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoominSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach listener. this.onZoomInWrapper_ = Blockly.browserEvents.conditionalBind( @@ -456,16 +459,17 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { }, clip); var zoomresetSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -92, 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')' }, this.zoomResetGroup_); - zoomresetSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoomresetSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach event listeners. this.onZoomResetWrapper_ = Blockly.browserEvents.conditionalBind( diff --git a/tests/deps.js b/tests/deps.js index d7e7ec201..abbcce849 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -177,7 +177,7 @@ goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'] goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); -goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); @@ -206,7 +206,7 @@ goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); -goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']); goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -214,6 +214,6 @@ goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.Workspa goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From ad5836b26d73e153cc0f8499abdfa2534f3a94bd Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:57:48 -0700 Subject: [PATCH 192/313] Convert more names to use internalConstants --- blocks/procedures.js | 6 ++++-- core/block_svg.js | 3 ++- core/contextmenu.js | 9 ++++----- core/gesture.js | 8 ++++---- core/insertion_marker_manager.js | 7 +++---- core/rendered_connection.js | 21 +++++++++++++-------- core/utils.js | 16 ++++++++-------- core/workspace_svg.js | 12 ++++++------ tests/deps.js | 14 +++++++------- 9 files changed, 51 insertions(+), 45 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 644d7a751..328bc89e0 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -18,6 +18,7 @@ goog.require('Blockly.Comment'); goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Mutator'); goog.require('Blockly.Warning'); @@ -867,8 +868,9 @@ Blockly.Blocks['procedures_callnoreturn'] = { var block = Blockly.utils.xml.createElement('block'); block.setAttribute('type', this.defType_); var xy = this.getRelativeToSurfaceXY(); - var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); - var y = xy.y + Blockly.SNAP_RADIUS * 2; + var x = + xy.x + Blockly.internalConstants.SNAP_RADIUS * (this.RTL ? -1 : 1); + var y = xy.y + Blockly.internalConstants.SNAP_RADIUS * 2; block.setAttribute('x', x); block.setAttribute('y', y); var mutation = this.mutationToDom(); diff --git a/core/block_svg.js b/core/block_svg.js index 08e5addcb..f7da81fe3 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1550,7 +1550,8 @@ Blockly.BlockSvg.prototype.bumpNeighbours = function() { connection.targetBlock().bumpNeighbours(); } - var neighbours = connection.neighbours(Blockly.SNAP_RADIUS); + var neighbours = + connection.neighbours(Blockly.internalConstants.SNAP_RADIUS); for (var j = 0, otherConnection; (otherConnection = neighbours[j]); j++) { // If both connections are connected, that's probably fine. But if diff --git a/core/contextmenu.js b/core/contextmenu.js index e070207b7..3bfcda167 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -17,11 +17,10 @@ goog.provide('Blockly.ContextMenu'); goog.require('Blockly.browserEvents'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockCreate'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Menu'); goog.require('Blockly.MenuItem'); goog.require('Blockly.Msg'); @@ -195,11 +194,11 @@ Blockly.ContextMenu.callbackFactory = function(block, xml) { // Move the new block next to the old block. var xy = block.getRelativeToSurfaceXY(); if (block.RTL) { - xy.x -= Blockly.SNAP_RADIUS; + xy.x -= Blockly.internalConstants.SNAP_RADIUS; } else { - xy.x += Blockly.SNAP_RADIUS; + xy.x += Blockly.internalConstants.SNAP_RADIUS; } - xy.y += Blockly.SNAP_RADIUS * 2; + xy.y += Blockly.internalConstants.SNAP_RADIUS * 2; newBlock.moveBy(xy.x, xy.y); } finally { Blockly.Events.enable(); diff --git a/core/gesture.js b/core/gesture.js index 55378930b..77a720527 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -18,11 +18,10 @@ goog.require('Blockly.blockAnimations'); goog.require('Blockly.BlockDragger'); goog.require('Blockly.browserEvents'); goog.require('Blockly.BubbleDragger'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); @@ -295,8 +294,9 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - var limitRadius = - this.flyout_ ? Blockly.FLYOUT_DRAG_RADIUS : Blockly.DRAG_RADIUS; + var limitRadius = this.flyout_ ? + Blockly.internalConstants.FLYOUT_DRAG_RADIUS : + Blockly.internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index d0fea4502..bad4f28bc 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -15,9 +15,8 @@ goog.provide('Blockly.InsertionMarkerManager'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); +goog.require('Blockly.internalConstants'); goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.RenderedConnection'); @@ -439,9 +438,9 @@ Blockly.InsertionMarkerManager.prototype.getStartRadius_ = function() { // By increasing radiusConnection when a connection already exists, // we never "lose" the connection from the offset. if (this.closestConnection_ && this.localConnection_) { - return Blockly.CONNECTING_SNAP_RADIUS; + return Blockly.internalConstants.CONNECTING_SNAP_RADIUS; } - return Blockly.SNAP_RADIUS; + return Blockly.internalConstants.SNAP_RADIUS; }; /** diff --git a/core/rendered_connection.js b/core/rendered_connection.js index f9d3864e3..f229a2fac 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -14,8 +14,7 @@ goog.provide('Blockly.RenderedConnection'); goog.require('Blockly.Connection'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.deprecation'); @@ -173,17 +172,23 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { // Raise it to the top for extra visibility. var selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); - var dx = (staticConnection.x + Blockly.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x; - var dy = (staticConnection.y + Blockly.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.y; + var dx = + (staticConnection.x + Blockly.internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.x; + var dy = + (staticConnection.y + Blockly.internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.y; if (reverse) { // When reversing a bump due to an uneditable block, bump up. dy = -dy; } if (rootBlock.RTL) { - dx = (staticConnection.x - Blockly.SNAP_RADIUS - - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x; + dx = (staticConnection.x - Blockly.internalConstants.SNAP_RADIUS - + Math.floor( + Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.x; } rootBlock.moveBy(dx, dy); selected || rootBlock.removeSelect(); diff --git a/core/utils.js b/core/utils.js index 171e83422..8213d38d9 100644 --- a/core/utils.js +++ b/core/utils.js @@ -18,8 +18,7 @@ */ goog.provide('Blockly.utils'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.Coordinate'); @@ -194,13 +193,13 @@ Blockly.utils.getScrollDeltaPixels = function(e) { }; case 0x01: // Line mode. return { - x: e.deltaX * Blockly.LINE_MODE_MULTIPLIER, - y: e.deltaY * Blockly.LINE_MODE_MULTIPLIER + x: e.deltaX * Blockly.internalConstants.LINE_MODE_MULTIPLIER, + y: e.deltaY * Blockly.internalConstants.LINE_MODE_MULTIPLIER }; case 0x02: // Page mode. return { - x: e.deltaX * Blockly.PAGE_MODE_MULTIPLIER, - y: e.deltaY * Blockly.PAGE_MODE_MULTIPLIER + x: e.deltaX * Blockly.internalConstants.PAGE_MODE_MULTIPLIER, + y: e.deltaY * Blockly.internalConstants.PAGE_MODE_MULTIPLIER }; } }; @@ -634,8 +633,9 @@ Blockly.utils.parseBlockColour = function(colour) { if (!isNaN(hue) && 0 <= hue && hue <= 360) { return { hue: hue, - hex: Blockly.utils.colour.hsvToHex(hue, Blockly.HSV_SATURATION, - Blockly.HSV_VALUE * 255) + hex: Blockly.utils.colour.hsvToHex( + hue, Blockly.internalConstants.HSV_SATURATION, + Blockly.internalConstants.HSV_VALUE * 255) }; } else { var hex = Blockly.utils.colour.parse(dereferenced); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 21ee217ae..f62107e4f 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -17,8 +17,6 @@ goog.require('Blockly.BlockSvg'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.ConnectionDB'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenuRegistry'); goog.require('Blockly.Events'); @@ -31,6 +29,7 @@ goog.require('Blockly.Events.ViewportChange'); goog.require('Blockly.Gesture'); goog.require('Blockly.Grid'); goog.require('Blockly.IASTNodeLocationSvg'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.MarkerManager'); /** @suppress {extraRequire} */ goog.require('Blockly.MetricsManager'); @@ -1521,7 +1520,8 @@ Blockly.WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock) { // Check for blocks in snap range to any of its connections. var connections = block.getConnections_(false); for (var i = 0, connection; (connection = connections[i]); i++) { - var neighbour = connection.closest(Blockly.SNAP_RADIUS, + var neighbour = connection.closest( + Blockly.internalConstants.SNAP_RADIUS, new Blockly.utils.Coordinate(blockX, blockY)); if (neighbour.connection) { collide = true; @@ -1531,11 +1531,11 @@ Blockly.WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock) { } if (collide) { if (this.RTL) { - blockX -= Blockly.SNAP_RADIUS; + blockX -= Blockly.internalConstants.SNAP_RADIUS; } else { - blockX += Blockly.SNAP_RADIUS; + blockX += Blockly.internalConstants.SNAP_RADIUS; } - blockY += Blockly.SNAP_RADIUS * 2; + blockY += Blockly.internalConstants.SNAP_RADIUS * 2; } } while (collide); block.moveBy(blockX, blockY); diff --git a/tests/deps.js b/tests/deps.js index abbcce849..a41eba2bb 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -3,7 +3,7 @@ goog.addDependency('../../blocks/lists.js', ['Blockly.Constants.Lists'], ['Block goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Constants.Logic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Mutator']); goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); -goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); +goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -24,7 +24,7 @@ goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionCheck goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); @@ -66,13 +66,13 @@ goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Bl goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.constants', 'Blockly.utils.deprecation']); -goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.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/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.internalConstants'], {'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'], {'lang': 'es6', 'module': 'goog'}); @@ -122,7 +122,7 @@ goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils.xml']); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); -goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); @@ -178,7 +178,7 @@ goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.brows goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], [], {'lang': 'es6', 'module': 'goog'}); @@ -212,7 +212,7 @@ goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.Works goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); -goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From 8b5f5f72d632ecbcaa55277a08c56b825ef6cf82 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:10:34 -0700 Subject: [PATCH 193/313] Refer to more constants through internalConstants --- blocks/procedures.js | 6 ++---- core/block_svg.js | 8 ++++---- core/blockly.js | 5 +++-- core/gesture.js | 2 +- core/insertion_marker_manager.js | 6 ++++-- core/mutator.js | 3 ++- core/rendered_connection.js | 2 +- core/touch.js | 6 ++---- tests/deps.js | 8 ++++---- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 328bc89e0..644d7a751 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -18,7 +18,6 @@ goog.require('Blockly.Comment'); goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.internalConstants'); goog.require('Blockly.Mutator'); goog.require('Blockly.Warning'); @@ -868,9 +867,8 @@ Blockly.Blocks['procedures_callnoreturn'] = { var block = Blockly.utils.xml.createElement('block'); block.setAttribute('type', this.defType_); var xy = this.getRelativeToSurfaceXY(); - var x = - xy.x + Blockly.internalConstants.SNAP_RADIUS * (this.RTL ? -1 : 1); - var y = xy.y + Blockly.internalConstants.SNAP_RADIUS * 2; + var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); + var y = xy.y + Blockly.SNAP_RADIUS * 2; block.setAttribute('x', x); block.setAttribute('y', y); var mutation = this.mutationToDom(); diff --git a/core/block_svg.js b/core/block_svg.js index f7da81fe3..fd5be3212 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -18,7 +18,6 @@ goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockRendering.IPathObject'); goog.require('Blockly.browserEvents'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenuRegistry'); @@ -31,6 +30,7 @@ goog.require('Blockly.IASTNodeLocationSvg'); goog.require('Blockly.IBoundedElement'); goog.require('Blockly.ICopyable'); goog.require('Blockly.IDraggable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.RenderedConnection'); goog.require('Blockly.TabNavigateCursor'); @@ -688,7 +688,7 @@ Blockly.BlockSvg.prototype.updateCollapsed_ = function() { icon.setVisible(false); } - var text = this.toString(Blockly.COLLAPSE_CHARS); + var text = this.toString(Blockly.internalConstants.COLLAPSE_CHARS); var field = this.getField(collapsedFieldName); if (field) { field.setValue(text); @@ -1586,13 +1586,13 @@ Blockly.BlockSvg.prototype.scheduleSnapAndBump = function() { Blockly.Events.setGroup(group); block.snapToGrid(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY / 2); + }, Blockly.internalConstants.BUMP_DELAY / 2); setTimeout(function() { Blockly.Events.setGroup(group); block.bumpNeighbours(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY); + }, Blockly.internalConstants.BUMP_DELAY); }; /** diff --git a/core/blockly.js b/core/blockly.js index 554e02c8d..94f485c99 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -425,8 +425,9 @@ Blockly.isNumber = function(str) { * @return {string} RGB code, e.g. '#5ba65b'. */ Blockly.hueToHex = function(hue) { - return Blockly.utils.colour.hsvToHex(hue, Blockly.HSV_SATURATION, - Blockly.HSV_VALUE * 255); + return Blockly.utils.colour.hsvToHex( + hue, Blockly.internalConstants.HSV_SATURATION, + Blockly.internalConstants.HSV_VALUE * 255); }; /** diff --git a/core/gesture.js b/core/gesture.js index 77a720527..483d73a25 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -229,7 +229,7 @@ Blockly.Gesture = function(e, creatorWorkspace) { * @type {boolean} * @private */ - this.healStack_ = !Blockly.DRAG_STACK; + this.healStack_ = !Blockly.internalConstants.DRAG_STACK; }; /** diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index bad4f28bc..614f7e70b 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -377,8 +377,10 @@ Blockly.InsertionMarkerManager.prototype.shouldUpdatePreviews_ = function( var yDiff = this.localConnection_.y + dxy.y - this.closestConnection_.y; var curDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff); // Slightly prefer the existing preview over a new preview. - return !(candidateClosest && radius > curDistance - - Blockly.CURRENT_CONNECTION_PREFERENCE); + return !( + candidateClosest && + radius > curDistance - + Blockly.internalConstants.CURRENT_CONNECTION_PREFERENCE); } else if (!this.localConnection_ && !this.closestConnection_) { // We weren't showing a preview before, but we should now. return true; diff --git a/core/mutator.js b/core/mutator.js index 1bd6d0988..2733964c7 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -20,6 +20,7 @@ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BubbleOpen'); goog.require('Blockly.Icon'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Options'); goog.require('Blockly.utils'); goog.require('Blockly.utils.dom'); @@ -444,7 +445,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { Blockly.Events.setGroup(group); block.bumpNeighbours(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY); + }, Blockly.internalConstants.BUMP_DELAY); } // Don't update the bubble until the drag has ended, to avoid moving blocks diff --git a/core/rendered_connection.js b/core/rendered_connection.js index f229a2fac..14795c181 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -471,7 +471,7 @@ Blockly.RenderedConnection.prototype.onFailedConnect = this.bumpAwayFrom(otherConnection); Blockly.Events.setGroup(false); } - }.bind(this), Blockly.BUMP_DELAY); + }.bind(this), Blockly.internalConstants.BUMP_DELAY); } }; diff --git a/core/touch.js b/core/touch.js index b6668c398..7dc578663 100644 --- a/core/touch.js +++ b/core/touch.js @@ -16,8 +16,7 @@ */ goog.provide('Blockly.Touch'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.string'); @@ -107,8 +106,7 @@ Blockly.longStart = function(e, gesture) { if (gesture) { gesture.handleRightClick(e); } - - }, Blockly.LONGPRESS); + }, Blockly.internalConstants.LONGPRESS); }; /** diff --git a/tests/deps.js b/tests/deps.js index a41eba2bb..39f55df61 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -3,7 +3,7 @@ goog.addDependency('../../blocks/lists.js', ['Blockly.Constants.Lists'], ['Block goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Constants.Logic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Mutator']); goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); -goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.internalConstants'], {'lang': 'es5'}); +goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -11,7 +11,7 @@ goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); @@ -116,7 +116,7 @@ goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEven goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); -goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.constants']); goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); @@ -175,7 +175,7 @@ goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.BlockSvg', 'Blockly.CollapsibleToolboxCategory', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.ToolboxItemSelect', 'Blockly.IAutoHideable', 'Blockly.IKeyboardAccessible', 'Blockly.IStyleable', 'Blockly.IToolbox', 'Blockly.Options', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem']); goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); -goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); +goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); From b3f837a8d2d9152bad0dff2b54278de32f750733 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:24:59 -0700 Subject: [PATCH 194/313] Replace references to constants with internalConstants --- core/connection_checker.js | 5 ++--- core/field_variable.js | 22 ++++++++++------------ core/generator.js | 7 +++---- core/names.js | 17 +++++++++-------- core/procedures.js | 8 ++++---- core/rendered_connection.js | 5 +++-- core/variables.js | 7 +++---- core/workspace_svg.js | 9 ++++++--- tests/deps.js | 12 ++++++------ 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 4bd7bd4e2..5dcaef376 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -16,11 +16,10 @@ goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); +const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); /** @@ -144,7 +143,7 @@ ConnectionChecker.prototype.doSafetyChecks = function(a, b) { } if (blockA == blockB) { return Connection.REASON_SELF_CONNECTION; - } else if (b.type != Blockly.OPPOSITE_TYPE[a.type]) { + } else if (b.type != OPPOSITE_TYPE[a.type]) { return Connection.REASON_WRONG_TYPE; } else if (blockA.workspace !== blockB.workspace) { return Connection.REASON_DIFFERENT_WORKSPACES; diff --git a/core/field_variable.js b/core/field_variable.js index 18f2d20b4..e5e379c13 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -12,13 +12,11 @@ goog.provide('Blockly.FieldVariable'); -/** @suppress {extraRequire} */ -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.FieldDropdown'); goog.require('Blockly.fieldRegistry'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils'); goog.require('Blockly.utils.object'); @@ -417,14 +415,14 @@ Blockly.FieldVariable.dropdownCreate = function() { // Set the UUID as the internal representation of the variable. options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } - options.push([Blockly.Msg['RENAME_VARIABLE'], Blockly.RENAME_VARIABLE_ID]); + options.push([ + Blockly.Msg['RENAME_VARIABLE'], Blockly.internalConstants.RENAME_VARIABLE_ID + ]); if (Blockly.Msg['DELETE_VARIABLE']) { - options.push( - [ - Blockly.Msg['DELETE_VARIABLE'].replace('%1', name), - Blockly.DELETE_VARIABLE_ID - ] - ); + options.push([ + Blockly.Msg['DELETE_VARIABLE'].replace('%1', name), + Blockly.internalConstants.DELETE_VARIABLE_ID + ]); } return options; @@ -442,12 +440,12 @@ Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { var id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { - if (id == Blockly.RENAME_VARIABLE_ID) { + if (id == Blockly.internalConstants.RENAME_VARIABLE_ID) { // Rename variable. Blockly.Variables.renameVariable( this.sourceBlock_.workspace, this.variable_); return; - } else if (id == Blockly.DELETE_VARIABLE_ID) { + } else if (id == Blockly.internalConstants.DELETE_VARIABLE_ID) { // Delete variable. this.sourceBlock_.workspace.deleteVariableById(this.variable_.getId()); return; diff --git a/core/generator.js b/core/generator.js index d2af08852..e365c69ba 100644 --- a/core/generator.js +++ b/core/generator.js @@ -14,8 +14,7 @@ goog.provide('Blockly.Generator'); goog.require('Blockly.Block'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils.deprecation'); goog.requireType('Blockly.Names'); @@ -451,8 +450,8 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { */ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { - var functionName = this.nameDB_.getDistinctName(desiredName, - Blockly.PROCEDURE_CATEGORY_NAME); + var functionName = this.nameDB_.getDistinctName( + desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; var codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); diff --git a/core/names.js b/core/names.js index 3abd27f9e..a559321cf 100644 --- a/core/names.js +++ b/core/names.js @@ -12,8 +12,7 @@ goog.provide('Blockly.Names'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.requireType('Blockly.VariableMap'); @@ -77,7 +76,7 @@ Blockly.Names.prototype.setVariableMap = function(map) { /** * Get the name for a user-defined variable, based on its ID. * This should only be used for variables of realm - * Blockly.VARIABLE_CATEGORY_NAME. + * Blockly.internalConstants.VARIABLE_CATEGORY_NAME. * @param {string} id The ID to look up in the variable map. * @return {?string} The name of the referenced variable, or null if there was * no variable map or the variable was not found in the map. @@ -106,7 +105,8 @@ Blockly.Names.prototype.getNameForUserVariable_ = function(id) { Blockly.Names.prototype.populateVariables = function(workspace) { var variables = Blockly.Variables.allUsedVarModels(workspace); for (var i = 0; i < variables.length; i++) { - this.getName(variables[i].getId(), Blockly.VARIABLE_CATEGORY_NAME); + this.getName( + variables[i].getId(), Blockly.internalConstants.VARIABLE_CATEGORY_NAME); } }; @@ -119,7 +119,8 @@ Blockly.Names.prototype.populateProcedures = function(workspace) { // Flatten the return vs no-return procedure lists. procedures = procedures[0].concat(procedures[1]); for (var i = 0; i < procedures.length; i++) { - this.getName(procedures[i][0], Blockly.PROCEDURE_CATEGORY_NAME); + this.getName( + procedures[i][0], Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); } }; @@ -133,7 +134,7 @@ Blockly.Names.prototype.populateProcedures = function(workspace) { */ Blockly.Names.prototype.getName = function(nameOrId, realm) { var name = nameOrId; - if (realm == Blockly.VARIABLE_CATEGORY_NAME) { + if (realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME) { var varName = this.getNameForUserVariable_(nameOrId); if (varName) { // Successful ID lookup. @@ -142,7 +143,7 @@ Blockly.Names.prototype.getName = function(nameOrId, realm) { } var normalizedName = name.toLowerCase(); - var isVar = realm == Blockly.VARIABLE_CATEGORY_NAME || + var isVar = realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME || realm == Blockly.Names.DEVELOPER_VARIABLE_TYPE; var prefix = isVar ? this.variablePrefix_ : ''; @@ -189,7 +190,7 @@ Blockly.Names.prototype.getDistinctName = function(name, realm) { } safeName += i; this.dbReverse_[safeName] = true; - var isVar = realm == Blockly.VARIABLE_CATEGORY_NAME || + var isVar = realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME || realm == Blockly.Names.DEVELOPER_VARIABLE_TYPE; var prefix = isVar ? this.variablePrefix_ : ''; return prefix + safeName; diff --git a/core/procedures.js b/core/procedures.js index 984ef03fa..3323bb130 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -17,12 +17,11 @@ goog.provide('Blockly.Procedures'); goog.require('Blockly.Blocks'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Field'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.Names'); goog.require('Blockly.utils.xml'); @@ -37,9 +36,10 @@ goog.requireType('Blockly.WorkspaceSvg'); /** * Constant to separate procedure names from variables and generated functions * when running generators. - * @deprecated Use Blockly.PROCEDURE_CATEGORY_NAME + * @deprecated Use Blockly.internalConstants.PROCEDURE_CATEGORY_NAME */ -Blockly.Procedures.NAME_TYPE = Blockly.PROCEDURE_CATEGORY_NAME; +Blockly.Procedures.NAME_TYPE = + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME; /** * The default argument for a procedures_mutatorarg block. diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 14795c181..cddda9200 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -50,8 +50,9 @@ Blockly.RenderedConnection = function(source, type) { * @const {!Blockly.ConnectionDB} * @private */ - this.dbOpposite_ = source.workspace - .connectionDBList[Blockly.OPPOSITE_TYPE[type]]; + this.dbOpposite_ = + source.workspace + .connectionDBList[Blockly.internalConstants.OPPOSITE_TYPE[type]]; /** * Workspace units, (0, 0) is top left of block. diff --git a/core/variables.js b/core/variables.js index 1c091898e..223838a2b 100644 --- a/core/variables.js +++ b/core/variables.js @@ -17,8 +17,7 @@ goog.provide('Blockly.Variables'); goog.require('Blockly.Blocks'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils'); goog.require('Blockly.utils.xml'); @@ -31,9 +30,9 @@ goog.requireType('Blockly.Workspace'); /** * Constant to separate variable names from procedures and generated functions * when running generators. - * @deprecated Use Blockly.VARIABLE_CATEGORY_NAME + * @deprecated Use Blockly.internalConstants.VARIABLE_CATEGORY_NAME */ -Blockly.Variables.NAME_TYPE = Blockly.VARIABLE_CATEGORY_NAME; +Blockly.Variables.NAME_TYPE = Blockly.internalConstants.VARIABLE_CATEGORY_NAME; /** * Find all user-created variables that are in use in the workspace. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index f62107e4f..1c3cee44f 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -180,15 +180,18 @@ Blockly.WorkspaceSvg = function( this.flyoutButtonCallbacks_ = Object.create(null); if (Blockly.Variables && Blockly.Variables.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.VARIABLE_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.VARIABLE_CATEGORY_NAME, Blockly.Variables.flyoutCategory); } if (Blockly.VariablesDynamic && Blockly.VariablesDynamic.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME, Blockly.VariablesDynamic.flyoutCategory); } if (Blockly.Procedures && Blockly.Procedures.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.PROCEDURE_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME, Blockly.Procedures.flyoutCategory); this.addChangeListener(Blockly.Procedures.mutatorOpenListener); } diff --git a/tests/deps.js b/tests/deps.js index 39f55df61..8570bfd1c 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'], {'lang': 'es6', 'module': 'goog'}); 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'], {'lang': 'es6', 'module': 'goog'}); -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_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); @@ -60,12 +60,12 @@ goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilin goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); +goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.constants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); @@ -117,10 +117,10 @@ goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.uti goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); -goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.constants']); +goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.internalConstants']); goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils.xml']); +goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.xml']); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); @@ -201,7 +201,7 @@ goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); -goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.xml']); +goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.xml']); goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); From cf7a8b95b847be2f6136f121601bc81c5c8674df Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:51:58 -0700 Subject: [PATCH 195/313] Remove extra requires of Blockly.constants --- core/flyout_horizontal.js | 2 -- core/input.js | 2 -- core/keyboard_nav/ast_node.js | 2 -- core/renderers/common/constants.js | 2 -- core/renderers/common/debugger.js | 2 -- core/renderers/common/marker_svg.js | 2 -- core/renderers/common/renderer.js | 2 -- core/renderers/geras/info.js | 2 -- core/renderers/zelos/constants.js | 2 -- core/renderers/zelos/info.js | 2 -- core/renderers/zelos/renderer.js | 2 -- core/xml.js | 3 -- core/zoom_controls.js | 2 -- tests/deps.js | 48 +++++++++++++---------------- 14 files changed, 21 insertions(+), 54 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 485d29617..66e9ff18e 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -14,8 +14,6 @@ goog.provide('Blockly.HorizontalFlyout'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.Flyout'); goog.require('Blockly.registry'); diff --git a/core/input.js b/core/input.js index 57189c278..443bfc83f 100644 --- a/core/input.js +++ b/core/input.js @@ -13,8 +13,6 @@ goog.provide('Blockly.Input'); goog.require('Blockly.Connection'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 37145a090..332e9af8c 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -13,8 +13,6 @@ goog.provide('Blockly.ASTNode'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.Coordinate'); goog.requireType('Blockly.Block'); diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index a21ef85aa..5c73d0510 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -13,8 +13,6 @@ goog.provide('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.dom'); diff --git a/core/renderers/common/debugger.js b/core/renderers/common/debugger.js index 0e99fc613..a6ab9d387 100644 --- a/core/renderers/common/debugger.js +++ b/core/renderers/common/debugger.js @@ -17,8 +17,6 @@ goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Row'); goog.require('Blockly.blockRendering.Types'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); diff --git a/core/renderers/common/marker_svg.js b/core/renderers/common/marker_svg.js index f9559e071..36d12b119 100644 --- a/core/renderers/common/marker_svg.js +++ b/core/renderers/common/marker_svg.js @@ -15,8 +15,6 @@ goog.provide('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.ASTNode'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.MarkerMove'); diff --git a/core/renderers/common/renderer.js b/core/renderers/common/renderer.js index 77df5e518..37e4a883a 100644 --- a/core/renderers/common/renderer.js +++ b/core/renderers/common/renderer.js @@ -20,8 +20,6 @@ goog.require('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.blockRendering.PathObject'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.IRegistrable'); diff --git a/core/renderers/geras/info.js b/core/renderers/geras/info.js index ffc515a17..121e3b353 100644 --- a/core/renderers/geras/info.js +++ b/core/renderers/geras/info.js @@ -19,8 +19,6 @@ goog.require('Blockly.blockRendering.InputRow'); goog.require('Blockly.blockRendering.InRowSpacer'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.geras.InlineInput'); goog.require('Blockly.geras.StatementInput'); goog.require('Blockly.inputTypes'); diff --git a/core/renderers/zelos/constants.js b/core/renderers/zelos/constants.js index bb039250a..2070197cf 100644 --- a/core/renderers/zelos/constants.js +++ b/core/renderers/zelos/constants.js @@ -15,8 +15,6 @@ goog.provide('Blockly.zelos.ConstantProvider'); goog.require('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.object'); diff --git a/core/renderers/zelos/info.js b/core/renderers/zelos/info.js index b7dc3d972..078031756 100644 --- a/core/renderers/zelos/info.js +++ b/core/renderers/zelos/info.js @@ -18,8 +18,6 @@ goog.require('Blockly.blockRendering.InRowSpacer'); goog.require('Blockly.blockRendering.Measurable'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.FieldImage'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); diff --git a/core/renderers/zelos/renderer.js b/core/renderers/zelos/renderer.js index d192fa178..3c5287bbb 100644 --- a/core/renderers/zelos/renderer.js +++ b/core/renderers/zelos/renderer.js @@ -15,8 +15,6 @@ goog.provide('Blockly.zelos.Renderer'); goog.require('Blockly.blockRendering'); goog.require('Blockly.blockRendering.Renderer'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.utils.object'); goog.require('Blockly.zelos.ConstantProvider'); diff --git a/core/xml.js b/core/xml.js index 4140d6528..e581bfd01 100644 --- a/core/xml.js +++ b/core/xml.js @@ -15,9 +15,6 @@ * @namespace */ goog.provide('Blockly.Xml'); - -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.inputTypes'); goog.require('Blockly.utils'); diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 6ecf8b041..7d0d7e6ce 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -14,8 +14,6 @@ goog.provide('Blockly.ZoomControls'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Css'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ diff --git a/tests/deps.js b/tests/deps.js index 8570bfd1c..2d1386395 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); @@ -48,9 +48,9 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -63,14 +63,14 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', '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.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); @@ -80,7 +80,6 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid 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'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_collapsible_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem'], ['Blockly.ISelectableToolboxItem'], {'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'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); @@ -94,23 +93,18 @@ goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.I 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'}); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'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'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'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'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); -<<<<<<< HEAD -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); -======= goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); ->>>>>>> 3a5ddf4d (Rebuild) -goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); @@ -124,19 +118,19 @@ goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); -goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); +goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/geras/highlight_constants.js', ['Blockly.geras.HighlightConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/highlighter.js', ['Blockly.geras.Highlighter'], ['Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); -goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/geras/measurables/inputs.js', ['Blockly.geras.InlineInput', 'Blockly.geras.StatementInput'], ['Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/geras/path_object.js', ['Blockly.geras.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.PathObject', 'Blockly.geras.ConstantProvider', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/geras/renderer.js', ['Blockly.geras.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.geras.ConstantProvider', 'Blockly.geras.Drawer', 'Blockly.geras.HighlightConstantProvider', 'Blockly.geras.PathObject', 'Blockly.geras.RenderInfo', 'Blockly.utils.object']); @@ -152,15 +146,15 @@ goog.addDependency('../../core/renderers/minimalist/info.js', ['Blockly.minimali goog.addDependency('../../core/renderers/minimalist/renderer.js', ['Blockly.minimalist.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.minimalist.ConstantProvider', 'Blockly.minimalist.Drawer', 'Blockly.minimalist.RenderInfo', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/thrasos/info.js', ['Blockly.thrasos', 'Blockly.thrasos.RenderInfo'], ['Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/thrasos/renderer.js', ['Blockly.thrasos.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.thrasos.RenderInfo', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/zelos/drawer.js', ['Blockly.zelos.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.utils.object', 'Blockly.utils.svgPaths', 'Blockly.zelos.RenderInfo']); -goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.TopRow']); +goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.TopRow']); goog.addDependency('../../core/renderers/zelos/marker_svg.js', ['Blockly.zelos.MarkerSvg'], ['Blockly.blockRendering.MarkerSvg', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/zelos/measurables/inputs.js', ['Blockly.zelos.StatementInput'], ['Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/measurables/row_elements.js', ['Blockly.zelos.RightConnectionShape'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/measurables/rows.js', ['Blockly.zelos.BottomRow', 'Blockly.zelos.TopRow'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.TopRow', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/path_object.js', ['Blockly.zelos.PathObject'], ['Blockly.blockRendering.PathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider']); -goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); +goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); @@ -196,7 +190,7 @@ goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); 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'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); @@ -213,7 +207,7 @@ goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCom goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From 12636da1824cce1eb429d61ca974556e2b1208cb Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 21 Jul 2021 15:47:55 -0700 Subject: [PATCH 196/313] Reorder some requires and rebuild --- core/connection_checker.js | 2 +- core/internal_constants.js | 1 + tests/deps.js | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 5dcaef376..8b2abfaab 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -16,10 +16,10 @@ goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); -const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); +const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); /** diff --git a/core/internal_constants.js b/core/internal_constants.js index b5a8cd568..b97c723b4 100644 --- a/core/internal_constants.js +++ b/core/internal_constants.js @@ -8,6 +8,7 @@ * @fileoverview Module that provides constants for use inside Blockly. Do not * use these constants outside of the core library. * @author fenichel@google.com (Rachel Fenichel) + * @package */ 'use strict'; diff --git a/tests/deps.js b/tests/deps.js index 2d1386395..74d330e51 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); @@ -48,9 +48,9 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -80,6 +80,7 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid 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'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_collapsible_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem'], ['Blockly.ISelectableToolboxItem'], {'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'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); @@ -93,18 +94,19 @@ goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.I 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'}); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); +goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'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'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); @@ -122,7 +124,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); @@ -190,7 +192,7 @@ goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); 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'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); From c6650f0b8313b9ab93cf8ce3a2badd7a03e8c997 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Wed, 21 Jul 2021 16:53:08 -0700 Subject: [PATCH 197/313] Remove need for require instead of requireType for Block in ASTNode (#5157) --- core/keyboard_nav/ast_node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 332e9af8c..d86a22a4c 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -418,7 +418,7 @@ Blockly.ASTNode.prototype.findPrevForField_ = function() { */ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); - if (!(curLocation instanceof Blockly.Block)) { + if (curLocation.getSourceBlock) { curLocation = /** @type {!Blockly.IASTNodeLocationWithBlock} */ ( curLocation).getSourceBlock(); } From f1a41023d9a21ccd121c10aea22eb897a9a95925 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:27:35 -0700 Subject: [PATCH 198/313] Migrate core/field_registry.js to ES6 const/let --- core/field_registry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_registry.js b/core/field_registry.js index 7f431ff7d..463308d3e 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -54,7 +54,7 @@ Blockly.fieldRegistry.unregister = function(type) { * @package */ Blockly.fieldRegistry.fromJson = function(options) { - var fieldObject = /** @type {?Blockly.IRegistrableField} */ ( + const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); if (!fieldObject) { console.warn('Blockly could not create a field of type ' + options['type'] + From 063dc8b804af6caa117afbe361b5cfde7ec6fd22 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:30:54 -0700 Subject: [PATCH 199/313] Migrate core/field_registry.js to goog.module --- core/field_registry.js | 14 +++++++++----- tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index 463308d3e..f1c342579 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.fieldRegistry'); +goog.module('Blockly.fieldRegistry'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.registry'); @@ -31,17 +32,19 @@ goog.requireType('Blockly.IRegistrableField'); * registered, or the fieldClass is not an object containing a fromJson * function. */ -Blockly.fieldRegistry.register = function(type, fieldClass) { +const register = function(type, fieldClass) { Blockly.registry.register(Blockly.registry.Type.FIELD, type, fieldClass); }; +exports.register = register; /** * Unregisters the field registered with the given type. * @param {string} type The field type name as used in the JSON definition. */ -Blockly.fieldRegistry.unregister = function(type) { +const unregister = function(type) { Blockly.registry.unregister(Blockly.registry.Type.FIELD, type); }; +exports.unregister = unregister; /** * Construct a Field from a JSON arg object. @@ -51,9 +54,8 @@ Blockly.fieldRegistry.unregister = function(type) { * to the field type. * @return {?Blockly.Field} The new field instance or null if a field wasn't * found with the given type name - * @package */ -Blockly.fieldRegistry.fromJson = function(options) { +const fromJson = function(options) { const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); if (!fieldObject) { @@ -65,3 +67,5 @@ Blockly.fieldRegistry.fromJson = function(options) { } return fieldObject.fromJson(options); }; +/** @package */ +exports.fromJson = fromJson; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..2cb4d384f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -58,7 +58,7 @@ goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockl goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); +goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); From 222b23480253e7a35e0b426baa2a9fa07b966ed2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:34:55 -0700 Subject: [PATCH 200/313] Migrate core/field_registry.js to named requires --- core/field_registry.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index f1c342579..1ae36d903 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -15,25 +15,26 @@ goog.module('Blockly.fieldRegistry'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.registry'); - -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IRegistrableField'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const IRegistrableField = goog.requireType('Blockly.IRegistrableField'); +const registry = goog.require('Blockly.registry'); /** * Registers a field type. - * Blockly.fieldRegistry.fromJson uses this registry to + * fieldRegistry.fromJson uses this registry to * find the appropriate field type. * @param {string} type The field type name as used in the JSON definition. - * @param {!Blockly.IRegistrableField} fieldClass The field class containing a + * @param {!IRegistrableField} fieldClass The field class containing a * fromJson function that can construct an instance of the field. * @throws {Error} if the type name is empty, the field is already * registered, or the fieldClass is not an object containing a fromJson * function. */ const register = function(type, fieldClass) { - Blockly.registry.register(Blockly.registry.Type.FIELD, type, fieldClass); + registry.register(registry.Type.FIELD, type, fieldClass); }; exports.register = register; @@ -42,22 +43,22 @@ exports.register = register; * @param {string} type The field type name as used in the JSON definition. */ const unregister = function(type) { - Blockly.registry.unregister(Blockly.registry.Type.FIELD, type); + registry.unregister(registry.Type.FIELD, type); }; exports.unregister = unregister; /** * Construct a Field from a JSON arg object. * Finds the appropriate registered field by the type name as registered using - * Blockly.fieldRegistry.register. + * fieldRegistry.register. * @param {!Object} options A JSON object with a type and options specific * to the field type. - * @return {?Blockly.Field} The new field instance or null if a field wasn't + * @return {?Field} The new field instance or null if a field wasn't * found with the given type name */ const fromJson = function(options) { - const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( - Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); + const fieldObject = /** @type {?IRegistrableField} */ ( + registry.getObject(registry.Type.FIELD, options['type'])); if (!fieldObject) { console.warn('Blockly could not create a field of type ' + options['type'] + '. The field is probably not being registered. This could be because' + From 223ec1dd6c717dc12ccf1e9d78f6a4eb783f93e9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:35:25 -0700 Subject: [PATCH 201/313] clang-format core/field_registry.js --- core/field_registry.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index 1ae36d903..97c149346 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -58,12 +58,13 @@ exports.unregister = unregister; */ const fromJson = function(options) { const fieldObject = /** @type {?IRegistrableField} */ ( - registry.getObject(registry.Type.FIELD, options['type'])); + registry.getObject(registry.Type.FIELD, options['type'])); if (!fieldObject) { - console.warn('Blockly could not create a field of type ' + options['type'] + - '. The field is probably not being registered. This could be because' + - ' the file is not loaded, the field does not register itself (Issue' + - ' #1584), or the registration is not being reached.'); + console.warn( + 'Blockly could not create a field of type ' + options['type'] + + '. The field is probably not being registered. This could be because' + + ' the file is not loaded, the field does not register itself (Issue' + + ' #1584), or the registration is not being reached.'); return null; } return fieldObject.fromJson(options); From c3eaf1afc5061f8d20665355b070724e2acfd584 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:44:28 -0700 Subject: [PATCH 202/313] Migrate core/field_textinput.js to ES6 const/let --- core/field_textinput.js | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index b2153b65e..c4c55dfcf 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -109,7 +109,7 @@ Blockly.FieldTextInput.prototype.DEFAULT_VALUE = ''; * @nocollapse */ Blockly.FieldTextInput.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -150,12 +150,12 @@ Blockly.FieldTextInput.prototype.initView = function() { if (this.getConstants().FULL_BLOCK_FIELDS) { // Step one: figure out if this is the only field on this block. // Rendering is quite different in that case. - var nFields = 0; - var nConnections = 0; + let nFields = 0; + let nConnections = 0; // Count the number of fields, excluding text fields - for (var i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { - for (var j = 0; (input.fieldRow[j]); j++) { + for (let i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { + for (let j = 0; (input.fieldRow[j]); j++) { nFields ++; } if (input.connection) { @@ -203,7 +203,7 @@ Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { if (this.isBeingEdited_) { this.isTextValid_ = false; - var oldValue = this.value_; + const oldValue = this.value_; // Revert value when the text becomes invalid. this.value_ = this.htmlInput_.untypedDefaultValue_; if (this.sourceBlock_ && Blockly.Events.isEnabled()) { @@ -257,7 +257,7 @@ Blockly.FieldTextInput.prototype.render_ = function() { // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { this.resizeEditor_(); - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); Blockly.utils.aria.setState(htmlInput, @@ -296,7 +296,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; - var quietInput = opt_quietInput || false; + const quietInput = opt_quietInput || false; if (!quietInput && (Blockly.utils.userAgent.MOBILE || Blockly.utils.userAgent.ANDROID || Blockly.utils.userAgent.IPAD)) { @@ -343,28 +343,28 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { */ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { Blockly.Events.setGroup(true); - var div = Blockly.WidgetDiv.DIV; + const div = Blockly.WidgetDiv.DIV; Blockly.utils.dom.addClass(this.getClickTarget_(), 'editing'); - var htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); + const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); - var scale = this.workspace_.getScale(); - var fontSize = + const scale = this.workspace_.getScale(); + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - var borderRadius = + let borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { - var bBox = this.getScaledBBox(); + const bBox = this.getScaledBBox(); // Override border radius. borderRadius = (bBox.bottom - bBox.top) / 2 + 'px'; // Pull stroke colour from the existing shadow block - var strokeColour = this.sourceBlock_.getParent() ? + const strokeColour = this.sourceBlock_.getParent() ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; htmlInput.style.border = (1 * scale) + 'px solid ' + strokeColour; @@ -409,7 +409,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { // Actual disposal. this.unbindInputEvents_(); - var style = Blockly.WidgetDiv.DIV.style; + const style = Blockly.WidgetDiv.DIV.style; style.width = 'auto'; style.height = 'auto'; style.fontSize = ''; @@ -477,11 +477,11 @@ Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { * @private */ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { - var text = this.htmlInput_.value; + const text = this.htmlInput_.value; if (text !== this.htmlInput_.oldValue_) { this.htmlInput_.oldValue_ = text; - var value = this.getValueFromEditorText_(text); + const value = this.getValueFromEditorText_(text); this.setValue(value); this.forceRerender(); this.resizeEditor_(); @@ -512,15 +512,15 @@ Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { * @protected */ Blockly.FieldTextInput.prototype.resizeEditor_ = function() { - var div = Blockly.WidgetDiv.DIV; - var bBox = this.getScaledBBox(); + const div = Blockly.WidgetDiv.DIV; + const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; div.style.height = bBox.bottom - bBox.top + 'px'; // In RTL mode block fields and LTR input fields the left edge moves, // whereas the right edge is fixed. Reposition the editor. - var x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; - var xy = new Blockly.utils.Coordinate(x, bBox.top); + const x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; + const xy = new Blockly.utils.Coordinate(x, bBox.top); div.style.left = xy.x + 'px'; div.style.top = xy.y + 'px'; From d2a43460d0de014ee671de42f123a6f4ae1bc523 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:49:08 -0700 Subject: [PATCH 203/313] Migrate core/field_textinput.js to goog.module --- core/field_textinput.js | 77 +++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index c4c55dfcf..4585ba382 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldTextInput'); +goog.module('Blockly.FieldTextInput'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.DropDownDiv'); @@ -46,7 +47,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { +const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * Allow browser to spellcheck this field. * @type {boolean} @@ -54,7 +55,7 @@ Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.spellcheck_ = true; - Blockly.FieldTextInput.superClass_.constructor.call(this, + FieldTextInput.superClass_.constructor.call(this, opt_value, opt_validator, opt_config); /** @@ -91,24 +92,24 @@ Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.workspace_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldTextInput, Blockly.Field); +Blockly.utils.object.inherits(FieldTextInput, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldTextInput.prototype.DEFAULT_VALUE = ''; +FieldTextInput.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldTextInput from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and spellcheck). - * @return {!Blockly.FieldTextInput} The new field instance. + * @return {!FieldTextInput} The new field instance. * @package * @nocollapse */ -Blockly.FieldTextInput.fromJson = function(options) { +FieldTextInput.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. @@ -120,24 +121,24 @@ Blockly.FieldTextInput.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldTextInput.prototype.SERIALIZABLE = true; +FieldTextInput.prototype.SERIALIZABLE = true; /** * Pixel size of input border radius. * Should match blocklyText's border-radius in CSS. */ -Blockly.FieldTextInput.BORDERRADIUS = 4; +FieldTextInput.BORDERRADIUS = 4; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldTextInput.prototype.CURSOR = 'text'; +FieldTextInput.prototype.CURSOR = 'text'; /** * @override */ -Blockly.FieldTextInput.prototype.configure_ = function(config) { - Blockly.FieldTextInput.superClass_.configure_.call(this, config); +FieldTextInput.prototype.configure_ = function(config) { + FieldTextInput.superClass_.configure_.call(this, config); if (typeof config['spellcheck'] == 'boolean') { this.spellcheck_ = config['spellcheck']; } @@ -146,7 +147,7 @@ Blockly.FieldTextInput.prototype.configure_ = function(config) { /** * @override */ -Blockly.FieldTextInput.prototype.initView = function() { +FieldTextInput.prototype.initView = function() { if (this.getConstants().FULL_BLOCK_FIELDS) { // Step one: figure out if this is the only field on this block. // Rendering is quite different in that case. @@ -184,7 +185,7 @@ Blockly.FieldTextInput.prototype.initView = function() { * @return {*} A valid string, or null if invalid. * @protected */ -Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { +FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -200,7 +201,7 @@ Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { * the htmlInput_. * @protected */ -Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { +FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { if (this.isBeingEdited_) { this.isTextValid_ = false; const oldValue = this.value_; @@ -221,7 +222,7 @@ Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { * that this is a string. * @protected */ -Blockly.FieldTextInput.prototype.doValueUpdate_ = function(newValue) { +FieldTextInput.prototype.doValueUpdate_ = function(newValue) { this.isTextValid_ = true; this.value_ = newValue; if (!this.isBeingEdited_) { @@ -234,7 +235,7 @@ Blockly.FieldTextInput.prototype.doValueUpdate_ = function(newValue) { * Updates text field to match the colour/style of the block. * @package */ -Blockly.FieldTextInput.prototype.applyColour = function() { +FieldTextInput.prototype.applyColour = function() { if (this.sourceBlock_ && this.getConstants().FULL_BLOCK_FIELDS) { if (this.borderRect_) { this.borderRect_.setAttribute('stroke', @@ -251,8 +252,8 @@ Blockly.FieldTextInput.prototype.applyColour = function() { * field's value. * @protected */ -Blockly.FieldTextInput.prototype.render_ = function() { - Blockly.FieldTextInput.superClass_.render_.call(this); +FieldTextInput.prototype.render_ = function() { + FieldTextInput.superClass_.render_.call(this); // This logic is done in render_ rather than doValueInvalid_ or // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { @@ -274,7 +275,7 @@ Blockly.FieldTextInput.prototype.render_ = function() { * Set whether this field is spellchecked by the browser. * @param {boolean} check True if checked. */ -Blockly.FieldTextInput.prototype.setSpellcheck = function(check) { +FieldTextInput.prototype.setSpellcheck = function(check) { if (check == this.spellcheck_) { return; } @@ -292,7 +293,7 @@ Blockly.FieldTextInput.prototype.setSpellcheck = function(check) { * focus. Defaults to false. * @protected */ -Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, +FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; @@ -311,7 +312,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, * Mobile browsers have issues with in-line textareas (focus and keyboards). * @private */ -Blockly.FieldTextInput.prototype.showPromptEditor_ = function() { +FieldTextInput.prototype.showPromptEditor_ = function() { Blockly.prompt(Blockly.Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { this.setValue(this.getValueFromEditorText_(text)); @@ -324,7 +325,7 @@ Blockly.FieldTextInput.prototype.showPromptEditor_ = function() { * focus. * @private */ -Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { +FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { Blockly.WidgetDiv.show( this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); @@ -341,7 +342,7 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { * @return {!HTMLElement} The newly created text input editor. * @protected */ -Blockly.FieldTextInput.prototype.widgetCreate_ = function() { +FieldTextInput.prototype.widgetCreate_ = function() { Blockly.Events.setGroup(true); const div = Blockly.WidgetDiv.DIV; @@ -356,7 +357,7 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; let borderRadius = - (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + (FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { const bBox = this.getScaledBBox(); @@ -395,7 +396,7 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { * DOM-references belonging to the editor. * @protected */ -Blockly.FieldTextInput.prototype.widgetDispose_ = function() { +FieldTextInput.prototype.widgetDispose_ = function() { // Non-disposal related things that we do when the editor closes. this.isBeingEdited_ = false; this.isTextValid_ = true; @@ -426,7 +427,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { * handlers will be bound. * @protected */ -Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { +FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { // Trap Enter without IME and Esc to hide. this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); @@ -439,7 +440,7 @@ Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { * Unbind handlers for user input and workspace size changes. * @protected */ -Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() { +FieldTextInput.prototype.unbindInputEvents_ = function() { if (this.onKeyDownWrapper_) { Blockly.browserEvents.unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; @@ -455,7 +456,7 @@ Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() { * @param {!Event} e Keyboard event. * @protected */ -Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { +FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { if (e.keyCode == Blockly.utils.KeyCodes.ENTER) { Blockly.WidgetDiv.hide(); Blockly.DropDownDiv.hideWithoutAnimation(); @@ -476,7 +477,7 @@ Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { * @param {!Event} _e Keyboard event. * @private */ -Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { +FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { const text = this.htmlInput_.value; if (text !== this.htmlInput_.oldValue_) { this.htmlInput_.oldValue_ = text; @@ -495,7 +496,7 @@ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { * @param {*} newValue New value. * @protected */ -Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { +FieldTextInput.prototype.setEditorValue_ = function(newValue) { this.isDirty_ = true; if (this.isBeingEdited_) { // In the case this method is passed an invalid value, we still @@ -511,7 +512,7 @@ Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { * Resize the editor to fit the text. * @protected */ -Blockly.FieldTextInput.prototype.resizeEditor_ = function() { +FieldTextInput.prototype.resizeEditor_ = function() { const div = Blockly.WidgetDiv.DIV; const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; @@ -531,7 +532,7 @@ Blockly.FieldTextInput.prototype.resizeEditor_ = function() { * @return {boolean} True if the field is tab navigable. * @override */ -Blockly.FieldTextInput.prototype.isTabNavigable = function() { +FieldTextInput.prototype.isTabNavigable = function() { return true; }; @@ -544,7 +545,7 @@ Blockly.FieldTextInput.prototype.isTabNavigable = function() { * @protected * @override */ -Blockly.FieldTextInput.prototype.getText_ = function() { +FieldTextInput.prototype.getText_ = function() { if (this.isBeingEdited_ && this.htmlInput_) { // We are currently editing, return the HTML input value instead. return this.htmlInput_.value; @@ -561,7 +562,7 @@ Blockly.FieldTextInput.prototype.getText_ = function() { * @return {string} The text to show on the HTML input. * @protected */ -Blockly.FieldTextInput.prototype.getEditorText_ = function(value) { +FieldTextInput.prototype.getEditorText_ = function(value) { return String(value); }; @@ -575,8 +576,10 @@ Blockly.FieldTextInput.prototype.getEditorText_ = function(value) { * @return {*} The value to store. * @protected */ -Blockly.FieldTextInput.prototype.getValueFromEditorText_ = function(text) { +FieldTextInput.prototype.getValueFromEditorText_ = function(text) { return text; }; -Blockly.fieldRegistry.register('field_input', Blockly.FieldTextInput); +Blockly.fieldRegistry.register('field_input', FieldTextInput); + +exports = FieldTextInput; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..0e96aa2c3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -59,7 +59,7 @@ goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabe goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); -goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); From 9134d45d94e3d3506e7b1b9d3bb2bac18d8b45b8 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:35:59 -0700 Subject: [PATCH 204/313] Migrate core/menu.js to ES6 const/let --- core/menu.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/core/menu.js b/core/menu.js index 97f47248a..011199252 100644 --- a/core/menu.js +++ b/core/menu.js @@ -118,7 +118,8 @@ Blockly.Menu.prototype.addChild = function(menuItem) { * @param {!Element} container Element upon which to append this menu. */ Blockly.Menu.prototype.render = function(container) { - var element = /** @type {!HTMLDivElement} */ (document.createElement('div')); + const element = /** @type {!HTMLDivElement} */ (document.createElement( + 'div')); // goog-menu is deprecated, use blocklyMenu. May 2020. element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; @@ -128,7 +129,7 @@ Blockly.Menu.prototype.render = function(container) { this.element_ = element; // Add menu items. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { element.appendChild(menuItem.createDom()); } @@ -161,7 +162,7 @@ Blockly.Menu.prototype.getElement = function() { * @package */ Blockly.Menu.prototype.focus = function() { - var el = this.getElement(); + const el = this.getElement(); if (el) { el.focus({preventScroll:true}); Blockly.utils.dom.addClass(el, 'blocklyFocused'); @@ -173,7 +174,7 @@ Blockly.Menu.prototype.focus = function() { * @private */ Blockly.Menu.prototype.blur_ = function() { - var el = this.getElement(); + const el = this.getElement(); if (el) { el.blur(); Blockly.utils.dom.removeClass(el, 'blocklyFocused'); @@ -216,7 +217,7 @@ Blockly.Menu.prototype.dispose = function() { } // Remove menu items. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { menuItem.dispose(); } this.element_ = null; @@ -232,7 +233,7 @@ Blockly.Menu.prototype.dispose = function() { * @private */ Blockly.Menu.prototype.getMenuItem_ = function(elem) { - var menuElem = this.getElement(); + const menuElem = this.getElement(); // Node might be the menu border (resulting in no associated menu item), or // a menu item's div, or some element within the menu item. // Walk up parents until one meets either the menu's root element, or @@ -240,7 +241,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { while (elem && elem != menuElem) { if (Blockly.utils.dom.hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { return menuItem; } @@ -259,7 +260,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { * @package */ Blockly.Menu.prototype.setHighlighted = function(item) { - var currentHighlighted = this.highlightedItem_; + const currentHighlighted = this.highlightedItem_; if (currentHighlighted) { currentHighlighted.setHighlighted(false); this.highlightedItem_ = null; @@ -269,7 +270,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { this.highlightedItem_ = item; // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. - var el = /** @type {!Element} */ (this.getElement()); + const el = /** @type {!Element} */ (this.getElement()); Blockly.utils.style.scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); @@ -284,7 +285,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { * @package */ Blockly.Menu.prototype.highlightNext = function() { - var index = this.menuItems_.indexOf(this.highlightedItem_); + const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index, 1); }; @@ -294,7 +295,7 @@ Blockly.Menu.prototype.highlightNext = function() { * @package */ Blockly.Menu.prototype.highlightPrevious = function() { - var index = this.menuItems_.indexOf(this.highlightedItem_); + const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1); }; @@ -322,8 +323,8 @@ Blockly.Menu.prototype.highlightLast_ = function() { * @private */ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { - var index = startIndex + delta; - var menuItem; + let index = startIndex + delta; + let menuItem; while ((menuItem = this.menuItems_[index])) { if (menuItem.isEnabled()) { this.setHighlighted(menuItem); @@ -341,7 +342,7 @@ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { * @private */ Blockly.Menu.prototype.handleMouseOver_ = function(e) { - var menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); + const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { if (menuItem.isEnabled()) { @@ -360,11 +361,11 @@ Blockly.Menu.prototype.handleMouseOver_ = function(e) { * @private */ Blockly.Menu.prototype.handleClick_ = function(e) { - var oldCoords = this.openingCoords; + const oldCoords = this.openingCoords; // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; if (oldCoords && typeof e.clientX == 'number') { - var newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); if (Blockly.utils.Coordinate.distance(oldCoords, newCoords) < 1) { // This menu was opened by a mousedown and we're handling the consequent // click event. The coords haven't changed, meaning this was the same @@ -374,7 +375,7 @@ Blockly.Menu.prototype.handleClick_ = function(e) { } } - var menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); + const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { menuItem.performAction(); } @@ -419,7 +420,7 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { return; } - var highlighted = this.highlightedItem_; + const highlighted = this.highlightedItem_; switch (e.keyCode) { case Blockly.utils.KeyCodes.ENTER: case Blockly.utils.KeyCodes.SPACE: @@ -461,8 +462,9 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { * @package */ Blockly.Menu.prototype.getSize = function() { - var menuDom = this.getElement(); - var menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ (menuDom)); + const menuDom = this.getElement(); + const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ + (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; return menuSize; From 4b19c7ecb5bc873009ba7621dff90054b1b141c3 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:41:32 -0700 Subject: [PATCH 205/313] Migrate core/menu.js to goog.module --- core/menu.js | 47 +++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/menu.js b/core/menu.js index 011199252..d1faf4415 100644 --- a/core/menu.js +++ b/core/menu.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Menu'); +goog.module('Blockly.Menu'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.utils.aria'); @@ -27,7 +28,7 @@ goog.requireType('Blockly.utils.Size'); * A basic menu class. * @constructor */ -Blockly.Menu = function() { +const Menu = function() { /** * Array of menu items. * (Nulls are never in the array, but typing the array as nullable prevents @@ -109,7 +110,7 @@ Blockly.Menu = function() { * Add a new menu item to the bottom of this menu. * @param {!Blockly.MenuItem} menuItem Menu item to append. */ -Blockly.Menu.prototype.addChild = function(menuItem) { +Menu.prototype.addChild = function(menuItem) { this.menuItems_.push(menuItem); }; @@ -117,7 +118,7 @@ Blockly.Menu.prototype.addChild = function(menuItem) { * Creates the menu DOM. * @param {!Element} container Element upon which to append this menu. */ -Blockly.Menu.prototype.render = function(container) { +Menu.prototype.render = function(container) { const element = /** @type {!HTMLDivElement} */ (document.createElement( 'div')); // goog-menu is deprecated, use blocklyMenu. May 2020. @@ -153,7 +154,7 @@ Blockly.Menu.prototype.render = function(container) { * @return {?Element} The DOM element. * @package */ -Blockly.Menu.prototype.getElement = function() { +Menu.prototype.getElement = function() { return this.element_; }; @@ -161,7 +162,7 @@ Blockly.Menu.prototype.getElement = function() { * Focus the menu element. * @package */ -Blockly.Menu.prototype.focus = function() { +Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll:true}); @@ -173,7 +174,7 @@ Blockly.Menu.prototype.focus = function() { * Blur the menu element. * @private */ -Blockly.Menu.prototype.blur_ = function() { +Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); @@ -186,14 +187,14 @@ Blockly.Menu.prototype.blur_ = function() { * @param {!Blockly.utils.aria.Role} roleName role name. * @package */ -Blockly.Menu.prototype.setRole = function(roleName) { +Menu.prototype.setRole = function(roleName) { this.roleName_ = roleName; }; /** * Dispose of this menu. */ -Blockly.Menu.prototype.dispose = function() { +Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { Blockly.browserEvents.unbind(this.mouseOverHandler_); @@ -232,7 +233,7 @@ Blockly.Menu.prototype.dispose = function() { * @return {?Blockly.MenuItem} Menu item for which the DOM element belongs to. * @private */ -Blockly.Menu.prototype.getMenuItem_ = function(elem) { +Menu.prototype.getMenuItem_ = function(elem) { const menuElem = this.getElement(); // Node might be the menu border (resulting in no associated menu item), or // a menu item's div, or some element within the menu item. @@ -259,7 +260,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { * @param {?Blockly.MenuItem} item Item to highlight, or null. * @package */ -Blockly.Menu.prototype.setHighlighted = function(item) { +Menu.prototype.setHighlighted = function(item) { const currentHighlighted = this.highlightedItem_; if (currentHighlighted) { currentHighlighted.setHighlighted(false); @@ -284,7 +285,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { * highlighted). * @package */ -Blockly.Menu.prototype.highlightNext = function() { +Menu.prototype.highlightNext = function() { const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index, 1); }; @@ -294,7 +295,7 @@ Blockly.Menu.prototype.highlightNext = function() { * currently highlighted). * @package */ -Blockly.Menu.prototype.highlightPrevious = function() { +Menu.prototype.highlightPrevious = function() { const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1); }; @@ -303,7 +304,7 @@ Blockly.Menu.prototype.highlightPrevious = function() { * Highlights the first highlightable item. * @private */ -Blockly.Menu.prototype.highlightFirst_ = function() { +Menu.prototype.highlightFirst_ = function() { this.highlightHelper_(-1, 1); }; @@ -311,7 +312,7 @@ Blockly.Menu.prototype.highlightFirst_ = function() { * Highlights the last highlightable item. * @private */ -Blockly.Menu.prototype.highlightLast_ = function() { +Menu.prototype.highlightLast_ = function() { this.highlightHelper_(this.menuItems_.length, -1); }; @@ -322,7 +323,7 @@ Blockly.Menu.prototype.highlightLast_ = function() { * @param {number} delta Step direction: 1 to go down, -1 to go up. * @private */ -Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { +Menu.prototype.highlightHelper_ = function(startIndex, delta) { let index = startIndex + delta; let menuItem; while ((menuItem = this.menuItems_[index])) { @@ -341,7 +342,7 @@ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { * @param {!Event} e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseOver_ = function(e) { +Menu.prototype.handleMouseOver_ = function(e) { const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { @@ -360,7 +361,7 @@ Blockly.Menu.prototype.handleMouseOver_ = function(e) { * @param {!Event} e Click event to handle. * @private */ -Blockly.Menu.prototype.handleClick_ = function(e) { +Menu.prototype.handleClick_ = function(e) { const oldCoords = this.openingCoords; // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; @@ -386,7 +387,7 @@ Blockly.Menu.prototype.handleClick_ = function(e) { * @param {!Event} _e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseEnter_ = function(_e) { +Menu.prototype.handleMouseEnter_ = function(_e) { this.focus(); }; @@ -395,7 +396,7 @@ Blockly.Menu.prototype.handleMouseEnter_ = function(_e) { * @param {!Event} _e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseLeave_ = function(_e) { +Menu.prototype.handleMouseLeave_ = function(_e) { if (this.getElement()) { this.blur_(); this.setHighlighted(null); @@ -410,7 +411,7 @@ Blockly.Menu.prototype.handleMouseLeave_ = function(_e) { * @param {!Event} e Key event to handle. * @private */ -Blockly.Menu.prototype.handleKeyEvent_ = function(e) { +Menu.prototype.handleKeyEvent_ = function(e) { if (!this.menuItems_.length) { // Empty menu. return; @@ -461,7 +462,7 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { * @return {!Blockly.utils.Size} Object with width and height properties. * @package */ -Blockly.Menu.prototype.getSize = function() { +Menu.prototype.getSize = function() { const menuDom = this.getElement(); const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ (menuDom)); @@ -469,3 +470,5 @@ Blockly.Menu.prototype.getSize = function() { menuSize.height = menuDom.scrollHeight; return menuSize; }; + +exports = Menu; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..477087f5c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -108,7 +108,7 @@ goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Bl goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); -goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); +goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); From 6dd36c3432c499d862f18096861b9aa35efa7bf6 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:47:09 -0700 Subject: [PATCH 206/313] Migrate core/menu.js named requires --- core/menu.js | 99 ++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/core/menu.js b/core/menu.js index d1faf4415..df7f8058d 100644 --- a/core/menu.js +++ b/core/menu.js @@ -13,15 +13,14 @@ goog.module('Blockly.Menu'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.style'); - -goog.requireType('Blockly.MenuItem'); -goog.requireType('Blockly.utils.Size'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const MenuItem = goog.requireType('Blockly.MenuItem'); +const Size = goog.requireType('Blockly.utils.Size'); +const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); +const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); +const {DOWN, END, ENTER, HOME, PAGE_DOWN, PAGE_UP, SPACE, UP} = goog.require('Blockly.utils.KeyCodes'); +const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); +const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); /** @@ -33,7 +32,7 @@ const Menu = function() { * Array of menu items. * (Nulls are never in the array, but typing the array as nullable prevents * the compiler from objecting to .indexOf(null)) - * @type {!Array} + * @type {!Array} * @private */ this.menuItems_ = []; @@ -42,7 +41,7 @@ const Menu = function() { * Coordinates of the mousedown event that caused this menu to open. Used to * prevent the consequent mouseup event due to a simple click from activating * a menu item immediately. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @package */ this.openingCoords = null; @@ -50,42 +49,42 @@ const Menu = function() { /** * This is the element that we will listen to the real focus events on. * A value of null means no menu item is highlighted. - * @type {?Blockly.MenuItem} + * @type {?MenuItem} * @private */ this.highlightedItem_ = null; /** * Mouse over event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseOverHandler_ = null; /** * Click event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.clickHandler_ = null; /** * Mouse enter event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseEnterHandler_ = null; /** * Mouse leave event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseLeaveHandler_ = null; /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onKeyDownHandler_ = null; @@ -99,7 +98,7 @@ const Menu = function() { /** * ARIA name for this menu. - * @type {?Blockly.utils.aria.Role} + * @type {?Role} * @private */ this.roleName_ = null; @@ -108,7 +107,7 @@ const Menu = function() { /** * Add a new menu item to the bottom of this menu. - * @param {!Blockly.MenuItem} menuItem Menu item to append. + * @param {!MenuItem} menuItem Menu item to append. */ Menu.prototype.addChild = function(menuItem) { this.menuItems_.push(menuItem); @@ -125,7 +124,7 @@ Menu.prototype.render = function(container) { element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; if (this.roleName_) { - Blockly.utils.aria.setRole(element, this.roleName_); + setRole(element, this.roleName_); } this.element_ = element; @@ -135,15 +134,15 @@ Menu.prototype.render = function(container) { } // Add event handlers. - this.mouseOverHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseOverHandler_ = conditionalBind( element, 'mouseover', this, this.handleMouseOver_, true); - this.clickHandler_ = Blockly.browserEvents.conditionalBind( + this.clickHandler_ = conditionalBind( element, 'click', this, this.handleClick_, true); - this.mouseEnterHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseEnterHandler_ = conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); - this.mouseLeaveHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseLeaveHandler_ = conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); - this.onKeyDownHandler_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownHandler_ = conditionalBind( element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); @@ -166,7 +165,7 @@ Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll:true}); - Blockly.utils.dom.addClass(el, 'blocklyFocused'); + addClass(el, 'blocklyFocused'); } }; @@ -178,13 +177,13 @@ Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); - Blockly.utils.dom.removeClass(el, 'blocklyFocused'); + removeClass(el, 'blocklyFocused'); } }; /** * Set the menu accessibility role. - * @param {!Blockly.utils.aria.Role} roleName role name. + * @param {!Role} roleName role name. * @package */ Menu.prototype.setRole = function(roleName) { @@ -197,23 +196,23 @@ Menu.prototype.setRole = function(roleName) { Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { - Blockly.browserEvents.unbind(this.mouseOverHandler_); + unbind(this.mouseOverHandler_); this.mouseOverHandler_ = null; } if (this.clickHandler_) { - Blockly.browserEvents.unbind(this.clickHandler_); + unbind(this.clickHandler_); this.clickHandler_ = null; } if (this.mouseEnterHandler_) { - Blockly.browserEvents.unbind(this.mouseEnterHandler_); + unbind(this.mouseEnterHandler_); this.mouseEnterHandler_ = null; } if (this.mouseLeaveHandler_) { - Blockly.browserEvents.unbind(this.mouseLeaveHandler_); + unbind(this.mouseLeaveHandler_); this.mouseLeaveHandler_ = null; } if (this.onKeyDownHandler_) { - Blockly.browserEvents.unbind(this.onKeyDownHandler_); + unbind(this.onKeyDownHandler_); this.onKeyDownHandler_ = null; } @@ -230,7 +229,7 @@ Menu.prototype.dispose = function() { * Returns the child menu item that owns the given DOM element, * or null if no such menu item is found. * @param {Element} elem DOM element whose owner is to be returned. - * @return {?Blockly.MenuItem} Menu item for which the DOM element belongs to. + * @return {?MenuItem} Menu item for which the DOM element belongs to. * @private */ Menu.prototype.getMenuItem_ = function(elem) { @@ -240,7 +239,7 @@ Menu.prototype.getMenuItem_ = function(elem) { // Walk up parents until one meets either the menu's root element, or // a menu item's div. while (elem && elem != menuElem) { - if (Blockly.utils.dom.hasClass(elem, 'blocklyMenuItem')) { + if (hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { @@ -257,7 +256,7 @@ Menu.prototype.getMenuItem_ = function(elem) { /** * Highlights the given menu item, or clears highlighting if null. - * @param {?Blockly.MenuItem} item Item to highlight, or null. + * @param {?MenuItem} item Item to highlight, or null. * @package */ Menu.prototype.setHighlighted = function(item) { @@ -272,10 +271,10 @@ Menu.prototype.setHighlighted = function(item) { // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. const el = /** @type {!Element} */ (this.getElement()); - Blockly.utils.style.scrollIntoContainerView( + scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - Blockly.utils.aria.setState(el, Blockly.utils.aria.State.ACTIVEDESCENDANT, + setState(el, State.ACTIVEDESCENDANT, item.getId()); } }; @@ -366,8 +365,8 @@ Menu.prototype.handleClick_ = function(e) { // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; if (oldCoords && typeof e.clientX == 'number') { - const newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); - if (Blockly.utils.Coordinate.distance(oldCoords, newCoords) < 1) { + const newCoords = new Coordinate(e.clientX, e.clientY); + if (Coordinate.distance(oldCoords, newCoords) < 1) { // This menu was opened by a mousedown and we're handling the consequent // click event. The coords haven't changed, meaning this was the same // opening event. Don't do the usual behavior because the menu just popped @@ -423,28 +422,28 @@ Menu.prototype.handleKeyEvent_ = function(e) { const highlighted = this.highlightedItem_; switch (e.keyCode) { - case Blockly.utils.KeyCodes.ENTER: - case Blockly.utils.KeyCodes.SPACE: + case ENTER: + case SPACE: if (highlighted) { highlighted.performAction(); } break; - case Blockly.utils.KeyCodes.UP: + case UP: this.highlightPrevious(); break; - case Blockly.utils.KeyCodes.DOWN: + case DOWN: this.highlightNext(); break; - case Blockly.utils.KeyCodes.PAGE_UP: - case Blockly.utils.KeyCodes.HOME: + case PAGE_UP: + case HOME: this.highlightFirst_(); break; - case Blockly.utils.KeyCodes.PAGE_DOWN: - case Blockly.utils.KeyCodes.END: + case PAGE_DOWN: + case END: this.highlightLast_(); break; @@ -459,12 +458,12 @@ Menu.prototype.handleKeyEvent_ = function(e) { /** * Get the size of a rendered menu. - * @return {!Blockly.utils.Size} Object with width and height properties. + * @return {!Size} Object with width and height properties. * @package */ Menu.prototype.getSize = function() { const menuDom = this.getElement(); - const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ + const menuSize = getSize(/** @type {!Element} */ (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; From e5468a50b4e5cca373e72281a482d532ac855172 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:47:58 -0700 Subject: [PATCH 207/313] clang-format core/menu.js --- core/menu.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/core/menu.js b/core/menu.js index df7f8058d..85672f717 100644 --- a/core/menu.js +++ b/core/menu.js @@ -118,8 +118,8 @@ Menu.prototype.addChild = function(menuItem) { * @param {!Element} container Element upon which to append this menu. */ Menu.prototype.render = function(container) { - const element = /** @type {!HTMLDivElement} */ (document.createElement( - 'div')); + const element = + /** @type {!HTMLDivElement} */ (document.createElement('div')); // goog-menu is deprecated, use blocklyMenu. May 2020. element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; @@ -134,16 +134,16 @@ Menu.prototype.render = function(container) { } // Add event handlers. - this.mouseOverHandler_ = conditionalBind( - element, 'mouseover', this, this.handleMouseOver_, true); - this.clickHandler_ = conditionalBind( - element, 'click', this, this.handleClick_, true); + this.mouseOverHandler_ = + conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); + this.clickHandler_ = + conditionalBind(element, 'click', this, this.handleClick_, true); this.mouseEnterHandler_ = conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); this.mouseLeaveHandler_ = conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); - this.onKeyDownHandler_ = conditionalBind( - element, 'keydown', this, this.handleKeyEvent_); + this.onKeyDownHandler_ = + conditionalBind(element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); }; @@ -164,7 +164,7 @@ Menu.prototype.getElement = function() { Menu.prototype.focus = function() { const el = this.getElement(); if (el) { - el.focus({preventScroll:true}); + el.focus({preventScroll: true}); addClass(el, 'blocklyFocused'); } }; @@ -274,8 +274,7 @@ Menu.prototype.setHighlighted = function(item) { scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - setState(el, State.ACTIVEDESCENDANT, - item.getId()); + setState(el, State.ACTIVEDESCENDANT, item.getId()); } }; @@ -464,7 +463,7 @@ Menu.prototype.handleKeyEvent_ = function(e) { Menu.prototype.getSize = function() { const menuDom = this.getElement(); const menuSize = getSize(/** @type {!Element} */ - (menuDom)); + (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; return menuSize; From 296eed06fbd64d7e6b554665a3332806da495b0b Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 09:01:59 -0700 Subject: [PATCH 208/313] Fix build --- core/menu.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/menu.js b/core/menu.js index 85672f717..ac79922cf 100644 --- a/core/menu.js +++ b/core/menu.js @@ -18,7 +18,7 @@ const MenuItem = goog.requireType('Blockly.MenuItem'); const Size = goog.requireType('Blockly.utils.Size'); const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); -const {DOWN, END, ENTER, HOME, PAGE_DOWN, PAGE_UP, SPACE, UP} = goog.require('Blockly.utils.KeyCodes'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); @@ -421,28 +421,28 @@ Menu.prototype.handleKeyEvent_ = function(e) { const highlighted = this.highlightedItem_; switch (e.keyCode) { - case ENTER: - case SPACE: + case KeyCodes.ENTER: + case KeyCodes.SPACE: if (highlighted) { highlighted.performAction(); } break; - case UP: + case KeyCodes.UP: this.highlightPrevious(); break; - case DOWN: + case KeyCodes.DOWN: this.highlightNext(); break; - case PAGE_UP: - case HOME: + case KeyCodes.PAGE_UP: + case KeyCodes.HOME: this.highlightFirst_(); break; - case PAGE_DOWN: - case END: + case KeyCodes.PAGE_DOWN: + case KeyCodes.END: this.highlightLast_(); break; From efdc9e3afab6993d69c80799d263492913310d4a Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 09:11:54 -0700 Subject: [PATCH 209/313] Support filepath as first argument and cleanup (#5168) --- scripts/goog_module/convert-file.sh | 125 ++++++++++++++-------------- 1 file changed, 61 insertions(+), 64 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 1861ad7f3..fa66fe0f9 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -1,7 +1,7 @@ #!/bin/bash ####################################### -# Logging functions +# Logging functions. ####################################### COLOR_NONE="\033[0m" GREEN="\033[0;32m" @@ -20,17 +20,24 @@ warn() { err() { echo -e "${RED}[ERROR]:${COLOR_NONE} $*" >&2 } + ####################################### # Checks whether the provided filepath exists. # Arguments: # The filepath to check for existence. +# Optional: Whether to log an error. ####################################### verify-filepath() { - if [[ ! -f "$1" ]]; then - err "File $1 does not exist" + local filepath="$1" + local no_log="$2" + if [[ ! -f "${filepath}" ]]; then + if [[ -z "${no_log}" || "${no_log}" == 'true' ]]; then + err "File ${filepath} does not exist" + fi return 1 fi } + ####################################### # Creates a commit with a message based on the specified step and file. # Arguments: @@ -40,11 +47,11 @@ verify-filepath() { commit-step() { local step="$1" local filepath="$2" - if [ -z "${step}" ]; then + if [[ -z "${step}" ]]; then err "Missing argument (1-4)" return 1 fi - if [ -z "${filepath}" ]; then + if [[ -z "${filepath}" ]]; then err "Missing argument filepath" return 1 fi @@ -78,6 +85,7 @@ commit-step() { git commit -m "${message}" success "created commit with message: \"${message}\"" } + ####################################### # Runs step 2 of the automated conversion. # Arguments: @@ -85,25 +93,10 @@ commit-step() { ####################################### step2 () { local filepath="$1" - if [ -z "${filepath}" ]; then - err "Missing argument filepath" - return 1 - fi - - inf "Verifying single goog.provide declarations..." - local provide_count=$(grep -o 'goog.provide' ${filepath} | wc -l) - if [[ "${provide_count}" -gt "1" ]]; then - err "Cannot convert file with multiple provides. Please split the file first." - return 1 - elif [[ "${provide_count}" -eq "0" ]]; then - err "Cannot convert file without a provide." - return 1 - fi inf "Updating goog.provide declaration..." perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/g' "${filepath}" - inf "Extracting module name..." local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") if [[ -z "${module_name}" ]]; then @@ -117,11 +110,9 @@ step2 () { inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" - inf 'Updating class properties...' - perl -pi -e 's/^'"${module_name}"'((\.\w+)+) =/'"${class_name}"'\1 =/g' "${filepath}" inf "Updating local references to class..." - perl -pi -e 's/'"${module_name}"'([^'\''])/'"${class_name}"'\1/g' "${filepath}" + perl -pi -e 's/'"${module_name}"'(?!['\''\w])/'"${class_name}"'/g' "${filepath}" inf "Appending class export to end of file..." echo "" >> "${filepath}" @@ -140,20 +131,15 @@ step2 () { perl -pi -e 's/'"${module_name}"'\.([^ ]+)/\1/g' "${filepath}" npm run build:deps - success "Completed automation for step 3. Please manually review and add exports for non-private top-level functions." + success "Completed automation for step 2. Please manually review and add exports for non-private top-level functions." } + ####################################### # Runs step 3 of the automated conversion. # Arguments: # The filepath of the file being converted. ####################################### step3() { - local filepath="$1" - if [ -z "${filepath}" ]; then - err "Missing argument filepath" - return 1 - fi - inf "Extracting module name..." local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") if [[ -z "${module_name}" ]]; then @@ -162,10 +148,10 @@ step3() { fi inf "Extracted module name \"${module_name}\"" - local requires=$(perl -nle'print $& while m{^goog.require(|Type)\('\''(.*)'\''\)}g' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') + local requires=$(perl -nle'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") # Process each require - echo "${requires}" | while read -r require ; do + echo "${requires}" | while read -r require; do inf "Processing require \"${require}\"" local usages=$(perl -nle'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) @@ -179,27 +165,25 @@ step3() { # Detect requires overlap # (ex: Blockly.utils require and Blockly.utils.dom also in requires) local requires_overlap=$(echo "${requires}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ ! -z "${requires_overlap}" ]]; then - while read -r requires_overlap_prop ; do + if [[ -n "${requires_overlap}" ]]; then + while read -r requires_overlap_prop; do properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') done <<<"${requires_overlap}" fi # Detect module name overlap # (ex: Blockly require and Blockly.ContextMenuItems module being converted) local module_overlap=$(echo "${module_name}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ ! -z "${module_overlap}" ]]; then + if [[ -n "${module_overlap}" ]]; then properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') fi properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) - if [[ "${direct_access_count}" -eq "0" && ! -z "${properties_accessed}" ]]; then + if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"" - - inf "Updating require declaration for ${require}..." + inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"..." perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - for require_prop in $(echo "${properties_accessed}"); do + for require_prop in echo "${properties_accessed}"; do inf "Updating references of ${require}.${require_prop} to ${require_prop}..." perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" done @@ -215,26 +199,24 @@ step3() { done local missing_requires=$(perl -nle'print $& while m{(?|-s ] " - echo " -h Display help" - echo " -c Create a commit for the specified step [2-4]" - echo " -s Run the specified step [1-4]" + echo "Usage: $0 [-h] [-c |-s ]" + echo " -h Display help and exit" + echo " -c Create a commit for the specified step [2-4]" + echo " -s Run the specified step [1-4]" } -if [ "$1" = "" ]; then +####################################### +# Main entry point. +####################################### +main { + if [ "$1" = "" ]; then help else - command="$1" + local filepath="" + # Support filepath as first argument. + verify-filepath "${filepath}" "false" + if [[ $? -eq 0 ]]; then + filepath="$1" + shift + fi + + local command="$1" shift case $command in - -h) help $@;; - -c) commit-step $@;; - -s) run-step $@;; - *) help;; + -c) commit-step "$@" "${filepath}" ;; + -s) run-step "$@" "${filepath}" ;; + *) err "INVALID ARGUMENT ${command}";; esac fi +} + +main "$@" From 720059e502394ebc44e4d01686d2b67f652a32f5 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 09:59:02 -0700 Subject: [PATCH 210/313] Fix bugs (#5175) --- scripts/goog_module/convert-file.sh | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index fa66fe0f9..24529dab1 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -257,7 +257,7 @@ run-step() { ####################################### # Prints usage information. ####################################### -help { +help() { echo "Conversion steps:" echo " 1. Use IDE to convert var to let/const" echo " 2. Rewrite the goog.provide statement as goog.module and explicitly enumerate exports" @@ -273,26 +273,26 @@ help { ####################################### # Main entry point. ####################################### -main { +main() { if [ "$1" = "" ]; then - help -else - local filepath="" - # Support filepath as first argument. - verify-filepath "${filepath}" "false" - if [[ $? -eq 0 ]]; then - filepath="$1" - shift - fi + help + else + local filepath="" + # Support filepath as first argument. + verify-filepath "$1" "false" + if [[ $? -eq 0 ]]; then + filepath="$1" + shift + fi - local command="$1" - shift - case $command in - -c) commit-step "$@" "${filepath}" ;; - -s) run-step "$@" "${filepath}" ;; - *) err "INVALID ARGUMENT ${command}";; - esac -fi + local command="$1" + shift + case $command in + -c) commit-step "$@" "${filepath}" ;; + -s) run-step "$@" "${filepath}" ;; + *) err "INVALID ARGUMENT ${command}";; + esac + fi } main "$@" From 9d29bff7138b954351c6ed9bee23504ae40cf795 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 10:01:41 -0700 Subject: [PATCH 211/313] Ask before deconstructing properties for a require (#5169) --- scripts/goog_module/convert-file.sh | 35 +++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 24529dab1..8b6bdfc6f 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -20,6 +20,9 @@ warn() { err() { echo -e "${RED}[ERROR]:${COLOR_NONE} $*" >&2 } +reenter_instructions() { + echo -e "${ORANGE}$*${COLOR_NONE}" >&2 +} ####################################### # Checks whether the provided filepath exists. @@ -180,14 +183,32 @@ step3() { if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"..." - perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - - for require_prop in echo "${properties_accessed}"; do - inf "Updating references of ${require}.${require_prop} to ${require_prop}..." - perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" + local confirm='' + while true; do + read -p "Would you like to deconstruct ${require} into \"{${deconstructed_comma}}\"? (y/n): " yn Date: Thu, 22 Jul 2021 10:21:57 -0700 Subject: [PATCH 212/313] Migrate core/field_textinput.js to named requires --- core/field_textinput.js | 120 ++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 4585ba382..07c0e3282 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -13,25 +13,27 @@ goog.module('Blockly.FieldTextInput'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Events = goog.require('Blockly.Events'); +const Field = goog.require('Blockly.Field'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Msg = goog.require('Blockly.Msg'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const aria = goog.require('Blockly.utils.aria'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {inherits} = goog.require('Blockly.utils.object'); +const {prompt: blocklyPrompt} = goog.require('Blockly'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.Msg'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -44,7 +46,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldTextInput = function(opt_value, opt_validator, opt_config) { @@ -66,14 +68,14 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onKeyDownWrapper_ = null; /** * Key input event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onKeyInputWrapper_ = null; @@ -87,12 +89,12 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * The workspace that this field belongs to. - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} * @protected */ this.workspace_ = null; }; -Blockly.utils.object.inherits(FieldTextInput, Blockly.Field); +inherits(FieldTextInput, Field); /** * The default value for this field. @@ -110,7 +112,7 @@ FieldTextInput.prototype.DEFAULT_VALUE = ''; * @nocollapse */ FieldTextInput.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -207,8 +209,8 @@ FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { const oldValue = this.value_; // Revert value when the text becomes invalid. this.value_ = this.htmlInput_.untypedDefaultValue_; - if (this.sourceBlock_ && Blockly.Events.isEnabled()) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + if (this.sourceBlock_ && Events.isEnabled()) { + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this.sourceBlock_, 'field', this.name || null, oldValue, this.value_)); } } @@ -260,13 +262,13 @@ FieldTextInput.prototype.render_ = function() { this.resizeEditor_(); const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, true); + dom.addClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, true); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, false); + dom.removeClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, false); } } }; @@ -296,11 +298,11 @@ FieldTextInput.prototype.setSpellcheck = function(check) { FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = - (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; + (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; const quietInput = opt_quietInput || false; - if (!quietInput && (Blockly.utils.userAgent.MOBILE || - Blockly.utils.userAgent.ANDROID || - Blockly.utils.userAgent.IPAD)) { + if (!quietInput && (userAgent.MOBILE || + userAgent.ANDROID || + userAgent.IPAD)) { this.showPromptEditor_(); } else { this.showInlineEditor_(quietInput); @@ -313,7 +315,7 @@ FieldTextInput.prototype.showEditor_ = function(_opt_e, * @private */ FieldTextInput.prototype.showPromptEditor_ = function() { - Blockly.prompt(Blockly.Msg['CHANGE_VALUE_TITLE'], this.getText(), + blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { this.setValue(this.getValueFromEditorText_(text)); }.bind(this)); @@ -326,7 +328,7 @@ FieldTextInput.prototype.showPromptEditor_ = function() { * @private */ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { - Blockly.WidgetDiv.show( + WidgetDiv.show( this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); this.isBeingEdited_ = true; @@ -343,10 +345,10 @@ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { * @protected */ FieldTextInput.prototype.widgetCreate_ = function() { - Blockly.Events.setGroup(true); - const div = Blockly.WidgetDiv.DIV; + Events.setGroup(true); + const div = WidgetDiv.DIV; - Blockly.utils.dom.addClass(this.getClickTarget_(), 'editing'); + dom.addClass(this.getClickTarget_(), 'editing'); const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; @@ -406,11 +408,11 @@ FieldTextInput.prototype.widgetDispose_ = function() { if (this.onFinishEditing_) { this.onFinishEditing_(this.value_); } - Blockly.Events.setGroup(false); + Events.setGroup(false); // Actual disposal. this.unbindInputEvents_(); - const style = Blockly.WidgetDiv.DIV.style; + const style = WidgetDiv.DIV.style; style.width = 'auto'; style.height = 'auto'; style.fontSize = ''; @@ -418,7 +420,7 @@ FieldTextInput.prototype.widgetDispose_ = function() { style.boxShadow = ''; this.htmlInput_ = null; - Blockly.utils.dom.removeClass(this.getClickTarget_(), 'editing'); + dom.removeClass(this.getClickTarget_(), 'editing'); }; /** @@ -429,10 +431,10 @@ FieldTextInput.prototype.widgetDispose_ = function() { */ FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { // Trap Enter without IME and Esc to hide. - this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownWrapper_ = browserEvents.conditionalBind( htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); // Resize after every input change. - this.onKeyInputWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyInputWrapper_ = browserEvents.conditionalBind( htmlInput, 'input', this, this.onHtmlInputChange_); }; @@ -442,11 +444,11 @@ FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { */ FieldTextInput.prototype.unbindInputEvents_ = function() { if (this.onKeyDownWrapper_) { - Blockly.browserEvents.unbind(this.onKeyDownWrapper_); + browserEvents.unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; } if (this.onKeyInputWrapper_) { - Blockly.browserEvents.unbind(this.onKeyInputWrapper_); + browserEvents.unbind(this.onKeyInputWrapper_); this.onKeyInputWrapper_ = null; } }; @@ -457,16 +459,16 @@ FieldTextInput.prototype.unbindInputEvents_ = function() { * @protected */ FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { - if (e.keyCode == Blockly.utils.KeyCodes.ENTER) { - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); - } else if (e.keyCode == Blockly.utils.KeyCodes.ESC) { + if (e.keyCode == KeyCodes.ENTER) { + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); + } else if (e.keyCode == KeyCodes.ESC) { this.setValue(this.htmlInput_.untypedDefaultValue_); - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); - } else if (e.keyCode == Blockly.utils.KeyCodes.TAB) { - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); + } else if (e.keyCode == KeyCodes.TAB) { + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); this.sourceBlock_.tab(this, !e.shiftKey); e.preventDefault(); } @@ -513,7 +515,7 @@ FieldTextInput.prototype.setEditorValue_ = function(newValue) { * @protected */ FieldTextInput.prototype.resizeEditor_ = function() { - const div = Blockly.WidgetDiv.DIV; + const div = WidgetDiv.DIV; const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; div.style.height = bBox.bottom - bBox.top + 'px'; @@ -521,7 +523,7 @@ FieldTextInput.prototype.resizeEditor_ = function() { // In RTL mode block fields and LTR input fields the left edge moves, // whereas the right edge is fixed. Reposition the editor. const x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; - const xy = new Blockly.utils.Coordinate(x, bBox.top); + const xy = new Coordinate(x, bBox.top); div.style.left = xy.x + 'px'; div.style.top = xy.y + 'px'; @@ -580,6 +582,6 @@ FieldTextInput.prototype.getValueFromEditorText_ = function(text) { return text; }; -Blockly.fieldRegistry.register('field_input', FieldTextInput); +fieldRegistry.register('field_input', FieldTextInput); exports = FieldTextInput; diff --git a/tests/deps.js b/tests/deps.js index 0e96aa2c3..c68a0441f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -59,7 +59,7 @@ goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabe goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); -goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); From 13272c37136992a91639e6c27ed0fcd100f9cabb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:23:06 -0700 Subject: [PATCH 213/313] clang-format core/field_textinput.js --- core/field_textinput.js | 76 +++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 07c0e3282..cfa891e34 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -44,7 +44,8 @@ goog.require('Blockly.Events.BlockChange'); * changes to the field's value. Takes in a string & returns a validated * string, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -57,8 +58,8 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.spellcheck_ = true; - FieldTextInput.superClass_.constructor.call(this, - opt_value, opt_validator, opt_config); + FieldTextInput.superClass_.constructor.call( + this, opt_value, opt_validator, opt_config); /** * The HTML input element. @@ -159,7 +160,7 @@ FieldTextInput.prototype.initView = function() { // Count the number of fields, excluding text fields for (let i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { for (let j = 0; (input.fieldRow[j]); j++) { - nFields ++; + nFields++; } if (input.connection) { nConnections++; @@ -211,7 +212,8 @@ FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { this.value_ = this.htmlInput_.untypedDefaultValue_; if (this.sourceBlock_ && Events.isEnabled()) { Events.fire(new (Events.get(Events.BLOCK_CHANGE))( - this.sourceBlock_, 'field', this.name || null, oldValue, this.value_)); + this.sourceBlock_, 'field', this.name || null, oldValue, + this.value_)); } } }; @@ -240,11 +242,11 @@ FieldTextInput.prototype.doValueUpdate_ = function(newValue) { FieldTextInput.prototype.applyColour = function() { if (this.sourceBlock_ && this.getConstants().FULL_BLOCK_FIELDS) { if (this.borderRect_) { - this.borderRect_.setAttribute('stroke', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'stroke', this.sourceBlock_.style.colourTertiary); } else { - this.sourceBlock_.pathObject.svgPath.setAttribute('fill', - this.getConstants().FIELD_BORDER_RECT_COLOUR); + this.sourceBlock_.pathObject.svgPath.setAttribute( + 'fill', this.getConstants().FIELD_BORDER_RECT_COLOUR); } } }; @@ -260,15 +262,13 @@ FieldTextInput.prototype.render_ = function() { // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { this.resizeEditor_(); - const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + const htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (!this.isTextValid_) { dom.addClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, true); + aria.setState(htmlInput, aria.State.INVALID, true); } else { dom.removeClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, false); + aria.setState(htmlInput, aria.State.INVALID, false); } } }; @@ -295,14 +295,11 @@ FieldTextInput.prototype.setSpellcheck = function(check) { * focus. Defaults to false. * @protected */ -FieldTextInput.prototype.showEditor_ = function(_opt_e, - opt_quietInput) { - this.workspace_ = - (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; +FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { + this.workspace_ = (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; const quietInput = opt_quietInput || false; - if (!quietInput && (userAgent.MOBILE || - userAgent.ANDROID || - userAgent.IPAD)) { + if (!quietInput && + (userAgent.MOBILE || userAgent.ANDROID || userAgent.IPAD)) { this.showPromptEditor_(); } else { this.showInlineEditor_(quietInput); @@ -315,10 +312,9 @@ FieldTextInput.prototype.showEditor_ = function(_opt_e, * @private */ FieldTextInput.prototype.showPromptEditor_ = function() { - blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), - function(text) { - this.setValue(this.getValueFromEditorText_(text)); - }.bind(this)); + blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { + this.setValue(this.getValueFromEditorText_(text)); + }.bind(this)); }; /** @@ -328,13 +324,12 @@ FieldTextInput.prototype.showPromptEditor_ = function() { * @private */ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { - WidgetDiv.show( - this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); + WidgetDiv.show(this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); this.isBeingEdited_ = true; if (!quietInput) { - this.htmlInput_.focus({preventScroll:true}); + this.htmlInput_.focus({preventScroll: true}); this.htmlInput_.select(); } }; @@ -350,16 +345,15 @@ FieldTextInput.prototype.widgetCreate_ = function() { dom.addClass(this.getClickTarget_(), 'editing'); - const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); + const htmlInput = + /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); const scale = this.workspace_.getScale(); - const fontSize = - (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - let borderRadius = - (FieldTextInput.BORDERRADIUS * scale) + 'px'; + let borderRadius = (FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { const bBox = this.getScaledBBox(); @@ -368,14 +362,14 @@ FieldTextInput.prototype.widgetCreate_ = function() { borderRadius = (bBox.bottom - bBox.top) / 2 + 'px'; // Pull stroke colour from the existing shadow block const strokeColour = this.sourceBlock_.getParent() ? - this.sourceBlock_.getParent().style.colourTertiary : - this.sourceBlock_.style.colourTertiary; + this.sourceBlock_.getParent().style.colourTertiary : + this.sourceBlock_.style.colourTertiary; htmlInput.style.border = (1 * scale) + 'px solid ' + strokeColour; div.style.borderRadius = borderRadius; div.style.transition = 'box-shadow 0.25s ease 0s'; if (this.getConstants().FIELD_TEXTINPUT_BOX_SHADOW) { - div.style.boxShadow = 'rgba(255, 255, 255, 0.3) 0 0 0 ' + - (4 * scale) + 'px'; + div.style.boxShadow = + 'rgba(255, 255, 255, 0.3) 0 0 0 ' + (4 * scale) + 'px'; } } htmlInput.style.borderRadius = borderRadius; @@ -539,10 +533,10 @@ FieldTextInput.prototype.isTabNavigable = function() { }; /** - * Use the `getText_` developer hook to override the field's text representation. - * When we're currently editing, return the current HTML value instead. - * Otherwise, return null which tells the field to use the default behaviour - * (which is a string cast of the field's value). + * Use the `getText_` developer hook to override the field's text + * representation. When we're currently editing, return the current HTML value + * instead. Otherwise, return null which tells the field to use the default + * behaviour (which is a string cast of the field's value). * @return {?string} The HTML value if we're editing, otherwise null. * @protected * @override From f92968b3023759af5e78a887332cf6e5c7d75abd Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:29:34 -0700 Subject: [PATCH 214/313] Migrate core/field_variable.js to ES6 const/let --- core/field_variable.js | 55 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index e5e379c13..e481c728a 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -97,7 +97,7 @@ Blockly.utils.object.inherits(Blockly.FieldVariable, Blockly.FieldDropdown); * @nocollapse */ Blockly.FieldVariable.fromJson = function(options) { - var varName = Blockly.utils.replaceMessageReferences(options['variable']); + const varName = Blockly.utils.replaceMessageReferences(options['variable']); // `this` might be a subclass of FieldVariable if that class doesn't override // the static fromJson method. return new this(varName, undefined, undefined, undefined, options); @@ -130,7 +130,7 @@ Blockly.FieldVariable.prototype.initModel = function() { if (this.variable_) { return; // Initialization already happened. } - var variable = Blockly.Variables.getOrCreateVariablePackage( + const variable = Blockly.Variables.getOrCreateVariablePackage( this.sourceBlock_.workspace, null, this.defaultVariableName, this.defaultType_); @@ -153,14 +153,14 @@ Blockly.FieldVariable.prototype.shouldAddBorderRect_ = function() { * variable field's state. */ Blockly.FieldVariable.prototype.fromXml = function(fieldElement) { - var id = fieldElement.getAttribute('id'); - var variableName = fieldElement.textContent; + const id = fieldElement.getAttribute('id'); + const variableName = fieldElement.textContent; // 'variabletype' should be lowercase, but until July 2019 it was sometimes // recorded as 'variableType'. Thus we need to check for both. - var variableType = fieldElement.getAttribute('variabletype') || + const variableType = fieldElement.getAttribute('variabletype') || fieldElement.getAttribute('variableType') || ''; - var variable = Blockly.Variables.getOrCreateVariablePackage( + const variable = Blockly.Variables.getOrCreateVariablePackage( this.sourceBlock_.workspace, id, variableName, variableType); // This should never happen :) @@ -259,8 +259,8 @@ Blockly.FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null) { return null; } - var newId = /** @type {string} */ (opt_newValue); - var variable = Blockly.Variables.getVariable( + const newId = /** @type {string} */ (opt_newValue); + const variable = Blockly.Variables.getVariable( this.sourceBlock_.workspace, newId); if (!variable) { console.warn('Variable id doesn\'t point to a real variable! ' + @@ -268,7 +268,7 @@ Blockly.FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { return null; } // Type Checks. - var type = variable.type; + const type = variable.type; if (!this.typeIsAllowed_(type)) { console.warn('Variable type doesn\'t match this field! Type was ' + type); return null; @@ -297,11 +297,11 @@ Blockly.FieldVariable.prototype.doValueUpdate_ = function(newId) { * @private */ Blockly.FieldVariable.prototype.typeIsAllowed_ = function(type) { - var typeList = this.getVariableTypes_(); + const typeList = this.getVariableTypes_(); if (!typeList) { return true; // If it's null, all types are valid. } - for (var i = 0; i < typeList.length; i++) { + for (let i = 0; i < typeList.length; i++) { if (type == typeList[i]) { return true; } @@ -317,7 +317,7 @@ Blockly.FieldVariable.prototype.typeIsAllowed_ = function(type) { */ Blockly.FieldVariable.prototype.getVariableTypes_ = function() { // TODO (#1513): Try to avoid calling this every time the field is edited. - var variableTypes = this.variableTypes; + let variableTypes = this.variableTypes; if (variableTypes === null) { // If variableTypes is null, return all variable types. if (this.sourceBlock_ && this.sourceBlock_.workspace) { @@ -327,7 +327,7 @@ Blockly.FieldVariable.prototype.getVariableTypes_ = function() { variableTypes = variableTypes || ['']; if (variableTypes.length == 0) { // Throw an error if variableTypes is an empty list. - var name = this.getText(); + const name = this.getText(); throw Error('\'variableTypes\' of field variable ' + name + ' was an empty list'); } @@ -348,15 +348,16 @@ Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes, opt_defaultType) { // If you expected that the default type would be the same as the only entry // in the variable types array, tell the Blockly team by commenting on #1499. - var defaultType = opt_defaultType || ''; + const defaultType = opt_defaultType || ''; + let variableTypes; // Set the allowable variable types. Null means all types on the workspace. if (opt_variableTypes == null || opt_variableTypes == undefined) { - var variableTypes = null; + variableTypes = null; } else if (Array.isArray(opt_variableTypes)) { - var variableTypes = opt_variableTypes; + variableTypes = opt_variableTypes; // Make sure the default type is valid. - var isInArray = false; - for (var i = 0; i < variableTypes.length; i++) { + let isInArray = false; + for (let i = 0; i < variableTypes.length; i++) { if (variableTypes[i] == defaultType) { isInArray = true; } @@ -395,23 +396,23 @@ Blockly.FieldVariable.dropdownCreate = function() { throw Error('Tried to call dropdownCreate on a variable field with no' + ' variable selected.'); } - var name = this.getText(); - var variableModelList = []; + const name = this.getText(); + let variableModelList = []; if (this.sourceBlock_ && this.sourceBlock_.workspace) { - var variableTypes = this.getVariableTypes_(); + const variableTypes = this.getVariableTypes_(); // Get a copy of the list, so that adding rename and new variable options // doesn't modify the workspace's list. - for (var i = 0; i < variableTypes.length; i++) { - var variableType = variableTypes[i]; - var variables = + for (let i = 0; i < variableTypes.length; i++) { + const variableType = variableTypes[i]; + const variables = this.sourceBlock_.workspace.getVariablesOfType(variableType); variableModelList = variableModelList.concat(variables); } } variableModelList.sort(Blockly.VariableModel.compareByName); - var options = []; - for (var i = 0; i < variableModelList.length; i++) { + const options = []; + for (let i = 0; i < variableModelList.length; i++) { // Set the UUID as the internal representation of the variable. options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } @@ -437,7 +438,7 @@ Blockly.FieldVariable.dropdownCreate = function() { * @protected */ Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { - var id = menuItem.getValue(); + const id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { if (id == Blockly.internalConstants.RENAME_VARIABLE_ID) { From f5de84486f8d10bfa55737f816c7fc3b25690ee7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:32:47 -0700 Subject: [PATCH 215/313] Migrate core/field_variable.js to goog.module --- core/field_variable.js | 67 ++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index e481c728a..11d16532e 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldVariable'); +goog.module('Blockly.FieldVariable'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); @@ -47,7 +48,7 @@ goog.requireType('Blockly.MenuItem'); * @extends {Blockly.FieldDropdown} * @constructor */ -Blockly.FieldVariable = function(varName, opt_validator, opt_variableTypes, +const FieldVariable = function(varName, opt_validator, opt_variableTypes, opt_defaultType, opt_config) { // The FieldDropdown constructor expects the field's initial value to be // the first entry in the menu generator, which it may or may not be. @@ -60,7 +61,7 @@ Blockly.FieldVariable = function(varName, opt_validator, opt_variableTypes, * !function(this:Blockly.FieldDropdown): !Array)} * @protected */ - this.menuGenerator_ = Blockly.FieldVariable.dropdownCreate; + this.menuGenerator_ = FieldVariable.dropdownCreate; /** * The initial variable name passed to this field's constructor, or an @@ -85,18 +86,18 @@ Blockly.FieldVariable = function(varName, opt_validator, opt_variableTypes, this.setTypes_(opt_variableTypes, opt_defaultType); } }; -Blockly.utils.object.inherits(Blockly.FieldVariable, Blockly.FieldDropdown); +Blockly.utils.object.inherits(FieldVariable, Blockly.FieldDropdown); /** * Construct a FieldVariable from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (variable, * variableTypes, and defaultType). - * @return {!Blockly.FieldVariable} The new field instance. + * @return {!FieldVariable} The new field instance. * @package * @nocollapse */ -Blockly.FieldVariable.fromJson = function(options) { +FieldVariable.fromJson = function(options) { const varName = Blockly.utils.replaceMessageReferences(options['variable']); // `this` might be a subclass of FieldVariable if that class doesn't override // the static fromJson method. @@ -108,15 +109,15 @@ Blockly.FieldVariable.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldVariable.prototype.SERIALIZABLE = true; +FieldVariable.prototype.SERIALIZABLE = true; /** * Configure the field based on the given map of options. * @param {!Object} config A map of options to configure the field based on. * @protected */ -Blockly.FieldVariable.prototype.configure_ = function(config) { - Blockly.FieldVariable.superClass_.configure_.call(this, config); +FieldVariable.prototype.configure_ = function(config) { + FieldVariable.superClass_.configure_.call(this, config); this.setTypes_(config['variableTypes'], config['defaultType']); }; @@ -126,7 +127,7 @@ Blockly.FieldVariable.prototype.configure_ = function(config) { * variable rather than let the value be invalid. * @package */ -Blockly.FieldVariable.prototype.initModel = function() { +FieldVariable.prototype.initModel = function() { if (this.variable_) { return; // Initialization already happened. } @@ -141,8 +142,8 @@ Blockly.FieldVariable.prototype.initModel = function() { /** * @override */ -Blockly.FieldVariable.prototype.shouldAddBorderRect_ = function() { - return Blockly.FieldVariable.superClass_.shouldAddBorderRect_.call(this) && +FieldVariable.prototype.shouldAddBorderRect_ = function() { + return FieldVariable.superClass_.shouldAddBorderRect_.call(this) && (!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || this.sourceBlock_.type != 'variables_get'); }; @@ -152,7 +153,7 @@ Blockly.FieldVariable.prototype.shouldAddBorderRect_ = function() { * @param {!Element} fieldElement The element containing information about the * variable field's state. */ -Blockly.FieldVariable.prototype.fromXml = function(fieldElement) { +FieldVariable.prototype.fromXml = function(fieldElement) { const id = fieldElement.getAttribute('id'); const variableName = fieldElement.textContent; // 'variabletype' should be lowercase, but until July 2019 it was sometimes @@ -180,7 +181,7 @@ Blockly.FieldVariable.prototype.fromXml = function(fieldElement) { * field's state. * @return {!Element} The element containing info about the field's state. */ -Blockly.FieldVariable.prototype.toXml = function(fieldElement) { +FieldVariable.prototype.toXml = function(fieldElement) { // Make sure the variable is initialized. this.initModel(); @@ -196,18 +197,18 @@ Blockly.FieldVariable.prototype.toXml = function(fieldElement) { * Attach this field to a block. * @param {!Blockly.Block} block The block containing this field. */ -Blockly.FieldVariable.prototype.setSourceBlock = function(block) { +FieldVariable.prototype.setSourceBlock = function(block) { if (block.isShadow()) { throw Error('Variable fields are not allowed to exist on shadow blocks.'); } - Blockly.FieldVariable.superClass_.setSourceBlock.call(this, block); + FieldVariable.superClass_.setSourceBlock.call(this, block); }; /** * Get the variable's ID. * @return {string} Current variable's ID. */ -Blockly.FieldVariable.prototype.getValue = function() { +FieldVariable.prototype.getValue = function() { return this.variable_ ? this.variable_.getId() : null; }; @@ -216,7 +217,7 @@ Blockly.FieldVariable.prototype.getValue = function() { * @return {string} The selected variable's name, or the empty string if no * variable is selected. */ -Blockly.FieldVariable.prototype.getText = function() { +FieldVariable.prototype.getText = function() { return this.variable_ ? this.variable_.name : ''; }; @@ -228,7 +229,7 @@ Blockly.FieldVariable.prototype.getText = function() { * selected. * @package */ -Blockly.FieldVariable.prototype.getVariable = function() { +FieldVariable.prototype.getVariable = function() { return this.variable_; }; @@ -239,7 +240,7 @@ Blockly.FieldVariable.prototype.getVariable = function() { * a block and workspace at that point. * @return {?Function} Validation function, or null. */ -Blockly.FieldVariable.prototype.getValidator = function() { +FieldVariable.prototype.getValidator = function() { // Validators shouldn't operate on the initial setValue call. // Normally this is achieved by calling setValidator after setValue, but // this is not a possibility with variable fields. @@ -255,7 +256,7 @@ Blockly.FieldVariable.prototype.getValidator = function() { * @return {?string} The validated ID, or null if invalid. * @protected */ -Blockly.FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { +FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null) { return null; } @@ -284,10 +285,10 @@ Blockly.FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { * @param {*} newId The value to be saved. * @protected */ -Blockly.FieldVariable.prototype.doValueUpdate_ = function(newId) { +FieldVariable.prototype.doValueUpdate_ = function(newId) { this.variable_ = Blockly.Variables.getVariable( this.sourceBlock_.workspace, /** @type {string} */ (newId)); - Blockly.FieldVariable.superClass_.doValueUpdate_.call(this, newId); + FieldVariable.superClass_.doValueUpdate_.call(this, newId); }; /** @@ -296,7 +297,7 @@ Blockly.FieldVariable.prototype.doValueUpdate_ = function(newId) { * @return {boolean} True if the type is in the list of allowed types. * @private */ -Blockly.FieldVariable.prototype.typeIsAllowed_ = function(type) { +FieldVariable.prototype.typeIsAllowed_ = function(type) { const typeList = this.getVariableTypes_(); if (!typeList) { return true; // If it's null, all types are valid. @@ -315,7 +316,7 @@ Blockly.FieldVariable.prototype.typeIsAllowed_ = function(type) { * @throws {Error} if variableTypes is an empty array. * @private */ -Blockly.FieldVariable.prototype.getVariableTypes_ = function() { +FieldVariable.prototype.getVariableTypes_ = function() { // TODO (#1513): Try to avoid calling this every time the field is edited. let variableTypes = this.variableTypes; if (variableTypes === null) { @@ -344,7 +345,7 @@ Blockly.FieldVariable.prototype.getVariableTypes_ = function() { * field's value is not explicitly set. Defaults to ''. * @private */ -Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes, +FieldVariable.prototype.setTypes_ = function(opt_variableTypes, opt_defaultType) { // If you expected that the default type would be the same as the only entry // in the variable types array, tell the Blockly team by commenting on #1499. @@ -381,7 +382,7 @@ Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes, * be called by the block. * @package */ -Blockly.FieldVariable.prototype.refreshVariableName = function() { +FieldVariable.prototype.refreshVariableName = function() { this.forceRerender(); }; @@ -389,9 +390,9 @@ Blockly.FieldVariable.prototype.refreshVariableName = function() { * Return a sorted list of variable names for variable dropdown menus. * Include a special option at the end for creating a new variable name. * @return {!Array} Array of variable names/id tuples. - * @this {Blockly.FieldVariable} + * @this {FieldVariable} */ -Blockly.FieldVariable.dropdownCreate = function() { +FieldVariable.dropdownCreate = function() { if (!this.variable_) { throw Error('Tried to call dropdownCreate on a variable field with no' + ' variable selected.'); @@ -437,7 +438,7 @@ Blockly.FieldVariable.dropdownCreate = function() { * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. * @protected */ -Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { +FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { const id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { @@ -462,8 +463,10 @@ Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { * @package * @override */ -Blockly.FieldVariable.prototype.referencesVariables = function() { +FieldVariable.prototype.referencesVariables = function() { return true; }; -Blockly.fieldRegistry.register('field_variable', Blockly.FieldVariable); +Blockly.fieldRegistry.register('field_variable', FieldVariable); + +exports = FieldVariable; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..5b085e8e6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -60,7 +60,7 @@ goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilin goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); +goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); From bd5fd3bb088af2127d717dea81825ba178e86f1e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:37:24 -0700 Subject: [PATCH 216/313] Migrate core/field_variable.js named requires --- core/field_variable.js | 75 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index 11d16532e..1a50f8c88 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -13,22 +13,21 @@ goog.module('Blockly.FieldVariable'); goog.module.declareLegacyNamespace(); +const Block = goog.requireType('Blockly.Block'); +const FieldDropdown = goog.require('Blockly.FieldDropdown'); +const Menu = goog.requireType('Blockly.Menu'); +const MenuItem = goog.requireType('Blockly.MenuItem'); +const Msg = goog.require('Blockly.Msg'); +const Size = goog.require('Blockly.utils.Size'); +const VariableModel = goog.require('Blockly.VariableModel'); +const Variables = goog.require('Blockly.Variables'); +const Xml = goog.require('Blockly.Xml'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const internalConstants = goog.require('Blockly.internalConstants'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.FieldDropdown'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.Msg'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.VariableModel'); -goog.require('Blockly.Variables'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.Menu'); -goog.requireType('Blockly.MenuItem'); /** @@ -45,7 +44,7 @@ goog.requireType('Blockly.MenuItem'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/variable#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldDropdown} + * @extends {FieldDropdown} * @constructor */ const FieldVariable = function(varName, opt_validator, opt_variableTypes, @@ -58,7 +57,7 @@ const FieldVariable = function(varName, opt_validator, opt_variableTypes, * An array of options for a dropdown list, * or a function which generates these options. * @type {(!Array| - * !function(this:Blockly.FieldDropdown): !Array)} + * !function(this:FieldDropdown): !Array)} * @protected */ this.menuGenerator_ = FieldVariable.dropdownCreate; @@ -73,11 +72,11 @@ const FieldVariable = function(varName, opt_validator, opt_variableTypes, /** * The size of the area rendered by the field. - * @type {Blockly.utils.Size} + * @type {Size} * @protected * @override */ - this.size_ = new Blockly.utils.Size(0, 0); + this.size_ = new Size(0, 0); opt_config && this.configure_(opt_config); opt_validator && this.setValidator(opt_validator); @@ -86,7 +85,7 @@ const FieldVariable = function(varName, opt_validator, opt_variableTypes, this.setTypes_(opt_variableTypes, opt_defaultType); } }; -Blockly.utils.object.inherits(FieldVariable, Blockly.FieldDropdown); +inherits(FieldVariable, FieldDropdown); /** * Construct a FieldVariable from a JSON arg object, @@ -98,7 +97,7 @@ Blockly.utils.object.inherits(FieldVariable, Blockly.FieldDropdown); * @nocollapse */ FieldVariable.fromJson = function(options) { - const varName = Blockly.utils.replaceMessageReferences(options['variable']); + const varName = replaceMessageReferences(options['variable']); // `this` might be a subclass of FieldVariable if that class doesn't override // the static fromJson method. return new this(varName, undefined, undefined, undefined, options); @@ -131,7 +130,7 @@ FieldVariable.prototype.initModel = function() { if (this.variable_) { return; // Initialization already happened. } - const variable = Blockly.Variables.getOrCreateVariablePackage( + const variable = Variables.getOrCreateVariablePackage( this.sourceBlock_.workspace, null, this.defaultVariableName, this.defaultType_); @@ -161,7 +160,7 @@ FieldVariable.prototype.fromXml = function(fieldElement) { const variableType = fieldElement.getAttribute('variabletype') || fieldElement.getAttribute('variableType') || ''; - const variable = Blockly.Variables.getOrCreateVariablePackage( + const variable = Variables.getOrCreateVariablePackage( this.sourceBlock_.workspace, id, variableName, variableType); // This should never happen :) @@ -169,7 +168,7 @@ FieldVariable.prototype.fromXml = function(fieldElement) { throw Error('Serialized variable type with id \'' + variable.getId() + '\' had type ' + variable.type + ', and ' + 'does not match variable field that references it: ' + - Blockly.Xml.domToText(fieldElement) + '.'); + Xml.domToText(fieldElement) + '.'); } this.setValue(variable.getId()); @@ -195,7 +194,7 @@ FieldVariable.prototype.toXml = function(fieldElement) { /** * Attach this field to a block. - * @param {!Blockly.Block} block The block containing this field. + * @param {!Block} block The block containing this field. */ FieldVariable.prototype.setSourceBlock = function(block) { if (block.isShadow()) { @@ -225,7 +224,7 @@ FieldVariable.prototype.getText = function() { * Get the variable model for the selected variable. * Not guaranteed to be in the variable map on the workspace (e.g. if accessed * after the variable has been deleted). - * @return {?Blockly.VariableModel} The selected variable, or null if none was + * @return {?VariableModel} The selected variable, or null if none was * selected. * @package */ @@ -261,7 +260,7 @@ FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { return null; } const newId = /** @type {string} */ (opt_newValue); - const variable = Blockly.Variables.getVariable( + const variable = Variables.getVariable( this.sourceBlock_.workspace, newId); if (!variable) { console.warn('Variable id doesn\'t point to a real variable! ' + @@ -286,7 +285,7 @@ FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { * @protected */ FieldVariable.prototype.doValueUpdate_ = function(newId) { - this.variable_ = Blockly.Variables.getVariable( + this.variable_ = Variables.getVariable( this.sourceBlock_.workspace, /** @type {string} */ (newId)); FieldVariable.superClass_.doValueUpdate_.call(this, newId); }; @@ -410,7 +409,7 @@ FieldVariable.dropdownCreate = function() { variableModelList = variableModelList.concat(variables); } } - variableModelList.sort(Blockly.VariableModel.compareByName); + variableModelList.sort(VariableModel.compareByName); const options = []; for (let i = 0; i < variableModelList.length; i++) { @@ -418,12 +417,12 @@ FieldVariable.dropdownCreate = function() { options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } options.push([ - Blockly.Msg['RENAME_VARIABLE'], Blockly.internalConstants.RENAME_VARIABLE_ID + Msg['RENAME_VARIABLE'], internalConstants.RENAME_VARIABLE_ID ]); - if (Blockly.Msg['DELETE_VARIABLE']) { + if (Msg['DELETE_VARIABLE']) { options.push([ - Blockly.Msg['DELETE_VARIABLE'].replace('%1', name), - Blockly.internalConstants.DELETE_VARIABLE_ID + Msg['DELETE_VARIABLE'].replace('%1', name), + internalConstants.DELETE_VARIABLE_ID ]); } @@ -434,20 +433,20 @@ FieldVariable.dropdownCreate = function() { * Handle the selection of an item in the variable dropdown menu. * Special case the 'Rename variable...' and 'Delete variable...' options. * In the rename case, prompt the user for a new name. - * @param {!Blockly.Menu} menu The Menu component clicked. - * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. + * @param {!Menu} menu The Menu component clicked. + * @param {!MenuItem} menuItem The MenuItem selected within menu. * @protected */ FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { const id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { - if (id == Blockly.internalConstants.RENAME_VARIABLE_ID) { + if (id == internalConstants.RENAME_VARIABLE_ID) { // Rename variable. - Blockly.Variables.renameVariable( + Variables.renameVariable( this.sourceBlock_.workspace, this.variable_); return; - } else if (id == Blockly.internalConstants.DELETE_VARIABLE_ID) { + } else if (id == internalConstants.DELETE_VARIABLE_ID) { // Delete variable. this.sourceBlock_.workspace.deleteVariableById(this.variable_.getId()); return; @@ -467,6 +466,6 @@ FieldVariable.prototype.referencesVariables = function() { return true; }; -Blockly.fieldRegistry.register('field_variable', FieldVariable); +fieldRegistry.register('field_variable', FieldVariable); exports = FieldVariable; From 88aa32510c8549a68d0e234146535710a8689b83 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:38:10 -0700 Subject: [PATCH 217/313] clang-format core/field_variable.js --- core/field_variable.js | 56 ++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index 1a50f8c88..f700d4a99 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -42,13 +42,14 @@ goog.require('Blockly.Events.BlockChange'); * @param {string=} opt_defaultType The type of variable to create if this * field's value is not explicitly set. Defaults to ''. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/variable#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/variable#creation} * for a list of properties this parameter supports. * @extends {FieldDropdown} * @constructor */ -const FieldVariable = function(varName, opt_validator, opt_variableTypes, - opt_defaultType, opt_config) { +const FieldVariable = function( + varName, opt_validator, opt_variableTypes, opt_defaultType, opt_config) { // The FieldDropdown constructor expects the field's initial value to be // the first entry in the menu generator, which it may or may not be. // Just do the relevant parts of the constructor. @@ -131,8 +132,8 @@ FieldVariable.prototype.initModel = function() { return; // Initialization already happened. } const variable = Variables.getOrCreateVariablePackage( - this.sourceBlock_.workspace, null, - this.defaultVariableName, this.defaultType_); + this.sourceBlock_.workspace, null, this.defaultVariableName, + this.defaultType_); // Don't call setValue because we don't want to cause a rerender. this.doValueUpdate_(variable.getId()); @@ -143,8 +144,8 @@ FieldVariable.prototype.initModel = function() { */ FieldVariable.prototype.shouldAddBorderRect_ = function() { return FieldVariable.superClass_.shouldAddBorderRect_.call(this) && - (!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || - this.sourceBlock_.type != 'variables_get'); + (!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || + this.sourceBlock_.type != 'variables_get'); }; /** @@ -165,10 +166,11 @@ FieldVariable.prototype.fromXml = function(fieldElement) { // This should never happen :) if (variableType != null && variableType !== variable.type) { - throw Error('Serialized variable type with id \'' + - variable.getId() + '\' had type ' + variable.type + ', and ' + - 'does not match variable field that references it: ' + - Xml.domToText(fieldElement) + '.'); + throw Error( + 'Serialized variable type with id \'' + variable.getId() + + '\' had type ' + variable.type + ', and ' + + 'does not match variable field that references it: ' + + Xml.domToText(fieldElement) + '.'); } this.setValue(variable.getId()); @@ -260,10 +262,10 @@ FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { return null; } const newId = /** @type {string} */ (opt_newValue); - const variable = Variables.getVariable( - this.sourceBlock_.workspace, newId); + const variable = Variables.getVariable(this.sourceBlock_.workspace, newId); if (!variable) { - console.warn('Variable id doesn\'t point to a real variable! ' + + console.warn( + 'Variable id doesn\'t point to a real variable! ' + 'ID was ' + newId); return null; } @@ -328,8 +330,8 @@ FieldVariable.prototype.getVariableTypes_ = function() { if (variableTypes.length == 0) { // Throw an error if variableTypes is an empty list. const name = this.getText(); - throw Error('\'variableTypes\' of field variable ' + - name + ' was an empty list'); + throw Error( + '\'variableTypes\' of field variable ' + name + ' was an empty list'); } return variableTypes; }; @@ -344,8 +346,8 @@ FieldVariable.prototype.getVariableTypes_ = function() { * field's value is not explicitly set. Defaults to ''. * @private */ -FieldVariable.prototype.setTypes_ = function(opt_variableTypes, - opt_defaultType) { +FieldVariable.prototype.setTypes_ = function( + opt_variableTypes, opt_defaultType) { // If you expected that the default type would be the same as the only entry // in the variable types array, tell the Blockly team by commenting on #1499. const defaultType = opt_defaultType || ''; @@ -363,11 +365,13 @@ FieldVariable.prototype.setTypes_ = function(opt_variableTypes, } } if (!isInArray) { - throw Error('Invalid default type \'' + defaultType + '\' in ' + + throw Error( + 'Invalid default type \'' + defaultType + '\' in ' + 'the definition of a FieldVariable'); } } else { - throw Error('\'variableTypes\' was not an array in the definition of ' + + throw Error( + '\'variableTypes\' was not an array in the definition of ' + 'a FieldVariable'); } // Only update the field once all checks pass. @@ -393,7 +397,8 @@ FieldVariable.prototype.refreshVariableName = function() { */ FieldVariable.dropdownCreate = function() { if (!this.variable_) { - throw Error('Tried to call dropdownCreate on a variable field with no' + + throw Error( + 'Tried to call dropdownCreate on a variable field with no' + ' variable selected.'); } const name = this.getText(); @@ -405,7 +410,7 @@ FieldVariable.dropdownCreate = function() { for (let i = 0; i < variableTypes.length; i++) { const variableType = variableTypes[i]; const variables = - this.sourceBlock_.workspace.getVariablesOfType(variableType); + this.sourceBlock_.workspace.getVariablesOfType(variableType); variableModelList = variableModelList.concat(variables); } } @@ -416,9 +421,7 @@ FieldVariable.dropdownCreate = function() { // Set the UUID as the internal representation of the variable. options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } - options.push([ - Msg['RENAME_VARIABLE'], internalConstants.RENAME_VARIABLE_ID - ]); + options.push([Msg['RENAME_VARIABLE'], internalConstants.RENAME_VARIABLE_ID]); if (Msg['DELETE_VARIABLE']) { options.push([ Msg['DELETE_VARIABLE'].replace('%1', name), @@ -443,8 +446,7 @@ FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { if (this.sourceBlock_ && this.sourceBlock_.workspace) { if (id == internalConstants.RENAME_VARIABLE_ID) { // Rename variable. - Variables.renameVariable( - this.sourceBlock_.workspace, this.variable_); + Variables.renameVariable(this.sourceBlock_.workspace, this.variable_); return; } else if (id == internalConstants.DELETE_VARIABLE_ID) { // Delete variable. From ee565f16d6899cbe857529194a4d7852d0effdf2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:41:55 -0700 Subject: [PATCH 218/313] Silence unused variable warnings for requires used in JSDoc --- core/interfaces/i_collapsible_toolbox_item.js | 2 ++ core/interfaces/i_registrable_field.js | 1 + core/interfaces/i_selectable_toolbox_item.js | 2 ++ core/keyboard_nav/tab_navigate_cursor.js | 1 + core/renderers/common/info.js | 8 ++++++++ 5 files changed, 14 insertions(+) diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js index 732c7aab7..45bd3ae3e 100644 --- a/core/interfaces/i_collapsible_toolbox_item.js +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -14,7 +14,9 @@ goog.module('Blockly.ICollapsibleToolboxItem'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const ISelectableToolboxItem = goog.require('Blockly.ISelectableToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 2c8c005bd..c9d04325d 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -14,6 +14,7 @@ goog.module('Blockly.IRegistrableField'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js index 2addc7b9e..cefe35740 100644 --- a/core/interfaces/i_selectable_toolbox_item.js +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -14,7 +14,9 @@ goog.module('Blockly.ISelectableToolboxItem'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.require('Blockly.IToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const {FlyoutItemInfoArray} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 3b82267a1..77fc5a2a2 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -16,6 +16,7 @@ goog.module.declareLegacyNamespace(); const ASTNode = goog.require('Blockly.ASTNode'); const BasicCursor = goog.require('Blockly.BasicCursor'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); const {inherits} = goog.require('Blockly.utils.object'); diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 73e02dfff..0f8548192 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -13,25 +13,33 @@ goog.module('Blockly.blockRendering.RenderInfo'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const BottomRow = goog.require('Blockly.blockRendering.BottomRow'); +/* eslint-disable-next-line no-unused-vars */ const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); const ExternalValueInput = goog.require('Blockly.blockRendering.ExternalValueInput'); const Field = goog.require('Blockly.blockRendering.Field'); const Hat = goog.require('Blockly.blockRendering.Hat'); const Icon = goog.require('Blockly.blockRendering.Icon'); const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); +/* eslint-disable-next-line no-unused-vars */ const Input = goog.requireType('Blockly.Input'); const InputRow = goog.require('Blockly.blockRendering.InputRow'); const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); +/* eslint-disable-next-line no-unused-vars */ const Measurable = goog.require('Blockly.blockRendering.Measurable'); const NextConnection = goog.require('Blockly.blockRendering.NextConnection'); const OutputConnection = goog.require('Blockly.blockRendering.OutputConnection'); const PreviousConnection = goog.require('Blockly.blockRendering.PreviousConnection'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +/* eslint-disable-next-line no-unused-vars */ const Renderer = goog.requireType('Blockly.blockRendering.Renderer'); +/* eslint-disable-next-line no-unused-vars */ const RoundCorner = goog.require('Blockly.blockRendering.RoundCorner'); +/* eslint-disable-next-line no-unused-vars */ const Row = goog.require('Blockly.blockRendering.Row'); const SpacerRow = goog.require('Blockly.blockRendering.SpacerRow'); const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); From 48ccc38cbb2c45ea34b796cacf338319d6a721c3 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 10:42:56 -0700 Subject: [PATCH 219/313] Fix destructuring --- core/menu.js | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/core/menu.js b/core/menu.js index ac79922cf..083d76e06 100644 --- a/core/menu.js +++ b/core/menu.js @@ -15,12 +15,12 @@ goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); const MenuItem = goog.requireType('Blockly.MenuItem'); -const Size = goog.requireType('Blockly.utils.Size'); -const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); -const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); -const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); -const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); +const Size = goog.requireType('Blockly.utils.Size'); +const aria = goog.require('Blockly.utils.aria'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const style = goog.require('Blockly.utils.style'); /** @@ -56,35 +56,35 @@ const Menu = function() { /** * Mouse over event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseOverHandler_ = null; /** * Click event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.clickHandler_ = null; /** * Mouse enter event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseEnterHandler_ = null; /** * Mouse leave event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseLeaveHandler_ = null; /** * Key down event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.onKeyDownHandler_ = null; @@ -98,7 +98,7 @@ const Menu = function() { /** * ARIA name for this menu. - * @type {?Role} + * @type {?aria.Role} * @private */ this.roleName_ = null; @@ -124,7 +124,7 @@ Menu.prototype.render = function(container) { element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; if (this.roleName_) { - setRole(element, this.roleName_); + aria.setRole(element, this.roleName_); } this.element_ = element; @@ -135,15 +135,15 @@ Menu.prototype.render = function(container) { // Add event handlers. this.mouseOverHandler_ = - conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); + browserEvents.conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); this.clickHandler_ = - conditionalBind(element, 'click', this, this.handleClick_, true); - this.mouseEnterHandler_ = conditionalBind( + browserEvents.conditionalBind(element, 'click', this, this.handleClick_, true); + this.mouseEnterHandler_ = browserEvents.conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); - this.mouseLeaveHandler_ = conditionalBind( + this.mouseLeaveHandler_ = browserEvents.conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); this.onKeyDownHandler_ = - conditionalBind(element, 'keydown', this, this.handleKeyEvent_); + browserEvents.conditionalBind(element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); }; @@ -165,7 +165,7 @@ Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll: true}); - addClass(el, 'blocklyFocused'); + dom.addClass(el, 'blocklyFocused'); } }; @@ -177,13 +177,13 @@ Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); - removeClass(el, 'blocklyFocused'); + dom.removeClass(el, 'blocklyFocused'); } }; /** * Set the menu accessibility role. - * @param {!Role} roleName role name. + * @param {!aria.Role} roleName role name. * @package */ Menu.prototype.setRole = function(roleName) { @@ -196,23 +196,23 @@ Menu.prototype.setRole = function(roleName) { Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { - unbind(this.mouseOverHandler_); + browserEvents.unbind(this.mouseOverHandler_); this.mouseOverHandler_ = null; } if (this.clickHandler_) { - unbind(this.clickHandler_); + browserEvents.unbind(this.clickHandler_); this.clickHandler_ = null; } if (this.mouseEnterHandler_) { - unbind(this.mouseEnterHandler_); + browserEvents.unbind(this.mouseEnterHandler_); this.mouseEnterHandler_ = null; } if (this.mouseLeaveHandler_) { - unbind(this.mouseLeaveHandler_); + browserEvents.unbind(this.mouseLeaveHandler_); this.mouseLeaveHandler_ = null; } if (this.onKeyDownHandler_) { - unbind(this.onKeyDownHandler_); + browserEvents.unbind(this.onKeyDownHandler_); this.onKeyDownHandler_ = null; } @@ -239,7 +239,7 @@ Menu.prototype.getMenuItem_ = function(elem) { // Walk up parents until one meets either the menu's root element, or // a menu item's div. while (elem && elem != menuElem) { - if (hasClass(elem, 'blocklyMenuItem')) { + if (dom.hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { @@ -271,10 +271,10 @@ Menu.prototype.setHighlighted = function(item) { // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. const el = /** @type {!Element} */ (this.getElement()); - scrollIntoContainerView( + style.scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - setState(el, State.ACTIVEDESCENDANT, item.getId()); + aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId()); } }; @@ -462,7 +462,7 @@ Menu.prototype.handleKeyEvent_ = function(e) { */ Menu.prototype.getSize = function() { const menuDom = this.getElement(); - const menuSize = getSize(/** @type {!Element} */ + const menuSize = style.getSize(/** @type {!Element} */ (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; From 380cfd5963d3a2e2e235fcccee3ebd02718e1573 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:08:58 -0700 Subject: [PATCH 220/313] Migrate core/flyout_base.js to ES6 const/let --- core/flyout_base.js | 144 +++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 70 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 84d6d3870..3c62ebe51 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -396,7 +396,7 @@ Blockly.Flyout.prototype.isVisible = function() { * @param {boolean} visible True if visible. */ Blockly.Flyout.prototype.setVisible = function(visible) { - var visibilityChanged = (visible != this.isVisible()); + const visibilityChanged = (visible != this.isVisible()); this.isVisible_ = visible; if (visibilityChanged) { @@ -414,7 +414,7 @@ Blockly.Flyout.prototype.setVisible = function(visible) { * @param {boolean} visible Whether the container is visible. */ Blockly.Flyout.prototype.setContainerVisible = function(visible) { - var visibilityChanged = (visible != this.containerVisible_); + const visibilityChanged = (visible != this.containerVisible_); this.containerVisible_ = visible; if (visibilityChanged) { this.updateDisplay_(); @@ -427,7 +427,7 @@ Blockly.Flyout.prototype.setContainerVisible = function(visible) { * @private */ Blockly.Flyout.prototype.updateDisplay_ = function() { - var show = true; + let show = true; if (!this.containerVisible_) { show = false; } else { @@ -453,17 +453,17 @@ Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { this.workspace_.setCachedParentSvgSize(width, height); if (this.svgGroup_.tagName == 'svg') { - var transform = 'translate(' + x + 'px,' + y + 'px)'; + const transform = 'translate(' + x + 'px,' + y + 'px)'; Blockly.utils.dom.setCssTransform(this.svgGroup_, transform); } else { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself - var transform = 'translate(' + x + ',' + y + ')'; + const transform = 'translate(' + x + ',' + y + ')'; this.svgGroup_.setAttribute("transform", transform); } // Update the scrollbar (if one exists). - var scrollbar = this.workspace_.scrollbar; + const scrollbar = this.workspace_.scrollbar; if (scrollbar) { // Set the scrollbars origin to be the top left of the flyout. scrollbar.setOrigin(x, y); @@ -491,7 +491,7 @@ Blockly.Flyout.prototype.hide = function() { } this.setVisible(false); // Delete all the event listeners. - for (var i = 0, listen; (listen = this.listeners_[i]); i++) { + for (let i = 0, listen; (listen = this.listeners_[i]); i++) { Blockly.browserEvents.unbind(listen); } this.listeners_.length = 0; @@ -521,8 +521,8 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { this.setVisible(true); // Parse the Array, Node or NodeList into a a list of flyout items. - var parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); - var flyoutInfo = + const parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); + const flyoutInfo = /** @type {{contents:!Array, gaps:!Array}} */ ( this.createFlyoutInfo_(parsedContent)); @@ -530,9 +530,9 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { // IE 11 is an incompetent browser that fails to fire mouseout events. // When the mouse is over the background, deselect all blocks. - var deselectAll = function() { - var topBlocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = topBlocks[i]); i++) { + const deselectAll = function() { + const topBlocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = topBlocks[i]); i++) { block.removeSelect(); } }; @@ -567,50 +567,54 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { * @private */ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { - var contents = []; - var gaps = []; + const contents = []; + const gaps = []; this.permanentlyDisabled_.length = 0; - var defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; - for (var i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { + const defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; + for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { if (contentInfo['custom']) { - var customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); - var categoryName = customInfo['custom']; - var flyoutDef = this.getDynamicCategoryContents_(categoryName); - var parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ + const customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); + const categoryName = customInfo['custom']; + const flyoutDef = this.getDynamicCategoryContents_(categoryName); + const parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ (Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef)); parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } switch (contentInfo['kind'].toUpperCase()) { - case 'BLOCK': - var blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); - var blockXml = this.getBlockXml_(blockInfo); - var block = this.createBlock_(blockXml); + case 'BLOCK': { + const blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); + const blockXml = this.getBlockXml_(blockInfo); + const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. // - var gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); + const gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); gaps.push(isNaN(gap) ? defaultGap : gap); contents.push({type: 'block', block: block}); break; - case 'SEP': - var sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); + } + case 'SEP': { + const sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); this.addSeparatorGap_(sepInfo, gaps, defaultGap); break; - case 'LABEL': - var labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); + } + case 'LABEL': { + const labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); // A label is a button with different styling. - var label = this.createButton_(labelInfo, /** isLabel */ true); + const label = this.createButton_(labelInfo, /** isLabel */ true); contents.push({type: 'button', button: label}); gaps.push(defaultGap); break; - case 'BUTTON': - var buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); - var button = this.createButton_(buttonInfo, /** isLabel */ false); + } + case 'BUTTON': { + const buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); + const button = this.createButton_(buttonInfo, /** isLabel */ false); contents.push({type: 'button', button: button}); gaps.push(defaultGap); break; + } } } return {contents: contents, gaps: gaps}; @@ -625,13 +629,13 @@ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. - var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( + const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( categoryName); if (typeof fnToApply != 'function') { throw TypeError('Couldn\'t find a callback function when opening' + ' a toolbox category.'); } - var flyoutDef = fnToApply(this.workspace_.targetWorkspace); + const flyoutDef = fnToApply(this.workspace_.targetWorkspace); if (!Array.isArray(flyoutDef)) { throw new TypeError('Result of toolbox category callback must be an array.'); } @@ -651,7 +655,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!Blockly.FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - var curButton = new Blockly.FlyoutButton(this.workspace_, + const curButton = new Blockly.FlyoutButton(this.workspace_, /** @type {!Blockly.WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; @@ -665,7 +669,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @protected */ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { - var curBlock = /** @type {!Blockly.BlockSvg} */ ( + const curBlock = /** @type {!Blockly.BlockSvg} */ ( Blockly.Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. @@ -684,8 +688,8 @@ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { * @private */ Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { - var blockElement = null; - var blockXml = blockInfo['blockxml']; + let blockElement = null; + const blockXml = blockInfo['blockxml']; if (blockXml && typeof blockXml != 'string') { blockElement = blockXml; @@ -718,7 +722,7 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) // // The default gap is 24, can be set larger or smaller. // This overwrites the gap attribute on the previous element. - var newGap = parseInt(sepInfo['gap'], 10); + const newGap = parseInt(sepInfo['gap'], 10); // Ignore gaps before the first block. if (!isNaN(newGap) && gaps.length > 0) { gaps[gaps.length - 1] = newGap; @@ -733,15 +737,15 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) */ Blockly.Flyout.prototype.clearOldBlocks_ = function() { // Delete any blocks from a previous showing. - var oldBlocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = oldBlocks[i]); i++) { + const oldBlocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = oldBlocks[i]); i++) { if (block.workspace == this.workspace_) { block.dispose(false, false); } } // Delete any mats from a previous showing. - for (var j = 0; j < this.mats_.length; j++) { - var rect = this.mats_[j]; + for (let j = 0; j < this.mats_.length; j++) { + const rect = this.mats_[j]; if (rect) { Blockly.Tooltip.unbindMouseEvents(rect); Blockly.utils.dom.removeNode(rect); @@ -749,7 +753,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { } this.mats_.length = 0; // Delete any buttons from a previous showing. - for (var i = 0, button; (button = this.buttons_[i]); i++) { + for (let i = 0, button; (button = this.buttons_[i]); i++) { button.dispose(); } this.buttons_.length = 0; @@ -788,9 +792,9 @@ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { * @private */ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { - var flyout = this; + const flyout = this; return function(e) { - var gesture = flyout.targetWorkspace.getGesture(e); + const gesture = flyout.targetWorkspace.getGesture(e); if (gesture) { gesture.setStartBlock(block); gesture.handleFlyoutStart(e, flyout); @@ -804,7 +808,7 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { * @private */ Blockly.Flyout.prototype.onMouseDown_ = function(e) { - var gesture = this.targetWorkspace.getGesture(e); + const gesture = this.targetWorkspace.getGesture(e); if (gesture) { gesture.handleFlyoutStart(e, this); } @@ -830,9 +834,9 @@ Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { * @package */ Blockly.Flyout.prototype.createBlock = function(originalBlock) { - var newBlock = null; + let newBlock = null; Blockly.Events.disable(); - var variablesBeforeCreation = this.targetWorkspace.getAllVariables(); + const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); this.targetWorkspace.setResizesEnabled(false); try { newBlock = this.placeNewBlock_(originalBlock); @@ -843,14 +847,14 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { // Close the flyout. Blockly.hideChaff(); - var newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, + const newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, variablesBeforeCreation); if (Blockly.Events.isEnabled()) { Blockly.Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. - for (var i = 0; i < newVariables.length; i++) { - var thisVariable = newVariables[i]; + for (let i = 0; i < newVariables.length; i++) { + const thisVariable = newVariables[i]; Blockly.Events.fire( new (Blockly.Events.get(Blockly.Events.VAR_CREATE))(thisVariable)); } @@ -877,7 +881,7 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { * @protected */ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { - var buttonSvg = button.createDom(); + const buttonSvg = button.createDom(); button.moveTo(x, y); button.show(); // Clicking on a flyout button or label is a lot like clicking on the @@ -904,7 +908,7 @@ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. - var rect = Blockly.utils.dom.createSvgElement( + const rect = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'fill-opacity': 0, @@ -931,11 +935,11 @@ Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * @protected */ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { - var blockHW = block.getHeightWidth(); + const blockHW = block.getHeightWidth(); rect.setAttribute('width', blockHW.width); rect.setAttribute('height', blockHW.height); - var blockXY = block.getRelativeToSurfaceXY(); + const blockXY = block.getRelativeToSurfaceXY(); rect.setAttribute('y', blockXY.y); rect.setAttribute('x', this.RTL ? blockXY.x - blockHW.width : blockXY.x); }; @@ -947,10 +951,10 @@ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { * @private */ Blockly.Flyout.prototype.filterForCapacity_ = function() { - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { - var enable = this.targetWorkspace + const enable = this.targetWorkspace .isCapacityAvailable(Blockly.utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); @@ -990,50 +994,50 @@ Blockly.Flyout.prototype.isScrollable = function() { * @private */ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { - var targetWorkspace = this.targetWorkspace; - var svgRootOld = oldBlock.getSvgRoot(); + const targetWorkspace = this.targetWorkspace; + const svgRootOld = oldBlock.getSvgRoot(); if (!svgRootOld) { throw Error('oldBlock is not rendered.'); } // Create the new block by cloning the block in the flyout (via XML). // This cast assumes that the oldBlock can not be an insertion marker. - var xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); + const xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); // The target workspace would normally resize during domToBlock, which will // lead to weird jumps. Save it for terminateDrag. targetWorkspace.setResizesEnabled(false); // Using domToBlock instead of domToWorkspace means that the new block will be // placed at position (0, 0) in main workspace units. - var block = /** @type {!Blockly.BlockSvg} */ + const block = /** @type {!Blockly.BlockSvg} */ (Blockly.Xml.domToBlock(xml, targetWorkspace)); - var svgRootNew = block.getSvgRoot(); + const svgRootNew = block.getSvgRoot(); if (!svgRootNew) { throw Error('block is not rendered.'); } // The offset in pixels between the main workspace's origin and the upper left // corner of the injection div. - var mainOffsetPixels = targetWorkspace.getOriginOffsetInPixels(); + const mainOffsetPixels = targetWorkspace.getOriginOffsetInPixels(); // The offset in pixels between the flyout workspace's origin and the upper // left corner of the injection div. - var flyoutOffsetPixels = this.workspace_.getOriginOffsetInPixels(); + const flyoutOffsetPixels = this.workspace_.getOriginOffsetInPixels(); // The position of the old block in flyout workspace coordinates. - var oldBlockPos = oldBlock.getRelativeToSurfaceXY(); + const oldBlockPos = oldBlock.getRelativeToSurfaceXY(); // The position of the old block in pixels relative to the flyout // workspace's origin. oldBlockPos.scale(this.workspace_.scale); // The position of the old block in pixels relative to the upper left corner // of the injection div. - var oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, + const oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - var finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, + const finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); From 3df8c32594b6583a3f692f16952ea4dc254a83ce Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:11:27 -0700 Subject: [PATCH 221/313] Migrate core/flyout_base.js to goog.module --- core/flyout_base.js | 117 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 61 insertions(+), 58 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 3c62ebe51..18a3ab909 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Flyout'); +goog.module('Blockly.Flyout'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Block'); /** @suppress {extraRequire} */ @@ -55,8 +56,8 @@ goog.requireType('Blockly.utils.Rect'); * @implements {Blockly.IFlyout} * @extends {Blockly.DeleteArea} */ -Blockly.Flyout = function(workspaceOptions) { - Blockly.Flyout.superClass_.constructor.call(this); +const Flyout = function(workspaceOptions) { + Flyout.superClass_.constructor.call(this); workspaceOptions.setMetrics = this.setMetrics_.bind(this); /** @@ -149,41 +150,41 @@ Blockly.Flyout = function(workspaceOptions) { */ this.targetWorkspace = null; }; -Blockly.utils.object.inherits(Blockly.Flyout, Blockly.DeleteArea); +Blockly.utils.object.inherits(Flyout, Blockly.DeleteArea); /** * Does the flyout automatically close when a block is created? * @type {boolean} */ -Blockly.Flyout.prototype.autoClose = true; +Flyout.prototype.autoClose = true; /** * Whether the flyout is visible. * @type {boolean} * @private */ -Blockly.Flyout.prototype.isVisible_ = false; +Flyout.prototype.isVisible_ = false; /** * Whether the workspace containing this flyout is visible. * @type {boolean} * @private */ -Blockly.Flyout.prototype.containerVisible_ = true; +Flyout.prototype.containerVisible_ = true; /** * Corner radius of the flyout background. * @type {number} * @const */ -Blockly.Flyout.prototype.CORNER_RADIUS = 8; +Flyout.prototype.CORNER_RADIUS = 8; /** * Margin around the edges of the blocks in the flyout. * @type {number} * @const */ -Blockly.Flyout.prototype.MARGIN = Blockly.Flyout.prototype.CORNER_RADIUS; +Flyout.prototype.MARGIN = Flyout.prototype.CORNER_RADIUS; // TODO: Move GAP_X and GAP_Y to their appropriate files. @@ -192,35 +193,35 @@ Blockly.Flyout.prototype.MARGIN = Blockly.Flyout.prototype.CORNER_RADIUS; * element. * @const {number} */ -Blockly.Flyout.prototype.GAP_X = Blockly.Flyout.prototype.MARGIN * 3; +Flyout.prototype.GAP_X = Flyout.prototype.MARGIN * 3; /** * Gap between items in vertical flyouts. Can be overridden with the "sep" * element. * @const {number} */ -Blockly.Flyout.prototype.GAP_Y = Blockly.Flyout.prototype.MARGIN * 3; +Flyout.prototype.GAP_Y = Flyout.prototype.MARGIN * 3; /** * Top/bottom padding between scrollbar and edge of flyout background. * @type {number} * @const */ -Blockly.Flyout.prototype.SCROLLBAR_MARGIN = 2.5; +Flyout.prototype.SCROLLBAR_MARGIN = 2.5; /** * Width of flyout. * @type {number} * @protected */ -Blockly.Flyout.prototype.width_ = 0; +Flyout.prototype.width_ = 0; /** * Height of flyout. * @type {number} * @protected */ -Blockly.Flyout.prototype.height_ = 0; +Flyout.prototype.height_ = 0; /** * Range of a drag angle from a flyout considered "dragging toward workspace". @@ -238,7 +239,7 @@ Blockly.Flyout.prototype.height_ = 0; * @type {number} * @protected */ -Blockly.Flyout.prototype.dragAngleRange_ = 70; +Flyout.prototype.dragAngleRange_ = 70; /** * Creates the flyout's DOM. Only needs to be called once. The flyout can @@ -250,7 +251,7 @@ Blockly.Flyout.prototype.dragAngleRange_ = 70; * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ -Blockly.Flyout.prototype.createDom = function(tagName) { +Flyout.prototype.createDom = function(tagName) { /* @@ -277,7 +278,7 @@ Blockly.Flyout.prototype.createDom = function(tagName) { * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ -Blockly.Flyout.prototype.init = function(targetWorkspace) { +Flyout.prototype.init = function(targetWorkspace) { this.targetWorkspace = targetWorkspace; this.workspace_.targetWorkspace = targetWorkspace; @@ -326,7 +327,7 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { * Unlink from all DOM elements to prevent memory leaks. * @suppress {checkTypes} */ -Blockly.Flyout.prototype.dispose = function() { +Flyout.prototype.dispose = function() { this.hide(); this.workspace_.getComponentManager().removeComponent(this.id); Blockly.browserEvents.unbind(this.eventWrappers_); @@ -352,7 +353,7 @@ Blockly.Flyout.prototype.dispose = function() { * Get the width of the flyout. * @return {number} The width of the flyout. */ -Blockly.Flyout.prototype.getWidth = function() { +Flyout.prototype.getWidth = function() { return this.width_; }; @@ -360,7 +361,7 @@ Blockly.Flyout.prototype.getWidth = function() { * Get the height of the flyout. * @return {number} The width of the flyout. */ -Blockly.Flyout.prototype.getHeight = function() { +Flyout.prototype.getHeight = function() { return this.height_; }; @@ -369,7 +370,7 @@ Blockly.Flyout.prototype.getHeight = function() { * this matches the target workspace scale, but this can be overridden. * @return {number} Flyout workspace scale. */ -Blockly.Flyout.prototype.getFlyoutScale = function() { +Flyout.prototype.getFlyoutScale = function() { return this.targetWorkspace.scale; }; @@ -378,7 +379,7 @@ Blockly.Flyout.prototype.getFlyoutScale = function() { * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. * @package */ -Blockly.Flyout.prototype.getWorkspace = function() { +Flyout.prototype.getWorkspace = function() { return this.workspace_; }; @@ -386,7 +387,7 @@ Blockly.Flyout.prototype.getWorkspace = function() { * Is the flyout visible? * @return {boolean} True if visible. */ -Blockly.Flyout.prototype.isVisible = function() { +Flyout.prototype.isVisible = function() { return this.isVisible_; }; @@ -395,7 +396,7 @@ Blockly.Flyout.prototype.isVisible = function() { * that the flyout is shown. It could be hidden because its container is hidden. * @param {boolean} visible True if visible. */ -Blockly.Flyout.prototype.setVisible = function(visible) { +Flyout.prototype.setVisible = function(visible) { const visibilityChanged = (visible != this.isVisible()); this.isVisible_ = visible; @@ -413,7 +414,7 @@ Blockly.Flyout.prototype.setVisible = function(visible) { * Set whether this flyout's container is visible. * @param {boolean} visible Whether the container is visible. */ -Blockly.Flyout.prototype.setContainerVisible = function(visible) { +Flyout.prototype.setContainerVisible = function(visible) { const visibilityChanged = (visible != this.containerVisible_); this.containerVisible_ = visible; if (visibilityChanged) { @@ -426,7 +427,7 @@ Blockly.Flyout.prototype.setContainerVisible = function(visible) { * be visible and whether its containing workspace is visible. * @private */ -Blockly.Flyout.prototype.updateDisplay_ = function() { +Flyout.prototype.updateDisplay_ = function() { let show = true; if (!this.containerVisible_) { show = false; @@ -447,7 +448,7 @@ Blockly.Flyout.prototype.updateDisplay_ = function() { * @param {number} y The computed y origin of the flyout's SVG group. * @protected */ -Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { +Flyout.prototype.positionAt_ = function(width, height, x, y) { this.svgGroup_.setAttribute("width", width); this.svgGroup_.setAttribute("height", height); this.workspace_.setCachedParentSvgSize(width, height); @@ -485,7 +486,7 @@ Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { /** * Hide and empty the flyout. */ -Blockly.Flyout.prototype.hide = function() { +Flyout.prototype.hide = function() { if (!this.isVisible()) { return; } @@ -509,7 +510,7 @@ Blockly.Flyout.prototype.hide = function() { * in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ -Blockly.Flyout.prototype.show = function(flyoutDef) { +Flyout.prototype.show = function(flyoutDef) { this.workspace_.setResizesEnabled(false); this.hide(); this.clearOldBlocks_(); @@ -566,7 +567,7 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { * and gaps needed to lay out the flyout. * @private */ -Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { +Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { const contents = []; const gaps = []; this.permanentlyDisabled_.length = 0; @@ -626,7 +627,7 @@ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { * @return {!Array} The array of flyout items. * @private */ -Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { +Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( @@ -651,7 +652,7 @@ Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { * flyout. * @private */ -Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { +Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!Blockly.FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } @@ -668,7 +669,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @return {!Blockly.BlockSvg} The block created from the blockXml. * @protected */ -Blockly.Flyout.prototype.createBlock_ = function(blockXml) { +Flyout.prototype.createBlock_ = function(blockXml) { const curBlock = /** @type {!Blockly.BlockSvg} */ ( Blockly.Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { @@ -687,7 +688,7 @@ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { * @throws {Error} if the xml is not a valid block definition. * @private */ -Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { +Flyout.prototype.getBlockXml_ = function(blockInfo) { let blockElement = null; const blockXml = blockInfo['blockxml']; @@ -717,7 +718,7 @@ Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { * @param {number} defaultGap The default gap between the button and next element. * @private */ -Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { +Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { // Change the gap between two toolbox elements. // // The default gap is 24, can be set larger or smaller. @@ -735,7 +736,7 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) * Delete blocks, mats and buttons from a previous showing of the flyout. * @protected */ -Blockly.Flyout.prototype.clearOldBlocks_ = function() { +Flyout.prototype.clearOldBlocks_ = function() { // Delete any blocks from a previous showing. const oldBlocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = oldBlocks[i]); i++) { @@ -770,7 +771,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { * as a mat for that block. * @protected */ -Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { +Flyout.prototype.addBlockListeners_ = function(root, block, rect) { this.listeners_.push(Blockly.browserEvents.conditionalBind( root, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push(Blockly.browserEvents.conditionalBind( @@ -791,7 +792,7 @@ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { * @return {!Function} Function to call when block is clicked. * @private */ -Blockly.Flyout.prototype.blockMouseDown_ = function(block) { +Flyout.prototype.blockMouseDown_ = function(block) { const flyout = this; return function(e) { const gesture = flyout.targetWorkspace.getGesture(e); @@ -807,7 +808,7 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { * @param {!Event} e Mouse down event. * @private */ -Blockly.Flyout.prototype.onMouseDown_ = function(e) { +Flyout.prototype.onMouseDown_ = function(e) { const gesture = this.targetWorkspace.getGesture(e); if (gesture) { gesture.handleFlyoutStart(e, this); @@ -822,7 +823,7 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) { * otherwise. * @package */ -Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { +Flyout.prototype.isBlockCreatable_ = function(block) { return block.isEnabled(); }; @@ -833,7 +834,7 @@ Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { * @throws {Error} if something went wrong with deserialization. * @package */ -Blockly.Flyout.prototype.createBlock = function(originalBlock) { +Flyout.prototype.createBlock = function(originalBlock) { let newBlock = null; Blockly.Events.disable(); const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); @@ -880,7 +881,7 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { * @param {number} y The y position of the cursor during this layout pass. * @protected */ -Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { +Flyout.prototype.initFlyoutButton_ = function(button, x, y) { const buttonSvg = button.createDom(); button.moveTo(x, y); button.show(); @@ -905,7 +906,7 @@ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { * block. * @protected */ -Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { +Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. const rect = Blockly.utils.dom.createSvgElement( @@ -934,7 +935,7 @@ Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * @param {!Blockly.BlockSvg} block The block the rectangle should be behind. * @protected */ -Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { +Flyout.prototype.moveRectToBlock_ = function(rect, block) { const blockHW = block.getHeightWidth(); rect.setAttribute('width', blockHW.width); rect.setAttribute('height', blockHW.height); @@ -950,7 +951,7 @@ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { * the workspace, an "a + b" block that has two shadow blocks would be disabled. * @private */ -Blockly.Flyout.prototype.filterForCapacity_ = function() { +Flyout.prototype.filterForCapacity_ = function() { const blocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { @@ -967,7 +968,7 @@ Blockly.Flyout.prototype.filterForCapacity_ = function() { /** * Reflow blocks and their mats. */ -Blockly.Flyout.prototype.reflow = function() { +Flyout.prototype.reflow = function() { if (this.reflowWrapper_) { this.workspace_.removeChangeListener(this.reflowWrapper_); } @@ -982,7 +983,7 @@ Blockly.Flyout.prototype.reflow = function() { * dragging. * @package */ -Blockly.Flyout.prototype.isScrollable = function() { +Flyout.prototype.isScrollable = function() { return this.workspace_.scrollbar ? this.workspace_.scrollbar.isVisible() : false; }; @@ -993,7 +994,7 @@ Blockly.Flyout.prototype.isScrollable = function() { * @return {!Blockly.BlockSvg} The new block in the main workspace. * @private */ -Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { +Flyout.prototype.placeNewBlock_ = function(oldBlock) { const targetWorkspace = this.targetWorkspace; const svgRootOld = oldBlock.getSvgRoot(); if (!svgRootOld) { @@ -1051,13 +1052,13 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { * relative to viewport. * @return {Blockly.utils.Rect} The component's bounding box. */ -Blockly.Flyout.prototype.getClientRect; +Flyout.prototype.getClientRect; /** * Position the flyout. * @return {void} */ -Blockly.Flyout.prototype.position; +Flyout.prototype.position; /** * Determine if a drag delta is toward the workspace, based on the position @@ -1068,7 +1069,7 @@ Blockly.Flyout.prototype.position; * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.Flyout.prototype.isDragTowardWorkspace; +Flyout.prototype.isDragTowardWorkspace; /** * Sets the translation of the flyout to match the scrollbars. @@ -1077,7 +1078,7 @@ Blockly.Flyout.prototype.isDragTowardWorkspace; * similar x property. * @protected */ -Blockly.Flyout.prototype.setMetrics_; +Flyout.prototype.setMetrics_; /** * Lay out the blocks in the flyout. @@ -1085,14 +1086,14 @@ Blockly.Flyout.prototype.setMetrics_; * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.Flyout.prototype.layout_; +Flyout.prototype.layout_; /** * Scroll the flyout. * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.Flyout.prototype.wheel_; +Flyout.prototype.wheel_; /** * Compute height of flyout. Position mat under each block. @@ -1100,16 +1101,18 @@ Blockly.Flyout.prototype.wheel_; * @return {void} * @protected */ -Blockly.Flyout.prototype.reflowInternal_; +Flyout.prototype.reflowInternal_; /** * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.Flyout.prototype.getX; +Flyout.prototype.getX; /** * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.Flyout.prototype.getY; +Flyout.prototype.getY; + +exports = Flyout; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..f9a77b67a 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -61,7 +61,7 @@ goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Bloc goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); -goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); From c5694ba711ba14e43a7bf9906d9bcde94b05c99b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:26:32 -0700 Subject: [PATCH 222/313] Migrate core/flyout_base.js named requires --- core/flyout_base.js | 228 ++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 117 insertions(+), 113 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 18a3ab909..42e4d0966 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -13,60 +13,64 @@ goog.module('Blockly.Flyout'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const ComponentManager = goog.require('Blockly.ComponentManager'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DeleteArea = goog.require('Blockly.DeleteArea'); +const Events = goog.require('Blockly.Events'); +const FlyoutButton = goog.require('Blockly.FlyoutButton'); +const FlyoutMetricsManager = goog.require('Blockly.FlyoutMetricsManager'); +/* eslint-disable-next-line no-unused-vars */ +const IFlyout = goog.require('Blockly.IFlyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const ScrollbarPair = goog.require('Blockly.ScrollbarPair'); +const Svg = goog.require('Blockly.utils.Svg'); +const Tooltip = goog.require('Blockly.Tooltip'); +const Variables = goog.require('Blockly.Variables'); +const WorkspaceSvg = goog.require('Blockly.WorkspaceSvg'); +const Xml = goog.require('Blockly.Xml'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const toolbox = goog.require('Blockly.utils.toolbox'); +const utils = goog.require('Blockly.utils'); +const utilsXml = goog.require('Blockly.utils.xml'); +const {hideChaff} = goog.require('Blockly'); /** @suppress {extraRequire} */ goog.require('Blockly.blockRendering'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.ComponentManager'); -goog.require('Blockly.DeleteArea'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockCreate'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarCreate'); -goog.require('Blockly.FlyoutMetricsManager'); /** @suppress {extraRequire} */ goog.require('Blockly.Gesture'); -goog.require('Blockly.IFlyout'); -goog.require('Blockly.ScrollbarPair'); -goog.require('Blockly.Tooltip'); /** @suppress {extraRequire} */ goog.require('Blockly.Touch'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.utils.xml'); -goog.require('Blockly.WorkspaceSvg'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.FlyoutButton'); -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Rect'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. * @constructor * @abstract - * @implements {Blockly.IFlyout} - * @extends {Blockly.DeleteArea} + * @implements {IFlyout} + * @extends {DeleteArea} */ const Flyout = function(workspaceOptions) { Flyout.superClass_.constructor.call(this); workspaceOptions.setMetrics = this.setMetrics_.bind(this); /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @protected */ - this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions); + this.workspace_ = new WorkspaceSvg(workspaceOptions); this.workspace_.setMetricsManager( - new Blockly.FlyoutMetricsManager(this.workspace_, this)); + new FlyoutMetricsManager(this.workspace_, this)); this.workspace_.isFlyout = true; // Keep the workspace visibility consistent with the flyout's visibility. @@ -77,7 +81,7 @@ const Flyout = function(workspaceOptions) { * ComponentManager. * @type {string} */ - this.id = Blockly.utils.genUid(); + this.id = utils.genUid(); /** * Is RTL vs LTR. @@ -116,7 +120,7 @@ const Flyout = function(workspaceOptions) { /** * List of visible buttons. - * @type {!Array} + * @type {!Array} * @protected */ this.buttons_ = []; @@ -130,7 +134,7 @@ const Flyout = function(workspaceOptions) { /** * List of blocks that should always be disabled. - * @type {!Array} + * @type {!Array} * @private */ this.permanentlyDisabled_ = []; @@ -145,12 +149,12 @@ const Flyout = function(workspaceOptions) { /** * The target workspace - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} * @package */ this.targetWorkspace = null; }; -Blockly.utils.object.inherits(Flyout, Blockly.DeleteArea); +utils.object.inherits(Flyout, DeleteArea); /** * Does the flyout automatically close when a block is created? @@ -246,8 +250,8 @@ Flyout.prototype.dragAngleRange_ = 70; * either exist as its own SVG element or be a g element nested inside a * separate SVG element. * @param {string| - * !Blockly.utils.Svg| - * !Blockly.utils.Svg} tagName The type of tag to + * !Svg| + * !Svg} tagName The type of tag to * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ @@ -260,10 +264,10 @@ Flyout.prototype.createDom = function(tagName) { */ // Setting style to display:none to start. The toolbox and flyout // hide/show code will set up proper visibility and size later. - this.svgGroup_ = Blockly.utils.dom.createSvgElement(tagName, + this.svgGroup_ = dom.createSvgElement(tagName, {'class': 'blocklyFlyout', 'style': 'display: none'}, null); - this.svgBackground_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + this.svgBackground_ = dom.createSvgElement( + Svg.PATH, {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); this.svgGroup_.appendChild(this.workspace_.createDom()); this.workspace_.getThemeManager().subscribe( @@ -275,14 +279,14 @@ Flyout.prototype.createDom = function(tagName) { /** * Initializes the flyout. - * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to + * @param {!WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ Flyout.prototype.init = function(targetWorkspace) { this.targetWorkspace = targetWorkspace; this.workspace_.targetWorkspace = targetWorkspace; - this.workspace_.scrollbar = new Blockly.ScrollbarPair( + this.workspace_.scrollbar = new ScrollbarPair( this.workspace_, this.horizontalLayout, !this.horizontalLayout, 'blocklyFlyoutScrollbar', this.SCROLLBAR_MARGIN); @@ -290,7 +294,7 @@ Flyout.prototype.init = function(targetWorkspace) { Array.prototype.push.apply( this.eventWrappers_, - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.svgGroup_, 'wheel', this, this.wheel_)); if (!this.autoClose) { this.filterWrapper_ = this.filterForCapacity_.bind(this); @@ -300,7 +304,7 @@ Flyout.prototype.init = function(targetWorkspace) { // Dragging the flyout up and down. Array.prototype.push.apply( this.eventWrappers_, - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.svgBackground_, 'mousedown', this, this.onMouseDown_)); // A flyout connected to a workspace doesn't have its own current gesture. @@ -316,8 +320,8 @@ Flyout.prototype.init = function(targetWorkspace) { component: this, weight: 1, capabilities: [ - Blockly.ComponentManager.Capability.DELETE_AREA, - Blockly.ComponentManager.Capability.DRAG_TARGET + ComponentManager.Capability.DELETE_AREA, + ComponentManager.Capability.DRAG_TARGET ] }); }; @@ -330,7 +334,7 @@ Flyout.prototype.init = function(targetWorkspace) { Flyout.prototype.dispose = function() { this.hide(); this.workspace_.getComponentManager().removeComponent(this.id); - Blockly.browserEvents.unbind(this.eventWrappers_); + browserEvents.unbind(this.eventWrappers_); if (this.filterWrapper_) { this.targetWorkspace.removeChangeListener(this.filterWrapper_); this.filterWrapper_ = null; @@ -342,7 +346,7 @@ Flyout.prototype.dispose = function() { this.workspace_ = null; } if (this.svgGroup_) { - Blockly.utils.dom.removeNode(this.svgGroup_); + dom.removeNode(this.svgGroup_); this.svgGroup_ = null; } this.svgBackground_ = null; @@ -376,7 +380,7 @@ Flyout.prototype.getFlyoutScale = function() { /** * Get the workspace inside the flyout. - * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. + * @return {!WorkspaceSvg} The workspace inside the flyout. * @package */ Flyout.prototype.getWorkspace = function() { @@ -455,7 +459,7 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { if (this.svgGroup_.tagName == 'svg') { const transform = 'translate(' + x + 'px,' + y + 'px)'; - Blockly.utils.dom.setCssTransform(this.svgGroup_, transform); + dom.setCssTransform(this.svgGroup_, transform); } else { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself @@ -493,7 +497,7 @@ Flyout.prototype.hide = function() { this.setVisible(false); // Delete all the event listeners. for (let i = 0, listen; (listen = this.listeners_[i]); i++) { - Blockly.browserEvents.unbind(listen); + browserEvents.unbind(listen); } this.listeners_.length = 0; if (this.reflowWrapper_) { @@ -506,7 +510,7 @@ Flyout.prototype.hide = function() { /** * Show and populate the flyout. - * @param {!Blockly.utils.toolbox.FlyoutDefinition|string} flyoutDef Contents to display + * @param {!toolbox.FlyoutDefinition|string} flyoutDef Contents to display * in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ @@ -522,7 +526,7 @@ Flyout.prototype.show = function(flyoutDef) { this.setVisible(true); // Parse the Array, Node or NodeList into a a list of flyout items. - const parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); + const parsedContent = toolbox.convertFlyoutDefToJsonArray(flyoutDef); const flyoutInfo = /** @type {{contents:!Array, gaps:!Array}} */ ( this.createFlyoutInfo_(parsedContent)); @@ -538,7 +542,7 @@ Flyout.prototype.show = function(flyoutDef) { } }; - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( this.svgBackground_, 'mouseover', this, deselectAll)); if (this.horizontalLayout) { @@ -561,7 +565,7 @@ Flyout.prototype.show = function(flyoutDef) { /** * Create the contents array and gaps array necessary to create the layout for * the flyout. - * @param {!Blockly.utils.toolbox.FlyoutItemInfoArray} parsedContent The array + * @param {!toolbox.FlyoutItemInfoArray} parsedContent The array * of objects to show in the flyout. * @return {{contents:Array, gaps:Array}} The list of contents * and gaps needed to lay out the flyout. @@ -575,18 +579,18 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { if (contentInfo['custom']) { - const customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); + const customInfo = /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); const categoryName = customInfo['custom']; const flyoutDef = this.getDynamicCategoryContents_(categoryName); - const parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ - (Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef)); + const parsedDynamicContent = /** @type {!toolbox.FlyoutItemInfoArray} */ + (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } switch (contentInfo['kind'].toUpperCase()) { case 'BLOCK': { - const blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); + const blockInfo = /** @type {!toolbox.BlockInfo} */ (contentInfo); const blockXml = this.getBlockXml_(blockInfo); const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. @@ -597,12 +601,12 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { break; } case 'SEP': { - const sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); + const sepInfo = /** @type {!toolbox.SeparatorInfo} */ (contentInfo); this.addSeparatorGap_(sepInfo, gaps, defaultGap); break; } case 'LABEL': { - const labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); + const labelInfo = /** @type {!toolbox.LabelInfo} */ (contentInfo); // A label is a button with different styling. const label = this.createButton_(labelInfo, /** isLabel */ true); contents.push({type: 'button', button: label}); @@ -610,7 +614,7 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { break; } case 'BUTTON': { - const buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); + const buttonInfo = /** @type {!toolbox.ButtonInfo} */ (contentInfo); const button = this.createButton_(buttonInfo, /** isLabel */ false); contents.push({type: 'button', button: button}); gaps.push(defaultGap); @@ -645,19 +649,19 @@ Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { /** * Creates a flyout button or a flyout label. - * @param {!Blockly.utils.toolbox.ButtonOrLabelInfo} btnInfo + * @param {!toolbox.ButtonOrLabelInfo} btnInfo * The object holding information about a button or a label. * @param {boolean} isLabel True if the button is a label, false otherwise. - * @return {!Blockly.FlyoutButton} The object used to display the button in the + * @return {!FlyoutButton} The object used to display the button in the * flyout. * @private */ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { - if (!Blockly.FlyoutButton) { + if (!FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - const curButton = new Blockly.FlyoutButton(this.workspace_, - /** @type {!Blockly.WorkspaceSvg} */ (this.targetWorkspace), btnInfo, + const curButton = new FlyoutButton(this.workspace_, + /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; }; @@ -666,12 +670,12 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * Create a block from the xml and permanently disable any blocks that were * defined as disabled. * @param {!Element} blockXml The xml of the block. - * @return {!Blockly.BlockSvg} The block created from the blockXml. + * @return {!BlockSvg} The block created from the blockXml. * @protected */ Flyout.prototype.createBlock_ = function(blockXml) { - const curBlock = /** @type {!Blockly.BlockSvg} */ ( - Blockly.Xml.domToBlock(blockXml, this.workspace_)); + const curBlock = /** @type {!BlockSvg} */ ( + Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. // Do not enable these blocks as a result of capacity filtering. @@ -682,7 +686,7 @@ Flyout.prototype.createBlock_ = function(blockXml) { /** * Get the xml from the block info object. - * @param {!Blockly.utils.toolbox.BlockInfo} blockInfo The object holding + * @param {!toolbox.BlockInfo} blockInfo The object holding * information about a block. * @return {!Element} The xml for the block. * @throws {Error} if the xml is not a valid block definition. @@ -695,10 +699,10 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { if (blockXml && typeof blockXml != 'string') { blockElement = blockXml; } else if (blockXml && typeof blockXml == 'string') { - blockElement = Blockly.Xml.textToDom(blockXml); + blockElement = Xml.textToDom(blockXml); blockInfo['blockxml'] = blockElement; } else if (blockInfo['type']) { - blockElement = Blockly.utils.xml.createElement('xml'); + blockElement = utilsXml.createElement('xml'); blockElement.setAttribute('type', blockInfo['type']); blockElement.setAttribute('disabled', blockInfo['disabled']); blockInfo['blockxml'] = blockElement; @@ -712,7 +716,7 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { /** * Add the necessary gap in the flyout for a separator. - * @param {!Blockly.utils.toolbox.SeparatorInfo} sepInfo The object holding + * @param {!toolbox.SeparatorInfo} sepInfo The object holding * information about a separator. * @param {!Array} gaps The list gaps between items in the flyout. * @param {number} defaultGap The default gap between the button and next element. @@ -748,8 +752,8 @@ Flyout.prototype.clearOldBlocks_ = function() { for (let j = 0; j < this.mats_.length; j++) { const rect = this.mats_[j]; if (rect) { - Blockly.Tooltip.unbindMouseEvents(rect); - Blockly.utils.dom.removeNode(rect); + Tooltip.unbindMouseEvents(rect); + dom.removeNode(rect); } } this.mats_.length = 0; @@ -766,29 +770,29 @@ Flyout.prototype.clearOldBlocks_ = function() { /** * Add listeners to a block that has been added to the flyout. * @param {!SVGElement} root The root node of the SVG group the block is in. - * @param {!Blockly.BlockSvg} block The block to add listeners for. + * @param {!BlockSvg} block The block to add listeners for. * @param {!SVGElement} rect The invisible rectangle under the block that acts * as a mat for that block. * @protected */ Flyout.prototype.addBlockListeners_ = function(root, block, rect) { - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( root, 'mousedown', null, this.blockMouseDown_(block))); - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( rect, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push( - Blockly.browserEvents.bind(root, 'mouseenter', block, block.addSelect)); - this.listeners_.push(Blockly.browserEvents.bind( + browserEvents.bind(root, 'mouseenter', block, block.addSelect)); + this.listeners_.push(browserEvents.bind( root, 'mouseleave', block, block.removeSelect)); this.listeners_.push( - Blockly.browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); - this.listeners_.push(Blockly.browserEvents.bind( + browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); + this.listeners_.push(browserEvents.bind( rect, 'mouseleave', block, block.removeSelect)); }; /** * Handle a mouse-down on an SVG block in a non-closing flyout. - * @param {!Blockly.BlockSvg} block The flyout block to copy. + * @param {!BlockSvg} block The flyout block to copy. * @return {!Function} Function to call when block is clicked. * @private */ @@ -818,7 +822,7 @@ Flyout.prototype.onMouseDown_ = function(e) { /** * Does this flyout allow you to create a new instance of the given block? * Used for deciding if a block can be "dragged out of" the flyout. - * @param {!Blockly.BlockSvg} block The block to copy from the flyout. + * @param {!BlockSvg} block The block to copy from the flyout. * @return {boolean} True if you can create a new instance of the block, false * otherwise. * @package @@ -829,41 +833,41 @@ Flyout.prototype.isBlockCreatable_ = function(block) { /** * Create a copy of this block on the workspace. - * @param {!Blockly.BlockSvg} originalBlock The block to copy from the flyout. - * @return {!Blockly.BlockSvg} The newly created block. + * @param {!BlockSvg} originalBlock The block to copy from the flyout. + * @return {!BlockSvg} The newly created block. * @throws {Error} if something went wrong with deserialization. * @package */ Flyout.prototype.createBlock = function(originalBlock) { let newBlock = null; - Blockly.Events.disable(); + Events.disable(); const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); this.targetWorkspace.setResizesEnabled(false); try { newBlock = this.placeNewBlock_(originalBlock); } finally { - Blockly.Events.enable(); + Events.enable(); } // Close the flyout. - Blockly.hideChaff(); + hideChaff(); - const newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, + const newVariables = Variables.getAddedVariables(this.targetWorkspace, variablesBeforeCreation); - if (Blockly.Events.isEnabled()) { - Blockly.Events.setGroup(true); + if (Events.isEnabled()) { + Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. for (let i = 0; i < newVariables.length; i++) { const thisVariable = newVariables[i]; - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.VAR_CREATE))(thisVariable)); + Events.fire( + new (Events.get(Events.VAR_CREATE))(thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock)); + Events.fire( + new (Events.get(Events.BLOCK_CREATE))(newBlock)); } if (this.autoClose) { this.hide(); @@ -876,7 +880,7 @@ Flyout.prototype.createBlock = function(originalBlock) { /** * Initialize the given button: move it to the correct location, * add listeners, etc. - * @param {!Blockly.FlyoutButton} button The button to initialize and place. + * @param {!FlyoutButton} button The button to initialize and place. * @param {number} x The x position of the cursor during this layout pass. * @param {number} y The y position of the cursor during this layout pass. * @protected @@ -887,7 +891,7 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { button.show(); // Clicking on a flyout button or label is a lot like clicking on the // flyout background. - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( buttonSvg, 'mousedown', this, this.onMouseDown_)); this.buttons_.push(button); @@ -895,7 +899,7 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { /** * Create and place a rectangle corresponding to the given block. - * @param {!Blockly.BlockSvg} block The block to associate the rect to. + * @param {!BlockSvg} block The block to associate the rect to. * @param {number} x The x position of the cursor during this layout pass. * @param {number} y The y position of the cursor during this layout pass. * @param {!{height: number, width: number}} blockHW The height and width of the @@ -909,8 +913,8 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. - const rect = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + const rect = dom.createSvgElement( + Svg.RECT, { 'fill-opacity': 0, 'x': x, @@ -919,7 +923,7 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { 'width': blockHW.width }, null); rect.tooltip = block; - Blockly.Tooltip.bindMouseEvents(rect); + Tooltip.bindMouseEvents(rect); // Add the rectangles under the blocks, so that the blocks' tooltips work. this.workspace_.getCanvas().insertBefore(rect, block.getSvgRoot()); @@ -932,7 +936,7 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * Move a rectangle to sit exactly behind a block, taking into account tabs, * hats, and any other protrusions we invent. * @param {!SVGElement} rect The rectangle to move directly behind the block. - * @param {!Blockly.BlockSvg} block The block the rectangle should be behind. + * @param {!BlockSvg} block The block the rectangle should be behind. * @protected */ Flyout.prototype.moveRectToBlock_ = function(rect, block) { @@ -956,7 +960,7 @@ Flyout.prototype.filterForCapacity_ = function() { for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { const enable = this.targetWorkspace - .isCapacityAvailable(Blockly.utils.getBlockTypeCounts(block)); + .isCapacityAvailable(utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); block = block.getNextBlock(); @@ -990,8 +994,8 @@ Flyout.prototype.isScrollable = function() { /** * Copy a block from the flyout to the workspace and position it correctly. - * @param {!Blockly.BlockSvg} oldBlock The flyout block to copy. - * @return {!Blockly.BlockSvg} The new block in the main workspace. + * @param {!BlockSvg} oldBlock The flyout block to copy. + * @return {!BlockSvg} The new block in the main workspace. * @private */ Flyout.prototype.placeNewBlock_ = function(oldBlock) { @@ -1003,15 +1007,15 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // Create the new block by cloning the block in the flyout (via XML). // This cast assumes that the oldBlock can not be an insertion marker. - const xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); + const xml = /** @type {!Element} */ (Xml.blockToDom(oldBlock, true)); // The target workspace would normally resize during domToBlock, which will // lead to weird jumps. Save it for terminateDrag. targetWorkspace.setResizesEnabled(false); // Using domToBlock instead of domToWorkspace means that the new block will be // placed at position (0, 0) in main workspace units. - const block = /** @type {!Blockly.BlockSvg} */ - (Blockly.Xml.domToBlock(xml, targetWorkspace)); + const block = /** @type {!BlockSvg} */ + (Xml.domToBlock(xml, targetWorkspace)); const svgRootNew = block.getSvgRoot(); if (!svgRootNew) { throw Error('block is not rendered.'); @@ -1033,12 +1037,12 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // The position of the old block in pixels relative to the upper left corner // of the injection div. - const oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, + const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - const finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, + const finalOffset = Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); @@ -1050,7 +1054,7 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {Blockly.utils.Rect} The component's bounding box. + * @return {utils.Rect} The component's bounding box. */ Flyout.prototype.getClientRect; @@ -1064,7 +1068,7 @@ Flyout.prototype.position; * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package diff --git a/tests/deps.js b/tests/deps.js index f9a77b67a..54c8af48e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -61,7 +61,7 @@ goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Bloc goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); -goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly', 'Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutButton', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); From 47314fd0b921a0d315f6aadc4cd6837a039613b8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:27:36 -0700 Subject: [PATCH 223/313] clang-format core/flyout_base.js --- core/flyout_base.js | 97 +++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 42e4d0966..594d83a9f 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -242,7 +242,7 @@ Flyout.prototype.height_ = 0; * flyout. Setting it to 360 means that all drags create a new block. * @type {number} * @protected -*/ + */ Flyout.prototype.dragAngleRange_ = 70; /** @@ -264,11 +264,10 @@ Flyout.prototype.createDom = function(tagName) { */ // Setting style to display:none to start. The toolbox and flyout // hide/show code will set up proper visibility and size later. - this.svgGroup_ = dom.createSvgElement(tagName, - {'class': 'blocklyFlyout', 'style': 'display: none'}, null); + this.svgGroup_ = dom.createSvgElement( + tagName, {'class': 'blocklyFlyout', 'style': 'display: none'}, null); this.svgBackground_ = dom.createSvgElement( - Svg.PATH, - {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); + Svg.PATH, {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); this.svgGroup_.appendChild(this.workspace_.createDom()); this.workspace_.getThemeManager().subscribe( this.svgBackground_, 'flyoutBackgroundColour', 'fill'); @@ -453,8 +452,8 @@ Flyout.prototype.updateDisplay_ = function() { * @protected */ Flyout.prototype.positionAt_ = function(width, height, x, y) { - this.svgGroup_.setAttribute("width", width); - this.svgGroup_.setAttribute("height", height); + this.svgGroup_.setAttribute('width', width); + this.svgGroup_.setAttribute('height', height); this.workspace_.setCachedParentSvgSize(width, height); if (this.svgGroup_.tagName == 'svg') { @@ -464,7 +463,7 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself const transform = 'translate(' + x + ',' + y + ')'; - this.svgGroup_.setAttribute("transform", transform); + this.svgGroup_.setAttribute('transform', transform); } // Update the scrollbar (if one exists). @@ -482,7 +481,6 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { if (scrollbar.vScroll) { scrollbar.vScroll.setPosition( scrollbar.vScroll.position.x, scrollbar.vScroll.position.y); - } } }; @@ -528,8 +526,8 @@ Flyout.prototype.show = function(flyoutDef) { // Parse the Array, Node or NodeList into a a list of flyout items. const parsedContent = toolbox.convertFlyoutDefToJsonArray(flyoutDef); const flyoutInfo = - /** @type {{contents:!Array, gaps:!Array}} */ ( - this.createFlyoutInfo_(parsedContent)); + /** @type {{contents:!Array, gaps:!Array}} */ ( + this.createFlyoutInfo_(parsedContent)); this.layout_(flyoutInfo.contents, flyoutInfo.gaps); @@ -577,14 +575,15 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { this.permanentlyDisabled_.length = 0; const defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { - if (contentInfo['custom']) { - const customInfo = /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); + const customInfo = + /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); const categoryName = customInfo['custom']; const flyoutDef = this.getDynamicCategoryContents_(categoryName); const parsedDynamicContent = /** @type {!toolbox.FlyoutItemInfoArray} */ - (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); - parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); + (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); + parsedContent.splice.apply( + parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } @@ -595,7 +594,8 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. // - const gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); + const gap = + parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); gaps.push(isNaN(gap) ? defaultGap : gap); contents.push({type: 'block', block: block}); break; @@ -634,15 +634,17 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. - const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( - categoryName); + const fnToApply = + this.workspace_.targetWorkspace.getToolboxCategoryCallback(categoryName); if (typeof fnToApply != 'function') { - throw TypeError('Couldn\'t find a callback function when opening' + + throw TypeError( + 'Couldn\'t find a callback function when opening' + ' a toolbox category.'); } const flyoutDef = fnToApply(this.workspace_.targetWorkspace); if (!Array.isArray(flyoutDef)) { - throw new TypeError('Result of toolbox category callback must be an array.'); + throw new TypeError( + 'Result of toolbox category callback must be an array.'); } return flyoutDef; }; @@ -660,9 +662,9 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - const curButton = new FlyoutButton(this.workspace_, - /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, - isLabel); + const curButton = new FlyoutButton( + this.workspace_, + /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; }; @@ -674,8 +676,8 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @protected */ Flyout.prototype.createBlock_ = function(blockXml) { - const curBlock = /** @type {!BlockSvg} */ ( - Xml.domToBlock(blockXml, this.workspace_)); + const curBlock = + /** @type {!BlockSvg} */ (Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. // Do not enable these blocks as a result of capacity filtering. @@ -709,7 +711,8 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { } if (!blockElement) { - throw Error('Error: Invalid block definition. Block definition must have blockxml or type.'); + throw Error( + 'Error: Invalid block definition. Block definition must have blockxml or type.'); } return blockElement; }; @@ -719,7 +722,8 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { * @param {!toolbox.SeparatorInfo} sepInfo The object holding * information about a separator. * @param {!Array} gaps The list gaps between items in the flyout. - * @param {number} defaultGap The default gap between the button and next element. + * @param {number} defaultGap The default gap between the button and next + * element. * @private */ Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { @@ -782,12 +786,12 @@ Flyout.prototype.addBlockListeners_ = function(root, block, rect) { rect, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push( browserEvents.bind(root, 'mouseenter', block, block.addSelect)); - this.listeners_.push(browserEvents.bind( - root, 'mouseleave', block, block.removeSelect)); + this.listeners_.push( + browserEvents.bind(root, 'mouseleave', block, block.removeSelect)); this.listeners_.push( browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); - this.listeners_.push(browserEvents.bind( - rect, 'mouseleave', block, block.removeSelect)); + this.listeners_.push( + browserEvents.bind(rect, 'mouseleave', block, block.removeSelect)); }; /** @@ -852,22 +856,20 @@ Flyout.prototype.createBlock = function(originalBlock) { // Close the flyout. hideChaff(); - const newVariables = Variables.getAddedVariables(this.targetWorkspace, - variablesBeforeCreation); + const newVariables = Variables.getAddedVariables( + this.targetWorkspace, variablesBeforeCreation); if (Events.isEnabled()) { Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. for (let i = 0; i < newVariables.length; i++) { const thisVariable = newVariables[i]; - Events.fire( - new (Events.get(Events.VAR_CREATE))(thisVariable)); + Events.fire(new (Events.get(Events.VAR_CREATE))(thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. - Events.fire( - new (Events.get(Events.BLOCK_CREATE))(newBlock)); + Events.fire(new (Events.get(Events.BLOCK_CREATE))(newBlock)); } if (this.autoClose) { this.hide(); @@ -914,14 +916,14 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. const rect = dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'fill-opacity': 0, 'x': x, 'y': y, 'height': blockHW.height, 'width': blockHW.width - }, null); + }, + null); rect.tooltip = block; Tooltip.bindMouseEvents(rect); // Add the rectangles under the blocks, so that the blocks' tooltips work. @@ -959,8 +961,8 @@ Flyout.prototype.filterForCapacity_ = function() { const blocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { - const enable = this.targetWorkspace - .isCapacityAvailable(utils.getBlockTypeCounts(block)); + const enable = this.targetWorkspace.isCapacityAvailable( + utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); block = block.getNextBlock(); @@ -988,8 +990,8 @@ Flyout.prototype.reflow = function() { * @package */ Flyout.prototype.isScrollable = function() { - return this.workspace_.scrollbar ? - this.workspace_.scrollbar.isVisible() : false; + return this.workspace_.scrollbar ? this.workspace_.scrollbar.isVisible() : + false; }; /** @@ -1037,13 +1039,12 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // The position of the old block in pixels relative to the upper left corner // of the injection div. - const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, - oldBlockPos); + const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - const finalOffset = Coordinate.difference(oldBlockOffsetPixels, - mainOffsetPixels); + const finalOffset = + Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); From 8cb794feb5f9285476c6fdff6e7467881535afcf Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 16:36:30 -0700 Subject: [PATCH 224/313] Suppress unused vars --- core/menu.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/menu.js b/core/menu.js index 083d76e06..6a1667964 100644 --- a/core/menu.js +++ b/core/menu.js @@ -14,6 +14,7 @@ goog.module('Blockly.Menu'); goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const MenuItem = goog.requireType('Blockly.MenuItem'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); const Size = goog.requireType('Blockly.utils.Size'); From 39f5b4c7cd606602cffa70a1b8d2f60d3f794296 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 16:49:01 -0700 Subject: [PATCH 225/313] Fixes lint warnings --- core/menu.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/menu.js b/core/menu.js index 6a1667964..91cfb4d36 100644 --- a/core/menu.js +++ b/core/menu.js @@ -17,6 +17,7 @@ const Coordinate = goog.require('Blockly.utils.Coordinate'); /* eslint-disable-next-line no-unused-vars */ const MenuItem = goog.requireType('Blockly.MenuItem'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); const aria = goog.require('Blockly.utils.aria'); const browserEvents = goog.require('Blockly.browserEvents'); From b07c6869ba6cc42b80db3c8a9b458d04b930fc20 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:28 -0700 Subject: [PATCH 226/313] Migrate core/field_label_serializable.js to ES6 const/let --- core/field_label_serializable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 0201db130..0d1acf52a 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -47,7 +47,7 @@ Blockly.utils.object.inherits(Blockly.FieldLabelSerializable, * @nocollapse */ Blockly.FieldLabelSerializable.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. return new this(text, undefined, options); From 20ef2462b5bdaf24d0e2d527ca63e8bb25e806cc Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:40 -0700 Subject: [PATCH 227/313] Migrate core/field_label_serializable.js to goog.module --- core/field_label_serializable.js | 21 ++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 0d1acf52a..77784eb4c 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldLabelSerializable'); +goog.module('Blockly.FieldLabelSerializable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.FieldLabel'); goog.require('Blockly.fieldRegistry'); @@ -31,22 +32,22 @@ goog.require('Blockly.utils.object'); * @constructor * */ -Blockly.FieldLabelSerializable = function(opt_value, opt_class, opt_config) { - Blockly.FieldLabelSerializable.superClass_.constructor.call( +const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { + FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -Blockly.utils.object.inherits(Blockly.FieldLabelSerializable, +Blockly.utils.object.inherits(FieldLabelSerializable, Blockly.FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and class). - * @return {!Blockly.FieldLabelSerializable} The new field instance. + * @return {!FieldLabelSerializable} The new field instance. * @package * @nocollapse */ -Blockly.FieldLabelSerializable.fromJson = function(options) { +FieldLabelSerializable.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. @@ -58,14 +59,16 @@ Blockly.FieldLabelSerializable.fromJson = function(options) { * editable. This field should not. * @type {boolean} */ -Blockly.FieldLabelSerializable.prototype.EDITABLE = false; +FieldLabelSerializable.prototype.EDITABLE = false; /** * Serializable fields are saved by the XML renderer, non-serializable fields * are not. This field should be serialized, but only edited programmatically. * @type {boolean} */ -Blockly.FieldLabelSerializable.prototype.SERIALIZABLE = true; +FieldLabelSerializable.prototype.SERIALIZABLE = true; Blockly.fieldRegistry.register( - 'field_label_serializable', Blockly.FieldLabelSerializable); + 'field_label_serializable', FieldLabelSerializable); + +exports = FieldLabelSerializable; diff --git a/tests/deps.js b/tests/deps.js index d02bbc5ea..226f67c0f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -55,7 +55,7 @@ goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Bloc goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); From bcb57b7efd721878e275255ac4b09fc18064fced Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:51 -0700 Subject: [PATCH 228/313] Migrate core/field_label_serializable.js named requires --- core/field_label_serializable.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 77784eb4c..828a9954b 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -14,10 +14,10 @@ goog.module('Blockly.FieldLabelSerializable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.FieldLabel'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); +const FieldLabel = goog.require('Blockly.FieldLabel'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -28,7 +28,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldLabel} + * @extends {FieldLabel} * @constructor * */ @@ -36,8 +36,8 @@ const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -Blockly.utils.object.inherits(FieldLabelSerializable, - Blockly.FieldLabel); +inherits(FieldLabelSerializable, + FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, @@ -48,7 +48,7 @@ Blockly.utils.object.inherits(FieldLabelSerializable, * @nocollapse */ FieldLabelSerializable.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -68,7 +68,7 @@ FieldLabelSerializable.prototype.EDITABLE = false; */ FieldLabelSerializable.prototype.SERIALIZABLE = true; -Blockly.fieldRegistry.register( +fieldRegistry.register( 'field_label_serializable', FieldLabelSerializable); exports = FieldLabelSerializable; From 569a86901ea7888678d7364e96a1d6b99284d103 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:08:45 -0700 Subject: [PATCH 229/313] clang-format core/field_label_serializable.js --- core/field_label_serializable.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 828a9954b..daabaa59f 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -26,7 +26,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * string. Defaults to an empty string if null or undefined. * @param {string=} opt_class Optional CSS class for the field's text. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} * for a list of properties this parameter supports. * @extends {FieldLabel} * @constructor @@ -36,8 +37,7 @@ const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -inherits(FieldLabelSerializable, - FieldLabel); +inherits(FieldLabelSerializable, FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, @@ -68,7 +68,6 @@ FieldLabelSerializable.prototype.EDITABLE = false; */ FieldLabelSerializable.prototype.SERIALIZABLE = true; -fieldRegistry.register( - 'field_label_serializable', FieldLabelSerializable); +fieldRegistry.register('field_label_serializable', FieldLabelSerializable); exports = FieldLabelSerializable; From 60c03cef4fd495cb2a23dc25ce00d70d9e2b89bd Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:23:23 -0700 Subject: [PATCH 230/313] Migrate core/field_image.js to ES6 const/let --- core/field_image.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index eed381b63..163941efb 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -44,8 +44,8 @@ Blockly.FieldImage = function(src, width, height, throw Error('Src value of an image field is required'); } src = Blockly.utils.replaceMessageReferences(src); - var imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); - var imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); + const imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); + const imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { throw Error('Height and width values of an image field must cast to' + ' numbers.'); From f1882fc2180949292db8f5961ffa8308ff254c26 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:23:35 -0700 Subject: [PATCH 231/313] Migrate core/field_image.js to goog.module --- core/field_image.js | 55 ++++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 163941efb..68a1fb43c 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldImage'); +goog.module('Blockly.FieldImage'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Field'); goog.require('Blockly.fieldRegistry'); @@ -27,7 +28,7 @@ goog.require('Blockly.utils.Svg'); * @param {!(string|number)} width Width of the image. * @param {!(string|number)} height Height of the image. * @param {string=} opt_alt Optional alt text for when block is collapsed. - * @param {function(!Blockly.FieldImage)=} opt_onClick Optional function to be + * @param {function(!FieldImage)=} opt_onClick Optional function to be * called when the image is clicked. If opt_onClick is defined, opt_alt must * also be defined. * @param {boolean=} opt_flipRtl Whether to flip the icon in RTL. @@ -37,7 +38,7 @@ goog.require('Blockly.utils.Svg'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldImage = function(src, width, height, +const FieldImage = function(src, width, height, opt_alt, opt_onClick, opt_flipRtl, opt_config) { // Return early. if (!src) { @@ -70,7 +71,7 @@ Blockly.FieldImage = function(src, width, height, */ this.altText_ = ''; - Blockly.FieldImage.superClass_.constructor.call( + FieldImage.superClass_.constructor.call( this, src, null, opt_config); if (!opt_config) { // If the config wasn't passed, do old configuration. @@ -86,7 +87,7 @@ Blockly.FieldImage = function(src, width, height, * @override */ this.size_ = new Blockly.utils.Size(imageWidth, - imageHeight + Blockly.FieldImage.Y_PADDING); + imageHeight + FieldImage.Y_PADDING); /** * Store the image height, since it is different from the field height. @@ -97,7 +98,7 @@ Blockly.FieldImage = function(src, width, height, /** * The function to be called when this field is clicked. - * @type {?function(!Blockly.FieldImage)} + * @type {?function(!FieldImage)} * @private */ this.clickHandler_ = null; @@ -113,25 +114,25 @@ Blockly.FieldImage = function(src, width, height, */ this.imageElement_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldImage, Blockly.Field); +Blockly.utils.object.inherits(FieldImage, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldImage.prototype.DEFAULT_VALUE = ''; +FieldImage.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldImage from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (src, width, height, * alt, and flipRtl). - * @return {!Blockly.FieldImage} The new field instance. + * @return {!FieldImage} The new field instance. * @package * @nocollapse */ -Blockly.FieldImage.fromJson = function(options) { +FieldImage.fromJson = function(options) { // `this` might be a subclass of FieldImage if that class doesn't override // the static fromJson method. return new this(options['src'], options['width'], options['height'], @@ -144,14 +145,14 @@ Blockly.FieldImage.fromJson = function(options) { * @type {number} * @private */ -Blockly.FieldImage.Y_PADDING = 1; +FieldImage.Y_PADDING = 1; /** * Editable fields usually show some sort of UI indicating they are * editable. This field should not. * @type {boolean} */ -Blockly.FieldImage.prototype.EDITABLE = false; +FieldImage.prototype.EDITABLE = false; /** * Used to tell if the field needs to be rendered the next time the block is @@ -160,7 +161,7 @@ Blockly.FieldImage.prototype.EDITABLE = false; * @type {boolean} * @protected */ -Blockly.FieldImage.prototype.isDirty_ = false; +FieldImage.prototype.isDirty_ = false; /** * Configure the field based on the given map of options. @@ -168,8 +169,8 @@ Blockly.FieldImage.prototype.isDirty_ = false; * @protected * @override */ -Blockly.FieldImage.prototype.configure_ = function(config) { - Blockly.FieldImage.superClass_.configure_.call(this, config); +FieldImage.prototype.configure_ = function(config) { + FieldImage.superClass_.configure_.call(this, config); this.flipRtl_ = !!config['flipRtl']; this.altText_ = Blockly.utils.replaceMessageReferences(config['alt']) || ''; }; @@ -178,7 +179,7 @@ Blockly.FieldImage.prototype.configure_ = function(config) { * Create the block UI for this image. * @package */ -Blockly.FieldImage.prototype.initView = function() { +FieldImage.prototype.initView = function() { this.imageElement_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { @@ -198,7 +199,7 @@ Blockly.FieldImage.prototype.initView = function() { /** * @override */ -Blockly.FieldImage.prototype.updateSize_ = function() { +FieldImage.prototype.updateSize_ = function() { // NOP }; @@ -208,7 +209,7 @@ Blockly.FieldImage.prototype.updateSize_ = function() { * @return {?string} A string, or null if invalid. * @protected */ -Blockly.FieldImage.prototype.doClassValidation_ = function(opt_newValue) { +FieldImage.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } @@ -221,7 +222,7 @@ Blockly.FieldImage.prototype.doClassValidation_ = function(opt_newValue) { * that this is a string. * @protected */ -Blockly.FieldImage.prototype.doValueUpdate_ = function(newValue) { +FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, @@ -234,7 +235,7 @@ Blockly.FieldImage.prototype.doValueUpdate_ = function(newValue) { * @return {boolean} True if we should flip in RTL. * @override */ -Blockly.FieldImage.prototype.getFlipRtl = function() { +FieldImage.prototype.getFlipRtl = function() { return this.flipRtl_; }; @@ -243,7 +244,7 @@ Blockly.FieldImage.prototype.getFlipRtl = function() { * @param {?string} alt New alt text. * @public */ -Blockly.FieldImage.prototype.setAlt = function(alt) { +FieldImage.prototype.setAlt = function(alt) { if (alt == this.altText_) { return; } @@ -258,7 +259,7 @@ Blockly.FieldImage.prototype.setAlt = function(alt) { * call the handler. * @protected */ -Blockly.FieldImage.prototype.showEditor_ = function() { +FieldImage.prototype.showEditor_ = function() { if (this.clickHandler_) { this.clickHandler_(this); } @@ -266,10 +267,10 @@ Blockly.FieldImage.prototype.showEditor_ = function() { /** * Set the function that is called when this image is clicked. - * @param {?function(!Blockly.FieldImage)} func The function that is called + * @param {?function(!FieldImage)} func The function that is called * when the image is clicked, or null to remove. */ -Blockly.FieldImage.prototype.setOnClickHandler = function(func) { +FieldImage.prototype.setOnClickHandler = function(func) { this.clickHandler_ = func; }; @@ -281,8 +282,10 @@ Blockly.FieldImage.prototype.setOnClickHandler = function(func) { * @protected * @override */ -Blockly.FieldImage.prototype.getText_ = function() { +FieldImage.prototype.getText_ = function() { return this.altText_; }; -Blockly.fieldRegistry.register('field_image', Blockly.FieldImage); +Blockly.fieldRegistry.register('field_image', FieldImage); + +exports = FieldImage; diff --git a/tests/deps.js b/tests/deps.js index 226f67c0f..77f7d15a2 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -53,7 +53,7 @@ goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockl goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); From 8a934b0e9c27871561679bca3e502a51f41b16ec Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:24:07 -0700 Subject: [PATCH 232/313] Migrate core/field_image.js named requires --- core/field_image.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 68a1fb43c..09c814a1b 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -13,13 +13,13 @@ goog.module('Blockly.FieldImage'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.Svg'); +const Field = goog.require('Blockly.Field'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {createSvgElement, XLINK_NS} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -35,7 +35,7 @@ goog.require('Blockly.utils.Svg'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldImage = function(src, width, height, @@ -44,9 +44,9 @@ const FieldImage = function(src, width, height, if (!src) { throw Error('Src value of an image field is required'); } - src = Blockly.utils.replaceMessageReferences(src); - const imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); - const imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); + src = replaceMessageReferences(src); + const imageHeight = Number(replaceMessageReferences(height)); + const imageWidth = Number(replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { throw Error('Height and width values of an image field must cast to' + ' numbers.'); @@ -76,17 +76,17 @@ const FieldImage = function(src, width, height, if (!opt_config) { // If the config wasn't passed, do old configuration. this.flipRtl_ = !!opt_flipRtl; - this.altText_ = Blockly.utils.replaceMessageReferences(opt_alt) || ''; + this.altText_ = replaceMessageReferences(opt_alt) || ''; } // Initialize other properties. /** * The size of the area rendered by the field. - * @type {Blockly.utils.Size} + * @type {Size} * @protected * @override */ - this.size_ = new Blockly.utils.Size(imageWidth, + this.size_ = new Size(imageWidth, imageHeight + FieldImage.Y_PADDING); /** @@ -114,7 +114,7 @@ const FieldImage = function(src, width, height, */ this.imageElement_ = null; }; -Blockly.utils.object.inherits(FieldImage, Blockly.Field); +inherits(FieldImage, Field); /** * The default value for this field. @@ -172,7 +172,7 @@ FieldImage.prototype.isDirty_ = false; FieldImage.prototype.configure_ = function(config) { FieldImage.superClass_.configure_.call(this, config); this.flipRtl_ = !!config['flipRtl']; - this.altText_ = Blockly.utils.replaceMessageReferences(config['alt']) || ''; + this.altText_ = replaceMessageReferences(config['alt']) || ''; }; /** @@ -180,15 +180,15 @@ FieldImage.prototype.configure_ = function(config) { * @package */ FieldImage.prototype.initView = function() { - this.imageElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, + this.imageElement_ = createSvgElement( + Svg.IMAGE, { 'height': this.imageHeight_ + 'px', 'width': this.size_.width + 'px', 'alt': this.altText_ }, this.fieldGroup_); - this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, + this.imageElement_.setAttributeNS(XLINK_NS, 'xlink:href', /** @type {string} */ (this.value_)); if (this.clickHandler_) { @@ -225,7 +225,7 @@ FieldImage.prototype.doClassValidation_ = function(opt_newValue) { FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { - this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, + this.imageElement_.setAttributeNS(XLINK_NS, 'xlink:href', String(this.value_)); } }; @@ -286,6 +286,6 @@ FieldImage.prototype.getText_ = function() { return this.altText_; }; -Blockly.fieldRegistry.register('field_image', FieldImage); +fieldRegistry.register('field_image', FieldImage); exports = FieldImage; From 8b815cd5b14976764b243dce5b9d625874baad5d Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:41:35 -0700 Subject: [PATCH 233/313] clang-format core/field_image.js --- core/field_image.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 09c814a1b..9edc92c56 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -33,13 +33,14 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * also be defined. * @param {boolean=} opt_flipRtl Whether to flip the icon in RTL. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor */ -const FieldImage = function(src, width, height, - opt_alt, opt_onClick, opt_flipRtl, opt_config) { +const FieldImage = function( + src, width, height, opt_alt, opt_onClick, opt_flipRtl, opt_config) { // Return early. if (!src) { throw Error('Src value of an image field is required'); @@ -48,12 +49,14 @@ const FieldImage = function(src, width, height, const imageHeight = Number(replaceMessageReferences(height)); const imageWidth = Number(replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { - throw Error('Height and width values of an image field must cast to' + - ' numbers.'); + throw Error( + 'Height and width values of an image field must cast to' + + ' numbers.'); } if (imageHeight <= 0 || imageWidth <= 0) { - throw Error('Height and width values of an image field must be greater' + - ' than 0.'); + throw Error( + 'Height and width values of an image field must be greater' + + ' than 0.'); } // Initialize configurable properties. @@ -71,8 +74,7 @@ const FieldImage = function(src, width, height, */ this.altText_ = ''; - FieldImage.superClass_.constructor.call( - this, src, null, opt_config); + FieldImage.superClass_.constructor.call(this, src, null, opt_config); if (!opt_config) { // If the config wasn't passed, do old configuration. this.flipRtl_ = !!opt_flipRtl; @@ -86,8 +88,7 @@ const FieldImage = function(src, width, height, * @protected * @override */ - this.size_ = new Size(imageWidth, - imageHeight + FieldImage.Y_PADDING); + this.size_ = new Size(imageWidth, imageHeight + FieldImage.Y_PADDING); /** * Store the image height, since it is different from the field height. @@ -135,8 +136,9 @@ FieldImage.prototype.DEFAULT_VALUE = ''; FieldImage.fromJson = function(options) { // `this` might be a subclass of FieldImage if that class doesn't override // the static fromJson method. - return new this(options['src'], options['width'], options['height'], - undefined, undefined, undefined, options); + return new this( + options['src'], options['width'], options['height'], undefined, undefined, + undefined, options); }; /** @@ -181,15 +183,14 @@ FieldImage.prototype.configure_ = function(config) { */ FieldImage.prototype.initView = function() { this.imageElement_ = createSvgElement( - Svg.IMAGE, - { + Svg.IMAGE, { 'height': this.imageHeight_ + 'px', 'width': this.size_.width + 'px', 'alt': this.altText_ }, this.fieldGroup_); - this.imageElement_.setAttributeNS(XLINK_NS, - 'xlink:href', /** @type {string} */ (this.value_)); + this.imageElement_.setAttributeNS( + XLINK_NS, 'xlink:href', /** @type {string} */ (this.value_)); if (this.clickHandler_) { this.imageElement_.style.cursor = 'pointer'; @@ -225,8 +226,8 @@ FieldImage.prototype.doClassValidation_ = function(opt_newValue) { FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { - this.imageElement_.setAttributeNS(XLINK_NS, - 'xlink:href', String(this.value_)); + this.imageElement_.setAttributeNS( + XLINK_NS, 'xlink:href', String(this.value_)); } }; From ae818c05261522af9ab105712ffb2004690a530d Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:52:54 -0700 Subject: [PATCH 234/313] Migrate core/field_multilineinput.js to ES6 const/let --- core/field_multilineinput.js | 70 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index 887d4007f..d57989b86 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -88,7 +88,7 @@ Blockly.FieldMultilineInput.prototype.configure_ = function(config) { * @nocollapse */ Blockly.FieldMultilineInput.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -141,16 +141,17 @@ Blockly.FieldMultilineInput.prototype.initView = function() { * @override */ Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { - var textLines = this.getText(); + let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. return Blockly.Field.NBSP; } - var lines = textLines.split('\n'); + const lines = textLines.split('\n'); textLines = ''; - var displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ : lines.length; - for (var i = 0; i < displayLinesNumber; i++) { - var text = lines[i]; + const displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ + : lines.length; + for (let i = 0; i < displayLinesNumber; i++) { + let text = lines[i]; if (text.length > this.maxDisplayLength) { // Truncate displayed string and add an ellipsis ('...'). text = text.substring(0, this.maxDisplayLength - 4) + '...'; @@ -192,18 +193,18 @@ Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { */ Blockly.FieldMultilineInput.prototype.render_ = function() { // Remove all text group children. - var currentChild; + let currentChild; while ((currentChild = this.textGroup_.firstChild)) { this.textGroup_.removeChild(currentChild); } // Add in text elements into the group. - var lines = this.getDisplayText_().split('\n'); - var y = 0; - for (var i = 0; i < lines.length; i++) { - var lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + + const lines = this.getDisplayText_().split('\n'); + let y = 0; + for (let i = 0; i < lines.length; i++) { + const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; - var span = Blockly.utils.dom.createSvgElement( + const span = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': 'blocklyText blocklyMultilineText', x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, @@ -252,12 +253,12 @@ Blockly.FieldMultilineInput.prototype.render_ = function() { * @protected */ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { - var nodes = this.textGroup_.childNodes; - var totalWidth = 0; - var totalHeight = 0; + const nodes = this.textGroup_.childNodes; + let totalWidth = 0; + let totalHeight = 0; for (var i = 0; i < nodes.length; i++) { - var tspan = /** @type {!Element} */ (nodes[i]); - var textWidth = Blockly.utils.dom.getTextWidth(tspan); + const tspan = /** @type {!Element} */ (nodes[i]); + const textWidth = Blockly.utils.dom.getTextWidth(tspan); if (textWidth > totalWidth) { totalWidth = textWidth; } @@ -270,26 +271,27 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { // absolute longest line, even if it would be truncated after editing. // Otherwise we would get wrong editor width when there are more // lines than this.maxLines_. - var actualEditorLines = this.value_.split('\n'); - var dummyTextElement = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT,{'class': 'blocklyText blocklyMultilineText'}); - var fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; - var fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; - var fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; + const actualEditorLines = this.value_.split('\n'); + const dummyTextElement = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); + const fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; + const fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; + const fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; for (var i = 0; i < actualEditorLines.length; i++) { if (actualEditorLines[i].length > this.maxDisplayLength) { actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; - var lineWidth = Blockly.utils.dom.getFastTextWidth( + const lineWidth = Blockly.utils.dom.getFastTextWidth( dummyTextElement, fontSize, fontWeight, fontFamily); if (lineWidth > totalWidth) { totalWidth = lineWidth; } } - var scrollbarWidth = this.htmlInput_.offsetWidth - this.htmlInput_.clientWidth; + const scrollbarWidth = this.htmlInput_.offsetWidth + - this.htmlInput_.clientWidth; totalWidth += scrollbarWidth; } if (this.borderRect_) { @@ -325,23 +327,23 @@ Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietIn * @protected */ Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { - var div = Blockly.WidgetDiv.DIV; - var scale = this.workspace_.getScale(); + const div = Blockly.WidgetDiv.DIV; + const scale = this.workspace_.getScale(); - var htmlInput = - /** @type {HTMLTextAreaElement} */ (document.createElement('textarea')); + const htmlInput = + /** @type {HTMLTextAreaElement} */ (document.createElement('textarea')); htmlInput.className = 'blocklyHtmlInput blocklyHtmlTextAreaInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); - var fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - var borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + const borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; htmlInput.style.borderRadius = borderRadius; - var paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; - var paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; + const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; + const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; htmlInput.style.padding = paddingY + 'px ' + paddingX + 'px ' + paddingY + 'px ' + paddingX + 'px'; - var lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + + const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; htmlInput.style.lineHeight = (lineHeight * scale) + 'px'; From 8af597761d267fde72c23794badeb35bb6c57a17 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:53:18 -0700 Subject: [PATCH 235/313] Migrate core/field_multilineinput.js to goog.module --- core/field_multilineinput.js | 51 +++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index d57989b86..ea6ed7531 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldMultilineInput'); +goog.module('Blockly.FieldMultilineInput'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Css'); goog.require('Blockly.Field'); @@ -42,8 +43,8 @@ goog.require('Blockly.WidgetDiv'); * @extends {Blockly.FieldTextInput} * @constructor */ -Blockly.FieldMultilineInput = function(opt_value, opt_validator, opt_config) { - Blockly.FieldMultilineInput.superClass_.constructor.call(this, +const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { + FieldMultilineInput.superClass_.constructor.call(this, opt_value, opt_validator, opt_config); /** @@ -68,14 +69,14 @@ Blockly.FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -Blockly.utils.object.inherits(Blockly.FieldMultilineInput, +Blockly.utils.object.inherits(FieldMultilineInput, Blockly.FieldTextInput); /** * @override */ -Blockly.FieldMultilineInput.prototype.configure_ = function(config) { - Blockly.FieldMultilineInput.superClass_.configure_.call(this, config); +FieldMultilineInput.prototype.configure_ = function(config) { + FieldMultilineInput.superClass_.configure_.call(this, config); config.maxLines && this.setMaxLines(config.maxLines); }; @@ -83,11 +84,11 @@ Blockly.FieldMultilineInput.prototype.configure_ = function(config) { * Construct a FieldMultilineInput from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and spellcheck). - * @return {!Blockly.FieldMultilineInput} The new field instance. + * @return {!FieldMultilineInput} The new field instance. * @package * @nocollapse */ -Blockly.FieldMultilineInput.fromJson = function(options) { +FieldMultilineInput.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. @@ -101,7 +102,7 @@ Blockly.FieldMultilineInput.fromJson = function(options) { * @return {!Element} The element containing info about the field's state. * @package */ -Blockly.FieldMultilineInput.prototype.toXml = function(fieldElement) { +FieldMultilineInput.prototype.toXml = function(fieldElement) { // Replace '\n' characters with HTML-escaped equivalent ' '. This is // needed so the plain-text representation of the XML produced by // `Blockly.Xml.domToText` will appear on a single line (this is a limitation @@ -117,7 +118,7 @@ Blockly.FieldMultilineInput.prototype.toXml = function(fieldElement) { * field's state. * @package */ -Blockly.FieldMultilineInput.prototype.fromXml = function(fieldElement) { +FieldMultilineInput.prototype.fromXml = function(fieldElement) { this.setValue(fieldElement.textContent.replace(/ /g, '\n')); }; @@ -125,7 +126,7 @@ Blockly.FieldMultilineInput.prototype.fromXml = function(fieldElement) { * Create the block UI for this field. * @package */ -Blockly.FieldMultilineInput.prototype.initView = function() { +FieldMultilineInput.prototype.initView = function() { this.createBorderRect_(); this.textGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, { @@ -140,7 +141,7 @@ Blockly.FieldMultilineInput.prototype.initView = function() { * @protected * @override */ -Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { +FieldMultilineInput.prototype.getDisplayText_ = function() { let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. @@ -182,8 +183,8 @@ Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { * that this is a string. * @protected */ -Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { - Blockly.FieldMultilineInput.superClass_.doValueUpdate_.call(this, newValue); +FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { + FieldMultilineInput.superClass_.doValueUpdate_.call(this, newValue); this.isOverflowedY_ = this.value_.split('\n').length > this.maxLines_; }; @@ -191,7 +192,7 @@ Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { * Updates the text of the textElement. * @protected */ -Blockly.FieldMultilineInput.prototype.render_ = function() { +FieldMultilineInput.prototype.render_ = function() { // Remove all text group children. let currentChild; while ((currentChild = this.textGroup_.firstChild)) { @@ -252,7 +253,7 @@ Blockly.FieldMultilineInput.prototype.render_ = function() { * Updates the size of the field based on the text. * @protected */ -Blockly.FieldMultilineInput.prototype.updateSize_ = function() { +FieldMultilineInput.prototype.updateSize_ = function() { const nodes = this.textGroup_.childNodes; let totalWidth = 0; let totalHeight = 0; @@ -316,8 +317,8 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { * focus. Defaults to false. * @override */ -Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { - Blockly.FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); +FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { + FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); this.forceRerender(); }; @@ -326,7 +327,7 @@ Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietIn * @return {!HTMLTextAreaElement} The newly created text input editor. * @protected */ -Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { +FieldMultilineInput.prototype.widgetCreate_ = function() { const div = Blockly.WidgetDiv.DIV; const scale = this.workspace_.getScale(); @@ -369,7 +370,7 @@ Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { * @param {number} maxLines Defines the maximum number of lines allowed, * before scrolling functionality is enabled. */ -Blockly.FieldMultilineInput.prototype.setMaxLines = function(maxLines) { +FieldMultilineInput.prototype.setMaxLines = function(maxLines) { if (typeof maxLines === 'number' && maxLines > 0 && maxLines !== this.maxLines_) { this.maxLines_ = maxLines; this.forceRerender(); @@ -380,7 +381,7 @@ Blockly.FieldMultilineInput.prototype.setMaxLines = function(maxLines) { * Returns the maxLines config of this field. * @return {number} The maxLines config value. */ -Blockly.FieldMultilineInput.prototype.getMaxLines = function() { +FieldMultilineInput.prototype.getMaxLines = function() { return this.maxLines_; }; @@ -390,9 +391,9 @@ Blockly.FieldMultilineInput.prototype.getMaxLines = function() { * @param {!Event} e Keyboard event. * @protected */ -Blockly.FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { +FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { if (e.keyCode !== Blockly.utils.KeyCodes.ENTER) { - Blockly.FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); + FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); } }; @@ -415,4 +416,6 @@ Blockly.Css.register([ ]); -Blockly.fieldRegistry.register('field_multilinetext', Blockly.FieldMultilineInput); +Blockly.fieldRegistry.register('field_multilinetext', FieldMultilineInput); + +exports = FieldMultilineInput; diff --git a/tests/deps.js b/tests/deps.js index 77f7d15a2..f62333982 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -56,7 +56,7 @@ goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], [' goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); From d91f36eab9f4e9a3251d95967ffea3947166daf5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:51:10 -0700 Subject: [PATCH 236/313] Migrate core/field_multilineinput.js named requires --- core/field_multilineinput.js | 80 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index ea6ed7531..f3872919a 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -15,18 +15,18 @@ goog.module('Blockly.FieldMultilineInput'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Css'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); +const Css = goog.require('Blockly.Css'); +const Field = goog.require('Blockly.Field'); +const FieldTextInput = goog.require('Blockly.FieldTextInput'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Svg = goog.require('Blockly.utils.Svg'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const aria = goog.require('Blockly.utils.aria'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -40,7 +40,7 @@ goog.require('Blockly.WidgetDiv'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldTextInput} + * @extends {FieldTextInput} * @constructor */ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { @@ -69,8 +69,8 @@ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -Blockly.utils.object.inherits(FieldMultilineInput, - Blockly.FieldTextInput); +inherits(FieldMultilineInput, + FieldTextInput); /** * @override @@ -89,7 +89,7 @@ FieldMultilineInput.prototype.configure_ = function(config) { * @nocollapse */ FieldMultilineInput.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -128,8 +128,8 @@ FieldMultilineInput.prototype.fromXml = function(fieldElement) { */ FieldMultilineInput.prototype.initView = function() { this.createBorderRect_(); - this.textGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, { + this.textGroup_ = dom.createSvgElement( + Svg.G, { 'class': 'blocklyEditableText', }, this.fieldGroup_); }; @@ -145,7 +145,7 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. - return Blockly.Field.NBSP; + return Field.NBSP; } const lines = textLines.split('\n'); textLines = ''; @@ -160,7 +160,7 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { text = text.substring(0, text.length - 3) + '...'; } // Replace whitespace with non-breaking spaces so the text doesn't collapse. - text = text.replace(/\s/g, Blockly.Field.NBSP); + text = text.replace(/\s/g, Field.NBSP); textLines += text; if (i !== displayLinesNumber - 1) { @@ -205,8 +205,8 @@ FieldMultilineInput.prototype.render_ = function() { for (let i = 0; i < lines.length; i++) { const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; - const span = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, { + const span = dom.createSvgElement( + Svg.TEXT, { 'class': 'blocklyText blocklyMultilineText', x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, y: y + this.getConstants().FIELD_BORDER_RECT_Y_PADDING, @@ -219,9 +219,9 @@ FieldMultilineInput.prototype.render_ = function() { if (this.isBeingEdited_) { var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (this.isOverflowedY_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); + dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); + dom.removeClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } } @@ -238,13 +238,13 @@ FieldMultilineInput.prototype.render_ = function() { } var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, true); + dom.addClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, true); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, false); + dom.removeClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, false); } } }; @@ -259,7 +259,7 @@ FieldMultilineInput.prototype.updateSize_ = function() { let totalHeight = 0; for (var i = 0; i < nodes.length; i++) { const tspan = /** @type {!Element} */ (nodes[i]); - const textWidth = Blockly.utils.dom.getTextWidth(tspan); + const textWidth = dom.getTextWidth(tspan); if (textWidth > totalWidth) { totalWidth = textWidth; } @@ -273,8 +273,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { // Otherwise we would get wrong editor width when there are more // lines than this.maxLines_. const actualEditorLines = this.value_.split('\n'); - const dummyTextElement = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); + const dummyTextElement = dom.createSvgElement( + Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); const fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; const fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; const fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; @@ -284,7 +284,7 @@ FieldMultilineInput.prototype.updateSize_ = function() { actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; - const lineWidth = Blockly.utils.dom.getFastTextWidth( + const lineWidth = dom.getFastTextWidth( dummyTextElement, fontSize, fontWeight, fontFamily); if (lineWidth > totalWidth) { totalWidth = lineWidth; @@ -328,7 +328,7 @@ FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { * @protected */ FieldMultilineInput.prototype.widgetCreate_ = function() { - const div = Blockly.WidgetDiv.DIV; + const div = WidgetDiv.DIV; const scale = this.workspace_.getScale(); const htmlInput = @@ -338,7 +338,7 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - const borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + const borderRadius = (FieldTextInput.BORDERRADIUS * scale) + 'px'; htmlInput.style.borderRadius = borderRadius; const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; @@ -353,7 +353,7 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { htmlInput.value = htmlInput.defaultValue = this.getEditorText_(this.value_); htmlInput.untypedDefaultValue_ = this.value_; htmlInput.oldValue_ = null; - if (Blockly.utils.userAgent.GECKO) { + if (userAgent.GECKO) { // In FF, ensure the browser reflows before resizing to avoid issue #2777. setTimeout(this.resizeEditor_.bind(this), 0); } else { @@ -392,7 +392,7 @@ FieldMultilineInput.prototype.getMaxLines = function() { * @protected */ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { - if (e.keyCode !== Blockly.utils.KeyCodes.ENTER) { + if (e.keyCode !== KeyCodes.ENTER) { FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); } }; @@ -400,7 +400,7 @@ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { /** * CSS for multiline field. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyHtmlTextAreaInput {', 'font-family: monospace;', @@ -416,6 +416,6 @@ Blockly.Css.register([ ]); -Blockly.fieldRegistry.register('field_multilinetext', FieldMultilineInput); +fieldRegistry.register('field_multilinetext', FieldMultilineInput); exports = FieldMultilineInput; From aeac27661dacc3b01d9d6fb79ccf28b9b92681f5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 11:01:39 -0700 Subject: [PATCH 237/313] clang-format core/field_multilineinput.js --- core/field_multilineinput.js | 69 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index f3872919a..4842429a5 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -38,14 +38,15 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * text as an argument and returns either the accepted text, a replacement * text, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} * for a list of properties this parameter supports. * @extends {FieldTextInput} * @constructor */ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { - FieldMultilineInput.superClass_.constructor.call(this, - opt_value, opt_validator, opt_config); + FieldMultilineInput.superClass_.constructor.call( + this, opt_value, opt_validator, opt_config); /** * The SVG group element that will contain a text element for each text row @@ -69,8 +70,7 @@ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -inherits(FieldMultilineInput, - FieldTextInput); +inherits(FieldMultilineInput, FieldTextInput); /** * @override @@ -131,7 +131,8 @@ FieldMultilineInput.prototype.initView = function() { this.textGroup_ = dom.createSvgElement( Svg.G, { 'class': 'blocklyEditableText', - }, this.fieldGroup_); + }, + this.fieldGroup_); }; /** @@ -149,8 +150,8 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { } const lines = textLines.split('\n'); textLines = ''; - const displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ - : lines.length; + const displayLinesNumber = + this.isOverflowedY_ ? this.maxLines_ : lines.length; for (let i = 0; i < displayLinesNumber; i++) { let text = lines[i]; if (text.length > this.maxDisplayLength) { @@ -211,13 +212,14 @@ FieldMultilineInput.prototype.render_ = function() { x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, y: y + this.getConstants().FIELD_BORDER_RECT_Y_PADDING, dy: this.getConstants().FIELD_TEXT_BASELINE - }, this.textGroup_); + }, + this.textGroup_); span.appendChild(document.createTextNode(lines[i])); y += lineHeight; } if (this.isBeingEdited_) { - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + var htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (this.isOverflowedY_) { dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } else { @@ -236,15 +238,13 @@ FieldMultilineInput.prototype.render_ = function() { } else { this.resizeEditor_(); } - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + var htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (!this.isTextValid_) { dom.addClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, true); + aria.setState(htmlInput, aria.State.INVALID, true); } else { dom.removeClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, false); + aria.setState(htmlInput, aria.State.INVALID, false); } } }; @@ -281,7 +281,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { for (var i = 0; i < actualEditorLines.length; i++) { if (actualEditorLines[i].length > this.maxDisplayLength) { - actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); + actualEditorLines[i] = + actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; const lineWidth = dom.getFastTextWidth( @@ -291,8 +292,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { } } - const scrollbarWidth = this.htmlInput_.offsetWidth - - this.htmlInput_.clientWidth; + const scrollbarWidth = + this.htmlInput_.offsetWidth - this.htmlInput_.clientWidth; totalWidth += scrollbarWidth; } if (this.borderRect_) { @@ -318,7 +319,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { * @override */ FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { - FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); + FieldMultilineInput.superClass_.showEditor_.call( + this, _opt_e, opt_quietInput); this.forceRerender(); }; @@ -342,8 +344,8 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { htmlInput.style.borderRadius = borderRadius; const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; - htmlInput.style.padding = paddingY + 'px ' + paddingX + 'px ' + paddingY + - 'px ' + paddingX + 'px'; + htmlInput.style.padding = + paddingY + 'px ' + paddingX + 'px ' + paddingY + 'px ' + paddingX + 'px'; const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; htmlInput.style.lineHeight = (lineHeight * scale) + 'px'; @@ -371,7 +373,8 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { * before scrolling functionality is enabled. */ FieldMultilineInput.prototype.setMaxLines = function(maxLines) { - if (typeof maxLines === 'number' && maxLines > 0 && maxLines !== this.maxLines_) { + if (typeof maxLines === 'number' && maxLines > 0 && + maxLines !== this.maxLines_) { this.maxLines_ = maxLines; this.forceRerender(); } @@ -401,18 +404,16 @@ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { * CSS for multiline field. See css.js for use. */ Css.register([ - /* eslint-disable indent */ - '.blocklyHtmlTextAreaInput {', - 'font-family: monospace;', - 'resize: none;', - 'overflow: hidden;', - 'height: 100%;', - 'text-align: left;', - '}', - '.blocklyHtmlTextAreaInputOverflowedY {', - 'overflow-y: scroll;', - '}' - /* eslint-enable indent */ + `.blocklyHtmlTextAreaInput { + font-family: monospace; + resize: none; + overflow: hidden; + height: 100%; + text-align: left; +}`, + `.blocklyHtmlTextAreaInputOverflowedY { + overflow-y: scroll; +}` ]); From b1f868fbafd01b8284f1e6155e71442303424b9b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:02:15 -0700 Subject: [PATCH 238/313] Migrate core/flyout_horizontal.js to ES6 const/let --- core/flyout_horizontal.js | 103 +++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 66e9ff18e..3ec62518a 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -53,10 +53,10 @@ Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { return; } - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); if (typeof xyRatio.x == 'number') { this.workspace_.scrollX = @@ -85,13 +85,13 @@ Blockly.HorizontalFlyout.prototype.getY = function() { if (!this.isVisible()) { return 0; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var toolboxMetrics = metricsManager.getToolboxMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const toolboxMetrics = metricsManager.getToolboxMetrics(); - var y = 0; - var atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + let y = 0; + const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. @@ -133,18 +133,18 @@ Blockly.HorizontalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); // Record the width for workspace metrics. this.width_ = targetWorkspaceViewMetrics.width; - var edgeWidth = targetWorkspaceViewMetrics.width - 2 * this.CORNER_RADIUS; - var edgeHeight = this.height_ - this.CORNER_RADIUS; + const edgeWidth = targetWorkspaceViewMetrics.width - 2 * this.CORNER_RADIUS; + const edgeHeight = this.height_ - this.CORNER_RADIUS; this.setBackgroundPath_(edgeWidth, edgeHeight); - var x = this.getX(); - var y = this.getY(); + const x = this.getX(); + const y = this.getY(); this.positionAt_(this.width_, this.height_, x, y); }; @@ -159,9 +159,9 @@ Blockly.HorizontalFlyout.prototype.position = function() { */ Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { - var atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // Start at top left. - var path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; + const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; if (atTop) { // Top. @@ -206,15 +206,15 @@ Blockly.HorizontalFlyout.prototype.scrollToStart = function() { * @protected */ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { - var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); - var delta = scrollDelta.x || scrollDelta.y; + const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const delta = scrollDelta.x || scrollDelta.y; if (delta) { - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); - var pos = (viewMetrics.left - scrollMetrics.left) + delta; + const pos = (viewMetrics.left - scrollMetrics.left) + delta; this.workspace_.scrollbar.setX(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. Blockly.WidgetDiv.hide(); @@ -235,37 +235,38 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { */ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; - var margin = this.MARGIN; - var cursorX = margin + this.tabWidth_; - var cursorY = margin; + const margin = this.MARGIN; + let cursorX = margin + this.tabWidth_; + const cursorY = margin; if (this.RTL) { contents = contents.reverse(); } - for (var i = 0, item; (item = contents[i]); i++) { + for (let i = 0, item; (item = contents[i]); i++) { if (item.type == 'block') { - var block = item.block; - var allBlocks = block.getDescendants(false); - for (var j = 0, child; (child = allBlocks[j]); j++) { + const block = item.block; + const allBlocks = block.getDescendants(false); + for (let j = 0, child; (child = allBlocks[j]); j++) { // Mark blocks as being inside a flyout. This is used to detect and // prevent the closure of the flyout if the user right-clicks on such a // block. child.isInFlyout = true; } block.render(); - var root = block.getSvgRoot(); - var blockHW = block.getHeightWidth(); + const root = block.getSvgRoot(); + const blockHW = block.getHeightWidth(); // Figure out where to place the block. - var tab = block.outputConnection ? this.tabWidth_ : 0; + const tab = block.outputConnection ? this.tabWidth_ : 0; + let moveX; if (this.RTL) { - var moveX = cursorX + blockHW.width; + moveX = cursorX + blockHW.width; } else { - var moveX = cursorX - tab; + moveX = cursorX - tab; } block.moveBy(moveX, cursorY); - var rect = this.createRect_(block, moveX, cursorY, blockHW, i); + const rect = this.createRect_(block, moveX, cursorY, blockHW, i); cursorX += (blockHW.width + gaps[i]); this.addBlockListeners_(root, block, rect); @@ -287,12 +288,12 @@ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { */ Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { - var dx = currentDragDeltaXY.x; - var dy = currentDragDeltaXY.y; + const dx = currentDragDeltaXY.x; + const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. - var dragDirection = Math.atan2(dy, dx) / Math.PI * 180; + const dragDirection = Math.atan2(dy, dx) / Math.PI * 180; - var range = this.dragAngleRange_; + const range = this.dragAngleRange_; // Check for up or down dragging. if ((dragDirection < 90 + range && dragDirection > 90 - range) || (dragDirection > -90 - range && dragDirection < -90 + range)) { @@ -314,15 +315,15 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { return null; } - var flyoutRect = this.svgGroup_.getBoundingClientRect(); + const flyoutRect = this.svgGroup_.getBoundingClientRect(); // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout // area are still deleted. Must be larger than the largest screen size, // but be smaller than half Number.MAX_SAFE_INTEGER (not available on IE). - var BIG_NUM = 1000000000; - var top = flyoutRect.top; + const BIG_NUM = 1000000000; + const top = flyoutRect.top; if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP) { - var height = flyoutRect.height; + const height = flyoutRect.height; return new Blockly.utils.Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); } else { // Bottom. return new Blockly.utils.Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); @@ -336,13 +337,13 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { */ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); - var flyoutHeight = 0; - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { + let flyoutHeight = 0; + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { flyoutHeight = Math.max(flyoutHeight, block.getHeightWidth().height); } - var buttons = this.buttons_; - for (var i = 0, button; (button = buttons[i]); i++) { + const buttons = this.buttons_; + for (let i = 0, button; (button = buttons[i]); i++) { flyoutHeight = Math.max(flyoutHeight, button.height); } flyoutHeight += this.MARGIN * 1.5; @@ -350,7 +351,7 @@ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { flyoutHeight += Blockly.Scrollbar.scrollbarThickness; if (this.height_ != flyoutHeight) { - for (var i = 0, block; (block = blocks[i]); i++) { + for (let i = 0, block; (block = blocks[i]); i++) { if (block.flyoutRect_) { this.moveRectToBlock_(block.flyoutRect_, block); } From 8b0d1df173b43ae48d4d9d84e89d46ded89d2659 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:04:52 -0700 Subject: [PATCH 239/313] Migrate core/flyout_horizontal.js to goog.module --- core/flyout_horizontal.js | 35 +++++++++++++++++++---------------- tests/deps.js | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 3ec62518a..96cad2c9f 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.HorizontalFlyout'); +goog.module('Blockly.HorizontalFlyout'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); @@ -35,11 +36,11 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.Flyout} * @constructor */ -Blockly.HorizontalFlyout = function(workspaceOptions) { - Blockly.HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); +const HorizontalFlyout = function(workspaceOptions) { + HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); this.horizontalLayout = true; }; -Blockly.utils.object.inherits(Blockly.HorizontalFlyout, Blockly.Flyout); +Blockly.utils.object.inherits(HorizontalFlyout, Blockly.Flyout); /** * Sets the translation of the flyout to match the scrollbars. @@ -48,7 +49,7 @@ Blockly.utils.object.inherits(Blockly.HorizontalFlyout, Blockly.Flyout); * similar x property. * @protected */ -Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { +HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } @@ -72,7 +73,7 @@ Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.HorizontalFlyout.prototype.getX = function() { +HorizontalFlyout.prototype.getX = function() { // X is always 0 since this is a horizontal flyout. return 0; }; @@ -81,7 +82,7 @@ Blockly.HorizontalFlyout.prototype.getX = function() { * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.HorizontalFlyout.prototype.getY = function() { +HorizontalFlyout.prototype.getY = function() { if (!this.isVisible()) { return 0; } @@ -129,7 +130,7 @@ Blockly.HorizontalFlyout.prototype.getY = function() { /** * Move the flyout to the edge of the workspace. */ -Blockly.HorizontalFlyout.prototype.position = function() { +HorizontalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } @@ -157,7 +158,7 @@ Blockly.HorizontalFlyout.prototype.position = function() { * rounded corners. * @private */ -Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( +HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // Start at top left. @@ -196,7 +197,7 @@ Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( /** * Scroll the flyout to the top. */ -Blockly.HorizontalFlyout.prototype.scrollToStart = function() { +HorizontalFlyout.prototype.scrollToStart = function() { this.workspace_.scrollbar.setX(this.RTL ? Infinity : 0); }; @@ -205,7 +206,7 @@ Blockly.HorizontalFlyout.prototype.scrollToStart = function() { * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { +HorizontalFlyout.prototype.wheel_ = function(e) { const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); const delta = scrollDelta.x || scrollDelta.y; @@ -233,7 +234,7 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { +HorizontalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; const margin = this.MARGIN; let cursorX = margin + this.tabWidth_; @@ -286,7 +287,7 @@ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( +HorizontalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; @@ -308,7 +309,7 @@ Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.HorizontalFlyout.prototype.getClientRect = function() { +HorizontalFlyout.prototype.getClientRect = function() { if (!this.svgGroup_ || this.autoClose || !this.isVisible()) { // The bounding rectangle won't compute correctly if the flyout is closed // and auto-close flyouts aren't valid drag targets (or delete areas). @@ -335,7 +336,7 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { * For RTL: Lay out the blocks right-aligned. * @protected */ -Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { +HorizontalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); let flyoutHeight = 0; const blocks = this.workspace_.getTopBlocks(false); @@ -375,4 +376,6 @@ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { }; Blockly.registry.register(Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - Blockly.registry.DEFAULT, Blockly.HorizontalFlyout); + Blockly.registry.DEFAULT, HorizontalFlyout); + +exports = HorizontalFlyout; diff --git a/tests/deps.js b/tests/deps.js index f62333982..87600526f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -63,7 +63,7 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); From 7ee9b0a41cc286cab6ff75e163c02d92ccc0c010 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:11:53 -0700 Subject: [PATCH 240/313] Migrate core/flyout_horizontal.js to named requires --- core/flyout_horizontal.js | 59 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 96cad2c9f..8f530516d 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -13,34 +13,35 @@ goog.module('Blockly.HorizontalFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Flyout = goog.require('Blockly.Flyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const Rect = goog.require('Blockly.utils.Rect'); +const Scrollbar = goog.require('Blockly.Scrollbar'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const registry = goog.require('Blockly.registry'); +const {Position} = goog.require('Blockly.utils.toolbox'); +const {getScrollDeltaPixels} = goog.require('Blockly.utils'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Flyout'); -goog.require('Blockly.registry'); -goog.require('Blockly.Scrollbar'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Coordinate'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. - * @extends {Blockly.Flyout} + * @extends {Flyout} * @constructor */ const HorizontalFlyout = function(workspaceOptions) { HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); this.horizontalLayout = true; }; -Blockly.utils.object.inherits(HorizontalFlyout, Blockly.Flyout); +inherits(HorizontalFlyout, Flyout); /** * Sets the translation of the flyout to match the scrollbars. @@ -92,7 +93,7 @@ HorizontalFlyout.prototype.getY = function() { const toolboxMetrics = metricsManager.getToolboxMetrics(); let y = 0; - const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Position.TOP; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. @@ -160,7 +161,7 @@ HorizontalFlyout.prototype.position = function() { */ HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { - const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Position.TOP; // Start at top left. const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; @@ -207,7 +208,7 @@ HorizontalFlyout.prototype.scrollToStart = function() { * @protected */ HorizontalFlyout.prototype.wheel_ = function(e) { - const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = getScrollDeltaPixels(e); const delta = scrollDelta.x || scrollDelta.y; if (delta) { @@ -218,8 +219,8 @@ HorizontalFlyout.prototype.wheel_ = function(e) { const pos = (viewMetrics.left - scrollMetrics.left) + delta; this.workspace_.scrollbar.setX(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); } // Don't scroll the page. @@ -282,7 +283,7 @@ HorizontalFlyout.prototype.layout_ = function(contents, gaps) { * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package @@ -306,7 +307,7 @@ HorizontalFlyout.prototype.isDragTowardWorkspace = 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. */ HorizontalFlyout.prototype.getClientRect = function() { @@ -323,11 +324,11 @@ HorizontalFlyout.prototype.getClientRect = function() { const BIG_NUM = 1000000000; const top = flyoutRect.top; - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP) { + if (this.toolboxPosition_ == Position.TOP) { const height = flyoutRect.height; - return new Blockly.utils.Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); + return new Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); } else { // Bottom. - return new Blockly.utils.Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); + return new Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); } }; @@ -349,7 +350,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } flyoutHeight += this.MARGIN * 1.5; flyoutHeight *= this.workspace_.scale; - flyoutHeight += Blockly.Scrollbar.scrollbarThickness; + flyoutHeight += Scrollbar.scrollbarThickness; if (this.height_ != flyoutHeight) { for (let i = 0, block; (block = blocks[i]); i++) { @@ -359,7 +360,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_ && - this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP && + this.toolboxPosition_ == Position.TOP && !this.targetWorkspace.getToolbox()) { // This flyout is a simple toolbox. Reposition the workspace so that (0,0) // is in the correct position relative to the new absolute edge (ie @@ -375,7 +376,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } }; -Blockly.registry.register(Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - Blockly.registry.DEFAULT, HorizontalFlyout); +registry.register(registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, + registry.DEFAULT, HorizontalFlyout); exports = HorizontalFlyout; From 08c18b479cc9f6d5cc9566d00dfb5a534e6ad35b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:13:11 -0700 Subject: [PATCH 241/313] clang-format core/flyout_horizontal.js --- core/flyout_horizontal.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 8f530516d..9bfc8aa91 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -63,10 +63,11 @@ HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { if (typeof xyRatio.x == 'number') { this.workspace_.scrollX = -(scrollMetrics.left + - (scrollMetrics.width - viewMetrics.width) * xyRatio.x); + (scrollMetrics.width - viewMetrics.width) * xyRatio.x); } - this.workspace_.translate(this.workspace_.scrollX + absoluteMetrics.left, + this.workspace_.translate( + this.workspace_.scrollX + absoluteMetrics.left, this.workspace_.scrollY + absoluteMetrics.top); }; @@ -159,8 +160,7 @@ HorizontalFlyout.prototype.position = function() { * rounded corners. * @private */ -HorizontalFlyout.prototype.setBackgroundPath_ = function( - width, height) { +HorizontalFlyout.prototype.setBackgroundPath_ = function(width, height) { const atTop = this.toolboxPosition_ == Position.TOP; // Start at top left. const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; @@ -171,20 +171,24 @@ HorizontalFlyout.prototype.setBackgroundPath_ = function( // Right. path.push('v', height); // Bottom. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, -this.CORNER_RADIUS, this.CORNER_RADIUS); path.push('h', -width); // Left. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, -this.CORNER_RADIUS, -this.CORNER_RADIUS); path.push('z'); } else { // Top. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, this.CORNER_RADIUS, -this.CORNER_RADIUS); path.push('h', width); // Right. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, this.CORNER_RADIUS, this.CORNER_RADIUS); path.push('v', height); // Bottom. @@ -366,7 +370,8 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { // is in the correct position relative to the new absolute edge (ie // toolbox edge). this.targetWorkspace.translate( - this.targetWorkspace.scrollX, this.targetWorkspace.scrollY + flyoutHeight); + this.targetWorkspace.scrollX, + this.targetWorkspace.scrollY + flyoutHeight); } // Record the height for workspace metrics and .position. @@ -376,7 +381,8 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } }; -registry.register(registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - registry.DEFAULT, HorizontalFlyout); +registry.register( + registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, registry.DEFAULT, + HorizontalFlyout); exports = HorizontalFlyout; From adc78d192c6b5852f0cfc5363777a5ac2a882465 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:24:09 -0700 Subject: [PATCH 242/313] Migrate core/flyout_vertical.js to ES6 const/let --- core/flyout_vertical.js | 106 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index a09b3fb8e..786deff96 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -59,10 +59,10 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); if (typeof xyRatio.y == 'number') { this.workspace_.scrollY = @@ -81,11 +81,11 @@ Blockly.VerticalFlyout.prototype.getX = function() { if (!this.isVisible()) { return 0; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var toolboxMetrics = metricsManager.getToolboxMetrics(); - var x = 0; + const metricsManager = this.targetWorkspace.getMetricsManager(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const toolboxMetrics = metricsManager.getToolboxMetrics(); + let x = 0; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { @@ -137,18 +137,18 @@ Blockly.VerticalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); // Record the height for workspace metrics. this.height_ = targetWorkspaceViewMetrics.height; - var edgeWidth = this.width_ - this.CORNER_RADIUS; - var edgeHeight = targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; + const edgeWidth = this.width_ - this.CORNER_RADIUS; + const edgeHeight = targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; this.setBackgroundPath_(edgeWidth, edgeHeight); - var x = this.getX(); - var y = this.getY(); + const x = this.getX(); + const y = this.getY(); this.positionAt_(this.width_, this.height_, x, y); }; @@ -162,11 +162,11 @@ Blockly.VerticalFlyout.prototype.position = function() { * @private */ Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { - var atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; - var totalWidth = width + this.CORNER_RADIUS; + const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; + const totalWidth = width + this.CORNER_RADIUS; // Decide whether to start on the left or right. - var path = ['M ' + (atRight ? totalWidth : 0) + ',0']; + const path = ['M ' + (atRight ? totalWidth : 0) + ',0']; // Top. path.push('h', atRight ? -width : width); // Rounded corner. @@ -200,13 +200,13 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() { * @protected */ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { - var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); if (scrollDelta.y) { - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var pos = (viewMetrics.top - scrollMetrics.top) + scrollDelta.y; + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const pos = (viewMetrics.top - scrollMetrics.top) + scrollDelta.y; this.workspace_.scrollbar.setY(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. @@ -228,27 +228,27 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { */ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; - var margin = this.MARGIN; - var cursorX = this.RTL ? margin : margin + this.tabWidth_; - var cursorY = margin; + const margin = this.MARGIN; + const cursorX = this.RTL ? margin : margin + this.tabWidth_; + let cursorY = margin; - for (var i = 0, item; (item = contents[i]); i++) { + for (let i = 0, item; (item = contents[i]); i++) { if (item.type == 'block') { - var block = item.block; - var allBlocks = block.getDescendants(false); - for (var j = 0, child; (child = allBlocks[j]); j++) { + const block = item.block; + const allBlocks = block.getDescendants(false); + for (let j = 0, child; (child = allBlocks[j]); j++) { // Mark blocks as being inside a flyout. This is used to detect and // prevent the closure of the flyout if the user right-clicks on such a // block. child.isInFlyout = true; } block.render(); - var root = block.getSvgRoot(); - var blockHW = block.getHeightWidth(); - var moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; + const root = block.getSvgRoot(); + const blockHW = block.getHeightWidth(); + const moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; block.moveBy(moveX, cursorY); - var rect = this.createRect_(block, + const rect = this.createRect_(block, this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); this.addBlockListeners_(root, block, rect); @@ -272,12 +272,12 @@ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { */ Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { - var dx = currentDragDeltaXY.x; - var dy = currentDragDeltaXY.y; + const dx = currentDragDeltaXY.x; + const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. - var dragDirection = Math.atan2(dy, dx) / Math.PI * 180; + const dragDirection = Math.atan2(dy, dx) / Math.PI * 180; - var range = this.dragAngleRange_; + const range = this.dragAngleRange_; // Check for left or right dragging. if ((dragDirection < range && dragDirection > -range) || (dragDirection < -180 + range || dragDirection > 180 - range)) { @@ -299,15 +299,15 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { return null; } - var flyoutRect = this.svgGroup_.getBoundingClientRect(); + const flyoutRect = this.svgGroup_.getBoundingClientRect(); // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout // area are still deleted. Must be larger than the largest screen size, // but be smaller than half Number.MAX_SAFE_INTEGER (not available on IE). - var BIG_NUM = 1000000000; - var left = flyoutRect.left; + const BIG_NUM = 1000000000; + const left = flyoutRect.left; if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { - var width = flyoutRect.width; + const width = flyoutRect.width; return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); } else { // Right return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); @@ -321,16 +321,16 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { */ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); - var flyoutWidth = 0; - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { - var width = block.getHeightWidth().width; + let flyoutWidth = 0; + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { + let width = block.getHeightWidth().width; if (block.outputConnection) { width -= this.tabWidth_; } flyoutWidth = Math.max(flyoutWidth, width); } - for (var i = 0, button; (button = this.buttons_[i]); i++) { + for (let i = 0, button; (button = this.buttons_[i]); i++) { flyoutWidth = Math.max(flyoutWidth, button.width); } flyoutWidth += this.MARGIN * 1.5 + this.tabWidth_; @@ -338,11 +338,11 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { flyoutWidth += Blockly.Scrollbar.scrollbarThickness; if (this.width_ != flyoutWidth) { - for (var i = 0, block; (block = blocks[i]); i++) { + for (let i = 0, block; (block = blocks[i]); i++) { if (this.RTL) { // With the flyoutWidth known, right-align the blocks. - var oldX = block.getRelativeToSurfaceXY().x; - var newX = flyoutWidth / this.workspace_.scale - this.MARGIN; + const oldX = block.getRelativeToSurfaceXY().x; + let newX = flyoutWidth / this.workspace_.scale - this.MARGIN; if (!block.outputConnection) { newX -= this.tabWidth_; } @@ -354,9 +354,9 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { } if (this.RTL) { // With the flyoutWidth known, right-align the buttons. - for (var i = 0, button; (button = this.buttons_[i]); i++) { - var y = button.getPosition().y; - var x = flyoutWidth / this.workspace_.scale - button.width - + for (let i = 0, button; (button = this.buttons_[i]); i++) { + const y = button.getPosition().y; + const x = flyoutWidth / this.workspace_.scale - button.width - this.MARGIN - this.tabWidth_; button.moveTo(x, y); } From cd4f0e9f8c67edcfc9f068de9a3c49526b85bdaf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:27:27 -0700 Subject: [PATCH 243/313] Migrate core/flyout_vertical.js to goog.module --- core/flyout_vertical.js | 37 ++++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 786deff96..d937cce6e 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.VerticalFlyout'); +goog.module('Blockly.VerticalFlyout'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); @@ -37,16 +38,16 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.Flyout} * @constructor */ -Blockly.VerticalFlyout = function(workspaceOptions) { - Blockly.VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); +const VerticalFlyout = function(workspaceOptions) { + VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); }; -Blockly.utils.object.inherits(Blockly.VerticalFlyout, Blockly.Flyout); +Blockly.utils.object.inherits(VerticalFlyout, Blockly.Flyout); /** * The name of the vertical flyout in the registry. * @type {string} */ -Blockly.VerticalFlyout.registryName = 'verticalFlyout'; +VerticalFlyout.registryName = 'verticalFlyout'; /** * Sets the translation of the flyout to match the scrollbars. @@ -55,7 +56,7 @@ Blockly.VerticalFlyout.registryName = 'verticalFlyout'; * similar x property. * @protected */ -Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { +VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } @@ -77,7 +78,7 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.VerticalFlyout.prototype.getX = function() { +VerticalFlyout.prototype.getX = function() { if (!this.isVisible()) { return 0; } @@ -125,7 +126,7 @@ Blockly.VerticalFlyout.prototype.getX = function() { * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.VerticalFlyout.prototype.getY = function() { +VerticalFlyout.prototype.getY = function() { // Y is always 0 since this is a vertical flyout. return 0; }; @@ -133,7 +134,7 @@ Blockly.VerticalFlyout.prototype.getY = function() { /** * Move the flyout to the edge of the workspace. */ -Blockly.VerticalFlyout.prototype.position = function() { +VerticalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } @@ -161,7 +162,7 @@ Blockly.VerticalFlyout.prototype.position = function() { * rounded corners. * @private */ -Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { +VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; const totalWidth = width + this.CORNER_RADIUS; @@ -190,7 +191,7 @@ Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { /** * Scroll the flyout to the top. */ -Blockly.VerticalFlyout.prototype.scrollToStart = function() { +VerticalFlyout.prototype.scrollToStart = function() { this.workspace_.scrollbar.setY(0); }; @@ -199,7 +200,7 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() { * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.VerticalFlyout.prototype.wheel_ = function(e) { +VerticalFlyout.prototype.wheel_ = function(e) { const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); if (scrollDelta.y) { @@ -226,7 +227,7 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { +VerticalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; const margin = this.MARGIN; const cursorX = this.RTL ? margin : margin + this.tabWidth_; @@ -270,7 +271,7 @@ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( +VerticalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; @@ -292,7 +293,7 @@ Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.VerticalFlyout.prototype.getClientRect = function() { +VerticalFlyout.prototype.getClientRect = function() { if (!this.svgGroup_ || this.autoClose || !this.isVisible()) { // The bounding rectangle won't compute correctly if the flyout is closed // and auto-close flyouts aren't valid drag targets (or delete areas). @@ -319,7 +320,7 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { * For RTL: Lay out the blocks and buttons to be right-aligned. * @protected */ -Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { +VerticalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); let flyoutWidth = 0; const blocks = this.workspace_.getTopBlocks(false); @@ -380,4 +381,6 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { }; Blockly.registry.register(Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - Blockly.registry.DEFAULT, Blockly.VerticalFlyout); + Blockly.registry.DEFAULT, VerticalFlyout); + +exports = VerticalFlyout; diff --git a/tests/deps.js b/tests/deps.js index f62333982..de0ab070c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -64,7 +64,7 @@ goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], [' goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); From 394d71a7d97cd24653491a944c17e0c746bac810 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:32:27 -0700 Subject: [PATCH 244/313] Migrate core/flyout_vertical.js to named requires --- core/flyout_vertical.js | 63 +++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index d937cce6e..8c1177c30 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -13,35 +13,36 @@ goog.module('Blockly.VerticalFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Flyout = goog.require('Blockly.Flyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const Rect = goog.require('Blockly.utils.Rect'); +const Scrollbar = goog.require('Blockly.Scrollbar'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const registry = goog.require('Blockly.registry'); +const {Position} = goog.require('Blockly.utils.toolbox'); +const {getScrollDeltaPixels} = goog.require('Blockly.utils'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Flyout'); -goog.require('Blockly.registry'); -goog.require('Blockly.Scrollbar'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Coordinate'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. - * @extends {Blockly.Flyout} + * @extends {Flyout} * @constructor */ const VerticalFlyout = function(workspaceOptions) { VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); }; -Blockly.utils.object.inherits(VerticalFlyout, Blockly.Flyout); +inherits(VerticalFlyout, Flyout); /** * The name of the vertical flyout in the registry. @@ -92,14 +93,14 @@ VerticalFlyout.prototype.getX = function() { if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. if (this.targetWorkspace.getToolbox()) { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = toolboxMetrics.width; } else { x = viewMetrics.width - this.width_; } // Simple (flyout-only) toolbox. } else { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = 0; } else { // The simple flyout does not cover the workspace. @@ -108,7 +109,7 @@ VerticalFlyout.prototype.getX = function() { } // Trashcan flyout is opposite the main flyout. } else { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = 0; } else { // Because the anchor point of the flyout is on the left, but we want @@ -163,7 +164,7 @@ VerticalFlyout.prototype.position = function() { * @private */ VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { - const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; + const atRight = this.toolboxPosition_ == Position.RIGHT; const totalWidth = width + this.CORNER_RADIUS; // Decide whether to start on the left or right. @@ -201,7 +202,7 @@ VerticalFlyout.prototype.scrollToStart = function() { * @protected */ VerticalFlyout.prototype.wheel_ = function(e) { - const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = getScrollDeltaPixels(e); if (scrollDelta.y) { const metricsManager = this.workspace_.getMetricsManager(); @@ -211,8 +212,8 @@ VerticalFlyout.prototype.wheel_ = function(e) { this.workspace_.scrollbar.setY(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); } // Don't scroll the page. @@ -266,7 +267,7 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package @@ -290,7 +291,7 @@ VerticalFlyout.prototype.isDragTowardWorkspace = 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. */ VerticalFlyout.prototype.getClientRect = function() { @@ -307,11 +308,11 @@ VerticalFlyout.prototype.getClientRect = function() { const BIG_NUM = 1000000000; const left = flyoutRect.left; - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { const width = flyoutRect.width; - return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); + return new Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); } else { // Right - return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); + return new Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); } }; @@ -336,7 +337,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } flyoutWidth += this.MARGIN * 1.5 + this.tabWidth_; flyoutWidth *= this.workspace_.scale; - flyoutWidth += Blockly.Scrollbar.scrollbarThickness; + flyoutWidth += Scrollbar.scrollbarThickness; if (this.width_ != flyoutWidth) { for (let i = 0, block; (block = blocks[i]); i++) { @@ -364,7 +365,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_ && - this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT && + this.toolboxPosition_ == Position.LEFT && !this.targetWorkspace.getToolbox()) { // This flyout is a simple toolbox. Reposition the workspace so that (0,0) // is in the correct position relative to the new absolute edge (ie @@ -380,7 +381,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } }; -Blockly.registry.register(Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - Blockly.registry.DEFAULT, VerticalFlyout); +registry.register(registry.Type.FLYOUTS_VERTICAL_TOOLBOX, + registry.DEFAULT, VerticalFlyout); exports = VerticalFlyout; From def3458a10729c15b43bd1bac35e78cd931d9951 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:32:59 -0700 Subject: [PATCH 245/313] clang-format core/flyout_vertical.js --- core/flyout_vertical.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 8c1177c30..2091d1321 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -69,9 +69,10 @@ VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (typeof xyRatio.y == 'number') { this.workspace_.scrollY = -(scrollMetrics.top + - (scrollMetrics.height - viewMetrics.height) * xyRatio.y); + (scrollMetrics.height - viewMetrics.height) * xyRatio.y); } - this.workspace_.translate(this.workspace_.scrollX + absoluteMetrics.left, + this.workspace_.translate( + this.workspace_.scrollX + absoluteMetrics.left, this.workspace_.scrollY + absoluteMetrics.top); }; @@ -172,17 +173,15 @@ VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { // Top. path.push('h', atRight ? -width : width); // Rounded corner. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, - atRight ? 0 : 1, - atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, - this.CORNER_RADIUS); + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, + atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, this.CORNER_RADIUS); // Side closest to workspace. path.push('v', Math.max(0, height)); // Rounded corner. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, - atRight ? 0 : 1, - atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, - this.CORNER_RADIUS); + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, + atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, this.CORNER_RADIUS); // Bottom. path.push('h', atRight ? width : -width); path.push('z'); @@ -250,8 +249,8 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { const moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; block.moveBy(moveX, cursorY); - const rect = this.createRect_(block, - this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); + const rect = this.createRect_( + block, this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); this.addBlockListeners_(root, block, rect); @@ -272,8 +271,7 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -VerticalFlyout.prototype.isDragTowardWorkspace = function( - currentDragDeltaXY) { +VerticalFlyout.prototype.isDragTowardWorkspace = function(currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. @@ -371,7 +369,8 @@ VerticalFlyout.prototype.reflowInternal_ = function() { // is in the correct position relative to the new absolute edge (ie // toolbox edge). this.targetWorkspace.translate( - this.targetWorkspace.scrollX + flyoutWidth, this.targetWorkspace.scrollY); + this.targetWorkspace.scrollX + flyoutWidth, + this.targetWorkspace.scrollY); } // Record the width for workspace metrics and .position. @@ -381,7 +380,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } }; -registry.register(registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - registry.DEFAULT, VerticalFlyout); +registry.register( + registry.Type.FLYOUTS_VERTICAL_TOOLBOX, registry.DEFAULT, VerticalFlyout); exports = VerticalFlyout; From 90ed883eb0d06fceecbb6a17aa5bd018105adad6 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:38:39 -0700 Subject: [PATCH 246/313] Migrate core/generator.js to ES6 const/let --- core/generator.js | 48 +++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/core/generator.js b/core/generator.js index e365c69ba..a9a2d5418 100644 --- a/core/generator.js +++ b/core/generator.js @@ -96,11 +96,11 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) { console.warn('No workspace specified in workspaceToCode call. Guessing.'); workspace = Blockly.getMainWorkspace(); } - var code = []; + let code = []; this.init(workspace); - var blocks = workspace.getTopBlocks(true); - for (var i = 0, block; (block = blocks[i]); i++) { - var line = this.blockToCode(block); + const blocks = workspace.getTopBlocks(true); + for (let i = 0, block; (block = blocks[i]); i++) { + let line = this.blockToCode(block); if (Array.isArray(line)) { // Value blocks return tuples of code and operator order. // Top-level blocks don't care about operator order. @@ -150,10 +150,10 @@ Blockly.Generator.prototype.prefixLines = function(text, prefix) { * @return {string} Concatenated list of comments. */ Blockly.Generator.prototype.allNestedComments = function(block) { - var comments = []; - var blocks = block.getDescendants(true); - for (var i = 0; i < blocks.length; i++) { - var comment = blocks[i].getCommentText(); + const comments = []; + const blocks = block.getDescendants(true); + for (let i = 0; i < blocks.length; i++) { + const comment = blocks[i].getCommentText(); if (comment) { comments.push(comment); } @@ -191,7 +191,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { return opt_thisOnly ? '' : this.blockToCode(block.getChildren(false)[0]); } - var func = this[block.type]; + const func = this[block.type]; if (typeof func != 'function') { throw Error('Language "' + this.name_ + '" does not know how to generate ' + 'code for block type "' + block.type + '".'); @@ -200,7 +200,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { // Prior to 24 September 2013 'this' was the only way to access the block. // The current preferred method of accessing the block is through the second // argument to func.call, which becomes the first parameter to the generator. - var code = func.call(block, block); + let code = func.call(block, block); if (Array.isArray(code)) { // Value blocks return tuples of code and operator order. if (!block.outputConnection) { @@ -235,11 +235,11 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { if (isNaN(outerOrder)) { throw TypeError('Expecting valid order from block: ' + block.type); } - var targetBlock = block.getInputTargetBlock(name); + const targetBlock = block.getInputTargetBlock(name); if (!targetBlock) { return ''; } - var tuple = this.blockToCode(targetBlock); + const tuple = this.blockToCode(targetBlock); if (tuple === '') { // Disabled block. return ''; @@ -249,8 +249,8 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { if (!Array.isArray(tuple)) { throw TypeError('Expecting tuple from value block: ' + targetBlock.type); } - var code = tuple[0]; - var innerOrder = tuple[1]; + let code = tuple[0]; + const innerOrder = tuple[1]; if (isNaN(innerOrder)) { throw TypeError('Expecting valid order from value block: ' + targetBlock.type); @@ -260,9 +260,9 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { } // Add parentheses if needed. - var parensNeeded = false; - var outerOrderClass = Math.floor(outerOrder); - var innerOrderClass = Math.floor(innerOrder); + let parensNeeded = false; + const outerOrderClass = Math.floor(outerOrder); + const innerOrderClass = Math.floor(innerOrder); if (outerOrderClass <= innerOrderClass) { if (outerOrderClass == innerOrderClass && (outerOrderClass == 0 || outerOrderClass == 99)) { @@ -276,7 +276,7 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { // wrap the code in parentheses. parensNeeded = true; // Check for special exceptions. - for (var i = 0; i < this.ORDER_OVERRIDES.length; i++) { + for (let i = 0; i < this.ORDER_OVERRIDES.length; i++) { if (this.ORDER_OVERRIDES[i][0] == outerOrder && this.ORDER_OVERRIDES[i][1] == innerOrder) { parensNeeded = false; @@ -303,8 +303,8 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { * @return {string} Generated code or '' if no blocks are connected. */ Blockly.Generator.prototype.statementToCode = function(block, name) { - var targetBlock = block.getInputTargetBlock(name); - var code = this.blockToCode(targetBlock); + const targetBlock = block.getInputTargetBlock(name); + let code = this.blockToCode(targetBlock); // Value blocks must return code and order of operations info. // Statement blocks must only return code. if (typeof code != 'string') { @@ -350,7 +350,7 @@ Blockly.Generator.prototype.addLoopTrap = function(branch, block) { * @return {string} Code snippet with ID. */ Blockly.Generator.prototype.injectId = function(msg, block) { - var id = block.id.replace(/\$/g, '$$$$'); // Issue 251. + const id = block.id.replace(/\$/g, '$$$$'); // Issue 251. return msg.replace(/%1/g, '\'' + id + '\''); }; @@ -450,16 +450,16 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { */ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { - var functionName = this.nameDB_.getDistinctName( + const functionName = this.nameDB_.getDistinctName( desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; - var codeText = code.join('\n').replace( + let codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); // Change all ' ' indents into the desired indent. // To avoid an infinite loop of replacements, change all indents to '\0' // character first, then replace them all with the indent. // We are assuming that no provided functions contain a literal null char. - var oldCodeText; + let oldCodeText; while (oldCodeText != codeText) { oldCodeText = codeText; codeText = codeText.replace(/^(( {2})*) {2}/gm, '$1\0'); diff --git a/tests/deps.js b/tests/deps.js index f62333982..87a32ab95 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 4741d4c312586221a1c776510b8354fde6f1102f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:41:57 -0700 Subject: [PATCH 247/313] Migrate core/generator.js to goog.module --- core/generator.js | 69 ++++++++++++++++++++++++----------------------- tests/deps.js | 2 +- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/core/generator.js b/core/generator.js index a9a2d5418..609e9d56c 100644 --- a/core/generator.js +++ b/core/generator.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Generator'); +goog.module('Blockly.Generator'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Block'); goog.require('Blockly.internalConstants'); @@ -26,7 +27,7 @@ goog.requireType('Blockly.Workspace'); * @param {string} name Language name of this generator. * @constructor */ -Blockly.Generator = function(name) { +const Generator = function(name) { this.name_ = name; this.FUNCTION_NAME_PLACEHOLDER_REGEXP_ = new RegExp(this.FUNCTION_NAME_PLACEHOLDER_, 'g'); @@ -38,7 +39,7 @@ Blockly.Generator = function(name) { * E.g. ' checkTimeout(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.INFINITE_LOOP_TRAP = null; +Generator.prototype.INFINITE_LOOP_TRAP = null; /** * Arbitrary code to inject before every statement. @@ -46,7 +47,7 @@ Blockly.Generator.prototype.INFINITE_LOOP_TRAP = null; * E.g. 'highlight(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.STATEMENT_PREFIX = null; +Generator.prototype.STATEMENT_PREFIX = null; /** * Arbitrary code to inject after every statement. @@ -54,27 +55,27 @@ Blockly.Generator.prototype.STATEMENT_PREFIX = null; * E.g. 'highlight(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.STATEMENT_SUFFIX = null; +Generator.prototype.STATEMENT_SUFFIX = null; /** * The method of indenting. Defaults to two spaces, but language generators * may override this to increase indent or change to tabs. * @type {string} */ -Blockly.Generator.prototype.INDENT = ' '; +Generator.prototype.INDENT = ' '; /** * Maximum length for a comment before wrapping. Does not account for * indenting level. * @type {number} */ -Blockly.Generator.prototype.COMMENT_WRAP = 60; +Generator.prototype.COMMENT_WRAP = 60; /** * List of outer-inner pairings that do NOT require parentheses. * @type {!Array>} */ -Blockly.Generator.prototype.ORDER_OVERRIDES = []; +Generator.prototype.ORDER_OVERRIDES = []; /** * Whether the init method has been called. @@ -83,14 +84,14 @@ Blockly.Generator.prototype.ORDER_OVERRIDES = []; * initialized. If this flag is untouched, it will have no effect. * @type {?boolean} */ -Blockly.Generator.prototype.isInitialized = null; +Generator.prototype.isInitialized = null; /** * Generate code for all blocks in the workspace to the specified language. * @param {!Blockly.Workspace=} workspace Workspace to generate code from. * @return {string} Generated code. */ -Blockly.Generator.prototype.workspaceToCode = function(workspace) { +Generator.prototype.workspaceToCode = function(workspace) { if (!workspace) { // Backwards compatibility from before there could be multiple workspaces. console.warn('No workspace specified in workspaceToCode call. Guessing.'); @@ -140,7 +141,7 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) { * @param {string} prefix The common prefix. * @return {string} The prefixed lines of code. */ -Blockly.Generator.prototype.prefixLines = function(text, prefix) { +Generator.prototype.prefixLines = function(text, prefix) { return prefix + text.replace(/(?!\n$)\n/g, '\n' + prefix); }; @@ -149,7 +150,7 @@ Blockly.Generator.prototype.prefixLines = function(text, prefix) { * @param {!Blockly.Block} block The block from which to start spidering. * @return {string} Concatenated list of comments. */ -Blockly.Generator.prototype.allNestedComments = function(block) { +Generator.prototype.allNestedComments = function(block) { const comments = []; const blocks = block.getDescendants(true); for (let i = 0; i < blocks.length; i++) { @@ -174,7 +175,7 @@ Blockly.Generator.prototype.allNestedComments = function(block) { * For value blocks, an array containing the generated code and an * operator order value. Returns '' if block is null. */ -Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { +Generator.prototype.blockToCode = function(block, opt_thisOnly) { if (this.isInitialized === false) { console.warn( 'Generator init was not called before blockToCode was called.'); @@ -231,7 +232,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { * @return {string} Generated code or '' if no blocks are connected or the * specified input does not exist. */ -Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { +Generator.prototype.valueToCode = function(block, name, outerOrder) { if (isNaN(outerOrder)) { throw TypeError('Expecting valid order from block: ' + block.type); } @@ -302,7 +303,7 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { * @param {string} name The name of the input. * @return {string} Generated code or '' if no blocks are connected. */ -Blockly.Generator.prototype.statementToCode = function(block, name) { +Generator.prototype.statementToCode = function(block, name) { const targetBlock = block.getInputTargetBlock(name); let code = this.blockToCode(targetBlock); // Value blocks must return code and order of operations info. @@ -326,7 +327,7 @@ Blockly.Generator.prototype.statementToCode = function(block, name) { * @param {!Blockly.Block} block Enclosing block. * @return {string} Loop contents, with infinite loop trap added. */ -Blockly.Generator.prototype.addLoopTrap = function(branch, block) { +Generator.prototype.addLoopTrap = function(branch, block) { if (this.INFINITE_LOOP_TRAP) { branch = this.prefixLines(this.injectId(this.INFINITE_LOOP_TRAP, block), this.INDENT) + branch; @@ -349,7 +350,7 @@ Blockly.Generator.prototype.addLoopTrap = function(branch, block) { * @param {!Blockly.Block} block Block which has an ID. * @return {string} Code snippet with ID. */ -Blockly.Generator.prototype.injectId = function(msg, block) { +Generator.prototype.injectId = function(msg, block) { const id = block.id.replace(/\$/g, '$$$$'); // Issue 251. return msg.replace(/%1/g, '\'' + id + '\''); }; @@ -359,33 +360,33 @@ Blockly.Generator.prototype.injectId = function(msg, block) { * @type {string} * @protected */ -Blockly.Generator.prototype.RESERVED_WORDS_ = ''; +Generator.prototype.RESERVED_WORDS_ = ''; /** * Add one or more words to the list of reserved words for this language. * @param {string} words Comma-separated list of words to add to the list. * No spaces. Duplicates are ok. */ -Blockly.Generator.prototype.addReservedWords = function(words) { +Generator.prototype.addReservedWords = function(words) { this.RESERVED_WORDS_ += words + ','; }; /** * This is used as a placeholder in functions defined using - * Blockly.Generator.provideFunction_. It must not be legal code that could + * Generator.provideFunction_. It must not be legal code that could * legitimately appear in a function definition (or comment), and it must * not confuse the regular expression parser. * @type {string} * @protected */ -Blockly.Generator.prototype.FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}'; +Generator.prototype.FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}'; /** * A dictionary of definitions to be printed before the code. * @type {!Object|undefined} * @protected */ -Blockly.Generator.prototype.definitions_; +Generator.prototype.definitions_; /** * A dictionary mapping desired function names in definitions_ to actual @@ -393,20 +394,20 @@ Blockly.Generator.prototype.definitions_; * @type {!Object|undefined} * @protected */ -Blockly.Generator.prototype.functionNames_; +Generator.prototype.functionNames_; /** * A database of variable and procedure names. * @type {!Blockly.Names|undefined} * @protected */ -Blockly.Generator.prototype.nameDB_; +Generator.prototype.nameDB_; -Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { +Object.defineProperty(Generator.prototype, 'variableDB_', { /** * Getter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). - * @this {Blockly.Generator} + * @this {Generator} * @return {!Blockly.Names|undefined} Name database. */ get: function() { @@ -417,7 +418,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { /** * Setter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). - * @this {Blockly.Generator} + * @this {Generator} * @param {!Blockly.Names|undefined} nameDb New name database. */ set: function(nameDb) { @@ -439,7 +440,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { * "listRandom", not "random"). There is no danger of colliding with reserved * words, or user-defined variable or procedure names. * - * The code gets output when Blockly.Generator.finish() is called. + * The code gets output when Generator.finish() is called. * * @param {string} desiredName The desired name of the function * (e.g. mathIsPrime). @@ -448,7 +449,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { * from desiredName if the former has already been taken by the user. * @protected */ -Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { +Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { const functionName = this.nameDB_.getDistinctName( desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); @@ -476,7 +477,7 @@ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { * names. * @param {!Blockly.Workspace} _workspace Workspace to generate code from. */ -Blockly.Generator.prototype.init = function(_workspace) { +Generator.prototype.init = function(_workspace) { // Optionally override // Create a dictionary of definitions to be printed before the code. this.definitions_ = Object.create(null); @@ -499,7 +500,7 @@ Blockly.Generator.prototype.init = function(_workspace) { * @return {string} Code with comments and subsequent blocks added. * @protected */ -Blockly.Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { +Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { // Optionally override return code; }; @@ -511,7 +512,7 @@ Blockly.Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { * @param {string} code Generated code. * @return {string} Completed code. */ -Blockly.Generator.prototype.finish = function(code) { +Generator.prototype.finish = function(code) { // Optionally override // Clean up temporary data. delete this.definitions_; @@ -527,7 +528,9 @@ Blockly.Generator.prototype.finish = function(code) { * @param {string} line Line of generated code. * @return {string} Legal line of code. */ -Blockly.Generator.prototype.scrubNakedValue = function(line) { +Generator.prototype.scrubNakedValue = function(line) { // Optionally override return line; }; + +exports = Generator; diff --git a/tests/deps.js b/tests/deps.js index 87a32ab95..db93b7671 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 1a1bad0bd718255cf53ce9de1787e123356da225 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:45:25 -0700 Subject: [PATCH 248/313] Migrate core/generator.js to named requires --- core/generator.js | 47 +++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/generator.js b/core/generator.js index 609e9d56c..7882a0402 100644 --- a/core/generator.js +++ b/core/generator.js @@ -14,12 +14,15 @@ goog.module('Blockly.Generator'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Block'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils.deprecation'); - -goog.requireType('Blockly.Names'); -goog.requireType('Blockly.Workspace'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Names = goog.requireType('Blockly.Names'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const internalConstants = goog.require('Blockly.internalConstants'); +const deprecation = goog.require('Blockly.utils.deprecation'); +const {getMainWorkspace} = goog.require('Blockly'); /** @@ -88,14 +91,14 @@ Generator.prototype.isInitialized = null; /** * Generate code for all blocks in the workspace to the specified language. - * @param {!Blockly.Workspace=} workspace Workspace to generate code from. + * @param {!Workspace=} workspace Workspace to generate code from. * @return {string} Generated code. */ Generator.prototype.workspaceToCode = function(workspace) { if (!workspace) { // Backwards compatibility from before there could be multiple workspaces. console.warn('No workspace specified in workspaceToCode call. Guessing.'); - workspace = Blockly.getMainWorkspace(); + workspace = getMainWorkspace(); } let code = []; this.init(workspace); @@ -147,7 +150,7 @@ Generator.prototype.prefixLines = function(text, prefix) { /** * Recursively spider a tree of blocks, returning all their comments. - * @param {!Blockly.Block} block The block from which to start spidering. + * @param {!Block} block The block from which to start spidering. * @return {string} Concatenated list of comments. */ Generator.prototype.allNestedComments = function(block) { @@ -169,7 +172,7 @@ Generator.prototype.allNestedComments = function(block) { /** * Generate code for the specified block (and attached blocks). * The generator must be initialized before calling this function. - * @param {Blockly.Block} block The block to generate code for. + * @param {Block} block The block to generate code for. * @param {boolean=} opt_thisOnly True to generate code for only this statement. * @return {string|!Array} For statement blocks, the generated code. * For value blocks, an array containing the generated code and an @@ -225,7 +228,7 @@ Generator.prototype.blockToCode = function(block, opt_thisOnly) { /** * Generate code representing the specified value input. - * @param {!Blockly.Block} block The block containing the input. + * @param {!Block} block The block containing the input. * @param {string} name The name of the input. * @param {number} outerOrder The maximum binding strength (minimum order value) * of any operators adjacent to "block". @@ -299,7 +302,7 @@ Generator.prototype.valueToCode = function(block, name, outerOrder) { * statement input. Indent the code. * This is mainly used in generators. When trying to generate code to evaluate * look at using workspaceToCode or blockToCode. - * @param {!Blockly.Block} block The block containing the input. + * @param {!Block} block The block containing the input. * @param {string} name The name of the input. * @return {string} Generated code or '' if no blocks are connected. */ @@ -324,7 +327,7 @@ Generator.prototype.statementToCode = function(block, name) { * statement executes), and a statement prefix to the end of the loop block * (right before the loop statement executes). * @param {string} branch Code for loop contents. - * @param {!Blockly.Block} block Enclosing block. + * @param {!Block} block Enclosing block. * @return {string} Loop contents, with infinite loop trap added. */ Generator.prototype.addLoopTrap = function(branch, block) { @@ -347,7 +350,7 @@ Generator.prototype.addLoopTrap = function(branch, block) { * Inject a block ID into a message to replace '%1'. * Used for STATEMENT_PREFIX, STATEMENT_SUFFIX, and INFINITE_LOOP_TRAP. * @param {string} msg Code snippet with '%1'. - * @param {!Blockly.Block} block Block which has an ID. + * @param {!Block} block Block which has an ID. * @return {string} Code snippet with ID. */ Generator.prototype.injectId = function(msg, block) { @@ -398,7 +401,7 @@ Generator.prototype.functionNames_; /** * A database of variable and procedure names. - * @type {!Blockly.Names|undefined} + * @type {!Names|undefined} * @protected */ Generator.prototype.nameDB_; @@ -408,10 +411,10 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * Getter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). * @this {Generator} - * @return {!Blockly.Names|undefined} Name database. + * @return {!Names|undefined} Name database. */ get: function() { - Blockly.utils.deprecation.warn( + deprecation.warn( 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); return this.nameDB_; }, @@ -419,10 +422,10 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * Setter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). * @this {Generator} - * @param {!Blockly.Names|undefined} nameDb New name database. + * @param {!Names|undefined} nameDb New name database. */ set: function(nameDb) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); this.nameDB_ = nameDb; } @@ -452,7 +455,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { const functionName = this.nameDB_.getDistinctName( - desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); + desiredName, internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; let codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); @@ -475,7 +478,7 @@ Generator.prototype.provideFunction_ = function(desiredName, code) { * Hook for code to run before code generation starts. * Subclasses may override this, e.g. to initialise the database of variable * names. - * @param {!Blockly.Workspace} _workspace Workspace to generate code from. + * @param {!Workspace} _workspace Workspace to generate code from. */ Generator.prototype.init = function(_workspace) { // Optionally override @@ -493,7 +496,7 @@ Generator.prototype.init = function(_workspace) { * Subclasses may override this, e.g. to generate code for statements following * the block, or to handle comments for the specified block and any connected * value blocks. - * @param {!Blockly.Block} _block The current block. + * @param {!Block} _block The current block. * @param {string} code The code created for this block. * @param {boolean=} _opt_thisOnly True to generate code for only this * statement. diff --git a/tests/deps.js b/tests/deps.js index db93b7671..c40db7cbc 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From da77f3e5b42985828486f19fefcaeacca0c0eedd Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:46:01 -0700 Subject: [PATCH 249/313] clang-format core/generator.js --- core/generator.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/core/generator.js b/core/generator.js index 7882a0402..8e71fb040 100644 --- a/core/generator.js +++ b/core/generator.js @@ -197,7 +197,8 @@ Generator.prototype.blockToCode = function(block, opt_thisOnly) { const func = this[block.type]; if (typeof func != 'function') { - throw Error('Language "' + this.name_ + '" does not know how to generate ' + + throw Error( + 'Language "' + this.name_ + '" does not know how to generate ' + 'code for block type "' + block.type + '".'); } // First argument to func.call is the value of 'this' in the generator. @@ -256,8 +257,8 @@ Generator.prototype.valueToCode = function(block, name, outerOrder) { let code = tuple[0]; const innerOrder = tuple[1]; if (isNaN(innerOrder)) { - throw TypeError('Expecting valid order from value block: ' + - targetBlock.type); + throw TypeError( + 'Expecting valid order from value block: ' + targetBlock.type); } if (!code) { return ''; @@ -312,7 +313,8 @@ Generator.prototype.statementToCode = function(block, name) { // Value blocks must return code and order of operations info. // Statement blocks must only return code. if (typeof code != 'string') { - throw TypeError('Expecting code from statement block: ' + + throw TypeError( + 'Expecting code from statement block: ' + (targetBlock && targetBlock.type)); } if (code) { @@ -332,16 +334,19 @@ Generator.prototype.statementToCode = function(block, name) { */ Generator.prototype.addLoopTrap = function(branch, block) { if (this.INFINITE_LOOP_TRAP) { - branch = this.prefixLines(this.injectId(this.INFINITE_LOOP_TRAP, block), - this.INDENT) + branch; + branch = this.prefixLines( + this.injectId(this.INFINITE_LOOP_TRAP, block), this.INDENT) + + branch; } if (this.STATEMENT_SUFFIX && !block.suppressPrefixSuffix) { - branch = this.prefixLines(this.injectId(this.STATEMENT_SUFFIX, block), - this.INDENT) + branch; + branch = this.prefixLines( + this.injectId(this.STATEMENT_SUFFIX, block), this.INDENT) + + branch; } if (this.STATEMENT_PREFIX && !block.suppressPrefixSuffix) { - branch = branch + this.prefixLines(this.injectId(this.STATEMENT_PREFIX, - block), this.INDENT); + branch = branch + + this.prefixLines( + this.injectId(this.STATEMENT_PREFIX, block), this.INDENT); } return branch; }; @@ -414,8 +419,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * @return {!Names|undefined} Name database. */ get: function() { - deprecation.warn( - 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); + deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); return this.nameDB_; }, /** @@ -425,8 +429,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * @param {!Names|undefined} nameDb New name database. */ set: function(nameDb) { - deprecation.warn( - 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); + deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); this.nameDB_ = nameDb; } }); From 1941e857e3564b6aa9ad323b607d66559ef1fe5b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:51:58 -0700 Subject: [PATCH 250/313] Migrate core/grid.js to ES6 const/let --- core/grid.js | 10 +++++----- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/grid.js b/core/grid.js index 56171ef50..b01d59dbd 100644 --- a/core/grid.js +++ b/core/grid.js @@ -125,14 +125,14 @@ Blockly.Grid.prototype.getPatternId = function() { Blockly.Grid.prototype.update = function(scale) { this.scale_ = scale; // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. - var safeSpacing = (this.spacing_ * scale) || 100; + const safeSpacing = (this.spacing_ * scale) || 100; this.gridPattern_.setAttribute('width', safeSpacing); this.gridPattern_.setAttribute('height', safeSpacing); - var half = Math.floor(this.spacing_ / 2) + 0.5; - var start = half - this.length_ / 2; - var end = half + this.length_ / 2; + let half = Math.floor(this.spacing_ / 2) + 0.5; + let start = half - this.length_ / 2; + let end = half + this.length_ / 2; half *= scale; start *= scale; @@ -197,7 +197,7 @@ Blockly.Grid.createDom = function(rnd, gridOptions, defs) { */ - var gridPattern = Blockly.utils.dom.createSvgElement( + const gridPattern = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATTERN, { 'id': 'blocklyGridPattern' + rnd, diff --git a/tests/deps.js b/tests/deps.js index f62333982..25dd37c2e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -67,7 +67,7 @@ goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); From 4c7ac8dd382cd2cc8d2dd46c4e9eabf7af86def4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:54:43 -0700 Subject: [PATCH 251/313] Migrate core/grid.js to goog.module --- core/grid.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/grid.js b/core/grid.js index b01d59dbd..48189fe69 100644 --- a/core/grid.js +++ b/core/grid.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Grid'); +goog.module('Blockly.Grid'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); @@ -27,7 +28,7 @@ goog.require('Blockly.utils.userAgent'); * https://developers.google.com/blockly/guides/configure/web/grid * @constructor */ -Blockly.Grid = function(pattern, options) { +const Grid = function(pattern, options) { /** * The grid's SVG pattern, created during injection. * @type {!SVGElement} @@ -78,14 +79,14 @@ Blockly.Grid = function(pattern, options) { * @type {number} * @private */ -Blockly.Grid.prototype.scale_ = 1; +Grid.prototype.scale_ = 1; /** * Dispose of this grid and unlink from the DOM. * @package * @suppress {checkTypes} */ -Blockly.Grid.prototype.dispose = function() { +Grid.prototype.dispose = function() { this.gridPattern_ = null; }; @@ -94,7 +95,7 @@ Blockly.Grid.prototype.dispose = function() { * @return {boolean} True if blocks should snap, false otherwise. * @package */ -Blockly.Grid.prototype.shouldSnap = function() { +Grid.prototype.shouldSnap = function() { return this.snapToGrid_; }; @@ -103,7 +104,7 @@ Blockly.Grid.prototype.shouldSnap = function() { * @return {number} The spacing of the grid points. * @package */ -Blockly.Grid.prototype.getSpacing = function() { +Grid.prototype.getSpacing = function() { return this.spacing_; }; @@ -113,7 +114,7 @@ Blockly.Grid.prototype.getSpacing = function() { * @return {string} The pattern ID. * @package */ -Blockly.Grid.prototype.getPatternId = function() { +Grid.prototype.getPatternId = function() { return this.gridPattern_.id; }; @@ -122,7 +123,7 @@ Blockly.Grid.prototype.getPatternId = function() { * @param {number} scale The new workspace scale. * @package */ -Blockly.Grid.prototype.update = function(scale) { +Grid.prototype.update = function(scale) { this.scale_ = scale; // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. const safeSpacing = (this.spacing_ * scale) || 100; @@ -153,7 +154,7 @@ Blockly.Grid.prototype.update = function(scale) { * @param {number} y2 The new y end position of the line (in px). * @private */ -Blockly.Grid.prototype.setLineAttributes_ = function(line, width, +Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) { if (line) { line.setAttribute('stroke-width', width); @@ -171,7 +172,7 @@ Blockly.Grid.prototype.setLineAttributes_ = function(line, width, * @param {number} y The new y position of the grid (in px). * @package */ -Blockly.Grid.prototype.moveTo = function(x, y) { +Grid.prototype.moveTo = function(x, y) { this.gridPattern_.setAttribute('x', x); this.gridPattern_.setAttribute('y', y); @@ -190,7 +191,7 @@ Blockly.Grid.prototype.moveTo = function(x, y) { * @return {!SVGElement} The SVG element for the grid pattern. * @package */ -Blockly.Grid.createDom = function(rnd, gridOptions, defs) { +Grid.createDom = function(rnd, gridOptions, defs) { /* @@ -220,3 +221,5 @@ Blockly.Grid.createDom = function(rnd, gridOptions, defs) { } return gridPattern; }; + +exports = Grid; diff --git a/tests/deps.js b/tests/deps.js index 25dd37c2e..f6a0972e2 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -67,7 +67,7 @@ goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6'}); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); From 25cb8773cd0627fe8c6066a5bf6c2198f2de5cac Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:59:42 -0700 Subject: [PATCH 252/313] Migrate core/grid.js to named requires --- core/grid.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/grid.js b/core/grid.js index 48189fe69..b93a39fa1 100644 --- a/core/grid.js +++ b/core/grid.js @@ -14,9 +14,9 @@ goog.module('Blockly.Grid'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); +const userAgent = goog.require('Blockly.utils.userAgent'); /** @@ -176,7 +176,7 @@ Grid.prototype.moveTo = function(x, y) { this.gridPattern_.setAttribute('x', x); this.gridPattern_.setAttribute('y', y); - if (Blockly.utils.userAgent.IE || Blockly.utils.userAgent.EDGE) { + if (userAgent.IE || userAgent.EDGE) { // IE/Edge doesn't notice that the x/y offsets have changed. // Force an update. this.update(this.scale_); @@ -198,26 +198,26 @@ Grid.createDom = function(rnd, gridOptions, defs) { */ - const gridPattern = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATTERN, + const gridPattern = dom.createSvgElement( + Svg.PATTERN, { 'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse' }, defs); if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, + dom.createSvgElement( + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, + dom.createSvgElement( + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } // x1, y1, x1, x2 properties will be set later in update. } else { // Edge 16 doesn't handle empty patterns - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, {}, gridPattern); + dom.createSvgElement( + Svg.LINE, {}, gridPattern); } return gridPattern; }; From d36abd2b338117eb4ca248346926bdc5f36e7c2f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:00:09 -0700 Subject: [PATCH 253/313] clang-format core/grid.js --- core/grid.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/core/grid.js b/core/grid.js index b93a39fa1..1a1d5f2a3 100644 --- a/core/grid.js +++ b/core/grid.js @@ -62,8 +62,8 @@ const Grid = function(pattern, options) { * @type {SVGElement} * @private */ - this.line2_ = this.line1_ && - (/** @type {SVGElement} */ (this.line1_.nextSibling)); + this.line2_ = + this.line1_ && (/** @type {SVGElement} */ (this.line1_.nextSibling)); /** * Whether blocks should snap to the grid. @@ -154,8 +154,7 @@ Grid.prototype.update = function(scale) { * @param {number} y2 The new y end position of the line (in px). * @private */ -Grid.prototype.setLineAttributes_ = function(line, width, - x1, x2, y1, y2) { +Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) { if (line) { line.setAttribute('stroke-width', width); line.setAttribute('x1', x1); @@ -200,24 +199,19 @@ Grid.createDom = function(rnd, gridOptions, defs) { */ const gridPattern = dom.createSvgElement( Svg.PATTERN, - { - 'id': 'blocklyGridPattern' + rnd, - 'patternUnits': 'userSpaceOnUse' - }, defs); + {'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse'}, + defs); if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { dom.createSvgElement( - Svg.LINE, - {'stroke': gridOptions['colour']}, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { dom.createSvgElement( - Svg.LINE, - {'stroke': gridOptions['colour']}, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } // x1, y1, x1, x2 properties will be set later in update. } else { // Edge 16 doesn't handle empty patterns - dom.createSvgElement( - Svg.LINE, {}, gridPattern); + dom.createSvgElement(Svg.LINE, {}, gridPattern); } return gridPattern; }; From 341b5156934f8239924049c51c918c80ec973258 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:15:58 -0700 Subject: [PATCH 254/313] Migrate core/icon.js to ES6 const/let --- core/icon.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/icon.js b/core/icon.js index c5f3477cd..ca1548aa3 100644 --- a/core/icon.js +++ b/core/icon.js @@ -164,10 +164,10 @@ Blockly.Icon.prototype.setIconLocation = function(xy) { */ Blockly.Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. - var blockXY = this.block_.getRelativeToSurfaceXY(); - var iconXY = Blockly.utils.getRelativeXY( + const blockXY = this.block_.getRelativeToSurfaceXY(); + const iconXY = Blockly.utils.getRelativeXY( /** @type {!SVGElement} */ (this.iconGroup_)); - var newXY = new Blockly.utils.Coordinate( + const newXY = new Blockly.utils.Coordinate( blockXY.x + iconXY.x + this.SIZE / 2, blockXY.y + iconXY.y + this.SIZE / 2); if (!Blockly.utils.Coordinate.equals(this.getIconLocation(), newXY)) { From 8f72d004741ef12eca40fd96ebd4ff85395efa41 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:17:59 -0700 Subject: [PATCH 255/313] Migrate core/icon.js to goog.module --- core/icon.js | 41 ++++++++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/core/icon.js b/core/icon.js index ca1548aa3..02e6f7348 100644 --- a/core/icon.js +++ b/core/icon.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Icon'); +goog.module('Blockly.Icon'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.utils'); @@ -29,7 +30,7 @@ goog.requireType('Blockly.Bubble'); * @constructor * @abstract */ -Blockly.Icon = function(block) { +const Icon = function(block) { /** * The block this icon is attached to. * @type {Blockly.BlockSvg} @@ -47,31 +48,31 @@ Blockly.Icon = function(block) { /** * Does this icon get hidden when the block is collapsed. */ -Blockly.Icon.prototype.collapseHidden = true; +Icon.prototype.collapseHidden = true; /** * Height and width of icons. */ -Blockly.Icon.prototype.SIZE = 17; +Icon.prototype.SIZE = 17; /** * Bubble UI (if visible). * @type {?Blockly.Bubble} * @protected */ -Blockly.Icon.prototype.bubble_ = null; +Icon.prototype.bubble_ = null; /** * Absolute coordinate of icon's center. * @type {?Blockly.utils.Coordinate} * @protected */ -Blockly.Icon.prototype.iconXY_ = null; +Icon.prototype.iconXY_ = null; /** * Create the icon on the block. */ -Blockly.Icon.prototype.createIcon = function() { +Icon.prototype.createIcon = function() { if (this.iconGroup_) { // Icon already exists. return; @@ -99,7 +100,7 @@ Blockly.Icon.prototype.createIcon = function() { /** * Dispose of this icon. */ -Blockly.Icon.prototype.dispose = function() { +Icon.prototype.dispose = function() { // Dispose of and unlink the icon. Blockly.utils.dom.removeNode(this.iconGroup_); this.iconGroup_ = null; @@ -111,7 +112,7 @@ Blockly.Icon.prototype.dispose = function() { /** * Add or remove the UI indicating if this icon may be clicked or not. */ -Blockly.Icon.prototype.updateEditable = function() { +Icon.prototype.updateEditable = function() { // No-op on the base class. }; @@ -119,7 +120,7 @@ Blockly.Icon.prototype.updateEditable = function() { * Is the associated bubble visible? * @return {boolean} True if the bubble is visible. */ -Blockly.Icon.prototype.isVisible = function() { +Icon.prototype.isVisible = function() { return !!this.bubble_; }; @@ -128,7 +129,7 @@ Blockly.Icon.prototype.isVisible = function() { * @param {!Event} e Mouse click event. * @protected */ -Blockly.Icon.prototype.iconClick_ = function(e) { +Icon.prototype.iconClick_ = function(e) { if (this.block_.workspace.isDragging()) { // Drag operation is concluding. Don't open the editor. return; @@ -141,7 +142,7 @@ Blockly.Icon.prototype.iconClick_ = function(e) { /** * Change the colour of the associated bubble to match its block. */ -Blockly.Icon.prototype.applyColour = function() { +Icon.prototype.applyColour = function() { if (this.isVisible()) { this.bubble_.setColour(this.block_.style.colourPrimary); } @@ -151,7 +152,7 @@ Blockly.Icon.prototype.applyColour = function() { * Notification that the icon has moved. Update the arrow accordingly. * @param {!Blockly.utils.Coordinate} xy Absolute location in workspace coordinates. */ -Blockly.Icon.prototype.setIconLocation = function(xy) { +Icon.prototype.setIconLocation = function(xy) { this.iconXY_ = xy; if (this.isVisible()) { this.bubble_.setAnchorLocation(xy); @@ -162,7 +163,7 @@ Blockly.Icon.prototype.setIconLocation = function(xy) { * Notification that the icon has moved, but we don't really know where. * Recompute the icon's location from scratch. */ -Blockly.Icon.prototype.computeIconLocation = function() { +Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. const blockXY = this.block_.getRelativeToSurfaceXY(); const iconXY = Blockly.utils.getRelativeXY( @@ -180,7 +181,7 @@ Blockly.Icon.prototype.computeIconLocation = function() { * @return {?Blockly.utils.Coordinate} Object with x and y properties in * workspace coordinates. */ -Blockly.Icon.prototype.getIconLocation = function() { +Icon.prototype.getIconLocation = function() { return this.iconXY_; }; @@ -191,9 +192,9 @@ Blockly.Icon.prototype.getIconLocation = function() { * @return {!Blockly.utils.Size} Height and width. */ // TODO (#2562): Remove getCorrectedSize. -Blockly.Icon.prototype.getCorrectedSize = function() { +Icon.prototype.getCorrectedSize = function() { return new Blockly.utils.Size( - Blockly.Icon.prototype.SIZE, Blockly.Icon.prototype.SIZE - 2); + Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; /** @@ -201,10 +202,12 @@ Blockly.Icon.prototype.getCorrectedSize = function() { * @param {!Element} group The icon group. * @protected */ -Blockly.Icon.prototype.drawIcon_; +Icon.prototype.drawIcon_; /** * Show or hide the icon. * @param {boolean} visible True if the icon should be visible. */ -Blockly.Icon.prototype.setVisible; +Icon.prototype.setVisible; + +exports = Icon; diff --git a/tests/deps.js b/tests/deps.js index f62333982..57ab7a557 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -68,7 +68,7 @@ goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); From f0a3c7214dc086de2ad29dabc41fc35e8c975102 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 13:40:19 -0700 Subject: [PATCH 256/313] Migrate core/interfaces/i_metrics_manager.js to goog.module --- core/interfaces/i_metrics_manager.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index 916f14d5d..f9b74e4c2 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IMetricsManager'); +goog.module('Blockly.IMetricsManager'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.MetricsManager'); goog.requireType('Blockly.utils.Metrics'); @@ -22,14 +23,14 @@ goog.requireType('Blockly.utils.Size'); * Interface for a metrics manager. * @interface */ -Blockly.IMetricsManager = function() {}; +const IMetricsManager = function() {}; /** * Returns whether the scroll area has fixed edges. * @return {boolean} Whether the scroll area has fixed edges. * @package */ -Blockly.IMetricsManager.prototype.hasFixedEdges; +IMetricsManager.prototype.hasFixedEdges; /** * Returns the metrics for the scroll area of the workspace. @@ -44,7 +45,7 @@ Blockly.IMetricsManager.prototype.hasFixedEdges; * @return {!Blockly.MetricsManager.ContainerRegion} The metrics for the scroll * container */ -Blockly.IMetricsManager.prototype.getScrollMetrics; +IMetricsManager.prototype.getScrollMetrics; /** * Gets the width and the height of the flyout on the workspace in pixel @@ -55,7 +56,7 @@ Blockly.IMetricsManager.prototype.getScrollMetrics; * flyout. * @public */ -Blockly.IMetricsManager.prototype.getFlyoutMetrics; +IMetricsManager.prototype.getFlyoutMetrics; /** * Gets the width, height and position of the toolbox on the workspace in pixel @@ -66,7 +67,7 @@ Blockly.IMetricsManager.prototype.getFlyoutMetrics; * height and position of the toolbox. * @public */ -Blockly.IMetricsManager.prototype.getToolboxMetrics; +IMetricsManager.prototype.getToolboxMetrics; /** * Gets the width and height of the workspace's parent SVG element in pixel @@ -75,7 +76,7 @@ Blockly.IMetricsManager.prototype.getToolboxMetrics; * SVG element. * @public */ -Blockly.IMetricsManager.prototype.getSvgMetrics; +IMetricsManager.prototype.getSvgMetrics; /** * Gets the absolute left and absolute top in pixel coordinates. @@ -84,7 +85,7 @@ Blockly.IMetricsManager.prototype.getSvgMetrics; * the workspace. * @public */ -Blockly.IMetricsManager.prototype.getAbsoluteMetrics; +IMetricsManager.prototype.getAbsoluteMetrics; /** * Gets the metrics for the visible workspace in either pixel or workspace @@ -96,7 +97,7 @@ Blockly.IMetricsManager.prototype.getAbsoluteMetrics; * coordinates. * @public */ -Blockly.IMetricsManager.prototype.getViewMetrics; +IMetricsManager.prototype.getViewMetrics; /** * Gets content metrics in either pixel or workspace coordinates. @@ -108,7 +109,7 @@ Blockly.IMetricsManager.prototype.getViewMetrics; * metrics for the content container. * @public */ -Blockly.IMetricsManager.prototype.getContentMetrics; +IMetricsManager.prototype.getContentMetrics; /** * Returns an object with all the metrics required to size scrollbars for a @@ -142,4 +143,6 @@ Blockly.IMetricsManager.prototype.getContentMetrics; * level workspace. * @public */ -Blockly.IMetricsManager.prototype.getMetrics; +IMetricsManager.prototype.getMetrics; + +exports = IMetricsManager; diff --git a/tests/deps.js b/tests/deps.js index f62333982..5cadf3977 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -91,7 +91,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'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); 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_metrics_manager.js', ['Blockly.IMetricsManager'], [], {'lang': 'es6', 'module': 'goog'}); 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'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); From f3a0c6414f673f957afff3e921023821820a6f7d Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 13:40:51 -0700 Subject: [PATCH 257/313] Migrate core/interfaces/i_metrics_manager.js named requires --- core/interfaces/i_metrics_manager.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index f9b74e4c2..b8cbd2231 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -14,9 +14,9 @@ goog.module('Blockly.IMetricsManager'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.MetricsManager'); -goog.requireType('Blockly.utils.Metrics'); -goog.requireType('Blockly.utils.Size'); +const Metrics = goog.requireType('Blockly.utils.Metrics'); +const Size = goog.requireType('Blockly.utils.Size'); +const {AbsoluteMetrics, ContainerRegion, ToolboxMetrics} = goog.requireType('Blockly.MetricsManager'); /** @@ -36,13 +36,13 @@ IMetricsManager.prototype.hasFixedEdges; * Returns the metrics for the scroll area of the workspace. * @param {boolean=} opt_getWorkspaceCoordinates True to get the scroll metrics * in workspace coordinates, false to get them in pixel coordinates. - * @param {!Blockly.MetricsManager.ContainerRegion=} opt_viewMetrics The view + * @param {!ContainerRegion=} opt_viewMetrics The view * metrics if they have been previously computed. Passing in null may cause * the view metrics to be computed again, if it is needed. - * @param {!Blockly.MetricsManager.ContainerRegion=} opt_contentMetrics The + * @param {!ContainerRegion=} opt_contentMetrics The * content metrics if they have been previously computed. Passing in null * may cause the content metrics to be computed again, if it is needed. - * @return {!Blockly.MetricsManager.ContainerRegion} The metrics for the scroll + * @return {!ContainerRegion} The metrics for the scroll * container */ IMetricsManager.prototype.getScrollMetrics; @@ -52,7 +52,7 @@ IMetricsManager.prototype.getScrollMetrics; * coordinates. Returns 0 for the width and height if the workspace has a * category toolbox instead of a simple toolbox. * @param {boolean=} opt_own Whether to only return the workspace's own flyout. - * @return {!Blockly.MetricsManager.ToolboxMetrics} The width and height of the + * @return {!ToolboxMetrics} The width and height of the * flyout. * @public */ @@ -63,7 +63,7 @@ IMetricsManager.prototype.getFlyoutMetrics; * coordinates. Returns 0 for the width and height if the workspace has a simple * toolbox instead of a category toolbox. To get the width and height of a * simple toolbox @see {@link getFlyoutMetrics}. - * @return {!Blockly.MetricsManager.ToolboxMetrics} The object with the width, + * @return {!ToolboxMetrics} The object with the width, * height and position of the toolbox. * @public */ @@ -72,7 +72,7 @@ IMetricsManager.prototype.getToolboxMetrics; /** * Gets the width and height of the workspace's parent SVG element in pixel * coordinates. This area includes the toolbox and the visible workspace area. - * @return {!Blockly.utils.Size} The width and height of the workspace's parent + * @return {!Size} The width and height of the workspace's parent * SVG element. * @public */ @@ -81,7 +81,7 @@ IMetricsManager.prototype.getSvgMetrics; /** * Gets the absolute left and absolute top in pixel coordinates. * This is where the visible workspace starts in relation to the SVG container. - * @return {!Blockly.MetricsManager.AbsoluteMetrics} The absolute metrics for + * @return {!AbsoluteMetrics} The absolute metrics for * the workspace. * @public */ @@ -92,7 +92,7 @@ IMetricsManager.prototype.getAbsoluteMetrics; * coordinates. The visible workspace does not include the toolbox or flyout. * @param {boolean=} opt_getWorkspaceCoordinates True to get the view metrics in * workspace coordinates, false to get them in pixel coordinates. - * @return {!Blockly.MetricsManager.ContainerRegion} The width, height, top and + * @return {!ContainerRegion} The width, height, top and * left of the viewport in either workspace coordinates or pixel * coordinates. * @public @@ -105,7 +105,7 @@ IMetricsManager.prototype.getViewMetrics; * workspace (workspace comments and blocks). * @param {boolean=} opt_getWorkspaceCoordinates True to get the content metrics * in workspace coordinates, false to get them in pixel coordinates. - * @return {!Blockly.MetricsManager.ContainerRegion} The + * @return {!ContainerRegion} The * metrics for the content container. * @public */ @@ -139,7 +139,7 @@ IMetricsManager.prototype.getContentMetrics; * .flyoutHeight: Height of the flyout if it is always open. Otherwise zero. * .toolboxPosition: Top, bottom, left or right. Use TOOLBOX_AT constants to * compare. - * @return {!Blockly.utils.Metrics} Contains size and position metrics of a top + * @return {!Metrics} Contains size and position metrics of a top * level workspace. * @public */ From b72c07ad8decc7ec809a2e566bb9bfd524a38d4f Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 09:16:10 -0700 Subject: [PATCH 258/313] Add eslint disable for no-unused-vars to core/interfaces/i_metrics_manager.js --- core/interfaces/i_metrics_manager.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index b8cbd2231..db1f575c1 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -14,8 +14,11 @@ goog.module('Blockly.IMetricsManager'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Metrics = goog.requireType('Blockly.utils.Metrics'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); +/* eslint-disable-next-line no-unused-vars */ const {AbsoluteMetrics, ContainerRegion, ToolboxMetrics} = goog.requireType('Blockly.MetricsManager'); From 977d0f35bff7303573bb83e93e821edd4b839c8d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:21:00 -0700 Subject: [PATCH 259/313] Migrate core/icon.js to named requires --- core/icon.js | 53 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/core/icon.js b/core/icon.js index 02e6f7348..0eaf37f0b 100644 --- a/core/icon.js +++ b/core/icon.js @@ -13,27 +13,28 @@ goog.module('Blockly.Icon'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Bubble = goog.requireType('Blockly.Bubble'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const {getRelativeXY, isRightButton} = goog.require('Blockly.utils'); /** * Class for an icon. - * @param {Blockly.BlockSvg} block The block associated with this icon. + * @param {BlockSvg} block The block associated with this icon. * @constructor * @abstract */ const Icon = function(block) { /** * The block this icon is attached to. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @protected */ this.block_ = block; @@ -57,14 +58,14 @@ Icon.prototype.SIZE = 17; /** * Bubble UI (if visible). - * @type {?Blockly.Bubble} + * @type {?Bubble} * @protected */ Icon.prototype.bubble_ = null; /** * Absolute coordinate of icon's center. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @protected */ Icon.prototype.iconXY_ = null; @@ -82,17 +83,17 @@ Icon.prototype.createIcon = function() { ... */ - this.iconGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.iconGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyIconGroup'}, null); if (this.block_.isInFlyout) { - Blockly.utils.dom.addClass( + dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } this.drawIcon_(this.iconGroup_); this.block_.getSvgRoot().appendChild(this.iconGroup_); - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.iconGroup_, 'mouseup', this, this.iconClick_); this.updateEditable(); }; @@ -102,7 +103,7 @@ Icon.prototype.createIcon = function() { */ Icon.prototype.dispose = function() { // Dispose of and unlink the icon. - Blockly.utils.dom.removeNode(this.iconGroup_); + dom.removeNode(this.iconGroup_); this.iconGroup_ = null; // Dispose of and unlink the bubble. this.setVisible(false); @@ -134,7 +135,7 @@ Icon.prototype.iconClick_ = function(e) { // Drag operation is concluding. Don't open the editor. return; } - if (!this.block_.isInFlyout && !Blockly.utils.isRightButton(e)) { + if (!this.block_.isInFlyout && !isRightButton(e)) { this.setVisible(!this.isVisible()); } }; @@ -150,7 +151,7 @@ Icon.prototype.applyColour = function() { /** * Notification that the icon has moved. Update the arrow accordingly. - * @param {!Blockly.utils.Coordinate} xy Absolute location in workspace coordinates. + * @param {!Coordinate} xy Absolute location in workspace coordinates. */ Icon.prototype.setIconLocation = function(xy) { this.iconXY_ = xy; @@ -166,19 +167,19 @@ Icon.prototype.setIconLocation = function(xy) { Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. const blockXY = this.block_.getRelativeToSurfaceXY(); - const iconXY = Blockly.utils.getRelativeXY( + const iconXY = getRelativeXY( /** @type {!SVGElement} */ (this.iconGroup_)); - const newXY = new Blockly.utils.Coordinate( + const newXY = new Coordinate( blockXY.x + iconXY.x + this.SIZE / 2, blockXY.y + iconXY.y + this.SIZE / 2); - if (!Blockly.utils.Coordinate.equals(this.getIconLocation(), newXY)) { + if (!Coordinate.equals(this.getIconLocation(), newXY)) { this.setIconLocation(newXY); } }; /** * Returns the center of the block's icon relative to the surface. - * @return {?Blockly.utils.Coordinate} Object with x and y properties in + * @return {?Coordinate} Object with x and y properties in * workspace coordinates. */ Icon.prototype.getIconLocation = function() { @@ -189,11 +190,11 @@ Icon.prototype.getIconLocation = function() { * Get the size of the icon as used for rendering. * This differs from the actual size of the icon, because it bulges slightly * out of its row rather than increasing the height of its row. - * @return {!Blockly.utils.Size} Height and width. + * @return {!Size} Height and width. */ // TODO (#2562): Remove getCorrectedSize. Icon.prototype.getCorrectedSize = function() { - return new Blockly.utils.Size( + return new Size( Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; From 7175e9452bceadbf15e80e017bf00e5ffb61bb6b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:21:41 -0700 Subject: [PATCH 260/313] clang-format core/icon.js --- core/icon.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/icon.js b/core/icon.js index 0eaf37f0b..b6b8942a7 100644 --- a/core/icon.js +++ b/core/icon.js @@ -83,9 +83,8 @@ Icon.prototype.createIcon = function() { ... */ - this.iconGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyIconGroup'}, null); + this.iconGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyIconGroup'}, null); if (this.block_.isInFlyout) { dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); @@ -194,8 +193,7 @@ Icon.prototype.getIconLocation = function() { */ // TODO (#2562): Remove getCorrectedSize. Icon.prototype.getCorrectedSize = function() { - return new Size( - Icon.prototype.SIZE, Icon.prototype.SIZE - 2); + return new Size(Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; /** From 2aff67498b516c50479c51a5fbda79bd04aa0951 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:49:13 -0700 Subject: [PATCH 261/313] Migrate core/input.js to ES6 const/let --- core/input.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/input.js b/core/input.js index 443bfc83f..315570ed3 100644 --- a/core/input.js +++ b/core/input.js @@ -151,7 +151,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { * @throws {Error} if the field is not present and opt_quiet is false. */ Blockly.Input.prototype.removeField = function(name, opt_quiet) { - for (var i = 0, field; (field = this.fieldRow[i]); i++) { + for (let i = 0, field; (field = this.fieldRow[i]); i++) { if (field.name === name) { field.dispose(); this.fieldRow.splice(i, 1); @@ -189,13 +189,13 @@ Blockly.Input.prototype.setVisible = function(visible) { // Note: Currently there are only unit tests for block.setCollapsed() // because this function is package. If this function goes back to being a // public API tests (lots of tests) should be added. - var renderList = []; + let renderList = []; if (this.visible_ == visible) { return renderList; } this.visible_ = visible; - for (var y = 0, field; (field = this.fieldRow[y]); y++) { + for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.setVisible(visible); } if (this.connection) { @@ -207,7 +207,7 @@ Blockly.Input.prototype.setVisible = function(visible) { } else { this.connection.stopTrackingAll(); } - var child = this.connection.targetBlock(); + const child = this.connection.targetBlock(); if (child) { child.getSvgRoot().style.display = visible ? 'block' : 'none'; } @@ -220,7 +220,7 @@ Blockly.Input.prototype.setVisible = function(visible) { * @package */ Blockly.Input.prototype.markDirty = function() { - for (var y = 0, field; (field = this.fieldRow[y]); y++) { + for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.markDirty(); } }; @@ -285,7 +285,7 @@ Blockly.Input.prototype.init = function() { if (!this.sourceBlock_.workspace.rendered) { return; // Headless blocks don't need fields initialized. } - for (var i = 0; i < this.fieldRow.length; i++) { + for (let i = 0; i < this.fieldRow.length; i++) { this.fieldRow[i].init(); } }; @@ -295,7 +295,7 @@ Blockly.Input.prototype.init = function() { * @suppress {checkTypes} */ Blockly.Input.prototype.dispose = function() { - for (var i = 0, field; (field = this.fieldRow[i]); i++) { + for (let i = 0, field; (field = this.fieldRow[i]); i++) { field.dispose(); } if (this.connection) { From f96c14c0033b27e1a1eef0146fef5f6615283287 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:51:25 -0700 Subject: [PATCH 262/313] Migrate core/input.js to goog.module --- core/input.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/core/input.js b/core/input.js index 315570ed3..b9b277fde 100644 --- a/core/input.js +++ b/core/input.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Input'); +goog.module('Blockly.Input'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Connection'); goog.require('Blockly.fieldRegistry'); @@ -33,7 +34,7 @@ goog.requireType('Blockly.RenderedConnection'); * @param {Blockly.Connection} connection Optional connection for this input. * @constructor */ -Blockly.Input = function(type, name, block, connection) { +const Input = function(type, name, block, connection) { if (type != Blockly.inputTypes.DUMMY && !name) { throw Error('Value inputs and statement inputs must have non-empty name.'); } @@ -56,20 +57,20 @@ Blockly.Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Blockly.Input.prototype.align = Blockly.constants.ALIGN.LEFT; +Input.prototype.align = Blockly.constants.ALIGN.LEFT; /** * Is the input visible? * @type {boolean} * @private */ -Blockly.Input.prototype.visible_ = true; +Input.prototype.visible_ = true; /** * Get the source block for this input. * @return {?Blockly.Block} The source block, or null if there is none. */ -Blockly.Input.prototype.getSourceBlock = function() { +Input.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -79,9 +80,9 @@ Blockly.Input.prototype.getSourceBlock = function() { * @param {string|!Blockly.Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. - * @return {!Blockly.Input} The input being append to (to allow chaining). + * @return {!Input} The input being append to (to allow chaining). */ -Blockly.Input.prototype.appendField = function(field, opt_name) { +Input.prototype.appendField = function(field, opt_name) { this.insertFieldAt(this.fieldRow.length, field, opt_name); return this; }; @@ -95,7 +96,7 @@ Blockly.Input.prototype.appendField = function(field, opt_name) { * this field again. Should be unique to the host block. * @return {number} The index following the last inserted field. */ -Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { +Input.prototype.insertFieldAt = function(index, field, opt_name) { if (index < 0 || index > this.fieldRow.length) { throw Error('index ' + index + ' out of bounds.'); } @@ -150,7 +151,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { * and opt_quiet is true. * @throws {Error} if the field is not present and opt_quiet is false. */ -Blockly.Input.prototype.removeField = function(name, opt_quiet) { +Input.prototype.removeField = function(name, opt_quiet) { for (let i = 0, field; (field = this.fieldRow[i]); i++) { if (field.name === name) { field.dispose(); @@ -174,7 +175,7 @@ Blockly.Input.prototype.removeField = function(name, opt_quiet) { * Gets whether this input is visible or not. * @return {boolean} True if visible. */ -Blockly.Input.prototype.isVisible = function() { +Input.prototype.isVisible = function() { return this.visible_; }; @@ -185,7 +186,7 @@ Blockly.Input.prototype.isVisible = function() { * @return {!Array} List of blocks to render. * @package */ -Blockly.Input.prototype.setVisible = function(visible) { +Input.prototype.setVisible = function(visible) { // Note: Currently there are only unit tests for block.setCollapsed() // because this function is package. If this function goes back to being a // public API tests (lots of tests) should be added. @@ -219,7 +220,7 @@ Blockly.Input.prototype.setVisible = function(visible) { * Mark all fields on this input as dirty. * @package */ -Blockly.Input.prototype.markDirty = function() { +Input.prototype.markDirty = function() { for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.markDirty(); } @@ -229,9 +230,9 @@ Blockly.Input.prototype.markDirty = function() { * Change a connection's compatibility. * @param {string|Array|null} check Compatible value type or * list of value types. Null if all types are compatible. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setCheck = function(check) { +Input.prototype.setCheck = function(check) { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -243,9 +244,9 @@ Blockly.Input.prototype.setCheck = function(check) { * Change the alignment of the connection's field(s). * @param {number} align One of the values of Blockly.constants.ALIGN. * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setAlign = function(align) { +Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); @@ -257,9 +258,9 @@ Blockly.Input.prototype.setAlign = function(align) { /** * Changes the connection's shadow block. * @param {?Element} shadow DOM representation of a block or null. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setShadowDom = function(shadow) { +Input.prototype.setShadowDom = function(shadow) { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -271,7 +272,7 @@ Blockly.Input.prototype.setShadowDom = function(shadow) { * Returns the XML representation of the connection's shadow block. * @return {?Element} Shadow DOM representation of a block or null. */ -Blockly.Input.prototype.getShadowDom = function() { +Input.prototype.getShadowDom = function() { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -281,7 +282,7 @@ Blockly.Input.prototype.getShadowDom = function() { /** * Initialize the fields on this input. */ -Blockly.Input.prototype.init = function() { +Input.prototype.init = function() { if (!this.sourceBlock_.workspace.rendered) { return; // Headless blocks don't need fields initialized. } @@ -294,7 +295,7 @@ Blockly.Input.prototype.init = function() { * Sever all links to this input. * @suppress {checkTypes} */ -Blockly.Input.prototype.dispose = function() { +Input.prototype.dispose = function() { for (let i = 0, field; (field = this.fieldRow[i]); i++) { field.dispose(); } @@ -303,3 +304,5 @@ Blockly.Input.prototype.dispose = function() { } this.sourceBlock_ = null; }; + +exports = Input; From f59da974b44dcd4fd1de119ae889815e5e86ca7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:55:41 -0700 Subject: [PATCH 263/313] Migrate core/input.js to named requires --- core/input.js | 56 +++++++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/core/input.js b/core/input.js index b9b277fde..59c3b8a72 100644 --- a/core/input.js +++ b/core/input.js @@ -13,29 +13,33 @@ goog.module('Blockly.Input'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Connection'); -goog.require('Blockly.fieldRegistry'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const constants = goog.require('Blockly.constants'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const inputTypes = goog.require('Blockly.inputTypes'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); -goog.require('Blockly.inputTypes'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.RenderedConnection'); - /** * Class for an input with an optional field. * @param {number} type The type of the input. * @param {string} name Language-neutral identifier which may used to find this * input again. - * @param {!Blockly.Block} block The block containing this input. - * @param {Blockly.Connection} connection Optional connection for this input. + * @param {!Block} block The block containing this input. + * @param {Connection} connection Optional connection for this input. * @constructor */ const Input = function(type, name, block, connection) { - if (type != Blockly.inputTypes.DUMMY && !name) { + if (type != inputTypes.DUMMY && !name) { throw Error('Value inputs and statement inputs must have non-empty name.'); } /** @type {number} */ @@ -43,13 +47,13 @@ const Input = function(type, name, block, connection) { /** @type {string} */ this.name = name; /** - * @type {!Blockly.Block} + * @type {!Block} * @private */ this.sourceBlock_ = block; - /** @type {Blockly.Connection} */ + /** @type {Connection} */ this.connection = connection; - /** @type {!Array} */ + /** @type {!Array} */ this.fieldRow = []; }; @@ -57,7 +61,7 @@ const Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Input.prototype.align = Blockly.constants.ALIGN.LEFT; +Input.prototype.align = constants.ALIGN.LEFT; /** * Is the input visible? @@ -68,7 +72,7 @@ Input.prototype.visible_ = true; /** * Get the source block for this input. - * @return {?Blockly.Block} The source block, or null if there is none. + * @return {?Block} The source block, or null if there is none. */ Input.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -77,7 +81,7 @@ Input.prototype.getSourceBlock = function() { /** * Add a field (or label from string), and all prefix and suffix fields, to the * end of the input's field row. - * @param {string|!Blockly.Field} field Something to add as a field. + * @param {string|!Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. * @return {!Input} The input being append to (to allow chaining). @@ -91,7 +95,7 @@ Input.prototype.appendField = function(field, opt_name) { * Inserts a field (or label from string), and all prefix and suffix fields, at * the location of the input's field row. * @param {number} index The index at which to insert field. - * @param {string|!Blockly.Field} field Something to add as a field. + * @param {string|!Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. * @return {number} The index following the last inserted field. @@ -108,7 +112,7 @@ Input.prototype.insertFieldAt = function(index, field, opt_name) { // Generate a FieldLabel when given a plain text field. if (typeof field == 'string') { - field = /** @type {!Blockly.Field} **/ (Blockly.fieldRegistry.fromJson({ + field = /** @type {!Field} **/ (fieldRegistry.fromJson({ 'type': 'field_label', 'text': field, })); @@ -135,7 +139,7 @@ Input.prototype.insertFieldAt = function(index, field, opt_name) { } if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Adding a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -157,7 +161,7 @@ Input.prototype.removeField = function(name, opt_quiet) { field.dispose(); this.fieldRow.splice(i, 1); if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Removing a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -183,7 +187,7 @@ Input.prototype.isVisible = function() { * Sets whether this input is visible or not. * Should only be used to collapse/uncollapse a block. * @param {boolean} visible True if visible. - * @return {!Array} List of blocks to render. + * @return {!Array} List of blocks to render. * @package */ Input.prototype.setVisible = function(visible) { @@ -201,7 +205,7 @@ Input.prototype.setVisible = function(visible) { } if (this.connection) { this.connection = - /** @type {!Blockly.RenderedConnection} */ (this.connection); + /** @type {!RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll(); @@ -242,14 +246,14 @@ Input.prototype.setCheck = function(check) { /** * Change the alignment of the connection's field(s). - * @param {number} align One of the values of Blockly.constants.ALIGN. + * @param {number} align One of the values of constants.ALIGN. * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. * @return {!Input} The input being modified (to allow chaining). */ Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); } return this; diff --git a/tests/deps.js b/tests/deps.js index f62333982..1cda35a7e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -70,7 +70,7 @@ goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.Block goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); 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.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); From 761eec2b69dd20638171cf7a75302d1a79a89e3b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:56:17 -0700 Subject: [PATCH 264/313] clang-format core/input.js --- core/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/input.js b/core/input.js index 59c3b8a72..afa7a3358 100644 --- a/core/input.js +++ b/core/input.js @@ -205,7 +205,7 @@ Input.prototype.setVisible = function(visible) { } if (this.connection) { this.connection = - /** @type {!RenderedConnection} */ (this.connection); + /** @type {!RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll(); From fc10f9e62551d7a5e13841f6ce3fab0751705322 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 07:57:49 -0700 Subject: [PATCH 265/313] Migrate core/block_dragger.js to ES6 const/let --- core/block_dragger.js | 53 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index a1d4b6f2d..d51eead48 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -116,12 +116,13 @@ Blockly.BlockDragger.prototype.dispose = function() { */ Blockly.BlockDragger.initIconData_ = function(block) { // Build a list of icons that need to be moved and where they started. - var dragIconData = []; - var descendants = block.getDescendants(false); - for (var i = 0, descendant; (descendant = descendants[i]); i++) { - var icons = descendant.getIcons(); - for (var j = 0; j < icons.length; j++) { - var data = { + const dragIconData = []; + const descendants = block.getDescendants(false); + + for (let i = 0, descendant; (descendant = descendants[i]); i++) { + const icons = descendant.getIcons(); + for (let j = 0; j < icons.length; j++) { + const data = { // Blockly.utils.Coordinate with x and y properties (workspace // coordinates). location: icons[j].getIconLocation(), @@ -198,8 +199,8 @@ Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { Blockly.BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); - 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.draggingBlock_.translate(newLoc.x, newLoc.y); Blockly.blockAnimations.disconnectUiEffect(this.draggingBlock_); @@ -211,7 +212,7 @@ Blockly.BlockDragger.prototype.disconnectBlock_ = function( * @protected */ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { - var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -225,16 +226,16 @@ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { * @public */ Blockly.BlockDragger.prototype.drag = 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.draggingBlock_.moveDuringDrag(newLoc); this.dragIcons_(delta); - var oldDragTarget = this.dragTarget_; + const oldDragTarget = this.dragTarget_; this.dragTarget_ = this.workspace_.getDragTarget(e); this.draggedConnectionManager_.update(delta, this.dragTarget_); - var oldWouldDeleteBlock = this.wouldDeleteBlock_; + const oldWouldDeleteBlock = this.wouldDeleteBlock_; this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock(); if (oldWouldDeleteBlock != this.wouldDeleteBlock_) { // Prevent unnecessary add/remove class calls. @@ -267,12 +268,12 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { Blockly.blockAnimations.disconnectUiStop(); - var preventMove = !!this.dragTarget_ && + const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); if (preventMove) { var newLoc = this.startXY_; } else { - var newValues = this.getNewLocationAfterDrag_(currentDragDeltaXY); + const newValues = this.getNewLocationAfterDrag_(currentDragDeltaXY); var delta = newValues.delta; var newLoc = newValues.newLocation; } @@ -282,7 +283,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragTarget_.onDrop(this.draggingBlock_); } - var deleted = this.maybeDeleteBlock_(); + const deleted = this.maybeDeleteBlock_(); if (!deleted) { // These are expensive and don't need to be done if we're deleting. this.draggingBlock_.setDragging(false); @@ -314,7 +315,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { */ Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( currentDragDeltaXY) { - var newValues = {}; + const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); newValues.newLocation = Blockly.utils.Coordinate.sum(this.startXY_, newValues.delta); @@ -362,7 +363,7 @@ Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { - var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -375,11 +376,11 @@ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { * @protected */ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { - var toolbox = this.workspace_.getToolbox(); + const toolbox = this.workspace_.getToolbox(); if (toolbox) { - var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : - 'blocklyToolboxGrab'; + const style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : + 'blocklyToolboxGrab'; if (isEnd && typeof toolbox.removeStyle == 'function') { toolbox.removeStyle(style); @@ -395,7 +396,7 @@ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { - var event = + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); @@ -423,7 +424,7 @@ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { * @protected */ Blockly.BlockDragger.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) { @@ -431,7 +432,7 @@ Blockly.BlockDragger.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; @@ -445,8 +446,8 @@ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { */ Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. - for (var i = 0; i < this.dragIconData_.length; i++) { - var data = this.dragIconData_[i]; + for (let i = 0; i < this.dragIconData_.length; i++) { + const data = this.dragIconData_[i]; data.icon.setIconLocation(Blockly.utils.Coordinate.sum(data.location, dxy)); } }; From 4850ad0300f5293bbe37511e52cda6853126a662 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:08:31 -0700 Subject: [PATCH 266/313] Migrate core/block_dragger.js to goog.module --- core/block_dragger.js | 48 ++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index d51eead48..ee103f81b 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.BlockDragger'); +goog.module('Blockly.BlockDragger'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockAnimations'); /** @suppress {extraRequire} */ @@ -39,7 +40,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @implements {Blockly.IBlockDragger} */ -Blockly.BlockDragger = function(block, workspace) { +const BlockDragger = function(block, workspace) { /** * The top block in the stack that is being dragged. * @type {!Blockly.BlockSvg} @@ -91,14 +92,14 @@ Blockly.BlockDragger = function(block, workspace) { * @type {Array} * @protected */ - this.dragIconData_ = Blockly.BlockDragger.initIconData_(block); + this.dragIconData_ = initIconData(block); }; /** * Sever all links from this object. * @package */ -Blockly.BlockDragger.prototype.dispose = function() { +BlockDragger.prototype.dispose = function() { this.dragIconData_.length = 0; if (this.draggedConnectionManager_) { @@ -112,9 +113,8 @@ Blockly.BlockDragger.prototype.dispose = function() { * extends from it if that bubble is open. * @param {!Blockly.BlockSvg} block The root block that is being dragged. * @return {!Array} The list of all icons and their locations. - * @private */ -Blockly.BlockDragger.initIconData_ = function(block) { +const initIconData = function(block) { // Build a list of icons that need to be moved and where they started. const dragIconData = []; const descendants = block.getDescendants(false); @@ -143,7 +143,7 @@ Blockly.BlockDragger.initIconData_ = function(block) { * disconnecting. * @public */ -Blockly.BlockDragger.prototype.startDrag = function( +BlockDragger.prototype.startDrag = function( currentDragDeltaXY, healStack) { if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); @@ -181,7 +181,7 @@ Blockly.BlockDragger.prototype.startDrag = function( * @return {boolean} True to disconnect the block, false otherwise. * @protected */ -Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { +BlockDragger.prototype.shouldDisconnect_ = function(healStack) { return !!( this.draggingBlock_.getParent() || (healStack && this.draggingBlock_.nextConnection && @@ -196,7 +196,7 @@ Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { * moved from the position at mouse down, in pixel units. * @protected */ -Blockly.BlockDragger.prototype.disconnectBlock_ = function( +BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); @@ -211,7 +211,7 @@ Blockly.BlockDragger.prototype.disconnectBlock_ = function( * Fire a UI event at the start of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { +BlockDragger.prototype.fireDragStartEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); @@ -225,7 +225,7 @@ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { * moved from the position at the start of the drag, in pixel units. * @public */ -Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { +BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBlock_.moveDuringDrag(newLoc); @@ -258,7 +258,7 @@ Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { * moved from the position at the start of the drag, in pixel units. * @public */ -Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { +BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { // Make sure internal state is fresh. this.drag(e, currentDragDeltaXY); this.dragIconData_ = []; @@ -313,7 +313,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { * end up. * @protected */ -Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( +BlockDragger.prototype.getNewLocationAfterDrag_ = function( currentDragDeltaXY) { const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); @@ -329,7 +329,7 @@ Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( * @return {boolean} True if the block was deleted. * @protected */ -Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() { +BlockDragger.prototype.maybeDeleteBlock_ = function() { if (this.wouldDeleteBlock_) { // Fire a move event, so we know where to go back to for an undo. this.fireMoveEvent_(); @@ -346,7 +346,7 @@ Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() { * the block started the drag to where it ended the drag. * @protected */ -Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { +BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { this.draggingBlock_.moveConnections(delta.x, delta.y); this.fireMoveEvent_(); if (this.draggedConnectionManager_.wouldConnectBlock()) { @@ -362,7 +362,7 @@ Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * Fire a UI event at the end of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { +BlockDragger.prototype.fireDragEndEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); @@ -375,7 +375,7 @@ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { * @param {boolean} isEnd True if we are at the end of a drag, false otherwise. * @protected */ -Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { +BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { const toolbox = this.workspace_.getToolbox(); if (toolbox) { @@ -395,7 +395,7 @@ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * Fire a move event at the end of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { +BlockDragger.prototype.fireMoveEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; @@ -408,7 +408,7 @@ Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { * dragging block would be deleted if released immediately. * @protected */ -Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { +BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { this.draggingBlock_.setDeleteStyle(this.wouldDeleteBlock_); }; @@ -423,7 +423,7 @@ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { * workspace scale. * @protected */ -Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { +BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); @@ -444,7 +444,7 @@ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { * original positions, in workspace units. * @protected */ -Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { +BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. for (let i = 0; i < this.dragIconData_.length; i++) { const data = this.dragIconData_[i]; @@ -459,7 +459,7 @@ Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { * marker blocks. * @public */ -Blockly.BlockDragger.prototype.getInsertionMarkers = function() { +BlockDragger.prototype.getInsertionMarkers = function() { // No insertion markers with the old style of dragged connection managers. if (this.draggedConnectionManager_ && this.draggedConnectionManager_.getInsertionMarkers) { @@ -470,4 +470,6 @@ Blockly.BlockDragger.prototype.getInsertionMarkers = function() { Blockly.registry.register( Blockly.registry.Type.BLOCK_DRAGGER, Blockly.registry.DEFAULT, - Blockly.BlockDragger); + BlockDragger); + +exports = BlockDragger; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..b268b88c1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -10,7 +10,7 @@ goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.Vari goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); From 873b75e58a8560506daf39f06c9ed19ddbe3a62f Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:15:10 -0700 Subject: [PATCH 267/313] Migrate core/block_dragger.js named requires --- core/block_dragger.js | 109 +++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index ee103f81b..40436a4e1 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,59 +13,58 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockAnimations'); +const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.Events'); +const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -goog.require('Blockly.IBlockDragger'); -goog.require('Blockly.InsertionMarkerManager'); -goog.require('Blockly.registry'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.IDragTarget'); -goog.requireType('Blockly.WorkspaceSvg'); +const IBlockDragger = goog.require('Blockly.IBlockDragger'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +const {DEFAULT, Type, register} = goog.require('Blockly.registry'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** * Class for a block dragger. It moves blocks around the workspace when they * are being dragged by a mouse or touch. - * @param {!Blockly.BlockSvg} block The block to drag. - * @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on. + * @param {!BlockSvg} block The block to drag. + * @param {!WorkspaceSvg} workspace The workspace to drag on. * @constructor - * @implements {Blockly.IBlockDragger} + * @implements {IBlockDragger} */ const BlockDragger = function(block, workspace) { /** * The top block in the stack that is being dragged. - * @type {!Blockly.BlockSvg} + * @type {!BlockSvg} * @protected */ this.draggingBlock_ = block; /** * The workspace on which the block is being dragged. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @protected */ this.workspace_ = workspace; /** * Object that keeps track of connections on dragged blocks. - * @type {!Blockly.InsertionMarkerManager} + * @type {!InsertionMarkerManager} * @protected */ this.draggedConnectionManager_ = - new Blockly.InsertionMarkerManager(this.draggingBlock_); + new InsertionMarkerManager(this.draggingBlock_); /** * Which drag area the mouse pointer is over, if any. - * @type {?Blockly.IDragTarget} + * @type {?IDragTarget} * @private */ this.dragTarget_ = null; @@ -80,7 +79,7 @@ const BlockDragger = function(block, workspace) { /** * The location of the top left corner of the dragging block at the beginning * of the drag in workspace coordinates. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @protected */ this.startXY_ = this.draggingBlock_.getRelativeToSurfaceXY(); @@ -111,7 +110,7 @@ BlockDragger.prototype.dispose = function() { * Make a list of all of the icons (comment, warning, and mutator) that are * on this block and its descendants. Moving an icon moves the bubble that * extends from it if that bubble is open. - * @param {!Blockly.BlockSvg} block The root block that is being dragged. + * @param {!BlockSvg} block The root block that is being dragged. * @return {!Array} The list of all icons and their locations. */ const initIconData = function(block) { @@ -123,7 +122,7 @@ const initIconData = function(block) { const icons = descendant.getIcons(); for (let j = 0; j < icons.length; j++) { const data = { - // Blockly.utils.Coordinate with x and y properties (workspace + // Coordinate with x and y properties (workspace // coordinates). location: icons[j].getIconLocation(), // Blockly.Icon @@ -137,7 +136,7 @@ const initIconData = function(block) { /** * Start dragging a block. This includes moving it to the drag surface. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. @@ -145,8 +144,8 @@ const initIconData = function(block) { */ BlockDragger.prototype.startDrag = function( currentDragDeltaXY, healStack) { - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!getGroup()) { + setGroup(true); } this.fireDragStartEvent_(); @@ -160,9 +159,9 @@ BlockDragger.prototype.startDrag = function( // During a drag there may be a lot of rerenders, but not field changes. // Turn the cache on so we don't do spurious remeasures during the drag. - Blockly.utils.dom.startTextWidthCache(); + startTextWidthCache(); this.workspace_.setResizesEnabled(false); - Blockly.blockAnimations.disconnectUiStop(); + disconnectUiStop(); if (this.shouldDisconnect_(healStack)) { this.disconnectBlock_(healStack, currentDragDeltaXY); @@ -192,7 +191,7 @@ BlockDragger.prototype.shouldDisconnect_ = function(healStack) { * Disconnects the block and moves it to a new location. * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @protected */ @@ -200,10 +199,10 @@ BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBlock_.translate(newLoc.x, newLoc.y); - Blockly.blockAnimations.disconnectUiEffect(this.draggingBlock_); + disconnectUiEffect(this.draggingBlock_); this.draggedConnectionManager_.updateAvailableConnections(); }; @@ -212,22 +211,22 @@ BlockDragger.prototype.disconnectBlock_ = function( * @protected */ BlockDragger.prototype.fireDragStartEvent_ = function() { - const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (get(BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); - Blockly.Events.fire(event); + fire(event); }; /** * Execute a step of block 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. * @public */ BlockDragger.prototype.drag = 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.draggingBlock_.moveDuringDrag(newLoc); this.dragIcons_(delta); @@ -254,7 +253,7 @@ BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { /** * Finish a block drag and put the block 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. * @public */ @@ -264,9 +263,9 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragIconData_ = []; this.fireDragEndEvent_(); - Blockly.utils.dom.stopTextWidthCache(); + stopTextWidthCache(); - Blockly.blockAnimations.disconnectUiStop(); + disconnectUiStop(); const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); @@ -300,15 +299,15 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { } this.workspace_.setResizesEnabled(true); - Blockly.Events.setGroup(false); + setGroup(false); }; /** * Calculates the drag delta and new location values after a block is dragged. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the start of the drag, in pixel units. - * @return {{delta: !Blockly.utils.Coordinate, newLocation: - * !Blockly.utils.Coordinate}} New location after drag. delta is in + * @return {{delta: !Coordinate, newLocation: + * !Coordinate}} New location after drag. delta is in * workspace units. newLocation is the new coordinate where the block should * end up. * @protected @@ -318,7 +317,7 @@ BlockDragger.prototype.getNewLocationAfterDrag_ = function( const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); newValues.newLocation = - Blockly.utils.Coordinate.sum(this.startXY_, newValues.delta); + Coordinate.sum(this.startXY_, newValues.delta); return newValues; }; @@ -342,7 +341,7 @@ BlockDragger.prototype.maybeDeleteBlock_ = function() { /** * Updates the necessary information to place a block at a certain location. - * @param {!Blockly.utils.Coordinate} delta The change in location from where + * @param {!Coordinate} delta The change in location from where * the block started the drag to where it ended the drag. * @protected */ @@ -363,9 +362,9 @@ BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ BlockDragger.prototype.fireDragEndEvent_ = function() { - const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (get(BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); - Blockly.Events.fire(event); + fire(event); }; /** @@ -397,10 +396,10 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { */ BlockDragger.prototype.fireMoveEvent_ = function() { const event = - new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); + new (get(BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); - Blockly.Events.fire(event); + fire(event); }; /** @@ -417,14 +416,14 @@ BlockDragger.prototype.updateCursorDuringBlockDrag_ = 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. * @protected */ BlockDragger.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) { @@ -440,7 +439,7 @@ BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { /** * Move all of the icons connected to this drag. - * @param {!Blockly.utils.Coordinate} dxy How far to move the icons from their + * @param {!Coordinate} dxy How far to move the icons from their * original positions, in workspace units. * @protected */ @@ -448,14 +447,14 @@ BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. for (let i = 0; i < this.dragIconData_.length; i++) { const data = this.dragIconData_[i]; - data.icon.setIconLocation(Blockly.utils.Coordinate.sum(data.location, dxy)); + data.icon.setIconLocation(Coordinate.sum(data.location, dxy)); } }; /** * Get a list of the insertion markers that currently exist. Drags have 0, 1, * or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion + * @return {!Array} A possibly empty list of insertion * marker blocks. * @public */ @@ -468,8 +467,8 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -Blockly.registry.register( - Blockly.registry.Type.BLOCK_DRAGGER, Blockly.registry.DEFAULT, +register( + Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); exports = BlockDragger; From 848ec34a0aef90bafe46c2cbee9b5f761d002f99 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:16:19 -0700 Subject: [PATCH 268/313] clang-format core/block_dragger.js --- core/block_dragger.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 40436a4e1..e97457d22 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -142,8 +142,7 @@ const initIconData = function(block) { * disconnecting. * @public */ -BlockDragger.prototype.startDrag = function( - currentDragDeltaXY, healStack) { +BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { if (!getGroup()) { setGroup(true); } @@ -182,7 +181,7 @@ BlockDragger.prototype.startDrag = function( */ BlockDragger.prototype.shouldDisconnect_ = function(healStack) { return !!( - this.draggingBlock_.getParent() || + this.draggingBlock_.getParent() || (healStack && this.draggingBlock_.nextConnection && this.draggingBlock_.nextConnection.targetBlock())); }; @@ -312,12 +311,10 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { * end up. * @protected */ -BlockDragger.prototype.getNewLocationAfterDrag_ = function( - currentDragDeltaXY) { +BlockDragger.prototype.getNewLocationAfterDrag_ = function(currentDragDeltaXY) { const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - newValues.newLocation = - Coordinate.sum(this.startXY_, newValues.delta); + newValues.newLocation = Coordinate.sum(this.startXY_, newValues.delta); return newValues; }; @@ -379,7 +376,7 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { if (toolbox) { const style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : - 'blocklyToolboxGrab'; + 'blocklyToolboxGrab'; if (isEnd && typeof toolbox.removeStyle == 'function') { toolbox.removeStyle(style); @@ -395,8 +392,7 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ BlockDragger.prototype.fireMoveEvent_ = function() { - const event = - new (get(BLOCK_MOVE))(this.draggingBlock_); + const event = new (get(BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); fire(event); @@ -467,8 +463,6 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -register( - Type.BLOCK_DRAGGER, DEFAULT, - BlockDragger); +register(Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); exports = BlockDragger; From c838b0e27c158e72810250442e119fffedf8f223 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:23:28 -0700 Subject: [PATCH 269/313] Reorder requires --- core/block_dragger.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index e97457d22..20c619cbc 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,22 +13,22 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); -const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const IBlockDragger = goog.require('Blockly.IBlockDragger'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); +const {DEFAULT, Type, register} = goog.require('Blockly.registry'); +const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); +const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -const IBlockDragger = goog.require('Blockly.IBlockDragger'); -const IDragTarget = goog.requireType('Blockly.IDragTarget'); -const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); -const {DEFAULT, Type, register} = goog.require('Blockly.registry'); -const Coordinate = goog.require('Blockly.utils.Coordinate'); -const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); -const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** From 2688329aefdc7b5501a1d77aa688ec842d0923bf Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 23 Jul 2021 12:12:59 -0700 Subject: [PATCH 270/313] Fix imports --- core/block_dragger.js | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 20c619cbc..5c3ff6916 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,16 +13,20 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IBlockDragger = goog.require('Blockly.IBlockDragger'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); -const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); -const {DEFAULT, Type, register} = goog.require('Blockly.registry'); -const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); -const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); +const blockAnimation = goog.require('Blockly.blockAnimations'); +const dom = goog.require('Blockly.utils.dom'); +const events = goog.require('Blockly.Events'); +const registry = goog.require('Blockly.registry'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); /** @suppress {extraRequire} */ @@ -143,8 +147,8 @@ const initIconData = function(block) { * @public */ BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { - if (!getGroup()) { - setGroup(true); + if (!events.getGroup()) { + events.setGroup(true); } this.fireDragStartEvent_(); @@ -158,9 +162,9 @@ BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { // During a drag there may be a lot of rerenders, but not field changes. // Turn the cache on so we don't do spurious remeasures during the drag. - startTextWidthCache(); + dom.startTextWidthCache(); this.workspace_.setResizesEnabled(false); - disconnectUiStop(); + blockAnimation.disconnectUiStop(); if (this.shouldDisconnect_(healStack)) { this.disconnectBlock_(healStack, currentDragDeltaXY); @@ -201,7 +205,7 @@ BlockDragger.prototype.disconnectBlock_ = function( const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBlock_.translate(newLoc.x, newLoc.y); - disconnectUiEffect(this.draggingBlock_); + blockAnimation.disconnectUiEffect(this.draggingBlock_); this.draggedConnectionManager_.updateAvailableConnections(); }; @@ -210,9 +214,9 @@ BlockDragger.prototype.disconnectBlock_ = function( * @protected */ BlockDragger.prototype.fireDragStartEvent_ = function() { - const event = new (get(BLOCK_DRAG))( + const event = new (events.get(events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); - fire(event); + events.fire(event); }; /** @@ -262,9 +266,9 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragIconData_ = []; this.fireDragEndEvent_(); - stopTextWidthCache(); + dom.stopTextWidthCache(); - disconnectUiStop(); + blockAnimation.disconnectUiStop(); const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); @@ -298,7 +302,7 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { } this.workspace_.setResizesEnabled(true); - setGroup(false); + events.setGroup(false); }; /** @@ -359,9 +363,9 @@ BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ BlockDragger.prototype.fireDragEndEvent_ = function() { - const event = new (get(BLOCK_DRAG))( + const event = new (events.get(events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); - fire(event); + events.fire(event); }; /** @@ -392,10 +396,10 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ BlockDragger.prototype.fireMoveEvent_ = function() { - const event = new (get(BLOCK_MOVE))(this.draggingBlock_); + const event = new (events.get(events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); - fire(event); + events.fire(event); }; /** @@ -463,6 +467,6 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -register(Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); +registry.register(registry.Type.BLOCK_DRAGGER, registry.DEFAULT, BlockDragger); exports = BlockDragger; From f88320770c7d6e045279916b537eabcdc3345aa7 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 23 Jul 2021 12:16:00 -0700 Subject: [PATCH 271/313] Remove unnecessary require --- core/block_dragger.js | 2 -- tests/deps.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 5c3ff6916..b7c11e8a3 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -28,8 +28,6 @@ const dom = goog.require('Blockly.utils.dom'); const events = goog.require('Blockly.Events'); const registry = goog.require('Blockly.registry'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -/** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); diff --git a/tests/deps.js b/tests/deps.js index b268b88c1..42191e253 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -10,7 +10,7 @@ goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.Vari goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); From 6649619f120e5c8a98c1e581a2a32e87f61269fd Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 12:47:55 -0700 Subject: [PATCH 272/313] Convert Blockly.Block from require to requireType --- core/generator.js | 2 +- tests/deps.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/generator.js b/core/generator.js index 8e71fb040..112c2f8a1 100644 --- a/core/generator.js +++ b/core/generator.js @@ -15,7 +15,7 @@ goog.module('Blockly.Generator'); goog.module.declareLegacyNamespace(); /* eslint-disable-next-line no-unused-vars */ -const Block = goog.require('Blockly.Block'); +const Block = goog.requireType('Blockly.Block'); /* eslint-disable-next-line no-unused-vars */ const Names = goog.requireType('Blockly.Names'); /* eslint-disable-next-line no-unused-vars */ diff --git a/tests/deps.js b/tests/deps.js index c40db7cbc..94b646890 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 35673a79e12376c4beacd1223591c230f2c3ea34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 13:02:15 -0700 Subject: [PATCH 273/313] Remove unused Block.Block require --- core/flyout_horizontal.js | 2 -- tests/deps.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 9bfc8aa91..7f1ad72fd 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -26,8 +26,6 @@ const registry = goog.require('Blockly.registry'); const {Position} = goog.require('Blockly.utils.toolbox'); const {getScrollDeltaPixels} = goog.require('Blockly.utils'); const {inherits} = goog.require('Blockly.utils.object'); -/** @suppress {extraRequire} */ -goog.require('Blockly.Block'); /** diff --git a/tests/deps.js b/tests/deps.js index 87600526f..a5e2310db 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -63,7 +63,7 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); From a5c486e5717215fa4fe83ca64988f22c4149b622 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 13:09:48 -0700 Subject: [PATCH 274/313] Made icon size field const --- core/icon.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/icon.js b/core/icon.js index b6b8942a7..69ff3ef37 100644 --- a/core/icon.js +++ b/core/icon.js @@ -53,6 +53,7 @@ Icon.prototype.collapseHidden = true; /** * Height and width of icons. + * @const */ Icon.prototype.SIZE = 17; From 808ec6a5d3c6069c28e9751e369c224df1cbfcc0 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:29:05 -0700 Subject: [PATCH 275/313] Migrate core/marker_manager.js to ES6 const/let --- core/marker_manager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 82c149052..3d3c64bbb 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -81,7 +81,7 @@ Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { * @param {string} id The ID of the marker to unregister. */ Blockly.MarkerManager.prototype.unregisterMarker = function(id) { - var marker = this.markers_[id]; + const marker = this.markers_[id]; if (marker) { marker.dispose(); delete this.markers_[id]; @@ -119,7 +119,7 @@ Blockly.MarkerManager.prototype.setCursor = function(cursor) { } this.cursor_ = cursor; if (this.cursor_) { - var drawer = this.workspace_.getRenderer() + const drawer = this.workspace_.getRenderer() .makeMarkerDrawer(this.workspace_, this.cursor_); this.cursor_.setDrawer(drawer); this.setCursorSvg(this.cursor_.getDrawer().createDom()); @@ -180,8 +180,8 @@ Blockly.MarkerManager.prototype.updateMarkers = function() { * @package */ Blockly.MarkerManager.prototype.dispose = function() { - var markerIds = Object.keys(this.markers_); - for (var i = 0, markerId; (markerId = markerIds[i]); i++) { + const markerIds = Object.keys(this.markers_); + for (let i = 0, markerId; (markerId = markerIds[i]); i++) { this.unregisterMarker(markerId); } this.markers_ = null; From df794d7e3a47acec6fe91ed278ea99fbcb2652ab Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:31:10 -0700 Subject: [PATCH 276/313] Migrate core/marker_manager.js to goog.module --- core/marker_manager.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 3d3c64bbb..59bc64b7a 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.MarkerManager'); +goog.module('Blockly.MarkerManager'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Cursor'); goog.require('Blockly.Marker'); @@ -24,7 +25,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -Blockly.MarkerManager = function(workspace){ +const MarkerManager = function(workspace){ /** * The cursor. * @type {?Blockly.Cursor} @@ -59,14 +60,14 @@ Blockly.MarkerManager = function(workspace){ * @type {string} * @const */ -Blockly.MarkerManager.LOCAL_MARKER = 'local_marker_1'; +MarkerManager.LOCAL_MARKER = 'local_marker_1'; /** * Register the marker by adding it to the map of markers. * @param {string} id A unique identifier for the marker. * @param {!Blockly.Marker} marker The marker to register. */ -Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { +MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { this.unregisterMarker(id); } @@ -80,7 +81,7 @@ Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { * Unregister the marker by removing it from the map of markers. * @param {string} id The ID of the marker to unregister. */ -Blockly.MarkerManager.prototype.unregisterMarker = function(id) { +MarkerManager.prototype.unregisterMarker = function(id) { const marker = this.markers_[id]; if (marker) { marker.dispose(); @@ -95,7 +96,7 @@ Blockly.MarkerManager.prototype.unregisterMarker = function(id) { * Get the cursor for the workspace. * @return {?Blockly.Cursor} The cursor for this workspace. */ -Blockly.MarkerManager.prototype.getCursor = function() { +MarkerManager.prototype.getCursor = function() { return this.cursor_; }; @@ -105,7 +106,7 @@ Blockly.MarkerManager.prototype.getCursor = function() { * @return {?Blockly.Marker} The marker that corresponds to the given ID, * or null if none exists. */ -Blockly.MarkerManager.prototype.getMarker = function(id) { +MarkerManager.prototype.getMarker = function(id) { return this.markers_[id] || null; }; @@ -113,7 +114,7 @@ Blockly.MarkerManager.prototype.getMarker = function(id) { * Sets the cursor and initializes the drawer for use with keyboard navigation. * @param {Blockly.Cursor} cursor The cursor used to move around this workspace. */ -Blockly.MarkerManager.prototype.setCursor = function(cursor) { +MarkerManager.prototype.setCursor = function(cursor) { if (this.cursor_ && this.cursor_.getDrawer()) { this.cursor_.getDrawer().dispose(); } @@ -132,7 +133,7 @@ Blockly.MarkerManager.prototype.setCursor = function(cursor) { * workspace SVG group. * @package */ -Blockly.MarkerManager.prototype.setCursorSvg = function(cursorSvg) { +MarkerManager.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg_ = null; return; @@ -148,7 +149,7 @@ Blockly.MarkerManager.prototype.setCursorSvg = function(cursorSvg) { * workspace SVG group. * @package */ -Blockly.MarkerManager.prototype.setMarkerSvg = function(markerSvg) { +MarkerManager.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg_ = null; return; @@ -167,7 +168,7 @@ Blockly.MarkerManager.prototype.setMarkerSvg = function(markerSvg) { * Redraw the attached cursor SVG if needed. * @package */ -Blockly.MarkerManager.prototype.updateMarkers = function() { +MarkerManager.prototype.updateMarkers = function() { if (this.workspace_.keyboardAccessibilityMode && this.cursorSvg_) { this.workspace_.getCursor().draw(); } @@ -179,7 +180,7 @@ Blockly.MarkerManager.prototype.updateMarkers = function() { * @suppress {checkTypes} * @package */ -Blockly.MarkerManager.prototype.dispose = function() { +MarkerManager.prototype.dispose = function() { const markerIds = Object.keys(this.markers_); for (let i = 0, markerId; (markerId = markerIds[i]); i++) { this.unregisterMarker(markerId); @@ -190,3 +191,5 @@ Blockly.MarkerManager.prototype.dispose = function() { this.cursor_ = null; } }; + +exports = MarkerManager; From 608a4fd9f1906f99704751d457f578688cbf92de Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:34:01 -0700 Subject: [PATCH 277/313] Migrate core/marker_manager.js to named requires --- core/marker_manager.js | 26 ++++++++++++++------------ tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 59bc64b7a..b2d5c2bd5 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -13,22 +13,24 @@ goog.module('Blockly.MarkerManager'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Cursor'); -goog.require('Blockly.Marker'); - -goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Cursor = goog.requireType('Blockly.Cursor'); +/* eslint-disable-next-line no-unused-vars */ +const Marker = goog.requireType('Blockly.Marker'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** * Class to manage the multiple markers and the cursor on a workspace. - * @param {!Blockly.WorkspaceSvg} workspace The workspace for the marker manager. + * @param {!WorkspaceSvg} workspace The workspace for the marker manager. * @constructor * @package */ const MarkerManager = function(workspace){ /** * The cursor. - * @type {?Blockly.Cursor} + * @type {?Cursor} * @private */ this.cursor_ = null; @@ -42,14 +44,14 @@ const MarkerManager = function(workspace){ /** * The map of markers for the workspace. - * @type {!Object} + * @type {!Object} * @private */ this.markers_ = Object.create(null); /** * The workspace this marker manager is associated with. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; @@ -65,7 +67,7 @@ MarkerManager.LOCAL_MARKER = 'local_marker_1'; /** * Register the marker by adding it to the map of markers. * @param {string} id A unique identifier for the marker. - * @param {!Blockly.Marker} marker The marker to register. + * @param {!Marker} marker The marker to register. */ MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { @@ -94,7 +96,7 @@ MarkerManager.prototype.unregisterMarker = function(id) { /** * Get the cursor for the workspace. - * @return {?Blockly.Cursor} The cursor for this workspace. + * @return {?Cursor} The cursor for this workspace. */ MarkerManager.prototype.getCursor = function() { return this.cursor_; @@ -103,7 +105,7 @@ MarkerManager.prototype.getCursor = function() { /** * Get a single marker that corresponds to the given ID. * @param {string} id A unique identifier for the marker. - * @return {?Blockly.Marker} The marker that corresponds to the given ID, + * @return {?Marker} The marker that corresponds to the given ID, * or null if none exists. */ MarkerManager.prototype.getMarker = function(id) { @@ -112,7 +114,7 @@ MarkerManager.prototype.getMarker = function(id) { /** * Sets the cursor and initializes the drawer for use with keyboard navigation. - * @param {Blockly.Cursor} cursor The cursor used to move around this workspace. + * @param {Cursor} cursor The cursor used to move around this workspace. */ MarkerManager.prototype.setCursor = function(cursor) { if (this.cursor_ && this.cursor_.getDrawer()) { diff --git a/tests/deps.js b/tests/deps.js index de575339f..6ed58a69c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -107,7 +107,7 @@ goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCur goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); +goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); From 126e02927f8752b9dc1c18bee9b9c4e4ab2117d8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:34:30 -0700 Subject: [PATCH 278/313] clang-format core/marker_manager.js --- core/marker_manager.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index b2d5c2bd5..1f16f500a 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -27,7 +27,7 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -const MarkerManager = function(workspace){ +const MarkerManager = function(workspace) { /** * The cursor. * @type {?Cursor} @@ -73,8 +73,8 @@ MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { this.unregisterMarker(id); } - marker.setDrawer(this.workspace_.getRenderer() - .makeMarkerDrawer(this.workspace_, marker)); + marker.setDrawer( + this.workspace_.getRenderer().makeMarkerDrawer(this.workspace_, marker)); this.setMarkerSvg(marker.getDrawer().createDom()); this.markers_[id] = marker; }; @@ -89,7 +89,8 @@ MarkerManager.prototype.unregisterMarker = function(id) { marker.dispose(); delete this.markers_[id]; } else { - throw Error('Marker with ID ' + id + ' does not exist. ' + + throw Error( + 'Marker with ID ' + id + ' does not exist. ' + 'Can only unregister markers that exist.'); } }; @@ -122,8 +123,8 @@ MarkerManager.prototype.setCursor = function(cursor) { } this.cursor_ = cursor; if (this.cursor_) { - const drawer = this.workspace_.getRenderer() - .makeMarkerDrawer(this.workspace_, this.cursor_); + const drawer = this.workspace_.getRenderer().makeMarkerDrawer( + this.workspace_, this.cursor_); this.cursor_.setDrawer(drawer); this.setCursorSvg(this.cursor_.getDrawer().createDom()); } From 046636547ef5e31ea7db352509248a9ccb500fc1 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:26:11 -0700 Subject: [PATCH 279/313] Change how the debug filter is created --- core/renderers/common/constants.js | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 5c73d0510..7508b6050 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -401,6 +401,14 @@ Blockly.blockRendering.ConstantProvider = function() { */ this.randomIdentifier = String(Math.random()).substring(2); + /** + * The defs tag that contains all filters and patterns for this Blockly + * instance. + * @type {SVGElement} + * @private + */ + this.defs = null; + /** * The ID of the emboss filter, or the empty string if no filter is set. * @type {string} @@ -1023,7 +1031,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - var defs = Blockly.utils.dom.createSvgElement( + this.defs = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.DEFS, {}, svg); /* @@ -1041,7 +1049,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, */ var embossFilter = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FILTER, - {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, defs); + {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); @@ -1095,7 +1103,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 - }, defs); + }, this.defs); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); @@ -1105,42 +1113,46 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; - if (Blockly.blockRendering.Debug) { + this.createDebugFilter(); +}; + +/** + * Create a filter for highlighting the currently rendering block during + * render debugging. + * @private + */ +Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = + function() { + // Only create the debug filter once. + if (!this.debugFilter_) { var debugFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, - { + Blockly.utils.Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', y: '-30%', x: '-40%' }, - defs); + this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood var debugComponentTransfer = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPONENTTRANSFER, { - 'result': 'outBlur' - }, debugFilter); + Blockly.utils.Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, + debugFilter); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEFUNCA, - { - 'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1' - }, + {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, debugComponentTransfer); // Color the highlight Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEFLOOD, - { - 'flood-color': '#ff0000', - 'flood-opacity': 0.5, - 'result': 'outColor' - }, + {'flood-color': '#ff0000', 'flood-opacity': 0.5, 'result': 'outColor'}, debugFilter); Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, - { - 'in': 'outColor', 'in2': 'outBlur', - 'operator': 'in', 'result': 'outGlow' + Blockly.utils.Svg.FECOMPOSITE, { + 'in': 'outColor', + 'in2': 'outBlur', + 'operator': 'in', + 'result': 'outGlow' }, debugFilter); this.debugFilterId = debugFilter.id; From e9c1e67d17457111c02f3c1bc53681dafa540974 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:38:20 -0700 Subject: [PATCH 280/313] Migrate core/renderers/common/constants.js to goog.module --- core/renderers/common/constants.js | 53 ++++++++++++++++-------------- tests/deps.js | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 7508b6050..071b21e7d 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockRendering.ConstantProvider'); +goog.module('Blockly.blockRendering.ConstantProvider'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); goog.require('Blockly.utils'); @@ -30,7 +31,7 @@ goog.requireType('Blockly.Theme'); * @constructor * @package */ -Blockly.blockRendering.ConstantProvider = function() { +const ConstantProvider = function() { /** * The size of an empty spacer. @@ -543,7 +544,7 @@ Blockly.blockRendering.ConstantProvider = function() { * Initialize shape objects based on the constants set in the constructor. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.init = function() { +ConstantProvider.prototype.init = function() { /** * An object containing sizing and path information about collapsed block @@ -588,7 +589,7 @@ Blockly.blockRendering.ConstantProvider.prototype.init = function() { * @param {!Blockly.Theme} theme The current workspace theme. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.setTheme = function( +ConstantProvider.prototype.setTheme = function( theme) { /** @@ -611,7 +612,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setTheme = function( * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setDynamicProperties_ = +ConstantProvider.prototype.setDynamicProperties_ = function(theme) { /* eslint-disable indent */ this.setFontConstants_(theme); @@ -626,7 +627,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setDynamicProperties_ = * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setFontConstants_ = function( +ConstantProvider.prototype.setFontConstants_ = function( theme) { this.FIELD_TEXT_FONTFAMILY = theme.fontStyle && theme.fontStyle['family'] != undefined ? @@ -652,7 +653,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setFontConstants_ = function( * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setComponentConstants_ = +ConstantProvider.prototype.setComponentConstants_ = function(theme) { /* eslint-disable indent */ this.CURSOR_COLOUR = theme.getComponentStyle('cursorColour') || @@ -675,7 +676,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setComponentConstants_ = * containing the style and an autogenerated name for that style. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.getBlockStyleForColour = +ConstantProvider.prototype.getBlockStyleForColour = function(colour) { /* eslint-disable indent */ var name = 'auto_' + colour; @@ -691,7 +692,7 @@ Blockly.blockRendering.ConstantProvider.prototype.getBlockStyleForColour = * @return {!Blockly.Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ -Blockly.blockRendering.ConstantProvider.prototype.getBlockStyle = function( +ConstantProvider.prototype.getBlockStyle = function( blockStyleName) { return this.blockStyles[blockStyleName || ''] || (blockStyleName && blockStyleName.indexOf('auto_') == 0 ? @@ -706,7 +707,7 @@ Blockly.blockRendering.ConstantProvider.prototype.getBlockStyle = function( * given colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.createBlockStyle_ = function( +ConstantProvider.prototype.createBlockStyle_ = function( colour) { return this.validatedBlockStyle_({ 'colourPrimary': colour @@ -727,7 +728,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createBlockStyle_ = function( * required properties populated. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.validatedBlockStyle_ = +ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { /* eslint-disable indent */ // Make a new object with all of the same properties. @@ -756,7 +757,7 @@ Blockly.blockRendering.ConstantProvider.prototype.validatedBlockStyle_ = * @return {string} The generated secondary colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.generateSecondaryColour_ = +ConstantProvider.prototype.generateSecondaryColour_ = function(colour) { /* eslint-disable indent */ return Blockly.utils.colour.blend('#fff', colour, 0.6) || colour; @@ -768,7 +769,7 @@ Blockly.blockRendering.ConstantProvider.prototype.generateSecondaryColour_ = * @return {string} The generated tertiary colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.generateTertiaryColour_ = +ConstantProvider.prototype.generateTertiaryColour_ = function(colour) { /* eslint-disable indent */ return Blockly.utils.colour.blend('#fff', colour, 0.3) || colour; @@ -780,7 +781,7 @@ Blockly.blockRendering.ConstantProvider.prototype.generateTertiaryColour_ = * Delete all DOM elements that this provider created. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.dispose = function() { +ConstantProvider.prototype.dispose = function() { if (this.embossFilter_) { Blockly.utils.dom.removeNode(this.embossFilter_); } @@ -798,7 +799,7 @@ Blockly.blockRendering.ConstantProvider.prototype.dispose = function() { * collapsed block indicators. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeJaggedTeeth = function() { +ConstantProvider.prototype.makeJaggedTeeth = function() { var height = this.JAGGED_TEETH_HEIGHT; var width = this.JAGGED_TEETH_WIDTH; @@ -821,7 +822,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeJaggedTeeth = function() { * start hats. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeStartHat = function() { +ConstantProvider.prototype.makeStartHat = function() { var height = this.START_HAT_HEIGHT; var width = this.START_HAT_WIDTH; @@ -844,7 +845,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeStartHat = function() { * puzzle tabs. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makePuzzleTab = function() { +ConstantProvider.prototype.makePuzzleTab = function() { var width = this.TAB_WIDTH; var height = this.TAB_HEIGHT; @@ -898,7 +899,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makePuzzleTab = function() { * notches. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeNotch = function() { +ConstantProvider.prototype.makeNotch = function() { var width = this.NOTCH_WIDTH; var height = this.NOTCH_HEIGHT; var innerWidth = 3; @@ -928,7 +929,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeNotch = function() { * inside corners. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeInsideCorners = function() { +ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; var innerTopLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, @@ -950,7 +951,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeInsideCorners = function() * outside corners. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeOutsideCorners = function() { +ConstantProvider.prototype.makeOutsideCorners = function() { var radius = this.CORNER_RADIUS; /** * SVG path for drawing the rounded top-left corner. @@ -1000,7 +1001,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeOutsideCorners = function( * @return {!Object} The shape object for the connection. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function( +ConstantProvider.prototype.shapeFor = function( connection) { switch (connection.type) { case Blockly.connectionTypes.INPUT_VALUE: @@ -1022,7 +1023,7 @@ Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function( * @suppress {strictModuleDepCheck} Debug renderer only included in playground. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, +ConstantProvider.prototype.createDom = function(svg, tagName, selector) { this.injectCSS_(tagName, selector); @@ -1121,7 +1122,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, * render debugging. * @private */ -Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = +ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { @@ -1166,7 +1167,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = * @param {string} selector The CSS selector to use. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.injectCSS_ = function( +ConstantProvider.prototype.injectCSS_ = function( tagName, selector) { var cssArray = this.getCSS_(selector); var cssNodeId = 'blockly-renderer-style-' + tagName; @@ -1194,7 +1195,7 @@ Blockly.blockRendering.ConstantProvider.prototype.injectCSS_ = function( * @return {!Array} Array of CSS strings. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.getCSS_ = function(selector) { +ConstantProvider.prototype.getCSS_ = function(selector) { return [ /* eslint-disable indent */ // Text. @@ -1269,3 +1270,5 @@ Blockly.blockRendering.ConstantProvider.prototype.getCSS_ = function(selector) { /* eslint-enable indent */ ]; }; + +exports = ConstantProvider; diff --git a/tests/deps.js b/tests/deps.js index de575339f..14992f734 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -120,7 +120,7 @@ goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); -goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); From 82c1d8c47ad70327dde017dfd1a13142109e679a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:48:55 -0700 Subject: [PATCH 281/313] Migrate core/renderers/common/constants.js named requires --- core/renderers/common/constants.js | 207 ++++++++++++++--------------- 1 file changed, 103 insertions(+), 104 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 071b21e7d..4f64223d7 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -13,17 +13,17 @@ goog.module('Blockly.blockRendering.ConstantProvider'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.colour'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.svgPaths'); -goog.require('Blockly.utils.userAgent'); - -goog.requireType('Blockly.blockRendering.Debug'); -goog.requireType('Blockly.RenderedConnection'); -goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +const colour = goog.require('Blockly.utils.colour'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const dom = goog.require('Blockly.utils.dom'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const utils = goog.require('Blockly.utils'); /** @@ -223,7 +223,7 @@ const ConstantProvider = function() { */ this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT; - this.START_POINT = Blockly.utils.svgPaths.moveBy(0, 0); + this.START_POINT = svgPaths.moveBy(0, 0); /** * Height of SVG path for jagged teeth at the end of collapsed blocks. @@ -305,7 +305,7 @@ const ConstantProvider = function() { * @type {boolean} */ this.FIELD_TEXT_BASELINE_CENTER = - !Blockly.utils.userAgent.IE && !Blockly.utils.userAgent.EDGE; + !userAgent.IE && !userAgent.EDGE; /** * A dropdown field's border rect height. @@ -586,7 +586,7 @@ ConstantProvider.prototype.init = function() { /** * Refresh constants properties that depend on the theme. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @package */ ConstantProvider.prototype.setTheme = function( @@ -594,7 +594,7 @@ ConstantProvider.prototype.setTheme = function( /** * The block styles map. - * @type {Object} + * @type {Object} * @package */ this.blockStyles = Object.create(null); @@ -609,7 +609,7 @@ ConstantProvider.prototype.setTheme = function( /** * Sets dynamic properties that depend on other values or theme properties. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setDynamicProperties_ = @@ -624,7 +624,7 @@ ConstantProvider.prototype.setDynamicProperties_ = /** * Set constants related to fonts. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setFontConstants_ = function( @@ -639,7 +639,7 @@ ConstantProvider.prototype.setFontConstants_ = function( theme.fontStyle && theme.fontStyle['size'] != undefined ? theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; - var fontMetrics = Blockly.utils.dom.measureFontMetrics('Hg', + var fontMetrics = dom.measureFontMetrics('Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); @@ -650,7 +650,7 @@ ConstantProvider.prototype.setFontConstants_ = function( /** * Set constants from a theme's component styles. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setComponentConstants_ = @@ -672,7 +672,7 @@ ConstantProvider.prototype.setComponentConstants_ = * Get or create a block style based on a single colour value. Generate a name * for the style based on the colour. * @param {string} colour #RRGGBB colour string. - * @return {{style: !Blockly.Theme.BlockStyle, name: string}} An object + * @return {{style: !Theme.BlockStyle, name: string}} An object * containing the style and an autogenerated name for that style. * @package */ @@ -689,7 +689,7 @@ ConstantProvider.prototype.getBlockStyleForColour = /** * Gets the BlockStyle for the given block style name. * @param {?string} blockStyleName The name of the block style. - * @return {!Blockly.Theme.BlockStyle} The named block style, or a default style + * @return {!Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ ConstantProvider.prototype.getBlockStyle = function( @@ -703,7 +703,7 @@ ConstantProvider.prototype.getBlockStyle = function( /** * Create a block style object based on the given colour. * @param {string} colour #RRGGBB colour string. - * @return {!Blockly.Theme.BlockStyle} A populated block style based on the + * @return {!Theme.BlockStyle} A populated block style based on the * given colour. * @protected */ @@ -724,7 +724,7 @@ ConstantProvider.prototype.createBlockStyle_ = function( * hat:(string|undefined) * }} blockStyle A full or partial block style object. - * @return {!Blockly.Theme.BlockStyle} A full block style object, with all + * @return {!Theme.BlockStyle} A full block style object, with all * required properties populated. * @protected */ @@ -732,19 +732,19 @@ ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { /* eslint-disable indent */ // Make a new object with all of the same properties. - var valid = /** @type {!Blockly.Theme.BlockStyle} */ ({}); + var valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { - Blockly.utils.object.mixin(valid, blockStyle); + utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = Blockly.utils.parseBlockColour( + var parsedColour = utils.parseBlockColour( valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? - Blockly.utils.parseBlockColour(valid['colourSecondary']).hex : + utils.parseBlockColour(valid['colourSecondary']).hex : this.generateSecondaryColour_(valid.colourPrimary); valid.colourTertiary = valid['colourTertiary'] ? - Blockly.utils.parseBlockColour(valid['colourTertiary']).hex : + utils.parseBlockColour(valid['colourTertiary']).hex : this.generateTertiaryColour_(valid.colourPrimary); valid.hat = valid['hat'] || ''; @@ -758,9 +758,9 @@ ConstantProvider.prototype.validatedBlockStyle_ = * @protected */ ConstantProvider.prototype.generateSecondaryColour_ = - function(colour) { + function(inputColour) { /* eslint-disable indent */ - return Blockly.utils.colour.blend('#fff', colour, 0.6) || colour; + return colour.blend('#fff', inputColour, 0.6) || inputColour; }; /* eslint-enable indent */ /** @@ -769,10 +769,9 @@ ConstantProvider.prototype.generateSecondaryColour_ = * @return {string} The generated tertiary colour. * @protected */ -ConstantProvider.prototype.generateTertiaryColour_ = - function(colour) { - /* eslint-disable indent */ - return Blockly.utils.colour.blend('#fff', colour, 0.3) || colour; +ConstantProvider.prototype.generateTertiaryColour_ = function(inputColour) { + /* eslint-disable indent */ + return colour.blend('#fff', inputColour, 0.3) || inputColour; }; /* eslint-enable indent */ @@ -783,13 +782,13 @@ ConstantProvider.prototype.generateTertiaryColour_ = */ ConstantProvider.prototype.dispose = function() { if (this.embossFilter_) { - Blockly.utils.dom.removeNode(this.embossFilter_); + dom.removeNode(this.embossFilter_); } if (this.disabledPattern_) { - Blockly.utils.dom.removeNode(this.disabledPattern_); + dom.removeNode(this.disabledPattern_); } if (this.debugFilter_) { - Blockly.utils.dom.removeNode(this.debugFilter_); + dom.removeNode(this.debugFilter_); } this.cssNode_ = null; }; @@ -804,11 +803,11 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { var width = this.JAGGED_TEETH_WIDTH; var mainPath = - Blockly.utils.svgPaths.line( + svgPaths.line( [ - Blockly.utils.svgPaths.point(width, height / 4), - Blockly.utils.svgPaths.point(-width * 2, height / 2), - Blockly.utils.svgPaths.point(width, height / 4) + svgPaths.point(width, height / 4), + svgPaths.point(-width * 2, height / 2), + svgPaths.point(width, height / 4) ]); return { height: height, @@ -827,11 +826,11 @@ ConstantProvider.prototype.makeStartHat = function() { var width = this.START_HAT_WIDTH; var mainPath = - Blockly.utils.svgPaths.curve('c', + svgPaths.curve('c', [ - Blockly.utils.svgPaths.point(30, -height), - Blockly.utils.svgPaths.point(70, -height), - Blockly.utils.svgPaths.point(width, 0) + svgPaths.point(30, -height), + svgPaths.point(70, -height), + svgPaths.point(width, 0) ]); return { height: height, @@ -864,18 +863,18 @@ ConstantProvider.prototype.makePuzzleTab = function() { var control2Y = halfHeight + 0.5; var control3Y = overlap; // 2.5 - var endPoint1 = Blockly.utils.svgPaths.point(-width, forward * halfHeight); - var endPoint2 = Blockly.utils.svgPaths.point(width, forward * halfHeight); + var endPoint1 = svgPaths.point(-width, forward * halfHeight); + var endPoint2 = svgPaths.point(width, forward * halfHeight); - return Blockly.utils.svgPaths.curve('c', + return svgPaths.curve('c', [ - Blockly.utils.svgPaths.point(0, forward * control1Y), - Blockly.utils.svgPaths.point(-width, back * control2Y), + svgPaths.point(0, forward * control1Y), + svgPaths.point(-width, back * control2Y), endPoint1 ]) + - Blockly.utils.svgPaths.curve('s', + svgPaths.curve('s', [ - Blockly.utils.svgPaths.point(width, back * control3Y), + svgPaths.point(width, back * control3Y), endPoint2 ]); } @@ -905,11 +904,11 @@ ConstantProvider.prototype.makeNotch = function() { var innerWidth = 3; var outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { - return Blockly.utils.svgPaths.line( + return svgPaths.line( [ - Blockly.utils.svgPaths.point(dir * outerWidth, height), - Blockly.utils.svgPaths.point(dir * innerWidth, 0), - Blockly.utils.svgPaths.point(dir * outerWidth, -height) + svgPaths.point(dir * outerWidth, height), + svgPaths.point(dir * innerWidth, 0), + svgPaths.point(dir * outerWidth, -height) ]); } var pathLeft = makeMainPath(1); @@ -932,11 +931,11 @@ ConstantProvider.prototype.makeNotch = function() { ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; - var innerTopLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point(-radius, radius)); + var innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, + svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point(radius, radius)); + var innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, + svgPaths.point(radius, radius)); return { width: radius, @@ -958,31 +957,31 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * @const */ var topLeft = - Blockly.utils.svgPaths.moveBy(0, radius) + - Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(radius, -radius)); + svgPaths.moveBy(0, radius) + + svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ var topRight = - Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(-radius, -radius)); + var bottomLeft = svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(-radius, radius)); + var bottomRight = svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(-radius, radius)); return { topLeft: topLeft, @@ -996,7 +995,7 @@ ConstantProvider.prototype.makeOutsideCorners = function() { /** * Get an object with connection shape and sizing information based on the type * of the connection. - * @param {!Blockly.RenderedConnection} connection The connection to find a + * @param {!RenderedConnection} connection The connection to find a * shape object for * @return {!Object} The shape object for the connection. * @package @@ -1004,11 +1003,11 @@ ConstantProvider.prototype.makeOutsideCorners = function() { ConstantProvider.prototype.shapeFor = function( connection) { switch (connection.type) { - case Blockly.connectionTypes.INPUT_VALUE: - case Blockly.connectionTypes.OUTPUT_VALUE: + case connectionTypes.INPUT_VALUE: + case connectionTypes.OUTPUT_VALUE: return this.PUZZLE_TAB; - case Blockly.connectionTypes.PREVIOUS_STATEMENT: - case Blockly.connectionTypes.NEXT_STATEMENT: + case connectionTypes.PREVIOUS_STATEMENT: + case connectionTypes.NEXT_STATEMENT: return this.NOTCH; default: throw Error('Unknown connection type'); @@ -1032,8 +1031,8 @@ ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - this.defs = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.DEFS, {}, svg); + this.defs = dom.createSvgElement( + Svg.DEFS, {}, svg); /* @@ -1048,14 +1047,14 @@ ConstantProvider.prototype.createDom = function(svg, k1="0" k2="1" k3="1" k4="0" /> */ - var embossFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, + var embossFilter = dom.createSvgElement( + Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEGAUSSIANBLUR, + dom.createSvgElement( + Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); - var feSpecularLighting = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FESPECULARLIGHTING, + var feSpecularLighting = dom.createSvgElement( + Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, @@ -1065,19 +1064,19 @@ ConstantProvider.prototype.createDom = function(svg, 'result': 'specOut' }, embossFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEPOINTLIGHT, + dom.createSvgElement( + Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in', 'result': 'specOut' }, embossFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'SourceGraphic', 'in2': 'specOut', @@ -1097,19 +1096,19 @@ ConstantProvider.prototype.createDom = function(svg, */ - var disabledPattern = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATTERN, + var disabledPattern = dom.createSvgElement( + Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 }, this.defs); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; @@ -1126,8 +1125,8 @@ ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { - var debugFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, { + var debugFilter = dom.createSvgElement( + Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', @@ -1136,20 +1135,20 @@ ConstantProvider.prototype.createDebugFilter = }, this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood - var debugComponentTransfer = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, + var debugComponentTransfer = dom.createSvgElement( + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEFUNCA, + dom.createSvgElement( + Svg.FEFUNCA, {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, debugComponentTransfer); // Color the highlight - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEFLOOD, + dom.createSvgElement( + Svg.FEFLOOD, {'flood-color': '#ff0000', 'flood-opacity': 0.5, 'result': 'outColor'}, debugFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, { + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'outColor', 'in2': 'outBlur', 'operator': 'in', From 96ec93f91e9f2e46295e70cd72dd712c2921afb8 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:52:42 -0700 Subject: [PATCH 282/313] Remove deconstructing properties and update logic (#5202) --- scripts/goog_module/convert-file.sh | 47 +++++++++-------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 8b6bdfc6f..f3138e9cf 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -163,6 +163,11 @@ step3() { continue fi + local require_name=$(echo "${require}" | perl -pe 's/(\w+\.)+(\w+)/\2/g') + inf "Updating require declaration for ${require}..." + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" + + # Parse property access of module local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) # Detect requires overlap @@ -181,42 +186,18 @@ step3() { fi properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) - if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then - local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - local confirm='' - while true; do - read -p "Would you like to deconstruct ${require} into \"{${deconstructed_comma}}\"? (y/n): " yn Date: Fri, 23 Jul 2021 15:00:14 -0700 Subject: [PATCH 283/313] clang-format core/renderers/common/constants.js --- core/renderers/common/constants.js | 286 ++++++++++++----------------- 1 file changed, 118 insertions(+), 168 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 4f64223d7..5fdacc2ea 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -32,7 +32,6 @@ const utils = goog.require('Blockly.utils'); * @package */ const ConstantProvider = function() { - /** * The size of an empty spacer. * @type {number} @@ -215,10 +214,10 @@ const ConstantProvider = function() { this.EXTERNAL_VALUE_INPUT_PADDING = 2; /** - * The height of an empty statement input. Note that in the old rendering this - * varies slightly depending on whether the block has external or inline inputs. - * In the new rendering this is consistent. It seems unlikely that the old - * behaviour was intentional. + * The height of an empty statement input. Note that in the old rendering + * this varies slightly depending on whether the block has external or inline + * inputs. In the new rendering this is consistent. It seems unlikely that + * the old behaviour was intentional. * @type {number} */ this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT; @@ -304,8 +303,7 @@ const ConstantProvider = function() { * A field's text element's dominant baseline. * @type {boolean} */ - this.FIELD_TEXT_BASELINE_CENTER = - !userAgent.IE && !userAgent.EDGE; + this.FIELD_TEXT_BASELINE_CENTER = !userAgent.IE && !userAgent.EDGE; /** * A dropdown field's border rect height. @@ -350,17 +348,17 @@ const ConstantProvider = function() { * @type {string} */ this.FIELD_DROPDOWN_SVG_ARROW_DATAURI = - 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' + - 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' + - 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' + - 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' + - 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' + - 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' + - 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' + - 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' + - 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' + - 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' + - 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4='; + 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' + + 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' + + 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' + + 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' + + 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' + + 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' + + 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' + + 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' + + 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' + + 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' + + 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4='; /** * Whether or not to show a box shadow around the widget div. This is only a @@ -534,10 +532,7 @@ const ConstantProvider = function() { * Enum for connection shapes. * @enum {number} */ - this.SHAPES = { - PUZZLE: 1, - NOTCH: 2 - }; + this.SHAPES = {PUZZLE: 1, NOTCH: 2}; }; /** @@ -545,7 +540,6 @@ const ConstantProvider = function() { * @package */ ConstantProvider.prototype.init = function() { - /** * An object containing sizing and path information about collapsed block * indicators. @@ -589,9 +583,7 @@ ConstantProvider.prototype.init = function() { * @param {!Theme} theme The current workspace theme. * @package */ -ConstantProvider.prototype.setTheme = function( - theme) { - +ConstantProvider.prototype.setTheme = function(theme) { /** * The block styles map. * @type {Object} @@ -612,36 +604,35 @@ ConstantProvider.prototype.setTheme = function( * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setDynamicProperties_ = - function(theme) { - /* eslint-disable indent */ +ConstantProvider.prototype.setDynamicProperties_ = function(theme) { this.setFontConstants_(theme); this.setComponentConstants_(theme); - this.ADD_START_HATS = theme.startHats != null ? theme.startHats : - this.ADD_START_HATS; -}; /* eslint-enable indent */ + this.ADD_START_HATS = + theme.startHats != null ? theme.startHats : this.ADD_START_HATS; +}; /** * Set constants related to fonts. * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setFontConstants_ = function( - theme) { +ConstantProvider.prototype.setFontConstants_ = function(theme) { this.FIELD_TEXT_FONTFAMILY = theme.fontStyle && theme.fontStyle['family'] != undefined ? - theme.fontStyle['family'] : this.FIELD_TEXT_FONTFAMILY; + theme.fontStyle['family'] : + this.FIELD_TEXT_FONTFAMILY; this.FIELD_TEXT_FONTWEIGHT = theme.fontStyle && theme.fontStyle['weight'] != undefined ? - theme.fontStyle['weight'] : this.FIELD_TEXT_FONTWEIGHT; + theme.fontStyle['weight'] : + this.FIELD_TEXT_FONTWEIGHT; this.FIELD_TEXT_FONTSIZE = theme.fontStyle && theme.fontStyle['size'] != undefined ? - theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; + theme.fontStyle['size'] : + this.FIELD_TEXT_FONTSIZE; - var fontMetrics = dom.measureFontMetrics('Hg', - this.FIELD_TEXT_FONTSIZE + 'pt', - this.FIELD_TEXT_FONTWEIGHT, + var fontMetrics = dom.measureFontMetrics( + 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); this.FIELD_TEXT_HEIGHT = fontMetrics.height; @@ -653,20 +644,18 @@ ConstantProvider.prototype.setFontConstants_ = function( * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setComponentConstants_ = - function(theme) { - /* eslint-disable indent */ - this.CURSOR_COLOUR = theme.getComponentStyle('cursorColour') || - this.CURSOR_COLOUR; - this.MARKER_COLOUR = theme.getComponentStyle('markerColour') || - this.MARKER_COLOUR; +ConstantProvider.prototype.setComponentConstants_ = function(theme) { + this.CURSOR_COLOUR = + theme.getComponentStyle('cursorColour') || this.CURSOR_COLOUR; + this.MARKER_COLOUR = + theme.getComponentStyle('markerColour') || this.MARKER_COLOUR; this.INSERTION_MARKER_COLOUR = - theme.getComponentStyle('insertionMarkerColour') || - this.INSERTION_MARKER_COLOUR; + theme.getComponentStyle('insertionMarkerColour') || + this.INSERTION_MARKER_COLOUR; this.INSERTION_MARKER_OPACITY = - Number(theme.getComponentStyle('insertionMarkerOpacity')) || - this.INSERTION_MARKER_OPACITY; -}; /* eslint-enable indent */ + Number(theme.getComponentStyle('insertionMarkerOpacity')) || + this.INSERTION_MARKER_OPACITY; +}; /** * Get or create a block style based on a single colour value. Generate a name @@ -676,15 +665,13 @@ ConstantProvider.prototype.setComponentConstants_ = * containing the style and an autogenerated name for that style. * @package */ -ConstantProvider.prototype.getBlockStyleForColour = - function(colour) { - /* eslint-disable indent */ +ConstantProvider.prototype.getBlockStyleForColour = function(colour) { var name = 'auto_' + colour; if (!this.blockStyles[name]) { this.blockStyles[name] = this.createBlockStyle_(colour); } return {style: this.blockStyles[name], name: name}; -}; /* eslint-enable indent */ +}; /** * Gets the BlockStyle for the given block style name. @@ -692,12 +679,11 @@ ConstantProvider.prototype.getBlockStyleForColour = * @return {!Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ -ConstantProvider.prototype.getBlockStyle = function( - blockStyleName) { +ConstantProvider.prototype.getBlockStyle = function(blockStyleName) { return this.blockStyles[blockStyleName || ''] || (blockStyleName && blockStyleName.indexOf('auto_') == 0 ? - this.getBlockStyleForColour(blockStyleName.substring(5)).style : - this.createBlockStyle_('#000000')); + this.getBlockStyleForColour(blockStyleName.substring(5)).style : + this.createBlockStyle_('#000000')); }; /** @@ -707,11 +693,8 @@ ConstantProvider.prototype.getBlockStyle = function( * given colour. * @protected */ -ConstantProvider.prototype.createBlockStyle_ = function( - colour) { - return this.validatedBlockStyle_({ - 'colourPrimary': colour - }); +ConstantProvider.prototype.createBlockStyle_ = function(colour) { + return this.validatedBlockStyle_({'colourPrimary': colour}); }; /** @@ -728,17 +711,14 @@ ConstantProvider.prototype.createBlockStyle_ = function( * required properties populated. * @protected */ -ConstantProvider.prototype.validatedBlockStyle_ = - function(blockStyle) { - /* eslint-disable indent */ +ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { // Make a new object with all of the same properties. var valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = utils.parseBlockColour( - valid['colourPrimary'] || '#000'); + var parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? utils.parseBlockColour(valid['colourSecondary']).hex : @@ -749,30 +729,27 @@ ConstantProvider.prototype.validatedBlockStyle_ = valid.hat = valid['hat'] || ''; return valid; -}; /* eslint-enable indent */ +}; /** * Generate a secondary colour from the passed in primary colour. - * @param {string} colour Primary colour. + * @param {string} inputColour Primary colour. * @return {string} The generated secondary colour. * @protected */ -ConstantProvider.prototype.generateSecondaryColour_ = - function(inputColour) { - /* eslint-disable indent */ - return colour.blend('#fff', inputColour, 0.6) || inputColour; -}; /* eslint-enable indent */ +ConstantProvider.prototype.generateSecondaryColour_ = function(inputColour) { + return colour.blend('#fff', inputColour, 0.6) || inputColour; +}; /** * Generate a tertiary colour from the passed in primary colour. - * @param {string} colour Primary colour. + * @param {string} inputColour Primary colour. * @return {string} The generated tertiary colour. * @protected */ ConstantProvider.prototype.generateTertiaryColour_ = function(inputColour) { - /* eslint-disable indent */ return colour.blend('#fff', inputColour, 0.3) || inputColour; -}; /* eslint-enable indent */ +}; /** @@ -802,18 +779,11 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { var height = this.JAGGED_TEETH_HEIGHT; var width = this.JAGGED_TEETH_WIDTH; - var mainPath = - svgPaths.line( - [ - svgPaths.point(width, height / 4), - svgPaths.point(-width * 2, height / 2), - svgPaths.point(width, height / 4) - ]); - return { - height: height, - width: width, - path: mainPath - }; + var mainPath = svgPaths.line([ + svgPaths.point(width, height / 4), svgPaths.point(-width * 2, height / 2), + svgPaths.point(width, height / 4) + ]); + return {height: height, width: width, path: mainPath}; }; /** @@ -825,18 +795,11 @@ ConstantProvider.prototype.makeStartHat = function() { var height = this.START_HAT_HEIGHT; var width = this.START_HAT_WIDTH; - var mainPath = - svgPaths.curve('c', - [ - svgPaths.point(30, -height), - svgPaths.point(70, -height), - svgPaths.point(width, 0) - ]); - return { - height: height, - width: width, - path: mainPath - }; + var mainPath = svgPaths.curve('c', [ + svgPaths.point(30, -height), svgPaths.point(70, -height), + svgPaths.point(width, 0) + ]); + return {height: height, width: width, path: mainPath}; }; /** @@ -866,17 +829,14 @@ ConstantProvider.prototype.makePuzzleTab = function() { var endPoint1 = svgPaths.point(-width, forward * halfHeight); var endPoint2 = svgPaths.point(width, forward * halfHeight); - return svgPaths.curve('c', - [ - svgPaths.point(0, forward * control1Y), - svgPaths.point(-width, back * control2Y), - endPoint1 - ]) + - svgPaths.curve('s', - [ - svgPaths.point(width, back * control3Y), - endPoint2 - ]); + return svgPaths.curve( + 'c', + [ + svgPaths.point(0, forward * control1Y), + svgPaths.point(-width, back * control2Y), endPoint1 + ]) + + svgPaths.curve( + 's', [svgPaths.point(width, back * control3Y), endPoint2]); } // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 @@ -904,12 +864,11 @@ ConstantProvider.prototype.makeNotch = function() { var innerWidth = 3; var outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { - return svgPaths.line( - [ - svgPaths.point(dir * outerWidth, height), - svgPaths.point(dir * innerWidth, 0), - svgPaths.point(dir * outerWidth, -height) - ]); + return svgPaths.line([ + svgPaths.point(dir * outerWidth, height), + svgPaths.point(dir * innerWidth, 0), + svgPaths.point(dir * outerWidth, -height) + ]); } var pathLeft = makeMainPath(1); var pathRight = makeMainPath(-1); @@ -931,11 +890,11 @@ ConstantProvider.prototype.makeNotch = function() { ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; - var innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, - svgPaths.point(-radius, radius)); + var innerTopLeftCorner = + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, - svgPaths.point(radius, radius)); + var innerBottomLeftCorner = + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); return { width: radius, @@ -956,32 +915,29 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * SVG path for drawing the rounded top-left corner. * @const */ - var topLeft = - svgPaths.moveBy(0, radius) + - svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(radius, -radius)); + var topLeft = svgPaths.moveBy(0, radius) + + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ var topRight = - svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(-radius, -radius)); + var bottomLeft = + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(-radius, radius)); + var bottomRight = + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); return { topLeft: topLeft, @@ -1000,8 +956,7 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * @return {!Object} The shape object for the connection. * @package */ -ConstantProvider.prototype.shapeFor = function( - connection) { +ConstantProvider.prototype.shapeFor = function(connection) { switch (connection.type) { case connectionTypes.INPUT_VALUE: case connectionTypes.OUTPUT_VALUE: @@ -1022,8 +977,7 @@ ConstantProvider.prototype.shapeFor = function( * @suppress {strictModuleDepCheck} Debug renderer only included in playground. * @package */ -ConstantProvider.prototype.createDom = function(svg, - tagName, selector) { +ConstantProvider.prototype.createDom = function(svg, tagName, selector) { this.injectCSS_(tagName, selector); /* @@ -1031,8 +985,7 @@ ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - this.defs = dom.createSvgElement( - Svg.DEFS, {}, svg); + this.defs = dom.createSvgElement(Svg.DEFS, {}, svg); /* @@ -1048,14 +1001,13 @@ ConstantProvider.prototype.createDom = function(svg, */ var embossFilter = dom.createSvgElement( - Svg.FILTER, - {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); + Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, + this.defs); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); var feSpecularLighting = dom.createSvgElement( - Svg.FESPECULARLIGHTING, - { + Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, 'specularConstant': 0.5, @@ -1065,19 +1017,18 @@ ConstantProvider.prototype.createDom = function(svg, }, embossFilter); dom.createSvgElement( - Svg.FEPOINTLIGHT, - {'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting); + Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000}, + feSpecularLighting); dom.createSvgElement( - Svg.FECOMPOSITE, - { + Svg.FECOMPOSITE, { 'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in', 'result': 'specOut' - }, embossFilter); + }, + embossFilter); dom.createSvgElement( - Svg.FECOMPOSITE, - { + Svg.FECOMPOSITE, { 'in': 'SourceGraphic', 'in2': 'specOut', 'operator': 'arithmetic', @@ -1085,7 +1036,8 @@ ConstantProvider.prototype.createDom = function(svg, 'k2': 1, 'k3': 1, 'k4': 0 - }, embossFilter); + }, + embossFilter); this.embossFilterId = embossFilter.id; this.embossFilter_ = embossFilter; @@ -1097,19 +1049,18 @@ ConstantProvider.prototype.createDom = function(svg, */ var disabledPattern = dom.createSvgElement( - Svg.PATTERN, - { + Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 - }, this.defs); + }, + this.defs); dom.createSvgElement( - Svg.RECT, - {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); + Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); dom.createSvgElement( - Svg.PATH, - {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); + Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, + disabledPattern); this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; @@ -1121,8 +1072,7 @@ ConstantProvider.prototype.createDom = function(svg, * render debugging. * @private */ -ConstantProvider.prototype.createDebugFilter = - function() { +ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { var debugFilter = dom.createSvgElement( @@ -1136,8 +1086,7 @@ ConstantProvider.prototype.createDebugFilter = this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood var debugComponentTransfer = dom.createSvgElement( - Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, - debugFilter); + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); dom.createSvgElement( Svg.FEFUNCA, {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, @@ -1166,12 +1115,11 @@ ConstantProvider.prototype.createDebugFilter = * @param {string} selector The CSS selector to use. * @protected */ -ConstantProvider.prototype.injectCSS_ = function( - tagName, selector) { +ConstantProvider.prototype.injectCSS_ = function(tagName, selector) { var cssArray = this.getCSS_(selector); var cssNodeId = 'blockly-renderer-style-' + tagName; this.cssNode_ = - /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); + /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); var text = cssArray.join('\n'); if (this.cssNode_) { // Already injected, update if the theme changed. @@ -1180,7 +1128,7 @@ ConstantProvider.prototype.injectCSS_ = function( } // Inject CSS tag at start of head. var cssNode = - /** @type {!HTMLStyleElement} */ (document.createElement('style')); + /** @type {!HTMLStyleElement} */ (document.createElement('style')); cssNode.id = cssNodeId; var cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); @@ -1197,6 +1145,7 @@ ConstantProvider.prototype.injectCSS_ = function( ConstantProvider.prototype.getCSS_ = function(selector) { return [ /* eslint-disable indent */ + /* clang-format off */ // Text. selector + ' .blocklyText, ', selector + ' .blocklyFlyoutLabelText {', @@ -1266,6 +1215,7 @@ ConstantProvider.prototype.getCSS_ = function(selector) { 'fill-opacity: ' + this.INSERTION_MARKER_OPACITY + ';', 'stroke: none;', '}', + /* clang-format on */ /* eslint-enable indent */ ]; }; From a392696c7a633f0e4d88fa2db42977ca39ce413b Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 15:07:30 -0700 Subject: [PATCH 284/313] Convert core/renderers/common/constants.js to const/let --- core/renderers/common/constants.js | 98 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 5fdacc2ea..6847aea22 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -591,8 +591,8 @@ ConstantProvider.prototype.setTheme = function(theme) { */ this.blockStyles = Object.create(null); - var blockStyles = theme.blockStyles; - for (var key in blockStyles) { + const blockStyles = theme.blockStyles; + for (const key in blockStyles) { this.blockStyles[key] = this.validatedBlockStyle_(blockStyles[key]); } @@ -631,7 +631,7 @@ ConstantProvider.prototype.setFontConstants_ = function(theme) { theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; - var fontMetrics = dom.measureFontMetrics( + const fontMetrics = dom.measureFontMetrics( 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); @@ -666,7 +666,7 @@ ConstantProvider.prototype.setComponentConstants_ = function(theme) { * @package */ ConstantProvider.prototype.getBlockStyleForColour = function(colour) { - var name = 'auto_' + colour; + const name = 'auto_' + colour; if (!this.blockStyles[name]) { this.blockStyles[name] = this.createBlockStyle_(colour); } @@ -713,12 +713,12 @@ ConstantProvider.prototype.createBlockStyle_ = function(colour) { */ ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { // Make a new object with all of the same properties. - var valid = /** @type {!Theme.BlockStyle} */ ({}); + const valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); + const parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? utils.parseBlockColour(valid['colourSecondary']).hex : @@ -776,10 +776,10 @@ ConstantProvider.prototype.dispose = function() { * @package */ ConstantProvider.prototype.makeJaggedTeeth = function() { - var height = this.JAGGED_TEETH_HEIGHT; - var width = this.JAGGED_TEETH_WIDTH; + const height = this.JAGGED_TEETH_HEIGHT; + const width = this.JAGGED_TEETH_WIDTH; - var mainPath = svgPaths.line([ + const mainPath = svgPaths.line([ svgPaths.point(width, height / 4), svgPaths.point(-width * 2, height / 2), svgPaths.point(width, height / 4) ]); @@ -792,10 +792,10 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { * @package */ ConstantProvider.prototype.makeStartHat = function() { - var height = this.START_HAT_HEIGHT; - var width = this.START_HAT_WIDTH; + const height = this.START_HAT_HEIGHT; + const width = this.START_HAT_WIDTH; - var mainPath = svgPaths.curve('c', [ + const mainPath = svgPaths.curve('c', [ svgPaths.point(30, -height), svgPaths.point(70, -height), svgPaths.point(width, 0) ]); @@ -808,8 +808,8 @@ ConstantProvider.prototype.makeStartHat = function() { * @package */ ConstantProvider.prototype.makePuzzleTab = function() { - var width = this.TAB_WIDTH; - var height = this.TAB_HEIGHT; + const width = this.TAB_WIDTH; + const height = this.TAB_HEIGHT; // The main path for the puzzle tab is made out of a few curves (c and s). // Those curves are defined with relative positions. The 'up' and 'down' @@ -817,17 +817,17 @@ ConstantProvider.prototype.makePuzzleTab = function() { // are the signs to use to move the cursor in the direction that the path is // being drawn. function makeMainPath(up) { - var forward = up ? -1 : 1; - var back = -forward; + const forward = up ? -1 : 1; + const back = -forward; - var overlap = 2.5; - var halfHeight = height / 2; - var control1Y = halfHeight + overlap; - var control2Y = halfHeight + 0.5; - var control3Y = overlap; // 2.5 + const overlap = 2.5; + const halfHeight = height / 2; + const control1Y = halfHeight + overlap; + const control2Y = halfHeight + 0.5; + const control3Y = overlap; // 2.5 - var endPoint1 = svgPaths.point(-width, forward * halfHeight); - var endPoint2 = svgPaths.point(width, forward * halfHeight); + const endPoint1 = svgPaths.point(-width, forward * halfHeight); + const endPoint2 = svgPaths.point(width, forward * halfHeight); return svgPaths.curve( 'c', @@ -840,9 +840,9 @@ ConstantProvider.prototype.makePuzzleTab = function() { } // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 - var pathUp = makeMainPath(true); + const pathUp = makeMainPath(true); // c 0,10 -8,-8 -8,7.5 s 8,-2.5 8,7.5 - var pathDown = makeMainPath(false); + const pathDown = makeMainPath(false); return { type: this.SHAPES.PUZZLE, @@ -859,10 +859,10 @@ ConstantProvider.prototype.makePuzzleTab = function() { * @package */ ConstantProvider.prototype.makeNotch = function() { - var width = this.NOTCH_WIDTH; - var height = this.NOTCH_HEIGHT; - var innerWidth = 3; - var outerWidth = (width - innerWidth) / 2; + const width = this.NOTCH_WIDTH; + const height = this.NOTCH_HEIGHT; + const innerWidth = 3; + const outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { return svgPaths.line([ svgPaths.point(dir * outerWidth, height), @@ -870,8 +870,8 @@ ConstantProvider.prototype.makeNotch = function() { svgPaths.point(dir * outerWidth, -height) ]); } - var pathLeft = makeMainPath(1); - var pathRight = makeMainPath(-1); + const pathLeft = makeMainPath(1); + const pathRight = makeMainPath(-1); return { type: this.SHAPES.NOTCH, @@ -888,12 +888,12 @@ ConstantProvider.prototype.makeNotch = function() { * @package */ ConstantProvider.prototype.makeInsideCorners = function() { - var radius = this.CORNER_RADIUS; + const radius = this.CORNER_RADIUS; - var innerTopLeftCorner = + const innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = + const innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); return { @@ -910,33 +910,33 @@ ConstantProvider.prototype.makeInsideCorners = function() { * @package */ ConstantProvider.prototype.makeOutsideCorners = function() { - var radius = this.CORNER_RADIUS; + const radius = this.CORNER_RADIUS; /** * SVG path for drawing the rounded top-left corner. * @const */ - var topLeft = svgPaths.moveBy(0, radius) + + const topLeft = svgPaths.moveBy(0, radius) + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ - var topRight = + const topRight = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = + const bottomLeft = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = + const bottomRight = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); return { @@ -1000,13 +1000,13 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { k1="0" k2="1" k3="1" k4="0" /> */ - var embossFilter = dom.createSvgElement( + const embossFilter = dom.createSvgElement( Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); - var feSpecularLighting = dom.createSvgElement( + const feSpecularLighting = dom.createSvgElement( Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, @@ -1048,7 +1048,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { */ - var disabledPattern = dom.createSvgElement( + const disabledPattern = dom.createSvgElement( Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', @@ -1075,7 +1075,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { - var debugFilter = dom.createSvgElement( + const debugFilter = dom.createSvgElement( Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', @@ -1085,7 +1085,7 @@ ConstantProvider.prototype.createDebugFilter = function() { }, this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood - var debugComponentTransfer = dom.createSvgElement( + const debugComponentTransfer = dom.createSvgElement( Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); dom.createSvgElement( Svg.FEFUNCA, @@ -1116,21 +1116,21 @@ ConstantProvider.prototype.createDebugFilter = function() { * @protected */ ConstantProvider.prototype.injectCSS_ = function(tagName, selector) { - var cssArray = this.getCSS_(selector); - var cssNodeId = 'blockly-renderer-style-' + tagName; + const cssArray = this.getCSS_(selector); + const cssNodeId = 'blockly-renderer-style-' + tagName; this.cssNode_ = /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); - var text = cssArray.join('\n'); + const text = cssArray.join('\n'); if (this.cssNode_) { // Already injected, update if the theme changed. this.cssNode_.firstChild.textContent = text; return; } // Inject CSS tag at start of head. - var cssNode = + const cssNode = /** @type {!HTMLStyleElement} */ (document.createElement('style')); cssNode.id = cssNodeId; - var cssTextNode = document.createTextNode(text); + const cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); document.head.insertBefore(cssNode, document.head.firstChild); this.cssNode_ = cssNode; From 1dfee3a722a6f542700a5d980440e6c091418bcd Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 16:39:40 -0700 Subject: [PATCH 285/313] Make defs private and add nullability --- core/renderers/common/constants.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 6847aea22..5e5ecb747 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -403,10 +403,10 @@ const ConstantProvider = function() { /** * The defs tag that contains all filters and patterns for this Blockly * instance. - * @type {SVGElement} + * @type {?SVGElement} * @private */ - this.defs = null; + this.defs_ = null; /** * The ID of the emboss filter, or the empty string if no filter is set. @@ -985,7 +985,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { ... filters go here ... */ - this.defs = dom.createSvgElement(Svg.DEFS, {}, svg); + this.defs_ = dom.createSvgElement(Svg.DEFS, {}, svg); /* @@ -1002,7 +1002,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { */ const embossFilter = dom.createSvgElement( Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, - this.defs); + this.defs_); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); @@ -1055,7 +1055,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { 'width': 10, 'height': 10 }, - this.defs); + this.defs_); dom.createSvgElement( Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); dom.createSvgElement( @@ -1083,7 +1083,7 @@ ConstantProvider.prototype.createDebugFilter = function() { y: '-30%', x: '-40%' }, - this.defs); + this.defs_); // Set all gaussian blur pixels to 1 opacity before applying flood const debugComponentTransfer = dom.createSvgElement( Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); From 1360b5bb49fa460f7ccaf1ba37fa56999b0b95b1 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Fri, 23 Jul 2021 18:10:38 -0700 Subject: [PATCH 286/313] Apply fixes for convert-file script (#5206) --- scripts/goog_module/convert-file.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index f3138e9cf..6a8d36cd0 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -190,20 +190,27 @@ step3() { local comma_properties=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') inf "Detected references of ${require}: ${comma_properties}" - for require_prop in echo "${properties_accessed}"; do + for require_prop in $(echo "${properties_accessed}"); do inf "Updating references of ${require}.${require_prop} to ${require_name}.${require_prop}..." - perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_name}"'\.'"${require_prop}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'\.'"${require_prop}"'(?!\w)/'"${require_name}"'\.'"${require_prop}"'/g' "${filepath}" done fi inf "Updating direct references of ${require} to ${require_name}..." - perl -pi -e 's/'"${require}"'([^'\''\w]\.)/'"${require_name}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'(?!['\''\w\.])/'"${require_name}"'/g' "${filepath}" done local missing_requires=$(perl -nle'print $& while m{(? Date: Wed, 21 Jul 2021 15:32:39 -0700 Subject: [PATCH 287/313] Migrate core/field_label.js to ES6 const/let --- core/field_label.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label.js b/core/field_label.js index 5dc434c92..4a19dc07e 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -64,7 +64,7 @@ Blockly.FieldLabel.prototype.DEFAULT_VALUE = ''; * @nocollapse */ Blockly.FieldLabel.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. return new this(text, undefined, options); From a765a3016e4f9cc341f0b5696be548a5f0e6acfa Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:32:52 -0700 Subject: [PATCH 288/313] Migrate core/field_label.js to goog.module --- core/field_label.js | 31 +++++++++++++++++-------------- tests/deps.js | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index 4a19dc07e..4c15d4f96 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldLabel'); +goog.module('Blockly.FieldLabel'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Field'); goog.require('Blockly.fieldRegistry'); @@ -31,7 +32,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldLabel = function(opt_value, opt_class, opt_config) { +const FieldLabel = function(opt_value, opt_class, opt_config) { /** * The html class name to use for this field. * @type {?string} @@ -39,31 +40,31 @@ Blockly.FieldLabel = function(opt_value, opt_class, opt_config) { */ this.class_ = null; - Blockly.FieldLabel.superClass_.constructor.call( + FieldLabel.superClass_.constructor.call( this, opt_value, null, opt_config); if (!opt_config) { // If the config was not passed use old configuration. this.class_ = opt_class || null; } }; -Blockly.utils.object.inherits(Blockly.FieldLabel, Blockly.Field); +Blockly.utils.object.inherits(FieldLabel, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldLabel.prototype.DEFAULT_VALUE = ''; +FieldLabel.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldLabel from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and class). - * @return {!Blockly.FieldLabel} The new field instance. + * @return {!FieldLabel} The new field instance. * @package * @nocollapse */ -Blockly.FieldLabel.fromJson = function(options) { +FieldLabel.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. @@ -75,13 +76,13 @@ Blockly.FieldLabel.fromJson = function(options) { * editable. This field should not. * @type {boolean} */ -Blockly.FieldLabel.prototype.EDITABLE = false; +FieldLabel.prototype.EDITABLE = false; /** * @override */ -Blockly.FieldLabel.prototype.configure_ = function(config) { - Blockly.FieldLabel.superClass_.configure_.call(this, config); +FieldLabel.prototype.configure_ = function(config) { + FieldLabel.superClass_.configure_.call(this, config); this.class_ = config['class']; }; @@ -89,7 +90,7 @@ Blockly.FieldLabel.prototype.configure_ = function(config) { * Create block UI for this label. * @package */ -Blockly.FieldLabel.prototype.initView = function() { +FieldLabel.prototype.initView = function() { this.createTextElement_(); if (this.class_) { Blockly.utils.dom.addClass( @@ -103,7 +104,7 @@ Blockly.FieldLabel.prototype.initView = function() { * @return {?string} A valid string, or null if invalid. * @protected */ -Blockly.FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { +FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -114,7 +115,7 @@ Blockly.FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { * Set the CSS class applied to the field's textElement_. * @param {?string} cssClass The new CSS class name, or null to remove. */ -Blockly.FieldLabel.prototype.setClass = function(cssClass) { +FieldLabel.prototype.setClass = function(cssClass) { if (this.textElement_) { // This check isn't necessary, but it's faster than letting removeClass // figure it out. @@ -128,4 +129,6 @@ Blockly.FieldLabel.prototype.setClass = function(cssClass) { this.class_ = cssClass; }; -Blockly.fieldRegistry.register('field_label', Blockly.FieldLabel); +Blockly.fieldRegistry.register('field_label', FieldLabel); + +exports = FieldLabel; diff --git a/tests/deps.js b/tests/deps.js index 3dc163ac5..9b2ca48af 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -54,7 +54,7 @@ goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], [' goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From 4945825d6edeeed9728751cd27755dbe341c5ff5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:33:37 -0700 Subject: [PATCH 289/313] Migrate core/field_label.js named requires --- core/field_label.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index 4c15d4f96..c6f1bbcd8 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -14,11 +14,11 @@ goog.module('Blockly.FieldLabel'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); +const Field = goog.require('Blockly.Field'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const dom = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -29,7 +29,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldLabel = function(opt_value, opt_class, opt_config) { @@ -47,7 +47,7 @@ const FieldLabel = function(opt_value, opt_class, opt_config) { this.class_ = opt_class || null; } }; -Blockly.utils.object.inherits(FieldLabel, Blockly.Field); +inherits(FieldLabel, Field); /** * The default value for this field. @@ -65,7 +65,7 @@ FieldLabel.prototype.DEFAULT_VALUE = ''; * @nocollapse */ FieldLabel.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -93,7 +93,7 @@ FieldLabel.prototype.configure_ = function(config) { FieldLabel.prototype.initView = function() { this.createTextElement_(); if (this.class_) { - Blockly.utils.dom.addClass( + dom.addClass( /** @type {!SVGTextElement} */ (this.textElement_), this.class_); } }; @@ -120,15 +120,15 @@ FieldLabel.prototype.setClass = function(cssClass) { // This check isn't necessary, but it's faster than letting removeClass // figure it out. if (this.class_) { - Blockly.utils.dom.removeClass(this.textElement_, this.class_); + dom.removeClass(this.textElement_, this.class_); } if (cssClass) { - Blockly.utils.dom.addClass(this.textElement_, cssClass); + dom.addClass(this.textElement_, cssClass); } } this.class_ = cssClass; }; -Blockly.fieldRegistry.register('field_label', FieldLabel); +fieldRegistry.register('field_label', FieldLabel); exports = FieldLabel; From 0889defe55645de721ba84e56e2e26c4d1baf1ad Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:22:33 -0700 Subject: [PATCH 290/313] clang-format core/field_label.js --- core/field_label.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index c6f1bbcd8..8d23bbb18 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -27,7 +27,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * string. Defaults to an empty string if null or undefined. * @param {string=} opt_class Optional CSS class for the field's text. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -40,8 +41,7 @@ const FieldLabel = function(opt_value, opt_class, opt_config) { */ this.class_ = null; - FieldLabel.superClass_.constructor.call( - this, opt_value, null, opt_config); + FieldLabel.superClass_.constructor.call(this, opt_value, null, opt_config); if (!opt_config) { // If the config was not passed use old configuration. this.class_ = opt_class || null; From e997330085edd26b57dd254ae4622bb6186c4d40 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:24:42 -0700 Subject: [PATCH 291/313] Fix require order in core/field_label.js --- core/field_label.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label.js b/core/field_label.js index 8d23bbb18..822d476ab 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -15,8 +15,8 @@ goog.module('Blockly.FieldLabel'); goog.module.declareLegacyNamespace(); const Field = goog.require('Blockly.Field'); -const fieldRegistry = goog.require('Blockly.fieldRegistry'); const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); const {inherits} = goog.require('Blockly.utils.object'); const {replaceMessageReferences} = goog.require('Blockly.utils'); From 71e187adc9af78b56c171ebaf46c8d7926172a28 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 17:59:35 -0700 Subject: [PATCH 292/313] Migrate core/gesture.js to ES6 const/let --- core/gesture.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index 483d73a25..59dbd57f0 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -266,8 +266,8 @@ Blockly.Gesture.prototype.dispose = function() { * @private */ Blockly.Gesture.prototype.updateFromEvent_ = function(e) { - var currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); - var changed = this.updateDragDelta_(currentXY); + const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. if (changed) { this.updateIsDragging_(); @@ -290,11 +290,11 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { - var currentDragDelta = + const currentDragDelta = Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - var limitRadius = this.flyout_ ? + const limitRadius = this.flyout_ ? Blockly.internalConstants.FLYOUT_DRAG_RADIUS : Blockly.internalConstants.DRAG_RADIUS; @@ -394,7 +394,7 @@ Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { * @private */ Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { - var wsMovable = this.flyout_ ? + const wsMovable = this.flyout_ ? this.flyout_.isScrollable() : this.startWorkspace_ && this.startWorkspace_.isDraggable(); @@ -439,8 +439,9 @@ Blockly.Gesture.prototype.updateIsDragging_ = function() { * @private */ Blockly.Gesture.prototype.startDraggingBlock_ = function() { - var BlockDraggerClass = Blockly.registry.getClassFromOptions( - Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); + const BlockDraggerClass = Blockly.registry.getClassFromOptions( + Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, + true); this.blockDragger_ = new BlockDraggerClass( /** @type {!Blockly.BlockSvg} */ (this.targetBlock_), @@ -747,12 +748,12 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); } - var newBlock = this.flyout_.createBlock(this.targetBlock_); + const newBlock = this.flyout_.createBlock(this.targetBlock_); newBlock.scheduleSnapAndBump(); } } else { // Clicks events are on the start block, even if it was a shadow. - var event = new (Blockly.Events.get(Blockly.Events.CLICK))( + const event = new (Blockly.Events.get(Blockly.Events.CLICK))( this.startBlock_, this.startWorkspace_.id, 'block'); Blockly.Events.fire(event); } @@ -767,7 +768,7 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { * @private */ Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { - var ws = this.creatorWorkspace_; + const ws = this.creatorWorkspace_; if (Blockly.selected) { Blockly.selected.unselect(); } @@ -888,7 +889,7 @@ Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { */ Blockly.Gesture.prototype.isBubbleClick_ = function() { // A bubble click starts on a bubble and never escapes the drag radius. - var hasStartBubble = !!this.startBubble_; + const hasStartBubble = !!this.startBubble_; return hasStartBubble && !this.hasExceededDragRadius_; }; @@ -901,7 +902,7 @@ Blockly.Gesture.prototype.isBubbleClick_ = function() { Blockly.Gesture.prototype.isBlockClick_ = function() { // A block click starts on a block, never escapes the drag radius, and is not // a field click. - var hasStartBlock = !!this.startBlock_; + const hasStartBlock = !!this.startBlock_; return hasStartBlock && !this.hasExceededDragRadius_ && !this.isFieldClick_(); }; @@ -912,7 +913,7 @@ Blockly.Gesture.prototype.isBlockClick_ = function() { * @private */ Blockly.Gesture.prototype.isFieldClick_ = function() { - var fieldClickable = + const fieldClickable = this.startField_ ? this.startField_.isClickable() : false; return fieldClickable && !this.hasExceededDragRadius_ && (!this.flyout_ || !this.flyout_.autoClose); @@ -925,7 +926,7 @@ Blockly.Gesture.prototype.isFieldClick_ = function() { * @private */ Blockly.Gesture.prototype.isWorkspaceClick_ = function() { - var onlyTouchedWorkspace = + const onlyTouchedWorkspace = !this.startBlock_ && !this.startBubble_ && !this.startField_; return onlyTouchedWorkspace && !this.hasExceededDragRadius_; }; @@ -991,8 +992,8 @@ Blockly.Gesture.prototype.getCurrentDragger = function() { * @return {boolean} True if gesture is occurring. */ Blockly.Gesture.inProgress = function() { - var workspaces = Blockly.Workspace.getAll(); - for (var i = 0, workspace; (workspace = workspaces[i]); i++) { + const workspaces = Blockly.Workspace.getAll(); + for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { return true; } From 1d847eda4a847ad0ac77326db8a79cbd7d2e3893 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:45:51 -0700 Subject: [PATCH 293/313] Migrate core/gesture.js to goog.module --- core/gesture.js | 90 ++++++++++++++++++++++++++----------------------- tests/deps.js | 2 +- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index 59dbd57f0..a5b786b5b 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Gesture'); +goog.module('Blockly.Gesture'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockAnimations'); /** @suppress {extraRequire} */ @@ -22,6 +23,7 @@ goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); goog.require('Blockly.internalConstants'); +goog.require('Blockly.registry'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); @@ -50,7 +52,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * this gesture and has a reference to it. * @constructor */ -Blockly.Gesture = function(e, creatorWorkspace) { +const Gesture = function(e, creatorWorkspace) { /** * The position of the mouse when the gesture started. Units are CSS pixels, * with (0, 0) at the top left of the browser window (mouseEvent clientX/Y). @@ -236,7 +238,7 @@ Blockly.Gesture = function(e, creatorWorkspace) { * Sever all links from this object. * @package */ -Blockly.Gesture.prototype.dispose = function() { +Gesture.prototype.dispose = function() { Blockly.Touch.clearTouchIdentifier(); Blockly.Tooltip.unblock(); // Clear the owner's reference to this gesture. @@ -265,7 +267,7 @@ Blockly.Gesture.prototype.dispose = function() { * @param {!Event} e The most recent mouse or touch event. * @private */ -Blockly.Gesture.prototype.updateFromEvent_ = function(e) { +Gesture.prototype.updateFromEvent_ = function(e) { const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. @@ -284,7 +286,7 @@ Blockly.Gesture.prototype.updateFromEvent_ = function(e) { * first time. * @private */ -Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { +Gesture.prototype.updateDragDelta_ = function(currentXY) { this.currentDragDeltaXY_ = Blockly.utils.Coordinate.difference( currentXY, /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); @@ -314,7 +316,7 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { * @return {boolean} True if a block is being dragged from the flyout. * @private */ -Blockly.Gesture.prototype.updateIsDraggingFromFlyout_ = function() { +Gesture.prototype.updateIsDraggingFromFlyout_ = function() { if (!this.targetBlock_) { return false; } @@ -348,7 +350,7 @@ Blockly.Gesture.prototype.updateIsDraggingFromFlyout_ = function() { * @return {boolean} True if a bubble is being dragged. * @private */ -Blockly.Gesture.prototype.updateIsDraggingBubble_ = function() { +Gesture.prototype.updateIsDraggingBubble_ = function() { if (!this.startBubble_) { return false; } @@ -367,7 +369,7 @@ Blockly.Gesture.prototype.updateIsDraggingBubble_ = function() { * @return {boolean} True if a block is being dragged. * @private */ -Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { +Gesture.prototype.updateIsDraggingBlock_ = function() { if (!this.targetBlock_) { return false; } @@ -393,7 +395,7 @@ Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { * WorkspaceDragger and starts the drag. * @private */ -Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { +Gesture.prototype.updateIsDraggingWorkspace_ = function() { const wsMovable = this.flyout_ ? this.flyout_.isScrollable() : this.startWorkspace_ && this.startWorkspace_.isDraggable(); @@ -415,7 +417,7 @@ Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { * drag radius is exceeded. It should be called no more than once per gesture. * @private */ -Blockly.Gesture.prototype.updateIsDragging_ = function() { +Gesture.prototype.updateIsDragging_ = function() { // Sanity check. if (this.calledUpdateIsDragging_) { throw Error('updateIsDragging_ should only be called once per gesture.'); @@ -438,7 +440,7 @@ Blockly.Gesture.prototype.updateIsDragging_ = function() { * Create a block dragger and start dragging the selected block. * @private */ -Blockly.Gesture.prototype.startDraggingBlock_ = function() { +Gesture.prototype.startDraggingBlock_ = function() { const BlockDraggerClass = Blockly.registry.getClassFromOptions( Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); @@ -455,7 +457,7 @@ Blockly.Gesture.prototype.startDraggingBlock_ = function() { * @private */ // TODO (fenichel): Possibly combine this and startDraggingBlock_. -Blockly.Gesture.prototype.startDraggingBubble_ = function() { +Gesture.prototype.startDraggingBubble_ = function() { this.bubbleDragger_ = new Blockly.BubbleDragger( /** @type {!Blockly.IBubble} */ (this.startBubble_), /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); @@ -469,7 +471,7 @@ Blockly.Gesture.prototype.startDraggingBubble_ = function() { * @param {!Event} e A mouse down or touch start event. * @package */ -Blockly.Gesture.prototype.doStart = function(e) { +Gesture.prototype.doStart = function(e) { if (Blockly.utils.isTargetInput(e)) { this.cancel(); return; @@ -519,7 +521,7 @@ Blockly.Gesture.prototype.doStart = function(e) { * @param {!Event} e A mouse down or touch start event. * @package */ -Blockly.Gesture.prototype.bindMouseEvents = function(e) { +Gesture.prototype.bindMouseEvents = function(e) { this.onMoveWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mousemove', null, this.handleMove.bind(this)); this.onUpWrapper_ = Blockly.browserEvents.conditionalBind( @@ -534,7 +536,7 @@ Blockly.Gesture.prototype.bindMouseEvents = function(e) { * @param {!Event} e A mouse move or touch move event. * @package */ -Blockly.Gesture.prototype.handleMove = function(e) { +Gesture.prototype.handleMove = function(e) { this.updateFromEvent_(e); if (this.isDraggingWorkspace_) { this.workspaceDragger_.drag(this.currentDragDeltaXY_); @@ -554,7 +556,7 @@ Blockly.Gesture.prototype.handleMove = function(e) { * @param {!Event} e A mouse up or touch end event. * @package */ -Blockly.Gesture.prototype.handleUp = function(e) { +Gesture.prototype.handleUp = function(e) { this.updateFromEvent_(e); Blockly.longStop_(); @@ -596,7 +598,7 @@ Blockly.Gesture.prototype.handleUp = function(e) { * end the drag at the most recent location. * @package */ -Blockly.Gesture.prototype.cancel = function() { +Gesture.prototype.cancel = function() { // Disposing of a block cancels in-progress drags, but dragging to a delete // area disposes of a block and leads to recursive disposal. Break that cycle. if (this.isEnding_) { @@ -620,7 +622,7 @@ Blockly.Gesture.prototype.cancel = function() { * @param {!Event} e A mouse move or touch move event. * @package */ -Blockly.Gesture.prototype.handleRightClick = function(e) { +Gesture.prototype.handleRightClick = function(e) { if (this.targetBlock_) { this.bringBlockToFront_(); Blockly.hideChaff(!!this.flyout_); @@ -645,7 +647,7 @@ Blockly.Gesture.prototype.handleRightClick = function(e) { * @param {!Blockly.WorkspaceSvg} ws The workspace the event hit. * @package */ -Blockly.Gesture.prototype.handleWsStart = function(e, ws) { +Gesture.prototype.handleWsStart = function(e, ws) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleWsStart, ' + @@ -661,7 +663,7 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { * @param {!Blockly.WorkspaceSvg} ws The workspace that a user clicks on. * @private */ -Blockly.Gesture.prototype.fireWorkspaceClick_ = function(ws) { +Gesture.prototype.fireWorkspaceClick_ = function(ws) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CLICK))( null, ws.id, 'workspace')); }; @@ -672,7 +674,7 @@ Blockly.Gesture.prototype.fireWorkspaceClick_ = function(ws) { * @param {!Blockly.IFlyout} flyout The flyout the event hit. * @package */ -Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { +Gesture.prototype.handleFlyoutStart = function(e, flyout) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleFlyoutStart, ' + @@ -688,7 +690,7 @@ Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { * @param {!Blockly.BlockSvg} block The block the event hit. * @package */ -Blockly.Gesture.prototype.handleBlockStart = function(e, block) { +Gesture.prototype.handleBlockStart = function(e, block) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleBlockStart, ' + @@ -704,7 +706,7 @@ Blockly.Gesture.prototype.handleBlockStart = function(e, block) { * @param {!Blockly.IBubble} bubble The bubble the event hit. * @package */ -Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) { +Gesture.prototype.handleBubbleStart = function(e, bubble) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleBubbleStart, ' + @@ -722,7 +724,7 @@ Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) { * Execute a bubble click. * @private */ -Blockly.Gesture.prototype.doBubbleClick_ = function() { +Gesture.prototype.doBubbleClick_ = function() { // TODO (#1673): Consistent handling of single clicks. this.startBubble_.setFocus && this.startBubble_.setFocus(); this.startBubble_.select && this.startBubble_.select(); @@ -732,7 +734,7 @@ Blockly.Gesture.prototype.doBubbleClick_ = function() { * Execute a field click. * @private */ -Blockly.Gesture.prototype.doFieldClick_ = function() { +Gesture.prototype.doFieldClick_ = function() { this.startField_.showEditor(this.mostRecentEvent_); this.bringBlockToFront_(); }; @@ -741,7 +743,7 @@ Blockly.Gesture.prototype.doFieldClick_ = function() { * Execute a block click. * @private */ -Blockly.Gesture.prototype.doBlockClick_ = function() { +Gesture.prototype.doBlockClick_ = function() { // Block click in an autoclosing flyout. if (this.flyout_ && this.flyout_.autoClose) { if (this.targetBlock_.isEnabled()) { @@ -767,7 +769,7 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { * @param {!Event} _e A mouse up or touch end event. * @private */ -Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { +Gesture.prototype.doWorkspaceClick_ = function(_e) { const ws = this.creatorWorkspace_; if (Blockly.selected) { Blockly.selected.unselect(); @@ -784,7 +786,7 @@ Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { * not occluded by other blocks. * @private */ -Blockly.Gesture.prototype.bringBlockToFront_ = function() { +Gesture.prototype.bringBlockToFront_ = function() { // Blocks in the flyout don't overlap, so skip the work. if (this.targetBlock_ && !this.flyout_) { this.targetBlock_.bringToFront(); @@ -798,7 +800,7 @@ Blockly.Gesture.prototype.bringBlockToFront_ = function() { * @param {Blockly.Field} field The field the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartField = function(field) { +Gesture.prototype.setStartField = function(field) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.setStartField, ' + @@ -814,7 +816,7 @@ Blockly.Gesture.prototype.setStartField = function(field) { * @param {Blockly.IBubble} bubble The bubble the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartBubble = function(bubble) { +Gesture.prototype.setStartBubble = function(bubble) { if (!this.startBubble_) { this.startBubble_ = bubble; } @@ -826,7 +828,7 @@ Blockly.Gesture.prototype.setStartBubble = function(bubble) { * @param {Blockly.BlockSvg} block The block the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartBlock = function(block) { +Gesture.prototype.setStartBlock = function(block) { // If the gesture already went through a bubble, don't set the start block. if (!this.startBlock_ && !this.startBubble_) { this.startBlock_ = block; @@ -845,7 +847,7 @@ Blockly.Gesture.prototype.setStartBlock = function(block) { * @param {Blockly.BlockSvg} block The block the gesture targets. * @private */ -Blockly.Gesture.prototype.setTargetBlock_ = function(block) { +Gesture.prototype.setTargetBlock_ = function(block) { if (block.isShadow()) { this.setTargetBlock_(block.getParent()); } else { @@ -858,7 +860,7 @@ Blockly.Gesture.prototype.setTargetBlock_ = function(block) { * @param {Blockly.WorkspaceSvg} ws The workspace the gesture started on. * @private */ -Blockly.Gesture.prototype.setStartWorkspace_ = function(ws) { +Gesture.prototype.setStartWorkspace_ = function(ws) { if (!this.startWorkspace_) { this.startWorkspace_ = ws; } @@ -869,7 +871,7 @@ Blockly.Gesture.prototype.setStartWorkspace_ = function(ws) { * @param {Blockly.IFlyout} flyout The flyout the gesture started on. * @private */ -Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { +Gesture.prototype.setStartFlyout_ = function(flyout) { if (!this.flyout_) { this.flyout_ = flyout; } @@ -887,7 +889,7 @@ Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { * @return {boolean} Whether this gesture was a click on a bubble. * @private */ -Blockly.Gesture.prototype.isBubbleClick_ = function() { +Gesture.prototype.isBubbleClick_ = function() { // A bubble click starts on a bubble and never escapes the drag radius. const hasStartBubble = !!this.startBubble_; return hasStartBubble && !this.hasExceededDragRadius_; @@ -899,7 +901,7 @@ Blockly.Gesture.prototype.isBubbleClick_ = function() { * @return {boolean} Whether this gesture was a click on a block. * @private */ -Blockly.Gesture.prototype.isBlockClick_ = function() { +Gesture.prototype.isBlockClick_ = function() { // A block click starts on a block, never escapes the drag radius, and is not // a field click. const hasStartBlock = !!this.startBlock_; @@ -912,7 +914,7 @@ Blockly.Gesture.prototype.isBlockClick_ = function() { * @return {boolean} Whether this gesture was a click on a field. * @private */ -Blockly.Gesture.prototype.isFieldClick_ = function() { +Gesture.prototype.isFieldClick_ = function() { const fieldClickable = this.startField_ ? this.startField_.isClickable() : false; return fieldClickable && !this.hasExceededDragRadius_ && @@ -925,7 +927,7 @@ Blockly.Gesture.prototype.isFieldClick_ = function() { * @return {boolean} Whether this gesture was a click on a workspace. * @private */ -Blockly.Gesture.prototype.isWorkspaceClick_ = function() { +Gesture.prototype.isWorkspaceClick_ = function() { const onlyTouchedWorkspace = !this.startBlock_ && !this.startBubble_ && !this.startField_; return onlyTouchedWorkspace && !this.hasExceededDragRadius_; @@ -940,7 +942,7 @@ Blockly.Gesture.prototype.isWorkspaceClick_ = function() { * @return {boolean} True if this gesture is a drag of a workspace or block. * @package */ -Blockly.Gesture.prototype.isDragging = function() { +Gesture.prototype.isDragging = function() { return this.isDraggingWorkspace_ || this.isDraggingBlock_ || this.isDraggingBubble_; }; @@ -952,7 +954,7 @@ Blockly.Gesture.prototype.isDragging = function() { * @return {boolean} Whether this gesture was a click on a workspace. * @package */ -Blockly.Gesture.prototype.hasStarted = function() { +Gesture.prototype.hasStarted = function() { return this.hasStarted_; }; @@ -963,7 +965,7 @@ Blockly.Gesture.prototype.hasStarted = function() { * marker blocks. * @package */ -Blockly.Gesture.prototype.getInsertionMarkers = function() { +Gesture.prototype.getInsertionMarkers = function() { if (this.blockDragger_) { return this.blockDragger_.getInsertionMarkers(); } @@ -976,7 +978,7 @@ Blockly.Gesture.prototype.getInsertionMarkers = function() { * @return {!Blockly.WorkspaceDragger|!Blockly.BubbleDragger|!Blockly.IBlockDragger|null} * The dragger that is currently in use or null if no drag is in progress. */ -Blockly.Gesture.prototype.getCurrentDragger = function() { +Gesture.prototype.getCurrentDragger = function() { if (this.isDraggingBlock_) { return this.blockDragger_; } else if (this.isDraggingWorkspace_) { @@ -991,7 +993,7 @@ Blockly.Gesture.prototype.getCurrentDragger = function() { * Is a drag or other gesture currently in progress on any workspace? * @return {boolean} True if gesture is occurring. */ -Blockly.Gesture.inProgress = function() { +Gesture.inProgress = function() { const workspaces = Blockly.Workspace.getAll(); for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { @@ -1000,3 +1002,5 @@ Blockly.Gesture.inProgress = function() { } return false; }; + +exports = Gesture; diff --git a/tests/deps.js b/tests/deps.js index 9b2ca48af..6d78e4217 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -66,7 +66,7 @@ goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Bl goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); From 12aa4af67462d8c5003836c10cb13ae2b9e31a1d Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:47:55 -0700 Subject: [PATCH 294/313] Migrate core/gesture.js named requires --- core/gesture.js | 177 +++++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 85 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index a5b786b5b..c74efb2f4 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -14,29 +14,36 @@ goog.module('Blockly.Gesture'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockAnimations'); +// TODO(#5073): Add Blockly require after fixing circular dependency. +// goog.require('Blockly'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const BubbleDragger = goog.require('Blockly.BubbleDragger'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ +const Events = goog.require('Blockly.Events'); +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const IBlockDragger = goog.requireType('Blockly.IBlockDragger'); +/* eslint-disable-next-line no-unused-vars */ +const IBubble = goog.requireType('Blockly.IBubble'); +/* eslint-disable-next-line no-unused-vars */ +const IFlyout = goog.requireType('Blockly.IFlyout'); +const Tooltip = goog.require('Blockly.Tooltip'); +const Touch = goog.require('Blockly.Touch'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.require('Blockly.Workspace'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const WorkspaceDragger = goog.require('Blockly.WorkspaceDragger'); +const blockAnimations = goog.require('Blockly.blockAnimations'); +const browserEvents = goog.require('Blockly.browserEvents'); +const internalConstants = goog.require('Blockly.internalConstants'); +const registry = goog.require('Blockly.registry'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.BlockDragger'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.BubbleDragger'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.registry'); -goog.require('Blockly.Tooltip'); -goog.require('Blockly.Touch'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.Workspace'); -goog.require('Blockly.WorkspaceDragger'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IBlockDragger'); -goog.requireType('Blockly.IBubble'); -goog.requireType('Blockly.IFlyout'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -48,7 +55,7 @@ goog.requireType('Blockly.WorkspaceSvg'); /** * Class for one gesture. * @param {!Event} e The event that kicked off this gesture. - * @param {!Blockly.WorkspaceSvg} creatorWorkspace The workspace that created + * @param {!WorkspaceSvg} creatorWorkspace The workspace that created * this gesture and has a reference to it. * @constructor */ @@ -56,7 +63,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The position of the mouse when the gesture started. Units are CSS pixels, * with (0, 0) at the top left of the browser window (mouseEvent clientX/Y). - * @type {Blockly.utils.Coordinate} + * @type {Coordinate} * @private */ this.mouseDownXY_ = null; @@ -64,15 +71,15 @@ const Gesture = function(e, creatorWorkspace) { /** * How far the mouse has moved during this drag, in pixel units. * (0, 0) is at this.mouseDownXY_. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ - this.currentDragDeltaXY_ = new Blockly.utils.Coordinate(0, 0); + this.currentDragDeltaXY_ = new Coordinate(0, 0); /** * The bubble that the gesture started on, or null if it did not start on a * bubble. - * @type {Blockly.IBubble} + * @type {IBubble} * @private */ this.startBubble_ = null; @@ -80,7 +87,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The field that the gesture started on, or null if it did not start on a * field. - * @type {Blockly.Field} + * @type {Field} * @private */ this.startField_ = null; @@ -88,7 +95,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The block that the gesture started on, or null if it did not start on a * block. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @private */ this.startBlock_ = null; @@ -98,7 +105,7 @@ const Gesture = function(e, creatorWorkspace) { * shadow block, this is the first non-shadow parent of the block. If the * gesture started in the flyout, this is the root block of the block group * that was clicked or dragged. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @private */ this.targetBlock_ = null; @@ -107,7 +114,7 @@ const Gesture = function(e, creatorWorkspace) { * The workspace that the gesture started on. There may be multiple * workspaces on a page; this is more accurate than using * Blockly.getMainWorkspace(). - * @type {Blockly.WorkspaceSvg} + * @type {WorkspaceSvg} * @protected */ this.startWorkspace_ = null; @@ -117,7 +124,7 @@ const Gesture = function(e, creatorWorkspace) { * to the gesture, which will need to be cleared at deletion. * This may be different from the start workspace. For instance, a flyout is * a workspace, but its parent workspace manages gestures for it. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.creatorWorkspace_ = creatorWorkspace; @@ -162,7 +169,7 @@ const Gesture = function(e, creatorWorkspace) { /** * A handle to use to unbind a mouse move listener at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @protected */ this.onMoveWrapper_ = null; @@ -170,21 +177,21 @@ const Gesture = function(e, creatorWorkspace) { /** * A handle to use to unbind a mouse up listener at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @protected */ this.onUpWrapper_ = null; /** * The object tracking a bubble drag, or null if none is in progress. - * @type {Blockly.BubbleDragger} + * @type {BubbleDragger} * @private */ this.bubbleDragger_ = null; /** * The object tracking a block drag, or null if none is in progress. - * @type {?Blockly.IBlockDragger} + * @type {?IBlockDragger} * @private */ this.blockDragger_ = null; @@ -192,14 +199,14 @@ const Gesture = function(e, creatorWorkspace) { /** * The object tracking a workspace or flyout workspace drag, or null if none * is in progress. - * @type {Blockly.WorkspaceDragger} + * @type {WorkspaceDragger} * @private */ this.workspaceDragger_ = null; /** * The flyout a gesture started in, if any. - * @type {Blockly.IFlyout} + * @type {IFlyout} * @private */ this.flyout_ = null; @@ -231,7 +238,7 @@ const Gesture = function(e, creatorWorkspace) { * @type {boolean} * @private */ - this.healStack_ = !Blockly.internalConstants.DRAG_STACK; + this.healStack_ = !internalConstants.DRAG_STACK; }; /** @@ -239,16 +246,16 @@ const Gesture = function(e, creatorWorkspace) { * @package */ Gesture.prototype.dispose = function() { - Blockly.Touch.clearTouchIdentifier(); - Blockly.Tooltip.unblock(); + Touch.clearTouchIdentifier(); + Tooltip.unblock(); // Clear the owner's reference to this gesture. this.creatorWorkspace_.clearGesture(); if (this.onMoveWrapper_) { - Blockly.browserEvents.unbind(this.onMoveWrapper_); + browserEvents.unbind(this.onMoveWrapper_); } if (this.onUpWrapper_) { - Blockly.browserEvents.unbind(this.onUpWrapper_); + browserEvents.unbind(this.onUpWrapper_); } if (this.blockDragger_) { @@ -268,7 +275,7 @@ Gesture.prototype.dispose = function() { * @private */ Gesture.prototype.updateFromEvent_ = function(e) { - const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const currentXY = new Coordinate(e.clientX, e.clientY); const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. if (changed) { @@ -280,25 +287,25 @@ Gesture.prototype.updateFromEvent_ = function(e) { /** * DO MATH to set currentDragDeltaXY_ based on the most recent mouse position. - * @param {!Blockly.utils.Coordinate} currentXY The most recent mouse/pointer + * @param {!Coordinate} currentXY The most recent mouse/pointer * position, in pixel units, with (0, 0) at the window's top left corner. * @return {boolean} True if the drag just exceeded the drag radius for the * first time. * @private */ Gesture.prototype.updateDragDelta_ = function(currentXY) { - this.currentDragDeltaXY_ = Blockly.utils.Coordinate.difference( + this.currentDragDeltaXY_ = Coordinate.difference( currentXY, - /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); + /** @type {!Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { const currentDragDelta = - Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); + Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. const limitRadius = this.flyout_ ? - Blockly.internalConstants.FLYOUT_DRAG_RADIUS : - Blockly.internalConstants.DRAG_RADIUS; + internalConstants.FLYOUT_DRAG_RADIUS : + internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; @@ -329,8 +336,8 @@ Gesture.prototype.updateIsDraggingFromFlyout_ = function() { this.startWorkspace_.updateScreenCalculationsIfScrolled(); // Start the event group now, so that the same event group is used for block // creation and block dragging. - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!Events.getGroup()) { + Events.setGroup(true); } // The start block is no longer relevant, because this is a drag. this.startBlock_ = null; @@ -404,8 +411,8 @@ Gesture.prototype.updateIsDraggingWorkspace_ = function() { return; } - this.workspaceDragger_ = new Blockly.WorkspaceDragger( - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + this.workspaceDragger_ = new WorkspaceDragger( + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.isDraggingWorkspace_ = true; this.workspaceDragger_.startDrag(); @@ -441,13 +448,13 @@ Gesture.prototype.updateIsDragging_ = function() { * @private */ Gesture.prototype.startDraggingBlock_ = function() { - const BlockDraggerClass = Blockly.registry.getClassFromOptions( - Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, + const BlockDraggerClass = registry.getClassFromOptions( + registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); this.blockDragger_ = new BlockDraggerClass( - /** @type {!Blockly.BlockSvg} */ (this.targetBlock_), - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + /** @type {!BlockSvg} */ (this.targetBlock_), + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.blockDragger_.startDrag(this.currentDragDeltaXY_, this.healStack_); this.blockDragger_.drag(this.mostRecentEvent_, this.currentDragDeltaXY_); }; @@ -458,9 +465,9 @@ Gesture.prototype.startDraggingBlock_ = function() { */ // TODO (fenichel): Possibly combine this and startDraggingBlock_. Gesture.prototype.startDraggingBubble_ = function() { - this.bubbleDragger_ = new Blockly.BubbleDragger( - /** @type {!Blockly.IBubble} */ (this.startBubble_), - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + this.bubbleDragger_ = new BubbleDragger( + /** @type {!IBubble} */ (this.startBubble_), + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.bubbleDragger_.startBubbleDrag(); this.bubbleDragger_.dragBubble( this.mostRecentEvent_, this.currentDragDeltaXY_); @@ -472,13 +479,13 @@ Gesture.prototype.startDraggingBubble_ = function() { * @package */ Gesture.prototype.doStart = function(e) { - if (Blockly.utils.isTargetInput(e)) { + if (utils.isTargetInput(e)) { this.cancel(); return; } this.hasStarted_ = true; - Blockly.blockAnimations.disconnectUiStop(); + blockAnimations.disconnectUiStop(); this.startWorkspace_.updateScreenCalculationsIfScrolled(); if (this.startWorkspace_.isMutator) { // Mutator's coordinate system could be out of date because the bubble was @@ -493,13 +500,13 @@ Gesture.prototype.doStart = function(e) { this.startWorkspace_.markFocused(); this.mostRecentEvent_ = e; - Blockly.Tooltip.block(); + Tooltip.block(); if (this.targetBlock_) { this.targetBlock_.select(); } - if (Blockly.utils.isRightButton(e)) { + if (utils.isRightButton(e)) { this.handleRightClick(e); return; } @@ -510,7 +517,7 @@ Gesture.prototype.doStart = function(e) { Blockly.longStart(e, this); } - this.mouseDownXY_ = new Blockly.utils.Coordinate(e.clientX, e.clientY); + this.mouseDownXY_ = new Coordinate(e.clientX, e.clientY); this.healStack_ = e.altKey || e.ctrlKey || e.metaKey; this.bindMouseEvents(e); @@ -522,9 +529,9 @@ Gesture.prototype.doStart = function(e) { * @package */ Gesture.prototype.bindMouseEvents = function(e) { - this.onMoveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMoveWrapper_ = browserEvents.conditionalBind( document, 'mousemove', null, this.handleMove.bind(this)); - this.onUpWrapper_ = Blockly.browserEvents.conditionalBind( + this.onUpWrapper_ = browserEvents.conditionalBind( document, 'mouseup', null, this.handleUp.bind(this)); e.preventDefault(); @@ -644,7 +651,7 @@ Gesture.prototype.handleRightClick = function(e) { /** * Handle a mousedown/touchstart event on a workspace. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.WorkspaceSvg} ws The workspace the event hit. + * @param {!WorkspaceSvg} ws The workspace the event hit. * @package */ Gesture.prototype.handleWsStart = function(e, ws) { @@ -660,18 +667,18 @@ Gesture.prototype.handleWsStart = function(e, ws) { /** * Fires a workspace click event. - * @param {!Blockly.WorkspaceSvg} ws The workspace that a user clicks on. + * @param {!WorkspaceSvg} ws The workspace that a user clicks on. * @private */ Gesture.prototype.fireWorkspaceClick_ = function(ws) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CLICK))( + Events.fire(new (Events.get(Events.CLICK))( null, ws.id, 'workspace')); }; /** * Handle a mousedown/touchstart event on a flyout. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.IFlyout} flyout The flyout the event hit. + * @param {!IFlyout} flyout The flyout the event hit. * @package */ Gesture.prototype.handleFlyoutStart = function(e, flyout) { @@ -687,7 +694,7 @@ Gesture.prototype.handleFlyoutStart = function(e, flyout) { /** * Handle a mousedown/touchstart event on a block. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.BlockSvg} block The block the event hit. + * @param {!BlockSvg} block The block the event hit. * @package */ Gesture.prototype.handleBlockStart = function(e, block) { @@ -703,7 +710,7 @@ Gesture.prototype.handleBlockStart = function(e, block) { /** * Handle a mousedown/touchstart event on a bubble. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.IBubble} bubble The bubble the event hit. + * @param {!IBubble} bubble The bubble the event hit. * @package */ Gesture.prototype.handleBubbleStart = function(e, bubble) { @@ -747,20 +754,20 @@ Gesture.prototype.doBlockClick_ = function() { // Block click in an autoclosing flyout. if (this.flyout_ && this.flyout_.autoClose) { if (this.targetBlock_.isEnabled()) { - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!Events.getGroup()) { + Events.setGroup(true); } const newBlock = this.flyout_.createBlock(this.targetBlock_); newBlock.scheduleSnapAndBump(); } } else { // Clicks events are on the start block, even if it was a shadow. - const event = new (Blockly.Events.get(Blockly.Events.CLICK))( + const event = new (Events.get(Events.CLICK))( this.startBlock_, this.startWorkspace_.id, 'block'); - Blockly.Events.fire(event); + Events.fire(event); } this.bringBlockToFront_(); - Blockly.Events.setGroup(false); + Events.setGroup(false); }; /** @@ -797,7 +804,7 @@ Gesture.prototype.bringBlockToFront_ = function() { /** * Record the field that a gesture started on. - * @param {Blockly.Field} field The field the gesture started on. + * @param {Field} field The field the gesture started on. * @package */ Gesture.prototype.setStartField = function(field) { @@ -813,7 +820,7 @@ Gesture.prototype.setStartField = function(field) { /** * Record the bubble that a gesture started on - * @param {Blockly.IBubble} bubble The bubble the gesture started on. + * @param {IBubble} bubble The bubble the gesture started on. * @package */ Gesture.prototype.setStartBubble = function(bubble) { @@ -825,7 +832,7 @@ Gesture.prototype.setStartBubble = function(bubble) { /** * Record the block that a gesture started on, and set the target block * appropriately. - * @param {Blockly.BlockSvg} block The block the gesture started on. + * @param {BlockSvg} block The block the gesture started on. * @package */ Gesture.prototype.setStartBlock = function(block) { @@ -844,7 +851,7 @@ Gesture.prototype.setStartBlock = function(block) { * Record the block that a gesture targets, meaning the block that will be * dragged if this turns into a drag. If this block is a shadow, that will be * its first non-shadow parent. - * @param {Blockly.BlockSvg} block The block the gesture targets. + * @param {BlockSvg} block The block the gesture targets. * @private */ Gesture.prototype.setTargetBlock_ = function(block) { @@ -857,7 +864,7 @@ Gesture.prototype.setTargetBlock_ = function(block) { /** * Record the workspace that a gesture started on. - * @param {Blockly.WorkspaceSvg} ws The workspace the gesture started on. + * @param {WorkspaceSvg} ws The workspace the gesture started on. * @private */ Gesture.prototype.setStartWorkspace_ = function(ws) { @@ -868,7 +875,7 @@ Gesture.prototype.setStartWorkspace_ = function(ws) { /** * Record the flyout that a gesture started on. - * @param {Blockly.IFlyout} flyout The flyout the gesture started on. + * @param {IFlyout} flyout The flyout the gesture started on. * @private */ Gesture.prototype.setStartFlyout_ = function(flyout) { @@ -961,7 +968,7 @@ Gesture.prototype.hasStarted = function() { /** * Get a list of the insertion markers that currently exist. Block drags have * 0, 1, or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion + * @return {!Array} A possibly empty list of insertion * marker blocks. * @package */ @@ -975,7 +982,7 @@ Gesture.prototype.getInsertionMarkers = function() { /** * Gets the current dragger if an item is being dragged. Null if nothing is * being dragged. - * @return {!Blockly.WorkspaceDragger|!Blockly.BubbleDragger|!Blockly.IBlockDragger|null} + * @return {!WorkspaceDragger|!BubbleDragger|!IBlockDragger|null} * The dragger that is currently in use or null if no drag is in progress. */ Gesture.prototype.getCurrentDragger = function() { @@ -994,7 +1001,7 @@ Gesture.prototype.getCurrentDragger = function() { * @return {boolean} True if gesture is occurring. */ Gesture.inProgress = function() { - const workspaces = Blockly.Workspace.getAll(); + const workspaces = Workspace.getAll(); for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { return true; From 46c0050ce6f4ec2bbc5a87c3e4e2adf9b4b72aaf Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:48:02 -0700 Subject: [PATCH 295/313] clang-format core/gesture.js --- core/gesture.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index c74efb2f4..933930e44 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -299,13 +299,11 @@ Gesture.prototype.updateDragDelta_ = function(currentXY) { /** @type {!Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { - const currentDragDelta = - Coordinate.magnitude(this.currentDragDeltaXY_); + const currentDragDelta = Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - const limitRadius = this.flyout_ ? - internalConstants.FLYOUT_DRAG_RADIUS : - internalConstants.DRAG_RADIUS; + const limitRadius = this.flyout_ ? internalConstants.FLYOUT_DRAG_RADIUS : + internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; @@ -449,8 +447,7 @@ Gesture.prototype.updateIsDragging_ = function() { */ Gesture.prototype.startDraggingBlock_ = function() { const BlockDraggerClass = registry.getClassFromOptions( - registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, - true); + registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); this.blockDragger_ = new BlockDraggerClass( /** @type {!BlockSvg} */ (this.targetBlock_), @@ -548,8 +545,7 @@ Gesture.prototype.handleMove = function(e) { if (this.isDraggingWorkspace_) { this.workspaceDragger_.drag(this.currentDragDeltaXY_); } else if (this.isDraggingBlock_) { - this.blockDragger_.drag( - this.mostRecentEvent_, this.currentDragDeltaXY_); + this.blockDragger_.drag(this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingBubble_) { this.bubbleDragger_.dragBubble( this.mostRecentEvent_, this.currentDragDeltaXY_); @@ -616,8 +612,7 @@ Gesture.prototype.cancel = function() { this.bubbleDragger_.endBubbleDrag( this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingBlock_) { - this.blockDragger_.endDrag( - this.mostRecentEvent_, this.currentDragDeltaXY_); + this.blockDragger_.endDrag(this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingWorkspace_) { this.workspaceDragger_.endDrag(this.currentDragDeltaXY_); } @@ -671,8 +666,7 @@ Gesture.prototype.handleWsStart = function(e, ws) { * @private */ Gesture.prototype.fireWorkspaceClick_ = function(ws) { - Events.fire(new (Events.get(Events.CLICK))( - null, ws.id, 'workspace')); + Events.fire(new (Events.get(Events.CLICK))(null, ws.id, 'workspace')); }; /** From a663b1225b8f7fe4fd534187e5e5d28324498334 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:50:47 -0700 Subject: [PATCH 296/313] Move @package annotation to export for core/marker_manager.js --- core/marker_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 1f16f500a..60cb3b870 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -25,7 +25,6 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * Class to manage the multiple markers and the cursor on a workspace. * @param {!WorkspaceSvg} workspace The workspace for the marker manager. * @constructor - * @package */ const MarkerManager = function(workspace) { /** @@ -195,4 +194,5 @@ MarkerManager.prototype.dispose = function() { } }; +/** @package */ exports = MarkerManager; From 055533e783dcaf9268a3f6849a2974e91537be7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:17:17 -0700 Subject: [PATCH 297/313] Migrate core/shortcut_registry.js to ES6 const/let --- core/shortcut_registry.js | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index 14684e1b8..807f40d84 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -78,7 +78,7 @@ Blockly.ShortcutRegistry.KeyboardShortcut; */ Blockly.ShortcutRegistry.prototype.register = function( shortcut, opt_allowOverrides) { - var registeredShortcut = this.registry_[shortcut.name]; + const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( 'Shortcut with name "' + shortcut.name + '" already exists.'); @@ -94,7 +94,7 @@ Blockly.ShortcutRegistry.prototype.register = function( * @public */ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { - var shortcut = this.registry_[shortcutName]; + const shortcut = this.registry_[shortcutName]; if (!shortcut) { console.warn( @@ -123,7 +123,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { Blockly.ShortcutRegistry.prototype.addKeyMapping = function( keyCode, shortcutName, opt_allowCollision) { keyCode = String(keyCode); - var shortcutNames = this.keyMap_[keyCode]; + const shortcutNames = this.keyMap_[keyCode]; if (shortcutNames && !opt_allowCollision) { throw new Error( 'Shortcut with name "' + shortcutName + '" collides with shortcuts ' + @@ -149,7 +149,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( */ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( keyCode, shortcutName, opt_quiet) { - var shortcutNames = this.keyMap_[keyCode]; + const shortcutNames = this.keyMap_[keyCode]; if (!shortcutNames && !opt_quiet) { console.warn( @@ -158,7 +158,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( return false; } - var shortcutIdx = shortcutNames.indexOf(shortcutName); + const shortcutIdx = shortcutNames.indexOf(shortcutName); if (shortcutIdx > -1) { shortcutNames.splice(shortcutIdx, 1); if (shortcutNames.length == 0) { @@ -181,7 +181,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( * @public */ Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { - for (var keyCode in this.keyMap_) { + for (const keyCode in this.keyMap_) { this.removeKeyMapping(keyCode, shortcutName, true); } }; @@ -225,13 +225,13 @@ Blockly.ShortcutRegistry.prototype.getRegistry = function() { * @public */ Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { - var key = this.serializeKeyEvent_(e); - var shortcutNames = this.getShortcutNamesByKeyCode(key); + const key = this.serializeKeyEvent_(e); + const shortcutNames = this.getShortcutNamesByKeyCode(key); if (!shortcutNames) { return false; } - for (var i = 0, shortcutName; (shortcutName = shortcutNames[i]); i++) { - var shortcut = this.registry_[shortcutName]; + for (let i = 0, shortcutName; (shortcutName = shortcutNames[i]); i++) { + const shortcut = this.registry_[shortcutName]; if (!shortcut.preconditionFn || shortcut.preconditionFn(workspace)) { // If the key has been handled, stop processing shortcuts. if (shortcut.callback && shortcut.callback(workspace, e, shortcut)) { @@ -264,10 +264,10 @@ Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( */ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( shortcutName) { - var keys = []; - for (var keyCode in this.keyMap_) { - var shortcuts = this.keyMap_[keyCode]; - var shortcutIdx = shortcuts.indexOf(shortcutName); + const keys = []; + for (const keyCode in this.keyMap_) { + const shortcuts = this.keyMap_[keyCode]; + const shortcutIdx = shortcuts.indexOf(shortcutName); if (shortcutIdx > -1) { keys.push(keyCode); } @@ -282,8 +282,8 @@ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( * @private */ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { - var serializedKey = ''; - for (var modifier in Blockly.ShortcutRegistry.modifierKeys) { + let serializedKey = ''; + for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { if (e.getModifierState(modifier)) { if (serializedKey != '') { serializedKey += '+'; @@ -307,9 +307,9 @@ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { */ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { - var validModifiers = Blockly.utils.object.values( + const validModifiers = Blockly.utils.object.values( Blockly.ShortcutRegistry.modifierKeys); - for (var i = 0, modifier; (modifier = modifiers[i]); i++) { + for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); } @@ -327,12 +327,12 @@ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( */ Blockly.ShortcutRegistry.prototype.createSerializedKey = function( keyCode, modifiers) { - var serializedKey = ''; + let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); - for (var modifier in Blockly.ShortcutRegistry.modifierKeys) { - var modifierKeyCode = + for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + const modifierKeyCode = Blockly.ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { From 69b900aa4626cf584066a670e22cd8ae4553bc99 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:25:30 -0700 Subject: [PATCH 298/313] Migrate core/shortcut_registry.js to goog.module --- core/interfaces/i_keyboard_accessible.js | 5 +- core/shortcut_registry.js | 71 ++++++++++++------------ tests/deps.js | 2 +- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 8243e67d1..04704a2fe 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -15,7 +15,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); /* eslint-disable-next-line no-unused-vars */ -const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); +const ShortcutRegistry = goog.requireType('Blockly.ShortcutRegistry'); /** @@ -26,7 +26,8 @@ const IKeyboardAccessible = function() {}; /** * Handles the given keyboard shortcut. - * @param {!KeyboardShortcut} shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be + * handled. * @return {boolean} True if the shortcut has been handled, false otherwise. */ IKeyboardAccessible.prototype.onShortcut; diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index 807f40d84..d75ec9546 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.ShortcutRegistry'); +goog.module('Blockly.ShortcutRegistry'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.KeyCodes'); goog.require('Blockly.utils.object'); @@ -22,16 +23,16 @@ goog.requireType('Blockly.Workspace'); /** * Class for the registry of keyboard shortcuts. This is intended to be a * singleton. You should not create a new instance, and only access this class - * from Blockly.ShortcutRegistry.registry. + * from ShortcutRegistry.registry. * @constructor */ -Blockly.ShortcutRegistry = function() { +const ShortcutRegistry = function() { // Singleton instance should be registered once. - Blockly.ShortcutRegistry.registry = this; + ShortcutRegistry.registry = this; /** * Registry of all keyboard shortcuts, keyed by name of shortcut. - * @type {!Object} + * @type {!Object} * @private */ this.registry_ = Object.create(null); @@ -48,7 +49,7 @@ Blockly.ShortcutRegistry = function() { * Enum of valid modifiers. * @enum {!Blockly.utils.KeyCodes} */ -Blockly.ShortcutRegistry.modifierKeys = { +ShortcutRegistry.modifierKeys = { 'Shift': Blockly.utils.KeyCodes.SHIFT, 'Control': Blockly.utils.KeyCodes.CTRL, 'Alt': Blockly.utils.KeyCodes.ALT, @@ -59,24 +60,24 @@ Blockly.ShortcutRegistry.modifierKeys = { * A keyboard shortcut. * @typedef {{ * callback: ((function(!Blockly.Workspace, Event, - * !Blockly.ShortcutRegistry.KeyboardShortcut):boolean)|undefined), + * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), * name: string, * preconditionFn: ((function(!Blockly.Workspace):boolean)|undefined), * metadata: (Object|undefined) * }} */ -Blockly.ShortcutRegistry.KeyboardShortcut; +ShortcutRegistry.KeyboardShortcut; /** * Registers a keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The + * @param {!ShortcutRegistry.KeyboardShortcut} shortcut The * shortcut for this key code. * @param {boolean=} opt_allowOverrides True to prevent a warning when * overriding an already registered item. * @throws {Error} if a shortcut with the same name already exists. * @public */ -Blockly.ShortcutRegistry.prototype.register = function( +ShortcutRegistry.prototype.register = function( shortcut, opt_allowOverrides) { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { @@ -93,7 +94,7 @@ Blockly.ShortcutRegistry.prototype.register = function( * @return {boolean} True if an item was unregistered, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { +ShortcutRegistry.prototype.unregister = function(shortcutName) { const shortcut = this.registry_[shortcutName]; if (!shortcut) { @@ -112,7 +113,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { * Adds a mapping between a keycode and a keyboard shortcut. * @param {string|Blockly.utils.KeyCodes} keyCode The key code for the keyboard * shortcut. If registering a key code with a modifier (ex: ctrl+c) use - * Blockly.ShortcutRegistry.registry.createSerializedKey; + * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the * given keycode is pressed. * @param {boolean=} opt_allowCollision True to prevent an error when adding a @@ -120,7 +121,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { * @throws {Error} if the given key code is already mapped to a shortcut. * @public */ -Blockly.ShortcutRegistry.prototype.addKeyMapping = function( +ShortcutRegistry.prototype.addKeyMapping = function( keyCode, shortcutName, opt_allowCollision) { keyCode = String(keyCode); const shortcutNames = this.keyMap_[keyCode]; @@ -139,7 +140,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( * Removes a mapping between a keycode and a keyboard shortcut. * @param {string} keyCode The key code for the keyboard shortcut. If * registering a key code with a modifier (ex: ctrl+c) use - * Blockly.ShortcutRegistry.registry.createSerializedKey; + * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the * given keycode is pressed. * @param {boolean=} opt_quiet True to not console warn when there is no @@ -147,7 +148,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( * @return {boolean} True if a key mapping was removed, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( +ShortcutRegistry.prototype.removeKeyMapping = function( keyCode, shortcutName, opt_quiet) { const shortcutNames = this.keyMap_[keyCode]; @@ -180,7 +181,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( * @param {string} shortcutName The name of the shortcut to remove from the key map. * @public */ -Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { +ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { for (const keyCode in this.keyMap_) { this.removeKeyMapping(keyCode, shortcutName, true); } @@ -192,27 +193,27 @@ Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) * shortcut names. * @public */ -Blockly.ShortcutRegistry.prototype.setKeyMap = function(keyMap) { +ShortcutRegistry.prototype.setKeyMap = function(keyMap) { this.keyMap_ = keyMap; }; /** * Gets the current key map. - * @return {!Object>} - * The object holding key codes to Blockly.ShortcutRegistry.KeyboardShortcut. + * @return {!Object>} + * The object holding key codes to ShortcutRegistry.KeyboardShortcut. * @public */ -Blockly.ShortcutRegistry.prototype.getKeyMap = function() { +ShortcutRegistry.prototype.getKeyMap = function() { return Blockly.utils.object.deepMerge(Object.create(null), this.keyMap_); }; /** * Gets the registry of keyboard shortcuts. - * @return {!Object} + * @return {!Object} * The registry of keyboard shortcuts. * @public */ -Blockly.ShortcutRegistry.prototype.getRegistry = function() { +ShortcutRegistry.prototype.getRegistry = function() { return Blockly.utils.object.deepMerge(Object.create(null), this.registry_); }; @@ -224,7 +225,7 @@ Blockly.ShortcutRegistry.prototype.getRegistry = function() { * @return {boolean} True if the event was handled, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { +ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { const key = this.serializeKeyEvent_(e); const shortcutNames = this.getShortcutNamesByKeyCode(key); if (!shortcutNames) { @@ -249,7 +250,7 @@ Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { * given keyCode is used. Undefined if no shortcuts exist. * @public */ -Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( +ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( keyCode) { return this.keyMap_[keyCode] || []; }; @@ -262,7 +263,7 @@ Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( * registered under. * @public */ -Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( +ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( shortcutName) { const keys = []; for (const keyCode in this.keyMap_) { @@ -281,9 +282,9 @@ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( * @return {string} The serialized key code for the given event. * @private */ -Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { +ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { let serializedKey = ''; - for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + for (const modifier in ShortcutRegistry.modifierKeys) { if (e.getModifierState(modifier)) { if (serializedKey != '') { serializedKey += '+'; @@ -305,10 +306,10 @@ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { * @throws {Error} if the modifier is not in the valid modifiers list. * @private */ -Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( +ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { const validModifiers = Blockly.utils.object.values( - Blockly.ShortcutRegistry.modifierKeys); + ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); @@ -321,19 +322,19 @@ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( * @param {number} keyCode Number code representing the key. * @param {?Array} modifiers List of modifier key codes to be used with * the key. All valid modifiers can be found in the - * Blockly.ShortcutRegistry.modifierKeys. + * ShortcutRegistry.modifierKeys. * @return {string} The serialized key code for the given modifiers and key. * @public */ -Blockly.ShortcutRegistry.prototype.createSerializedKey = function( +ShortcutRegistry.prototype.createSerializedKey = function( keyCode, modifiers) { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); - for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + for (const modifier in ShortcutRegistry.modifierKeys) { const modifierKeyCode = - Blockly.ShortcutRegistry.modifierKeys[modifier]; + ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { serializedKey += '+'; @@ -352,4 +353,6 @@ Blockly.ShortcutRegistry.prototype.createSerializedKey = function( }; // Creates and assigns the singleton instance. -new Blockly.ShortcutRegistry(); +new ShortcutRegistry(); + +exports = ShortcutRegistry; diff --git a/tests/deps.js b/tests/deps.js index de575339f..d67006c87 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -160,7 +160,7 @@ goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Ren goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); -goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']); +goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); From 3519f4abc8d5352214a3a9f7851ca9ca9326afd1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:28:19 -0700 Subject: [PATCH 299/313] Migrate core/shortcut_registry.js to named requires --- core/shortcut_registry.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index d75ec9546..ac492397a 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -14,10 +14,10 @@ goog.module('Blockly.ShortcutRegistry'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Workspace'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const object = goog.require('Blockly.utils.object'); /** @@ -47,22 +47,22 @@ const ShortcutRegistry = function() { /** * Enum of valid modifiers. - * @enum {!Blockly.utils.KeyCodes} + * @enum {!KeyCodes} */ ShortcutRegistry.modifierKeys = { - 'Shift': Blockly.utils.KeyCodes.SHIFT, - 'Control': Blockly.utils.KeyCodes.CTRL, - 'Alt': Blockly.utils.KeyCodes.ALT, - 'Meta': Blockly.utils.KeyCodes.META + 'Shift': KeyCodes.SHIFT, + 'Control': KeyCodes.CTRL, + 'Alt': KeyCodes.ALT, + 'Meta': KeyCodes.META }; /** * A keyboard shortcut. * @typedef {{ - * callback: ((function(!Blockly.Workspace, Event, + * callback: ((function(!Workspace, Event, * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), * name: string, - * preconditionFn: ((function(!Blockly.Workspace):boolean)|undefined), + * preconditionFn: ((function(!Workspace):boolean)|undefined), * metadata: (Object|undefined) * }} */ @@ -111,7 +111,7 @@ ShortcutRegistry.prototype.unregister = function(shortcutName) { /** * Adds a mapping between a keycode and a keyboard shortcut. - * @param {string|Blockly.utils.KeyCodes} keyCode The key code for the keyboard + * @param {string|KeyCodes} keyCode The key code for the keyboard * shortcut. If registering a key code with a modifier (ex: ctrl+c) use * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the @@ -204,7 +204,7 @@ ShortcutRegistry.prototype.setKeyMap = function(keyMap) { * @public */ ShortcutRegistry.prototype.getKeyMap = function() { - return Blockly.utils.object.deepMerge(Object.create(null), this.keyMap_); + return object.deepMerge(Object.create(null), this.keyMap_); }; /** @@ -214,12 +214,12 @@ ShortcutRegistry.prototype.getKeyMap = function() { * @public */ ShortcutRegistry.prototype.getRegistry = function() { - return Blockly.utils.object.deepMerge(Object.create(null), this.registry_); + return object.deepMerge(Object.create(null), this.registry_); }; /** * Handles key down events. - * @param {!Blockly.Workspace} workspace The main workspace where the event was + * @param {!Workspace} workspace The main workspace where the event was * captured. * @param {!Event} e The key down event. * @return {boolean} True if the event was handled, false otherwise. @@ -308,7 +308,7 @@ ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { */ ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { - const validModifiers = Blockly.utils.object.values( + const validModifiers = object.values( ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { From 9e2d6f2aba5b7c3d43a0705ce7d28f5b4d44cc76 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:28:57 -0700 Subject: [PATCH 300/313] clang-format core/shortcut_registry.js --- core/shortcut_registry.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index ac492397a..3da777eae 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -77,8 +77,7 @@ ShortcutRegistry.KeyboardShortcut; * @throws {Error} if a shortcut with the same name already exists. * @public */ -ShortcutRegistry.prototype.register = function( - shortcut, opt_allowOverrides) { +ShortcutRegistry.prototype.register = function(shortcut, opt_allowOverrides) { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( @@ -168,7 +167,8 @@ ShortcutRegistry.prototype.removeKeyMapping = function( return true; } if (!opt_quiet) { - console.warn('No keyboard shortcut with name "' + shortcutName + + console.warn( + 'No keyboard shortcut with name "' + shortcutName + '" registered with key code "' + keyCode + '"'); } return false; @@ -176,9 +176,10 @@ ShortcutRegistry.prototype.removeKeyMapping = function( /** * Removes all the key mappings for a shortcut with the given name. - * Useful when changing the default key mappings and the key codes registered to the shortcut are - * unknown. - * @param {string} shortcutName The name of the shortcut to remove from the key map. + * Useful when changing the default key mappings and the key codes registered to + * the shortcut are unknown. + * @param {string} shortcutName The name of the shortcut to remove from the key + * map. * @public */ ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { @@ -250,8 +251,7 @@ ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { * given keyCode is used. Undefined if no shortcuts exist. * @public */ -ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( - keyCode) { +ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function(keyCode) { return this.keyMap_[keyCode] || []; }; @@ -263,8 +263,7 @@ ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( * registered under. * @public */ -ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( - shortcutName) { +ShortcutRegistry.prototype.getKeyCodesByShortcutName = function(shortcutName) { const keys = []; for (const keyCode in this.keyMap_) { const shortcuts = this.keyMap_[keyCode]; @@ -306,10 +305,8 @@ ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { * @throws {Error} if the modifier is not in the valid modifiers list. * @private */ -ShortcutRegistry.prototype.checkModifiers_ = function( - modifiers) { - const validModifiers = object.values( - ShortcutRegistry.modifierKeys); +ShortcutRegistry.prototype.checkModifiers_ = function(modifiers) { + const validModifiers = object.values(ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); @@ -326,15 +323,13 @@ ShortcutRegistry.prototype.checkModifiers_ = function( * @return {string} The serialized key code for the given modifiers and key. * @public */ -ShortcutRegistry.prototype.createSerializedKey = function( - keyCode, modifiers) { +ShortcutRegistry.prototype.createSerializedKey = function(keyCode, modifiers) { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); for (const modifier in ShortcutRegistry.modifierKeys) { - const modifierKeyCode = - ShortcutRegistry.modifierKeys[modifier]; + const modifierKeyCode = ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { serializedKey += '+'; From 2d480a1b202e9fca2eda7bfb25c6c7c8a7e07c79 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:46:58 -0700 Subject: [PATCH 301/313] Migrate core/theme_manager.js to ES6 const/let --- core/theme_manager.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index 6c461a2e7..d432e0dd0 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -82,11 +82,11 @@ Blockly.ThemeManager.prototype.getTheme = function() { * @package */ Blockly.ThemeManager.prototype.setTheme = function(theme) { - var prevTheme = this.theme_; + const prevTheme = this.theme_; this.theme_ = theme; // Set the theme name onto the injection div. - var injectionDiv = this.workspace_.getInjectionDiv(); + const injectionDiv = this.workspace_.getInjectionDiv(); if (injectionDiv) { if (prevTheme) { Blockly.utils.dom.removeClass(injectionDiv, prevTheme.getClassName()); @@ -95,17 +95,17 @@ Blockly.ThemeManager.prototype.setTheme = function(theme) { } // Refresh all subscribed workspaces. - for (var i = 0, workspace; (workspace = this.subscribedWorkspaces_[i]); i++) { + for (let i = 0, workspace; (workspace = this.subscribedWorkspaces_[i]); i++) { workspace.refreshTheme(); } // Refresh all registered Blockly UI components. - for (var i = 0, keys = Object.keys(this.componentDB_), + for (let i = 0, keys = Object.keys(this.componentDB_), key; (key = keys[i]); i++) { - for (var j = 0, component; (component = this.componentDB_[key][j]); j++) { - var element = component.element; - var propertyName = component.propertyName; - var style = this.theme_ && this.theme_.getComponentStyle(key); + for (let j = 0, component; (component = this.componentDB_[key][j]); j++) { + const element = component.element; + const propertyName = component.propertyName; + const style = this.theme_ && this.theme_.getComponentStyle(key); element.style[propertyName] = style || ''; } } @@ -129,7 +129,7 @@ Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { * @package */ Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { - var index = this.subscribedWorkspaces_.indexOf(workspace); + const index = this.subscribedWorkspaces_.indexOf(workspace); if (index < 0) { throw Error('Cannot unsubscribe a workspace that hasn\'t been subscribed.'); } @@ -158,7 +158,7 @@ Blockly.ThemeManager.prototype.subscribe = function(element, componentName, }); // Initialize the element with its corresponding theme style. - var style = this.theme_ && this.theme_.getComponentStyle(componentName); + const style = this.theme_ && this.theme_.getComponentStyle(componentName); element.style[propertyName] = style || ''; }; @@ -172,10 +172,10 @@ Blockly.ThemeManager.prototype.unsubscribe = function(element) { return; } // Go through all component, and remove any references to this element. - var componentNames = Object.keys(this.componentDB_); - for (var c = 0, componentName; (componentName = componentNames[c]); c++) { - var elements = this.componentDB_[componentName]; - for (var i = elements.length - 1; i >= 0; i--) { + const componentNames = Object.keys(this.componentDB_); + for (let c = 0, componentName; (componentName = componentNames[c]); c++) { + const elements = this.componentDB_[componentName]; + for (let i = elements.length - 1; i >= 0; i--) { if (elements[i].element === element) { elements.splice(i, 1); } From 48d422159b246c1062ff413f02ca51c4916bf7fc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:48:59 -0700 Subject: [PATCH 302/313] Migrate core/theme_manager.js to goog.module --- core/theme_manager.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index d432e0dd0..3b43f2f55 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.ThemeManager'); +goog.module('Blockly.ThemeManager'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Theme'); @@ -27,7 +28,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -Blockly.ThemeManager = function(workspace, theme) { +const ThemeManager = function(workspace, theme) { /** * The main workspace. @@ -52,7 +53,7 @@ Blockly.ThemeManager = function(workspace, theme) { /** * A map of subscribed UI components, keyed by component name. - * @type {!Object>} + * @type {!Object>} * @private */ this.componentDB_ = Object.create(null); @@ -65,14 +66,14 @@ Blockly.ThemeManager = function(workspace, theme) { * propertyName:string * }} */ -Blockly.ThemeManager.Component; +ThemeManager.Component; /** * Get the workspace theme. * @return {!Blockly.Theme} The workspace theme. * @package */ -Blockly.ThemeManager.prototype.getTheme = function() { +ThemeManager.prototype.getTheme = function() { return this.theme_; }; @@ -81,7 +82,7 @@ Blockly.ThemeManager.prototype.getTheme = function() { * @param {!Blockly.Theme} theme The workspace theme. * @package */ -Blockly.ThemeManager.prototype.setTheme = function(theme) { +ThemeManager.prototype.setTheme = function(theme) { const prevTheme = this.theme_; this.theme_ = theme; @@ -119,7 +120,7 @@ Blockly.ThemeManager.prototype.setTheme = function(theme) { * @param {!Blockly.Workspace} workspace The workspace to subscribe. * @package */ -Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { +ThemeManager.prototype.subscribeWorkspace = function(workspace) { this.subscribedWorkspaces_.push(workspace); }; @@ -128,7 +129,7 @@ Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { * @param {!Blockly.Workspace} workspace The workspace to unsubscribe. * @package */ -Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { +ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { const index = this.subscribedWorkspaces_.indexOf(workspace); if (index < 0) { throw Error('Cannot unsubscribe a workspace that hasn\'t been subscribed.'); @@ -145,7 +146,7 @@ Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { * @param {string} propertyName The inline style property name to update. * @package */ -Blockly.ThemeManager.prototype.subscribe = function(element, componentName, +ThemeManager.prototype.subscribe = function(element, componentName, propertyName) { if (!this.componentDB_[componentName]) { this.componentDB_[componentName] = []; @@ -167,7 +168,7 @@ Blockly.ThemeManager.prototype.subscribe = function(element, componentName, * @param {Element} element The element to unsubscribe. * @package */ -Blockly.ThemeManager.prototype.unsubscribe = function(element) { +ThemeManager.prototype.unsubscribe = function(element) { if (!element) { return; } @@ -192,9 +193,11 @@ Blockly.ThemeManager.prototype.unsubscribe = function(element) { * @package * @suppress {checkTypes} */ -Blockly.ThemeManager.prototype.dispose = function() { +ThemeManager.prototype.dispose = function() { this.owner_ = null; this.theme_ = null; this.subscribedWorkspaces_ = null; this.componentDB_ = null; }; + +exports = ThemeManager; diff --git a/tests/deps.js b/tests/deps.js index de575339f..48a76dd48 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -164,7 +164,7 @@ goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); -goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme']); +goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); From 794e28ed481da67009d366e35a60d6de034837ea Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:52:43 -0700 Subject: [PATCH 303/313] Migrate core/theme_manager.js to named requires --- core/theme_manager.js | 33 ++++++++++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index 3b43f2f55..a4f0aed6c 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -15,16 +15,19 @@ goog.module('Blockly.ThemeManager'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Theme'); - -goog.requireType('Blockly.Workspace'); -goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const dom = goog.require('Blockly.utils.dom'); /** * Class for storing and updating a workspace's theme and UI components. - * @param {!Blockly.WorkspaceSvg} workspace The main workspace. - * @param {!Blockly.Theme} theme The workspace theme. + * @param {!WorkspaceSvg} workspace The main workspace. + * @param {!Theme} theme The workspace theme. * @constructor * @package */ @@ -32,21 +35,21 @@ const ThemeManager = function(workspace, theme) { /** * The main workspace. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; /** * The Blockly theme to use. - * @type {!Blockly.Theme} + * @type {!Theme} * @private */ this.theme_ = theme; /** * A list of workspaces that are subscribed to this theme. - * @type {!Array} + * @type {!Array} * @private */ this.subscribedWorkspaces_ = []; @@ -70,7 +73,7 @@ ThemeManager.Component; /** * Get the workspace theme. - * @return {!Blockly.Theme} The workspace theme. + * @return {!Theme} The workspace theme. * @package */ ThemeManager.prototype.getTheme = function() { @@ -79,7 +82,7 @@ ThemeManager.prototype.getTheme = function() { /** * Set the workspace theme, and refresh the workspace and all components. - * @param {!Blockly.Theme} theme The workspace theme. + * @param {!Theme} theme The workspace theme. * @package */ ThemeManager.prototype.setTheme = function(theme) { @@ -90,9 +93,9 @@ ThemeManager.prototype.setTheme = function(theme) { const injectionDiv = this.workspace_.getInjectionDiv(); if (injectionDiv) { if (prevTheme) { - Blockly.utils.dom.removeClass(injectionDiv, prevTheme.getClassName()); + dom.removeClass(injectionDiv, prevTheme.getClassName()); } - Blockly.utils.dom.addClass(injectionDiv, this.theme_.getClassName()); + dom.addClass(injectionDiv, this.theme_.getClassName()); } // Refresh all subscribed workspaces. @@ -117,7 +120,7 @@ ThemeManager.prototype.setTheme = function(theme) { /** * Subscribe a workspace to changes to the selected theme. If a new theme is * set, the workspace is called to refresh its blocks. - * @param {!Blockly.Workspace} workspace The workspace to subscribe. + * @param {!Workspace} workspace The workspace to subscribe. * @package */ ThemeManager.prototype.subscribeWorkspace = function(workspace) { @@ -126,7 +129,7 @@ ThemeManager.prototype.subscribeWorkspace = function(workspace) { /** * Unsubscribe a workspace to changes to the selected theme. - * @param {!Blockly.Workspace} workspace The workspace to unsubscribe. + * @param {!Workspace} workspace The workspace to unsubscribe. * @package */ ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { diff --git a/tests/deps.js b/tests/deps.js index 48a76dd48..6affa4354 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -164,7 +164,7 @@ goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); -goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); From d2a6e93a8a168c2ed87ea3370011de6cffc20722 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:53:07 -0700 Subject: [PATCH 304/313] clang-format core/theme_manager.js --- core/theme_manager.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index a4f0aed6c..859a33658 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -32,7 +32,6 @@ const dom = goog.require('Blockly.utils.dom'); * @package */ const ThemeManager = function(workspace, theme) { - /** * The main workspace. * @type {!WorkspaceSvg} @@ -65,10 +64,10 @@ const ThemeManager = function(workspace, theme) { /** * A Blockly UI component type. * @typedef {{ - * element:!Element, - * propertyName:string - * }} - */ + * element:!Element, + * propertyName:string + * }} + */ ThemeManager.Component; /** @@ -104,8 +103,8 @@ ThemeManager.prototype.setTheme = function(theme) { } // Refresh all registered Blockly UI components. - for (let i = 0, keys = Object.keys(this.componentDB_), - key; (key = keys[i]); i++) { + for (let i = 0, keys = Object.keys(this.componentDB_), key; (key = keys[i]); + i++) { for (let j = 0, component; (component = this.componentDB_[key][j]); j++) { const element = component.element; const propertyName = component.propertyName; @@ -149,17 +148,15 @@ ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { * @param {string} propertyName The inline style property name to update. * @package */ -ThemeManager.prototype.subscribe = function(element, componentName, - propertyName) { +ThemeManager.prototype.subscribe = function( + element, componentName, propertyName) { if (!this.componentDB_[componentName]) { this.componentDB_[componentName] = []; } // Add the element to our component map. - this.componentDB_[componentName].push({ - element: element, - propertyName: propertyName - }); + this.componentDB_[componentName].push( + {element: element, propertyName: propertyName}); // Initialize the element with its corresponding theme style. const style = this.theme_ && this.theme_.getComponentStyle(componentName); From f6adf865f29bd9619148a1fbd77ccecfbe25457e Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 23 Jul 2021 19:39:37 +0100 Subject: [PATCH 305/313] Migrate core/utils/size.js to goog.module --- core/utils/size.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/utils/size.js b/core/utils/size.js index 2ffa91ac1..56ec2eb91 100644 --- a/core/utils/size.js +++ b/core/utils/size.js @@ -13,10 +13,11 @@ 'use strict'; /** - * @name Blockly.utils.Size + * @name Size * @namespace */ -goog.provide('Blockly.utils.Size'); +goog.module('Blockly.utils.Size'); +goog.module.declareLegacyNamespace(); /** @@ -26,7 +27,7 @@ goog.provide('Blockly.utils.Size'); * @struct * @constructor */ -Blockly.utils.Size = function(width, height) { +const Size = function(width, height) { /** * Width * @type {number} @@ -42,12 +43,12 @@ Blockly.utils.Size = function(width, height) { /** * Compares sizes for equality. - * @param {?Blockly.utils.Size} a A Size. - * @param {?Blockly.utils.Size} b A Size. + * @param {?Size} a A Size. + * @param {?Size} b A Size. * @return {boolean} True iff the sizes have equal widths and equal * heights, or if both are null. */ -Blockly.utils.Size.equals = function(a, b) { +Size.equals = function(a, b) { if (a == b) { return true; } @@ -56,3 +57,5 @@ Blockly.utils.Size.equals = function(a, b) { } return a.width == b.width && a.height == b.height; }; + +exports = Size; diff --git a/tests/deps.js b/tests/deps.js index ae77407c9..c9fc4067f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -187,7 +187,7 @@ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lan goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); +goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); 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'], []); From 61bbffc29e28af25531c081760f9ddee9766d48f Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:03:46 -0700 Subject: [PATCH 306/313] Migrate core/zoom_controls.js to ES6 const/let --- core/zoom_controls.js | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 7d0d7e6ce..465a5d165 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -182,7 +182,7 @@ Blockly.ZoomControls.prototype.createDom = function() { // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. // https://neil.fraser.name/news/2015/11/01/ - var rnd = String(Math.random()).substring(2); + const rnd = String(Math.random()).substring(2); this.createZoomOutSvg_(rnd); this.createZoomInSvg_(rnd); if (this.workspace_.isMovable()) { @@ -232,12 +232,12 @@ Blockly.ZoomControls.prototype.dispose = function() { * bounding box should be ignored by other UI elements. */ Blockly.ZoomControls.prototype.getBoundingRectangle = function() { - var height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; + let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - var bottom = this.top_ + height; - var right = this.left_ + this.WIDTH_; + const bottom = this.top_ + height; + const right = this.left_ + this.WIDTH_; return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); }; @@ -256,41 +256,41 @@ Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { return; } - var cornerPosition = + const cornerPosition = Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); - var height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; + let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - var startRect = Blockly.uiPosition.getStartPositionRect( + const startRect = Blockly.uiPosition.getStartPositionRect( cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); - var verticalPosition = cornerPosition.vertical; - var bumpDirection = + const verticalPosition = cornerPosition.vertical; + const bumpDirection = verticalPosition === Blockly.uiPosition.verticalPosition.TOP ? Blockly.uiPosition.bumpDirection.DOWN : Blockly.uiPosition.bumpDirection.UP; - var positionRect = Blockly.uiPosition.bumpPositionRect( + const positionRect = Blockly.uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); if (verticalPosition === Blockly.uiPosition.verticalPosition.TOP) { - var zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; + const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); if (this.zoomResetGroup_) { - var zoomResetTranslateY = + const zoomResetTranslateY = zoomInTranslateY + this.LARGE_SPACING_ + this.HEIGHT_; this.zoomResetGroup_.setAttribute('transform', 'translate(0, ' + zoomResetTranslateY + ')'); } } else { - var zoomInTranslateY = this.zoomResetGroup_ ? + const zoomInTranslateY = this.zoomResetGroup_ ? this.LARGE_SPACING_ + this.HEIGHT_ : 0; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); - var zoomOutTranslateY = + const zoomOutTranslateY = zoomInTranslateY + this.SMALL_SPACING_ + this.HEIGHT_; this.zoomOutGroup_.setAttribute('transform', 'translate(0, ' + zoomOutTranslateY + ')'); @@ -322,7 +322,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { this.zoomOutGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoomoutClipPath' + rnd @@ -335,7 +335,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { 'height': 32, }, clip); - var zoomoutSvg = Blockly.utils.dom.createSvgElement( + const zoomoutSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -374,7 +374,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { this.zoomInGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoominClipPath' + rnd @@ -387,7 +387,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { 'height': 32, }, clip); - var zoominSvg = Blockly.utils.dom.createSvgElement( + const zoominSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -443,7 +443,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { this.zoomResetGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoomresetClipPath' + rnd @@ -456,7 +456,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { 'height': 32 }, clip); - var zoomresetSvg = Blockly.utils.dom.createSvgElement( + const zoomresetSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -484,14 +484,14 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { // zoom is passed amount and computes the new scale using the formula: // targetScale = currentScale * Math.pow(speed, amount) - var targetScale = this.workspace_.options.zoomOptions.startScale; - var currentScale = this.workspace_.scale; - var speed = this.workspace_.options.zoomOptions.scaleSpeed; + const targetScale = this.workspace_.options.zoomOptions.startScale; + const currentScale = this.workspace_.scale; + const speed = this.workspace_.options.zoomOptions.scaleSpeed; // To compute amount: // amount = log(speed, (targetScale / currentScale)) // Math.log computes natural logarithm (ln), to change the base, use formula: // log(base, value) = ln(value) / ln(base) - var amount = Math.log(targetScale / currentScale) / Math.log(speed); + const amount = Math.log(targetScale / currentScale) / Math.log(speed); this.workspace_.beginCanvasTransition(); this.workspace_.zoomCenter(amount); this.workspace_.scrollCenter(); @@ -508,7 +508,7 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { * @private */ Blockly.ZoomControls.prototype.fireZoomEvent_ = function() { - var uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( + const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); Blockly.Events.fire(uiEvent); }; From bc7c5115e1ca36f235a64052584878cb49b8b8e4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:03:55 -0700 Subject: [PATCH 307/313] Migrate core/zoom_controls.js to goog.module --- core/zoom_controls.js | 50 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 465a5d165..61455c120 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -10,8 +10,10 @@ */ 'use strict'; -goog.provide('Blockly.ZoomControls'); +goog.module('Blockly.ZoomControls'); +goog.module.declareLegacyNamespace(); +goog.require('Blockly'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.Css'); @@ -36,7 +38,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @implements {Blockly.IPositionable} */ -Blockly.ZoomControls = function(workspace) { +const ZoomControls = function(workspace) { /** * @type {!Blockly.WorkspaceSvg} * @private @@ -102,7 +104,7 @@ Blockly.ZoomControls = function(workspace) { * @const * @private */ -Blockly.ZoomControls.prototype.WIDTH_ = 32; +ZoomControls.prototype.WIDTH_ = 32; /** * Height of each zoom control. @@ -110,7 +112,7 @@ Blockly.ZoomControls.prototype.WIDTH_ = 32; * @const * @private */ -Blockly.ZoomControls.prototype.HEIGHT_ = 32; +ZoomControls.prototype.HEIGHT_ = 32; /** * Small spacing used between the zoom in and out control, in pixels. @@ -118,7 +120,7 @@ Blockly.ZoomControls.prototype.HEIGHT_ = 32; * @const * @private */ -Blockly.ZoomControls.prototype.SMALL_SPACING_ = 2; +ZoomControls.prototype.SMALL_SPACING_ = 2; /** * Large spacing used between the zoom in and reset control, in pixels. @@ -126,7 +128,7 @@ Blockly.ZoomControls.prototype.SMALL_SPACING_ = 2; * @const * @private */ -Blockly.ZoomControls.prototype.LARGE_SPACING_ = 11; +ZoomControls.prototype.LARGE_SPACING_ = 11; /** * Distance between zoom controls and bottom or top edge of workspace. @@ -134,48 +136,48 @@ Blockly.ZoomControls.prototype.LARGE_SPACING_ = 11; * @const * @private */ -Blockly.ZoomControls.prototype.MARGIN_VERTICAL_ = 20; +ZoomControls.prototype.MARGIN_VERTICAL_ = 20; /** * Distance between zoom controls and right or left edge of workspace. * @type {number} * @private */ -Blockly.ZoomControls.prototype.MARGIN_HORIZONTAL_ = 20; +ZoomControls.prototype.MARGIN_HORIZONTAL_ = 20; /** * The SVG group containing the zoom controls. * @type {SVGElement} * @private */ -Blockly.ZoomControls.prototype.svgGroup_ = null; +ZoomControls.prototype.svgGroup_ = null; /** * Left coordinate of the zoom controls. * @type {number} * @private */ -Blockly.ZoomControls.prototype.left_ = 0; +ZoomControls.prototype.left_ = 0; /** * Top coordinate of the zoom controls. * @type {number} * @private */ -Blockly.ZoomControls.prototype.top_ = 0; +ZoomControls.prototype.top_ = 0; /** * Whether this has been initialized. * @type {boolean} * @private */ -Blockly.ZoomControls.prototype.initialized_ = false; +ZoomControls.prototype.initialized_ = false; /** * Create the zoom controls. * @return {!SVGElement} The zoom controls SVG group. */ -Blockly.ZoomControls.prototype.createDom = function() { +ZoomControls.prototype.createDom = function() { this.svgGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {}, null); @@ -196,7 +198,7 @@ Blockly.ZoomControls.prototype.createDom = function() { /** * Initializes the zoom controls. */ -Blockly.ZoomControls.prototype.init = function() { +ZoomControls.prototype.init = function() { this.workspace_.getComponentManager().addComponent({ component: this, weight: 2, @@ -209,7 +211,7 @@ Blockly.ZoomControls.prototype.init = function() { * Disposes of this zoom controls. * Unlink from all DOM elements to prevent memory leaks. */ -Blockly.ZoomControls.prototype.dispose = function() { +ZoomControls.prototype.dispose = function() { this.workspace_.getComponentManager().removeComponent('zoomControls'); if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); @@ -231,7 +233,7 @@ Blockly.ZoomControls.prototype.dispose = function() { * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ -Blockly.ZoomControls.prototype.getBoundingRectangle = function() { +ZoomControls.prototype.getBoundingRectangle = function() { let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; @@ -250,7 +252,7 @@ Blockly.ZoomControls.prototype.getBoundingRectangle = function() { * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ -Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { +ZoomControls.prototype.position = function(metrics, savedPositions) { // Not yet initialized. if (!this.initialized_) { return; @@ -309,7 +311,7 @@ Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { +ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -361,7 +363,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { +ZoomControls.prototype.createZoomInSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -414,7 +416,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { * @param {!Event} e A mouse down event. * @private */ -Blockly.ZoomControls.prototype.zoom_ = function(amount, e) { +ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.markFocused(); this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); @@ -430,7 +432,7 @@ Blockly.ZoomControls.prototype.zoom_ = function(amount, e) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { +ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -479,7 +481,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { * @param {!Event} e A mouse down event. * @private */ -Blockly.ZoomControls.prototype.resetZoom_ = function(e) { +ZoomControls.prototype.resetZoom_ = function(e) { this.workspace_.markFocused(); // zoom is passed amount and computes the new scale using the formula: @@ -507,7 +509,7 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { * Fires a zoom control UI event. * @private */ -Blockly.ZoomControls.prototype.fireZoomEvent_ = function() { +ZoomControls.prototype.fireZoomEvent_ = function() { const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); Blockly.Events.fire(uiEvent); @@ -531,3 +533,5 @@ Blockly.Css.register([ '}' /* eslint-enable indent */ ]); + +exports = ZoomControls; diff --git a/tests/deps.js b/tests/deps.js index 702bf5ae4..c61cd74c1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -210,6 +210,6 @@ goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.Workspa goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('base.js', [], []); From 40c095f496a8d901d97b0b3506fdc586e0f12101 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:05:49 -0700 Subject: [PATCH 308/313] Migrate core/zoom_controls.js named requires --- core/zoom_controls.js | 166 +++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 61455c120..84451bbd1 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -13,34 +13,34 @@ goog.module('Blockly.ZoomControls'); goog.module.declareLegacyNamespace(); -goog.require('Blockly'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.ComponentManager'); -goog.require('Blockly.Css'); -goog.require('Blockly.Events'); +const Blockly = goog.require('Blockly'); +const ComponentManager = goog.require('Blockly.ComponentManager'); +const Css = goog.require('Blockly.Css'); +const Events = goog.require('Blockly.Events'); +const IPositionable = goog.require('Blockly.IPositionable'); +const Rect = goog.require('Blockly.utils.Rect'); +const Svg = goog.require('Blockly.utils.Svg'); +const Touch = goog.require('Blockly.Touch'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const internalConstants = goog.require('Blockly.internalConstants'); +const uiPosition = goog.require('Blockly.uiPosition'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); -goog.require('Blockly.IPositionable'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.Touch'); -goog.require('Blockly.uiPosition'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.WorkspaceSvg'); /** * Class for a zoom controls. - * @param {!Blockly.WorkspaceSvg} workspace The workspace to sit in. + * @param {!WorkspaceSvg} workspace The workspace to sit in. * @constructor - * @implements {Blockly.IPositionable} + * @implements {IPositionable} */ const ZoomControls = function(workspace) { /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; @@ -55,7 +55,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom reset * button. Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomResetWrapper_ = null; @@ -63,7 +63,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom in button. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomInWrapper_ = null; @@ -71,7 +71,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom out button. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomOutWrapper_ = null; @@ -178,8 +178,8 @@ ZoomControls.prototype.initialized_ = false; * @return {!SVGElement} The zoom controls SVG group. */ ZoomControls.prototype.createDom = function() { - this.svgGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, {}, null); + this.svgGroup_ = dom.createSvgElement( + Svg.G, {}, null); // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. @@ -202,7 +202,7 @@ ZoomControls.prototype.init = function() { this.workspace_.getComponentManager().addComponent({ component: this, weight: 2, - capabilities: [Blockly.ComponentManager.Capability.POSITIONABLE] + capabilities: [ComponentManager.Capability.POSITIONABLE] }); this.initialized_ = true; }; @@ -214,23 +214,23 @@ ZoomControls.prototype.init = function() { ZoomControls.prototype.dispose = function() { this.workspace_.getComponentManager().removeComponent('zoomControls'); if (this.svgGroup_) { - Blockly.utils.dom.removeNode(this.svgGroup_); + dom.removeNode(this.svgGroup_); } if (this.onZoomResetWrapper_) { - Blockly.browserEvents.unbind(this.onZoomResetWrapper_); + browserEvents.unbind(this.onZoomResetWrapper_); } if (this.onZoomInWrapper_) { - Blockly.browserEvents.unbind(this.onZoomInWrapper_); + browserEvents.unbind(this.onZoomInWrapper_); } if (this.onZoomOutWrapper_) { - Blockly.browserEvents.unbind(this.onZoomOutWrapper_); + browserEvents.unbind(this.onZoomOutWrapper_); } }; /** * 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. */ ZoomControls.prototype.getBoundingRectangle = function() { @@ -240,7 +240,7 @@ ZoomControls.prototype.getBoundingRectangle = function() { } const bottom = this.top_ + height; const right = this.left_ + this.WIDTH_; - return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); + return new Rect(this.top_, bottom, this.left_, right); }; @@ -249,7 +249,7 @@ ZoomControls.prototype.getBoundingRectangle = function() { * It is positioned in the opposite corner to the corner the * categories/toolbox starts at. * @param {!Blockly.MetricsManager.UiMetrics} metrics The workspace metrics. - * @param {!Array} savedPositions List of rectangles that + * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ ZoomControls.prototype.position = function(metrics, savedPositions) { @@ -259,25 +259,25 @@ ZoomControls.prototype.position = function(metrics, savedPositions) { } const cornerPosition = - Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); + uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - const startRect = Blockly.uiPosition.getStartPositionRect( - cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), + const startRect = uiPosition.getStartPositionRect( + cornerPosition, new utils.Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); const verticalPosition = cornerPosition.vertical; const bumpDirection = - verticalPosition === Blockly.uiPosition.verticalPosition.TOP ? - Blockly.uiPosition.bumpDirection.DOWN : - Blockly.uiPosition.bumpDirection.UP; - const positionRect = Blockly.uiPosition.bumpPositionRect( + verticalPosition === uiPosition.verticalPosition.TOP ? + uiPosition.bumpDirection.DOWN : + uiPosition.bumpDirection.UP; + const positionRect = uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); - if (verticalPosition === Blockly.uiPosition.verticalPosition.TOP) { + if (verticalPosition === uiPosition.verticalPosition.TOP) { const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); @@ -321,38 +321,38 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { clip-path="url(#blocklyZoomoutClipPath837493)"> */ - this.zoomOutGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomOutGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoomoutClipPath' + rnd }, this.zoomOutGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32, }, clip); - const zoomoutSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoomoutSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'x': -64, 'y': -92, 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')' }, this.zoomOutGroup_); zoomoutSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach listener. - this.onZoomOutWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomOutWrapper_ = browserEvents.conditionalBind( this.zoomOutGroup_, 'mousedown', null, this.zoom_.bind(this, -1)); }; @@ -373,38 +373,38 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { clip-path="url(#blocklyZoominClipPath837493)"> */ - this.zoomInGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomInGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoominClipPath' + rnd }, this.zoomInGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32, }, clip); - const zoominSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoominSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'x': -32, 'y': -92, 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')' }, this.zoomInGroup_); zoominSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach listener. - this.onZoomInWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomInWrapper_ = browserEvents.conditionalBind( this.zoomInGroup_, 'mousedown', null, this.zoom_.bind(this, 1)); }; @@ -420,7 +420,7 @@ ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.markFocused(); this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); - Blockly.Touch.clearTouchIdentifier(); // Don't block future drags. + Touch.clearTouchIdentifier(); // Don't block future drags. e.stopPropagation(); // Don't start a workspace scroll. e.preventDefault(); // Stop double-clicking from selecting text. }; @@ -442,37 +442,37 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { clip-path="url(#blocklyZoomresetClipPath837493)"> */ - this.zoomResetGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomResetGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoomresetClipPath' + rnd }, this.zoomResetGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32 }, clip); - const zoomresetSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoomresetSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'y': -92, 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')' }, this.zoomResetGroup_); zoomresetSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach event listeners. - this.onZoomResetWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomResetWrapper_ = browserEvents.conditionalBind( this.zoomResetGroup_, 'mousedown', null, this.resetZoom_.bind(this)); }; @@ -500,7 +500,7 @@ ZoomControls.prototype.resetZoom_ = function(e) { setTimeout(this.workspace_.endCanvasTransition.bind(this.workspace_), 500); this.fireZoomEvent_(); - Blockly.Touch.clearTouchIdentifier(); // Don't block future drags. + Touch.clearTouchIdentifier(); // Don't block future drags. e.stopPropagation(); // Don't start a workspace scroll. e.preventDefault(); // Stop double-clicking from selecting text. }; @@ -510,15 +510,15 @@ ZoomControls.prototype.resetZoom_ = function(e) { * @private */ ZoomControls.prototype.fireZoomEvent_ = function() { - const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( + const uiEvent = new (Events.get(Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); - Blockly.Events.fire(uiEvent); + Events.fire(uiEvent); }; /** * CSS for zoom controls. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyZoom>image, .blocklyZoom>svg>image {', 'opacity: .4;', From 5a5aabb7e7a759ce254cd675be84ad8e297285b8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:09:14 -0700 Subject: [PATCH 309/313] clang-format core/zoom_controls.js --- core/zoom_controls.js | 133 +++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 80 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 84451bbd1..37c1cb17d 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -178,8 +178,7 @@ ZoomControls.prototype.initialized_ = false; * @return {!SVGElement} The zoom controls SVG group. */ ZoomControls.prototype.createDom = function() { - this.svgGroup_ = dom.createSvgElement( - Svg.G, {}, null); + this.svgGroup_ = dom.createSvgElement(Svg.G, {}, null); // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. @@ -266,42 +265,40 @@ ZoomControls.prototype.position = function(metrics, savedPositions) { } const startRect = uiPosition.getStartPositionRect( cornerPosition, new utils.Size(this.WIDTH_, height), - this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, - this.workspace_); + this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); const verticalPosition = cornerPosition.vertical; - const bumpDirection = - verticalPosition === uiPosition.verticalPosition.TOP ? - uiPosition.bumpDirection.DOWN : - uiPosition.bumpDirection.UP; + const bumpDirection = verticalPosition === uiPosition.verticalPosition.TOP ? + uiPosition.bumpDirection.DOWN : + uiPosition.bumpDirection.UP; const positionRect = uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); if (verticalPosition === uiPosition.verticalPosition.TOP) { const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; - this.zoomInGroup_.setAttribute('transform', - 'translate(0, ' + zoomInTranslateY + ')'); + this.zoomInGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomInTranslateY + ')'); if (this.zoomResetGroup_) { const zoomResetTranslateY = zoomInTranslateY + this.LARGE_SPACING_ + this.HEIGHT_; - this.zoomResetGroup_.setAttribute('transform', - 'translate(0, ' + zoomResetTranslateY + ')'); + this.zoomResetGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomResetTranslateY + ')'); } } else { - const zoomInTranslateY = this.zoomResetGroup_ ? - this.LARGE_SPACING_ + this.HEIGHT_ : 0; - this.zoomInGroup_.setAttribute('transform', - 'translate(0, ' + zoomInTranslateY + ')'); + const zoomInTranslateY = + this.zoomResetGroup_ ? this.LARGE_SPACING_ + this.HEIGHT_ : 0; + this.zoomInGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomInTranslateY + ')'); const zoomOutTranslateY = zoomInTranslateY + this.SMALL_SPACING_ + this.HEIGHT_; - this.zoomOutGroup_.setAttribute('transform', - 'translate(0, ' + zoomOutTranslateY + ')'); + this.zoomOutGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomOutTranslateY + ')'); } this.top_ = positionRect.top; this.left_ = positionRect.left; - this.svgGroup_.setAttribute('transform', - 'translate(' + this.left_ + ',' + this.top_ + ')'); + this.svgGroup_.setAttribute( + 'transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); }; /** @@ -317,22 +314,17 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { */ - this.zoomOutGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomOutGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoomoutClipPath' + rnd - }, - this.zoomOutGroup_); + Svg.CLIPPATH, {'id': 'blocklyZoomoutClipPath' + rnd}, this.zoomOutGroup_); dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'width': 32, 'height': 32, }, @@ -348,8 +340,7 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { this.zoomOutGroup_); zoomoutSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach listener. this.onZoomOutWrapper_ = browserEvents.conditionalBind( @@ -369,22 +360,17 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { - */ - this.zoomInGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomInGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoominClipPath' + rnd - }, - this.zoomInGroup_); + Svg.CLIPPATH, {'id': 'blocklyZoominClipPath' + rnd}, this.zoomInGroup_); dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'width': 32, 'height': 32, }, @@ -400,8 +386,7 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { this.zoomInGroup_); zoominSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach listener. this.onZoomInWrapper_ = browserEvents.conditionalBind( @@ -421,8 +406,8 @@ ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); Touch.clearTouchIdentifier(); // Don't block future drags. - e.stopPropagation(); // Don't start a workspace scroll. - e.preventDefault(); // Stop double-clicking from selecting text. + e.stopPropagation(); // Don't start a workspace scroll. + e.preventDefault(); // Stop double-clicking from selecting text. }; /** @@ -438,26 +423,17 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { - */ - this.zoomResetGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomResetGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoomresetClipPath' + rnd - }, + Svg.CLIPPATH, {'id': 'blocklyZoomresetClipPath' + rnd}, this.zoomResetGroup_); - dom.createSvgElement( - Svg.RECT, - { - 'width': 32, - 'height': 32 - }, - clip); + dom.createSvgElement(Svg.RECT, {'width': 32, 'height': 32}, clip); const zoomresetSvg = dom.createSvgElement( Svg.IMAGE, { 'width': internalConstants.SPRITE.width, @@ -468,8 +444,7 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { this.zoomResetGroup_); zoomresetSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach event listeners. this.onZoomResetWrapper_ = browserEvents.conditionalBind( @@ -501,8 +476,8 @@ ZoomControls.prototype.resetZoom_ = function(e) { setTimeout(this.workspace_.endCanvasTransition.bind(this.workspace_), 500); this.fireZoomEvent_(); Touch.clearTouchIdentifier(); // Don't block future drags. - e.stopPropagation(); // Don't start a workspace scroll. - e.preventDefault(); // Stop double-clicking from selecting text. + e.stopPropagation(); // Don't start a workspace scroll. + e.preventDefault(); // Stop double-clicking from selecting text. }; /** @@ -510,8 +485,8 @@ ZoomControls.prototype.resetZoom_ = function(e) { * @private */ ZoomControls.prototype.fireZoomEvent_ = function() { - const uiEvent = new (Events.get(Events.CLICK))( - null, this.workspace_.id, 'zoom_controls'); + const uiEvent = + new (Events.get(Events.CLICK))(null, this.workspace_.id, 'zoom_controls'); Events.fire(uiEvent); }; @@ -519,19 +494,17 @@ ZoomControls.prototype.fireZoomEvent_ = function() { * CSS for zoom controls. See css.js for use. */ Css.register([ - /* eslint-disable indent */ - '.blocklyZoom>image, .blocklyZoom>svg>image {', - 'opacity: .4;', - '}', + `.blocklyZoom>image, .blocklyZoom>svg>image { + opacity: .4; +}`, - '.blocklyZoom>image:hover, .blocklyZoom>svg>image:hover {', - 'opacity: .6;', - '}', + `.blocklyZoom>image:hover, .blocklyZoom>svg>image:hover { + opacity: .6; +}`, - '.blocklyZoom>image:active, .blocklyZoom>svg>image:active {', - 'opacity: .8;', - '}' - /* eslint-enable indent */ + `.blocklyZoom>image:active, .blocklyZoom>svg>image:active { + 'opacity: .8; +}` ]); exports = ZoomControls; From 636cd58add1b0449e6b91d660374eecd1eedae4d Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 12:35:21 -0700 Subject: [PATCH 310/313] Add comment to top of convert-file script for reference to syntax used throughout the file --- scripts/goog_module/convert-file.sh | 55 +++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 6a8d36cd0..9f8ea63ee 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -1,5 +1,39 @@ #!/bin/bash +# This file makes extensive use of perl for the purpose of extracting and +# replacing string (regex) patterns in a way that is both GNU and macOS +# compatible. +# +# Common perl flags used (also decribed at https://perldoc.perl.org/perlrun): +# -e : Used to execute perl programs on the command line +# -p : Assumes an input loop around script. Prints every processed line. +# -n : Assumes an input loop around script. Does not print every line. +# -i : Used for in-place editing. Used for commands for find/replace. +# -l[octnum] : Assigns the output record separator "$/" as an octal number. If +# octnum is not present, sets output record separator to the current +# value of the input record separator "$\". +# +# Common perl commands found: +# 1. perl -pi -e 's/regex/replacement/modifiers' +# This command does an in-place search-and-replace. The global ("/g") modifier +# causes it to replace all occurrences, rather than only the first match. +# 2. perl -ne 'print m/regex/modifiers' +# This command returns the all regex matches. If the global ("/g") modifier is +# specified, then the capture group "()" is not necessary and it will return +# all matches, rather than only the first match. +# 3. perl -nle 'print $& while m{regex}modifiers' +# Similar to (2), but returns regex matches separated by newlines. +# The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. +# +# Additional information on regex: +# This script makes use of some advanced regex syntax such as "capture groups" +# and "lookaround assertions". +# Additionally, characters are escaped from regex with a backslash "\". +# Single quotes need to be escaped in both regex and the string, resulting in +# '\'' being used to represent a single quote character. +# For a reference to syntax of regular expressions in Perl, see: +# https://perldoc.perl.org/perire + ####################################### # Logging functions. ####################################### @@ -98,10 +132,10 @@ step2 () { local filepath="$1" inf "Updating goog.provide declaration..." - perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/g' "${filepath}" + perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/' "${filepath}" inf "Extracting module name..." - local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") + local module_name=$(perl -ne 'print m/(?<=^goog\.module\('\'')([^'\'']+)/' "${filepath}") if [[ -z "${module_name}" ]]; then err "Could not extract module name" return 1 @@ -109,7 +143,7 @@ step2 () { inf "Extracted module name \"${module_name}\"" if [[ $(grep "${module_name} = " "${filepath}") ]]; then - local class_name=$(echo "${module_name}" | perl -nle'print $& while m{(\w+)$}g') + local class_name=$(echo "${module_name}" | perl -ne 'print m/(\w+)$/') inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" @@ -144,19 +178,19 @@ step2 () { ####################################### step3() { inf "Extracting module name..." - local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") + local module_name=$(perl -ne 'print m/(?<=^goog\.module\('\'')([^'\'']+)/' "${filepath}") if [[ -z "${module_name}" ]]; then err "Could not extract module name" return 1 fi inf "Extracted module name \"${module_name}\"" - local requires=$(perl -nle'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") + local requires=$(perl -nle 'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") # Process each require echo "${requires}" | while read -r require; do inf "Processing require \"${require}\"" - local usages=$(perl -nle'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) + local usages=$(perl -nle 'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) if [[ "${usages}" -eq "0" ]]; then warn "Unused require \"${require}\"" @@ -168,11 +202,12 @@ step3() { perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" # Parse property access of module - local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) - local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) + local direct_access_count=$(perl -nle 'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) + local properties_accessed=$(perl -nle 'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | sort -u) + # Detect requires overlap # (ex: Blockly.utils require and Blockly.utils.dom also in requires) - local requires_overlap=$(echo "${requires}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + local requires_overlap=$(echo "${requires}" | perl -nle 'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ -n "${requires_overlap}" ]]; then while read -r requires_overlap_prop; do properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') @@ -180,7 +215,7 @@ step3() { fi # Detect module name overlap # (ex: Blockly require and Blockly.ContextMenuItems module being converted) - local module_overlap=$(echo "${module_name}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + local module_overlap=$(echo "${module_name}" | perl -nle 'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ -n "${module_overlap}" ]]; then properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') fi From f64e8df4866056444c44505f771397e40ea0fed1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 15:26:16 -0700 Subject: [PATCH 311/313] Update wording --- scripts/goog_module/convert-file.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 9f8ea63ee..0246be0be 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -18,9 +18,10 @@ # This command does an in-place search-and-replace. The global ("/g") modifier # causes it to replace all occurrences, rather than only the first match. # 2. perl -ne 'print m/regex/modifiers' -# This command returns the all regex matches. If the global ("/g") modifier is -# specified, then the capture group "()" is not necessary and it will return -# all matches, rather than only the first match. +# This command returns a string containing the regex match. The regex must +# contain a capture group "()", unless the global ("\g") modifier is +# specified. This will return the first match, unless the global modifier is +# specified, in which case, it will return all matches. # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. From 3fbbedf6f1c9156b7ddfd64d4e82b8a28271c191 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 18:10:53 -0700 Subject: [PATCH 312/313] Fix typos and update wording again --- scripts/goog_module/convert-file.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 0246be0be..38ac2eafb 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -4,11 +4,11 @@ # replacing string (regex) patterns in a way that is both GNU and macOS # compatible. # -# Common perl flags used (also decribed at https://perldoc.perl.org/perlrun): +# Common perl flags used (also described at https://perldoc.perl.org/perlrun): # -e : Used to execute perl programs on the command line # -p : Assumes an input loop around script. Prints every processed line. # -n : Assumes an input loop around script. Does not print every line. -# -i : Used for in-place editing. Used for commands for find/replace. +# -i : Used for in-place editing. Used in commands for find/replace. # -l[octnum] : Assigns the output record separator "$/" as an octal number. If # octnum is not present, sets output record separator to the current # value of the input record separator "$\". @@ -18,10 +18,11 @@ # This command does an in-place search-and-replace. The global ("/g") modifier # causes it to replace all occurrences, rather than only the first match. # 2. perl -ne 'print m/regex/modifiers' -# This command returns a string containing the regex match. The regex must -# contain a capture group "()", unless the global ("\g") modifier is -# specified. This will return the first match, unless the global modifier is -# specified, in which case, it will return all matches. +# This command returns a string containing the regex match (designated by the +# capture group "()" in the regex). This will return the first match, unless +# the global modifier is specified, in which case, it will return all matches. +# If this command is used without a capture group it returns true or false (in +# the form a truthy or falsey value) # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. @@ -33,7 +34,7 @@ # Single quotes need to be escaped in both regex and the string, resulting in # '\'' being used to represent a single quote character. # For a reference to syntax of regular expressions in Perl, see: -# https://perldoc.perl.org/perire +# https://perldoc.perl.org/perlre ####################################### # Logging functions. @@ -240,7 +241,7 @@ step3() { missing_requires=$(echo "${missing_requires}" | tr ' ' '\n' | sort -u) if [[ -n "${missing_requires}" ]]; then # Search for the string goog.require('Blockly') or goog.requireType('Blockly') - local has_blockly_require=$(perl -ne'print m{goog\.(require|requireType)\('\''Blockly'\''\)}g' "${filepath}") + local has_blockly_require=$(perl -ne 'print m/goog\.(?:require|requireType)\('\''Blockly'\''\)/' "${filepath}") if [[ -n "${has_blockly_require}" ]]; then warn 'Blockly detected as a require.' warn "Potentially missing requires for:\n${missing_requires}\nPlease manually review." From 7495fad6b3d9e489e504f66a7b19e96288df55c4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 18:37:13 -0700 Subject: [PATCH 313/313] Add missing period and fix typo --- scripts/goog_module/convert-file.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 38ac2eafb..ebf791d3b 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -22,7 +22,7 @@ # capture group "()" in the regex). This will return the first match, unless # the global modifier is specified, in which case, it will return all matches. # If this command is used without a capture group it returns true or false (in -# the form a truthy or falsey value) +# the form a truthy or falsy value). # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax.