From 042b235764e98e359d67672121170d487b618534 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:52:17 -0700 Subject: [PATCH 001/291] Migrate core/utils/dom.js to ES6 const/let --- core/utils/dom.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 57843c8b9..049aa9f07 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -84,9 +84,9 @@ Blockly.utils.dom.canvasContext_ = null; * @template T */ Blockly.utils.dom.createSvgElement = function(name, attrs, opt_parent) { - var e = /** @type {T} */ + const e = /** @type {T} */ (document.createElementNS(Blockly.utils.dom.SVG_NS, String(name))); - for (var key in attrs) { + for (const key in attrs) { e.setAttribute(key, attrs[key]); } // IE defines a unique attribute "runtimeStyle", it is NOT applied to @@ -109,7 +109,7 @@ Blockly.utils.dom.createSvgElement = function(name, attrs, opt_parent) { * @return {boolean} True if class was added, false if already present. */ Blockly.utils.dom.addClass = function(element, className) { - var classes = element.getAttribute('class') || ''; + let classes = element.getAttribute('class') || ''; if ((' ' + classes + ' ').indexOf(' ' + className + ' ') != -1) { return false; } @@ -127,9 +127,9 @@ Blockly.utils.dom.addClass = function(element, className) { * element. */ Blockly.utils.dom.removeClasses = function(element, classNames) { - var classList = classNames.split(' '); - for (var i = 0; i < classList.length; i++) { - var cssName = classList[i]; + const classList = classNames.split(' '); + for (let i = 0; i < classList.length; i++) { + const cssName = classList[i]; Blockly.utils.dom.removeClass(element, cssName); } }; @@ -142,12 +142,12 @@ Blockly.utils.dom.removeClasses = function(element, classNames) { * @return {boolean} True if class was removed, false if never present. */ Blockly.utils.dom.removeClass = function(element, className) { - var classes = element.getAttribute('class'); + const classes = element.getAttribute('class'); if ((' ' + classes + ' ').indexOf(' ' + className + ' ') == -1) { return false; } - var classList = classes.split(/\s+/); - for (var i = 0; i < classList.length; i++) { + const classList = classes.split(/\s+/); + for (let i = 0; i < classList.length; i++) { if (!classList[i] || classList[i] == className) { classList.splice(i, 1); i--; @@ -169,7 +169,7 @@ Blockly.utils.dom.removeClass = function(element, className) { * @return {boolean} True if class exists, false otherwise. */ Blockly.utils.dom.hasClass = function(element, className) { - var classes = element.getAttribute('class'); + const classes = element.getAttribute('class'); return (' ' + classes + ' ').indexOf(' ' + className + ' ') != -1; }; @@ -190,8 +190,8 @@ Blockly.utils.dom.removeNode = function(node) { * @param {!Element} refNode Existing element to precede new node. */ Blockly.utils.dom.insertAfter = function(newNode, refNode) { - var siblingNode = refNode.nextSibling; - var parentNode = refNode.parentNode; + const siblingNode = refNode.nextSibling; + const parentNode = refNode.parentNode; if (!parentNode) { throw Error('Reference node has no parent.'); } @@ -253,8 +253,8 @@ Blockly.utils.dom.stopTextWidthCache = function() { * @return {number} Width of element. */ Blockly.utils.dom.getTextWidth = function(textElement) { - var key = textElement.textContent + '\n' + textElement.className.baseVal; - var width; + const key = textElement.textContent + '\n' + textElement.className.baseVal; + let width; // Return the cached width if it exists. if (Blockly.utils.dom.cacheWidths_) { @@ -316,9 +316,9 @@ Blockly.utils.dom.getFastTextWidth = function(textElement, */ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, fontSize, fontWeight, fontFamily) { - var text = textElement.textContent; - var key = text + '\n' + textElement.className.baseVal; - var width; + const text = textElement.textContent; + const key = text + '\n' + textElement.className.baseVal; + let width; // Return the cached width if it exists. if (Blockly.utils.dom.cacheWidths_) { @@ -330,7 +330,7 @@ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, if (!Blockly.utils.dom.canvasContext_) { // Inject the canvas element used for computing text widths. - var computeCanvas = document.createElement('canvas'); + const computeCanvas = document.createElement('canvas'); computeCanvas.className = 'blocklyComputeCanvas'; document.body.appendChild(computeCanvas); @@ -364,15 +364,15 @@ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, Blockly.utils.dom.measureFontMetrics = function(text, fontSize, fontWeight, fontFamily) { - var span = document.createElement('span'); + const span = document.createElement('span'); span.style.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; span.textContent = text; - var block = document.createElement('div'); + const block = document.createElement('div'); block.style.width = '1px'; block.style.height = 0; - var div = document.createElement('div'); + const div = document.createElement('div'); div.setAttribute('style', 'position: fixed; top: 0; left: 0; display: flex;'); div.appendChild(span); div.appendChild(block); From 563defa3badcf64f8f18d8f5c1a4d52017b5313b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 15:01:16 -0700 Subject: [PATCH 002/291] Migrate core/utils/dom.js to goog.module --- core/utils/dom.js | 113 ++++++++++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 049aa9f07..7219bd93c 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -16,7 +16,8 @@ * @name Blockly.utils.dom * @namespace */ -goog.provide('Blockly.utils.dom'); +goog.module('Blockly.utils.dom'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.Svg'); goog.require('Blockly.utils.userAgent'); @@ -26,26 +27,26 @@ goog.require('Blockly.utils.userAgent'); * Required name space for SVG elements. * @const */ -Blockly.utils.dom.SVG_NS = 'http://www.w3.org/2000/svg'; +const SVG_NS = 'http://www.w3.org/2000/svg'; /** * Required name space for HTML elements. * @const */ -Blockly.utils.dom.HTML_NS = 'http://www.w3.org/1999/xhtml'; +const HTML_NS = 'http://www.w3.org/1999/xhtml'; /** * Required name space for XLINK elements. * @const */ -Blockly.utils.dom.XLINK_NS = 'http://www.w3.org/1999/xlink'; +const XLINK_NS = 'http://www.w3.org/1999/xlink'; /** * Node type constants. * https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType * @enum {number} */ -Blockly.utils.dom.NodeType = { +const NodeType = { ELEMENT_NODE: 1, TEXT_NODE: 3, COMMENT_NODE: 8, @@ -57,21 +58,21 @@ Blockly.utils.dom.NodeType = { * @type {Object} * @private */ -Blockly.utils.dom.cacheWidths_ = null; +let cacheWidths = null; /** * Number of current references to cache. * @type {number} * @private */ -Blockly.utils.dom.cacheReference_ = 0; +let cacheReference = 0; /** * A HTML canvas context used for computing text width. * @type {CanvasRenderingContext2D} * @private */ -Blockly.utils.dom.canvasContext_ = null; +let canvasContext = null; /** * Helper method for creating SVG elements. @@ -83,9 +84,9 @@ Blockly.utils.dom.canvasContext_ = null; * Blockly.utils.Svg * @template T */ -Blockly.utils.dom.createSvgElement = function(name, attrs, opt_parent) { +const createSvgElement = function(name, attrs, opt_parent) { const e = /** @type {T} */ - (document.createElementNS(Blockly.utils.dom.SVG_NS, String(name))); + (document.createElementNS(SVG_NS, String(name))); for (const key in attrs) { e.setAttribute(key, attrs[key]); } @@ -108,7 +109,7 @@ Blockly.utils.dom.createSvgElement = function(name, attrs, opt_parent) { * @param {string} className Name of class to add. * @return {boolean} True if class was added, false if already present. */ -Blockly.utils.dom.addClass = function(element, className) { +const addClass = function(element, className) { let classes = element.getAttribute('class') || ''; if ((' ' + classes + ' ').indexOf(' ' + className + ' ') != -1) { return false; @@ -126,11 +127,11 @@ Blockly.utils.dom.addClass = function(element, className) { * @param {string} classNames A string of one or multiple class names for an * element. */ -Blockly.utils.dom.removeClasses = function(element, classNames) { +const removeClasses = function(element, classNames) { const classList = classNames.split(' '); for (let i = 0; i < classList.length; i++) { const cssName = classList[i]; - Blockly.utils.dom.removeClass(element, cssName); + removeClass(element, cssName); } }; @@ -141,7 +142,7 @@ Blockly.utils.dom.removeClasses = function(element, classNames) { * @param {string} className Name of class to remove. * @return {boolean} True if class was removed, false if never present. */ -Blockly.utils.dom.removeClass = function(element, className) { +const removeClass = function(element, className) { const classes = element.getAttribute('class'); if ((' ' + classes + ' ').indexOf(' ' + className + ' ') == -1) { return false; @@ -168,7 +169,7 @@ Blockly.utils.dom.removeClass = function(element, className) { * @param {string} className Name of class to check. * @return {boolean} True if class exists, false otherwise. */ -Blockly.utils.dom.hasClass = function(element, className) { +const hasClass = function(element, className) { const classes = element.getAttribute('class'); return (' ' + classes + ' ').indexOf(' ' + className + ' ') != -1; }; @@ -179,7 +180,7 @@ Blockly.utils.dom.hasClass = function(element, className) { * @return {?Node} The node removed if removed; else, null. */ // Copied from Closure goog.dom.removeNode -Blockly.utils.dom.removeNode = function(node) { +const removeNode = function(node) { return node && node.parentNode ? node.parentNode.removeChild(node) : null; }; @@ -189,7 +190,7 @@ Blockly.utils.dom.removeNode = function(node) { * @param {!Element} newNode New element to insert. * @param {!Element} refNode Existing element to precede new node. */ -Blockly.utils.dom.insertAfter = function(newNode, refNode) { +const insertAfter = function(newNode, refNode) { const siblingNode = refNode.nextSibling; const parentNode = refNode.parentNode; if (!parentNode) { @@ -208,9 +209,9 @@ Blockly.utils.dom.insertAfter = function(newNode, refNode) { * @param {!Node} descendant The node to test presence of. * @return {boolean} Whether the parent node contains the descendant node. */ -Blockly.utils.dom.containsNode = function(parent, descendant) { +const containsNode = function(parent, descendant) { return !!(parent.compareDocumentPosition(descendant) & - Blockly.utils.dom.NodeType.DOCUMENT_POSITION_CONTAINED_BY); + NodeType.DOCUMENT_POSITION_CONTAINED_BY); }; /** @@ -220,7 +221,7 @@ Blockly.utils.dom.containsNode = function(parent, descendant) { * @param {!Element} element Element to which the CSS transform will be applied. * @param {string} transform The value of the CSS `transform` property. */ -Blockly.utils.dom.setCssTransform = function(element, transform) { +const setCssTransform = function(element, transform) { element.style['transform'] = transform; element.style['-webkit-transform'] = transform; }; @@ -229,10 +230,10 @@ Blockly.utils.dom.setCssTransform = function(element, transform) { * Start caching text widths. Every call to this function MUST also call * stopTextWidthCache. Caches must not survive between execution threads. */ -Blockly.utils.dom.startTextWidthCache = function() { - Blockly.utils.dom.cacheReference_++; - if (!Blockly.utils.dom.cacheWidths_) { - Blockly.utils.dom.cacheWidths_ = Object.create(null); +const startTextWidthCache = function() { + cacheReference++; + if (!cacheWidths) { + cacheWidths = Object.create(null); } }; @@ -240,10 +241,10 @@ Blockly.utils.dom.startTextWidthCache = function() { * Stop caching field widths. Unless caching was already on when the * corresponding call to startTextWidthCache was made. */ -Blockly.utils.dom.stopTextWidthCache = function() { - Blockly.utils.dom.cacheReference_--; - if (!Blockly.utils.dom.cacheReference_) { - Blockly.utils.dom.cacheWidths_ = null; +const stopTextWidthCache = function() { + cacheReference--; + if (!cacheReference) { + cacheWidths = null; } }; @@ -252,13 +253,13 @@ Blockly.utils.dom.stopTextWidthCache = function() { * @param {!Element} textElement An SVG 'text' element. * @return {number} Width of element. */ -Blockly.utils.dom.getTextWidth = function(textElement) { +const getTextWidth = function(textElement) { const key = textElement.textContent + '\n' + textElement.className.baseVal; let width; // Return the cached width if it exists. - if (Blockly.utils.dom.cacheWidths_) { - width = Blockly.utils.dom.cacheWidths_[key]; + if (cacheWidths) { + width = cacheWidths[key]; if (width) { return width; } @@ -280,8 +281,8 @@ Blockly.utils.dom.getTextWidth = function(textElement) { } // Cache the computed width and return. - if (Blockly.utils.dom.cacheWidths_) { - Blockly.utils.dom.cacheWidths_[key] = width; + if (cacheWidths) { + cacheWidths[key] = width; } return width; }; @@ -296,9 +297,9 @@ Blockly.utils.dom.getTextWidth = function(textElement) { * @param {string} fontFamily The font family to use. * @return {number} Width of element. */ -Blockly.utils.dom.getFastTextWidth = function(textElement, +const getFastTextWidth = function(textElement, fontSize, fontWeight, fontFamily) { - return Blockly.utils.dom.getFastTextWidthWithSizeString(textElement, + return getFastTextWidthWithSizeString(textElement, fontSize + 'pt', fontWeight, fontFamily); }; @@ -314,21 +315,21 @@ Blockly.utils.dom.getFastTextWidth = function(textElement, * @param {string} fontFamily The font family to use. * @return {number} Width of element. */ -Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, +const getFastTextWidthWithSizeString = function(textElement, fontSize, fontWeight, fontFamily) { const text = textElement.textContent; const key = text + '\n' + textElement.className.baseVal; let width; // Return the cached width if it exists. - if (Blockly.utils.dom.cacheWidths_) { - width = Blockly.utils.dom.cacheWidths_[key]; + if (cacheWidths) { + width = cacheWidths[key]; if (width) { return width; } } - if (!Blockly.utils.dom.canvasContext_) { + if (!canvasContext) { // Inject the canvas element used for computing text widths. const computeCanvas = document.createElement('canvas'); computeCanvas.className = 'blocklyComputeCanvas'; @@ -337,18 +338,18 @@ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, // Initialize the HTML canvas context and set the font. // The context font must match blocklyText's fontsize and font-family // set in CSS. - Blockly.utils.dom.canvasContext_ = computeCanvas.getContext('2d'); + canvasContext = computeCanvas.getContext('2d'); } // Set the desired font size and family. - Blockly.utils.dom.canvasContext_.font = + canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; // Measure the text width using the helper canvas context. - width = Blockly.utils.dom.canvasContext_.measureText(text).width; + width = canvasContext.measureText(text).width; // Cache the computed width and return. - if (Blockly.utils.dom.cacheWidths_) { - Blockly.utils.dom.cacheWidths_[key] = width; + if (cacheWidths) { + cacheWidths[key] = width; } return width; }; @@ -361,7 +362,7 @@ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, * @param {string} fontFamily The font family to use. * @return {{height: number, baseline: number}} Font measurements. */ -Blockly.utils.dom.measureFontMetrics = function(text, fontSize, fontWeight, +const measureFontMetrics = function(text, fontSize, fontWeight, fontFamily) { const span = document.createElement('span'); @@ -389,3 +390,25 @@ Blockly.utils.dom.measureFontMetrics = function(text, fontSize, fontWeight, } return result; }; + +exports = { + SVG_NS, + HTML_NS, + XLINK_NS, + NodeType, + createSvgElement, + addClass, + removeClasses, + removeClass, + hasClass, + removeNode, + insertAfter, + containsNode, + setCssTransform, + startTextWidthCache, + stopTextWidthCache, + getTextWidth, + getFastTextWidth, + getFastTextWidthWithSizeString, + measureFontMetrics, +}; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..dc28906b6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -173,7 +173,7 @@ goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); 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'], []); -goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); From 1d8f6e903c2a74bc4ba9e2eeb0e563becd0ae33c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 15:38:35 -0700 Subject: [PATCH 003/291] Migrate core/utils/dom.js to named requires --- core/utils/dom.js | 11 +++++------ tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 7219bd93c..192aba58e 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -19,8 +19,8 @@ goog.module('Blockly.utils.dom'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Svg = goog.require('Blockly.utils.Svg'); +const userAgent = goog.require('Blockly.utils.userAgent'); /** @@ -76,12 +76,11 @@ let canvasContext = null; /** * Helper method for creating SVG elements. - * @param {string|Blockly.utils.Svg} name Element's tag name. + * @param {string|Svg} name Element's tag name. * @param {!Object} attrs Dictionary of attribute names and values. * @param {Element=} opt_parent Optional parent on which to append the element. * @return {T} Newly created SVG element. The return type is {!SVGElement} if - * name is a string or a more specific type if it a member of - * Blockly.utils.Svg + * name is a string or a more specific type if it a member of Svg. * @template T */ const createSvgElement = function(name, attrs, opt_parent) { @@ -267,7 +266,7 @@ const getTextWidth = function(textElement) { // Attempt to compute fetch the width of the SVG text element. try { - if (Blockly.utils.userAgent.IE || Blockly.utils.userAgent.EDGE) { + if (userAgent.IE || userAgent.EDGE) { width = textElement.getBBox().width; } else { width = textElement.getComputedTextLength(); diff --git a/tests/deps.js b/tests/deps.js index dc28906b6..b8b42f583 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -173,7 +173,7 @@ goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); 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'], []); -goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); From 07bd3b3c799fd99aa02ce3c08462bd312925c501 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 08:42:28 -0700 Subject: [PATCH 004/291] clang-format core/utils/dom.js --- core/utils/dom.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 192aba58e..0e0480c0f 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -209,8 +209,9 @@ const insertAfter = function(newNode, refNode) { * @return {boolean} Whether the parent node contains the descendant node. */ const containsNode = function(parent, descendant) { - return !!(parent.compareDocumentPosition(descendant) & - NodeType.DOCUMENT_POSITION_CONTAINED_BY); + return !!( + parent.compareDocumentPosition(descendant) & + NodeType.DOCUMENT_POSITION_CONTAINED_BY); }; /** @@ -296,10 +297,10 @@ const getTextWidth = function(textElement) { * @param {string} fontFamily The font family to use. * @return {number} Width of element. */ -const getFastTextWidth = function(textElement, - fontSize, fontWeight, fontFamily) { - return getFastTextWidthWithSizeString(textElement, - fontSize + 'pt', fontWeight, fontFamily); +const getFastTextWidth = function( + textElement, fontSize, fontWeight, fontFamily) { + return getFastTextWidthWithSizeString( + textElement, fontSize + 'pt', fontWeight, fontFamily); }; /** @@ -314,8 +315,8 @@ const getFastTextWidth = function(textElement, * @param {string} fontFamily The font family to use. * @return {number} Width of element. */ -const getFastTextWidthWithSizeString = function(textElement, - fontSize, fontWeight, fontFamily) { +const getFastTextWidthWithSizeString = function( + textElement, fontSize, fontWeight, fontFamily) { const text = textElement.textContent; const key = text + '\n' + textElement.className.baseVal; let width; @@ -340,8 +341,7 @@ const getFastTextWidthWithSizeString = function(textElement, canvasContext = computeCanvas.getContext('2d'); } // Set the desired font size and family. - canvasContext.font = - fontWeight + ' ' + fontSize + ' ' + fontFamily; + canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; // Measure the text width using the helper canvas context. width = canvasContext.measureText(text).width; @@ -361,9 +361,7 @@ const getFastTextWidthWithSizeString = function(textElement, * @param {string} fontFamily The font family to use. * @return {{height: number, baseline: number}} Font measurements. */ -const measureFontMetrics = function(text, fontSize, fontWeight, - fontFamily) { - +const measureFontMetrics = function(text, fontSize, fontWeight, fontFamily) { const span = document.createElement('span'); span.style.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; span.textContent = text; From f0fc360bfa8849cac38f68988f3f1370797ecac8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 20 Jul 2021 11:30:09 -0700 Subject: [PATCH 005/291] Inline otherwise-unused variable in core/utils/dom.js --- core/utils/dom.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 0e0480c0f..5ec684acf 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -129,8 +129,7 @@ const addClass = function(element, className) { const removeClasses = function(element, classNames) { const classList = classNames.split(' '); for (let i = 0; i < classList.length; i++) { - const cssName = classList[i]; - removeClass(element, cssName); + removeClass(element, classList[i]); } }; From c3d14479932c33aca47fdbdd54d9de766290fede Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 14:47:23 -0700 Subject: [PATCH 006/291] Migrate core/flyout_button.js to ES6 const/let --- core/flyout_button.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/flyout_button.js b/core/flyout_button.js index 643790d9f..793699e6a 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -126,7 +126,7 @@ Blockly.FlyoutButton.prototype.height = 0; * @return {!SVGElement} The button's SVG group. */ Blockly.FlyoutButton.prototype.createDom = function() { - var cssClass = this.isLabel_ ? 'blocklyFlyoutLabel' : 'blocklyFlyoutButton'; + let cssClass = this.isLabel_ ? 'blocklyFlyoutLabel' : 'blocklyFlyoutButton'; if (this.cssClass_) { cssClass += ' ' + this.cssClass_; } @@ -135,9 +135,10 @@ Blockly.FlyoutButton.prototype.createDom = function() { Blockly.utils.Svg.G, {'class': cssClass}, this.workspace_.getCanvas()); + let shadow; if (!this.isLabel_) { // Shadow rectangle (light source does not mirror in RTL). - var shadow = Blockly.utils.dom.createSvgElement( + shadow = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'class': 'blocklyFlyoutButtonShadow', @@ -146,7 +147,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { this.svgGroup_); } // Background rectangle. - var rect = Blockly.utils.dom.createSvgElement( + const rect = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'class': this.isLabel_ ? @@ -155,7 +156,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { }, this.svgGroup_); - var svgText = Blockly.utils.dom.createSvgElement( + const svgText = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', @@ -164,7 +165,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { 'text-anchor': 'middle' }, this.svgGroup_); - var text = Blockly.utils.replaceMessageReferences(this.text_); + let text = Blockly.utils.replaceMessageReferences(this.text_); if (this.workspace_.RTL) { // Force text to be RTL by adding an RLM. text += '\u200F'; @@ -176,12 +177,12 @@ Blockly.FlyoutButton.prototype.createDom = function() { 'flyoutForegroundColour', 'fill'); } - var fontSize = Blockly.utils.style.getComputedStyle(svgText, 'fontSize'); - var fontWeight = Blockly.utils.style.getComputedStyle(svgText, 'fontWeight'); - var fontFamily = Blockly.utils.style.getComputedStyle(svgText, 'fontFamily'); + const fontSize = Blockly.utils.style.getComputedStyle(svgText, 'fontSize'); + const fontWeight = Blockly.utils.style.getComputedStyle(svgText, 'fontWeight'); + const fontFamily = Blockly.utils.style.getComputedStyle(svgText, 'fontFamily'); this.width = Blockly.utils.dom.getFastTextWidthWithSizeString(svgText, fontSize, fontWeight, fontFamily); - var fontMetrics = Blockly.utils.dom.measureFontMetrics(text, fontSize, + const fontMetrics = Blockly.utils.dom.measureFontMetrics(text, fontSize, fontWeight, fontFamily); this.height = fontMetrics.height; @@ -286,7 +287,7 @@ Blockly.FlyoutButton.prototype.dispose = function() { * @private */ Blockly.FlyoutButton.prototype.onMouseUp_ = function(e) { - var gesture = this.targetWorkspace_.getGesture(e); + const gesture = this.targetWorkspace_.getGesture(e); if (gesture) { gesture.cancel(); } From a84660000f78ef26d89c2a204f11eeac720099f4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 14:53:15 -0700 Subject: [PATCH 007/291] Migrate core/flyout_button.js to goog.module --- core/flyout_button.js | 39 +++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/flyout_button.js b/core/flyout_button.js index 793699e6a..7399e3997 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FlyoutButton'); +goog.module('Blockly.FlyoutButton'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); @@ -35,7 +36,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -Blockly.FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { +const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { // Labels behave the same as buttons, but are styled differently. /** @@ -102,30 +103,30 @@ Blockly.FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { /** * The horizontal margin around the text in the button. */ -Blockly.FlyoutButton.MARGIN_X = 5; +FlyoutButton.MARGIN_X = 5; /** * The vertical margin around the text in the button. */ -Blockly.FlyoutButton.MARGIN_Y = 2; +FlyoutButton.MARGIN_Y = 2; /** * The width of the button's rect. * @type {number} */ -Blockly.FlyoutButton.prototype.width = 0; +FlyoutButton.prototype.width = 0; /** * The height of the button's rect. * @type {number} */ -Blockly.FlyoutButton.prototype.height = 0; +FlyoutButton.prototype.height = 0; /** * Create the button elements. * @return {!SVGElement} The button's SVG group. */ -Blockly.FlyoutButton.prototype.createDom = function() { +FlyoutButton.prototype.createDom = function() { let cssClass = this.isLabel_ ? 'blocklyFlyoutLabel' : 'blocklyFlyoutButton'; if (this.cssClass_) { cssClass += ' ' + this.cssClass_; @@ -187,8 +188,8 @@ Blockly.FlyoutButton.prototype.createDom = function() { this.height = fontMetrics.height; if (!this.isLabel_) { - this.width += 2 * Blockly.FlyoutButton.MARGIN_X; - this.height += 2 * Blockly.FlyoutButton.MARGIN_Y; + this.width += 2 * FlyoutButton.MARGIN_X; + this.height += 2 * FlyoutButton.MARGIN_Y; shadow.setAttribute('width', this.width); shadow.setAttribute('height', this.height); } @@ -209,7 +210,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { /** * Correctly position the flyout button and make it visible. */ -Blockly.FlyoutButton.prototype.show = function() { +FlyoutButton.prototype.show = function() { this.updateTransform_(); this.svgGroup_.setAttribute('display', 'block'); }; @@ -218,7 +219,7 @@ Blockly.FlyoutButton.prototype.show = function() { * Update SVG attributes to match internal state. * @private */ -Blockly.FlyoutButton.prototype.updateTransform_ = function() { +FlyoutButton.prototype.updateTransform_ = function() { this.svgGroup_.setAttribute('transform', 'translate(' + this.position_.x + ',' + this.position_.y + ')'); }; @@ -228,7 +229,7 @@ Blockly.FlyoutButton.prototype.updateTransform_ = function() { * @param {number} x The new x coordinate. * @param {number} y The new y coordinate. */ -Blockly.FlyoutButton.prototype.moveTo = function(x, y) { +FlyoutButton.prototype.moveTo = function(x, y) { this.position_.x = x; this.position_.y = y; this.updateTransform_(); @@ -237,7 +238,7 @@ Blockly.FlyoutButton.prototype.moveTo = function(x, y) { /** * @return {boolean} Whether or not the button is a label. */ -Blockly.FlyoutButton.prototype.isLabel = function() { +FlyoutButton.prototype.isLabel = function() { return this.isLabel_; }; @@ -246,14 +247,14 @@ Blockly.FlyoutButton.prototype.isLabel = function() { * @return {!Blockly.utils.Coordinate} x, y coordinates. * @package */ -Blockly.FlyoutButton.prototype.getPosition = function() { +FlyoutButton.prototype.getPosition = function() { return this.position_; }; /** * @return {string} Text of the button. */ -Blockly.FlyoutButton.prototype.getButtonText = function() { +FlyoutButton.prototype.getButtonText = function() { return this.text_; }; @@ -262,14 +263,14 @@ Blockly.FlyoutButton.prototype.getButtonText = function() { * @return {!Blockly.WorkspaceSvg} The target workspace of the flyout where this * button resides. */ -Blockly.FlyoutButton.prototype.getTargetWorkspace = function() { +FlyoutButton.prototype.getTargetWorkspace = function() { return this.targetWorkspace_; }; /** * Dispose of this button. */ -Blockly.FlyoutButton.prototype.dispose = function() { +FlyoutButton.prototype.dispose = function() { if (this.onMouseUpWrapper_) { Blockly.browserEvents.unbind(this.onMouseUpWrapper_); } @@ -286,7 +287,7 @@ Blockly.FlyoutButton.prototype.dispose = function() { * @param {!Event} e Mouse up event. * @private */ -Blockly.FlyoutButton.prototype.onMouseUp_ = function(e) { +FlyoutButton.prototype.onMouseUp_ = function(e) { const gesture = this.targetWorkspace_.getGesture(e); if (gesture) { gesture.cancel(); @@ -329,3 +330,5 @@ Blockly.Css.register([ '}', /* eslint-enable indent */ ]); + +exports = FlyoutButton; diff --git a/tests/deps.js b/tests/deps.js index d02bbc5ea..d0f326297 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -62,7 +62,7 @@ goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], [' 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'], {'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_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); 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']); From fe01fbebc211a49bdd120acaeaba695486e0a9b1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 15:03:35 -0700 Subject: [PATCH 008/291] Migrate core/flyout_button.js named requires --- core/flyout_button.js | 79 ++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/core/flyout_button.js b/core/flyout_button.js index 7399e3997..372060237 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -13,24 +13,25 @@ goog.module('Blockly.FlyoutButton'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.Css'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.style'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.utils.toolbox'); -goog.requireType('Blockly.WorkspaceSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Css = goog.require('Blockly.Css'); +const Svg = goog.require('Blockly.utils.Svg'); +/* 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 style = goog.require('Blockly.utils.style'); +/* eslint-disable-next-line no-unused-vars */ +const toolbox = goog.requireType('Blockly.utils.toolbox'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** * Class for a button in the flyout. - * @param {!Blockly.WorkspaceSvg} workspace The workspace in which to place this + * @param {!WorkspaceSvg} workspace The workspace in which to place this * button. - * @param {!Blockly.WorkspaceSvg} targetWorkspace The flyout's target workspace. - * @param {!Blockly.utils.toolbox.ButtonOrLabelInfo} json + * @param {!WorkspaceSvg} targetWorkspace The flyout's target workspace. + * @param {!toolbox.ButtonOrLabelInfo} json * The JSON specifying the label/button. * @param {boolean} isLabel Whether this button should be styled as a label. * @constructor @@ -40,13 +41,13 @@ const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { // Labels behave the same as buttons, but are styled differently. /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.targetWorkspace_ = targetWorkspace; @@ -58,10 +59,10 @@ const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { this.text_ = json['text']; /** - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ - this.position_ = new Blockly.utils.Coordinate(0, 0); + this.position_ = new Coordinate(0, 0); /** * Whether this button should be styled as a label. @@ -88,14 +89,14 @@ const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { /** * Mouse up event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onMouseUpWrapper_ = null; /** * The JSON specifying the label / button. - * @type {!Blockly.utils.toolbox.ButtonOrLabelInfo} + * @type {!toolbox.ButtonOrLabelInfo} */ this.info = json; }; @@ -132,15 +133,15 @@ FlyoutButton.prototype.createDom = function() { cssClass += ' ' + this.cssClass_; } - this.svgGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, {'class': cssClass}, + this.svgGroup_ = dom.createSvgElement( + Svg.G, {'class': cssClass}, this.workspace_.getCanvas()); let shadow; if (!this.isLabel_) { // Shadow rectangle (light source does not mirror in RTL). - shadow = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + shadow = dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyFlyoutButtonShadow', 'rx': 4, 'ry': 4, 'x': 1, 'y': 1 @@ -148,8 +149,8 @@ FlyoutButton.prototype.createDom = function() { this.svgGroup_); } // Background rectangle. - const rect = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + const rect = dom.createSvgElement( + Svg.RECT, { 'class': this.isLabel_ ? 'blocklyFlyoutLabelBackground' : 'blocklyFlyoutButtonBackground', @@ -157,8 +158,8 @@ FlyoutButton.prototype.createDom = function() { }, this.svgGroup_); - const svgText = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, + const svgText = dom.createSvgElement( + Svg.TEXT, { 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', 'x': 0, @@ -166,7 +167,7 @@ FlyoutButton.prototype.createDom = function() { 'text-anchor': 'middle' }, this.svgGroup_); - let text = Blockly.utils.replaceMessageReferences(this.text_); + let text = replaceMessageReferences(this.text_); if (this.workspace_.RTL) { // Force text to be RTL by adding an RLM. text += '\u200F'; @@ -178,12 +179,12 @@ FlyoutButton.prototype.createDom = function() { 'flyoutForegroundColour', 'fill'); } - const fontSize = Blockly.utils.style.getComputedStyle(svgText, 'fontSize'); - const fontWeight = Blockly.utils.style.getComputedStyle(svgText, 'fontWeight'); - const fontFamily = Blockly.utils.style.getComputedStyle(svgText, 'fontFamily'); - this.width = Blockly.utils.dom.getFastTextWidthWithSizeString(svgText, + const fontSize = style.getComputedStyle(svgText, 'fontSize'); + const fontWeight = style.getComputedStyle(svgText, 'fontWeight'); + const fontFamily = style.getComputedStyle(svgText, 'fontFamily'); + this.width = dom.getFastTextWidthWithSizeString(svgText, fontSize, fontWeight, fontFamily); - const fontMetrics = Blockly.utils.dom.measureFontMetrics(text, fontSize, + const fontMetrics = dom.measureFontMetrics(text, fontSize, fontWeight, fontFamily); this.height = fontMetrics.height; @@ -202,7 +203,7 @@ FlyoutButton.prototype.createDom = function() { this.updateTransform_(); - this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseUpWrapper_ = browserEvents.conditionalBind( this.svgGroup_, 'mouseup', this, this.onMouseUp_); return this.svgGroup_; }; @@ -244,7 +245,7 @@ FlyoutButton.prototype.isLabel = function() { /** * Location of the button. - * @return {!Blockly.utils.Coordinate} x, y coordinates. + * @return {!Coordinate} x, y coordinates. * @package */ FlyoutButton.prototype.getPosition = function() { @@ -260,7 +261,7 @@ FlyoutButton.prototype.getButtonText = function() { /** * Get the button's target workspace. - * @return {!Blockly.WorkspaceSvg} The target workspace of the flyout where this + * @return {!WorkspaceSvg} The target workspace of the flyout where this * button resides. */ FlyoutButton.prototype.getTargetWorkspace = function() { @@ -272,10 +273,10 @@ FlyoutButton.prototype.getTargetWorkspace = function() { */ FlyoutButton.prototype.dispose = function() { if (this.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(this.onMouseUpWrapper_); + browserEvents.unbind(this.onMouseUpWrapper_); } if (this.svgGroup_) { - Blockly.utils.dom.removeNode(this.svgGroup_); + dom.removeNode(this.svgGroup_); } if (this.svgText_) { this.workspace_.getThemeManager().unsubscribe(this.svgText_); @@ -306,7 +307,7 @@ FlyoutButton.prototype.onMouseUp_ = function(e) { /** * CSS for buttons and labels. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyFlyoutButton {', 'fill: #888;', From 6a43f7c9b7f04bbc355bb0fb1a9b7313d4cabfd4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 15:04:19 -0700 Subject: [PATCH 009/291] clang-format core/flyout_button.js --- core/flyout_button.js | 57 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/core/flyout_button.js b/core/flyout_button.js index 372060237..db05ca4f4 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -77,8 +77,8 @@ const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { * @private */ this.callbackKey_ = json['callbackKey'] || - /* Check the lower case version too to satisfy IE */ - json['callbackkey']; + /* Check the lower case version too to satisfy IE */ + json['callbackkey']; /** * If specified, a CSS class to add to this button. @@ -134,33 +134,33 @@ FlyoutButton.prototype.createDom = function() { } this.svgGroup_ = dom.createSvgElement( - Svg.G, {'class': cssClass}, - this.workspace_.getCanvas()); + Svg.G, {'class': cssClass}, this.workspace_.getCanvas()); let shadow; if (!this.isLabel_) { // Shadow rectangle (light source does not mirror in RTL). shadow = dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyFlyoutButtonShadow', - 'rx': 4, 'ry': 4, 'x': 1, 'y': 1 + 'rx': 4, + 'ry': 4, + 'x': 1, + 'y': 1 }, this.svgGroup_); } // Background rectangle. const rect = dom.createSvgElement( - Svg.RECT, - { - 'class': this.isLabel_ ? - 'blocklyFlyoutLabelBackground' : 'blocklyFlyoutButtonBackground', - 'rx': 4, 'ry': 4 + Svg.RECT, { + 'class': this.isLabel_ ? 'blocklyFlyoutLabelBackground' : + 'blocklyFlyoutButtonBackground', + 'rx': 4, + 'ry': 4 }, this.svgGroup_); const svgText = dom.createSvgElement( - Svg.TEXT, - { + Svg.TEXT, { 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', 'x': 0, 'y': 0, @@ -175,17 +175,17 @@ FlyoutButton.prototype.createDom = function() { svgText.textContent = text; if (this.isLabel_) { this.svgText_ = svgText; - this.workspace_.getThemeManager().subscribe(this.svgText_, - 'flyoutForegroundColour', 'fill'); + this.workspace_.getThemeManager().subscribe( + this.svgText_, 'flyoutForegroundColour', 'fill'); } const fontSize = style.getComputedStyle(svgText, 'fontSize'); const fontWeight = style.getComputedStyle(svgText, 'fontWeight'); const fontFamily = style.getComputedStyle(svgText, 'fontFamily'); - this.width = dom.getFastTextWidthWithSizeString(svgText, - fontSize, fontWeight, fontFamily); - const fontMetrics = dom.measureFontMetrics(text, fontSize, - fontWeight, fontFamily); + this.width = dom.getFastTextWidthWithSizeString( + svgText, fontSize, fontWeight, fontFamily); + const fontMetrics = + dom.measureFontMetrics(text, fontSize, fontWeight, fontFamily); this.height = fontMetrics.height; if (!this.isLabel_) { @@ -198,8 +198,8 @@ FlyoutButton.prototype.createDom = function() { rect.setAttribute('height', this.height); svgText.setAttribute('x', this.width / 2); - svgText.setAttribute('y', this.height / 2 - fontMetrics.height / 2 + - fontMetrics.baseline); + svgText.setAttribute( + 'y', this.height / 2 - fontMetrics.height / 2 + fontMetrics.baseline); this.updateTransform_(); @@ -221,7 +221,8 @@ FlyoutButton.prototype.show = function() { * @private */ FlyoutButton.prototype.updateTransform_ = function() { - this.svgGroup_.setAttribute('transform', + this.svgGroup_.setAttribute( + 'transform', 'translate(' + this.position_.x + ',' + this.position_.y + ')'); }; @@ -296,8 +297,10 @@ FlyoutButton.prototype.onMouseUp_ = function(e) { if (this.isLabel_ && this.callbackKey_) { console.warn('Labels should not have callbacks. Label text: ' + this.text_); - } else if (!this.isLabel_ && !(this.callbackKey_ && - this.targetWorkspace_.getButtonCallback(this.callbackKey_))) { + } else if ( + !this.isLabel_ && + !(this.callbackKey_ && + this.targetWorkspace_.getButtonCallback(this.callbackKey_))) { console.warn('Buttons should have callbacks. Button text: ' + this.text_); } else if (!this.isLabel_) { this.targetWorkspace_.getButtonCallback(this.callbackKey_)(this); @@ -326,9 +329,7 @@ Css.register([ 'cursor: default;', '}', - '.blocklyFlyoutLabelBackground {', - 'opacity: 0;', - '}', + '.blocklyFlyoutLabelBackground {', 'opacity: 0;', '}', /* eslint-enable indent */ ]); From 227030f451511c0eceb3bf303de25e2ad89e57ca Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:41:22 -0700 Subject: [PATCH 010/291] Migrate core/mutator.js to ES6 const/let --- core/mutator.js | 98 +++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index 2733964c7..3a87e2035 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -161,17 +161,18 @@ Blockly.Mutator.prototype.createEditor_ = function() { {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, null); // Convert the list of names into a list of XML objects for the flyout. + let quarkXml; if (this.quarkNames_.length) { - var quarkXml = Blockly.utils.xml.createElement('xml'); - for (var i = 0, quarkName; (quarkName = this.quarkNames_[i]); i++) { - var element = Blockly.utils.xml.createElement('block'); + quarkXml = Blockly.utils.xml.createElement('xml'); + for (let i = 0, quarkName; (quarkName = this.quarkNames_[i]); i++) { + const element = Blockly.utils.xml.createElement('block'); element.setAttribute('type', quarkName); quarkXml.appendChild(element); } } else { - var quarkXml = null; + quarkXml = null; } - var workspaceOptions = new Blockly.Options( + const workspaceOptions = new Blockly.Options( /** @type {!Blockly.BlocklyOptions} */ ({ // If you want to enable disabling, also remove the @@ -187,7 +188,7 @@ Blockly.Mutator.prototype.createEditor_ = function() { workspaceOptions.toolboxPosition = this.block_.RTL ? Blockly.utils.toolbox.Position.RIGHT : Blockly.utils.toolbox.Position.LEFT; - var hasFlyout = !!quarkXml; + const hasFlyout = !!quarkXml; if (hasFlyout) { workspaceOptions.languageTree = Blockly.utils.toolbox.convertToolboxDefToJson(quarkXml); @@ -200,9 +201,9 @@ Blockly.Mutator.prototype.createEditor_ = function() { // a top level SVG. Instead of handling scale themselves, mutators // inherit scale from the parent workspace. // To fix this, scale needs to be applied at a different level in the DOM. - var flyoutSvg = hasFlyout ? + const flyoutSvg = hasFlyout ? this.workspace_.addFlyout(Blockly.utils.Svg.G) : null; - var background = this.workspace_.createDom('blocklyMutatorBackground'); + const background = this.workspace_.createDom('blocklyMutatorBackground'); if (flyoutSvg) { // Insert the flyout after the but before the block canvas so that @@ -244,13 +245,13 @@ Blockly.Mutator.prototype.updateEditable = function() { * @private */ Blockly.Mutator.prototype.resizeBubble_ = function() { - var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; - var workspaceSize = this.workspace_.getCanvas().getBBox(); - var width = workspaceSize.width + workspaceSize.x; - var height = workspaceSize.height + doubleBorderWidth * 3; - var flyout = this.workspace_.getFlyout(); + const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const workspaceSize = this.workspace_.getCanvas().getBBox(); + let width = workspaceSize.width + workspaceSize.x; + let height = workspaceSize.height + doubleBorderWidth * 3; + const flyout = this.workspace_.getFlyout(); if (flyout) { - var flyoutScrollMetrics = flyout.getWorkspace().getMetricsManager() + const flyoutScrollMetrics = flyout.getWorkspace().getMetricsManager() .getScrollMetrics(); height = Math.max(height, flyoutScrollMetrics.height + 20); width += flyout.getWidth(); @@ -276,7 +277,7 @@ Blockly.Mutator.prototype.resizeBubble_ = function() { if (this.block_.RTL) { // Scroll the workspace to always left-align. - var translation = 'translate(' + this.workspaceWidth_ + ',0)'; + const translation = 'translate(' + this.workspaceWidth_ + ',0)'; this.workspace_.getCanvas().setAttribute('transform', translation); } this.workspace_.resize(); @@ -312,27 +313,28 @@ Blockly.Mutator.prototype.setVisible = function(visible) { // Expose this mutator's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerMoveEvent(this.onBubbleMove_.bind(this)); - var tree = this.workspace_.options.languageTree; - var flyout = this.workspace_.getFlyout(); + const tree = this.workspace_.options.languageTree; + const flyout = this.workspace_.getFlyout(); if (tree) { flyout.init(this.workspace_); flyout.show(tree); } this.rootBlock_ = this.block_.decompose(this.workspace_); - var blocks = this.rootBlock_.getDescendants(false); - for (var i = 0, child; (child = blocks[i]); i++) { + const blocks = this.rootBlock_.getDescendants(false); + for (let i = 0, child; (child = blocks[i]); i++) { child.render(); } // The root block should not be draggable or deletable. this.rootBlock_.setMovable(false); this.rootBlock_.setDeletable(false); + let margin, x; if (flyout) { - var margin = flyout.CORNER_RADIUS * 2; - var x = this.rootBlock_.RTL ? flyout.getWidth() + margin : margin; + margin = flyout.CORNER_RADIUS * 2; + x = this.rootBlock_.RTL ? flyout.getWidth() + margin : margin; } else { - var margin = 16; - var x = margin; + margin = 16; + x = margin; } if (this.block_.RTL) { x = -x; @@ -340,8 +342,8 @@ Blockly.Mutator.prototype.setVisible = function(visible) { this.rootBlock_.moveBy(x, margin); // Save the initial connections, then listen for further changes. if (this.block_.saveConnections) { - var thisMutator = this; - var mutatorBlock = + const thisMutator = this; + const mutatorBlock = /** @type {{saveConnections: function(!Blockly.Block)}} */ ( this.block_); mutatorBlock.saveConnections(this.rootBlock_); @@ -385,11 +387,11 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { } if (!this.workspace_.isDragging()) { - var blocks = this.workspace_.getTopBlocks(false); - var MARGIN = 20; + const blocks = this.workspace_.getTopBlocks(false); + const MARGIN = 20; - for (var b = 0, block; (block = blocks[b]); b++) { - var blockXY = block.getRelativeToSurfaceXY(); + for (let b = 0, block; (block = blocks[b]); b++) { + const blockXY = block.getRelativeToSurfaceXY(); // Bump any block that's above the top back inside. if (blockXY.y < MARGIN) { @@ -397,8 +399,8 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { } // Bump any block overlapping the flyout back inside. if (block.RTL) { - var right = -MARGIN; - var flyout = this.workspace_.getFlyout(); + let right = -MARGIN; + const flyout = this.workspace_.getFlyout(); if (flyout) { right -= flyout.getWidth(); } @@ -414,12 +416,12 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { // When the mutator's workspace changes, update the source block. if (this.rootBlock_.workspace == this.workspace_) { Blockly.Events.setGroup(true); - var block = this.block_; - var oldMutationDom = block.mutationToDom(); - var oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); + const block = this.block_; + const oldMutationDom = block.mutationToDom(); + const oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); // Switch off rendering while the source block is rebuilt. - var savedRendered = block.rendered; + const savedRendered = block.rendered; // TODO(#4288): We should not be setting the rendered property to false. block.rendered = false; @@ -434,13 +436,13 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { block.render(); } - var newMutationDom = block.mutationToDom(); - var newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); + const newMutationDom = block.mutationToDom(); + const newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); if (oldMutation != newMutation) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( block, 'mutation', null, oldMutation, newMutation)); // Ensure that any bump is part of this mutation's event group. - var group = Blockly.Events.getGroup(); + const group = Blockly.Events.getGroup(); setTimeout(function() { Blockly.Events.setGroup(group); block.bumpNeighbours(); @@ -470,18 +472,18 @@ Blockly.Mutator.prototype.dispose = function() { * @public */ Blockly.Mutator.prototype.updateBlockStyle = function() { - var ws = this.workspace_; + const ws = this.workspace_; if (ws && ws.getAllBlocks(false)) { - var workspaceBlocks = ws.getAllBlocks(false); - for (var i = 0, block; (block = workspaceBlocks[i]); i++) { + const workspaceBlocks = ws.getAllBlocks(false); + for (let i = 0, block; (block = workspaceBlocks[i]); i++) { block.setStyle(block.getStyleName()); } - var flyout = ws.getFlyout(); + const flyout = ws.getFlyout(); if (flyout) { - var flyoutBlocks = flyout.workspace_.getAllBlocks(false); - for (var i = 0, block; (block = flyoutBlocks[i]); i++) { + const flyoutBlocks = flyout.workspace_.getAllBlocks(false); + for (let i = 0, block; (block = flyoutBlocks[i]); i++) { block.setStyle(block.getStyleName()); } } @@ -499,8 +501,8 @@ Blockly.Mutator.reconnect = function(connectionChild, block, inputName) { if (!connectionChild || !connectionChild.getSourceBlock().workspace) { return false; // No connection or block has been deleted. } - var connectionParent = block.getInput(inputName).connection; - var currentParent = connectionChild.targetBlock(); + const connectionParent = block.getInput(inputName).connection; + const currentParent = connectionChild.targetBlock(); if ((!currentParent || currentParent == block) && connectionParent.targetConnection != connectionChild) { if (connectionParent.isConnected()) { @@ -521,9 +523,9 @@ Blockly.Mutator.reconnect = function(connectionChild, block, inputName) { * @public */ Blockly.Mutator.findParentWs = function(workspace) { - var outerWs = null; + let outerWs = null; if (workspace && workspace.options) { - var parent = workspace.options.parentWorkspace; + const parent = workspace.options.parentWorkspace; // If we were in a flyout in a mutator, need to go up two levels to find // the actual parent. if (workspace.isFlyout) { From e843a68b4117c4d96d497d22b43ed31f80007604 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:43:32 -0700 Subject: [PATCH 011/291] Migrate core/mutator.js to goog.module --- core/mutator.js | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index 3a87e2035..5f1c4cfab 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Mutator'); +goog.module('Blockly.Mutator'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Bubble'); goog.require('Blockly.Events'); @@ -45,37 +46,37 @@ goog.requireType('Blockly.Workspace'); * @extends {Blockly.Icon} * @constructor */ -Blockly.Mutator = function(quarkNames) { - Blockly.Mutator.superClass_.constructor.call(this, null); +const Mutator = function(quarkNames) { + Mutator.superClass_.constructor.call(this, null); this.quarkNames_ = quarkNames; }; -Blockly.utils.object.inherits(Blockly.Mutator, Blockly.Icon); +Blockly.utils.object.inherits(Mutator, Blockly.Icon); /** * Workspace in the mutator's bubble. * @type {?Blockly.WorkspaceSvg} * @private */ -Blockly.Mutator.prototype.workspace_ = null; +Mutator.prototype.workspace_ = null; /** * Width of workspace. * @private */ -Blockly.Mutator.prototype.workspaceWidth_ = 0; +Mutator.prototype.workspaceWidth_ = 0; /** * Height of workspace. * @private */ -Blockly.Mutator.prototype.workspaceHeight_ = 0; +Mutator.prototype.workspaceHeight_ = 0; /** * Set the block this mutator is associated with. * @param {!Blockly.BlockSvg} block The block associated with this mutator. * @package */ -Blockly.Mutator.prototype.setBlock = function(block) { +Mutator.prototype.setBlock = function(block) { this.block_ = block; }; @@ -85,7 +86,7 @@ Blockly.Mutator.prototype.setBlock = function(block) { * bubble or null if the mutator isn't open. * @package */ -Blockly.Mutator.prototype.getWorkspace = function() { +Mutator.prototype.getWorkspace = function() { return this.workspace_; }; @@ -94,7 +95,7 @@ Blockly.Mutator.prototype.getWorkspace = function() { * @param {!Element} group The icon group. * @protected */ -Blockly.Mutator.prototype.drawIcon_ = function(group) { +Mutator.prototype.drawIcon_ = function(group) { // Square with rounded corners. Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, @@ -139,7 +140,7 @@ Blockly.Mutator.prototype.drawIcon_ = function(group) { * @protected * @override */ -Blockly.Mutator.prototype.iconClick_ = function(e) { +Mutator.prototype.iconClick_ = function(e) { if (this.block_.isEditable()) { Blockly.Icon.prototype.iconClick_.call(this, e); } @@ -150,7 +151,7 @@ Blockly.Mutator.prototype.iconClick_ = function(e) { * @return {!SVGElement} The top-level node of the editor. * @private */ -Blockly.Mutator.prototype.createEditor_ = function() { +Mutator.prototype.createEditor_ = function() { /* Create the editor. Here's the markup that will be generated: [Workspace] @@ -219,8 +220,8 @@ Blockly.Mutator.prototype.createEditor_ = function() { /** * Add or remove the UI indicating if this icon may be clicked or not. */ -Blockly.Mutator.prototype.updateEditable = function() { - Blockly.Mutator.superClass_.updateEditable.call(this); +Mutator.prototype.updateEditable = function() { + Mutator.superClass_.updateEditable.call(this); if (!this.block_.isInFlyout) { if (this.block_.isEditable()) { if (this.iconGroup_) { @@ -244,7 +245,7 @@ Blockly.Mutator.prototype.updateEditable = function() { * Resize the bubble to match the size of the workspace. * @private */ -Blockly.Mutator.prototype.resizeBubble_ = function() { +Mutator.prototype.resizeBubble_ = function() { const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; const workspaceSize = this.workspace_.getCanvas().getBBox(); let width = workspaceSize.width + workspaceSize.x; @@ -287,7 +288,7 @@ Blockly.Mutator.prototype.resizeBubble_ = function() { * A method handler for when the bubble is moved. * @private */ -Blockly.Mutator.prototype.onBubbleMove_ = function() { +Mutator.prototype.onBubbleMove_ = function() { if (this.workspace_) { this.workspace_.recordDragTargets(); } @@ -297,7 +298,7 @@ Blockly.Mutator.prototype.onBubbleMove_ = function() { * Show or hide the mutator bubble. * @param {boolean} visible True if the bubble should be visible. */ -Blockly.Mutator.prototype.setVisible = function(visible) { +Mutator.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { // No change. return; @@ -380,7 +381,7 @@ Blockly.Mutator.prototype.setVisible = function(visible) { * @param {!Blockly.Events.Abstract} e Custom data for event. * @private */ -Blockly.Mutator.prototype.workspaceChanged_ = function(e) { +Mutator.prototype.workspaceChanged_ = function(e) { if (e.isUiEvent || (e.type == Blockly.Events.CHANGE && e.element == 'disabled')) { return; @@ -462,7 +463,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { /** * Dispose of this mutator. */ -Blockly.Mutator.prototype.dispose = function() { +Mutator.prototype.dispose = function() { this.block_.mutator = null; Blockly.Icon.prototype.dispose.call(this); }; @@ -471,7 +472,7 @@ Blockly.Mutator.prototype.dispose = function() { * Update the styles on all blocks in the mutator. * @public */ -Blockly.Mutator.prototype.updateBlockStyle = function() { +Mutator.prototype.updateBlockStyle = function() { const ws = this.workspace_; if (ws && ws.getAllBlocks(false)) { @@ -497,7 +498,7 @@ Blockly.Mutator.prototype.updateBlockStyle = function() { * @param {string} inputName Name of input on parent block. * @return {boolean} True iff a reconnection was made, false otherwise. */ -Blockly.Mutator.reconnect = function(connectionChild, block, inputName) { +Mutator.reconnect = function(connectionChild, block, inputName) { if (!connectionChild || !connectionChild.getSourceBlock().workspace) { return false; // No connection or block has been deleted. } @@ -522,7 +523,7 @@ Blockly.Mutator.reconnect = function(connectionChild, block, inputName) { * @return {?Blockly.Workspace} The mutator's parent workspace or null. * @public */ -Blockly.Mutator.findParentWs = function(workspace) { +Mutator.findParentWs = function(workspace) { let outerWs = null; if (workspace && workspace.options) { const parent = workspace.options.parentWorkspace; @@ -538,3 +539,5 @@ Blockly.Mutator.findParentWs = function(workspace) { } return outerWs; }; + +exports = Mutator; From 949d3f3593d19b8fdca6d8abf8a2cb4ef976c13e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:59:16 -0700 Subject: [PATCH 012/291] Migrate core/mutator.js to named requires --- core/mutator.js | 142 +++++++++++++++++++++++++----------------------- tests/deps.js | 2 +- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index 5f1c4cfab..ca8475cdf 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -14,47 +14,53 @@ goog.module('Blockly.Mutator'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Bubble'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Abstract = goog.requireType('Blockly.Events.Abstract'); +/* 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 Blockly = goog.requireType('Blockly'); +const Bubble = goog.require('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.requireType('Blockly.Connection'); +/* 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'); +const Options = goog.require('Blockly.Options'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const WorkspaceSvg = goog.require('Blockly.WorkspaceSvg'); +const Xml = goog.require('Blockly.Xml'); +const dom = goog.require('Blockly.utils.dom'); +const internalConstants = goog.require('Blockly.internalConstants'); +const object = goog.require('Blockly.utils.object'); +const toolbox = goog.require('Blockly.utils.toolbox'); +const xml = goog.require('Blockly.utils.xml'); /** @suppress {extraRequire} */ 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'); -goog.require('Blockly.utils.object'); -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.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Connection'); -goog.requireType('Blockly.Events.Abstract'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.Workspace'); /** * Class for a mutator dialog. * @param {!Array} quarkNames List of names of sub-blocks for flyout. - * @extends {Blockly.Icon} + * @extends {Icon} * @constructor */ const Mutator = function(quarkNames) { Mutator.superClass_.constructor.call(this, null); this.quarkNames_ = quarkNames; }; -Blockly.utils.object.inherits(Mutator, Blockly.Icon); +object.inherits(Mutator, Icon); /** * Workspace in the mutator's bubble. - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} * @private */ Mutator.prototype.workspace_ = null; @@ -73,7 +79,7 @@ Mutator.prototype.workspaceHeight_ = 0; /** * Set the block this mutator is associated with. - * @param {!Blockly.BlockSvg} block The block associated with this mutator. + * @param {!BlockSvg} block The block associated with this mutator. * @package */ Mutator.prototype.setBlock = function(block) { @@ -82,7 +88,7 @@ Mutator.prototype.setBlock = function(block) { /** * Returns the workspace inside this mutator icon's bubble. - * @return {?Blockly.WorkspaceSvg} The workspace inside this mutator icon's + * @return {?WorkspaceSvg} The workspace inside this mutator icon's * bubble or null if the mutator isn't open. * @package */ @@ -97,8 +103,8 @@ Mutator.prototype.getWorkspace = function() { */ Mutator.prototype.drawIcon_ = function(group) { // Square with rounded corners. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyIconShape', 'rx': '4', @@ -108,8 +114,8 @@ Mutator.prototype.drawIcon_ = function(group) { }, group); // Gear teeth. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,' + @@ -122,8 +128,8 @@ Mutator.prototype.drawIcon_ = function(group) { }, group); // Axle hole. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, + dom.createSvgElement( + Svg.CIRCLE, { 'class': 'blocklyIconShape', 'r': '2.7', @@ -142,7 +148,7 @@ Mutator.prototype.drawIcon_ = function(group) { */ Mutator.prototype.iconClick_ = function(e) { if (this.block_.isEditable()) { - Blockly.Icon.prototype.iconClick_.call(this, e); + Icon.prototype.iconClick_.call(this, e); } }; @@ -157,23 +163,23 @@ Mutator.prototype.createEditor_ = function() { [Workspace] */ - this.svgDialog_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.SVG, - {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, + this.svgDialog_ = dom.createSvgElement( + Svg.SVG, + {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); // Convert the list of names into a list of XML objects for the flyout. let quarkXml; if (this.quarkNames_.length) { - quarkXml = Blockly.utils.xml.createElement('xml'); + quarkXml = xml.createElement('xml'); for (let i = 0, quarkName; (quarkName = this.quarkNames_[i]); i++) { - const element = Blockly.utils.xml.createElement('block'); + const element = xml.createElement('block'); element.setAttribute('type', quarkName); quarkXml.appendChild(element); } } else { quarkXml = null; } - const workspaceOptions = new Blockly.Options( + const workspaceOptions = new Options( /** @type {!Blockly.BlocklyOptions} */ ({ // If you want to enable disabling, also remove the @@ -187,23 +193,23 @@ Mutator.prototype.createEditor_ = function() { 'rendererOverrides': this.block_.workspace.options.rendererOverrides })); workspaceOptions.toolboxPosition = this.block_.RTL ? - Blockly.utils.toolbox.Position.RIGHT : - Blockly.utils.toolbox.Position.LEFT; + toolbox.Position.RIGHT : + toolbox.Position.LEFT; const hasFlyout = !!quarkXml; if (hasFlyout) { workspaceOptions.languageTree = - Blockly.utils.toolbox.convertToolboxDefToJson(quarkXml); + toolbox.convertToolboxDefToJson(quarkXml); } - this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions); + this.workspace_ = new WorkspaceSvg(workspaceOptions); this.workspace_.isMutator = true; - this.workspace_.addChangeListener(Blockly.Events.disableOrphans); + this.workspace_.addChangeListener(Events.disableOrphans); // Mutator flyouts go inside the mutator workspace's rather than in // a top level SVG. Instead of handling scale themselves, mutators // inherit scale from the parent workspace. // To fix this, scale needs to be applied at a different level in the DOM. const flyoutSvg = hasFlyout ? - this.workspace_.addFlyout(Blockly.utils.Svg.G) : null; + this.workspace_.addFlyout(Svg.G) : null; const background = this.workspace_.createDom('blocklyMutatorBackground'); if (flyoutSvg) { @@ -225,7 +231,7 @@ Mutator.prototype.updateEditable = function() { if (!this.block_.isInFlyout) { if (this.block_.isEditable()) { if (this.iconGroup_) { - Blockly.utils.dom.removeClass( + dom.removeClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } @@ -233,7 +239,7 @@ Mutator.prototype.updateEditable = function() { // Close any mutator bubble. Icon is not clickable. this.setVisible(false); if (this.iconGroup_) { - Blockly.utils.dom.addClass( + dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } @@ -246,7 +252,7 @@ Mutator.prototype.updateEditable = function() { * @private */ Mutator.prototype.resizeBubble_ = function() { - const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const doubleBorderWidth = 2 * Bubble.BORDER_WIDTH; const workspaceSize = this.workspace_.getCanvas().getBBox(); let width = workspaceSize.width + workspaceSize.x; let height = workspaceSize.height + doubleBorderWidth * 3; @@ -303,14 +309,14 @@ Mutator.prototype.setVisible = function(visible) { // No change. return; } - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + Events.fire(new (Events.get(Events.BUBBLE_OPEN))( this.block_, visible, 'mutator')); if (visible) { // Create the bubble. - 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_), null, null); + /** @type {!Coordinate} */ (this.iconXY_), null, null); // Expose this mutator's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerMoveEvent(this.onBubbleMove_.bind(this)); @@ -345,7 +351,7 @@ Mutator.prototype.setVisible = function(visible) { if (this.block_.saveConnections) { const thisMutator = this; const mutatorBlock = - /** @type {{saveConnections: function(!Blockly.Block)}} */ ( + /** @type {{saveConnections: function(!Block)}} */ ( this.block_); mutatorBlock.saveConnections(this.rootBlock_); this.sourceListener_ = function() { @@ -378,12 +384,12 @@ Mutator.prototype.setVisible = function(visible) { * Update the source block when the mutator's blocks are changed. * Bump down any block that's too high. * Fired whenever a change is made to the mutator's workspace. - * @param {!Blockly.Events.Abstract} e Custom data for event. + * @param {!Abstract} e Custom data for event. * @private */ Mutator.prototype.workspaceChanged_ = function(e) { if (e.isUiEvent || - (e.type == Blockly.Events.CHANGE && e.element == 'disabled')) { + (e.type == Events.CHANGE && e.element == 'disabled')) { return; } @@ -416,10 +422,10 @@ Mutator.prototype.workspaceChanged_ = function(e) { // When the mutator's workspace changes, update the source block. if (this.rootBlock_.workspace == this.workspace_) { - Blockly.Events.setGroup(true); + Events.setGroup(true); const block = this.block_; const oldMutationDom = block.mutationToDom(); - const oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); + const oldMutation = oldMutationDom && Xml.domToText(oldMutationDom); // Switch off rendering while the source block is rebuilt. const savedRendered = block.rendered; @@ -438,17 +444,17 @@ Mutator.prototype.workspaceChanged_ = function(e) { } const newMutationDom = block.mutationToDom(); - const newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); + const newMutation = newMutationDom && Xml.domToText(newMutationDom); if (oldMutation != newMutation) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( block, 'mutation', null, oldMutation, newMutation)); // Ensure that any bump is part of this mutation's event group. - const group = Blockly.Events.getGroup(); + const group = Events.getGroup(); setTimeout(function() { - Blockly.Events.setGroup(group); + Events.setGroup(group); block.bumpNeighbours(); - Blockly.Events.setGroup(false); - }, Blockly.internalConstants.BUMP_DELAY); + Events.setGroup(false); + }, internalConstants.BUMP_DELAY); } // Don't update the bubble until the drag has ended, to avoid moving blocks @@ -456,7 +462,7 @@ Mutator.prototype.workspaceChanged_ = function(e) { if (!this.workspace_.isDragging()) { this.resizeBubble_(); } - Blockly.Events.setGroup(false); + Events.setGroup(false); } }; @@ -465,7 +471,7 @@ Mutator.prototype.workspaceChanged_ = function(e) { */ Mutator.prototype.dispose = function() { this.block_.mutator = null; - Blockly.Icon.prototype.dispose.call(this); + Icon.prototype.dispose.call(this); }; /** @@ -493,8 +499,8 @@ Mutator.prototype.updateBlockStyle = function() { /** * Reconnect an block to a mutated input. - * @param {Blockly.Connection} connectionChild Connection on child block. - * @param {!Blockly.Block} block Parent block. + * @param {Connection} connectionChild Connection on child block. + * @param {!Block} block Parent block. * @param {string} inputName Name of input on parent block. * @return {boolean} True iff a reconnection was made, false otherwise. */ @@ -519,8 +525,8 @@ Mutator.reconnect = function(connectionChild, block, inputName) { /** * Get the parent workspace of a workspace that is inside a mutator, taking into * account whether it is a flyout. - * @param {Blockly.Workspace} workspace The workspace that is inside a mutator. - * @return {?Blockly.Workspace} The mutator's parent workspace or null. + * @param {Workspace} workspace The workspace that is inside a mutator. + * @return {?Workspace} The mutator's parent workspace or null. * @public */ Mutator.findParentWs = function(workspace) { diff --git a/tests/deps.js b/tests/deps.js index de575339f..de6795326 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -112,7 +112,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.internalConstants', '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.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); 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']); From e7feef669ebe281630c1cd16e8d1bf7c9ef011a5 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 15:00:09 -0700 Subject: [PATCH 013/291] clang-format core/mutator.js --- core/mutator.js | 55 ++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index ca8475cdf..8f9bab118 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -104,8 +104,7 @@ Mutator.prototype.getWorkspace = function() { Mutator.prototype.drawIcon_ = function(group) { // Square with rounded corners. dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyIconShape', 'rx': '4', 'ry': '4', @@ -115,28 +114,21 @@ Mutator.prototype.drawIcon_ = function(group) { group); // Gear teeth. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,' + - '0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,' + - '-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,' + - '-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,' + - '-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 ' + - '-0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,' + - '0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z' + '0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,' + + '-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,' + + '-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,' + + '-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 ' + + '-0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,' + + '0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z' }, group); // Axle hole. dom.createSvgElement( Svg.CIRCLE, - { - 'class': 'blocklyIconShape', - 'r': '2.7', - 'cx': '8', - 'cy': '8' - }, - group); + {'class': 'blocklyIconShape', 'r': '2.7', 'cx': '8', 'cy': '8'}, group); }; /** @@ -164,9 +156,7 @@ Mutator.prototype.createEditor_ = function() { */ this.svgDialog_ = dom.createSvgElement( - Svg.SVG, - {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, - null); + Svg.SVG, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); // Convert the list of names into a list of XML objects for the flyout. let quarkXml; if (this.quarkNames_.length) { @@ -192,13 +182,11 @@ Mutator.prototype.createEditor_ = function() { 'renderer': this.block_.workspace.options.renderer, 'rendererOverrides': this.block_.workspace.options.rendererOverrides })); - workspaceOptions.toolboxPosition = this.block_.RTL ? - toolbox.Position.RIGHT : - toolbox.Position.LEFT; + workspaceOptions.toolboxPosition = + this.block_.RTL ? toolbox.Position.RIGHT : toolbox.Position.LEFT; const hasFlyout = !!quarkXml; if (hasFlyout) { - workspaceOptions.languageTree = - toolbox.convertToolboxDefToJson(quarkXml); + workspaceOptions.languageTree = toolbox.convertToolboxDefToJson(quarkXml); } this.workspace_ = new WorkspaceSvg(workspaceOptions); this.workspace_.isMutator = true; @@ -208,8 +196,7 @@ Mutator.prototype.createEditor_ = function() { // a top level SVG. Instead of handling scale themselves, mutators // inherit scale from the parent workspace. // To fix this, scale needs to be applied at a different level in the DOM. - const flyoutSvg = hasFlyout ? - this.workspace_.addFlyout(Svg.G) : null; + const flyoutSvg = hasFlyout ? this.workspace_.addFlyout(Svg.G) : null; const background = this.workspace_.createDom('blocklyMutatorBackground'); if (flyoutSvg) { @@ -258,8 +245,8 @@ Mutator.prototype.resizeBubble_ = function() { let height = workspaceSize.height + doubleBorderWidth * 3; const flyout = this.workspace_.getFlyout(); if (flyout) { - const flyoutScrollMetrics = flyout.getWorkspace().getMetricsManager() - .getScrollMetrics(); + const flyoutScrollMetrics = + flyout.getWorkspace().getMetricsManager().getScrollMetrics(); height = Math.max(height, flyoutScrollMetrics.height + 20); width += flyout.getWidth(); } @@ -309,8 +296,8 @@ Mutator.prototype.setVisible = function(visible) { // No change. return; } - Events.fire(new (Events.get(Events.BUBBLE_OPEN))( - this.block_, visible, 'mutator')); + Events.fire( + new (Events.get(Events.BUBBLE_OPEN))(this.block_, visible, 'mutator')); if (visible) { // Create the bubble. this.bubble_ = new Bubble( @@ -351,8 +338,7 @@ Mutator.prototype.setVisible = function(visible) { if (this.block_.saveConnections) { const thisMutator = this; const mutatorBlock = - /** @type {{saveConnections: function(!Block)}} */ ( - this.block_); + /** @type {{saveConnections: function(!Block)}} */ (this.block_); mutatorBlock.saveConnections(this.rootBlock_); this.sourceListener_ = function() { mutatorBlock.saveConnections(thisMutator.rootBlock_); @@ -388,8 +374,7 @@ Mutator.prototype.setVisible = function(visible) { * @private */ Mutator.prototype.workspaceChanged_ = function(e) { - if (e.isUiEvent || - (e.type == Events.CHANGE && e.element == 'disabled')) { + if (e.isUiEvent || (e.type == Events.CHANGE && e.element == 'disabled')) { return; } From ccd314279e022002fe4feaa1011e43dd6c66c5de Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:24:43 -0700 Subject: [PATCH 014/291] Migrate core/registry.js to ES6 const/let --- core/registry.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/registry.js b/core/registry.js index 2959cf73e..0ea2883f8 100644 --- a/core/registry.js +++ b/core/registry.js @@ -139,7 +139,7 @@ Blockly.registry.register = function( if (!registryItem) { throw Error('Can not register a null value'); } - var typeRegistry = Blockly.registry.typeMap_[type]; + let typeRegistry = Blockly.registry.typeMap_[type]; // If the type registry has not been created, create it. if (!typeRegistry) { typeRegistry = Blockly.registry.typeMap_[type] = Object.create(null); @@ -184,7 +184,7 @@ Blockly.registry.validate_ = function(type, registryItem) { Blockly.registry.unregister = function(type, name) { type = String(type).toLowerCase(); name = name.toLowerCase(); - var typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = Blockly.registry.typeMap_[type]; if (!typeRegistry || !typeRegistry[name]) { console.warn('Unable to unregister [' + name + '][' + type + '] from the ' + 'registry.'); @@ -208,9 +208,9 @@ Blockly.registry.unregister = function(type, name) { Blockly.registry.getItem_ = function(type, name, opt_throwIfMissing) { type = String(type).toLowerCase(); name = name.toLowerCase(); - var typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = Blockly.registry.typeMap_[type]; if (!typeRegistry || !typeRegistry[name]) { - var msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; + const msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; if (opt_throwIfMissing) { throw new Error(msg + ' You must require or register a ' + type + ' plugin.'); @@ -235,7 +235,7 @@ Blockly.registry.getItem_ = function(type, name, opt_throwIfMissing) { Blockly.registry.hasItem = function(type, name) { type = String(type).toLowerCase(); name = name.toLowerCase(); - var typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = Blockly.registry.typeMap_[type]; if (!typeRegistry) { return false; } @@ -286,8 +286,8 @@ Blockly.registry.getObject = function(type, name, opt_throwIfMissing) { */ Blockly.registry.getClassFromOptions = function(type, options, opt_throwIfMissing) { - var typeName = type.toString(); - var plugin = options.plugins[typeName] || Blockly.registry.DEFAULT; + const typeName = type.toString(); + const plugin = options.plugins[typeName] || Blockly.registry.DEFAULT; // If the user passed in a plugin class instead of a registered plugin name. if (typeof plugin == 'function') { From 6ce759d15e02ffbd7bddb5902ccf7dca93d9f7f7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:40:02 -0700 Subject: [PATCH 015/291] Migrate core/registry.js to goog.module --- core/registry.js | 138 +++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 75 insertions(+), 65 deletions(-) diff --git a/core/registry.js b/core/registry.js index 0ea2883f8..9d7d72201 100644 --- a/core/registry.js +++ b/core/registry.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.registry'); +goog.module('Blockly.registry'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.blockRendering.Renderer'); goog.requireType('Blockly.Cursor'); @@ -34,13 +35,16 @@ goog.requireType('Blockly.ToolboxItem'); * * @type {Object>} */ -Blockly.registry.typeMap_ = Object.create(null); +const typeMap = Object.create(null); +/** @private */ +exports.typeMap_ = typeMap; /** * The string used to register the default class for a type of plugin. * @type {string} */ -Blockly.registry.DEFAULT = 'default'; +const DEFAULT = 'default'; +exports.DEFAULT = DEFAULT; /** * A name with the type of the element stored in the generic. @@ -48,67 +52,68 @@ Blockly.registry.DEFAULT = 'default'; * @constructor * @template T */ -Blockly.registry.Type = function(name) { +const Type = function(name) { /** * @type {string} * @private */ this.name_ = name; }; +exports.Type = Type; /** * Returns the name of the type. * @return {string} The name. * @override */ -Blockly.registry.Type.prototype.toString = function() { +Type.prototype.toString = function() { return this.name_; }; -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.CONNECTION_CHECKER = - new Blockly.registry.Type('connectionChecker'); +/** @type {!Type} */ +Type.CONNECTION_CHECKER = + new Type('connectionChecker'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.CURSOR = new Blockly.registry.Type('cursor'); +/** @type {!Type} */ +Type.CURSOR = new Type('cursor'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.EVENT = new Blockly.registry.Type('event'); +/** @type {!Type} */ +Type.EVENT = new Type('event'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.FIELD = new Blockly.registry.Type('field'); +/** @type {!Type} */ +Type.FIELD = new Type('field'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.RENDERER = new Blockly.registry.Type('renderer'); +/** @type {!Type} */ +Type.RENDERER = new Type('renderer'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.TOOLBOX = new Blockly.registry.Type('toolbox'); +/** @type {!Type} */ +Type.TOOLBOX = new Type('toolbox'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.THEME = new Blockly.registry.Type('theme'); +/** @type {!Type} */ +Type.THEME = new Type('theme'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.TOOLBOX_ITEM = new Blockly.registry.Type('toolboxItem'); +/** @type {!Type} */ +Type.TOOLBOX_ITEM = new Type('toolboxItem'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX = - new Blockly.registry.Type('flyoutsVerticalToolbox'); +/** @type {!Type} */ +Type.FLYOUTS_VERTICAL_TOOLBOX = + new Type('flyoutsVerticalToolbox'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX = - new Blockly.registry.Type('flyoutsHorizontalToolbox'); +/** @type {!Type} */ +Type.FLYOUTS_HORIZONTAL_TOOLBOX = + new Type('flyoutsHorizontalToolbox'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.METRICS_MANAGER = - new Blockly.registry.Type('metricsManager'); +/** @type {!Type} */ +Type.METRICS_MANAGER = + new Type('metricsManager'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.BLOCK_DRAGGER = - new Blockly.registry.Type('blockDragger'); +/** @type {!Type} */ +Type.BLOCK_DRAGGER = + new Type('blockDragger'); /** * Registers a class based on a type and name. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @param {?function(new:T, ...?)|Object} registryItem The class or object to @@ -120,13 +125,13 @@ Blockly.registry.Type.BLOCK_DRAGGER = * it's type. * @template T */ -Blockly.registry.register = function( +const register = function( type, name, registryItem, opt_allowOverrides) { - if ((!(type instanceof Blockly.registry.Type) && typeof type != 'string') || + if ((!(type instanceof Type) && typeof type != 'string') || String(type).trim() == '') { throw Error( 'Invalid type "' + type + '". The type must be a' + - ' non-empty string or a Blockly.registry.Type.'); + ' non-empty string or a Type.'); } type = String(type).toLowerCase(); @@ -139,14 +144,14 @@ Blockly.registry.register = function( if (!registryItem) { throw Error('Can not register a null value'); } - let typeRegistry = Blockly.registry.typeMap_[type]; + let typeRegistry = typeMap[type]; // If the type registry has not been created, create it. if (!typeRegistry) { - typeRegistry = Blockly.registry.typeMap_[type] = Object.create(null); + typeRegistry = typeMap[type] = Object.create(null); } // Validate that the given class has all the required properties. - Blockly.registry.validate_(type, registryItem); + validate(type, registryItem); // Don't throw an error if opt_allowOverrides is true. if (!opt_allowOverrides && typeRegistry[name]) { @@ -155,6 +160,7 @@ Blockly.registry.register = function( } typeRegistry[name] = registryItem; }; +exports.register = register; /** * Checks the given registry item for properties that are required based on the @@ -162,11 +168,10 @@ Blockly.registry.register = function( * @param {string} type The type of the plugin. (e.g. Field, Renderer) * @param {Function|Object} registryItem A class or object that we are checking * for the required properties. - * @private */ -Blockly.registry.validate_ = function(type, registryItem) { +const validate = function(type, registryItem) { switch (type) { - case String(Blockly.registry.Type.FIELD): + case String(Type.FIELD): if (typeof registryItem.fromJson != 'function') { throw Error('Type "' + type + '" must have a fromJson function'); } @@ -176,27 +181,28 @@ Blockly.registry.validate_ = function(type, registryItem) { /** * Unregisters the registry item with the given type and name. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @template T */ -Blockly.registry.unregister = function(type, name) { +const unregister = function(type, name) { type = String(type).toLowerCase(); name = name.toLowerCase(); - const typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = typeMap[type]; if (!typeRegistry || !typeRegistry[name]) { console.warn('Unable to unregister [' + name + '][' + type + '] from the ' + 'registry.'); return; } - delete Blockly.registry.typeMap_[type][name]; + delete typeMap[type][name]; }; +exports.unregister = unregister; /** * Gets the registry item for the given name and type. This can be either a * class or an object. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we @@ -205,10 +211,10 @@ Blockly.registry.unregister = function(type, name) { * name and type or null if none exists. * @template T */ -Blockly.registry.getItem_ = function(type, name, opt_throwIfMissing) { +const getItem = function(type, name, opt_throwIfMissing) { type = String(type).toLowerCase(); name = name.toLowerCase(); - const typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = typeMap[type]; if (!typeRegistry || !typeRegistry[name]) { const msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; if (opt_throwIfMissing) { @@ -225,26 +231,27 @@ Blockly.registry.getItem_ = function(type, name, opt_throwIfMissing) { /** * Returns whether or not the registry contains an item with the given type and * name. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @return {boolean} True if the registry has an item with the given type and * name, false otherwise. * @template T */ -Blockly.registry.hasItem = function(type, name) { +const hasItem = function(type, name) { type = String(type).toLowerCase(); name = name.toLowerCase(); - const typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = typeMap[type]; if (!typeRegistry) { return false; } return !!(typeRegistry[name]); }; +exports.hasItem = hasItem; /** * Gets the class for the given name and type. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we @@ -253,14 +260,15 @@ Blockly.registry.hasItem = function(type, name) { * null if none exists. * @template T */ -Blockly.registry.getClass = function(type, name, opt_throwIfMissing) { +const getClass = function(type, name, opt_throwIfMissing) { return /** @type {?function(new:T, ...?)} */ ( - Blockly.registry.getItem_(type, name, opt_throwIfMissing)); + getItem(type, name, opt_throwIfMissing)); }; +exports.getClass = getClass; /** * Gets the object for the given name and type. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Category) * @param {string} name The plugin's name. (Ex. logic_category) * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we @@ -268,15 +276,16 @@ Blockly.registry.getClass = function(type, name, opt_throwIfMissing) { * @return {?T} The object with the given name and type or null if none exists. * @template T */ -Blockly.registry.getObject = function(type, name, opt_throwIfMissing) { +const getObject = function(type, name, opt_throwIfMissing) { return /** @type {T} */ ( - Blockly.registry.getItem_(type, name, opt_throwIfMissing)); + getItem(type, name, opt_throwIfMissing)); }; +exports.getObject = getObject; /** * Gets the class from Blockly options for the given type. * This is used for plugins that override a built in feature. (e.g. Toolbox) - * @param {!Blockly.registry.Type} type The type of the plugin. + * @param {!Type} type The type of the plugin. * @param {!Blockly.Options} options The option object to check for the given * plugin. * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we @@ -284,14 +293,15 @@ Blockly.registry.getObject = function(type, name, opt_throwIfMissing) { * @return {?function(new:T, ...?)} The class for the plugin. * @template T */ -Blockly.registry.getClassFromOptions = function(type, options, +const getClassFromOptions = function(type, options, opt_throwIfMissing) { const typeName = type.toString(); - const plugin = options.plugins[typeName] || Blockly.registry.DEFAULT; + const plugin = options.plugins[typeName] || DEFAULT; // If the user passed in a plugin class instead of a registered plugin name. if (typeof plugin == 'function') { return plugin; } - return Blockly.registry.getClass(type, plugin, opt_throwIfMissing); + return getClass(type, plugin, opt_throwIfMissing); }; +exports.getClassFromOptions = getClassFromOptions; diff --git a/tests/deps.js b/tests/deps.js index de575339f..93d8ee6a0 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -117,7 +117,7 @@ goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Bl 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.internalConstants', 'Blockly.utils.xml']); -goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); +goog.addDependency('../../core/registry.js', ['Blockly.registry'], [], {'lang': 'es6', 'module': 'goog'}); 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'}); From 6c40e05dc83973d108a4baf1b7997745b8b81140 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:46:35 -0700 Subject: [PATCH 016/291] Migrate core/registry.js to named requires --- core/registry.js | 62 +++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/core/registry.js b/core/registry.js index 9d7d72201..8c29a6e3e 100644 --- a/core/registry.js +++ b/core/registry.js @@ -14,18 +14,30 @@ goog.module('Blockly.registry'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.blockRendering.Renderer'); -goog.requireType('Blockly.Cursor'); -goog.requireType('Blockly.Events.Abstract'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IBlockDragger'); -goog.requireType('Blockly.IConnectionChecker'); -goog.requireType('Blockly.IFlyout'); -goog.requireType('Blockly.IMetricsManager'); -goog.requireType('Blockly.IToolbox'); -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.Theme'); -goog.requireType('Blockly.ToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ +const Abstract = goog.requireType('Blockly.Events.Abstract'); +/* eslint-disable-next-line no-unused-vars */ +const Cursor = goog.requireType('Blockly.Cursor'); +/* eslint-disable-next-line no-unused-vars */ +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 IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ +const IFlyout = goog.requireType('Blockly.IFlyout'); +/* eslint-disable-next-line no-unused-vars */ +const IMetricsManager = goog.requireType('Blockly.IMetricsManager'); +/* eslint-disable-next-line no-unused-vars */ +const IToolbox = goog.requireType('Blockly.IToolbox'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +/* eslint-disable-next-line no-unused-vars */ +const Renderer = goog.requireType('Blockly.blockRendering.Renderer'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const ToolboxItem = goog.requireType('Blockly.ToolboxItem'); /** @@ -70,44 +82,44 @@ Type.prototype.toString = function() { return this.name_; }; -/** @type {!Type} */ +/** @type {!Type} */ Type.CONNECTION_CHECKER = new Type('connectionChecker'); -/** @type {!Type} */ +/** @type {!Type} */ Type.CURSOR = new Type('cursor'); -/** @type {!Type} */ +/** @type {!Type} */ Type.EVENT = new Type('event'); -/** @type {!Type} */ +/** @type {!Type} */ Type.FIELD = new Type('field'); -/** @type {!Type} */ +/** @type {!Type} */ Type.RENDERER = new Type('renderer'); -/** @type {!Type} */ +/** @type {!Type} */ Type.TOOLBOX = new Type('toolbox'); -/** @type {!Type} */ +/** @type {!Type} */ Type.THEME = new Type('theme'); -/** @type {!Type} */ +/** @type {!Type} */ Type.TOOLBOX_ITEM = new Type('toolboxItem'); -/** @type {!Type} */ +/** @type {!Type} */ Type.FLYOUTS_VERTICAL_TOOLBOX = new Type('flyoutsVerticalToolbox'); -/** @type {!Type} */ +/** @type {!Type} */ Type.FLYOUTS_HORIZONTAL_TOOLBOX = new Type('flyoutsHorizontalToolbox'); -/** @type {!Type} */ +/** @type {!Type} */ Type.METRICS_MANAGER = new Type('metricsManager'); -/** @type {!Type} */ +/** @type {!Type} */ Type.BLOCK_DRAGGER = new Type('blockDragger'); @@ -286,7 +298,7 @@ exports.getObject = getObject; * Gets the class from Blockly options for the given type. * This is used for plugins that override a built in feature. (e.g. Toolbox) * @param {!Type} type The type of the plugin. - * @param {!Blockly.Options} options The option object to check for the given + * @param {!Options} options The option object to check for the given * plugin. * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we * are unable to find the plugin. From e0efd4cf29293dd5ee348ccde3674c171be8905a Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:47:06 -0700 Subject: [PATCH 017/291] clang-format core/registry.js --- core/registry.js | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/core/registry.js b/core/registry.js index 8c29a6e3e..1be9b2a2b 100644 --- a/core/registry.js +++ b/core/registry.js @@ -83,8 +83,7 @@ Type.prototype.toString = function() { }; /** @type {!Type} */ -Type.CONNECTION_CHECKER = - new Type('connectionChecker'); +Type.CONNECTION_CHECKER = new Type('connectionChecker'); /** @type {!Type} */ Type.CURSOR = new Type('cursor'); @@ -108,20 +107,16 @@ Type.THEME = new Type('theme'); Type.TOOLBOX_ITEM = new Type('toolboxItem'); /** @type {!Type} */ -Type.FLYOUTS_VERTICAL_TOOLBOX = - new Type('flyoutsVerticalToolbox'); +Type.FLYOUTS_VERTICAL_TOOLBOX = new Type('flyoutsVerticalToolbox'); /** @type {!Type} */ -Type.FLYOUTS_HORIZONTAL_TOOLBOX = - new Type('flyoutsHorizontalToolbox'); +Type.FLYOUTS_HORIZONTAL_TOOLBOX = new Type('flyoutsHorizontalToolbox'); /** @type {!Type} */ -Type.METRICS_MANAGER = - new Type('metricsManager'); +Type.METRICS_MANAGER = new Type('metricsManager'); /** @type {!Type} */ -Type.BLOCK_DRAGGER = - new Type('blockDragger'); +Type.BLOCK_DRAGGER = new Type('blockDragger'); /** * Registers a class based on a type and name. @@ -137,8 +132,7 @@ Type.BLOCK_DRAGGER = * it's type. * @template T */ -const register = function( - type, name, registryItem, opt_allowOverrides) { +const register = function(type, name, registryItem, opt_allowOverrides) { if ((!(type instanceof Type) && typeof type != 'string') || String(type).trim() == '') { throw Error( @@ -203,8 +197,9 @@ const unregister = function(type, name) { name = name.toLowerCase(); const typeRegistry = typeMap[type]; if (!typeRegistry || !typeRegistry[name]) { - console.warn('Unable to unregister [' + name + '][' + type + '] from the ' + - 'registry.'); + console.warn( + 'Unable to unregister [' + name + '][' + type + '] from the ' + + 'registry.'); return; } delete typeMap[type][name]; @@ -230,8 +225,8 @@ const getItem = function(type, name, opt_throwIfMissing) { if (!typeRegistry || !typeRegistry[name]) { const msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; if (opt_throwIfMissing) { - throw new Error(msg + ' You must require or register a ' + type + - ' plugin.'); + throw new Error( + msg + ' You must require or register a ' + type + ' plugin.'); } else { console.warn(msg); } @@ -274,7 +269,7 @@ exports.hasItem = hasItem; */ const getClass = function(type, name, opt_throwIfMissing) { return /** @type {?function(new:T, ...?)} */ ( - getItem(type, name, opt_throwIfMissing)); + getItem(type, name, opt_throwIfMissing)); }; exports.getClass = getClass; @@ -289,8 +284,7 @@ exports.getClass = getClass; * @template T */ const getObject = function(type, name, opt_throwIfMissing) { - return /** @type {T} */ ( - getItem(type, name, opt_throwIfMissing)); + return /** @type {T} */ (getItem(type, name, opt_throwIfMissing)); }; exports.getObject = getObject; @@ -305,8 +299,7 @@ exports.getObject = getObject; * @return {?function(new:T, ...?)} The class for the plugin. * @template T */ -const getClassFromOptions = function(type, options, - opt_throwIfMissing) { +const getClassFromOptions = function(type, options, opt_throwIfMissing) { const typeName = type.toString(); const plugin = options.plugins[typeName] || DEFAULT; From d5f729e636b2c318b820b79afceabcfbfc74e1d1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:56:57 -0700 Subject: [PATCH 018/291] Migrate core/rendered_connection.js to ES6 const/let --- core/rendered_connection.js | 88 ++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/core/rendered_connection.js b/core/rendered_connection.js index cddda9200..11c7a9a6d 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -135,8 +135,8 @@ Blockly.RenderedConnection.prototype.targetBlock = function() { * @return {number} The distance between connections, in workspace units. */ Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) { - var xDiff = this.x - otherConnection.x; - var yDiff = this.y - otherConnection.y; + const xDiff = this.x - otherConnection.x; + const yDiff = this.y - otherConnection.y; return Math.sqrt(xDiff * xDiff + yDiff * yDiff); }; @@ -153,12 +153,12 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { return; } // Move the root block. - var rootBlock = this.sourceBlock_.getRootBlock(); + let rootBlock = this.sourceBlock_.getRootBlock(); if (rootBlock.isInFlyout) { // Don't move blocks around in a flyout. return; } - var reverse = false; + let reverse = false; if (!rootBlock.isMovable()) { // Can't bump an uneditable block away. // Check to see if the other block is movable. @@ -171,13 +171,13 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { reverse = true; } // Raise it to the top for extra visibility. - var selected = Blockly.selected == rootBlock; + const selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); - var dx = + let dx = (staticConnection.x + Blockly.internalConstants.SNAP_RADIUS + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - this.x; - var dy = + let dy = (staticConnection.y + Blockly.internalConstants.SNAP_RADIUS + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - this.y; @@ -257,16 +257,16 @@ Blockly.RenderedConnection.prototype.getOffsetInBlock = function() { * @package */ Blockly.RenderedConnection.prototype.tighten = function() { - var dx = this.targetConnection.x - this.x; - var dy = this.targetConnection.y - this.y; + const dx = this.targetConnection.x - this.x; + const dy = this.targetConnection.y - this.y; if (dx != 0 || dy != 0) { - var block = this.targetBlock(); - var svgRoot = block.getSvgRoot(); + const block = this.targetBlock(); + const svgRoot = block.getSvgRoot(); if (!svgRoot) { throw Error('block is not rendered.'); } // Workspace coordinates. - var xy = Blockly.utils.getRelativeXY(svgRoot); + const xy = Blockly.utils.getRelativeXY(svgRoot); block.getSvgRoot().setAttribute('transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); block.moveConnections(-dx, -dy); @@ -291,20 +291,20 @@ Blockly.RenderedConnection.prototype.closest = function(maxLimit, dxy) { * Add highlighting around this connection. */ Blockly.RenderedConnection.prototype.highlight = function() { - var steps; - var sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); - var renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); - var shape = renderConstants.shapeFor(this); + let steps; + const sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); + const shape = renderConstants.shapeFor(this); if (this.type == Blockly.connectionTypes.INPUT_VALUE || this.type == Blockly.connectionTypes.OUTPUT_VALUE) { // Vertical line, puzzle tab, vertical line. - var yLen = renderConstants.TAB_OFFSET_FROM_TOP; + const yLen = renderConstants.TAB_OFFSET_FROM_TOP; steps = Blockly.utils.svgPaths.moveBy(0, -yLen) + Blockly.utils.svgPaths.lineOnAxis('v', yLen) + shape.pathDown + Blockly.utils.svgPaths.lineOnAxis('v', yLen); } else { - var xLen = + const xLen = renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; // Horizontal line, notch, horizontal line. steps = Blockly.utils.svgPaths.moveBy(-xLen, 0) + @@ -312,9 +312,9 @@ Blockly.RenderedConnection.prototype.highlight = function() { shape.pathLeft + Blockly.utils.svgPaths.lineOnAxis('h', xLen); } - var xy = this.sourceBlock_.getRelativeToSurfaceXY(); - var x = this.x - xy.x; - var y = this.y - xy.y; + const xy = this.sourceBlock_.getRelativeToSurfaceXY(); + const x = this.x - xy.x; + const y = this.y - xy.y; Blockly.Connection.highlightedPath_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATH, { @@ -372,17 +372,17 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { Blockly.RenderedConnection.prototype.stopTrackingAll = function() { this.setTracking(false); if (this.targetConnection) { - var blocks = this.targetBlock().getDescendants(false); - for (var i = 0; i < blocks.length; i++) { - var block = blocks[i]; + const blocks = this.targetBlock().getDescendants(false); + for (let i = 0; i < blocks.length; i++) { + const block = blocks[i]; // Stop tracking connections of all children. - var connections = block.getConnections_(true); - for (var j = 0; j < connections.length; j++) { + const connections = block.getConnections_(true); + for (let j = 0; j < connections.length; j++) { connections[j].setTracking(false); } // Close all bubbles of all children. - var icons = block.getIcons(); - for (var j = 0; j < icons.length; j++) { + const icons = block.getIcons(); + for (let j = 0; j < icons.length; j++) { icons[j].setVisible(false); } } @@ -400,15 +400,15 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() { // rendering takes place, since rendering requires knowing the dimensions // of lower blocks. Also, since rendering a block renders all its parents, // we only need to render the leaf nodes. - var renderList = []; + const renderList = []; if (this.type != Blockly.connectionTypes.INPUT_VALUE && this.type != Blockly.connectionTypes.NEXT_STATEMENT) { // Only spider down. return renderList; } - var block = this.targetBlock(); + const block = this.targetBlock(); if (block) { - var connections; + let connections; if (block.isCollapsed()) { // This block should only be partially revealed since it is collapsed. connections = []; @@ -419,7 +419,7 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() { // Show all connections of this block. connections = block.getConnections_(true); } - for (var i = 0; i < connections.length; i++) { + for (let i = 0; i < connections.length; i++) { renderList.push.apply(renderList, connections[i].startTrackingAll()); } if (!renderList.length) { @@ -463,9 +463,9 @@ Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate, */ Blockly.RenderedConnection.prototype.onFailedConnect = function(otherConnection) { - var block = this.getSourceBlock(); + const block = this.getSourceBlock(); if (Blockly.Events.recordUndo) { - var group = Blockly.Events.getGroup(); + const group = Blockly.Events.getGroup(); setTimeout(function() { if (!block.isDisposed() && !block.getParent()) { Blockly.Events.setGroup(group); @@ -508,7 +508,7 @@ Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, */ Blockly.RenderedConnection.prototype.respawnShadow_ = function() { Blockly.RenderedConnection.superClass_.respawnShadow_.call(this); - var blockShadow = this.targetBlock(); + const blockShadow = this.targetBlock(); if (!blockShadow) { // This connection must not have a shadowDom_. return; @@ -516,7 +516,7 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() { blockShadow.initSvg(); blockShadow.render(false); - var parentBlock = this.getSourceBlock(); + const parentBlock = this.getSourceBlock(); if (parentBlock.rendered) { parentBlock.render(); } @@ -543,11 +543,11 @@ Blockly.RenderedConnection.prototype.neighbours = function(maxLimit) { Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { Blockly.RenderedConnection.superClass_.connect_.call(this, childConnection); - var parentConnection = this; - var parentBlock = parentConnection.getSourceBlock(); - var childBlock = childConnection.getSourceBlock(); - var parentRendered = parentBlock.rendered; - var childRendered = childBlock.rendered; + const parentConnection = this; + const parentBlock = parentConnection.getSourceBlock(); + const childBlock = childConnection.getSourceBlock(); + const parentRendered = parentBlock.rendered; + const childRendered = childBlock.rendered; if (parentRendered) { parentBlock.updateDisabled(); @@ -569,9 +569,9 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { } // The input the child block is connected to (if any). - var parentInput = parentBlock.getInputWithBlock(childBlock); + const parentInput = parentBlock.getInputWithBlock(childBlock); if (parentInput) { - var visible = parentInput.isVisible(); + const visible = parentInput.isVisible(); childBlock.getSvgRoot().style.display = visible ? 'block' : 'none'; } }; @@ -585,7 +585,7 @@ Blockly.RenderedConnection.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(); // Bump away. this.sourceBlock_.bumpNeighbours(); From 07b2e07ba88903ff385ebdc595c59f9eab9f9a95 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:59:41 -0700 Subject: [PATCH 019/291] Migrate core/rendered_connection.js to goog.module --- core/rendered_connection.js | 99 +++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 11c7a9a6d..a4d265746 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.RenderedConnection'); +goog.module('Blockly.RenderedConnection'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Connection'); goog.require('Blockly.connectionTypes'); @@ -34,8 +35,8 @@ goog.requireType('Blockly.ConnectionDB'); * @extends {Blockly.Connection} * @constructor */ -Blockly.RenderedConnection = function(source, type) { - Blockly.RenderedConnection.superClass_.constructor.call(this, source, type); +const RenderedConnection = function(source, type) { + RenderedConnection.superClass_.constructor.call(this, source, type); /** * Connection database for connections of this type on the current workspace. @@ -63,18 +64,18 @@ Blockly.RenderedConnection = function(source, type) { /** * Describes the state of this connection's tracked-ness. - * @type {Blockly.RenderedConnection.TrackedState} + * @type {RenderedConnection.TrackedState} * @private */ - this.trackedState_ = Blockly.RenderedConnection.TrackedState.WILL_TRACK; + this.trackedState_ = RenderedConnection.TrackedState.WILL_TRACK; /** * Connection this connection connects to. Null if not connected. - * @type {Blockly.RenderedConnection} + * @type {RenderedConnection} */ this.targetConnection = null; }; -Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection); +Blockly.utils.object.inherits(RenderedConnection, Blockly.Connection); /** * Enum for different kinds of tracked states. @@ -88,7 +89,7 @@ Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection); * TRACKED means that this connection is currently being tracked. * @enum {number} */ -Blockly.RenderedConnection.TrackedState = { +RenderedConnection.TrackedState = { WILL_TRACK: -1, UNTRACKED: 0, TRACKED: 1 @@ -100,9 +101,9 @@ Blockly.RenderedConnection.TrackedState = { * @override * @package */ -Blockly.RenderedConnection.prototype.dispose = function() { - Blockly.RenderedConnection.superClass_.dispose.call(this); - if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.TRACKED) { +RenderedConnection.prototype.dispose = function() { + RenderedConnection.superClass_.dispose.call(this); + if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) { this.db_.removeConnection(this, this.y); } }; @@ -112,9 +113,9 @@ Blockly.RenderedConnection.prototype.dispose = function() { * @return {!Blockly.BlockSvg} The source block. * @override */ -Blockly.RenderedConnection.prototype.getSourceBlock = function() { +RenderedConnection.prototype.getSourceBlock = function() { return /** @type {!Blockly.BlockSvg} */ ( - Blockly.RenderedConnection.superClass_.getSourceBlock.call(this)); + RenderedConnection.superClass_.getSourceBlock.call(this)); }; /** @@ -122,9 +123,9 @@ Blockly.RenderedConnection.prototype.getSourceBlock = function() { * @return {?Blockly.BlockSvg} The connected block or null if none is connected. * @override */ -Blockly.RenderedConnection.prototype.targetBlock = function() { +RenderedConnection.prototype.targetBlock = function() { return /** @type {Blockly.BlockSvg} */ ( - Blockly.RenderedConnection.superClass_.targetBlock.call(this)); + RenderedConnection.superClass_.targetBlock.call(this)); }; /** @@ -134,7 +135,7 @@ Blockly.RenderedConnection.prototype.targetBlock = function() { * the distance to. * @return {number} The distance between connections, in workspace units. */ -Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) { +RenderedConnection.prototype.distanceFrom = function(otherConnection) { const xDiff = this.x - otherConnection.x; const yDiff = this.y - otherConnection.y; return Math.sqrt(xDiff * xDiff + yDiff * yDiff); @@ -147,7 +148,7 @@ Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) { * from. * @package */ -Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { +RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { if (this.sourceBlock_.workspace.isDragging()) { // Don't move blocks around while the user is doing the same. return; @@ -200,11 +201,11 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { * @param {number} x New absolute x coordinate, in workspace coordinates. * @param {number} y New absolute y coordinate, in workspace coordinates. */ -Blockly.RenderedConnection.prototype.moveTo = function(x, y) { - if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.WILL_TRACK) { +RenderedConnection.prototype.moveTo = function(x, y) { + if (this.trackedState_ == RenderedConnection.TrackedState.WILL_TRACK) { this.db_.addConnection(this, y); - this.trackedState_ = Blockly.RenderedConnection.TrackedState.TRACKED; - } else if (this.trackedState_ == Blockly.RenderedConnection + this.trackedState_ = RenderedConnection.TrackedState.TRACKED; + } else if (this.trackedState_ == RenderedConnection .TrackedState.TRACKED) { this.db_.removeConnection(this, this.y); this.db_.addConnection(this, y); @@ -218,7 +219,7 @@ Blockly.RenderedConnection.prototype.moveTo = function(x, y) { * @param {number} dx Change to x coordinate, in workspace units. * @param {number} dy Change to y coordinate, in workspace units. */ -Blockly.RenderedConnection.prototype.moveBy = function(dx, dy) { +RenderedConnection.prototype.moveBy = function(dx, dy) { this.moveTo(this.x + dx, this.y + dy); }; @@ -228,7 +229,7 @@ Blockly.RenderedConnection.prototype.moveBy = function(dx, dy) { * @param {!Blockly.utils.Coordinate} blockTL The location of the top left * corner of the block, in workspace coordinates. */ -Blockly.RenderedConnection.prototype.moveToOffset = function(blockTL) { +RenderedConnection.prototype.moveToOffset = function(blockTL) { this.moveTo(blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y); }; @@ -238,7 +239,7 @@ Blockly.RenderedConnection.prototype.moveToOffset = function(blockTL) { * @param {number} x The new relative x, in workspace units. * @param {number} y The new relative y, in workspace units. */ -Blockly.RenderedConnection.prototype.setOffsetInBlock = function(x, y) { +RenderedConnection.prototype.setOffsetInBlock = function(x, y) { this.offsetInBlock_.x = x; this.offsetInBlock_.y = y; }; @@ -248,7 +249,7 @@ Blockly.RenderedConnection.prototype.setOffsetInBlock = function(x, y) { * @return {!Blockly.utils.Coordinate} The offset of the connection. * @package */ -Blockly.RenderedConnection.prototype.getOffsetInBlock = function() { +RenderedConnection.prototype.getOffsetInBlock = function() { return this.offsetInBlock_; }; @@ -256,7 +257,7 @@ Blockly.RenderedConnection.prototype.getOffsetInBlock = function() { * Move the blocks on either side of this connection right next to each other. * @package */ -Blockly.RenderedConnection.prototype.tighten = function() { +RenderedConnection.prototype.tighten = function() { const dx = this.targetConnection.x - this.x; const dy = this.targetConnection.y - this.y; if (dx != 0 || dy != 0) { @@ -283,14 +284,14 @@ Blockly.RenderedConnection.prototype.tighten = function() { * properties: 'connection' which is either another connection or null, * and 'radius' which is the distance. */ -Blockly.RenderedConnection.prototype.closest = function(maxLimit, dxy) { +RenderedConnection.prototype.closest = function(maxLimit, dxy) { return this.dbOpposite_.searchForClosest(this, maxLimit, dxy); }; /** * Add highlighting around this connection. */ -Blockly.RenderedConnection.prototype.highlight = function() { +RenderedConnection.prototype.highlight = function() { let steps; const sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); @@ -329,7 +330,7 @@ Blockly.RenderedConnection.prototype.highlight = function() { /** * Remove the highlighting around this connection. */ -Blockly.RenderedConnection.prototype.unhighlight = function() { +RenderedConnection.prototype.unhighlight = function() { Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_); delete Blockly.Connection.highlightedPath_; }; @@ -339,11 +340,11 @@ Blockly.RenderedConnection.prototype.unhighlight = function() { * @param {boolean} doTracking If true, start tracking. If false, stop tracking. * @package */ -Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { +RenderedConnection.prototype.setTracking = function(doTracking) { if ((doTracking && this.trackedState_ == - Blockly.RenderedConnection.TrackedState.TRACKED) || + RenderedConnection.TrackedState.TRACKED) || (!doTracking && this.trackedState_ == - Blockly.RenderedConnection.TrackedState.UNTRACKED)) { + RenderedConnection.TrackedState.UNTRACKED)) { return; } if (this.sourceBlock_.isInFlyout) { @@ -352,13 +353,13 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { } if (doTracking) { this.db_.addConnection(this, this.y); - this.trackedState_ = Blockly.RenderedConnection.TrackedState.TRACKED; + this.trackedState_ = RenderedConnection.TrackedState.TRACKED; return; } - if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.TRACKED) { + if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) { this.db_.removeConnection(this, this.y); } - this.trackedState_ = Blockly.RenderedConnection.TrackedState.UNTRACKED; + this.trackedState_ = RenderedConnection.TrackedState.UNTRACKED; }; /** @@ -369,7 +370,7 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { * Also closes down-stream icons/bubbles. * @package */ -Blockly.RenderedConnection.prototype.stopTrackingAll = function() { +RenderedConnection.prototype.stopTrackingAll = function() { this.setTracking(false); if (this.targetConnection) { const blocks = this.targetBlock().getDescendants(false); @@ -394,7 +395,7 @@ Blockly.RenderedConnection.prototype.stopTrackingAll = function() { * any block attached to this connection. This happens when a block is expanded. * @return {!Array} List of blocks to render. */ -Blockly.RenderedConnection.prototype.startTrackingAll = function() { +RenderedConnection.prototype.startTrackingAll = function() { this.setTracking(true); // All blocks that are not tracked must start tracking before any // rendering takes place, since rendering requires knowing the dimensions @@ -438,7 +439,7 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() { * @return {boolean} True if the connection is allowed, false otherwise. * @deprecated July 2020 */ -Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate, +RenderedConnection.prototype.isConnectionAllowed = function(candidate, maxRadius) { Blockly.utils.deprecation.warn( 'RenderedConnection.prototype.isConnectionAllowed', @@ -449,7 +450,7 @@ Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate, return false; } - return Blockly.RenderedConnection.superClass_.isConnectionAllowed.call(this, + return RenderedConnection.superClass_.isConnectionAllowed.call(this, candidate); }; @@ -461,7 +462,7 @@ Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate, * failed to connect to. * @package */ -Blockly.RenderedConnection.prototype.onFailedConnect = +RenderedConnection.prototype.onFailedConnect = function(otherConnection) { const block = this.getSourceBlock(); if (Blockly.Events.recordUndo) { @@ -484,9 +485,9 @@ Blockly.RenderedConnection.prototype.onFailedConnect = * @protected * @override */ -Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, +RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { - Blockly.RenderedConnection.superClass_.disconnectInternal_.call(this, + RenderedConnection.superClass_.disconnectInternal_.call(this, parentBlock, childBlock); // Rerender the parent so that it may reflow. if (parentBlock.rendered) { @@ -506,8 +507,8 @@ Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, * @protected * @override */ -Blockly.RenderedConnection.prototype.respawnShadow_ = function() { - Blockly.RenderedConnection.superClass_.respawnShadow_.call(this); +RenderedConnection.prototype.respawnShadow_ = function() { + RenderedConnection.superClass_.respawnShadow_.call(this); const blockShadow = this.targetBlock(); if (!blockShadow) { // This connection must not have a shadowDom_. @@ -530,7 +531,7 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() { * @return {!Array} List of connections. * @package */ -Blockly.RenderedConnection.prototype.neighbours = function(maxLimit) { +RenderedConnection.prototype.neighbours = function(maxLimit) { return this.dbOpposite_.getNeighbours(this, maxLimit); }; @@ -540,8 +541,8 @@ Blockly.RenderedConnection.prototype.neighbours = function(maxLimit) { * @param {!Blockly.Connection} childConnection Connection on inferior block. * @protected */ -Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { - Blockly.RenderedConnection.superClass_.connect_.call(this, childConnection); +RenderedConnection.prototype.connect_ = function(childConnection) { + RenderedConnection.superClass_.connect_.call(this, childConnection); const parentConnection = this; const parentBlock = parentConnection.getSourceBlock(); @@ -580,7 +581,7 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { * Function to be called when this connection's compatible types have changed. * @protected */ -Blockly.RenderedConnection.prototype.onCheckChanged_ = function() { +RenderedConnection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( @@ -591,3 +592,5 @@ Blockly.RenderedConnection.prototype.onCheckChanged_ = function() { this.sourceBlock_.bumpNeighbours(); } }; + +exports = RenderedConnection; diff --git a/tests/deps.js b/tests/deps.js index de575339f..367e41229 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,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.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/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'], {'lang': 'es6', 'module': 'goog'}); 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/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'}); From c9225da3f3038f7965f9bb94de6aebdd09fa2185 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 10:38:47 -0700 Subject: [PATCH 020/291] Migrate core/rendered_connection.js to named requires --- core/rendered_connection.js | 139 ++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 72 insertions(+), 69 deletions(-) diff --git a/core/rendered_connection.js b/core/rendered_connection.js index a4d265746..953062f20 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -13,26 +13,29 @@ goog.module('Blockly.RenderedConnection'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Connection'); -goog.require('Blockly.connectionTypes'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.deprecation'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.ConnectionDB'); +/* 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 Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const ConnectionDB = goog.requireType('Blockly.ConnectionDB'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Events = goog.require('Blockly.Events'); +const Svg = goog.require('Blockly.utils.Svg'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const deprecation = goog.require('Blockly.utils.deprecation'); +const dom = goog.require('Blockly.utils.dom'); +const internalConstants = goog.require('Blockly.internalConstants'); +const object = goog.require('Blockly.utils.object'); +const utils = goog.require('Blockly.utils'); /** * Class for a connection between blocks that may be rendered on screen. - * @param {!Blockly.BlockSvg} source The block establishing this connection. + * @param {!BlockSvg} source The block establishing this connection. * @param {number} type The type of the connection. - * @extends {Blockly.Connection} + * @extends {Connection} * @constructor */ const RenderedConnection = function(source, type) { @@ -40,7 +43,7 @@ const RenderedConnection = function(source, type) { /** * Connection database for connections of this type on the current workspace. - * @const {!Blockly.ConnectionDB} + * @const {!ConnectionDB} * @private */ this.db_ = source.workspace.connectionDBList[type]; @@ -48,19 +51,19 @@ const RenderedConnection = function(source, type) { /** * Connection database for connections compatible with this type on the * current workspace. - * @const {!Blockly.ConnectionDB} + * @const {!ConnectionDB} * @private */ this.dbOpposite_ = source.workspace - .connectionDBList[Blockly.internalConstants.OPPOSITE_TYPE[type]]; + .connectionDBList[internalConstants.OPPOSITE_TYPE[type]]; /** * Workspace units, (0, 0) is top left of block. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ - this.offsetInBlock_ = new Blockly.utils.Coordinate(0, 0); + this.offsetInBlock_ = new Coordinate(0, 0); /** * Describes the state of this connection's tracked-ness. @@ -75,7 +78,7 @@ const RenderedConnection = function(source, type) { */ this.targetConnection = null; }; -Blockly.utils.object.inherits(RenderedConnection, Blockly.Connection); +object.inherits(RenderedConnection, Connection); /** * Enum for different kinds of tracked states. @@ -110,28 +113,28 @@ RenderedConnection.prototype.dispose = function() { /** * Get the source block for this connection. - * @return {!Blockly.BlockSvg} The source block. + * @return {!BlockSvg} The source block. * @override */ RenderedConnection.prototype.getSourceBlock = function() { - return /** @type {!Blockly.BlockSvg} */ ( + return /** @type {!BlockSvg} */ ( RenderedConnection.superClass_.getSourceBlock.call(this)); }; /** * Returns the block that this connection connects to. - * @return {?Blockly.BlockSvg} The connected block or null if none is connected. + * @return {?BlockSvg} The connected block or null if none is connected. * @override */ RenderedConnection.prototype.targetBlock = function() { - return /** @type {Blockly.BlockSvg} */ ( + return /** @type {BlockSvg} */ ( RenderedConnection.superClass_.targetBlock.call(this)); }; /** * Returns the distance between this connection and another connection in * workspace units. - * @param {!Blockly.Connection} otherConnection The other connection to measure + * @param {!Connection} otherConnection The other connection to measure * the distance to. * @return {number} The distance between connections, in workspace units. */ @@ -144,7 +147,7 @@ RenderedConnection.prototype.distanceFrom = function(otherConnection) { /** * Move the block(s) belonging to the connection to a point where they don't * visually interfere with the specified connection. - * @param {!Blockly.Connection} staticConnection The connection to move away + * @param {!Connection} staticConnection The connection to move away * from. * @package */ @@ -175,21 +178,21 @@ RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { const selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); let dx = - (staticConnection.x + Blockly.internalConstants.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + (staticConnection.x + internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.x; let dy = - (staticConnection.y + Blockly.internalConstants.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + (staticConnection.y + internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * 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.internalConstants.SNAP_RADIUS - + dx = (staticConnection.x - internalConstants.SNAP_RADIUS - Math.floor( - Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.x; } rootBlock.moveBy(dx, dy); @@ -226,7 +229,7 @@ RenderedConnection.prototype.moveBy = function(dx, dy) { /** * Move this connection to the location given by its offset within the block and * the location of the block's top left corner. - * @param {!Blockly.utils.Coordinate} blockTL The location of the top left + * @param {!Coordinate} blockTL The location of the top left * corner of the block, in workspace coordinates. */ RenderedConnection.prototype.moveToOffset = function(blockTL) { @@ -246,7 +249,7 @@ RenderedConnection.prototype.setOffsetInBlock = function(x, y) { /** * Get the offset of this connection relative to the top left of its block. - * @return {!Blockly.utils.Coordinate} The offset of the connection. + * @return {!Coordinate} The offset of the connection. * @package */ RenderedConnection.prototype.getOffsetInBlock = function() { @@ -267,7 +270,7 @@ RenderedConnection.prototype.tighten = function() { throw Error('block is not rendered.'); } // Workspace coordinates. - const xy = Blockly.utils.getRelativeXY(svgRoot); + const xy = utils.getRelativeXY(svgRoot); block.getSvgRoot().setAttribute('transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); block.moveConnections(-dx, -dy); @@ -278,9 +281,9 @@ RenderedConnection.prototype.tighten = function() { * Find the closest compatible connection to this connection. * All parameters are in workspace units. * @param {number} maxLimit The maximum radius to another connection. - * @param {!Blockly.utils.Coordinate} dxy Offset between this connection's location + * @param {!Coordinate} dxy Offset between this connection's location * in the database and the current location (as a result of dragging). - * @return {!{connection: ?Blockly.Connection, radius: number}} Contains two + * @return {!{connection: ?Connection, radius: number}} Contains two * properties: 'connection' which is either another connection or null, * and 'radius' which is the distance. */ @@ -293,31 +296,31 @@ RenderedConnection.prototype.closest = function(maxLimit, dxy) { */ RenderedConnection.prototype.highlight = function() { let steps; - const sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + const sourceBlockSvg = /** @type {!BlockSvg} */ (this.sourceBlock_); const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); const shape = renderConstants.shapeFor(this); - if (this.type == Blockly.connectionTypes.INPUT_VALUE || - this.type == Blockly.connectionTypes.OUTPUT_VALUE) { + if (this.type == connectionTypes.INPUT_VALUE || + this.type == connectionTypes.OUTPUT_VALUE) { // Vertical line, puzzle tab, vertical line. const yLen = renderConstants.TAB_OFFSET_FROM_TOP; - steps = Blockly.utils.svgPaths.moveBy(0, -yLen) + - Blockly.utils.svgPaths.lineOnAxis('v', yLen) + + steps = utils.svgPaths.moveBy(0, -yLen) + + utils.svgPaths.lineOnAxis('v', yLen) + shape.pathDown + - Blockly.utils.svgPaths.lineOnAxis('v', yLen); + utils.svgPaths.lineOnAxis('v', yLen); } else { const xLen = renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; // Horizontal line, notch, horizontal line. - steps = Blockly.utils.svgPaths.moveBy(-xLen, 0) + - Blockly.utils.svgPaths.lineOnAxis('h', xLen) + + steps = utils.svgPaths.moveBy(-xLen, 0) + + utils.svgPaths.lineOnAxis('h', xLen) + shape.pathLeft + - Blockly.utils.svgPaths.lineOnAxis('h', xLen); + utils.svgPaths.lineOnAxis('h', xLen); } const xy = this.sourceBlock_.getRelativeToSurfaceXY(); const x = this.x - xy.x; const y = this.y - xy.y; - Blockly.Connection.highlightedPath_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + Connection.highlightedPath_ = dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyHighlightedConnectionPath', 'd': steps, @@ -331,8 +334,8 @@ RenderedConnection.prototype.highlight = function() { * Remove the highlighting around this connection. */ RenderedConnection.prototype.unhighlight = function() { - Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_); - delete Blockly.Connection.highlightedPath_; + dom.removeNode(Connection.highlightedPath_); + delete Connection.highlightedPath_; }; /** @@ -393,7 +396,7 @@ RenderedConnection.prototype.stopTrackingAll = function() { /** * Start tracking this connection, as well as all down-stream connections on * any block attached to this connection. This happens when a block is expanded. - * @return {!Array} List of blocks to render. + * @return {!Array} List of blocks to render. */ RenderedConnection.prototype.startTrackingAll = function() { this.setTracking(true); @@ -402,8 +405,8 @@ RenderedConnection.prototype.startTrackingAll = function() { // of lower blocks. Also, since rendering a block renders all its parents, // we only need to render the leaf nodes. const renderList = []; - if (this.type != Blockly.connectionTypes.INPUT_VALUE && - this.type != Blockly.connectionTypes.NEXT_STATEMENT) { + if (this.type != connectionTypes.INPUT_VALUE && + this.type != connectionTypes.NEXT_STATEMENT) { // Only spider down. return renderList; } @@ -433,7 +436,7 @@ RenderedConnection.prototype.startTrackingAll = function() { /** * 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. * @param {number=} maxRadius The maximum radius allowed for connections, in * workspace units. * @return {boolean} True if the connection is allowed, false otherwise. @@ -441,7 +444,7 @@ RenderedConnection.prototype.startTrackingAll = function() { */ RenderedConnection.prototype.isConnectionAllowed = function(candidate, maxRadius) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'RenderedConnection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', @@ -458,30 +461,30 @@ RenderedConnection.prototype.isConnectionAllowed = function(candidate, * Behavior after a connection attempt fails. * Bumps this connection away from the other connection. Called when an * attempted connection fails. - * @param {!Blockly.Connection} otherConnection Connection that this connection + * @param {!Connection} otherConnection Connection that this connection * failed to connect to. * @package */ RenderedConnection.prototype.onFailedConnect = function(otherConnection) { const block = this.getSourceBlock(); - if (Blockly.Events.recordUndo) { - const group = Blockly.Events.getGroup(); + if (Events.recordUndo) { + const group = Events.getGroup(); setTimeout(function() { if (!block.isDisposed() && !block.getParent()) { - Blockly.Events.setGroup(group); + Events.setGroup(group); this.bumpAwayFrom(otherConnection); - Blockly.Events.setGroup(false); + Events.setGroup(false); } - }.bind(this), Blockly.internalConstants.BUMP_DELAY); + }.bind(this), internalConstants.BUMP_DELAY); } }; /** * 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 * @override */ @@ -528,7 +531,7 @@ RenderedConnection.prototype.respawnShadow_ = function() { * Type checking does not apply, since this function is used for bumping. * @param {number} maxLimit The maximum radius to another connection, in * workspace units. - * @return {!Array} List of connections. + * @return {!Array} List of connections. * @package */ RenderedConnection.prototype.neighbours = function(maxLimit) { @@ -538,7 +541,7 @@ RenderedConnection.prototype.neighbours = function(maxLimit) { /** * Connect two connections together. This is the connection on the superior * block. Rerender blocks as needed. - * @param {!Blockly.Connection} childConnection Connection on inferior block. + * @param {!Connection} childConnection Connection on inferior block. * @protected */ RenderedConnection.prototype.connect_ = function(childConnection) { @@ -557,8 +560,8 @@ RenderedConnection.prototype.connect_ = function(childConnection) { childBlock.updateDisabled(); } if (parentRendered && childRendered) { - if (parentConnection.type == Blockly.connectionTypes.NEXT_STATEMENT || - parentConnection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { + if (parentConnection.type == connectionTypes.NEXT_STATEMENT || + parentConnection.type == connectionTypes.PREVIOUS_STATEMENT) { // Child block may need to square off its corners if it is in a stack. // Rendering a child will render its parent. childBlock.render(); diff --git a/tests/deps.js b/tests/deps.js index 367e41229..1b419caf7 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,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.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'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.Events', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); 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/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'}); From 372f5c0834f23d8e08cfc6fee4278f2c7bc74668 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 10:39:45 -0700 Subject: [PATCH 021/291] clang-format core/rendered_connection.js --- core/rendered_connection.js | 99 +++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 54 deletions(-) diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 953062f20..0abc123e5 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -55,8 +55,7 @@ const RenderedConnection = function(source, type) { * @private */ this.dbOpposite_ = - source.workspace - .connectionDBList[internalConstants.OPPOSITE_TYPE[type]]; + source.workspace.connectionDBList[internalConstants.OPPOSITE_TYPE[type]]; /** * Workspace units, (0, 0) is top left of block. @@ -118,7 +117,7 @@ RenderedConnection.prototype.dispose = function() { */ RenderedConnection.prototype.getSourceBlock = function() { return /** @type {!BlockSvg} */ ( - RenderedConnection.superClass_.getSourceBlock.call(this)); + RenderedConnection.superClass_.getSourceBlock.call(this)); }; /** @@ -128,7 +127,7 @@ RenderedConnection.prototype.getSourceBlock = function() { */ RenderedConnection.prototype.targetBlock = function() { return /** @type {BlockSvg} */ ( - RenderedConnection.superClass_.targetBlock.call(this)); + RenderedConnection.superClass_.targetBlock.call(this)); }; /** @@ -177,13 +176,11 @@ RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { // Raise it to the top for extra visibility. const selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); - let dx = - (staticConnection.x + internalConstants.SNAP_RADIUS + - Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - + let dx = (staticConnection.x + internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.x; - let dy = - (staticConnection.y + internalConstants.SNAP_RADIUS + - Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - + let dy = (staticConnection.y + internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.y; if (reverse) { // When reversing a bump due to an uneditable block, bump up. @@ -191,8 +188,7 @@ RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { } if (rootBlock.RTL) { dx = (staticConnection.x - internalConstants.SNAP_RADIUS - - Math.floor( - Math.random() * internalConstants.BUMP_RANDOMNESS)) - + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.x; } rootBlock.moveBy(dx, dy); @@ -208,8 +204,7 @@ RenderedConnection.prototype.moveTo = function(x, y) { if (this.trackedState_ == RenderedConnection.TrackedState.WILL_TRACK) { this.db_.addConnection(this, y); this.trackedState_ = RenderedConnection.TrackedState.TRACKED; - } else if (this.trackedState_ == RenderedConnection - .TrackedState.TRACKED) { + } else if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) { this.db_.removeConnection(this, this.y); this.db_.addConnection(this, y); } @@ -233,8 +228,8 @@ RenderedConnection.prototype.moveBy = function(dx, dy) { * corner of the block, in workspace coordinates. */ RenderedConnection.prototype.moveToOffset = function(blockTL) { - this.moveTo(blockTL.x + this.offsetInBlock_.x, - blockTL.y + this.offsetInBlock_.y); + this.moveTo( + blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y); }; /** @@ -271,8 +266,8 @@ RenderedConnection.prototype.tighten = function() { } // Workspace coordinates. const xy = utils.getRelativeXY(svgRoot); - block.getSvgRoot().setAttribute('transform', - 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); + block.getSvgRoot().setAttribute( + 'transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); block.moveConnections(-dx, -dy); } }; @@ -304,24 +299,21 @@ RenderedConnection.prototype.highlight = function() { // Vertical line, puzzle tab, vertical line. const yLen = renderConstants.TAB_OFFSET_FROM_TOP; steps = utils.svgPaths.moveBy(0, -yLen) + - utils.svgPaths.lineOnAxis('v', yLen) + - shape.pathDown + + utils.svgPaths.lineOnAxis('v', yLen) + shape.pathDown + utils.svgPaths.lineOnAxis('v', yLen); } else { const xLen = renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; // Horizontal line, notch, horizontal line. steps = utils.svgPaths.moveBy(-xLen, 0) + - utils.svgPaths.lineOnAxis('h', xLen) + - shape.pathLeft + + utils.svgPaths.lineOnAxis('h', xLen) + shape.pathLeft + utils.svgPaths.lineOnAxis('h', xLen); } const xy = this.sourceBlock_.getRelativeToSurfaceXY(); const x = this.x - xy.x; const y = this.y - xy.y; Connection.highlightedPath_ = dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyHighlightedConnectionPath', 'd': steps, transform: 'translate(' + x + ',' + y + ')' + @@ -344,10 +336,10 @@ RenderedConnection.prototype.unhighlight = function() { * @package */ RenderedConnection.prototype.setTracking = function(doTracking) { - if ((doTracking && this.trackedState_ == - RenderedConnection.TrackedState.TRACKED) || - (!doTracking && this.trackedState_ == - RenderedConnection.TrackedState.UNTRACKED)) { + if ((doTracking && + this.trackedState_ == RenderedConnection.TrackedState.TRACKED) || + (!doTracking && + this.trackedState_ == RenderedConnection.TrackedState.UNTRACKED)) { return; } if (this.sourceBlock_.isInFlyout) { @@ -442,19 +434,18 @@ RenderedConnection.prototype.startTrackingAll = function() { * @return {boolean} True if the connection is allowed, false otherwise. * @deprecated July 2020 */ -RenderedConnection.prototype.isConnectionAllowed = function(candidate, - maxRadius) { +RenderedConnection.prototype.isConnectionAllowed = function( + candidate, maxRadius) { deprecation.warn( - 'RenderedConnection.prototype.isConnectionAllowed', - 'July 2020', + 'RenderedConnection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', 'Blockly.Workspace.prototype.getConnectionChecker().canConnect'); if (this.distanceFrom(candidate) > maxRadius) { return false; } - return RenderedConnection.superClass_.isConnectionAllowed.call(this, - candidate); + return RenderedConnection.superClass_.isConnectionAllowed.call( + this, candidate); }; /** @@ -465,20 +456,19 @@ RenderedConnection.prototype.isConnectionAllowed = function(candidate, * failed to connect to. * @package */ -RenderedConnection.prototype.onFailedConnect = - function(otherConnection) { - const block = this.getSourceBlock(); - if (Events.recordUndo) { - const group = Events.getGroup(); - setTimeout(function() { - if (!block.isDisposed() && !block.getParent()) { - Events.setGroup(group); - this.bumpAwayFrom(otherConnection); - Events.setGroup(false); - } - }.bind(this), internalConstants.BUMP_DELAY); +RenderedConnection.prototype.onFailedConnect = function(otherConnection) { + const block = this.getSourceBlock(); + if (Events.recordUndo) { + const group = Events.getGroup(); + setTimeout(function() { + if (!block.isDisposed() && !block.getParent()) { + Events.setGroup(group); + this.bumpAwayFrom(otherConnection); + Events.setGroup(false); } - }; + }.bind(this), internalConstants.BUMP_DELAY); + } +}; /** @@ -488,10 +478,10 @@ RenderedConnection.prototype.onFailedConnect = * @protected * @override */ -RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, - childBlock) { - RenderedConnection.superClass_.disconnectInternal_.call(this, - parentBlock, childBlock); +RenderedConnection.prototype.disconnectInternal_ = function( + parentBlock, childBlock) { + RenderedConnection.superClass_.disconnectInternal_.call( + this, parentBlock, childBlock); // Rerender the parent so that it may reflow. if (parentBlock.rendered) { parentBlock.render(); @@ -586,9 +576,10 @@ RenderedConnection.prototype.connect_ = function(childConnection) { */ RenderedConnection.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(); // Bump away. From a106f37cbb3f9a1dd62062c3ed5eedb7b472c0c4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:33:46 -0700 Subject: [PATCH 022/291] Migrate core/theme.js to ES6 const/let --- core/theme.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/theme.js b/core/theme.js index 182710f16..75bfb3779 100644 --- a/core/theme.js +++ b/core/theme.js @@ -165,7 +165,7 @@ Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName, * @return {?string} The style value. */ Blockly.Theme.prototype.getComponentStyle = function(componentName) { - var style = this.componentStyles[componentName]; + const style = this.componentStyles[componentName]; if (style && typeof style == 'string' && this.getComponentStyle(/** @type {string} */ (style))) { return this.getComponentStyle(/** @type {string} */ (style)); @@ -207,8 +207,8 @@ Blockly.Theme.prototype.setStartHats = function(startHats) { * @return {!Blockly.Theme} A new Blockly theme. */ Blockly.Theme.defineTheme = function(name, themeObj) { - var theme = new Blockly.Theme(name); - var base = themeObj['base']; + const theme = new Blockly.Theme(name); + let base = themeObj['base']; if (base) { if (typeof base == "string") { base = Blockly.registry.getObject(Blockly.registry.Type.THEME, base); From 367b94dfdd8c2856efea4f9b66e6237a73200787 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:36:48 -0700 Subject: [PATCH 023/291] Migrate core/theme.js to goog.module --- core/theme.js | 61 +++++++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/core/theme.js b/core/theme.js index 75bfb3779..16289a3ad 100644 --- a/core/theme.js +++ b/core/theme.js @@ -9,7 +9,8 @@ */ 'use strict'; -goog.provide('Blockly.Theme'); +goog.module('Blockly.Theme'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.registry'); goog.require('Blockly.utils'); @@ -19,16 +20,16 @@ goog.require('Blockly.utils.object'); /** * Class for a theme. * @param {string} name Theme name. - * @param {!Object=} opt_blockStyles A map + * @param {!Object=} opt_blockStyles A map * from style names (strings) to objects with style attributes for blocks. - * @param {!Object=} opt_categoryStyles A + * @param {!Object=} opt_categoryStyles A * map from style names (strings) to objects with style attributes for * categories. - * @param {!Blockly.Theme.ComponentStyle=} opt_componentStyles A map of Blockly + * @param {!Theme.ComponentStyle=} opt_componentStyles A map of Blockly * component names to style value. * @constructor */ -Blockly.Theme = function(name, opt_blockStyles, opt_categoryStyles, +const Theme = function(name, opt_blockStyles, opt_categoryStyles, opt_componentStyles) { /** @@ -39,32 +40,32 @@ Blockly.Theme = function(name, opt_blockStyles, opt_categoryStyles, /** * The block styles map. - * @type {!Object} + * @type {!Object} * @package */ this.blockStyles = opt_blockStyles || Object.create(null); /** * The category styles map. - * @type {!Object} + * @type {!Object} * @package */ this.categoryStyles = opt_categoryStyles || Object.create(null); /** * The UI components styles map. - * @type {!Blockly.Theme.ComponentStyle} + * @type {!Theme.ComponentStyle} * @package */ this.componentStyles = opt_componentStyles || - (/** @type {Blockly.Theme.ComponentStyle} */ (Object.create(null))); + (/** @type {Theme.ComponentStyle} */ (Object.create(null))); /** * The font style. - * @type {!Blockly.Theme.FontStyle} + * @type {!Theme.FontStyle} * @package */ - this.fontStyle = /** @type {Blockly.Theme.FontStyle} */ (Object.create(null)); + this.fontStyle = /** @type {Theme.FontStyle} */ (Object.create(null)); /** * Whether or not to add a 'hat' on top of all blocks with no previous or @@ -87,7 +88,7 @@ Blockly.Theme = function(name, opt_blockStyles, opt_categoryStyles, * hat:string * }} */ -Blockly.Theme.BlockStyle; +Theme.BlockStyle; /** * A category style. @@ -95,7 +96,7 @@ Blockly.Theme.BlockStyle; * colour:string * }} */ -Blockly.Theme.CategoryStyle; +Theme.CategoryStyle; /** * A component style. @@ -118,7 +119,7 @@ Blockly.Theme.CategoryStyle; * replacementGlowOpacity:?number * }} */ -Blockly.Theme.ComponentStyle; +Theme.ComponentStyle; /** * A font style. @@ -128,32 +129,32 @@ Blockly.Theme.ComponentStyle; * size:?number * }} */ -Blockly.Theme.FontStyle; +Theme.FontStyle; /** * Gets the class name that identifies this theme. * @return {string} The CSS class name. * @package */ -Blockly.Theme.prototype.getClassName = function() { +Theme.prototype.getClassName = function() { return this.name + '-theme'; }; /** * Overrides or adds a style to the blockStyles map. * @param {string} blockStyleName The name of the block style. - * @param {Blockly.Theme.BlockStyle} blockStyle The block style. + * @param {Theme.BlockStyle} blockStyle The block style. */ -Blockly.Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) { +Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) { this.blockStyles[blockStyleName] = blockStyle; }; /** * Overrides or adds a style to the categoryStyles map. * @param {string} categoryStyleName The name of the category style. - * @param {Blockly.Theme.CategoryStyle} categoryStyle The category style. + * @param {Theme.CategoryStyle} categoryStyle The category style. */ -Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName, +Theme.prototype.setCategoryStyle = function(categoryStyleName, categoryStyle) { this.categoryStyles[categoryStyleName] = categoryStyle; }; @@ -164,7 +165,7 @@ Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName, * @param {string} componentName The name of the component. * @return {?string} The style value. */ -Blockly.Theme.prototype.getComponentStyle = function(componentName) { +Theme.prototype.getComponentStyle = function(componentName) { const style = this.componentStyles[componentName]; if (style && typeof style == 'string' && this.getComponentStyle(/** @type {string} */ (style))) { @@ -178,16 +179,16 @@ Blockly.Theme.prototype.getComponentStyle = function(componentName) { * @param {string} componentName The name of the component. * @param {*} styleValue The style value. */ -Blockly.Theme.prototype.setComponentStyle = function(componentName, +Theme.prototype.setComponentStyle = function(componentName, styleValue) { this.componentStyles[componentName] = styleValue; }; /** * Configure a theme's font style. - * @param {Blockly.Theme.FontStyle} fontStyle The font style. + * @param {Theme.FontStyle} fontStyle The font style. */ -Blockly.Theme.prototype.setFontStyle = function(fontStyle) { +Theme.prototype.setFontStyle = function(fontStyle) { this.fontStyle = fontStyle; }; @@ -196,7 +197,7 @@ Blockly.Theme.prototype.setFontStyle = function(fontStyle) { * @param {boolean} startHats True if the theme enables start hats, false * otherwise. */ -Blockly.Theme.prototype.setStartHats = function(startHats) { +Theme.prototype.setStartHats = function(startHats) { this.startHats = startHats; }; @@ -204,16 +205,16 @@ Blockly.Theme.prototype.setStartHats = function(startHats) { * Define a new Blockly theme. * @param {string} name The name of the theme. * @param {!Object} themeObj An object containing theme properties. - * @return {!Blockly.Theme} A new Blockly theme. + * @return {!Theme} A new Blockly theme. */ -Blockly.Theme.defineTheme = function(name, themeObj) { - const theme = new Blockly.Theme(name); +Theme.defineTheme = function(name, themeObj) { + const theme = new Theme(name); let base = themeObj['base']; if (base) { if (typeof base == "string") { base = Blockly.registry.getObject(Blockly.registry.Type.THEME, base); } - if (base instanceof Blockly.Theme) { + if (base instanceof Theme) { Blockly.utils.object.deepMerge(theme, base); theme.name = name; } @@ -233,3 +234,5 @@ Blockly.Theme.defineTheme = function(name, themeObj) { return theme; }; + +exports = Theme; diff --git a/tests/deps.js b/tests/deps.js index de575339f..42d14c6a8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -161,7 +161,7 @@ goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', ' 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/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); 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']); From 9cf50a61c189e9e3c076f81bd86d1b436a1878dc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:39:57 -0700 Subject: [PATCH 024/291] Migrate core/theme.js to named requires --- core/theme.js | 19 +++++++++---------- tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/theme.js b/core/theme.js index 16289a3ad..c9cd46968 100644 --- a/core/theme.js +++ b/core/theme.js @@ -12,9 +12,8 @@ goog.module('Blockly.Theme'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.registry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); +const object = goog.require('Blockly.utils.object'); +const registry = goog.require('Blockly.registry'); /** @@ -76,7 +75,7 @@ const Theme = function(name, opt_blockStyles, opt_categoryStyles, this.startHats = null; // Register the theme by name. - Blockly.registry.register(Blockly.registry.Type.THEME, name, this); + registry.register(registry.Type.THEME, name, this); }; /** @@ -212,21 +211,21 @@ Theme.defineTheme = function(name, themeObj) { let base = themeObj['base']; if (base) { if (typeof base == "string") { - base = Blockly.registry.getObject(Blockly.registry.Type.THEME, base); + base = registry.getObject(registry.Type.THEME, base); } if (base instanceof Theme) { - Blockly.utils.object.deepMerge(theme, base); + object.deepMerge(theme, base); theme.name = name; } } - Blockly.utils.object.deepMerge(theme.blockStyles, + object.deepMerge(theme.blockStyles, themeObj['blockStyles']); - Blockly.utils.object.deepMerge(theme.categoryStyles, + object.deepMerge(theme.categoryStyles, themeObj['categoryStyles']); - Blockly.utils.object.deepMerge(theme.componentStyles, + object.deepMerge(theme.componentStyles, themeObj['componentStyles']); - Blockly.utils.object.deepMerge(theme.fontStyle, + object.deepMerge(theme.fontStyle, themeObj['fontStyle']); if (themeObj['startHats'] != null) { theme.startHats = themeObj['startHats']; diff --git a/tests/deps.js b/tests/deps.js index 42d14c6a8..d27093d4d 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -161,7 +161,7 @@ goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', ' 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/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); 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']); From 4e3bfee2aacb5391a8ee0ede11b4d3b8989ceaf2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:42:17 -0700 Subject: [PATCH 025/291] clang-format core/theme.js --- core/theme.js | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/core/theme.js b/core/theme.js index c9cd46968..11c72e491 100644 --- a/core/theme.js +++ b/core/theme.js @@ -28,9 +28,8 @@ const registry = goog.require('Blockly.registry'); * component names to style value. * @constructor */ -const Theme = function(name, opt_blockStyles, opt_categoryStyles, - opt_componentStyles) { - +const Theme = function( + name, opt_blockStyles, opt_categoryStyles, opt_componentStyles) { /** * The theme name. This can be used to reference a specific theme in CSS. * @type {string} @@ -57,7 +56,7 @@ const Theme = function(name, opt_blockStyles, opt_categoryStyles, * @package */ this.componentStyles = opt_componentStyles || - (/** @type {Theme.ComponentStyle} */ (Object.create(null))); + (/** @type {Theme.ComponentStyle} */ (Object.create(null))); /** * The font style. @@ -143,7 +142,7 @@ Theme.prototype.getClassName = function() { * Overrides or adds a style to the blockStyles map. * @param {string} blockStyleName The name of the block style. * @param {Theme.BlockStyle} blockStyle The block style. -*/ + */ Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) { this.blockStyles[blockStyleName] = blockStyle; }; @@ -152,9 +151,8 @@ Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) { * Overrides or adds a style to the categoryStyles map. * @param {string} categoryStyleName The name of the category style. * @param {Theme.CategoryStyle} categoryStyle The category style. -*/ -Theme.prototype.setCategoryStyle = function(categoryStyleName, - categoryStyle) { + */ +Theme.prototype.setCategoryStyle = function(categoryStyleName, categoryStyle) { this.categoryStyles[categoryStyleName] = categoryStyle; }; @@ -177,16 +175,15 @@ Theme.prototype.getComponentStyle = function(componentName) { * Configure a specific Blockly UI component with a style value. * @param {string} componentName The name of the component. * @param {*} styleValue The style value. -*/ -Theme.prototype.setComponentStyle = function(componentName, - styleValue) { + */ +Theme.prototype.setComponentStyle = function(componentName, styleValue) { this.componentStyles[componentName] = styleValue; }; /** * Configure a theme's font style. * @param {Theme.FontStyle} fontStyle The font style. -*/ + */ Theme.prototype.setFontStyle = function(fontStyle) { this.fontStyle = fontStyle; }; @@ -195,7 +192,7 @@ Theme.prototype.setFontStyle = function(fontStyle) { * Configure a theme's start hats. * @param {boolean} startHats True if the theme enables start hats, false * otherwise. -*/ + */ Theme.prototype.setStartHats = function(startHats) { this.startHats = startHats; }; @@ -205,12 +202,12 @@ Theme.prototype.setStartHats = function(startHats) { * @param {string} name The name of the theme. * @param {!Object} themeObj An object containing theme properties. * @return {!Theme} A new Blockly theme. -*/ + */ Theme.defineTheme = function(name, themeObj) { const theme = new Theme(name); let base = themeObj['base']; if (base) { - if (typeof base == "string") { + if (typeof base == 'string') { base = registry.getObject(registry.Type.THEME, base); } if (base instanceof Theme) { @@ -219,14 +216,10 @@ Theme.defineTheme = function(name, themeObj) { } } - object.deepMerge(theme.blockStyles, - themeObj['blockStyles']); - object.deepMerge(theme.categoryStyles, - themeObj['categoryStyles']); - object.deepMerge(theme.componentStyles, - themeObj['componentStyles']); - object.deepMerge(theme.fontStyle, - themeObj['fontStyle']); + object.deepMerge(theme.blockStyles, themeObj['blockStyles']); + object.deepMerge(theme.categoryStyles, themeObj['categoryStyles']); + object.deepMerge(theme.componentStyles, themeObj['componentStyles']); + object.deepMerge(theme.fontStyle, themeObj['fontStyle']); if (themeObj['startHats'] != null) { theme.startHats = themeObj['startHats']; } From c068a3b6f9dcd304278bd5aa87a0d66460d698df Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:26:04 -0700 Subject: [PATCH 026/291] Migrate core/renderers/common/path_object.js to goog.module --- core/renderers/common/path_object.js | 39 +++++++++++++++------------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index e81b8e0e2..c6de3c492 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.blockRendering.PathObject'); +goog.module('Blockly.blockRendering.PathObject'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.blockRendering.IPathObject'); @@ -35,7 +36,7 @@ goog.requireType('Blockly.Connection'); * @implements {Blockly.blockRendering.IPathObject} * @package */ -Blockly.blockRendering.PathObject = function(root, style, constants) { +const PathObject = function(root, style, constants) { /** * The renderer's constant provider. * @type {!Blockly.blockRendering.ConstantProvider} @@ -83,7 +84,7 @@ Blockly.blockRendering.PathObject = function(root, style, constants) { * @param {string} pathString The path. * @package */ -Blockly.blockRendering.PathObject.prototype.setPath = function(pathString) { +PathObject.prototype.setPath = function(pathString) { this.svgPath.setAttribute('d', pathString); }; @@ -91,7 +92,7 @@ Blockly.blockRendering.PathObject.prototype.setPath = function(pathString) { * Flip the SVG paths in RTL. * @package */ -Blockly.blockRendering.PathObject.prototype.flipRTL = function() { +PathObject.prototype.flipRTL = function() { // Mirror the block's path. this.svgPath.setAttribute('transform', 'scale(-1 1)'); }; @@ -102,7 +103,7 @@ Blockly.blockRendering.PathObject.prototype.flipRTL = function() { * block SVG group. * @package */ -Blockly.blockRendering.PathObject.prototype.setCursorSvg = function(cursorSvg) { +PathObject.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg = null; return; @@ -118,7 +119,7 @@ Blockly.blockRendering.PathObject.prototype.setCursorSvg = function(cursorSvg) { * block SVG group. * @package */ -Blockly.blockRendering.PathObject.prototype.setMarkerSvg = function(markerSvg) { +PathObject.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg = null; return; @@ -138,7 +139,7 @@ Blockly.blockRendering.PathObject.prototype.setMarkerSvg = function(markerSvg) { * @param {!Blockly.Block} block The source block. * @package */ -Blockly.blockRendering.PathObject.prototype.applyColour = function(block) { +PathObject.prototype.applyColour = function(block) { this.svgPath.setAttribute('stroke', this.style.colourTertiary); this.svgPath.setAttribute('fill', this.style.colourPrimary); @@ -151,7 +152,7 @@ Blockly.blockRendering.PathObject.prototype.applyColour = function(block) { * @param {!Blockly.Theme.BlockStyle} blockStyle The block style to use. * @package */ -Blockly.blockRendering.PathObject.prototype.setStyle = function(blockStyle) { +PathObject.prototype.setStyle = function(blockStyle) { this.style = blockStyle; }; @@ -162,7 +163,7 @@ Blockly.blockRendering.PathObject.prototype.setStyle = function(blockStyle) { * be removed. * @protected */ -Blockly.blockRendering.PathObject.prototype.setClass_ = function( +PathObject.prototype.setClass_ = function( className, add) { if (add) { Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgRoot), @@ -179,7 +180,7 @@ Blockly.blockRendering.PathObject.prototype.setClass_ = function( * @param {boolean} enable True if highlighted. * @package */ -Blockly.blockRendering.PathObject.prototype.updateHighlighted = function( +PathObject.prototype.updateHighlighted = function( enable) { if (enable) { this.svgPath.setAttribute('filter', @@ -194,7 +195,7 @@ Blockly.blockRendering.PathObject.prototype.updateHighlighted = function( * @param {boolean} shadow True if the block is a shadow block. * @protected */ -Blockly.blockRendering.PathObject.prototype.updateShadow_ = function(shadow) { +PathObject.prototype.updateShadow_ = function(shadow) { if (shadow) { this.svgPath.setAttribute('stroke', 'none'); this.svgPath.setAttribute('fill', this.style.colourSecondary); @@ -206,7 +207,7 @@ Blockly.blockRendering.PathObject.prototype.updateShadow_ = function(shadow) { * @param {boolean} disabled True if disabled. * @protected */ -Blockly.blockRendering.PathObject.prototype.updateDisabled_ = function( +PathObject.prototype.updateDisabled_ = function( disabled) { this.setClass_('blocklyDisabled', disabled); if (disabled) { @@ -220,7 +221,7 @@ Blockly.blockRendering.PathObject.prototype.updateDisabled_ = function( * @param {boolean} enable True if selection is enabled, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateSelected = function(enable) { +PathObject.prototype.updateSelected = function(enable) { this.setClass_('blocklySelected', enable); }; @@ -230,7 +231,7 @@ Blockly.blockRendering.PathObject.prototype.updateSelected = function(enable) { * area, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateDraggingDelete = function( +PathObject.prototype.updateDraggingDelete = function( enable) { this.setClass_('blocklyDraggingDelete', enable); }; @@ -241,7 +242,7 @@ Blockly.blockRendering.PathObject.prototype.updateDraggingDelete = function( * otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateInsertionMarker = function( +PathObject.prototype.updateInsertionMarker = function( enable) { this.setClass_('blocklyInsertionMarker', enable); }; @@ -251,7 +252,7 @@ Blockly.blockRendering.PathObject.prototype.updateInsertionMarker = function( * @param {boolean} enable True if the block is movable, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateMovable = function(enable) { +PathObject.prototype.updateMovable = function(enable) { this.setClass_('blocklyDraggable', enable); }; @@ -262,7 +263,7 @@ Blockly.blockRendering.PathObject.prototype.updateMovable = function(enable) { * @param {boolean} enable True if styling should be added. * @package */ -Blockly.blockRendering.PathObject.prototype.updateReplacementFade = +PathObject.prototype.updateReplacementFade = function(enable) { /* eslint-disable indent */ this.setClass_('blocklyReplaceable', enable); @@ -275,8 +276,10 @@ Blockly.blockRendering.PathObject.prototype.updateReplacementFade = * @param {boolean} _enable True if styling should be added. * @package */ -Blockly.blockRendering.PathObject.prototype.updateShapeForInputHighlight = +PathObject.prototype.updateShapeForInputHighlight = function(_conn, _enable) { /* eslint-disable indent */ // NOP }; /* eslint-enable indent */ + +exports = PathObject; diff --git a/tests/deps.js b/tests/deps.js index 805416071..aa69691cb 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -126,7 +126,7 @@ goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRende goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); From cf3d22c4901b65894ce6a63151140139079173f2 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:39:02 -0700 Subject: [PATCH 027/291] Migrate core/renderers/common/path_object.js named requires --- core/renderers/common/path_object.js | 44 +++++++++++++++------------- tests/deps.js | 2 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index c6de3c492..bb3cca63a 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -14,32 +14,36 @@ goog.module('Blockly.blockRendering.PathObject'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockRendering.ConstantProvider'); -goog.require('Blockly.blockRendering.IPathObject'); -goog.require('Blockly.Theme'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ +const IPathObject = goog.require('Blockly.blockRendering.IPathObject'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +const dom = goog.require('Blockly.utils.dom'); /** * An object that handles creating and setting each of the SVG elements * used by the renderer. * @param {!SVGElement} root The root SVG element. - * @param {!Blockly.Theme.BlockStyle} style The style object to use for + * @param {!Theme.BlockStyle} style The style object to use for * colouring. - * @param {!Blockly.blockRendering.ConstantProvider} constants The renderer's + * @param {!ConstantProvider} constants The renderer's * constants. * @constructor - * @implements {Blockly.blockRendering.IPathObject} + * @implements {IPathObject} * @package */ const PathObject = function(root, style, constants) { /** * The renderer's constant provider. - * @type {!Blockly.blockRendering.ConstantProvider} + * @type {!ConstantProvider} * @package */ this.constants = constants; @@ -51,13 +55,13 @@ const PathObject = function(root, style, constants) { * @type {!SVGElement} * @package */ - this.svgPath = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + this.svgPath = dom.createSvgElement( + Svg.PATH, {'class': 'blocklyPath'}, this.svgRoot); /** * The style object to use when colouring block paths. - * @type {!Blockly.Theme.BlockStyle} + * @type {!Theme.BlockStyle} * @package */ this.style = style; @@ -136,7 +140,7 @@ PathObject.prototype.setMarkerSvg = function(markerSvg) { /** * Apply the stored colours to the block's path, taking into account whether * the paths belong to a shadow block. - * @param {!Blockly.Block} block The source block. + * @param {!Block} block The source block. * @package */ PathObject.prototype.applyColour = function(block) { @@ -149,7 +153,7 @@ PathObject.prototype.applyColour = function(block) { /** * Set the style. - * @param {!Blockly.Theme.BlockStyle} blockStyle The block style to use. + * @param {!Theme.BlockStyle} blockStyle The block style to use. * @package */ PathObject.prototype.setStyle = function(blockStyle) { @@ -166,10 +170,10 @@ PathObject.prototype.setStyle = function(blockStyle) { PathObject.prototype.setClass_ = function( className, add) { if (add) { - Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgRoot), + dom.addClass(/** @type {!Element} */ (this.svgRoot), className); } else { - Blockly.utils.dom.removeClass(/** @type {!Element} */ (this.svgRoot), + dom.removeClass(/** @type {!Element} */ (this.svgRoot), className); } }; @@ -272,7 +276,7 @@ PathObject.prototype.updateReplacementFade = /** * Add or remove styling that shows that if the dragging block is dropped, this * block will be connected to the input. - * @param {Blockly.Connection} _conn The connection on the input to highlight. + * @param {Connection} _conn The connection on the input to highlight. * @param {boolean} _enable True if styling should be added. * @package */ diff --git a/tests/deps.js b/tests/deps.js index aa69691cb..8d394ea2f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -126,7 +126,7 @@ goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRende goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); From 55207a2e7fd152412d0a41740e5dfdc17201a705 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:41:29 -0700 Subject: [PATCH 028/291] clang-format core/renderers/common/path_object.js --- core/renderers/common/path_object.js | 46 ++++++++++------------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index bb3cca63a..7b1f6af9d 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -55,9 +55,8 @@ const PathObject = function(root, style, constants) { * @type {!SVGElement} * @package */ - this.svgPath = dom.createSvgElement( - Svg.PATH, - {'class': 'blocklyPath'}, this.svgRoot); + this.svgPath = + dom.createSvgElement(Svg.PATH, {'class': 'blocklyPath'}, this.svgRoot); /** * The style object to use when colouring block paths. @@ -167,14 +166,11 @@ PathObject.prototype.setStyle = function(blockStyle) { * be removed. * @protected */ -PathObject.prototype.setClass_ = function( - className, add) { +PathObject.prototype.setClass_ = function(className, add) { if (add) { - dom.addClass(/** @type {!Element} */ (this.svgRoot), - className); + dom.addClass(/** @type {!Element} */ (this.svgRoot), className); } else { - dom.removeClass(/** @type {!Element} */ (this.svgRoot), - className); + dom.removeClass(/** @type {!Element} */ (this.svgRoot), className); } }; @@ -184,11 +180,10 @@ PathObject.prototype.setClass_ = function( * @param {boolean} enable True if highlighted. * @package */ -PathObject.prototype.updateHighlighted = function( - enable) { +PathObject.prototype.updateHighlighted = function(enable) { if (enable) { - this.svgPath.setAttribute('filter', - 'url(#' + this.constants.embossFilterId + ')'); + this.svgPath.setAttribute( + 'filter', 'url(#' + this.constants.embossFilterId + ')'); } else { this.svgPath.setAttribute('filter', 'none'); } @@ -211,12 +206,11 @@ PathObject.prototype.updateShadow_ = function(shadow) { * @param {boolean} disabled True if disabled. * @protected */ -PathObject.prototype.updateDisabled_ = function( - disabled) { +PathObject.prototype.updateDisabled_ = function(disabled) { this.setClass_('blocklyDisabled', disabled); if (disabled) { - this.svgPath.setAttribute('fill', - 'url(#' + this.constants.disabledPatternId + ')'); + this.svgPath.setAttribute( + 'fill', 'url(#' + this.constants.disabledPatternId + ')'); } }; @@ -235,8 +229,7 @@ PathObject.prototype.updateSelected = function(enable) { * area, false otherwise. * @package */ -PathObject.prototype.updateDraggingDelete = function( - enable) { +PathObject.prototype.updateDraggingDelete = function(enable) { this.setClass_('blocklyDraggingDelete', enable); }; @@ -246,8 +239,7 @@ PathObject.prototype.updateDraggingDelete = function( * otherwise. * @package */ -PathObject.prototype.updateInsertionMarker = function( - enable) { +PathObject.prototype.updateInsertionMarker = function(enable) { this.setClass_('blocklyInsertionMarker', enable); }; @@ -267,11 +259,9 @@ PathObject.prototype.updateMovable = function(enable) { * @param {boolean} enable True if styling should be added. * @package */ -PathObject.prototype.updateReplacementFade = - function(enable) { - /* eslint-disable indent */ +PathObject.prototype.updateReplacementFade = function(enable) { this.setClass_('blocklyReplaceable', enable); -}; /* eslint-enable indent */ +}; /** * Add or remove styling that shows that if the dragging block is dropped, this @@ -280,10 +270,8 @@ PathObject.prototype.updateReplacementFade = * @param {boolean} _enable True if styling should be added. * @package */ -PathObject.prototype.updateShapeForInputHighlight = - function(_conn, _enable) { - /* eslint-disable indent */ +PathObject.prototype.updateShapeForInputHighlight = function(_conn, _enable) { // NOP -}; /* eslint-enable indent */ +}; exports = PathObject; From e04050cd710199763591270640fefa7b3a3d6aba Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:54:32 -0700 Subject: [PATCH 029/291] Migrate core/warning.js to ES6 const/let --- core/warning.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/warning.js b/core/warning.js index 9bbd9c91b..e596f0328 100644 --- a/core/warning.js +++ b/core/warning.js @@ -145,8 +145,8 @@ Blockly.Warning.prototype.setText = function(text, id) { * @return {string} All texts concatenated into one string. */ Blockly.Warning.prototype.getText = function() { - var allWarnings = []; - for (var id in this.text_) { + const allWarnings = []; + for (let id in this.text_) { allWarnings.push(this.text_[id]); } return allWarnings.join('\n'); From 94b9169bf56402140a0cbcb123595fd5cabb64ab Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:54:52 -0700 Subject: [PATCH 030/291] Migrate core/warning.js to goog.module --- core/warning.js | 27 +++++++++++++++------------ tests/deps.js | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/warning.js b/core/warning.js index e596f0328..c39e7cad9 100644 --- a/core/warning.js +++ b/core/warning.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Warning'); +goog.module('Blockly.Warning'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Bubble'); goog.require('Blockly.Events'); @@ -32,25 +33,25 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.Icon} * @constructor */ -Blockly.Warning = function(block) { - Blockly.Warning.superClass_.constructor.call(this, block); +const Warning = function(block) { + Warning.superClass_.constructor.call(this, block); this.createIcon(); // The text_ object can contain multiple warnings. this.text_ = Object.create(null); }; -Blockly.utils.object.inherits(Blockly.Warning, Blockly.Icon); +Blockly.utils.object.inherits(Warning, Blockly.Icon); /** * Does this icon get hidden when the block is collapsed. */ -Blockly.Warning.prototype.collapseHidden = false; +Warning.prototype.collapseHidden = false; /** * Draw the warning icon. * @param {!Element} group The icon group. * @protected */ -Blockly.Warning.prototype.drawIcon_ = function(group) { +Warning.prototype.drawIcon_ = function(group) { // Triangle with rounded corners. Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATH, @@ -83,7 +84,7 @@ Blockly.Warning.prototype.drawIcon_ = function(group) { * Show or hide the warning bubble. * @param {boolean} visible True if the bubble should be visible. */ -Blockly.Warning.prototype.setVisible = function(visible) { +Warning.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } @@ -100,7 +101,7 @@ Blockly.Warning.prototype.setVisible = function(visible) { * Show the bubble. * @private */ -Blockly.Warning.prototype.createBubble_ = function() { +Warning.prototype.createBubble_ = function() { this.paragraphElement_ = Blockly.Bubble.textToDom(this.getText()); this.bubble_ = Blockly.Bubble.createNonEditableBubble( this.paragraphElement_, /** @type {!Blockly.BlockSvg} */ (this.block_), @@ -112,7 +113,7 @@ Blockly.Warning.prototype.createBubble_ = function() { * Dispose of the bubble and references to it. * @private */ -Blockly.Warning.prototype.disposeBubble_ = function() { +Warning.prototype.disposeBubble_ = function() { this.bubble_.dispose(); this.bubble_ = null; this.paragraphElement_ = null; @@ -125,7 +126,7 @@ Blockly.Warning.prototype.disposeBubble_ = function() { * @param {string} id An ID for this text entry to be able to maintain * multiple warnings. */ -Blockly.Warning.prototype.setText = function(text, id) { +Warning.prototype.setText = function(text, id) { if (this.text_[id] == text) { return; } @@ -144,7 +145,7 @@ Blockly.Warning.prototype.setText = function(text, id) { * Get this warning's texts. * @return {string} All texts concatenated into one string. */ -Blockly.Warning.prototype.getText = function() { +Warning.prototype.getText = function() { const allWarnings = []; for (let id in this.text_) { allWarnings.push(this.text_[id]); @@ -155,7 +156,9 @@ Blockly.Warning.prototype.getText = function() { /** * Dispose of this warning. */ -Blockly.Warning.prototype.dispose = function() { +Warning.prototype.dispose = function() { this.block_.warning = null; Blockly.Icon.prototype.dispose.call(this); }; + +exports = Warning; diff --git a/tests/deps.js b/tests/deps.js index 84c1c2b48..c6ccc9bb8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -199,7 +199,7 @@ goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Bloc 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.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/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); 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.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); From 9f3139c7520906c91ba18bc2edbcbda170414893 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:58:28 -0700 Subject: [PATCH 031/291] Migrate core/warning.js named requires --- core/warning.js | 52 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/core/warning.js b/core/warning.js index c39e7cad9..90bc15b12 100644 --- a/core/warning.js +++ b/core/warning.js @@ -13,24 +13,26 @@ goog.module('Blockly.Warning'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Bubble'); -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'); +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'); +const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); +const object = goog.require('Blockly.utils.object'); /** @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.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.utils.Coordinate'); /** * Class for a warning. - * @param {!Blockly.Block} block The block associated with this warning. - * @extends {Blockly.Icon} + * @param {!Block} block The block associated with this warning. + * @extends {Icon} * @constructor */ const Warning = function(block) { @@ -39,7 +41,7 @@ const Warning = function(block) { // The text_ object can contain multiple warnings. this.text_ = Object.create(null); }; -Blockly.utils.object.inherits(Warning, Blockly.Icon); +object.inherits(Warning, Icon); /** * Does this icon get hidden when the block is collapsed. @@ -53,8 +55,8 @@ Warning.prototype.collapseHidden = false; */ Warning.prototype.drawIcon_ = function(group) { // Triangle with rounded corners. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconShape', 'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z' @@ -63,16 +65,16 @@ Warning.prototype.drawIcon_ = function(group) { // Can't use a real '!' text character since different browsers and operating // systems render it differently. // Body of exclamation point. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z' }, group); // Dot of exclamation point. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '7', 'y': '11', 'height': '2', 'width': '2' @@ -88,7 +90,7 @@ Warning.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, 'warning')); if (visible) { this.createBubble_(); @@ -102,10 +104,10 @@ Warning.prototype.setVisible = function(visible) { * @private */ Warning.prototype.createBubble_ = function() { - this.paragraphElement_ = Blockly.Bubble.textToDom(this.getText()); - this.bubble_ = Blockly.Bubble.createNonEditableBubble( - this.paragraphElement_, /** @type {!Blockly.BlockSvg} */ (this.block_), - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_)); + this.paragraphElement_ = Bubble.textToDom(this.getText()); + this.bubble_ = Bubble.createNonEditableBubble( + this.paragraphElement_, /** @type {!BlockSvg} */ (this.block_), + /** @type {!Coordinate} */ (this.iconXY_)); this.applyColour(); }; @@ -158,7 +160,7 @@ Warning.prototype.getText = function() { */ Warning.prototype.dispose = function() { this.block_.warning = null; - Blockly.Icon.prototype.dispose.call(this); + Icon.prototype.dispose.call(this); }; exports = Warning; From 8056bf04845a1c6666e6db8a3f02b4f2a762b291 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:59:56 -0700 Subject: [PATCH 032/291] clang-format core/warning.js --- core/warning.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/warning.js b/core/warning.js index 90bc15b12..e08088e94 100644 --- a/core/warning.js +++ b/core/warning.js @@ -56,8 +56,7 @@ Warning.prototype.collapseHidden = false; Warning.prototype.drawIcon_ = function(group) { // Triangle with rounded corners. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconShape', 'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z' }, @@ -66,18 +65,19 @@ Warning.prototype.drawIcon_ = function(group) { // systems render it differently. // Body of exclamation point. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z' }, group); // Dot of exclamation point. dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyIconSymbol', - 'x': '7', 'y': '11', 'height': '2', 'width': '2' + 'x': '7', + 'y': '11', + 'height': '2', + 'width': '2' }, group); }; @@ -90,8 +90,8 @@ Warning.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Events.fire(new (Events.get(Events.BUBBLE_OPEN))( - this.block_, visible, 'warning')); + Events.fire( + new (Events.get(Events.BUBBLE_OPEN))(this.block_, visible, 'warning')); if (visible) { this.createBubble_(); } else { From 284d68be805dfc891d5f12d44abf73076098e70e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 15:17:11 -0700 Subject: [PATCH 033/291] Update syntax for for..in loop --- core/warning.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/warning.js b/core/warning.js index e08088e94..6ed5d0c02 100644 --- a/core/warning.js +++ b/core/warning.js @@ -149,7 +149,7 @@ Warning.prototype.setText = function(text, id) { */ Warning.prototype.getText = function() { const allWarnings = []; - for (let id in this.text_) { + for (const id in this.text_) { allWarnings.push(this.text_[id]); } return allWarnings.join('\n'); From e6bd6cabb18a312ae9c7ba35157d28576c5bc2b3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:01:01 -0700 Subject: [PATCH 034/291] Migrate core/keyboard_nav/ast_node.js to ES6 const/let --- core/keyboard_nav/ast_node.js | 156 ++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 71 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index d86a22a4c..115ffe2a1 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -147,7 +147,7 @@ Blockly.ASTNode.createConnectionNode = function(connection) { if (!connection) { return null; } - var type = connection.type; + const type = connection.type; if (type == Blockly.connectionTypes.INPUT_VALUE) { return Blockly.ASTNode.createInputNode(connection.getParentInput()); } else if (type == Blockly.connectionTypes.NEXT_STATEMENT && @@ -215,7 +215,7 @@ Blockly.ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { if (!wsCoordinate || !workspace) { return null; } - var params = { + const params = { wsCoordinate: wsCoordinate }; return new Blockly.ASTNode( @@ -230,8 +230,8 @@ Blockly.ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { * block. */ Blockly.ASTNode.createTopNode = function(block) { - var astNode; - var topConnection = block.previousConnection || block.outputConnection; + let astNode; + const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { astNode = Blockly.ASTNode.createConnectionNode(topConnection); } else { @@ -302,13 +302,15 @@ Blockly.ASTNode.prototype.isConnection = function() { * @private */ Blockly.ASTNode.prototype.findNextForInput_ = function() { - var location = /** @type {!Blockly.Connection} */ (this.location_); - var parentInput = location.getParentInput(); - var block = parentInput.getSourceBlock(); - var curIdx = block.inputList.indexOf(parentInput); - for (var i = curIdx + 1, input; (input = block.inputList[i]); i++) { - var fieldRow = input.fieldRow; - for (var j = 0, field; (field = fieldRow[j]); j++) { + const location = /** @type {!Blockly.Connection} */ (this.location_); + const parentInput = location.getParentInput(); + const block = parentInput.getSourceBlock(); + const curIdx = block.inputList.indexOf(parentInput); + let i = curIdx + 1, input; + for (; (input = block.inputList[i]); i++) { + const fieldRow = input.fieldRow; + let j = 0, field; + for (; (field = fieldRow[j]); j++) { if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(field); } @@ -329,13 +331,14 @@ Blockly.ASTNode.prototype.findNextForInput_ = function() { * @private */ Blockly.ASTNode.prototype.findNextForField_ = function() { - var location = /** @type {!Blockly.Field} */ (this.location_); - var input = location.getParentInput(); - var block = location.getSourceBlock(); - var curIdx = block.inputList.indexOf(/** @type {!Blockly.Input} */ (input)); - var fieldIdx = input.fieldRow.indexOf(location) + 1; - for (var i = curIdx, newInput; (newInput = block.inputList[i]); i++) { - var fieldRow = newInput.fieldRow; + const location = /** @type {!Blockly.Field} */ (this.location_); + const input = location.getParentInput(); + const block = location.getSourceBlock(); + const curIdx = block.inputList.indexOf(/** @type {!Blockly.Input} */ (input)); + let fieldIdx = input.fieldRow.indexOf(location) + 1; + let i = curIdx, newInput; + for (; (newInput = block.inputList[i]); i++) { + const fieldRow = newInput.fieldRow; while (fieldIdx < fieldRow.length) { if (fieldRow[fieldIdx].isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); @@ -359,16 +362,18 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { * @private */ Blockly.ASTNode.prototype.findPrevForInput_ = function() { - var location = /** @type {!Blockly.Connection} */ (this.location_); - var parentInput = location.getParentInput(); - var block = parentInput.getSourceBlock(); - var curIdx = block.inputList.indexOf(parentInput); - for (var i = curIdx, input; (input = block.inputList[i]); i--) { + const location = /** @type {!Blockly.Connection} */ (this.location_); + const parentInput = location.getParentInput(); + const block = parentInput.getSourceBlock(); + const curIdx = block.inputList.indexOf(parentInput); + let i = curIdx, input; + for (; (input = block.inputList[i]); i--) { if (input.connection && input !== parentInput) { return Blockly.ASTNode.createInputNode(input); } - var fieldRow = input.fieldRow; - for (var j = fieldRow.length - 1, field; (field = fieldRow[j]); j--) { + const fieldRow = input.fieldRow; + let j = fieldRow.length - 1, field; + for (; (field = fieldRow[j]); j--) { if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(field); } @@ -384,17 +389,18 @@ Blockly.ASTNode.prototype.findPrevForInput_ = function() { * @private */ Blockly.ASTNode.prototype.findPrevForField_ = function() { - var location = /** @type {!Blockly.Field} */ (this.location_); - var parentInput = location.getParentInput(); - var block = location.getSourceBlock(); - var curIdx = block.inputList.indexOf( + const location = /** @type {!Blockly.Field} */ (this.location_); + const parentInput = location.getParentInput(); + const block = location.getSourceBlock(); + const curIdx = block.inputList.indexOf( /** @type {!Blockly.Input} */ (parentInput)); - var fieldIdx = parentInput.fieldRow.indexOf(location) - 1; - for (var i = curIdx, input; (input = block.inputList[i]); i--) { + let fieldIdx = parentInput.fieldRow.indexOf(location) - 1; + let i = curIdx, input; + for (; (input = block.inputList[i]); i--) { if (input.connection && input !== parentInput) { return Blockly.ASTNode.createInputNode(input); } - var fieldRow = input.fieldRow; + const fieldRow = input.fieldRow; while (fieldIdx > -1) { if (fieldRow[fieldIdx].isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); @@ -425,12 +431,13 @@ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { if (!curLocation || !curLocation.workspace) { return null; } - var curRoot = curLocation.getRootBlock(); - var topBlocks = curRoot.workspace.getTopBlocks(true); - for (var i = 0, topBlock; (topBlock = topBlocks[i]); i++) { + const curRoot = curLocation.getRootBlock(); + const topBlocks = curRoot.workspace.getTopBlocks(true); + let i = 0, topBlock; + for (; (topBlock = topBlocks[i]); i++) { if (curRoot.id == topBlock.id) { - var offset = forward ? 1 : -1; - var resultIndex = i + offset; + const offset = forward ? 1 : -1; + const resultIndex = i + offset; if (resultIndex == -1 || resultIndex == topBlocks.length) { return null; } @@ -450,7 +457,7 @@ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { * @private */ Blockly.ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { - var topConnection = block.previousConnection || block.outputConnection; + const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { return /** @type {!Blockly.ASTNode} */ (Blockly.ASTNode.createConnectionNode( topConnection)); @@ -472,11 +479,12 @@ Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { if (!block) { return null; } - var topBlock; + let topBlock; // If the block doesn't have a previous connection then it is the top of the // substack. topBlock = block.getTopStackBlock(); - var topConnection = topBlock.previousConnection || topBlock.outputConnection; + const topConnection = + topBlock.previousConnection || topBlock.outputConnection; // If the top connection has a parentInput, create an AST node pointing to // that input. if (topConnection && topConnection.targetConnection && @@ -497,10 +505,12 @@ Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { * @private */ Blockly.ASTNode.prototype.findFirstFieldOrInput_ = function(block) { - var inputs = block.inputList; - for (var i = 0, input; (input = inputs[i]); i++) { - var fieldRow = input.fieldRow; - for (var j = 0, field; (field = fieldRow[j]); j++) { + const inputs = block.inputList; + let i = 0, input; + for (; (input = inputs[i]); i++) { + const fieldRow = input.fieldRow; + let j = 0, field; + for (; (field = fieldRow[j]); j++) { if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(field); } @@ -536,12 +546,13 @@ Blockly.ASTNode.prototype.getSourceBlock = function() { * block, or workspace. Or null if there is no node to the right. */ Blockly.ASTNode.prototype.next = function() { + let connection, block, nextConnection, targetConnection; switch (this.type_) { case Blockly.ASTNode.types.STACK: return this.navigateBetweenStacks_(true); case Blockly.ASTNode.types.OUTPUT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); case Blockly.ASTNode.types.FIELD: @@ -551,17 +562,17 @@ Blockly.ASTNode.prototype.next = function() { return this.findNextForInput_(); case Blockly.ASTNode.types.BLOCK: - var block = /** @type {!Blockly.Block} */ (this.location_); - var nextConnection = block.nextConnection; + block = /** @type {!Blockly.Block} */ (this.location_); + nextConnection = block.nextConnection; return Blockly.ASTNode.createConnectionNode(nextConnection); case Blockly.ASTNode.types.PREVIOUS: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); case Blockly.ASTNode.types.NEXT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); - var targetConnection = connection.targetConnection; + connection = /** @type {!Blockly.Connection} */ (this.location_); + targetConnection = connection.targetConnection; return Blockly.ASTNode.createConnectionNode(targetConnection); } @@ -575,26 +586,27 @@ Blockly.ASTNode.prototype.next = function() { * workspace, or block. Or null if there is nothing below this node. */ Blockly.ASTNode.prototype.in = function() { + let workspace, topBlocks, block, connection, targetConnection; switch (this.type_) { case Blockly.ASTNode.types.WORKSPACE: - var workspace = /** @type {!Blockly.Workspace} */ (this.location_); - var topBlocks = workspace.getTopBlocks(true); + workspace = /** @type {!Blockly.Workspace} */ (this.location_); + topBlocks = workspace.getTopBlocks(true); if (topBlocks.length > 0) { return Blockly.ASTNode.createStackNode(topBlocks[0]); } break; case Blockly.ASTNode.types.STACK: - var block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Blockly.Block} */ (this.location_); return this.findTopASTNodeForBlock_(block); case Blockly.ASTNode.types.BLOCK: - var block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Blockly.Block} */ (this.location_); return this.findFirstFieldOrInput_(block); case Blockly.ASTNode.types.INPUT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); - var targetConnection = connection.targetConnection; + connection = /** @type {!Blockly.Connection} */ (this.location_); + targetConnection = connection.targetConnection; return Blockly.ASTNode.createConnectionNode(targetConnection); } @@ -608,6 +620,7 @@ Blockly.ASTNode.prototype.in = function() { * null. */ Blockly.ASTNode.prototype.prev = function() { + let block, topConnection, connection, targetConnection; switch (this.type_) { case Blockly.ASTNode.types.STACK: return this.navigateBetweenStacks_(false); @@ -622,20 +635,20 @@ Blockly.ASTNode.prototype.prev = function() { return this.findPrevForInput_(); case Blockly.ASTNode.types.BLOCK: - var block = /** @type {!Blockly.Block} */ (this.location_); - var topConnection = block.previousConnection || block.outputConnection; + block = /** @type {!Blockly.Block} */ (this.location_); + topConnection = block.previousConnection || block.outputConnection; return Blockly.ASTNode.createConnectionNode(topConnection); case Blockly.ASTNode.types.PREVIOUS: - var connection = /** @type {!Blockly.Connection} */ (this.location_); - var targetConnection = connection.targetConnection; + connection = /** @type {!Blockly.Connection} */ (this.location_); + targetConnection = connection.targetConnection; if (targetConnection && !targetConnection.getParentInput()) { return Blockly.ASTNode.createConnectionNode(targetConnection); } break; case Blockly.ASTNode.types.NEXT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); } @@ -649,41 +662,42 @@ Blockly.ASTNode.prototype.prev = function() { * workspace or block. Or null if we are at the workspace level. */ Blockly.ASTNode.prototype.out = function() { + let block, blockPos, wsCoordinate, connection, target, field; switch (this.type_) { case Blockly.ASTNode.types.STACK: - var block = /** @type {!Blockly.Block} */ (this.location_); - var blockPos = block.getRelativeToSurfaceXY(); + block = /** @type {!Blockly.Block} */ (this.location_); + blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. - var wsCoordinate = new Blockly.utils.Coordinate( + wsCoordinate = new Blockly.utils.Coordinate( blockPos.x, blockPos.y + Blockly.ASTNode.DEFAULT_OFFSET_Y); return Blockly.ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); case Blockly.ASTNode.types.OUTPUT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); - var target = connection.targetConnection; + connection = /** @type {!Blockly.Connection} */ (this.location_); + target = connection.targetConnection; if (target) { return Blockly.ASTNode.createConnectionNode(target); } return Blockly.ASTNode.createStackNode(connection.getSourceBlock()); case Blockly.ASTNode.types.FIELD: - var field = /** @type {!Blockly.Field} */ (this.location_); + field = /** @type {!Blockly.Field} */ (this.location_); return Blockly.ASTNode.createBlockNode(field.getSourceBlock()); case Blockly.ASTNode.types.INPUT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); case Blockly.ASTNode.types.BLOCK: - var block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Blockly.Block} */ (this.location_); return this.getOutAstNodeForBlock_(block); case Blockly.ASTNode.types.PREVIOUS: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); case Blockly.ASTNode.types.NEXT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); } From ec06ea6586f06ded38c27815bdc07722406f6819 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:13:39 -0700 Subject: [PATCH 035/291] Migrate core/keyboard_nav/ast_node.js to goog.module --- core/keyboard_nav/ast_node.js | 279 +++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 142 insertions(+), 139 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 115ffe2a1..e0a75d0c0 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.ASTNode'); +goog.module('Blockly.ASTNode'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); goog.require('Blockly.utils.Coordinate'); @@ -29,19 +30,19 @@ goog.requireType('Blockly.Workspace'); * It is recommended that you use one of the createNode methods instead of * creating a node directly. * @param {string} type The type of the location. - * Must be in Blockly.ASTNode.types. + * Must be in ASTNode.types. * @param {!Blockly.IASTNodeLocation} location The position in the AST. - * @param {!Blockly.ASTNode.Params=} opt_params Optional dictionary of options. + * @param {!ASTNode.Params=} opt_params Optional dictionary of options. * @constructor */ -Blockly.ASTNode = function(type, location, opt_params) { +const ASTNode = function(type, location, opt_params) { if (!location) { throw Error('Cannot create a node without a location.'); } /** * The type of the location. - * One of Blockly.ASTNode.types + * One of ASTNode.types * @type {string} * @private */ @@ -52,7 +53,7 @@ Blockly.ASTNode = function(type, location, opt_params) { * @type {boolean} * @private */ - this.isConnection_ = Blockly.ASTNode.isConnectionType_(type); + this.isConnection_ = ASTNode.isConnectionType_(type); /** * The location of the AST node. @@ -76,13 +77,13 @@ Blockly.ASTNode = function(type, location, opt_params) { * wsCoordinate: Blockly.utils.Coordinate * }} */ -Blockly.ASTNode.Params; +ASTNode.Params; /** * Object holding different types for an AST node. * @enum {string} */ -Blockly.ASTNode.types = { +ASTNode.types = { FIELD: 'field', BLOCK: 'block', INPUT: 'input', @@ -97,7 +98,7 @@ Blockly.ASTNode.types = { * True to navigate to all fields. False to only navigate to clickable fields. * @type {boolean} */ -Blockly.ASTNode.NAVIGATE_ALL_FIELDS = false; +ASTNode.NAVIGATE_ALL_FIELDS = false; /** * The default y offset to use when moving the cursor from a stack to the @@ -105,20 +106,20 @@ Blockly.ASTNode.NAVIGATE_ALL_FIELDS = false; * @type {number} * @private */ -Blockly.ASTNode.DEFAULT_OFFSET_Y = -20; +ASTNode.DEFAULT_OFFSET_Y = -20; /** * Whether an AST node of the given type points to a connection. - * @param {string} type The type to check. One of Blockly.ASTNode.types. + * @param {string} type The type to check. One of ASTNode.types. * @return {boolean} True if a node of the given type points to a connection. * @private */ -Blockly.ASTNode.isConnectionType_ = function(type) { +ASTNode.isConnectionType_ = function(type) { switch (type) { - case Blockly.ASTNode.types.PREVIOUS: - case Blockly.ASTNode.types.NEXT: - case Blockly.ASTNode.types.INPUT: - case Blockly.ASTNode.types.OUTPUT: + case ASTNode.types.PREVIOUS: + case ASTNode.types.NEXT: + case ASTNode.types.INPUT: + case ASTNode.types.OUTPUT: return true; } return false; @@ -127,13 +128,13 @@ Blockly.ASTNode.isConnectionType_ = function(type) { /** * Create an AST node pointing to a field. * @param {Blockly.Field} field The location of the AST node. - * @return {Blockly.ASTNode} An AST node pointing to a field. + * @return {ASTNode} An AST node pointing to a field. */ -Blockly.ASTNode.createFieldNode = function(field) { +ASTNode.createFieldNode = function(field) { if (!field) { return null; } - return new Blockly.ASTNode(Blockly.ASTNode.types.FIELD, field); + return new ASTNode(ASTNode.types.FIELD, field); }; /** @@ -141,24 +142,24 @@ Blockly.ASTNode.createFieldNode = function(field) { * input then create an AST node of type input that will hold the connection. * @param {Blockly.Connection} connection This is the connection the node will * point to. - * @return {Blockly.ASTNode} An AST node pointing to a connection. + * @return {ASTNode} An AST node pointing to a connection. */ -Blockly.ASTNode.createConnectionNode = function(connection) { +ASTNode.createConnectionNode = function(connection) { if (!connection) { return null; } const type = connection.type; if (type == Blockly.connectionTypes.INPUT_VALUE) { - return Blockly.ASTNode.createInputNode(connection.getParentInput()); + return ASTNode.createInputNode(connection.getParentInput()); } else if (type == Blockly.connectionTypes.NEXT_STATEMENT && connection.getParentInput()) { - return Blockly.ASTNode.createInputNode(connection.getParentInput()); + return ASTNode.createInputNode(connection.getParentInput()); } else if (type == Blockly.connectionTypes.NEXT_STATEMENT) { - return new Blockly.ASTNode(Blockly.ASTNode.types.NEXT, connection); + return new ASTNode(ASTNode.types.NEXT, connection); } else if (type == Blockly.connectionTypes.OUTPUT_VALUE) { - return new Blockly.ASTNode(Blockly.ASTNode.types.OUTPUT, connection); + return new ASTNode(ASTNode.types.OUTPUT, connection); } else if (type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { - return new Blockly.ASTNode(Blockly.ASTNode.types.PREVIOUS, connection); + return new ASTNode(ASTNode.types.PREVIOUS, connection); } return null; }; @@ -167,25 +168,25 @@ Blockly.ASTNode.createConnectionNode = function(connection) { * Creates an AST node pointing to an input. Stores the input connection as the * location. * @param {Blockly.Input} input The input used to create an AST node. - * @return {Blockly.ASTNode} An AST node pointing to a input. + * @return {ASTNode} An AST node pointing to a input. */ -Blockly.ASTNode.createInputNode = function(input) { +ASTNode.createInputNode = function(input) { if (!input || !input.connection) { return null; } - return new Blockly.ASTNode(Blockly.ASTNode.types.INPUT, input.connection); + return new ASTNode(ASTNode.types.INPUT, input.connection); }; /** * Creates an AST node pointing to a block. * @param {Blockly.Block} block The block used to create an AST node. - * @return {Blockly.ASTNode} An AST node pointing to a block. + * @return {ASTNode} An AST node pointing to a block. */ -Blockly.ASTNode.createBlockNode = function(block) { +ASTNode.createBlockNode = function(block) { if (!block) { return null; } - return new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, block); + return new ASTNode(ASTNode.types.BLOCK, block); }; /** @@ -193,14 +194,14 @@ Blockly.ASTNode.createBlockNode = function(block) { * the set of all blocks connected to a top block, including the top block. * @param {Blockly.Block} topBlock A top block has no parent and can be found * in the list returned by workspace.getTopBlocks(). - * @return {Blockly.ASTNode} An AST node of type stack that points to the top + * @return {ASTNode} An AST node of type stack that points to the top * block on the stack. */ -Blockly.ASTNode.createStackNode = function(topBlock) { +ASTNode.createStackNode = function(topBlock) { if (!topBlock) { return null; } - return new Blockly.ASTNode(Blockly.ASTNode.types.STACK, topBlock); + return new ASTNode(ASTNode.types.STACK, topBlock); }; /** @@ -208,44 +209,44 @@ Blockly.ASTNode.createStackNode = function(topBlock) { * @param {!Blockly.Workspace} workspace The workspace that we are on. * @param {Blockly.utils.Coordinate} wsCoordinate The position on the workspace * for this node. - * @return {Blockly.ASTNode} An AST node pointing to a workspace and a position + * @return {ASTNode} An AST node pointing to a workspace and a position * on the workspace. */ -Blockly.ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { +ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { if (!wsCoordinate || !workspace) { return null; } const params = { wsCoordinate: wsCoordinate }; - return new Blockly.ASTNode( - Blockly.ASTNode.types.WORKSPACE, workspace, params); + return new ASTNode( + ASTNode.types.WORKSPACE, workspace, params); }; /** * Creates an AST node for the top position on a block. * This is either an output connection, previous connection, or block. * @param {!Blockly.Block} block The block to find the top most AST node on. - * @return {Blockly.ASTNode} The AST node holding the top most position on the + * @return {ASTNode} The AST node holding the top most position on the * block. */ -Blockly.ASTNode.createTopNode = function(block) { +ASTNode.createTopNode = function(block) { let astNode; const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { - astNode = Blockly.ASTNode.createConnectionNode(topConnection); + astNode = ASTNode.createConnectionNode(topConnection); } else { - astNode = Blockly.ASTNode.createBlockNode(block); + astNode = ASTNode.createBlockNode(block); } return astNode; }; /** * Parse the optional parameters. - * @param {?Blockly.ASTNode.Params} params The user specified parameters. + * @param {?ASTNode.Params} params The user specified parameters. * @private */ -Blockly.ASTNode.prototype.processParams_ = function(params) { +ASTNode.prototype.processParams_ = function(params) { if (!params) { return; } @@ -261,16 +262,16 @@ Blockly.ASTNode.prototype.processParams_ = function(params) { * @return {!Blockly.IASTNodeLocation} The current field, connection, workspace, or * block the cursor is on. */ -Blockly.ASTNode.prototype.getLocation = function() { +ASTNode.prototype.getLocation = function() { return this.location_; }; /** * The type of the current location. - * One of Blockly.ASTNode.types + * One of ASTNode.types * @return {string} The type of the location. */ -Blockly.ASTNode.prototype.getType = function() { +ASTNode.prototype.getType = function() { return this.type_; }; @@ -279,7 +280,7 @@ Blockly.ASTNode.prototype.getType = function() { * @return {Blockly.utils.Coordinate} The workspace coordinate or null if the * location is not a workspace. */ -Blockly.ASTNode.prototype.getWsCoordinate = function() { +ASTNode.prototype.getWsCoordinate = function() { return this.wsCoordinate_; }; @@ -288,7 +289,7 @@ Blockly.ASTNode.prototype.getWsCoordinate = function() { * @return {boolean} [description] * @package */ -Blockly.ASTNode.prototype.isConnection = function() { +ASTNode.prototype.isConnection = function() { return this.isConnection_; }; @@ -296,12 +297,12 @@ Blockly.ASTNode.prototype.isConnection = function() { * Given an input find the next editable field or an input with a non null * connection in the same block. The current location must be an input * connection. - * @return {Blockly.ASTNode} The AST node holding the next field or connection + * @return {ASTNode} The AST node holding the next field or connection * or null if there is no editable field or input connection after the given * input. * @private */ -Blockly.ASTNode.prototype.findNextForInput_ = function() { +ASTNode.prototype.findNextForInput_ = function() { const location = /** @type {!Blockly.Connection} */ (this.location_); const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); @@ -311,12 +312,12 @@ Blockly.ASTNode.prototype.findNextForInput_ = function() { const fieldRow = input.fieldRow; let j = 0, field; for (; (field = fieldRow[j]); j++) { - if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(field); + if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(field); } } if (input.connection) { - return Blockly.ASTNode.createInputNode(input); + return ASTNode.createInputNode(input); } } return null; @@ -325,12 +326,12 @@ Blockly.ASTNode.prototype.findNextForInput_ = function() { /** * Given a field find the next editable field or an input with a non null * connection in the same block. The current location must be a field. - * @return {Blockly.ASTNode} The AST node pointing to the next field or + * @return {ASTNode} The AST node pointing to the next field or * connection or null if there is no editable field or input connection * after the given input. * @private */ -Blockly.ASTNode.prototype.findNextForField_ = function() { +ASTNode.prototype.findNextForField_ = function() { const location = /** @type {!Blockly.Field} */ (this.location_); const input = location.getParentInput(); const block = location.getSourceBlock(); @@ -340,14 +341,14 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { for (; (newInput = block.inputList[i]); i++) { const fieldRow = newInput.fieldRow; while (fieldIdx < fieldRow.length) { - if (fieldRow[fieldIdx].isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); + if (fieldRow[fieldIdx].isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(fieldRow[fieldIdx]); } fieldIdx++; } fieldIdx = 0; if (newInput.connection) { - return Blockly.ASTNode.createInputNode(newInput); + return ASTNode.createInputNode(newInput); } } return null; @@ -357,11 +358,11 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { * Given an input find the previous editable field or an input with a non null * connection in the same block. The current location must be an input * connection. - * @return {Blockly.ASTNode} The AST node holding the previous field or + * @return {ASTNode} The AST node holding the previous field or * connection. * @private */ -Blockly.ASTNode.prototype.findPrevForInput_ = function() { +ASTNode.prototype.findPrevForInput_ = function() { const location = /** @type {!Blockly.Connection} */ (this.location_); const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); @@ -369,13 +370,13 @@ Blockly.ASTNode.prototype.findPrevForInput_ = function() { let i = curIdx, input; for (; (input = block.inputList[i]); i--) { if (input.connection && input !== parentInput) { - return Blockly.ASTNode.createInputNode(input); + return ASTNode.createInputNode(input); } const fieldRow = input.fieldRow; let j = fieldRow.length - 1, field; for (; (field = fieldRow[j]); j--) { - if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(field); + if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(field); } } } @@ -385,10 +386,10 @@ Blockly.ASTNode.prototype.findPrevForInput_ = function() { /** * Given a field find the previous editable field or an input with a non null * connection in the same block. The current location must be a field. - * @return {Blockly.ASTNode} The AST node holding the previous input or field. + * @return {ASTNode} The AST node holding the previous input or field. * @private */ -Blockly.ASTNode.prototype.findPrevForField_ = function() { +ASTNode.prototype.findPrevForField_ = function() { const location = /** @type {!Blockly.Field} */ (this.location_); const parentInput = location.getParentInput(); const block = location.getSourceBlock(); @@ -398,12 +399,12 @@ Blockly.ASTNode.prototype.findPrevForField_ = function() { let i = curIdx, input; for (; (input = block.inputList[i]); i--) { if (input.connection && input !== parentInput) { - return Blockly.ASTNode.createInputNode(input); + return ASTNode.createInputNode(input); } const fieldRow = input.fieldRow; while (fieldIdx > -1) { - if (fieldRow[fieldIdx].isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); + if (fieldRow[fieldIdx].isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(fieldRow[fieldIdx]); } fieldIdx--; } @@ -418,11 +419,11 @@ Blockly.ASTNode.prototype.findPrevForField_ = function() { /** * Navigate between stacks of blocks on the workspace. * @param {boolean} forward True to go forward. False to go backwards. - * @return {Blockly.ASTNode} The first block of the next stack or null if there + * @return {ASTNode} The first block of the next stack or null if there * are no blocks on the workspace. * @private */ -Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { +ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); if (curLocation.getSourceBlock) { curLocation = /** @type {!Blockly.IASTNodeLocationWithBlock} */ ( @@ -441,7 +442,7 @@ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { if (resultIndex == -1 || resultIndex == topBlocks.length) { return null; } - return Blockly.ASTNode.createStackNode(topBlocks[resultIndex]); + return ASTNode.createStackNode(topBlocks[resultIndex]); } } throw Error('Couldn\'t find ' + (forward ? 'next' : 'previous') + ' stack?!'); @@ -453,16 +454,16 @@ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { * on what kind of connections the block has. * @param {!Blockly.Block} block The block that we want to find the top * connection on. - * @return {!Blockly.ASTNode} The AST node containing the top connection. + * @return {!ASTNode} The AST node containing the top connection. * @private */ -Blockly.ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { +ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { - return /** @type {!Blockly.ASTNode} */ (Blockly.ASTNode.createConnectionNode( + return /** @type {!ASTNode} */ (ASTNode.createConnectionNode( topConnection)); } else { - return /** @type {!Blockly.ASTNode} */ (Blockly.ASTNode.createBlockNode( + return /** @type {!ASTNode} */ (ASTNode.createBlockNode( block)); } }; @@ -471,11 +472,11 @@ Blockly.ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { * Get the AST node pointing to the input that the block is nested under or if * the block is not nested then get the stack AST node. * @param {Blockly.Block} block The source block of the current location. - * @return {Blockly.ASTNode} The AST node pointing to the input connection or + * @return {ASTNode} The AST node pointing to the input connection or * the top block of the stack this block is in. * @private */ -Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { +ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { if (!block) { return null; } @@ -489,34 +490,34 @@ Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { // that input. if (topConnection && topConnection.targetConnection && topConnection.targetConnection.getParentInput()) { - return Blockly.ASTNode.createInputNode( + return ASTNode.createInputNode( topConnection.targetConnection.getParentInput()); } else { // Go to stack level if you are not underneath an input. - return Blockly.ASTNode.createStackNode(topBlock); + return ASTNode.createStackNode(topBlock); } }; /** * Find the first editable field or input with a connection on a given block. * @param {!Blockly.Block} block The source block of the current location. - * @return {Blockly.ASTNode} An AST node pointing to the first field or input. + * @return {ASTNode} An AST node pointing to the first field or input. * Null if there are no editable fields or inputs with connections on the block. * @private */ -Blockly.ASTNode.prototype.findFirstFieldOrInput_ = function(block) { +ASTNode.prototype.findFirstFieldOrInput_ = function(block) { const inputs = block.inputList; let i = 0, input; for (; (input = inputs[i]); i++) { const fieldRow = input.fieldRow; let j = 0, field; for (; (field = fieldRow[j]); j++) { - if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(field); + if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(field); } } if (input.connection) { - return Blockly.ASTNode.createInputNode(input); + return ASTNode.createInputNode(input); } } return null; @@ -527,12 +528,12 @@ Blockly.ASTNode.prototype.findFirstFieldOrInput_ = function(block) { * @return {Blockly.Block} The source block of the location, or null if the node * is of type workspace. */ -Blockly.ASTNode.prototype.getSourceBlock = function() { - if (this.getType() === Blockly.ASTNode.types.BLOCK) { +ASTNode.prototype.getSourceBlock = function() { + if (this.getType() === ASTNode.types.BLOCK) { return /** @type {Blockly.Block} */ (this.getLocation()); - } else if (this.getType() === Blockly.ASTNode.types.STACK) { + } else if (this.getType() === ASTNode.types.STACK) { return /** @type {Blockly.Block} */ (this.getLocation()); - } else if (this.getType() === Blockly.ASTNode.types.WORKSPACE) { + } else if (this.getType() === ASTNode.types.WORKSPACE) { return null; } else { return /** @type {Blockly.IASTNodeLocationWithBlock} */ ( @@ -542,38 +543,38 @@ Blockly.ASTNode.prototype.getSourceBlock = function() { /** * Find the element to the right of the current element in the AST. - * @return {Blockly.ASTNode} An AST node that wraps the next field, connection, + * @return {ASTNode} An AST node that wraps the next field, connection, * block, or workspace. Or null if there is no node to the right. */ -Blockly.ASTNode.prototype.next = function() { +ASTNode.prototype.next = function() { let connection, block, nextConnection, targetConnection; switch (this.type_) { - case Blockly.ASTNode.types.STACK: + case ASTNode.types.STACK: return this.navigateBetweenStacks_(true); - case Blockly.ASTNode.types.OUTPUT: + case ASTNode.types.OUTPUT: connection = /** @type {!Blockly.Connection} */ (this.location_); - return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); + return ASTNode.createBlockNode(connection.getSourceBlock()); - case Blockly.ASTNode.types.FIELD: + case ASTNode.types.FIELD: return this.findNextForField_(); - case Blockly.ASTNode.types.INPUT: + case ASTNode.types.INPUT: return this.findNextForInput_(); - case Blockly.ASTNode.types.BLOCK: + case ASTNode.types.BLOCK: block = /** @type {!Blockly.Block} */ (this.location_); nextConnection = block.nextConnection; - return Blockly.ASTNode.createConnectionNode(nextConnection); + return ASTNode.createConnectionNode(nextConnection); - case Blockly.ASTNode.types.PREVIOUS: + case ASTNode.types.PREVIOUS: connection = /** @type {!Blockly.Connection} */ (this.location_); - return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); + return ASTNode.createBlockNode(connection.getSourceBlock()); - case Blockly.ASTNode.types.NEXT: + case ASTNode.types.NEXT: connection = /** @type {!Blockly.Connection} */ (this.location_); targetConnection = connection.targetConnection; - return Blockly.ASTNode.createConnectionNode(targetConnection); + return ASTNode.createConnectionNode(targetConnection); } return null; @@ -582,32 +583,32 @@ Blockly.ASTNode.prototype.next = function() { /** * Find the element one level below and all the way to the left of the current * location. - * @return {Blockly.ASTNode} An AST node that wraps the next field, connection, + * @return {ASTNode} An AST node that wraps the next field, connection, * workspace, or block. Or null if there is nothing below this node. */ -Blockly.ASTNode.prototype.in = function() { +ASTNode.prototype.in = function() { let workspace, topBlocks, block, connection, targetConnection; switch (this.type_) { - case Blockly.ASTNode.types.WORKSPACE: + case ASTNode.types.WORKSPACE: workspace = /** @type {!Blockly.Workspace} */ (this.location_); topBlocks = workspace.getTopBlocks(true); if (topBlocks.length > 0) { - return Blockly.ASTNode.createStackNode(topBlocks[0]); + return ASTNode.createStackNode(topBlocks[0]); } break; - case Blockly.ASTNode.types.STACK: + case ASTNode.types.STACK: block = /** @type {!Blockly.Block} */ (this.location_); return this.findTopASTNodeForBlock_(block); - case Blockly.ASTNode.types.BLOCK: + case ASTNode.types.BLOCK: block = /** @type {!Blockly.Block} */ (this.location_); return this.findFirstFieldOrInput_(block); - case Blockly.ASTNode.types.INPUT: + case ASTNode.types.INPUT: connection = /** @type {!Blockly.Connection} */ (this.location_); targetConnection = connection.targetConnection; - return Blockly.ASTNode.createConnectionNode(targetConnection); + return ASTNode.createConnectionNode(targetConnection); } return null; @@ -615,41 +616,41 @@ Blockly.ASTNode.prototype.in = function() { /** * Find the element to the left of the current element in the AST. - * @return {Blockly.ASTNode} An AST node that wraps the previous field, + * @return {ASTNode} An AST node that wraps the previous field, * connection, workspace or block. Or null if no node exists to the left. * null. */ -Blockly.ASTNode.prototype.prev = function() { +ASTNode.prototype.prev = function() { let block, topConnection, connection, targetConnection; switch (this.type_) { - case Blockly.ASTNode.types.STACK: + case ASTNode.types.STACK: return this.navigateBetweenStacks_(false); - case Blockly.ASTNode.types.OUTPUT: + case ASTNode.types.OUTPUT: return null; - case Blockly.ASTNode.types.FIELD: + case ASTNode.types.FIELD: return this.findPrevForField_(); - case Blockly.ASTNode.types.INPUT: + case ASTNode.types.INPUT: return this.findPrevForInput_(); - case Blockly.ASTNode.types.BLOCK: + case ASTNode.types.BLOCK: block = /** @type {!Blockly.Block} */ (this.location_); topConnection = block.previousConnection || block.outputConnection; - return Blockly.ASTNode.createConnectionNode(topConnection); + return ASTNode.createConnectionNode(topConnection); - case Blockly.ASTNode.types.PREVIOUS: + case ASTNode.types.PREVIOUS: connection = /** @type {!Blockly.Connection} */ (this.location_); targetConnection = connection.targetConnection; if (targetConnection && !targetConnection.getParentInput()) { - return Blockly.ASTNode.createConnectionNode(targetConnection); + return ASTNode.createConnectionNode(targetConnection); } break; - case Blockly.ASTNode.types.NEXT: + case ASTNode.types.NEXT: connection = /** @type {!Blockly.Connection} */ (this.location_); - return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); + return ASTNode.createBlockNode(connection.getSourceBlock()); } return null; @@ -658,48 +659,50 @@ Blockly.ASTNode.prototype.prev = function() { /** * Find the next element that is one position above and all the way to the left * of the current location. - * @return {Blockly.ASTNode} An AST node that wraps the next field, connection, + * @return {ASTNode} An AST node that wraps the next field, connection, * workspace or block. Or null if we are at the workspace level. */ -Blockly.ASTNode.prototype.out = function() { +ASTNode.prototype.out = function() { let block, blockPos, wsCoordinate, connection, target, field; switch (this.type_) { - case Blockly.ASTNode.types.STACK: + case ASTNode.types.STACK: block = /** @type {!Blockly.Block} */ (this.location_); blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. wsCoordinate = new Blockly.utils.Coordinate( - blockPos.x, blockPos.y + Blockly.ASTNode.DEFAULT_OFFSET_Y); - return Blockly.ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); + blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); + return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); - case Blockly.ASTNode.types.OUTPUT: + case ASTNode.types.OUTPUT: connection = /** @type {!Blockly.Connection} */ (this.location_); target = connection.targetConnection; if (target) { - return Blockly.ASTNode.createConnectionNode(target); + return ASTNode.createConnectionNode(target); } - return Blockly.ASTNode.createStackNode(connection.getSourceBlock()); + return ASTNode.createStackNode(connection.getSourceBlock()); - case Blockly.ASTNode.types.FIELD: + case ASTNode.types.FIELD: field = /** @type {!Blockly.Field} */ (this.location_); - return Blockly.ASTNode.createBlockNode(field.getSourceBlock()); + return ASTNode.createBlockNode(field.getSourceBlock()); - case Blockly.ASTNode.types.INPUT: + case ASTNode.types.INPUT: connection = /** @type {!Blockly.Connection} */ (this.location_); - return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); + return ASTNode.createBlockNode(connection.getSourceBlock()); - case Blockly.ASTNode.types.BLOCK: + case ASTNode.types.BLOCK: block = /** @type {!Blockly.Block} */ (this.location_); return this.getOutAstNodeForBlock_(block); - case Blockly.ASTNode.types.PREVIOUS: + case ASTNode.types.PREVIOUS: connection = /** @type {!Blockly.Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); - case Blockly.ASTNode.types.NEXT: + case ASTNode.types.NEXT: connection = /** @type {!Blockly.Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); } return null; }; + +exports = ASTNode; diff --git a/tests/deps.js b/tests/deps.js index c6ccc9bb8..957896ec3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -102,7 +102,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.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/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'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': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); From e79faf4147255a29982e12b95d3d6bb3bfc36939 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 17:16:02 -0700 Subject: [PATCH 036/291] Migrate core/keyboard_nav/ast_node.js named requires --- core/keyboard_nav/ast_node.js | 123 +++++++++++++++++----------------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index e0a75d0c0..09a63b3a2 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -13,16 +13,15 @@ goog.module('Blockly.ASTNode'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); -goog.require('Blockly.utils.Coordinate'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.Connection'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IASTNodeLocation'); -goog.requireType('Blockly.IASTNodeLocationWithBlock'); -goog.requireType('Blockly.Input'); -goog.requireType('Blockly.Workspace'); +const Block = goog.requireType('Blockly.Block'); +const Connection = goog.requireType('Blockly.Connection'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Field = goog.requireType('Blockly.Field'); +const IASTNodeLocation = goog.requireType('Blockly.IASTNodeLocation'); +const IASTNodeLocationWithBlock = goog.requireType('Blockly.IASTNodeLocationWithBlock'); +const Input = goog.requireType('Blockly.Input'); +const Workspace = goog.requireType('Blockly.Workspace'); +const connectionTypes = goog.require('Blockly.connectionTypes'); /** @@ -31,7 +30,7 @@ goog.requireType('Blockly.Workspace'); * creating a node directly. * @param {string} type The type of the location. * Must be in ASTNode.types. - * @param {!Blockly.IASTNodeLocation} location The position in the AST. + * @param {!IASTNodeLocation} location The position in the AST. * @param {!ASTNode.Params=} opt_params Optional dictionary of options. * @constructor */ @@ -57,14 +56,14 @@ const ASTNode = function(type, location, opt_params) { /** * The location of the AST node. - * @type {!Blockly.IASTNodeLocation} + * @type {!IASTNodeLocation} * @private */ this.location_ = location; /** * The coordinate on the workspace. - * @type {Blockly.utils.Coordinate} + * @type {Coordinate} * @private */ this.wsCoordinate_ = null; @@ -74,7 +73,7 @@ const ASTNode = function(type, location, opt_params) { /** * @typedef {{ - * wsCoordinate: Blockly.utils.Coordinate + * wsCoordinate: Coordinate * }} */ ASTNode.Params; @@ -127,7 +126,7 @@ ASTNode.isConnectionType_ = function(type) { /** * Create an AST node pointing to a field. - * @param {Blockly.Field} field The location of the AST node. + * @param {Field} field The location of the AST node. * @return {ASTNode} An AST node pointing to a field. */ ASTNode.createFieldNode = function(field) { @@ -140,7 +139,7 @@ ASTNode.createFieldNode = function(field) { /** * Creates an AST node pointing to a connection. If the connection has a parent * input then create an AST node of type input that will hold the connection. - * @param {Blockly.Connection} connection This is the connection the node will + * @param {Connection} connection This is the connection the node will * point to. * @return {ASTNode} An AST node pointing to a connection. */ @@ -149,16 +148,16 @@ ASTNode.createConnectionNode = function(connection) { return null; } const type = connection.type; - if (type == Blockly.connectionTypes.INPUT_VALUE) { + if (type == connectionTypes.INPUT_VALUE) { return ASTNode.createInputNode(connection.getParentInput()); - } else if (type == Blockly.connectionTypes.NEXT_STATEMENT && + } else if (type == connectionTypes.NEXT_STATEMENT && connection.getParentInput()) { return ASTNode.createInputNode(connection.getParentInput()); - } else if (type == Blockly.connectionTypes.NEXT_STATEMENT) { + } else if (type == connectionTypes.NEXT_STATEMENT) { return new ASTNode(ASTNode.types.NEXT, connection); - } else if (type == Blockly.connectionTypes.OUTPUT_VALUE) { + } else if (type == connectionTypes.OUTPUT_VALUE) { return new ASTNode(ASTNode.types.OUTPUT, connection); - } else if (type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { + } else if (type == connectionTypes.PREVIOUS_STATEMENT) { return new ASTNode(ASTNode.types.PREVIOUS, connection); } return null; @@ -167,7 +166,7 @@ ASTNode.createConnectionNode = function(connection) { /** * Creates an AST node pointing to an input. Stores the input connection as the * location. - * @param {Blockly.Input} input The input used to create an AST node. + * @param {Input} input The input used to create an AST node. * @return {ASTNode} An AST node pointing to a input. */ ASTNode.createInputNode = function(input) { @@ -179,7 +178,7 @@ ASTNode.createInputNode = function(input) { /** * Creates an AST node pointing to a block. - * @param {Blockly.Block} block The block used to create an AST node. + * @param {Block} block The block used to create an AST node. * @return {ASTNode} An AST node pointing to a block. */ ASTNode.createBlockNode = function(block) { @@ -192,7 +191,7 @@ ASTNode.createBlockNode = function(block) { /** * Create an AST node of type stack. A stack, represented by its top block, is * the set of all blocks connected to a top block, including the top block. - * @param {Blockly.Block} topBlock A top block has no parent and can be found + * @param {Block} topBlock A top block has no parent and can be found * in the list returned by workspace.getTopBlocks(). * @return {ASTNode} An AST node of type stack that points to the top * block on the stack. @@ -206,8 +205,8 @@ ASTNode.createStackNode = function(topBlock) { /** * Creates an AST node pointing to a workspace. - * @param {!Blockly.Workspace} workspace The workspace that we are on. - * @param {Blockly.utils.Coordinate} wsCoordinate The position on the workspace + * @param {!Workspace} workspace The workspace that we are on. + * @param {Coordinate} wsCoordinate The position on the workspace * for this node. * @return {ASTNode} An AST node pointing to a workspace and a position * on the workspace. @@ -226,7 +225,7 @@ ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { /** * Creates an AST node for the top position on a block. * This is either an output connection, previous connection, or block. - * @param {!Blockly.Block} block The block to find the top most AST node on. + * @param {!Block} block The block to find the top most AST node on. * @return {ASTNode} The AST node holding the top most position on the * block. */ @@ -259,7 +258,7 @@ ASTNode.prototype.processParams_ = function(params) { * Gets the value pointed to by this node. * It is the callers responsibility to check the node type to figure out what * type of object they get back from this. - * @return {!Blockly.IASTNodeLocation} The current field, connection, workspace, or + * @return {!IASTNodeLocation} The current field, connection, workspace, or * block the cursor is on. */ ASTNode.prototype.getLocation = function() { @@ -277,7 +276,7 @@ ASTNode.prototype.getType = function() { /** * The coordinate on the workspace. - * @return {Blockly.utils.Coordinate} The workspace coordinate or null if the + * @return {Coordinate} The workspace coordinate or null if the * location is not a workspace. */ ASTNode.prototype.getWsCoordinate = function() { @@ -303,7 +302,7 @@ ASTNode.prototype.isConnection = function() { * @private */ ASTNode.prototype.findNextForInput_ = function() { - const location = /** @type {!Blockly.Connection} */ (this.location_); + const location = /** @type {!Connection} */ (this.location_); const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); const curIdx = block.inputList.indexOf(parentInput); @@ -332,10 +331,10 @@ ASTNode.prototype.findNextForInput_ = function() { * @private */ ASTNode.prototype.findNextForField_ = function() { - const location = /** @type {!Blockly.Field} */ (this.location_); + const location = /** @type {!Field} */ (this.location_); const input = location.getParentInput(); const block = location.getSourceBlock(); - const curIdx = block.inputList.indexOf(/** @type {!Blockly.Input} */ (input)); + const curIdx = block.inputList.indexOf(/** @type {!Input} */ (input)); let fieldIdx = input.fieldRow.indexOf(location) + 1; let i = curIdx, newInput; for (; (newInput = block.inputList[i]); i++) { @@ -363,7 +362,7 @@ ASTNode.prototype.findNextForField_ = function() { * @private */ ASTNode.prototype.findPrevForInput_ = function() { - const location = /** @type {!Blockly.Connection} */ (this.location_); + const location = /** @type {!Connection} */ (this.location_); const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); const curIdx = block.inputList.indexOf(parentInput); @@ -390,11 +389,11 @@ ASTNode.prototype.findPrevForInput_ = function() { * @private */ ASTNode.prototype.findPrevForField_ = function() { - const location = /** @type {!Blockly.Field} */ (this.location_); + const location = /** @type {!Field} */ (this.location_); const parentInput = location.getParentInput(); const block = location.getSourceBlock(); const curIdx = block.inputList.indexOf( - /** @type {!Blockly.Input} */ (parentInput)); + /** @type {!Input} */ (parentInput)); let fieldIdx = parentInput.fieldRow.indexOf(location) - 1; let i = curIdx, input; for (; (input = block.inputList[i]); i--) { @@ -426,7 +425,7 @@ ASTNode.prototype.findPrevForField_ = function() { ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); if (curLocation.getSourceBlock) { - curLocation = /** @type {!Blockly.IASTNodeLocationWithBlock} */ ( + curLocation = /** @type {!IASTNodeLocationWithBlock} */ ( curLocation).getSourceBlock(); } if (!curLocation || !curLocation.workspace) { @@ -452,7 +451,7 @@ ASTNode.prototype.navigateBetweenStacks_ = function(forward) { * Finds the top most AST node for a given block. * This is either the previous connection, output connection or block depending * on what kind of connections the block has. - * @param {!Blockly.Block} block The block that we want to find the top + * @param {!Block} block The block that we want to find the top * connection on. * @return {!ASTNode} The AST node containing the top connection. * @private @@ -471,7 +470,7 @@ ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { /** * Get the AST node pointing to the input that the block is nested under or if * the block is not nested then get the stack AST node. - * @param {Blockly.Block} block The source block of the current location. + * @param {Block} block The source block of the current location. * @return {ASTNode} The AST node pointing to the input connection or * the top block of the stack this block is in. * @private @@ -500,7 +499,7 @@ ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { /** * Find the first editable field or input with a connection on a given block. - * @param {!Blockly.Block} block The source block of the current location. + * @param {!Block} block The source block of the current location. * @return {ASTNode} An AST node pointing to the first field or input. * Null if there are no editable fields or inputs with connections on the block. * @private @@ -525,18 +524,18 @@ ASTNode.prototype.findFirstFieldOrInput_ = function(block) { /** * Finds the source block of the location of this node. - * @return {Blockly.Block} The source block of the location, or null if the node + * @return {Block} The source block of the location, or null if the node * is of type workspace. */ ASTNode.prototype.getSourceBlock = function() { if (this.getType() === ASTNode.types.BLOCK) { - return /** @type {Blockly.Block} */ (this.getLocation()); + return /** @type {Block} */ (this.getLocation()); } else if (this.getType() === ASTNode.types.STACK) { - return /** @type {Blockly.Block} */ (this.getLocation()); + return /** @type {Block} */ (this.getLocation()); } else if (this.getType() === ASTNode.types.WORKSPACE) { return null; } else { - return /** @type {Blockly.IASTNodeLocationWithBlock} */ ( + return /** @type {IASTNodeLocationWithBlock} */ ( this.getLocation()).getSourceBlock(); } }; @@ -553,7 +552,7 @@ ASTNode.prototype.next = function() { return this.navigateBetweenStacks_(true); case ASTNode.types.OUTPUT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); case ASTNode.types.FIELD: @@ -563,16 +562,16 @@ ASTNode.prototype.next = function() { return this.findNextForInput_(); case ASTNode.types.BLOCK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); nextConnection = block.nextConnection; return ASTNode.createConnectionNode(nextConnection); case ASTNode.types.PREVIOUS: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); case ASTNode.types.NEXT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); targetConnection = connection.targetConnection; return ASTNode.createConnectionNode(targetConnection); } @@ -590,7 +589,7 @@ ASTNode.prototype.in = function() { let workspace, topBlocks, block, connection, targetConnection; switch (this.type_) { case ASTNode.types.WORKSPACE: - workspace = /** @type {!Blockly.Workspace} */ (this.location_); + workspace = /** @type {!Workspace} */ (this.location_); topBlocks = workspace.getTopBlocks(true); if (topBlocks.length > 0) { return ASTNode.createStackNode(topBlocks[0]); @@ -598,15 +597,15 @@ ASTNode.prototype.in = function() { break; case ASTNode.types.STACK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); return this.findTopASTNodeForBlock_(block); case ASTNode.types.BLOCK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); return this.findFirstFieldOrInput_(block); case ASTNode.types.INPUT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); targetConnection = connection.targetConnection; return ASTNode.createConnectionNode(targetConnection); } @@ -636,12 +635,12 @@ ASTNode.prototype.prev = function() { return this.findPrevForInput_(); case ASTNode.types.BLOCK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); topConnection = block.previousConnection || block.outputConnection; return ASTNode.createConnectionNode(topConnection); case ASTNode.types.PREVIOUS: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); targetConnection = connection.targetConnection; if (targetConnection && !targetConnection.getParentInput()) { return ASTNode.createConnectionNode(targetConnection); @@ -649,7 +648,7 @@ ASTNode.prototype.prev = function() { break; case ASTNode.types.NEXT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); } @@ -666,15 +665,15 @@ ASTNode.prototype.out = function() { let block, blockPos, wsCoordinate, connection, target, field; switch (this.type_) { case ASTNode.types.STACK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. - wsCoordinate = new Blockly.utils.Coordinate( + wsCoordinate = new Coordinate( blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); case ASTNode.types.OUTPUT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); target = connection.targetConnection; if (target) { return ASTNode.createConnectionNode(target); @@ -682,23 +681,23 @@ ASTNode.prototype.out = function() { return ASTNode.createStackNode(connection.getSourceBlock()); case ASTNode.types.FIELD: - field = /** @type {!Blockly.Field} */ (this.location_); + field = /** @type {!Field} */ (this.location_); return ASTNode.createBlockNode(field.getSourceBlock()); case ASTNode.types.INPUT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); case ASTNode.types.BLOCK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); return this.getOutAstNodeForBlock_(block); case ASTNode.types.PREVIOUS: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); case ASTNode.types.NEXT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); } From c19ce37a4accf24f1f044691bcf68af1d19c1938 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:29:05 -0700 Subject: [PATCH 037/291] clang-format core/keyboard_nav/ast_node.js --- core/keyboard_nav/ast_node.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 09a63b3a2..0c349bbd0 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -150,8 +150,8 @@ ASTNode.createConnectionNode = function(connection) { const type = connection.type; if (type == connectionTypes.INPUT_VALUE) { return ASTNode.createInputNode(connection.getParentInput()); - } else if (type == connectionTypes.NEXT_STATEMENT && - connection.getParentInput()) { + } else if ( + type == connectionTypes.NEXT_STATEMENT && connection.getParentInput()) { return ASTNode.createInputNode(connection.getParentInput()); } else if (type == connectionTypes.NEXT_STATEMENT) { return new ASTNode(ASTNode.types.NEXT, connection); @@ -215,11 +215,8 @@ ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { if (!wsCoordinate || !workspace) { return null; } - const params = { - wsCoordinate: wsCoordinate - }; - return new ASTNode( - ASTNode.types.WORKSPACE, workspace, params); + const params = {wsCoordinate: wsCoordinate}; + return new ASTNode(ASTNode.types.WORKSPACE, workspace, params); }; /** @@ -425,8 +422,8 @@ ASTNode.prototype.findPrevForField_ = function() { ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); if (curLocation.getSourceBlock) { - curLocation = /** @type {!IASTNodeLocationWithBlock} */ ( - curLocation).getSourceBlock(); + curLocation = /** @type {!IASTNodeLocationWithBlock} */ (curLocation) + .getSourceBlock(); } if (!curLocation || !curLocation.workspace) { return null; @@ -459,11 +456,10 @@ ASTNode.prototype.navigateBetweenStacks_ = function(forward) { ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { - return /** @type {!ASTNode} */ (ASTNode.createConnectionNode( - topConnection)); + return /** @type {!ASTNode} */ ( + ASTNode.createConnectionNode(topConnection)); } else { - return /** @type {!ASTNode} */ (ASTNode.createBlockNode( - block)); + return /** @type {!ASTNode} */ (ASTNode.createBlockNode(block)); } }; @@ -535,8 +531,8 @@ ASTNode.prototype.getSourceBlock = function() { } else if (this.getType() === ASTNode.types.WORKSPACE) { return null; } else { - return /** @type {IASTNodeLocationWithBlock} */ ( - this.getLocation()).getSourceBlock(); + return /** @type {IASTNodeLocationWithBlock} */ (this.getLocation()) + .getSourceBlock(); } }; @@ -668,8 +664,8 @@ ASTNode.prototype.out = function() { block = /** @type {!Block} */ (this.location_); blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. - wsCoordinate = new Coordinate( - blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); + wsCoordinate = + new Coordinate(blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); case ASTNode.types.OUTPUT: From 02f1055c445fb3db78a1dd30695dc2802f94c523 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 19:05:24 -0700 Subject: [PATCH 038/291] Add eslint disable lines to core/keyboard_nav/ast_node.js --- core/keyboard_nav/ast_node.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 0c349bbd0..c1323099f 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -13,13 +13,20 @@ goog.module('Blockly.ASTNode'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const Connection = goog.requireType('Blockly.Connection'); const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocation = goog.requireType('Blockly.IASTNodeLocation'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocationWithBlock = goog.requireType('Blockly.IASTNodeLocationWithBlock'); +/* eslint-disable-next-line no-unused-vars */ const Input = goog.requireType('Blockly.Input'); +/* eslint-disable-next-line no-unused-vars */ const Workspace = goog.requireType('Blockly.Workspace'); const connectionTypes = goog.require('Blockly.connectionTypes'); From d9edeca432351250bf2077c4b2ffd8ba3b91eba6 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 19:19:13 -0700 Subject: [PATCH 039/291] Update for loop syntax in core/keyboard_nav/ast_node.js --- core/keyboard_nav/ast_node.js | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index c1323099f..11405bc22 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -310,11 +310,11 @@ ASTNode.prototype.findNextForInput_ = function() { const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); const curIdx = block.inputList.indexOf(parentInput); - let i = curIdx + 1, input; - for (; (input = block.inputList[i]); i++) { + for (let i = curIdx + 1; i < block.inputList.length; i++) { + const input = block.inputList[i]; const fieldRow = input.fieldRow; - let j = 0, field; - for (; (field = fieldRow[j]); j++) { + for (let j = 0; j < fieldRow.length; j++) { + const field = fieldRow[j]; if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { return ASTNode.createFieldNode(field); } @@ -340,8 +340,8 @@ ASTNode.prototype.findNextForField_ = function() { const block = location.getSourceBlock(); const curIdx = block.inputList.indexOf(/** @type {!Input} */ (input)); let fieldIdx = input.fieldRow.indexOf(location) + 1; - let i = curIdx, newInput; - for (; (newInput = block.inputList[i]); i++) { + for (let i = curIdx; i < block.inputList.length; i++) { + const newInput = block.inputList[i]; const fieldRow = newInput.fieldRow; while (fieldIdx < fieldRow.length) { if (fieldRow[fieldIdx].isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { @@ -370,14 +370,14 @@ ASTNode.prototype.findPrevForInput_ = function() { const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); const curIdx = block.inputList.indexOf(parentInput); - let i = curIdx, input; - for (; (input = block.inputList[i]); i--) { + for (let i = curIdx; i >= 0; i--) { + const input = block.inputList[i]; if (input.connection && input !== parentInput) { return ASTNode.createInputNode(input); } const fieldRow = input.fieldRow; - let j = fieldRow.length - 1, field; - for (; (field = fieldRow[j]); j--) { + for (let j = fieldRow.length - 1; j >= 0; j--) { + const field = fieldRow[j]; if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { return ASTNode.createFieldNode(field); } @@ -399,8 +399,8 @@ ASTNode.prototype.findPrevForField_ = function() { const curIdx = block.inputList.indexOf( /** @type {!Input} */ (parentInput)); let fieldIdx = parentInput.fieldRow.indexOf(location) - 1; - let i = curIdx, input; - for (; (input = block.inputList[i]); i--) { + for (let i = curIdx; i >= 0; i--) { + const input = block.inputList[i]; if (input.connection && input !== parentInput) { return ASTNode.createInputNode(input); } @@ -437,8 +437,8 @@ ASTNode.prototype.navigateBetweenStacks_ = function(forward) { } const curRoot = curLocation.getRootBlock(); const topBlocks = curRoot.workspace.getTopBlocks(true); - let i = 0, topBlock; - for (; (topBlock = topBlocks[i]); i++) { + for (let i = 0; i < topBlocks.length; i++) { + const topBlock = topBlocks[i]; if (curRoot.id == topBlock.id) { const offset = forward ? 1 : -1; const resultIndex = i + offset; @@ -509,11 +509,11 @@ ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { */ ASTNode.prototype.findFirstFieldOrInput_ = function(block) { const inputs = block.inputList; - let i = 0, input; - for (; (input = inputs[i]); i++) { + for (let i = 0; i < inputs.length; i++) { + const input = inputs[i]; const fieldRow = input.fieldRow; - let j = 0, field; - for (; (field = fieldRow[j]); j++) { + for (let j = 0; j < fieldRow.length; j++) { + const field = fieldRow[j]; if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { return ASTNode.createFieldNode(field); } From fabba95beb07a268b81e2a5e7f408aa20555e917 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 19:26:15 -0700 Subject: [PATCH 040/291] Adding blocks to case statements in core/keyboard_nav/ast_node.js --- core/keyboard_nav/ast_node.js | 126 +++++++++++++++++----------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 11405bc22..b52ca1b18 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -549,34 +549,34 @@ ASTNode.prototype.getSourceBlock = function() { * block, or workspace. Or null if there is no node to the right. */ ASTNode.prototype.next = function() { - let connection, block, nextConnection, targetConnection; switch (this.type_) { case ASTNode.types.STACK: return this.navigateBetweenStacks_(true); - case ASTNode.types.OUTPUT: - connection = /** @type {!Connection} */ (this.location_); + case ASTNode.types.OUTPUT: { + const connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); - + } case ASTNode.types.FIELD: return this.findNextForField_(); case ASTNode.types.INPUT: return this.findNextForInput_(); - case ASTNode.types.BLOCK: - block = /** @type {!Block} */ (this.location_); - nextConnection = block.nextConnection; + case ASTNode.types.BLOCK: { + const block = /** @type {!Block} */ (this.location_); + const nextConnection = block.nextConnection; return ASTNode.createConnectionNode(nextConnection); - - case ASTNode.types.PREVIOUS: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.PREVIOUS: { + const connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); - - case ASTNode.types.NEXT: - connection = /** @type {!Connection} */ (this.location_); - targetConnection = connection.targetConnection; + } + case ASTNode.types.NEXT: { + const connection = /** @type {!Connection} */ (this.location_); + const targetConnection = connection.targetConnection; return ASTNode.createConnectionNode(targetConnection); + } } return null; @@ -589,28 +589,28 @@ ASTNode.prototype.next = function() { * workspace, or block. Or null if there is nothing below this node. */ ASTNode.prototype.in = function() { - let workspace, topBlocks, block, connection, targetConnection; switch (this.type_) { - case ASTNode.types.WORKSPACE: - workspace = /** @type {!Workspace} */ (this.location_); - topBlocks = workspace.getTopBlocks(true); + case ASTNode.types.WORKSPACE: { + const workspace = /** @type {!Workspace} */ (this.location_); + const topBlocks = workspace.getTopBlocks(true); if (topBlocks.length > 0) { return ASTNode.createStackNode(topBlocks[0]); } break; - - case ASTNode.types.STACK: - block = /** @type {!Block} */ (this.location_); + } + case ASTNode.types.STACK: { + const block = /** @type {!Block} */ (this.location_); return this.findTopASTNodeForBlock_(block); - - case ASTNode.types.BLOCK: - block = /** @type {!Block} */ (this.location_); + } + case ASTNode.types.BLOCK: { + const block = /** @type {!Block} */ (this.location_); return this.findFirstFieldOrInput_(block); - - case ASTNode.types.INPUT: - connection = /** @type {!Connection} */ (this.location_); - targetConnection = connection.targetConnection; + } + case ASTNode.types.INPUT: { + const connection = /** @type {!Connection} */ (this.location_); + const targetConnection = connection.targetConnection; return ASTNode.createConnectionNode(targetConnection); + } } return null; @@ -623,7 +623,6 @@ ASTNode.prototype.in = function() { * null. */ ASTNode.prototype.prev = function() { - let block, topConnection, connection, targetConnection; switch (this.type_) { case ASTNode.types.STACK: return this.navigateBetweenStacks_(false); @@ -637,22 +636,23 @@ ASTNode.prototype.prev = function() { case ASTNode.types.INPUT: return this.findPrevForInput_(); - case ASTNode.types.BLOCK: - block = /** @type {!Block} */ (this.location_); - topConnection = block.previousConnection || block.outputConnection; + case ASTNode.types.BLOCK: { + const block = /** @type {!Block} */ (this.location_); + const topConnection = block.previousConnection || block.outputConnection; return ASTNode.createConnectionNode(topConnection); - - case ASTNode.types.PREVIOUS: - connection = /** @type {!Connection} */ (this.location_); - targetConnection = connection.targetConnection; + } + case ASTNode.types.PREVIOUS: { + const connection = /** @type {!Connection} */ (this.location_); + const targetConnection = connection.targetConnection; if (targetConnection && !targetConnection.getParentInput()) { return ASTNode.createConnectionNode(targetConnection); } break; - - case ASTNode.types.NEXT: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.NEXT: { + const connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); + } } return null; @@ -665,43 +665,43 @@ ASTNode.prototype.prev = function() { * workspace or block. Or null if we are at the workspace level. */ ASTNode.prototype.out = function() { - let block, blockPos, wsCoordinate, connection, target, field; switch (this.type_) { - case ASTNode.types.STACK: - block = /** @type {!Block} */ (this.location_); - blockPos = block.getRelativeToSurfaceXY(); + case ASTNode.types.STACK: { + const block = /** @type {!Block} */ (this.location_); + const blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. - wsCoordinate = + const wsCoordinate = new Coordinate(blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); - - case ASTNode.types.OUTPUT: - connection = /** @type {!Connection} */ (this.location_); - target = connection.targetConnection; + } + case ASTNode.types.OUTPUT: { + const connection = /** @type {!Connection} */ (this.location_); + const target = connection.targetConnection; if (target) { return ASTNode.createConnectionNode(target); } return ASTNode.createStackNode(connection.getSourceBlock()); - - case ASTNode.types.FIELD: - field = /** @type {!Field} */ (this.location_); + } + case ASTNode.types.FIELD: { + const field = /** @type {!Field} */ (this.location_); return ASTNode.createBlockNode(field.getSourceBlock()); - - case ASTNode.types.INPUT: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.INPUT: { + const connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); - - case ASTNode.types.BLOCK: - block = /** @type {!Block} */ (this.location_); + } + case ASTNode.types.BLOCK: { + const block = /** @type {!Block} */ (this.location_); return this.getOutAstNodeForBlock_(block); - - case ASTNode.types.PREVIOUS: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.PREVIOUS: { + const connection = /** @type {!Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); - - case ASTNode.types.NEXT: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.NEXT: { + const connection = /** @type {!Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); + } } return null; From 6787624e3ef9cb748b3d8e1f534b3ece46d483e1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:46:10 -0700 Subject: [PATCH 041/291] Migrate core/workspace_audio.js to ES6 const/let --- core/workspace_audio.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 378c19287..1ca2a2255 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -71,17 +71,18 @@ Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { if (!filenames.length) { return; } + let audioTest; try { - var audioTest = new Blockly.utils.global['Audio'](); + audioTest = new Blockly.utils.global['Audio'](); } catch (e) { // No browser support for Audio. // IE can throw an error even if the Audio object exists. return; } - var sound; - for (var i = 0; i < filenames.length; i++) { - var filename = filenames[i]; - var ext = filename.match(/\.(\w+)$/); + let sound; + for (let i = 0; i < filenames.length; i++) { + const filename = filenames[i]; + const ext = filename.match(/\.(\w+)$/); if (ext && audioTest.canPlayType('audio/' + ext[1])) { // Found an audio format we can play. sound = new Blockly.utils.global['Audio'](filename); @@ -98,10 +99,10 @@ Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { * @package */ Blockly.WorkspaceAudio.prototype.preload = function() { - for (var name in this.SOUNDS_) { - var sound = this.SOUNDS_[name]; + for (let name in this.SOUNDS_) { + const sound = this.SOUNDS_[name]; sound.volume = 0.01; - var playPromise = sound.play(); + const playPromise = sound.play(); // Edge does not return a promise, so we need to check. if (playPromise !== undefined) { // If we don't wait for the play request to complete before calling pause() @@ -129,16 +130,16 @@ Blockly.WorkspaceAudio.prototype.preload = function() { * @param {number=} opt_volume Volume of sound (0-1). */ Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { - var sound = this.SOUNDS_[name]; + const sound = this.SOUNDS_[name]; if (sound) { // Don't play one sound on top of another. - var now = new Date; + const now = new Date; if (this.lastSound_ != null && now - this.lastSound_ < Blockly.internalConstants.SOUND_LIMIT) { return; } this.lastSound_ = now; - var mySound; + let mySound; if (Blockly.utils.userAgent.IPAD || Blockly.utils.userAgent.ANDROID) { // Creating a new audio node causes lag in Android and iPad. Android // refetches the file from the server, iPad uses a singleton audio From f7c88bfcd91bb2168137358e91ce01ae17036bee Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:46:27 -0700 Subject: [PATCH 042/291] Migrate core/workspace_audio.js to goog.module --- core/workspace_audio.js | 18 ++++++++++-------- tests/deps.js | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 1ca2a2255..72e66d952 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -11,10 +11,10 @@ */ 'use strict'; -goog.provide('Blockly.WorkspaceAudio'); +goog.module('Blockly.WorkspaceAudio'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.userAgent'); @@ -27,7 +27,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * this audio object belongs to, or null. * @constructor */ -Blockly.WorkspaceAudio = function(parentWorkspace) { +const WorkspaceAudio = function(parentWorkspace) { /** * The parent of the workspace this object belongs to, or null. May be @@ -49,13 +49,13 @@ Blockly.WorkspaceAudio = function(parentWorkspace) { * @type {Date} * @private */ -Blockly.WorkspaceAudio.prototype.lastSound_ = null; +WorkspaceAudio.prototype.lastSound_ = null; /** * Dispose of this audio manager. * @package */ -Blockly.WorkspaceAudio.prototype.dispose = function() { +WorkspaceAudio.prototype.dispose = function() { this.parentWorkspace_ = null; this.SOUNDS_ = null; }; @@ -67,7 +67,7 @@ Blockly.WorkspaceAudio.prototype.dispose = function() { * Filenames include path from Blockly's root. File extensions matter. * @param {string} name Name of sound. */ -Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { +WorkspaceAudio.prototype.load = function(filenames, name) { if (!filenames.length) { return; } @@ -98,7 +98,7 @@ Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { * Preload all the audio files so that they play quickly when asked for. * @package */ -Blockly.WorkspaceAudio.prototype.preload = function() { +WorkspaceAudio.prototype.preload = function() { for (let name in this.SOUNDS_) { const sound = this.SOUNDS_[name]; sound.volume = 0.01; @@ -129,7 +129,7 @@ Blockly.WorkspaceAudio.prototype.preload = function() { * @param {string} name Name of sound. * @param {number=} opt_volume Volume of sound (0-1). */ -Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { +WorkspaceAudio.prototype.play = function(name, opt_volume) { const sound = this.SOUNDS_[name]; if (sound) { // Don't play one sound on top of another. @@ -155,3 +155,5 @@ Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { this.parentWorkspace_.getAudioManager().play(name, opt_volume); } }; + +exports = WorkspaceAudio; diff --git a/tests/deps.js b/tests/deps.js index 957896ec3..0018d3a1d 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -202,7 +202,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'], {'lang': 'es6', 'module': 'goog'}); 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.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); 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']); From 5f819cd0fe949c619b1d333492ad074e3e51e38d Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:48:10 -0700 Subject: [PATCH 043/291] Migrate core/workspace_audio.js named requires --- core/workspace_audio.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 72e66d952..7a6acde4f 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -14,16 +14,16 @@ goog.module('Blockly.WorkspaceAudio'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils.global'); -goog.require('Blockly.utils.userAgent'); - -goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const global = goog.require('Blockly.utils.global'); +const internalConstants = goog.require('Blockly.internalConstants'); +const userAgent = goog.require('Blockly.utils.userAgent'); /** * Class for loading, storing, and playing audio for a workspace. - * @param {Blockly.WorkspaceSvg} parentWorkspace The parent of the workspace + * @param {WorkspaceSvg} parentWorkspace The parent of the workspace * this audio object belongs to, or null. * @constructor */ @@ -32,7 +32,7 @@ const WorkspaceAudio = function(parentWorkspace) { /** * The parent of the workspace this object belongs to, or null. May be * checked for sounds that this object can't find. - * @type {Blockly.WorkspaceSvg} + * @type {WorkspaceSvg} * @private */ this.parentWorkspace_ = parentWorkspace; @@ -73,7 +73,7 @@ WorkspaceAudio.prototype.load = function(filenames, name) { } let audioTest; try { - audioTest = new Blockly.utils.global['Audio'](); + audioTest = new global['Audio'](); } catch (e) { // No browser support for Audio. // IE can throw an error even if the Audio object exists. @@ -85,7 +85,7 @@ WorkspaceAudio.prototype.load = function(filenames, name) { const ext = filename.match(/\.(\w+)$/); if (ext && audioTest.canPlayType('audio/' + ext[1])) { // Found an audio format we can play. - sound = new Blockly.utils.global['Audio'](filename); + sound = new global['Audio'](filename); break; } } @@ -117,7 +117,7 @@ WorkspaceAudio.prototype.preload = function() { // iOS can only process one sound at a time. Trying to load more than one // corrupts the earlier ones. Just load one and leave the others uncached. - if (Blockly.utils.userAgent.IPAD || Blockly.utils.userAgent.IPHONE) { + if (userAgent.IPAD || userAgent.IPHONE) { break; } } @@ -135,12 +135,12 @@ WorkspaceAudio.prototype.play = function(name, opt_volume) { // Don't play one sound on top of another. const now = new Date; if (this.lastSound_ != null && - now - this.lastSound_ < Blockly.internalConstants.SOUND_LIMIT) { + now - this.lastSound_ < internalConstants.SOUND_LIMIT) { return; } this.lastSound_ = now; let mySound; - if (Blockly.utils.userAgent.IPAD || Blockly.utils.userAgent.ANDROID) { + if (userAgent.IPAD || userAgent.ANDROID) { // Creating a new audio node causes lag in Android and iPad. Android // refetches the file from the server, iPad uses a singleton audio // node which must be deleted and recreated for each new audio tag. From 813f27706f4ce84db3d54ac8d1e41341e35559a2 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:50:13 -0700 Subject: [PATCH 044/291] clang-format core/workspace_audio.js --- core/workspace_audio.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 7a6acde4f..11f16b8b1 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -28,7 +28,6 @@ const userAgent = goog.require('Blockly.utils.userAgent'); * @constructor */ const WorkspaceAudio = function(parentWorkspace) { - /** * The parent of the workspace this object belongs to, or null. May be * checked for sounds that this object can't find. @@ -105,9 +104,10 @@ WorkspaceAudio.prototype.preload = function() { const playPromise = sound.play(); // Edge does not return a promise, so we need to check. if (playPromise !== undefined) { - // If we don't wait for the play request to complete before calling pause() - // we will get an exception: (DOMException: The play() request was interrupted) - // See more: https://developers.google.com/web/updates/2017/06/play-request-was-interrupted + // If we don't wait for the play request to complete before calling + // pause() we will get an exception: (DOMException: The play() request was + // interrupted) See more: + // https://developers.google.com/web/updates/2017/06/play-request-was-interrupted playPromise.then(sound.pause).catch(function() { // Play without user interaction was prevented. }); From 4e147b2593befd887a06c5dae91583019c4cbc00 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 15:32:42 -0700 Subject: [PATCH 045/291] Update syntax for for..in loop --- core/workspace_audio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 11f16b8b1..ba1da0c95 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -98,7 +98,7 @@ WorkspaceAudio.prototype.load = function(filenames, name) { * @package */ WorkspaceAudio.prototype.preload = function() { - for (let name in this.SOUNDS_) { + for (const name in this.SOUNDS_) { const sound = this.SOUNDS_[name]; sound.volume = 0.01; const playPromise = sound.play(); From adc4c02abfd85b4d60a064d94b433e52ed56f787 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 16:39:44 -0700 Subject: [PATCH 046/291] Fix lint --- core/field_variable.js | 3 +++ core/gesture.js | 2 ++ core/zoom_controls.js | 8 ++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index f700d4a99..f4ae38a51 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -13,9 +13,12 @@ goog.module('Blockly.FieldVariable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); const FieldDropdown = goog.require('Blockly.FieldDropdown'); +/* eslint-disable-next-line no-unused-vars */ const Menu = goog.requireType('Blockly.Menu'); +/* eslint-disable-next-line no-unused-vars */ const MenuItem = goog.requireType('Blockly.MenuItem'); const Msg = goog.require('Blockly.Msg'); const Size = goog.require('Blockly.utils.Size'); diff --git a/core/gesture.js b/core/gesture.js index 933930e44..a1ef6ca91 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -22,6 +22,7 @@ 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'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); /* eslint-disable-next-line no-unused-vars */ const IBlockDragger = goog.requireType('Blockly.IBlockDragger'); @@ -33,6 +34,7 @@ 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'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const WorkspaceDragger = goog.require('Blockly.WorkspaceDragger'); const blockAnimations = goog.require('Blockly.blockAnimations'); diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 37c1cb17d..1b7a568cc 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -13,10 +13,10 @@ goog.module('Blockly.ZoomControls'); goog.module.declareLegacyNamespace(); -const Blockly = goog.require('Blockly'); const ComponentManager = goog.require('Blockly.ComponentManager'); const Css = goog.require('Blockly.Css'); const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ const IPositionable = goog.require('Blockly.IPositionable'); const Rect = goog.require('Blockly.utils.Rect'); const Svg = goog.require('Blockly.utils.Svg'); @@ -54,7 +54,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_. + * button. Opaque data returned from browserEvents.conditionalBind. * @type {?browserEvents.Data} * @private */ @@ -62,7 +62,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_. + * Opaque data returned from browserEvents.conditionalBind. * @type {?browserEvents.Data} * @private */ @@ -70,7 +70,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_. + * Opaque data returned from browserEvents.conditionalBind. * @type {?browserEvents.Data} * @private */ From 4c6b2bae3985979c565d83af4622c1d01adb7c1f Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 16:45:05 -0700 Subject: [PATCH 047/291] Rebuild --- tests/deps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/deps.js b/tests/deps.js index 0018d3a1d..0820fc9e1 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', '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('../../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': 'es6', 'module': 'goog'}); goog.addDependency('base.js', [], []); From 38374405647c789c4e74eafae77f578e5a92177f Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:27:57 -0700 Subject: [PATCH 048/291] Migrate core/keyboard_nav/marker.js to ES6 const/let --- core/keyboard_nav/marker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index de31d6084..555bf7c97 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -85,7 +85,7 @@ Blockly.Marker.prototype.getCurNode = function() { * @param {Blockly.ASTNode} newNode The new location of the marker. */ Blockly.Marker.prototype.setCurNode = function(newNode) { - var oldNode = this.curNode_; + const oldNode = this.curNode_; this.curNode_ = newNode; if (this.drawer_) { this.drawer_.draw(oldNode, this.curNode_); From 014316431e848ff549352d1f5ba4e491219199a3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:28:11 -0700 Subject: [PATCH 049/291] Migrate core/keyboard_nav/marker.js to goog.module --- core/keyboard_nav/marker.js | 21 ++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index 555bf7c97..115a1f861 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Marker'); +goog.module('Blockly.Marker'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); @@ -23,7 +24,7 @@ goog.requireType('Blockly.blockRendering.MarkerSvg'); * This is used in keyboard navigation to save a location in the Blockly AST. * @constructor */ -Blockly.Marker = function() { +const Marker = function() { /** * The colour of the marker. * @type {?string} @@ -56,7 +57,7 @@ Blockly.Marker = function() { * @param {Blockly.blockRendering.MarkerSvg} drawer The object in charge of * drawing the marker. */ -Blockly.Marker.prototype.setDrawer = function(drawer) { +Marker.prototype.setDrawer = function(drawer) { this.drawer_ = drawer; }; @@ -65,7 +66,7 @@ Blockly.Marker.prototype.setDrawer = function(drawer) { * @return {Blockly.blockRendering.MarkerSvg} The object in charge of drawing * the marker. */ -Blockly.Marker.prototype.getDrawer = function() { +Marker.prototype.getDrawer = function() { return this.drawer_; }; @@ -74,7 +75,7 @@ Blockly.Marker.prototype.getDrawer = function() { * @return {Blockly.ASTNode} The current field, connection, or block the marker * is on. */ -Blockly.Marker.prototype.getCurNode = function() { +Marker.prototype.getCurNode = function() { return this.curNode_; }; @@ -84,7 +85,7 @@ Blockly.Marker.prototype.getCurNode = function() { * output or previous connection on a stack. * @param {Blockly.ASTNode} newNode The new location of the marker. */ -Blockly.Marker.prototype.setCurNode = function(newNode) { +Marker.prototype.setCurNode = function(newNode) { const oldNode = this.curNode_; this.curNode_ = newNode; if (this.drawer_) { @@ -96,7 +97,7 @@ Blockly.Marker.prototype.setCurNode = function(newNode) { * Redraw the current marker. * @package */ -Blockly.Marker.prototype.draw = function() { +Marker.prototype.draw = function() { if (this.drawer_) { this.drawer_.draw(this.curNode_, this.curNode_); } @@ -105,7 +106,7 @@ Blockly.Marker.prototype.draw = function() { /** * Hide the marker SVG. */ -Blockly.Marker.prototype.hide = function() { +Marker.prototype.hide = function() { if (this.drawer_) { this.drawer_.hide(); } @@ -114,8 +115,10 @@ Blockly.Marker.prototype.hide = function() { /** * Dispose of this marker. */ -Blockly.Marker.prototype.dispose = function() { +Marker.prototype.dispose = function() { if (this.getDrawer()) { this.getDrawer().dispose(); } }; + +exports = Marker; diff --git a/tests/deps.js b/tests/deps.js index 759caeae4..8d3102c14 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -105,7 +105,7 @@ goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstan goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'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': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); +goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode'], {'lang': 'es6', 'module': 'goog'}); 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'], [], {'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'}); From 50f7293f2d4b16eda5c72cf3e4d9e1c275991d5e Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:34:35 -0700 Subject: [PATCH 050/291] Migrate core/keyboard_nav/marker.js named requires --- core/keyboard_nav/marker.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index 115a1f861..28f905949 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -14,9 +14,8 @@ goog.module('Blockly.Marker'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); - -goog.requireType('Blockly.blockRendering.MarkerSvg'); +const ASTNode = goog.require('Blockly.ASTNode'); +const MarkerSvg = goog.requireType('Blockly.blockRendering.MarkerSvg'); /** @@ -33,14 +32,14 @@ const Marker = function() { /** * The current location of the marker. - * @type {Blockly.ASTNode} + * @type {ASTNode} * @private */ this.curNode_ = null; /** * The object in charge of drawing the visual representation of the current node. - * @type {Blockly.blockRendering.MarkerSvg} + * @type {MarkerSvg} * @private */ this.drawer_ = null; @@ -54,7 +53,7 @@ const Marker = function() { /** * Sets the object in charge of drawing the marker. - * @param {Blockly.blockRendering.MarkerSvg} drawer The object in charge of + * @param {MarkerSvg} drawer The object in charge of * drawing the marker. */ Marker.prototype.setDrawer = function(drawer) { @@ -63,7 +62,7 @@ Marker.prototype.setDrawer = function(drawer) { /** * Get the current drawer for the marker. - * @return {Blockly.blockRendering.MarkerSvg} The object in charge of drawing + * @return {MarkerSvg} The object in charge of drawing * the marker. */ Marker.prototype.getDrawer = function() { @@ -72,7 +71,7 @@ Marker.prototype.getDrawer = function() { /** * Gets the current location of the marker. - * @return {Blockly.ASTNode} The current field, connection, or block the marker + * @return {ASTNode} The current field, connection, or block the marker * is on. */ Marker.prototype.getCurNode = function() { @@ -83,7 +82,7 @@ Marker.prototype.getCurNode = function() { * Set the location of the marker and call the update method. * Setting isStack to true will only work if the newLocation is the top most * output or previous connection on a stack. - * @param {Blockly.ASTNode} newNode The new location of the marker. + * @param {ASTNode} newNode The new location of the marker. */ Marker.prototype.setCurNode = function(newNode) { const oldNode = this.curNode_; From 1a83b7584680f48a226d40cc87780d50eeec127c Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:34:44 -0700 Subject: [PATCH 051/291] clang-format core/keyboard_nav/marker.js --- core/keyboard_nav/marker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index 28f905949..654703f7b 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -38,7 +38,8 @@ const Marker = function() { this.curNode_ = null; /** - * The object in charge of drawing the visual representation of the current node. + * The object in charge of drawing the visual representation of the current + * node. * @type {MarkerSvg} * @private */ From 667048b3f52262e8f1e0ff3c78a0bf411b20be4d Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 19:29:17 -0700 Subject: [PATCH 052/291] Add eslint disable and make ASTNode a requireType --- core/keyboard_nav/marker.js | 4 +++- tests/deps.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index 654703f7b..4b6f341bb 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -14,7 +14,9 @@ goog.module('Blockly.Marker'); goog.module.declareLegacyNamespace(); -const ASTNode = goog.require('Blockly.ASTNode'); +/* eslint-disable-next-line no-unused-vars */ +const ASTNode = goog.requireType('Blockly.ASTNode'); +/* eslint-disable-next-line no-unused-vars */ const MarkerSvg = goog.requireType('Blockly.blockRendering.MarkerSvg'); diff --git a/tests/deps.js b/tests/deps.js index 8d3102c14..6666e9369 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -105,7 +105,7 @@ goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstan goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'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': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], [], {'lang': 'es6', 'module': 'goog'}); 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'], [], {'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'}); From 961254663d1a0347e664638c077af54d3fbc6002 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 28 Jul 2021 11:57:24 -0700 Subject: [PATCH 053/291] Move clipboard functions to a separate namespace --- core/blockly.js | 50 ++---------- core/clipboard.js | 106 ++++++++++++++++++++++++++ core/contextmenu_items.js | 4 +- core/shortcut_items.js | 7 +- tests/deps.js | 7 +- tests/mocha/contextmenu_items_test.js | 10 +-- tests/mocha/keydown_test.js | 2 +- 7 files changed, 129 insertions(+), 57 deletions(-) create mode 100644 core/clipboard.js diff --git a/core/blockly.js b/core/blockly.js index 94f485c99..808c035b0 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -17,6 +17,7 @@ goog.provide('Blockly'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.clipboard'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); @@ -96,21 +97,21 @@ Blockly.draggingConnections = []; * @type {Element} * @private */ -Blockly.clipboardXml_ = null; +Blockly.clipboardXml_ = Blockly.clipboard.xml; /** * Source of the local clipboard. * @type {Blockly.WorkspaceSvg} * @private */ -Blockly.clipboardSource_ = null; +Blockly.clipboardSource_ = Blockly.clipboard.source; /** * Map of types to type counts for the clipboard object and descendants. * @type {Object} * @private */ -Blockly.clipboardTypeCounts_ = null; +Blockly.clipboardTypeCounts_ = Blockly.clipboard.typeCounts; /** * Cached value for whether 3D is supported. @@ -234,39 +235,14 @@ Blockly.deleteBlock = function(selected) { * @param {!Blockly.ICopyable} toCopy Block or Workspace Comment to be copied. * @package */ -Blockly.copy = function(toCopy) { - var data = toCopy.toCopyData(); - if (data) { - Blockly.clipboardXml_ = data.xml; - Blockly.clipboardSource_ = data.source; - Blockly.clipboardTypeCounts_ = data.typeCounts; - } -}; +Blockly.copy = Blockly.clipboard.copy; /** * Paste a block or workspace comment on to the main workspace. * @return {boolean} True if the paste was successful, false otherwise. * @package */ -Blockly.paste = function() { - if (!Blockly.clipboardXml_) { - return false; - } - // Pasting always pastes to the main workspace, even if the copy - // started in a flyout workspace. - var workspace = Blockly.clipboardSource_; - if (workspace.isFlyout) { - workspace = workspace.targetWorkspace; - } - if (Blockly.clipboardTypeCounts_ && - workspace.isCapacityAvailable(Blockly.clipboardTypeCounts_)) { - Blockly.Events.setGroup(true); - workspace.paste(Blockly.clipboardXml_); - Blockly.Events.setGroup(false); - return true; - } - return false; -}; +Blockly.paste = Blockly.clipboard.paste; /** * Duplicate this block and its children, or a workspace comment. @@ -274,19 +250,7 @@ Blockly.paste = function() { * copied. * @package */ -Blockly.duplicate = function(toDuplicate) { - // Save the clipboard. - var clipboardXml = Blockly.clipboardXml_; - var clipboardSource = Blockly.clipboardSource_; - - // Create a duplicate via a copy/paste operation. - Blockly.copy(toDuplicate); - toDuplicate.workspace.paste(Blockly.clipboardXml_); - - // Restore the clipboard. - Blockly.clipboardXml_ = clipboardXml; - Blockly.clipboardSource_ = clipboardSource; -}; +Blockly.duplicate = Blockly.clipboard.duplicate; /** * Cancel the native context menu, unless the focus is on an HTML input widget. diff --git a/core/clipboard.js b/core/clipboard.js new file mode 100644 index 000000000..887346a58 --- /dev/null +++ b/core/clipboard.js @@ -0,0 +1,106 @@ +/** + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Blockly's internal clipboard for managing copy-paste. + * @author fenichel@google.com (Rachel Fenichel) + */ +'use strict'; + +goog.module('Blockly.clipboard'); +goog.module.declareLegacyNamespace(); + +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const ICopyable = goog.requireType('Blockly.ICopyable'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); + + +/** + * Contents of the local clipboard. + * @type {Element} + * @private + */ +let xml = null; +exports.xml = xml; + +/** + * Source of the local clipboard. + * @type {WorkspaceSvg} + * @private + */ +let source = null; +exports.source = source; + +/** + * Map of types to type counts for the clipboard object and descendants. + * @type {Object} + * @private + */ +let typeCounts = null; +exports.typeCounts = typeCounts; + +/** + * Copy a block or workspace comment onto the local clipboard. + * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. + * @package + */ +const copy = function(toCopy) { + var data = toCopy.toCopyData(); + if (data) { + xml = data.xml; + source = data.source; + typeCounts = data.typeCounts; + } +}; +exports.copy = copy; + +/** + * Paste a block or workspace comment on to the main workspace. + * @return {boolean} True if the paste was successful, false otherwise. + * @package + */ +const paste = function() { + if (!xml) { + return false; + } + // Pasting always pastes to the main workspace, even if the copy + // started in a flyout workspace. + var workspace = source; + if (workspace.isFlyout) { + workspace = workspace.targetWorkspace; + } + if (typeCounts && workspace.isCapacityAvailable(typeCounts)) { + Events.setGroup(true); + workspace.paste(xml); + Events.setGroup(false); + return true; + } + return false; +}; +exports.paste = paste; + +/** + * Duplicate this block and its children, or a workspace comment. + * @param {!ICopyable} toDuplicate Block or Workspace Comment to be + * copied. + * @package + */ +const duplicate = function(toDuplicate) { + // Save the clipboard. + const oldXml = xml; + const oldSource = source; + + // Create a duplicate via a copy/paste operation. + copy(toDuplicate); + toDuplicate.workspace.paste(xml); + + // Restore the clipboard. + xml = oldXml; + source = oldSource; +}; +exports.duplicate = duplicate; diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index dffd4a83d..e985a8e5c 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -15,7 +15,7 @@ * @namespace */ goog.provide('Blockly.ContextMenuItems'); - +goog.require('Blockly.clipboard'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.ContextMenuRegistry'); @@ -316,7 +316,7 @@ Blockly.ContextMenuItems.registerDuplicate = function() { }, callback: function(/** @type {!Blockly.ContextMenuRegistry.Scope} */ scope) { if (scope.block) { - Blockly.duplicate(scope.block); + Blockly.clipboard.duplicate(scope.block); } }, scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK, diff --git a/core/shortcut_items.js b/core/shortcut_items.js index ef1cb07fc..494b64bfe 100644 --- a/core/shortcut_items.js +++ b/core/shortcut_items.js @@ -16,6 +16,7 @@ */ goog.provide('Blockly.ShortcutItems'); +goog.require('Blockly.clipboard'); goog.require('Blockly.Gesture'); goog.require('Blockly.ShortcutRegistry'); goog.require('Blockly.utils.KeyCodes'); @@ -104,7 +105,7 @@ Blockly.ShortcutItems.registerCopy = function() { // an error due to the lack of a selection. e.preventDefault(); Blockly.hideChaff(); - Blockly.copy(/** @type {!Blockly.ICopyable} */ (Blockly.selected)); + Blockly.clipboard.copy(/** @type {!Blockly.ICopyable} */ (Blockly.selected)); return true; } }; @@ -137,7 +138,7 @@ Blockly.ShortcutItems.registerCut = function() { !Blockly.selected.workspace.isFlyout; }, callback: function() { - Blockly.copy(/** @type {!Blockly.ICopyable} */ (Blockly.selected)); + Blockly.clipboard.copy(/** @type {!Blockly.ICopyable} */ (Blockly.selected)); Blockly.deleteBlock(/** @type {!Blockly.BlockSvg} */ (Blockly.selected)); return true; } @@ -167,7 +168,7 @@ Blockly.ShortcutItems.registerPaste = function() { return !workspace.options.readOnly && !Blockly.Gesture.inProgress(); }, callback: function() { - return Blockly.paste(); + return Blockly.clipboard.paste(); } }; diff --git a/tests/deps.js b/tests/deps.js index b28f86da2..44b852995 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -12,11 +12,12 @@ 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.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/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.clipboard', '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']); 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/clipboard.js', ['Blockly.clipboard'], ['Blockly.Events'], {'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'], {'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'}); @@ -25,7 +26,7 @@ goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Bl 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.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_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.clipboard', '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', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); @@ -159,7 +160,7 @@ goog.addDependency('../../core/renderers/zelos/path_object.js', ['Blockly.zelos. 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']); +goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.clipboard', 'Blockly.utils.KeyCodes']); 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']); diff --git a/tests/mocha/contextmenu_items_test.js b/tests/mocha/contextmenu_items_test.js index 62dd6f9ea..0d69fa77e 100644 --- a/tests/mocha/contextmenu_items_test.js +++ b/tests/mocha/contextmenu_items_test.js @@ -17,11 +17,11 @@ suite('Context Menu Items', function() { Blockly.ContextMenuItems.registerDefaultOptions(); this.registry = Blockly.ContextMenuRegistry.registry; }); - + teardown(function() { sharedTestTeardown.call(this); }); - + suite('Workspace Items', function() { setup(function() { this.scope = {workspace: this.workspace}; @@ -328,12 +328,12 @@ suite('Context Menu Items', function() { }); test('Calls duplicate', function() { - var stub = sinon.stub(Blockly, 'duplicate'); + var spy = sinon.spy(Blockly.clipboard, 'duplicate'); this.duplicateOption.callback(this.scope); - sinon.assert.calledOnce(stub); - sinon.assert.calledWith(stub, this.block); + sinon.assert.calledOnce(spy); + sinon.assert.calledWith(spy, this.block); }); test('Has correct label', function() { diff --git a/tests/mocha/keydown_test.js b/tests/mocha/keydown_test.js index aec646111..22fdbf96e 100644 --- a/tests/mocha/keydown_test.js +++ b/tests/mocha/keydown_test.js @@ -93,7 +93,7 @@ suite('Key Down', function() { suite('Copy', function() { setup(function() { setSelectedBlock(this.workspace); - this.copySpy = sinon.spy(Blockly, 'copy'); + this.copySpy = sinon.spy(Blockly.clipboard, 'copy'); this.hideChaffSpy = sinon.spy(Blockly, 'hideChaff'); }); var testCases = [ From 311373230fed2adb4cdfd103a87d412902f574e3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 28 Jul 2021 14:48:08 -0700 Subject: [PATCH 054/291] Fix help log --- scripts/goog_module/convert-file.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index ebf791d3b..a412a7933 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -312,8 +312,8 @@ help() { echo "" 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]" + echo " -c Create a commit for the specified step [1-4]" + echo " -s Run the specified step [2-4]" } ####################################### From 87a714fff8d10073f813a9afce8aceda6060c2f9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 28 Jul 2021 14:47:25 -0700 Subject: [PATCH 055/291] Add handling for modules that are not leaf nodes --- scripts/goog_module/convert-file.sh | 85 ++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index a412a7933..1c5b92fc8 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -125,6 +125,59 @@ commit-step() { success "created commit with message: \"${message}\"" } +####################################### +# Extracts a list of properties that are accessed on the specified module name. +# Excludes any matches +# Arguments: +# The module name to find properties accessed for. +# The modules required by the specified module as a single string. +# The filepath to extract requires from. +# Optional: The top-level module. +# Outputs: +# Writes list of properties to stdout as items separated by spaces. +####################################### +getPropertiesAccessed() { + local module_name="$1" + local requires="$2" + local filepath="$3" + local top_module_name="$4" + # Get any strings that follow "$module_name.", excluding matches for + # "$module_name.prototype" and remove list item duplicates (sort -u). + local properties_accessed=$(perl -nle 'print $& while m{(?<='"${module_name}"'\.)(?!prototype)\w+}g' "${filepath}" | sort -u) + + # Get a list of any requires that are a child of $module_name. + # Ex: Blockly.utils.dom is a child of Blockly.utils, this would return "dom" + local requires_overlap=$(echo "${requires}" | perl -nle 'print $& while m{(?<='"${module_name}"'\.)\w+}g') + # Detect if there was any overlap. + 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 + + # Fix formatting (remove extra whitespace) and delimit the list with spaces. + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) + + echo "${properties_accessed}" +} + +####################################### +# Extracts a list of requires defined in the file in the form of a single string +# of items separated by newlines. +# Arguments: +# The filepath to extract requires from. +# Outputs: +# Writes list of requires to stdout as items separated by newlines. +####################################### +getRequires() { + local filepath="$1" + # Extracts all strings that start with goog.require(' or goog.requireType(' + # up until the ending single quote. + # Ex: "goog.require('Blockly.utils')" would extract "Blockly.utils" + local requires=$(perl -nle 'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") + echo "${requires}" +} + ####################################### # Runs step 2 of the automated conversion. # Arguments: @@ -166,8 +219,18 @@ step2 () { # No top level class. inf 'Updating top-level property declarations...' perl -pi -e 's/^'"${module_name}"'\.([^ ]+) =/const \1 =/g' "${filepath}" + + # Extract specific properties accessed so that properties from requires that + # are children of the module aren't changed. + # Ex: The module Blockly.utils shouldn't update Blockly.utils.dom (since it is + # a require from another module. + local requires=$(getRequires "${filepath}") + local properties_accessed=$(getPropertiesAccessed "${module_name}" "${requires}" "${filepath}") inf "Updating local references to module..." - perl -pi -e 's/'"${module_name}"'\.([^ ]+)/\1/g' "${filepath}" + for property in $(echo "${properties_accessed}"); do + inf "Updating references of ${module_name}.${property} to ${property}..." + perl -pi -e 's/'"${module_name}"'\.'"${property}"'(?!\w)/'"${property}"'/g' "${filepath}" + done npm run build:deps success "Completed automation for step 2. Please manually review and add exports for non-private top-level functions." @@ -187,7 +250,7 @@ step3() { fi inf "Extracted module name \"${module_name}\"" - local requires=$(perl -nle 'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") + local requires=$(getRequires "${filepath}") # Process each require echo "${requires}" | while read -r require; do @@ -205,23 +268,17 @@ step3() { # 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}" | sort -u) + local properties_accessed=$(getPropertiesAccessed "${require}" "${requires}" "${filepath}") - # 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 [[ -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) + # Remove $module_name in case it is a child of $require. + # Ex: Blockly.utils.dom would be a child of Blockly, module_overlap would be + # "utils" 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') + # Trim any extra whitespace created. + properties_accessed=$(echo "${properties_accessed}" | xargs) fi - properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) if [[ -n "${properties_accessed}" ]]; then local comma_properties=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') From 8372ecb2125e75e35ec532fa40b46fa4f10fb34d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:05:40 -0700 Subject: [PATCH 056/291] Include full namespace in error message --- core/registry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/registry.js b/core/registry.js index 1be9b2a2b..5752702ae 100644 --- a/core/registry.js +++ b/core/registry.js @@ -137,7 +137,7 @@ const register = function(type, name, registryItem, opt_allowOverrides) { String(type).trim() == '') { throw Error( 'Invalid type "' + type + '". The type must be a' + - ' non-empty string or a Type.'); + ' non-empty string or a Blockly.registry.Type.'); } type = String(type).toLowerCase(); From 0f193f1f5a9c502824fb7987f494062ee39ca1cf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:17:57 -0700 Subject: [PATCH 057/291] Migrate core/trashcan.js to ES6 const/let --- core/trashcan.js | 62 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index 619299b21..dea20acd2 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -80,7 +80,7 @@ Blockly.Trashcan = function(workspace) { return; } // Create flyout options. - var flyoutWorkspaceOptions = new Blockly.Options( + const flyoutWorkspaceOptions = new Blockly.Options( /** @type {!Blockly.BlocklyOptions} */ ({ 'scrollbars': true, @@ -98,7 +98,7 @@ Blockly.Trashcan = function(workspace) { flyoutWorkspaceOptions.toolboxPosition = this.workspace_.toolboxPosition == Blockly.utils.toolbox.Position.TOP ? Blockly.utils.toolbox.Position.BOTTOM : Blockly.utils.toolbox.Position.TOP; - var HorizontalFlyout = Blockly.registry.getClassFromOptions( + const HorizontalFlyout = Blockly.registry.getClassFromOptions( Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, this.workspace_.options, true); this.flyout = new HorizontalFlyout(flyoutWorkspaceOptions); @@ -106,7 +106,7 @@ Blockly.Trashcan = function(workspace) { flyoutWorkspaceOptions.toolboxPosition = this.workspace_.toolboxPosition == Blockly.utils.toolbox.Position.RIGHT ? Blockly.utils.toolbox.Position.LEFT : Blockly.utils.toolbox.Position.RIGHT; - var VerticalFlyout = Blockly.registry.getClassFromOptions( + const VerticalFlyout = Blockly.registry.getClassFromOptions( Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX, this.workspace_.options, true); this.flyout = new VerticalFlyout(flyoutWorkspaceOptions); @@ -300,8 +300,8 @@ Blockly.Trashcan.prototype.createDom = function() { this.svgGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyTrash'}, null); - var clip; - var rnd = String(Math.random()).substring(2); + let clip; + const rnd = String(Math.random()).substring(2); clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, {'id': 'blocklyTrashBodyClipPath' + rnd}, @@ -314,7 +314,7 @@ Blockly.Trashcan.prototype.createDom = function() { 'y': this.LID_HEIGHT_ }, clip); - var body = Blockly.utils.dom.createSvgElement( + const body = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'x': -this.SPRITE_LEFT_, @@ -427,7 +427,7 @@ Blockly.Trashcan.prototype.openFlyout = function() { if (this.contentsIsOpen()) { return; } - var xml = this.contents_.map(Blockly.Xml.textToDom); + const xml = this.contents_.map(Blockly.Xml.textToDom); this.flyout.show(xml); this.fireUiEvent_(true); }; @@ -483,20 +483,20 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { return; } - var cornerPosition = + const cornerPosition = Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); - var height = this.BODY_HEIGHT_ + this.LID_HEIGHT_; - var startRect = Blockly.uiPosition.getStartPositionRect( + const height = this.BODY_HEIGHT_ + this.LID_HEIGHT_; + 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); this.top_ = positionRect.top; @@ -512,8 +512,8 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { * bounding box should be ignored by other UI elements. */ Blockly.Trashcan.prototype.getBoundingRectangle = function() { - var bottom = this.top_ + this.BODY_HEIGHT_ + this.LID_HEIGHT_; - var right = this.left_ + this.WIDTH_; + const bottom = this.top_ + this.BODY_HEIGHT_ + this.LID_HEIGHT_; + const right = this.left_ + this.WIDTH_; return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); }; @@ -528,12 +528,12 @@ Blockly.Trashcan.prototype.getClientRect = function() { return null; } - var trashRect = this.svgGroup_.getBoundingClientRect(); - var top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_; - var bottom = top + this.LID_HEIGHT_ + this.BODY_HEIGHT_ + + const trashRect = this.svgGroup_.getBoundingClientRect(); + const top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_; + const bottom = top + this.LID_HEIGHT_ + this.BODY_HEIGHT_ + 2 * this.MARGIN_HOTSPOT_; - var left = trashRect.left + this.SPRITE_LEFT_ - this.MARGIN_HOTSPOT_; - var right = left + this.WIDTH_ + 2 * this.MARGIN_HOTSPOT_; + const left = trashRect.left + this.SPRITE_LEFT_ - this.MARGIN_HOTSPOT_; + const right = left + this.WIDTH_ + 2 * this.MARGIN_HOTSPOT_; return new Blockly.utils.Rect(top, bottom, left, right); }; @@ -588,18 +588,18 @@ Blockly.Trashcan.prototype.setLidOpen = function(state) { * @private */ Blockly.Trashcan.prototype.animateLid_ = function() { - var frames = Blockly.Trashcan.ANIMATION_FRAMES_; + const frames = Blockly.Trashcan.ANIMATION_FRAMES_; - var delta = 1 / (frames + 1); + const delta = 1 / (frames + 1); this.lidOpen_ += this.isLidOpen ? delta : -delta; this.lidOpen_ = Math.min(Math.max(this.lidOpen_, this.minOpenness_), 1); this.setLidAngle_(this.lidOpen_ * Blockly.Trashcan.MAX_LID_ANGLE_); - var minOpacity = Blockly.Trashcan.OPACITY_MIN_; - var maxOpacity = Blockly.Trashcan.OPACITY_MAX_; + const minOpacity = Blockly.Trashcan.OPACITY_MIN_; + const maxOpacity = Blockly.Trashcan.OPACITY_MAX_; // Linear interpolation between min and max. - var opacity = minOpacity + this.lidOpen_ * (maxOpacity - minOpacity); + const opacity = minOpacity + this.lidOpen_ * (maxOpacity - minOpacity); this.svgGroup_.style.opacity = opacity; if (this.lidOpen_ > this.minOpenness_ && this.lidOpen_ < 1) { @@ -614,7 +614,7 @@ Blockly.Trashcan.prototype.animateLid_ = function() { * @private */ Blockly.Trashcan.prototype.setLidAngle_ = function(lidAngle) { - var openAtRight = + const openAtRight = this.workspace_.toolboxPosition == Blockly.utils.toolbox.Position.RIGHT || (this.workspace_.horizontalLayout && this.workspace_.RTL); this.svgLid_.setAttribute('transform', 'rotate(' + @@ -661,7 +661,7 @@ Blockly.Trashcan.prototype.click = function() { * @private */ Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { - var uiEvent = new (Blockly.Events.get(Blockly.Events.TRASHCAN_OPEN))( + const uiEvent = new (Blockly.Events.get(Blockly.Events.TRASHCAN_OPEN))( trashcanOpen,this.workspace_.id); Blockly.Events.fire(uiEvent); }; @@ -710,7 +710,7 @@ Blockly.Trashcan.prototype.onDelete_ = function(event) { // Must check that the tagName exists since oldXml can be a DocumentFragment. if (event.type == Blockly.Events.BLOCK_DELETE && event.oldXml.tagName && event.oldXml.tagName.toLowerCase() != 'shadow') { - var cleanedXML = this.cleanBlockXML_(event.oldXml); + const cleanedXML = this.cleanBlockXML_(event.oldXml); if (this.contents_.indexOf(cleanedXML) != -1) { return; } @@ -734,8 +734,8 @@ Blockly.Trashcan.prototype.onDelete_ = function(event) { * @private */ Blockly.Trashcan.prototype.cleanBlockXML_ = function(xml) { - var xmlBlock = xml.cloneNode(true); - var node = xmlBlock; + const xmlBlock = xml.cloneNode(true); + let node = xmlBlock; while (node) { // Things like text inside tags are still treated as nodes, but they // don't have attributes (or the removeAttribute function) so we can @@ -753,7 +753,7 @@ Blockly.Trashcan.prototype.cleanBlockXML_ = function(xml) { } // Try to go down the tree - var nextNode = node.firstChild || node.nextSibling; + let nextNode = node.firstChild || node.nextSibling; // If we can't go down, try to go back up the tree. if (!nextNode) { nextNode = node.parentNode; From 1d9c9359f959d931668ef625ad0a7bdb36fc74cb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:30:44 -0700 Subject: [PATCH 058/291] Migrate core/variable_map.js to ES6 const/let --- core/variable_map.js | 98 ++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/core/variable_map.js b/core/variable_map.js index 34fa926ec..3cbe5d561 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -66,9 +66,9 @@ Blockly.VariableMap.prototype.clear = function() { * @package */ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { - var type = variable.type; - var conflictVar = this.getVariable(newName, type); - var blocks = this.workspace.getAllBlocks(false); + const type = variable.type; + const conflictVar = this.getVariable(newName, type); + const blocks = this.workspace.getAllBlocks(false); Blockly.Events.setGroup(true); try { // The IDs may match if the rename is a simple case change (name1 -> Name1). @@ -89,7 +89,7 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { * @param {string} newName New variable name. */ Blockly.VariableMap.prototype.renameVariableById = function(id, newName) { - var variable = this.getVariableById(id); + const variable = this.getVariableById(id); if (!variable) { throw Error('Tried to rename a variable that didn\'t exist. ID: ' + id); } @@ -111,7 +111,7 @@ Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_RENAME))( variable, newName)); variable.name = newName; - for (var i = 0; i < blocks.length; i++) { + for (let i = 0; i < blocks.length; i++) { blocks[i].updateVarName(variable); } }; @@ -131,8 +131,8 @@ Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, */ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, newName, conflictVar, blocks) { - var type = variable.type; - var oldCase = conflictVar.name; + const type = variable.type; + const oldCase = conflictVar.name; if (newName != oldCase) { // Simple rename to change the case and update references. @@ -141,7 +141,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, // These blocks now refer to a different variable. // These will fire change events. - for (var i = 0; i < blocks.length; i++) { + for (let i = 0; i < blocks.length; i++) { blocks[i].renameVarById(variable.getId(), conflictVar.getId()); } @@ -149,8 +149,8 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( variable)); // And remove it from the list. - var variableList = this.getVariablesOfType(type); - var variableIndex = variableList.indexOf(variable); + const variableList = this.getVariablesOfType(type); + const variableIndex = variableList.indexOf(variable); this.variableMap_[type].splice(variableIndex, 1); }; @@ -170,7 +170,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, */ Blockly.VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { - var variable = this.getVariable(name, opt_type); + let variable = this.getVariable(name, opt_type); if (variable) { if (opt_id && variable.getId() != opt_id) { throw Error('Variable "' + name + '" is already in use and its id is "' + @@ -183,11 +183,11 @@ Blockly.VariableMap.prototype.createVariable = function(name, if (opt_id && this.getVariableById(opt_id)) { throw Error('Variable id, "' + opt_id + '", is already in use.'); } - var id = opt_id || Blockly.utils.genUid(); - var type = opt_type || ''; + const id = opt_id || Blockly.utils.genUid(); + const type = opt_type || ''; variable = new Blockly.VariableModel(this.workspace, name, type, id); - var variables = this.variableMap_[type] || []; + const variables = this.variableMap_[type] || []; variables.push(variable); // Delete the list of variables of this type, and re-add it so that // the most recent addition is at the end. @@ -205,8 +205,8 @@ Blockly.VariableMap.prototype.createVariable = function(name, * @param {!Blockly.VariableModel} variable Variable to delete. */ Blockly.VariableMap.prototype.deleteVariable = function(variable) { - var variableList = this.variableMap_[variable.type]; - for (var i = 0, tempVar; (tempVar = variableList[i]); i++) { + const variableList = this.variableMap_[variable.type]; + for (let i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { variableList.splice(i, 1); Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( @@ -222,16 +222,16 @@ Blockly.VariableMap.prototype.deleteVariable = function(variable) { * @param {string} id ID of variable to delete. */ Blockly.VariableMap.prototype.deleteVariableById = function(id) { - var variable = this.getVariableById(id); + const variable = this.getVariableById(id); if (variable) { // Check whether this variable is a function parameter before deleting. - var variableName = variable.name; - var uses = this.getVariableUsesById(id); - for (var i = 0, block; (block = uses[i]); i++) { + const variableName = variable.name; + const uses = this.getVariableUsesById(id); + for (let i = 0, block; (block = uses[i]); i++) { if (block.type == 'procedures_defnoreturn' || block.type == 'procedures_defreturn') { - var procedureName = block.getFieldValue('NAME'); - var deleteText = Blockly.Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. + const procedureName = block.getFieldValue('NAME'); + const deleteText = Blockly.Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. replace('%1', variableName). replace('%2', procedureName); Blockly.alert(deleteText); @@ -239,10 +239,10 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) { } } - var map = this; + const map = this; if (uses.length > 1) { // Confirm before deleting multiple blocks. - var confirmText = Blockly.Msg['DELETE_VARIABLE_CONFIRMATION']. + const confirmText = Blockly.Msg['DELETE_VARIABLE_CONFIRMATION']. replace('%1', String(uses.length)). replace('%2', variableName); Blockly.confirm(confirmText, @@ -269,12 +269,12 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) { */ Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, uses) { - var existingGroup = Blockly.Events.getGroup(); + const existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { Blockly.Events.setGroup(true); } try { - for (var i = 0; i < uses.length; i++) { + for (let i = 0; i < uses.length; i++) { uses[i].dispose(true); } this.deleteVariable(variable); @@ -297,10 +297,10 @@ Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, * it was not found. */ Blockly.VariableMap.prototype.getVariable = function(name, opt_type) { - var type = opt_type || ''; - var list = this.variableMap_[type]; + const type = opt_type || ''; + const list = this.variableMap_[type]; if (list) { - for (var j = 0, variable; (variable = list[j]); j++) { + for (let j = 0, variable; (variable = list[j]); j++) { if (Blockly.Names.equals(variable.name, name)) { return variable; } @@ -315,10 +315,10 @@ Blockly.VariableMap.prototype.getVariable = function(name, opt_type) { * @return {?Blockly.VariableModel} The variable with the given ID. */ Blockly.VariableMap.prototype.getVariableById = function(id) { - var keys = Object.keys(this.variableMap_); - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - for (var j = 0, variable; (variable = this.variableMap_[key][j]); j++) { + const keys = Object.keys(this.variableMap_); + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + for (let j = 0, variable; (variable = this.variableMap_[key][j]); j++) { if (variable.getId() == id) { return variable; } @@ -336,7 +336,7 @@ Blockly.VariableMap.prototype.getVariableById = function(id) { */ Blockly.VariableMap.prototype.getVariablesOfType = function(type) { type = type || ''; - var variable_list = this.variableMap_[type]; + const variable_list = this.variableMap_[type]; if (variable_list) { return variable_list.slice(); } @@ -353,15 +353,15 @@ Blockly.VariableMap.prototype.getVariablesOfType = function(type) { * @package */ Blockly.VariableMap.prototype.getVariableTypes = function(ws) { - var variableMap = {}; + const variableMap = {}; Blockly.utils.object.mixin(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { Blockly.utils.object.mixin(variableMap, ws.getPotentialVariableMap().variableMap_); } - var types = Object.keys(variableMap); - var hasEmpty = false; - for (var i = 0; i < types.length; i++) { + const types = Object.keys(variableMap); + let hasEmpty = false; + for (let i = 0; i < types.length; i++) { if (types[i] == '') { hasEmpty = true; } @@ -377,8 +377,8 @@ Blockly.VariableMap.prototype.getVariableTypes = function(ws) { * @return {!Array} List of variable models. */ Blockly.VariableMap.prototype.getAllVariables = function() { - var all_variables = []; - for (var key in this.variableMap_) { + let all_variables = []; + for (const key in this.variableMap_) { all_variables = all_variables.concat(this.variableMap_[key]); } return all_variables; @@ -389,10 +389,10 @@ Blockly.VariableMap.prototype.getAllVariables = function() { * @return {!Array} All of the variable names of all types. */ Blockly.VariableMap.prototype.getAllVariableNames = function() { - var allNames = []; - for (var key in this.variableMap_) { - var variables = this.variableMap_[key]; - for (var i = 0, variable; (variable = variables[i]); i++) { + const allNames = []; + for (const key in this.variableMap_) { + const variables = this.variableMap_[key]; + for (let i = 0, variable; (variable = variables[i]); i++) { allNames.push(variable.name); } } @@ -405,13 +405,13 @@ Blockly.VariableMap.prototype.getAllVariableNames = function() { * @return {!Array} Array of block usages. */ Blockly.VariableMap.prototype.getVariableUsesById = function(id) { - var uses = []; - var blocks = this.workspace.getAllBlocks(false); + const uses = []; + const blocks = this.workspace.getAllBlocks(false); // Iterate through every block and check the name. - for (var i = 0; i < blocks.length; i++) { - var blockVariables = blocks[i].getVarModels(); + for (let i = 0; i < blocks.length; i++) { + const blockVariables = blocks[i].getVarModels(); if (blockVariables) { - for (var j = 0; j < blockVariables.length; j++) { + for (let j = 0; j < blockVariables.length; j++) { if (blockVariables[j].getId() == id) { uses.push(blocks[i]); } From 959d976723edc29c9caecfdb648c7975b0d39f64 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:34:37 -0700 Subject: [PATCH 059/291] Migrate core/variable_map.js to goog.module --- core/variable_map.js | 39 +++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/variable_map.js b/core/variable_map.js index 3cbe5d561..22eb11c9c 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.VariableMap'); +goog.module('Blockly.VariableMap'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -33,7 +34,7 @@ goog.requireType('Blockly.Workspace'); * @param {!Blockly.Workspace} workspace The workspace this map belongs to. * @constructor */ -Blockly.VariableMap = function(workspace) { +const VariableMap = function(workspace) { /** * A map from variable type to list of variable names. The lists contain all * of the named variables in the workspace, including variables @@ -53,7 +54,7 @@ Blockly.VariableMap = function(workspace) { /** * Clear the variable map. */ -Blockly.VariableMap.prototype.clear = function() { +VariableMap.prototype.clear = function() { this.variableMap_ = Object.create(null); }; @@ -65,7 +66,7 @@ Blockly.VariableMap.prototype.clear = function() { * @param {string} newName New variable name. * @package */ -Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { +VariableMap.prototype.renameVariable = function(variable, newName) { const type = variable.type; const conflictVar = this.getVariable(newName, type); const blocks = this.workspace.getAllBlocks(false); @@ -88,7 +89,7 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { * @param {string} id ID of the variable to rename. * @param {string} newName New variable name. */ -Blockly.VariableMap.prototype.renameVariableById = function(id, newName) { +VariableMap.prototype.renameVariableById = function(id, newName) { const variable = this.getVariableById(id); if (!variable) { throw Error('Tried to rename a variable that didn\'t exist. ID: ' + id); @@ -106,7 +107,7 @@ Blockly.VariableMap.prototype.renameVariableById = function(id, newName) { * workspace. * @private */ -Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, +VariableMap.prototype.renameVariableAndUses_ = function(variable, newName, blocks) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_RENAME))( variable, newName)); @@ -129,7 +130,7 @@ Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, * workspace. * @private */ -Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, +VariableMap.prototype.renameVariableWithConflict_ = function(variable, newName, conflictVar, blocks) { const type = variable.type; const oldCase = conflictVar.name; @@ -168,7 +169,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, * a UUID. * @return {!Blockly.VariableModel} The newly created variable. */ -Blockly.VariableMap.prototype.createVariable = function(name, +VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { let variable = this.getVariable(name, opt_type); if (variable) { @@ -204,7 +205,7 @@ Blockly.VariableMap.prototype.createVariable = function(name, * Delete a variable. * @param {!Blockly.VariableModel} variable Variable to delete. */ -Blockly.VariableMap.prototype.deleteVariable = function(variable) { +VariableMap.prototype.deleteVariable = function(variable) { const variableList = this.variableMap_[variable.type]; for (let i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { @@ -221,7 +222,7 @@ Blockly.VariableMap.prototype.deleteVariable = function(variable) { * workspace. May prompt the user for confirmation. * @param {string} id ID of variable to delete. */ -Blockly.VariableMap.prototype.deleteVariableById = function(id) { +VariableMap.prototype.deleteVariableById = function(id) { const variable = this.getVariableById(id); if (variable) { // Check whether this variable is a function parameter before deleting. @@ -267,7 +268,7 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) { * @param {!Array} uses An array of uses of the variable. * @package */ -Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, +VariableMap.prototype.deleteVariableInternal = function(variable, uses) { const existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { @@ -296,7 +297,7 @@ Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, * @return {?Blockly.VariableModel} The variable with the given name, or null if * it was not found. */ -Blockly.VariableMap.prototype.getVariable = function(name, opt_type) { +VariableMap.prototype.getVariable = function(name, opt_type) { const type = opt_type || ''; const list = this.variableMap_[type]; if (list) { @@ -314,7 +315,7 @@ Blockly.VariableMap.prototype.getVariable = function(name, opt_type) { * @param {string} id The ID to check for. * @return {?Blockly.VariableModel} The variable with the given ID. */ -Blockly.VariableMap.prototype.getVariableById = function(id) { +VariableMap.prototype.getVariableById = function(id) { const keys = Object.keys(this.variableMap_); for (let i = 0; i < keys.length; i++) { const key = keys[i]; @@ -334,7 +335,7 @@ Blockly.VariableMap.prototype.getVariableById = function(id) { * @return {!Array} The sought after variables of the * passed in type. An empty array if none are found. */ -Blockly.VariableMap.prototype.getVariablesOfType = function(type) { +VariableMap.prototype.getVariablesOfType = function(type) { type = type || ''; const variable_list = this.variableMap_[type]; if (variable_list) { @@ -352,7 +353,7 @@ Blockly.VariableMap.prototype.getVariablesOfType = function(type) { * @return {!Array} List of variable types. * @package */ -Blockly.VariableMap.prototype.getVariableTypes = function(ws) { +VariableMap.prototype.getVariableTypes = function(ws) { const variableMap = {}; Blockly.utils.object.mixin(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { @@ -376,7 +377,7 @@ Blockly.VariableMap.prototype.getVariableTypes = function(ws) { * Return all variables of all types. * @return {!Array} List of variable models. */ -Blockly.VariableMap.prototype.getAllVariables = function() { +VariableMap.prototype.getAllVariables = function() { let all_variables = []; for (const key in this.variableMap_) { all_variables = all_variables.concat(this.variableMap_[key]); @@ -388,7 +389,7 @@ Blockly.VariableMap.prototype.getAllVariables = function() { * Returns all of the variable names of all types. * @return {!Array} All of the variable names of all types. */ -Blockly.VariableMap.prototype.getAllVariableNames = function() { +VariableMap.prototype.getAllVariableNames = function() { const allNames = []; for (const key in this.variableMap_) { const variables = this.variableMap_[key]; @@ -404,7 +405,7 @@ Blockly.VariableMap.prototype.getAllVariableNames = function() { * @param {string} id ID of the variable to find. * @return {!Array} Array of block usages. */ -Blockly.VariableMap.prototype.getVariableUsesById = function(id) { +VariableMap.prototype.getVariableUsesById = function(id) { const uses = []; const blocks = this.workspace.getAllBlocks(false); // Iterate through every block and check the name. @@ -420,3 +421,5 @@ Blockly.VariableMap.prototype.getVariableUsesById = function(id) { } return uses; }; + +exports = VariableMap; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..d4217d539 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -195,7 +195,7 @@ goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], 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']); +goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); 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.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']); From 9847b8c027c6581246616d6554eb1e6c541eb6fc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:39:58 -0700 Subject: [PATCH 060/291] Migrate core/variable_map.js to named requires --- core/variable_map.js | 86 ++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/core/variable_map.js b/core/variable_map.js index 22eb11c9c..e2c371149 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -13,25 +13,27 @@ goog.module('Blockly.VariableMap'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +const Events = goog.require('Blockly.Events'); +const Msg = goog.require('Blockly.Msg'); +const Names = goog.require('Blockly.Names'); +const VariableModel = goog.require('Blockly.VariableModel'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const object = goog.require('Blockly.utils.object'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarDelete'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarRename'); -goog.require('Blockly.Msg'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.VariableModel'); -goog.requireType('Blockly.Workspace'); /** * Class for a variable map. This contains a dictionary data structure with * variable types as keys and lists of variables as values. The list of * variables are the type indicated by the key. - * @param {!Blockly.Workspace} workspace The workspace this map belongs to. + * @param {!Workspace} workspace The workspace this map belongs to. * @constructor */ const VariableMap = function(workspace) { @@ -39,14 +41,14 @@ const VariableMap = function(workspace) { * A map from variable type to list of variable names. The lists contain all * of the named variables in the workspace, including variables * that are not currently in use. - * @type {!Object>} + * @type {!Object>} * @private */ this.variableMap_ = Object.create(null); /** * The workspace this map belongs to. - * @type {!Blockly.Workspace} + * @type {!Workspace} */ this.workspace = workspace; }; @@ -62,7 +64,7 @@ VariableMap.prototype.clear = function() { /** * Rename the given variable by updating its name in the variable map. - * @param {!Blockly.VariableModel} variable Variable to rename. + * @param {!VariableModel} variable Variable to rename. * @param {string} newName New variable name. * @package */ @@ -70,7 +72,7 @@ VariableMap.prototype.renameVariable = function(variable, newName) { const type = variable.type; const conflictVar = this.getVariable(newName, type); const blocks = this.workspace.getAllBlocks(false); - Blockly.Events.setGroup(true); + Events.setGroup(true); try { // The IDs may match if the rename is a simple case change (name1 -> Name1). if (!conflictVar || conflictVar.getId() == variable.getId()) { @@ -79,7 +81,7 @@ VariableMap.prototype.renameVariable = function(variable, newName) { this.renameVariableWithConflict_(variable, newName, conflictVar, blocks); } } finally { - Blockly.Events.setGroup(false); + Events.setGroup(false); } }; @@ -101,15 +103,15 @@ VariableMap.prototype.renameVariableById = function(id, newName) { /** * Update the name of the given variable and refresh all references to it. * The new name must not conflict with any existing variable names. - * @param {!Blockly.VariableModel} variable Variable to rename. + * @param {!VariableModel} variable Variable to rename. * @param {string} newName New variable name. - * @param {!Array} blocks The list of all blocks in the + * @param {!Array} blocks The list of all blocks in the * workspace. * @private */ VariableMap.prototype.renameVariableAndUses_ = function(variable, newName, blocks) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_RENAME))( + Events.fire(new (Events.get(Events.VAR_RENAME))( variable, newName)); variable.name = newName; for (let i = 0; i < blocks.length; i++) { @@ -122,11 +124,11 @@ VariableMap.prototype.renameVariableAndUses_ = function(variable, * variable. The two variables are coalesced into a single variable with the ID * of the existing variable that was already using newName. * Refresh all references to the variable. - * @param {!Blockly.VariableModel} variable Variable to rename. + * @param {!VariableModel} variable Variable to rename. * @param {string} newName New variable name. - * @param {!Blockly.VariableModel} conflictVar The variable that was already + * @param {!VariableModel} conflictVar The variable that was already * using newName. - * @param {!Array} blocks The list of all blocks in the + * @param {!Array} blocks The list of all blocks in the * workspace. * @private */ @@ -147,7 +149,7 @@ VariableMap.prototype.renameVariableWithConflict_ = function(variable, } // Finally delete the original variable, which is now unreferenced. - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( + Events.fire(new (Events.get(Events.VAR_DELETE))( variable)); // And remove it from the list. const variableList = this.getVariablesOfType(type); @@ -167,7 +169,7 @@ VariableMap.prototype.renameVariableWithConflict_ = function(variable, * their type. This will default to '' which is a specific type. * @param {?string=} opt_id The unique ID of the variable. This will default to * a UUID. - * @return {!Blockly.VariableModel} The newly created variable. + * @return {!VariableModel} The newly created variable. */ VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { @@ -184,9 +186,9 @@ VariableMap.prototype.createVariable = function(name, if (opt_id && this.getVariableById(opt_id)) { throw Error('Variable id, "' + opt_id + '", is already in use.'); } - const id = opt_id || Blockly.utils.genUid(); + const id = opt_id || utils.genUid(); const type = opt_type || ''; - variable = new Blockly.VariableModel(this.workspace, name, type, id); + variable = new VariableModel(this.workspace, name, type, id); const variables = this.variableMap_[type] || []; variables.push(variable); @@ -203,14 +205,14 @@ VariableMap.prototype.createVariable = function(name, /** * Delete a variable. - * @param {!Blockly.VariableModel} variable Variable to delete. + * @param {!VariableModel} variable Variable to delete. */ VariableMap.prototype.deleteVariable = function(variable) { const variableList = this.variableMap_[variable.type]; for (let i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { variableList.splice(i, 1); - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( + Events.fire(new (Events.get(Events.VAR_DELETE))( variable)); return; } @@ -232,7 +234,7 @@ VariableMap.prototype.deleteVariableById = function(id) { if (block.type == 'procedures_defnoreturn' || block.type == 'procedures_defreturn') { const procedureName = block.getFieldValue('NAME'); - const deleteText = Blockly.Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. + const deleteText = Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. replace('%1', variableName). replace('%2', procedureName); Blockly.alert(deleteText); @@ -243,7 +245,7 @@ VariableMap.prototype.deleteVariableById = function(id) { const map = this; if (uses.length > 1) { // Confirm before deleting multiple blocks. - const confirmText = Blockly.Msg['DELETE_VARIABLE_CONFIRMATION']. + const confirmText = Msg['DELETE_VARIABLE_CONFIRMATION']. replace('%1', String(uses.length)). replace('%2', variableName); Blockly.confirm(confirmText, @@ -264,15 +266,15 @@ VariableMap.prototype.deleteVariableById = function(id) { /** * Deletes a variable and all of its uses from this workspace without asking the * user for confirmation. - * @param {!Blockly.VariableModel} variable Variable to delete. - * @param {!Array} uses An array of uses of the variable. + * @param {!VariableModel} variable Variable to delete. + * @param {!Array} uses An array of uses of the variable. * @package */ VariableMap.prototype.deleteVariableInternal = function(variable, uses) { - const existingGroup = Blockly.Events.getGroup(); + const existingGroup = Events.getGroup(); if (!existingGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } try { for (let i = 0; i < uses.length; i++) { @@ -281,7 +283,7 @@ VariableMap.prototype.deleteVariableInternal = function(variable, this.deleteVariable(variable); } finally { if (!existingGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } } }; @@ -294,7 +296,7 @@ VariableMap.prototype.deleteVariableInternal = function(variable, * @param {string} name The name to check for. * @param {?string=} opt_type The type of the variable. If not provided it * defaults to the empty string, which is a specific type. - * @return {?Blockly.VariableModel} The variable with the given name, or null if + * @return {?VariableModel} The variable with the given name, or null if * it was not found. */ VariableMap.prototype.getVariable = function(name, opt_type) { @@ -302,7 +304,7 @@ VariableMap.prototype.getVariable = function(name, opt_type) { const list = this.variableMap_[type]; if (list) { for (let j = 0, variable; (variable = list[j]); j++) { - if (Blockly.Names.equals(variable.name, name)) { + if (Names.equals(variable.name, name)) { return variable; } } @@ -313,7 +315,7 @@ VariableMap.prototype.getVariable = function(name, opt_type) { /** * Find the variable by the given ID and return it. Return null if not found. * @param {string} id The ID to check for. - * @return {?Blockly.VariableModel} The variable with the given ID. + * @return {?VariableModel} The variable with the given ID. */ VariableMap.prototype.getVariableById = function(id) { const keys = Object.keys(this.variableMap_); @@ -332,7 +334,7 @@ VariableMap.prototype.getVariableById = function(id) { * Get a list containing all of the variables of a specified type. If type is * null, return list of variables with empty string type. * @param {?string} type Type of the variables to find. - * @return {!Array} The sought after variables of the + * @return {!Array} The sought after variables of the * passed in type. An empty array if none are found. */ VariableMap.prototype.getVariablesOfType = function(type) { @@ -347,7 +349,7 @@ VariableMap.prototype.getVariablesOfType = function(type) { /** * Return all variable and potential variable types. This list always contains * the empty string. - * @param {?Blockly.Workspace} ws The workspace used to look for potential + * @param {?Workspace} ws The workspace used to look for potential * variables. This can be different than the workspace stored on this object * if the passed in ws is a flyout workspace. * @return {!Array} List of variable types. @@ -355,9 +357,9 @@ VariableMap.prototype.getVariablesOfType = function(type) { */ VariableMap.prototype.getVariableTypes = function(ws) { const variableMap = {}; - Blockly.utils.object.mixin(variableMap, this.variableMap_); + object.mixin(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { - Blockly.utils.object.mixin(variableMap, + object.mixin(variableMap, ws.getPotentialVariableMap().variableMap_); } const types = Object.keys(variableMap); @@ -375,7 +377,7 @@ VariableMap.prototype.getVariableTypes = function(ws) { /** * Return all variables of all types. - * @return {!Array} List of variable models. + * @return {!Array} List of variable models. */ VariableMap.prototype.getAllVariables = function() { let all_variables = []; @@ -403,7 +405,7 @@ VariableMap.prototype.getAllVariableNames = function() { /** * Find all the uses of a named variable. * @param {string} id ID of the variable to find. - * @return {!Array} Array of block usages. + * @return {!Array} Array of block usages. */ VariableMap.prototype.getVariableUsesById = function(id) { const uses = []; diff --git a/tests/deps.js b/tests/deps.js index d4217d539..fa4d62a5c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -195,7 +195,7 @@ goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], 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'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.Names', 'Blockly.VariableModel', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); 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.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']); From d58a878fad99b4eedc4db2f09d6ee1820cb0c110 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 29 Jul 2021 12:43:49 -0700 Subject: [PATCH 061/291] Switch to getter for keyboard contents. --- core/blockly.js | 34 +++++++++------------------------- core/clipboard.js | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 808c035b0..ab82638fe 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -93,25 +93,12 @@ Blockly.selected = null; Blockly.draggingConnections = []; /** - * Contents of the local clipboard. - * @type {Element} - * @private + * Get the current contents of the clipboard and associated metadata. + * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object + * containing the clipboard contents and associated metadata. + * @public */ -Blockly.clipboardXml_ = Blockly.clipboard.xml; - -/** - * Source of the local clipboard. - * @type {Blockly.WorkspaceSvg} - * @private - */ -Blockly.clipboardSource_ = Blockly.clipboard.source; - -/** - * Map of types to type counts for the clipboard object and descendants. - * @type {Object} - * @private - */ -Blockly.clipboardTypeCounts_ = Blockly.clipboard.typeCounts; +Blockly.getClipboardInfo = Blockly.common.getClipboardInfo; /** * Cached value for whether 3D is supported. @@ -137,9 +124,7 @@ Blockly.svgSize = function(svg) { // When removing this function, remove svg.cachedWidth_ and svg.cachedHeight_ // from setCachedParentSvgSize. Blockly.utils.deprecation.warn( - 'Blockly.svgSize', - 'March 2021', - 'March 2022', + 'Blockly.svgSize', 'March 2021', 'March 2022', 'workspace.getCachedParentSvgSize'); svg = /** @type {?} */ (svg); return new Blockly.utils.Size(svg.cachedWidth_, svg.cachedHeight_); @@ -221,7 +206,8 @@ Blockly.deleteBlock = function(selected) { Blockly.Events.setGroup(true); Blockly.hideChaff(); if (selected.outputConnection) { - // Do not attempt to heal rows (https://github.com/google/blockly/issues/4832) + // Do not attempt to heal rows + // (https://github.com/google/blockly/issues/4832) selected.dispose(false, true); } else { selected.dispose(/* heal */ true, true); @@ -366,9 +352,7 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) { 'Block definition #' + i + ' in JSON array' + ' overwrites prior definition of "' + typename + '".'); } - Blockly.Blocks[typename] = { - init: Blockly.jsonInitFactory_(elem) - }; + Blockly.Blocks[typename] = {init: Blockly.jsonInitFactory_(elem)}; } } } diff --git a/core/clipboard.js b/core/clipboard.js index 887346a58..b93f92530 100644 --- a/core/clipboard.js +++ b/core/clipboard.js @@ -26,7 +26,6 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * @private */ let xml = null; -exports.xml = xml; /** * Source of the local clipboard. @@ -34,7 +33,6 @@ exports.xml = xml; * @private */ let source = null; -exports.source = source; /** * Map of types to type counts for the clipboard object and descendants. @@ -42,12 +40,20 @@ exports.source = source; * @private */ let typeCounts = null; -exports.typeCounts = typeCounts; + +/** + * Get the current contents of the clipboard and associated metadata. + * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object + * containing the clipboard contents and associated metadata. + */ +const getClipboardInfo = function() { + return {xml: xml, source: source, typeCounts: typeCounts}; +}; +exports.getClipboardInfo = getClipboardInfo; /** * Copy a block or workspace comment onto the local clipboard. * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. - * @package */ const copy = function(toCopy) { var data = toCopy.toCopyData(); @@ -57,12 +63,12 @@ const copy = function(toCopy) { typeCounts = data.typeCounts; } }; +/** @package */ exports.copy = copy; /** * Paste a block or workspace comment on to the main workspace. * @return {boolean} True if the paste was successful, false otherwise. - * @package */ const paste = function() { if (!xml) { @@ -82,13 +88,13 @@ const paste = function() { } return false; }; +/** @package */ exports.paste = paste; /** * Duplicate this block and its children, or a workspace comment. * @param {!ICopyable} toDuplicate Block or Workspace Comment to be - * copied. - * @package + * duplicated. */ const duplicate = function(toDuplicate) { // Save the clipboard. @@ -103,4 +109,5 @@ const duplicate = function(toDuplicate) { xml = oldXml; source = oldSource; }; +/** @package */ exports.duplicate = duplicate; From 78646eae51980af96b9e97add9a13d8978773595 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:47:51 -0700 Subject: [PATCH 062/291] clang-format core/variable_map.js --- core/variable_map.js | 57 +++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/core/variable_map.js b/core/variable_map.js index e2c371149..a22ab75d5 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -109,10 +109,9 @@ VariableMap.prototype.renameVariableById = function(id, newName) { * workspace. * @private */ -VariableMap.prototype.renameVariableAndUses_ = function(variable, - newName, blocks) { - Events.fire(new (Events.get(Events.VAR_RENAME))( - variable, newName)); +VariableMap.prototype.renameVariableAndUses_ = function( + variable, newName, blocks) { + Events.fire(new (Events.get(Events.VAR_RENAME))(variable, newName)); variable.name = newName; for (let i = 0; i < blocks.length; i++) { blocks[i].updateVarName(variable); @@ -132,8 +131,8 @@ VariableMap.prototype.renameVariableAndUses_ = function(variable, * workspace. * @private */ -VariableMap.prototype.renameVariableWithConflict_ = function(variable, - newName, conflictVar, blocks) { +VariableMap.prototype.renameVariableWithConflict_ = function( + variable, newName, conflictVar, blocks) { const type = variable.type; const oldCase = conflictVar.name; @@ -149,13 +148,11 @@ VariableMap.prototype.renameVariableWithConflict_ = function(variable, } // Finally delete the original variable, which is now unreferenced. - Events.fire(new (Events.get(Events.VAR_DELETE))( - variable)); + Events.fire(new (Events.get(Events.VAR_DELETE))(variable)); // And remove it from the list. const variableList = this.getVariablesOfType(type); const variableIndex = variableList.indexOf(variable); this.variableMap_[type].splice(variableIndex, 1); - }; /* End functions for renaming variables. */ @@ -171,12 +168,12 @@ VariableMap.prototype.renameVariableWithConflict_ = function(variable, * a UUID. * @return {!VariableModel} The newly created variable. */ -VariableMap.prototype.createVariable = function(name, - opt_type, opt_id) { +VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { let variable = this.getVariable(name, opt_type); if (variable) { if (opt_id && variable.getId() != opt_id) { - throw Error('Variable "' + name + '" is already in use and its id is "' + + throw Error( + 'Variable "' + name + '" is already in use and its id is "' + variable.getId() + '" which conflicts with the passed in ' + 'id, "' + opt_id + '".'); } @@ -212,8 +209,7 @@ VariableMap.prototype.deleteVariable = function(variable) { for (let i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { variableList.splice(i, 1); - Events.fire(new (Events.get(Events.VAR_DELETE))( - variable)); + Events.fire(new (Events.get(Events.VAR_DELETE))(variable)); return; } } @@ -232,11 +228,11 @@ VariableMap.prototype.deleteVariableById = function(id) { const uses = this.getVariableUsesById(id); for (let i = 0, block; (block = uses[i]); i++) { if (block.type == 'procedures_defnoreturn' || - block.type == 'procedures_defreturn') { + block.type == 'procedures_defreturn') { const procedureName = block.getFieldValue('NAME'); - const deleteText = Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. - replace('%1', variableName). - replace('%2', procedureName); + const deleteText = Msg['CANNOT_DELETE_VARIABLE_PROCEDURE'] + .replace('%1', variableName) + .replace('%2', procedureName); Blockly.alert(deleteText); return; } @@ -245,21 +241,20 @@ VariableMap.prototype.deleteVariableById = function(id) { const map = this; if (uses.length > 1) { // Confirm before deleting multiple blocks. - const confirmText = Msg['DELETE_VARIABLE_CONFIRMATION']. - replace('%1', String(uses.length)). - replace('%2', variableName); - Blockly.confirm(confirmText, - function(ok) { - if (ok && variable) { - map.deleteVariableInternal(variable, uses); - } - }); + const confirmText = Msg['DELETE_VARIABLE_CONFIRMATION'] + .replace('%1', String(uses.length)) + .replace('%2', variableName); + Blockly.confirm(confirmText, function(ok) { + if (ok && variable) { + map.deleteVariableInternal(variable, uses); + } + }); } else { // No confirmation necessary for a single block. map.deleteVariableInternal(variable, uses); } } else { - console.warn("Can't delete non-existent variable: " + id); + console.warn('Can\'t delete non-existent variable: ' + id); } }; @@ -270,8 +265,7 @@ VariableMap.prototype.deleteVariableById = function(id) { * @param {!Array} uses An array of uses of the variable. * @package */ -VariableMap.prototype.deleteVariableInternal = function(variable, - uses) { +VariableMap.prototype.deleteVariableInternal = function(variable, uses) { const existingGroup = Events.getGroup(); if (!existingGroup) { Events.setGroup(true); @@ -359,8 +353,7 @@ VariableMap.prototype.getVariableTypes = function(ws) { const variableMap = {}; object.mixin(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { - object.mixin(variableMap, - ws.getPotentialVariableMap().variableMap_); + object.mixin(variableMap, ws.getPotentialVariableMap().variableMap_); } const types = Object.keys(variableMap); let hasEmpty = false; From dc4a719e2f507468b303ed228381dc7d033cdd57 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:50:42 -0700 Subject: [PATCH 063/291] Migrate core/variable_model.js to goog.module --- core/variable_model.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index bc097da8a..ce4c37c66 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.VariableModel'); +goog.module('Blockly.VariableModel'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -34,7 +35,7 @@ goog.requireType('Blockly.Workspace'); * @see {Blockly.FieldVariable} * @constructor */ -Blockly.VariableModel = function(workspace, name, opt_type, opt_id) { +const VariableModel = function(workspace, name, opt_type, opt_id) { /** * The workspace the variable is in. * @type {!Blockly.Workspace} @@ -73,18 +74,20 @@ Blockly.VariableModel = function(workspace, name, opt_type, opt_id) { /** * @return {string} The ID for the variable. */ -Blockly.VariableModel.prototype.getId = function() { +VariableModel.prototype.getId = function() { return this.id_; }; /** * A custom compare function for the VariableModel objects. - * @param {Blockly.VariableModel} var1 First variable to compare. - * @param {Blockly.VariableModel} var2 Second variable to compare. + * @param {VariableModel} var1 First variable to compare. + * @param {VariableModel} var2 Second variable to compare. * @return {number} -1 if name of var1 is less than name of var2, 0 if equal, * and 1 if greater. * @package */ -Blockly.VariableModel.compareByName = function(var1, var2) { +VariableModel.compareByName = function(var1, var2) { return var1.name.localeCompare(var2.name, undefined, {sensitivity: 'base'}); }; + +exports = VariableModel; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..0e0a7f034 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -196,7 +196,7 @@ goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['B 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']); -goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); +goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); 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'], {'lang': 'es6', 'module': 'goog'}); From 714bb6120f9caebc04dc6707d300f784924b33b7 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 29 Jul 2021 12:52:14 -0700 Subject: [PATCH 064/291] Fix annotations --- core/blockly.js | 6 +++--- core/clipboard.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index ab82638fe..9fae4e84a 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -94,11 +94,11 @@ Blockly.draggingConnections = []; /** * Get the current contents of the clipboard and associated metadata. - * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object - * containing the clipboard contents and associated metadata. + * @return {{xml: ?Element, source: ?Blockly.WorkspaceSvg, typeCounts: ?Object}} + * An object containing the clipboard contents and associated metadata. * @public */ -Blockly.getClipboardInfo = Blockly.common.getClipboardInfo; +Blockly.getClipboardInfo = Blockly.clipboard.getClipboardInfo; /** * Cached value for whether 3D is supported. diff --git a/core/clipboard.js b/core/clipboard.js index b93f92530..9f7097f71 100644 --- a/core/clipboard.js +++ b/core/clipboard.js @@ -22,29 +22,29 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** * Contents of the local clipboard. - * @type {Element} + * @type {?Element} * @private */ let xml = null; /** * Source of the local clipboard. - * @type {WorkspaceSvg} + * @type {?WorkspaceSvg} * @private */ let source = null; /** * Map of types to type counts for the clipboard object and descendants. - * @type {Object} + * @type {?Object} * @private */ let typeCounts = null; /** * Get the current contents of the clipboard and associated metadata. - * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object - * containing the clipboard contents and associated metadata. + * @return {{xml: ?Element, source: ?WorkspaceSvg, typeCounts: ?Object}} An + * object containing the clipboard contents and associated metadata. */ const getClipboardInfo = function() { return {xml: xml, source: source, typeCounts: typeCounts}; From 0a6893706f2c2a64b6865ab68c4bc62ce625a2ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:55:26 -0700 Subject: [PATCH 065/291] Migrate core/variable_model.js to named requires --- core/variable_model.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index ce4c37c66..74bc2b578 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -13,18 +13,18 @@ goog.module('Blockly.VariableModel'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Events'); +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarCreate'); -goog.require('Blockly.utils'); - -goog.requireType('Blockly.Workspace'); /** * Class for a variable model. * Holds information for the variable including name, ID, and type. - * @param {!Blockly.Workspace} workspace The variable's workspace. + * @param {!Workspace} workspace The variable's workspace. * @param {string} name The name of the variable. This is the user-visible name * (e.g. 'my var' or '私の変数'), not the generated name. * @param {string=} opt_type The type of the variable like 'int' or 'string'. @@ -38,7 +38,7 @@ goog.requireType('Blockly.Workspace'); const VariableModel = function(workspace, name, opt_type, opt_id) { /** * The workspace the variable is in. - * @type {!Blockly.Workspace} + * @type {!Workspace} */ this.workspace = workspace; @@ -65,9 +65,9 @@ const VariableModel = function(workspace, name, opt_type, opt_id) { * @type {string} * @private */ - this.id_ = opt_id || Blockly.utils.genUid(); + this.id_ = opt_id || utils.genUid(); - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_CREATE))( + Events.fire(new (Events.get(Events.VAR_CREATE))( this)); }; From 6eb8667c3ccb5c9a4d613a881f0711a845cec533 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:55:46 -0700 Subject: [PATCH 066/291] clang-format core/variable_model.js --- core/variable_model.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index 74bc2b578..2f5936f4e 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -67,8 +67,7 @@ const VariableModel = function(workspace, name, opt_type, opt_id) { */ this.id_ = opt_id || utils.genUid(); - Events.fire(new (Events.get(Events.VAR_CREATE))( - this)); + Events.fire(new (Events.get(Events.VAR_CREATE))(this)); }; /** From 34042519f47492a9041e071556a18b8999858cbc Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 29 Jul 2021 15:00:44 -0700 Subject: [PATCH 067/291] Add regex lookarounds to check for require overlaps --- scripts/goog_module/convert-file.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 1c5b92fc8..4f433e428 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -151,7 +151,12 @@ getPropertiesAccessed() { # Detect if there was any overlap. if [[ -n "${requires_overlap}" ]]; then while read -r requires_overlap_prop; do - properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') + # Replace any instances of $requires_overlap_prop. Includes regex + # lookarounds so that it does not simply match string contains. + # Ex: if $requires_overlap is "Svg", then it would update the list + # "isTargetInput mouseToSvg noEvent Svg" to + # "isTargetInput mouseToSvg noEvent " (note that mouseToSvg is unchanged). + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/(? Date: Thu, 29 Jul 2021 15:18:15 -0700 Subject: [PATCH 068/291] wording update --- 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 4f433e428..4d6c13345 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -151,7 +151,7 @@ getPropertiesAccessed() { # Detect if there was any overlap. if [[ -n "${requires_overlap}" ]]; then while read -r requires_overlap_prop; do - # Replace any instances of $requires_overlap_prop. Includes regex + # Removes any instances of $requires_overlap_prop. Includes regex # lookarounds so that it does not simply match string contains. # Ex: if $requires_overlap is "Svg", then it would update the list # "isTargetInput mouseToSvg noEvent Svg" to From b3bbd70280d2ddab3844ea918800c5c9922b056e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 15:57:08 -0700 Subject: [PATCH 069/291] Migrate core/trashcan.js to goog.module --- core/trashcan.js | 195 ++++++++++++++++++++--------------------------- tests/deps.js | 2 +- 2 files changed, 85 insertions(+), 112 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index dea20acd2..7771deba0 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Trashcan'); +goog.module('Blockly.Trashcan'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); @@ -46,8 +47,8 @@ goog.requireType('Blockly.WorkspaceSvg'); * @implements {Blockly.IPositionable} * @extends {Blockly.DeleteArea} */ -Blockly.Trashcan = function(workspace) { - Blockly.Trashcan.superClass_.constructor.call(this); +const Trashcan = function(workspace) { + Trashcan.superClass_.constructor.call(this); /** * The workspace the trashcan sits in. * @type {!Blockly.WorkspaceSvg} @@ -113,113 +114,85 @@ Blockly.Trashcan = function(workspace) { } this.workspace_.addChangeListener(this.onDelete_.bind(this)); }; -Blockly.utils.object.inherits(Blockly.Trashcan, Blockly.DeleteArea); +Blockly.utils.object.inherits(Trashcan, Blockly.DeleteArea); /** * Width of both the trash can and lid images. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.WIDTH_ = 47; +const WIDTH = 47; /** * Height of the trashcan image (minus lid). - * @const {number} - * @private */ -Blockly.Trashcan.prototype.BODY_HEIGHT_ = 44; +const BODY_HEIGHT = 44; /** * Height of the lid image. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.LID_HEIGHT_ = 16; +const LID_HEIGHT = 16; /** * Distance between trashcan and bottom or top edge of workspace. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.MARGIN_VERTICAL_ = 20; +const MARGIN_VERTICAL = 20; /** * Distance between trashcan and right or left edge of workspace. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.MARGIN_HORIZONTAL_ = 20; +const MARGIN_HORIZONTAL = 20; /** * Extent of hotspot on all sides beyond the size of the image. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.MARGIN_HOTSPOT_ = 10; +const MARGIN_HOTSPOT = 10; /** * Location of trashcan in sprite image. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.SPRITE_LEFT_ = 0; +const SPRITE_LEFT = 0; /** * Location of trashcan in sprite image. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.SPRITE_TOP_ = 32; +const SPRITE_TOP = 32; /** * The openness of the lid when the trashcan contains blocks. * (0.0 = closed, 1.0 = open) - * @const {number} - * @private */ -Blockly.Trashcan.prototype.HAS_BLOCKS_LID_ANGLE_ = 0.1; +const HAS_BLOCKS_LID_ANGLE = 0.1; /** * The length of the lid open/close animation in milliseconds. - * @const {number} - * @private */ -Blockly.Trashcan.ANIMATION_LENGTH_ = 80; +const ANIMATION_LENGTH = 80; /** * The number of frames in the animation. - * @const {number} - * @private */ -Blockly.Trashcan.ANIMATION_FRAMES_ = 4; +const ANIMATION_FRAMES = 4; /** * The minimum (resting) opacity of the trashcan and lid. - * @const {number} - * @private */ -Blockly.Trashcan.OPACITY_MIN_ = 0.4; +const OPACITY_MIN = 0.4; /** * The maximum (hovered) opacity of the trashcan and lid. - * @const {number} - * @private */ -Blockly.Trashcan.OPACITY_MAX_ = 0.8; +const OPACITY_MAX = 0.8; /** * The maximum angle the trashcan lid can opens to. At the end of the open * animation the lid will be open to this angle. - * @const {number} - * @private */ -Blockly.Trashcan.MAX_LID_ANGLE_ = 45; +const MAX_LID_ANGLE = 45; /** * Current open/close state of the lid. * @type {boolean} */ -Blockly.Trashcan.prototype.isLidOpen = false; +Trashcan.prototype.isLidOpen = false; /** * The minimum openness of the lid. Used to indicate if the trashcan contains @@ -227,62 +200,62 @@ Blockly.Trashcan.prototype.isLidOpen = false; * @type {number} * @private */ -Blockly.Trashcan.prototype.minOpenness_ = 0; +Trashcan.prototype.minOpenness_ = 0; /** * The SVG group containing the trash can. * @type {SVGElement} * @private */ -Blockly.Trashcan.prototype.svgGroup_ = null; +Trashcan.prototype.svgGroup_ = null; /** * The SVG image element of the trash can lid. * @type {SVGElement} * @private */ -Blockly.Trashcan.prototype.svgLid_ = null; +Trashcan.prototype.svgLid_ = null; /** * Task ID of opening/closing animation. * @type {number} * @private */ -Blockly.Trashcan.prototype.lidTask_ = 0; +Trashcan.prototype.lidTask_ = 0; /** * Current state of lid opening (0.0 = closed, 1.0 = open). * @type {number} * @private */ -Blockly.Trashcan.prototype.lidOpen_ = 0; +Trashcan.prototype.lidOpen_ = 0; /** * Left coordinate of the trash can. * @type {number} * @private */ -Blockly.Trashcan.prototype.left_ = 0; +Trashcan.prototype.left_ = 0; /** * Top coordinate of the trash can. * @type {number} * @private */ -Blockly.Trashcan.prototype.top_ = 0; +Trashcan.prototype.top_ = 0; /** * Whether this has been initialized. * @type {boolean} * @private */ -Blockly.Trashcan.prototype.initialized_ = false; +Trashcan.prototype.initialized_ = false; /** * Create the trash can elements. * @return {!SVGElement} The trash can's SVG group. */ -Blockly.Trashcan.prototype.createDom = function() { +Trashcan.prototype.createDom = function() { /* Here's the markup that will be generated: @@ -309,17 +282,17 @@ Blockly.Trashcan.prototype.createDom = function() { Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { - 'width': this.WIDTH_, - 'height': this.BODY_HEIGHT_, - 'y': this.LID_HEIGHT_ + 'width': WIDTH, + 'height': BODY_HEIGHT, + 'y': LID_HEIGHT }, clip); const body = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, - 'x': -this.SPRITE_LEFT_, + 'x': -SPRITE_LEFT, 'height': Blockly.internalConstants.SPRITE.height, - 'y': -this.SPRITE_TOP_, + 'y': -SPRITE_TOP, 'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')' }, this.svgGroup_); @@ -334,13 +307,13 @@ Blockly.Trashcan.prototype.createDom = function() { this.svgGroup_); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, - {'width': this.WIDTH_, 'height': this.LID_HEIGHT_}, clip); + {'width': WIDTH, 'height': LID_HEIGHT}, clip); this.svgLid_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, - 'x': -this.SPRITE_LEFT_, + 'x': -SPRITE_LEFT, 'height': Blockly.internalConstants.SPRITE.height, - 'y': -this.SPRITE_TOP_, + 'y': -SPRITE_TOP, 'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')' }, this.svgGroup_); @@ -366,7 +339,7 @@ Blockly.Trashcan.prototype.createDom = function() { /** * Initializes the trash can. */ -Blockly.Trashcan.prototype.init = function() { +Trashcan.prototype.init = function() { if (this.workspace_.options.maxTrashcanContents > 0) { Blockly.utils.dom.insertAfter( this.flyout.createDom(Blockly.utils.Svg.SVG), @@ -392,7 +365,7 @@ Blockly.Trashcan.prototype.init = function() { * Unlink from all DOM elements to prevent memory leaks. * @suppress {checkTypes} */ -Blockly.Trashcan.prototype.dispose = function() { +Trashcan.prototype.dispose = function() { this.workspace_.getComponentManager().removeComponent('trashcan'); if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); @@ -408,7 +381,7 @@ Blockly.Trashcan.prototype.dispose = function() { * @return {boolean} True if the trashcan has contents. * @private */ -Blockly.Trashcan.prototype.hasContents_ = function() { +Trashcan.prototype.hasContents_ = function() { return !!this.contents_.length; }; @@ -416,14 +389,14 @@ Blockly.Trashcan.prototype.hasContents_ = function() { * Returns true if the trashcan contents-flyout is currently open. * @return {boolean} True if the trashcan contents-flyout is currently open. */ -Blockly.Trashcan.prototype.contentsIsOpen = function() { +Trashcan.prototype.contentsIsOpen = function() { return this.flyout.isVisible(); }; /** * Opens the trashcan flyout. */ -Blockly.Trashcan.prototype.openFlyout = function() { +Trashcan.prototype.openFlyout = function() { if (this.contentsIsOpen()) { return; } @@ -435,7 +408,7 @@ Blockly.Trashcan.prototype.openFlyout = function() { /** * Closes the trashcan flyout. */ -Blockly.Trashcan.prototype.closeFlyout = function() { +Trashcan.prototype.closeFlyout = function() { if (!this.contentsIsOpen()) { return; } @@ -448,7 +421,7 @@ Blockly.Trashcan.prototype.closeFlyout = function() { * @param {boolean} onlyClosePopups Whether only popups should be closed. * Flyouts should not be closed if this is true. */ -Blockly.Trashcan.prototype.autoHide = function(onlyClosePopups) { +Trashcan.prototype.autoHide = function(onlyClosePopups) { // For now the trashcan flyout always autocloses because it overlays the // trashcan UI (no trashcan to click to close it). if (!onlyClosePopups && this.flyout) { @@ -460,7 +433,7 @@ Blockly.Trashcan.prototype.autoHide = function(onlyClosePopups) { * Empties the trashcan's contents. If the contents-flyout is currently open * it will be closed. */ -Blockly.Trashcan.prototype.emptyContents = function() { +Trashcan.prototype.emptyContents = function() { if (!this.hasContents_()) { return; } @@ -477,7 +450,7 @@ Blockly.Trashcan.prototype.emptyContents = function() { * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ -Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { +Trashcan.prototype.position = function(metrics, savedPositions) { // Not yet initialized. if (!this.initialized_) { return; @@ -486,10 +459,10 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { const cornerPosition = Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); - const height = this.BODY_HEIGHT_ + this.LID_HEIGHT_; + const height = BODY_HEIGHT + LID_HEIGHT; const startRect = Blockly.uiPosition.getStartPositionRect( - cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), - this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); + cornerPosition, new Blockly.utils.Size(WIDTH, height), + MARGIN_HORIZONTAL, MARGIN_VERTICAL, metrics, this.workspace_); const verticalPosition = cornerPosition.vertical; const bumpDirection = @@ -497,7 +470,7 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { Blockly.uiPosition.bumpDirection.DOWN : Blockly.uiPosition.bumpDirection.UP; const positionRect = Blockly.uiPosition.bumpPositionRect( - startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); + startRect, MARGIN_VERTICAL, bumpDirection, savedPositions); this.top_ = positionRect.top; this.left_ = positionRect.left; @@ -511,9 +484,9 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ -Blockly.Trashcan.prototype.getBoundingRectangle = function() { - const bottom = this.top_ + this.BODY_HEIGHT_ + this.LID_HEIGHT_; - const right = this.left_ + this.WIDTH_; +Trashcan.prototype.getBoundingRectangle = function() { + const bottom = this.top_ + BODY_HEIGHT + LID_HEIGHT; + const right = this.left_ + WIDTH; return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); }; @@ -523,17 +496,17 @@ Blockly.Trashcan.prototype.getBoundingRectangle = function() { * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.Trashcan.prototype.getClientRect = function() { +Trashcan.prototype.getClientRect = function() { if (!this.svgGroup_) { return null; } const trashRect = this.svgGroup_.getBoundingClientRect(); - const top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_; - const bottom = top + this.LID_HEIGHT_ + this.BODY_HEIGHT_ + - 2 * this.MARGIN_HOTSPOT_; - const left = trashRect.left + this.SPRITE_LEFT_ - this.MARGIN_HOTSPOT_; - const right = left + this.WIDTH_ + 2 * this.MARGIN_HOTSPOT_; + const top = trashRect.top + SPRITE_TOP - MARGIN_HOTSPOT; + const bottom = top + LID_HEIGHT + BODY_HEIGHT + + 2 * MARGIN_HOTSPOT; + const left = trashRect.left + SPRITE_LEFT - MARGIN_HOTSPOT; + const right = left + WIDTH + 2 * MARGIN_HOTSPOT; return new Blockly.utils.Rect(top, bottom, left, right); }; @@ -544,7 +517,7 @@ Blockly.Trashcan.prototype.getClientRect = function() { * dragged. * @override */ -Blockly.Trashcan.prototype.onDragOver = function(_dragElement) { +Trashcan.prototype.onDragOver = function(_dragElement) { this.setLidOpen(this.wouldDelete_); }; @@ -554,7 +527,7 @@ Blockly.Trashcan.prototype.onDragOver = function(_dragElement) { * dragged. * @override */ -Blockly.Trashcan.prototype.onDragExit = function(_dragElement) { +Trashcan.prototype.onDragExit = function(_dragElement) { this.setLidOpen(false); }; @@ -565,7 +538,7 @@ Blockly.Trashcan.prototype.onDragExit = function(_dragElement) { * dragged. * @override */ -Blockly.Trashcan.prototype.onDrop = function(_dragElement) { +Trashcan.prototype.onDrop = function(_dragElement) { setTimeout(this.setLidOpen.bind(this, false), 100); }; @@ -574,7 +547,7 @@ Blockly.Trashcan.prototype.onDrop = function(_dragElement) { * @param {boolean} state True if open. * @package */ -Blockly.Trashcan.prototype.setLidOpen = function(state) { +Trashcan.prototype.setLidOpen = function(state) { if (this.isLidOpen == state) { return; } @@ -587,24 +560,22 @@ Blockly.Trashcan.prototype.setLidOpen = function(state) { * Rotate the lid open or closed by one step. Then wait and recurse. * @private */ -Blockly.Trashcan.prototype.animateLid_ = function() { - const frames = Blockly.Trashcan.ANIMATION_FRAMES_; +Trashcan.prototype.animateLid_ = function() { + const frames = ANIMATION_FRAMES; const delta = 1 / (frames + 1); this.lidOpen_ += this.isLidOpen ? delta : -delta; this.lidOpen_ = Math.min(Math.max(this.lidOpen_, this.minOpenness_), 1); - this.setLidAngle_(this.lidOpen_ * Blockly.Trashcan.MAX_LID_ANGLE_); + this.setLidAngle_(this.lidOpen_ * MAX_LID_ANGLE); - const minOpacity = Blockly.Trashcan.OPACITY_MIN_; - const maxOpacity = Blockly.Trashcan.OPACITY_MAX_; // Linear interpolation between min and max. - const opacity = minOpacity + this.lidOpen_ * (maxOpacity - minOpacity); + const opacity = OPACITY_MIN + this.lidOpen_ * (OPACITY_MAX - OPACITY_MIN); this.svgGroup_.style.opacity = opacity; if (this.lidOpen_ > this.minOpenness_ && this.lidOpen_ < 1) { this.lidTask_ = setTimeout(this.animateLid_.bind(this), - Blockly.Trashcan.ANIMATION_LENGTH_ / frames); + ANIMATION_LENGTH / frames); } }; @@ -613,14 +584,14 @@ Blockly.Trashcan.prototype.animateLid_ = function() { * @param {number} lidAngle The angle at which to set the lid. * @private */ -Blockly.Trashcan.prototype.setLidAngle_ = function(lidAngle) { +Trashcan.prototype.setLidAngle_ = function(lidAngle) { const openAtRight = this.workspace_.toolboxPosition == Blockly.utils.toolbox.Position.RIGHT || (this.workspace_.horizontalLayout && this.workspace_.RTL); this.svgLid_.setAttribute('transform', 'rotate(' + (openAtRight ? -lidAngle : lidAngle) + ',' + - (openAtRight ? 4 : this.WIDTH_ - 4) + ',' + - (this.LID_HEIGHT_ - 2) + ')'); + (openAtRight ? 4 : WIDTH - 4) + ',' + + (LID_HEIGHT - 2) + ')'); }; /** @@ -630,10 +601,10 @@ Blockly.Trashcan.prototype.setLidAngle_ = function(lidAngle) { * 0 and 1. * @private */ -Blockly.Trashcan.prototype.setMinOpenness_ = function(newMin) { +Trashcan.prototype.setMinOpenness_ = function(newMin) { this.minOpenness_ = newMin; if (!this.isLidOpen) { - this.setLidAngle_(newMin * Blockly.Trashcan.MAX_LID_ANGLE_); + this.setLidAngle_(newMin * MAX_LID_ANGLE); } }; @@ -641,14 +612,14 @@ Blockly.Trashcan.prototype.setMinOpenness_ = function(newMin) { * Flip the lid shut. * Called externally after a drag. */ -Blockly.Trashcan.prototype.closeLid = function() { +Trashcan.prototype.closeLid = function() { this.setLidOpen(false); }; /** * Inspect the contents of the trash. */ -Blockly.Trashcan.prototype.click = function() { +Trashcan.prototype.click = function() { if (!this.hasContents_()) { return; } @@ -660,7 +631,7 @@ Blockly.Trashcan.prototype.click = function() { * @param {boolean} trashcanOpen Whether the flyout is opening. * @private */ -Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { +Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { const uiEvent = new (Blockly.Events.get(Blockly.Events.TRASHCAN_OPEN))( trashcanOpen,this.workspace_.id); Blockly.Events.fire(uiEvent); @@ -671,7 +642,7 @@ Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { * @param {!Event} e A mouse down event. * @private */ -Blockly.Trashcan.prototype.blockMouseDownWhenOpenable_ = function(e) { +Trashcan.prototype.blockMouseDownWhenOpenable_ = function(e) { if (!this.contentsIsOpen() && this.hasContents_()) { e.stopPropagation(); // Don't start a workspace scroll. } @@ -681,7 +652,7 @@ Blockly.Trashcan.prototype.blockMouseDownWhenOpenable_ = function(e) { * Indicate that the trashcan can be clicked (by opening it) if it has blocks. * @private */ -Blockly.Trashcan.prototype.mouseOver_ = function() { +Trashcan.prototype.mouseOver_ = function() { if (this.hasContents_()) { this.setLidOpen(true); } @@ -692,7 +663,7 @@ Blockly.Trashcan.prototype.mouseOver_ = function() { * blocks). * @private */ -Blockly.Trashcan.prototype.mouseOut_ = function() { +Trashcan.prototype.mouseOut_ = function() { // No need to do a .hasBlocks check here because if it doesn't the trashcan // won't be open in the first place, and setOpen won't run. this.setLidOpen(false); @@ -703,7 +674,7 @@ Blockly.Trashcan.prototype.mouseOut_ = function() { * @param {!Blockly.Events.Abstract} event Workspace event. * @private */ -Blockly.Trashcan.prototype.onDelete_ = function(event) { +Trashcan.prototype.onDelete_ = function(event) { if (this.workspace_.options.maxTrashcanContents <= 0) { return; } @@ -720,7 +691,7 @@ Blockly.Trashcan.prototype.onDelete_ = function(event) { this.contents_.pop(); } - this.setMinOpenness_(this.HAS_BLOCKS_LID_ANGLE_); + this.setMinOpenness_(HAS_BLOCKS_LID_ANGLE); } }; @@ -733,7 +704,7 @@ Blockly.Trashcan.prototype.onDelete_ = function(event) { * attributes. * @private */ -Blockly.Trashcan.prototype.cleanBlockXML_ = function(xml) { +Trashcan.prototype.cleanBlockXML_ = function(xml) { const xmlBlock = xml.cloneNode(true); let node = xmlBlock; while (node) { @@ -772,3 +743,5 @@ Blockly.Trashcan.prototype.cleanBlockXML_ = function(xml) { } return Blockly.Xml.domToText(xmlBlock); }; + +exports = Trashcan; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..ed128d55c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -173,7 +173,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.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/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': 'es6', 'module': 'goog'}); 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'}); From 787145acf46c6feae193b521477d25c402b0ebca Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:40:48 -0700 Subject: [PATCH 070/291] Migrate core/toolbox/collapsible_category.js to ES6 const/let --- core/toolbox/collapsible_category.js | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index 979931848..4bf907278 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -92,7 +92,8 @@ Blockly.CollapsibleToolboxCategory.registrationName = 'collapsibleCategory'; * @override */ Blockly.CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() { - var cssConfig = Blockly.CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call(this); + const cssConfig = Blockly.CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call( + this); cssConfig['contents'] = 'blocklyToolboxContents'; return cssConfig; }; @@ -101,19 +102,20 @@ Blockly.CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() * @override */ Blockly.CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { - var contents = categoryDef['contents']; - var prevIsFlyoutItem = true; + const contents = categoryDef['contents']; + let prevIsFlyoutItem = true; if (categoryDef['custom']) { this.flyoutItems_ = categoryDef['custom']; } else if (contents) { - for (var i = 0, itemDef; (itemDef = contents[i]); i++) { + for (let i = 0; i < contents.length; i++) { + const itemDef = contents[i]; // Separators can exist as either a flyout item or a toolbox item so // decide where it goes based on the type of the previous item. if (!Blockly.registry.hasItem(Blockly.registry.Type.TOOLBOX_ITEM, itemDef['kind']) || (itemDef['kind'].toLowerCase() == Blockly.ToolboxSeparator.registrationName && prevIsFlyoutItem)) { - var flyoutItem = /** @type {Blockly.utils.toolbox.FlyoutItemInfo} */ (itemDef); + const flyoutItem = /** @type {Blockly.utils.toolbox.FlyoutItemInfo} */ (itemDef); this.flyoutItems_.push(flyoutItem); prevIsFlyoutItem = true; } else { @@ -131,8 +133,8 @@ Blockly.CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryD * @private */ Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { - var registryName = itemDef['kind']; - var categoryDef = /** @type {!Blockly.utils.toolbox.CategoryInfo} */ (itemDef); + let registryName = itemDef['kind']; + const categoryDef = /** @type {!Blockly.utils.toolbox.CategoryInfo} */ (itemDef); // Categories that are collapsible are created using a class registered under // a diffferent name. @@ -140,9 +142,9 @@ Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemD Blockly.utils.toolbox.isCategoryCollapsible(categoryDef)) { registryName = Blockly.CollapsibleToolboxCategory.registrationName; } - var ToolboxItemClass = Blockly.registry.getClass( + const ToolboxItemClass = Blockly.registry.getClass( Blockly.registry.Type.TOOLBOX_ITEM, registryName); - var toolboxItem = new ToolboxItemClass(itemDef, this.parentToolbox_, this); + const toolboxItem = new ToolboxItemClass(itemDef, this.parentToolbox_, this); this.toolboxItems_.push(toolboxItem); }; @@ -162,7 +164,7 @@ Blockly.CollapsibleToolboxCategory.prototype.init = function() { Blockly.CollapsibleToolboxCategory.prototype.createDom_ = function() { Blockly.CollapsibleToolboxCategory.superClass_.createDom_.call(this); - var subCategories = this.getChildToolboxItems(); + const subCategories = this.getChildToolboxItems(); this.subcategoriesDiv_ = this.createSubCategoriesDom_(subCategories); Blockly.utils.aria.setRole(this.subcategoriesDiv_, Blockly.utils.aria.Role.GROUP); @@ -175,7 +177,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createDom_ = function() { * @override */ Blockly.CollapsibleToolboxCategory.prototype.createIconDom_ = function() { - var toolboxIcon = document.createElement('span'); + const toolboxIcon = document.createElement('span'); if (!this.parentToolbox_.isHorizontal()) { Blockly.utils.dom.addClass(toolboxIcon, this.cssConfig_['icon']); toolboxIcon.style.visibility = 'visible'; @@ -192,13 +194,13 @@ Blockly.CollapsibleToolboxCategory.prototype.createIconDom_ = function() { * @protected */ Blockly.CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { - var contentsContainer = document.createElement('div'); + const contentsContainer = document.createElement('div'); Blockly.utils.dom.addClass(contentsContainer, this.cssConfig_['contents']); - for (var i = 0; i < subcategories.length; i++) { - var newCategory = subcategories[i]; + for (let i = 0; i < subcategories.length; i++) { + const newCategory = subcategories[i]; newCategory.init(); - var newCategoryDiv = newCategory.getDiv(); + const newCategoryDiv = newCategory.getDiv(); contentsContainer.appendChild(newCategoryDiv); if (newCategory.getClickTarget) { newCategory.getClickTarget().setAttribute('id', newCategory.getId()); @@ -236,7 +238,9 @@ Blockly.CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) */ Blockly.CollapsibleToolboxCategory.prototype.setVisible_ = function(isVisible) { this.htmlDiv_.style.display = isVisible ? 'block' : 'none'; - for (var i = 0, child; (child = this.getChildToolboxItems()[i]); i++) { + const childToolboxItems = this.getChildToolboxItems(); + for (let i = 0; i < childToolboxItems.length; i++) { + const child = childToolboxItems[i]; child.setVisible_(isVisible); } this.isHidden_ = !isVisible; From 41b53c50cd4c0e0c83a1d6cb0a28a8a4173048ff Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:41:01 -0700 Subject: [PATCH 071/291] Migrate core/toolbox/collapsible_category.js to goog.module --- core/toolbox/collapsible_category.js | 55 +++++++++++++++------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index 4bf907278..50c0a2d5d 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.CollapsibleToolboxCategory'); +goog.module('Blockly.CollapsibleToolboxCategory'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ICollapsibleToolboxItem'); goog.require('Blockly.registry'); @@ -37,7 +38,7 @@ goog.requireType('Blockly.IToolboxItem'); * @extends {Blockly.ToolboxCategory} * @implements {Blockly.ICollapsibleToolboxItem} */ -Blockly.CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { +const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { /** * Container for any child categories. * @type {?Element} @@ -59,11 +60,11 @@ Blockly.CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) */ this.toolboxItems_ = []; - Blockly.CollapsibleToolboxCategory.superClass_.constructor.call( + CollapsibleToolboxCategory.superClass_.constructor.call( this, categoryDef, toolbox, opt_parent); }; -Blockly.utils.object.inherits(Blockly.CollapsibleToolboxCategory, Blockly.ToolboxCategory); +Blockly.utils.object.inherits(CollapsibleToolboxCategory, Blockly.ToolboxCategory); /** * All the CSS class names that are used to create a collapsible @@ -80,19 +81,19 @@ Blockly.utils.object.inherits(Blockly.CollapsibleToolboxCategory, Blockly.Toolbo * contents:?string * }} */ -Blockly.CollapsibleToolboxCategory.CssConfig; +CollapsibleToolboxCategory.CssConfig; /** * Name used for registering a collapsible toolbox category. * @const {string} */ -Blockly.CollapsibleToolboxCategory.registrationName = 'collapsibleCategory'; +CollapsibleToolboxCategory.registrationName = 'collapsibleCategory'; /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() { - const cssConfig = Blockly.CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call( +CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() { + const cssConfig = CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call( this); cssConfig['contents'] = 'blocklyToolboxContents'; return cssConfig; @@ -101,7 +102,7 @@ Blockly.CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { +CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { const contents = categoryDef['contents']; let prevIsFlyoutItem = true; @@ -132,7 +133,7 @@ Blockly.CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryD * to create a toolbox item. * @private */ -Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { +CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { let registryName = itemDef['kind']; const categoryDef = /** @type {!Blockly.utils.toolbox.CategoryInfo} */ (itemDef); @@ -140,7 +141,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemD // a diffferent name. if (registryName.toUpperCase() == 'CATEGORY' && Blockly.utils.toolbox.isCategoryCollapsible(categoryDef)) { - registryName = Blockly.CollapsibleToolboxCategory.registrationName; + registryName = CollapsibleToolboxCategory.registrationName; } const ToolboxItemClass = Blockly.registry.getClass( Blockly.registry.Type.TOOLBOX_ITEM, registryName); @@ -151,8 +152,8 @@ Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemD /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.init = function() { - Blockly.CollapsibleToolboxCategory.superClass_.init.call(this); +CollapsibleToolboxCategory.prototype.init = function() { + CollapsibleToolboxCategory.superClass_.init.call(this); this.setExpanded(this.toolboxItemDef_['expanded'] == 'true' || this.toolboxItemDef_['expanded']); @@ -161,8 +162,8 @@ Blockly.CollapsibleToolboxCategory.prototype.init = function() { /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.createDom_ = function() { - Blockly.CollapsibleToolboxCategory.superClass_.createDom_.call(this); +CollapsibleToolboxCategory.prototype.createDom_ = function() { + CollapsibleToolboxCategory.superClass_.createDom_.call(this); const subCategories = this.getChildToolboxItems(); this.subcategoriesDiv_ = this.createSubCategoriesDom_(subCategories); @@ -176,7 +177,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createDom_ = function() { /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.createIconDom_ = function() { +CollapsibleToolboxCategory.prototype.createIconDom_ = function() { const toolboxIcon = document.createElement('span'); if (!this.parentToolbox_.isHorizontal()) { Blockly.utils.dom.addClass(toolboxIcon, this.cssConfig_['icon']); @@ -193,7 +194,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createIconDom_ = function() { * @return {!Element} The div holding all the subcategories. * @protected */ -Blockly.CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { +CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { const contentsContainer = document.createElement('div'); Blockly.utils.dom.addClass(contentsContainer, this.cssConfig_['contents']); @@ -215,7 +216,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function( * @param {boolean} isExpanded True to expand the category, false to close. * @public */ -Blockly.CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) { +CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) { if (this.expanded_ == isExpanded) { return; } @@ -236,7 +237,7 @@ Blockly.CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.setVisible_ = function(isVisible) { +CollapsibleToolboxCategory.prototype.setVisible_ = function(isVisible) { this.htmlDiv_.style.display = isVisible ? 'block' : 'none'; const childToolboxItems = this.getChildToolboxItems(); for (let i = 0; i < childToolboxItems.length; i++) { @@ -256,21 +257,21 @@ Blockly.CollapsibleToolboxCategory.prototype.setVisible_ = function(isVisible) { * is collapsed. * @public */ -Blockly.CollapsibleToolboxCategory.prototype.isExpanded = function() { +CollapsibleToolboxCategory.prototype.isExpanded = function() { return this.expanded_; }; /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.isCollapsible = function() { +CollapsibleToolboxCategory.prototype.isCollapsible = function() { return true; }; /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.onClick = function(_e) { +CollapsibleToolboxCategory.prototype.onClick = function(_e) { this.toggleExpanded(); }; @@ -278,14 +279,14 @@ Blockly.CollapsibleToolboxCategory.prototype.onClick = function(_e) { * Toggles whether or not the category is expanded. * @public */ -Blockly.CollapsibleToolboxCategory.prototype.toggleExpanded = function() { +CollapsibleToolboxCategory.prototype.toggleExpanded = function() { this.setExpanded(!this.expanded_); }; /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.getDiv = function() { +CollapsibleToolboxCategory.prototype.getDiv = function() { return this.htmlDiv_; }; @@ -293,10 +294,12 @@ Blockly.CollapsibleToolboxCategory.prototype.getDiv = function() { * Gets any children toolbox items. (ex. Gets the subcategories) * @return {!Array} The child toolbox items. */ -Blockly.CollapsibleToolboxCategory.prototype.getChildToolboxItems = function() { +CollapsibleToolboxCategory.prototype.getChildToolboxItems = function() { return this.toolboxItems_; }; Blockly.registry.register(Blockly.registry.Type.TOOLBOX_ITEM, - Blockly.CollapsibleToolboxCategory.registrationName, Blockly.CollapsibleToolboxCategory); + CollapsibleToolboxCategory.registrationName, CollapsibleToolboxCategory); + +exports = CollapsibleToolboxCategory; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..46ca32e0a 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -166,7 +166,7 @@ goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], [' goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); 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/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'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); 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']); From d7a864a498677c2cf733b0845f86c17c88bfd6e3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:42:18 -0700 Subject: [PATCH 072/291] Migrate core/toolbox/collapsible_category.js named requires --- core/toolbox/collapsible_category.js | 71 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index 50c0a2d5d..a35220fb8 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -13,30 +13,29 @@ goog.module('Blockly.CollapsibleToolboxCategory'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ICollapsibleToolboxItem'); -goog.require('Blockly.registry'); -goog.require('Blockly.ToolboxCategory'); -goog.require('Blockly.ToolboxItem'); -goog.require('Blockly.ToolboxSeparator'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.toolbox'); - -goog.requireType('Blockly.IToolbox'); -goog.requireType('Blockly.IToolboxItem'); +const ICollapsibleToolboxItem = goog.require('Blockly.ICollapsibleToolboxItem'); +const IToolbox = goog.requireType('Blockly.IToolbox'); +const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); +const ToolboxCategory = goog.require('Blockly.ToolboxCategory'); +const ToolboxItem = goog.require('Blockly.ToolboxItem'); +const ToolboxSeparator = goog.require('Blockly.ToolboxSeparator'); +const aria = goog.require('Blockly.utils.aria'); +const dom = goog.require('Blockly.utils.dom'); +const object = goog.require('Blockly.utils.object'); +const registry = goog.require('Blockly.registry'); +const toolbox = goog.require('Blockly.utils.toolbox'); /** * Class for a category in a toolbox that can be collapsed. - * @param {!Blockly.utils.toolbox.CategoryInfo} categoryDef The information needed + * @param {!toolbox.CategoryInfo} categoryDef The information needed * to create a category in the toolbox. - * @param {!Blockly.IToolbox} toolbox The parent toolbox for the category. - * @param {Blockly.ICollapsibleToolboxItem=} opt_parent The parent category or null if + * @param {!IToolbox} toolbox The parent toolbox for the category. + * @param {ICollapsibleToolboxItem=} opt_parent The parent category or null if * the category does not have a parent. * @constructor - * @extends {Blockly.ToolboxCategory} - * @implements {Blockly.ICollapsibleToolboxItem} + * @extends {ToolboxCategory} + * @implements {ICollapsibleToolboxItem} */ const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { /** @@ -55,7 +54,7 @@ const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { /** * The child toolbox items for this category. - * @type {!Array} + * @type {!Array} * @protected */ this.toolboxItems_ = []; @@ -64,7 +63,7 @@ const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { this, categoryDef, toolbox, opt_parent); }; -Blockly.utils.object.inherits(CollapsibleToolboxCategory, Blockly.ToolboxCategory); +object.inherits(CollapsibleToolboxCategory, ToolboxCategory); /** * All the CSS class names that are used to create a collapsible @@ -113,10 +112,10 @@ CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { const itemDef = contents[i]; // Separators can exist as either a flyout item or a toolbox item so // decide where it goes based on the type of the previous item. - if (!Blockly.registry.hasItem(Blockly.registry.Type.TOOLBOX_ITEM, itemDef['kind']) || - (itemDef['kind'].toLowerCase() == Blockly.ToolboxSeparator.registrationName && + if (!registry.hasItem(registry.Type.TOOLBOX_ITEM, itemDef['kind']) || + (itemDef['kind'].toLowerCase() == ToolboxSeparator.registrationName && prevIsFlyoutItem)) { - const flyoutItem = /** @type {Blockly.utils.toolbox.FlyoutItemInfo} */ (itemDef); + const flyoutItem = /** @type {toolbox.FlyoutItemInfo} */ (itemDef); this.flyoutItems_.push(flyoutItem); prevIsFlyoutItem = true; } else { @@ -129,22 +128,22 @@ CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { /** * Creates a toolbox item and adds it to the list of toolbox items. - * @param {!Blockly.utils.toolbox.ToolboxItemInfo} itemDef The information needed + * @param {!toolbox.ToolboxItemInfo} itemDef The information needed * to create a toolbox item. * @private */ CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { let registryName = itemDef['kind']; - const categoryDef = /** @type {!Blockly.utils.toolbox.CategoryInfo} */ (itemDef); + const categoryDef = /** @type {!toolbox.CategoryInfo} */ (itemDef); // Categories that are collapsible are created using a class registered under // a diffferent name. if (registryName.toUpperCase() == 'CATEGORY' && - Blockly.utils.toolbox.isCategoryCollapsible(categoryDef)) { + toolbox.isCategoryCollapsible(categoryDef)) { registryName = CollapsibleToolboxCategory.registrationName; } - const ToolboxItemClass = Blockly.registry.getClass( - Blockly.registry.Type.TOOLBOX_ITEM, registryName); + const ToolboxItemClass = registry.getClass( + registry.Type.TOOLBOX_ITEM, registryName); const toolboxItem = new ToolboxItemClass(itemDef, this.parentToolbox_, this); this.toolboxItems_.push(toolboxItem); }; @@ -167,8 +166,8 @@ CollapsibleToolboxCategory.prototype.createDom_ = function() { const subCategories = this.getChildToolboxItems(); this.subcategoriesDiv_ = this.createSubCategoriesDom_(subCategories); - Blockly.utils.aria.setRole(this.subcategoriesDiv_, - Blockly.utils.aria.Role.GROUP); + aria.setRole(this.subcategoriesDiv_, + aria.Role.GROUP); this.htmlDiv_.appendChild(this.subcategoriesDiv_); return this.htmlDiv_; @@ -180,7 +179,7 @@ CollapsibleToolboxCategory.prototype.createDom_ = function() { CollapsibleToolboxCategory.prototype.createIconDom_ = function() { const toolboxIcon = document.createElement('span'); if (!this.parentToolbox_.isHorizontal()) { - Blockly.utils.dom.addClass(toolboxIcon, this.cssConfig_['icon']); + dom.addClass(toolboxIcon, this.cssConfig_['icon']); toolboxIcon.style.visibility = 'visible'; } @@ -190,13 +189,13 @@ CollapsibleToolboxCategory.prototype.createIconDom_ = function() { /** * Create the DOM for all subcategories. - * @param {!Array} subcategories The subcategories. + * @param {!Array} subcategories The subcategories. * @return {!Element} The div holding all the subcategories. * @protected */ CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { const contentsContainer = document.createElement('div'); - Blockly.utils.dom.addClass(contentsContainer, this.cssConfig_['contents']); + dom.addClass(contentsContainer, this.cssConfig_['contents']); for (let i = 0; i < subcategories.length; i++) { const newCategory = subcategories[i]; @@ -228,8 +227,8 @@ CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) { this.subcategoriesDiv_.style.display = 'none'; this.closeIcon_(this.iconDom_); } - Blockly.utils.aria.setState(/** @type {!Element} */ (this.htmlDiv_), - Blockly.utils.aria.State.EXPANDED, isExpanded); + aria.setState(/** @type {!Element} */ (this.htmlDiv_), + aria.State.EXPANDED, isExpanded); this.parentToolbox_.handleToolboxItemResize(); }; @@ -292,14 +291,14 @@ CollapsibleToolboxCategory.prototype.getDiv = function() { /** * Gets any children toolbox items. (ex. Gets the subcategories) - * @return {!Array} The child toolbox items. + * @return {!Array} The child toolbox items. */ CollapsibleToolboxCategory.prototype.getChildToolboxItems = function() { return this.toolboxItems_; }; -Blockly.registry.register(Blockly.registry.Type.TOOLBOX_ITEM, +registry.register(registry.Type.TOOLBOX_ITEM, CollapsibleToolboxCategory.registrationName, CollapsibleToolboxCategory); exports = CollapsibleToolboxCategory; From c3521b7eb479781c371d5facd3837964ef4115d1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:42:23 -0700 Subject: [PATCH 073/291] clang-format core/toolbox/collapsible_category.js --- core/toolbox/collapsible_category.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index a35220fb8..fde610f0c 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -92,8 +92,8 @@ CollapsibleToolboxCategory.registrationName = 'collapsibleCategory'; * @override */ CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() { - const cssConfig = CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call( - this); + const cssConfig = + CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call(this); cssConfig['contents'] = 'blocklyToolboxContents'; return cssConfig; }; @@ -114,7 +114,7 @@ CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { // decide where it goes based on the type of the previous item. if (!registry.hasItem(registry.Type.TOOLBOX_ITEM, itemDef['kind']) || (itemDef['kind'].toLowerCase() == ToolboxSeparator.registrationName && - prevIsFlyoutItem)) { + prevIsFlyoutItem)) { const flyoutItem = /** @type {toolbox.FlyoutItemInfo} */ (itemDef); this.flyoutItems_.push(flyoutItem); prevIsFlyoutItem = true; @@ -142,8 +142,8 @@ CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { toolbox.isCategoryCollapsible(categoryDef)) { registryName = CollapsibleToolboxCategory.registrationName; } - const ToolboxItemClass = registry.getClass( - registry.Type.TOOLBOX_ITEM, registryName); + const ToolboxItemClass = + registry.getClass(registry.Type.TOOLBOX_ITEM, registryName); const toolboxItem = new ToolboxItemClass(itemDef, this.parentToolbox_, this); this.toolboxItems_.push(toolboxItem); }; @@ -154,7 +154,8 @@ CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { CollapsibleToolboxCategory.prototype.init = function() { CollapsibleToolboxCategory.superClass_.init.call(this); - this.setExpanded(this.toolboxItemDef_['expanded'] == 'true' || + this.setExpanded( + this.toolboxItemDef_['expanded'] == 'true' || this.toolboxItemDef_['expanded']); }; @@ -166,8 +167,7 @@ CollapsibleToolboxCategory.prototype.createDom_ = function() { const subCategories = this.getChildToolboxItems(); this.subcategoriesDiv_ = this.createSubCategoriesDom_(subCategories); - aria.setRole(this.subcategoriesDiv_, - aria.Role.GROUP); + aria.setRole(this.subcategoriesDiv_, aria.Role.GROUP); this.htmlDiv_.appendChild(this.subcategoriesDiv_); return this.htmlDiv_; @@ -193,7 +193,8 @@ CollapsibleToolboxCategory.prototype.createIconDom_ = function() { * @return {!Element} The div holding all the subcategories. * @protected */ -CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { +CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function( + subcategories) { const contentsContainer = document.createElement('div'); dom.addClass(contentsContainer, this.cssConfig_['contents']); @@ -227,8 +228,8 @@ CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) { this.subcategoriesDiv_.style.display = 'none'; this.closeIcon_(this.iconDom_); } - aria.setState(/** @type {!Element} */ (this.htmlDiv_), - aria.State.EXPANDED, isExpanded); + aria.setState( + /** @type {!Element} */ (this.htmlDiv_), aria.State.EXPANDED, isExpanded); this.parentToolbox_.handleToolboxItemResize(); }; @@ -298,7 +299,8 @@ CollapsibleToolboxCategory.prototype.getChildToolboxItems = function() { }; -registry.register(registry.Type.TOOLBOX_ITEM, - CollapsibleToolboxCategory.registrationName, CollapsibleToolboxCategory); +registry.register( + registry.Type.TOOLBOX_ITEM, CollapsibleToolboxCategory.registrationName, + CollapsibleToolboxCategory); exports = CollapsibleToolboxCategory; From 17bc528039beb9a6d11d2a3f66c3bdc107e883d4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:52:03 -0700 Subject: [PATCH 074/291] Add eslint disable for requireType in core/toolbox/collapsible_category.js --- core/toolbox/collapsible_category.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index fde610f0c..bc6ea253d 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -14,7 +14,9 @@ goog.module('Blockly.CollapsibleToolboxCategory'); goog.module.declareLegacyNamespace(); const ICollapsibleToolboxItem = goog.require('Blockly.ICollapsibleToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const IToolbox = goog.requireType('Blockly.IToolbox'); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); const ToolboxCategory = goog.require('Blockly.ToolboxCategory'); const ToolboxItem = goog.require('Blockly.ToolboxItem'); From 7f5ec67860777ec680e61555e4b919ae079b52d2 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 29 Jul 2021 16:50:38 -0700 Subject: [PATCH 075/291] Fix lint warnings in core/toolbox/collapsible_category.js --- core/toolbox/collapsible_category.js | 6 +++--- tests/deps.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index bc6ea253d..ae243f1e6 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -13,13 +13,13 @@ goog.module('Blockly.CollapsibleToolboxCategory'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const ICollapsibleToolboxItem = goog.require('Blockly.ICollapsibleToolboxItem'); /* eslint-disable-next-line no-unused-vars */ const IToolbox = goog.requireType('Blockly.IToolbox'); /* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); const ToolboxCategory = goog.require('Blockly.ToolboxCategory'); -const ToolboxItem = goog.require('Blockly.ToolboxItem'); const ToolboxSeparator = goog.require('Blockly.ToolboxSeparator'); const aria = goog.require('Blockly.utils.aria'); const dom = goog.require('Blockly.utils.dom'); @@ -56,7 +56,7 @@ const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { /** * The child toolbox items for this category. - * @type {!Array} + * @type {!Array} * @protected */ this.toolboxItems_ = []; @@ -191,7 +191,7 @@ CollapsibleToolboxCategory.prototype.createIconDom_ = function() { /** * Create the DOM for all subcategories. - * @param {!Array} subcategories The subcategories. + * @param {!Array} subcategories The subcategories. * @return {!Element} The div holding all the subcategories. * @protected */ diff --git a/tests/deps.js b/tests/deps.js index 46ca32e0a..613a2793d 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -166,7 +166,7 @@ goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], [' goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); 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'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); 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']); From 9f83ade1e7ba6413c6c32d7e0d623a4d36a64893 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:12:17 -0700 Subject: [PATCH 076/291] Migrate core/workspace_comment.js to ES6 const/let --- core/workspace_comment.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 5399dbe39..d71b60c60 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -185,7 +185,7 @@ Blockly.WorkspaceComment.prototype.getXY = function() { * @package */ Blockly.WorkspaceComment.prototype.moveBy = function(dx, dy) { - var event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); + const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); Blockly.Events.fire(event); @@ -275,7 +275,7 @@ Blockly.WorkspaceComment.prototype.setContent = function(content) { * @package */ Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { - var element = this.toXml(opt_noId); + const element = this.toXml(opt_noId); element.setAttribute('x', Math.round(this.xy_.x)); element.setAttribute('y', Math.round(this.xy_.y)); element.setAttribute('h', this.height_); @@ -292,7 +292,7 @@ Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { * @package */ Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { - var commentElement = Blockly.utils.xml.createElement('comment'); + const commentElement = Blockly.utils.xml.createElement('comment'); if (!opt_noId) { commentElement.id = this.id; } @@ -307,7 +307,7 @@ Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { */ Blockly.WorkspaceComment.fireCreateEvent = function(comment) { if (Blockly.Events.isEnabled()) { - var existingGroup = Blockly.Events.getGroup(); + const existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { Blockly.Events.setGroup(true); } @@ -330,13 +330,13 @@ Blockly.WorkspaceComment.fireCreateEvent = function(comment) { * @package */ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { - var info = Blockly.WorkspaceComment.parseAttributes(xmlComment); + const info = Blockly.WorkspaceComment.parseAttributes(xmlComment); - var comment = new Blockly.WorkspaceComment( + const comment = new Blockly.WorkspaceComment( workspace, info.content, info.h, info.w, info.id); - var commentX = parseInt(xmlComment.getAttribute('x'), 10); - var commentY = parseInt(xmlComment.getAttribute('y'), 10); + const commentX = parseInt(xmlComment.getAttribute('x'), 10); + const commentY = parseInt(xmlComment.getAttribute('y'), 10); if (!isNaN(commentX) && !isNaN(commentY)) { comment.moveBy(commentX, commentY); } @@ -353,8 +353,8 @@ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { * @package */ Blockly.WorkspaceComment.parseAttributes = function(xml) { - var xmlH = xml.getAttribute('h'); - var xmlW = xml.getAttribute('w'); + const xmlH = xml.getAttribute('h'); + const xmlW = xml.getAttribute('w'); return { // @type {string} From 2b6f5ba31a399d9a93711a6e8cb878480342dd4b Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:12:28 -0700 Subject: [PATCH 077/291] Migrate core/workspace_comment.js to goog.module --- core/workspace_comment.js | 61 +++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index d71b60c60..874877a89 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.WorkspaceComment'); +goog.module('Blockly.WorkspaceComment'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -25,6 +26,8 @@ goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.xml'); +goog.requireType('Blockly.Workspace'); + /** * Class for a workspace comment. @@ -36,7 +39,7 @@ goog.require('Blockly.utils.xml'); * create a new ID. * @constructor */ -Blockly.WorkspaceComment = function(workspace, content, height, width, opt_id) { +const WorkspaceComment = function(workspace, content, height, width, opt_id) { /** @type {string} */ this.id = (opt_id && !workspace.getCommentById(opt_id)) ? opt_id : Blockly.utils.genUid(); @@ -106,14 +109,14 @@ Blockly.WorkspaceComment = function(workspace, content, height, width, opt_id) { */ this.isComment = true; - Blockly.WorkspaceComment.fireCreateEvent(this); + WorkspaceComment.fireCreateEvent(this); }; /** * Dispose of this comment. * @package */ -Blockly.WorkspaceComment.prototype.dispose = function() { +WorkspaceComment.prototype.dispose = function() { if (!this.workspace) { // The comment has already been deleted. return; @@ -137,7 +140,7 @@ Blockly.WorkspaceComment.prototype.dispose = function() { * @return {number} Comment height. * @package */ -Blockly.WorkspaceComment.prototype.getHeight = function() { +WorkspaceComment.prototype.getHeight = function() { return this.height_; }; @@ -146,7 +149,7 @@ Blockly.WorkspaceComment.prototype.getHeight = function() { * @param {number} height Comment height. * @package */ -Blockly.WorkspaceComment.prototype.setHeight = function(height) { +WorkspaceComment.prototype.setHeight = function(height) { this.height_ = height; }; @@ -155,7 +158,7 @@ Blockly.WorkspaceComment.prototype.setHeight = function(height) { * @return {number} Comment width. * @package */ -Blockly.WorkspaceComment.prototype.getWidth = function() { +WorkspaceComment.prototype.getWidth = function() { return this.width_; }; @@ -164,7 +167,7 @@ Blockly.WorkspaceComment.prototype.getWidth = function() { * @param {number} width comment width. * @package */ -Blockly.WorkspaceComment.prototype.setWidth = function(width) { +WorkspaceComment.prototype.setWidth = function(width) { this.width_ = width; }; @@ -174,7 +177,7 @@ Blockly.WorkspaceComment.prototype.setWidth = function(width) { * This is not valid if the comment is currently being dragged. * @package */ -Blockly.WorkspaceComment.prototype.getXY = function() { +WorkspaceComment.prototype.getXY = function() { return new Blockly.utils.Coordinate(this.xy_.x, this.xy_.y); }; @@ -184,7 +187,7 @@ Blockly.WorkspaceComment.prototype.getXY = function() { * @param {number} dy Vertical offset, in workspace units. * @package */ -Blockly.WorkspaceComment.prototype.moveBy = function(dx, dy) { +WorkspaceComment.prototype.moveBy = function(dx, dy) { const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); @@ -196,7 +199,7 @@ Blockly.WorkspaceComment.prototype.moveBy = function(dx, dy) { * @return {boolean} True if deletable. * @package */ -Blockly.WorkspaceComment.prototype.isDeletable = function() { +WorkspaceComment.prototype.isDeletable = function() { return this.deletable_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -206,7 +209,7 @@ Blockly.WorkspaceComment.prototype.isDeletable = function() { * @param {boolean} deletable True if deletable. * @package */ -Blockly.WorkspaceComment.prototype.setDeletable = function(deletable) { +WorkspaceComment.prototype.setDeletable = function(deletable) { this.deletable_ = deletable; }; @@ -215,7 +218,7 @@ Blockly.WorkspaceComment.prototype.setDeletable = function(deletable) { * @return {boolean} True if movable. * @package */ -Blockly.WorkspaceComment.prototype.isMovable = function() { +WorkspaceComment.prototype.isMovable = function() { return this.movable_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -225,7 +228,7 @@ Blockly.WorkspaceComment.prototype.isMovable = function() { * @param {boolean} movable True if movable. * @package */ -Blockly.WorkspaceComment.prototype.setMovable = function(movable) { +WorkspaceComment.prototype.setMovable = function(movable) { this.movable_ = movable; }; @@ -233,7 +236,7 @@ Blockly.WorkspaceComment.prototype.setMovable = function(movable) { * Get whether this comment is editable or not. * @return {boolean} True if editable. */ -Blockly.WorkspaceComment.prototype.isEditable = function() { +WorkspaceComment.prototype.isEditable = function() { return this.editable_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -242,7 +245,7 @@ Blockly.WorkspaceComment.prototype.isEditable = function() { * Set whether this comment is editable or not. * @param {boolean} editable True if editable. */ -Blockly.WorkspaceComment.prototype.setEditable = function(editable) { +WorkspaceComment.prototype.setEditable = function(editable) { this.editable_ = editable; }; @@ -251,7 +254,7 @@ Blockly.WorkspaceComment.prototype.setEditable = function(editable) { * @return {string} Comment text. * @package */ -Blockly.WorkspaceComment.prototype.getContent = function() { +WorkspaceComment.prototype.getContent = function() { return this.content_; }; @@ -260,7 +263,7 @@ Blockly.WorkspaceComment.prototype.getContent = function() { * @param {string} content Comment content. * @package */ -Blockly.WorkspaceComment.prototype.setContent = function(content) { +WorkspaceComment.prototype.setContent = function(content) { if (this.content_ != content) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.COMMENT_CHANGE))( this, this.content_, content)); @@ -274,7 +277,7 @@ Blockly.WorkspaceComment.prototype.setContent = function(content) { * @return {!Element} Tree of XML elements. * @package */ -Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { +WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { const element = this.toXml(opt_noId); element.setAttribute('x', Math.round(this.xy_.x)); element.setAttribute('y', Math.round(this.xy_.y)); @@ -291,7 +294,7 @@ Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { * @return {!Element} Tree of XML elements. * @package */ -Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { +WorkspaceComment.prototype.toXml = function(opt_noId) { const commentElement = Blockly.utils.xml.createElement('comment'); if (!opt_noId) { commentElement.id = this.id; @@ -302,10 +305,10 @@ Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { /** * Fire a create event for the given workspace comment, if comments are enabled. - * @param {!Blockly.WorkspaceComment} comment The comment that was just created. + * @param {!WorkspaceComment} comment The comment that was just created. * @package */ -Blockly.WorkspaceComment.fireCreateEvent = function(comment) { +WorkspaceComment.fireCreateEvent = function(comment) { if (Blockly.Events.isEnabled()) { const existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { @@ -326,13 +329,13 @@ Blockly.WorkspaceComment.fireCreateEvent = function(comment) { * Decode an XML comment tag and create a comment on the workspace. * @param {!Element} xmlComment XML comment element. * @param {!Blockly.Workspace} workspace The workspace. - * @return {!Blockly.WorkspaceComment} The created workspace comment. + * @return {!WorkspaceComment} The created workspace comment. * @package */ -Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { - const info = Blockly.WorkspaceComment.parseAttributes(xmlComment); +WorkspaceComment.fromXml = function(xmlComment, workspace) { + const info = WorkspaceComment.parseAttributes(xmlComment); - const comment = new Blockly.WorkspaceComment( + const comment = new WorkspaceComment( workspace, info.content, info.h, info.w, info.id); const commentX = parseInt(xmlComment.getAttribute('x'), 10); @@ -341,7 +344,7 @@ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { comment.moveBy(commentX, commentY); } - Blockly.WorkspaceComment.fireCreateEvent(comment); + WorkspaceComment.fireCreateEvent(comment); return comment; }; @@ -352,7 +355,7 @@ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { * object containing the id, size, position, and comment string. * @package */ -Blockly.WorkspaceComment.parseAttributes = function(xml) { +WorkspaceComment.parseAttributes = function(xml) { const xmlH = xml.getAttribute('h'); const xmlW = xml.getAttribute('w'); @@ -377,3 +380,5 @@ Blockly.WorkspaceComment.parseAttributes = function(xml) { content: xml.textContent }; }; + +exports = WorkspaceComment; diff --git a/tests/deps.js b/tests/deps.js index 613a2793d..f17d995b9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -203,7 +203,7 @@ goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubbl 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.internalConstants', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); -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.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'], {'lang': 'es6', 'module': 'goog'}); 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']); goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From b159c382a0ddfe5466a7f919b03b8fcd0d57cd0e Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:15:33 -0700 Subject: [PATCH 078/291] Migrate core/workspace_comment.js named requires --- core/workspace_comment.js | 54 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 874877a89..971cbd0a7 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -13,7 +13,12 @@ goog.module('Blockly.WorkspaceComment'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Events'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const utils = goog.require('Blockly.utils'); +const xml = goog.require('Blockly.utils.xml'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.CommentChange'); /** @suppress {extraRequire} */ @@ -22,16 +27,11 @@ goog.require('Blockly.Events.CommentCreate'); goog.require('Blockly.Events.CommentDelete'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.CommentMove'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.xml'); - -goog.requireType('Blockly.Workspace'); /** * Class for a workspace comment. - * @param {!Blockly.Workspace} workspace The block's workspace. + * @param {!Workspace} workspace The block's workspace. * @param {string} content The content of this workspace comment. * @param {number} height Height of the comment. * @param {number} width Width of the comment. @@ -42,17 +42,17 @@ goog.requireType('Blockly.Workspace'); const WorkspaceComment = function(workspace, content, height, width, opt_id) { /** @type {string} */ this.id = (opt_id && !workspace.getCommentById(opt_id)) ? - opt_id : Blockly.utils.genUid(); + opt_id : utils.genUid(); workspace.addTopComment(this); /** * The comment's position in workspace units. (0, 0) is at the workspace's * origin; scale does not change this value. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @protected */ - this.xy_ = new Blockly.utils.Coordinate(0, 0); + this.xy_ = new Coordinate(0, 0); /** * The comment's height in workspace units. Scale does not change this value. @@ -69,7 +69,7 @@ const WorkspaceComment = function(workspace, content, height, width, opt_id) { this.width_ = width; /** - * @type {!Blockly.Workspace} + * @type {!Workspace} */ this.workspace = workspace; @@ -122,9 +122,9 @@ WorkspaceComment.prototype.dispose = function() { return; } - if (Blockly.Events.isEnabled()) { - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.COMMENT_DELETE))(this)); + if (Events.isEnabled()) { + Events.fire( + new (Events.get(Events.COMMENT_DELETE))(this)); } // Remove from the list of top comments and the comment database. @@ -173,12 +173,12 @@ WorkspaceComment.prototype.setWidth = function(width) { /** * Get stored location. - * @return {!Blockly.utils.Coordinate} The comment's stored location. + * @return {!Coordinate} The comment's stored location. * This is not valid if the comment is currently being dragged. * @package */ WorkspaceComment.prototype.getXY = function() { - return new Blockly.utils.Coordinate(this.xy_.x, this.xy_.y); + return new Coordinate(this.xy_.x, this.xy_.y); }; /** @@ -188,10 +188,10 @@ WorkspaceComment.prototype.getXY = function() { * @package */ WorkspaceComment.prototype.moveBy = function(dx, dy) { - const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); + const event = new (Events.get(Events.COMMENT_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); }; /** @@ -265,7 +265,7 @@ WorkspaceComment.prototype.getContent = function() { */ WorkspaceComment.prototype.setContent = function(content) { if (this.content_ != content) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.COMMENT_CHANGE))( + Events.fire(new (Events.get(Events.COMMENT_CHANGE))( this, this.content_, content)); this.content_ = content; } @@ -295,7 +295,7 @@ WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { * @package */ WorkspaceComment.prototype.toXml = function(opt_noId) { - const commentElement = Blockly.utils.xml.createElement('comment'); + const commentElement = xml.createElement('comment'); if (!opt_noId) { commentElement.id = this.id; } @@ -309,17 +309,17 @@ WorkspaceComment.prototype.toXml = function(opt_noId) { * @package */ WorkspaceComment.fireCreateEvent = function(comment) { - if (Blockly.Events.isEnabled()) { - const existingGroup = Blockly.Events.getGroup(); + if (Events.isEnabled()) { + const existingGroup = Events.getGroup(); if (!existingGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } try { - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.COMMENT_CREATE))(comment)); + Events.fire( + new (Events.get(Events.COMMENT_CREATE))(comment)); } finally { if (!existingGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } } } @@ -328,7 +328,7 @@ WorkspaceComment.fireCreateEvent = function(comment) { /** * Decode an XML comment tag and create a comment on the workspace. * @param {!Element} xmlComment XML comment element. - * @param {!Blockly.Workspace} workspace The workspace. + * @param {!Workspace} workspace The workspace. * @return {!WorkspaceComment} The created workspace comment. * @package */ From 568c5cb40f6af9d661d6965befa090a15535a721 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:16:47 -0700 Subject: [PATCH 079/291] clang-format core/workspace_comment.js --- core/workspace_comment.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 971cbd0a7..8d9009f94 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -41,8 +41,8 @@ goog.require('Blockly.Events.CommentMove'); */ const WorkspaceComment = function(workspace, content, height, width, opt_id) { /** @type {string} */ - this.id = (opt_id && !workspace.getCommentById(opt_id)) ? - opt_id : utils.genUid(); + this.id = + (opt_id && !workspace.getCommentById(opt_id)) ? opt_id : utils.genUid(); workspace.addTopComment(this); @@ -123,8 +123,7 @@ WorkspaceComment.prototype.dispose = function() { } if (Events.isEnabled()) { - Events.fire( - new (Events.get(Events.COMMENT_DELETE))(this)); + Events.fire(new (Events.get(Events.COMMENT_DELETE))(this)); } // Remove from the list of top comments and the comment database. @@ -219,8 +218,7 @@ WorkspaceComment.prototype.setDeletable = function(deletable) { * @package */ WorkspaceComment.prototype.isMovable = function() { - return this.movable_ && - !(this.workspace && this.workspace.options.readOnly); + return this.movable_ && !(this.workspace && this.workspace.options.readOnly); }; /** @@ -237,8 +235,7 @@ WorkspaceComment.prototype.setMovable = function(movable) { * @return {boolean} True if editable. */ WorkspaceComment.prototype.isEditable = function() { - return this.editable_ && - !(this.workspace && this.workspace.options.readOnly); + return this.editable_ && !(this.workspace && this.workspace.options.readOnly); }; /** @@ -265,8 +262,8 @@ WorkspaceComment.prototype.getContent = function() { */ WorkspaceComment.prototype.setContent = function(content) { if (this.content_ != content) { - Events.fire(new (Events.get(Events.COMMENT_CHANGE))( - this, this.content_, content)); + Events.fire( + new (Events.get(Events.COMMENT_CHANGE))(this, this.content_, content)); this.content_ = content; } }; @@ -315,8 +312,7 @@ WorkspaceComment.fireCreateEvent = function(comment) { Events.setGroup(true); } try { - Events.fire( - new (Events.get(Events.COMMENT_CREATE))(comment)); + Events.fire(new (Events.get(Events.COMMENT_CREATE))(comment)); } finally { if (!existingGroup) { Events.setGroup(false); @@ -335,8 +331,8 @@ WorkspaceComment.fireCreateEvent = function(comment) { WorkspaceComment.fromXml = function(xmlComment, workspace) { const info = WorkspaceComment.parseAttributes(xmlComment); - const comment = new WorkspaceComment( - workspace, info.content, info.h, info.w, info.id); + const comment = + new WorkspaceComment(workspace, info.content, info.h, info.w, info.id); const commentX = parseInt(xmlComment.getAttribute('x'), 10); const commentY = parseInt(xmlComment.getAttribute('y'), 10); From beff5e19bf5e8fab93a7fac6d5f76a34e6ee0c3b Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 15:41:33 -0700 Subject: [PATCH 080/291] Combine workspace_comment_render_svg.js with workspace_comment_svg.js --- core/requires.js | 1 - core/workspace_comment_render_svg.js | 463 --------------------- core/workspace_comment_svg.js | 450 ++++++++++++++++++++ tests/deps.js | 3 +- tests/playground.html | 1 - tests/playgrounds/advanced_playground.html | 1 - 6 files changed, 451 insertions(+), 468 deletions(-) delete mode 100644 core/workspace_comment_render_svg.js diff --git a/core/requires.js b/core/requires.js index 2ca295441..cc67f564a 100644 --- a/core/requires.js +++ b/core/requires.js @@ -42,7 +42,6 @@ goog.require('Blockly.Trashcan'); goog.require('Blockly.VariablesDynamic'); // Only need to require these two if you're using workspace comments. // goog.require('Blockly.WorkspaceCommentSvg'); -// goog.require('Blockly.WorkspaceCommentSvg.render'); // If zoom controls aren't required, then Blockly.inject's // "zoom"/"controls" configuration must be false. goog.require('Blockly.ZoomControls'); diff --git a/core/workspace_comment_render_svg.js b/core/workspace_comment_render_svg.js deleted file mode 100644 index 5097f0c92..000000000 --- a/core/workspace_comment_render_svg.js +++ /dev/null @@ -1,463 +0,0 @@ -/** - * @license - * Copyright 2017 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @fileoverview Methods for rendering a workspace comment as SVG - * @author fenichel@google.com (Rachel Fenichel) - */ -'use strict'; - -goog.provide('Blockly.WorkspaceCommentSvg.render'); - -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); - - -/** - * Size of the resize icon. - * @type {number} - * @const - * @private - */ -Blockly.WorkspaceCommentSvg.RESIZE_SIZE = 8; - -/** - * Radius of the border around the comment. - * @type {number} - * @const - * @private - */ -Blockly.WorkspaceCommentSvg.BORDER_RADIUS = 3; - -/** - * Offset from the foreignobject edge to the textarea edge. - * @type {number} - * @const - * @private - */ -Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET = 2; - -/** - * Offset from the top to make room for a top bar. - * @type {number} - * @const - * @private - */ -Blockly.WorkspaceCommentSvg.TOP_OFFSET = 10; - -/** - * Returns a bounding box describing the dimensions of this comment. - * @return {!{height: number, width: number}} Object with height and width - * properties in workspace units. - * @package - */ -Blockly.WorkspaceCommentSvg.prototype.getHeightWidth = function() { - return { width: this.getWidth(), height: this.getHeight() }; -}; - -/** - * Renders the workspace comment. - * @package - */ -Blockly.WorkspaceCommentSvg.prototype.render = function() { - if (this.rendered_) { - return; - } - - var size = this.getHeightWidth(); - - // Add text area - this.createEditor_(); - this.svgGroup_.appendChild(this.foreignObject_); - - this.svgHandleTarget_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, - { - 'class': 'blocklyCommentHandleTarget', - 'x': 0, - 'y': 0 - }); - this.svgGroup_.appendChild(this.svgHandleTarget_); - this.svgRectTarget_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, - { - 'class': 'blocklyCommentTarget', - 'x': 0, - 'y': 0, - 'rx': Blockly.WorkspaceCommentSvg.BORDER_RADIUS, - 'ry': Blockly.WorkspaceCommentSvg.BORDER_RADIUS - }); - this.svgGroup_.appendChild(this.svgRectTarget_); - - // Add the resize icon - this.addResizeDom_(); - if (this.isDeletable()) { - // Add the delete icon - this.addDeleteDom_(); - } - - this.setSize_(size.width, size.height); - - // Set the content - this.textarea_.value = this.content_; - - this.rendered_ = true; - - if (this.resizeGroup_) { - Blockly.browserEvents.conditionalBind( - this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); - } - - if (this.isDeletable()) { - Blockly.browserEvents.conditionalBind( - this.deleteGroup_, 'mousedown', this, this.deleteMouseDown_); - Blockly.browserEvents.conditionalBind( - this.deleteGroup_, 'mouseout', this, this.deleteMouseOut_); - Blockly.browserEvents.conditionalBind( - this.deleteGroup_, 'mouseup', this, this.deleteMouseUp_); - } -}; - -/** - * Create the text area for the comment. - * @return {!Element} The top-level node of the editor. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.createEditor_ = function() { - /* Create the editor. Here's the markup that will be generated: - - - - - - */ - this.foreignObject_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FOREIGNOBJECT, - { - 'x': 0, - 'y': Blockly.WorkspaceCommentSvg.TOP_OFFSET, - 'class': 'blocklyCommentForeignObject' - }, - null); - var body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); - body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); - body.className = 'blocklyMinimalBody'; - var textarea = document.createElementNS(Blockly.utils.dom.HTML_NS, 'textarea'); - textarea.className = 'blocklyCommentTextarea'; - textarea.setAttribute('dir', this.RTL ? 'RTL' : 'LTR'); - textarea.readOnly = !this.isEditable(); - body.appendChild(textarea); - this.textarea_ = textarea; - this.foreignObject_.appendChild(body); - // Don't zoom with mousewheel. - Blockly.browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { - e.stopPropagation(); - }); - Blockly.browserEvents.conditionalBind( - textarea, 'change', this, - function( - /* eslint-disable no-unused-vars */ e - /* eslint-enable no-unused-vars */) { - this.setContent(textarea.value); - }); - return this.foreignObject_; -}; - -/** - * Add the resize icon to the DOM - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.addResizeDom_ = function() { - this.resizeGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, - { - 'class': this.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE' - }, - this.svgGroup_); - var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE; - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.POLYGON, - {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())}, - this.resizeGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, - { - 'class': 'blocklyResizeLine', - 'x1': resizeSize / 3, 'y1': resizeSize - 1, - 'x2': resizeSize - 1, 'y2': resizeSize / 3 - }, this.resizeGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, - { - 'class': 'blocklyResizeLine', - 'x1': resizeSize * 2 / 3, 'y1': resizeSize - 1, - 'x2': resizeSize - 1, 'y2': resizeSize * 2 / 3 - }, this.resizeGroup_); -}; - -/** - * Add the delete icon to the DOM - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_ = function() { - this.deleteGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, - { - 'class': 'blocklyCommentDeleteIcon' - }, - this.svgGroup_); - this.deleteIconBorder_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, - { - 'class': 'blocklyDeleteIconShape', - 'r': '7', - 'cx': '7.5', - 'cy': '7.5' - }, - this.deleteGroup_); - // x icon. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, - { - 'x1': '5', 'y1': '10', - 'x2': '10', 'y2': '5', - 'stroke': '#fff', - 'stroke-width': '2' - }, - this.deleteGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, - { - 'x1': '5', 'y1': '5', - 'x2': '10', 'y2': '10', - 'stroke': '#fff', - 'stroke-width': '2' - }, - this.deleteGroup_); -}; - -/** - * Handle a mouse-down on comment's resize corner. - * @param {!Event} e Mouse down event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_ = function(e) { - this.unbindDragEvents_(); - if (Blockly.utils.isRightButton(e)) { - // No right-click. - e.stopPropagation(); - return; - } - // Left-click (or middle click) - this.workspace.startDrag(e, new Blockly.utils.Coordinate( - this.workspace.RTL ? -this.width_ : this.width_, this.height_)); - - this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( - document, 'mouseup', this, this.resizeMouseUp_); - this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( - document, 'mousemove', this, this.resizeMouseMove_); - Blockly.hideChaff(); - // This event has been handled. No need to bubble up to the document. - e.stopPropagation(); -}; - -/** - * Handle a mouse-down on comment's delete icon. - * @param {!Event} e Mouse down event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_ = function(e) { - // Highlight the delete icon. - Blockly.utils.dom.addClass( - /** @type {!Element} */ (this.deleteIconBorder_), - 'blocklyDeleteIconHighlighted'); - // This event has been handled. No need to bubble up to the document. - e.stopPropagation(); -}; - -/** - * Handle a mouse-out on comment's delete icon. - * @param {!Event} _e Mouse out event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_ = function(_e) { - // Restore highlight on the delete icon. - Blockly.utils.dom.removeClass( - /** @type {!Element} */ (this.deleteIconBorder_), - 'blocklyDeleteIconHighlighted'); -}; - -/** - * Handle a mouse-up on comment's delete icon. - * @param {!Event} e Mouse up event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_ = function(e) { - // Delete this comment. - this.dispose(true, true); - // This event has been handled. No need to bubble up to the document. - e.stopPropagation(); -}; - -/** - * Stop binding to the global mouseup and mousemove events. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.unbindDragEvents_ = function() { - if (this.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(this.onMouseUpWrapper_); - this.onMouseUpWrapper_ = null; - } - if (this.onMouseMoveWrapper_) { - Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); - this.onMouseMoveWrapper_ = null; - } -}; - -/** - * Handle a mouse-up event while dragging a comment's border or resize handle. - * @param {!Event} e Mouse up event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.resizeMouseUp_ = function(/* e */) { - Blockly.Touch.clearTouchIdentifier(); - this.unbindDragEvents_(); -}; - -/** - * Resize this comment to follow the mouse. - * @param {!Event} e Mouse move event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.resizeMouseMove_ = function(e) { - this.autoLayout_ = false; - var newXY = this.workspace.moveDrag(e); - this.setSize_(this.RTL ? -newXY.x : newXY.x, newXY.y); -}; - -/** - * Callback function triggered when the comment has resized. - * Resize the text area accordingly. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.resizeComment_ = function() { - var size = this.getHeightWidth(); - var topOffset = Blockly.WorkspaceCommentSvg.TOP_OFFSET; - var textOffset = Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET * 2; - - this.foreignObject_.setAttribute('width', size.width); - this.foreignObject_.setAttribute('height', size.height - topOffset); - if (this.RTL) { - this.foreignObject_.setAttribute('x', -size.width); - } - this.textarea_.style.width = (size.width - textOffset) + 'px'; - this.textarea_.style.height = (size.height - textOffset - topOffset) + 'px'; -}; - -/** - * Set size - * @param {number} width width of the container - * @param {number} height height of the container - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.setSize_ = function(width, height) { - // Minimum size of a comment. - width = Math.max(width, 45); - height = Math.max(height, 20 + Blockly.WorkspaceCommentSvg.TOP_OFFSET); - this.width_ = width; - this.height_ = height; - this.svgRect_.setAttribute('width', width); - this.svgRect_.setAttribute('height', height); - this.svgRectTarget_.setAttribute('width', width); - this.svgRectTarget_.setAttribute('height', height); - this.svgHandleTarget_.setAttribute('width', width); - this.svgHandleTarget_.setAttribute('height', - Blockly.WorkspaceCommentSvg.TOP_OFFSET); - if (this.RTL) { - this.svgRect_.setAttribute('transform', 'scale(-1 1)'); - this.svgRectTarget_.setAttribute('transform', 'scale(-1 1)'); - } - - var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE; - if (this.resizeGroup_) { - if (this.RTL) { - // Mirror the resize group. - this.resizeGroup_.setAttribute('transform', 'translate(' + - (-width + resizeSize) + ',' + (height - resizeSize) + ') scale(-1 1)'); - this.deleteGroup_.setAttribute('transform', 'translate(' + - (-width + resizeSize) + ',' + (-resizeSize) + ') scale(-1 1)'); - } else { - this.resizeGroup_.setAttribute('transform', 'translate(' + - (width - resizeSize) + ',' + - (height - resizeSize) + ')'); - this.deleteGroup_.setAttribute('transform', 'translate(' + - (width - resizeSize) + ',' + - (-resizeSize) + ')'); - } - } - - // Allow the contents to resize. - this.resizeComment_(); -}; - -/** - * Dispose of any rendered comment components. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.disposeInternal_ = function() { - this.textarea_ = null; - this.foreignObject_ = null; - this.svgRectTarget_ = null; - this.svgHandleTarget_ = null; - this.disposed_ = true; -}; - -/** - * Set the focus on the text area. - * @package - */ -Blockly.WorkspaceCommentSvg.prototype.setFocus = function() { - var comment = this; - this.focused_ = true; - // Defer CSS changes. - setTimeout(function() { - if (comment.disposed_) { - return; - } - comment.textarea_.focus(); - comment.addFocus(); - Blockly.utils.dom.addClass( - comment.svgRectTarget_, 'blocklyCommentTargetFocused'); - Blockly.utils.dom.addClass( - comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); - }, 0); -}; - -/** - * Remove focus from the text area. - * @package - */ -Blockly.WorkspaceCommentSvg.prototype.blurFocus = function() { - var comment = this; - this.focused_ = false; - // Defer CSS changes. - setTimeout(function() { - if (comment.disposed_) { - return; - } - - comment.textarea_.blur(); - comment.removeFocus(); - Blockly.utils.dom.removeClass( - comment.svgRectTarget_, 'blocklyCommentTargetFocused'); - Blockly.utils.dom.removeClass( - comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); - }, 0); -}; diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 401b840e1..84864422b 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -12,6 +12,9 @@ goog.provide('Blockly.WorkspaceCommentSvg'); +goog.require('Blockly'); +goog.require('Blockly.browserEvents'); +goog.require('Blockly.ContextMenu'); goog.require('Blockly.Css'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -22,6 +25,7 @@ goog.require('Blockly.Events.CommentDelete'); goog.require('Blockly.Events.CommentMove'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Selected'); +goog.require('Blockly.Touch'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -30,9 +34,11 @@ goog.require('Blockly.utils.Rect'); goog.require('Blockly.utils.Svg'); goog.require('Blockly.WorkspaceComment'); +goog.requireType('Blockly.BlockDragSurfaceSvg'); goog.requireType('Blockly.IBoundedElement'); goog.requireType('Blockly.IBubble'); goog.requireType('Blockly.ICopyable'); +goog.requireType('Blockly.Workspace'); /** @@ -116,6 +122,38 @@ Blockly.utils.object.inherits( */ Blockly.WorkspaceCommentSvg.DEFAULT_SIZE = 100; +/** + * Size of the resize icon. + * @type {number} + * @const + * @private + */ +Blockly.WorkspaceCommentSvg.RESIZE_SIZE = 8; + +/** + * Radius of the border around the comment. + * @type {number} + * @const + * @private + */ +Blockly.WorkspaceCommentSvg.BORDER_RADIUS = 3; + +/** + * Offset from the foreignobject edge to the textarea edge. + * @type {number} + * @const + * @private + */ +Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET = 2; + +/** + * Offset from the top to make room for a top bar. + * @type {number} + * @const + * @private + */ +Blockly.WorkspaceCommentSvg.TOP_OFFSET = 10; + /** * Dispose of this comment. * @package @@ -646,6 +684,418 @@ Blockly.WorkspaceCommentSvg.prototype.toCopyData = function() { return {xml: this.toXmlWithXY(), source: this.workspace, typeCounts: null}; }; +/** + * Returns a bounding box describing the dimensions of this comment. + * @return {!{height: number, width: number}} Object with height and width + * properties in workspace units. + * @package + */ +Blockly.WorkspaceCommentSvg.prototype.getHeightWidth = function() { + return { width: this.getWidth(), height: this.getHeight() }; +}; + +/** + * Renders the workspace comment. + * @package + */ +Blockly.WorkspaceCommentSvg.prototype.render = function() { + if (this.rendered_) { + return; + } + + var size = this.getHeightWidth(); + + // Add text area + this.createEditor_(); + this.svgGroup_.appendChild(this.foreignObject_); + + this.svgHandleTarget_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.RECT, + { + 'class': 'blocklyCommentHandleTarget', + 'x': 0, + 'y': 0 + }); + this.svgGroup_.appendChild(this.svgHandleTarget_); + this.svgRectTarget_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.RECT, + { + 'class': 'blocklyCommentTarget', + 'x': 0, + 'y': 0, + 'rx': Blockly.WorkspaceCommentSvg.BORDER_RADIUS, + 'ry': Blockly.WorkspaceCommentSvg.BORDER_RADIUS + }); + this.svgGroup_.appendChild(this.svgRectTarget_); + + // Add the resize icon + this.addResizeDom_(); + if (this.isDeletable()) { + // Add the delete icon + this.addDeleteDom_(); + } + + this.setSize_(size.width, size.height); + + // Set the content + this.textarea_.value = this.content_; + + this.rendered_ = true; + + if (this.resizeGroup_) { + Blockly.browserEvents.conditionalBind( + this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); + } + + if (this.isDeletable()) { + Blockly.browserEvents.conditionalBind( + this.deleteGroup_, 'mousedown', this, this.deleteMouseDown_); + Blockly.browserEvents.conditionalBind( + this.deleteGroup_, 'mouseout', this, this.deleteMouseOut_); + Blockly.browserEvents.conditionalBind( + this.deleteGroup_, 'mouseup', this, this.deleteMouseUp_); + } +}; + +/** + * Create the text area for the comment. + * @return {!Element} The top-level node of the editor. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.createEditor_ = function() { + /* Create the editor. Here's the markup that will be generated: + + + + + + */ + this.foreignObject_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.FOREIGNOBJECT, + { + 'x': 0, + 'y': Blockly.WorkspaceCommentSvg.TOP_OFFSET, + 'class': 'blocklyCommentForeignObject' + }, + null); + var body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); + body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); + body.className = 'blocklyMinimalBody'; + var textarea = document.createElementNS(Blockly.utils.dom.HTML_NS, 'textarea'); + textarea.className = 'blocklyCommentTextarea'; + textarea.setAttribute('dir', this.RTL ? 'RTL' : 'LTR'); + textarea.readOnly = !this.isEditable(); + body.appendChild(textarea); + this.textarea_ = textarea; + this.foreignObject_.appendChild(body); + // Don't zoom with mousewheel. + Blockly.browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { + e.stopPropagation(); + }); + Blockly.browserEvents.conditionalBind( + textarea, 'change', this, + function( + /* eslint-disable no-unused-vars */ e + /* eslint-enable no-unused-vars */) { + this.setContent(textarea.value); + }); + return this.foreignObject_; +}; + +/** + * Add the resize icon to the DOM + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.addResizeDom_ = function() { + this.resizeGroup_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.G, + { + 'class': this.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE' + }, + this.svgGroup_); + var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE; + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.POLYGON, + {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())}, + this.resizeGroup_); + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.LINE, + { + 'class': 'blocklyResizeLine', + 'x1': resizeSize / 3, 'y1': resizeSize - 1, + 'x2': resizeSize - 1, 'y2': resizeSize / 3 + }, this.resizeGroup_); + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.LINE, + { + 'class': 'blocklyResizeLine', + 'x1': resizeSize * 2 / 3, 'y1': resizeSize - 1, + 'x2': resizeSize - 1, 'y2': resizeSize * 2 / 3 + }, this.resizeGroup_); +}; + +/** + * Add the delete icon to the DOM + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_ = function() { + this.deleteGroup_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.G, + { + 'class': 'blocklyCommentDeleteIcon' + }, + this.svgGroup_); + this.deleteIconBorder_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.CIRCLE, + { + 'class': 'blocklyDeleteIconShape', + 'r': '7', + 'cx': '7.5', + 'cy': '7.5' + }, + this.deleteGroup_); + // x icon. + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.LINE, + { + 'x1': '5', 'y1': '10', + 'x2': '10', 'y2': '5', + 'stroke': '#fff', + 'stroke-width': '2' + }, + this.deleteGroup_); + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.LINE, + { + 'x1': '5', 'y1': '5', + 'x2': '10', 'y2': '10', + 'stroke': '#fff', + 'stroke-width': '2' + }, + this.deleteGroup_); +}; + +/** + * Handle a mouse-down on comment's resize corner. + * @param {!Event} e Mouse down event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_ = function(e) { + this.unbindDragEvents_(); + if (Blockly.utils.isRightButton(e)) { + // No right-click. + e.stopPropagation(); + return; + } + // Left-click (or middle click) + this.workspace.startDrag(e, new Blockly.utils.Coordinate( + this.workspace.RTL ? -this.width_ : this.width_, this.height_)); + + this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + document, 'mouseup', this, this.resizeMouseUp_); + this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + document, 'mousemove', this, this.resizeMouseMove_); + Blockly.hideChaff(); + // This event has been handled. No need to bubble up to the document. + e.stopPropagation(); +}; + +/** + * Handle a mouse-down on comment's delete icon. + * @param {!Event} e Mouse down event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_ = function(e) { + // Highlight the delete icon. + Blockly.utils.dom.addClass( + /** @type {!Element} */ (this.deleteIconBorder_), + 'blocklyDeleteIconHighlighted'); + // This event has been handled. No need to bubble up to the document. + e.stopPropagation(); +}; + +/** + * Handle a mouse-out on comment's delete icon. + * @param {!Event} _e Mouse out event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_ = function(_e) { + // Restore highlight on the delete icon. + Blockly.utils.dom.removeClass( + /** @type {!Element} */ (this.deleteIconBorder_), + 'blocklyDeleteIconHighlighted'); +}; + +/** + * Handle a mouse-up on comment's delete icon. + * @param {!Event} e Mouse up event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_ = function(e) { + // Delete this comment. + this.dispose(true, true); + // This event has been handled. No need to bubble up to the document. + e.stopPropagation(); +}; + +/** + * Stop binding to the global mouseup and mousemove events. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.unbindDragEvents_ = function() { + if (this.onMouseUpWrapper_) { + Blockly.browserEvents.unbind(this.onMouseUpWrapper_); + this.onMouseUpWrapper_ = null; + } + if (this.onMouseMoveWrapper_) { + Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); + this.onMouseMoveWrapper_ = null; + } +}; + +/** + * Handle a mouse-up event while dragging a comment's border or resize handle. + * @param {!Event} e Mouse up event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.resizeMouseUp_ = function(/* e */) { + Blockly.Touch.clearTouchIdentifier(); + this.unbindDragEvents_(); +}; + +/** + * Resize this comment to follow the mouse. + * @param {!Event} e Mouse move event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.resizeMouseMove_ = function(e) { + this.autoLayout_ = false; + var newXY = this.workspace.moveDrag(e); + this.setSize_(this.RTL ? -newXY.x : newXY.x, newXY.y); +}; + +/** + * Callback function triggered when the comment has resized. + * Resize the text area accordingly. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.resizeComment_ = function() { + var size = this.getHeightWidth(); + var topOffset = Blockly.WorkspaceCommentSvg.TOP_OFFSET; + var textOffset = Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET * 2; + + this.foreignObject_.setAttribute('width', size.width); + this.foreignObject_.setAttribute('height', size.height - topOffset); + if (this.RTL) { + this.foreignObject_.setAttribute('x', -size.width); + } + this.textarea_.style.width = (size.width - textOffset) + 'px'; + this.textarea_.style.height = (size.height - textOffset - topOffset) + 'px'; +}; + +/** + * Set size + * @param {number} width width of the container + * @param {number} height height of the container + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.setSize_ = function(width, height) { + // Minimum size of a comment. + width = Math.max(width, 45); + height = Math.max(height, 20 + Blockly.WorkspaceCommentSvg.TOP_OFFSET); + this.width_ = width; + this.height_ = height; + this.svgRect_.setAttribute('width', width); + this.svgRect_.setAttribute('height', height); + this.svgRectTarget_.setAttribute('width', width); + this.svgRectTarget_.setAttribute('height', height); + this.svgHandleTarget_.setAttribute('width', width); + this.svgHandleTarget_.setAttribute('height', + Blockly.WorkspaceCommentSvg.TOP_OFFSET); + if (this.RTL) { + this.svgRect_.setAttribute('transform', 'scale(-1 1)'); + this.svgRectTarget_.setAttribute('transform', 'scale(-1 1)'); + } + + var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE; + if (this.resizeGroup_) { + if (this.RTL) { + // Mirror the resize group. + this.resizeGroup_.setAttribute('transform', 'translate(' + + (-width + resizeSize) + ',' + (height - resizeSize) + ') scale(-1 1)'); + this.deleteGroup_.setAttribute('transform', 'translate(' + + (-width + resizeSize) + ',' + (-resizeSize) + ') scale(-1 1)'); + } else { + this.resizeGroup_.setAttribute('transform', 'translate(' + + (width - resizeSize) + ',' + + (height - resizeSize) + ')'); + this.deleteGroup_.setAttribute('transform', 'translate(' + + (width - resizeSize) + ',' + + (-resizeSize) + ')'); + } + } + + // Allow the contents to resize. + this.resizeComment_(); +}; + +/** + * Dispose of any rendered comment components. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.disposeInternal_ = function() { + this.textarea_ = null; + this.foreignObject_ = null; + this.svgRectTarget_ = null; + this.svgHandleTarget_ = null; + this.disposed_ = true; +}; + +/** + * Set the focus on the text area. + * @package + */ +Blockly.WorkspaceCommentSvg.prototype.setFocus = function() { + var comment = this; + this.focused_ = true; + // Defer CSS changes. + setTimeout(function() { + if (comment.disposed_) { + return; + } + comment.textarea_.focus(); + comment.addFocus(); + Blockly.utils.dom.addClass( + comment.svgRectTarget_, 'blocklyCommentTargetFocused'); + Blockly.utils.dom.addClass( + comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); + }, 0); +}; + +/** + * Remove focus from the text area. + * @package + */ +Blockly.WorkspaceCommentSvg.prototype.blurFocus = function() { + var comment = this; + this.focused_ = false; + // Defer CSS changes. + setTimeout(function() { + if (comment.disposed_) { + return; + } + + comment.textarea_.blur(); + comment.removeFocus(); + Blockly.utils.dom.removeClass( + comment.svgRectTarget_, 'blocklyCommentTargetFocused'); + Blockly.utils.dom.removeClass( + comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); + }, 0); +}; + /** * CSS for workspace comment. See css.js for use. */ diff --git a/tests/deps.js b/tests/deps.js index f17d995b9..a729ae7b9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -204,8 +204,7 @@ goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.u 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.internalConstants', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); 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'], {'lang': 'es6', 'module': 'goog'}); -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']); +goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly', 'Blockly.ContextMenu', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.Touch', 'Blockly.WorkspaceComment', 'Blockly.browserEvents', '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.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'}); diff --git a/tests/playground.html b/tests/playground.html index 11179a0db..b53e76ea8 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -71,7 +71,6 @@