-
Notifications
You must be signed in to change notification settings - Fork 26
/
vuedraggable.min.js
1 lines (1 loc) · 6.11 KB
/
vuedraggable.min.js
1
"use strict";function _toConsumableArray(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}var _extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t};!function(){function t(t){function e(t){t.parentElement.removeChild(t)}function n(t,e,n){var o=0===n?t.children[0]:t.children[n-1].nextSibling;t.insertBefore(e,o)}function o(t,e){return t.map(function(t){return t.elm}).indexOf(e)}function i(t,e,n){if(!t)return[];var o=t.map(function(t){return t.elm}),i=[].concat(_toConsumableArray(e)).map(function(t){return o.indexOf(t)});return n?i.filter(function(t){return t!==-1}):i}function r(t,e){var n=this;this.$nextTick(function(){return n.$emit(t.toLowerCase(),e)})}function s(t){var e=this;return function(n){null!==e.realList&&e["onDrag"+t](n),r.call(e,t,n)}}var a=["Start","Add","Remove","Update","End"],l=["Choose","Sort","Filter","Clone"],u=["Move"].concat(a,l).map(function(t){return"on"+t}),d=null,c={options:Object,list:{type:Array,required:!1,"default":null},value:{type:Array,required:!1,"default":null},noTransitionOnDrag:{type:Boolean,"default":!1},clone:{type:Function,"default":function(t){return t}},element:{type:String,"default":"div"},move:{type:Function,"default":null}},f={name:"draggable",props:c,data:function(){return{transitionMode:!1,componentMode:!1}},render:function(t){var e=this.$slots["default"];if(e&&1===e.length){var n=e[0];n.componentOptions&&"transition-group"===n.componentOptions.tag&&(this.transitionMode=!0)}var o=e,i=this.$slots.footer;return i&&(o=e?[].concat(_toConsumableArray(e),_toConsumableArray(i)):[].concat(_toConsumableArray(i))),t(this.element,null,o)},mounted:function(){var e=this;if(this.componentMode=this.element.toLowerCase()!==this.$el.nodeName.toLowerCase(),this.componentMode&&this.transitionMode)throw new Error("Transition-group inside component is not supported. Please alter element value or remove transition-group. Current element value: "+this.element);var n={};a.forEach(function(t){n["on"+t]=s.call(e,t)}),l.forEach(function(t){n["on"+t]=r.bind(e,t)});var o=_extends({},this.options,n,{onMove:function(t,n){return e.onDragMove(t,n)}});!("draggable"in o)&&(o.draggable=">*"),this._sortable=new t(this.rootContainer,o),this.computeIndexes()},beforeDestroy:function(){this._sortable.destroy()},computed:{rootContainer:function(){return this.transitionMode?this.$el.children[0]:this.$el},isCloning:function(){return!!this.options&&!!this.options.group&&"clone"===this.options.group.pull},realList:function(){return this.list?this.list:this.value}},watch:{options:{handler:function(t){for(var e in t)u.indexOf(e)==-1&&this._sortable.option(e,t[e])},deep:!0},realList:function(){this.computeIndexes()}},methods:{getChildrenNodes:function(){if(this.componentMode)return this.$children[0].$slots["default"];var t=this.$slots["default"];return this.transitionMode?t[0].child.$slots["default"]:t},computeIndexes:function(){var t=this;this.$nextTick(function(){t.visibleIndexes=i(t.getChildrenNodes(),t.rootContainer.children,t.transitionMode)})},getUnderlyingVm:function(t){var e=o(this.getChildrenNodes()||[],t);if(e===-1)return null;var n=this.realList[e];return{index:e,element:n}},getUnderlyingPotencialDraggableComponent:function(t){var e=t.__vue__;return e&&e.$options&&"transition-group"===e.$options._componentTag?e.$parent:e},emitChanges:function(t){var e=this;this.$nextTick(function(){e.$emit("change",t)})},alterList:function(t){if(this.list)t(this.list);else{var e=[].concat(_toConsumableArray(this.value));t(e),this.$emit("input",e)}},spliceList:function h(){var t=arguments,h=function(e){return e.splice.apply(e,t)};this.alterList(h)},updatePosition:function m(t,e){var m=function(n){return n.splice(e,0,n.splice(t,1)[0])};this.alterList(m)},getRelatedContextFromMoveEvent:function(t){var e=t.to,n=t.related,o=this.getUnderlyingPotencialDraggableComponent(e);if(!o)return{component:o};var i=o.realList,r={list:i,component:o};if(e!==n&&i&&o.getUnderlyingVm){var s=o.getUnderlyingVm(n);if(s)return _extends(s,r)}return r},getVmIndex:function(t){var e=this.visibleIndexes,n=e.length;return t>n-1?n:e[t]},getComponent:function(){return this.$slots["default"][0].componentInstance},resetTransitionData:function(t){if(this.noTransitionOnDrag&&this.transitionMode){var e=this.getChildrenNodes();e[t].data=null;var n=this.getComponent();n.children=[],n.kept=void 0}},onDragStart:function(t){this.context=this.getUnderlyingVm(t.item),t.item._underlying_vm_=this.clone(this.context.element),d=t.item},onDragAdd:function(t){var n=t.item._underlying_vm_;if(void 0!==n){e(t.item);var o=this.getVmIndex(t.newIndex);this.spliceList(o,0,n),this.computeIndexes();var i={element:n,newIndex:o};this.emitChanges({added:i})}},onDragRemove:function(t){if(n(this.rootContainer,t.item,t.oldIndex),this.isCloning)return void e(t.clone);var o=this.context.index;this.spliceList(o,1);var i={element:this.context.element,oldIndex:o};this.resetTransitionData(o),this.emitChanges({removed:i})},onDragUpdate:function(t){e(t.item),n(t.from,t.item,t.oldIndex);var o=this.context.index,i=this.getVmIndex(t.newIndex);this.updatePosition(o,i);var r={element:this.context.element,oldIndex:o,newIndex:i};this.emitChanges({moved:r})},computeFutureIndex:function(t,e){if(!t.element)return 0;var n=[].concat(_toConsumableArray(e.to.children)).filter(function(t){return"none"!==t.style.display}),o=n.indexOf(e.related),i=t.component.getVmIndex(o),r=n.indexOf(d)!=-1;return r||!e.willInsertAfter?i:i+1},onDragMove:function(t,e){var n=this.move;if(!n||!this.realList)return!0;var o=this.getRelatedContextFromMoveEvent(t),i=this.context,r=this.computeFutureIndex(o,t);return _extends(i,{futureIndex:r}),_extends(t,{relatedContext:o,draggedContext:i}),n(t,e)},onDragEnd:function(t){this.computeIndexes(),d=null}}};return f}if(Array.from||(Array.from=function(t){return[].slice.call(t)}),(typeof exports == "object")){var e=require("sortablejs");module.exports=t(e)}else if("function"==typeof define&&define.amd)define(["sortablejs"],function(e){return t(e)});else if(window&&window.Vue&&window.Sortable){var n=t(window.Sortable);Vue.component("draggable",n)}}();