diff --git a/core/block_dragger.js b/core/block_dragger.js index b7c11e8a3..6e5ac10c1 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -24,6 +24,7 @@ const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); /* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const blockAnimation = goog.require('Blockly.blockAnimations'); +const common = goog.require('Blockly.common'); const dom = goog.require('Blockly.utils.dom'); const events = goog.require('Blockly.Events'); const registry = goog.require('Blockly.registry'); @@ -332,7 +333,7 @@ BlockDragger.prototype.maybeDeleteBlock_ = function() { // Fire a move event, so we know where to go back to for an undo. this.fireMoveEvent_(); this.draggingBlock_.dispose(false, true); - Blockly.draggingConnections = []; + common.draggingConnections.length = 0; return true; } return false; diff --git a/core/block_svg.js b/core/block_svg.js index 57d20c1ba..fbd3dd5dc 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -17,6 +17,7 @@ goog.require('Blockly.Block'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockRendering.IPathObject'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.common'); goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); @@ -824,12 +825,11 @@ Blockly.BlockSvg.prototype.setDragging = function(adding) { var group = this.getSvgRoot(); group.translate_ = ''; group.skew_ = ''; - Blockly.draggingConnections = - Blockly.draggingConnections.concat(this.getConnections_(true)); + Blockly.common.draggingConnections.push(...this.getConnections_(true)); Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDragging'); } else { - Blockly.draggingConnections = []; + Blockly.common.draggingConnections.length = 0; Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDragging'); } diff --git a/core/blockly.js b/core/blockly.js index 7ad87be94..1f8cfa55a 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -57,7 +57,6 @@ goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.Xml'); goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Connection'); goog.requireType('Blockly.ICopyable'); goog.requireType('Blockly.Workspace'); @@ -76,9 +75,14 @@ Blockly.VERSION = 'uncompiled'; // Add a getter and setter pair for Blockly.mainWorkspace, for legacy reasons. Object.defineProperty(Blockly, 'mainWorkspace', { set: function(x) { + Blockly.utils.deprecation.warn( + 'Blockly.mainWorkspace', 'September 2021', 'September 2022'); Blockly.common.setMainWorkspace(x); }, get: function() { + Blockly.utils.deprecation.warn( + 'Blockly.mainWorkspace', 'September 2021', 'September 2022', + 'Blockly.getMainWorkspace()'); return Blockly.common.getMainWorkspace(); } }); @@ -89,27 +93,6 @@ Object.defineProperty(Blockly, 'mainWorkspace', { */ Blockly.selected = null; -/** - * All of the connections on blocks that are currently being dragged. - * @type {!Array} - * @package - */ -Blockly.draggingConnections = []; - -/** - * Cached value for whether 3D is supported. - * @type {?boolean} - * @private - */ -Blockly.cache3dSupported_ = null; - -/** - * Container element to render the WidgetDiv, DropDownDiv and Tooltip. - * @type {?Element} - * @package - */ -Blockly.parentContainer = null; - /** * Returns the dimensions of the specified SVG image. * @param {!SVGElement} svg SVG image. @@ -372,78 +355,6 @@ Blockly.hueToHex = function(hue) { Blockly.internalConstants.HSV_VALUE * 255); }; -/** - * Checks old colour constants are not overwritten by the host application. - * If a constant is overwritten, it prints a console warning directing the - * developer to use the equivalent Msg constant. - * @package - */ -Blockly.checkBlockColourConstants = function() { - Blockly.checkBlockColourConstant_( - 'LOGIC_HUE', ['Blocks', 'logic', 'HUE'], undefined); - Blockly.checkBlockColourConstant_( - 'LOGIC_HUE', ['Constants', 'Logic', 'HUE'], 210); - Blockly.checkBlockColourConstant_( - 'LOOPS_HUE', ['Blocks', 'loops', 'HUE'], undefined); - Blockly.checkBlockColourConstant_( - 'LOOPS_HUE', ['Constants', 'Loops', 'HUE'], 120); - Blockly.checkBlockColourConstant_( - 'MATH_HUE', ['Blocks', 'math', 'HUE'], undefined); - Blockly.checkBlockColourConstant_( - 'MATH_HUE', ['Constants', 'Math', 'HUE'], 230); - Blockly.checkBlockColourConstant_( - 'TEXTS_HUE', ['Blocks', 'texts', 'HUE'], undefined); - Blockly.checkBlockColourConstant_( - 'TEXTS_HUE', ['Constants', 'Text', 'HUE'], 160); - Blockly.checkBlockColourConstant_( - 'LISTS_HUE', ['Blocks', 'lists', 'HUE'], undefined); - Blockly.checkBlockColourConstant_( - 'LISTS_HUE', ['Constants', 'Lists', 'HUE'], 260); - Blockly.checkBlockColourConstant_( - 'COLOUR_HUE', ['Blocks', 'colour', 'HUE'], undefined); - Blockly.checkBlockColourConstant_( - 'COLOUR_HUE', ['Constants', 'Colour', 'HUE'], 20); - Blockly.checkBlockColourConstant_( - 'VARIABLES_HUE', ['Blocks', 'variables', 'HUE'], undefined); - Blockly.checkBlockColourConstant_( - 'VARIABLES_HUE', ['Constants', 'Variables', 'HUE'], 330); - // Blockly.Blocks.variables_dynamic.HUE never existed. - Blockly.checkBlockColourConstant_( - 'VARIABLES_DYNAMIC_HUE', ['Constants', 'VariablesDynamic', 'HUE'], 310); - Blockly.checkBlockColourConstant_( - 'PROCEDURES_HUE', ['Blocks', 'procedures', 'HUE'], undefined); - // Blockly.Constants.Procedures.HUE never existed. -}; - -/** - * Checks for a constant in the Blockly namespace, verifying it is undefined or - * has the old/original value. Prints a warning if this is not true. - * @param {string} msgName The Msg constant identifier. - * @param {!Array} blocklyNamePath The name parts of the tested - * constant. - * @param {number|undefined} expectedValue The expected value of the constant. - * @private - */ -Blockly.checkBlockColourConstant_ = function( - msgName, blocklyNamePath, expectedValue) { - var namePath = 'Blockly'; - var value = Blockly; - for (var i = 0; i < blocklyNamePath.length; ++i) { - namePath += '.' + blocklyNamePath[i]; - if (value) { - value = value[blocklyNamePath[i]]; - } - } - - if (value && value !== expectedValue) { - var warningPattern = (expectedValue === undefined) ? - '%1 has been removed. Use Blockly.Msg["%2"].' : - '%1 is deprecated and unused. Override Blockly.Msg["%2"].'; - var warning = warningPattern.replace('%1', namePath).replace('%2', msgName); - console.warn(warning); - } -}; - /** * Set the parent container. This is the container element that the WidgetDiv, * DropDownDiv, and Tooltip are rendered into the first time `Blockly.inject` @@ -451,9 +362,7 @@ Blockly.checkBlockColourConstant_ = function( * This method is a NOP if called after the first ``Blockly.inject``. * @param {!Element} container The container element. */ -Blockly.setParentContainer = function(container) { - Blockly.parentContainer = container; -}; +Blockly.setParentContainer = Blockly.common.setParentContainer; /** Aliases. */ diff --git a/core/common.js b/core/common.js index d9a6b9638..b6d7ad369 100644 --- a/core/common.js +++ b/core/common.js @@ -14,6 +14,8 @@ goog.module('Blockly.common'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.requireType('Blockly.Connection'); /* eslint-disable-next-line no-unused-vars */ const Workspace = goog.requireType('Blockly.Workspace'); @@ -44,3 +46,37 @@ const setMainWorkspace = function(workspace) { mainWorkspace = workspace; }; exports.setMainWorkspace = setMainWorkspace; + +/** + * Container element in which to render the WidgetDiv, DropDownDiv and Tooltip. + * @type {?Element} + */ +let parentContainer; + +/** + * Get the container element in which to render the WidgetDiv, DropDownDiv and\ + * Tooltip. + * @return {?Element} The parent container. + */ +const getParentContainer = function() { + return parentContainer; +}; +exports.getParentContainer = getParentContainer; + +/** + * Set the parent container. This is the container element that the WidgetDiv, + * DropDownDiv, and Tooltip are rendered into the first time `Blockly.inject` + * is called. + * This method is a NOP if called after the first ``Blockly.inject``. + * @param {!Element} newParent The container element. + */ +const setParentContainer = function(newParent) { + parentContainer = newParent; +}; +exports.setParentContainer = setParentContainer; + +/** + * All of the connections on blocks that are currently being dragged. + * @type {!Array} + */ +exports.draggingConnections = []; diff --git a/core/connection_checker.js b/core/connection_checker.js index 20a582aac..76162b017 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -19,6 +19,7 @@ const Connection = goog.require('Blockly.Connection'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); /* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const common = goog.require('Blockly.common'); const connectionTypes = goog.require('Blockly.connectionTypes'); const internalConstants = goog.require('Blockly.internalConstants'); const registry = goog.require('Blockly.registry'); @@ -239,7 +240,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } // Don't let blocks try to connect to themselves or ones they nest. - if (Blockly.draggingConnections.indexOf(b) != -1) { + if (common.draggingConnections.indexOf(b) != -1) { return false; } @@ -263,7 +264,7 @@ ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { } // Don't let blocks try to connect to themselves or ones they nest. - if (Blockly.draggingConnections.indexOf(b) != -1) { + if (common.draggingConnections.indexOf(b) != -1) { return false; } diff --git a/core/dropdowndiv.js b/core/dropdowndiv.js index bf5eddb69..5ebb22a5e 100644 --- a/core/dropdowndiv.js +++ b/core/dropdowndiv.js @@ -163,7 +163,7 @@ Blockly.DropDownDiv.createDom = function() { } var div = document.createElement('div'); div.className = 'blocklyDropDownDiv'; - var container = Blockly.parentContainer || document.body; + var container = Blockly.common.getParentContainer() || document.body; container.appendChild(div); /** * The div element. diff --git a/core/inject.js b/core/inject.js index 6bb3e6077..3b3715b0f 100644 --- a/core/inject.js +++ b/core/inject.js @@ -45,8 +45,6 @@ goog.requireType('Blockly.BlockSvg'); * @return {!Blockly.WorkspaceSvg} Newly created main workspace. */ Blockly.inject = function(container, opt_options) { - Blockly.checkBlockColourConstants(); - if (typeof container == 'string') { container = document.getElementById(container) || document.querySelector(container); diff --git a/core/tooltip.js b/core/tooltip.js index 12819e13f..d93825815 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -22,6 +22,7 @@ goog.provide('Blockly.Tooltip'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.common'); goog.require('Blockly.utils.string'); @@ -170,7 +171,7 @@ Blockly.Tooltip.createDom = function() { // Create an HTML container for popup overlays (e.g. editor widgets). Blockly.Tooltip.DIV = document.createElement('div'); Blockly.Tooltip.DIV.className = 'blocklyTooltipDiv'; - var container = Blockly.parentContainer || document.body; + var container = Blockly.common.getParentContainer() || document.body; container.appendChild(Blockly.Tooltip.DIV); }; diff --git a/core/widgetdiv.js b/core/widgetdiv.js index 8b7de7dac..106dce645 100644 --- a/core/widgetdiv.js +++ b/core/widgetdiv.js @@ -67,7 +67,7 @@ Blockly.WidgetDiv.createDom = function() { */ Blockly.WidgetDiv.DIV = document.createElement('div'); Blockly.WidgetDiv.DIV.className = 'blocklyWidgetDiv'; - var container = Blockly.parentContainer || document.body; + var container = Blockly.common.getParentContainer() || document.body; container.appendChild(Blockly.WidgetDiv.DIV); }; diff --git a/tests/deps.js b/tests/deps.js index 9b5264dc5..abed86ec5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -10,8 +10,8 @@ goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.Vari goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.common', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.common', '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'], {'lang': 'es6'}); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.clipboard', 'Blockly.common', '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'], {'lang': 'es6', 'module': 'goog'}); @@ -22,7 +22,7 @@ goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubbl goog.addDependency('../../core/common.js', ['Blockly.common'], [], {'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.internalConstants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.common', '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'}); @@ -173,7 +173,7 @@ goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.Colla goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.Css', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); 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', 'Blockly.utils.IdGenerator'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); +goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.common', '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': 'es6', 'module': 'goog'});