UNPKG

dnd-multi-backend

Version:
6 lines (5 loc) 4.46 kB
var E=r=>{throw TypeError(r)};var P=(r,n,e)=>n.has(r)||E("Cannot "+e);var t=(r,n,e)=>(P(r,n,"read from private field"),e?e.call(r):n.get(r)),s=(r,n,e)=>n.has(r)?E("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(r):n.set(r,e),p=(r,n,e,i)=>(P(r,n,"write to private field"),i?i.call(r,e):n.set(r,e),e);var h,B=class{constructor(){s(this,h);this.register=n=>{t(this,h).push(n)};this.unregister=n=>{for(;t(this,h).indexOf(n)!==-1;)t(this,h).splice(t(this,h).indexOf(n),1)};this.backendChanged=n=>{for(let e of t(this,h))e.backendChanged(n)};p(this,h,[])}};h=new WeakMap;var c,l,a,d,k,x,T,D,m,v,f,w=class w{constructor(n,e,i){s(this,c);s(this,l);s(this,a);s(this,d);s(this,k);s(this,x,(n,e,i)=>{if(!i.backend)throw new Error(`You must specify a 'backend' property in your Backend entry: ${JSON.stringify(i)}`);let u=i.backend(n,e,i.options),o=i.id,g=!i.id&&u&&u.constructor;if(g&&(o=u.constructor.name),!o)throw new Error(`You must specify an 'id' property in your Backend entry: ${JSON.stringify(i)} see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-5xx`);if(g&&console.warn(`Deprecation notice: You are using a pipeline which doesn't include backends' 'id'. This might be unsupported in the future, please specify 'id' explicitely for every backend.`),t(this,a)[o])throw new Error(`You must specify a unique 'id' property in your Backend entry: ${JSON.stringify(i)} (conflicts with: ${JSON.stringify(t(this,a)[o])})`);return{id:o,instance:u,preview:i.preview??!1,transition:i.transition,skipDispatchOnTransition:i.skipDispatchOnTransition??!1}});this.setup=()=>{if(!(typeof window>"u")){if(w.isSetUp)throw new Error("Cannot have two MultiBackends at the same time.");w.isSetUp=!0,t(this,T).call(this,window),t(this,a)[t(this,c)].instance.setup()}};this.teardown=()=>{typeof window>"u"||(w.isSetUp=!1,t(this,D).call(this,window),t(this,a)[t(this,c)].instance.teardown())};this.connectDragSource=(n,e,i)=>t(this,f).call(this,"connectDragSource",n,e,i);this.connectDragPreview=(n,e,i)=>t(this,f).call(this,"connectDragPreview",n,e,i);this.connectDropTarget=(n,e,i)=>t(this,f).call(this,"connectDropTarget",n,e,i);this.profile=()=>t(this,a)[t(this,c)].instance.profile();this.previewEnabled=()=>t(this,a)[t(this,c)].preview;this.previewsList=()=>t(this,l);this.backendsList=()=>t(this,d);s(this,T,n=>{for(let e of t(this,d))e.transition&&n.addEventListener(e.transition.event,t(this,m))});s(this,D,n=>{for(let e of t(this,d))e.transition&&n.removeEventListener(e.transition.event,t(this,m))});s(this,m,n=>{let e=t(this,c);if(t(this,d).some(i=>i.id!==t(this,c)&&i.transition&&i.transition.check(n)?(p(this,c,i.id),!0):!1),t(this,c)!==e){t(this,a)[e].instance.teardown();for(let[g,b]of Object.entries(t(this,k)))b.unsubscribe(),b.unsubscribe=t(this,v).call(this,b.func,...b.args);t(this,l).backendChanged(this);let i=t(this,a)[t(this,c)];if(i.instance.setup(),i.skipDispatchOnTransition)return;let u=n.constructor,o=new u(n.type,n);n.target?.dispatchEvent(o)}});s(this,v,(n,e,i,u)=>t(this,a)[t(this,c)].instance[n](e,i,u));s(this,f,(n,e,i,u)=>{let o=`${n}_${e}`,g=t(this,v).call(this,n,e,i,u);return t(this,k)[o]={func:n,args:[e,i,u],unsubscribe:g},()=>{t(this,k)[o].unsubscribe(),delete t(this,k)[o]}});if(!i||!i.backends||i.backends.length<1)throw new Error(`You must specify at least one Backend, if you are coming from 2.x.x (or don't understand this error) see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-2xx`);p(this,l,new B),p(this,a,{}),p(this,d,[]);for(let u of i.backends){let o=t(this,x).call(this,n,e,u);t(this,a)[o.id]=o,t(this,d).push(o)}p(this,c,t(this,d)[0].id),p(this,k,{})}};c=new WeakMap,l=new WeakMap,a=new WeakMap,d=new WeakMap,k=new WeakMap,x=new WeakMap,T=new WeakMap,D=new WeakMap,m=new WeakMap,v=new WeakMap,f=new WeakMap,w.isSetUp=!1;var M=w;var S=(r,n,e)=>new M(r,n,e);var y=(r,n)=>({event:r,check:n});var L=y("touchstart",r=>{let n=r;return n.touches!==null&&n.touches!==void 0}),O=y("dragstart",r=>r.type.indexOf("drag")!==-1||r.type.indexOf("drop")!==-1),C=y("mousedown",r=>r.type.indexOf("touch")===-1&&r.type.indexOf("mouse")!==-1),U=y("pointerdown",r=>r.pointerType==="mouse");export{O as HTML5DragTransition,C as MouseTransition,S as MultiBackend,U as PointerTransition,L as TouchTransition,y as createTransition};