//>>built
define("dijit/tree/dndSource","dojo/_base/array dojo/_base/declare dojo/dnd/common dojo/dom-class dojo/dom-geometry dojo/_base/lang dojo/mouse dojo/on dojo/touch dojo/topic dojo/dnd/Manager ./_dndSelector".split(" "),function(n,y,z,w,A,m,B,F,G,p,l,C){return y("dijit.tree.dndSource",C,{isSource:!0,accept:["text","treeNode"],copyOnly:!1,dragThreshold:5,betweenThreshold:0,generateText:!0,constructor:function(a,e){e||(e={});m.mixin(this,e);var c=e.accept instanceof Array?e.accept:["text","treeNode"];
this.accept=null;if(c.length){this.accept={};for(var f=0;f<c.length;++f)this.accept[c[f]]=1}this.mouseDown=this.isDragging=!1;this.targetBox=this.targetAnchor=null;this.dropPosition="";this._lastY=this._lastX=0;this.sourceState="";this.isSource&&w.add(this.node,"dojoDndSource");this.targetState="";this.accept&&w.add(this.node,"dojoDndTarget");this.topics=[p.subscribe("/dnd/source/over",m.hitch(this,"onDndSourceOver")),p.subscribe("/dnd/start",m.hitch(this,"onDndStart")),p.subscribe("/dnd/drop",m.hitch(this,
"onDndDrop")),p.subscribe("/dnd/cancel",m.hitch(this,"onDndCancel"))]},checkAcceptance:function(){return!0},copyState:function(a){return this.copyOnly||a},destroy:function(){this.inherited(arguments);for(var a;a=this.topics.pop();)a.remove();this.targetAnchor=null},_onDragMouse:function(a,e){var c=l.manager(),f=this.targetAnchor,b=this.current,d=this.dropPosition,g="Over";b&&0<this.betweenThreshold&&(this.targetBox&&f==b||(this.targetBox=A.position(b.rowNode,!0)),a.pageY-this.targetBox.y<=this.betweenThreshold?
g="Before":a.pageY-this.targetBox.y>=this.targetBox.h-this.betweenThreshold&&(g="After"));if(e||b!=f||g!=d){f&&this._removeItemClass(f.rowNode,d);b&&this._addItemClass(b.rowNode,g);if(b)if(b==this.tree.rootNode&&"Over"!=g)c.canDrop(!1);else{d=f=!1;if(c.source==this){d="Over"===g;for(var h in this.selection){var k=this.selection[h];if(k.item===b.item){f=!0;break}k.getParent().id!==b.id&&(d=!1)}}c.canDrop(!f&&!d&&!this._isParentChildDrop(c.source,b.rowNode)&&this.checkItemAcceptance(b.rowNode,c.source,
g.toLowerCase()))}else c.canDrop(!1);this.targetAnchor=b;this.dropPosition=g}},onMouseMove:function(a){if(!this.isDragging||"Disabled"!=this.targetState){this.inherited(arguments);var e=l.manager();if(this.isDragging)this._onDragMouse(a);else if(this.mouseDown&&this.isSource&&(Math.abs(a.pageX-this._lastX)>=this.dragThreshold||Math.abs(a.pageY-this._lastY)>=this.dragThreshold)){var c=this.getSelectedTreeNodes();if(c.length){if(1<c.length){var f=this.selection,b=0,d=[],g,h;a:for(;g=c[b++];){for(h=
g.getParent();h&&h!==this.tree;h=h.getParent())if(f[h.id])continue a;d.push(g)}c=d}c=n.map(c,function(k){return k.domNode});e.startDrag(this,c,this.copyState(z.getCopyKeyState(a)));this._onDragMouse(a,!0)}}}},onMouseDown:function(a){if("touchstart"==a.type||B.isLeft(a))this.mouseDown=!0,this.mouseButton=a.button,this._lastX=a.pageX,this._lastY=a.pageY;this.inherited(arguments)},onMouseUp:function(a){this.mouseDown&&(this.mouseDown=!1,this.inherited(arguments))},onMouseOut:function(){this.inherited(arguments);
this._unmarkTargetAnchor()},checkItemAcceptance:function(){return!0},onDndSourceOver:function(a){this!=a?(this.mouseDown=!1,this._unmarkTargetAnchor()):this.isDragging&&l.manager().canDrop(!1)},onDndStart:function(a,e,c){this.isSource&&this._changeState("Source",this==a?c?"Copied":"Moved":"");e=this.checkAcceptance(a,e);this._changeState("Target",e?"":"Disabled");this==a&&l.manager().overSource(this);this.isDragging=!0},itemCreator:function(a){return n.map(a,function(e){return{id:e.id,name:e.textContent||
e.innerText||""}})},onDndDrop:function(a,e,c){if("Over"==this.containerState){var f=this.tree,b=f.model,d=this.targetAnchor,g=!1;this.isDragging=!1;var h=d&&d.item||f.item;if("Before"==this.dropPosition||"After"==this.dropPosition){h=d.getParent()&&d.getParent().item||f.item;var k=d.getIndexInParent();if("After"==this.dropPosition){k=d.getIndexInParent()+1;var q=d.getNextSibling()&&d.getNextSibling().item}else q=d.item}else h=d&&d.item||f.item,g=!0;var r;n.forEach(e,function(D,E){var x=a.getItem(D.id);
if(-1!=n.indexOf(x.type,"treeNode"))var t=x.data,u=t.item,v=t.getParent().item;a==this?("number"==typeof k&&h==v&&t.getIndexInParent()<k&&--k,b.pasteItem(u,v,h,c,k,q)):b.isItem(u)?b.pasteItem(u,v,h,c,k,q):(r||(r=this.itemCreator(e,d.rowNode,a)),b.newItem(r[E],h,k,q))},this);g&&this.tree._expandNode(d)}this.onDndCancel()},onDndCancel:function(){this._unmarkTargetAnchor();this.mouseDown=this.isDragging=!1;delete this.mouseButton;this._changeState("Source","");this._changeState("Target","")},onOverEvent:function(){this.inherited(arguments);
l.manager().overSource(this)},onOutEvent:function(){this._unmarkTargetAnchor();var a=l.manager();this.isDragging&&a.canDrop(!1);a.outSource(this);this.inherited(arguments)},_isParentChildDrop:function(a,e){if(!a.tree||a.tree!=this.tree)return!1;for(var c=a.tree.domNode,f=a.selection,b=e.parentNode;b!=c&&!f[b.id];)b=b.parentNode;return b.id&&f[b.id]},_unmarkTargetAnchor:function(){this.targetAnchor&&(this._removeItemClass(this.targetAnchor.rowNode,this.dropPosition),this.dropPosition=this.targetBox=
this.targetAnchor=null)},_markDndStatus:function(a){this._changeState("Source",a?"Copied":"Moved")}})});