mirror of
https://github.com/google/blockly.git
synced 2026-01-15 04:47:10 +01:00
@@ -44,9 +44,9 @@ Blockly.utils.dom.createSvgElement=function(a,b,c){a=document.createElementNS(Bl
|
||||
Blockly.utils.dom.removeClass=function(a,b){var c=a.getAttribute("class");if(-1==(" "+c+" ").indexOf(" "+b+" "))return!1;c=c.split(/\s+/);for(var d=0;d<c.length;d++)c[d]&&c[d]!=b||(c.splice(d,1),d--);c.length?a.setAttribute("class",c.join(" ")):a.removeAttribute("class");return!0};Blockly.utils.dom.hasClass=function(a,b){return-1!=(" "+a.getAttribute("class")+" ").indexOf(" "+b+" ")};Blockly.utils.dom.removeNode=function(a){return a&&a.parentNode?a.parentNode.removeChild(a):null};
|
||||
Blockly.utils.dom.insertAfter=function(a,b){var c=b.nextSibling,d=b.parentNode;if(!d)throw Error("Reference node has no parent.");c?d.insertBefore(a,c):d.appendChild(a)};Blockly.utils.dom.containsNode=function(a,b){return!!(a.compareDocumentPosition(b)&Blockly.utils.dom.Node.DOCUMENT_POSITION_CONTAINED_BY)};Blockly.utils.dom.setCssTransform=function(a,b){a.style.transform=b;a.style["-webkit-transform"]=b};
|
||||
Blockly.utils.dom.startTextWidthCache=function(){Blockly.utils.dom.cacheReference_++;Blockly.utils.dom.cacheWidths_||(Blockly.utils.dom.cacheWidths_={})};Blockly.utils.dom.stopTextWidthCache=function(){Blockly.utils.dom.cacheReference_--;Blockly.utils.dom.cacheReference_||(Blockly.utils.dom.cacheWidths_=null)};
|
||||
Blockly.utils.dom.getTextWidth=function(a){var b=a.textContent+"\n"+a.className.baseVal,c;if(Blockly.utils.dom.cacheWidths_&&(c=Blockly.utils.dom.cacheWidths_[b]))return c;try{c=Blockly.utils.userAgent.IE||Blockly.utils.userAgent.EDGE?a.getBBox().width:a.getComputedTextLength()}catch(d){return 8*a.textContent.length}Blockly.utils.dom.cacheWidths_&&(Blockly.utils.dom.cacheWidths_[b]=c);return c};Blockly.utils.math={};Blockly.utils.math.toRadians=function(a){return a*Math.PI/180};Blockly.utils.math.toDegrees=function(a){return 180*a/Math.PI};Blockly.utils.math.clamp=function(a,b,c){if(c<a){var d=c;c=a;a=d}return Math.max(a,Math.min(b,c))};Blockly.Cursor=function(a){this.curNode_=null;this.isMarker_=!!a};Blockly.Cursor.prototype.types={FIELD:"field",BLOCK:"block",INPUT:"input",OUTPUT:"output",NEXT:"next",PREVIOUS:"previous",STACK:"stack",WORKSPACE:"workspace"};Blockly.Cursor.prototype.getCurNode=function(){return this.curNode_};Blockly.Cursor.prototype.setLocation=function(a){this.curNode_=a;this.update_()};Blockly.Cursor.prototype.update_=function(){};Blockly.Cursor.prototype.hide=function(){};
|
||||
Blockly.utils.dom.getTextWidth=function(a){var b=a.textContent+"\n"+a.className.baseVal,c;if(Blockly.utils.dom.cacheWidths_&&(c=Blockly.utils.dom.cacheWidths_[b]))return c;try{c=Blockly.utils.userAgent.IE||Blockly.utils.userAgent.EDGE?a.getBBox().width:a.getComputedTextLength()}catch(d){return 8*a.textContent.length}Blockly.utils.dom.cacheWidths_&&(Blockly.utils.dom.cacheWidths_[b]=c);return c};Blockly.utils.math={};Blockly.utils.math.toRadians=function(a){return a*Math.PI/180};Blockly.utils.math.toDegrees=function(a){return 180*a/Math.PI};Blockly.utils.math.clamp=function(a,b,c){if(c<a){var d=c;c=a;a=d}return Math.max(a,Math.min(b,c))};Blockly.Cursor=function(){this.drawer_=this.curNode_=null};Blockly.Cursor.prototype.setDrawer=function(a){this.drawer_=a};Blockly.Cursor.prototype.getDrawer=function(){return this.drawer_};Blockly.Cursor.prototype.getCurNode=function(){return this.curNode_};Blockly.Cursor.prototype.setLocation=function(a){this.curNode_=a;this.drawer_&&this.drawer_.draw(this.getCurNode())};Blockly.Cursor.prototype.hide=function(){this.drawer_&&this.drawer_.hide()};
|
||||
Blockly.Cursor.prototype.next=function(){var a=this.getCurNode();if(!a)return null;(a=a.next())&&a.getType()===Blockly.ASTNode.types.NEXT&&(a=a.next()||a);a&&this.setLocation(a);return a};Blockly.Cursor.prototype["in"]=function(){var a=this.getCurNode();if(!a)return null;(a=a["in"]())&&a.getType()===Blockly.ASTNode.types.OUTPUT&&(a=a.next()||a);a&&this.setLocation(a);return a};
|
||||
Blockly.Cursor.prototype.prev=function(){var a=this.getCurNode();if(!a)return null;(a=a.prev())&&a.getType()===Blockly.ASTNode.types.NEXT&&(a=a.prev()||a);a&&this.setLocation(a);return a};Blockly.Cursor.prototype.out=function(){var a=this.getCurNode();if(!a)return null;(a=a.out())&&this.setLocation(a);return a};Blockly.Events={};Blockly.Events.group_="";Blockly.Events.recordUndo=!0;Blockly.Events.disabled_=0;Blockly.Events.CREATE="create";Blockly.Events.BLOCK_CREATE=Blockly.Events.CREATE;Blockly.Events.DELETE="delete";Blockly.Events.BLOCK_DELETE=Blockly.Events.DELETE;Blockly.Events.CHANGE="change";Blockly.Events.BLOCK_CHANGE=Blockly.Events.CHANGE;Blockly.Events.MOVE="move";Blockly.Events.BLOCK_MOVE=Blockly.Events.MOVE;Blockly.Events.VAR_CREATE="var_create";Blockly.Events.VAR_DELETE="var_delete";
|
||||
Blockly.Cursor.prototype.prev=function(){var a=this.getCurNode();if(!a)return null;(a=a.prev())&&a.getType()===Blockly.ASTNode.types.NEXT&&(a=a.prev()||a);a&&this.setLocation(a);return a};Blockly.Cursor.prototype.out=function(){var a=this.getCurNode();if(!a)return null;(a=a.out())&&this.setLocation(a);return a};Blockly.utils.object={};Blockly.utils.object.inherits=function(a,b){a.superClass_=b.prototype;a.prototype=Object.create(b.prototype);a.prototype.constructor=a};Blockly.utils.object.mixin=function(a,b){for(var c in b)a[c]=b[c]};Blockly.utils.object.values=function(a){return Object.values?Object.values(a):Object.keys(a).map(function(b){return a[b]})};Blockly.MarkerCursor=function(){Blockly.MarkerCursor.superClass_.constructor.call(this)};Blockly.utils.object.inherits(Blockly.MarkerCursor,Blockly.Cursor);Blockly.MarkerCursor.prototype.next=function(){return null};Blockly.MarkerCursor.prototype["in"]=function(){return null};Blockly.MarkerCursor.prototype.prev=function(){return null};Blockly.MarkerCursor.prototype.out=function(){return null};Blockly.Events={};Blockly.Events.group_="";Blockly.Events.recordUndo=!0;Blockly.Events.disabled_=0;Blockly.Events.CREATE="create";Blockly.Events.BLOCK_CREATE=Blockly.Events.CREATE;Blockly.Events.DELETE="delete";Blockly.Events.BLOCK_DELETE=Blockly.Events.DELETE;Blockly.Events.CHANGE="change";Blockly.Events.BLOCK_CHANGE=Blockly.Events.CHANGE;Blockly.Events.MOVE="move";Blockly.Events.BLOCK_MOVE=Blockly.Events.MOVE;Blockly.Events.VAR_CREATE="var_create";Blockly.Events.VAR_DELETE="var_delete";
|
||||
Blockly.Events.VAR_RENAME="var_rename";Blockly.Events.UI="ui";Blockly.Events.COMMENT_CREATE="comment_create";Blockly.Events.COMMENT_DELETE="comment_delete";Blockly.Events.COMMENT_CHANGE="comment_change";Blockly.Events.COMMENT_MOVE="comment_move";Blockly.Events.FINISHED_LOADING="finished_loading";Blockly.Events.BUMP_EVENTS=[Blockly.Events.BLOCK_CREATE,Blockly.Events.BLOCK_MOVE,Blockly.Events.COMMENT_CREATE,Blockly.Events.COMMENT_MOVE];Blockly.Events.FIRE_QUEUE_=[];
|
||||
Blockly.Events.fire=function(a){Blockly.Events.isEnabled()&&(Blockly.Events.FIRE_QUEUE_.length||setTimeout(Blockly.Events.fireNow_,0),Blockly.Events.FIRE_QUEUE_.push(a))};Blockly.Events.fireNow_=function(){for(var a=Blockly.Events.filter(Blockly.Events.FIRE_QUEUE_,!0),b=Blockly.Events.FIRE_QUEUE_.length=0,c;c=a[b];b++){var d=Blockly.Workspace.getById(c.workspaceId);d&&d.fireChangeListener(c)}};
|
||||
Blockly.Events.filter=function(a,b){var c=a.slice();b||c.reverse();for(var d=[],e=Object.create(null),f=0,g;g=c[f];f++)if(!g.isNull()){var h=[g.type,g.blockId,g.workspaceId].join(" "),k=e[h],l=k?k.event:null;if(!k)e[h]={event:g,index:f},d.push(g);else if(g.type==Blockly.Events.MOVE&&k.index==f-1)l.newParentId=g.newParentId,l.newInputName=g.newInputName,l.newCoordinate=g.newCoordinate,k.index=f;else if(g.type==Blockly.Events.CHANGE&&g.element==l.element&&g.name==l.name)l.newValue=g.newValue;else if(g.type!=
|
||||
@@ -58,7 +58,7 @@ return c};Blockly.Events.disableOrphans=function(a){if(a.type==Blockly.Events.MO
|
||||
Blockly.Theme=function(a,b){this.blockStyles_=a;this.categoryStyles_=b};Blockly.Theme.prototype.setAllBlockStyles=function(a){for(var b in a)this.setBlockStyle(b,a[b])};Blockly.Theme.prototype.getAllBlockStyles=function(){return this.blockStyles_};Blockly.Theme.prototype.getBlockStyle=function(a){return this.blockStyles_[a]};Blockly.Theme.prototype.setBlockStyle=function(a,b){this.blockStyles_[a]=b};Blockly.Theme.prototype.getCategoryStyle=function(a){return this.categoryStyles_[a]};
|
||||
Blockly.Theme.prototype.setCategoryStyle=function(a,b){this.categoryStyles_[a]=b};Blockly.Themes={};Blockly.Themes.Classic={};Blockly.Themes.Classic.defaultBlockStyles={colour_blocks:{colourPrimary:"20"},list_blocks:{colourPrimary:"260"},logic_blocks:{colourPrimary:"210"},loop_blocks:{colourPrimary:"120"},math_blocks:{colourPrimary:"230"},procedure_blocks:{colourPrimary:"290"},text_blocks:{colourPrimary:"160"},variable_blocks:{colourPrimary:"330"},variable_dynamic_blocks:{colourPrimary:"310"},hat_blocks:{colourPrimary:"330",hat:"cap"}};
|
||||
Blockly.Themes.Classic.categoryStyles={colour_category:{colour:"20"},list_category:{colour:"260"},logic_category:{colour:"210"},loop_category:{colour:"120"},math_category:{colour:"230"},procedure_category:{colour:"290"},text_category:{colour:"160"},variable_category:{colour:"330"},variable_dynamic_category:{colour:"310"}};Blockly.Themes.Classic=new Blockly.Theme(Blockly.Themes.Classic.defaultBlockStyles,Blockly.Themes.Classic.categoryStyles);Blockly.Events.Abstract=function(){this.workspaceId=void 0;this.group=Blockly.Events.group_;this.recordUndo=Blockly.Events.recordUndo};Blockly.Events.Abstract.prototype.toJson=function(){var a={type:this.type};this.group&&(a.group=this.group);return a};Blockly.Events.Abstract.prototype.fromJson=function(a){this.group=a.group};Blockly.Events.Abstract.prototype.isNull=function(){return!1};Blockly.Events.Abstract.prototype.run=function(a){};
|
||||
Blockly.Events.Abstract.prototype.getEventWorkspace_=function(){var a=Blockly.Workspace.getById(this.workspaceId);if(!a)throw Error("Workspace is null. Event must have been generated from real Blockly events.");return a};Blockly.utils.object={};Blockly.utils.object.inherits=function(a,b){a.superClass_=b.prototype;a.prototype=Object.create(b.prototype);a.prototype.constructor=a};Blockly.utils.object.mixin=function(a,b){for(var c in b)a[c]=b[c]};Blockly.utils.object.values=function(a){return Object.values?Object.values(a):Object.keys(a).map(function(b){return a[b]})};Blockly.Events.VarBase=function(a){Blockly.Events.VarBase.superClass_.constructor.call(this);this.varId=a.getId();this.workspaceId=a.workspace.id};Blockly.utils.object.inherits(Blockly.Events.VarBase,Blockly.Events.Abstract);Blockly.Events.VarBase.prototype.toJson=function(){var a=Blockly.Events.VarBase.superClass_.toJson.call(this);a.varId=this.varId;return a};Blockly.Events.VarBase.prototype.fromJson=function(a){Blockly.Events.VarBase.superClass_.toJson.call(this);this.varId=a.varId};
|
||||
Blockly.Events.Abstract.prototype.getEventWorkspace_=function(){var a=Blockly.Workspace.getById(this.workspaceId);if(!a)throw Error("Workspace is null. Event must have been generated from real Blockly events.");return a};Blockly.Events.VarBase=function(a){Blockly.Events.VarBase.superClass_.constructor.call(this);this.varId=a.getId();this.workspaceId=a.workspace.id};Blockly.utils.object.inherits(Blockly.Events.VarBase,Blockly.Events.Abstract);Blockly.Events.VarBase.prototype.toJson=function(){var a=Blockly.Events.VarBase.superClass_.toJson.call(this);a.varId=this.varId;return a};Blockly.Events.VarBase.prototype.fromJson=function(a){Blockly.Events.VarBase.superClass_.toJson.call(this);this.varId=a.varId};
|
||||
Blockly.Events.VarCreate=function(a){a&&(Blockly.Events.VarCreate.superClass_.constructor.call(this,a),this.varType=a.type,this.varName=a.name)};Blockly.utils.object.inherits(Blockly.Events.VarCreate,Blockly.Events.VarBase);Blockly.Events.VarCreate.prototype.type=Blockly.Events.VAR_CREATE;Blockly.Events.VarCreate.prototype.toJson=function(){var a=Blockly.Events.VarCreate.superClass_.toJson.call(this);a.varType=this.varType;a.varName=this.varName;return a};
|
||||
Blockly.Events.VarCreate.prototype.fromJson=function(a){Blockly.Events.VarCreate.superClass_.fromJson.call(this,a);this.varType=a.varType;this.varName=a.varName};Blockly.Events.VarCreate.prototype.run=function(a){var b=this.getEventWorkspace_();a?b.createVariable(this.varName,this.varType,this.varId):b.deleteVariableById(this.varId)};Blockly.Events.VarDelete=function(a){a&&(Blockly.Events.VarDelete.superClass_.constructor.call(this,a),this.varType=a.type,this.varName=a.name)};
|
||||
Blockly.utils.object.inherits(Blockly.Events.VarDelete,Blockly.Events.VarBase);Blockly.Events.VarDelete.prototype.type=Blockly.Events.VAR_DELETE;Blockly.Events.VarDelete.prototype.toJson=function(){var a=Blockly.Events.VarDelete.superClass_.toJson.call(this);a.varType=this.varType;a.varName=this.varName;return a};Blockly.Events.VarDelete.prototype.fromJson=function(a){Blockly.Events.VarDelete.superClass_.fromJson.call(this,a);this.varType=a.varType;this.varName=a.varName};
|
||||
@@ -132,10 +132,11 @@ Blockly.WorkspaceComment.prototype.setContent=function(a){this.content_!=a&&(Blo
|
||||
Blockly.WorkspaceComment.prototype.toXml=function(a){var b=Blockly.utils.xml.createElement("comment");a||(b.id=this.id);b.textContent=this.getContent();return b};Blockly.WorkspaceComment.fireCreateEvent=function(a){if(Blockly.Events.isEnabled()){var b=Blockly.Events.getGroup();b||Blockly.Events.setGroup(!0);try{Blockly.Events.fire(new Blockly.Events.CommentCreate(a))}finally{b||Blockly.Events.setGroup(!1)}}};
|
||||
Blockly.WorkspaceComment.fromXml=function(a,b){var c=Blockly.WorkspaceComment.parseAttributes(a);c=new Blockly.WorkspaceComment(b,c.content,c.h,c.w,c.id);var d=parseInt(a.getAttribute("x"),10),e=parseInt(a.getAttribute("y"),10);isNaN(d)||isNaN(e)||c.moveBy(d,e);Blockly.WorkspaceComment.fireCreateEvent(c);return c};
|
||||
Blockly.WorkspaceComment.parseAttributes=function(a){var b=a.getAttribute("h"),c=a.getAttribute("w");return{id:a.getAttribute("id"),h:b?parseInt(b,10):100,w:c?parseInt(c,10):100,x:parseInt(a.getAttribute("x"),10),y:parseInt(a.getAttribute("y"),10),content:a.textContent}};Blockly.Workspace=function(a){this.id=Blockly.utils.genUid();Blockly.Workspace.WorkspaceDB_[this.id]=this;this.options=a||{};this.RTL=!!this.options.RTL;this.horizontalLayout=!!this.options.horizontalLayout;this.toolboxPosition=this.options.toolboxPosition;this.topBlocks_=[];this.topComments_=[];this.commentDB_=Object.create(null);this.listeners_=[];this.undoStack_=[];this.redoStack_=[];this.blockDB_=Object.create(null);this.typedBlocksDB_=Object.create(null);this.variableMap_=new Blockly.VariableMap(this);
|
||||
this.potentialVariableMap_=null;this.cursor=this.createCursor();this.marker=this.createMarker();Blockly.getTheme()||Blockly.setTheme(Blockly.Themes.Classic)};Blockly.Workspace.prototype.rendered=!1;Blockly.Workspace.prototype.isClearing=!1;Blockly.Workspace.prototype.MAX_UNDO=1024;Blockly.Workspace.prototype.connectionDBList=null;Blockly.Workspace.prototype.createCursor=function(){return new Blockly.Cursor};Blockly.Workspace.prototype.createMarker=function(){return new Blockly.Cursor(!0)};
|
||||
Blockly.Workspace.prototype.dispose=function(){this.listeners_.length=0;this.clear();delete Blockly.Workspace.WorkspaceDB_[this.id]};Blockly.Workspace.SCAN_ANGLE=3;Blockly.Workspace.prototype.sortObjects_=function(a,b){var c=a.getRelativeToSurfaceXY(),d=b.getRelativeToSurfaceXY();return c.y+Blockly.Workspace.prototype.sortObjects_.offset*c.x-(d.y+Blockly.Workspace.prototype.sortObjects_.offset*d.x)};Blockly.Workspace.prototype.addTopBlock=function(a){this.topBlocks_.push(a)};
|
||||
Blockly.Workspace.prototype.removeTopBlock=function(a){if(!Blockly.utils.arrayRemove(this.topBlocks_,a))throw Error("Block not present in workspace's list of top-most blocks.");};Blockly.Workspace.prototype.getTopBlocks=function(a){var b=[].concat(this.topBlocks_);a&&1<b.length&&(this.sortObjects_.offset=Math.sin(Blockly.utils.math.toRadians(Blockly.Workspace.SCAN_ANGLE)),this.RTL&&(this.sortObjects_.offset*=-1),b.sort(this.sortObjects_));return b};
|
||||
Blockly.Workspace.prototype.addTypedBlock=function(a){this.typedBlocksDB_[a.type]||(this.typedBlocksDB_[a.type]=[]);this.typedBlocksDB_[a.type].push(a)};Blockly.Workspace.prototype.removeTypedBlock=function(a){this.typedBlocksDB_[a.type].splice(this.typedBlocksDB_[a.type].indexOf(a),1);this.typedBlocksDB_[a.type].length||delete this.typedBlocksDB_[a.type]};
|
||||
this.marker_=this.cursor_=this.potentialVariableMap_=null;Blockly.getTheme()||Blockly.setTheme(Blockly.Themes.Classic);this.setCursor(new Blockly.Cursor);this.setMarker(new Blockly.MarkerCursor)};Blockly.Workspace.prototype.rendered=!1;Blockly.Workspace.prototype.isClearing=!1;Blockly.Workspace.prototype.MAX_UNDO=1024;Blockly.Workspace.prototype.connectionDBList=null;Blockly.Workspace.prototype.setCursor=function(a){this.cursor_=a};Blockly.Workspace.prototype.setMarker=function(a){this.marker_=a};
|
||||
Blockly.Workspace.prototype.getCursor=function(){return this.cursor_};Blockly.Workspace.prototype.getMarker=function(){return this.marker_};Blockly.Workspace.prototype.dispose=function(){this.listeners_.length=0;this.clear();delete Blockly.Workspace.WorkspaceDB_[this.id]};Blockly.Workspace.SCAN_ANGLE=3;
|
||||
Blockly.Workspace.prototype.sortObjects_=function(a,b){var c=a.getRelativeToSurfaceXY(),d=b.getRelativeToSurfaceXY();return c.y+Blockly.Workspace.prototype.sortObjects_.offset*c.x-(d.y+Blockly.Workspace.prototype.sortObjects_.offset*d.x)};Blockly.Workspace.prototype.addTopBlock=function(a){this.topBlocks_.push(a)};Blockly.Workspace.prototype.removeTopBlock=function(a){if(!Blockly.utils.arrayRemove(this.topBlocks_,a))throw Error("Block not present in workspace's list of top-most blocks.");};
|
||||
Blockly.Workspace.prototype.getTopBlocks=function(a){var b=[].concat(this.topBlocks_);a&&1<b.length&&(this.sortObjects_.offset=Math.sin(Blockly.utils.math.toRadians(Blockly.Workspace.SCAN_ANGLE)),this.RTL&&(this.sortObjects_.offset*=-1),b.sort(this.sortObjects_));return b};Blockly.Workspace.prototype.addTypedBlock=function(a){this.typedBlocksDB_[a.type]||(this.typedBlocksDB_[a.type]=[]);this.typedBlocksDB_[a.type].push(a)};
|
||||
Blockly.Workspace.prototype.removeTypedBlock=function(a){this.typedBlocksDB_[a.type].splice(this.typedBlocksDB_[a.type].indexOf(a),1);this.typedBlocksDB_[a.type].length||delete this.typedBlocksDB_[a.type]};
|
||||
Blockly.Workspace.prototype.getBlocksByType=function(a,b){if(!this.typedBlocksDB_[a])return[];var c=this.typedBlocksDB_[a].slice(0);b&&1<c.length&&(this.sortObjects_.offset=Math.sin(Blockly.utils.math.toRadians(Blockly.Workspace.SCAN_ANGLE)),this.RTL&&(this.sortObjects_.offset*=-1),c.sort(this.sortObjects_));return c};
|
||||
Blockly.Workspace.prototype.addTopComment=function(a){this.topComments_.push(a);this.commentDB_[a.id]&&console.warn('Overriding an existing comment on this workspace, with id "'+a.id+'"');this.commentDB_[a.id]=a};Blockly.Workspace.prototype.removeTopComment=function(a){if(!Blockly.utils.arrayRemove(this.topComments_,a))throw Error("Comment not present in workspace's list of top-most comments.");delete this.commentDB_[a.id]};
|
||||
Blockly.Workspace.prototype.getTopComments=function(a){var b=[].concat(this.topComments_);a&&1<b.length&&(this.sortObjects_.offset=Math.sin(Blockly.utils.math.toRadians(Blockly.Workspace.SCAN_ANGLE)),this.RTL&&(this.sortObjects_.offset*=-1),b.sort(this.sortObjects_));return b};
|
||||
@@ -400,25 +401,23 @@ Blockly.ConnectionDB.prototype.searchForClosest=function(a,b,c){if(!this.connect
|
||||
d;return{connection:c,radius:g}};Blockly.ConnectionDB.init=function(){var a=[];a[Blockly.INPUT_VALUE]=new Blockly.ConnectionDB;a[Blockly.OUTPUT_VALUE]=new Blockly.ConnectionDB;a[Blockly.NEXT_STATEMENT]=new Blockly.ConnectionDB;a[Blockly.PREVIOUS_STATEMENT]=new Blockly.ConnectionDB;return a};Blockly.constants={};Blockly.LINE_MODE_MULTIPLIER=40;Blockly.PAGE_MODE_MULTIPLIER=125;Blockly.DRAG_RADIUS=5;Blockly.FLYOUT_DRAG_RADIUS=10;Blockly.SNAP_RADIUS=28;Blockly.CONNECTING_SNAP_RADIUS=Blockly.SNAP_RADIUS;Blockly.CURRENT_CONNECTION_PREFERENCE=8;Blockly.INSERTION_MARKER_COLOUR="#000000";Blockly.BUMP_DELAY=250;Blockly.BUMP_RANDOMNESS=10;Blockly.COLLAPSE_CHARS=30;Blockly.LONGPRESS=750;Blockly.SOUND_LIMIT=100;Blockly.DRAG_STACK=!0;Blockly.HSV_SATURATION=.45;Blockly.HSV_VALUE=.65;
|
||||
Blockly.SPRITE={width:96,height:124,url:"sprites.png"};Blockly.INPUT_VALUE=1;Blockly.OUTPUT_VALUE=2;Blockly.NEXT_STATEMENT=3;Blockly.PREVIOUS_STATEMENT=4;Blockly.DUMMY_INPUT=5;Blockly.ALIGN_LEFT=-1;Blockly.ALIGN_CENTRE=0;Blockly.ALIGN_RIGHT=1;Blockly.DRAG_NONE=0;Blockly.DRAG_STICKY=1;Blockly.DRAG_BEGIN=1;Blockly.DRAG_FREE=2;Blockly.OPPOSITE_TYPE=[];Blockly.OPPOSITE_TYPE[Blockly.INPUT_VALUE]=Blockly.OUTPUT_VALUE;Blockly.OPPOSITE_TYPE[Blockly.OUTPUT_VALUE]=Blockly.INPUT_VALUE;
|
||||
Blockly.OPPOSITE_TYPE[Blockly.NEXT_STATEMENT]=Blockly.PREVIOUS_STATEMENT;Blockly.OPPOSITE_TYPE[Blockly.PREVIOUS_STATEMENT]=Blockly.NEXT_STATEMENT;Blockly.TOOLBOX_AT_TOP=0;Blockly.TOOLBOX_AT_BOTTOM=1;Blockly.TOOLBOX_AT_LEFT=2;Blockly.TOOLBOX_AT_RIGHT=3;Blockly.DELETE_AREA_NONE=null;Blockly.DELETE_AREA_TRASH=1;Blockly.DELETE_AREA_TOOLBOX=2;Blockly.VARIABLE_CATEGORY_NAME="VARIABLE";Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME="VARIABLE_DYNAMIC";Blockly.PROCEDURE_CATEGORY_NAME="PROCEDURE";
|
||||
Blockly.RENAME_VARIABLE_ID="RENAME_VARIABLE_ID";Blockly.DELETE_VARIABLE_ID="DELETE_VARIABLE_ID";Blockly.CursorSvg=function(a,b){Blockly.CursorSvg.superClass_.constructor.call(this,b);this.workspace_=a;this.constants=new Blockly.blockRendering.ConstantProvider;this.constants.init()};Blockly.utils.object.inherits(Blockly.CursorSvg,Blockly.Cursor);Blockly.CursorSvg.CURSOR_HEIGHT=5;Blockly.CursorSvg.CURSOR_WIDTH=100;Blockly.CursorSvg.NOTCH_START_LENGTH=24;Blockly.CursorSvg.VERTICAL_PADDING=5;Blockly.CursorSvg.STACK_PADDING=10;Blockly.CursorSvg.CURSOR_COLOR="#cc0a0a";
|
||||
Blockly.CursorSvg.MARKER_COLOR="#4286f4";Blockly.CursorSvg.CURSOR_CLASS="blocklyCursor";Blockly.CursorSvg.MARKER_CLASS="blocklyMarker";Blockly.CursorSvg.prototype.parent_=null;Blockly.CursorSvg.prototype.currentCursorSvg=null;Blockly.CursorSvg.prototype.getSvgRoot=function(){return this.svgGroup_};
|
||||
Blockly.CursorSvg.prototype.createDom=function(){this.svgGroup_=Blockly.utils.dom.createSvgElement("g",{"class":this.isMarker_?Blockly.CursorSvg.MARKER_CLASS:Blockly.CursorSvg.CURSOR_CLASS},null);this.createCursorSvg_();return this.svgGroup_};
|
||||
Blockly.RENAME_VARIABLE_ID="RENAME_VARIABLE_ID";Blockly.DELETE_VARIABLE_ID="DELETE_VARIABLE_ID";Blockly.CursorSvg=function(a,b){this.workspace_=a;this.isMarker_=b;this.constants_=new Blockly.blockRendering.ConstantProvider;this.constants_.init()};Blockly.CursorSvg.CURSOR_HEIGHT=5;Blockly.CursorSvg.CURSOR_WIDTH=100;Blockly.CursorSvg.NOTCH_START_LENGTH=24;Blockly.CursorSvg.VERTICAL_PADDING=5;Blockly.CursorSvg.STACK_PADDING=10;Blockly.CursorSvg.CURSOR_COLOR="#cc0a0a";Blockly.CursorSvg.MARKER_COLOR="#4286f4";Blockly.CursorSvg.CURSOR_CLASS="blocklyCursor";Blockly.CursorSvg.MARKER_CLASS="blocklyMarker";
|
||||
Blockly.CursorSvg.prototype.parent_=null;Blockly.CursorSvg.prototype.currentCursorSvg=null;Blockly.CursorSvg.prototype.getSvgRoot=function(){return this.svgGroup_};Blockly.CursorSvg.prototype.createDom=function(){this.svgGroup_=Blockly.utils.dom.createSvgElement("g",{"class":this.isMarker_?Blockly.CursorSvg.MARKER_CLASS:Blockly.CursorSvg.CURSOR_CLASS},null);this.createCursorSvg_();return this.svgGroup_};
|
||||
Blockly.CursorSvg.prototype.setParent_=function(a){if(a!=this.parent_){var b=this.getSvgRoot(),c=null;if(a){if(this.isMarker_){for(var d=0,e;e=a.childNodes[d];d++)Blockly.utils.dom.hasClass(e,Blockly.CursorSvg.CURSOR_CLASS)&&(c=e);a.insertBefore(b,c)}else a.appendChild(b);this.parent_=a}}};
|
||||
Blockly.CursorSvg.prototype.showWithCoordinates_=function(){var a=this.getCurNode().getWsCoordinate();this.currentCursorSvg=this.cursorSvgLine_;this.setParent_(this.workspace_.svgBlockCanvas_);this.positionLine_(a.x,a.y,Blockly.CursorSvg.CURSOR_WIDTH);this.showCurrent_()};Blockly.CursorSvg.prototype.showWithBlock_=function(){var a=this.getCurNode().getLocation();this.currentCursorSvg=this.cursorSvgRect_;this.setParent_(a.getSvgRoot());this.positionRect_(0,0,a.width,a.height);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithInputOutput_=function(){var a=this.getCurNode().getLocation();this.currentCursorSvg=this.cursorInputOutput_;var b=Blockly.utils.svgPaths.moveTo(0,0)+this.constants.shapeFor(a).pathDown;this.cursorInputOutput_.setAttribute("d",b);this.setParent_(a.getSourceBlock().getSvgRoot());this.positionInputOutput_(a);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithNext_=function(){var a=this.getCurNode().getLocation(),b=a.getSourceBlock(),c=a.getOffsetInBlock().y;b=b.getHeightWidth().width;this.currentCursorSvg=this.cursorSvgLine_;this.setParent_(a.getSourceBlock().getSvgRoot());this.positionLine_(0,c,b);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithPrev_=function(){var a=this.getCurNode().getLocation(),b=a.getSourceBlock().getHeightWidth().width;this.currentCursorSvg=this.cursorSvgLine_;this.setParent_(a.getSourceBlock().getSvgRoot());this.positionLine_(0,0,b);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithField_=function(){var a=this.getCurNode().getLocation(),b=a.borderRect_.width.baseVal.value,c=a.borderRect_.height.baseVal.value;this.currentCursorSvg=this.cursorSvgRect_;this.setParent_(a.getSvgRoot());this.positionRect_(0,0,b,c);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithStack_=function(){var a=this.getCurNode().getLocation(),b=a.getHeightWidth(),c=b.width+Blockly.CursorSvg.STACK_PADDING;b=b.height+Blockly.CursorSvg.STACK_PADDING;var d=-1*Blockly.CursorSvg.STACK_PADDING/2,e=-1*Blockly.CursorSvg.STACK_PADDING/2;this.currentCursorSvg=this.cursorSvgRect_;this.setParent_(a.getSvgRoot());this.positionRect_(d,e,c,b);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithCoordinates_=function(a){a=a.getWsCoordinate();this.currentCursorSvg=this.cursorSvgLine_;this.setParent_(this.workspace_.svgBlockCanvas_);this.positionLine_(a.x,a.y,Blockly.CursorSvg.CURSOR_WIDTH);this.showCurrent_()};Blockly.CursorSvg.prototype.showWithBlock_=function(a){a=a.getLocation();this.currentCursorSvg=this.cursorSvgRect_;this.setParent_(a.getSvgRoot());this.positionRect_(0,0,a.width,a.height);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithInputOutput_=function(a){a=a.getLocation();this.currentCursorSvg=this.cursorInputOutput_;var b=Blockly.utils.svgPaths.moveTo(0,0)+this.constants_.shapeFor(a).pathDown;this.cursorInputOutput_.setAttribute("d",b);this.setParent_(a.getSourceBlock().getSvgRoot());this.positionInputOutput_(a);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithNext_=function(a){a=a.getLocation();var b=a.getSourceBlock(),c=a.getOffsetInBlock().y;b=b.getHeightWidth().width;this.currentCursorSvg=this.cursorSvgLine_;this.setParent_(a.getSourceBlock().getSvgRoot());this.positionLine_(0,c,b);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithPrev_=function(a){a=a.getLocation();var b=a.getSourceBlock().getHeightWidth().width;this.currentCursorSvg=this.cursorSvgLine_;this.setParent_(a.getSourceBlock().getSvgRoot());this.positionLine_(0,0,b);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithField_=function(a){a=a.getLocation();var b=a.borderRect_.width.baseVal.value,c=a.borderRect_.height.baseVal.value;this.currentCursorSvg=this.cursorSvgRect_;this.setParent_(a.getSvgRoot());this.positionRect_(0,0,b,c);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.showWithStack_=function(a){a=a.getLocation();var b=a.getHeightWidth(),c=b.width+Blockly.CursorSvg.STACK_PADDING;b=b.height+Blockly.CursorSvg.STACK_PADDING;var d=-1*Blockly.CursorSvg.STACK_PADDING/2,e=-1*Blockly.CursorSvg.STACK_PADDING/2;this.currentCursorSvg=this.cursorSvgRect_;this.setParent_(a.getSvgRoot());this.positionRect_(d,e,c,b);this.showCurrent_()};
|
||||
Blockly.CursorSvg.prototype.positionLine_=function(a,b,c){this.cursorSvgLine_.setAttribute("x",a);this.cursorSvgLine_.setAttribute("y",b);this.cursorSvgLine_.setAttribute("width",c)};Blockly.CursorSvg.prototype.positionRect_=function(a,b,c,d){this.cursorSvgRect_.setAttribute("x",a);this.cursorSvgRect_.setAttribute("y",b);this.cursorSvgRect_.setAttribute("width",c);this.cursorSvgRect_.setAttribute("height",d)};
|
||||
Blockly.CursorSvg.prototype.positionInputOutput_=function(a){var b=a.getOffsetInBlock().x,c=a.getOffsetInBlock().y;this.cursorInputOutput_.setAttribute("transform","translate("+b+","+c+")"+(a.getSourceBlock().RTL?" scale(-1 1)":""))};Blockly.CursorSvg.prototype.showCurrent_=function(){this.hide();this.currentCursorSvg.style.display=""};
|
||||
Blockly.CursorSvg.prototype.hide=function(){this.cursorSvgLine_.style.display="none";this.cursorSvgRect_.style.display="none";this.cursorInputOutput_.style.display="none"};
|
||||
Blockly.CursorSvg.prototype.update_=function(){if(this.getCurNode()){var a=this.getCurNode();a.getType()===Blockly.ASTNode.types.BLOCK?this.showWithBlock_():a.getLocation().type===Blockly.INPUT_VALUE||a.getType()===Blockly.ASTNode.types.OUTPUT?this.showWithInputOutput_():a.getLocation().type===Blockly.NEXT_STATEMENT?this.showWithNext_():a.getType()===Blockly.ASTNode.types.PREVIOUS?this.showWithPrev_():a.getType()===Blockly.ASTNode.types.FIELD?this.showWithField_():a.getType()===Blockly.ASTNode.types.WORKSPACE?
|
||||
this.showWithCoordinates_():a.getType()===Blockly.ASTNode.types.STACK&&this.showWithStack_()}};
|
||||
Blockly.CursorSvg.prototype.draw=function(a){a&&(a.getType()===Blockly.ASTNode.types.BLOCK?this.showWithBlock_(a):a.getLocation().type===Blockly.INPUT_VALUE||a.getType()===Blockly.ASTNode.types.OUTPUT?this.showWithInputOutput_(a):a.getLocation().type===Blockly.NEXT_STATEMENT?this.showWithNext_(a):a.getType()===Blockly.ASTNode.types.PREVIOUS?this.showWithPrev_(a):a.getType()===Blockly.ASTNode.types.FIELD?this.showWithField_(a):a.getType()===Blockly.ASTNode.types.WORKSPACE?this.showWithCoordinates_(a):
|
||||
a.getType()===Blockly.ASTNode.types.STACK&&this.showWithStack_(a))};
|
||||
Blockly.CursorSvg.prototype.createCursorSvg_=function(){var a=this.isMarker_?Blockly.CursorSvg.MARKER_COLOR:Blockly.CursorSvg.CURSOR_COLOR;this.cursorSvg_=Blockly.utils.dom.createSvgElement("g",{width:Blockly.CursorSvg.CURSOR_WIDTH,height:Blockly.CursorSvg.CURSOR_HEIGHT},this.svgGroup_);this.cursorSvgLine_=Blockly.utils.dom.createSvgElement("rect",{x:"0",y:"0",fill:a,width:Blockly.CursorSvg.CURSOR_WIDTH,height:Blockly.CursorSvg.CURSOR_HEIGHT,style:"display: none;"},this.cursorSvg_);this.cursorSvgRect_=
|
||||
Blockly.utils.dom.createSvgElement("rect",{"class":"blocklyVerticalCursor",x:"0",y:"0",rx:"10",ry:"10",style:"display: none;",stroke:a},this.cursorSvg_);this.cursorInputOutput_=Blockly.utils.dom.createSvgElement("path",{width:Blockly.CursorSvg.CURSOR_WIDTH,height:Blockly.CursorSvg.CURSOR_HEIGHT,transform:"",style:"display: none;",fill:a},this.cursorSvg_);this.isMarker_||(Blockly.utils.dom.createSvgElement("animate",{attributeType:"XML",attributeName:"fill",dur:"1s",values:Blockly.CursorSvg.CURSOR_COLOR+
|
||||
";transparent;transparent;",repeatCount:"indefinite"},this.cursorSvgLine_),Blockly.utils.dom.createSvgElement("animate",{attributeType:"XML",attributeName:"fill",dur:"1s",values:Blockly.CursorSvg.CURSOR_COLOR+";transparent;transparent;",repeatCount:"indefinite"},this.cursorInputOutput_));return this.cursorSvg_};Blockly.CursorSvg.prototype.next=function(){return this.isMarker_?null:Blockly.CursorSvg.superClass_.next.call(this)};
|
||||
Blockly.CursorSvg.prototype["in"]=function(){return this.isMarker_?null:Blockly.CursorSvg.superClass_["in"].call(this)};Blockly.CursorSvg.prototype.prev=function(){return this.isMarker_?null:Blockly.CursorSvg.superClass_.prev.call(this)};Blockly.CursorSvg.prototype.out=function(){return this.isMarker_?null:Blockly.CursorSvg.superClass_.out.call(this)};Blockly.CursorSvg.prototype.dispose=function(){this.svgGroup_&&Blockly.utils.dom.removeNode(this.svgGroup_)};Blockly.blockAnimations={};Blockly.blockAnimations.disconnectPid_=0;Blockly.blockAnimations.disconnectGroup_=null;Blockly.blockAnimations.disposeUiEffect=function(a){var b=a.workspace,c=a.getSvgRoot();b.getAudioManager().play("delete");a=b.getSvgXY(c);c=c.cloneNode(!0);c.translateX_=a.x;c.translateY_=a.y;c.setAttribute("transform","translate("+a.x+","+a.y+")");b.getParentSvg().appendChild(c);c.bBox_=c.getBBox();Blockly.blockAnimations.disposeUiStep_(c,b.RTL,new Date,b.scale)};
|
||||
";transparent;transparent;",repeatCount:"indefinite"},this.cursorSvgLine_),Blockly.utils.dom.createSvgElement("animate",{attributeType:"XML",attributeName:"fill",dur:"1s",values:Blockly.CursorSvg.CURSOR_COLOR+";transparent;transparent;",repeatCount:"indefinite"},this.cursorInputOutput_));return this.cursorSvg_};Blockly.CursorSvg.prototype.dispose=function(){this.svgGroup_&&Blockly.utils.dom.removeNode(this.svgGroup_)};Blockly.blockAnimations={};Blockly.blockAnimations.disconnectPid_=0;Blockly.blockAnimations.disconnectGroup_=null;Blockly.blockAnimations.disposeUiEffect=function(a){var b=a.workspace,c=a.getSvgRoot();b.getAudioManager().play("delete");a=b.getSvgXY(c);c=c.cloneNode(!0);c.translateX_=a.x;c.translateY_=a.y;c.setAttribute("transform","translate("+a.x+","+a.y+")");b.getParentSvg().appendChild(c);c.bBox_=c.getBBox();Blockly.blockAnimations.disposeUiStep_(c,b.RTL,new Date,b.scale)};
|
||||
Blockly.blockAnimations.disposeUiStep_=function(a,b,c,d){var e=(new Date-c)/150;1<e?Blockly.utils.dom.removeNode(a):(a.setAttribute("transform","translate("+(a.translateX_+(b?-1:1)*a.bBox_.width*d/2*e)+","+(a.translateY_+a.bBox_.height*d*e)+") scale("+(1-e)*d+")"),setTimeout(Blockly.blockAnimations.disposeUiStep_,10,a,b,c,d))};
|
||||
Blockly.blockAnimations.connectionUiEffect=function(a){var b=a.workspace,c=b.scale;b.getAudioManager().play("click");if(!(1>c)){var d=b.getSvgXY(a.getSvgRoot());a.outputConnection?(d.x+=(a.RTL?3:-3)*c,d.y+=13*c):a.previousConnection&&(d.x+=(a.RTL?-23:23)*c,d.y+=3*c);a=Blockly.utils.dom.createSvgElement("circle",{cx:d.x,cy:d.y,r:0,fill:"none",stroke:"#888","stroke-width":10},b.getParentSvg());Blockly.blockAnimations.connectionUiStep_(a,new Date,c)}};
|
||||
Blockly.blockAnimations.connectionUiStep_=function(a,b,c){var d=(new Date-b)/150;1<d?Blockly.utils.dom.removeNode(a):(a.setAttribute("r",25*d*c),a.style.opacity=1-d,Blockly.blockAnimations.disconnectPid_=setTimeout(Blockly.blockAnimations.connectionUiStep_,10,a,b,c))};
|
||||
@@ -509,7 +508,7 @@ Blockly.Gesture.prototype.handleWsStart=function(a,b){if(this.hasStarted_)throw
|
||||
Blockly.Gesture.prototype.handleBlockStart=function(a,b){if(this.hasStarted_)throw Error("Tried to call gesture.handleBlockStart, but the gesture had already been started.");this.setStartBlock(b);this.mostRecentEvent_=a};Blockly.Gesture.prototype.handleBubbleStart=function(a,b){if(this.hasStarted_)throw Error("Tried to call gesture.handleBubbleStart, but the gesture had already been started.");this.setStartBubble(b);this.mostRecentEvent_=a};
|
||||
Blockly.Gesture.prototype.doBubbleClick_=function(){this.startBubble_.setFocus&&this.startBubble_.setFocus();this.startBubble_.select&&this.startBubble_.select()};Blockly.Gesture.prototype.doFieldClick_=function(){this.startField_.showEditor_();this.bringBlockToFront_()};
|
||||
Blockly.Gesture.prototype.doBlockClick_=function(){this.flyout_&&this.flyout_.autoClose?this.targetBlock_.isEnabled()&&(Blockly.Events.getGroup()||Blockly.Events.setGroup(!0),this.flyout_.createBlock(this.targetBlock_).scheduleSnapAndBump()):Blockly.Events.fire(new Blockly.Events.Ui(this.startBlock_,"click",void 0,void 0));this.bringBlockToFront_();Blockly.Events.setGroup(!1)};
|
||||
Blockly.Gesture.prototype.doWorkspaceClick_=function(a){var b=this.creatorWorkspace_;a.shiftKey?(Blockly.navigation.enableKeyboardAccessibility(),a=new Blockly.utils.Coordinate(a.clientX,a.clientY),a=Blockly.utils.screenToWsCoordinates(b,a),a=Blockly.ASTNode.createWorkspaceNode(b,a),b.cursor.setLocation(a)):Blockly.selected&&Blockly.selected.unselect()};Blockly.Gesture.prototype.bringBlockToFront_=function(){this.targetBlock_&&!this.flyout_&&this.targetBlock_.bringToFront()};
|
||||
Blockly.Gesture.prototype.doWorkspaceClick_=function(a){var b=this.creatorWorkspace_;a.shiftKey?(Blockly.navigation.enableKeyboardAccessibility(),a=new Blockly.utils.Coordinate(a.clientX,a.clientY),a=Blockly.utils.screenToWsCoordinates(b,a),a=Blockly.ASTNode.createWorkspaceNode(b,a),b.getCursor().setLocation(a)):Blockly.selected&&Blockly.selected.unselect()};Blockly.Gesture.prototype.bringBlockToFront_=function(){this.targetBlock_&&!this.flyout_&&this.targetBlock_.bringToFront()};
|
||||
Blockly.Gesture.prototype.setStartField=function(a){if(this.hasStarted_)throw Error("Tried to call gesture.setStartField, but the gesture had already been started.");this.startField_||(this.startField_=a)};Blockly.Gesture.prototype.setStartBubble=function(a){this.startBubble_||(this.startBubble_=a)};Blockly.Gesture.prototype.setStartBlock=function(a){this.startBlock_||this.startBubble_||(this.startBlock_=a,a.isInFlyout&&a!=a.getRootBlock()?this.setTargetBlock_(a.getRootBlock()):this.setTargetBlock_(a))};
|
||||
Blockly.Gesture.prototype.setTargetBlock_=function(a){a.isShadow()?this.setTargetBlock_(a.getParent()):this.targetBlock_=a};Blockly.Gesture.prototype.setStartWorkspace_=function(a){this.startWorkspace_||(this.startWorkspace_=a)};Blockly.Gesture.prototype.setStartFlyout_=function(a){this.flyout_||(this.flyout_=a)};Blockly.Gesture.prototype.isBubbleClick_=function(){return!!this.startBubble_&&!this.hasExceededDragRadius_};
|
||||
Blockly.Gesture.prototype.isBlockClick_=function(){return!!this.startBlock_&&!this.hasExceededDragRadius_&&!this.isFieldClick_()};Blockly.Gesture.prototype.isFieldClick_=function(){return(this.startField_?this.startField_.isClickable():!1)&&!this.hasExceededDragRadius_&&(!this.flyout_||!this.flyout_.autoClose)};Blockly.Gesture.prototype.isWorkspaceClick_=function(){return!this.startBlock_&&!this.startBubble_&&!this.startField_&&!this.hasExceededDragRadius_};
|
||||
@@ -629,15 +628,16 @@ new Blockly.WorkspaceAudio(a.parentWorkspace);this.grid_=this.options.gridPatter
|
||||
this.registerToolboxCategoryCallback(Blockly.PROCEDURE_CATEGORY_NAME,Blockly.Procedures.flyoutCategory);Blockly.blockRendering.init()};Blockly.utils.object.inherits(Blockly.WorkspaceSvg,Blockly.Workspace);Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_=null;Blockly.WorkspaceSvg.prototype.rendered=!0;Blockly.WorkspaceSvg.prototype.isVisible_=!0;Blockly.WorkspaceSvg.prototype.isFlyout=!1;Blockly.WorkspaceSvg.prototype.isMutator=!1;Blockly.WorkspaceSvg.prototype.resizesEnabled_=!0;
|
||||
Blockly.WorkspaceSvg.prototype.scrollX=0;Blockly.WorkspaceSvg.prototype.scrollY=0;Blockly.WorkspaceSvg.prototype.startScrollX=0;Blockly.WorkspaceSvg.prototype.startScrollY=0;Blockly.WorkspaceSvg.prototype.dragDeltaXY_=null;Blockly.WorkspaceSvg.prototype.scale=1;Blockly.WorkspaceSvg.prototype.trashcan=null;Blockly.WorkspaceSvg.prototype.scrollbar=null;Blockly.WorkspaceSvg.prototype.flyout_=null;Blockly.WorkspaceSvg.prototype.toolbox_=null;Blockly.WorkspaceSvg.prototype.currentGesture_=null;
|
||||
Blockly.WorkspaceSvg.prototype.blockDragSurface_=null;Blockly.WorkspaceSvg.prototype.workspaceDragSurface_=null;Blockly.WorkspaceSvg.prototype.useWorkspaceDragSurface_=!1;Blockly.WorkspaceSvg.prototype.isDragSurfaceActive_=!1;Blockly.WorkspaceSvg.prototype.injectionDiv_=null;Blockly.WorkspaceSvg.prototype.lastRecordedPageScroll_=null;Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_={};Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_={};
|
||||
Blockly.WorkspaceSvg.prototype.configureContextMenu=null;Blockly.WorkspaceSvg.prototype.targetWorkspace=null;Blockly.WorkspaceSvg.prototype.inverseScreenCTM_=null;Blockly.WorkspaceSvg.prototype.inverseScreenCTMDirty_=!0;Blockly.WorkspaceSvg.prototype.createCursor=function(){return new Blockly.CursorSvg(this)};Blockly.WorkspaceSvg.prototype.createMarker=function(){return new Blockly.CursorSvg(this,!0)};
|
||||
Blockly.WorkspaceSvg.prototype.getInverseScreenCTM=function(){if(this.inverseScreenCTMDirty_){var a=this.getParentSvg().getScreenCTM();a&&(this.inverseScreenCTM_=a.inverse(),this.inverseScreenCTMDirty_=!1)}return this.inverseScreenCTM_};Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM=function(){this.inverseScreenCTMDirty_=!0};Blockly.WorkspaceSvg.prototype.isVisible=function(){return this.isVisible_};
|
||||
Blockly.WorkspaceSvg.prototype.configureContextMenu=null;Blockly.WorkspaceSvg.prototype.targetWorkspace=null;Blockly.WorkspaceSvg.prototype.inverseScreenCTM_=null;Blockly.WorkspaceSvg.prototype.inverseScreenCTMDirty_=!0;Blockly.WorkspaceSvg.prototype.setCursor=function(a){this.cursor_&&this.cursor_.getDrawer().dispose();this.cursor_=a;this.cursor_.setDrawer(new Blockly.CursorSvg(this,!1));this.svgGroup_&&this.svgGroup_.appendChild(this.cursor_.getDrawer().createDom())};
|
||||
Blockly.WorkspaceSvg.prototype.setMarker=function(a){this.marker_&&this.marker_.getDrawer().dispose();this.marker_=a;this.marker_.setDrawer(new Blockly.CursorSvg(this,!0));this.svgGroup_&&this.svgGroup_.appendChild(this.marker_.getDrawer().createDom())};Blockly.WorkspaceSvg.prototype.getInverseScreenCTM=function(){if(this.inverseScreenCTMDirty_){var a=this.getParentSvg().getScreenCTM();a&&(this.inverseScreenCTM_=a.inverse(),this.inverseScreenCTMDirty_=!1)}return this.inverseScreenCTM_};
|
||||
Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM=function(){this.inverseScreenCTMDirty_=!0};Blockly.WorkspaceSvg.prototype.isVisible=function(){return this.isVisible_};
|
||||
Blockly.WorkspaceSvg.prototype.getSvgXY=function(a){var b=0,c=0,d=1;if(Blockly.utils.dom.containsNode(this.getCanvas(),a)||Blockly.utils.dom.containsNode(this.getBubbleCanvas(),a))d=this.scale;do{var e=Blockly.utils.getRelativeXY(a);if(a==this.getCanvas()||a==this.getBubbleCanvas())d=1;b+=e.x*d;c+=e.y*d;a=a.parentNode}while(a&&a!=this.getParentSvg());return new Blockly.utils.Coordinate(b,c)};Blockly.WorkspaceSvg.prototype.getOriginOffsetInPixels=function(){return Blockly.utils.getInjectionDivXY_(this.svgBlockCanvas_)};
|
||||
Blockly.WorkspaceSvg.prototype.getInjectionDiv=function(){if(!this.injectionDiv_)for(var a=this.svgGroup_;a;){if(-1!=(" "+(a.getAttribute("class")||"")+" ").indexOf(" injectionDiv ")){this.injectionDiv_=a;break}a=a.parentNode}return this.injectionDiv_};Blockly.WorkspaceSvg.prototype.setResizeHandlerWrapper=function(a){this.resizeHandlerWrapper_=a};
|
||||
Blockly.WorkspaceSvg.prototype.createDom=function(a){this.svgGroup_=Blockly.utils.dom.createSvgElement("g",{"class":"blocklyWorkspace"},null);a&&(this.svgBackground_=Blockly.utils.dom.createSvgElement("rect",{height:"100%",width:"100%","class":a},this.svgGroup_),"blocklyMainBackground"==a&&this.grid_&&(this.svgBackground_.style.fill="url(#"+this.grid_.getPatternId()+")"));this.svgBlockCanvas_=Blockly.utils.dom.createSvgElement("g",{"class":"blocklyBlockCanvas"},this.svgGroup_);this.svgBubbleCanvas_=
|
||||
Blockly.utils.dom.createSvgElement("g",{"class":"blocklyBubbleCanvas"},this.svgGroup_);this.isFlyout||(Blockly.bindEventWithChecks_(this.svgGroup_,"mousedown",this,this.onMouseDown_,!1,!0),Blockly.bindEventWithChecks_(this.svgGroup_,"wheel",this,this.onMouseWheel_));this.options.hasCategories&&(this.toolbox_=new Blockly.Toolbox(this));this.grid_&&this.grid_.update(this.scale);this.recordDeleteAreas();a=this.cursor.createDom();this.svgGroup_.appendChild(a);a=this.marker.createDom();this.svgGroup_.appendChild(a);
|
||||
return this.svgGroup_};
|
||||
Blockly.utils.dom.createSvgElement("g",{"class":"blocklyBubbleCanvas"},this.svgGroup_);this.isFlyout||(Blockly.bindEventWithChecks_(this.svgGroup_,"mousedown",this,this.onMouseDown_,!1,!0),Blockly.bindEventWithChecks_(this.svgGroup_,"wheel",this,this.onMouseWheel_));this.options.hasCategories&&(this.toolbox_=new Blockly.Toolbox(this));this.grid_&&this.grid_.update(this.scale);this.recordDeleteAreas();a=this.cursor_.getDrawer().createDom();this.svgGroup_.appendChild(a);a=this.marker_.getDrawer().createDom();
|
||||
this.svgGroup_.appendChild(a);return this.svgGroup_};
|
||||
Blockly.WorkspaceSvg.prototype.dispose=function(){this.rendered=!1;this.currentGesture_&&this.currentGesture_.cancel();Blockly.WorkspaceSvg.superClass_.dispose.call(this);this.svgGroup_&&(Blockly.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.svgBubbleCanvas_=this.svgBlockCanvas_=null;this.toolbox_&&(this.toolbox_.dispose(),this.toolbox_=null);this.flyout_&&(this.flyout_.dispose(),this.flyout_=null);this.trashcan&&(this.trashcan.dispose(),this.trashcan=null);this.scrollbar&&(this.scrollbar.dispose(),
|
||||
this.scrollbar=null);this.zoomControls_&&(this.zoomControls_.dispose(),this.zoomControls_=null);this.marker&&this.marker.dispose();this.cursor&&this.cursor.dispose();this.audioManager_&&(this.audioManager_.dispose(),this.audioManager_=null);this.grid_&&(this.grid_.dispose(),this.grid_=null);this.flyoutButtonCallbacks_=this.toolboxCategoryCallbacks_=this.connectionDBList=null;if(!this.options.parentWorkspace){var a=this.getParentSvg().parentNode;a&&Blockly.utils.dom.removeNode(a)}this.resizeHandlerWrapper_&&
|
||||
this.scrollbar=null);this.zoomControls_&&(this.zoomControls_.dispose(),this.zoomControls_=null);this.marker_&&this.marker_.getDrawer().dispose();this.cursor_&&this.cursor_.getDrawer().dispose();this.audioManager_&&(this.audioManager_.dispose(),this.audioManager_=null);this.grid_&&(this.grid_.dispose(),this.grid_=null);this.flyoutButtonCallbacks_=this.toolboxCategoryCallbacks_=this.connectionDBList=null;if(!this.options.parentWorkspace){var a=this.getParentSvg().parentNode;a&&Blockly.utils.dom.removeNode(a)}this.resizeHandlerWrapper_&&
|
||||
(Blockly.unbindEvent_(this.resizeHandlerWrapper_),this.resizeHandlerWrapper_=null)};Blockly.WorkspaceSvg.prototype.newBlock=function(a,b){return new Blockly.BlockSvg(this,a,b)};Blockly.WorkspaceSvg.prototype.addTrashcan=function(){this.trashcan=new Blockly.Trashcan(this);var a=this.trashcan.createDom();this.svgGroup_.insertBefore(a,this.svgBlockCanvas_)};
|
||||
Blockly.WorkspaceSvg.prototype.addZoomControls=function(){this.zoomControls_=new Blockly.ZoomControls(this);var a=this.zoomControls_.createDom();this.svgGroup_.appendChild(a)};
|
||||
Blockly.WorkspaceSvg.prototype.addFlyout_=function(a){var b={disabledPatternId:this.options.disabledPatternId,parentWorkspace:this,RTL:this.RTL,oneBasedIndex:this.options.oneBasedIndex,horizontalLayout:this.horizontalLayout,toolboxPosition:this.options.toolboxPosition};this.flyout_=this.horizontalLayout?new Blockly.HorizontalFlyout(b):new Blockly.VerticalFlyout(b);this.flyout_.autoClose=!1;return this.flyout_.createDom(a)};
|
||||
@@ -654,8 +654,8 @@ Blockly.WorkspaceSvg.prototype.setVisible=function(a){this.scrollbar&&this.scrol
|
||||
Blockly.WorkspaceSvg.prototype.render=function(){for(var a=this.getAllBlocks(!1),b=a.length-1;0<=b;b--)a[b].render(!1);if(this.currentGesture_)for(a=this.currentGesture_.getInsertionMarkers(),b=0;b<a.length;b++)a[b].render(!1)};Blockly.WorkspaceSvg.prototype.traceOn=function(){console.warn("Deprecated call to traceOn, delete this.")};
|
||||
Blockly.WorkspaceSvg.prototype.highlightBlock=function(a,b){if(void 0===b){for(var c=0,d;d=this.highlightedBlocks_[c];c++)d.setHighlighted(!1);this.highlightedBlocks_.length=0}if(d=a?this.getBlockById(a):null)(c=void 0===b||b)?-1==this.highlightedBlocks_.indexOf(d)&&this.highlightedBlocks_.push(d):Blockly.utils.arrayRemove(this.highlightedBlocks_,d),d.setHighlighted(c)};
|
||||
Blockly.WorkspaceSvg.prototype.paste=function(a){!this.rendered||a.getElementsByTagName("block").length>=this.remainingCapacity()||(this.currentGesture_&&this.currentGesture_.cancel(),"comment"==a.tagName.toLowerCase()?this.pasteWorkspaceComment_(a):this.pasteBlock_(a))};
|
||||
Blockly.WorkspaceSvg.prototype.pasteBlock_=function(a){Blockly.Events.disable();try{var b=Blockly.Xml.domToBlock(a,this),c=Blockly.navigation.marker_.getCurNode();if(Blockly.keyboardAccessibilityMode&&c){Blockly.navigation.insertBlock(b,c.getLocation());return}var d=parseInt(a.getAttribute("x"),10),e=parseInt(a.getAttribute("y"),10);if(!isNaN(d)&&!isNaN(e)){this.RTL&&(d=-d);do{a=!1;var f=this.getAllBlocks(!1);c=0;for(var g;g=f[c];c++){var h=g.getRelativeToSurfaceXY();if(1>=Math.abs(d-h.x)&&1>=Math.abs(e-
|
||||
h.y)){a=!0;break}}if(!a){var k=b.getConnections_(!1);c=0;for(var l;l=k[c];c++)if(l.closest(Blockly.SNAP_RADIUS,new Blockly.utils.Coordinate(d,e)).connection){a=!0;break}}a&&(d=this.RTL?d-Blockly.SNAP_RADIUS:d+Blockly.SNAP_RADIUS,e+=2*Blockly.SNAP_RADIUS)}while(a);b.moveBy(d,e)}}finally{Blockly.Events.enable()}Blockly.Events.isEnabled()&&!b.isShadow()&&Blockly.Events.fire(new Blockly.Events.BlockCreate(b));b.select()};
|
||||
Blockly.WorkspaceSvg.prototype.pasteBlock_=function(a){Blockly.Events.disable();try{var b=Blockly.Xml.domToBlock(a,this),c=this.getMarker().getCurNode();if(Blockly.keyboardAccessibilityMode&&c){Blockly.navigation.insertBlock(b,c.getLocation());return}var d=parseInt(a.getAttribute("x"),10),e=parseInt(a.getAttribute("y"),10);if(!isNaN(d)&&!isNaN(e)){this.RTL&&(d=-d);do{a=!1;var f=this.getAllBlocks(!1);c=0;for(var g;g=f[c];c++){var h=g.getRelativeToSurfaceXY();if(1>=Math.abs(d-h.x)&&1>=Math.abs(e-h.y)){a=
|
||||
!0;break}}if(!a){var k=b.getConnections_(!1);c=0;for(var l;l=k[c];c++)if(l.closest(Blockly.SNAP_RADIUS,new Blockly.utils.Coordinate(d,e)).connection){a=!0;break}}a&&(d=this.RTL?d-Blockly.SNAP_RADIUS:d+Blockly.SNAP_RADIUS,e+=2*Blockly.SNAP_RADIUS)}while(a);b.moveBy(d,e)}}finally{Blockly.Events.enable()}Blockly.Events.isEnabled()&&!b.isShadow()&&Blockly.Events.fire(new Blockly.Events.BlockCreate(b));b.select()};
|
||||
Blockly.WorkspaceSvg.prototype.pasteWorkspaceComment_=function(a){Blockly.Events.disable();try{var b=Blockly.WorkspaceCommentSvg.fromXml(a,this),c=parseInt(a.getAttribute("x"),10),d=parseInt(a.getAttribute("y"),10);isNaN(c)||isNaN(d)||(this.RTL&&(c=-c),b.moveBy(c+50,d+50))}finally{Blockly.Events.enable()}Blockly.Events.isEnabled();b.select()};
|
||||
Blockly.WorkspaceSvg.prototype.refreshToolboxSelection=function(){var a=this.isFlyout?this.targetWorkspace:this;a&&!a.currentGesture_&&a.toolbox_&&a.toolbox_.flyout_&&a.toolbox_.refreshSelection()};Blockly.WorkspaceSvg.prototype.renameVariableById=function(a,b){Blockly.WorkspaceSvg.superClass_.renameVariableById.call(this,a,b);this.refreshToolboxSelection()};Blockly.WorkspaceSvg.prototype.deleteVariableById=function(a){Blockly.WorkspaceSvg.superClass_.deleteVariableById.call(this,a);this.refreshToolboxSelection()};
|
||||
Blockly.WorkspaceSvg.prototype.createVariable=function(a,b,c){a=Blockly.WorkspaceSvg.superClass_.createVariable.call(this,a,b,c);this.refreshToolboxSelection();return a};Blockly.WorkspaceSvg.prototype.recordDeleteAreas=function(){this.deleteAreaTrash_=this.trashcan&&this.svgGroup_.parentNode?this.trashcan.getClientRect():null;this.deleteAreaToolbox_=this.flyout_?this.flyout_.getClientRect():this.toolbox_?this.toolbox_.getClientRect():null};
|
||||
@@ -1049,48 +1049,47 @@ case Blockly.ASTNode.types.INPUT:return Blockly.ASTNode.createBlockNode(this.loc
|
||||
Blockly.user.keyMap.getActionByKeyCode=function(a){return Blockly.user.keyMap.map_[a]};Blockly.user.keyMap.getKeyByAction=function(a){for(var b=Object.keys(Blockly.user.keyMap.map_),c=0,d;d=b[c];c++)if(Blockly.user.keyMap.map_[d].name===a.name)return d;return null};Blockly.user.keyMap.serializeKeyEvent=function(a){for(var b=Blockly.utils.object.values(Blockly.user.keyMap.modifierKeys),c="",d=0,e;e=b[d];d++)a.getModifierState(e)&&(c+=e);return c+=a.keyCode};
|
||||
Blockly.user.keyMap.createSerializedKey=function(a,b){for(var c="",d=Blockly.utils.object.values(Blockly.user.keyMap.modifierKeys),e=0,f;f=b[e];e++)if(-1<d.indexOf(f))c+=f;else throw Error(f+" is not a valid modifier key.");return c+a};
|
||||
Blockly.user.keyMap.createDefaultKeyMap=function(){var a={},b=Blockly.user.keyMap.createSerializedKey(Blockly.utils.KeyCodes.K,[Blockly.user.keyMap.modifierKeys.CONTROL]);a[Blockly.utils.KeyCodes.W]=Blockly.navigation.ACTION_PREVIOUS;a[Blockly.utils.KeyCodes.A]=Blockly.navigation.ACTION_OUT;a[Blockly.utils.KeyCodes.S]=Blockly.navigation.ACTION_NEXT;a[Blockly.utils.KeyCodes.D]=Blockly.navigation.ACTION_IN;a[Blockly.utils.KeyCodes.I]=Blockly.navigation.ACTION_INSERT;a[Blockly.utils.KeyCodes.ENTER]=
|
||||
Blockly.navigation.ACTION_MARK;a[Blockly.utils.KeyCodes.X]=Blockly.navigation.ACTION_DISCONNECT;a[Blockly.utils.KeyCodes.T]=Blockly.navigation.ACTION_TOOLBOX;a[Blockly.utils.KeyCodes.E]=Blockly.navigation.ACTION_EXIT;a[Blockly.utils.KeyCodes.ESC]=Blockly.navigation.ACTION_EXIT;a[b]=Blockly.navigation.ACTION_TOGGLE_KEYBOARD_NAV;return a};Blockly.navigation={};Blockly.navigation.cursor_=null;Blockly.navigation.marker_=null;Blockly.navigation.currentCategory_=null;Blockly.navigation.flyoutBlock_=null;Blockly.navigation.loggingCallback=null;Blockly.navigation.STATE_FLYOUT=1;Blockly.navigation.STATE_WS=2;Blockly.navigation.STATE_TOOLBOX=3;Blockly.navigation.currentState_=Blockly.navigation.STATE_WS;
|
||||
Blockly.navigation.actionNames={PREVIOUS:"previous",NEXT:"next",IN:"in",OUT:"out",INSERT:"insert",MARK:"mark",DISCONNECT:"disconnect",TOOLBOX:"toolbox",EXIT:"exit",TOGGLE_KEYBOARD_NAV:"toggle_keyboard_nav"};Blockly.navigation.setCursor=function(a){Blockly.navigation.cursor_=a};Blockly.navigation.setMarker=function(a){Blockly.navigation.marker_=a};Blockly.navigation.markAtCursor=function(){Blockly.navigation.marker_.setLocation(Blockly.navigation.cursor_.getCurNode())};
|
||||
Blockly.navigation.removeMark=function(){Blockly.navigation.marker_.setLocation(null);Blockly.navigation.marker_.hide()};Blockly.navigation.getTopNode=function(a){var b=a.previousConnection,c=a.outputConnection;return(b=b?b:c)?Blockly.ASTNode.createConnectionNode(b):Blockly.ASTNode.createBlockNode(a)};
|
||||
Blockly.navigation.focusToolbox=function(){Blockly.navigation.resetFlyout(!1);Blockly.navigation.currentState_=Blockly.navigation.STATE_TOOLBOX;var a=Blockly.getMainWorkspace(),b=a.getToolbox();Blockly.navigation.marker_.getCurNode()||Blockly.navigation.markAtCursor();a&&!Blockly.navigation.currentCategory_&&(Blockly.navigation.currentCategory_=b.tree_.firstChild_);b.tree_.setSelectedItem(Blockly.navigation.currentCategory_)};
|
||||
Blockly.navigation.ACTION_MARK;a[Blockly.utils.KeyCodes.X]=Blockly.navigation.ACTION_DISCONNECT;a[Blockly.utils.KeyCodes.T]=Blockly.navigation.ACTION_TOOLBOX;a[Blockly.utils.KeyCodes.E]=Blockly.navigation.ACTION_EXIT;a[Blockly.utils.KeyCodes.ESC]=Blockly.navigation.ACTION_EXIT;a[b]=Blockly.navigation.ACTION_TOGGLE_KEYBOARD_NAV;return a};Blockly.navigation={};Blockly.navigation.currentCategory_=null;Blockly.navigation.loggingCallback=null;Blockly.navigation.STATE_FLYOUT=1;Blockly.navigation.STATE_WS=2;Blockly.navigation.STATE_TOOLBOX=3;Blockly.navigation.currentState_=Blockly.navigation.STATE_WS;Blockly.navigation.actionNames={PREVIOUS:"previous",NEXT:"next",IN:"in",OUT:"out",INSERT:"insert",MARK:"mark",DISCONNECT:"disconnect",TOOLBOX:"toolbox",EXIT:"exit",TOGGLE_KEYBOARD_NAV:"toggle_keyboard_nav"};
|
||||
Blockly.navigation.markAtCursor=function(){Blockly.getMainWorkspace().getMarker().setLocation(Blockly.getMainWorkspace().getCursor().getCurNode())};Blockly.navigation.removeMark=function(){Blockly.getMainWorkspace().getMarker().setLocation(null);Blockly.getMainWorkspace().getMarker().hide()};Blockly.navigation.getTopNode=function(a){var b=a.previousConnection,c=a.outputConnection;return(b=b?b:c)?Blockly.ASTNode.createConnectionNode(b):Blockly.ASTNode.createBlockNode(a)};
|
||||
Blockly.navigation.focusToolbox=function(){Blockly.navigation.resetFlyout(!1);Blockly.navigation.currentState_=Blockly.navigation.STATE_TOOLBOX;var a=Blockly.getMainWorkspace(),b=a.getToolbox();Blockly.getMainWorkspace().getMarker().getCurNode()||Blockly.navigation.markAtCursor();a&&!Blockly.navigation.currentCategory_&&(Blockly.navigation.currentCategory_=b.tree_.firstChild_);b.tree_.setSelectedItem(Blockly.navigation.currentCategory_)};
|
||||
Blockly.navigation.nextCategory=function(){if(Blockly.navigation.currentCategory_){var a=Blockly.navigation.currentCategory_.getNextShownNode();a&&(a.select(),Blockly.navigation.currentCategory_=a)}};Blockly.navigation.previousCategory=function(){if(Blockly.navigation.currentCategory_){var a=Blockly.navigation.currentCategory_.getPreviousShownNode();a&&(a.select(),Blockly.navigation.currentCategory_=a)}};
|
||||
Blockly.navigation.inCategory=function(){if(Blockly.navigation.currentCategory_){var a=Blockly.navigation.currentCategory_;a.hasChildren()?a.getExpanded()?(a.getFirstChild().select(),Blockly.navigation.currentCategory_=a.getFirstChild()):a.setExpanded(!0):Blockly.navigation.focusFlyout()}};
|
||||
Blockly.navigation.outCategory=function(){if(Blockly.navigation.currentCategory_){var a=Blockly.navigation.currentCategory_;if(a.hasChildren()&&a.getExpanded()&&a.isUserCollapsible())a.setExpanded(!1);else{var b=a.getParent();a=a.getTree();b&&b!=a&&(b.select(),Blockly.navigation.currentCategory_=b)}}};
|
||||
Blockly.navigation.focusFlyout=function(){Blockly.navigation.currentState_=Blockly.navigation.STATE_FLYOUT;var a=Blockly.getMainWorkspace();var b=a.getToolbox(),c=Blockly.navigation.cursor_;a=b?b.flyout_:a.getFlyout();Blockly.navigation.marker_.getCurNode()||Blockly.navigation.markAtCursor();a&&a.getWorkspace()&&(a=a.getWorkspace().getTopBlocks(),0<a.length&&(a=a[0],Blockly.navigation.flyoutBlock_=a,a=Blockly.ASTNode.createBlockNode(Blockly.navigation.flyoutBlock_),c.setLocation(a)))};
|
||||
Blockly.navigation.selectNextBlockInFlyout=function(){if(Blockly.navigation.flyoutBlock_){var a=Blockly.navigation.getFlyoutBlocks_(),b=a.indexOf(Blockly.navigation.flyoutBlock_),c=Blockly.navigation.cursor_,d;-1<b&&a[++b]&&(d=a[b]);d&&(Blockly.navigation.flyoutBlock_=d,a=Blockly.ASTNode.createBlockNode(d),c.setLocation(a))}};
|
||||
Blockly.navigation.selectPreviousBlockInFlyout=function(){if(Blockly.navigation.flyoutBlock_){var a=Blockly.navigation.getFlyoutBlocks_(),b=a.indexOf(Blockly.navigation.flyoutBlock_),c=Blockly.navigation.cursor_,d;-1<b&&a[--b]&&(d=a[b]);d&&(Blockly.navigation.flyoutBlock_=d,a=Blockly.ASTNode.createBlockNode(d),c.setLocation(a))}};
|
||||
Blockly.navigation.getFlyoutBlocks_=function(){var a=Blockly.getMainWorkspace(),b=a.getToolbox(),c=[];(a=b?b.flyout_:a.getFlyout())&&a.getWorkspace()&&(c=a.getWorkspace().getTopBlocks());return c};
|
||||
Blockly.navigation.insertFromFlyout=function(){var a=Blockly.getMainWorkspace().getFlyout();a&&a.isVisible()?(a=a.createBlock(Blockly.navigation.flyoutBlock_),a.render(),a.setConnectionsHidden(!1),Blockly.navigation.cursor_.setLocation(Blockly.ASTNode.createBlockNode(a)),Blockly.navigation.modify_()||Blockly.navigation.warn("Something went wrong while inserting a block from the flyout."),Blockly.navigation.focusWorkspace(),Blockly.navigation.cursor_.setLocation(Blockly.navigation.getTopNode(a)),Blockly.navigation.removeMark()):
|
||||
Blockly.navigation.warn("Trying to insert from the flyout when the flyout does not exist or is not visible")};Blockly.navigation.resetFlyout=function(a){var b=Blockly.navigation.cursor_;Blockly.navigation.flyoutBlock_=null;b.hide();a&&b.workspace_.getFlyout().hide()};
|
||||
Blockly.navigation.modifyWarn_=function(){var a=Blockly.navigation.marker_.getCurNode(),b=Blockly.navigation.cursor_.getCurNode();if(!a)return Blockly.navigation.warn("Cannot insert with no marked node."),!1;if(!b)return Blockly.navigation.warn("Cannot insert with no cursor node."),!1;a=a.getType();b=b.getType();return a==Blockly.ASTNode.types.FIELD?(Blockly.navigation.warn("Should not have been able to mark a field."),!1):a==Blockly.ASTNode.types.BLOCK?(Blockly.navigation.warn("Should not have been able to mark a block."),
|
||||
Blockly.navigation.focusFlyout=function(){Blockly.navigation.currentState_=Blockly.navigation.STATE_FLYOUT;var a=Blockly.getMainWorkspace();var b=a.getToolbox();a=b?b.flyout_:a.getFlyout();Blockly.getMainWorkspace().getMarker().getCurNode()||Blockly.navigation.markAtCursor();a&&a.getWorkspace()&&(a=a.getWorkspace().getTopBlocks(),0<a.length&&(a=a[0],a=Blockly.ASTNode.createStackNode(a),Blockly.navigation.getFlyoutCursor_().setLocation(a)))};
|
||||
Blockly.navigation.getFlyoutCursor_=function(){var a=Blockly.getMainWorkspace(),b=null;a.rendered&&(b=(a=(b=a.getToolbox())?b.flyout_:a.getFlyout())?a.workspace_.getCursor():null);return b};
|
||||
Blockly.navigation.insertFromFlyout=function(){var a=Blockly.getMainWorkspace().getFlyout();a&&a.isVisible()?(a=a.createBlock(Blockly.navigation.getFlyoutCursor_().getCurNode().getLocation()),a.render(),a.setConnectionsHidden(!1),Blockly.getMainWorkspace().getCursor().setLocation(Blockly.ASTNode.createBlockNode(a)),Blockly.navigation.modify_()||Blockly.navigation.warn("Something went wrong while inserting a block from the flyout."),Blockly.navigation.focusWorkspace(),Blockly.getMainWorkspace().getCursor().setLocation(Blockly.navigation.getTopNode(a)),
|
||||
Blockly.navigation.removeMark()):Blockly.navigation.warn("Trying to insert from the flyout when the flyout does not exist or is not visible")};Blockly.navigation.resetFlyout=function(a){Blockly.navigation.getFlyoutCursor_()&&(Blockly.navigation.getFlyoutCursor_().hide(),a&&Blockly.getMainWorkspace().getFlyout().hide())};
|
||||
Blockly.navigation.modifyWarn_=function(){var a=Blockly.getMainWorkspace().getMarker().getCurNode(),b=Blockly.getMainWorkspace().getCursor().getCurNode();if(!a)return Blockly.navigation.warn("Cannot insert with no marked node."),!1;if(!b)return Blockly.navigation.warn("Cannot insert with no cursor node."),!1;a=a.getType();b=b.getType();return a==Blockly.ASTNode.types.FIELD?(Blockly.navigation.warn("Should not have been able to mark a field."),!1):a==Blockly.ASTNode.types.BLOCK?(Blockly.navigation.warn("Should not have been able to mark a block."),
|
||||
!1):a==Blockly.ASTNode.types.STACK?(Blockly.navigation.warn("Should not have been able to mark a stack."),!1):b==Blockly.ASTNode.types.FIELD?(Blockly.navigation.warn("Cannot attach a field to anything else."),!1):b==Blockly.ASTNode.types.WORKSPACE?(Blockly.navigation.warn("Cannot attach a workspace to anything else."),!1):!0};
|
||||
Blockly.navigation.moveBlockToWorkspace_=function(a,b){if(a.isShadow())return Blockly.navigation.warn("Cannot move a shadow block to the workspace."),!1;a.getParent()&&a.unplug(!1);a.moveTo(b.getWsCoordinate());return!0};
|
||||
Blockly.navigation.modify_=function(){var a=Blockly.navigation.marker_.getCurNode(),b=Blockly.navigation.cursor_.getCurNode();if(!Blockly.navigation.modifyWarn_())return!1;var c=a.getType(),d=b.getType(),e=b.getLocation(),f=a.getLocation();if(a.isConnection()&&b.isConnection())return Blockly.navigation.connect(e,f);if(a.isConnection()&&(d==Blockly.ASTNode.types.BLOCK||d==Blockly.ASTNode.types.STACK))return Blockly.navigation.insertBlock(e,f);if(c==Blockly.ASTNode.types.WORKSPACE)return b=Blockly.navigation.getSourceBlock_(b),
|
||||
Blockly.navigation.moveBlockToWorkspace_(b,a);Blockly.navigation.warn("Unexpected state in Blockly.navigation.modify_.");return!1};Blockly.navigation.disconnectChild_=function(a,b){var c=a.getSourceBlock(),d=b.getSourceBlock();c.getRootBlock()==d.getRootBlock()&&(-1<c.getDescendants().indexOf(d)?Blockly.navigation.getInferiorConnection_(b).disconnect():Blockly.navigation.getInferiorConnection_(a).disconnect())};
|
||||
Blockly.navigation.modify_=function(){var a=Blockly.getMainWorkspace().getMarker().getCurNode(),b=Blockly.getMainWorkspace().getCursor().getCurNode();if(!Blockly.navigation.modifyWarn_())return!1;var c=a.getType(),d=b.getType(),e=b.getLocation(),f=a.getLocation();if(a.isConnection()&&b.isConnection())return Blockly.navigation.connect(e,f);if(a.isConnection()&&(d==Blockly.ASTNode.types.BLOCK||d==Blockly.ASTNode.types.STACK))return Blockly.navigation.insertBlock(e,f);if(c==Blockly.ASTNode.types.WORKSPACE)return b=
|
||||
Blockly.navigation.getSourceBlock_(b),Blockly.navigation.moveBlockToWorkspace_(b,a);Blockly.navigation.warn("Unexpected state in Blockly.navigation.modify_.");return!1};Blockly.navigation.disconnectChild_=function(a,b){var c=a.getSourceBlock(),d=b.getSourceBlock();c.getRootBlock()==d.getRootBlock()&&(-1<c.getDescendants().indexOf(d)?Blockly.navigation.getInferiorConnection_(b).disconnect():Blockly.navigation.getInferiorConnection_(a).disconnect())};
|
||||
Blockly.navigation.moveAndConnect_=function(a,b){if(!a||!b)return!1;var c=a.getSourceBlock();return b.canConnectWithReason_(a)==Blockly.Connection.CAN_CONNECT?(Blockly.navigation.disconnectChild_(a,b),b.isSuperior()||c.getRootBlock().positionNearConnection(a,b),b.connect(a),!0):!1};Blockly.navigation.getInferiorConnection_=function(a){var b=a.getSourceBlock();return a.isSuperior()?b.previousConnection?b.previousConnection:b.outputConnection?b.outputConnection:null:a};
|
||||
Blockly.navigation.getSuperiorConnection_=function(a){return a.isSuperior()?a:a.targetConnection?a.targetConnection:null};
|
||||
Blockly.navigation.connect=function(a,b){if(!a||!b)return!1;var c=Blockly.navigation.getInferiorConnection_(a),d=Blockly.navigation.getSuperiorConnection_(b),e=Blockly.navigation.getSuperiorConnection_(a),f=Blockly.navigation.getInferiorConnection_(b);if(c&&d&&Blockly.navigation.moveAndConnect_(c,d)||e&&f&&Blockly.navigation.moveAndConnect_(e,f)||Blockly.navigation.moveAndConnect_(a,b))return!0;try{b.checkConnection_(a)}catch(g){Blockly.navigation.warn("Connection failed with error: "+g)}return!1};
|
||||
Blockly.navigation.insertBlock=function(a,b){switch(b.type){case Blockly.PREVIOUS_STATEMENT:if(Blockly.navigation.moveAndConnect_(a.nextConnection,b))return!0;break;case Blockly.NEXT_STATEMENT:if(Blockly.navigation.moveAndConnect_(a.previousConnection,b))return!0;break;case Blockly.INPUT_VALUE:if(Blockly.navigation.moveAndConnect_(a.outputConnection,b))return!0;break;case Blockly.OUTPUT_VALUE:for(var c=0;c<a.inputList.length;c++){var d=a.inputList[c].connection;if(d.type===Blockly.INPUT_VALUE&&Blockly.navigation.moveAndConnect_(d,
|
||||
b))return!0}}Blockly.navigation.warn("This block can not be inserted at the marked location.");return!1};
|
||||
Blockly.navigation.disconnectBlocks=function(){var a=Blockly.navigation.cursor_.getCurNode();if(a.isConnection()){var b=a.getLocation();b.isConnected()?(a=b.isSuperior()?b:b.targetConnection,b=b.isSuperior()?b.targetConnection:b,b.getSourceBlock().isShadow()?Blockly.navigation.log("Cannot disconnect a shadow block"):(a.disconnect(),b.bumpAwayFrom_(a),a.getSourceBlock().getRootBlock().bringToFront(),a=Blockly.ASTNode.createConnectionNode(a),Blockly.navigation.cursor_.setLocation(a))):Blockly.navigation.log("Cannot disconnect unconnected connection")}else Blockly.navigation.log("Cannot disconnect blocks when the cursor is not on a connection")};
|
||||
Blockly.navigation.focusWorkspace=function(){var a=Blockly.navigation.cursor_,b=Blockly.getMainWorkspace().getToolbox()?!0:!1,c=Blockly.getMainWorkspace().getTopBlocks();Blockly.navigation.resetFlyout(b);Blockly.navigation.currentState_=Blockly.navigation.STATE_WS;0<c.length?a.setLocation(Blockly.navigation.getTopNode(c[0])):(b=a.workspace_,c=new Blockly.utils.Coordinate(100,100),b=Blockly.ASTNode.createWorkspaceNode(b,c),a.setLocation(b))};
|
||||
Blockly.navigation.handleEnterForWS=function(){var a=Blockly.navigation.cursor_.getCurNode(),b=a.getType();b===Blockly.ASTNode.types.FIELD?a.getLocation().showEditor_():a.isConnection()||b==Blockly.ASTNode.types.WORKSPACE?Blockly.navigation.markAtCursor():b==Blockly.ASTNode.types.BLOCK?Blockly.navigation.warn("Cannot mark a block."):b==Blockly.ASTNode.types.STACK&&Blockly.navigation.warn("Cannot mark a stack.")};
|
||||
Blockly.navigation.disconnectBlocks=function(){var a=Blockly.getMainWorkspace().getCursor().getCurNode();if(a.isConnection()){var b=a.getLocation();b.isConnected()?(a=b.isSuperior()?b:b.targetConnection,b=b.isSuperior()?b.targetConnection:b,b.getSourceBlock().isShadow()?Blockly.navigation.log("Cannot disconnect a shadow block"):(a.disconnect(),b.bumpAwayFrom_(a),a.getSourceBlock().getRootBlock().bringToFront(),a=Blockly.ASTNode.createConnectionNode(a),Blockly.getMainWorkspace().getCursor().setLocation(a))):
|
||||
Blockly.navigation.log("Cannot disconnect unconnected connection")}else Blockly.navigation.log("Cannot disconnect blocks when the cursor is not on a connection")};
|
||||
Blockly.navigation.focusWorkspace=function(){Blockly.hideChaff();var a=Blockly.getMainWorkspace().getCursor(),b=Blockly.getMainWorkspace().getToolbox()?!0:!1,c=Blockly.getMainWorkspace().getTopBlocks();Blockly.navigation.resetFlyout(b);Blockly.navigation.currentState_=Blockly.navigation.STATE_WS;0<c.length?a.setLocation(Blockly.navigation.getTopNode(c[0])):(b=Blockly.getMainWorkspace(),c=new Blockly.utils.Coordinate(100,100),b=Blockly.ASTNode.createWorkspaceNode(b,c),a.setLocation(b))};
|
||||
Blockly.navigation.handleEnterForWS=function(){var a=Blockly.getMainWorkspace().getCursor().getCurNode(),b=a.getType();b===Blockly.ASTNode.types.FIELD?a.getLocation().showEditor_():a.isConnection()||b==Blockly.ASTNode.types.WORKSPACE?Blockly.navigation.markAtCursor():b==Blockly.ASTNode.types.BLOCK?Blockly.navigation.warn("Cannot mark a block."):b==Blockly.ASTNode.types.STACK&&Blockly.navigation.warn("Cannot mark a stack.")};
|
||||
Blockly.navigation.getSourceBlock_=function(a){return a?a.getType()===Blockly.ASTNode.types.BLOCK?a.getLocation():a.getType()===Blockly.ASTNode.types.STACK?a.getLocation():a.getType()===Blockly.ASTNode.types.WORKSPACE?null:a.getLocation().getSourceBlock():null};
|
||||
Blockly.navigation.moveCursorOnBlockDelete=function(a){var b=Blockly.navigation.cursor_;if(b){var c=b.getCurNode();c=Blockly.navigation.getSourceBlock_(c);c===a?c.getParent()?(a=c.previousConnection?c.previousConnection:c.outputConnection)&&b.setLocation(Blockly.ASTNode.createConnectionNode(a.targetConnection)):b.setLocation(Blockly.ASTNode.createWorkspaceNode(c.workspace,c.getRelativeToSurfaceXY())):-1<a.getChildren().indexOf(c)&&b.setLocation(Blockly.ASTNode.createWorkspaceNode(c.workspace,c.getRelativeToSurfaceXY()))}};
|
||||
Blockly.navigation.moveCursorOnBlockMutation=function(a){var b=Blockly.navigation.cursor_;if(b){var c=b.getCurNode();c=Blockly.navigation.getSourceBlock_(c);c===a&&b.setLocation(Blockly.ASTNode.createBlockNode(c))}};
|
||||
Blockly.navigation.onKeyPress=function(a){a=Blockly.user.keyMap.serializeKeyEvent(a);a=Blockly.user.keyMap.getActionByKeyCode(a);var b=Blockly.navigation.cursor_.getCurNode(),c=Blockly.getMainWorkspace().options.readOnly,d=!1;a&&(Blockly.keyboardAccessibilityMode?c?-1<Blockly.navigation.READONLY_ACTION_LIST.indexOf(a)&&(d=Blockly.navigation.onBlocklyAction(a)):(b&&b.getType()===Blockly.ASTNode.types.FIELD&&(d=b.getLocation().onBlocklyAction(a)),d||(d=Blockly.navigation.onBlocklyAction(a))):a.name===
|
||||
Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV&&(Blockly.navigation.enableKeyboardAccessibility(),d=!0));return d};
|
||||
Blockly.navigation.onBlocklyAction=function(a){return a.name===Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV?(Blockly.navigation.disableKeyboardAccessibility(),!0):Blockly.navigation.currentState_===Blockly.navigation.STATE_WS?Blockly.navigation.workspaceOnAction_(a):Blockly.navigation.currentState_===Blockly.navigation.STATE_FLYOUT?Blockly.navigation.flyoutOnAction_(a):Blockly.navigation.currentState_===Blockly.navigation.STATE_TOOLBOX?Blockly.navigation.toolboxOnAction_(a):!1};
|
||||
Blockly.navigation.workspaceOnAction_=function(a){switch(a.name){case Blockly.navigation.actionNames.PREVIOUS:return Blockly.navigation.cursor_.prev(),!0;case Blockly.navigation.actionNames.OUT:return Blockly.navigation.cursor_.out(),!0;case Blockly.navigation.actionNames.NEXT:return Blockly.navigation.cursor_.next(),!0;case Blockly.navigation.actionNames.IN:return Blockly.navigation.cursor_["in"](),!0;case Blockly.navigation.actionNames.INSERT:return Blockly.navigation.modify_(),!0;case Blockly.navigation.actionNames.MARK:return Blockly.navigation.handleEnterForWS(),
|
||||
!0;case Blockly.navigation.actionNames.DISCONNECT:return Blockly.navigation.disconnectBlocks(),!0;case Blockly.navigation.actionNames.TOOLBOX:return Blockly.getMainWorkspace().getToolbox()?Blockly.navigation.focusToolbox():Blockly.navigation.focusFlyout(),!0;default:return!1}};
|
||||
Blockly.navigation.flyoutOnAction_=function(a){switch(a.name){case Blockly.navigation.actionNames.PREVIOUS:return Blockly.navigation.selectPreviousBlockInFlyout(),!0;case Blockly.navigation.actionNames.OUT:return Blockly.navigation.focusToolbox(),!0;case Blockly.navigation.actionNames.NEXT:return Blockly.navigation.selectNextBlockInFlyout(),!0;case Blockly.navigation.actionNames.MARK:return Blockly.navigation.insertFromFlyout(),!0;case Blockly.navigation.actionNames.EXIT:return Blockly.navigation.focusWorkspace(),
|
||||
Blockly.navigation.moveCursorOnBlockDelete=function(a){if(Blockly.getMainWorkspace()){var b=Blockly.getMainWorkspace().getCursor();if(b){var c=b.getCurNode();c=Blockly.navigation.getSourceBlock_(c);c===a?c.getParent()?(a=c.previousConnection?c.previousConnection:c.outputConnection)&&b.setLocation(Blockly.ASTNode.createConnectionNode(a.targetConnection)):b.setLocation(Blockly.ASTNode.createWorkspaceNode(c.workspace,c.getRelativeToSurfaceXY())):-1<a.getChildren().indexOf(c)&&b.setLocation(Blockly.ASTNode.createWorkspaceNode(c.workspace,
|
||||
c.getRelativeToSurfaceXY()))}}};Blockly.navigation.moveCursorOnBlockMutation=function(a){var b=Blockly.getMainWorkspace().getCursor();if(b){var c=b.getCurNode();c=Blockly.navigation.getSourceBlock_(c);c===a&&b.setLocation(Blockly.ASTNode.createBlockNode(c))}};Blockly.navigation.onKeyPress=function(a){a=Blockly.user.keyMap.serializeKeyEvent(a);return(a=Blockly.user.keyMap.getActionByKeyCode(a))?Blockly.navigation.onBlocklyAction(a):!1};
|
||||
Blockly.navigation.onBlocklyAction=function(a){var b=Blockly.getMainWorkspace().options.readOnly,c=!1;Blockly.keyboardAccessibilityMode?b?-1<Blockly.navigation.READONLY_ACTION_LIST.indexOf(a)&&(c=Blockly.navigation.handleActions_(a)):((b=Blockly.getMainWorkspace().getCursor().getCurNode())&&b.getType()===Blockly.ASTNode.types.FIELD&&(c=b.getLocation().onBlocklyAction(a)),c||(c=Blockly.navigation.handleActions_(a))):a.name===Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV&&(Blockly.navigation.enableKeyboardAccessibility(),
|
||||
c=!0);return c};
|
||||
Blockly.navigation.handleActions_=function(a){return a.name===Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV?(Blockly.navigation.disableKeyboardAccessibility(),!0):a.name===Blockly.navigation.actionNames.TOOLBOX?(Blockly.getMainWorkspace().getToolbox()?Blockly.navigation.focusToolbox():Blockly.navigation.focusFlyout(),!0):Blockly.navigation.currentState_===Blockly.navigation.STATE_WS?Blockly.navigation.workspaceOnAction_(a):Blockly.navigation.currentState_===Blockly.navigation.STATE_FLYOUT?Blockly.navigation.flyoutOnAction_(a):
|
||||
Blockly.navigation.currentState_===Blockly.navigation.STATE_TOOLBOX?Blockly.navigation.toolboxOnAction_(a):!1};
|
||||
Blockly.navigation.workspaceOnAction_=function(a){switch(a.name){case Blockly.navigation.actionNames.PREVIOUS:return Blockly.getMainWorkspace().getCursor().prev(),!0;case Blockly.navigation.actionNames.OUT:return Blockly.getMainWorkspace().getCursor().out(),!0;case Blockly.navigation.actionNames.NEXT:return Blockly.getMainWorkspace().getCursor().next(),!0;case Blockly.navigation.actionNames.IN:return Blockly.getMainWorkspace().getCursor()["in"](),!0;case Blockly.navigation.actionNames.INSERT:return Blockly.navigation.modify_(),
|
||||
!0;case Blockly.navigation.actionNames.MARK:return Blockly.navigation.handleEnterForWS(),!0;case Blockly.navigation.actionNames.DISCONNECT:return Blockly.navigation.disconnectBlocks(),!0;default:return!1}};
|
||||
Blockly.navigation.flyoutOnAction_=function(a){switch(a.name){case Blockly.navigation.actionNames.PREVIOUS:return Blockly.navigation.getFlyoutCursor_().prev(),!0;case Blockly.navigation.actionNames.OUT:return Blockly.navigation.focusToolbox(),!0;case Blockly.navigation.actionNames.NEXT:return Blockly.navigation.getFlyoutCursor_().next(),!0;case Blockly.navigation.actionNames.MARK:return Blockly.navigation.insertFromFlyout(),!0;case Blockly.navigation.actionNames.EXIT:return Blockly.navigation.focusWorkspace(),
|
||||
!0;default:return!1}};
|
||||
Blockly.navigation.toolboxOnAction_=function(a){switch(a.name){case Blockly.navigation.actionNames.PREVIOUS:return Blockly.navigation.previousCategory(),!0;case Blockly.navigation.actionNames.OUT:return Blockly.navigation.outCategory(),!0;case Blockly.navigation.actionNames.NEXT:return Blockly.navigation.nextCategory(),!0;case Blockly.navigation.actionNames.IN:return Blockly.navigation.inCategory(),!0;case Blockly.navigation.actionNames.EXIT:return Blockly.navigation.focusWorkspace(),!0;default:return!1}};
|
||||
Blockly.navigation.enableKeyboardAccessibility=function(){Blockly.keyboardAccessibilityMode||(Blockly.keyboardAccessibilityMode=!0,Blockly.navigation.focusWorkspace())};Blockly.navigation.disableKeyboardAccessibility=function(){Blockly.keyboardAccessibilityMode&&(Blockly.keyboardAccessibilityMode=!1,Blockly.navigation.cursor_.hide())};Blockly.navigation.log=function(a){Blockly.navigation.loggingCallback?Blockly.navigation.loggingCallback("log",a):console.log(a)};
|
||||
Blockly.navigation.warn=function(a){Blockly.navigation.loggingCallback?Blockly.navigation.loggingCallback("warn",a):console.warn(a)};Blockly.navigation.error=function(a){Blockly.navigation.loggingCallback?Blockly.navigation.loggingCallback("error",a):console.error(a)};Blockly.navigation.ACTION_PREVIOUS=new Blockly.Action(Blockly.navigation.actionNames.PREVIOUS,"Go to the previous location.");Blockly.navigation.ACTION_OUT=new Blockly.Action(Blockly.navigation.actionNames.OUT,"Go to the parent of the current location.");
|
||||
Blockly.navigation.ACTION_NEXT=new Blockly.Action(Blockly.navigation.actionNames.NEXT,"Go to the next location.");Blockly.navigation.ACTION_IN=new Blockly.Action(Blockly.navigation.actionNames.IN,"Go to the first child of the current location.");Blockly.navigation.ACTION_INSERT=new Blockly.Action(Blockly.navigation.actionNames.INSERT,"Connect the current location to the marked location.");Blockly.navigation.ACTION_MARK=new Blockly.Action(Blockly.navigation.actionNames.MARK,"Mark the current location.");
|
||||
Blockly.navigation.ACTION_DISCONNECT=new Blockly.Action(Blockly.navigation.actionNames.DISCONNECT,"Dicsonnect the block at thecurrent location from its parent.");Blockly.navigation.ACTION_TOOLBOX=new Blockly.Action(Blockly.navigation.actionNames.TOOLBOX,"Open the toolbox.");Blockly.navigation.ACTION_EXIT=new Blockly.Action(Blockly.navigation.actionNames.EXIT,"Close the current modal, such as a toolbox or field editor.");
|
||||
Blockly.navigation.ACTION_TOGGLE_KEYBOARD_NAV=new Blockly.Action(Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV,"Turns on and off keyboard navigation.");Blockly.navigation.READONLY_ACTION_LIST=[Blockly.navigation.ACTION_PREVIOUS,Blockly.navigation.ACTION_OUT,Blockly.navigation.ACTION_IN,Blockly.navigation.ACTION_NEXT];Blockly.Names=function(a,b){this.variablePrefix_=b||"";this.reservedDict_=Object.create(null);if(a)for(var c=a.split(","),d=0;d<c.length;d++)this.reservedDict_[c[d]]=!0;this.reset()};Blockly.Names.DEVELOPER_VARIABLE_TYPE="DEVELOPER_VARIABLE";Blockly.Names.prototype.reset=function(){this.db_=Object.create(null);this.dbReverse_=Object.create(null);this.variableMap_=null};Blockly.Names.prototype.setVariableMap=function(a){this.variableMap_=a};
|
||||
Blockly.navigation.enableKeyboardAccessibility=function(){Blockly.keyboardAccessibilityMode||(Blockly.keyboardAccessibilityMode=!0,Blockly.navigation.focusWorkspace())};Blockly.navigation.disableKeyboardAccessibility=function(){Blockly.keyboardAccessibilityMode&&(Blockly.keyboardAccessibilityMode=!1,Blockly.getMainWorkspace().getCursor().hide(),Blockly.getMainWorkspace().getMarker().hide(),Blockly.navigation.getFlyoutCursor_()&&Blockly.navigation.getFlyoutCursor_().hide())};
|
||||
Blockly.navigation.log=function(a){Blockly.navigation.loggingCallback?Blockly.navigation.loggingCallback("log",a):console.log(a)};Blockly.navigation.warn=function(a){Blockly.navigation.loggingCallback?Blockly.navigation.loggingCallback("warn",a):console.warn(a)};Blockly.navigation.error=function(a){Blockly.navigation.loggingCallback?Blockly.navigation.loggingCallback("error",a):console.error(a)};Blockly.navigation.ACTION_PREVIOUS=new Blockly.Action(Blockly.navigation.actionNames.PREVIOUS,"Go to the previous location.");
|
||||
Blockly.navigation.ACTION_OUT=new Blockly.Action(Blockly.navigation.actionNames.OUT,"Go to the parent of the current location.");Blockly.navigation.ACTION_NEXT=new Blockly.Action(Blockly.navigation.actionNames.NEXT,"Go to the next location.");Blockly.navigation.ACTION_IN=new Blockly.Action(Blockly.navigation.actionNames.IN,"Go to the first child of the current location.");Blockly.navigation.ACTION_INSERT=new Blockly.Action(Blockly.navigation.actionNames.INSERT,"Connect the current location to the marked location.");
|
||||
Blockly.navigation.ACTION_MARK=new Blockly.Action(Blockly.navigation.actionNames.MARK,"Mark the current location.");Blockly.navigation.ACTION_DISCONNECT=new Blockly.Action(Blockly.navigation.actionNames.DISCONNECT,"Dicsonnect the block at thecurrent location from its parent.");Blockly.navigation.ACTION_TOOLBOX=new Blockly.Action(Blockly.navigation.actionNames.TOOLBOX,"Open the toolbox.");Blockly.navigation.ACTION_EXIT=new Blockly.Action(Blockly.navigation.actionNames.EXIT,"Close the current modal, such as a toolbox or field editor.");
|
||||
Blockly.navigation.ACTION_TOGGLE_KEYBOARD_NAV=new Blockly.Action(Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV,"Turns on and off keyboard navigation.");Blockly.navigation.READONLY_ACTION_LIST=[Blockly.navigation.ACTION_PREVIOUS,Blockly.navigation.ACTION_OUT,Blockly.navigation.ACTION_IN,Blockly.navigation.ACTION_NEXT,Blockly.navigation.ACTION_TOGGLE_KEYBOARD_NAV];Blockly.Names=function(a,b){this.variablePrefix_=b||"";this.reservedDict_=Object.create(null);if(a)for(var c=a.split(","),d=0;d<c.length;d++)this.reservedDict_[c[d]]=!0;this.reset()};Blockly.Names.DEVELOPER_VARIABLE_TYPE="DEVELOPER_VARIABLE";Blockly.Names.prototype.reset=function(){this.db_=Object.create(null);this.dbReverse_=Object.create(null);this.variableMap_=null};Blockly.Names.prototype.setVariableMap=function(a){this.variableMap_=a};
|
||||
Blockly.Names.prototype.getNameForUserVariable_=function(a){return this.variableMap_?(a=this.variableMap_.getVariableById(a))?a.name:null:(console.log("Deprecated call to Blockly.Names.prototype.getName without defining a variable map. To fix, add the folowing code in your generator's init() function:\nBlockly.YourGeneratorName.variableDB_.setVariableMap(workspace.getVariableMap());"),null)};
|
||||
Blockly.Names.prototype.getName=function(a,b){if(b==Blockly.Variables.NAME_TYPE){var c=this.getNameForUserVariable_(a);c&&(a=c)}c=a.toLowerCase()+"_"+b;var d=b==Blockly.Variables.NAME_TYPE||b==Blockly.Names.DEVELOPER_VARIABLE_TYPE?this.variablePrefix_:"";if(c in this.db_)return d+this.db_[c];var e=this.getDistinctName(a,b);this.db_[c]=e.substr(d.length);return e};
|
||||
Blockly.Names.prototype.getDistinctName=function(a,b){for(var c=this.safeName_(a),d="";this.dbReverse_[c+d]||c+d in this.reservedDict_;)d=d?d+1:2;c+=d;this.dbReverse_[c]=!0;return(b==Blockly.Variables.NAME_TYPE||b==Blockly.Names.DEVELOPER_VARIABLE_TYPE?this.variablePrefix_:"")+c};Blockly.Names.prototype.safeName_=function(a){a?(a=encodeURI(a.replace(/ /g,"_")).replace(/[^\w]/g,"_"),-1!="0123456789".indexOf(a[0])&&(a="my_"+a)):a=Blockly.Msg.UNNAMED_KEY||"unnamed";return a};
|
||||
@@ -1108,8 +1107,9 @@ rx:4,ry:4},this.svgGroup_);var c=Blockly.utils.dom.createSvgElement("text",{"cla
|
||||
c.setAttribute("x",this.width/2);c.setAttribute("y",this.height-Blockly.FlyoutButton.MARGIN);this.updateTransform_();this.onMouseUpWrapper_=Blockly.bindEventWithChecks_(this.svgGroup_,"mouseup",this,this.onMouseUp_);return this.svgGroup_};Blockly.FlyoutButton.prototype.show=function(){this.updateTransform_();this.svgGroup_.setAttribute("display","block")};
|
||||
Blockly.FlyoutButton.prototype.updateTransform_=function(){this.svgGroup_.setAttribute("transform","translate("+this.position_.x+","+this.position_.y+")")};Blockly.FlyoutButton.prototype.moveTo=function(a,b){this.position_.x=a;this.position_.y=b;this.updateTransform_()};Blockly.FlyoutButton.prototype.getPosition=function(){return this.position_};Blockly.FlyoutButton.prototype.getTargetWorkspace=function(){return this.targetWorkspace_};
|
||||
Blockly.FlyoutButton.prototype.dispose=function(){this.onMouseUpWrapper_&&Blockly.unbindEvent_(this.onMouseUpWrapper_);this.svgGroup_&&(Blockly.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.workspace_=null};
|
||||
Blockly.FlyoutButton.prototype.onMouseUp_=function(a){(a=this.targetWorkspace_.getGesture(a))&&a.cancel();this.isLabel_&&this.callbackKey_?console.warn("Labels should not have callbacks. Label text: "+this.text_):this.isLabel_||this.callbackKey_&&this.targetWorkspace_.getButtonCallback(this.callbackKey_)?this.isLabel_||this.targetWorkspace_.getButtonCallback(this.callbackKey_)(this):console.warn("Buttons should have callbacks. Button text: "+this.text_)};Blockly.Flyout=function(a){a.getMetrics=this.getMetrics_.bind(this);a.setMetrics=this.setMetrics_.bind(this);this.workspace_=new Blockly.WorkspaceSvg(a);this.workspace_.isFlyout=!0;this.RTL=!!a.RTL;this.toolboxPosition_=a.toolboxPosition;this.eventWrappers_=[];this.mats_=[];this.buttons_=[];this.listeners_=[];this.permanentlyDisabled_=[]};Blockly.Flyout.prototype.autoClose=!0;Blockly.Flyout.prototype.isVisible_=!1;Blockly.Flyout.prototype.containerVisible_=!0;
|
||||
Blockly.Flyout.prototype.CORNER_RADIUS=8;Blockly.Flyout.prototype.MARGIN=Blockly.Flyout.prototype.CORNER_RADIUS;Blockly.Flyout.prototype.GAP_X=3*Blockly.Flyout.prototype.MARGIN;Blockly.Flyout.prototype.GAP_Y=3*Blockly.Flyout.prototype.MARGIN;Blockly.Flyout.prototype.SCROLLBAR_PADDING=2;Blockly.Flyout.prototype.width_=0;Blockly.Flyout.prototype.height_=0;Blockly.Flyout.prototype.dragAngleRange_=70;
|
||||
Blockly.FlyoutButton.prototype.onMouseUp_=function(a){(a=this.targetWorkspace_.getGesture(a))&&a.cancel();this.isLabel_&&this.callbackKey_?console.warn("Labels should not have callbacks. Label text: "+this.text_):this.isLabel_||this.callbackKey_&&this.targetWorkspace_.getButtonCallback(this.callbackKey_)?this.isLabel_||this.targetWorkspace_.getButtonCallback(this.callbackKey_)(this):console.warn("Buttons should have callbacks. Button text: "+this.text_)};Blockly.FlyoutCursor=function(){Blockly.FlyoutCursor.superClass_.constructor.call(this)};Blockly.utils.object.inherits(Blockly.FlyoutCursor,Blockly.Cursor);Blockly.FlyoutCursor.prototype.next=function(){if(!this.isMarker_){var a=this.getCurNode();if(!a)return null;(a=a.next())&&this.setLocation(a);return a}};Blockly.FlyoutCursor.prototype["in"]=function(){return null};
|
||||
Blockly.FlyoutCursor.prototype.prev=function(){if(!this.isMarker_){var a=this.getCurNode();if(!a)return null;(a=a.prev())&&this.setLocation(a);return a}};Blockly.FlyoutCursor.prototype.out=function(){return null};Blockly.Flyout=function(a){a.getMetrics=this.getMetrics_.bind(this);a.setMetrics=this.setMetrics_.bind(this);this.workspace_=new Blockly.WorkspaceSvg(a);this.workspace_.isFlyout=!0;this.workspace_.setCursor(new Blockly.FlyoutCursor);this.workspace_.setMarker(new Blockly.MarkerCursor);this.RTL=!!a.RTL;this.toolboxPosition_=a.toolboxPosition;this.eventWrappers_=[];this.mats_=[];this.buttons_=[];this.listeners_=[];this.permanentlyDisabled_=[]};Blockly.Flyout.prototype.autoClose=!0;
|
||||
Blockly.Flyout.prototype.isVisible_=!1;Blockly.Flyout.prototype.containerVisible_=!0;Blockly.Flyout.prototype.CORNER_RADIUS=8;Blockly.Flyout.prototype.MARGIN=Blockly.Flyout.prototype.CORNER_RADIUS;Blockly.Flyout.prototype.GAP_X=3*Blockly.Flyout.prototype.MARGIN;Blockly.Flyout.prototype.GAP_Y=3*Blockly.Flyout.prototype.MARGIN;Blockly.Flyout.prototype.SCROLLBAR_PADDING=2;Blockly.Flyout.prototype.width_=0;Blockly.Flyout.prototype.height_=0;Blockly.Flyout.prototype.dragAngleRange_=70;
|
||||
Blockly.Flyout.prototype.createDom=function(a){this.svgGroup_=Blockly.utils.dom.createSvgElement(a,{"class":"blocklyFlyout",style:"display: none"},null);this.svgBackground_=Blockly.utils.dom.createSvgElement("path",{"class":"blocklyFlyoutBackground"},this.svgGroup_);this.svgGroup_.appendChild(this.workspace_.createDom());return this.svgGroup_};
|
||||
Blockly.Flyout.prototype.init=function(a){this.targetWorkspace_=a;this.workspace_.targetWorkspace=a;this.scrollbar_=new Blockly.Scrollbar(this.workspace_,this.horizontalLayout_,!1,"blocklyFlyoutScrollbar");this.hide();Array.prototype.push.apply(this.eventWrappers_,Blockly.bindEventWithChecks_(this.svgGroup_,"wheel",this,this.wheel_));this.autoClose||(this.filterWrapper_=this.filterForCapacity_.bind(this),this.targetWorkspace_.addChangeListener(this.filterWrapper_));Array.prototype.push.apply(this.eventWrappers_,
|
||||
Blockly.bindEventWithChecks_(this.svgBackground_,"mousedown",this,this.onMouseDown_));this.workspace_.getGesture=this.targetWorkspace_.getGesture.bind(this.targetWorkspace_);this.workspace_.variableMap_=this.targetWorkspace_.getVariableMap();this.workspace_.createPotentialVariableMap()};
|
||||
@@ -1259,13 +1259,13 @@ f,d);Blockly.setTheme(c.theme);Blockly.user.keyMap.setKeyMap(c.keyMap);Blockly.i
|
||||
Blockly.createDom_=function(a,b){a.setAttribute("dir","LTR");Blockly.Component.setDefaultRightToLeft(b.RTL);Blockly.Css.inject(b.hasCss,b.pathToMedia);var c=Blockly.utils.dom.createSvgElement("svg",{xmlns:Blockly.utils.dom.SVG_NS,"xmlns:html":Blockly.utils.dom.HTML_NS,"xmlns:xlink":Blockly.utils.dom.XLINK_NS,version:"1.1","class":"blocklySvg"},a),d=Blockly.utils.dom.createSvgElement("defs",{},c),e=String(Math.random()).substring(2),f=Blockly.utils.dom.createSvgElement("filter",{id:"blocklyEmbossFilter"+
|
||||
e},d);Blockly.utils.dom.createSvgElement("feGaussianBlur",{"in":"SourceAlpha",stdDeviation:1,result:"blur"},f);var g=Blockly.utils.dom.createSvgElement("feSpecularLighting",{"in":"blur",surfaceScale:1,specularConstant:.5,specularExponent:10,"lighting-color":"white",result:"specOut"},f);Blockly.utils.dom.createSvgElement("fePointLight",{x:-5E3,y:-1E4,z:2E4},g);Blockly.utils.dom.createSvgElement("feComposite",{"in":"specOut",in2:"SourceAlpha",operator:"in",result:"specOut"},f);Blockly.utils.dom.createSvgElement("feComposite",
|
||||
{"in":"SourceGraphic",in2:"specOut",operator:"arithmetic",k1:0,k2:1,k3:1,k4:0},f);b.embossFilterId=f.id;f=Blockly.utils.dom.createSvgElement("pattern",{id:"blocklyDisabledPattern"+e,patternUnits:"userSpaceOnUse",width:10,height:10},d);Blockly.utils.dom.createSvgElement("rect",{width:10,height:10,fill:"#aaa"},f);Blockly.utils.dom.createSvgElement("path",{d:"M 0 0 L 10 10 M 10 0 L 0 10",stroke:"#cc0"},f);b.disabledPatternId=f.id;b.gridPattern=Blockly.Grid.createDom(e,b.gridOptions,d);return c};
|
||||
Blockly.createMainWorkspace_=function(a,b,c,d){b.parentWorkspace=null;var e=new Blockly.WorkspaceSvg(b,c,d);e.scale=b.zoomOptions.startScale;a.appendChild(e.createDom("blocklyMainBackground"));!b.hasCategories&&b.languageTree&&(c=e.addFlyout_("svg"),Blockly.utils.dom.insertAfter(c,a));b.hasTrashcan&&e.addTrashcan();b.zoomOptions&&b.zoomOptions.controls&&e.addZoomControls();Blockly.navigation.setCursor(e.cursor);Blockly.navigation.setMarker(e.marker);e.translate(0,0);Blockly.mainWorkspace=e;b.readOnly||
|
||||
e.isMovable()||e.addChangeListener(function(a){if(!e.isDragging()&&!e.isMovable()&&-1!=Blockly.Events.BUMP_EVENTS.indexOf(a.type)){var b=Object.create(null),c=e.getMetrics(),d=e.scale;b.RTL=e.RTL;b.viewLeft=c.viewLeft/d;b.viewTop=c.viewTop/d;b.viewRight=(c.viewLeft+c.viewWidth)/d;b.viewBottom=(c.viewTop+c.viewHeight)/d;e.isContentBounded()?(c=e.getBlocksBoundingBox(),b.contentLeft=c.left,b.contentTop=c.top,b.contentRight=c.right,b.contentBottom=c.bottom):(b.contentLeft=c.contentLeft/d,b.contentTop=
|
||||
c.contentTop/d,b.contentRight=(c.contentLeft+c.contentWidth)/d,b.contentBottom=(c.contentTop+c.contentHeight)/d);if(b.contentTop<b.viewTop||b.contentBottom>b.viewBottom||b.contentLeft<b.viewLeft||b.contentRight>b.viewRight){c=null;a&&(c=Blockly.Events.getGroup(),Blockly.Events.setGroup(a.group));switch(a.type){case Blockly.Events.BLOCK_CREATE:case Blockly.Events.BLOCK_MOVE:var f=e.getBlockById(a.blockId);f=f.getRootBlock();break;case Blockly.Events.COMMENT_CREATE:case Blockly.Events.COMMENT_MOVE:f=
|
||||
e.getCommentById(a.commentId)}if(f){d=f.getBoundingRectangle();d.height=d.bottom-d.top;d.width=d.right-d.left;var m=b.viewTop,n=b.viewBottom-d.height;n=Math.max(m,n);m=Blockly.utils.math.clamp(m,d.top,n)-d.top;n=b.viewLeft;var p=b.viewRight-d.width;b.RTL?n=Math.min(p,n):p=Math.max(n,p);b=Blockly.utils.math.clamp(n,d.left,p)-d.left;f.moveBy(b,m)}a&&(a.group||console.log("WARNING: Moved object in bounds but there was no event group. This may break undo."),Blockly.Events.setGroup(c))}}});Blockly.svgResize(e);
|
||||
Blockly.WidgetDiv.createDom();Blockly.DropDownDiv.createDom();Blockly.Tooltip.createDom();return e};
|
||||
Blockly.init_=function(a){var b=a.options,c=a.getParentSvg();Blockly.bindEventWithChecks_(c.parentNode,"contextmenu",null,function(a){Blockly.utils.isTargetInput(a)||a.preventDefault()});c=Blockly.bindEventWithChecks_(window,"resize",null,function(){Blockly.hideChaff(!0);Blockly.svgResize(a)});a.setResizeHandlerWrapper(c);Blockly.inject.bindDocumentEvents_();b.languageTree&&(a.toolbox_?a.toolbox_.init(a):a.flyout_&&(a.flyout_.init(a),a.flyout_.show(b.languageTree.childNodes),a.flyout_.scrollToStart()));
|
||||
c=Blockly.Scrollbar.scrollbarThickness;b.hasTrashcan&&(c=a.trashcan.init(c));b.zoomOptions&&b.zoomOptions.controls&&a.zoomControls_.init(c);b.moveOptions&&b.moveOptions.scrollbars?(a.scrollbar=new Blockly.ScrollbarPair(a),a.scrollbar.resize()):a.setMetrics({x:.5,y:.5});b.hasSounds&&Blockly.inject.loadSounds_(b.pathToMedia,a)};
|
||||
Blockly.createMainWorkspace_=function(a,b,c,d){b.parentWorkspace=null;var e=new Blockly.WorkspaceSvg(b,c,d);e.scale=b.zoomOptions.startScale;a.appendChild(e.createDom("blocklyMainBackground"));!b.hasCategories&&b.languageTree&&(c=e.addFlyout_("svg"),Blockly.utils.dom.insertAfter(c,a));b.hasTrashcan&&e.addTrashcan();b.zoomOptions&&b.zoomOptions.controls&&e.addZoomControls();e.translate(0,0);Blockly.mainWorkspace=e;b.readOnly||e.isMovable()||e.addChangeListener(function(a){if(!e.isDragging()&&!e.isMovable()&&
|
||||
-1!=Blockly.Events.BUMP_EVENTS.indexOf(a.type)){var b=Object.create(null),c=e.getMetrics(),d=e.scale;b.RTL=e.RTL;b.viewLeft=c.viewLeft/d;b.viewTop=c.viewTop/d;b.viewRight=(c.viewLeft+c.viewWidth)/d;b.viewBottom=(c.viewTop+c.viewHeight)/d;e.isContentBounded()?(c=e.getBlocksBoundingBox(),b.contentLeft=c.left,b.contentTop=c.top,b.contentRight=c.right,b.contentBottom=c.bottom):(b.contentLeft=c.contentLeft/d,b.contentTop=c.contentTop/d,b.contentRight=(c.contentLeft+c.contentWidth)/d,b.contentBottom=(c.contentTop+
|
||||
c.contentHeight)/d);if(b.contentTop<b.viewTop||b.contentBottom>b.viewBottom||b.contentLeft<b.viewLeft||b.contentRight>b.viewRight){c=null;a&&(c=Blockly.Events.getGroup(),Blockly.Events.setGroup(a.group));switch(a.type){case Blockly.Events.BLOCK_CREATE:case Blockly.Events.BLOCK_MOVE:var f=e.getBlockById(a.blockId);f=f.getRootBlock();break;case Blockly.Events.COMMENT_CREATE:case Blockly.Events.COMMENT_MOVE:f=e.getCommentById(a.commentId)}if(f){d=f.getBoundingRectangle();d.height=d.bottom-d.top;d.width=
|
||||
d.right-d.left;var m=b.viewTop,n=b.viewBottom-d.height;n=Math.max(m,n);m=Blockly.utils.math.clamp(m,d.top,n)-d.top;n=b.viewLeft;var p=b.viewRight-d.width;b.RTL?n=Math.min(p,n):p=Math.max(n,p);b=Blockly.utils.math.clamp(n,d.left,p)-d.left;f.moveBy(b,m)}a&&(a.group||console.log("WARNING: Moved object in bounds but there was no event group. This may break undo."),Blockly.Events.setGroup(c))}}});Blockly.svgResize(e);Blockly.WidgetDiv.createDom();Blockly.DropDownDiv.createDom();Blockly.Tooltip.createDom();
|
||||
return e};
|
||||
Blockly.init_=function(a){var b=a.options,c=a.getParentSvg();Blockly.bindEventWithChecks_(c.parentNode,"contextmenu",null,function(a){Blockly.utils.isTargetInput(a)||a.preventDefault()});c=Blockly.bindEventWithChecks_(window,"resize",null,function(){Blockly.hideChaff(!0);Blockly.svgResize(a)});a.setResizeHandlerWrapper(c);Blockly.inject.bindDocumentEvents_();b.languageTree&&(a.toolbox_?a.toolbox_.init(a):a.flyout_&&(a.flyout_.init(a),a.flyout_.show(b.languageTree.childNodes),a.flyout_.scrollToStart()));c=
|
||||
Blockly.Scrollbar.scrollbarThickness;b.hasTrashcan&&(c=a.trashcan.init(c));b.zoomOptions&&b.zoomOptions.controls&&a.zoomControls_.init(c);b.moveOptions&&b.moveOptions.scrollbars?(a.scrollbar=new Blockly.ScrollbarPair(a),a.scrollbar.resize()):a.setMetrics({x:.5,y:.5});b.hasSounds&&Blockly.inject.loadSounds_(b.pathToMedia,a)};
|
||||
Blockly.inject.bindDocumentEvents_=function(){Blockly.documentEventsBound_||(Blockly.bindEventWithChecks_(document,"scroll",null,function(){for(var a=Blockly.Workspace.getAll(),b=0,c;c=a[b];b++)c.updateInverseScreenCTM&&c.updateInverseScreenCTM()}),Blockly.bindEventWithChecks_(document,"keydown",null,Blockly.onKeyDown_),Blockly.bindEvent_(document,"touchend",null,Blockly.longStop_),Blockly.bindEvent_(document,"touchcancel",null,Blockly.longStop_),Blockly.utils.userAgent.IPAD&&Blockly.bindEventWithChecks_(window,
|
||||
"orientationchange",document,function(){Blockly.svgResize(Blockly.getMainWorkspace())}));Blockly.documentEventsBound_=!0};
|
||||
Blockly.inject.loadSounds_=function(a,b){var c=b.getAudioManager();c.load([a+"click.mp3",a+"click.wav",a+"click.ogg"],"click");c.load([a+"disconnect.wav",a+"disconnect.mp3",a+"disconnect.ogg"],"disconnect");c.load([a+"delete.mp3",a+"delete.ogg",a+"delete.wav"],"delete");var d=[],e=function(){for(;d.length;)Blockly.unbindEvent_(d.pop());c.preload()};d.push(Blockly.bindEventWithChecks_(document,"mousemove",null,e,!0));d.push(Blockly.bindEventWithChecks_(document,"touchstart",null,e,!0))};
|
||||
|
||||
@@ -69,7 +69,7 @@ goog.addDependency("../../../" + dir + "/core/field_number.js", ['Blockly.FieldN
|
||||
goog.addDependency("../../../" + dir + "/core/field_registry.js", ['Blockly.fieldRegistry'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/field_textinput.js", ['Blockly.FieldTextInput'], ['Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.Coordinate', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.Size', 'Blockly.utils.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/field_variable.js", ['Blockly.FieldVariable'], ['Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.fieldRegistry', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object', 'Blockly.utils.Size', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml']);
|
||||
goog.addDependency("../../../" + dir + "/core/flyout_base.js", ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutButton', 'Blockly.Gesture', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom', 'Blockly.WorkspaceSvg', 'Blockly.Xml']);
|
||||
goog.addDependency("../../../" + dir + "/core/flyout_base.js", ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutButton', 'Blockly.FlyoutCursor', 'Blockly.Gesture', 'Blockly.MarkerCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom', 'Blockly.WorkspaceSvg', 'Blockly.Xml']);
|
||||
goog.addDependency("../../../" + dir + "/core/flyout_button.js", ['Blockly.FlyoutButton'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']);
|
||||
goog.addDependency("../../../" + dir + "/core/flyout_dragger.js", ['Blockly.FlyoutDragger'], ['Blockly.utils.object', 'Blockly.WorkspaceDragger']);
|
||||
goog.addDependency("../../../" + dir + "/core/flyout_horizontal.js", ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.Flyout', 'Blockly.FlyoutButton', 'Blockly.utils', 'Blockly.utils.object', 'Blockly.utils.Rect']);
|
||||
@@ -85,8 +85,10 @@ goog.addDependency("../../../" + dir + "/core/keyboard_nav/action.js", ['Blockly
|
||||
goog.addDependency("../../../" + dir + "/core/keyboard_nav/ast_node.js", ['Blockly.ASTNode'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/keyboard_nav/cursor.js", ['Blockly.Cursor'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/keyboard_nav/cursor_svg.js", ['Blockly.CursorSvg'], ['Blockly.Cursor', 'Blockly.utils.object']);
|
||||
goog.addDependency("../../../" + dir + "/core/keyboard_nav/flyout_cursor.js", ['Blockly.FlyoutCursor'], ['Blockly.Cursor', 'Blockly.utils.object']);
|
||||
goog.addDependency("../../../" + dir + "/core/keyboard_nav/key_map.js", ['Blockly.user.keyMap'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']);
|
||||
goog.addDependency("../../../" + dir + "/core/keyboard_nav/navigation.js", ['Blockly.navigation'], ['Blockly.Action', 'Blockly.ASTNode', 'Blockly.user.keyMap']);
|
||||
goog.addDependency("../../../" + dir + "/core/keyboard_nav/marker_cursor.js", ['Blockly.MarkerCursor'], ['Blockly.Cursor', 'Blockly.utils.object']);
|
||||
goog.addDependency("../../../" + dir + "/core/keyboard_nav/navigation.js", ['Blockly.navigation'], ['Blockly.Action', 'Blockly.ASTNode', 'Blockly.utils.Coordinate', 'Blockly.user.keyMap']);
|
||||
goog.addDependency("../../../" + dir + "/core/msg.js", ['Blockly.Msg'], []);
|
||||
goog.addDependency("../../../" + dir + "/core/mutator.js", ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.Ui', 'Blockly.Icon', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.global', 'Blockly.utils.object', 'Blockly.utils.xml', 'Blockly.WorkspaceSvg', 'Blockly.Xml']);
|
||||
goog.addDependency("../../../" + dir + "/core/names.js", ['Blockly.Names'], ['Blockly.Msg']);
|
||||
@@ -153,7 +155,7 @@ goog.addDependency("../../../" + dir + "/core/variables.js", ['Blockly.Variables
|
||||
goog.addDependency("../../../" + dir + "/core/variables_dynamic.js", ['Blockly.VariablesDynamic'], ['Blockly.Variables', 'Blockly.Blocks', 'Blockly.Msg', 'Blockly.utils.xml', 'Blockly.VariableModel', 'Blockly.Xml']);
|
||||
goog.addDependency("../../../" + dir + "/core/warning.js", ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.Ui', 'Blockly.Icon', 'Blockly.utils.dom', 'Blockly.utils.object']);
|
||||
goog.addDependency("../../../" + dir + "/core/widgetdiv.js", ['Blockly.WidgetDiv'], ['Blockly.Css', 'Blockly.utils.style']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace.js", ['Blockly.Workspace'], ['Blockly.Cursor', 'Blockly.Events', 'Blockly.Themes.Classic', 'Blockly.utils', 'Blockly.utils.math', 'Blockly.VariableMap', 'Blockly.WorkspaceComment']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace.js", ['Blockly.Workspace'], ['Blockly.Cursor', 'Blockly.MarkerCursor', 'Blockly.Events', 'Blockly.Themes.Classic', 'Blockly.utils', 'Blockly.utils.math', 'Blockly.VariableMap', 'Blockly.WorkspaceComment']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace_audio.js", ['Blockly.WorkspaceAudio'], ['Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace_comment.js", ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']);
|
||||
goog.addDependency("../../../" + dir + "/core/workspace_comment_render_svg.js", ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom', 'Blockly.WorkspaceCommentSvg']);
|
||||
@@ -227,6 +229,7 @@ goog.require('Blockly.FieldTextInput');
|
||||
goog.require('Blockly.FieldVariable');
|
||||
goog.require('Blockly.Flyout');
|
||||
goog.require('Blockly.FlyoutButton');
|
||||
goog.require('Blockly.FlyoutCursor');
|
||||
goog.require('Blockly.FlyoutDragger');
|
||||
goog.require('Blockly.Generator');
|
||||
goog.require('Blockly.Gesture');
|
||||
@@ -235,6 +238,7 @@ goog.require('Blockly.HorizontalFlyout');
|
||||
goog.require('Blockly.Icon');
|
||||
goog.require('Blockly.Input');
|
||||
goog.require('Blockly.InsertionMarkerManager');
|
||||
goog.require('Blockly.MarkerCursor');
|
||||
goog.require('Blockly.Menu');
|
||||
goog.require('Blockly.MenuItem');
|
||||
goog.require('Blockly.Msg');
|
||||
|
||||
@@ -31,7 +31,9 @@ goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.BlockCreate');
|
||||
goog.require('Blockly.Events.VarCreate');
|
||||
goog.require('Blockly.FlyoutButton');
|
||||
goog.require('Blockly.FlyoutCursor');
|
||||
goog.require('Blockly.Gesture');
|
||||
goog.require('Blockly.MarkerCursor');
|
||||
goog.require('Blockly.Tooltip');
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.utils');
|
||||
@@ -56,6 +58,8 @@ Blockly.Flyout = function(workspaceOptions) {
|
||||
*/
|
||||
this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions);
|
||||
this.workspace_.isFlyout = true;
|
||||
this.workspace_.setCursor(new Blockly.FlyoutCursor());
|
||||
this.workspace_.setMarker(new Blockly.MarkerCursor());
|
||||
|
||||
/**
|
||||
* Is RTL vs LTR.
|
||||
|
||||
@@ -769,7 +769,7 @@ Blockly.Gesture.prototype.doWorkspaceClick_ = function(e) {
|
||||
var screenCoord = new Blockly.utils.Coordinate(e.clientX, e.clientY);
|
||||
var wsCoord = Blockly.utils.screenToWsCoordinates(ws, screenCoord);
|
||||
var wsNode = Blockly.ASTNode.createWorkspaceNode(ws, wsCoord);
|
||||
ws.cursor.setLocation(wsNode);
|
||||
ws.getCursor().setLocation(wsNode);
|
||||
} else if (Blockly.selected) {
|
||||
Blockly.selected.unselect();
|
||||
}
|
||||
|
||||
@@ -232,9 +232,6 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface,
|
||||
mainWorkspace.addZoomControls();
|
||||
}
|
||||
|
||||
Blockly.navigation.setCursor(mainWorkspace.cursor);
|
||||
Blockly.navigation.setMarker(mainWorkspace.marker);
|
||||
|
||||
// A null translation will also apply the correct initial scale.
|
||||
mainWorkspace.translate(0, 0);
|
||||
Blockly.mainWorkspace = mainWorkspace;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
/**
|
||||
* @fileoverview The class representing a cursor.
|
||||
* Used primarily for keyboard navigation.
|
||||
* @author aschmiedt@google.com (Abby Schmiedt)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
@@ -29,39 +30,39 @@ goog.provide('Blockly.Cursor');
|
||||
|
||||
/**
|
||||
* Class for a cursor.
|
||||
* @param {boolean=} opt_marker True if the cursor is a marker. A marker is used
|
||||
* to save a location and is an immovable cursor. False or undefined if the
|
||||
* cursor is not a marker.
|
||||
* A cursor controls how a user navigates the Blockly AST.
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.Cursor = function(opt_marker) {
|
||||
Blockly.Cursor = function() {
|
||||
/*
|
||||
* The current location of the cursor.
|
||||
* @type {Blockly.Field|Blockly.Connection|Blockly.Block}
|
||||
* @type {Blockly.ASTNode}
|
||||
* @private
|
||||
*/
|
||||
this.curNode_ = null;
|
||||
|
||||
/**
|
||||
* Whether or not the cursor is a marker.
|
||||
* @type {boolean} True if the cursor is a marker. False otherwise.
|
||||
* The object in charge of drawing the visual representation of the current node.
|
||||
* @type {Blockly.CursorSvg}
|
||||
* @private
|
||||
*/
|
||||
this.isMarker_ = !!opt_marker;
|
||||
this.drawer_ = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Object holding different types for a cursor.
|
||||
* Sets the object in charge of drawing the cursor.
|
||||
* @param {Blockly.CursorSvg} drawer The object in charge of drawing the cursor.
|
||||
*/
|
||||
Blockly.Cursor.prototype.types = {
|
||||
FIELD: 'field',
|
||||
BLOCK: 'block',
|
||||
INPUT: 'input',
|
||||
OUTPUT: 'output',
|
||||
NEXT: 'next',
|
||||
PREVIOUS: 'previous',
|
||||
STACK: 'stack',
|
||||
WORKSPACE: 'workspace'
|
||||
Blockly.Cursor.prototype.setDrawer = function(drawer) {
|
||||
this.drawer_ = drawer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the current drawer for the cursor.
|
||||
* @return {Blockly.CursorSvg} The object in charge of drawing the cursor.
|
||||
*/
|
||||
Blockly.Cursor.prototype.getDrawer = function() {
|
||||
return this.drawer_;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -81,20 +82,19 @@ Blockly.Cursor.prototype.getCurNode = function() {
|
||||
*/
|
||||
Blockly.Cursor.prototype.setLocation = function(newNode) {
|
||||
this.curNode_ = newNode;
|
||||
this.update_();
|
||||
if (this.drawer_) {
|
||||
this.drawer_.draw(this.getCurNode());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update method to be overwritten in cursor_svg.
|
||||
* @protected
|
||||
* Hide the cursor svg.
|
||||
*/
|
||||
Blockly.Cursor.prototype.update_ = function() {};
|
||||
|
||||
/**
|
||||
* Hide method to be overwritten in cursor_svg.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.Cursor.prototype.hide = function() {};
|
||||
Blockly.Cursor.prototype.hide = function() {
|
||||
if (this.drawer_) {
|
||||
this.drawer_.hide();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the next connection, field, or block.
|
||||
|
||||
@@ -32,20 +32,37 @@ goog.require('Blockly.utils.object');
|
||||
|
||||
/**
|
||||
* Class for a cursor.
|
||||
* @param {!Blockly.Workspace} workspace The workspace to sit in.
|
||||
* @param {!Blockly.Workspace} workspace The workspace the cursor belongs to.
|
||||
* @param {boolean=} opt_marker True if the cursor is a marker. A marker is used
|
||||
* to save a location and is an immovable cursor. False or undefined if the
|
||||
* cursor is not a marker.
|
||||
* @extends {Blockly.Cursor}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.CursorSvg = function(workspace, opt_marker) {
|
||||
Blockly.CursorSvg.superClass_.constructor.call(this, opt_marker);
|
||||
/**
|
||||
* The workspace the cursor belongs to.
|
||||
* @type {!Blockly.Workspace}
|
||||
* @private
|
||||
*/
|
||||
this.workspace_ = workspace;
|
||||
this.constants = new Blockly.blockRendering.ConstantProvider();
|
||||
this.constants.init();
|
||||
|
||||
/**
|
||||
* True if the cursor should be drawn as a marker, false otherwise.
|
||||
* A marker is drawn as a solid blue line, while the cursor is drawns as a
|
||||
* flashing red one.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.isMarker_ = opt_marker;
|
||||
|
||||
/**
|
||||
* The constants necessary to draw the cursor.
|
||||
* @type {Blockly.blockRendering.ConstantProvider}
|
||||
* @private
|
||||
*/
|
||||
this.constants_ = new Blockly.blockRendering.ConstantProvider();
|
||||
this.constants_.init();
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.CursorSvg, Blockly.Cursor);
|
||||
|
||||
/**
|
||||
* Height of the horizontal cursor.
|
||||
@@ -181,11 +198,11 @@ Blockly.CursorSvg.prototype.setParent_ = function(newParent) {
|
||||
|
||||
/**
|
||||
* Show the cursor using coordinates.
|
||||
* @param {!Blockly.ASTNode} curNode The node that we want to draw the cursor for.
|
||||
* @private
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.showWithCoordinates_ = function() {
|
||||
var workspaceNode = this.getCurNode();
|
||||
var wsCoordinate = workspaceNode.getWsCoordinate();
|
||||
Blockly.CursorSvg.prototype.showWithCoordinates_ = function(curNode) {
|
||||
var wsCoordinate = curNode.getWsCoordinate();
|
||||
this.currentCursorSvg = this.cursorSvgLine_;
|
||||
this.setParent_(this.workspace_.svgBlockCanvas_);
|
||||
this.positionLine_(wsCoordinate.x, wsCoordinate.y,
|
||||
@@ -194,11 +211,12 @@ Blockly.CursorSvg.prototype.showWithCoordinates_ = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the cursor using a block
|
||||
* Show the cursor using a block.
|
||||
* @param {!Blockly.ASTNode} curNode The node that we want to draw the cursor for.
|
||||
* @private
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.showWithBlock_ = function() {
|
||||
var block = this.getCurNode().getLocation();
|
||||
Blockly.CursorSvg.prototype.showWithBlock_ = function(curNode) {
|
||||
var block = curNode.getLocation();
|
||||
|
||||
this.currentCursorSvg = this.cursorSvgRect_;
|
||||
this.setParent_(block.getSvgRoot());
|
||||
@@ -207,15 +225,16 @@ Blockly.CursorSvg.prototype.showWithBlock_ = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the cursor using a connection with input or output type
|
||||
* Show the cursor using a connection with input or output type.
|
||||
* @param {!Blockly.ASTNode} curNode The node that we want to draw the cursor for.
|
||||
* @private
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.showWithInputOutput_ = function() {
|
||||
Blockly.CursorSvg.prototype.showWithInputOutput_ = function(curNode) {
|
||||
var connection = /** @type {Blockly.Connection} */
|
||||
(this.getCurNode().getLocation());
|
||||
(curNode.getLocation());
|
||||
this.currentCursorSvg = this.cursorInputOutput_;
|
||||
var path = Blockly.utils.svgPaths.moveTo(0, 0) +
|
||||
this.constants.shapeFor(connection).pathDown;
|
||||
this.constants_.shapeFor(connection).pathDown;
|
||||
this.cursorInputOutput_.setAttribute('d', path);
|
||||
this.setParent_(connection.getSourceBlock().getSvgRoot());
|
||||
this.positionInputOutput_(connection);
|
||||
@@ -223,11 +242,12 @@ Blockly.CursorSvg.prototype.showWithInputOutput_ = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the cursor using a next connection
|
||||
* Show the cursor using a next connection.
|
||||
* @param {!Blockly.ASTNode} curNode The node that we want to draw the cursor for.
|
||||
* @private
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.showWithNext_ = function() {
|
||||
var connection = this.getCurNode().getLocation();
|
||||
Blockly.CursorSvg.prototype.showWithNext_ = function(curNode) {
|
||||
var connection = curNode.getLocation();
|
||||
var targetBlock = connection.getSourceBlock();
|
||||
var x = 0;
|
||||
var y = connection.getOffsetInBlock().y;
|
||||
@@ -241,10 +261,11 @@ Blockly.CursorSvg.prototype.showWithNext_ = function() {
|
||||
|
||||
/**
|
||||
* Show the cursor using a previous connection.
|
||||
* @param {!Blockly.ASTNode} curNode The node that we want to draw the cursor for.
|
||||
* @private
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.showWithPrev_ = function() {
|
||||
var connection = this.getCurNode().getLocation();
|
||||
Blockly.CursorSvg.prototype.showWithPrev_ = function(curNode) {
|
||||
var connection = curNode.getLocation();
|
||||
var targetBlock = connection.getSourceBlock();
|
||||
var width = targetBlock.getHeightWidth().width;
|
||||
|
||||
@@ -256,10 +277,11 @@ Blockly.CursorSvg.prototype.showWithPrev_ = function() {
|
||||
|
||||
/**
|
||||
* Show the cursor using a field.
|
||||
* @param {!Blockly.ASTNode} curNode The node that we want to draw the cursor for.
|
||||
* @private
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.showWithField_ = function() {
|
||||
var field = this.getCurNode().getLocation();
|
||||
Blockly.CursorSvg.prototype.showWithField_ = function(curNode) {
|
||||
var field = curNode.getLocation();
|
||||
var width = field.borderRect_.width.baseVal.value;
|
||||
var height = field.borderRect_.height.baseVal.value;
|
||||
|
||||
@@ -271,10 +293,11 @@ Blockly.CursorSvg.prototype.showWithField_ = function() {
|
||||
|
||||
/**
|
||||
* Show the cursor using a stack.
|
||||
* @param {!Blockly.ASTNode} curNode The node that we want to draw the cursor for.
|
||||
* @private
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.showWithStack_ = function() {
|
||||
var block = this.getCurNode().getLocation();
|
||||
Blockly.CursorSvg.prototype.showWithStack_ = function(curNode) {
|
||||
var block = curNode.getLocation();
|
||||
|
||||
// Gets the height and width of entire stack.
|
||||
var heightWidth = block.getHeightWidth();
|
||||
@@ -361,30 +384,30 @@ Blockly.CursorSvg.prototype.hide = function() {
|
||||
|
||||
/**
|
||||
* Update the cursor.
|
||||
* @param {!Blockly.ASTNode} curNode The node that we want to draw the cursor for.
|
||||
* @package
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.update_ = function() {
|
||||
if (!this.getCurNode()) {
|
||||
Blockly.CursorSvg.prototype.draw = function(curNode) {
|
||||
if (!curNode) {
|
||||
return;
|
||||
}
|
||||
var curNode = this.getCurNode();
|
||||
if (curNode.getType() === Blockly.ASTNode.types.BLOCK) {
|
||||
this.showWithBlock_();
|
||||
//This needs to be the location type because next connections can be input
|
||||
//type but they need to draw like they are a next statement
|
||||
this.showWithBlock_(curNode);
|
||||
// This needs to be the location type because next connections can be input
|
||||
// type but they need to draw like they are a next statement
|
||||
} else if (curNode.getLocation().type === Blockly.INPUT_VALUE ||
|
||||
curNode.getType() === Blockly.ASTNode.types.OUTPUT) {
|
||||
this.showWithInputOutput_();
|
||||
this.showWithInputOutput_(curNode);
|
||||
} else if (curNode.getLocation().type === Blockly.NEXT_STATEMENT) {
|
||||
this.showWithNext_();
|
||||
this.showWithNext_(curNode);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.PREVIOUS) {
|
||||
this.showWithPrev_();
|
||||
this.showWithPrev_(curNode);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.FIELD) {
|
||||
this.showWithField_();
|
||||
this.showWithField_(curNode);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.WORKSPACE) {
|
||||
this.showWithCoordinates_();
|
||||
this.showWithCoordinates_(curNode);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.STACK) {
|
||||
this.showWithStack_();
|
||||
this.showWithStack_(curNode);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -470,58 +493,6 @@ Blockly.CursorSvg.prototype.createCursorSvg_ = function() {
|
||||
return this.cursorSvg_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the next connection, field, or block.
|
||||
* Does nothing if this cursor is an immovable marker.
|
||||
* @return {Blockly.ASTNode} The next element, or null if the current node is
|
||||
* not set or there is no next value.
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.next = function() {
|
||||
if (this.isMarker_) {
|
||||
return null;
|
||||
}
|
||||
return Blockly.CursorSvg.superClass_.next.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the in connection or field.
|
||||
* Does nothing if this cursor is an immovable marker.
|
||||
* @return {Blockly.ASTNode} The in element, or null if the current node is
|
||||
* not set or there is no in value.
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.in = function() {
|
||||
if (this.isMarker_) {
|
||||
return null;
|
||||
}
|
||||
return Blockly.CursorSvg.superClass_.in.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the previous connection, field, or block.
|
||||
* Does nothing if this cursor is an immovable marker.
|
||||
* @return {Blockly.ASTNode} The previous element, or null if the current node
|
||||
* is not set or there is no previous value.
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.prev = function() {
|
||||
if (this.isMarker_) {
|
||||
return null;
|
||||
}
|
||||
return Blockly.CursorSvg.superClass_.prev.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the out connection, field, or block.
|
||||
* Does nothing if this cursor is an immovable marker.
|
||||
* @return {Blockly.ASTNode} The out element, or null if the current node is
|
||||
* not set or there is no out value.
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.out = function() {
|
||||
if (this.isMarker_) {
|
||||
return null;
|
||||
}
|
||||
return Blockly.CursorSvg.superClass_.out.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispose of this cursor.
|
||||
*/
|
||||
|
||||
103
core/keyboard_nav/flyout_cursor.js
Normal file
103
core/keyboard_nav/flyout_cursor.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2019 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview The class representing a cursor used to navigate the flyout.
|
||||
* Used primarily for keyboard navigation.
|
||||
* @author aschmiedt@google.com (Abby Schmiedt)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.FlyoutCursor');
|
||||
|
||||
goog.require('Blockly.Cursor');
|
||||
goog.require('Blockly.utils.object');
|
||||
|
||||
|
||||
/**
|
||||
* Class for a flyout cursor.
|
||||
* This controls how a user navigates blocks in the flyout.
|
||||
* @constructor
|
||||
* @extends {Blockly.Cursor}
|
||||
*/
|
||||
Blockly.FlyoutCursor = function() {
|
||||
Blockly.FlyoutCursor.superClass_.constructor.call(this);
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.FlyoutCursor, Blockly.Cursor);
|
||||
|
||||
/**
|
||||
* Find the next connection, field, or block.
|
||||
* @return {Blockly.ASTNode} The next element, or null if the current node is
|
||||
* not set or there is no next value.
|
||||
* @override
|
||||
*/
|
||||
Blockly.FlyoutCursor.prototype.next = function() {
|
||||
if (!this.isMarker_) {
|
||||
var curNode = this.getCurNode();
|
||||
if (!curNode) {
|
||||
return null;
|
||||
}
|
||||
var newNode = curNode.next();
|
||||
|
||||
if (newNode) {
|
||||
this.setLocation(newNode);
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a no-op since a flyout cursor can not go in.
|
||||
* @return {null} Always null.
|
||||
* @override
|
||||
*/
|
||||
Blockly.FlyoutCursor.prototype.in = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the previous connection, field, or block.
|
||||
* @return {Blockly.ASTNode} The previous element, or null if the current node
|
||||
* is not set or there is no previous value.
|
||||
* @override
|
||||
*/
|
||||
Blockly.FlyoutCursor.prototype.prev = function() {
|
||||
if (!this.isMarker_) {
|
||||
var curNode = this.getCurNode();
|
||||
if (!curNode) {
|
||||
return null;
|
||||
}
|
||||
var newNode = curNode.prev();
|
||||
|
||||
if (newNode) {
|
||||
this.setLocation(newNode);
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a no-op since a flyout cursor can not go out.
|
||||
* @return {null} Always null.
|
||||
* @override
|
||||
*/
|
||||
Blockly.FlyoutCursor.prototype.out = function() {
|
||||
return null;
|
||||
};
|
||||
79
core/keyboard_nav/marker_cursor.js
Normal file
79
core/keyboard_nav/marker_cursor.js
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2019 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview The class representing a cursor used for marking a location.
|
||||
* Used primarily for keyboard navigation.
|
||||
* @author aschmiedt@google.com (Abby Schmiedt)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.MarkerCursor');
|
||||
|
||||
goog.require('Blockly.Cursor');
|
||||
goog.require('Blockly.utils.object');
|
||||
|
||||
|
||||
/**
|
||||
* Class for a marker.
|
||||
* This is used in keyboard navigation to save a location in the Blockly AST.
|
||||
* @constructor
|
||||
* @extends {Blockly.Cursor}
|
||||
*/
|
||||
Blockly.MarkerCursor = function() {
|
||||
Blockly.MarkerCursor.superClass_.constructor.call(this);
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.MarkerCursor, Blockly.Cursor);
|
||||
|
||||
/**
|
||||
* This is a no-op since markers do not move.
|
||||
* @return {null} Always null.
|
||||
* @override
|
||||
*/
|
||||
Blockly.MarkerCursor.prototype.next = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a no-op since markers do not move.
|
||||
* @return {null} Always null.
|
||||
* @override
|
||||
*/
|
||||
Blockly.MarkerCursor.prototype.in = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a no-op since markers do not move.
|
||||
* @return {null} Always null.
|
||||
* @override
|
||||
*/
|
||||
Blockly.MarkerCursor.prototype.prev = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a no-op since markers do not move.
|
||||
* @return {null} Always null.
|
||||
* @override
|
||||
*/
|
||||
Blockly.MarkerCursor.prototype.out = function() {
|
||||
return null;
|
||||
};
|
||||
@@ -18,26 +18,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview The class in charge of handling actions related to keyboard
|
||||
* navigation.
|
||||
* @author aschmiedt@google.com (Abby Schmiedt)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.navigation');
|
||||
|
||||
goog.require('Blockly.Action');
|
||||
goog.require('Blockly.ASTNode');
|
||||
goog.require('Blockly.utils.Coordinate');
|
||||
goog.require('Blockly.user.keyMap');
|
||||
|
||||
|
||||
/**
|
||||
* The cursor for keyboard navigation.
|
||||
* @type {Blockly.Cursor}
|
||||
* @private
|
||||
*/
|
||||
Blockly.navigation.cursor_ = null;
|
||||
|
||||
/**
|
||||
* The marker that shows where a user has marked while navigating blocks.
|
||||
* @type {!Blockly.Cursor}
|
||||
*/
|
||||
Blockly.navigation.marker_ = null;
|
||||
|
||||
/**
|
||||
* The current selected category if the toolbox is open or
|
||||
* last selected category if focus is on a different element.
|
||||
@@ -46,13 +41,6 @@ Blockly.navigation.marker_ = null;
|
||||
*/
|
||||
Blockly.navigation.currentCategory_ = null;
|
||||
|
||||
/**
|
||||
* The current selected block in the flyout.
|
||||
* @type {Blockly.BlockSvg}
|
||||
* @private
|
||||
*/
|
||||
Blockly.navigation.flyoutBlock_ = null;
|
||||
|
||||
/**
|
||||
* A function to call to give feedback to the user about logs, warnings, and
|
||||
* errors. You can override this to customize feedback (e.g. warning sounds,
|
||||
@@ -108,33 +96,14 @@ Blockly.navigation.actionNames = {
|
||||
EXIT: 'exit',
|
||||
TOGGLE_KEYBOARD_NAV: 'toggle_keyboard_nav'
|
||||
};
|
||||
/**
|
||||
* Set the navigation cursor.
|
||||
* @param {Blockly.Cursor} cursor The cursor to navigate through blocks on a
|
||||
* workspace.
|
||||
* @package
|
||||
*/
|
||||
Blockly.navigation.setCursor = function(cursor) {
|
||||
Blockly.navigation.cursor_ = cursor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the navigation marker.
|
||||
* @param {Blockly.CursorSvg} marker The marker that shows where a user has
|
||||
* marked while navigating blocks.
|
||||
* @package
|
||||
*/
|
||||
Blockly.navigation.setMarker = function(marker) {
|
||||
Blockly.navigation.marker_ = marker;
|
||||
};
|
||||
|
||||
/**
|
||||
* Move the marker to the cursor's current location.
|
||||
* @package
|
||||
*/
|
||||
Blockly.navigation.markAtCursor = function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
Blockly.navigation.cursor_.getCurNode());
|
||||
Blockly.getMainWorkspace().getMarker().setLocation(
|
||||
Blockly.getMainWorkspace().getCursor().getCurNode());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -142,15 +111,15 @@ Blockly.navigation.markAtCursor = function() {
|
||||
* @package
|
||||
*/
|
||||
Blockly.navigation.removeMark = function() {
|
||||
Blockly.navigation.marker_.setLocation(null);
|
||||
Blockly.navigation.marker_.hide();
|
||||
Blockly.getMainWorkspace().getMarker().setLocation(null);
|
||||
Blockly.getMainWorkspace().getMarker().hide();
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the top node on a block.
|
||||
* This is either the previous connection, output connection or the block.
|
||||
* @param {Blockly.Block} block The block to find the top most ast node on.
|
||||
* @return {Blockly.ASTNode} The ast node holding the top most node on the
|
||||
* @param {Blockly.Block} block The block to find the top most AST node on.
|
||||
* @return {Blockly.ASTNode} The AST node holding the top most node on the
|
||||
* block.
|
||||
* @package
|
||||
*/
|
||||
@@ -181,7 +150,7 @@ Blockly.navigation.focusToolbox = function() {
|
||||
var workspace = Blockly.getMainWorkspace();
|
||||
var toolbox = workspace.getToolbox();
|
||||
|
||||
if (!Blockly.navigation.marker_.getCurNode()) {
|
||||
if (!Blockly.getMainWorkspace().getMarker().getCurNode()) {
|
||||
Blockly.navigation.markAtCursor();
|
||||
}
|
||||
if (workspace && !Blockly.navigation.currentCategory_) {
|
||||
@@ -282,10 +251,9 @@ Blockly.navigation.focusFlyout = function() {
|
||||
Blockly.navigation.currentState_ = Blockly.navigation.STATE_FLYOUT;
|
||||
var workspace = Blockly.getMainWorkspace();
|
||||
var toolbox = workspace.getToolbox();
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
var flyout = toolbox ? toolbox.flyout_ : workspace.getFlyout();
|
||||
|
||||
if (!Blockly.navigation.marker_.getCurNode()) {
|
||||
if (!Blockly.getMainWorkspace().getMarker().getCurNode()) {
|
||||
Blockly.navigation.markAtCursor();
|
||||
}
|
||||
|
||||
@@ -293,74 +261,25 @@ Blockly.navigation.focusFlyout = function() {
|
||||
var topBlocks = flyout.getWorkspace().getTopBlocks();
|
||||
if (topBlocks.length > 0) {
|
||||
topBlock = topBlocks[0];
|
||||
Blockly.navigation.flyoutBlock_ = topBlock;
|
||||
var astNode = Blockly.ASTNode.createBlockNode(Blockly.navigation.flyoutBlock_);
|
||||
cursor.setLocation(astNode);
|
||||
var astNode = Blockly.ASTNode.createStackNode(topBlock);
|
||||
Blockly.navigation.getFlyoutCursor_().setLocation(astNode);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Select the next block in the flyout.
|
||||
* Get the cursor from the flyouts workspace.
|
||||
* @return {Blockly.FlyoutCursor} The flyouts cursor or null if no flyout exists.
|
||||
*/
|
||||
Blockly.navigation.selectNextBlockInFlyout = function() {
|
||||
if (!Blockly.navigation.flyoutBlock_) {
|
||||
return;
|
||||
}
|
||||
var blocks = Blockly.navigation.getFlyoutBlocks_();
|
||||
var curBlock = Blockly.navigation.flyoutBlock_;
|
||||
var curIdx = blocks.indexOf(curBlock);
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
var nextBlock;
|
||||
|
||||
if (curIdx > -1 && blocks[++curIdx]) {
|
||||
nextBlock = blocks[curIdx];
|
||||
}
|
||||
|
||||
if (nextBlock) {
|
||||
Blockly.navigation.flyoutBlock_ = nextBlock;
|
||||
var astNode = Blockly.ASTNode.createBlockNode(nextBlock);
|
||||
cursor.setLocation(astNode);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Select the previous block in the flyout.
|
||||
*/
|
||||
Blockly.navigation.selectPreviousBlockInFlyout = function() {
|
||||
if (!Blockly.navigation.flyoutBlock_) {
|
||||
return;
|
||||
}
|
||||
var blocks = Blockly.navigation.getFlyoutBlocks_();
|
||||
var curBlock = Blockly.navigation.flyoutBlock_;
|
||||
var curIdx = blocks.indexOf(curBlock);
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
var prevBlock;
|
||||
|
||||
if (curIdx > -1 && blocks[--curIdx]) {
|
||||
prevBlock = blocks[curIdx];
|
||||
}
|
||||
|
||||
if (prevBlock) {
|
||||
Blockly.navigation.flyoutBlock_ = prevBlock;
|
||||
var astNode = Blockly.ASTNode.createBlockNode(prevBlock);
|
||||
cursor.setLocation(astNode);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a list of all blocks in the flyout.
|
||||
* @return {!Array<Blockly.BlockSvg>} List of blocks in the flyout.
|
||||
*/
|
||||
Blockly.navigation.getFlyoutBlocks_ = function() {
|
||||
Blockly.navigation.getFlyoutCursor_ = function() {
|
||||
var workspace = Blockly.getMainWorkspace();
|
||||
var toolbox = workspace.getToolbox();
|
||||
var topBlocks = [];
|
||||
var flyout = toolbox ? toolbox.flyout_ : workspace.getFlyout();
|
||||
if (flyout && flyout.getWorkspace()) {
|
||||
topBlocks = flyout.getWorkspace().getTopBlocks();
|
||||
var cursor = null;
|
||||
if (workspace.rendered) {
|
||||
var toolbox = workspace.getToolbox();
|
||||
var flyout = toolbox ? toolbox.flyout_ : workspace.getFlyout();
|
||||
cursor = flyout ? flyout.workspace_.getCursor() : null;
|
||||
}
|
||||
return topBlocks;
|
||||
return cursor;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -369,7 +288,6 @@ Blockly.navigation.getFlyoutBlocks_ = function() {
|
||||
* it on the workspace.
|
||||
*/
|
||||
Blockly.navigation.insertFromFlyout = function() {
|
||||
|
||||
var flyout = Blockly.getMainWorkspace().getFlyout();
|
||||
if (!flyout || !flyout.isVisible()) {
|
||||
Blockly.navigation.warn('Trying to insert from the flyout when the flyout does not ' +
|
||||
@@ -377,21 +295,22 @@ Blockly.navigation.insertFromFlyout = function() {
|
||||
return;
|
||||
}
|
||||
|
||||
var newBlock = flyout.createBlock(Blockly.navigation.flyoutBlock_);
|
||||
var newBlock = flyout.createBlock(
|
||||
Blockly.navigation.getFlyoutCursor_().getCurNode().getLocation());
|
||||
// Render to get the sizing right.
|
||||
newBlock.render();
|
||||
// Connections are hidden when the block is first created. Normally there's
|
||||
// enough time for them to become unhidden in the user's mouse movements,
|
||||
// but not here.
|
||||
newBlock.setConnectionsHidden(false);
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
Blockly.getMainWorkspace().getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(newBlock));
|
||||
if (!Blockly.navigation.modify_()) {
|
||||
Blockly.navigation.warn('Something went wrong while inserting a block from the flyout.');
|
||||
}
|
||||
|
||||
Blockly.navigation.focusWorkspace();
|
||||
Blockly.navigation.cursor_.setLocation(Blockly.navigation.getTopNode(newBlock));
|
||||
Blockly.getMainWorkspace().getCursor().setLocation(Blockly.navigation.getTopNode(newBlock));
|
||||
Blockly.navigation.removeMark();
|
||||
};
|
||||
|
||||
@@ -400,11 +319,11 @@ Blockly.navigation.insertFromFlyout = function() {
|
||||
* @param {boolean} shouldHide True if the flyout should be hidden.
|
||||
*/
|
||||
Blockly.navigation.resetFlyout = function(shouldHide) {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
Blockly.navigation.flyoutBlock_ = null;
|
||||
cursor.hide();
|
||||
if (shouldHide) {
|
||||
cursor.workspace_.getFlyout().hide();
|
||||
if (Blockly.navigation.getFlyoutCursor_()) {
|
||||
Blockly.navigation.getFlyoutCursor_().hide();
|
||||
if (shouldHide) {
|
||||
Blockly.getMainWorkspace().getFlyout().hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -419,8 +338,8 @@ Blockly.navigation.resetFlyout = function(shouldHide) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.navigation.modifyWarn_ = function() {
|
||||
var markerNode = Blockly.navigation.marker_.getCurNode();
|
||||
var cursorNode = Blockly.navigation.cursor_.getCurNode();
|
||||
var markerNode = Blockly.getMainWorkspace().getMarker().getCurNode();
|
||||
var cursorNode = Blockly.getMainWorkspace().getCursor().getCurNode();
|
||||
|
||||
if (!markerNode) {
|
||||
Blockly.navigation.warn('Cannot insert with no marked node.');
|
||||
@@ -487,8 +406,8 @@ Blockly.navigation.moveBlockToWorkspace_ = function(block, wsNode) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.navigation.modify_ = function() {
|
||||
var markerNode = Blockly.navigation.marker_.getCurNode();
|
||||
var cursorNode = Blockly.navigation.cursor_.getCurNode();
|
||||
var markerNode = Blockly.getMainWorkspace().getMarker().getCurNode();
|
||||
var cursorNode = Blockly.getMainWorkspace().getCursor().getCurNode();
|
||||
if (!Blockly.navigation.modifyWarn_()) {
|
||||
return false;
|
||||
}
|
||||
@@ -690,7 +609,7 @@ Blockly.navigation.insertBlock = function(block, destConnection) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.navigation.disconnectBlocks = function() {
|
||||
var curNode = Blockly.navigation.cursor_.getCurNode();
|
||||
var curNode = Blockly.getMainWorkspace().getCursor().getCurNode();
|
||||
if (!curNode.isConnection()) {
|
||||
Blockly.navigation.log('Cannot disconnect blocks when the cursor is not on a connection');
|
||||
return;
|
||||
@@ -717,7 +636,7 @@ Blockly.navigation.disconnectBlocks = function() {
|
||||
rootBlock.bringToFront();
|
||||
|
||||
var connectionNode = Blockly.ASTNode.createConnectionNode(superiorConnection);
|
||||
Blockly.navigation.cursor_.setLocation(connectionNode);
|
||||
Blockly.getMainWorkspace().getCursor().setLocation(connectionNode);
|
||||
};
|
||||
|
||||
/*************************/
|
||||
@@ -729,7 +648,8 @@ Blockly.navigation.disconnectBlocks = function() {
|
||||
* block or a set position on the workspace.
|
||||
*/
|
||||
Blockly.navigation.focusWorkspace = function() {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
Blockly.hideChaff();
|
||||
var cursor = Blockly.getMainWorkspace().getCursor();
|
||||
var reset = Blockly.getMainWorkspace().getToolbox() ? true : false;
|
||||
var topBlocks = Blockly.getMainWorkspace().getTopBlocks();
|
||||
|
||||
@@ -738,7 +658,7 @@ Blockly.navigation.focusWorkspace = function() {
|
||||
if (topBlocks.length > 0) {
|
||||
cursor.setLocation(Blockly.navigation.getTopNode(topBlocks[0]));
|
||||
} else {
|
||||
var ws = cursor.workspace_;
|
||||
var ws = Blockly.getMainWorkspace();
|
||||
// TODO: Find the center of the visible workspace.
|
||||
var wsCoord = new Blockly.utils.Coordinate(100, 100);
|
||||
var wsNode = Blockly.ASTNode.createWorkspaceNode(ws, wsCoord);
|
||||
@@ -750,7 +670,7 @@ Blockly.navigation.focusWorkspace = function() {
|
||||
* Handles hitting the enter key on the workspace.
|
||||
*/
|
||||
Blockly.navigation.handleEnterForWS = function() {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
var cursor = Blockly.getMainWorkspace().getCursor();
|
||||
var curNode = cursor.getCurNode();
|
||||
var nodeType = curNode.getType();
|
||||
if (nodeType === Blockly.ASTNode.types.FIELD) {
|
||||
@@ -798,7 +718,10 @@ Blockly.navigation.getSourceBlock_ = function(node) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.navigation.moveCursorOnBlockDelete = function(deletedBlock) {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
if (!Blockly.getMainWorkspace()) {
|
||||
return;
|
||||
}
|
||||
var cursor = Blockly.getMainWorkspace().getCursor();
|
||||
if (cursor) {
|
||||
var curNode = cursor.getCurNode();
|
||||
var block = Blockly.navigation.getSourceBlock_(curNode);
|
||||
@@ -833,7 +756,7 @@ Blockly.navigation.moveCursorOnBlockDelete = function(deletedBlock) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.navigation.moveCursorOnBlockMutation = function(mutatedBlock) {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
var cursor = Blockly.getMainWorkspace().getCursor();
|
||||
if (cursor) {
|
||||
var curNode = cursor.getCurNode();
|
||||
var block = Blockly.navigation.getSourceBlock_(curNode);
|
||||
@@ -852,30 +775,11 @@ Blockly.navigation.moveCursorOnBlockMutation = function(mutatedBlock) {
|
||||
Blockly.navigation.onKeyPress = function(e) {
|
||||
var key = Blockly.user.keyMap.serializeKeyEvent(e);
|
||||
var action = Blockly.user.keyMap.getActionByKeyCode(key);
|
||||
var curNode = Blockly.navigation.cursor_.getCurNode();
|
||||
var readOnly = Blockly.getMainWorkspace().options.readOnly;
|
||||
var actionHandled = false;
|
||||
|
||||
if (action) {
|
||||
if (Blockly.keyboardAccessibilityMode) {
|
||||
if (!readOnly) {
|
||||
if (curNode && curNode.getType() === Blockly.ASTNode.types.FIELD) {
|
||||
actionHandled = curNode.getLocation().onBlocklyAction(action);
|
||||
}
|
||||
if (!actionHandled) {
|
||||
actionHandled = Blockly.navigation.onBlocklyAction(action);
|
||||
}
|
||||
// If in readonly mode only handle valid actions.
|
||||
} else if (Blockly.navigation.READONLY_ACTION_LIST.indexOf(action) > -1) {
|
||||
actionHandled = Blockly.navigation.onBlocklyAction(action);
|
||||
}
|
||||
// If not in accessibility mode only hanlde turning on keyboard navigation.
|
||||
} else if (action.name === Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV) {
|
||||
Blockly.navigation.enableKeyboardAccessibility();
|
||||
actionHandled = true;
|
||||
}
|
||||
return Blockly.navigation.onBlocklyAction(action);
|
||||
}
|
||||
return actionHandled;
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -883,12 +787,49 @@ Blockly.navigation.onKeyPress = function(e) {
|
||||
* the given action.
|
||||
* @param {!Blockly.Action} action The current action.
|
||||
* @return {boolean} True if the action has been handled, false otherwise.
|
||||
* @package
|
||||
*/
|
||||
Blockly.navigation.onBlocklyAction = function(action) {
|
||||
var readOnly = Blockly.getMainWorkspace().options.readOnly;
|
||||
var actionHandled = false;
|
||||
|
||||
if (Blockly.keyboardAccessibilityMode) {
|
||||
if (!readOnly) {
|
||||
var curNode = Blockly.getMainWorkspace().getCursor().getCurNode();
|
||||
if (curNode && curNode.getType() === Blockly.ASTNode.types.FIELD) {
|
||||
actionHandled = curNode.getLocation().onBlocklyAction(action);
|
||||
}
|
||||
if (!actionHandled) {
|
||||
actionHandled = Blockly.navigation.handleActions_(action);
|
||||
}
|
||||
// If in readonly mode only handle valid actions.
|
||||
} else if (Blockly.navigation.READONLY_ACTION_LIST.indexOf(action) > -1) {
|
||||
actionHandled = Blockly.navigation.handleActions_(action);
|
||||
}
|
||||
// If not in accessibility mode only hanlde turning on keyboard navigation.
|
||||
} else if (action.name === Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV) {
|
||||
Blockly.navigation.enableKeyboardAccessibility();
|
||||
actionHandled = true;
|
||||
}
|
||||
return actionHandled;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles the action or dispatches to the appropriate action handler.
|
||||
* @param {!Blockly.Action} action The current action
|
||||
* @return {boolean} True if the action has been handled, false otherwise.
|
||||
* @private
|
||||
*/
|
||||
Blockly.navigation.handleActions_ = function(action) {
|
||||
if (action.name === Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV) {
|
||||
Blockly.navigation.disableKeyboardAccessibility();
|
||||
return true;
|
||||
} else if (action.name === Blockly.navigation.actionNames.TOOLBOX) {
|
||||
if (!Blockly.getMainWorkspace().getToolbox()) {
|
||||
Blockly.navigation.focusFlyout();
|
||||
} else {
|
||||
Blockly.navigation.focusToolbox();
|
||||
}
|
||||
return true;
|
||||
} else if (Blockly.navigation.currentState_ === Blockly.navigation.STATE_WS) {
|
||||
return Blockly.navigation.workspaceOnAction_(action);
|
||||
} else if (Blockly.navigation.currentState_ === Blockly.navigation.STATE_FLYOUT) {
|
||||
@@ -908,16 +849,16 @@ Blockly.navigation.onBlocklyAction = function(action) {
|
||||
Blockly.navigation.workspaceOnAction_ = function(action) {
|
||||
switch (action.name) {
|
||||
case Blockly.navigation.actionNames.PREVIOUS:
|
||||
Blockly.navigation.cursor_.prev();
|
||||
Blockly.getMainWorkspace().getCursor().prev();
|
||||
return true;
|
||||
case Blockly.navigation.actionNames.OUT:
|
||||
Blockly.navigation.cursor_.out();
|
||||
Blockly.getMainWorkspace().getCursor().out();
|
||||
return true;
|
||||
case Blockly.navigation.actionNames.NEXT:
|
||||
Blockly.navigation.cursor_.next();
|
||||
Blockly.getMainWorkspace().getCursor().next();
|
||||
return true;
|
||||
case Blockly.navigation.actionNames.IN:
|
||||
Blockly.navigation.cursor_.in();
|
||||
Blockly.getMainWorkspace().getCursor().in();
|
||||
return true;
|
||||
case Blockly.navigation.actionNames.INSERT:
|
||||
Blockly.navigation.modify_();
|
||||
@@ -928,13 +869,6 @@ Blockly.navigation.workspaceOnAction_ = function(action) {
|
||||
case Blockly.navigation.actionNames.DISCONNECT:
|
||||
Blockly.navigation.disconnectBlocks();
|
||||
return true;
|
||||
case Blockly.navigation.actionNames.TOOLBOX:
|
||||
if (!Blockly.getMainWorkspace().getToolbox()) {
|
||||
Blockly.navigation.focusFlyout();
|
||||
} else {
|
||||
Blockly.navigation.focusToolbox();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -949,13 +883,13 @@ Blockly.navigation.workspaceOnAction_ = function(action) {
|
||||
Blockly.navigation.flyoutOnAction_ = function(action) {
|
||||
switch (action.name) {
|
||||
case Blockly.navigation.actionNames.PREVIOUS:
|
||||
Blockly.navigation.selectPreviousBlockInFlyout();
|
||||
Blockly.navigation.getFlyoutCursor_().prev();
|
||||
return true;
|
||||
case Blockly.navigation.actionNames.OUT:
|
||||
Blockly.navigation.focusToolbox();
|
||||
return true;
|
||||
case Blockly.navigation.actionNames.NEXT:
|
||||
Blockly.navigation.selectNextBlockInFlyout();
|
||||
Blockly.navigation.getFlyoutCursor_().next();
|
||||
return true;
|
||||
case Blockly.navigation.actionNames.MARK:
|
||||
Blockly.navigation.insertFromFlyout();
|
||||
@@ -1012,7 +946,11 @@ Blockly.navigation.enableKeyboardAccessibility = function() {
|
||||
Blockly.navigation.disableKeyboardAccessibility = function() {
|
||||
if (Blockly.keyboardAccessibilityMode) {
|
||||
Blockly.keyboardAccessibilityMode = false;
|
||||
Blockly.navigation.cursor_.hide();
|
||||
Blockly.getMainWorkspace().getCursor().hide();
|
||||
Blockly.getMainWorkspace().getMarker().hide();
|
||||
if (Blockly.navigation.getFlyoutCursor_()) {
|
||||
Blockly.navigation.getFlyoutCursor_().hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1138,5 +1076,6 @@ Blockly.navigation.READONLY_ACTION_LIST = [
|
||||
Blockly.navigation.ACTION_PREVIOUS,
|
||||
Blockly.navigation.ACTION_OUT,
|
||||
Blockly.navigation.ACTION_IN,
|
||||
Blockly.navigation.ACTION_NEXT
|
||||
Blockly.navigation.ACTION_NEXT,
|
||||
Blockly.navigation.ACTION_TOGGLE_KEYBOARD_NAV
|
||||
];
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
goog.provide('Blockly.Workspace');
|
||||
|
||||
goog.require('Blockly.Cursor');
|
||||
goog.require('Blockly.MarkerCursor');
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Themes.Classic');
|
||||
goog.require('Blockly.utils');
|
||||
@@ -117,22 +118,28 @@ Blockly.Workspace = function(opt_options) {
|
||||
this.potentialVariableMap_ = null;
|
||||
|
||||
/**
|
||||
* The cursor for navigating blocks.
|
||||
* @type {!Blockly.Cursor}
|
||||
* The cursor used to navigate around the AST for keyboard navigation.
|
||||
* @type {Blockly.Cursor}
|
||||
* @private
|
||||
*/
|
||||
this.cursor = this.createCursor();
|
||||
this.cursor_ = null;
|
||||
|
||||
/**
|
||||
* The marker that shows where a user has marked while navigating blocks.
|
||||
* @type {!Blockly.Cursor}
|
||||
* The marker used to mark a location for keyboard navigation.
|
||||
* @type {Blockly.MarkerCursor}
|
||||
* @private
|
||||
*/
|
||||
this.marker = this.createMarker();
|
||||
this.marker_ = null;
|
||||
|
||||
// Set the default theme. This is for headless workspaces. This will get
|
||||
// overwritten by the theme passed into the inject call for rendered workspaces.
|
||||
if (!Blockly.getTheme()) {
|
||||
Blockly.setTheme(Blockly.Themes.Classic);
|
||||
}
|
||||
|
||||
this.setCursor(new Blockly.Cursor());
|
||||
|
||||
this.setMarker(new Blockly.MarkerCursor());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -162,19 +169,37 @@ Blockly.Workspace.prototype.MAX_UNDO = 1024;
|
||||
Blockly.Workspace.prototype.connectionDBList = null;
|
||||
|
||||
/**
|
||||
* Adds cursor for keyboard navigation.
|
||||
* @return {!Blockly.Cursor} Cursor for keyboard navigation.
|
||||
* Sets the cursor for keyboard navigation.
|
||||
* @param {Blockly.Cursor} cursor The cursor used to navigate around the Blockly
|
||||
* AST for keyboard navigation.
|
||||
*/
|
||||
Blockly.Workspace.prototype.createCursor = function() {
|
||||
return new Blockly.Cursor();
|
||||
Blockly.Workspace.prototype.setCursor = function(cursor) {
|
||||
this.cursor_ = cursor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds marker for keyboard navigation.
|
||||
* @return {!Blockly.Cursor} Cursor for keyboard navigation.
|
||||
* Sets the marker for keyboard navigation.
|
||||
* @param {Blockly.MarkerCursor} marker The marker used to mark a location for
|
||||
* keyboard navigation.
|
||||
*/
|
||||
Blockly.Workspace.prototype.createMarker = function() {
|
||||
return new Blockly.Cursor(true);
|
||||
Blockly.Workspace.prototype.setMarker = function(marker) {
|
||||
this.marker_ = marker;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the cursor used to navigate around the AST for keyboard navigation.
|
||||
* @return {Blockly.Cursor} The cursor for this workspace.
|
||||
*/
|
||||
Blockly.Workspace.prototype.getCursor = function() {
|
||||
return this.cursor_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the marker used to mark a location for keyboard navigation.
|
||||
* @return {Blockly.MarkerCursor} the marker for this workspace.
|
||||
*/
|
||||
Blockly.Workspace.prototype.getMarker = function() {
|
||||
return this.marker_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -396,19 +396,34 @@ Blockly.WorkspaceSvg.prototype.inverseScreenCTM_ = null;
|
||||
Blockly.WorkspaceSvg.prototype.inverseScreenCTMDirty_ = true;
|
||||
|
||||
/**
|
||||
* Adds cursor for keyboard navigation.
|
||||
* @return {!Blockly.CursorSvg} Cursor for keyboard navigation.
|
||||
* Sets the cursor for use with keyboard navigation.
|
||||
* @param {!Blockly.Cursor} cursor The cursor used to move around this workspace.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.createCursor = function() {
|
||||
return new Blockly.CursorSvg(this);
|
||||
Blockly.WorkspaceSvg.prototype.setCursor = function(cursor) {
|
||||
if (this.cursor_) {
|
||||
this.cursor_.getDrawer().dispose();
|
||||
}
|
||||
this.cursor_ = cursor;
|
||||
this.cursor_.setDrawer(new Blockly.CursorSvg(this, false));
|
||||
if (this.svgGroup_) {
|
||||
this.svgGroup_.appendChild(this.cursor_.getDrawer().createDom());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds marker for keyboard navigation.
|
||||
* @return {!Blockly.CursorSvg} Marker for keyboard navigation.
|
||||
* Sets the marker for use with keyboard navigation.
|
||||
* @param {!Blockly.MarkerCursor} marker The immovable cursor used to mark a
|
||||
* location on the workspace.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.createMarker = function() {
|
||||
return new Blockly.CursorSvg(this, true);
|
||||
Blockly.WorkspaceSvg.prototype.setMarker = function(marker) {
|
||||
if (this.marker_) {
|
||||
this.marker_.getDrawer().dispose();
|
||||
}
|
||||
this.marker_ = marker;
|
||||
this.marker_.setDrawer(new Blockly.CursorSvg(this, true));
|
||||
if (this.svgGroup_) {
|
||||
this.svgGroup_.appendChild(this.marker_.getDrawer().createDom());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -578,10 +593,10 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
|
||||
}
|
||||
this.recordDeleteAreas();
|
||||
|
||||
var svgCursor = this.cursor.createDom();
|
||||
var svgCursor = this.cursor_.getDrawer().createDom();
|
||||
this.svgGroup_.appendChild(svgCursor);
|
||||
|
||||
var svgMarker = this.marker.createDom();
|
||||
var svgMarker = this.marker_.getDrawer().createDom();
|
||||
this.svgGroup_.appendChild(svgMarker);
|
||||
|
||||
return this.svgGroup_;
|
||||
@@ -625,12 +640,12 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
|
||||
this.zoomControls_ = null;
|
||||
}
|
||||
|
||||
if (this.marker) {
|
||||
this.marker.dispose();
|
||||
if (this.marker_) {
|
||||
this.marker_.getDrawer().dispose();
|
||||
}
|
||||
|
||||
if (this.cursor) {
|
||||
this.cursor.dispose();
|
||||
if (this.cursor_) {
|
||||
this.cursor_.getDrawer().dispose();
|
||||
}
|
||||
|
||||
if (this.audioManager_) {
|
||||
@@ -1081,7 +1096,7 @@ Blockly.WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock) {
|
||||
var block = Blockly.Xml.domToBlock(xmlBlock, this);
|
||||
|
||||
// Handle paste for keyboard navigation
|
||||
var markedNode = Blockly.navigation.marker_.getCurNode();
|
||||
var markedNode = this.getMarker().getCurNode();
|
||||
if (Blockly.keyboardAccessibilityMode && markedNode) {
|
||||
Blockly.navigation.insertBlock(block, markedNode.getLocation());
|
||||
return;
|
||||
|
||||
@@ -46,7 +46,8 @@ suite('Cursor', function() {
|
||||
}
|
||||
]);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
this.cursor = this.workspace.cursor;
|
||||
this.workspace.setCursor(new Blockly.Cursor());
|
||||
this.cursor = this.workspace.getCursor();
|
||||
var blockA = this.workspace.newBlock('input_statement');
|
||||
var blockB = this.workspace.newBlock('input_statement');
|
||||
var blockC = this.workspace.newBlock('input_statement');
|
||||
|
||||
@@ -37,25 +37,25 @@ suite('Insert/Modify', function() {
|
||||
// TODO: Marked connection or cursor connection is already connected.
|
||||
suite('Marker on next', function() {
|
||||
setup(function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_1.nextConnection));
|
||||
});
|
||||
test('Cursor on workspace', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createWorkspaceNode(this.workspace,
|
||||
new Blockly.utils.Coordinate(0, 0)));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on compatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_2.previousConnection));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
chai.assert.equal(this.stack_block_1.getNextBlock().id, 'stack_block_2');
|
||||
});
|
||||
test('Cursor on incompatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_2.nextConnection));
|
||||
// Connect method will try to find a way to connect blocks with
|
||||
@@ -64,14 +64,14 @@ suite('Insert/Modify', function() {
|
||||
chai.assert.equal(this.stack_block_1.getNextBlock(), this.stack_block_2);
|
||||
});
|
||||
test('Cursor on really incompatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_1.outputConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
chai.assert.isNull(this.stack_block_1.getNextBlock());
|
||||
});
|
||||
test('Cursor on block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.stack_block_2));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
@@ -81,40 +81,40 @@ suite('Insert/Modify', function() {
|
||||
|
||||
suite('Marker on previous', function() {
|
||||
setup(function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_1.previousConnection));
|
||||
});
|
||||
test('Cursor on compatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_2.nextConnection));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
chai.assert.equal(this.stack_block_1.getPreviousBlock().id, 'stack_block_2');
|
||||
});
|
||||
test('Cursor on incompatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_2.previousConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
chai.assert.isNull(this.stack_block_1.getPreviousBlock());
|
||||
});
|
||||
test('Cursor on really incompatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_1.outputConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
chai.assert.isNull(this.stack_block_1.getNextBlock());
|
||||
});
|
||||
test('Cursor on block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.stack_block_2));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
chai.assert.equal(this.stack_block_1.getPreviousBlock().id, 'stack_block_2');
|
||||
});
|
||||
test('Cursor on incompatible block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.row_block_1));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
@@ -124,19 +124,19 @@ suite('Insert/Modify', function() {
|
||||
|
||||
suite('Marker on value input', function() {
|
||||
setup(function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_1.inputList[0].connection));
|
||||
});
|
||||
test('Cursor on compatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_2.outputConnection));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
chai.assert.equal(this.row_block_2.getParent().id, 'row_block_1');
|
||||
});
|
||||
test('Cursor on incompatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_2.inputList[0].connection));
|
||||
// Connect method will try to find a way to connect blocks with
|
||||
@@ -146,13 +146,13 @@ suite('Insert/Modify', function() {
|
||||
this.row_block_2);
|
||||
});
|
||||
test('Cursor on really incompatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_1.previousConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.row_block_2));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
@@ -165,12 +165,12 @@ suite('Insert/Modify', function() {
|
||||
this.statement_block_1.inputList[0].connection.connect(
|
||||
this.stack_block_1.previousConnection);
|
||||
this.stack_block_1.nextConnection.connect(this.stack_block_2.previousConnection);
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createInputNode(
|
||||
this.statement_block_1.inputList[0]));
|
||||
});
|
||||
test('Cursor on block inside statement', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_2.previousConnection));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
@@ -178,14 +178,14 @@ suite('Insert/Modify', function() {
|
||||
this.statement_block_1);
|
||||
});
|
||||
test('Cursor on stack', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createStackNode(
|
||||
this.statement_block_2));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
chai.assert.equal(this.statement_block_2.getParent().id, 'statement_block_1');
|
||||
});
|
||||
test('Cursor on incompatible type', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_1.outputConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
@@ -196,31 +196,31 @@ suite('Insert/Modify', function() {
|
||||
|
||||
suite('Marker on output', function() {
|
||||
setup(function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_1.outputConnection));
|
||||
});
|
||||
test('Cursor on compatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_2.inputList[0].connection));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
chai.assert.equal(this.row_block_1.getParent().id, 'row_block_2');
|
||||
});
|
||||
test('Cursor on incompatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_2.outputConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on really incompatible connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_1.previousConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.row_block_2));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
@@ -232,12 +232,12 @@ suite('Insert/Modify', function() {
|
||||
|
||||
suite('Marked Workspace', function() {
|
||||
setup(function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createWorkspaceNode(
|
||||
this.workspace, new Blockly.utils.Coordinate(100, 200)));
|
||||
});
|
||||
test('Cursor on row block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.row_block_1));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
@@ -247,7 +247,7 @@ suite('Insert/Modify', function() {
|
||||
});
|
||||
|
||||
test('Cursor on output connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_1.outputConnection));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
@@ -257,7 +257,7 @@ suite('Insert/Modify', function() {
|
||||
});
|
||||
|
||||
test('Cursor on previous connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_1.previousConnection));
|
||||
chai.assert.isTrue(Blockly.navigation.modify_());
|
||||
@@ -267,7 +267,7 @@ suite('Insert/Modify', function() {
|
||||
});
|
||||
|
||||
test('Cursor on input connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_1.inputList[0].connection));
|
||||
// Move the source block to the marked location on the workspace.
|
||||
@@ -275,7 +275,7 @@ suite('Insert/Modify', function() {
|
||||
});
|
||||
|
||||
test('Cursor on next connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_1.nextConnection));
|
||||
// Move the source block to the marked location on the workspace.
|
||||
@@ -286,7 +286,7 @@ suite('Insert/Modify', function() {
|
||||
this.row_block_1.inputList[0].connection.connect(
|
||||
this.row_block_2.outputConnection);
|
||||
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.row_block_2));
|
||||
|
||||
@@ -301,7 +301,7 @@ suite('Insert/Modify', function() {
|
||||
this.stack_block_1.nextConnection.connect(
|
||||
this.stack_block_2.previousConnection);
|
||||
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.stack_block_2));
|
||||
|
||||
@@ -313,7 +313,7 @@ suite('Insert/Modify', function() {
|
||||
});
|
||||
|
||||
test('Cursor on workspace', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createWorkspaceNode(
|
||||
this.workspace, new Blockly.utils.Coordinate(100, 100)));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
@@ -327,12 +327,12 @@ suite('Insert/Modify', function() {
|
||||
// These tests are using a stack block, but do not depend on the type of
|
||||
// the block.
|
||||
setup(function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.stack_block_1));
|
||||
});
|
||||
test('Cursor on workspace', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createWorkspaceNode(
|
||||
this.workspace, new Blockly.utils.Coordinate(100, 100)));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
@@ -341,30 +341,30 @@ suite('Insert/Modify', function() {
|
||||
});
|
||||
suite('Marked stack block', function() {
|
||||
setup(function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.stack_block_1));
|
||||
});
|
||||
test('Cursor on row block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.row_block_1));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on stack block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.stack_block_1));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on next connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_2.nextConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on previous connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.stack_block_2.previousConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
@@ -372,30 +372,30 @@ suite('Insert/Modify', function() {
|
||||
});
|
||||
suite('Marked row block', function() {
|
||||
setup(function() {
|
||||
Blockly.navigation.marker_.setLocation(
|
||||
this.workspace.getMarker().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.row_block_1));
|
||||
});
|
||||
test('Cursor on stack block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.stack_block_1));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on row block', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createBlockNode(
|
||||
this.row_block_1));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on value input connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_2.inputList[0].connection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
});
|
||||
test('Cursor on output connection', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(
|
||||
this.row_block_2.outputConnection));
|
||||
chai.assert.isFalse(Blockly.navigation.modify_());
|
||||
|
||||
@@ -93,8 +93,9 @@ suite('Navigation', function() {
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
chai.assert.equal(Blockly.navigation.currentState_,
|
||||
Blockly.navigation.STATE_FLYOUT);
|
||||
var flyoutCursor = Blockly.navigation.getFlyoutCursor_();
|
||||
|
||||
chai.assert.equal(Blockly.navigation.flyoutBlock_.getFieldValue("TEXT"),
|
||||
chai.assert.equal(flyoutCursor.getCurNode().getLocation().getFieldValue("TEXT"),
|
||||
"FirstCategory-FirstBlock");
|
||||
});
|
||||
|
||||
@@ -154,19 +155,23 @@ suite('Navigation', function() {
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
chai.assert.equal(Blockly.navigation.currentState_,
|
||||
Blockly.navigation.STATE_FLYOUT);
|
||||
chai.assert.equal(Blockly.navigation.flyoutBlock_.getFieldValue("TEXT"),
|
||||
chai.assert.equal(Blockly.navigation.getFlyoutCursor_().getCurNode().getLocation().getFieldValue("TEXT"),
|
||||
"FirstCategory-FirstBlock");
|
||||
});
|
||||
|
||||
test('Previous', function() {
|
||||
Blockly.navigation.selectNextBlockInFlyout();
|
||||
chai.assert.equal(Blockly.navigation.flyoutBlock_.getFieldValue("TEXT"),
|
||||
var flyoutBlocks = this.workspace.getFlyout().getWorkspace().getTopBlocks();
|
||||
Blockly.navigation.getFlyoutCursor_().setLocation(
|
||||
Blockly.ASTNode.createStackNode(flyoutBlocks[1]));
|
||||
var flyoutBlock = Blockly.navigation.getFlyoutCursor_().getCurNode().getLocation();
|
||||
chai.assert.equal(flyoutBlock.getFieldValue("TEXT"),
|
||||
"FirstCategory-SecondBlock");
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.W;
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
chai.assert.equal(Blockly.navigation.currentState_,
|
||||
Blockly.navigation.STATE_FLYOUT);
|
||||
chai.assert.equal(Blockly.navigation.flyoutBlock_.getFieldValue("TEXT"),
|
||||
flyoutBlock = Blockly.navigation.getFlyoutCursor_().getCurNode().getLocation();
|
||||
chai.assert.equal(flyoutBlock.getFieldValue("TEXT"),
|
||||
"FirstCategory-FirstBlock");
|
||||
});
|
||||
|
||||
@@ -175,7 +180,8 @@ suite('Navigation', function() {
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
chai.assert.equal(Blockly.navigation.currentState_,
|
||||
Blockly.navigation.STATE_FLYOUT);
|
||||
chai.assert.equal(Blockly.navigation.flyoutBlock_.getFieldValue("TEXT"),
|
||||
var flyoutBlock = Blockly.navigation.getFlyoutCursor_().getCurNode().getLocation();
|
||||
chai.assert.equal(flyoutBlock.getFieldValue("TEXT"),
|
||||
"FirstCategory-SecondBlock");
|
||||
});
|
||||
|
||||
@@ -238,18 +244,17 @@ suite('Navigation', function() {
|
||||
});
|
||||
|
||||
test('Previous', function() {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
sinon.spy(cursor, 'prev');
|
||||
sinon.spy(this.workspace.getCursor(), 'prev');
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.W;
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
chai.assert.isTrue(cursor.prev.calledOnce);
|
||||
chai.assert.isTrue(this.workspace.getCursor().prev.calledOnce);
|
||||
chai.assert.equal(Blockly.navigation.currentState_,
|
||||
Blockly.navigation.STATE_WS);
|
||||
cursor.prev.restore();
|
||||
this.workspace.getCursor().prev.restore();
|
||||
});
|
||||
|
||||
test('Next', function() {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
var cursor = this.workspace.getCursor();
|
||||
sinon.spy(cursor, 'next');
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.S;
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
@@ -260,7 +265,7 @@ suite('Navigation', function() {
|
||||
});
|
||||
|
||||
test('Out', function() {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
var cursor = this.workspace.getCursor();
|
||||
sinon.spy(cursor, 'out');
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.A;
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
@@ -271,7 +276,7 @@ suite('Navigation', function() {
|
||||
});
|
||||
|
||||
test('In', function() {
|
||||
var cursor = Blockly.navigation.cursor_;
|
||||
var cursor = this.workspace.getCursor();
|
||||
sinon.spy(cursor, 'in');
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.D;
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
@@ -292,11 +297,11 @@ suite('Navigation', function() {
|
||||
});
|
||||
|
||||
test('Mark', function() {
|
||||
Blockly.navigation.cursor_.setLocation(
|
||||
this.workspace.getCursor().setLocation(
|
||||
Blockly.ASTNode.createConnectionNode(this.basicBlock.previousConnection));
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.ENTER;
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
var markedNode = Blockly.navigation.marker_.getCurNode();
|
||||
var markedNode = this.workspace.getMarker().getCurNode();
|
||||
chai.assert.equal(markedNode.getLocation(), this.basicBlock.previousConnection);
|
||||
chai.assert.equal(Blockly.navigation.currentState_,
|
||||
Blockly.navigation.STATE_WS);
|
||||
@@ -313,6 +318,11 @@ suite('Navigation', function() {
|
||||
|
||||
suite('Test key press', function() {
|
||||
setup(function() {
|
||||
this.workspace = new Blockly.Workspace({readOnly: false});
|
||||
Blockly.user.keyMap.setKeyMap(Blockly.user.keyMap.createDefaultKeyMap());
|
||||
Blockly.mainWorkspace = this.workspace;
|
||||
Blockly.keyboardAccessibilityMode = true;
|
||||
|
||||
this.mockEvent = {
|
||||
getModifierState: function() {
|
||||
return false;
|
||||
@@ -320,11 +330,9 @@ suite('Navigation', function() {
|
||||
};
|
||||
});
|
||||
test('Action does not exist', function() {
|
||||
var cursor = new Blockly.Cursor();
|
||||
var field = new Blockly.Field('value');
|
||||
Blockly.navigation.setCursor(cursor);
|
||||
var field = new Blockly.FieldDropdown([['a','b'], ['c','d']]);
|
||||
sinon.spy(field, 'onBlocklyAction');
|
||||
cursor.setLocation(Blockly.ASTNode.createFieldNode(field));
|
||||
this.workspace.getCursor().setLocation(Blockly.ASTNode.createFieldNode(field));
|
||||
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.N;
|
||||
var isHandled = Blockly.navigation.onKeyPress(this.mockEvent);
|
||||
@@ -335,45 +343,33 @@ suite('Navigation', function() {
|
||||
});
|
||||
|
||||
test('Action exists - field handles action', function() {
|
||||
var cursor = new Blockly.Cursor();
|
||||
var field = new Blockly.Field('value');
|
||||
Blockly.navigation.setCursor(cursor);
|
||||
sinon.spy(Blockly.navigation, 'onBlocklyAction');
|
||||
var field = new Blockly.FieldDropdown([['a','b'], ['c','d']]);
|
||||
sinon.stub(field, 'onBlocklyAction').callsFake(function(){
|
||||
return true;
|
||||
});
|
||||
cursor.setLocation(Blockly.ASTNode.createFieldNode(field));
|
||||
this.workspace.getCursor().setLocation(Blockly.ASTNode.createFieldNode(field));
|
||||
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.A;
|
||||
var isHandled = Blockly.navigation.onKeyPress(this.mockEvent);
|
||||
var isHandled = Blockly.navigation.onBlocklyAction(Blockly.navigation.ACTION_OUT);
|
||||
chai.assert.isTrue(isHandled);
|
||||
chai.assert.isTrue(field.onBlocklyAction.calledOnce);
|
||||
chai.assert.isFalse(Blockly.navigation.onBlocklyAction.calledOnce);
|
||||
|
||||
Blockly.navigation.onBlocklyAction.restore();
|
||||
field.onBlocklyAction.restore();
|
||||
});
|
||||
|
||||
test('Action exists - field does not handle action', function() {
|
||||
var cursor = new Blockly.Cursor();
|
||||
var field = new Blockly.Field('value');
|
||||
Blockly.navigation.setCursor(cursor);
|
||||
var field = new Blockly.FieldDropdown([['a','b'], ['c','d']]);
|
||||
sinon.spy(field, 'onBlocklyAction');
|
||||
sinon.spy(Blockly.navigation, 'onBlocklyAction');
|
||||
cursor.setLocation(Blockly.ASTNode.createFieldNode(field));
|
||||
this.workspace.getCursor().setLocation(Blockly.ASTNode.createFieldNode(field));
|
||||
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.A;
|
||||
var isHandled = Blockly.navigation.onKeyPress(this.mockEvent);
|
||||
var isHandled = Blockly.navigation.onBlocklyAction(Blockly.navigation.ACTION_OUT);
|
||||
chai.assert.isTrue(isHandled);
|
||||
chai.assert.isTrue(field.onBlocklyAction.calledOnce);
|
||||
|
||||
field.onBlocklyAction.restore();
|
||||
Blockly.navigation.onBlocklyAction.restore();
|
||||
});
|
||||
|
||||
test('Toggle Action Off', function() {
|
||||
var cursor = new Blockly.Cursor();
|
||||
Blockly.navigation.setCursor(cursor);
|
||||
this.mockEvent.keyCode = 'Control75';
|
||||
sinon.spy(Blockly.navigation, 'onBlocklyAction');
|
||||
Blockly.keyboardAccessibilityMode = true;
|
||||
@@ -386,9 +382,6 @@ suite('Navigation', function() {
|
||||
});
|
||||
|
||||
test('Toggle Action On', function() {
|
||||
var cursor = new Blockly.Cursor();
|
||||
Blockly.navigation.setCursor(cursor);
|
||||
this.workspace = Blockly.inject('blocklyDiv', {readOnly: false});
|
||||
this.mockEvent.keyCode = 'Control75';
|
||||
sinon.stub(Blockly.navigation, 'focusWorkspace');
|
||||
Blockly.keyboardAccessibilityMode = false;
|
||||
@@ -429,7 +422,7 @@ suite('Navigation', function() {
|
||||
"helpUrl": ""
|
||||
}]);
|
||||
this.workspace = new Blockly.Workspace({readOnly: true});
|
||||
Blockly.navigation.setCursor(this.workspace.cursor);
|
||||
this.workspace.setCursor(new Blockly.Cursor());
|
||||
Blockly.mainWorkspace = this.workspace;
|
||||
this.fieldBlock1 = this.workspace.newBlock('field_block');
|
||||
Blockly.keyboardAccessibilityMode = true;
|
||||
@@ -448,14 +441,14 @@ suite('Navigation', function() {
|
||||
|
||||
test('Perform valid action for read only', function() {
|
||||
var astNode = Blockly.ASTNode.createBlockNode(this.fieldBlock1);
|
||||
this.workspace.cursor.setLocation(astNode);
|
||||
this.workspace.getCursor().setLocation(astNode);
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.S;
|
||||
chai.assert.isTrue(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
});
|
||||
|
||||
test('Perform invalid action for read only', function() {
|
||||
var astNode = Blockly.ASTNode.createBlockNode(this.fieldBlock1);
|
||||
this.workspace.cursor.setLocation(astNode);
|
||||
this.workspace.getCursor().setLocation(astNode);
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.I;
|
||||
chai.assert.isFalse(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
});
|
||||
@@ -463,7 +456,7 @@ suite('Navigation', function() {
|
||||
test('Try to perform action on a field', function() {
|
||||
var field = this.fieldBlock1.inputList[0].fieldRow[0];
|
||||
var astNode = Blockly.ASTNode.createFieldNode(field);
|
||||
this.workspace.cursor.setLocation(astNode);
|
||||
this.workspace.getCursor().setLocation(astNode);
|
||||
this.mockEvent.keyCode = Blockly.utils.KeyCodes.ENTER;
|
||||
chai.assert.isFalse(Blockly.navigation.onKeyPress(this.mockEvent));
|
||||
});
|
||||
@@ -498,7 +491,7 @@ suite('Navigation', function() {
|
||||
test('Insert from flyout with a valid connection marked', function() {
|
||||
var previousConnection = this.basicBlock.previousConnection;
|
||||
var prevNode = Blockly.ASTNode.createConnectionNode(previousConnection);
|
||||
Blockly.navigation.marker_.setLocation(prevNode);
|
||||
this.workspace.getMarker().setLocation(prevNode);
|
||||
|
||||
Blockly.navigation.focusToolbox();
|
||||
Blockly.navigation.focusFlyout();
|
||||
@@ -530,10 +523,10 @@ suite('Navigation', function() {
|
||||
|
||||
test('Connect two blocks that are on the workspace', function() {
|
||||
var targetNode = Blockly.ASTNode.createConnectionNode(this.basicBlock.previousConnection);
|
||||
Blockly.navigation.marker_.setLocation(targetNode);
|
||||
this.workspace.getMarker().setLocation(targetNode);
|
||||
|
||||
var sourceNode = Blockly.ASTNode.createConnectionNode(this.basicBlock2.nextConnection);
|
||||
Blockly.navigation.cursor_.setLocation(sourceNode);
|
||||
this.workspace.getCursor().setLocation(sourceNode);
|
||||
|
||||
Blockly.navigation.modify_();
|
||||
var insertedBlock = this.basicBlock.previousConnection.targetBlock();
|
||||
@@ -678,18 +671,18 @@ suite('Navigation', function() {
|
||||
this.basicBlockA.nextConnection.connect(this.basicBlockB.previousConnection);
|
||||
var astNode = Blockly.ASTNode.createBlockNode(this.basicBlockB);
|
||||
// Set the cursor to be on the child block
|
||||
this.workspace.cursor.setLocation(astNode);
|
||||
this.workspace.getCursor().setLocation(astNode);
|
||||
// Remove the child block
|
||||
this.basicBlockB.dispose();
|
||||
chai.assert.equal(this.workspace.cursor.getCurNode().getType(),
|
||||
chai.assert.equal(this.workspace.getCursor().getCurNode().getType(),
|
||||
Blockly.ASTNode.types.NEXT);
|
||||
});
|
||||
|
||||
test('Delete block - no parent ', function() {
|
||||
var astNode = Blockly.ASTNode.createBlockNode(this.basicBlockB);
|
||||
this.workspace.cursor.setLocation(astNode);
|
||||
this.workspace.getCursor().setLocation(astNode);
|
||||
this.basicBlockB.dispose();
|
||||
chai.assert.equal(this.workspace.cursor.getCurNode().getType(),
|
||||
chai.assert.equal(this.workspace.getCursor().getCurNode().getType(),
|
||||
Blockly.ASTNode.types.WORKSPACE);
|
||||
});
|
||||
|
||||
@@ -697,10 +690,10 @@ suite('Navigation', function() {
|
||||
this.basicBlockA.nextConnection.connect(this.basicBlockB.previousConnection);
|
||||
var astNode = Blockly.ASTNode.createBlockNode(this.basicBlockB);
|
||||
// Set the cursor to be on the child block
|
||||
this.workspace.cursor.setLocation(astNode);
|
||||
this.workspace.getCursor().setLocation(astNode);
|
||||
// Remove the parent block
|
||||
this.basicBlockA.dispose();
|
||||
chai.assert.equal(this.workspace.cursor.getCurNode().getType(),
|
||||
chai.assert.equal(this.workspace.getCursor().getCurNode().getType(),
|
||||
Blockly.ASTNode.types.WORKSPACE);
|
||||
});
|
||||
|
||||
@@ -708,10 +701,10 @@ suite('Navigation', function() {
|
||||
this.basicBlockA.nextConnection.connect(this.basicBlockB.previousConnection);
|
||||
var astNode = Blockly.ASTNode.createStackNode(this.basicBlockA);
|
||||
// Set the cursor to be on the stack
|
||||
this.workspace.cursor.setLocation(astNode);
|
||||
this.workspace.getCursor().setLocation(astNode);
|
||||
// Remove the top block in the stack
|
||||
this.basicBlockA.dispose();
|
||||
chai.assert.equal(this.workspace.cursor.getCurNode().getType(),
|
||||
chai.assert.equal(this.workspace.getCursor().getCurNode().getType(),
|
||||
Blockly.ASTNode.types.WORKSPACE);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user