From ddb8e46b87c315e5194e87d6fc3bb2a67a192477 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 23 Sep 2019 22:02:59 -0700 Subject: [PATCH] Make flyouts be optional modules. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No Blockly instances need both Horizontal and Vertical flyouts. Dropping one of these saves 2 KB. Some don’t need flyouts at all (e.g. Blockly Games Puzzle or readonly documentation blocks). --- core/blockly.js | 2 -- core/requires.js | 3 +++ core/toolbox.js | 9 ++++++--- core/trashcan.js | 6 ++++++ core/workspace_svg.js | 6 ++++++ tests/compile/main.js | 1 + 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index ecce4cdd5..15adebfc0 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -34,12 +34,10 @@ goog.require('Blockly.BlockSvg.render'); goog.require('Blockly.Events'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.Generator'); -goog.require('Blockly.HorizontalFlyout'); goog.require('Blockly.navigation'); goog.require('Blockly.Procedures'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); -goog.require('Blockly.VerticalFlyout'); goog.require('Blockly.WidgetDiv'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.constants'); diff --git a/core/requires.js b/core/requires.js index 31f1506c7..7ad15a03f 100644 --- a/core/requires.js +++ b/core/requires.js @@ -35,6 +35,9 @@ goog.require('Blockly'); // configuration must be false, and no blocks may be loaded from XML which // define comments. goog.require('Blockly.Comment'); +// One of these two will almost certainly be needed (usually VerticalFlyout). +goog.require('Blockly.HorizontalFlyout'); +goog.require('Blockly.VerticalFlyout'); // If the toolbox does not have categories and only has a simple flyout, then // 'Blockly.Toolbox' is not needed. goog.require('Blockly.Toolbox'); diff --git a/core/toolbox.js b/core/toolbox.js index b32614521..945748058 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -28,8 +28,6 @@ goog.provide('Blockly.Toolbox'); goog.require('Blockly.Events'); goog.require('Blockly.Events.Ui'); -goog.require('Blockly.Flyout'); -goog.require('Blockly.HorizontalFlyout'); goog.require('Blockly.navigation'); goog.require('Blockly.Touch'); goog.require('Blockly.tree.TreeControl'); @@ -40,7 +38,6 @@ goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.object'); goog.require('Blockly.utils.Rect'); -goog.require('Blockly.VerticalFlyout'); /** @@ -186,8 +183,14 @@ Blockly.Toolbox.prototype.init = function() { */ this.flyout_ = null; if (workspace.horizontalLayout) { + if (!Blockly.HorizontalFlyout) { + throw Error('Missing require for Blockly.HorizontalFlyout'); + } this.flyout_ = new Blockly.HorizontalFlyout(workspaceOptions); } else { + if (!Blockly.VerticalFlyout) { + throw Error('Missing require for Blockly.VerticalFlyout'); + } this.flyout_ = new Blockly.VerticalFlyout(workspaceOptions); } // Insert the flyout after the workspace. diff --git a/core/trashcan.js b/core/trashcan.js index e78341a59..a0a6efd7b 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -78,11 +78,17 @@ Blockly.Trashcan = function(workspace) { flyoutWorkspaceOptions.toolboxPosition = this.workspace_.toolboxPosition == Blockly.TOOLBOX_AT_TOP ? Blockly.TOOLBOX_AT_BOTTOM : Blockly.TOOLBOX_AT_TOP; + if (!Blockly.HorizontalFlyout) { + throw Error('Missing require for Blockly.HorizontalFlyout'); + } this.flyout_ = new Blockly.HorizontalFlyout(flyoutWorkspaceOptions); } else { flyoutWorkspaceOptions.toolboxPosition = this.workspace_.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT ? Blockly.TOOLBOX_AT_LEFT : Blockly.TOOLBOX_AT_RIGHT; + if (!Blockly.VerticalFlyout) { + throw Error('Missing require for Blockly.VerticalFlyout'); + } this.flyout_ = new Blockly.VerticalFlyout(flyoutWorkspaceOptions); } this.workspace_.addChangeListener(this.onDelete_()); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 1d291e382..14dd6eb39 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -810,8 +810,14 @@ Blockly.WorkspaceSvg.prototype.addFlyout_ = function(tagName) { renderer: this.options.renderer }; if (this.horizontalLayout) { + if (!Blockly.HorizontalFlyout) { + throw Error('Missing require for Blockly.HorizontalFlyout'); + } this.flyout_ = new Blockly.HorizontalFlyout(workspaceOptions); } else { + if (!Blockly.VerticalFlyout) { + throw Error('Missing require for Blockly.VerticalFlyout'); + } this.flyout_ = new Blockly.VerticalFlyout(workspaceOptions); } this.flyout_.autoClose = false; diff --git a/tests/compile/main.js b/tests/compile/main.js index e8dac7402..e0e19f69f 100644 --- a/tests/compile/main.js +++ b/tests/compile/main.js @@ -3,6 +3,7 @@ goog.provide('Main'); // Either require 'Blockly.requires', or just the components you use: goog.require('Blockly'); goog.require('Blockly.geras.Renderer'); +goog.require('Blockly.VerticalFlyout'); // Blocks goog.require('Blockly.Constants.Logic'); goog.require('Blockly.Constants.Loops');