From e14d3aa99c553c1d0ba362a32ac3c8213210af4a Mon Sep 17 00:00:00 2001 From: vivid Date: Fri, 14 Oct 2016 14:23:37 +0900 Subject: [PATCH 1/2] temp commit --- dist/entry.js | 51 ++++++++++++++++++++----------------- src/workspace/block_view.js | 9 ++++--- src/workspace/board.js | 12 ++++++--- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/dist/entry.js b/dist/entry.js index 30fa439dc2..232c588662 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -21171,7 +21171,7 @@ Entry.BlockView.pngMap = {}; b._updateBG = function() { if (this._board.dragBlock && this._board.dragBlock.dragInstance) { var a = this.svgGroup; - if (this.magnet.next) { + if (this.magnet.next || this.magnet.previous) { if (a = this.magneting) { var b = this._board.dragBlock.getShadow(), c = this.getAbsoluteCoordinate(), e; if ("previous" === a) { @@ -21243,15 +21243,17 @@ Entry.BlockView.pngMap = {}; c._moveBy(a, a, !1); }, b) : c._moveBy(a, a, !1); }; - b.bindPrev = function(a) { + b.bindPrev = function(a, b) { if (a) { - if (this._toLocalCoordinate(a.view._nextGroup), (a = a.getNextBlock()) && a !== this.block) { - var b = this.block.getLastBlock(); - b.view.magnet.next ? a.view._toLocalCoordinate(b.view._nextGroup) : (a.view._toGlobalCoordinate(), a.separate(), a.view.bumpAway(null, 100)); + this._toLocalCoordinate(a.view._nextGroup); + var c = a.getNextBlock(); + if (c && c && c !== this.block) { + var e = this.block.getLastBlock(); + b ? c.view._toLocalCoordinate(a.view._nextGroup) : e.view.magnet.next ? c.view._toLocalCoordinate(e.view._nextGroup) : (c.view._toGlobalCoordinate(), c.separate(), c.view.bumpAway(null, 100)); } } else { if (a = this.block.getPrevBlock()) { - this._toLocalCoordinate(a.view._nextGroup), (a = this.block.getNextBlock()) && a.view && a.view._toLocalCoordinate(this._nextGroup); + this._toLocalCoordinate(a.view._nextGroup), (c = this.block.getNextBlock()) && c.view && c.view._toLocalCoordinate(this._nextGroup); } } }; @@ -23505,25 +23507,27 @@ Entry.Board.DRAG_RADIUS = 5; this.workspace.setMode(Entry.Workspace.MODE_BOARD, "save"); }; b.generateCodeMagnetMap = function() { - var a = this.code; - if (a && this.dragBlock) { - for (var b in this.dragBlock.magnet) { - var c = this._getCodeBlocks(a, b); - c.sort(function(a, b) { - return a.point - b.point; - }); - c.unshift({point:-Number.MAX_VALUE, blocks:[]}); - for (var e = 1;e < c.length;e++) { - var f = c[e], g = f, h = f.startBlock; - if (h) { - for (var k = f.endPoint, l = e;k > g.point && (g.blocks.push(h), l++, g = c[l], g);) { + var a = this.code, b = this.dragBlock; + if (a && b) { + for (var c in b.magnet) { + if ("next" !== c || void 0 !== b.block.getLastBlock().view.magnet.next) { + var e = this._getCodeBlocks(a, c); + e.sort(function(a, b) { + return a.point - b.point; + }); + e.unshift({point:-Number.MAX_VALUE, blocks:[]}); + for (var f = 1;f < e.length;f++) { + var g = e[f], h = g, k = g.startBlock; + if (k) { + for (var l = g.endPoint, m = f;l > h.point && (h.blocks.push(k), m++, h = e[m], h);) { + } + delete g.startBlock; } - delete f.startBlock; + g.endPoint = Number.MAX_VALUE; + e[f - 1].endPoint = g.point; } - f.endPoint = Number.MAX_VALUE; - c[e - 1].endPoint = f.point; + this._magnetMap[c] = e; } - this._magnetMap[b] = c; } } }; @@ -23537,8 +23541,7 @@ Entry.Board.DRAG_RADIUS = 5; f = this._getPreviousMagnets; break; case "string": - f = this._getFieldMagnets; - break; + ; case "boolean": f = this._getFieldMagnets; break; diff --git a/src/workspace/block_view.js b/src/workspace/block_view.js index 2c7bac9c7f..c8bf69a386 100644 --- a/src/workspace/block_view.js +++ b/src/workspace/block_view.js @@ -778,7 +778,7 @@ Entry.BlockView.pngMap = {}; return; var blockView = this; var svgGroup = blockView.svgGroup; - if (!this.magnet.next) {// field block + if (!(this.magnet.next || this.magnet.previous)) {// field block if (this.magneting) { svgGroup.attr({ filter: 'url(#entryBlockHighlightFilter_' + this.getBoard().suffix + ')' @@ -921,13 +921,16 @@ Entry.BlockView.pngMap = {}; } else that._moveBy(distance, distance, false); }; - p.bindPrev = function(prevBlock) { + p.bindPrev = function(prevBlock, isDestroy) { if (prevBlock) { this._toLocalCoordinate(prevBlock.view._nextGroup); var nextBlock = prevBlock.getNextBlock(); + if (nextBlock) if (nextBlock && nextBlock !== this.block) { var endBlock = this.block.getLastBlock(); - if (endBlock.view.magnet.next) + if (isDestroy) + nextBlock.view._toLocalCoordinate(prevBlock.view._nextGroup); + else if (endBlock.view.magnet.next) nextBlock.view._toLocalCoordinate(endBlock.view._nextGroup); else { nextBlock.view._toGlobalCoordinate(); diff --git a/src/workspace/board.js b/src/workspace/board.js index 553581fd7c..0db46e8a8a 100644 --- a/src/workspace/board.js +++ b/src/workspace/board.js @@ -395,9 +395,15 @@ Entry.Board.DRAG_RADIUS = 5; p.generateCodeMagnetMap = function() { var code = this.code; - if (!code || !this.dragBlock) return; + var dragBlock = this.dragBlock; + if (!(code && dragBlock)) return; + + for (var targetType in dragBlock.magnet) { + if (targetType === 'next' && + dragBlock.block.getLastBlock().view.magnet.next === undefined) { + continue; + } - for (var targetType in this.dragBlock.magnet) { var metaData = this._getCodeBlocks(code, targetType); metaData.sort(function(a, b) {return a.point - b.point;}); @@ -441,8 +447,6 @@ Entry.Board.DRAG_RADIUS = 5; func = this._getPreviousMagnets; break; case "string": - func = this._getFieldMagnets; - break; case "boolean": func = this._getFieldMagnets; break; From 2c09ed77bc6938c5aa2587c1375ae85742b954eb Mon Sep 17 00:00:00 2001 From: vivid Date: Mon, 17 Oct 2016 14:34:22 +0900 Subject: [PATCH 2/2] endBlock bug fix --- dist/entry.js | 3 ++- dist/entry.min.js | 60 +++++++++++++++++++++--------------------- src/workspace/block.js | 2 +- src/workspace/board.js | 3 +++ 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/dist/entry.js b/dist/entry.js index 232c588662..233ba25a24 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -23509,6 +23509,7 @@ Entry.Board.DRAG_RADIUS = 5; b.generateCodeMagnetMap = function() { var a = this.code, b = this.dragBlock; if (a && b) { + this._magnetMap = {}; for (var c in b.magnet) { if ("next" !== c || void 0 !== b.block.getLastBlock().view.magnet.next) { var e = this._getCodeBlocks(a, c); @@ -24328,7 +24329,7 @@ Entry.Block.DELETABLE_FALSE_LIGHTEN = 3; this.getCode().unregisterBlock(this); f = this.getThread(); this._schema && this._schema.event && f.unregisterEvent(this, this._schema.event); - c && (b ? c.destroy(a, b) : g ? c.view && c.view.bindPrev(g) : (b = this.getThread().view.getParent(), b.constructor === Entry.FieldStatement ? (c.view && c.view.bindPrev(b), b.insertTopBlock(c)) : b.constructor === Entry.FieldStatement ? c.replace(b._valueBlock) : c.view._toGlobalCoordinate())); + c && (b ? c.destroy(a, b) : g ? c.view && c.view.bindPrev(g, !0) : (b = this.getThread().view.getParent(), b.constructor === Entry.FieldStatement ? (c.view && c.view.bindPrev(b), b.insertTopBlock(c)) : b.constructor === Entry.FieldStatement ? c.replace(b._valueBlock) : c.view._toGlobalCoordinate())); !this.doNotSplice && f.spliceBlock ? f.spliceBlock(this) : delete this.doNotSplice; this.view && this.view.destroy(a); this._schemaChangeEvent && this._schemaChangeEvent.destroy(); diff --git a/dist/entry.min.js b/dist/entry.min.js index a10f26cf08..5aadd76132 100644 --- a/dist/entry.min.js +++ b/dist/entry.min.js @@ -2452,23 +2452,23 @@ e,g).isPass(f),a=!0),createjs.Sound.play("entryMagneting")):Entry.do("moveBlock" f?this.block.destroy(!1,!0):this.block.doDestroyBelow(!1)}b.setMagnetedBlock(null);a&&Entry.ConnectionRipple.setView(e.view).dispose()}this.destroyShadow();delete this.originPos;this.dominate()};b._updateCloseBlock=function(){var a=this.getBoard(),b;if(this._skeleton.magnets){for(var c in this.magnet)if(b="next"===c?this.getBoard().getNearestMagnet(this.x,this.y+this.getBelowHeight(),c):this.getBoard().getNearestMagnet(this.x,this.y,c))return a.setMagnetedBlock(b.view,c);a.setMagnetedBlock(null)}}; b.dominate=function(){this.block.getThread().view.dominate()};b.getSvgRoot=function(){for(var a=this.getBoard().svgBlockGroup,b=this.svgGroup;b.parentNode!==a;)b=b.parentNode;return b};b.getBoard=function(){return this._board};b._setBoard=function(){this._board=this._board.code.board};b.destroy=function(a){$(this.svgGroup).unbind(".blockViewMousedown");this._destroyObservers();var b=this.svgGroup;a?$(b).fadeOut(100,function(){b.remove()}):b.remove();this._contents.forEach(function(a){a.constructor!== Entry.Block&&a.destroy()});var c=this.block;a=c.events.viewDestroy;"workspace"==Entry.type&&a&&!this.isInBlockMenu&&a.forEach(function(a){Entry.Utils.isFunction(a)&&a(c)});this._schemaChangeEvent&&this._schemaChangeEvent.destroy()};b.getShadow=function(){this._shadow||(this._shadow=Entry.SVG.createElement(this.svgGroup.cloneNode(!0),{opacity:.5}),this.getBoard().svgGroup.appendChild(this._shadow));return this._shadow};b.destroyShadow=function(){this._shadow&&(this._shadow.remove(),delete this._shadow)}; -b._updateMagnet=function(){if(this._skeleton.magnets){var a=this._skeleton.magnets(this);a.next&&this._nextGroup.attr("transform","translate("+a.next.x+","+a.next.y+")");this.magnet=a;this.block.getThread().changeEvent.notify()}};b._updateBG=function(){if(this._board.dragBlock&&this._board.dragBlock.dragInstance){var a=this.svgGroup;if(this.magnet.next){if(a=this.magneting){var b=this._board.dragBlock.getShadow(),c=this.getAbsoluteCoordinate(),e;if("previous"===a)e=this.magnet.next,e="translate("+ -(c.x+e.x)+","+(c.y+e.y)+")";else if("next"===a){e=this.magnet.previous;var f=this._board.dragBlock.getBelowHeight();e="translate("+(c.x+e.x)+","+(c.y+e.y-f)+")"}$(b).attr({transform:e,display:"block"});this._clonedShadow=b;this.background&&(this.background.remove(),this.nextBackground.remove(),delete this.background,delete this.nextBackground);"previous"===a&&(a=this._board.dragBlock.getBelowHeight()+this.offsetY,this.originalHeight=this.offsetY,this.set({offsetY:a}))}else this._clonedShadow&&(this._clonedShadow.attr({display:"none"}), -delete this._clonedShadow),a=this.originalHeight,void 0!==a&&(this.background&&(this.background.remove(),this.nextBackground.remove(),delete this.background,delete this.nextBackground),this.set({offsetY:a}),delete this.originalHeight);(a=this.block.thread.changeEvent)&&a.notify()}else this.magneting?(a.attr({filter:"url(#entryBlockHighlightFilter_"+this.getBoard().suffix+")"}),a.addClass("outputHighlight")):(a.removeClass("outputHighlight"),a.removeAttr("filter"))}};b.addDragging=function(){this.svgGroup.addClass("dragging")}; -b.removeDragging=function(){this.svgGroup.removeClass("dragging")};b.addSelected=function(){this.svgGroup.addClass("selected")};b.removeSelected=function(){this.svgGroup.removeClass("selected")};b.getSkeleton=function(){return this._skeleton};b.getContentPos=function(){return this._skeleton.contentPos(this)};b.renderText=function(){this._startContentRender(Entry.Workspace.MODE_VIMBOARD)};b.renderBlock=function(){this._startContentRender(Entry.Workspace.MODE_BOARD)};b._updateOpacity=function(){this.svgGroup.attr({opacity:!1=== -this.visible?0:1});this.visible&&this._setPosition()};b._updateShadow=function(){this.shadow&&Entry.Utils.colorDarken(this._schema.color,.7)};b._setMovable=function(){this.movable=null!==this.block.isMovable()?this.block.isMovable():void 0!==this._skeleton.movable?this._skeleton.movable:!0};b._setReadOnly=function(){this.readOnly=null!==this.block.isReadOnly()?this.block.isReadOnly():void 0!==this._skeleton.readOnly?this._skeleton.readOnly:!1};b._setCopyable=function(){this.copyable=null!==this.block.isCopyable()? -this.block.isCopyable():void 0!==this._skeleton.copyable?this._skeleton.copyable:!0};b.bumpAway=function(a,b){var c=this;a=a||15;b?window.setTimeout(function(){c._moveBy(a,a,!1)},b):c._moveBy(a,a,!1)};b.bindPrev=function(a){if(a){if(this._toLocalCoordinate(a.view._nextGroup),(a=a.getNextBlock())&&a!==this.block){var b=this.block.getLastBlock();b.view.magnet.next?a.view._toLocalCoordinate(b.view._nextGroup):(a.view._toGlobalCoordinate(),a.separate(),a.view.bumpAway(null,100))}}else if(a=this.block.getPrevBlock())this._toLocalCoordinate(a.view._nextGroup), -(a=this.block.getNextBlock())&&a.view&&a.view._toLocalCoordinate(this._nextGroup)};b.getAbsoluteCoordinate=function(a){a=void 0!==a?a:this.dragMode;if(a===Entry.DRAG_MODE_DRAG)return{x:this.x,y:this.y};a=this.block.getThread().view.requestAbsoluteCoordinate(this);a.x+=this.x;a.y+=this.y;return a};b.getBelowHeight=function(){return this.block.getThread().view.requestPartHeight(this)};b._updateDisplay=function(){this.svgGroup.attr({display:!1===this.display?"none":"block"});this.display&&this._setPosition()}; -b._updateColor=function(){var a=this._schema.color;this.block.deletable===Entry.Block.DELETABLE_FALSE_LIGHTEN&&(a=Entry.Utils.colorLighten(a));this._fillColor=a;this._path.attr({fill:a});this._updateContents()};b._updateContents=function(){for(var a=0;a\s+/g,">").replace(/\s+(svgGroup)(defs)',h=this.svgGroup.getBoundingClientRect(),k=a?this.svgGroup:this.svgGroup.cloneNode(!0),l=this._skeleton.box(this),m=b?1:1.5,n=function(){var a=window.platform; -return a&&"windows"===a.name.toLowerCase()&&"7"===a.version[0]?!0:!1}()?.9:.95;-1<=+-x/".split(""),v=0;v\s+/g, +">").replace(/\s+(svgGroup)(defs)',h=this.svgGroup.getBoundingClientRect(),k=a?this.svgGroup:this.svgGroup.cloneNode(!0), +l=this._skeleton.box(this),m=b?1:1.5,n=function(){var a=window.platform;return a&&"windows"===a.name.toLowerCase()&&"7"===a.version[0]?!0:!1}()?.9:.95;-1<=+-x/".split(""),v=0;ve||c.splice(e,1)}};b.raiseEvent=function(a,b,c){a=this._eventMap[a];var e=[];if(void 0!==a){for(var f=0;fa&&(f=f+e+10,e=0,c=15);e=Math.max(e,k.width);l=c+15;h._moveTo(f-k.x,l,!1);c=c+k.height+15}}this.scroller.resizeScrollBar()};b.clear=function(){this.svgBlockGroup.remove();this.svgThreadGroup.remove()}; b.updateOffset=function(){this._offset=this.svg.getBoundingClientRect();var a=$(window),b=a.scrollTop(),a=a.scrollLeft(),c=this._offset;this.relativeOffset={top:c.top-b,left:c.left-a};this.btnWrapper&&this.btnWrapper.attr({transform:"translate("+(c.width/2-65)+","+(c.height-200)+")"})};b.generateButtons=function(){var a=this,b=this.svgGroup.elem("g");this.btnWrapper=b;var c=b.elem("text",{x:27,y:33,class:"entryFunctionButtonText"});c.textContent=Lang.Buttons.save;var e=b.elem("text",{x:102.5,y:33, class:"entryFunctionButtonText"});e.textContent=Lang.Buttons.cancel;var f=b.elem("circle",{cx:27.5,cy:27.5,r:27.5,class:"entryFunctionButton"}),b=b.elem("circle",{cx:102.5,cy:27.5,r:27.5,class:"entryFunctionButton"});$(f).bind("mousedown touchstart",function(){a.save()});$(c).bind("mousedown touchstart",function(){a.save()});$(b).bind("mousedown touchstart",function(){a.cancelEdit()});$(e).bind("mousedown touchstart",function(){a.cancelEdit()})};b.cancelEdit=function(){this.workspace.setMode(Entry.Workspace.MODE_BOARD, -"cancelEdit")};b.save=function(){this.workspace.setMode(Entry.Workspace.MODE_BOARD,"save")};b.generateCodeMagnetMap=function(){var a=this.code;if(a&&this.dragBlock)for(var b in this.dragBlock.magnet){var c=this._getCodeBlocks(a,b);c.sort(function(a,b){return a.point-b.point});c.unshift({point:-Number.MAX_VALUE,blocks:[]});for(var e=1;eg.point&&(g.blocks.push(h),l++,g=c[l],g););delete f.startBlock}f.endPoint=Number.MAX_VALUE; -c[e-1].endPoint=f.point}this._magnetMap[b]=c}};b._getCodeBlocks=function(a,b){var c=a.getThreads(),e=[],f;switch(b){case "previous":f=this._getNextMagnets;break;case "next":f=this._getPreviousMagnets;break;case "string":f=this._getFieldMagnets;break;case "boolean":f=this._getFieldMagnets;break;case "param":f=this._getOutputMagnets;break;default:return[]}for(var g=0;gc.endPoint)f=h+1;else{e=c.blocks;for(f=0;fh.point&&(h.blocks.push(k), +m++,h=e[m],h););delete g.startBlock}g.endPoint=Number.MAX_VALUE;e[f-1].endPoint=g.point}this._magnetMap[c]=e}}};b._getCodeBlocks=function(a,b){var c=a.getThreads(),e=[],f;switch(b){case "previous":f=this._getNextMagnets;break;case "next":f=this._getPreviousMagnets;break;case "string":case "boolean":f=this._getFieldMagnets;break;case "param":f=this._getOutputMagnets;break;default:return[]}for(var g=0;gc.endPoint)f=h+1;else{e=c.blocks;for(f=0;f