mirror of
https://github.com/google/blockly.git
synced 2026-06-17 08:35:12 +02:00
Merge pull request #4337 from alschmiedt/patch_2
Patch release with #4334, #4336, #4340
This commit is contained in:
@@ -928,17 +928,17 @@ Blockly.Generator.prototype.provideFunction_=function(a,b){if(!this.definitions_
|
||||
Blockly.Generator.prototype.finish=function(a){return a};Blockly.Generator.prototype.scrubNakedValue=function(a){return a};Blockly.ToolboxItem=function(a,b,c){this.id_=a.toolboxitemid||Blockly.utils.IdGenerator.getNextUniqueId();this.level_=(this.parent_=c||null)?this.parent_.getLevel()+1:0;this.toolboxItemDef_=a;this.parentToolbox_=b;this.workspace_=this.parentToolbox_.getWorkspace()};Blockly.ToolboxItem.prototype.init=function(){};Blockly.ToolboxItem.prototype.getDiv=function(){return null};Blockly.ToolboxItem.prototype.getId=function(){return this.id_};Blockly.ToolboxItem.prototype.getParent=function(){return null};
|
||||
Blockly.ToolboxItem.prototype.getLevel=function(){return this.level_};Blockly.ToolboxItem.prototype.isSelectable=function(){return!1};Blockly.ToolboxItem.prototype.isCollapsible=function(){return!1};Blockly.ToolboxItem.prototype.dispose=function(){};Blockly.ToolboxCategory=function(a,b,c){Blockly.ToolboxCategory.superClass_.constructor.call(this,a,b,c);this.name_=Blockly.utils.replaceMessageReferences(a.name);this.colour_=this.getColour_(a);this.iconDom_=this.rowContents_=this.rowDiv_=this.htmlDiv_=null;this.cssConfig_=this.makeDefaultCssConfig_();Blockly.utils.object.mixin(this.cssConfig_,a.cssconfig||a.cssConfig);this.isDisabled_=this.isHidden_=!1;this.flyoutItems_=[];this.parseContents_(a)};
|
||||
Blockly.utils.object.inherits(Blockly.ToolboxCategory,Blockly.ToolboxItem);Blockly.ToolboxCategory.registrationName="category";Blockly.ToolboxCategory.nestedPadding=19;Blockly.ToolboxCategory.borderWidth=8;Blockly.ToolboxCategory.defaultBackgroundColour="#57e";
|
||||
Blockly.ToolboxCategory.prototype.makeDefaultCssConfig_=function(){return{container:"blocklyToolboxCategory",row:"blocklyTreeRow",rowContentContainer:"blocklyTreeRowContentContainer",icon:"blocklyTreeIcon",label:"blocklyTreeLabel",contents:"blocklyToolboxContents",selected:"blocklyTreeSelected",openIcon:"blocklyTreeIconOpen",closedIcon:"blocklyTreeIconClosed"}};
|
||||
Blockly.ToolboxCategory.prototype.makeDefaultCssConfig_=function(){return{container:"blocklyToolboxCategory",row:"blocklyTreeRow",rowcontentcontainer:"blocklyTreeRowContentContainer",icon:"blocklyTreeIcon",label:"blocklyTreeLabel",contents:"blocklyToolboxContents",selected:"blocklyTreeSelected",openicon:"blocklyTreeIconOpen",closedicon:"blocklyTreeIconClosed"}};
|
||||
Blockly.ToolboxCategory.prototype.parseContents_=function(a){var b=a.contents;if(a.custom)this.flyoutItems_=a.custom;else if(b){a=0;for(var c;c=b[a];a++)this.flyoutItems_.push(c)}};Blockly.ToolboxCategory.prototype.init=function(){this.createDom_();"true"==this.toolboxItemDef_.hidden&&this.hide()};
|
||||
Blockly.ToolboxCategory.prototype.createDom_=function(){this.htmlDiv_=this.createContainer_();Blockly.utils.aria.setRole(this.htmlDiv_,Blockly.utils.aria.Role.TREEITEM);Blockly.utils.aria.setState(this.htmlDiv_,Blockly.utils.aria.State.SELECTED,!1);Blockly.utils.aria.setState(this.htmlDiv_,Blockly.utils.aria.State.LEVEL,this.level_);this.rowDiv_=this.createRowContainer_();this.rowDiv_.setAttribute("id",this.id_);this.rowDiv_.style.pointerEvents="auto";this.htmlDiv_.appendChild(this.rowDiv_);this.rowContents_=
|
||||
this.createRowContentsContainer_();this.rowContents_.style.pointerEvents="none";this.rowDiv_.appendChild(this.rowContents_);this.iconDom_=this.createIconDom_();Blockly.utils.aria.setRole(this.iconDom_,Blockly.utils.aria.Role.PRESENTATION);this.rowContents_.appendChild(this.iconDom_);var a=this.createLabelDom_(this.name_);this.rowContents_.appendChild(a);Blockly.utils.aria.setState(this.htmlDiv_,Blockly.utils.aria.State.LABELLEDBY,a.getAttribute("id"));this.addColourBorder_(this.colour_);return this.htmlDiv_};
|
||||
Blockly.ToolboxCategory.prototype.createContainer_=function(){var a=document.createElement("div");Blockly.utils.dom.addClass(a,this.cssConfig_.container);return a};Blockly.ToolboxCategory.prototype.createRowContainer_=function(){var a=document.createElement("div");Blockly.utils.dom.addClass(a,this.cssConfig_.row);var b=Blockly.ToolboxCategory.nestedPadding*this.getLevel();b=b.toString()+"px";this.workspace_.RTL?a.style.paddingRight=b:a.style.paddingLeft=b;return a};
|
||||
Blockly.ToolboxCategory.prototype.createRowContentsContainer_=function(){var a=document.createElement("div");Blockly.utils.dom.addClass(a,this.cssConfig_.rowContentContainer);return a};Blockly.ToolboxCategory.prototype.createIconDom_=function(){var a=document.createElement("span");this.parentToolbox_.isHorizontal()||Blockly.utils.dom.addClass(a,this.cssConfig_.icon);a.style.display="inline-block";return a};
|
||||
Blockly.ToolboxCategory.prototype.createRowContentsContainer_=function(){var a=document.createElement("div");Blockly.utils.dom.addClass(a,this.cssConfig_.rowcontentcontainer);return a};Blockly.ToolboxCategory.prototype.createIconDom_=function(){var a=document.createElement("span");this.parentToolbox_.isHorizontal()||Blockly.utils.dom.addClass(a,this.cssConfig_.icon);a.style.display="inline-block";return a};
|
||||
Blockly.ToolboxCategory.prototype.createLabelDom_=function(a){var b=document.createElement("span");b.setAttribute("id",this.getId()+".label");b.textContent=a;Blockly.utils.dom.addClass(b,this.cssConfig_.label);return b};Blockly.ToolboxCategory.prototype.refreshTheme=function(){this.colour_=this.getColour_(this.toolboxItemDef_);this.addColourBorder_(this.colour_)};
|
||||
Blockly.ToolboxCategory.prototype.addColourBorder_=function(a){a&&(a=Blockly.ToolboxCategory.borderWidth+"px solid "+(a||"#ddd"),this.workspace_.RTL?this.rowDiv_.style.borderRight=a:this.rowDiv_.style.borderLeft=a)};Blockly.ToolboxCategory.prototype.getColour_=function(a){var b=a.categorystyle||a.categoryStyle;if((a=a.colour)&&b)console.warn('Toolbox category "'+this.name_+'" must not have both a style and a colour');else return b?this.getColourfromStyle_(b):this.parseColour_(a);return""};
|
||||
Blockly.ToolboxCategory.prototype.getColourfromStyle_=function(a){var b=this.workspace_.getTheme();if(a&&b){if((b=b.categoryStyles[a])&&b.colour)return this.parseColour_(b.colour);console.warn('Style "'+a+'" must exist and contain a colour value')}return""};
|
||||
Blockly.ToolboxCategory.prototype.parseColour_=function(a){a=Blockly.utils.replaceMessageReferences(a);if(null==a||""===a)return"";var b=Number(a);if(isNaN(b)){if(b=Blockly.utils.colour.parse(a))return b;console.warn('Toolbox category "'+this.name_+'" has unrecognized colour attribute: '+a);return""}return Blockly.hueToHex(b)};Blockly.ToolboxCategory.prototype.openIcon_=function(a){a&&(Blockly.utils.dom.removeClasses(a,this.cssConfig_.closedIcon),Blockly.utils.dom.addClass(a,this.cssConfig_.openIcon))};
|
||||
Blockly.ToolboxCategory.prototype.closeIcon_=function(a){a&&(Blockly.utils.dom.removeClasses(a,this.cssConfig_.openIcon),Blockly.utils.dom.addClass(a,this.cssConfig_.closedIcon))};Blockly.ToolboxCategory.prototype.setVisible_=function(a){this.htmlDiv_.style.display=a?"block":"none";this.isHidden_=!a;this.parentToolbox_.getSelectedItem()==this&&this.parentToolbox_.clearSelection()};Blockly.ToolboxCategory.prototype.hide=function(){this.setVisible_(!1)};Blockly.ToolboxCategory.prototype.show=function(){this.setVisible_(!0)};
|
||||
Blockly.ToolboxCategory.prototype.parseColour_=function(a){a=Blockly.utils.replaceMessageReferences(a);if(null==a||""===a)return"";var b=Number(a);if(isNaN(b)){if(b=Blockly.utils.colour.parse(a))return b;console.warn('Toolbox category "'+this.name_+'" has unrecognized colour attribute: '+a);return""}return Blockly.hueToHex(b)};Blockly.ToolboxCategory.prototype.openIcon_=function(a){a&&(Blockly.utils.dom.removeClasses(a,this.cssConfig_.closedicon),Blockly.utils.dom.addClass(a,this.cssConfig_.openicon))};
|
||||
Blockly.ToolboxCategory.prototype.closeIcon_=function(a){a&&(Blockly.utils.dom.removeClasses(a,this.cssConfig_.openicon),Blockly.utils.dom.addClass(a,this.cssConfig_.closedicon))};Blockly.ToolboxCategory.prototype.setVisible_=function(a){this.htmlDiv_.style.display=a?"block":"none";this.isHidden_=!a;this.parentToolbox_.getSelectedItem()==this&&this.parentToolbox_.clearSelection()};Blockly.ToolboxCategory.prototype.hide=function(){this.setVisible_(!1)};Blockly.ToolboxCategory.prototype.show=function(){this.setVisible_(!0)};
|
||||
Blockly.ToolboxCategory.prototype.isVisible=function(){return!this.isHidden_&&this.allAncestorsExpanded_()};Blockly.ToolboxCategory.prototype.allAncestorsExpanded_=function(){for(var a=this;a.getParent();)if(a=a.getParent(),!a.isExpanded())return!1;return!0};Blockly.ToolboxCategory.prototype.isSelectable=function(){return this.isVisible()&&!this.isDisabled_};Blockly.ToolboxCategory.prototype.onClick=function(a){};
|
||||
Blockly.ToolboxCategory.prototype.setSelected=function(a){if(a){var b=this.parseColour_(Blockly.ToolboxCategory.defaultBackgroundColour);this.rowDiv_.style.backgroundColor=this.colour_||b;Blockly.utils.dom.addClass(this.rowDiv_,this.cssConfig_.selected)}else this.rowDiv_.style.backgroundColor="",Blockly.utils.dom.removeClass(this.rowDiv_,this.cssConfig_.selected);Blockly.utils.aria.setState(this.htmlDiv_,Blockly.utils.aria.State.SELECTED,a)};
|
||||
Blockly.ToolboxCategory.prototype.setDisabled=function(a){this.isDisabled_=a;this.getDiv().setAttribute("disabled",a);a?this.getDiv().setAttribute("disabled","true"):this.getDiv().removeAttribute("disabled")};Blockly.ToolboxCategory.prototype.getName=function(){return this.name_};Blockly.ToolboxCategory.prototype.getParent=function(){return this.parent_};Blockly.ToolboxCategory.prototype.getDiv=function(){return this.htmlDiv_};Blockly.ToolboxCategory.prototype.getContents=function(){return this.flyoutItems_};
|
||||
@@ -973,8 +973,8 @@ Blockly.Toolbox.prototype.addToolboxItem_=function(a){this.contents_.push(a);thi
|
||||
Blockly.Toolbox.prototype.getClientRect=function(){if(!this.HtmlDiv)return null;var a=this.HtmlDiv.getBoundingClientRect(),b=a.top,c=b+a.height,d=a.left;a=d+a.width;return this.toolboxPosition==Blockly.utils.toolbox.Position.TOP?new Blockly.utils.Rect(-1E7,c,-1E7,1E7):this.toolboxPosition==Blockly.utils.toolbox.Position.BOTTOM?new Blockly.utils.Rect(b,1E7,-1E7,1E7):this.toolboxPosition==Blockly.utils.toolbox.Position.LEFT?new Blockly.utils.Rect(-1E7,1E7,-1E7,a):new Blockly.utils.Rect(-1E7,1E7,d,1E7)};
|
||||
Blockly.Toolbox.prototype.getToolboxItemById=function(a){return this.contentMap_[a]};Blockly.Toolbox.prototype.getWidth=function(){return this.width_};Blockly.Toolbox.prototype.getHeight=function(){return this.height_};Blockly.Toolbox.prototype.getFlyout=function(){return this.flyout_};Blockly.Toolbox.prototype.getWorkspace=function(){return this.workspace_};Blockly.Toolbox.prototype.getSelectedItem=function(){return this.selectedItem_};Blockly.Toolbox.prototype.getPreviouslySelectedItem=function(){return this.previouslySelectedItem_};
|
||||
Blockly.Toolbox.prototype.isHorizontal=function(){return this.horizontalLayout_};Blockly.Toolbox.prototype.position=function(){var a=this.HtmlDiv;a&&(this.horizontalLayout_?(a.style.left="0",a.style.height="auto",a.style.width="100%",this.height_=a.offsetHeight,this.toolboxPosition==Blockly.TOOLBOX_AT_TOP?a.style.top="0":a.style.bottom="0"):(this.toolboxPosition==Blockly.TOOLBOX_AT_RIGHT?a.style.right="0":a.style.left="0",a.style.height="100%",this.width_=a.offsetWidth),this.flyout_.position())};
|
||||
Blockly.Toolbox.prototype.handleToolboxItemResize=function(){var a=this.workspace_,b=this.HtmlDiv.getBoundingClientRect();a.translate(this.toolboxPosition==Blockly.TOOLBOX_AT_LEFT?a.scrollX+b.width:0,this.toolboxPosition==Blockly.TOOLBOX_AT_TOP?a.scrollY+b.height:0);Blockly.svgResize(a)};Blockly.Toolbox.prototype.clearSelection=function(){this.setSelectedItem(null)};Blockly.Toolbox.prototype.refreshTheme=function(){for(var a=0;a<this.contents_.length;a++){var b=this.contents_[a];b.refreshTheme&&b.refreshTheme()}};
|
||||
Blockly.Toolbox.prototype.refreshSelection=function(){this.selectedItem_&&this.selectedItem_.isSelectable()&&this.selectedItem_.getContents().length&&this.flyout_.show(this.selectedItem_.getContents())};Blockly.Toolbox.prototype.setVisible=function(a){this.HtmlDiv.style.display=a?"block":"none"};
|
||||
Blockly.Toolbox.prototype.handleToolboxItemResize=function(){var a=this.workspace_,b=this.HtmlDiv.getBoundingClientRect();a.translate(this.toolboxPosition==Blockly.TOOLBOX_AT_LEFT?a.scrollX+b.width:a.scrollX,this.toolboxPosition==Blockly.TOOLBOX_AT_TOP?a.scrollY+b.height:a.scrollY);Blockly.svgResize(a)};Blockly.Toolbox.prototype.clearSelection=function(){this.setSelectedItem(null)};
|
||||
Blockly.Toolbox.prototype.refreshTheme=function(){for(var a=0;a<this.contents_.length;a++){var b=this.contents_[a];b.refreshTheme&&b.refreshTheme()}};Blockly.Toolbox.prototype.refreshSelection=function(){this.selectedItem_&&this.selectedItem_.isSelectable()&&this.selectedItem_.getContents().length&&this.flyout_.show(this.selectedItem_.getContents())};Blockly.Toolbox.prototype.setVisible=function(a){this.HtmlDiv.style.display=a?"block":"none"};
|
||||
Blockly.Toolbox.prototype.setSelectedItem=function(a){var b=this.selectedItem_;!a&&!b||a&&!a.isSelectable()||(this.shouldDeselectItem_(b,a)&&null!=b&&this.deselectItem_(b),this.shouldSelectItem_(b,a)&&null!=a&&this.selectItem_(b,a),this.updateFlyout_(b,a),this.fireSelectEvent_(b,a))};Blockly.Toolbox.prototype.shouldDeselectItem_=function(a,b){return null!=a&&(!a.isCollapsible()||a!=b)};Blockly.Toolbox.prototype.shouldSelectItem_=function(a,b){return null!=b&&b!=a};
|
||||
Blockly.Toolbox.prototype.deselectItem_=function(a){this.selectedItem_=null;this.previouslySelectedItem_=a;a.setSelected(!1);Blockly.utils.aria.setState(this.contentsDiv_,Blockly.utils.aria.State.ACTIVEDESCENDANT,"")};Blockly.Toolbox.prototype.selectItem_=function(a,b){this.selectedItem_=b;this.previouslySelectedItem_=a;b.setSelected(!0);Blockly.utils.aria.setState(this.contentsDiv_,Blockly.utils.aria.State.ACTIVEDESCENDANT,b.getId())};
|
||||
Blockly.Toolbox.prototype.selectItemByPosition=function(a){-1<a&&a<this.contents_.length&&(a=this.contents_[a],a.isSelectable()&&this.setSelectedItem(a))};Blockly.Toolbox.prototype.updateFlyout_=function(a,b){(a!=b||b.isCollapsible())&&b&&b.getContents().length?(this.flyout_.show(b.getContents()),this.flyout_.scrollToStart()):this.flyout_.hide()};
|
||||
|
||||
File diff suppressed because one or more lines are too long
+11
-10
@@ -123,11 +123,12 @@ Blockly.utils.object.inherits(Blockly.ToolboxCategory, Blockly.ToolboxItem);
|
||||
* @typedef {{
|
||||
* container:?string,
|
||||
* row:?string,
|
||||
* rowcontentcontainer:?string,
|
||||
* icon:?string,
|
||||
* label:?string,
|
||||
* selected:?string,
|
||||
* openIcon:?string,
|
||||
* closedIcon:?string
|
||||
* openicon:?string,
|
||||
* closedicon:?string
|
||||
* }}
|
||||
*/
|
||||
Blockly.ToolboxCategory.CssConfig;
|
||||
@@ -167,13 +168,13 @@ Blockly.ToolboxCategory.prototype.makeDefaultCssConfig_ = function() {
|
||||
return {
|
||||
'container': 'blocklyToolboxCategory',
|
||||
'row': 'blocklyTreeRow',
|
||||
'rowContentContainer': 'blocklyTreeRowContentContainer',
|
||||
'rowcontentcontainer': 'blocklyTreeRowContentContainer',
|
||||
'icon': 'blocklyTreeIcon',
|
||||
'label': 'blocklyTreeLabel',
|
||||
'contents': 'blocklyToolboxContents',
|
||||
'selected': 'blocklyTreeSelected',
|
||||
'openIcon': 'blocklyTreeIconOpen',
|
||||
'closedIcon': 'blocklyTreeIconClosed',
|
||||
'openicon': 'blocklyTreeIconOpen',
|
||||
'closedicon': 'blocklyTreeIconClosed',
|
||||
};
|
||||
};
|
||||
|
||||
@@ -278,7 +279,7 @@ Blockly.ToolboxCategory.prototype.createRowContainer_ = function() {
|
||||
*/
|
||||
Blockly.ToolboxCategory.prototype.createRowContentsContainer_ = function() {
|
||||
var contentsContainer = document.createElement('div');
|
||||
Blockly.utils.dom.addClass(contentsContainer, this.cssConfig_['rowContentContainer']);
|
||||
Blockly.utils.dom.addClass(contentsContainer, this.cssConfig_['rowcontentcontainer']);
|
||||
return contentsContainer;
|
||||
};
|
||||
|
||||
@@ -422,8 +423,8 @@ Blockly.ToolboxCategory.prototype.openIcon_ = function(iconDiv) {
|
||||
if (!iconDiv) {
|
||||
return;
|
||||
}
|
||||
Blockly.utils.dom.removeClasses(iconDiv, this.cssConfig_['closedIcon']);
|
||||
Blockly.utils.dom.addClass(iconDiv, this.cssConfig_['openIcon']);
|
||||
Blockly.utils.dom.removeClasses(iconDiv, this.cssConfig_['closedicon']);
|
||||
Blockly.utils.dom.addClass(iconDiv, this.cssConfig_['openicon']);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -435,8 +436,8 @@ Blockly.ToolboxCategory.prototype.closeIcon_ = function(iconDiv) {
|
||||
if (!iconDiv) {
|
||||
return;
|
||||
}
|
||||
Blockly.utils.dom.removeClasses(iconDiv, this.cssConfig_['openIcon']);
|
||||
Blockly.utils.dom.addClass(iconDiv, this.cssConfig_['closedIcon']);
|
||||
Blockly.utils.dom.removeClasses(iconDiv, this.cssConfig_['openicon']);
|
||||
Blockly.utils.dom.addClass(iconDiv, this.cssConfig_['closedicon']);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,11 +71,12 @@ Blockly.utils.object.inherits(Blockly.CollapsibleToolboxCategory, Blockly.Toolbo
|
||||
* @typedef {{
|
||||
* container:?string,
|
||||
* row:?string,
|
||||
* rowcontentcontainer:?string,
|
||||
* icon:?string,
|
||||
* label:?string,
|
||||
* selected:?string,
|
||||
* openIcon:?string,
|
||||
* closedIcon:?string,
|
||||
* openicon:?string,
|
||||
* closedicon:?string,
|
||||
* contents:?string
|
||||
* }}
|
||||
*/
|
||||
|
||||
@@ -614,9 +614,9 @@ Blockly.Toolbox.prototype.handleToolboxItemResize = function() {
|
||||
var workspace = this.workspace_;
|
||||
var rect = this.HtmlDiv.getBoundingClientRect();
|
||||
var newX = this.toolboxPosition == Blockly.TOOLBOX_AT_LEFT ?
|
||||
workspace.scrollX + rect.width : 0;
|
||||
workspace.scrollX + rect.width : workspace.scrollX;
|
||||
var newY = this.toolboxPosition == Blockly.TOOLBOX_AT_TOP ?
|
||||
workspace.scrollY + rect.height : 0;
|
||||
workspace.scrollY + rect.height : workspace.scrollY;
|
||||
workspace.translate(newX, newY);
|
||||
|
||||
// Even though the div hasn't changed size, the visible workspace
|
||||
|
||||
@@ -87,7 +87,9 @@ Blockly.Blocks['factory_base'] = {
|
||||
type.setShadow(true);
|
||||
type.outputConnection.connect(this.getInput(outputType).connection);
|
||||
type.initSvg();
|
||||
type.render();
|
||||
if (this.rendered) {
|
||||
type.render();
|
||||
}
|
||||
},
|
||||
updateShape_: function(option) {
|
||||
var outputExists = this.getInput('OUTPUTTYPE');
|
||||
|
||||
Vendored
+730
-717
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user