mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-20 18:09:43 -04:00
* Add textinput restrictor and FieldNumber use * Update FieldNumber to remove validator and add appropriate restrictor * Update blocks for new restrictors * Remove restriction on FIELD_WIDTH_MAX_EDIT * Remove extra console.log * Version of FieldNumber that brings back min/max/precision * opt_validator order to match Blockly * Math.floor(precision) == precision * Fixing JSDoc * Invert decimalAllowed_ * Reverse opt_validator positioning per Neil * Don't allow typing 'e', per design meeting * Update for agreed-upon API * Allow NaN constraints per agreement * Remove optional parameters from math.js blocks * Recompile 2, June 23 * Correct JSDoc for optionals
This commit is contained in:
parent
ca3275eaf0
commit
2fa746d408
8 changed files with 97 additions and 97 deletions
|
@ -1281,13 +1281,13 @@ Blockly.genUid=function(){for(var a=Blockly.genUid.soup_.length,b=[],c=0;20>c;c+
|
|||
Blockly.utils.wrap_line_=function(a,b){if(a.length<=b)return a;for(var c=a.trim().split(/\s+/),d=0;d<c.length;d++)c[d].length>b&&(b=c[d].length);var e,d=-Infinity,f,g=1;do{e=d;f=a;for(var h=[],k=c.length/g,l=1,d=0;d<c.length-1;d++)l<(d+1.5)/k?(l++,h[d]=!0):h[d]=!1;h=Blockly.utils.wrapMutate_(c,h,b);d=Blockly.utils.wrapScore_(c,h,b);a=Blockly.utils.wrapToText_(c,h);g++}while(d>e);return f};
|
||||
Blockly.utils.wrapScore_=function(a,b,c){for(var d=[0],e=[],f=0;f<a.length;f++)d[d.length-1]+=a[f].length,!0===b[f]?(d.push(0),e.push(a[f].charAt(a[f].length-1))):!1===b[f]&&d[d.length-1]++;a=Math.max.apply(Math,d);for(f=b=0;f<d.length;f++)b-=2*Math.pow(Math.abs(c-d[f]),1.5),b-=Math.pow(a-d[f],1.5),-1!=".?!".indexOf(e[f])?b+=c/3:-1!=",;)]}".indexOf(e[f])&&(b+=c/4);1<d.length&&d[d.length-1]<=d[d.length-2]&&(b+=.5);return b};
|
||||
Blockly.utils.wrapMutate_=function(a,b,c){for(var d=Blockly.utils.wrapScore_(a,b,c),e,f=0;f<b.length-1;f++)if(b[f]!=b[f+1]){var g=[].concat(b);g[f]=!g[f];g[f+1]=!g[f+1];var h=Blockly.utils.wrapScore_(a,g,c);h>d&&(d=h,e=g)}return e?Blockly.utils.wrapMutate_(a,e,c):b};Blockly.utils.wrapToText_=function(a,b){for(var c=[],d=0;d<a.length;d++)c.push(a[d]),void 0!==b[d]&&c.push(b[d]?"\n":" ");return c.join("")};
|
||||
Blockly.measureText=function(a,b,c,d){var e=document.createElement("canvas").getContext("2d");e.font=c+" "+a+" "+b;return e.measureText(d).width};Blockly.FieldTextInput=function(a,b){Blockly.FieldTextInput.superClass_.constructor.call(this,a,b)};goog.inherits(Blockly.FieldTextInput,Blockly.Field);Blockly.FieldTextInput.ANIMATION_TIME=.25;Blockly.FieldTextInput.TEXT_MEASURE_PADDING_MAGIC=45;Blockly.FieldTextInput.prototype.CURSOR="text";Blockly.FieldTextInput.prototype.spellcheck_=!0;Blockly.FieldTextInput.prototype.dispose=function(){Blockly.WidgetDiv.hideIfOwner(this);Blockly.FieldTextInput.superClass_.dispose.call(this)};
|
||||
Blockly.FieldTextInput.prototype.setValue=function(a){if(null!==a){if(this.sourceBlock_&&this.validator_){var b=this.validator_(a);null!==b&&void 0!==b&&(a=b)}Blockly.Field.prototype.setValue.call(this,a)}};Blockly.FieldTextInput.prototype.setSpellcheck=function(a){this.spellcheck_=a};
|
||||
Blockly.measureText=function(a,b,c,d){var e=document.createElement("canvas").getContext("2d");e.font=c+" "+a+" "+b;return e.measureText(d).width};Blockly.FieldTextInput=function(a,b,c){Blockly.FieldTextInput.superClass_.constructor.call(this,a,b);this.setRestrictor(c)};goog.inherits(Blockly.FieldTextInput,Blockly.Field);Blockly.FieldTextInput.ANIMATION_TIME=.25;Blockly.FieldTextInput.TEXT_MEASURE_PADDING_MAGIC=45;Blockly.FieldTextInput.prototype.CURSOR="text";Blockly.FieldTextInput.prototype.spellcheck_=!0;Blockly.FieldTextInput.prototype.dispose=function(){Blockly.WidgetDiv.hideIfOwner(this);Blockly.FieldTextInput.superClass_.dispose.call(this)};
|
||||
Blockly.FieldTextInput.prototype.setValue=function(a){if(null!==a){if(this.sourceBlock_&&this.validator_){var b=this.validator_(a);null!==b&&void 0!==b&&(a=b)}Blockly.Field.prototype.setValue.call(this,a)}};Blockly.FieldTextInput.prototype.setSpellcheck=function(a){this.spellcheck_=a};Blockly.FieldTextInput.prototype.setRestrictor=function(a){this.restrictor_=a};
|
||||
Blockly.FieldTextInput.prototype.showEditor_=function(a,b){this.workspace_=this.sourceBlock_.workspace;var c=a||!1,d=b||!1;Blockly.WidgetDiv.show(this,this.sourceBlock_.RTL,this.widgetDispose_(),this.widgetDisposeAnimationFinished_(),Blockly.FieldTextInput.ANIMATION_TIME);var e=Blockly.WidgetDiv.DIV;e.className+=" fieldTextInput";var f=goog.dom.createDom("input","blocklyHtmlInput");f.setAttribute("spellcheck",this.spellcheck_);d&&f.setAttribute("readonly","true");Blockly.FieldTextInput.htmlInput_=
|
||||
f;e.appendChild(f);f.value=f.defaultValue=this.text_;f.oldValue_=null;this.validate_();this.resizeEditor_();c||(f.focus(),f.select(),f.setSelectionRange(0,99999));f.onKeyDownWrapper_=Blockly.bindEvent_(f,"keydown",this,this.onHtmlInputKeyDown_);f.onKeyUpWrapper_=Blockly.bindEvent_(f,"keyup",this,this.onHtmlInputChange_);f.onKeyPressWrapper_=Blockly.bindEvent_(f,"keypress",this,this.onHtmlInputChange_);f.onInputWrapper_=Blockly.bindEvent_(f,"input",this,this.onHtmlInputChange_);f.onWorkspaceChangeWrapper_=
|
||||
this.resizeEditor_.bind(this);this.workspace_.addChangeListener(f.onWorkspaceChangeWrapper_);c="box-shadow "+Blockly.FieldTextInput.ANIMATION_TIME+"s";Blockly.BlockSvg.FIELD_TEXTINPUT_ANIMATE_POSITIONING&&(e.style.transition+=",padding "+Blockly.FieldTextInput.ANIMATION_TIME+"s,width "+Blockly.FieldTextInput.ANIMATION_TIME+"s,height "+Blockly.FieldTextInput.ANIMATION_TIME+"s,margin-left "+Blockly.FieldTextInput.ANIMATION_TIME+"s");e.style.transition=c;f.style.transition="font-size "+Blockly.FieldTextInput.ANIMATION_TIME+
|
||||
"s";f.style.fontSize=Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_FINAL+"pt";e.style.boxShadow="0px 0px 0px 4px "+Blockly.Colours.fieldShadow};Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_=function(a){var b=Blockly.FieldTextInput.htmlInput_;13==a.keyCode?Blockly.WidgetDiv.hide():27==a.keyCode?(b.value=b.defaultValue,Blockly.WidgetDiv.hide()):9==a.keyCode&&(Blockly.WidgetDiv.hide(),this.sourceBlock_.tab(this,!a.shiftKey),a.preventDefault())};
|
||||
Blockly.FieldTextInput.prototype.onHtmlInputChange_=function(a){a=Blockly.FieldTextInput.htmlInput_;var b=a.value;b!==a.oldValue_?(a.oldValue_=b,this.setValue(b),this.validate_()):goog.userAgent.WEBKIT&&this.sourceBlock_.render();this.resizeEditor_();Blockly.svgResize(this.sourceBlock_.workspace)};
|
||||
Blockly.FieldTextInput.prototype.onHtmlInputChange_=function(a){if("keypress"===a.type&&this.restrictor_){var b=String.fromCharCode(a.keyCode);if(!this.restrictor_.test(b)&&a.preventDefault){a.preventDefault();return}}a=Blockly.FieldTextInput.htmlInput_;b=a.value;b!==a.oldValue_?(a.oldValue_=b,this.setValue(b),this.validate_()):goog.userAgent.WEBKIT&&this.sourceBlock_.render();this.resizeEditor_();Blockly.svgResize(this.sourceBlock_.workspace)};
|
||||
Blockly.FieldTextInput.prototype.validate_=function(){var a=!0;goog.asserts.assertObject(Blockly.FieldTextInput.htmlInput_);var b=Blockly.FieldTextInput.htmlInput_;this.sourceBlock_&&this.validator_&&(a=this.validator_(b.value));null===a?Blockly.addClass_(b,"blocklyInvalidInput"):Blockly.removeClass_(b,"blocklyInvalidInput")};
|
||||
Blockly.FieldTextInput.prototype.resizeEditor_=function(){var a=this.sourceBlock_.workspace.scale,b=Blockly.WidgetDiv.DIV,c;Blockly.BlockSvg.FIELD_TEXTINPUT_EXPAND_PAST_TRUNCATION?(c=Blockly.measureText(Blockly.FieldTextInput.htmlInput_.style.fontSize,Blockly.FieldTextInput.htmlInput_.style.fontFamily,Blockly.FieldTextInput.htmlInput_.style.fontWeight,Blockly.FieldTextInput.htmlInput_.value),c+=Blockly.FieldTextInput.TEXT_MEASURE_PADDING_MAGIC,c*=a):c=this.sourceBlock_.getHeightWidth().width*a;c=
|
||||
Math.max(c,Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT*a);c=Math.min(c,Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT*a);b.style.width=c/a+1+"px";b.style.height=Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT+1+"px";b.style.transform="scale("+a+")";var d=this.sourceBlock_.getHeightWidth().width;b.style.marginLeft=-.5*(c-d*a)+"px";d=this.getBorderRadius()+.5;b.style.borderRadius=d+"px";d=this.sourceBlock_.getColourTertiary();b.style.borderColor=d;d=this.getAbsoluteXY_();d.x-=a/2;d.y-=a/2;this.sourceBlock_.RTL&&(d.x+=c,d.x-=
|
||||
|
@ -1305,18 +1305,17 @@ Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGE
|
|||
b,this.setValue(b),this.validate_(),this.resizeEditor_())};Blockly.FieldAngle.prototype.setText=function(a){Blockly.FieldAngle.superClass_.setText.call(this,a);this.textElement_&&(this.updateGraph_(),this.sourceBlock_.RTL?this.textElement_.insertBefore(this.symbol_,this.textElement_.firstChild):this.textElement_.appendChild(this.symbol_),this.size_.width=0)};
|
||||
Blockly.FieldAngle.prototype.updateGraph_=function(){if(this.gauge_){var a=Number(this.getText())+Blockly.FieldAngle.OFFSET,b=goog.math.toRadians(a),a=["M ",Blockly.FieldAngle.HALF,",",Blockly.FieldAngle.HALF],c=Blockly.FieldAngle.HALF,d=Blockly.FieldAngle.HALF;if(!isNaN(b)){var e=goog.math.toRadians(Blockly.FieldAngle.OFFSET),f=Math.cos(e)*Blockly.FieldAngle.RADIUS,g=Math.sin(e)*-Blockly.FieldAngle.RADIUS;Blockly.FieldAngle.CLOCKWISE&&(b=2*e-b);c+=Math.cos(b)*Blockly.FieldAngle.RADIUS;d-=Math.sin(b)*
|
||||
Blockly.FieldAngle.RADIUS;b=Math.abs(Math.floor((b-e)/Math.PI)%2);Blockly.FieldAngle.CLOCKWISE&&(b=1-b);a.push(" l ",f,",",g," A ",Blockly.FieldAngle.RADIUS,",",Blockly.FieldAngle.RADIUS," 0 ",b," ",Number(Blockly.FieldAngle.CLOCKWISE)," ",c,",",d," z")}this.gauge_.setAttribute("d",a.join(""));this.line_.setAttribute("x2",c);this.line_.setAttribute("y2",d)}};
|
||||
Blockly.FieldAngle.angleValidator=function(a){if(null===a)return null;a=parseFloat(a||0);if(isNaN(a))return null;a%=360;0>a&&(a+=360);a>Blockly.FieldAngle.WRAP&&(a-=360);return String(a)};Blockly.FieldNumber=function(a,b,c,d,e){this.precision_=c;this.min_=d;this.max_=e;Blockly.FieldNumber.superClass_.constructor.call(this,a,b)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.DROPDOWN_WIDTH=168;Blockly.FieldNumber.DROPDOWN_Y_PADDING=8;Blockly.FieldNumber.NUMPAD_BUTTONS="789456123.0".split("");
|
||||
Blockly.FieldAngle.angleValidator=function(a){if(null===a)return null;a=parseFloat(a||0);if(isNaN(a))return null;a%=360;0>a&&(a+=360);a>Blockly.FieldAngle.WRAP&&(a-=360);return String(a)};var getNumRestrictor=function(a,b){var c="[\\d]";a&&(c+="|[\\.]");b&&(c+="|[-]");return new RegExp(c)};Blockly.FieldNumber=function(a,b,c,d,e){this.decimalAllowed_="undefined"==typeof d||isNaN(d)||0==d||Math.floor(d)!=d;this.negativeAllowed_="undefined"==typeof b||isNaN(b)||0>b;b=getNumRestrictor(this.decimalAllowed_,this.negativeAllowed_);Blockly.FieldNumber.superClass_.constructor.call(this,a,e,b)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.DROPDOWN_WIDTH=168;
|
||||
Blockly.FieldNumber.DROPDOWN_Y_PADDING=8;Blockly.FieldNumber.NUMPAD_BUTTONS="789456123.0".split("");
|
||||
Blockly.FieldNumber.NUMPAD_DELETE_ICON='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><path d="M28.89,11.45H16.79a2.86,2.86,0,0,0-2,.84L9.09,18a2.85,2.85,0,0,0,0,4l5.69,5.69a2.86,2.86,0,0,0,2,.84h12.1a2.86,2.86,0,0,0,2.86-2.86V14.31A2.86,2.86,0,0,0,28.89,11.45ZM27.15,22.73a1,1,0,0,1,0,1.41,1,1,0,0,1-.71.3,1,1,0,0,1-.71-0.3L23,21.41l-2.73,2.73a1,1,0,0,1-1.41,0,1,1,0,0,1,0-1.41L21.59,20l-2.73-2.73a1,1,0,0,1,0-1.41,1,1,0,0,1,1.41,0L23,18.59l2.73-2.73a1,1,0,1,1,1.42,1.41L24.42,20Z" fill="'+Blockly.Colours.numPadText+
|
||||
'"/></svg>';Blockly.FieldNumber.activeField_=null;Blockly.FieldNumber.prototype.setValidator=function(a){Blockly.FieldNumber.superClass_.setValidator.call(this,a?function(b){var c=a.call(this,b),d;null===c?d=c:(void 0===c&&(c=b),d=Blockly.FieldNumber.numberValidator.call(this,c),void 0===d&&(d=c));return d===b?void 0:d}:Blockly.FieldNumber.numberValidator)};
|
||||
Blockly.FieldNumber.prototype.showEditor_=function(){Blockly.FieldNumber.activeField_=this;var a=goog.userAgent.MOBILE||goog.userAgent.ANDROID||goog.userAgent.IPAD;Blockly.FieldNumber.superClass_.showEditor_.call(this,!1,a);a&&this.showNumPad_()};
|
||||
'"/></svg>';Blockly.FieldNumber.activeField_=null;Blockly.FieldNumber.prototype.setConstraints_=function(a,b,c){this.decimalAllowed_="undefined"==typeof c||isNaN(c)||0==c||Math.floor(c)!=c;this.negativeAllowed_="undefined"==typeof a||isNaN(a)||0>a};Blockly.FieldNumber.prototype.showEditor_=function(){Blockly.FieldNumber.activeField_=this;var a=goog.userAgent.MOBILE||goog.userAgent.ANDROID||goog.userAgent.IPAD;Blockly.FieldNumber.superClass_.showEditor_.call(this,!1,a);a&&this.showNumPad_()};
|
||||
Blockly.FieldNumber.prototype.showNumPad_=function(){Blockly.DropDownDiv.hideWithoutAnimation();Blockly.DropDownDiv.clearContent();var a=Blockly.DropDownDiv.getContentDiv();a.setAttribute("role","menu");a.setAttribute("aria-haspopup","true");for(var b=Blockly.FieldNumber.NUMPAD_BUTTONS,c=0,d;d=b[c];c++){var e=document.createElement("button");e.setAttribute("role","menuitem");e.setAttribute("class","blocklyNumPadButton");e.title=d;e.innerHTML=d;Blockly.bindEvent_(e,"mousedown",e,Blockly.FieldNumber.numPadButtonTouch_);
|
||||
"."==d&&0==this.precision_&&e.setAttribute("style","visibility: hidden");a.appendChild(e)}b=document.createElement("button");b.setAttribute("role","menuitem");b.setAttribute("class","blocklyNumPadButton");b.title="Delete";c=document.createElement("img");c.src=Blockly.FieldNumber.NUMPAD_DELETE_ICON;b.appendChild(c);Blockly.bindEvent_(b,"mousedown",null,Blockly.FieldNumber.numPadEraseButtonTouch_);a.appendChild(b);Blockly.DropDownDiv.setColour(Blockly.Colours.numPadBackground,Blockly.Colours.numPadBorder);
|
||||
"."!=d||this.decimalAllowed||e.setAttribute("style","visibility: hidden");a.appendChild(e)}b=document.createElement("button");b.setAttribute("role","menuitem");b.setAttribute("class","blocklyNumPadButton");b.title="Delete";c=document.createElement("img");c.src=Blockly.FieldNumber.NUMPAD_DELETE_ICON;b.appendChild(c);Blockly.bindEvent_(b,"mousedown",null,Blockly.FieldNumber.numPadEraseButtonTouch_);a.appendChild(b);Blockly.DropDownDiv.setColour(Blockly.Colours.numPadBackground,Blockly.Colours.numPadBorder);
|
||||
a.style.width=Blockly.FieldNumber.DROPDOWN_WIDTH+"px";b=this.sourceBlock_.workspace.scale;d=this.sourceBlock_.getHeightWidth();d.width*=b;d.height*=b;c=this.getAbsoluteXY_();a=c.x+d.width/2;d=c.y+d.height+Blockly.FieldNumber.DROPDOWN_Y_PADDING;b=c.y-Blockly.BlockSvg.MIN_BLOCK_Y*b-Blockly.BlockSvg.FIELD_Y_OFFSET*b;Blockly.DropDownDiv.setBoundsElement(this.sourceBlock_.workspace.getParentSvg().parentNode);Blockly.DropDownDiv.show(this,a,d,a,b,this.onHide_.bind(this))};
|
||||
Blockly.FieldNumber.numPadButtonTouch_=function(){var a=this.innerHTML,b=Blockly.FieldTextInput.htmlInput_.value,c=Blockly.FieldTextInput.htmlInput_.selectionEnd,a=b.slice(0,Blockly.FieldTextInput.htmlInput_.selectionStart)+a+b.slice(c);Blockly.FieldTextInput.htmlInput_.value=a;Blockly.FieldNumber.superClass_.resizeEditor_.call(Blockly.FieldNumber.activeField_);Blockly.FieldTextInput.htmlInput_.setSelectionRange(a.length,a.length);Blockly.FieldTextInput.htmlInput_.scrollLeft=Blockly.FieldTextInput.htmlInput_.scrollWidth;
|
||||
Blockly.FieldNumber.activeField_.validate_()};
|
||||
Blockly.FieldNumber.numPadEraseButtonTouch_=function(){var a=Blockly.FieldTextInput.htmlInput_.value,b=Blockly.FieldTextInput.htmlInput_.selectionStart,c=Blockly.FieldTextInput.htmlInput_.selectionEnd,d=a.slice(0,b)+a.slice(c);0==c-b&&(d=a.slice(0,b-1)+a.slice(b));Blockly.FieldTextInput.htmlInput_.value=d;Blockly.FieldNumber.superClass_.resizeEditor_.call(Blockly.FieldNumber.activeField_);Blockly.FieldTextInput.htmlInput_.setSelectionRange(d.length,d.length);Blockly.FieldTextInput.htmlInput_.scrollLeft=
|
||||
Blockly.FieldTextInput.htmlInput_.scrollWidth;Blockly.FieldNumber.activeField_.validate_()};Blockly.FieldNumber.prototype.onHide_=function(){Blockly.DropDownDiv.content_.removeAttribute("role");Blockly.DropDownDiv.content_.removeAttribute("aria-haspopup")};Blockly.FieldNumber.numberValidator=function(a){a=Blockly.FieldTextInput.numberValidator(a);null!==a&&(a=parseFloat(a),a=Math.min(Math.max(a,this.min_),this.max_),a=a.toFixed(this.precision_),a=parseFloat(a),a=String(a));return a};
|
||||
Blockly.FieldNumber.prototype.getBorderRadius=function(){return Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS};Blockly.FieldCheckbox=function(a,b){Blockly.FieldCheckbox.superClass_.constructor.call(this,"",b);this.setValue(a)};goog.inherits(Blockly.FieldCheckbox,Blockly.Field);Blockly.FieldCheckbox.CHECK_CHAR="\u2713";Blockly.FieldCheckbox.prototype.CURSOR="default";
|
||||
Blockly.FieldTextInput.htmlInput_.scrollWidth;Blockly.FieldNumber.activeField_.validate_()};Blockly.FieldNumber.prototype.onHide_=function(){Blockly.DropDownDiv.content_.removeAttribute("role");Blockly.DropDownDiv.content_.removeAttribute("aria-haspopup")};Blockly.FieldNumber.prototype.getBorderRadius=function(){return Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS};Blockly.FieldCheckbox=function(a,b){Blockly.FieldCheckbox.superClass_.constructor.call(this,"",b);this.setValue(a)};goog.inherits(Blockly.FieldCheckbox,Blockly.Field);Blockly.FieldCheckbox.CHECK_CHAR="\u2713";Blockly.FieldCheckbox.prototype.CURSOR="default";
|
||||
Blockly.FieldCheckbox.prototype.init=function(){if(!this.fieldGroup_){Blockly.FieldCheckbox.superClass_.init.call(this);this.checkElement_=Blockly.createSvgElement("text",{"class":"blocklyText blocklyCheckbox",x:-3,y:14},this.fieldGroup_);var a=document.createTextNode(Blockly.FieldCheckbox.CHECK_CHAR);this.checkElement_.appendChild(a);this.checkElement_.style.display=this.state_?"block":"none"}};Blockly.FieldCheckbox.prototype.getValue=function(){return String(this.state_).toUpperCase()};
|
||||
Blockly.FieldCheckbox.prototype.setValue=function(a){a="TRUE"==a;this.state_!==a&&(this.sourceBlock_&&Blockly.Events.isEnabled()&&Blockly.Events.fire(new Blockly.Events.Change(this.sourceBlock_,"field",this.name,this.state_,a)),this.state_=a,this.checkElement_&&(this.checkElement_.style.display=a?"block":"none"))};Blockly.FieldCheckbox.prototype.showEditor_=function(){var a=!this.state_;if(this.sourceBlock_&&this.validator_){var b=this.validator_(a);void 0!==b&&(a=b)}null!==a&&this.setValue(String(a).toUpperCase())};Blockly.FieldColour=function(a,b){Blockly.FieldColour.superClass_.constructor.call(this,a,b);this.setText(Blockly.Field.NBSP+Blockly.Field.NBSP+Blockly.Field.NBSP)};goog.inherits(Blockly.FieldColour,Blockly.Field);Blockly.FieldColour.prototype.colours_=null;Blockly.FieldColour.prototype.columns_=0;Blockly.FieldColour.prototype.init=function(a){Blockly.FieldColour.superClass_.init.call(this,a);this.borderRect_&&(this.borderRect_.style.fillOpacity=1);this.setValue(this.getValue())};
|
||||
Blockly.FieldColour.prototype.CURSOR="default";Blockly.FieldColour.prototype.dispose=function(){Blockly.WidgetDiv.hideIfOwner(this);Blockly.FieldColour.superClass_.dispose.call(this)};Blockly.FieldColour.prototype.getValue=function(){return this.colour_};
|
||||
|
|
|
@ -1236,9 +1236,8 @@ Blockly.BlockSvg.INNER_BOTTOM_LEFT_CORNER="a "+Blockly.BlockSvg.CORNER_RADIUS+",
|
|||
Blockly.BlockSvg.INPUT_SHAPE_BOOLEAN="M "+4*Blockly.BlockSvg.GRID_UNIT+",0 h "+4*Blockly.BlockSvg.GRID_UNIT+" l "+4*Blockly.BlockSvg.GRID_UNIT+","+4*Blockly.BlockSvg.GRID_UNIT+" l "+-4*Blockly.BlockSvg.GRID_UNIT+","+4*Blockly.BlockSvg.GRID_UNIT+" h "+-4*Blockly.BlockSvg.GRID_UNIT+" l "+-4*Blockly.BlockSvg.GRID_UNIT+","+-4*Blockly.BlockSvg.GRID_UNIT+" l "+4*Blockly.BlockSvg.GRID_UNIT+","+-4*Blockly.BlockSvg.GRID_UNIT+" z";Blockly.BlockSvg.INPUT_SHAPE_BOOLEAN_WIDTH=10*Blockly.BlockSvg.GRID_UNIT;
|
||||
Blockly.BlockSvg.INPUT_SHAPE_STRING=Blockly.BlockSvg.TOP_LEFT_CORNER_START+Blockly.BlockSvg.TOP_LEFT_CORNER+" h "+(12*Blockly.BlockSvg.GRID_UNIT-2*Blockly.BlockSvg.CORNER_RADIUS)+Blockly.BlockSvg.TOP_RIGHT_CORNER+" v "+(8*Blockly.BlockSvg.GRID_UNIT-2*Blockly.BlockSvg.CORNER_RADIUS)+Blockly.BlockSvg.BOTTOM_RIGHT_CORNER+" h "+(-12*Blockly.BlockSvg.GRID_UNIT+2*Blockly.BlockSvg.CORNER_RADIUS)+Blockly.BlockSvg.BOTTOM_LEFT_CORNER+" z";Blockly.BlockSvg.INPUT_SHAPE_STRING_WIDTH=9*Blockly.BlockSvg.GRID_UNIT;
|
||||
Blockly.BlockSvg.INPUT_SHAPE_NUMBER="M "+4*Blockly.BlockSvg.GRID_UNIT+",0 h "+4*Blockly.BlockSvg.GRID_UNIT+" a "+4*Blockly.BlockSvg.GRID_UNIT+" "+4*Blockly.BlockSvg.GRID_UNIT+" 0 0 1 0 "+8*Blockly.BlockSvg.GRID_UNIT+" h "+-4*Blockly.BlockSvg.GRID_UNIT+" a "+4*Blockly.BlockSvg.GRID_UNIT+" "+4*Blockly.BlockSvg.GRID_UNIT+" 0 0 1 0 -"+8*Blockly.BlockSvg.GRID_UNIT+" z";Blockly.BlockSvg.INPUT_SHAPE_NUMBER_WIDTH=10*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.INPUT_SHAPE_HEIGHT=8*Blockly.BlockSvg.GRID_UNIT;
|
||||
Blockly.BlockSvg.FIELD_HEIGHT=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT=52*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT=Blockly.BlockSvg.FIELD_HEIGHT;Blockly.BlockSvg.FIELD_TOP_PADDING=1.5*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS=4*Blockly.BlockSvg.GRID_UNIT;
|
||||
Blockly.BlockSvg.TEXT_FIELD_CORNER_RADIUS=1*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_DEFAULT_CORNER_RADIUS=4*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.MAX_DISPLAY_LENGTH=Infinity;Blockly.BlockSvg.NO_PREVIOUS_INPUT_X_MIN=12*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.INLINE_PADDING_Y=2*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_INITIAL=12;Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_FINAL=12;Blockly.BlockSvg.FIELD_TEXTINPUT_EXPAND_PAST_TRUNCATION=!1;
|
||||
Blockly.BlockSvg.FIELD_TEXTINPUT_ANIMATE_POSITIONING=!1;
|
||||
Blockly.BlockSvg.FIELD_HEIGHT=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT=8*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT=Infinity;Blockly.BlockSvg.FIELD_HEIGHT_MAX_EDIT=Blockly.BlockSvg.FIELD_HEIGHT;Blockly.BlockSvg.FIELD_TOP_PADDING=1.5*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS=4*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.TEXT_FIELD_CORNER_RADIUS=1*Blockly.BlockSvg.GRID_UNIT;
|
||||
Blockly.BlockSvg.FIELD_DEFAULT_CORNER_RADIUS=4*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.MAX_DISPLAY_LENGTH=Infinity;Blockly.BlockSvg.NO_PREVIOUS_INPUT_X_MIN=12*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.INLINE_PADDING_Y=2*Blockly.BlockSvg.GRID_UNIT;Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_INITIAL=12;Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_FINAL=12;Blockly.BlockSvg.FIELD_TEXTINPUT_EXPAND_PAST_TRUNCATION=!1;Blockly.BlockSvg.FIELD_TEXTINPUT_ANIMATE_POSITIONING=!1;
|
||||
Blockly.BlockSvg.prototype.updateColour=function(){var a=this.getColourTertiary();this.isShadow()&&this.parentBlock_&&(a=this.parentBlock_.getColourTertiary());this.svgPath_.setAttribute("stroke",a);a=this.isGlowingBlock_?this.getColourSecondary():this.getColour();this.svgPath_.setAttribute("fill",a);this.svgPath_.setAttribute("fill-opacity",this.getOpacity());for(var b in this.inputShapes_)this.inputShapes_[b].setAttribute("fill",this.getColourTertiary());b=this.getIcons();for(a=0;a<b.length;a++)b[a].updateColour();
|
||||
for(b=0;a=this.inputList[b];b++)for(var c=0,d;d=a.fieldRow[c];c++)d.setText(null)};Blockly.BlockSvg.prototype.highlightForReplacement=function(a){a?this.svgPath_.setAttribute("filter","url(#blocklyReplacementGlowFilter)"):this.svgPath_.removeAttribute("filter")};
|
||||
Blockly.BlockSvg.prototype.highlightShapeForInput=function(a,b){var c=this.getInputWithConnection(a);if(!c)throw"No input found for the connection";c=this.inputShapes_[c.name];b?c.setAttribute("filter","url(#blocklyReplacementGlowFilter)"):c.removeAttribute("filter")};Blockly.BlockSvg.prototype.getHeightWidth=function(){var a=this.height,b=this.width,c=this.getNextBlock();c&&(c=c.getHeightWidth(),a+=c.height,a-=Blockly.BlockSvg.NOTCH_HEIGHT,b=Math.max(b,c.width));return{height:a,width:b}};
|
||||
|
@ -1291,13 +1290,13 @@ Blockly.genUid=function(){for(var a=Blockly.genUid.soup_.length,b=[],c=0;20>c;c+
|
|||
Blockly.utils.wrap_line_=function(a,b){if(a.length<=b)return a;for(var c=a.trim().split(/\s+/),d=0;d<c.length;d++)c[d].length>b&&(b=c[d].length);var e,d=-Infinity,f,g=1;do{e=d;f=a;for(var h=[],k=c.length/g,l=1,d=0;d<c.length-1;d++)l<(d+1.5)/k?(l++,h[d]=!0):h[d]=!1;h=Blockly.utils.wrapMutate_(c,h,b);d=Blockly.utils.wrapScore_(c,h,b);a=Blockly.utils.wrapToText_(c,h);g++}while(d>e);return f};
|
||||
Blockly.utils.wrapScore_=function(a,b,c){for(var d=[0],e=[],f=0;f<a.length;f++)d[d.length-1]+=a[f].length,!0===b[f]?(d.push(0),e.push(a[f].charAt(a[f].length-1))):!1===b[f]&&d[d.length-1]++;a=Math.max.apply(Math,d);for(f=b=0;f<d.length;f++)b-=2*Math.pow(Math.abs(c-d[f]),1.5),b-=Math.pow(a-d[f],1.5),-1!=".?!".indexOf(e[f])?b+=c/3:-1!=",;)]}".indexOf(e[f])&&(b+=c/4);1<d.length&&d[d.length-1]<=d[d.length-2]&&(b+=.5);return b};
|
||||
Blockly.utils.wrapMutate_=function(a,b,c){for(var d=Blockly.utils.wrapScore_(a,b,c),e,f=0;f<b.length-1;f++)if(b[f]!=b[f+1]){var g=[].concat(b);g[f]=!g[f];g[f+1]=!g[f+1];var h=Blockly.utils.wrapScore_(a,g,c);h>d&&(d=h,e=g)}return e?Blockly.utils.wrapMutate_(a,e,c):b};Blockly.utils.wrapToText_=function(a,b){for(var c=[],d=0;d<a.length;d++)c.push(a[d]),void 0!==b[d]&&c.push(b[d]?"\n":" ");return c.join("")};
|
||||
Blockly.measureText=function(a,b,c,d){var e=document.createElement("canvas").getContext("2d");e.font=c+" "+a+" "+b;return e.measureText(d).width};Blockly.FieldTextInput=function(a,b){Blockly.FieldTextInput.superClass_.constructor.call(this,a,b)};goog.inherits(Blockly.FieldTextInput,Blockly.Field);Blockly.FieldTextInput.ANIMATION_TIME=.25;Blockly.FieldTextInput.TEXT_MEASURE_PADDING_MAGIC=45;Blockly.FieldTextInput.prototype.CURSOR="text";Blockly.FieldTextInput.prototype.spellcheck_=!0;Blockly.FieldTextInput.prototype.dispose=function(){Blockly.WidgetDiv.hideIfOwner(this);Blockly.FieldTextInput.superClass_.dispose.call(this)};
|
||||
Blockly.FieldTextInput.prototype.setValue=function(a){if(null!==a){if(this.sourceBlock_&&this.validator_){var b=this.validator_(a);null!==b&&void 0!==b&&(a=b)}Blockly.Field.prototype.setValue.call(this,a)}};Blockly.FieldTextInput.prototype.setSpellcheck=function(a){this.spellcheck_=a};
|
||||
Blockly.measureText=function(a,b,c,d){var e=document.createElement("canvas").getContext("2d");e.font=c+" "+a+" "+b;return e.measureText(d).width};Blockly.FieldTextInput=function(a,b,c){Blockly.FieldTextInput.superClass_.constructor.call(this,a,b);this.setRestrictor(c)};goog.inherits(Blockly.FieldTextInput,Blockly.Field);Blockly.FieldTextInput.ANIMATION_TIME=.25;Blockly.FieldTextInput.TEXT_MEASURE_PADDING_MAGIC=45;Blockly.FieldTextInput.prototype.CURSOR="text";Blockly.FieldTextInput.prototype.spellcheck_=!0;Blockly.FieldTextInput.prototype.dispose=function(){Blockly.WidgetDiv.hideIfOwner(this);Blockly.FieldTextInput.superClass_.dispose.call(this)};
|
||||
Blockly.FieldTextInput.prototype.setValue=function(a){if(null!==a){if(this.sourceBlock_&&this.validator_){var b=this.validator_(a);null!==b&&void 0!==b&&(a=b)}Blockly.Field.prototype.setValue.call(this,a)}};Blockly.FieldTextInput.prototype.setSpellcheck=function(a){this.spellcheck_=a};Blockly.FieldTextInput.prototype.setRestrictor=function(a){this.restrictor_=a};
|
||||
Blockly.FieldTextInput.prototype.showEditor_=function(a,b){this.workspace_=this.sourceBlock_.workspace;var c=a||!1,d=b||!1;Blockly.WidgetDiv.show(this,this.sourceBlock_.RTL,this.widgetDispose_(),this.widgetDisposeAnimationFinished_(),Blockly.FieldTextInput.ANIMATION_TIME);var e=Blockly.WidgetDiv.DIV;e.className+=" fieldTextInput";var f=goog.dom.createDom("input","blocklyHtmlInput");f.setAttribute("spellcheck",this.spellcheck_);d&&f.setAttribute("readonly","true");Blockly.FieldTextInput.htmlInput_=
|
||||
f;e.appendChild(f);f.value=f.defaultValue=this.text_;f.oldValue_=null;this.validate_();this.resizeEditor_();c||(f.focus(),f.select(),f.setSelectionRange(0,99999));f.onKeyDownWrapper_=Blockly.bindEvent_(f,"keydown",this,this.onHtmlInputKeyDown_);f.onKeyUpWrapper_=Blockly.bindEvent_(f,"keyup",this,this.onHtmlInputChange_);f.onKeyPressWrapper_=Blockly.bindEvent_(f,"keypress",this,this.onHtmlInputChange_);f.onInputWrapper_=Blockly.bindEvent_(f,"input",this,this.onHtmlInputChange_);f.onWorkspaceChangeWrapper_=
|
||||
this.resizeEditor_.bind(this);this.workspace_.addChangeListener(f.onWorkspaceChangeWrapper_);c="box-shadow "+Blockly.FieldTextInput.ANIMATION_TIME+"s";Blockly.BlockSvg.FIELD_TEXTINPUT_ANIMATE_POSITIONING&&(e.style.transition+=",padding "+Blockly.FieldTextInput.ANIMATION_TIME+"s,width "+Blockly.FieldTextInput.ANIMATION_TIME+"s,height "+Blockly.FieldTextInput.ANIMATION_TIME+"s,margin-left "+Blockly.FieldTextInput.ANIMATION_TIME+"s");e.style.transition=c;f.style.transition="font-size "+Blockly.FieldTextInput.ANIMATION_TIME+
|
||||
"s";f.style.fontSize=Blockly.BlockSvg.FIELD_TEXTINPUT_FONTSIZE_FINAL+"pt";e.style.boxShadow="0px 0px 0px 4px "+Blockly.Colours.fieldShadow};Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_=function(a){var b=Blockly.FieldTextInput.htmlInput_;13==a.keyCode?Blockly.WidgetDiv.hide():27==a.keyCode?(b.value=b.defaultValue,Blockly.WidgetDiv.hide()):9==a.keyCode&&(Blockly.WidgetDiv.hide(),this.sourceBlock_.tab(this,!a.shiftKey),a.preventDefault())};
|
||||
Blockly.FieldTextInput.prototype.onHtmlInputChange_=function(a){a=Blockly.FieldTextInput.htmlInput_;var b=a.value;b!==a.oldValue_?(a.oldValue_=b,this.setValue(b),this.validate_()):goog.userAgent.WEBKIT&&this.sourceBlock_.render();this.resizeEditor_();Blockly.svgResize(this.sourceBlock_.workspace)};
|
||||
Blockly.FieldTextInput.prototype.onHtmlInputChange_=function(a){if("keypress"===a.type&&this.restrictor_){var b=String.fromCharCode(a.keyCode);if(!this.restrictor_.test(b)&&a.preventDefault){a.preventDefault();return}}a=Blockly.FieldTextInput.htmlInput_;b=a.value;b!==a.oldValue_?(a.oldValue_=b,this.setValue(b),this.validate_()):goog.userAgent.WEBKIT&&this.sourceBlock_.render();this.resizeEditor_();Blockly.svgResize(this.sourceBlock_.workspace)};
|
||||
Blockly.FieldTextInput.prototype.validate_=function(){var a=!0;goog.asserts.assertObject(Blockly.FieldTextInput.htmlInput_);var b=Blockly.FieldTextInput.htmlInput_;this.sourceBlock_&&this.validator_&&(a=this.validator_(b.value));null===a?Blockly.addClass_(b,"blocklyInvalidInput"):Blockly.removeClass_(b,"blocklyInvalidInput")};
|
||||
Blockly.FieldTextInput.prototype.resizeEditor_=function(){var a=this.sourceBlock_.workspace.scale,b=Blockly.WidgetDiv.DIV,c;Blockly.BlockSvg.FIELD_TEXTINPUT_EXPAND_PAST_TRUNCATION?(c=Blockly.measureText(Blockly.FieldTextInput.htmlInput_.style.fontSize,Blockly.FieldTextInput.htmlInput_.style.fontFamily,Blockly.FieldTextInput.htmlInput_.style.fontWeight,Blockly.FieldTextInput.htmlInput_.value),c+=Blockly.FieldTextInput.TEXT_MEASURE_PADDING_MAGIC,c*=a):c=this.sourceBlock_.getHeightWidth().width*a;c=
|
||||
Math.max(c,Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT*a);c=Math.min(c,Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT*a);b.style.width=c/a+1+"px";b.style.height=Blockly.BlockSvg.FIELD_HEIGHT+1+"px";b.style.transform="scale("+a+")";var d=this.sourceBlock_.getHeightWidth().width;b.style.marginLeft=-.5*(c-d*a)+"px";d=this.getBorderRadius()+.5;b.style.borderRadius=d+"px";d=this.sourceBlock_.getColourTertiary();b.style.borderColor=d;d=this.getAbsoluteXY_();d.x-=a/2;d.y-=a/2;this.sourceBlock_.RTL&&(d.x+=c,d.x-=b.offsetWidth*
|
||||
|
@ -1315,18 +1314,17 @@ Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGE
|
|||
b,this.setValue(b),this.validate_(),this.resizeEditor_())};Blockly.FieldAngle.prototype.setText=function(a){Blockly.FieldAngle.superClass_.setText.call(this,a);this.textElement_&&(this.updateGraph_(),this.sourceBlock_.RTL?this.textElement_.insertBefore(this.symbol_,this.textElement_.firstChild):this.textElement_.appendChild(this.symbol_),this.size_.width=0)};
|
||||
Blockly.FieldAngle.prototype.updateGraph_=function(){if(this.gauge_){var a=Number(this.getText())+Blockly.FieldAngle.OFFSET,b=goog.math.toRadians(a),a=["M ",Blockly.FieldAngle.HALF,",",Blockly.FieldAngle.HALF],c=Blockly.FieldAngle.HALF,d=Blockly.FieldAngle.HALF;if(!isNaN(b)){var e=goog.math.toRadians(Blockly.FieldAngle.OFFSET),f=Math.cos(e)*Blockly.FieldAngle.RADIUS,g=Math.sin(e)*-Blockly.FieldAngle.RADIUS;Blockly.FieldAngle.CLOCKWISE&&(b=2*e-b);c+=Math.cos(b)*Blockly.FieldAngle.RADIUS;d-=Math.sin(b)*
|
||||
Blockly.FieldAngle.RADIUS;b=Math.abs(Math.floor((b-e)/Math.PI)%2);Blockly.FieldAngle.CLOCKWISE&&(b=1-b);a.push(" l ",f,",",g," A ",Blockly.FieldAngle.RADIUS,",",Blockly.FieldAngle.RADIUS," 0 ",b," ",Number(Blockly.FieldAngle.CLOCKWISE)," ",c,",",d," z")}this.gauge_.setAttribute("d",a.join(""));this.line_.setAttribute("x2",c);this.line_.setAttribute("y2",d)}};
|
||||
Blockly.FieldAngle.angleValidator=function(a){if(null===a)return null;a=parseFloat(a||0);if(isNaN(a))return null;a%=360;0>a&&(a+=360);a>Blockly.FieldAngle.WRAP&&(a-=360);return String(a)};Blockly.FieldNumber=function(a,b,c,d,e){this.precision_=c;this.min_=d;this.max_=e;Blockly.FieldNumber.superClass_.constructor.call(this,a,b)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.DROPDOWN_WIDTH=168;Blockly.FieldNumber.DROPDOWN_Y_PADDING=8;Blockly.FieldNumber.NUMPAD_BUTTONS="789456123.0".split("");
|
||||
Blockly.FieldAngle.angleValidator=function(a){if(null===a)return null;a=parseFloat(a||0);if(isNaN(a))return null;a%=360;0>a&&(a+=360);a>Blockly.FieldAngle.WRAP&&(a-=360);return String(a)};var getNumRestrictor=function(a,b){var c="[\\d]";a&&(c+="|[\\.]");b&&(c+="|[-]");return new RegExp(c)};Blockly.FieldNumber=function(a,b,c,d,e){this.decimalAllowed_="undefined"==typeof d||isNaN(d)||0==d||Math.floor(d)!=d;this.negativeAllowed_="undefined"==typeof b||isNaN(b)||0>b;b=getNumRestrictor(this.decimalAllowed_,this.negativeAllowed_);Blockly.FieldNumber.superClass_.constructor.call(this,a,e,b)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.DROPDOWN_WIDTH=168;
|
||||
Blockly.FieldNumber.DROPDOWN_Y_PADDING=8;Blockly.FieldNumber.NUMPAD_BUTTONS="789456123.0".split("");
|
||||
Blockly.FieldNumber.NUMPAD_DELETE_ICON='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><path d="M28.89,11.45H16.79a2.86,2.86,0,0,0-2,.84L9.09,18a2.85,2.85,0,0,0,0,4l5.69,5.69a2.86,2.86,0,0,0,2,.84h12.1a2.86,2.86,0,0,0,2.86-2.86V14.31A2.86,2.86,0,0,0,28.89,11.45ZM27.15,22.73a1,1,0,0,1,0,1.41,1,1,0,0,1-.71.3,1,1,0,0,1-.71-0.3L23,21.41l-2.73,2.73a1,1,0,0,1-1.41,0,1,1,0,0,1,0-1.41L21.59,20l-2.73-2.73a1,1,0,0,1,0-1.41,1,1,0,0,1,1.41,0L23,18.59l2.73-2.73a1,1,0,1,1,1.42,1.41L24.42,20Z" fill="'+Blockly.Colours.numPadText+
|
||||
'"/></svg>';Blockly.FieldNumber.activeField_=null;Blockly.FieldNumber.prototype.setValidator=function(a){Blockly.FieldNumber.superClass_.setValidator.call(this,a?function(b){var c=a.call(this,b),d;null===c?d=c:(void 0===c&&(c=b),d=Blockly.FieldNumber.numberValidator.call(this,c),void 0===d&&(d=c));return d===b?void 0:d}:Blockly.FieldNumber.numberValidator)};
|
||||
Blockly.FieldNumber.prototype.showEditor_=function(){Blockly.FieldNumber.activeField_=this;var a=goog.userAgent.MOBILE||goog.userAgent.ANDROID||goog.userAgent.IPAD;Blockly.FieldNumber.superClass_.showEditor_.call(this,!1,a);a&&this.showNumPad_()};
|
||||
'"/></svg>';Blockly.FieldNumber.activeField_=null;Blockly.FieldNumber.prototype.setConstraints_=function(a,b,c){this.decimalAllowed_="undefined"==typeof c||isNaN(c)||0==c||Math.floor(c)!=c;this.negativeAllowed_="undefined"==typeof a||isNaN(a)||0>a};Blockly.FieldNumber.prototype.showEditor_=function(){Blockly.FieldNumber.activeField_=this;var a=goog.userAgent.MOBILE||goog.userAgent.ANDROID||goog.userAgent.IPAD;Blockly.FieldNumber.superClass_.showEditor_.call(this,!1,a);a&&this.showNumPad_()};
|
||||
Blockly.FieldNumber.prototype.showNumPad_=function(){Blockly.DropDownDiv.hideWithoutAnimation();Blockly.DropDownDiv.clearContent();var a=Blockly.DropDownDiv.getContentDiv();a.setAttribute("role","menu");a.setAttribute("aria-haspopup","true");for(var b=Blockly.FieldNumber.NUMPAD_BUTTONS,c=0,d;d=b[c];c++){var e=document.createElement("button");e.setAttribute("role","menuitem");e.setAttribute("class","blocklyNumPadButton");e.title=d;e.innerHTML=d;Blockly.bindEvent_(e,"mousedown",e,Blockly.FieldNumber.numPadButtonTouch_);
|
||||
"."==d&&0==this.precision_&&e.setAttribute("style","visibility: hidden");a.appendChild(e)}b=document.createElement("button");b.setAttribute("role","menuitem");b.setAttribute("class","blocklyNumPadButton");b.title="Delete";c=document.createElement("img");c.src=Blockly.FieldNumber.NUMPAD_DELETE_ICON;b.appendChild(c);Blockly.bindEvent_(b,"mousedown",null,Blockly.FieldNumber.numPadEraseButtonTouch_);a.appendChild(b);Blockly.DropDownDiv.setColour(Blockly.Colours.numPadBackground,Blockly.Colours.numPadBorder);
|
||||
"."!=d||this.decimalAllowed||e.setAttribute("style","visibility: hidden");a.appendChild(e)}b=document.createElement("button");b.setAttribute("role","menuitem");b.setAttribute("class","blocklyNumPadButton");b.title="Delete";c=document.createElement("img");c.src=Blockly.FieldNumber.NUMPAD_DELETE_ICON;b.appendChild(c);Blockly.bindEvent_(b,"mousedown",null,Blockly.FieldNumber.numPadEraseButtonTouch_);a.appendChild(b);Blockly.DropDownDiv.setColour(Blockly.Colours.numPadBackground,Blockly.Colours.numPadBorder);
|
||||
a.style.width=Blockly.FieldNumber.DROPDOWN_WIDTH+"px";b=this.sourceBlock_.workspace.scale;d=this.sourceBlock_.getHeightWidth();d.width*=b;d.height*=b;c=this.getAbsoluteXY_();a=c.x+d.width/2;d=c.y+d.height+Blockly.FieldNumber.DROPDOWN_Y_PADDING;b=c.y-Blockly.BlockSvg.MIN_BLOCK_Y*b-Blockly.BlockSvg.FIELD_Y_OFFSET*b;Blockly.DropDownDiv.setBoundsElement(this.sourceBlock_.workspace.getParentSvg().parentNode);Blockly.DropDownDiv.show(this,a,d,a,b,this.onHide_.bind(this))};
|
||||
Blockly.FieldNumber.numPadButtonTouch_=function(){var a=this.innerHTML,b=Blockly.FieldTextInput.htmlInput_.value,c=Blockly.FieldTextInput.htmlInput_.selectionEnd,a=b.slice(0,Blockly.FieldTextInput.htmlInput_.selectionStart)+a+b.slice(c);Blockly.FieldTextInput.htmlInput_.value=a;Blockly.FieldNumber.superClass_.resizeEditor_.call(Blockly.FieldNumber.activeField_);Blockly.FieldTextInput.htmlInput_.setSelectionRange(a.length,a.length);Blockly.FieldTextInput.htmlInput_.scrollLeft=Blockly.FieldTextInput.htmlInput_.scrollWidth;
|
||||
Blockly.FieldNumber.activeField_.validate_()};
|
||||
Blockly.FieldNumber.numPadEraseButtonTouch_=function(){var a=Blockly.FieldTextInput.htmlInput_.value,b=Blockly.FieldTextInput.htmlInput_.selectionStart,c=Blockly.FieldTextInput.htmlInput_.selectionEnd,d=a.slice(0,b)+a.slice(c);0==c-b&&(d=a.slice(0,b-1)+a.slice(b));Blockly.FieldTextInput.htmlInput_.value=d;Blockly.FieldNumber.superClass_.resizeEditor_.call(Blockly.FieldNumber.activeField_);Blockly.FieldTextInput.htmlInput_.setSelectionRange(d.length,d.length);Blockly.FieldTextInput.htmlInput_.scrollLeft=
|
||||
Blockly.FieldTextInput.htmlInput_.scrollWidth;Blockly.FieldNumber.activeField_.validate_()};Blockly.FieldNumber.prototype.onHide_=function(){Blockly.DropDownDiv.content_.removeAttribute("role");Blockly.DropDownDiv.content_.removeAttribute("aria-haspopup")};Blockly.FieldNumber.numberValidator=function(a){a=Blockly.FieldTextInput.numberValidator(a);null!==a&&(a=parseFloat(a),a=Math.min(Math.max(a,this.min_),this.max_),a=a.toFixed(this.precision_),a=parseFloat(a),a=String(a));return a};
|
||||
Blockly.FieldNumber.prototype.getBorderRadius=function(){return Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS};Blockly.FieldCheckbox=function(a,b){Blockly.FieldCheckbox.superClass_.constructor.call(this,"",b);this.setValue(a)};goog.inherits(Blockly.FieldCheckbox,Blockly.Field);Blockly.FieldCheckbox.CHECK_CHAR="\u2713";Blockly.FieldCheckbox.prototype.CURSOR="default";
|
||||
Blockly.FieldTextInput.htmlInput_.scrollWidth;Blockly.FieldNumber.activeField_.validate_()};Blockly.FieldNumber.prototype.onHide_=function(){Blockly.DropDownDiv.content_.removeAttribute("role");Blockly.DropDownDiv.content_.removeAttribute("aria-haspopup")};Blockly.FieldNumber.prototype.getBorderRadius=function(){return Blockly.BlockSvg.NUMBER_FIELD_CORNER_RADIUS};Blockly.FieldCheckbox=function(a,b){Blockly.FieldCheckbox.superClass_.constructor.call(this,"",b);this.setValue(a)};goog.inherits(Blockly.FieldCheckbox,Blockly.Field);Blockly.FieldCheckbox.CHECK_CHAR="\u2713";Blockly.FieldCheckbox.prototype.CURSOR="default";
|
||||
Blockly.FieldCheckbox.prototype.init=function(){if(!this.fieldGroup_){Blockly.FieldCheckbox.superClass_.init.call(this);this.checkElement_=Blockly.createSvgElement("text",{"class":"blocklyText blocklyCheckbox",x:-3,y:14},this.fieldGroup_);var a=document.createTextNode(Blockly.FieldCheckbox.CHECK_CHAR);this.checkElement_.appendChild(a);this.checkElement_.style.display=this.state_?"block":"none"}};Blockly.FieldCheckbox.prototype.getValue=function(){return String(this.state_).toUpperCase()};
|
||||
Blockly.FieldCheckbox.prototype.setValue=function(a){a="TRUE"==a;this.state_!==a&&(this.sourceBlock_&&Blockly.Events.isEnabled()&&Blockly.Events.fire(new Blockly.Events.Change(this.sourceBlock_,"field",this.name,this.state_,a)),this.state_=a,this.checkElement_&&(this.checkElement_.style.display=a?"block":"none"))};Blockly.FieldCheckbox.prototype.showEditor_=function(){var a=!this.state_;if(this.sourceBlock_&&this.validator_){var b=this.validator_(a);void 0!==b&&(a=b)}null!==a&&this.setValue(String(a).toUpperCase())};Blockly.FieldColour=function(a,b){Blockly.FieldColour.superClass_.constructor.call(this,a,b);this.setText(Blockly.Field.NBSP+Blockly.Field.NBSP+Blockly.Field.NBSP)};goog.inherits(Blockly.FieldColour,Blockly.Field);Blockly.FieldColour.prototype.colours_=null;Blockly.FieldColour.prototype.columns_=0;Blockly.FieldColour.prototype.init=function(a){Blockly.FieldColour.superClass_.init.call(this,a);this.borderRect_&&(this.borderRect_.style.fillOpacity=1);this.setValue(this.getValue())};
|
||||
Blockly.FieldColour.prototype.CURSOR="default";Blockly.FieldColour.prototype.dispose=function(){Blockly.WidgetDiv.hideIfOwner(this);Blockly.FieldColour.superClass_.dispose.call(this)};Blockly.FieldColour.prototype.getValue=function(){return this.colour_};
|
||||
|
|
|
@ -38,15 +38,14 @@ Blockly.Blocks.math.HUE = Blockly.Colours.textField;
|
|||
|
||||
Blockly.Blocks['math_number'] = {
|
||||
/**
|
||||
* Block for numeric value.
|
||||
* Block for generic numeric value.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function() {
|
||||
this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);
|
||||
this.setColour(Blockly.Blocks.math.HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldNumber('0',
|
||||
Blockly.FieldTextInput.numberValidator, 20, -Infinity, Infinity), 'NUM');
|
||||
.appendField(new Blockly.FieldNumber('0'), 'NUM');
|
||||
this.setOutput(true, 'Number');
|
||||
// Assign 'this' to a variable for use in the tooltip closure below.
|
||||
var thisBlock = this;
|
||||
|
@ -61,30 +60,28 @@ Blockly.Blocks['math_number'] = {
|
|||
|
||||
Blockly.Blocks['math_whole_number'] = {
|
||||
/**
|
||||
* Block for whole number value, with min of 0 and max Infinity, precision 0.
|
||||
* Block for whole number value, no negatives or decimals.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function() {
|
||||
this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);
|
||||
this.setColour(Blockly.Blocks.math.HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldNumber('0',
|
||||
Blockly.FieldNumber.numberValidator, 0, 0, Infinity), 'NUM');
|
||||
.appendField(new Blockly.FieldNumber('0', 0, Infinity, 1), 'NUM');
|
||||
this.setOutput(true, 'Number');
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['math_positive_number'] = {
|
||||
/**
|
||||
* Block for positive number value, with min of 0 and max Infinity, precision 20.
|
||||
* Block for positive number value, with decimal.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function() {
|
||||
this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);
|
||||
this.setColour(Blockly.Blocks.math.HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldNumber('0',
|
||||
Blockly.FieldNumber.numberValidator, 20, 0, Infinity), 'NUM');
|
||||
.appendField(new Blockly.FieldNumber('0', 0, Infinity), 'NUM');
|
||||
this.setOutput(true, 'Number');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -65,9 +65,8 @@ CONTINUE:Blockly.Msg.CONTROLS_FLOW_STATEMENTS_TOOLTIP_CONTINUE}[a]})},onchange:f
|
|||
limitations under the License.
|
||||
*/
|
||||
Blockly.Colours={motion:{primary:"#4C97FF",secondary:"#4280D7",tertiary:"#3373CC"},looks:{primary:"#9966FF",secondary:"#855CD6",tertiary:"#774DCB"},sounds:{primary:"#D65CD6",secondary:"#BF40BF",tertiary:"#A63FA6"},control:{primary:"#FFAB19",secondary:"#EC9C13",tertiary:"#CF8B17"},event:{primary:"#FFD500",secondary:"#DBC200",tertiary:"#CCAA00"},operators:{primary:"#4CBF56",secondary:"#489D84",tertiary:"#489D84"},text:"#575E75",workspace:"#F5F8FF",toolbox:"#DDDDDD",toolboxText:"#000000",flyout:"#DDDDDD",
|
||||
scrollbar:"#CCCCCC",scrollbarHover:"#BBBBBB",textField:"#FFFFFF",insertionMarker:"#949494",insertionMarkerOpacity:.6,dragShadowOpacity:.3,stackGlow:"#FFF200",stackGlowOpacity:1,replacementGlow:"#FFFFFF",replacementGlowOpacity:1,fieldShadow:"rgba(0,0,0,0.1)",dropDownShadow:"rgba(0, 0, 0, .3)",numPadBackground:"#547AB2",numPadBorder:"#435F91",numPadActiveBackground:"#435F91",numPadText:"#FFFFFF"};Blockly.Blocks.math={};Blockly.Blocks.math.HUE=Blockly.Colours.textField;Blockly.Blocks.math_number={init:function(){this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);this.setColour(Blockly.Blocks.math.HUE);this.appendDummyInput().appendField(new Blockly.FieldNumber("0",Blockly.FieldTextInput.numberValidator,20,-Infinity,Infinity),"NUM");this.setOutput(!0,"Number");var a=this;this.setTooltip(function(){var b=a.getParent();return b&&b.getInputsInline()&&b.tooltip||Blockly.Msg.MATH_NUMBER_TOOLTIP})}};
|
||||
Blockly.Blocks.math_whole_number={init:function(){this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);this.setColour(Blockly.Blocks.math.HUE);this.appendDummyInput().appendField(new Blockly.FieldNumber("0",Blockly.FieldNumber.numberValidator,0,0,Infinity),"NUM");this.setOutput(!0,"Number")}};
|
||||
Blockly.Blocks.math_positive_number={init:function(){this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);this.setColour(Blockly.Blocks.math.HUE);this.appendDummyInput().appendField(new Blockly.FieldNumber("0",Blockly.FieldNumber.numberValidator,20,0,Infinity),"NUM");this.setOutput(!0,"Number")}};Blockly.Blocks.procedures={};Blockly.Blocks.procedures.HUE=290;
|
||||
scrollbar:"#CCCCCC",scrollbarHover:"#BBBBBB",textField:"#FFFFFF",insertionMarker:"#949494",insertionMarkerOpacity:.6,dragShadowOpacity:.3,stackGlow:"#FFF200",stackGlowOpacity:1,replacementGlow:"#FFFFFF",replacementGlowOpacity:1,fieldShadow:"rgba(0,0,0,0.1)",dropDownShadow:"rgba(0, 0, 0, .3)",numPadBackground:"#547AB2",numPadBorder:"#435F91",numPadActiveBackground:"#435F91",numPadText:"#FFFFFF"};Blockly.Blocks.math={};Blockly.Blocks.math.HUE=Blockly.Colours.textField;Blockly.Blocks.math_number={init:function(){this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);this.setColour(Blockly.Blocks.math.HUE);this.appendDummyInput().appendField(new Blockly.FieldNumber("0"),"NUM");this.setOutput(!0,"Number");var a=this;this.setTooltip(function(){var b=a.getParent();return b&&b.getInputsInline()&&b.tooltip||Blockly.Msg.MATH_NUMBER_TOOLTIP})}};
|
||||
Blockly.Blocks.math_whole_number={init:function(){this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);this.setColour(Blockly.Blocks.math.HUE);this.appendDummyInput().appendField(new Blockly.FieldNumber("0",0,Infinity,1),"NUM");this.setOutput(!0,"Number")}};Blockly.Blocks.math_positive_number={init:function(){this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);this.setColour(Blockly.Blocks.math.HUE);this.appendDummyInput().appendField(new Blockly.FieldNumber("0",0,Infinity),"NUM");this.setOutput(!0,"Number")}};Blockly.Blocks.procedures={};Blockly.Blocks.procedures.HUE=290;
|
||||
Blockly.Blocks.procedures_defnoreturn={init:function(){var a=new Blockly.FieldTextInput(Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE,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"]));Blockly.Msg.PROCEDURES_DEFNORETURN_COMMENT&&this.setCommentText(Blockly.Msg.PROCEDURES_DEFNORETURN_COMMENT);this.setColour(Blockly.Blocks.procedures.HUE);
|
||||
this.setTooltip(Blockly.Msg.PROCEDURES_DEFNORETURN_TOOLTIP);this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL);this.arguments_=[];this.setStatements_(!0);this.statementConnection_=null},validate:function(){var a=Blockly.Procedures.findLegalName(this.getFieldValue("NAME"),this);this.setFieldValue(a,"NAME")},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();this.setFieldValue(a,"PARAMS");Blockly.Events.enable()},
|
||||
|
|
|
@ -324,7 +324,7 @@ Blockly.BlockSvg.FIELD_WIDTH_MIN_EDIT = 8 * Blockly.BlockSvg.GRID_UNIT;
|
|||
* Maximum width of user inputs during editing
|
||||
* @const
|
||||
*/
|
||||
Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT = 52 * Blockly.BlockSvg.GRID_UNIT;
|
||||
Blockly.BlockSvg.FIELD_WIDTH_MAX_EDIT = Infinity;
|
||||
|
||||
/**
|
||||
* Maximum height of user inputs during editing
|
||||
|
|
|
@ -31,24 +31,48 @@ goog.require('goog.math');
|
|||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
/**
|
||||
* Return an appropriate restrictor, depending on whether this FieldNumber
|
||||
* allows decimal or negative numbers.
|
||||
* @param {boolean} decimalAllowed Whether number may have decimal/float component.
|
||||
* @param {boolean} negativeAllowed Whether number may be negative.
|
||||
* @return {!RegExp} Regular expression for this FieldNumber's restrictor.
|
||||
*/
|
||||
var getNumRestrictor = function(decimalAllowed, negativeAllowed) {
|
||||
var pattern = "[\\d]"; // Always allow digits.
|
||||
if (decimalAllowed) {
|
||||
pattern += "|[\\.]";
|
||||
}
|
||||
if (negativeAllowed) {
|
||||
pattern += "|[-]";
|
||||
}
|
||||
return new RegExp(pattern);
|
||||
};
|
||||
|
||||
/**
|
||||
* Class for an editable number field.
|
||||
* @param {string} text The initial content of the field.
|
||||
* In scratch-blocks, the min/max/precision properties are only used
|
||||
* to construct a restrictor on typable characters, and to inform the pop-up numpad on touch devices.
|
||||
* These properties are included here (i.e. instead of just accepting a decimalAllowed, negativeAllowed)
|
||||
* to maintain API compatibility with Blockly and Blockly for Android.
|
||||
* @param {string} value The initial value of the field.
|
||||
* @param {number=} opt_min Minimum number allowed.
|
||||
* @param {number=} opt_max Maximum number allowed.
|
||||
* @param {number=} opt_precision Step allowed between numbers
|
||||
* @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 the accepted text or null to abort
|
||||
* the change.
|
||||
* @param {number} precision Precision of the decimal value (negative power of 10).
|
||||
* @param {number} min Minimum value of the number.
|
||||
* @param {number} max Maximum value of the number.
|
||||
* @extends {Blockly.FieldTextInput}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.FieldNumber = function(text, opt_validator, precision, min, max) {
|
||||
this.precision_ = precision;
|
||||
this.min_ = min;
|
||||
this.max_ = max;
|
||||
Blockly.FieldNumber.superClass_.constructor.call(this, text, opt_validator);
|
||||
Blockly.FieldNumber = function(value, opt_min, opt_max, opt_precision, opt_validator) {
|
||||
this.decimalAllowed_ = (typeof opt_precision == 'undefined') || isNaN(opt_precision) ||
|
||||
(opt_precision == 0) ||
|
||||
(Math.floor(opt_precision) != opt_precision);
|
||||
this.negativeAllowed_ = (typeof opt_min == 'undefined') || isNaN(opt_min) || opt_min < 0;
|
||||
var numRestrictor = getNumRestrictor(this.decimalAllowed_, this.negativeAllowed_);
|
||||
Blockly.FieldNumber.superClass_.constructor.call(this, value, opt_validator, numRestrictor);
|
||||
};
|
||||
goog.inherits(Blockly.FieldNumber, Blockly.FieldTextInput);
|
||||
|
||||
|
@ -102,34 +126,16 @@ Blockly.FieldNumber.NUMPAD_DELETE_ICON = 'data:image/svg+xml;utf8,' +
|
|||
Blockly.FieldNumber.activeField_ = null;
|
||||
|
||||
/**
|
||||
* Sets a new change handler for angle field.
|
||||
* @param {Function} handler New change handler, or null.
|
||||
* Set the constraints for this field.
|
||||
* @param {number=} opt_min Minimum number allowed.
|
||||
* @param {number=} opt_max Maximum number allowed.
|
||||
* @param {number=} opt_precision Step allowed between numbers
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setValidator = function(handler) {
|
||||
var wrappedHandler;
|
||||
if (handler) {
|
||||
// Wrap the user's change handler together with the number validator.
|
||||
// This is copied entirely from FieldAngle.
|
||||
wrappedHandler = function(value) {
|
||||
var v1 = handler.call(this, value);
|
||||
var v2;
|
||||
if (v1 === null) {
|
||||
v2 = v1;
|
||||
} else {
|
||||
if (v1 === undefined) {
|
||||
v1 = value;
|
||||
}
|
||||
v2 = Blockly.FieldNumber.numberValidator.call(this, v1);
|
||||
if (v2 === undefined) {
|
||||
v2 = v1;
|
||||
}
|
||||
}
|
||||
return v2 === value ? undefined : v2;
|
||||
};
|
||||
} else {
|
||||
wrappedHandler = Blockly.FieldNumber.numberValidator;
|
||||
}
|
||||
Blockly.FieldNumber.superClass_.setValidator.call(this, wrappedHandler);
|
||||
Blockly.FieldNumber.prototype.setConstraints_ = function(opt_min, opt_max, opt_precision) {
|
||||
this.decimalAllowed_ = (typeof opt_precision == 'undefined') || isNaN(opt_precision) ||
|
||||
(opt_precision == 0) ||
|
||||
(Math.floor(opt_precision) != opt_precision);
|
||||
this.negativeAllowed_ = (typeof opt_min == 'undefined') || isNaN(opt_min) || opt_min < 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -170,7 +176,7 @@ Blockly.FieldNumber.prototype.showNumPad_ = function() {
|
|||
button.innerHTML = buttonText;
|
||||
Blockly.bindEvent_(button, 'mousedown', button,
|
||||
Blockly.FieldNumber.numPadButtonTouch_);
|
||||
if (buttonText == '.' && this.precision_ == 0) {
|
||||
if (buttonText == '.' && !this.decimalAllowed) {
|
||||
// Don't show the decimal point for inputs that must be round numbers
|
||||
button.setAttribute('style', 'visibility: hidden');
|
||||
}
|
||||
|
@ -267,27 +273,6 @@ Blockly.FieldNumber.prototype.onHide_ = function() {
|
|||
Blockly.DropDownDiv.content_.removeAttribute('aria-haspopup');
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensure that only a number may be entered with the properties of this field.
|
||||
* @param {string} text The user's text.
|
||||
* @return {?string} A string representing a valid angle, or null if invalid.
|
||||
*/
|
||||
Blockly.FieldNumber.numberValidator = function(text) {
|
||||
var n = Blockly.FieldTextInput.numberValidator(text);
|
||||
if (n !== null) {
|
||||
// string -> float
|
||||
n = parseFloat(n);
|
||||
// Keep within min and max
|
||||
n = Math.min(Math.max(n, this.min_), this.max_);
|
||||
// Update float precision (returns a string)
|
||||
n = n.toFixed(this.precision_);
|
||||
// Parse to a float and back to string to remove trailing decimals
|
||||
n = parseFloat(n);
|
||||
n = String(n);
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
||||
/**
|
||||
* Border radius for drawing this field, called when rendering the owning shadow block.
|
||||
* @return {Number} Border radius in px.
|
||||
|
|
|
@ -43,12 +43,16 @@ goog.require('goog.userAgent');
|
|||
* 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 {RegExp=} opt_restrictor An optional regular expression to restrict
|
||||
* typed text to. Text that doesn't match the restrictor will never show
|
||||
* in the text field.
|
||||
* @extends {Blockly.Field}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.FieldTextInput = function(text, opt_validator) {
|
||||
Blockly.FieldTextInput = function(text, opt_validator, opt_restrictor) {
|
||||
Blockly.FieldTextInput.superClass_.constructor.call(this, text,
|
||||
opt_validator);
|
||||
this.setRestrictor(opt_restrictor);
|
||||
};
|
||||
goog.inherits(Blockly.FieldTextInput, Blockly.Field);
|
||||
|
||||
|
@ -109,6 +113,15 @@ Blockly.FieldTextInput.prototype.setSpellcheck = function(check) {
|
|||
this.spellcheck_ = check;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the restrictor regex for this text input.
|
||||
* Text that doesn't match the restrictor will never show in the text field.
|
||||
* @param {?RegExp} restrictor Regular expression to restrict text.
|
||||
*/
|
||||
Blockly.FieldTextInput.prototype.setRestrictor = function(restrictor) {
|
||||
this.restrictor_ = restrictor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the inline free-text editor on top of the text.
|
||||
* @param {boolean=} opt_quietInput True if editor should be created without
|
||||
|
@ -208,6 +221,15 @@ Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) {
|
|||
* @private
|
||||
*/
|
||||
Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(e) {
|
||||
// Check if the key matches the restrictor.
|
||||
if (e.type === 'keypress' && this.restrictor_) {
|
||||
var charCode = String.fromCharCode(e.keyCode);
|
||||
if (!this.restrictor_.test(charCode) && e.preventDefault) {
|
||||
// Failed to pass restrictor.
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
}
|
||||
var htmlInput = Blockly.FieldTextInput.htmlInput_;
|
||||
// Update source block.
|
||||
var text = htmlInput.value;
|
||||
|
|
|
@ -393,15 +393,15 @@
|
|||
<category name="Control">
|
||||
<block type="control_wait">
|
||||
<value name="DURATION">
|
||||
<shadow type="math_number">
|
||||
<shadow type="math_positive_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="control_repeat">
|
||||
<value name="TIMES">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">4</field>
|
||||
<shadow type="math_whole_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
|
@ -543,7 +543,7 @@
|
|||
</block>
|
||||
<block type="operator_letter_of">
|
||||
<value name="LETTER">
|
||||
<shadow type="math_number">
|
||||
<shadow type="math_whole_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue