mirror of
https://github.com/google/blockly.git
synced 2026-01-12 19:37:08 +01:00
refactor: Migrate blocks/loops.js to goog.module syntax (#5755)
* refactor: Turn .getSurroundLoop into a (Block) method This considerably simplifies the code in the genrators, obviating the need for generators to import Blockly.Constants.Loops, and allowing the compiler to remove blocks/loops.js from the first (Blockly) chunk of the compilation. (The latter could and should have been arranged by making the generator chunks depend on the blocks chunk, but that is no longer necessary.) * refactor: Migrate blocks/loops.js to goog.module * refactor: Migrate blocks/loops.js named requires * chore: clang-format blocks/loops.js
This commit is contained in:
committed by
GitHub
parent
874bbc13c9
commit
208d2008a3
393
blocks/loops.js
393
blocks/loops.js
@@ -6,242 +6,248 @@
|
||||
|
||||
/**
|
||||
* @fileoverview Loop blocks for Blockly.
|
||||
* @suppress {extraRequire|missingRequire|checkTypes}
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.blocks.loops');
|
||||
goog.provide('Blockly.Constants.Loops');
|
||||
goog.module('Blockly.blocks.loops');
|
||||
|
||||
goog.require('Blockly');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const AbstractEvent = goog.requireType('Blockly.Events.Abstract');
|
||||
const ContextMenu = goog.require('Blockly.ContextMenu');
|
||||
const Events = goog.require('Blockly.Events');
|
||||
const Extensions = goog.require('Blockly.Extensions');
|
||||
const Msg = goog.require('Blockly.Msg');
|
||||
const Variables = goog.require('Blockly.Variables');
|
||||
const common = goog.require('Blockly.common');
|
||||
const xmlUtils = goog.require('Blockly.utils.xml');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const {Block} = goog.requireType('Blockly.Block');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldDropdown');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldLabel');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldNumber');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldVariable');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.Warning');
|
||||
|
||||
|
||||
/**
|
||||
* Unused constant for the common HSV hue for all blocks in this category.
|
||||
* @deprecated Use Blockly.Msg['LOOPS_HUE']. (2018 April 5)
|
||||
*/
|
||||
Blockly.Constants.Loops.HUE = 120;
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
common.defineBlocksWithJsonArray([
|
||||
// Block for repeat n times (external number).
|
||||
{
|
||||
"type": "controls_repeat_ext",
|
||||
"message0": "%{BKY_CONTROLS_REPEAT_TITLE}",
|
||||
"args0": [{
|
||||
"type": "input_value",
|
||||
"name": "TIMES",
|
||||
"check": "Number",
|
||||
'type': 'controls_repeat_ext',
|
||||
'message0': '%{BKY_CONTROLS_REPEAT_TITLE}',
|
||||
'args0': [{
|
||||
'type': 'input_value',
|
||||
'name': 'TIMES',
|
||||
'check': 'Number',
|
||||
}],
|
||||
"message1": "%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",
|
||||
"args1": [{
|
||||
"type": "input_statement",
|
||||
"name": "DO",
|
||||
'message1': '%{BKY_CONTROLS_REPEAT_INPUT_DO} %1',
|
||||
'args1': [{
|
||||
'type': 'input_statement',
|
||||
'name': 'DO',
|
||||
}],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"style": "loop_blocks",
|
||||
"tooltip": "%{BKY_CONTROLS_REPEAT_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_CONTROLS_REPEAT_HELPURL}",
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
'style': 'loop_blocks',
|
||||
'tooltip': '%{BKY_CONTROLS_REPEAT_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_CONTROLS_REPEAT_HELPURL}',
|
||||
},
|
||||
// Block for repeat n times (internal number).
|
||||
// The 'controls_repeat_ext' block is preferred as it is more flexible.
|
||||
{
|
||||
"type": "controls_repeat",
|
||||
"message0": "%{BKY_CONTROLS_REPEAT_TITLE}",
|
||||
"args0": [{
|
||||
"type": "field_number",
|
||||
"name": "TIMES",
|
||||
"value": 10,
|
||||
"min": 0,
|
||||
"precision": 1,
|
||||
'type': 'controls_repeat',
|
||||
'message0': '%{BKY_CONTROLS_REPEAT_TITLE}',
|
||||
'args0': [{
|
||||
'type': 'field_number',
|
||||
'name': 'TIMES',
|
||||
'value': 10,
|
||||
'min': 0,
|
||||
'precision': 1,
|
||||
}],
|
||||
"message1": "%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",
|
||||
"args1": [{
|
||||
"type": "input_statement",
|
||||
"name": "DO",
|
||||
'message1': '%{BKY_CONTROLS_REPEAT_INPUT_DO} %1',
|
||||
'args1': [{
|
||||
'type': 'input_statement',
|
||||
'name': 'DO',
|
||||
}],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"style": "loop_blocks",
|
||||
"tooltip": "%{BKY_CONTROLS_REPEAT_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_CONTROLS_REPEAT_HELPURL}",
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
'style': 'loop_blocks',
|
||||
'tooltip': '%{BKY_CONTROLS_REPEAT_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_CONTROLS_REPEAT_HELPURL}',
|
||||
},
|
||||
// Block for 'do while/until' loop.
|
||||
{
|
||||
"type": "controls_whileUntil",
|
||||
"message0": "%1 %2",
|
||||
"args0": [
|
||||
'type': 'controls_whileUntil',
|
||||
'message0': '%1 %2',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "MODE",
|
||||
"options": [
|
||||
["%{BKY_CONTROLS_WHILEUNTIL_OPERATOR_WHILE}", "WHILE"],
|
||||
["%{BKY_CONTROLS_WHILEUNTIL_OPERATOR_UNTIL}", "UNTIL"],
|
||||
'type': 'field_dropdown',
|
||||
'name': 'MODE',
|
||||
'options': [
|
||||
['%{BKY_CONTROLS_WHILEUNTIL_OPERATOR_WHILE}', 'WHILE'],
|
||||
['%{BKY_CONTROLS_WHILEUNTIL_OPERATOR_UNTIL}', 'UNTIL'],
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "BOOL",
|
||||
"check": "Boolean",
|
||||
'type': 'input_value',
|
||||
'name': 'BOOL',
|
||||
'check': 'Boolean',
|
||||
},
|
||||
],
|
||||
"message1": "%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",
|
||||
"args1": [{
|
||||
"type": "input_statement",
|
||||
"name": "DO",
|
||||
'message1': '%{BKY_CONTROLS_REPEAT_INPUT_DO} %1',
|
||||
'args1': [{
|
||||
'type': 'input_statement',
|
||||
'name': 'DO',
|
||||
}],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"style": "loop_blocks",
|
||||
"helpUrl": "%{BKY_CONTROLS_WHILEUNTIL_HELPURL}",
|
||||
"extensions": ["controls_whileUntil_tooltip"],
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
'style': 'loop_blocks',
|
||||
'helpUrl': '%{BKY_CONTROLS_WHILEUNTIL_HELPURL}',
|
||||
'extensions': ['controls_whileUntil_tooltip'],
|
||||
},
|
||||
// Block for 'for' loop.
|
||||
{
|
||||
"type": "controls_for",
|
||||
"message0": "%{BKY_CONTROLS_FOR_TITLE}",
|
||||
"args0": [
|
||||
'type': 'controls_for',
|
||||
'message0': '%{BKY_CONTROLS_FOR_TITLE}',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_variable",
|
||||
"name": "VAR",
|
||||
"variable": null,
|
||||
'type': 'field_variable',
|
||||
'name': 'VAR',
|
||||
'variable': null,
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "FROM",
|
||||
"check": "Number",
|
||||
"align": "RIGHT",
|
||||
'type': 'input_value',
|
||||
'name': 'FROM',
|
||||
'check': 'Number',
|
||||
'align': 'RIGHT',
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "TO",
|
||||
"check": "Number",
|
||||
"align": "RIGHT",
|
||||
'type': 'input_value',
|
||||
'name': 'TO',
|
||||
'check': 'Number',
|
||||
'align': 'RIGHT',
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "BY",
|
||||
"check": "Number",
|
||||
"align": "RIGHT",
|
||||
'type': 'input_value',
|
||||
'name': 'BY',
|
||||
'check': 'Number',
|
||||
'align': 'RIGHT',
|
||||
},
|
||||
],
|
||||
"message1": "%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",
|
||||
"args1": [{
|
||||
"type": "input_statement",
|
||||
"name": "DO",
|
||||
'message1': '%{BKY_CONTROLS_REPEAT_INPUT_DO} %1',
|
||||
'args1': [{
|
||||
'type': 'input_statement',
|
||||
'name': 'DO',
|
||||
}],
|
||||
"inputsInline": true,
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"style": "loop_blocks",
|
||||
"helpUrl": "%{BKY_CONTROLS_FOR_HELPURL}",
|
||||
"extensions": [
|
||||
"contextMenu_newGetVariableBlock",
|
||||
"controls_for_tooltip",
|
||||
'inputsInline': true,
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
'style': 'loop_blocks',
|
||||
'helpUrl': '%{BKY_CONTROLS_FOR_HELPURL}',
|
||||
'extensions': [
|
||||
'contextMenu_newGetVariableBlock',
|
||||
'controls_for_tooltip',
|
||||
],
|
||||
},
|
||||
// Block for 'for each' loop.
|
||||
{
|
||||
"type": "controls_forEach",
|
||||
"message0": "%{BKY_CONTROLS_FOREACH_TITLE}",
|
||||
"args0": [
|
||||
'type': 'controls_forEach',
|
||||
'message0': '%{BKY_CONTROLS_FOREACH_TITLE}',
|
||||
'args0': [
|
||||
{
|
||||
"type": "field_variable",
|
||||
"name": "VAR",
|
||||
"variable": null,
|
||||
'type': 'field_variable',
|
||||
'name': 'VAR',
|
||||
'variable': null,
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "LIST",
|
||||
"check": "Array",
|
||||
'type': 'input_value',
|
||||
'name': 'LIST',
|
||||
'check': 'Array',
|
||||
},
|
||||
],
|
||||
"message1": "%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",
|
||||
"args1": [{
|
||||
"type": "input_statement",
|
||||
"name": "DO",
|
||||
'message1': '%{BKY_CONTROLS_REPEAT_INPUT_DO} %1',
|
||||
'args1': [{
|
||||
'type': 'input_statement',
|
||||
'name': 'DO',
|
||||
}],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"style": "loop_blocks",
|
||||
"helpUrl": "%{BKY_CONTROLS_FOREACH_HELPURL}",
|
||||
"extensions": [
|
||||
"contextMenu_newGetVariableBlock",
|
||||
"controls_forEach_tooltip",
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
'style': 'loop_blocks',
|
||||
'helpUrl': '%{BKY_CONTROLS_FOREACH_HELPURL}',
|
||||
'extensions': [
|
||||
'contextMenu_newGetVariableBlock',
|
||||
'controls_forEach_tooltip',
|
||||
],
|
||||
},
|
||||
// Block for flow statements: continue, break.
|
||||
{
|
||||
"type": "controls_flow_statements",
|
||||
"message0": "%1",
|
||||
"args0": [{
|
||||
"type": "field_dropdown",
|
||||
"name": "FLOW",
|
||||
"options": [
|
||||
["%{BKY_CONTROLS_FLOW_STATEMENTS_OPERATOR_BREAK}", "BREAK"],
|
||||
["%{BKY_CONTROLS_FLOW_STATEMENTS_OPERATOR_CONTINUE}", "CONTINUE"],
|
||||
'type': 'controls_flow_statements',
|
||||
'message0': '%1',
|
||||
'args0': [{
|
||||
'type': 'field_dropdown',
|
||||
'name': 'FLOW',
|
||||
'options': [
|
||||
['%{BKY_CONTROLS_FLOW_STATEMENTS_OPERATOR_BREAK}', 'BREAK'],
|
||||
['%{BKY_CONTROLS_FLOW_STATEMENTS_OPERATOR_CONTINUE}', 'CONTINUE'],
|
||||
],
|
||||
}],
|
||||
"previousStatement": null,
|
||||
"style": "loop_blocks",
|
||||
"helpUrl": "%{BKY_CONTROLS_FLOW_STATEMENTS_HELPURL}",
|
||||
"suppressPrefixSuffix": true,
|
||||
"extensions": [
|
||||
"controls_flow_tooltip",
|
||||
"controls_flow_in_loop_check",
|
||||
'previousStatement': null,
|
||||
'style': 'loop_blocks',
|
||||
'helpUrl': '%{BKY_CONTROLS_FLOW_STATEMENTS_HELPURL}',
|
||||
'suppressPrefixSuffix': true,
|
||||
'extensions': [
|
||||
'controls_flow_tooltip',
|
||||
'controls_flow_in_loop_check',
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
/**
|
||||
* Tooltips for the 'controls_whileUntil' block, keyed by MODE value.
|
||||
* @see {Blockly.Extensions#buildTooltipForDropdown}
|
||||
* @package
|
||||
* @see {Extensions#buildTooltipForDropdown}
|
||||
* @readonly
|
||||
*/
|
||||
Blockly.Constants.Loops.WHILE_UNTIL_TOOLTIPS = {
|
||||
const WHILE_UNTIL_TOOLTIPS = {
|
||||
'WHILE': '%{BKY_CONTROLS_WHILEUNTIL_TOOLTIP_WHILE}',
|
||||
'UNTIL': '%{BKY_CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL}',
|
||||
};
|
||||
|
||||
Blockly.Extensions.register('controls_whileUntil_tooltip',
|
||||
Blockly.Extensions.buildTooltipForDropdown(
|
||||
'MODE', Blockly.Constants.Loops.WHILE_UNTIL_TOOLTIPS));
|
||||
Extensions.register(
|
||||
'controls_whileUntil_tooltip',
|
||||
Extensions.buildTooltipForDropdown('MODE', WHILE_UNTIL_TOOLTIPS));
|
||||
|
||||
/**
|
||||
* Tooltips for the 'controls_flow_statements' block, keyed by FLOW value.
|
||||
* @see {Blockly.Extensions#buildTooltipForDropdown}
|
||||
* @package
|
||||
* @see {Extensions#buildTooltipForDropdown}
|
||||
* @readonly
|
||||
*/
|
||||
Blockly.Constants.Loops.BREAK_CONTINUE_TOOLTIPS = {
|
||||
const BREAK_CONTINUE_TOOLTIPS = {
|
||||
'BREAK': '%{BKY_CONTROLS_FLOW_STATEMENTS_TOOLTIP_BREAK}',
|
||||
'CONTINUE': '%{BKY_CONTROLS_FLOW_STATEMENTS_TOOLTIP_CONTINUE}',
|
||||
};
|
||||
|
||||
Blockly.Extensions.register('controls_flow_tooltip',
|
||||
Blockly.Extensions.buildTooltipForDropdown(
|
||||
'FLOW', Blockly.Constants.Loops.BREAK_CONTINUE_TOOLTIPS));
|
||||
Extensions.register(
|
||||
'controls_flow_tooltip',
|
||||
Extensions.buildTooltipForDropdown('FLOW', BREAK_CONTINUE_TOOLTIPS));
|
||||
|
||||
/**
|
||||
* Mixin to add a context menu item to create a 'variables_get' block.
|
||||
* Used by blocks 'controls_for' and 'controls_forEach'.
|
||||
* @mixin
|
||||
* @augments Blockly.Block
|
||||
* @augments Block
|
||||
* @package
|
||||
* @readonly
|
||||
*/
|
||||
Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = {
|
||||
const CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = {
|
||||
/**
|
||||
* Add context menu option to create getter block for the loop's variable.
|
||||
* (customContextMenu support limited to web BlockSvg.)
|
||||
* @param {!Array} options List of menu options to add to.
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
*/
|
||||
customContextMenu: function(options) {
|
||||
if (this.isInFlyout) {
|
||||
@@ -251,61 +257,71 @@ Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = {
|
||||
const varName = variable.name;
|
||||
if (!this.isCollapsed() && varName !== null) {
|
||||
const option = {enabled: true};
|
||||
option.text =
|
||||
Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', varName);
|
||||
const xmlField = Blockly.Variables.generateVariableFieldDom(variable);
|
||||
const xmlBlock = Blockly.utils.xml.createElement('block');
|
||||
option.text = Msg['VARIABLES_SET_CREATE_GET'].replace('%1', varName);
|
||||
const xmlField = Variables.generateVariableFieldDom(variable);
|
||||
const xmlBlock = xmlUtils.createElement('block');
|
||||
xmlBlock.setAttribute('type', 'variables_get');
|
||||
xmlBlock.appendChild(xmlField);
|
||||
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
|
||||
option.callback = ContextMenu.callbackFactory(this, xmlBlock);
|
||||
options.push(option);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Extensions.registerMixin('contextMenu_newGetVariableBlock',
|
||||
Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN);
|
||||
Extensions.registerMixin(
|
||||
'contextMenu_newGetVariableBlock',
|
||||
CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN);
|
||||
|
||||
Blockly.Extensions.register('controls_for_tooltip',
|
||||
Blockly.Extensions.buildTooltipWithFieldText(
|
||||
'%{BKY_CONTROLS_FOR_TOOLTIP}', 'VAR'));
|
||||
Extensions.register(
|
||||
'controls_for_tooltip',
|
||||
Extensions.buildTooltipWithFieldText('%{BKY_CONTROLS_FOR_TOOLTIP}', 'VAR'));
|
||||
|
||||
Blockly.Extensions.register('controls_forEach_tooltip',
|
||||
Blockly.Extensions.buildTooltipWithFieldText(
|
||||
Extensions.register(
|
||||
'controls_forEach_tooltip',
|
||||
Extensions.buildTooltipWithFieldText(
|
||||
'%{BKY_CONTROLS_FOREACH_TOOLTIP}', 'VAR'));
|
||||
|
||||
/**
|
||||
* List of block types that are loops and thus do not need warnings.
|
||||
* To add a new loop type add this to your code:
|
||||
*
|
||||
* // If using the Blockly npm package and es6 import syntax:
|
||||
* import {loopTypes} from 'blockly/blocks';
|
||||
* loopTypes.push('custom_loop');
|
||||
*
|
||||
* // Else if using Closure Compiler and goog.modules:
|
||||
* const {loopTypes} = goog.require('Blockly.blocks.loops');
|
||||
* loopTypes.push('custom_loop');
|
||||
*
|
||||
* @type {!Array<string>}
|
||||
*/
|
||||
const loopTypes = [
|
||||
'controls_repeat',
|
||||
'controls_repeat_ext',
|
||||
'controls_forEach',
|
||||
'controls_for',
|
||||
'controls_whileUntil',
|
||||
];
|
||||
exports.loopTypes = loopTypes;
|
||||
|
||||
/**
|
||||
* This mixin adds a check to make sure the 'controls_flow_statements' block
|
||||
* is contained in a loop. Otherwise a warning is added to the block.
|
||||
* @mixin
|
||||
* @augments Blockly.Block
|
||||
* @augments Block
|
||||
* @public
|
||||
* @readonly
|
||||
*/
|
||||
Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {
|
||||
const CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {
|
||||
/**
|
||||
* List of block types that are loops and thus do not need warnings.
|
||||
* To add a new loop type add this to your code:
|
||||
* Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.LOOP_TYPES.push('custom_loop');
|
||||
* Is this block enclosed (at any level) by a loop?
|
||||
* @return {Block} The nearest surrounding loop, or null if none.
|
||||
* @this {Block}
|
||||
*/
|
||||
LOOP_TYPES: [
|
||||
'controls_repeat',
|
||||
'controls_repeat_ext',
|
||||
'controls_forEach',
|
||||
'controls_for',
|
||||
'controls_whileUntil',
|
||||
],
|
||||
|
||||
/**
|
||||
* Is the given block enclosed (at any level) by a loop?
|
||||
* @param {!Blockly.Block} block Current block.
|
||||
* @return {Blockly.Block} The nearest surrounding loop, or null if none.
|
||||
*/
|
||||
getSurroundLoop: function(block) {
|
||||
// Is the block nested in a loop?
|
||||
getSurroundLoop: function() {
|
||||
let block = this;
|
||||
do {
|
||||
if (Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.LOOP_TYPES
|
||||
.indexOf(block.type) !== -1) {
|
||||
if (loopTypes.includes(block.type)) {
|
||||
return block;
|
||||
}
|
||||
block = block.getSurroundParent();
|
||||
@@ -316,30 +332,29 @@ Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {
|
||||
/**
|
||||
* Called whenever anything on the workspace changes.
|
||||
* Add warning if this flow block is not nested inside a loop.
|
||||
* @param {!Blockly.Events.Abstract} e Change event.
|
||||
* @this {Blockly.Block}
|
||||
* @param {!AbstractEvent} e Change event.
|
||||
* @this {Block}
|
||||
*/
|
||||
onchange: function(e) {
|
||||
// Don't change state if:
|
||||
// * It's at the start of a drag.
|
||||
// * It's not a move event.
|
||||
if (!this.workspace.isDragging || this.workspace.isDragging() ||
|
||||
e.type !== Blockly.Events.BLOCK_MOVE) {
|
||||
e.type !== Events.BLOCK_MOVE) {
|
||||
return;
|
||||
}
|
||||
const enabled = Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN
|
||||
.getSurroundLoop(this);
|
||||
this.setWarningText(enabled ? null :
|
||||
Blockly.Msg['CONTROLS_FLOW_STATEMENTS_WARNING']);
|
||||
const enabled = this.getSurroundLoop(this);
|
||||
this.setWarningText(
|
||||
enabled ? null : Msg['CONTROLS_FLOW_STATEMENTS_WARNING']);
|
||||
if (!this.isInFlyout) {
|
||||
const group = Blockly.Events.getGroup();
|
||||
const group = Events.getGroup();
|
||||
// Makes it so the move and the disable event get undone together.
|
||||
Blockly.Events.setGroup(e.group);
|
||||
Events.setGroup(e.group);
|
||||
this.setEnabled(enabled);
|
||||
Blockly.Events.setGroup(group);
|
||||
Events.setGroup(group);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Blockly.Extensions.registerMixin('controls_flow_in_loop_check',
|
||||
Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN);
|
||||
Extensions.registerMixin(
|
||||
'controls_flow_in_loop_check', CONTROL_FLOW_IN_LOOP_CHECK_MIXIN);
|
||||
|
||||
@@ -152,8 +152,7 @@ Blockly.Dart['controls_flow_statements'] = function(block) {
|
||||
xfix += Blockly.Dart.injectId(Blockly.Dart.STATEMENT_SUFFIX, block);
|
||||
}
|
||||
if (Blockly.Dart.STATEMENT_PREFIX) {
|
||||
const loop = Blockly.Constants.Loops
|
||||
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
|
||||
const loop = block.getSurroundLoop();
|
||||
if (loop && !loop.suppressPrefixSuffix) {
|
||||
// Inject loop's statement prefix here since the regular one at the end
|
||||
// of the loop will not get executed if 'continue' is triggered.
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
goog.provide('Blockly.JavaScript.loops');
|
||||
|
||||
goog.require('Blockly.Constants.Loops');
|
||||
goog.require('Blockly.JavaScript');
|
||||
goog.require('Blockly.utils.string');
|
||||
|
||||
@@ -167,8 +166,7 @@ Blockly.JavaScript['controls_flow_statements'] = function(block) {
|
||||
block);
|
||||
}
|
||||
if (Blockly.JavaScript.STATEMENT_PREFIX) {
|
||||
const loop = Blockly.Constants.Loops
|
||||
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
|
||||
const loop = block.getSurroundLoop();
|
||||
if (loop && !loop.suppressPrefixSuffix) {
|
||||
// Inject loop's statement prefix here since the regular one at the end
|
||||
// of the loop will not get executed if 'continue' is triggered.
|
||||
|
||||
@@ -156,8 +156,7 @@ Blockly.Lua['controls_flow_statements'] = function(block) {
|
||||
xfix += Blockly.Lua.injectId(Blockly.Lua.STATEMENT_SUFFIX, block);
|
||||
}
|
||||
if (Blockly.Lua.STATEMENT_PREFIX) {
|
||||
const loop = Blockly.Constants.Loops
|
||||
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
|
||||
const loop = block.getSurroundLoop();
|
||||
if (loop && !loop.suppressPrefixSuffix) {
|
||||
// Inject loop's statement prefix here since the regular one at the end
|
||||
// of the loop will not get executed if 'continue' is triggered.
|
||||
|
||||
@@ -153,8 +153,7 @@ Blockly.PHP['controls_flow_statements'] = function(block) {
|
||||
xfix += Blockly.PHP.injectId(Blockly.PHP.STATEMENT_SUFFIX, block);
|
||||
}
|
||||
if (Blockly.PHP.STATEMENT_PREFIX) {
|
||||
const loop = Blockly.Constants.Loops
|
||||
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
|
||||
const loop = block.getSurroundLoop();
|
||||
if (loop && !loop.suppressPrefixSuffix) {
|
||||
// Inject loop's statement prefix here since the regular one at the end
|
||||
// of the loop will not get executed if 'continue' is triggered.
|
||||
|
||||
@@ -197,8 +197,7 @@ Blockly.Python['controls_flow_statements'] = function(block) {
|
||||
xfix += Blockly.Python.injectId(Blockly.Python.STATEMENT_SUFFIX, block);
|
||||
}
|
||||
if (Blockly.Python.STATEMENT_PREFIX) {
|
||||
const loop = Blockly.Constants.Loops
|
||||
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
|
||||
const loop = block.getSurroundLoop();
|
||||
if (loop && !loop.suppressPrefixSuffix) {
|
||||
// Inject loop's statement prefix here since the regular one at the end
|
||||
// of the loop will not get executed if 'continue' is triggered.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"chunk": [
|
||||
"requires:259",
|
||||
"all:9:requires",
|
||||
"requires:258",
|
||||
"all:10:requires",
|
||||
"all1:11:requires",
|
||||
"all2:11:requires",
|
||||
"all3:11:requires",
|
||||
@@ -11,68 +11,68 @@
|
||||
"js": [
|
||||
"./core/serialization/workspaces.js",
|
||||
"./core/serialization/variables.js",
|
||||
"./core/inject.js",
|
||||
"./core/flyout_vertical.js",
|
||||
"./core/toolbox/toolbox.js",
|
||||
"./core/interfaces/i_styleable.js",
|
||||
"./core/flyout_horizontal.js",
|
||||
"./core/flyout_base.js",
|
||||
"./core/flyout_metrics_manager.js",
|
||||
"./core/field_variable.js",
|
||||
"./core/field_number.js",
|
||||
"./core/field_multilineinput.js",
|
||||
"./core/field_label_serializable.js",
|
||||
"./core/field_colour.js",
|
||||
"./core/field_checkbox.js",
|
||||
"./core/field_angle.js",
|
||||
"./core/toolbox/collapsible_category.js",
|
||||
"./core/renderers/zelos/measurables/top_row.js",
|
||||
"./core/renderers/zelos/measurables/inputs.js",
|
||||
"./core/renderers/zelos/measurables/row_elements.js",
|
||||
"./core/renderers/zelos/marker_svg.js",
|
||||
"./core/renderers/zelos/renderer.js",
|
||||
"./core/field_textinput.js",
|
||||
"./core/field_image.js",
|
||||
"./core/renderers/zelos/info.js",
|
||||
"./core/renderers/zelos/path_object.js",
|
||||
"./core/renderers/zelos/drawer.js",
|
||||
"./core/renderers/zelos/constants.js",
|
||||
"./core/renderers/zelos/measurables/bottom_row.js",
|
||||
"./core/renderers/zelos/zelos.js",
|
||||
"./core/renderers/thrasos/renderer.js",
|
||||
"./core/renderers/thrasos/info.js",
|
||||
"./core/renderers/thrasos/thrasos.js",
|
||||
"./core/contextmenu_items.js",
|
||||
"./core/shortcut_items.js",
|
||||
"./core/theme/zelos.js",
|
||||
"./core/theme/themes.js",
|
||||
"./core/renderers/geras/constants.js",
|
||||
"./core/renderers/geras/highlight_constants.js",
|
||||
"./core/renderers/geras/measurables/inline_input.js",
|
||||
"./core/renderers/geras/path_object.js",
|
||||
"./core/renderers/geras/renderer.js",
|
||||
"./core/renderers/geras/measurables/statement_input.js",
|
||||
"./core/renderers/geras/info.js",
|
||||
"./core/renderers/geras/highlighter.js",
|
||||
"./core/renderers/geras/drawer.js",
|
||||
"./core/renderers/geras/geras.js",
|
||||
"./core/renderers/minimalist/constants.js",
|
||||
"./core/renderers/minimalist/renderer.js",
|
||||
"./core/renderers/minimalist/info.js",
|
||||
"./core/renderers/minimalist/drawer.js",
|
||||
"./core/renderers/minimalist/constants.js",
|
||||
"./core/renderers/minimalist/minimalist.js",
|
||||
"./core/renderers/geras/measurables/statement_input.js",
|
||||
"./core/renderers/geras/path_object.js",
|
||||
"./core/renderers/geras/renderer.js",
|
||||
"./core/renderers/geras/measurables/inline_input.js",
|
||||
"./core/renderers/geras/info.js",
|
||||
"./core/renderers/geras/highlight_constants.js",
|
||||
"./core/renderers/geras/highlighter.js",
|
||||
"./core/renderers/geras/drawer.js",
|
||||
"./core/renderers/geras/constants.js",
|
||||
"./core/renderers/geras/geras.js",
|
||||
"./core/theme/zelos.js",
|
||||
"./core/theme/themes.js",
|
||||
"./core/shortcut_items.js",
|
||||
"./core/contextmenu_items.js",
|
||||
"./core/menu.js",
|
||||
"./core/menuitem.js",
|
||||
"./core/clipboard.js",
|
||||
"./core/widgetdiv.js",
|
||||
"./core/contextmenu.js",
|
||||
"./core/blockly.js",
|
||||
"./core/renderers/thrasos/renderer.js",
|
||||
"./core/renderers/thrasos/info.js",
|
||||
"./core/renderers/thrasos/thrasos.js",
|
||||
"./core/renderers/zelos/measurables/bottom_row.js",
|
||||
"./core/renderers/zelos/constants.js",
|
||||
"./core/renderers/zelos/path_object.js",
|
||||
"./core/field_image.js",
|
||||
"./core/field_textinput.js",
|
||||
"./core/renderers/zelos/marker_svg.js",
|
||||
"./core/renderers/zelos/renderer.js",
|
||||
"./core/renderers/zelos/measurables/row_elements.js",
|
||||
"./core/renderers/zelos/measurables/inputs.js",
|
||||
"./core/renderers/zelos/measurables/top_row.js",
|
||||
"./core/renderers/zelos/info.js",
|
||||
"./core/renderers/zelos/drawer.js",
|
||||
"./core/renderers/zelos/zelos.js",
|
||||
"./core/toolbox/collapsible_category.js",
|
||||
"./core/field_angle.js",
|
||||
"./core/field_checkbox.js",
|
||||
"./core/field_colour.js",
|
||||
"./core/field_label_serializable.js",
|
||||
"./core/field_multilineinput.js",
|
||||
"./core/flyout_metrics_manager.js",
|
||||
"./core/flyout_base.js",
|
||||
"./core/generator.js",
|
||||
"./core/flyout_horizontal.js",
|
||||
"./core/interfaces/i_styleable.js",
|
||||
"./core/toolbox/toolbox.js",
|
||||
"./core/flyout_vertical.js",
|
||||
"./core/inject.js",
|
||||
"./core/blockly.js",
|
||||
"./core/field_variable.js",
|
||||
"./core/field_number.js",
|
||||
"./core/field_dropdown.js",
|
||||
"./core/events/workspace_events.js",
|
||||
"./core/events/events_toolbox_item_select.js",
|
||||
"./core/events/events_ui.js",
|
||||
"./core/events/events.js",
|
||||
"./core/widgetdiv.js",
|
||||
"./core/clipboard.js",
|
||||
"./core/menuitem.js",
|
||||
"./core/menu.js",
|
||||
"./core/contextmenu.js",
|
||||
"./core/blocks.js",
|
||||
"./core/utils/useragent.js",
|
||||
"./core/utils/svg.js",
|
||||
@@ -266,13 +266,13 @@
|
||||
"./core/utils/global.js",
|
||||
"./core/msg.js",
|
||||
"./closure/goog/base_minimal.js",
|
||||
"./blocks/loops.js",
|
||||
"./core/requires.js",
|
||||
"./blocks/variables_dynamic.js",
|
||||
"./blocks/variables.js",
|
||||
"./blocks/text.js",
|
||||
"./blocks/procedures.js",
|
||||
"./blocks/math.js",
|
||||
"./blocks/loops.js",
|
||||
"./blocks/logic.js",
|
||||
"./blocks/lists.js",
|
||||
"./blocks/colour.js",
|
||||
|
||||
@@ -2,7 +2,7 @@ goog.addDependency('../../blocks/all.js', ['Blockly.blocks.all'], ['Blockly.bloc
|
||||
goog.addDependency('../../blocks/colour.js', ['Blockly.blocks.colour'], ['Blockly.common'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/lists.js', ['Blockly.blocks.lists'], ['Blockly.ConnectionType', 'Blockly.FieldDropdown', 'Blockly.Input', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.blocks', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/logic.js', ['Blockly.blocks.logic'], ['Blockly.Events', 'Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/loops.js', ['Blockly.Constants.Loops', 'Blockly.blocks.loops'], ['Blockly', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning'], {'lang': 'es6'});
|
||||
goog.addDependency('../../blocks/loops.js', ['Blockly.blocks.loops'], ['Blockly.Block', 'Blockly.ContextMenu', 'Blockly.Events', 'Blockly.Events.Abstract', '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.Constants.Math', 'Blockly.blocks.math'], ['Blockly', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable'], {'lang': 'es6'});
|
||||
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'});
|
||||
@@ -281,7 +281,7 @@ goog.addDependency('../../generators/javascript/all.js', ['Blockly.JavaScript.al
|
||||
goog.addDependency('../../generators/javascript/colour.js', ['Blockly.JavaScript.colour'], ['Blockly.JavaScript'], {'lang': 'es6'});
|
||||
goog.addDependency('../../generators/javascript/lists.js', ['Blockly.JavaScript.lists'], ['Blockly.JavaScript'], {'lang': 'es6'});
|
||||
goog.addDependency('../../generators/javascript/logic.js', ['Blockly.JavaScript.logic'], ['Blockly.JavaScript'], {'lang': 'es6'});
|
||||
goog.addDependency('../../generators/javascript/loops.js', ['Blockly.JavaScript.loops'], ['Blockly.Constants.Loops', 'Blockly.JavaScript', 'Blockly.utils.string'], {'lang': 'es6'});
|
||||
goog.addDependency('../../generators/javascript/loops.js', ['Blockly.JavaScript.loops'], ['Blockly.JavaScript', 'Blockly.utils.string'], {'lang': 'es6'});
|
||||
goog.addDependency('../../generators/javascript/math.js', ['Blockly.JavaScript.math'], ['Blockly.JavaScript'], {'lang': 'es6'});
|
||||
goog.addDependency('../../generators/javascript/procedures.js', ['Blockly.JavaScript.procedures'], ['Blockly.JavaScript'], {'lang': 'es6'});
|
||||
goog.addDependency('../../generators/javascript/text.js', ['Blockly.JavaScript.texts'], ['Blockly.JavaScript', 'Blockly.Names'], {'lang': 'es6', 'module': 'goog'});
|
||||
|
||||
Reference in New Issue
Block a user