From adc78d192c6b5852f0cfc5363777a5ac2a882465 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:24:09 -0700 Subject: [PATCH] Migrate core/flyout_vertical.js to ES6 const/let --- core/flyout_vertical.js | 106 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index a09b3fb8e..786deff96 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -59,10 +59,10 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); if (typeof xyRatio.y == 'number') { this.workspace_.scrollY = @@ -81,11 +81,11 @@ Blockly.VerticalFlyout.prototype.getX = function() { if (!this.isVisible()) { return 0; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var toolboxMetrics = metricsManager.getToolboxMetrics(); - var x = 0; + const metricsManager = this.targetWorkspace.getMetricsManager(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const toolboxMetrics = metricsManager.getToolboxMetrics(); + let x = 0; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { @@ -137,18 +137,18 @@ Blockly.VerticalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); // Record the height for workspace metrics. this.height_ = targetWorkspaceViewMetrics.height; - var edgeWidth = this.width_ - this.CORNER_RADIUS; - var edgeHeight = targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; + const edgeWidth = this.width_ - this.CORNER_RADIUS; + const edgeHeight = targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; this.setBackgroundPath_(edgeWidth, edgeHeight); - var x = this.getX(); - var y = this.getY(); + const x = this.getX(); + const y = this.getY(); this.positionAt_(this.width_, this.height_, x, y); }; @@ -162,11 +162,11 @@ Blockly.VerticalFlyout.prototype.position = function() { * @private */ Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { - var atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; - var totalWidth = width + this.CORNER_RADIUS; + const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; + const totalWidth = width + this.CORNER_RADIUS; // Decide whether to start on the left or right. - var path = ['M ' + (atRight ? totalWidth : 0) + ',0']; + const path = ['M ' + (atRight ? totalWidth : 0) + ',0']; // Top. path.push('h', atRight ? -width : width); // Rounded corner. @@ -200,13 +200,13 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() { * @protected */ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { - var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); if (scrollDelta.y) { - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var pos = (viewMetrics.top - scrollMetrics.top) + scrollDelta.y; + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const pos = (viewMetrics.top - scrollMetrics.top) + scrollDelta.y; this.workspace_.scrollbar.setY(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. @@ -228,27 +228,27 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { */ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; - var margin = this.MARGIN; - var cursorX = this.RTL ? margin : margin + this.tabWidth_; - var cursorY = margin; + const margin = this.MARGIN; + const cursorX = this.RTL ? margin : margin + this.tabWidth_; + let cursorY = margin; - for (var i = 0, item; (item = contents[i]); i++) { + for (let i = 0, item; (item = contents[i]); i++) { if (item.type == 'block') { - var block = item.block; - var allBlocks = block.getDescendants(false); - for (var j = 0, child; (child = allBlocks[j]); j++) { + const block = item.block; + const allBlocks = block.getDescendants(false); + for (let j = 0, child; (child = allBlocks[j]); j++) { // Mark blocks as being inside a flyout. This is used to detect and // prevent the closure of the flyout if the user right-clicks on such a // block. child.isInFlyout = true; } block.render(); - var root = block.getSvgRoot(); - var blockHW = block.getHeightWidth(); - var moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; + const root = block.getSvgRoot(); + const blockHW = block.getHeightWidth(); + const moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; block.moveBy(moveX, cursorY); - var rect = this.createRect_(block, + const rect = this.createRect_(block, this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); this.addBlockListeners_(root, block, rect); @@ -272,12 +272,12 @@ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { */ Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { - var dx = currentDragDeltaXY.x; - var dy = currentDragDeltaXY.y; + const dx = currentDragDeltaXY.x; + const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. - var dragDirection = Math.atan2(dy, dx) / Math.PI * 180; + const dragDirection = Math.atan2(dy, dx) / Math.PI * 180; - var range = this.dragAngleRange_; + const range = this.dragAngleRange_; // Check for left or right dragging. if ((dragDirection < range && dragDirection > -range) || (dragDirection < -180 + range || dragDirection > 180 - range)) { @@ -299,15 +299,15 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { return null; } - var flyoutRect = this.svgGroup_.getBoundingClientRect(); + const flyoutRect = this.svgGroup_.getBoundingClientRect(); // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout // area are still deleted. Must be larger than the largest screen size, // but be smaller than half Number.MAX_SAFE_INTEGER (not available on IE). - var BIG_NUM = 1000000000; - var left = flyoutRect.left; + const BIG_NUM = 1000000000; + const left = flyoutRect.left; if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { - var width = flyoutRect.width; + const width = flyoutRect.width; return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); } else { // Right return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); @@ -321,16 +321,16 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { */ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); - var flyoutWidth = 0; - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { - var width = block.getHeightWidth().width; + let flyoutWidth = 0; + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { + let width = block.getHeightWidth().width; if (block.outputConnection) { width -= this.tabWidth_; } flyoutWidth = Math.max(flyoutWidth, width); } - for (var i = 0, button; (button = this.buttons_[i]); i++) { + for (let i = 0, button; (button = this.buttons_[i]); i++) { flyoutWidth = Math.max(flyoutWidth, button.width); } flyoutWidth += this.MARGIN * 1.5 + this.tabWidth_; @@ -338,11 +338,11 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { flyoutWidth += Blockly.Scrollbar.scrollbarThickness; if (this.width_ != flyoutWidth) { - for (var i = 0, block; (block = blocks[i]); i++) { + for (let i = 0, block; (block = blocks[i]); i++) { if (this.RTL) { // With the flyoutWidth known, right-align the blocks. - var oldX = block.getRelativeToSurfaceXY().x; - var newX = flyoutWidth / this.workspace_.scale - this.MARGIN; + const oldX = block.getRelativeToSurfaceXY().x; + let newX = flyoutWidth / this.workspace_.scale - this.MARGIN; if (!block.outputConnection) { newX -= this.tabWidth_; } @@ -354,9 +354,9 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { } if (this.RTL) { // With the flyoutWidth known, right-align the buttons. - for (var i = 0, button; (button = this.buttons_[i]); i++) { - var y = button.getPosition().y; - var x = flyoutWidth / this.workspace_.scale - button.width - + for (let i = 0, button; (button = this.buttons_[i]); i++) { + const y = button.getPosition().y; + const x = flyoutWidth / this.workspace_.scale - button.width - this.MARGIN - this.tabWidth_; button.moveTo(x, y); }