This commit is contained in:
Abby
2020-09-29 18:08:24 -07:00
parent 42679161cb
commit eb38834ac4
3 changed files with 735 additions and 722 deletions

View File

@@ -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_};