mirror of
https://github.com/google/blockly.git
synced 2026-06-17 00:25:14 +02:00
Merge pull request #2027 from google/rc/august_2018
August 2018 release
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"rules": {
|
||||
"curly": ["error"],
|
||||
"eol-last": ["error"],
|
||||
"_comment": "Blockly/Google use 2-space indents",
|
||||
"_comment": "Blockly/Google uses +4 space indents for line continuations.",
|
||||
"_comment": "Ignore default rules for ternary expressions.",
|
||||
"indent": [
|
||||
"error", 2,
|
||||
{
|
||||
"SwitchCase": 1,
|
||||
"MemberExpression": 2,
|
||||
"ObjectExpression": 1,
|
||||
"FunctionDeclaration": {
|
||||
"body": 1,
|
||||
"parameters": 2
|
||||
},
|
||||
"FunctionExpression": {
|
||||
"body": 1,
|
||||
"parameters": 2
|
||||
},
|
||||
"CallExpression": {
|
||||
"arguments": 2
|
||||
},
|
||||
"ignoredNodes": ["ConditionalExpression"]
|
||||
}
|
||||
],
|
||||
"keyword-spacing": ["error"],
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"max-len": [
|
||||
"error",
|
||||
{
|
||||
"code": 100,
|
||||
"tabWidth": 4,
|
||||
"ignoreStrings": true,
|
||||
"ignoreRegExpLiterals": true
|
||||
}
|
||||
],
|
||||
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"args": "after-used",
|
||||
"_comment": "Ignore vars starting with an underscore.",
|
||||
"varsIgnorePattern": "^_",
|
||||
"_comment": "Ignore arguments starting with an underscore.",
|
||||
"argsIgnorePattern": "^_"
|
||||
}
|
||||
],
|
||||
"no-use-before-define": ["error"],
|
||||
"_comment":"Blockly uses for exporting symbols. no-self-assign added in eslint 5.",
|
||||
"no-self-assign": ["off"],
|
||||
"_comment": "Blockly uses single quotes except for JSON blobs, which must use double quotes.",
|
||||
"quotes": ["off"],
|
||||
"semi": ["error", "always"],
|
||||
"_comment": "Blockly doesn't have space before function paren",
|
||||
"space-before-function-paren": ["error", "never"],
|
||||
"space-infix-ops": ["error"],
|
||||
"_comment": "Blockly uses 'use strict' in files",
|
||||
"strict": ["off"],
|
||||
"_comment": "Blockly often uses cond-assignment in loops",
|
||||
"no-cond-assign": ["off"],
|
||||
"_comment": "Closure style allows redeclarations",
|
||||
"no-redeclare": ["off"],
|
||||
"valid-jsdoc": ["error", {"requireReturn": false}],
|
||||
"no-console": ["off"]
|
||||
},
|
||||
"env": {
|
||||
"browser": true
|
||||
},
|
||||
"globals": {
|
||||
"Blockly": true,
|
||||
"goog": true
|
||||
},
|
||||
"extends": "eslint:recommended"
|
||||
}
|
||||
+303
-350
File diff suppressed because it is too large
Load Diff
+172
-177
File diff suppressed because one or more lines are too long
+307
-354
File diff suppressed because it is too large
Load Diff
+172
-177
File diff suppressed because one or more lines are too long
+1
-1
@@ -819,7 +819,7 @@ Blockly.Blocks['lists_split'] = {
|
||||
} else if (mode == 'JOIN') {
|
||||
return Blockly.Msg['LISTS_SPLIT_TOOLTIP_JOIN'];
|
||||
}
|
||||
throw 'Unknown mode: ' + mode;
|
||||
throw Error('Unknown mode: ' + mode);
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
||||
+2
-2
@@ -381,7 +381,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
|
||||
elseStatementConnection = clauseBlock.statementConnection_;
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown block type.';
|
||||
throw TypeError('Unknown block type: ' + clauseBlock.type);
|
||||
}
|
||||
clauseBlock = clauseBlock.nextConnection &&
|
||||
clauseBlock.nextConnection.targetBlock();
|
||||
@@ -419,7 +419,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
|
||||
inputDo && inputDo.connection.targetConnection;
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown block type.';
|
||||
throw TypeError('Unknown block type: ' + clauseBlock.type);
|
||||
}
|
||||
clauseBlock = clauseBlock.nextConnection &&
|
||||
clauseBlock.nextConnection.targetBlock();
|
||||
|
||||
+2
-1
@@ -268,8 +268,9 @@ Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = {
|
||||
option.text =
|
||||
Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', varName);
|
||||
var xmlField = Blockly.Variables.generateVariableFieldDom(variable);
|
||||
var xmlBlock = goog.dom.createDom('block', null, xmlField);
|
||||
var xmlBlock = document.createElement('block');
|
||||
xmlBlock.setAttribute('type', 'variables_get');
|
||||
xmlBlock.appendChild(xmlField);
|
||||
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
|
||||
options.push(option);
|
||||
}
|
||||
|
||||
+48
-18
@@ -131,7 +131,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
var parameter = document.createElement('arg');
|
||||
var argModel = this.argumentVarModels_[i];
|
||||
parameter.setAttribute('name', argModel.name);
|
||||
parameter.setAttribute('varId', argModel.getId());
|
||||
parameter.setAttribute('varid', argModel.getId());
|
||||
if (opt_paramIds && this.paramIds_) {
|
||||
parameter.setAttribute('paramId', this.paramIds_[i]);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
for (var i = 0, childNode; childNode = xmlElement.childNodes[i]; i++) {
|
||||
if (childNode.nodeName.toLowerCase() == 'arg') {
|
||||
var varName = childNode.getAttribute('name');
|
||||
var varId = childNode.getAttribute('varId');
|
||||
var varId = childNode.getAttribute('varid') || childNode.getAttribute('varId');
|
||||
this.arguments_.push(varName);
|
||||
var variable = Blockly.Variables.getOrCreateVariablePackage(
|
||||
this.workspace, varId, varName, '');
|
||||
@@ -282,6 +282,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
* @param {string} newId ID of new variable. May be the same as oldId, but
|
||||
* with an updated name. Guaranteed to be the same type as the old
|
||||
* variable.
|
||||
* @override
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
renameVarById: function(oldId, newId) {
|
||||
@@ -310,6 +311,8 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
* variable is in use on this block, rerender to show the new name.
|
||||
* @param {!Blockly.VariableModel} variable The variable being renamed.
|
||||
* @package
|
||||
* @override
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
updateVarName: function(variable) {
|
||||
var newName = variable.name;
|
||||
@@ -357,15 +360,16 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
var option = {enabled: true};
|
||||
var name = this.getFieldValue('NAME');
|
||||
option.text = Blockly.Msg['PROCEDURES_CREATE_DO'].replace('%1', name);
|
||||
var xmlMutation = goog.dom.createDom('mutation');
|
||||
var xmlMutation = document.createElement('mutation');
|
||||
xmlMutation.setAttribute('name', name);
|
||||
for (var i = 0; i < this.arguments_.length; i++) {
|
||||
var xmlArg = goog.dom.createDom('arg');
|
||||
var xmlArg = document.createElement('arg');
|
||||
xmlArg.setAttribute('name', this.arguments_[i]);
|
||||
xmlMutation.appendChild(xmlArg);
|
||||
}
|
||||
var xmlBlock = goog.dom.createDom('block', null, xmlMutation);
|
||||
var xmlBlock = document.createElement('block');
|
||||
xmlBlock.setAttribute('type', this.callType_);
|
||||
xmlBlock.appendChild(xmlMutation);
|
||||
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
|
||||
options.push(option);
|
||||
|
||||
@@ -378,8 +382,9 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
option.text = Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', name);
|
||||
|
||||
var xmlField = Blockly.Variables.generateVariableFieldDom(argVar);
|
||||
var xmlBlock = goog.dom.createDom('block', null, xmlField);
|
||||
var xmlBlock = document.createElement('block');
|
||||
xmlBlock.setAttribute('type', 'variables_get');
|
||||
xmlBlock.appendChild(xmlField);
|
||||
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
|
||||
options.push(option);
|
||||
}
|
||||
@@ -564,7 +569,9 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
this.argumentVarModels_ = [];
|
||||
this.quarkConnections_ = {};
|
||||
this.quarkIds_ = null;
|
||||
this.previousDisabledState_ = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the name of the procedure this block calls.
|
||||
* @return {string} Procedure name.
|
||||
@@ -621,25 +628,21 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
// Reset the quarks (a mutator is about to open).
|
||||
return;
|
||||
}
|
||||
if (goog.array.equals(this.arguments_, paramNames)) {
|
||||
// Test arguments (arrays of strings) for changes. '\n' is not a valid
|
||||
// argument name character, so it is a valid delimiter here.
|
||||
if (paramNames.join('\n') == this.arguments_.join('\n')) {
|
||||
// No change.
|
||||
this.quarkIds_ = paramIds;
|
||||
return;
|
||||
}
|
||||
if (paramIds.length != paramNames.length) {
|
||||
throw 'Error: paramNames and paramIds must be the same length.';
|
||||
throw RangeError('paramNames and paramIds must be the same length.');
|
||||
}
|
||||
this.setCollapsed(false);
|
||||
if (!this.quarkIds_) {
|
||||
// Initialize tracking for this block.
|
||||
this.quarkConnections_ = {};
|
||||
if (paramNames.join('\n') == this.arguments_.join('\n')) {
|
||||
// No change to the parameters, allow quarkConnections_ to be
|
||||
// populated with the existing connections.
|
||||
this.quarkIds_ = paramIds;
|
||||
} else {
|
||||
this.quarkIds_ = [];
|
||||
}
|
||||
this.quarkIds_ = [];
|
||||
}
|
||||
// Switch off rendering while the block is rebuilt.
|
||||
var savedRendered = this.rendered;
|
||||
@@ -788,6 +791,10 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
// Block is deleted or is in a flyout.
|
||||
return;
|
||||
}
|
||||
if (!event.recordUndo) {
|
||||
// Events not generated by user. Skip handling.
|
||||
return;
|
||||
}
|
||||
if (event.type == Blockly.Events.BLOCK_CREATE &&
|
||||
event.ids.indexOf(this.id) != -1) {
|
||||
// Look for the case where a procedure call was created (usually through
|
||||
@@ -813,8 +820,8 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
* </block>
|
||||
* </xml>
|
||||
*/
|
||||
var xml = goog.dom.createDom('xml');
|
||||
var block = goog.dom.createDom('block');
|
||||
var xml = document.createElement('xml');
|
||||
var block = document.createElement('block');
|
||||
block.setAttribute('type', this.defType_);
|
||||
var xy = this.getRelativeToSurfaceXY();
|
||||
var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1);
|
||||
@@ -823,7 +830,7 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
block.setAttribute('y', y);
|
||||
var mutation = this.mutationToDom();
|
||||
block.appendChild(mutation);
|
||||
var field = goog.dom.createDom('field');
|
||||
var field = document.createElement('field');
|
||||
field.setAttribute('name', 'NAME');
|
||||
field.appendChild(document.createTextNode(this.getProcedureCall()));
|
||||
block.appendChild(field);
|
||||
@@ -842,6 +849,27 @@ Blockly.Blocks['procedures_callnoreturn'] = {
|
||||
this.dispose(true, false);
|
||||
Blockly.Events.setGroup(false);
|
||||
}
|
||||
} else if (event.type == Blockly.Events.CHANGE && event.element == 'disabled') {
|
||||
var name = this.getProcedureCall();
|
||||
var def = Blockly.Procedures.getDefinition(name, this.workspace);
|
||||
if (def && def.id == event.blockId) {
|
||||
// in most cases the old group should be ''
|
||||
var oldGroup = Blockly.Events.getGroup();
|
||||
if (oldGroup) {
|
||||
// This should only be possible programatically and may indicate a problem
|
||||
// with event grouping. If you see this message please investigate. If the
|
||||
// use ends up being valid we may need to reorder events in the undo stack.
|
||||
console.log('Saw an existing group while responding to a definition change');
|
||||
}
|
||||
Blockly.Events.setGroup(event.group);
|
||||
if (event.newValue) {
|
||||
this.previousDisabledState_ = this.disabled;
|
||||
this.setDisabled(true);
|
||||
} else {
|
||||
this.setDisabled(this.previousDisabledState_);
|
||||
}
|
||||
Blockly.Events.setGroup(oldGroup);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -881,7 +909,9 @@ Blockly.Blocks['procedures_callreturn'] = {
|
||||
this.arguments_ = [];
|
||||
this.quarkConnections_ = {};
|
||||
this.quarkIds_ = null;
|
||||
this.previousDisabledState_ = false;
|
||||
},
|
||||
|
||||
getProcedureCall: Blockly.Blocks['procedures_callnoreturn'].getProcedureCall,
|
||||
renameProcedure: Blockly.Blocks['procedures_callnoreturn'].renameProcedure,
|
||||
setProcedureParameters_:
|
||||
|
||||
+4
-2
@@ -115,10 +115,12 @@ Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = {
|
||||
var option = {enabled: this.workspace.remainingCapacity() > 0};
|
||||
var name = this.getField('VAR').getText();
|
||||
option.text = contextMenuMsg.replace('%1', name);
|
||||
var xmlField = goog.dom.createDom('field', null, name);
|
||||
var xmlField = document.createElement('field');
|
||||
xmlField.setAttribute('name', 'VAR');
|
||||
var xmlBlock = goog.dom.createDom('block', null, xmlField);
|
||||
xmlField.appendChild(document.createTextNode(name));
|
||||
var xmlBlock = document.createElement('block');
|
||||
xmlBlock.setAttribute('type', opposite_type);
|
||||
xmlBlock.appendChild(xmlField);
|
||||
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
|
||||
options.push(option);
|
||||
}
|
||||
|
||||
@@ -113,10 +113,12 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
|
||||
var option = {enabled: this.workspace.remainingCapacity() > 0};
|
||||
var name = this.getField('VAR').getText();
|
||||
option.text = contextMenuMsg.replace('%1', name);
|
||||
var xmlField = goog.dom.createDom('field', null, name);
|
||||
var xmlField = document.createElement('field');
|
||||
xmlField.setAttribute('name', 'VAR');
|
||||
var xmlBlock = goog.dom.createDom('block', null, xmlField);
|
||||
xmlField.appendChild(document.createTextNode(name));
|
||||
var xmlBlock = document.createElement('block');
|
||||
xmlBlock.setAttribute('type', opposite_type);
|
||||
xmlBlock.appendChild(xmlField);
|
||||
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
|
||||
options.push(option);
|
||||
},
|
||||
|
||||
+46
-45
@@ -10,7 +10,7 @@ Blockly.defineBlocksWithJsonArray([{type:"lists_create_empty",message0:"%{BKY_LI
|
||||
message0:"%{BKY_LISTS_REVERSE_MESSAGE0}",args0:[{type:"input_value",name:"LIST",check:"Array"}],output:"Array",inputsInline:!0,colour:"%{BKY_LISTS_HUE}",tooltip:"%{BKY_LISTS_REVERSE_TOOLTIP}",helpUrl:"%{BKY_LISTS_REVERSE_HELPURL}"},{type:"lists_isEmpty",message0:"%{BKY_LISTS_ISEMPTY_TITLE}",args0:[{type:"input_value",name:"VALUE",check:["String","Array"]}],output:"Boolean",colour:"%{BKY_LISTS_HUE}",tooltip:"%{BKY_LISTS_ISEMPTY_TOOLTIP}",helpUrl:"%{BKY_LISTS_ISEMPTY_HELPURL}"},{type:"lists_length",
|
||||
message0:"%{BKY_LISTS_LENGTH_TITLE}",args0:[{type:"input_value",name:"VALUE",check:["String","Array"]}],output:"Number",colour:"%{BKY_LISTS_HUE}",tooltip:"%{BKY_LISTS_LENGTH_TOOLTIP}",helpUrl:"%{BKY_LISTS_LENGTH_HELPURL}"}]);
|
||||
Blockly.Blocks.lists_create_with={init:function(){this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL);this.setColour(Blockly.Msg.LISTS_HUE);this.itemCount_=3;this.updateShape_();this.setOutput(!0,"Array");this.setMutator(new Blockly.Mutator(["lists_create_with_item"]));this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP)},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("items",this.itemCount_);return a},domToMutation:function(a){this.itemCount_=parseInt(a.getAttribute("items"),
|
||||
10);this.updateShape_()},decompose:function(a){var b=a.newBlock("lists_create_with_container");b.initSvg();for(var c=b.getInput("STACK").connection,d=0;d<this.itemCount_;d++){var e=a.newBlock("lists_create_with_item");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();for(b=0;b<this.itemCount_;b++){var c=this.getInput("ADD"+b).connection.targetConnection;
|
||||
10);this.updateShape_()},decompose:function(a){var b=a.newBlock("lists_create_with_container");b.initSvg();for(var c=b.getInput("STACK").connection,e=0;e<this.itemCount_;e++){var d=a.newBlock("lists_create_with_item");d.initSvg();c.connect(d.previousConnection);c=d.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();for(b=0;b<this.itemCount_;b++){var c=this.getInput("ADD"+b).connection.targetConnection;
|
||||
c&&-1==a.indexOf(c)&&c.disconnect()}this.itemCount_=a.length;this.updateShape_();for(b=0;b<this.itemCount_;b++)Blockly.Mutator.reconnect(a[b],this,"ADD"+b)},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=0;a;){var c=this.getInput("ADD"+b);a.valueConnection_=c&&c.connection.targetConnection;b++;a=a.nextConnection&&a.nextConnection.targetBlock()}},updateShape_:function(){this.itemCount_&&this.getInput("EMPTY")?this.removeInput("EMPTY"):this.itemCount_||this.getInput("EMPTY")||
|
||||
this.appendDummyInput("EMPTY").appendField(Blockly.Msg.LISTS_CREATE_EMPTY_TITLE);for(var a=0;a<this.itemCount_;a++)if(!this.getInput("ADD"+a)){var b=this.appendValueInput("ADD"+a);0==a&&b.appendField(Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH)}for(;this.getInput("ADD"+a);)this.removeInput("ADD"+a),a++}};
|
||||
Blockly.Blocks.lists_create_with_container={init:function(){this.setColour(Blockly.Msg.LISTS_HUE);this.appendDummyInput().appendField(Blockly.Msg.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD);this.appendStatementInput("STACK");this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_CONTAINER_TOOLTIP);this.contextMenu=!1}};
|
||||
@@ -19,25 +19,25 @@ Blockly.Blocks.lists_indexOf={init:function(){var a=[[Blockly.Msg.LISTS_INDEX_OF
|
||||
b.workspace.options.oneBasedIndex?"0":"-1")})}};
|
||||
Blockly.Blocks.lists_getIndex={init:function(){var a=[[Blockly.Msg.LISTS_GET_INDEX_GET,"GET"],[Blockly.Msg.LISTS_GET_INDEX_GET_REMOVE,"GET_REMOVE"],[Blockly.Msg.LISTS_GET_INDEX_REMOVE,"REMOVE"]];this.WHERE_OPTIONS=[[Blockly.Msg.LISTS_GET_INDEX_FROM_START,"FROM_START"],[Blockly.Msg.LISTS_GET_INDEX_FROM_END,"FROM_END"],[Blockly.Msg.LISTS_GET_INDEX_FIRST,"FIRST"],[Blockly.Msg.LISTS_GET_INDEX_LAST,"LAST"],[Blockly.Msg.LISTS_GET_INDEX_RANDOM,"RANDOM"]];this.setHelpUrl(Blockly.Msg.LISTS_GET_INDEX_HELPURL);this.setColour(Blockly.Msg.LISTS_HUE);
|
||||
a=new Blockly.FieldDropdown(a,function(a){this.sourceBlock_.updateStatement_("REMOVE"==a)});this.appendValueInput("VALUE").setCheck("Array").appendField(Blockly.Msg.LISTS_GET_INDEX_INPUT_IN_LIST);this.appendDummyInput().appendField(a,"MODE").appendField("","SPACE");this.appendDummyInput("AT");Blockly.Msg.LISTS_GET_INDEX_TAIL&&this.appendDummyInput("TAIL").appendField(Blockly.Msg.LISTS_GET_INDEX_TAIL);this.setInputsInline(!0);this.setOutput(!0);this.updateAt_(!0);var b=this;this.setTooltip(function(){var a=
|
||||
b.getFieldValue("MODE"),d=b.getFieldValue("WHERE"),e="";switch(a+" "+d){case "GET FROM_START":case "GET FROM_END":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_FROM;break;case "GET FIRST":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_FIRST;break;case "GET LAST":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_LAST;break;case "GET RANDOM":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_RANDOM;break;case "GET_REMOVE FROM_START":case "GET_REMOVE FROM_END":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FROM;break;case "GET_REMOVE FIRST":e=
|
||||
Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FIRST;break;case "GET_REMOVE LAST":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_LAST;break;case "GET_REMOVE RANDOM":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_RANDOM;break;case "REMOVE FROM_START":case "REMOVE FROM_END":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_FROM;break;case "REMOVE FIRST":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_FIRST;break;case "REMOVE LAST":e=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_LAST;break;case "REMOVE RANDOM":e=
|
||||
Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_RANDOM}if("FROM_START"==d||"FROM_END"==d)e+=" "+("FROM_START"==d?Blockly.Msg.LISTS_INDEX_FROM_START_TOOLTIP:Blockly.Msg.LISTS_INDEX_FROM_END_TOOLTIP).replace("%1",b.workspace.options.oneBasedIndex?"#1":"#0");return e})},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("statement",!this.outputConnection);var b=this.getInput("AT").type==Blockly.INPUT_VALUE;a.setAttribute("at",b);return a},domToMutation:function(a){var b="true"==
|
||||
b.getFieldValue("MODE"),e=b.getFieldValue("WHERE"),d="";switch(a+" "+e){case "GET FROM_START":case "GET FROM_END":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_FROM;break;case "GET FIRST":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_FIRST;break;case "GET LAST":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_LAST;break;case "GET RANDOM":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_RANDOM;break;case "GET_REMOVE FROM_START":case "GET_REMOVE FROM_END":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FROM;break;case "GET_REMOVE FIRST":d=
|
||||
Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FIRST;break;case "GET_REMOVE LAST":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_LAST;break;case "GET_REMOVE RANDOM":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_RANDOM;break;case "REMOVE FROM_START":case "REMOVE FROM_END":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_FROM;break;case "REMOVE FIRST":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_FIRST;break;case "REMOVE LAST":d=Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_LAST;break;case "REMOVE RANDOM":d=
|
||||
Blockly.Msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_RANDOM}if("FROM_START"==e||"FROM_END"==e)d+=" "+("FROM_START"==e?Blockly.Msg.LISTS_INDEX_FROM_START_TOOLTIP:Blockly.Msg.LISTS_INDEX_FROM_END_TOOLTIP).replace("%1",b.workspace.options.oneBasedIndex?"#1":"#0");return d})},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("statement",!this.outputConnection);var b=this.getInput("AT").type==Blockly.INPUT_VALUE;a.setAttribute("at",b);return a},domToMutation:function(a){var b="true"==
|
||||
a.getAttribute("statement");this.updateStatement_(b);a="false"!=a.getAttribute("at");this.updateAt_(a)},updateStatement_:function(a){a!=!this.outputConnection&&(this.unplug(!0,!0),a?(this.setOutput(!1),this.setPreviousStatement(!0),this.setNextStatement(!0)):(this.setPreviousStatement(!1),this.setNextStatement(!1),this.setOutput(!0)))},updateAt_:function(a){this.removeInput("AT");this.removeInput("ORDINAL",!0);a?(this.appendValueInput("AT").setCheck("Number"),Blockly.Msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL").appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX)):
|
||||
this.appendDummyInput("AT");var b=new Blockly.FieldDropdown(this.WHERE_OPTIONS,function(b){var c="FROM_START"==b||"FROM_END"==b;if(c!=a){var e=this.sourceBlock_;e.updateAt_(c);e.setFieldValue(b,"WHERE");return null}});this.getInput("AT").appendField(b,"WHERE");Blockly.Msg.LISTS_GET_INDEX_TAIL&&this.moveInputBefore("TAIL",null)}};
|
||||
this.appendDummyInput("AT");var b=new Blockly.FieldDropdown(this.WHERE_OPTIONS,function(b){var c="FROM_START"==b||"FROM_END"==b;if(c!=a){var d=this.sourceBlock_;d.updateAt_(c);d.setFieldValue(b,"WHERE");return null}});this.getInput("AT").appendField(b,"WHERE");Blockly.Msg.LISTS_GET_INDEX_TAIL&&this.moveInputBefore("TAIL",null)}};
|
||||
Blockly.Blocks.lists_setIndex={init:function(){var a=[[Blockly.Msg.LISTS_SET_INDEX_SET,"SET"],[Blockly.Msg.LISTS_SET_INDEX_INSERT,"INSERT"]];this.WHERE_OPTIONS=[[Blockly.Msg.LISTS_GET_INDEX_FROM_START,"FROM_START"],[Blockly.Msg.LISTS_GET_INDEX_FROM_END,"FROM_END"],[Blockly.Msg.LISTS_GET_INDEX_FIRST,"FIRST"],[Blockly.Msg.LISTS_GET_INDEX_LAST,"LAST"],[Blockly.Msg.LISTS_GET_INDEX_RANDOM,"RANDOM"]];this.setHelpUrl(Blockly.Msg.LISTS_SET_INDEX_HELPURL);this.setColour(Blockly.Msg.LISTS_HUE);this.appendValueInput("LIST").setCheck("Array").appendField(Blockly.Msg.LISTS_SET_INDEX_INPUT_IN_LIST);
|
||||
this.appendDummyInput().appendField(new Blockly.FieldDropdown(a),"MODE").appendField("","SPACE");this.appendDummyInput("AT");this.appendValueInput("TO").appendField(Blockly.Msg.LISTS_SET_INDEX_INPUT_TO);this.setInputsInline(!0);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.LISTS_SET_INDEX_TOOLTIP);this.updateAt_(!0);var b=this;this.setTooltip(function(){var a=b.getFieldValue("MODE"),d=b.getFieldValue("WHERE"),e="";switch(a+" "+d){case "SET FROM_START":case "SET FROM_END":e=
|
||||
Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_FROM;break;case "SET FIRST":e=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_FIRST;break;case "SET LAST":e=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_LAST;break;case "SET RANDOM":e=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_RANDOM;break;case "INSERT FROM_START":case "INSERT FROM_END":e=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_INSERT_FROM;break;case "INSERT FIRST":e=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_INSERT_FIRST;break;case "INSERT LAST":e=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_INSERT_LAST;
|
||||
break;case "INSERT RANDOM":e=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_INSERT_RANDOM}if("FROM_START"==d||"FROM_END"==d)e+=" "+Blockly.Msg.LISTS_INDEX_FROM_START_TOOLTIP.replace("%1",b.workspace.options.oneBasedIndex?"#1":"#0");return e})},mutationToDom:function(){var a=document.createElement("mutation"),b=this.getInput("AT").type==Blockly.INPUT_VALUE;a.setAttribute("at",b);return a},domToMutation:function(a){a="false"!=a.getAttribute("at");this.updateAt_(a)},updateAt_:function(a){this.removeInput("AT");
|
||||
this.removeInput("ORDINAL",!0);a?(this.appendValueInput("AT").setCheck("Number"),Blockly.Msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL").appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX)):this.appendDummyInput("AT");var b=new Blockly.FieldDropdown(this.WHERE_OPTIONS,function(b){var c="FROM_START"==b||"FROM_END"==b;if(c!=a){var e=this.sourceBlock_;e.updateAt_(c);e.setFieldValue(b,"WHERE");return null}});this.moveInputBefore("AT","TO");this.getInput("ORDINAL")&&this.moveInputBefore("ORDINAL",
|
||||
this.appendDummyInput().appendField(new Blockly.FieldDropdown(a),"MODE").appendField("","SPACE");this.appendDummyInput("AT");this.appendValueInput("TO").appendField(Blockly.Msg.LISTS_SET_INDEX_INPUT_TO);this.setInputsInline(!0);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.LISTS_SET_INDEX_TOOLTIP);this.updateAt_(!0);var b=this;this.setTooltip(function(){var a=b.getFieldValue("MODE"),e=b.getFieldValue("WHERE"),d="";switch(a+" "+e){case "SET FROM_START":case "SET FROM_END":d=
|
||||
Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_FROM;break;case "SET FIRST":d=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_FIRST;break;case "SET LAST":d=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_LAST;break;case "SET RANDOM":d=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_SET_RANDOM;break;case "INSERT FROM_START":case "INSERT FROM_END":d=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_INSERT_FROM;break;case "INSERT FIRST":d=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_INSERT_FIRST;break;case "INSERT LAST":d=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_INSERT_LAST;
|
||||
break;case "INSERT RANDOM":d=Blockly.Msg.LISTS_SET_INDEX_TOOLTIP_INSERT_RANDOM}if("FROM_START"==e||"FROM_END"==e)d+=" "+Blockly.Msg.LISTS_INDEX_FROM_START_TOOLTIP.replace("%1",b.workspace.options.oneBasedIndex?"#1":"#0");return d})},mutationToDom:function(){var a=document.createElement("mutation"),b=this.getInput("AT").type==Blockly.INPUT_VALUE;a.setAttribute("at",b);return a},domToMutation:function(a){a="false"!=a.getAttribute("at");this.updateAt_(a)},updateAt_:function(a){this.removeInput("AT");
|
||||
this.removeInput("ORDINAL",!0);a?(this.appendValueInput("AT").setCheck("Number"),Blockly.Msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL").appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX)):this.appendDummyInput("AT");var b=new Blockly.FieldDropdown(this.WHERE_OPTIONS,function(b){var c="FROM_START"==b||"FROM_END"==b;if(c!=a){var d=this.sourceBlock_;d.updateAt_(c);d.setFieldValue(b,"WHERE");return null}});this.moveInputBefore("AT","TO");this.getInput("ORDINAL")&&this.moveInputBefore("ORDINAL",
|
||||
"TO");this.getInput("AT").appendField(b,"WHERE")}};
|
||||
Blockly.Blocks.lists_getSublist={init:function(){this.WHERE_OPTIONS_1=[[Blockly.Msg.LISTS_GET_SUBLIST_START_FROM_START,"FROM_START"],[Blockly.Msg.LISTS_GET_SUBLIST_START_FROM_END,"FROM_END"],[Blockly.Msg.LISTS_GET_SUBLIST_START_FIRST,"FIRST"]];this.WHERE_OPTIONS_2=[[Blockly.Msg.LISTS_GET_SUBLIST_END_FROM_START,"FROM_START"],[Blockly.Msg.LISTS_GET_SUBLIST_END_FROM_END,"FROM_END"],[Blockly.Msg.LISTS_GET_SUBLIST_END_LAST,"LAST"]];this.setHelpUrl(Blockly.Msg.LISTS_GET_SUBLIST_HELPURL);this.setColour(Blockly.Msg.LISTS_HUE);
|
||||
this.appendValueInput("LIST").setCheck("Array").appendField(Blockly.Msg.LISTS_GET_SUBLIST_INPUT_IN_LIST);this.appendDummyInput("AT1");this.appendDummyInput("AT2");Blockly.Msg.LISTS_GET_SUBLIST_TAIL&&this.appendDummyInput("TAIL").appendField(Blockly.Msg.LISTS_GET_SUBLIST_TAIL);this.setInputsInline(!0);this.setOutput(!0,"Array");this.updateAt_(1,!0);this.updateAt_(2,!0);this.setTooltip(Blockly.Msg.LISTS_GET_SUBLIST_TOOLTIP)},mutationToDom:function(){var a=document.createElement("mutation"),b=this.getInput("AT1").type==
|
||||
Blockly.INPUT_VALUE;a.setAttribute("at1",b);b=this.getInput("AT2").type==Blockly.INPUT_VALUE;a.setAttribute("at2",b);return a},domToMutation:function(a){var b="true"==a.getAttribute("at1");a="true"==a.getAttribute("at2");this.updateAt_(1,b);this.updateAt_(2,a)},updateAt_:function(a,b){this.removeInput("AT"+a);this.removeInput("ORDINAL"+a,!0);b?(this.appendValueInput("AT"+a).setCheck("Number"),Blockly.Msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL"+a).appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX)):
|
||||
this.appendDummyInput("AT"+a);var c=new Blockly.FieldDropdown(this["WHERE_OPTIONS_"+a],function(c){var e="FROM_START"==c||"FROM_END"==c;if(e!=b){var d=this.sourceBlock_;d.updateAt_(a,e);d.setFieldValue(c,"WHERE"+a);return null}});this.getInput("AT"+a).appendField(c,"WHERE"+a);1==a&&(this.moveInputBefore("AT1","AT2"),this.getInput("ORDINAL1")&&this.moveInputBefore("ORDINAL1","AT2"));Blockly.Msg.LISTS_GET_SUBLIST_TAIL&&this.moveInputBefore("TAIL",null)}};
|
||||
this.appendDummyInput("AT"+a);var c=new Blockly.FieldDropdown(this["WHERE_OPTIONS_"+a],function(c){var d="FROM_START"==c||"FROM_END"==c;if(d!=b){var e=this.sourceBlock_;e.updateAt_(a,d);e.setFieldValue(c,"WHERE"+a);return null}});this.getInput("AT"+a).appendField(c,"WHERE"+a);1==a&&(this.moveInputBefore("AT1","AT2"),this.getInput("ORDINAL1")&&this.moveInputBefore("ORDINAL1","AT2"));Blockly.Msg.LISTS_GET_SUBLIST_TAIL&&this.moveInputBefore("TAIL",null)}};
|
||||
Blockly.Blocks.lists_sort={init:function(){this.jsonInit({message0:Blockly.Msg.LISTS_SORT_TITLE,args0:[{type:"field_dropdown",name:"TYPE",options:[[Blockly.Msg.LISTS_SORT_TYPE_NUMERIC,"NUMERIC"],[Blockly.Msg.LISTS_SORT_TYPE_TEXT,"TEXT"],[Blockly.Msg.LISTS_SORT_TYPE_IGNORECASE,"IGNORE_CASE"]]},{type:"field_dropdown",name:"DIRECTION",options:[[Blockly.Msg.LISTS_SORT_ORDER_ASCENDING,"1"],[Blockly.Msg.LISTS_SORT_ORDER_DESCENDING,"-1"]]},{type:"input_value",name:"LIST",check:"Array"}],output:"Array",colour:Blockly.Msg.LISTS_HUE,
|
||||
tooltip:Blockly.Msg.LISTS_SORT_TOOLTIP,helpUrl:Blockly.Msg.LISTS_SORT_HELPURL})}};
|
||||
Blockly.Blocks.lists_split={init:function(){var a=this,b=new Blockly.FieldDropdown([[Blockly.Msg.LISTS_SPLIT_LIST_FROM_TEXT,"SPLIT"],[Blockly.Msg.LISTS_SPLIT_TEXT_FROM_LIST,"JOIN"]],function(b){a.updateType_(b)});this.setHelpUrl(Blockly.Msg.LISTS_SPLIT_HELPURL);this.setColour(Blockly.Msg.LISTS_HUE);this.appendValueInput("INPUT").setCheck("String").appendField(b,"MODE");this.appendValueInput("DELIM").setCheck("String").appendField(Blockly.Msg.LISTS_SPLIT_WITH_DELIMITER);this.setInputsInline(!0);this.setOutput(!0,
|
||||
"Array");this.setTooltip(function(){var b=a.getFieldValue("MODE");if("SPLIT"==b)return Blockly.Msg.LISTS_SPLIT_TOOLTIP_SPLIT;if("JOIN"==b)return Blockly.Msg.LISTS_SPLIT_TOOLTIP_JOIN;throw"Unknown mode: "+b;})},updateType_:function(a){"SPLIT"==a?(this.outputConnection.setCheck("Array"),this.getInput("INPUT").setCheck("String")):(this.outputConnection.setCheck("String"),this.getInput("INPUT").setCheck("Array"))},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("mode",
|
||||
"Array");this.setTooltip(function(){var b=a.getFieldValue("MODE");if("SPLIT"==b)return Blockly.Msg.LISTS_SPLIT_TOOLTIP_SPLIT;if("JOIN"==b)return Blockly.Msg.LISTS_SPLIT_TOOLTIP_JOIN;throw Error("Unknown mode: "+b);})},updateType_:function(a){"SPLIT"==a?(this.outputConnection.setCheck("Array"),this.getInput("INPUT").setCheck("String")):(this.outputConnection.setCheck("String"),this.getInput("INPUT").setCheck("Array"))},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("mode",
|
||||
this.getFieldValue("MODE"));return a},domToMutation:function(a){this.updateType_(a.getAttribute("mode"))}};Blockly.Blocks.logic={};Blockly.Constants.Logic={};Blockly.Constants.Logic.HUE=210;
|
||||
Blockly.defineBlocksWithJsonArray([{type:"logic_boolean",message0:"%1",args0:[{type:"field_dropdown",name:"BOOL",options:[["%{BKY_LOGIC_BOOLEAN_TRUE}","TRUE"],["%{BKY_LOGIC_BOOLEAN_FALSE}","FALSE"]]}],output:"Boolean",colour:"%{BKY_LOGIC_HUE}",tooltip:"%{BKY_LOGIC_BOOLEAN_TOOLTIP}",helpUrl:"%{BKY_LOGIC_BOOLEAN_HELPURL}"},{type:"controls_if",message0:"%{BKY_CONTROLS_IF_MSG_IF} %1",args0:[{type:"input_value",name:"IF0",check:"Boolean"}],message1:"%{BKY_CONTROLS_IF_MSG_THEN} %1",args1:[{type:"input_statement",
|
||||
name:"DO0"}],previousStatement:null,nextStatement:null,colour:"%{BKY_LOGIC_HUE}",helpUrl:"%{BKY_CONTROLS_IF_HELPURL}",mutator:"controls_if_mutator",extensions:["controls_if_tooltip"]},{type:"controls_ifelse",message0:"%{BKY_CONTROLS_IF_MSG_IF} %1",args0:[{type:"input_value",name:"IF0",check:"Boolean"}],message1:"%{BKY_CONTROLS_IF_MSG_THEN} %1",args1:[{type:"input_statement",name:"DO0"}],message2:"%{BKY_CONTROLS_IF_MSG_ELSE} %1",args2:[{type:"input_statement",name:"ELSE"}],previousStatement:null,nextStatement:null,
|
||||
@@ -49,15 +49,15 @@ Blockly.defineBlocksWithJsonArray([{type:"controls_if_if",message0:"%{BKY_CONTRO
|
||||
enableContextMenu:!1,colour:"%{BKY_LOGIC_HUE}",tooltip:"%{BKY_CONTROLS_IF_ELSE_TOOLTIP}"}]);Blockly.Constants.Logic.TOOLTIPS_BY_OP={EQ:"%{BKY_LOGIC_COMPARE_TOOLTIP_EQ}",NEQ:"%{BKY_LOGIC_COMPARE_TOOLTIP_NEQ}",LT:"%{BKY_LOGIC_COMPARE_TOOLTIP_LT}",LTE:"%{BKY_LOGIC_COMPARE_TOOLTIP_LTE}",GT:"%{BKY_LOGIC_COMPARE_TOOLTIP_GT}",GTE:"%{BKY_LOGIC_COMPARE_TOOLTIP_GTE}",AND:"%{BKY_LOGIC_OPERATION_TOOLTIP_AND}",OR:"%{BKY_LOGIC_OPERATION_TOOLTIP_OR}"};
|
||||
Blockly.Extensions.register("logic_op_tooltip",Blockly.Extensions.buildTooltipForDropdown("OP",Blockly.Constants.Logic.TOOLTIPS_BY_OP));
|
||||
Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN={elseifCount_:0,elseCount_:0,mutationToDom:function(){if(!this.elseifCount_&&!this.elseCount_)return null;var a=document.createElement("mutation");this.elseifCount_&&a.setAttribute("elseif",this.elseifCount_);this.elseCount_&&a.setAttribute("else",1);return a},domToMutation:function(a){this.elseifCount_=parseInt(a.getAttribute("elseif"),10)||0;this.elseCount_=parseInt(a.getAttribute("else"),10)||0;this.updateShape_()},decompose:function(a){var b=a.newBlock("controls_if_if");
|
||||
b.initSvg();for(var c=b.nextConnection,d=1;d<=this.elseifCount_;d++){var e=a.newBlock("controls_if_elseif");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}this.elseCount_&&(a=a.newBlock("controls_if_else"),a.initSvg(),c.connect(a.previousConnection));return b},compose:function(a){var b=a.nextConnection.targetBlock();this.elseCount_=this.elseifCount_=0;a=[null];for(var c=[null],d=null;b;){switch(b.type){case "controls_if_elseif":this.elseifCount_++;a.push(b.valueConnection_);c.push(b.statementConnection_);
|
||||
break;case "controls_if_else":this.elseCount_++;d=b.statementConnection_;break;default:throw"Unknown block type.";}b=b.nextConnection&&b.nextConnection.targetBlock()}this.updateShape_();for(b=1;b<=this.elseifCount_;b++)Blockly.Mutator.reconnect(a[b],this,"IF"+b),Blockly.Mutator.reconnect(c[b],this,"DO"+b);Blockly.Mutator.reconnect(d,this,"ELSE")},saveConnections:function(a){a=a.nextConnection.targetBlock();for(var b=1;a;){switch(a.type){case "controls_if_elseif":var c=this.getInput("IF"+b),d=this.getInput("DO"+
|
||||
b);a.valueConnection_=c&&c.connection.targetConnection;a.statementConnection_=d&&d.connection.targetConnection;b++;break;case "controls_if_else":d=this.getInput("ELSE");a.statementConnection_=d&&d.connection.targetConnection;break;default:throw"Unknown block type.";}a=a.nextConnection&&a.nextConnection.targetBlock()}},updateShape_:function(){this.getInput("ELSE")&&this.removeInput("ELSE");for(var a=1;this.getInput("IF"+a);)this.removeInput("IF"+a),this.removeInput("DO"+a),a++;for(a=1;a<=this.elseifCount_;a++)this.appendValueInput("IF"+
|
||||
a).setCheck("Boolean").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF),this.appendStatementInput("DO"+a).appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);this.elseCount_&&this.appendStatementInput("ELSE").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSE)}};Blockly.Extensions.registerMutator("controls_if_mutator",Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN,null,["controls_if_elseif","controls_if_else"]);
|
||||
b.initSvg();for(var c=b.nextConnection,e=1;e<=this.elseifCount_;e++){var d=a.newBlock("controls_if_elseif");d.initSvg();c.connect(d.previousConnection);c=d.nextConnection}this.elseCount_&&(a=a.newBlock("controls_if_else"),a.initSvg(),c.connect(a.previousConnection));return b},compose:function(a){var b=a.nextConnection.targetBlock();this.elseCount_=this.elseifCount_=0;a=[null];for(var c=[null],e=null;b;){switch(b.type){case "controls_if_elseif":this.elseifCount_++;a.push(b.valueConnection_);c.push(b.statementConnection_);
|
||||
break;case "controls_if_else":this.elseCount_++;e=b.statementConnection_;break;default:throw TypeError("Unknown block type: "+b.type);}b=b.nextConnection&&b.nextConnection.targetBlock()}this.updateShape_();for(b=1;b<=this.elseifCount_;b++)Blockly.Mutator.reconnect(a[b],this,"IF"+b),Blockly.Mutator.reconnect(c[b],this,"DO"+b);Blockly.Mutator.reconnect(e,this,"ELSE")},saveConnections:function(a){a=a.nextConnection.targetBlock();for(var b=1;a;){switch(a.type){case "controls_if_elseif":var c=this.getInput("IF"+
|
||||
b),e=this.getInput("DO"+b);a.valueConnection_=c&&c.connection.targetConnection;a.statementConnection_=e&&e.connection.targetConnection;b++;break;case "controls_if_else":e=this.getInput("ELSE");a.statementConnection_=e&&e.connection.targetConnection;break;default:throw TypeError("Unknown block type: "+a.type);}a=a.nextConnection&&a.nextConnection.targetBlock()}},updateShape_:function(){this.getInput("ELSE")&&this.removeInput("ELSE");for(var a=1;this.getInput("IF"+a);)this.removeInput("IF"+a),this.removeInput("DO"+
|
||||
a),a++;for(a=1;a<=this.elseifCount_;a++)this.appendValueInput("IF"+a).setCheck("Boolean").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF),this.appendStatementInput("DO"+a).appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);this.elseCount_&&this.appendStatementInput("ELSE").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSE)}};Blockly.Extensions.registerMutator("controls_if_mutator",Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN,null,["controls_if_elseif","controls_if_else"]);
|
||||
Blockly.Constants.Logic.CONTROLS_IF_TOOLTIP_EXTENSION=function(){this.setTooltip(function(){if(this.elseifCount_||this.elseCount_){if(!this.elseifCount_&&this.elseCount_)return Blockly.Msg.CONTROLS_IF_TOOLTIP_2;if(this.elseifCount_&&!this.elseCount_)return Blockly.Msg.CONTROLS_IF_TOOLTIP_3;if(this.elseifCount_&&this.elseCount_)return Blockly.Msg.CONTROLS_IF_TOOLTIP_4}else return Blockly.Msg.CONTROLS_IF_TOOLTIP_1;return""}.bind(this))};Blockly.Extensions.register("controls_if_tooltip",Blockly.Constants.Logic.CONTROLS_IF_TOOLTIP_EXTENSION);
|
||||
Blockly.Constants.Logic.LOGIC_COMPARE_ONCHANGE_MIXIN={onchange:function(a){this.prevBlocks_||(this.prevBlocks_=[null,null]);var b=this.getInputTargetBlock("A"),c=this.getInputTargetBlock("B");b&&c&&!b.outputConnection.checkType_(c.outputConnection)&&(Blockly.Events.setGroup(a.group),a=this.prevBlocks_[0],a!==b&&(b.unplug(),a&&!a.isShadow()&&this.getInput("A").connection.connect(a.outputConnection)),b=this.prevBlocks_[1],b!==c&&(c.unplug(),b&&!b.isShadow()&&this.getInput("B").connection.connect(b.outputConnection)),
|
||||
this.bumpNeighbours_(),Blockly.Events.setGroup(!1));this.prevBlocks_[0]=this.getInputTargetBlock("A");this.prevBlocks_[1]=this.getInputTargetBlock("B")}};Blockly.Constants.Logic.LOGIC_COMPARE_EXTENSION=function(){this.mixin(Blockly.Constants.Logic.LOGIC_COMPARE_ONCHANGE_MIXIN)};Blockly.Extensions.register("logic_compare",Blockly.Constants.Logic.LOGIC_COMPARE_EXTENSION);
|
||||
Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN={prevParentConnection_:null,onchange:function(a){var b=this.getInputTargetBlock("THEN"),c=this.getInputTargetBlock("ELSE"),d=this.outputConnection.targetConnection;if((b||c)&&d)for(var e=0;2>e;e++){var f=1==e?b:c;f&&!f.outputConnection.checkType_(d)&&(Blockly.Events.setGroup(a.group),d===this.prevParentConnection_?(this.unplug(),d.getSourceBlock().bumpNeighbours_()):(f.unplug(),f.bumpNeighbours_()),Blockly.Events.setGroup(!1))}this.prevParentConnection_=
|
||||
d}};Blockly.Extensions.registerMixin("logic_ternary",Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN);Blockly.Blocks.loops={};Blockly.Constants.Loops={};Blockly.Constants.Loops.HUE=120;
|
||||
Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN={prevParentConnection_:null,onchange:function(a){var b=this.getInputTargetBlock("THEN"),c=this.getInputTargetBlock("ELSE"),e=this.outputConnection.targetConnection;if((b||c)&&e)for(var d=0;2>d;d++){var f=1==d?b:c;f&&!f.outputConnection.checkType_(e)&&(Blockly.Events.setGroup(a.group),e===this.prevParentConnection_?(this.unplug(),e.getSourceBlock().bumpNeighbours_()):(f.unplug(),f.bumpNeighbours_()),Blockly.Events.setGroup(!1))}this.prevParentConnection_=
|
||||
e}};Blockly.Extensions.registerMixin("logic_ternary",Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN);Blockly.Blocks.loops={};Blockly.Constants.Loops={};Blockly.Constants.Loops.HUE=120;
|
||||
Blockly.defineBlocksWithJsonArray([{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"}],previousStatement:null,nextStatement:null,colour:"%{BKY_LOOPS_HUE}",tooltip:"%{BKY_CONTROLS_REPEAT_TOOLTIP}",helpUrl:"%{BKY_CONTROLS_REPEAT_HELPURL}"},{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"}],previousStatement:null,nextStatement:null,colour:"%{BKY_LOOPS_HUE}",tooltip:"%{BKY_CONTROLS_REPEAT_TOOLTIP}",helpUrl:"%{BKY_CONTROLS_REPEAT_HELPURL}"},{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:"input_value",name:"BOOL",
|
||||
check:"Boolean"}],message1:"%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",args1:[{type:"input_statement",name:"DO"}],previousStatement:null,nextStatement:null,colour:"%{BKY_LOOPS_HUE}",helpUrl:"%{BKY_CONTROLS_WHILEUNTIL_HELPURL}",extensions:["controls_whileUntil_tooltip"]},{type:"controls_for",message0:"%{BKY_CONTROLS_FOR_TITLE}",args0:[{type:"field_variable",name:"VAR",variable:null},{type:"input_value",name:"FROM",check:"Number",align:"RIGHT"},{type:"input_value",name:"TO",check:"Number",align:"RIGHT"},{type:"input_value",
|
||||
@@ -65,7 +65,7 @@ name:"BY",check:"Number",align:"RIGHT"}],message1:"%{BKY_CONTROLS_REPEAT_INPUT_D
|
||||
args1:[{type:"input_statement",name:"DO"}],previousStatement:null,nextStatement:null,colour:"%{BKY_LOOPS_HUE}",helpUrl:"%{BKY_CONTROLS_FOREACH_HELPURL}",extensions:["contextMenu_newGetVariableBlock","controls_forEach_tooltip"]},{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,colour:"%{BKY_LOOPS_HUE}",
|
||||
helpUrl:"%{BKY_CONTROLS_FLOW_STATEMENTS_HELPURL}",extensions:["controls_flow_tooltip","controls_flow_in_loop_check"]}]);Blockly.Constants.Loops.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));
|
||||
Blockly.Constants.Loops.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));
|
||||
Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN={customContextMenu:function(a){if(!this.isInFlyout){var b=this.getField("VAR").getVariable(),c=b.name;if(!this.isCollapsed()&&null!=c){var d={enabled:!0};d.text=Blockly.Msg.VARIABLES_SET_CREATE_GET.replace("%1",c);b=Blockly.Variables.generateVariableFieldDom(b);b=goog.dom.createDom("block",null,b);b.setAttribute("type","variables_get");d.callback=Blockly.ContextMenu.callbackFactory(this,b);a.push(d)}}}};
|
||||
Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN={customContextMenu:function(a){if(!this.isInFlyout){var b=this.getField("VAR").getVariable(),c=b.name;if(!this.isCollapsed()&&null!=c){var e={enabled:!0};e.text=Blockly.Msg.VARIABLES_SET_CREATE_GET.replace("%1",c);b=Blockly.Variables.generateVariableFieldDom(b);c=document.createElement("block");c.setAttribute("type","variables_get");c.appendChild(b);e.callback=Blockly.ContextMenu.callbackFactory(this,c);a.push(e)}}}};
|
||||
Blockly.Extensions.registerMixin("contextMenu_newGetVariableBlock",Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN);Blockly.Extensions.register("controls_for_tooltip",Blockly.Extensions.buildTooltipWithFieldText("%{BKY_CONTROLS_FOR_TOOLTIP}","VAR"));Blockly.Extensions.register("controls_forEach_tooltip",Blockly.Extensions.buildTooltipWithFieldText("%{BKY_CONTROLS_FOREACH_TOOLTIP}","VAR"));
|
||||
Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN={LOOP_TYPES:["controls_repeat","controls_repeat_ext","controls_forEach","controls_for","controls_whileUntil"],onchange:function(){if(this.workspace.isDragging&&!this.workspace.isDragging()){var a=!1,b=this;do{if(-1!=this.LOOP_TYPES.indexOf(b.type)){a=!0;break}b=b.getSurroundParent()}while(b);a?(this.setWarningText(null),this.isInFlyout||this.setDisabled(!1)):(this.setWarningText(Blockly.Msg.CONTROLS_FLOW_STATEMENTS_WARNING),this.isInFlyout||
|
||||
this.getInheritedDisabled()||this.setDisabled(!0))}}};Blockly.Extensions.registerMixin("controls_flow_in_loop_check",Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN);Blockly.Blocks.math={};Blockly.Constants.Math={};Blockly.Constants.Math.HUE=230;
|
||||
@@ -89,14 +89,14 @@ Blockly.Extensions.registerMutator("math_modes_of_list_mutator",Blockly.Constant
|
||||
Blockly.Blocks.procedures_defnoreturn={init:function(){var a=new Blockly.FieldTextInput("",Blockly.Procedures.rename);a.setSpellcheck(!1);this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_DEFNORETURN_TITLE).appendField(a,"NAME").appendField("","PARAMS");this.setMutator(new Blockly.Mutator(["procedures_mutatorarg"]));(this.workspace.options.comments||this.workspace.options.parentWorkspace&&this.workspace.options.parentWorkspace.options.comments)&&Blockly.Msg.PROCEDURES_DEFNORETURN_COMMENT&&this.setCommentText(Blockly.Msg.PROCEDURES_DEFNORETURN_COMMENT);
|
||||
this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setTooltip(Blockly.Msg.PROCEDURES_DEFNORETURN_TOOLTIP);this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL);this.arguments_=[];this.argumentVarModels_=[];this.setStatements_(!0);this.statementConnection_=null},setStatements_:function(a){this.hasStatements_!==a&&(a?(this.appendStatementInput("STACK").appendField(Blockly.Msg.PROCEDURES_DEFNORETURN_DO),this.getInput("RETURN")&&this.moveInputBefore("STACK","RETURN")):this.removeInput("STACK",!0),
|
||||
this.hasStatements_=a)},updateParams_:function(){for(var a=!1,b={},c=0;c<this.arguments_.length;c++){if(b["arg_"+this.arguments_[c].toLowerCase()]){a=!0;break}b["arg_"+this.arguments_[c].toLowerCase()]=!0}a?this.setWarningText(Blockly.Msg.PROCEDURES_DEF_DUPLICATE_WARNING):this.setWarningText(null);a="";this.arguments_.length&&(a=Blockly.Msg.PROCEDURES_BEFORE_PARAMS+" "+this.arguments_.join(", "));Blockly.Events.disable();try{this.setFieldValue(a,"PARAMS")}finally{Blockly.Events.enable()}},mutationToDom:function(a){var b=
|
||||
document.createElement("mutation");a&&b.setAttribute("name",this.getFieldValue("NAME"));for(var c=0;c<this.argumentVarModels_.length;c++){var d=document.createElement("arg"),e=this.argumentVarModels_[c];d.setAttribute("name",e.name);d.setAttribute("varId",e.getId());a&&this.paramIds_&&d.setAttribute("paramId",this.paramIds_[c]);b.appendChild(d)}this.hasStatements_||b.setAttribute("statements","false");return b},domToMutation:function(a){this.arguments_=[];this.argumentVarModels_=[];for(var b=0,c;c=
|
||||
a.childNodes[b];b++)if("arg"==c.nodeName.toLowerCase()){var d=c.getAttribute("name");c=c.getAttribute("varId");this.arguments_.push(d);d=Blockly.Variables.getOrCreateVariablePackage(this.workspace,c,d,"");this.argumentVarModels_.push(d)}this.updateParams_();Blockly.Procedures.mutateCallers(this);this.setStatements_("false"!==a.getAttribute("statements"))},decompose:function(a){var b=a.newBlock("procedures_mutatorcontainer");b.initSvg();this.getInput("RETURN")?b.setFieldValue(this.hasStatements_?"TRUE":
|
||||
"FALSE","STATEMENTS"):b.getInput("STATEMENT_INPUT").setVisible(!1);for(var c=b.getInput("STACK").connection,d=0;d<this.arguments_.length;d++){var e=a.newBlock("procedures_mutatorarg");e.initSvg();e.setFieldValue(this.arguments_[d],"NAME");e.oldLocation=d;c.connect(e.previousConnection);c=e.nextConnection}Blockly.Procedures.mutateCallers(this);return b},compose:function(a){this.arguments_=[];this.paramIds_=[];this.argumentVarModels_=[];for(var b=a.getInputTargetBlock("STACK");b;){var c=b.getFieldValue("NAME");
|
||||
document.createElement("mutation");a&&b.setAttribute("name",this.getFieldValue("NAME"));for(var c=0;c<this.argumentVarModels_.length;c++){var e=document.createElement("arg"),d=this.argumentVarModels_[c];e.setAttribute("name",d.name);e.setAttribute("varid",d.getId());a&&this.paramIds_&&e.setAttribute("paramId",this.paramIds_[c]);b.appendChild(e)}this.hasStatements_||b.setAttribute("statements","false");return b},domToMutation:function(a){this.arguments_=[];this.argumentVarModels_=[];for(var b=0,c;c=
|
||||
a.childNodes[b];b++)if("arg"==c.nodeName.toLowerCase()){var e=c.getAttribute("name");c=c.getAttribute("varid")||c.getAttribute("varId");this.arguments_.push(e);e=Blockly.Variables.getOrCreateVariablePackage(this.workspace,c,e,"");this.argumentVarModels_.push(e)}this.updateParams_();Blockly.Procedures.mutateCallers(this);this.setStatements_("false"!==a.getAttribute("statements"))},decompose:function(a){var b=a.newBlock("procedures_mutatorcontainer");b.initSvg();this.getInput("RETURN")?b.setFieldValue(this.hasStatements_?
|
||||
"TRUE":"FALSE","STATEMENTS"):b.getInput("STATEMENT_INPUT").setVisible(!1);for(var c=b.getInput("STACK").connection,e=0;e<this.arguments_.length;e++){var d=a.newBlock("procedures_mutatorarg");d.initSvg();d.setFieldValue(this.arguments_[e],"NAME");d.oldLocation=e;c.connect(d.previousConnection);c=d.nextConnection}Blockly.Procedures.mutateCallers(this);return b},compose:function(a){this.arguments_=[];this.paramIds_=[];this.argumentVarModels_=[];for(var b=a.getInputTargetBlock("STACK");b;){var c=b.getFieldValue("NAME");
|
||||
this.arguments_.push(c);c=this.workspace.getVariable(c,"");this.argumentVarModels_.push(c);this.paramIds_.push(b.id);b=b.nextConnection&&b.nextConnection.targetBlock()}this.updateParams_();Blockly.Procedures.mutateCallers(this);a=a.getFieldValue("STATEMENTS");if(null!==a&&(a="TRUE"==a,this.hasStatements_!=a))if(a)this.setStatements_(!0),Blockly.Mutator.reconnect(this.statementConnection_,this,"STACK"),this.statementConnection_=null;else{a=this.getInput("STACK").connection;if(this.statementConnection_=
|
||||
a.targetConnection)a=a.targetBlock(),a.unplug(),a.bumpNeighbours_();this.setStatements_(!1)}},getProcedureDef:function(){return[this.getFieldValue("NAME"),this.arguments_,!1]},getVars:function(){return this.arguments_},getVarModels:function(){return this.argumentVarModels_},renameVarById:function(a,b){var c=this.workspace.getVariableById(a);if(""==c.type){c=c.name;for(var d=this.workspace.getVariableById(b),e=!1,f=0;f<this.argumentVarModels_.length;f++)this.argumentVarModels_[f].getId()==a&&(this.arguments_[f]=
|
||||
d.name,this.argumentVarModels_[f]=d,e=!0);e&&this.displayRenamedVar_(c,d.name)}},updateVarName:function(a){for(var b=a.name,c=!1,d=0;d<this.argumentVarModels_.length;d++)if(this.argumentVarModels_[d].getId()==a.getId()){var e=this.arguments_[d];this.arguments_[d]=b;c=!0}c&&this.displayRenamedVar_(e,b)},displayRenamedVar_:function(a,b){this.updateParams_();if(this.mutator.isVisible())for(var c=this.mutator.workspace_.getAllBlocks(),d=0,e;e=c[d];d++)"procedures_mutatorarg"==e.type&&Blockly.Names.equals(a,
|
||||
e.getFieldValue("NAME"))&&e.setFieldValue(b,"NAME")},customContextMenu:function(a){if(!this.isInFlyout){var b={enabled:!0},c=this.getFieldValue("NAME");b.text=Blockly.Msg.PROCEDURES_CREATE_DO.replace("%1",c);var d=goog.dom.createDom("mutation");d.setAttribute("name",c);for(var e=0;e<this.arguments_.length;e++)c=goog.dom.createDom("arg"),c.setAttribute("name",this.arguments_[e]),d.appendChild(c);c=goog.dom.createDom("block",null,d);c.setAttribute("type",this.callType_);b.callback=Blockly.ContextMenu.callbackFactory(this,
|
||||
c);a.push(b);if(!this.isCollapsed())for(e=0;e<this.argumentVarModels_.length;e++)b={enabled:!0},d=this.argumentVarModels_[e],c=d.name,b.text=Blockly.Msg.VARIABLES_SET_CREATE_GET.replace("%1",c),c=Blockly.Variables.generateVariableFieldDom(d),c=goog.dom.createDom("block",null,c),c.setAttribute("type","variables_get"),b.callback=Blockly.ContextMenu.callbackFactory(this,c),a.push(b)}},callType_:"procedures_callnoreturn"};
|
||||
a.targetConnection)a=a.targetBlock(),a.unplug(),a.bumpNeighbours_();this.setStatements_(!1)}},getProcedureDef:function(){return[this.getFieldValue("NAME"),this.arguments_,!1]},getVars:function(){return this.arguments_},getVarModels:function(){return this.argumentVarModels_},renameVarById:function(a,b){var c=this.workspace.getVariableById(a);if(""==c.type){c=c.name;for(var e=this.workspace.getVariableById(b),d=!1,f=0;f<this.argumentVarModels_.length;f++)this.argumentVarModels_[f].getId()==a&&(this.arguments_[f]=
|
||||
e.name,this.argumentVarModels_[f]=e,d=!0);d&&this.displayRenamedVar_(c,e.name)}},updateVarName:function(a){for(var b=a.name,c=!1,e=0;e<this.argumentVarModels_.length;e++)if(this.argumentVarModels_[e].getId()==a.getId()){var d=this.arguments_[e];this.arguments_[e]=b;c=!0}c&&this.displayRenamedVar_(d,b)},displayRenamedVar_:function(a,b){this.updateParams_();if(this.mutator.isVisible())for(var c=this.mutator.workspace_.getAllBlocks(),e=0,d;d=c[e];e++)"procedures_mutatorarg"==d.type&&Blockly.Names.equals(a,
|
||||
d.getFieldValue("NAME"))&&d.setFieldValue(b,"NAME")},customContextMenu:function(a){if(!this.isInFlyout){var b={enabled:!0},c=this.getFieldValue("NAME");b.text=Blockly.Msg.PROCEDURES_CREATE_DO.replace("%1",c);var e=document.createElement("mutation");e.setAttribute("name",c);for(var d=0;d<this.arguments_.length;d++)c=document.createElement("arg"),c.setAttribute("name",this.arguments_[d]),e.appendChild(c);c=document.createElement("block");c.setAttribute("type",this.callType_);c.appendChild(e);b.callback=
|
||||
Blockly.ContextMenu.callbackFactory(this,c);a.push(b);if(!this.isCollapsed())for(d=0;d<this.argumentVarModels_.length;d++)b={enabled:!0},e=this.argumentVarModels_[d],c=e.name,b.text=Blockly.Msg.VARIABLES_SET_CREATE_GET.replace("%1",c),e=Blockly.Variables.generateVariableFieldDom(e),c=document.createElement("block"),c.setAttribute("type","variables_get"),c.appendChild(e),b.callback=Blockly.ContextMenu.callbackFactory(this,c),a.push(b)}},callType_:"procedures_callnoreturn"};
|
||||
Blockly.Blocks.procedures_defreturn={init:function(){var a=new Blockly.FieldTextInput("",Blockly.Procedures.rename);a.setSpellcheck(!1);this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_DEFRETURN_TITLE).appendField(a,"NAME").appendField("","PARAMS");this.appendValueInput("RETURN").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN);this.setMutator(new Blockly.Mutator(["procedures_mutatorarg"]));(this.workspace.options.comments||this.workspace.options.parentWorkspace&&
|
||||
this.workspace.options.parentWorkspace.options.comments)&&Blockly.Msg.PROCEDURES_DEFRETURN_COMMENT&&this.setCommentText(Blockly.Msg.PROCEDURES_DEFRETURN_COMMENT);this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setTooltip(Blockly.Msg.PROCEDURES_DEFRETURN_TOOLTIP);this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFRETURN_HELPURL);this.arguments_=[];this.argumentVarModels_=[];this.setStatements_(!0);this.statementConnection_=null},setStatements_:Blockly.Blocks.procedures_defnoreturn.setStatements_,updateParams_:Blockly.Blocks.procedures_defnoreturn.updateParams_,
|
||||
mutationToDom:Blockly.Blocks.procedures_defnoreturn.mutationToDom,domToMutation:Blockly.Blocks.procedures_defnoreturn.domToMutation,decompose:Blockly.Blocks.procedures_defnoreturn.decompose,compose:Blockly.Blocks.procedures_defnoreturn.compose,getProcedureDef:function(){return[this.getFieldValue("NAME"),this.arguments_,!0]},getVars:Blockly.Blocks.procedures_defnoreturn.getVars,getVarModels:Blockly.Blocks.procedures_defnoreturn.getVarModels,renameVarById:Blockly.Blocks.procedures_defnoreturn.renameVarById,
|
||||
@@ -104,17 +104,18 @@ updateVarName:Blockly.Blocks.procedures_defnoreturn.updateVarName,displayRenamed
|
||||
Blockly.Blocks.procedures_mutatorcontainer={init:function(){this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TITLE);this.appendStatementInput("STACK");this.appendDummyInput("STATEMENT_INPUT").appendField(Blockly.Msg.PROCEDURES_ALLOW_STATEMENTS).appendField(new Blockly.FieldCheckbox("TRUE"),"STATEMENTS");this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.procedures_mutatorarg={init:function(){var a=new Blockly.FieldTextInput("x",this.validator_);a.oldShowEditorFn_=a.showEditor_;a.showEditor_=function(){this.createdVariables_=[];this.oldShowEditorFn_()};this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_MUTATORARG_TITLE).appendField(a,"NAME");this.setPreviousStatement(!0);this.setNextStatement(!0);this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORARG_TOOLTIP);this.contextMenu=!1;a.onFinishEditing_=
|
||||
this.deleteIntermediateVars_;a.createdVariables_=[];a.onFinishEditing_("x")},validator_:function(a){var b=Blockly.Mutator.findParentWs(this.sourceBlock_.workspace);a=a.replace(/[\s\xa0]+/g," ").replace(/^ | $/g,"");if(!a)return null;var c=b.getVariable(a,"");c&&c.name!=a&&b.renameVarById(c.getId(),a);c||(c=b.createVariable(a,""))&&this.createdVariables_&&this.createdVariables_.push(c);return a},deleteIntermediateVars_:function(a){var b=Blockly.Mutator.findParentWs(this.sourceBlock_.workspace);if(b)for(var c=
|
||||
0;c<this.createdVariables_.length;c++){var d=this.createdVariables_[c];d.name!=a&&b.deleteVariableById(d.getId())}}};
|
||||
Blockly.Blocks.procedures_callnoreturn={init:function(){this.appendDummyInput("TOPROW").appendField(this.id,"NAME");this.setPreviousStatement(!0);this.setNextStatement(!0);this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL);this.arguments_=[];this.argumentVarModels_=[];this.quarkConnections_={};this.quarkIds_=null},getProcedureCall:function(){return this.getFieldValue("NAME")},renameProcedure:function(a,b){Blockly.Names.equals(a,this.getProcedureCall())&&
|
||||
(this.setFieldValue(b,"NAME"),this.setTooltip((this.outputConnection?Blockly.Msg.PROCEDURES_CALLRETURN_TOOLTIP:Blockly.Msg.PROCEDURES_CALLNORETURN_TOOLTIP).replace("%1",b)))},setProcedureParameters_:function(a,b){var c=Blockly.Procedures.getDefinition(this.getProcedureCall(),this.workspace),d=c&&c.mutator&&c.mutator.isVisible();d||(this.quarkConnections_={},this.quarkIds_=null);if(b)if(goog.array.equals(this.arguments_,a))this.quarkIds_=b;else{if(b.length!=a.length)throw"Error: paramNames and paramIds must be the same length.";
|
||||
this.setCollapsed(!1);this.quarkIds_||(this.quarkConnections_={},a.join("\n")==this.arguments_.join("\n")?this.quarkIds_=b:this.quarkIds_=[]);c=this.rendered;this.rendered=!1;for(var e=0;e<this.arguments_.length;e++){var f=this.getInput("ARG"+e);f&&(f=f.connection.targetConnection,this.quarkConnections_[this.quarkIds_[e]]=f,d&&f&&-1==b.indexOf(this.quarkIds_[e])&&(f.disconnect(),f.getSourceBlock().bumpNeighbours_()))}this.arguments_=[].concat(a);this.argumentVarModels_=[];for(e=0;e<this.arguments_.length;e++)d=
|
||||
Blockly.Variables.getOrCreateVariablePackage(this.workspace,null,this.arguments_[e],""),this.argumentVarModels_.push(d);this.updateShape_();if(this.quarkIds_=b)for(e=0;e<this.arguments_.length;e++)d=this.quarkIds_[e],d in this.quarkConnections_&&(f=this.quarkConnections_[d],Blockly.Mutator.reconnect(f,this,"ARG"+e)||delete this.quarkConnections_[d]);(this.rendered=c)&&this.render()}},updateShape_:function(){for(var a=0;a<this.arguments_.length;a++){var b=this.getField("ARGNAME"+a);if(b){Blockly.Events.disable();
|
||||
try{b.setValue(this.arguments_[a])}finally{Blockly.Events.enable()}}else b=new Blockly.FieldLabel(this.arguments_[a]),this.appendValueInput("ARG"+a).setAlign(Blockly.ALIGN_RIGHT).appendField(b,"ARGNAME"+a).init()}for(;this.getInput("ARG"+a);)this.removeInput("ARG"+a),a++;if(a=this.getInput("TOPROW"))this.arguments_.length?this.getField("WITH")||(a.appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS,"WITH"),a.init()):this.getField("WITH")&&a.removeField("WITH")},mutationToDom:function(){var a=document.createElement("mutation");
|
||||
a.setAttribute("name",this.getProcedureCall());for(var b=0;b<this.arguments_.length;b++){var c=document.createElement("arg");c.setAttribute("name",this.arguments_[b]);a.appendChild(c)}return a},domToMutation:function(a){var b=a.getAttribute("name");this.renameProcedure(this.getProcedureCall(),b);b=[];for(var c=[],d=0,e;e=a.childNodes[d];d++)"arg"==e.nodeName.toLowerCase()&&(b.push(e.getAttribute("name")),c.push(e.getAttribute("paramId")));this.setProcedureParameters_(b,c)},getVarModels:function(){return this.argumentVarModels_},
|
||||
onchange:function(a){if(this.workspace&&!this.workspace.isFlyout)if(a.type==Blockly.Events.BLOCK_CREATE&&-1!=a.ids.indexOf(this.id)){var b=this.getProcedureCall();b=Blockly.Procedures.getDefinition(b,this.workspace);!b||b.type==this.defType_&&JSON.stringify(b.arguments_)==JSON.stringify(this.arguments_)||(b=null);if(!b){Blockly.Events.setGroup(a.group);a=goog.dom.createDom("xml");b=goog.dom.createDom("block");b.setAttribute("type",this.defType_);var c=this.getRelativeToSurfaceXY(),d=c.y+2*Blockly.SNAP_RADIUS;
|
||||
b.setAttribute("x",c.x+Blockly.SNAP_RADIUS*(this.RTL?-1:1));b.setAttribute("y",d);c=this.mutationToDom();b.appendChild(c);c=goog.dom.createDom("field");c.setAttribute("name","NAME");c.appendChild(document.createTextNode(this.getProcedureCall()));b.appendChild(c);a.appendChild(b);Blockly.Xml.domToWorkspace(a,this.workspace);Blockly.Events.setGroup(!1)}}else a.type==Blockly.Events.BLOCK_DELETE&&(b=this.getProcedureCall(),b=Blockly.Procedures.getDefinition(b,this.workspace),b||(Blockly.Events.setGroup(a.group),
|
||||
this.dispose(!0,!1),Blockly.Events.setGroup(!1)))},customContextMenu:function(a){var b={enabled:!0};b.text=Blockly.Msg.PROCEDURES_HIGHLIGHT_DEF;var c=this.getProcedureCall(),d=this.workspace;b.callback=function(){var a=Blockly.Procedures.getDefinition(c,d);a&&(d.centerOnBlock(a.id),a.select())};a.push(b)},defType_:"procedures_defnoreturn"};
|
||||
Blockly.Blocks.procedures_callreturn={init:function(){this.appendDummyInput("TOPROW").appendField("","NAME");this.setOutput(!0);this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLRETURN_HELPURL);this.arguments_=[];this.quarkConnections_={};this.quarkIds_=null},getProcedureCall:Blockly.Blocks.procedures_callnoreturn.getProcedureCall,renameProcedure:Blockly.Blocks.procedures_callnoreturn.renameProcedure,setProcedureParameters_:Blockly.Blocks.procedures_callnoreturn.setProcedureParameters_,
|
||||
0;c<this.createdVariables_.length;c++){var e=this.createdVariables_[c];e.name!=a&&b.deleteVariableById(e.getId())}}};
|
||||
Blockly.Blocks.procedures_callnoreturn={init:function(){this.appendDummyInput("TOPROW").appendField(this.id,"NAME");this.setPreviousStatement(!0);this.setNextStatement(!0);this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL);this.arguments_=[];this.argumentVarModels_=[];this.quarkConnections_={};this.quarkIds_=null;this.previousDisabledState_=!1},getProcedureCall:function(){return this.getFieldValue("NAME")},renameProcedure:function(a,b){Blockly.Names.equals(a,
|
||||
this.getProcedureCall())&&(this.setFieldValue(b,"NAME"),this.setTooltip((this.outputConnection?Blockly.Msg.PROCEDURES_CALLRETURN_TOOLTIP:Blockly.Msg.PROCEDURES_CALLNORETURN_TOOLTIP).replace("%1",b)))},setProcedureParameters_:function(a,b){var c=Blockly.Procedures.getDefinition(this.getProcedureCall(),this.workspace),e=c&&c.mutator&&c.mutator.isVisible();e||(this.quarkConnections_={},this.quarkIds_=null);if(b)if(a.join("\n")==this.arguments_.join("\n"))this.quarkIds_=b;else{if(b.length!=a.length)throw RangeError("paramNames and paramIds must be the same length.");
|
||||
this.setCollapsed(!1);this.quarkIds_||(this.quarkConnections_={},this.quarkIds_=[]);c=this.rendered;this.rendered=!1;for(var d=0;d<this.arguments_.length;d++){var f=this.getInput("ARG"+d);f&&(f=f.connection.targetConnection,this.quarkConnections_[this.quarkIds_[d]]=f,e&&f&&-1==b.indexOf(this.quarkIds_[d])&&(f.disconnect(),f.getSourceBlock().bumpNeighbours_()))}this.arguments_=[].concat(a);this.argumentVarModels_=[];for(d=0;d<this.arguments_.length;d++)e=Blockly.Variables.getOrCreateVariablePackage(this.workspace,
|
||||
null,this.arguments_[d],""),this.argumentVarModels_.push(e);this.updateShape_();if(this.quarkIds_=b)for(d=0;d<this.arguments_.length;d++)e=this.quarkIds_[d],e in this.quarkConnections_&&(f=this.quarkConnections_[e],Blockly.Mutator.reconnect(f,this,"ARG"+d)||delete this.quarkConnections_[e]);(this.rendered=c)&&this.render()}},updateShape_:function(){for(var a=0;a<this.arguments_.length;a++){var b=this.getField("ARGNAME"+a);if(b){Blockly.Events.disable();try{b.setValue(this.arguments_[a])}finally{Blockly.Events.enable()}}else b=
|
||||
new Blockly.FieldLabel(this.arguments_[a]),this.appendValueInput("ARG"+a).setAlign(Blockly.ALIGN_RIGHT).appendField(b,"ARGNAME"+a).init()}for(;this.getInput("ARG"+a);)this.removeInput("ARG"+a),a++;if(a=this.getInput("TOPROW"))this.arguments_.length?this.getField("WITH")||(a.appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS,"WITH"),a.init()):this.getField("WITH")&&a.removeField("WITH")},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("name",this.getProcedureCall());
|
||||
for(var b=0;b<this.arguments_.length;b++){var c=document.createElement("arg");c.setAttribute("name",this.arguments_[b]);a.appendChild(c)}return a},domToMutation:function(a){var b=a.getAttribute("name");this.renameProcedure(this.getProcedureCall(),b);b=[];for(var c=[],e=0,d;d=a.childNodes[e];e++)"arg"==d.nodeName.toLowerCase()&&(b.push(d.getAttribute("name")),c.push(d.getAttribute("paramId")));this.setProcedureParameters_(b,c)},getVarModels:function(){return this.argumentVarModels_},onchange:function(a){if(this.workspace&&
|
||||
!this.workspace.isFlyout&&a.recordUndo)if(a.type==Blockly.Events.BLOCK_CREATE&&-1!=a.ids.indexOf(this.id)){var b=this.getProcedureCall();b=Blockly.Procedures.getDefinition(b,this.workspace);!b||b.type==this.defType_&&JSON.stringify(b.arguments_)==JSON.stringify(this.arguments_)||(b=null);if(!b){Blockly.Events.setGroup(a.group);a=document.createElement("xml");b=document.createElement("block");b.setAttribute("type",this.defType_);var c=this.getRelativeToSurfaceXY(),e=c.y+2*Blockly.SNAP_RADIUS;b.setAttribute("x",
|
||||
c.x+Blockly.SNAP_RADIUS*(this.RTL?-1:1));b.setAttribute("y",e);c=this.mutationToDom();b.appendChild(c);c=document.createElement("field");c.setAttribute("name","NAME");c.appendChild(document.createTextNode(this.getProcedureCall()));b.appendChild(c);a.appendChild(b);Blockly.Xml.domToWorkspace(a,this.workspace);Blockly.Events.setGroup(!1)}}else a.type==Blockly.Events.BLOCK_DELETE?(b=this.getProcedureCall(),b=Blockly.Procedures.getDefinition(b,this.workspace),b||(Blockly.Events.setGroup(a.group),this.dispose(!0,
|
||||
!1),Blockly.Events.setGroup(!1))):a.type==Blockly.Events.CHANGE&&"disabled"==a.element&&(b=this.getProcedureCall(),(b=Blockly.Procedures.getDefinition(b,this.workspace))&&b.id==a.blockId&&((b=Blockly.Events.getGroup())&&console.log("Saw an existing group while responding to a definition change"),Blockly.Events.setGroup(a.group),a.newValue?(this.previousDisabledState_=this.disabled,this.setDisabled(!0)):this.setDisabled(this.previousDisabledState_),Blockly.Events.setGroup(b)))},customContextMenu:function(a){var b=
|
||||
{enabled:!0};b.text=Blockly.Msg.PROCEDURES_HIGHLIGHT_DEF;var c=this.getProcedureCall(),e=this.workspace;b.callback=function(){var a=Blockly.Procedures.getDefinition(c,e);a&&(e.centerOnBlock(a.id),a.select())};a.push(b)},defType_:"procedures_defnoreturn"};
|
||||
Blockly.Blocks.procedures_callreturn={init:function(){this.appendDummyInput("TOPROW").appendField("","NAME");this.setOutput(!0);this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLRETURN_HELPURL);this.arguments_=[];this.quarkConnections_={};this.quarkIds_=null;this.previousDisabledState_=!1},getProcedureCall:Blockly.Blocks.procedures_callnoreturn.getProcedureCall,renameProcedure:Blockly.Blocks.procedures_callnoreturn.renameProcedure,setProcedureParameters_:Blockly.Blocks.procedures_callnoreturn.setProcedureParameters_,
|
||||
updateShape_:Blockly.Blocks.procedures_callnoreturn.updateShape_,mutationToDom:Blockly.Blocks.procedures_callnoreturn.mutationToDom,domToMutation:Blockly.Blocks.procedures_callnoreturn.domToMutation,getVarModels:Blockly.Blocks.procedures_callnoreturn.getVarModels,onchange:Blockly.Blocks.procedures_callnoreturn.onchange,customContextMenu:Blockly.Blocks.procedures_callnoreturn.customContextMenu,defType_:"procedures_defreturn"};
|
||||
Blockly.Blocks.procedures_ifreturn={init:function(){this.appendValueInput("CONDITION").setCheck("Boolean").appendField(Blockly.Msg.CONTROLS_IF_MSG_IF);this.appendValueInput("VALUE").appendField(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN);this.setInputsInline(!0);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setColour(Blockly.Msg.PROCEDURES_HUE);this.setTooltip(Blockly.Msg.PROCEDURES_IFRETURN_TOOLTIP);this.setHelpUrl(Blockly.Msg.PROCEDURES_IFRETURN_HELPURL);this.hasReturnValue_=!0},mutationToDom:function(){var a=
|
||||
document.createElement("mutation");a.setAttribute("value",Number(this.hasReturnValue_));return a},domToMutation:function(a){this.hasReturnValue_=1==a.getAttribute("value");this.hasReturnValue_||(this.removeInput("VALUE"),this.appendDummyInput("VALUE").appendField(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN))},onchange:function(){if(this.workspace.isDragging&&!this.workspace.isDragging()){var a=!1,b=this;do{if(-1!=this.FUNCTION_TYPES.indexOf(b.type)){a=!0;break}b=b.getSurroundParent()}while(b);a?("procedures_defnoreturn"==
|
||||
@@ -128,7 +129,7 @@ extensions:["text_indexOf_tooltip"]},{type:"text_charAt",message0:"%{BKY_TEXT_CH
|
||||
Blockly.Blocks.text_getSubstring={init:function(){this.WHERE_OPTIONS_1=[[Blockly.Msg.TEXT_GET_SUBSTRING_START_FROM_START,"FROM_START"],[Blockly.Msg.TEXT_GET_SUBSTRING_START_FROM_END,"FROM_END"],[Blockly.Msg.TEXT_GET_SUBSTRING_START_FIRST,"FIRST"]];this.WHERE_OPTIONS_2=[[Blockly.Msg.TEXT_GET_SUBSTRING_END_FROM_START,"FROM_START"],[Blockly.Msg.TEXT_GET_SUBSTRING_END_FROM_END,"FROM_END"],[Blockly.Msg.TEXT_GET_SUBSTRING_END_LAST,"LAST"]];this.setHelpUrl(Blockly.Msg.TEXT_GET_SUBSTRING_HELPURL);this.setColour(Blockly.Msg.TEXTS_HUE);
|
||||
this.appendValueInput("STRING").setCheck("String").appendField(Blockly.Msg.TEXT_GET_SUBSTRING_INPUT_IN_TEXT);this.appendDummyInput("AT1");this.appendDummyInput("AT2");Blockly.Msg.TEXT_GET_SUBSTRING_TAIL&&this.appendDummyInput("TAIL").appendField(Blockly.Msg.TEXT_GET_SUBSTRING_TAIL);this.setInputsInline(!0);this.setOutput(!0,"String");this.updateAt_(1,!0);this.updateAt_(2,!0);this.setTooltip(Blockly.Msg.TEXT_GET_SUBSTRING_TOOLTIP)},mutationToDom:function(){var a=document.createElement("mutation"),
|
||||
b=this.getInput("AT1").type==Blockly.INPUT_VALUE;a.setAttribute("at1",b);b=this.getInput("AT2").type==Blockly.INPUT_VALUE;a.setAttribute("at2",b);return a},domToMutation:function(a){var b="true"==a.getAttribute("at1");a="true"==a.getAttribute("at2");this.updateAt_(1,b);this.updateAt_(2,a)},updateAt_:function(a,b){this.removeInput("AT"+a);this.removeInput("ORDINAL"+a,!0);b?(this.appendValueInput("AT"+a).setCheck("Number"),Blockly.Msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL"+a).appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX)):
|
||||
this.appendDummyInput("AT"+a);2==a&&Blockly.Msg.TEXT_GET_SUBSTRING_TAIL&&(this.removeInput("TAIL",!0),this.appendDummyInput("TAIL").appendField(Blockly.Msg.TEXT_GET_SUBSTRING_TAIL));var c=new Blockly.FieldDropdown(this["WHERE_OPTIONS_"+a],function(c){var d="FROM_START"==c||"FROM_END"==c;if(d!=b){var f=this.sourceBlock_;f.updateAt_(a,d);f.setFieldValue(c,"WHERE"+a);return null}});this.getInput("AT"+a).appendField(c,"WHERE"+a);1==a&&(this.moveInputBefore("AT1","AT2"),this.getInput("ORDINAL1")&&this.moveInputBefore("ORDINAL1",
|
||||
this.appendDummyInput("AT"+a);2==a&&Blockly.Msg.TEXT_GET_SUBSTRING_TAIL&&(this.removeInput("TAIL",!0),this.appendDummyInput("TAIL").appendField(Blockly.Msg.TEXT_GET_SUBSTRING_TAIL));var c=new Blockly.FieldDropdown(this["WHERE_OPTIONS_"+a],function(c){var d="FROM_START"==c||"FROM_END"==c;if(d!=b){var e=this.sourceBlock_;e.updateAt_(a,d);e.setFieldValue(c,"WHERE"+a);return null}});this.getInput("AT"+a).appendField(c,"WHERE"+a);1==a&&(this.moveInputBefore("AT1","AT2"),this.getInput("ORDINAL1")&&this.moveInputBefore("ORDINAL1",
|
||||
"AT2"))}};Blockly.Blocks.text_changeCase={init:function(){var a=[[Blockly.Msg.TEXT_CHANGECASE_OPERATOR_UPPERCASE,"UPPERCASE"],[Blockly.Msg.TEXT_CHANGECASE_OPERATOR_LOWERCASE,"LOWERCASE"],[Blockly.Msg.TEXT_CHANGECASE_OPERATOR_TITLECASE,"TITLECASE"]];this.setHelpUrl(Blockly.Msg.TEXT_CHANGECASE_HELPURL);this.setColour(Blockly.Msg.TEXTS_HUE);this.appendValueInput("TEXT").setCheck("String").appendField(new Blockly.FieldDropdown(a),"CASE");this.setOutput(!0,"String");this.setTooltip(Blockly.Msg.TEXT_CHANGECASE_TOOLTIP)}};
|
||||
Blockly.Blocks.text_trim={init:function(){var a=[[Blockly.Msg.TEXT_TRIM_OPERATOR_BOTH,"BOTH"],[Blockly.Msg.TEXT_TRIM_OPERATOR_LEFT,"LEFT"],[Blockly.Msg.TEXT_TRIM_OPERATOR_RIGHT,"RIGHT"]];this.setHelpUrl(Blockly.Msg.TEXT_TRIM_HELPURL);this.setColour(Blockly.Msg.TEXTS_HUE);this.appendValueInput("TEXT").setCheck("String").appendField(new Blockly.FieldDropdown(a),"MODE");this.setOutput(!0,"String");this.setTooltip(Blockly.Msg.TEXT_TRIM_TOOLTIP)}};
|
||||
Blockly.Blocks.text_print={init:function(){this.jsonInit({message0:Blockly.Msg.TEXT_PRINT_TITLE,args0:[{type:"input_value",name:"TEXT"}],previousStatement:null,nextStatement:null,colour:Blockly.Msg.TEXTS_HUE,tooltip:Blockly.Msg.TEXT_PRINT_TOOLTIP,helpUrl:Blockly.Msg.TEXT_PRINT_HELPURL})}};
|
||||
@@ -140,24 +141,24 @@ Blockly.Blocks.text_count={init:function(){this.jsonInit({message0:Blockly.Msg.T
|
||||
Blockly.Blocks.text_replace={init:function(){this.jsonInit({message0:Blockly.Msg.TEXT_REPLACE_MESSAGE0,args0:[{type:"input_value",name:"FROM",check:"String"},{type:"input_value",name:"TO",check:"String"},{type:"input_value",name:"TEXT",check:"String"}],output:"String",inputsInline:!0,colour:Blockly.Msg.TEXTS_HUE,tooltip:Blockly.Msg.TEXT_REPLACE_TOOLTIP,helpUrl:Blockly.Msg.TEXT_REPLACE_HELPURL})}};
|
||||
Blockly.Blocks.text_reverse={init:function(){this.jsonInit({message0:Blockly.Msg.TEXT_REVERSE_MESSAGE0,args0:[{type:"input_value",name:"TEXT",check:"String"}],output:"String",inputsInline:!0,colour:Blockly.Msg.TEXTS_HUE,tooltip:Blockly.Msg.TEXT_REVERSE_TOOLTIP,helpUrl:Blockly.Msg.TEXT_REVERSE_HELPURL})}};
|
||||
Blockly.Constants.Text.QUOTE_IMAGE_MIXIN={QUOTE_IMAGE_LEFT_DATAURI:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC",QUOTE_IMAGE_RIGHT_DATAURI:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==",
|
||||
QUOTE_IMAGE_WIDTH:12,QUOTE_IMAGE_HEIGHT:12,quoteField_:function(a){for(var b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)if(a==e.name){c.insertFieldAt(d,this.newQuote_(!0));c.insertFieldAt(d+2,this.newQuote_(!1));return}console.warn('field named "'+a+'" not found in '+this.toDevString())},newQuote_:function(a){a=this.RTL?!a:a;return new Blockly.FieldImage(a?this.QUOTE_IMAGE_LEFT_DATAURI:this.QUOTE_IMAGE_RIGHT_DATAURI,this.QUOTE_IMAGE_WIDTH,this.QUOTE_IMAGE_HEIGHT,a?"\u201c":"\u201d")}};
|
||||
QUOTE_IMAGE_WIDTH:12,QUOTE_IMAGE_HEIGHT:12,quoteField_:function(a){for(var b=0,c;c=this.inputList[b];b++)for(var e=0,d;d=c.fieldRow[e];e++)if(a==d.name){c.insertFieldAt(e,this.newQuote_(!0));c.insertFieldAt(e+2,this.newQuote_(!1));return}console.warn('field named "'+a+'" not found in '+this.toDevString())},newQuote_:function(a){a=this.RTL?!a:a;return new Blockly.FieldImage(a?this.QUOTE_IMAGE_LEFT_DATAURI:this.QUOTE_IMAGE_RIGHT_DATAURI,this.QUOTE_IMAGE_WIDTH,this.QUOTE_IMAGE_HEIGHT,a?"\u201c":"\u201d")}};
|
||||
Blockly.Constants.Text.TEXT_QUOTES_EXTENSION=function(){this.mixin(Blockly.Constants.Text.QUOTE_IMAGE_MIXIN);this.quoteField_("TEXT")};
|
||||
Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN={mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("items",this.itemCount_);return a},domToMutation:function(a){this.itemCount_=parseInt(a.getAttribute("items"),10);this.updateShape_()},decompose:function(a){var b=a.newBlock("text_create_join_container");b.initSvg();for(var c=b.getInput("STACK").connection,d=0;d<this.itemCount_;d++){var e=a.newBlock("text_create_join_item");e.initSvg();c.connect(e.previousConnection);c=
|
||||
e.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();for(b=0;b<this.itemCount_;b++){var c=this.getInput("ADD"+b).connection.targetConnection;c&&-1==a.indexOf(c)&&c.disconnect()}this.itemCount_=a.length;this.updateShape_();for(b=0;b<this.itemCount_;b++)Blockly.Mutator.reconnect(a[b],this,"ADD"+b)},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=0;a;){var c=
|
||||
Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN={mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("items",this.itemCount_);return a},domToMutation:function(a){this.itemCount_=parseInt(a.getAttribute("items"),10);this.updateShape_()},decompose:function(a){var b=a.newBlock("text_create_join_container");b.initSvg();for(var c=b.getInput("STACK").connection,e=0;e<this.itemCount_;e++){var d=a.newBlock("text_create_join_item");d.initSvg();c.connect(d.previousConnection);c=
|
||||
d.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();for(b=0;b<this.itemCount_;b++){var c=this.getInput("ADD"+b).connection.targetConnection;c&&-1==a.indexOf(c)&&c.disconnect()}this.itemCount_=a.length;this.updateShape_();for(b=0;b<this.itemCount_;b++)Blockly.Mutator.reconnect(a[b],this,"ADD"+b)},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=0;a;){var c=
|
||||
this.getInput("ADD"+b);a.valueConnection_=c&&c.connection.targetConnection;b++;a=a.nextConnection&&a.nextConnection.targetBlock()}},updateShape_:function(){this.itemCount_&&this.getInput("EMPTY")?this.removeInput("EMPTY"):this.itemCount_||this.getInput("EMPTY")||this.appendDummyInput("EMPTY").appendField(this.newQuote_(!0)).appendField(this.newQuote_(!1));for(var a=0;a<this.itemCount_;a++)if(!this.getInput("ADD"+a)){var b=this.appendValueInput("ADD"+a);0==a&&b.appendField(Blockly.Msg.TEXT_JOIN_TITLE_CREATEWITH)}for(;this.getInput("ADD"+
|
||||
a);)this.removeInput("ADD"+a),a++}};Blockly.Constants.Text.TEXT_JOIN_EXTENSION=function(){this.mixin(Blockly.Constants.Text.QUOTE_IMAGE_MIXIN);this.itemCount_=2;this.updateShape_();this.setMutator(new Blockly.Mutator(["text_create_join_item"]))};Blockly.Extensions.register("text_append_tooltip",Blockly.Extensions.buildTooltipWithFieldText("%{BKY_TEXT_APPEND_TOOLTIP}","VAR"));
|
||||
Blockly.Constants.Text.TEXT_INDEXOF_TOOLTIP_EXTENSION=function(){var a=this;this.setTooltip(function(){return Blockly.Msg.TEXT_INDEXOF_TOOLTIP.replace("%1",a.workspace.options.oneBasedIndex?"0":"-1")})};
|
||||
Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN={mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("at",!!this.isAt_);return a},domToMutation:function(a){a="false"!=a.getAttribute("at");this.updateAt_(a)},updateAt_:function(a){this.removeInput("AT",!0);this.removeInput("ORDINAL",!0);a&&(this.appendValueInput("AT").setCheck("Number"),Blockly.Msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL").appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX));Blockly.Msg.TEXT_CHARAT_TAIL&&
|
||||
(this.removeInput("TAIL",!0),this.appendDummyInput("TAIL").appendField(Blockly.Msg.TEXT_CHARAT_TAIL));this.isAt_=a}};
|
||||
Blockly.Constants.Text.TEXT_CHARAT_EXTENSION=function(){this.getField("WHERE").setValidator(function(a){var b="FROM_START"==a||"FROM_END"==a;if(b!=this.isAt_){var d=this.sourceBlock_;d.updateAt_(b);d.setFieldValue(a,"WHERE");return null}});this.updateAt_(!0);var a=this;this.setTooltip(function(){var b=a.getFieldValue("WHERE"),c=Blockly.Msg.TEXT_CHARAT_TOOLTIP;("FROM_START"==b||"FROM_END"==b)&&(b="FROM_START"==b?Blockly.Msg.LISTS_INDEX_FROM_START_TOOLTIP:Blockly.Msg.LISTS_INDEX_FROM_END_TOOLTIP)&&
|
||||
Blockly.Constants.Text.TEXT_CHARAT_EXTENSION=function(){this.getField("WHERE").setValidator(function(a){var b="FROM_START"==a||"FROM_END"==a;if(b!=this.isAt_){var e=this.sourceBlock_;e.updateAt_(b);e.setFieldValue(a,"WHERE");return null}});this.updateAt_(!0);var a=this;this.setTooltip(function(){var b=a.getFieldValue("WHERE"),c=Blockly.Msg.TEXT_CHARAT_TOOLTIP;("FROM_START"==b||"FROM_END"==b)&&(b="FROM_START"==b?Blockly.Msg.LISTS_INDEX_FROM_START_TOOLTIP:Blockly.Msg.LISTS_INDEX_FROM_END_TOOLTIP)&&
|
||||
(c+=" "+b.replace("%1",a.workspace.options.oneBasedIndex?"#1":"#0"));return c})};Blockly.Extensions.register("text_indexOf_tooltip",Blockly.Constants.Text.TEXT_INDEXOF_TOOLTIP_EXTENSION);Blockly.Extensions.register("text_quotes",Blockly.Constants.Text.TEXT_QUOTES_EXTENSION);Blockly.Extensions.registerMutator("text_join_mutator",Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN,Blockly.Constants.Text.TEXT_JOIN_EXTENSION);
|
||||
Blockly.Extensions.registerMutator("text_charAt_mutator",Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN,Blockly.Constants.Text.TEXT_CHARAT_EXTENSION);Blockly.Blocks.variables={};Blockly.Constants.Variables={};Blockly.Constants.Variables.HUE=330;
|
||||
Blockly.defineBlocksWithJsonArray([{type:"variables_get",message0:"%1",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}"}],output:null,colour:"%{BKY_VARIABLES_HUE}",helpUrl:"%{BKY_VARIABLES_GET_HELPURL}",tooltip:"%{BKY_VARIABLES_GET_TOOLTIP}",extensions:["contextMenu_variableSetterGetter"]},{type:"variables_set",message0:"%{BKY_VARIABLES_SET}",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}"},{type:"input_value",name:"VALUE"}],previousStatement:null,
|
||||
nextStatement:null,colour:"%{BKY_VARIABLES_HUE}",tooltip:"%{BKY_VARIABLES_SET_TOOLTIP}",helpUrl:"%{BKY_VARIABLES_SET_HELPURL}",extensions:["contextMenu_variableSetterGetter"]}]);
|
||||
Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN={customContextMenu:function(a){if(!this.isInFlyout){if("variables_get"==this.type)var b="variables_set",c=Blockly.Msg.VARIABLES_GET_CREATE_SET;else b="variables_get",c=Blockly.Msg.VARIABLES_SET_CREATE_GET;var d={enabled:0<this.workspace.remainingCapacity()},e=this.getField("VAR").getText();d.text=c.replace("%1",e);c=goog.dom.createDom("field",null,e);c.setAttribute("name","VAR");c=goog.dom.createDom("block",null,c);c.setAttribute("type",
|
||||
b);d.callback=Blockly.ContextMenu.callbackFactory(this,c);a.push(d)}}};Blockly.Extensions.registerMixin("contextMenu_variableSetterGetter",Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN);
|
||||
Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN={customContextMenu:function(a){if(!this.isInFlyout){if("variables_get"==this.type)var b="variables_set",c=Blockly.Msg.VARIABLES_GET_CREATE_SET;else b="variables_get",c=Blockly.Msg.VARIABLES_SET_CREATE_GET;var e={enabled:0<this.workspace.remainingCapacity()},d=this.getField("VAR").getText();e.text=c.replace("%1",d);c=document.createElement("field");c.setAttribute("name","VAR");c.appendChild(document.createTextNode(d));d=document.createElement("block");
|
||||
d.setAttribute("type",b);d.appendChild(c);e.callback=Blockly.ContextMenu.callbackFactory(this,d);a.push(e)}}};Blockly.Extensions.registerMixin("contextMenu_variableSetterGetter",Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN);
|
||||
Blockly.Constants.VariablesDynamic={};Blockly.Constants.VariablesDynamic.HUE=310;
|
||||
Blockly.defineBlocksWithJsonArray([{type:"variables_get_dynamic",message0:"%1",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}"}],output:null,colour:"%{BKY_VARIABLES_DYNAMIC_HUE}",helpUrl:"%{BKY_VARIABLES_GET_HELPURL}",tooltip:"%{BKY_VARIABLES_GET_TOOLTIP}",extensions:["contextMenu_variableDynamicSetterGetter"]},{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,colour:"%{BKY_VARIABLES_DYNAMIC_HUE}",tooltip:"%{BKY_VARIABLES_SET_TOOLTIP}",helpUrl:"%{BKY_VARIABLES_SET_HELPURL}",extensions:["contextMenu_variableDynamicSetterGetter"]}]);
|
||||
Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN={customContextMenu:function(a){if(!this.isInFlyout){if("variables_get_dynamic"==this.type){var b="variables_set_dynamic";var c=Blockly.Msg.VARIABLES_GET_CREATE_SET}else b="variables_get_dynamic",c=Blockly.Msg.VARIABLES_SET_CREATE_GET;var d={enabled:0<this.workspace.remainingCapacity()},e=this.getField("VAR").getText();d.text=c.replace("%1",e);c=goog.dom.createDom("field",null,e);c.setAttribute("name","VAR");c=goog.dom.createDom("block",
|
||||
null,c);c.setAttribute("type",b);d.callback=Blockly.ContextMenu.callbackFactory(this,c);a.push(d)}},onchange:function(){var a=this.getFieldValue("VAR");a=this.workspace.getVariableById(a);"variables_get_dynamic"==this.type?this.outputConnection.setCheck(a.type):this.getInput("VALUE").connection.setCheck(a.type)}};Blockly.Extensions.registerMixin("contextMenu_variableDynamicSetterGetter",Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN);
|
||||
Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN={customContextMenu:function(a){if(!this.isInFlyout){if("variables_get_dynamic"==this.type){var b="variables_set_dynamic";var c=Blockly.Msg.VARIABLES_GET_CREATE_SET}else b="variables_get_dynamic",c=Blockly.Msg.VARIABLES_SET_CREATE_GET;var e={enabled:0<this.workspace.remainingCapacity()},d=this.getField("VAR").getText();e.text=c.replace("%1",d);c=document.createElement("field");c.setAttribute("name","VAR");c.appendChild(document.createTextNode(d));
|
||||
d=document.createElement("block");d.setAttribute("type",b);d.appendChild(c);e.callback=Blockly.ContextMenu.callbackFactory(this,d);a.push(e)}},onchange:function(){var a=this.getFieldValue("VAR");a=this.workspace.getVariableById(a);"variables_get_dynamic"==this.type?this.outputConnection.setCheck(a.type):this.getInput("VALUE").connection.setCheck(a.type)}};Blockly.Extensions.registerMixin("contextMenu_variableDynamicSetterGetter",Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN);
|
||||
+157
-69
@@ -36,13 +36,12 @@ goog.require('Blockly.Events.BlockMove');
|
||||
goog.require('Blockly.Extensions');
|
||||
goog.require('Blockly.Input');
|
||||
goog.require('Blockly.Mutator');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.Warning');
|
||||
goog.require('Blockly.Workspace');
|
||||
goog.require('Blockly.Xml');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,11 +56,11 @@ goog.require('goog.string');
|
||||
*/
|
||||
Blockly.Block = function(workspace, prototypeName, opt_id) {
|
||||
if (typeof Blockly.Generator.prototype[prototypeName] !== 'undefined') {
|
||||
console.warn('FUTURE ERROR: Block prototypeName "' + prototypeName
|
||||
+ '" conflicts with Blockly.Generator members. Registering Generators '
|
||||
+ 'for this block type will incur errors.'
|
||||
+ '\nThis name will be DISALLOWED (throwing an error) in future '
|
||||
+ 'versions of Blockly.');
|
||||
console.warn('FUTURE ERROR: Block prototypeName "' + prototypeName +
|
||||
'" conflicts with Blockly.Generator members. Registering Generators ' +
|
||||
'for this block type will incur errors.' +
|
||||
'\nThis name will be DISALLOWED (throwing an error) in future ' +
|
||||
'versions of Blockly.');
|
||||
}
|
||||
|
||||
/** @type {string} */
|
||||
@@ -153,15 +152,16 @@ Blockly.Block = function(workspace, prototypeName, opt_id) {
|
||||
/** @type {string} */
|
||||
this.type = prototypeName;
|
||||
var prototype = Blockly.Blocks[prototypeName];
|
||||
goog.asserts.assertObject(prototype,
|
||||
'Error: Unknown block type "%s".', prototypeName);
|
||||
if (!prototype || typeof prototype != 'object') {
|
||||
throw TypeError('Unknown block type: ' + prototypeName);
|
||||
}
|
||||
goog.mixin(this, prototype);
|
||||
}
|
||||
|
||||
workspace.addTopBlock(this);
|
||||
|
||||
// Call an initialization function, if it exists.
|
||||
if (goog.isFunction(this.init)) {
|
||||
if (typeof this.init == 'function') {
|
||||
this.init();
|
||||
}
|
||||
// Record initial inline state.
|
||||
@@ -184,7 +184,7 @@ Blockly.Block = function(workspace, prototypeName, opt_id) {
|
||||
|
||||
}
|
||||
// Bind an onchange function, if it exists.
|
||||
if (goog.isFunction(this.onchange)) {
|
||||
if (typeof this.onchange == 'function') {
|
||||
this.setOnChange(this.onchange);
|
||||
}
|
||||
};
|
||||
@@ -314,27 +314,92 @@ Blockly.Block.prototype.initModel = function() {
|
||||
*/
|
||||
Blockly.Block.prototype.unplug = function(opt_healStack) {
|
||||
if (this.outputConnection) {
|
||||
if (this.outputConnection.isConnected()) {
|
||||
// Disconnect from any superior block.
|
||||
this.outputConnection.disconnect();
|
||||
}
|
||||
this.unplugFromRow_(opt_healStack);
|
||||
} else if (this.previousConnection) {
|
||||
var previousTarget = null;
|
||||
if (this.previousConnection.isConnected()) {
|
||||
// Remember the connection that any next statements need to connect to.
|
||||
previousTarget = this.previousConnection.targetConnection;
|
||||
// Detach this block from the parent's tree.
|
||||
this.previousConnection.disconnect();
|
||||
}
|
||||
var nextBlock = this.getNextBlock();
|
||||
if (opt_healStack && nextBlock) {
|
||||
// Disconnect the next statement.
|
||||
var nextTarget = this.nextConnection.targetConnection;
|
||||
nextTarget.disconnect();
|
||||
if (previousTarget && previousTarget.checkType_(nextTarget)) {
|
||||
// Attach the next statement to the previous statement.
|
||||
previousTarget.connect(nextTarget);
|
||||
this.unplugFromStack_(opt_healStack);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Unplug this block's output from an input on another block. Optionally
|
||||
* reconnect the block's parent to the only child block, if possible.
|
||||
* @param {boolean=} opt_healStack Disconnect right-side block and connect to
|
||||
* left-side block. Defaults to false.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Block.prototype.unplugFromRow_ = function(opt_healStack) {
|
||||
var parentConnection = null;
|
||||
if (this.outputConnection.isConnected()) {
|
||||
parentConnection = this.outputConnection.targetConnection;
|
||||
// Disconnect from any superior block.
|
||||
this.outputConnection.disconnect();
|
||||
}
|
||||
|
||||
// Return early in obvious cases.
|
||||
if (!parentConnection || !opt_healStack) {
|
||||
return;
|
||||
}
|
||||
|
||||
var thisConnection = this.getOnlyValueConnection_();
|
||||
if (!thisConnection || !thisConnection.isConnected()) {
|
||||
// Too many or too few possible connections on this block, or there's
|
||||
// nothing on the other side of this connection.
|
||||
return;
|
||||
}
|
||||
|
||||
// Only disconnect the child if it's possible to move it to the parent.
|
||||
var childConnection = thisConnection.targetConnection;
|
||||
if (childConnection.checkType_(parentConnection)) {
|
||||
// Disconnect the child block.
|
||||
childConnection.disconnect();
|
||||
parentConnection.connect(childConnection);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the connection on the only value input on the block, or null if the
|
||||
* number of value inputs is not one.
|
||||
* @return {Blockly.Connection} The connection on the value input, or null.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Block.prototype.getOnlyValueConnection_ = function() {
|
||||
var connection = false;
|
||||
for (var i = 0; i < this.inputList.length; i++) {
|
||||
var thisConnection = this.inputList[i].connection;
|
||||
if (thisConnection && thisConnection.type == Blockly.INPUT_VALUE) {
|
||||
if (connection) {
|
||||
return null; // More than one value input found.
|
||||
}
|
||||
connection = thisConnection;
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unplug this statement block from its superior block. Optionally reconnect
|
||||
* the block underneath with the block on top.
|
||||
* @param {boolean=} opt_healStack Disconnect child statement and reconnect
|
||||
* stack. Defaults to false.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Block.prototype.unplugFromStack_ = function(opt_healStack) {
|
||||
var previousTarget = null;
|
||||
if (this.previousConnection.isConnected()) {
|
||||
// Remember the connection that any next statements need to connect to.
|
||||
previousTarget = this.previousConnection.targetConnection;
|
||||
// Detach this block from the parent's tree.
|
||||
this.previousConnection.disconnect();
|
||||
}
|
||||
var nextBlock = this.getNextBlock();
|
||||
if (opt_healStack && nextBlock) {
|
||||
// Disconnect the next statement.
|
||||
var nextTarget = this.nextConnection.targetConnection;
|
||||
nextTarget.disconnect();
|
||||
// TODO (#1994): Check types before unplugging.
|
||||
if (previousTarget && previousTarget.checkType_(nextTarget)) {
|
||||
// Attach the next statement to the previous statement.
|
||||
previousTarget.connect(nextTarget);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -497,14 +562,14 @@ Blockly.Block.prototype.setParent = function(newParent) {
|
||||
}
|
||||
if (this.parentBlock_) {
|
||||
// Remove this block from the old parent's child list.
|
||||
goog.array.remove(this.parentBlock_.childBlocks_, this);
|
||||
Blockly.utils.arrayRemove(this.parentBlock_.childBlocks_, this);
|
||||
|
||||
// Disconnect from superior blocks.
|
||||
if (this.previousConnection && this.previousConnection.isConnected()) {
|
||||
throw 'Still connected to previous block.';
|
||||
throw Error('Still connected to previous block.');
|
||||
}
|
||||
if (this.outputConnection && this.outputConnection.isConnected()) {
|
||||
throw 'Still connected to parent block.';
|
||||
throw Error('Still connected to parent block.');
|
||||
}
|
||||
this.parentBlock_ = null;
|
||||
// This block hasn't actually moved on-screen, so there's no need to update
|
||||
@@ -686,14 +751,14 @@ Blockly.Block.prototype.getHue = function() {
|
||||
* or a message reference string pointing to one of those two values.
|
||||
*/
|
||||
Blockly.Block.prototype.setColour = function(colour) {
|
||||
var dereferenced = goog.isString(colour) ?
|
||||
var dereferenced = (typeof colour == 'string') ?
|
||||
Blockly.utils.replaceMessageReferences(colour) : colour;
|
||||
|
||||
var hue = Number(dereferenced);
|
||||
if (!isNaN(hue) && 0 <= hue && hue <= 360) {
|
||||
this.hue_ = hue;
|
||||
this.colour_ = Blockly.hueToRgb(hue);
|
||||
} else if (goog.isString(dereferenced) &&
|
||||
} else if ((typeof dereferenced == 'string') &&
|
||||
/^#[0-9a-fA-F]{6}$/.test(dereferenced)) {
|
||||
this.colour_ = dereferenced;
|
||||
// Only store hue if colour is set as a hue.
|
||||
@@ -717,8 +782,8 @@ Blockly.Block.prototype.setColour = function(colour) {
|
||||
* @throws {Error} if onchangeFn is not falsey or a function.
|
||||
*/
|
||||
Blockly.Block.prototype.setOnChange = function(onchangeFn) {
|
||||
if (onchangeFn && !goog.isFunction(onchangeFn)) {
|
||||
throw new Error("onchange must be a function.");
|
||||
if (onchangeFn && typeof onchangeFn != 'function') {
|
||||
throw new Error('onchange must be a function.');
|
||||
}
|
||||
if (this.onchangeWrapper_) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
@@ -840,7 +905,9 @@ Blockly.Block.prototype.getFieldValue = function(name) {
|
||||
*/
|
||||
Blockly.Block.prototype.setFieldValue = function(newValue, name) {
|
||||
var field = this.getField(name);
|
||||
goog.asserts.assertObject(field, 'Field "%s" not found.', name);
|
||||
if (!field) {
|
||||
throw Error('Field "' + name + '" not found.');
|
||||
}
|
||||
field.setValue(newValue);
|
||||
};
|
||||
|
||||
@@ -856,16 +923,20 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) {
|
||||
opt_check = null;
|
||||
}
|
||||
if (!this.previousConnection) {
|
||||
goog.asserts.assert(!this.outputConnection,
|
||||
'Remove output connection prior to adding previous connection.');
|
||||
if (this.outputConnection) {
|
||||
throw Error('Remove output connection prior to adding previous ' +
|
||||
'connection.');
|
||||
}
|
||||
this.previousConnection =
|
||||
this.makeConnection_(Blockly.PREVIOUS_STATEMENT);
|
||||
}
|
||||
this.previousConnection.setCheck(opt_check);
|
||||
} else {
|
||||
if (this.previousConnection) {
|
||||
goog.asserts.assert(!this.previousConnection.isConnected(),
|
||||
'Must disconnect previous statement before removing connection.');
|
||||
if (this.previousConnection.isConnected()) {
|
||||
throw Error('Must disconnect previous statement before removing ' +
|
||||
'connection.');
|
||||
}
|
||||
this.previousConnection.dispose();
|
||||
this.previousConnection = null;
|
||||
}
|
||||
@@ -889,8 +960,10 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) {
|
||||
this.nextConnection.setCheck(opt_check);
|
||||
} else {
|
||||
if (this.nextConnection) {
|
||||
goog.asserts.assert(!this.nextConnection.isConnected(),
|
||||
'Must disconnect next statement before removing connection.');
|
||||
if (this.nextConnection.isConnected()) {
|
||||
throw Error('Must disconnect next statement before removing ' +
|
||||
'connection.');
|
||||
}
|
||||
this.nextConnection.dispose();
|
||||
this.nextConnection = null;
|
||||
}
|
||||
@@ -910,15 +983,18 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) {
|
||||
opt_check = null;
|
||||
}
|
||||
if (!this.outputConnection) {
|
||||
goog.asserts.assert(!this.previousConnection,
|
||||
'Remove previous connection prior to adding output connection.');
|
||||
if (this.previousConnection) {
|
||||
throw Error('Remove previous connection prior to adding output ' +
|
||||
'connection.');
|
||||
}
|
||||
this.outputConnection = this.makeConnection_(Blockly.OUTPUT_VALUE);
|
||||
}
|
||||
this.outputConnection.setCheck(opt_check);
|
||||
} else {
|
||||
if (this.outputConnection) {
|
||||
goog.asserts.assert(!this.outputConnection.isConnected(),
|
||||
'Must disconnect output value before removing connection.');
|
||||
if (this.outputConnection.isConnected()) {
|
||||
throw Error('Must disconnect output value before removing connection.');
|
||||
}
|
||||
this.outputConnection.dispose();
|
||||
this.outputConnection = null;
|
||||
}
|
||||
@@ -1044,12 +1120,14 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) {
|
||||
}
|
||||
}
|
||||
}
|
||||
text = goog.string.trim(text.join(' ')) || '???';
|
||||
text = text.join(' ').trim() || '???';
|
||||
if (opt_maxLength) {
|
||||
// TODO: Improve truncation so that text from this block is given priority.
|
||||
// E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not "1+2+3+4+5...".
|
||||
// E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...".
|
||||
text = goog.string.truncate(text, opt_maxLength);
|
||||
if (text.length > opt_maxLength) {
|
||||
text = text.substring(0, opt_maxLength - 3) + '...';
|
||||
}
|
||||
}
|
||||
return text;
|
||||
};
|
||||
@@ -1093,9 +1171,10 @@ Blockly.Block.prototype.jsonInit = function(json) {
|
||||
var warningPrefix = json['type'] ? 'Block "' + json['type'] + '": ' : '';
|
||||
|
||||
// Validate inputs.
|
||||
goog.asserts.assert(
|
||||
json['output'] == undefined || json['previousStatement'] == undefined,
|
||||
warningPrefix + 'Must not have both an output and a previousStatement.');
|
||||
if (json['output'] && json['previousStatement']) {
|
||||
throw Error(warningPrefix +
|
||||
'Must not have both an output and a previousStatement.');
|
||||
}
|
||||
|
||||
// Set basic properties of block.
|
||||
this.jsonInitColour_(json, warningPrefix);
|
||||
@@ -1135,7 +1214,7 @@ Blockly.Block.prototype.jsonInit = function(json) {
|
||||
var localizedValue = Blockly.utils.replaceMessageReferences(rawValue);
|
||||
this.setHelpUrl(localizedValue);
|
||||
}
|
||||
if (goog.isString(json['extensions'])) {
|
||||
if (typeof json['extensions'] == 'string') {
|
||||
console.warn(
|
||||
warningPrefix + 'JSON attribute \'extensions\' should be an array of' +
|
||||
' strings. Found raw string in JSON for \'' + json['type'] +
|
||||
@@ -1188,8 +1267,8 @@ Blockly.Block.prototype.jsonInitColour_ = function(json, warningPrefix) {
|
||||
* @param {boolean=} opt_disableCheck Option flag to disable overwrite checks.
|
||||
*/
|
||||
Blockly.Block.prototype.mixin = function(mixinObj, opt_disableCheck) {
|
||||
if (goog.isDef(opt_disableCheck) && !goog.isBoolean(opt_disableCheck)) {
|
||||
throw new Error("opt_disableCheck must be a boolean if provided");
|
||||
if (opt_disableCheck !== undefined && typeof opt_disableCheck != 'boolean') {
|
||||
throw new Error('opt_disableCheck must be a boolean if provided');
|
||||
}
|
||||
if (!opt_disableCheck) {
|
||||
var overwrites = [];
|
||||
@@ -1248,7 +1327,7 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
|
||||
}
|
||||
// Add last dummy input if needed.
|
||||
if (elements.length && (typeof elements[elements.length - 1] == 'string' ||
|
||||
goog.string.startsWith(
|
||||
Blockly.utils.startsWith(
|
||||
elements[elements.length - 1]['type'], 'field_'))) {
|
||||
var dummyInput = {type: 'input_dummy'};
|
||||
if (lastDummyAlign) {
|
||||
@@ -1368,9 +1447,12 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) {
|
||||
}
|
||||
}
|
||||
}
|
||||
goog.asserts.assert(inputIndex != -1, 'Named input "%s" not found.', name);
|
||||
goog.asserts.assert(
|
||||
refIndex != -1, 'Reference input "%s" not found.', refName);
|
||||
if (inputIndex == -1) {
|
||||
throw Error('Named input "' + name + '" not found.');
|
||||
}
|
||||
if (refIndex == -1) {
|
||||
throw Error('Reference input "' + refName + '" not found.');
|
||||
}
|
||||
this.moveNumberedInputBefore(inputIndex, refIndex);
|
||||
};
|
||||
|
||||
@@ -1382,11 +1464,15 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) {
|
||||
Blockly.Block.prototype.moveNumberedInputBefore = function(
|
||||
inputIndex, refIndex) {
|
||||
// Validate arguments.
|
||||
goog.asserts.assert(inputIndex != refIndex, 'Can\'t move input to itself.');
|
||||
goog.asserts.assert(inputIndex < this.inputList.length,
|
||||
'Input index ' + inputIndex + ' out of bounds.');
|
||||
goog.asserts.assert(refIndex <= this.inputList.length,
|
||||
'Reference input ' + refIndex + ' out of bounds.');
|
||||
if (inputIndex == refIndex) {
|
||||
throw Error('Can\'t move input to itself.');
|
||||
}
|
||||
if (inputIndex >= this.inputList.length) {
|
||||
throw RangeError('Input index ' + inputIndex + ' out of bounds.');
|
||||
}
|
||||
if (refIndex > this.inputList.length) {
|
||||
throw RangeError('Reference input ' + refIndex + ' out of bounds.');
|
||||
}
|
||||
// Remove input.
|
||||
var input = this.inputList[inputIndex];
|
||||
this.inputList.splice(inputIndex, 1);
|
||||
@@ -1401,7 +1487,7 @@ Blockly.Block.prototype.moveNumberedInputBefore = function(
|
||||
* Remove an input from this block.
|
||||
* @param {string} name The name of the input.
|
||||
* @param {boolean=} opt_quiet True to prevent error if input is not present.
|
||||
* @throws {goog.asserts.AssertionError} if the input is not present and
|
||||
* @throws {Error} if the input is not present and
|
||||
* opt_quiet is not true.
|
||||
*/
|
||||
Blockly.Block.prototype.removeInput = function(name, opt_quiet) {
|
||||
@@ -1424,7 +1510,7 @@ Blockly.Block.prototype.removeInput = function(name, opt_quiet) {
|
||||
}
|
||||
}
|
||||
if (!opt_quiet) {
|
||||
goog.asserts.fail('Input "%s" not found.', name);
|
||||
throw Error('Input not found: ' + name);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1508,7 +1594,9 @@ Blockly.Block.prototype.getRelativeToSurfaceXY = function() {
|
||||
* @param {number} dy Vertical offset, in workspace units.
|
||||
*/
|
||||
Blockly.Block.prototype.moveBy = function(dx, dy) {
|
||||
goog.asserts.assert(!this.parentBlock_, 'Block has parent.');
|
||||
if (this.parentBlock_) {
|
||||
throw Error('Block has parent.');
|
||||
}
|
||||
var event = new Blockly.Events.BlockMove(this);
|
||||
this.xy_.translate(dx, dy);
|
||||
event.recordNew();
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
goog.provide('Blockly.BlockAnimations');
|
||||
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
|
||||
/**
|
||||
* PID of disconnect UI animation. There can only be one at a time.
|
||||
@@ -79,7 +81,7 @@ Blockly.BlockAnimations.disposeUiStep_ = function(clone, rtl, start,
|
||||
var ms = new Date - start;
|
||||
var percent = ms / 150;
|
||||
if (percent > 1) {
|
||||
goog.dom.removeNode(clone);
|
||||
clone.parentNode.removeChild(clone);
|
||||
} else {
|
||||
var x = clone.translateX_ +
|
||||
(rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent;
|
||||
@@ -139,7 +141,7 @@ Blockly.BlockAnimations.connectionUiStep_ = function(ripple, start, scale) {
|
||||
var ms = new Date - start;
|
||||
var percent = ms / 150;
|
||||
if (percent > 1) {
|
||||
goog.dom.removeNode(ripple);
|
||||
ripple.parentNode.removeChild(ripple);
|
||||
} else {
|
||||
ripple.setAttribute('r', percent * 25 * scale);
|
||||
ripple.style.opacity = 1 - percent;
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
goog.provide('Blockly.BlockDragSurfaceSvg');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
@@ -113,8 +112,9 @@ Blockly.BlockDragSurfaceSvg.prototype.createDom = function() {
|
||||
* surface.
|
||||
*/
|
||||
Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) {
|
||||
goog.asserts.assert(
|
||||
this.dragGroup_.childNodes.length == 0, 'Already dragging a block.');
|
||||
if (this.dragGroup_.childNodes.length) {
|
||||
throw Error('Already dragging a block.');
|
||||
}
|
||||
// appendChild removes the blocks from the previous parent
|
||||
this.dragGroup_.appendChild(blocks);
|
||||
this.SVG_.style.display = 'block';
|
||||
@@ -214,7 +214,8 @@ Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) {
|
||||
this.dragGroup_.removeChild(this.getCurrentBlock());
|
||||
}
|
||||
this.SVG_.style.display = 'none';
|
||||
goog.asserts.assert(
|
||||
this.dragGroup_.childNodes.length == 0, 'Drag group was not cleared.');
|
||||
if (this.dragGroup_.childNodes.length) {
|
||||
throw Error('Drag group was not cleared.');
|
||||
}
|
||||
this.surfaceXY_ = null;
|
||||
};
|
||||
|
||||
@@ -31,7 +31,6 @@ goog.require('Blockly.DraggedConnectionManager');
|
||||
goog.require('Blockly.Events.BlockMove');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.asserts');
|
||||
|
||||
|
||||
/**
|
||||
@@ -153,6 +152,13 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, hea
|
||||
Blockly.Events.setGroup(true);
|
||||
}
|
||||
|
||||
// Mutators don't have the same type of z-ordering as the normal workspace during a drag.
|
||||
// They have to rely on the order of the blocks in the svg. For performance reasons that
|
||||
// usually happens at the end of a drag, but do it at the beginning for mutators.
|
||||
if (this.workspace_.isMutator) {
|
||||
this.draggingBlock_.bringToFront();
|
||||
}
|
||||
|
||||
this.workspace_.setResizesEnabled(false);
|
||||
Blockly.BlockAnimations.disconnectUiStop();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ goog.provide('Blockly.Events.Move'); // Deprecated.
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.Abstract');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ Blockly.Events.Delete = function(block) {
|
||||
return; // Blank event to be populated by fromJson.
|
||||
}
|
||||
if (block.getParent()) {
|
||||
throw 'Connected blocks cannot be deleted.';
|
||||
throw Error('Connected blocks cannot be deleted.');
|
||||
}
|
||||
Blockly.Events.Delete.superClass_.constructor.call(this, block);
|
||||
|
||||
|
||||
+19
-9
@@ -37,8 +37,7 @@ goog.require('Blockly.Tooltip');
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.color');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
@@ -145,7 +144,9 @@ Blockly.BlockSvg.INLINE = -1;
|
||||
* May be called more than once.
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.initSvg = function() {
|
||||
goog.asserts.assert(this.workspace.rendered, 'Workspace is headless.');
|
||||
if (!this.workspace.rendered) {
|
||||
throw TypeError('Workspace is headless.');
|
||||
}
|
||||
for (var i = 0, input; input = this.inputList[i]; i++) {
|
||||
input.init();
|
||||
}
|
||||
@@ -327,7 +328,9 @@ Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() {
|
||||
* @param {number} dy Vertical offset in workspace units.
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.moveBy = function(dx, dy) {
|
||||
goog.asserts.assert(!this.parentBlock_, 'Block has parent.');
|
||||
if (this.parentBlock_) {
|
||||
throw Error('Block has parent.');
|
||||
}
|
||||
var eventsEnabled = Blockly.Events.isEnabled();
|
||||
if (eventsEnabled) {
|
||||
var event = new Blockly.Events.BlockMove(this);
|
||||
@@ -594,7 +597,7 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.showHelp_ = function() {
|
||||
var url = goog.isFunction(this.helpUrl) ? this.helpUrl() : this.helpUrl;
|
||||
var url = (typeof this.helpUrl == 'function') ? this.helpUrl() : this.helpUrl;
|
||||
if (url) {
|
||||
window.open(url);
|
||||
}
|
||||
@@ -666,7 +669,14 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
|
||||
Blockly.Msg['ENABLE_BLOCK'] : Blockly.Msg['DISABLE_BLOCK'],
|
||||
enabled: !this.getInheritedDisabled(),
|
||||
callback: function() {
|
||||
var group = Blockly.Events.getGroup();
|
||||
if (!group) {
|
||||
Blockly.Events.setGroup(true);
|
||||
}
|
||||
block.setDisabled(!block.disabled);
|
||||
if (!group) {
|
||||
Blockly.Events.setGroup(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
menuOptions.push(disableOption);
|
||||
@@ -845,7 +855,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
|
||||
}
|
||||
Blockly.BlockSvg.superClass_.dispose.call(this, healStack);
|
||||
|
||||
goog.dom.removeNode(this.svgGroup_);
|
||||
this.svgGroup_.parentNode.removeChild(this.svgGroup_);
|
||||
blockWorkspace.resizeContents();
|
||||
// Sever JavaScript to DOM connections.
|
||||
this.svgGroup_ = null;
|
||||
@@ -936,7 +946,7 @@ Blockly.BlockSvg.prototype.getCommentText = function() {
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.setCommentText = function(text) {
|
||||
var changedState = false;
|
||||
if (goog.isString(text)) {
|
||||
if (typeof text == 'string') {
|
||||
if (!this.comment) {
|
||||
this.comment = new Blockly.Comment(this);
|
||||
changedState = true;
|
||||
@@ -1009,7 +1019,7 @@ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
|
||||
}
|
||||
|
||||
var changedState = false;
|
||||
if (goog.isString(text)) {
|
||||
if (typeof text == 'string') {
|
||||
if (!this.warning) {
|
||||
this.warning = new Blockly.Warning(this);
|
||||
changedState = true;
|
||||
@@ -1213,7 +1223,7 @@ Blockly.BlockSvg.prototype.setInputsInline = function(newBoolean) {
|
||||
* Remove an input from this block.
|
||||
* @param {string} name The name of the input.
|
||||
* @param {boolean=} opt_quiet True to prevent error if input is not present.
|
||||
* @throws {goog.asserts.AssertionError} if the input is not present and
|
||||
* @throws {Error} if the input is not present and
|
||||
* opt_quiet is not true.
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.removeInput = function(name, opt_quiet) {
|
||||
|
||||
+7
-2
@@ -168,14 +168,19 @@ Blockly.svgResize = function(workspace) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle a key-down on SVG drawing surface.
|
||||
* Handle a key-down on SVG drawing surface. Does nothing if the main workspace is not visible.
|
||||
* @param {!Event} e Key down event.
|
||||
* @private
|
||||
*/
|
||||
// TODO (https://github.com/google/blockly/issues/1998) handle cases where there are
|
||||
// multiple workspaces and non-main workspaces are able to accept input.
|
||||
Blockly.onKeyDown_ = function(e) {
|
||||
if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e)) {
|
||||
if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e)
|
||||
|| (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible())) {
|
||||
// No key actions on readonly workspaces.
|
||||
// When focused on an HTML text input widget, don't trap any keys.
|
||||
// Ignore keypresses on rendered workspaces that have been explicitly
|
||||
// hidden.
|
||||
return;
|
||||
}
|
||||
var deleteBlock = false;
|
||||
|
||||
+2
-4
@@ -28,8 +28,6 @@ goog.provide('Blockly.Bubble');
|
||||
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.Workspace');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math');
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
@@ -56,7 +54,7 @@ Blockly.Bubble = function(workspace, content, shape, anchorXY,
|
||||
if (this.workspace_.RTL) {
|
||||
angle = -angle;
|
||||
}
|
||||
this.arrow_radians_ = goog.math.toRadians(angle);
|
||||
this.arrow_radians_ = Blockly.utils.toRadians(angle);
|
||||
|
||||
var canvas = workspace.getBubbleCanvas();
|
||||
canvas.appendChild(this.createDom_(content, !!(bubbleWidth && bubbleHeight)));
|
||||
@@ -606,7 +604,7 @@ Blockly.Bubble.prototype.setColour = function(hexColour) {
|
||||
Blockly.Bubble.prototype.dispose = function() {
|
||||
Blockly.Bubble.unbindDragEvents_();
|
||||
// Dispose of and unlink the bubble.
|
||||
goog.dom.removeNode(this.bubbleGroup_);
|
||||
this.bubbleGroup_.parentNode.removeChild(this.bubbleGroup_);
|
||||
this.bubbleGroup_ = null;
|
||||
this.bubbleArrow_ = null;
|
||||
this.bubbleBack_ = null;
|
||||
|
||||
@@ -28,10 +28,10 @@ goog.provide('Blockly.BubbleDragger');
|
||||
|
||||
goog.require('Blockly.Bubble');
|
||||
goog.require('Blockly.Events.CommentMove');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.WorkspaceCommentSvg');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.asserts');
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,8 @@ goog.require('Blockly.Bubble');
|
||||
goog.require('Blockly.Events.BlockChange');
|
||||
goog.require('Blockly.Events.Ui');
|
||||
goog.require('Blockly.Icon');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
|
||||
+28
-23
@@ -28,9 +28,6 @@ goog.provide('Blockly.Connection');
|
||||
|
||||
goog.require('Blockly.Events.BlockMove');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom');
|
||||
|
||||
|
||||
/**
|
||||
* Class for a connection between blocks.
|
||||
@@ -160,7 +157,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
|
||||
// Value connections.
|
||||
// If female block is already connected, disconnect and bump the male.
|
||||
if (!orphanBlock.outputConnection) {
|
||||
throw 'Orphan block does not have an output connection.';
|
||||
throw Error('Orphan block does not have an output connection.');
|
||||
}
|
||||
// Attempt to reattach the orphan at the end of the newly inserted
|
||||
// block. Since this block may be a row, walk down to the end
|
||||
@@ -176,7 +173,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
|
||||
// Statement blocks may be inserted into the middle of a stack.
|
||||
// Split the stack.
|
||||
if (!orphanBlock.previousConnection) {
|
||||
throw 'Orphan block does not have a previous connection.';
|
||||
throw Error('Orphan block does not have a previous connection.');
|
||||
}
|
||||
// Attempt to reattach the orphan at the bottom of the newly inserted
|
||||
// block. Since this block may be a stack, walk down to the end.
|
||||
@@ -238,7 +235,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
|
||||
*/
|
||||
Blockly.Connection.prototype.dispose = function() {
|
||||
if (this.isConnected()) {
|
||||
throw 'Disconnect connection before disposing of it.';
|
||||
throw Error('Disconnect connection before disposing of it.');
|
||||
}
|
||||
if (this.inDB_) {
|
||||
this.db_.removeConnection_(this);
|
||||
@@ -317,22 +314,22 @@ Blockly.Connection.prototype.checkConnection_ = function(target) {
|
||||
case Blockly.Connection.CAN_CONNECT:
|
||||
break;
|
||||
case Blockly.Connection.REASON_SELF_CONNECTION:
|
||||
throw 'Attempted to connect a block to itself.';
|
||||
throw Error('Attempted to connect a block to itself.');
|
||||
case Blockly.Connection.REASON_DIFFERENT_WORKSPACES:
|
||||
// Usually this means one block has been deleted.
|
||||
throw 'Blocks not on same workspace.';
|
||||
throw Error('Blocks not on same workspace.');
|
||||
case Blockly.Connection.REASON_WRONG_TYPE:
|
||||
throw 'Attempt to connect incompatible types.';
|
||||
throw Error('Attempt to connect incompatible types.');
|
||||
case Blockly.Connection.REASON_TARGET_NULL:
|
||||
throw 'Target connection is null.';
|
||||
throw Error('Target connection is null.');
|
||||
case Blockly.Connection.REASON_CHECKS_FAILED:
|
||||
var msg = 'Connection checks failed. ';
|
||||
msg += this + ' expected ' + this.check_ + ', found ' + target.check_;
|
||||
throw msg;
|
||||
throw Error(msg);
|
||||
case Blockly.Connection.REASON_SHADOW_PARENT:
|
||||
throw 'Connecting non-shadow to shadow block.';
|
||||
throw Error('Connecting non-shadow to shadow block.');
|
||||
default:
|
||||
throw 'Unknown connection failure: this should never happen!';
|
||||
throw Error('Unknown connection failure: this should never happen!');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -414,7 +411,9 @@ Blockly.Connection.prototype.connect = function(otherConnection) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.Connection.connectReciprocally_ = function(first, second) {
|
||||
goog.asserts.assert(first && second, 'Cannot connect null connections.');
|
||||
if (!first || !second) {
|
||||
throw Error('Cannot connect null connections.');
|
||||
}
|
||||
first.targetConnection = second;
|
||||
second.targetConnection = first;
|
||||
};
|
||||
@@ -474,10 +473,12 @@ Blockly.Connection.lastConnectionInRow_ = function(startBlock, orphanBlock) {
|
||||
*/
|
||||
Blockly.Connection.prototype.disconnect = function() {
|
||||
var otherConnection = this.targetConnection;
|
||||
goog.asserts.assert(otherConnection, 'Source connection not connected.');
|
||||
goog.asserts.assert(otherConnection.targetConnection == this,
|
||||
'Target connection not connected to source connection.');
|
||||
|
||||
if (!otherConnection) {
|
||||
throw Error('Source connection not connected.');
|
||||
}
|
||||
if (otherConnection.targetConnection != this) {
|
||||
throw Error('Target connection not connected to source connection.');
|
||||
}
|
||||
var parentBlock, childBlock, parentConnection;
|
||||
if (this.isSuperior()) {
|
||||
// Superior block.
|
||||
@@ -531,7 +532,7 @@ Blockly.Connection.prototype.respawnShadow_ = function() {
|
||||
} else if (blockShadow.previousConnection) {
|
||||
this.connect(blockShadow.previousConnection);
|
||||
} else {
|
||||
throw 'Child block does not have output or previous statement.';
|
||||
throw Error('Child block does not have output or previous statement.');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -591,7 +592,7 @@ Blockly.Connection.prototype.onCheckChanged_ = function() {
|
||||
Blockly.Connection.prototype.setCheck = function(check) {
|
||||
if (check) {
|
||||
// Ensure that check is in an array.
|
||||
if (!goog.isArray(check)) {
|
||||
if (!Array.isArray(check)) {
|
||||
check = [check];
|
||||
}
|
||||
this.check_ = check;
|
||||
@@ -651,9 +652,13 @@ Blockly.Connection.prototype.toString = function() {
|
||||
} else if (block.nextConnection == this) {
|
||||
msg = 'Next Connection of ';
|
||||
} else {
|
||||
var parentInput = goog.array.find(block.inputList, function(input) {
|
||||
return input.connection == this;
|
||||
}, this);
|
||||
var parentInput = null;
|
||||
for (var i = 0, input; input = block.inputList[i]; i++) {
|
||||
if (input.connection == this) {
|
||||
parentInput = input;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (parentInput) {
|
||||
msg = 'Input "' + parentInput.name + '" connection on ';
|
||||
} else {
|
||||
|
||||
@@ -51,7 +51,7 @@ Blockly.ConnectionDB.constructor = Blockly.ConnectionDB;
|
||||
*/
|
||||
Blockly.ConnectionDB.prototype.addConnection = function(connection) {
|
||||
if (connection.inDB_) {
|
||||
throw 'Connection already in database.';
|
||||
throw Error('Connection already in database.');
|
||||
}
|
||||
if (connection.getSourceBlock().isInFlyout) {
|
||||
// Don't bother maintaining a database of connections in a flyout.
|
||||
@@ -137,11 +137,11 @@ Blockly.ConnectionDB.prototype.findPositionForConnection_ = function(
|
||||
*/
|
||||
Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) {
|
||||
if (!connection.inDB_) {
|
||||
throw 'Connection not in database.';
|
||||
throw Error('Connection not in database.');
|
||||
}
|
||||
var removalIndex = this.findConnection(connection);
|
||||
if (removalIndex == -1) {
|
||||
throw 'Unable to find connection in connectionDB.';
|
||||
throw Error('Unable to find connection in connectionDB.');
|
||||
}
|
||||
connection.inDB_ = false;
|
||||
this.splice(removalIndex, 1);
|
||||
|
||||
+3
-3
@@ -34,9 +34,8 @@ goog.require('Blockly.Events.BlockCreate');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.uiMenu');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.style');
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.ui.Menu');
|
||||
goog.require('goog.ui.MenuItem');
|
||||
goog.require('goog.userAgent');
|
||||
@@ -241,7 +240,8 @@ Blockly.ContextMenu.blockDeleteOption = function(block) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.ContextMenu.blockHelpOption = function(block) {
|
||||
var url = goog.isFunction(block.helpUrl) ? block.helpUrl() : block.helpUrl;
|
||||
var url = (typeof block.helpUrl == 'function') ?
|
||||
block.helpUrl() : block.helpUrl;
|
||||
var helpOption = {
|
||||
enabled: !!url,
|
||||
text: Blockly.Msg['HELP'],
|
||||
|
||||
+19
-41
@@ -164,6 +164,11 @@ Blockly.Css.CONTENT = [
|
||||
'z-index: 50;', /* Display below toolbox, but above everything else. */
|
||||
'}',
|
||||
|
||||
'.blocklyBlockCanvas.blocklyCanvasTransitioning,',
|
||||
'.blocklyBubbleCanvas.blocklyCanvasTransitioning {',
|
||||
'transition: transform .5s;',
|
||||
'}',
|
||||
|
||||
'.blocklyTooltipDiv {',
|
||||
'background-color: #ffffc7;',
|
||||
'border: 1px solid #ddc;',
|
||||
@@ -689,55 +694,28 @@ Blockly.Css.CONTENT = [
|
||||
'color: #fff;',
|
||||
'}',
|
||||
|
||||
/* Copied from: goog/css/colorpicker-simplegrid.css */
|
||||
/*
|
||||
* Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by the Apache License, Version 2.0.
|
||||
* See the COPYING file for details.
|
||||
*/
|
||||
|
||||
/* Author: pupius@google.com (Daniel Pupius) */
|
||||
|
||||
/*
|
||||
Styles to make the colorpicker look like the old gmail color picker
|
||||
NOTE: without CSS scoping this will override styles defined in palette.css
|
||||
*/
|
||||
'.blocklyWidgetDiv .goog-palette {',
|
||||
'outline: none;',
|
||||
'cursor: default;',
|
||||
'}',
|
||||
|
||||
'.blocklyWidgetDiv .goog-palette-table {',
|
||||
'border: 1px solid #666;',
|
||||
/* Colour Picker Field */
|
||||
'.blocklyColourTable {',
|
||||
'border-collapse: collapse;',
|
||||
'}',
|
||||
|
||||
'.blocklyWidgetDiv .goog-palette-cell {',
|
||||
'height: 13px;',
|
||||
'width: 15px;',
|
||||
'margin: 0;',
|
||||
'border: 0;',
|
||||
'text-align: center;',
|
||||
'vertical-align: middle;',
|
||||
'border-right: 1px solid #666;',
|
||||
'font-size: 1px;',
|
||||
'}',
|
||||
|
||||
'.blocklyWidgetDiv .goog-palette-colorswatch {',
|
||||
'position: relative;',
|
||||
'height: 13px;',
|
||||
'width: 15px;',
|
||||
'.blocklyColourTable>tr>td {',
|
||||
'border: 1px solid #666;',
|
||||
'padding: 0;',
|
||||
'}',
|
||||
|
||||
'.blocklyWidgetDiv .goog-palette-cell-hover .goog-palette-colorswatch {',
|
||||
'border: 1px solid #FFF;',
|
||||
'.blocklyColourTable>tr>td>div {',
|
||||
'border: 1px solid #666;',
|
||||
'height: 13px;',
|
||||
'width: 15px;',
|
||||
'}',
|
||||
|
||||
'.blocklyWidgetDiv .goog-palette-cell-selected .goog-palette-colorswatch {',
|
||||
'border: 1px solid #000;',
|
||||
'color: #fff;',
|
||||
'.blocklyColourTable>tr>td>div:hover {',
|
||||
'border: 1px solid #fff;',
|
||||
'}',
|
||||
|
||||
'.blocklyColourSelected, .blocklyColourSelected:hover {',
|
||||
'border: 1px solid #000 !important;',
|
||||
'}',
|
||||
|
||||
/* Copied from: goog/css/menu.css */
|
||||
|
||||
+3
-4
@@ -30,8 +30,7 @@
|
||||
*/
|
||||
goog.provide('Blockly.Events');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
|
||||
/**
|
||||
@@ -193,7 +192,7 @@ Blockly.Events.fireNow_ = function() {
|
||||
* @return {!Array.<!Blockly.Events.Abstract>} Array of filtered events.
|
||||
*/
|
||||
Blockly.Events.filter = function(queueIn, forward) {
|
||||
var queue = goog.array.clone(queueIn);
|
||||
var queue = queueIn.slice(); // Shallow copy of queue.
|
||||
if (!forward) {
|
||||
// Undo is merged in reverse order.
|
||||
queue.reverse();
|
||||
@@ -372,7 +371,7 @@ Blockly.Events.fromJson = function(json, workspace) {
|
||||
event = new Blockly.Events.CommentDelete(null);
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown event type.';
|
||||
throw Error('Unknown event type.');
|
||||
}
|
||||
event.fromJson(json);
|
||||
event.workspaceId = workspace.id;
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
goog.provide('Blockly.Events.Abstract');
|
||||
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
/**
|
||||
* Abstract class for an event.
|
||||
@@ -105,7 +103,7 @@ Blockly.Events.Abstract.prototype.getEventWorkspace_ = function() {
|
||||
var workspace = Blockly.Workspace.getById(this.workspaceId);
|
||||
if (!workspace) {
|
||||
throw Error('Workspace is null. Event must have been generated from real' +
|
||||
' Blockly events.');
|
||||
' Blockly events.');
|
||||
}
|
||||
return workspace;
|
||||
};
|
||||
|
||||
+5
-6
@@ -35,7 +35,6 @@ goog.provide('Blockly.Extensions');
|
||||
|
||||
goog.require('Blockly.Mutator');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('goog.string');
|
||||
|
||||
/**
|
||||
* The set of all registered extensions, keyed by extension name/id.
|
||||
@@ -54,13 +53,13 @@ Blockly.Extensions.ALL_ = {};
|
||||
* registered, or extensionFn is not a function.
|
||||
*/
|
||||
Blockly.Extensions.register = function(name, initFn) {
|
||||
if (!goog.isString(name) || goog.string.isEmptyOrWhitespace(name)) {
|
||||
if ((typeof name != 'string') || (name.trim() == '')) {
|
||||
throw new Error('Error: Invalid extension name "' + name + '"');
|
||||
}
|
||||
if (Blockly.Extensions.ALL_[name]) {
|
||||
throw new Error('Error: Extension "' + name + '" is already registered.');
|
||||
}
|
||||
if (!goog.isFunction(initFn)) {
|
||||
if (typeof initFn != 'function') {
|
||||
throw new Error('Error: Extension "' + name + '" must be a function');
|
||||
}
|
||||
Blockly.Extensions.ALL_[name] = initFn;
|
||||
@@ -74,7 +73,7 @@ Blockly.Extensions.register = function(name, initFn) {
|
||||
* registered.
|
||||
*/
|
||||
Blockly.Extensions.registerMixin = function(name, mixinObj) {
|
||||
if (!goog.isObject(mixinObj)){
|
||||
if (!mixinObj || typeof mixinObj != 'object'){
|
||||
throw new Error('Error: Mixin "' + name + '" must be a object');
|
||||
}
|
||||
Blockly.Extensions.register(name, function() {
|
||||
@@ -108,7 +107,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn,
|
||||
var hasMutatorDialog =
|
||||
Blockly.Extensions.checkMutatorDialog_(mixinObj, errorPrefix);
|
||||
|
||||
if (opt_helperFn && !goog.isFunction(opt_helperFn)) {
|
||||
if (opt_helperFn && (typeof opt_helperFn != 'function')) {
|
||||
throw new Error('Extension "' + name + '" is not a function');
|
||||
}
|
||||
|
||||
@@ -136,7 +135,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn,
|
||||
*/
|
||||
Blockly.Extensions.apply = function(name, block, isMutator) {
|
||||
var extensionFn = Blockly.Extensions.ALL_[name];
|
||||
if (!goog.isFunction(extensionFn)) {
|
||||
if (typeof extensionFn != 'function') {
|
||||
throw new Error('Error: Extension "' + name + '" not found.');
|
||||
}
|
||||
if (isMutator) {
|
||||
|
||||
+25
-14
@@ -30,9 +30,8 @@ goog.provide('Blockly.Field');
|
||||
|
||||
goog.require('Blockly.Events.BlockChange');
|
||||
goog.require('Blockly.Gesture');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math.Size');
|
||||
goog.require('goog.style');
|
||||
goog.require('goog.userAgent');
|
||||
@@ -41,10 +40,8 @@ goog.require('goog.userAgent');
|
||||
/**
|
||||
* Abstract class for an editable field.
|
||||
* @param {string} text The initial content of the field.
|
||||
* @param {Function=} opt_validator An optional function that is called
|
||||
* to validate any constraints on what the user entered. Takes the new
|
||||
* text as an argument and returns either the accepted text, a replacement
|
||||
* text, or null to abort the change.
|
||||
* @param {function(string):(string|null|undefined)=} opt_validator An optional
|
||||
* function that is called to validate user input. See setValidator().
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.Field = function(text, opt_validator) {
|
||||
@@ -71,10 +68,10 @@ Blockly.Field.TYPE_MAP_ = {};
|
||||
* object containing a fromJson function.
|
||||
*/
|
||||
Blockly.Field.register = function(type, fieldClass) {
|
||||
if (!goog.isString(type) || goog.string.isEmptyOrWhitespace(type)) {
|
||||
if ((typeof type != 'string') || (type.trim() == '')) {
|
||||
throw new Error('Invalid field type "' + type + '"');
|
||||
}
|
||||
if (!goog.isObject(fieldClass) || !goog.isFunction(fieldClass.fromJson)) {
|
||||
if (!fieldClass || (typeof fieldClass.fromJson != 'function')) {
|
||||
throw new Error('Field "' + fieldClass +
|
||||
'" must have a fromJson function');
|
||||
}
|
||||
@@ -171,7 +168,9 @@ Blockly.Field.prototype.EDITABLE = true;
|
||||
* @param {!Blockly.Block} block The block containing this field.
|
||||
*/
|
||||
Blockly.Field.prototype.setSourceBlock = function(block) {
|
||||
goog.asserts.assert(!this.sourceBlock_, 'Field already bound to a block.');
|
||||
if (this.sourceBlock_) {
|
||||
throw Error('Field already bound to a block.');
|
||||
}
|
||||
this.sourceBlock_ = block;
|
||||
};
|
||||
|
||||
@@ -226,8 +225,10 @@ Blockly.Field.prototype.dispose = function() {
|
||||
this.mouseDownWrapper_ = null;
|
||||
}
|
||||
this.sourceBlock_ = null;
|
||||
goog.dom.removeNode(this.fieldGroup_);
|
||||
this.fieldGroup_ = null;
|
||||
if (this.fieldGroup_) {
|
||||
this.fieldGroup_.parentNode.removeChild(this.fieldGroup_);
|
||||
this.fieldGroup_ = null;
|
||||
}
|
||||
this.textElement_ = null;
|
||||
this.borderRect_ = null;
|
||||
this.validator_ = null;
|
||||
@@ -288,15 +289,25 @@ Blockly.Field.prototype.setVisible = function(visible) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets a new validation function for editable fields.
|
||||
* @param {Function} handler New validation function, or null.
|
||||
* Sets a new validation function for editable fields, or clears a previously
|
||||
* set validator.
|
||||
*
|
||||
* The validator function takes in the text form of the users input, and
|
||||
* optionally returns the accepted field text. Alternatively, if the function
|
||||
* returns null, the field value change aborts. If the function does not return
|
||||
* anything (or returns undefined), the input value is accepted as valid. This
|
||||
* is a shorthand for fields using the validator function call as a field-level
|
||||
* change event notification.
|
||||
*
|
||||
* @param {?function(string):(string|null|undefined)} handler The validator
|
||||
* function or null to clear a previous validator.
|
||||
*/
|
||||
Blockly.Field.prototype.setValidator = function(handler) {
|
||||
this.validator_ = handler;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the validation function for editable fields.
|
||||
* Gets the validation function for editable fields, or null if not set.
|
||||
* @return {Function} Validation function, or null.
|
||||
*/
|
||||
Blockly.Field.prototype.getValidator = function() {
|
||||
|
||||
+5
-4
@@ -27,7 +27,8 @@
|
||||
goog.provide('Blockly.FieldAngle');
|
||||
|
||||
goog.require('Blockly.FieldTextInput');
|
||||
goog.require('goog.math');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
@@ -231,7 +232,7 @@ Blockly.FieldAngle.prototype.onMouseMove = function(e) {
|
||||
// This shouldn't happen, but let's not let this error propagate further.
|
||||
return;
|
||||
}
|
||||
angle = goog.math.toDegrees(angle);
|
||||
angle = Blockly.utils.toDegrees(angle);
|
||||
// 0: East, 90: North, 180: West, 270: South.
|
||||
if (dx < 0) {
|
||||
angle += 180;
|
||||
@@ -278,12 +279,12 @@ Blockly.FieldAngle.prototype.updateGraph_ = function() {
|
||||
return;
|
||||
}
|
||||
var angleDegrees = Number(this.getText()) + Blockly.FieldAngle.OFFSET;
|
||||
var angleRadians = goog.math.toRadians(angleDegrees);
|
||||
var angleRadians = Blockly.utils.toRadians(angleDegrees);
|
||||
var path = ['M ', Blockly.FieldAngle.HALF, ',', Blockly.FieldAngle.HALF];
|
||||
var x2 = Blockly.FieldAngle.HALF;
|
||||
var y2 = Blockly.FieldAngle.HALF;
|
||||
if (!isNaN(angleRadians)) {
|
||||
var angle1 = goog.math.toRadians(Blockly.FieldAngle.OFFSET);
|
||||
var angle1 = Blockly.utils.toRadians(Blockly.FieldAngle.OFFSET);
|
||||
var x1 = Math.cos(angle1) * Blockly.FieldAngle.RADIUS;
|
||||
var y1 = Math.sin(angle1) * -Blockly.FieldAngle.RADIUS;
|
||||
if (Blockly.FieldAngle.CLOCKWISE) {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
goog.provide('Blockly.FieldCheckbox');
|
||||
|
||||
goog.require('Blockly.Field');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+105
-37
@@ -29,10 +29,7 @@ goog.provide('Blockly.FieldColour');
|
||||
goog.require('Blockly.Field');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.style');
|
||||
goog.require('goog.ui.ColorPicker');
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,13 +61,21 @@ Blockly.FieldColour.fromJson = function(options) {
|
||||
};
|
||||
|
||||
/**
|
||||
* By default use the global constants for colours.
|
||||
* Array of colours used by this field. If null, use the global list.
|
||||
* @type {Array.<string>}
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldColour.prototype.colours_ = null;
|
||||
|
||||
/**
|
||||
* Array of colour tooltips used by this field. If null, use the global list.
|
||||
* @type {Array.<string>}
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldColour.prototype.titles_ = null;
|
||||
|
||||
/**
|
||||
* Number of colour columns used by this field. If 0, use the global setting.
|
||||
* By default use the global constants for columns.
|
||||
* @type {number}
|
||||
* @private
|
||||
@@ -139,14 +144,44 @@ Blockly.FieldColour.prototype.getText = function() {
|
||||
|
||||
/**
|
||||
* An array of colour strings for the palette.
|
||||
* See bottom of this page for the default:
|
||||
* http://docs.closure-library.googlecode.com/git/closure_goog_ui_colorpicker.js.source.html
|
||||
* Copied from goog.ui.ColorPicker.SIMPLE_GRID_COLORS
|
||||
* All colour pickers use this unless overridden with setColours.
|
||||
* @type {!Array.<string>}
|
||||
*/
|
||||
Blockly.FieldColour.COLOURS = goog.ui.ColorPicker.SIMPLE_GRID_COLORS;
|
||||
Blockly.FieldColour.COLOURS = [
|
||||
// grays
|
||||
'#ffffff', '#cccccc', '#c0c0c0', '#999999', '#666666', '#333333', '#000000',
|
||||
// reds
|
||||
'#ffcccc', '#ff6666', '#ff0000', '#cc0000', '#990000', '#660000', '#330000',
|
||||
// oranges
|
||||
'#ffcc99', '#ff9966', '#ff9900', '#ff6600', '#cc6600', '#993300', '#663300',
|
||||
// yellows
|
||||
'#ffff99', '#ffff66', '#ffcc66', '#ffcc33', '#cc9933', '#996633', '#663333',
|
||||
// olives
|
||||
'#ffffcc', '#ffff33', '#ffff00', '#ffcc00', '#999900', '#666600', '#333300',
|
||||
// greens
|
||||
'#99ff99', '#66ff99', '#33ff33', '#33cc00', '#009900', '#006600', '#003300',
|
||||
// turquoises
|
||||
'#99ffff', '#33ffff', '#66cccc', '#00cccc', '#339999', '#336666', '#003333',
|
||||
// blues
|
||||
'#ccffff', '#66ffff', '#33ccff', '#3366ff', '#3333ff', '#000099', '#000066',
|
||||
// purples
|
||||
'#ccccff', '#9999ff', '#6666cc', '#6633ff', '#6600cc', '#333399', '#330099',
|
||||
// violets
|
||||
'#ffccff', '#ff99ff', '#cc66cc', '#cc33cc', '#993399', '#663366', '#330033'
|
||||
];
|
||||
|
||||
/**
|
||||
* An array of tooltip strings for the palette. If not the same length as
|
||||
* COLOURS, the colour's hex code will be used for any missing titles.
|
||||
* All colour pickers use this unless overridden with setColours.
|
||||
* @type {!Array.<string>}
|
||||
*/
|
||||
Blockly.FieldColour.TITLES = [];
|
||||
|
||||
/**
|
||||
* Number of columns in the palette.
|
||||
* All colour pickers use this unless overridden with setColumns.
|
||||
*/
|
||||
Blockly.FieldColour.COLUMNS = 7;
|
||||
|
||||
@@ -154,10 +189,15 @@ Blockly.FieldColour.COLUMNS = 7;
|
||||
* Set a custom colour grid for this field.
|
||||
* @param {Array.<string>} colours Array of colours for this block,
|
||||
* or null to use default (Blockly.FieldColour.COLOURS).
|
||||
* @param {Array.<string>} opt_titles Optional array of colour tooltips,
|
||||
* or null to use default (Blockly.FieldColour.TITLES).
|
||||
* @return {!Blockly.FieldColour} Returns itself (for method chaining).
|
||||
*/
|
||||
Blockly.FieldColour.prototype.setColours = function(colours) {
|
||||
Blockly.FieldColour.prototype.setColours = function(colours, opt_titles) {
|
||||
this.colours_ = colours;
|
||||
if (opt_titles !== undefined) {
|
||||
this.titles_ = opt_titles;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -186,52 +226,80 @@ Blockly.FieldColour.prototype.showEditor_ = function() {
|
||||
|
||||
// Create and add the colour picker, then record the size.
|
||||
var picker = this.createWidget_();
|
||||
var paletteSize = goog.style.getSize(picker.getElement());
|
||||
Blockly.WidgetDiv.DIV.appendChild(picker);
|
||||
var paletteSize = goog.style.getSize(picker);
|
||||
|
||||
// Position the picker to line up with the field.
|
||||
Blockly.WidgetDiv.positionWithAnchor(viewportBBox, anchorBBox, paletteSize,
|
||||
this.sourceBlock_.RTL);
|
||||
|
||||
// Configure event handler.
|
||||
var thisField = this;
|
||||
Blockly.FieldColour.changeEventKey_ = goog.events.listen(picker,
|
||||
goog.ui.ColorPicker.EventType.CHANGE,
|
||||
function(event) {
|
||||
var colour = event.target.getSelectedColor() || '#000000';
|
||||
Blockly.WidgetDiv.hide();
|
||||
if (thisField.sourceBlock_) {
|
||||
// Call any validation function, and allow it to override.
|
||||
colour = thisField.callValidator(colour);
|
||||
}
|
||||
if (colour !== null) {
|
||||
thisField.setValue(colour);
|
||||
}
|
||||
});
|
||||
// Configure event handler on the table to listen for any event in a cell.
|
||||
Blockly.FieldColour.onUpWrapper_ = Blockly.bindEvent_(picker,
|
||||
'mouseup', this, this.onClick_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a color picker widget and render it inside the widget div.
|
||||
* @return {!goog.ui.ColorPicker} The newly created color picker.
|
||||
* Handle a click on a colour cell.
|
||||
* @param {!Event} e Mouse event.
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldColour.prototype.onClick_ = function(e) {
|
||||
var cell = e.target;
|
||||
if (cell && !cell.label) {
|
||||
// The target element is the 'div', back out to the 'td'.
|
||||
cell = cell.parentNode;
|
||||
}
|
||||
var colour = cell && cell.label;
|
||||
Blockly.WidgetDiv.hide();
|
||||
if (this.sourceBlock_) {
|
||||
// Call any validation function, and allow it to override.
|
||||
colour = this.callValidator(colour);
|
||||
}
|
||||
if (colour !== null) {
|
||||
this.setValue(colour);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a colour picker widget.
|
||||
* @return {!Element} The newly created colour picker.
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldColour.prototype.createWidget_ = function() {
|
||||
// Create the palette using Closure.
|
||||
var picker = new goog.ui.ColorPicker();
|
||||
picker.setSize(this.columns_ || Blockly.FieldColour.COLUMNS);
|
||||
picker.setColors(this.colours_ || Blockly.FieldColour.COLOURS);
|
||||
var div = Blockly.WidgetDiv.DIV;
|
||||
picker.render(div);
|
||||
picker.setSelectedColor(this.getValue());
|
||||
return picker;
|
||||
var columns = this.columns_ || Blockly.FieldColour.COLUMNS;
|
||||
var colours = this.colours_ || Blockly.FieldColour.COLOURS;
|
||||
var titles = this.titles_ || Blockly.FieldColour.TITLES;
|
||||
var selectedColour = this.getValue();
|
||||
// Create the palette.
|
||||
var table = document.createElement('table');
|
||||
table.className = 'blocklyColourTable';
|
||||
var row;
|
||||
for (var i = 0; i < colours.length; i++) {
|
||||
if (i % columns == 0) {
|
||||
row = document.createElement('tr');
|
||||
table.appendChild(row);
|
||||
}
|
||||
var cell = document.createElement('td');
|
||||
row.appendChild(cell);
|
||||
var div = document.createElement('div');
|
||||
cell.appendChild(div);
|
||||
cell.label = colours[i]; // This becomes the value, if clicked.
|
||||
cell.title = titles[i] || colours[i];
|
||||
div.style.backgroundColor = colours[i];
|
||||
if (colours[i] == selectedColour) {
|
||||
div.className = 'blocklyColourSelected';
|
||||
}
|
||||
}
|
||||
return table;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the colour palette.
|
||||
* Hide the colour picker widget.
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldColour.widgetDispose_ = function() {
|
||||
if (Blockly.FieldColour.changeEventKey_) {
|
||||
goog.events.unlistenByKey(Blockly.FieldColour.changeEventKey_);
|
||||
if (Blockly.FieldColour.onUpWrapper_) {
|
||||
Blockly.unbindEvent_(Blockly.FieldColour.onUpWrapper_);
|
||||
}
|
||||
Blockly.Events.setGroup(false);
|
||||
};
|
||||
|
||||
@@ -31,7 +31,6 @@ goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.date');
|
||||
goog.require('goog.date.DateTime');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.i18n.DateTimeSymbols');
|
||||
goog.require('goog.i18n.DateTimeSymbols_he');
|
||||
|
||||
+19
-15
@@ -32,9 +32,7 @@ goog.require('Blockly.Field');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.uiMenu');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.style');
|
||||
goog.require('goog.ui.Menu');
|
||||
goog.require('goog.ui.MenuItem');
|
||||
goog.require('goog.userAgent');
|
||||
@@ -53,7 +51,7 @@ goog.require('goog.userAgent');
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.FieldDropdown = function(menuGenerator, opt_validator) {
|
||||
if (!goog.isFunction(menuGenerator)) {
|
||||
if (typeof menuGenerator != 'function') {
|
||||
Blockly.FieldDropdown.validateOptions_(menuGenerator);
|
||||
}
|
||||
this.menuGenerator_ = menuGenerator;
|
||||
@@ -291,7 +289,7 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() {
|
||||
this.prefixField = null;
|
||||
this.suffixField = null;
|
||||
var options = this.menuGenerator_;
|
||||
if (!goog.isArray(options)) {
|
||||
if (!Array.isArray(options)) {
|
||||
return;
|
||||
}
|
||||
var hasImages = false;
|
||||
@@ -362,7 +360,7 @@ Blockly.FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength)
|
||||
* Otherwise false.
|
||||
*/
|
||||
Blockly.FieldDropdown.prototype.isOptionListDynamic = function() {
|
||||
return goog.isFunction(this.menuGenerator_);
|
||||
return typeof this.menuGenerator_ == 'function';
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -372,7 +370,7 @@ Blockly.FieldDropdown.prototype.isOptionListDynamic = function() {
|
||||
* @throws If generated options are incorrectly structured.
|
||||
*/
|
||||
Blockly.FieldDropdown.prototype.getOptions = function() {
|
||||
if (goog.isFunction(this.menuGenerator_)) {
|
||||
if (this.isOptionListDynamic()) {
|
||||
var generatedOptions = this.menuGenerator_.call(this);
|
||||
Blockly.FieldDropdown.validateOptions_(generatedOptions);
|
||||
return generatedOptions;
|
||||
@@ -438,9 +436,14 @@ Blockly.FieldDropdown.prototype.render_ = function() {
|
||||
// Update arrow's colour.
|
||||
this.arrow_.style.fill = this.sourceBlock_.getColour();
|
||||
}
|
||||
goog.dom.removeChildren(/** @type {!Element} */ (this.textElement_));
|
||||
goog.dom.removeNode(this.imageElement_);
|
||||
this.imageElement_ = null;
|
||||
var child;
|
||||
while ((child = this.textElement_.firstChild)) {
|
||||
this.textElement_.removeChild(child);
|
||||
}
|
||||
if (this.imageElement_) {
|
||||
this.imageElement_.parentNode.removeChild(this.imageElement_);
|
||||
this.imageElement_ = null;
|
||||
}
|
||||
|
||||
if (this.imageJson_) {
|
||||
this.renderSelectedImage_();
|
||||
@@ -537,23 +540,24 @@ Blockly.FieldDropdown.prototype.dispose = function() {
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldDropdown.validateOptions_ = function(options) {
|
||||
if (!goog.isArray(options)) {
|
||||
throw 'FieldDropdown options must be an array.';
|
||||
if (!Array.isArray(options)) {
|
||||
throw TypeError('FieldDropdown options must be an array.');
|
||||
}
|
||||
var foundError = false;
|
||||
for (var i = 0; i < options.length; ++i) {
|
||||
var tuple = options[i];
|
||||
if (!goog.isArray(options)) {
|
||||
if (!Array.isArray(options)) {
|
||||
foundError = true;
|
||||
console.error(
|
||||
'Invalid option[' + i + ']: Each FieldDropdown option must be an ' +
|
||||
'array. Found: ', tuple);
|
||||
} else if (!goog.isString(tuple[1])) {
|
||||
} else if (typeof tuple[1] != 'string') {
|
||||
foundError = true;
|
||||
console.error(
|
||||
'Invalid option[' + i + ']: Each FieldDropdown option id must be ' +
|
||||
'a string. Found ' + tuple[1] + ' in: ', tuple);
|
||||
} else if (!goog.isString(tuple[0]) && !goog.isString(tuple[0].src)) {
|
||||
} else if ((typeof tuple[0] != 'string') &&
|
||||
(typeof tuple[0].src != 'string')) {
|
||||
foundError = true;
|
||||
console.error(
|
||||
'Invalid option[' + i + ']: Each FieldDropdown option must have a ' +
|
||||
@@ -562,7 +566,7 @@ Blockly.FieldDropdown.validateOptions_ = function(options) {
|
||||
}
|
||||
}
|
||||
if (foundError) {
|
||||
throw 'Found invalid FieldDropdown options.';
|
||||
throw TypeError('Found invalid FieldDropdown options.');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+6
-3
@@ -27,7 +27,8 @@
|
||||
goog.provide('Blockly.FieldImage');
|
||||
|
||||
goog.require('Blockly.Field');
|
||||
goog.require('goog.dom');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Size');
|
||||
|
||||
|
||||
@@ -118,8 +119,10 @@ Blockly.FieldImage.prototype.init = function() {
|
||||
* Dispose of all DOM objects belonging to this text.
|
||||
*/
|
||||
Blockly.FieldImage.prototype.dispose = function() {
|
||||
goog.dom.removeNode(this.fieldGroup_);
|
||||
this.fieldGroup_ = null;
|
||||
if (this.fieldGroup_) {
|
||||
this.fieldGroup_.parentNode.removeChild(this.fieldGroup_);
|
||||
this.fieldGroup_ = null;
|
||||
}
|
||||
this.imageElement_ = null;
|
||||
};
|
||||
|
||||
|
||||
+6
-3
@@ -28,7 +28,8 @@ goog.provide('Blockly.FieldLabel');
|
||||
|
||||
goog.require('Blockly.Field');
|
||||
goog.require('Blockly.Tooltip');
|
||||
goog.require('goog.dom');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Size');
|
||||
|
||||
|
||||
@@ -94,8 +95,10 @@ Blockly.FieldLabel.prototype.init = function() {
|
||||
* Dispose of all DOM objects belonging to this text.
|
||||
*/
|
||||
Blockly.FieldLabel.prototype.dispose = function() {
|
||||
goog.dom.removeNode(this.textElement_);
|
||||
this.textElement_ = null;
|
||||
if (this.textElement_) {
|
||||
this.textElement_.parentNode.removeChild(this.textElement_);
|
||||
this.textElement_ = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
goog.provide('Blockly.FieldNumber');
|
||||
|
||||
goog.require('Blockly.FieldTextInput');
|
||||
goog.require('goog.math');
|
||||
|
||||
|
||||
/**
|
||||
@@ -112,7 +111,7 @@ Blockly.FieldNumber.prototype.classValidator = function(text) {
|
||||
n = Math.round(n / this.precision_) * this.precision_;
|
||||
}
|
||||
// Get the value in range.
|
||||
n = goog.math.clamp(n, this.min_, this.max_);
|
||||
n = Math.min(Math.max(n, this.min_), this.max_);
|
||||
return String(n);
|
||||
};
|
||||
|
||||
|
||||
+22
-16
@@ -28,9 +28,9 @@ goog.provide('Blockly.FieldTextInput');
|
||||
|
||||
goog.require('Blockly.Field');
|
||||
goog.require('Blockly.Msg');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
@@ -106,18 +106,17 @@ Blockly.FieldTextInput.prototype.dispose = function() {
|
||||
* @override
|
||||
*/
|
||||
Blockly.FieldTextInput.prototype.setValue = function(newValue) {
|
||||
if (newValue === null) {
|
||||
return; // No change if null.
|
||||
}
|
||||
if (this.sourceBlock_) {
|
||||
var validated = this.callValidator(newValue);
|
||||
// If the new value is invalid, validation returns null.
|
||||
// In this case we still want to display the illegal result.
|
||||
if (validated !== null) {
|
||||
newValue = validated;
|
||||
if (newValue !== null) { // No change if null.
|
||||
if (this.sourceBlock_) {
|
||||
var validated = this.callValidator(newValue);
|
||||
// If the new value is invalid, validation returns null.
|
||||
// In this case we still want to display the illegal result.
|
||||
if (validated !== null) {
|
||||
newValue = validated;
|
||||
}
|
||||
}
|
||||
Blockly.Field.prototype.setValue.call(this, newValue);
|
||||
}
|
||||
Blockly.Field.prototype.setValue.call(this, newValue);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -192,8 +191,8 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) {
|
||||
Blockly.WidgetDiv.show(this, this.sourceBlock_.RTL, this.widgetDispose_());
|
||||
var div = Blockly.WidgetDiv.DIV;
|
||||
// Create the input.
|
||||
var htmlInput =
|
||||
goog.dom.createDom(goog.dom.TagName.INPUT, 'blocklyHtmlInput');
|
||||
var htmlInput = document.createElement('input');
|
||||
htmlInput.className = 'blocklyHtmlInput';
|
||||
htmlInput.setAttribute('spellcheck', this.spellcheck_);
|
||||
var fontSize =
|
||||
(Blockly.FieldTextInput.FONTSIZE * this.workspace_.scale) + 'pt';
|
||||
@@ -300,7 +299,9 @@ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) {
|
||||
*/
|
||||
Blockly.FieldTextInput.prototype.validate_ = function() {
|
||||
var valid = true;
|
||||
goog.asserts.assertObject(Blockly.FieldTextInput.htmlInput_);
|
||||
if (!Blockly.FieldTextInput.htmlInput_) {
|
||||
throw Error('htmlInput not defined');
|
||||
}
|
||||
var htmlInput = Blockly.FieldTextInput.htmlInput_;
|
||||
if (this.sourceBlock_) {
|
||||
valid = this.callValidator(htmlInput.value);
|
||||
@@ -367,6 +368,11 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempt to save the text field changes when the user input loses focus.
|
||||
* If the value is not valid, revert to the default value.
|
||||
* @private
|
||||
*/
|
||||
Blockly.FieldTextInput.prototype.maybeSaveEdit_ = function() {
|
||||
var htmlInput = Blockly.FieldTextInput.htmlInput_;
|
||||
// Save the edit (if it validates).
|
||||
|
||||
@@ -28,10 +28,11 @@ goog.provide('Blockly.FieldVariable');
|
||||
|
||||
goog.require('Blockly.FieldDropdown');
|
||||
goog.require('Blockly.Msg');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.VariableModel');
|
||||
goog.require('Blockly.Variables');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.string');
|
||||
|
||||
goog.require('goog.math.Size');
|
||||
|
||||
|
||||
/**
|
||||
@@ -132,8 +133,9 @@ Blockly.FieldVariable.prototype.dispose = function() {
|
||||
* @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.');
|
||||
if (block.isShadow()) {
|
||||
throw Error('Variable fields are not allowed to exist on shadow blocks.');
|
||||
}
|
||||
Blockly.FieldVariable.superClass_.setSourceBlock.call(this, block);
|
||||
};
|
||||
|
||||
|
||||
+12
-10
@@ -33,9 +33,9 @@ goog.require('Blockly.Events.VarCreate');
|
||||
goog.require('Blockly.FlyoutButton');
|
||||
goog.require('Blockly.Gesture');
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.WorkspaceSvg');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
|
||||
goog.require('goog.math.Rect');
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ Blockly.Flyout.prototype.dispose = function() {
|
||||
this.workspace_ = null;
|
||||
}
|
||||
if (this.svgGroup_) {
|
||||
goog.dom.removeNode(this.svgGroup_);
|
||||
this.svgGroup_.parentNode.removeChild(this.svgGroup_);
|
||||
this.svgGroup_ = null;
|
||||
}
|
||||
this.svgBackground_ = null;
|
||||
@@ -426,11 +426,13 @@ Blockly.Flyout.prototype.show = function(xmlList) {
|
||||
if (typeof xmlList == 'string') {
|
||||
var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback(
|
||||
xmlList);
|
||||
goog.asserts.assert(goog.isFunction(fnToApply),
|
||||
'Couldn\'t find a callback function when opening a toolbox category.');
|
||||
if (typeof fnToApply != 'function') {
|
||||
throw TypeError('Couldn\'t find a callback function when opening a toolbox category.');
|
||||
}
|
||||
xmlList = fnToApply(this.workspace_.targetWorkspace);
|
||||
goog.asserts.assert(goog.isArray(xmlList),
|
||||
'The result of a toolbox category callback must be an array.');
|
||||
if (!Array.isArray(xmlList)) {
|
||||
throw TypeError('Result of toolbox category callback must be an array.');
|
||||
}
|
||||
}
|
||||
|
||||
this.setVisible(true);
|
||||
@@ -524,7 +526,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() {
|
||||
for (var j = 0; j < this.mats_.length; j++) {
|
||||
var rect = this.mats_[j];
|
||||
if (rect) {
|
||||
goog.dom.removeNode(rect);
|
||||
rect.parentNode.removeChild(rect);
|
||||
}
|
||||
}
|
||||
this.mats_.length = 0;
|
||||
@@ -762,7 +764,7 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) {
|
||||
var targetWorkspace = this.targetWorkspace_;
|
||||
var svgRootOld = oldBlock.getSvgRoot();
|
||||
if (!svgRootOld) {
|
||||
throw 'oldBlock is not rendered.';
|
||||
throw Error('oldBlock is not rendered.');
|
||||
}
|
||||
|
||||
// Create the new block by cloning the block in the flyout (via XML).
|
||||
@@ -776,7 +778,7 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) {
|
||||
var block = Blockly.Xml.domToBlock(xml, targetWorkspace);
|
||||
var svgRootNew = block.getSvgRoot();
|
||||
if (!svgRootNew) {
|
||||
throw 'block is not rendered.';
|
||||
throw Error('block is not rendered.');
|
||||
}
|
||||
|
||||
// The offset in pixels between the main workspace's origin and the upper left
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
|
||||
goog.provide('Blockly.FlyoutButton');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
@@ -238,7 +239,7 @@ Blockly.FlyoutButton.prototype.dispose = function() {
|
||||
Blockly.unbindEvent_(this.onMouseUpWrapper_);
|
||||
}
|
||||
if (this.svgGroup_) {
|
||||
goog.dom.removeNode(this.svgGroup_);
|
||||
this.svgGroup_.parentNode.removeChild(this.svgGroup_);
|
||||
this.svgGroup_ = null;
|
||||
}
|
||||
this.workspace_ = null;
|
||||
|
||||
@@ -28,9 +28,6 @@ goog.provide('Blockly.FlyoutDragger');
|
||||
|
||||
goog.require('Blockly.WorkspaceDragger');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
* Class for a flyout dragger. It moves a flyout workspace around when it is
|
||||
|
||||
@@ -31,8 +31,7 @@ goog.require('Blockly.Events');
|
||||
goog.require('Blockly.FlyoutButton');
|
||||
goog.require('Blockly.Flyout');
|
||||
goog.require('Blockly.WorkspaceSvg');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
|
||||
goog.require('goog.math.Rect');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
@@ -126,7 +125,7 @@ Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (goog.isNumber(xyRatio.x)) {
|
||||
if (typeof xyRatio.x == 'number') {
|
||||
this.workspace_.scrollX = -metrics.contentWidth * xyRatio.x;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,8 @@ goog.require('Blockly.Block');
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Flyout');
|
||||
goog.require('Blockly.FlyoutButton');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.WorkspaceSvg');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
|
||||
goog.require('goog.math.Rect');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
@@ -125,7 +123,7 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) {
|
||||
if (!metrics) {
|
||||
return;
|
||||
}
|
||||
if (goog.isNumber(xyRatio.y)) {
|
||||
if (typeof xyRatio.y == 'number') {
|
||||
this.workspace_.scrollY = -metrics.contentHeight * xyRatio.y;
|
||||
}
|
||||
this.workspace_.translate(this.workspace_.scrollX + metrics.absoluteLeft,
|
||||
|
||||
+21
-18
@@ -28,7 +28,6 @@
|
||||
goog.provide('Blockly.Generator');
|
||||
|
||||
goog.require('Blockly.Block');
|
||||
goog.require('goog.asserts');
|
||||
|
||||
|
||||
/**
|
||||
@@ -99,7 +98,7 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) {
|
||||
var blocks = workspace.getTopBlocks(true);
|
||||
for (var x = 0, block; block = blocks[x]; x++) {
|
||||
var line = this.blockToCode(block);
|
||||
if (goog.isArray(line)) {
|
||||
if (Array.isArray(line)) {
|
||||
// Value blocks return tuples of code and operator order.
|
||||
// Top-level blocks don't care about operator order.
|
||||
line = line[0];
|
||||
@@ -173,31 +172,32 @@ Blockly.Generator.prototype.blockToCode = function(block) {
|
||||
}
|
||||
|
||||
var func = this[block.type];
|
||||
goog.asserts.assertFunction(func,
|
||||
'Language "%s" does not know how to generate code for block type "%s".',
|
||||
this.name_, block.type);
|
||||
if (typeof func != 'function') {
|
||||
throw Error('Language "' + this.name_ + '" does not know how to generate ' +
|
||||
' code for block type "' + block.type + '".');
|
||||
}
|
||||
// First argument to func.call is the value of 'this' in the generator.
|
||||
// Prior to 24 September 2013 'this' was the only way to access the block.
|
||||
// The current prefered method of accessing the block is through the second
|
||||
// argument to func.call, which becomes the first parameter to the generator.
|
||||
var code = func.call(block, block);
|
||||
if (goog.isArray(code)) {
|
||||
if (Array.isArray(code)) {
|
||||
// Value blocks return tuples of code and operator order.
|
||||
goog.asserts.assert(block.outputConnection,
|
||||
'Expecting string from statement block "%s".', block.type);
|
||||
if (!block.outputConnection) {
|
||||
throw TypeError('Expecting string from statement block: ' + block.type);
|
||||
}
|
||||
return [this.scrub_(block, code[0]), code[1]];
|
||||
} else if (goog.isString(code)) {
|
||||
} else if (typeof code == 'string') {
|
||||
var id = block.id.replace(/\$/g, '$$$$'); // Issue 251.
|
||||
if (this.STATEMENT_PREFIX) {
|
||||
code = this.STATEMENT_PREFIX.replace(/%1/g, '\'' + id + '\'') +
|
||||
code;
|
||||
code = this.STATEMENT_PREFIX.replace(/%1/g, '\'' + id + '\'') + code;
|
||||
}
|
||||
return this.scrub_(block, code);
|
||||
} else if (code === null) {
|
||||
// Block has handled code generation itself.
|
||||
return '';
|
||||
} else {
|
||||
goog.asserts.fail('Invalid code generated: %s', code);
|
||||
throw SyntaxError('Invalid code generated: ' + code);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -212,7 +212,7 @@ Blockly.Generator.prototype.blockToCode = function(block) {
|
||||
*/
|
||||
Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) {
|
||||
if (isNaN(outerOrder)) {
|
||||
goog.asserts.fail('Expecting valid order from block "%s".', block.type);
|
||||
throw TypeError('Expecting valid order from block: ' + block.type);
|
||||
}
|
||||
var targetBlock = block.getInputTargetBlock(name);
|
||||
if (!targetBlock) {
|
||||
@@ -225,12 +225,13 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) {
|
||||
}
|
||||
// Value blocks must return code and order of operations info.
|
||||
// Statement blocks must only return code.
|
||||
goog.asserts.assertArray(tuple, 'Expecting tuple from value block "%s".',
|
||||
targetBlock.type);
|
||||
if (!Array.isArray(tuple)) {
|
||||
throw TypeError('Expecting tuple from value block: ' + targetBlock.type);
|
||||
}
|
||||
var code = tuple[0];
|
||||
var innerOrder = tuple[1];
|
||||
if (isNaN(innerOrder)) {
|
||||
goog.asserts.fail('Expecting valid order from value block "%s".',
|
||||
throw TypeError('Expecting valid order from value block: ' +
|
||||
targetBlock.type);
|
||||
}
|
||||
if (!code) {
|
||||
@@ -282,8 +283,10 @@ Blockly.Generator.prototype.statementToCode = function(block, name) {
|
||||
var code = this.blockToCode(targetBlock);
|
||||
// Value blocks must return code and order of operations info.
|
||||
// Statement blocks must only return code.
|
||||
goog.asserts.assertString(code, 'Expecting code from statement block "%s".',
|
||||
targetBlock && targetBlock.type);
|
||||
if (typeof code != 'string') {
|
||||
throw TypeError('Expecting code from statement block: ' +
|
||||
(targetBlock && targetBlock.type));
|
||||
}
|
||||
if (code) {
|
||||
code = this.prefixLines(/** @type {string} */ (code), this.INDENT);
|
||||
}
|
||||
|
||||
+27
-20
@@ -35,9 +35,9 @@ goog.require('Blockly.Events.Ui');
|
||||
goog.require('Blockly.FlyoutDragger');
|
||||
goog.require('Blockly.Tooltip');
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.WorkspaceDragger');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
@@ -429,8 +429,9 @@ Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() {
|
||||
*/
|
||||
Blockly.Gesture.prototype.updateIsDragging_ = function() {
|
||||
// Sanity check.
|
||||
goog.asserts.assert(!this.calledUpdateIsDragging_,
|
||||
'updateIsDragging_ should only be called once per gesture.');
|
||||
if (this.calledUpdateIsDragging_) {
|
||||
throw Error('updateIsDragging_ should only be called once per gesture.');
|
||||
}
|
||||
this.calledUpdateIsDragging_ = true;
|
||||
|
||||
// First check if it was a bubble drag. Bubbles always sit on top of blocks.
|
||||
@@ -505,8 +506,9 @@ Blockly.Gesture.prototype.doStart = function(e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (goog.string.caseInsensitiveEquals(e.type, 'touchstart') ||
|
||||
(goog.string.caseInsensitiveEquals(e.type, 'pointerdown') && e.pointerType != 'mouse')) {
|
||||
if ((e.type.toLowerCase() == 'touchstart' ||
|
||||
e.type.toLowerCase() == 'pointerdown') &&
|
||||
e.pointerType != 'mouse') {
|
||||
Blockly.longStart_(e, this);
|
||||
}
|
||||
|
||||
@@ -648,9 +650,10 @@ Blockly.Gesture.prototype.handleRightClick = function(e) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.Gesture.prototype.handleWsStart = function(e, ws) {
|
||||
goog.asserts.assert(!this.hasStarted_,
|
||||
'Tried to call gesture.handleWsStart, but the gesture had already been ' +
|
||||
'started.');
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.handleWsStart, ' +
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
this.setStartWorkspace_(ws);
|
||||
this.mostRecentEvent_ = e;
|
||||
this.doStart(e);
|
||||
@@ -663,9 +666,10 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) {
|
||||
goog.asserts.assert(!this.hasStarted_,
|
||||
'Tried to call gesture.handleFlyoutStart, but the gesture had already ' +
|
||||
'been started.');
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.handleFlyoutStart, ' +
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
this.setStartFlyout_(flyout);
|
||||
this.handleWsStart(e, flyout.getWorkspace());
|
||||
};
|
||||
@@ -677,9 +681,10 @@ Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.Gesture.prototype.handleBlockStart = function(e, block) {
|
||||
goog.asserts.assert(!this.hasStarted_,
|
||||
'Tried to call gesture.handleBlockStart, but the gesture had already ' +
|
||||
'been started.');
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.handleBlockStart, ' +
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
this.setStartBlock(block);
|
||||
this.mostRecentEvent_ = e;
|
||||
};
|
||||
@@ -691,9 +696,10 @@ Blockly.Gesture.prototype.handleBlockStart = function(e, block) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) {
|
||||
goog.asserts.assert(!this.hasStarted_,
|
||||
'Tried to call gesture.handleBubbleStart, but the gesture had already ' +
|
||||
'been started.');
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.handleBubbleStart, ' +
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
this.setStartBubble(bubble);
|
||||
this.mostRecentEvent_ = e;
|
||||
};
|
||||
@@ -779,9 +785,10 @@ Blockly.Gesture.prototype.bringBlockToFront_ = function() {
|
||||
* @package
|
||||
*/
|
||||
Blockly.Gesture.prototype.setStartField = function(field) {
|
||||
goog.asserts.assert(!this.hasStarted_,
|
||||
'Tried to call gesture.setStartField, but the gesture had already been ' +
|
||||
'started.');
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.setStartField, ' +
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
if (!this.startField_) {
|
||||
this.startField_ = field;
|
||||
}
|
||||
|
||||
+3
-2
@@ -26,7 +26,8 @@
|
||||
|
||||
goog.provide('Blockly.Icon');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
@@ -95,7 +96,7 @@ Blockly.Icon.prototype.createIcon = function() {
|
||||
*/
|
||||
Blockly.Icon.prototype.dispose = function() {
|
||||
// Dispose of and unlink the icon.
|
||||
goog.dom.removeNode(this.iconGroup_);
|
||||
this.iconGroup_.parentNode.removeChild(this.iconGroup_);
|
||||
this.iconGroup_ = null;
|
||||
// Dispose of and unlink the bubble.
|
||||
this.setVisible(false);
|
||||
|
||||
+8
-6
@@ -30,9 +30,10 @@ goog.require('Blockly.BlockDragSurfaceSvg');
|
||||
goog.require('Blockly.Css');
|
||||
goog.require('Blockly.Grid');
|
||||
goog.require('Blockly.Options');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.WorkspaceSvg');
|
||||
goog.require('Blockly.WorkspaceDragSurfaceSvg');
|
||||
goog.require('goog.dom');
|
||||
|
||||
goog.require('goog.ui.Component');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
@@ -47,16 +48,17 @@ goog.require('goog.userAgent');
|
||||
Blockly.inject = function(container, opt_options) {
|
||||
Blockly.checkBlockColourConstants();
|
||||
|
||||
if (goog.isString(container)) {
|
||||
if (typeof container == 'string') {
|
||||
container = document.getElementById(container) ||
|
||||
document.querySelector(container);
|
||||
}
|
||||
// Verify that the container is in document.
|
||||
if (!goog.dom.contains(document, container)) {
|
||||
throw 'Error: container is not in current document.';
|
||||
if (!Blockly.utils.containsNode(document, container)) {
|
||||
throw Error('Error: container is not in current document.');
|
||||
}
|
||||
var options = new Blockly.Options(opt_options || {});
|
||||
var subContainer = goog.dom.createDom(goog.dom.TagName.DIV, 'injectionDiv');
|
||||
var subContainer = document.createElement('div');
|
||||
subContainer.className = 'injectionDiv';
|
||||
container.appendChild(subContainer);
|
||||
var svg = Blockly.createDom_(subContainer, options);
|
||||
|
||||
@@ -212,7 +214,7 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, workspac
|
||||
if (!options.hasCategories && options.languageTree) {
|
||||
// Add flyout as an <svg> that is a sibling of the workspace svg.
|
||||
var flyout = mainWorkspace.addFlyout_('svg');
|
||||
Blockly.utils.insertAfter_(flyout, svg);
|
||||
Blockly.utils.insertAfter(flyout, svg);
|
||||
}
|
||||
|
||||
// A null translation will also apply the correct initial scale.
|
||||
|
||||
+5
-6
@@ -28,7 +28,6 @@ goog.provide('Blockly.Input');
|
||||
|
||||
goog.require('Blockly.Connection');
|
||||
goog.require('Blockly.FieldLabel');
|
||||
goog.require('goog.asserts');
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,7 +41,7 @@ goog.require('goog.asserts');
|
||||
*/
|
||||
Blockly.Input = function(type, name, block, connection) {
|
||||
if (type != Blockly.DUMMY_INPUT && !name) {
|
||||
throw 'Value inputs and statement inputs must have non-empty name.';
|
||||
throw Error('Value inputs and statement inputs must have non-empty name.');
|
||||
}
|
||||
/** @type {number} */
|
||||
this.type = type;
|
||||
@@ -104,7 +103,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) {
|
||||
return index;
|
||||
}
|
||||
// Generate a FieldLabel when given a plain text field.
|
||||
if (goog.isString(field)) {
|
||||
if (typeof field == 'string') {
|
||||
field = new Blockly.FieldLabel(/** @type {string} */ (field));
|
||||
}
|
||||
field.setSourceBlock(this.sourceBlock_);
|
||||
@@ -136,7 +135,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) {
|
||||
/**
|
||||
* Remove a field from this input.
|
||||
* @param {string} name The name of the field.
|
||||
* @throws {goog.asserts.AssertionError} if the field is not present.
|
||||
* @throws {Error} if the field is not present.
|
||||
*/
|
||||
Blockly.Input.prototype.removeField = function(name) {
|
||||
for (var i = 0, field; field = this.fieldRow[i]; i++) {
|
||||
@@ -151,7 +150,7 @@ Blockly.Input.prototype.removeField = function(name) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
goog.asserts.fail('Field "%s" not found.', name);
|
||||
throw Error('Field "%s" not found.', name);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -205,7 +204,7 @@ Blockly.Input.prototype.setVisible = function(visible) {
|
||||
*/
|
||||
Blockly.Input.prototype.setCheck = function(check) {
|
||||
if (!this.connection) {
|
||||
throw 'This input does not have a connection.';
|
||||
throw Error('This input does not have a connection.');
|
||||
}
|
||||
this.connection.setCheck(check);
|
||||
return this;
|
||||
|
||||
@@ -31,7 +31,9 @@ goog.require('Blockly.Bubble');
|
||||
goog.require('Blockly.Events.BlockChange');
|
||||
goog.require('Blockly.Events.Ui');
|
||||
goog.require('Blockly.Icon');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.WorkspaceSvg');
|
||||
|
||||
goog.require('goog.dom');
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ goog.require('Blockly.Field');
|
||||
goog.require('Blockly.Names');
|
||||
goog.require('Blockly.Workspace');
|
||||
|
||||
goog.require('goog.dom');
|
||||
|
||||
|
||||
/**
|
||||
* Constant to separate procedure names from variables and generated functions
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
goog.provide('Blockly.RenderedConnection');
|
||||
|
||||
goog.require('Blockly.Connection');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
@@ -166,7 +169,7 @@ Blockly.RenderedConnection.prototype.tighten_ = function() {
|
||||
var block = this.targetBlock();
|
||||
var svgRoot = block.getSvgRoot();
|
||||
if (!svgRoot) {
|
||||
throw 'block is not rendered.';
|
||||
throw Error('block is not rendered.');
|
||||
}
|
||||
// Workspace coordinates.
|
||||
var xy = Blockly.utils.getRelativeXY(svgRoot);
|
||||
@@ -259,7 +262,7 @@ Blockly.RenderedConnection.prototype.unhideAll = function() {
|
||||
* Remove the highlighting around this connection.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.unhighlight = function() {
|
||||
goog.dom.removeNode(Blockly.Connection.highlightedPath_);
|
||||
Blockly.Connection.highlightedPath_.parentNode.removeChild(Blockly.Connection.highlightedPath_);
|
||||
delete Blockly.Connection.highlightedPath_;
|
||||
};
|
||||
|
||||
@@ -351,7 +354,7 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() {
|
||||
Blockly.RenderedConnection.superClass_.respawnShadow_.call(this);
|
||||
var blockShadow = this.targetBlock();
|
||||
if (!blockShadow) {
|
||||
throw 'Couldn\'t respawn the shadow block that should exist here.';
|
||||
throw Error('Couldn\'t respawn the shadow block that should exist here.');
|
||||
}
|
||||
blockShadow.initSvg();
|
||||
blockShadow.render(false);
|
||||
|
||||
+9
-7
@@ -27,8 +27,10 @@
|
||||
goog.provide('Blockly.Scrollbar');
|
||||
goog.provide('Blockly.ScrollbarPair');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.events.BrowserFeature');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,7 +57,7 @@ Blockly.ScrollbarPair = function(workspace) {
|
||||
'class': 'blocklyScrollbarBackground'
|
||||
},
|
||||
null);
|
||||
Blockly.utils.insertAfter_(this.corner_, workspace.getBubbleCanvas());
|
||||
Blockly.utils.insertAfter(this.corner_, workspace.getBubbleCanvas());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -70,7 +72,7 @@ Blockly.ScrollbarPair.prototype.oldHostMetrics_ = null;
|
||||
* Unlink from all DOM elements to prevent memory leaks.
|
||||
*/
|
||||
Blockly.ScrollbarPair.prototype.dispose = function() {
|
||||
goog.dom.removeNode(this.corner_);
|
||||
this.corner_.parentNode.removeChild(this.corner_);
|
||||
this.corner_ = null;
|
||||
this.workspace_ = null;
|
||||
this.oldHostMetrics_ = null;
|
||||
@@ -345,7 +347,7 @@ Blockly.Scrollbar.prototype.dispose = function() {
|
||||
Blockly.unbindEvent_(this.onMouseDownHandleWrapper_);
|
||||
this.onMouseDownHandleWrapper_ = null;
|
||||
|
||||
goog.dom.removeNode(this.outerSvg_);
|
||||
this.outerSvg_.parentNode.removeChild(this.outerSvg_);
|
||||
this.outerSvg_ = null;
|
||||
this.svgGroup_ = null;
|
||||
this.svgBackground_ = null;
|
||||
@@ -623,7 +625,7 @@ Blockly.Scrollbar.prototype.createDom_ = function(opt_class) {
|
||||
'ry': radius
|
||||
},
|
||||
this.svgGroup_);
|
||||
Blockly.utils.insertAfter_(this.outerSvg_, this.workspace_.getParentSvg());
|
||||
Blockly.utils.insertAfter(this.outerSvg_, this.workspace_.getParentSvg());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -660,7 +662,7 @@ Blockly.Scrollbar.prototype.setVisible = function(visible) {
|
||||
// Ideally this would also apply to scrollbar pairs, but that's a bigger
|
||||
// headache (due to interactions with the corner square).
|
||||
if (this.pair_) {
|
||||
throw 'Unable to toggle visibility of paired scrollbars.';
|
||||
throw Error('Unable to toggle visibility of paired scrollbars.');
|
||||
}
|
||||
this.isVisible_ = visible;
|
||||
if (visibilityChanged) {
|
||||
|
||||
+10
-8
@@ -30,9 +30,9 @@ goog.require('Blockly.Events.Ui');
|
||||
goog.require('Blockly.Flyout');
|
||||
goog.require('Blockly.HorizontalFlyout');
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.VerticalFlyout');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.BrowserFeature');
|
||||
goog.require('goog.html.SafeHtml');
|
||||
@@ -155,8 +155,8 @@ Blockly.Toolbox.prototype.init = function() {
|
||||
* HTML container for the Toolbox menu.
|
||||
* @type {Element}
|
||||
*/
|
||||
this.HtmlDiv =
|
||||
goog.dom.createDom(goog.dom.TagName.DIV, 'blocklyToolboxDiv');
|
||||
this.HtmlDiv = document.createElement('div');
|
||||
this.HtmlDiv.className = 'blocklyToolboxDiv';
|
||||
this.HtmlDiv.setAttribute('dir', workspace.RTL ? 'RTL' : 'LTR');
|
||||
svg.parentNode.insertBefore(this.HtmlDiv, svg);
|
||||
|
||||
@@ -190,8 +190,9 @@ Blockly.Toolbox.prototype.init = function() {
|
||||
} else {
|
||||
this.flyout_ = new Blockly.VerticalFlyout(workspaceOptions);
|
||||
}
|
||||
goog.dom.insertSiblingAfter(
|
||||
this.flyout_.createDom('svg'), this.workspace_.getParentSvg());
|
||||
// Insert the flyout after the workspace.
|
||||
Blockly.utils.insertAfter(this.flyout_.createDom('svg'),
|
||||
this.workspace_.getParentSvg());
|
||||
this.flyout_.init(workspace);
|
||||
|
||||
this.config_['cleardotPath'] = workspace.options.pathToMedia + '1x1.gif';
|
||||
@@ -218,7 +219,7 @@ Blockly.Toolbox.prototype.init = function() {
|
||||
Blockly.Toolbox.prototype.dispose = function() {
|
||||
this.flyout_.dispose();
|
||||
this.tree_.dispose();
|
||||
goog.dom.removeNode(this.HtmlDiv);
|
||||
this.HtmlDiv.parentNode.removeChild(this.HtmlDiv);
|
||||
this.workspace_ = null;
|
||||
this.lastCategory_ = null;
|
||||
};
|
||||
@@ -286,7 +287,8 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
|
||||
this.syncTrees_(newTree, this.tree_, this.workspace_.options.pathToMedia);
|
||||
|
||||
if (this.tree_.blocks.length) {
|
||||
throw 'Toolbox cannot have both blocks and categories in the root level.';
|
||||
throw Error('Toolbox cannot have both blocks and categories ' +
|
||||
'in the root level.');
|
||||
}
|
||||
|
||||
// Fire a resize event since the toolbox may have changed width and height.
|
||||
|
||||
+8
-6
@@ -35,8 +35,9 @@
|
||||
**/
|
||||
goog.provide('Blockly.Tooltip');
|
||||
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
|
||||
|
||||
/**
|
||||
@@ -132,8 +133,8 @@ Blockly.Tooltip.createDom = function() {
|
||||
return; // Already created.
|
||||
}
|
||||
// Create an HTML container for popup overlays (e.g. editor widgets).
|
||||
Blockly.Tooltip.DIV =
|
||||
goog.dom.createDom(goog.dom.TagName.DIV, 'blocklyTooltipDiv');
|
||||
Blockly.Tooltip.DIV = document.createElement('div');
|
||||
Blockly.Tooltip.DIV.className = 'blocklyTooltipDiv';
|
||||
document.body.appendChild(Blockly.Tooltip.DIV);
|
||||
};
|
||||
|
||||
@@ -167,7 +168,8 @@ Blockly.Tooltip.onMouseOver_ = function(e) {
|
||||
// If the tooltip is an object, treat it as a pointer to the next object in
|
||||
// the chain to look at. Terminate when a string or function is found.
|
||||
var element = e.target;
|
||||
while (!goog.isString(element.tooltip) && !goog.isFunction(element.tooltip)) {
|
||||
while ((typeof element.tooltip != 'string') &&
|
||||
(typeof element.tooltip != 'function')) {
|
||||
element = element.tooltip;
|
||||
}
|
||||
if (Blockly.Tooltip.element_ != element) {
|
||||
@@ -286,10 +288,10 @@ Blockly.Tooltip.show_ = function() {
|
||||
return;
|
||||
}
|
||||
// Erase all existing text.
|
||||
goog.dom.removeChildren(/** @type {!Element} */ (Blockly.Tooltip.DIV));
|
||||
Blockly.Tooltip.DIV.innerHTML = '';
|
||||
// Get the new text.
|
||||
var tip = Blockly.Tooltip.element_.tooltip;
|
||||
while (goog.isFunction(tip)) {
|
||||
while (typeof tip == 'function') {
|
||||
tip = tip();
|
||||
}
|
||||
tip = Blockly.utils.wrap(tip, Blockly.Tooltip.LIMIT);
|
||||
|
||||
+12
-12
@@ -30,9 +30,9 @@
|
||||
**/
|
||||
goog.provide('Blockly.Touch');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.events.BrowserFeature');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
/**
|
||||
@@ -152,8 +152,8 @@ Blockly.Touch.shouldHandleEvent = function(e) {
|
||||
Blockly.Touch.getTouchIdentifierFromEvent = function(e) {
|
||||
return e.pointerId != undefined ? e.pointerId :
|
||||
(e.changedTouches && e.changedTouches[0] &&
|
||||
e.changedTouches[0].identifier != undefined &&
|
||||
e.changedTouches[0].identifier != null) ?
|
||||
e.changedTouches[0].identifier !== undefined &&
|
||||
e.changedTouches[0].identifier !== null) ?
|
||||
e.changedTouches[0].identifier : 'mouse';
|
||||
};
|
||||
|
||||
@@ -174,8 +174,8 @@ Blockly.Touch.checkTouchIdentifier = function(e) {
|
||||
|
||||
// if (Blockly.touchIdentifier_ )is insufficient because Android touch
|
||||
// identifiers may be zero.
|
||||
if (Blockly.Touch.touchIdentifier_ != undefined &&
|
||||
Blockly.Touch.touchIdentifier_ != null) {
|
||||
if (Blockly.Touch.touchIdentifier_ !== undefined &&
|
||||
Blockly.Touch.touchIdentifier_ !== null) {
|
||||
// We're already tracking some touch/mouse event. Is this from the same
|
||||
// source?
|
||||
return Blockly.Touch.touchIdentifier_ == identifier;
|
||||
@@ -198,7 +198,7 @@ Blockly.Touch.checkTouchIdentifier = function(e) {
|
||||
* @param {!Event} e A touch event.
|
||||
*/
|
||||
Blockly.Touch.setClientFromTouch = function(e) {
|
||||
if (goog.string.startsWith(e.type, 'touch')) {
|
||||
if (Blockly.utils.startsWith(e.type, 'touch')) {
|
||||
// Map the touch event's properties to the event.
|
||||
var touchPoint = e.changedTouches[0];
|
||||
e.clientX = touchPoint.clientX;
|
||||
@@ -212,9 +212,9 @@ Blockly.Touch.setClientFromTouch = function(e) {
|
||||
* @return {boolean} true if it is a mouse or touch event; false otherwise.
|
||||
*/
|
||||
Blockly.Touch.isMouseOrTouchEvent = function(e) {
|
||||
return goog.string.startsWith(e.type, 'touch') ||
|
||||
goog.string.startsWith(e.type, 'mouse') ||
|
||||
goog.string.startsWith(e.type, 'pointer');
|
||||
return Blockly.utils.startsWith(e.type, 'touch') ||
|
||||
Blockly.utils.startsWith(e.type, 'mouse') ||
|
||||
Blockly.utils.startsWith(e.type, 'pointer');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -223,8 +223,8 @@ Blockly.Touch.isMouseOrTouchEvent = function(e) {
|
||||
* @return {boolean} true if it is a touch event; false otherwise.
|
||||
*/
|
||||
Blockly.Touch.isTouchEvent = function(e) {
|
||||
return goog.string.startsWith(e.type, 'touch') ||
|
||||
goog.string.startsWith(e.type, 'pointer');
|
||||
return Blockly.utils.startsWith(e.type, 'touch') ||
|
||||
Blockly.utils.startsWith(e.type, 'pointer');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
goog.provide('Blockly.TouchGesture');
|
||||
|
||||
goog.require('Blockly.Gesture');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
|
||||
+6
-5
@@ -26,8 +26,8 @@
|
||||
|
||||
goog.provide('Blockly.Trashcan');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Rect');
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ Blockly.Trashcan.prototype.init = function(bottom) {
|
||||
*/
|
||||
Blockly.Trashcan.prototype.dispose = function() {
|
||||
if (this.svgGroup_) {
|
||||
goog.dom.removeNode(this.svgGroup_);
|
||||
this.svgGroup_.parentNode.removeChild(this.svgGroup_);
|
||||
this.svgGroup_ = null;
|
||||
}
|
||||
this.svgLid_ = null;
|
||||
@@ -309,13 +309,14 @@ Blockly.Trashcan.prototype.setOpen_ = function(state) {
|
||||
*/
|
||||
Blockly.Trashcan.prototype.animateLid_ = function() {
|
||||
this.lidOpen_ += this.isOpen ? 0.2 : -0.2;
|
||||
this.lidOpen_ = goog.math.clamp(this.lidOpen_, 0, 1);
|
||||
this.lidOpen_ = Math.min(Math.max(this.lidOpen_, 0), 1);
|
||||
var lidAngle = this.lidOpen_ * 45;
|
||||
this.svgLid_.setAttribute('transform', 'rotate(' +
|
||||
(this.workspace_.RTL ? -lidAngle : lidAngle) + ',' +
|
||||
(this.workspace_.RTL ? 4 : this.WIDTH_ - 4) + ',' +
|
||||
(this.LID_HEIGHT_ - 2) + ')');
|
||||
var opacity = goog.math.lerp(0.4, 0.8, this.lidOpen_);
|
||||
// Linear interpolation between 0.4 and 0.8.
|
||||
var opacity = 0.4 + this.lidOpen_ * (0.8 - 0.4);
|
||||
this.svgGroup_.style.opacity = opacity;
|
||||
if (this.lidOpen_ > 0 && this.lidOpen_ < 1) {
|
||||
this.lidTask_ = setTimeout(this.animateLid_.bind(this), 20);
|
||||
|
||||
@@ -29,8 +29,6 @@ goog.provide('Blockly.Events.Ui');
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.Abstract');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
/**
|
||||
* Class for a UI event.
|
||||
|
||||
+72
-11
@@ -32,9 +32,7 @@
|
||||
**/
|
||||
goog.provide('Blockly.utils');
|
||||
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events.BrowserFeature');
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
@@ -403,7 +401,7 @@ Blockly.utils.tokenizeInterpolation = function(message) {
|
||||
* @return {!string} String with message references replaced.
|
||||
*/
|
||||
Blockly.utils.replaceMessageReferences = function(message) {
|
||||
if (!goog.isString(message)) {
|
||||
if (typeof message != 'string') {
|
||||
return message;
|
||||
}
|
||||
var interpolatedResult = Blockly.utils.tokenizeInterpolation_(message, false);
|
||||
@@ -511,9 +509,9 @@ Blockly.utils.tokenizeInterpolation_ = function(message,
|
||||
} else if (state == 3) { // String table reference
|
||||
if (c == '') {
|
||||
// Premature end before closing '}'
|
||||
buffer.splice(0, 0, '%{'); // Re-insert leading delimiter
|
||||
buffer.splice(0, 0, '%{'); // Re-insert leading delimiter
|
||||
i--; // Parse this char again.
|
||||
state = 0; // and parse as string literal.
|
||||
state = 0; // and parse as string literal.
|
||||
} else if (c != '}') {
|
||||
buffer.push(c);
|
||||
} else {
|
||||
@@ -525,11 +523,11 @@ Blockly.utils.tokenizeInterpolation_ = function(message,
|
||||
// BKY_ is the prefix used to namespace the strings used in Blockly
|
||||
// core files and the predefined blocks in ../blocks/. These strings
|
||||
// are defined in ../msgs/ files.
|
||||
var bklyKey = goog.string.startsWith(keyUpper, 'BKY_') ?
|
||||
var bklyKey = Blockly.utils.startsWith(keyUpper, 'BKY_') ?
|
||||
keyUpper.substring(4) : null;
|
||||
if (bklyKey && bklyKey in Blockly.Msg) {
|
||||
var rawValue = Blockly.Msg[bklyKey];
|
||||
if (goog.isString(rawValue)) {
|
||||
if (typeof rawValue == 'string') {
|
||||
// Attempt to dereference substrings, too, appending to the end.
|
||||
Array.prototype.push.apply(tokens,
|
||||
Blockly.utils.tokenizeInterpolation_(
|
||||
@@ -551,7 +549,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message,
|
||||
} else {
|
||||
tokens.push('%{' + rawKey + '}');
|
||||
buffer.length = 0;
|
||||
state = 0; // and parse as string literal.
|
||||
state = 0; // and parse as string literal.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -833,13 +831,13 @@ Blockly.utils.is3dSupported = function() {
|
||||
* Contrast with node.insertBefore function.
|
||||
* @param {!Element} newNode New element to insert.
|
||||
* @param {!Element} refNode Existing element to precede new node.
|
||||
* @private
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.insertAfter_ = function(newNode, refNode) {
|
||||
Blockly.utils.insertAfter = function(newNode, refNode) {
|
||||
var siblingNode = refNode.nextSibling;
|
||||
var parentNode = refNode.parentNode;
|
||||
if (!parentNode) {
|
||||
throw 'Reference node has no parent.';
|
||||
throw Error('Reference node has no parent.');
|
||||
}
|
||||
if (siblingNode) {
|
||||
parentNode.insertBefore(newNode, siblingNode);
|
||||
@@ -901,3 +899,66 @@ Blockly.utils.getViewportBBox = function() {
|
||||
left: scrollOffset.x
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Fast prefix-checker.
|
||||
* Copied from Closure's goog.string.startsWith.
|
||||
* @param {string} str The string to check.
|
||||
* @param {string} prefix A string to look for at the start of `str`.
|
||||
* @return {boolean} True if `str` begins with `prefix`.
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.startsWith = function(str, prefix) {
|
||||
return str.lastIndexOf(prefix, 0) == 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the first occurrence of a particular value from an array.
|
||||
* @param {!Array} arr Array from which to remove
|
||||
* value.
|
||||
* @param {*} obj Object to remove.
|
||||
* @return {boolean} True if an element was removed.
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.arrayRemove = function(arr, obj) {
|
||||
var i = arr.indexOf(obj);
|
||||
if (i == -1) {
|
||||
return false;
|
||||
}
|
||||
arr.splice(i, 1);
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts degrees to radians.
|
||||
* Copied from Closure's goog.math.toRadians.
|
||||
* @param {number} angleDegrees Angle in degrees.
|
||||
* @return {number} Angle in radians.
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.toRadians = function(angleDegrees) {
|
||||
return angleDegrees * Math.PI / 180;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts radians to degrees.
|
||||
* Copied from Closure's goog.math.toDegrees.
|
||||
* @param {number} angleRadians Angle in radians.
|
||||
* @return {number} Angle in degrees.
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.toDegrees = function(angleRadians) {
|
||||
return angleRadians * 180 / Math.PI;
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether a node contains another node.
|
||||
* @param {!Node} parent The node that should contain the other node.
|
||||
* @param {!Node} descendant The node to test presence of.
|
||||
* @return {boolean} Whether the parent node contains the descendant node.
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.containsNode = function(parent, descendant) {
|
||||
return !!(parent.compareDocumentPosition(descendant) &
|
||||
Node.DOCUMENT_POSITION_CONTAINED_BY);
|
||||
};
|
||||
|
||||
@@ -32,9 +32,6 @@ goog.provide('Blockly.Events.VarRename');
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.Abstract');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for a variable event.
|
||||
|
||||
@@ -28,6 +28,8 @@ goog.provide('Blockly.VariableMap');
|
||||
|
||||
goog.require('Blockly.Events.VarDelete');
|
||||
goog.require('Blockly.Events.VarRename');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
|
||||
/**
|
||||
* Class for a variable map. This contains a dictionary data structure with
|
||||
@@ -175,8 +177,8 @@ Blockly.VariableMap.prototype.createVariable = function(name,
|
||||
if (variable) {
|
||||
if (opt_id && variable.getId() != opt_id) {
|
||||
throw Error('Variable "' + name + '" is already in use and its id is "' +
|
||||
variable.getId() + '" which conflicts with the passed in ' +
|
||||
'id, "' + opt_id + '".');
|
||||
variable.getId() + '" which conflicts with the passed in ' +
|
||||
'id, "' + opt_id + '".');
|
||||
}
|
||||
// The variable already exists and has the same ID.
|
||||
return variable;
|
||||
|
||||
+10
-3
@@ -27,8 +27,7 @@
|
||||
goog.provide('Blockly.VariableModel');
|
||||
|
||||
goog.require('Blockly.Events.VarCreate');
|
||||
|
||||
goog.require('goog.string');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
|
||||
/**
|
||||
@@ -97,5 +96,13 @@ Blockly.VariableModel.prototype.getId = function() {
|
||||
* @package
|
||||
*/
|
||||
Blockly.VariableModel.compareByName = function(var1, var2) {
|
||||
return goog.string.caseInsensitiveCompare(var1.name, var2.name);
|
||||
var name1 = var1.name.toLowerCase();
|
||||
var name2 = var2.name.toLowerCase();
|
||||
if (name1 < name2) {
|
||||
return -1;
|
||||
} else if (name1 == name2) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
+23
-2
@@ -34,6 +34,8 @@ goog.require('Blockly.Blocks');
|
||||
goog.require('Blockly.constants');
|
||||
goog.require('Blockly.VariableModel');
|
||||
goog.require('Blockly.Workspace');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
@@ -89,6 +91,12 @@ Blockly.Variables.allUsedVariables = function() {
|
||||
'issue please file a bug on GitHub.');
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<string,boolean>}
|
||||
*/
|
||||
Blockly.Variables.ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE_ = {};
|
||||
|
||||
/**
|
||||
* Find all developer variables used by blocks in the workspace.
|
||||
* Developer variables are never shown to the user, but are declared as global
|
||||
@@ -104,8 +112,21 @@ Blockly.Variables.allDeveloperVariables = function(workspace) {
|
||||
var hash = {};
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
var block = blocks[i];
|
||||
if (block.getDeveloperVars) {
|
||||
var devVars = block.getDeveloperVars();
|
||||
var getDeveloperVariables = block.getDeveloperVariables;
|
||||
if (!getDeveloperVariables && block.getDeveloperVars) {
|
||||
// August 2018: getDeveloperVars() was deprecated and renamed
|
||||
// getDeveloperVariables().
|
||||
getDeveloperVariables = block.getDeveloperVars;
|
||||
if (!Blockly.Variables.ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE_[
|
||||
block.type]) {
|
||||
console.warn('Function getDeveloperVars() deprecated. Use ' +
|
||||
'getDeveloperVariables() (block type \'' + block.type + '\')');
|
||||
Blockly.Variables.ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE_[
|
||||
block.type] = true;
|
||||
}
|
||||
}
|
||||
if (getDeveloperVariables) {
|
||||
var devVars = getDeveloperVariables();
|
||||
for (var j = 0; j < devVars.length; j++) {
|
||||
hash[devVars[j]] = devVars[j];
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ goog.require('Blockly.constants');
|
||||
goog.require('Blockly.VariableModel');
|
||||
// TODO Fix circular dependencies
|
||||
// goog.require('Blockly.Workspace');
|
||||
goog.require('goog.string');
|
||||
|
||||
goog.require('goog.dom');
|
||||
|
||||
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) {
|
||||
|
||||
@@ -29,6 +29,7 @@ goog.provide('Blockly.Warning');
|
||||
goog.require('Blockly.Bubble');
|
||||
goog.require('Blockly.Events.Ui');
|
||||
goog.require('Blockly.Icon');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+3
-5
@@ -33,8 +33,6 @@
|
||||
goog.provide('Blockly.WidgetDiv');
|
||||
|
||||
goog.require('Blockly.Css');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.style');
|
||||
|
||||
|
||||
@@ -66,8 +64,8 @@ Blockly.WidgetDiv.createDom = function() {
|
||||
return; // Already created.
|
||||
}
|
||||
// Create an HTML container for popup overlays (e.g. editor widgets).
|
||||
Blockly.WidgetDiv.DIV =
|
||||
goog.dom.createDom(goog.dom.TagName.DIV, 'blocklyWidgetDiv');
|
||||
Blockly.WidgetDiv.DIV = document.createElement('div');
|
||||
Blockly.WidgetDiv.DIV.className = 'blocklyWidgetDiv';
|
||||
document.body.appendChild(Blockly.WidgetDiv.DIV);
|
||||
};
|
||||
|
||||
@@ -101,7 +99,7 @@ Blockly.WidgetDiv.hide = function() {
|
||||
Blockly.WidgetDiv.DIV.style.top = '';
|
||||
Blockly.WidgetDiv.dispose_ && Blockly.WidgetDiv.dispose_();
|
||||
Blockly.WidgetDiv.dispose_ = null;
|
||||
goog.dom.removeChildren(Blockly.WidgetDiv.DIV);
|
||||
Blockly.WidgetDiv.DIV.innerHTML = '';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+11
-9
@@ -26,10 +26,9 @@
|
||||
|
||||
goog.provide('Blockly.Workspace');
|
||||
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.VariableMap');
|
||||
goog.require('Blockly.WorkspaceComment');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.math');
|
||||
|
||||
|
||||
/**
|
||||
@@ -160,8 +159,8 @@ Blockly.Workspace.prototype.addTopBlock = function(block) {
|
||||
* @param {!Blockly.Block} block Block to remove.
|
||||
*/
|
||||
Blockly.Workspace.prototype.removeTopBlock = function(block) {
|
||||
if (!goog.array.remove(this.topBlocks_, block)) {
|
||||
throw 'Block not present in workspace\'s list of top-most blocks.';
|
||||
if (!Blockly.utils.arrayRemove(this.topBlocks_, block)) {
|
||||
throw Error('Block not present in workspace\'s list of top-most blocks.');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -175,7 +174,8 @@ Blockly.Workspace.prototype.getTopBlocks = function(ordered) {
|
||||
// Copy the topBlocks_ list.
|
||||
var blocks = [].concat(this.topBlocks_);
|
||||
if (ordered && blocks.length > 1) {
|
||||
var offset = Math.sin(goog.math.toRadians(Blockly.Workspace.SCAN_ANGLE));
|
||||
var offset =
|
||||
Math.sin(Blockly.utils.toRadians(Blockly.Workspace.SCAN_ANGLE));
|
||||
if (this.RTL) {
|
||||
offset *= -1;
|
||||
}
|
||||
@@ -211,8 +211,9 @@ Blockly.Workspace.prototype.addTopComment = function(comment) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.Workspace.prototype.removeTopComment = function(comment) {
|
||||
if (!goog.array.remove(this.topComments_, comment)) {
|
||||
throw 'Comment not present in workspace\'s list of top-most comments.';
|
||||
if (!Blockly.utils.arrayRemove(this.topComments_, comment)) {
|
||||
throw Error('Comment not present in workspace\'s list of top-most ' +
|
||||
'comments.');
|
||||
}
|
||||
// Note: If the comment database starts to hold block comments, this may need
|
||||
// to move to a separate function.
|
||||
@@ -230,7 +231,8 @@ Blockly.Workspace.prototype.getTopComments = function(ordered) {
|
||||
// Copy the topComments_ list.
|
||||
var comments = [].concat(this.topComments_);
|
||||
if (ordered && comments.length > 1) {
|
||||
var offset = Math.sin(goog.math.toRadians(Blockly.Workspace.SCAN_ANGLE));
|
||||
var offset =
|
||||
Math.sin(Blockly.utils.toRadians(Blockly.Workspace.SCAN_ANGLE));
|
||||
if (this.RTL) {
|
||||
offset *= -1;
|
||||
}
|
||||
@@ -510,7 +512,7 @@ Blockly.Workspace.prototype.addChangeListener = function(func) {
|
||||
* @param {Function} func Function to stop calling.
|
||||
*/
|
||||
Blockly.Workspace.prototype.removeChangeListener = function(func) {
|
||||
goog.array.remove(this.listeners_, func);
|
||||
Blockly.utils.arrayRemove(this.listeners_, func);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+16
-22
@@ -30,7 +30,9 @@ goog.require('Blockly.Events.CommentChange');
|
||||
goog.require('Blockly.Events.CommentCreate');
|
||||
goog.require('Blockly.Events.CommentDelete');
|
||||
goog.require('Blockly.Events.CommentMove');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
@@ -331,7 +333,8 @@ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) {
|
||||
/**
|
||||
* Decode an XML comment tag and return the results in an object.
|
||||
* @param {!Element} xml XML comment element.
|
||||
* @return {!Object} An object containing the information about the comment.
|
||||
* @return {{w: number, h: number, x: number, y: number, content: string}} An
|
||||
* object containing the id, size, position, and comment string.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceComment.parseAttributes = function(xml) {
|
||||
@@ -339,32 +342,23 @@ Blockly.WorkspaceComment.parseAttributes = function(xml) {
|
||||
var xmlW = xml.getAttribute('w');
|
||||
|
||||
return {
|
||||
/* @type {string} */
|
||||
// @type {string}
|
||||
id: xml.getAttribute('id'),
|
||||
/**
|
||||
* The height of the comment in workspace units, or 100 if not specified.
|
||||
* @type {number}
|
||||
*/
|
||||
// The height of the comment in workspace units, or 100 if not specified.
|
||||
// @type {number}
|
||||
h: xmlH ? parseInt(xmlH, 10) : 100,
|
||||
/**
|
||||
* The width of the comment in workspace units, or 100 if not specified.
|
||||
* @type {number}
|
||||
*/
|
||||
// The width of the comment in workspace units, or 100 if not specified.
|
||||
// @type {number}
|
||||
w: xmlW ? parseInt(xmlW, 10) : 100,
|
||||
/**
|
||||
* The x position of the comment in workspace coordinates, or NaN if not
|
||||
* specified in the XML.
|
||||
* @type {number}
|
||||
*/
|
||||
// The x position of the comment in workspace coordinates, or NaN if not
|
||||
// specified in the XML.
|
||||
// @type {number}
|
||||
x: parseInt(xml.getAttribute('x'), 10),
|
||||
/**
|
||||
* The y position of the comment in workspace coordinates, or NaN if not
|
||||
* specified in the XML.
|
||||
* @type {number}
|
||||
*/
|
||||
// The y position of the comment in workspace coordinates, or NaN if not
|
||||
// specified in the XML.
|
||||
// @type {number}
|
||||
y: parseInt(xml.getAttribute('y'), 10),
|
||||
/* @type {string} */
|
||||
// @type {string}
|
||||
content: xml.textContent
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -26,8 +26,11 @@
|
||||
|
||||
goog.provide('Blockly.WorkspaceCommentSvg.render');
|
||||
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.WorkspaceCommentSvg');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
* Size of the resize icon.
|
||||
|
||||
@@ -29,8 +29,11 @@ goog.provide('Blockly.WorkspaceCommentSvg');
|
||||
goog.require('Blockly.Events.CommentCreate');
|
||||
goog.require('Blockly.Events.CommentDelete');
|
||||
goog.require('Blockly.Events.CommentMove');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.WorkspaceComment');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
* Class for a workspace comment's SVG representation.
|
||||
@@ -114,7 +117,7 @@ Blockly.WorkspaceCommentSvg.prototype.dispose = function() {
|
||||
Blockly.Events.fire(new Blockly.Events.CommentDelete(this));
|
||||
}
|
||||
|
||||
goog.dom.removeNode(this.svgGroup_);
|
||||
this.svgGroup_.parentNode.removeChild(this.svgGroup_);
|
||||
// Sever JavaScript to DOM connections.
|
||||
this.svgGroup_ = null;
|
||||
this.svgRect_ = null;
|
||||
@@ -132,7 +135,9 @@ Blockly.WorkspaceCommentSvg.prototype.dispose = function() {
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceCommentSvg.prototype.initSvg = function() {
|
||||
goog.asserts.assert(this.workspace.rendered, 'Workspace is headless.');
|
||||
if (!this.workspace.rendered) {
|
||||
throw TypeError('Workspace is headless.');
|
||||
}
|
||||
if (!this.workspace.options.readOnly && !this.eventsInit_) {
|
||||
Blockly.bindEventWithChecks_(
|
||||
this.svgRectTarget_, 'mousedown', this, this.pathMouseDown_);
|
||||
|
||||
@@ -32,9 +32,6 @@ goog.provide('Blockly.WorkspaceDragSurfaceSvg');
|
||||
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
* Blocks are moved into this SVG during a drag, improving performance.
|
||||
@@ -138,30 +135,33 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.getSurfaceTranslation = function() {
|
||||
*/
|
||||
Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
||||
if (!newSurface) {
|
||||
throw 'Couldn\'t clear and hide the drag surface: missing new surface.';
|
||||
throw Error('Couldn\'t clear and hide the drag surface: missing ' +
|
||||
'new surface.');
|
||||
}
|
||||
var blockCanvas = this.SVG_.childNodes[0];
|
||||
var bubbleCanvas = this.SVG_.childNodes[1];
|
||||
if (!blockCanvas || !bubbleCanvas ||
|
||||
!Blockly.utils.hasClass(blockCanvas, 'blocklyBlockCanvas') ||
|
||||
!Blockly.utils.hasClass(bubbleCanvas, 'blocklyBubbleCanvas')) {
|
||||
throw 'Couldn\'t clear and hide the drag surface. A node was missing.';
|
||||
throw Error('Couldn\'t clear and hide the drag surface. ' +
|
||||
'A node was missing.');
|
||||
}
|
||||
|
||||
// If there is a previous sibling, put the blockCanvas back right afterwards,
|
||||
// otherwise insert it as the first child node in newSurface.
|
||||
if (this.previousSibling_ != null) {
|
||||
Blockly.utils.insertAfter_(blockCanvas, this.previousSibling_);
|
||||
Blockly.utils.insertAfter(blockCanvas, this.previousSibling_);
|
||||
} else {
|
||||
newSurface.insertBefore(blockCanvas, newSurface.firstChild);
|
||||
}
|
||||
|
||||
// Reattach the bubble canvas after the blockCanvas.
|
||||
Blockly.utils.insertAfter_(bubbleCanvas, blockCanvas);
|
||||
Blockly.utils.insertAfter(bubbleCanvas, blockCanvas);
|
||||
// Hide the drag surface.
|
||||
this.SVG_.style.display = 'none';
|
||||
goog.asserts.assert(
|
||||
this.SVG_.childNodes.length == 0, 'Drag surface was not cleared.');
|
||||
if (this.SVG_.childNodes.length) {
|
||||
throw Error('Drag surface was not cleared.');
|
||||
}
|
||||
Blockly.utils.setCssTransform(this.SVG_, '');
|
||||
this.previousSibling_ = null;
|
||||
};
|
||||
@@ -180,8 +180,9 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
||||
*/
|
||||
Blockly.WorkspaceDragSurfaceSvg.prototype.setContentsAndShow = function(
|
||||
blockCanvas, bubbleCanvas, previousSibling, width, height, scale) {
|
||||
goog.asserts.assert(
|
||||
this.SVG_.childNodes.length == 0, 'Already dragging a block.');
|
||||
if (this.SVG_.childNodes.length) {
|
||||
throw Error('Already dragging a block.');
|
||||
}
|
||||
this.previousSibling_ = previousSibling;
|
||||
// Make sure the blocks and bubble canvas are scaled appropriately.
|
||||
blockCanvas.setAttribute('transform', 'translate(0, 0) scale(' + scale + ')');
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
goog.provide('Blockly.WorkspaceDragger');
|
||||
|
||||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.asserts');
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+71
-20
@@ -38,6 +38,7 @@ goog.require('Blockly.ScrollbarPair');
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.TouchGesture');
|
||||
goog.require('Blockly.Trashcan');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.VariablesDynamic');
|
||||
goog.require('Blockly.Workspace');
|
||||
goog.require('Blockly.WorkspaceAudio');
|
||||
@@ -48,7 +49,6 @@ goog.require('Blockly.WorkspaceDragSurfaceSvg');
|
||||
goog.require('Blockly.Xml');
|
||||
goog.require('Blockly.ZoomControls');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
@@ -131,12 +131,20 @@ Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_ = null;
|
||||
|
||||
/**
|
||||
* The render status of an SVG workspace.
|
||||
* Returns `true` for visible workspaces and `false` for non-visible,
|
||||
* or headless, workspaces.
|
||||
* Returns `false` for headless workspaces and true for instances of
|
||||
* `Blockly.WorkspaceSvg`.
|
||||
* @type {boolean}
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.rendered = true;
|
||||
|
||||
/**
|
||||
* Whether the workspace is visible. False if the workspace has been hidden
|
||||
* by calling `setVisible(false)`.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.isVisible_ = true;
|
||||
|
||||
/**
|
||||
* Is this workspace the surface for a flyout?
|
||||
* @type {boolean}
|
||||
@@ -334,6 +342,15 @@ Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM = function() {
|
||||
this.inverseScreenCTMDirty_ = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Getter for isVisible
|
||||
* @return {boolean} Whether the workspace is visible. False if the workspace has been hidden
|
||||
* by calling `setVisible(false)`.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.isVisible = function() {
|
||||
return this.isVisible_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the absolute coordinates of the top-left corner of this element,
|
||||
* scales that after canvas SVG element, if it's a descendant.
|
||||
@@ -346,8 +363,8 @@ Blockly.WorkspaceSvg.prototype.getSvgXY = function(element) {
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var scale = 1;
|
||||
if (goog.dom.contains(this.getCanvas(), element) ||
|
||||
goog.dom.contains(this.getBubbleCanvas(), element)) {
|
||||
if (Blockly.utils.containsNode(this.getCanvas(), element) ||
|
||||
Blockly.utils.containsNode(this.getBubbleCanvas(), element)) {
|
||||
// Before the SVG canvas, scale the coordinates.
|
||||
scale = this.scale;
|
||||
}
|
||||
@@ -494,7 +511,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
|
||||
}
|
||||
Blockly.WorkspaceSvg.superClass_.dispose.call(this);
|
||||
if (this.svgGroup_) {
|
||||
goog.dom.removeNode(this.svgGroup_);
|
||||
this.svgGroup_.parentNode.removeChild(this.svgGroup_);
|
||||
this.svgGroup_ = null;
|
||||
}
|
||||
this.svgBlockCanvas_ = null;
|
||||
@@ -539,7 +556,10 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
|
||||
if (!this.options.parentWorkspace) {
|
||||
// Top-most workspace. Dispose of the div that the
|
||||
// SVG is injected into (i.e. injectionDiv).
|
||||
goog.dom.removeNode(this.getParentSvg().parentNode);
|
||||
var div = this.getParentSvg().parentNode;
|
||||
if (div) {
|
||||
div.parentNode.removeChild(div);
|
||||
}
|
||||
}
|
||||
if (this.resizeHandlerWrapper_) {
|
||||
Blockly.unbindEvent_(this.resizeHandlerWrapper_);
|
||||
@@ -879,6 +899,7 @@ Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) {
|
||||
} else {
|
||||
Blockly.hideChaff(true);
|
||||
}
|
||||
this.isVisible_ = isVisible;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -926,7 +947,7 @@ Blockly.WorkspaceSvg.prototype.highlightBlock = function(id, opt_state) {
|
||||
var state = (opt_state === undefined) || opt_state;
|
||||
// Using Set here would be great, but at the cost of IE10 support.
|
||||
if (!state) {
|
||||
goog.array.remove(this.highlightedBlocks_, block);
|
||||
Blockly.utils.arrayRemove(this.highlightedBlocks_, block);
|
||||
} else if (this.highlightedBlocks_.indexOf(block) == -1) {
|
||||
this.highlightedBlocks_.push(block);
|
||||
}
|
||||
@@ -1090,7 +1111,8 @@ Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) {
|
||||
* @return {?Blockly.VariableModel} The newly created variable.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.createVariable = function(name, opt_type, opt_id) {
|
||||
Blockly.WorkspaceSvg.prototype.createVariable = function(name,
|
||||
opt_type, opt_id) {
|
||||
var newVar = Blockly.WorkspaceSvg.superClass_.createVariable.call(
|
||||
this, name, opt_type, opt_id);
|
||||
this.refreshToolboxSelection();
|
||||
@@ -1427,23 +1449,23 @@ Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) {
|
||||
tree = Blockly.Options.parseToolboxTree(tree);
|
||||
if (!tree) {
|
||||
if (this.options.languageTree) {
|
||||
throw 'Can\'t nullify an existing toolbox.';
|
||||
throw Error('Can\'t nullify an existing toolbox.');
|
||||
}
|
||||
return; // No change (null to null).
|
||||
}
|
||||
if (!this.options.languageTree) {
|
||||
throw 'Existing toolbox is null. Can\'t create new toolbox.';
|
||||
throw Error('Existing toolbox is null. Can\'t create new toolbox.');
|
||||
}
|
||||
if (tree.getElementsByTagName('category').length) {
|
||||
if (!this.toolbox_) {
|
||||
throw 'Existing toolbox has no categories. Can\'t change mode.';
|
||||
throw Error('Existing toolbox has no categories. Can\'t change mode.');
|
||||
}
|
||||
this.options.languageTree = tree;
|
||||
this.toolbox_.populate_(tree);
|
||||
this.toolbox_.addColour_();
|
||||
} else {
|
||||
if (!this.flyout_) {
|
||||
throw 'Existing toolbox has categories. Can\'t change mode.';
|
||||
throw Error('Existing toolbox has categories. Can\'t change mode.');
|
||||
}
|
||||
this.options.languageTree = tree;
|
||||
this.flyout_.show(tree.childNodes);
|
||||
@@ -1573,6 +1595,32 @@ Blockly.WorkspaceSvg.prototype.zoomToFit = function() {
|
||||
this.scrollCenter();
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a transition class to the block and bubble canvas, to animate any
|
||||
* transform changes.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.beginCanvasTransition = function() {
|
||||
Blockly.utils.addClass(
|
||||
/** @type {!SVGElement} */ this.svgBlockCanvas_,
|
||||
'blocklyCanvasTransitioning');
|
||||
Blockly.utils.addClass(
|
||||
/** @type {!SVGElement} */ this.svgBubbleCanvas_,
|
||||
'blocklyCanvasTransitioning');
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove transition class from the block and bubble canvas.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.endCanvasTransition = function() {
|
||||
Blockly.utils.removeClass(
|
||||
/** @type {!SVGElement} */ this.svgBlockCanvas_,
|
||||
'blocklyCanvasTransitioning');
|
||||
Blockly.utils.removeClass(
|
||||
/** @type {!SVGElement} */ this.svgBubbleCanvas_,
|
||||
'blocklyCanvasTransitioning');
|
||||
};
|
||||
/**
|
||||
* Center the workspace.
|
||||
*/
|
||||
@@ -1878,13 +1926,14 @@ Blockly.WorkspaceSvg.getTopLevelWorkspaceMetrics_ = function() {
|
||||
*/
|
||||
Blockly.WorkspaceSvg.setTopLevelWorkspaceMetrics_ = function(xyRatio) {
|
||||
if (!this.scrollbar) {
|
||||
throw 'Attempt to set top level workspace scroll without scrollbars.';
|
||||
throw Error('Attempt to set top level workspace scroll without ' +
|
||||
'scrollbars.');
|
||||
}
|
||||
var metrics = this.getMetrics();
|
||||
if (goog.isNumber(xyRatio.x)) {
|
||||
if (typeof xyRatio.x == 'number') {
|
||||
this.scrollX = -metrics.contentWidth * xyRatio.x - metrics.contentLeft;
|
||||
}
|
||||
if (goog.isNumber(xyRatio.y)) {
|
||||
if (typeof xyRatio.y == 'number') {
|
||||
this.scrollY = -metrics.contentHeight * xyRatio.y - metrics.contentTop;
|
||||
}
|
||||
var x = this.scrollX + metrics.absoluteLeft;
|
||||
@@ -1932,8 +1981,9 @@ Blockly.WorkspaceSvg.prototype.clear = function() {
|
||||
* given button is clicked.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.registerButtonCallback = function(key, func) {
|
||||
goog.asserts.assert(goog.isFunction(func),
|
||||
'Button callbacks must be functions.');
|
||||
if (typeof func != 'function') {
|
||||
throw TypeError('Button callbacks must be functions.');
|
||||
}
|
||||
this.flyoutButtonCallbacks_[key] = func;
|
||||
};
|
||||
|
||||
@@ -1967,8 +2017,9 @@ Blockly.WorkspaceSvg.prototype.removeButtonCallback = function(key) {
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.registerToolboxCategoryCallback = function(key,
|
||||
func) {
|
||||
goog.asserts.assert(goog.isFunction(func),
|
||||
'Toolbox category callbacks must be functions.');
|
||||
if (typeof func != 'function') {
|
||||
throw TypeError('Toolbox category callbacks must be functions.');
|
||||
}
|
||||
this.toolboxCategoryCallbacks_[key] = func;
|
||||
};
|
||||
|
||||
|
||||
+14
-19
@@ -33,6 +33,7 @@ goog.provide('Blockly.Events.CommentMove');
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.Abstract');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math.Coordinate');
|
||||
|
||||
|
||||
@@ -191,9 +192,9 @@ Blockly.Events.CommentCreate.prototype.type = Blockly.Events.COMMENT_CREATE;
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
* TODO (#1266): "Full" and "minimal" serialization.
|
||||
* @return {!Object} JSON representation.
|
||||
*/
|
||||
// TODO(#1266): "Full" and "minimal" serialization.
|
||||
Blockly.Events.CommentCreate.prototype.toJson = function() {
|
||||
var json = Blockly.Events.CommentCreate.superClass_.toJson.call(this);
|
||||
json['xml'] = Blockly.Xml.domToText(this.xml);
|
||||
@@ -214,8 +215,16 @@ Blockly.Events.CommentCreate.prototype.fromJson = function(json) {
|
||||
* @param {boolean} forward True if run forward, false if run backward (undo).
|
||||
*/
|
||||
Blockly.Events.CommentCreate.prototype.run = function(forward) {
|
||||
Blockly.Events.CommentCreateDeleteHelper(forward);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function for Comment[Create|Delete]
|
||||
* @param {boolean} create if True then Create, if False then Delete
|
||||
*/
|
||||
Blockly.Events.CommentCreateDeleteHelper = function(create) {
|
||||
var workspace = this.getEventWorkspace_();
|
||||
if (forward) {
|
||||
if (create) {
|
||||
var xml = goog.dom.createDom('xml');
|
||||
xml.appendChild(this.xml);
|
||||
Blockly.Xml.domToWorkspace(xml, workspace);
|
||||
@@ -229,7 +238,6 @@ Blockly.Events.CommentCreate.prototype.run = function(forward) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Class for a comment deletion event.
|
||||
* @param {Blockly.WorkspaceComment} comment The deleted comment.
|
||||
@@ -255,9 +263,9 @@ Blockly.Events.CommentDelete.prototype.type = Blockly.Events.COMMENT_DELETE;
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
* TODO (#1266): "Full" and "minimal" serialization.
|
||||
* @return {!Object} JSON representation.
|
||||
*/
|
||||
// TODO(#1266): "Full" and "minimal" serialization.
|
||||
Blockly.Events.CommentDelete.prototype.toJson = function() {
|
||||
var json = Blockly.Events.CommentDelete.superClass_.toJson.call(this);
|
||||
return json;
|
||||
@@ -276,20 +284,7 @@ Blockly.Events.CommentDelete.prototype.fromJson = function(json) {
|
||||
* @param {boolean} forward True if run forward, false if run backward (undo).
|
||||
*/
|
||||
Blockly.Events.CommentDelete.prototype.run = function(forward) {
|
||||
var workspace = this.getEventWorkspace_();
|
||||
if (forward) {
|
||||
var comment = workspace.getCommentById(this.commentId);
|
||||
if (comment) {
|
||||
comment.dispose(false, false);
|
||||
} else {
|
||||
// Only complain about root-level block.
|
||||
console.warn("Can't uncreate non-existent comment: " + this.commentId);
|
||||
}
|
||||
} else {
|
||||
var xml = goog.dom.createDom('xml');
|
||||
xml.appendChild(this.xml);
|
||||
Blockly.Xml.domToWorkspace(xml, workspace);
|
||||
}
|
||||
Blockly.Events.CommentCreateDeleteHelper(!forward);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -357,9 +352,9 @@ Blockly.Events.CommentMove.prototype.setOldCoordinate = function(xy) {
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
* TODO (#1266): "Full" and "minimal" serialization.
|
||||
* @return {!Object} JSON representation.
|
||||
*/
|
||||
// TODO(#1266): "Full" and "minimal" serialization.
|
||||
Blockly.Events.CommentMove.prototype.toJson = function() {
|
||||
var json = Blockly.Events.CommentMove.superClass_.toJson.call(this);
|
||||
if (this.newCoordinate_) {
|
||||
|
||||
+22
-19
@@ -44,8 +44,11 @@ goog.require('goog.dom');
|
||||
*/
|
||||
Blockly.Xml.workspaceToDom = function(workspace, opt_noId) {
|
||||
var xml = goog.dom.createDom('xml');
|
||||
xml.appendChild(Blockly.Xml.variablesToDom(
|
||||
Blockly.Variables.allUsedVarModels(workspace)));
|
||||
var variablesElement = Blockly.Xml.variablesToDom(
|
||||
Blockly.Variables.allUsedVarModels(workspace));
|
||||
if (variablesElement.hasChildNodes()) {
|
||||
xml.appendChild(variablesElement);
|
||||
}
|
||||
var comments = workspace.getTopComments(true);
|
||||
for (var i = 0, comment; comment = comments[i]; i++) {
|
||||
xml.appendChild(comment.toXmlWithXY(opt_noId));
|
||||
@@ -286,7 +289,7 @@ Blockly.Xml.cloneShadow_ = function(shadow) {
|
||||
if (textNode.nodeType == 3 && textNode.data.trim() == '' &&
|
||||
node.firstChild != textNode) {
|
||||
// Prune whitespace after a tag.
|
||||
goog.dom.removeNode(textNode);
|
||||
textNode.parentNode.removeChild(textNode);
|
||||
}
|
||||
}
|
||||
if (node) {
|
||||
@@ -294,7 +297,7 @@ Blockly.Xml.cloneShadow_ = function(shadow) {
|
||||
node = node.nextSibling;
|
||||
if (textNode.nodeType == 3 && textNode.data.trim() == '') {
|
||||
// Prune whitespace before a tag.
|
||||
goog.dom.removeNode(textNode);
|
||||
textNode.parentNode.removeChild(textNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -370,7 +373,7 @@ Blockly.Xml.textToDom = function(text) {
|
||||
if (!doc || !doc.documentElement ||
|
||||
doc.documentElement.nodeName.toLowerCase() != 'xml') {
|
||||
// Whatever we got back from the parser is not the expected structure.
|
||||
throw Error('Blockly.Xml.textToDom expected an <xml> document.');
|
||||
throw TypeError('Blockly.Xml.textToDom expected an <xml> document.');
|
||||
}
|
||||
return doc.documentElement;
|
||||
};
|
||||
@@ -445,7 +448,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
||||
}
|
||||
variablesFirst = false;
|
||||
} else if (name == 'shadow') {
|
||||
throw Error('Shadow block cannot be a top-level block.');
|
||||
throw TypeError('Shadow block cannot be a top-level block.');
|
||||
} else if (name == 'comment') {
|
||||
if (workspace.rendered) {
|
||||
Blockly.WorkspaceCommentSvg.fromXml(xmlChild, workspace, width);
|
||||
@@ -457,8 +460,8 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
||||
Blockly.Xml.domToVariables(xmlChild, workspace);
|
||||
} else {
|
||||
throw Error('\'variables\' tag must exist once before block and ' +
|
||||
'shadow tag elements in the workspace XML, but it was found in ' +
|
||||
'another location.');
|
||||
'shadow tag elements in the workspace XML, but it was found in ' +
|
||||
'another location.');
|
||||
}
|
||||
variablesFirst = false;
|
||||
}
|
||||
@@ -628,7 +631,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
||||
var block = null;
|
||||
var prototypeName = xmlBlock.getAttribute('type');
|
||||
if (!prototypeName) {
|
||||
throw Error('Block type unspecified: ' + xmlBlock.outerHTML);
|
||||
throw TypeError('Block type unspecified: ' + xmlBlock.outerHTML);
|
||||
}
|
||||
var id = xmlBlock.getAttribute('id');
|
||||
block = workspace.newBlock(prototypeName, id);
|
||||
@@ -717,7 +720,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
||||
} else if (blockChild.previousConnection) {
|
||||
input.connection.connect(blockChild.previousConnection);
|
||||
} else {
|
||||
throw Error(
|
||||
throw TypeError(
|
||||
'Child block does not have output or previous statement.');
|
||||
}
|
||||
}
|
||||
@@ -728,16 +731,16 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
||||
}
|
||||
if (childBlockElement) {
|
||||
if (!block.nextConnection) {
|
||||
throw Error('Next statement does not exist.');
|
||||
throw TypeError('Next statement does not exist.');
|
||||
}
|
||||
// If there is more than one XML 'next' tag.
|
||||
if (block.nextConnection.isConnected()) {
|
||||
throw Error('Next statement is already connected.');
|
||||
throw TypeError('Next statement is already connected.');
|
||||
}
|
||||
blockChild = Blockly.Xml.domToBlockHeadless_(childBlockElement,
|
||||
workspace);
|
||||
if (!blockChild.previousConnection) {
|
||||
throw Error('Next block does not have previous statement.');
|
||||
throw TypeError('Next block does not have previous statement.');
|
||||
}
|
||||
block.nextConnection.connect(blockChild.previousConnection);
|
||||
}
|
||||
@@ -776,13 +779,13 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
||||
// Ensure all children are also shadows.
|
||||
var children = block.getChildren(false);
|
||||
for (var i = 0, child; child = children[i]; i++) {
|
||||
if (child.isShadow()) {
|
||||
throw Error('Shadow block not allowed non-shadow child.');
|
||||
if (!child.isShadow()) {
|
||||
throw TypeError('Shadow block not allowed non-shadow child.');
|
||||
}
|
||||
}
|
||||
// Ensure this block doesn't have any variable inputs.
|
||||
if (block.getVarModels().length) {
|
||||
throw Error('Shadow blocks cannot have variable references.');
|
||||
throw TypeError('Shadow blocks cannot have variable references.');
|
||||
}
|
||||
block.setShadow(true);
|
||||
}
|
||||
@@ -812,9 +815,9 @@ Blockly.Xml.domToFieldVariable_ = function(workspace, xml, text, field) {
|
||||
// This should never happen :)
|
||||
if (type != null && type !== variable.type) {
|
||||
throw Error('Serialized variable type with id \'' +
|
||||
variable.getId() + '\' had type ' + variable.type + ', and ' +
|
||||
'does not match variable field that references it: ' +
|
||||
Blockly.Xml.domToText(xml) + '.');
|
||||
variable.getId() + '\' had type ' + variable.type + ', and ' +
|
||||
'does not match variable field that references it: ' +
|
||||
Blockly.Xml.domToText(xml) + '.');
|
||||
}
|
||||
|
||||
field.setValue(variable.getId());
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
goog.provide('Blockly.ZoomControls');
|
||||
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('goog.dom');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
|
||||
/**
|
||||
@@ -122,7 +122,7 @@ Blockly.ZoomControls.prototype.init = function(bottom) {
|
||||
*/
|
||||
Blockly.ZoomControls.prototype.dispose = function() {
|
||||
if (this.svgGroup_) {
|
||||
goog.dom.removeNode(this.svgGroup_);
|
||||
this.svgGroup_.parentNode.removeChild(this.svgGroup_);
|
||||
this.svgGroup_ = null;
|
||||
}
|
||||
this.workspace_ = null;
|
||||
@@ -302,7 +302,11 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) {
|
||||
Blockly.bindEventWithChecks_(zoomresetSvg, 'mousedown', null, function(e) {
|
||||
ws.markFocused();
|
||||
ws.setScale(ws.options.zoomOptions.startScale);
|
||||
ws.beginCanvasTransition();
|
||||
ws.scrollCenter();
|
||||
setTimeout(function() {
|
||||
ws.endCanvasTransition();
|
||||
}, 500);
|
||||
Blockly.Touch.clearTouchIdentifier(); // Don't block future drags.
|
||||
e.stopPropagation(); // Don't start a workspace scroll.
|
||||
e.preventDefault(); // Stop double-clicking from selecting text.
|
||||
|
||||
+15
-15
@@ -28,16 +28,16 @@ Blockly.Dart.ORDER_UNARY_POSTFIX];if("GET_REMOVE"==c)return[e+".removeAt(0)",Blo
|
||||
if("REMOVE"==c)return c=Blockly.Dart.variableDB_.getDistinctName("tmp_x",Blockly.Variables.NAME_TYPE),"int "+c+" = new Math.Random().nextInt("+e+".length);\n"+(e+".removeAt("+c+");\n");if("GET"==c)return c=Blockly.Dart.provideFunction_("lists_get_random_item",["dynamic "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List my_list) {"," int x = new Math.Random().nextInt(my_list.length);"," return my_list[x];","}"]),[c+"("+e+")",Blockly.Dart.ORDER_UNARY_POSTFIX];if("GET_REMOVE"==c)return c=Blockly.Dart.provideFunction_("lists_remove_random_item",
|
||||
["dynamic "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List my_list) {"," int x = new Math.Random().nextInt(my_list.length);"," return my_list.removeAt(x);","}"]),[c+"("+e+")",Blockly.Dart.ORDER_UNARY_POSTFIX]}else{if("RANDOM"==d)return Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;",a=b(),c=Blockly.Dart.variableDB_.getDistinctName("tmp_x",Blockly.Variables.NAME_TYPE),a+("int "+c+" = new Math.Random().nextInt("+e+".length);\n")+(e+".removeAt("+c+");\n");if("REMOVE"==c)return d=
|
||||
Blockly.Dart.getAdjusted(a,"AT",1,!1,Blockly.Dart.ORDER_ADDITIVE),a=b(),a+=e+".removeAt("+e+".length - "+d+");\n";if("GET"==c)return d=Blockly.Dart.getAdjusted(a,"AT",1),c=Blockly.Dart.provideFunction_("lists_get_from_end",["dynamic "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List my_list, num x) {"," x = my_list.length - x;"," return my_list[x];","}"]),[c+"("+e+", "+d+")",Blockly.Dart.ORDER_UNARY_POSTFIX];if("GET_REMOVE"==c)return d=Blockly.Dart.getAdjusted(a,"AT",1),c=Blockly.Dart.provideFunction_("lists_remove_from_end",
|
||||
["dynamic "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List my_list, num x) {"," x = my_list.length - x;"," return my_list.removeAt(x);","}"]),[c+"("+e+", "+d+")",Blockly.Dart.ORDER_UNARY_POSTFIX]}throw"Unhandled combination (lists_getIndex).";};
|
||||
["dynamic "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List my_list, num x) {"," x = my_list.length - x;"," return my_list.removeAt(x);","}"]),[c+"("+e+", "+d+")",Blockly.Dart.ORDER_UNARY_POSTFIX]}throw Error("Unhandled combination (lists_getIndex).");};
|
||||
Blockly.Dart.lists_setIndex=function(a){function b(){if(e.match(/^\w+$/))return"";var a=Blockly.Dart.variableDB_.getDistinctName("tmp_list",Blockly.Variables.NAME_TYPE),b="List "+a+" = "+e+";\n";e=a;return b}var c=a.getFieldValue("MODE")||"GET",d=a.getFieldValue("WHERE")||"FROM_START",e=Blockly.Dart.valueToCode(a,"LIST",Blockly.Dart.ORDER_UNARY_POSTFIX)||"[]",f=Blockly.Dart.valueToCode(a,"TO",Blockly.Dart.ORDER_ASSIGNMENT)||"null";switch(d){case "FIRST":if("SET"==c)return e+"[0] = "+f+";\n";if("INSERT"==
|
||||
c)return e+".insert(0, "+f+");\n";break;case "LAST":if("SET"==c)return a=b(),a+(e+"["+e+".length - 1] = "+f+";\n");if("INSERT"==c)return e+".add("+f+");\n";break;case "FROM_START":d=Blockly.Dart.getAdjusted(a,"AT");if("SET"==c)return e+"["+d+"] = "+f+";\n";if("INSERT"==c)return e+".insert("+d+", "+f+");\n";break;case "FROM_END":d=Blockly.Dart.getAdjusted(a,"AT",1,!1,Blockly.Dart.ORDER_ADDITIVE);a=b();if("SET"==c)return a+(e+"["+e+".length - "+d+"] = "+f+";\n");if("INSERT"==c)return a+(e+".insert("+
|
||||
e+".length - "+d+", "+f+");\n");break;case "RANDOM":Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";a=b();d=Blockly.Dart.variableDB_.getDistinctName("tmp_x",Blockly.Variables.NAME_TYPE);a+="int "+d+" = new Math.Random().nextInt("+e+".length);\n";if("SET"==c)return a+(e+"["+d+"] = "+f+";\n");if("INSERT"==c)return a+(e+".insert("+d+", "+f+");\n")}throw"Unhandled combination (lists_setIndex).";};
|
||||
Blockly.Dart.lists_getSublist=function(a){var b=Blockly.Dart.valueToCode(a,"LIST",Blockly.Dart.ORDER_UNARY_POSTFIX)||"[]",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2");if(b.match(/^\w+$/)||"FROM_END"!=c&&"FROM_START"==d){switch(c){case "FROM_START":var e=Blockly.Dart.getAdjusted(a,"AT1");break;case "FROM_END":e=Blockly.Dart.getAdjusted(a,"AT1",1,!1,Blockly.Dart.ORDER_ADDITIVE);e=b+".length - "+e;break;case "FIRST":e="0";break;default:throw"Unhandled option (lists_getSublist).";}switch(d){case "FROM_START":var f=
|
||||
Blockly.Dart.getAdjusted(a,"AT2",1);break;case "FROM_END":f=Blockly.Dart.getAdjusted(a,"AT2",0,!1,Blockly.Dart.ORDER_ADDITIVE);f=b+".length - "+f;break;case "LAST":break;default:throw"Unhandled option (lists_getSublist).";}a="LAST"==d?b+".sublist("+e+")":b+".sublist("+e+", "+f+")"}else e=Blockly.Dart.getAdjusted(a,"AT1"),f=Blockly.Dart.getAdjusted(a,"AT2"),a=Blockly.Dart.provideFunction_("lists_get_sublist",["List "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(list, where1, at1, where2, at2) {"," int getAt(where, at) {",
|
||||
" if (where == 'FROM_END') {"," at = list.length - 1 - at;"," } else if (where == 'FIRST') {"," at = 0;"," } else if (where == 'LAST') {"," at = list.length - 1;"," } else if (where != 'FROM_START') {"," throw 'Unhandled option (lists_getSublist).';"," }"," return at;"," }"," at1 = getAt(where1, at1);"," at2 = getAt(where2, at2) + 1;"," return list.sublist(at1, at2);","}"])+"("+b+", '"+c+"', "+e+", '"+d+"', "+f+")";return[a,Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
e+".length - "+d+", "+f+");\n");break;case "RANDOM":Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";a=b();d=Blockly.Dart.variableDB_.getDistinctName("tmp_x",Blockly.Variables.NAME_TYPE);a+="int "+d+" = new Math.Random().nextInt("+e+".length);\n";if("SET"==c)return a+(e+"["+d+"] = "+f+";\n");if("INSERT"==c)return a+(e+".insert("+d+", "+f+");\n")}throw Error("Unhandled combination (lists_setIndex).");};
|
||||
Blockly.Dart.lists_getSublist=function(a){var b=Blockly.Dart.valueToCode(a,"LIST",Blockly.Dart.ORDER_UNARY_POSTFIX)||"[]",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2");if(b.match(/^\w+$/)||"FROM_END"!=c&&"FROM_START"==d){switch(c){case "FROM_START":var e=Blockly.Dart.getAdjusted(a,"AT1");break;case "FROM_END":e=Blockly.Dart.getAdjusted(a,"AT1",1,!1,Blockly.Dart.ORDER_ADDITIVE);e=b+".length - "+e;break;case "FIRST":e="0";break;default:throw Error("Unhandled option (lists_getSublist).");}switch(d){case "FROM_START":var f=
|
||||
Blockly.Dart.getAdjusted(a,"AT2",1);break;case "FROM_END":f=Blockly.Dart.getAdjusted(a,"AT2",0,!1,Blockly.Dart.ORDER_ADDITIVE);f=b+".length - "+f;break;case "LAST":break;default:throw Error("Unhandled option (lists_getSublist).");}a="LAST"==d?b+".sublist("+e+")":b+".sublist("+e+", "+f+")"}else e=Blockly.Dart.getAdjusted(a,"AT1"),f=Blockly.Dart.getAdjusted(a,"AT2"),a=Blockly.Dart.provideFunction_("lists_get_sublist",["List "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(list, where1, at1, where2, at2) {",
|
||||
" int getAt(where, at) {"," if (where == 'FROM_END') {"," at = list.length - 1 - at;"," } else if (where == 'FIRST') {"," at = 0;"," } else if (where == 'LAST') {"," at = list.length - 1;"," } else if (where != 'FROM_START') {"," throw 'Unhandled option (lists_getSublist).';"," }"," return at;"," }"," at1 = getAt(where1, at1);"," at2 = getAt(where2, at2) + 1;"," return list.sublist(at1, at2);","}"])+"("+b+", '"+c+"', "+e+", '"+d+"', "+f+")";return[a,Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.lists_sort=function(a){var b=Blockly.Dart.valueToCode(a,"LIST",Blockly.Dart.ORDER_NONE)||"[]",c="1"===a.getFieldValue("DIRECTION")?1:-1;a=a.getFieldValue("TYPE");return[Blockly.Dart.provideFunction_("lists_sort",["List "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(list, type, direction) {"," var compareFuncs = {",' "NUMERIC": (a, b) => direction * a.compareTo(b),',' "TEXT": (a, b) => direction * a.toString().compareTo(b.toString()),',' "IGNORE_CASE": '," (a, b) => direction * ",
|
||||
" a.toString().toLowerCase().compareTo(b.toString().toLowerCase())"," };"," list = new List.from(list);"," var compare = compareFuncs[type];"," list.sort(compare);"," return list;","}"])+"("+b+', "'+a+'", '+c+")",Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.lists_split=function(a){var b=Blockly.Dart.valueToCode(a,"INPUT",Blockly.Dart.ORDER_UNARY_POSTFIX),c=Blockly.Dart.valueToCode(a,"DELIM",Blockly.Dart.ORDER_NONE)||"''";a=a.getFieldValue("MODE");if("SPLIT"==a)b||(b="''"),a="split";else if("JOIN"==a)b||(b="[]"),a="join";else throw"Unknown mode: "+a;return[b+"."+a+"("+c+")",Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.lists_split=function(a){var b=Blockly.Dart.valueToCode(a,"INPUT",Blockly.Dart.ORDER_UNARY_POSTFIX),c=Blockly.Dart.valueToCode(a,"DELIM",Blockly.Dart.ORDER_NONE)||"''";a=a.getFieldValue("MODE");if("SPLIT"==a)b||(b="''"),a="split";else if("JOIN"==a)b||(b="[]"),a="join";else throw Error("Unknown mode: "+a);return[b+"."+a+"("+c+")",Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.lists_reverse=function(a){return["new List.from("+(Blockly.Dart.valueToCode(a,"LIST",Blockly.Dart.ORDER_NONE)||"[]")+".reversed)",Blockly.Dart.ORDER_UNARY_POSTFIX]};Blockly.Dart.logic={};Blockly.Dart.controls_if=function(a){var b=0,c="";do{var d=Blockly.Dart.valueToCode(a,"IF"+b,Blockly.Dart.ORDER_NONE)||"false";var e=Blockly.Dart.statementToCode(a,"DO"+b);c+=(0<b?"else ":"")+"if ("+d+") {\n"+e+"}";++b}while(a.getInput("IF"+b));a.getInput("ELSE")&&(e=Blockly.Dart.statementToCode(a,"ELSE"),c+=" else {\n"+e+"}");return c+"\n"};Blockly.Dart.controls_ifelse=Blockly.Dart.controls_if;
|
||||
Blockly.Dart.logic_compare=function(a){var b={EQ:"==",NEQ:"!=",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getFieldValue("OP")],c="=="==b||"!="==b?Blockly.Dart.ORDER_EQUALITY:Blockly.Dart.ORDER_RELATIONAL,d=Blockly.Dart.valueToCode(a,"A",c)||"0";a=Blockly.Dart.valueToCode(a,"B",c)||"0";return[d+" "+b+" "+a,c]};
|
||||
Blockly.Dart.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"&&":"||",c="&&"==b?Blockly.Dart.ORDER_LOGICAL_AND:Blockly.Dart.ORDER_LOGICAL_OR,d=Blockly.Dart.valueToCode(a,"A",c);a=Blockly.Dart.valueToCode(a,"B",c);if(d||a){var e="&&"==b?"true":"false";d||(d=e);a||(a=e)}else a=d="false";return[d+" "+b+" "+a,c]};Blockly.Dart.logic_negate=function(a){var b=Blockly.Dart.ORDER_UNARY_PREFIX;return["!"+(Blockly.Dart.valueToCode(a,"BOOL",b)||"true"),b]};
|
||||
@@ -48,12 +48,12 @@ Blockly.Dart.controls_for=function(a){var b=Blockly.Dart.variableDB_.getName(a.g
|
||||
parseFloat(d);a="for ("+b+" = "+c+"; "+b+(g?" <= ":" >= ")+d+"; "+b;b=Math.abs(parseFloat(e));a=(1==b?a+(g?"++":"--"):a+((g?" += ":" -= ")+b))+(") {\n"+f+"}\n")}else a="",g=c,c.match(/^\w+$/)||Blockly.isNumber(c)||(g=Blockly.Dart.variableDB_.getDistinctName(b+"_start",Blockly.Variables.NAME_TYPE),a+="var "+g+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.Dart.variableDB_.getDistinctName(b+"_end",Blockly.Variables.NAME_TYPE),a+="var "+c+" = "+d+";\n"),d=Blockly.Dart.variableDB_.getDistinctName(b+
|
||||
"_inc",Blockly.Variables.NAME_TYPE),a+="num "+d+" = ",a=Blockly.isNumber(e)?a+(Math.abs(e)+";\n"):a+("("+e+").abs();\n"),a=a+("if ("+g+" > "+c+") {\n")+(Blockly.Dart.INDENT+d+" = -"+d+";\n"),a+="}\n",a+="for ("+b+" = "+g+"; "+d+" >= 0 ? "+b+" <= "+c+" : "+b+" >= "+c+"; "+b+" += "+d+") {\n"+f+"}\n";return a};
|
||||
Blockly.Dart.controls_forEach=function(a){var b=Blockly.Dart.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Dart.valueToCode(a,"LIST",Blockly.Dart.ORDER_ASSIGNMENT)||"[]",d=Blockly.Dart.statementToCode(a,"DO");d=Blockly.Dart.addLoopTrap(d,a.id);return"for (var "+b+" in "+c+") {\n"+d+"}\n"};
|
||||
Blockly.Dart.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"break;\n";case "CONTINUE":return"continue;\n"}throw"Unknown flow statement.";};Blockly.Dart.math={};Blockly.Dart.addReservedWords("Math");Blockly.Dart.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));if(Infinity==a){a="double.INFINITY";var b=Blockly.Dart.ORDER_UNARY_POSTFIX}else-Infinity==a?(a="-double.INFINITY",b=Blockly.Dart.ORDER_UNARY_PREFIX):b=0>a?Blockly.Dart.ORDER_UNARY_PREFIX:Blockly.Dart.ORDER_ATOMIC;return[a,b]};
|
||||
Blockly.Dart.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"break;\n";case "CONTINUE":return"continue;\n"}throw Error("Unknown flow statement.");};Blockly.Dart.math={};Blockly.Dart.addReservedWords("Math");Blockly.Dart.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));if(Infinity==a){a="double.INFINITY";var b=Blockly.Dart.ORDER_UNARY_POSTFIX}else-Infinity==a?(a="-double.INFINITY",b=Blockly.Dart.ORDER_UNARY_PREFIX):b=0>a?Blockly.Dart.ORDER_UNARY_PREFIX:Blockly.Dart.ORDER_ATOMIC;return[a,b]};
|
||||
Blockly.Dart.math_arithmetic=function(a){var b={ADD:[" + ",Blockly.Dart.ORDER_ADDITIVE],MINUS:[" - ",Blockly.Dart.ORDER_ADDITIVE],MULTIPLY:[" * ",Blockly.Dart.ORDER_MULTIPLICATIVE],DIVIDE:[" / ",Blockly.Dart.ORDER_MULTIPLICATIVE],POWER:[null,Blockly.Dart.ORDER_NONE]}[a.getFieldValue("OP")],c=b[0];b=b[1];var d=Blockly.Dart.valueToCode(a,"A",b)||"0";a=Blockly.Dart.valueToCode(a,"B",b)||"0";return c?[d+c+a,b]:(Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;",["Math.pow("+d+", "+
|
||||
a+")",Blockly.Dart.ORDER_UNARY_POSTFIX])};
|
||||
Blockly.Dart.math_single=function(a){var b=a.getFieldValue("OP");if("NEG"==b)return a=Blockly.Dart.valueToCode(a,"NUM",Blockly.Dart.ORDER_UNARY_PREFIX)||"0","-"==a[0]&&(a=" "+a),["-"+a,Blockly.Dart.ORDER_UNARY_PREFIX];Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";a="ABS"==b||"ROUND"==b.substring(0,5)?Blockly.Dart.valueToCode(a,"NUM",Blockly.Dart.ORDER_UNARY_POSTFIX)||"0":"SIN"==b||"COS"==b||"TAN"==b?Blockly.Dart.valueToCode(a,"NUM",Blockly.Dart.ORDER_MULTIPLICATIVE)||"0":
|
||||
Blockly.Dart.valueToCode(a,"NUM",Blockly.Dart.ORDER_NONE)||"0";switch(b){case "ABS":var c=a+".abs()";break;case "ROOT":c="Math.sqrt("+a+")";break;case "LN":c="Math.log("+a+")";break;case "EXP":c="Math.exp("+a+")";break;case "POW10":c="Math.pow(10,"+a+")";break;case "ROUND":c=a+".round()";break;case "ROUNDUP":c=a+".ceil()";break;case "ROUNDDOWN":c=a+".floor()";break;case "SIN":c="Math.sin("+a+" / 180 * Math.PI)";break;case "COS":c="Math.cos("+a+" / 180 * Math.PI)";break;case "TAN":c="Math.tan("+a+
|
||||
" / 180 * Math.PI)"}if(c)return[c,Blockly.Dart.ORDER_UNARY_POSTFIX];switch(b){case "LOG10":c="Math.log("+a+") / Math.log(10)";break;case "ASIN":c="Math.asin("+a+") / Math.PI * 180";break;case "ACOS":c="Math.acos("+a+") / Math.PI * 180";break;case "ATAN":c="Math.atan("+a+") / Math.PI * 180";break;default:throw"Unknown math operator: "+b;}return[c,Blockly.Dart.ORDER_MULTIPLICATIVE]};
|
||||
" / 180 * Math.PI)"}if(c)return[c,Blockly.Dart.ORDER_UNARY_POSTFIX];switch(b){case "LOG10":c="Math.log("+a+") / Math.log(10)";break;case "ASIN":c="Math.asin("+a+") / Math.PI * 180";break;case "ACOS":c="Math.acos("+a+") / Math.PI * 180";break;case "ATAN":c="Math.atan("+a+") / Math.PI * 180";break;default:throw Error("Unknown math operator: "+b);}return[c,Blockly.Dart.ORDER_MULTIPLICATIVE]};
|
||||
Blockly.Dart.math_constant=function(a){var b={PI:["Math.PI",Blockly.Dart.ORDER_UNARY_POSTFIX],E:["Math.E",Blockly.Dart.ORDER_UNARY_POSTFIX],GOLDEN_RATIO:["(1 + Math.sqrt(5)) / 2",Blockly.Dart.ORDER_MULTIPLICATIVE],SQRT2:["Math.SQRT2",Blockly.Dart.ORDER_UNARY_POSTFIX],SQRT1_2:["Math.SQRT1_2",Blockly.Dart.ORDER_UNARY_POSTFIX],INFINITY:["double.INFINITY",Blockly.Dart.ORDER_ATOMIC]};a=a.getFieldValue("CONSTANT");"INFINITY"!=a&&(Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;");
|
||||
return b[a]};
|
||||
Blockly.Dart.math_number_property=function(a){var b=Blockly.Dart.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Dart.ORDER_MULTIPLICATIVE);if(!b)return["false",Blockly.Python.ORDER_ATOMIC];var c=a.getFieldValue("PROPERTY");if("PRIME"==c)return Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;",[Blockly.Dart.provideFunction_("math_isPrime",["bool "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(n) {"," // https://en.wikipedia.org/wiki/Primality_test#Naive_methods"," if (n == 2 || n == 3) {"," return true;",
|
||||
@@ -67,8 +67,8 @@ Blockly.Dart.math_on_list=function(a){var b=a.getFieldValue("OP");a=Blockly.Dart
|
||||
" if (localList.length % 2 == 1) {"," return localList[index];"," } else {"," return (localList[index - 1] + localList[index]) / 2;"," }","}"]);b=b+"("+a+")";break;case "MODE":Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";b=Blockly.Dart.provideFunction_("math_modes",["List "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List values) {"," List modes = [];"," List counts = [];"," int maxCount = 0;"," for (int i = 0; i < values.length; i++) {"," var value = values[i];",
|
||||
" bool found = false;"," int thisCount;"," for (int j = 0; j < counts.length; j++) {"," if (counts[j][0] == value) {"," thisCount = ++counts[j][1];"," found = true;"," break;"," }"," }"," if (!found) {"," counts.add([value, 1]);"," thisCount = 1;"," }"," maxCount = Math.max(thisCount, maxCount);"," }"," for (int j = 0; j < counts.length; j++) {"," if (counts[j][1] == maxCount) {"," modes.add(counts[j][0]);"," }"," }"," return modes;",
|
||||
"}"]);b=b+"("+a+")";break;case "STD_DEV":Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";b=Blockly.Dart.provideFunction_("math_standard_deviation",["num "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List myList) {"," // First filter list for numbers only."," List numbers = new List.from(myList);"," numbers.removeWhere((a) => a is! num);"," if (numbers.isEmpty) return null;"," num n = numbers.length;"," num sum = 0;"," numbers.forEach((x) => sum += x);"," num mean = sum / n;",
|
||||
" num sumSquare = 0;"," numbers.forEach((x) => sumSquare += Math.pow(x - mean, 2));"," return Math.sqrt(sumSquare / n);","}"]);b=b+"("+a+")";break;case "RANDOM":Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";b=Blockly.Dart.provideFunction_("math_random_item",["dynamic "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List myList) {"," int x = new Math.Random().nextInt(myList.length);"," return myList[x];","}"]);b=b+"("+a+")";break;default:throw"Unknown operator: "+b;}return[b,
|
||||
Blockly.Dart.ORDER_UNARY_POSTFIX]};Blockly.Dart.math_modulo=function(a){var b=Blockly.Dart.valueToCode(a,"DIVIDEND",Blockly.Dart.ORDER_MULTIPLICATIVE)||"0";a=Blockly.Dart.valueToCode(a,"DIVISOR",Blockly.Dart.ORDER_MULTIPLICATIVE)||"0";return[b+" % "+a,Blockly.Dart.ORDER_MULTIPLICATIVE]};
|
||||
" num sumSquare = 0;"," numbers.forEach((x) => sumSquare += Math.pow(x - mean, 2));"," return Math.sqrt(sumSquare / n);","}"]);b=b+"("+a+")";break;case "RANDOM":Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";b=Blockly.Dart.provideFunction_("math_random_item",["dynamic "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(List myList) {"," int x = new Math.Random().nextInt(myList.length);"," return myList[x];","}"]);b=b+"("+a+")";break;default:throw Error("Unknown operator: "+
|
||||
b);}return[b,Blockly.Dart.ORDER_UNARY_POSTFIX]};Blockly.Dart.math_modulo=function(a){var b=Blockly.Dart.valueToCode(a,"DIVIDEND",Blockly.Dart.ORDER_MULTIPLICATIVE)||"0";a=Blockly.Dart.valueToCode(a,"DIVISOR",Blockly.Dart.ORDER_MULTIPLICATIVE)||"0";return[b+" % "+a,Blockly.Dart.ORDER_MULTIPLICATIVE]};
|
||||
Blockly.Dart.math_constrain=function(a){Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";var b=Blockly.Dart.valueToCode(a,"VALUE",Blockly.Dart.ORDER_NONE)||"0",c=Blockly.Dart.valueToCode(a,"LOW",Blockly.Dart.ORDER_NONE)||"0";a=Blockly.Dart.valueToCode(a,"HIGH",Blockly.Dart.ORDER_NONE)||"double.INFINITY";return["Math.min(Math.max("+b+", "+c+"), "+a+")",Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.math_random_int=function(a){Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";var b=Blockly.Dart.valueToCode(a,"FROM",Blockly.Dart.ORDER_NONE)||"0";a=Blockly.Dart.valueToCode(a,"TO",Blockly.Dart.ORDER_NONE)||"0";return[Blockly.Dart.provideFunction_("math_random_int",["int "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(num a, num b) {"," if (a > b) {"," // Swap a and b to ensure a is smaller."," num c = a;"," a = b;"," b = c;"," }"," return new Math.Random().nextInt(b - a + 1) + a;",
|
||||
"}"])+"("+b+", "+a+")",Blockly.Dart.ORDER_UNARY_POSTFIX]};Blockly.Dart.math_random_float=function(a){Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";return["new Math.Random().nextDouble()",Blockly.Dart.ORDER_UNARY_POSTFIX]};Blockly.Dart.procedures={};
|
||||
@@ -82,11 +82,11 @@ Blockly.Dart.text_append=function(a){var b=Blockly.Dart.variableDB_.getName(a.ge
|
||||
Blockly.Dart.text_isEmpty=function(a){return[(Blockly.Dart.valueToCode(a,"VALUE",Blockly.Dart.ORDER_UNARY_POSTFIX)||"''")+".isEmpty",Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.text_indexOf=function(a){var b="FIRST"==a.getFieldValue("END")?"indexOf":"lastIndexOf",c=Blockly.Dart.valueToCode(a,"FIND",Blockly.Dart.ORDER_NONE)||"''";b=(Blockly.Dart.valueToCode(a,"VALUE",Blockly.Dart.ORDER_UNARY_POSTFIX)||"''")+"."+b+"("+c+")";return a.workspace.options.oneBasedIndex?[b+" + 1",Blockly.Dart.ORDER_ADDITIVE]:[b,Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.text_charAt=function(a){var b=a.getFieldValue("WHERE")||"FROM_START",c=Blockly.Dart.valueToCode(a,"VALUE",Blockly.Dart.ORDER_UNARY_POSTFIX)||"''";switch(b){case "FIRST":return[c+"[0]",Blockly.Dart.ORDER_UNARY_POSTFIX];case "FROM_START":return a=Blockly.Dart.getAdjusted(a,"AT"),[c+"["+a+"]",Blockly.Dart.ORDER_UNARY_POSTFIX];case "LAST":case "FROM_END":return a=Blockly.Dart.getAdjusted(a,"AT",1),b=Blockly.Dart.provideFunction_("text_get_from_end",["String "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+
|
||||
"(String text, num x) {"," return text[text.length - x];","}"]),[b+"("+c+", "+a+")",Blockly.Dart.ORDER_UNARY_POSTFIX];case "RANDOM":return Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;",b=Blockly.Dart.provideFunction_("text_random_letter",["String "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(String text) {"," int x = new Math.Random().nextInt(text.length);"," return text[x];","}"]),[b+"("+c+")",Blockly.Dart.ORDER_UNARY_POSTFIX]}throw"Unhandled option (text_charAt).";};
|
||||
Blockly.Dart.text_getSubstring=function(a){var b=Blockly.Dart.valueToCode(a,"STRING",Blockly.Dart.ORDER_UNARY_POSTFIX)||"''",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2");if("FIRST"==c&&"LAST"==d)a=b;else if(b.match(/^'?\w+'?$/)||"FROM_END"!=c&&"FROM_START"==d){switch(c){case "FROM_START":var e=Blockly.Dart.getAdjusted(a,"AT1");break;case "FROM_END":e=Blockly.Dart.getAdjusted(a,"AT1",1,!1,Blockly.Dart.ORDER_ADDITIVE);e=b+".length - "+e;break;case "FIRST":e="0";break;default:throw"Unhandled option (text_getSubstring).";
|
||||
}switch(d){case "FROM_START":var f=Blockly.Dart.getAdjusted(a,"AT2",1);break;case "FROM_END":f=Blockly.Dart.getAdjusted(a,"AT2",0,!1,Blockly.Dart.ORDER_ADDITIVE);f=b+".length - "+f;break;case "LAST":break;default:throw"Unhandled option (text_getSubstring).";}a="LAST"==d?b+".substring("+e+")":b+".substring("+e+", "+f+")"}else e=Blockly.Dart.getAdjusted(a,"AT1"),f=Blockly.Dart.getAdjusted(a,"AT2"),a=Blockly.Dart.provideFunction_("text_get_substring",["List "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+
|
||||
"(text, where1, at1, where2, at2) {"," int getAt(where, at) {"," if (where == 'FROM_END') {"," at = text.length - 1 - at;"," } else if (where == 'FIRST') {"," at = 0;"," } else if (where == 'LAST') {"," at = text.length - 1;"," } else if (where != 'FROM_START') {"," throw 'Unhandled option (text_getSubstring).';"," }"," return at;"," }"," at1 = getAt(where1, at1);"," at2 = getAt(where2, at2) + 1;"," return text.substring(at1, at2);","}"])+"("+b+", '"+c+"', "+
|
||||
e+", '"+d+"', "+f+")";return[a,Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
"(String text, num x) {"," return text[text.length - x];","}"]),[b+"("+c+", "+a+")",Blockly.Dart.ORDER_UNARY_POSTFIX];case "RANDOM":return Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;",b=Blockly.Dart.provideFunction_("text_random_letter",["String "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(String text) {"," int x = new Math.Random().nextInt(text.length);"," return text[x];","}"]),[b+"("+c+")",Blockly.Dart.ORDER_UNARY_POSTFIX]}throw Error("Unhandled option (text_charAt).");
|
||||
};
|
||||
Blockly.Dart.text_getSubstring=function(a){var b=Blockly.Dart.valueToCode(a,"STRING",Blockly.Dart.ORDER_UNARY_POSTFIX)||"''",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2");if("FIRST"==c&&"LAST"==d)a=b;else if(b.match(/^'?\w+'?$/)||"FROM_END"!=c&&"FROM_START"==d){switch(c){case "FROM_START":var e=Blockly.Dart.getAdjusted(a,"AT1");break;case "FROM_END":e=Blockly.Dart.getAdjusted(a,"AT1",1,!1,Blockly.Dart.ORDER_ADDITIVE);e=b+".length - "+e;break;case "FIRST":e="0";break;default:throw Error("Unhandled option (text_getSubstring).");}switch(d){case "FROM_START":var f=
|
||||
Blockly.Dart.getAdjusted(a,"AT2",1);break;case "FROM_END":f=Blockly.Dart.getAdjusted(a,"AT2",0,!1,Blockly.Dart.ORDER_ADDITIVE);f=b+".length - "+f;break;case "LAST":break;default:throw Error("Unhandled option (text_getSubstring).");}a="LAST"==d?b+".substring("+e+")":b+".substring("+e+", "+f+")"}else e=Blockly.Dart.getAdjusted(a,"AT1"),f=Blockly.Dart.getAdjusted(a,"AT2"),a=Blockly.Dart.provideFunction_("text_get_substring",["List "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(text, where1, at1, where2, at2) {",
|
||||
" int getAt(where, at) {"," if (where == 'FROM_END') {"," at = text.length - 1 - at;"," } else if (where == 'FIRST') {"," at = 0;"," } else if (where == 'LAST') {"," at = text.length - 1;"," } else if (where != 'FROM_START') {"," throw 'Unhandled option (text_getSubstring).';"," }"," return at;"," }"," at1 = getAt(where1, at1);"," at2 = getAt(where2, at2) + 1;"," return text.substring(at1, at2);","}"])+"("+b+", '"+c+"', "+e+", '"+d+"', "+f+")";return[a,Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.text_changeCase=function(a){var b={UPPERCASE:".toUpperCase()",LOWERCASE:".toLowerCase()",TITLECASE:null}[a.getFieldValue("CASE")];a=Blockly.Dart.valueToCode(a,"TEXT",b?Blockly.Dart.ORDER_UNARY_POSTFIX:Blockly.Dart.ORDER_NONE)||"''";return[b?a+b:Blockly.Dart.provideFunction_("text_toTitleCase",["String "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"(String str) {"," RegExp exp = new RegExp(r'\\b');"," List<String> list = str.split(exp);"," final title = new StringBuffer();"," for (String part in list) {",
|
||||
" if (part.length > 0) {"," title.write(part[0].toUpperCase());"," if (part.length > 0) {"," title.write(part.substring(1).toLowerCase());"," }"," }"," }"," return title.toString();","}"])+"("+a+")",Blockly.Dart.ORDER_UNARY_POSTFIX]};
|
||||
Blockly.Dart.text_trim=function(a){var b={LEFT:".replaceFirst(new RegExp(r'^\\s+'), '')",RIGHT:".replaceFirst(new RegExp(r'\\s+$'), '')",BOTH:".trim()"}[a.getFieldValue("MODE")];return[(Blockly.Dart.valueToCode(a,"TEXT",Blockly.Dart.ORDER_UNARY_POSTFIX)||"''")+b,Blockly.Dart.ORDER_UNARY_POSTFIX]};Blockly.Dart.text_print=function(a){return"print("+(Blockly.Dart.valueToCode(a,"TEXT",Blockly.Dart.ORDER_NONE)||"''")+");\n"};
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
blocklyDiv.style.top = y + 'px';
|
||||
blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
|
||||
blocklyDiv.style.height = blocklyArea.offsetHeight + 'px';
|
||||
Blockly.svgResize(demoWorkspace);
|
||||
};
|
||||
window.addEventListener('resize', onresize, false);
|
||||
onresize();
|
||||
|
||||
@@ -243,7 +243,7 @@ Blockly.Dart['lists_getIndex'] = function(block) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw 'Unhandled combination (lists_getIndex).';
|
||||
throw Error('Unhandled combination (lists_getIndex).');
|
||||
};
|
||||
|
||||
Blockly.Dart['lists_setIndex'] = function(block) {
|
||||
@@ -323,7 +323,7 @@ Blockly.Dart['lists_setIndex'] = function(block) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw 'Unhandled combination (lists_setIndex).';
|
||||
throw Error('Unhandled combination (lists_setIndex).');
|
||||
};
|
||||
|
||||
Blockly.Dart['lists_getSublist'] = function(block) {
|
||||
@@ -348,7 +348,7 @@ Blockly.Dart['lists_getSublist'] = function(block) {
|
||||
var at1 = '0';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (lists_getSublist).';
|
||||
throw Error('Unhandled option (lists_getSublist).');
|
||||
}
|
||||
switch (where2) {
|
||||
case 'FROM_START':
|
||||
@@ -363,7 +363,7 @@ Blockly.Dart['lists_getSublist'] = function(block) {
|
||||
// There is no second index if LAST option is chosen.
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (lists_getSublist).';
|
||||
throw Error('Unhandled option (lists_getSublist).');
|
||||
}
|
||||
if (where2 == 'LAST') {
|
||||
var code = list + '.sublist(' + at1 + ')';
|
||||
@@ -445,7 +445,7 @@ Blockly.Dart['lists_split'] = function(block) {
|
||||
}
|
||||
var functionName = 'join';
|
||||
} else {
|
||||
throw 'Unknown mode: ' + mode;
|
||||
throw Error('Unknown mode: ' + mode);
|
||||
}
|
||||
var code = input + '.' + functionName + '(' + delimiter + ')';
|
||||
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];
|
||||
|
||||
@@ -159,5 +159,5 @@ Blockly.Dart['controls_flow_statements'] = function(block) {
|
||||
case 'CONTINUE':
|
||||
return 'continue;\n';
|
||||
}
|
||||
throw 'Unknown flow statement.';
|
||||
throw Error('Unknown flow statement.');
|
||||
};
|
||||
|
||||
@@ -160,7 +160,7 @@ Blockly.Dart['math_single'] = function(block) {
|
||||
code = 'Math.atan(' + arg + ') / Math.PI * 180';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown math operator: ' + operator;
|
||||
throw Error('Unknown math operator: ' + operator);
|
||||
}
|
||||
return [code, Blockly.Dart.ORDER_MULTIPLICATIVE];
|
||||
};
|
||||
@@ -426,7 +426,7 @@ Blockly.Dart['math_on_list'] = function(block) {
|
||||
code = functionName + '(' + list + ')';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown operator: ' + func;
|
||||
throw Error('Unknown operator: ' + func);
|
||||
}
|
||||
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];
|
||||
};
|
||||
|
||||
@@ -136,7 +136,7 @@ Blockly.Dart['text_charAt'] = function(block) {
|
||||
code = functionName + '(' + text + ')';
|
||||
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];
|
||||
}
|
||||
throw 'Unhandled option (text_charAt).';
|
||||
throw Error('Unhandled option (text_charAt).');
|
||||
};
|
||||
|
||||
Blockly.Dart['text_getSubstring'] = function(block) {
|
||||
@@ -164,7 +164,7 @@ Blockly.Dart['text_getSubstring'] = function(block) {
|
||||
var at1 = '0';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (text_getSubstring).';
|
||||
throw Error('Unhandled option (text_getSubstring).');
|
||||
}
|
||||
switch (where2) {
|
||||
case 'FROM_START':
|
||||
@@ -178,7 +178,7 @@ Blockly.Dart['text_getSubstring'] = function(block) {
|
||||
case 'LAST':
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (text_getSubstring).';
|
||||
throw Error('Unhandled option (text_getSubstring).');
|
||||
}
|
||||
if (where2 == 'LAST') {
|
||||
var code = text + '.substring(' + at1 + ')';
|
||||
|
||||
@@ -170,7 +170,7 @@ Blockly.JavaScript['lists_getIndex'] = function(block) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw 'Unhandled combination (lists_getIndex).';
|
||||
throw Error('Unhandled combination (lists_getIndex).');
|
||||
};
|
||||
|
||||
Blockly.JavaScript['lists_setIndex'] = function(block) {
|
||||
@@ -247,7 +247,7 @@ Blockly.JavaScript['lists_setIndex'] = function(block) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw 'Unhandled combination (lists_setIndex).';
|
||||
throw Error('Unhandled combination (lists_setIndex).');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -295,7 +295,7 @@ Blockly.JavaScript['lists_getSublist'] = function(block) {
|
||||
var at1 = '0';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (lists_getSublist).';
|
||||
throw Error('Unhandled option (lists_getSublist).');
|
||||
}
|
||||
switch (where2) {
|
||||
case 'FROM_START':
|
||||
@@ -310,7 +310,7 @@ Blockly.JavaScript['lists_getSublist'] = function(block) {
|
||||
var at2 = list + '.length';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (lists_getSublist).';
|
||||
throw Error('Unhandled option (lists_getSublist).');
|
||||
}
|
||||
code = list + '.slice(' + at1 + ', ' + at2 + ')';
|
||||
} else {
|
||||
@@ -387,7 +387,7 @@ Blockly.JavaScript['lists_split'] = function(block) {
|
||||
}
|
||||
var functionName = 'join';
|
||||
} else {
|
||||
throw 'Unknown mode: ' + mode;
|
||||
throw Error('Unknown mode: ' + mode);
|
||||
}
|
||||
var code = input + '.' + functionName + '(' + delimiter + ')';
|
||||
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
|
||||
|
||||
@@ -171,5 +171,5 @@ Blockly.JavaScript['controls_flow_statements'] = function(block) {
|
||||
case 'CONTINUE':
|
||||
return 'continue;\n';
|
||||
}
|
||||
throw 'Unknown flow statement.';
|
||||
throw Error('Unknown flow statement.');
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ goog.require('Blockly.JavaScript');
|
||||
Blockly.JavaScript['math_number'] = function(block) {
|
||||
// Numeric value.
|
||||
var code = parseFloat(block.getFieldValue('NUM'));
|
||||
var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC :
|
||||
var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC :
|
||||
Blockly.JavaScript.ORDER_UNARY_NEGATION;
|
||||
return [code, order];
|
||||
};
|
||||
@@ -140,7 +140,7 @@ Blockly.JavaScript['math_single'] = function(block) {
|
||||
code = 'Math.atan(' + arg + ') / Math.PI * 180';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown math operator: ' + operator;
|
||||
throw Error('Unknown math operator: ' + operator);
|
||||
}
|
||||
return [code, Blockly.JavaScript.ORDER_DIVISION];
|
||||
};
|
||||
@@ -357,7 +357,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
|
||||
code = functionName + '(' + list + ')';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown operator: ' + func;
|
||||
throw Error('Unknown operator: ' + func);
|
||||
}
|
||||
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
|
||||
};
|
||||
|
||||
@@ -137,7 +137,7 @@ Blockly.JavaScript['text_charAt'] = function(block) {
|
||||
var code = functionName + '(' + text + ')';
|
||||
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
|
||||
}
|
||||
throw 'Unhandled option (text_charAt).';
|
||||
throw Error('Unhandled option (text_charAt).');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -186,7 +186,7 @@ Blockly.JavaScript['text_getSubstring'] = function(block) {
|
||||
var at1 = '0';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (text_getSubstring).';
|
||||
throw Error('Unhandled option (text_getSubstring).');
|
||||
}
|
||||
switch (where2) {
|
||||
case 'FROM_START':
|
||||
@@ -201,7 +201,7 @@ Blockly.JavaScript['text_getSubstring'] = function(block) {
|
||||
var at2 = text + '.length';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (text_getSubstring).';
|
||||
throw Error('Unhandled option (text_getSubstring).');
|
||||
}
|
||||
code = text + '.slice(' + at1 + ', ' + at2 + ')';
|
||||
} else {
|
||||
|
||||
@@ -358,7 +358,7 @@ Blockly.Lua['lists_split'] = function(block) {
|
||||
}
|
||||
functionName = 'table.concat';
|
||||
} else {
|
||||
throw 'Unknown mode: ' + mode;
|
||||
throw Error('Unknown mode: ' + mode);
|
||||
}
|
||||
var code = functionName + '(' + input + ', ' + delimiter + ')';
|
||||
return [code, Blockly.Lua.ORDER_HIGH];
|
||||
|
||||
@@ -162,5 +162,5 @@ Blockly.Lua['controls_flow_statements'] = function(block) {
|
||||
case 'CONTINUE':
|
||||
return Blockly.Lua.CONTINUE_STATEMENT;
|
||||
}
|
||||
throw 'Unknown flow statement.';
|
||||
throw Error('Unknown flow statement.');
|
||||
};
|
||||
|
||||
@@ -123,7 +123,7 @@ Blockly.Lua['math_single'] = function(block) {
|
||||
code = 'math.deg(math.atan(' + arg + '))';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown math operator: ' + operator;
|
||||
throw Error('Unknown math operator: ' + operator);
|
||||
}
|
||||
return [code, Blockly.Lua.ORDER_HIGH];
|
||||
};
|
||||
@@ -383,7 +383,7 @@ Blockly.Lua['math_on_list'] = function(block) {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw 'Unknown operator: ' + func;
|
||||
throw Error('Unknown operator: ' + func);
|
||||
}
|
||||
return [functionName + '(' + list + ')', Blockly.Lua.ORDER_HIGH];
|
||||
};
|
||||
|
||||
@@ -149,7 +149,7 @@ Blockly.Lua['text_charAt'] = function(block) {
|
||||
} else if (where == 'FROM_END') {
|
||||
var start = '-' + at;
|
||||
} else {
|
||||
throw 'Unhandled option (text_charAt).';
|
||||
throw Error('Unhandled option (text_charAt).');
|
||||
}
|
||||
}
|
||||
if (start.match(/^-?\w*$/)) {
|
||||
@@ -185,7 +185,7 @@ Blockly.Lua['text_getSubstring'] = function(block) {
|
||||
} else if (where1 == 'FROM_END') {
|
||||
var start = '-' + at1;
|
||||
} else {
|
||||
throw 'Unhandled option (text_getSubstring)';
|
||||
throw Error('Unhandled option (text_getSubstring)');
|
||||
}
|
||||
|
||||
// Get end index.
|
||||
@@ -200,7 +200,7 @@ Blockly.Lua['text_getSubstring'] = function(block) {
|
||||
} else if (where2 == 'FROM_END') {
|
||||
var end = '-' + at2;
|
||||
} else {
|
||||
throw 'Unhandled option (text_getSubstring)';
|
||||
throw Error('Unhandled option (text_getSubstring)');
|
||||
}
|
||||
var code = 'string.sub(' + text + ', ' + start + ', ' + end + ')';
|
||||
return [code, Blockly.Lua.ORDER_HIGH];
|
||||
|
||||
@@ -255,7 +255,7 @@ Blockly.PHP['lists_getIndex'] = function(block) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw 'Unhandled combination (lists_getIndex).';
|
||||
throw Error('Unhandled combination (lists_getIndex).');
|
||||
};
|
||||
|
||||
Blockly.PHP['lists_setIndex'] = function(block) {
|
||||
@@ -355,7 +355,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw 'Unhandled combination (lists_setIndex).';
|
||||
throw Error('Unhandled combination (lists_setIndex).');
|
||||
};
|
||||
|
||||
Blockly.PHP['lists_getSublist'] = function(block) {
|
||||
@@ -383,7 +383,7 @@ Blockly.PHP['lists_getSublist'] = function(block) {
|
||||
var at1 = '0';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (lists_getSublist).';
|
||||
throw Error('Unhandled option (lists_getSublist).');
|
||||
}
|
||||
switch (where2) {
|
||||
case 'FROM_START':
|
||||
@@ -416,7 +416,7 @@ Blockly.PHP['lists_getSublist'] = function(block) {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (lists_getSublist).';
|
||||
throw Error('Unhandled option (lists_getSublist).');
|
||||
}
|
||||
code = 'array_slice(' + list + ', ' + at1 + ', ' + length + ')';
|
||||
} else {
|
||||
@@ -497,7 +497,7 @@ Blockly.PHP['lists_split'] = function(block) {
|
||||
}
|
||||
var functionName = 'implode';
|
||||
} else {
|
||||
throw 'Unknown mode: ' + mode;
|
||||
throw Error('Unknown mode: ' + mode);
|
||||
}
|
||||
var code = functionName + '(' + value_delim + ', ' + value_input + ')';
|
||||
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
|
||||
|
||||
@@ -160,5 +160,5 @@ Blockly.PHP['controls_flow_statements'] = function(block) {
|
||||
case 'CONTINUE':
|
||||
return 'continue;\n';
|
||||
}
|
||||
throw 'Unknown flow statement.';
|
||||
throw Error('Unknown flow statement.');
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ goog.require('Blockly.PHP');
|
||||
Blockly.PHP['math_number'] = function(block) {
|
||||
// Numeric value.
|
||||
var code = parseFloat(block.getFieldValue('NUM'));
|
||||
var order = code >= 0 ? Blockly.PHP.ORDER_ATOMIC :
|
||||
var order = code >= 0 ? Blockly.PHP.ORDER_ATOMIC :
|
||||
Blockly.PHP.ORDER_UNARY_NEGATION;
|
||||
if (code == Infinity) {
|
||||
code = 'INF';
|
||||
@@ -139,7 +139,7 @@ Blockly.PHP['math_single'] = function(block) {
|
||||
code = 'atan(' + arg + ') / pi() * 180';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown math operator: ' + operator;
|
||||
throw Error('Unknown math operator: ' + operator);
|
||||
}
|
||||
return [code, Blockly.PHP.ORDER_DIVISION];
|
||||
};
|
||||
@@ -321,7 +321,7 @@ Blockly.PHP['math_on_list'] = function(block) {
|
||||
code = functionName + '(' + list + ')';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown operator: ' + func;
|
||||
throw Error('Unknown operator: ' + func);
|
||||
}
|
||||
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
|
||||
};
|
||||
|
||||
@@ -152,7 +152,7 @@ Blockly.PHP['text_charAt'] = function(block) {
|
||||
code = functionName + '(' + text + ')';
|
||||
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
|
||||
}
|
||||
throw 'Unhandled option (text_charAt).';
|
||||
throw Error('Unhandled option (text_charAt).');
|
||||
};
|
||||
|
||||
Blockly.PHP['text_getSubstring'] = function(block) {
|
||||
|
||||
@@ -224,8 +224,7 @@ Blockly.Python.scrubNakedValue = function(line) {
|
||||
Blockly.Python.quote_ = function(string) {
|
||||
// Can't use goog.string.quote since % must also be escaped.
|
||||
string = string.replace(/\\/g, '\\\\')
|
||||
.replace(/\n/g, '\\\n')
|
||||
.replace(/\%/g, '\\%');
|
||||
.replace(/\n/g, '\\\n');
|
||||
|
||||
// Follow the CPython behaviour of repr() for a non-byte string.
|
||||
var quote = '\'';
|
||||
|
||||
@@ -183,7 +183,7 @@ Blockly.Python['lists_getIndex'] = function(block) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw 'Unhandled combination (lists_getIndex).';
|
||||
throw Error('Unhandled combination (lists_getIndex).');
|
||||
};
|
||||
|
||||
Blockly.Python['lists_setIndex'] = function(block) {
|
||||
@@ -254,7 +254,7 @@ Blockly.Python['lists_setIndex'] = function(block) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw 'Unhandled combination (lists_setIndex).';
|
||||
throw Error('Unhandled combination (lists_setIndex).');
|
||||
};
|
||||
|
||||
Blockly.Python['lists_getSublist'] = function(block) {
|
||||
@@ -277,7 +277,7 @@ Blockly.Python['lists_getSublist'] = function(block) {
|
||||
var at1 = '';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (lists_getSublist)';
|
||||
throw Error('Unhandled option (lists_getSublist)');
|
||||
}
|
||||
switch (where2) {
|
||||
case 'FROM_START':
|
||||
@@ -298,7 +298,7 @@ Blockly.Python['lists_getSublist'] = function(block) {
|
||||
var at2 = '';
|
||||
break;
|
||||
default:
|
||||
throw 'Unhandled option (lists_getSublist)';
|
||||
throw Error('Unhandled option (lists_getSublist)');
|
||||
}
|
||||
var code = list + '[' + at1 + ' : ' + at2 + ']';
|
||||
return [code, Blockly.Python.ORDER_MEMBER];
|
||||
@@ -349,7 +349,7 @@ Blockly.Python['lists_split'] = function(block) {
|
||||
Blockly.Python.ORDER_MEMBER) || '\'\'';
|
||||
var code = value_delim + '.join(' + value_input + ')';
|
||||
} else {
|
||||
throw 'Unknown mode: ' + mode;
|
||||
throw Error('Unknown mode: ' + mode);
|
||||
}
|
||||
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
|
||||
};
|
||||
|
||||
@@ -207,5 +207,5 @@ Blockly.Python['controls_flow_statements'] = function(block) {
|
||||
case 'CONTINUE':
|
||||
return 'continue\n';
|
||||
}
|
||||
throw 'Unknown flow statement.';
|
||||
throw Error('Unknown flow statement.');
|
||||
};
|
||||
|
||||
@@ -147,7 +147,7 @@ Blockly.Python['math_single'] = function(block) {
|
||||
code = 'math.atan(' + arg + ') / math.pi * 180';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown math operator: ' + operator;
|
||||
throw Error('Unknown math operator: ' + operator);
|
||||
}
|
||||
return [code, Blockly.Python.ORDER_MULTIPLICATIVE];
|
||||
};
|
||||
@@ -342,7 +342,7 @@ Blockly.Python['math_on_list'] = function(block) {
|
||||
code = 'random.choice(' + list + ')';
|
||||
break;
|
||||
default:
|
||||
throw 'Unknown operator: ' + func;
|
||||
throw Error('Unknown operator: ' + func);
|
||||
}
|
||||
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user