UNPKG

7.96 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("dragula"),require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ng2-dragula",["exports","dragula","@angular/core","rxjs","rxjs/operators"],t):t(e["ng2-dragula"]={},e.dragula,e.ng.core,e.rxjs,e.rxjs.operators)}(this,function(e,t,r,n,a){"use strict";var o="default"in t?t["default"]:t;function i(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||0<t--)&&!(n=i.next()).done;)a.push(n.value)}catch(s){o={error:s}}finally{try{n&&!n.done&&(r=i["return"])&&r.call(i)}finally{if(o)throw o.error}}return a}var s=function u(e,t,r){this.name=e,this.drake=t,this.options=r,this.initEvents=!1},v={Cancel:"cancel",Cloned:"cloned",Drag:"drag",DragEnd:"dragend",Drop:"drop",Out:"out",Over:"over",Remove:"remove",Shadow:"shadow",DropModel:"dropModel",RemoveModel:"removeModel"},d=Object.keys(v).map(function(e){return v[e]}),c=o||t,l=function p(e){void 0===e&&(e=c),this.build=e},f=function(n,o,i){return function(e){return e.pipe(a.filter(function(e){var t=e.event,r=e.name;return t===n&&(o===undefined||r===o)}),a.map(function(e){var t=e.name,r=e.args;return i(t,r)}))}},h=function(e,t){var r=i(t,3);return{name:e,el:r[0],container:r[1],source:r[2]}},g=function(){function e(e){void 0===e&&(e=null);var r=this;this.drakeFactory=e,this.dispatch$=new n.Subject,this.drag=function(e){return r.dispatch$.pipe(f(v.Drag,e,function(e,t){var r=i(t,2);return{name:e,el:r[0],source:r[1]}}))},this.dragend=function(e){return r.dispatch$.pipe(f(v.DragEnd,e,function(e,t){return{name:e,el:i(t,1)[0]}}))},this.drop=function(e){return r.dispatch$.pipe(f(v.Drop,e,function(e,t){var r=i(t,4);return{name:e,el:r[0],target:r[1],source:r[2],sibling:r[3]}}))},this.elContainerSource=function(t){return function(e){return r.dispatch$.pipe(f(t,e,h))}},this.cancel=this.elContainerSource(v.Cancel),this.remove=this.elContainerSource(v.Remove),this.shadow=this.elContainerSource(v.Shadow),this.over=this.elContainerSource(v.Over),this.out=this.elContainerSource(v.Out),this.cloned=function(e){return r.dispatch$.pipe(f(v.Cloned,e,function(e,t){var r=i(t,3);return{name:e,clone:r[0],original:r[1],cloneType:r[2]}}))},this.dropModel=function(e){return r.dispatch$.pipe(f(v.DropModel,e,function(e,t){var r=i(t,9);return{name:e,el:r[0],target:r[1],source:r[2],sibling:r[3],item:r[4],sourceModel:r[5],targetModel:r[6],sourceIndex:r[7],targetIndex:r[8]}}))},this.removeModel=function(e){return r.dispatch$.pipe(f(v.RemoveModel,e,function(e,t){var r=i(t,6);return{name:e,el:r[0],container:r[1],source:r[2],item:r[3],sourceModel:r[4],sourceIndex:r[5]}}))},this.groups={},null===this.drakeFactory&&(this.drakeFactory=new l)}return e.prototype.add=function(e){if(this.find(e.name))throw new Error('Group named: "'+e.name+'" already exists.');return this.groups[e.name]=e,this.handleModels(e),this.setupEvents(e),e},e.prototype.find=function(e){return this.groups[e]},e.prototype.destroy=function(e){var t=this.find(e);t&&(t.drake&&t.drake.destroy(),delete this.groups[e])},e.prototype.createGroup=function(e,t){return this.add(new s(e,this.drakeFactory.build([],t),t))},e.prototype.handleModels=function(e){var d,c,l,p=this,f=e.name,h=e.drake,g=e.options;h.on("remove",function(e,t,r){if(h.models){var n=h.models[h.containers.indexOf(r)],o=(n=n.slice(0)).splice(c,1)[0];p.dispatch$.next({event:v.RemoveModel,name:f,args:[e,t,r,o,n,c]})}}),h.on("drag",function(e,t){h.models&&(d=e,c=p.domIndexOf(e,t))}),h.on("drop",function(e,t,r,n){if(h.models&&t){l=p.domIndexOf(e,t);var o,i=h.models[h.containers.indexOf(r)],a=h.models[h.containers.indexOf(t)];if(t===r)o=(i=i.slice(0)).splice(c,1)[0],i.splice(l,0,o),a=i;else{var s=d!==e;if(o=i[c],s){if(!g.copyItem)throw new Error("If you have enabled `copy` on a group, you must provide a `copyItem` function.");o=g.copyItem(o)}if(s||(i=i.slice(0)).splice(c,1),(a=a.slice(0)).splice(l,0,o),s)try{t.removeChild(e)}catch(u){}}p.dispatch$.next({event:v.DropModel,name:f,args:[e,t,r,n,o,i,a,c,l]})}})},e.prototype.setupEvents=function(e){var n=this;if(!e.initEvents){e.initEvents=!0;var o=e.name;d.forEach(function(r){e.drake.on(r,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];n.dispatch$.next({event:r,name:o,args:e})})})}},e.prototype.domIndexOf=function(e,t){return Array.prototype.indexOf.call(t.children,e)},e.decorators=[{type:r.Injectable}],e.ctorParameters=function(){return[{type:l,decorators:[{type:r.Optional}]}]},e}(),m=function(){function e(e,t){this.el=e,this.dragulaService=t,this.dragulaModelChange=new r.EventEmitter}return Object.defineProperty(e.prototype,"container",{get:function(){return this.el&&this.el.nativeElement},enumerable:!0,configurable:!0}),e.prototype.ngOnChanges=function(e){if(e&&e.dragula){var t=e.dragula,r=t.previousValue,n=t.currentValue,o=(t.firstChange,!!n);!!r&&this.teardown(r),o&&this.setup()}else if(e&&e.dragulaModel){var i=e.dragulaModel,a=(r=i.previousValue,n=i.currentValue,i.firstChange,this.group.drake);if(this.dragula&&a){a.models=a.models||[];var s=a.models.indexOf(r);-1!==s?(a.models.splice(s,1),n&&a.models.splice(s,0,n)):n&&a.models.push(n)}}},e.prototype.setup=function(){var e,t=this,r=this.dragulaService.find(this.dragula);if(!r){r=this.dragulaService.createGroup(this.dragula,{})}e=r,t.dragulaModel&&(e.drake.models?e.drake.models.push(t.dragulaModel):e.drake.models=[t.dragulaModel]),r.drake.containers.push(this.container),this.subscribe(this.dragula),this.group=r},e.prototype.subscribe=function(e){var i=this;this.subs=new n.Subscription,this.subs.add(this.dragulaService.dropModel(e).subscribe(function(e){var t=e.source,r=e.target,n=e.sourceModel,o=e.targetModel;t===i.el.nativeElement?i.dragulaModelChange.emit(n):r===i.el.nativeElement&&i.dragulaModelChange.emit(o)})),this.subs.add(this.dragulaService.removeModel(e).subscribe(function(e){var t=e.source,r=e.sourceModel;t===i.el.nativeElement&&i.dragulaModelChange.emit(r)}))},e.prototype.teardown=function(e){this.subs&&this.subs.unsubscribe();var t=this.dragulaService.find(e);if(t){var r=t.drake.containers.indexOf(this.el.nativeElement);if(-1!==r&&t.drake.containers.splice(r,1),this.dragulaModel&&t.drake&&t.drake.models){var n=t.drake.models.indexOf(this.dragulaModel);-1!==n&&t.drake.models.splice(n,1)}}},e.prototype.ngOnDestroy=function(){this.teardown(this.dragula)},e.decorators=[{type:r.Directive,args:[{selector:"[dragula]"}]}],e.ctorParameters=function(){return[{type:r.ElementRef},{type:g}]},e.propDecorators={dragula:[{type:r.Input}],dragulaModel:[{type:r.Input}],dragulaModelChange:[{type:r.Output}]},e}(),y=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[g]}},e.decorators=[{type:r.NgModule,args:[{exports:[m],declarations:[m]}]}],e}(),b=new l(function(e,t){return new M(e,t)}),M=function(){function e(e,t,r){void 0===e&&(e=[]),void 0===t&&(t={}),this.containers=e,this.options=t,this.models=r,this.dragging=!1,this.emitter$=new n.Subject,this.subs=new n.Subscription}return e.prototype.start=function(e){this.dragging=!0},e.prototype.end=function(){this.dragging=!1},e.prototype.cancel=function(e){this.dragging=!1},e.prototype.remove=function(){this.dragging=!1},e.prototype.on=function(t,n){this.subs.add(this.emitter$.pipe(a.filter(function(e){return e.eventType===t})).subscribe(function(e){var t=e.args;n.apply(void 0,function r(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(i(arguments[t]));return e}(t))}))},e.prototype.destroy=function(){this.subs.unsubscribe()},e.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];this.emitter$.next({eventType:e,args:t})},e}();e.DragulaDirective=m,e.DragulaService=g,e.DragulaModule=y,e.dragula=c,e.DrakeFactory=l,e.Group=s,e.EventTypes=v,e.MockDrake=M,e.MockDrakeFactory=b,Object.defineProperty(e,"__esModule",{value:!0})});
2//# sourceMappingURL=ng2-dragula.umd.min.js.map
\No newline at end of file