vue-insertable
Version:
Insert components in Vue page
8 lines (7 loc) • 3.26 kB
JavaScript
/*!
* vue-insertable v0.1.1
* (c) 2019-2020 Fierflame
* @license MIT
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("vue")):"function"==typeof define&&define.amd?define(["vue"],e):(t=t||self).VueInsertable=e(t.Vue)}(this,(function(t){"use strict";function e(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function n(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(i,!0).forEach((function(r){e(t,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):r(i).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}t=t&&t.hasOwnProperty("default")?t.default:t;const i={name:"InsertView",functional:!0,render(t,{parent:e,props:r,data:i}){const{name:s}=r,{$insertable:o}=e;if(!o)return[];const c=o.get(s);return c?c.map(e=>t(e,function(t){const{key:e,slot:r,ref:i,staticClass:s,class:o,staticStyle:c,style:a,props:p,attrs:u,domProps:f,on:l,nativeOn:d,show:h,directives:b,keepAlive:y}=t;return{key:e,slot:r,ref:i,refInFor:!0,staticClass:s,class:o,staticStyle:c,style:a,props:n({},p),attrs:n({},u),domProps:n({},f),on:n({},l),nativeOn:n({},d),show:h,directives:b&&[...b],keepAlive:y}}(i))):[]}};class s{constructor(t,r){e(this,"_inited",!1),e(this,"parent",void 0),e(this,"_groups",Object.create(null)),t instanceof s?this.parent=t:[t,r]=[,t];const{groups:n={}}=r||{};for(let t in n)this.set(t,n)}init(){if(this._inited)return this._groups;if(!o)return this._groups;this._inited=!0;const t=Object.create(null),e=this._groups;for(const r in e)o.set(t,r,e[r]);return this._groups=t,t}add(t,e,r=0){const n=this.init();Array.isArray(e)||(e=[e]);const i=n[t]?[...n[t]]:[];i.push(...e.map(t=>({component:t,order:r}))),i.sort(({order:t},{order:e})=>t-e),o?o.set(n,t,i):n[t]=i}remove(t,e,r=0){const n=this.init(),i=n[t];if(!i)return;if(!e)return void(o?o.set(n,t,[]):n[t]=[]);const s=i.findIndex(t=>t.component===e&&t.order===r);if(s<0)return;const c=[...i.slice(0,s),...i.slice(s+1)];o?o.set(n,t,c):n[t]=c}set(t,e,r=0){const n=this.init();Array.isArray(e)||(e=[e]);const i=e.map(t=>({component:t,order:r}));o?o.set(n,t,i):n[t]=i}_getInfo(t,e){const r=this.init()[t]||[];if(e)return r;const n=this.parent?this.parent._getInfo(t):[],i=[...n,...r];return r.length&&n.length&&i.sort(({order:t},{order:e})=>t-e),i}get(t,e){return this._getInfo(t,e).map(({component:t})=>t)}static get install(){return c}static get View(){return i}}let o;function c(t){o!==t&&(o=t,Object.defineProperty(t.prototype,"$insertable",{get(){if(this.$parent)return this.$parent.$insertable},configurable:!0}),t.component("InsertView",i),t.mixin({beforeCreate(){let t=this.$options.insertable;"function"==typeof t&&(t=t(this.$parent&&this.$parent.$insertable)),t instanceof s&&Object.defineProperty(this,"$insertable",{value:t,configurable:!0})}}))}return e(s,"version","0.1.1"),t&&c(t),s}));
//# sourceMappingURL=vue-insertable.min.js.map