@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
3 lines (2 loc) • 4.77 kB
JavaScript
;const l=require("vue"),t=require("../../../utils/common/event/NeonEventBus.cjs.js"),o=require("../../../model/feedback/alert/NeonAlertLevel.cjs.js"),s=require("../../../utils/feedback/alert/NeonAlertService.cjs.js"),D=require("./container/NeonAlertContainer.vue.cjs.js"),C=require("./container/NeonToastContainer.vue.cjs.js"),i=require("../../../utils/feedback/toast/NeonToastService.cjs.js"),a=require("../../../model/feedback/alert/NeonAlertPlacement.cjs.js"),u=require("../../../model/common/position/NeonVerticalPosition.cjs.js"),_=require("./container/NeonDialogContainer.vue.cjs.js"),V=require("../../../utils/feedback/dialog/NeonDialogService.cjs.js"),M=l.defineComponent({name:"NeonAlert",components:{NeonAlertContainer:D,NeonToastContainer:C,NeonDialogContainer:_},props:{dismissible:{type:Boolean,default:!0},duration:{type:Number,default:2500}},setup(L){const N=l.ref([]),f=l.ref([]),A=l.ref([]),E=l.ref([]),m=l.ref([]),d=l.ref([]),B=l.ref({question:"",title:"",open:!1}),c=l.ref(1),w=e=>{switch(e.placement||a.NeonAlertPlacement.TopRight){case a.NeonAlertPlacement.TopLeft:N.value=N.value.filter(n=>n.id!==e.id);break;case a.NeonAlertPlacement.TopRight:f.value=f.value.filter(n=>n.id!==e.id);break;case a.NeonAlertPlacement.BottomLeft:A.value=A.value.filter(n=>n.id!==e.id);break;case a.NeonAlertPlacement.BottomRight:E.value=E.value.filter(n=>n.id!==e.id);break}},T=(e,n)=>{const v=c.value;c.value=c.value+1;const r={dismissible:L.dismissible,...n,level:e,id:v};switch(n.placement||a.NeonAlertPlacement.TopRight){case a.NeonAlertPlacement.TopLeft:N.value.unshift(r);break;case a.NeonAlertPlacement.TopRight:f.value.unshift(r);break;case a.NeonAlertPlacement.BottomLeft:A.value.push(r);break;case a.NeonAlertPlacement.BottomRight:E.value.push(r);break}const S=n.duration===void 0?L.duration:n.duration;S>0&&!n.primaryAction&&setTimeout(()=>w(r),S)},x=e=>{switch(e.placement||u.NeonVerticalPosition.Top){case u.NeonVerticalPosition.Top:m.value=m.value.filter(n=>n.id!==e.id);break;case u.NeonVerticalPosition.Bottom:d.value=d.value.filter(n=>n.id!==e.id);break}},g=(e,n)=>{const v=c.value;c.value=c.value+1;const r={dismissible:L.dismissible,...n,level:e,id:v};switch(n.placement||u.NeonVerticalPosition.Top){case u.NeonVerticalPosition.Top:m.value.unshift(r);break;case u.NeonVerticalPosition.Bottom:d.value.push(r);break}const S=n.duration===void 0?L.duration:n.duration;S>0&&setTimeout(()=>x(r),S)},p=e=>{T(o.NeonAlertLevel.Info,e)},y=e=>{T(o.NeonAlertLevel.Success,e)},K=e=>{T(o.NeonAlertLevel.Warn,e)},b=e=>{T(o.NeonAlertLevel.Error,e)},h=e=>{g(o.NeonAlertLevel.Info,e)},P=e=>{g(o.NeonAlertLevel.Success,e)},k=e=>{g(o.NeonAlertLevel.Warn,e)},q=e=>{g(o.NeonAlertLevel.Error,e)},I=e=>{[m.value,d.value].forEach(n=>{const v=n.findIndex(r=>r.key===e);v>=0&&n.splice(v,1)})},R=e=>{[f.value,E.value,N.value,A.value].forEach(n=>{const v=n.findIndex(r=>r.key===e);v>=0&&n.splice(v,1)})},W=e=>{B.value={...e,open:!0}};return l.onMounted(()=>{t.NeonEventBus.on(s.NeonAlertService.generateEventKey(o.NeonAlertLevel.Info),p),t.NeonEventBus.on(s.NeonAlertService.generateEventKey(o.NeonAlertLevel.Success),y),t.NeonEventBus.on(s.NeonAlertService.generateEventKey(o.NeonAlertLevel.Warn),K),t.NeonEventBus.on(s.NeonAlertService.generateEventKey(o.NeonAlertLevel.Error),b),t.NeonEventBus.on(s.NeonAlertService.removeEventKey,R),t.NeonEventBus.on(i.NeonToastService.generateEventKey(o.NeonAlertLevel.Info),h),t.NeonEventBus.on(i.NeonToastService.generateEventKey(o.NeonAlertLevel.Success),P),t.NeonEventBus.on(i.NeonToastService.generateEventKey(o.NeonAlertLevel.Warn),k),t.NeonEventBus.on(i.NeonToastService.generateEventKey(o.NeonAlertLevel.Error),q),t.NeonEventBus.on(i.NeonToastService.removeEventKey,I),t.NeonEventBus.on(V.NeonDialogService.generateEventKey(),W)}),l.onUnmounted(()=>{t.NeonEventBus.off(s.NeonAlertService.generateEventKey(o.NeonAlertLevel.Info),p),t.NeonEventBus.off(s.NeonAlertService.generateEventKey(o.NeonAlertLevel.Success),y),t.NeonEventBus.off(s.NeonAlertService.generateEventKey(o.NeonAlertLevel.Warn),K),t.NeonEventBus.off(s.NeonAlertService.generateEventKey(o.NeonAlertLevel.Error),b),t.NeonEventBus.off(s.NeonAlertService.removeEventKey,R),t.NeonEventBus.off(i.NeonToastService.generateEventKey(o.NeonAlertLevel.Info),h),t.NeonEventBus.off(i.NeonToastService.generateEventKey(o.NeonAlertLevel.Success),P),t.NeonEventBus.off(i.NeonToastService.generateEventKey(o.NeonAlertLevel.Warn),k),t.NeonEventBus.off(i.NeonToastService.generateEventKey(o.NeonAlertLevel.Error),q),t.NeonEventBus.off(i.NeonToastService.removeEventKey,I),t.NeonEventBus.off(V.NeonDialogService.generateEventKey(),W)}),{topLeft:N,topRight:f,bottomLeft:A,bottomRight:E,top:m,bottom:d,dialog:B}}});module.exports=M;
//# sourceMappingURL=NeonAlert.cjs.js.map