From 1e81334c15cffda802a0d44f27ffc993052483a8 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 14:15:25 -0700 Subject: [PATCH 01/48] Migrate core/renderers/common/info.js to ES6 const/let --- core/renderers/common/info.js | 108 +++++++++++++++++----------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index f3eac053a..9c5d62a9a 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -205,13 +205,13 @@ Blockly.blockRendering.RenderInfo.prototype.measure = function() { Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); - var activeRow = new Blockly.blockRendering.InputRow(this.constants_); + let activeRow = new Blockly.blockRendering.InputRow(this.constants_); this.inputRows.push(activeRow); // Icons always go on the first row, before anything else. - var icons = this.block_.getIcons(); - for (var i = 0, icon; (icon = icons[i]); i++) { - var iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); + const icons = this.block_.getIcons(); + for (let i = 0, icon; (icon = icons[i]); i++) { + const iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); if (this.isCollapsed && icon.collapseHidden) { this.hiddenIcons.push(iconInfo); } else { @@ -219,10 +219,10 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { } } - var lastInput = null; + let lastInput = null; // Loop across all of the inputs on the block, creating objects for anything // that needs to be rendered and breaking the block up into visual rows. - for (var i = 0, input; (input = this.block_.inputList[i]); i++) { + for (let i = 0, input; (input = this.block_.inputList[i]); i++) { if (!input.isVisible()) { continue; } @@ -234,7 +234,7 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { } // All of the fields in an input go on the same row. - for (var j = 0, field; (field = input.fieldRow[j]); j++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { activeRow.elements.push( new Blockly.blockRendering.Field(this.constants_, field, input)); } @@ -260,17 +260,18 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { * @package */ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { - var hasPrevious = !!this.block_.previousConnection; - var hasHat = (this.block_.hat ? - this.block_.hat === 'cap' : this.constants_.ADD_START_HATS) && + const hasPrevious = !!this.block_.previousConnection; + const hasHat = (this.block_.hat ? this.block_.hat === 'cap' : + this.constants_.ADD_START_HATS) && !this.outputConnection && !hasPrevious; - var cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : Blockly.blockRendering.RoundCorner; + let cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? + Blockly.blockRendering.SquareCorner : + Blockly.blockRendering.RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_)); if (hasHat) { - var hat = new Blockly.blockRendering.Hat(this.constants_); + const hat = new Blockly.blockRendering.Hat(this.constants_); this.topRow.elements.push(hat); this.topRow.capline = hat.ascenderHeight; } else if (hasPrevious) { @@ -282,7 +283,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { this.topRow.elements.push(this.topRow.connection); } - var precedesStatement = this.block_.inputList.length && + const precedesStatement = this.block_.inputList.length && this.block_.inputList[0].type == Blockly.inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a @@ -306,7 +307,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; - var followsStatement = this.block_.inputList.length && + const followsStatement = this.block_.inputList.length && this.block_.inputList[this.block_.inputList.length - 1].type == Blockly.inputTypes.STATEMENT; @@ -319,7 +320,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.minHeight = this.constants_.BOTTOM_ROW_MIN_HEIGHT; } - var leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); + const leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); if (leftSquareCorner) { this.bottomRow.elements.push( @@ -336,7 +337,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.elements.push(this.bottomRow.connection); } - var rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); + const rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); if (rightSquareCorner) { this.bottomRow.elements.push( @@ -414,8 +415,8 @@ Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, * @protected */ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { - for (var i = 0, row; (row = this.rows[i]); i++) { - var oldElems = row.elements; + for (let i = 0, row; (row = this.rows[i]); i++) { + const oldElems = row.elements; row.elements = []; // No spacing needed before the corner on the top row or the bottom row. if (row.startsWithElemSpacer()) { @@ -426,9 +427,9 @@ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { if (!oldElems.length) { continue; } - for (var e = 0; e < oldElems.length - 1; e++) { + for (let e = 0; e < oldElems.length - 1; e++) { row.elements.push(oldElems[e]); - var spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); + const spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); row.elements.push( new Blockly.blockRendering.InRowSpacer(this.constants_, spacing)); } @@ -496,15 +497,15 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne */ // TODO: More cleanup. Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { - var widestStatementRowFields = 0; - var blockWidth = 0; - var widestRowWithConnectedBlocks = 0; - for (var i = 0, row; (row = this.rows[i]); i++) { + let widestStatementRowFields = 0; + let blockWidth = 0; + let widestRowWithConnectedBlocks = 0; + for (let i = 0, row; (row = this.rows[i]); i++) { row.measure(); blockWidth = Math.max(blockWidth, row.width); if (row.hasStatement) { - var statementInput = row.getLastInput(); - var innerWidth = row.width - statementInput.width; + const statementInput = row.getLastInput(); + const innerWidth = row.width - statementInput.width; widestStatementRowFields = Math.max(widestStatementRowFields, innerWidth); } widestRowWithConnectedBlocks = @@ -514,7 +515,7 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { this.statementEdge = widestStatementRowFields; this.width = blockWidth; - for (var i = 0, row; (row = this.rows[i]); i++) { + for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { row.statementEdge = this.statementEdge; } @@ -536,14 +537,14 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { * @protected */ Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { - for (var i = 0, row; (row = this.rows[i]); i++) { + for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( /** @type {!Blockly.blockRendering.InputRow} */ (row)); } else { - var currentWidth = row.width; - var desiredWidth = this.getDesiredRowWidth_(row); - var missingSpace = desiredWidth - currentWidth; + const currentWidth = row.width; + const desiredWidth = this.getDesiredRowWidth_(row); + const missingSpace = desiredWidth - currentWidth; if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } @@ -573,10 +574,10 @@ Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( * @param {number} missingSpace How much padding to add. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row, - missingSpace) { - var firstSpacer = row.getFirstSpacer(); - var lastSpacer = row.getLastSpacer(); +Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( + row, missingSpace) { + const firstSpacer = row.getFirstSpacer(); + const lastSpacer = row.getLastSpacer(); if (row.hasExternalInput || row.hasStatement) { row.widthWithConnectedBlocks += missingSpace; } @@ -606,11 +607,11 @@ Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row, * @protected */ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { - var statementInput = row.getLastInput(); - var currentWidth = row.width - statementInput.width; - var desiredWidth = this.statementEdge; + const statementInput = row.getLastInput(); + let currentWidth = row.width - statementInput.width; + let desiredWidth = this.statementEdge; // Add padding before the statement input. - var missingSpace = desiredWidth - currentWidth; + const missingSpace = desiredWidth - currentWidth; if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } @@ -630,10 +631,10 @@ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { * @protected */ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { - var oldRows = this.rows; + const oldRows = this.rows; this.rows = []; - for (var r = 0; r < oldRows.length; r++) { + for (let r = 0; r < oldRows.length; r++) { this.rows.push(oldRows[r]); if (r != oldRows.length - 1) { this.rows.push(this.makeSpacerRow_(oldRows[r], oldRows[r + 1])); @@ -648,11 +649,12 @@ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { - var height = this.getSpacerRowHeight_(prev, next); - var width = this.getSpacerRowWidth_(prev, next); - var spacer = new Blockly.blockRendering.SpacerRow( - this.constants_, height, width); +Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( + prev, next) { + const height = this.getSpacerRowHeight_(prev, next); + const width = this.getSpacerRowWidth_(prev, next); + const spacer = + new Blockly.blockRendering.SpacerRow(this.constants_, height, width); if (prev.hasStatement) { spacer.followsStatement = true; } @@ -703,7 +705,7 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, return row.yPos + elem.height / 2; } if (Blockly.blockRendering.Types.isBottomRow(row)) { - var baseline = row.yPos + row.height - row.descenderHeight; + const baseline = row.yPos + row.height - row.descenderHeight; if (Blockly.blockRendering.Types.isNextConnection(elem)) { return baseline + elem.height / 2; } @@ -726,8 +728,8 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, */ Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( row) { - var xCursor = row.xPos; - for (var j = 0, elem; (elem = row.elements[j]); j++) { + let xCursor = row.xPos; + for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. if (Blockly.blockRendering.Types.isSpacer(elem)) { elem.height = row.height; @@ -747,9 +749,9 @@ Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { // Performance note: this could be combined with the draw pass, if the time // that this takes is excessive. But it shouldn't be, because it only // accesses and sets properties that already exist on the objects. - var widestRowWithConnectedBlocks = 0; - var yCursor = 0; - for (var i = 0, row; (row = this.rows[i]); i++) { + let widestRowWithConnectedBlocks = 0; + let yCursor = 0; + for (let i = 0, row; (row = this.rows[i]); i++) { row.yPos = yCursor; row.xPos = this.startX; yCursor += row.height; From 20079a64aa66b87ca2ee8026801178fb4178ebb3 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 14:38:01 -0700 Subject: [PATCH 02/48] Migrate core/renderers/common/info.js to goog.module --- core/renderers/common/info.js | 56 ++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 9c5d62a9a..6efc4692f 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockRendering.RenderInfo'); +goog.module('Blockly.blockRendering.RenderInfo'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockRendering.BottomRow'); goog.require('Blockly.blockRendering.ExternalValueInput'); @@ -55,7 +56,7 @@ goog.requireType('Blockly.RenderedConnection'); * @constructor * @package */ -Blockly.blockRendering.RenderInfo = function(renderer, block) { +const RenderInfo = function(renderer, block) { this.block_ = block; /** @@ -174,7 +175,7 @@ Blockly.blockRendering.RenderInfo = function(renderer, block) { * @return {!Blockly.blockRendering.Renderer} The block renderer in use. * @package */ -Blockly.blockRendering.RenderInfo.prototype.getRenderer = function() { +RenderInfo.prototype.getRenderer = function() { return this.renderer_; }; @@ -188,7 +189,7 @@ Blockly.blockRendering.RenderInfo.prototype.getRenderer = function() { * * @package */ -Blockly.blockRendering.RenderInfo.prototype.measure = function() { +RenderInfo.prototype.measure = function() { this.createRows_(); this.addElemSpacing_(); this.addRowSpacing_(); @@ -202,7 +203,7 @@ Blockly.blockRendering.RenderInfo.prototype.measure = function() { * block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { +RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); let activeRow = new Blockly.blockRendering.InputRow(this.constants_); @@ -259,7 +260,7 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { * Create all non-spacer elements that belong on the top row. * @package */ -Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { +RenderInfo.prototype.populateTopRow_ = function() { const hasPrevious = !!this.block_.previousConnection; const hasHat = (this.block_.hat ? this.block_.hat === 'cap' : this.constants_.ADD_START_HATS) && @@ -304,7 +305,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { * Create all non-spacer elements that belong on the bottom row. * @package */ -Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { +RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; const followsStatement = this.block_.inputList.length && @@ -356,7 +357,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { * populated. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRow) { +RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. if (this.isInline && input.type == Blockly.inputTypes.VALUE) { activeRow.elements.push( @@ -391,7 +392,7 @@ Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRo * @return {boolean} True if the next input should be rendered on a new row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { +RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { // If this is the first input, just add to the existing row. // That row is either empty or has some icons in it. if (!lastInput) { @@ -414,7 +415,7 @@ Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, * Add horizontal spacing between and around elements within each row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { +RenderInfo.prototype.addElemSpacing_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { const oldElems = row.elements; row.elements = []; @@ -453,7 +454,7 @@ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { * @return {number} The size of the spacing between the two elements. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { +RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Statement input padding. if (next && Blockly.blockRendering.Types.isStatementInput(next)) { @@ -496,7 +497,7 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne * @protected */ // TODO: More cleanup. -Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { +RenderInfo.prototype.computeBounds_ = function() { let widestStatementRowFields = 0; let blockWidth = 0; let widestRowWithConnectedBlocks = 0; @@ -536,7 +537,7 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { * the sizes of all rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { +RenderInfo.prototype.alignRowElements_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( @@ -561,8 +562,7 @@ Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { * @return {number} The desired width of the input row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( - _row) { +RenderInfo.prototype.getDesiredRowWidth_ = function(_row) { return this.width - this.startX; }; @@ -574,8 +574,7 @@ Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( * @param {number} missingSpace How much padding to add. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( - row, missingSpace) { +RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { const firstSpacer = row.getFirstSpacer(); const lastSpacer = row.getLastSpacer(); if (row.hasExternalInput || row.hasStatement) { @@ -606,7 +605,7 @@ Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( * @param {!Blockly.blockRendering.InputRow} row The statement row to resize. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { +RenderInfo.prototype.alignStatementRow_ = function(row) { const statementInput = row.getLastInput(); let currentWidth = row.width - statementInput.width; let desiredWidth = this.statementEdge; @@ -630,7 +629,7 @@ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { * Add spacers between rows and set their sizes. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { +RenderInfo.prototype.addRowSpacing_ = function() { const oldRows = this.rows; this.rows = []; @@ -649,8 +648,7 @@ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( - prev, next) { +RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { const height = this.getSpacerRowHeight_(prev, next); const width = this.getSpacerRowWidth_(prev, next); const spacer = @@ -671,8 +669,7 @@ Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( * @return {number} The desired width of the spacer row between these two rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getSpacerRowWidth_ = function( - _prev, _next) { +RenderInfo.prototype.getSpacerRowWidth_ = function(_prev, _next) { return this.width - this.startX; }; @@ -683,8 +680,7 @@ Blockly.blockRendering.RenderInfo.prototype.getSpacerRowWidth_ = function( * @return {number} The desired height of the spacer row between these two rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getSpacerRowHeight_ = function( - _prev, _next) { +RenderInfo.prototype.getSpacerRowHeight_ = function(_prev, _next) { return this.constants_.MEDIUM_PADDING; }; @@ -699,8 +695,7 @@ Blockly.blockRendering.RenderInfo.prototype.getSpacerRowHeight_ = function( * from the top left of the block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, - elem) { +RenderInfo.prototype.getElemCenterline_ = function(row, elem) { if (Blockly.blockRendering.Types.isSpacer(elem)) { return row.yPos + elem.height / 2; } @@ -726,8 +721,7 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, * @param {!Blockly.blockRendering.Row} row The row containing the elements. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( - row) { +RenderInfo.prototype.recordElemPositions_ = function(row) { let xCursor = row.xPos; for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. @@ -745,7 +739,7 @@ Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( * store the y position of each row, and record the height of the full block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { +RenderInfo.prototype.finalize_ = function() { // Performance note: this could be combined with the draw pass, if the time // that this takes is excessive. But it shouldn't be, because it only // accesses and sets properties that already exist on the objects. @@ -774,3 +768,5 @@ Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { this.startY = this.topRow.capline; this.bottomRow.baseline = yCursor - this.bottomRow.descenderHeight; }; + +exports = RenderInfo; diff --git a/tests/deps.js b/tests/deps.js index 5a06dd4ae..8baeee5ab 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); From b3877ffbb9e720351bb2e3aa27982584233fffe1 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 15:13:41 -0700 Subject: [PATCH 03/48] Migrate core/renderers/common/info.js to named requires --- core/renderers/common/info.js | 249 ++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 118 insertions(+), 133 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 6efc4692f..3c5e70ee4 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -13,35 +13,34 @@ goog.module('Blockly.blockRendering.RenderInfo'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockRendering.BottomRow'); -goog.require('Blockly.blockRendering.ExternalValueInput'); -goog.require('Blockly.blockRendering.Field'); -goog.require('Blockly.blockRendering.Hat'); -goog.require('Blockly.blockRendering.InlineInput'); -goog.require('Blockly.blockRendering.InputRow'); -goog.require('Blockly.blockRendering.InRowSpacer'); -goog.require('Blockly.blockRendering.JaggedEdge'); -goog.require('Blockly.blockRendering.Measurable'); -goog.require('Blockly.blockRendering.NextConnection'); -goog.require('Blockly.blockRendering.OutputConnection'); -goog.require('Blockly.blockRendering.PreviousConnection'); -goog.require('Blockly.blockRendering.RoundCorner'); -goog.require('Blockly.blockRendering.Row'); -goog.require('Blockly.blockRendering.SpacerRow'); -goog.require('Blockly.blockRendering.SquareCorner'); -goog.require('Blockly.blockRendering.StatementInput'); -goog.require('Blockly.blockRendering.TopRow'); -goog.require('Blockly.blockRendering.Types'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const BottomRow = goog.require('Blockly.blockRendering.BottomRow'); +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +const ExternalValueInput = goog.require('Blockly.blockRendering.ExternalValueInput'); +const Field = goog.require('Blockly.blockRendering.Field'); +const Hat = goog.require('Blockly.blockRendering.Hat'); +const Icon = goog.require('Blockly.blockRendering.Icon'); +const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); +const Input = goog.requireType('Blockly.Input'); +const InputRow = goog.require('Blockly.blockRendering.InputRow'); +const inputTypes = goog.require('Blockly.inputTypes'); +const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); +const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); +const Measurable = goog.require('Blockly.blockRendering.Measurable'); +const NextConnection = goog.require('Blockly.blockRendering.NextConnection'); +const OutputConnection = goog.require('Blockly.blockRendering.OutputConnection'); +const PreviousConnection = goog.require('Blockly.blockRendering.PreviousConnection'); +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const Renderer = goog.requireType('Blockly.blockRendering.Renderer'); +const RoundCorner = goog.require('Blockly.blockRendering.RoundCorner'); +const Row = goog.require('Blockly.blockRendering.Row'); +const SpacerRow = goog.require('Blockly.blockRendering.SpacerRow'); +const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); +const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); +const TopRow = goog.require('Blockly.blockRendering.TopRow'); +const Types = goog.require('Blockly.blockRendering.Types'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -goog.require('Blockly.inputTypes'); - -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.blockRendering.Icon'); -goog.requireType('Blockly.blockRendering.Renderer'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Input'); -goog.requireType('Blockly.RenderedConnection'); +const blocklyConstants = goog.require('Blockly.constants'); /** @@ -51,8 +50,8 @@ goog.requireType('Blockly.RenderedConnection'); * may choose to rerender when getSize() is called). However, calling it * repeatedly may be expensive. * - * @param {!Blockly.blockRendering.Renderer} renderer The renderer in use. - * @param {!Blockly.BlockSvg} block The block to measure. + * @param {!Renderer} renderer The renderer in use. + * @param {!BlockSvg} block The block to measure. * @constructor * @package */ @@ -61,14 +60,14 @@ const RenderInfo = function(renderer, block) { /** * The block renderer in use. - * @type {!Blockly.blockRendering.Renderer} + * @type {!Renderer} * @protected */ this.renderer_ = renderer; /** * The renderer's constant provider. - * @type {!Blockly.blockRendering.ConstantProvider} + * @type {!ConstantProvider} * @protected */ this.constants_ = this.renderer_.getConstants(); @@ -76,12 +75,13 @@ const RenderInfo = function(renderer, block) { /** * A measurable representing the output connection if the block has one. * Otherwise null. - * @type {Blockly.blockRendering.OutputConnection} + * @type {OutputConnection} */ - this.outputConnection = !block.outputConnection ? null : - new Blockly.blockRendering.OutputConnection( + this.outputConnection = !block.outputConnection ? + null : + new OutputConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */(block.outputConnection)); + /** @type {RenderedConnection} */ (block.outputConnection)); /** * Whether the block should be rendered as a single line, either because it's @@ -136,33 +136,33 @@ const RenderInfo = function(renderer, block) { /** * An array of Row objects containing sizing information. - * @type {!Array} + * @type {!Array} */ this.rows = []; /** * An array of input rows on the block. - * @type {!Array} + * @type {!Array} */ this.inputRows = []; /** * An array of measurable objects containing hidden icons. - * @type {!Array} + * @type {!Array} */ this.hiddenIcons = []; /** * An object with rendering information about the top row of the block. - * @type {!Blockly.blockRendering.TopRow} + * @type {!TopRow} */ - this.topRow = new Blockly.blockRendering.TopRow(this.constants_); + this.topRow = new TopRow(this.constants_); /** * An object with rendering information about the bottom row of the block. - * @type {!Blockly.blockRendering.BottomRow} + * @type {!BottomRow} */ - this.bottomRow = new Blockly.blockRendering.BottomRow(this.constants_); + this.bottomRow = new BottomRow(this.constants_); // The position of the start point for drawing, relative to the block's // location. @@ -172,7 +172,7 @@ const RenderInfo = function(renderer, block) { /** * Get the block renderer in use. - * @return {!Blockly.blockRendering.Renderer} The block renderer in use. + * @return {!Renderer} The block renderer in use. * @package */ RenderInfo.prototype.getRenderer = function() { @@ -206,13 +206,13 @@ RenderInfo.prototype.measure = function() { RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); - let activeRow = new Blockly.blockRendering.InputRow(this.constants_); + let activeRow = new InputRow(this.constants_); this.inputRows.push(activeRow); // Icons always go on the first row, before anything else. const icons = this.block_.getIcons(); for (let i = 0, icon; (icon = icons[i]); i++) { - const iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); + const iconInfo = new Icon(this.constants_, icon); if (this.isCollapsed && icon.collapseHidden) { this.hiddenIcons.push(iconInfo); } else { @@ -230,14 +230,13 @@ RenderInfo.prototype.createRows_ = function() { if (this.shouldStartNewRow_(input, lastInput)) { // Finish this row and create a new one. this.rows.push(activeRow); - activeRow = new Blockly.blockRendering.InputRow(this.constants_); + activeRow = new InputRow(this.constants_); this.inputRows.push(activeRow); } // All of the fields in an input go on the same row. for (let j = 0, field; (field = input.fieldRow[j]); j++) { - activeRow.elements.push( - new Blockly.blockRendering.Field(this.constants_, field, input)); + activeRow.elements.push(new Field(this.constants_, field, input)); } this.addInput_(input, activeRow); lastInput = input; @@ -245,8 +244,7 @@ RenderInfo.prototype.createRows_ = function() { if (this.isCollapsed) { activeRow.hasJaggedEdge = true; - activeRow.elements.push( - new Blockly.blockRendering.JaggedEdge(this.constants_)); + activeRow.elements.push(new JaggedEdge(this.constants_)); } if (activeRow.elements.length || activeRow.hasDummyInput) { @@ -266,26 +264,25 @@ RenderInfo.prototype.populateTopRow_ = function() { this.constants_.ADD_START_HATS) && !this.outputConnection && !hasPrevious; - let cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : - Blockly.blockRendering.RoundCorner; + let cornerClass = + this.topRow.hasLeftSquareCorner(this.block_) ? SquareCorner : RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_)); if (hasHat) { - const hat = new Blockly.blockRendering.Hat(this.constants_); + const hat = new Hat(this.constants_); this.topRow.elements.push(hat); this.topRow.capline = hat.ascenderHeight; } else if (hasPrevious) { this.topRow.hasPreviousConnection = true; - this.topRow.connection = new Blockly.blockRendering.PreviousConnection( + this.topRow.connection = new PreviousConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */ + /** @type {RenderedConnection} */ (this.block_.previousConnection)); this.topRow.elements.push(this.topRow.connection); } const precedesStatement = this.block_.inputList.length && - this.block_.inputList[0].type == Blockly.inputTypes.STATEMENT; + this.block_.inputList[0].type == inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -296,8 +293,8 @@ RenderInfo.prototype.populateTopRow_ = function() { this.topRow.minHeight = this.constants_.TOP_ROW_MIN_HEIGHT; } - cornerClass = this.topRow.hasRightSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : Blockly.blockRendering.RoundCorner; + cornerClass = this.topRow.hasRightSquareCorner(this.block_) ? SquareCorner : + RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_, 'right')); }; @@ -310,7 +307,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { const followsStatement = this.block_.inputList.length && this.block_.inputList[this.block_.inputList.length - 1].type == - Blockly.inputTypes.STATEMENT; + inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -324,54 +321,47 @@ RenderInfo.prototype.populateBottomRow_ = function() { const leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); if (leftSquareCorner) { - this.bottomRow.elements.push( - new Blockly.blockRendering.SquareCorner(this.constants_)); + this.bottomRow.elements.push(new SquareCorner(this.constants_)); } else { - this.bottomRow.elements.push( - new Blockly.blockRendering.RoundCorner(this.constants_)); + this.bottomRow.elements.push(new RoundCorner(this.constants_)); } if (this.bottomRow.hasNextConnection) { - this.bottomRow.connection = new Blockly.blockRendering.NextConnection( + this.bottomRow.connection = new NextConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */ (this.block_.nextConnection)); + /** @type {RenderedConnection} */ (this.block_.nextConnection)); this.bottomRow.elements.push(this.bottomRow.connection); } const rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); if (rightSquareCorner) { - this.bottomRow.elements.push( - new Blockly.blockRendering.SquareCorner(this.constants_, 'right')); + this.bottomRow.elements.push(new SquareCorner(this.constants_, 'right')); } else { - this.bottomRow.elements.push( - new Blockly.blockRendering.RoundCorner(this.constants_, 'right')); + this.bottomRow.elements.push(new RoundCorner(this.constants_, 'right')); } }; /** * Add an input element to the active row, if needed, and record the type of the * input on the row. - * @param {!Blockly.Input} input The input to record information about. - * @param {!Blockly.blockRendering.Row} activeRow The row that is currently being + * @param {!Input} input The input to record information about. + * @param {!Row} activeRow The row that is currently being * populated. * @protected */ RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. - if (this.isInline && input.type == Blockly.inputTypes.VALUE) { - activeRow.elements.push( - new Blockly.blockRendering.InlineInput(this.constants_, input)); + if (this.isInline && input.type == inputTypes.VALUE) { + activeRow.elements.push(new InlineInput(this.constants_, input)); activeRow.hasInlineInput = true; - } else if (input.type == Blockly.inputTypes.STATEMENT) { - activeRow.elements.push( - new Blockly.blockRendering.StatementInput(this.constants_, input)); + } else if (input.type == inputTypes.STATEMENT) { + activeRow.elements.push(new StatementInput(this.constants_, input)); activeRow.hasStatement = true; - } else if (input.type == Blockly.inputTypes.VALUE) { - activeRow.elements.push( - new Blockly.blockRendering.ExternalValueInput(this.constants_, input)); + } else if (input.type == inputTypes.VALUE) { + activeRow.elements.push(new ExternalValueInput(this.constants_, input)); activeRow.hasExternalInput = true; - } else if (input.type == Blockly.inputTypes.DUMMY) { + } else if (input.type == inputTypes.DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. activeRow.minHeight = Math.max(activeRow.minHeight, @@ -387,8 +377,8 @@ RenderInfo.prototype.addInput_ = function(input, activeRow) { /** * Decide whether to start a new row between the two Blockly.Inputs. - * @param {!Blockly.Input} input The first input to consider - * @param {Blockly.Input} lastInput The input that follows. + * @param {!Input} input The first input to consider + * @param {Input} lastInput The input that follows. * @return {boolean} True if the next input should be rendered on a new row. * @protected */ @@ -399,13 +389,12 @@ RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { return false; } // A statement input or an input following one always gets a new row. - if (input.type == Blockly.inputTypes.STATEMENT || - lastInput.type == Blockly.inputTypes.STATEMENT) { + if (input.type == inputTypes.STATEMENT || + lastInput.type == inputTypes.STATEMENT) { return true; } // Value and dummy inputs get new row if inputs are not inlined. - if (input.type == Blockly.inputTypes.VALUE || - input.type == Blockly.inputTypes.DUMMY) { + if (input.type == inputTypes.VALUE || input.type == inputTypes.DUMMY) { return !this.isInline; } return false; @@ -422,7 +411,7 @@ RenderInfo.prototype.addElemSpacing_ = function() { // No spacing needed before the corner on the top row or the bottom row. if (row.startsWithElemSpacer()) { // There's a spacer before the first element in the row. - row.elements.push(new Blockly.blockRendering.InRowSpacer( + row.elements.push(new InRowSpacer( this.constants_, this.getInRowSpacing_(null, oldElems[0]))); } if (!oldElems.length) { @@ -431,13 +420,12 @@ RenderInfo.prototype.addElemSpacing_ = function() { for (let e = 0; e < oldElems.length - 1; e++) { row.elements.push(oldElems[e]); const spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); - row.elements.push( - new Blockly.blockRendering.InRowSpacer(this.constants_, spacing)); + row.elements.push(new InRowSpacer(this.constants_, spacing)); } row.elements.push(oldElems[oldElems.length - 1]); if (row.endsWithElemSpacer()) { // There's a spacer after the last element in the row. - row.elements.push(new Blockly.blockRendering.InRowSpacer( + row.elements.push(new InRowSpacer( this.constants_, this.getInRowSpacing_(oldElems[oldElems.length - 1], null))); } @@ -448,42 +436,40 @@ RenderInfo.prototype.addElemSpacing_ = function() { * Calculate the width of a spacer element in a row based on the previous and * next elements in that row. For instance, extra padding is added between two * editable fields. - * @param {Blockly.blockRendering.Measurable} prev The element before the + * @param {Measurable} prev The element before the * spacer. - * @param {Blockly.blockRendering.Measurable} next The element after the spacer. + * @param {Measurable} next The element after the spacer. * @return {number} The size of the spacing between the two elements. * @protected */ RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Statement input padding. - if (next && Blockly.blockRendering.Types.isStatementInput(next)) { + if (next && Types.isStatementInput(next)) { return this.constants_.STATEMENT_INPUT_PADDING_LEFT; } } // Between inputs and the end of the row. - if (prev && Blockly.blockRendering.Types.isInput(prev) && !next) { - if (Blockly.blockRendering.Types.isExternalInput(prev)) { + if (prev && Types.isInput(prev) && !next) { + if (Types.isExternalInput(prev)) { return this.constants_.NO_PADDING; - } else if (Blockly.blockRendering.Types.isInlineInput(prev)) { + } else if (Types.isInlineInput(prev)) { return this.constants_.LARGE_PADDING; - } else if (Blockly.blockRendering.Types.isStatementInput(prev)) { + } else if (Types.isStatementInput(prev)) { return this.constants_.NO_PADDING; } } // Spacing between a square corner and a previous or next connection - if (prev && Blockly.blockRendering.Types.isLeftSquareCorner(prev) && next) { - if (Blockly.blockRendering.Types.isPreviousConnection(next) || - Blockly.blockRendering.Types.isNextConnection(next)) { + if (prev && Types.isLeftSquareCorner(prev) && next) { + if (Types.isPreviousConnection(next) || Types.isNextConnection(next)) { return next.notchOffset; } } // Spacing between a rounded corner and a previous or next connection. - if (prev && Blockly.blockRendering.Types.isLeftRoundedCorner(prev) && next) { - if (Blockly.blockRendering.Types.isPreviousConnection(next) || - Blockly.blockRendering.Types.isNextConnection(next)) { + if (prev && Types.isLeftRoundedCorner(prev) && next) { + if (Types.isPreviousConnection(next) || Types.isNextConnection(next)) { return next.notchOffset - this.constants_.CORNER_RADIUS; } } @@ -541,7 +527,7 @@ RenderInfo.prototype.alignRowElements_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( - /** @type {!Blockly.blockRendering.InputRow} */ (row)); + /** @type {!InputRow} */ (row)); } else { const currentWidth = row.width; const desiredWidth = this.getDesiredRowWidth_(row); @@ -549,7 +535,7 @@ RenderInfo.prototype.alignRowElements_ = function() { if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } - if (Blockly.blockRendering.Types.isTopOrBottomRow(row)) { + if (Types.isTopOrBottomRow(row)) { row.widthWithConnectedBlocks = row.width; } } @@ -558,7 +544,7 @@ RenderInfo.prototype.alignRowElements_ = function() { /** * Calculate the desired width of an input row. - * @param {!Blockly.blockRendering.Row} _row The input row. + * @param {!Row} _row The input row. * @return {number} The desired width of the input row. * @protected */ @@ -570,7 +556,7 @@ RenderInfo.prototype.getDesiredRowWidth_ = function(_row) { * Modify the given row to add the given amount of padding around its fields. * The exact location of the padding is based on the alignment property of the * last input in the field. - * @param {Blockly.blockRendering.Row} row The row to add padding to. + * @param {Row} row The row to add padding to. * @param {number} missingSpace How much padding to add. * @protected */ @@ -582,14 +568,14 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { } // Decide where the extra padding goes. - if (row.align == Blockly.constants.ALIGN.LEFT) { + if (row.align == blocklyConstants.ALIGN.LEFT) { // Add padding to the end of the row. lastSpacer.width += missingSpace; - } else if (row.align == Blockly.constants.ALIGN.CENTRE) { + } else if (row.align == blocklyConstants.ALIGN.CENTRE) { // Split the padding between the beginning and end of the row. firstSpacer.width += missingSpace / 2; lastSpacer.width += missingSpace / 2; - } else if (row.align == Blockly.constants.ALIGN.RIGHT) { + } else if (row.align == blocklyConstants.ALIGN.RIGHT) { // Add padding at the beginning of the row. firstSpacer.width += missingSpace; } else { @@ -602,7 +588,7 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { /** * Align the elements of a statement row based on computed bounds. * Unlike other types of rows, statement rows add space in multiple places. - * @param {!Blockly.blockRendering.InputRow} row The statement row to resize. + * @param {!InputRow} row The statement row to resize. * @protected */ RenderInfo.prototype.alignStatementRow_ = function(row) { @@ -643,16 +629,15 @@ RenderInfo.prototype.addRowSpacing_ = function() { /** * Create a spacer row to go between prev and next, and set its size. - * @param {!Blockly.blockRendering.Row} prev The previous row. - * @param {!Blockly.blockRendering.Row} next The next row. - * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. + * @param {!Row} prev The previous row. + * @param {!Row} next The next row. + * @return {!SpacerRow} The newly created spacer row. * @protected */ RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { const height = this.getSpacerRowHeight_(prev, next); const width = this.getSpacerRowWidth_(prev, next); - const spacer = - new Blockly.blockRendering.SpacerRow(this.constants_, height, width); + const spacer = new SpacerRow(this.constants_, height, width); if (prev.hasStatement) { spacer.followsStatement = true; } @@ -664,8 +649,8 @@ RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { /** * Calculate the width of a spacer row. - * @param {!Blockly.blockRendering.Row} _prev The row before the spacer. - * @param {!Blockly.blockRendering.Row} _next The row after the spacer. + * @param {!Row} _prev The row before the spacer. + * @param {!Row} _next The row after the spacer. * @return {number} The desired width of the spacer row between these two rows. * @protected */ @@ -675,8 +660,8 @@ RenderInfo.prototype.getSpacerRowWidth_ = function(_prev, _next) { /** * Calculate the height of a spacer row. - * @param {!Blockly.blockRendering.Row} _prev The row before the spacer. - * @param {!Blockly.blockRendering.Row} _next The row after the spacer. + * @param {!Row} _prev The row before the spacer. + * @param {!Row} _next The row after the spacer. * @return {number} The desired height of the spacer row between these two rows. * @protected */ @@ -689,25 +674,25 @@ RenderInfo.prototype.getSpacerRowHeight_ = function(_prev, _next) { * This base implementation puts the centerline at the middle of the row * vertically, with no special cases. You will likely need extra logic to * handle (at minimum) top and bottom rows. - * @param {!Blockly.blockRendering.Row} row The row containing the element. - * @param {!Blockly.blockRendering.Measurable} elem The element to place. + * @param {!Row} row The row containing the element. + * @param {!Measurable} elem The element to place. * @return {number} The desired centerline of the given element, as an offset * from the top left of the block. * @protected */ RenderInfo.prototype.getElemCenterline_ = function(row, elem) { - if (Blockly.blockRendering.Types.isSpacer(elem)) { + if (Types.isSpacer(elem)) { return row.yPos + elem.height / 2; } - if (Blockly.blockRendering.Types.isBottomRow(row)) { + if (Types.isBottomRow(row)) { const baseline = row.yPos + row.height - row.descenderHeight; - if (Blockly.blockRendering.Types.isNextConnection(elem)) { + if (Types.isNextConnection(elem)) { return baseline + elem.height / 2; } return baseline - elem.height / 2; } - if (Blockly.blockRendering.Types.isTopRow(row)) { - if (Blockly.blockRendering.Types.isHat(elem)) { + if (Types.isTopRow(row)) { + if (Types.isHat(elem)) { return row.capline - elem.height / 2; } return row.capline + elem.height / 2; @@ -718,14 +703,14 @@ RenderInfo.prototype.getElemCenterline_ = function(row, elem) { /** * Record final position information on elements on the given row, for use in * drawing. At minimum this records xPos and centerline on each element. - * @param {!Blockly.blockRendering.Row} row The row containing the elements. + * @param {!Row} row The row containing the elements. * @protected */ RenderInfo.prototype.recordElemPositions_ = function(row) { let xCursor = row.xPos; for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. - if (Blockly.blockRendering.Types.isSpacer(elem)) { + if (Types.isSpacer(elem)) { elem.height = row.height; } elem.xPos = xCursor; diff --git a/tests/deps.js b/tests/deps.js index 8baeee5ab..f2de1b0f9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); From f7a5d809bc3e37fd736aa29c7c35a47791c569d0 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 15:14:32 -0700 Subject: [PATCH 04/48] clang-format core/renderers/common/info.js --- core/renderers/common/info.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 3c5e70ee4..146ca5cdd 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -313,7 +313,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { // greater height it will be overwritten in the compute pass. if (followsStatement) { this.bottomRow.minHeight = - this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT; + this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT; } else { this.bottomRow.minHeight = this.constants_.BOTTOM_ROW_MIN_HEIGHT; } @@ -364,10 +364,11 @@ RenderInfo.prototype.addInput_ = function(input, activeRow) { } else if (input.type == inputTypes.DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. - activeRow.minHeight = Math.max(activeRow.minHeight, + activeRow.minHeight = Math.max( + activeRow.minHeight, input.getSourceBlock() && input.getSourceBlock().isShadow() ? - this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT : - this.constants_.DUMMY_INPUT_MIN_HEIGHT); + this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT : + this.constants_.DUMMY_INPUT_MIN_HEIGHT); activeRow.hasDummyInput = true; } if (activeRow.align == null) { @@ -478,8 +479,8 @@ RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { }; /** - * Figure out where the right edge of the block and right edge of statement inputs - * should be placed. + * Figure out where the right edge of the block and right edge of statement + * inputs should be placed. * @protected */ // TODO: More cleanup. @@ -607,8 +608,8 @@ RenderInfo.prototype.alignStatementRow_ = function(row) { statementInput.width += (desiredWidth - currentWidth); statementInput.height = Math.max(statementInput.height, row.height); row.width += (desiredWidth - currentWidth); - row.widthWithConnectedBlocks = Math.max(row.width, - this.statementEdge + row.connectedBlockWidths); + row.widthWithConnectedBlocks = + Math.max(row.width, this.statementEdge + row.connectedBlockWidths); }; /** @@ -742,9 +743,9 @@ RenderInfo.prototype.finalize_ = function() { if (this.outputConnection && this.block_.nextConnection && this.block_.nextConnection.isConnected()) { // Include width of connected block in value to stack width measurement. - widestRowWithConnectedBlocks = - Math.max(widestRowWithConnectedBlocks, - this.block_.nextConnection.targetBlock().getHeightWidth().width); + widestRowWithConnectedBlocks = Math.max( + widestRowWithConnectedBlocks, + this.block_.nextConnection.targetBlock().getHeightWidth().width); } this.widthWithChildren = widestRowWithConnectedBlocks + this.startX; From 8afef7f59861c0b0af34f99dee6e36aa0fd19607 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 19 Jul 2021 13:29:45 -0700 Subject: [PATCH 05/48] Destructure some requires --- core/renderers/common/info.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 146ca5cdd..1cc61af85 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -23,7 +23,6 @@ const Icon = goog.require('Blockly.blockRendering.Icon'); const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); const Input = goog.requireType('Blockly.Input'); const InputRow = goog.require('Blockly.blockRendering.InputRow'); -const inputTypes = goog.require('Blockly.inputTypes'); const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); const Measurable = goog.require('Blockly.blockRendering.Measurable'); @@ -39,8 +38,9 @@ const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); const TopRow = goog.require('Blockly.blockRendering.TopRow'); const Types = goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -const blocklyConstants = goog.require('Blockly.constants'); +const {ALIGN} = goog.require('Blockly.constants'); +const {VALUE, STATEMENT, DUMMY} = goog.require('Blockly.inputTypes'); + /** @@ -282,7 +282,7 @@ RenderInfo.prototype.populateTopRow_ = function() { } const precedesStatement = this.block_.inputList.length && - this.block_.inputList[0].type == inputTypes.STATEMENT; + this.block_.inputList[0].type == STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -306,8 +306,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; const followsStatement = this.block_.inputList.length && - this.block_.inputList[this.block_.inputList.length - 1].type == - inputTypes.STATEMENT; + this.block_.inputList[this.block_.inputList.length - 1].type == STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -352,16 +351,16 @@ RenderInfo.prototype.populateBottomRow_ = function() { */ RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. - if (this.isInline && input.type == inputTypes.VALUE) { + if (this.isInline && input.type == VALUE) { activeRow.elements.push(new InlineInput(this.constants_, input)); activeRow.hasInlineInput = true; - } else if (input.type == inputTypes.STATEMENT) { + } else if (input.type == STATEMENT) { activeRow.elements.push(new StatementInput(this.constants_, input)); activeRow.hasStatement = true; - } else if (input.type == inputTypes.VALUE) { + } else if (input.type == VALUE) { activeRow.elements.push(new ExternalValueInput(this.constants_, input)); activeRow.hasExternalInput = true; - } else if (input.type == inputTypes.DUMMY) { + } else if (input.type == DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. activeRow.minHeight = Math.max( @@ -390,12 +389,11 @@ RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { return false; } // A statement input or an input following one always gets a new row. - if (input.type == inputTypes.STATEMENT || - lastInput.type == inputTypes.STATEMENT) { + if (input.type == STATEMENT || lastInput.type == STATEMENT) { return true; } // Value and dummy inputs get new row if inputs are not inlined. - if (input.type == inputTypes.VALUE || input.type == inputTypes.DUMMY) { + if (input.type == VALUE || input.type == DUMMY) { return !this.isInline; } return false; @@ -569,14 +567,14 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { } // Decide where the extra padding goes. - if (row.align == blocklyConstants.ALIGN.LEFT) { + if (row.align == ALIGN.LEFT) { // Add padding to the end of the row. lastSpacer.width += missingSpace; - } else if (row.align == blocklyConstants.ALIGN.CENTRE) { + } else if (row.align == ALIGN.CENTRE) { // Split the padding between the beginning and end of the row. firstSpacer.width += missingSpace / 2; lastSpacer.width += missingSpace / 2; - } else if (row.align == blocklyConstants.ALIGN.RIGHT) { + } else if (row.align == ALIGN.RIGHT) { // Add padding at the beginning of the row. firstSpacer.width += missingSpace; } else { From ff591b0e732395085f89fc5e1d0d7c100a455317 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 19 Jul 2021 21:26:53 -0700 Subject: [PATCH 06/48] Alphabetize --- core/renderers/common/info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 1cc61af85..73e02dfff 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -39,7 +39,7 @@ const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); const TopRow = goog.require('Blockly.blockRendering.TopRow'); const Types = goog.require('Blockly.blockRendering.Types'); const {ALIGN} = goog.require('Blockly.constants'); -const {VALUE, STATEMENT, DUMMY} = goog.require('Blockly.inputTypes'); +const {DUMMY, STATEMENT, VALUE} = goog.require('Blockly.inputTypes'); From 0e6258ca1a78f384944977c29e5c3e3bcf0ba748 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:17:13 -0700 Subject: [PATCH 07/48] Migrated to inline exports --- core/block_animations.js | 31 +++++----- core/block_drag_surface.js | 2 +- core/bubble_dragger.js | 11 +++- core/comment.js | 6 ++ core/component_manager.js | 5 ++ core/connection.js | 8 ++- core/connection_checker.js | 2 + core/connection_db.js | 3 + core/css.js | 9 +-- core/extensions.js | 20 +++--- core/interfaces/i_ast_node_location_svg.js | 1 + .../i_ast_node_location_with_block.js | 2 + core/interfaces/i_autohideable.js | 1 + core/interfaces/i_block_dragger.js | 2 + core/interfaces/i_bounded_element.js | 1 + core/interfaces/i_bubble.js | 4 ++ core/interfaces/i_connection_checker.js | 2 + core/interfaces/i_copyable.js | 2 + core/interfaces/i_delete_area.js | 2 + core/interfaces/i_drag_target.js | 3 + core/interfaces/i_draggable.js | 1 + core/interfaces/i_flyout.js | 6 ++ core/interfaces/i_keyboard_accessible.js | 1 + core/interfaces/i_positionable.js | 3 + core/interfaces/i_toolbox.js | 5 ++ core/renderers/common/drawer.js | 9 ++- core/utils/colour.js | 15 ++--- core/utils/deprecation.js | 5 +- core/utils/idgenerator.js | 4 +- core/utils/math.js | 9 +-- core/utils/object.js | 11 ++-- core/utils/style.js | 48 +++++++-------- core/utils/svg_paths.js | 27 +++----- core/utils/toolbox.js | 61 ++++++++----------- 34 files changed, 178 insertions(+), 144 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 86b4b44b5..27926002e 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -13,9 +13,10 @@ goog.module('Blockly.blockAnimations'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); -const dom = goog.require('Blockly.utils.dom'); const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); /** @@ -34,7 +35,7 @@ let disconnectGroup = null; * Play some UI effects (sound, animation) when disposing of a block. * @param {!BlockSvg} block The block being disposed of. */ -function disposeUiEffect(block) { +const disposeUiEffect = function(block) { const workspace = block.workspace; const svgGroup = block.getSvgRoot(); workspace.getAudioManager().play('delete'); @@ -49,7 +50,7 @@ function disposeUiEffect(block) { clone.bBox_ = clone.getBBox(); // Start the animation. disposeUiStep(clone, workspace.RTL, new Date, workspace.scale); -} +}; /** @package */ exports.disposeUiEffect = disposeUiEffect; @@ -62,7 +63,7 @@ exports.disposeUiEffect = disposeUiEffect; * @param {!Date} start Date of animation's start. * @param {number} workspaceScale Scale of workspace. */ -function disposeUiStep(clone, rtl, start, workspaceScale) { +const disposeUiStep = function(clone, rtl, start, workspaceScale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -78,13 +79,13 @@ function disposeUiStep(clone, rtl, start, workspaceScale) { ' scale(' + scale + ')'); setTimeout(disposeUiStep, 10, clone, rtl, start, workspaceScale); } -} +}; /** * Play some UI effects (sound, ripple) after a connection has been established. * @param {!BlockSvg} block The block being connected. */ -function connectionUiEffect(block) { +const connectionUiEffect = function(block) { const workspace = block.workspace; const scale = workspace.scale; workspace.getAudioManager().play('click'); @@ -113,7 +114,7 @@ function connectionUiEffect(block) { workspace.getParentSvg()); // Start the animation. connectionUiStep(ripple, new Date, scale); -} +}; /** @package */ exports.connectionUiEffect = connectionUiEffect; @@ -123,7 +124,7 @@ exports.connectionUiEffect = connectionUiEffect; * @param {!Date} start Date of animation's start. * @param {number} scale Scale of workspace. */ -function connectionUiStep(ripple, start, scale) { +const connectionUiStep = function(ripple, start, scale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -133,13 +134,13 @@ function connectionUiStep(ripple, start, scale) { ripple.style.opacity = 1 - percent; disconnectPid = setTimeout(connectionUiStep, 10, ripple, start, scale); } -} +}; /** * Play some UI effects (sound, animation) when disconnecting a block. * @param {!BlockSvg} block The block being disconnected. */ -function disconnectUiEffect(block) { +const disconnectUiEffect = function(block) { block.workspace.getAudioManager().play('disconnect'); if (block.workspace.scale < 1) { return; // Too small to care about visual effects. @@ -154,7 +155,7 @@ function disconnectUiEffect(block) { } // Start the animation. disconnectUiStep(block.getSvgRoot(), magnitude, new Date); -} +}; /** @package */ exports.disconnectUiEffect = disconnectUiEffect; @@ -164,7 +165,7 @@ exports.disconnectUiEffect = disconnectUiEffect; * @param {number} magnitude Maximum degrees skew (reversed for RTL). * @param {!Date} start Date of animation's start. */ -function disconnectUiStep(group, magnitude, start) { +const disconnectUiStep = function(group, magnitude, start) { const DURATION = 200; // Milliseconds. const WIGGLES = 3; // Half oscillations. @@ -181,12 +182,12 @@ function disconnectUiStep(group, magnitude, start) { disconnectPid = setTimeout(disconnectUiStep, 10, group, magnitude, start); } group.setAttribute('transform', group.translate_ + group.skew_); -} +}; /** * Stop the disconnect UI animation immediately. */ -function disconnectUiStop() { +const disconnectUiStop = function() { if (disconnectGroup) { clearTimeout(disconnectPid); const group = disconnectGroup; @@ -194,6 +195,6 @@ function disconnectUiStop() { group.setAttribute('transform', group.translate_); disconnectGroup = null; } -} +}; /** @package */ exports.disconnectUiStop = disconnectUiStop; diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 69b7a5ca5..2b911ef09 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -20,8 +20,8 @@ goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); const {G, SVG} = goog.require('Blockly.utils.Svg'); -const {getRelativeXY} = goog.require('Blockly.utils'); const {createSvgElement, HTML_NS, setCssTransform, SVG_NS, XLINK_NS} = goog.require('Blockly.utils.dom'); +const {getRelativeXY} = goog.require('Blockly.utils'); /** diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 3a6d36331..d06c2fdc0 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -13,21 +13,26 @@ goog.module('Blockly.BubbleDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); const ComponentManager = goog.require('Blockly.ComponentManager'); const Coordinate = goog.require('Blockly.utils.Coordinate'); const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ const IBubble = goog.requireType('Blockly.IBubble'); +/* eslint-disable-next-line no-unused-vars */ const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); -const utils = goog.require('Blockly.utils'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Bubble'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -/** @suppress {extraRequire} */ goog.require('Blockly.Events.CommentMove'); +/** @suppress {extraRequire} */ +goog.require('Blockly.constants'); /** diff --git a/core/comment.js b/core/comment.js index 7f4085faf..99d81e89c 100644 --- a/core/comment.js +++ b/core/comment.js @@ -13,16 +13,22 @@ goog.module('Blockly.Comment'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const Bubble = goog.require('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); const Events = goog.require('Blockly.Events'); const Icon = goog.require('Blockly.Icon'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const userAgent = goog.require('Blockly.utils.userAgent'); +/* eslint-disable-next-line no-unused-vars */ const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); const {inherits} = goog.require('Blockly.utils.object'); diff --git a/core/component_manager.js b/core/component_manager.js index 31b661e8a..ad2370bd6 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -14,10 +14,15 @@ goog.module('Blockly.ComponentManager'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IAutoHideable = goog.requireType('Blockly.IAutoHideable'); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.requireType('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); +/* eslint-disable-next-line no-unused-vars */ const IPositionable = goog.requireType('Blockly.IPositionable'); diff --git a/core/connection.js b/core/connection.js index 553938825..f272b59e0 100644 --- a/core/connection.js +++ b/core/connection.js @@ -13,14 +13,18 @@ goog.module('Blockly.Connection'); goog.module.declareLegacyNamespace(); -const connectionTypes = goog.require('Blockly.connectionTypes'); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); -const deprecation = goog.require('Blockly.utils.deprecation'); const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const Input = goog.requireType('Blockly.Input'); const Xml = goog.require('Blockly.Xml'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const deprecation = goog.require('Blockly.utils.deprecation'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); /** @suppress {extraRequire} */ diff --git a/core/connection_checker.js b/core/connection_checker.js index 4bd7bd4e2..12c6418db 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -15,7 +15,9 @@ goog.module('Blockly.ConnectionChecker'); goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); diff --git a/core/connection_db.js b/core/connection_db.js index 49bccb504..d3bc0507d 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -15,8 +15,11 @@ goog.module('Blockly.ConnectionDB'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.require('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ diff --git a/core/css.js b/core/css.js index 52228b4fb..6f34e6c0d 100644 --- a/core/css.js +++ b/core/css.js @@ -39,6 +39,7 @@ const register = function(cssArray) { Array.prototype.push.apply(CONTENT, cssArray); cssArray.length = 0; // Garbage collect provided CSS content. }; +exports.register = register; /** * Inject the CSS into the DOM. This is preferable over using a regular CSS @@ -72,6 +73,7 @@ const inject = function(hasCss, pathToMedia) { cssNode.appendChild(cssTextNode); document.head.insertBefore(cssNode, document.head.firstChild); }; +exports.inject = inject; /** * Array making up the CSS content for Blockly. @@ -553,9 +555,4 @@ const CONTENT = [ margin-right: -24px; }`, ]; - -exports = { - register, - inject, - CONTENT -}; +exports.CONTENT = CONTENT; diff --git a/core/extensions.js b/core/extensions.js index c73737c43..3f20777aa 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -20,6 +20,7 @@ goog.module('Blockly.Extensions'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goog.require('Blockly.utils'); @@ -29,6 +30,7 @@ const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goo * @private */ const allExtensions = Object.create(null); +exports.ALL_ = allExtensions; /** * Registers a new extension function. Extensions are functions that help @@ -52,6 +54,7 @@ const register = function(name, initFn) { } allExtensions[name] = initFn; }; +exports.register = register; /** * Registers a new extension function that adds all key/value of mixinObj. @@ -68,6 +71,7 @@ const registerMixin = function(name, mixinObj) { this.mixin(mixinObj); }); }; +exports.registerMixin = registerMixin; /** * Registers a new extension function that adds a mutator to the block. @@ -111,6 +115,7 @@ const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { } }); }; +exports.registerMutator = registerMutator; /** * Unregisters the extension registered with the given name. @@ -124,6 +129,7 @@ const unregister = function(name) { 'No extension mapping for name "' + name + '" found to unregister'); } }; +exports.unregister = unregister; /** * Applies an extension method to a block. This should only be called during @@ -161,6 +167,7 @@ const apply = function(name, block, isMutator) { } } }; +exports.apply = apply; /** * Check that the given value is a function. @@ -366,6 +373,7 @@ const buildTooltipForDropdown = function(dropdownName, lookupTable) { }; return extensionFn; }; +exports.buildTooltipForDropdown = buildTooltipForDropdown; /** * Checks all options keys are present in the provided string lookup table. @@ -425,6 +433,7 @@ const buildTooltipWithFieldText = function(msgTemplate, fieldName) { }; return extensionFn; }; +exports.buildTooltipWithFieldText = buildTooltipWithFieldText; /** * Configures the tooltip to mimic the parent block when connected. Otherwise, @@ -443,14 +452,3 @@ const extensionParentTooltip = function() { }.bind(this)); }; register('parent_tooltip_when_inline', extensionParentTooltip); - -exports = { - ALL_: allExtensions, - register, - registerMixin, - registerMutator, - unregister, - apply, - buildTooltipForDropdown, - buildTooltipWithFieldText -}; diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js index 5b58d4abc..526fbffa3 100644 --- a/core/interfaces/i_ast_node_location_svg.js +++ b/core/interfaces/i_ast_node_location_svg.js @@ -14,6 +14,7 @@ goog.module('Blockly.IASTNodeLocationSvg'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js index 58da7a902..002db0ad8 100644 --- a/core/interfaces/i_ast_node_location_with_block.js +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -15,7 +15,9 @@ goog.module('Blockly.IASTNodeLocationWithBlock'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); diff --git a/core/interfaces/i_autohideable.js b/core/interfaces/i_autohideable.js index bf11adc01..0ccbf310a 100644 --- a/core/interfaces/i_autohideable.js +++ b/core/interfaces/i_autohideable.js @@ -15,6 +15,7 @@ goog.module('Blockly.IAutoHideable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); diff --git a/core/interfaces/i_block_dragger.js b/core/interfaces/i_block_dragger.js index ebfc820ba..b87cd9865 100644 --- a/core/interfaces/i_block_dragger.js +++ b/core/interfaces/i_block_dragger.js @@ -14,7 +14,9 @@ goog.module('Blockly.IBlockDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); diff --git a/core/interfaces/i_bounded_element.js b/core/interfaces/i_bounded_element.js index 461d52ca1..f2c84633e 100644 --- a/core/interfaces/i_bounded_element.js +++ b/core/interfaces/i_bounded_element.js @@ -14,6 +14,7 @@ goog.module('Blockly.IBoundedElement'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index e41a1bf25..b6e9736d7 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -14,9 +14,13 @@ goog.module('Blockly.IBubble'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IContextMenu = goog.require('Blockly.IContextMenu'); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.require('Blockly.IDraggable'); diff --git a/core/interfaces/i_connection_checker.js b/core/interfaces/i_connection_checker.js index 03693604c..d0eb21e24 100644 --- a/core/interfaces/i_connection_checker.js +++ b/core/interfaces/i_connection_checker.js @@ -14,7 +14,9 @@ goog.module('Blockly.IConnectionChecker'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Connection = goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); diff --git a/core/interfaces/i_copyable.js b/core/interfaces/i_copyable.js index 07556eb23..87b776600 100644 --- a/core/interfaces/i_copyable.js +++ b/core/interfaces/i_copyable.js @@ -14,7 +14,9 @@ goog.module('Blockly.ICopyable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const ISelectable = goog.requireType('Blockly.ISelectable'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); diff --git a/core/interfaces/i_delete_area.js b/core/interfaces/i_delete_area.js index 5c5cbd380..845d7dddb 100644 --- a/core/interfaces/i_delete_area.js +++ b/core/interfaces/i_delete_area.js @@ -15,7 +15,9 @@ goog.module('Blockly.IDeleteArea'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.require('Blockly.IDragTarget'); diff --git a/core/interfaces/i_drag_target.js b/core/interfaces/i_drag_target.js index 803bcbc74..6b777781d 100644 --- a/core/interfaces/i_drag_target.js +++ b/core/interfaces/i_drag_target.js @@ -15,8 +15,11 @@ goog.module('Blockly.IDragTarget'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); diff --git a/core/interfaces/i_draggable.js b/core/interfaces/i_draggable.js index 81303a24b..5d7e17d53 100644 --- a/core/interfaces/i_draggable.js +++ b/core/interfaces/i_draggable.js @@ -14,6 +14,7 @@ goog.module('Blockly.IDraggable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IDeletable = goog.require('Blockly.IDeletable'); diff --git a/core/interfaces/i_flyout.js b/core/interfaces/i_flyout.js index b9b1c8e15..23c76dd0b 100644 --- a/core/interfaces/i_flyout.js +++ b/core/interfaces/i_flyout.js @@ -14,11 +14,17 @@ goog.module('Blockly.IFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ const Svg = goog.requireType('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const {FlyoutDefinition} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 8f21153da..8243e67d1 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -14,6 +14,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); diff --git a/core/interfaces/i_positionable.js b/core/interfaces/i_positionable.js index ed324196b..1fe773add 100644 --- a/core/interfaces/i_positionable.js +++ b/core/interfaces/i_positionable.js @@ -14,8 +14,11 @@ goog.module('Blockly.IPositionable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ const {UiMetrics} = goog.requireType('Blockly.MetricsManager'); diff --git a/core/interfaces/i_toolbox.js b/core/interfaces/i_toolbox.js index 5ecd0a69f..0c7e7deb3 100644 --- a/core/interfaces/i_toolbox.js +++ b/core/interfaces/i_toolbox.js @@ -14,10 +14,15 @@ goog.module('Blockly.IToolbox'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IFlyout = goog.requireType('Blockly.IFlyout'); +/* eslint-disable-next-line no-unused-vars */ const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const {ToolboxInfo} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 9504695a2..2dde92d3f 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,15 +13,22 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.blockRendering.Field'); +/* eslint-disable-next-line no-unused-vars */ const Icon = goog.requireType('Blockly.blockRendering.Icon'); +/* eslint-disable-next-line no-unused-vars */ const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); +/* eslint-disable-next-line no-unused-vars */ const RenderInfo = goog.requireType('Blockly.blockRendering.RenderInfo'); +/* eslint-disable-next-line no-unused-vars */ const Row = goog.require('Blockly.blockRendering.Row'); -const svgPaths = goog.require('Blockly.utils.svgPaths'); const Types = goog.require('Blockly.blockRendering.Types'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); /** diff --git a/core/utils/colour.js b/core/utils/colour.js index 7b2c978f4..29ba0187c 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -60,6 +60,7 @@ const parse = function(str) { } return null; }; +exports.parse = parse; /** * Converts a colour from RGB to hex representation. @@ -75,6 +76,7 @@ const rgbToHex = function(r, g, b) { } return '#' + rgb.toString(16); }; +exports.rgbToHex = rgbToHex; /** * Converts a colour to RGB. @@ -95,6 +97,7 @@ const hexToRgb = function(colour) { return [r, g, b]; }; +exports.hexToRgb = hexToRgb; /** * Converts an HSV triplet to hex representation. @@ -153,6 +156,7 @@ const hsvToHex = function(h, s, v) { } return rgbToHex(Math.floor(red), Math.floor(green), Math.floor(blue)); }; +exports.hsvToHex = hsvToHex; /** * Blend two colours together, using the specified factor to indicate the @@ -179,6 +183,7 @@ const blend = function(colour1, colour2, factor) { const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); return rgbToHex(r, g, b); }; +exports.blend = blend; /** * A map that contains the 16 basic colour keywords as defined by W3C: @@ -206,12 +211,4 @@ const names = { 'white': '#ffffff', 'yellow': '#ffff00' }; - -exports = { - parse, - rgbToHex, - hexToRgb, - hsvToHex, - blend, - names -}; +exports.names = names; diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index ad798b1ab..870294172 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -28,7 +28,6 @@ goog.module.declareLegacyNamespace(); * deprecation date. * @param {string=} opt_use The name of a function or property to use instead, * if any. - * @package */ const warn = function(name, deprecationDate, deletionDate, opt_use) { let msg = name + ' was deprecated on ' + deprecationDate + @@ -38,5 +37,5 @@ const warn = function(name, deprecationDate, deletionDate, opt_use) { } console.warn(msg); }; - -exports = {warn}; +/** @package */ +exports.warn = warn; diff --git a/core/utils/idgenerator.js b/core/utils/idgenerator.js index 6ad7bcf55..537dfde2b 100644 --- a/core/utils/idgenerator.js +++ b/core/utils/idgenerator.js @@ -23,7 +23,6 @@ goog.module.declareLegacyNamespace(); /** * Next unique ID to use. * @type {number} - * @private */ let nextId = 0; @@ -36,5 +35,4 @@ let nextId = 0; const getNextUniqueId = function() { return 'blockly-' + (nextId++).toString(36); }; - -exports = {getNextUniqueId}; +exports.getNextUniqueId = getNextUniqueId; diff --git a/core/utils/math.js b/core/utils/math.js index dade91c21..9b717d065 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -29,6 +29,7 @@ goog.module.declareLegacyNamespace(); const toRadians = function(angleDegrees) { return angleDegrees * Math.PI / 180; }; +exports.toRadians = toRadians; /** * Converts radians to degrees. @@ -39,6 +40,7 @@ const toRadians = function(angleDegrees) { const toDegrees = function(angleRadians) { return angleRadians * 180 / Math.PI; }; +exports.toDegrees = toDegrees; /** * Clamp the provided number between the lower bound and the upper bound. @@ -55,9 +57,4 @@ const clamp = function(lowerBound, number, upperBound) { } return Math.max(lowerBound, Math.min(number, upperBound)); }; - -exports = { - toRadians, - toDegrees, - clamp -}; +exports.clamp = clamp; diff --git a/core/utils/object.js b/core/utils/object.js index dae55ec51..3507d33ab 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -40,6 +40,7 @@ const inherits = function(childCtor, parentCtor) { // Alternatively, one could use this instead: // Object.setPrototypeOf(childCtor.prototype, parentCtor.prototype); }; +exports.inherits = inherits; /** * Copies all the members of a source object to a target object. @@ -51,6 +52,7 @@ const mixin = function(target, source) { target[x] = source[x]; } }; +exports.mixin = mixin; /** * Complete a deep merge of all members of a source object with a target object. @@ -68,6 +70,7 @@ const deepMerge = function(target, source) { } return target; }; +exports.deepMerge = deepMerge; /** * Returns an array of a given object's own enumerable property values. @@ -83,10 +86,4 @@ const values = function(obj) { return obj[e]; }); }; - -exports = { - inherits, - mixin, - deepMerge, - values, -}; +exports.values = values; diff --git a/core/utils/style.js b/core/utils/style.js index 1fcfbdd62..0fbd22093 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -29,7 +29,7 @@ const Size = goog.require('Blockly.utils.Size'); * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. */ -function getSize(element) { +const getSize = function(element) { if (getStyle(element, 'display') != 'none') { return getSizeWithDisplay(element); } @@ -52,7 +52,7 @@ function getSize(element) { style.visibility = originalVisibility; return new Size(offsetWidth, offsetHeight); -} +}; exports.getSize = getSize; /** @@ -60,11 +60,11 @@ exports.getSize = getSize; * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. */ -function getSizeWithDisplay(element) { +const getSizeWithDisplay = function(element) { const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; return new Size(offsetWidth, offsetHeight); -} +}; /** * Cross-browser pseudo get computed style. It returns the computed style where @@ -79,10 +79,10 @@ function getSizeWithDisplay(element) { * @param {string} style Property to get (must be camelCase, not CSS-style). * @return {string} Style value. */ -function getStyle(element, style) { +const getStyle = function(element, style) { return getComputedStyle(element, style) || getCascadedStyle(element, style) || (element.style && element.style[style]); -} +}; /** * Retrieves a computed style value of a node. It returns empty string if the @@ -96,7 +96,7 @@ function getStyle(element, style) { * @param {string} property Property to get (camel-case). * @return {string} Style value. */ -function getComputedStyle(element, property) { +const getComputedStyle = function(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { const styles = document.defaultView.getComputedStyle(element, null); if (styles) { @@ -107,7 +107,7 @@ function getComputedStyle(element, property) { } return ''; -} +}; exports.getComputedStyle = getComputedStyle; /** @@ -120,10 +120,10 @@ exports.getComputedStyle = getComputedStyle; * @param {string} style Property to get (camel-case). * @return {string} Style value. */ -function getCascadedStyle(element, style) { +const getCascadedStyle = function(element, style) { return /** @type {string} */ ( element.currentStyle ? element.currentStyle[style] : null); -} +}; exports.getCascadedStyle = getCascadedStyle; /** @@ -132,7 +132,7 @@ exports.getCascadedStyle = getCascadedStyle; * @param {!Element} el Element to get the page offset for. * @return {!Coordinate} The page offset. */ -function getPageOffset(el) { +const getPageOffset = function(el) { const pos = new Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; @@ -146,7 +146,7 @@ function getPageOffset(el) { pos.y = box.top + scrollCoord.y; return pos; -} +}; exports.getPageOffset = getPageOffset; /** @@ -154,13 +154,13 @@ exports.getPageOffset = getPageOffset; * Similar to Closure's goog.style.getViewportPageOffset * @return {!Coordinate} The page offset of the viewport. */ -function getViewportPageOffset() { +const getViewportPageOffset = function() { const body = document.body; const documentElement = document.documentElement; const scrollLeft = body.scrollLeft || documentElement.scrollLeft; const scrollTop = body.scrollTop || documentElement.scrollTop; return new Coordinate(scrollLeft, scrollTop); -} +}; exports.getViewportPageOffset = getViewportPageOffset; /** @@ -175,9 +175,9 @@ exports.getViewportPageOffset = getViewportPageOffset; * @param {*} isShown True to render the element in its default style, * false to disable rendering the element. */ -function setElementShown(el, isShown) { +const setElementShown = function(el, isShown) { el.style.display = isShown ? '' : 'none'; -} +}; exports.setElementShown = setElementShown; /** @@ -187,9 +187,9 @@ exports.setElementShown = setElementShown; * @param {!Element} el The element to test. * @return {boolean} True for right to left, false for left to right. */ -function isRightToLeft(el) { +const isRightToLeft = function(el) { return 'rtl' == getStyle(el, 'direction'); -} +}; exports.isRightToLeft = isRightToLeft; /** @@ -198,7 +198,7 @@ exports.isRightToLeft = isRightToLeft; * @param {!Element} element The element to get the border widths for. * @return {!Object} The computed border widths. */ -function getBorderBox(element) { +const getBorderBox = function(element) { const left = getComputedStyle(element, 'borderLeftWidth'); const right = getComputedStyle(element, 'borderRightWidth'); const top = getComputedStyle(element, 'borderTopWidth'); @@ -210,7 +210,7 @@ function getBorderBox(element) { bottom: parseFloat(bottom), left: parseFloat(left) }; -} +}; exports.getBorderBox = getBorderBox; /** @@ -226,11 +226,11 @@ exports.getBorderBox = getBorderBox; * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -function scrollIntoContainerView(element, container, opt_center) { +const scrollIntoContainerView = function(element, container, opt_center) { const offset = getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; -} +}; exports.scrollIntoContainerView = scrollIntoContainerView; /** @@ -248,7 +248,7 @@ exports.scrollIntoContainerView = scrollIntoContainerView; * @return {!Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ -function getContainerOffsetToScrollInto(element, container, opt_center) { +const getContainerOffsetToScrollInto = function(element, container, opt_center) { // Absolute position of the element's border's top left corner. const elementPos = getPageOffset(element); // Absolute position of the container's border's top left corner. @@ -281,5 +281,5 @@ function getContainerOffsetToScrollInto(element, container, opt_center) { scrollTop += Math.min(relY, Math.max(relY - spaceY, 0)); } return new Coordinate(scrollLeft, scrollTop); -} +}; exports.getContainerOffsetToScrollInto = getContainerOffsetToScrollInto; diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index 02602e4ac..7286e8bc6 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -27,11 +27,11 @@ goog.module.declareLegacyNamespace(); * @param {number} x The x coordinate. * @param {number} y The y coordinate. * @return {string} A string of the format ' x,y ' - * @public */ const point = function(x, y) { return ' ' + x + ',' + y + ' '; }; +exports.point = point; /** * Draw a cubic or quadratic curve. See @@ -44,11 +44,11 @@ const point = function(x, y) { * the format ' x, y '. * @return {string} A string defining one or more Bezier curves. See the MDN * documentation for exact format. - * @public */ const curve = function(command, points) { return ' ' + command + points.join(''); }; +exports.curve = curve; /** * Move the cursor to the given position without drawing a line. @@ -58,11 +58,11 @@ const curve = function(command, points) { * @param {number} x The absolute x coordinate. * @param {number} y The absolute y coordinate. * @return {string} A string of the format ' M x,y ' - * @public */ const moveTo = function(x, y) { return ' M ' + x + ',' + y + ' '; }; +exports.moveTo = moveTo; /** * Move the cursor to the given position without drawing a line. @@ -72,11 +72,11 @@ const moveTo = function(x, y) { * @param {number} dx The relative x coordinate. * @param {number} dy The relative y coordinate. * @return {string} A string of the format ' m dx,dy ' - * @public */ const moveBy = function(dx, dy) { return ' m ' + dx + ',' + dy + ' '; }; +exports.moveBy = moveBy; /** * Draw a line from the current point to the end point, which is the current @@ -86,11 +86,11 @@ const moveBy = function(dx, dy) { * @param {number} dx The relative x coordinate. * @param {number} dy The relative y coordinate. * @return {string} A string of the format ' l dx,dy ' - * @public */ const lineTo = function(dx, dy) { return ' l ' + dx + ',' + dy + ' '; }; +exports.lineTo = lineTo; /** * Draw multiple lines connecting all of the given points in order. This is @@ -101,11 +101,11 @@ const lineTo = function(dx, dy) { * draw lines to, in order. The points are represented as strings of the * format ' dx,dy '. * @return {string} A string of the format ' l (dx,dy)+ ' - * @public */ const line = function(points) { return ' l' + points.join(''); }; +exports.line = line; /** * Draw a horizontal or vertical line. @@ -118,11 +118,11 @@ const line = function(points) { * @param {number} val The coordinate to pass to the command. It may be * absolute or relative. * @return {string} A string of the format ' command val ' - * @public */ const lineOnAxis = function(command, val) { return ' ' + command + ' ' + val + ' '; }; +exports.lineOnAxis = lineOnAxis; /** * Draw an elliptical arc curve. @@ -136,19 +136,8 @@ const lineOnAxis = function(command, val) { * specified either in absolute or relative coordinates depending on the * command. * @return {string} A string of the format 'command radius radius flags point' - * @public */ const arc = function(command, flags, radius, point) { return command + ' ' + radius + ' ' + radius + ' ' + flags + point; }; - -exports = { - point, - curve, - moveTo, - moveBy, - lineTo, - line, - lineOnAxis, - arc, -}; +exports.arc = arc; diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index aab51d826..6dabc1fd5 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -18,11 +18,11 @@ goog.module('Blockly.utils.toolbox'); goog.module.declareLegacyNamespace(); const userAgent = goog.require('Blockly.utils.userAgent'); -const {textToDom} = goog.require('Blockly.Xml'); - +/* eslint-disable-next-line no-unused-vars */ const {CssConfig: CategoryCssConfig} = goog.requireType('Blockly.ToolboxCategory'); +/* eslint-disable-next-line no-unused-vars */ const {CssConfig: SeparatorCssConfig} = goog.requireType('Blockly.ToolboxSeparator'); - +const {textToDom} = goog.require('Blockly.Xml'); /** * The information needed to create a block in the toolbox. @@ -35,6 +35,7 @@ const {CssConfig: SeparatorCssConfig} = goog.requireType('Blockly.ToolboxSeparat * }} */ let BlockInfo; +exports.BlockInfo = BlockInfo; /** * The information needed to create a separator in the toolbox. @@ -46,6 +47,7 @@ let BlockInfo; * }} */ let SeparatorInfo; +exports.SeparatorInfo = SeparatorInfo; /** * The information needed to create a button in the toolbox. @@ -56,6 +58,7 @@ let SeparatorInfo; * }} */ let ButtonInfo; +exports.ButtonInfo = ButtonInfo; /** * The information needed to create a label in the toolbox. @@ -66,6 +69,7 @@ let ButtonInfo; * }} */ let LabelInfo; +exports.LabelInfo = LabelInfo; /** * The information needed to create either a button or a label in the flyout. @@ -73,6 +77,7 @@ let LabelInfo; * LabelInfo} */ let ButtonOrLabelInfo; +exports.ButtonOrLabelInfo = ButtonOrLabelInfo; /** * The information needed to create a category in the toolbox. @@ -88,6 +93,7 @@ let ButtonOrLabelInfo; * }} */ let StaticCategoryInfo; +exports.StaticCategoryInfo = StaticCategoryInfo; /** * The information needed to create a custom category. @@ -102,6 +108,7 @@ let StaticCategoryInfo; * }} */ let DynamicCategoryInfo; +exports.DynamicCategoryInfo = DynamicCategoryInfo; /** * The information needed to create either a dynamic or static category. @@ -109,6 +116,7 @@ let DynamicCategoryInfo; * DynamicCategoryInfo} */ let CategoryInfo; +exports.CategoryInfo = CategoryInfo; /** * Any information that can be used to create an item in the toolbox. @@ -116,6 +124,7 @@ let CategoryInfo; * StaticCategoryInfo} */ let ToolboxItemInfo; +exports.ToolboxItemInfo = ToolboxItemInfo; /** * All the different types that can be displayed in a flyout. @@ -126,6 +135,7 @@ let ToolboxItemInfo; * DynamicCategoryInfo} */ let FlyoutItemInfo; +exports.FlyoutItemInfo = FlyoutItemInfo; /** * The JSON definition of a toolbox. @@ -135,6 +145,7 @@ let FlyoutItemInfo; * }} */ let ToolboxInfo; +exports.ToolboxInfo = ToolboxInfo; /** * An array holding flyout items. @@ -143,6 +154,7 @@ let ToolboxInfo; * } */ let FlyoutItemInfoArray; +exports.FlyoutItemInfoArray = FlyoutItemInfoArray; /** * All of the different types that can create a toolbox. @@ -151,6 +163,7 @@ let FlyoutItemInfoArray; * string} */ let ToolboxDefinition; +exports.ToolboxDefinition = ToolboxDefinition; /** * All of the different types that can be used to show items in a flyout. @@ -160,6 +173,7 @@ let ToolboxDefinition; * Array} */ let FlyoutDefinition; +exports.FlyoutDefinition = FlyoutDefinition; /** * The name used to identify a toolbox that has category like items. @@ -187,6 +201,7 @@ const Position = { LEFT: 2, RIGHT: 3 }; +exports.Position = Position; /** * Converts the toolbox definition into toolbox JSON. @@ -194,7 +209,6 @@ const Position = { * of the toolbox in one of its many forms. * @return {?ToolboxInfo} Object holding information * for creating a toolbox. - * @package */ const convertToolboxDefToJson = function(toolboxDef) { if (!toolboxDef) { @@ -210,13 +224,14 @@ const convertToolboxDefToJson = function(toolboxDef) { validateToolbox(toolboxJson); return toolboxJson; }; +/** @package */ +exports.convertToolboxDefToJson = convertToolboxDefToJson; /** * Validates the toolbox JSON fields have been set correctly. * @param {!ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @throws {Error} if the toolbox is not the correct format. - * @private */ const validateToolbox = function(toolboxJson) { const toolboxKind = toolboxJson['kind']; @@ -241,7 +256,6 @@ const validateToolbox = function(toolboxJson) { * @param {?FlyoutDefinition} flyoutDef The definition of * the flyout in one of its many forms. * @return {!FlyoutItemInfoArray} A list of flyout items. - * @package */ const convertFlyoutDefToJsonArray = function(flyoutDef) { if (!flyoutDef) { @@ -260,13 +274,14 @@ const convertFlyoutDefToJsonArray = function(flyoutDef) { return xmlToJsonArray(/** @type {!Array|!NodeList} */ (flyoutDef)); }; +/** @package */ +exports.convertFlyoutDefToJsonArray = convertFlyoutDefToJsonArray; /** * Whether or not the toolbox definition has categories. * @param {?ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @return {boolean} True if the toolbox has categories. - * @package */ const hasCategories = function(toolboxJson) { if (!toolboxJson) { @@ -283,13 +298,14 @@ const hasCategories = function(toolboxJson) { }); return !!categories.length; }; +/** @package */ +exports.hasCategories = hasCategories; /** * Whether or not the category is collapsible. * @param {!CategoryInfo} categoryInfo Object holing * information for creating a category. * @return {boolean} True if the category has subcategories. - * @package */ const isCategoryCollapsible = function(categoryInfo) { if (!categoryInfo || !categoryInfo['contents']) { @@ -301,6 +317,8 @@ const isCategoryCollapsible = function(categoryInfo) { }); return !!categories.length; }; +/** @package */ +exports.isCategoryCollapsible = isCategoryCollapsible; /** * Parses the provided toolbox definition into a consistent format. @@ -308,7 +326,6 @@ const isCategoryCollapsible = function(categoryInfo) { * forms. * @return {!ToolboxInfo} Object holding information * for creating a toolbox. - * @private */ const convertToToolboxJson = function(toolboxDef) { const contents = xmlToJsonArray( @@ -327,7 +344,6 @@ const convertToToolboxJson = function(toolboxDef) { * @return {!FlyoutItemInfoArray| * !Array} A list of objects in * the toolbox. - * @private */ const xmlToJsonArray = function(toolboxDef) { const arr = []; @@ -364,7 +380,6 @@ const xmlToJsonArray = function(toolboxDef) { * Adds the attributes on the node to the given object. * @param {!Node} node The node to copy the attributes from. * @param {!Object} obj The object to copy the attributes to. - * @private */ const addAttributes = function(node, obj) { for (let j = 0; j < node.attributes.length; j++) { @@ -408,26 +423,4 @@ const parseToolboxTree = function(toolboxDef) { } return toolboxDef; }; - -exports = { - BlockInfo, - SeparatorInfo, - ButtonInfo, - LabelInfo, - ButtonOrLabelInfo, - StaticCategoryInfo, - DynamicCategoryInfo, - CategoryInfo, - ToolboxItemInfo, - FlyoutItemInfo, - ToolboxInfo, - FlyoutItemInfoArray, - ToolboxDefinition, - FlyoutDefinition, - Position, - convertToolboxDefToJson, - convertFlyoutDefToJsonArray, - hasCategories, - isCategoryCollapsible, - parseToolboxTree -}; +exports.parseToolboxTree = parseToolboxTree; From 94bdd1850582ef4332c76f3f9c486fba9c48367b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:23:17 -0700 Subject: [PATCH 08/48] Migrate core/field_number.js to ES6 const/let --- core/field_number.js | 10 +++++----- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index 369a161f8..d45c790cd 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -225,14 +225,14 @@ Blockly.FieldNumber.prototype.setPrecision = function(precision) { */ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { this.precision_ = Number(precision) || 0; - var precisionString = String(this.precision_); + let precisionString = String(this.precision_); if (precisionString.indexOf('e') != -1) { // String() is fast. But it turns .0000001 into '1e-7'. // Use the much slower toLocaleString to access all the digits. precisionString = this.precision_.toLocaleString('en-US', {maximumFractionDigits: 20}); } - var decimalIndex = precisionString.indexOf('.'); + const decimalIndex = precisionString.indexOf('.'); if (decimalIndex == -1) { // If the precision is 0 (float) allow any number of decimals, // otherwise allow none. @@ -265,7 +265,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { return null; } // Clean up text. - var newValue = String(opt_newValue); + let newValue = String(opt_newValue); // TODO: Handle cases like 'ten', '1.203,14', etc. // 'O' is sometimes mistaken for '0' by inexperienced users. newValue = newValue.replace(/O/ig, '0'); @@ -275,7 +275,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { newValue = newValue.replace(/infinity/i, 'Infinity'); // Clean up number. - var n = Number(newValue || 0); + let n = Number(newValue || 0); if (isNaN(n)) { // Invalid number. return null; @@ -300,7 +300,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { * @override */ Blockly.FieldNumber.prototype.widgetCreate_ = function() { - var htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); + const htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); // Set the accessibility state if (this.min_ > -Infinity) { diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..5485014dd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -57,7 +57,7 @@ goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockl goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); +goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); From 0a1311c9b5002d8edd568eb24f8e203743b699f2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:26:41 -0700 Subject: [PATCH 09/48] Migrate core/field_number.js to goog.module --- core/field_number.js | 51 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index d45c790cd..67900f344 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldNumber'); +goog.module('Blockly.FieldNumber'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.fieldRegistry'); goog.require('Blockly.FieldTextInput'); @@ -34,7 +35,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.FieldTextInput} * @constructor */ -Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, +const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, opt_validator, opt_config) { /** @@ -66,31 +67,31 @@ Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, */ this.decimalPlaces_ = null; - Blockly.FieldNumber.superClass_.constructor.call( + FieldNumber.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); if (!opt_config) { // Only do one kind of configuration or the other. this.setConstraints(opt_min, opt_max, opt_precision); } }; -Blockly.utils.object.inherits(Blockly.FieldNumber, Blockly.FieldTextInput); +Blockly.utils.object.inherits(FieldNumber, Blockly.FieldTextInput); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldNumber.prototype.DEFAULT_VALUE = 0; +FieldNumber.prototype.DEFAULT_VALUE = 0; /** * Construct a FieldNumber from a JSON arg object. * @param {!Object} options A JSON object with options (value, min, max, and * precision). - * @return {!Blockly.FieldNumber} The new field instance. + * @return {!FieldNumber} The new field instance. * @package * @nocollapse */ -Blockly.FieldNumber.fromJson = function(options) { +FieldNumber.fromJson = function(options) { // `this` might be a subclass of FieldNumber if that class doesn't override // the static fromJson method. return new this(options['value'], @@ -102,7 +103,7 @@ Blockly.FieldNumber.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldNumber.prototype.SERIALIZABLE = true; +FieldNumber.prototype.SERIALIZABLE = true; /** * Configure the field based on the given map of options. @@ -110,8 +111,8 @@ Blockly.FieldNumber.prototype.SERIALIZABLE = true; * @protected * @override */ -Blockly.FieldNumber.prototype.configure_ = function(config) { - Blockly.FieldNumber.superClass_.configure_.call(this, config); +FieldNumber.prototype.configure_ = function(config) { + FieldNumber.superClass_.configure_.call(this, config); this.setMinInternal_(config['min']); this.setMaxInternal_(config['max']); this.setPrecisionInternal_(config['precision']); @@ -128,7 +129,7 @@ Blockly.FieldNumber.prototype.configure_ = function(config) { * @param {?(number|string|undefined)} max Maximum value. * @param {?(number|string|undefined)} precision Precision for value. */ -Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) { +FieldNumber.prototype.setConstraints = function(min, max, precision) { this.setMinInternal_(min); this.setMaxInternal_(max); this.setPrecisionInternal_(precision); @@ -139,7 +140,7 @@ Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) { * Sets the minimum value this field can contain. Updates the value to reflect. * @param {?(number|string|undefined)} min Minimum value. */ -Blockly.FieldNumber.prototype.setMin = function(min) { +FieldNumber.prototype.setMin = function(min) { this.setMinInternal_(min); this.setValue(this.getValue()); }; @@ -150,7 +151,7 @@ Blockly.FieldNumber.prototype.setMin = function(min) { * @param {?(number|string|undefined)} min Minimum value. * @private */ -Blockly.FieldNumber.prototype.setMinInternal_ = function(min) { +FieldNumber.prototype.setMinInternal_ = function(min) { if (min == null) { this.min_ = -Infinity; } else { @@ -166,7 +167,7 @@ Blockly.FieldNumber.prototype.setMinInternal_ = function(min) { * -Infinity. * @return {number} The current minimum value this field can contain. */ -Blockly.FieldNumber.prototype.getMin = function() { +FieldNumber.prototype.getMin = function() { return this.min_; }; @@ -174,7 +175,7 @@ Blockly.FieldNumber.prototype.getMin = function() { * Sets the maximum value this field can contain. Updates the value to reflect. * @param {?(number|string|undefined)} max Maximum value. */ -Blockly.FieldNumber.prototype.setMax = function(max) { +FieldNumber.prototype.setMax = function(max) { this.setMaxInternal_(max); this.setValue(this.getValue()); }; @@ -185,7 +186,7 @@ Blockly.FieldNumber.prototype.setMax = function(max) { * @param {?(number|string|undefined)} max Maximum value. * @private */ -Blockly.FieldNumber.prototype.setMaxInternal_ = function(max) { +FieldNumber.prototype.setMaxInternal_ = function(max) { if (max == null) { this.max_ = Infinity; } else { @@ -201,7 +202,7 @@ Blockly.FieldNumber.prototype.setMaxInternal_ = function(max) { * Infinity. * @return {number} The current maximum value this field can contain. */ -Blockly.FieldNumber.prototype.getMax = function() { +FieldNumber.prototype.getMax = function() { return this.max_; }; @@ -211,7 +212,7 @@ Blockly.FieldNumber.prototype.getMax = function() { * @param {?(number|string|undefined)} precision The number to which the * field's value is rounded. */ -Blockly.FieldNumber.prototype.setPrecision = function(precision) { +FieldNumber.prototype.setPrecision = function(precision) { this.setPrecisionInternal_(precision); this.setValue(this.getValue()); }; @@ -223,7 +224,7 @@ Blockly.FieldNumber.prototype.setPrecision = function(precision) { * field's value is rounded. * @private */ -Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { +FieldNumber.prototype.setPrecisionInternal_ = function(precision) { this.precision_ = Number(precision) || 0; let precisionString = String(this.precision_); if (precisionString.indexOf('e') != -1) { @@ -248,7 +249,7 @@ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { * the value is not rounded. * @return {number} The number to which this field's value is rounded. */ -Blockly.FieldNumber.prototype.getPrecision = function() { +FieldNumber.prototype.getPrecision = function() { return this.precision_; }; @@ -260,7 +261,7 @@ Blockly.FieldNumber.prototype.getPrecision = function() { * @protected * @override */ -Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { +FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null) { return null; } @@ -299,8 +300,8 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { * @protected * @override */ -Blockly.FieldNumber.prototype.widgetCreate_ = function() { - const htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); +FieldNumber.prototype.widgetCreate_ = function() { + const htmlInput = FieldNumber.superClass_.widgetCreate_.call(this); // Set the accessibility state if (this.min_ > -Infinity) { @@ -314,4 +315,6 @@ Blockly.FieldNumber.prototype.widgetCreate_ = function() { return htmlInput; }; -Blockly.fieldRegistry.register('field_number', Blockly.FieldNumber); +Blockly.fieldRegistry.register('field_number', FieldNumber); + +exports = FieldNumber; diff --git a/tests/deps.js b/tests/deps.js index 5485014dd..80ddf87c8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -57,7 +57,7 @@ goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockl goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6'}); +goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); From 25fc34925f194c3c703cb9b4c7945e34950f1b34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:31:39 -0700 Subject: [PATCH 10/48] Migrate core/field_number.js to named requires --- core/field_number.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index 67900f344..e8d628572 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -13,10 +13,10 @@ goog.module('Blockly.FieldNumber'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.object'); +const FieldTextInput = goog.require('Blockly.FieldTextInput'); +const aria = goog.require('Blockly.utils.aria'); +const {inherits} = goog.require('Blockly.utils.object'); +const {register} = goog.require('Blockly.fieldRegistry'); /** @@ -32,7 +32,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldTextInput} + * @extends {FieldTextInput} * @constructor */ const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, @@ -74,7 +74,7 @@ const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, this.setConstraints(opt_min, opt_max, opt_precision); } }; -Blockly.utils.object.inherits(FieldNumber, Blockly.FieldTextInput); +inherits(FieldNumber, FieldTextInput); /** * The default value for this field. @@ -305,16 +305,16 @@ FieldNumber.prototype.widgetCreate_ = function() { // Set the accessibility state if (this.min_ > -Infinity) { - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.VALUEMIN, this.min_); + aria.setState(htmlInput, + aria.State.VALUEMIN, this.min_); } if (this.max_ < Infinity) { - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.VALUEMAX, this.max_); + aria.setState(htmlInput, + aria.State.VALUEMAX, this.max_); } return htmlInput; }; -Blockly.fieldRegistry.register('field_number', FieldNumber); +register('field_number', FieldNumber); exports = FieldNumber; From e15470bbd0f7ca74e0452dba8606fe2344e1539b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:32:09 -0700 Subject: [PATCH 11/48] clang-format core/field_number.js --- core/field_number.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index e8d628572..8389f477f 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -30,14 +30,14 @@ const {register} = goog.require('Blockly.fieldRegistry'); * changes to the field's value. Takes in a number & returns a validated * number, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} * for a list of properties this parameter supports. * @extends {FieldTextInput} * @constructor */ -const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, - opt_validator, opt_config) { - +const FieldNumber = function( + opt_value, opt_min, opt_max, opt_precision, opt_validator, opt_config) { /** * The minimum value this number field can contain. * @type {number} @@ -94,8 +94,8 @@ FieldNumber.prototype.DEFAULT_VALUE = 0; FieldNumber.fromJson = function(options) { // `this` might be a subclass of FieldNumber if that class doesn't override // the static fromJson method. - return new this(options['value'], - undefined, undefined, undefined, undefined, options); + return new this( + options['value'], undefined, undefined, undefined, undefined, options); }; /** @@ -305,12 +305,10 @@ FieldNumber.prototype.widgetCreate_ = function() { // Set the accessibility state if (this.min_ > -Infinity) { - aria.setState(htmlInput, - aria.State.VALUEMIN, this.min_); + aria.setState(htmlInput, aria.State.VALUEMIN, this.min_); } if (this.max_ < Infinity) { - aria.setState(htmlInput, - aria.State.VALUEMAX, this.max_); + aria.setState(htmlInput, aria.State.VALUEMAX, this.max_); } return htmlInput; }; From 7a050d021db8d56f2c64a139678c7659ff739e23 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:43:46 -0700 Subject: [PATCH 12/48] Migrate core/field_checkbox.js to goog.module --- core/field_checkbox.js | 55 ++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 207b29f7f..df3509239 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldCheckbox'); +goog.module('Blockly.FieldCheckbox'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); @@ -34,7 +35,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldCheckbox = function(opt_value, opt_validator, opt_config) { +const FieldCheckbox = function(opt_value, opt_validator, opt_config) { /** * Character for the check mark. Used to apply a different check mark * character to individual fields. @@ -43,26 +44,26 @@ Blockly.FieldCheckbox = function(opt_value, opt_validator, opt_config) { */ this.checkChar_ = null; - Blockly.FieldCheckbox.superClass_.constructor.call( + FieldCheckbox.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); }; -Blockly.utils.object.inherits(Blockly.FieldCheckbox, Blockly.Field); +Blockly.utils.object.inherits(FieldCheckbox, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldCheckbox.prototype.DEFAULT_VALUE = false; +FieldCheckbox.prototype.DEFAULT_VALUE = false; /** * Construct a FieldCheckbox from a JSON arg object. * @param {!Object} options A JSON object with options (checked). - * @return {!Blockly.FieldCheckbox} The new field instance. + * @return {!FieldCheckbox} The new field instance. * @package * @nocollapse */ -Blockly.FieldCheckbox.fromJson = function(options) { +FieldCheckbox.fromJson = function(options) { // `this` might be a subclass of FieldCheckbox if that class doesn't override // the static fromJson method. return new this(options['checked'], undefined, options); @@ -73,19 +74,19 @@ Blockly.FieldCheckbox.fromJson = function(options) { * @type {string} * @const */ -Blockly.FieldCheckbox.CHECK_CHAR = '\u2713'; +FieldCheckbox.CHECK_CHAR = '\u2713'; /** * Serializable fields are saved by the XML renderer, non-serializable fields * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldCheckbox.prototype.SERIALIZABLE = true; +FieldCheckbox.prototype.SERIALIZABLE = true; /** * Mouse cursor style when over the hotspot that initiates editability. */ -Blockly.FieldCheckbox.prototype.CURSOR = 'default'; +FieldCheckbox.prototype.CURSOR = 'default'; /** * Configure the field based on the given map of options. @@ -93,8 +94,8 @@ Blockly.FieldCheckbox.prototype.CURSOR = 'default'; * @protected * @override */ -Blockly.FieldCheckbox.prototype.configure_ = function(config) { - Blockly.FieldCheckbox.superClass_.configure_.call(this, config); +FieldCheckbox.prototype.configure_ = function(config) { + FieldCheckbox.superClass_.configure_.call(this, config); if (config['checkCharacter']) { this.checkChar_ = config['checkCharacter']; } @@ -104,8 +105,8 @@ Blockly.FieldCheckbox.prototype.configure_ = function(config) { * Create the block UI for this checkbox. * @package */ -Blockly.FieldCheckbox.prototype.initView = function() { - Blockly.FieldCheckbox.superClass_.initView.call(this); +FieldCheckbox.prototype.initView = function() { + FieldCheckbox.superClass_.initView.call(this); Blockly.utils.dom.addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); @@ -115,7 +116,7 @@ Blockly.FieldCheckbox.prototype.initView = function() { /** * @override */ -Blockly.FieldCheckbox.prototype.render_ = function() { +FieldCheckbox.prototype.render_ = function() { if (this.textContent_) { this.textContent_.nodeValue = this.getDisplayText_(); } @@ -125,8 +126,8 @@ Blockly.FieldCheckbox.prototype.render_ = function() { /** * @override */ -Blockly.FieldCheckbox.prototype.getDisplayText_ = function() { - return this.checkChar_ || Blockly.FieldCheckbox.CHECK_CHAR; +FieldCheckbox.prototype.getDisplayText_ = function() { + return this.checkChar_ || FieldCheckbox.CHECK_CHAR; }; /** @@ -134,7 +135,7 @@ Blockly.FieldCheckbox.prototype.getDisplayText_ = function() { * @param {?string} character The character to use for the check mark, or * null to use the default. */ -Blockly.FieldCheckbox.prototype.setCheckCharacter = function(character) { +FieldCheckbox.prototype.setCheckCharacter = function(character) { this.checkChar_ = character; this.forceRerender(); }; @@ -143,7 +144,7 @@ Blockly.FieldCheckbox.prototype.setCheckCharacter = function(character) { * Toggle the state of the checkbox on click. * @protected */ -Blockly.FieldCheckbox.prototype.showEditor_ = function() { +FieldCheckbox.prototype.showEditor_ = function() { this.setValue(!this.value_); }; @@ -153,7 +154,7 @@ Blockly.FieldCheckbox.prototype.showEditor_ = function() { * @return {?string} A valid value ('TRUE' or 'FALSE), or null if invalid. * @protected */ -Blockly.FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { +FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === true || opt_newValue === 'TRUE') { return 'TRUE'; } @@ -169,7 +170,7 @@ Blockly.FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { * that this is a either 'TRUE' or 'FALSE'. * @protected */ -Blockly.FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { +FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { this.value_ = this.convertValueToBool_(newValue); // Update visual. if (this.textElement_) { @@ -181,7 +182,7 @@ Blockly.FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { * Get the value of this field, either 'TRUE' or 'FALSE'. * @return {string} The value of this field. */ -Blockly.FieldCheckbox.prototype.getValue = function() { +FieldCheckbox.prototype.getValue = function() { return this.value_ ? 'TRUE' : 'FALSE'; }; @@ -189,7 +190,7 @@ Blockly.FieldCheckbox.prototype.getValue = function() { * Get the boolean value of this field. * @return {boolean} The boolean value of this field. */ -Blockly.FieldCheckbox.prototype.getValueBoolean = function() { +FieldCheckbox.prototype.getValueBoolean = function() { return /** @type {boolean} */ (this.value_); }; @@ -198,7 +199,7 @@ Blockly.FieldCheckbox.prototype.getValueBoolean = function() { * @return {string} Text representing the value of this field * ('true' or 'false'). */ -Blockly.FieldCheckbox.prototype.getText = function() { +FieldCheckbox.prototype.getText = function() { return String(this.convertValueToBool_(this.value_)); }; @@ -211,7 +212,7 @@ Blockly.FieldCheckbox.prototype.getText = function() { * @return {boolean} The converted value. * @private */ -Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) { +FieldCheckbox.prototype.convertValueToBool_ = function(value) { if (typeof value == 'string') { return value == 'TRUE'; } else { @@ -219,4 +220,6 @@ Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -Blockly.fieldRegistry.register('field_checkbox', Blockly.FieldCheckbox); +Blockly.fieldRegistry.register('field_checkbox', FieldCheckbox); + +exports = FieldCheckbox; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..d6e6163f8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -50,7 +50,7 @@ goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.Co goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); From 29135ec920d974b1eb170b44f59b19a6194de19d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:47:44 -0700 Subject: [PATCH 13/48] Migrate core/field_checkbox.js to named requires --- core/field_checkbox.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index df3509239..9100aa8d3 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -13,12 +13,12 @@ goog.module('Blockly.FieldCheckbox'); goog.module.declareLegacyNamespace(); +const Field = goog.require('Blockly.Field'); +const {addClass} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {register} = goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); /** @@ -32,7 +32,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldCheckbox = function(opt_value, opt_validator, opt_config) { @@ -47,7 +47,7 @@ const FieldCheckbox = function(opt_value, opt_validator, opt_config) { FieldCheckbox.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); }; -Blockly.utils.object.inherits(FieldCheckbox, Blockly.Field); +inherits(FieldCheckbox, Field); /** * The default value for this field. @@ -108,7 +108,7 @@ FieldCheckbox.prototype.configure_ = function(config) { FieldCheckbox.prototype.initView = function() { FieldCheckbox.superClass_.initView.call(this); - Blockly.utils.dom.addClass( + addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); this.textElement_.style.display = this.value_ ? 'block' : 'none'; }; @@ -220,6 +220,6 @@ FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -Blockly.fieldRegistry.register('field_checkbox', FieldCheckbox); +register('field_checkbox', FieldCheckbox); exports = FieldCheckbox; From 5bc41ac960588334e0af831754f58a92ae264ab4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:48:43 -0700 Subject: [PATCH 14/48] clang-format core/field_checkbox.js --- core/field_checkbox.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 9100aa8d3..3cbe8d07f 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -30,7 +30,8 @@ goog.require('Blockly.Events.BlockChange'); * returns a validated value ('TRUE' or 'FALSE'), or null to abort the * change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor From 9d6cbe96d3df420984b23f2fb02ea57722691962 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:45:30 -0700 Subject: [PATCH 15/48] Migrate core/keyboard_nav/tab_navigate_cursor.js to ES6 const/let --- core/keyboard_nav/tab_navigate_cursor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 7d43a79f8..b339520c0 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -37,10 +37,10 @@ Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); * @override */ Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { - var isValid = false; - var type = node && node.getType(); + let isValid = false; + const type = node && node.getType(); if (node) { - var location = /** @type {Blockly.Field} */ (node.getLocation()); + const location = /** @type {Blockly.Field} */ (node.getLocation()); if (type == Blockly.ASTNode.types.FIELD && location && location.isTabNavigable() && location.isClickable()) { isValid = true; From f282c573239970143e4d92eb6933cff82086e914 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:45:55 -0700 Subject: [PATCH 16/48] Migrate core/keyboard_nav/tab_navigate_cursor.js to goog.module --- core/keyboard_nav/tab_navigate_cursor.js | 13 ++++++++----- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index b339520c0..ad2bb45ba 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.TabNavigateCursor'); +goog.module('Blockly.TabNavigateCursor'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); goog.require('Blockly.BasicCursor'); @@ -25,10 +26,10 @@ goog.requireType('Blockly.Field'); * @constructor * @extends {Blockly.BasicCursor} */ -Blockly.TabNavigateCursor = function() { - Blockly.TabNavigateCursor.superClass_.constructor.call(this); +const TabNavigateCursor = function() { + TabNavigateCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); +Blockly.utils.object.inherits(TabNavigateCursor, Blockly.BasicCursor); /** * Skip all nodes except for tab navigable fields. @@ -36,7 +37,7 @@ Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); * @return {boolean} True if the node should be visited, false otherwise. * @override */ -Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { +TabNavigateCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); if (node) { @@ -48,3 +49,5 @@ Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { } return isValid; }; + +exports = TabNavigateCursor; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..0c03cecf3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -105,7 +105,7 @@ goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], [ goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); From 9a6a92bf52d748bd36c82250e9c023a0084e550e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:47:25 -0700 Subject: [PATCH 17/48] Migrate core/keyboard_nav/tab_navigate_cursor.js named requires --- core/keyboard_nav/tab_navigate_cursor.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index ad2bb45ba..37f90fe37 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -14,26 +14,25 @@ goog.module('Blockly.TabNavigateCursor'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); -goog.require('Blockly.BasicCursor'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Field'); +const ASTNode = goog.require('Blockly.ASTNode'); +const BasicCursor = goog.require('Blockly.BasicCursor'); +const Field = goog.requireType('Blockly.Field'); +const {inherits} = goog.require('Blockly.utils.object'); /** * A cursor for navigating between tab navigable fields. * @constructor - * @extends {Blockly.BasicCursor} + * @extends {BasicCursor} */ const TabNavigateCursor = function() { TabNavigateCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(TabNavigateCursor, Blockly.BasicCursor); +inherits(TabNavigateCursor, BasicCursor); /** * Skip all nodes except for tab navigable fields. - * @param {Blockly.ASTNode} node The AST node to check whether it is valid. + * @param {?ASTNode} node The AST node to check whether it is valid. * @return {boolean} True if the node should be visited, false otherwise. * @override */ @@ -41,8 +40,8 @@ TabNavigateCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); if (node) { - const location = /** @type {Blockly.Field} */ (node.getLocation()); - if (type == Blockly.ASTNode.types.FIELD && + const location = /** @type {Field} */ (node.getLocation()); + if (type == ASTNode.types.FIELD && location && location.isTabNavigable() && location.isClickable()) { isValid = true; } From ecec6daf80e9b7910393e371223b3824855f180b Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:47:41 -0700 Subject: [PATCH 18/48] clang-format core/keyboard_nav/tab_navigate_cursor.js --- core/keyboard_nav/tab_navigate_cursor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 37f90fe37..3b82267a1 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -41,8 +41,8 @@ TabNavigateCursor.prototype.validNode_ = function(node) { const type = node && node.getType(); if (node) { const location = /** @type {Field} */ (node.getLocation()); - if (type == ASTNode.types.FIELD && - location && location.isTabNavigable() && location.isClickable()) { + if (type == ASTNode.types.FIELD && location && location.isTabNavigable() && + location.isClickable()) { isValid = true; } } From 0dc01b16188564b949b90512133d59c4eabb7c40 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:02:32 -0700 Subject: [PATCH 19/48] Migrate core/drag_target.js to goog.module --- core/drag_target.js | 19 +++++++++++-------- tests/deps.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/drag_target.js b/core/drag_target.js index 438bf6a31..91d46c5ca 100644 --- a/core/drag_target.js +++ b/core/drag_target.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.DragTarget'); +goog.module('Blockly.DragTarget'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IDragTarget'); @@ -26,7 +27,7 @@ goog.requireType('Blockly.utils.Rect'); * @implements {Blockly.IDragTarget} * @constructor */ -Blockly.DragTarget = function() {}; +const DragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units @@ -34,14 +35,14 @@ Blockly.DragTarget = function() {}; * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.DragTarget.prototype.getClientRect; +DragTarget.prototype.getClientRect; /** * Handles when a cursor with a block or bubble enters this drag target. * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDragEnter = function(_dragElement) { +DragTarget.prototype.onDragEnter = function(_dragElement) { // no-op }; @@ -51,7 +52,7 @@ Blockly.DragTarget.prototype.onDragEnter = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDragOver = function(_dragElement) { +DragTarget.prototype.onDragOver = function(_dragElement) { // no-op }; @@ -60,7 +61,7 @@ Blockly.DragTarget.prototype.onDragOver = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDragExit = function(_dragElement) { +DragTarget.prototype.onDragExit = function(_dragElement) { // no-op }; @@ -70,7 +71,7 @@ Blockly.DragTarget.prototype.onDragExit = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDrop = function(_dragElement) { +DragTarget.prototype.onDrop = function(_dragElement) { // no-op }; @@ -83,6 +84,8 @@ Blockly.DragTarget.prototype.onDrop = function(_dragElement) { * @return {boolean} Whether the block or bubble provided should be returned to * drag start. */ -Blockly.DragTarget.prototype.shouldPreventMove = function(_dragElement) { +DragTarget.prototype.shouldPreventMove = function(_dragElement) { return false; }; + +exports = DragTarget; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..74b561fe4 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); From b1b5358b678041ac0603fc59f93c4829e0554735 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:06:53 -0700 Subject: [PATCH 20/48] Migrate core/drag_target.js to named requires --- core/drag_target.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/drag_target.js b/core/drag_target.js index 91d46c5ca..18e29b40a 100644 --- a/core/drag_target.js +++ b/core/drag_target.js @@ -15,16 +15,18 @@ goog.module('Blockly.DragTarget'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IDragTarget'); - -goog.requireType('Blockly.IDraggable'); -goog.requireType('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ +const IDragTarget = goog.require('Blockly.IDragTarget'); +/* eslint-disable-next-line no-unused-vars */ +const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ +const Rect = goog.requireType('Blockly.utils.Rect'); /** * Abstract class for a component with custom behaviour when a block or bubble * is dragged over or dropped on top of it. - * @implements {Blockly.IDragTarget} + * @implements {IDragTarget} * @constructor */ const DragTarget = function() {}; @@ -32,14 +34,14 @@ const DragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units * relative to the Blockly injection div. - * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag + * @return {?Rect} The component's bounding box. Null if drag * target area should be ignored. */ DragTarget.prototype.getClientRect; /** * Handles when a cursor with a block or bubble enters this drag target. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. */ DragTarget.prototype.onDragEnter = function(_dragElement) { @@ -49,7 +51,7 @@ DragTarget.prototype.onDragEnter = function(_dragElement) { /** * Handles when a cursor with a block or bubble is dragged over this drag * target. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. */ DragTarget.prototype.onDragOver = function(_dragElement) { @@ -58,7 +60,7 @@ DragTarget.prototype.onDragOver = function(_dragElement) { /** * Handles when a cursor with a block or bubble exits this drag target. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. */ DragTarget.prototype.onDragExit = function(_dragElement) { @@ -68,7 +70,7 @@ DragTarget.prototype.onDragExit = function(_dragElement) { /** * Handles when a block or bubble is dropped on this component. * Should not handle delete here. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. */ DragTarget.prototype.onDrop = function(_dragElement) { @@ -79,7 +81,7 @@ DragTarget.prototype.onDrop = function(_dragElement) { * Returns whether the provided block or bubble should not be moved after being * dropped on this component. If true, the element will return to where it was * when the drag started. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. * @return {boolean} Whether the block or bubble provided should be returned to * drag start. From a57399704f5be6af807040bc12190f8e00f576f0 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:15:25 -0700 Subject: [PATCH 21/48] Migrate core/field.js to ES6 const/let --- core/field.js | 79 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/core/field.js b/core/field.js index f5f027c45..ed15cd494 100644 --- a/core/field.js +++ b/core/field.js @@ -267,7 +267,7 @@ Blockly.Field.prototype.SERIALIZABLE = false; * @protected */ Blockly.Field.prototype.configure_ = function(config) { - var tooltip = config['tooltip']; + let tooltip = config['tooltip']; if (typeof tooltip == 'string') { tooltip = Blockly.utils.replaceMessageReferences( config['tooltip']); @@ -325,7 +325,7 @@ Blockly.Field.prototype.init = function() { if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } - var sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); + const sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); sourceBlockSvg.getSvgRoot().appendChild(this.fieldGroup_); this.initView(); this.updateEditable(); @@ -444,7 +444,7 @@ Blockly.Field.prototype.dispose = function() { * Add or remove the UI indicating if this field is editable or not. */ Blockly.Field.prototype.updateEditable = function() { - var group = this.fieldGroup_; + const group = this.fieldGroup_; if (!this.EDITABLE || !group) { return; } @@ -506,7 +506,7 @@ Blockly.Field.prototype.isCurrentlyEditable = function() { * @return {boolean} Whether this field should be serialized or not. */ Blockly.Field.prototype.isSerializable = function() { - var isSerializable = false; + let isSerializable = false; if (this.name) { if (this.SERIALIZABLE) { isSerializable = true; @@ -539,7 +539,7 @@ Blockly.Field.prototype.setVisible = function(visible) { return; } this.visible_ = visible; - var root = this.getSvgRoot(); + const root = this.getSvgRoot(); if (root) { root.style.display = visible ? 'block' : 'none'; } @@ -622,13 +622,13 @@ Blockly.Field.prototype.showEditor = function(opt_e) { * @protected */ Blockly.Field.prototype.updateSize_ = function(opt_margin) { - var constants = this.getConstants(); - var xOffset = opt_margin != undefined ? opt_margin : + const constants = this.getConstants(); + const xOffset = opt_margin != undefined ? opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); - var totalWidth = xOffset * 2; - var totalHeight = constants.FIELD_TEXT_HEIGHT; + let totalWidth = xOffset * 2; + let totalHeight = constants.FIELD_TEXT_HEIGHT; - var contentWidth = 0; + let contentWidth = 0; if (this.textElement_) { contentWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, constants.FIELD_TEXT_FONTSIZE, @@ -658,8 +658,8 @@ Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { if (!this.textElement_) { return; } - var constants = this.getConstants(); - var halfHeight = this.size_.height / 2; + const constants = this.getConstants(); + const halfHeight = this.size_.height / 2; this.textElement_.setAttribute('x', this.sourceBlock_.RTL ? this.size_.width - contentWidth - xOffset : xOffset); @@ -717,15 +717,16 @@ Blockly.Field.prototype.getSize = function() { * @package */ Blockly.Field.prototype.getScaledBBox = function() { + let scaledWidth, scaledHeight, xy; if (!this.borderRect_) { // Browsers are inconsistent in what they return for a bounding box. // - Webkit / Blink: fill-box / object bounding box // - Gecko / Triden / EdgeHTML: stroke-box - var bBox = this.sourceBlock_.getHeightWidth(); - var scale = this.sourceBlock_.workspace.scale; - var xy = this.getAbsoluteXY_(); - var scaledWidth = bBox.width * scale; - var scaledHeight = bBox.height * scale; + const bBox = this.sourceBlock_.getHeightWidth(); + const scale = this.sourceBlock_.workspace.scale; + xy = this.getAbsoluteXY_(); + scaledWidth = bBox.width * scale; + scaledHeight = bBox.height * scale; if (Blockly.utils.userAgent.GECKO) { xy.x += 1.5 * scale; @@ -741,10 +742,10 @@ Blockly.Field.prototype.getScaledBBox = function() { scaledHeight += 1 * scale; } } else { - var bBox = this.borderRect_.getBoundingClientRect(); - var xy = Blockly.utils.style.getPageOffset(this.borderRect_); - var scaledWidth = bBox.width; - var scaledHeight = bBox.height; + const bBox = this.borderRect_.getBoundingClientRect(); + xy = Blockly.utils.style.getPageOffset(this.borderRect_); + scaledWidth = bBox.width; + scaledHeight = bBox.height; } return new Blockly.utils.Rect( xy.y, @@ -761,7 +762,7 @@ Blockly.Field.prototype.getScaledBBox = function() { * @protected */ Blockly.Field.prototype.getDisplayText_ = function() { - var text = this.getText(); + let text = this.getText(); if (!text) { // Prevent the field from disappearing if empty. return Blockly.Field.NBSP; @@ -785,7 +786,7 @@ Blockly.Field.prototype.getDisplayText_ = function() { */ Blockly.Field.prototype.getText = function() { if (this.getText_) { - var text = this.getText_.call(this); + const text = this.getText_.call(this); if (text !== null) { return String(text); } @@ -828,14 +829,14 @@ Blockly.Field.prototype.forceRerender = function() { * @param {*} newValue New value. */ Blockly.Field.prototype.setValue = function(newValue) { - var doLogging = false; + const doLogging = false; if (newValue === null) { doLogging && console.log('null, return'); // Not a valid value to check. return; } - var validatedValue = this.doClassValidation_(newValue); + let validatedValue = this.doClassValidation_(newValue); // Class validators might accidentally forget to return, we'll ignore that. newValue = this.processValidation_(newValue, validatedValue); if (newValue instanceof Error) { @@ -843,7 +844,7 @@ Blockly.Field.prototype.setValue = function(newValue) { return; } - var localValidator = this.getValidator(); + const localValidator = this.getValidator(); if (localValidator) { validatedValue = localValidator.call(this, newValue); // Local validators might accidentally forget to return, we'll ignore that. @@ -853,12 +854,12 @@ Blockly.Field.prototype.setValue = function(newValue) { return; } } - var source = this.sourceBlock_; + const source = this.sourceBlock_; if (source && source.disposed) { doLogging && console.log('source disposed, return'); return; } - var oldValue = this.getValue(); + const oldValue = this.getValue(); if (oldValue === newValue) { doLogging && console.log('same, doValueUpdate_, return'); this.doValueUpdate_(newValue); @@ -951,7 +952,7 @@ Blockly.Field.prototype.onMouseDown_ = function(e) { if (!this.sourceBlock_ || !this.sourceBlock_.workspace) { return; } - var gesture = this.sourceBlock_.workspace.getGesture(e); + const gesture = this.sourceBlock_.workspace.getGesture(e); if (gesture) { gesture.setStartField(this); } @@ -968,7 +969,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { if (!newTip && newTip !== '') { // If null or undefined. newTip = this.sourceBlock_; } - var clickTarget = this.getClickTarget_(); + const clickTarget = this.getClickTarget_(); if (clickTarget) { clickTarget.tooltip = newTip; } else { @@ -982,7 +983,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { * @return {string} The tooltip text for this field. */ Blockly.Field.prototype.getTooltip = function() { - var clickTarget = this.getClickTarget_(); + const clickTarget = this.getClickTarget_(); if (clickTarget) { return Blockly.Tooltip.getTooltipOfObject(clickTarget); } @@ -1030,14 +1031,14 @@ Blockly.Field.prototype.referencesVariables = function() { * @package */ Blockly.Field.prototype.getParentInput = function() { - var parentInput = null; - var block = this.sourceBlock_; - var inputs = block.inputList; + let parentInput = null; + const block = this.sourceBlock_; + const inputs = block.inputList; - for (var idx = 0; idx < block.inputList.length; idx++) { - var input = inputs[idx]; - var fieldRows = input.fieldRow; - for (var j = 0; j < fieldRows.length; j++) { + for (let idx = 0; idx < block.inputList.length; idx++) { + const input = inputs[idx]; + const fieldRows = input.fieldRow; + for (let j = 0; j < fieldRows.length; j++) { if (fieldRows[j] === this) { parentInput = input; break; @@ -1110,7 +1111,7 @@ Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { * @protected */ Blockly.Field.prototype.updateMarkers_ = function() { - var workspace = + const workspace = /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); From 91721f7d163092940d6cb8941889d8a6045acee2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:18:41 -0700 Subject: [PATCH 22/48] Migrate core/field.js to goog.module --- core/field.js | 151 +++++++++++++++++++++++++------------------------- tests/deps.js | 2 +- 2 files changed, 78 insertions(+), 75 deletions(-) diff --git a/core/field.js b/core/field.js index ed15cd494..d9db11cbd 100644 --- a/core/field.js +++ b/core/field.js @@ -7,12 +7,13 @@ /** * @fileoverview Field. Used for editable titles, variables, etc. * This is an abstract class that defines the UI on the block. Actual - * instances would be Blockly.FieldTextInput, Blockly.FieldDropdown, etc. + * instances would be FieldTextInput, FieldDropdown, etc. * @author fraser@google.com (Neil Fraser) */ 'use strict'; -goog.provide('Blockly.Field'); +goog.module('Blockly.Field'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.DropDownDiv'); @@ -61,7 +62,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @implements {Blockly.IKeyboardAccessible} * @implements {Blockly.IRegistrable} */ -Blockly.Field = function(value, opt_validator, opt_config) { +const Field = function(value, opt_validator, opt_config) { /** * A generic value possessed by the field. * Should generally be non-null, only null when the field is created. @@ -160,62 +161,62 @@ Blockly.Field = function(value, opt_validator, opt_config) { * @type {*} * @protected */ -Blockly.Field.prototype.DEFAULT_VALUE = null; +Field.prototype.DEFAULT_VALUE = null; /** * Name of field. Unique within each block. * Static labels are usually unnamed. * @type {string|undefined} */ -Blockly.Field.prototype.name = undefined; +Field.prototype.name = undefined; /** * Has this field been disposed of? * @type {boolean} * @package */ -Blockly.Field.prototype.disposed = false; +Field.prototype.disposed = false; /** * Maximum characters of text to display before adding an ellipsis. * @type {number} */ -Blockly.Field.prototype.maxDisplayLength = 50; +Field.prototype.maxDisplayLength = 50; /** * Block this field is attached to. Starts as null, then set in init. * @type {Blockly.Block} * @protected */ -Blockly.Field.prototype.sourceBlock_ = null; +Field.prototype.sourceBlock_ = null; /** * Does this block need to be re-rendered? * @type {boolean} * @protected */ -Blockly.Field.prototype.isDirty_ = true; +Field.prototype.isDirty_ = true; /** * Is the field visible, or hidden due to the block being collapsed? * @type {boolean} * @protected */ -Blockly.Field.prototype.visible_ = true; +Field.prototype.visible_ = true; /** * Can the field value be changed using the editor on an editable block? * @type {boolean} * @protected */ -Blockly.Field.prototype.enabled_ = true; +Field.prototype.enabled_ = true; /** * The element the click handler is bound to. * @type {Element} * @protected */ -Blockly.Field.prototype.clickTarget_ = null; +Field.prototype.clickTarget_ = null; /** * A developer hook to override the returned text of this field. @@ -225,7 +226,7 @@ Blockly.Field.prototype.clickTarget_ = null; * @return {?string} Current text. Return null to resort to a string cast. * @protected */ -Blockly.Field.prototype.getText_; +Field.prototype.getText_; /** * An optional method that can be defined to show an editor when the field is @@ -236,20 +237,20 @@ Blockly.Field.prototype.getText_; * @return {void} * @protected */ -Blockly.Field.prototype.showEditor_; +Field.prototype.showEditor_; /** * Non-breaking space. * @const */ -Blockly.Field.NBSP = '\u00A0'; +Field.NBSP = '\u00A0'; /** * Editable fields usually show some sort of UI indicating they are editable. * They will also be saved by the XML renderer. * @type {boolean} */ -Blockly.Field.prototype.EDITABLE = true; +Field.prototype.EDITABLE = true; /** * Serializable fields are saved by the XML renderer, non-serializable fields @@ -257,7 +258,7 @@ Blockly.Field.prototype.EDITABLE = true; * case by default so that SERIALIZABLE is backwards compatible. * @type {boolean} */ -Blockly.Field.prototype.SERIALIZABLE = false; +Field.prototype.SERIALIZABLE = false; /** * Process the configuration map passed to the field. @@ -266,7 +267,7 @@ Blockly.Field.prototype.SERIALIZABLE = false; * parameter supports. * @protected */ -Blockly.Field.prototype.configure_ = function(config) { +Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { tooltip = Blockly.utils.replaceMessageReferences( @@ -282,7 +283,7 @@ Blockly.Field.prototype.configure_ = function(config) { * Attach this field to a block. * @param {!Blockly.Block} block The block containing this field. */ -Blockly.Field.prototype.setSourceBlock = function(block) { +Field.prototype.setSourceBlock = function(block) { if (this.sourceBlock_) { throw Error('Field already bound to a block'); } @@ -294,7 +295,7 @@ Blockly.Field.prototype.setSourceBlock = function(block) { * @return {?Blockly.blockRendering.ConstantProvider} The renderer constant * provider. */ -Blockly.Field.prototype.getConstants = function() { +Field.prototype.getConstants = function() { if (!this.constants_ && this.sourceBlock_ && this.sourceBlock_.workspace && this.sourceBlock_.workspace.rendered) { this.constants_ = this.sourceBlock_.workspace.getRenderer().getConstants(); @@ -306,7 +307,7 @@ Blockly.Field.prototype.getConstants = function() { * Get the block this field is attached to. * @return {Blockly.Block} The block containing this field. */ -Blockly.Field.prototype.getSourceBlock = function() { +Field.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -315,7 +316,7 @@ Blockly.Field.prototype.getSourceBlock = function() { * methods initModel and initView rather than this method. * @package */ -Blockly.Field.prototype.init = function() { +Field.prototype.init = function() { if (this.fieldGroup_) { // Field has already been initialized once. return; @@ -338,7 +339,7 @@ Blockly.Field.prototype.init = function() { * Create the block UI for this field. * @package */ -Blockly.Field.prototype.initView = function() { +Field.prototype.initView = function() { this.createBorderRect_(); this.createTextElement_(); }; @@ -348,7 +349,7 @@ Blockly.Field.prototype.initView = function() { * No-op by default. * @package */ -Blockly.Field.prototype.initModel = function() { +Field.prototype.initModel = function() { }; /** @@ -357,7 +358,7 @@ Blockly.Field.prototype.initModel = function() { * separate function to call. * @protected */ -Blockly.Field.prototype.createBorderRect_ = function() { +Field.prototype.createBorderRect_ = function() { this.borderRect_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'rx': this.getConstants().FIELD_BORDER_RECT_RADIUS, @@ -376,7 +377,7 @@ Blockly.Field.prototype.createBorderRect_ = function() { * function to call. * @protected */ -Blockly.Field.prototype.createTextElement_ = function() { +Field.prototype.createTextElement_ = function() { this.textElement_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': 'blocklyText', @@ -393,7 +394,7 @@ Blockly.Field.prototype.createTextElement_ = function() { * custom input handling. * @protected */ -Blockly.Field.prototype.bindEvents_ = function() { +Field.prototype.bindEvents_ = function() { Blockly.Tooltip.bindMouseEvents(this.getClickTarget_()); this.mouseDownWrapper_ = Blockly.browserEvents.conditionalBind( this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); @@ -406,7 +407,7 @@ Blockly.Field.prototype.bindEvents_ = function() { * field's state. * @package */ -Blockly.Field.prototype.fromXml = function(fieldElement) { +Field.prototype.fromXml = function(fieldElement) { this.setValue(fieldElement.textContent); }; @@ -417,7 +418,7 @@ Blockly.Field.prototype.fromXml = function(fieldElement) { * @return {!Element} The element containing info about the field's state. * @package */ -Blockly.Field.prototype.toXml = function(fieldElement) { +Field.prototype.toXml = function(fieldElement) { fieldElement.textContent = this.getValue(); return fieldElement; }; @@ -426,7 +427,7 @@ Blockly.Field.prototype.toXml = function(fieldElement) { * Dispose of all DOM objects and events belonging to this editable field. * @package */ -Blockly.Field.prototype.dispose = function() { +Field.prototype.dispose = function() { Blockly.DropDownDiv.hideIfOwner(this); Blockly.WidgetDiv.hideIfOwner(this); Blockly.Tooltip.unbindMouseEvents(this.getClickTarget_()); @@ -443,7 +444,7 @@ Blockly.Field.prototype.dispose = function() { /** * Add or remove the UI indicating if this field is editable or not. */ -Blockly.Field.prototype.updateEditable = function() { +Field.prototype.updateEditable = function() { const group = this.fieldGroup_; if (!this.EDITABLE || !group) { return; @@ -464,7 +465,7 @@ Blockly.Field.prototype.updateEditable = function() { * source block is editable. * @param {boolean} enabled True if enabled. */ -Blockly.Field.prototype.setEnabled = function(enabled) { +Field.prototype.setEnabled = function(enabled) { this.enabled_ = enabled; this.updateEditable(); }; @@ -474,7 +475,7 @@ Blockly.Field.prototype.setEnabled = function(enabled) { * source block is editable. * @return {boolean} Whether this field is enabled. */ -Blockly.Field.prototype.isEnabled = function() { +Field.prototype.isEnabled = function() { return this.enabled_; }; @@ -482,7 +483,7 @@ Blockly.Field.prototype.isEnabled = function() { * Check whether this field defines the showEditor_ function. * @return {boolean} Whether this field is clickable. */ -Blockly.Field.prototype.isClickable = function() { +Field.prototype.isClickable = function() { return this.enabled_ && !!this.sourceBlock_ && this.sourceBlock_.isEditable() && !!this.showEditor_ && (typeof this.showEditor_ === 'function'); @@ -495,7 +496,7 @@ Blockly.Field.prototype.isClickable = function() { * @return {boolean} Whether this field is currently enabled, editable and on * an editable block. */ -Blockly.Field.prototype.isCurrentlyEditable = function() { +Field.prototype.isCurrentlyEditable = function() { return this.enabled_ && this.EDITABLE && !!this.sourceBlock_ && this.sourceBlock_.isEditable(); }; @@ -505,7 +506,7 @@ Blockly.Field.prototype.isCurrentlyEditable = function() { * Handles the logic for backwards compatibility and incongruous states. * @return {boolean} Whether this field should be serialized or not. */ -Blockly.Field.prototype.isSerializable = function() { +Field.prototype.isSerializable = function() { let isSerializable = false; if (this.name) { if (this.SERIALIZABLE) { @@ -524,7 +525,7 @@ Blockly.Field.prototype.isSerializable = function() { * Gets whether this editable field is visible or not. * @return {boolean} True if visible. */ -Blockly.Field.prototype.isVisible = function() { +Field.prototype.isVisible = function() { return this.visible_; }; @@ -534,7 +535,7 @@ Blockly.Field.prototype.isVisible = function() { * @param {boolean} visible True if visible. * @package */ -Blockly.Field.prototype.setVisible = function(visible) { +Field.prototype.setVisible = function(visible) { if (this.visible_ == visible) { return; } @@ -560,7 +561,7 @@ Blockly.Field.prototype.setVisible = function(visible) { * @param {Function} handler The validator function * or null to clear a previous validator. */ -Blockly.Field.prototype.setValidator = function(handler) { +Field.prototype.setValidator = function(handler) { this.validator_ = handler; }; @@ -568,7 +569,7 @@ Blockly.Field.prototype.setValidator = function(handler) { * Gets the validation function for editable fields, or null if not set. * @return {?Function} Validation function, or null. */ -Blockly.Field.prototype.getValidator = function() { +Field.prototype.getValidator = function() { return this.validator_; }; @@ -577,7 +578,7 @@ Blockly.Field.prototype.getValidator = function() { * Used for measuring the size and for positioning. * @return {!SVGGElement} The group element. */ -Blockly.Field.prototype.getSvgRoot = function() { +Field.prototype.getSvgRoot = function() { return /** @type {!SVGGElement} */ (this.fieldGroup_); }; @@ -586,7 +587,7 @@ Blockly.Field.prototype.getSvgRoot = function() { * called by BlockSvg.applyColour(). * @package */ -Blockly.Field.prototype.applyColour = function() { +Field.prototype.applyColour = function() { // Non-abstract sub-classes may wish to implement this. See FieldDropdown. }; @@ -597,7 +598,7 @@ Blockly.Field.prototype.applyColour = function() { * done here, and should be triggered by getSize(). * @protected */ -Blockly.Field.prototype.render_ = function() { +Field.prototype.render_ = function() { if (this.textContent_) { this.textContent_.nodeValue = this.getDisplayText_(); } @@ -610,7 +611,7 @@ Blockly.Field.prototype.render_ = function() { * or undefined if triggered programmatically. * @package */ -Blockly.Field.prototype.showEditor = function(opt_e) { +Field.prototype.showEditor = function(opt_e) { if (this.isClickable()) { this.showEditor_(opt_e); } @@ -621,7 +622,7 @@ Blockly.Field.prototype.showEditor = function(opt_e) { * @param {number=} opt_margin margin to use when positioning the text element. * @protected */ -Blockly.Field.prototype.updateSize_ = function(opt_margin) { +Field.prototype.updateSize_ = function(opt_margin) { const constants = this.getConstants(); const xOffset = opt_margin != undefined ? opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); @@ -654,7 +655,7 @@ Blockly.Field.prototype.updateSize_ = function(opt_margin) { * @param {number} contentWidth The content width. * @protected */ -Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { +Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { if (!this.textElement_) { return; } @@ -672,7 +673,7 @@ Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { * Position a field's border rect after a size change. * @protected */ -Blockly.Field.prototype.positionBorderRect_ = function() { +Field.prototype.positionBorderRect_ = function() { if (!this.borderRect_) { return; } @@ -691,7 +692,7 @@ Blockly.Field.prototype.positionBorderRect_ = function() { * This should *in general* be the only place render_ gets called from. * @return {!Blockly.utils.Size} Height and width. */ -Blockly.Field.prototype.getSize = function() { +Field.prototype.getSize = function() { if (!this.isVisible()) { return new Blockly.utils.Size(0, 0); } @@ -716,7 +717,7 @@ Blockly.Field.prototype.getSize = function() { * pixels relative to the top left corner of the page (window coordinates). * @package */ -Blockly.Field.prototype.getScaledBBox = function() { +Field.prototype.getScaledBBox = function() { let scaledWidth, scaledHeight, xy; if (!this.borderRect_) { // Browsers are inconsistent in what they return for a bounding box. @@ -761,18 +762,18 @@ Blockly.Field.prototype.getScaledBBox = function() { * @return {string} Text to display. * @protected */ -Blockly.Field.prototype.getDisplayText_ = function() { +Field.prototype.getDisplayText_ = function() { let text = this.getText(); if (!text) { // Prevent the field from disappearing if empty. - return Blockly.Field.NBSP; + return Field.NBSP; } if (text.length > this.maxDisplayLength) { // Truncate displayed string and add an ellipsis ('...'). text = text.substring(0, this.maxDisplayLength - 2) + '\u2026'; } // Replace whitespace with non-breaking spaces so the text doesn't collapse. - text = text.replace(/\s/g, Blockly.Field.NBSP); + text = text.replace(/\s/g, Field.NBSP); if (this.sourceBlock_ && this.sourceBlock_.RTL) { // The SVG is LTR, force text to be RTL. text += '\u200F'; @@ -784,7 +785,7 @@ Blockly.Field.prototype.getDisplayText_ = function() { * Get the text from this field. * @return {string} Current text. */ -Blockly.Field.prototype.getText = function() { +Field.prototype.getText = function() { if (this.getText_) { const text = this.getText_.call(this); if (text !== null) { @@ -801,7 +802,7 @@ Blockly.Field.prototype.getText = function() { * already been recorded. * @package */ -Blockly.Field.prototype.markDirty = function() { +Field.prototype.markDirty = function() { this.isDirty_ = true; this.constants_ = null; }; @@ -813,7 +814,7 @@ Blockly.Field.prototype.markDirty = function() { * already been recorded. * @package */ -Blockly.Field.prototype.forceRerender = function() { +Field.prototype.forceRerender = function() { this.isDirty_ = true; if (this.sourceBlock_ && this.sourceBlock_.rendered) { this.sourceBlock_.render(); @@ -828,7 +829,7 @@ Blockly.Field.prototype.forceRerender = function() { * than this method. * @param {*} newValue New value. */ -Blockly.Field.prototype.setValue = function(newValue) { +Field.prototype.setValue = function(newValue) { const doLogging = false; if (newValue === null) { doLogging && console.log('null, return'); @@ -884,7 +885,7 @@ Blockly.Field.prototype.setValue = function(newValue) { * @return {*} New value, or an Error object. * @private */ -Blockly.Field.prototype.processValidation_ = function(newValue, +Field.prototype.processValidation_ = function(newValue, validatedValue) { if (validatedValue === null) { this.doValueInvalid_(newValue); @@ -903,7 +904,7 @@ Blockly.Field.prototype.processValidation_ = function(newValue, * Get the current value of the field. * @return {*} Current value. */ -Blockly.Field.prototype.getValue = function() { +Field.prototype.getValue = function() { return this.value_; }; @@ -914,7 +915,7 @@ Blockly.Field.prototype.getValue = function() { * @return {*} The validated value, same as input by default. * @protected */ -Blockly.Field.prototype.doClassValidation_ = function(opt_newValue) { +Field.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -927,7 +928,7 @@ Blockly.Field.prototype.doClassValidation_ = function(opt_newValue) { * @param {*} newValue The value to be saved. * @protected */ -Blockly.Field.prototype.doValueUpdate_ = function(newValue) { +Field.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; this.isDirty_ = true; }; @@ -939,7 +940,7 @@ Blockly.Field.prototype.doValueUpdate_ = function(newValue) { * @param {*} _invalidValue The input value that was determined to be invalid. * @protected */ -Blockly.Field.prototype.doValueInvalid_ = function(_invalidValue) { +Field.prototype.doValueInvalid_ = function(_invalidValue) { // NOP }; @@ -948,7 +949,7 @@ Blockly.Field.prototype.doValueInvalid_ = function(_invalidValue) { * @param {!Event} e Mouse down event. * @protected */ -Blockly.Field.prototype.onMouseDown_ = function(e) { +Field.prototype.onMouseDown_ = function(e) { if (!this.sourceBlock_ || !this.sourceBlock_.workspace) { return; } @@ -965,7 +966,7 @@ Blockly.Field.prototype.onMouseDown_ = function(e) { * parent object whose tooltip will be used, or null to display the tooltip * of the parent block. To not display a tooltip pass the empty string. */ -Blockly.Field.prototype.setTooltip = function(newTip) { +Field.prototype.setTooltip = function(newTip) { if (!newTip && newTip !== '') { // If null or undefined. newTip = this.sourceBlock_; } @@ -982,7 +983,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { * Returns the tooltip text for this field. * @return {string} The tooltip text for this field. */ -Blockly.Field.prototype.getTooltip = function() { +Field.prototype.getTooltip = function() { const clickTarget = this.getClickTarget_(); if (clickTarget) { return Blockly.Tooltip.getTooltipOfObject(clickTarget); @@ -998,7 +999,7 @@ Blockly.Field.prototype.getTooltip = function() { * @return {!Element} Element to bind click handler to. * @protected */ -Blockly.Field.prototype.getClickTarget_ = function() { +Field.prototype.getClickTarget_ = function() { return this.clickTarget_ || this.getSvgRoot(); }; @@ -1008,7 +1009,7 @@ Blockly.Field.prototype.getClickTarget_ = function() { * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. * @protected */ -Blockly.Field.prototype.getAbsoluteXY_ = function() { +Field.prototype.getAbsoluteXY_ = function() { return Blockly.utils.style.getPageOffset( /** @type {!SVGRectElement} */ (this.getClickTarget_())); }; @@ -1020,7 +1021,7 @@ Blockly.Field.prototype.getAbsoluteXY_ = function() { * @return {boolean} True if this field has any variable references. * @package */ -Blockly.Field.prototype.referencesVariables = function() { +Field.prototype.referencesVariables = function() { return false; }; @@ -1030,7 +1031,7 @@ Blockly.Field.prototype.referencesVariables = function() { * @return {Blockly.Input} The input that the field belongs to. * @package */ -Blockly.Field.prototype.getParentInput = function() { +Field.prototype.getParentInput = function() { let parentInput = null; const block = this.sourceBlock_; const inputs = block.inputList; @@ -1052,7 +1053,7 @@ Blockly.Field.prototype.getParentInput = function() { * Returns whether or not we should flip the field in RTL. * @return {boolean} True if we should flip in RTL. */ -Blockly.Field.prototype.getFlipRtl = function() { +Field.prototype.getFlipRtl = function() { return false; }; @@ -1060,7 +1061,7 @@ Blockly.Field.prototype.getFlipRtl = function() { * Returns whether or not the field is tab navigable. * @return {boolean} True if the field is tab navigable. */ -Blockly.Field.prototype.isTabNavigable = function() { +Field.prototype.isTabNavigable = function() { return false; }; @@ -1070,7 +1071,7 @@ Blockly.Field.prototype.isTabNavigable = function() { * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ -Blockly.Field.prototype.onShortcut = function(_shortcut) { +Field.prototype.onShortcut = function(_shortcut) { return false; }; @@ -1080,7 +1081,7 @@ Blockly.Field.prototype.onShortcut = function(_shortcut) { * field group. * @package */ -Blockly.Field.prototype.setCursorSvg = function(cursorSvg) { +Field.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg_ = null; return; @@ -1096,7 +1097,7 @@ Blockly.Field.prototype.setCursorSvg = function(cursorSvg) { * field group. * @package */ -Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { +Field.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg_ = null; return; @@ -1110,7 +1111,7 @@ Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { * Redraw any attached marker or cursor svgs if needed. * @protected */ -Blockly.Field.prototype.updateMarkers_ = function() { +Field.prototype.updateMarkers_ = function() { const workspace = /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { @@ -1121,3 +1122,5 @@ Blockly.Field.prototype.updateMarkers_ = function() { workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw(); } }; + +exports = Field; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..8d3cef438 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -48,7 +48,7 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); From 00a74e9d37dbc74dd6b479714b8c7a9ca655320c Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:26:28 -0700 Subject: [PATCH 23/48] Migrate core/interfaces/i_registrable_field.js to goog.module --- core/interfaces/i_registrable_field.js | 12 ++++++++---- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 1d49edad2..180599bdb 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -11,21 +11,25 @@ 'use strict'; -goog.provide('Blockly.IRegistrableField'); +goog.module('Blockly.IRegistrableField'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.Field'); + /** * A registrable field. * Note: We are not using an interface here as we are interested in defining the * static methods of a field rather than the instance methods. * @typedef {{ - * fromJson:Blockly.IRegistrableField.fromJson + * fromJson:IRegistrableField.fromJson * }} */ -Blockly.IRegistrableField; +let IRegistrableField; /** * @typedef {function(!Object): Blockly.Field} */ -Blockly.IRegistrableField.fromJson; +IRegistrableField.fromJson; + +exports = IRegistrableField; diff --git a/tests/deps.js b/tests/deps.js index 9a0ae6896..fb0b9793c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -95,7 +95,7 @@ goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetr goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); From 7d946afb4ea7f00f8111444dd828b6c3400122f7 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:26:43 -0700 Subject: [PATCH 24/48] Migrate core/interfaces/i_registrable_field.js named requires --- core/interfaces/i_registrable_field.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 180599bdb..2c8c005bd 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -14,7 +14,7 @@ goog.module('Blockly.IRegistrableField'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.Field'); +const Field = goog.requireType('Blockly.Field'); /** @@ -28,7 +28,7 @@ goog.requireType('Blockly.Field'); let IRegistrableField; /** - * @typedef {function(!Object): Blockly.Field} + * @typedef {function(!Object): Field} */ IRegistrableField.fromJson; From a3ae4f30162f500619325c44f211179a9369cdee Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:41:48 -0700 Subject: [PATCH 25/48] Migrate core/field.js to named requires --- core/field.js | 163 +++++++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 76 deletions(-) diff --git a/core/field.js b/core/field.js index d9db11cbd..37352c64e 100644 --- a/core/field.js +++ b/core/field.js @@ -15,35 +15,46 @@ goog.module('Blockly.Field'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const IASTNodeLocationSvg = goog.require('Blockly.IASTNodeLocationSvg'); +/* eslint-disable-next-line no-unused-vars */ +const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +/* eslint-disable-next-line no-unused-vars */ +const IKeyboardAccessible = goog.require('Blockly.IKeyboardAccessible'); +/* eslint-disable-next-line no-unused-vars */ +const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ +const Input = goog.requireType('Blockly.Input'); +const MarkerManager = goog.require('Blockly.MarkerManager'); +const Rect = goog.require('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ +const ShortcutRegistry = goog.requireType('Blockly.ShortcutRegistry'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const Tooltip = goog.require('Blockly.Tooltip'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {addClass, createSvgElement, getFastTextWidth, removeClass, removeNode} = goog.require('Blockly.utils.dom'); +/* eslint-disable-next-line no-unused-vars */ +const {conditionalBind, unbind, Data} = goog.require('Blockly.browserEvents'); +const {getPageOffset} = goog.require('Blockly.utils.style'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Gesture'); -goog.require('Blockly.IASTNodeLocationSvg'); -goog.require('Blockly.IASTNodeLocationWithBlock'); -goog.require('Blockly.IKeyboardAccessible'); -goog.require('Blockly.IRegistrable'); -goog.require('Blockly.MarkerManager'); -goog.require('Blockly.Tooltip'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.style'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Input'); -goog.requireType('Blockly.ShortcutRegistry'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -57,10 +68,10 @@ goog.requireType('Blockly.WorkspaceSvg'); * parameter supports. * @constructor * @abstract - * @implements {Blockly.IASTNodeLocationSvg} - * @implements {Blockly.IASTNodeLocationWithBlock} - * @implements {Blockly.IKeyboardAccessible} - * @implements {Blockly.IRegistrable} + * @implements {IASTNodeLocationSvg} + * @implements {IASTNodeLocationWithBlock} + * @implements {IKeyboardAccessible} + * @implements {IRegistrable} */ const Field = function(value, opt_validator, opt_config) { /** @@ -81,17 +92,17 @@ const Field = function(value, opt_validator, opt_config) { /** * Used to cache the field's tooltip value if setTooltip is called when the * field is not yet initialized. Is *not* guaranteed to be accurate. - * @type {?Blockly.Tooltip.TipInfo} + * @type {?Tooltip.TipInfo} * @private */ this.tooltip_ = null; /** * The size of the area rendered by the field. - * @type {!Blockly.utils.Size} + * @type {!Size} * @protected */ - this.size_ = new Blockly.utils.Size(0, 0); + this.size_ = new Size(0, 0); /** * Holds the cursors svg element when the cursor is attached to the field. @@ -139,14 +150,14 @@ const Field = function(value, opt_validator, opt_config) { /** * Mouse down event listener data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseDownWrapper_ = null; /** * Constants associated with the source block's renderer. - * @type {Blockly.blockRendering.ConstantProvider} + * @type {ConstantProvider} * @protected */ this.constants_ = null; @@ -185,7 +196,7 @@ Field.prototype.maxDisplayLength = 50; /** * Block this field is attached to. Starts as null, then set in init. - * @type {Blockly.Block} + * @type {Block} * @protected */ Field.prototype.sourceBlock_ = null; @@ -270,7 +281,7 @@ Field.prototype.SERIALIZABLE = false; Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { - tooltip = Blockly.utils.replaceMessageReferences( + tooltip = replaceMessageReferences( config['tooltip']); } tooltip && this.setTooltip(tooltip); @@ -281,7 +292,7 @@ Field.prototype.configure_ = function(config) { /** * Attach this field to a block. - * @param {!Blockly.Block} block The block containing this field. + * @param {!Block} block The block containing this field. */ Field.prototype.setSourceBlock = function(block) { if (this.sourceBlock_) { @@ -292,7 +303,7 @@ Field.prototype.setSourceBlock = function(block) { /** * Get the renderer constant provider. - * @return {?Blockly.blockRendering.ConstantProvider} The renderer constant + * @return {?ConstantProvider} The renderer constant * provider. */ Field.prototype.getConstants = function() { @@ -305,7 +316,7 @@ Field.prototype.getConstants = function() { /** * Get the block this field is attached to. - * @return {Blockly.Block} The block containing this field. + * @return {Block} The block containing this field. */ Field.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -321,12 +332,12 @@ Field.prototype.init = function() { // Field has already been initialized once. return; } - this.fieldGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, {}, null); + this.fieldGroup_ = createSvgElement( + Svg.G, {}, null); if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } - const sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); + const sourceBlockSvg = /** @type {!BlockSvg} **/ (this.sourceBlock_); sourceBlockSvg.getSvgRoot().appendChild(this.fieldGroup_); this.initView(); this.updateEditable(); @@ -359,8 +370,8 @@ Field.prototype.initModel = function() { * @protected */ Field.prototype.createBorderRect_ = function() { - this.borderRect_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, { + this.borderRect_ = createSvgElement( + Svg.RECT, { 'rx': this.getConstants().FIELD_BORDER_RECT_RADIUS, 'ry': this.getConstants().FIELD_BORDER_RECT_RADIUS, 'x': 0, @@ -378,8 +389,8 @@ Field.prototype.createBorderRect_ = function() { * @protected */ Field.prototype.createTextElement_ = function() { - this.textElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, { + this.textElement_ = createSvgElement( + Svg.TEXT, { 'class': 'blocklyText', }, this.fieldGroup_); if (this.getConstants().FIELD_TEXT_BASELINE_CENTER) { @@ -395,8 +406,8 @@ Field.prototype.createTextElement_ = function() { * @protected */ Field.prototype.bindEvents_ = function() { - Blockly.Tooltip.bindMouseEvents(this.getClickTarget_()); - this.mouseDownWrapper_ = Blockly.browserEvents.conditionalBind( + Tooltip.bindMouseEvents(this.getClickTarget_()); + this.mouseDownWrapper_ = conditionalBind( this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); }; @@ -428,15 +439,15 @@ Field.prototype.toXml = function(fieldElement) { * @package */ Field.prototype.dispose = function() { - Blockly.DropDownDiv.hideIfOwner(this); - Blockly.WidgetDiv.hideIfOwner(this); - Blockly.Tooltip.unbindMouseEvents(this.getClickTarget_()); + DropDownDiv.hideIfOwner(this); + WidgetDiv.hideIfOwner(this); + Tooltip.unbindMouseEvents(this.getClickTarget_()); if (this.mouseDownWrapper_) { - Blockly.browserEvents.unbind(this.mouseDownWrapper_); + unbind(this.mouseDownWrapper_); } - Blockly.utils.dom.removeNode(this.fieldGroup_); + removeNode(this.fieldGroup_); this.disposed = true; }; @@ -450,12 +461,12 @@ Field.prototype.updateEditable = function() { return; } if (this.enabled_ && this.sourceBlock_.isEditable()) { - Blockly.utils.dom.addClass(group, 'blocklyEditableText'); - Blockly.utils.dom.removeClass(group, 'blocklyNonEditableText'); + addClass(group, 'blocklyEditableText'); + removeClass(group, 'blocklyNonEditableText'); group.style.cursor = this.CURSOR; } else { - Blockly.utils.dom.addClass(group, 'blocklyNonEditableText'); - Blockly.utils.dom.removeClass(group, 'blocklyEditableText'); + addClass(group, 'blocklyNonEditableText'); + removeClass(group, 'blocklyEditableText'); group.style.cursor = ''; } }; @@ -631,7 +642,7 @@ Field.prototype.updateSize_ = function(opt_margin) { let contentWidth = 0; if (this.textElement_) { - contentWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + contentWidth = getFastTextWidth(this.textElement_, constants.FIELD_TEXT_FONTSIZE, constants.FIELD_TEXT_FONTWEIGHT, constants.FIELD_TEXT_FONTFAMILY); @@ -690,11 +701,11 @@ Field.prototype.positionBorderRect_ = function() { * Returns the height and width of the field. * * This should *in general* be the only place render_ gets called from. - * @return {!Blockly.utils.Size} Height and width. + * @return {!Size} Height and width. */ Field.prototype.getSize = function() { if (!this.isVisible()) { - return new Blockly.utils.Size(0, 0); + return new Size(0, 0); } if (this.isDirty_) { @@ -713,7 +724,7 @@ Field.prototype.getSize = function() { /** * Returns the bounding box of the rendered field, accounting for workspace * scaling. - * @return {!Blockly.utils.Rect} An object with top, bottom, left, and right in + * @return {!Rect} An object with top, bottom, left, and right in * pixels relative to the top left corner of the page (window coordinates). * @package */ @@ -729,13 +740,13 @@ Field.prototype.getScaledBBox = function() { scaledWidth = bBox.width * scale; scaledHeight = bBox.height * scale; - if (Blockly.utils.userAgent.GECKO) { + if (userAgent.GECKO) { xy.x += 1.5 * scale; xy.y += 1.5 * scale; scaledWidth += 1 * scale; scaledHeight += 1 * scale; } else { - if (!Blockly.utils.userAgent.EDGE && !Blockly.utils.userAgent.IE) { + if (!userAgent.EDGE && !userAgent.IE) { xy.x -= 0.5 * scale; xy.y -= 0.5 * scale; } @@ -744,11 +755,11 @@ Field.prototype.getScaledBBox = function() { } } else { const bBox = this.borderRect_.getBoundingClientRect(); - xy = Blockly.utils.style.getPageOffset(this.borderRect_); + xy = getPageOffset(this.borderRect_); scaledWidth = bBox.width; scaledHeight = bBox.height; } - return new Blockly.utils.Rect( + return new Rect( xy.y, xy.y + scaledHeight, xy.x, @@ -867,8 +878,8 @@ Field.prototype.setValue = function(newValue) { return; } - if (source && Blockly.Events.isEnabled()) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + if (source && Events.isEnabled()) { + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( source, 'field', this.name || null, oldValue, newValue)); } this.doValueUpdate_(newValue); @@ -961,7 +972,7 @@ Field.prototype.onMouseDown_ = function(e) { /** * Sets the tooltip for this field. - * @param {?Blockly.Tooltip.TipInfo} newTip The + * @param {?Tooltip.TipInfo} newTip The * text for the tooltip, a function that returns the text for the tooltip, a * parent object whose tooltip will be used, or null to display the tooltip * of the parent block. To not display a tooltip pass the empty string. @@ -986,10 +997,10 @@ Field.prototype.setTooltip = function(newTip) { Field.prototype.getTooltip = function() { const clickTarget = this.getClickTarget_(); if (clickTarget) { - return Blockly.Tooltip.getTooltipOfObject(clickTarget); + return Tooltip.getTooltipOfObject(clickTarget); } // Field has not been initialized yet. Return stashed this.tooltip_ value. - return Blockly.Tooltip.getTooltipOfObject({tooltip: this.tooltip_}); + return Tooltip.getTooltipOfObject({tooltip: this.tooltip_}); }; /** @@ -1006,11 +1017,11 @@ Field.prototype.getClickTarget_ = function() { /** * Return the absolute coordinates of the top-left corner of this field. * The origin (0,0) is the top-left corner of the page body. - * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. + * @return {!Coordinate} Object with .x and .y properties. * @protected */ Field.prototype.getAbsoluteXY_ = function() { - return Blockly.utils.style.getPageOffset( + return getPageOffset( /** @type {!SVGRectElement} */ (this.getClickTarget_())); }; @@ -1028,7 +1039,7 @@ Field.prototype.referencesVariables = function() { /** * Search through the list of inputs and their fields in order to find the * parent input of a field. - * @return {Blockly.Input} The input that the field belongs to. + * @return {Input} The input that the field belongs to. * @package */ Field.prototype.getParentInput = function() { @@ -1067,7 +1078,7 @@ Field.prototype.isTabNavigable = function() { /** * Handles the given keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ @@ -1113,13 +1124,13 @@ Field.prototype.setMarkerSvg = function(markerSvg) { */ Field.prototype.updateMarkers_ = function() { const workspace = - /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); + /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); } if (workspace.keyboardAccessibilityMode && this.markerSvg_) { // TODO(#4592): Update all markers on the field. - workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw(); + workspace.getMarker(MarkerManager.LOCAL_MARKER).draw(); } }; From edcfc04da15db66184f8ace8f3f2ce026b7c31c2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:45:32 -0700 Subject: [PATCH 26/48] clang-format core/field.js --- core/field.js | 74 +++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/core/field.js b/core/field.js index 37352c64e..926e62008 100644 --- a/core/field.js +++ b/core/field.js @@ -281,8 +281,7 @@ Field.prototype.SERIALIZABLE = false; Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { - tooltip = replaceMessageReferences( - config['tooltip']); + tooltip = replaceMessageReferences(config['tooltip']); } tooltip && this.setTooltip(tooltip); @@ -332,8 +331,7 @@ Field.prototype.init = function() { // Field has already been initialized once. return; } - this.fieldGroup_ = createSvgElement( - Svg.G, {}, null); + this.fieldGroup_ = createSvgElement(Svg.G, {}, null); if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } @@ -360,8 +358,7 @@ Field.prototype.initView = function() { * No-op by default. * @package */ -Field.prototype.initModel = function() { -}; +Field.prototype.initModel = function() {}; /** * Create a field border rect element. Not to be overridden by subclasses. @@ -379,7 +376,8 @@ Field.prototype.createBorderRect_ = function() { 'height': this.size_.height, 'width': this.size_.width, 'class': 'blocklyFieldRect' - }, this.fieldGroup_); + }, + this.fieldGroup_); }; /** @@ -392,7 +390,8 @@ Field.prototype.createTextElement_ = function() { this.textElement_ = createSvgElement( Svg.TEXT, { 'class': 'blocklyText', - }, this.fieldGroup_); + }, + this.fieldGroup_); if (this.getConstants().FIELD_TEXT_BASELINE_CENTER) { this.textElement_.setAttribute('dominant-baseline', 'central'); } @@ -523,9 +522,10 @@ Field.prototype.isSerializable = function() { if (this.SERIALIZABLE) { isSerializable = true; } else if (this.EDITABLE) { - console.warn('Detected an editable field that was not serializable.' + - ' Please define SERIALIZABLE property as true on all editable custom' + - ' fields. Proceeding with serialization.'); + console.warn( + 'Detected an editable field that was not serializable.' + + ' Please define SERIALIZABLE property as true on all editable custom' + + ' fields. Proceeding with serialization.'); isSerializable = true; } } @@ -635,17 +635,17 @@ Field.prototype.showEditor = function(opt_e) { */ Field.prototype.updateSize_ = function(opt_margin) { const constants = this.getConstants(); - const xOffset = opt_margin != undefined ? opt_margin : + const xOffset = opt_margin != undefined ? + opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); let totalWidth = xOffset * 2; let totalHeight = constants.FIELD_TEXT_HEIGHT; let contentWidth = 0; if (this.textElement_) { - contentWidth = getFastTextWidth(this.textElement_, - constants.FIELD_TEXT_FONTSIZE, - constants.FIELD_TEXT_FONTWEIGHT, - constants.FIELD_TEXT_FONTFAMILY); + contentWidth = getFastTextWidth( + this.textElement_, constants.FIELD_TEXT_FONTSIZE, + constants.FIELD_TEXT_FONTWEIGHT, constants.FIELD_TEXT_FONTFAMILY); totalWidth += contentWidth; } if (this.borderRect_) { @@ -673,11 +673,15 @@ Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { const constants = this.getConstants(); const halfHeight = this.size_.height / 2; - this.textElement_.setAttribute('x', this.sourceBlock_.RTL ? - this.size_.width - contentWidth - xOffset : xOffset); - this.textElement_.setAttribute('y', constants.FIELD_TEXT_BASELINE_CENTER ? - halfHeight : halfHeight - constants.FIELD_TEXT_HEIGHT / 2 + - constants.FIELD_TEXT_BASELINE); + this.textElement_.setAttribute( + 'x', + this.sourceBlock_.RTL ? this.size_.width - contentWidth - xOffset : + xOffset); + this.textElement_.setAttribute( + 'y', + constants.FIELD_TEXT_BASELINE_CENTER ? halfHeight : + halfHeight - + constants.FIELD_TEXT_HEIGHT / 2 + constants.FIELD_TEXT_BASELINE); }; /** @@ -690,10 +694,10 @@ Field.prototype.positionBorderRect_ = function() { } this.borderRect_.setAttribute('width', this.size_.width); this.borderRect_.setAttribute('height', this.size_.height); - this.borderRect_.setAttribute('rx', - this.getConstants().FIELD_BORDER_RECT_RADIUS); - this.borderRect_.setAttribute('ry', - this.getConstants().FIELD_BORDER_RECT_RADIUS); + this.borderRect_.setAttribute( + 'rx', this.getConstants().FIELD_BORDER_RECT_RADIUS); + this.borderRect_.setAttribute( + 'ry', this.getConstants().FIELD_BORDER_RECT_RADIUS); }; @@ -714,8 +718,9 @@ Field.prototype.getSize = function() { } else if (this.visible_ && this.size_.width == 0) { // If the field is not visible the width will be 0 as well, one of the // problems with the old system. - console.warn('Deprecated use of setting size_.width to 0 to rerender a' + - ' field. Set field.isDirty_ to true instead.'); + console.warn( + 'Deprecated use of setting size_.width to 0 to rerender a' + + ' field. Set field.isDirty_ to true instead.'); this.render_(); } return this.size_; @@ -759,12 +764,7 @@ Field.prototype.getScaledBBox = function() { scaledWidth = bBox.width; scaledHeight = bBox.height; } - return new Rect( - xy.y, - xy.y + scaledHeight, - xy.x, - xy.x + scaledWidth - ); + return new Rect(xy.y, xy.y + scaledHeight, xy.x, xy.x + scaledWidth); }; /** @@ -896,8 +896,7 @@ Field.prototype.setValue = function(newValue) { * @return {*} New value, or an Error object. * @private */ -Field.prototype.processValidation_ = function(newValue, - validatedValue) { +Field.prototype.processValidation_ = function(newValue, validatedValue) { if (validatedValue === null) { this.doValueInvalid_(newValue); if (this.isDirty_) { @@ -1078,7 +1077,8 @@ Field.prototype.isTabNavigable = function() { /** * Handles the given keyboard shortcut. - * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be + * handled. * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ @@ -1124,7 +1124,7 @@ Field.prototype.setMarkerSvg = function(markerSvg) { */ Field.prototype.updateMarkers_ = function() { const workspace = - /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); + /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); } From 5f305041a9de4108a00535060cb1df3b54a8aa34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 12:57:19 -0700 Subject: [PATCH 27/48] Migrate core/field_colour.js to ES6 const/let --- core/field_colour.js | 58 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 17d593f0e..632bf6965 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -233,7 +233,7 @@ Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { * @return {string} Text representing the value of this field. */ Blockly.FieldColour.prototype.getText = function() { - var colour = /** @type {string} */ (this.value_); + let colour = /** @type {string} */ (this.value_); // Try to use #rgb format if possible, rather than #rrggbb. if (/^#(.)\1(.)\2(.)\3$/.test(colour)) { colour = '#' + colour[1] + colour[3] + colour[5]; @@ -339,8 +339,8 @@ Blockly.FieldColour.prototype.showEditor_ = function() { * @private */ Blockly.FieldColour.prototype.onClick_ = function(e) { - var cell = /** @type {!Element} */ (e.target); - var colour = cell && cell.label; + const cell = /** @type {!Element} */ (e.target); + const colour = cell && cell.label; if (colour !== null) { this.setValue(colour); Blockly.DropDownDiv.hideIfOwner(this); @@ -354,7 +354,7 @@ Blockly.FieldColour.prototype.onClick_ = function(e) { * @private */ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { - var handled = false; + let handled = false; if (e.keyCode === Blockly.utils.KeyCodes.UP) { this.moveHighlightBy_(0, -1); handled = true; @@ -369,9 +369,9 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { handled = true; } else if (e.keyCode === Blockly.utils.KeyCodes.ENTER) { // Select the highlighted colour. - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { - var colour = highlighted && highlighted.label; + const colour = highlighted && highlighted.label; if (colour !== null) { this.setValue(colour); } @@ -391,12 +391,12 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { * @private */ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { - var colours = this.colours_ || Blockly.FieldColour.COLOURS; - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const colours = this.colours_ || Blockly.FieldColour.COLOURS; + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; // Get the current x and y coordinates - var x = this.highlightedIndex_ % columns; - var y = Math.floor(this.highlightedIndex_ / columns); + let x = this.highlightedIndex_ % columns; + let y = Math.floor(this.highlightedIndex_ / columns); // Add the offset x += dx; @@ -434,8 +434,8 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } // Move the highlight to the new coordinates. - var cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); - var index = (y * columns) + x; + const cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); + const index = (y * columns) + x; this.setHighlightedCell_(cell, index); }; @@ -445,8 +445,8 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { * @private */ Blockly.FieldColour.prototype.onMouseMove_ = function(e) { - var cell = /** @type {!Element} */ (e.target); - var index = cell && Number(cell.getAttribute('data-index')); + const cell = /** @type {!Element} */ (e.target); + const index = cell && Number(cell.getAttribute('data-index')); if (index !== null && index !== this.highlightedIndex_) { this.setHighlightedCell_(cell, index); } @@ -467,7 +467,7 @@ Blockly.FieldColour.prototype.onMouseEnter_ = function() { */ Blockly.FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); } @@ -479,14 +479,14 @@ Blockly.FieldColour.prototype.onMouseLeave_ = function() { * @private */ Blockly.FieldColour.prototype.getHighlighted_ = function() { - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; - var x = this.highlightedIndex_ % columns; - var y = Math.floor(this.highlightedIndex_ / columns); - var row = this.picker_.childNodes[y]; + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const x = this.highlightedIndex_ % columns; + const y = Math.floor(this.highlightedIndex_ / columns); + const row = this.picker_.childNodes[y]; if (!row) { return null; } - var col = /** @type {HTMLElement} */ (row.childNodes[x]); + const col = /** @type {HTMLElement} */ (row.childNodes[x]); return col; }; @@ -498,7 +498,7 @@ Blockly.FieldColour.prototype.getHighlighted_ = function() { */ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); } @@ -517,12 +517,12 @@ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { * @private */ Blockly.FieldColour.prototype.dropdownCreate_ = function() { - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; - var colours = this.colours_ || Blockly.FieldColour.COLOURS; - var titles = this.titles_ || Blockly.FieldColour.TITLES; - var selectedColour = this.getValue(); + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const colours = this.colours_ || Blockly.FieldColour.COLOURS; + const titles = this.titles_ || Blockly.FieldColour.TITLES; + const selectedColour = this.getValue(); // Create the palette. - var table = document.createElement('table'); + const table = document.createElement('table'); table.className = 'blocklyColourTable'; table.tabIndex = 0; table.dir = 'ltr'; @@ -532,14 +532,14 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { Math.floor(colours.length / columns)); Blockly.utils.aria.setState(table, Blockly.utils.aria.State.COLCOUNT, columns); - var row; - for (var i = 0; i < colours.length; i++) { + let row; + for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { row = document.createElement('tr'); Blockly.utils.aria.setRole(row, Blockly.utils.aria.Role.ROW); table.appendChild(row); } - var cell = document.createElement('td'); + const cell = document.createElement('td'); row.appendChild(cell); cell.label = colours[i]; // This becomes the value, if clicked. cell.title = titles[i] || colours[i]; From 03e1725f3244bfbedc9934b2ca339f73cbfcb646 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:00:05 -0700 Subject: [PATCH 28/48] Migrate core/field_colour.js to goog.module --- core/field_colour.js | 99 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 632bf6965..9d342150c 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldColour'); +goog.module('Blockly.FieldColour'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); @@ -41,8 +42,8 @@ goog.require('Blockly.utils.Size'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldColour = function(opt_value, opt_validator, opt_config) { - Blockly.FieldColour.superClass_.constructor.call( +const FieldColour = function(opt_value, opt_validator, opt_config) { + FieldColour.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); /** @@ -94,16 +95,16 @@ Blockly.FieldColour = function(opt_value, opt_validator, opt_config) { */ this.onKeyDownWrapper_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldColour, Blockly.Field); +Blockly.utils.object.inherits(FieldColour, Blockly.Field); /** * Construct a FieldColour from a JSON arg object. * @param {!Object} options A JSON object with options (colour). - * @return {!Blockly.FieldColour} The new field instance. + * @return {!FieldColour} The new field instance. * @package * @nocollapse */ -Blockly.FieldColour.fromJson = function(options) { +FieldColour.fromJson = function(options) { // `this` might be a subclass of FieldColour if that class doesn't override // the static fromJson method. return new this(options['colour'], undefined, options); @@ -114,12 +115,12 @@ Blockly.FieldColour.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldColour.prototype.SERIALIZABLE = true; +FieldColour.prototype.SERIALIZABLE = true; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldColour.prototype.CURSOR = 'default'; +FieldColour.prototype.CURSOR = 'default'; /** * Used to tell if the field needs to be rendered the next time the block is @@ -128,21 +129,21 @@ Blockly.FieldColour.prototype.CURSOR = 'default'; * @type {boolean} * @protected */ -Blockly.FieldColour.prototype.isDirty_ = false; +FieldColour.prototype.isDirty_ = false; /** * Array of colours used by this field. If null, use the global list. * @type {Array} * @private */ -Blockly.FieldColour.prototype.colours_ = null; +FieldColour.prototype.colours_ = null; /** * Array of colour tooltips used by this field. If null, use the global list. * @type {Array} * @private */ -Blockly.FieldColour.prototype.titles_ = null; +FieldColour.prototype.titles_ = null; /** * Number of colour columns used by this field. If 0, use the global setting. @@ -150,7 +151,7 @@ Blockly.FieldColour.prototype.titles_ = null; * @type {number} * @private */ -Blockly.FieldColour.prototype.columns_ = 0; +FieldColour.prototype.columns_ = 0; /** * Configure the field based on the given map of options. @@ -158,8 +159,8 @@ Blockly.FieldColour.prototype.columns_ = 0; * @protected * @override */ -Blockly.FieldColour.prototype.configure_ = function(config) { - Blockly.FieldColour.superClass_.configure_.call(this, config); +FieldColour.prototype.configure_ = function(config) { + FieldColour.superClass_.configure_.call(this, config); if (config['colourOptions']) { this.colours_ = config['colourOptions']; this.titles_ = config['colourTitles']; @@ -173,7 +174,7 @@ Blockly.FieldColour.prototype.configure_ = function(config) { * Create the block UI for this colour field. * @package */ -Blockly.FieldColour.prototype.initView = function() { +FieldColour.prototype.initView = function() { this.size_ = new Blockly.utils.Size( this.getConstants().FIELD_COLOUR_DEFAULT_WIDTH, this.getConstants().FIELD_COLOUR_DEFAULT_HEIGHT); @@ -188,7 +189,7 @@ Blockly.FieldColour.prototype.initView = function() { /** * @override */ -Blockly.FieldColour.prototype.applyColour = function() { +FieldColour.prototype.applyColour = function() { if (!this.getConstants().FIELD_COLOUR_FULL_BLOCK) { if (this.borderRect_) { this.borderRect_.style.fill = /** @type {string} */ (this.getValue()); @@ -205,7 +206,7 @@ Blockly.FieldColour.prototype.applyColour = function() { * @return {?string} A valid colour, or null if invalid. * @protected */ -Blockly.FieldColour.prototype.doClassValidation_ = function(opt_newValue) { +FieldColour.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } @@ -218,7 +219,7 @@ Blockly.FieldColour.prototype.doClassValidation_ = function(opt_newValue) { * that this is a colour in '#rrggbb' format. * @protected */ -Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { +FieldColour.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.borderRect_) { this.borderRect_.style.fill = /** @type {string} */ (newValue); @@ -232,7 +233,7 @@ Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { * Get the text for this field. Used when the block is collapsed. * @return {string} Text representing the value of this field. */ -Blockly.FieldColour.prototype.getText = function() { +FieldColour.prototype.getText = function() { let colour = /** @type {string} */ (this.value_); // Try to use #rgb format if possible, rather than #rrggbb. if (/^#(.)\1(.)\2(.)\3$/.test(colour)) { @@ -247,7 +248,7 @@ Blockly.FieldColour.prototype.getText = function() { * All colour pickers use this unless overridden with setColours. * @type {!Array} */ -Blockly.FieldColour.COLOURS = [ +FieldColour.COLOURS = [ // grays '#ffffff', '#cccccc', '#c0c0c0', '#999999', '#666666', '#333333', '#000000', // reds @@ -275,7 +276,7 @@ Blockly.FieldColour.COLOURS = [ * @type {*} * @protected */ -Blockly.FieldColour.prototype.DEFAULT_VALUE = Blockly.FieldColour.COLOURS[0]; +FieldColour.prototype.DEFAULT_VALUE = FieldColour.COLOURS[0]; /** * An array of tooltip strings for the palette. If not the same length as @@ -283,23 +284,23 @@ Blockly.FieldColour.prototype.DEFAULT_VALUE = Blockly.FieldColour.COLOURS[0]; * All colour pickers use this unless overridden with setColours. * @type {!Array} */ -Blockly.FieldColour.TITLES = []; +FieldColour.TITLES = []; /** * Number of columns in the palette. * All colour pickers use this unless overridden with setColumns. */ -Blockly.FieldColour.COLUMNS = 7; +FieldColour.COLUMNS = 7; /** * Set a custom colour grid for this field. * @param {Array} colours Array of colours for this block, - * or null to use default (Blockly.FieldColour.COLOURS). + * or null to use default (FieldColour.COLOURS). * @param {Array=} opt_titles Optional array of colour tooltips, - * or null to use default (Blockly.FieldColour.TITLES). - * @return {!Blockly.FieldColour} Returns itself (for method chaining). + * or null to use default (FieldColour.TITLES). + * @return {!FieldColour} Returns itself (for method chaining). */ -Blockly.FieldColour.prototype.setColours = function(colours, opt_titles) { +FieldColour.prototype.setColours = function(colours, opt_titles) { this.colours_ = colours; if (opt_titles) { this.titles_ = opt_titles; @@ -310,10 +311,10 @@ Blockly.FieldColour.prototype.setColours = function(colours, opt_titles) { /** * Set a custom grid size for this field. * @param {number} columns Number of columns for this block, - * or 0 to use default (Blockly.FieldColour.COLUMNS). - * @return {!Blockly.FieldColour} Returns itself (for method chaining). + * or 0 to use default (FieldColour.COLUMNS). + * @return {!FieldColour} Returns itself (for method chaining). */ -Blockly.FieldColour.prototype.setColumns = function(columns) { +FieldColour.prototype.setColumns = function(columns) { this.columns_ = columns; return this; }; @@ -322,7 +323,7 @@ Blockly.FieldColour.prototype.setColumns = function(columns) { * Create and show the colour field's editor. * @protected */ -Blockly.FieldColour.prototype.showEditor_ = function() { +FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); Blockly.DropDownDiv.getContentDiv().appendChild(this.picker_); @@ -338,7 +339,7 @@ Blockly.FieldColour.prototype.showEditor_ = function() { * @param {!MouseEvent} e Mouse event. * @private */ -Blockly.FieldColour.prototype.onClick_ = function(e) { +FieldColour.prototype.onClick_ = function(e) { const cell = /** @type {!Element} */ (e.target); const colour = cell && cell.label; if (colour !== null) { @@ -353,7 +354,7 @@ Blockly.FieldColour.prototype.onClick_ = function(e) { * @param {!KeyboardEvent} e Keyboard event. * @private */ -Blockly.FieldColour.prototype.onKeyDown_ = function(e) { +FieldColour.prototype.onKeyDown_ = function(e) { let handled = false; if (e.keyCode === Blockly.utils.KeyCodes.UP) { this.moveHighlightBy_(0, -1); @@ -390,9 +391,9 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { * @param {number} dy Change of y * @private */ -Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { - const colours = this.colours_ || Blockly.FieldColour.COLOURS; - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; +FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { + const colours = this.colours_ || FieldColour.COLOURS; + const columns = this.columns_ || FieldColour.COLUMNS; // Get the current x and y coordinates let x = this.highlightedIndex_ % columns; @@ -444,7 +445,7 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { * @param {!MouseEvent} e Mouse event. * @private */ -Blockly.FieldColour.prototype.onMouseMove_ = function(e) { +FieldColour.prototype.onMouseMove_ = function(e) { const cell = /** @type {!Element} */ (e.target); const index = cell && Number(cell.getAttribute('data-index')); if (index !== null && index !== this.highlightedIndex_) { @@ -456,7 +457,7 @@ Blockly.FieldColour.prototype.onMouseMove_ = function(e) { * Handle a mouse enter event. Focus the picker. * @private */ -Blockly.FieldColour.prototype.onMouseEnter_ = function() { +FieldColour.prototype.onMouseEnter_ = function() { this.picker_.focus({preventScroll:true}); }; @@ -465,7 +466,7 @@ Blockly.FieldColour.prototype.onMouseEnter_ = function() { * the currently highlighted colour. * @private */ -Blockly.FieldColour.prototype.onMouseLeave_ = function() { +FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); const highlighted = this.getHighlighted_(); if (highlighted) { @@ -478,8 +479,8 @@ Blockly.FieldColour.prototype.onMouseLeave_ = function() { * @return {?HTMLElement} Highlighted item (null if none). * @private */ -Blockly.FieldColour.prototype.getHighlighted_ = function() { - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; +FieldColour.prototype.getHighlighted_ = function() { + const columns = this.columns_ || FieldColour.COLUMNS; const x = this.highlightedIndex_ % columns; const y = Math.floor(this.highlightedIndex_ / columns); const row = this.picker_.childNodes[y]; @@ -496,7 +497,7 @@ Blockly.FieldColour.prototype.getHighlighted_ = function() { * @param {number} index the index of the new cell * @private */ -Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { +FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. const highlighted = this.getHighlighted_(); if (highlighted) { @@ -516,10 +517,10 @@ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { * Create a colour picker dropdown editor. * @private */ -Blockly.FieldColour.prototype.dropdownCreate_ = function() { - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; - const colours = this.colours_ || Blockly.FieldColour.COLOURS; - const titles = this.titles_ || Blockly.FieldColour.TITLES; +FieldColour.prototype.dropdownCreate_ = function() { + const columns = this.columns_ || FieldColour.COLUMNS; + const colours = this.colours_ || FieldColour.COLOURS; + const titles = this.titles_ || FieldColour.TITLES; const selectedColour = this.getValue(); // Create the palette. const table = document.createElement('table'); @@ -576,7 +577,7 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { * Disposes of events and DOM-references belonging to the colour editor. * @private */ -Blockly.FieldColour.prototype.dropdownDispose_ = function() { +FieldColour.prototype.dropdownDispose_ = function() { if (this.onClickWrapper_) { Blockly.browserEvents.unbind(this.onClickWrapper_); this.onClickWrapper_ = null; @@ -637,4 +638,6 @@ Blockly.Css.register([ /* eslint-enable indent */ ]); -Blockly.fieldRegistry.register('field_colour', Blockly.FieldColour); +Blockly.fieldRegistry.register('field_colour', FieldColour); + +exports = FieldColour; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..0e33cec9b 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -51,7 +51,7 @@ goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); From ba30031d366e2b7f9af77f1be01c433487d76842 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:13:31 -0700 Subject: [PATCH 29/48] Migrate core/field_colour.js to named requires --- core/field_colour.js | 119 ++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 9d342150c..879c340bc 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -13,20 +13,21 @@ goog.module('Blockly.FieldColour'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.Css'); -goog.require('Blockly.DropDownDiv'); +const Css = goog.require('Blockly.Css'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Field = goog.require('Blockly.Field'); +const IdGenerator = goog.require('Blockly.utils.IdGenerator'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Size = goog.require('Blockly.utils.Size'); +const aria = goog.require('Blockly.utils.aria'); +const colour = goog.require('Blockly.utils.colour'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {addClass, removeClass} = goog.require('Blockly.utils.dom'); +/* eslint-disable-next-line no-unused-vars */ +const {conditionalBind, unbind, Data} = goog.require('Blockly.browserEvents'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.colour'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.IdGenerator'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); /** @@ -35,11 +36,11 @@ goog.require('Blockly.utils.Size'); * '#rrggbb' format. Defaults to the first value in the default colour array. * @param {Function=} opt_validator A function that is called to validate * changes to the field's value. Takes in a colour string & returns a - * validated colour string ('#rrggbb' format), or null to abort the change. + * validated colour string ('#rrggbb' format), or null to abort the change.Blockly. * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldColour = function(opt_value, opt_validator, opt_config) { @@ -62,40 +63,40 @@ const FieldColour = function(opt_value, opt_validator, opt_config) { /** * Mouse click event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onClickWrapper_ = null; /** * Mouse move event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseMoveWrapper_ = null; /** * Mouse enter event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseEnterWrapper_ = null; /** * Mouse leave event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseLeaveWrapper_ = null; /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onKeyDownWrapper_ = null; }; -Blockly.utils.object.inherits(FieldColour, Blockly.Field); +inherits(FieldColour, Field); /** * Construct a FieldColour from a JSON arg object. @@ -175,7 +176,7 @@ FieldColour.prototype.configure_ = function(config) { * @package */ FieldColour.prototype.initView = function() { - this.size_ = new Blockly.utils.Size( + this.size_ = new Size( this.getConstants().FIELD_COLOUR_DEFAULT_WIDTH, this.getConstants().FIELD_COLOUR_DEFAULT_HEIGHT); if (!this.getConstants().FIELD_COLOUR_FULL_BLOCK) { @@ -210,7 +211,7 @@ FieldColour.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } - return Blockly.utils.colour.parse(opt_newValue); + return colour.parse(opt_newValue); }; /** @@ -325,9 +326,9 @@ FieldColour.prototype.setColumns = function(columns) { */ FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); - Blockly.DropDownDiv.getContentDiv().appendChild(this.picker_); + DropDownDiv.getContentDiv().appendChild(this.picker_); - Blockly.DropDownDiv.showPositionedByField( + DropDownDiv.showPositionedByField( this, this.dropdownDispose_.bind(this)); // Focus so we can start receiving keyboard events. @@ -344,7 +345,7 @@ FieldColour.prototype.onClick_ = function(e) { const colour = cell && cell.label; if (colour !== null) { this.setValue(colour); - Blockly.DropDownDiv.hideIfOwner(this); + DropDownDiv.hideIfOwner(this); } }; @@ -356,19 +357,19 @@ FieldColour.prototype.onClick_ = function(e) { */ FieldColour.prototype.onKeyDown_ = function(e) { let handled = false; - if (e.keyCode === Blockly.utils.KeyCodes.UP) { + if (e.keyCode === KeyCodes.UP) { this.moveHighlightBy_(0, -1); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.DOWN) { + } else if (e.keyCode === KeyCodes.DOWN) { this.moveHighlightBy_(0, 1); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.LEFT) { + } else if (e.keyCode === KeyCodes.LEFT) { this.moveHighlightBy_(-1, 0); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.RIGHT) { + } else if (e.keyCode === KeyCodes.RIGHT) { this.moveHighlightBy_(1, 0); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.ENTER) { + } else if (e.keyCode === KeyCodes.ENTER) { // Select the highlighted colour. const highlighted = this.getHighlighted_(); if (highlighted) { @@ -377,7 +378,7 @@ FieldColour.prototype.onKeyDown_ = function(e) { this.setValue(colour); } } - Blockly.DropDownDiv.hideWithoutAnimation(); + DropDownDiv.hideWithoutAnimation(); handled = true; } if (handled) { @@ -470,7 +471,7 @@ FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); const highlighted = this.getHighlighted_(); if (highlighted) { - Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); + removeClass(highlighted, 'blocklyColourHighlighted'); } }; @@ -501,16 +502,16 @@ FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. const highlighted = this.getHighlighted_(); if (highlighted) { - Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); + removeClass(highlighted, 'blocklyColourHighlighted'); } // Highlight new item. - Blockly.utils.dom.addClass(cell, 'blocklyColourHighlighted'); + addClass(cell, 'blocklyColourHighlighted'); // Set new highlighted index. this.highlightedIndex_ = index; // Update accessibility roles. - Blockly.utils.aria.setState(/** @type {!Element} */ (this.picker_), - Blockly.utils.aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); + aria.setState(/** @type {!Element} */ (this.picker_), + aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); }; /** @@ -527,30 +528,30 @@ FieldColour.prototype.dropdownCreate_ = function() { table.className = 'blocklyColourTable'; table.tabIndex = 0; table.dir = 'ltr'; - Blockly.utils.aria.setRole(table, Blockly.utils.aria.Role.GRID); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.EXPANDED, true); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.ROWCOUNT, + aria.setRole(table, aria.Role.GRID); + aria.setState(table, aria.State.EXPANDED, true); + aria.setState(table, aria.State.ROWCOUNT, Math.floor(colours.length / columns)); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.COLCOUNT, + aria.setState(table, aria.State.COLCOUNT, columns); let row; for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { row = document.createElement('tr'); - Blockly.utils.aria.setRole(row, Blockly.utils.aria.Role.ROW); + aria.setRole(row, aria.Role.ROW); table.appendChild(row); } const cell = document.createElement('td'); row.appendChild(cell); cell.label = colours[i]; // This becomes the value, if clicked. cell.title = titles[i] || colours[i]; - cell.id = Blockly.utils.IdGenerator.getNextUniqueId(); + cell.id = IdGenerator.getNextUniqueId(); cell.setAttribute('data-index', i); - Blockly.utils.aria.setRole(cell, Blockly.utils.aria.Role.GRIDCELL); - Blockly.utils.aria.setState(cell, - Blockly.utils.aria.State.LABEL, colours[i]); - Blockly.utils.aria.setState(cell, - Blockly.utils.aria.State.SELECTED, colours[i] == selectedColour); + aria.setRole(cell, aria.Role.GRIDCELL); + aria.setState(cell, + aria.State.LABEL, colours[i]); + aria.setState(cell, + aria.State.SELECTED, colours[i] == selectedColour); cell.style.backgroundColor = colours[i]; if (colours[i] == selectedColour) { cell.className = 'blocklyColourSelected'; @@ -559,15 +560,15 @@ FieldColour.prototype.dropdownCreate_ = function() { } // Configure event handler on the table to listen for any event in a cell. - this.onClickWrapper_ = Blockly.browserEvents.conditionalBind( + this.onClickWrapper_ = conditionalBind( table, 'click', this, this.onClick_, true); - this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseMoveWrapper_ = conditionalBind( table, 'mousemove', this, this.onMouseMove_, true); - this.onMouseEnterWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseEnterWrapper_ = conditionalBind( table, 'mouseenter', this, this.onMouseEnter_, true); - this.onMouseLeaveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseLeaveWrapper_ = conditionalBind( table, 'mouseleave', this, this.onMouseLeave_, true); - this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownWrapper_ = conditionalBind( table, 'keydown', this, this.onKeyDown_); this.picker_ = table; @@ -579,23 +580,23 @@ FieldColour.prototype.dropdownCreate_ = function() { */ FieldColour.prototype.dropdownDispose_ = function() { if (this.onClickWrapper_) { - Blockly.browserEvents.unbind(this.onClickWrapper_); + unbind(this.onClickWrapper_); this.onClickWrapper_ = null; } if (this.onMouseMoveWrapper_) { - Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); + unbind(this.onMouseMoveWrapper_); this.onMouseMoveWrapper_ = null; } if (this.onMouseEnterWrapper_) { - Blockly.browserEvents.unbind(this.onMouseEnterWrapper_); + unbind(this.onMouseEnterWrapper_); this.onMouseEnterWrapper_ = null; } if (this.onMouseLeaveWrapper_) { - Blockly.browserEvents.unbind(this.onMouseLeaveWrapper_); + unbind(this.onMouseLeaveWrapper_); this.onMouseLeaveWrapper_ = null; } if (this.onKeyDownWrapper_) { - Blockly.browserEvents.unbind(this.onKeyDownWrapper_); + unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; } this.picker_ = null; @@ -605,7 +606,7 @@ FieldColour.prototype.dropdownDispose_ = function() { /** * CSS for colour picker. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyColourTable {', 'border-collapse: collapse;', @@ -638,6 +639,6 @@ Blockly.Css.register([ /* eslint-enable indent */ ]); -Blockly.fieldRegistry.register('field_colour', FieldColour); +fieldRegistry.register('field_colour', FieldColour); exports = FieldColour; From 595f3c0802ce404b8d8987c747278acc1c1c339d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:17:10 -0700 Subject: [PATCH 30/48] clang-format core/field_colour.js --- core/field_colour.js | 57 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 879c340bc..a3dc0bf72 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -36,9 +36,11 @@ goog.require('Blockly.Events.BlockChange'); * '#rrggbb' format. Defaults to the first value in the default colour array. * @param {Function=} opt_validator A function that is called to validate * changes to the field's value. Takes in a colour string & returns a - * validated colour string ('#rrggbb' format), or null to abort the change.Blockly. + * validated colour string ('#rrggbb' format), or null to abort the + * change.Blockly. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -328,11 +330,10 @@ FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); DropDownDiv.getContentDiv().appendChild(this.picker_); - DropDownDiv.showPositionedByField( - this, this.dropdownDispose_.bind(this)); + DropDownDiv.showPositionedByField(this, this.dropdownDispose_.bind(this)); // Focus so we can start receiving keyboard events. - this.picker_.focus({preventScroll:true}); + this.picker_.focus({preventScroll: true}); }; /** @@ -416,8 +417,7 @@ FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } else if (dx > 0) { // Move right one grid cell, even in RTL. // Loop to the start of the next row, if there's room. - if (x > columns - 1 && - y < Math.floor(colours.length / columns) - 1) { + if (x > columns - 1 && y < Math.floor(colours.length / columns) - 1) { x = 0; y++; } else if (x > columns - 1) { @@ -436,7 +436,8 @@ FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } // Move the highlight to the new coordinates. - const cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); + const cell = + /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); const index = (y * columns) + x; this.setHighlightedCell_(cell, index); }; @@ -459,7 +460,7 @@ FieldColour.prototype.onMouseMove_ = function(e) { * @private */ FieldColour.prototype.onMouseEnter_ = function() { - this.picker_.focus({preventScroll:true}); + this.picker_.focus({preventScroll: true}); }; /** @@ -510,8 +511,9 @@ FieldColour.prototype.setHighlightedCell_ = function(cell, index) { this.highlightedIndex_ = index; // Update accessibility roles. - aria.setState(/** @type {!Element} */ (this.picker_), - aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); + aria.setState( + /** @type {!Element} */ (this.picker_), aria.State.ACTIVEDESCENDANT, + cell.getAttribute('id')); }; /** @@ -530,10 +532,9 @@ FieldColour.prototype.dropdownCreate_ = function() { table.dir = 'ltr'; aria.setRole(table, aria.Role.GRID); aria.setState(table, aria.State.EXPANDED, true); - aria.setState(table, aria.State.ROWCOUNT, - Math.floor(colours.length / columns)); - aria.setState(table, aria.State.COLCOUNT, - columns); + aria.setState( + table, aria.State.ROWCOUNT, Math.floor(colours.length / columns)); + aria.setState(table, aria.State.COLCOUNT, columns); let row; for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { @@ -548,10 +549,8 @@ FieldColour.prototype.dropdownCreate_ = function() { cell.id = IdGenerator.getNextUniqueId(); cell.setAttribute('data-index', i); aria.setRole(cell, aria.Role.GRIDCELL); - aria.setState(cell, - aria.State.LABEL, colours[i]); - aria.setState(cell, - aria.State.SELECTED, colours[i] == selectedColour); + aria.setState(cell, aria.State.LABEL, colours[i]); + aria.setState(cell, aria.State.SELECTED, colours[i] == selectedColour); cell.style.backgroundColor = colours[i]; if (colours[i] == selectedColour) { cell.className = 'blocklyColourSelected'; @@ -560,16 +559,16 @@ FieldColour.prototype.dropdownCreate_ = function() { } // Configure event handler on the table to listen for any event in a cell. - this.onClickWrapper_ = conditionalBind( - table, 'click', this, this.onClick_, true); - this.onMouseMoveWrapper_ = conditionalBind( - table, 'mousemove', this, this.onMouseMove_, true); - this.onMouseEnterWrapper_ = conditionalBind( - table, 'mouseenter', this, this.onMouseEnter_, true); - this.onMouseLeaveWrapper_ = conditionalBind( - table, 'mouseleave', this, this.onMouseLeave_, true); - this.onKeyDownWrapper_ = conditionalBind( - table, 'keydown', this, this.onKeyDown_); + this.onClickWrapper_ = + conditionalBind(table, 'click', this, this.onClick_, true); + this.onMouseMoveWrapper_ = + conditionalBind(table, 'mousemove', this, this.onMouseMove_, true); + this.onMouseEnterWrapper_ = + conditionalBind(table, 'mouseenter', this, this.onMouseEnter_, true); + this.onMouseLeaveWrapper_ = + conditionalBind(table, 'mouseleave', this, this.onMouseLeave_, true); + this.onKeyDownWrapper_ = + conditionalBind(table, 'keydown', this, this.onKeyDown_); this.picker_ = table; }; From 0d248583c8e542cf979a1e4e14117a4b94113bb1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:26:52 -0700 Subject: [PATCH 31/48] Migrate core/field_dropdown.js to ES6 const/let --- core/field_dropdown.js | 102 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 5dad752d8..c1554928d 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -299,14 +299,14 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { } // Element gets created in render. this.menu_.render(Blockly.DropDownDiv.getContentDiv()); - var menuElement = /** @type {!Element} */ (this.menu_.getElement()); + const menuElement = /** @type {!Element} */ (this.menu_.getElement()); Blockly.utils.dom.addClass(menuElement, 'blocklyDropdownMenu'); if (this.getConstants().FIELD_DROPDOWN_COLOURED_DIV) { - var primaryColour = (this.sourceBlock_.isShadow()) ? + const primaryColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().getColour() : this.sourceBlock_.getColour(); - var borderColour = (this.sourceBlock_.isShadow()) ? + const borderColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; Blockly.DropDownDiv.setColour(primaryColour, borderColour); @@ -332,23 +332,23 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { * @private */ Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { - var menu = new Blockly.Menu(); + const menu = new Blockly.Menu(); menu.setRole(Blockly.utils.aria.Role.LISTBOX); this.menu_ = menu; - var options = this.getOptions(false); + const options = this.getOptions(false); this.selectedMenuItem_ = null; - for (var i = 0; i < options.length; i++) { - var content = options[i][0]; // Human-readable text or image. - var value = options[i][1]; // Language-neutral value. + for (let i = 0; i < options.length; i++) { + let content = options[i][0]; // Human-readable text or image. + const value = options[i][1]; // Language-neutral value. if (typeof content == 'object') { // An image, not text. - var image = new Image(content['width'], content['height']); + const image = new Image(content['width'], content['height']); image.src = content['src']; image.alt = content['alt'] || ''; content = image; } - var menuItem = new Blockly.MenuItem(content, value); + const menuItem = new Blockly.MenuItem(content, value); menuItem.setRole(Blockly.utils.aria.Role.OPTION); menuItem.setRightToLeft(this.sourceBlock_.RTL); menuItem.setCheckable(true); @@ -400,15 +400,15 @@ Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { * @private */ Blockly.FieldDropdown.prototype.trimOptions_ = function() { - var options = this.menuGenerator_; + const options = this.menuGenerator_; if (!Array.isArray(options)) { return; } - var hasImages = false; + let hasImages = false; // Localize label text and image alt text. - for (var i = 0; i < options.length; i++) { - var label = options[i][0]; + for (let i = 0; i < options.length; i++) { + const label = options[i][0]; if (typeof label == 'string') { options[i][0] = Blockly.utils.replaceMessageReferences(label); } else { @@ -421,13 +421,13 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { if (hasImages || options.length < 2) { return; // Do nothing if too few items or at least one label is an image. } - var strings = []; - for (var i = 0; i < options.length; i++) { + const strings = []; + for (let i = 0; i < options.length; i++) { strings.push(options[i][0]); } - var shortest = Blockly.utils.string.shortestStringLength(strings); - var prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); - var suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); + const shortest = Blockly.utils.string.shortestStringLength(strings); + const prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); + const suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); if (!prefixLength && !suffixLength) { return; } @@ -457,11 +457,11 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { */ Blockly.FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { - var newOptions = []; + const newOptions = []; // Remove the prefix and suffix from the options. - for (var i = 0; i < options.length; i++) { - var text = options[i][0]; - var value = options[i][1]; + for (let i = 0; i < options.length; i++) { + let text = options[i][0]; + const value = options[i][1]; text = text.substring(prefixLength, text.length - suffixLength); newOptions[i] = [text, value]; } @@ -502,9 +502,9 @@ Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { * @protected */ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { - var isValueValid = false; - var options = this.getOptions(true); - for (var i = 0, option; (option = options[i]); i++) { + let isValueValid = false; + const options = this.getOptions(true); + for (let i = 0, option; (option = options[i]); i++) { // Options are tuples of human-readable text and language-neutral values. if (option[1] == opt_newValue) { isValueValid = true; @@ -530,8 +530,8 @@ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { */ Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { Blockly.FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); - var options = this.getOptions(true); - for (var i = 0, option; (option = options[i]); i++) { + const options = this.getOptions(true); + for (let i = 0, option; (option = options[i]); i++) { if (option[1] == this.value_) { this.selectedOption_ = option; } @@ -573,7 +573,7 @@ Blockly.FieldDropdown.prototype.render_ = function() { this.imageElement_.style.display = 'none'; // Show correct element. - var option = this.selectedOption_ && this.selectedOption_[0]; + const option = this.selectedOption_ && this.selectedOption_[0]; if (option && typeof option == 'object') { this.renderSelectedImage_( /** @type {!Blockly.FieldDropdown.ImageProperties} */ (option)); @@ -597,16 +597,16 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); - var imageHeight = Number(imageJson.height); - var imageWidth = Number(imageJson.width); + const imageHeight = Number(imageJson.height); + const imageWidth = Number(imageJson.width); // Height and width include the border rect. - var hasBorder = !!this.borderRect_; - var height = Math.max( + const hasBorder = !!this.borderRect_; + const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, imageHeight + Blockly.FieldDropdown.IMAGE_Y_PADDING); - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var arrowWidth = 0; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + let arrowWidth = 0; if (this.svgArrow_) { arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); @@ -620,9 +620,9 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.size_.width = imageWidth + arrowWidth + xPadding * 2; this.size_.height = height; - var arrowX = 0; + let arrowX = 0; if (this.sourceBlock_.RTL) { - var imageX = xPadding + arrowWidth; + const imageX = xPadding + arrowWidth; this.imageElement_.setAttribute('x', imageX); } else { arrowX = imageWidth + arrowWidth; @@ -646,16 +646,16 @@ Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { this.textElement_.setAttribute('text-anchor', 'start'); // Height and width include the border rect. - var hasBorder = !!this.borderRect_; - var height = Math.max( + const hasBorder = !!this.borderRect_; + const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - var textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + const textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var arrowWidth = 0; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + let arrowWidth = 0; if (this.svgArrow_) { arrowWidth = this.positionSVGArrow_(textWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); @@ -677,11 +677,11 @@ Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { if (!this.svgArrow_) { return 0; } - var hasBorder = !!this.borderRect_; - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; - var svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; - var arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; + const hasBorder = !!this.borderRect_; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; + const svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; + const arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; this.svgArrow_.setAttribute('transform', 'translate(' + arrowX + ',' + y + ')'); return svgArrowSize + textPadding; @@ -699,7 +699,7 @@ Blockly.FieldDropdown.prototype.getText_ = function() { if (!this.selectedOption_) { return null; } - var option = this.selectedOption_[0]; + const option = this.selectedOption_[0]; if (typeof option == 'object') { return option['alt']; } @@ -719,9 +719,9 @@ Blockly.FieldDropdown.validateOptions_ = function(options) { if (!options.length) { throw TypeError('FieldDropdown options must not be an empty array.'); } - var foundError = false; - for (var i = 0; i < options.length; ++i) { - var tuple = options[i]; + let foundError = false; + for (let i = 0; i < options.length; ++i) { + const tuple = options[i]; if (!Array.isArray(tuple)) { foundError = true; console.error( From 5f213b48a691992489b6de9df8560637aad2a712 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:30:06 -0700 Subject: [PATCH 32/48] Migrate core/field_dropdown.js to goog.module --- core/field_dropdown.js | 101 +++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index c1554928d..be6c38e98 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldDropdown'); +goog.module('Blockly.FieldDropdown'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.Field'); @@ -44,16 +45,16 @@ goog.require('Blockly.utils.userAgent'); * @constructor * @throws {TypeError} If `menuGenerator` options are incorrectly structured. */ -Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { +const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { if (typeof menuGenerator != 'function') { - Blockly.FieldDropdown.validateOptions_(menuGenerator); + FieldDropdown.validateOptions_(menuGenerator); } /** * An array of options for a dropdown list, * or a function which generates these options. * @type {(!Array| - * !function(this:Blockly.FieldDropdown): !Array)} + * !function(this:FieldDropdown): !Array)} * @protected */ this.menuGenerator_ = menuGenerator; @@ -90,7 +91,7 @@ Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { this.selectedOption_ = this.getOptions(false)[0]; // Call parent's constructor. - Blockly.FieldDropdown.superClass_.constructor.call( + FieldDropdown.superClass_.constructor.call( this, this.selectedOption_[1], opt_validator, opt_config); /** @@ -128,7 +129,7 @@ Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { */ this.svgArrow_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldDropdown, Blockly.Field); +Blockly.utils.object.inherits(FieldDropdown, Blockly.Field); /** * Dropdown image properties. @@ -139,16 +140,16 @@ Blockly.utils.object.inherits(Blockly.FieldDropdown, Blockly.Field); * height:number * }} */ -Blockly.FieldDropdown.ImageProperties; +FieldDropdown.ImageProperties; /** * Construct a FieldDropdown from a JSON arg object. * @param {!Object} options A JSON object with options (options). - * @return {!Blockly.FieldDropdown} The new field instance. + * @return {!FieldDropdown} The new field instance. * @package * @nocollapse */ -Blockly.FieldDropdown.fromJson = function(options) { +FieldDropdown.fromJson = function(options) { // `this` might be a subclass of FieldDropdown if that class doesn't override // the static fromJson method. return new this(options['options'], undefined, options); @@ -161,7 +162,7 @@ Blockly.FieldDropdown.fromJson = function(options) { * field's state. * @package */ -Blockly.FieldDropdown.prototype.fromXml = function(fieldElement) { +FieldDropdown.prototype.fromXml = function(fieldElement) { if (this.isOptionListDynamic()) { this.getOptions(false); } @@ -173,17 +174,17 @@ Blockly.FieldDropdown.prototype.fromXml = function(fieldElement) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldDropdown.prototype.SERIALIZABLE = true; +FieldDropdown.prototype.SERIALIZABLE = true; /** * Horizontal distance that a checkmark overhangs the dropdown. */ -Blockly.FieldDropdown.CHECKMARK_OVERHANG = 25; +FieldDropdown.CHECKMARK_OVERHANG = 25; /** * Maximum height of the dropdown menu, as a percentage of the viewport height. */ -Blockly.FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; +FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; /** * The y offset from the top of the field to the top of the image, if an image @@ -192,7 +193,7 @@ Blockly.FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; * @const * @private */ -Blockly.FieldDropdown.IMAGE_Y_OFFSET = 5; +FieldDropdown.IMAGE_Y_OFFSET = 5; /** * The total vertical padding above and below an image. @@ -200,25 +201,25 @@ Blockly.FieldDropdown.IMAGE_Y_OFFSET = 5; * @const * @private */ -Blockly.FieldDropdown.IMAGE_Y_PADDING = - Blockly.FieldDropdown.IMAGE_Y_OFFSET * 2; +FieldDropdown.IMAGE_Y_PADDING = + FieldDropdown.IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "â–¾", so use "â–¼" instead. */ -Blockly.FieldDropdown.ARROW_CHAR = +FieldDropdown.ARROW_CHAR = Blockly.utils.userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldDropdown.prototype.CURSOR = 'default'; +FieldDropdown.prototype.CURSOR = 'default'; /** * Create the block UI for this dropdown. * @package */ -Blockly.FieldDropdown.prototype.initView = function() { +FieldDropdown.prototype.initView = function() { if (this.shouldAddBorderRect_()) { this.createBorderRect_(); } else { @@ -245,7 +246,7 @@ Blockly.FieldDropdown.prototype.initView = function() { * @return {boolean} True if the dropdown field should add a border rect. * @protected */ -Blockly.FieldDropdown.prototype.shouldAddBorderRect_ = function() { +FieldDropdown.prototype.shouldAddBorderRect_ = function() { return !this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || (this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW && !this.sourceBlock_.isShadow()); @@ -255,13 +256,13 @@ Blockly.FieldDropdown.prototype.shouldAddBorderRect_ = function() { * Create a tspan based arrow. * @protected */ -Blockly.FieldDropdown.prototype.createTextArrow_ = function() { +FieldDropdown.prototype.createTextArrow_ = function() { this.arrow_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( this.sourceBlock_.RTL ? - Blockly.FieldDropdown.ARROW_CHAR + ' ' : - ' ' + Blockly.FieldDropdown.ARROW_CHAR)); + FieldDropdown.ARROW_CHAR + ' ' : + ' ' + FieldDropdown.ARROW_CHAR)); if (this.sourceBlock_.RTL) { this.textElement_.insertBefore(this.arrow_, this.textContent_); } else { @@ -273,7 +274,7 @@ Blockly.FieldDropdown.prototype.createTextArrow_ = function() { * Create an SVG based arrow. * @protected */ -Blockly.FieldDropdown.prototype.createSVGArrow_ = function() { +FieldDropdown.prototype.createSVGArrow_ = function() { this.svgArrow_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', @@ -289,7 +290,7 @@ Blockly.FieldDropdown.prototype.createSVGArrow_ = function() { * or undefined if triggered programmatically. * @protected */ -Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { +FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { this.menu_.openingCoords = @@ -331,7 +332,7 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { * Create the dropdown editor. * @private */ -Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { +FieldDropdown.prototype.dropdownCreate_ = function() { const menu = new Blockly.Menu(); menu.setRole(Blockly.utils.aria.Role.LISTBOX); this.menu_ = menu; @@ -365,7 +366,7 @@ Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { * Disposes of events and DOM-references belonging to the dropdown editor. * @private */ -Blockly.FieldDropdown.prototype.dropdownDispose_ = function() { +FieldDropdown.prototype.dropdownDispose_ = function() { if (this.menu_) { this.menu_.dispose(); } @@ -379,7 +380,7 @@ Blockly.FieldDropdown.prototype.dropdownDispose_ = function() { * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. * @private */ -Blockly.FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { +FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { Blockly.DropDownDiv.hideIfOwner(this, true); this.onItemSelected_(/** @type {!Blockly.Menu} */ (this.menu_), menuItem); }; @@ -390,7 +391,7 @@ Blockly.FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. * @protected */ -Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { +FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { this.setValue(menuItem.getValue()); }; @@ -399,7 +400,7 @@ Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { * Create prefix and/or suffix labels. * @private */ -Blockly.FieldDropdown.prototype.trimOptions_ = function() { +FieldDropdown.prototype.trimOptions_ = function() { const options = this.menuGenerator_; if (!Array.isArray(options)) { return; @@ -442,7 +443,7 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { this.suffixField = strings[0].substr(1 - suffixLength); } - this.menuGenerator_ = Blockly.FieldDropdown.applyTrim_(options, prefixLength, + this.menuGenerator_ = FieldDropdown.applyTrim_(options, prefixLength, suffixLength); }; @@ -455,7 +456,7 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { * @param {number} suffixLength The length of the common suffix * @return {!Array} A new array with all of the option text trimmed. */ -Blockly.FieldDropdown.applyTrim_ = function(options, +FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { const newOptions = []; // Remove the prefix and suffix from the options. @@ -472,7 +473,7 @@ Blockly.FieldDropdown.applyTrim_ = function(options, * @return {boolean} True if the option list is generated by a function. * Otherwise false. */ -Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { +FieldDropdown.prototype.isOptionListDynamic = function() { return typeof this.menuGenerator_ == 'function'; }; @@ -484,11 +485,11 @@ Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { * (human-readable text or image, language-neutral name). * @throws {TypeError} If generated options are incorrectly structured. */ -Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { +FieldDropdown.prototype.getOptions = function(opt_useCache) { if (this.isOptionListDynamic()) { if (!this.generatedOptions_ || !opt_useCache) { this.generatedOptions_ = this.menuGenerator_.call(this); - Blockly.FieldDropdown.validateOptions_(this.generatedOptions_); + FieldDropdown.validateOptions_(this.generatedOptions_); } return this.generatedOptions_; } @@ -501,7 +502,7 @@ Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { * @return {?string} A valid language-neutral option, or null if invalid. * @protected */ -Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { +FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { let isValueValid = false; const options = this.getOptions(true); for (let i = 0, option; (option = options[i]); i++) { @@ -528,8 +529,8 @@ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { * that this is one of the valid dropdown options. * @protected */ -Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { - Blockly.FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); +FieldDropdown.prototype.doValueUpdate_ = function(newValue) { + FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); const options = this.getOptions(true); for (let i = 0, option; (option = options[i]); i++) { if (option[1] == this.value_) { @@ -542,7 +543,7 @@ Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { * Updates the dropdown arrow to match the colour/style of the block. * @package */ -Blockly.FieldDropdown.prototype.applyColour = function() { +FieldDropdown.prototype.applyColour = function() { if (this.borderRect_) { this.borderRect_.setAttribute('stroke', this.sourceBlock_.style.colourTertiary); @@ -567,7 +568,7 @@ Blockly.FieldDropdown.prototype.applyColour = function() { * Draws the border with the correct width. * @protected */ -Blockly.FieldDropdown.prototype.render_ = function() { +FieldDropdown.prototype.render_ = function() { // Hide both elements. this.textContent_.nodeValue = ''; this.imageElement_.style.display = 'none'; @@ -576,7 +577,7 @@ Blockly.FieldDropdown.prototype.render_ = function() { const option = this.selectedOption_ && this.selectedOption_[0]; if (option && typeof option == 'object') { this.renderSelectedImage_( - /** @type {!Blockly.FieldDropdown.ImageProperties} */ (option)); + /** @type {!FieldDropdown.ImageProperties} */ (option)); } else { this.renderSelectedText_(); } @@ -586,11 +587,11 @@ Blockly.FieldDropdown.prototype.render_ = function() { /** * Renders the selected option, which must be an image. - * @param {!Blockly.FieldDropdown.ImageProperties} imageJson Selected + * @param {!FieldDropdown.ImageProperties} imageJson Selected * option that must be an image. * @private */ -Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { +FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; this.imageElement_.setAttributeNS( Blockly.utils.dom.XLINK_NS, 'xlink:href', imageJson.src); @@ -604,7 +605,7 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const hasBorder = !!this.borderRect_; const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, - imageHeight + Blockly.FieldDropdown.IMAGE_Y_PADDING); + imageHeight + FieldDropdown.IMAGE_Y_PADDING); const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { @@ -638,7 +639,7 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { * Renders the selected option, which must be text. * @private */ -Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { +FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); Blockly.utils.dom.addClass(/** @type {!Element} */ (this.textElement_), @@ -673,7 +674,7 @@ Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { * @return {number} Amount of space the arrow is taking up, in px. * @private */ -Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { +FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { if (!this.svgArrow_) { return 0; } @@ -695,7 +696,7 @@ Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { * @protected * @override */ -Blockly.FieldDropdown.prototype.getText_ = function() { +FieldDropdown.prototype.getText_ = function() { if (!this.selectedOption_) { return null; } @@ -712,7 +713,7 @@ Blockly.FieldDropdown.prototype.getText_ = function() { * @throws {TypeError} If proposed options are incorrectly structured. * @private */ -Blockly.FieldDropdown.validateOptions_ = function(options) { +FieldDropdown.validateOptions_ = function(options) { if (!Array.isArray(options)) { throw TypeError('FieldDropdown options must be an array.'); } @@ -747,4 +748,6 @@ Blockly.FieldDropdown.validateOptions_ = function(options) { } }; -Blockly.fieldRegistry.register('field_dropdown', Blockly.FieldDropdown); +Blockly.fieldRegistry.register('field_dropdown', FieldDropdown); + +exports = FieldDropdown; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..65e09fda9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -52,7 +52,7 @@ goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownD goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); From 393cdf1fa4d5a94a083755b4037e5beac28f2f6a Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:18:05 -0700 Subject: [PATCH 33/48] Switch from destructuring to normal imports in core/field_checkbox.js --- core/field_checkbox.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 3cbe8d07f..d2ce60eaa 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -14,9 +14,9 @@ goog.module('Blockly.FieldCheckbox'); goog.module.declareLegacyNamespace(); const Field = goog.require('Blockly.Field'); -const {addClass} = goog.require('Blockly.utils.dom'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); const {inherits} = goog.require('Blockly.utils.object'); -const {register} = goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); @@ -109,7 +109,7 @@ FieldCheckbox.prototype.configure_ = function(config) { FieldCheckbox.prototype.initView = function() { FieldCheckbox.superClass_.initView.call(this); - addClass( + dom.addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); this.textElement_.style.display = this.value_ ? 'block' : 'none'; }; @@ -221,6 +221,6 @@ FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -register('field_checkbox', FieldCheckbox); +fieldRegistry.register('field_checkbox', FieldCheckbox); exports = FieldCheckbox; From 36bb605bbc9f362a2bbf435048c420bf763ef397 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:53:44 -0700 Subject: [PATCH 34/48] Migrate core/field_dropdown.js to named requires --- core/field_dropdown.js | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index be6c38e98..5a5234c90 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -15,19 +15,19 @@ goog.module('Blockly.FieldDropdown'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.Menu'); -goog.require('Blockly.MenuItem'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.string'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Field = goog.require('Blockly.Field'); +const Menu = goog.require('Blockly.Menu'); +const MenuItem = goog.require('Blockly.MenuItem'); +const Svg = goog.require('Blockly.utils.Svg'); +const aria = goog.require('Blockly.utils.aria'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {commonWordPrefix, commonWordSuffix, shortestStringLength} = goog.require('Blockly.utils.string'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -41,7 +41,7 @@ goog.require('Blockly.utils.userAgent'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor * @throws {TypeError} If `menuGenerator` options are incorrectly structured. */ @@ -96,14 +96,14 @@ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { /** * A reference to the currently selected menu item. - * @type {?Blockly.MenuItem} + * @type {?MenuItem} * @private */ this.selectedMenuItem_ = null; /** * The dropdown menu. - * @type {?Blockly.Menu} + * @type {?Menu} * @protected */ this.menu_ = null; @@ -129,7 +129,7 @@ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { */ this.svgArrow_ = null; }; -Blockly.utils.object.inherits(FieldDropdown, Blockly.Field); +inherits(FieldDropdown, Field); /** * Dropdown image properties. @@ -208,7 +208,7 @@ FieldDropdown.IMAGE_Y_PADDING = * Android can't (in 2014) display "â–¾", so use "â–¼" instead. */ FieldDropdown.ARROW_CHAR = - Blockly.utils.userAgent.ANDROID ? '\u25BC' : '\u25BE'; + userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. @@ -227,8 +227,8 @@ FieldDropdown.prototype.initView = function() { } this.createTextElement_(); - this.imageElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, {}, this.fieldGroup_); + this.imageElement_ = dom.createSvgElement( + Svg.IMAGE, {}, this.fieldGroup_); if (this.getConstants().FIELD_DROPDOWN_SVG_ARROW) { this.createSVGArrow_(); @@ -237,7 +237,7 @@ FieldDropdown.prototype.initView = function() { } if (this.borderRect_) { - Blockly.utils.dom.addClass(this.borderRect_, 'blocklyDropdownRect'); + dom.addClass(this.borderRect_, 'blocklyDropdownRect'); } }; @@ -257,8 +257,8 @@ FieldDropdown.prototype.shouldAddBorderRect_ = function() { * @protected */ FieldDropdown.prototype.createTextArrow_ = function() { - this.arrow_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TSPAN, {}, this.textElement_); + this.arrow_ = dom.createSvgElement( + Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + ' ' : @@ -275,12 +275,12 @@ FieldDropdown.prototype.createTextArrow_ = function() { * @protected */ FieldDropdown.prototype.createSVGArrow_ = function() { - this.svgArrow_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { + this.svgArrow_ = dom.createSvgElement( + Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', 'width': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px' }, this.fieldGroup_); - this.svgArrow_.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.svgArrow_.setAttributeNS(dom.XLINK_NS, 'xlink:href', this.getConstants().FIELD_DROPDOWN_SVG_ARROW_DATAURI); }; @@ -294,14 +294,14 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { this.menu_.openingCoords = - new Blockly.utils.Coordinate(opt_e.clientX, opt_e.clientY); + new Coordinate(opt_e.clientX, opt_e.clientY); } else { this.menu_.openingCoords = null; } // Element gets created in render. - this.menu_.render(Blockly.DropDownDiv.getContentDiv()); + this.menu_.render(DropDownDiv.getContentDiv()); const menuElement = /** @type {!Element} */ (this.menu_.getElement()); - Blockly.utils.dom.addClass(menuElement, 'blocklyDropdownMenu'); + dom.addClass(menuElement, 'blocklyDropdownMenu'); if (this.getConstants().FIELD_DROPDOWN_COLOURED_DIV) { const primaryColour = (this.sourceBlock_.isShadow()) ? @@ -310,10 +310,10 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { const borderColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; - Blockly.DropDownDiv.setColour(primaryColour, borderColour); + DropDownDiv.setColour(primaryColour, borderColour); } - Blockly.DropDownDiv.showPositionedByField( + DropDownDiv.showPositionedByField( this, this.dropdownDispose_.bind(this)); // Focusing needs to be handled after the menu is rendered and positioned. @@ -333,8 +333,8 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { * @private */ FieldDropdown.prototype.dropdownCreate_ = function() { - const menu = new Blockly.Menu(); - menu.setRole(Blockly.utils.aria.Role.LISTBOX); + const menu = new Menu(); + menu.setRole(aria.Role.LISTBOX); this.menu_ = menu; const options = this.getOptions(false); @@ -349,8 +349,8 @@ FieldDropdown.prototype.dropdownCreate_ = function() { image.alt = content['alt'] || ''; content = image; } - const menuItem = new Blockly.MenuItem(content, value); - menuItem.setRole(Blockly.utils.aria.Role.OPTION); + const menuItem = new MenuItem(content, value); + menuItem.setRole(aria.Role.OPTION); menuItem.setRightToLeft(this.sourceBlock_.RTL); menuItem.setCheckable(true); menu.addChild(menuItem); @@ -377,18 +377,18 @@ FieldDropdown.prototype.dropdownDispose_ = function() { /** * Handle an action in the dropdown menu. - * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. + * @param {!MenuItem} menuItem The MenuItem selected within menu. * @private */ FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { - Blockly.DropDownDiv.hideIfOwner(this, true); - this.onItemSelected_(/** @type {!Blockly.Menu} */ (this.menu_), menuItem); + DropDownDiv.hideIfOwner(this, true); + this.onItemSelected_(/** @type {!Menu} */ (this.menu_), menuItem); }; /** * Handle the selection of an item in the dropdown menu. - * @param {!Blockly.Menu} menu The Menu component clicked. - * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. + * @param {!Menu} menu The Menu component clicked. + * @param {!MenuItem} menuItem The MenuItem selected within menu. * @protected */ FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { @@ -411,10 +411,10 @@ FieldDropdown.prototype.trimOptions_ = function() { for (let i = 0; i < options.length; i++) { const label = options[i][0]; if (typeof label == 'string') { - options[i][0] = Blockly.utils.replaceMessageReferences(label); + options[i][0] = replaceMessageReferences(label); } else { if (label.alt != null) { - options[i][0].alt = Blockly.utils.replaceMessageReferences(label.alt); + options[i][0].alt = replaceMessageReferences(label.alt); } hasImages = true; } @@ -426,9 +426,9 @@ FieldDropdown.prototype.trimOptions_ = function() { for (let i = 0; i < options.length; i++) { strings.push(options[i][0]); } - const shortest = Blockly.utils.string.shortestStringLength(strings); - const prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); - const suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); + const shortest = shortestStringLength(strings); + const prefixLength = commonWordPrefix(strings, shortest); + const suffixLength = commonWordSuffix(strings, shortest); if (!prefixLength && !suffixLength) { return; } @@ -594,7 +594,7 @@ FieldDropdown.prototype.render_ = function() { FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; this.imageElement_.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', imageJson.src); + dom.XLINK_NS, 'xlink:href', imageJson.src); this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); @@ -612,7 +612,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } else { - arrowWidth = Blockly.utils.dom.getFastTextWidth( + arrowWidth = dom.getFastTextWidth( /** @type {!SVGTSpanElement} */ (this.arrow_), this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, @@ -642,7 +642,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); - Blockly.utils.dom.addClass(/** @type {!Element} */ (this.textElement_), + dom.addClass(/** @type {!Element} */ (this.textElement_), 'blocklyDropdownText'); this.textElement_.setAttribute('text-anchor', 'start'); @@ -651,7 +651,7 @@ FieldDropdown.prototype.renderSelectedText_ = function() { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - const textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + const textWidth = dom.getFastTextWidth(this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); @@ -748,6 +748,6 @@ FieldDropdown.validateOptions_ = function(options) { } }; -Blockly.fieldRegistry.register('field_dropdown', FieldDropdown); +fieldRegistry.register('field_dropdown', FieldDropdown); exports = FieldDropdown; From 740e4651b178dfbcbe6ab07930896ee3ccf10834 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:56:32 -0700 Subject: [PATCH 35/48] clang-format core/field_dropdown.js --- core/field_dropdown.js | 118 +++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 5a5234c90..79b6ea404 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -39,7 +39,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * option & returns a validated language-neutral dropdown option, or null to * abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -134,12 +135,12 @@ inherits(FieldDropdown, Field); /** * Dropdown image properties. * @typedef {{ - * src:string, - * alt:string, - * width:number, - * height:number - * }} - */ + * src:string, + * alt:string, + * width:number, + * height:number + * }} + */ FieldDropdown.ImageProperties; /** @@ -201,14 +202,12 @@ FieldDropdown.IMAGE_Y_OFFSET = 5; * @const * @private */ -FieldDropdown.IMAGE_Y_PADDING = - FieldDropdown.IMAGE_Y_OFFSET * 2; +FieldDropdown.IMAGE_Y_PADDING = FieldDropdown.IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "â–¾", so use "â–¼" instead. */ -FieldDropdown.ARROW_CHAR = - userAgent.ANDROID ? '\u25BC' : '\u25BE'; +FieldDropdown.ARROW_CHAR = userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. @@ -227,8 +226,7 @@ FieldDropdown.prototype.initView = function() { } this.createTextElement_(); - this.imageElement_ = dom.createSvgElement( - Svg.IMAGE, {}, this.fieldGroup_); + this.imageElement_ = dom.createSvgElement(Svg.IMAGE, {}, this.fieldGroup_); if (this.getConstants().FIELD_DROPDOWN_SVG_ARROW) { this.createSVGArrow_(); @@ -249,7 +247,7 @@ FieldDropdown.prototype.initView = function() { FieldDropdown.prototype.shouldAddBorderRect_ = function() { return !this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || (this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW && - !this.sourceBlock_.isShadow()); + !this.sourceBlock_.isShadow()); }; /** @@ -257,12 +255,10 @@ FieldDropdown.prototype.shouldAddBorderRect_ = function() { * @protected */ FieldDropdown.prototype.createTextArrow_ = function() { - this.arrow_ = dom.createSvgElement( - Svg.TSPAN, {}, this.textElement_); + this.arrow_ = dom.createSvgElement(Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( - this.sourceBlock_.RTL ? - FieldDropdown.ARROW_CHAR + ' ' : - ' ' + FieldDropdown.ARROW_CHAR)); + this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + ' ' : + ' ' + FieldDropdown.ARROW_CHAR)); if (this.sourceBlock_.RTL) { this.textElement_.insertBefore(this.arrow_, this.textContent_); } else { @@ -279,8 +275,10 @@ FieldDropdown.prototype.createSVGArrow_ = function() { Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', 'width': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px' - }, this.fieldGroup_); - this.svgArrow_.setAttributeNS(dom.XLINK_NS, 'xlink:href', + }, + this.fieldGroup_); + this.svgArrow_.setAttributeNS( + dom.XLINK_NS, 'xlink:href', this.getConstants().FIELD_DROPDOWN_SVG_ARROW_DATAURI); }; @@ -293,8 +291,7 @@ FieldDropdown.prototype.createSVGArrow_ = function() { FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { - this.menu_.openingCoords = - new Coordinate(opt_e.clientX, opt_e.clientY); + this.menu_.openingCoords = new Coordinate(opt_e.clientX, opt_e.clientY); } else { this.menu_.openingCoords = null; } @@ -313,8 +310,7 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { DropDownDiv.setColour(primaryColour, borderColour); } - DropDownDiv.showPositionedByField( - this, this.dropdownDispose_.bind(this)); + DropDownDiv.showPositionedByField(this, this.dropdownDispose_.bind(this)); // Focusing needs to be handled after the menu is rendered and positioned. // Otherwise it will cause a page scroll to get the misplaced menu in @@ -341,7 +337,7 @@ FieldDropdown.prototype.dropdownCreate_ = function() { this.selectedMenuItem_ = null; for (let i = 0; i < options.length; i++) { let content = options[i][0]; // Human-readable text or image. - const value = options[i][1]; // Language-neutral value. + const value = options[i][1]; // Language-neutral value. if (typeof content == 'object') { // An image, not text. const image = new Image(content['width'], content['height']); @@ -443,8 +439,8 @@ FieldDropdown.prototype.trimOptions_ = function() { this.suffixField = strings[0].substr(1 - suffixLength); } - this.menuGenerator_ = FieldDropdown.applyTrim_(options, prefixLength, - suffixLength); + this.menuGenerator_ = + FieldDropdown.applyTrim_(options, prefixLength, suffixLength); }; /** @@ -456,8 +452,7 @@ FieldDropdown.prototype.trimOptions_ = function() { * @param {number} suffixLength The length of the common suffix * @return {!Array} A new array with all of the option text trimmed. */ -FieldDropdown.applyTrim_ = function(options, - prefixLength, suffixLength) { +FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { const newOptions = []; // Remove the prefix and suffix from the options. for (let i = 0; i < options.length; i++) { @@ -514,9 +509,10 @@ FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { } if (!isValueValid) { if (this.sourceBlock_) { - console.warn('Cannot set the dropdown\'s value to an unavailable option.' + - ' Block type: ' + this.sourceBlock_.type + ', Field name: ' + this.name + - ', Value: ' + opt_newValue); + console.warn( + 'Cannot set the dropdown\'s value to an unavailable option.' + + ' Block type: ' + this.sourceBlock_.type + + ', Field name: ' + this.name + ', Value: ' + opt_newValue); } return null; } @@ -545,11 +541,11 @@ FieldDropdown.prototype.doValueUpdate_ = function(newValue) { */ FieldDropdown.prototype.applyColour = function() { if (this.borderRect_) { - this.borderRect_.setAttribute('stroke', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'stroke', this.sourceBlock_.style.colourTertiary); if (this.menu_) { - this.borderRect_.setAttribute('fill', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'fill', this.sourceBlock_.style.colourTertiary); } else { this.borderRect_.setAttribute('fill', 'transparent'); } @@ -593,8 +589,7 @@ FieldDropdown.prototype.render_ = function() { */ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; - this.imageElement_.setAttributeNS( - dom.XLINK_NS, 'xlink:href', imageJson.src); + this.imageElement_.setAttributeNS(dom.XLINK_NS, 'xlink:href', imageJson.src); this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); @@ -606,11 +601,13 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, imageHeight + FieldDropdown.IMAGE_Y_PADDING); - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { - arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); + arrowWidth = this.positionSVGArrow_( + imageWidth + xPadding, + height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } else { arrowWidth = dom.getFastTextWidth( /** @type {!SVGTSpanElement} */ (this.arrow_), @@ -642,8 +639,8 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); - dom.addClass(/** @type {!Element} */ (this.textElement_), - 'blocklyDropdownText'); + dom.addClass( + /** @type {!Element} */ (this.textElement_), 'blocklyDropdownText'); this.textElement_.setAttribute('text-anchor', 'start'); // Height and width include the border rect. @@ -651,15 +648,17 @@ FieldDropdown.prototype.renderSelectedText_ = function() { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - const textWidth = dom.getFastTextWidth(this.textElement_, - this.getConstants().FIELD_TEXT_FONTSIZE, + const textWidth = dom.getFastTextWidth( + this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { - arrowWidth = this.positionSVGArrow_(textWidth + xPadding, height / 2 - - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); + arrowWidth = this.positionSVGArrow_( + textWidth + xPadding, + height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } this.size_.width = textWidth + arrowWidth + xPadding * 2; this.size_.height = height; @@ -679,12 +678,13 @@ FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { return 0; } const hasBorder = !!this.borderRect_; - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; const textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; const svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; const arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; - this.svgArrow_.setAttribute('transform', - 'translate(' + arrowX + ',' + y + ')'); + this.svgArrow_.setAttribute( + 'transform', 'translate(' + arrowX + ',' + y + ')'); return svgArrowSize + textPadding; }; @@ -727,19 +727,21 @@ FieldDropdown.validateOptions_ = function(options) { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option must be an ' + - 'array. Found: ', tuple); + 'array. Found: ', + tuple); } else if (typeof tuple[1] != 'string') { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option id must be ' + - 'a string. Found ' + tuple[1] + ' in: ', tuple); - } else if (tuple[0] && - (typeof tuple[0] != 'string') && - (typeof tuple[0].src != 'string')) { + 'a string. Found ' + tuple[1] + ' in: ', + tuple); + } else if ( + tuple[0] && (typeof tuple[0] != 'string') && + (typeof tuple[0].src != 'string')) { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option must have a ' + - 'string label or image description. Found' + tuple[0] + ' in: ', + 'string label or image description. Found' + tuple[0] + ' in: ', tuple); } } From 5e3940195f8c718d812a4c5b7d0b64a8f7fd6a7c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 15:02:35 -0700 Subject: [PATCH 36/48] Migrate private static fields/functions in core/field_dropdown.js to module-internal --- core/field_dropdown.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 79b6ea404..ddb5a4e18 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -48,7 +48,7 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); */ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { if (typeof menuGenerator != 'function') { - FieldDropdown.validateOptions_(menuGenerator); + validateOptions(menuGenerator); } /** @@ -192,17 +192,15 @@ FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; * is selected. * @type {number} * @const - * @private */ -FieldDropdown.IMAGE_Y_OFFSET = 5; +const IMAGE_Y_OFFSET = 5; /** * The total vertical padding above and below an image. * @type {number} * @const - * @private */ -FieldDropdown.IMAGE_Y_PADDING = FieldDropdown.IMAGE_Y_OFFSET * 2; +const IMAGE_Y_PADDING = IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "â–¾", so use "â–¼" instead. @@ -484,7 +482,7 @@ FieldDropdown.prototype.getOptions = function(opt_useCache) { if (this.isOptionListDynamic()) { if (!this.generatedOptions_ || !opt_useCache) { this.generatedOptions_ = this.menuGenerator_.call(this); - FieldDropdown.validateOptions_(this.generatedOptions_); + validateOptions(this.generatedOptions_); } return this.generatedOptions_; } @@ -600,7 +598,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const hasBorder = !!this.borderRect_; const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, - imageHeight + FieldDropdown.IMAGE_Y_PADDING); + imageHeight + IMAGE_Y_PADDING); const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; @@ -711,9 +709,8 @@ FieldDropdown.prototype.getText_ = function() { * Validates the data structure to be processed as an options list. * @param {?} options The proposed dropdown options. * @throws {TypeError} If proposed options are incorrectly structured. - * @private */ -FieldDropdown.validateOptions_ = function(options) { +const validateOptions = function(options) { if (!Array.isArray(options)) { throw TypeError('FieldDropdown options must be an array.'); } From c15f1e4767798f1b8230fc07f9ae7d89e669e634 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:17:00 -0700 Subject: [PATCH 37/48] Move constants to internal_constants.js and add aliases --- core/blockly.js | 36 ++++++ core/constants.js | 189 ++------------------------------ core/internal_constants.js | 217 +++++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+), 181 deletions(-) create mode 100644 core/internal_constants.js diff --git a/core/blockly.js b/core/blockly.js index 92716e4d1..554e02c8d 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -35,6 +35,7 @@ goog.require('Blockly.Events.VarCreate'); /** @suppress {extraRequire} */ goog.require('Blockly.inject'); goog.require('Blockly.inputTypes'); +goog.require('Blockly.internalConstants'); /** @suppress {extraRequire} */ goog.require('Blockly.Procedures'); goog.require('Blockly.ShortcutRegistry'); @@ -596,3 +597,38 @@ Blockly.TOOLBOX_AT_LEFT = Blockly.utils.toolbox.Position.LEFT; * @see Blockly.utils.toolbox.Position.RIGHT */ Blockly.TOOLBOX_AT_RIGHT = Blockly.utils.toolbox.Position.RIGHT; + +// Aliases to allow external code to access these values for legacy reasons. +Blockly.LINE_MODE_MULTIPLIER = Blockly.internalConstants.LINE_MODE_MULTIPLIER; +Blockly.PAGE_MODE_MULTIPLIER = Blockly.internalConstants.PAGE_MODE_MULTIPLIER; +Blockly.DRAG_RADIUS = Blockly.internalConstants.DRAG_RADIUS; +Blockly.FLYOUT_DRAG_RADIUS = Blockly.internalConstants.FLYOUT_DRAG_RADIUS; +Blockly.SNAP_RADIUS = Blockly.internalConstants.SNAP_RADIUS; +Blockly.CONNECTING_SNAP_RADIUS = + Blockly.internalConstants.CONNECTING_SNAP_RADIUS; +Blockly.CURRENT_CONNECTION_PREFERENCE = + Blockly.internalConstants.CURRENT_CONNECTION_PREFERENCE; +Blockly.BUMP_DELAY = Blockly.internalConstants.BUMP_DELAY; +Blockly.BUMP_RANDOMNESS = Blockly.internalConstants.BUMP_RANDOMNESS; +Blockly.COLLAPSE_CHARS = Blockly.internalConstants.COLLAPSE_CHARS; +Blockly.LONGPRESS = Blockly.internalConstants.LONGPRESS; +Blockly.SOUND_LIMIT = Blockly.internalConstants.SOUND_LIMIT; +Blockly.DRAG_STACK = Blockly.internalConstants.DRAG_STACK; +Blockly.HSV_SATURATION = Blockly.internalConstants.HSV_SATURATION; +Blockly.HSV_VALUE = Blockly.internalConstants.HSV_VALUE; +Blockly.SPRITE = Blockly.internalConstants.SPRITE; +Blockly.DRAG_NONE = Blockly.internalConstants.DRAG_NONE; +Blockly.DRAG_STICKY = Blockly.internalConstants.DRAG_STICKY; +Blockly.DRAG_BEGIN = Blockly.internalConstants.DRAG_BEGIN; +Blockly.DRAG_FREE = Blockly.internalConstants.DRAG_FREE; +Blockly.OPPOSITE_TYPE = Blockly.internalConstants.OPPOSITE_TYPE; +Blockly.VARIABLE_CATEGORY_NAME = + Blockly.internalConstants.VARIABLE_CATEGORY_NAME; +Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME = + Blockly.internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME; +Blockly.PROCEDURE_CATEGORY_NAME = + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME; +Blockly.RENAME_VARIABLE_ID = Blockly.internalConstants.RENAME_VARIABLE_ID; +Blockly.DELETE_VARIABLE_ID = Blockly.internalConstants.DELETE_VARIABLE_ID; +Blockly.COLLAPSED_INPUT_NAME = Blockly.constants.COLLAPSED_INPUT_NAME; +Blockly.COLLAPSED_FIELD_NAME = Blockly.constants.COLLAPSED_FIELD_NAME; diff --git a/core/constants.js b/core/constants.js index 1d19fb8d5..727e42a1f 100644 --- a/core/constants.js +++ b/core/constants.js @@ -10,204 +10,31 @@ */ 'use strict'; -goog.provide('Blockly.constants'); +goog.module('Blockly.constants'); +goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); - - -/** - * The multiplier for scroll wheel deltas using the line delta mode. - * @type {number} - */ -Blockly.LINE_MODE_MULTIPLIER = 40; - -/** - * The multiplier for scroll wheel deltas using the page delta mode. - * @type {number} - */ -Blockly.PAGE_MODE_MULTIPLIER = 125; - -/** - * Number of pixels the mouse must move before a drag starts. - */ -Blockly.DRAG_RADIUS = 5; - -/** - * Number of pixels the mouse must move before a drag/scroll starts from the - * flyout. Because the drag-intention is determined when this is reached, it is - * larger than Blockly.DRAG_RADIUS so that the drag-direction is clearer. - */ -Blockly.FLYOUT_DRAG_RADIUS = 10; - -/** - * Maximum misalignment between connections for them to snap together. - */ -Blockly.SNAP_RADIUS = 28; - -/** - * Maximum misalignment between connections for them to snap together, - * when a connection is already highlighted. - */ -Blockly.CONNECTING_SNAP_RADIUS = Blockly.SNAP_RADIUS; - -/** - * How much to prefer staying connected to the current connection over moving to - * a new connection. The current previewed connection is considered to be this - * much closer to the matching connection on the block than it actually is. - */ -Blockly.CURRENT_CONNECTION_PREFERENCE = 8; - -/** - * Delay in ms between trigger and bumping unconnected block out of alignment. - */ -Blockly.BUMP_DELAY = 250; - -/** - * Maximum randomness in workspace units for bumping a block. - */ -Blockly.BUMP_RANDOMNESS = 10; - -/** - * Number of characters to truncate a collapsed block to. - */ -Blockly.COLLAPSE_CHARS = 30; - -/** - * Length in ms for a touch to become a long press. - */ -Blockly.LONGPRESS = 750; - -/** - * Prevent a sound from playing if another sound preceded it within this many - * milliseconds. - */ -Blockly.SOUND_LIMIT = 100; - -/** - * When dragging a block out of a stack, split the stack in two (true), or drag - * out the block healing the stack (false). - */ -Blockly.DRAG_STACK = true; - -/** - * The richness of block colours, regardless of the hue. - * Must be in the range of 0 (inclusive) to 1 (exclusive). - */ -Blockly.HSV_SATURATION = 0.45; - -/** - * The intensity of block colours, regardless of the hue. - * Must be in the range of 0 (inclusive) to 1 (exclusive). - */ -Blockly.HSV_VALUE = 0.65; - -/** - * Sprited icons and images. - */ -Blockly.SPRITE = { - width: 96, - height: 124, - url: 'sprites.png' -}; - -// Constants below this point are not intended to be changed. /** * Enum for alignment of inputs. * @enum {number} */ -Blockly.constants.ALIGN = { +const ALIGN = { LEFT: -1, CENTRE: 0, RIGHT: 1 }; - -/** - * ENUM for no drag operation. - * @const - */ -Blockly.DRAG_NONE = 0; - -/** - * ENUM for inside the sticky DRAG_RADIUS. - * @const - */ -Blockly.DRAG_STICKY = 1; - -/** - * ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between - * clicks and drags. - * @const - */ -Blockly.DRAG_BEGIN = 1; - -/** - * ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). - * @const - */ -Blockly.DRAG_FREE = 2; - -/** - * Lookup table for determining the opposite type of a connection. - * @const - */ -Blockly.OPPOSITE_TYPE = []; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.INPUT_VALUE] = - Blockly.connectionTypes.OUTPUT_VALUE; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.OUTPUT_VALUE] = - Blockly.connectionTypes.INPUT_VALUE; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.NEXT_STATEMENT] = - Blockly.connectionTypes.PREVIOUS_STATEMENT; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.PREVIOUS_STATEMENT] = - Blockly.connectionTypes.NEXT_STATEMENT; - -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * variable blocks. - * @const {string} - */ -Blockly.VARIABLE_CATEGORY_NAME = 'VARIABLE'; -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * variable blocks. - * @const {string} - */ -Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME = 'VARIABLE_DYNAMIC'; - -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * procedure blocks. - * @const {string} - */ -Blockly.PROCEDURE_CATEGORY_NAME = 'PROCEDURE'; - -/** - * String for use in the dropdown created in field_variable. - * This string indicates that this option in the dropdown is 'Rename - * variable...' and if selected, should trigger the prompt to rename a variable. - * @const {string} - */ -Blockly.RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID'; - -/** - * String for use in the dropdown created in field_variable. - * This string indicates that this option in the dropdown is 'Delete the "%1" - * variable' and if selected, should trigger the prompt to delete a variable. - * @const {string} - */ -Blockly.DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID'; +exports.ALIGN = ALIGN; /** * The language-neutral ID given to the collapsed input. * @const {string} */ -Blockly.constants.COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT'; +const COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT'; +exports.COLLAPSED_INPUT_NAME = COLLAPSED_INPUT_NAME; /** * The language-neutral ID given to the collapsed field. * @const {string} */ -Blockly.constants.COLLAPSED_FIELD_NAME = '_TEMP_COLLAPSED_FIELD'; +const COLLAPSED_FIELD_NAME = '_TEMP_COLLAPSED_FIELD'; +exports.COLLAPSED_FIELD_NAME = COLLAPSED_FIELD_NAME; diff --git a/core/internal_constants.js b/core/internal_constants.js new file mode 100644 index 000000000..b5a8cd568 --- /dev/null +++ b/core/internal_constants.js @@ -0,0 +1,217 @@ +/** + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Module that provides constants for use inside Blockly. Do not + * use these constants outside of the core library. + * @author fenichel@google.com (Rachel Fenichel) + */ +'use strict'; + +goog.module('Blockly.internalConstants'); +goog.module.declareLegacyNamespace(); + +const connectionTypes = goog.require('Blockly.connectionTypes'); + + +/** + * The multiplier for scroll wheel deltas using the line delta mode. + * @type {number} + */ +const LINE_MODE_MULTIPLIER = 40; +exports.LINE_MODE_MULTIPLIER = LINE_MODE_MULTIPLIER; + +/** + * The multiplier for scroll wheel deltas using the page delta mode. + * @type {number} + */ +const PAGE_MODE_MULTIPLIER = 125; +exports.PAGE_MODE_MULTIPLIER = PAGE_MODE_MULTIPLIER; + +/** + * Number of pixels the mouse must move before a drag starts. + */ +const DRAG_RADIUS = 5; +exports.DRAG_RADIUS = DRAG_RADIUS; + +/** + * Number of pixels the mouse must move before a drag/scroll starts from the + * flyout. Because the drag-intention is determined when this is reached, it is + * larger than DRAG_RADIUS so that the drag-direction is clearer. + */ +const FLYOUT_DRAG_RADIUS = 10; +exports.FLYOUT_DRAG_RADIUS = FLYOUT_DRAG_RADIUS; + +/** + * Maximum misalignment between connections for them to snap together. + */ +const SNAP_RADIUS = 28; +exports.SNAP_RADIUS = SNAP_RADIUS; + +/** + * Maximum misalignment between connections for them to snap together, + * when a connection is already highlighted. + */ +const CONNECTING_SNAP_RADIUS = SNAP_RADIUS; +exports.CONNECTING_SNAP_RADIUS = CONNECTING_SNAP_RADIUS; + +/** + * How much to prefer staying connected to the current connection over moving to + * a new connection. The current previewed connection is considered to be this + * much closer to the matching connection on the block than it actually is. + */ +const CURRENT_CONNECTION_PREFERENCE = 8; +exports.CURRENT_CONNECTION_PREFERENCE = CURRENT_CONNECTION_PREFERENCE; + +/** + * Delay in ms between trigger and bumping unconnected block out of alignment. + */ +const BUMP_DELAY = 250; +exports.BUMP_DELAY = BUMP_DELAY; + +/** + * Maximum randomness in workspace units for bumping a block. + */ +const BUMP_RANDOMNESS = 10; +exports.BUMP_RANDOMNESS = BUMP_RANDOMNESS; + +/** + * Number of characters to truncate a collapsed block to. + */ +const COLLAPSE_CHARS = 30; +exports.COLLAPSE_CHARS = COLLAPSE_CHARS; + +/** + * Length in ms for a touch to become a long press. + */ +const LONGPRESS = 750; +exports.LONGPRESS = LONGPRESS; + +/** + * Prevent a sound from playing if another sound preceded it within this many + * milliseconds. + */ +const SOUND_LIMIT = 100; +exports.SOUND_LIMIT = SOUND_LIMIT; + +/** + * When dragging a block out of a stack, split the stack in two (true), or drag + * out the block healing the stack (false). + */ +const DRAG_STACK = true; +exports.DRAG_STACK = DRAG_STACK; + +/** + * The richness of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + */ +const HSV_SATURATION = 0.45; +exports.HSV_SATURATION = HSV_SATURATION; + +/** + * The intensity of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + */ +const HSV_VALUE = 0.65; +exports.HSV_VALUE = HSV_VALUE; + +/** + * Sprited icons and images. + */ +const SPRITE = { + width: 96, + height: 124, + url: 'sprites.png' +}; +exports.SPRITE = SPRITE; + +/** + * ENUM for no drag operation. + * @const + */ +const DRAG_NONE = 0; +exports.DRAG_NONE = DRAG_NONE; + +/** + * ENUM for inside the sticky DRAG_RADIUS. + * @const + */ +const DRAG_STICKY = 1; +exports.DRAG_STICKY = DRAG_STICKY; + +/** + * ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between + * clicks and drags. + * @const + */ +const DRAG_BEGIN = 1; +exports.DRAG_BEGIN = DRAG_BEGIN; + +/** + * ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). + * @const + */ +const DRAG_FREE = 2; +exports.DRAG_FREE = DRAG_FREE; + +/** + * Lookup table for determining the opposite type of a connection. + * @const + */ +const OPPOSITE_TYPE = []; +OPPOSITE_TYPE[connectionTypes.INPUT_VALUE] = connectionTypes.OUTPUT_VALUE; +OPPOSITE_TYPE[connectionTypes.OUTPUT_VALUE] = connectionTypes.INPUT_VALUE; +OPPOSITE_TYPE[connectionTypes.NEXT_STATEMENT] = + connectionTypes.PREVIOUS_STATEMENT; +OPPOSITE_TYPE[connectionTypes.PREVIOUS_STATEMENT] = + connectionTypes.NEXT_STATEMENT; + +exports.OPPOSITE_TYPE = OPPOSITE_TYPE; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * variable blocks. + * @const {string} + */ +const VARIABLE_CATEGORY_NAME = 'VARIABLE'; +exports.VARIABLE_CATEGORY_NAME = VARIABLE_CATEGORY_NAME; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * variable blocks. + * @const {string} + */ +const VARIABLE_DYNAMIC_CATEGORY_NAME = 'VARIABLE_DYNAMIC'; +exports.VARIABLE_DYNAMIC_CATEGORY_NAME = VARIABLE_DYNAMIC_CATEGORY_NAME; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * procedure blocks. + * @const {string} + */ +const PROCEDURE_CATEGORY_NAME = 'PROCEDURE'; +exports.PROCEDURE_CATEGORY_NAME = PROCEDURE_CATEGORY_NAME; + +/** + * String for use in the dropdown created in field_variable. + * This string indicates that this option in the dropdown is 'Rename + * variable...' and if selected, should trigger the prompt to rename a variable. + * @const {string} + */ +const RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID'; +exports.RENAME_VARIABLE_ID = RENAME_VARIABLE_ID; + +/** + * String for use in the dropdown created in field_variable. + * This string indicates that this option in the dropdown is 'Delete the "%1" + * variable' and if selected, should trigger the prompt to delete a variable. + * @const {string} + */ +const DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID'; +exports.DELETE_VARIABLE_ID = DELETE_VARIABLE_ID; From 324c3c038f81dad7ce7c321c97cc4b4b3a8ab12e Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:17:19 -0700 Subject: [PATCH 38/48] Rebuild --- tests/deps.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/deps.js b/tests/deps.js index 52ca3e4f3..d7e7ec201 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -12,7 +12,7 @@ goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'] goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); @@ -23,7 +23,7 @@ goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); +goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); @@ -100,7 +100,12 @@ goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectabl goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); +<<<<<<< HEAD goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); +======= +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); +>>>>>>> 3a5ddf4d (Rebuild) goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From cc7a263fb3842ca6a2bc800288eca2d4474bfba0 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:48:56 -0700 Subject: [PATCH 39/48] Replace references to SPRITE and SOUND_LIMIT with internalConstants versions --- core/trashcan.js | 29 +++++++++++++++-------------- core/workspace_audio.js | 5 ++--- core/zoom_controls.js | 40 ++++++++++++++++++++++------------------ tests/deps.js | 6 +++--- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index 831a26ba4..619299b21 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -14,13 +14,12 @@ goog.provide('Blockly.Trashcan'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.DeleteArea'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.TrashcanOpen'); goog.require('Blockly.IAutoHideable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.IPositionable'); goog.require('Blockly.Options'); goog.require('Blockly.registry'); @@ -316,17 +315,18 @@ Blockly.Trashcan.prototype.createDom = function() { }, clip); var body = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, 'x': -this.SPRITE_LEFT_, - 'height': Blockly.SPRITE.height, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -this.SPRITE_TOP_, 'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')' }, this.svgGroup_); - body.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + body.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, @@ -336,17 +336,18 @@ Blockly.Trashcan.prototype.createDom = function() { Blockly.utils.Svg.RECT, {'width': this.WIDTH_, 'height': this.LID_HEIGHT_}, clip); this.svgLid_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, 'x': -this.SPRITE_LEFT_, - 'height': Blockly.SPRITE.height, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -this.SPRITE_TOP_, 'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')' }, this.svgGroup_); - this.svgLid_.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + this.svgLid_.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // bindEventWithChecks_ quashes events too aggressively. See: // https://groups.google.com/forum/#!topic/blockly/QF4yB9Wx00s diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 954b8f892..378c19287 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -13,8 +13,7 @@ goog.provide('Blockly.WorkspaceAudio'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.userAgent'); @@ -135,7 +134,7 @@ Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { // Don't play one sound on top of another. var now = new Date; if (this.lastSound_ != null && - now - this.lastSound_ < Blockly.SOUND_LIMIT) { + now - this.lastSound_ < Blockly.internalConstants.SOUND_LIMIT) { return; } this.lastSound_ = now; diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 96ff41ac4..6ecf8b041 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -21,6 +21,7 @@ goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); goog.require('Blockly.IPositionable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Touch'); goog.require('Blockly.uiPosition'); goog.require('Blockly.utils'); @@ -337,17 +338,18 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { }, clip); var zoomoutSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'x': -64, 'y': -92, 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')' }, this.zoomOutGroup_); - zoomoutSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoomoutSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach listener. this.onZoomOutWrapper_ = Blockly.browserEvents.conditionalBind( @@ -388,17 +390,18 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { }, clip); var zoominSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'x': -32, 'y': -92, 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')' }, this.zoomInGroup_); - zoominSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoominSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach listener. this.onZoomInWrapper_ = Blockly.browserEvents.conditionalBind( @@ -456,16 +459,17 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { }, clip); var zoomresetSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -92, 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')' }, this.zoomResetGroup_); - zoomresetSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoomresetSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach event listeners. this.onZoomResetWrapper_ = Blockly.browserEvents.conditionalBind( diff --git a/tests/deps.js b/tests/deps.js index d7e7ec201..abbcce849 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -177,7 +177,7 @@ goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'] goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); -goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); @@ -206,7 +206,7 @@ goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); -goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']); goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -214,6 +214,6 @@ goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.Workspa goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From ad5836b26d73e153cc0f8499abdfa2534f3a94bd Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:57:48 -0700 Subject: [PATCH 40/48] Convert more names to use internalConstants --- blocks/procedures.js | 6 ++++-- core/block_svg.js | 3 ++- core/contextmenu.js | 9 ++++----- core/gesture.js | 8 ++++---- core/insertion_marker_manager.js | 7 +++---- core/rendered_connection.js | 21 +++++++++++++-------- core/utils.js | 16 ++++++++-------- core/workspace_svg.js | 12 ++++++------ tests/deps.js | 14 +++++++------- 9 files changed, 51 insertions(+), 45 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 644d7a751..328bc89e0 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -18,6 +18,7 @@ goog.require('Blockly.Comment'); goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Mutator'); goog.require('Blockly.Warning'); @@ -867,8 +868,9 @@ Blockly.Blocks['procedures_callnoreturn'] = { var block = Blockly.utils.xml.createElement('block'); block.setAttribute('type', this.defType_); var xy = this.getRelativeToSurfaceXY(); - var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); - var y = xy.y + Blockly.SNAP_RADIUS * 2; + var x = + xy.x + Blockly.internalConstants.SNAP_RADIUS * (this.RTL ? -1 : 1); + var y = xy.y + Blockly.internalConstants.SNAP_RADIUS * 2; block.setAttribute('x', x); block.setAttribute('y', y); var mutation = this.mutationToDom(); diff --git a/core/block_svg.js b/core/block_svg.js index 08e5addcb..f7da81fe3 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1550,7 +1550,8 @@ Blockly.BlockSvg.prototype.bumpNeighbours = function() { connection.targetBlock().bumpNeighbours(); } - var neighbours = connection.neighbours(Blockly.SNAP_RADIUS); + var neighbours = + connection.neighbours(Blockly.internalConstants.SNAP_RADIUS); for (var j = 0, otherConnection; (otherConnection = neighbours[j]); j++) { // If both connections are connected, that's probably fine. But if diff --git a/core/contextmenu.js b/core/contextmenu.js index e070207b7..3bfcda167 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -17,11 +17,10 @@ goog.provide('Blockly.ContextMenu'); goog.require('Blockly.browserEvents'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockCreate'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Menu'); goog.require('Blockly.MenuItem'); goog.require('Blockly.Msg'); @@ -195,11 +194,11 @@ Blockly.ContextMenu.callbackFactory = function(block, xml) { // Move the new block next to the old block. var xy = block.getRelativeToSurfaceXY(); if (block.RTL) { - xy.x -= Blockly.SNAP_RADIUS; + xy.x -= Blockly.internalConstants.SNAP_RADIUS; } else { - xy.x += Blockly.SNAP_RADIUS; + xy.x += Blockly.internalConstants.SNAP_RADIUS; } - xy.y += Blockly.SNAP_RADIUS * 2; + xy.y += Blockly.internalConstants.SNAP_RADIUS * 2; newBlock.moveBy(xy.x, xy.y); } finally { Blockly.Events.enable(); diff --git a/core/gesture.js b/core/gesture.js index 55378930b..77a720527 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -18,11 +18,10 @@ goog.require('Blockly.blockAnimations'); goog.require('Blockly.BlockDragger'); goog.require('Blockly.browserEvents'); goog.require('Blockly.BubbleDragger'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); @@ -295,8 +294,9 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - var limitRadius = - this.flyout_ ? Blockly.FLYOUT_DRAG_RADIUS : Blockly.DRAG_RADIUS; + var limitRadius = this.flyout_ ? + Blockly.internalConstants.FLYOUT_DRAG_RADIUS : + Blockly.internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index d0fea4502..bad4f28bc 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -15,9 +15,8 @@ goog.provide('Blockly.InsertionMarkerManager'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); +goog.require('Blockly.internalConstants'); goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.RenderedConnection'); @@ -439,9 +438,9 @@ Blockly.InsertionMarkerManager.prototype.getStartRadius_ = function() { // By increasing radiusConnection when a connection already exists, // we never "lose" the connection from the offset. if (this.closestConnection_ && this.localConnection_) { - return Blockly.CONNECTING_SNAP_RADIUS; + return Blockly.internalConstants.CONNECTING_SNAP_RADIUS; } - return Blockly.SNAP_RADIUS; + return Blockly.internalConstants.SNAP_RADIUS; }; /** diff --git a/core/rendered_connection.js b/core/rendered_connection.js index f9d3864e3..f229a2fac 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -14,8 +14,7 @@ goog.provide('Blockly.RenderedConnection'); goog.require('Blockly.Connection'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.deprecation'); @@ -173,17 +172,23 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { // Raise it to the top for extra visibility. var selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); - var dx = (staticConnection.x + Blockly.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x; - var dy = (staticConnection.y + Blockly.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.y; + var dx = + (staticConnection.x + Blockly.internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.x; + var dy = + (staticConnection.y + Blockly.internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.y; if (reverse) { // When reversing a bump due to an uneditable block, bump up. dy = -dy; } if (rootBlock.RTL) { - dx = (staticConnection.x - Blockly.SNAP_RADIUS - - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x; + dx = (staticConnection.x - Blockly.internalConstants.SNAP_RADIUS - + Math.floor( + Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.x; } rootBlock.moveBy(dx, dy); selected || rootBlock.removeSelect(); diff --git a/core/utils.js b/core/utils.js index 171e83422..8213d38d9 100644 --- a/core/utils.js +++ b/core/utils.js @@ -18,8 +18,7 @@ */ goog.provide('Blockly.utils'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.Coordinate'); @@ -194,13 +193,13 @@ Blockly.utils.getScrollDeltaPixels = function(e) { }; case 0x01: // Line mode. return { - x: e.deltaX * Blockly.LINE_MODE_MULTIPLIER, - y: e.deltaY * Blockly.LINE_MODE_MULTIPLIER + x: e.deltaX * Blockly.internalConstants.LINE_MODE_MULTIPLIER, + y: e.deltaY * Blockly.internalConstants.LINE_MODE_MULTIPLIER }; case 0x02: // Page mode. return { - x: e.deltaX * Blockly.PAGE_MODE_MULTIPLIER, - y: e.deltaY * Blockly.PAGE_MODE_MULTIPLIER + x: e.deltaX * Blockly.internalConstants.PAGE_MODE_MULTIPLIER, + y: e.deltaY * Blockly.internalConstants.PAGE_MODE_MULTIPLIER }; } }; @@ -634,8 +633,9 @@ Blockly.utils.parseBlockColour = function(colour) { if (!isNaN(hue) && 0 <= hue && hue <= 360) { return { hue: hue, - hex: Blockly.utils.colour.hsvToHex(hue, Blockly.HSV_SATURATION, - Blockly.HSV_VALUE * 255) + hex: Blockly.utils.colour.hsvToHex( + hue, Blockly.internalConstants.HSV_SATURATION, + Blockly.internalConstants.HSV_VALUE * 255) }; } else { var hex = Blockly.utils.colour.parse(dereferenced); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 21ee217ae..f62107e4f 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -17,8 +17,6 @@ goog.require('Blockly.BlockSvg'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.ConnectionDB'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenuRegistry'); goog.require('Blockly.Events'); @@ -31,6 +29,7 @@ goog.require('Blockly.Events.ViewportChange'); goog.require('Blockly.Gesture'); goog.require('Blockly.Grid'); goog.require('Blockly.IASTNodeLocationSvg'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.MarkerManager'); /** @suppress {extraRequire} */ goog.require('Blockly.MetricsManager'); @@ -1521,7 +1520,8 @@ Blockly.WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock) { // Check for blocks in snap range to any of its connections. var connections = block.getConnections_(false); for (var i = 0, connection; (connection = connections[i]); i++) { - var neighbour = connection.closest(Blockly.SNAP_RADIUS, + var neighbour = connection.closest( + Blockly.internalConstants.SNAP_RADIUS, new Blockly.utils.Coordinate(blockX, blockY)); if (neighbour.connection) { collide = true; @@ -1531,11 +1531,11 @@ Blockly.WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock) { } if (collide) { if (this.RTL) { - blockX -= Blockly.SNAP_RADIUS; + blockX -= Blockly.internalConstants.SNAP_RADIUS; } else { - blockX += Blockly.SNAP_RADIUS; + blockX += Blockly.internalConstants.SNAP_RADIUS; } - blockY += Blockly.SNAP_RADIUS * 2; + blockY += Blockly.internalConstants.SNAP_RADIUS * 2; } } while (collide); block.moveBy(blockX, blockY); diff --git a/tests/deps.js b/tests/deps.js index abbcce849..a41eba2bb 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -3,7 +3,7 @@ goog.addDependency('../../blocks/lists.js', ['Blockly.Constants.Lists'], ['Block goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Constants.Logic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Mutator']); goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); -goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); +goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -24,7 +24,7 @@ goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionCheck goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); @@ -66,13 +66,13 @@ goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Bl goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.constants', 'Blockly.utils.deprecation']); -goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); -goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); +goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); @@ -122,7 +122,7 @@ goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils.xml']); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); -goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); @@ -178,7 +178,7 @@ goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.brows goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], [], {'lang': 'es6', 'module': 'goog'}); @@ -212,7 +212,7 @@ goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.Works goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); -goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From 8b5f5f72d632ecbcaa55277a08c56b825ef6cf82 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:10:34 -0700 Subject: [PATCH 41/48] Refer to more constants through internalConstants --- blocks/procedures.js | 6 ++---- core/block_svg.js | 8 ++++---- core/blockly.js | 5 +++-- core/gesture.js | 2 +- core/insertion_marker_manager.js | 6 ++++-- core/mutator.js | 3 ++- core/rendered_connection.js | 2 +- core/touch.js | 6 ++---- tests/deps.js | 8 ++++---- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 328bc89e0..644d7a751 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -18,7 +18,6 @@ goog.require('Blockly.Comment'); goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.internalConstants'); goog.require('Blockly.Mutator'); goog.require('Blockly.Warning'); @@ -868,9 +867,8 @@ Blockly.Blocks['procedures_callnoreturn'] = { var block = Blockly.utils.xml.createElement('block'); block.setAttribute('type', this.defType_); var xy = this.getRelativeToSurfaceXY(); - var x = - xy.x + Blockly.internalConstants.SNAP_RADIUS * (this.RTL ? -1 : 1); - var y = xy.y + Blockly.internalConstants.SNAP_RADIUS * 2; + var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); + var y = xy.y + Blockly.SNAP_RADIUS * 2; block.setAttribute('x', x); block.setAttribute('y', y); var mutation = this.mutationToDom(); diff --git a/core/block_svg.js b/core/block_svg.js index f7da81fe3..fd5be3212 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -18,7 +18,6 @@ goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockRendering.IPathObject'); goog.require('Blockly.browserEvents'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenuRegistry'); @@ -31,6 +30,7 @@ goog.require('Blockly.IASTNodeLocationSvg'); goog.require('Blockly.IBoundedElement'); goog.require('Blockly.ICopyable'); goog.require('Blockly.IDraggable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.RenderedConnection'); goog.require('Blockly.TabNavigateCursor'); @@ -688,7 +688,7 @@ Blockly.BlockSvg.prototype.updateCollapsed_ = function() { icon.setVisible(false); } - var text = this.toString(Blockly.COLLAPSE_CHARS); + var text = this.toString(Blockly.internalConstants.COLLAPSE_CHARS); var field = this.getField(collapsedFieldName); if (field) { field.setValue(text); @@ -1586,13 +1586,13 @@ Blockly.BlockSvg.prototype.scheduleSnapAndBump = function() { Blockly.Events.setGroup(group); block.snapToGrid(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY / 2); + }, Blockly.internalConstants.BUMP_DELAY / 2); setTimeout(function() { Blockly.Events.setGroup(group); block.bumpNeighbours(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY); + }, Blockly.internalConstants.BUMP_DELAY); }; /** diff --git a/core/blockly.js b/core/blockly.js index 554e02c8d..94f485c99 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -425,8 +425,9 @@ Blockly.isNumber = function(str) { * @return {string} RGB code, e.g. '#5ba65b'. */ Blockly.hueToHex = function(hue) { - return Blockly.utils.colour.hsvToHex(hue, Blockly.HSV_SATURATION, - Blockly.HSV_VALUE * 255); + return Blockly.utils.colour.hsvToHex( + hue, Blockly.internalConstants.HSV_SATURATION, + Blockly.internalConstants.HSV_VALUE * 255); }; /** diff --git a/core/gesture.js b/core/gesture.js index 77a720527..483d73a25 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -229,7 +229,7 @@ Blockly.Gesture = function(e, creatorWorkspace) { * @type {boolean} * @private */ - this.healStack_ = !Blockly.DRAG_STACK; + this.healStack_ = !Blockly.internalConstants.DRAG_STACK; }; /** diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index bad4f28bc..614f7e70b 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -377,8 +377,10 @@ Blockly.InsertionMarkerManager.prototype.shouldUpdatePreviews_ = function( var yDiff = this.localConnection_.y + dxy.y - this.closestConnection_.y; var curDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff); // Slightly prefer the existing preview over a new preview. - return !(candidateClosest && radius > curDistance - - Blockly.CURRENT_CONNECTION_PREFERENCE); + return !( + candidateClosest && + radius > curDistance - + Blockly.internalConstants.CURRENT_CONNECTION_PREFERENCE); } else if (!this.localConnection_ && !this.closestConnection_) { // We weren't showing a preview before, but we should now. return true; diff --git a/core/mutator.js b/core/mutator.js index 1bd6d0988..2733964c7 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -20,6 +20,7 @@ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BubbleOpen'); goog.require('Blockly.Icon'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Options'); goog.require('Blockly.utils'); goog.require('Blockly.utils.dom'); @@ -444,7 +445,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { Blockly.Events.setGroup(group); block.bumpNeighbours(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY); + }, Blockly.internalConstants.BUMP_DELAY); } // Don't update the bubble until the drag has ended, to avoid moving blocks diff --git a/core/rendered_connection.js b/core/rendered_connection.js index f229a2fac..14795c181 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -471,7 +471,7 @@ Blockly.RenderedConnection.prototype.onFailedConnect = this.bumpAwayFrom(otherConnection); Blockly.Events.setGroup(false); } - }.bind(this), Blockly.BUMP_DELAY); + }.bind(this), Blockly.internalConstants.BUMP_DELAY); } }; diff --git a/core/touch.js b/core/touch.js index b6668c398..7dc578663 100644 --- a/core/touch.js +++ b/core/touch.js @@ -16,8 +16,7 @@ */ goog.provide('Blockly.Touch'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.string'); @@ -107,8 +106,7 @@ Blockly.longStart = function(e, gesture) { if (gesture) { gesture.handleRightClick(e); } - - }, Blockly.LONGPRESS); + }, Blockly.internalConstants.LONGPRESS); }; /** diff --git a/tests/deps.js b/tests/deps.js index a41eba2bb..39f55df61 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -3,7 +3,7 @@ goog.addDependency('../../blocks/lists.js', ['Blockly.Constants.Lists'], ['Block goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Constants.Logic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Mutator']); goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); -goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.internalConstants'], {'lang': 'es5'}); +goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -11,7 +11,7 @@ goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); @@ -116,7 +116,7 @@ goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEven goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); -goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.constants']); goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); @@ -175,7 +175,7 @@ goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.BlockSvg', 'Blockly.CollapsibleToolboxCategory', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.ToolboxItemSelect', 'Blockly.IAutoHideable', 'Blockly.IKeyboardAccessible', 'Blockly.IStyleable', 'Blockly.IToolbox', 'Blockly.Options', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem']); goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); -goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); +goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); From b3f837a8d2d9152bad0dff2b54278de32f750733 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:24:59 -0700 Subject: [PATCH 42/48] Replace references to constants with internalConstants --- core/connection_checker.js | 5 ++--- core/field_variable.js | 22 ++++++++++------------ core/generator.js | 7 +++---- core/names.js | 17 +++++++++-------- core/procedures.js | 8 ++++---- core/rendered_connection.js | 5 +++-- core/variables.js | 7 +++---- core/workspace_svg.js | 9 ++++++--- tests/deps.js | 12 ++++++------ 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 4bd7bd4e2..5dcaef376 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -16,11 +16,10 @@ goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); +const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); /** @@ -144,7 +143,7 @@ ConnectionChecker.prototype.doSafetyChecks = function(a, b) { } if (blockA == blockB) { return Connection.REASON_SELF_CONNECTION; - } else if (b.type != Blockly.OPPOSITE_TYPE[a.type]) { + } else if (b.type != OPPOSITE_TYPE[a.type]) { return Connection.REASON_WRONG_TYPE; } else if (blockA.workspace !== blockB.workspace) { return Connection.REASON_DIFFERENT_WORKSPACES; diff --git a/core/field_variable.js b/core/field_variable.js index 18f2d20b4..e5e379c13 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -12,13 +12,11 @@ goog.provide('Blockly.FieldVariable'); -/** @suppress {extraRequire} */ -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.FieldDropdown'); goog.require('Blockly.fieldRegistry'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils'); goog.require('Blockly.utils.object'); @@ -417,14 +415,14 @@ Blockly.FieldVariable.dropdownCreate = function() { // Set the UUID as the internal representation of the variable. options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } - options.push([Blockly.Msg['RENAME_VARIABLE'], Blockly.RENAME_VARIABLE_ID]); + options.push([ + Blockly.Msg['RENAME_VARIABLE'], Blockly.internalConstants.RENAME_VARIABLE_ID + ]); if (Blockly.Msg['DELETE_VARIABLE']) { - options.push( - [ - Blockly.Msg['DELETE_VARIABLE'].replace('%1', name), - Blockly.DELETE_VARIABLE_ID - ] - ); + options.push([ + Blockly.Msg['DELETE_VARIABLE'].replace('%1', name), + Blockly.internalConstants.DELETE_VARIABLE_ID + ]); } return options; @@ -442,12 +440,12 @@ Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { var id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { - if (id == Blockly.RENAME_VARIABLE_ID) { + if (id == Blockly.internalConstants.RENAME_VARIABLE_ID) { // Rename variable. Blockly.Variables.renameVariable( this.sourceBlock_.workspace, this.variable_); return; - } else if (id == Blockly.DELETE_VARIABLE_ID) { + } else if (id == Blockly.internalConstants.DELETE_VARIABLE_ID) { // Delete variable. this.sourceBlock_.workspace.deleteVariableById(this.variable_.getId()); return; diff --git a/core/generator.js b/core/generator.js index d2af08852..e365c69ba 100644 --- a/core/generator.js +++ b/core/generator.js @@ -14,8 +14,7 @@ goog.provide('Blockly.Generator'); goog.require('Blockly.Block'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils.deprecation'); goog.requireType('Blockly.Names'); @@ -451,8 +450,8 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { */ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { - var functionName = this.nameDB_.getDistinctName(desiredName, - Blockly.PROCEDURE_CATEGORY_NAME); + var functionName = this.nameDB_.getDistinctName( + desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; var codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); diff --git a/core/names.js b/core/names.js index 3abd27f9e..a559321cf 100644 --- a/core/names.js +++ b/core/names.js @@ -12,8 +12,7 @@ goog.provide('Blockly.Names'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.requireType('Blockly.VariableMap'); @@ -77,7 +76,7 @@ Blockly.Names.prototype.setVariableMap = function(map) { /** * Get the name for a user-defined variable, based on its ID. * This should only be used for variables of realm - * Blockly.VARIABLE_CATEGORY_NAME. + * Blockly.internalConstants.VARIABLE_CATEGORY_NAME. * @param {string} id The ID to look up in the variable map. * @return {?string} The name of the referenced variable, or null if there was * no variable map or the variable was not found in the map. @@ -106,7 +105,8 @@ Blockly.Names.prototype.getNameForUserVariable_ = function(id) { Blockly.Names.prototype.populateVariables = function(workspace) { var variables = Blockly.Variables.allUsedVarModels(workspace); for (var i = 0; i < variables.length; i++) { - this.getName(variables[i].getId(), Blockly.VARIABLE_CATEGORY_NAME); + this.getName( + variables[i].getId(), Blockly.internalConstants.VARIABLE_CATEGORY_NAME); } }; @@ -119,7 +119,8 @@ Blockly.Names.prototype.populateProcedures = function(workspace) { // Flatten the return vs no-return procedure lists. procedures = procedures[0].concat(procedures[1]); for (var i = 0; i < procedures.length; i++) { - this.getName(procedures[i][0], Blockly.PROCEDURE_CATEGORY_NAME); + this.getName( + procedures[i][0], Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); } }; @@ -133,7 +134,7 @@ Blockly.Names.prototype.populateProcedures = function(workspace) { */ Blockly.Names.prototype.getName = function(nameOrId, realm) { var name = nameOrId; - if (realm == Blockly.VARIABLE_CATEGORY_NAME) { + if (realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME) { var varName = this.getNameForUserVariable_(nameOrId); if (varName) { // Successful ID lookup. @@ -142,7 +143,7 @@ Blockly.Names.prototype.getName = function(nameOrId, realm) { } var normalizedName = name.toLowerCase(); - var isVar = realm == Blockly.VARIABLE_CATEGORY_NAME || + var isVar = realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME || realm == Blockly.Names.DEVELOPER_VARIABLE_TYPE; var prefix = isVar ? this.variablePrefix_ : ''; @@ -189,7 +190,7 @@ Blockly.Names.prototype.getDistinctName = function(name, realm) { } safeName += i; this.dbReverse_[safeName] = true; - var isVar = realm == Blockly.VARIABLE_CATEGORY_NAME || + var isVar = realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME || realm == Blockly.Names.DEVELOPER_VARIABLE_TYPE; var prefix = isVar ? this.variablePrefix_ : ''; return prefix + safeName; diff --git a/core/procedures.js b/core/procedures.js index 984ef03fa..3323bb130 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -17,12 +17,11 @@ goog.provide('Blockly.Procedures'); goog.require('Blockly.Blocks'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Field'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.Names'); goog.require('Blockly.utils.xml'); @@ -37,9 +36,10 @@ goog.requireType('Blockly.WorkspaceSvg'); /** * Constant to separate procedure names from variables and generated functions * when running generators. - * @deprecated Use Blockly.PROCEDURE_CATEGORY_NAME + * @deprecated Use Blockly.internalConstants.PROCEDURE_CATEGORY_NAME */ -Blockly.Procedures.NAME_TYPE = Blockly.PROCEDURE_CATEGORY_NAME; +Blockly.Procedures.NAME_TYPE = + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME; /** * The default argument for a procedures_mutatorarg block. diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 14795c181..cddda9200 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -50,8 +50,9 @@ Blockly.RenderedConnection = function(source, type) { * @const {!Blockly.ConnectionDB} * @private */ - this.dbOpposite_ = source.workspace - .connectionDBList[Blockly.OPPOSITE_TYPE[type]]; + this.dbOpposite_ = + source.workspace + .connectionDBList[Blockly.internalConstants.OPPOSITE_TYPE[type]]; /** * Workspace units, (0, 0) is top left of block. diff --git a/core/variables.js b/core/variables.js index 1c091898e..223838a2b 100644 --- a/core/variables.js +++ b/core/variables.js @@ -17,8 +17,7 @@ goog.provide('Blockly.Variables'); goog.require('Blockly.Blocks'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils'); goog.require('Blockly.utils.xml'); @@ -31,9 +30,9 @@ goog.requireType('Blockly.Workspace'); /** * Constant to separate variable names from procedures and generated functions * when running generators. - * @deprecated Use Blockly.VARIABLE_CATEGORY_NAME + * @deprecated Use Blockly.internalConstants.VARIABLE_CATEGORY_NAME */ -Blockly.Variables.NAME_TYPE = Blockly.VARIABLE_CATEGORY_NAME; +Blockly.Variables.NAME_TYPE = Blockly.internalConstants.VARIABLE_CATEGORY_NAME; /** * Find all user-created variables that are in use in the workspace. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index f62107e4f..1c3cee44f 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -180,15 +180,18 @@ Blockly.WorkspaceSvg = function( this.flyoutButtonCallbacks_ = Object.create(null); if (Blockly.Variables && Blockly.Variables.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.VARIABLE_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.VARIABLE_CATEGORY_NAME, Blockly.Variables.flyoutCategory); } if (Blockly.VariablesDynamic && Blockly.VariablesDynamic.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME, Blockly.VariablesDynamic.flyoutCategory); } if (Blockly.Procedures && Blockly.Procedures.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.PROCEDURE_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME, Blockly.Procedures.flyoutCategory); this.addChangeListener(Blockly.Procedures.mutatorOpenListener); } diff --git a/tests/deps.js b/tests/deps.js index 39f55df61..8570bfd1c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -20,7 +20,7 @@ goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], [' goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); @@ -60,12 +60,12 @@ goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilin goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); +goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.constants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); @@ -117,10 +117,10 @@ goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.uti goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); -goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.constants']); +goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.internalConstants']); goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils.xml']); +goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.xml']); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); @@ -201,7 +201,7 @@ goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); -goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.xml']); +goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.xml']); goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); From cf7a8b95b847be2f6136f121601bc81c5c8674df Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:51:58 -0700 Subject: [PATCH 43/48] Remove extra requires of Blockly.constants --- core/flyout_horizontal.js | 2 -- core/input.js | 2 -- core/keyboard_nav/ast_node.js | 2 -- core/renderers/common/constants.js | 2 -- core/renderers/common/debugger.js | 2 -- core/renderers/common/marker_svg.js | 2 -- core/renderers/common/renderer.js | 2 -- core/renderers/geras/info.js | 2 -- core/renderers/zelos/constants.js | 2 -- core/renderers/zelos/info.js | 2 -- core/renderers/zelos/renderer.js | 2 -- core/xml.js | 3 -- core/zoom_controls.js | 2 -- tests/deps.js | 48 +++++++++++++---------------- 14 files changed, 21 insertions(+), 54 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 485d29617..66e9ff18e 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -14,8 +14,6 @@ goog.provide('Blockly.HorizontalFlyout'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.Flyout'); goog.require('Blockly.registry'); diff --git a/core/input.js b/core/input.js index 57189c278..443bfc83f 100644 --- a/core/input.js +++ b/core/input.js @@ -13,8 +13,6 @@ goog.provide('Blockly.Input'); goog.require('Blockly.Connection'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 37145a090..332e9af8c 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -13,8 +13,6 @@ goog.provide('Blockly.ASTNode'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.Coordinate'); goog.requireType('Blockly.Block'); diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index a21ef85aa..5c73d0510 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -13,8 +13,6 @@ goog.provide('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.dom'); diff --git a/core/renderers/common/debugger.js b/core/renderers/common/debugger.js index 0e99fc613..a6ab9d387 100644 --- a/core/renderers/common/debugger.js +++ b/core/renderers/common/debugger.js @@ -17,8 +17,6 @@ goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Row'); goog.require('Blockly.blockRendering.Types'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); diff --git a/core/renderers/common/marker_svg.js b/core/renderers/common/marker_svg.js index f9559e071..36d12b119 100644 --- a/core/renderers/common/marker_svg.js +++ b/core/renderers/common/marker_svg.js @@ -15,8 +15,6 @@ goog.provide('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.ASTNode'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.MarkerMove'); diff --git a/core/renderers/common/renderer.js b/core/renderers/common/renderer.js index 77df5e518..37e4a883a 100644 --- a/core/renderers/common/renderer.js +++ b/core/renderers/common/renderer.js @@ -20,8 +20,6 @@ goog.require('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.blockRendering.PathObject'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.IRegistrable'); diff --git a/core/renderers/geras/info.js b/core/renderers/geras/info.js index ffc515a17..121e3b353 100644 --- a/core/renderers/geras/info.js +++ b/core/renderers/geras/info.js @@ -19,8 +19,6 @@ goog.require('Blockly.blockRendering.InputRow'); goog.require('Blockly.blockRendering.InRowSpacer'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.geras.InlineInput'); goog.require('Blockly.geras.StatementInput'); goog.require('Blockly.inputTypes'); diff --git a/core/renderers/zelos/constants.js b/core/renderers/zelos/constants.js index bb039250a..2070197cf 100644 --- a/core/renderers/zelos/constants.js +++ b/core/renderers/zelos/constants.js @@ -15,8 +15,6 @@ goog.provide('Blockly.zelos.ConstantProvider'); goog.require('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.object'); diff --git a/core/renderers/zelos/info.js b/core/renderers/zelos/info.js index b7dc3d972..078031756 100644 --- a/core/renderers/zelos/info.js +++ b/core/renderers/zelos/info.js @@ -18,8 +18,6 @@ goog.require('Blockly.blockRendering.InRowSpacer'); goog.require('Blockly.blockRendering.Measurable'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.FieldImage'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); diff --git a/core/renderers/zelos/renderer.js b/core/renderers/zelos/renderer.js index d192fa178..3c5287bbb 100644 --- a/core/renderers/zelos/renderer.js +++ b/core/renderers/zelos/renderer.js @@ -15,8 +15,6 @@ goog.provide('Blockly.zelos.Renderer'); goog.require('Blockly.blockRendering'); goog.require('Blockly.blockRendering.Renderer'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.utils.object'); goog.require('Blockly.zelos.ConstantProvider'); diff --git a/core/xml.js b/core/xml.js index 4140d6528..e581bfd01 100644 --- a/core/xml.js +++ b/core/xml.js @@ -15,9 +15,6 @@ * @namespace */ goog.provide('Blockly.Xml'); - -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.inputTypes'); goog.require('Blockly.utils'); diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 6ecf8b041..7d0d7e6ce 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -14,8 +14,6 @@ goog.provide('Blockly.ZoomControls'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Css'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ diff --git a/tests/deps.js b/tests/deps.js index 8570bfd1c..2d1386395 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); @@ -48,9 +48,9 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -63,14 +63,14 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); @@ -80,7 +80,6 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_collapsible_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem'], ['Blockly.ISelectableToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); @@ -94,23 +93,18 @@ goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.I goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); -<<<<<<< HEAD -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); -======= goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); ->>>>>>> 3a5ddf4d (Rebuild) -goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); @@ -124,19 +118,19 @@ goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); -goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); +goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/geras/highlight_constants.js', ['Blockly.geras.HighlightConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/highlighter.js', ['Blockly.geras.Highlighter'], ['Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); -goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/geras/measurables/inputs.js', ['Blockly.geras.InlineInput', 'Blockly.geras.StatementInput'], ['Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/geras/path_object.js', ['Blockly.geras.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.PathObject', 'Blockly.geras.ConstantProvider', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/geras/renderer.js', ['Blockly.geras.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.geras.ConstantProvider', 'Blockly.geras.Drawer', 'Blockly.geras.HighlightConstantProvider', 'Blockly.geras.PathObject', 'Blockly.geras.RenderInfo', 'Blockly.utils.object']); @@ -152,15 +146,15 @@ goog.addDependency('../../core/renderers/minimalist/info.js', ['Blockly.minimali goog.addDependency('../../core/renderers/minimalist/renderer.js', ['Blockly.minimalist.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.minimalist.ConstantProvider', 'Blockly.minimalist.Drawer', 'Blockly.minimalist.RenderInfo', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/thrasos/info.js', ['Blockly.thrasos', 'Blockly.thrasos.RenderInfo'], ['Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/thrasos/renderer.js', ['Blockly.thrasos.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.thrasos.RenderInfo', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/zelos/drawer.js', ['Blockly.zelos.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.utils.object', 'Blockly.utils.svgPaths', 'Blockly.zelos.RenderInfo']); -goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.TopRow']); +goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.TopRow']); goog.addDependency('../../core/renderers/zelos/marker_svg.js', ['Blockly.zelos.MarkerSvg'], ['Blockly.blockRendering.MarkerSvg', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/zelos/measurables/inputs.js', ['Blockly.zelos.StatementInput'], ['Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/measurables/row_elements.js', ['Blockly.zelos.RightConnectionShape'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/measurables/rows.js', ['Blockly.zelos.BottomRow', 'Blockly.zelos.TopRow'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.TopRow', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/path_object.js', ['Blockly.zelos.PathObject'], ['Blockly.blockRendering.PathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider']); -goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); +goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); @@ -196,7 +190,7 @@ goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); @@ -213,7 +207,7 @@ goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCom goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From 12636da1824cce1eb429d61ca974556e2b1208cb Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 21 Jul 2021 15:47:55 -0700 Subject: [PATCH 44/48] Reorder some requires and rebuild --- core/connection_checker.js | 2 +- core/internal_constants.js | 1 + tests/deps.js | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 5dcaef376..8b2abfaab 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -16,10 +16,10 @@ goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); -const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); +const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); /** diff --git a/core/internal_constants.js b/core/internal_constants.js index b5a8cd568..b97c723b4 100644 --- a/core/internal_constants.js +++ b/core/internal_constants.js @@ -8,6 +8,7 @@ * @fileoverview Module that provides constants for use inside Blockly. Do not * use these constants outside of the core library. * @author fenichel@google.com (Rachel Fenichel) + * @package */ 'use strict'; diff --git a/tests/deps.js b/tests/deps.js index 2d1386395..74d330e51 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); @@ -48,9 +48,9 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -80,6 +80,7 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_collapsible_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem'], ['Blockly.ISelectableToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); @@ -93,18 +94,19 @@ goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.I goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); +goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); @@ -122,7 +124,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); @@ -190,7 +192,7 @@ goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); From c6650f0b8313b9ab93cf8ce3a2badd7a03e8c997 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Wed, 21 Jul 2021 16:53:08 -0700 Subject: [PATCH 45/48] Remove need for require instead of requireType for Block in ASTNode (#5157) --- core/keyboard_nav/ast_node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 332e9af8c..d86a22a4c 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -418,7 +418,7 @@ Blockly.ASTNode.prototype.findPrevForField_ = function() { */ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); - if (!(curLocation instanceof Blockly.Block)) { + if (curLocation.getSourceBlock) { curLocation = /** @type {!Blockly.IASTNodeLocationWithBlock} */ ( curLocation).getSourceBlock(); } From efdc9e3afab6993d69c80799d263492913310d4a Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 09:11:54 -0700 Subject: [PATCH 46/48] Support filepath as first argument and cleanup (#5168) --- scripts/goog_module/convert-file.sh | 125 ++++++++++++++-------------- 1 file changed, 61 insertions(+), 64 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 1861ad7f3..fa66fe0f9 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -1,7 +1,7 @@ #!/bin/bash ####################################### -# Logging functions +# Logging functions. ####################################### COLOR_NONE="\033[0m" GREEN="\033[0;32m" @@ -20,17 +20,24 @@ warn() { err() { echo -e "${RED}[ERROR]:${COLOR_NONE} $*" >&2 } + ####################################### # Checks whether the provided filepath exists. # Arguments: # The filepath to check for existence. +# Optional: Whether to log an error. ####################################### verify-filepath() { - if [[ ! -f "$1" ]]; then - err "File $1 does not exist" + local filepath="$1" + local no_log="$2" + if [[ ! -f "${filepath}" ]]; then + if [[ -z "${no_log}" || "${no_log}" == 'true' ]]; then + err "File ${filepath} does not exist" + fi return 1 fi } + ####################################### # Creates a commit with a message based on the specified step and file. # Arguments: @@ -40,11 +47,11 @@ verify-filepath() { commit-step() { local step="$1" local filepath="$2" - if [ -z "${step}" ]; then + if [[ -z "${step}" ]]; then err "Missing argument (1-4)" return 1 fi - if [ -z "${filepath}" ]; then + if [[ -z "${filepath}" ]]; then err "Missing argument filepath" return 1 fi @@ -78,6 +85,7 @@ commit-step() { git commit -m "${message}" success "created commit with message: \"${message}\"" } + ####################################### # Runs step 2 of the automated conversion. # Arguments: @@ -85,25 +93,10 @@ commit-step() { ####################################### step2 () { local filepath="$1" - if [ -z "${filepath}" ]; then - err "Missing argument filepath" - return 1 - fi - - inf "Verifying single goog.provide declarations..." - local provide_count=$(grep -o 'goog.provide' ${filepath} | wc -l) - if [[ "${provide_count}" -gt "1" ]]; then - err "Cannot convert file with multiple provides. Please split the file first." - return 1 - elif [[ "${provide_count}" -eq "0" ]]; then - err "Cannot convert file without a provide." - return 1 - fi inf "Updating goog.provide declaration..." perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/g' "${filepath}" - inf "Extracting module name..." local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") if [[ -z "${module_name}" ]]; then @@ -117,11 +110,9 @@ step2 () { inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" - inf 'Updating class properties...' - perl -pi -e 's/^'"${module_name}"'((\.\w+)+) =/'"${class_name}"'\1 =/g' "${filepath}" inf "Updating local references to class..." - perl -pi -e 's/'"${module_name}"'([^'\''])/'"${class_name}"'\1/g' "${filepath}" + perl -pi -e 's/'"${module_name}"'(?!['\''\w])/'"${class_name}"'/g' "${filepath}" inf "Appending class export to end of file..." echo "" >> "${filepath}" @@ -140,20 +131,15 @@ step2 () { perl -pi -e 's/'"${module_name}"'\.([^ ]+)/\1/g' "${filepath}" npm run build:deps - success "Completed automation for step 3. Please manually review and add exports for non-private top-level functions." + success "Completed automation for step 2. Please manually review and add exports for non-private top-level functions." } + ####################################### # Runs step 3 of the automated conversion. # Arguments: # The filepath of the file being converted. ####################################### step3() { - local filepath="$1" - if [ -z "${filepath}" ]; then - err "Missing argument filepath" - return 1 - fi - inf "Extracting module name..." local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") if [[ -z "${module_name}" ]]; then @@ -162,10 +148,10 @@ step3() { fi inf "Extracted module name \"${module_name}\"" - local requires=$(perl -nle'print $& while m{^goog.require(|Type)\('\''(.*)'\''\)}g' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') + local requires=$(perl -nle'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") # Process each require - echo "${requires}" | while read -r require ; do + echo "${requires}" | while read -r require; do inf "Processing require \"${require}\"" local usages=$(perl -nle'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) @@ -179,27 +165,25 @@ step3() { # Detect requires overlap # (ex: Blockly.utils require and Blockly.utils.dom also in requires) local requires_overlap=$(echo "${requires}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ ! -z "${requires_overlap}" ]]; then - while read -r requires_overlap_prop ; do + if [[ -n "${requires_overlap}" ]]; then + while read -r requires_overlap_prop; do properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') done <<<"${requires_overlap}" fi # Detect module name overlap # (ex: Blockly require and Blockly.ContextMenuItems module being converted) local module_overlap=$(echo "${module_name}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ ! -z "${module_overlap}" ]]; then + if [[ -n "${module_overlap}" ]]; then properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') fi properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) - if [[ "${direct_access_count}" -eq "0" && ! -z "${properties_accessed}" ]]; then + if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"" - - inf "Updating require declaration for ${require}..." + inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"..." perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - for require_prop in $(echo "${properties_accessed}"); do + for require_prop in echo "${properties_accessed}"; do inf "Updating references of ${require}.${require_prop} to ${require_prop}..." perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" done @@ -215,26 +199,24 @@ step3() { done local missing_requires=$(perl -nle'print $& while m{(?|-s ] " - echo " -h Display help" - echo " -c Create a commit for the specified step [2-4]" - echo " -s Run the specified step [1-4]" + echo "Usage: $0 [-h] [-c |-s ]" + echo " -h Display help and exit" + echo " -c Create a commit for the specified step [2-4]" + echo " -s Run the specified step [1-4]" } -if [ "$1" = "" ]; then +####################################### +# Main entry point. +####################################### +main { + if [ "$1" = "" ]; then help else - command="$1" + local filepath="" + # Support filepath as first argument. + verify-filepath "${filepath}" "false" + if [[ $? -eq 0 ]]; then + filepath="$1" + shift + fi + + local command="$1" shift case $command in - -h) help $@;; - -c) commit-step $@;; - -s) run-step $@;; - *) help;; + -c) commit-step "$@" "${filepath}" ;; + -s) run-step "$@" "${filepath}" ;; + *) err "INVALID ARGUMENT ${command}";; esac fi +} + +main "$@" From 720059e502394ebc44e4d01686d2b67f652a32f5 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 09:59:02 -0700 Subject: [PATCH 47/48] Fix bugs (#5175) --- scripts/goog_module/convert-file.sh | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index fa66fe0f9..24529dab1 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -257,7 +257,7 @@ run-step() { ####################################### # Prints usage information. ####################################### -help { +help() { echo "Conversion steps:" echo " 1. Use IDE to convert var to let/const" echo " 2. Rewrite the goog.provide statement as goog.module and explicitly enumerate exports" @@ -273,26 +273,26 @@ help { ####################################### # Main entry point. ####################################### -main { +main() { if [ "$1" = "" ]; then - help -else - local filepath="" - # Support filepath as first argument. - verify-filepath "${filepath}" "false" - if [[ $? -eq 0 ]]; then - filepath="$1" - shift - fi + help + else + local filepath="" + # Support filepath as first argument. + verify-filepath "$1" "false" + if [[ $? -eq 0 ]]; then + filepath="$1" + shift + fi - local command="$1" - shift - case $command in - -c) commit-step "$@" "${filepath}" ;; - -s) run-step "$@" "${filepath}" ;; - *) err "INVALID ARGUMENT ${command}";; - esac -fi + local command="$1" + shift + case $command in + -c) commit-step "$@" "${filepath}" ;; + -s) run-step "$@" "${filepath}" ;; + *) err "INVALID ARGUMENT ${command}";; + esac + fi } main "$@" From 9d29bff7138b954351c6ed9bee23504ae40cf795 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 10:01:41 -0700 Subject: [PATCH 48/48] Ask before deconstructing properties for a require (#5169) --- scripts/goog_module/convert-file.sh | 35 +++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 24529dab1..8b6bdfc6f 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -20,6 +20,9 @@ warn() { err() { echo -e "${RED}[ERROR]:${COLOR_NONE} $*" >&2 } +reenter_instructions() { + echo -e "${ORANGE}$*${COLOR_NONE}" >&2 +} ####################################### # Checks whether the provided filepath exists. @@ -180,14 +183,32 @@ step3() { if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"..." - perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - - for require_prop in echo "${properties_accessed}"; do - inf "Updating references of ${require}.${require_prop} to ${require_prop}..." - perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" + local confirm='' + while true; do + read -p "Would you like to deconstruct ${require} into \"{${deconstructed_comma}}\"? (y/n): " yn