3 lines
38 KiB
JavaScript
3 lines
38 KiB
JavaScript
define("local_treestudyplan/vue-easy-dnd/vue-easy-dnd.esm",["exports","../vue/vue"],(function(_exports,_vue){function _toConsumableArray(arr){return function(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr)}(arr)||function(iter){if("undefined"!=typeof Symbol&&null!=iter[Symbol.iterator]||null!=iter["@@iterator"])return Array.from(iter)}(arr)||_unsupportedIterableToArray(arr)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _typeof(obj){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}function _slicedToArray(arr,i){return function(arr){if(Array.isArray(arr))return arr}(arr)||function(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null==_i)return;var _s,_e,_arr=[],_n=!0,_d=!1;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i.return||_i.return()}finally{if(_d)throw _e}}return _arr}(arr,i)||_unsupportedIterableToArray(arr,i)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _createForOfIteratorHelper(o,allowArrayLike){var it="undefined"!=typeof Symbol&&o[Symbol.iterator]||o["@@iterator"];if(!it){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&"number"==typeof o.length){it&&(o=it);var i=0,F=function(){};return{s:F,n:function(){return i>=o.length?{done:!0}:{done:!1,value:o[i++]}},e:function(_e2){throw _e2},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var err,normalCompletion=!0,didErr=!1;return{s:function(){it=it.call(o)},n:function(){var step=it.next();return normalCompletion=step.done,step},e:function(_e3){didErr=!0,err=_e3},f:function(){try{normalCompletion||null==it.return||it.return()}finally{if(didErr)throw err}}}}function _unsupportedIterableToArray(o,minLen){if(o){if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,minLen):void 0}}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter((function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable}))),keys.push.apply(keys,symbols)}return keys}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys(Object(source),!0).forEach((function(key){_defineProperty(target,key,source[key])})):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach((function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))}))}return target}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Object.defineProperty(Constructor,"prototype",{writable:!1}),Constructor}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.ReorderEvent=_exports.InsertEvent=_exports.DropMixin=_exports.DropMask=_exports.DropList=_exports.Drop=_exports.DragMixin=_exports.DragImagesManager=_exports.DragFeedback=_exports.DragAwareMixin=_exports.Drag=_exports.DnDEvent=void 0,_exports.createDragImage=_createDragImage,_exports.dnd=void 0;var DnD=function(){function DnD(){var n;_classCallCheck(this,DnD),_defineProperty(this,"inProgress",!1),_defineProperty(this,"type",null),_defineProperty(this,"data",null),_defineProperty(this,"source",null),_defineProperty(this,"top",null),_defineProperty(this,"position",null),_defineProperty(this,"eventBus",{all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e])},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]))},emit:function(t,e){var i=n.get(t);i&&i.slice().map((function(n){n(e)})),(i=n.get("*"))&&i.slice().map((function(n){n(t,e)}))}}),_defineProperty(this,"success",null)}return _createClass(DnD,[{key:"startDrag",value:function(source,event,x,y,type,data){this.type=type,this.data=data,this.source=source,this.position={x:x,y:y},this.top=null,this.inProgress=!0,this.emit(event,"dragstart"),this.emit(event,"dragtopchanged",{previousTop:null})}},{key:"resetVariables",value:function(){this.inProgress=!1,this.data=null,this.source=null,this.position=null,this.success=null}},{key:"stopDrag",value:function(event){this.success=null!==this.top&&this.top.compatibleMode&&this.top.dropAllowed,null!==this.top&&this.emit(event,"drop"),this.emit(event,"dragend"),this.resetVariables()}},{key:"cancelDrag",value:function(event){this.success=!1,this.emit(event,"dragend"),this.resetVariables()}},{key:"mouseMove",value:function(event,comp){if(this.inProgress){var prevent=!1,previousTop=this.top;null===comp||comp.isDropMask?(this.top=null,prevent=!0):comp.candidate(this.type,this.data,this.source)&&(this.top=comp,prevent=!0),prevent&&event.stopPropagation(),this.top!==previousTop&&this.emit(event.detail.native,"dragtopchanged",{previousTop:previousTop}),this.position={x:event.detail.x,y:event.detail.y},this.emit(event.detail.native,"dragpositionchanged")}}},{key:"emit",value:function(native,event){var data=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.eventBus.emit(event,_objectSpread({type:this.type,data:this.data,top:this.top,source:this.source,position:this.position,success:this.success,native:native},data))}},{key:"on",value:function(event,callback){this.eventBus.on(event,callback)}},{key:"off",value:function(event,callback){this.eventBus.off(event,callback)}}]),DnD}(),dnd=(0,_vue.reactive)(new DnD);_exports.dnd=dnd;var DragAwareMixin={data:function(){return{isDropMask:!1}},computed:{dragInProgress:function(){return dnd.inProgress},dragData:function(){return dnd.data},dragType:function(){return dnd.type},dragPosition:function(){return dnd.position},dragSource:function(){return dnd.source},dragTop:function(){return dnd.top}}};function _createDragImage(el){var clone=function(el){var clone=el.cloneNode(!0);copyStyle(el,clone);for(var vSrcElements=el.getElementsByTagName("*"),vDstElements=clone.getElementsByTagName("*"),i=vSrcElements.length;i--;){copyStyle(vSrcElements[i],vDstElements[i])}return clone}(el);return clone.style.position="fixed",clone.style.margin="0",clone.style["z-index"]="1000",clone.style.transition="opacity 0.2s",clone}function copyStyle(src,destination){var _step,computedStyle=window.getComputedStyle(src),_iterator=_createForOfIteratorHelper(computedStyle);try{for(_iterator.s();!(_step=_iterator.n()).done;){var key=_step.value;if("width"===key){var width="border-box"===computedStyle.getPropertyValue("box-sizing")?src.clientWidth:src.clientWidth-parseFloat(computedStyle.paddingLeft)-parseFloat(computedStyle.paddingRight);destination.style.setProperty("width",width+"px")}else if("height"===key){var height="border-box"===computedStyle.getPropertyValue("box-sizing")?src.clientHeight:src.clientHeight-parseFloat(computedStyle.paddingTop)-parseFloat(computedStyle.paddingBottom);destination.style.setProperty("height",height+"px")}else destination.style.setProperty(key,computedStyle.getPropertyValue(key),computedStyle.getPropertyPriority(key))}}catch(err){_iterator.e(err)}finally{_iterator.f()}destination.style.pointerEvents="none"}_exports.DragAwareMixin=DragAwareMixin;var regex=/(auto|scroll)/,style=function(node,prop){return getComputedStyle(node,null).getPropertyValue(prop)},scrollparent=function scrollparent(node){return node&&node!==document.body?function(node){return regex.test(style(node,"overflow")+style(node,"overflow-y")+style(node,"overflow-x"))}(node)?node:scrollparent(node.parentNode):document.body},timer=null;function cancelScrollAction(){clearTimeout(timer)}function performEdgeScroll(event,container,clientX,clientY,edgeSize){if(!container||!edgeSize)return cancelScrollAction(),!1;var rect=container.getBoundingClientRect(),isBody=container===document.body,viewportX=clientX-rect.left,viewportY=clientY-rect.top;isBody&&(viewportX=clientX,viewportY=clientY);var viewportWidth=rect.width,viewportHeight=rect.height;isBody&&(viewportWidth=document.documentElement.clientWidth,viewportHeight=document.documentElement.clientHeight);var edgeTop=edgeSize,edgeLeft=edgeSize,edgeBottom=viewportHeight-edgeSize,edgeRight=viewportWidth-edgeSize,isInLeftEdge=viewportX<edgeLeft,isInRightEdge=viewportX>edgeRight,isInTopEdge=viewportY<edgeTop,isInBottomEdge=viewportY>edgeBottom;if(!(isInLeftEdge||isInRightEdge||isInTopEdge||isInBottomEdge))return cancelScrollAction(),!1;var documentWidth=Math.max(container.scrollWidth,container.offsetWidth,container.clientWidth),documentHeight=Math.max(container.scrollHeight,container.offsetHeight,container.clientHeight),maxScrollX=documentWidth-viewportWidth,maxScrollY=documentHeight-viewportHeight;return function checkForWindowScroll(){cancelScrollAction(),function(){var currentScrollX=container.scrollLeft,currentScrollY=container.scrollTop;isBody&&(currentScrollX=window.pageXOffset,currentScrollY=window.pageYOffset);var canScrollUp=currentScrollY>0,canScrollDown=currentScrollY<maxScrollY,canScrollLeft=currentScrollX>0,canScrollRight=currentScrollX<maxScrollX,nextScrollX=currentScrollX,nextScrollY=currentScrollY,maxStep=50;if(isInLeftEdge&&canScrollLeft){nextScrollX-=maxStep*((edgeLeft-viewportX)/edgeSize)}else if(isInRightEdge&&canScrollRight){nextScrollX+=maxStep*((viewportX-edgeRight)/edgeSize)}if(isInTopEdge&&canScrollUp){nextScrollY-=maxStep*((edgeTop-viewportY)/edgeSize)}else if(isInBottomEdge&&canScrollDown){nextScrollY+=maxStep*((viewportY-edgeBottom)/edgeSize)}return nextScrollX=Math.max(0,Math.min(maxScrollX,nextScrollX)),nextScrollY=Math.max(0,Math.min(maxScrollY,nextScrollY)),(nextScrollX!==currentScrollX||nextScrollY!==currentScrollY)&&((isBody?window:container).scrollTo(nextScrollX,nextScrollY),!0)}()&&(timer=setTimeout(checkForWindowScroll,30))}(),!0}var DragMixin={mixins:[DragAwareMixin],props:{type:{type:String,default:null},data:{default:null},dragImageOpacity:{type:Number,default:.7},disabled:{type:Boolean,default:!1},goBack:{type:Boolean,default:!1},handle:{type:String,default:null},delta:{type:Number,default:0},delay:{type:Number,default:0},dragClass:{type:String,default:null},vibration:{type:Number,default:0},scrollingEdgeSize:{type:Number,default:100}},emits:["dragstart","dragend","cut","copy"],data:function(){return{dragInitialised:!1,dragStarted:!1,ignoreNextClick:!1,initialUserSelect:null,downEvent:null,startPosition:null,delayTimer:null,scrollContainer:null}},computed:{cssClasses:function(){var clazz={"dnd-drag":!0};return this.disabled?clazz:_objectSpread(_objectSpread({},clazz),{},{"drag-source":this.dragInProgress&&this.dragSource===this,"drag-mode-copy":"copy"===this.currentDropMode,"drag-mode-cut":"cut"===this.currentDropMode,"drag-mode-reordering":"reordering"===this.currentDropMode,"drag-no-handle":!this.handle})},currentDropMode:function(){return this.dragInProgress&&this.dragSource===this&&this.dragTop&&this.dragTop.dropAllowed?this.dragTop.reordering?"reordering":this.dragTop.mode:null}},methods:{onSelectStart:function(e){e.stopPropagation(),e.preventDefault()},performVibration:function(){this.vibration>0&&window.navigator&&window.navigator.vibrate&&window.navigator.vibrate(this.vibration)},onMouseDown:function(e){var _this=this,target=null,goodButton=!1;if("mousedown"===e.type){var mouse=e;target=e.target,goodButton=1===mouse.buttons}else{target=e.touches[0].target,goodButton=!0}if(!this.disabled&&null===this.downEvent&&goodButton&&(!target.matches(".dnd-no-drag, .dnd-no-drag *")&&(!this.handle||target.matches(this.handle+", "+this.handle+" *")))){if(this.scrollContainer=scrollparent(target),this.initialUserSelect=document.body.style.userSelect,document.documentElement.style.userSelect="none",this.dragStarted=!1,this.downEvent=e,"mousedown"===this.downEvent.type){var _mouse=e;this.startPosition={x:_mouse.clientX,y:_mouse.clientY}}else{var _touch=e;this.startPosition={x:_touch.touches[0].clientX,y:_touch.touches[0].clientY}}this.delay?(this.dragInitialised=!1,clearTimeout(this.delayTimer),this.delayTimer=setTimeout((function(){_this.dragInitialised=!0,_this.performVibration()}),this.delay)):(this.dragInitialised=!0,this.performVibration()),document.addEventListener("click",this.onMouseClick,!0),document.addEventListener("mouseup",this.onMouseUp),document.addEventListener("touchend",this.onMouseUp),document.addEventListener("selectstart",this.onSelectStart),document.addEventListener("keyup",this.onKeyUp),setTimeout((function(){document.addEventListener("mousemove",_this.onMouseMove),document.addEventListener("touchmove",_this.onMouseMove,{passive:!1}),document.addEventListener("easy-dnd-move",_this.onEasyDnDMove)}),0),e.stopPropagation()}},onMouseClick:function(e){if(this.ignoreNextClick)return e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation(),this.ignoreNextClick=!1,!1},onMouseMove:function(e){if(null!==this.downEvent&&("touchstart"!==this.downEvent.type||"mousemove"!==e.type)){var target=null,x=null,y=null;if("touchmove"===e.type){var touch=e;if(x=touch.touches[0].clientX,y=touch.touches[0].clientY,!(target=document.elementFromPoint(x,y)))return}else{var mouse=e;x=mouse.clientX,y=mouse.clientY,target=mouse.target}var dist=Math.sqrt(Math.pow(this.startPosition.x-x,2)+Math.pow(this.startPosition.y-y,2));if(!this.dragStarted&&dist>this.delta&&(this.dragInitialised?(this.ignoreNextClick=!0,this.dragStarted=!0,dnd.startDrag(this,this.downEvent,this.startPosition.x,this.startPosition.y,this.type,this.data),document.documentElement.classList.add("drag-in-progress")):clearTimeout(this.delayTimer)),this.dragStarted){var currEdgeSize=this.dragTop&&void 0!==this.dragTop.$props.scrollingEdgeSize?this.dragTop.$props.scrollingEdgeSize:this.scrollingEdgeSize;if(currEdgeSize)performEdgeScroll(0,this.dragTop?scrollparent(this.dragTop.$el):this.scrollContainer,x,y,currEdgeSize);else cancelScrollAction();var custom=new CustomEvent("easy-dnd-move",{bubbles:!0,cancelable:!0,detail:{x:x,y:y,native:e}});target.dispatchEvent(custom)}this.dragInitialised&&e.cancelable&&e.preventDefault()}},onEasyDnDMove:function(e){dnd.mouseMove(e,null)},onMouseUp:function(e){var _this2=this;"touchstart"===this.downEvent.type&&"mouseup"===e.type||setTimeout((function(){_this2.cancelDragActions(),_this2.dragStarted&&dnd.stopDrag(e),_this2.finishDrag()}),0)},onKeyUp:function(e){var _this3=this;"Escape"===e.key&&(this.cancelDragActions(),setTimeout((function(){dnd.cancelDrag(e),_this3.finishDrag()}),0))},cancelDragActions:function(){this.dragInitialised=!1,clearTimeout(this.delayTimer),cancelScrollAction()},finishDrag:function(){this.downEvent=null,this.scrollContainer=null,this.dragStarted&&document.documentElement.classList.remove("drag-in-progress"),document.removeEventListener("click",this.onMouseClick,!0),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("touchmove",this.onMouseMove),document.removeEventListener("easy-dnd-move",this.onEasyDnDMove),document.removeEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchend",this.onMouseUp),document.removeEventListener("selectstart",this.onSelectStart),document.removeEventListener("keyup",this.onKeyUp),document.documentElement.style.userSelect=this.initialUserSelect},dndDragStart:function(ev){ev.source===this&&this.$emit("dragstart",ev)},dndDragEnd:function(ev){ev.source===this&&this.$emit("dragend",ev)},createDragImage:function(selfTransform){var image;if(this.$slots["drag-image"]){var el=this.$refs["drag-image"]||document.createElement("div");image=1!==el.childElementCount?_createDragImage(el):_createDragImage(el.children.item(0))}else(image=_createDragImage(this.$el)).style.transform=selfTransform;return this.dragClass&&image.classList.add(this.dragClass),image.classList.add("dnd-ghost"),image.__opacity=this.dragImageOpacity,image}},created:function(){dnd.on("dragstart",this.dndDragStart),dnd.on("dragend",this.dndDragEnd)},mounted:function(){this.$el.addEventListener("mousedown",this.onMouseDown),this.$el.addEventListener("touchstart",this.onMouseDown)},beforeUnmount:function(){dnd.off("dragstart",this.dndDragStart),dnd.off("dragend",this.dndDragEnd),this.$el.removeEventListener("mousedown",this.onMouseDown),this.$el.removeEventListener("touchstart",this.onMouseDown)}};_exports.DragMixin=DragMixin;var script$4={name:"Drag",mixins:[DragMixin],props:{tag:{type:[String,Object,Function],default:"div"}},computed:{dynamicSlots:function(){return Object.entries(this.$slots).filter((function(_ref){var key=_slicedToArray(_ref,1)[0];return"drag-image"!==key&&"default"!==key}))}}};_exports.Drag=script$4;var _hoisted_1$2={key:0,ref:"drag-image",class:"__drag-image"};function _dropAllowed(inst){return inst.dragInProgress&&inst.typeAllowed?inst.compatibleMode&&inst.effectiveAcceptsData(inst.dragData,inst.dragType):null}function _doDrop(inst,event){inst.$emit("drop",event),event.source.$emit(inst.mode,event)}function _candidate(inst,type){return inst.effectiveAcceptsType(type)}script$4.render=function(_ctx,_cache,$props,$setup,$data,$options){return(0,_vue.openBlock)(),(0,_vue.createBlock)((0,_vue.resolveDynamicComponent)($props.tag),{class:(0,_vue.normalizeClass)(_ctx.cssClasses)},(0,_vue.createSlots)({default:(0,_vue.withCtx)((function(){return[(0,_vue.renderSlot)(_ctx.$slots,"default",(0,_vue.normalizeProps)((0,_vue.guardReactiveProps)(_ctx.$slots.default||{}))),_ctx.dragInitialised?((0,_vue.openBlock)(),(0,_vue.createElementBlock)("div",_hoisted_1$2,[(0,_vue.renderSlot)(_ctx.$slots,"drag-image")],512)):(0,_vue.createCommentVNode)("v-if",!0)]})),_:2},[(0,_vue.renderList)($options.dynamicSlots,(function(_ref3){var _ref4=_slicedToArray(_ref3,2),slot=_ref4[0],args=_ref4[1];return{name:slot,fn:(0,_vue.withCtx)((function(){return[(0,_vue.renderSlot)(_ctx.$slots,slot,(0,_vue.normalizeProps)((0,_vue.guardReactiveProps)(args)))]}))}}))]),1032,["class"])},script$4.__scopeId="data-v-f87407ce";var DropMixin={mixins:[DragAwareMixin],props:{acceptsType:{type:[String,Array,Function],default:null},acceptsData:{type:Function,default:function(){return!0}},mode:{type:String,default:"copy"},dragImageOpacity:{type:Number,default:.7}},emits:["dragover","dragenter","dragleave","dragend","drop"],data:function(){return{isDrop:!0}},computed:{compatibleMode:function(){return!!this.dragInProgress||null},dropIn:function(){return this.dragInProgress?this.dragTop===this:null},typeAllowed:function(){return this.dragInProgress?this.effectiveAcceptsType(this.dragType):null},dropAllowed:function(){return _dropAllowed(this)},cssClasses:function(){var clazz={"dnd-drop":!0};return null!==this.dropIn&&(clazz["drop-in"]=this.dropIn,clazz["drop-out"]=!this.dropIn),null!==this.typeAllowed&&(clazz["type-allowed"]=this.typeAllowed,clazz["type-forbidden"]=!this.typeAllowed),null!==this.dropAllowed&&(clazz["drop-allowed"]=this.dropAllowed,clazz["drop-forbidden"]=!this.dropAllowed),clazz}},methods:{effectiveAcceptsType:function(type){return null===this.acceptsType||("string"==typeof this.acceptsType||"number"==typeof this.acceptsType?this.acceptsType===type:"object"===_typeof(this.acceptsType)&&Array.isArray(this.acceptsType)?this.acceptsType.includes(type):this.acceptsType(type))},effectiveAcceptsData:function(data,type){return this.acceptsData(data,type)},onDragPositionChanged:function(event){this===event.top&&this.$emit("dragover",event)},onDragTopChanged:function(event){this===event.top&&this.$emit("dragenter",event),this===event.previousTop&&this.$emit("dragleave",event)},onDragEnd:function(event){this===event.top&&this.$emit("dragend",event)},onDrop:function(event){this.dropIn&&this.compatibleMode&&this.dropAllowed&&this.doDrop(event)},doDrop:function(event){_doDrop(this,event)},candidate:function(type){return _candidate(this,type)},createDragImage:function(){var image="source";if(this.$refs["drag-image"]){var el=this.$refs["drag-image"];(image=1!==el.childElementCount?_createDragImage(el):_createDragImage(el.children.item(0))).__opacity=this.dragImageOpacity,image.classList.add("dnd-ghost")}return image},onDnDMove:function(e){dnd.mouseMove(e,this)}},created:function(){dnd.on("dragpositionchanged",this.onDragPositionChanged),dnd.on("dragtopchanged",this.onDragTopChanged),dnd.on("drop",this.onDrop),dnd.on("dragend",this.onDragEnd)},mounted:function(){this.$el.addEventListener("easy-dnd-move",this.onDnDMove)},beforeUnmount:function(){this.$el.removeEventListener("easy-dnd-move",this.onDnDMove),dnd.off("dragpositionchanged",this.onDragPositionChanged),dnd.off("dragtopchanged",this.onDragTopChanged),dnd.off("drop",this.onDrop),dnd.off("dragend",this.onDragEnd)}};_exports.DropMixin=DropMixin;var script$3={name:"Drop",mixins:[DropMixin],props:{tag:{type:[String,Object,Function],default:"div"}},computed:{dynamicSlots:function(){return Object.entries(this.$slots).filter((function(_ref5){var key=_slicedToArray(_ref5,1)[0];return"drag-image"!==key&&"default"!==key}))},showDragImage:function(){return this.dragInProgress&&this.typeAllowed&&!!this.$slots["drag-image"]}}};_exports.Drop=script$3;var _hoisted_1$1={key:0,ref:"drag-image",class:"__drag-image"};script$3.render=function(_ctx,_cache,$props,$setup,$data,$options){return(0,_vue.openBlock)(),(0,_vue.createBlock)((0,_vue.resolveDynamicComponent)($props.tag),{class:(0,_vue.normalizeClass)(_ctx.cssClasses)},(0,_vue.createSlots)({default:(0,_vue.withCtx)((function(){return[(0,_vue.renderSlot)(_ctx.$slots,"default",(0,_vue.normalizeProps)((0,_vue.guardReactiveProps)(_ctx.$slots.default||{}))),$options.showDragImage?((0,_vue.openBlock)(),(0,_vue.createElementBlock)("div",_hoisted_1$1,[(0,_vue.renderSlot)(_ctx.$slots,"drag-image",{type:_ctx.dragType,data:_ctx.dragData})],512)):(0,_vue.createCommentVNode)("v-if",!0)]})),_:2},[(0,_vue.renderList)($options.dynamicSlots,(function(_ref7){var _ref8=_slicedToArray(_ref7,2),slot=_ref8[0],args=_ref8[1];return{name:slot,fn:(0,_vue.withCtx)((function(){return[(0,_vue.renderSlot)(_ctx.$slots,slot,(0,_vue.normalizeProps)((0,_vue.guardReactiveProps)(args)))]}))}}))]),1032,["class"])},script$3.__scopeId="data-v-12a39e52";var script$2={name:"DropMask",mixins:[DragAwareMixin],props:{tag:{type:[String,Object,Function],default:"div"}},data:function(){return{isDropMask:!0}},mounted:function(){this.$el.addEventListener("easy-dnd-move",this.onDndMove)},beforeUnmount:function(){this.$el.removeEventListener("easy-dnd-move",this.onDndMove)},methods:{createDragImage:function(){return"source"},onDndMove:function(e){dnd.mouseMove(e,this)}}};_exports.DropMask=script$2,script$2.render=function(_ctx,_cache,$props,$setup,$data,$options){return(0,_vue.openBlock)(),(0,_vue.createBlock)((0,_vue.resolveDynamicComponent)($props.tag),null,(0,_vue.createSlots)({_:2},[(0,_vue.renderList)(_ctx.$slots,(function(args,slot){return{name:slot,fn:(0,_vue.withCtx)((function(){return[(0,_vue.renderSlot)(_ctx.$slots,slot,(0,_vue.normalizeProps)((0,_vue.guardReactiveProps)(args)))]}))}}))]),1024)};var script$1={name:"DragFeedback"};_exports.DragFeedback=script$1;var _hoisted_1={class:"DragFeedback"};script$1.render=function(_ctx,_cache,$props,$setup,$data,$options){return(0,_vue.openBlock)(),(0,_vue.createElementBlock)("div",_hoisted_1,[(0,_vue.renderSlot)(_ctx.$slots,"default")])};var Grid=function(){function Grid(collection,upToIndex,direction,fromIndex){_classCallCheck(this,Grid),_defineProperty(this,"reference",void 0),_defineProperty(this,"referenceOriginalPosition",void 0),_defineProperty(this,"magnets",[]),this.reference=collection.item(0).parentNode,this.referenceOriginalPosition={x:this.reference.getBoundingClientRect().left-this.reference.scrollLeft,y:this.reference.getBoundingClientRect().top-this.reference.scrollTop};var _step2,index=0,_iterator2=_createForOfIteratorHelper(collection);try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var child=_step2.value;if(index>upToIndex)break;var rect=child.getBoundingClientRect(),hasNestedDrop=child.classList.contains("dnd-drop")||child.getElementsByClassName("dnd-drop").length>0,horizontal=!1;if(hasNestedDrop){if("auto"===direction)throw"Easy-DnD error : a drop list is missing one of these attributes : 'row' or 'column'.";horizontal="row"===direction}null===fromIndex?this.magnets.push(hasNestedDrop?this.before(rect,horizontal):this.center(rect)):this.magnets.push(hasNestedDrop?(fromIndex<index?this.after:this.before)(rect,horizontal):this.center(rect)),index++}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}}return _createClass(Grid,[{key:"center",value:function(rect){return{x:rect.left+rect.width/2,y:rect.top+rect.height/2}}},{key:"before",value:function(rect,horizontal){return horizontal?{x:rect.left,y:rect.top+rect.height/2}:{x:rect.left+rect.width/2,y:rect.top}}},{key:"after",value:function(rect,horizontal){return horizontal?{x:rect.left+rect.width,y:rect.top+rect.height/2}:{x:rect.left+rect.width/2,y:rect.top+rect.height}}},{key:"correction",value:function(){return{x:this.reference.getBoundingClientRect().left-this.reference.scrollLeft-this.referenceOriginalPosition.x,y:this.reference.getBoundingClientRect().top-this.reference.scrollTop-this.referenceOriginalPosition.y}}},{key:"closestIndex",value:function(position){for(var x=position.x-this.correction().x,y=position.y-this.correction().y,minDist=999999,index=-1,i=0;i<this.magnets.length;i++){var magnet=this.magnets[i],dist=Math.sqrt(Math.pow(magnet.x-x,2)+Math.pow(magnet.y-y,2));dist<minDist&&(minDist=dist,index=i)}return index}}]),Grid}(),DnDEvent=_createClass((function DnDEvent(){_classCallCheck(this,DnDEvent),_defineProperty(this,"type",void 0),_defineProperty(this,"data",void 0),_defineProperty(this,"top",void 0),_defineProperty(this,"previousTop",void 0),_defineProperty(this,"source",void 0),_defineProperty(this,"position",void 0),_defineProperty(this,"success",void 0),_defineProperty(this,"native",void 0)}));_exports.DnDEvent=DnDEvent;var ReorderEvent=function(){function ReorderEvent(from,to){_classCallCheck(this,ReorderEvent),_defineProperty(this,"from",void 0),_defineProperty(this,"to",void 0),this.from=from,this.to=to}return _createClass(ReorderEvent,[{key:"apply",value:function(array){var temp=array[this.from];array.splice(this.from,1),array.splice(this.to,0,temp)}}]),ReorderEvent}();_exports.ReorderEvent=ReorderEvent;var InsertEvent=_createClass((function InsertEvent(type,data,index){_classCallCheck(this,InsertEvent),_defineProperty(this,"type",void 0),_defineProperty(this,"data",void 0),_defineProperty(this,"index",void 0),this.type=type,this.data=data,this.index=index}));_exports.InsertEvent=InsertEvent;var script={name:"DropList",mixins:[DropMixin],props:{tag:{type:[String,Object,Function],default:"div"},items:{type:Array,required:!0},row:{type:Boolean,default:!1},column:{type:Boolean,default:!1},noAnimations:{type:Boolean,default:!1},scrollingEdgeSize:{type:Number,default:void 0}},emits:["reorder","insert"],data:function(){return{grid:null,forbiddenKeys:[],feedbackKey:null,fromIndex:null}},computed:{rootTag:function(){return this.noAnimations?this.tag:_vue.TransitionGroup},rootProps:function(){return this.noAnimations?{}:{tag:this.tag,css:!1}},direction:function(){return this.row?"row":this.column?"column":"auto"},reordering:function(){return dnd.inProgress?dnd.source.$el.parentElement===this.$el:null},closestIndex:function(){return this.grid?this.grid.closestIndex(dnd.position):null},dropAllowed:function(){return this.dragInProgress?this.reordering?this.items.length>1:!!_dropAllowed(this)&&(null===this.forbiddenKeys||null===this.feedbackKey||!this.forbiddenKeys.includes(this.feedbackKey)):null},itemsBeforeFeedback:function(){return 0===this.closestIndex?[]:this.items.slice(0,this.closestIndex)},itemsAfterFeedback:function(){return this.closestIndex===this.items.length?[]:this.items.slice(this.closestIndex)},itemsBeforeReorderingFeedback:function(){return this.closestIndex<=this.fromIndex?this.items.slice(0,this.closestIndex):this.items.slice(0,this.closestIndex+1)},itemsAfterReorderingFeedback:function(){return this.closestIndex<=this.fromIndex?this.items.slice(this.closestIndex):this.items.slice(this.closestIndex+1)},reorderedItems:function(){var toIndex=this.closestIndex,reordered=_toConsumableArray(this.items),temp=reordered[this.fromIndex];return reordered.splice(this.fromIndex,1),reordered.splice(toIndex,0,temp),reordered},clazz:function(){return _objectSpread({"drop-list":!0,reordering:!0===this.reordering,inserting:!1===this.reordering},!1===this.reordering?this.cssClasses:{"dnd-drop":!0})},showDragFeedback:function(){return this.dragInProgress&&this.typeAllowed&&!this.reordering},showInsertingDragImage:function(){return this.dragInProgress&&this.typeAllowed&&!this.reordering&&!!this.$slots["drag-image"]},showReorderingDragImage:function(){return this.dragInProgress&&this.reordering&&!!this.$slots["reordering-drag-image"]},hasReorderingFeedback:function(){return!!this.$slots["reordering-feedback"]},hasEmptySlot:function(){return!!this.$slots.empty}},created:function(){dnd.on("dragstart",this.onDragStart),dnd.on("dragend",this.onDragEnd)},beforeUnmount:function(){dnd.off("dragstart",this.onDragStart),dnd.off("dragend",this.onDragEnd)},methods:{refresh:function(){var _this4=this;this.$nextTick((function(){_this4.grid=_this4.computeInsertingGrid(),_this4.feedbackKey=_this4.computeFeedbackKey(),_this4.forbiddenKeys=_this4.computeForbiddenKeys()}))},onDragStart:function(event){this.candidate(dnd.type)&&(this.reordering?(this.fromIndex=Array.prototype.indexOf.call(event.source.$el.parentElement.children,event.source.$el),this.grid=this.computeReorderingGrid()):this.refresh())},onDragEnd:function(){this.fromIndex=null,this.feedbackKey=null,this.forbiddenKeys=null,this.grid=null},doDrop:function(event){this.reordering?this.fromIndex!==this.closestIndex&&this.$emit("reorder",new ReorderEvent(this.fromIndex,this.closestIndex)):(_doDrop(this,event),this.$emit("insert",new InsertEvent(event.type,event.data,this.closestIndex)))},candidate:function(type){return _candidate(this,type)||this.reordering},computeForbiddenKeys:function(){return(this.noAnimations?[]:this.$refs.component.$slots.default()).map((function(vn){return vn.key})).filter((function(k){return!!k&&"drag-image"!==k&&"drag-feedback"!==k}))},computeFeedbackKey:function(){return this.$refs.feedback.$slots.default()[0].key},computeInsertingGrid:function(){if(this.$refs.feedback.$el.children.length<1)return null;var clone=this.$refs.feedback.$el.children[0].cloneNode(!0),tg=this.$el;tg.children.length>this.items.length?tg.insertBefore(clone,tg.children[this.items.length]):tg.appendChild(clone);var grid=new Grid(tg.children,this.items.length,this.direction,null);return tg.removeChild(clone),grid},computeReorderingGrid:function(){return new Grid(this.$el.children,this.items.length-1,this.direction,this.fromIndex)},createDragImage:function(){var image;if(this.$refs["drag-image"]){var el=this.$refs["drag-image"],clone=(1!==el.childElementCount?el:el.children.item(0)).cloneNode(!0),tg=this.$el;tg.appendChild(clone),image=_createDragImage(clone),tg.removeChild(clone),image.__opacity=this.dragImageOpacity,image.classList.add("dnd-ghost")}else image="source";return image}},render:function(){var _this5=this;if(!this.$slots.item)throw'The "Item" slot must be defined to use DropList';if(!this.$slots.feedback)throw'The "Feedback" slot must be defined to use DropList';var defaultArr=[];if(this.dropIn&&this.dropAllowed)if(this.reordering)if(this.hasReorderingFeedback){var itemsReorderingBefore=this.itemsBeforeReorderingFeedback.map((function(item,index){return _this5.$slots.item({item:item,index:index,reorder:!1})[0]}));itemsReorderingBefore.length>0&&(defaultArr=defaultArr.concat(itemsReorderingBefore)),defaultArr.push(this.$slots["reordering-feedback"]({key:"reordering-feedback",item:this.items[this.fromIndex]})[0]);var itemsReorderingAfter=this.itemsAfterReorderingFeedback.map((function(item,index){return _this5.$slots.item({item:item,index:_this5.itemsBeforeReorderingFeedback.length+index,reorder:!1})[0]}));itemsReorderingAfter.length>0&&(defaultArr=defaultArr.concat(itemsReorderingAfter))}else{var reorderedItems=this.reorderedItems.map((function(item,index){return _this5.$slots.item({item:item,index:index,reorder:index===_this5.closestIndex})[0]}));reorderedItems.length>0&&(defaultArr=defaultArr.concat(reorderedItems))}else{var itemsBefore=this.itemsBeforeFeedback.map((function(item,index){return _this5.$slots.item({item:item,index:index,reorder:!1})[0]}));itemsBefore.length>0&&(defaultArr=defaultArr.concat(itemsBefore)),defaultArr.push(this.$slots.feedback({key:"drag-feedback",data:this.dragData,type:this.dragType})[0]);var itemsAfter=this.itemsAfterFeedback.map((function(item,index){return _this5.$slots.item({item:item,index:_this5.itemsBeforeFeedback.length+index,reorder:!1})[0]}));itemsAfter.length>0&&(defaultArr=defaultArr.concat(itemsAfter))}else{var defaultItems=this.items.map((function(item,index){return _this5.$slots.item({item:item,index:index,reorder:!1})[0]}));defaultItems.length>0?defaultArr=defaultArr.concat(defaultItems):this.hasEmptySlot&&defaultArr.push(this.$slots.empty()[0])}return this.showDragFeedback&&defaultArr.push((0,_vue.h)(script$1,{class:"__feedback",ref:"feedback",key:"drag-feedback"},{default:function(){return _this5.$slots.feedback({type:_this5.dragType,data:_this5.dragData})[0]}})),this.showReorderingDragImage&&defaultArr.push((0,_vue.h)("div",{class:"__drag-image",ref:"drag-image",key:"reordering-drag-image"},{default:function(){return _this5.$slots["reordering-drag-image"]({item:_this5.items[_this5.fromIndex]})[0]}})),this.showInsertingDragImage&&defaultArr.push((0,_vue.h)("div",{class:"__drag-image",ref:"drag-image",key:"inserting-drag-image"},{default:function(){return _this5.$slots["drag-image"]({type:_this5.dragType,data:_this5.dragData})[0]}})),(0,_vue.h)(this.rootTag,_objectSpread({ref:"component",class:this.clazz},this.rootProps),{default:function(){return defaultArr}})}};_exports.DropList=script,script.__scopeId="data-v-230f65e3";var DragImagesManager=function(){function DragImagesManager(){_classCallCheck(this,DragImagesManager),_defineProperty(this,"selfTransform",null),_defineProperty(this,"clones",null),_defineProperty(this,"source",null),_defineProperty(this,"sourcePos",null),_defineProperty(this,"sourceClone",null),dnd.on("dragstart",this.onDragStart.bind(this)),dnd.on("dragtopchanged",this.onDragTopChanged.bind(this)),dnd.on("dragpositionchanged",this.onDragPositionChanged.bind(this)),dnd.on("dragend",this.onDragEnd.bind(this))}return _createClass(DragImagesManager,[{key:"onDragStart",value:function(event){this.cleanUp(),this.sourcePos={x:event.source.$el.getBoundingClientRect().left,y:event.source.$el.getBoundingClientRect().top},this.selfTransform="translate(-"+(event.position.x-this.sourcePos.x)+"px, -"+(event.position.y-this.sourcePos.y)+"px)",this.clones=new Map,this.source=event.source}},{key:"onDragEnd",value:function(event){var _this6=this;(0,_vue.nextTick)().then((function(){if(!event.success&&_this6.source&&_this6.source.goBack){var img=_this6.switch(null);window.requestAnimationFrame((function(){img.style.transition="all 0.5s",window.requestAnimationFrame((function(){img.style.left=_this6.sourcePos.x+"px",img.style.top=_this6.sourcePos.y+"px",img.style.transform="translate(0,0)";img.addEventListener("transitionend",(function handler(){_this6.cleanUp(),img.removeEventListener("transitionend",handler)}))}))}))}else _this6.cleanUp()}))}},{key:"cleanUp",value:function(){this.clones&&this.clones.forEach((function(clone){clone.parentNode===document.body&&document.body.removeChild(clone)})),null!==this.sourceClone&&this.sourceClone.parentNode===document.body&&document.body.removeChild(this.sourceClone),this.selfTransform=null,this.clones=null,this.source=null,this.sourceClone=null,this.sourcePos=null}},{key:"onDragTopChanged",value:function(event){this.switch(event.top)}},{key:"switch",value:function(top){var activeClone;if(this.clones.forEach((function(clone){clone.style.opacity="0"})),this.sourceClone&&(this.sourceClone.style.opacity="0"),null===top)activeClone=this.getSourceClone();else{if(!this.clones.has(top)){var clone=top.createDragImage(this.selfTransform);"source"===clone?clone=this.getSourceClone():null!==clone&&(clone.style.opacity="0",document.body.appendChild(clone)),this.clones.set(top,clone)}activeClone=this.clones.get(top)}return null!==activeClone&&(activeClone.offsetWidth,activeClone.style.opacity=activeClone.__opacity,activeClone.style.visibility="visible"),activeClone}},{key:"getSourceClone",value:function(){return null===this.sourceClone&&(this.sourceClone=this.source.createDragImage(this.selfTransform),this.sourceClone.style.opacity="0",document.body.appendChild(this.sourceClone)),this.sourceClone}},{key:"onDragPositionChanged",value:function(){this.clones.forEach((function(clone){clone.style.left=dnd.position.x+"px",clone.style.top=dnd.position.y+"px"})),this.sourceClone&&(this.sourceClone.style.left=dnd.position.x+"px",this.sourceClone.style.top=dnd.position.y+"px")}}]),DragImagesManager}();_exports.DragImagesManager=DragImagesManager,new DragImagesManager}));
|
|
|
|
//# sourceMappingURL=vue-easy-dnd.esm.min.js.map
|