mirror of
https://github.com/google/blockly.git
synced 2026-01-11 10:57:07 +01:00
refactor: Migrate blocks/variables_dynamic.js to goog.module syntax (#5779)
* refactor: Migrate blocks/variables_dynamic.js to goog.module * refactor: Migrate blocks/variables_dynamic.js named requires * chore: clang-format blocks/variables_dynamic.js
This commit is contained in:
committed by
GitHub
parent
c93e1dfd30
commit
b08187cd0a
@@ -6,60 +6,65 @@
|
||||
|
||||
/**
|
||||
* @fileoverview Variable blocks for Blockly.
|
||||
* @suppress {extraRequire|missingRequire|checkTypes}
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.blocks.variablesDynamic');
|
||||
goog.provide('Blockly.Constants.VariablesDynamic');
|
||||
goog.module('Blockly.blocks.variablesDynamic');
|
||||
|
||||
goog.require('Blockly');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const AbstractEvent = goog.requireType('Blockly.Events.Abstract');
|
||||
const ContextMenu = goog.require('Blockly.ContextMenu');
|
||||
const Extensions = goog.require('Blockly.Extensions');
|
||||
const Variables = goog.require('Blockly.Variables');
|
||||
const xml = goog.require('Blockly.utils.xml');
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
const {Block} = goog.requireType('Blockly.Block');
|
||||
const {Msg} = goog.require('Blockly.Msg');
|
||||
const {defineBlocksWithJsonArray} = goog.require('Blockly.common');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldLabel');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.FieldVariable');
|
||||
|
||||
|
||||
/**
|
||||
* Unused constant for the common HSV hue for all blocks in this category.
|
||||
* @deprecated Use Blockly.Msg['VARIABLES_DYNAMIC_HUE']. (2018 April 5)
|
||||
*/
|
||||
Blockly.Constants.VariablesDynamic.HUE = 310;
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
defineBlocksWithJsonArray([
|
||||
// Block for variable getter.
|
||||
{
|
||||
"type": "variables_get_dynamic",
|
||||
"message0": "%1",
|
||||
"args0": [{
|
||||
"type": "field_variable",
|
||||
"name": "VAR",
|
||||
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
|
||||
'type': 'variables_get_dynamic',
|
||||
'message0': '%1',
|
||||
'args0': [{
|
||||
'type': 'field_variable',
|
||||
'name': 'VAR',
|
||||
'variable': '%{BKY_VARIABLES_DEFAULT_NAME}',
|
||||
}],
|
||||
"output": null,
|
||||
"style": "variable_dynamic_blocks",
|
||||
"helpUrl": "%{BKY_VARIABLES_GET_HELPURL}",
|
||||
"tooltip": "%{BKY_VARIABLES_GET_TOOLTIP}",
|
||||
"extensions": ["contextMenu_variableDynamicSetterGetter"],
|
||||
'output': null,
|
||||
'style': 'variable_dynamic_blocks',
|
||||
'helpUrl': '%{BKY_VARIABLES_GET_HELPURL}',
|
||||
'tooltip': '%{BKY_VARIABLES_GET_TOOLTIP}',
|
||||
'extensions': ['contextMenu_variableDynamicSetterGetter'],
|
||||
},
|
||||
// Block for variable setter.
|
||||
{
|
||||
"type": "variables_set_dynamic",
|
||||
"message0": "%{BKY_VARIABLES_SET}",
|
||||
"args0": [{
|
||||
"type": "field_variable",
|
||||
"name": "VAR",
|
||||
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "VALUE",
|
||||
},
|
||||
'type': 'variables_set_dynamic',
|
||||
'message0': '%{BKY_VARIABLES_SET}',
|
||||
'args0': [
|
||||
{
|
||||
'type': 'field_variable',
|
||||
'name': 'VAR',
|
||||
'variable': '%{BKY_VARIABLES_DEFAULT_NAME}',
|
||||
},
|
||||
{
|
||||
'type': 'input_value',
|
||||
'name': 'VALUE',
|
||||
},
|
||||
],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"style": "variable_dynamic_blocks",
|
||||
"tooltip": "%{BKY_VARIABLES_SET_TOOLTIP}",
|
||||
"helpUrl": "%{BKY_VARIABLES_SET_HELPURL}",
|
||||
"extensions": ["contextMenu_variableDynamicSetterGetter"],
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
'style': 'variable_dynamic_blocks',
|
||||
'tooltip': '%{BKY_VARIABLES_SET_TOOLTIP}',
|
||||
'helpUrl': '%{BKY_VARIABLES_SET_HELPURL}',
|
||||
'extensions': ['contextMenu_variableDynamicSetterGetter'],
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -68,15 +73,14 @@ Blockly.defineBlocksWithJsonArray([
|
||||
* setter/getter.
|
||||
* Used by blocks 'variables_set_dynamic' and 'variables_get_dynamic'.
|
||||
* @mixin
|
||||
* @augments Blockly.Block
|
||||
* @package
|
||||
* @augments Block
|
||||
* @readonly
|
||||
*/
|
||||
Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = {
|
||||
const CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = {
|
||||
/**
|
||||
* Add menu option to create getter/setter block for this setter/getter.
|
||||
* @param {!Array} options List of menu options to add to.
|
||||
* @this {Blockly.Block}
|
||||
* @this {Block}
|
||||
*/
|
||||
customContextMenu: function(options) {
|
||||
// Getter blocks have the option to create a setter block, and vice versa.
|
||||
@@ -88,37 +92,37 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
|
||||
const varType = variableModel.type;
|
||||
if (this.type === 'variables_get_dynamic') {
|
||||
oppositeType = 'variables_set_dynamic';
|
||||
contextMenuMsg = Blockly.Msg['VARIABLES_GET_CREATE_SET'];
|
||||
contextMenuMsg = Msg['VARIABLES_GET_CREATE_SET'];
|
||||
} else {
|
||||
oppositeType = 'variables_get_dynamic';
|
||||
contextMenuMsg = Blockly.Msg['VARIABLES_SET_CREATE_GET'];
|
||||
contextMenuMsg = Msg['VARIABLES_SET_CREATE_GET'];
|
||||
}
|
||||
|
||||
const option = {enabled: this.workspace.remainingCapacity() > 0};
|
||||
const name = this.getField('VAR').getText();
|
||||
option.text = contextMenuMsg.replace('%1', name);
|
||||
const xmlField = Blockly.utils.xml.createElement('field');
|
||||
const xmlField = xml.createElement('field');
|
||||
xmlField.setAttribute('name', 'VAR');
|
||||
xmlField.setAttribute('variabletype', varType);
|
||||
xmlField.appendChild(Blockly.utils.xml.createTextNode(name));
|
||||
const xmlBlock = Blockly.utils.xml.createElement('block');
|
||||
xmlField.appendChild(xml.createTextNode(name));
|
||||
const xmlBlock = xml.createElement('block');
|
||||
xmlBlock.setAttribute('type', oppositeType);
|
||||
xmlBlock.appendChild(xmlField);
|
||||
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
|
||||
option.callback = ContextMenu.callbackFactory(this, xmlBlock);
|
||||
options.push(option);
|
||||
} else {
|
||||
if (this.type === 'variables_get_dynamic' ||
|
||||
this.type === 'variables_get_reporter_dynamic') {
|
||||
this.type === 'variables_get_reporter_dynamic') {
|
||||
const renameOption = {
|
||||
text: Blockly.Msg['RENAME_VARIABLE'],
|
||||
text: Msg['RENAME_VARIABLE'],
|
||||
enabled: true,
|
||||
callback: Blockly.Constants.Variables.RENAME_OPTION_CALLBACK_FACTORY(this),
|
||||
callback: renameOptionCallbackFactory(this),
|
||||
};
|
||||
const name = this.getField('VAR').getText();
|
||||
const deleteOption = {
|
||||
text: Blockly.Msg['DELETE_VARIABLE'].replace('%1', name),
|
||||
text: Msg['DELETE_VARIABLE'].replace('%1', name),
|
||||
enabled: true,
|
||||
callback: Blockly.Constants.Variables.DELETE_OPTION_CALLBACK_FACTORY(this),
|
||||
callback: deleteOptionCallbackFactory(this),
|
||||
};
|
||||
options.unshift(renameOption);
|
||||
options.unshift(deleteOption);
|
||||
@@ -128,12 +132,12 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
|
||||
/**
|
||||
* Called whenever anything on the workspace changes.
|
||||
* Set the connection type for this block.
|
||||
* @param {!Blockly.Events.Abstract} _e Change event.
|
||||
* @this {Blockly.Block}
|
||||
* @param {AbstractEvent} _e Change event.
|
||||
* @this {Block}
|
||||
*/
|
||||
onchange: function(_e) {
|
||||
const id = this.getFieldValue('VAR');
|
||||
const variableModel = Blockly.Variables.getVariable(this.workspace, id);
|
||||
const variableModel = Variables.getVariable(this.workspace, id);
|
||||
if (this.type === 'variables_get_dynamic') {
|
||||
this.outputConnection.setCheck(variableModel.type);
|
||||
} else {
|
||||
@@ -143,26 +147,26 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for rename variable dropdown menu option associated with a
|
||||
* variable getter block.
|
||||
* @param {!Blockly.Block} block The block with the variable to rename.
|
||||
* @return {!function()} A function that renames the variable.
|
||||
*/
|
||||
Blockly.Constants.VariablesDynamic.RENAME_OPTION_CALLBACK_FACTORY = function(block) {
|
||||
* Factory for callbacks for rename variable dropdown menu option
|
||||
* associated with a variable getter block.
|
||||
* @param {!Block} block The block with the variable to rename.
|
||||
* @return {!function()} A function that renames the variable.
|
||||
*/
|
||||
const renameOptionCallbackFactory = function(block) {
|
||||
return function() {
|
||||
const workspace = block.workspace;
|
||||
const variable = block.getField('VAR').getVariable();
|
||||
Blockly.Variables.renameVariable(workspace, variable);
|
||||
Variables.renameVariable(workspace, variable);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for delete variable dropdown menu option associated with a
|
||||
* variable getter block.
|
||||
* @param {!Blockly.Block} block The block with the variable to delete.
|
||||
* Factory for callbacks for delete variable dropdown menu option
|
||||
* associated with a variable getter block.
|
||||
* @param {!Block} block The block with the variable to delete.
|
||||
* @return {!function()} A function that deletes the variable.
|
||||
*/
|
||||
Blockly.Constants.VariablesDynamic.DELETE_OPTION_CALLBACK_FACTORY = function(block) {
|
||||
const deleteOptionCallbackFactory = function(block) {
|
||||
return function() {
|
||||
const workspace = block.workspace;
|
||||
const variable = block.getField('VAR').getVariable();
|
||||
@@ -171,5 +175,6 @@ Blockly.Constants.VariablesDynamic.DELETE_OPTION_CALLBACK_FACTORY = function(blo
|
||||
};
|
||||
};
|
||||
|
||||
Blockly.Extensions.registerMixin('contextMenu_variableDynamicSetterGetter',
|
||||
Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN);
|
||||
Extensions.registerMixin(
|
||||
'contextMenu_variableDynamicSetterGetter',
|
||||
CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN);
|
||||
|
||||
@@ -9,65 +9,64 @@
|
||||
"all5:11:requires"
|
||||
],
|
||||
"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/minimalist.js",
|
||||
"./core/serialization/variables.js",
|
||||
"./core/serialization/workspaces.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/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_colour.js",
|
||||
"./core/field_label_serializable.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/flyout_vertical.js",
|
||||
"./core/toolbox/toolbox.js",
|
||||
"./core/interfaces/i_styleable.js",
|
||||
"./core/flyout_horizontal.js",
|
||||
"./core/generator.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_dropdown.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/serialization/workspaces.js",
|
||||
"./core/serialization/variables.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/events/workspace_events.js",
|
||||
"./core/events/events_toolbox_item_select.js",
|
||||
"./core/events/events_ui.js",
|
||||
"./core/events/events.js",
|
||||
"./core/contextmenu_items.js",
|
||||
"./core/widgetdiv.js",
|
||||
"./core/clipboard.js",
|
||||
"./core/menuitem.js",
|
||||
@@ -265,6 +264,7 @@
|
||||
"./core/xml.js",
|
||||
"./core/connection.js",
|
||||
"./core/common.js",
|
||||
"./core/blockly.js",
|
||||
"./closure/goog/base_minimal.js",
|
||||
"./core/requires.js",
|
||||
"./blocks/variables_dynamic.js",
|
||||
|
||||
@@ -7,7 +7,7 @@ goog.addDependency('../../blocks/math.js', ['Blockly.blocks.math'], ['Blockly.Ex
|
||||
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.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.blocks.variables'], ['Blockly.ContextMenu', 'Blockly.Extensions', 'Blockly.FieldLabel', 'Blockly.FieldVariable', 'Blockly.Msg', 'Blockly.Variables', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic', 'Blockly.blocks.variablesDynamic'], ['Blockly', 'Blockly.FieldLabel', 'Blockly.FieldVariable'], {'lang': 'es6'});
|
||||
goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.blocks.variablesDynamic'], ['Blockly.ContextMenu', 'Blockly.Extensions', 'Blockly.FieldLabel', 'Blockly.FieldVariable', 'Blockly.Msg', 'Blockly.Variables', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
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'});
|
||||
goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.svgMath'], {'lang': 'es6', 'module': 'goog'});
|
||||
|
||||
Reference in New Issue
Block a user