+"use strict";var Le=Object.defineProperty,Se=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var Q=(e,n,t)=>n in e?Le(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,C=(e,n)=>{for(var t in n||(n={}))Z.call(n,t)&&Q(e,t,n[t]);if(P)for(var t of P(n))ee.call(n,t)&&Q(e,t,n[t]);return e},ne=(e,n)=>Se(e,Ce(n));var q=(e,n)=>{var t={};for(var o in e)Z.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(e!=null&&P)for(var o of P(e))n.indexOf(o)<0&&ee.call(e,o)&&(t[o]=e[o]);return t};Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue"),D=require("sortablejs"),fe="[vue-draggable-plus]: ";function De(e){console.warn(fe+e)}function Ae(e){console.error(fe+e)}function te(e,n,t){return t>=0&&t<e.length&&e.splice(t,0,e.splice(n,1)[0]),e}function we(e){return e.replace(/-(\w)/g,(n,t)=>t?t.toUpperCase():"")}function Ie(e){return Object.keys(e).reduce((n,t)=>(typeof e[t]!="undefined"&&(n[we(t)]=e[t]),n),{})}function oe(e,n){return Array.isArray(e)&&e.splice(n,1),e}function re(e,n,t){return Array.isArray(e)&&e.splice(n,0,t),e}function Ge(e){return typeof e=="undefined"}function Te(e){return typeof e=="string"}function le(e,n,t){const o=e.children[t];e.insertBefore(n,o)}function F(e){e.parentNode&&e.parentNode.removeChild(e)}function Ne(e,n=document){var o;let t=null;return typeof(n==null?void 0:n.querySelector)=="function"?t=(o=n==null?void 0:n.querySelector)==null?void 0:o.call(n,e):t=document.querySelector(e),t||De(`Element not found: ${e}`),t}function xe(e,n,t=null){return function(...o){return e.apply(t,o),n.apply(t,o)}}function Me(e,n){const t=C({},e);return Object.keys(n).forEach(o=>{t[o]?t[o]=xe(e[o],n[o]):t[o]=n[o]}),t}function Be(e){return e instanceof HTMLElement}function ie(e,n){Object.keys(e).forEach(t=>{n(t,e[t])})}function Ee(e){return e.charCodeAt(0)===111&&e.charCodeAt(1)===110&&(e.charCodeAt(2)>122||e.charCodeAt(2)<97)}const He=Object.assign,z=Symbol("cloneGhostOriginalHtml"),x=Symbol("cloneGhostAppliedBy");function G(){return D.dragged}function T(e){if(!e||!e[x])return;const n=e[z];typeof n=="string"&&(e.innerHTML=n),e[z]=void 0,e[x]=void 0}function Pe(e,n,t){const o=n();o&&(e[z]=e.innerHTML,e.innerHTML=typeof o=="string"?o:o.innerHTML,e[x]=t)}function R(){}R.prototype={dragOverValid(e){if(e.isOwner)return;const n=e.sortable.options.cloneGhost;if(!n)return;const t=G();t&&t[x]!==e.sortable.el&&(t[x]&&T(t),Pe(t,n,e.sortable.el))},dragOverGlobal(e){e.isOwner&&T(G())},revertGlobal(){const e=G();T(e),e&&e.style.display==="none"&&(e.style.display="")},dropGlobal(){T(G())},nullingGlobal(){T(G())}};R.pluginName="cloneGhost";R.initializeByDefault=!0;let N=null;function Re(e,n,t){return e>=t.left&&e<=t.right&&n>=t.top&&n<=t.bottom}function Ve(){if(N)return;let e=null;const n=t=>{var L;const o=D.dragged;if(!o||!o.parentNode){e=null;return}const u=o.parentNode,m=D.get(u);if(!((L=m==null?void 0:m.options)==null?void 0:L.hideOnLeave)){e=null;return}const O=Re(t.clientX,t.clientY,u.getBoundingClientRect());O!==e&&(o.style.display=O?"":"none",e=O)};document.addEventListener("pointermove",n),N=n}function _e(){N&&(document.removeEventListener("pointermove",N),N=null)}function V(){}V.prototype={dragStartGlobal(){Ve()},nullingGlobal(){_e();const e=D.dragged;e&&e.style.display==="none"&&(e.style.display="")}};V.pluginName="hideOnLeave";V.initializeByDefault=!0;const ue="sortable-dragging";function _(){}_.prototype={dragStartGlobal(){document.body.classList.add(ue)},nullingGlobal(){document.body.classList.remove(ue)}};_.pluginName="bodyClass";_.initializeByDefault=!0;let se=!1;function Ue(){se||(se=!0,D.mount(R,V,_))}Ue();function je(e){return e==null?e:JSON.parse(JSON.stringify(e))}function qe(e){l.getCurrentInstance()&&l.onUnmounted(e)}function Fe(e){l.getCurrentInstance()?l.onMounted(e):l.nextTick(e)}let ge=null,pe=null;const me=l.shallowRef(null);function ae(e=null,n=null){ge=e,pe=n,me.value=n}function $e(){return{data:ge,clonedData:pe}}const ce=Symbol("cloneElement");function k(...e){var K,W;const n=(K=l.getCurrentInstance())==null?void 0:K.proxy;let t=null;const o=e[0];let[,u,m]=e;Array.isArray(l.unref(u))||(m=u,u=null);let i=null;const{immediate:O=!0,clone:L=je,forceFallback:M,fallbackOnBody:b,customUpdate:S}=(W=l.unref(m))!=null?W:{};function A(r){var p;const{from:s,oldIndex:c,item:f}=r,a=Array.from(s.childNodes);t=M&&!b?a.slice(0,-1):a;const d=l.unref((p=l.unref(u))==null?void 0:p[c]),g=L(d);ae(d,g),f[ce]=g}function h(r){const s=r.item[ce];if(!Ge(s)){if(F(r.item),l.isRef(u)){const c=[...l.unref(u)];u.value=re(c,r.newDraggableIndex,s);return}re(l.unref(u),r.newDraggableIndex,s)}}function B(r){const{from:s,item:c,oldIndex:f,oldDraggableIndex:a,pullMode:d,clone:g}=r;if(le(s,c,f),d==="clone"){F(g);return}if(l.isRef(u)){const p=[...l.unref(u)];u.value=oe(p,a);return}oe(l.unref(u),a)}function U(r){if(S){S(r);return}const{from:s,item:c,oldIndex:f,oldDraggableIndex:a,newDraggableIndex:d}=r;if(F(c),le(s,c,f),l.isRef(u)){const g=[...l.unref(u)];u.value=te(g,a,d);return}te(l.unref(u),a,d)}function j(r){const{newIndex:s,oldIndex:c,from:f,to:a}=r;let d=null;const g=s===c&&f===a;try{if(g){let p=null;t==null||t.some((w,v)=>{if(p&&(t==null?void 0:t.length)!==a.childNodes.length)return f.insertBefore(p,w.nextSibling),!0;const H=a.childNodes[v];p=a==null?void 0:a.replaceChild(w,H)})}}catch(p){d=p}finally{t=null}l.nextTick(()=>{if(ae(),d)throw d})}const E={onUpdate:U,onStart:A,onAdd:h,onRemove:B,onEnd:j};function be(r){const s=l.unref(o);return r||(r=Te(s)?Ne(s,n==null?void 0:n.$el):s),r&&!Be(r)&&(r=r.$el),r||Ae("Root element not found"),r}function J(){var p;const w=(p=l.unref(m))!=null?p:{},{immediate:r,clone:s}=w,c=q(w,["immediate","clone"]);ie(c,(v,H)=>{Ee(v)&&(c[v]=(I,...ve)=>{const Oe=$e();return He(I,Oe),H(I,...ve)})});const f=c.onAdd;delete c.onAdd;const a=u===null?{}:E,d=Me(a,c),g=a.onAdd;return(f||g)&&(d.onAdd=function(v){var I;if(((I=v.item)==null?void 0:I.style.display)==="none")return;(f==null?void 0:f.call(this,v))!==!1&&(g==null||g.call(this,v))}),d}const X=r=>{r=be(r),i&&y.destroy(),i=new D(r,J())};l.watch(()=>m,()=>{i&&ie(J(),(r,s)=>{i==null||i.option(r,s)})},{deep:!0});const y={option:(r,s)=>i==null?void 0:i.option(r,s),destroy:()=>{i==null||i.destroy(),i=null},save:()=>i==null?void 0:i.save(),toArray:()=>i==null?void 0:i.toArray(),closest:(...r)=>i==null?void 0:i.closest(...r)},ye=()=>y==null?void 0:y.option("disabled",!0),he=()=>y==null?void 0:y.option("disabled",!1);return Fe(()=>{O&&X()}),qe(y.destroy),ne(C({start:X,pause:ye,resume:he},y),{draggedData:me})}const Y=["update","start","add","remove","choose","unchoose","end","sort","filter","clone","move","change"],ze=["clone","animation","ghostClass","group","sort","disabled","store","handle","draggable","swapThreshold","invertSwap","invertedSwapThreshold","removeCloneOnHide","direction","chosenClass","dragClass","ignore","filter","preventOnFilter","easing","setData","dropBubble","dragoverBubble","dataIdAttr","delay","delayOnTouchOnly","touchStartThreshold","forceFallback","fallbackClass","fallbackOnBody","fallbackTolerance","fallbackOffset","supportPointer","emptyInsertThreshold","scroll","forceAutoScrollFallback","scrollSensitivity","scrollSpeed","bubbleScroll","modelValue","tag","target","customUpdate",...Y.map(e=>`on${e.replace(/^\S/,n=>n.toUpperCase())}`)],Ye=l.defineComponent({name:"VueDraggable",model:{prop:"modelValue",event:"update:modelValue"},props:ze,emits:["update:modelValue",...Y],setup(e,{slots:n,emit:t,expose:o,attrs:u}){const m=Y.reduce((b,S)=>{const A=`on${S.replace(/^\S/,h=>h.toUpperCase())}`;return b[A]=(...h)=>t(S,...h),b},{}),i=l.computed(()=>{const h=l.toRefs(e),{modelValue:b}=h,S=q(h,["modelValue"]),A=Object.entries(S).reduce((B,[U,j])=>{const E=l.unref(j);return E!==void 0&&(B[U]=E),B},{});return C(C({},m),Ie(C(C({},u),A)))}),O=l.computed({get:()=>e.modelValue,set:b=>t("update:modelValue",b)}),L=l.ref(),M=l.reactive(k(e.target||L,O,i));return o(M),()=>{var b;return l.h(e.tag||"div",{ref:L},(b=n==null?void 0:n.default)==null?void 0:b.call(n,M))}}}),de={mounted:"mounted",unmounted:"unmounted"},$=new WeakMap,ke={[de.mounted](e,n){const t=l.isProxy(n.value)?[n.value]:n.value,[o,u]=t,m=k(e,o,u);$.set(e,m.destroy)},[de.unmounted](e){var n;(n=$.get(e))==null||n(),$.delete(e)}};exports.VueDraggable=Ye;exports.useDraggable=k;exports.vDraggable=ke;
0 commit comments