vue-mount-plugin 3.0.0 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +297 -19
- package/dist/index.cjs +969 -0
- package/dist/index.d.ts +266 -21
- package/dist/index.es5.js +7767 -0
- package/dist/index.es5.min.js +1 -0
- package/dist/index.iife.js +1103 -0
- package/dist/index.iife.min.js +1 -0
- package/dist/index.mjs +896 -90
- package/package.json +64 -63
- package/dist/index.cjs.js +0 -122
- package/dist/index.esm-browser.js +0 -65
- package/dist/index.esm-browser.prod.js +0 -7
- package/dist/index.esm-bundler.js +0 -59
- package/dist/index.global.js +0 -245
- package/dist/index.global.prod.js +0 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _VueDemiGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,VueDemi=function(e,t,n){if(e.install)return e;if(!t)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if("2.7."===t.version.slice(0,4)){for(var o in t)e[o]=t[o];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=t,e.Vue2=t,e.version=t.version,e.warn=t.util.warn,e.hasInjectionContext=function(){return!!e.getCurrentInstance()},e.createApp=function(e,n){var o,i={},r={config:t.config,use:t.use.bind(t),mixin:t.mixin.bind(t),component:t.component.bind(t),provide:function(e,t){return i[e]=t,this},directive:function(e,n){return n?(t.directive(e,n),r):t.directive(e)},mount:function(r,u){return o||((o=new t(Object.assign({propsData:n},e,{provide:Object.assign(i,e.provide)}))).$mount(r,u),o)},unmount:function(){o&&(o.$destroy(),o=void 0)}};return r}}else if("2."===t.version.slice(0,2))if(n){for(var o in n)e[o]=n[o];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=t,e.Vue2=t,e.version=t.version,e.hasInjectionContext=function(){return!!e.getCurrentInstance()}}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if("3."===t.version.slice(0,2)){for(var o in t)e[o]=t[o];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=t,e.Vue2=void 0,e.version=t.version,e.set=function(e,t,n){return Array.isArray(e)?(e.length=Math.max(e.length,t),e.splice(t,1,n),n):(e[t]=n,n)},e.del=function(e,t){Array.isArray(e)?e.splice(t,1):delete e[t]}}else console.error("[vue-demi] Vue version "+t.version+" is unsupported.");return e}(_VueDemiGlobal.VueDemi=_VueDemiGlobal.VueDemi||(void 0!==VueDemi?VueDemi:{}),_VueDemiGlobal.Vue||("undefined"!=typeof Vue?Vue:void 0),_VueDemiGlobal.VueCompositionAPI||("undefined"!=typeof VueCompositionAPI?VueCompositionAPI:void 0));!function(e,t){"use strict";function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function o(e,t,n,o,i,r,u){try{var s=e[r](u),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(o,i)}function i(e,t,n){return t=a(t),function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,f()?Reflect.construct(t,n||[],a(e).constructor):t.apply(e,n))}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,y(o.key),o)}}function s(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(e,t,n){return(t=y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(f=function(){return!!e})()}function h(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?h(Object(n),!0).forEach(function(t){l(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):h(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,i,r,u,s=[],l=!0,a=!1;try{if(r=(n=n.call(e)).next,0===t);else for(;!(l=(o=r.call(n)).done)&&(s.push(o.value),s.length!==t);l=!0);}catch(e){a=!0,i=e}finally{try{if(!l&&null!=n.return&&(u=n.return(),Object(u)!==u))return}finally{if(a)throw i}}return s}}(e,t)||g(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t);if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:t+""}function g(e,t){if(e){if("string"==typeof e)return n(e,t);var o={}.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?n(e,t):void 0}}var _=new Map,b=new WeakMap;function V(e,t){if(!1!==t)return"string"==typeof t?t:!0===t?function(e){return b.has(e)||b.set(e,Symbol(e.name||"anonymous")),b.get(e)}(e):void 0}function w(e,t){var n=_.get(e);n&&n!==t&&n.unmount(),_.set(e,t)}function O(e){_.delete(e)}var k={installed:!1};function j(e){Object.assign(k,e)}function E(e){return v(v({},k),e)}function I(){return"undefined"!=typeof document}function C(e){return e?"string"==typeof e?I()?document.querySelector(e):null:e:null}function M(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"div",t=arguments.length>1?arguments[1]:void 0;if(!I())throw new TypeError("This plugin works in browser");var n=document.createElement(e);return t&&Object.entries(t).forEach(function(e){var t=p(e,2),o=t[0],i=t[1];n.setAttribute(o,i)}),n}function A(e,t){if(I()){var n=C(t);n?n.appendChild(e):document.body.appendChild(e)}}function P(e){e.parentNode&&e.parentNode.removeChild(e)}function x(e){return document.body.contains(e)}function S(e,t){void 0!==t&&(e.style.zIndex=String(t))}var T=s(function e(){r(this,e),l(this,"events",new Map)},[{key:"on",value:function(e,t){return this.events.has(e)||this.events.set(e,new Set),this.events.get(e).add(t),this}},{key:"off",value:function(e,t){var n;return t?null===(n=this.events.get(e))||void 0===n||n.delete(t):this.events.delete(e),this}},{key:"emit",value:function(e){for(var t,n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return null===(t=this.events.get(e))||void 0===t||t.forEach(function(t){try{t.apply(void 0,o)}catch(t){console.error('Error in event handler for "'.concat(e,'":'),t)}}),this}},{key:"has",value:function(e){return this.events.has(e)&&this.events.get(e).size>0}},{key:"clear",value:function(){this.events.clear()}},{key:"eventNames",value:function(){return Array.from(this.events.keys())}}]),$=0;function D(){return"mount-".concat(++$,"-").concat(Date.now().toString(36))}function N(e){return e.charAt(0).toUpperCase()+e.slice(1)}var B=new Set,G=s(function e(t){var n=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,e),l(this,"mounted",!1),l(this,"el",null),l(this,"_eventEmitter",new T),l(this,"_autoCreatedTarget",!1),l(this,"_hidden",!1),l(this,"_destroyed",!1),l(this,"destroy",this.unmount),l(this,"remove",this.unmount),this.id=D(),this._component=t,this.options=E(o),this._promise=new Promise(function(e,t){n._resolve=e,n._reject=t}),this._singletonKey=V(t,o.singleton),this._singletonKey&&w(this._singletonKey,this),B.add(this)},[{key:"show",value:function(){var e,t,n,o;return this.mounted&&!this._hidden||(null===(e=(t=this.options).onBeforeMount)||void 0===e||e.call(t,this),this._ensureElement(),this._mountVM(),this.options.zIndex&&this.el&&S(this.el,this.options.zIndex),this.mounted=!0,this._hidden=!1,null===(n=(o=this.options).onMounted)||void 0===n||n.call(o,this),this.emit("show",this)),this}},{key:"hide",value:function(){return!this.mounted||this._hidden||(this.emit("beforeHide",this),this.el&&x(this.el)&&P(this.el),this._hidden=!0,this.emit("hide",this)),this}},{key:"unmount",value:function(){var e,t,n,o;this._destroyed||(this._destroyed=!0,(this.mounted||this._hidden)&&(null===(n=(o=this.options).onBeforeUnmount)||void 0===n||n.call(o,this)),this._eventEmitter.emit("beforeUnmount",this),this._unmountVM(),this._autoCreatedTarget&&this.el&&P(this.el),this.mounted=!1,this._hidden=!1,this.el=null,this.vm=null,B.delete(this),this._singletonKey&&O(this._singletonKey),null===(e=(t=this.options).onUnmounted)||void 0===e||e.call(t,this),this._eventEmitter.clear())}},{key:"setProps",value:function(e){return this.options=v(v({},this.options),{},{props:v(v({},this.options.props),e)}),this.mounted&&this._updateVM(),this}},{key:"on",value:function(e,t){return this._eventEmitter.on(e,t),this}},{key:"off",value:function(e,t){return this._eventEmitter.off(e,t),this}},{key:"emit",value:function(e){var t;if(this._destroyed)return this;for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return(t=this._eventEmitter).emit.apply(t,[e].concat(o)),this}},{key:"then",value:function(e){return this._promise.then(e)}},{key:"catch",value:function(e){return this._promise.catch(e)}},{key:"finally",value:function(e){return this._promise.finally(e)}},{key:"setTarget",value:function(e){return this.options.target=e,this}},{key:"setHooks",value:function(e){return this.options=v(v({},this.options),e),this}},{key:"setSlots",value:function(e){return this.options=v(v({},this.options),{},{slots:v(v({},this.options.slots),e)}),this}},{key:"_ensureElement",value:function(){if(!this.el){var e=C(this.options.target);e instanceof Element?(this.el=e,this._autoCreatedTarget=!1):(this.el=M(this.options.tagName||"div",{"data-mount-id":this.id}),this._autoCreatedTarget=!0)}}},{key:"_appendElementToDOM",value:function(){this.el&&this._autoCreatedTarget&&A(this.el,null)}},{key:"_resolvePromise",value:function(e){this._resolve(e)}},{key:"_rejectPromise",value:function(e){this._reject(e)}},{key:"_mergeListenersToProps",value:function(e){var t={};return Object.entries(e).forEach(function(e){var n=p(e,2),o=n[0],i=n[1];t["on".concat(N(o))]=i}),t}}],[{key:"instances",get:function(){return Array.from(B)}},{key:"unmountAll",value:function(){B.forEach(function(e){return e.unmount()})}},{key:"getById",value:function(e){return Array.from(B).find(function(t){return t.id===e})}}]);function K(){return Array.from(B)}function U(e){return G.getById(e)}function z(e,t){var n=t.context||{};return e&&(e._isVue||e.$options)?v({router:e.$router||n.router,store:e.$store||n.store,i18n:e.$i18n||n.i18n,route:e.$route},n):n}var L,R=function(e){function n(e){var o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(r(this,n),l(o=i(this,n,[e,u]),"vm",null),l(o,"_vue2Instance",null),!t.isVue2)throw new Error("MountVue2 can only be used with Vue 2");return o._createVM(),o}return c(n,e),s(n,[{key:"_createVM",value:function(){var e=t.Vue2,n=this.options,o=n.props,i=n.parent,r=n.listeners,u=n.on,s=v(v({},r),u),l=z(i,this.options),a=this._component;this._component.options&&(a=this._component.options);var c=new(e.extend(a))({propsData:o||{},parent:i,router:l.router,store:l.store,i18n:l.i18n});Object.entries(s).forEach(function(e){var t=p(e,2),n=t[0],o=t[1];Array.isArray(o)?o.forEach(function(e){return c.$on(n,e)}):c.$on(n,o)}),c._mountId=this.id,this._vue2Instance=c}},{key:"_mountVM",value:function(){this._vue2Instance&&(this._ensureElement(),this._appendElementToDOM(),this._vue2Instance.$mount(this.el),this._vue2Instance.$el&&(this.el=this._vue2Instance.$el),this.vm=this._vue2Instance,this.mounted=!0)}},{key:"_unmountVM",value:function(){this._vue2Instance&&(this._vue2Instance.$destroy(),this._vue2Instance=null),this.vm=null,this.mounted=!1}},{key:"_updateVM",value:function(){this._vue2Instance&&this.options.props&&Object.assign(this._vue2Instance.$props,this.options.props)}}])}(G);function H(){return W.apply(this,arguments)}function W(){var e;return e=function*(){if(L)return L;var e=yield import("vue");return L=e.render},W=function(){var t=this,n=arguments;return new Promise(function(i,r){var u=e.apply(t,n);function s(e){o(u,i,r,s,l,"next",e)}function l(e){o(u,i,r,s,l,"throw",e)}s(void 0)})},W.apply(this,arguments)}var q=function(e){function n(e){var o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(r(this,n),l(o=i(this,n,[e,u]),"vm",null),l(o,"_vNode",null),t.isVue2)throw new Error("MountVue3 can only be used with Vue 3");return o._createVM(),o}return c(n,e),s(n,[{key:"_createVM",value:function(){var e=this.options,n=e.props,o=e.children,i=e.app,r=e.listeners,u=e.on,s=e.slots,l=v(v({},r),u),a=v(v({},n),this._mergeListenersToProps(l)),c=s?v(v({},s),o?{default:o}:{}):o,f=t.h(this._component,a,c);null!=i&&i._context&&(f.appContext=i._context),this._vNode=f}},{key:"_mountVM",value:function(){var e=this;this._vNode||this._createVM(),this._ensureElement(),this._appendElementToDOM(),H().then(function(t){var n,o;t&&e._vNode&&e.el&&(t(e._vNode,e.el),e.vm=null!==(n=null===(o=e._vNode.component)||void 0===o?void 0:o.proxy)&&void 0!==n?n:null)}),this.mounted=!0}},{key:"_unmountVM",value:function(){var e=this;this._vNode&&(H().then(function(t){t&&e.el&&t(null,e.el)}),this._vNode=null),this.vm=null,this.mounted=!1}},{key:"_updateVM",value:function(){var e=this;this._createVM(),this.mounted&&this.el&&this._vNode&&H().then(function(t){var n,o;t&&(t(e._vNode,e.el),e.vm=null!==(n=null===(o=e._vNode.component)||void 0===o?void 0:o.proxy)&&void 0!==n?n:null)})}}])}(G);function Z(){var e=t.ref([]),n=function(){e.value.forEach(function(e){return e.unmount()}),e.value=[]};return t.isVue2||t.onUnmounted(n),{instances:e,mount:function(t,n){var o=F(t,n);return e.value.push(o),o},unmount:function(t){t.unmount(),e.value=e.value.filter(function(e){return e!==t})},unmountAll:n,getById:function(t){return e.value.find(function(e){return e.id===t})},hasInstances:function(){return e.value.length>0},count:function(){return e.value.length}}}function F(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.isVue2?new R(e,n):new q(e,n)}function J(e){return F(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).show()}var Q={install:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};j(v(v({},n),{},{installed:!0}));var o=n.name||"$mount";t.isVue2?e.prototype[o]=J:e.config.globalProperties[o]=J}};e.EventEmitter=T,e.MountBase=G,e.MountPlugin=Q,e.MountVue2=R,e.MountVue3=q,e.addClass=function(e,t){var n;t&&(n=e.classList).add.apply(n,m(t.split(/\s+/).filter(Boolean)))},e.appendTo=A,e.capitalize=N,e.clearSingletons=function(){_.forEach(function(e){return e.unmount()}),_.clear()},e.createElement=M,e.createInstanceId=D,e.createMount=F,e.eventToPropName=function(e){return"on".concat(N(e))},e.getActiveInstanceIds=function(){return K().map(function(e){return e.id})},e.getCurrentComponentContext=function(e){var t;if(!e)return{};var n={};return e.$router&&(n.router=e.$router),e.$store&&(n.store=e.$store),e.$i18n&&(n.i18n=e.$i18n),null!==(t=e.$)&&void 0!==t&&t.appContext&&(n.appContext=e.$.appContext),n},e.getGlobalConfig=function(){return v({},k)},e.getInstanceById=U,e.getInstances=K,e.getSingleton=function(e){return _.get(e)},e.getSingletonKey=V,e.getSingletonKeys=function(){return Array.from(_.keys())},e.globalConfig=k,e.hasSingleton=function(e){return _.has(e)},e.inheritVue2Context=z,e.inheritVue3Context=function(e,t){return null!=e&&e._context?{appContext:e._context,provides:e._context.provides}:{}},e.isBrowser=I,e.isInDOM=x,e.isMounted=function(e){var t,n=U(e);return null!==(t=null==n?void 0:n.mounted)&&void 0!==t&&t},e.isNodeEnv=function(){var e;return"undefined"!=typeof process&&!(null===(e=process.versions)||void 0===e||!e.node)},e.mergeWithGlobalConfig=E,e.mount=J,e.removeClass=function(e,t){var n;t&&(n=e.classList).remove.apply(n,m(t.split(/\s+/).filter(Boolean)))},e.removeElement=P,e.removeSingleton=O,e.resetGlobalConfig=function(){Object.keys(k).forEach(function(e){delete k[e]}),k.installed=!1},e.resolveTarget=C,e.setGlobalConfig=j,e.setSingleton=w,e.setZIndex=S,e.unmountAll=function(){G.unmountAll()},e.useMount=Z,e.useSingleton=function(){return{getOrCreate:function(e,t,n){var o=Z().instances.value.find(function(t){return t.id===e||t.options.singleton===e});return o||F(t,v(v({},n),{},{singleton:e}))}}}}(this.VueMount=this.VueMount||{},VueDemi);
|