From 042b235764e98e359d67672121170d487b618534 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:52:17 -0700 Subject: [PATCH 001/172] 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/172] 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/172] 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/172] 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/172] 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 c3eaf1afc5061f8d20665355b070724e2acfd584 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:44:28 -0700 Subject: [PATCH 006/172] Migrate core/field_textinput.js to ES6 const/let --- core/field_textinput.js | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index b2153b65e..c4c55dfcf 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -109,7 +109,7 @@ Blockly.FieldTextInput.prototype.DEFAULT_VALUE = ''; * @nocollapse */ Blockly.FieldTextInput.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -150,12 +150,12 @@ Blockly.FieldTextInput.prototype.initView = function() { if (this.getConstants().FULL_BLOCK_FIELDS) { // Step one: figure out if this is the only field on this block. // Rendering is quite different in that case. - var nFields = 0; - var nConnections = 0; + let nFields = 0; + let nConnections = 0; // Count the number of fields, excluding text fields - for (var i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { - for (var j = 0; (input.fieldRow[j]); j++) { + for (let i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { + for (let j = 0; (input.fieldRow[j]); j++) { nFields ++; } if (input.connection) { @@ -203,7 +203,7 @@ Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { if (this.isBeingEdited_) { this.isTextValid_ = false; - var oldValue = this.value_; + const oldValue = this.value_; // Revert value when the text becomes invalid. this.value_ = this.htmlInput_.untypedDefaultValue_; if (this.sourceBlock_ && Blockly.Events.isEnabled()) { @@ -257,7 +257,7 @@ Blockly.FieldTextInput.prototype.render_ = function() { // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { this.resizeEditor_(); - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); Blockly.utils.aria.setState(htmlInput, @@ -296,7 +296,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; - var quietInput = opt_quietInput || false; + const quietInput = opt_quietInput || false; if (!quietInput && (Blockly.utils.userAgent.MOBILE || Blockly.utils.userAgent.ANDROID || Blockly.utils.userAgent.IPAD)) { @@ -343,28 +343,28 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { */ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { Blockly.Events.setGroup(true); - var div = Blockly.WidgetDiv.DIV; + const div = Blockly.WidgetDiv.DIV; Blockly.utils.dom.addClass(this.getClickTarget_(), 'editing'); - var htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); + const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); - var scale = this.workspace_.getScale(); - var fontSize = + const scale = this.workspace_.getScale(); + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - var borderRadius = + let borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { - var bBox = this.getScaledBBox(); + const bBox = this.getScaledBBox(); // Override border radius. borderRadius = (bBox.bottom - bBox.top) / 2 + 'px'; // Pull stroke colour from the existing shadow block - var strokeColour = this.sourceBlock_.getParent() ? + const strokeColour = this.sourceBlock_.getParent() ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; htmlInput.style.border = (1 * scale) + 'px solid ' + strokeColour; @@ -409,7 +409,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { // Actual disposal. this.unbindInputEvents_(); - var style = Blockly.WidgetDiv.DIV.style; + const style = Blockly.WidgetDiv.DIV.style; style.width = 'auto'; style.height = 'auto'; style.fontSize = ''; @@ -477,11 +477,11 @@ Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { * @private */ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { - var text = this.htmlInput_.value; + const text = this.htmlInput_.value; if (text !== this.htmlInput_.oldValue_) { this.htmlInput_.oldValue_ = text; - var value = this.getValueFromEditorText_(text); + const value = this.getValueFromEditorText_(text); this.setValue(value); this.forceRerender(); this.resizeEditor_(); @@ -512,15 +512,15 @@ Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { * @protected */ Blockly.FieldTextInput.prototype.resizeEditor_ = function() { - var div = Blockly.WidgetDiv.DIV; - var bBox = this.getScaledBBox(); + const div = Blockly.WidgetDiv.DIV; + const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; div.style.height = bBox.bottom - bBox.top + 'px'; // In RTL mode block fields and LTR input fields the left edge moves, // whereas the right edge is fixed. Reposition the editor. - var x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; - var xy = new Blockly.utils.Coordinate(x, bBox.top); + const x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; + const xy = new Blockly.utils.Coordinate(x, bBox.top); div.style.left = xy.x + 'px'; div.style.top = xy.y + 'px'; From d2a43460d0de014ee671de42f123a6f4ae1bc523 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:49:08 -0700 Subject: [PATCH 007/172] Migrate core/field_textinput.js to goog.module --- core/field_textinput.js | 77 +++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index c4c55dfcf..4585ba382 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldTextInput'); +goog.module('Blockly.FieldTextInput'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.DropDownDiv'); @@ -46,7 +47,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { +const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * Allow browser to spellcheck this field. * @type {boolean} @@ -54,7 +55,7 @@ Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.spellcheck_ = true; - Blockly.FieldTextInput.superClass_.constructor.call(this, + FieldTextInput.superClass_.constructor.call(this, opt_value, opt_validator, opt_config); /** @@ -91,24 +92,24 @@ Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.workspace_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldTextInput, Blockly.Field); +Blockly.utils.object.inherits(FieldTextInput, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldTextInput.prototype.DEFAULT_VALUE = ''; +FieldTextInput.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldTextInput from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and spellcheck). - * @return {!Blockly.FieldTextInput} The new field instance. + * @return {!FieldTextInput} The new field instance. * @package * @nocollapse */ -Blockly.FieldTextInput.fromJson = function(options) { +FieldTextInput.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. @@ -120,24 +121,24 @@ Blockly.FieldTextInput.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldTextInput.prototype.SERIALIZABLE = true; +FieldTextInput.prototype.SERIALIZABLE = true; /** * Pixel size of input border radius. * Should match blocklyText's border-radius in CSS. */ -Blockly.FieldTextInput.BORDERRADIUS = 4; +FieldTextInput.BORDERRADIUS = 4; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldTextInput.prototype.CURSOR = 'text'; +FieldTextInput.prototype.CURSOR = 'text'; /** * @override */ -Blockly.FieldTextInput.prototype.configure_ = function(config) { - Blockly.FieldTextInput.superClass_.configure_.call(this, config); +FieldTextInput.prototype.configure_ = function(config) { + FieldTextInput.superClass_.configure_.call(this, config); if (typeof config['spellcheck'] == 'boolean') { this.spellcheck_ = config['spellcheck']; } @@ -146,7 +147,7 @@ Blockly.FieldTextInput.prototype.configure_ = function(config) { /** * @override */ -Blockly.FieldTextInput.prototype.initView = function() { +FieldTextInput.prototype.initView = function() { if (this.getConstants().FULL_BLOCK_FIELDS) { // Step one: figure out if this is the only field on this block. // Rendering is quite different in that case. @@ -184,7 +185,7 @@ Blockly.FieldTextInput.prototype.initView = function() { * @return {*} A valid string, or null if invalid. * @protected */ -Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { +FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -200,7 +201,7 @@ Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { * the htmlInput_. * @protected */ -Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { +FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { if (this.isBeingEdited_) { this.isTextValid_ = false; const oldValue = this.value_; @@ -221,7 +222,7 @@ Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { * that this is a string. * @protected */ -Blockly.FieldTextInput.prototype.doValueUpdate_ = function(newValue) { +FieldTextInput.prototype.doValueUpdate_ = function(newValue) { this.isTextValid_ = true; this.value_ = newValue; if (!this.isBeingEdited_) { @@ -234,7 +235,7 @@ Blockly.FieldTextInput.prototype.doValueUpdate_ = function(newValue) { * Updates text field to match the colour/style of the block. * @package */ -Blockly.FieldTextInput.prototype.applyColour = function() { +FieldTextInput.prototype.applyColour = function() { if (this.sourceBlock_ && this.getConstants().FULL_BLOCK_FIELDS) { if (this.borderRect_) { this.borderRect_.setAttribute('stroke', @@ -251,8 +252,8 @@ Blockly.FieldTextInput.prototype.applyColour = function() { * field's value. * @protected */ -Blockly.FieldTextInput.prototype.render_ = function() { - Blockly.FieldTextInput.superClass_.render_.call(this); +FieldTextInput.prototype.render_ = function() { + FieldTextInput.superClass_.render_.call(this); // This logic is done in render_ rather than doValueInvalid_ or // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { @@ -274,7 +275,7 @@ Blockly.FieldTextInput.prototype.render_ = function() { * Set whether this field is spellchecked by the browser. * @param {boolean} check True if checked. */ -Blockly.FieldTextInput.prototype.setSpellcheck = function(check) { +FieldTextInput.prototype.setSpellcheck = function(check) { if (check == this.spellcheck_) { return; } @@ -292,7 +293,7 @@ Blockly.FieldTextInput.prototype.setSpellcheck = function(check) { * focus. Defaults to false. * @protected */ -Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, +FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; @@ -311,7 +312,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, * Mobile browsers have issues with in-line textareas (focus and keyboards). * @private */ -Blockly.FieldTextInput.prototype.showPromptEditor_ = function() { +FieldTextInput.prototype.showPromptEditor_ = function() { Blockly.prompt(Blockly.Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { this.setValue(this.getValueFromEditorText_(text)); @@ -324,7 +325,7 @@ Blockly.FieldTextInput.prototype.showPromptEditor_ = function() { * focus. * @private */ -Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { +FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { Blockly.WidgetDiv.show( this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); @@ -341,7 +342,7 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { * @return {!HTMLElement} The newly created text input editor. * @protected */ -Blockly.FieldTextInput.prototype.widgetCreate_ = function() { +FieldTextInput.prototype.widgetCreate_ = function() { Blockly.Events.setGroup(true); const div = Blockly.WidgetDiv.DIV; @@ -356,7 +357,7 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; let borderRadius = - (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + (FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { const bBox = this.getScaledBBox(); @@ -395,7 +396,7 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { * DOM-references belonging to the editor. * @protected */ -Blockly.FieldTextInput.prototype.widgetDispose_ = function() { +FieldTextInput.prototype.widgetDispose_ = function() { // Non-disposal related things that we do when the editor closes. this.isBeingEdited_ = false; this.isTextValid_ = true; @@ -426,7 +427,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { * handlers will be bound. * @protected */ -Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { +FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { // Trap Enter without IME and Esc to hide. this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); @@ -439,7 +440,7 @@ Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { * Unbind handlers for user input and workspace size changes. * @protected */ -Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() { +FieldTextInput.prototype.unbindInputEvents_ = function() { if (this.onKeyDownWrapper_) { Blockly.browserEvents.unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; @@ -455,7 +456,7 @@ Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() { * @param {!Event} e Keyboard event. * @protected */ -Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { +FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { if (e.keyCode == Blockly.utils.KeyCodes.ENTER) { Blockly.WidgetDiv.hide(); Blockly.DropDownDiv.hideWithoutAnimation(); @@ -476,7 +477,7 @@ Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { * @param {!Event} _e Keyboard event. * @private */ -Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { +FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { const text = this.htmlInput_.value; if (text !== this.htmlInput_.oldValue_) { this.htmlInput_.oldValue_ = text; @@ -495,7 +496,7 @@ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { * @param {*} newValue New value. * @protected */ -Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { +FieldTextInput.prototype.setEditorValue_ = function(newValue) { this.isDirty_ = true; if (this.isBeingEdited_) { // In the case this method is passed an invalid value, we still @@ -511,7 +512,7 @@ Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { * Resize the editor to fit the text. * @protected */ -Blockly.FieldTextInput.prototype.resizeEditor_ = function() { +FieldTextInput.prototype.resizeEditor_ = function() { const div = Blockly.WidgetDiv.DIV; const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; @@ -531,7 +532,7 @@ Blockly.FieldTextInput.prototype.resizeEditor_ = function() { * @return {boolean} True if the field is tab navigable. * @override */ -Blockly.FieldTextInput.prototype.isTabNavigable = function() { +FieldTextInput.prototype.isTabNavigable = function() { return true; }; @@ -544,7 +545,7 @@ Blockly.FieldTextInput.prototype.isTabNavigable = function() { * @protected * @override */ -Blockly.FieldTextInput.prototype.getText_ = function() { +FieldTextInput.prototype.getText_ = function() { if (this.isBeingEdited_ && this.htmlInput_) { // We are currently editing, return the HTML input value instead. return this.htmlInput_.value; @@ -561,7 +562,7 @@ Blockly.FieldTextInput.prototype.getText_ = function() { * @return {string} The text to show on the HTML input. * @protected */ -Blockly.FieldTextInput.prototype.getEditorText_ = function(value) { +FieldTextInput.prototype.getEditorText_ = function(value) { return String(value); }; @@ -575,8 +576,10 @@ Blockly.FieldTextInput.prototype.getEditorText_ = function(value) { * @return {*} The value to store. * @protected */ -Blockly.FieldTextInput.prototype.getValueFromEditorText_ = function(text) { +FieldTextInput.prototype.getValueFromEditorText_ = function(text) { return text; }; -Blockly.fieldRegistry.register('field_input', Blockly.FieldTextInput); +Blockly.fieldRegistry.register('field_input', FieldTextInput); + +exports = FieldTextInput; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..0e96aa2c3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -59,7 +59,7 @@ goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabe goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); -goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); From 9134d45d94e3d3506e7b1b9d3bb2bac18d8b45b8 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:35:59 -0700 Subject: [PATCH 008/172] Migrate core/menu.js to ES6 const/let --- core/menu.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/core/menu.js b/core/menu.js index 97f47248a..011199252 100644 --- a/core/menu.js +++ b/core/menu.js @@ -118,7 +118,8 @@ Blockly.Menu.prototype.addChild = function(menuItem) { * @param {!Element} container Element upon which to append this menu. */ Blockly.Menu.prototype.render = function(container) { - var element = /** @type {!HTMLDivElement} */ (document.createElement('div')); + const element = /** @type {!HTMLDivElement} */ (document.createElement( + 'div')); // goog-menu is deprecated, use blocklyMenu. May 2020. element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; @@ -128,7 +129,7 @@ Blockly.Menu.prototype.render = function(container) { this.element_ = element; // Add menu items. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { element.appendChild(menuItem.createDom()); } @@ -161,7 +162,7 @@ Blockly.Menu.prototype.getElement = function() { * @package */ Blockly.Menu.prototype.focus = function() { - var el = this.getElement(); + const el = this.getElement(); if (el) { el.focus({preventScroll:true}); Blockly.utils.dom.addClass(el, 'blocklyFocused'); @@ -173,7 +174,7 @@ Blockly.Menu.prototype.focus = function() { * @private */ Blockly.Menu.prototype.blur_ = function() { - var el = this.getElement(); + const el = this.getElement(); if (el) { el.blur(); Blockly.utils.dom.removeClass(el, 'blocklyFocused'); @@ -216,7 +217,7 @@ Blockly.Menu.prototype.dispose = function() { } // Remove menu items. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { menuItem.dispose(); } this.element_ = null; @@ -232,7 +233,7 @@ Blockly.Menu.prototype.dispose = function() { * @private */ Blockly.Menu.prototype.getMenuItem_ = function(elem) { - var menuElem = this.getElement(); + const menuElem = this.getElement(); // Node might be the menu border (resulting in no associated menu item), or // a menu item's div, or some element within the menu item. // Walk up parents until one meets either the menu's root element, or @@ -240,7 +241,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { while (elem && elem != menuElem) { if (Blockly.utils.dom.hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { return menuItem; } @@ -259,7 +260,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { * @package */ Blockly.Menu.prototype.setHighlighted = function(item) { - var currentHighlighted = this.highlightedItem_; + const currentHighlighted = this.highlightedItem_; if (currentHighlighted) { currentHighlighted.setHighlighted(false); this.highlightedItem_ = null; @@ -269,7 +270,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { this.highlightedItem_ = item; // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. - var el = /** @type {!Element} */ (this.getElement()); + const el = /** @type {!Element} */ (this.getElement()); Blockly.utils.style.scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); @@ -284,7 +285,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { * @package */ Blockly.Menu.prototype.highlightNext = function() { - var index = this.menuItems_.indexOf(this.highlightedItem_); + const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index, 1); }; @@ -294,7 +295,7 @@ Blockly.Menu.prototype.highlightNext = function() { * @package */ Blockly.Menu.prototype.highlightPrevious = function() { - var index = this.menuItems_.indexOf(this.highlightedItem_); + const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1); }; @@ -322,8 +323,8 @@ Blockly.Menu.prototype.highlightLast_ = function() { * @private */ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { - var index = startIndex + delta; - var menuItem; + let index = startIndex + delta; + let menuItem; while ((menuItem = this.menuItems_[index])) { if (menuItem.isEnabled()) { this.setHighlighted(menuItem); @@ -341,7 +342,7 @@ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { * @private */ Blockly.Menu.prototype.handleMouseOver_ = function(e) { - var menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); + const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { if (menuItem.isEnabled()) { @@ -360,11 +361,11 @@ Blockly.Menu.prototype.handleMouseOver_ = function(e) { * @private */ Blockly.Menu.prototype.handleClick_ = function(e) { - var oldCoords = this.openingCoords; + const oldCoords = this.openingCoords; // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; if (oldCoords && typeof e.clientX == 'number') { - var newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); if (Blockly.utils.Coordinate.distance(oldCoords, newCoords) < 1) { // This menu was opened by a mousedown and we're handling the consequent // click event. The coords haven't changed, meaning this was the same @@ -374,7 +375,7 @@ Blockly.Menu.prototype.handleClick_ = function(e) { } } - var menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); + const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { menuItem.performAction(); } @@ -419,7 +420,7 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { return; } - var highlighted = this.highlightedItem_; + const highlighted = this.highlightedItem_; switch (e.keyCode) { case Blockly.utils.KeyCodes.ENTER: case Blockly.utils.KeyCodes.SPACE: @@ -461,8 +462,9 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { * @package */ Blockly.Menu.prototype.getSize = function() { - var menuDom = this.getElement(); - var menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ (menuDom)); + const menuDom = this.getElement(); + const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ + (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; return menuSize; From 4b19c7ecb5bc873009ba7621dff90054b1b141c3 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:41:32 -0700 Subject: [PATCH 009/172] Migrate core/menu.js to goog.module --- core/menu.js | 47 +++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/menu.js b/core/menu.js index 011199252..d1faf4415 100644 --- a/core/menu.js +++ b/core/menu.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Menu'); +goog.module('Blockly.Menu'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.utils.aria'); @@ -27,7 +28,7 @@ goog.requireType('Blockly.utils.Size'); * A basic menu class. * @constructor */ -Blockly.Menu = function() { +const Menu = function() { /** * Array of menu items. * (Nulls are never in the array, but typing the array as nullable prevents @@ -109,7 +110,7 @@ Blockly.Menu = function() { * Add a new menu item to the bottom of this menu. * @param {!Blockly.MenuItem} menuItem Menu item to append. */ -Blockly.Menu.prototype.addChild = function(menuItem) { +Menu.prototype.addChild = function(menuItem) { this.menuItems_.push(menuItem); }; @@ -117,7 +118,7 @@ Blockly.Menu.prototype.addChild = function(menuItem) { * Creates the menu DOM. * @param {!Element} container Element upon which to append this menu. */ -Blockly.Menu.prototype.render = function(container) { +Menu.prototype.render = function(container) { const element = /** @type {!HTMLDivElement} */ (document.createElement( 'div')); // goog-menu is deprecated, use blocklyMenu. May 2020. @@ -153,7 +154,7 @@ Blockly.Menu.prototype.render = function(container) { * @return {?Element} The DOM element. * @package */ -Blockly.Menu.prototype.getElement = function() { +Menu.prototype.getElement = function() { return this.element_; }; @@ -161,7 +162,7 @@ Blockly.Menu.prototype.getElement = function() { * Focus the menu element. * @package */ -Blockly.Menu.prototype.focus = function() { +Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll:true}); @@ -173,7 +174,7 @@ Blockly.Menu.prototype.focus = function() { * Blur the menu element. * @private */ -Blockly.Menu.prototype.blur_ = function() { +Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); @@ -186,14 +187,14 @@ Blockly.Menu.prototype.blur_ = function() { * @param {!Blockly.utils.aria.Role} roleName role name. * @package */ -Blockly.Menu.prototype.setRole = function(roleName) { +Menu.prototype.setRole = function(roleName) { this.roleName_ = roleName; }; /** * Dispose of this menu. */ -Blockly.Menu.prototype.dispose = function() { +Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { Blockly.browserEvents.unbind(this.mouseOverHandler_); @@ -232,7 +233,7 @@ Blockly.Menu.prototype.dispose = function() { * @return {?Blockly.MenuItem} Menu item for which the DOM element belongs to. * @private */ -Blockly.Menu.prototype.getMenuItem_ = function(elem) { +Menu.prototype.getMenuItem_ = function(elem) { const menuElem = this.getElement(); // Node might be the menu border (resulting in no associated menu item), or // a menu item's div, or some element within the menu item. @@ -259,7 +260,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { * @param {?Blockly.MenuItem} item Item to highlight, or null. * @package */ -Blockly.Menu.prototype.setHighlighted = function(item) { +Menu.prototype.setHighlighted = function(item) { const currentHighlighted = this.highlightedItem_; if (currentHighlighted) { currentHighlighted.setHighlighted(false); @@ -284,7 +285,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { * highlighted). * @package */ -Blockly.Menu.prototype.highlightNext = function() { +Menu.prototype.highlightNext = function() { const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index, 1); }; @@ -294,7 +295,7 @@ Blockly.Menu.prototype.highlightNext = function() { * currently highlighted). * @package */ -Blockly.Menu.prototype.highlightPrevious = function() { +Menu.prototype.highlightPrevious = function() { const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1); }; @@ -303,7 +304,7 @@ Blockly.Menu.prototype.highlightPrevious = function() { * Highlights the first highlightable item. * @private */ -Blockly.Menu.prototype.highlightFirst_ = function() { +Menu.prototype.highlightFirst_ = function() { this.highlightHelper_(-1, 1); }; @@ -311,7 +312,7 @@ Blockly.Menu.prototype.highlightFirst_ = function() { * Highlights the last highlightable item. * @private */ -Blockly.Menu.prototype.highlightLast_ = function() { +Menu.prototype.highlightLast_ = function() { this.highlightHelper_(this.menuItems_.length, -1); }; @@ -322,7 +323,7 @@ Blockly.Menu.prototype.highlightLast_ = function() { * @param {number} delta Step direction: 1 to go down, -1 to go up. * @private */ -Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { +Menu.prototype.highlightHelper_ = function(startIndex, delta) { let index = startIndex + delta; let menuItem; while ((menuItem = this.menuItems_[index])) { @@ -341,7 +342,7 @@ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { * @param {!Event} e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseOver_ = function(e) { +Menu.prototype.handleMouseOver_ = function(e) { const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { @@ -360,7 +361,7 @@ Blockly.Menu.prototype.handleMouseOver_ = function(e) { * @param {!Event} e Click event to handle. * @private */ -Blockly.Menu.prototype.handleClick_ = function(e) { +Menu.prototype.handleClick_ = function(e) { const oldCoords = this.openingCoords; // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; @@ -386,7 +387,7 @@ Blockly.Menu.prototype.handleClick_ = function(e) { * @param {!Event} _e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseEnter_ = function(_e) { +Menu.prototype.handleMouseEnter_ = function(_e) { this.focus(); }; @@ -395,7 +396,7 @@ Blockly.Menu.prototype.handleMouseEnter_ = function(_e) { * @param {!Event} _e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseLeave_ = function(_e) { +Menu.prototype.handleMouseLeave_ = function(_e) { if (this.getElement()) { this.blur_(); this.setHighlighted(null); @@ -410,7 +411,7 @@ Blockly.Menu.prototype.handleMouseLeave_ = function(_e) { * @param {!Event} e Key event to handle. * @private */ -Blockly.Menu.prototype.handleKeyEvent_ = function(e) { +Menu.prototype.handleKeyEvent_ = function(e) { if (!this.menuItems_.length) { // Empty menu. return; @@ -461,7 +462,7 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { * @return {!Blockly.utils.Size} Object with width and height properties. * @package */ -Blockly.Menu.prototype.getSize = function() { +Menu.prototype.getSize = function() { const menuDom = this.getElement(); const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ (menuDom)); @@ -469,3 +470,5 @@ Blockly.Menu.prototype.getSize = function() { menuSize.height = menuDom.scrollHeight; return menuSize; }; + +exports = Menu; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..477087f5c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -108,7 +108,7 @@ goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Bl goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); -goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); +goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); From 6dd36c3432c499d862f18096861b9aa35efa7bf6 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:47:09 -0700 Subject: [PATCH 010/172] Migrate core/menu.js named requires --- core/menu.js | 99 ++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/core/menu.js b/core/menu.js index d1faf4415..df7f8058d 100644 --- a/core/menu.js +++ b/core/menu.js @@ -13,15 +13,14 @@ goog.module('Blockly.Menu'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.style'); - -goog.requireType('Blockly.MenuItem'); -goog.requireType('Blockly.utils.Size'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const MenuItem = goog.requireType('Blockly.MenuItem'); +const Size = goog.requireType('Blockly.utils.Size'); +const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); +const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); +const {DOWN, END, ENTER, HOME, PAGE_DOWN, PAGE_UP, SPACE, UP} = goog.require('Blockly.utils.KeyCodes'); +const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); +const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); /** @@ -33,7 +32,7 @@ const Menu = function() { * Array of menu items. * (Nulls are never in the array, but typing the array as nullable prevents * the compiler from objecting to .indexOf(null)) - * @type {!Array} + * @type {!Array} * @private */ this.menuItems_ = []; @@ -42,7 +41,7 @@ const Menu = function() { * Coordinates of the mousedown event that caused this menu to open. Used to * prevent the consequent mouseup event due to a simple click from activating * a menu item immediately. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @package */ this.openingCoords = null; @@ -50,42 +49,42 @@ const Menu = function() { /** * This is the element that we will listen to the real focus events on. * A value of null means no menu item is highlighted. - * @type {?Blockly.MenuItem} + * @type {?MenuItem} * @private */ this.highlightedItem_ = null; /** * Mouse over event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseOverHandler_ = null; /** * Click event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.clickHandler_ = null; /** * Mouse enter event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseEnterHandler_ = null; /** * Mouse leave event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseLeaveHandler_ = null; /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onKeyDownHandler_ = null; @@ -99,7 +98,7 @@ const Menu = function() { /** * ARIA name for this menu. - * @type {?Blockly.utils.aria.Role} + * @type {?Role} * @private */ this.roleName_ = null; @@ -108,7 +107,7 @@ const Menu = function() { /** * Add a new menu item to the bottom of this menu. - * @param {!Blockly.MenuItem} menuItem Menu item to append. + * @param {!MenuItem} menuItem Menu item to append. */ Menu.prototype.addChild = function(menuItem) { this.menuItems_.push(menuItem); @@ -125,7 +124,7 @@ Menu.prototype.render = function(container) { element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; if (this.roleName_) { - Blockly.utils.aria.setRole(element, this.roleName_); + setRole(element, this.roleName_); } this.element_ = element; @@ -135,15 +134,15 @@ Menu.prototype.render = function(container) { } // Add event handlers. - this.mouseOverHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseOverHandler_ = conditionalBind( element, 'mouseover', this, this.handleMouseOver_, true); - this.clickHandler_ = Blockly.browserEvents.conditionalBind( + this.clickHandler_ = conditionalBind( element, 'click', this, this.handleClick_, true); - this.mouseEnterHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseEnterHandler_ = conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); - this.mouseLeaveHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseLeaveHandler_ = conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); - this.onKeyDownHandler_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownHandler_ = conditionalBind( element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); @@ -166,7 +165,7 @@ Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll:true}); - Blockly.utils.dom.addClass(el, 'blocklyFocused'); + addClass(el, 'blocklyFocused'); } }; @@ -178,13 +177,13 @@ Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); - Blockly.utils.dom.removeClass(el, 'blocklyFocused'); + removeClass(el, 'blocklyFocused'); } }; /** * Set the menu accessibility role. - * @param {!Blockly.utils.aria.Role} roleName role name. + * @param {!Role} roleName role name. * @package */ Menu.prototype.setRole = function(roleName) { @@ -197,23 +196,23 @@ Menu.prototype.setRole = function(roleName) { Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { - Blockly.browserEvents.unbind(this.mouseOverHandler_); + unbind(this.mouseOverHandler_); this.mouseOverHandler_ = null; } if (this.clickHandler_) { - Blockly.browserEvents.unbind(this.clickHandler_); + unbind(this.clickHandler_); this.clickHandler_ = null; } if (this.mouseEnterHandler_) { - Blockly.browserEvents.unbind(this.mouseEnterHandler_); + unbind(this.mouseEnterHandler_); this.mouseEnterHandler_ = null; } if (this.mouseLeaveHandler_) { - Blockly.browserEvents.unbind(this.mouseLeaveHandler_); + unbind(this.mouseLeaveHandler_); this.mouseLeaveHandler_ = null; } if (this.onKeyDownHandler_) { - Blockly.browserEvents.unbind(this.onKeyDownHandler_); + unbind(this.onKeyDownHandler_); this.onKeyDownHandler_ = null; } @@ -230,7 +229,7 @@ Menu.prototype.dispose = function() { * Returns the child menu item that owns the given DOM element, * or null if no such menu item is found. * @param {Element} elem DOM element whose owner is to be returned. - * @return {?Blockly.MenuItem} Menu item for which the DOM element belongs to. + * @return {?MenuItem} Menu item for which the DOM element belongs to. * @private */ Menu.prototype.getMenuItem_ = function(elem) { @@ -240,7 +239,7 @@ Menu.prototype.getMenuItem_ = function(elem) { // Walk up parents until one meets either the menu's root element, or // a menu item's div. while (elem && elem != menuElem) { - if (Blockly.utils.dom.hasClass(elem, 'blocklyMenuItem')) { + if (hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { @@ -257,7 +256,7 @@ Menu.prototype.getMenuItem_ = function(elem) { /** * Highlights the given menu item, or clears highlighting if null. - * @param {?Blockly.MenuItem} item Item to highlight, or null. + * @param {?MenuItem} item Item to highlight, or null. * @package */ Menu.prototype.setHighlighted = function(item) { @@ -272,10 +271,10 @@ Menu.prototype.setHighlighted = function(item) { // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. const el = /** @type {!Element} */ (this.getElement()); - Blockly.utils.style.scrollIntoContainerView( + scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - Blockly.utils.aria.setState(el, Blockly.utils.aria.State.ACTIVEDESCENDANT, + setState(el, State.ACTIVEDESCENDANT, item.getId()); } }; @@ -366,8 +365,8 @@ Menu.prototype.handleClick_ = function(e) { // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; if (oldCoords && typeof e.clientX == 'number') { - const newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); - if (Blockly.utils.Coordinate.distance(oldCoords, newCoords) < 1) { + const newCoords = new Coordinate(e.clientX, e.clientY); + if (Coordinate.distance(oldCoords, newCoords) < 1) { // This menu was opened by a mousedown and we're handling the consequent // click event. The coords haven't changed, meaning this was the same // opening event. Don't do the usual behavior because the menu just popped @@ -423,28 +422,28 @@ Menu.prototype.handleKeyEvent_ = function(e) { const highlighted = this.highlightedItem_; switch (e.keyCode) { - case Blockly.utils.KeyCodes.ENTER: - case Blockly.utils.KeyCodes.SPACE: + case ENTER: + case SPACE: if (highlighted) { highlighted.performAction(); } break; - case Blockly.utils.KeyCodes.UP: + case UP: this.highlightPrevious(); break; - case Blockly.utils.KeyCodes.DOWN: + case DOWN: this.highlightNext(); break; - case Blockly.utils.KeyCodes.PAGE_UP: - case Blockly.utils.KeyCodes.HOME: + case PAGE_UP: + case HOME: this.highlightFirst_(); break; - case Blockly.utils.KeyCodes.PAGE_DOWN: - case Blockly.utils.KeyCodes.END: + case PAGE_DOWN: + case END: this.highlightLast_(); break; @@ -459,12 +458,12 @@ Menu.prototype.handleKeyEvent_ = function(e) { /** * Get the size of a rendered menu. - * @return {!Blockly.utils.Size} Object with width and height properties. + * @return {!Size} Object with width and height properties. * @package */ Menu.prototype.getSize = function() { const menuDom = this.getElement(); - const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ + const menuSize = getSize(/** @type {!Element} */ (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; From e5468a50b4e5cca373e72281a482d532ac855172 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:47:58 -0700 Subject: [PATCH 011/172] clang-format core/menu.js --- core/menu.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/core/menu.js b/core/menu.js index df7f8058d..85672f717 100644 --- a/core/menu.js +++ b/core/menu.js @@ -118,8 +118,8 @@ Menu.prototype.addChild = function(menuItem) { * @param {!Element} container Element upon which to append this menu. */ Menu.prototype.render = function(container) { - const element = /** @type {!HTMLDivElement} */ (document.createElement( - 'div')); + const element = + /** @type {!HTMLDivElement} */ (document.createElement('div')); // goog-menu is deprecated, use blocklyMenu. May 2020. element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; @@ -134,16 +134,16 @@ Menu.prototype.render = function(container) { } // Add event handlers. - this.mouseOverHandler_ = conditionalBind( - element, 'mouseover', this, this.handleMouseOver_, true); - this.clickHandler_ = conditionalBind( - element, 'click', this, this.handleClick_, true); + this.mouseOverHandler_ = + conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); + this.clickHandler_ = + conditionalBind(element, 'click', this, this.handleClick_, true); this.mouseEnterHandler_ = conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); this.mouseLeaveHandler_ = conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); - this.onKeyDownHandler_ = conditionalBind( - element, 'keydown', this, this.handleKeyEvent_); + this.onKeyDownHandler_ = + conditionalBind(element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); }; @@ -164,7 +164,7 @@ Menu.prototype.getElement = function() { Menu.prototype.focus = function() { const el = this.getElement(); if (el) { - el.focus({preventScroll:true}); + el.focus({preventScroll: true}); addClass(el, 'blocklyFocused'); } }; @@ -274,8 +274,7 @@ Menu.prototype.setHighlighted = function(item) { scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - setState(el, State.ACTIVEDESCENDANT, - item.getId()); + setState(el, State.ACTIVEDESCENDANT, item.getId()); } }; @@ -464,7 +463,7 @@ Menu.prototype.handleKeyEvent_ = function(e) { Menu.prototype.getSize = function() { const menuDom = this.getElement(); const menuSize = getSize(/** @type {!Element} */ - (menuDom)); + (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; return menuSize; From 296eed06fbd64d7e6b554665a3332806da495b0b Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 09:01:59 -0700 Subject: [PATCH 012/172] Fix build --- core/menu.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/menu.js b/core/menu.js index 85672f717..ac79922cf 100644 --- a/core/menu.js +++ b/core/menu.js @@ -18,7 +18,7 @@ const MenuItem = goog.requireType('Blockly.MenuItem'); const Size = goog.requireType('Blockly.utils.Size'); const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); -const {DOWN, END, ENTER, HOME, PAGE_DOWN, PAGE_UP, SPACE, UP} = goog.require('Blockly.utils.KeyCodes'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); @@ -421,28 +421,28 @@ Menu.prototype.handleKeyEvent_ = function(e) { const highlighted = this.highlightedItem_; switch (e.keyCode) { - case ENTER: - case SPACE: + case KeyCodes.ENTER: + case KeyCodes.SPACE: if (highlighted) { highlighted.performAction(); } break; - case UP: + case KeyCodes.UP: this.highlightPrevious(); break; - case DOWN: + case KeyCodes.DOWN: this.highlightNext(); break; - case PAGE_UP: - case HOME: + case KeyCodes.PAGE_UP: + case KeyCodes.HOME: this.highlightFirst_(); break; - case PAGE_DOWN: - case END: + case KeyCodes.PAGE_DOWN: + case KeyCodes.END: this.highlightLast_(); break; From 9573f2b7ec102a0621e40ddbda6da9b1238795a7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:21:57 -0700 Subject: [PATCH 013/172] Migrate core/field_textinput.js to named requires --- core/field_textinput.js | 120 ++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 4585ba382..07c0e3282 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -13,25 +13,27 @@ goog.module('Blockly.FieldTextInput'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Events = goog.require('Blockly.Events'); +const Field = goog.require('Blockly.Field'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Msg = goog.require('Blockly.Msg'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const aria = goog.require('Blockly.utils.aria'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {inherits} = goog.require('Blockly.utils.object'); +const {prompt: blocklyPrompt} = goog.require('Blockly'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.Msg'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -44,7 +46,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldTextInput = function(opt_value, opt_validator, opt_config) { @@ -66,14 +68,14 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onKeyDownWrapper_ = null; /** * Key input event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onKeyInputWrapper_ = null; @@ -87,12 +89,12 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * The workspace that this field belongs to. - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} * @protected */ this.workspace_ = null; }; -Blockly.utils.object.inherits(FieldTextInput, Blockly.Field); +inherits(FieldTextInput, Field); /** * The default value for this field. @@ -110,7 +112,7 @@ FieldTextInput.prototype.DEFAULT_VALUE = ''; * @nocollapse */ FieldTextInput.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -207,8 +209,8 @@ FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { const oldValue = this.value_; // Revert value when the text becomes invalid. this.value_ = this.htmlInput_.untypedDefaultValue_; - if (this.sourceBlock_ && Blockly.Events.isEnabled()) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + if (this.sourceBlock_ && Events.isEnabled()) { + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this.sourceBlock_, 'field', this.name || null, oldValue, this.value_)); } } @@ -260,13 +262,13 @@ FieldTextInput.prototype.render_ = function() { this.resizeEditor_(); const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, true); + dom.addClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, true); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, false); + dom.removeClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, false); } } }; @@ -296,11 +298,11 @@ FieldTextInput.prototype.setSpellcheck = function(check) { FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = - (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; + (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; const quietInput = opt_quietInput || false; - if (!quietInput && (Blockly.utils.userAgent.MOBILE || - Blockly.utils.userAgent.ANDROID || - Blockly.utils.userAgent.IPAD)) { + if (!quietInput && (userAgent.MOBILE || + userAgent.ANDROID || + userAgent.IPAD)) { this.showPromptEditor_(); } else { this.showInlineEditor_(quietInput); @@ -313,7 +315,7 @@ FieldTextInput.prototype.showEditor_ = function(_opt_e, * @private */ FieldTextInput.prototype.showPromptEditor_ = function() { - Blockly.prompt(Blockly.Msg['CHANGE_VALUE_TITLE'], this.getText(), + blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { this.setValue(this.getValueFromEditorText_(text)); }.bind(this)); @@ -326,7 +328,7 @@ FieldTextInput.prototype.showPromptEditor_ = function() { * @private */ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { - Blockly.WidgetDiv.show( + WidgetDiv.show( this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); this.isBeingEdited_ = true; @@ -343,10 +345,10 @@ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { * @protected */ FieldTextInput.prototype.widgetCreate_ = function() { - Blockly.Events.setGroup(true); - const div = Blockly.WidgetDiv.DIV; + Events.setGroup(true); + const div = WidgetDiv.DIV; - Blockly.utils.dom.addClass(this.getClickTarget_(), 'editing'); + dom.addClass(this.getClickTarget_(), 'editing'); const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; @@ -406,11 +408,11 @@ FieldTextInput.prototype.widgetDispose_ = function() { if (this.onFinishEditing_) { this.onFinishEditing_(this.value_); } - Blockly.Events.setGroup(false); + Events.setGroup(false); // Actual disposal. this.unbindInputEvents_(); - const style = Blockly.WidgetDiv.DIV.style; + const style = WidgetDiv.DIV.style; style.width = 'auto'; style.height = 'auto'; style.fontSize = ''; @@ -418,7 +420,7 @@ FieldTextInput.prototype.widgetDispose_ = function() { style.boxShadow = ''; this.htmlInput_ = null; - Blockly.utils.dom.removeClass(this.getClickTarget_(), 'editing'); + dom.removeClass(this.getClickTarget_(), 'editing'); }; /** @@ -429,10 +431,10 @@ FieldTextInput.prototype.widgetDispose_ = function() { */ FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { // Trap Enter without IME and Esc to hide. - this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownWrapper_ = browserEvents.conditionalBind( htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); // Resize after every input change. - this.onKeyInputWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyInputWrapper_ = browserEvents.conditionalBind( htmlInput, 'input', this, this.onHtmlInputChange_); }; @@ -442,11 +444,11 @@ FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { */ FieldTextInput.prototype.unbindInputEvents_ = function() { if (this.onKeyDownWrapper_) { - Blockly.browserEvents.unbind(this.onKeyDownWrapper_); + browserEvents.unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; } if (this.onKeyInputWrapper_) { - Blockly.browserEvents.unbind(this.onKeyInputWrapper_); + browserEvents.unbind(this.onKeyInputWrapper_); this.onKeyInputWrapper_ = null; } }; @@ -457,16 +459,16 @@ FieldTextInput.prototype.unbindInputEvents_ = function() { * @protected */ FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { - if (e.keyCode == Blockly.utils.KeyCodes.ENTER) { - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); - } else if (e.keyCode == Blockly.utils.KeyCodes.ESC) { + if (e.keyCode == KeyCodes.ENTER) { + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); + } else if (e.keyCode == KeyCodes.ESC) { this.setValue(this.htmlInput_.untypedDefaultValue_); - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); - } else if (e.keyCode == Blockly.utils.KeyCodes.TAB) { - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); + } else if (e.keyCode == KeyCodes.TAB) { + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); this.sourceBlock_.tab(this, !e.shiftKey); e.preventDefault(); } @@ -513,7 +515,7 @@ FieldTextInput.prototype.setEditorValue_ = function(newValue) { * @protected */ FieldTextInput.prototype.resizeEditor_ = function() { - const div = Blockly.WidgetDiv.DIV; + const div = WidgetDiv.DIV; const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; div.style.height = bBox.bottom - bBox.top + 'px'; @@ -521,7 +523,7 @@ FieldTextInput.prototype.resizeEditor_ = function() { // In RTL mode block fields and LTR input fields the left edge moves, // whereas the right edge is fixed. Reposition the editor. const x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; - const xy = new Blockly.utils.Coordinate(x, bBox.top); + const xy = new Coordinate(x, bBox.top); div.style.left = xy.x + 'px'; div.style.top = xy.y + 'px'; @@ -580,6 +582,6 @@ FieldTextInput.prototype.getValueFromEditorText_ = function(text) { return text; }; -Blockly.fieldRegistry.register('field_input', FieldTextInput); +fieldRegistry.register('field_input', FieldTextInput); exports = FieldTextInput; diff --git a/tests/deps.js b/tests/deps.js index 0e96aa2c3..c68a0441f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -59,7 +59,7 @@ goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabe goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); -goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); From 13272c37136992a91639e6c27ed0fcd100f9cabb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:23:06 -0700 Subject: [PATCH 014/172] clang-format core/field_textinput.js --- core/field_textinput.js | 76 +++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 07c0e3282..cfa891e34 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -44,7 +44,8 @@ goog.require('Blockly.Events.BlockChange'); * changes to the field's value. Takes in a string & returns a validated * string, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -57,8 +58,8 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.spellcheck_ = true; - FieldTextInput.superClass_.constructor.call(this, - opt_value, opt_validator, opt_config); + FieldTextInput.superClass_.constructor.call( + this, opt_value, opt_validator, opt_config); /** * The HTML input element. @@ -159,7 +160,7 @@ FieldTextInput.prototype.initView = function() { // Count the number of fields, excluding text fields for (let i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { for (let j = 0; (input.fieldRow[j]); j++) { - nFields ++; + nFields++; } if (input.connection) { nConnections++; @@ -211,7 +212,8 @@ FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { this.value_ = this.htmlInput_.untypedDefaultValue_; if (this.sourceBlock_ && Events.isEnabled()) { Events.fire(new (Events.get(Events.BLOCK_CHANGE))( - this.sourceBlock_, 'field', this.name || null, oldValue, this.value_)); + this.sourceBlock_, 'field', this.name || null, oldValue, + this.value_)); } } }; @@ -240,11 +242,11 @@ FieldTextInput.prototype.doValueUpdate_ = function(newValue) { FieldTextInput.prototype.applyColour = function() { if (this.sourceBlock_ && this.getConstants().FULL_BLOCK_FIELDS) { if (this.borderRect_) { - this.borderRect_.setAttribute('stroke', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'stroke', this.sourceBlock_.style.colourTertiary); } else { - this.sourceBlock_.pathObject.svgPath.setAttribute('fill', - this.getConstants().FIELD_BORDER_RECT_COLOUR); + this.sourceBlock_.pathObject.svgPath.setAttribute( + 'fill', this.getConstants().FIELD_BORDER_RECT_COLOUR); } } }; @@ -260,15 +262,13 @@ FieldTextInput.prototype.render_ = function() { // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { this.resizeEditor_(); - const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + const htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (!this.isTextValid_) { dom.addClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, true); + aria.setState(htmlInput, aria.State.INVALID, true); } else { dom.removeClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, false); + aria.setState(htmlInput, aria.State.INVALID, false); } } }; @@ -295,14 +295,11 @@ FieldTextInput.prototype.setSpellcheck = function(check) { * focus. Defaults to false. * @protected */ -FieldTextInput.prototype.showEditor_ = function(_opt_e, - opt_quietInput) { - this.workspace_ = - (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; +FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { + this.workspace_ = (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; const quietInput = opt_quietInput || false; - if (!quietInput && (userAgent.MOBILE || - userAgent.ANDROID || - userAgent.IPAD)) { + if (!quietInput && + (userAgent.MOBILE || userAgent.ANDROID || userAgent.IPAD)) { this.showPromptEditor_(); } else { this.showInlineEditor_(quietInput); @@ -315,10 +312,9 @@ FieldTextInput.prototype.showEditor_ = function(_opt_e, * @private */ FieldTextInput.prototype.showPromptEditor_ = function() { - blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), - function(text) { - this.setValue(this.getValueFromEditorText_(text)); - }.bind(this)); + blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { + this.setValue(this.getValueFromEditorText_(text)); + }.bind(this)); }; /** @@ -328,13 +324,12 @@ FieldTextInput.prototype.showPromptEditor_ = function() { * @private */ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { - WidgetDiv.show( - this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); + WidgetDiv.show(this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); this.isBeingEdited_ = true; if (!quietInput) { - this.htmlInput_.focus({preventScroll:true}); + this.htmlInput_.focus({preventScroll: true}); this.htmlInput_.select(); } }; @@ -350,16 +345,15 @@ FieldTextInput.prototype.widgetCreate_ = function() { dom.addClass(this.getClickTarget_(), 'editing'); - const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); + const htmlInput = + /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); const scale = this.workspace_.getScale(); - const fontSize = - (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - let borderRadius = - (FieldTextInput.BORDERRADIUS * scale) + 'px'; + let borderRadius = (FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { const bBox = this.getScaledBBox(); @@ -368,14 +362,14 @@ FieldTextInput.prototype.widgetCreate_ = function() { borderRadius = (bBox.bottom - bBox.top) / 2 + 'px'; // Pull stroke colour from the existing shadow block const strokeColour = this.sourceBlock_.getParent() ? - this.sourceBlock_.getParent().style.colourTertiary : - this.sourceBlock_.style.colourTertiary; + this.sourceBlock_.getParent().style.colourTertiary : + this.sourceBlock_.style.colourTertiary; htmlInput.style.border = (1 * scale) + 'px solid ' + strokeColour; div.style.borderRadius = borderRadius; div.style.transition = 'box-shadow 0.25s ease 0s'; if (this.getConstants().FIELD_TEXTINPUT_BOX_SHADOW) { - div.style.boxShadow = 'rgba(255, 255, 255, 0.3) 0 0 0 ' + - (4 * scale) + 'px'; + div.style.boxShadow = + 'rgba(255, 255, 255, 0.3) 0 0 0 ' + (4 * scale) + 'px'; } } htmlInput.style.borderRadius = borderRadius; @@ -539,10 +533,10 @@ FieldTextInput.prototype.isTabNavigable = function() { }; /** - * Use the `getText_` developer hook to override the field's text representation. - * When we're currently editing, return the current HTML value instead. - * Otherwise, return null which tells the field to use the default behaviour - * (which is a string cast of the field's value). + * Use the `getText_` developer hook to override the field's text + * representation. When we're currently editing, return the current HTML value + * instead. Otherwise, return null which tells the field to use the default + * behaviour (which is a string cast of the field's value). * @return {?string} The HTML value if we're editing, otherwise null. * @protected * @override From ee565f16d6899cbe857529194a4d7852d0effdf2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:41:55 -0700 Subject: [PATCH 015/172] Silence unused variable warnings for requires used in JSDoc --- core/interfaces/i_collapsible_toolbox_item.js | 2 ++ core/interfaces/i_registrable_field.js | 1 + core/interfaces/i_selectable_toolbox_item.js | 2 ++ core/keyboard_nav/tab_navigate_cursor.js | 1 + core/renderers/common/info.js | 8 ++++++++ 5 files changed, 14 insertions(+) diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js index 732c7aab7..45bd3ae3e 100644 --- a/core/interfaces/i_collapsible_toolbox_item.js +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -14,7 +14,9 @@ goog.module('Blockly.ICollapsibleToolboxItem'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const ISelectableToolboxItem = goog.require('Blockly.ISelectableToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 2c8c005bd..c9d04325d 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -14,6 +14,7 @@ goog.module('Blockly.IRegistrableField'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js index 2addc7b9e..cefe35740 100644 --- a/core/interfaces/i_selectable_toolbox_item.js +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -14,7 +14,9 @@ goog.module('Blockly.ISelectableToolboxItem'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.require('Blockly.IToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const {FlyoutItemInfoArray} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 3b82267a1..77fc5a2a2 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -16,6 +16,7 @@ goog.module.declareLegacyNamespace(); const ASTNode = goog.require('Blockly.ASTNode'); const BasicCursor = goog.require('Blockly.BasicCursor'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); const {inherits} = goog.require('Blockly.utils.object'); diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 73e02dfff..0f8548192 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -13,25 +13,33 @@ goog.module('Blockly.blockRendering.RenderInfo'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const BottomRow = goog.require('Blockly.blockRendering.BottomRow'); +/* eslint-disable-next-line no-unused-vars */ const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); const ExternalValueInput = goog.require('Blockly.blockRendering.ExternalValueInput'); const Field = goog.require('Blockly.blockRendering.Field'); const Hat = goog.require('Blockly.blockRendering.Hat'); const Icon = goog.require('Blockly.blockRendering.Icon'); const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); +/* eslint-disable-next-line no-unused-vars */ const Input = goog.requireType('Blockly.Input'); const InputRow = goog.require('Blockly.blockRendering.InputRow'); const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); +/* eslint-disable-next-line no-unused-vars */ const Measurable = goog.require('Blockly.blockRendering.Measurable'); const NextConnection = goog.require('Blockly.blockRendering.NextConnection'); const OutputConnection = goog.require('Blockly.blockRendering.OutputConnection'); const PreviousConnection = goog.require('Blockly.blockRendering.PreviousConnection'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +/* eslint-disable-next-line no-unused-vars */ const Renderer = goog.requireType('Blockly.blockRendering.Renderer'); +/* eslint-disable-next-line no-unused-vars */ const RoundCorner = goog.require('Blockly.blockRendering.RoundCorner'); +/* eslint-disable-next-line no-unused-vars */ const Row = goog.require('Blockly.blockRendering.Row'); const SpacerRow = goog.require('Blockly.blockRendering.SpacerRow'); const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); From 48ccc38cbb2c45ea34b796cacf338319d6a721c3 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 10:42:56 -0700 Subject: [PATCH 016/172] Fix destructuring --- core/menu.js | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/core/menu.js b/core/menu.js index ac79922cf..083d76e06 100644 --- a/core/menu.js +++ b/core/menu.js @@ -15,12 +15,12 @@ goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); const MenuItem = goog.requireType('Blockly.MenuItem'); -const Size = goog.requireType('Blockly.utils.Size'); -const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); -const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); -const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); -const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); +const Size = goog.requireType('Blockly.utils.Size'); +const aria = goog.require('Blockly.utils.aria'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const style = goog.require('Blockly.utils.style'); /** @@ -56,35 +56,35 @@ const Menu = function() { /** * Mouse over event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseOverHandler_ = null; /** * Click event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.clickHandler_ = null; /** * Mouse enter event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseEnterHandler_ = null; /** * Mouse leave event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseLeaveHandler_ = null; /** * Key down event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.onKeyDownHandler_ = null; @@ -98,7 +98,7 @@ const Menu = function() { /** * ARIA name for this menu. - * @type {?Role} + * @type {?aria.Role} * @private */ this.roleName_ = null; @@ -124,7 +124,7 @@ Menu.prototype.render = function(container) { element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; if (this.roleName_) { - setRole(element, this.roleName_); + aria.setRole(element, this.roleName_); } this.element_ = element; @@ -135,15 +135,15 @@ Menu.prototype.render = function(container) { // Add event handlers. this.mouseOverHandler_ = - conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); + browserEvents.conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); this.clickHandler_ = - conditionalBind(element, 'click', this, this.handleClick_, true); - this.mouseEnterHandler_ = conditionalBind( + browserEvents.conditionalBind(element, 'click', this, this.handleClick_, true); + this.mouseEnterHandler_ = browserEvents.conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); - this.mouseLeaveHandler_ = conditionalBind( + this.mouseLeaveHandler_ = browserEvents.conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); this.onKeyDownHandler_ = - conditionalBind(element, 'keydown', this, this.handleKeyEvent_); + browserEvents.conditionalBind(element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); }; @@ -165,7 +165,7 @@ Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll: true}); - addClass(el, 'blocklyFocused'); + dom.addClass(el, 'blocklyFocused'); } }; @@ -177,13 +177,13 @@ Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); - removeClass(el, 'blocklyFocused'); + dom.removeClass(el, 'blocklyFocused'); } }; /** * Set the menu accessibility role. - * @param {!Role} roleName role name. + * @param {!aria.Role} roleName role name. * @package */ Menu.prototype.setRole = function(roleName) { @@ -196,23 +196,23 @@ Menu.prototype.setRole = function(roleName) { Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { - unbind(this.mouseOverHandler_); + browserEvents.unbind(this.mouseOverHandler_); this.mouseOverHandler_ = null; } if (this.clickHandler_) { - unbind(this.clickHandler_); + browserEvents.unbind(this.clickHandler_); this.clickHandler_ = null; } if (this.mouseEnterHandler_) { - unbind(this.mouseEnterHandler_); + browserEvents.unbind(this.mouseEnterHandler_); this.mouseEnterHandler_ = null; } if (this.mouseLeaveHandler_) { - unbind(this.mouseLeaveHandler_); + browserEvents.unbind(this.mouseLeaveHandler_); this.mouseLeaveHandler_ = null; } if (this.onKeyDownHandler_) { - unbind(this.onKeyDownHandler_); + browserEvents.unbind(this.onKeyDownHandler_); this.onKeyDownHandler_ = null; } @@ -239,7 +239,7 @@ Menu.prototype.getMenuItem_ = function(elem) { // Walk up parents until one meets either the menu's root element, or // a menu item's div. while (elem && elem != menuElem) { - if (hasClass(elem, 'blocklyMenuItem')) { + if (dom.hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { @@ -271,10 +271,10 @@ Menu.prototype.setHighlighted = function(item) { // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. const el = /** @type {!Element} */ (this.getElement()); - scrollIntoContainerView( + style.scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - setState(el, State.ACTIVEDESCENDANT, item.getId()); + aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId()); } }; @@ -462,7 +462,7 @@ Menu.prototype.handleKeyEvent_ = function(e) { */ Menu.prototype.getSize = function() { const menuDom = this.getElement(); - const menuSize = getSize(/** @type {!Element} */ + const menuSize = style.getSize(/** @type {!Element} */ (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; From 380cfd5963d3a2e2e235fcccee3ebd02718e1573 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:08:58 -0700 Subject: [PATCH 017/172] Migrate core/flyout_base.js to ES6 const/let --- core/flyout_base.js | 144 +++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 70 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 84d6d3870..3c62ebe51 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -396,7 +396,7 @@ Blockly.Flyout.prototype.isVisible = function() { * @param {boolean} visible True if visible. */ Blockly.Flyout.prototype.setVisible = function(visible) { - var visibilityChanged = (visible != this.isVisible()); + const visibilityChanged = (visible != this.isVisible()); this.isVisible_ = visible; if (visibilityChanged) { @@ -414,7 +414,7 @@ Blockly.Flyout.prototype.setVisible = function(visible) { * @param {boolean} visible Whether the container is visible. */ Blockly.Flyout.prototype.setContainerVisible = function(visible) { - var visibilityChanged = (visible != this.containerVisible_); + const visibilityChanged = (visible != this.containerVisible_); this.containerVisible_ = visible; if (visibilityChanged) { this.updateDisplay_(); @@ -427,7 +427,7 @@ Blockly.Flyout.prototype.setContainerVisible = function(visible) { * @private */ Blockly.Flyout.prototype.updateDisplay_ = function() { - var show = true; + let show = true; if (!this.containerVisible_) { show = false; } else { @@ -453,17 +453,17 @@ Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { this.workspace_.setCachedParentSvgSize(width, height); if (this.svgGroup_.tagName == 'svg') { - var transform = 'translate(' + x + 'px,' + y + 'px)'; + const transform = 'translate(' + x + 'px,' + y + 'px)'; Blockly.utils.dom.setCssTransform(this.svgGroup_, transform); } else { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself - var transform = 'translate(' + x + ',' + y + ')'; + const transform = 'translate(' + x + ',' + y + ')'; this.svgGroup_.setAttribute("transform", transform); } // Update the scrollbar (if one exists). - var scrollbar = this.workspace_.scrollbar; + const scrollbar = this.workspace_.scrollbar; if (scrollbar) { // Set the scrollbars origin to be the top left of the flyout. scrollbar.setOrigin(x, y); @@ -491,7 +491,7 @@ Blockly.Flyout.prototype.hide = function() { } this.setVisible(false); // Delete all the event listeners. - for (var i = 0, listen; (listen = this.listeners_[i]); i++) { + for (let i = 0, listen; (listen = this.listeners_[i]); i++) { Blockly.browserEvents.unbind(listen); } this.listeners_.length = 0; @@ -521,8 +521,8 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { this.setVisible(true); // Parse the Array, Node or NodeList into a a list of flyout items. - var parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); - var flyoutInfo = + const parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); + const flyoutInfo = /** @type {{contents:!Array, gaps:!Array}} */ ( this.createFlyoutInfo_(parsedContent)); @@ -530,9 +530,9 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { // IE 11 is an incompetent browser that fails to fire mouseout events. // When the mouse is over the background, deselect all blocks. - var deselectAll = function() { - var topBlocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = topBlocks[i]); i++) { + const deselectAll = function() { + const topBlocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = topBlocks[i]); i++) { block.removeSelect(); } }; @@ -567,50 +567,54 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { * @private */ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { - var contents = []; - var gaps = []; + const contents = []; + const gaps = []; this.permanentlyDisabled_.length = 0; - var defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; - for (var i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { + const defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; + for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { if (contentInfo['custom']) { - var customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); - var categoryName = customInfo['custom']; - var flyoutDef = this.getDynamicCategoryContents_(categoryName); - var parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ + const customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); + const categoryName = customInfo['custom']; + const flyoutDef = this.getDynamicCategoryContents_(categoryName); + const parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ (Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef)); parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } switch (contentInfo['kind'].toUpperCase()) { - case 'BLOCK': - var blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); - var blockXml = this.getBlockXml_(blockInfo); - var block = this.createBlock_(blockXml); + case 'BLOCK': { + const blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); + const blockXml = this.getBlockXml_(blockInfo); + const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. // - var gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); + const gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); gaps.push(isNaN(gap) ? defaultGap : gap); contents.push({type: 'block', block: block}); break; - case 'SEP': - var sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); + } + case 'SEP': { + const sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); this.addSeparatorGap_(sepInfo, gaps, defaultGap); break; - case 'LABEL': - var labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); + } + case 'LABEL': { + const labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); // A label is a button with different styling. - var label = this.createButton_(labelInfo, /** isLabel */ true); + const label = this.createButton_(labelInfo, /** isLabel */ true); contents.push({type: 'button', button: label}); gaps.push(defaultGap); break; - case 'BUTTON': - var buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); - var button = this.createButton_(buttonInfo, /** isLabel */ false); + } + case 'BUTTON': { + const buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); + const button = this.createButton_(buttonInfo, /** isLabel */ false); contents.push({type: 'button', button: button}); gaps.push(defaultGap); break; + } } } return {contents: contents, gaps: gaps}; @@ -625,13 +629,13 @@ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. - var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( + const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( categoryName); if (typeof fnToApply != 'function') { throw TypeError('Couldn\'t find a callback function when opening' + ' a toolbox category.'); } - var flyoutDef = fnToApply(this.workspace_.targetWorkspace); + const flyoutDef = fnToApply(this.workspace_.targetWorkspace); if (!Array.isArray(flyoutDef)) { throw new TypeError('Result of toolbox category callback must be an array.'); } @@ -651,7 +655,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!Blockly.FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - var curButton = new Blockly.FlyoutButton(this.workspace_, + const curButton = new Blockly.FlyoutButton(this.workspace_, /** @type {!Blockly.WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; @@ -665,7 +669,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @protected */ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { - var curBlock = /** @type {!Blockly.BlockSvg} */ ( + const curBlock = /** @type {!Blockly.BlockSvg} */ ( Blockly.Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. @@ -684,8 +688,8 @@ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { * @private */ Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { - var blockElement = null; - var blockXml = blockInfo['blockxml']; + let blockElement = null; + const blockXml = blockInfo['blockxml']; if (blockXml && typeof blockXml != 'string') { blockElement = blockXml; @@ -718,7 +722,7 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) // // The default gap is 24, can be set larger or smaller. // This overwrites the gap attribute on the previous element. - var newGap = parseInt(sepInfo['gap'], 10); + const newGap = parseInt(sepInfo['gap'], 10); // Ignore gaps before the first block. if (!isNaN(newGap) && gaps.length > 0) { gaps[gaps.length - 1] = newGap; @@ -733,15 +737,15 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) */ Blockly.Flyout.prototype.clearOldBlocks_ = function() { // Delete any blocks from a previous showing. - var oldBlocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = oldBlocks[i]); i++) { + const oldBlocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = oldBlocks[i]); i++) { if (block.workspace == this.workspace_) { block.dispose(false, false); } } // Delete any mats from a previous showing. - for (var j = 0; j < this.mats_.length; j++) { - var rect = this.mats_[j]; + for (let j = 0; j < this.mats_.length; j++) { + const rect = this.mats_[j]; if (rect) { Blockly.Tooltip.unbindMouseEvents(rect); Blockly.utils.dom.removeNode(rect); @@ -749,7 +753,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { } this.mats_.length = 0; // Delete any buttons from a previous showing. - for (var i = 0, button; (button = this.buttons_[i]); i++) { + for (let i = 0, button; (button = this.buttons_[i]); i++) { button.dispose(); } this.buttons_.length = 0; @@ -788,9 +792,9 @@ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { * @private */ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { - var flyout = this; + const flyout = this; return function(e) { - var gesture = flyout.targetWorkspace.getGesture(e); + const gesture = flyout.targetWorkspace.getGesture(e); if (gesture) { gesture.setStartBlock(block); gesture.handleFlyoutStart(e, flyout); @@ -804,7 +808,7 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { * @private */ Blockly.Flyout.prototype.onMouseDown_ = function(e) { - var gesture = this.targetWorkspace.getGesture(e); + const gesture = this.targetWorkspace.getGesture(e); if (gesture) { gesture.handleFlyoutStart(e, this); } @@ -830,9 +834,9 @@ Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { * @package */ Blockly.Flyout.prototype.createBlock = function(originalBlock) { - var newBlock = null; + let newBlock = null; Blockly.Events.disable(); - var variablesBeforeCreation = this.targetWorkspace.getAllVariables(); + const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); this.targetWorkspace.setResizesEnabled(false); try { newBlock = this.placeNewBlock_(originalBlock); @@ -843,14 +847,14 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { // Close the flyout. Blockly.hideChaff(); - var newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, + const newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, variablesBeforeCreation); if (Blockly.Events.isEnabled()) { Blockly.Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. - for (var i = 0; i < newVariables.length; i++) { - var thisVariable = newVariables[i]; + for (let i = 0; i < newVariables.length; i++) { + const thisVariable = newVariables[i]; Blockly.Events.fire( new (Blockly.Events.get(Blockly.Events.VAR_CREATE))(thisVariable)); } @@ -877,7 +881,7 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { * @protected */ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { - var buttonSvg = button.createDom(); + const buttonSvg = button.createDom(); button.moveTo(x, y); button.show(); // Clicking on a flyout button or label is a lot like clicking on the @@ -904,7 +908,7 @@ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. - var rect = Blockly.utils.dom.createSvgElement( + const rect = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'fill-opacity': 0, @@ -931,11 +935,11 @@ Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * @protected */ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { - var blockHW = block.getHeightWidth(); + const blockHW = block.getHeightWidth(); rect.setAttribute('width', blockHW.width); rect.setAttribute('height', blockHW.height); - var blockXY = block.getRelativeToSurfaceXY(); + const blockXY = block.getRelativeToSurfaceXY(); rect.setAttribute('y', blockXY.y); rect.setAttribute('x', this.RTL ? blockXY.x - blockHW.width : blockXY.x); }; @@ -947,10 +951,10 @@ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { * @private */ Blockly.Flyout.prototype.filterForCapacity_ = function() { - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { - var enable = this.targetWorkspace + const enable = this.targetWorkspace .isCapacityAvailable(Blockly.utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); @@ -990,50 +994,50 @@ Blockly.Flyout.prototype.isScrollable = function() { * @private */ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { - var targetWorkspace = this.targetWorkspace; - var svgRootOld = oldBlock.getSvgRoot(); + const targetWorkspace = this.targetWorkspace; + const svgRootOld = oldBlock.getSvgRoot(); if (!svgRootOld) { throw Error('oldBlock is not rendered.'); } // Create the new block by cloning the block in the flyout (via XML). // This cast assumes that the oldBlock can not be an insertion marker. - var xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); + const xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); // The target workspace would normally resize during domToBlock, which will // lead to weird jumps. Save it for terminateDrag. targetWorkspace.setResizesEnabled(false); // Using domToBlock instead of domToWorkspace means that the new block will be // placed at position (0, 0) in main workspace units. - var block = /** @type {!Blockly.BlockSvg} */ + const block = /** @type {!Blockly.BlockSvg} */ (Blockly.Xml.domToBlock(xml, targetWorkspace)); - var svgRootNew = block.getSvgRoot(); + const svgRootNew = block.getSvgRoot(); if (!svgRootNew) { throw Error('block is not rendered.'); } // The offset in pixels between the main workspace's origin and the upper left // corner of the injection div. - var mainOffsetPixels = targetWorkspace.getOriginOffsetInPixels(); + const mainOffsetPixels = targetWorkspace.getOriginOffsetInPixels(); // The offset in pixels between the flyout workspace's origin and the upper // left corner of the injection div. - var flyoutOffsetPixels = this.workspace_.getOriginOffsetInPixels(); + const flyoutOffsetPixels = this.workspace_.getOriginOffsetInPixels(); // The position of the old block in flyout workspace coordinates. - var oldBlockPos = oldBlock.getRelativeToSurfaceXY(); + const oldBlockPos = oldBlock.getRelativeToSurfaceXY(); // The position of the old block in pixels relative to the flyout // workspace's origin. oldBlockPos.scale(this.workspace_.scale); // The position of the old block in pixels relative to the upper left corner // of the injection div. - var oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, + const oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - var finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, + const finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); From 3df8c32594b6583a3f692f16952ea4dc254a83ce Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:11:27 -0700 Subject: [PATCH 018/172] Migrate core/flyout_base.js to goog.module --- core/flyout_base.js | 117 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 61 insertions(+), 58 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 3c62ebe51..18a3ab909 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Flyout'); +goog.module('Blockly.Flyout'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Block'); /** @suppress {extraRequire} */ @@ -55,8 +56,8 @@ goog.requireType('Blockly.utils.Rect'); * @implements {Blockly.IFlyout} * @extends {Blockly.DeleteArea} */ -Blockly.Flyout = function(workspaceOptions) { - Blockly.Flyout.superClass_.constructor.call(this); +const Flyout = function(workspaceOptions) { + Flyout.superClass_.constructor.call(this); workspaceOptions.setMetrics = this.setMetrics_.bind(this); /** @@ -149,41 +150,41 @@ Blockly.Flyout = function(workspaceOptions) { */ this.targetWorkspace = null; }; -Blockly.utils.object.inherits(Blockly.Flyout, Blockly.DeleteArea); +Blockly.utils.object.inherits(Flyout, Blockly.DeleteArea); /** * Does the flyout automatically close when a block is created? * @type {boolean} */ -Blockly.Flyout.prototype.autoClose = true; +Flyout.prototype.autoClose = true; /** * Whether the flyout is visible. * @type {boolean} * @private */ -Blockly.Flyout.prototype.isVisible_ = false; +Flyout.prototype.isVisible_ = false; /** * Whether the workspace containing this flyout is visible. * @type {boolean} * @private */ -Blockly.Flyout.prototype.containerVisible_ = true; +Flyout.prototype.containerVisible_ = true; /** * Corner radius of the flyout background. * @type {number} * @const */ -Blockly.Flyout.prototype.CORNER_RADIUS = 8; +Flyout.prototype.CORNER_RADIUS = 8; /** * Margin around the edges of the blocks in the flyout. * @type {number} * @const */ -Blockly.Flyout.prototype.MARGIN = Blockly.Flyout.prototype.CORNER_RADIUS; +Flyout.prototype.MARGIN = Flyout.prototype.CORNER_RADIUS; // TODO: Move GAP_X and GAP_Y to their appropriate files. @@ -192,35 +193,35 @@ Blockly.Flyout.prototype.MARGIN = Blockly.Flyout.prototype.CORNER_RADIUS; * element. * @const {number} */ -Blockly.Flyout.prototype.GAP_X = Blockly.Flyout.prototype.MARGIN * 3; +Flyout.prototype.GAP_X = Flyout.prototype.MARGIN * 3; /** * Gap between items in vertical flyouts. Can be overridden with the "sep" * element. * @const {number} */ -Blockly.Flyout.prototype.GAP_Y = Blockly.Flyout.prototype.MARGIN * 3; +Flyout.prototype.GAP_Y = Flyout.prototype.MARGIN * 3; /** * Top/bottom padding between scrollbar and edge of flyout background. * @type {number} * @const */ -Blockly.Flyout.prototype.SCROLLBAR_MARGIN = 2.5; +Flyout.prototype.SCROLLBAR_MARGIN = 2.5; /** * Width of flyout. * @type {number} * @protected */ -Blockly.Flyout.prototype.width_ = 0; +Flyout.prototype.width_ = 0; /** * Height of flyout. * @type {number} * @protected */ -Blockly.Flyout.prototype.height_ = 0; +Flyout.prototype.height_ = 0; /** * Range of a drag angle from a flyout considered "dragging toward workspace". @@ -238,7 +239,7 @@ Blockly.Flyout.prototype.height_ = 0; * @type {number} * @protected */ -Blockly.Flyout.prototype.dragAngleRange_ = 70; +Flyout.prototype.dragAngleRange_ = 70; /** * Creates the flyout's DOM. Only needs to be called once. The flyout can @@ -250,7 +251,7 @@ Blockly.Flyout.prototype.dragAngleRange_ = 70; * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ -Blockly.Flyout.prototype.createDom = function(tagName) { +Flyout.prototype.createDom = function(tagName) { /* @@ -277,7 +278,7 @@ Blockly.Flyout.prototype.createDom = function(tagName) { * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ -Blockly.Flyout.prototype.init = function(targetWorkspace) { +Flyout.prototype.init = function(targetWorkspace) { this.targetWorkspace = targetWorkspace; this.workspace_.targetWorkspace = targetWorkspace; @@ -326,7 +327,7 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { * Unlink from all DOM elements to prevent memory leaks. * @suppress {checkTypes} */ -Blockly.Flyout.prototype.dispose = function() { +Flyout.prototype.dispose = function() { this.hide(); this.workspace_.getComponentManager().removeComponent(this.id); Blockly.browserEvents.unbind(this.eventWrappers_); @@ -352,7 +353,7 @@ Blockly.Flyout.prototype.dispose = function() { * Get the width of the flyout. * @return {number} The width of the flyout. */ -Blockly.Flyout.prototype.getWidth = function() { +Flyout.prototype.getWidth = function() { return this.width_; }; @@ -360,7 +361,7 @@ Blockly.Flyout.prototype.getWidth = function() { * Get the height of the flyout. * @return {number} The width of the flyout. */ -Blockly.Flyout.prototype.getHeight = function() { +Flyout.prototype.getHeight = function() { return this.height_; }; @@ -369,7 +370,7 @@ Blockly.Flyout.prototype.getHeight = function() { * this matches the target workspace scale, but this can be overridden. * @return {number} Flyout workspace scale. */ -Blockly.Flyout.prototype.getFlyoutScale = function() { +Flyout.prototype.getFlyoutScale = function() { return this.targetWorkspace.scale; }; @@ -378,7 +379,7 @@ Blockly.Flyout.prototype.getFlyoutScale = function() { * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. * @package */ -Blockly.Flyout.prototype.getWorkspace = function() { +Flyout.prototype.getWorkspace = function() { return this.workspace_; }; @@ -386,7 +387,7 @@ Blockly.Flyout.prototype.getWorkspace = function() { * Is the flyout visible? * @return {boolean} True if visible. */ -Blockly.Flyout.prototype.isVisible = function() { +Flyout.prototype.isVisible = function() { return this.isVisible_; }; @@ -395,7 +396,7 @@ Blockly.Flyout.prototype.isVisible = function() { * that the flyout is shown. It could be hidden because its container is hidden. * @param {boolean} visible True if visible. */ -Blockly.Flyout.prototype.setVisible = function(visible) { +Flyout.prototype.setVisible = function(visible) { const visibilityChanged = (visible != this.isVisible()); this.isVisible_ = visible; @@ -413,7 +414,7 @@ Blockly.Flyout.prototype.setVisible = function(visible) { * Set whether this flyout's container is visible. * @param {boolean} visible Whether the container is visible. */ -Blockly.Flyout.prototype.setContainerVisible = function(visible) { +Flyout.prototype.setContainerVisible = function(visible) { const visibilityChanged = (visible != this.containerVisible_); this.containerVisible_ = visible; if (visibilityChanged) { @@ -426,7 +427,7 @@ Blockly.Flyout.prototype.setContainerVisible = function(visible) { * be visible and whether its containing workspace is visible. * @private */ -Blockly.Flyout.prototype.updateDisplay_ = function() { +Flyout.prototype.updateDisplay_ = function() { let show = true; if (!this.containerVisible_) { show = false; @@ -447,7 +448,7 @@ Blockly.Flyout.prototype.updateDisplay_ = function() { * @param {number} y The computed y origin of the flyout's SVG group. * @protected */ -Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { +Flyout.prototype.positionAt_ = function(width, height, x, y) { this.svgGroup_.setAttribute("width", width); this.svgGroup_.setAttribute("height", height); this.workspace_.setCachedParentSvgSize(width, height); @@ -485,7 +486,7 @@ Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { /** * Hide and empty the flyout. */ -Blockly.Flyout.prototype.hide = function() { +Flyout.prototype.hide = function() { if (!this.isVisible()) { return; } @@ -509,7 +510,7 @@ Blockly.Flyout.prototype.hide = function() { * in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ -Blockly.Flyout.prototype.show = function(flyoutDef) { +Flyout.prototype.show = function(flyoutDef) { this.workspace_.setResizesEnabled(false); this.hide(); this.clearOldBlocks_(); @@ -566,7 +567,7 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { * and gaps needed to lay out the flyout. * @private */ -Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { +Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { const contents = []; const gaps = []; this.permanentlyDisabled_.length = 0; @@ -626,7 +627,7 @@ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { * @return {!Array} The array of flyout items. * @private */ -Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { +Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( @@ -651,7 +652,7 @@ Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { * flyout. * @private */ -Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { +Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!Blockly.FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } @@ -668,7 +669,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @return {!Blockly.BlockSvg} The block created from the blockXml. * @protected */ -Blockly.Flyout.prototype.createBlock_ = function(blockXml) { +Flyout.prototype.createBlock_ = function(blockXml) { const curBlock = /** @type {!Blockly.BlockSvg} */ ( Blockly.Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { @@ -687,7 +688,7 @@ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { * @throws {Error} if the xml is not a valid block definition. * @private */ -Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { +Flyout.prototype.getBlockXml_ = function(blockInfo) { let blockElement = null; const blockXml = blockInfo['blockxml']; @@ -717,7 +718,7 @@ Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { * @param {number} defaultGap The default gap between the button and next element. * @private */ -Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { +Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { // Change the gap between two toolbox elements. // // The default gap is 24, can be set larger or smaller. @@ -735,7 +736,7 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) * Delete blocks, mats and buttons from a previous showing of the flyout. * @protected */ -Blockly.Flyout.prototype.clearOldBlocks_ = function() { +Flyout.prototype.clearOldBlocks_ = function() { // Delete any blocks from a previous showing. const oldBlocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = oldBlocks[i]); i++) { @@ -770,7 +771,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { * as a mat for that block. * @protected */ -Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { +Flyout.prototype.addBlockListeners_ = function(root, block, rect) { this.listeners_.push(Blockly.browserEvents.conditionalBind( root, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push(Blockly.browserEvents.conditionalBind( @@ -791,7 +792,7 @@ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { * @return {!Function} Function to call when block is clicked. * @private */ -Blockly.Flyout.prototype.blockMouseDown_ = function(block) { +Flyout.prototype.blockMouseDown_ = function(block) { const flyout = this; return function(e) { const gesture = flyout.targetWorkspace.getGesture(e); @@ -807,7 +808,7 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { * @param {!Event} e Mouse down event. * @private */ -Blockly.Flyout.prototype.onMouseDown_ = function(e) { +Flyout.prototype.onMouseDown_ = function(e) { const gesture = this.targetWorkspace.getGesture(e); if (gesture) { gesture.handleFlyoutStart(e, this); @@ -822,7 +823,7 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) { * otherwise. * @package */ -Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { +Flyout.prototype.isBlockCreatable_ = function(block) { return block.isEnabled(); }; @@ -833,7 +834,7 @@ Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { * @throws {Error} if something went wrong with deserialization. * @package */ -Blockly.Flyout.prototype.createBlock = function(originalBlock) { +Flyout.prototype.createBlock = function(originalBlock) { let newBlock = null; Blockly.Events.disable(); const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); @@ -880,7 +881,7 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { * @param {number} y The y position of the cursor during this layout pass. * @protected */ -Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { +Flyout.prototype.initFlyoutButton_ = function(button, x, y) { const buttonSvg = button.createDom(); button.moveTo(x, y); button.show(); @@ -905,7 +906,7 @@ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { * block. * @protected */ -Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { +Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. const rect = Blockly.utils.dom.createSvgElement( @@ -934,7 +935,7 @@ Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * @param {!Blockly.BlockSvg} block The block the rectangle should be behind. * @protected */ -Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { +Flyout.prototype.moveRectToBlock_ = function(rect, block) { const blockHW = block.getHeightWidth(); rect.setAttribute('width', blockHW.width); rect.setAttribute('height', blockHW.height); @@ -950,7 +951,7 @@ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { * the workspace, an "a + b" block that has two shadow blocks would be disabled. * @private */ -Blockly.Flyout.prototype.filterForCapacity_ = function() { +Flyout.prototype.filterForCapacity_ = function() { const blocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { @@ -967,7 +968,7 @@ Blockly.Flyout.prototype.filterForCapacity_ = function() { /** * Reflow blocks and their mats. */ -Blockly.Flyout.prototype.reflow = function() { +Flyout.prototype.reflow = function() { if (this.reflowWrapper_) { this.workspace_.removeChangeListener(this.reflowWrapper_); } @@ -982,7 +983,7 @@ Blockly.Flyout.prototype.reflow = function() { * dragging. * @package */ -Blockly.Flyout.prototype.isScrollable = function() { +Flyout.prototype.isScrollable = function() { return this.workspace_.scrollbar ? this.workspace_.scrollbar.isVisible() : false; }; @@ -993,7 +994,7 @@ Blockly.Flyout.prototype.isScrollable = function() { * @return {!Blockly.BlockSvg} The new block in the main workspace. * @private */ -Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { +Flyout.prototype.placeNewBlock_ = function(oldBlock) { const targetWorkspace = this.targetWorkspace; const svgRootOld = oldBlock.getSvgRoot(); if (!svgRootOld) { @@ -1051,13 +1052,13 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { * relative to viewport. * @return {Blockly.utils.Rect} The component's bounding box. */ -Blockly.Flyout.prototype.getClientRect; +Flyout.prototype.getClientRect; /** * Position the flyout. * @return {void} */ -Blockly.Flyout.prototype.position; +Flyout.prototype.position; /** * Determine if a drag delta is toward the workspace, based on the position @@ -1068,7 +1069,7 @@ Blockly.Flyout.prototype.position; * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.Flyout.prototype.isDragTowardWorkspace; +Flyout.prototype.isDragTowardWorkspace; /** * Sets the translation of the flyout to match the scrollbars. @@ -1077,7 +1078,7 @@ Blockly.Flyout.prototype.isDragTowardWorkspace; * similar x property. * @protected */ -Blockly.Flyout.prototype.setMetrics_; +Flyout.prototype.setMetrics_; /** * Lay out the blocks in the flyout. @@ -1085,14 +1086,14 @@ Blockly.Flyout.prototype.setMetrics_; * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.Flyout.prototype.layout_; +Flyout.prototype.layout_; /** * Scroll the flyout. * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.Flyout.prototype.wheel_; +Flyout.prototype.wheel_; /** * Compute height of flyout. Position mat under each block. @@ -1100,16 +1101,18 @@ Blockly.Flyout.prototype.wheel_; * @return {void} * @protected */ -Blockly.Flyout.prototype.reflowInternal_; +Flyout.prototype.reflowInternal_; /** * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.Flyout.prototype.getX; +Flyout.prototype.getX; /** * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.Flyout.prototype.getY; +Flyout.prototype.getY; + +exports = Flyout; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..f9a77b67a 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -61,7 +61,7 @@ goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Bloc goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); -goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); From c5694ba711ba14e43a7bf9906d9bcde94b05c99b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:26:32 -0700 Subject: [PATCH 019/172] Migrate core/flyout_base.js named requires --- core/flyout_base.js | 228 ++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 117 insertions(+), 113 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 18a3ab909..42e4d0966 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -13,60 +13,64 @@ goog.module('Blockly.Flyout'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const ComponentManager = goog.require('Blockly.ComponentManager'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DeleteArea = goog.require('Blockly.DeleteArea'); +const Events = goog.require('Blockly.Events'); +const FlyoutButton = goog.require('Blockly.FlyoutButton'); +const FlyoutMetricsManager = goog.require('Blockly.FlyoutMetricsManager'); +/* eslint-disable-next-line no-unused-vars */ +const IFlyout = goog.require('Blockly.IFlyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const ScrollbarPair = goog.require('Blockly.ScrollbarPair'); +const Svg = goog.require('Blockly.utils.Svg'); +const Tooltip = goog.require('Blockly.Tooltip'); +const Variables = goog.require('Blockly.Variables'); +const WorkspaceSvg = goog.require('Blockly.WorkspaceSvg'); +const Xml = goog.require('Blockly.Xml'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const toolbox = goog.require('Blockly.utils.toolbox'); +const utils = goog.require('Blockly.utils'); +const utilsXml = goog.require('Blockly.utils.xml'); +const {hideChaff} = goog.require('Blockly'); /** @suppress {extraRequire} */ goog.require('Blockly.blockRendering'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.ComponentManager'); -goog.require('Blockly.DeleteArea'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockCreate'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarCreate'); -goog.require('Blockly.FlyoutMetricsManager'); /** @suppress {extraRequire} */ goog.require('Blockly.Gesture'); -goog.require('Blockly.IFlyout'); -goog.require('Blockly.ScrollbarPair'); -goog.require('Blockly.Tooltip'); /** @suppress {extraRequire} */ goog.require('Blockly.Touch'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.utils.xml'); -goog.require('Blockly.WorkspaceSvg'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.FlyoutButton'); -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Rect'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. * @constructor * @abstract - * @implements {Blockly.IFlyout} - * @extends {Blockly.DeleteArea} + * @implements {IFlyout} + * @extends {DeleteArea} */ const Flyout = function(workspaceOptions) { Flyout.superClass_.constructor.call(this); workspaceOptions.setMetrics = this.setMetrics_.bind(this); /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @protected */ - this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions); + this.workspace_ = new WorkspaceSvg(workspaceOptions); this.workspace_.setMetricsManager( - new Blockly.FlyoutMetricsManager(this.workspace_, this)); + new FlyoutMetricsManager(this.workspace_, this)); this.workspace_.isFlyout = true; // Keep the workspace visibility consistent with the flyout's visibility. @@ -77,7 +81,7 @@ const Flyout = function(workspaceOptions) { * ComponentManager. * @type {string} */ - this.id = Blockly.utils.genUid(); + this.id = utils.genUid(); /** * Is RTL vs LTR. @@ -116,7 +120,7 @@ const Flyout = function(workspaceOptions) { /** * List of visible buttons. - * @type {!Array} + * @type {!Array} * @protected */ this.buttons_ = []; @@ -130,7 +134,7 @@ const Flyout = function(workspaceOptions) { /** * List of blocks that should always be disabled. - * @type {!Array} + * @type {!Array} * @private */ this.permanentlyDisabled_ = []; @@ -145,12 +149,12 @@ const Flyout = function(workspaceOptions) { /** * The target workspace - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} * @package */ this.targetWorkspace = null; }; -Blockly.utils.object.inherits(Flyout, Blockly.DeleteArea); +utils.object.inherits(Flyout, DeleteArea); /** * Does the flyout automatically close when a block is created? @@ -246,8 +250,8 @@ Flyout.prototype.dragAngleRange_ = 70; * either exist as its own SVG element or be a g element nested inside a * separate SVG element. * @param {string| - * !Blockly.utils.Svg| - * !Blockly.utils.Svg} tagName The type of tag to + * !Svg| + * !Svg} tagName The type of tag to * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ @@ -260,10 +264,10 @@ Flyout.prototype.createDom = function(tagName) { */ // Setting style to display:none to start. The toolbox and flyout // hide/show code will set up proper visibility and size later. - this.svgGroup_ = Blockly.utils.dom.createSvgElement(tagName, + this.svgGroup_ = dom.createSvgElement(tagName, {'class': 'blocklyFlyout', 'style': 'display: none'}, null); - this.svgBackground_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + this.svgBackground_ = dom.createSvgElement( + Svg.PATH, {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); this.svgGroup_.appendChild(this.workspace_.createDom()); this.workspace_.getThemeManager().subscribe( @@ -275,14 +279,14 @@ Flyout.prototype.createDom = function(tagName) { /** * Initializes the flyout. - * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to + * @param {!WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ Flyout.prototype.init = function(targetWorkspace) { this.targetWorkspace = targetWorkspace; this.workspace_.targetWorkspace = targetWorkspace; - this.workspace_.scrollbar = new Blockly.ScrollbarPair( + this.workspace_.scrollbar = new ScrollbarPair( this.workspace_, this.horizontalLayout, !this.horizontalLayout, 'blocklyFlyoutScrollbar', this.SCROLLBAR_MARGIN); @@ -290,7 +294,7 @@ Flyout.prototype.init = function(targetWorkspace) { Array.prototype.push.apply( this.eventWrappers_, - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.svgGroup_, 'wheel', this, this.wheel_)); if (!this.autoClose) { this.filterWrapper_ = this.filterForCapacity_.bind(this); @@ -300,7 +304,7 @@ Flyout.prototype.init = function(targetWorkspace) { // Dragging the flyout up and down. Array.prototype.push.apply( this.eventWrappers_, - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.svgBackground_, 'mousedown', this, this.onMouseDown_)); // A flyout connected to a workspace doesn't have its own current gesture. @@ -316,8 +320,8 @@ Flyout.prototype.init = function(targetWorkspace) { component: this, weight: 1, capabilities: [ - Blockly.ComponentManager.Capability.DELETE_AREA, - Blockly.ComponentManager.Capability.DRAG_TARGET + ComponentManager.Capability.DELETE_AREA, + ComponentManager.Capability.DRAG_TARGET ] }); }; @@ -330,7 +334,7 @@ Flyout.prototype.init = function(targetWorkspace) { Flyout.prototype.dispose = function() { this.hide(); this.workspace_.getComponentManager().removeComponent(this.id); - Blockly.browserEvents.unbind(this.eventWrappers_); + browserEvents.unbind(this.eventWrappers_); if (this.filterWrapper_) { this.targetWorkspace.removeChangeListener(this.filterWrapper_); this.filterWrapper_ = null; @@ -342,7 +346,7 @@ Flyout.prototype.dispose = function() { this.workspace_ = null; } if (this.svgGroup_) { - Blockly.utils.dom.removeNode(this.svgGroup_); + dom.removeNode(this.svgGroup_); this.svgGroup_ = null; } this.svgBackground_ = null; @@ -376,7 +380,7 @@ Flyout.prototype.getFlyoutScale = function() { /** * Get the workspace inside the flyout. - * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. + * @return {!WorkspaceSvg} The workspace inside the flyout. * @package */ Flyout.prototype.getWorkspace = function() { @@ -455,7 +459,7 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { if (this.svgGroup_.tagName == 'svg') { const transform = 'translate(' + x + 'px,' + y + 'px)'; - Blockly.utils.dom.setCssTransform(this.svgGroup_, transform); + dom.setCssTransform(this.svgGroup_, transform); } else { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself @@ -493,7 +497,7 @@ Flyout.prototype.hide = function() { this.setVisible(false); // Delete all the event listeners. for (let i = 0, listen; (listen = this.listeners_[i]); i++) { - Blockly.browserEvents.unbind(listen); + browserEvents.unbind(listen); } this.listeners_.length = 0; if (this.reflowWrapper_) { @@ -506,7 +510,7 @@ Flyout.prototype.hide = function() { /** * Show and populate the flyout. - * @param {!Blockly.utils.toolbox.FlyoutDefinition|string} flyoutDef Contents to display + * @param {!toolbox.FlyoutDefinition|string} flyoutDef Contents to display * in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ @@ -522,7 +526,7 @@ Flyout.prototype.show = function(flyoutDef) { this.setVisible(true); // Parse the Array, Node or NodeList into a a list of flyout items. - const parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); + const parsedContent = toolbox.convertFlyoutDefToJsonArray(flyoutDef); const flyoutInfo = /** @type {{contents:!Array, gaps:!Array}} */ ( this.createFlyoutInfo_(parsedContent)); @@ -538,7 +542,7 @@ Flyout.prototype.show = function(flyoutDef) { } }; - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( this.svgBackground_, 'mouseover', this, deselectAll)); if (this.horizontalLayout) { @@ -561,7 +565,7 @@ Flyout.prototype.show = function(flyoutDef) { /** * Create the contents array and gaps array necessary to create the layout for * the flyout. - * @param {!Blockly.utils.toolbox.FlyoutItemInfoArray} parsedContent The array + * @param {!toolbox.FlyoutItemInfoArray} parsedContent The array * of objects to show in the flyout. * @return {{contents:Array, gaps:Array}} The list of contents * and gaps needed to lay out the flyout. @@ -575,18 +579,18 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { if (contentInfo['custom']) { - const customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); + const customInfo = /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); const categoryName = customInfo['custom']; const flyoutDef = this.getDynamicCategoryContents_(categoryName); - const parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ - (Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef)); + const parsedDynamicContent = /** @type {!toolbox.FlyoutItemInfoArray} */ + (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } switch (contentInfo['kind'].toUpperCase()) { case 'BLOCK': { - const blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); + const blockInfo = /** @type {!toolbox.BlockInfo} */ (contentInfo); const blockXml = this.getBlockXml_(blockInfo); const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. @@ -597,12 +601,12 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { break; } case 'SEP': { - const sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); + const sepInfo = /** @type {!toolbox.SeparatorInfo} */ (contentInfo); this.addSeparatorGap_(sepInfo, gaps, defaultGap); break; } case 'LABEL': { - const labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); + const labelInfo = /** @type {!toolbox.LabelInfo} */ (contentInfo); // A label is a button with different styling. const label = this.createButton_(labelInfo, /** isLabel */ true); contents.push({type: 'button', button: label}); @@ -610,7 +614,7 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { break; } case 'BUTTON': { - const buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); + const buttonInfo = /** @type {!toolbox.ButtonInfo} */ (contentInfo); const button = this.createButton_(buttonInfo, /** isLabel */ false); contents.push({type: 'button', button: button}); gaps.push(defaultGap); @@ -645,19 +649,19 @@ Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { /** * Creates a flyout button or a flyout label. - * @param {!Blockly.utils.toolbox.ButtonOrLabelInfo} btnInfo + * @param {!toolbox.ButtonOrLabelInfo} btnInfo * The object holding information about a button or a label. * @param {boolean} isLabel True if the button is a label, false otherwise. - * @return {!Blockly.FlyoutButton} The object used to display the button in the + * @return {!FlyoutButton} The object used to display the button in the * flyout. * @private */ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { - if (!Blockly.FlyoutButton) { + if (!FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - const curButton = new Blockly.FlyoutButton(this.workspace_, - /** @type {!Blockly.WorkspaceSvg} */ (this.targetWorkspace), btnInfo, + const curButton = new FlyoutButton(this.workspace_, + /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; }; @@ -666,12 +670,12 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * Create a block from the xml and permanently disable any blocks that were * defined as disabled. * @param {!Element} blockXml The xml of the block. - * @return {!Blockly.BlockSvg} The block created from the blockXml. + * @return {!BlockSvg} The block created from the blockXml. * @protected */ Flyout.prototype.createBlock_ = function(blockXml) { - const curBlock = /** @type {!Blockly.BlockSvg} */ ( - Blockly.Xml.domToBlock(blockXml, this.workspace_)); + const curBlock = /** @type {!BlockSvg} */ ( + Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. // Do not enable these blocks as a result of capacity filtering. @@ -682,7 +686,7 @@ Flyout.prototype.createBlock_ = function(blockXml) { /** * Get the xml from the block info object. - * @param {!Blockly.utils.toolbox.BlockInfo} blockInfo The object holding + * @param {!toolbox.BlockInfo} blockInfo The object holding * information about a block. * @return {!Element} The xml for the block. * @throws {Error} if the xml is not a valid block definition. @@ -695,10 +699,10 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { if (blockXml && typeof blockXml != 'string') { blockElement = blockXml; } else if (blockXml && typeof blockXml == 'string') { - blockElement = Blockly.Xml.textToDom(blockXml); + blockElement = Xml.textToDom(blockXml); blockInfo['blockxml'] = blockElement; } else if (blockInfo['type']) { - blockElement = Blockly.utils.xml.createElement('xml'); + blockElement = utilsXml.createElement('xml'); blockElement.setAttribute('type', blockInfo['type']); blockElement.setAttribute('disabled', blockInfo['disabled']); blockInfo['blockxml'] = blockElement; @@ -712,7 +716,7 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { /** * Add the necessary gap in the flyout for a separator. - * @param {!Blockly.utils.toolbox.SeparatorInfo} sepInfo The object holding + * @param {!toolbox.SeparatorInfo} sepInfo The object holding * information about a separator. * @param {!Array} gaps The list gaps between items in the flyout. * @param {number} defaultGap The default gap between the button and next element. @@ -748,8 +752,8 @@ Flyout.prototype.clearOldBlocks_ = function() { for (let j = 0; j < this.mats_.length; j++) { const rect = this.mats_[j]; if (rect) { - Blockly.Tooltip.unbindMouseEvents(rect); - Blockly.utils.dom.removeNode(rect); + Tooltip.unbindMouseEvents(rect); + dom.removeNode(rect); } } this.mats_.length = 0; @@ -766,29 +770,29 @@ Flyout.prototype.clearOldBlocks_ = function() { /** * Add listeners to a block that has been added to the flyout. * @param {!SVGElement} root The root node of the SVG group the block is in. - * @param {!Blockly.BlockSvg} block The block to add listeners for. + * @param {!BlockSvg} block The block to add listeners for. * @param {!SVGElement} rect The invisible rectangle under the block that acts * as a mat for that block. * @protected */ Flyout.prototype.addBlockListeners_ = function(root, block, rect) { - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( root, 'mousedown', null, this.blockMouseDown_(block))); - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( rect, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push( - Blockly.browserEvents.bind(root, 'mouseenter', block, block.addSelect)); - this.listeners_.push(Blockly.browserEvents.bind( + browserEvents.bind(root, 'mouseenter', block, block.addSelect)); + this.listeners_.push(browserEvents.bind( root, 'mouseleave', block, block.removeSelect)); this.listeners_.push( - Blockly.browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); - this.listeners_.push(Blockly.browserEvents.bind( + browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); + this.listeners_.push(browserEvents.bind( rect, 'mouseleave', block, block.removeSelect)); }; /** * Handle a mouse-down on an SVG block in a non-closing flyout. - * @param {!Blockly.BlockSvg} block The flyout block to copy. + * @param {!BlockSvg} block The flyout block to copy. * @return {!Function} Function to call when block is clicked. * @private */ @@ -818,7 +822,7 @@ Flyout.prototype.onMouseDown_ = function(e) { /** * Does this flyout allow you to create a new instance of the given block? * Used for deciding if a block can be "dragged out of" the flyout. - * @param {!Blockly.BlockSvg} block The block to copy from the flyout. + * @param {!BlockSvg} block The block to copy from the flyout. * @return {boolean} True if you can create a new instance of the block, false * otherwise. * @package @@ -829,41 +833,41 @@ Flyout.prototype.isBlockCreatable_ = function(block) { /** * Create a copy of this block on the workspace. - * @param {!Blockly.BlockSvg} originalBlock The block to copy from the flyout. - * @return {!Blockly.BlockSvg} The newly created block. + * @param {!BlockSvg} originalBlock The block to copy from the flyout. + * @return {!BlockSvg} The newly created block. * @throws {Error} if something went wrong with deserialization. * @package */ Flyout.prototype.createBlock = function(originalBlock) { let newBlock = null; - Blockly.Events.disable(); + Events.disable(); const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); this.targetWorkspace.setResizesEnabled(false); try { newBlock = this.placeNewBlock_(originalBlock); } finally { - Blockly.Events.enable(); + Events.enable(); } // Close the flyout. - Blockly.hideChaff(); + hideChaff(); - const newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, + const newVariables = Variables.getAddedVariables(this.targetWorkspace, variablesBeforeCreation); - if (Blockly.Events.isEnabled()) { - Blockly.Events.setGroup(true); + if (Events.isEnabled()) { + Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. for (let i = 0; i < newVariables.length; i++) { const thisVariable = newVariables[i]; - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.VAR_CREATE))(thisVariable)); + Events.fire( + new (Events.get(Events.VAR_CREATE))(thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock)); + Events.fire( + new (Events.get(Events.BLOCK_CREATE))(newBlock)); } if (this.autoClose) { this.hide(); @@ -876,7 +880,7 @@ Flyout.prototype.createBlock = function(originalBlock) { /** * Initialize the given button: move it to the correct location, * add listeners, etc. - * @param {!Blockly.FlyoutButton} button The button to initialize and place. + * @param {!FlyoutButton} button The button to initialize and place. * @param {number} x The x position of the cursor during this layout pass. * @param {number} y The y position of the cursor during this layout pass. * @protected @@ -887,7 +891,7 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { button.show(); // Clicking on a flyout button or label is a lot like clicking on the // flyout background. - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( buttonSvg, 'mousedown', this, this.onMouseDown_)); this.buttons_.push(button); @@ -895,7 +899,7 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { /** * Create and place a rectangle corresponding to the given block. - * @param {!Blockly.BlockSvg} block The block to associate the rect to. + * @param {!BlockSvg} block The block to associate the rect to. * @param {number} x The x position of the cursor during this layout pass. * @param {number} y The y position of the cursor during this layout pass. * @param {!{height: number, width: number}} blockHW The height and width of the @@ -909,8 +913,8 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. - const rect = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + const rect = dom.createSvgElement( + Svg.RECT, { 'fill-opacity': 0, 'x': x, @@ -919,7 +923,7 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { 'width': blockHW.width }, null); rect.tooltip = block; - Blockly.Tooltip.bindMouseEvents(rect); + Tooltip.bindMouseEvents(rect); // Add the rectangles under the blocks, so that the blocks' tooltips work. this.workspace_.getCanvas().insertBefore(rect, block.getSvgRoot()); @@ -932,7 +936,7 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * Move a rectangle to sit exactly behind a block, taking into account tabs, * hats, and any other protrusions we invent. * @param {!SVGElement} rect The rectangle to move directly behind the block. - * @param {!Blockly.BlockSvg} block The block the rectangle should be behind. + * @param {!BlockSvg} block The block the rectangle should be behind. * @protected */ Flyout.prototype.moveRectToBlock_ = function(rect, block) { @@ -956,7 +960,7 @@ Flyout.prototype.filterForCapacity_ = function() { for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { const enable = this.targetWorkspace - .isCapacityAvailable(Blockly.utils.getBlockTypeCounts(block)); + .isCapacityAvailable(utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); block = block.getNextBlock(); @@ -990,8 +994,8 @@ Flyout.prototype.isScrollable = function() { /** * Copy a block from the flyout to the workspace and position it correctly. - * @param {!Blockly.BlockSvg} oldBlock The flyout block to copy. - * @return {!Blockly.BlockSvg} The new block in the main workspace. + * @param {!BlockSvg} oldBlock The flyout block to copy. + * @return {!BlockSvg} The new block in the main workspace. * @private */ Flyout.prototype.placeNewBlock_ = function(oldBlock) { @@ -1003,15 +1007,15 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // Create the new block by cloning the block in the flyout (via XML). // This cast assumes that the oldBlock can not be an insertion marker. - const xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); + const xml = /** @type {!Element} */ (Xml.blockToDom(oldBlock, true)); // The target workspace would normally resize during domToBlock, which will // lead to weird jumps. Save it for terminateDrag. targetWorkspace.setResizesEnabled(false); // Using domToBlock instead of domToWorkspace means that the new block will be // placed at position (0, 0) in main workspace units. - const block = /** @type {!Blockly.BlockSvg} */ - (Blockly.Xml.domToBlock(xml, targetWorkspace)); + const block = /** @type {!BlockSvg} */ + (Xml.domToBlock(xml, targetWorkspace)); const svgRootNew = block.getSvgRoot(); if (!svgRootNew) { throw Error('block is not rendered.'); @@ -1033,12 +1037,12 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // The position of the old block in pixels relative to the upper left corner // of the injection div. - const oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, + const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - const finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, + const finalOffset = Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); @@ -1050,7 +1054,7 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {Blockly.utils.Rect} The component's bounding box. + * @return {utils.Rect} The component's bounding box. */ Flyout.prototype.getClientRect; @@ -1064,7 +1068,7 @@ Flyout.prototype.position; * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package diff --git a/tests/deps.js b/tests/deps.js index f9a77b67a..54c8af48e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -61,7 +61,7 @@ goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Bloc goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); -goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly', 'Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutButton', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); From 47314fd0b921a0d315f6aadc4cd6837a039613b8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:27:36 -0700 Subject: [PATCH 020/172] clang-format core/flyout_base.js --- core/flyout_base.js | 97 +++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 42e4d0966..594d83a9f 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -242,7 +242,7 @@ Flyout.prototype.height_ = 0; * flyout. Setting it to 360 means that all drags create a new block. * @type {number} * @protected -*/ + */ Flyout.prototype.dragAngleRange_ = 70; /** @@ -264,11 +264,10 @@ Flyout.prototype.createDom = function(tagName) { */ // Setting style to display:none to start. The toolbox and flyout // hide/show code will set up proper visibility and size later. - this.svgGroup_ = dom.createSvgElement(tagName, - {'class': 'blocklyFlyout', 'style': 'display: none'}, null); + this.svgGroup_ = dom.createSvgElement( + tagName, {'class': 'blocklyFlyout', 'style': 'display: none'}, null); this.svgBackground_ = dom.createSvgElement( - Svg.PATH, - {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); + Svg.PATH, {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); this.svgGroup_.appendChild(this.workspace_.createDom()); this.workspace_.getThemeManager().subscribe( this.svgBackground_, 'flyoutBackgroundColour', 'fill'); @@ -453,8 +452,8 @@ Flyout.prototype.updateDisplay_ = function() { * @protected */ Flyout.prototype.positionAt_ = function(width, height, x, y) { - this.svgGroup_.setAttribute("width", width); - this.svgGroup_.setAttribute("height", height); + this.svgGroup_.setAttribute('width', width); + this.svgGroup_.setAttribute('height', height); this.workspace_.setCachedParentSvgSize(width, height); if (this.svgGroup_.tagName == 'svg') { @@ -464,7 +463,7 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself const transform = 'translate(' + x + ',' + y + ')'; - this.svgGroup_.setAttribute("transform", transform); + this.svgGroup_.setAttribute('transform', transform); } // Update the scrollbar (if one exists). @@ -482,7 +481,6 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { if (scrollbar.vScroll) { scrollbar.vScroll.setPosition( scrollbar.vScroll.position.x, scrollbar.vScroll.position.y); - } } }; @@ -528,8 +526,8 @@ Flyout.prototype.show = function(flyoutDef) { // Parse the Array, Node or NodeList into a a list of flyout items. const parsedContent = toolbox.convertFlyoutDefToJsonArray(flyoutDef); const flyoutInfo = - /** @type {{contents:!Array, gaps:!Array}} */ ( - this.createFlyoutInfo_(parsedContent)); + /** @type {{contents:!Array, gaps:!Array}} */ ( + this.createFlyoutInfo_(parsedContent)); this.layout_(flyoutInfo.contents, flyoutInfo.gaps); @@ -577,14 +575,15 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { this.permanentlyDisabled_.length = 0; const defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { - if (contentInfo['custom']) { - const customInfo = /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); + const customInfo = + /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); const categoryName = customInfo['custom']; const flyoutDef = this.getDynamicCategoryContents_(categoryName); const parsedDynamicContent = /** @type {!toolbox.FlyoutItemInfoArray} */ - (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); - parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); + (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); + parsedContent.splice.apply( + parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } @@ -595,7 +594,8 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. // - const gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); + const gap = + parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); gaps.push(isNaN(gap) ? defaultGap : gap); contents.push({type: 'block', block: block}); break; @@ -634,15 +634,17 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. - const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( - categoryName); + const fnToApply = + this.workspace_.targetWorkspace.getToolboxCategoryCallback(categoryName); if (typeof fnToApply != 'function') { - throw TypeError('Couldn\'t find a callback function when opening' + + throw TypeError( + 'Couldn\'t find a callback function when opening' + ' a toolbox category.'); } const flyoutDef = fnToApply(this.workspace_.targetWorkspace); if (!Array.isArray(flyoutDef)) { - throw new TypeError('Result of toolbox category callback must be an array.'); + throw new TypeError( + 'Result of toolbox category callback must be an array.'); } return flyoutDef; }; @@ -660,9 +662,9 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - const curButton = new FlyoutButton(this.workspace_, - /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, - isLabel); + const curButton = new FlyoutButton( + this.workspace_, + /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; }; @@ -674,8 +676,8 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @protected */ Flyout.prototype.createBlock_ = function(blockXml) { - const curBlock = /** @type {!BlockSvg} */ ( - Xml.domToBlock(blockXml, this.workspace_)); + const curBlock = + /** @type {!BlockSvg} */ (Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. // Do not enable these blocks as a result of capacity filtering. @@ -709,7 +711,8 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { } if (!blockElement) { - throw Error('Error: Invalid block definition. Block definition must have blockxml or type.'); + throw Error( + 'Error: Invalid block definition. Block definition must have blockxml or type.'); } return blockElement; }; @@ -719,7 +722,8 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { * @param {!toolbox.SeparatorInfo} sepInfo The object holding * information about a separator. * @param {!Array} gaps The list gaps between items in the flyout. - * @param {number} defaultGap The default gap between the button and next element. + * @param {number} defaultGap The default gap between the button and next + * element. * @private */ Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { @@ -782,12 +786,12 @@ Flyout.prototype.addBlockListeners_ = function(root, block, rect) { rect, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push( browserEvents.bind(root, 'mouseenter', block, block.addSelect)); - this.listeners_.push(browserEvents.bind( - root, 'mouseleave', block, block.removeSelect)); + this.listeners_.push( + browserEvents.bind(root, 'mouseleave', block, block.removeSelect)); this.listeners_.push( browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); - this.listeners_.push(browserEvents.bind( - rect, 'mouseleave', block, block.removeSelect)); + this.listeners_.push( + browserEvents.bind(rect, 'mouseleave', block, block.removeSelect)); }; /** @@ -852,22 +856,20 @@ Flyout.prototype.createBlock = function(originalBlock) { // Close the flyout. hideChaff(); - const newVariables = Variables.getAddedVariables(this.targetWorkspace, - variablesBeforeCreation); + const newVariables = Variables.getAddedVariables( + this.targetWorkspace, variablesBeforeCreation); if (Events.isEnabled()) { Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. for (let i = 0; i < newVariables.length; i++) { const thisVariable = newVariables[i]; - Events.fire( - new (Events.get(Events.VAR_CREATE))(thisVariable)); + Events.fire(new (Events.get(Events.VAR_CREATE))(thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. - Events.fire( - new (Events.get(Events.BLOCK_CREATE))(newBlock)); + Events.fire(new (Events.get(Events.BLOCK_CREATE))(newBlock)); } if (this.autoClose) { this.hide(); @@ -914,14 +916,14 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. const rect = dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'fill-opacity': 0, 'x': x, 'y': y, 'height': blockHW.height, 'width': blockHW.width - }, null); + }, + null); rect.tooltip = block; Tooltip.bindMouseEvents(rect); // Add the rectangles under the blocks, so that the blocks' tooltips work. @@ -959,8 +961,8 @@ Flyout.prototype.filterForCapacity_ = function() { const blocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { - const enable = this.targetWorkspace - .isCapacityAvailable(utils.getBlockTypeCounts(block)); + const enable = this.targetWorkspace.isCapacityAvailable( + utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); block = block.getNextBlock(); @@ -988,8 +990,8 @@ Flyout.prototype.reflow = function() { * @package */ Flyout.prototype.isScrollable = function() { - return this.workspace_.scrollbar ? - this.workspace_.scrollbar.isVisible() : false; + return this.workspace_.scrollbar ? this.workspace_.scrollbar.isVisible() : + false; }; /** @@ -1037,13 +1039,12 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // The position of the old block in pixels relative to the upper left corner // of the injection div. - const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, - oldBlockPos); + const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - const finalOffset = Coordinate.difference(oldBlockOffsetPixels, - mainOffsetPixels); + const finalOffset = + Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); From 8cb794feb5f9285476c6fdff6e7467881535afcf Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 16:36:30 -0700 Subject: [PATCH 021/172] Suppress unused vars --- core/menu.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/menu.js b/core/menu.js index 083d76e06..6a1667964 100644 --- a/core/menu.js +++ b/core/menu.js @@ -14,6 +14,7 @@ goog.module('Blockly.Menu'); goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const MenuItem = goog.requireType('Blockly.MenuItem'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); const Size = goog.requireType('Blockly.utils.Size'); From 39f5b4c7cd606602cffa70a1b8d2f60d3f794296 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 16:49:01 -0700 Subject: [PATCH 022/172] Fixes lint warnings --- core/menu.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/menu.js b/core/menu.js index 6a1667964..91cfb4d36 100644 --- a/core/menu.js +++ b/core/menu.js @@ -17,6 +17,7 @@ const Coordinate = goog.require('Blockly.utils.Coordinate'); /* eslint-disable-next-line no-unused-vars */ const MenuItem = goog.requireType('Blockly.MenuItem'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); const aria = goog.require('Blockly.utils.aria'); const browserEvents = goog.require('Blockly.browserEvents'); From b07c6869ba6cc42b80db3c8a9b458d04b930fc20 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:28 -0700 Subject: [PATCH 023/172] Migrate core/field_label_serializable.js to ES6 const/let --- core/field_label_serializable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 0201db130..0d1acf52a 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -47,7 +47,7 @@ Blockly.utils.object.inherits(Blockly.FieldLabelSerializable, * @nocollapse */ Blockly.FieldLabelSerializable.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. return new this(text, undefined, options); From 20ef2462b5bdaf24d0e2d527ca63e8bb25e806cc Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:40 -0700 Subject: [PATCH 024/172] Migrate core/field_label_serializable.js to goog.module --- core/field_label_serializable.js | 21 ++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 0d1acf52a..77784eb4c 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldLabelSerializable'); +goog.module('Blockly.FieldLabelSerializable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.FieldLabel'); goog.require('Blockly.fieldRegistry'); @@ -31,22 +32,22 @@ goog.require('Blockly.utils.object'); * @constructor * */ -Blockly.FieldLabelSerializable = function(opt_value, opt_class, opt_config) { - Blockly.FieldLabelSerializable.superClass_.constructor.call( +const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { + FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -Blockly.utils.object.inherits(Blockly.FieldLabelSerializable, +Blockly.utils.object.inherits(FieldLabelSerializable, Blockly.FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and class). - * @return {!Blockly.FieldLabelSerializable} The new field instance. + * @return {!FieldLabelSerializable} The new field instance. * @package * @nocollapse */ -Blockly.FieldLabelSerializable.fromJson = function(options) { +FieldLabelSerializable.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. @@ -58,14 +59,16 @@ Blockly.FieldLabelSerializable.fromJson = function(options) { * editable. This field should not. * @type {boolean} */ -Blockly.FieldLabelSerializable.prototype.EDITABLE = false; +FieldLabelSerializable.prototype.EDITABLE = false; /** * Serializable fields are saved by the XML renderer, non-serializable fields * are not. This field should be serialized, but only edited programmatically. * @type {boolean} */ -Blockly.FieldLabelSerializable.prototype.SERIALIZABLE = true; +FieldLabelSerializable.prototype.SERIALIZABLE = true; Blockly.fieldRegistry.register( - 'field_label_serializable', Blockly.FieldLabelSerializable); + 'field_label_serializable', FieldLabelSerializable); + +exports = FieldLabelSerializable; diff --git a/tests/deps.js b/tests/deps.js index d02bbc5ea..226f67c0f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -55,7 +55,7 @@ goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Bloc goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); From bcb57b7efd721878e275255ac4b09fc18064fced Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:51 -0700 Subject: [PATCH 025/172] Migrate core/field_label_serializable.js named requires --- core/field_label_serializable.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 77784eb4c..828a9954b 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -14,10 +14,10 @@ goog.module('Blockly.FieldLabelSerializable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.FieldLabel'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); +const FieldLabel = goog.require('Blockly.FieldLabel'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -28,7 +28,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldLabel} + * @extends {FieldLabel} * @constructor * */ @@ -36,8 +36,8 @@ const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -Blockly.utils.object.inherits(FieldLabelSerializable, - Blockly.FieldLabel); +inherits(FieldLabelSerializable, + FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, @@ -48,7 +48,7 @@ Blockly.utils.object.inherits(FieldLabelSerializable, * @nocollapse */ FieldLabelSerializable.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -68,7 +68,7 @@ FieldLabelSerializable.prototype.EDITABLE = false; */ FieldLabelSerializable.prototype.SERIALIZABLE = true; -Blockly.fieldRegistry.register( +fieldRegistry.register( 'field_label_serializable', FieldLabelSerializable); exports = FieldLabelSerializable; From 569a86901ea7888678d7364e96a1d6b99284d103 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:08:45 -0700 Subject: [PATCH 026/172] clang-format core/field_label_serializable.js --- core/field_label_serializable.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 828a9954b..daabaa59f 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -26,7 +26,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * string. Defaults to an empty string if null or undefined. * @param {string=} opt_class Optional CSS class for the field's text. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} * for a list of properties this parameter supports. * @extends {FieldLabel} * @constructor @@ -36,8 +37,7 @@ const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -inherits(FieldLabelSerializable, - FieldLabel); +inherits(FieldLabelSerializable, FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, @@ -68,7 +68,6 @@ FieldLabelSerializable.prototype.EDITABLE = false; */ FieldLabelSerializable.prototype.SERIALIZABLE = true; -fieldRegistry.register( - 'field_label_serializable', FieldLabelSerializable); +fieldRegistry.register('field_label_serializable', FieldLabelSerializable); exports = FieldLabelSerializable; From 60c03cef4fd495cb2a23dc25ce00d70d9e2b89bd Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:23:23 -0700 Subject: [PATCH 027/172] Migrate core/field_image.js to ES6 const/let --- core/field_image.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index eed381b63..163941efb 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -44,8 +44,8 @@ Blockly.FieldImage = function(src, width, height, throw Error('Src value of an image field is required'); } src = Blockly.utils.replaceMessageReferences(src); - var imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); - var imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); + const imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); + const imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { throw Error('Height and width values of an image field must cast to' + ' numbers.'); From f1882fc2180949292db8f5961ffa8308ff254c26 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:23:35 -0700 Subject: [PATCH 028/172] Migrate core/field_image.js to goog.module --- core/field_image.js | 55 ++++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 163941efb..68a1fb43c 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldImage'); +goog.module('Blockly.FieldImage'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Field'); goog.require('Blockly.fieldRegistry'); @@ -27,7 +28,7 @@ goog.require('Blockly.utils.Svg'); * @param {!(string|number)} width Width of the image. * @param {!(string|number)} height Height of the image. * @param {string=} opt_alt Optional alt text for when block is collapsed. - * @param {function(!Blockly.FieldImage)=} opt_onClick Optional function to be + * @param {function(!FieldImage)=} opt_onClick Optional function to be * called when the image is clicked. If opt_onClick is defined, opt_alt must * also be defined. * @param {boolean=} opt_flipRtl Whether to flip the icon in RTL. @@ -37,7 +38,7 @@ goog.require('Blockly.utils.Svg'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldImage = function(src, width, height, +const FieldImage = function(src, width, height, opt_alt, opt_onClick, opt_flipRtl, opt_config) { // Return early. if (!src) { @@ -70,7 +71,7 @@ Blockly.FieldImage = function(src, width, height, */ this.altText_ = ''; - Blockly.FieldImage.superClass_.constructor.call( + FieldImage.superClass_.constructor.call( this, src, null, opt_config); if (!opt_config) { // If the config wasn't passed, do old configuration. @@ -86,7 +87,7 @@ Blockly.FieldImage = function(src, width, height, * @override */ this.size_ = new Blockly.utils.Size(imageWidth, - imageHeight + Blockly.FieldImage.Y_PADDING); + imageHeight + FieldImage.Y_PADDING); /** * Store the image height, since it is different from the field height. @@ -97,7 +98,7 @@ Blockly.FieldImage = function(src, width, height, /** * The function to be called when this field is clicked. - * @type {?function(!Blockly.FieldImage)} + * @type {?function(!FieldImage)} * @private */ this.clickHandler_ = null; @@ -113,25 +114,25 @@ Blockly.FieldImage = function(src, width, height, */ this.imageElement_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldImage, Blockly.Field); +Blockly.utils.object.inherits(FieldImage, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldImage.prototype.DEFAULT_VALUE = ''; +FieldImage.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldImage from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (src, width, height, * alt, and flipRtl). - * @return {!Blockly.FieldImage} The new field instance. + * @return {!FieldImage} The new field instance. * @package * @nocollapse */ -Blockly.FieldImage.fromJson = function(options) { +FieldImage.fromJson = function(options) { // `this` might be a subclass of FieldImage if that class doesn't override // the static fromJson method. return new this(options['src'], options['width'], options['height'], @@ -144,14 +145,14 @@ Blockly.FieldImage.fromJson = function(options) { * @type {number} * @private */ -Blockly.FieldImage.Y_PADDING = 1; +FieldImage.Y_PADDING = 1; /** * Editable fields usually show some sort of UI indicating they are * editable. This field should not. * @type {boolean} */ -Blockly.FieldImage.prototype.EDITABLE = false; +FieldImage.prototype.EDITABLE = false; /** * Used to tell if the field needs to be rendered the next time the block is @@ -160,7 +161,7 @@ Blockly.FieldImage.prototype.EDITABLE = false; * @type {boolean} * @protected */ -Blockly.FieldImage.prototype.isDirty_ = false; +FieldImage.prototype.isDirty_ = false; /** * Configure the field based on the given map of options. @@ -168,8 +169,8 @@ Blockly.FieldImage.prototype.isDirty_ = false; * @protected * @override */ -Blockly.FieldImage.prototype.configure_ = function(config) { - Blockly.FieldImage.superClass_.configure_.call(this, config); +FieldImage.prototype.configure_ = function(config) { + FieldImage.superClass_.configure_.call(this, config); this.flipRtl_ = !!config['flipRtl']; this.altText_ = Blockly.utils.replaceMessageReferences(config['alt']) || ''; }; @@ -178,7 +179,7 @@ Blockly.FieldImage.prototype.configure_ = function(config) { * Create the block UI for this image. * @package */ -Blockly.FieldImage.prototype.initView = function() { +FieldImage.prototype.initView = function() { this.imageElement_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { @@ -198,7 +199,7 @@ Blockly.FieldImage.prototype.initView = function() { /** * @override */ -Blockly.FieldImage.prototype.updateSize_ = function() { +FieldImage.prototype.updateSize_ = function() { // NOP }; @@ -208,7 +209,7 @@ Blockly.FieldImage.prototype.updateSize_ = function() { * @return {?string} A string, or null if invalid. * @protected */ -Blockly.FieldImage.prototype.doClassValidation_ = function(opt_newValue) { +FieldImage.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } @@ -221,7 +222,7 @@ Blockly.FieldImage.prototype.doClassValidation_ = function(opt_newValue) { * that this is a string. * @protected */ -Blockly.FieldImage.prototype.doValueUpdate_ = function(newValue) { +FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, @@ -234,7 +235,7 @@ Blockly.FieldImage.prototype.doValueUpdate_ = function(newValue) { * @return {boolean} True if we should flip in RTL. * @override */ -Blockly.FieldImage.prototype.getFlipRtl = function() { +FieldImage.prototype.getFlipRtl = function() { return this.flipRtl_; }; @@ -243,7 +244,7 @@ Blockly.FieldImage.prototype.getFlipRtl = function() { * @param {?string} alt New alt text. * @public */ -Blockly.FieldImage.prototype.setAlt = function(alt) { +FieldImage.prototype.setAlt = function(alt) { if (alt == this.altText_) { return; } @@ -258,7 +259,7 @@ Blockly.FieldImage.prototype.setAlt = function(alt) { * call the handler. * @protected */ -Blockly.FieldImage.prototype.showEditor_ = function() { +FieldImage.prototype.showEditor_ = function() { if (this.clickHandler_) { this.clickHandler_(this); } @@ -266,10 +267,10 @@ Blockly.FieldImage.prototype.showEditor_ = function() { /** * Set the function that is called when this image is clicked. - * @param {?function(!Blockly.FieldImage)} func The function that is called + * @param {?function(!FieldImage)} func The function that is called * when the image is clicked, or null to remove. */ -Blockly.FieldImage.prototype.setOnClickHandler = function(func) { +FieldImage.prototype.setOnClickHandler = function(func) { this.clickHandler_ = func; }; @@ -281,8 +282,10 @@ Blockly.FieldImage.prototype.setOnClickHandler = function(func) { * @protected * @override */ -Blockly.FieldImage.prototype.getText_ = function() { +FieldImage.prototype.getText_ = function() { return this.altText_; }; -Blockly.fieldRegistry.register('field_image', Blockly.FieldImage); +Blockly.fieldRegistry.register('field_image', FieldImage); + +exports = FieldImage; diff --git a/tests/deps.js b/tests/deps.js index 226f67c0f..77f7d15a2 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -53,7 +53,7 @@ goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockl goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); From 8a934b0e9c27871561679bca3e502a51f41b16ec Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:24:07 -0700 Subject: [PATCH 029/172] Migrate core/field_image.js named requires --- core/field_image.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 68a1fb43c..09c814a1b 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -13,13 +13,13 @@ goog.module('Blockly.FieldImage'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.Svg'); +const Field = goog.require('Blockly.Field'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {createSvgElement, XLINK_NS} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -35,7 +35,7 @@ goog.require('Blockly.utils.Svg'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldImage = function(src, width, height, @@ -44,9 +44,9 @@ const FieldImage = function(src, width, height, if (!src) { throw Error('Src value of an image field is required'); } - src = Blockly.utils.replaceMessageReferences(src); - const imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); - const imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); + src = replaceMessageReferences(src); + const imageHeight = Number(replaceMessageReferences(height)); + const imageWidth = Number(replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { throw Error('Height and width values of an image field must cast to' + ' numbers.'); @@ -76,17 +76,17 @@ const FieldImage = function(src, width, height, if (!opt_config) { // If the config wasn't passed, do old configuration. this.flipRtl_ = !!opt_flipRtl; - this.altText_ = Blockly.utils.replaceMessageReferences(opt_alt) || ''; + this.altText_ = replaceMessageReferences(opt_alt) || ''; } // Initialize other properties. /** * The size of the area rendered by the field. - * @type {Blockly.utils.Size} + * @type {Size} * @protected * @override */ - this.size_ = new Blockly.utils.Size(imageWidth, + this.size_ = new Size(imageWidth, imageHeight + FieldImage.Y_PADDING); /** @@ -114,7 +114,7 @@ const FieldImage = function(src, width, height, */ this.imageElement_ = null; }; -Blockly.utils.object.inherits(FieldImage, Blockly.Field); +inherits(FieldImage, Field); /** * The default value for this field. @@ -172,7 +172,7 @@ FieldImage.prototype.isDirty_ = false; FieldImage.prototype.configure_ = function(config) { FieldImage.superClass_.configure_.call(this, config); this.flipRtl_ = !!config['flipRtl']; - this.altText_ = Blockly.utils.replaceMessageReferences(config['alt']) || ''; + this.altText_ = replaceMessageReferences(config['alt']) || ''; }; /** @@ -180,15 +180,15 @@ FieldImage.prototype.configure_ = function(config) { * @package */ FieldImage.prototype.initView = function() { - this.imageElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, + this.imageElement_ = createSvgElement( + Svg.IMAGE, { 'height': this.imageHeight_ + 'px', 'width': this.size_.width + 'px', 'alt': this.altText_ }, this.fieldGroup_); - this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, + this.imageElement_.setAttributeNS(XLINK_NS, 'xlink:href', /** @type {string} */ (this.value_)); if (this.clickHandler_) { @@ -225,7 +225,7 @@ FieldImage.prototype.doClassValidation_ = function(opt_newValue) { FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { - this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, + this.imageElement_.setAttributeNS(XLINK_NS, 'xlink:href', String(this.value_)); } }; @@ -286,6 +286,6 @@ FieldImage.prototype.getText_ = function() { return this.altText_; }; -Blockly.fieldRegistry.register('field_image', FieldImage); +fieldRegistry.register('field_image', FieldImage); exports = FieldImage; From 8b815cd5b14976764b243dce5b9d625874baad5d Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:41:35 -0700 Subject: [PATCH 030/172] clang-format core/field_image.js --- core/field_image.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 09c814a1b..9edc92c56 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -33,13 +33,14 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * also be defined. * @param {boolean=} opt_flipRtl Whether to flip the icon in RTL. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor */ -const FieldImage = function(src, width, height, - opt_alt, opt_onClick, opt_flipRtl, opt_config) { +const FieldImage = function( + src, width, height, opt_alt, opt_onClick, opt_flipRtl, opt_config) { // Return early. if (!src) { throw Error('Src value of an image field is required'); @@ -48,12 +49,14 @@ const FieldImage = function(src, width, height, const imageHeight = Number(replaceMessageReferences(height)); const imageWidth = Number(replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { - throw Error('Height and width values of an image field must cast to' + - ' numbers.'); + throw Error( + 'Height and width values of an image field must cast to' + + ' numbers.'); } if (imageHeight <= 0 || imageWidth <= 0) { - throw Error('Height and width values of an image field must be greater' + - ' than 0.'); + throw Error( + 'Height and width values of an image field must be greater' + + ' than 0.'); } // Initialize configurable properties. @@ -71,8 +74,7 @@ const FieldImage = function(src, width, height, */ this.altText_ = ''; - FieldImage.superClass_.constructor.call( - this, src, null, opt_config); + FieldImage.superClass_.constructor.call(this, src, null, opt_config); if (!opt_config) { // If the config wasn't passed, do old configuration. this.flipRtl_ = !!opt_flipRtl; @@ -86,8 +88,7 @@ const FieldImage = function(src, width, height, * @protected * @override */ - this.size_ = new Size(imageWidth, - imageHeight + FieldImage.Y_PADDING); + this.size_ = new Size(imageWidth, imageHeight + FieldImage.Y_PADDING); /** * Store the image height, since it is different from the field height. @@ -135,8 +136,9 @@ FieldImage.prototype.DEFAULT_VALUE = ''; FieldImage.fromJson = function(options) { // `this` might be a subclass of FieldImage if that class doesn't override // the static fromJson method. - return new this(options['src'], options['width'], options['height'], - undefined, undefined, undefined, options); + return new this( + options['src'], options['width'], options['height'], undefined, undefined, + undefined, options); }; /** @@ -181,15 +183,14 @@ FieldImage.prototype.configure_ = function(config) { */ FieldImage.prototype.initView = function() { this.imageElement_ = createSvgElement( - Svg.IMAGE, - { + Svg.IMAGE, { 'height': this.imageHeight_ + 'px', 'width': this.size_.width + 'px', 'alt': this.altText_ }, this.fieldGroup_); - this.imageElement_.setAttributeNS(XLINK_NS, - 'xlink:href', /** @type {string} */ (this.value_)); + this.imageElement_.setAttributeNS( + XLINK_NS, 'xlink:href', /** @type {string} */ (this.value_)); if (this.clickHandler_) { this.imageElement_.style.cursor = 'pointer'; @@ -225,8 +226,8 @@ FieldImage.prototype.doClassValidation_ = function(opt_newValue) { FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { - this.imageElement_.setAttributeNS(XLINK_NS, - 'xlink:href', String(this.value_)); + this.imageElement_.setAttributeNS( + XLINK_NS, 'xlink:href', String(this.value_)); } }; From ae818c05261522af9ab105712ffb2004690a530d Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:52:54 -0700 Subject: [PATCH 031/172] Migrate core/field_multilineinput.js to ES6 const/let --- core/field_multilineinput.js | 70 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index 887d4007f..d57989b86 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -88,7 +88,7 @@ Blockly.FieldMultilineInput.prototype.configure_ = function(config) { * @nocollapse */ Blockly.FieldMultilineInput.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -141,16 +141,17 @@ Blockly.FieldMultilineInput.prototype.initView = function() { * @override */ Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { - var textLines = this.getText(); + let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. return Blockly.Field.NBSP; } - var lines = textLines.split('\n'); + const lines = textLines.split('\n'); textLines = ''; - var displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ : lines.length; - for (var i = 0; i < displayLinesNumber; i++) { - var text = lines[i]; + const displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ + : lines.length; + for (let i = 0; i < displayLinesNumber; i++) { + let text = lines[i]; if (text.length > this.maxDisplayLength) { // Truncate displayed string and add an ellipsis ('...'). text = text.substring(0, this.maxDisplayLength - 4) + '...'; @@ -192,18 +193,18 @@ Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { */ Blockly.FieldMultilineInput.prototype.render_ = function() { // Remove all text group children. - var currentChild; + let currentChild; while ((currentChild = this.textGroup_.firstChild)) { this.textGroup_.removeChild(currentChild); } // Add in text elements into the group. - var lines = this.getDisplayText_().split('\n'); - var y = 0; - for (var i = 0; i < lines.length; i++) { - var lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + + const lines = this.getDisplayText_().split('\n'); + let y = 0; + for (let i = 0; i < lines.length; i++) { + const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; - var span = Blockly.utils.dom.createSvgElement( + const span = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': 'blocklyText blocklyMultilineText', x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, @@ -252,12 +253,12 @@ Blockly.FieldMultilineInput.prototype.render_ = function() { * @protected */ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { - var nodes = this.textGroup_.childNodes; - var totalWidth = 0; - var totalHeight = 0; + const nodes = this.textGroup_.childNodes; + let totalWidth = 0; + let totalHeight = 0; for (var i = 0; i < nodes.length; i++) { - var tspan = /** @type {!Element} */ (nodes[i]); - var textWidth = Blockly.utils.dom.getTextWidth(tspan); + const tspan = /** @type {!Element} */ (nodes[i]); + const textWidth = Blockly.utils.dom.getTextWidth(tspan); if (textWidth > totalWidth) { totalWidth = textWidth; } @@ -270,26 +271,27 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { // absolute longest line, even if it would be truncated after editing. // Otherwise we would get wrong editor width when there are more // lines than this.maxLines_. - var actualEditorLines = this.value_.split('\n'); - var dummyTextElement = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT,{'class': 'blocklyText blocklyMultilineText'}); - var fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; - var fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; - var fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; + const actualEditorLines = this.value_.split('\n'); + const dummyTextElement = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); + const fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; + const fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; + const fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; for (var i = 0; i < actualEditorLines.length; i++) { if (actualEditorLines[i].length > this.maxDisplayLength) { actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; - var lineWidth = Blockly.utils.dom.getFastTextWidth( + const lineWidth = Blockly.utils.dom.getFastTextWidth( dummyTextElement, fontSize, fontWeight, fontFamily); if (lineWidth > totalWidth) { totalWidth = lineWidth; } } - var scrollbarWidth = this.htmlInput_.offsetWidth - this.htmlInput_.clientWidth; + const scrollbarWidth = this.htmlInput_.offsetWidth + - this.htmlInput_.clientWidth; totalWidth += scrollbarWidth; } if (this.borderRect_) { @@ -325,23 +327,23 @@ Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietIn * @protected */ Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { - var div = Blockly.WidgetDiv.DIV; - var scale = this.workspace_.getScale(); + const div = Blockly.WidgetDiv.DIV; + const scale = this.workspace_.getScale(); - var htmlInput = - /** @type {HTMLTextAreaElement} */ (document.createElement('textarea')); + const htmlInput = + /** @type {HTMLTextAreaElement} */ (document.createElement('textarea')); htmlInput.className = 'blocklyHtmlInput blocklyHtmlTextAreaInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); - var fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - var borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + const borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; htmlInput.style.borderRadius = borderRadius; - var paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; - var paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; + const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; + const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; htmlInput.style.padding = paddingY + 'px ' + paddingX + 'px ' + paddingY + 'px ' + paddingX + 'px'; - var lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + + const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; htmlInput.style.lineHeight = (lineHeight * scale) + 'px'; From 8af597761d267fde72c23794badeb35bb6c57a17 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:53:18 -0700 Subject: [PATCH 032/172] Migrate core/field_multilineinput.js to goog.module --- core/field_multilineinput.js | 51 +++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index d57989b86..ea6ed7531 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldMultilineInput'); +goog.module('Blockly.FieldMultilineInput'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Css'); goog.require('Blockly.Field'); @@ -42,8 +43,8 @@ goog.require('Blockly.WidgetDiv'); * @extends {Blockly.FieldTextInput} * @constructor */ -Blockly.FieldMultilineInput = function(opt_value, opt_validator, opt_config) { - Blockly.FieldMultilineInput.superClass_.constructor.call(this, +const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { + FieldMultilineInput.superClass_.constructor.call(this, opt_value, opt_validator, opt_config); /** @@ -68,14 +69,14 @@ Blockly.FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -Blockly.utils.object.inherits(Blockly.FieldMultilineInput, +Blockly.utils.object.inherits(FieldMultilineInput, Blockly.FieldTextInput); /** * @override */ -Blockly.FieldMultilineInput.prototype.configure_ = function(config) { - Blockly.FieldMultilineInput.superClass_.configure_.call(this, config); +FieldMultilineInput.prototype.configure_ = function(config) { + FieldMultilineInput.superClass_.configure_.call(this, config); config.maxLines && this.setMaxLines(config.maxLines); }; @@ -83,11 +84,11 @@ Blockly.FieldMultilineInput.prototype.configure_ = function(config) { * Construct a FieldMultilineInput from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and spellcheck). - * @return {!Blockly.FieldMultilineInput} The new field instance. + * @return {!FieldMultilineInput} The new field instance. * @package * @nocollapse */ -Blockly.FieldMultilineInput.fromJson = function(options) { +FieldMultilineInput.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. @@ -101,7 +102,7 @@ Blockly.FieldMultilineInput.fromJson = function(options) { * @return {!Element} The element containing info about the field's state. * @package */ -Blockly.FieldMultilineInput.prototype.toXml = function(fieldElement) { +FieldMultilineInput.prototype.toXml = function(fieldElement) { // Replace '\n' characters with HTML-escaped equivalent ' '. This is // needed so the plain-text representation of the XML produced by // `Blockly.Xml.domToText` will appear on a single line (this is a limitation @@ -117,7 +118,7 @@ Blockly.FieldMultilineInput.prototype.toXml = function(fieldElement) { * field's state. * @package */ -Blockly.FieldMultilineInput.prototype.fromXml = function(fieldElement) { +FieldMultilineInput.prototype.fromXml = function(fieldElement) { this.setValue(fieldElement.textContent.replace(/ /g, '\n')); }; @@ -125,7 +126,7 @@ Blockly.FieldMultilineInput.prototype.fromXml = function(fieldElement) { * Create the block UI for this field. * @package */ -Blockly.FieldMultilineInput.prototype.initView = function() { +FieldMultilineInput.prototype.initView = function() { this.createBorderRect_(); this.textGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, { @@ -140,7 +141,7 @@ Blockly.FieldMultilineInput.prototype.initView = function() { * @protected * @override */ -Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { +FieldMultilineInput.prototype.getDisplayText_ = function() { let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. @@ -182,8 +183,8 @@ Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { * that this is a string. * @protected */ -Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { - Blockly.FieldMultilineInput.superClass_.doValueUpdate_.call(this, newValue); +FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { + FieldMultilineInput.superClass_.doValueUpdate_.call(this, newValue); this.isOverflowedY_ = this.value_.split('\n').length > this.maxLines_; }; @@ -191,7 +192,7 @@ Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { * Updates the text of the textElement. * @protected */ -Blockly.FieldMultilineInput.prototype.render_ = function() { +FieldMultilineInput.prototype.render_ = function() { // Remove all text group children. let currentChild; while ((currentChild = this.textGroup_.firstChild)) { @@ -252,7 +253,7 @@ Blockly.FieldMultilineInput.prototype.render_ = function() { * Updates the size of the field based on the text. * @protected */ -Blockly.FieldMultilineInput.prototype.updateSize_ = function() { +FieldMultilineInput.prototype.updateSize_ = function() { const nodes = this.textGroup_.childNodes; let totalWidth = 0; let totalHeight = 0; @@ -316,8 +317,8 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { * focus. Defaults to false. * @override */ -Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { - Blockly.FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); +FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { + FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); this.forceRerender(); }; @@ -326,7 +327,7 @@ Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietIn * @return {!HTMLTextAreaElement} The newly created text input editor. * @protected */ -Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { +FieldMultilineInput.prototype.widgetCreate_ = function() { const div = Blockly.WidgetDiv.DIV; const scale = this.workspace_.getScale(); @@ -369,7 +370,7 @@ Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { * @param {number} maxLines Defines the maximum number of lines allowed, * before scrolling functionality is enabled. */ -Blockly.FieldMultilineInput.prototype.setMaxLines = function(maxLines) { +FieldMultilineInput.prototype.setMaxLines = function(maxLines) { if (typeof maxLines === 'number' && maxLines > 0 && maxLines !== this.maxLines_) { this.maxLines_ = maxLines; this.forceRerender(); @@ -380,7 +381,7 @@ Blockly.FieldMultilineInput.prototype.setMaxLines = function(maxLines) { * Returns the maxLines config of this field. * @return {number} The maxLines config value. */ -Blockly.FieldMultilineInput.prototype.getMaxLines = function() { +FieldMultilineInput.prototype.getMaxLines = function() { return this.maxLines_; }; @@ -390,9 +391,9 @@ Blockly.FieldMultilineInput.prototype.getMaxLines = function() { * @param {!Event} e Keyboard event. * @protected */ -Blockly.FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { +FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { if (e.keyCode !== Blockly.utils.KeyCodes.ENTER) { - Blockly.FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); + FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); } }; @@ -415,4 +416,6 @@ Blockly.Css.register([ ]); -Blockly.fieldRegistry.register('field_multilinetext', Blockly.FieldMultilineInput); +Blockly.fieldRegistry.register('field_multilinetext', FieldMultilineInput); + +exports = FieldMultilineInput; diff --git a/tests/deps.js b/tests/deps.js index 77f7d15a2..f62333982 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -56,7 +56,7 @@ goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], [' goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); From d91f36eab9f4e9a3251d95967ffea3947166daf5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:51:10 -0700 Subject: [PATCH 033/172] Migrate core/field_multilineinput.js named requires --- core/field_multilineinput.js | 80 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index ea6ed7531..f3872919a 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -15,18 +15,18 @@ goog.module('Blockly.FieldMultilineInput'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Css'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); +const Css = goog.require('Blockly.Css'); +const Field = goog.require('Blockly.Field'); +const FieldTextInput = goog.require('Blockly.FieldTextInput'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Svg = goog.require('Blockly.utils.Svg'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const aria = goog.require('Blockly.utils.aria'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -40,7 +40,7 @@ goog.require('Blockly.WidgetDiv'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldTextInput} + * @extends {FieldTextInput} * @constructor */ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { @@ -69,8 +69,8 @@ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -Blockly.utils.object.inherits(FieldMultilineInput, - Blockly.FieldTextInput); +inherits(FieldMultilineInput, + FieldTextInput); /** * @override @@ -89,7 +89,7 @@ FieldMultilineInput.prototype.configure_ = function(config) { * @nocollapse */ FieldMultilineInput.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -128,8 +128,8 @@ FieldMultilineInput.prototype.fromXml = function(fieldElement) { */ FieldMultilineInput.prototype.initView = function() { this.createBorderRect_(); - this.textGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, { + this.textGroup_ = dom.createSvgElement( + Svg.G, { 'class': 'blocklyEditableText', }, this.fieldGroup_); }; @@ -145,7 +145,7 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. - return Blockly.Field.NBSP; + return Field.NBSP; } const lines = textLines.split('\n'); textLines = ''; @@ -160,7 +160,7 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { text = text.substring(0, text.length - 3) + '...'; } // Replace whitespace with non-breaking spaces so the text doesn't collapse. - text = text.replace(/\s/g, Blockly.Field.NBSP); + text = text.replace(/\s/g, Field.NBSP); textLines += text; if (i !== displayLinesNumber - 1) { @@ -205,8 +205,8 @@ FieldMultilineInput.prototype.render_ = function() { for (let i = 0; i < lines.length; i++) { const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; - const span = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, { + const span = dom.createSvgElement( + Svg.TEXT, { 'class': 'blocklyText blocklyMultilineText', x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, y: y + this.getConstants().FIELD_BORDER_RECT_Y_PADDING, @@ -219,9 +219,9 @@ FieldMultilineInput.prototype.render_ = function() { if (this.isBeingEdited_) { var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (this.isOverflowedY_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); + dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); + dom.removeClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } } @@ -238,13 +238,13 @@ FieldMultilineInput.prototype.render_ = function() { } var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, true); + dom.addClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, true); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, false); + dom.removeClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, false); } } }; @@ -259,7 +259,7 @@ FieldMultilineInput.prototype.updateSize_ = function() { let totalHeight = 0; for (var i = 0; i < nodes.length; i++) { const tspan = /** @type {!Element} */ (nodes[i]); - const textWidth = Blockly.utils.dom.getTextWidth(tspan); + const textWidth = dom.getTextWidth(tspan); if (textWidth > totalWidth) { totalWidth = textWidth; } @@ -273,8 +273,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { // Otherwise we would get wrong editor width when there are more // lines than this.maxLines_. const actualEditorLines = this.value_.split('\n'); - const dummyTextElement = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); + const dummyTextElement = dom.createSvgElement( + Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); const fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; const fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; const fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; @@ -284,7 +284,7 @@ FieldMultilineInput.prototype.updateSize_ = function() { actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; - const lineWidth = Blockly.utils.dom.getFastTextWidth( + const lineWidth = dom.getFastTextWidth( dummyTextElement, fontSize, fontWeight, fontFamily); if (lineWidth > totalWidth) { totalWidth = lineWidth; @@ -328,7 +328,7 @@ FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { * @protected */ FieldMultilineInput.prototype.widgetCreate_ = function() { - const div = Blockly.WidgetDiv.DIV; + const div = WidgetDiv.DIV; const scale = this.workspace_.getScale(); const htmlInput = @@ -338,7 +338,7 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - const borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + const borderRadius = (FieldTextInput.BORDERRADIUS * scale) + 'px'; htmlInput.style.borderRadius = borderRadius; const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; @@ -353,7 +353,7 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { htmlInput.value = htmlInput.defaultValue = this.getEditorText_(this.value_); htmlInput.untypedDefaultValue_ = this.value_; htmlInput.oldValue_ = null; - if (Blockly.utils.userAgent.GECKO) { + if (userAgent.GECKO) { // In FF, ensure the browser reflows before resizing to avoid issue #2777. setTimeout(this.resizeEditor_.bind(this), 0); } else { @@ -392,7 +392,7 @@ FieldMultilineInput.prototype.getMaxLines = function() { * @protected */ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { - if (e.keyCode !== Blockly.utils.KeyCodes.ENTER) { + if (e.keyCode !== KeyCodes.ENTER) { FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); } }; @@ -400,7 +400,7 @@ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { /** * CSS for multiline field. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyHtmlTextAreaInput {', 'font-family: monospace;', @@ -416,6 +416,6 @@ Blockly.Css.register([ ]); -Blockly.fieldRegistry.register('field_multilinetext', FieldMultilineInput); +fieldRegistry.register('field_multilinetext', FieldMultilineInput); exports = FieldMultilineInput; From aeac27661dacc3b01d9d6fb79ccf28b9b92681f5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 11:01:39 -0700 Subject: [PATCH 034/172] clang-format core/field_multilineinput.js --- core/field_multilineinput.js | 69 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index f3872919a..4842429a5 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -38,14 +38,15 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * text as an argument and returns either the accepted text, a replacement * text, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} * for a list of properties this parameter supports. * @extends {FieldTextInput} * @constructor */ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { - FieldMultilineInput.superClass_.constructor.call(this, - opt_value, opt_validator, opt_config); + FieldMultilineInput.superClass_.constructor.call( + this, opt_value, opt_validator, opt_config); /** * The SVG group element that will contain a text element for each text row @@ -69,8 +70,7 @@ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -inherits(FieldMultilineInput, - FieldTextInput); +inherits(FieldMultilineInput, FieldTextInput); /** * @override @@ -131,7 +131,8 @@ FieldMultilineInput.prototype.initView = function() { this.textGroup_ = dom.createSvgElement( Svg.G, { 'class': 'blocklyEditableText', - }, this.fieldGroup_); + }, + this.fieldGroup_); }; /** @@ -149,8 +150,8 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { } const lines = textLines.split('\n'); textLines = ''; - const displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ - : lines.length; + const displayLinesNumber = + this.isOverflowedY_ ? this.maxLines_ : lines.length; for (let i = 0; i < displayLinesNumber; i++) { let text = lines[i]; if (text.length > this.maxDisplayLength) { @@ -211,13 +212,14 @@ FieldMultilineInput.prototype.render_ = function() { x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, y: y + this.getConstants().FIELD_BORDER_RECT_Y_PADDING, dy: this.getConstants().FIELD_TEXT_BASELINE - }, this.textGroup_); + }, + this.textGroup_); span.appendChild(document.createTextNode(lines[i])); y += lineHeight; } if (this.isBeingEdited_) { - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + var htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (this.isOverflowedY_) { dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } else { @@ -236,15 +238,13 @@ FieldMultilineInput.prototype.render_ = function() { } else { this.resizeEditor_(); } - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + var htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (!this.isTextValid_) { dom.addClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, true); + aria.setState(htmlInput, aria.State.INVALID, true); } else { dom.removeClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, false); + aria.setState(htmlInput, aria.State.INVALID, false); } } }; @@ -281,7 +281,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { for (var i = 0; i < actualEditorLines.length; i++) { if (actualEditorLines[i].length > this.maxDisplayLength) { - actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); + actualEditorLines[i] = + actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; const lineWidth = dom.getFastTextWidth( @@ -291,8 +292,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { } } - const scrollbarWidth = this.htmlInput_.offsetWidth - - this.htmlInput_.clientWidth; + const scrollbarWidth = + this.htmlInput_.offsetWidth - this.htmlInput_.clientWidth; totalWidth += scrollbarWidth; } if (this.borderRect_) { @@ -318,7 +319,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { * @override */ FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { - FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); + FieldMultilineInput.superClass_.showEditor_.call( + this, _opt_e, opt_quietInput); this.forceRerender(); }; @@ -342,8 +344,8 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { htmlInput.style.borderRadius = borderRadius; const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; - htmlInput.style.padding = paddingY + 'px ' + paddingX + 'px ' + paddingY + - 'px ' + paddingX + 'px'; + htmlInput.style.padding = + paddingY + 'px ' + paddingX + 'px ' + paddingY + 'px ' + paddingX + 'px'; const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; htmlInput.style.lineHeight = (lineHeight * scale) + 'px'; @@ -371,7 +373,8 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { * before scrolling functionality is enabled. */ FieldMultilineInput.prototype.setMaxLines = function(maxLines) { - if (typeof maxLines === 'number' && maxLines > 0 && maxLines !== this.maxLines_) { + if (typeof maxLines === 'number' && maxLines > 0 && + maxLines !== this.maxLines_) { this.maxLines_ = maxLines; this.forceRerender(); } @@ -401,18 +404,16 @@ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { * CSS for multiline field. See css.js for use. */ Css.register([ - /* eslint-disable indent */ - '.blocklyHtmlTextAreaInput {', - 'font-family: monospace;', - 'resize: none;', - 'overflow: hidden;', - 'height: 100%;', - 'text-align: left;', - '}', - '.blocklyHtmlTextAreaInputOverflowedY {', - 'overflow-y: scroll;', - '}' - /* eslint-enable indent */ + `.blocklyHtmlTextAreaInput { + font-family: monospace; + resize: none; + overflow: hidden; + height: 100%; + text-align: left; +}`, + `.blocklyHtmlTextAreaInputOverflowedY { + overflow-y: scroll; +}` ]); From b1f868fbafd01b8284f1e6155e71442303424b9b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:02:15 -0700 Subject: [PATCH 035/172] Migrate core/flyout_horizontal.js to ES6 const/let --- core/flyout_horizontal.js | 103 +++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 66e9ff18e..3ec62518a 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -53,10 +53,10 @@ Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { return; } - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); if (typeof xyRatio.x == 'number') { this.workspace_.scrollX = @@ -85,13 +85,13 @@ Blockly.HorizontalFlyout.prototype.getY = function() { if (!this.isVisible()) { return 0; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var toolboxMetrics = metricsManager.getToolboxMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const toolboxMetrics = metricsManager.getToolboxMetrics(); - var y = 0; - var atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + let y = 0; + const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. @@ -133,18 +133,18 @@ Blockly.HorizontalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); // Record the width for workspace metrics. this.width_ = targetWorkspaceViewMetrics.width; - var edgeWidth = targetWorkspaceViewMetrics.width - 2 * this.CORNER_RADIUS; - var edgeHeight = this.height_ - this.CORNER_RADIUS; + const edgeWidth = targetWorkspaceViewMetrics.width - 2 * this.CORNER_RADIUS; + const edgeHeight = this.height_ - this.CORNER_RADIUS; this.setBackgroundPath_(edgeWidth, edgeHeight); - var x = this.getX(); - var y = this.getY(); + const x = this.getX(); + const y = this.getY(); this.positionAt_(this.width_, this.height_, x, y); }; @@ -159,9 +159,9 @@ Blockly.HorizontalFlyout.prototype.position = function() { */ Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { - var atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // Start at top left. - var path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; + const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; if (atTop) { // Top. @@ -206,15 +206,15 @@ Blockly.HorizontalFlyout.prototype.scrollToStart = function() { * @protected */ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { - var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); - var delta = scrollDelta.x || scrollDelta.y; + const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const delta = scrollDelta.x || scrollDelta.y; if (delta) { - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); - var pos = (viewMetrics.left - scrollMetrics.left) + delta; + const pos = (viewMetrics.left - scrollMetrics.left) + delta; this.workspace_.scrollbar.setX(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. Blockly.WidgetDiv.hide(); @@ -235,37 +235,38 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { */ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; - var margin = this.MARGIN; - var cursorX = margin + this.tabWidth_; - var cursorY = margin; + const margin = this.MARGIN; + let cursorX = margin + this.tabWidth_; + const cursorY = margin; if (this.RTL) { contents = contents.reverse(); } - for (var i = 0, item; (item = contents[i]); i++) { + for (let i = 0, item; (item = contents[i]); i++) { if (item.type == 'block') { - var block = item.block; - var allBlocks = block.getDescendants(false); - for (var j = 0, child; (child = allBlocks[j]); j++) { + const block = item.block; + const allBlocks = block.getDescendants(false); + for (let j = 0, child; (child = allBlocks[j]); j++) { // Mark blocks as being inside a flyout. This is used to detect and // prevent the closure of the flyout if the user right-clicks on such a // block. child.isInFlyout = true; } block.render(); - var root = block.getSvgRoot(); - var blockHW = block.getHeightWidth(); + const root = block.getSvgRoot(); + const blockHW = block.getHeightWidth(); // Figure out where to place the block. - var tab = block.outputConnection ? this.tabWidth_ : 0; + const tab = block.outputConnection ? this.tabWidth_ : 0; + let moveX; if (this.RTL) { - var moveX = cursorX + blockHW.width; + moveX = cursorX + blockHW.width; } else { - var moveX = cursorX - tab; + moveX = cursorX - tab; } block.moveBy(moveX, cursorY); - var rect = this.createRect_(block, moveX, cursorY, blockHW, i); + const rect = this.createRect_(block, moveX, cursorY, blockHW, i); cursorX += (blockHW.width + gaps[i]); this.addBlockListeners_(root, block, rect); @@ -287,12 +288,12 @@ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { */ Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { - var dx = currentDragDeltaXY.x; - var dy = currentDragDeltaXY.y; + const dx = currentDragDeltaXY.x; + const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. - var dragDirection = Math.atan2(dy, dx) / Math.PI * 180; + const dragDirection = Math.atan2(dy, dx) / Math.PI * 180; - var range = this.dragAngleRange_; + const range = this.dragAngleRange_; // Check for up or down dragging. if ((dragDirection < 90 + range && dragDirection > 90 - range) || (dragDirection > -90 - range && dragDirection < -90 + range)) { @@ -314,15 +315,15 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { return null; } - var flyoutRect = this.svgGroup_.getBoundingClientRect(); + const flyoutRect = this.svgGroup_.getBoundingClientRect(); // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout // area are still deleted. Must be larger than the largest screen size, // but be smaller than half Number.MAX_SAFE_INTEGER (not available on IE). - var BIG_NUM = 1000000000; - var top = flyoutRect.top; + const BIG_NUM = 1000000000; + const top = flyoutRect.top; if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP) { - var height = flyoutRect.height; + const height = flyoutRect.height; return new Blockly.utils.Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); } else { // Bottom. return new Blockly.utils.Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); @@ -336,13 +337,13 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { */ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); - var flyoutHeight = 0; - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { + let flyoutHeight = 0; + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { flyoutHeight = Math.max(flyoutHeight, block.getHeightWidth().height); } - var buttons = this.buttons_; - for (var i = 0, button; (button = buttons[i]); i++) { + const buttons = this.buttons_; + for (let i = 0, button; (button = buttons[i]); i++) { flyoutHeight = Math.max(flyoutHeight, button.height); } flyoutHeight += this.MARGIN * 1.5; @@ -350,7 +351,7 @@ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { flyoutHeight += Blockly.Scrollbar.scrollbarThickness; if (this.height_ != flyoutHeight) { - for (var i = 0, block; (block = blocks[i]); i++) { + for (let i = 0, block; (block = blocks[i]); i++) { if (block.flyoutRect_) { this.moveRectToBlock_(block.flyoutRect_, block); } From 8b0d1df173b43ae48d4d9d84e89d46ded89d2659 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:04:52 -0700 Subject: [PATCH 036/172] Migrate core/flyout_horizontal.js to goog.module --- core/flyout_horizontal.js | 35 +++++++++++++++++++---------------- tests/deps.js | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 3ec62518a..96cad2c9f 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.HorizontalFlyout'); +goog.module('Blockly.HorizontalFlyout'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); @@ -35,11 +36,11 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.Flyout} * @constructor */ -Blockly.HorizontalFlyout = function(workspaceOptions) { - Blockly.HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); +const HorizontalFlyout = function(workspaceOptions) { + HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); this.horizontalLayout = true; }; -Blockly.utils.object.inherits(Blockly.HorizontalFlyout, Blockly.Flyout); +Blockly.utils.object.inherits(HorizontalFlyout, Blockly.Flyout); /** * Sets the translation of the flyout to match the scrollbars. @@ -48,7 +49,7 @@ Blockly.utils.object.inherits(Blockly.HorizontalFlyout, Blockly.Flyout); * similar x property. * @protected */ -Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { +HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } @@ -72,7 +73,7 @@ Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.HorizontalFlyout.prototype.getX = function() { +HorizontalFlyout.prototype.getX = function() { // X is always 0 since this is a horizontal flyout. return 0; }; @@ -81,7 +82,7 @@ Blockly.HorizontalFlyout.prototype.getX = function() { * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.HorizontalFlyout.prototype.getY = function() { +HorizontalFlyout.prototype.getY = function() { if (!this.isVisible()) { return 0; } @@ -129,7 +130,7 @@ Blockly.HorizontalFlyout.prototype.getY = function() { /** * Move the flyout to the edge of the workspace. */ -Blockly.HorizontalFlyout.prototype.position = function() { +HorizontalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } @@ -157,7 +158,7 @@ Blockly.HorizontalFlyout.prototype.position = function() { * rounded corners. * @private */ -Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( +HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // Start at top left. @@ -196,7 +197,7 @@ Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( /** * Scroll the flyout to the top. */ -Blockly.HorizontalFlyout.prototype.scrollToStart = function() { +HorizontalFlyout.prototype.scrollToStart = function() { this.workspace_.scrollbar.setX(this.RTL ? Infinity : 0); }; @@ -205,7 +206,7 @@ Blockly.HorizontalFlyout.prototype.scrollToStart = function() { * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { +HorizontalFlyout.prototype.wheel_ = function(e) { const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); const delta = scrollDelta.x || scrollDelta.y; @@ -233,7 +234,7 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { +HorizontalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; const margin = this.MARGIN; let cursorX = margin + this.tabWidth_; @@ -286,7 +287,7 @@ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( +HorizontalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; @@ -308,7 +309,7 @@ Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.HorizontalFlyout.prototype.getClientRect = function() { +HorizontalFlyout.prototype.getClientRect = function() { if (!this.svgGroup_ || this.autoClose || !this.isVisible()) { // The bounding rectangle won't compute correctly if the flyout is closed // and auto-close flyouts aren't valid drag targets (or delete areas). @@ -335,7 +336,7 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { * For RTL: Lay out the blocks right-aligned. * @protected */ -Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { +HorizontalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); let flyoutHeight = 0; const blocks = this.workspace_.getTopBlocks(false); @@ -375,4 +376,6 @@ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { }; Blockly.registry.register(Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - Blockly.registry.DEFAULT, Blockly.HorizontalFlyout); + Blockly.registry.DEFAULT, HorizontalFlyout); + +exports = HorizontalFlyout; diff --git a/tests/deps.js b/tests/deps.js index f62333982..87600526f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -63,7 +63,7 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); From 7ee9b0a41cc286cab6ff75e163c02d92ccc0c010 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:11:53 -0700 Subject: [PATCH 037/172] Migrate core/flyout_horizontal.js to named requires --- core/flyout_horizontal.js | 59 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 96cad2c9f..8f530516d 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -13,34 +13,35 @@ goog.module('Blockly.HorizontalFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Flyout = goog.require('Blockly.Flyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const Rect = goog.require('Blockly.utils.Rect'); +const Scrollbar = goog.require('Blockly.Scrollbar'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const registry = goog.require('Blockly.registry'); +const {Position} = goog.require('Blockly.utils.toolbox'); +const {getScrollDeltaPixels} = goog.require('Blockly.utils'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Flyout'); -goog.require('Blockly.registry'); -goog.require('Blockly.Scrollbar'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Coordinate'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. - * @extends {Blockly.Flyout} + * @extends {Flyout} * @constructor */ const HorizontalFlyout = function(workspaceOptions) { HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); this.horizontalLayout = true; }; -Blockly.utils.object.inherits(HorizontalFlyout, Blockly.Flyout); +inherits(HorizontalFlyout, Flyout); /** * Sets the translation of the flyout to match the scrollbars. @@ -92,7 +93,7 @@ HorizontalFlyout.prototype.getY = function() { const toolboxMetrics = metricsManager.getToolboxMetrics(); let y = 0; - const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Position.TOP; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. @@ -160,7 +161,7 @@ HorizontalFlyout.prototype.position = function() { */ HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { - const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Position.TOP; // Start at top left. const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; @@ -207,7 +208,7 @@ HorizontalFlyout.prototype.scrollToStart = function() { * @protected */ HorizontalFlyout.prototype.wheel_ = function(e) { - const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = getScrollDeltaPixels(e); const delta = scrollDelta.x || scrollDelta.y; if (delta) { @@ -218,8 +219,8 @@ HorizontalFlyout.prototype.wheel_ = function(e) { const pos = (viewMetrics.left - scrollMetrics.left) + delta; this.workspace_.scrollbar.setX(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); } // Don't scroll the page. @@ -282,7 +283,7 @@ HorizontalFlyout.prototype.layout_ = function(contents, gaps) { * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package @@ -306,7 +307,7 @@ HorizontalFlyout.prototype.isDragTowardWorkspace = function( /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag + * @return {?Rect} The component's bounding box. Null if drag * target area should be ignored. */ HorizontalFlyout.prototype.getClientRect = function() { @@ -323,11 +324,11 @@ HorizontalFlyout.prototype.getClientRect = function() { const BIG_NUM = 1000000000; const top = flyoutRect.top; - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP) { + if (this.toolboxPosition_ == Position.TOP) { const height = flyoutRect.height; - return new Blockly.utils.Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); + return new Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); } else { // Bottom. - return new Blockly.utils.Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); + return new Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); } }; @@ -349,7 +350,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } flyoutHeight += this.MARGIN * 1.5; flyoutHeight *= this.workspace_.scale; - flyoutHeight += Blockly.Scrollbar.scrollbarThickness; + flyoutHeight += Scrollbar.scrollbarThickness; if (this.height_ != flyoutHeight) { for (let i = 0, block; (block = blocks[i]); i++) { @@ -359,7 +360,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_ && - this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP && + this.toolboxPosition_ == Position.TOP && !this.targetWorkspace.getToolbox()) { // This flyout is a simple toolbox. Reposition the workspace so that (0,0) // is in the correct position relative to the new absolute edge (ie @@ -375,7 +376,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } }; -Blockly.registry.register(Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - Blockly.registry.DEFAULT, HorizontalFlyout); +registry.register(registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, + registry.DEFAULT, HorizontalFlyout); exports = HorizontalFlyout; From 08c18b479cc9f6d5cc9566d00dfb5a534e6ad35b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:13:11 -0700 Subject: [PATCH 038/172] clang-format core/flyout_horizontal.js --- core/flyout_horizontal.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 8f530516d..9bfc8aa91 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -63,10 +63,11 @@ HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { if (typeof xyRatio.x == 'number') { this.workspace_.scrollX = -(scrollMetrics.left + - (scrollMetrics.width - viewMetrics.width) * xyRatio.x); + (scrollMetrics.width - viewMetrics.width) * xyRatio.x); } - this.workspace_.translate(this.workspace_.scrollX + absoluteMetrics.left, + this.workspace_.translate( + this.workspace_.scrollX + absoluteMetrics.left, this.workspace_.scrollY + absoluteMetrics.top); }; @@ -159,8 +160,7 @@ HorizontalFlyout.prototype.position = function() { * rounded corners. * @private */ -HorizontalFlyout.prototype.setBackgroundPath_ = function( - width, height) { +HorizontalFlyout.prototype.setBackgroundPath_ = function(width, height) { const atTop = this.toolboxPosition_ == Position.TOP; // Start at top left. const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; @@ -171,20 +171,24 @@ HorizontalFlyout.prototype.setBackgroundPath_ = function( // Right. path.push('v', height); // Bottom. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, -this.CORNER_RADIUS, this.CORNER_RADIUS); path.push('h', -width); // Left. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, -this.CORNER_RADIUS, -this.CORNER_RADIUS); path.push('z'); } else { // Top. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, this.CORNER_RADIUS, -this.CORNER_RADIUS); path.push('h', width); // Right. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, this.CORNER_RADIUS, this.CORNER_RADIUS); path.push('v', height); // Bottom. @@ -366,7 +370,8 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { // is in the correct position relative to the new absolute edge (ie // toolbox edge). this.targetWorkspace.translate( - this.targetWorkspace.scrollX, this.targetWorkspace.scrollY + flyoutHeight); + this.targetWorkspace.scrollX, + this.targetWorkspace.scrollY + flyoutHeight); } // Record the height for workspace metrics and .position. @@ -376,7 +381,8 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } }; -registry.register(registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - registry.DEFAULT, HorizontalFlyout); +registry.register( + registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, registry.DEFAULT, + HorizontalFlyout); exports = HorizontalFlyout; From adc78d192c6b5852f0cfc5363777a5ac2a882465 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:24:09 -0700 Subject: [PATCH 039/172] Migrate core/flyout_vertical.js to ES6 const/let --- core/flyout_vertical.js | 106 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index a09b3fb8e..786deff96 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -59,10 +59,10 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); if (typeof xyRatio.y == 'number') { this.workspace_.scrollY = @@ -81,11 +81,11 @@ Blockly.VerticalFlyout.prototype.getX = function() { if (!this.isVisible()) { return 0; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var toolboxMetrics = metricsManager.getToolboxMetrics(); - var x = 0; + const metricsManager = this.targetWorkspace.getMetricsManager(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const toolboxMetrics = metricsManager.getToolboxMetrics(); + let x = 0; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { @@ -137,18 +137,18 @@ Blockly.VerticalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); // Record the height for workspace metrics. this.height_ = targetWorkspaceViewMetrics.height; - var edgeWidth = this.width_ - this.CORNER_RADIUS; - var edgeHeight = targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; + const edgeWidth = this.width_ - this.CORNER_RADIUS; + const edgeHeight = targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; this.setBackgroundPath_(edgeWidth, edgeHeight); - var x = this.getX(); - var y = this.getY(); + const x = this.getX(); + const y = this.getY(); this.positionAt_(this.width_, this.height_, x, y); }; @@ -162,11 +162,11 @@ Blockly.VerticalFlyout.prototype.position = function() { * @private */ Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { - var atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; - var totalWidth = width + this.CORNER_RADIUS; + const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; + const totalWidth = width + this.CORNER_RADIUS; // Decide whether to start on the left or right. - var path = ['M ' + (atRight ? totalWidth : 0) + ',0']; + const path = ['M ' + (atRight ? totalWidth : 0) + ',0']; // Top. path.push('h', atRight ? -width : width); // Rounded corner. @@ -200,13 +200,13 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() { * @protected */ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { - var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); if (scrollDelta.y) { - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var pos = (viewMetrics.top - scrollMetrics.top) + scrollDelta.y; + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const pos = (viewMetrics.top - scrollMetrics.top) + scrollDelta.y; this.workspace_.scrollbar.setY(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. @@ -228,27 +228,27 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { */ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; - var margin = this.MARGIN; - var cursorX = this.RTL ? margin : margin + this.tabWidth_; - var cursorY = margin; + const margin = this.MARGIN; + const cursorX = this.RTL ? margin : margin + this.tabWidth_; + let cursorY = margin; - for (var i = 0, item; (item = contents[i]); i++) { + for (let i = 0, item; (item = contents[i]); i++) { if (item.type == 'block') { - var block = item.block; - var allBlocks = block.getDescendants(false); - for (var j = 0, child; (child = allBlocks[j]); j++) { + const block = item.block; + const allBlocks = block.getDescendants(false); + for (let j = 0, child; (child = allBlocks[j]); j++) { // Mark blocks as being inside a flyout. This is used to detect and // prevent the closure of the flyout if the user right-clicks on such a // block. child.isInFlyout = true; } block.render(); - var root = block.getSvgRoot(); - var blockHW = block.getHeightWidth(); - var moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; + const root = block.getSvgRoot(); + const blockHW = block.getHeightWidth(); + const moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; block.moveBy(moveX, cursorY); - var rect = this.createRect_(block, + const rect = this.createRect_(block, this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); this.addBlockListeners_(root, block, rect); @@ -272,12 +272,12 @@ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { */ Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { - var dx = currentDragDeltaXY.x; - var dy = currentDragDeltaXY.y; + const dx = currentDragDeltaXY.x; + const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. - var dragDirection = Math.atan2(dy, dx) / Math.PI * 180; + const dragDirection = Math.atan2(dy, dx) / Math.PI * 180; - var range = this.dragAngleRange_; + const range = this.dragAngleRange_; // Check for left or right dragging. if ((dragDirection < range && dragDirection > -range) || (dragDirection < -180 + range || dragDirection > 180 - range)) { @@ -299,15 +299,15 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { return null; } - var flyoutRect = this.svgGroup_.getBoundingClientRect(); + const flyoutRect = this.svgGroup_.getBoundingClientRect(); // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout // area are still deleted. Must be larger than the largest screen size, // but be smaller than half Number.MAX_SAFE_INTEGER (not available on IE). - var BIG_NUM = 1000000000; - var left = flyoutRect.left; + const BIG_NUM = 1000000000; + const left = flyoutRect.left; if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { - var width = flyoutRect.width; + const width = flyoutRect.width; return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); } else { // Right return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); @@ -321,16 +321,16 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { */ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); - var flyoutWidth = 0; - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { - var width = block.getHeightWidth().width; + let flyoutWidth = 0; + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { + let width = block.getHeightWidth().width; if (block.outputConnection) { width -= this.tabWidth_; } flyoutWidth = Math.max(flyoutWidth, width); } - for (var i = 0, button; (button = this.buttons_[i]); i++) { + for (let i = 0, button; (button = this.buttons_[i]); i++) { flyoutWidth = Math.max(flyoutWidth, button.width); } flyoutWidth += this.MARGIN * 1.5 + this.tabWidth_; @@ -338,11 +338,11 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { flyoutWidth += Blockly.Scrollbar.scrollbarThickness; if (this.width_ != flyoutWidth) { - for (var i = 0, block; (block = blocks[i]); i++) { + for (let i = 0, block; (block = blocks[i]); i++) { if (this.RTL) { // With the flyoutWidth known, right-align the blocks. - var oldX = block.getRelativeToSurfaceXY().x; - var newX = flyoutWidth / this.workspace_.scale - this.MARGIN; + const oldX = block.getRelativeToSurfaceXY().x; + let newX = flyoutWidth / this.workspace_.scale - this.MARGIN; if (!block.outputConnection) { newX -= this.tabWidth_; } @@ -354,9 +354,9 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { } if (this.RTL) { // With the flyoutWidth known, right-align the buttons. - for (var i = 0, button; (button = this.buttons_[i]); i++) { - var y = button.getPosition().y; - var x = flyoutWidth / this.workspace_.scale - button.width - + for (let i = 0, button; (button = this.buttons_[i]); i++) { + const y = button.getPosition().y; + const x = flyoutWidth / this.workspace_.scale - button.width - this.MARGIN - this.tabWidth_; button.moveTo(x, y); } From cd4f0e9f8c67edcfc9f068de9a3c49526b85bdaf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:27:27 -0700 Subject: [PATCH 040/172] Migrate core/flyout_vertical.js to goog.module --- core/flyout_vertical.js | 37 ++++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 786deff96..d937cce6e 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.VerticalFlyout'); +goog.module('Blockly.VerticalFlyout'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); @@ -37,16 +38,16 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.Flyout} * @constructor */ -Blockly.VerticalFlyout = function(workspaceOptions) { - Blockly.VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); +const VerticalFlyout = function(workspaceOptions) { + VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); }; -Blockly.utils.object.inherits(Blockly.VerticalFlyout, Blockly.Flyout); +Blockly.utils.object.inherits(VerticalFlyout, Blockly.Flyout); /** * The name of the vertical flyout in the registry. * @type {string} */ -Blockly.VerticalFlyout.registryName = 'verticalFlyout'; +VerticalFlyout.registryName = 'verticalFlyout'; /** * Sets the translation of the flyout to match the scrollbars. @@ -55,7 +56,7 @@ Blockly.VerticalFlyout.registryName = 'verticalFlyout'; * similar x property. * @protected */ -Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { +VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } @@ -77,7 +78,7 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.VerticalFlyout.prototype.getX = function() { +VerticalFlyout.prototype.getX = function() { if (!this.isVisible()) { return 0; } @@ -125,7 +126,7 @@ Blockly.VerticalFlyout.prototype.getX = function() { * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.VerticalFlyout.prototype.getY = function() { +VerticalFlyout.prototype.getY = function() { // Y is always 0 since this is a vertical flyout. return 0; }; @@ -133,7 +134,7 @@ Blockly.VerticalFlyout.prototype.getY = function() { /** * Move the flyout to the edge of the workspace. */ -Blockly.VerticalFlyout.prototype.position = function() { +VerticalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } @@ -161,7 +162,7 @@ Blockly.VerticalFlyout.prototype.position = function() { * rounded corners. * @private */ -Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { +VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; const totalWidth = width + this.CORNER_RADIUS; @@ -190,7 +191,7 @@ Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { /** * Scroll the flyout to the top. */ -Blockly.VerticalFlyout.prototype.scrollToStart = function() { +VerticalFlyout.prototype.scrollToStart = function() { this.workspace_.scrollbar.setY(0); }; @@ -199,7 +200,7 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() { * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.VerticalFlyout.prototype.wheel_ = function(e) { +VerticalFlyout.prototype.wheel_ = function(e) { const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); if (scrollDelta.y) { @@ -226,7 +227,7 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { +VerticalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; const margin = this.MARGIN; const cursorX = this.RTL ? margin : margin + this.tabWidth_; @@ -270,7 +271,7 @@ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( +VerticalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; @@ -292,7 +293,7 @@ Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.VerticalFlyout.prototype.getClientRect = function() { +VerticalFlyout.prototype.getClientRect = function() { if (!this.svgGroup_ || this.autoClose || !this.isVisible()) { // The bounding rectangle won't compute correctly if the flyout is closed // and auto-close flyouts aren't valid drag targets (or delete areas). @@ -319,7 +320,7 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { * For RTL: Lay out the blocks and buttons to be right-aligned. * @protected */ -Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { +VerticalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); let flyoutWidth = 0; const blocks = this.workspace_.getTopBlocks(false); @@ -380,4 +381,6 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { }; Blockly.registry.register(Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - Blockly.registry.DEFAULT, Blockly.VerticalFlyout); + Blockly.registry.DEFAULT, VerticalFlyout); + +exports = VerticalFlyout; diff --git a/tests/deps.js b/tests/deps.js index f62333982..de0ab070c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -64,7 +64,7 @@ goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], [' goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); From 394d71a7d97cd24653491a944c17e0c746bac810 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:32:27 -0700 Subject: [PATCH 041/172] Migrate core/flyout_vertical.js to named requires --- core/flyout_vertical.js | 63 +++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index d937cce6e..8c1177c30 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -13,35 +13,36 @@ goog.module('Blockly.VerticalFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Flyout = goog.require('Blockly.Flyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const Rect = goog.require('Blockly.utils.Rect'); +const Scrollbar = goog.require('Blockly.Scrollbar'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const registry = goog.require('Blockly.registry'); +const {Position} = goog.require('Blockly.utils.toolbox'); +const {getScrollDeltaPixels} = goog.require('Blockly.utils'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Flyout'); -goog.require('Blockly.registry'); -goog.require('Blockly.Scrollbar'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Coordinate'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. - * @extends {Blockly.Flyout} + * @extends {Flyout} * @constructor */ const VerticalFlyout = function(workspaceOptions) { VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); }; -Blockly.utils.object.inherits(VerticalFlyout, Blockly.Flyout); +inherits(VerticalFlyout, Flyout); /** * The name of the vertical flyout in the registry. @@ -92,14 +93,14 @@ VerticalFlyout.prototype.getX = function() { if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. if (this.targetWorkspace.getToolbox()) { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = toolboxMetrics.width; } else { x = viewMetrics.width - this.width_; } // Simple (flyout-only) toolbox. } else { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = 0; } else { // The simple flyout does not cover the workspace. @@ -108,7 +109,7 @@ VerticalFlyout.prototype.getX = function() { } // Trashcan flyout is opposite the main flyout. } else { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = 0; } else { // Because the anchor point of the flyout is on the left, but we want @@ -163,7 +164,7 @@ VerticalFlyout.prototype.position = function() { * @private */ VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { - const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; + const atRight = this.toolboxPosition_ == Position.RIGHT; const totalWidth = width + this.CORNER_RADIUS; // Decide whether to start on the left or right. @@ -201,7 +202,7 @@ VerticalFlyout.prototype.scrollToStart = function() { * @protected */ VerticalFlyout.prototype.wheel_ = function(e) { - const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = getScrollDeltaPixels(e); if (scrollDelta.y) { const metricsManager = this.workspace_.getMetricsManager(); @@ -211,8 +212,8 @@ VerticalFlyout.prototype.wheel_ = function(e) { this.workspace_.scrollbar.setY(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); } // Don't scroll the page. @@ -266,7 +267,7 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package @@ -290,7 +291,7 @@ VerticalFlyout.prototype.isDragTowardWorkspace = function( /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag + * @return {?Rect} The component's bounding box. Null if drag * target area should be ignored. */ VerticalFlyout.prototype.getClientRect = function() { @@ -307,11 +308,11 @@ VerticalFlyout.prototype.getClientRect = function() { const BIG_NUM = 1000000000; const left = flyoutRect.left; - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { const width = flyoutRect.width; - return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); + return new Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); } else { // Right - return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); + return new Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); } }; @@ -336,7 +337,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } flyoutWidth += this.MARGIN * 1.5 + this.tabWidth_; flyoutWidth *= this.workspace_.scale; - flyoutWidth += Blockly.Scrollbar.scrollbarThickness; + flyoutWidth += Scrollbar.scrollbarThickness; if (this.width_ != flyoutWidth) { for (let i = 0, block; (block = blocks[i]); i++) { @@ -364,7 +365,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_ && - this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT && + this.toolboxPosition_ == Position.LEFT && !this.targetWorkspace.getToolbox()) { // This flyout is a simple toolbox. Reposition the workspace so that (0,0) // is in the correct position relative to the new absolute edge (ie @@ -380,7 +381,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } }; -Blockly.registry.register(Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - Blockly.registry.DEFAULT, VerticalFlyout); +registry.register(registry.Type.FLYOUTS_VERTICAL_TOOLBOX, + registry.DEFAULT, VerticalFlyout); exports = VerticalFlyout; From def3458a10729c15b43bd1bac35e78cd931d9951 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:32:59 -0700 Subject: [PATCH 042/172] clang-format core/flyout_vertical.js --- core/flyout_vertical.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 8c1177c30..2091d1321 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -69,9 +69,10 @@ VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (typeof xyRatio.y == 'number') { this.workspace_.scrollY = -(scrollMetrics.top + - (scrollMetrics.height - viewMetrics.height) * xyRatio.y); + (scrollMetrics.height - viewMetrics.height) * xyRatio.y); } - this.workspace_.translate(this.workspace_.scrollX + absoluteMetrics.left, + this.workspace_.translate( + this.workspace_.scrollX + absoluteMetrics.left, this.workspace_.scrollY + absoluteMetrics.top); }; @@ -172,17 +173,15 @@ VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { // Top. path.push('h', atRight ? -width : width); // Rounded corner. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, - atRight ? 0 : 1, - atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, - this.CORNER_RADIUS); + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, + atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, this.CORNER_RADIUS); // Side closest to workspace. path.push('v', Math.max(0, height)); // Rounded corner. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, - atRight ? 0 : 1, - atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, - this.CORNER_RADIUS); + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, + atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, this.CORNER_RADIUS); // Bottom. path.push('h', atRight ? width : -width); path.push('z'); @@ -250,8 +249,8 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { const moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; block.moveBy(moveX, cursorY); - const rect = this.createRect_(block, - this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); + const rect = this.createRect_( + block, this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); this.addBlockListeners_(root, block, rect); @@ -272,8 +271,7 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -VerticalFlyout.prototype.isDragTowardWorkspace = function( - currentDragDeltaXY) { +VerticalFlyout.prototype.isDragTowardWorkspace = function(currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. @@ -371,7 +369,8 @@ VerticalFlyout.prototype.reflowInternal_ = function() { // is in the correct position relative to the new absolute edge (ie // toolbox edge). this.targetWorkspace.translate( - this.targetWorkspace.scrollX + flyoutWidth, this.targetWorkspace.scrollY); + this.targetWorkspace.scrollX + flyoutWidth, + this.targetWorkspace.scrollY); } // Record the width for workspace metrics and .position. @@ -381,7 +380,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } }; -registry.register(registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - registry.DEFAULT, VerticalFlyout); +registry.register( + registry.Type.FLYOUTS_VERTICAL_TOOLBOX, registry.DEFAULT, VerticalFlyout); exports = VerticalFlyout; From 90ed883eb0d06fceecbb6a17aa5bd018105adad6 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:38:39 -0700 Subject: [PATCH 043/172] Migrate core/generator.js to ES6 const/let --- core/generator.js | 48 +++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/core/generator.js b/core/generator.js index e365c69ba..a9a2d5418 100644 --- a/core/generator.js +++ b/core/generator.js @@ -96,11 +96,11 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) { console.warn('No workspace specified in workspaceToCode call. Guessing.'); workspace = Blockly.getMainWorkspace(); } - var code = []; + let code = []; this.init(workspace); - var blocks = workspace.getTopBlocks(true); - for (var i = 0, block; (block = blocks[i]); i++) { - var line = this.blockToCode(block); + const blocks = workspace.getTopBlocks(true); + for (let i = 0, block; (block = blocks[i]); i++) { + let line = this.blockToCode(block); if (Array.isArray(line)) { // Value blocks return tuples of code and operator order. // Top-level blocks don't care about operator order. @@ -150,10 +150,10 @@ Blockly.Generator.prototype.prefixLines = function(text, prefix) { * @return {string} Concatenated list of comments. */ Blockly.Generator.prototype.allNestedComments = function(block) { - var comments = []; - var blocks = block.getDescendants(true); - for (var i = 0; i < blocks.length; i++) { - var comment = blocks[i].getCommentText(); + const comments = []; + const blocks = block.getDescendants(true); + for (let i = 0; i < blocks.length; i++) { + const comment = blocks[i].getCommentText(); if (comment) { comments.push(comment); } @@ -191,7 +191,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { return opt_thisOnly ? '' : this.blockToCode(block.getChildren(false)[0]); } - var func = this[block.type]; + const func = this[block.type]; if (typeof func != 'function') { throw Error('Language "' + this.name_ + '" does not know how to generate ' + 'code for block type "' + block.type + '".'); @@ -200,7 +200,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { // Prior to 24 September 2013 'this' was the only way to access the block. // The current preferred method of accessing the block is through the second // argument to func.call, which becomes the first parameter to the generator. - var code = func.call(block, block); + let code = func.call(block, block); if (Array.isArray(code)) { // Value blocks return tuples of code and operator order. if (!block.outputConnection) { @@ -235,11 +235,11 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { if (isNaN(outerOrder)) { throw TypeError('Expecting valid order from block: ' + block.type); } - var targetBlock = block.getInputTargetBlock(name); + const targetBlock = block.getInputTargetBlock(name); if (!targetBlock) { return ''; } - var tuple = this.blockToCode(targetBlock); + const tuple = this.blockToCode(targetBlock); if (tuple === '') { // Disabled block. return ''; @@ -249,8 +249,8 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { if (!Array.isArray(tuple)) { throw TypeError('Expecting tuple from value block: ' + targetBlock.type); } - var code = tuple[0]; - var innerOrder = tuple[1]; + let code = tuple[0]; + const innerOrder = tuple[1]; if (isNaN(innerOrder)) { throw TypeError('Expecting valid order from value block: ' + targetBlock.type); @@ -260,9 +260,9 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { } // Add parentheses if needed. - var parensNeeded = false; - var outerOrderClass = Math.floor(outerOrder); - var innerOrderClass = Math.floor(innerOrder); + let parensNeeded = false; + const outerOrderClass = Math.floor(outerOrder); + const innerOrderClass = Math.floor(innerOrder); if (outerOrderClass <= innerOrderClass) { if (outerOrderClass == innerOrderClass && (outerOrderClass == 0 || outerOrderClass == 99)) { @@ -276,7 +276,7 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { // wrap the code in parentheses. parensNeeded = true; // Check for special exceptions. - for (var i = 0; i < this.ORDER_OVERRIDES.length; i++) { + for (let i = 0; i < this.ORDER_OVERRIDES.length; i++) { if (this.ORDER_OVERRIDES[i][0] == outerOrder && this.ORDER_OVERRIDES[i][1] == innerOrder) { parensNeeded = false; @@ -303,8 +303,8 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { * @return {string} Generated code or '' if no blocks are connected. */ Blockly.Generator.prototype.statementToCode = function(block, name) { - var targetBlock = block.getInputTargetBlock(name); - var code = this.blockToCode(targetBlock); + const targetBlock = block.getInputTargetBlock(name); + let code = this.blockToCode(targetBlock); // Value blocks must return code and order of operations info. // Statement blocks must only return code. if (typeof code != 'string') { @@ -350,7 +350,7 @@ Blockly.Generator.prototype.addLoopTrap = function(branch, block) { * @return {string} Code snippet with ID. */ Blockly.Generator.prototype.injectId = function(msg, block) { - var id = block.id.replace(/\$/g, '$$$$'); // Issue 251. + const id = block.id.replace(/\$/g, '$$$$'); // Issue 251. return msg.replace(/%1/g, '\'' + id + '\''); }; @@ -450,16 +450,16 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { */ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { - var functionName = this.nameDB_.getDistinctName( + const functionName = this.nameDB_.getDistinctName( desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; - var codeText = code.join('\n').replace( + let codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); // Change all ' ' indents into the desired indent. // To avoid an infinite loop of replacements, change all indents to '\0' // character first, then replace them all with the indent. // We are assuming that no provided functions contain a literal null char. - var oldCodeText; + let oldCodeText; while (oldCodeText != codeText) { oldCodeText = codeText; codeText = codeText.replace(/^(( {2})*) {2}/gm, '$1\0'); diff --git a/tests/deps.js b/tests/deps.js index f62333982..87a32ab95 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 4741d4c312586221a1c776510b8354fde6f1102f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:41:57 -0700 Subject: [PATCH 044/172] Migrate core/generator.js to goog.module --- core/generator.js | 69 ++++++++++++++++++++++++----------------------- tests/deps.js | 2 +- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/core/generator.js b/core/generator.js index a9a2d5418..609e9d56c 100644 --- a/core/generator.js +++ b/core/generator.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Generator'); +goog.module('Blockly.Generator'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Block'); goog.require('Blockly.internalConstants'); @@ -26,7 +27,7 @@ goog.requireType('Blockly.Workspace'); * @param {string} name Language name of this generator. * @constructor */ -Blockly.Generator = function(name) { +const Generator = function(name) { this.name_ = name; this.FUNCTION_NAME_PLACEHOLDER_REGEXP_ = new RegExp(this.FUNCTION_NAME_PLACEHOLDER_, 'g'); @@ -38,7 +39,7 @@ Blockly.Generator = function(name) { * E.g. ' checkTimeout(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.INFINITE_LOOP_TRAP = null; +Generator.prototype.INFINITE_LOOP_TRAP = null; /** * Arbitrary code to inject before every statement. @@ -46,7 +47,7 @@ Blockly.Generator.prototype.INFINITE_LOOP_TRAP = null; * E.g. 'highlight(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.STATEMENT_PREFIX = null; +Generator.prototype.STATEMENT_PREFIX = null; /** * Arbitrary code to inject after every statement. @@ -54,27 +55,27 @@ Blockly.Generator.prototype.STATEMENT_PREFIX = null; * E.g. 'highlight(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.STATEMENT_SUFFIX = null; +Generator.prototype.STATEMENT_SUFFIX = null; /** * The method of indenting. Defaults to two spaces, but language generators * may override this to increase indent or change to tabs. * @type {string} */ -Blockly.Generator.prototype.INDENT = ' '; +Generator.prototype.INDENT = ' '; /** * Maximum length for a comment before wrapping. Does not account for * indenting level. * @type {number} */ -Blockly.Generator.prototype.COMMENT_WRAP = 60; +Generator.prototype.COMMENT_WRAP = 60; /** * List of outer-inner pairings that do NOT require parentheses. * @type {!Array>} */ -Blockly.Generator.prototype.ORDER_OVERRIDES = []; +Generator.prototype.ORDER_OVERRIDES = []; /** * Whether the init method has been called. @@ -83,14 +84,14 @@ Blockly.Generator.prototype.ORDER_OVERRIDES = []; * initialized. If this flag is untouched, it will have no effect. * @type {?boolean} */ -Blockly.Generator.prototype.isInitialized = null; +Generator.prototype.isInitialized = null; /** * Generate code for all blocks in the workspace to the specified language. * @param {!Blockly.Workspace=} workspace Workspace to generate code from. * @return {string} Generated code. */ -Blockly.Generator.prototype.workspaceToCode = function(workspace) { +Generator.prototype.workspaceToCode = function(workspace) { if (!workspace) { // Backwards compatibility from before there could be multiple workspaces. console.warn('No workspace specified in workspaceToCode call. Guessing.'); @@ -140,7 +141,7 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) { * @param {string} prefix The common prefix. * @return {string} The prefixed lines of code. */ -Blockly.Generator.prototype.prefixLines = function(text, prefix) { +Generator.prototype.prefixLines = function(text, prefix) { return prefix + text.replace(/(?!\n$)\n/g, '\n' + prefix); }; @@ -149,7 +150,7 @@ Blockly.Generator.prototype.prefixLines = function(text, prefix) { * @param {!Blockly.Block} block The block from which to start spidering. * @return {string} Concatenated list of comments. */ -Blockly.Generator.prototype.allNestedComments = function(block) { +Generator.prototype.allNestedComments = function(block) { const comments = []; const blocks = block.getDescendants(true); for (let i = 0; i < blocks.length; i++) { @@ -174,7 +175,7 @@ Blockly.Generator.prototype.allNestedComments = function(block) { * For value blocks, an array containing the generated code and an * operator order value. Returns '' if block is null. */ -Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { +Generator.prototype.blockToCode = function(block, opt_thisOnly) { if (this.isInitialized === false) { console.warn( 'Generator init was not called before blockToCode was called.'); @@ -231,7 +232,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { * @return {string} Generated code or '' if no blocks are connected or the * specified input does not exist. */ -Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { +Generator.prototype.valueToCode = function(block, name, outerOrder) { if (isNaN(outerOrder)) { throw TypeError('Expecting valid order from block: ' + block.type); } @@ -302,7 +303,7 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { * @param {string} name The name of the input. * @return {string} Generated code or '' if no blocks are connected. */ -Blockly.Generator.prototype.statementToCode = function(block, name) { +Generator.prototype.statementToCode = function(block, name) { const targetBlock = block.getInputTargetBlock(name); let code = this.blockToCode(targetBlock); // Value blocks must return code and order of operations info. @@ -326,7 +327,7 @@ Blockly.Generator.prototype.statementToCode = function(block, name) { * @param {!Blockly.Block} block Enclosing block. * @return {string} Loop contents, with infinite loop trap added. */ -Blockly.Generator.prototype.addLoopTrap = function(branch, block) { +Generator.prototype.addLoopTrap = function(branch, block) { if (this.INFINITE_LOOP_TRAP) { branch = this.prefixLines(this.injectId(this.INFINITE_LOOP_TRAP, block), this.INDENT) + branch; @@ -349,7 +350,7 @@ Blockly.Generator.prototype.addLoopTrap = function(branch, block) { * @param {!Blockly.Block} block Block which has an ID. * @return {string} Code snippet with ID. */ -Blockly.Generator.prototype.injectId = function(msg, block) { +Generator.prototype.injectId = function(msg, block) { const id = block.id.replace(/\$/g, '$$$$'); // Issue 251. return msg.replace(/%1/g, '\'' + id + '\''); }; @@ -359,33 +360,33 @@ Blockly.Generator.prototype.injectId = function(msg, block) { * @type {string} * @protected */ -Blockly.Generator.prototype.RESERVED_WORDS_ = ''; +Generator.prototype.RESERVED_WORDS_ = ''; /** * Add one or more words to the list of reserved words for this language. * @param {string} words Comma-separated list of words to add to the list. * No spaces. Duplicates are ok. */ -Blockly.Generator.prototype.addReservedWords = function(words) { +Generator.prototype.addReservedWords = function(words) { this.RESERVED_WORDS_ += words + ','; }; /** * This is used as a placeholder in functions defined using - * Blockly.Generator.provideFunction_. It must not be legal code that could + * Generator.provideFunction_. It must not be legal code that could * legitimately appear in a function definition (or comment), and it must * not confuse the regular expression parser. * @type {string} * @protected */ -Blockly.Generator.prototype.FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}'; +Generator.prototype.FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}'; /** * A dictionary of definitions to be printed before the code. * @type {!Object|undefined} * @protected */ -Blockly.Generator.prototype.definitions_; +Generator.prototype.definitions_; /** * A dictionary mapping desired function names in definitions_ to actual @@ -393,20 +394,20 @@ Blockly.Generator.prototype.definitions_; * @type {!Object|undefined} * @protected */ -Blockly.Generator.prototype.functionNames_; +Generator.prototype.functionNames_; /** * A database of variable and procedure names. * @type {!Blockly.Names|undefined} * @protected */ -Blockly.Generator.prototype.nameDB_; +Generator.prototype.nameDB_; -Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { +Object.defineProperty(Generator.prototype, 'variableDB_', { /** * Getter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). - * @this {Blockly.Generator} + * @this {Generator} * @return {!Blockly.Names|undefined} Name database. */ get: function() { @@ -417,7 +418,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { /** * Setter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). - * @this {Blockly.Generator} + * @this {Generator} * @param {!Blockly.Names|undefined} nameDb New name database. */ set: function(nameDb) { @@ -439,7 +440,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { * "listRandom", not "random"). There is no danger of colliding with reserved * words, or user-defined variable or procedure names. * - * The code gets output when Blockly.Generator.finish() is called. + * The code gets output when Generator.finish() is called. * * @param {string} desiredName The desired name of the function * (e.g. mathIsPrime). @@ -448,7 +449,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { * from desiredName if the former has already been taken by the user. * @protected */ -Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { +Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { const functionName = this.nameDB_.getDistinctName( desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); @@ -476,7 +477,7 @@ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { * names. * @param {!Blockly.Workspace} _workspace Workspace to generate code from. */ -Blockly.Generator.prototype.init = function(_workspace) { +Generator.prototype.init = function(_workspace) { // Optionally override // Create a dictionary of definitions to be printed before the code. this.definitions_ = Object.create(null); @@ -499,7 +500,7 @@ Blockly.Generator.prototype.init = function(_workspace) { * @return {string} Code with comments and subsequent blocks added. * @protected */ -Blockly.Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { +Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { // Optionally override return code; }; @@ -511,7 +512,7 @@ Blockly.Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { * @param {string} code Generated code. * @return {string} Completed code. */ -Blockly.Generator.prototype.finish = function(code) { +Generator.prototype.finish = function(code) { // Optionally override // Clean up temporary data. delete this.definitions_; @@ -527,7 +528,9 @@ Blockly.Generator.prototype.finish = function(code) { * @param {string} line Line of generated code. * @return {string} Legal line of code. */ -Blockly.Generator.prototype.scrubNakedValue = function(line) { +Generator.prototype.scrubNakedValue = function(line) { // Optionally override return line; }; + +exports = Generator; diff --git a/tests/deps.js b/tests/deps.js index 87a32ab95..db93b7671 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 1a1bad0bd718255cf53ce9de1787e123356da225 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:45:25 -0700 Subject: [PATCH 045/172] Migrate core/generator.js to named requires --- core/generator.js | 47 +++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/generator.js b/core/generator.js index 609e9d56c..7882a0402 100644 --- a/core/generator.js +++ b/core/generator.js @@ -14,12 +14,15 @@ goog.module('Blockly.Generator'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Block'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils.deprecation'); - -goog.requireType('Blockly.Names'); -goog.requireType('Blockly.Workspace'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Names = goog.requireType('Blockly.Names'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const internalConstants = goog.require('Blockly.internalConstants'); +const deprecation = goog.require('Blockly.utils.deprecation'); +const {getMainWorkspace} = goog.require('Blockly'); /** @@ -88,14 +91,14 @@ Generator.prototype.isInitialized = null; /** * Generate code for all blocks in the workspace to the specified language. - * @param {!Blockly.Workspace=} workspace Workspace to generate code from. + * @param {!Workspace=} workspace Workspace to generate code from. * @return {string} Generated code. */ Generator.prototype.workspaceToCode = function(workspace) { if (!workspace) { // Backwards compatibility from before there could be multiple workspaces. console.warn('No workspace specified in workspaceToCode call. Guessing.'); - workspace = Blockly.getMainWorkspace(); + workspace = getMainWorkspace(); } let code = []; this.init(workspace); @@ -147,7 +150,7 @@ Generator.prototype.prefixLines = function(text, prefix) { /** * Recursively spider a tree of blocks, returning all their comments. - * @param {!Blockly.Block} block The block from which to start spidering. + * @param {!Block} block The block from which to start spidering. * @return {string} Concatenated list of comments. */ Generator.prototype.allNestedComments = function(block) { @@ -169,7 +172,7 @@ Generator.prototype.allNestedComments = function(block) { /** * Generate code for the specified block (and attached blocks). * The generator must be initialized before calling this function. - * @param {Blockly.Block} block The block to generate code for. + * @param {Block} block The block to generate code for. * @param {boolean=} opt_thisOnly True to generate code for only this statement. * @return {string|!Array} For statement blocks, the generated code. * For value blocks, an array containing the generated code and an @@ -225,7 +228,7 @@ Generator.prototype.blockToCode = function(block, opt_thisOnly) { /** * Generate code representing the specified value input. - * @param {!Blockly.Block} block The block containing the input. + * @param {!Block} block The block containing the input. * @param {string} name The name of the input. * @param {number} outerOrder The maximum binding strength (minimum order value) * of any operators adjacent to "block". @@ -299,7 +302,7 @@ Generator.prototype.valueToCode = function(block, name, outerOrder) { * statement input. Indent the code. * This is mainly used in generators. When trying to generate code to evaluate * look at using workspaceToCode or blockToCode. - * @param {!Blockly.Block} block The block containing the input. + * @param {!Block} block The block containing the input. * @param {string} name The name of the input. * @return {string} Generated code or '' if no blocks are connected. */ @@ -324,7 +327,7 @@ Generator.prototype.statementToCode = function(block, name) { * statement executes), and a statement prefix to the end of the loop block * (right before the loop statement executes). * @param {string} branch Code for loop contents. - * @param {!Blockly.Block} block Enclosing block. + * @param {!Block} block Enclosing block. * @return {string} Loop contents, with infinite loop trap added. */ Generator.prototype.addLoopTrap = function(branch, block) { @@ -347,7 +350,7 @@ Generator.prototype.addLoopTrap = function(branch, block) { * Inject a block ID into a message to replace '%1'. * Used for STATEMENT_PREFIX, STATEMENT_SUFFIX, and INFINITE_LOOP_TRAP. * @param {string} msg Code snippet with '%1'. - * @param {!Blockly.Block} block Block which has an ID. + * @param {!Block} block Block which has an ID. * @return {string} Code snippet with ID. */ Generator.prototype.injectId = function(msg, block) { @@ -398,7 +401,7 @@ Generator.prototype.functionNames_; /** * A database of variable and procedure names. - * @type {!Blockly.Names|undefined} + * @type {!Names|undefined} * @protected */ Generator.prototype.nameDB_; @@ -408,10 +411,10 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * Getter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). * @this {Generator} - * @return {!Blockly.Names|undefined} Name database. + * @return {!Names|undefined} Name database. */ get: function() { - Blockly.utils.deprecation.warn( + deprecation.warn( 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); return this.nameDB_; }, @@ -419,10 +422,10 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * Setter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). * @this {Generator} - * @param {!Blockly.Names|undefined} nameDb New name database. + * @param {!Names|undefined} nameDb New name database. */ set: function(nameDb) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); this.nameDB_ = nameDb; } @@ -452,7 +455,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { const functionName = this.nameDB_.getDistinctName( - desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); + desiredName, internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; let codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); @@ -475,7 +478,7 @@ Generator.prototype.provideFunction_ = function(desiredName, code) { * Hook for code to run before code generation starts. * Subclasses may override this, e.g. to initialise the database of variable * names. - * @param {!Blockly.Workspace} _workspace Workspace to generate code from. + * @param {!Workspace} _workspace Workspace to generate code from. */ Generator.prototype.init = function(_workspace) { // Optionally override @@ -493,7 +496,7 @@ Generator.prototype.init = function(_workspace) { * Subclasses may override this, e.g. to generate code for statements following * the block, or to handle comments for the specified block and any connected * value blocks. - * @param {!Blockly.Block} _block The current block. + * @param {!Block} _block The current block. * @param {string} code The code created for this block. * @param {boolean=} _opt_thisOnly True to generate code for only this * statement. diff --git a/tests/deps.js b/tests/deps.js index db93b7671..c40db7cbc 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From da77f3e5b42985828486f19fefcaeacca0c0eedd Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:46:01 -0700 Subject: [PATCH 046/172] clang-format core/generator.js --- core/generator.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/core/generator.js b/core/generator.js index 7882a0402..8e71fb040 100644 --- a/core/generator.js +++ b/core/generator.js @@ -197,7 +197,8 @@ Generator.prototype.blockToCode = function(block, opt_thisOnly) { const func = this[block.type]; if (typeof func != 'function') { - throw Error('Language "' + this.name_ + '" does not know how to generate ' + + throw Error( + 'Language "' + this.name_ + '" does not know how to generate ' + 'code for block type "' + block.type + '".'); } // First argument to func.call is the value of 'this' in the generator. @@ -256,8 +257,8 @@ Generator.prototype.valueToCode = function(block, name, outerOrder) { let code = tuple[0]; const innerOrder = tuple[1]; if (isNaN(innerOrder)) { - throw TypeError('Expecting valid order from value block: ' + - targetBlock.type); + throw TypeError( + 'Expecting valid order from value block: ' + targetBlock.type); } if (!code) { return ''; @@ -312,7 +313,8 @@ Generator.prototype.statementToCode = function(block, name) { // Value blocks must return code and order of operations info. // Statement blocks must only return code. if (typeof code != 'string') { - throw TypeError('Expecting code from statement block: ' + + throw TypeError( + 'Expecting code from statement block: ' + (targetBlock && targetBlock.type)); } if (code) { @@ -332,16 +334,19 @@ Generator.prototype.statementToCode = function(block, name) { */ Generator.prototype.addLoopTrap = function(branch, block) { if (this.INFINITE_LOOP_TRAP) { - branch = this.prefixLines(this.injectId(this.INFINITE_LOOP_TRAP, block), - this.INDENT) + branch; + branch = this.prefixLines( + this.injectId(this.INFINITE_LOOP_TRAP, block), this.INDENT) + + branch; } if (this.STATEMENT_SUFFIX && !block.suppressPrefixSuffix) { - branch = this.prefixLines(this.injectId(this.STATEMENT_SUFFIX, block), - this.INDENT) + branch; + branch = this.prefixLines( + this.injectId(this.STATEMENT_SUFFIX, block), this.INDENT) + + branch; } if (this.STATEMENT_PREFIX && !block.suppressPrefixSuffix) { - branch = branch + this.prefixLines(this.injectId(this.STATEMENT_PREFIX, - block), this.INDENT); + branch = branch + + this.prefixLines( + this.injectId(this.STATEMENT_PREFIX, block), this.INDENT); } return branch; }; @@ -414,8 +419,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * @return {!Names|undefined} Name database. */ get: function() { - deprecation.warn( - 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); + deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); return this.nameDB_; }, /** @@ -425,8 +429,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * @param {!Names|undefined} nameDb New name database. */ set: function(nameDb) { - deprecation.warn( - 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); + deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); this.nameDB_ = nameDb; } }); From 1941e857e3564b6aa9ad323b607d66559ef1fe5b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:51:58 -0700 Subject: [PATCH 047/172] Migrate core/grid.js to ES6 const/let --- core/grid.js | 10 +++++----- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/grid.js b/core/grid.js index 56171ef50..b01d59dbd 100644 --- a/core/grid.js +++ b/core/grid.js @@ -125,14 +125,14 @@ Blockly.Grid.prototype.getPatternId = function() { Blockly.Grid.prototype.update = function(scale) { this.scale_ = scale; // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. - var safeSpacing = (this.spacing_ * scale) || 100; + const safeSpacing = (this.spacing_ * scale) || 100; this.gridPattern_.setAttribute('width', safeSpacing); this.gridPattern_.setAttribute('height', safeSpacing); - var half = Math.floor(this.spacing_ / 2) + 0.5; - var start = half - this.length_ / 2; - var end = half + this.length_ / 2; + let half = Math.floor(this.spacing_ / 2) + 0.5; + let start = half - this.length_ / 2; + let end = half + this.length_ / 2; half *= scale; start *= scale; @@ -197,7 +197,7 @@ Blockly.Grid.createDom = function(rnd, gridOptions, defs) { */ - var gridPattern = Blockly.utils.dom.createSvgElement( + const gridPattern = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATTERN, { 'id': 'blocklyGridPattern' + rnd, diff --git a/tests/deps.js b/tests/deps.js index f62333982..25dd37c2e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -67,7 +67,7 @@ goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); From 4c7ac8dd382cd2cc8d2dd46c4e9eabf7af86def4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:54:43 -0700 Subject: [PATCH 048/172] Migrate core/grid.js to goog.module --- core/grid.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/grid.js b/core/grid.js index b01d59dbd..48189fe69 100644 --- a/core/grid.js +++ b/core/grid.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Grid'); +goog.module('Blockly.Grid'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); @@ -27,7 +28,7 @@ goog.require('Blockly.utils.userAgent'); * https://developers.google.com/blockly/guides/configure/web/grid * @constructor */ -Blockly.Grid = function(pattern, options) { +const Grid = function(pattern, options) { /** * The grid's SVG pattern, created during injection. * @type {!SVGElement} @@ -78,14 +79,14 @@ Blockly.Grid = function(pattern, options) { * @type {number} * @private */ -Blockly.Grid.prototype.scale_ = 1; +Grid.prototype.scale_ = 1; /** * Dispose of this grid and unlink from the DOM. * @package * @suppress {checkTypes} */ -Blockly.Grid.prototype.dispose = function() { +Grid.prototype.dispose = function() { this.gridPattern_ = null; }; @@ -94,7 +95,7 @@ Blockly.Grid.prototype.dispose = function() { * @return {boolean} True if blocks should snap, false otherwise. * @package */ -Blockly.Grid.prototype.shouldSnap = function() { +Grid.prototype.shouldSnap = function() { return this.snapToGrid_; }; @@ -103,7 +104,7 @@ Blockly.Grid.prototype.shouldSnap = function() { * @return {number} The spacing of the grid points. * @package */ -Blockly.Grid.prototype.getSpacing = function() { +Grid.prototype.getSpacing = function() { return this.spacing_; }; @@ -113,7 +114,7 @@ Blockly.Grid.prototype.getSpacing = function() { * @return {string} The pattern ID. * @package */ -Blockly.Grid.prototype.getPatternId = function() { +Grid.prototype.getPatternId = function() { return this.gridPattern_.id; }; @@ -122,7 +123,7 @@ Blockly.Grid.prototype.getPatternId = function() { * @param {number} scale The new workspace scale. * @package */ -Blockly.Grid.prototype.update = function(scale) { +Grid.prototype.update = function(scale) { this.scale_ = scale; // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. const safeSpacing = (this.spacing_ * scale) || 100; @@ -153,7 +154,7 @@ Blockly.Grid.prototype.update = function(scale) { * @param {number} y2 The new y end position of the line (in px). * @private */ -Blockly.Grid.prototype.setLineAttributes_ = function(line, width, +Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) { if (line) { line.setAttribute('stroke-width', width); @@ -171,7 +172,7 @@ Blockly.Grid.prototype.setLineAttributes_ = function(line, width, * @param {number} y The new y position of the grid (in px). * @package */ -Blockly.Grid.prototype.moveTo = function(x, y) { +Grid.prototype.moveTo = function(x, y) { this.gridPattern_.setAttribute('x', x); this.gridPattern_.setAttribute('y', y); @@ -190,7 +191,7 @@ Blockly.Grid.prototype.moveTo = function(x, y) { * @return {!SVGElement} The SVG element for the grid pattern. * @package */ -Blockly.Grid.createDom = function(rnd, gridOptions, defs) { +Grid.createDom = function(rnd, gridOptions, defs) { /* @@ -220,3 +221,5 @@ Blockly.Grid.createDom = function(rnd, gridOptions, defs) { } return gridPattern; }; + +exports = Grid; diff --git a/tests/deps.js b/tests/deps.js index 25dd37c2e..f6a0972e2 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -67,7 +67,7 @@ goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6'}); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); From 25cb8773cd0627fe8c6066a5bf6c2198f2de5cac Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:59:42 -0700 Subject: [PATCH 049/172] Migrate core/grid.js to named requires --- core/grid.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/grid.js b/core/grid.js index 48189fe69..b93a39fa1 100644 --- a/core/grid.js +++ b/core/grid.js @@ -14,9 +14,9 @@ goog.module('Blockly.Grid'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); +const userAgent = goog.require('Blockly.utils.userAgent'); /** @@ -176,7 +176,7 @@ Grid.prototype.moveTo = function(x, y) { this.gridPattern_.setAttribute('x', x); this.gridPattern_.setAttribute('y', y); - if (Blockly.utils.userAgent.IE || Blockly.utils.userAgent.EDGE) { + if (userAgent.IE || userAgent.EDGE) { // IE/Edge doesn't notice that the x/y offsets have changed. // Force an update. this.update(this.scale_); @@ -198,26 +198,26 @@ Grid.createDom = function(rnd, gridOptions, defs) { */ - const gridPattern = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATTERN, + const gridPattern = dom.createSvgElement( + Svg.PATTERN, { 'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse' }, defs); if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, + dom.createSvgElement( + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, + dom.createSvgElement( + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } // x1, y1, x1, x2 properties will be set later in update. } else { // Edge 16 doesn't handle empty patterns - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, {}, gridPattern); + dom.createSvgElement( + Svg.LINE, {}, gridPattern); } return gridPattern; }; From d36abd2b338117eb4ca248346926bdc5f36e7c2f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:00:09 -0700 Subject: [PATCH 050/172] clang-format core/grid.js --- core/grid.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/core/grid.js b/core/grid.js index b93a39fa1..1a1d5f2a3 100644 --- a/core/grid.js +++ b/core/grid.js @@ -62,8 +62,8 @@ const Grid = function(pattern, options) { * @type {SVGElement} * @private */ - this.line2_ = this.line1_ && - (/** @type {SVGElement} */ (this.line1_.nextSibling)); + this.line2_ = + this.line1_ && (/** @type {SVGElement} */ (this.line1_.nextSibling)); /** * Whether blocks should snap to the grid. @@ -154,8 +154,7 @@ Grid.prototype.update = function(scale) { * @param {number} y2 The new y end position of the line (in px). * @private */ -Grid.prototype.setLineAttributes_ = function(line, width, - x1, x2, y1, y2) { +Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) { if (line) { line.setAttribute('stroke-width', width); line.setAttribute('x1', x1); @@ -200,24 +199,19 @@ Grid.createDom = function(rnd, gridOptions, defs) { */ const gridPattern = dom.createSvgElement( Svg.PATTERN, - { - 'id': 'blocklyGridPattern' + rnd, - 'patternUnits': 'userSpaceOnUse' - }, defs); + {'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse'}, + defs); if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { dom.createSvgElement( - Svg.LINE, - {'stroke': gridOptions['colour']}, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { dom.createSvgElement( - Svg.LINE, - {'stroke': gridOptions['colour']}, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } // x1, y1, x1, x2 properties will be set later in update. } else { // Edge 16 doesn't handle empty patterns - dom.createSvgElement( - Svg.LINE, {}, gridPattern); + dom.createSvgElement(Svg.LINE, {}, gridPattern); } return gridPattern; }; From 341b5156934f8239924049c51c918c80ec973258 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:15:58 -0700 Subject: [PATCH 051/172] Migrate core/icon.js to ES6 const/let --- core/icon.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/icon.js b/core/icon.js index c5f3477cd..ca1548aa3 100644 --- a/core/icon.js +++ b/core/icon.js @@ -164,10 +164,10 @@ Blockly.Icon.prototype.setIconLocation = function(xy) { */ Blockly.Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. - var blockXY = this.block_.getRelativeToSurfaceXY(); - var iconXY = Blockly.utils.getRelativeXY( + const blockXY = this.block_.getRelativeToSurfaceXY(); + const iconXY = Blockly.utils.getRelativeXY( /** @type {!SVGElement} */ (this.iconGroup_)); - var newXY = new Blockly.utils.Coordinate( + const newXY = new Blockly.utils.Coordinate( blockXY.x + iconXY.x + this.SIZE / 2, blockXY.y + iconXY.y + this.SIZE / 2); if (!Blockly.utils.Coordinate.equals(this.getIconLocation(), newXY)) { From 8f72d004741ef12eca40fd96ebd4ff85395efa41 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:17:59 -0700 Subject: [PATCH 052/172] Migrate core/icon.js to goog.module --- core/icon.js | 41 ++++++++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/core/icon.js b/core/icon.js index ca1548aa3..02e6f7348 100644 --- a/core/icon.js +++ b/core/icon.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Icon'); +goog.module('Blockly.Icon'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.utils'); @@ -29,7 +30,7 @@ goog.requireType('Blockly.Bubble'); * @constructor * @abstract */ -Blockly.Icon = function(block) { +const Icon = function(block) { /** * The block this icon is attached to. * @type {Blockly.BlockSvg} @@ -47,31 +48,31 @@ Blockly.Icon = function(block) { /** * Does this icon get hidden when the block is collapsed. */ -Blockly.Icon.prototype.collapseHidden = true; +Icon.prototype.collapseHidden = true; /** * Height and width of icons. */ -Blockly.Icon.prototype.SIZE = 17; +Icon.prototype.SIZE = 17; /** * Bubble UI (if visible). * @type {?Blockly.Bubble} * @protected */ -Blockly.Icon.prototype.bubble_ = null; +Icon.prototype.bubble_ = null; /** * Absolute coordinate of icon's center. * @type {?Blockly.utils.Coordinate} * @protected */ -Blockly.Icon.prototype.iconXY_ = null; +Icon.prototype.iconXY_ = null; /** * Create the icon on the block. */ -Blockly.Icon.prototype.createIcon = function() { +Icon.prototype.createIcon = function() { if (this.iconGroup_) { // Icon already exists. return; @@ -99,7 +100,7 @@ Blockly.Icon.prototype.createIcon = function() { /** * Dispose of this icon. */ -Blockly.Icon.prototype.dispose = function() { +Icon.prototype.dispose = function() { // Dispose of and unlink the icon. Blockly.utils.dom.removeNode(this.iconGroup_); this.iconGroup_ = null; @@ -111,7 +112,7 @@ Blockly.Icon.prototype.dispose = function() { /** * Add or remove the UI indicating if this icon may be clicked or not. */ -Blockly.Icon.prototype.updateEditable = function() { +Icon.prototype.updateEditable = function() { // No-op on the base class. }; @@ -119,7 +120,7 @@ Blockly.Icon.prototype.updateEditable = function() { * Is the associated bubble visible? * @return {boolean} True if the bubble is visible. */ -Blockly.Icon.prototype.isVisible = function() { +Icon.prototype.isVisible = function() { return !!this.bubble_; }; @@ -128,7 +129,7 @@ Blockly.Icon.prototype.isVisible = function() { * @param {!Event} e Mouse click event. * @protected */ -Blockly.Icon.prototype.iconClick_ = function(e) { +Icon.prototype.iconClick_ = function(e) { if (this.block_.workspace.isDragging()) { // Drag operation is concluding. Don't open the editor. return; @@ -141,7 +142,7 @@ Blockly.Icon.prototype.iconClick_ = function(e) { /** * Change the colour of the associated bubble to match its block. */ -Blockly.Icon.prototype.applyColour = function() { +Icon.prototype.applyColour = function() { if (this.isVisible()) { this.bubble_.setColour(this.block_.style.colourPrimary); } @@ -151,7 +152,7 @@ Blockly.Icon.prototype.applyColour = function() { * Notification that the icon has moved. Update the arrow accordingly. * @param {!Blockly.utils.Coordinate} xy Absolute location in workspace coordinates. */ -Blockly.Icon.prototype.setIconLocation = function(xy) { +Icon.prototype.setIconLocation = function(xy) { this.iconXY_ = xy; if (this.isVisible()) { this.bubble_.setAnchorLocation(xy); @@ -162,7 +163,7 @@ Blockly.Icon.prototype.setIconLocation = function(xy) { * Notification that the icon has moved, but we don't really know where. * Recompute the icon's location from scratch. */ -Blockly.Icon.prototype.computeIconLocation = function() { +Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. const blockXY = this.block_.getRelativeToSurfaceXY(); const iconXY = Blockly.utils.getRelativeXY( @@ -180,7 +181,7 @@ Blockly.Icon.prototype.computeIconLocation = function() { * @return {?Blockly.utils.Coordinate} Object with x and y properties in * workspace coordinates. */ -Blockly.Icon.prototype.getIconLocation = function() { +Icon.prototype.getIconLocation = function() { return this.iconXY_; }; @@ -191,9 +192,9 @@ Blockly.Icon.prototype.getIconLocation = function() { * @return {!Blockly.utils.Size} Height and width. */ // TODO (#2562): Remove getCorrectedSize. -Blockly.Icon.prototype.getCorrectedSize = function() { +Icon.prototype.getCorrectedSize = function() { return new Blockly.utils.Size( - Blockly.Icon.prototype.SIZE, Blockly.Icon.prototype.SIZE - 2); + Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; /** @@ -201,10 +202,12 @@ Blockly.Icon.prototype.getCorrectedSize = function() { * @param {!Element} group The icon group. * @protected */ -Blockly.Icon.prototype.drawIcon_; +Icon.prototype.drawIcon_; /** * Show or hide the icon. * @param {boolean} visible True if the icon should be visible. */ -Blockly.Icon.prototype.setVisible; +Icon.prototype.setVisible; + +exports = Icon; diff --git a/tests/deps.js b/tests/deps.js index f62333982..57ab7a557 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -68,7 +68,7 @@ goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); From f0a3c7214dc086de2ad29dabc41fc35e8c975102 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 13:40:19 -0700 Subject: [PATCH 053/172] Migrate core/interfaces/i_metrics_manager.js to goog.module --- core/interfaces/i_metrics_manager.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index 916f14d5d..f9b74e4c2 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IMetricsManager'); +goog.module('Blockly.IMetricsManager'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.MetricsManager'); goog.requireType('Blockly.utils.Metrics'); @@ -22,14 +23,14 @@ goog.requireType('Blockly.utils.Size'); * Interface for a metrics manager. * @interface */ -Blockly.IMetricsManager = function() {}; +const IMetricsManager = function() {}; /** * Returns whether the scroll area has fixed edges. * @return {boolean} Whether the scroll area has fixed edges. * @package */ -Blockly.IMetricsManager.prototype.hasFixedEdges; +IMetricsManager.prototype.hasFixedEdges; /** * Returns the metrics for the scroll area of the workspace. @@ -44,7 +45,7 @@ Blockly.IMetricsManager.prototype.hasFixedEdges; * @return {!Blockly.MetricsManager.ContainerRegion} The metrics for the scroll * container */ -Blockly.IMetricsManager.prototype.getScrollMetrics; +IMetricsManager.prototype.getScrollMetrics; /** * Gets the width and the height of the flyout on the workspace in pixel @@ -55,7 +56,7 @@ Blockly.IMetricsManager.prototype.getScrollMetrics; * flyout. * @public */ -Blockly.IMetricsManager.prototype.getFlyoutMetrics; +IMetricsManager.prototype.getFlyoutMetrics; /** * Gets the width, height and position of the toolbox on the workspace in pixel @@ -66,7 +67,7 @@ Blockly.IMetricsManager.prototype.getFlyoutMetrics; * height and position of the toolbox. * @public */ -Blockly.IMetricsManager.prototype.getToolboxMetrics; +IMetricsManager.prototype.getToolboxMetrics; /** * Gets the width and height of the workspace's parent SVG element in pixel @@ -75,7 +76,7 @@ Blockly.IMetricsManager.prototype.getToolboxMetrics; * SVG element. * @public */ -Blockly.IMetricsManager.prototype.getSvgMetrics; +IMetricsManager.prototype.getSvgMetrics; /** * Gets the absolute left and absolute top in pixel coordinates. @@ -84,7 +85,7 @@ Blockly.IMetricsManager.prototype.getSvgMetrics; * the workspace. * @public */ -Blockly.IMetricsManager.prototype.getAbsoluteMetrics; +IMetricsManager.prototype.getAbsoluteMetrics; /** * Gets the metrics for the visible workspace in either pixel or workspace @@ -96,7 +97,7 @@ Blockly.IMetricsManager.prototype.getAbsoluteMetrics; * coordinates. * @public */ -Blockly.IMetricsManager.prototype.getViewMetrics; +IMetricsManager.prototype.getViewMetrics; /** * Gets content metrics in either pixel or workspace coordinates. @@ -108,7 +109,7 @@ Blockly.IMetricsManager.prototype.getViewMetrics; * metrics for the content container. * @public */ -Blockly.IMetricsManager.prototype.getContentMetrics; +IMetricsManager.prototype.getContentMetrics; /** * Returns an object with all the metrics required to size scrollbars for a @@ -142,4 +143,6 @@ Blockly.IMetricsManager.prototype.getContentMetrics; * level workspace. * @public */ -Blockly.IMetricsManager.prototype.getMetrics; +IMetricsManager.prototype.getMetrics; + +exports = IMetricsManager; diff --git a/tests/deps.js b/tests/deps.js index f62333982..5cadf3977 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -91,7 +91,7 @@ goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarg goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); +goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); From f3a0c6414f673f957afff3e921023821820a6f7d Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 13:40:51 -0700 Subject: [PATCH 054/172] Migrate core/interfaces/i_metrics_manager.js named requires --- core/interfaces/i_metrics_manager.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index f9b74e4c2..b8cbd2231 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -14,9 +14,9 @@ goog.module('Blockly.IMetricsManager'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.MetricsManager'); -goog.requireType('Blockly.utils.Metrics'); -goog.requireType('Blockly.utils.Size'); +const Metrics = goog.requireType('Blockly.utils.Metrics'); +const Size = goog.requireType('Blockly.utils.Size'); +const {AbsoluteMetrics, ContainerRegion, ToolboxMetrics} = goog.requireType('Blockly.MetricsManager'); /** @@ -36,13 +36,13 @@ IMetricsManager.prototype.hasFixedEdges; * Returns the metrics for the scroll area of the workspace. * @param {boolean=} opt_getWorkspaceCoordinates True to get the scroll metrics * in workspace coordinates, false to get them in pixel coordinates. - * @param {!Blockly.MetricsManager.ContainerRegion=} opt_viewMetrics The view + * @param {!ContainerRegion=} opt_viewMetrics The view * metrics if they have been previously computed. Passing in null may cause * the view metrics to be computed again, if it is needed. - * @param {!Blockly.MetricsManager.ContainerRegion=} opt_contentMetrics The + * @param {!ContainerRegion=} opt_contentMetrics The * content metrics if they have been previously computed. Passing in null * may cause the content metrics to be computed again, if it is needed. - * @return {!Blockly.MetricsManager.ContainerRegion} The metrics for the scroll + * @return {!ContainerRegion} The metrics for the scroll * container */ IMetricsManager.prototype.getScrollMetrics; @@ -52,7 +52,7 @@ IMetricsManager.prototype.getScrollMetrics; * coordinates. Returns 0 for the width and height if the workspace has a * category toolbox instead of a simple toolbox. * @param {boolean=} opt_own Whether to only return the workspace's own flyout. - * @return {!Blockly.MetricsManager.ToolboxMetrics} The width and height of the + * @return {!ToolboxMetrics} The width and height of the * flyout. * @public */ @@ -63,7 +63,7 @@ IMetricsManager.prototype.getFlyoutMetrics; * coordinates. Returns 0 for the width and height if the workspace has a simple * toolbox instead of a category toolbox. To get the width and height of a * simple toolbox @see {@link getFlyoutMetrics}. - * @return {!Blockly.MetricsManager.ToolboxMetrics} The object with the width, + * @return {!ToolboxMetrics} The object with the width, * height and position of the toolbox. * @public */ @@ -72,7 +72,7 @@ IMetricsManager.prototype.getToolboxMetrics; /** * Gets the width and height of the workspace's parent SVG element in pixel * coordinates. This area includes the toolbox and the visible workspace area. - * @return {!Blockly.utils.Size} The width and height of the workspace's parent + * @return {!Size} The width and height of the workspace's parent * SVG element. * @public */ @@ -81,7 +81,7 @@ IMetricsManager.prototype.getSvgMetrics; /** * Gets the absolute left and absolute top in pixel coordinates. * This is where the visible workspace starts in relation to the SVG container. - * @return {!Blockly.MetricsManager.AbsoluteMetrics} The absolute metrics for + * @return {!AbsoluteMetrics} The absolute metrics for * the workspace. * @public */ @@ -92,7 +92,7 @@ IMetricsManager.prototype.getAbsoluteMetrics; * coordinates. The visible workspace does not include the toolbox or flyout. * @param {boolean=} opt_getWorkspaceCoordinates True to get the view metrics in * workspace coordinates, false to get them in pixel coordinates. - * @return {!Blockly.MetricsManager.ContainerRegion} The width, height, top and + * @return {!ContainerRegion} The width, height, top and * left of the viewport in either workspace coordinates or pixel * coordinates. * @public @@ -105,7 +105,7 @@ IMetricsManager.prototype.getViewMetrics; * workspace (workspace comments and blocks). * @param {boolean=} opt_getWorkspaceCoordinates True to get the content metrics * in workspace coordinates, false to get them in pixel coordinates. - * @return {!Blockly.MetricsManager.ContainerRegion} The + * @return {!ContainerRegion} The * metrics for the content container. * @public */ @@ -139,7 +139,7 @@ IMetricsManager.prototype.getContentMetrics; * .flyoutHeight: Height of the flyout if it is always open. Otherwise zero. * .toolboxPosition: Top, bottom, left or right. Use TOOLBOX_AT constants to * compare. - * @return {!Blockly.utils.Metrics} Contains size and position metrics of a top + * @return {!Metrics} Contains size and position metrics of a top * level workspace. * @public */ From b72c07ad8decc7ec809a2e566bb9bfd524a38d4f Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 09:16:10 -0700 Subject: [PATCH 055/172] Add eslint disable for no-unused-vars to core/interfaces/i_metrics_manager.js --- core/interfaces/i_metrics_manager.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index b8cbd2231..db1f575c1 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -14,8 +14,11 @@ goog.module('Blockly.IMetricsManager'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Metrics = goog.requireType('Blockly.utils.Metrics'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); +/* eslint-disable-next-line no-unused-vars */ const {AbsoluteMetrics, ContainerRegion, ToolboxMetrics} = goog.requireType('Blockly.MetricsManager'); From 977d0f35bff7303573bb83e93e821edd4b839c8d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:21:00 -0700 Subject: [PATCH 056/172] Migrate core/icon.js to named requires --- core/icon.js | 53 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/core/icon.js b/core/icon.js index 02e6f7348..0eaf37f0b 100644 --- a/core/icon.js +++ b/core/icon.js @@ -13,27 +13,28 @@ goog.module('Blockly.Icon'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Bubble = goog.requireType('Blockly.Bubble'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const {getRelativeXY, isRightButton} = goog.require('Blockly.utils'); /** * Class for an icon. - * @param {Blockly.BlockSvg} block The block associated with this icon. + * @param {BlockSvg} block The block associated with this icon. * @constructor * @abstract */ const Icon = function(block) { /** * The block this icon is attached to. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @protected */ this.block_ = block; @@ -57,14 +58,14 @@ Icon.prototype.SIZE = 17; /** * Bubble UI (if visible). - * @type {?Blockly.Bubble} + * @type {?Bubble} * @protected */ Icon.prototype.bubble_ = null; /** * Absolute coordinate of icon's center. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @protected */ Icon.prototype.iconXY_ = null; @@ -82,17 +83,17 @@ Icon.prototype.createIcon = function() { ... */ - this.iconGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.iconGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyIconGroup'}, null); if (this.block_.isInFlyout) { - Blockly.utils.dom.addClass( + dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } this.drawIcon_(this.iconGroup_); this.block_.getSvgRoot().appendChild(this.iconGroup_); - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.iconGroup_, 'mouseup', this, this.iconClick_); this.updateEditable(); }; @@ -102,7 +103,7 @@ Icon.prototype.createIcon = function() { */ Icon.prototype.dispose = function() { // Dispose of and unlink the icon. - Blockly.utils.dom.removeNode(this.iconGroup_); + dom.removeNode(this.iconGroup_); this.iconGroup_ = null; // Dispose of and unlink the bubble. this.setVisible(false); @@ -134,7 +135,7 @@ Icon.prototype.iconClick_ = function(e) { // Drag operation is concluding. Don't open the editor. return; } - if (!this.block_.isInFlyout && !Blockly.utils.isRightButton(e)) { + if (!this.block_.isInFlyout && !isRightButton(e)) { this.setVisible(!this.isVisible()); } }; @@ -150,7 +151,7 @@ Icon.prototype.applyColour = function() { /** * Notification that the icon has moved. Update the arrow accordingly. - * @param {!Blockly.utils.Coordinate} xy Absolute location in workspace coordinates. + * @param {!Coordinate} xy Absolute location in workspace coordinates. */ Icon.prototype.setIconLocation = function(xy) { this.iconXY_ = xy; @@ -166,19 +167,19 @@ Icon.prototype.setIconLocation = function(xy) { Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. const blockXY = this.block_.getRelativeToSurfaceXY(); - const iconXY = Blockly.utils.getRelativeXY( + const iconXY = getRelativeXY( /** @type {!SVGElement} */ (this.iconGroup_)); - const newXY = new Blockly.utils.Coordinate( + const newXY = new Coordinate( blockXY.x + iconXY.x + this.SIZE / 2, blockXY.y + iconXY.y + this.SIZE / 2); - if (!Blockly.utils.Coordinate.equals(this.getIconLocation(), newXY)) { + if (!Coordinate.equals(this.getIconLocation(), newXY)) { this.setIconLocation(newXY); } }; /** * Returns the center of the block's icon relative to the surface. - * @return {?Blockly.utils.Coordinate} Object with x and y properties in + * @return {?Coordinate} Object with x and y properties in * workspace coordinates. */ Icon.prototype.getIconLocation = function() { @@ -189,11 +190,11 @@ Icon.prototype.getIconLocation = function() { * Get the size of the icon as used for rendering. * This differs from the actual size of the icon, because it bulges slightly * out of its row rather than increasing the height of its row. - * @return {!Blockly.utils.Size} Height and width. + * @return {!Size} Height and width. */ // TODO (#2562): Remove getCorrectedSize. Icon.prototype.getCorrectedSize = function() { - return new Blockly.utils.Size( + return new Size( Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; From 7175e9452bceadbf15e80e017bf00e5ffb61bb6b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:21:41 -0700 Subject: [PATCH 057/172] clang-format core/icon.js --- core/icon.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/icon.js b/core/icon.js index 0eaf37f0b..b6b8942a7 100644 --- a/core/icon.js +++ b/core/icon.js @@ -83,9 +83,8 @@ Icon.prototype.createIcon = function() { ... */ - this.iconGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyIconGroup'}, null); + this.iconGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyIconGroup'}, null); if (this.block_.isInFlyout) { dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); @@ -194,8 +193,7 @@ Icon.prototype.getIconLocation = function() { */ // TODO (#2562): Remove getCorrectedSize. Icon.prototype.getCorrectedSize = function() { - return new Size( - Icon.prototype.SIZE, Icon.prototype.SIZE - 2); + return new Size(Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; /** From 2aff67498b516c50479c51a5fbda79bd04aa0951 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:49:13 -0700 Subject: [PATCH 058/172] Migrate core/input.js to ES6 const/let --- core/input.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/input.js b/core/input.js index 443bfc83f..315570ed3 100644 --- a/core/input.js +++ b/core/input.js @@ -151,7 +151,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { * @throws {Error} if the field is not present and opt_quiet is false. */ Blockly.Input.prototype.removeField = function(name, opt_quiet) { - for (var i = 0, field; (field = this.fieldRow[i]); i++) { + for (let i = 0, field; (field = this.fieldRow[i]); i++) { if (field.name === name) { field.dispose(); this.fieldRow.splice(i, 1); @@ -189,13 +189,13 @@ Blockly.Input.prototype.setVisible = function(visible) { // Note: Currently there are only unit tests for block.setCollapsed() // because this function is package. If this function goes back to being a // public API tests (lots of tests) should be added. - var renderList = []; + let renderList = []; if (this.visible_ == visible) { return renderList; } this.visible_ = visible; - for (var y = 0, field; (field = this.fieldRow[y]); y++) { + for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.setVisible(visible); } if (this.connection) { @@ -207,7 +207,7 @@ Blockly.Input.prototype.setVisible = function(visible) { } else { this.connection.stopTrackingAll(); } - var child = this.connection.targetBlock(); + const child = this.connection.targetBlock(); if (child) { child.getSvgRoot().style.display = visible ? 'block' : 'none'; } @@ -220,7 +220,7 @@ Blockly.Input.prototype.setVisible = function(visible) { * @package */ Blockly.Input.prototype.markDirty = function() { - for (var y = 0, field; (field = this.fieldRow[y]); y++) { + for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.markDirty(); } }; @@ -285,7 +285,7 @@ Blockly.Input.prototype.init = function() { if (!this.sourceBlock_.workspace.rendered) { return; // Headless blocks don't need fields initialized. } - for (var i = 0; i < this.fieldRow.length; i++) { + for (let i = 0; i < this.fieldRow.length; i++) { this.fieldRow[i].init(); } }; @@ -295,7 +295,7 @@ Blockly.Input.prototype.init = function() { * @suppress {checkTypes} */ Blockly.Input.prototype.dispose = function() { - for (var i = 0, field; (field = this.fieldRow[i]); i++) { + for (let i = 0, field; (field = this.fieldRow[i]); i++) { field.dispose(); } if (this.connection) { From f96c14c0033b27e1a1eef0146fef5f6615283287 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:51:25 -0700 Subject: [PATCH 059/172] Migrate core/input.js to goog.module --- core/input.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/core/input.js b/core/input.js index 315570ed3..b9b277fde 100644 --- a/core/input.js +++ b/core/input.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Input'); +goog.module('Blockly.Input'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Connection'); goog.require('Blockly.fieldRegistry'); @@ -33,7 +34,7 @@ goog.requireType('Blockly.RenderedConnection'); * @param {Blockly.Connection} connection Optional connection for this input. * @constructor */ -Blockly.Input = function(type, name, block, connection) { +const Input = function(type, name, block, connection) { if (type != Blockly.inputTypes.DUMMY && !name) { throw Error('Value inputs and statement inputs must have non-empty name.'); } @@ -56,20 +57,20 @@ Blockly.Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Blockly.Input.prototype.align = Blockly.constants.ALIGN.LEFT; +Input.prototype.align = Blockly.constants.ALIGN.LEFT; /** * Is the input visible? * @type {boolean} * @private */ -Blockly.Input.prototype.visible_ = true; +Input.prototype.visible_ = true; /** * Get the source block for this input. * @return {?Blockly.Block} The source block, or null if there is none. */ -Blockly.Input.prototype.getSourceBlock = function() { +Input.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -79,9 +80,9 @@ Blockly.Input.prototype.getSourceBlock = function() { * @param {string|!Blockly.Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. - * @return {!Blockly.Input} The input being append to (to allow chaining). + * @return {!Input} The input being append to (to allow chaining). */ -Blockly.Input.prototype.appendField = function(field, opt_name) { +Input.prototype.appendField = function(field, opt_name) { this.insertFieldAt(this.fieldRow.length, field, opt_name); return this; }; @@ -95,7 +96,7 @@ Blockly.Input.prototype.appendField = function(field, opt_name) { * this field again. Should be unique to the host block. * @return {number} The index following the last inserted field. */ -Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { +Input.prototype.insertFieldAt = function(index, field, opt_name) { if (index < 0 || index > this.fieldRow.length) { throw Error('index ' + index + ' out of bounds.'); } @@ -150,7 +151,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { * and opt_quiet is true. * @throws {Error} if the field is not present and opt_quiet is false. */ -Blockly.Input.prototype.removeField = function(name, opt_quiet) { +Input.prototype.removeField = function(name, opt_quiet) { for (let i = 0, field; (field = this.fieldRow[i]); i++) { if (field.name === name) { field.dispose(); @@ -174,7 +175,7 @@ Blockly.Input.prototype.removeField = function(name, opt_quiet) { * Gets whether this input is visible or not. * @return {boolean} True if visible. */ -Blockly.Input.prototype.isVisible = function() { +Input.prototype.isVisible = function() { return this.visible_; }; @@ -185,7 +186,7 @@ Blockly.Input.prototype.isVisible = function() { * @return {!Array} List of blocks to render. * @package */ -Blockly.Input.prototype.setVisible = function(visible) { +Input.prototype.setVisible = function(visible) { // Note: Currently there are only unit tests for block.setCollapsed() // because this function is package. If this function goes back to being a // public API tests (lots of tests) should be added. @@ -219,7 +220,7 @@ Blockly.Input.prototype.setVisible = function(visible) { * Mark all fields on this input as dirty. * @package */ -Blockly.Input.prototype.markDirty = function() { +Input.prototype.markDirty = function() { for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.markDirty(); } @@ -229,9 +230,9 @@ Blockly.Input.prototype.markDirty = function() { * Change a connection's compatibility. * @param {string|Array|null} check Compatible value type or * list of value types. Null if all types are compatible. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setCheck = function(check) { +Input.prototype.setCheck = function(check) { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -243,9 +244,9 @@ Blockly.Input.prototype.setCheck = function(check) { * Change the alignment of the connection's field(s). * @param {number} align One of the values of Blockly.constants.ALIGN. * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setAlign = function(align) { +Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); @@ -257,9 +258,9 @@ Blockly.Input.prototype.setAlign = function(align) { /** * Changes the connection's shadow block. * @param {?Element} shadow DOM representation of a block or null. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setShadowDom = function(shadow) { +Input.prototype.setShadowDom = function(shadow) { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -271,7 +272,7 @@ Blockly.Input.prototype.setShadowDom = function(shadow) { * Returns the XML representation of the connection's shadow block. * @return {?Element} Shadow DOM representation of a block or null. */ -Blockly.Input.prototype.getShadowDom = function() { +Input.prototype.getShadowDom = function() { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -281,7 +282,7 @@ Blockly.Input.prototype.getShadowDom = function() { /** * Initialize the fields on this input. */ -Blockly.Input.prototype.init = function() { +Input.prototype.init = function() { if (!this.sourceBlock_.workspace.rendered) { return; // Headless blocks don't need fields initialized. } @@ -294,7 +295,7 @@ Blockly.Input.prototype.init = function() { * Sever all links to this input. * @suppress {checkTypes} */ -Blockly.Input.prototype.dispose = function() { +Input.prototype.dispose = function() { for (let i = 0, field; (field = this.fieldRow[i]); i++) { field.dispose(); } @@ -303,3 +304,5 @@ Blockly.Input.prototype.dispose = function() { } this.sourceBlock_ = null; }; + +exports = Input; From f59da974b44dcd4fd1de119ae889815e5e86ca7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:55:41 -0700 Subject: [PATCH 060/172] Migrate core/input.js to named requires --- core/input.js | 56 +++++++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/core/input.js b/core/input.js index b9b277fde..59c3b8a72 100644 --- a/core/input.js +++ b/core/input.js @@ -13,29 +13,33 @@ goog.module('Blockly.Input'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Connection'); -goog.require('Blockly.fieldRegistry'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const constants = goog.require('Blockly.constants'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const inputTypes = goog.require('Blockly.inputTypes'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); -goog.require('Blockly.inputTypes'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.RenderedConnection'); - /** * Class for an input with an optional field. * @param {number} type The type of the input. * @param {string} name Language-neutral identifier which may used to find this * input again. - * @param {!Blockly.Block} block The block containing this input. - * @param {Blockly.Connection} connection Optional connection for this input. + * @param {!Block} block The block containing this input. + * @param {Connection} connection Optional connection for this input. * @constructor */ const Input = function(type, name, block, connection) { - if (type != Blockly.inputTypes.DUMMY && !name) { + if (type != inputTypes.DUMMY && !name) { throw Error('Value inputs and statement inputs must have non-empty name.'); } /** @type {number} */ @@ -43,13 +47,13 @@ const Input = function(type, name, block, connection) { /** @type {string} */ this.name = name; /** - * @type {!Blockly.Block} + * @type {!Block} * @private */ this.sourceBlock_ = block; - /** @type {Blockly.Connection} */ + /** @type {Connection} */ this.connection = connection; - /** @type {!Array} */ + /** @type {!Array} */ this.fieldRow = []; }; @@ -57,7 +61,7 @@ const Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Input.prototype.align = Blockly.constants.ALIGN.LEFT; +Input.prototype.align = constants.ALIGN.LEFT; /** * Is the input visible? @@ -68,7 +72,7 @@ Input.prototype.visible_ = true; /** * Get the source block for this input. - * @return {?Blockly.Block} The source block, or null if there is none. + * @return {?Block} The source block, or null if there is none. */ Input.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -77,7 +81,7 @@ Input.prototype.getSourceBlock = function() { /** * Add a field (or label from string), and all prefix and suffix fields, to the * end of the input's field row. - * @param {string|!Blockly.Field} field Something to add as a field. + * @param {string|!Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. * @return {!Input} The input being append to (to allow chaining). @@ -91,7 +95,7 @@ Input.prototype.appendField = function(field, opt_name) { * Inserts a field (or label from string), and all prefix and suffix fields, at * the location of the input's field row. * @param {number} index The index at which to insert field. - * @param {string|!Blockly.Field} field Something to add as a field. + * @param {string|!Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. * @return {number} The index following the last inserted field. @@ -108,7 +112,7 @@ Input.prototype.insertFieldAt = function(index, field, opt_name) { // Generate a FieldLabel when given a plain text field. if (typeof field == 'string') { - field = /** @type {!Blockly.Field} **/ (Blockly.fieldRegistry.fromJson({ + field = /** @type {!Field} **/ (fieldRegistry.fromJson({ 'type': 'field_label', 'text': field, })); @@ -135,7 +139,7 @@ Input.prototype.insertFieldAt = function(index, field, opt_name) { } if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Adding a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -157,7 +161,7 @@ Input.prototype.removeField = function(name, opt_quiet) { field.dispose(); this.fieldRow.splice(i, 1); if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Removing a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -183,7 +187,7 @@ Input.prototype.isVisible = function() { * Sets whether this input is visible or not. * Should only be used to collapse/uncollapse a block. * @param {boolean} visible True if visible. - * @return {!Array} List of blocks to render. + * @return {!Array} List of blocks to render. * @package */ Input.prototype.setVisible = function(visible) { @@ -201,7 +205,7 @@ Input.prototype.setVisible = function(visible) { } if (this.connection) { this.connection = - /** @type {!Blockly.RenderedConnection} */ (this.connection); + /** @type {!RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll(); @@ -242,14 +246,14 @@ Input.prototype.setCheck = function(check) { /** * Change the alignment of the connection's field(s). - * @param {number} align One of the values of Blockly.constants.ALIGN. + * @param {number} align One of the values of constants.ALIGN. * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. * @return {!Input} The input being modified (to allow chaining). */ Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); } return this; diff --git a/tests/deps.js b/tests/deps.js index f62333982..1cda35a7e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -70,7 +70,7 @@ goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.Block goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); From 761eec2b69dd20638171cf7a75302d1a79a89e3b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:56:17 -0700 Subject: [PATCH 061/172] clang-format core/input.js --- core/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/input.js b/core/input.js index 59c3b8a72..afa7a3358 100644 --- a/core/input.js +++ b/core/input.js @@ -205,7 +205,7 @@ Input.prototype.setVisible = function(visible) { } if (this.connection) { this.connection = - /** @type {!RenderedConnection} */ (this.connection); + /** @type {!RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll(); From fc10f9e62551d7a5e13841f6ce3fab0751705322 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 07:57:49 -0700 Subject: [PATCH 062/172] Migrate core/block_dragger.js to ES6 const/let --- core/block_dragger.js | 53 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index a1d4b6f2d..d51eead48 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -116,12 +116,13 @@ Blockly.BlockDragger.prototype.dispose = function() { */ Blockly.BlockDragger.initIconData_ = function(block) { // Build a list of icons that need to be moved and where they started. - var dragIconData = []; - var descendants = block.getDescendants(false); - for (var i = 0, descendant; (descendant = descendants[i]); i++) { - var icons = descendant.getIcons(); - for (var j = 0; j < icons.length; j++) { - var data = { + const dragIconData = []; + const descendants = block.getDescendants(false); + + for (let i = 0, descendant; (descendant = descendants[i]); i++) { + const icons = descendant.getIcons(); + for (let j = 0; j < icons.length; j++) { + const data = { // Blockly.utils.Coordinate with x and y properties (workspace // coordinates). location: icons[j].getIconLocation(), @@ -198,8 +199,8 @@ Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { Blockly.BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); - var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); + const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBlock_.translate(newLoc.x, newLoc.y); Blockly.blockAnimations.disconnectUiEffect(this.draggingBlock_); @@ -211,7 +212,7 @@ Blockly.BlockDragger.prototype.disconnectBlock_ = function( * @protected */ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { - var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -225,16 +226,16 @@ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { * @public */ Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { - var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); + const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBlock_.moveDuringDrag(newLoc); this.dragIcons_(delta); - var oldDragTarget = this.dragTarget_; + const oldDragTarget = this.dragTarget_; this.dragTarget_ = this.workspace_.getDragTarget(e); this.draggedConnectionManager_.update(delta, this.dragTarget_); - var oldWouldDeleteBlock = this.wouldDeleteBlock_; + const oldWouldDeleteBlock = this.wouldDeleteBlock_; this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock(); if (oldWouldDeleteBlock != this.wouldDeleteBlock_) { // Prevent unnecessary add/remove class calls. @@ -267,12 +268,12 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { Blockly.blockAnimations.disconnectUiStop(); - var preventMove = !!this.dragTarget_ && + const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); if (preventMove) { var newLoc = this.startXY_; } else { - var newValues = this.getNewLocationAfterDrag_(currentDragDeltaXY); + const newValues = this.getNewLocationAfterDrag_(currentDragDeltaXY); var delta = newValues.delta; var newLoc = newValues.newLocation; } @@ -282,7 +283,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragTarget_.onDrop(this.draggingBlock_); } - var deleted = this.maybeDeleteBlock_(); + const deleted = this.maybeDeleteBlock_(); if (!deleted) { // These are expensive and don't need to be done if we're deleting. this.draggingBlock_.setDragging(false); @@ -314,7 +315,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { */ Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( currentDragDeltaXY) { - var newValues = {}; + const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); newValues.newLocation = Blockly.utils.Coordinate.sum(this.startXY_, newValues.delta); @@ -362,7 +363,7 @@ Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { - var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -375,11 +376,11 @@ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { * @protected */ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { - var toolbox = this.workspace_.getToolbox(); + const toolbox = this.workspace_.getToolbox(); if (toolbox) { - var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : - 'blocklyToolboxGrab'; + const style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : + 'blocklyToolboxGrab'; if (isEnd && typeof toolbox.removeStyle == 'function') { toolbox.removeStyle(style); @@ -395,7 +396,7 @@ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { - var event = + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); @@ -423,7 +424,7 @@ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { * @protected */ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { - var result = new Blockly.utils.Coordinate( + const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); if (this.workspace_.isMutator) { @@ -431,7 +432,7 @@ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { // oddities in our rendering optimizations. The actual scale is the same as // the scale on the parent workspace. // Fix that for dragging. - var mainScale = this.workspace_.options.parentWorkspace.scale; + const mainScale = this.workspace_.options.parentWorkspace.scale; result.scale(1 / mainScale); } return result; @@ -445,8 +446,8 @@ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { */ Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. - for (var i = 0; i < this.dragIconData_.length; i++) { - var data = this.dragIconData_[i]; + for (let i = 0; i < this.dragIconData_.length; i++) { + const data = this.dragIconData_[i]; data.icon.setIconLocation(Blockly.utils.Coordinate.sum(data.location, dxy)); } }; From 4850ad0300f5293bbe37511e52cda6853126a662 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:08:31 -0700 Subject: [PATCH 063/172] Migrate core/block_dragger.js to goog.module --- core/block_dragger.js | 48 ++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index d51eead48..ee103f81b 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.BlockDragger'); +goog.module('Blockly.BlockDragger'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockAnimations'); /** @suppress {extraRequire} */ @@ -39,7 +40,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @implements {Blockly.IBlockDragger} */ -Blockly.BlockDragger = function(block, workspace) { +const BlockDragger = function(block, workspace) { /** * The top block in the stack that is being dragged. * @type {!Blockly.BlockSvg} @@ -91,14 +92,14 @@ Blockly.BlockDragger = function(block, workspace) { * @type {Array} * @protected */ - this.dragIconData_ = Blockly.BlockDragger.initIconData_(block); + this.dragIconData_ = initIconData(block); }; /** * Sever all links from this object. * @package */ -Blockly.BlockDragger.prototype.dispose = function() { +BlockDragger.prototype.dispose = function() { this.dragIconData_.length = 0; if (this.draggedConnectionManager_) { @@ -112,9 +113,8 @@ Blockly.BlockDragger.prototype.dispose = function() { * extends from it if that bubble is open. * @param {!Blockly.BlockSvg} block The root block that is being dragged. * @return {!Array} The list of all icons and their locations. - * @private */ -Blockly.BlockDragger.initIconData_ = function(block) { +const initIconData = function(block) { // Build a list of icons that need to be moved and where they started. const dragIconData = []; const descendants = block.getDescendants(false); @@ -143,7 +143,7 @@ Blockly.BlockDragger.initIconData_ = function(block) { * disconnecting. * @public */ -Blockly.BlockDragger.prototype.startDrag = function( +BlockDragger.prototype.startDrag = function( currentDragDeltaXY, healStack) { if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); @@ -181,7 +181,7 @@ Blockly.BlockDragger.prototype.startDrag = function( * @return {boolean} True to disconnect the block, false otherwise. * @protected */ -Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { +BlockDragger.prototype.shouldDisconnect_ = function(healStack) { return !!( this.draggingBlock_.getParent() || (healStack && this.draggingBlock_.nextConnection && @@ -196,7 +196,7 @@ Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { * moved from the position at mouse down, in pixel units. * @protected */ -Blockly.BlockDragger.prototype.disconnectBlock_ = function( +BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); @@ -211,7 +211,7 @@ Blockly.BlockDragger.prototype.disconnectBlock_ = function( * Fire a UI event at the start of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { +BlockDragger.prototype.fireDragStartEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); @@ -225,7 +225,7 @@ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { * moved from the position at the start of the drag, in pixel units. * @public */ -Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { +BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBlock_.moveDuringDrag(newLoc); @@ -258,7 +258,7 @@ Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { * moved from the position at the start of the drag, in pixel units. * @public */ -Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { +BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { // Make sure internal state is fresh. this.drag(e, currentDragDeltaXY); this.dragIconData_ = []; @@ -313,7 +313,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { * end up. * @protected */ -Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( +BlockDragger.prototype.getNewLocationAfterDrag_ = function( currentDragDeltaXY) { const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); @@ -329,7 +329,7 @@ Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( * @return {boolean} True if the block was deleted. * @protected */ -Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() { +BlockDragger.prototype.maybeDeleteBlock_ = function() { if (this.wouldDeleteBlock_) { // Fire a move event, so we know where to go back to for an undo. this.fireMoveEvent_(); @@ -346,7 +346,7 @@ Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() { * the block started the drag to where it ended the drag. * @protected */ -Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { +BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { this.draggingBlock_.moveConnections(delta.x, delta.y); this.fireMoveEvent_(); if (this.draggedConnectionManager_.wouldConnectBlock()) { @@ -362,7 +362,7 @@ Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * Fire a UI event at the end of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { +BlockDragger.prototype.fireDragEndEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); @@ -375,7 +375,7 @@ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { * @param {boolean} isEnd True if we are at the end of a drag, false otherwise. * @protected */ -Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { +BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { const toolbox = this.workspace_.getToolbox(); if (toolbox) { @@ -395,7 +395,7 @@ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * Fire a move event at the end of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { +BlockDragger.prototype.fireMoveEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; @@ -408,7 +408,7 @@ Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { * dragging block would be deleted if released immediately. * @protected */ -Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { +BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { this.draggingBlock_.setDeleteStyle(this.wouldDeleteBlock_); }; @@ -423,7 +423,7 @@ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { * workspace scale. * @protected */ -Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { +BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); @@ -444,7 +444,7 @@ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { * original positions, in workspace units. * @protected */ -Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { +BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. for (let i = 0; i < this.dragIconData_.length; i++) { const data = this.dragIconData_[i]; @@ -459,7 +459,7 @@ Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { * marker blocks. * @public */ -Blockly.BlockDragger.prototype.getInsertionMarkers = function() { +BlockDragger.prototype.getInsertionMarkers = function() { // No insertion markers with the old style of dragged connection managers. if (this.draggedConnectionManager_ && this.draggedConnectionManager_.getInsertionMarkers) { @@ -470,4 +470,6 @@ Blockly.BlockDragger.prototype.getInsertionMarkers = function() { Blockly.registry.register( Blockly.registry.Type.BLOCK_DRAGGER, Blockly.registry.DEFAULT, - Blockly.BlockDragger); + BlockDragger); + +exports = BlockDragger; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..b268b88c1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -10,7 +10,7 @@ goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.Vari goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); From 873b75e58a8560506daf39f06c9ed19ddbe3a62f Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:15:10 -0700 Subject: [PATCH 064/172] Migrate core/block_dragger.js named requires --- core/block_dragger.js | 109 +++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index ee103f81b..40436a4e1 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,59 +13,58 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockAnimations'); +const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.Events'); +const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -goog.require('Blockly.IBlockDragger'); -goog.require('Blockly.InsertionMarkerManager'); -goog.require('Blockly.registry'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.IDragTarget'); -goog.requireType('Blockly.WorkspaceSvg'); +const IBlockDragger = goog.require('Blockly.IBlockDragger'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +const {DEFAULT, Type, register} = goog.require('Blockly.registry'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** * Class for a block dragger. It moves blocks around the workspace when they * are being dragged by a mouse or touch. - * @param {!Blockly.BlockSvg} block The block to drag. - * @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on. + * @param {!BlockSvg} block The block to drag. + * @param {!WorkspaceSvg} workspace The workspace to drag on. * @constructor - * @implements {Blockly.IBlockDragger} + * @implements {IBlockDragger} */ const BlockDragger = function(block, workspace) { /** * The top block in the stack that is being dragged. - * @type {!Blockly.BlockSvg} + * @type {!BlockSvg} * @protected */ this.draggingBlock_ = block; /** * The workspace on which the block is being dragged. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @protected */ this.workspace_ = workspace; /** * Object that keeps track of connections on dragged blocks. - * @type {!Blockly.InsertionMarkerManager} + * @type {!InsertionMarkerManager} * @protected */ this.draggedConnectionManager_ = - new Blockly.InsertionMarkerManager(this.draggingBlock_); + new InsertionMarkerManager(this.draggingBlock_); /** * Which drag area the mouse pointer is over, if any. - * @type {?Blockly.IDragTarget} + * @type {?IDragTarget} * @private */ this.dragTarget_ = null; @@ -80,7 +79,7 @@ const BlockDragger = function(block, workspace) { /** * The location of the top left corner of the dragging block at the beginning * of the drag in workspace coordinates. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @protected */ this.startXY_ = this.draggingBlock_.getRelativeToSurfaceXY(); @@ -111,7 +110,7 @@ BlockDragger.prototype.dispose = function() { * Make a list of all of the icons (comment, warning, and mutator) that are * on this block and its descendants. Moving an icon moves the bubble that * extends from it if that bubble is open. - * @param {!Blockly.BlockSvg} block The root block that is being dragged. + * @param {!BlockSvg} block The root block that is being dragged. * @return {!Array} The list of all icons and their locations. */ const initIconData = function(block) { @@ -123,7 +122,7 @@ const initIconData = function(block) { const icons = descendant.getIcons(); for (let j = 0; j < icons.length; j++) { const data = { - // Blockly.utils.Coordinate with x and y properties (workspace + // Coordinate with x and y properties (workspace // coordinates). location: icons[j].getIconLocation(), // Blockly.Icon @@ -137,7 +136,7 @@ const initIconData = function(block) { /** * Start dragging a block. This includes moving it to the drag surface. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. @@ -145,8 +144,8 @@ const initIconData = function(block) { */ BlockDragger.prototype.startDrag = function( currentDragDeltaXY, healStack) { - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!getGroup()) { + setGroup(true); } this.fireDragStartEvent_(); @@ -160,9 +159,9 @@ BlockDragger.prototype.startDrag = function( // During a drag there may be a lot of rerenders, but not field changes. // Turn the cache on so we don't do spurious remeasures during the drag. - Blockly.utils.dom.startTextWidthCache(); + startTextWidthCache(); this.workspace_.setResizesEnabled(false); - Blockly.blockAnimations.disconnectUiStop(); + disconnectUiStop(); if (this.shouldDisconnect_(healStack)) { this.disconnectBlock_(healStack, currentDragDeltaXY); @@ -192,7 +191,7 @@ BlockDragger.prototype.shouldDisconnect_ = function(healStack) { * Disconnects the block and moves it to a new location. * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @protected */ @@ -200,10 +199,10 @@ BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBlock_.translate(newLoc.x, newLoc.y); - Blockly.blockAnimations.disconnectUiEffect(this.draggingBlock_); + disconnectUiEffect(this.draggingBlock_); this.draggedConnectionManager_.updateAvailableConnections(); }; @@ -212,22 +211,22 @@ BlockDragger.prototype.disconnectBlock_ = function( * @protected */ BlockDragger.prototype.fireDragStartEvent_ = function() { - const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (get(BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); - Blockly.Events.fire(event); + fire(event); }; /** * Execute a step of block dragging, based on the given event. Update the * display accordingly. * @param {!Event} e The most recent move event. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. * @public */ BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBlock_.moveDuringDrag(newLoc); this.dragIcons_(delta); @@ -254,7 +253,7 @@ BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { /** * Finish a block drag and put the block back on the workspace. * @param {!Event} e The mouseup/touchend event. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. * @public */ @@ -264,9 +263,9 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragIconData_ = []; this.fireDragEndEvent_(); - Blockly.utils.dom.stopTextWidthCache(); + stopTextWidthCache(); - Blockly.blockAnimations.disconnectUiStop(); + disconnectUiStop(); const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); @@ -300,15 +299,15 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { } this.workspace_.setResizesEnabled(true); - Blockly.Events.setGroup(false); + setGroup(false); }; /** * Calculates the drag delta and new location values after a block is dragged. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the start of the drag, in pixel units. - * @return {{delta: !Blockly.utils.Coordinate, newLocation: - * !Blockly.utils.Coordinate}} New location after drag. delta is in + * @return {{delta: !Coordinate, newLocation: + * !Coordinate}} New location after drag. delta is in * workspace units. newLocation is the new coordinate where the block should * end up. * @protected @@ -318,7 +317,7 @@ BlockDragger.prototype.getNewLocationAfterDrag_ = function( const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); newValues.newLocation = - Blockly.utils.Coordinate.sum(this.startXY_, newValues.delta); + Coordinate.sum(this.startXY_, newValues.delta); return newValues; }; @@ -342,7 +341,7 @@ BlockDragger.prototype.maybeDeleteBlock_ = function() { /** * Updates the necessary information to place a block at a certain location. - * @param {!Blockly.utils.Coordinate} delta The change in location from where + * @param {!Coordinate} delta The change in location from where * the block started the drag to where it ended the drag. * @protected */ @@ -363,9 +362,9 @@ BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ BlockDragger.prototype.fireDragEndEvent_ = function() { - const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (get(BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); - Blockly.Events.fire(event); + fire(event); }; /** @@ -397,10 +396,10 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { */ BlockDragger.prototype.fireMoveEvent_ = function() { const event = - new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); + new (get(BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); - Blockly.Events.fire(event); + fire(event); }; /** @@ -417,14 +416,14 @@ BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { * correction for mutator workspaces. * This function does not consider differing origins. It simply scales the * input's x and y values. - * @param {!Blockly.utils.Coordinate} pixelCoord A coordinate with x and y + * @param {!Coordinate} pixelCoord A coordinate with x and y * values in CSS pixel units. - * @return {!Blockly.utils.Coordinate} The input coordinate divided by the + * @return {!Coordinate} The input coordinate divided by the * workspace scale. * @protected */ BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { - const result = new Blockly.utils.Coordinate( + const result = new Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); if (this.workspace_.isMutator) { @@ -440,7 +439,7 @@ BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { /** * Move all of the icons connected to this drag. - * @param {!Blockly.utils.Coordinate} dxy How far to move the icons from their + * @param {!Coordinate} dxy How far to move the icons from their * original positions, in workspace units. * @protected */ @@ -448,14 +447,14 @@ BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. for (let i = 0; i < this.dragIconData_.length; i++) { const data = this.dragIconData_[i]; - data.icon.setIconLocation(Blockly.utils.Coordinate.sum(data.location, dxy)); + data.icon.setIconLocation(Coordinate.sum(data.location, dxy)); } }; /** * Get a list of the insertion markers that currently exist. Drags have 0, 1, * or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion + * @return {!Array} A possibly empty list of insertion * marker blocks. * @public */ @@ -468,8 +467,8 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -Blockly.registry.register( - Blockly.registry.Type.BLOCK_DRAGGER, Blockly.registry.DEFAULT, +register( + Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); exports = BlockDragger; From 848ec34a0aef90bafe46c2cbee9b5f761d002f99 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:16:19 -0700 Subject: [PATCH 065/172] clang-format core/block_dragger.js --- core/block_dragger.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 40436a4e1..e97457d22 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -142,8 +142,7 @@ const initIconData = function(block) { * disconnecting. * @public */ -BlockDragger.prototype.startDrag = function( - currentDragDeltaXY, healStack) { +BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { if (!getGroup()) { setGroup(true); } @@ -182,7 +181,7 @@ BlockDragger.prototype.startDrag = function( */ BlockDragger.prototype.shouldDisconnect_ = function(healStack) { return !!( - this.draggingBlock_.getParent() || + this.draggingBlock_.getParent() || (healStack && this.draggingBlock_.nextConnection && this.draggingBlock_.nextConnection.targetBlock())); }; @@ -312,12 +311,10 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { * end up. * @protected */ -BlockDragger.prototype.getNewLocationAfterDrag_ = function( - currentDragDeltaXY) { +BlockDragger.prototype.getNewLocationAfterDrag_ = function(currentDragDeltaXY) { const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - newValues.newLocation = - Coordinate.sum(this.startXY_, newValues.delta); + newValues.newLocation = Coordinate.sum(this.startXY_, newValues.delta); return newValues; }; @@ -379,7 +376,7 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { if (toolbox) { const style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : - 'blocklyToolboxGrab'; + 'blocklyToolboxGrab'; if (isEnd && typeof toolbox.removeStyle == 'function') { toolbox.removeStyle(style); @@ -395,8 +392,7 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ BlockDragger.prototype.fireMoveEvent_ = function() { - const event = - new (get(BLOCK_MOVE))(this.draggingBlock_); + const event = new (get(BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); fire(event); @@ -467,8 +463,6 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -register( - Type.BLOCK_DRAGGER, DEFAULT, - BlockDragger); +register(Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); exports = BlockDragger; From c838b0e27c158e72810250442e119fffedf8f223 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:23:28 -0700 Subject: [PATCH 066/172] Reorder requires --- core/block_dragger.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index e97457d22..20c619cbc 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,22 +13,22 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); -const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const IBlockDragger = goog.require('Blockly.IBlockDragger'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); +const {DEFAULT, Type, register} = goog.require('Blockly.registry'); +const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); +const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -const IBlockDragger = goog.require('Blockly.IBlockDragger'); -const IDragTarget = goog.requireType('Blockly.IDragTarget'); -const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); -const {DEFAULT, Type, register} = goog.require('Blockly.registry'); -const Coordinate = goog.require('Blockly.utils.Coordinate'); -const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); -const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** From 2688329aefdc7b5501a1d77aa688ec842d0923bf Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 23 Jul 2021 12:12:59 -0700 Subject: [PATCH 067/172] Fix imports --- core/block_dragger.js | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 20c619cbc..5c3ff6916 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,16 +13,20 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IBlockDragger = goog.require('Blockly.IBlockDragger'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); -const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); -const {DEFAULT, Type, register} = goog.require('Blockly.registry'); -const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); -const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); +const blockAnimation = goog.require('Blockly.blockAnimations'); +const dom = goog.require('Blockly.utils.dom'); +const events = goog.require('Blockly.Events'); +const registry = goog.require('Blockly.registry'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); /** @suppress {extraRequire} */ @@ -143,8 +147,8 @@ const initIconData = function(block) { * @public */ BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { - if (!getGroup()) { - setGroup(true); + if (!events.getGroup()) { + events.setGroup(true); } this.fireDragStartEvent_(); @@ -158,9 +162,9 @@ BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { // During a drag there may be a lot of rerenders, but not field changes. // Turn the cache on so we don't do spurious remeasures during the drag. - startTextWidthCache(); + dom.startTextWidthCache(); this.workspace_.setResizesEnabled(false); - disconnectUiStop(); + blockAnimation.disconnectUiStop(); if (this.shouldDisconnect_(healStack)) { this.disconnectBlock_(healStack, currentDragDeltaXY); @@ -201,7 +205,7 @@ BlockDragger.prototype.disconnectBlock_ = function( const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBlock_.translate(newLoc.x, newLoc.y); - disconnectUiEffect(this.draggingBlock_); + blockAnimation.disconnectUiEffect(this.draggingBlock_); this.draggedConnectionManager_.updateAvailableConnections(); }; @@ -210,9 +214,9 @@ BlockDragger.prototype.disconnectBlock_ = function( * @protected */ BlockDragger.prototype.fireDragStartEvent_ = function() { - const event = new (get(BLOCK_DRAG))( + const event = new (events.get(events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); - fire(event); + events.fire(event); }; /** @@ -262,9 +266,9 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragIconData_ = []; this.fireDragEndEvent_(); - stopTextWidthCache(); + dom.stopTextWidthCache(); - disconnectUiStop(); + blockAnimation.disconnectUiStop(); const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); @@ -298,7 +302,7 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { } this.workspace_.setResizesEnabled(true); - setGroup(false); + events.setGroup(false); }; /** @@ -359,9 +363,9 @@ BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ BlockDragger.prototype.fireDragEndEvent_ = function() { - const event = new (get(BLOCK_DRAG))( + const event = new (events.get(events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); - fire(event); + events.fire(event); }; /** @@ -392,10 +396,10 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ BlockDragger.prototype.fireMoveEvent_ = function() { - const event = new (get(BLOCK_MOVE))(this.draggingBlock_); + const event = new (events.get(events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); - fire(event); + events.fire(event); }; /** @@ -463,6 +467,6 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -register(Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); +registry.register(registry.Type.BLOCK_DRAGGER, registry.DEFAULT, BlockDragger); exports = BlockDragger; From f88320770c7d6e045279916b537eabcdc3345aa7 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 23 Jul 2021 12:16:00 -0700 Subject: [PATCH 068/172] Remove unnecessary require --- core/block_dragger.js | 2 -- tests/deps.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 5c3ff6916..b7c11e8a3 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -28,8 +28,6 @@ const dom = goog.require('Blockly.utils.dom'); const events = goog.require('Blockly.Events'); const registry = goog.require('Blockly.registry'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -/** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); diff --git a/tests/deps.js b/tests/deps.js index b268b88c1..42191e253 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -10,7 +10,7 @@ goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.Vari goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); From 6649619f120e5c8a98c1e581a2a32e87f61269fd Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 12:47:55 -0700 Subject: [PATCH 069/172] Convert Blockly.Block from require to requireType --- core/generator.js | 2 +- tests/deps.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/generator.js b/core/generator.js index 8e71fb040..112c2f8a1 100644 --- a/core/generator.js +++ b/core/generator.js @@ -15,7 +15,7 @@ goog.module('Blockly.Generator'); goog.module.declareLegacyNamespace(); /* eslint-disable-next-line no-unused-vars */ -const Block = goog.require('Blockly.Block'); +const Block = goog.requireType('Blockly.Block'); /* eslint-disable-next-line no-unused-vars */ const Names = goog.requireType('Blockly.Names'); /* eslint-disable-next-line no-unused-vars */ diff --git a/tests/deps.js b/tests/deps.js index c40db7cbc..94b646890 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 35673a79e12376c4beacd1223591c230f2c3ea34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 13:02:15 -0700 Subject: [PATCH 070/172] Remove unused Block.Block require --- core/flyout_horizontal.js | 2 -- tests/deps.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 9bfc8aa91..7f1ad72fd 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -26,8 +26,6 @@ const registry = goog.require('Blockly.registry'); const {Position} = goog.require('Blockly.utils.toolbox'); const {getScrollDeltaPixels} = goog.require('Blockly.utils'); const {inherits} = goog.require('Blockly.utils.object'); -/** @suppress {extraRequire} */ -goog.require('Blockly.Block'); /** diff --git a/tests/deps.js b/tests/deps.js index 87600526f..a5e2310db 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -63,7 +63,7 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); From a5c486e5717215fa4fe83ca64988f22c4149b622 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 13:09:48 -0700 Subject: [PATCH 071/172] Made icon size field const --- core/icon.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/icon.js b/core/icon.js index b6b8942a7..69ff3ef37 100644 --- a/core/icon.js +++ b/core/icon.js @@ -53,6 +53,7 @@ Icon.prototype.collapseHidden = true; /** * Height and width of icons. + * @const */ Icon.prototype.SIZE = 17; From 808ec6a5d3c6069c28e9751e369c224df1cbfcc0 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:29:05 -0700 Subject: [PATCH 072/172] Migrate core/marker_manager.js to ES6 const/let --- core/marker_manager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 82c149052..3d3c64bbb 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -81,7 +81,7 @@ Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { * @param {string} id The ID of the marker to unregister. */ Blockly.MarkerManager.prototype.unregisterMarker = function(id) { - var marker = this.markers_[id]; + const marker = this.markers_[id]; if (marker) { marker.dispose(); delete this.markers_[id]; @@ -119,7 +119,7 @@ Blockly.MarkerManager.prototype.setCursor = function(cursor) { } this.cursor_ = cursor; if (this.cursor_) { - var drawer = this.workspace_.getRenderer() + const drawer = this.workspace_.getRenderer() .makeMarkerDrawer(this.workspace_, this.cursor_); this.cursor_.setDrawer(drawer); this.setCursorSvg(this.cursor_.getDrawer().createDom()); @@ -180,8 +180,8 @@ Blockly.MarkerManager.prototype.updateMarkers = function() { * @package */ Blockly.MarkerManager.prototype.dispose = function() { - var markerIds = Object.keys(this.markers_); - for (var i = 0, markerId; (markerId = markerIds[i]); i++) { + const markerIds = Object.keys(this.markers_); + for (let i = 0, markerId; (markerId = markerIds[i]); i++) { this.unregisterMarker(markerId); } this.markers_ = null; From df794d7e3a47acec6fe91ed278ea99fbcb2652ab Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:31:10 -0700 Subject: [PATCH 073/172] Migrate core/marker_manager.js to goog.module --- core/marker_manager.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 3d3c64bbb..59bc64b7a 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.MarkerManager'); +goog.module('Blockly.MarkerManager'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Cursor'); goog.require('Blockly.Marker'); @@ -24,7 +25,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -Blockly.MarkerManager = function(workspace){ +const MarkerManager = function(workspace){ /** * The cursor. * @type {?Blockly.Cursor} @@ -59,14 +60,14 @@ Blockly.MarkerManager = function(workspace){ * @type {string} * @const */ -Blockly.MarkerManager.LOCAL_MARKER = 'local_marker_1'; +MarkerManager.LOCAL_MARKER = 'local_marker_1'; /** * Register the marker by adding it to the map of markers. * @param {string} id A unique identifier for the marker. * @param {!Blockly.Marker} marker The marker to register. */ -Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { +MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { this.unregisterMarker(id); } @@ -80,7 +81,7 @@ Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { * Unregister the marker by removing it from the map of markers. * @param {string} id The ID of the marker to unregister. */ -Blockly.MarkerManager.prototype.unregisterMarker = function(id) { +MarkerManager.prototype.unregisterMarker = function(id) { const marker = this.markers_[id]; if (marker) { marker.dispose(); @@ -95,7 +96,7 @@ Blockly.MarkerManager.prototype.unregisterMarker = function(id) { * Get the cursor for the workspace. * @return {?Blockly.Cursor} The cursor for this workspace. */ -Blockly.MarkerManager.prototype.getCursor = function() { +MarkerManager.prototype.getCursor = function() { return this.cursor_; }; @@ -105,7 +106,7 @@ Blockly.MarkerManager.prototype.getCursor = function() { * @return {?Blockly.Marker} The marker that corresponds to the given ID, * or null if none exists. */ -Blockly.MarkerManager.prototype.getMarker = function(id) { +MarkerManager.prototype.getMarker = function(id) { return this.markers_[id] || null; }; @@ -113,7 +114,7 @@ Blockly.MarkerManager.prototype.getMarker = function(id) { * Sets the cursor and initializes the drawer for use with keyboard navigation. * @param {Blockly.Cursor} cursor The cursor used to move around this workspace. */ -Blockly.MarkerManager.prototype.setCursor = function(cursor) { +MarkerManager.prototype.setCursor = function(cursor) { if (this.cursor_ && this.cursor_.getDrawer()) { this.cursor_.getDrawer().dispose(); } @@ -132,7 +133,7 @@ Blockly.MarkerManager.prototype.setCursor = function(cursor) { * workspace SVG group. * @package */ -Blockly.MarkerManager.prototype.setCursorSvg = function(cursorSvg) { +MarkerManager.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg_ = null; return; @@ -148,7 +149,7 @@ Blockly.MarkerManager.prototype.setCursorSvg = function(cursorSvg) { * workspace SVG group. * @package */ -Blockly.MarkerManager.prototype.setMarkerSvg = function(markerSvg) { +MarkerManager.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg_ = null; return; @@ -167,7 +168,7 @@ Blockly.MarkerManager.prototype.setMarkerSvg = function(markerSvg) { * Redraw the attached cursor SVG if needed. * @package */ -Blockly.MarkerManager.prototype.updateMarkers = function() { +MarkerManager.prototype.updateMarkers = function() { if (this.workspace_.keyboardAccessibilityMode && this.cursorSvg_) { this.workspace_.getCursor().draw(); } @@ -179,7 +180,7 @@ Blockly.MarkerManager.prototype.updateMarkers = function() { * @suppress {checkTypes} * @package */ -Blockly.MarkerManager.prototype.dispose = function() { +MarkerManager.prototype.dispose = function() { const markerIds = Object.keys(this.markers_); for (let i = 0, markerId; (markerId = markerIds[i]); i++) { this.unregisterMarker(markerId); @@ -190,3 +191,5 @@ Blockly.MarkerManager.prototype.dispose = function() { this.cursor_ = null; } }; + +exports = MarkerManager; From 608a4fd9f1906f99704751d457f578688cbf92de Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:34:01 -0700 Subject: [PATCH 074/172] Migrate core/marker_manager.js to named requires --- core/marker_manager.js | 26 ++++++++++++++------------ tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 59bc64b7a..b2d5c2bd5 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -13,22 +13,24 @@ goog.module('Blockly.MarkerManager'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Cursor'); -goog.require('Blockly.Marker'); - -goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Cursor = goog.requireType('Blockly.Cursor'); +/* eslint-disable-next-line no-unused-vars */ +const Marker = goog.requireType('Blockly.Marker'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** * Class to manage the multiple markers and the cursor on a workspace. - * @param {!Blockly.WorkspaceSvg} workspace The workspace for the marker manager. + * @param {!WorkspaceSvg} workspace The workspace for the marker manager. * @constructor * @package */ const MarkerManager = function(workspace){ /** * The cursor. - * @type {?Blockly.Cursor} + * @type {?Cursor} * @private */ this.cursor_ = null; @@ -42,14 +44,14 @@ const MarkerManager = function(workspace){ /** * The map of markers for the workspace. - * @type {!Object} + * @type {!Object} * @private */ this.markers_ = Object.create(null); /** * The workspace this marker manager is associated with. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; @@ -65,7 +67,7 @@ MarkerManager.LOCAL_MARKER = 'local_marker_1'; /** * Register the marker by adding it to the map of markers. * @param {string} id A unique identifier for the marker. - * @param {!Blockly.Marker} marker The marker to register. + * @param {!Marker} marker The marker to register. */ MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { @@ -94,7 +96,7 @@ MarkerManager.prototype.unregisterMarker = function(id) { /** * Get the cursor for the workspace. - * @return {?Blockly.Cursor} The cursor for this workspace. + * @return {?Cursor} The cursor for this workspace. */ MarkerManager.prototype.getCursor = function() { return this.cursor_; @@ -103,7 +105,7 @@ MarkerManager.prototype.getCursor = function() { /** * Get a single marker that corresponds to the given ID. * @param {string} id A unique identifier for the marker. - * @return {?Blockly.Marker} The marker that corresponds to the given ID, + * @return {?Marker} The marker that corresponds to the given ID, * or null if none exists. */ MarkerManager.prototype.getMarker = function(id) { @@ -112,7 +114,7 @@ MarkerManager.prototype.getMarker = function(id) { /** * Sets the cursor and initializes the drawer for use with keyboard navigation. - * @param {Blockly.Cursor} cursor The cursor used to move around this workspace. + * @param {Cursor} cursor The cursor used to move around this workspace. */ MarkerManager.prototype.setCursor = function(cursor) { if (this.cursor_ && this.cursor_.getDrawer()) { diff --git a/tests/deps.js b/tests/deps.js index de575339f..6ed58a69c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -107,7 +107,7 @@ goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCur goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); +goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); From 126e02927f8752b9dc1c18bee9b9c4e4ab2117d8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:34:30 -0700 Subject: [PATCH 075/172] clang-format core/marker_manager.js --- core/marker_manager.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index b2d5c2bd5..1f16f500a 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -27,7 +27,7 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -const MarkerManager = function(workspace){ +const MarkerManager = function(workspace) { /** * The cursor. * @type {?Cursor} @@ -73,8 +73,8 @@ MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { this.unregisterMarker(id); } - marker.setDrawer(this.workspace_.getRenderer() - .makeMarkerDrawer(this.workspace_, marker)); + marker.setDrawer( + this.workspace_.getRenderer().makeMarkerDrawer(this.workspace_, marker)); this.setMarkerSvg(marker.getDrawer().createDom()); this.markers_[id] = marker; }; @@ -89,7 +89,8 @@ MarkerManager.prototype.unregisterMarker = function(id) { marker.dispose(); delete this.markers_[id]; } else { - throw Error('Marker with ID ' + id + ' does not exist. ' + + throw Error( + 'Marker with ID ' + id + ' does not exist. ' + 'Can only unregister markers that exist.'); } }; @@ -122,8 +123,8 @@ MarkerManager.prototype.setCursor = function(cursor) { } this.cursor_ = cursor; if (this.cursor_) { - const drawer = this.workspace_.getRenderer() - .makeMarkerDrawer(this.workspace_, this.cursor_); + const drawer = this.workspace_.getRenderer().makeMarkerDrawer( + this.workspace_, this.cursor_); this.cursor_.setDrawer(drawer); this.setCursorSvg(this.cursor_.getDrawer().createDom()); } From 046636547ef5e31ea7db352509248a9ccb500fc1 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:26:11 -0700 Subject: [PATCH 076/172] Change how the debug filter is created --- core/renderers/common/constants.js | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 5c73d0510..7508b6050 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -401,6 +401,14 @@ Blockly.blockRendering.ConstantProvider = function() { */ this.randomIdentifier = String(Math.random()).substring(2); + /** + * The defs tag that contains all filters and patterns for this Blockly + * instance. + * @type {SVGElement} + * @private + */ + this.defs = null; + /** * The ID of the emboss filter, or the empty string if no filter is set. * @type {string} @@ -1023,7 +1031,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - var defs = Blockly.utils.dom.createSvgElement( + this.defs = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.DEFS, {}, svg); /* @@ -1041,7 +1049,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, */ var embossFilter = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FILTER, - {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, defs); + {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); @@ -1095,7 +1103,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 - }, defs); + }, this.defs); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); @@ -1105,42 +1113,46 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; - if (Blockly.blockRendering.Debug) { + this.createDebugFilter(); +}; + +/** + * Create a filter for highlighting the currently rendering block during + * render debugging. + * @private + */ +Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = + function() { + // Only create the debug filter once. + if (!this.debugFilter_) { var debugFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, - { + Blockly.utils.Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', y: '-30%', x: '-40%' }, - defs); + this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood var debugComponentTransfer = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPONENTTRANSFER, { - 'result': 'outBlur' - }, debugFilter); + Blockly.utils.Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, + debugFilter); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEFUNCA, - { - 'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1' - }, + {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, debugComponentTransfer); // Color the highlight Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEFLOOD, - { - 'flood-color': '#ff0000', - 'flood-opacity': 0.5, - 'result': 'outColor' - }, + {'flood-color': '#ff0000', 'flood-opacity': 0.5, 'result': 'outColor'}, debugFilter); Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, - { - 'in': 'outColor', 'in2': 'outBlur', - 'operator': 'in', 'result': 'outGlow' + Blockly.utils.Svg.FECOMPOSITE, { + 'in': 'outColor', + 'in2': 'outBlur', + 'operator': 'in', + 'result': 'outGlow' }, debugFilter); this.debugFilterId = debugFilter.id; From e9c1e67d17457111c02f3c1bc53681dafa540974 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:38:20 -0700 Subject: [PATCH 077/172] Migrate core/renderers/common/constants.js to goog.module --- core/renderers/common/constants.js | 53 ++++++++++++++++-------------- tests/deps.js | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 7508b6050..071b21e7d 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockRendering.ConstantProvider'); +goog.module('Blockly.blockRendering.ConstantProvider'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); goog.require('Blockly.utils'); @@ -30,7 +31,7 @@ goog.requireType('Blockly.Theme'); * @constructor * @package */ -Blockly.blockRendering.ConstantProvider = function() { +const ConstantProvider = function() { /** * The size of an empty spacer. @@ -543,7 +544,7 @@ Blockly.blockRendering.ConstantProvider = function() { * Initialize shape objects based on the constants set in the constructor. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.init = function() { +ConstantProvider.prototype.init = function() { /** * An object containing sizing and path information about collapsed block @@ -588,7 +589,7 @@ Blockly.blockRendering.ConstantProvider.prototype.init = function() { * @param {!Blockly.Theme} theme The current workspace theme. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.setTheme = function( +ConstantProvider.prototype.setTheme = function( theme) { /** @@ -611,7 +612,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setTheme = function( * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setDynamicProperties_ = +ConstantProvider.prototype.setDynamicProperties_ = function(theme) { /* eslint-disable indent */ this.setFontConstants_(theme); @@ -626,7 +627,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setDynamicProperties_ = * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setFontConstants_ = function( +ConstantProvider.prototype.setFontConstants_ = function( theme) { this.FIELD_TEXT_FONTFAMILY = theme.fontStyle && theme.fontStyle['family'] != undefined ? @@ -652,7 +653,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setFontConstants_ = function( * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setComponentConstants_ = +ConstantProvider.prototype.setComponentConstants_ = function(theme) { /* eslint-disable indent */ this.CURSOR_COLOUR = theme.getComponentStyle('cursorColour') || @@ -675,7 +676,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setComponentConstants_ = * containing the style and an autogenerated name for that style. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.getBlockStyleForColour = +ConstantProvider.prototype.getBlockStyleForColour = function(colour) { /* eslint-disable indent */ var name = 'auto_' + colour; @@ -691,7 +692,7 @@ Blockly.blockRendering.ConstantProvider.prototype.getBlockStyleForColour = * @return {!Blockly.Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ -Blockly.blockRendering.ConstantProvider.prototype.getBlockStyle = function( +ConstantProvider.prototype.getBlockStyle = function( blockStyleName) { return this.blockStyles[blockStyleName || ''] || (blockStyleName && blockStyleName.indexOf('auto_') == 0 ? @@ -706,7 +707,7 @@ Blockly.blockRendering.ConstantProvider.prototype.getBlockStyle = function( * given colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.createBlockStyle_ = function( +ConstantProvider.prototype.createBlockStyle_ = function( colour) { return this.validatedBlockStyle_({ 'colourPrimary': colour @@ -727,7 +728,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createBlockStyle_ = function( * required properties populated. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.validatedBlockStyle_ = +ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { /* eslint-disable indent */ // Make a new object with all of the same properties. @@ -756,7 +757,7 @@ Blockly.blockRendering.ConstantProvider.prototype.validatedBlockStyle_ = * @return {string} The generated secondary colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.generateSecondaryColour_ = +ConstantProvider.prototype.generateSecondaryColour_ = function(colour) { /* eslint-disable indent */ return Blockly.utils.colour.blend('#fff', colour, 0.6) || colour; @@ -768,7 +769,7 @@ Blockly.blockRendering.ConstantProvider.prototype.generateSecondaryColour_ = * @return {string} The generated tertiary colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.generateTertiaryColour_ = +ConstantProvider.prototype.generateTertiaryColour_ = function(colour) { /* eslint-disable indent */ return Blockly.utils.colour.blend('#fff', colour, 0.3) || colour; @@ -780,7 +781,7 @@ Blockly.blockRendering.ConstantProvider.prototype.generateTertiaryColour_ = * Delete all DOM elements that this provider created. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.dispose = function() { +ConstantProvider.prototype.dispose = function() { if (this.embossFilter_) { Blockly.utils.dom.removeNode(this.embossFilter_); } @@ -798,7 +799,7 @@ Blockly.blockRendering.ConstantProvider.prototype.dispose = function() { * collapsed block indicators. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeJaggedTeeth = function() { +ConstantProvider.prototype.makeJaggedTeeth = function() { var height = this.JAGGED_TEETH_HEIGHT; var width = this.JAGGED_TEETH_WIDTH; @@ -821,7 +822,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeJaggedTeeth = function() { * start hats. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeStartHat = function() { +ConstantProvider.prototype.makeStartHat = function() { var height = this.START_HAT_HEIGHT; var width = this.START_HAT_WIDTH; @@ -844,7 +845,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeStartHat = function() { * puzzle tabs. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makePuzzleTab = function() { +ConstantProvider.prototype.makePuzzleTab = function() { var width = this.TAB_WIDTH; var height = this.TAB_HEIGHT; @@ -898,7 +899,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makePuzzleTab = function() { * notches. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeNotch = function() { +ConstantProvider.prototype.makeNotch = function() { var width = this.NOTCH_WIDTH; var height = this.NOTCH_HEIGHT; var innerWidth = 3; @@ -928,7 +929,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeNotch = function() { * inside corners. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeInsideCorners = function() { +ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; var innerTopLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, @@ -950,7 +951,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeInsideCorners = function() * outside corners. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeOutsideCorners = function() { +ConstantProvider.prototype.makeOutsideCorners = function() { var radius = this.CORNER_RADIUS; /** * SVG path for drawing the rounded top-left corner. @@ -1000,7 +1001,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeOutsideCorners = function( * @return {!Object} The shape object for the connection. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function( +ConstantProvider.prototype.shapeFor = function( connection) { switch (connection.type) { case Blockly.connectionTypes.INPUT_VALUE: @@ -1022,7 +1023,7 @@ Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function( * @suppress {strictModuleDepCheck} Debug renderer only included in playground. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, +ConstantProvider.prototype.createDom = function(svg, tagName, selector) { this.injectCSS_(tagName, selector); @@ -1121,7 +1122,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, * render debugging. * @private */ -Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = +ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { @@ -1166,7 +1167,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = * @param {string} selector The CSS selector to use. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.injectCSS_ = function( +ConstantProvider.prototype.injectCSS_ = function( tagName, selector) { var cssArray = this.getCSS_(selector); var cssNodeId = 'blockly-renderer-style-' + tagName; @@ -1194,7 +1195,7 @@ Blockly.blockRendering.ConstantProvider.prototype.injectCSS_ = function( * @return {!Array} Array of CSS strings. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.getCSS_ = function(selector) { +ConstantProvider.prototype.getCSS_ = function(selector) { return [ /* eslint-disable indent */ // Text. @@ -1269,3 +1270,5 @@ Blockly.blockRendering.ConstantProvider.prototype.getCSS_ = function(selector) { /* eslint-enable indent */ ]; }; + +exports = ConstantProvider; diff --git a/tests/deps.js b/tests/deps.js index de575339f..14992f734 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -120,7 +120,7 @@ goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); -goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); From 227030f451511c0eceb3bf303de25e2ad89e57ca Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:41:22 -0700 Subject: [PATCH 078/172] 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 079/172] 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 82c1d8c47ad70327dde017dfd1a13142109e679a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:48:55 -0700 Subject: [PATCH 080/172] Migrate core/renderers/common/constants.js named requires --- core/renderers/common/constants.js | 207 ++++++++++++++--------------- 1 file changed, 103 insertions(+), 104 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 071b21e7d..4f64223d7 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -13,17 +13,17 @@ goog.module('Blockly.blockRendering.ConstantProvider'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.colour'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.svgPaths'); -goog.require('Blockly.utils.userAgent'); - -goog.requireType('Blockly.blockRendering.Debug'); -goog.requireType('Blockly.RenderedConnection'); -goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +const colour = goog.require('Blockly.utils.colour'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const dom = goog.require('Blockly.utils.dom'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const utils = goog.require('Blockly.utils'); /** @@ -223,7 +223,7 @@ const ConstantProvider = function() { */ this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT; - this.START_POINT = Blockly.utils.svgPaths.moveBy(0, 0); + this.START_POINT = svgPaths.moveBy(0, 0); /** * Height of SVG path for jagged teeth at the end of collapsed blocks. @@ -305,7 +305,7 @@ const ConstantProvider = function() { * @type {boolean} */ this.FIELD_TEXT_BASELINE_CENTER = - !Blockly.utils.userAgent.IE && !Blockly.utils.userAgent.EDGE; + !userAgent.IE && !userAgent.EDGE; /** * A dropdown field's border rect height. @@ -586,7 +586,7 @@ ConstantProvider.prototype.init = function() { /** * Refresh constants properties that depend on the theme. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @package */ ConstantProvider.prototype.setTheme = function( @@ -594,7 +594,7 @@ ConstantProvider.prototype.setTheme = function( /** * The block styles map. - * @type {Object} + * @type {Object} * @package */ this.blockStyles = Object.create(null); @@ -609,7 +609,7 @@ ConstantProvider.prototype.setTheme = function( /** * Sets dynamic properties that depend on other values or theme properties. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setDynamicProperties_ = @@ -624,7 +624,7 @@ ConstantProvider.prototype.setDynamicProperties_ = /** * Set constants related to fonts. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setFontConstants_ = function( @@ -639,7 +639,7 @@ ConstantProvider.prototype.setFontConstants_ = function( theme.fontStyle && theme.fontStyle['size'] != undefined ? theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; - var fontMetrics = Blockly.utils.dom.measureFontMetrics('Hg', + var fontMetrics = dom.measureFontMetrics('Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); @@ -650,7 +650,7 @@ ConstantProvider.prototype.setFontConstants_ = function( /** * Set constants from a theme's component styles. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setComponentConstants_ = @@ -672,7 +672,7 @@ ConstantProvider.prototype.setComponentConstants_ = * Get or create a block style based on a single colour value. Generate a name * for the style based on the colour. * @param {string} colour #RRGGBB colour string. - * @return {{style: !Blockly.Theme.BlockStyle, name: string}} An object + * @return {{style: !Theme.BlockStyle, name: string}} An object * containing the style and an autogenerated name for that style. * @package */ @@ -689,7 +689,7 @@ ConstantProvider.prototype.getBlockStyleForColour = /** * Gets the BlockStyle for the given block style name. * @param {?string} blockStyleName The name of the block style. - * @return {!Blockly.Theme.BlockStyle} The named block style, or a default style + * @return {!Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ ConstantProvider.prototype.getBlockStyle = function( @@ -703,7 +703,7 @@ ConstantProvider.prototype.getBlockStyle = function( /** * Create a block style object based on the given colour. * @param {string} colour #RRGGBB colour string. - * @return {!Blockly.Theme.BlockStyle} A populated block style based on the + * @return {!Theme.BlockStyle} A populated block style based on the * given colour. * @protected */ @@ -724,7 +724,7 @@ ConstantProvider.prototype.createBlockStyle_ = function( * hat:(string|undefined) * }} blockStyle A full or partial block style object. - * @return {!Blockly.Theme.BlockStyle} A full block style object, with all + * @return {!Theme.BlockStyle} A full block style object, with all * required properties populated. * @protected */ @@ -732,19 +732,19 @@ ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { /* eslint-disable indent */ // Make a new object with all of the same properties. - var valid = /** @type {!Blockly.Theme.BlockStyle} */ ({}); + var valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { - Blockly.utils.object.mixin(valid, blockStyle); + utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = Blockly.utils.parseBlockColour( + var parsedColour = utils.parseBlockColour( valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? - Blockly.utils.parseBlockColour(valid['colourSecondary']).hex : + utils.parseBlockColour(valid['colourSecondary']).hex : this.generateSecondaryColour_(valid.colourPrimary); valid.colourTertiary = valid['colourTertiary'] ? - Blockly.utils.parseBlockColour(valid['colourTertiary']).hex : + utils.parseBlockColour(valid['colourTertiary']).hex : this.generateTertiaryColour_(valid.colourPrimary); valid.hat = valid['hat'] || ''; @@ -758,9 +758,9 @@ ConstantProvider.prototype.validatedBlockStyle_ = * @protected */ ConstantProvider.prototype.generateSecondaryColour_ = - function(colour) { + function(inputColour) { /* eslint-disable indent */ - return Blockly.utils.colour.blend('#fff', colour, 0.6) || colour; + return colour.blend('#fff', inputColour, 0.6) || inputColour; }; /* eslint-enable indent */ /** @@ -769,10 +769,9 @@ ConstantProvider.prototype.generateSecondaryColour_ = * @return {string} The generated tertiary colour. * @protected */ -ConstantProvider.prototype.generateTertiaryColour_ = - function(colour) { - /* eslint-disable indent */ - return Blockly.utils.colour.blend('#fff', colour, 0.3) || colour; +ConstantProvider.prototype.generateTertiaryColour_ = function(inputColour) { + /* eslint-disable indent */ + return colour.blend('#fff', inputColour, 0.3) || inputColour; }; /* eslint-enable indent */ @@ -783,13 +782,13 @@ ConstantProvider.prototype.generateTertiaryColour_ = */ ConstantProvider.prototype.dispose = function() { if (this.embossFilter_) { - Blockly.utils.dom.removeNode(this.embossFilter_); + dom.removeNode(this.embossFilter_); } if (this.disabledPattern_) { - Blockly.utils.dom.removeNode(this.disabledPattern_); + dom.removeNode(this.disabledPattern_); } if (this.debugFilter_) { - Blockly.utils.dom.removeNode(this.debugFilter_); + dom.removeNode(this.debugFilter_); } this.cssNode_ = null; }; @@ -804,11 +803,11 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { var width = this.JAGGED_TEETH_WIDTH; var mainPath = - Blockly.utils.svgPaths.line( + svgPaths.line( [ - Blockly.utils.svgPaths.point(width, height / 4), - Blockly.utils.svgPaths.point(-width * 2, height / 2), - Blockly.utils.svgPaths.point(width, height / 4) + svgPaths.point(width, height / 4), + svgPaths.point(-width * 2, height / 2), + svgPaths.point(width, height / 4) ]); return { height: height, @@ -827,11 +826,11 @@ ConstantProvider.prototype.makeStartHat = function() { var width = this.START_HAT_WIDTH; var mainPath = - Blockly.utils.svgPaths.curve('c', + svgPaths.curve('c', [ - Blockly.utils.svgPaths.point(30, -height), - Blockly.utils.svgPaths.point(70, -height), - Blockly.utils.svgPaths.point(width, 0) + svgPaths.point(30, -height), + svgPaths.point(70, -height), + svgPaths.point(width, 0) ]); return { height: height, @@ -864,18 +863,18 @@ ConstantProvider.prototype.makePuzzleTab = function() { var control2Y = halfHeight + 0.5; var control3Y = overlap; // 2.5 - var endPoint1 = Blockly.utils.svgPaths.point(-width, forward * halfHeight); - var endPoint2 = Blockly.utils.svgPaths.point(width, forward * halfHeight); + var endPoint1 = svgPaths.point(-width, forward * halfHeight); + var endPoint2 = svgPaths.point(width, forward * halfHeight); - return Blockly.utils.svgPaths.curve('c', + return svgPaths.curve('c', [ - Blockly.utils.svgPaths.point(0, forward * control1Y), - Blockly.utils.svgPaths.point(-width, back * control2Y), + svgPaths.point(0, forward * control1Y), + svgPaths.point(-width, back * control2Y), endPoint1 ]) + - Blockly.utils.svgPaths.curve('s', + svgPaths.curve('s', [ - Blockly.utils.svgPaths.point(width, back * control3Y), + svgPaths.point(width, back * control3Y), endPoint2 ]); } @@ -905,11 +904,11 @@ ConstantProvider.prototype.makeNotch = function() { var innerWidth = 3; var outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { - return Blockly.utils.svgPaths.line( + return svgPaths.line( [ - Blockly.utils.svgPaths.point(dir * outerWidth, height), - Blockly.utils.svgPaths.point(dir * innerWidth, 0), - Blockly.utils.svgPaths.point(dir * outerWidth, -height) + svgPaths.point(dir * outerWidth, height), + svgPaths.point(dir * innerWidth, 0), + svgPaths.point(dir * outerWidth, -height) ]); } var pathLeft = makeMainPath(1); @@ -932,11 +931,11 @@ ConstantProvider.prototype.makeNotch = function() { ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; - var innerTopLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point(-radius, radius)); + var innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, + svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point(radius, radius)); + var innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, + svgPaths.point(radius, radius)); return { width: radius, @@ -958,31 +957,31 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * @const */ var topLeft = - Blockly.utils.svgPaths.moveBy(0, radius) + - Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(radius, -radius)); + svgPaths.moveBy(0, radius) + + svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ var topRight = - Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(-radius, -radius)); + var bottomLeft = svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(-radius, radius)); + var bottomRight = svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(-radius, radius)); return { topLeft: topLeft, @@ -996,7 +995,7 @@ ConstantProvider.prototype.makeOutsideCorners = function() { /** * Get an object with connection shape and sizing information based on the type * of the connection. - * @param {!Blockly.RenderedConnection} connection The connection to find a + * @param {!RenderedConnection} connection The connection to find a * shape object for * @return {!Object} The shape object for the connection. * @package @@ -1004,11 +1003,11 @@ ConstantProvider.prototype.makeOutsideCorners = function() { ConstantProvider.prototype.shapeFor = function( connection) { switch (connection.type) { - case Blockly.connectionTypes.INPUT_VALUE: - case Blockly.connectionTypes.OUTPUT_VALUE: + case connectionTypes.INPUT_VALUE: + case connectionTypes.OUTPUT_VALUE: return this.PUZZLE_TAB; - case Blockly.connectionTypes.PREVIOUS_STATEMENT: - case Blockly.connectionTypes.NEXT_STATEMENT: + case connectionTypes.PREVIOUS_STATEMENT: + case connectionTypes.NEXT_STATEMENT: return this.NOTCH; default: throw Error('Unknown connection type'); @@ -1032,8 +1031,8 @@ ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - this.defs = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.DEFS, {}, svg); + this.defs = dom.createSvgElement( + Svg.DEFS, {}, svg); /* @@ -1048,14 +1047,14 @@ ConstantProvider.prototype.createDom = function(svg, k1="0" k2="1" k3="1" k4="0" /> */ - var embossFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, + var embossFilter = dom.createSvgElement( + Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEGAUSSIANBLUR, + dom.createSvgElement( + Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); - var feSpecularLighting = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FESPECULARLIGHTING, + var feSpecularLighting = dom.createSvgElement( + Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, @@ -1065,19 +1064,19 @@ ConstantProvider.prototype.createDom = function(svg, 'result': 'specOut' }, embossFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEPOINTLIGHT, + dom.createSvgElement( + Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in', 'result': 'specOut' }, embossFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'SourceGraphic', 'in2': 'specOut', @@ -1097,19 +1096,19 @@ ConstantProvider.prototype.createDom = function(svg, */ - var disabledPattern = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATTERN, + var disabledPattern = dom.createSvgElement( + Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 }, this.defs); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; @@ -1126,8 +1125,8 @@ ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { - var debugFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, { + var debugFilter = dom.createSvgElement( + Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', @@ -1136,20 +1135,20 @@ ConstantProvider.prototype.createDebugFilter = }, this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood - var debugComponentTransfer = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, + var debugComponentTransfer = dom.createSvgElement( + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEFUNCA, + dom.createSvgElement( + Svg.FEFUNCA, {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, debugComponentTransfer); // Color the highlight - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEFLOOD, + dom.createSvgElement( + Svg.FEFLOOD, {'flood-color': '#ff0000', 'flood-opacity': 0.5, 'result': 'outColor'}, debugFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, { + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'outColor', 'in2': 'outBlur', 'operator': 'in', From 96ec93f91e9f2e46295e70cd72dd712c2921afb8 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:52:42 -0700 Subject: [PATCH 081/172] Remove deconstructing properties and update logic (#5202) --- scripts/goog_module/convert-file.sh | 47 +++++++++-------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 8b6bdfc6f..f3138e9cf 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -163,6 +163,11 @@ step3() { continue fi + local require_name=$(echo "${require}" | perl -pe 's/(\w+\.)+(\w+)/\2/g') + inf "Updating require declaration for ${require}..." + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" + + # Parse property access of module local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) # Detect requires overlap @@ -181,42 +186,18 @@ step3() { fi properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) - if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then - local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - local confirm='' - while true; do - read -p "Would you like to deconstruct ${require} into \"{${deconstructed_comma}}\"? (y/n): " yn Date: Fri, 23 Jul 2021 14:59:16 -0700 Subject: [PATCH 082/172] 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 083/172] 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 4aef7e3bcdc78d8f09c44253d48a3a5cfcd238ef Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 15:00:14 -0700 Subject: [PATCH 084/172] clang-format core/renderers/common/constants.js --- core/renderers/common/constants.js | 286 ++++++++++++----------------- 1 file changed, 118 insertions(+), 168 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 4f64223d7..5fdacc2ea 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -32,7 +32,6 @@ const utils = goog.require('Blockly.utils'); * @package */ const ConstantProvider = function() { - /** * The size of an empty spacer. * @type {number} @@ -215,10 +214,10 @@ const ConstantProvider = function() { this.EXTERNAL_VALUE_INPUT_PADDING = 2; /** - * The height of an empty statement input. Note that in the old rendering this - * varies slightly depending on whether the block has external or inline inputs. - * In the new rendering this is consistent. It seems unlikely that the old - * behaviour was intentional. + * The height of an empty statement input. Note that in the old rendering + * this varies slightly depending on whether the block has external or inline + * inputs. In the new rendering this is consistent. It seems unlikely that + * the old behaviour was intentional. * @type {number} */ this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT; @@ -304,8 +303,7 @@ const ConstantProvider = function() { * A field's text element's dominant baseline. * @type {boolean} */ - this.FIELD_TEXT_BASELINE_CENTER = - !userAgent.IE && !userAgent.EDGE; + this.FIELD_TEXT_BASELINE_CENTER = !userAgent.IE && !userAgent.EDGE; /** * A dropdown field's border rect height. @@ -350,17 +348,17 @@ const ConstantProvider = function() { * @type {string} */ this.FIELD_DROPDOWN_SVG_ARROW_DATAURI = - 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' + - 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' + - 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' + - 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' + - 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' + - 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' + - 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' + - 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' + - 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' + - 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' + - 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4='; + 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' + + 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' + + 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' + + 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' + + 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' + + 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' + + 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' + + 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' + + 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' + + 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' + + 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4='; /** * Whether or not to show a box shadow around the widget div. This is only a @@ -534,10 +532,7 @@ const ConstantProvider = function() { * Enum for connection shapes. * @enum {number} */ - this.SHAPES = { - PUZZLE: 1, - NOTCH: 2 - }; + this.SHAPES = {PUZZLE: 1, NOTCH: 2}; }; /** @@ -545,7 +540,6 @@ const ConstantProvider = function() { * @package */ ConstantProvider.prototype.init = function() { - /** * An object containing sizing and path information about collapsed block * indicators. @@ -589,9 +583,7 @@ ConstantProvider.prototype.init = function() { * @param {!Theme} theme The current workspace theme. * @package */ -ConstantProvider.prototype.setTheme = function( - theme) { - +ConstantProvider.prototype.setTheme = function(theme) { /** * The block styles map. * @type {Object} @@ -612,36 +604,35 @@ ConstantProvider.prototype.setTheme = function( * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setDynamicProperties_ = - function(theme) { - /* eslint-disable indent */ +ConstantProvider.prototype.setDynamicProperties_ = function(theme) { this.setFontConstants_(theme); this.setComponentConstants_(theme); - this.ADD_START_HATS = theme.startHats != null ? theme.startHats : - this.ADD_START_HATS; -}; /* eslint-enable indent */ + this.ADD_START_HATS = + theme.startHats != null ? theme.startHats : this.ADD_START_HATS; +}; /** * Set constants related to fonts. * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setFontConstants_ = function( - theme) { +ConstantProvider.prototype.setFontConstants_ = function(theme) { this.FIELD_TEXT_FONTFAMILY = theme.fontStyle && theme.fontStyle['family'] != undefined ? - theme.fontStyle['family'] : this.FIELD_TEXT_FONTFAMILY; + theme.fontStyle['family'] : + this.FIELD_TEXT_FONTFAMILY; this.FIELD_TEXT_FONTWEIGHT = theme.fontStyle && theme.fontStyle['weight'] != undefined ? - theme.fontStyle['weight'] : this.FIELD_TEXT_FONTWEIGHT; + theme.fontStyle['weight'] : + this.FIELD_TEXT_FONTWEIGHT; this.FIELD_TEXT_FONTSIZE = theme.fontStyle && theme.fontStyle['size'] != undefined ? - theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; + theme.fontStyle['size'] : + this.FIELD_TEXT_FONTSIZE; - var fontMetrics = dom.measureFontMetrics('Hg', - this.FIELD_TEXT_FONTSIZE + 'pt', - this.FIELD_TEXT_FONTWEIGHT, + var fontMetrics = dom.measureFontMetrics( + 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); this.FIELD_TEXT_HEIGHT = fontMetrics.height; @@ -653,20 +644,18 @@ ConstantProvider.prototype.setFontConstants_ = function( * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setComponentConstants_ = - function(theme) { - /* eslint-disable indent */ - this.CURSOR_COLOUR = theme.getComponentStyle('cursorColour') || - this.CURSOR_COLOUR; - this.MARKER_COLOUR = theme.getComponentStyle('markerColour') || - this.MARKER_COLOUR; +ConstantProvider.prototype.setComponentConstants_ = function(theme) { + this.CURSOR_COLOUR = + theme.getComponentStyle('cursorColour') || this.CURSOR_COLOUR; + this.MARKER_COLOUR = + theme.getComponentStyle('markerColour') || this.MARKER_COLOUR; this.INSERTION_MARKER_COLOUR = - theme.getComponentStyle('insertionMarkerColour') || - this.INSERTION_MARKER_COLOUR; + theme.getComponentStyle('insertionMarkerColour') || + this.INSERTION_MARKER_COLOUR; this.INSERTION_MARKER_OPACITY = - Number(theme.getComponentStyle('insertionMarkerOpacity')) || - this.INSERTION_MARKER_OPACITY; -}; /* eslint-enable indent */ + Number(theme.getComponentStyle('insertionMarkerOpacity')) || + this.INSERTION_MARKER_OPACITY; +}; /** * Get or create a block style based on a single colour value. Generate a name @@ -676,15 +665,13 @@ ConstantProvider.prototype.setComponentConstants_ = * containing the style and an autogenerated name for that style. * @package */ -ConstantProvider.prototype.getBlockStyleForColour = - function(colour) { - /* eslint-disable indent */ +ConstantProvider.prototype.getBlockStyleForColour = function(colour) { var name = 'auto_' + colour; if (!this.blockStyles[name]) { this.blockStyles[name] = this.createBlockStyle_(colour); } return {style: this.blockStyles[name], name: name}; -}; /* eslint-enable indent */ +}; /** * Gets the BlockStyle for the given block style name. @@ -692,12 +679,11 @@ ConstantProvider.prototype.getBlockStyleForColour = * @return {!Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ -ConstantProvider.prototype.getBlockStyle = function( - blockStyleName) { +ConstantProvider.prototype.getBlockStyle = function(blockStyleName) { return this.blockStyles[blockStyleName || ''] || (blockStyleName && blockStyleName.indexOf('auto_') == 0 ? - this.getBlockStyleForColour(blockStyleName.substring(5)).style : - this.createBlockStyle_('#000000')); + this.getBlockStyleForColour(blockStyleName.substring(5)).style : + this.createBlockStyle_('#000000')); }; /** @@ -707,11 +693,8 @@ ConstantProvider.prototype.getBlockStyle = function( * given colour. * @protected */ -ConstantProvider.prototype.createBlockStyle_ = function( - colour) { - return this.validatedBlockStyle_({ - 'colourPrimary': colour - }); +ConstantProvider.prototype.createBlockStyle_ = function(colour) { + return this.validatedBlockStyle_({'colourPrimary': colour}); }; /** @@ -728,17 +711,14 @@ ConstantProvider.prototype.createBlockStyle_ = function( * required properties populated. * @protected */ -ConstantProvider.prototype.validatedBlockStyle_ = - function(blockStyle) { - /* eslint-disable indent */ +ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { // Make a new object with all of the same properties. var valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = utils.parseBlockColour( - valid['colourPrimary'] || '#000'); + var parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? utils.parseBlockColour(valid['colourSecondary']).hex : @@ -749,30 +729,27 @@ ConstantProvider.prototype.validatedBlockStyle_ = valid.hat = valid['hat'] || ''; return valid; -}; /* eslint-enable indent */ +}; /** * Generate a secondary colour from the passed in primary colour. - * @param {string} colour Primary colour. + * @param {string} inputColour Primary colour. * @return {string} The generated secondary colour. * @protected */ -ConstantProvider.prototype.generateSecondaryColour_ = - function(inputColour) { - /* eslint-disable indent */ - return colour.blend('#fff', inputColour, 0.6) || inputColour; -}; /* eslint-enable indent */ +ConstantProvider.prototype.generateSecondaryColour_ = function(inputColour) { + return colour.blend('#fff', inputColour, 0.6) || inputColour; +}; /** * Generate a tertiary colour from the passed in primary colour. - * @param {string} colour Primary colour. + * @param {string} inputColour Primary colour. * @return {string} The generated tertiary colour. * @protected */ ConstantProvider.prototype.generateTertiaryColour_ = function(inputColour) { - /* eslint-disable indent */ return colour.blend('#fff', inputColour, 0.3) || inputColour; -}; /* eslint-enable indent */ +}; /** @@ -802,18 +779,11 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { var height = this.JAGGED_TEETH_HEIGHT; var width = this.JAGGED_TEETH_WIDTH; - var mainPath = - svgPaths.line( - [ - svgPaths.point(width, height / 4), - svgPaths.point(-width * 2, height / 2), - svgPaths.point(width, height / 4) - ]); - return { - height: height, - width: width, - path: mainPath - }; + var mainPath = svgPaths.line([ + svgPaths.point(width, height / 4), svgPaths.point(-width * 2, height / 2), + svgPaths.point(width, height / 4) + ]); + return {height: height, width: width, path: mainPath}; }; /** @@ -825,18 +795,11 @@ ConstantProvider.prototype.makeStartHat = function() { var height = this.START_HAT_HEIGHT; var width = this.START_HAT_WIDTH; - var mainPath = - svgPaths.curve('c', - [ - svgPaths.point(30, -height), - svgPaths.point(70, -height), - svgPaths.point(width, 0) - ]); - return { - height: height, - width: width, - path: mainPath - }; + var mainPath = svgPaths.curve('c', [ + svgPaths.point(30, -height), svgPaths.point(70, -height), + svgPaths.point(width, 0) + ]); + return {height: height, width: width, path: mainPath}; }; /** @@ -866,17 +829,14 @@ ConstantProvider.prototype.makePuzzleTab = function() { var endPoint1 = svgPaths.point(-width, forward * halfHeight); var endPoint2 = svgPaths.point(width, forward * halfHeight); - return svgPaths.curve('c', - [ - svgPaths.point(0, forward * control1Y), - svgPaths.point(-width, back * control2Y), - endPoint1 - ]) + - svgPaths.curve('s', - [ - svgPaths.point(width, back * control3Y), - endPoint2 - ]); + return svgPaths.curve( + 'c', + [ + svgPaths.point(0, forward * control1Y), + svgPaths.point(-width, back * control2Y), endPoint1 + ]) + + svgPaths.curve( + 's', [svgPaths.point(width, back * control3Y), endPoint2]); } // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 @@ -904,12 +864,11 @@ ConstantProvider.prototype.makeNotch = function() { var innerWidth = 3; var outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { - return svgPaths.line( - [ - svgPaths.point(dir * outerWidth, height), - svgPaths.point(dir * innerWidth, 0), - svgPaths.point(dir * outerWidth, -height) - ]); + return svgPaths.line([ + svgPaths.point(dir * outerWidth, height), + svgPaths.point(dir * innerWidth, 0), + svgPaths.point(dir * outerWidth, -height) + ]); } var pathLeft = makeMainPath(1); var pathRight = makeMainPath(-1); @@ -931,11 +890,11 @@ ConstantProvider.prototype.makeNotch = function() { ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; - var innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, - svgPaths.point(-radius, radius)); + var innerTopLeftCorner = + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, - svgPaths.point(radius, radius)); + var innerBottomLeftCorner = + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); return { width: radius, @@ -956,32 +915,29 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * SVG path for drawing the rounded top-left corner. * @const */ - var topLeft = - svgPaths.moveBy(0, radius) + - svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(radius, -radius)); + var topLeft = svgPaths.moveBy(0, radius) + + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ var topRight = - svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(-radius, -radius)); + var bottomLeft = + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(-radius, radius)); + var bottomRight = + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); return { topLeft: topLeft, @@ -1000,8 +956,7 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * @return {!Object} The shape object for the connection. * @package */ -ConstantProvider.prototype.shapeFor = function( - connection) { +ConstantProvider.prototype.shapeFor = function(connection) { switch (connection.type) { case connectionTypes.INPUT_VALUE: case connectionTypes.OUTPUT_VALUE: @@ -1022,8 +977,7 @@ ConstantProvider.prototype.shapeFor = function( * @suppress {strictModuleDepCheck} Debug renderer only included in playground. * @package */ -ConstantProvider.prototype.createDom = function(svg, - tagName, selector) { +ConstantProvider.prototype.createDom = function(svg, tagName, selector) { this.injectCSS_(tagName, selector); /* @@ -1031,8 +985,7 @@ ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - this.defs = dom.createSvgElement( - Svg.DEFS, {}, svg); + this.defs = dom.createSvgElement(Svg.DEFS, {}, svg); /* @@ -1048,14 +1001,13 @@ ConstantProvider.prototype.createDom = function(svg, */ var embossFilter = dom.createSvgElement( - Svg.FILTER, - {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); + Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, + this.defs); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); var feSpecularLighting = dom.createSvgElement( - Svg.FESPECULARLIGHTING, - { + Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, 'specularConstant': 0.5, @@ -1065,19 +1017,18 @@ ConstantProvider.prototype.createDom = function(svg, }, embossFilter); dom.createSvgElement( - Svg.FEPOINTLIGHT, - {'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting); + Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000}, + feSpecularLighting); dom.createSvgElement( - Svg.FECOMPOSITE, - { + Svg.FECOMPOSITE, { 'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in', 'result': 'specOut' - }, embossFilter); + }, + embossFilter); dom.createSvgElement( - Svg.FECOMPOSITE, - { + Svg.FECOMPOSITE, { 'in': 'SourceGraphic', 'in2': 'specOut', 'operator': 'arithmetic', @@ -1085,7 +1036,8 @@ ConstantProvider.prototype.createDom = function(svg, 'k2': 1, 'k3': 1, 'k4': 0 - }, embossFilter); + }, + embossFilter); this.embossFilterId = embossFilter.id; this.embossFilter_ = embossFilter; @@ -1097,19 +1049,18 @@ ConstantProvider.prototype.createDom = function(svg, */ var disabledPattern = dom.createSvgElement( - Svg.PATTERN, - { + Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 - }, this.defs); + }, + this.defs); dom.createSvgElement( - Svg.RECT, - {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); + Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); dom.createSvgElement( - Svg.PATH, - {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); + Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, + disabledPattern); this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; @@ -1121,8 +1072,7 @@ ConstantProvider.prototype.createDom = function(svg, * render debugging. * @private */ -ConstantProvider.prototype.createDebugFilter = - function() { +ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { var debugFilter = dom.createSvgElement( @@ -1136,8 +1086,7 @@ ConstantProvider.prototype.createDebugFilter = this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood var debugComponentTransfer = dom.createSvgElement( - Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, - debugFilter); + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); dom.createSvgElement( Svg.FEFUNCA, {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, @@ -1166,12 +1115,11 @@ ConstantProvider.prototype.createDebugFilter = * @param {string} selector The CSS selector to use. * @protected */ -ConstantProvider.prototype.injectCSS_ = function( - tagName, selector) { +ConstantProvider.prototype.injectCSS_ = function(tagName, selector) { var cssArray = this.getCSS_(selector); var cssNodeId = 'blockly-renderer-style-' + tagName; this.cssNode_ = - /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); + /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); var text = cssArray.join('\n'); if (this.cssNode_) { // Already injected, update if the theme changed. @@ -1180,7 +1128,7 @@ ConstantProvider.prototype.injectCSS_ = function( } // Inject CSS tag at start of head. var cssNode = - /** @type {!HTMLStyleElement} */ (document.createElement('style')); + /** @type {!HTMLStyleElement} */ (document.createElement('style')); cssNode.id = cssNodeId; var cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); @@ -1197,6 +1145,7 @@ ConstantProvider.prototype.injectCSS_ = function( ConstantProvider.prototype.getCSS_ = function(selector) { return [ /* eslint-disable indent */ + /* clang-format off */ // Text. selector + ' .blocklyText, ', selector + ' .blocklyFlyoutLabelText {', @@ -1266,6 +1215,7 @@ ConstantProvider.prototype.getCSS_ = function(selector) { 'fill-opacity: ' + this.INSERTION_MARKER_OPACITY + ';', 'stroke: none;', '}', + /* clang-format on */ /* eslint-enable indent */ ]; }; From a392696c7a633f0e4d88fa2db42977ca39ce413b Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 15:07:30 -0700 Subject: [PATCH 085/172] Convert core/renderers/common/constants.js to const/let --- core/renderers/common/constants.js | 98 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 5fdacc2ea..6847aea22 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -591,8 +591,8 @@ ConstantProvider.prototype.setTheme = function(theme) { */ this.blockStyles = Object.create(null); - var blockStyles = theme.blockStyles; - for (var key in blockStyles) { + const blockStyles = theme.blockStyles; + for (const key in blockStyles) { this.blockStyles[key] = this.validatedBlockStyle_(blockStyles[key]); } @@ -631,7 +631,7 @@ ConstantProvider.prototype.setFontConstants_ = function(theme) { theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; - var fontMetrics = dom.measureFontMetrics( + const fontMetrics = dom.measureFontMetrics( 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); @@ -666,7 +666,7 @@ ConstantProvider.prototype.setComponentConstants_ = function(theme) { * @package */ ConstantProvider.prototype.getBlockStyleForColour = function(colour) { - var name = 'auto_' + colour; + const name = 'auto_' + colour; if (!this.blockStyles[name]) { this.blockStyles[name] = this.createBlockStyle_(colour); } @@ -713,12 +713,12 @@ ConstantProvider.prototype.createBlockStyle_ = function(colour) { */ ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { // Make a new object with all of the same properties. - var valid = /** @type {!Theme.BlockStyle} */ ({}); + const valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); + const parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? utils.parseBlockColour(valid['colourSecondary']).hex : @@ -776,10 +776,10 @@ ConstantProvider.prototype.dispose = function() { * @package */ ConstantProvider.prototype.makeJaggedTeeth = function() { - var height = this.JAGGED_TEETH_HEIGHT; - var width = this.JAGGED_TEETH_WIDTH; + const height = this.JAGGED_TEETH_HEIGHT; + const width = this.JAGGED_TEETH_WIDTH; - var mainPath = svgPaths.line([ + const mainPath = svgPaths.line([ svgPaths.point(width, height / 4), svgPaths.point(-width * 2, height / 2), svgPaths.point(width, height / 4) ]); @@ -792,10 +792,10 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { * @package */ ConstantProvider.prototype.makeStartHat = function() { - var height = this.START_HAT_HEIGHT; - var width = this.START_HAT_WIDTH; + const height = this.START_HAT_HEIGHT; + const width = this.START_HAT_WIDTH; - var mainPath = svgPaths.curve('c', [ + const mainPath = svgPaths.curve('c', [ svgPaths.point(30, -height), svgPaths.point(70, -height), svgPaths.point(width, 0) ]); @@ -808,8 +808,8 @@ ConstantProvider.prototype.makeStartHat = function() { * @package */ ConstantProvider.prototype.makePuzzleTab = function() { - var width = this.TAB_WIDTH; - var height = this.TAB_HEIGHT; + const width = this.TAB_WIDTH; + const height = this.TAB_HEIGHT; // The main path for the puzzle tab is made out of a few curves (c and s). // Those curves are defined with relative positions. The 'up' and 'down' @@ -817,17 +817,17 @@ ConstantProvider.prototype.makePuzzleTab = function() { // are the signs to use to move the cursor in the direction that the path is // being drawn. function makeMainPath(up) { - var forward = up ? -1 : 1; - var back = -forward; + const forward = up ? -1 : 1; + const back = -forward; - var overlap = 2.5; - var halfHeight = height / 2; - var control1Y = halfHeight + overlap; - var control2Y = halfHeight + 0.5; - var control3Y = overlap; // 2.5 + const overlap = 2.5; + const halfHeight = height / 2; + const control1Y = halfHeight + overlap; + const control2Y = halfHeight + 0.5; + const control3Y = overlap; // 2.5 - var endPoint1 = svgPaths.point(-width, forward * halfHeight); - var endPoint2 = svgPaths.point(width, forward * halfHeight); + const endPoint1 = svgPaths.point(-width, forward * halfHeight); + const endPoint2 = svgPaths.point(width, forward * halfHeight); return svgPaths.curve( 'c', @@ -840,9 +840,9 @@ ConstantProvider.prototype.makePuzzleTab = function() { } // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 - var pathUp = makeMainPath(true); + const pathUp = makeMainPath(true); // c 0,10 -8,-8 -8,7.5 s 8,-2.5 8,7.5 - var pathDown = makeMainPath(false); + const pathDown = makeMainPath(false); return { type: this.SHAPES.PUZZLE, @@ -859,10 +859,10 @@ ConstantProvider.prototype.makePuzzleTab = function() { * @package */ ConstantProvider.prototype.makeNotch = function() { - var width = this.NOTCH_WIDTH; - var height = this.NOTCH_HEIGHT; - var innerWidth = 3; - var outerWidth = (width - innerWidth) / 2; + const width = this.NOTCH_WIDTH; + const height = this.NOTCH_HEIGHT; + const innerWidth = 3; + const outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { return svgPaths.line([ svgPaths.point(dir * outerWidth, height), @@ -870,8 +870,8 @@ ConstantProvider.prototype.makeNotch = function() { svgPaths.point(dir * outerWidth, -height) ]); } - var pathLeft = makeMainPath(1); - var pathRight = makeMainPath(-1); + const pathLeft = makeMainPath(1); + const pathRight = makeMainPath(-1); return { type: this.SHAPES.NOTCH, @@ -888,12 +888,12 @@ ConstantProvider.prototype.makeNotch = function() { * @package */ ConstantProvider.prototype.makeInsideCorners = function() { - var radius = this.CORNER_RADIUS; + const radius = this.CORNER_RADIUS; - var innerTopLeftCorner = + const innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = + const innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); return { @@ -910,33 +910,33 @@ ConstantProvider.prototype.makeInsideCorners = function() { * @package */ ConstantProvider.prototype.makeOutsideCorners = function() { - var radius = this.CORNER_RADIUS; + const radius = this.CORNER_RADIUS; /** * SVG path for drawing the rounded top-left corner. * @const */ - var topLeft = svgPaths.moveBy(0, radius) + + const topLeft = svgPaths.moveBy(0, radius) + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ - var topRight = + const topRight = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = + const bottomLeft = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = + const bottomRight = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); return { @@ -1000,13 +1000,13 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { k1="0" k2="1" k3="1" k4="0" /> */ - var embossFilter = dom.createSvgElement( + const embossFilter = dom.createSvgElement( Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); - var feSpecularLighting = dom.createSvgElement( + const feSpecularLighting = dom.createSvgElement( Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, @@ -1048,7 +1048,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { */ - var disabledPattern = dom.createSvgElement( + const disabledPattern = dom.createSvgElement( Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', @@ -1075,7 +1075,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { - var debugFilter = dom.createSvgElement( + const debugFilter = dom.createSvgElement( Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', @@ -1085,7 +1085,7 @@ ConstantProvider.prototype.createDebugFilter = function() { }, this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood - var debugComponentTransfer = dom.createSvgElement( + const debugComponentTransfer = dom.createSvgElement( Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); dom.createSvgElement( Svg.FEFUNCA, @@ -1116,21 +1116,21 @@ ConstantProvider.prototype.createDebugFilter = function() { * @protected */ ConstantProvider.prototype.injectCSS_ = function(tagName, selector) { - var cssArray = this.getCSS_(selector); - var cssNodeId = 'blockly-renderer-style-' + tagName; + const cssArray = this.getCSS_(selector); + const cssNodeId = 'blockly-renderer-style-' + tagName; this.cssNode_ = /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); - var text = cssArray.join('\n'); + const text = cssArray.join('\n'); if (this.cssNode_) { // Already injected, update if the theme changed. this.cssNode_.firstChild.textContent = text; return; } // Inject CSS tag at start of head. - var cssNode = + const cssNode = /** @type {!HTMLStyleElement} */ (document.createElement('style')); cssNode.id = cssNodeId; - var cssTextNode = document.createTextNode(text); + const cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); document.head.insertBefore(cssNode, document.head.firstChild); this.cssNode_ = cssNode; From 1dfee3a722a6f542700a5d980440e6c091418bcd Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 16:39:40 -0700 Subject: [PATCH 086/172] Make defs private and add nullability --- core/renderers/common/constants.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 6847aea22..5e5ecb747 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -403,10 +403,10 @@ const ConstantProvider = function() { /** * The defs tag that contains all filters and patterns for this Blockly * instance. - * @type {SVGElement} + * @type {?SVGElement} * @private */ - this.defs = null; + this.defs_ = null; /** * The ID of the emboss filter, or the empty string if no filter is set. @@ -985,7 +985,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { ... filters go here ... */ - this.defs = dom.createSvgElement(Svg.DEFS, {}, svg); + this.defs_ = dom.createSvgElement(Svg.DEFS, {}, svg); /* @@ -1002,7 +1002,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { */ const embossFilter = dom.createSvgElement( Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, - this.defs); + this.defs_); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); @@ -1055,7 +1055,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { 'width': 10, 'height': 10 }, - this.defs); + this.defs_); dom.createSvgElement( Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); dom.createSvgElement( @@ -1083,7 +1083,7 @@ ConstantProvider.prototype.createDebugFilter = function() { y: '-30%', x: '-40%' }, - this.defs); + this.defs_); // Set all gaussian blur pixels to 1 opacity before applying flood const debugComponentTransfer = dom.createSvgElement( Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); From 1360b5bb49fa460f7ccaf1ba37fa56999b0b95b1 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Fri, 23 Jul 2021 18:10:38 -0700 Subject: [PATCH 087/172] Apply fixes for convert-file script (#5206) --- scripts/goog_module/convert-file.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index f3138e9cf..6a8d36cd0 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -190,20 +190,27 @@ step3() { local comma_properties=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') inf "Detected references of ${require}: ${comma_properties}" - for require_prop in echo "${properties_accessed}"; do + for require_prop in $(echo "${properties_accessed}"); do inf "Updating references of ${require}.${require_prop} to ${require_name}.${require_prop}..." - perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_name}"'\.'"${require_prop}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'\.'"${require_prop}"'(?!\w)/'"${require_name}"'\.'"${require_prop}"'/g' "${filepath}" done fi inf "Updating direct references of ${require} to ${require_name}..." - perl -pi -e 's/'"${require}"'([^'\''\w]\.)/'"${require_name}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'(?!['\''\w\.])/'"${require_name}"'/g' "${filepath}" done local missing_requires=$(perl -nle'print $& while m{(? Date: Wed, 21 Jul 2021 15:32:39 -0700 Subject: [PATCH 088/172] Migrate core/field_label.js to ES6 const/let --- core/field_label.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label.js b/core/field_label.js index 5dc434c92..4a19dc07e 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -64,7 +64,7 @@ Blockly.FieldLabel.prototype.DEFAULT_VALUE = ''; * @nocollapse */ Blockly.FieldLabel.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. return new this(text, undefined, options); From a765a3016e4f9cc341f0b5696be548a5f0e6acfa Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:32:52 -0700 Subject: [PATCH 089/172] Migrate core/field_label.js to goog.module --- core/field_label.js | 31 +++++++++++++++++-------------- tests/deps.js | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index 4a19dc07e..4c15d4f96 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldLabel'); +goog.module('Blockly.FieldLabel'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Field'); goog.require('Blockly.fieldRegistry'); @@ -31,7 +32,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldLabel = function(opt_value, opt_class, opt_config) { +const FieldLabel = function(opt_value, opt_class, opt_config) { /** * The html class name to use for this field. * @type {?string} @@ -39,31 +40,31 @@ Blockly.FieldLabel = function(opt_value, opt_class, opt_config) { */ this.class_ = null; - Blockly.FieldLabel.superClass_.constructor.call( + FieldLabel.superClass_.constructor.call( this, opt_value, null, opt_config); if (!opt_config) { // If the config was not passed use old configuration. this.class_ = opt_class || null; } }; -Blockly.utils.object.inherits(Blockly.FieldLabel, Blockly.Field); +Blockly.utils.object.inherits(FieldLabel, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldLabel.prototype.DEFAULT_VALUE = ''; +FieldLabel.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldLabel from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and class). - * @return {!Blockly.FieldLabel} The new field instance. + * @return {!FieldLabel} The new field instance. * @package * @nocollapse */ -Blockly.FieldLabel.fromJson = function(options) { +FieldLabel.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. @@ -75,13 +76,13 @@ Blockly.FieldLabel.fromJson = function(options) { * editable. This field should not. * @type {boolean} */ -Blockly.FieldLabel.prototype.EDITABLE = false; +FieldLabel.prototype.EDITABLE = false; /** * @override */ -Blockly.FieldLabel.prototype.configure_ = function(config) { - Blockly.FieldLabel.superClass_.configure_.call(this, config); +FieldLabel.prototype.configure_ = function(config) { + FieldLabel.superClass_.configure_.call(this, config); this.class_ = config['class']; }; @@ -89,7 +90,7 @@ Blockly.FieldLabel.prototype.configure_ = function(config) { * Create block UI for this label. * @package */ -Blockly.FieldLabel.prototype.initView = function() { +FieldLabel.prototype.initView = function() { this.createTextElement_(); if (this.class_) { Blockly.utils.dom.addClass( @@ -103,7 +104,7 @@ Blockly.FieldLabel.prototype.initView = function() { * @return {?string} A valid string, or null if invalid. * @protected */ -Blockly.FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { +FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -114,7 +115,7 @@ Blockly.FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { * Set the CSS class applied to the field's textElement_. * @param {?string} cssClass The new CSS class name, or null to remove. */ -Blockly.FieldLabel.prototype.setClass = function(cssClass) { +FieldLabel.prototype.setClass = function(cssClass) { if (this.textElement_) { // This check isn't necessary, but it's faster than letting removeClass // figure it out. @@ -128,4 +129,6 @@ Blockly.FieldLabel.prototype.setClass = function(cssClass) { this.class_ = cssClass; }; -Blockly.fieldRegistry.register('field_label', Blockly.FieldLabel); +Blockly.fieldRegistry.register('field_label', FieldLabel); + +exports = FieldLabel; diff --git a/tests/deps.js b/tests/deps.js index 3dc163ac5..9b2ca48af 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -54,7 +54,7 @@ goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], [' goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From 4945825d6edeeed9728751cd27755dbe341c5ff5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:33:37 -0700 Subject: [PATCH 090/172] Migrate core/field_label.js named requires --- core/field_label.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index 4c15d4f96..c6f1bbcd8 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -14,11 +14,11 @@ goog.module('Blockly.FieldLabel'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); +const Field = goog.require('Blockly.Field'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const dom = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -29,7 +29,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldLabel = function(opt_value, opt_class, opt_config) { @@ -47,7 +47,7 @@ const FieldLabel = function(opt_value, opt_class, opt_config) { this.class_ = opt_class || null; } }; -Blockly.utils.object.inherits(FieldLabel, Blockly.Field); +inherits(FieldLabel, Field); /** * The default value for this field. @@ -65,7 +65,7 @@ FieldLabel.prototype.DEFAULT_VALUE = ''; * @nocollapse */ FieldLabel.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -93,7 +93,7 @@ FieldLabel.prototype.configure_ = function(config) { FieldLabel.prototype.initView = function() { this.createTextElement_(); if (this.class_) { - Blockly.utils.dom.addClass( + dom.addClass( /** @type {!SVGTextElement} */ (this.textElement_), this.class_); } }; @@ -120,15 +120,15 @@ FieldLabel.prototype.setClass = function(cssClass) { // This check isn't necessary, but it's faster than letting removeClass // figure it out. if (this.class_) { - Blockly.utils.dom.removeClass(this.textElement_, this.class_); + dom.removeClass(this.textElement_, this.class_); } if (cssClass) { - Blockly.utils.dom.addClass(this.textElement_, cssClass); + dom.addClass(this.textElement_, cssClass); } } this.class_ = cssClass; }; -Blockly.fieldRegistry.register('field_label', FieldLabel); +fieldRegistry.register('field_label', FieldLabel); exports = FieldLabel; From 0889defe55645de721ba84e56e2e26c4d1baf1ad Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:22:33 -0700 Subject: [PATCH 091/172] clang-format core/field_label.js --- core/field_label.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index c6f1bbcd8..8d23bbb18 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -27,7 +27,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * string. Defaults to an empty string if null or undefined. * @param {string=} opt_class Optional CSS class for the field's text. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -40,8 +41,7 @@ const FieldLabel = function(opt_value, opt_class, opt_config) { */ this.class_ = null; - FieldLabel.superClass_.constructor.call( - this, opt_value, null, opt_config); + FieldLabel.superClass_.constructor.call(this, opt_value, null, opt_config); if (!opt_config) { // If the config was not passed use old configuration. this.class_ = opt_class || null; From e997330085edd26b57dd254ae4622bb6186c4d40 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:24:42 -0700 Subject: [PATCH 092/172] Fix require order in core/field_label.js --- core/field_label.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label.js b/core/field_label.js index 8d23bbb18..822d476ab 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -15,8 +15,8 @@ goog.module('Blockly.FieldLabel'); goog.module.declareLegacyNamespace(); const Field = goog.require('Blockly.Field'); -const fieldRegistry = goog.require('Blockly.fieldRegistry'); const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); const {inherits} = goog.require('Blockly.utils.object'); const {replaceMessageReferences} = goog.require('Blockly.utils'); From ccd314279e022002fe4feaa1011e43dd6c66c5de Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:24:43 -0700 Subject: [PATCH 093/172] 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 094/172] 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 71e187adc9af78b56c171ebaf46c8d7926172a28 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 17:59:35 -0700 Subject: [PATCH 095/172] Migrate core/gesture.js to ES6 const/let --- core/gesture.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index 483d73a25..59dbd57f0 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -266,8 +266,8 @@ Blockly.Gesture.prototype.dispose = function() { * @private */ Blockly.Gesture.prototype.updateFromEvent_ = function(e) { - var currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); - var changed = this.updateDragDelta_(currentXY); + const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. if (changed) { this.updateIsDragging_(); @@ -290,11 +290,11 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { - var currentDragDelta = + const currentDragDelta = Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - var limitRadius = this.flyout_ ? + const limitRadius = this.flyout_ ? Blockly.internalConstants.FLYOUT_DRAG_RADIUS : Blockly.internalConstants.DRAG_RADIUS; @@ -394,7 +394,7 @@ Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { * @private */ Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { - var wsMovable = this.flyout_ ? + const wsMovable = this.flyout_ ? this.flyout_.isScrollable() : this.startWorkspace_ && this.startWorkspace_.isDraggable(); @@ -439,8 +439,9 @@ Blockly.Gesture.prototype.updateIsDragging_ = function() { * @private */ Blockly.Gesture.prototype.startDraggingBlock_ = function() { - var BlockDraggerClass = Blockly.registry.getClassFromOptions( - Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); + const BlockDraggerClass = Blockly.registry.getClassFromOptions( + Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, + true); this.blockDragger_ = new BlockDraggerClass( /** @type {!Blockly.BlockSvg} */ (this.targetBlock_), @@ -747,12 +748,12 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); } - var newBlock = this.flyout_.createBlock(this.targetBlock_); + const newBlock = this.flyout_.createBlock(this.targetBlock_); newBlock.scheduleSnapAndBump(); } } else { // Clicks events are on the start block, even if it was a shadow. - var event = new (Blockly.Events.get(Blockly.Events.CLICK))( + const event = new (Blockly.Events.get(Blockly.Events.CLICK))( this.startBlock_, this.startWorkspace_.id, 'block'); Blockly.Events.fire(event); } @@ -767,7 +768,7 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { * @private */ Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { - var ws = this.creatorWorkspace_; + const ws = this.creatorWorkspace_; if (Blockly.selected) { Blockly.selected.unselect(); } @@ -888,7 +889,7 @@ Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { */ Blockly.Gesture.prototype.isBubbleClick_ = function() { // A bubble click starts on a bubble and never escapes the drag radius. - var hasStartBubble = !!this.startBubble_; + const hasStartBubble = !!this.startBubble_; return hasStartBubble && !this.hasExceededDragRadius_; }; @@ -901,7 +902,7 @@ Blockly.Gesture.prototype.isBubbleClick_ = function() { Blockly.Gesture.prototype.isBlockClick_ = function() { // A block click starts on a block, never escapes the drag radius, and is not // a field click. - var hasStartBlock = !!this.startBlock_; + const hasStartBlock = !!this.startBlock_; return hasStartBlock && !this.hasExceededDragRadius_ && !this.isFieldClick_(); }; @@ -912,7 +913,7 @@ Blockly.Gesture.prototype.isBlockClick_ = function() { * @private */ Blockly.Gesture.prototype.isFieldClick_ = function() { - var fieldClickable = + const fieldClickable = this.startField_ ? this.startField_.isClickable() : false; return fieldClickable && !this.hasExceededDragRadius_ && (!this.flyout_ || !this.flyout_.autoClose); @@ -925,7 +926,7 @@ Blockly.Gesture.prototype.isFieldClick_ = function() { * @private */ Blockly.Gesture.prototype.isWorkspaceClick_ = function() { - var onlyTouchedWorkspace = + const onlyTouchedWorkspace = !this.startBlock_ && !this.startBubble_ && !this.startField_; return onlyTouchedWorkspace && !this.hasExceededDragRadius_; }; @@ -991,8 +992,8 @@ Blockly.Gesture.prototype.getCurrentDragger = function() { * @return {boolean} True if gesture is occurring. */ Blockly.Gesture.inProgress = function() { - var workspaces = Blockly.Workspace.getAll(); - for (var i = 0, workspace; (workspace = workspaces[i]); i++) { + const workspaces = Blockly.Workspace.getAll(); + for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { return true; } From 1d847eda4a847ad0ac77326db8a79cbd7d2e3893 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:45:51 -0700 Subject: [PATCH 096/172] Migrate core/gesture.js to goog.module --- core/gesture.js | 90 ++++++++++++++++++++++++++----------------------- tests/deps.js | 2 +- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index 59dbd57f0..a5b786b5b 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Gesture'); +goog.module('Blockly.Gesture'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockAnimations'); /** @suppress {extraRequire} */ @@ -22,6 +23,7 @@ goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); goog.require('Blockly.internalConstants'); +goog.require('Blockly.registry'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); @@ -50,7 +52,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * this gesture and has a reference to it. * @constructor */ -Blockly.Gesture = function(e, creatorWorkspace) { +const Gesture = function(e, creatorWorkspace) { /** * The position of the mouse when the gesture started. Units are CSS pixels, * with (0, 0) at the top left of the browser window (mouseEvent clientX/Y). @@ -236,7 +238,7 @@ Blockly.Gesture = function(e, creatorWorkspace) { * Sever all links from this object. * @package */ -Blockly.Gesture.prototype.dispose = function() { +Gesture.prototype.dispose = function() { Blockly.Touch.clearTouchIdentifier(); Blockly.Tooltip.unblock(); // Clear the owner's reference to this gesture. @@ -265,7 +267,7 @@ Blockly.Gesture.prototype.dispose = function() { * @param {!Event} e The most recent mouse or touch event. * @private */ -Blockly.Gesture.prototype.updateFromEvent_ = function(e) { +Gesture.prototype.updateFromEvent_ = function(e) { const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. @@ -284,7 +286,7 @@ Blockly.Gesture.prototype.updateFromEvent_ = function(e) { * first time. * @private */ -Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { +Gesture.prototype.updateDragDelta_ = function(currentXY) { this.currentDragDeltaXY_ = Blockly.utils.Coordinate.difference( currentXY, /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); @@ -314,7 +316,7 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { * @return {boolean} True if a block is being dragged from the flyout. * @private */ -Blockly.Gesture.prototype.updateIsDraggingFromFlyout_ = function() { +Gesture.prototype.updateIsDraggingFromFlyout_ = function() { if (!this.targetBlock_) { return false; } @@ -348,7 +350,7 @@ Blockly.Gesture.prototype.updateIsDraggingFromFlyout_ = function() { * @return {boolean} True if a bubble is being dragged. * @private */ -Blockly.Gesture.prototype.updateIsDraggingBubble_ = function() { +Gesture.prototype.updateIsDraggingBubble_ = function() { if (!this.startBubble_) { return false; } @@ -367,7 +369,7 @@ Blockly.Gesture.prototype.updateIsDraggingBubble_ = function() { * @return {boolean} True if a block is being dragged. * @private */ -Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { +Gesture.prototype.updateIsDraggingBlock_ = function() { if (!this.targetBlock_) { return false; } @@ -393,7 +395,7 @@ Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { * WorkspaceDragger and starts the drag. * @private */ -Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { +Gesture.prototype.updateIsDraggingWorkspace_ = function() { const wsMovable = this.flyout_ ? this.flyout_.isScrollable() : this.startWorkspace_ && this.startWorkspace_.isDraggable(); @@ -415,7 +417,7 @@ Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { * drag radius is exceeded. It should be called no more than once per gesture. * @private */ -Blockly.Gesture.prototype.updateIsDragging_ = function() { +Gesture.prototype.updateIsDragging_ = function() { // Sanity check. if (this.calledUpdateIsDragging_) { throw Error('updateIsDragging_ should only be called once per gesture.'); @@ -438,7 +440,7 @@ Blockly.Gesture.prototype.updateIsDragging_ = function() { * Create a block dragger and start dragging the selected block. * @private */ -Blockly.Gesture.prototype.startDraggingBlock_ = function() { +Gesture.prototype.startDraggingBlock_ = function() { const BlockDraggerClass = Blockly.registry.getClassFromOptions( Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); @@ -455,7 +457,7 @@ Blockly.Gesture.prototype.startDraggingBlock_ = function() { * @private */ // TODO (fenichel): Possibly combine this and startDraggingBlock_. -Blockly.Gesture.prototype.startDraggingBubble_ = function() { +Gesture.prototype.startDraggingBubble_ = function() { this.bubbleDragger_ = new Blockly.BubbleDragger( /** @type {!Blockly.IBubble} */ (this.startBubble_), /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); @@ -469,7 +471,7 @@ Blockly.Gesture.prototype.startDraggingBubble_ = function() { * @param {!Event} e A mouse down or touch start event. * @package */ -Blockly.Gesture.prototype.doStart = function(e) { +Gesture.prototype.doStart = function(e) { if (Blockly.utils.isTargetInput(e)) { this.cancel(); return; @@ -519,7 +521,7 @@ Blockly.Gesture.prototype.doStart = function(e) { * @param {!Event} e A mouse down or touch start event. * @package */ -Blockly.Gesture.prototype.bindMouseEvents = function(e) { +Gesture.prototype.bindMouseEvents = function(e) { this.onMoveWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mousemove', null, this.handleMove.bind(this)); this.onUpWrapper_ = Blockly.browserEvents.conditionalBind( @@ -534,7 +536,7 @@ Blockly.Gesture.prototype.bindMouseEvents = function(e) { * @param {!Event} e A mouse move or touch move event. * @package */ -Blockly.Gesture.prototype.handleMove = function(e) { +Gesture.prototype.handleMove = function(e) { this.updateFromEvent_(e); if (this.isDraggingWorkspace_) { this.workspaceDragger_.drag(this.currentDragDeltaXY_); @@ -554,7 +556,7 @@ Blockly.Gesture.prototype.handleMove = function(e) { * @param {!Event} e A mouse up or touch end event. * @package */ -Blockly.Gesture.prototype.handleUp = function(e) { +Gesture.prototype.handleUp = function(e) { this.updateFromEvent_(e); Blockly.longStop_(); @@ -596,7 +598,7 @@ Blockly.Gesture.prototype.handleUp = function(e) { * end the drag at the most recent location. * @package */ -Blockly.Gesture.prototype.cancel = function() { +Gesture.prototype.cancel = function() { // Disposing of a block cancels in-progress drags, but dragging to a delete // area disposes of a block and leads to recursive disposal. Break that cycle. if (this.isEnding_) { @@ -620,7 +622,7 @@ Blockly.Gesture.prototype.cancel = function() { * @param {!Event} e A mouse move or touch move event. * @package */ -Blockly.Gesture.prototype.handleRightClick = function(e) { +Gesture.prototype.handleRightClick = function(e) { if (this.targetBlock_) { this.bringBlockToFront_(); Blockly.hideChaff(!!this.flyout_); @@ -645,7 +647,7 @@ Blockly.Gesture.prototype.handleRightClick = function(e) { * @param {!Blockly.WorkspaceSvg} ws The workspace the event hit. * @package */ -Blockly.Gesture.prototype.handleWsStart = function(e, ws) { +Gesture.prototype.handleWsStart = function(e, ws) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleWsStart, ' + @@ -661,7 +663,7 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { * @param {!Blockly.WorkspaceSvg} ws The workspace that a user clicks on. * @private */ -Blockly.Gesture.prototype.fireWorkspaceClick_ = function(ws) { +Gesture.prototype.fireWorkspaceClick_ = function(ws) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CLICK))( null, ws.id, 'workspace')); }; @@ -672,7 +674,7 @@ Blockly.Gesture.prototype.fireWorkspaceClick_ = function(ws) { * @param {!Blockly.IFlyout} flyout The flyout the event hit. * @package */ -Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { +Gesture.prototype.handleFlyoutStart = function(e, flyout) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleFlyoutStart, ' + @@ -688,7 +690,7 @@ Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { * @param {!Blockly.BlockSvg} block The block the event hit. * @package */ -Blockly.Gesture.prototype.handleBlockStart = function(e, block) { +Gesture.prototype.handleBlockStart = function(e, block) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleBlockStart, ' + @@ -704,7 +706,7 @@ Blockly.Gesture.prototype.handleBlockStart = function(e, block) { * @param {!Blockly.IBubble} bubble The bubble the event hit. * @package */ -Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) { +Gesture.prototype.handleBubbleStart = function(e, bubble) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleBubbleStart, ' + @@ -722,7 +724,7 @@ Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) { * Execute a bubble click. * @private */ -Blockly.Gesture.prototype.doBubbleClick_ = function() { +Gesture.prototype.doBubbleClick_ = function() { // TODO (#1673): Consistent handling of single clicks. this.startBubble_.setFocus && this.startBubble_.setFocus(); this.startBubble_.select && this.startBubble_.select(); @@ -732,7 +734,7 @@ Blockly.Gesture.prototype.doBubbleClick_ = function() { * Execute a field click. * @private */ -Blockly.Gesture.prototype.doFieldClick_ = function() { +Gesture.prototype.doFieldClick_ = function() { this.startField_.showEditor(this.mostRecentEvent_); this.bringBlockToFront_(); }; @@ -741,7 +743,7 @@ Blockly.Gesture.prototype.doFieldClick_ = function() { * Execute a block click. * @private */ -Blockly.Gesture.prototype.doBlockClick_ = function() { +Gesture.prototype.doBlockClick_ = function() { // Block click in an autoclosing flyout. if (this.flyout_ && this.flyout_.autoClose) { if (this.targetBlock_.isEnabled()) { @@ -767,7 +769,7 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { * @param {!Event} _e A mouse up or touch end event. * @private */ -Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { +Gesture.prototype.doWorkspaceClick_ = function(_e) { const ws = this.creatorWorkspace_; if (Blockly.selected) { Blockly.selected.unselect(); @@ -784,7 +786,7 @@ Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { * not occluded by other blocks. * @private */ -Blockly.Gesture.prototype.bringBlockToFront_ = function() { +Gesture.prototype.bringBlockToFront_ = function() { // Blocks in the flyout don't overlap, so skip the work. if (this.targetBlock_ && !this.flyout_) { this.targetBlock_.bringToFront(); @@ -798,7 +800,7 @@ Blockly.Gesture.prototype.bringBlockToFront_ = function() { * @param {Blockly.Field} field The field the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartField = function(field) { +Gesture.prototype.setStartField = function(field) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.setStartField, ' + @@ -814,7 +816,7 @@ Blockly.Gesture.prototype.setStartField = function(field) { * @param {Blockly.IBubble} bubble The bubble the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartBubble = function(bubble) { +Gesture.prototype.setStartBubble = function(bubble) { if (!this.startBubble_) { this.startBubble_ = bubble; } @@ -826,7 +828,7 @@ Blockly.Gesture.prototype.setStartBubble = function(bubble) { * @param {Blockly.BlockSvg} block The block the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartBlock = function(block) { +Gesture.prototype.setStartBlock = function(block) { // If the gesture already went through a bubble, don't set the start block. if (!this.startBlock_ && !this.startBubble_) { this.startBlock_ = block; @@ -845,7 +847,7 @@ Blockly.Gesture.prototype.setStartBlock = function(block) { * @param {Blockly.BlockSvg} block The block the gesture targets. * @private */ -Blockly.Gesture.prototype.setTargetBlock_ = function(block) { +Gesture.prototype.setTargetBlock_ = function(block) { if (block.isShadow()) { this.setTargetBlock_(block.getParent()); } else { @@ -858,7 +860,7 @@ Blockly.Gesture.prototype.setTargetBlock_ = function(block) { * @param {Blockly.WorkspaceSvg} ws The workspace the gesture started on. * @private */ -Blockly.Gesture.prototype.setStartWorkspace_ = function(ws) { +Gesture.prototype.setStartWorkspace_ = function(ws) { if (!this.startWorkspace_) { this.startWorkspace_ = ws; } @@ -869,7 +871,7 @@ Blockly.Gesture.prototype.setStartWorkspace_ = function(ws) { * @param {Blockly.IFlyout} flyout The flyout the gesture started on. * @private */ -Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { +Gesture.prototype.setStartFlyout_ = function(flyout) { if (!this.flyout_) { this.flyout_ = flyout; } @@ -887,7 +889,7 @@ Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { * @return {boolean} Whether this gesture was a click on a bubble. * @private */ -Blockly.Gesture.prototype.isBubbleClick_ = function() { +Gesture.prototype.isBubbleClick_ = function() { // A bubble click starts on a bubble and never escapes the drag radius. const hasStartBubble = !!this.startBubble_; return hasStartBubble && !this.hasExceededDragRadius_; @@ -899,7 +901,7 @@ Blockly.Gesture.prototype.isBubbleClick_ = function() { * @return {boolean} Whether this gesture was a click on a block. * @private */ -Blockly.Gesture.prototype.isBlockClick_ = function() { +Gesture.prototype.isBlockClick_ = function() { // A block click starts on a block, never escapes the drag radius, and is not // a field click. const hasStartBlock = !!this.startBlock_; @@ -912,7 +914,7 @@ Blockly.Gesture.prototype.isBlockClick_ = function() { * @return {boolean} Whether this gesture was a click on a field. * @private */ -Blockly.Gesture.prototype.isFieldClick_ = function() { +Gesture.prototype.isFieldClick_ = function() { const fieldClickable = this.startField_ ? this.startField_.isClickable() : false; return fieldClickable && !this.hasExceededDragRadius_ && @@ -925,7 +927,7 @@ Blockly.Gesture.prototype.isFieldClick_ = function() { * @return {boolean} Whether this gesture was a click on a workspace. * @private */ -Blockly.Gesture.prototype.isWorkspaceClick_ = function() { +Gesture.prototype.isWorkspaceClick_ = function() { const onlyTouchedWorkspace = !this.startBlock_ && !this.startBubble_ && !this.startField_; return onlyTouchedWorkspace && !this.hasExceededDragRadius_; @@ -940,7 +942,7 @@ Blockly.Gesture.prototype.isWorkspaceClick_ = function() { * @return {boolean} True if this gesture is a drag of a workspace or block. * @package */ -Blockly.Gesture.prototype.isDragging = function() { +Gesture.prototype.isDragging = function() { return this.isDraggingWorkspace_ || this.isDraggingBlock_ || this.isDraggingBubble_; }; @@ -952,7 +954,7 @@ Blockly.Gesture.prototype.isDragging = function() { * @return {boolean} Whether this gesture was a click on a workspace. * @package */ -Blockly.Gesture.prototype.hasStarted = function() { +Gesture.prototype.hasStarted = function() { return this.hasStarted_; }; @@ -963,7 +965,7 @@ Blockly.Gesture.prototype.hasStarted = function() { * marker blocks. * @package */ -Blockly.Gesture.prototype.getInsertionMarkers = function() { +Gesture.prototype.getInsertionMarkers = function() { if (this.blockDragger_) { return this.blockDragger_.getInsertionMarkers(); } @@ -976,7 +978,7 @@ Blockly.Gesture.prototype.getInsertionMarkers = function() { * @return {!Blockly.WorkspaceDragger|!Blockly.BubbleDragger|!Blockly.IBlockDragger|null} * The dragger that is currently in use or null if no drag is in progress. */ -Blockly.Gesture.prototype.getCurrentDragger = function() { +Gesture.prototype.getCurrentDragger = function() { if (this.isDraggingBlock_) { return this.blockDragger_; } else if (this.isDraggingWorkspace_) { @@ -991,7 +993,7 @@ Blockly.Gesture.prototype.getCurrentDragger = function() { * Is a drag or other gesture currently in progress on any workspace? * @return {boolean} True if gesture is occurring. */ -Blockly.Gesture.inProgress = function() { +Gesture.inProgress = function() { const workspaces = Blockly.Workspace.getAll(); for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { @@ -1000,3 +1002,5 @@ Blockly.Gesture.inProgress = function() { } return false; }; + +exports = Gesture; diff --git a/tests/deps.js b/tests/deps.js index 9b2ca48af..6d78e4217 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -66,7 +66,7 @@ goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Bl goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); From 12aa4af67462d8c5003836c10cb13ae2b9e31a1d Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:47:55 -0700 Subject: [PATCH 097/172] Migrate core/gesture.js named requires --- core/gesture.js | 177 +++++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 85 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index a5b786b5b..c74efb2f4 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -14,29 +14,36 @@ goog.module('Blockly.Gesture'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockAnimations'); +// TODO(#5073): Add Blockly require after fixing circular dependency. +// goog.require('Blockly'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const BubbleDragger = goog.require('Blockly.BubbleDragger'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ +const Events = goog.require('Blockly.Events'); +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const IBlockDragger = goog.requireType('Blockly.IBlockDragger'); +/* eslint-disable-next-line no-unused-vars */ +const IBubble = goog.requireType('Blockly.IBubble'); +/* eslint-disable-next-line no-unused-vars */ +const IFlyout = goog.requireType('Blockly.IFlyout'); +const Tooltip = goog.require('Blockly.Tooltip'); +const Touch = goog.require('Blockly.Touch'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.require('Blockly.Workspace'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const WorkspaceDragger = goog.require('Blockly.WorkspaceDragger'); +const blockAnimations = goog.require('Blockly.blockAnimations'); +const browserEvents = goog.require('Blockly.browserEvents'); +const internalConstants = goog.require('Blockly.internalConstants'); +const registry = goog.require('Blockly.registry'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.BlockDragger'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.BubbleDragger'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.registry'); -goog.require('Blockly.Tooltip'); -goog.require('Blockly.Touch'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.Workspace'); -goog.require('Blockly.WorkspaceDragger'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IBlockDragger'); -goog.requireType('Blockly.IBubble'); -goog.requireType('Blockly.IFlyout'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -48,7 +55,7 @@ goog.requireType('Blockly.WorkspaceSvg'); /** * Class for one gesture. * @param {!Event} e The event that kicked off this gesture. - * @param {!Blockly.WorkspaceSvg} creatorWorkspace The workspace that created + * @param {!WorkspaceSvg} creatorWorkspace The workspace that created * this gesture and has a reference to it. * @constructor */ @@ -56,7 +63,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The position of the mouse when the gesture started. Units are CSS pixels, * with (0, 0) at the top left of the browser window (mouseEvent clientX/Y). - * @type {Blockly.utils.Coordinate} + * @type {Coordinate} * @private */ this.mouseDownXY_ = null; @@ -64,15 +71,15 @@ const Gesture = function(e, creatorWorkspace) { /** * How far the mouse has moved during this drag, in pixel units. * (0, 0) is at this.mouseDownXY_. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ - this.currentDragDeltaXY_ = new Blockly.utils.Coordinate(0, 0); + this.currentDragDeltaXY_ = new Coordinate(0, 0); /** * The bubble that the gesture started on, or null if it did not start on a * bubble. - * @type {Blockly.IBubble} + * @type {IBubble} * @private */ this.startBubble_ = null; @@ -80,7 +87,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The field that the gesture started on, or null if it did not start on a * field. - * @type {Blockly.Field} + * @type {Field} * @private */ this.startField_ = null; @@ -88,7 +95,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The block that the gesture started on, or null if it did not start on a * block. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @private */ this.startBlock_ = null; @@ -98,7 +105,7 @@ const Gesture = function(e, creatorWorkspace) { * shadow block, this is the first non-shadow parent of the block. If the * gesture started in the flyout, this is the root block of the block group * that was clicked or dragged. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @private */ this.targetBlock_ = null; @@ -107,7 +114,7 @@ const Gesture = function(e, creatorWorkspace) { * The workspace that the gesture started on. There may be multiple * workspaces on a page; this is more accurate than using * Blockly.getMainWorkspace(). - * @type {Blockly.WorkspaceSvg} + * @type {WorkspaceSvg} * @protected */ this.startWorkspace_ = null; @@ -117,7 +124,7 @@ const Gesture = function(e, creatorWorkspace) { * to the gesture, which will need to be cleared at deletion. * This may be different from the start workspace. For instance, a flyout is * a workspace, but its parent workspace manages gestures for it. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.creatorWorkspace_ = creatorWorkspace; @@ -162,7 +169,7 @@ const Gesture = function(e, creatorWorkspace) { /** * A handle to use to unbind a mouse move listener at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @protected */ this.onMoveWrapper_ = null; @@ -170,21 +177,21 @@ const Gesture = function(e, creatorWorkspace) { /** * A handle to use to unbind a mouse up listener at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @protected */ this.onUpWrapper_ = null; /** * The object tracking a bubble drag, or null if none is in progress. - * @type {Blockly.BubbleDragger} + * @type {BubbleDragger} * @private */ this.bubbleDragger_ = null; /** * The object tracking a block drag, or null if none is in progress. - * @type {?Blockly.IBlockDragger} + * @type {?IBlockDragger} * @private */ this.blockDragger_ = null; @@ -192,14 +199,14 @@ const Gesture = function(e, creatorWorkspace) { /** * The object tracking a workspace or flyout workspace drag, or null if none * is in progress. - * @type {Blockly.WorkspaceDragger} + * @type {WorkspaceDragger} * @private */ this.workspaceDragger_ = null; /** * The flyout a gesture started in, if any. - * @type {Blockly.IFlyout} + * @type {IFlyout} * @private */ this.flyout_ = null; @@ -231,7 +238,7 @@ const Gesture = function(e, creatorWorkspace) { * @type {boolean} * @private */ - this.healStack_ = !Blockly.internalConstants.DRAG_STACK; + this.healStack_ = !internalConstants.DRAG_STACK; }; /** @@ -239,16 +246,16 @@ const Gesture = function(e, creatorWorkspace) { * @package */ Gesture.prototype.dispose = function() { - Blockly.Touch.clearTouchIdentifier(); - Blockly.Tooltip.unblock(); + Touch.clearTouchIdentifier(); + Tooltip.unblock(); // Clear the owner's reference to this gesture. this.creatorWorkspace_.clearGesture(); if (this.onMoveWrapper_) { - Blockly.browserEvents.unbind(this.onMoveWrapper_); + browserEvents.unbind(this.onMoveWrapper_); } if (this.onUpWrapper_) { - Blockly.browserEvents.unbind(this.onUpWrapper_); + browserEvents.unbind(this.onUpWrapper_); } if (this.blockDragger_) { @@ -268,7 +275,7 @@ Gesture.prototype.dispose = function() { * @private */ Gesture.prototype.updateFromEvent_ = function(e) { - const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const currentXY = new Coordinate(e.clientX, e.clientY); const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. if (changed) { @@ -280,25 +287,25 @@ Gesture.prototype.updateFromEvent_ = function(e) { /** * DO MATH to set currentDragDeltaXY_ based on the most recent mouse position. - * @param {!Blockly.utils.Coordinate} currentXY The most recent mouse/pointer + * @param {!Coordinate} currentXY The most recent mouse/pointer * position, in pixel units, with (0, 0) at the window's top left corner. * @return {boolean} True if the drag just exceeded the drag radius for the * first time. * @private */ Gesture.prototype.updateDragDelta_ = function(currentXY) { - this.currentDragDeltaXY_ = Blockly.utils.Coordinate.difference( + this.currentDragDeltaXY_ = Coordinate.difference( currentXY, - /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); + /** @type {!Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { const currentDragDelta = - Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); + Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. const limitRadius = this.flyout_ ? - Blockly.internalConstants.FLYOUT_DRAG_RADIUS : - Blockly.internalConstants.DRAG_RADIUS; + internalConstants.FLYOUT_DRAG_RADIUS : + internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; @@ -329,8 +336,8 @@ Gesture.prototype.updateIsDraggingFromFlyout_ = function() { this.startWorkspace_.updateScreenCalculationsIfScrolled(); // Start the event group now, so that the same event group is used for block // creation and block dragging. - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!Events.getGroup()) { + Events.setGroup(true); } // The start block is no longer relevant, because this is a drag. this.startBlock_ = null; @@ -404,8 +411,8 @@ Gesture.prototype.updateIsDraggingWorkspace_ = function() { return; } - this.workspaceDragger_ = new Blockly.WorkspaceDragger( - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + this.workspaceDragger_ = new WorkspaceDragger( + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.isDraggingWorkspace_ = true; this.workspaceDragger_.startDrag(); @@ -441,13 +448,13 @@ Gesture.prototype.updateIsDragging_ = function() { * @private */ Gesture.prototype.startDraggingBlock_ = function() { - const BlockDraggerClass = Blockly.registry.getClassFromOptions( - Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, + const BlockDraggerClass = registry.getClassFromOptions( + registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); this.blockDragger_ = new BlockDraggerClass( - /** @type {!Blockly.BlockSvg} */ (this.targetBlock_), - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + /** @type {!BlockSvg} */ (this.targetBlock_), + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.blockDragger_.startDrag(this.currentDragDeltaXY_, this.healStack_); this.blockDragger_.drag(this.mostRecentEvent_, this.currentDragDeltaXY_); }; @@ -458,9 +465,9 @@ Gesture.prototype.startDraggingBlock_ = function() { */ // TODO (fenichel): Possibly combine this and startDraggingBlock_. Gesture.prototype.startDraggingBubble_ = function() { - this.bubbleDragger_ = new Blockly.BubbleDragger( - /** @type {!Blockly.IBubble} */ (this.startBubble_), - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + this.bubbleDragger_ = new BubbleDragger( + /** @type {!IBubble} */ (this.startBubble_), + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.bubbleDragger_.startBubbleDrag(); this.bubbleDragger_.dragBubble( this.mostRecentEvent_, this.currentDragDeltaXY_); @@ -472,13 +479,13 @@ Gesture.prototype.startDraggingBubble_ = function() { * @package */ Gesture.prototype.doStart = function(e) { - if (Blockly.utils.isTargetInput(e)) { + if (utils.isTargetInput(e)) { this.cancel(); return; } this.hasStarted_ = true; - Blockly.blockAnimations.disconnectUiStop(); + blockAnimations.disconnectUiStop(); this.startWorkspace_.updateScreenCalculationsIfScrolled(); if (this.startWorkspace_.isMutator) { // Mutator's coordinate system could be out of date because the bubble was @@ -493,13 +500,13 @@ Gesture.prototype.doStart = function(e) { this.startWorkspace_.markFocused(); this.mostRecentEvent_ = e; - Blockly.Tooltip.block(); + Tooltip.block(); if (this.targetBlock_) { this.targetBlock_.select(); } - if (Blockly.utils.isRightButton(e)) { + if (utils.isRightButton(e)) { this.handleRightClick(e); return; } @@ -510,7 +517,7 @@ Gesture.prototype.doStart = function(e) { Blockly.longStart(e, this); } - this.mouseDownXY_ = new Blockly.utils.Coordinate(e.clientX, e.clientY); + this.mouseDownXY_ = new Coordinate(e.clientX, e.clientY); this.healStack_ = e.altKey || e.ctrlKey || e.metaKey; this.bindMouseEvents(e); @@ -522,9 +529,9 @@ Gesture.prototype.doStart = function(e) { * @package */ Gesture.prototype.bindMouseEvents = function(e) { - this.onMoveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMoveWrapper_ = browserEvents.conditionalBind( document, 'mousemove', null, this.handleMove.bind(this)); - this.onUpWrapper_ = Blockly.browserEvents.conditionalBind( + this.onUpWrapper_ = browserEvents.conditionalBind( document, 'mouseup', null, this.handleUp.bind(this)); e.preventDefault(); @@ -644,7 +651,7 @@ Gesture.prototype.handleRightClick = function(e) { /** * Handle a mousedown/touchstart event on a workspace. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.WorkspaceSvg} ws The workspace the event hit. + * @param {!WorkspaceSvg} ws The workspace the event hit. * @package */ Gesture.prototype.handleWsStart = function(e, ws) { @@ -660,18 +667,18 @@ Gesture.prototype.handleWsStart = function(e, ws) { /** * Fires a workspace click event. - * @param {!Blockly.WorkspaceSvg} ws The workspace that a user clicks on. + * @param {!WorkspaceSvg} ws The workspace that a user clicks on. * @private */ Gesture.prototype.fireWorkspaceClick_ = function(ws) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CLICK))( + Events.fire(new (Events.get(Events.CLICK))( null, ws.id, 'workspace')); }; /** * Handle a mousedown/touchstart event on a flyout. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.IFlyout} flyout The flyout the event hit. + * @param {!IFlyout} flyout The flyout the event hit. * @package */ Gesture.prototype.handleFlyoutStart = function(e, flyout) { @@ -687,7 +694,7 @@ Gesture.prototype.handleFlyoutStart = function(e, flyout) { /** * Handle a mousedown/touchstart event on a block. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.BlockSvg} block The block the event hit. + * @param {!BlockSvg} block The block the event hit. * @package */ Gesture.prototype.handleBlockStart = function(e, block) { @@ -703,7 +710,7 @@ Gesture.prototype.handleBlockStart = function(e, block) { /** * Handle a mousedown/touchstart event on a bubble. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.IBubble} bubble The bubble the event hit. + * @param {!IBubble} bubble The bubble the event hit. * @package */ Gesture.prototype.handleBubbleStart = function(e, bubble) { @@ -747,20 +754,20 @@ Gesture.prototype.doBlockClick_ = function() { // Block click in an autoclosing flyout. if (this.flyout_ && this.flyout_.autoClose) { if (this.targetBlock_.isEnabled()) { - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!Events.getGroup()) { + Events.setGroup(true); } const newBlock = this.flyout_.createBlock(this.targetBlock_); newBlock.scheduleSnapAndBump(); } } else { // Clicks events are on the start block, even if it was a shadow. - const event = new (Blockly.Events.get(Blockly.Events.CLICK))( + const event = new (Events.get(Events.CLICK))( this.startBlock_, this.startWorkspace_.id, 'block'); - Blockly.Events.fire(event); + Events.fire(event); } this.bringBlockToFront_(); - Blockly.Events.setGroup(false); + Events.setGroup(false); }; /** @@ -797,7 +804,7 @@ Gesture.prototype.bringBlockToFront_ = function() { /** * Record the field that a gesture started on. - * @param {Blockly.Field} field The field the gesture started on. + * @param {Field} field The field the gesture started on. * @package */ Gesture.prototype.setStartField = function(field) { @@ -813,7 +820,7 @@ Gesture.prototype.setStartField = function(field) { /** * Record the bubble that a gesture started on - * @param {Blockly.IBubble} bubble The bubble the gesture started on. + * @param {IBubble} bubble The bubble the gesture started on. * @package */ Gesture.prototype.setStartBubble = function(bubble) { @@ -825,7 +832,7 @@ Gesture.prototype.setStartBubble = function(bubble) { /** * Record the block that a gesture started on, and set the target block * appropriately. - * @param {Blockly.BlockSvg} block The block the gesture started on. + * @param {BlockSvg} block The block the gesture started on. * @package */ Gesture.prototype.setStartBlock = function(block) { @@ -844,7 +851,7 @@ Gesture.prototype.setStartBlock = function(block) { * Record the block that a gesture targets, meaning the block that will be * dragged if this turns into a drag. If this block is a shadow, that will be * its first non-shadow parent. - * @param {Blockly.BlockSvg} block The block the gesture targets. + * @param {BlockSvg} block The block the gesture targets. * @private */ Gesture.prototype.setTargetBlock_ = function(block) { @@ -857,7 +864,7 @@ Gesture.prototype.setTargetBlock_ = function(block) { /** * Record the workspace that a gesture started on. - * @param {Blockly.WorkspaceSvg} ws The workspace the gesture started on. + * @param {WorkspaceSvg} ws The workspace the gesture started on. * @private */ Gesture.prototype.setStartWorkspace_ = function(ws) { @@ -868,7 +875,7 @@ Gesture.prototype.setStartWorkspace_ = function(ws) { /** * Record the flyout that a gesture started on. - * @param {Blockly.IFlyout} flyout The flyout the gesture started on. + * @param {IFlyout} flyout The flyout the gesture started on. * @private */ Gesture.prototype.setStartFlyout_ = function(flyout) { @@ -961,7 +968,7 @@ Gesture.prototype.hasStarted = function() { /** * Get a list of the insertion markers that currently exist. Block drags have * 0, 1, or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion + * @return {!Array} A possibly empty list of insertion * marker blocks. * @package */ @@ -975,7 +982,7 @@ Gesture.prototype.getInsertionMarkers = function() { /** * Gets the current dragger if an item is being dragged. Null if nothing is * being dragged. - * @return {!Blockly.WorkspaceDragger|!Blockly.BubbleDragger|!Blockly.IBlockDragger|null} + * @return {!WorkspaceDragger|!BubbleDragger|!IBlockDragger|null} * The dragger that is currently in use or null if no drag is in progress. */ Gesture.prototype.getCurrentDragger = function() { @@ -994,7 +1001,7 @@ Gesture.prototype.getCurrentDragger = function() { * @return {boolean} True if gesture is occurring. */ Gesture.inProgress = function() { - const workspaces = Blockly.Workspace.getAll(); + const workspaces = Workspace.getAll(); for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { return true; From 46c0050ce6f4ec2bbc5a87c3e4e2adf9b4b72aaf Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:48:02 -0700 Subject: [PATCH 098/172] clang-format core/gesture.js --- core/gesture.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index c74efb2f4..933930e44 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -299,13 +299,11 @@ Gesture.prototype.updateDragDelta_ = function(currentXY) { /** @type {!Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { - const currentDragDelta = - Coordinate.magnitude(this.currentDragDeltaXY_); + const currentDragDelta = Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - const limitRadius = this.flyout_ ? - internalConstants.FLYOUT_DRAG_RADIUS : - internalConstants.DRAG_RADIUS; + const limitRadius = this.flyout_ ? internalConstants.FLYOUT_DRAG_RADIUS : + internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; @@ -449,8 +447,7 @@ Gesture.prototype.updateIsDragging_ = function() { */ Gesture.prototype.startDraggingBlock_ = function() { const BlockDraggerClass = registry.getClassFromOptions( - registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, - true); + registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); this.blockDragger_ = new BlockDraggerClass( /** @type {!BlockSvg} */ (this.targetBlock_), @@ -548,8 +545,7 @@ Gesture.prototype.handleMove = function(e) { if (this.isDraggingWorkspace_) { this.workspaceDragger_.drag(this.currentDragDeltaXY_); } else if (this.isDraggingBlock_) { - this.blockDragger_.drag( - this.mostRecentEvent_, this.currentDragDeltaXY_); + this.blockDragger_.drag(this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingBubble_) { this.bubbleDragger_.dragBubble( this.mostRecentEvent_, this.currentDragDeltaXY_); @@ -616,8 +612,7 @@ Gesture.prototype.cancel = function() { this.bubbleDragger_.endBubbleDrag( this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingBlock_) { - this.blockDragger_.endDrag( - this.mostRecentEvent_, this.currentDragDeltaXY_); + this.blockDragger_.endDrag(this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingWorkspace_) { this.workspaceDragger_.endDrag(this.currentDragDeltaXY_); } @@ -671,8 +666,7 @@ Gesture.prototype.handleWsStart = function(e, ws) { * @private */ Gesture.prototype.fireWorkspaceClick_ = function(ws) { - Events.fire(new (Events.get(Events.CLICK))( - null, ws.id, 'workspace')); + Events.fire(new (Events.get(Events.CLICK))(null, ws.id, 'workspace')); }; /** From 6c40e05dc83973d108a4baf1b7997745b8b81140 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:46:35 -0700 Subject: [PATCH 099/172] 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 100/172] 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 a663b1225b8f7fe4fd534187e5e5d28324498334 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:50:47 -0700 Subject: [PATCH 101/172] Move @package annotation to export for core/marker_manager.js --- core/marker_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 1f16f500a..60cb3b870 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -25,7 +25,6 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * Class to manage the multiple markers and the cursor on a workspace. * @param {!WorkspaceSvg} workspace The workspace for the marker manager. * @constructor - * @package */ const MarkerManager = function(workspace) { /** @@ -195,4 +194,5 @@ MarkerManager.prototype.dispose = function() { } }; +/** @package */ exports = MarkerManager; From d5f729e636b2c318b820b79afceabcfbfc74e1d1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:56:57 -0700 Subject: [PATCH 102/172] 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 103/172] 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 104/172] 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 105/172] 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 055533e783dcaf9268a3f6849a2974e91537be7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:17:17 -0700 Subject: [PATCH 106/172] Migrate core/shortcut_registry.js to ES6 const/let --- core/shortcut_registry.js | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index 14684e1b8..807f40d84 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -78,7 +78,7 @@ Blockly.ShortcutRegistry.KeyboardShortcut; */ Blockly.ShortcutRegistry.prototype.register = function( shortcut, opt_allowOverrides) { - var registeredShortcut = this.registry_[shortcut.name]; + const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( 'Shortcut with name "' + shortcut.name + '" already exists.'); @@ -94,7 +94,7 @@ Blockly.ShortcutRegistry.prototype.register = function( * @public */ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { - var shortcut = this.registry_[shortcutName]; + const shortcut = this.registry_[shortcutName]; if (!shortcut) { console.warn( @@ -123,7 +123,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { Blockly.ShortcutRegistry.prototype.addKeyMapping = function( keyCode, shortcutName, opt_allowCollision) { keyCode = String(keyCode); - var shortcutNames = this.keyMap_[keyCode]; + const shortcutNames = this.keyMap_[keyCode]; if (shortcutNames && !opt_allowCollision) { throw new Error( 'Shortcut with name "' + shortcutName + '" collides with shortcuts ' + @@ -149,7 +149,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( */ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( keyCode, shortcutName, opt_quiet) { - var shortcutNames = this.keyMap_[keyCode]; + const shortcutNames = this.keyMap_[keyCode]; if (!shortcutNames && !opt_quiet) { console.warn( @@ -158,7 +158,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( return false; } - var shortcutIdx = shortcutNames.indexOf(shortcutName); + const shortcutIdx = shortcutNames.indexOf(shortcutName); if (shortcutIdx > -1) { shortcutNames.splice(shortcutIdx, 1); if (shortcutNames.length == 0) { @@ -181,7 +181,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( * @public */ Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { - for (var keyCode in this.keyMap_) { + for (const keyCode in this.keyMap_) { this.removeKeyMapping(keyCode, shortcutName, true); } }; @@ -225,13 +225,13 @@ Blockly.ShortcutRegistry.prototype.getRegistry = function() { * @public */ Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { - var key = this.serializeKeyEvent_(e); - var shortcutNames = this.getShortcutNamesByKeyCode(key); + const key = this.serializeKeyEvent_(e); + const shortcutNames = this.getShortcutNamesByKeyCode(key); if (!shortcutNames) { return false; } - for (var i = 0, shortcutName; (shortcutName = shortcutNames[i]); i++) { - var shortcut = this.registry_[shortcutName]; + for (let i = 0, shortcutName; (shortcutName = shortcutNames[i]); i++) { + const shortcut = this.registry_[shortcutName]; if (!shortcut.preconditionFn || shortcut.preconditionFn(workspace)) { // If the key has been handled, stop processing shortcuts. if (shortcut.callback && shortcut.callback(workspace, e, shortcut)) { @@ -264,10 +264,10 @@ Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( */ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( shortcutName) { - var keys = []; - for (var keyCode in this.keyMap_) { - var shortcuts = this.keyMap_[keyCode]; - var shortcutIdx = shortcuts.indexOf(shortcutName); + const keys = []; + for (const keyCode in this.keyMap_) { + const shortcuts = this.keyMap_[keyCode]; + const shortcutIdx = shortcuts.indexOf(shortcutName); if (shortcutIdx > -1) { keys.push(keyCode); } @@ -282,8 +282,8 @@ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( * @private */ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { - var serializedKey = ''; - for (var modifier in Blockly.ShortcutRegistry.modifierKeys) { + let serializedKey = ''; + for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { if (e.getModifierState(modifier)) { if (serializedKey != '') { serializedKey += '+'; @@ -307,9 +307,9 @@ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { */ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { - var validModifiers = Blockly.utils.object.values( + const validModifiers = Blockly.utils.object.values( Blockly.ShortcutRegistry.modifierKeys); - for (var i = 0, modifier; (modifier = modifiers[i]); i++) { + for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); } @@ -327,12 +327,12 @@ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( */ Blockly.ShortcutRegistry.prototype.createSerializedKey = function( keyCode, modifiers) { - var serializedKey = ''; + let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); - for (var modifier in Blockly.ShortcutRegistry.modifierKeys) { - var modifierKeyCode = + for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + const modifierKeyCode = Blockly.ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { From 69b900aa4626cf584066a670e22cd8ae4553bc99 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:25:30 -0700 Subject: [PATCH 107/172] Migrate core/shortcut_registry.js to goog.module --- core/interfaces/i_keyboard_accessible.js | 5 +- core/shortcut_registry.js | 71 ++++++++++++------------ tests/deps.js | 2 +- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 8243e67d1..04704a2fe 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -15,7 +15,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); /* eslint-disable-next-line no-unused-vars */ -const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); +const ShortcutRegistry = goog.requireType('Blockly.ShortcutRegistry'); /** @@ -26,7 +26,8 @@ const IKeyboardAccessible = function() {}; /** * Handles the given keyboard shortcut. - * @param {!KeyboardShortcut} shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be + * handled. * @return {boolean} True if the shortcut has been handled, false otherwise. */ IKeyboardAccessible.prototype.onShortcut; diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index 807f40d84..d75ec9546 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.ShortcutRegistry'); +goog.module('Blockly.ShortcutRegistry'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.KeyCodes'); goog.require('Blockly.utils.object'); @@ -22,16 +23,16 @@ goog.requireType('Blockly.Workspace'); /** * Class for the registry of keyboard shortcuts. This is intended to be a * singleton. You should not create a new instance, and only access this class - * from Blockly.ShortcutRegistry.registry. + * from ShortcutRegistry.registry. * @constructor */ -Blockly.ShortcutRegistry = function() { +const ShortcutRegistry = function() { // Singleton instance should be registered once. - Blockly.ShortcutRegistry.registry = this; + ShortcutRegistry.registry = this; /** * Registry of all keyboard shortcuts, keyed by name of shortcut. - * @type {!Object} + * @type {!Object} * @private */ this.registry_ = Object.create(null); @@ -48,7 +49,7 @@ Blockly.ShortcutRegistry = function() { * Enum of valid modifiers. * @enum {!Blockly.utils.KeyCodes} */ -Blockly.ShortcutRegistry.modifierKeys = { +ShortcutRegistry.modifierKeys = { 'Shift': Blockly.utils.KeyCodes.SHIFT, 'Control': Blockly.utils.KeyCodes.CTRL, 'Alt': Blockly.utils.KeyCodes.ALT, @@ -59,24 +60,24 @@ Blockly.ShortcutRegistry.modifierKeys = { * A keyboard shortcut. * @typedef {{ * callback: ((function(!Blockly.Workspace, Event, - * !Blockly.ShortcutRegistry.KeyboardShortcut):boolean)|undefined), + * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), * name: string, * preconditionFn: ((function(!Blockly.Workspace):boolean)|undefined), * metadata: (Object|undefined) * }} */ -Blockly.ShortcutRegistry.KeyboardShortcut; +ShortcutRegistry.KeyboardShortcut; /** * Registers a keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The + * @param {!ShortcutRegistry.KeyboardShortcut} shortcut The * shortcut for this key code. * @param {boolean=} opt_allowOverrides True to prevent a warning when * overriding an already registered item. * @throws {Error} if a shortcut with the same name already exists. * @public */ -Blockly.ShortcutRegistry.prototype.register = function( +ShortcutRegistry.prototype.register = function( shortcut, opt_allowOverrides) { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { @@ -93,7 +94,7 @@ Blockly.ShortcutRegistry.prototype.register = function( * @return {boolean} True if an item was unregistered, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { +ShortcutRegistry.prototype.unregister = function(shortcutName) { const shortcut = this.registry_[shortcutName]; if (!shortcut) { @@ -112,7 +113,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { * Adds a mapping between a keycode and a keyboard shortcut. * @param {string|Blockly.utils.KeyCodes} keyCode The key code for the keyboard * shortcut. If registering a key code with a modifier (ex: ctrl+c) use - * Blockly.ShortcutRegistry.registry.createSerializedKey; + * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the * given keycode is pressed. * @param {boolean=} opt_allowCollision True to prevent an error when adding a @@ -120,7 +121,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { * @throws {Error} if the given key code is already mapped to a shortcut. * @public */ -Blockly.ShortcutRegistry.prototype.addKeyMapping = function( +ShortcutRegistry.prototype.addKeyMapping = function( keyCode, shortcutName, opt_allowCollision) { keyCode = String(keyCode); const shortcutNames = this.keyMap_[keyCode]; @@ -139,7 +140,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( * Removes a mapping between a keycode and a keyboard shortcut. * @param {string} keyCode The key code for the keyboard shortcut. If * registering a key code with a modifier (ex: ctrl+c) use - * Blockly.ShortcutRegistry.registry.createSerializedKey; + * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the * given keycode is pressed. * @param {boolean=} opt_quiet True to not console warn when there is no @@ -147,7 +148,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( * @return {boolean} True if a key mapping was removed, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( +ShortcutRegistry.prototype.removeKeyMapping = function( keyCode, shortcutName, opt_quiet) { const shortcutNames = this.keyMap_[keyCode]; @@ -180,7 +181,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( * @param {string} shortcutName The name of the shortcut to remove from the key map. * @public */ -Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { +ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { for (const keyCode in this.keyMap_) { this.removeKeyMapping(keyCode, shortcutName, true); } @@ -192,27 +193,27 @@ Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) * shortcut names. * @public */ -Blockly.ShortcutRegistry.prototype.setKeyMap = function(keyMap) { +ShortcutRegistry.prototype.setKeyMap = function(keyMap) { this.keyMap_ = keyMap; }; /** * Gets the current key map. - * @return {!Object>} - * The object holding key codes to Blockly.ShortcutRegistry.KeyboardShortcut. + * @return {!Object>} + * The object holding key codes to ShortcutRegistry.KeyboardShortcut. * @public */ -Blockly.ShortcutRegistry.prototype.getKeyMap = function() { +ShortcutRegistry.prototype.getKeyMap = function() { return Blockly.utils.object.deepMerge(Object.create(null), this.keyMap_); }; /** * Gets the registry of keyboard shortcuts. - * @return {!Object} + * @return {!Object} * The registry of keyboard shortcuts. * @public */ -Blockly.ShortcutRegistry.prototype.getRegistry = function() { +ShortcutRegistry.prototype.getRegistry = function() { return Blockly.utils.object.deepMerge(Object.create(null), this.registry_); }; @@ -224,7 +225,7 @@ Blockly.ShortcutRegistry.prototype.getRegistry = function() { * @return {boolean} True if the event was handled, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { +ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { const key = this.serializeKeyEvent_(e); const shortcutNames = this.getShortcutNamesByKeyCode(key); if (!shortcutNames) { @@ -249,7 +250,7 @@ Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { * given keyCode is used. Undefined if no shortcuts exist. * @public */ -Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( +ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( keyCode) { return this.keyMap_[keyCode] || []; }; @@ -262,7 +263,7 @@ Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( * registered under. * @public */ -Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( +ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( shortcutName) { const keys = []; for (const keyCode in this.keyMap_) { @@ -281,9 +282,9 @@ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( * @return {string} The serialized key code for the given event. * @private */ -Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { +ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { let serializedKey = ''; - for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + for (const modifier in ShortcutRegistry.modifierKeys) { if (e.getModifierState(modifier)) { if (serializedKey != '') { serializedKey += '+'; @@ -305,10 +306,10 @@ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { * @throws {Error} if the modifier is not in the valid modifiers list. * @private */ -Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( +ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { const validModifiers = Blockly.utils.object.values( - Blockly.ShortcutRegistry.modifierKeys); + ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); @@ -321,19 +322,19 @@ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( * @param {number} keyCode Number code representing the key. * @param {?Array} modifiers List of modifier key codes to be used with * the key. All valid modifiers can be found in the - * Blockly.ShortcutRegistry.modifierKeys. + * ShortcutRegistry.modifierKeys. * @return {string} The serialized key code for the given modifiers and key. * @public */ -Blockly.ShortcutRegistry.prototype.createSerializedKey = function( +ShortcutRegistry.prototype.createSerializedKey = function( keyCode, modifiers) { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); - for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + for (const modifier in ShortcutRegistry.modifierKeys) { const modifierKeyCode = - Blockly.ShortcutRegistry.modifierKeys[modifier]; + ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { serializedKey += '+'; @@ -352,4 +353,6 @@ Blockly.ShortcutRegistry.prototype.createSerializedKey = function( }; // Creates and assigns the singleton instance. -new Blockly.ShortcutRegistry(); +new ShortcutRegistry(); + +exports = ShortcutRegistry; diff --git a/tests/deps.js b/tests/deps.js index de575339f..d67006c87 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -160,7 +160,7 @@ goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Ren goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); -goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']); +goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); From 3519f4abc8d5352214a3a9f7851ca9ca9326afd1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:28:19 -0700 Subject: [PATCH 108/172] Migrate core/shortcut_registry.js to named requires --- core/shortcut_registry.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index d75ec9546..ac492397a 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -14,10 +14,10 @@ goog.module('Blockly.ShortcutRegistry'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Workspace'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const object = goog.require('Blockly.utils.object'); /** @@ -47,22 +47,22 @@ const ShortcutRegistry = function() { /** * Enum of valid modifiers. - * @enum {!Blockly.utils.KeyCodes} + * @enum {!KeyCodes} */ ShortcutRegistry.modifierKeys = { - 'Shift': Blockly.utils.KeyCodes.SHIFT, - 'Control': Blockly.utils.KeyCodes.CTRL, - 'Alt': Blockly.utils.KeyCodes.ALT, - 'Meta': Blockly.utils.KeyCodes.META + 'Shift': KeyCodes.SHIFT, + 'Control': KeyCodes.CTRL, + 'Alt': KeyCodes.ALT, + 'Meta': KeyCodes.META }; /** * A keyboard shortcut. * @typedef {{ - * callback: ((function(!Blockly.Workspace, Event, + * callback: ((function(!Workspace, Event, * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), * name: string, - * preconditionFn: ((function(!Blockly.Workspace):boolean)|undefined), + * preconditionFn: ((function(!Workspace):boolean)|undefined), * metadata: (Object|undefined) * }} */ @@ -111,7 +111,7 @@ ShortcutRegistry.prototype.unregister = function(shortcutName) { /** * Adds a mapping between a keycode and a keyboard shortcut. - * @param {string|Blockly.utils.KeyCodes} keyCode The key code for the keyboard + * @param {string|KeyCodes} keyCode The key code for the keyboard * shortcut. If registering a key code with a modifier (ex: ctrl+c) use * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the @@ -204,7 +204,7 @@ ShortcutRegistry.prototype.setKeyMap = function(keyMap) { * @public */ ShortcutRegistry.prototype.getKeyMap = function() { - return Blockly.utils.object.deepMerge(Object.create(null), this.keyMap_); + return object.deepMerge(Object.create(null), this.keyMap_); }; /** @@ -214,12 +214,12 @@ ShortcutRegistry.prototype.getKeyMap = function() { * @public */ ShortcutRegistry.prototype.getRegistry = function() { - return Blockly.utils.object.deepMerge(Object.create(null), this.registry_); + return object.deepMerge(Object.create(null), this.registry_); }; /** * Handles key down events. - * @param {!Blockly.Workspace} workspace The main workspace where the event was + * @param {!Workspace} workspace The main workspace where the event was * captured. * @param {!Event} e The key down event. * @return {boolean} True if the event was handled, false otherwise. @@ -308,7 +308,7 @@ ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { */ ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { - const validModifiers = Blockly.utils.object.values( + const validModifiers = object.values( ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { From 9e2d6f2aba5b7c3d43a0705ce7d28f5b4d44cc76 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:28:57 -0700 Subject: [PATCH 109/172] clang-format core/shortcut_registry.js --- core/shortcut_registry.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index ac492397a..3da777eae 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -77,8 +77,7 @@ ShortcutRegistry.KeyboardShortcut; * @throws {Error} if a shortcut with the same name already exists. * @public */ -ShortcutRegistry.prototype.register = function( - shortcut, opt_allowOverrides) { +ShortcutRegistry.prototype.register = function(shortcut, opt_allowOverrides) { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( @@ -168,7 +167,8 @@ ShortcutRegistry.prototype.removeKeyMapping = function( return true; } if (!opt_quiet) { - console.warn('No keyboard shortcut with name "' + shortcutName + + console.warn( + 'No keyboard shortcut with name "' + shortcutName + '" registered with key code "' + keyCode + '"'); } return false; @@ -176,9 +176,10 @@ ShortcutRegistry.prototype.removeKeyMapping = function( /** * Removes all the key mappings for a shortcut with the given name. - * Useful when changing the default key mappings and the key codes registered to the shortcut are - * unknown. - * @param {string} shortcutName The name of the shortcut to remove from the key map. + * Useful when changing the default key mappings and the key codes registered to + * the shortcut are unknown. + * @param {string} shortcutName The name of the shortcut to remove from the key + * map. * @public */ ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { @@ -250,8 +251,7 @@ ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { * given keyCode is used. Undefined if no shortcuts exist. * @public */ -ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( - keyCode) { +ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function(keyCode) { return this.keyMap_[keyCode] || []; }; @@ -263,8 +263,7 @@ ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( * registered under. * @public */ -ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( - shortcutName) { +ShortcutRegistry.prototype.getKeyCodesByShortcutName = function(shortcutName) { const keys = []; for (const keyCode in this.keyMap_) { const shortcuts = this.keyMap_[keyCode]; @@ -306,10 +305,8 @@ ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { * @throws {Error} if the modifier is not in the valid modifiers list. * @private */ -ShortcutRegistry.prototype.checkModifiers_ = function( - modifiers) { - const validModifiers = object.values( - ShortcutRegistry.modifierKeys); +ShortcutRegistry.prototype.checkModifiers_ = function(modifiers) { + const validModifiers = object.values(ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); @@ -326,15 +323,13 @@ ShortcutRegistry.prototype.checkModifiers_ = function( * @return {string} The serialized key code for the given modifiers and key. * @public */ -ShortcutRegistry.prototype.createSerializedKey = function( - keyCode, modifiers) { +ShortcutRegistry.prototype.createSerializedKey = function(keyCode, modifiers) { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); for (const modifier in ShortcutRegistry.modifierKeys) { - const modifierKeyCode = - ShortcutRegistry.modifierKeys[modifier]; + const modifierKeyCode = ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { serializedKey += '+'; From 2d480a1b202e9fca2eda7bfb25c6c7c8a7e07c79 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:46:58 -0700 Subject: [PATCH 110/172] Migrate core/theme_manager.js to ES6 const/let --- core/theme_manager.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index 6c461a2e7..d432e0dd0 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -82,11 +82,11 @@ Blockly.ThemeManager.prototype.getTheme = function() { * @package */ Blockly.ThemeManager.prototype.setTheme = function(theme) { - var prevTheme = this.theme_; + const prevTheme = this.theme_; this.theme_ = theme; // Set the theme name onto the injection div. - var injectionDiv = this.workspace_.getInjectionDiv(); + const injectionDiv = this.workspace_.getInjectionDiv(); if (injectionDiv) { if (prevTheme) { Blockly.utils.dom.removeClass(injectionDiv, prevTheme.getClassName()); @@ -95,17 +95,17 @@ Blockly.ThemeManager.prototype.setTheme = function(theme) { } // Refresh all subscribed workspaces. - for (var i = 0, workspace; (workspace = this.subscribedWorkspaces_[i]); i++) { + for (let i = 0, workspace; (workspace = this.subscribedWorkspaces_[i]); i++) { workspace.refreshTheme(); } // Refresh all registered Blockly UI components. - for (var i = 0, keys = Object.keys(this.componentDB_), + for (let i = 0, keys = Object.keys(this.componentDB_), key; (key = keys[i]); i++) { - for (var j = 0, component; (component = this.componentDB_[key][j]); j++) { - var element = component.element; - var propertyName = component.propertyName; - var style = this.theme_ && this.theme_.getComponentStyle(key); + for (let j = 0, component; (component = this.componentDB_[key][j]); j++) { + const element = component.element; + const propertyName = component.propertyName; + const style = this.theme_ && this.theme_.getComponentStyle(key); element.style[propertyName] = style || ''; } } @@ -129,7 +129,7 @@ Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { * @package */ Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { - var index = this.subscribedWorkspaces_.indexOf(workspace); + const index = this.subscribedWorkspaces_.indexOf(workspace); if (index < 0) { throw Error('Cannot unsubscribe a workspace that hasn\'t been subscribed.'); } @@ -158,7 +158,7 @@ Blockly.ThemeManager.prototype.subscribe = function(element, componentName, }); // Initialize the element with its corresponding theme style. - var style = this.theme_ && this.theme_.getComponentStyle(componentName); + const style = this.theme_ && this.theme_.getComponentStyle(componentName); element.style[propertyName] = style || ''; }; @@ -172,10 +172,10 @@ Blockly.ThemeManager.prototype.unsubscribe = function(element) { return; } // Go through all component, and remove any references to this element. - var componentNames = Object.keys(this.componentDB_); - for (var c = 0, componentName; (componentName = componentNames[c]); c++) { - var elements = this.componentDB_[componentName]; - for (var i = elements.length - 1; i >= 0; i--) { + const componentNames = Object.keys(this.componentDB_); + for (let c = 0, componentName; (componentName = componentNames[c]); c++) { + const elements = this.componentDB_[componentName]; + for (let i = elements.length - 1; i >= 0; i--) { if (elements[i].element === element) { elements.splice(i, 1); } From 48d422159b246c1062ff413f02ca51c4916bf7fc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:48:59 -0700 Subject: [PATCH 111/172] Migrate core/theme_manager.js to goog.module --- core/theme_manager.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index d432e0dd0..3b43f2f55 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.ThemeManager'); +goog.module('Blockly.ThemeManager'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Theme'); @@ -27,7 +28,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -Blockly.ThemeManager = function(workspace, theme) { +const ThemeManager = function(workspace, theme) { /** * The main workspace. @@ -52,7 +53,7 @@ Blockly.ThemeManager = function(workspace, theme) { /** * A map of subscribed UI components, keyed by component name. - * @type {!Object>} + * @type {!Object>} * @private */ this.componentDB_ = Object.create(null); @@ -65,14 +66,14 @@ Blockly.ThemeManager = function(workspace, theme) { * propertyName:string * }} */ -Blockly.ThemeManager.Component; +ThemeManager.Component; /** * Get the workspace theme. * @return {!Blockly.Theme} The workspace theme. * @package */ -Blockly.ThemeManager.prototype.getTheme = function() { +ThemeManager.prototype.getTheme = function() { return this.theme_; }; @@ -81,7 +82,7 @@ Blockly.ThemeManager.prototype.getTheme = function() { * @param {!Blockly.Theme} theme The workspace theme. * @package */ -Blockly.ThemeManager.prototype.setTheme = function(theme) { +ThemeManager.prototype.setTheme = function(theme) { const prevTheme = this.theme_; this.theme_ = theme; @@ -119,7 +120,7 @@ Blockly.ThemeManager.prototype.setTheme = function(theme) { * @param {!Blockly.Workspace} workspace The workspace to subscribe. * @package */ -Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { +ThemeManager.prototype.subscribeWorkspace = function(workspace) { this.subscribedWorkspaces_.push(workspace); }; @@ -128,7 +129,7 @@ Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { * @param {!Blockly.Workspace} workspace The workspace to unsubscribe. * @package */ -Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { +ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { const index = this.subscribedWorkspaces_.indexOf(workspace); if (index < 0) { throw Error('Cannot unsubscribe a workspace that hasn\'t been subscribed.'); @@ -145,7 +146,7 @@ Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { * @param {string} propertyName The inline style property name to update. * @package */ -Blockly.ThemeManager.prototype.subscribe = function(element, componentName, +ThemeManager.prototype.subscribe = function(element, componentName, propertyName) { if (!this.componentDB_[componentName]) { this.componentDB_[componentName] = []; @@ -167,7 +168,7 @@ Blockly.ThemeManager.prototype.subscribe = function(element, componentName, * @param {Element} element The element to unsubscribe. * @package */ -Blockly.ThemeManager.prototype.unsubscribe = function(element) { +ThemeManager.prototype.unsubscribe = function(element) { if (!element) { return; } @@ -192,9 +193,11 @@ Blockly.ThemeManager.prototype.unsubscribe = function(element) { * @package * @suppress {checkTypes} */ -Blockly.ThemeManager.prototype.dispose = function() { +ThemeManager.prototype.dispose = function() { this.owner_ = null; this.theme_ = null; this.subscribedWorkspaces_ = null; this.componentDB_ = null; }; + +exports = ThemeManager; diff --git a/tests/deps.js b/tests/deps.js index de575339f..48a76dd48 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -164,7 +164,7 @@ goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); -goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme']); +goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); From 794e28ed481da67009d366e35a60d6de034837ea Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:52:43 -0700 Subject: [PATCH 112/172] Migrate core/theme_manager.js to named requires --- core/theme_manager.js | 33 ++++++++++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index 3b43f2f55..a4f0aed6c 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -15,16 +15,19 @@ goog.module('Blockly.ThemeManager'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Theme'); - -goog.requireType('Blockly.Workspace'); -goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const dom = goog.require('Blockly.utils.dom'); /** * Class for storing and updating a workspace's theme and UI components. - * @param {!Blockly.WorkspaceSvg} workspace The main workspace. - * @param {!Blockly.Theme} theme The workspace theme. + * @param {!WorkspaceSvg} workspace The main workspace. + * @param {!Theme} theme The workspace theme. * @constructor * @package */ @@ -32,21 +35,21 @@ const ThemeManager = function(workspace, theme) { /** * The main workspace. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; /** * The Blockly theme to use. - * @type {!Blockly.Theme} + * @type {!Theme} * @private */ this.theme_ = theme; /** * A list of workspaces that are subscribed to this theme. - * @type {!Array} + * @type {!Array} * @private */ this.subscribedWorkspaces_ = []; @@ -70,7 +73,7 @@ ThemeManager.Component; /** * Get the workspace theme. - * @return {!Blockly.Theme} The workspace theme. + * @return {!Theme} The workspace theme. * @package */ ThemeManager.prototype.getTheme = function() { @@ -79,7 +82,7 @@ ThemeManager.prototype.getTheme = function() { /** * Set the workspace theme, and refresh the workspace and all components. - * @param {!Blockly.Theme} theme The workspace theme. + * @param {!Theme} theme The workspace theme. * @package */ ThemeManager.prototype.setTheme = function(theme) { @@ -90,9 +93,9 @@ ThemeManager.prototype.setTheme = function(theme) { const injectionDiv = this.workspace_.getInjectionDiv(); if (injectionDiv) { if (prevTheme) { - Blockly.utils.dom.removeClass(injectionDiv, prevTheme.getClassName()); + dom.removeClass(injectionDiv, prevTheme.getClassName()); } - Blockly.utils.dom.addClass(injectionDiv, this.theme_.getClassName()); + dom.addClass(injectionDiv, this.theme_.getClassName()); } // Refresh all subscribed workspaces. @@ -117,7 +120,7 @@ ThemeManager.prototype.setTheme = function(theme) { /** * Subscribe a workspace to changes to the selected theme. If a new theme is * set, the workspace is called to refresh its blocks. - * @param {!Blockly.Workspace} workspace The workspace to subscribe. + * @param {!Workspace} workspace The workspace to subscribe. * @package */ ThemeManager.prototype.subscribeWorkspace = function(workspace) { @@ -126,7 +129,7 @@ ThemeManager.prototype.subscribeWorkspace = function(workspace) { /** * Unsubscribe a workspace to changes to the selected theme. - * @param {!Blockly.Workspace} workspace The workspace to unsubscribe. + * @param {!Workspace} workspace The workspace to unsubscribe. * @package */ ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { diff --git a/tests/deps.js b/tests/deps.js index 48a76dd48..6affa4354 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -164,7 +164,7 @@ goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); -goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); From d2a6e93a8a168c2ed87ea3370011de6cffc20722 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:53:07 -0700 Subject: [PATCH 113/172] clang-format core/theme_manager.js --- core/theme_manager.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index a4f0aed6c..859a33658 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -32,7 +32,6 @@ const dom = goog.require('Blockly.utils.dom'); * @package */ const ThemeManager = function(workspace, theme) { - /** * The main workspace. * @type {!WorkspaceSvg} @@ -65,10 +64,10 @@ const ThemeManager = function(workspace, theme) { /** * A Blockly UI component type. * @typedef {{ - * element:!Element, - * propertyName:string - * }} - */ + * element:!Element, + * propertyName:string + * }} + */ ThemeManager.Component; /** @@ -104,8 +103,8 @@ ThemeManager.prototype.setTheme = function(theme) { } // Refresh all registered Blockly UI components. - for (let i = 0, keys = Object.keys(this.componentDB_), - key; (key = keys[i]); i++) { + for (let i = 0, keys = Object.keys(this.componentDB_), key; (key = keys[i]); + i++) { for (let j = 0, component; (component = this.componentDB_[key][j]); j++) { const element = component.element; const propertyName = component.propertyName; @@ -149,17 +148,15 @@ ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { * @param {string} propertyName The inline style property name to update. * @package */ -ThemeManager.prototype.subscribe = function(element, componentName, - propertyName) { +ThemeManager.prototype.subscribe = function( + element, componentName, propertyName) { if (!this.componentDB_[componentName]) { this.componentDB_[componentName] = []; } // Add the element to our component map. - this.componentDB_[componentName].push({ - element: element, - propertyName: propertyName - }); + this.componentDB_[componentName].push( + {element: element, propertyName: propertyName}); // Initialize the element with its corresponding theme style. const style = this.theme_ && this.theme_.getComponentStyle(componentName); From f6adf865f29bd9619148a1fbd77ccecfbe25457e Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 23 Jul 2021 19:39:37 +0100 Subject: [PATCH 114/172] Migrate core/utils/size.js to goog.module --- core/utils/size.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/utils/size.js b/core/utils/size.js index 2ffa91ac1..56ec2eb91 100644 --- a/core/utils/size.js +++ b/core/utils/size.js @@ -13,10 +13,11 @@ 'use strict'; /** - * @name Blockly.utils.Size + * @name Size * @namespace */ -goog.provide('Blockly.utils.Size'); +goog.module('Blockly.utils.Size'); +goog.module.declareLegacyNamespace(); /** @@ -26,7 +27,7 @@ goog.provide('Blockly.utils.Size'); * @struct * @constructor */ -Blockly.utils.Size = function(width, height) { +const Size = function(width, height) { /** * Width * @type {number} @@ -42,12 +43,12 @@ Blockly.utils.Size = function(width, height) { /** * Compares sizes for equality. - * @param {?Blockly.utils.Size} a A Size. - * @param {?Blockly.utils.Size} b A Size. + * @param {?Size} a A Size. + * @param {?Size} b A Size. * @return {boolean} True iff the sizes have equal widths and equal * heights, or if both are null. */ -Blockly.utils.Size.equals = function(a, b) { +Size.equals = function(a, b) { if (a == b) { return true; } @@ -56,3 +57,5 @@ Blockly.utils.Size.equals = function(a, b) { } return a.width == b.width && a.height == b.height; }; + +exports = Size; diff --git a/tests/deps.js b/tests/deps.js index ae77407c9..c9fc4067f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -187,7 +187,7 @@ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lan goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); +goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); From 61bbffc29e28af25531c081760f9ddee9766d48f Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:03:46 -0700 Subject: [PATCH 115/172] Migrate core/zoom_controls.js to ES6 const/let --- core/zoom_controls.js | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 7d0d7e6ce..465a5d165 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -182,7 +182,7 @@ Blockly.ZoomControls.prototype.createDom = function() { // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. // https://neil.fraser.name/news/2015/11/01/ - var rnd = String(Math.random()).substring(2); + const rnd = String(Math.random()).substring(2); this.createZoomOutSvg_(rnd); this.createZoomInSvg_(rnd); if (this.workspace_.isMovable()) { @@ -232,12 +232,12 @@ Blockly.ZoomControls.prototype.dispose = function() { * bounding box should be ignored by other UI elements. */ Blockly.ZoomControls.prototype.getBoundingRectangle = function() { - var height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; + let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - var bottom = this.top_ + height; - var right = this.left_ + this.WIDTH_; + const bottom = this.top_ + height; + const right = this.left_ + this.WIDTH_; return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); }; @@ -256,41 +256,41 @@ Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { return; } - var cornerPosition = + const cornerPosition = Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); - var height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; + let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - var startRect = Blockly.uiPosition.getStartPositionRect( + const startRect = Blockly.uiPosition.getStartPositionRect( cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); - var verticalPosition = cornerPosition.vertical; - var bumpDirection = + const verticalPosition = cornerPosition.vertical; + const bumpDirection = verticalPosition === Blockly.uiPosition.verticalPosition.TOP ? Blockly.uiPosition.bumpDirection.DOWN : Blockly.uiPosition.bumpDirection.UP; - var positionRect = Blockly.uiPosition.bumpPositionRect( + const positionRect = Blockly.uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); if (verticalPosition === Blockly.uiPosition.verticalPosition.TOP) { - var zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; + const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); if (this.zoomResetGroup_) { - var zoomResetTranslateY = + const zoomResetTranslateY = zoomInTranslateY + this.LARGE_SPACING_ + this.HEIGHT_; this.zoomResetGroup_.setAttribute('transform', 'translate(0, ' + zoomResetTranslateY + ')'); } } else { - var zoomInTranslateY = this.zoomResetGroup_ ? + const zoomInTranslateY = this.zoomResetGroup_ ? this.LARGE_SPACING_ + this.HEIGHT_ : 0; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); - var zoomOutTranslateY = + const zoomOutTranslateY = zoomInTranslateY + this.SMALL_SPACING_ + this.HEIGHT_; this.zoomOutGroup_.setAttribute('transform', 'translate(0, ' + zoomOutTranslateY + ')'); @@ -322,7 +322,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { this.zoomOutGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoomoutClipPath' + rnd @@ -335,7 +335,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { 'height': 32, }, clip); - var zoomoutSvg = Blockly.utils.dom.createSvgElement( + const zoomoutSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -374,7 +374,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { this.zoomInGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoominClipPath' + rnd @@ -387,7 +387,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { 'height': 32, }, clip); - var zoominSvg = Blockly.utils.dom.createSvgElement( + const zoominSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -443,7 +443,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { this.zoomResetGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoomresetClipPath' + rnd @@ -456,7 +456,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { 'height': 32 }, clip); - var zoomresetSvg = Blockly.utils.dom.createSvgElement( + const zoomresetSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -484,14 +484,14 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { // zoom is passed amount and computes the new scale using the formula: // targetScale = currentScale * Math.pow(speed, amount) - var targetScale = this.workspace_.options.zoomOptions.startScale; - var currentScale = this.workspace_.scale; - var speed = this.workspace_.options.zoomOptions.scaleSpeed; + const targetScale = this.workspace_.options.zoomOptions.startScale; + const currentScale = this.workspace_.scale; + const speed = this.workspace_.options.zoomOptions.scaleSpeed; // To compute amount: // amount = log(speed, (targetScale / currentScale)) // Math.log computes natural logarithm (ln), to change the base, use formula: // log(base, value) = ln(value) / ln(base) - var amount = Math.log(targetScale / currentScale) / Math.log(speed); + const amount = Math.log(targetScale / currentScale) / Math.log(speed); this.workspace_.beginCanvasTransition(); this.workspace_.zoomCenter(amount); this.workspace_.scrollCenter(); @@ -508,7 +508,7 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { * @private */ Blockly.ZoomControls.prototype.fireZoomEvent_ = function() { - var uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( + const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); Blockly.Events.fire(uiEvent); }; From bc7c5115e1ca36f235a64052584878cb49b8b8e4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:03:55 -0700 Subject: [PATCH 116/172] Migrate core/zoom_controls.js to goog.module --- core/zoom_controls.js | 50 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 465a5d165..61455c120 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -10,8 +10,10 @@ */ 'use strict'; -goog.provide('Blockly.ZoomControls'); +goog.module('Blockly.ZoomControls'); +goog.module.declareLegacyNamespace(); +goog.require('Blockly'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.Css'); @@ -36,7 +38,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @implements {Blockly.IPositionable} */ -Blockly.ZoomControls = function(workspace) { +const ZoomControls = function(workspace) { /** * @type {!Blockly.WorkspaceSvg} * @private @@ -102,7 +104,7 @@ Blockly.ZoomControls = function(workspace) { * @const * @private */ -Blockly.ZoomControls.prototype.WIDTH_ = 32; +ZoomControls.prototype.WIDTH_ = 32; /** * Height of each zoom control. @@ -110,7 +112,7 @@ Blockly.ZoomControls.prototype.WIDTH_ = 32; * @const * @private */ -Blockly.ZoomControls.prototype.HEIGHT_ = 32; +ZoomControls.prototype.HEIGHT_ = 32; /** * Small spacing used between the zoom in and out control, in pixels. @@ -118,7 +120,7 @@ Blockly.ZoomControls.prototype.HEIGHT_ = 32; * @const * @private */ -Blockly.ZoomControls.prototype.SMALL_SPACING_ = 2; +ZoomControls.prototype.SMALL_SPACING_ = 2; /** * Large spacing used between the zoom in and reset control, in pixels. @@ -126,7 +128,7 @@ Blockly.ZoomControls.prototype.SMALL_SPACING_ = 2; * @const * @private */ -Blockly.ZoomControls.prototype.LARGE_SPACING_ = 11; +ZoomControls.prototype.LARGE_SPACING_ = 11; /** * Distance between zoom controls and bottom or top edge of workspace. @@ -134,48 +136,48 @@ Blockly.ZoomControls.prototype.LARGE_SPACING_ = 11; * @const * @private */ -Blockly.ZoomControls.prototype.MARGIN_VERTICAL_ = 20; +ZoomControls.prototype.MARGIN_VERTICAL_ = 20; /** * Distance between zoom controls and right or left edge of workspace. * @type {number} * @private */ -Blockly.ZoomControls.prototype.MARGIN_HORIZONTAL_ = 20; +ZoomControls.prototype.MARGIN_HORIZONTAL_ = 20; /** * The SVG group containing the zoom controls. * @type {SVGElement} * @private */ -Blockly.ZoomControls.prototype.svgGroup_ = null; +ZoomControls.prototype.svgGroup_ = null; /** * Left coordinate of the zoom controls. * @type {number} * @private */ -Blockly.ZoomControls.prototype.left_ = 0; +ZoomControls.prototype.left_ = 0; /** * Top coordinate of the zoom controls. * @type {number} * @private */ -Blockly.ZoomControls.prototype.top_ = 0; +ZoomControls.prototype.top_ = 0; /** * Whether this has been initialized. * @type {boolean} * @private */ -Blockly.ZoomControls.prototype.initialized_ = false; +ZoomControls.prototype.initialized_ = false; /** * Create the zoom controls. * @return {!SVGElement} The zoom controls SVG group. */ -Blockly.ZoomControls.prototype.createDom = function() { +ZoomControls.prototype.createDom = function() { this.svgGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {}, null); @@ -196,7 +198,7 @@ Blockly.ZoomControls.prototype.createDom = function() { /** * Initializes the zoom controls. */ -Blockly.ZoomControls.prototype.init = function() { +ZoomControls.prototype.init = function() { this.workspace_.getComponentManager().addComponent({ component: this, weight: 2, @@ -209,7 +211,7 @@ Blockly.ZoomControls.prototype.init = function() { * Disposes of this zoom controls. * Unlink from all DOM elements to prevent memory leaks. */ -Blockly.ZoomControls.prototype.dispose = function() { +ZoomControls.prototype.dispose = function() { this.workspace_.getComponentManager().removeComponent('zoomControls'); if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); @@ -231,7 +233,7 @@ Blockly.ZoomControls.prototype.dispose = function() { * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ -Blockly.ZoomControls.prototype.getBoundingRectangle = function() { +ZoomControls.prototype.getBoundingRectangle = function() { let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; @@ -250,7 +252,7 @@ Blockly.ZoomControls.prototype.getBoundingRectangle = function() { * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ -Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { +ZoomControls.prototype.position = function(metrics, savedPositions) { // Not yet initialized. if (!this.initialized_) { return; @@ -309,7 +311,7 @@ Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { +ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -361,7 +363,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { +ZoomControls.prototype.createZoomInSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -414,7 +416,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { * @param {!Event} e A mouse down event. * @private */ -Blockly.ZoomControls.prototype.zoom_ = function(amount, e) { +ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.markFocused(); this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); @@ -430,7 +432,7 @@ Blockly.ZoomControls.prototype.zoom_ = function(amount, e) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { +ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -479,7 +481,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { * @param {!Event} e A mouse down event. * @private */ -Blockly.ZoomControls.prototype.resetZoom_ = function(e) { +ZoomControls.prototype.resetZoom_ = function(e) { this.workspace_.markFocused(); // zoom is passed amount and computes the new scale using the formula: @@ -507,7 +509,7 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { * Fires a zoom control UI event. * @private */ -Blockly.ZoomControls.prototype.fireZoomEvent_ = function() { +ZoomControls.prototype.fireZoomEvent_ = function() { const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); Blockly.Events.fire(uiEvent); @@ -531,3 +533,5 @@ Blockly.Css.register([ '}' /* eslint-enable indent */ ]); + +exports = ZoomControls; diff --git a/tests/deps.js b/tests/deps.js index 702bf5ae4..c61cd74c1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -210,6 +210,6 @@ goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.Workspa goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('base.js', [], []); From 40c095f496a8d901d97b0b3506fdc586e0f12101 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:05:49 -0700 Subject: [PATCH 117/172] Migrate core/zoom_controls.js named requires --- core/zoom_controls.js | 166 +++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 61455c120..84451bbd1 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -13,34 +13,34 @@ goog.module('Blockly.ZoomControls'); goog.module.declareLegacyNamespace(); -goog.require('Blockly'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.ComponentManager'); -goog.require('Blockly.Css'); -goog.require('Blockly.Events'); +const Blockly = goog.require('Blockly'); +const ComponentManager = goog.require('Blockly.ComponentManager'); +const Css = goog.require('Blockly.Css'); +const Events = goog.require('Blockly.Events'); +const IPositionable = goog.require('Blockly.IPositionable'); +const Rect = goog.require('Blockly.utils.Rect'); +const Svg = goog.require('Blockly.utils.Svg'); +const Touch = goog.require('Blockly.Touch'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const internalConstants = goog.require('Blockly.internalConstants'); +const uiPosition = goog.require('Blockly.uiPosition'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); -goog.require('Blockly.IPositionable'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.Touch'); -goog.require('Blockly.uiPosition'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.WorkspaceSvg'); /** * Class for a zoom controls. - * @param {!Blockly.WorkspaceSvg} workspace The workspace to sit in. + * @param {!WorkspaceSvg} workspace The workspace to sit in. * @constructor - * @implements {Blockly.IPositionable} + * @implements {IPositionable} */ const ZoomControls = function(workspace) { /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; @@ -55,7 +55,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom reset * button. Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomResetWrapper_ = null; @@ -63,7 +63,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom in button. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomInWrapper_ = null; @@ -71,7 +71,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom out button. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomOutWrapper_ = null; @@ -178,8 +178,8 @@ ZoomControls.prototype.initialized_ = false; * @return {!SVGElement} The zoom controls SVG group. */ ZoomControls.prototype.createDom = function() { - this.svgGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, {}, null); + this.svgGroup_ = dom.createSvgElement( + Svg.G, {}, null); // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. @@ -202,7 +202,7 @@ ZoomControls.prototype.init = function() { this.workspace_.getComponentManager().addComponent({ component: this, weight: 2, - capabilities: [Blockly.ComponentManager.Capability.POSITIONABLE] + capabilities: [ComponentManager.Capability.POSITIONABLE] }); this.initialized_ = true; }; @@ -214,23 +214,23 @@ ZoomControls.prototype.init = function() { ZoomControls.prototype.dispose = function() { this.workspace_.getComponentManager().removeComponent('zoomControls'); if (this.svgGroup_) { - Blockly.utils.dom.removeNode(this.svgGroup_); + dom.removeNode(this.svgGroup_); } if (this.onZoomResetWrapper_) { - Blockly.browserEvents.unbind(this.onZoomResetWrapper_); + browserEvents.unbind(this.onZoomResetWrapper_); } if (this.onZoomInWrapper_) { - Blockly.browserEvents.unbind(this.onZoomInWrapper_); + browserEvents.unbind(this.onZoomInWrapper_); } if (this.onZoomOutWrapper_) { - Blockly.browserEvents.unbind(this.onZoomOutWrapper_); + browserEvents.unbind(this.onZoomOutWrapper_); } }; /** * Returns the bounding rectangle of the UI element in pixel units relative to * the Blockly injection div. - * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if + * @return {?Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ ZoomControls.prototype.getBoundingRectangle = function() { @@ -240,7 +240,7 @@ ZoomControls.prototype.getBoundingRectangle = function() { } const bottom = this.top_ + height; const right = this.left_ + this.WIDTH_; - return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); + return new Rect(this.top_, bottom, this.left_, right); }; @@ -249,7 +249,7 @@ ZoomControls.prototype.getBoundingRectangle = function() { * It is positioned in the opposite corner to the corner the * categories/toolbox starts at. * @param {!Blockly.MetricsManager.UiMetrics} metrics The workspace metrics. - * @param {!Array} savedPositions List of rectangles that + * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ ZoomControls.prototype.position = function(metrics, savedPositions) { @@ -259,25 +259,25 @@ ZoomControls.prototype.position = function(metrics, savedPositions) { } const cornerPosition = - Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); + uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - const startRect = Blockly.uiPosition.getStartPositionRect( - cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), + const startRect = uiPosition.getStartPositionRect( + cornerPosition, new utils.Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); const verticalPosition = cornerPosition.vertical; const bumpDirection = - verticalPosition === Blockly.uiPosition.verticalPosition.TOP ? - Blockly.uiPosition.bumpDirection.DOWN : - Blockly.uiPosition.bumpDirection.UP; - const positionRect = Blockly.uiPosition.bumpPositionRect( + verticalPosition === uiPosition.verticalPosition.TOP ? + uiPosition.bumpDirection.DOWN : + uiPosition.bumpDirection.UP; + const positionRect = uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); - if (verticalPosition === Blockly.uiPosition.verticalPosition.TOP) { + if (verticalPosition === uiPosition.verticalPosition.TOP) { const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); @@ -321,38 +321,38 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { clip-path="url(#blocklyZoomoutClipPath837493)"> */ - this.zoomOutGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomOutGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoomoutClipPath' + rnd }, this.zoomOutGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32, }, clip); - const zoomoutSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoomoutSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'x': -64, 'y': -92, 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')' }, this.zoomOutGroup_); zoomoutSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach listener. - this.onZoomOutWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomOutWrapper_ = browserEvents.conditionalBind( this.zoomOutGroup_, 'mousedown', null, this.zoom_.bind(this, -1)); }; @@ -373,38 +373,38 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { clip-path="url(#blocklyZoominClipPath837493)"> */ - this.zoomInGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomInGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoominClipPath' + rnd }, this.zoomInGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32, }, clip); - const zoominSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoominSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'x': -32, 'y': -92, 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')' }, this.zoomInGroup_); zoominSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach listener. - this.onZoomInWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomInWrapper_ = browserEvents.conditionalBind( this.zoomInGroup_, 'mousedown', null, this.zoom_.bind(this, 1)); }; @@ -420,7 +420,7 @@ ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.markFocused(); this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); - Blockly.Touch.clearTouchIdentifier(); // Don't block future drags. + Touch.clearTouchIdentifier(); // Don't block future drags. e.stopPropagation(); // Don't start a workspace scroll. e.preventDefault(); // Stop double-clicking from selecting text. }; @@ -442,37 +442,37 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { clip-path="url(#blocklyZoomresetClipPath837493)"> */ - this.zoomResetGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomResetGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoomresetClipPath' + rnd }, this.zoomResetGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32 }, clip); - const zoomresetSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoomresetSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'y': -92, 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')' }, this.zoomResetGroup_); zoomresetSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach event listeners. - this.onZoomResetWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomResetWrapper_ = browserEvents.conditionalBind( this.zoomResetGroup_, 'mousedown', null, this.resetZoom_.bind(this)); }; @@ -500,7 +500,7 @@ ZoomControls.prototype.resetZoom_ = function(e) { setTimeout(this.workspace_.endCanvasTransition.bind(this.workspace_), 500); this.fireZoomEvent_(); - Blockly.Touch.clearTouchIdentifier(); // Don't block future drags. + Touch.clearTouchIdentifier(); // Don't block future drags. e.stopPropagation(); // Don't start a workspace scroll. e.preventDefault(); // Stop double-clicking from selecting text. }; @@ -510,15 +510,15 @@ ZoomControls.prototype.resetZoom_ = function(e) { * @private */ ZoomControls.prototype.fireZoomEvent_ = function() { - const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( + const uiEvent = new (Events.get(Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); - Blockly.Events.fire(uiEvent); + Events.fire(uiEvent); }; /** * CSS for zoom controls. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyZoom>image, .blocklyZoom>svg>image {', 'opacity: .4;', From 5a5aabb7e7a759ce254cd675be84ad8e297285b8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:09:14 -0700 Subject: [PATCH 118/172] clang-format core/zoom_controls.js --- core/zoom_controls.js | 133 +++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 80 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 84451bbd1..37c1cb17d 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -178,8 +178,7 @@ ZoomControls.prototype.initialized_ = false; * @return {!SVGElement} The zoom controls SVG group. */ ZoomControls.prototype.createDom = function() { - this.svgGroup_ = dom.createSvgElement( - Svg.G, {}, null); + this.svgGroup_ = dom.createSvgElement(Svg.G, {}, null); // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. @@ -266,42 +265,40 @@ ZoomControls.prototype.position = function(metrics, savedPositions) { } const startRect = uiPosition.getStartPositionRect( cornerPosition, new utils.Size(this.WIDTH_, height), - this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, - this.workspace_); + this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); const verticalPosition = cornerPosition.vertical; - const bumpDirection = - verticalPosition === uiPosition.verticalPosition.TOP ? - uiPosition.bumpDirection.DOWN : - uiPosition.bumpDirection.UP; + const bumpDirection = verticalPosition === uiPosition.verticalPosition.TOP ? + uiPosition.bumpDirection.DOWN : + uiPosition.bumpDirection.UP; const positionRect = uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); if (verticalPosition === uiPosition.verticalPosition.TOP) { const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; - this.zoomInGroup_.setAttribute('transform', - 'translate(0, ' + zoomInTranslateY + ')'); + this.zoomInGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomInTranslateY + ')'); if (this.zoomResetGroup_) { const zoomResetTranslateY = zoomInTranslateY + this.LARGE_SPACING_ + this.HEIGHT_; - this.zoomResetGroup_.setAttribute('transform', - 'translate(0, ' + zoomResetTranslateY + ')'); + this.zoomResetGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomResetTranslateY + ')'); } } else { - const zoomInTranslateY = this.zoomResetGroup_ ? - this.LARGE_SPACING_ + this.HEIGHT_ : 0; - this.zoomInGroup_.setAttribute('transform', - 'translate(0, ' + zoomInTranslateY + ')'); + const zoomInTranslateY = + this.zoomResetGroup_ ? this.LARGE_SPACING_ + this.HEIGHT_ : 0; + this.zoomInGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomInTranslateY + ')'); const zoomOutTranslateY = zoomInTranslateY + this.SMALL_SPACING_ + this.HEIGHT_; - this.zoomOutGroup_.setAttribute('transform', - 'translate(0, ' + zoomOutTranslateY + ')'); + this.zoomOutGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomOutTranslateY + ')'); } this.top_ = positionRect.top; this.left_ = positionRect.left; - this.svgGroup_.setAttribute('transform', - 'translate(' + this.left_ + ',' + this.top_ + ')'); + this.svgGroup_.setAttribute( + 'transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); }; /** @@ -317,22 +314,17 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { */ - this.zoomOutGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomOutGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoomoutClipPath' + rnd - }, - this.zoomOutGroup_); + Svg.CLIPPATH, {'id': 'blocklyZoomoutClipPath' + rnd}, this.zoomOutGroup_); dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'width': 32, 'height': 32, }, @@ -348,8 +340,7 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { this.zoomOutGroup_); zoomoutSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach listener. this.onZoomOutWrapper_ = browserEvents.conditionalBind( @@ -369,22 +360,17 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { - */ - this.zoomInGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomInGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoominClipPath' + rnd - }, - this.zoomInGroup_); + Svg.CLIPPATH, {'id': 'blocklyZoominClipPath' + rnd}, this.zoomInGroup_); dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'width': 32, 'height': 32, }, @@ -400,8 +386,7 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { this.zoomInGroup_); zoominSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach listener. this.onZoomInWrapper_ = browserEvents.conditionalBind( @@ -421,8 +406,8 @@ ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); Touch.clearTouchIdentifier(); // Don't block future drags. - e.stopPropagation(); // Don't start a workspace scroll. - e.preventDefault(); // Stop double-clicking from selecting text. + e.stopPropagation(); // Don't start a workspace scroll. + e.preventDefault(); // Stop double-clicking from selecting text. }; /** @@ -438,26 +423,17 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { - */ - this.zoomResetGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomResetGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoomresetClipPath' + rnd - }, + Svg.CLIPPATH, {'id': 'blocklyZoomresetClipPath' + rnd}, this.zoomResetGroup_); - dom.createSvgElement( - Svg.RECT, - { - 'width': 32, - 'height': 32 - }, - clip); + dom.createSvgElement(Svg.RECT, {'width': 32, 'height': 32}, clip); const zoomresetSvg = dom.createSvgElement( Svg.IMAGE, { 'width': internalConstants.SPRITE.width, @@ -468,8 +444,7 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { this.zoomResetGroup_); zoomresetSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach event listeners. this.onZoomResetWrapper_ = browserEvents.conditionalBind( @@ -501,8 +476,8 @@ ZoomControls.prototype.resetZoom_ = function(e) { setTimeout(this.workspace_.endCanvasTransition.bind(this.workspace_), 500); this.fireZoomEvent_(); Touch.clearTouchIdentifier(); // Don't block future drags. - e.stopPropagation(); // Don't start a workspace scroll. - e.preventDefault(); // Stop double-clicking from selecting text. + e.stopPropagation(); // Don't start a workspace scroll. + e.preventDefault(); // Stop double-clicking from selecting text. }; /** @@ -510,8 +485,8 @@ ZoomControls.prototype.resetZoom_ = function(e) { * @private */ ZoomControls.prototype.fireZoomEvent_ = function() { - const uiEvent = new (Events.get(Events.CLICK))( - null, this.workspace_.id, 'zoom_controls'); + const uiEvent = + new (Events.get(Events.CLICK))(null, this.workspace_.id, 'zoom_controls'); Events.fire(uiEvent); }; @@ -519,19 +494,17 @@ ZoomControls.prototype.fireZoomEvent_ = function() { * CSS for zoom controls. See css.js for use. */ Css.register([ - /* eslint-disable indent */ - '.blocklyZoom>image, .blocklyZoom>svg>image {', - 'opacity: .4;', - '}', + `.blocklyZoom>image, .blocklyZoom>svg>image { + opacity: .4; +}`, - '.blocklyZoom>image:hover, .blocklyZoom>svg>image:hover {', - 'opacity: .6;', - '}', + `.blocklyZoom>image:hover, .blocklyZoom>svg>image:hover { + opacity: .6; +}`, - '.blocklyZoom>image:active, .blocklyZoom>svg>image:active {', - 'opacity: .8;', - '}' - /* eslint-enable indent */ + `.blocklyZoom>image:active, .blocklyZoom>svg>image:active { + 'opacity: .8; +}` ]); exports = ZoomControls; From 636cd58add1b0449e6b91d660374eecd1eedae4d Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 12:35:21 -0700 Subject: [PATCH 119/172] Add comment to top of convert-file script for reference to syntax used throughout the file --- scripts/goog_module/convert-file.sh | 55 +++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 6a8d36cd0..9f8ea63ee 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -1,5 +1,39 @@ #!/bin/bash +# This file makes extensive use of perl for the purpose of extracting and +# replacing string (regex) patterns in a way that is both GNU and macOS +# compatible. +# +# Common perl flags used (also decribed at https://perldoc.perl.org/perlrun): +# -e : Used to execute perl programs on the command line +# -p : Assumes an input loop around script. Prints every processed line. +# -n : Assumes an input loop around script. Does not print every line. +# -i : Used for in-place editing. Used for commands for find/replace. +# -l[octnum] : Assigns the output record separator "$/" as an octal number. If +# octnum is not present, sets output record separator to the current +# value of the input record separator "$\". +# +# Common perl commands found: +# 1. perl -pi -e 's/regex/replacement/modifiers' +# This command does an in-place search-and-replace. The global ("/g") modifier +# causes it to replace all occurrences, rather than only the first match. +# 2. perl -ne 'print m/regex/modifiers' +# This command returns the all regex matches. If the global ("/g") modifier is +# specified, then the capture group "()" is not necessary and it will return +# all matches, rather than only the first match. +# 3. perl -nle 'print $& while m{regex}modifiers' +# Similar to (2), but returns regex matches separated by newlines. +# The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. +# +# Additional information on regex: +# This script makes use of some advanced regex syntax such as "capture groups" +# and "lookaround assertions". +# Additionally, characters are escaped from regex with a backslash "\". +# Single quotes need to be escaped in both regex and the string, resulting in +# '\'' being used to represent a single quote character. +# For a reference to syntax of regular expressions in Perl, see: +# https://perldoc.perl.org/perire + ####################################### # Logging functions. ####################################### @@ -98,10 +132,10 @@ step2 () { local filepath="$1" inf "Updating goog.provide declaration..." - perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/g' "${filepath}" + perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/' "${filepath}" inf "Extracting module name..." - local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") + local module_name=$(perl -ne 'print m/(?<=^goog\.module\('\'')([^'\'']+)/' "${filepath}") if [[ -z "${module_name}" ]]; then err "Could not extract module name" return 1 @@ -109,7 +143,7 @@ step2 () { inf "Extracted module name \"${module_name}\"" if [[ $(grep "${module_name} = " "${filepath}") ]]; then - local class_name=$(echo "${module_name}" | perl -nle'print $& while m{(\w+)$}g') + local class_name=$(echo "${module_name}" | perl -ne 'print m/(\w+)$/') inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" @@ -144,19 +178,19 @@ step2 () { ####################################### step3() { inf "Extracting module name..." - local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") + local module_name=$(perl -ne 'print m/(?<=^goog\.module\('\'')([^'\'']+)/' "${filepath}") if [[ -z "${module_name}" ]]; then err "Could not extract module name" return 1 fi inf "Extracted module name \"${module_name}\"" - local requires=$(perl -nle'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") + local requires=$(perl -nle 'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") # Process each require echo "${requires}" | while read -r require; do inf "Processing require \"${require}\"" - local usages=$(perl -nle'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) + local usages=$(perl -nle 'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) if [[ "${usages}" -eq "0" ]]; then warn "Unused require \"${require}\"" @@ -168,11 +202,12 @@ step3() { perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" # Parse property access of module - local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) - local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) + local direct_access_count=$(perl -nle 'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) + local properties_accessed=$(perl -nle 'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | sort -u) + # Detect requires overlap # (ex: Blockly.utils require and Blockly.utils.dom also in requires) - local requires_overlap=$(echo "${requires}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + local requires_overlap=$(echo "${requires}" | perl -nle 'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ -n "${requires_overlap}" ]]; then while read -r requires_overlap_prop; do properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') @@ -180,7 +215,7 @@ step3() { fi # Detect module name overlap # (ex: Blockly require and Blockly.ContextMenuItems module being converted) - local module_overlap=$(echo "${module_name}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + local module_overlap=$(echo "${module_name}" | perl -nle 'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ -n "${module_overlap}" ]]; then properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') fi From f64e8df4866056444c44505f771397e40ea0fed1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 15:26:16 -0700 Subject: [PATCH 120/172] Update wording --- scripts/goog_module/convert-file.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 9f8ea63ee..0246be0be 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -18,9 +18,10 @@ # This command does an in-place search-and-replace. The global ("/g") modifier # causes it to replace all occurrences, rather than only the first match. # 2. perl -ne 'print m/regex/modifiers' -# This command returns the all regex matches. If the global ("/g") modifier is -# specified, then the capture group "()" is not necessary and it will return -# all matches, rather than only the first match. +# This command returns a string containing the regex match. The regex must +# contain a capture group "()", unless the global ("\g") modifier is +# specified. This will return the first match, unless the global modifier is +# specified, in which case, it will return all matches. # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. From 3fbbedf6f1c9156b7ddfd64d4e82b8a28271c191 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 18:10:53 -0700 Subject: [PATCH 121/172] Fix typos and update wording again --- scripts/goog_module/convert-file.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 0246be0be..38ac2eafb 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -4,11 +4,11 @@ # replacing string (regex) patterns in a way that is both GNU and macOS # compatible. # -# Common perl flags used (also decribed at https://perldoc.perl.org/perlrun): +# Common perl flags used (also described at https://perldoc.perl.org/perlrun): # -e : Used to execute perl programs on the command line # -p : Assumes an input loop around script. Prints every processed line. # -n : Assumes an input loop around script. Does not print every line. -# -i : Used for in-place editing. Used for commands for find/replace. +# -i : Used for in-place editing. Used in commands for find/replace. # -l[octnum] : Assigns the output record separator "$/" as an octal number. If # octnum is not present, sets output record separator to the current # value of the input record separator "$\". @@ -18,10 +18,11 @@ # This command does an in-place search-and-replace. The global ("/g") modifier # causes it to replace all occurrences, rather than only the first match. # 2. perl -ne 'print m/regex/modifiers' -# This command returns a string containing the regex match. The regex must -# contain a capture group "()", unless the global ("\g") modifier is -# specified. This will return the first match, unless the global modifier is -# specified, in which case, it will return all matches. +# This command returns a string containing the regex match (designated by the +# capture group "()" in the regex). This will return the first match, unless +# the global modifier is specified, in which case, it will return all matches. +# If this command is used without a capture group it returns true or false (in +# the form a truthy or falsey value) # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. @@ -33,7 +34,7 @@ # Single quotes need to be escaped in both regex and the string, resulting in # '\'' being used to represent a single quote character. # For a reference to syntax of regular expressions in Perl, see: -# https://perldoc.perl.org/perire +# https://perldoc.perl.org/perlre ####################################### # Logging functions. @@ -240,7 +241,7 @@ step3() { missing_requires=$(echo "${missing_requires}" | tr ' ' '\n' | sort -u) if [[ -n "${missing_requires}" ]]; then # Search for the string goog.require('Blockly') or goog.requireType('Blockly') - local has_blockly_require=$(perl -ne'print m{goog\.(require|requireType)\('\''Blockly'\''\)}g' "${filepath}") + local has_blockly_require=$(perl -ne 'print m/goog\.(?:require|requireType)\('\''Blockly'\''\)/' "${filepath}") if [[ -n "${has_blockly_require}" ]]; then warn 'Blockly detected as a require.' warn "Potentially missing requires for:\n${missing_requires}\nPlease manually review." From 7495fad6b3d9e489e504f66a7b19e96288df55c4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 18:37:13 -0700 Subject: [PATCH 122/172] Add missing period and fix typo --- scripts/goog_module/convert-file.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 38ac2eafb..ebf791d3b 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -22,7 +22,7 @@ # capture group "()" in the regex). This will return the first match, unless # the global modifier is specified, in which case, it will return all matches. # If this command is used without a capture group it returns true or false (in -# the form a truthy or falsey value) +# the form a truthy or falsy value). # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. From c068a3b6f9dcd304278bd5aa87a0d66460d698df Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:26:04 -0700 Subject: [PATCH 123/172] 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 124/172] 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 125/172] 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 126/172] 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 127/172] 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 128/172] 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 129/172] 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 130/172] 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 131/172] 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 132/172] 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 133/172] 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 134/172] 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 135/172] 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 136/172] 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 137/172] 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 138/172] 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 139/172] 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 140/172] 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 141/172] 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 142/172] 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 143/172] 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 144/172] 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 145/172] 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 146/172] 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 147/172] 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 148/172] 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 149/172] 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 311373230fed2adb4cdfd103a87d412902f574e3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 28 Jul 2021 14:48:08 -0700 Subject: [PATCH 150/172] 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 151/172] 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 152/172] 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 34042519f47492a9041e071556a18b8999858cbc Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 29 Jul 2021 15:00:44 -0700 Subject: [PATCH 153/172] 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 154/172] 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 787145acf46c6feae193b521477d25c402b0ebca Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:40:48 -0700 Subject: [PATCH 155/172] 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 156/172] 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 157/172] 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 158/172] 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 159/172] 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 160/172] 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 161/172] 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 162/172] 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 163/172] 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 164/172] 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 165/172] 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 @@