diff --git a/blocks_common/math.js b/blocks_common/math.js index 63a95e9887..542026127f 100644 --- a/blocks_common/math.js +++ b/blocks_common/math.js @@ -22,15 +22,8 @@ * @fileoverview Math blocks for Blockly. * @author q.neutron@gmail.com (Quynh Neutron) */ -'use strict'; - -goog.provide('Blockly.Blocks.math'); - -goog.require('Blockly.Blocks'); - -goog.require('Blockly.Colours'); - -goog.require('Blockly.constants'); +import * as Blockly from 'blockly/core'; +import {Colours} from '../core/colours.js'; Blockly.Blocks['math_number'] = { /** @@ -48,11 +41,11 @@ Blockly.Blocks['math_number'] = { } ], "output": "Number", - "outputShape": Blockly.OUTPUT_SHAPE_ROUND, - "colour": Blockly.Colours.textField, - "colourSecondary": Blockly.Colours.textField, - "colourTertiary": Blockly.Colours.textField, - "colourQuaternary": Blockly.Colours.textField + // "outputShape": Blockly.OUTPUT_SHAPE_ROUND, + "colour": Colours.textField, + "colourSecondary": Colours.textField, + "colourTertiary": Colours.textField, + "colourQuaternary": Colours.textField }); } }; @@ -73,11 +66,11 @@ Blockly.Blocks['math_integer'] = { } ], "output": "Number", - "outputShape": Blockly.OUTPUT_SHAPE_ROUND, - "colour": Blockly.Colours.textField, - "colourSecondary": Blockly.Colours.textField, - "colourTertiary": Blockly.Colours.textField, - "colourQuaternary": Blockly.Colours.textField + // "outputShape": Blockly.OUTPUT_SHAPE_ROUND, + "colour": Colours.textField, + "colourSecondary": Colours.textField, + "colourTertiary": Colours.textField, + "colourQuaternary": Colours.textField }); } }; @@ -99,11 +92,11 @@ Blockly.Blocks['math_whole_number'] = { } ], "output": "Number", - "outputShape": Blockly.OUTPUT_SHAPE_ROUND, - "colour": Blockly.Colours.textField, - "colourSecondary": Blockly.Colours.textField, - "colourTertiary": Blockly.Colours.textField, - "colourQuaternary": Blockly.Colours.textField + // "outputShape": Blockly.OUTPUT_SHAPE_ROUND, + "colour": Colours.textField, + "colourSecondary": Colours.textField, + "colourTertiary": Colours.textField, + "colourQuaternary": Colours.textField }); } }; @@ -124,11 +117,11 @@ Blockly.Blocks['math_positive_number'] = { } ], "output": "Number", - "outputShape": Blockly.OUTPUT_SHAPE_ROUND, - "colour": Blockly.Colours.textField, - "colourSecondary": Blockly.Colours.textField, - "colourTertiary": Blockly.Colours.textField, - "colourQuaternary": Blockly.Colours.textField + // "outputShape": Blockly.OUTPUT_SHAPE_ROUND, + "colour": Colours.textField, + "colourSecondary": Colours.textField, + "colourTertiary": Colours.textField, + "colourQuaternary": Colours.textField }); } }; @@ -149,11 +142,11 @@ Blockly.Blocks['math_angle'] = { } ], "output": "Number", - "outputShape": Blockly.OUTPUT_SHAPE_ROUND, - "colour": Blockly.Colours.textField, - "colourSecondary": Blockly.Colours.textField, - "colourTertiary": Blockly.Colours.textField, - "colourQuaternary": Blockly.Colours.textField + // "outputShape": Blockly.OUTPUT_SHAPE_ROUND, + "colour": Colours.textField, + "colourSecondary": Colours.textField, + "colourTertiary": Colours.textField, + "colourQuaternary": Colours.textField }); } }; diff --git a/blocks_vertical/operators.js b/blocks_vertical/operators.js index 1caa04481c..f47c8743bf 100644 --- a/blocks_vertical/operators.js +++ b/blocks_vertical/operators.js @@ -18,15 +18,8 @@ * limitations under the License. */ -'use strict'; - -goog.provide('Blockly.Blocks.operators'); - -goog.require('Blockly.Blocks'); -goog.require('Blockly.Colours'); -goog.require('Blockly.constants'); -goog.require('Blockly.ScratchBlocks.VerticalExtensions'); - +import * as Blockly from 'blockly'; +import {Categories} from '../src/categories.js'; Blockly.Blocks['operator_add'] = { /** @@ -46,7 +39,7 @@ Blockly.Blocks['operator_add'] = { "name": "NUM2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_number"] }); } @@ -70,7 +63,7 @@ Blockly.Blocks['operator_subtract'] = { "name": "NUM2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_number"] }); } @@ -94,7 +87,7 @@ Blockly.Blocks['operator_multiply'] = { "name": "NUM2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_number"] }); } @@ -118,7 +111,7 @@ Blockly.Blocks['operator_divide'] = { "name": "NUM2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_number"] }); } @@ -142,7 +135,7 @@ Blockly.Blocks['operator_random'] = { "name": "TO" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_number"] }); } @@ -166,7 +159,7 @@ Blockly.Blocks['operator_lt'] = { "name": "OPERAND2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_boolean"] }); } @@ -190,7 +183,7 @@ Blockly.Blocks['operator_equals'] = { "name": "OPERAND2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_boolean"] }); } @@ -214,7 +207,7 @@ Blockly.Blocks['operator_gt'] = { "name": "OPERAND2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_boolean"] }); } @@ -240,7 +233,7 @@ Blockly.Blocks['operator_and'] = { "check": "Boolean" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_boolean"] }); } @@ -266,7 +259,7 @@ Blockly.Blocks['operator_or'] = { "check": "Boolean" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_boolean"] }); } @@ -287,7 +280,7 @@ Blockly.Blocks['operator_not'] = { "check": "Boolean" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_boolean"] }); } @@ -311,7 +304,7 @@ Blockly.Blocks['operator_join'] = { "name": "STRING2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_string"] }); } @@ -335,7 +328,7 @@ Blockly.Blocks['operator_letter_of'] = { "name": "STRING" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_string"] }); } @@ -355,7 +348,7 @@ Blockly.Blocks['operator_length'] = { "name": "STRING" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_string"] }); } @@ -379,7 +372,7 @@ Blockly.Blocks['operator_contains'] = { "name": "STRING2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_boolean"] }); } @@ -403,7 +396,7 @@ Blockly.Blocks['operator_mod'] = { "name": "NUM2" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_number"] }); } @@ -423,7 +416,7 @@ Blockly.Blocks['operator_round'] = { "name": "NUM" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_number"] }); } @@ -463,7 +456,7 @@ Blockly.Blocks['operator_mathop'] = { "name": "NUM" } ], - "category": Blockly.Categories.operators, + "category": Categories.operators, "extensions": ["colours_operators", "output_number"] }); } diff --git a/blocks_vertical/vertical_extensions.js b/blocks_vertical/vertical_extensions.js index 16059da1ec..22cc6162ff 100644 --- a/blocks_vertical/vertical_extensions.js +++ b/blocks_vertical/vertical_extensions.js @@ -25,14 +25,10 @@ * would have the "colours_operators" and "output_number" extensions. * @author fenichel@google.com (Rachel Fenichel) */ -'use strict'; - -goog.provide('Blockly.ScratchBlocks.VerticalExtensions'); - -goog.require('Blockly.Colours'); -goog.require('Blockly.constants'); - +import * as Blockly from 'blockly/core'; +import {Colours} from '../core/colours.js'; +const VerticalExtensions = {}; /** * Helper function that generates an extension based on a category name. * The generated function will set primary, secondary, tertiary, and quaternary @@ -41,8 +37,8 @@ goog.require('Blockly.constants'); * @return {function} An extension function that sets colours based on the given * category. */ -Blockly.ScratchBlocks.VerticalExtensions.colourHelper = function(category) { - var colours = Blockly.Colours[category]; +VerticalExtensions.colourHelper = function(category) { + var colours = Colours[category]; if (!(colours && colours.primary && colours.secondary && colours.tertiary && colours.quaternary)) { throw new Error('Could not find colours for category "' + category + '"'); @@ -53,18 +49,18 @@ Blockly.ScratchBlocks.VerticalExtensions.colourHelper = function(category) { * @this {Blockly.Block} */ return function() { - this.setColourFromRawValues_(colours.primary, colours.secondary, - colours.tertiary, colours.quaternary); + // this.setColourFromRawValues_(colours.primary, colours.secondary, + // colours.tertiary, colours.quaternary); }; }; /** * Extension to set the colours of a text field, which are all the same. */ -Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD = function() { - this.setColourFromRawValues_(Blockly.Colours.textField, - Blockly.Colours.textField, Blockly.Colours.textField, - Blockly.Colours.textField); +VerticalExtensions.COLOUR_TEXTFIELD = function() { + // this.setColourFromRawValues_(Colours.textField, + // Colours.textField, Colours.textField, + // Colours.textField); }; /** @@ -74,7 +70,7 @@ Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD = function() { * @this {Blockly.Block} * @readonly */ -Blockly.ScratchBlocks.VerticalExtensions.SHAPE_STATEMENT = function() { +VerticalExtensions.SHAPE_STATEMENT = function() { this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -87,7 +83,7 @@ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_STATEMENT = function() { * @this {Blockly.Block} * @readonly */ -Blockly.ScratchBlocks.VerticalExtensions.SHAPE_HAT = function() { +VerticalExtensions.SHAPE_HAT = function() { this.setInputsInline(true); this.setNextStatement(true, null); }; @@ -99,7 +95,7 @@ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_HAT = function() { * @this {Blockly.Block} * @readonly */ -Blockly.ScratchBlocks.VerticalExtensions.SHAPE_END = function() { +VerticalExtensions.SHAPE_END = function() { this.setInputsInline(true); this.setPreviousStatement(true, null); }; @@ -111,7 +107,7 @@ Blockly.ScratchBlocks.VerticalExtensions.SHAPE_END = function() { * @this {Blockly.Block} * @readonly */ -Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_NUMBER = function() { +VerticalExtensions.OUTPUT_NUMBER = function() { this.setInputsInline(true); this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND); this.setOutput(true, 'Number'); @@ -124,7 +120,7 @@ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_NUMBER = function() { * @this {Blockly.Block} * @readonly */ -Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_STRING = function() { +VerticalExtensions.OUTPUT_STRING = function() { this.setInputsInline(true); this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND); this.setOutput(true, 'String'); @@ -137,7 +133,7 @@ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_STRING = function() { * @this {Blockly.Block} * @readonly */ -Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_BOOLEAN = function() { +VerticalExtensions.OUTPUT_BOOLEAN = function() { this.setInputsInline(true); this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL); this.setOutput(true, 'Boolean'); @@ -151,7 +147,7 @@ Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_BOOLEAN = function() { * @package * @readonly */ -Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU = { +VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU = { /** * Add the "edit" option and removes the "duplicate" option from the context * menu. @@ -201,7 +197,7 @@ Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU = { * @package * @readonly */ -Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU = { +VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU = { /** * Add the "edit" option to the context menu. * @todo Add "go to definition" option once implemented. @@ -214,14 +210,14 @@ Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU = { }; -Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION = function() { +VerticalExtensions.SCRATCH_EXTENSION = function() { this.isScratchExtension = true; }; /** * Register all extensions for scratch-blocks. * @package */ -Blockly.ScratchBlocks.VerticalExtensions.registerAll = function() { +VerticalExtensions.registerAll = function() { var categoryNames = ['control', 'data', 'data_lists', 'sounds', 'motion', 'looks', 'event', 'sensing', 'pen', 'operators', 'more']; @@ -229,38 +225,38 @@ Blockly.ScratchBlocks.VerticalExtensions.registerAll = function() { for (var i = 0; i < categoryNames.length; i++) { var name = categoryNames[i]; Blockly.Extensions.register('colours_' + name, - Blockly.ScratchBlocks.VerticalExtensions.colourHelper(name)); + VerticalExtensions.colourHelper(name)); } // Text fields transcend categories. Blockly.Extensions.register('colours_textfield', - Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD); + VerticalExtensions.COLOUR_TEXTFIELD); // Register extensions for common block shapes. Blockly.Extensions.register('shape_statement', - Blockly.ScratchBlocks.VerticalExtensions.SHAPE_STATEMENT); + VerticalExtensions.SHAPE_STATEMENT); Blockly.Extensions.register('shape_hat', - Blockly.ScratchBlocks.VerticalExtensions.SHAPE_HAT); + VerticalExtensions.SHAPE_HAT); Blockly.Extensions.register('shape_end', - Blockly.ScratchBlocks.VerticalExtensions.SHAPE_END); + VerticalExtensions.SHAPE_END); // Output shapes and types are related. Blockly.Extensions.register('output_number', - Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_NUMBER); + VerticalExtensions.OUTPUT_NUMBER); Blockly.Extensions.register('output_string', - Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_STRING); + VerticalExtensions.OUTPUT_STRING); Blockly.Extensions.register('output_boolean', - Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_BOOLEAN); + VerticalExtensions.OUTPUT_BOOLEAN); // Custom procedures have interesting context menus. Blockly.Extensions.registerMixin('procedure_def_contextmenu', - Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU); + VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU); Blockly.Extensions.registerMixin('procedure_call_contextmenu', - Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU); + VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU); // Extension blocks have slightly different block rendering. Blockly.Extensions.register('scratch_extension', - Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION); + VerticalExtensions.SCRATCH_EXTENSION); }; -Blockly.ScratchBlocks.VerticalExtensions.registerAll(); +VerticalExtensions.registerAll(); diff --git a/src/categories.js b/src/categories.js new file mode 100644 index 0000000000..f691dbef7b --- /dev/null +++ b/src/categories.js @@ -0,0 +1,15 @@ +const Categories = { + "motion": "motion", + "looks": "looks", + "sound": "sounds", + "pen": "pen", + "data": "data", + "dataLists": "data-lists", + "event": "events", + "control": "control", + "sensing": "sensing", + "operators": "operators", + "more": "more" +}; + +export {Categories}; diff --git a/src/index.js b/src/index.js index 055ba88537..5b7ea64b59 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +import '../blocks_common/math.js'; +import '../blocks_vertical/vertical_extensions.js'; +import '../blocks_vertical/operators.js'; + export * from 'blockly'; +export * from './categories.js'; export * from '../core/colours.js'; export * from '../msg/scratch_msgs.js';