Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:google/blockly into refactor-too…
Browse files Browse the repository at this point in the history
…ltip
  • Loading branch information
maribethb committed Feb 18, 2022
2 parents 6334e2c + f1148f1 commit fd6e74a
Show file tree
Hide file tree
Showing 149 changed files with 18,763 additions and 17,740 deletions.
42 changes: 33 additions & 9 deletions blocks/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,37 @@
'use strict';

goog.module('Blockly.blocks.all');
goog.module.declareLegacyNamespace();

goog.require('Blockly.blocks.colour');
goog.require('Blockly.blocks.lists');
goog.require('Blockly.blocks.logic');
goog.require('Blockly.blocks.loops');
goog.require('Blockly.blocks.math');
goog.require('Blockly.blocks.procedures');
goog.require('Blockly.blocks.texts');
goog.require('Blockly.blocks.variables');
goog.require('Blockly.blocks.variablesDynamic');
const colour = goog.require('Blockly.blocks.colour');
const lists = goog.require('Blockly.blocks.lists');
const logic = goog.require('Blockly.blocks.logic');
const loops = goog.require('Blockly.blocks.loops');
const math = goog.require('Blockly.blocks.math');
const procedures = goog.require('Blockly.blocks.procedures');
const texts = goog.require('Blockly.blocks.texts');
const variables = goog.require('Blockly.blocks.variables');
const variablesDynamic = goog.require('Blockly.blocks.variablesDynamic');
/* eslint-disable-next-line no-unused-vars */
const {BlockDefinition} = goog.requireType('Blockly.blocks');


exports.colour = colour;
exports.lists = lists;
exports.logic = logic;
exports.loops = loops;
exports.math = math;
exports.procedures = procedures;
exports.texts = texts;
exports.variables = variables;
exports.variablesDynamic = variablesDynamic;

/**
* A dictionary of the block definitions provided by all the
* Blockly.blocks.* modules.
* @type {!Object<string, !BlockDefinition>}
*/
const blocks = Object.assign(
{}, colour.blocks, lists.blocks, logic.blocks, loops.blocks, math.blocks,
procedures.blocks, variables.blocks, variablesDynamic.blocks);
exports.blocks = blocks;
14 changes: 12 additions & 2 deletions blocks/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@

goog.module('Blockly.blocks.colour');

const {defineBlocksWithJsonArray} = goog.require('Blockly.common');
/* eslint-disable-next-line no-unused-vars */
const {BlockDefinition} = goog.requireType('Blockly.blocks');
const {createBlockDefinitionsFromJsonArray, defineBlocks} = goog.require('Blockly.common');
/** @suppress {extraRequire} */
goog.require('Blockly.FieldColour');


defineBlocksWithJsonArray([
/**
* A dictionary of the block definitions provided by this module.
* @type {!Object<string, !BlockDefinition>}
*/
const blocks = createBlockDefinitionsFromJsonArray([
// Block for colour picker.
{
'type': 'colour_picker',
Expand Down Expand Up @@ -107,3 +113,7 @@ defineBlocksWithJsonArray([
'tooltip': '%{BKY_COLOUR_BLEND_TOOLTIP}',
},
]);
exports.blocks = blocks;

// Register provided blocks.
defineBlocks(blocks);
33 changes: 21 additions & 12 deletions blocks/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@ 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');
/* eslint-disable-next-line no-unused-vars */
const {BlockDefinition} = goog.requireType('Blockly.blocks');
const {ConnectionType} = goog.require('Blockly.ConnectionType');
const {FieldDropdown} = goog.require('Blockly.FieldDropdown');
const {Msg} = goog.require('Blockly.Msg');
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');
const {createBlockDefinitionsFromJsonArray, defineBlocks} = goog.require('Blockly.common');
/** @suppress {extraRequire} */
goog.require('Blockly.FieldDropdown');


defineBlocksWithJsonArray([
/**
* A dictionary of the block definitions provided by this module.
* @type {!Object<string, !BlockDefinition>}
*/
const blocks = createBlockDefinitionsFromJsonArray([
// Block for creating an empty list
// The 'list_create_with' block is preferred as it is more flexible.
// <block type="lists_create_with">
Expand Down Expand Up @@ -112,8 +117,9 @@ defineBlocksWithJsonArray([
'helpUrl': '%{BKY_LISTS_LENGTH_HELPURL}',
},
]);
exports.blocks = blocks;

Blocks['lists_create_with'] = {
blocks['lists_create_with'] = {
/**
* Block for creating a list with any number of elements of any type.
* @this {Block}
Expand Down Expand Up @@ -255,7 +261,7 @@ Blocks['lists_create_with'] = {
},
};

Blocks['lists_create_with_container'] = {
blocks['lists_create_with_container'] = {
/**
* Mutator block for list container.
* @this {Block}
Expand All @@ -270,7 +276,7 @@ Blocks['lists_create_with_container'] = {
},
};

Blocks['lists_create_with_item'] = {
blocks['lists_create_with_item'] = {
/**
* Mutator block for adding items.
* @this {Block}
Expand All @@ -285,7 +291,7 @@ Blocks['lists_create_with_item'] = {
},
};

Blocks['lists_indexOf'] = {
blocks['lists_indexOf'] = {
/**
* Block for finding an item in the list.
* @this {Block}
Expand All @@ -312,7 +318,7 @@ Blocks['lists_indexOf'] = {
},
};

Blocks['lists_getIndex'] = {
blocks['lists_getIndex'] = {
/**
* Block for getting element at index.
* @this {Block}
Expand Down Expand Up @@ -516,7 +522,7 @@ Blocks['lists_getIndex'] = {
},
};

Blocks['lists_setIndex'] = {
blocks['lists_setIndex'] = {
/**
* Block for setting the element at index.
* @this {Block}
Expand Down Expand Up @@ -668,7 +674,7 @@ Blocks['lists_setIndex'] = {
},
};

Blocks['lists_getSublist'] = {
blocks['lists_getSublist'] = {
/**
* Block for getting sublist.
* @this {Block}
Expand Down Expand Up @@ -786,7 +792,7 @@ Blocks['lists_getSublist'] = {
},
};

Blocks['lists_sort'] = {
blocks['lists_sort'] = {
/**
* Block for sorting a list.
* @this {Block}
Expand Down Expand Up @@ -826,7 +832,7 @@ Blocks['lists_sort'] = {
},
};

Blocks['lists_split'] = {
blocks['lists_split'] = {
/**
* Block for splitting text into a list, or joining a list into text.
* @this {Block}
Expand Down Expand Up @@ -913,3 +919,6 @@ Blocks['lists_split'] = {
// dropdown values.
// XML hooks are kept for backwards compatibility.
};

// Register provided blocks.
defineBlocks(blocks);
14 changes: 12 additions & 2 deletions blocks/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ const Extensions = goog.require('Blockly.Extensions');
const xmlUtils = goog.require('Blockly.utils.xml');
/* eslint-disable-next-line no-unused-vars */
const {Block} = goog.requireType('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
const {BlockDefinition} = goog.requireType('Blockly.blocks');
const {Msg} = goog.require('Blockly.Msg');
const {Mutator} = goog.require('Blockly.Mutator');
/* eslint-disable-next-line no-unused-vars */
const {RenderedConnection} = goog.requireType('Blockly.RenderedConnection');
/* eslint-disable-next-line no-unused-vars */
const {Workspace} = goog.requireType('Blockly.Workspace');
const {defineBlocksWithJsonArray} = goog.require('Blockly.common');
const {createBlockDefinitionsFromJsonArray, defineBlocks} = goog.require('Blockly.common');
/** @suppress {extraRequire} */
goog.require('Blockly.FieldDropdown');
/** @suppress {extraRequire} */
goog.require('Blockly.FieldLabel');


defineBlocksWithJsonArray([
/**
* A dictionary of the block definitions provided by this module.
* @type {!Object<string, !BlockDefinition>}
*/
const blocks = createBlockDefinitionsFromJsonArray([
// Block for boolean data type: true and false.
{
'type': 'logic_boolean',
Expand Down Expand Up @@ -258,6 +264,7 @@ defineBlocksWithJsonArray([
'tooltip': '%{BKY_CONTROLS_IF_ELSE_TOOLTIP}',
},
]);
exports.blocks = blocks;

/**
* Tooltip text, keyed by block OP value. Used by logic_compare and
Expand Down Expand Up @@ -645,3 +652,6 @@ const LOGIC_TERNARY_ONCHANGE_MIXIN = {
};

Extensions.registerMixin('logic_ternary', LOGIC_TERNARY_ONCHANGE_MIXIN);

// Register provided blocks.
defineBlocks(blocks);
26 changes: 18 additions & 8 deletions blocks/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ const ContextMenu = goog.require('Blockly.ContextMenu');
const Events = goog.require('Blockly.Events');
const Extensions = goog.require('Blockly.Extensions');
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');
/* eslint-disable-next-line no-unused-vars */
const {BlockDefinition} = goog.requireType('Blockly.blocks');
const {Msg} = goog.require('Blockly.Msg');
const {createBlockDefinitionsFromJsonArray, defineBlocks} = goog.require('Blockly.common');
/** @suppress {extraRequire} */
goog.require('Blockly.FieldDropdown');
/** @suppress {extraRequire} */
Expand All @@ -35,7 +37,11 @@ goog.require('Blockly.FieldVariable');
goog.require('Blockly.Warning');


common.defineBlocksWithJsonArray([
/**
* A dictionary of the block definitions provided by this module.
* @type {!Object<string, !BlockDefinition>}
*/
const blocks = createBlockDefinitionsFromJsonArray([
// Block for repeat n times (external number).
{
'type': 'controls_repeat_ext',
Expand Down Expand Up @@ -205,6 +211,7 @@ common.defineBlocksWithJsonArray([
],
},
]);
exports.blocks = blocks;

/**
* Tooltips for the 'controls_whileUntil' block, keyed by MODE value.
Expand Down Expand Up @@ -287,21 +294,21 @@ Extensions.register(
*
* // If using the Blockly npm package and es6 import syntax:
* import {loopTypes} from 'blockly/blocks';
* loopTypes.push('custom_loop');
* loopTypes.add('custom_loop');
*
* // Else if using Closure Compiler and goog.modules:
* const {loopTypes} = goog.require('Blockly.blocks.loops');
* loopTypes.push('custom_loop');
* loopTypes.add('custom_loop');
*
* @type {!Array<string>}
* @type {!Set<string>}
*/
const loopTypes = [
const loopTypes = new Set([
'controls_repeat',
'controls_repeat_ext',
'controls_forEach',
'controls_for',
'controls_whileUntil',
];
]);
exports.loopTypes = loopTypes;

/**
Expand All @@ -321,7 +328,7 @@ const CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {
getSurroundLoop: function() {
let block = this;
do {
if (loopTypes.includes(block.type)) {
if (loopTypes.has(block.type)) {
return block;
}
block = block.getSurroundParent();
Expand Down Expand Up @@ -358,3 +365,6 @@ const CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = {

Extensions.registerMixin(
'controls_flow_in_loop_check', CONTROL_FLOW_IN_LOOP_CHECK_MIXIN);

// Register provided blocks.
defineBlocks(blocks);
13 changes: 11 additions & 2 deletions blocks/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const xmlUtils = goog.require('Blockly.utils.xml');
/* eslint-disable-next-line no-unused-vars */
const {Block} = goog.requireType('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
const {defineBlocksWithJsonArray} = goog.require('Blockly.common');
const {BlockDefinition} = goog.requireType('Blockly.blocks');
const {createBlockDefinitionsFromJsonArray, defineBlocks} = goog.require('Blockly.common');
/** @suppress {extraRequire} */
goog.require('Blockly.FieldLabel');
/** @suppress {extraRequire} */
Expand All @@ -29,7 +30,11 @@ goog.require('Blockly.FieldNumber');
goog.require('Blockly.FieldVariable');


defineBlocksWithJsonArray([
/**
* A dictionary of the block definitions provided by this module.
* @type {!Object<string, !BlockDefinition>}
*/
const blocks = createBlockDefinitionsFromJsonArray([
// Block for numeric value.
{
'type': 'math_number',
Expand Down Expand Up @@ -384,6 +389,7 @@ defineBlocksWithJsonArray([
'helpUrl': '%{BKY_MATH_ATAN2_HELPURL}',
},
]);
exports.blocks = blocks;

/**
* Mapping of math block OP value to tooltip message for blocks
Expand Down Expand Up @@ -581,3 +587,6 @@ const LIST_MODES_MUTATOR_EXTENSION = function() {
Extensions.registerMutator(
'math_modes_of_list_mutator', LIST_MODES_MUTATOR_MIXIN,
LIST_MODES_MUTATOR_EXTENSION);

// Register provided blocks.
defineBlocks(blocks);
Loading

0 comments on commit fd6e74a

Please sign in to comment.