UNPKG

snackbarstack

Version:

Queue up your Vuetify snackbars.

8 lines 11.8 kB
/* * Copyright 2018, 2019 TwelveTone LLC * * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SnackbarStackPlugin=t():e.SnackbarStackPlugin=t()}(window,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=8)}([function(e,t,n){var o=n(5);"string"==typeof o&&(o=[[e.i,o,""]]),o.locals&&(e.exports=o.locals);(0,n(3).default)("1203619d",o,!1,{})},function(e,t,n){var o=n(7);"string"==typeof o&&(o=[[e.i,o,""]]),o.locals&&(e.exports=o.locals);(0,n(3).default)("4addbe49",o,!1,{})},function(e,t,n){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=function(e,t){var n=e[1]||"",o=e[3];if(!o)return n;if(t&&"function"==typeof btoa){var r=(i=o,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */"),s=o.sources.map(function(e){return"/*# sourceURL="+o.sourceRoot+e+" */"});return[n].concat(s).concat([r]).join("\n")}var i;return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n}).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var o={},r=0;r<this.length;r++){var s=this[r][0];null!=s&&(o[s]=!0)}for(r=0;r<e.length;r++){var i=e[r];null!=i[0]&&o[i[0]]||(n&&!i[2]?i[2]=n:n&&(i[2]="("+i[2]+") and ("+n+")"),t.push(i))}},t}},function(e,t,n){"use strict";function o(e,t){for(var n=[],o={},r=0;r<t.length;r++){var s=t[r],i=s[0],a={id:e+":"+r,css:s[1],media:s[2],sourceMap:s[3]};o[i]?o[i].parts.push(a):n.push(o[i]={id:i,parts:[a]})}return n}n.r(t),n.d(t,"default",function(){return h});var r="undefined"!=typeof document;if("undefined"!=typeof DEBUG&&DEBUG&&!r)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var s={},i=r&&(document.head||document.getElementsByTagName("head")[0]),a=null,u=0,l=!1,c=function(){},p=null,f="data-vue-ssr-id",d="undefined"!=typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());function h(e,t,n,r){l=n,p=r||{};var i=o(e,t);return v(i),function(t){for(var n=[],r=0;r<i.length;r++){var a=i[r];(u=s[a.id]).refs--,n.push(u)}t?v(i=o(e,t)):i=[];for(r=0;r<n.length;r++){var u;if(0===(u=n[r]).refs){for(var l=0;l<u.parts.length;l++)u.parts[l]();delete s[u.id]}}}}function v(e){for(var t=0;t<e.length;t++){var n=e[t],o=s[n.id];if(o){o.refs++;for(var r=0;r<o.parts.length;r++)o.parts[r](n.parts[r]);for(;r<n.parts.length;r++)o.parts.push(m(n.parts[r]));o.parts.length>n.parts.length&&(o.parts.length=n.parts.length)}else{var i=[];for(r=0;r<n.parts.length;r++)i.push(m(n.parts[r]));s[n.id]={id:n.id,refs:1,parts:i}}}}function g(){var e=document.createElement("style");return e.type="text/css",i.appendChild(e),e}function m(e){var t,n,o=document.querySelector("style["+f+'~="'+e.id+'"]');if(o){if(l)return c;o.parentNode.removeChild(o)}if(d){var r=u++;o=a||(a=g()),t=_.bind(null,o,r,!1),n=_.bind(null,o,r,!0)}else o=g(),t=function(e,t){var n=t.css,o=t.media,r=t.sourceMap;o&&e.setAttribute("media",o);p.ssrId&&e.setAttribute(f,t.id);r&&(n+="\n/*# sourceURL="+r.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");if(e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}.bind(null,o),n=function(){o.parentNode.removeChild(o)};return t(e),function(o){if(o){if(o.css===e.css&&o.media===e.media&&o.sourceMap===e.sourceMap)return;t(e=o)}else n()}}var b,y=(b=[],function(e,t){return b[e]=t,b.filter(Boolean).join("\n")});function _(e,t,n,o){var r=n?"":o.css;if(e.styleSheet)e.styleSheet.cssText=y(t,r);else{var s=document.createTextNode(r),i=e.childNodes;i[t]&&e.removeChild(i[t]),i.length?e.insertBefore(s,i[t]):e.appendChild(s)}}},function(e,t,n){"use strict";var o=n(0);n.n(o).a},function(e,t,n){(e.exports=n(2)(!1)).push([e.i,".content[data-v-3a8061fa]{width:100%;display:flex;flex-direction:column;align-items:stretch}.btn[data-v-3a8061fa]{float:right}\n",""])},function(e,t,n){"use strict";var o=n(1);n.n(o).a},function(e,t,n){(e.exports=n(2)(!1)).push([e.i,".snack_with_progress .snack__content,.snack_with_progress .v-snack__content{height:80px}\n",""])},function(e,t,n){"use strict";n.r(t);var o=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("v-snackbar",{ref:"snackbar",staticClass:"snack_with_progress",attrs:{timeout:e.messageDuration},model:{value:e.isOpen,callback:function(t){e.isOpen=t},expression:"isOpen"}},[n("div",{staticClass:"content"},[n("v-progress-linear",{directives:[{name:"show",rawName:"v-show",value:-1!==e.messageOptions.duration,expression:"messageOptions.duration !== -1"}],attrs:{height:3},model:{value:e.value,callback:function(t){e.value=t},expression:"value"}}),e._v(" "),n("div",[e.component?n(e.component,{tag:"component"}):n("span",{domProps:{innerHTML:e._s(e.message)}}),e._v(" "),e.messageOptions.closeable?n("v-btn",{staticClass:"btn",attrs:{flat:"",dark:""},on:{click:function(t){e.isOpen=!1}}},[e._v(e._s(e.buttonCaption)+"\n "),e.queue.length>0?n("span",{staticStyle:{"white-space":"pre"}},[e._v(" ("+e._s(e.queue.length)+" more)")]):e._e()]):e.queue.length>0?n("span",[e._v("("+e._s(e.queue.length)+" more)")]):e._e(),e._v(" "),e._l(e.actions,function(t,o){return n("v-btn",{key:o,staticClass:"btn",attrs:{flat:"",dark:""},on:{click:function(){return e.onActionClick(t)}}},[e._v("\n "+e._s(t.caption)+"\n "),t.icon?n("v-icon",[e._v(e._s(t.icon))]):e._e()],1)})],2)],1)])};function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}o._withStripped=!0;var s={name:"SnackbarStack",data:function(){return{isOpen:!1,message:"",messageOptions:{},messageDuration:0,value:0,pollFreq:50,queue:[],component:void 0,outlets:{}}},props:{duration:{type:Number,default:6e3}},methods:{startOutletTimer:function(e,t){if(t.flushAll){for(;e.length>1;)e.shift();e.$thread&&(clearInterval(e.$thread),e.$thread=void 0)}else if(t.flushGroup){for(var n=e.length-1;n--;)t.group===e[n].options.group&&e.splice(n,1);1===e.length&&e.$thread&&(clearInterval(e.$thread),e.$thread=void 0)}else if(t.flushOtherGroups){for(var o=e.length-1;o--;)t.group!==e[o].options.group&&e.splice(o,1);1===e.length&&e.$thread&&(clearInterval(e.$thread),e.$thread=void 0)}if(!(e.length>1)){var r=e[0],s=function(e){r.ele=document.querySelector(e.options.outlet),e.ele?r.ele.innerHTML=e.message:console.info(e.message)};e.$thread=setTimeout(function t(){e.shift(),0===e.length?r.ele&&(r.ele.innerHTML=""):(r=e[0],e.$thread=setTimeout(t,r.options.duration||4e3),s(r))},r.options.duration||4e3),s(r)}},show:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t.outlet){var n=this.outlets[t.outlet];n||(n=[],this.outlets[t.outlet]=n),n.push({message:e,options:t,running:!1}),this.startOutletTimer(n,t)}else if(t.duration=t.duration||this.duration,t.closeable="boolean"!=typeof t.closeable||t.closeable,this.isOpen)if(t.flushAll)this.queue.length=0,this.queue.push({message:e,options:t}),this.isOpen=!1;else if(t.flushGroup){for(var o=this.queue.length;o--;)t.group===this.queue[o].options.group&&this.queue.splice(o,1);this.queue.push({message:e,options:t}),1===this.queue.length&&(this.messageOptions?t.group===this.messageOptions.group&&(this.isOpen=!1):this.isOpen=!1)}else if(t.flushOtherGroups){for(var r=this.queue.length;r--;)t.group!==this.queue[r].options.group&&this.queue.splice(r,1);this.queue.push({message:e,options:t}),1===this.queue.length&&(this.messageOptions?t.group!==this.messageOptions.group&&(this.isOpen=!1):this.isOpen=!1)}else this.queue.push({message:e,options:t});else this._show(e,t)},_show:function(e,t){var n,o=this;if("object"===r(e)&&e.toString&&(e=e.toString()),this.message=e,this.messageOptions=t,this.value=0,-1!==t.duration){var s=new Date;this.reg=setInterval(function(){o.value=100*(new Date-s)/(.93*o.messageDuration)},this.pollFreq)}t.template?(n=e.startsWith("#")?Vue.component("snackbar-template-component",{template:e}):void 0,this.component=n):this.component=void 0;this.messageDuration=-1===t.duration?99999999:t.duration,this.isOpen=!0},onActionClick:function(e){var t=this,n={close:function(){t.close()}};e.handler(n,this.messageOptions)},close:function(){this.isOpen=!1}},computed:{buttonCaption:function(){return this.queue.length>0?"Next":"Close"},actions:function(){var e=this.messageOptions.actions||[];return Array.isArray(e)||(e=[e]),e}},watch:{isOpen:function(e){var t=this;if(!e&&(this.reg&&clearInterval(this.reg),this.queue.length>0)){var n=this.queue.shift();this.$nextTick(function(){t._show(n.message,n.options)})}}}};n(4),n(6);var i=function(e,t,n,o,r,s,i,a){var u,l="function"==typeof e?e.options:e;if(t&&(l.render=t,l.staticRenderFns=n,l._compiled=!0),o&&(l.functional=!0),s&&(l._scopeId="data-v-"+s),i?(u=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),r&&r.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(i)},l._ssrRegister=u):r&&(u=a?function(){r.call(this,this.$root.$options.shadowRoot)}:r),u)if(l.functional){l._injectStyles=u;var c=l.render;l.render=function(e,t){return u.call(t),c(e,t)}}else{var p=l.beforeCreate;l.beforeCreate=p?[].concat(p,u):[u]}return{exports:e,options:l}}(s,o,[],!1,null,"3a8061fa",null);i.options.__file="src/components/SnackbarStack.vue";var a=i.exports,u={install:function(e,t){var n=(t||{}).duration,o=void 0===n?6e3:n,r=new(e.extend(a))({propsData:{duration:o}});function s(){var e=document.querySelector(".application--wrap");return e||(e=document.querySelector(".v-application--wrap")),e?(r.$mount(),e.appendChild(r.$el),!0):(console.warn("Could not install snackbarstack: CSS container not found"),!1)}if(e.prototype.$snackbar=r,e.$snackbar=r,!s())var i=setInterval(function(){s()&&clearInterval(i)},100)}};t.default=u}]).default});