From 4e31deca2b45f7140f30b75b87a458ceed7097a8 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 26 Feb 2021 11:12:53 -0800 Subject: [PATCH] Align constants -> Blockly.constants.ALIGN enum --- core/block.js | 8 ++++---- core/blockly.js | 15 +++++++++++++++ core/constants.js | 22 +++++++--------------- core/input.js | 6 +++--- core/renderers/common/info.js | 6 +++--- core/renderers/zelos/info.js | 4 ++-- tests/mocha/block_json_test.js | 16 ++++------------ 7 files changed, 38 insertions(+), 39 deletions(-) diff --git a/core/block.js b/core/block.js index 343fe0eb5..368e29dc5 100644 --- a/core/block.js +++ b/core/block.js @@ -1765,10 +1765,10 @@ Blockly.Block.prototype.fieldFromJson_ = function(element) { */ Blockly.Block.prototype.inputFromJson_ = function(element, warningPrefix) { var alignmentLookup = { - 'LEFT': Blockly.ALIGN_LEFT, - 'RIGHT': Blockly.ALIGN_RIGHT, - 'CENTRE': Blockly.ALIGN_CENTRE, - 'CENTER': Blockly.ALIGN_CENTRE + 'LEFT': Blockly.constants.ALIGN.LEFT, + 'RIGHT': Blockly.constants.ALIGN.RIGHT, + 'CENTRE': Blockly.constants.ALIGN.CENTRE, + 'CENTER': Blockly.constants.ALIGN.CENTRE }; var input = null; diff --git a/core/blockly.js b/core/blockly.js index 471b5042f..55bfa2f55 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -503,3 +503,18 @@ Blockly.unbindEvent_ = Blockly.browserEvents.unbind; * @see Blockly.browserEvents.conditionalBind */ Blockly.bindEventWithChecks_ = Blockly.browserEvents.conditionalBind; + +/** + * @see Blockly.constants.ALIGN.LEFT + */ +Blockly.ALIGN_LEFT = Blockly.constants.ALIGN.LEFT; + +/** + * @see Blockly.constants.ALIGN.CENTRE + */ +Blockly.ALIGN_CENTRE = Blockly.constants.ALIGN.CENTRE; + +/** + * @see Blockly.constants.ALIGN.RIGHT + */ +Blockly.ALIGN_RIGHT = Blockly.constants.ALIGN.RIGHT; diff --git a/core/constants.js b/core/constants.js index 8914bd140..4c91693b4 100644 --- a/core/constants.js +++ b/core/constants.js @@ -140,22 +140,14 @@ Blockly.PREVIOUS_STATEMENT = 4; Blockly.DUMMY_INPUT = 5; /** - * ENUM for left alignment. - * @const + * Enum for alignment of inputs. + * @enum {number} */ -Blockly.ALIGN_LEFT = -1; - -/** - * ENUM for centre alignment. - * @const - */ -Blockly.ALIGN_CENTRE = 0; - -/** - * ENUM for right alignment. - * @const - */ -Blockly.ALIGN_RIGHT = 1; +Blockly.constants.ALIGN = { + LEFT: -1, + CENTRE: 0, + RIGHT: 1 +}; /** * ENUM for no drag operation. diff --git a/core/input.js b/core/input.js index 6f7b63b7a..098471046 100644 --- a/core/input.js +++ b/core/input.js @@ -55,7 +55,7 @@ Blockly.Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Blockly.Input.prototype.align = Blockly.ALIGN_LEFT; +Blockly.Input.prototype.align = Blockly.constants.ALIGN.LEFT; /** * Is the input visible? @@ -242,8 +242,8 @@ Blockly.Input.prototype.setCheck = function(check) { /** * Change the alignment of the connection's field(s). - * @param {number} align One of Blockly.ALIGN_LEFT, ALIGN_CENTRE, ALIGN_RIGHT. - * In RTL mode directions are reversed, and ALIGN_RIGHT aligns to the left. + * @param {number} align One of the values of Blockly.constants.ALIGN. + * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. * @return {!Blockly.Input} The input being modified (to allow chaining). */ Blockly.Input.prototype.setAlign = function(align) { diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 4a262358a..b98c0cf36 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -591,14 +591,14 @@ Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row, } // Decide where the extra padding goes. - if (row.align == Blockly.ALIGN_LEFT) { + if (row.align == Blockly.constants.ALIGN.LEFT) { // Add padding to the end of the row. lastSpacer.width += missingSpace; - } else if (row.align == Blockly.ALIGN_CENTRE) { + } else if (row.align == Blockly.constants.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 == Blockly.ALIGN_RIGHT) { + } else if (row.align == Blockly.constants.ALIGN.RIGHT) { // Add padding at the beginning of the row. firstSpacer.width += missingSpace; } else { diff --git a/core/renderers/zelos/info.js b/core/renderers/zelos/info.js index 19d11e576..0ced02658 100644 --- a/core/renderers/zelos/info.js +++ b/core/renderers/zelos/info.js @@ -277,8 +277,8 @@ Blockly.zelos.RenderInfo.prototype.addInput_ = function(input, activeRow) { // right, keep track of the right aligned dummy input so we can add padding // later. if (input.type == Blockly.DUMMY_INPUT && activeRow.hasDummyInput && - activeRow.align == Blockly.ALIGN_LEFT && - input.align == Blockly.ALIGN_RIGHT) { + activeRow.align == Blockly.constants.ALIGN.LEFT && + input.align == Blockly.constants.ALIGN.RIGHT) { activeRow.rightAlignedDummyInput = input; } Blockly.zelos.RenderInfo.superClass_.addInput_.call(this, input, activeRow); diff --git a/tests/mocha/block_json_test.js b/tests/mocha/block_json_test.js index 6b93339fd..da025fa9b 100644 --- a/tests/mocha/block_json_test.js +++ b/tests/mocha/block_json_test.js @@ -561,9 +561,7 @@ suite('Block JSON initialization', function() { 'type': 'input_dummy', 'align': 'LEFT', }, - 'input_dummy', - undefined, - Blockly.ALIGN_LEFT); + 'input_dummy', undefined, Blockly.constants.ALIGN.LEFT); }); test('"Right" align', function() { @@ -572,9 +570,7 @@ suite('Block JSON initialization', function() { 'type': 'input_dummy', 'align': 'RIGHT', }, - 'input_dummy', - undefined, - Blockly.ALIGN_RIGHT); + 'input_dummy', undefined, Blockly.constants.ALIGN); }); test('"Center" align', function() { @@ -583,9 +579,7 @@ suite('Block JSON initialization', function() { 'type': 'input_dummy', 'align': 'CENTER', }, - 'input_dummy', - undefined, - Blockly.ALIGN_CENTRE); + 'input_dummy', undefined, Blockly.constants..); }); test('"Centre" align', function() { @@ -594,9 +588,7 @@ suite('Block JSON initialization', function() { 'type': 'input_dummy', 'align': 'CENTRE', }, - 'input_dummy', - undefined, - Blockly.ALIGN_CENTRE); + 'input_dummy', undefined, Blockly.constants.ALIGN.CENTRE); }); }); });