From c59f083485ca474d01dd2af75926073fe8864459 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 29 Jul 2021 14:21:57 -0700 Subject: [PATCH] Migrate core/positionable_helpers.js named requires --- core/positionable_helpers.js | 45 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/core/positionable_helpers.js b/core/positionable_helpers.js index 9ca1d0759..6579a5a4e 100644 --- a/core/positionable_helpers.js +++ b/core/positionable_helpers.js @@ -13,13 +13,12 @@ goog.module('Blockly.uiPosition'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Scrollbar'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.toolbox'); - -goog.requireType('Blockly.MetricsManager'); -goog.requireType('Blockly.utils.Size'); -goog.requireType('Blockly.WorkspaceSvg'); +const MetricsManager = goog.requireType('Blockly.MetricsManager'); +const Rect = goog.require('Blockly.utils.Rect'); +const Scrollbar = goog.require('Blockly.Scrollbar'); +const Size = goog.requireType('Blockly.utils.Size'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const toolbox = goog.require('Blockly.utils.toolbox'); /** @@ -73,13 +72,13 @@ exports.bumpDirection = bumpDirection; * elements. * @param {!Position} position The starting * horizontal and vertical position. - * @param {!Blockly.utils.Size} size the size of the UI element to get a start + * @param {!Size} size the size of the UI element to get a start * position for. * @param {number} horizontalPadding The horizontal padding to use. * @param {number} verticalPadding The vertical padding to use. - * @param {!Blockly.MetricsManager.UiMetrics} metrics The workspace UI metrics. - * @param {!Blockly.WorkspaceSvg} workspace The workspace. - * @return {!Blockly.utils.Rect} The suggested start position. + * @param {!MetricsManager.UiMetrics} metrics The workspace UI metrics. + * @param {!WorkspaceSvg} workspace The workspace. + * @return {!Rect} The suggested start position. */ const getStartPositionRect = function( position, size, horizontalPadding, @@ -92,13 +91,13 @@ const getStartPositionRect = function( horizontalPosition.LEFT) { left = metrics.absoluteMetrics.left + horizontalPadding; if (hasVerticalScrollbar && workspace.RTL) { - left += Blockly.Scrollbar.scrollbarThickness; + left += Scrollbar.scrollbarThickness; } } else { // position.horizontal == horizontalPosition.RIGHT left = metrics.absoluteMetrics.left + metrics.viewMetrics.width - size.width - horizontalPadding; if (hasVerticalScrollbar && !workspace.RTL) { - left -= Blockly.Scrollbar.scrollbarThickness; + left -= Scrollbar.scrollbarThickness; } } // Vertical positioning. @@ -111,10 +110,10 @@ const getStartPositionRect = function( size.height - verticalPadding; if (workspace.scrollbar && workspace.scrollbar.canScrollHorizontally()) { // The scrollbars are always positioned on the bottom if they exist. - top -= Blockly.Scrollbar.scrollbarThickness; + top -= Scrollbar.scrollbarThickness; } } - return new Blockly.utils.Rect( + return new Rect( top, top + size.height, left, left + size.width); }; /** @package */ @@ -125,17 +124,17 @@ exports.getStartPositionRect = getStartPositionRect; * the toolbox. * If in horizontal orientation, defaults to the bottom corner. If in vertical * orientation, defaults to the right corner. - * @param {!Blockly.WorkspaceSvg} workspace The workspace. - * @param {!Blockly.MetricsManager.UiMetrics} metrics The workspace metrics. + * @param {!WorkspaceSvg} workspace The workspace. + * @param {!MetricsManager.UiMetrics} metrics The workspace metrics. * @return {!Position} The suggested corner position. * @package */ const getCornerOppositeToolbox = function(workspace, metrics) { const leftCorner = - metrics.toolboxMetrics.position !== Blockly.utils.toolbox.Position.LEFT && + metrics.toolboxMetrics.position !== toolbox.Position.LEFT && (!workspace.horizontalLayout || workspace.RTL); const topCorner = - metrics.toolboxMetrics.position === Blockly.utils.toolbox.Position.BOTTOM; + metrics.toolboxMetrics.position === toolbox.Position.BOTTOM; const hPosition = leftCorner ? horizontalPosition.LEFT : horizontalPosition.RIGHT; const vPosition = topCorner ? @@ -152,13 +151,13 @@ exports.getCornerOppositeToolbox = getCornerOppositeToolbox; * Returns a position Rect based on a starting position that is bumped * so that it doesn't intersect with any of the provided savedPositions. This * method does not check that the bumped position is still within bounds. - * @param {!Blockly.utils.Rect} startRect The starting position to use. + * @param {!Rect} startRect The starting position to use. * @param {number} margin The margin to use between elements when bumping. * @param {!bumpDirection} bumpDir The direction to bump if there is a collision * with an existing UI element. - * @param {!Array} savedPositions List of rectangles that + * @param {!Array} savedPositions List of rectangles that * represent the positions of UI elements already placed. - * @return {!Blockly.utils.Rect} The suggested position rectangle. + * @return {!Rect} The suggested position rectangle. */ const bumpPositionRect = function( startRect, margin, bumpDir, savedPositions) { @@ -178,7 +177,7 @@ const bumpPositionRect = function( top = otherEl.bottom + margin; } // Recheck other savedPositions - boundingRect = new Blockly.utils.Rect( + boundingRect = new Rect( top, top + height, left, left + width); i = -1; }