From ee185530358aec8ed6768d26c1dd730041827382 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Thu, 2 Dec 2021 11:23:31 +0000 Subject: [PATCH] refactor: Migrate `blocks/text.js` to `goog.module` syntax (#5766) * refactor: Migrate blocks/text.js to goog.module * refactor: Migrate blocks/text.js named requires * refactor: Factor out common properties of text_prompt* blocks * clang-format blocks/text.js * fix: Fix lint warnings for PR #5766 --- blocks/text.js | 821 +++++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 415 insertions(+), 408 deletions(-) diff --git a/blocks/text.js b/blocks/text.js index ca009e40c..755283fb6 100644 --- a/blocks/text.js +++ b/blocks/text.js @@ -6,270 +6,281 @@ /** * @fileoverview Text blocks for Blockly. - * @suppress {extraRequire|missingRequire|checkTypes} + * @suppress {checkTypes} */ 'use strict'; -goog.provide('Blockly.blocks.texts'); -goog.provide('Blockly.Constants.Text'); +goog.module('Blockly.blocks.texts'); -goog.require('Blockly'); -goog.require('Blockly.FieldDropdown'); -goog.require('Blockly.FieldImage'); +const Extensions = goog.require('Blockly.Extensions'); +const Msg = goog.require('Blockly.Msg'); +/* eslint-disable-next-line no-unused-vars */ +const xmlUtils = goog.require('Blockly.utils.xml'); +const {Align} = goog.require('Blockly.Input'); +/* eslint-disable-next-line no-unused-vars */ +const {Block} = goog.requireType('Blockly.Block'); +const {Blocks} = goog.require('Blockly.blocks'); +const {ConnectionType} = goog.require('Blockly.ConnectionType'); +const {FieldDropdown} = goog.require('Blockly.FieldDropdown'); +const {FieldImage} = goog.require('Blockly.FieldImage'); +const {FieldTextInput} = goog.require('Blockly.FieldTextInput'); +const {Mutator} = goog.require('Blockly.Mutator'); +/* eslint-disable-next-line no-unused-vars */ +const {Workspace} = goog.requireType('Blockly.Workspace'); +const {defineBlocksWithJsonArray} = goog.require('Blockly.common'); +/** @suppress {extraRequire} */ goog.require('Blockly.FieldMultilineInput'); -goog.require('Blockly.FieldTextInput'); +/** @suppress {extraRequire} */ goog.require('Blockly.FieldVariable'); -goog.require('Blockly.Mutator'); -/** - * Unused constant for the common HSV hue for all blocks in this category. - * @deprecated Use Blockly.Msg['TEXTS_HUE']. (2018 April 5) - */ -Blockly.Constants.Text.HUE = 160; - -Blockly.defineBlocksWithJsonArray([ +defineBlocksWithJsonArray([ // Block for text value { - "type": "text", - "message0": "%1", - "args0": [{ - "type": "field_input", - "name": "TEXT", - "text": "", + 'type': 'text', + 'message0': '%1', + 'args0': [{ + 'type': 'field_input', + 'name': 'TEXT', + 'text': '', }], - "output": "String", - "style": "text_blocks", - "helpUrl": "%{BKY_TEXT_TEXT_HELPURL}", - "tooltip": "%{BKY_TEXT_TEXT_TOOLTIP}", - "extensions": [ - "text_quotes", - "parent_tooltip_when_inline", + 'output': 'String', + 'style': 'text_blocks', + 'helpUrl': '%{BKY_TEXT_TEXT_HELPURL}', + 'tooltip': '%{BKY_TEXT_TEXT_TOOLTIP}', + 'extensions': [ + 'text_quotes', + 'parent_tooltip_when_inline', ], }, { - "type": "text_multiline", - "message0": "%1 %2", - "args0": [{ - "type": "field_image", - "src": 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAARCAYAAADpP' + - 'U2iAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAdhgAAHYYBXaITgQAAABh0RVh0' + - 'U29mdHdhcmUAcGFpbnQubmV0IDQuMS42/U4J6AAAAP1JREFUOE+Vks0KQUEYhjm' + - 'RIja4ABtZ2dm5A3t3Ia6AUm7CylYuQRaUhZSlLZJiQbFAyRnPN33y01HOW08z88' + - '73zpwzM4F3GWOCruvGIE4/rLaV+Nq1hVGMBqzhqlxgCys4wJA65xnogMHsQ5luj' + - 'nYHTejBBCK2mE4abjCgMGhNxHgDFWjDSG07kdfVa2pZMf4ZyMAdWmpZMfYOsLiD' + - 'MYMjlMB+K613QISRhTnITnsYg5yUd0DETmEoMlkFOeIT/A58iyK5E18BuTBfgYX' + - 'fwNJv4P9/oEBerLylOnRhygmGdPpTTBZAPkde61lbQe4moWUvYUZYLfUNftIY4z' + - 'wA5X2Z9AYnQrEAAAAASUVORK5CYII=', - "width": 12, - "height": 17, - "alt": '\u00B6', - }, - { - "type": "field_multilinetext", - "name": "TEXT", - "text": "", - }], - "output": "String", - "style": "text_blocks", - "helpUrl": "%{BKY_TEXT_TEXT_HELPURL}", - "tooltip": "%{BKY_TEXT_TEXT_TOOLTIP}", - "extensions": [ - "parent_tooltip_when_inline", + 'type': 'text_multiline', + 'message0': '%1 %2', + 'args0': [ + { + 'type': 'field_image', + 'src': + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAARCAYAAADpP' + + 'U2iAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAdhgAAHYYBXaITgQAAABh0RVh0' + + 'U29mdHdhcmUAcGFpbnQubmV0IDQuMS42/U4J6AAAAP1JREFUOE+Vks0KQUEYhjm' + + 'RIja4ABtZ2dm5A3t3Ia6AUm7CylYuQRaUhZSlLZJiQbFAyRnPN33y01HOW08z88' + + '73zpwzM4F3GWOCruvGIE4/rLaV+Nq1hVGMBqzhqlxgCys4wJA65xnogMHsQ5luj' + + 'nYHTejBBCK2mE4abjCgMGhNxHgDFWjDSG07kdfVa2pZMf4ZyMAdWmpZMfYOsLiD' + + 'MYMjlMB+K613QISRhTnITnsYg5yUd0DETmEoMlkFOeIT/A58iyK5E18BuTBfgYX' + + 'fwNJv4P9/oEBerLylOnRhygmGdPpTTBZAPkde61lbQe4moWUvYUZYLfUNftIY4z' + + 'wA5X2Z9AYnQrEAAAAASUVORK5CYII=', + 'width': 12, + 'height': 17, + 'alt': '\u00B6', + }, + { + 'type': 'field_multilinetext', + 'name': 'TEXT', + 'text': '', + }, + ], + 'output': 'String', + 'style': 'text_blocks', + 'helpUrl': '%{BKY_TEXT_TEXT_HELPURL}', + 'tooltip': '%{BKY_TEXT_TEXT_TOOLTIP}', + 'extensions': [ + 'parent_tooltip_when_inline', ], }, { - "type": "text_join", - "message0": "", - "output": "String", - "style": "text_blocks", - "helpUrl": "%{BKY_TEXT_JOIN_HELPURL}", - "tooltip": "%{BKY_TEXT_JOIN_TOOLTIP}", - "mutator": "text_join_mutator", + 'type': 'text_join', + 'message0': '', + 'output': 'String', + 'style': 'text_blocks', + 'helpUrl': '%{BKY_TEXT_JOIN_HELPURL}', + 'tooltip': '%{BKY_TEXT_JOIN_TOOLTIP}', + 'mutator': 'text_join_mutator', }, { - "type": "text_create_join_container", - "message0": "%{BKY_TEXT_CREATE_JOIN_TITLE_JOIN} %1 %2", - "args0": [{ - "type": "input_dummy", - }, - { - "type": "input_statement", - "name": "STACK", - }], - "style": "text_blocks", - "tooltip": "%{BKY_TEXT_CREATE_JOIN_TOOLTIP}", - "enableContextMenu": false, + 'type': 'text_create_join_container', + 'message0': '%{BKY_TEXT_CREATE_JOIN_TITLE_JOIN} %1 %2', + 'args0': [ + { + 'type': 'input_dummy', + }, + { + 'type': 'input_statement', + 'name': 'STACK', + }, + ], + 'style': 'text_blocks', + 'tooltip': '%{BKY_TEXT_CREATE_JOIN_TOOLTIP}', + 'enableContextMenu': false, }, { - "type": "text_create_join_item", - "message0": "%{BKY_TEXT_CREATE_JOIN_ITEM_TITLE_ITEM}", - "previousStatement": null, - "nextStatement": null, - "style": "text_blocks", - "tooltip": "%{BKY_TEXT_CREATE_JOIN_ITEM_TOOLTIP}", - "enableContextMenu": false, + 'type': 'text_create_join_item', + 'message0': '%{BKY_TEXT_CREATE_JOIN_ITEM_TITLE_ITEM}', + 'previousStatement': null, + 'nextStatement': null, + 'style': 'text_blocks', + 'tooltip': '%{BKY_TEXT_CREATE_JOIN_ITEM_TOOLTIP}', + 'enableContextMenu': false, }, { - "type": "text_append", - "message0": "%{BKY_TEXT_APPEND_TITLE}", - "args0": [{ - "type": "field_variable", - "name": "VAR", - "variable": "%{BKY_TEXT_APPEND_VARIABLE}", - }, - { - "type": "input_value", - "name": "TEXT", - }], - "previousStatement": null, - "nextStatement": null, - "style": "text_blocks", - "extensions": [ - "text_append_tooltip", + 'type': 'text_append', + 'message0': '%{BKY_TEXT_APPEND_TITLE}', + 'args0': [ + { + 'type': 'field_variable', + 'name': 'VAR', + 'variable': '%{BKY_TEXT_APPEND_VARIABLE}', + }, + { + 'type': 'input_value', + 'name': 'TEXT', + }, + ], + 'previousStatement': null, + 'nextStatement': null, + 'style': 'text_blocks', + 'extensions': [ + 'text_append_tooltip', ], }, { - "type": "text_length", - "message0": "%{BKY_TEXT_LENGTH_TITLE}", - "args0": [ + 'type': 'text_length', + 'message0': '%{BKY_TEXT_LENGTH_TITLE}', + 'args0': [ { - "type": "input_value", - "name": "VALUE", - "check": ['String', 'Array'], + 'type': 'input_value', + 'name': 'VALUE', + 'check': ['String', 'Array'], }, ], - "output": 'Number', - "style": "text_blocks", - "tooltip": "%{BKY_TEXT_LENGTH_TOOLTIP}", - "helpUrl": "%{BKY_TEXT_LENGTH_HELPURL}", + 'output': 'Number', + 'style': 'text_blocks', + 'tooltip': '%{BKY_TEXT_LENGTH_TOOLTIP}', + 'helpUrl': '%{BKY_TEXT_LENGTH_HELPURL}', }, { - "type": "text_isEmpty", - "message0": "%{BKY_TEXT_ISEMPTY_TITLE}", - "args0": [ + 'type': 'text_isEmpty', + 'message0': '%{BKY_TEXT_ISEMPTY_TITLE}', + 'args0': [ { - "type": "input_value", - "name": "VALUE", - "check": ['String', 'Array'], + 'type': 'input_value', + 'name': 'VALUE', + 'check': ['String', 'Array'], }, ], - "output": 'Boolean', - "style": "text_blocks", - "tooltip": "%{BKY_TEXT_ISEMPTY_TOOLTIP}", - "helpUrl": "%{BKY_TEXT_ISEMPTY_HELPURL}", + 'output': 'Boolean', + 'style': 'text_blocks', + 'tooltip': '%{BKY_TEXT_ISEMPTY_TOOLTIP}', + 'helpUrl': '%{BKY_TEXT_ISEMPTY_HELPURL}', }, { - "type": "text_indexOf", - "message0": "%{BKY_TEXT_INDEXOF_TITLE}", - "args0": [ + 'type': 'text_indexOf', + 'message0': '%{BKY_TEXT_INDEXOF_TITLE}', + 'args0': [ { - "type": "input_value", - "name": "VALUE", - "check": "String", + 'type': 'input_value', + 'name': 'VALUE', + 'check': 'String', }, { - "type": "field_dropdown", - "name": "END", - "options": [ + 'type': 'field_dropdown', + 'name': 'END', + 'options': [ [ - "%{BKY_TEXT_INDEXOF_OPERATOR_FIRST}", - "FIRST", + '%{BKY_TEXT_INDEXOF_OPERATOR_FIRST}', + 'FIRST', ], [ - "%{BKY_TEXT_INDEXOF_OPERATOR_LAST}", - "LAST", + '%{BKY_TEXT_INDEXOF_OPERATOR_LAST}', + 'LAST', ], ], }, { - "type": "input_value", - "name": "FIND", - "check": "String", + 'type': 'input_value', + 'name': 'FIND', + 'check': 'String', }, ], - "output": "Number", - "style": "text_blocks", - "helpUrl": "%{BKY_TEXT_INDEXOF_HELPURL}", - "inputsInline": true, - "extensions": [ - "text_indexOf_tooltip", + 'output': 'Number', + 'style': 'text_blocks', + 'helpUrl': '%{BKY_TEXT_INDEXOF_HELPURL}', + 'inputsInline': true, + 'extensions': [ + 'text_indexOf_tooltip', ], }, { - "type": "text_charAt", - "message0": "%{BKY_TEXT_CHARAT_TITLE}", // "in text %1 %2" - "args0": [ + 'type': 'text_charAt', + 'message0': '%{BKY_TEXT_CHARAT_TITLE}', // "in text %1 %2" + 'args0': [ { - "type": "input_value", - "name": "VALUE", - "check": "String", + 'type': 'input_value', + 'name': 'VALUE', + 'check': 'String', }, { - "type": "field_dropdown", - "name": "WHERE", - "options": [ - ["%{BKY_TEXT_CHARAT_FROM_START}", "FROM_START"], - ["%{BKY_TEXT_CHARAT_FROM_END}", "FROM_END"], - ["%{BKY_TEXT_CHARAT_FIRST}", "FIRST"], - ["%{BKY_TEXT_CHARAT_LAST}", "LAST"], - ["%{BKY_TEXT_CHARAT_RANDOM}", "RANDOM"], + 'type': 'field_dropdown', + 'name': 'WHERE', + 'options': [ + ['%{BKY_TEXT_CHARAT_FROM_START}', 'FROM_START'], + ['%{BKY_TEXT_CHARAT_FROM_END}', 'FROM_END'], + ['%{BKY_TEXT_CHARAT_FIRST}', 'FIRST'], + ['%{BKY_TEXT_CHARAT_LAST}', 'LAST'], + ['%{BKY_TEXT_CHARAT_RANDOM}', 'RANDOM'], ], }, ], - "output": "String", - "style": "text_blocks", - "helpUrl": "%{BKY_TEXT_CHARAT_HELPURL}", - "inputsInline": true, - "mutator": "text_charAt_mutator", + 'output': 'String', + 'style': 'text_blocks', + 'helpUrl': '%{BKY_TEXT_CHARAT_HELPURL}', + 'inputsInline': true, + 'mutator': 'text_charAt_mutator', }, ]); -Blockly.Blocks['text_getSubstring'] = { +Blocks['text_getSubstring'] = { /** * Block for getting substring. - * @this {Blockly.Block} + * @this {Block} */ init: function() { this['WHERE_OPTIONS_1'] = [ - [Blockly.Msg['TEXT_GET_SUBSTRING_START_FROM_START'], 'FROM_START'], - [Blockly.Msg['TEXT_GET_SUBSTRING_START_FROM_END'], 'FROM_END'], - [Blockly.Msg['TEXT_GET_SUBSTRING_START_FIRST'], 'FIRST'], + [Msg['TEXT_GET_SUBSTRING_START_FROM_START'], 'FROM_START'], + [Msg['TEXT_GET_SUBSTRING_START_FROM_END'], 'FROM_END'], + [Msg['TEXT_GET_SUBSTRING_START_FIRST'], 'FIRST'], ]; this['WHERE_OPTIONS_2'] = [ - [Blockly.Msg['TEXT_GET_SUBSTRING_END_FROM_START'], 'FROM_START'], - [Blockly.Msg['TEXT_GET_SUBSTRING_END_FROM_END'], 'FROM_END'], - [Blockly.Msg['TEXT_GET_SUBSTRING_END_LAST'], 'LAST'], + [Msg['TEXT_GET_SUBSTRING_END_FROM_START'], 'FROM_START'], + [Msg['TEXT_GET_SUBSTRING_END_FROM_END'], 'FROM_END'], + [Msg['TEXT_GET_SUBSTRING_END_LAST'], 'LAST'], ]; - this.setHelpUrl(Blockly.Msg['TEXT_GET_SUBSTRING_HELPURL']); + this.setHelpUrl(Msg['TEXT_GET_SUBSTRING_HELPURL']); this.setStyle('text_blocks'); - this.appendValueInput('STRING') - .setCheck('String') - .appendField(Blockly.Msg['TEXT_GET_SUBSTRING_INPUT_IN_TEXT']); + this.appendValueInput('STRING').setCheck('String').appendField( + Msg['TEXT_GET_SUBSTRING_INPUT_IN_TEXT']); this.appendDummyInput('AT1'); this.appendDummyInput('AT2'); - if (Blockly.Msg['TEXT_GET_SUBSTRING_TAIL']) { - this.appendDummyInput('TAIL') - .appendField(Blockly.Msg['TEXT_GET_SUBSTRING_TAIL']); + if (Msg['TEXT_GET_SUBSTRING_TAIL']) { + this.appendDummyInput('TAIL').appendField(Msg['TEXT_GET_SUBSTRING_TAIL']); } this.setInputsInline(true); this.setOutput(true, 'String'); this.updateAt_(1, true); this.updateAt_(2, true); - this.setTooltip(Blockly.Msg['TEXT_GET_SUBSTRING_TOOLTIP']); + this.setTooltip(Msg['TEXT_GET_SUBSTRING_TOOLTIP']); }, /** * Create XML to represent whether there are 'AT' inputs. * Backwards compatible serialization implementation. * @return {!Element} XML storage element. - * @this {Blockly.Block} + * @this {Block} */ mutationToDom: function() { - const container = Blockly.utils.xml.createElement('mutation'); - const isAt1 = this.getInput('AT1').type === Blockly.INPUT_VALUE; + const container = xmlUtils.createElement('mutation'); + const isAt1 = this.getInput('AT1').type === ConnectionType.INPUT_VALUE; container.setAttribute('at1', isAt1); - const isAt2 = this.getInput('AT2').type === Blockly.INPUT_VALUE; + const isAt2 = this.getInput('AT2').type === ConnectionType.INPUT_VALUE; container.setAttribute('at2', isAt2); return container; }, @@ -277,7 +288,7 @@ Blockly.Blocks['text_getSubstring'] = { * Parse XML to restore the 'AT' inputs. * Backwards compatible serialization implementation. * @param {!Element} xmlElement XML storage element. - * @this {Blockly.Block} + * @this {Block} */ domToMutation: function(xmlElement) { const isAt1 = (xmlElement.getAttribute('at1') === 'true'); @@ -297,7 +308,7 @@ Blockly.Blocks['text_getSubstring'] = { * @param {number} n Specify first or second input (1 or 2). * @param {boolean} isAt True if the input should exist. * @private - * @this {Blockly.Block} + * @this {Block} */ updateAt_: function(n, isAt) { // Create or delete an input for the numeric index. @@ -307,24 +318,23 @@ Blockly.Blocks['text_getSubstring'] = { // Create either a value 'AT' input or a dummy input. if (isAt) { this.appendValueInput('AT' + n).setCheck('Number'); - if (Blockly.Msg['ORDINAL_NUMBER_SUFFIX']) { + if (Msg['ORDINAL_NUMBER_SUFFIX']) { this.appendDummyInput('ORDINAL' + n) - .appendField(Blockly.Msg['ORDINAL_NUMBER_SUFFIX']); + .appendField(Msg['ORDINAL_NUMBER_SUFFIX']); } } else { this.appendDummyInput('AT' + n); } // Move tail, if present, to end of block. - if (n === 2 && Blockly.Msg['TEXT_GET_SUBSTRING_TAIL']) { + if (n === 2 && Msg['TEXT_GET_SUBSTRING_TAIL']) { this.removeInput('TAIL', true); - this.appendDummyInput('TAIL') - .appendField(Blockly.Msg['TEXT_GET_SUBSTRING_TAIL']); + this.appendDummyInput('TAIL').appendField(Msg['TEXT_GET_SUBSTRING_TAIL']); } - const menu = new Blockly.FieldDropdown( + const menu = new FieldDropdown( this['WHERE_OPTIONS_' + n], /** * @param {*} value The input value. - * @this {Blockly.FieldDropdown} + * @this {FieldDropdown} * @returns {null|undefined} Null if the field has been replaced; * otherwise undefined. */ @@ -343,8 +353,7 @@ Blockly.Blocks['text_getSubstring'] = { return undefined; }); - this.getInput('AT' + n) - .appendField(menu, 'WHERE' + n); + this.getInput('AT' + n).appendField(menu, 'WHERE' + n); if (n === 1) { this.moveInputBefore('AT1', 'AT2'); if (this.getInput('ORDINAL1')) { @@ -354,102 +363,80 @@ Blockly.Blocks['text_getSubstring'] = { }, }; -Blockly.Blocks['text_changeCase'] = { +Blocks['text_changeCase'] = { /** * Block for changing capitalization. - * @this {Blockly.Block} + * @this {Block} */ init: function() { const OPERATORS = [ - [Blockly.Msg['TEXT_CHANGECASE_OPERATOR_UPPERCASE'], 'UPPERCASE'], - [Blockly.Msg['TEXT_CHANGECASE_OPERATOR_LOWERCASE'], 'LOWERCASE'], - [Blockly.Msg['TEXT_CHANGECASE_OPERATOR_TITLECASE'], 'TITLECASE'], + [Msg['TEXT_CHANGECASE_OPERATOR_UPPERCASE'], 'UPPERCASE'], + [Msg['TEXT_CHANGECASE_OPERATOR_LOWERCASE'], 'LOWERCASE'], + [Msg['TEXT_CHANGECASE_OPERATOR_TITLECASE'], 'TITLECASE'], ]; - this.setHelpUrl(Blockly.Msg['TEXT_CHANGECASE_HELPURL']); + this.setHelpUrl(Msg['TEXT_CHANGECASE_HELPURL']); this.setStyle('text_blocks'); - this.appendValueInput('TEXT') - .setCheck('String') - .appendField(new Blockly.FieldDropdown(OPERATORS), 'CASE'); + this.appendValueInput('TEXT').setCheck('String').appendField( + new FieldDropdown(OPERATORS), 'CASE'); this.setOutput(true, 'String'); - this.setTooltip(Blockly.Msg['TEXT_CHANGECASE_TOOLTIP']); + this.setTooltip(Msg['TEXT_CHANGECASE_TOOLTIP']); }, }; -Blockly.Blocks['text_trim'] = { +Blocks['text_trim'] = { /** * Block for trimming spaces. - * @this {Blockly.Block} + * @this {Block} */ init: function() { const OPERATORS = [ - [Blockly.Msg['TEXT_TRIM_OPERATOR_BOTH'], 'BOTH'], - [Blockly.Msg['TEXT_TRIM_OPERATOR_LEFT'], 'LEFT'], - [Blockly.Msg['TEXT_TRIM_OPERATOR_RIGHT'], 'RIGHT'], + [Msg['TEXT_TRIM_OPERATOR_BOTH'], 'BOTH'], + [Msg['TEXT_TRIM_OPERATOR_LEFT'], 'LEFT'], + [Msg['TEXT_TRIM_OPERATOR_RIGHT'], 'RIGHT'], ]; - this.setHelpUrl(Blockly.Msg['TEXT_TRIM_HELPURL']); + this.setHelpUrl(Msg['TEXT_TRIM_HELPURL']); this.setStyle('text_blocks'); - this.appendValueInput('TEXT') - .setCheck('String') - .appendField(new Blockly.FieldDropdown(OPERATORS), 'MODE'); + this.appendValueInput('TEXT').setCheck('String').appendField( + new FieldDropdown(OPERATORS), 'MODE'); this.setOutput(true, 'String'); - this.setTooltip(Blockly.Msg['TEXT_TRIM_TOOLTIP']); + this.setTooltip(Msg['TEXT_TRIM_TOOLTIP']); }, }; -Blockly.Blocks['text_print'] = { +Blocks['text_print'] = { /** * Block for print statement. - * @this {Blockly.Block} + * @this {Block} */ init: function() { this.jsonInit({ - "message0": Blockly.Msg['TEXT_PRINT_TITLE'], - "args0": [ + 'message0': Msg['TEXT_PRINT_TITLE'], + 'args0': [ { - "type": "input_value", - "name": "TEXT", + 'type': 'input_value', + 'name': 'TEXT', }, ], - "previousStatement": null, - "nextStatement": null, - "style": "text_blocks", - "tooltip": Blockly.Msg['TEXT_PRINT_TOOLTIP'], - "helpUrl": Blockly.Msg['TEXT_PRINT_HELPURL'], + 'previousStatement': null, + 'nextStatement': null, + 'style': 'text_blocks', + 'tooltip': Msg['TEXT_PRINT_TOOLTIP'], + 'helpUrl': Msg['TEXT_PRINT_HELPURL'], }); }, }; -Blockly.Blocks['text_prompt_ext'] = { - /** - * Block for prompt function (external message). - * @this {Blockly.Block} - */ - init: function() { - const TYPES = [ - [Blockly.Msg['TEXT_PROMPT_TYPE_TEXT'], 'TEXT'], - [Blockly.Msg['TEXT_PROMPT_TYPE_NUMBER'], 'NUMBER'], - ]; - this.setHelpUrl(Blockly.Msg['TEXT_PROMPT_HELPURL']); - this.setStyle('text_blocks'); - // Assign 'this' to a variable for use in the closures below. - const thisBlock = this; - const dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) { - thisBlock.updateType_(newOp); - }); - this.appendValueInput('TEXT') - .appendField(dropdown, 'TYPE'); - this.setOutput(true, 'String'); - this.setTooltip(function() { - return (thisBlock.getFieldValue('TYPE') === 'TEXT') ? - Blockly.Msg['TEXT_PROMPT_TOOLTIP_TEXT'] : - Blockly.Msg['TEXT_PROMPT_TOOLTIP_NUMBER']; - }); - }, + +/** + * Common properties for the text_prompt_ext and text_prompt blocks + * definitions. + */ +const TEXT_PROMPT_COMMON = { /** * Modify this block to have the correct output type. * @param {string} newOp Either 'TEXT' or 'NUMBER'. * @private - * @this {Blockly.Block} + * @this {Block} */ updateType_: function(newOp) { this.outputConnection.setCheck(newOp === 'NUMBER' ? 'Number' : 'String'); @@ -458,10 +445,10 @@ Blockly.Blocks['text_prompt_ext'] = { * Create XML to represent the output type. * Backwards compatible serialization implementation. * @return {!Element} XML storage element. - * @this {Blockly.Block} + * @this {Block} */ mutationToDom: function() { - const container = Blockly.utils.xml.createElement('mutation'); + const container = xmlUtils.createElement('mutation'); container.setAttribute('type', this.getFieldValue('TYPE')); return container; }, @@ -469,11 +456,39 @@ Blockly.Blocks['text_prompt_ext'] = { * Parse XML to restore the output type. * Backwards compatible serialization implementation. * @param {!Element} xmlElement XML storage element. - * @this {Blockly.Block} + * @this {Block} */ domToMutation: function(xmlElement) { this.updateType_(xmlElement.getAttribute('type')); }, +}; + +Blocks['text_prompt_ext'] = { + ...TEXT_PROMPT_COMMON, + /** + * Block for prompt function (external message). + * @this {Block} + */ + init: function() { + const TYPES = [ + [Msg['TEXT_PROMPT_TYPE_TEXT'], 'TEXT'], + [Msg['TEXT_PROMPT_TYPE_NUMBER'], 'NUMBER'], + ]; + this.setHelpUrl(Msg['TEXT_PROMPT_HELPURL']); + this.setStyle('text_blocks'); + // Assign 'this' to a variable for use in the closures below. + const thisBlock = this; + const dropdown = new FieldDropdown(TYPES, function(newOp) { + thisBlock.updateType_(newOp); + }); + this.appendValueInput('TEXT').appendField(dropdown, 'TYPE'); + this.setOutput(true, 'String'); + this.setTooltip(function() { + return (thisBlock.getFieldValue('TYPE') === 'TEXT') ? + Msg['TEXT_PROMPT_TOOLTIP_TEXT'] : + Msg['TEXT_PROMPT_TOOLTIP_NUMBER']; + }); + }, // This block does not need JSO serialization hooks (saveExtraState and // loadExtraState) because the state of this object is already encoded in the @@ -481,157 +496,156 @@ Blockly.Blocks['text_prompt_ext'] = { // XML hooks are kept for backwards compatibility. }; -Blockly.Blocks['text_prompt'] = { +Blocks['text_prompt'] = { + ...TEXT_PROMPT_COMMON, /** * Block for prompt function (internal message). * The 'text_prompt_ext' block is preferred as it is more flexible. - * @this {Blockly.Block} + * @this {Block} */ init: function() { - this.mixin(Blockly.Constants.Text.QUOTE_IMAGE_MIXIN); + this.mixin(QUOTE_IMAGE_MIXIN); const TYPES = [ - [Blockly.Msg['TEXT_PROMPT_TYPE_TEXT'], 'TEXT'], - [Blockly.Msg['TEXT_PROMPT_TYPE_NUMBER'], 'NUMBER'], + [Msg['TEXT_PROMPT_TYPE_TEXT'], 'TEXT'], + [Msg['TEXT_PROMPT_TYPE_NUMBER'], 'NUMBER'], ]; // Assign 'this' to a variable for use in the closures below. const thisBlock = this; - this.setHelpUrl(Blockly.Msg['TEXT_PROMPT_HELPURL']); + this.setHelpUrl(Msg['TEXT_PROMPT_HELPURL']); this.setStyle('text_blocks'); - const dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) { + const dropdown = new FieldDropdown(TYPES, function(newOp) { thisBlock.updateType_(newOp); }); this.appendDummyInput() .appendField(dropdown, 'TYPE') .appendField(this.newQuote_(true)) - .appendField(new Blockly.FieldTextInput(''), 'TEXT') + .appendField(new FieldTextInput(''), 'TEXT') .appendField(this.newQuote_(false)); this.setOutput(true, 'String'); this.setTooltip(function() { return (thisBlock.getFieldValue('TYPE') === 'TEXT') ? - Blockly.Msg['TEXT_PROMPT_TOOLTIP_TEXT'] : - Blockly.Msg['TEXT_PROMPT_TOOLTIP_NUMBER']; + Msg['TEXT_PROMPT_TOOLTIP_TEXT'] : + Msg['TEXT_PROMPT_TOOLTIP_NUMBER']; }); }, - updateType_: Blockly.Blocks['text_prompt_ext'].updateType_, - mutationToDom: Blockly.Blocks['text_prompt_ext'].mutationToDom, - domToMutation: Blockly.Blocks['text_prompt_ext'].domToMutation, }; -Blockly.Blocks['text_count'] = { +Blocks['text_count'] = { /** * Block for counting how many times one string appears within another string. - * @this {Blockly.Block} + * @this {Block} */ init: function() { this.jsonInit({ - "message0": Blockly.Msg['TEXT_COUNT_MESSAGE0'], - "args0": [ + 'message0': Msg['TEXT_COUNT_MESSAGE0'], + 'args0': [ { - "type": "input_value", - "name": "SUB", - "check": "String", + 'type': 'input_value', + 'name': 'SUB', + 'check': 'String', }, { - "type": "input_value", - "name": "TEXT", - "check": "String", + 'type': 'input_value', + 'name': 'TEXT', + 'check': 'String', }, ], - "output": "Number", - "inputsInline": true, - "style": "text_blocks", - "tooltip": Blockly.Msg['TEXT_COUNT_TOOLTIP'], - "helpUrl": Blockly.Msg['TEXT_COUNT_HELPURL'], + 'output': 'Number', + 'inputsInline': true, + 'style': 'text_blocks', + 'tooltip': Msg['TEXT_COUNT_TOOLTIP'], + 'helpUrl': Msg['TEXT_COUNT_HELPURL'], }); }, }; -Blockly.Blocks['text_replace'] = { +Blocks['text_replace'] = { /** * Block for replacing one string with another in the text. - * @this {Blockly.Block} + * @this {Block} */ init: function() { this.jsonInit({ - "message0": Blockly.Msg['TEXT_REPLACE_MESSAGE0'], - "args0": [ + 'message0': Msg['TEXT_REPLACE_MESSAGE0'], + 'args0': [ { - "type": "input_value", - "name": "FROM", - "check": "String", + 'type': 'input_value', + 'name': 'FROM', + 'check': 'String', }, { - "type": "input_value", - "name": "TO", - "check": "String", + 'type': 'input_value', + 'name': 'TO', + 'check': 'String', }, { - "type": "input_value", - "name": "TEXT", - "check": "String", + 'type': 'input_value', + 'name': 'TEXT', + 'check': 'String', }, ], - "output": "String", - "inputsInline": true, - "style": "text_blocks", - "tooltip": Blockly.Msg['TEXT_REPLACE_TOOLTIP'], - "helpUrl": Blockly.Msg['TEXT_REPLACE_HELPURL'], + 'output': 'String', + 'inputsInline': true, + 'style': 'text_blocks', + 'tooltip': Msg['TEXT_REPLACE_TOOLTIP'], + 'helpUrl': Msg['TEXT_REPLACE_HELPURL'], }); }, }; -Blockly.Blocks['text_reverse'] = { +Blocks['text_reverse'] = { /** * Block for reversing a string. - * @this {Blockly.Block} + * @this {Block} */ init: function() { this.jsonInit({ - "message0": Blockly.Msg['TEXT_REVERSE_MESSAGE0'], - "args0": [ + 'message0': Msg['TEXT_REVERSE_MESSAGE0'], + 'args0': [ { - "type": "input_value", - "name": "TEXT", - "check": "String", + 'type': 'input_value', + 'name': 'TEXT', + 'check': 'String', }, ], - "output": "String", - "inputsInline": true, - "style": "text_blocks", - "tooltip": Blockly.Msg['TEXT_REVERSE_TOOLTIP'], - "helpUrl": Blockly.Msg['TEXT_REVERSE_HELPURL'], + 'output': 'String', + 'inputsInline': true, + 'style': 'text_blocks', + 'tooltip': Msg['TEXT_REVERSE_TOOLTIP'], + 'helpUrl': Msg['TEXT_REVERSE_HELPURL'], }); }, }; /** - * * @mixin * @package * @readonly */ -Blockly.Constants.Text.QUOTE_IMAGE_MIXIN = { +const QUOTE_IMAGE_MIXIN = { /** - * Image data URI of an LTR opening double quote (same as RTL closing double quote). + * Image data URI of an LTR opening double quote (same as RTL closing double + * quote). * @readonly */ QUOTE_IMAGE_LEFT_DATAURI: - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAA' + - 'n0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY' + - '1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1' + - 'HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMf' + - 'z9AylsaRRgGzvZAAAAAElFTkSuQmCC', + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAA' + + 'n0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY' + + '1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1' + + 'HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMf' + + 'z9AylsaRRgGzvZAAAAAElFTkSuQmCC', /** - * Image data URI of an LTR closing double quote (same as RTL opening double quote). + * Image data URI of an LTR closing double quote (same as RTL opening double + * quote). * @readonly */ QUOTE_IMAGE_RIGHT_DATAURI: - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAA' + - 'qUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhg' + - 'gONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvB' + - 'O3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5Aos' + - 'lLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==', + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAA' + + 'qUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhg' + + 'gONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvB' + + 'O3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5Aos' + + 'lLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==', /** * Pixel width of QUOTE_IMAGE_LEFT_DATAURI and QUOTE_IMAGE_RIGHT_DATAURI. * @readonly @@ -646,7 +660,7 @@ Blockly.Constants.Text.QUOTE_IMAGE_MIXIN = { /** * Inserts appropriate quote images before and after the named field. * @param {string} fieldName The name of the field to wrap with quotes. - * @this {Blockly.Block} + * @this {Block} */ quoteField_: function(fieldName) { for (let i = 0, input; (input = this.inputList[i]); i++) { @@ -658,7 +672,8 @@ Blockly.Constants.Text.QUOTE_IMAGE_MIXIN = { } } } - console.warn('field named "' + fieldName + '" not found in ' + this.toDevString()); + console.warn( + 'field named "' + fieldName + '" not found in ' + this.toDevString()); }, /** @@ -666,46 +681,43 @@ Blockly.Constants.Text.QUOTE_IMAGE_MIXIN = { * closing double quote. The selected quote will be adapted for RTL blocks. * @param {boolean} open If the image should be open quote (“ in LTR). * Otherwise, a closing quote is used (” in LTR). - * @return {!Blockly.FieldImage} The new field. - * @this {Blockly.Block} + * @return {!FieldImage} The new field. + * @this {Block} */ newQuote_: function(open) { const isLeft = this.RTL ? !open : open; - const dataUri = isLeft ? - this.QUOTE_IMAGE_LEFT_DATAURI : - this.QUOTE_IMAGE_RIGHT_DATAURI; - return new Blockly.FieldImage( - dataUri, - this.QUOTE_IMAGE_WIDTH, - this.QUOTE_IMAGE_HEIGHT, + const dataUri = + isLeft ? this.QUOTE_IMAGE_LEFT_DATAURI : this.QUOTE_IMAGE_RIGHT_DATAURI; + return new FieldImage( + dataUri, this.QUOTE_IMAGE_WIDTH, this.QUOTE_IMAGE_HEIGHT, isLeft ? '\u201C' : '\u201D'); }, }; /** * Wraps TEXT field with images of double quote characters. - * @this {Blockly.Block} + * @this {Block} */ -Blockly.Constants.Text.TEXT_QUOTES_EXTENSION = function() { - this.mixin(Blockly.Constants.Text.QUOTE_IMAGE_MIXIN); +const TEXT_QUOTES_EXTENSION = function() { + this.mixin(QUOTE_IMAGE_MIXIN); this.quoteField_('TEXT'); }; /** * Mixin for mutator functions in the 'text_join_mutator' extension. * @mixin - * @augments Blockly.Block + * @augments Block * @package */ -Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { +const TEXT_JOIN_MUTATOR_MIXIN = { /** * Create XML to represent number of text inputs. * Backwards compatible serialization implementation. * @return {!Element} XML storage element. - * @this {Blockly.Block} + * @this {Block} */ mutationToDom: function() { - const container = Blockly.utils.xml.createElement('mutation'); + const container = xmlUtils.createElement('mutation'); container.setAttribute('items', this.itemCount_); return container; }, @@ -713,7 +725,7 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { * Parse XML to restore the text inputs. * Backwards compatible serialization implementation. * @param {!Element} xmlElement XML storage element. - * @this {Blockly.Block} + * @this {Block} */ domToMutation: function(xmlElement) { this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10); @@ -738,9 +750,9 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { }, /** * Populate the mutator's dialog with this block's components. - * @param {!Blockly.Workspace} workspace Mutator's workspace. - * @return {!Blockly.Block} Root block in mutator. - * @this {Blockly.Block} + * @param {!Workspace} workspace Mutator's workspace. + * @return {!Block} Root block in mutator. + * @this {Block} */ decompose: function(workspace) { const containerBlock = workspace.newBlock('text_create_join_container'); @@ -756,8 +768,8 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { }, /** * Reconfigure this block based on the mutator dialog's components. - * @param {!Blockly.Block} containerBlock Root block in mutator. - * @this {Blockly.Block} + * @param {!Block} containerBlock Root block in mutator. + * @this {Block} */ compose: function(containerBlock) { let itemBlock = containerBlock.getInputTargetBlock('STACK'); @@ -765,8 +777,8 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { const connections = []; while (itemBlock && !itemBlock.isInsertionMarker()) { connections.push(itemBlock.valueConnection_); - itemBlock = itemBlock.nextConnection && - itemBlock.nextConnection.targetBlock(); + itemBlock = + itemBlock.nextConnection && itemBlock.nextConnection.targetBlock(); } // Disconnect any children that don't belong. for (let i = 0; i < this.itemCount_; i++) { @@ -779,13 +791,13 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { this.updateShape_(); // Reconnect any child blocks. for (let i = 0; i < this.itemCount_; i++) { - Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i); + Mutator.reconnect(connections[i], this, 'ADD' + i); } }, /** * Store pointers to any connected child blocks. - * @param {!Blockly.Block} containerBlock Root block in mutator. - * @this {Blockly.Block} + * @param {!Block} containerBlock Root block in mutator. + * @this {Block} */ saveConnections: function(containerBlock) { let itemBlock = containerBlock.getInputTargetBlock('STACK'); @@ -801,7 +813,7 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { /** * Modify this block to have the correct number of inputs. * @private - * @this {Blockly.Block} + * @this {Block} */ updateShape_: function() { if (this.itemCount_ && this.getInput('EMPTY')) { @@ -814,10 +826,9 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { // Add new inputs. for (let i = 0; i < this.itemCount_; i++) { if (!this.getInput('ADD' + i)) { - const input = this.appendValueInput('ADD' + i) - .setAlign(Blockly.ALIGN_RIGHT); + const input = this.appendValueInput('ADD' + i).setAlign(Align.RIGHT); if (i === 0) { - input.appendField(Blockly.Msg['TEXT_JOIN_TITLE_CREATEWITH']); + input.appendField(Msg['TEXT_JOIN_TITLE_CREATEWITH']); } } } @@ -830,51 +841,51 @@ Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN = { /** * Performs final setup of a text_join block. - * @this {Blockly.Block} + * @this {Block} */ -Blockly.Constants.Text.TEXT_JOIN_EXTENSION = function() { +const TEXT_JOIN_EXTENSION = function() { // Add the quote mixin for the itemCount_ = 0 case. - this.mixin(Blockly.Constants.Text.QUOTE_IMAGE_MIXIN); + this.mixin(QUOTE_IMAGE_MIXIN); // Initialize the mutator values. this.itemCount_ = 2; this.updateShape_(); // Configure the mutator UI. - this.setMutator(new Blockly.Mutator(['text_create_join_item'])); + this.setMutator(new Mutator(['text_create_join_item'])); }; // Update the tooltip of 'text_append' block to reference the variable. -Blockly.Extensions.register('text_append_tooltip', - Blockly.Extensions.buildTooltipWithFieldText( - '%{BKY_TEXT_APPEND_TOOLTIP}', 'VAR')); +Extensions.register( + 'text_append_tooltip', + Extensions.buildTooltipWithFieldText('%{BKY_TEXT_APPEND_TOOLTIP}', 'VAR')); /** * Update the tooltip of 'text_append' block to reference the variable. - * @this {Blockly.Block} + * @this {Block} */ -Blockly.Constants.Text.TEXT_INDEXOF_TOOLTIP_EXTENSION = function() { +const TEXT_INDEXOF_TOOLTIP_EXTENSION = function() { // Assign 'this' to a variable for use in the tooltip closure below. const thisBlock = this; this.setTooltip(function() { - return Blockly.Msg['TEXT_INDEXOF_TOOLTIP'].replace('%1', - thisBlock.workspace.options.oneBasedIndex ? '0' : '-1'); + return Msg['TEXT_INDEXOF_TOOLTIP'].replace( + '%1', thisBlock.workspace.options.oneBasedIndex ? '0' : '-1'); }); }; /** * Mixin for mutator functions in the 'text_charAt_mutator' extension. * @mixin - * @augments Blockly.Block + * @augments Block * @package */ -Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN = { +const TEXT_CHARAT_MUTATOR_MIXIN = { /** * Create XML to represent whether there is an 'AT' input. * Backwards compatible serialization implementation. * @return {!Element} XML storage element. - * @this {Blockly.Block} + * @this {Block} */ mutationToDom: function() { - const container = Blockly.utils.xml.createElement('mutation'); + const container = xmlUtils.createElement('mutation'); container.setAttribute('at', !!this.isAt_); return container; }, @@ -882,7 +893,7 @@ Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN = { * Parse XML to restore the 'AT' input. * Backwards compatible serialization implementation. * @param {!Element} xmlElement XML storage element. - * @this {Blockly.Block} + * @this {Block} */ domToMutation: function(xmlElement) { // Note: Until January 2013 this block did not have mutations, @@ -900,7 +911,7 @@ Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN = { * Create or delete an input for the numeric index. * @param {boolean} isAt True if the input should exist. * @private - * @this {Blockly.Block} + * @this {Block} */ updateAt_: function(isAt) { // Destroy old 'AT' and 'ORDINAL' inputs. @@ -909,15 +920,14 @@ Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN = { // Create either a value 'AT' input or a dummy input. if (isAt) { this.appendValueInput('AT').setCheck('Number'); - if (Blockly.Msg['ORDINAL_NUMBER_SUFFIX']) { - this.appendDummyInput('ORDINAL') - .appendField(Blockly.Msg['ORDINAL_NUMBER_SUFFIX']); + if (Msg['ORDINAL_NUMBER_SUFFIX']) { + this.appendDummyInput('ORDINAL').appendField( + Msg['ORDINAL_NUMBER_SUFFIX']); } } - if (Blockly.Msg['TEXT_CHARAT_TAIL']) { + if (Msg['TEXT_CHARAT_TAIL']) { this.removeInput('TAIL', true); - this.appendDummyInput('TAIL') - .appendField(Blockly.Msg['TEXT_CHARAT_TAIL']); + this.appendDummyInput('TAIL').appendField(Msg['TEXT_CHARAT_TAIL']); } this.isAt_ = isAt; @@ -926,51 +936,48 @@ Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN = { /** * Does the initial mutator update of text_charAt and adds the tooltip - * @this {Blockly.Block} + * @this {Block} */ -Blockly.Constants.Text.TEXT_CHARAT_EXTENSION = function() { +const TEXT_CHARAT_EXTENSION = function() { const dropdown = this.getField('WHERE'); dropdown.setValidator( - /** - * @param {*} value The input value. - * @this {Blockly.FieldDropdown} - */ - function(value) { - const newAt = (value === 'FROM_START') || (value === 'FROM_END'); - if (newAt !== this.isAt_) { - const block = this.getSourceBlock(); - block.updateAt_(newAt); - } - }); + /** + * @param {*} value The input value. + * @this {FieldDropdown} + */ + function(value) { + const newAt = (value === 'FROM_START') || (value === 'FROM_END'); + if (newAt !== this.isAt_) { + const block = this.getSourceBlock(); + block.updateAt_(newAt); + } + }); this.updateAt_(true); // Assign 'this' to a variable for use in the tooltip closure below. const thisBlock = this; this.setTooltip(function() { const where = thisBlock.getFieldValue('WHERE'); - let tooltip = Blockly.Msg['TEXT_CHARAT_TOOLTIP']; + let tooltip = Msg['TEXT_CHARAT_TOOLTIP']; if (where === 'FROM_START' || where === 'FROM_END') { const msg = (where === 'FROM_START') ? - Blockly.Msg['LISTS_INDEX_FROM_START_TOOLTIP'] : - Blockly.Msg['LISTS_INDEX_FROM_END_TOOLTIP']; + Msg['LISTS_INDEX_FROM_START_TOOLTIP'] : + Msg['LISTS_INDEX_FROM_END_TOOLTIP']; if (msg) { - tooltip += ' ' + msg.replace('%1', - thisBlock.workspace.options.oneBasedIndex ? '#1' : '#0'); + tooltip += ' ' + + msg.replace( + '%1', thisBlock.workspace.options.oneBasedIndex ? '#1' : '#0'); } } return tooltip; }); }; -Blockly.Extensions.register('text_indexOf_tooltip', - Blockly.Constants.Text.TEXT_INDEXOF_TOOLTIP_EXTENSION); +Extensions.register('text_indexOf_tooltip', TEXT_INDEXOF_TOOLTIP_EXTENSION); -Blockly.Extensions.register('text_quotes', - Blockly.Constants.Text.TEXT_QUOTES_EXTENSION); +Extensions.register('text_quotes', TEXT_QUOTES_EXTENSION); -Blockly.Extensions.registerMutator('text_join_mutator', - Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN, - Blockly.Constants.Text.TEXT_JOIN_EXTENSION); +Extensions.registerMutator( + 'text_join_mutator', TEXT_JOIN_MUTATOR_MIXIN, TEXT_JOIN_EXTENSION); -Blockly.Extensions.registerMutator('text_charAt_mutator', - Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN, - Blockly.Constants.Text.TEXT_CHARAT_EXTENSION); +Extensions.registerMutator( + 'text_charAt_mutator', TEXT_CHARAT_MUTATOR_MIXIN, TEXT_CHARAT_EXTENSION); diff --git a/tests/deps.js b/tests/deps.js index e73e51f1f..15cd566b6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -5,7 +5,7 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.blocks.logic'], ['Blockly. goog.addDependency('../../blocks/loops.js', ['Blockly.blocks.loops'], ['Blockly.ContextMenu', 'Blockly.Events', 'Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Msg', 'Blockly.Variables', 'Blockly.Warning', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../blocks/math.js', ['Blockly.blocks.math'], ['Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../blocks/procedures.js', ['Blockly.blocks.procedures'], ['Blockly.Comment', 'Blockly.ContextMenu', 'Blockly.Events', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Input', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.Names', 'Blockly.Procedures', 'Blockly.Variables', 'Blockly.Warning', 'Blockly.Xml', 'Blockly.blocks', 'Blockly.internalConstants', 'Blockly.utils.xml'], {'lang': 'es9', 'module': 'goog'}); -goog.addDependency('../../blocks/text.js', ['Blockly.Constants.Text', 'Blockly.blocks.texts'], ['Blockly', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator'], {'lang': 'es6'}); +goog.addDependency('../../blocks/text.js', ['Blockly.blocks.texts'], ['Blockly.ConnectionType', 'Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Input', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.blocks', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es9', 'module': 'goog'}); goog.addDependency('../../blocks/variables.js', ['Blockly.Constants.Variables', 'Blockly.blocks.variables'], ['Blockly', 'Blockly.FieldLabel', 'Blockly.FieldVariable'], {'lang': 'es6'}); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic', 'Blockly.blocks.variablesDynamic'], ['Blockly', 'Blockly.FieldLabel', 'Blockly.FieldVariable'], {'lang': 'es6'}); goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Connection', 'Blockly.ConnectionType', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.utils', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.blocks', 'Blockly.common', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.array', 'Blockly.utils.idGenerator', 'Blockly.utils.object', 'Blockly.utils.parsing'], {'lang': 'es6', 'module': 'goog'});