From d2c61d57357406490cde305725518a5c30b96a65 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Wed, 9 Jun 2021 19:20:47 -0700 Subject: [PATCH 1/4] Prevent uncessary add/remove class calls on cursor during drag (#4885) --- core/block_dragger.js | 9 ++++++--- core/bubble_dragger.js | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index c9c477430..8dfac6542 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -217,9 +217,12 @@ Blockly.BlockDragger.prototype.dragBlock = function(e, currentDragDeltaXY) { } this.draggedConnectionManager_.update(delta, this.dragTarget_); - this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock(); - - this.updateCursorDuringBlockDrag_(); + var wouldDeleteBlock = this.draggedConnectionManager_.wouldDeleteBlock(); + if (wouldDeleteBlock != this.wouldDeleteBlock_) { + // Prevent unnecessary add/remove class calls. + this.updateCursorDuringBlockDrag_(); + } + this.wouldDeleteBlock_ = wouldDeleteBlock; }; /** diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 38c339158..2112eb3ab 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -140,9 +140,13 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { oldDragTarget && oldDragTarget.onDragExit(); this.dragTarget_ && this.dragTarget_.onDragEnter(); } - this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_); - this.updateCursorDuringBubbleDrag_(); + var wouldDeleteBubble = this.shouldDelete_(this.dragTarget_); + if (wouldDeleteBubble != this.wouldDeleteBubble_) { + // Prevent unnecessary add/remove class calls. + this.updateCursorDuringBubbleDrag_(); + } + this.wouldDeleteBubble_ = wouldDeleteBubble; }; /** @@ -177,11 +181,7 @@ Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { * @private */ Blockly.BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { - if (this.wouldDeleteBubble_) { - this.draggingBubble_.setDeleteStyle(true); - } else { - this.draggingBubble_.setDeleteStyle(false); - } + this.draggingBubble_.setDeleteStyle(this.wouldDeleteBubble_); }; /** From 96315ad4497ff3f4dccae12dd079d388051677f2 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 8 Jun 2021 06:11:20 -0700 Subject: [PATCH 2/4] Fix removal of spaces near parens inside strings Extra spaces should only be stripped from the inside of paren tokens. Parens in strings (and other static content) should not be edited. --- core/block.js | 11 +++++++---- tests/mocha/block_test.js | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/block.js b/core/block.js index d27f5256c..35b2cae62 100644 --- a/core/block.js +++ b/core/block.js @@ -1424,16 +1424,19 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { // Run through our text array and simplify expression to remove parentheses // around single field blocks. - for (var i = 2, l = text.length; i < l; i++) { + // E.g. ['repeat', '(', '10', ')', 'times', 'do', '?'] + for (var i = 2; i < text.length; i++) { if (text[i - 2] == '(' && text[i] == ')') { text[i - 2] = text[i - 1]; text.splice(i - 1, 2); - l -= 2; } } - // Join the text array, removing spaces around added paranthesis. - text = text.join(' ').replace(/(\() | (\))/gmi, '$1$2').trim() || '???'; + // Join the text array, removing spaces around added parentheses. + text = text.reduce(function(acc, value) { + return acc + ((acc.substr(-1) == '(' || value == ')') ? '' : ' ') + value; + }, ''); + text = text.trim() || '???'; if (opt_maxLength) { // TODO: Improve truncation so that text from this block is given priority. // E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not "1+2+3+4+5...". diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index 34c56ddeb..7995902ce 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -1710,7 +1710,7 @@ suite('Blocks', function() { '' + '' + '', - toString: 'repeat 10 times do ?', + toString: 'repeat 10 times do ?' }, { name: 'nested statement blocks', @@ -1724,7 +1724,7 @@ suite('Blocks', function() { '' + '' + '', - toString: 'repeat 10 times do if ? do ?', + toString: 'repeat 10 times do if ? do ?' }, { name: 'nested Boolean output blocks', @@ -1740,7 +1740,7 @@ suite('Blocks', function() { '' + '' + '', - toString: 'if ((? and ?) = ?) do ?', + toString: 'if ((? and ?) = ?) do ?' }, { name: 'output block', @@ -1752,7 +1752,7 @@ suite('Blocks', function() { '' + '' + '', - toString: 'square root 9', + toString: 'square root 9' }, { name: 'nested Number output blocks', @@ -1782,7 +1782,7 @@ suite('Blocks', function() { '' + '' + '', - toString: '(10 × 5) + 3', + toString: '(10 × 5) + 3' }, { name: 'nested String output blocks', @@ -1799,8 +1799,15 @@ suite('Blocks', function() { '' + '' + '', - toString: 'create text with “ Hello ” “ World ”', + toString: 'create text with “ Hello ” “ World ”' }, + { + name: 'parentheses in string literal', + xml: '' + + 'foo ( bar ) baz' + + '', + toString: '“ foo ( bar ) baz ”' + } ]; // Create mocha test cases for each toString test. toStringTests.forEach(function(t) { From d2579a7369668a948bff4860db3246cb1e42ce7f Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Wed, 9 Jun 2021 22:29:33 -0700 Subject: [PATCH 3/4] Add removeComponent to ComponentManager (#4884) --- blockly_uncompressed.js | 16 +++++------ core/blockly.js | 1 + core/bubble_dragger.js | 1 + core/component_manager.js | 47 +++++++++++++++++++++---------- core/flyout_base.js | 10 ++++++- core/insertion_marker_manager.js | 1 + core/interfaces/i_autohideable.js | 1 - core/interfaces/i_delete_area.js | 3 ++ core/interfaces/i_positionable.js | 3 ++ core/toolbox/toolbox.js | 2 ++ core/trashcan.js | 2 ++ core/workspace_svg.js | 2 +- core/zoom_controls.js | 2 ++ 13 files changed, 65 insertions(+), 26 deletions(-) diff --git a/blockly_uncompressed.js b/blockly_uncompressed.js index 0a3a3e336..583997513 100644 --- a/blockly_uncompressed.js +++ b/blockly_uncompressed.js @@ -26,11 +26,11 @@ 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']); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', '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.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.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.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], []); 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']); -goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); 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']); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], []); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); @@ -75,7 +75,7 @@ goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Bloc goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); -goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); 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']); @@ -86,7 +86,7 @@ goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEven 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.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.constants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], []); @@ -177,12 +177,12 @@ goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Bl goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); -goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.CollapsibleToolboxCategory', '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.js', ['Blockly.Toolbox'], ['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_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); -goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['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.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.constants', 'Blockly.registry', 'Blockly.uiPosition', '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'], []); @@ -219,11 +219,11 @@ 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.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.uiPosition', '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.uiPosition', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency("base.js", [], []); // Load Blockly. -goog.require('Blockly.requires') +goog.require('Blockly.requires'); delete root.BLOCKLY_DIR; delete root.BLOCKLY_BOOT; diff --git a/core/blockly.js b/core/blockly.js index e889cb840..2cef68caf 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -17,6 +17,7 @@ goog.provide('Blockly'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.ComponentManager'); goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); goog.require('Blockly.DropDownDiv'); diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 2112eb3ab..734445622 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -14,6 +14,7 @@ goog.provide('Blockly.BubbleDragger'); /** @suppress {extraRequire} */ goog.require('Blockly.Bubble'); +goog.require('Blockly.ComponentManager'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.Events'); diff --git a/core/component_manager.js b/core/component_manager.js index e5b7c4192..0e2600acd 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -46,7 +46,7 @@ Blockly.ComponentManager = function() { * id: string, * component: !Blockly.IComponent, * capabilities: ( - * !Array>), + * !Array>), * weight: number * }} */ @@ -70,20 +70,37 @@ Blockly.ComponentManager.prototype.addComponent = function( '" already added.'); } this.componentData_[componentInfo.id] = componentInfo; - for (var i = 0, type; (type = componentInfo.capabilities[i]); i++) { - var typeKey = String(type).toLowerCase(); - if (this.capabilityToComponentIds_[typeKey] === undefined) { - this.capabilityToComponentIds_[typeKey] = [componentInfo.id]; + for (var i = 0; i < componentInfo.capabilities.length; i++) { + var capability = String(componentInfo.capabilities[i]).toLowerCase(); + if (this.capabilityToComponentIds_[capability] === undefined) { + this.capabilityToComponentIds_[capability] = [componentInfo.id]; } else { - this.capabilityToComponentIds_[typeKey].push(componentInfo.id); + this.capabilityToComponentIds_[capability].push(componentInfo.id); } } }; +/** + * Removes a component. + * @param {string} id The ID of the component to remove. + */ +Blockly.ComponentManager.prototype.removeComponent = function(id) { + var componentInfo = this.componentData_[id]; + if (!componentInfo) { + return; + } + for (var i = 0; i < componentInfo.capabilities.length; i++) { + var capability = String(componentInfo.capabilities[i]).toLowerCase(); + this.capabilityToComponentIds_[capability].splice( + this.capabilityToComponentIds_[capability].indexOf(id), 1); + } + delete this.componentData_[id]; +}; + /** * Adds a capability to a existing registered component. * @param {string} id The ID of the component to add the capability to. - * @param {string|!Blockly.ComponentManager.Capability + * @param {string|!Blockly.ComponentManager.Capability * } capability The capability to add. */ Blockly.ComponentManager.prototype.addCapability = function(id, capability) { @@ -104,7 +121,7 @@ Blockly.ComponentManager.prototype.addCapability = function(id, capability) { /** * Removes a capability from an existing registered component. * @param {string} id The ID of the component to remove the capability from. - * @param {string|!Blockly.ComponentManager.Capability + * @param {string|!Blockly.ComponentManager.Capability * } capability The capability to remove. */ Blockly.ComponentManager.prototype.removeCapability = function(id, capability) { @@ -127,7 +144,7 @@ Blockly.ComponentManager.prototype.removeCapability = function(id, capability) { /** * Returns whether the component with this id has the specified capability. * @param {string} id The ID of the component to check. - * @param {string|!Blockly.ComponentManager.Capability + * @param {string|!Blockly.ComponentManager.Capability * } capability The capability to check for. * @return {boolean} Whether the component has the capability. */ @@ -137,7 +154,7 @@ Blockly.ComponentManager.prototype.hasCapability = function(id, capability) { }; /** - * Gets the component with the given ID and the given type. + * Gets the component with the given ID. * @param {string} id The ID of the component to get. * @return {!Blockly.IComponent|undefined} The component with the given name * or undefined if not found. @@ -147,16 +164,16 @@ Blockly.ComponentManager.prototype.getComponent = function(id) { }; /** - * Gets all the components of the specified type. - * @param {!Blockly.ComponentManager.Capability} capability The capability of the - * component. + * Gets all the components with the specified capability. + * @param {string|!Blockly.ComponentManager.Capability + * } capability The capability of the component. * @param {boolean} sorted Whether to return list ordered by weights. * @return {!Array} The components that match the specified capability. * @template T */ Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) { - var typeKey = String(capability).toLowerCase(); - var componentIds = this.capabilityToComponentIds_[typeKey]; + capability = String(capability).toLowerCase(); + var componentIds = this.capabilityToComponentIds_[capability]; if (!componentIds) { return []; } diff --git a/core/flyout_base.js b/core/flyout_base.js index 06ceecbbb..8aa2a91e3 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -16,6 +16,7 @@ goog.require('Blockly.Block'); /** @suppress {extraRequire} */ goog.require('Blockly.blockRendering'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.ComponentManager'); goog.require('Blockly.DeleteArea'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -70,6 +71,12 @@ Blockly.Flyout = function(workspaceOptions) { // Keep the workspace visibility consistent with the flyout's visibility. this.workspace_.setVisible(this.isVisible_); + /** + * The unique id for this component. + * @type {string} + */ + this.id = 'flyout' + this.workspace_.id; + /** * Is RTL vs LTR. * @type {boolean} @@ -304,7 +311,7 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { this.workspace_.createPotentialVariableMap(); targetWorkspace.getComponentManager().addComponent({ - id: 'flyout' + this.workspace_.id, + id: this.id, component: this, weight: 1, capabilities: [ @@ -321,6 +328,7 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { */ Blockly.Flyout.prototype.dispose = function() { this.hide(); + this.workspace_.getComponentManager().removeComponent(this.id); Blockly.browserEvents.unbind(this.eventWrappers_); if (this.filterWrapper_) { this.targetWorkspace.removeChangeListener(this.filterWrapper_); diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index 1a7988c24..da369adda 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -13,6 +13,7 @@ goog.provide('Blockly.InsertionMarkerManager'); goog.require('Blockly.blockAnimations'); +goog.require('Blockly.ComponentManager'); goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); diff --git a/core/interfaces/i_autohideable.js b/core/interfaces/i_autohideable.js index 542919286..ff976c549 100644 --- a/core/interfaces/i_autohideable.js +++ b/core/interfaces/i_autohideable.js @@ -14,7 +14,6 @@ goog.provide('Blockly.IAutoHideable'); - goog.require('Blockly.IComponent'); diff --git a/core/interfaces/i_delete_area.js b/core/interfaces/i_delete_area.js index e3bbb3d7c..4ab7cddbe 100644 --- a/core/interfaces/i_delete_area.js +++ b/core/interfaces/i_delete_area.js @@ -16,6 +16,9 @@ goog.provide('Blockly.IDeleteArea'); goog.require('Blockly.IDragTarget'); +goog.requireType('Blockly.BlockSvg'); +goog.requireType('Blockly.IBubble'); + /** * Interface for a component that can delete a block or bubble that is dropped diff --git a/core/interfaces/i_positionable.js b/core/interfaces/i_positionable.js index 64679bcc9..89f4c8094 100644 --- a/core/interfaces/i_positionable.js +++ b/core/interfaces/i_positionable.js @@ -15,6 +15,9 @@ goog.provide('Blockly.IPositionable'); goog.require('Blockly.IComponent'); +goog.requireType('Blockly.MetricsManager'); +goog.requireType('Blockly.utils.Rect'); + /** * Interface for a component that is positioned on top of the workspace. diff --git a/core/toolbox/toolbox.js b/core/toolbox/toolbox.js index 64a1a51db..4b3087421 100644 --- a/core/toolbox/toolbox.js +++ b/core/toolbox/toolbox.js @@ -14,6 +14,7 @@ goog.provide('Blockly.Toolbox'); goog.require('Blockly.browserEvents'); goog.require('Blockly.CollapsibleToolboxCategory'); +goog.require('Blockly.ComponentManager'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.Css'); @@ -966,6 +967,7 @@ Blockly.Toolbox.prototype.selectPrevious_ = function() { * @public */ Blockly.Toolbox.prototype.dispose = function() { + this.workspace_.getComponentManager().removeComponent('toolbox'); this.flyout_.dispose(); for (var i = 0; i < this.contents_.length; i++) { var toolboxItem = this.contents_[i]; diff --git a/core/trashcan.js b/core/trashcan.js index 7781a79bd..57fb1155a 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -13,6 +13,7 @@ goog.provide('Blockly.Trashcan'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.ComponentManager'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.DeleteArea'); @@ -382,6 +383,7 @@ Blockly.Trashcan.prototype.init = function() { * @suppress {checkTypes} */ Blockly.Trashcan.prototype.dispose = function() { + this.workspace_.getComponentManager().removeComponent('trashcan'); if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); this.svgGroup_ = null; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 2ff702918..7b976191e 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -15,6 +15,7 @@ goog.provide('Blockly.WorkspaceSvg'); goog.require('Blockly.blockRendering'); goog.require('Blockly.BlockSvg'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.ComponentManager'); goog.require('Blockly.ConnectionDB'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); @@ -36,7 +37,6 @@ goog.require('Blockly.MetricsManager'); /** @suppress {extraRequire} */ goog.require('Blockly.Msg'); goog.require('Blockly.Options'); -goog.require('Blockly.ComponentManager'); goog.require('Blockly.registry'); goog.require('Blockly.ThemeManager'); goog.require('Blockly.Themes.Classic'); diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 530a24142..796a04b5f 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -13,6 +13,7 @@ goog.provide('Blockly.ZoomControls'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.ComponentManager'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.Css'); @@ -203,6 +204,7 @@ Blockly.ZoomControls.prototype.init = function() { * Unlink from all DOM elements to prevent memory leaks. */ Blockly.ZoomControls.prototype.dispose = function() { + this.workspace_.getComponentManager().removeComponent('zoomControls'); if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); } From 77dddca02e7813e98b0c20a0404bbf2a19b2c55d Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 10 Jun 2021 10:57:09 -0700 Subject: [PATCH 4/4] Fix bug with updating cursor style in draggers (#4889) --- core/block_dragger.js | 6 +++--- core/bubble_dragger.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 8dfac6542..b9ce831be 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -217,12 +217,12 @@ Blockly.BlockDragger.prototype.dragBlock = function(e, currentDragDeltaXY) { } this.draggedConnectionManager_.update(delta, this.dragTarget_); - var wouldDeleteBlock = this.draggedConnectionManager_.wouldDeleteBlock(); - if (wouldDeleteBlock != this.wouldDeleteBlock_) { + var oldWouldDeleteBlock = this.wouldDeleteBlock_; + this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock(); + if (oldWouldDeleteBlock != this.wouldDeleteBlock_) { // Prevent unnecessary add/remove class calls. this.updateCursorDuringBlockDrag_(); } - this.wouldDeleteBlock_ = wouldDeleteBlock; }; /** diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 734445622..fd4b67b00 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -142,12 +142,12 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { this.dragTarget_ && this.dragTarget_.onDragEnter(); } - var wouldDeleteBubble = this.shouldDelete_(this.dragTarget_); - if (wouldDeleteBubble != this.wouldDeleteBubble_) { + var oldWouldDeleteBubble = this.wouldDeleteBubble_; + this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_); + if (oldWouldDeleteBubble != this.wouldDeleteBubble_) { // Prevent unnecessary add/remove class calls. this.updateCursorDuringBubbleDrag_(); } - this.wouldDeleteBubble_ = wouldDeleteBubble; }; /**