mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
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:
committed by
GitHub
parent
985af10f6e
commit
c0d22f2002
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user