vue-router-layout
Version:
Lightweight layout selector for Vue Router
10 lines • 4.41 kB
JavaScript
/*!
* vue-router-layout v0.4.1
* https://github.com/ktsn/vue-router-layout
*
* @license
* Copyright (c) 2018 katashin
* Released under the MIT license
* https://github.com/ktsn/vue-router-layout/blob/master/LICENSE
*/
var a,b;a=this,b=function(e,o){"use strict";var r=function(){return(r=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},t=function(e,a,i,l){return new(i=i||Promise)(function(n,t){function o(e){try{u(l.next(e))}catch(e){t(e)}}function r(e){try{u(l.throw(e))}catch(e){t(e)}}function u(e){var t;e.done?n(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(o,r)}u((l=l.apply(e,a||[])).next())})},c=function(n,o){var r,u,a,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,u&&(a=2&t[0]?u.return:t[0]?u.throw||((a=u.return)&&a.call(u),0):u.next)&&!(a=a.call(u,t[1])).done)return a;switch(u=0,(t=a?[2&t[0],a.value]:t)[0]){case 0:case 1:a=t;break;case 4:return i.label++,{value:t[1],done:!1};case 5:i.label++,u=t[1],t=[0];continue;case 7:t=i.ops.pop(),i.trys.pop();continue;default:if(!(a=0<(a=i.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){i=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3])){i.label=t[1];break}if(6===t[0]&&i.label<a[1]){i.label=a[1],a=t;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(t);break}a[2]&&i.ops.pop(),i.trys.pop();continue}t=o.call(n,i)}catch(e){t=[6,e],u=0}finally{r=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};function a(e){if("string"==typeof e)return{name:e,props:{}};if(e&&"object"==typeof e&&"name"in e)return{name:e.name,props:(null==e?void 0:e.props)||{}};throw new Error("[vue-router-layout] Incorrect value for the 'layout' property.")}function s(e){e=e[e.length-1];if(e){e=e.components.default;if(e)if(!("function"==typeof e&&!e.options))return function e(t){var n="function"==typeof t&&t.options;var n=n?t.options:t;if(n.layout)return a(n.layout);t=(n.mixins||[]).slice().reverse();n=n.extends||[];for(var o=0,r=t.concat(n);o<r.length;o++){var u=r[o],u=e(u);if(u)return u}}(e)||{name:"default",props:{}}}}function f(e){var o=[];return e.matched.forEach(function(n){Object.keys(n.components).forEach(function(t){var e=n.components[t];"function"!=typeof e||e.options||o.push(e().then(function(e){n.components[t]=p(e)}))})}),Promise.all(o)}function p(e){return e.__esModule||"undefined"!=typeof Symbol&&"Module"===e[Symbol.toStringTag]?e.default:e}var n={install:function(){console.info("[vue-router-layout] app.use(VueRouterLayout) is no longer needed. You can safely remove it.")}};e.createRouterLayout=function(l){return o.defineComponent({name:"RouterLayout",data:function(){return{layout:void 0,layouts:o.shallowReactive(Object.create(null))}},beforeRouteEnter:function(u,e,a){return t(this,void 0,void 0,function(){var t,n,o,r;return c(this,function(e){switch(e.label){case 0:return[4,f(u)];case 1:return(e.sent(),t=s(u.matched))?(r=p,[4,l(t.name)]):[3,3];case 2:return o=r.apply(void 0,[e.sent()]),[3,4];case 3:o=void 0,e.label=4;case 4:return n=o,a(function(e){(e.layout=t)&&n&&(e.layouts[t.name]=n)}),[2]}})})},beforeRouteUpdate:function(a,e,i){return t(this,void 0,void 0,function(){var t,n,o,r,u;return c(this,function(e){switch(e.label){case 0:return e.trys.push([0,4,,5]),[4,f(a)];case 1:return(e.sent(),!(t=s(a.matched)||this.layout)||this.layouts[t.name])?[3,3]:(n=this.layouts,o=t.name,r=p,[4,l(t.name)]);case 2:n[o]=r.apply(void 0,[e.sent()]),e.label=3;case 3:return this.layout=t,i(),[3,5];case 4:return u=e.sent(),i(u),[3,5];case 5:return[2]}})})},render:function(){var e,t=this.layout&&this.layouts[this.layout.name],n=s(this.$route.matched);return!t||n&&(null===(e=this.layout)||void 0===e?void 0:e.name)!==n.name?null:o.h(t,r({key:this.layout.name},this.layout.props))}})},e.default=n,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?b(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],b):b((a="undefined"!=typeof globalThis?globalThis:a||self).VueRouterLayout={},a.Vue);