refactor: Rename ALIGN to Align and move from constants.js to input.js (#5742)

This constant is used to specify the alignment of
an Input, so it should live in the same file as the Input class.

I've done this as a separate named export, but it could alternatively
be made a static member of Input (i.e., Input.Align with only Input
being exported by name).

Where mocha tests were referring to Blockly.constants.ALIGN.*
without actually requiring Blockly.constants, I have reverted
them to refer to Blockly.ALIGN_* instead (pending conversion
to named requries).

Part of #5073.
This commit is contained in:
Christopher Allen
2021-11-29 21:59:48 +00:00
committed by GitHub
parent 985af10f6e
commit c0d22f2002
9 changed files with 56 additions and 42 deletions

View File

@@ -27,6 +27,7 @@ const fieldRegistry = goog.require('Blockly.fieldRegistry');
const idGenerator = goog.require('Blockly.utils.idGenerator');
const object = goog.require('Blockly.utils.object');
const parsing = goog.require('Blockly.utils.parsing');
const {Align, Input} = goog.require('Blockly.Input');
const {ASTNode} = goog.require('Blockly.ASTNode');
const {Blocks} = goog.require('Blockly.blocks');
/* eslint-disable-next-line no-unused-vars */
@@ -40,7 +41,6 @@ const {Field} = goog.requireType('Blockly.Field');
const {IASTNodeLocation} = goog.require('Blockly.IASTNodeLocation');
/* eslint-disable-next-line no-unused-vars */
const {IDeletable} = goog.require('Blockly.IDeletable');
const {Input} = goog.require('Blockly.Input');
/* eslint-disable-next-line no-unused-vars */
const {Mutator} = goog.requireType('Blockly.Mutator');
const {Size} = goog.require('Blockly.utils.Size');
@@ -1824,10 +1824,10 @@ Block.prototype.fieldFromJson_ = function(element) {
*/
Block.prototype.inputFromJson_ = function(element, warningPrefix) {
const alignmentLookup = {
'LEFT': constants.ALIGN.LEFT,
'RIGHT': constants.ALIGN.RIGHT,
'CENTRE': constants.ALIGN.CENTRE,
'CENTER': constants.ALIGN.CENTRE,
'LEFT': Align.LEFT,
'RIGHT': Align.RIGHT,
'CENTRE': Align.CENTRE,
'CENTER': Align.CENTRE,
};
let input = null;

View File

@@ -52,6 +52,7 @@ const toolbox = goog.require('Blockly.utils.toolbox');
const uiPosition = goog.require('Blockly.uiPosition');
const utils = goog.require('Blockly.utils');
const zelos = goog.require('Blockly.zelos');
const {Align, Input} = goog.require('Blockly.Input');
const {ASTNode} = goog.require('Blockly.ASTNode');
const {BasicCursor} = goog.require('Blockly.BasicCursor');
const {BlockDragSurfaceSvg} = goog.require('Blockly.BlockDragSurfaceSvg');
@@ -122,7 +123,6 @@ const {IStyleable} = goog.require('Blockly.IStyleable');
const {IToolboxItem} = goog.require('Blockly.IToolboxItem');
const {IToolbox} = goog.require('Blockly.IToolbox');
const {Icon} = goog.require('Blockly.Icon');
const {Input} = goog.require('Blockly.Input');
const {InsertionMarkerManager} = goog.require('Blockly.InsertionMarkerManager');
const {Marker} = goog.require('Blockly.Marker');
const {MarkerManager} = goog.require('Blockly.MarkerManager');
@@ -438,22 +438,22 @@ exports.unbindEvent_ = browserEvents.unbind;
exports.bindEventWithChecks_ = browserEvents.conditionalBind;
/**
* @see constants.ALIGN.LEFT
* @see Blockly.Input.Align.LEFT
* @alias Blockly.ALIGN_LEFT
*/
exports.ALIGN_LEFT = constants.ALIGN.LEFT;
exports.ALIGN_LEFT = Align.LEFT;
/**
* @see constants.ALIGN.CENTRE
* @see Blockly.Input.Align.CENTRE
* @alias Blockly.ALIGN_CENTRE
*/
exports.ALIGN_CENTRE = constants.ALIGN.CENTRE;
exports.ALIGN_CENTRE = Align.CENTRE;
/**
* @see constants.ALIGN.RIGHT
* @see Blockly.Input.Align.RIGHT
* @alias Blockly.ALIGN_RIGHT
*/
exports.ALIGN_RIGHT = constants.ALIGN.RIGHT;
exports.ALIGN_RIGHT = Align.RIGHT;
/**
* @see common.svgResize

View File

@@ -16,18 +16,6 @@
goog.module('Blockly.constants');
/**
* Enum for alignment of inputs.
* @enum {number}
* @alias Blockly.constants.ALIGN
*/
const ALIGN = {
LEFT: -1,
CENTRE: 0,
RIGHT: 1,
};
exports.ALIGN = ALIGN;
/**
* The language-neutral ID given to the collapsed input.
* @const {string}

View File

@@ -15,7 +15,18 @@
*/
goog.module('Blockly.Input');
const constants = goog.require('Blockly.constants');
/**
* Enum for alignment of inputs.
* @enum {number}
* @alias Blockly.Input.Align
*/
const Align = {
LEFT: -1,
CENTRE: 0,
RIGHT: 1,
};
exports.Align = Align;
const fieldRegistry = goog.require('Blockly.fieldRegistry');
/* eslint-disable-next-line no-unused-vars */
const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
@@ -64,7 +75,7 @@ const Input = function(type, name, block, connection) {
* Alignment of input's fields (left, right or centre).
* @type {number}
*/
Input.prototype.align = constants.ALIGN.LEFT;
Input.prototype.align = Align.LEFT;
/**
* Is the input visible?
@@ -249,8 +260,8 @@ Input.prototype.setCheck = function(check) {
/**
* Change the alignment of the connection's field(s).
* @param {number} align One of the values of constants.ALIGN.
* In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left.
* @param {number} align One of the values of Align
* In RTL mode directions are reversed, and Align.RIGHT aligns to the left.
* @return {!Input} The input being modified (to allow chaining).
*/
Input.prototype.setAlign = function(align) {

View File

@@ -15,7 +15,7 @@
*/
goog.module('Blockly.blockRendering.RenderInfo');
const constants = goog.require('Blockly.constants');
const {Align} = goog.require('Blockly.Input');
/* eslint-disable-next-line no-unused-vars */
const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
const {BottomRow} = goog.require('Blockly.blockRendering.BottomRow');
@@ -578,14 +578,14 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) {
}
// Decide where the extra padding goes.
if (row.align === constants.ALIGN.LEFT) {
if (row.align === Align.LEFT) {
// Add padding to the end of the row.
lastSpacer.width += missingSpace;
} else if (row.align === constants.ALIGN.CENTRE) {
} else if (row.align === Align.CENTRE) {
// Split the padding between the beginning and end of the row.
firstSpacer.width += missingSpace / 2;
lastSpacer.width += missingSpace / 2;
} else if (row.align === constants.ALIGN.RIGHT) {
} else if (row.align === Align.RIGHT) {
// Add padding at the beginning of the row.
firstSpacer.width += missingSpace;
} else {

View File

@@ -16,7 +16,7 @@
*/
goog.module('Blockly.zelos.RenderInfo');
const constants = goog.require('Blockly.constants');
const {Align} = goog.require('Blockly.Input');
const object = goog.require('Blockly.utils.object');
/* eslint-disable-next-line no-unused-vars */
const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
@@ -266,8 +266,7 @@ RenderInfo.prototype.addInput_ = function(input, activeRow) {
// right, keep track of the right aligned dummy input so we can add padding
// later.
if (input.type === inputTypes.DUMMY && activeRow.hasDummyInput &&
activeRow.align === constants.ALIGN.LEFT &&
input.align === constants.ALIGN.RIGHT) {
activeRow.align === Align.LEFT && input.align === Align.RIGHT) {
activeRow.rightAlignedDummyInput = input;
} else if (input.type === inputTypes.STATEMENT) {
// Handle statements without next connections correctly.

View File

@@ -97,6 +97,22 @@ const renamings = {
'6.20210701.0': {
'Blockly': {
exports: {
// Align.
ALIGN_LEFT: {
module: 'Blockly.Input',
export: 'Align.LEFT',
path: 'Blockly.ALIGN_LEFT',
},
ALIGN_CENTRE: {
module: 'Blockly.Input',
export: 'Align.CENTRE',
path: 'Blockly.ALIGN_CENTRE',
},
ALIGN_RIGHT: {
module: 'Blockly.Input',
export: 'Align.RIGHT',
path: 'Blockly.ALIGN_RIGHT',
},
// Clipboard. See PR #5237.
clipboardXml_: {module: 'Blockly.clipboard', export: 'xml'},
clipboardSource_: {module: 'Blockly.clipboard', export: 'source'},

View File

@@ -90,7 +90,7 @@ goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.Block
goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.svgMath'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.bumpObjects', 'Blockly.common', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.ConnectionType'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.ConnectionType', 'Blockly.Events.utils', 'Blockly.blockAnimations', 'Blockly.common', 'Blockly.constants', 'Blockly.internalConstants'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'});
@@ -147,7 +147,7 @@ goog.addDependency('../../core/renderers/common/debug.js', ['Blockly.blockRender
goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.ConnectionType', 'Blockly.FieldLabel', 'Blockly.blockRendering.Types', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Types', 'Blockly.blockRendering.debug', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.Input', 'Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.ConnectionType', 'Blockly.Events.MarkerMove', 'Blockly.Events.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.Connection', 'Blockly.ConnectionType', 'Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.debug', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
@@ -193,7 +193,7 @@ goog.addDependency('../../core/renderers/thrasos/renderer.js', ['Blockly.thrasos
goog.addDependency('../../core/renderers/thrasos/thrasos.js', ['Blockly.thrasos'], ['Blockly.thrasos.RenderInfo', 'Blockly.thrasos.Renderer'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.ConnectionType', 'Blockly.blockRendering.ConstantProvider', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/zelos/drawer.js', ['Blockly.zelos.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.blockRendering.debug', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.StatementInput', 'Blockly.zelos.TopRow'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Input', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.StatementInput', 'Blockly.zelos.TopRow'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/zelos/marker_svg.js', ['Blockly.zelos.MarkerSvg'], ['Blockly.blockRendering.MarkerSvg', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/zelos/measurables/bottom_row.js', ['Blockly.zelos.BottomRow'], ['Blockly.blockRendering.BottomRow', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/renderers/zelos/measurables/inputs.js', ['Blockly.zelos.StatementInput'], ['Blockly.blockRendering.StatementInput', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});

View File

@@ -564,7 +564,7 @@ suite('Block JSON initialization', function() {
'type': 'input_dummy',
'align': 'LEFT',
},
'input_dummy', undefined, Blockly.constants.ALIGN.LEFT);
'input_dummy', undefined, Blockly.ALIGN_LEFT);
});
test('"Right" align', function() {
@@ -573,7 +573,7 @@ suite('Block JSON initialization', function() {
'type': 'input_dummy',
'align': 'RIGHT',
},
'input_dummy', undefined, Blockly.constants.ALIGN.RIGHT);
'input_dummy', undefined, Blockly.ALIGN_RIGHT);
});
test('"Center" align', function() {
@@ -582,7 +582,7 @@ suite('Block JSON initialization', function() {
'type': 'input_dummy',
'align': 'CENTER',
},
'input_dummy', undefined, Blockly.constants.ALIGN.CENTRE);
'input_dummy', undefined, Blockly.ALIGN_CENTRE);
});
test('"Centre" align', function() {
@@ -591,7 +591,7 @@ suite('Block JSON initialization', function() {
'type': 'input_dummy',
'align': 'CENTRE',
},
'input_dummy', undefined, Blockly.constants.ALIGN.CENTRE);
'input_dummy', undefined, Blockly.ALIGN_CENTRE);
});
});
});