jenesius-vue-modal
Advanced tools
Comparing version 1.10.3 to 1.11.0
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".modal-container{position:fixed;left:0;top:0;height:100%;width:100%;display:flex;align-items:center;justify-content:center;background-color:#3e3e3e21;cursor:pointer}.modal-item{cursor:default}.modal-list-enter-active,.modal-list-leave-active,.modal-list-enter-active .modal-item,.modal-list-leave-active .modal-item{transition:all .2s ease}.modal-list-enter-from,.modal-list-leave-to{opacity:0!important}.modal-list-enter-from .modal-item,.modal-list-leave-to .modal-item{transform:translateY(-60px)}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})(); | ||
"use strict";/*! | ||
* jenesius-vue-modal v1.10.3 | ||
* (c) 2023 Jenesius | ||
* jenesius-vue-modal v1.11.0 | ||
* (c) 2024 Jenesius | ||
* @license MIT | ||
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue");var E=function(t,e){return E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(n[i]=o[i])},E(t,e)};function B(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");E(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function m(t,e,n,o){function i(r){return r instanceof n?r:new n(function(a){a(r)})}return new(n||(n=Promise))(function(r,a){function c(d){try{u(o.next(d))}catch(b){a(b)}}function l(d){try{u(o.throw(d))}catch(b){a(b)}}function u(d){d.done?r(d.value):i(d.value).then(c,l)}u((o=o.apply(t,e||[])).next())})}function p(t,e){var n={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},o,i,r,a;return a={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function c(u){return function(d){return l([u,d])}}function l(u){if(o)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(n=0)),n;)try{if(o=1,i&&(r=u[0]&2?i.return:u[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,u[1])).done)return r;switch(i=0,r&&(u=[u[0]&2,r.value]),u[0]){case 0:case 1:r=u;break;case 4:return n.label++,{value:u[1],done:!1};case 5:n.label++,i=u[1],u=[0];continue;case 7:u=n.ops.pop(),n.trys.pop();continue;default:if(r=n.trys,!(r=r.length>0&&r[r.length-1])&&(u[0]===6||u[0]===2)){n=0;continue}if(u[0]===3&&(!r||u[1]>r[0]&&u[1]<r[3])){n.label=u[1];break}if(u[0]===6&&n.label<r[1]){n.label=r[1],r=u;break}if(r&&n.label<r[2]){n.label=r[2],n.ops.push(u);break}r[2]&&n.ops.pop(),n.trys.pop();continue}u=e.call(t,n)}catch(d){u=[6,d],i=0}finally{o=r=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}var f=function(t){B(e,t);function e(n,o){o===void 0&&(o=null);var i=t.call(this)||this;return i.isModalError=!0,i.message=n,i.details=o,i}return e.Undefined=function(n){return new e("Modal with id: ".concat(n," not founded. The modal window may have been closed earlier."))},e.UndefinedGuardName=function(n){return new e("Guard's name ".concat(n," is not declaration."))},e.NextReject=function(n){return new e("Guard returned false. Modal navigation was stopped. Modal id ".concat(n))},e.GuardDeclarationType=function(n){return new e("Guard's type should be a function. Provided:",n)},e.ConfigurationType=function(n){return new e("Configuration type must be an Object. Provided",n)},e.ConfigurationUndefinedParam=function(n,o){return new e("In configuration founded unknown parameter: ".concat(n,". Available are ").concat(o.join(", ")," "))},e.QueueNoEmpty=function(){return new e("Modal's queue is not empty. Probably some modal reject closing by onClose hook.")},e.EmptyModalQueue=function(){return new e("Modal queue is empty.")},e.NotInitialized=function(n){return new e("Modal Container not found. Put container from jenesius-vue-modal in App's template. Namespace: ".concat(n,". Check documentation for more information https://modal.jenesius.com/docs.html/installation#getting-started."))},e.ModalComponentNotProvided=function(){return new e("The first parameter(VueComponent) was not specified.")},e.DuplicatedRouterIntegration=function(){return new e("useModalRouter.init should escaped only once.")},e.ModalRouterIntegrationNotInitialized=function(){return new e("The integration was not initialized. Please, use useModalRouter.init(router). For more information: https://modal.jenesius.com/docs.html/integration-vue-router#installation")},e.ModalEventNameMustBeString=function(n){return new e("Event name must be a string. Provided: ".concat(n))},e.ModalNotFoundByID=function(n){return new e("Modal with ID ".concat(n," was not found."))},e.ModalNotExistsInStore=function(n){return new e("Provided name(".concat(n,") don't exist in the store. Has the given name been added to the store?"))},e}(Error),h=function(){function t(){this.state=new Map,t.instance=this}return t.prototype.getByName=function(e){return e===void 0&&(e=t.DEFAULT_NAMESPACE),this.state.has(e)||this.state.set(e,{queue:s.reactive([]),initialized:!1}),this.state.get(e)},t.prototype.forceClean=function(){this.state.forEach(function(e){e.queue.splice(0,e.queue.length)})},t.DEFAULT_NAMESPACE="default",t}(),k=function(){var t=new h,e={scrollLock:!0,animation:"modal-list",backgroundClose:!0,escClose:!0,store:{},skipInitCheck:!1},n=t.getByName().queue;return s.watch(function(){return n},function(){e.scrollLock&&(n.length?document.body.style.overflowY="hidden":document.body.style.overflowY="auto")},{deep:!0}),{namespaceStore:t,configuration:e}}();function v(t){return k.namespaceStore.getByName(t)}var g=k.configuration;function N(t){var e={backgroundClose:g.backgroundClose,isRoute:!1,namespace:h.DEFAULT_NAMESPACE};return t.backgroundClose!==void 0&&(e.backgroundClose=t.backgroundClose),t.isRoute&&(e.isRoute=t.isRoute),t.namespace&&(e.namespace=t.namespace),e}function q(t){t===void 0&&(t={});var e={background:!1,esc:!1};return Object.assign(e,t)}function R(t){return t||(t={}),t}function M(t,e){e===void 0&&(e={});var n=w.STORE.get(t);if(!n)return Promise.reject(f.ModalNotFoundByID(t));var o=v(n.namespace),i=o.queue.findIndex(function(a){return a.id===t});if(i===-1)return Promise.reject(f.Undefined(t));var r=y.get(t,"close").map(function(a){return F(a,t,q(e))});return I(r).then(function(){o.queue.splice(i,1),y.delete(t)})}var w=function(){function t(e,n,o){var i=this;this.events=s.reactive({}),this.backgroundClose=!0,this.isRoute=!1,this.id=t.modalId++,this.component=e,this.props=s.ref(n),this.closed=s.computed(function(){return!v(o.namespace).queue.includes(i)}),e.beforeModalClose&&y.add(this.id,"close",e.beforeModalClose);var r=N(o);this.backgroundClose=r.backgroundClose,this.isRoute=r.isRoute,this.namespace=r.namespace,t.STORE.set(this.id,this)}return t.prototype.close=function(){return M(this.id)},Object.defineProperty(t.prototype,"onclose",{set:function(e){y.add(this.id,"close",e)},enumerable:!1,configurable:!0}),t.prototype.on=function(e,n){var o=this;return Array.isArray(this.events[e])||(this.events[e]=[]),this.events[e].push(n),function(){var i=o.events[e].indexOf(n);i!==-1&&o.events[e].splice(i,1)}},t.STORE=new Map,t.modalId=0,t.EVENT_PROMPT="jenesius-vue-modal:____P____R____O____M____P____T",t}();function T(t){return w.STORE.get(t)}var D={store:{},add:function(t,e,n){var o;if(typeof n!="function")throw f.GuardDeclarationType(n);this.store[t]||(this.store[t]=(o={},o[e]=[],o)),this.store[t][e]||(this.store[t][e]=[]),this.store[t][e].push(n)},get:function(t,e){return t in this.store?e in this.store[t]?this.store[t][e]:[]:[]},delete:function(t){t in this.store&&delete this.store[t]}};const y=D;function I(t){return t.reduce(function(e,n){return e.then(function(){return n()})},Promise.resolve())}function F(t,e,n){return function(){return new Promise(function(o,i){var r,a=function(c){c===void 0&&(c=!0),c===!1&&i(f.NextReject(e)),o()};Promise.resolve(t.call((r=T(e))===null||r===void 0?void 0:r.instance,n)).then(a).catch(function(c){return i(c)})})}}function O(t){return t=R(t),I(v(t.namespace).queue.map(function(e){return function(){return e.close()}}))}function C(t){var e=v(t),n=e.queue;if(n.length!==0)return n[n.length-1]}function z(t){t=R(t);var e=C(t.namespace);return e?e.close():Promise.resolve()}function G(t,e,n){var o=N(n),i=v(o.namespace);if(o.namespace===h.DEFAULT_NAMESPACE&&!i.initialized&&!g.skipInitCheck)throw f.NotInitialized(o.namespace);if(typeof t=="string"){var r=x(t);if(!r)throw f.ModalNotExistsInStore(t);t=r}if(!t)throw f.ModalComponentNotProvided();var a=new w(t,e,o);return i.queue.push(s.markRaw(a)),a}function S(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),Promise.resolve().then(function(){return G(t,e,n)})}function A(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),O({namespace:n.namespace}).then(function(){var o=v(n.namespace);if(o.queue.length)throw f.QueueNoEmpty()}).then(function(){return S(t,e,n)})}function Q(t){if(typeof t!="object")throw f.ConfigurationType(t);Object.assign(g,t)}function U(t){var e,n,o,i=s.getCurrentInstance(),r=String(((e=i==null?void 0:i.props)===null||e===void 0?void 0:e.modalId)||((n=i==null?void 0:i.props)===null||n===void 0?void 0:n["modal-id"])||((o=i==null?void 0:i.attrs)===null||o===void 0?void 0:o.modalId)),a=r.replace(/[^0-9]/g,"");y.add(Number(a),"close",t)}function L(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),m(this,void 0,void 0,function(){var o,i=this;return p(this,function(r){switch(r.label){case 0:return[4,S(t,e,n)];case 1:return o=r.sent(),[2,new Promise(function(a){o.on(w.EVENT_PROMPT,function(c){return m(i,void 0,void 0,function(){return p(this,function(l){switch(l.label){case 0:return[4,o.close()];case 1:return l.sent(),a(c),[2]}})})})})]}})})}function x(t){return g.store[t]||void 0}const V=["onPointerdown"],P={__name:"WidgetModalContainerItem",props:{id:Number},setup(t){const e=s.ref(null),o=T(t.id);function i(){if(o.backgroundClose)return M(o.id,{background:!0}).catch(()=>{})}return s.watch(()=>e.value,r=>{o.instance=r}),(r,a)=>(s.openBlock(),s.createElementBlock("div",{class:"widget__modal-container__item modal-container",onPointerdown:s.withModifiers(i,["self","stop"])},[(s.openBlock(),s.createBlock(s.resolveDynamicComponent(s.unref(o).component),s.mergeProps(s.unref(o).props.value,{class:"modal-item widget__modal-wrap",modalId:`_modal_${t.id}`,ref_key:"modalRef",ref:e},s.toHandlers(s.unref(o).events)),null,16,["modalId"]))],40,V))}};function W(t){t===void 0&&(t=h.DEFAULT_NAMESPACE);var e=h.instance.getByName(t);e.initialized=!0,t===h.DEFAULT_NAMESPACE&&document.addEventListener("keyup",function(n){if(g.escClose&&(n.key==="Escape"||n.code==="Escape")){var o=C(t);if(!o)return;M(o.id,{esc:!0}).catch(function(){})}})}const $={props:{namespace:String},setup(t){return s.onMounted(()=>{W(t.namespace)}),()=>{const e=v(t.namespace);return s.h(s.TransitionGroup,{name:g.animation},{default:()=>e.queue.map(n=>s.h(P,{key:n.id,id:n.id}))})}},components:{WidgetContainerModalItem:P}};var _={router:null};function H(t){var e=this;if(_.router)throw f.DuplicatedRouterIntegration();_.router=t;function n(o){for(var i=o.matched.length-1;i>=0;i--){var r=o.matched[i].components,a=Object.values(r).find(function(c){return c._isModal});if(a)return a}return null}t.beforeEach(function(o,i){return m(e,void 0,void 0,function(){var r,a,c;return p(this,function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),r=n(i),r&&!(!((c=(a=r.getModalObject())===null||a===void 0?void 0:a.closed)===null||c===void 0)&&c.value)?[4,r.close(!0)]:[3,2];case 1:l.sent(),l.label=2;case 2:return[3,4];case 3:return l.sent(),[2,!1];case 4:return[2]}})})}),t.afterEach(function(o){return m(e,void 0,void 0,function(){var i;return p(this,function(r){switch(r.label){case 0:return i=n(o),i?[4,i.initialize()]:[3,2];case 1:r.sent(),r.label=2;case 2:return[2]}})})})}function j(t){var e=null,n=!1;function o(){return m(this,void 0,void 0,function(){return p(this,function(i){switch(i.label){case 0:if(!_.router)throw f.ModalRouterIntegrationNotInitialized();return n=!1,e=null,[4,A(t,s.computed(function(){var r;return(r=_.router)===null||r===void 0?void 0:r.currentRoute.value.params}),{isRoute:!0})];case 1:return e=i.sent(),e.onclose=function(){var r;n||(r=_.router)===null||r===void 0||r.back()},[2]}})})}return{getModalObject:function(){return e},_isModal:!0,close:function(i){return i===void 0&&(i=!1),m(this,void 0,void 0,function(){return p(this,function(r){switch(r.label){case 0:return n=i,e?[4,e.close()]:[3,2];case 1:return[2,r.sent()];case 2:return[2]}})})},initialize:o,setup:function(){return function(){return null}}}}j.init=H;var Y=v().queue;function J(t){return v(t).queue}exports.Modal=w;exports.closeById=M;exports.closeModal=O;exports.config=Q;exports.container=$;exports.getComponentFromStore=x;exports.getCurrentModal=C;exports.getQueueByNamespace=J;exports.modalQueue=Y;exports.onBeforeModalClose=U;exports.openModal=A;exports.popModal=z;exports.promptModal=L;exports.pushModal=S;exports.useModalRouter=j; | ||
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue");var E=function(t,e){return E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(n[o]=i[o])},E(t,e)};function q(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");E(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function p(t,e,n,i){function o(r){return r instanceof n?r:new n(function(u){u(r)})}return new(n||(n=Promise))(function(r,u){function c(d){try{a(i.next(d))}catch(b){u(b)}}function l(d){try{a(i.throw(d))}catch(b){u(b)}}function a(d){d.done?r(d.value):o(d.value).then(c,l)}a((i=i.apply(t,e||[])).next())})}function g(t,e){var n={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},i,o,r,u;return u={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function c(a){return function(d){return l([a,d])}}function l(a){if(i)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(n=0)),n;)try{if(i=1,o&&(r=a[0]&2?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[a[0]&2,r.value]),a[0]){case 0:case 1:r=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,o=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(r=n.trys,!(r=r.length>0&&r[r.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]<r[3])){n.label=a[1];break}if(a[0]===6&&n.label<r[1]){n.label=r[1],r=a;break}if(r&&n.label<r[2]){n.label=r[2],n.ops.push(a);break}r[2]&&n.ops.pop(),n.trys.pop();continue}a=e.call(t,n)}catch(d){a=[6,d],o=0}finally{i=r=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}var f=function(t){q(e,t);function e(n,i){i===void 0&&(i=null);var o=t.call(this)||this;return o.isModalError=!0,o.message=n,o.details=i,o}return e.Undefined=function(n){return new e("Modal with id: ".concat(n," not founded. The modal window may have been closed earlier."))},e.UndefinedGuardName=function(n){return new e("Guard's name ".concat(n," is not declaration."))},e.NextReject=function(n){return new e("Guard returned false. Modal navigation was stopped. Modal id ".concat(n))},e.GuardDeclarationType=function(n){return new e("Guard's type should be a function. Provided:",n)},e.ConfigurationType=function(n){return new e("Configuration type must be an Object. Provided",n)},e.ConfigurationUndefinedParam=function(n,i){return new e("In configuration founded unknown parameter: ".concat(n,". Available are ").concat(i.join(", ")," "))},e.QueueNoEmpty=function(){return new e("Modal's queue is not empty. Probably some modal reject closing by onClose hook.")},e.EmptyModalQueue=function(){return new e("Modal queue is empty.")},e.NotInitialized=function(n){return new e("Modal Container not found. Put container from jenesius-vue-modal in App's template. Namespace: ".concat(n,". Check documentation for more information https://modal.jenesius.com/docs.html/installation#getting-started."))},e.ModalComponentNotProvided=function(){return new e("The first parameter(VueComponent) was not specified.")},e.DuplicatedRouterIntegration=function(){return new e("useModalRouter.init should escaped only once.")},e.ModalRouterIntegrationNotInitialized=function(){return new e("The integration was not initialized. Please, use useModalRouter.init(router). For more information: https://modal.jenesius.com/docs.html/integration-vue-router#installation")},e.ModalEventNameMustBeString=function(n){return new e("Event name must be a string. Provided: ".concat(n))},e.ModalNotFoundByID=function(n){return new e("Modal with ID ".concat(n," was not found."))},e.ModalNotExistsInStore=function(n){return new e("Provided name(".concat(n,") don't exist in the store. Has the given name been added to the store?"))},e}(Error),m=function(){function t(){this.state=new Map,t.instance=this}return t.prototype.getByName=function(e){return e===void 0&&(e=t.DEFAULT_NAMESPACE),this.state.has(e)||this.state.set(e,{queue:s.reactive([]),initialized:!1}),this.state.get(e)},t.prototype.forceClean=function(){this.state.forEach(function(e){e.queue.splice(0,e.queue.length)})},t.DEFAULT_NAMESPACE="default",t}(),N=function(){var t=new m,e={scrollLock:!0,animation:"modal-list",backgroundClose:!0,escClose:!0,store:{},skipInitCheck:!1},n=t.getByName().queue;return s.watch(function(){return n},function(){e.scrollLock&&(n.length?document.body.style.overflowY="hidden":document.body.style.overflowY="auto")},{deep:!0}),{namespaceStore:t,configuration:e}}();function v(t){return N.namespaceStore.getByName(t)}var _=N.configuration;function R(t){var e={backgroundClose:_.backgroundClose,isRoute:!1,namespace:m.DEFAULT_NAMESPACE};return t.backgroundClose!==void 0&&(e.backgroundClose=t.backgroundClose),t.isRoute&&(e.isRoute=t.isRoute),t.namespace&&(e.namespace=t.namespace),e}function S(t){t===void 0&&(t={});var e={background:!1,esc:!1};return Object.assign(e,t)}function T(t){return t||(t={}),t}function w(t,e){e===void 0&&(e={});var n=M.STORE.get(t);if(!n)return Promise.reject(f.ModalNotFoundByID(t));var i=v(n.namespace),o=i.queue.findIndex(function(u){return u.id===t});if(o===-1)return Promise.reject(f.Undefined(t));var r=h.get(t,"close").map(function(u){return F(u,t,S(e))});return O(r).then(function(){i.queue.splice(o,1)}).then(function(){h.get(t,"destroy").forEach(function(u){return u(S(e))})}).then(function(){h.delete(t)})}var M=function(){function t(e,n,i){var o=this;this.events=s.reactive({}),this.backgroundClose=!0,this.isRoute=!1,this.id=t.modalId++,this.component=e,this.props=s.ref(n),this.closed=s.computed(function(){return!v(i.namespace).queue.includes(o)}),e.beforeModalClose&&h.add(this.id,"close",e.beforeModalClose);var r=R(i);this.backgroundClose=r.backgroundClose,this.isRoute=r.isRoute,this.namespace=r.namespace,t.STORE.set(this.id,this)}return t.prototype.close=function(){return w(this.id)},Object.defineProperty(t.prototype,"onclose",{set:function(e){h.add(this.id,"close",e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ondestroy",{set:function(e){h.add(this.id,"destroy",e)},enumerable:!1,configurable:!0}),t.prototype.on=function(e,n){var i=this;return Array.isArray(this.events[e])||(this.events[e]=[]),this.events[e].push(n),function(){var o=i.events[e].indexOf(n);o!==-1&&i.events[e].splice(o,1)}},t.STORE=new Map,t.modalId=0,t.EVENT_PROMPT="jenesius-vue-modal:____P____R____O____M____P____T",t}();function I(t){return M.STORE.get(t)}var D={store:{},add:function(t,e,n){var i,o;if(typeof n!="function")throw f.GuardDeclarationType(n);this.store[t]||(this.store[t]=(i={},i[e]=[],i)),this.store[t][e]||(this.store[t][e]=[]),(o=this.store[t][e])===null||o===void 0||o.push(n)},get:function(t,e){return t in this.store?e in this.store[t]?this.store[t][e]||[]:[]:[]},delete:function(t){t in this.store&&delete this.store[t]}};const h=D;function O(t){return t.reduce(function(e,n){return e.then(function(){return n()})},Promise.resolve())}function F(t,e,n){return function(){return new Promise(function(i,o){var r,u=function(c){c===void 0&&(c=!0),c===!1&&o(f.NextReject(e)),i()};Promise.resolve(t.call((r=I(e))===null||r===void 0?void 0:r.instance,n)).then(u).catch(function(c){return o(c)})})}}function A(t){return t=T(t),O(v(t.namespace).queue.map(function(e){return function(){return e.close()}}))}function C(t){var e=v(t),n=e.queue;if(n.length!==0)return n[n.length-1]}function z(t){t=T(t);var e=C(t.namespace);return e?e.close():Promise.resolve()}function G(t,e,n){var i=R(n),o=v(i.namespace);if(i.namespace===m.DEFAULT_NAMESPACE&&!o.initialized&&!_.skipInitCheck)throw f.NotInitialized(i.namespace);if(typeof t=="string"){var r=j(t);if(!r)throw f.ModalNotExistsInStore(t);t=r}if(!t)throw f.ModalComponentNotProvided();var u=new M(t,e,i);return o.queue.push(s.markRaw(u)),u}function P(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),Promise.resolve().then(function(){return G(t,e,n)})}function x(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),A({namespace:n.namespace}).then(function(){var i=v(n.namespace);if(i.queue.length)throw f.QueueNoEmpty()}).then(function(){return P(t,e,n)})}function Q(t){if(typeof t!="object")throw f.ConfigurationType(t);Object.assign(_,t)}function U(t){var e,n,i,o=s.getCurrentInstance(),r=String(((e=o==null?void 0:o.props)===null||e===void 0?void 0:e.modalId)||((n=o==null?void 0:o.props)===null||n===void 0?void 0:n["modal-id"])||((i=o==null?void 0:o.attrs)===null||i===void 0?void 0:i.modalId)),u=r.replace(/[^0-9]/g,"");h.add(Number(u),"close",t)}function L(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),p(this,void 0,void 0,function(){var i,o,r=this;return g(this,function(u){switch(u.label){case 0:return[4,P(t,e,n)];case 1:return i=u.sent(),o=!1,[2,new Promise(function(c){i.on(M.EVENT_PROMPT,function(l){return p(r,void 0,void 0,function(){return g(this,function(a){return o=!0,[2,i.close().then(function(){return c(l)}).catch(function(){return o=!1})]})})}),i.ondestroy=function(){o||c(null)}})]}})})}function j(t){return _.store[t]||void 0}const V=["onPointerdown"],k={__name:"WidgetModalContainerItem",props:{id:Number},setup(t){const e=s.ref(null),i=I(t.id);function o(){if(i.backgroundClose)return w(i.id,{background:!0}).catch(()=>{})}return s.watch(()=>e.value,r=>{i.instance=r}),(r,u)=>(s.openBlock(),s.createElementBlock("div",{class:"widget__modal-container__item modal-container",onPointerdown:s.withModifiers(o,["self","stop"])},[(s.openBlock(),s.createBlock(s.resolveDynamicComponent(s.unref(i).component),s.mergeProps(s.unref(i).props.value,{class:"modal-item widget__modal-wrap",modalId:`_modal_${t.id}`,ref_key:"modalRef",ref:e},s.toHandlers(s.unref(i).events)),null,16,["modalId"]))],40,V))}};function W(t){t===void 0&&(t=m.DEFAULT_NAMESPACE);var e=m.instance.getByName(t);e.initialized=!0,t===m.DEFAULT_NAMESPACE&&document.addEventListener("keyup",function(n){if(_.escClose&&(n.key==="Escape"||n.code==="Escape")){var i=C(t);if(!i)return;w(i.id,{esc:!0}).catch(function(){})}})}const $={props:{namespace:String},setup(t){return s.onMounted(()=>{W(t.namespace)}),()=>{const e=v(t.namespace);return s.h(s.TransitionGroup,{name:_.animation},{default:()=>e.queue.map(n=>s.h(k,{key:n.id,id:n.id}))})}},components:{WidgetContainerModalItem:k}};var y={router:null};function H(t){var e=this;if(y.router)throw f.DuplicatedRouterIntegration();y.router=t;function n(i){for(var o=i.matched.length-1;o>=0;o--){var r=i.matched[o].components,u=Object.values(r).find(function(c){return c._isModal});if(u)return u}return null}t.beforeEach(function(i,o){return p(e,void 0,void 0,function(){var r,u,c;return g(this,function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),r=n(o),r&&!(!((c=(u=r.getModalObject())===null||u===void 0?void 0:u.closed)===null||c===void 0)&&c.value)?[4,r.close(!0)]:[3,2];case 1:l.sent(),l.label=2;case 2:return[3,4];case 3:return l.sent(),[2,!1];case 4:return[2]}})})}),t.afterEach(function(i){return p(e,void 0,void 0,function(){var o;return g(this,function(r){switch(r.label){case 0:return o=n(i),o?[4,o.initialize()]:[3,2];case 1:r.sent(),r.label=2;case 2:return[2]}})})})}function B(t){var e=null,n=!1;function i(){return p(this,void 0,void 0,function(){return g(this,function(o){switch(o.label){case 0:if(!y.router)throw f.ModalRouterIntegrationNotInitialized();return n=!1,e=null,[4,x(t,s.computed(function(){var r;return(r=y.router)===null||r===void 0?void 0:r.currentRoute.value.params}),{isRoute:!0})];case 1:return e=o.sent(),e.onclose=function(){var r;n||(r=y.router)===null||r===void 0||r.back()},[2]}})})}return{getModalObject:function(){return e},_isModal:!0,close:function(o){return o===void 0&&(o=!1),p(this,void 0,void 0,function(){return g(this,function(r){switch(r.label){case 0:return n=o,e?[4,e.close()]:[3,2];case 1:return[2,r.sent()];case 2:return[2]}})})},initialize:i,setup:function(){return function(){return null}}}}B.init=H;var Y=v().queue;function J(t){return v(t).queue}exports.Modal=M;exports.closeById=w;exports.closeModal=A;exports.config=Q;exports.container=$;exports.getComponentFromStore=j;exports.getCurrentModal=C;exports.getQueueByNamespace=J;exports.modalQueue=Y;exports.onBeforeModalClose=U;exports.openModal=x;exports.popModal=z;exports.promptModal=L;exports.pushModal=P;exports.useModalRouter=B; | ||
//# sourceMappingURL=jenesius-vue-modal.cjs.js.map |
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".modal-container{position:fixed;left:0;top:0;height:100%;width:100%;display:flex;align-items:center;justify-content:center;background-color:#3e3e3e21;cursor:pointer}.modal-item{cursor:default}.modal-list-enter-active,.modal-list-leave-active,.modal-list-enter-active .modal-item,.modal-list-leave-active .modal-item{transition:all .2s ease}.modal-list-enter-from,.modal-list-leave-to{opacity:0!important}.modal-list-enter-from .modal-item,.modal-list-leave-to .modal-item{transform:translateY(-60px)}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})(); | ||
import { reactive as S, watch as N, ref as R, computed as T, markRaw as B, getCurrentInstance as z, openBlock as C, createElementBlock as F, withModifiers as G, createBlock as U, resolveDynamicComponent as L, unref as M, mergeProps as Q, toHandlers as V, onMounted as W, h as P, TransitionGroup as $ } from "vue"; | ||
import { reactive as N, watch as R, ref as T, computed as I, markRaw as z, getCurrentInstance as F, openBlock as C, createElementBlock as G, withModifiers as U, createBlock as L, resolveDynamicComponent as Q, unref as M, mergeProps as V, toHandlers as W, onMounted as $, h as P, TransitionGroup as H } from "vue"; | ||
/*! | ||
* jenesius-vue-modal v1.10.3 | ||
* (c) 2023 Jenesius | ||
* jenesius-vue-modal v1.11.0 | ||
* (c) 2024 Jenesius | ||
* @license MIT | ||
*/ | ||
var b = function(t, e) { | ||
return b = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, o) { | ||
n.__proto__ = o; | ||
} || function(n, o) { | ||
for (var i in o) | ||
Object.prototype.hasOwnProperty.call(o, i) && (n[i] = o[i]); | ||
return b = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, i) { | ||
n.__proto__ = i; | ||
} || function(n, i) { | ||
for (var o in i) | ||
Object.prototype.hasOwnProperty.call(i, o) && (n[o] = i[o]); | ||
}, b(t, e); | ||
}; | ||
function H(t, e) { | ||
function Y(t, e) { | ||
if (typeof e != "function" && e !== null) | ||
@@ -25,14 +25,14 @@ throw new TypeError("Class extends value " + String(e) + " is not a constructor or null"); | ||
} | ||
function h(t, e, n, o) { | ||
function i(r) { | ||
return r instanceof n ? r : new n(function(a) { | ||
a(r); | ||
function m(t, e, n, i) { | ||
function o(r) { | ||
return r instanceof n ? r : new n(function(u) { | ||
u(r); | ||
}); | ||
} | ||
return new (n || (n = Promise))(function(r, a) { | ||
return new (n || (n = Promise))(function(r, u) { | ||
function s(l) { | ||
try { | ||
u(o.next(l)); | ||
a(i.next(l)); | ||
} catch (w) { | ||
a(w); | ||
u(w); | ||
} | ||
@@ -42,14 +42,14 @@ } | ||
try { | ||
u(o.throw(l)); | ||
a(i.throw(l)); | ||
} catch (w) { | ||
a(w); | ||
u(w); | ||
} | ||
} | ||
function u(l) { | ||
l.done ? r(l.value) : i(l.value).then(s, c); | ||
function a(l) { | ||
l.done ? r(l.value) : o(l.value).then(s, c); | ||
} | ||
u((o = o.apply(t, e || [])).next()); | ||
a((i = i.apply(t, e || [])).next()); | ||
}); | ||
} | ||
function m(t, e) { | ||
function p(t, e) { | ||
var n = { label: 0, sent: function() { | ||
@@ -59,46 +59,46 @@ if (r[0] & 1) | ||
return r[1]; | ||
}, trys: [], ops: [] }, o, i, r, a; | ||
return a = { next: s(0), throw: s(1), return: s(2) }, typeof Symbol == "function" && (a[Symbol.iterator] = function() { | ||
}, trys: [], ops: [] }, i, o, r, u; | ||
return u = { next: s(0), throw: s(1), return: s(2) }, typeof Symbol == "function" && (u[Symbol.iterator] = function() { | ||
return this; | ||
}), a; | ||
function s(u) { | ||
}), u; | ||
function s(a) { | ||
return function(l) { | ||
return c([u, l]); | ||
return c([a, l]); | ||
}; | ||
} | ||
function c(u) { | ||
if (o) | ||
function c(a) { | ||
if (i) | ||
throw new TypeError("Generator is already executing."); | ||
for (; a && (a = 0, u[0] && (n = 0)), n; ) | ||
for (; u && (u = 0, a[0] && (n = 0)), n; ) | ||
try { | ||
if (o = 1, i && (r = u[0] & 2 ? i.return : u[0] ? i.throw || ((r = i.return) && r.call(i), 0) : i.next) && !(r = r.call(i, u[1])).done) | ||
if (i = 1, o && (r = a[0] & 2 ? o.return : a[0] ? o.throw || ((r = o.return) && r.call(o), 0) : o.next) && !(r = r.call(o, a[1])).done) | ||
return r; | ||
switch (i = 0, r && (u = [u[0] & 2, r.value]), u[0]) { | ||
switch (o = 0, r && (a = [a[0] & 2, r.value]), a[0]) { | ||
case 0: | ||
case 1: | ||
r = u; | ||
r = a; | ||
break; | ||
case 4: | ||
return n.label++, { value: u[1], done: !1 }; | ||
return n.label++, { value: a[1], done: !1 }; | ||
case 5: | ||
n.label++, i = u[1], u = [0]; | ||
n.label++, o = a[1], a = [0]; | ||
continue; | ||
case 7: | ||
u = n.ops.pop(), n.trys.pop(); | ||
a = n.ops.pop(), n.trys.pop(); | ||
continue; | ||
default: | ||
if (r = n.trys, !(r = r.length > 0 && r[r.length - 1]) && (u[0] === 6 || u[0] === 2)) { | ||
if (r = n.trys, !(r = r.length > 0 && r[r.length - 1]) && (a[0] === 6 || a[0] === 2)) { | ||
n = 0; | ||
continue; | ||
} | ||
if (u[0] === 3 && (!r || u[1] > r[0] && u[1] < r[3])) { | ||
n.label = u[1]; | ||
if (a[0] === 3 && (!r || a[1] > r[0] && a[1] < r[3])) { | ||
n.label = a[1]; | ||
break; | ||
} | ||
if (u[0] === 6 && n.label < r[1]) { | ||
n.label = r[1], r = u; | ||
if (a[0] === 6 && n.label < r[1]) { | ||
n.label = r[1], r = a; | ||
break; | ||
} | ||
if (r && n.label < r[2]) { | ||
n.label = r[2], n.ops.push(u); | ||
n.label = r[2], n.ops.push(a); | ||
break; | ||
@@ -109,11 +109,11 @@ } | ||
} | ||
u = e.call(t, n); | ||
a = e.call(t, n); | ||
} catch (l) { | ||
u = [6, l], i = 0; | ||
a = [6, l], o = 0; | ||
} finally { | ||
o = r = 0; | ||
i = r = 0; | ||
} | ||
if (u[0] & 5) | ||
throw u[1]; | ||
return { value: u[0] ? u[1] : void 0, done: !0 }; | ||
if (a[0] & 5) | ||
throw a[1]; | ||
return { value: a[0] ? a[1] : void 0, done: !0 }; | ||
} | ||
@@ -124,7 +124,7 @@ } | ||
function(t) { | ||
H(e, t); | ||
function e(n, o) { | ||
o === void 0 && (o = null); | ||
var i = t.call(this) || this; | ||
return i.isModalError = !0, i.message = n, i.details = o, i; | ||
Y(e, t); | ||
function e(n, i) { | ||
i === void 0 && (i = null); | ||
var o = t.call(this) || this; | ||
return o.isModalError = !0, o.message = n, o.details = i, o; | ||
} | ||
@@ -141,4 +141,4 @@ return e.Undefined = function(n) { | ||
return new e("Configuration type must be an Object. Provided", n); | ||
}, e.ConfigurationUndefinedParam = function(n, o) { | ||
return new e("In configuration founded unknown parameter: ".concat(n, ". Available are ").concat(o.join(", "), " ")); | ||
}, e.ConfigurationUndefinedParam = function(n, i) { | ||
return new e("In configuration founded unknown parameter: ".concat(n, ". Available are ").concat(i.join(", "), " ")); | ||
}, e.QueueNoEmpty = function() { | ||
@@ -164,3 +164,3 @@ return new e("Modal's queue is not empty. Probably some modal reject closing by onClose hook."); | ||
}(Error) | ||
), v = ( | ||
), h = ( | ||
/** @class */ | ||
@@ -173,3 +173,3 @@ function() { | ||
return e === void 0 && (e = t.DEFAULT_NAMESPACE), this.state.has(e) || this.state.set(e, { | ||
queue: S([]), | ||
queue: N([]), | ||
initialized: !1 | ||
@@ -183,4 +183,4 @@ }), this.state.get(e); | ||
}() | ||
), I = function() { | ||
var t = new v(), e = { | ||
), O = function() { | ||
var t = new h(), e = { | ||
scrollLock: !0, | ||
@@ -193,3 +193,3 @@ animation: "modal-list", | ||
}, n = t.getByName().queue; | ||
return N(function() { | ||
return R(function() { | ||
return n; | ||
@@ -204,14 +204,14 @@ }, function() { | ||
function f(t) { | ||
return I.namespaceStore.getByName(t); | ||
return O.namespaceStore.getByName(t); | ||
} | ||
var p = I.configuration; | ||
function O(t) { | ||
var _ = O.configuration; | ||
function A(t) { | ||
var e = { | ||
backgroundClose: p.backgroundClose, | ||
backgroundClose: _.backgroundClose, | ||
isRoute: !1, | ||
namespace: v.DEFAULT_NAMESPACE | ||
namespace: h.DEFAULT_NAMESPACE | ||
}; | ||
return t.backgroundClose !== void 0 && (e.backgroundClose = t.backgroundClose), t.isRoute && (e.isRoute = t.isRoute), t.namespace && (e.namespace = t.namespace), e; | ||
} | ||
function Y(t) { | ||
function k(t) { | ||
t === void 0 && (t = {}); | ||
@@ -224,3 +224,3 @@ var e = { | ||
} | ||
function A(t) { | ||
function x(t) { | ||
return t || (t = {}), t; | ||
@@ -233,12 +233,18 @@ } | ||
return Promise.reject(d.ModalNotFoundByID(t)); | ||
var o = f(n.namespace), i = o.queue.findIndex(function(a) { | ||
return a.id === t; | ||
var i = f(n.namespace), o = i.queue.findIndex(function(u) { | ||
return u.id === t; | ||
}); | ||
if (i === -1) | ||
if (o === -1) | ||
return Promise.reject(d.Undefined(t)); | ||
var r = g.get(t, "close").map(function(a) { | ||
return K(a, t, Y(e)); | ||
var r = v.get(t, "close").map(function(u) { | ||
return K(u, t, k(e)); | ||
}); | ||
return j(r).then(function() { | ||
o.queue.splice(i, 1), g.delete(t); | ||
return D(r).then(function() { | ||
i.queue.splice(o, 1); | ||
}).then(function() { | ||
v.get(t, "destroy").forEach(function(u) { | ||
return u(k(e)); | ||
}); | ||
}).then(function() { | ||
v.delete(t); | ||
}); | ||
@@ -249,8 +255,8 @@ } | ||
function() { | ||
function t(e, n, o) { | ||
var i = this; | ||
this.events = S({}), this.backgroundClose = !0, this.isRoute = !1, this.id = t.modalId++, this.component = e, this.props = R(n), this.closed = T(function() { | ||
return !f(o.namespace).queue.includes(i); | ||
}), e.beforeModalClose && g.add(this.id, "close", e.beforeModalClose); | ||
var r = O(o); | ||
function t(e, n, i) { | ||
var o = this; | ||
this.events = N({}), this.backgroundClose = !0, this.isRoute = !1, this.id = t.modalId++, this.component = e, this.props = T(n), this.closed = I(function() { | ||
return !f(i.namespace).queue.includes(o); | ||
}), e.beforeModalClose && v.add(this.id, "close", e.beforeModalClose); | ||
var r = A(i); | ||
this.backgroundClose = r.backgroundClose, this.isRoute = r.isRoute, this.namespace = r.namespace, t.STORE.set(this.id, this); | ||
@@ -265,11 +271,20 @@ } | ||
set: function(e) { | ||
g.add(this.id, "close", e); | ||
v.add(this.id, "close", e); | ||
}, | ||
enumerable: !1, | ||
configurable: !0 | ||
}), Object.defineProperty(t.prototype, "ondestroy", { | ||
/** | ||
* @description Hook for handling modal closing | ||
* */ | ||
set: function(e) { | ||
v.add(this.id, "destroy", e); | ||
}, | ||
enumerable: !1, | ||
configurable: !0 | ||
}), t.prototype.on = function(e, n) { | ||
var o = this; | ||
var i = this; | ||
return Array.isArray(this.events[e]) || (this.events[e] = []), this.events[e].push(n), function() { | ||
var i = o.events[e].indexOf(n); | ||
i !== -1 && o.events[e].splice(i, 1); | ||
var o = i.events[e].indexOf(n); | ||
o !== -1 && i.events[e].splice(o, 1); | ||
}; | ||
@@ -279,3 +294,3 @@ }, t.STORE = /* @__PURE__ */ new Map(), t.modalId = 0, t.EVENT_PROMPT = "jenesius-vue-modal:____P____R____O____M____P____T", t; | ||
); | ||
function x(t) { | ||
function j(t) { | ||
return y.STORE.get(t); | ||
@@ -286,9 +301,9 @@ } | ||
add: function(t, e, n) { | ||
var o; | ||
var i, o; | ||
if (typeof n != "function") | ||
throw d.GuardDeclarationType(n); | ||
this.store[t] || (this.store[t] = (o = {}, o[e] = [], o)), this.store[t][e] || (this.store[t][e] = []), this.store[t][e].push(n); | ||
this.store[t] || (this.store[t] = (i = {}, i[e] = [], i)), this.store[t][e] || (this.store[t][e] = []), (o = this.store[t][e]) === null || o === void 0 || o.push(n); | ||
}, | ||
get: function(t, e) { | ||
return t in this.store ? e in this.store[t] ? this.store[t][e] : [] : []; | ||
return t in this.store ? e in this.store[t] ? this.store[t][e] || [] : [] : []; | ||
}, | ||
@@ -299,4 +314,4 @@ delete: function(t) { | ||
}; | ||
const g = J; | ||
function j(t) { | ||
const v = J; | ||
function D(t) { | ||
return t.reduce(function(e, n) { | ||
@@ -310,8 +325,8 @@ return e.then(function() { | ||
return function() { | ||
return new Promise(function(o, i) { | ||
var r, a = function(s) { | ||
s === void 0 && (s = !0), s === !1 && i(d.NextReject(e)), o(); | ||
return new Promise(function(i, o) { | ||
var r, u = function(s) { | ||
s === void 0 && (s = !0), s === !1 && o(d.NextReject(e)), i(); | ||
}; | ||
Promise.resolve(t.call((r = x(e)) === null || r === void 0 ? void 0 : r.instance, n)).then(a).catch(function(s) { | ||
return i(s); | ||
Promise.resolve(t.call((r = j(e)) === null || r === void 0 ? void 0 : r.instance, n)).then(u).catch(function(s) { | ||
return o(s); | ||
}); | ||
@@ -322,3 +337,3 @@ }); | ||
function X(t) { | ||
return t = A(t), j(f(t.namespace).queue.map(function(e) { | ||
return t = x(t), D(f(t.namespace).queue.map(function(e) { | ||
return function() { | ||
@@ -329,3 +344,3 @@ return e.close(); | ||
} | ||
function D(t) { | ||
function q(t) { | ||
var e = f(t), n = e.queue; | ||
@@ -336,10 +351,10 @@ if (n.length !== 0) | ||
function ae(t) { | ||
t = A(t); | ||
var e = D(t.namespace); | ||
t = x(t); | ||
var e = q(t.namespace); | ||
return e ? e.close() : Promise.resolve(); | ||
} | ||
function Z(t, e, n) { | ||
var o = O(n), i = f(o.namespace); | ||
if (o.namespace === v.DEFAULT_NAMESPACE && !i.initialized && !p.skipInitCheck) | ||
throw d.NotInitialized(o.namespace); | ||
var i = A(n), o = f(i.namespace); | ||
if (i.namespace === h.DEFAULT_NAMESPACE && !o.initialized && !_.skipInitCheck) | ||
throw d.NotInitialized(i.namespace); | ||
if (typeof t == "string") { | ||
@@ -353,6 +368,6 @@ var r = te(t); | ||
throw d.ModalComponentNotProvided(); | ||
var a = new y(t, e, o); | ||
return i.queue.push(B(a)), a; | ||
var u = new y(t, e, i); | ||
return o.queue.push(z(u)), u; | ||
} | ||
function q(t, e, n) { | ||
function B(t, e, n) { | ||
return e === void 0 && (e = {}), n === void 0 && (n = {}), Promise.resolve().then(function() { | ||
@@ -366,7 +381,7 @@ return Z(t, e, n); | ||
}).then(function() { | ||
var o = f(n.namespace); | ||
if (o.queue.length) | ||
var i = f(n.namespace); | ||
if (i.queue.length) | ||
throw d.QueueNoEmpty(); | ||
}).then(function() { | ||
return q(t, e, n); | ||
return B(t, e, n); | ||
}); | ||
@@ -377,32 +392,30 @@ } | ||
throw d.ConfigurationType(t); | ||
Object.assign(p, t); | ||
Object.assign(_, t); | ||
} | ||
function ce(t) { | ||
var e, n, o, i = z(), r = String(((e = i == null ? void 0 : i.props) === null || e === void 0 ? void 0 : e.modalId) || ((n = i == null ? void 0 : i.props) === null || n === void 0 ? void 0 : n["modal-id"]) || ((o = i == null ? void 0 : i.attrs) === null || o === void 0 ? void 0 : o.modalId)), a = r.replace(/[^0-9]/g, ""); | ||
g.add(Number(a), "close", t); | ||
var e, n, i, o = F(), r = String(((e = o == null ? void 0 : o.props) === null || e === void 0 ? void 0 : e.modalId) || ((n = o == null ? void 0 : o.props) === null || n === void 0 ? void 0 : n["modal-id"]) || ((i = o == null ? void 0 : o.attrs) === null || i === void 0 ? void 0 : i.modalId)), u = r.replace(/[^0-9]/g, ""); | ||
v.add(Number(u), "close", t); | ||
} | ||
function le(t, e, n) { | ||
return e === void 0 && (e = {}), n === void 0 && (n = {}), h(this, void 0, void 0, function() { | ||
var o, i = this; | ||
return m(this, function(r) { | ||
switch (r.label) { | ||
return e === void 0 && (e = {}), n === void 0 && (n = {}), m(this, void 0, void 0, function() { | ||
var i, o, r = this; | ||
return p(this, function(u) { | ||
switch (u.label) { | ||
case 0: | ||
return [4, q(t, e, n)]; | ||
return [4, B(t, e, n)]; | ||
case 1: | ||
return o = r.sent(), [2, new Promise(function(a) { | ||
o.on(y.EVENT_PROMPT, function(s) { | ||
return h(i, void 0, void 0, function() { | ||
return m(this, function(c) { | ||
switch (c.label) { | ||
case 0: | ||
return [4, o.close()]; | ||
case 1: | ||
return c.sent(), a(s), [ | ||
2 | ||
/*return*/ | ||
]; | ||
} | ||
return i = u.sent(), o = !1, [2, new Promise(function(s) { | ||
i.on(y.EVENT_PROMPT, function(c) { | ||
return m(r, void 0, void 0, function() { | ||
return p(this, function(a) { | ||
return o = !0, [2, i.close().then(function() { | ||
return s(c); | ||
}).catch(function() { | ||
return o = !1; | ||
})]; | ||
}); | ||
}); | ||
}); | ||
}), i.ondestroy = function() { | ||
o || s(null); | ||
}; | ||
})]; | ||
@@ -414,5 +427,5 @@ } | ||
function te(t) { | ||
return p.store[t] || void 0; | ||
return _.store[t] || void 0; | ||
} | ||
const ne = ["onPointerdown"], k = { | ||
const ne = ["onPointerdown"], S = { | ||
__name: "WidgetModalContainerItem", | ||
@@ -423,15 +436,15 @@ props: { | ||
setup(t) { | ||
const e = R(null), o = x(t.id); | ||
function i() { | ||
if (o.backgroundClose) | ||
return E(o.id, { background: !0 }).catch(() => { | ||
const e = T(null), i = j(t.id); | ||
function o() { | ||
if (i.backgroundClose) | ||
return E(i.id, { background: !0 }).catch(() => { | ||
}); | ||
} | ||
return N(() => e.value, (r) => { | ||
o.instance = r; | ||
}), (r, a) => (C(), F("div", { | ||
return R(() => e.value, (r) => { | ||
i.instance = r; | ||
}), (r, u) => (C(), G("div", { | ||
class: "widget__modal-container__item modal-container", | ||
onPointerdown: G(i, ["self", "stop"]) | ||
onPointerdown: U(o, ["self", "stop"]) | ||
}, [ | ||
(C(), U(L(M(o).component), Q(M(o).props.value, { | ||
(C(), L(Q(M(i).component), V(M(i).props.value, { | ||
class: "modal-item widget__modal-wrap", | ||
@@ -441,3 +454,3 @@ modalId: `_modal_${t.id}`, | ||
ref: e | ||
}, V(M(o).events)), null, 16, ["modalId"])) | ||
}, W(M(i).events)), null, 16, ["modalId"])) | ||
], 40, ne)); | ||
@@ -447,10 +460,10 @@ } | ||
function re(t) { | ||
t === void 0 && (t = v.DEFAULT_NAMESPACE); | ||
var e = v.instance.getByName(t); | ||
e.initialized = !0, t === v.DEFAULT_NAMESPACE && document.addEventListener("keyup", function(n) { | ||
if (p.escClose && (n.key === "Escape" || n.code === "Escape")) { | ||
var o = D(t); | ||
if (!o) | ||
t === void 0 && (t = h.DEFAULT_NAMESPACE); | ||
var e = h.instance.getByName(t); | ||
e.initialized = !0, t === h.DEFAULT_NAMESPACE && document.addEventListener("keyup", function(n) { | ||
if (_.escClose && (n.key === "Escape" || n.code === "Escape")) { | ||
var i = q(t); | ||
if (!i) | ||
return; | ||
E(o.id, { esc: !0 }).catch(function() { | ||
E(i.id, { esc: !0 }).catch(function() { | ||
}); | ||
@@ -465,8 +478,8 @@ } | ||
setup(t) { | ||
return W(() => { | ||
return $(() => { | ||
re(t.namespace); | ||
}), () => { | ||
const e = f(t.namespace); | ||
return P($, { name: p.animation }, { | ||
default: () => e.queue.map((n) => P(k, { | ||
return P(H, { name: _.animation }, { | ||
default: () => e.queue.map((n) => P(S, { | ||
key: n.id, | ||
@@ -478,5 +491,5 @@ id: n.id | ||
}, | ||
components: { WidgetContainerModalItem: k } | ||
components: { WidgetContainerModalItem: S } | ||
}; | ||
var _ = { | ||
var g = { | ||
router: null | ||
@@ -486,22 +499,22 @@ }; | ||
var e = this; | ||
if (_.router) | ||
if (g.router) | ||
throw d.DuplicatedRouterIntegration(); | ||
_.router = t; | ||
function n(o) { | ||
for (var i = o.matched.length - 1; i >= 0; i--) { | ||
var r = o.matched[i].components, a = Object.values(r).find(function(s) { | ||
g.router = t; | ||
function n(i) { | ||
for (var o = i.matched.length - 1; o >= 0; o--) { | ||
var r = i.matched[o].components, u = Object.values(r).find(function(s) { | ||
return s._isModal; | ||
}); | ||
if (a) | ||
return a; | ||
if (u) | ||
return u; | ||
} | ||
return null; | ||
} | ||
t.beforeEach(function(o, i) { | ||
return h(e, void 0, void 0, function() { | ||
var r, a, s; | ||
return m(this, function(c) { | ||
t.beforeEach(function(i, o) { | ||
return m(e, void 0, void 0, function() { | ||
var r, u, s; | ||
return p(this, function(c) { | ||
switch (c.label) { | ||
case 0: | ||
return c.trys.push([0, 3, , 4]), r = n(i), r && !(!((s = (a = r.getModalObject()) === null || a === void 0 ? void 0 : a.closed) === null || s === void 0) && s.value) ? [4, r.close(!0)] : [3, 2]; | ||
return c.trys.push([0, 3, , 4]), r = n(o), r && !(!((s = (u = r.getModalObject()) === null || u === void 0 ? void 0 : u.closed) === null || s === void 0) && s.value) ? [4, r.close(!0)] : [3, 2]; | ||
case 1: | ||
@@ -521,9 +534,9 @@ c.sent(), c.label = 2; | ||
}); | ||
}), t.afterEach(function(o) { | ||
return h(e, void 0, void 0, function() { | ||
var i; | ||
return m(this, function(r) { | ||
}), t.afterEach(function(i) { | ||
return m(e, void 0, void 0, function() { | ||
var o; | ||
return p(this, function(r) { | ||
switch (r.label) { | ||
case 0: | ||
return i = n(o), i ? [4, i.initialize()] : [3, 2]; | ||
return o = n(i), o ? [4, o.initialize()] : [3, 2]; | ||
case 1: | ||
@@ -543,17 +556,17 @@ r.sent(), r.label = 2; | ||
var e = null, n = !1; | ||
function o() { | ||
return h(this, void 0, void 0, function() { | ||
return m(this, function(i) { | ||
switch (i.label) { | ||
function i() { | ||
return m(this, void 0, void 0, function() { | ||
return p(this, function(o) { | ||
switch (o.label) { | ||
case 0: | ||
if (!_.router) | ||
if (!g.router) | ||
throw d.ModalRouterIntegrationNotInitialized(); | ||
return n = !1, e = null, [4, ee(t, T(function() { | ||
return n = !1, e = null, [4, ee(t, I(function() { | ||
var r; | ||
return (r = _.router) === null || r === void 0 ? void 0 : r.currentRoute.value.params; | ||
return (r = g.router) === null || r === void 0 ? void 0 : r.currentRoute.value.params; | ||
}), { isRoute: !0 })]; | ||
case 1: | ||
return e = i.sent(), e.onclose = function() { | ||
return e = o.sent(), e.onclose = function() { | ||
var r; | ||
n || (r = _.router) === null || r === void 0 || r.back(); | ||
n || (r = g.router) === null || r === void 0 || r.back(); | ||
}, [ | ||
@@ -576,8 +589,8 @@ 2 | ||
_isModal: !0, | ||
close: function(i) { | ||
return i === void 0 && (i = !1), h(this, void 0, void 0, function() { | ||
return m(this, function(r) { | ||
close: function(o) { | ||
return o === void 0 && (o = !1), m(this, void 0, void 0, function() { | ||
return p(this, function(r) { | ||
switch (r.label) { | ||
case 0: | ||
return n = i, e ? [4, e.close()] : [3, 2]; | ||
return n = o, e ? [4, e.close()] : [3, 2]; | ||
case 1: | ||
@@ -594,3 +607,3 @@ return [2, r.sent()]; | ||
}, | ||
initialize: o, | ||
initialize: i, | ||
/** | ||
@@ -622,3 +635,3 @@ * Мнимая обёртка. Для того, чтобы рендеринг запускался. | ||
te as getComponentFromStore, | ||
D as getCurrentModal, | ||
q as getCurrentModal, | ||
ve as getQueueByNamespace, | ||
@@ -630,5 +643,5 @@ fe as modalQueue, | ||
le as promptModal, | ||
q as pushModal, | ||
B as pushModal, | ||
ie as useModalRouter | ||
}; | ||
//# sourceMappingURL=jenesius-vue-modal.es.js.map |
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".modal-container{position:fixed;left:0;top:0;height:100%;width:100%;display:flex;align-items:center;justify-content:center;background-color:#3e3e3e21;cursor:pointer}.modal-item{cursor:default}.modal-list-enter-active,.modal-list-leave-active,.modal-list-enter-active .modal-item,.modal-list-leave-active .modal-item{transition:all .2s ease}.modal-list-enter-from,.modal-list-leave-to{opacity:0!important}.modal-list-enter-from .modal-item,.modal-list-leave-to .modal-item{transform:translateY(-60px)}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})(); | ||
(function(c,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],s):(c=typeof globalThis<"u"?globalThis:c||self,s(c.JenesiusVueModal={},c.Vue))})(this,function(c,s){"use strict";/*! | ||
* jenesius-vue-modal v1.10.3 | ||
* (c) 2023 Jenesius | ||
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.JenesiusVueModal={},s.Vue))})(this,function(s,c){"use strict";/*! | ||
* jenesius-vue-modal v1.11.0 | ||
* (c) 2024 Jenesius | ||
* @license MIT | ||
*/var E=function(t,e){return E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(n[i]=o[i])},E(t,e)};function D(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");E(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function v(t,e,n,o){function i(r){return r instanceof n?r:new n(function(u){u(r)})}return new(n||(n=Promise))(function(r,u){function l(h){try{a(o.next(h))}catch(P){u(P)}}function d(h){try{a(o.throw(h))}catch(P){u(P)}}function a(h){h.done?r(h.value):i(h.value).then(l,d)}a((o=o.apply(t,e||[])).next())})}function p(t,e){var n={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},o,i,r,u;return u={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function l(a){return function(h){return d([a,h])}}function d(a){if(o)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(n=0)),n;)try{if(o=1,i&&(r=a[0]&2?i.return:a[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,a[1])).done)return r;switch(i=0,r&&(a=[a[0]&2,r.value]),a[0]){case 0:case 1:r=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,i=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(r=n.trys,!(r=r.length>0&&r[r.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]<r[3])){n.label=a[1];break}if(a[0]===6&&n.label<r[1]){n.label=r[1],r=a;break}if(r&&n.label<r[2]){n.label=r[2],n.ops.push(a);break}r[2]&&n.ops.pop(),n.trys.pop();continue}a=e.call(t,n)}catch(h){a=[6,h],i=0}finally{o=r=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}typeof SuppressedError=="function"&&SuppressedError;var f=function(t){D(e,t);function e(n,o){o===void 0&&(o=null);var i=t.call(this)||this;return i.isModalError=!0,i.message=n,i.details=o,i}return e.Undefined=function(n){return new e("Modal with id: ".concat(n," not founded. The modal window may have been closed earlier."))},e.UndefinedGuardName=function(n){return new e("Guard's name ".concat(n," is not declaration."))},e.NextReject=function(n){return new e("Guard returned false. Modal navigation was stopped. Modal id ".concat(n))},e.GuardDeclarationType=function(n){return new e("Guard's type should be a function. Provided:",n)},e.ConfigurationType=function(n){return new e("Configuration type must be an Object. Provided",n)},e.ConfigurationUndefinedParam=function(n,o){return new e("In configuration founded unknown parameter: ".concat(n,". Available are ").concat(o.join(", ")," "))},e.QueueNoEmpty=function(){return new e("Modal's queue is not empty. Probably some modal reject closing by onClose hook.")},e.EmptyModalQueue=function(){return new e("Modal queue is empty.")},e.NotInitialized=function(n){return new e("Modal Container not found. Put container from jenesius-vue-modal in App's template. Namespace: ".concat(n,". Check documentation for more information https://modal.jenesius.com/docs.html/installation#getting-started."))},e.ModalComponentNotProvided=function(){return new e("The first parameter(VueComponent) was not specified.")},e.DuplicatedRouterIntegration=function(){return new e("useModalRouter.init should escaped only once.")},e.ModalRouterIntegrationNotInitialized=function(){return new e("The integration was not initialized. Please, use useModalRouter.init(router). For more information: https://modal.jenesius.com/docs.html/integration-vue-router#installation")},e.ModalEventNameMustBeString=function(n){return new e("Event name must be a string. Provided: ".concat(n))},e.ModalNotFoundByID=function(n){return new e("Modal with ID ".concat(n," was not found."))},e.ModalNotExistsInStore=function(n){return new e("Provided name(".concat(n,") don't exist in the store. Has the given name been added to the store?"))},e}(Error),g=function(){function t(){this.state=new Map,t.instance=this}return t.prototype.getByName=function(e){return e===void 0&&(e=t.DEFAULT_NAMESPACE),this.state.has(e)||this.state.set(e,{queue:s.reactive([]),initialized:!1}),this.state.get(e)},t.prototype.forceClean=function(){this.state.forEach(function(e){e.queue.splice(0,e.queue.length)})},t.DEFAULT_NAMESPACE="default",t}(),k=function(){var t=new g,e={scrollLock:!0,animation:"modal-list",backgroundClose:!0,escClose:!0,store:{},skipInitCheck:!1},n=t.getByName().queue;return s.watch(function(){return n},function(){e.scrollLock&&(n.length?document.body.style.overflowY="hidden":document.body.style.overflowY="auto")},{deep:!0}),{namespaceStore:t,configuration:e}}();function m(t){return k.namespaceStore.getByName(t)}var _=k.configuration;function N(t){var e={backgroundClose:_.backgroundClose,isRoute:!1,namespace:g.DEFAULT_NAMESPACE};return t.backgroundClose!==void 0&&(e.backgroundClose=t.backgroundClose),t.isRoute&&(e.isRoute=t.isRoute),t.namespace&&(e.namespace=t.namespace),e}function F(t){t===void 0&&(t={});var e={background:!1,esc:!1};return Object.assign(e,t)}function T(t){return t||(t={}),t}function b(t,e){e===void 0&&(e={});var n=y.STORE.get(t);if(!n)return Promise.reject(f.ModalNotFoundByID(t));var o=m(n.namespace),i=o.queue.findIndex(function(u){return u.id===t});if(i===-1)return Promise.reject(f.Undefined(t));var r=M.get(t,"close").map(function(u){return G(u,t,F(e))});return I(r).then(function(){o.queue.splice(i,1),M.delete(t)})}var y=function(){function t(e,n,o){var i=this;this.events=s.reactive({}),this.backgroundClose=!0,this.isRoute=!1,this.id=t.modalId++,this.component=e,this.props=s.ref(n),this.closed=s.computed(function(){return!m(o.namespace).queue.includes(i)}),e.beforeModalClose&&M.add(this.id,"close",e.beforeModalClose);var r=N(o);this.backgroundClose=r.backgroundClose,this.isRoute=r.isRoute,this.namespace=r.namespace,t.STORE.set(this.id,this)}return t.prototype.close=function(){return b(this.id)},Object.defineProperty(t.prototype,"onclose",{set:function(e){M.add(this.id,"close",e)},enumerable:!1,configurable:!0}),t.prototype.on=function(e,n){var o=this;return Array.isArray(this.events[e])||(this.events[e]=[]),this.events[e].push(n),function(){var i=o.events[e].indexOf(n);i!==-1&&o.events[e].splice(i,1)}},t.STORE=new Map,t.modalId=0,t.EVENT_PROMPT="jenesius-vue-modal:____P____R____O____M____P____T",t}();function R(t){return y.STORE.get(t)}var z={store:{},add:function(t,e,n){var o;if(typeof n!="function")throw f.GuardDeclarationType(n);this.store[t]||(this.store[t]=(o={},o[e]=[],o)),this.store[t][e]||(this.store[t][e]=[]),this.store[t][e].push(n)},get:function(t,e){return t in this.store?e in this.store[t]?this.store[t][e]:[]:[]},delete:function(t){t in this.store&&delete this.store[t]}};const M=z;function I(t){return t.reduce(function(e,n){return e.then(function(){return n()})},Promise.resolve())}function G(t,e,n){return function(){return new Promise(function(o,i){var r,u=function(l){l===void 0&&(l=!0),l===!1&&i(f.NextReject(e)),o()};Promise.resolve(t.call((r=R(e))===null||r===void 0?void 0:r.instance,n)).then(u).catch(function(l){return i(l)})})}}function O(t){return t=T(t),I(m(t.namespace).queue.map(function(e){return function(){return e.close()}}))}function C(t){var e=m(t),n=e.queue;if(n.length!==0)return n[n.length-1]}function Q(t){t=T(t);var e=C(t.namespace);return e?e.close():Promise.resolve()}function U(t,e,n){var o=N(n),i=m(o.namespace);if(o.namespace===g.DEFAULT_NAMESPACE&&!i.initialized&&!_.skipInitCheck)throw f.NotInitialized(o.namespace);if(typeof t=="string"){var r=j(t);if(!r)throw f.ModalNotExistsInStore(t);t=r}if(!t)throw f.ModalComponentNotProvided();var u=new y(t,e,o);return i.queue.push(s.markRaw(u)),u}function S(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),Promise.resolve().then(function(){return U(t,e,n)})}function A(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),O({namespace:n.namespace}).then(function(){var o=m(n.namespace);if(o.queue.length)throw f.QueueNoEmpty()}).then(function(){return S(t,e,n)})}function x(t){if(typeof t!="object")throw f.ConfigurationType(t);Object.assign(_,t)}function L(t){var e,n,o,i=s.getCurrentInstance(),r=String(((e=i==null?void 0:i.props)===null||e===void 0?void 0:e.modalId)||((n=i==null?void 0:i.props)===null||n===void 0?void 0:n["modal-id"])||((o=i==null?void 0:i.attrs)===null||o===void 0?void 0:o.modalId)),u=r.replace(/[^0-9]/g,"");M.add(Number(u),"close",t)}function V(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),v(this,void 0,void 0,function(){var o,i=this;return p(this,function(r){switch(r.label){case 0:return[4,S(t,e,n)];case 1:return o=r.sent(),[2,new Promise(function(u){o.on(y.EVENT_PROMPT,function(l){return v(i,void 0,void 0,function(){return p(this,function(d){switch(d.label){case 0:return[4,o.close()];case 1:return d.sent(),u(l),[2]}})})})})]}})})}function j(t){return _.store[t]||void 0}const X="",W=["onPointerdown"],B={__name:"WidgetModalContainerItem",props:{id:Number},setup(t){const e=s.ref(null),o=R(t.id);function i(){if(o.backgroundClose)return b(o.id,{background:!0}).catch(()=>{})}return s.watch(()=>e.value,r=>{o.instance=r}),(r,u)=>(s.openBlock(),s.createElementBlock("div",{class:"widget__modal-container__item modal-container",onPointerdown:s.withModifiers(i,["self","stop"])},[(s.openBlock(),s.createBlock(s.resolveDynamicComponent(s.unref(o).component),s.mergeProps(s.unref(o).props.value,{class:"modal-item widget__modal-wrap",modalId:`_modal_${t.id}`,ref_key:"modalRef",ref:e},s.toHandlers(s.unref(o).events)),null,16,["modalId"]))],40,W))}};function $(t){t===void 0&&(t=g.DEFAULT_NAMESPACE);var e=g.instance.getByName(t);e.initialized=!0,t===g.DEFAULT_NAMESPACE&&document.addEventListener("keyup",function(n){if(_.escClose&&(n.key==="Escape"||n.code==="Escape")){var o=C(t);if(!o)return;b(o.id,{esc:!0}).catch(function(){})}})}const Z="",H={props:{namespace:String},setup(t){return s.onMounted(()=>{$(t.namespace)}),()=>{const e=m(t.namespace);return s.h(s.TransitionGroup,{name:_.animation},{default:()=>e.queue.map(n=>s.h(B,{key:n.id,id:n.id}))})}},components:{WidgetContainerModalItem:B}};var w={router:null};function Y(t){var e=this;if(w.router)throw f.DuplicatedRouterIntegration();w.router=t;function n(o){for(var i=o.matched.length-1;i>=0;i--){var r=o.matched[i].components,u=Object.values(r).find(function(l){return l._isModal});if(u)return u}return null}t.beforeEach(function(o,i){return v(e,void 0,void 0,function(){var r,u,l;return p(this,function(d){switch(d.label){case 0:return d.trys.push([0,3,,4]),r=n(i),r&&!(!((l=(u=r.getModalObject())===null||u===void 0?void 0:u.closed)===null||l===void 0)&&l.value)?[4,r.close(!0)]:[3,2];case 1:d.sent(),d.label=2;case 2:return[3,4];case 3:return d.sent(),[2,!1];case 4:return[2]}})})}),t.afterEach(function(o){return v(e,void 0,void 0,function(){var i;return p(this,function(r){switch(r.label){case 0:return i=n(o),i?[4,i.initialize()]:[3,2];case 1:r.sent(),r.label=2;case 2:return[2]}})})})}function q(t){var e=null,n=!1;function o(){return v(this,void 0,void 0,function(){return p(this,function(i){switch(i.label){case 0:if(!w.router)throw f.ModalRouterIntegrationNotInitialized();return n=!1,e=null,[4,A(t,s.computed(function(){var r;return(r=w.router)===null||r===void 0?void 0:r.currentRoute.value.params}),{isRoute:!0})];case 1:return e=i.sent(),e.onclose=function(){var r;n||(r=w.router)===null||r===void 0||r.back()},[2]}})})}return{getModalObject:function(){return e},_isModal:!0,close:function(i){return i===void 0&&(i=!1),v(this,void 0,void 0,function(){return p(this,function(r){switch(r.label){case 0:return n=i,e?[4,e.close()]:[3,2];case 1:return[2,r.sent()];case 2:return[2]}})})},initialize:o,setup:function(){return function(){return null}}}}q.init=Y;var J=m().queue;function K(t){return m(t).queue}c.Modal=y,c.closeById=b,c.closeModal=O,c.config=x,c.container=H,c.getComponentFromStore=j,c.getCurrentModal=C,c.getQueueByNamespace=K,c.modalQueue=J,c.onBeforeModalClose=L,c.openModal=A,c.popModal=Q,c.promptModal=V,c.pushModal=S,c.useModalRouter=q,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}); | ||
*/var E=function(t,e){return E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(n[i]=o[i])},E(t,e)};function F(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");E(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function p(t,e,n,o){function i(r){return r instanceof n?r:new n(function(a){a(r)})}return new(n||(n=Promise))(function(r,a){function l(h){try{u(o.next(h))}catch(S){a(S)}}function f(h){try{u(o.throw(h))}catch(S){a(S)}}function u(h){h.done?r(h.value):i(h.value).then(l,f)}u((o=o.apply(t,e||[])).next())})}function g(t,e){var n={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},o,i,r,a;return a={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function l(u){return function(h){return f([u,h])}}function f(u){if(o)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(n=0)),n;)try{if(o=1,i&&(r=u[0]&2?i.return:u[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,u[1])).done)return r;switch(i=0,r&&(u=[u[0]&2,r.value]),u[0]){case 0:case 1:r=u;break;case 4:return n.label++,{value:u[1],done:!1};case 5:n.label++,i=u[1],u=[0];continue;case 7:u=n.ops.pop(),n.trys.pop();continue;default:if(r=n.trys,!(r=r.length>0&&r[r.length-1])&&(u[0]===6||u[0]===2)){n=0;continue}if(u[0]===3&&(!r||u[1]>r[0]&&u[1]<r[3])){n.label=u[1];break}if(u[0]===6&&n.label<r[1]){n.label=r[1],r=u;break}if(r&&n.label<r[2]){n.label=r[2],n.ops.push(u);break}r[2]&&n.ops.pop(),n.trys.pop();continue}u=e.call(t,n)}catch(h){u=[6,h],i=0}finally{o=r=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}typeof SuppressedError=="function"&&SuppressedError;var d=function(t){F(e,t);function e(n,o){o===void 0&&(o=null);var i=t.call(this)||this;return i.isModalError=!0,i.message=n,i.details=o,i}return e.Undefined=function(n){return new e("Modal with id: ".concat(n," not founded. The modal window may have been closed earlier."))},e.UndefinedGuardName=function(n){return new e("Guard's name ".concat(n," is not declaration."))},e.NextReject=function(n){return new e("Guard returned false. Modal navigation was stopped. Modal id ".concat(n))},e.GuardDeclarationType=function(n){return new e("Guard's type should be a function. Provided:",n)},e.ConfigurationType=function(n){return new e("Configuration type must be an Object. Provided",n)},e.ConfigurationUndefinedParam=function(n,o){return new e("In configuration founded unknown parameter: ".concat(n,". Available are ").concat(o.join(", ")," "))},e.QueueNoEmpty=function(){return new e("Modal's queue is not empty. Probably some modal reject closing by onClose hook.")},e.EmptyModalQueue=function(){return new e("Modal queue is empty.")},e.NotInitialized=function(n){return new e("Modal Container not found. Put container from jenesius-vue-modal in App's template. Namespace: ".concat(n,". Check documentation for more information https://modal.jenesius.com/docs.html/installation#getting-started."))},e.ModalComponentNotProvided=function(){return new e("The first parameter(VueComponent) was not specified.")},e.DuplicatedRouterIntegration=function(){return new e("useModalRouter.init should escaped only once.")},e.ModalRouterIntegrationNotInitialized=function(){return new e("The integration was not initialized. Please, use useModalRouter.init(router). For more information: https://modal.jenesius.com/docs.html/integration-vue-router#installation")},e.ModalEventNameMustBeString=function(n){return new e("Event name must be a string. Provided: ".concat(n))},e.ModalNotFoundByID=function(n){return new e("Modal with ID ".concat(n," was not found."))},e.ModalNotExistsInStore=function(n){return new e("Provided name(".concat(n,") don't exist in the store. Has the given name been added to the store?"))},e}(Error),_=function(){function t(){this.state=new Map,t.instance=this}return t.prototype.getByName=function(e){return e===void 0&&(e=t.DEFAULT_NAMESPACE),this.state.has(e)||this.state.set(e,{queue:c.reactive([]),initialized:!1}),this.state.get(e)},t.prototype.forceClean=function(){this.state.forEach(function(e){e.queue.splice(0,e.queue.length)})},t.DEFAULT_NAMESPACE="default",t}(),k=function(){var t=new _,e={scrollLock:!0,animation:"modal-list",backgroundClose:!0,escClose:!0,store:{},skipInitCheck:!1},n=t.getByName().queue;return c.watch(function(){return n},function(){e.scrollLock&&(n.length?document.body.style.overflowY="hidden":document.body.style.overflowY="auto")},{deep:!0}),{namespaceStore:t,configuration:e}}();function m(t){return k.namespaceStore.getByName(t)}var y=k.configuration;function N(t){var e={backgroundClose:y.backgroundClose,isRoute:!1,namespace:_.DEFAULT_NAMESPACE};return t.backgroundClose!==void 0&&(e.backgroundClose=t.backgroundClose),t.isRoute&&(e.isRoute=t.isRoute),t.namespace&&(e.namespace=t.namespace),e}function T(t){t===void 0&&(t={});var e={background:!1,esc:!1};return Object.assign(e,t)}function R(t){return t||(t={}),t}function b(t,e){e===void 0&&(e={});var n=M.STORE.get(t);if(!n)return Promise.reject(d.ModalNotFoundByID(t));var o=m(n.namespace),i=o.queue.findIndex(function(a){return a.id===t});if(i===-1)return Promise.reject(d.Undefined(t));var r=v.get(t,"close").map(function(a){return G(a,t,T(e))});return O(r).then(function(){o.queue.splice(i,1)}).then(function(){v.get(t,"destroy").forEach(function(a){return a(T(e))})}).then(function(){v.delete(t)})}var M=function(){function t(e,n,o){var i=this;this.events=c.reactive({}),this.backgroundClose=!0,this.isRoute=!1,this.id=t.modalId++,this.component=e,this.props=c.ref(n),this.closed=c.computed(function(){return!m(o.namespace).queue.includes(i)}),e.beforeModalClose&&v.add(this.id,"close",e.beforeModalClose);var r=N(o);this.backgroundClose=r.backgroundClose,this.isRoute=r.isRoute,this.namespace=r.namespace,t.STORE.set(this.id,this)}return t.prototype.close=function(){return b(this.id)},Object.defineProperty(t.prototype,"onclose",{set:function(e){v.add(this.id,"close",e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ondestroy",{set:function(e){v.add(this.id,"destroy",e)},enumerable:!1,configurable:!0}),t.prototype.on=function(e,n){var o=this;return Array.isArray(this.events[e])||(this.events[e]=[]),this.events[e].push(n),function(){var i=o.events[e].indexOf(n);i!==-1&&o.events[e].splice(i,1)}},t.STORE=new Map,t.modalId=0,t.EVENT_PROMPT="jenesius-vue-modal:____P____R____O____M____P____T",t}();function I(t){return M.STORE.get(t)}var z={store:{},add:function(t,e,n){var o,i;if(typeof n!="function")throw d.GuardDeclarationType(n);this.store[t]||(this.store[t]=(o={},o[e]=[],o)),this.store[t][e]||(this.store[t][e]=[]),(i=this.store[t][e])===null||i===void 0||i.push(n)},get:function(t,e){return t in this.store?e in this.store[t]?this.store[t][e]||[]:[]:[]},delete:function(t){t in this.store&&delete this.store[t]}};const v=z;function O(t){return t.reduce(function(e,n){return e.then(function(){return n()})},Promise.resolve())}function G(t,e,n){return function(){return new Promise(function(o,i){var r,a=function(l){l===void 0&&(l=!0),l===!1&&i(d.NextReject(e)),o()};Promise.resolve(t.call((r=I(e))===null||r===void 0?void 0:r.instance,n)).then(a).catch(function(l){return i(l)})})}}function A(t){return t=R(t),O(m(t.namespace).queue.map(function(e){return function(){return e.close()}}))}function C(t){var e=m(t),n=e.queue;if(n.length!==0)return n[n.length-1]}function Q(t){t=R(t);var e=C(t.namespace);return e?e.close():Promise.resolve()}function U(t,e,n){var o=N(n),i=m(o.namespace);if(o.namespace===_.DEFAULT_NAMESPACE&&!i.initialized&&!y.skipInitCheck)throw d.NotInitialized(o.namespace);if(typeof t=="string"){var r=B(t);if(!r)throw d.ModalNotExistsInStore(t);t=r}if(!t)throw d.ModalComponentNotProvided();var a=new M(t,e,o);return i.queue.push(c.markRaw(a)),a}function P(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),Promise.resolve().then(function(){return U(t,e,n)})}function j(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),A({namespace:n.namespace}).then(function(){var o=m(n.namespace);if(o.queue.length)throw d.QueueNoEmpty()}).then(function(){return P(t,e,n)})}function x(t){if(typeof t!="object")throw d.ConfigurationType(t);Object.assign(y,t)}function L(t){var e,n,o,i=c.getCurrentInstance(),r=String(((e=i==null?void 0:i.props)===null||e===void 0?void 0:e.modalId)||((n=i==null?void 0:i.props)===null||n===void 0?void 0:n["modal-id"])||((o=i==null?void 0:i.attrs)===null||o===void 0?void 0:o.modalId)),a=r.replace(/[^0-9]/g,"");v.add(Number(a),"close",t)}function V(t,e,n){return e===void 0&&(e={}),n===void 0&&(n={}),p(this,void 0,void 0,function(){var o,i,r=this;return g(this,function(a){switch(a.label){case 0:return[4,P(t,e,n)];case 1:return o=a.sent(),i=!1,[2,new Promise(function(l){o.on(M.EVENT_PROMPT,function(f){return p(r,void 0,void 0,function(){return g(this,function(u){return i=!0,[2,o.close().then(function(){return l(f)}).catch(function(){return i=!1})]})})}),o.ondestroy=function(){i||l(null)}})]}})})}function B(t){return y.store[t]||void 0}const X="",W=["onPointerdown"],q={__name:"WidgetModalContainerItem",props:{id:Number},setup(t){const e=c.ref(null),o=I(t.id);function i(){if(o.backgroundClose)return b(o.id,{background:!0}).catch(()=>{})}return c.watch(()=>e.value,r=>{o.instance=r}),(r,a)=>(c.openBlock(),c.createElementBlock("div",{class:"widget__modal-container__item modal-container",onPointerdown:c.withModifiers(i,["self","stop"])},[(c.openBlock(),c.createBlock(c.resolveDynamicComponent(c.unref(o).component),c.mergeProps(c.unref(o).props.value,{class:"modal-item widget__modal-wrap",modalId:`_modal_${t.id}`,ref_key:"modalRef",ref:e},c.toHandlers(c.unref(o).events)),null,16,["modalId"]))],40,W))}};function $(t){t===void 0&&(t=_.DEFAULT_NAMESPACE);var e=_.instance.getByName(t);e.initialized=!0,t===_.DEFAULT_NAMESPACE&&document.addEventListener("keyup",function(n){if(y.escClose&&(n.key==="Escape"||n.code==="Escape")){var o=C(t);if(!o)return;b(o.id,{esc:!0}).catch(function(){})}})}const Z="",H={props:{namespace:String},setup(t){return c.onMounted(()=>{$(t.namespace)}),()=>{const e=m(t.namespace);return c.h(c.TransitionGroup,{name:y.animation},{default:()=>e.queue.map(n=>c.h(q,{key:n.id,id:n.id}))})}},components:{WidgetContainerModalItem:q}};var w={router:null};function Y(t){var e=this;if(w.router)throw d.DuplicatedRouterIntegration();w.router=t;function n(o){for(var i=o.matched.length-1;i>=0;i--){var r=o.matched[i].components,a=Object.values(r).find(function(l){return l._isModal});if(a)return a}return null}t.beforeEach(function(o,i){return p(e,void 0,void 0,function(){var r,a,l;return g(this,function(f){switch(f.label){case 0:return f.trys.push([0,3,,4]),r=n(i),r&&!(!((l=(a=r.getModalObject())===null||a===void 0?void 0:a.closed)===null||l===void 0)&&l.value)?[4,r.close(!0)]:[3,2];case 1:f.sent(),f.label=2;case 2:return[3,4];case 3:return f.sent(),[2,!1];case 4:return[2]}})})}),t.afterEach(function(o){return p(e,void 0,void 0,function(){var i;return g(this,function(r){switch(r.label){case 0:return i=n(o),i?[4,i.initialize()]:[3,2];case 1:r.sent(),r.label=2;case 2:return[2]}})})})}function D(t){var e=null,n=!1;function o(){return p(this,void 0,void 0,function(){return g(this,function(i){switch(i.label){case 0:if(!w.router)throw d.ModalRouterIntegrationNotInitialized();return n=!1,e=null,[4,j(t,c.computed(function(){var r;return(r=w.router)===null||r===void 0?void 0:r.currentRoute.value.params}),{isRoute:!0})];case 1:return e=i.sent(),e.onclose=function(){var r;n||(r=w.router)===null||r===void 0||r.back()},[2]}})})}return{getModalObject:function(){return e},_isModal:!0,close:function(i){return i===void 0&&(i=!1),p(this,void 0,void 0,function(){return g(this,function(r){switch(r.label){case 0:return n=i,e?[4,e.close()]:[3,2];case 1:return[2,r.sent()];case 2:return[2]}})})},initialize:o,setup:function(){return function(){return null}}}}D.init=Y;var J=m().queue;function K(t){return m(t).queue}s.Modal=M,s.closeById=b,s.closeModal=A,s.config=x,s.container=H,s.getComponentFromStore=B,s.getCurrentModal=C,s.getQueueByNamespace=K,s.modalQueue=J,s.onBeforeModalClose=L,s.openModal=j,s.popModal=Q,s.promptModal=V,s.pushModal=P,s.useModalRouter=D,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}); | ||
//# sourceMappingURL=jenesius-vue-modal.umd.js.map |
@@ -6,7 +6,7 @@ /** | ||
import { ModalID } from "./Modal"; | ||
declare type AvailableKeys = 'close'; | ||
declare type AvailableKeys = 'close' | 'destroy'; | ||
interface GuardsInterface { | ||
store: { | ||
[index: number]: { | ||
[key in AvailableKeys]: Array<GuardFunction>; | ||
[key in AvailableKeys]?: Array<GuardFunction>; | ||
}; | ||
@@ -29,4 +29,4 @@ }; | ||
* If guard return void or true value - resolve. | ||
* Otherwise reject(err) | ||
* Otherwise, reject(err) | ||
* */ | ||
export declare function guardToPromiseFn(guard: GuardFunction, id: ModalID, props?: any): GuardFunctionPromisify; |
@@ -70,2 +70,6 @@ import { Component, ComputedRef, Ref } from "vue"; | ||
/** | ||
* @description Hook for handling modal closing | ||
* */ | ||
set ondestroy(func: GuardFunction); | ||
/** | ||
* @description Method for handle default events from VueComponent. | ||
@@ -72,0 +76,0 @@ * */ |
{ | ||
"name": "jenesius-vue-modal", | ||
"version": "1.10.3", | ||
"version": "1.11.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "The progressive and simple modal system for Vue.js v3", |
import {mount} from "@vue/test-utils"; | ||
import {container, promptModal} from "../src/index"; | ||
import {container, promptModal, closeModal} from "../src/index"; | ||
import ModalPromptValue from "./components/modal-prompt-value.vue"; | ||
import wait from "./wait"; | ||
import NamespaceStore from "./../src/utils/NamespaceStore"; | ||
import ModalPromptValueWithHandler from "./components/modal-prompt-value-with-handler.vue"; | ||
import guards from "./../src/utils/guards"; | ||
const app = mount(container); | ||
beforeEach(async () => { | ||
NamespaceStore.instance.forceClean() | ||
guards.store = {} | ||
await wait() | ||
@@ -13,4 +17,4 @@ }) | ||
describe("Testing prompt-modal", () => { | ||
it('Test for opened modal window', async function () { | ||
const wrap = await mount(container); | ||
@@ -23,15 +27,47 @@ const value = '123'; | ||
expect(wrap.text()).toEqual(value); | ||
expect(app.text()).toEqual(value); | ||
}); | ||
it("Should be returned with provided value", async function () { | ||
await mount(container); | ||
const value = Math.random(); | ||
const prResult = promptModal(ModalPromptValue, { | ||
value | ||
}) | ||
await wait() | ||
app.find('button').trigger('click') | ||
expect(await promptModal(ModalPromptValue, { | ||
await wait() | ||
expect(await prResult).toEqual(value) | ||
}) | ||
it('If modal was prompted and then just closed, promise should be resolved with value null', async () => { | ||
const value = Math.random(); | ||
const prResult = promptModal(ModalPromptValue, { | ||
value | ||
})).toEqual(value) | ||
}) | ||
await wait() | ||
await closeModal() | ||
expect(await prResult).toEqual(null) | ||
}) | ||
it("Should not be executed, if on of close's handler stop closing process", async () => { | ||
const value = Math.random(); | ||
let isResolved = false | ||
const prResult = promptModal(ModalPromptValueWithHandler, { | ||
value | ||
}).then(data => { | ||
isResolved = true; | ||
return data; | ||
}) | ||
await wait() | ||
await app.find('button').trigger('click') | ||
await wait() | ||
await app.find('button').trigger('click') | ||
await wait() | ||
expect(await prResult).toEqual(value) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
219889
65
2457