mirror of
https://github.com/google/blockly.git
synced 2026-05-03 10:30:13 +02:00
Merge branch 'master' into date-field
This commit is contained in:
@@ -868,7 +868,7 @@ Blockly.Connection.prototype.setCheck=function(a){a?(goog.isArray(a)||(a=[a]),th
|
||||
Blockly.Connection.prototype.neighbours_=function(a){function b(b){var f=d-c[b].x_,g=e-c[b].y_;Math.sqrt(f*f+g*g)<=a&&k.push(c[b]);return g<a}for(var c=this.dbList_[Blockly.OPPOSITE_TYPE[this.type]],d=this.x_,e=this.y_,f=0,g=c.length-2,h=g;f<h;)c[h].y_<e?f=h:g=h,h=Math.floor((f+g)/2);var g=f=h,k=[];if(c.length){for(;0<=f&&b(f);)f--;do g++;while(g<c.length&&b(g))}return k};
|
||||
Blockly.Connection.prototype.hideAll=function(){this.inDB_&&this.dbList_[this.type].removeConnection_(this);if(this.targetConnection)for(var a=this.targetBlock().getDescendants(),b=0;b<a.length;b++){for(var c=a[b],d=c.getConnections_(!0),e=0;e<d.length;e++){var f=d[e];f.inDB_&&this.dbList_[f.type].removeConnection_(f)}c=c.getIcons();for(d=0;d<c.length;d++)c[d].setVisible(!1)}};
|
||||
Blockly.Connection.prototype.unhideAll=function(){this.dbList_[this.type].addConnection_(this);this.hidden_=!1;var a=[];if(this.type!=Blockly.INPUT_VALUE&&this.type!=Blockly.NEXT_STATEMENT)return a;var b=this.targetBlock();if(b){var c;b.isCollapsed()?(c=[],b.outputConnection&&c.push(b.outputConnection),b.nextConnection&&c.push(b.nextConnection),b.previousConnection&&c.push(b.previousConnection)):c=b.getConnections_(!0);for(var d=0;d<c.length;d++)a.push.apply(a,c[d].unhideAll());0==a.length&&(a[0]=
|
||||
b)}return a};Blockly.ConnectionDB=function(){};Blockly.ConnectionDB.prototype=[];Blockly.ConnectionDB.constructor=Blockly.ConnectionDB;Blockly.ConnectionDB.prototype.addConnection_=function(a){if(a.inDB_)throw"Connection already in database.";for(var b=0,c=this.length;b<c;){var d=Math.floor((b+c)/2);if(this[d].y_<a.y_)b=d+1;else if(this[d].y_>a.y_)c=d;else{b=d;break}}this.splice(b,0,a);a.inDB_=!0};
|
||||
b)}return a};Blockly.ConnectionDB=function(){};Blockly.ConnectionDB.prototype=[];Blockly.ConnectionDB.constructor=Blockly.ConnectionDB;Blockly.ConnectionDB.prototype.addConnection_=function(a){if(a.inDB_)throw"Connection already in database.";if(!a.sourceBlock_.isInFlyout){for(var b=0,c=this.length;b<c;){var d=Math.floor((b+c)/2);if(this[d].y_<a.y_)b=d+1;else if(this[d].y_>a.y_)c=d;else{b=d;break}}this.splice(b,0,a);a.inDB_=!0}};
|
||||
Blockly.ConnectionDB.prototype.removeConnection_=function(a){if(!a.inDB_)throw"Connection not in database.";a.inDB_=!1;for(var b=0,c=this.length-2,d=c;b<d;)this[d].y_<a.y_?b=d:c=d,d=Math.floor((b+c)/2);for(c=b=d;0<=b&&this[b].y_==a.y_;){if(this[b]==a){this.splice(b,1);return}b--}do{if(this[c]==a){this.splice(c,1);return}c++}while(c<this.length&&this[c].y_==a.y_);throw"Unable to find connection in connectionDB.";};
|
||||
Blockly.ConnectionDB.init=function(a){var b=[];b[Blockly.INPUT_VALUE]=new Blockly.ConnectionDB;b[Blockly.OUTPUT_VALUE]=new Blockly.ConnectionDB;b[Blockly.NEXT_STATEMENT]=new Blockly.ConnectionDB;b[Blockly.PREVIOUS_STATEMENT]=new Blockly.ConnectionDB;a.connectionDBList=b};
|
||||
// Copyright 2012 Google Inc. Apache License 2.0
|
||||
|
||||
+66
-65
File diff suppressed because one or more lines are too long
+13
-11
@@ -299,6 +299,7 @@ Blockly.Blocks['logic_compare'] = {
|
||||
};
|
||||
return TOOLTIPS[op];
|
||||
});
|
||||
this.prevBlocks_ = [null, null];
|
||||
},
|
||||
/**
|
||||
* Called whenever anything on the workspace changes.
|
||||
@@ -312,19 +313,20 @@ Blockly.Blocks['logic_compare'] = {
|
||||
}
|
||||
var blockA = this.getInputTargetBlock('A');
|
||||
var blockB = this.getInputTargetBlock('B');
|
||||
// Keep track of which block was added second
|
||||
// (so the first block may be ejected upon mismatch).
|
||||
if (blockA && !blockB) {
|
||||
this.blockAPriority_ = false;
|
||||
} else if (!blockA && blockB) {
|
||||
this.blockAPriority_ = true;
|
||||
} else if (blockA && blockB &&
|
||||
// Kick blocks that existed prior to this change if they don't match.
|
||||
if (blockA && blockB &&
|
||||
!blockA.outputConnection.checkType_(blockB.outputConnection)) {
|
||||
// Mismatch between two inputs. Disconnect one and bump it away.
|
||||
var child = this.blockAPriority_ ? blockB : blockA;
|
||||
child.setParent(null);
|
||||
child.bumpNeighbours_();
|
||||
// Mismatch between two inputs. Disconnect previous and bump it away.
|
||||
for (var i = 0; i < this.prevBlocks_.length; i++) {
|
||||
var block = this.prevBlocks_[i];
|
||||
if (block === blockA || block === blockB) {
|
||||
block.setParent(null);
|
||||
block.bumpNeighbours_();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.prevBlocks_[0] = blockA;
|
||||
this.prevBlocks_[1] = blockB;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ b++;break;case "controls_if_else":d=this.getInput("ELSE");a.statementConnection_
|
||||
Blockly.Blocks.controls_if_elseif={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_ELSEIF_TITLE_ELSEIF);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSEIF_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.controls_if_else={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE);this.setPreviousStatement(!0);this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSE_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.logic_compare={init:function(){var a=Blockly.RTL?[["=","EQ"],["\u2260","NEQ"],[">","LT"],["\u2265","LTE"],["<","GT"],["\u2264","GTE"]]:[["=","EQ"],["\u2260","NEQ"],["<","LT"],["\u2264","LTE"],[">","GT"],["\u2265","GTE"]];this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.appendValueInput("A");this.appendValueInput("B").appendField(new Blockly.FieldDropdown(a),"OP");this.setInputsInline(!0);var b=this;this.setTooltip(function(){var a=
|
||||
b.getFieldValue("OP");return{EQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,NEQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,LT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,LTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,GT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,GTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE}[a]})},onchange:function(){if(this.workspace){var a=this.getInputTargetBlock("A"),b=this.getInputTargetBlock("B");a&&!b?this.blockAPriority_=!1:!a&&b?this.blockAPriority_=!0:a&&b&&!a.outputConnection.checkType_(b.outputConnection)&&
|
||||
(a=this.blockAPriority_?b:a,a.setParent(null),a.bumpNeighbours_())}}};
|
||||
b.getFieldValue("OP");return{EQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,NEQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,LT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,LTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,GT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,GTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE}[a]});this.prevBlocks_=[null,null]},onchange:function(){if(this.workspace){var a=this.getInputTargetBlock("A"),b=this.getInputTargetBlock("B");if(a&&b&&!a.outputConnection.checkType_(b.outputConnection))for(var c=0;c<this.prevBlocks_.length;c++){var d=
|
||||
this.prevBlocks_[c];if(d===a||d===b)d.setParent(null),d.bumpNeighbours_()}this.prevBlocks_[0]=a;this.prevBlocks_[1]=b}}};
|
||||
Blockly.Blocks.logic_operation={init:function(){var a=[[Blockly.Msg.LOGIC_OPERATION_AND,"AND"],[Blockly.Msg.LOGIC_OPERATION_OR,"OR"]];this.setHelpUrl(Blockly.Msg.LOGIC_OPERATION_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.appendValueInput("A").setCheck("Boolean");this.appendValueInput("B").setCheck("Boolean").appendField(new Blockly.FieldDropdown(a),"OP");this.setInputsInline(!0);var b=this;this.setTooltip(function(){var a=b.getFieldValue("OP");return{AND:Blockly.Msg.LOGIC_OPERATION_TOOLTIP_AND,
|
||||
OR:Blockly.Msg.LOGIC_OPERATION_TOOLTIP_OR}[a]})}};Blockly.Blocks.logic_negate={init:function(){this.setHelpUrl(Blockly.Msg.LOGIC_NEGATE_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.interpolateMsg(Blockly.Msg.LOGIC_NEGATE_TITLE,["BOOL","Boolean",Blockly.ALIGN_RIGHT],Blockly.ALIGN_RIGHT);this.setTooltip(Blockly.Msg.LOGIC_NEGATE_TOOLTIP)}};
|
||||
Blockly.Blocks.logic_boolean={init:function(){var a=[[Blockly.Msg.LOGIC_BOOLEAN_TRUE,"TRUE"],[Blockly.Msg.LOGIC_BOOLEAN_FALSE,"FALSE"]];this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.appendDummyInput().appendField(new Blockly.FieldDropdown(a),"BOOL");this.setTooltip(Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP)}};
|
||||
|
||||
@@ -727,6 +727,10 @@ Blockly.ConnectionDB.prototype.addConnection_ = function(connection) {
|
||||
if (connection.inDB_) {
|
||||
throw 'Connection already in database.';
|
||||
}
|
||||
if (connection.sourceBlock_.isInFlyout) {
|
||||
// Don't bother maintaining a database of connections in a flyout.
|
||||
return;
|
||||
}
|
||||
// Insert connection using binary search.
|
||||
var pointerMin = 0;
|
||||
var pointerMax = this.length;
|
||||
|
||||
@@ -61,7 +61,9 @@ Blockly.Blocks['factory_base'] = {
|
||||
.appendField('help url');
|
||||
*/
|
||||
this.setTooltip('Build a custom block by plugging\n' +
|
||||
'fields, inputs and other blocks here.');
|
||||
'fields, inputs and other blocks here.');
|
||||
this.setHelpUrl(
|
||||
'https://developers.google.com/blockly/custom-blocks/block-factory');
|
||||
},
|
||||
mutationToDom: function() {
|
||||
var container = document.createElement('mutation');
|
||||
@@ -130,6 +132,7 @@ Blockly.Blocks['input_value'] = {
|
||||
this.setPreviousStatement(true, 'Input');
|
||||
this.setNextStatement(true, 'Input');
|
||||
this.setTooltip('A value socket for horizontal connections.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=71');
|
||||
},
|
||||
onchange: function() {
|
||||
if (!this.workspace) {
|
||||
@@ -158,6 +161,7 @@ Blockly.Blocks['input_statement'] = {
|
||||
this.setPreviousStatement(true, 'Input');
|
||||
this.setNextStatement(true, 'Input');
|
||||
this.setTooltip('A statement socket for enclosed vertical stacks.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=246');
|
||||
},
|
||||
onchange: function() {
|
||||
if (!this.workspace) {
|
||||
@@ -180,10 +184,10 @@ Blockly.Blocks['input_dummy'] = {
|
||||
.appendField(new Blockly.FieldDropdown(ALIGNMENT_OPTIONS), 'ALIGN');
|
||||
this.setPreviousStatement(true, 'Input');
|
||||
this.setNextStatement(true, 'Input');
|
||||
this.setTooltip('For adding fields on a separate\n' +
|
||||
'row with no connections.\n' +
|
||||
'Alignment options (left, right, centre)\n' +
|
||||
this.setTooltip('For adding fields on a separate row with no ' +
|
||||
'connections. Alignment options (left, right, centre) ' +
|
||||
'apply only to multi-line fields.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=293');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -197,6 +201,7 @@ Blockly.Blocks['field_static'] = {
|
||||
this.setPreviousStatement(true, 'Field');
|
||||
this.setNextStatement(true, 'Field');
|
||||
this.setTooltip('Static text that serves as a label.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=88');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -212,6 +217,7 @@ Blockly.Blocks['field_input'] = {
|
||||
this.setPreviousStatement(true, 'Field');
|
||||
this.setNextStatement(true, 'Field');
|
||||
this.setTooltip('An input field for the user to enter text.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=319');
|
||||
},
|
||||
onchange: function() {
|
||||
if (!this.workspace) {
|
||||
@@ -234,6 +240,7 @@ Blockly.Blocks['field_angle'] = {
|
||||
this.setPreviousStatement(true, 'Field');
|
||||
this.setNextStatement(true, 'Field');
|
||||
this.setTooltip('An input field for the user to enter an angle.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=372');
|
||||
},
|
||||
onchange: function() {
|
||||
if (!this.workspace) {
|
||||
@@ -267,6 +274,7 @@ Blockly.Blocks['field_dropdown'] = {
|
||||
this.setNextStatement(true, 'Field');
|
||||
this.setMutator(new Blockly.Mutator(['field_dropdown_option']));
|
||||
this.setTooltip('Dropdown menu with a list of options.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=386');
|
||||
this.optionCount_ = 3;
|
||||
},
|
||||
mutationToDom: function(workspace) {
|
||||
@@ -354,6 +362,7 @@ Blockly.Blocks['field_dropdown_container'] = {
|
||||
this.appendStatementInput('STACK');
|
||||
this.setTooltip('Add, remove, or reorder options\n' +
|
||||
'to reconfigure this dropdown menu.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=386');
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
@@ -367,6 +376,7 @@ Blockly.Blocks['field_dropdown_option'] = {
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip('Add a new option to the dropdown menu.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=386');
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
@@ -383,6 +393,7 @@ Blockly.Blocks['field_checkbox'] = {
|
||||
this.setPreviousStatement(true, 'Field');
|
||||
this.setNextStatement(true, 'Field');
|
||||
this.setTooltip('Checkbox field.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=485');
|
||||
},
|
||||
onchange: function() {
|
||||
if (!this.workspace) {
|
||||
@@ -405,6 +416,7 @@ Blockly.Blocks['field_colour'] = {
|
||||
this.setPreviousStatement(true, 'Field');
|
||||
this.setNextStatement(true, 'Field');
|
||||
this.setTooltip('Colour input field.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=495');
|
||||
},
|
||||
onchange: function() {
|
||||
if (!this.workspace) {
|
||||
@@ -427,6 +439,7 @@ Blockly.Blocks['field_variable'] = {
|
||||
this.setPreviousStatement(true, 'Field');
|
||||
this.setNextStatement(true, 'Field');
|
||||
this.setTooltip('Dropdown menu for variable names.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=510');
|
||||
},
|
||||
onchange: function() {
|
||||
if (!this.workspace) {
|
||||
@@ -459,6 +472,7 @@ Blockly.Blocks['field_image'] = {
|
||||
this.setTooltip('Static image (JPEG, PNG, GIF, SVG, BMP).\n' +
|
||||
'Retains aspect ratio regardless of height and width.\n' +
|
||||
'Alt text is for when collapsed.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=567');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -474,6 +488,7 @@ Blockly.Blocks['type_group'] = {
|
||||
this.setOutput(true, 'Type');
|
||||
this.setMutator(new Blockly.Mutator(['type_group_item']));
|
||||
this.setTooltip('Allows more than one type to be accepted.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=677');
|
||||
this.typeCount_ = 2;
|
||||
},
|
||||
mutationToDom: function(workspace) {
|
||||
@@ -552,6 +567,7 @@ Blockly.Blocks['type_group_container'] = {
|
||||
.appendField('add types');
|
||||
this.appendStatementInput('STACK');
|
||||
this.setTooltip('Add, or remove allowed type.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=677');
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
@@ -565,6 +581,7 @@ Blockly.Blocks['type_group_item'] = {
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip('Add a new allowed type.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=677');
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
@@ -578,6 +595,7 @@ Blockly.Blocks['type_null'] = {
|
||||
.appendField('any');
|
||||
this.setOutput(true, 'Type');
|
||||
this.setTooltip('Any type is allowed.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=602');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -590,6 +608,7 @@ Blockly.Blocks['type_boolean'] = {
|
||||
.appendField('boolean');
|
||||
this.setOutput(true, 'Type');
|
||||
this.setTooltip('Booleans (true/false) are allowed.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=602');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -602,6 +621,7 @@ Blockly.Blocks['type_number'] = {
|
||||
.appendField('number');
|
||||
this.setOutput(true, 'Type');
|
||||
this.setTooltip('Numbers (int/float) are allowed.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=602');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -614,6 +634,7 @@ Blockly.Blocks['type_string'] = {
|
||||
.appendField('string');
|
||||
this.setOutput(true, 'Type');
|
||||
this.setTooltip('Strings (text) are allowed.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=602');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -626,6 +647,7 @@ Blockly.Blocks['type_list'] = {
|
||||
.appendField('list');
|
||||
this.setOutput(true, 'Type');
|
||||
this.setTooltip('Arrays (lists) are allowed.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=602');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -638,6 +660,7 @@ Blockly.Blocks['type_other'] = {
|
||||
.appendField(new Blockly.FieldTextInput(''), 'TYPE');
|
||||
this.setOutput(true, 'Type');
|
||||
this.setTooltip('Custom type to allow.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=702');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -649,6 +672,7 @@ Blockly.Blocks['colour_hue'] = {
|
||||
.appendField(new Blockly.FieldAngle('0', this.validator), 'HUE');
|
||||
this.setOutput(true, 'Colour');
|
||||
this.setTooltip('Paint the block with this colour.');
|
||||
this.setHelpUrl('https://www.youtube.com/watch?v=s2_xaEvcVI0#t=55');
|
||||
},
|
||||
validator: function(text) {
|
||||
// Update the current block's colour to match.
|
||||
|
||||
Reference in New Issue
Block a user