UNPKG

vuedl

Version:
3 lines (2 loc) 17.7 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],e):e((t=t||self).vuedl={},t.Vue)}(this,function(t,e){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e,n,i,o,r,s){try{var a=t[r](s),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(i,o)}function o(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var s=t.apply(e,n);function a(t){i(s,o,r,a,c,"next",t)}function c(t){i(s,o,r,a,c,"throw",t)}a(void 0)})}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function a(t,e,n){return e&&s(t.prototype,e),n&&s(t,n),t}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,i)}return n}function l(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?u(Object(n),!0).forEach(function(e){c(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}e=e&&e.hasOwnProperty("default")?e.default:e;var h={computed:{$parameters:function(){return this.$attrs||this.$options.propsData||this.$props||{}},isNewRecord:function(){return!this.$parameters||!this.$parameters[this.$options.primaryKey]}}},f={name:"Activable",data:function(){return{isActive:!1}},watch:{isActive:function(t){this._dialogInstance?void 0!==this._dialogInstance.isActive&&(this._dialogInstance.isActive=t):this.$parent&&void 0!==this.$parent.isActive&&(this.$parent.isActive=t)}},methods:{close:function(){this.isActive=!1}}},d={name:"Layoutable",mixins:[f],inheritAttrs:!1,props:{width:{type:[String,Number],default:function(){return 450}},persistent:Boolean},data:function(){return{loading:!1}},computed:{isLayout:function(){return!0},getWidth:function(){return"string"==typeof this.width?this.width:this.width+"px"}},watch:{isActive:function(t){t||this._destroy()}},mounted:function(){this.isActive=!0},methods:{_destroy:function(){this.$destroy()},dismiss:function(){this.persistent||this.loading||(this.isActive=!1)},close:function(){this.isActive=!1}},beforeDestroy:function(){"function"==typeof this.$el.remove?this.$el.remove():this.$el.parentNode&&this.$el.parentNode.removeChild(this.$el)}};function p(t,e,n,i,o,r,s,a,c,u){"boolean"!=typeof s&&(c=a,a=s,s=!1);const l="function"==typeof n?n.options:n;let h;if(t&&t.render&&(l.render=t.render,l.staticRenderFns=t.staticRenderFns,l._compiled=!0,o&&(l.functional=!0)),i&&(l._scopeId=i),r?(h=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,c(t)),t&&t._registeredComponents&&t._registeredComponents.add(r)},l._ssrRegister=h):e&&(h=s?function(t){e.call(this,u(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,a(t))}),h)if(l.functional){const t=l.render;l.render=function(e,n){return h.call(n),t(e,n)}}else{const t=l.beforeCreate;l.beforeCreate=t?[].concat(t,h):[h]}return n}var v=p({render:function(){var t=this.$createElement,e=this._self._c||t;return e("div",{staticClass:"dialog-layout"},[e("dialog-child",this._b({ref:"dialog"},"dialog-child",this.$options.propsData,!1))],1)},staticRenderFns:[]},void 0,{},void 0,!1,void 0,!1,void 0,void 0,void 0),y=function(t){return"function"==typeof t},m=function(t){return null==t},_=function(t){return t&&(t instanceof Promise||"function"==typeof t.then)};function g(t,e){var n=this,i=[],o=this,r={};if("object"!=typeof t)return t;var s=function(s){var a=t[s];y(a)&&(a=a.call(n,e)),_(a)?(a=a.then(function(t){if(!m(t))return s.startsWith("...")?r=Object.assign({},r,t):r[s]=t,t}),e&&y(e.asyncDataError)&&(a=a.catch(function(n){return e.asyncDataError.call(o,n,{key:s,obj:t})})),i.push(a)):r[s]=a};for(var a in t)s(a);return Promise.all(i).then(function(){return Promise.resolve(r)})}var b=function(t,e){var n=[];if(t.options.asyncData&&!t.options.__hasAsyncData){var i=function(t,e){var n;if(n=y(t)?t.call(this,e):t,!_(n)){if("object"==typeof n)return g.call(this,n,e);n=Promise.resolve(n)}var i=this;return n.then(function(t){return g.call(i,t)})}(t.options.asyncData,e);i.then(function(e){return function(t,e){if(e||!t.options.__hasAsyncData){var n=t.options._originDataFn||t.options.data||function(){return{}};t.options._originDataFn=n,t.options.data=function(){var t=n.call(this);return Object.assign({},t,e)},t.options.__hasAsyncData=!0,t._Ctor&&t._Ctor.options&&(t._Ctor.options.data=t.options.data)}}(t,e),e}),n.push(i)}return t.options.fetch&&!t.options.__hasAsyncData&&n.push(t.options.fetch(e)),t.options.__hasAsyncData=!0,Promise.all(n)};function w(t){t&&!t._isDestroyed&&"function"==typeof t.$destroy&&t.$destroy()}function k(t){var e;return(e="string"==typeof t?document.querySelector(t):t)||(e=document.body),e}var $=1,x=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=n.layout,o=n.container;if(r(this,t),!e)throw Error("Component was not set");this._layout=i||{component:v,options:{}},this._component=e,this._vm=null,this._vmDialog=null,this._options={},this.id=++$,this._resolvers=[],this.container=k(o)}return a(t,[{key:"show",value:function(){var t=o(regeneratorRuntime.mark(function t(){var i,o,r,s,a,c,u,f=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=f.length>0&&void 0!==f[0]?f[0]:{},o=f.length>1&&void 0!==f[1]?f[1]:{},!e.prototype.$isServer){t.next=4;break}return t.abrupt("return");case 4:if("object"!==n(r=this._component)||r.options||(r=e.extend(l({},this._component))),r.options.primaryKey&&(r=r.extend({mixins:[h]})),!this.hasAsyncPreload){t.next=10;break}return t.next=10,b(r,l({},this.context,{params:i}));case 10:return s=(s=e.extend({mixins:[d],components:{"dialog-child":r}})).extend(this._layout.component),r.options.inheritAttrs=!1,a=l({},this._layout.options,{},i,{},o&&o.propsData),(c=new s(l({},this.context,{},o,{propsData:a}))).$mount(),u=c.$refs.dialog,c.$on("hook:destroyed",this._onDestroyed.bind(this)),c.$on("submit",this.onReturn.bind(this)),u&&u.$on("submit",this.onReturn.bind(this)),this._vm=c,this._vm._dialogInstance=u,this._vmDialog=u,(i.container?k(i.container):this.container).appendChild(c.$el),t.abrupt("return",this);case 26:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"wait",value:function(){var t=this;return new Promise(function(e){t._resolvers.push(e)})}},{key:"_onDestroyed",value:function(){this.remove()}},{key:"remove",value:function(){this.onDestroyed&&this.onDestroyed(this),this._processResultPromises(),w(this._vm),w(this._vmDialog),this._vm=null,this._vmDialog=null}},{key:"_processResultPromises",value:function(t){this._resolvers.length&&(this._resolvers.forEach(function(e){return e(t)}),this._resolvers=[])}},{key:"onReturn",value:function(t){this._processResultPromises(t),this.close()}},{key:"close",value:function(){this._vm&&this._vm.close()}},{key:"showed",get:function(){return!!this._vm&&!this._vm._isDestroyed}},{key:"element",get:function(){return this._vm&&this._vm.$el}},{key:"hasAsyncPreload",get:function(){return this._component&&(t=this._component.options||this._component,Boolean(!t.__hasAsyncData&&(t.asyncData||t.fetch)));var t}},{key:"vm",get:function(){return this._vm}},{key:"vmd",get:function(){return this._vmDialog}}]),t}(),A=function(){function t(e){r(this,t),this._component=e,this._vm=null}return a(t,[{key:"show",value:function(){if(!this._vm){var t=e.extend(this._component);this._vm=new t,this._vm.$mount(),document.body.appendChild(this._vm.$el)}this._vm.visible=!0}},{key:"hide",value:function(){this._vm.visible=!1}},{key:"destroy",value:function(){this._vm&&(this._vm.$el.parentNode.removeChild(this._vm.$el),this._vm.$destroy(),this._vm=null)}}]),t}(),D=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=n.context,o=n.container;r(this,t),this._context=i||{},x.prototype.context=i||{},this._components={},this._layouts={},this._overlays={},this._container=o,this._emitter=new e({}),this._instances=[]}return a(t,[{key:"layout",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this._layouts[t]={component:e,options:n}}},{key:"getLayout",value:function(t){if("function"==typeof t){var e=t.call(this._context);return l({},t=this._layouts[e.name||"default"],{},{options:e})}if("object"===n(t)&&"function"==typeof t.render)return{component:t};if(Array.isArray(t)){var i=t[0],o=t[1]||{},r="object"===n(i)&&"function"==typeof i.render?{component:i}:this._layouts[i];return r&&{component:r.component,options:l({},r.options,{},o)}}return this._layouts[t]}},{key:"overlay",value:function(t,e){if(void 0===e){if(this._overlays[t])return this._overlays[t];throw new Error('Overlay "'.concat(t," not found\n Please register it by calling dialog.overlay('").concat(t,"', component)"))}this._overlays[t]=new A(e)}},{key:"getComponent",value:function(t){if(!this._components[t])throw new Error('Component "'.concat(t,"\" was not found.\n Please register it by calling dialog.register('").concat(t,"', component)"));return this._components[t]}},{key:"component",value:function(t,e){var n=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(void 0===e)return this._components[t];this._components[t]={component:e,options:i},Object.defineProperty(this,t,{get:function(){return n.createFunctionWrapper(t)},configurable:!0})}},{key:"getComponentProperty",value:function(t,e){return t.options?t.options[e]:t[e]}},{key:"create",value:function(t){if(!t)throw new Error("Component is incorrect");var e=this.getLayout(this.getComponentProperty(t,"layout")||"default"),n=new x(t,{layout:e,context:this._context,container:this._container});return this._emitter.$emit("created",{dialog:n}),n}},{key:"show",value:function(){var t=o(regeneratorRuntime.mark(function t(e){var n,i,o,r,s=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=s.length>1&&void 0!==s[1]?s[1]:{},i=this.create(e),o=!!i.hasAsyncPreload&&(this.getComponentProperty(e,"overlay")||"default"),(r=o&&this._overlays[o]&&this.overlay(o))&&r.show(),t.prev=5,t.next=8,i.show(n);case 8:return this._emitter.$emit("shown",{dialog:i}),r&&r.hide(),i.onDestroyed=this.onDialogDestroyed.bind(this),t.abrupt("return",n.waitForResult?i.wait():i);case 14:throw t.prev=14,t.t0=t.catch(5),this._emitter.$emit("error",{error:t.t0,dialog:i}),r&&r.hide(),t.t0;case 19:case"end":return t.stop()}},t,this,[[5,14]])}));return function(e){return t.apply(this,arguments)}}()},{key:"createFunctionWrapper",value:function(t){var e=this,n=this.getComponent(t);return function(t){return e.show(n.component,l({},n.options,{},t))}}},{key:"showAndWait",value:function(){var t=o(regeneratorRuntime.mark(function t(e,n){var i;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.show(e,n);case 2:return i=t.sent,t.abrupt("return",i.wait());case 4:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"on",value:function(t,e){this._emitter.$on(t,e)}},{key:"off",value:function(t,e){this._emitter.$off(t,e)}},{key:"once",value:function(t,e){this._emitter.$once(t,e)}},{key:"onDialogDestroyed",value:function(t){this._emitter.$emit("destroyed",{dialog:t})}},{key:"context",get:function(){return this._context}}]),t}(),O=p({render:function(){var t=this.$createElement,e=this._self._c||t;return e("transition",{attrs:{name:"opacity"}},[this.visible?e("div",{staticClass:"dialog-overlay-loading",style:{zIndex:this.zIndex}},[this._v("\n Loading…\n ")]):this._e()])},staticRenderFns:[]},void 0,{name:"VDialogOverlay",props:{zIndex:{type:Number,default:function(){return 1250}},visible:{type:Boolean,default:function(){return!1}}}},void 0,!1,void 0,!1,void 0,void 0,void 0),P={name:"Returnable",props:{returnValue:null},data:function(){return{originalValue:this.returnValue,returnResovers:[]}},methods:{return:function(t){this.originalValue=t,this.$root.$emit("submit",this.originalValue),this.$emit("submit",this.originalValue)}}},C={name:"Actionable",mixins:[P],data:function(){return{loadingAction:null}},props:{actions:{type:[Array,Object,Function],default:function(){return[]}},handle:Function,handler:Function,params:Object},computed:{actionlist:function(){var t=[],e="function"==typeof this.actions?this.actions(this):this.actions||[];for(var i in e){var o=e[i];["string","boolean"].includes(n(o))&&(o={text:o}),o.key||(o.key=isNaN(i)?i:o.text||i),["true","false"].indexOf(o.key)>=0&&(o.key=JSON.parse(o.key)),this.isActionVisible(o)&&("string"==typeof o.icon&&(o.icon={text:o.icon}),t.push(o))}return t}},created:function(){this.handle&&console.warn('DEPRECATED: "handle" prop will be deprecated, please use "handler" instead')},methods:{trigger:function(t){var e=this.actionlist.find(function(e){return e.key===t});e&&!this.isActionDisabled(e)&&this.isActionVisible(e)&&this.onActionClick(e)},setLoadingToInstance:function(t,e){t&&void 0!==t.loading&&(t.loading=e)},setLoadingState:function(t){this.$emit("loading",t),!t&&(this.loadingAction=null),this.setLoadingToInstance(this.$root,t),this.setLoadingToInstance(this.$root._dialogInstance,t)},get:function(t,e){return void 0===t?e:"function"==typeof t?t(this.params):t},isActionDisabled:function(t){return this.get(t.disabled,!1)},isActionVisible:function(t){return this.get(t.visible,!0)},isActionInLoading:function(t){return this.loadingAction===t.key||this.get(t.loading)},onActionClick:function(){var t=o(regeneratorRuntime.mark(function t(e){var n,i,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=void 0===e.closable||!0===e.closable,"function"!=typeof(i=e.handle||e.handler||this.handle||this.handler)){t.next=20;break}return this.loadingAction=e.key,this.setLoadingState(!0),t.prev=5,t.next=8,i(this.params,e);case 8:o=t.sent,this.setLoadingState(!1),!1!==o&&n&&this.return(o||e.key),t.next=18;break;case 13:throw t.prev=13,t.t0=t.catch(5),this.setLoadingState(!1),console.error("error",t.t0),t.t0;case 18:t.next=21;break;case 20:n&&this.return(e.key);case 21:case"end":return t.stop()}},t,this,[[5,13]])}));return function(e){return t.apply(this,arguments)}}()}},R={name:"Confirmable",props:{type:{type:String},text:{type:[String,Function],reqiured:!0},title:{type:String},actions:{type:[Array,Object,Function]}}},j=[],E={props:{verticalOffset:Number,showClose:{type:Boolean,default:function(){return!0}},position:{type:String,default:function(){return"top-right"}},timeout:{type:[Number,Boolean],default:function(){return 4500}},width:{type:Number,default:function(){return 330}},zIndex:{type:Number,default:function(){return 2e3}}},data:function(){return{activeTimeout:null}},computed:{horizontalClass:function(){return this.position.indexOf("right")>-1?"right":"left"},verticalProperty:function(){return/^top-/.test(this.position)?"top":"bottom"},getStyle:function(){var t;return c(t={},this.verticalProperty,"".concat(this.verticalOffset,"px")),c(t,"max-width","".concat(this.width,"px")),c(t,"z-index",this.zIndex),t}},methods:{_destroy:function(){this.$el.addEventListener("transitionend",this.onTransitionEnd)},onTransitionEnd:function(){this.$el.removeEventListener("transitionend",this.onTransitionEnd),this.$destroy()},clearTimer:function(){clearTimeout(this.activeTimeout)},startTimer:function(){this.timeout>0&&(this.activeTimeout=setTimeout(this.close,this.timeout))},keydown:function(t){46===t.keyCode||8===t.keyCode?this.clearTimer():27===t.keyCode?this.close():this.startTimer()},close:function(){this.isActive=!1}},watch:{isActive:function(t){var e,n,i;t?(n=(e=this).position,i=10,j.filter(function(t){return t.position===n}).forEach(function(t){i+=t.$el.offsetHeight+10}),j.push(e),e.verticalOffset=i):function(t){var e=j.findIndex(function(e){return e===t});if(!(e<0)){j.splice(e,1);var n=j.length,i=t.position;if(n){var o=10;j.filter(function(t){return t.position===i}).forEach(function(t){t.verticalOffset=o,o+=t.$el.offsetHeight+10})}}}(this)}},mounted:function(){this.startTimer(),document.addEventListener("keydown",this.keydown)},beforeDestroy:function(){document.removeEventListener("keydown",this.keydown)}};var S={install:function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!t.installed){t.installed=!0;var i=n.property||"$dialog",o=new D(n);o.overlay("default",O),e.prototype[i]?console.warn("Property ".concat(i," is already defined in Vue prototype")):Object.defineProperty(e.prototype,i,{get:function(){return o},configurable:!0})}}},T=null;"undefined"!=typeof window?T=window.Vue:"undefined"!=typeof global&&(T=global.Vue),T&&T.use(S),t.Actionable=C,t.Activable=f,t.Confirmable=R,t.Notifiable=E,t.Recordable=h,t.Returnable=P,t.default=S,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=index.umd.min.js.map