From 6a882ca2e89be70c0deafd8efa8085d34b9fb3cd Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Sep 2016 18:19:16 -0700 Subject: [PATCH 01/12] disallow variables on shadow blocks --- core/field_variable.js | 11 +++++++++++ core/xml.js | 3 +++ 2 files changed, 14 insertions(+) diff --git a/core/field_variable.js b/core/field_variable.js index f93caa150..242cee9f0 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -29,6 +29,7 @@ goog.provide('Blockly.FieldVariable'); goog.require('Blockly.FieldDropdown'); goog.require('Blockly.Msg'); goog.require('Blockly.Variables'); +goog.require('goog.asserts'); goog.require('goog.string'); @@ -73,6 +74,16 @@ Blockly.FieldVariable.prototype.init = function() { } }; +/** + * Attach this field to a block. + * @param {!Blockly.Block} block The block containing this field. + */ +Blockly.FieldVariable.prototype.setSourceBlock = function(block) { + goog.asserts.assert(!block.isShadow(), + 'Variable fields are not allowed to exist on shadow blocks.'); + Blockly.FieldVariable.superClass_.setSourceBlock.call(this, block); +}; + /** * Get the variable's name (use a variableDB to convert into a real name). * Unline a regular dropdown, variables are literal and have no neutral value. diff --git a/core/xml.js b/core/xml.js index 2567560cd..8ee0e24af 100644 --- a/core/xml.js +++ b/core/xml.js @@ -535,6 +535,9 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { goog.asserts.assert(child.isShadow(), 'Shadow block not allowed non-shadow child.'); } + // Ensure this block doesn't have any variable inputs. + goog.asserts.assert(block.getVars().length == 0, + 'Shadow blocks cannot have variable fields.'); block.setShadow(true); } return block; From f9385d98d3df192c009bc155eedc747ffbcb2193 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 2 Nov 2016 16:52:37 -0700 Subject: [PATCH 02/12] Add ability to define blocks with a json array --- core/blockly.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/blockly.js b/core/blockly.js index 3d33d8e8c..9fa5966cb 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -399,6 +399,33 @@ Blockly.prompt = function(message, defaultValue, callback) { callback(window.prompt(message, defaultValue)); }; +/** + * Helper function for defining a block from json. The resulting function has + * the correct value of jsonDef at the point in code where jsonInit is called. + * @param {Object} jsonDef The JSON definition of a block. + * @return {function} A function that calls jsonInit with the correct value + * of jsonDef. + */ +Blockly.jsonInitFactory_ = function(jsonDef) { + return function() { + this.jsonInit(jsonDef); + }; +}; + +/** + * Define blocks from an array of JSON block definitions, as might be generated + * by the Blockly Developer Tools. + * @param {!Array} jsonArray An array of JSON block definitions. + */ +Blockly.defineBlocksWithJsonArray = function(jsonArray) { + for (var index = 0; index < jsonArray.length; index++) { + var elem = jsonArray[index]; + Blockly.Blocks[elem.type] = { + init: Blockly.jsonInitFactory_(elem) + }; + } +}; + // IE9 does not have a console. Create a stub to stop errors. if (!goog.global['console']) { goog.global['console'] = { From 9dbe4c2f53738556173fbcef171e7c26edc23041 Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Mon, 7 Nov 2016 15:29:27 -0800 Subject: [PATCH 03/12] Clarify the translation comment for CONTROLS_IFELSE_TITLE, including parameter usage descriptions and more specific example link. --- msg/messages.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/msg/messages.js b/msg/messages.js index c44508f5f..da310e0da 100644 --- a/msg/messages.js +++ b/msg/messages.js @@ -239,7 +239,11 @@ Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE = Blockly.Msg.CONTROLS_IF_MSG_ELSE; /// tooltip - Describes the 'else' subblock during [https://github.com/google/blockly/wiki/IfElse#block-modification if block modification]. Blockly.Msg.CONTROLS_IF_ELSE_TOOLTIP = 'Add a final, catch-all condition to the if block.'; -/// block text - See [https://github.com/google/blockly/wiki/IfElse https://github.com/google/blockly/wiki/IfElse]. The English word "otherwise" would probably be superior to "else", but the latter is used because it is traditional and shorter. +/// block text - Evaluates a boolean condition (%1), and will either execute +/// the statements in %2 if true, otherwise execute the statements in %3. +/// The English word "otherwise" would probably be superior to "else", but the +/// latter is used because it is traditional and shorter. +/// See [https://github.com/google/blockly/wiki/IfElse#if-else-blocks https://github.com/google/blockly/wiki/IfElse#if-else-blocks]. Blockly.Msg.CONTROLS_IFELSE_TITLE = 'if %1 do %2 else %3'; /// url - Information about comparisons. From d91ba9e2f9e081cfb53edeb2e73037257abab423 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 8 Nov 2016 16:54:35 -0800 Subject: [PATCH 04/12] Move injected css to start of head --- core/css.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/css.js b/core/css.js index 32f47a6f0..7c42cff1a 100644 --- a/core/css.js +++ b/core/css.js @@ -84,9 +84,14 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { // Strip off any trailing slash (either Unix or Windows). Blockly.Css.mediaPath_ = pathToMedia.replace(/[\\\/]$/, ''); text = text.replace(/<<>>/g, Blockly.Css.mediaPath_); - // Inject CSS tag. + // Inject CSS tag at start of head. var cssNode = document.createElement('style'); - document.head.appendChild(cssNode); + if (document.head.firstChild) { + document.head.insertBefore(cssNode, document.head.firstChild); + } else { + document.head.appendChild(cssNode); + } + var cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); Blockly.Css.styleSheet_ = cssNode.sheet; From 34a6d5e6e4b91e3990e4281cd3aa1ef7d9be829a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 9 Nov 2016 13:12:18 -0800 Subject: [PATCH 05/12] simplification --- core/css.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/css.js b/core/css.js index 7c42cff1a..bac0d628c 100644 --- a/core/css.js +++ b/core/css.js @@ -86,11 +86,7 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { text = text.replace(/<<>>/g, Blockly.Css.mediaPath_); // Inject CSS tag at start of head. var cssNode = document.createElement('style'); - if (document.head.firstChild) { - document.head.insertBefore(cssNode, document.head.firstChild); - } else { - document.head.appendChild(cssNode); - } + document.head.insertBefore(cssNode, document.head.firstChild); var cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); From 26c10fe585c189df81136a6385ffc63d653f47de Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 9 Nov 2016 13:42:58 -0800 Subject: [PATCH 06/12] lint --- core/blockly.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 9fa5966cb..eb7eb75b0 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -400,11 +400,12 @@ Blockly.prompt = function(message, defaultValue, callback) { }; /** - * Helper function for defining a block from json. The resulting function has + * Helper function for defining a block from JSON. The resulting function has * the correct value of jsonDef at the point in code where jsonInit is called. - * @param {Object} jsonDef The JSON definition of a block. + * @param {!Object} jsonDef The JSON definition of a block. * @return {function} A function that calls jsonInit with the correct value * of jsonDef. + * @private */ Blockly.jsonInitFactory_ = function(jsonDef) { return function() { @@ -415,11 +416,10 @@ Blockly.jsonInitFactory_ = function(jsonDef) { /** * Define blocks from an array of JSON block definitions, as might be generated * by the Blockly Developer Tools. - * @param {!Array} jsonArray An array of JSON block definitions. + * @param {!Array.} jsonArray An array of JSON block definitions. */ Blockly.defineBlocksWithJsonArray = function(jsonArray) { - for (var index = 0; index < jsonArray.length; index++) { - var elem = jsonArray[index]; + for (var i = 0, elem; elem = jsonArray[i]; i++) { Blockly.Blocks[elem.type] = { init: Blockly.jsonInitFactory_(elem) }; From eafd29fa7812350091b7caaedab65fe81602ae45 Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Fri, 11 Nov 2016 15:25:39 -0800 Subject: [PATCH 07/12] Unblock push to master. --- tests/playground.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/playground.html b/tests/playground.html index 8a7435915..6270af20c 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -379,7 +379,7 @@ h1 {