Migrate core/renderers/measurables/row_elements.js to goog.module syntax (#5381)

* Split provides in core/renderers/measurables/row_elements.js into individual files

* Migrate core/renderers/measurables/row_elements.js to ES6 const/let

* Migrate core/renderers/measurables/row_elements.js to goog.module

* Migrate core/renderers/measurables/row_elements.js to named requires

* clang-format core/renderers/measurables/row_elements.js
This commit is contained in:
Aaron Dodson
2021-08-16 15:54:11 -07:00
committed by GitHub
parent 6bf9a336f4
commit dbe7aaa8c8
9 changed files with 318 additions and 191 deletions

View File

@@ -0,0 +1,52 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Objects representing a field in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.module('Blockly.blockRendering.Field');
goog.module.declareLegacyNamespace();
/* eslint-disable-next-line no-unused-vars */
const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider');
/* eslint-disable-next-line no-unused-vars */
const BlocklyField = goog.requireType('Blockly.Field');
/* eslint-disable-next-line no-unused-vars */
const Input = goog.requireType('Blockly.Input');
const Measurable = goog.require('Blockly.blockRendering.Measurable');
const Types = goog.require('Blockly.blockRendering.Types');
const object = goog.require('Blockly.utils.object');
/**
* An object containing information about the space a field takes up during
* rendering
* @param {!ConstantProvider} constants The rendering
* constants provider.
* @param {!BlocklyField} field The field to measure and store information for.
* @param {!Input} parentInput The parent input for the field.
* @package
* @constructor
* @extends {Measurable}
*/
const Field = function(constants, field, parentInput) {
Field.superClass_.constructor.call(this, constants);
this.field = field;
this.isEditable = field.EDITABLE;
this.flipRtl = field.getFlipRtl();
this.type |= Types.FIELD;
const size = this.field.getSize();
this.height = size.height;
this.width = size.width;
this.parentInput = parentInput;
};
object.inherits(Field, Measurable);
exports = Field;

View File

@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Objects representing a hat in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.module('Blockly.blockRendering.Hat');
goog.module.declareLegacyNamespace();
/* eslint-disable-next-line no-unused-vars */
const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider');
const Measurable = goog.require('Blockly.blockRendering.Measurable');
const Types = goog.require('Blockly.blockRendering.Types');
const object = goog.require('Blockly.utils.object');
/**
* An object containing information about the space a hat takes up during
* rendering.
* @param {!ConstantProvider} constants The rendering
* constants provider.
* @package
* @constructor
* @extends {Measurable}
*/
const Hat = function(constants) {
Hat.superClass_.constructor.call(this, constants);
this.type |= Types.HAT;
this.height = this.constants_.START_HAT.height;
this.width = this.constants_.START_HAT.width;
this.ascenderHeight = this.height;
};
object.inherits(Hat, Measurable);
exports = Hat;

View File

@@ -0,0 +1,47 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Objects representing an icon in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.module('Blockly.blockRendering.Icon');
goog.module.declareLegacyNamespace();
/* eslint-disable-next-line no-unused-vars */
const BlocklyIcon = goog.requireType('Blockly.Icon');
/* eslint-disable-next-line no-unused-vars */
const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider');
const Measurable = goog.require('Blockly.blockRendering.Measurable');
const Types = goog.require('Blockly.blockRendering.Types');
const object = goog.require('Blockly.utils.object');
/**
* An object containing information about the space an icon takes up during
* rendering
* @param {!ConstantProvider} constants The rendering
* constants provider.
* @param {!BlocklyIcon} icon The icon to measure and store information for.
* @package
* @constructor
* @extends {Measurable}
*/
const Icon = function(constants, icon) {
Icon.superClass_.constructor.call(this, constants);
this.icon = icon;
this.isVisible = icon.isVisible();
this.type |= Types.ICON;
const size = icon.getCorrectedSize();
this.height = size.height;
this.width = size.width;
};
object.inherits(Icon, Measurable);
exports = Icon;

View File

@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Objects representing a spacer in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.module('Blockly.blockRendering.InRowSpacer');
goog.module.declareLegacyNamespace();
/* eslint-disable-next-line no-unused-vars */
const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider');
const Measurable = goog.require('Blockly.blockRendering.Measurable');
const Types = goog.require('Blockly.blockRendering.Types');
const object = goog.require('Blockly.utils.object');
/**
* An object containing information about a spacer between two elements on a
* row.
* @param {!ConstantProvider} constants The rendering
* constants provider.
* @param {number} width The width of the spacer.
* @package
* @constructor
* @extends {Measurable}
*/
const InRowSpacer = function(constants, width) {
InRowSpacer.superClass_.constructor.call(this, constants);
this.type |= Types.SPACER | Types.IN_ROW_SPACER;
this.width = width;
this.height = this.constants_.SPACER_DEFAULT_HEIGHT;
};
object.inherits(InRowSpacer, Measurable);
exports = InRowSpacer;

View File

@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Objects representing a jagged edge in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.module('Blockly.blockRendering.JaggedEdge');
goog.module.declareLegacyNamespace();
/* eslint-disable-next-line no-unused-vars */
const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider');
const Measurable = goog.require('Blockly.blockRendering.Measurable');
const Types = goog.require('Blockly.blockRendering.Types');
const object = goog.require('Blockly.utils.object');
/**
* An object containing information about the jagged edge of a collapsed block
* takes up during rendering
* @param {!ConstantProvider} constants The rendering
* constants provider.
* @package
* @constructor
* @extends {Measurable}
*/
const JaggedEdge = function(constants) {
JaggedEdge.superClass_.constructor.call(this, constants);
this.type |= Types.JAGGED_EDGE;
this.height = this.constants_.JAGGED_TEETH.height;
this.width = this.constants_.JAGGED_TEETH.width;
};
object.inherits(JaggedEdge, Measurable);
exports = JaggedEdge;

View File

@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Objects representing a round corner in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.module('Blockly.blockRendering.RoundCorner');
goog.module.declareLegacyNamespace();
/* eslint-disable-next-line no-unused-vars */
const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider');
const Measurable = goog.require('Blockly.blockRendering.Measurable');
const Types = goog.require('Blockly.blockRendering.Types');
const object = goog.require('Blockly.utils.object');
/**
* An object containing information about the space a rounded corner takes up
* during rendering.
* @param {!ConstantProvider} constants The rendering
* constants provider.
* @param {string=} opt_position The position of this corner.
* @package
* @constructor
* @extends {Measurable}
*/
const RoundCorner = function(constants, opt_position) {
RoundCorner.superClass_.constructor.call(this, constants);
this.type =
((!opt_position || opt_position == 'left') ? Types.LEFT_ROUND_CORNER :
Types.RIGHT_ROUND_CORNER) |
Types.CORNER;
this.width = this.constants_.CORNER_RADIUS;
// The rounded corner extends into the next row by 4 so we only take the
// height that is aligned with this row.
this.height = this.constants_.CORNER_RADIUS / 2;
};
object.inherits(RoundCorner, Measurable);
exports = RoundCorner;

View File

@@ -1,190 +0,0 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Objects representing elements in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.provide('Blockly.blockRendering.Field');
goog.provide('Blockly.blockRendering.Hat');
goog.provide('Blockly.blockRendering.Icon');
goog.provide('Blockly.blockRendering.InRowSpacer');
goog.provide('Blockly.blockRendering.JaggedEdge');
goog.provide('Blockly.blockRendering.RoundCorner');
goog.provide('Blockly.blockRendering.SquareCorner');
goog.require('Blockly.blockRendering.Measurable');
goog.require('Blockly.blockRendering.Types');
goog.require('Blockly.utils.object');
goog.requireType('Blockly.blockRendering.ConstantProvider');
goog.requireType('Blockly.Field');
goog.requireType('Blockly.Icon');
goog.requireType('Blockly.Input');
/**
* An object containing information about the space an icon takes up during
* rendering
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {!Blockly.Icon} icon The icon to measure and store information for.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.Icon = function(constants, icon) {
Blockly.blockRendering.Icon.superClass_.constructor.call(this, constants);
this.icon = icon;
this.isVisible = icon.isVisible();
this.type |= Blockly.blockRendering.Types.ICON;
var size = icon.getCorrectedSize();
this.height = size.height;
this.width = size.width;
};
Blockly.utils.object.inherits(Blockly.blockRendering.Icon,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the jagged edge of a collapsed block
* takes up during rendering
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.JaggedEdge = function(constants) {
Blockly.blockRendering.JaggedEdge.superClass_.constructor.call(
this, constants);
this.type |= Blockly.blockRendering.Types.JAGGED_EDGE;
this.height = this.constants_.JAGGED_TEETH.height;
this.width = this.constants_.JAGGED_TEETH.width;
};
Blockly.utils.object.inherits(Blockly.blockRendering.JaggedEdge,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space a field takes up during
* rendering
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {!Blockly.Field} field The field to measure and store information for.
* @param {!Blockly.Input} parentInput The parent input for the field.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.Field = function(constants, field, parentInput) {
Blockly.blockRendering.Field.superClass_.constructor.call(this, constants);
this.field = field;
this.isEditable = field.EDITABLE;
this.flipRtl = field.getFlipRtl();
this.type |= Blockly.blockRendering.Types.FIELD;
var size = this.field.getSize();
this.height = size.height;
this.width = size.width;
this.parentInput = parentInput;
};
Blockly.utils.object.inherits(Blockly.blockRendering.Field,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space a hat takes up during
* rendering.
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.Hat = function(constants) {
Blockly.blockRendering.Hat.superClass_.constructor.call(this, constants);
this.type |= Blockly.blockRendering.Types.HAT;
this.height = this.constants_.START_HAT.height;
this.width = this.constants_.START_HAT.width;
this.ascenderHeight = this.height;
};
Blockly.utils.object.inherits(Blockly.blockRendering.Hat,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space a square corner takes up
* during rendering.
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {string=} opt_position The position of this corner.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.SquareCorner = function(constants, opt_position) {
Blockly.blockRendering.SquareCorner.superClass_.constructor.call(this,
constants);
this.type = ((!opt_position || opt_position == 'left') ?
Blockly.blockRendering.Types.LEFT_SQUARE_CORNER :
Blockly.blockRendering.Types.RIGHT_SQUARE_CORNER) |
Blockly.blockRendering.Types.CORNER;
this.height = this.constants_.NO_PADDING;
this.width = this.constants_.NO_PADDING;
};
Blockly.utils.object.inherits(Blockly.blockRendering.SquareCorner,
Blockly.blockRendering.Measurable);
/**
* An object containing information about the space a rounded corner takes up
* during rendering.
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {string=} opt_position The position of this corner.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.RoundCorner = function(constants, opt_position) {
Blockly.blockRendering.RoundCorner.superClass_.constructor.call(this,
constants);
this.type = ((!opt_position || opt_position == 'left') ?
Blockly.blockRendering.Types.LEFT_ROUND_CORNER :
Blockly.blockRendering.Types.RIGHT_ROUND_CORNER) |
Blockly.blockRendering.Types.CORNER;
this.width = this.constants_.CORNER_RADIUS;
// The rounded corner extends into the next row by 4 so we only take the
// height that is aligned with this row.
this.height = this.constants_.CORNER_RADIUS / 2;
};
Blockly.utils.object.inherits(Blockly.blockRendering.RoundCorner,
Blockly.blockRendering.Measurable);
/**
* An object containing information about a spacer between two elements on a
* row.
* @param {!Blockly.blockRendering.ConstantProvider} constants The rendering
* constants provider.
* @param {number} width The width of the spacer.
* @package
* @constructor
* @extends {Blockly.blockRendering.Measurable}
*/
Blockly.blockRendering.InRowSpacer = function(constants, width) {
Blockly.blockRendering.InRowSpacer.superClass_.constructor.call(this,
constants);
this.type |= Blockly.blockRendering.Types.SPACER |
Blockly.blockRendering.Types.IN_ROW_SPACER;
this.width = width;
this.height = this.constants_.SPACER_DEFAULT_HEIGHT;
};
Blockly.utils.object.inherits(Blockly.blockRendering.InRowSpacer,
Blockly.blockRendering.Measurable);

View File

@@ -0,0 +1,44 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Objects representing a square corner in a row of a rendered
* block.
* @author fenichel@google.com (Rachel Fenichel)
*/
goog.module('Blockly.blockRendering.SquareCorner');
goog.module.declareLegacyNamespace();
/* eslint-disable-next-line no-unused-vars */
const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider');
const Measurable = goog.require('Blockly.blockRendering.Measurable');
const Types = goog.require('Blockly.blockRendering.Types');
const object = goog.require('Blockly.utils.object');
/**
* An object containing information about the space a square corner takes up
* during rendering.
* @param {!ConstantProvider} constants The rendering
* constants provider.
* @param {string=} opt_position The position of this corner.
* @package
* @constructor
* @extends {Measurable}
*/
const SquareCorner = function(constants, opt_position) {
SquareCorner.superClass_.constructor.call(this, constants);
this.type =
((!opt_position || opt_position == 'left') ? Types.LEFT_SQUARE_CORNER :
Types.RIGHT_SQUARE_CORNER) |
Types.CORNER;
this.height = this.constants_.NO_PADDING;
this.width = this.constants_.NO_PADDING;
};
object.inherits(SquareCorner, Measurable);
exports = SquareCorner;

View File

@@ -151,10 +151,16 @@ goog.addDependency('../../core/renderers/geras/renderer.js', ['Blockly.geras.Ren
goog.addDependency('../../core/renderers/measurables/base.js', ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.Types'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/connections.js', ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']);
goog.addDependency('../../core/renderers/measurables/external_value_input.js', ['Blockly.blockRendering.ExternalValueInput'], ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/field.js', ['Blockly.blockRendering.Field'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/hat.js', ['Blockly.blockRendering.Hat'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/icon.js', ['Blockly.blockRendering.Icon'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/in_row_spacer.js', ['Blockly.blockRendering.InRowSpacer'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/inline_input.js', ['Blockly.blockRendering.InlineInput'], ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/input_connection.js', ['Blockly.blockRendering.InputConnection'], ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/row_elements.js', ['Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.SquareCorner'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']);
goog.addDependency('../../core/renderers/measurables/jagged_edge.js', ['Blockly.blockRendering.JaggedEdge'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/round_corner.js', ['Blockly.blockRendering.RoundCorner'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/rows.js', ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow'], ['Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.Types', 'Blockly.utils.object']);
goog.addDependency('../../core/renderers/measurables/square_corner.js', ['Blockly.blockRendering.SquareCorner'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/statement_input.js', ['Blockly.blockRendering.StatementInput'], ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.Types', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/measurables/types.js', ['Blockly.blockRendering.Types'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/minimalist/constants.js', ['Blockly.minimalist.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});