Make block comments an optional module. (#3053)

Measured as a 5 KB *increase* in code size, but that's because some other commit just landed between my tests. It's like running down an up escalator.
This commit is contained in:
Neil Fraser
2019-09-19 14:53:28 -07:00
committed by GitHub
parent 57c8e3dded
commit a1e3973499
6 changed files with 39 additions and 19 deletions

View File

@@ -28,6 +28,7 @@ goog.provide('Blockly.Blocks.procedures');
goog.require('Blockly');
goog.require('Blockly.Blocks');
goog.require('Blockly.Comment');
goog.require('Blockly.FieldCheckbox');
goog.require('Blockly.FieldLabel');
goog.require('Blockly.FieldTextInput');

View File

@@ -248,6 +248,7 @@ class Gen_compressed(threading.Thread):
params.append(("js_code", """
goog.provide('Blockly');
goog.provide('Blockly.Blocks');
goog.provide('Blockly.Comment');
goog.provide('Blockly.FieldCheckbox');
goog.provide('Blockly.FieldColour');
goog.provide('Blockly.FieldDropdown');

View File

@@ -27,7 +27,6 @@
goog.provide('Blockly.Block');
goog.require('Blockly.Blocks');
goog.require('Blockly.Comment');
goog.require('Blockly.Connection');
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockChange');

View File

@@ -1092,6 +1092,9 @@ Blockly.BlockSvg.prototype.setCommentText = function(text) {
var changedState = false;
if (typeof text == 'string') {
if (!this.comment) {
if (!Blockly.Comment) {
throw Error('Missing require for Blockly.Comment');
}
this.comment = new Blockly.Comment(this);
changedState = true;
}

View File

@@ -27,26 +27,41 @@
goog.provide('Blockly.requires');
// Blockly Core.
// Blockly Core (absolutely mandatory).
goog.require('Blockly');
goog.require('Blockly.Mutator');
// If block comments aren't required, then Blockly.inject's "comments"
// configuration must be false, and no blocks may be loaded from XML which
// define comments.
goog.require('Blockly.Comment');
// If a trashcan on the workspace isn't required, then Blockly.inject's
// "trashcan" configuration must be false.
goog.require('Blockly.Trashcan');
// If zoom controls aren't required, then Blockly.inject's
// "zoom"/"controls" configuration must be false.
goog.require('Blockly.ZoomControls');
// Blockly Fields.
goog.require('Blockly.FieldAngle');
goog.require('Blockly.FieldCheckbox');
goog.require('Blockly.FieldColour');
// Date picker commented out since it increases footprint by 60%.
// Add it only if you need it.
// goog.require('Blockly.FieldDate');
goog.require('Blockly.FieldDropdown');
goog.require('Blockly.FieldLabelSerializable');
goog.require('Blockly.FieldImage');
goog.require('Blockly.FieldTextInput');
goog.require('Blockly.FieldMultilineInput');
goog.require('Blockly.FieldNumber');
goog.require('Blockly.FieldVariable');
// Block dependencies.
// None of these should be required since individual block files should
// include the requirements they depend on.
// goog.require('Blockly.Mutator');
// goog.require('Blockly.FieldAngle');
// goog.require('Blockly.FieldCheckbox');
// goog.require('Blockly.FieldColour');
// goog.require('Blockly.FieldDropdown');
// goog.require('Blockly.FieldLabelSerializable');
// goog.require('Blockly.FieldImage');
// goog.require('Blockly.FieldTextInput');
// goog.require('Blockly.FieldMultilineInput');
// goog.require('Blockly.FieldNumber');
// goog.require('Blockly.FieldVariable');
// Blockly Renderers.
// At least one renderer is mandatory. Geras is the default one.
// Others may be chosen using Blockly.inject's "renderer" configuration.
goog.require('Blockly.geras.Renderer');
goog.require('Blockly.thrasos.Renderer');
goog.require('Blockly.zelos.Renderer');
// goog.require('Blockly.thrasos.Renderer');
// goog.require('Blockly.zelos.Renderer');

View File

@@ -141,6 +141,7 @@ gulp.task('build-blocks', function () {
const provides = `
goog.provide('Blockly');
goog.provide('Blockly.Blocks');
goog.provide('Blockly.Comment');
goog.provide('Blockly.FieldCheckbox');
goog.provide('Blockly.FieldColour');
goog.provide('Blockly.FieldDropdown');