kdu-router 3.5.4 → 4.0.16
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/LICENSE +2 -2
- package/README.md +10 -4
- package/dist/kdu-router.cjs.js +3484 -0
- package/dist/kdu-router.cjs.prod.js +2759 -0
- package/dist/kdu-router.d.ts +1349 -0
- package/dist/kdu-router.esm-browser.js +3460 -0
- package/dist/kdu-router.esm-bundler.js +3478 -0
- package/dist/kdu-router.global.js +3625 -0
- package/dist/kdu-router.global.prod.js +6 -0
- package/ketur/attributes.json +8 -14
- package/ketur/tags.json +2 -12
- package/package.json +77 -71
- package/dist/kdu-router.common.js +0 -3147
- package/dist/kdu-router.esm.browser.js +0 -3113
- package/dist/kdu-router.esm.browser.min.js +0 -11
- package/dist/kdu-router.esm.js +0 -3145
- package/dist/kdu-router.js +0 -3152
- package/dist/kdu-router.min.js +0 -11
- package/src/components/link.js +0 -224
- package/src/components/view.js +0 -155
- package/src/create-matcher.js +0 -226
- package/src/create-route-map.js +0 -220
- package/src/history/abstract.js +0 -72
- package/src/history/base.js +0 -379
- package/src/history/hash.js +0 -152
- package/src/history/html5.js +0 -99
- package/src/index.js +0 -293
- package/src/install.js +0 -52
- package/src/util/async.js +0 -18
- package/src/util/dom.js +0 -3
- package/src/util/errors.js +0 -86
- package/src/util/location.js +0 -69
- package/src/util/misc.js +0 -6
- package/src/util/params.js +0 -37
- package/src/util/path.js +0 -74
- package/src/util/push-state.js +0 -46
- package/src/util/query.js +0 -113
- package/src/util/resolve-components.js +0 -109
- package/src/util/route.js +0 -151
- package/src/util/scroll.js +0 -175
- package/src/util/state-key.js +0 -22
- package/src/util/warn.js +0 -14
- package/types/index.d.ts +0 -21
- package/types/kdu.d.ts +0 -22
- package/types/router.d.ts +0 -211
package/dist/kdu-router.min.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* kdu-router v3.5.4
|
|
3
|
-
* (c) 2022 NKDuy
|
|
4
|
-
* @license MIT
|
|
5
|
-
*/
|
|
6
|
-
/*!
|
|
7
|
-
* kdu-router v3.5.4
|
|
8
|
-
* (c) 2022 NKDuy
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
var t,e;t=this,e=function(){"use strict";function t(t,e){for(var r in e)t[r]=e[r];return t}var e=/[!'()*]/g,r=function(t){return"%"+t.charCodeAt(0).toString(16)},n=/%2C/g,o=function(t){return encodeURIComponent(t).replace(e,r).replace(n,",")};function i(t){try{return decodeURIComponent(t)}catch(t){}return t}var a=function(t){return null==t||"object"==typeof t?t:String(t)};function s(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach((function(t){var r=t.replace(/\+/g," ").split("="),n=i(r.shift()),o=r.length>0?i(r.join("=")):null;void 0===e[n]?e[n]=o:Array.isArray(e[n])?e[n].push(o):e[n]=[e[n],o]})),e):e}function u(t){var e=t?Object.keys(t).map((function(e){var r=t[e];if(void 0===r)return"";if(null===r)return o(e);if(Array.isArray(r)){var n=[];return r.forEach((function(t){void 0!==t&&(null===t?n.push(o(e)):n.push(o(e)+"="+o(t)))})),n.join("&")}return o(e)+"="+o(r)})).filter((function(t){return t.length>0})).join("&"):null;return e?"?"+e:""}var c=/\/?$/;function p(t,e,r,n){var o=n&&n.options.stringifyQuery,i=e.query||{};try{i=f(i)}catch(t){}var a={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:i,params:e.params||{},fullPath:d(e,o),matched:t?l(t):[]};return r&&(a.redirectedFrom=d(r,o)),Object.freeze(a)}function f(t){if(Array.isArray(t))return t.map(f);if(t&&"object"==typeof t){var e={};for(var r in t)e[r]=f(t[r]);return e}return t}var h=p(null,{path:"/"});function l(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function d(t,e){var r=t.path,n=t.query;void 0===n&&(n={});var o=t.hash;return void 0===o&&(o=""),(r||"/")+(e||u)(n)+o}function v(t,e,r){return e===h?t===e:!!e&&(t.path&&e.path?t.path.replace(c,"")===e.path.replace(c,"")&&(r||t.hash===e.hash&&y(t.query,e.query)):!(!t.name||!e.name)&&t.name===e.name&&(r||t.hash===e.hash&&y(t.query,e.query)&&y(t.params,e.params)))}function y(t,e){if(void 0===t&&(t={}),void 0===e&&(e={}),!t||!e)return t===e;var r=Object.keys(t).sort(),n=Object.keys(e).sort();return r.length===n.length&&r.every((function(r,o){var i=t[r];if(n[o]!==r)return!1;var a=e[r];return null==i||null==a?i===a:"object"==typeof i&&"object"==typeof a?y(i,a):String(i)===String(a)}))}function m(t){for(var e=0;e<t.matched.length;e++){var r=t.matched[e];for(var n in r.instances){var o=r.instances[n],i=r.enteredCbs[n];if(o&&i){delete r.enteredCbs[n];for(var a=0;a<i.length;a++)o._isBeingDestroyed||i[a](o)}}}}var g={name:"RouterView",functional:!0,props:{name:{type:String,default:"default"}},render:function(e,r){var n=r.props,o=r.children,i=r.parent,a=r.data;a.routerView=!0;for(var s=i.$createElement,u=n.name,c=i.$route,p=i._routerViewCache||(i._routerViewCache={}),f=0,h=!1;i&&i._routerRoot!==i;){var l=i.$knode?i.$knode.data:{};l.routerView&&f++,l.keepAlive&&i._directInactive&&i._inactive&&(h=!0),i=i.$parent}if(a.routerViewDepth=f,h){var d=p[u],v=d&&d.component;return v?(d.configProps&&w(v,a,d.route,d.configProps),s(v,a,o)):s()}var y=c.matched[f],g=y&&y.components[u];if(!y||!g)return p[u]=null,s();p[u]={component:g},a.registerRouteInstance=function(t,e){var r=y.instances[u];(e&&r!==t||!e&&r===t)&&(y.instances[u]=e)},(a.hook||(a.hook={})).prepatch=function(t,e){y.instances[u]=e.componentInstance},a.hook.init=function(t){t.data.keepAlive&&t.componentInstance&&t.componentInstance!==y.instances[u]&&(y.instances[u]=t.componentInstance),m(c)};var b=y.props&&y.props[u];return b&&(t(p[u],{route:c,configProps:b}),w(g,a,c,b)),s(g,a,o)}};function w(e,r,n,o){var i=r.props=function(t,e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}(n,o);if(i){i=r.props=t({},i);var a=r.attrs=r.attrs||{};for(var s in i)e.props&&s in e.props||(a[s]=i[s],delete i[s])}}function b(t,e,r){var n=t.charAt(0);if("/"===n)return t;if("?"===n||"#"===n)return e+t;var o=e.split("/");r&&o[o.length-1]||o.pop();for(var i=t.replace(/^\//,"").split("/"),a=0;a<i.length;a++){var s=i[a];".."===s?o.pop():"."!==s&&o.push(s)}return""!==o[0]&&o.unshift(""),o.join("/")}function x(t){return t.replace(/\/(?:\s*\/)+/g,"/")}var R=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},k=B,E=j,C=function(t,e){return S(j(t,e),e)},A=S,O=U,_=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function j(t,e){for(var r,n=[],o=0,i=0,a="",s=e&&e.delimiter||"/";null!=(r=_.exec(t));){var u=r[0],c=r[1],p=r.index;if(a+=t.slice(i,p),i=p+u.length,c)a+=c[1];else{var f=t[i],h=r[2],l=r[3],d=r[4],v=r[5],y=r[6],m=r[7];a&&(n.push(a),a="");var g=null!=h&&null!=f&&f!==h,w="+"===y||"*"===y,b="?"===y||"*"===y,x=r[2]||s,R=d||v;n.push({name:l||o++,prefix:h||"",delimiter:x,optional:b,repeat:w,partial:g,asterisk:!!m,pattern:R?L(R):m?".*":"[^"+P(x)+"]+?"})}}return i<t.length&&(a+=t.substr(i)),a&&n.push(a),n}function T(t){return encodeURI(t).replace(/[\/?#]/g,(function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()}))}function S(t,e){for(var r=new Array(t.length),n=0;n<t.length;n++)"object"==typeof t[n]&&(r[n]=new RegExp("^(?:"+t[n].pattern+")$",q(e)));return function(e,n){for(var o="",i=e||{},a=(n||{}).pretty?T:encodeURIComponent,s=0;s<t.length;s++){var u=t[s];if("string"!=typeof u){var c,p=i[u.name];if(null==p){if(u.optional){u.partial&&(o+=u.prefix);continue}throw new TypeError('Expected "'+u.name+'" to be defined')}if(R(p)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but received `'+JSON.stringify(p)+"`");if(0===p.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var f=0;f<p.length;f++){if(c=a(p[f]),!r[s].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'", but received `'+JSON.stringify(c)+"`");o+=(0===f?u.prefix:u.delimiter)+c}}else{if(c=u.asterisk?encodeURI(p).replace(/[?#]/g,(function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})):a(p),!r[s].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but received "'+c+'"');o+=u.prefix+c}}else o+=u}return o}}function P(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function L(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function $(t,e){return t.keys=e,t}function q(t){return t&&t.sensitive?"":"i"}function U(t,e,r){R(e)||(r=e||r,e=[]);for(var n=(r=r||{}).strict,o=!1!==r.end,i="",a=0;a<t.length;a++){var s=t[a];if("string"==typeof s)i+=P(s);else{var u=P(s.prefix),c="(?:"+s.pattern+")";e.push(s),s.repeat&&(c+="(?:"+u+c+")*"),i+=c=s.optional?s.partial?u+"("+c+")?":"(?:"+u+"("+c+"))?":u+"("+c+")"}}var p=P(r.delimiter||"/"),f=i.slice(-p.length)===p;return n||(i=(f?i.slice(0,-p.length):i)+"(?:"+p+"(?=$))?"),i+=o?"$":n&&f?"":"(?="+p+"|$)",$(new RegExp("^"+i,q(r)),e)}function B(t,e,r){return R(e)||(r=e||r,e=[]),r=r||{},t instanceof RegExp?function(t,e){var r=t.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)e.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return $(t,e)}(t,e):R(t)?function(t,e,r){for(var n=[],o=0;o<t.length;o++)n.push(B(t[o],e,r).source);return $(new RegExp("(?:"+n.join("|")+")",q(r)),e)}(t,e,r):function(t,e,r){return U(j(t,r),e,r)}(t,e,r)}k.parse=E,k.compile=C,k.tokensToFunction=A,k.tokensToRegExp=O;var I=Object.create(null);function M(t,e,r){e=e||{};try{var n=I[t]||(I[t]=k.compile(t));return"string"==typeof e.pathMatch&&(e[0]=e.pathMatch),n(e,{pretty:!0})}catch(t){return""}finally{delete e[0]}}function H(e,r,n,o){var i="string"==typeof e?{path:e}:e;if(i._normalized)return i;if(i.name){var u=(i=t({},e)).params;return u&&"object"==typeof u&&(i.params=t({},u)),i}if(!i.path&&i.params&&r){(i=t({},i))._normalized=!0;var c=t(t({},r.params),i.params);if(r.name)i.name=r.name,i.params=c;else if(r.matched.length){var p=r.matched[r.matched.length-1].path;i.path=M(p,c,r.path)}return i}var f=function(t){var e="",r="",n=t.indexOf("#");n>=0&&(e=t.slice(n),t=t.slice(0,n));var o=t.indexOf("?");return o>=0&&(r=t.slice(o+1),t=t.slice(0,o)),{path:t,query:r,hash:e}}(i.path||""),h=r&&r.path||"/",l=f.path?b(f.path,h,n||i.append):h,d=function(t,e,r){void 0===e&&(e={});var n,o=r||s;try{n=o(t||"")}catch(t){n={}}for(var i in e){var u=e[i];n[i]=Array.isArray(u)?u.map(a):a(u)}return n}(f.query,i.query,o&&o.options.parseQuery),v=i.hash||f.hash;return v&&"#"!==v.charAt(0)&&(v="#"+v),{_normalized:!0,path:l,query:d,hash:v}}var N,F=function(){},V={name:"RouterLink",props:{to:{type:[String,Object],required:!0},tag:{type:String,default:"a"},custom:Boolean,exact:Boolean,exactPath:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,ariaCurrentValue:{type:String,default:"page"},event:{type:[String,Array],default:"click"}},render:function(e){var r=this,n=this.$router,o=this.$route,i=n.resolve(this.to,o,this.append),a=i.location,s=i.route,u=i.href,f={},h=n.options.linkActiveClass,l=n.options.linkExactActiveClass,d=null==h?"router-link-active":h,y=null==l?"router-link-exact-active":l,m=null==this.activeClass?d:this.activeClass,g=null==this.exactActiveClass?y:this.exactActiveClass,w=s.redirectedFrom?p(null,H(s.redirectedFrom),null,n):s;f[g]=v(o,w,this.exactPath),f[m]=this.exact||this.exactPath?f[g]:function(t,e){return 0===t.path.replace(c,"/").indexOf(e.path.replace(c,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(var r in e)if(!(r in t))return!1;return!0}(t.query,e.query)}(o,w);var b=f[g]?this.ariaCurrentValue:null,x=function(t){z(t)&&(r.replace?n.replace(a,F):n.push(a,F))},R={click:z};Array.isArray(this.event)?this.event.forEach((function(t){R[t]=x})):R[this.event]=x;var k={class:f},E=!this.$scopedSlots.$hasNormal&&this.$scopedSlots.default&&this.$scopedSlots.default({href:u,route:s,navigate:x,isActive:f[m],isExactActive:f[g]});if(E){if(1===E.length)return E[0];if(E.length>1||!E.length)return 0===E.length?e():e("span",{},E)}if("a"===this.tag)k.on=R,k.attrs={href:u,"aria-current":b};else{var C=function t(e){var r;if(e)for(var n=0;n<e.length;n++){if("a"===(r=e[n]).tag)return r;if(r.children&&(r=t(r.children)))return r}}(this.$slots.default);if(C){C.isStatic=!1;var A=C.data=t({},C.data);for(var O in A.on=A.on||{},A.on){var _=A.on[O];O in R&&(A.on[O]=Array.isArray(_)?_:[_])}for(var j in R)j in A.on?A.on[j].push(R[j]):A.on[j]=x;var T=C.data.attrs=t({},C.data.attrs);T.href=u,T["aria-current"]=b}else k.on=R}return e(this.tag,k,this.$slots.default)}};function z(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){var e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}var K="undefined"!=typeof window;function D(t,e,r,n,o){var i=e||[],a=r||Object.create(null),s=n||Object.create(null);t.forEach((function(t){!function t(e,r,n,o,i,a){var s=o.path,u=o.name,c=o.pathToRegexpOptions||{},p=function(t,e,r){return r||(t=t.replace(/\/$/,"")),"/"===t[0]||null==e?t:x(e.path+"/"+t)}(s,i,c.strict);"boolean"==typeof o.caseSensitive&&(c.sensitive=o.caseSensitive);var f={path:p,regex:J(p,c),components:o.components||{default:o.component},alias:o.alias?"string"==typeof o.alias?[o.alias]:o.alias:[],instances:{},enteredCbs:{},name:u,parent:i,matchAs:a,redirect:o.redirect,beforeEnter:o.beforeEnter,meta:o.meta||{},props:null==o.props?{}:o.components?o.props:{default:o.props}};if(o.children&&o.children.forEach((function(o){var i=a?x(a+"/"+o.path):void 0;t(e,r,n,o,f,i)})),r[f.path]||(e.push(f.path),r[f.path]=f),void 0!==o.alias)for(var h=Array.isArray(o.alias)?o.alias:[o.alias],l=0;l<h.length;++l){var d={path:h[l],children:o.children};t(e,r,n,d,i,f.path||"/")}u&&(n[u]||(n[u]=f))}(i,a,s,t,o)}));for(var u=0,c=i.length;u<c;u++)"*"===i[u]&&(i.push(i.splice(u,1)[0]),c--,u--);return{pathList:i,pathMap:a,nameMap:s}}function J(t,e){return k(t,[],e)}function Q(t,e){var r=D(t),n=r.pathList,o=r.pathMap,i=r.nameMap;function a(t,r,a){var s=H(t,r,!1,e),c=s.name;if(c){var p=i[c];if(!p)return u(null,s);var f=p.regex.keys.filter((function(t){return!t.optional})).map((function(t){return t.name}));if("object"!=typeof s.params&&(s.params={}),r&&"object"==typeof r.params)for(var h in r.params)!(h in s.params)&&f.indexOf(h)>-1&&(s.params[h]=r.params[h]);return s.path=M(p.path,s.params),u(p,s,a)}if(s.path){s.params={};for(var l=0;l<n.length;l++){var d=n[l],v=o[d];if(X(v.regex,s.path,s.params))return u(v,s,a)}}return u(null,s)}function s(t,r){var n=t.redirect,o="function"==typeof n?n(p(t,r,null,e)):n;if("string"==typeof o&&(o={path:o}),!o||"object"!=typeof o)return u(null,r);var s=o,c=s.name,f=s.path,h=r.query,l=r.hash,d=r.params;return h=s.hasOwnProperty("query")?s.query:h,l=s.hasOwnProperty("hash")?s.hash:l,d=s.hasOwnProperty("params")?s.params:d,c?(i[c],a({_normalized:!0,name:c,query:h,hash:l,params:d},void 0,r)):f?a({_normalized:!0,path:M(function(t,e){return b(t,e.parent?e.parent.path:"/",!0)}(f,t),d),query:h,hash:l},void 0,r):u(null,r)}function u(t,r,n){return t&&t.redirect?s(t,n||r):t&&t.matchAs?function(t,e,r){var n=a({_normalized:!0,path:M(r,e.params)});if(n){var o=n.matched,i=o[o.length-1];return e.params=n.params,u(i,e)}return u(null,e)}(0,r,t.matchAs):p(t,r,n,e)}return{match:a,addRoute:function(t,e){var r="object"!=typeof t?i[t]:void 0;D([e||t],n,o,i,r),r&&r.alias.length&&D(r.alias.map((function(t){return{path:t,children:[e]}})),n,o,i,r)},getRoutes:function(){return n.map((function(t){return o[t]}))},addRoutes:function(t){D(t,n,o,i)}}}function X(t,e,r){var n=e.match(t);if(!n)return!1;if(!r)return!0;for(var o=1,a=n.length;o<a;++o){var s=t.keys[o-1];s&&(r[s.name||"pathMatch"]="string"==typeof n[o]?i(n[o]):n[o])}return!0}var Y=K&&window.performance&&window.performance.now?window.performance:Date;function W(){return Y.now().toFixed(3)}var G=W();function Z(){return G}function tt(t){return G=t}var et=Object.create(null);function rt(){"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual");var e=window.location.protocol+"//"+window.location.host,r=window.location.href.replace(e,""),n=t({},window.history.state);return n.key=Z(),window.history.replaceState(n,"",r),window.addEventListener("popstate",it),function(){window.removeEventListener("popstate",it)}}function nt(t,e,r,n){if(t.app){var o=t.options.scrollBehavior;o&&t.app.$nextTick((function(){var i=function(){var t=Z();if(t)return et[t]}(),a=o.call(t,e,r,n?i:null);a&&("function"==typeof a.then?a.then((function(t){pt(t,i)})).catch((function(t){})):pt(a,i))}))}}function ot(){var t=Z();t&&(et[t]={x:window.pageXOffset,y:window.pageYOffset})}function it(t){ot(),t.state&&t.state.key&&tt(t.state.key)}function at(t){return ut(t.x)||ut(t.y)}function st(t){return{x:ut(t.x)?t.x:window.pageXOffset,y:ut(t.y)?t.y:window.pageYOffset}}function ut(t){return"number"==typeof t}var ct=/^#\d/;function pt(t,e){var r,n="object"==typeof t;if(n&&"string"==typeof t.selector){var o=ct.test(t.selector)?document.getElementById(t.selector.slice(1)):document.querySelector(t.selector);if(o){var i=t.offset&&"object"==typeof t.offset?t.offset:{};e=function(t,e){var r=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-r.left-e.x,y:n.top-r.top-e.y}}(o,i={x:ut((r=i).x)?r.x:0,y:ut(r.y)?r.y:0})}else at(t)&&(e=st(t))}else n&&at(t)&&(e=st(t));e&&("scrollBehavior"in document.documentElement.style?window.scrollTo({left:e.x,top:e.y,behavior:t.behavior}):window.scrollTo(e.x,e.y))}var ft,ht=K&&(-1===(ft=window.navigator.userAgent).indexOf("Android 2.")&&-1===ft.indexOf("Android 4.0")||-1===ft.indexOf("Mobile Safari")||-1!==ft.indexOf("Chrome")||-1!==ft.indexOf("Windows Phone"))&&window.history&&"function"==typeof window.history.pushState;function lt(e,r){ot();var n=window.history;try{if(r){var o=t({},n.state);o.key=Z(),n.replaceState(o,"",e)}else n.pushState({key:tt(W())},"",e)}catch(t){window.location[r?"replace":"assign"](e)}}function dt(t){lt(t,!0)}function vt(t,e,r){var n=function(o){o>=t.length?r():t[o]?e(t[o],(function(){n(o+1)})):n(o+1)};n(0)}var yt={redirected:2,aborted:4,cancelled:8,duplicated:16};function mt(t,e){return wt(t,e,yt.redirected,'Redirected when going from "'+t.fullPath+'" to "'+function(t){if("string"==typeof t)return t;if("path"in t)return t.path;var e={};return bt.forEach((function(r){r in t&&(e[r]=t[r])})),JSON.stringify(e,null,2)}(e)+'" via a navigation guard.')}function gt(t,e){return wt(t,e,yt.cancelled,'Navigation cancelled from "'+t.fullPath+'" to "'+e.fullPath+'" with a new navigation.')}function wt(t,e,r,n){var o=new Error(n);return o._isRouter=!0,o.from=t,o.to=e,o.type=r,o}var bt=["params","query","hash"];function xt(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function Rt(t,e){return xt(t)&&t._isRouter&&(null==e||t.type===e)}function kt(t){return function(e,r,n){var o=!1,i=0,a=null;Et(t,(function(t,e,r,s){if("function"==typeof t&&void 0===t.cid){o=!0,i++;var u,c=Ot((function(e){var o;((o=e).__esModule||At&&"Module"===o[Symbol.toStringTag])&&(e=e.default),t.resolved="function"==typeof e?e:N.extend(e),r.components[s]=e,--i<=0&&n()})),p=Ot((function(t){var e="Failed to resolve async component "+s+": "+t;a||(a=xt(t)?t:new Error(e),n(a))}));try{u=t(c,p)}catch(t){p(t)}if(u)if("function"==typeof u.then)u.then(c,p);else{var f=u.component;f&&"function"==typeof f.then&&f.then(c,p)}}})),o||n()}}function Et(t,e){return Ct(t.map((function(t){return Object.keys(t.components).map((function(r){return e(t.components[r],t.instances[r],t,r)}))})))}function Ct(t){return Array.prototype.concat.apply([],t)}var At="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function Ot(t){var e=!1;return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if(!e)return e=!0,t.apply(this,r)}}var _t=function(t,e){this.router=t,this.base=function(t){if(!t)if(K){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}(e),this.current=h,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[],this.listeners=[]};function jt(t,e,r,n){var o=Et(t,(function(t,n,o,i){var a=function(t,e){return"function"!=typeof t&&(t=N.extend(t)),t.options[e]}(t,e);if(a)return Array.isArray(a)?a.map((function(t){return r(t,n,o,i)})):r(a,n,o,i)}));return Ct(n?o.reverse():o)}function Tt(t,e){if(e)return function(){return t.apply(e,arguments)}}_t.prototype.listen=function(t){this.cb=t},_t.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},_t.prototype.onError=function(t){this.errorCbs.push(t)},_t.prototype.transitionTo=function(t,e,r){var n,o=this;try{n=this.router.match(t,this.current)}catch(t){throw this.errorCbs.forEach((function(e){e(t)})),t}var i=this.current;this.confirmTransition(n,(function(){o.updateRoute(n),e&&e(n),o.ensureURL(),o.router.afterHooks.forEach((function(t){t&&t(n,i)})),o.ready||(o.ready=!0,o.readyCbs.forEach((function(t){t(n)})))}),(function(t){r&&r(t),t&&!o.ready&&(Rt(t,yt.redirected)&&i===h||(o.ready=!0,o.readyErrorCbs.forEach((function(e){e(t)}))))}))},_t.prototype.confirmTransition=function(t,e,r){var n=this,o=this.current;this.pending=t;var i,a,s=function(t){!Rt(t)&&xt(t)&&(n.errorCbs.length?n.errorCbs.forEach((function(e){e(t)})):console.error(t)),r&&r(t)},u=t.matched.length-1,c=o.matched.length-1;if(v(t,o)&&u===c&&t.matched[u]===o.matched[c])return this.ensureURL(),t.hash&&nt(this.router,o,t,!1),s(((a=wt(i=o,t,yt.duplicated,'Avoided redundant navigation to current location: "'+i.fullPath+'".')).name="NavigationDuplicated",a));var p=function(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r<n&&t[r]===e[r];r++);return{updated:e.slice(0,r),activated:e.slice(r),deactivated:t.slice(r)}}(this.current.matched,t.matched),f=p.updated,h=p.deactivated,l=p.activated,d=[].concat(function(t){return jt(t,"beforeRouteLeave",Tt,!0)}(h),this.router.beforeHooks,function(t){return jt(t,"beforeRouteUpdate",Tt)}(f),l.map((function(t){return t.beforeEnter})),kt(l)),y=function(e,r){if(n.pending!==t)return s(gt(o,t));try{e(t,o,(function(e){!1===e?(n.ensureURL(!0),s(function(t,e){return wt(t,e,yt.aborted,'Navigation aborted from "'+t.fullPath+'" to "'+e.fullPath+'" via a navigation guard.')}(o,t))):xt(e)?(n.ensureURL(!0),s(e)):"string"==typeof e||"object"==typeof e&&("string"==typeof e.path||"string"==typeof e.name)?(s(mt(o,t)),"object"==typeof e&&e.replace?n.replace(e):n.push(e)):r(e)}))}catch(t){s(t)}};vt(d,y,(function(){vt(function(t){return jt(t,"beforeRouteEnter",(function(t,e,r,n){return function(t,e,r){return function(n,o,i){return t(n,o,(function(t){"function"==typeof t&&(e.enteredCbs[r]||(e.enteredCbs[r]=[]),e.enteredCbs[r].push(t)),i(t)}))}}(t,r,n)}))}(l).concat(n.router.resolveHooks),y,(function(){if(n.pending!==t)return s(gt(o,t));n.pending=null,e(t),n.router.app&&n.router.app.$nextTick((function(){m(t)}))}))}))},_t.prototype.updateRoute=function(t){this.current=t,this.cb&&this.cb(t)},_t.prototype.setupListeners=function(){},_t.prototype.teardown=function(){this.listeners.forEach((function(t){t()})),this.listeners=[],this.current=h,this.pending=null};var St=function(t){function e(e,r){t.call(this,e,r),this._startLocation=Pt(this.base)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this;if(!(this.listeners.length>0)){var e=this.router,r=e.options.scrollBehavior,n=ht&&r;n&&this.listeners.push(rt());var o=function(){var r=t.current,o=Pt(t.base);t.current===h&&o===t._startLocation||t.transitionTo(o,(function(t){n&&nt(e,t,r,!0)}))};window.addEventListener("popstate",o),this.listeners.push((function(){window.removeEventListener("popstate",o)}))}},e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,(function(t){lt(x(n.base+t.fullPath)),nt(n.router,t,o,!1),e&&e(t)}),r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,(function(t){dt(x(n.base+t.fullPath)),nt(n.router,t,o,!1),e&&e(t)}),r)},e.prototype.ensureURL=function(t){if(Pt(this.base)!==this.current.fullPath){var e=x(this.base+this.current.fullPath);t?lt(e):dt(e)}},e.prototype.getCurrentLocation=function(){return Pt(this.base)},e}(_t);function Pt(t){var e=window.location.pathname,r=e.toLowerCase(),n=t.toLowerCase();return!t||r!==n&&0!==r.indexOf(x(n+"/"))||(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}var Lt=function(t){function e(e,r,n){t.call(this,e,r),n&&function(t){var e=Pt(t);if(!/^\/#/.test(e))return window.location.replace(x(t+"/#"+e)),!0}(this.base)||$t()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this;if(!(this.listeners.length>0)){var e=this.router.options.scrollBehavior,r=ht&&e;r&&this.listeners.push(rt());var n=function(){var e=t.current;$t()&&t.transitionTo(qt(),(function(n){r&&nt(t.router,n,e,!0),ht||It(n.fullPath)}))},o=ht?"popstate":"hashchange";window.addEventListener(o,n),this.listeners.push((function(){window.removeEventListener(o,n)}))}},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,(function(t){Bt(t.fullPath),nt(n.router,t,o,!1),e&&e(t)}),r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,(function(t){It(t.fullPath),nt(n.router,t,o,!1),e&&e(t)}),r)},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(t){var e=this.current.fullPath;qt()!==e&&(t?Bt(e):It(e))},e.prototype.getCurrentLocation=function(){return qt()},e}(_t);function $t(){var t=qt();return"/"===t.charAt(0)||(It("/"+t),!1)}function qt(){var t=window.location.href,e=t.indexOf("#");return e<0?"":t=t.slice(e+1)}function Ut(t){var e=window.location.href,r=e.indexOf("#");return(r>=0?e.slice(0,r):e)+"#"+t}function Bt(t){ht?lt(Ut(t)):window.location.hash=t}function It(t){ht?dt(Ut(t)):window.location.replace(Ut(t))}var Mt=function(t){function e(e,r){t.call(this,e,r),this.stack=[],this.index=-1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(t,e,r){var n=this;this.transitionTo(t,(function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++,e&&e(t)}),r)},e.prototype.replace=function(t,e,r){var n=this;this.transitionTo(t,(function(t){n.stack=n.stack.slice(0,n.index).concat(t),e&&e(t)}),r)},e.prototype.go=function(t){var e=this,r=this.index+t;if(!(r<0||r>=this.stack.length)){var n=this.stack[r];this.confirmTransition(n,(function(){var t=e.current;e.index=r,e.updateRoute(n),e.router.afterHooks.forEach((function(e){e&&e(n,t)}))}),(function(t){Rt(t,yt.duplicated)&&(e.index=r)}))}},e.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},e.prototype.ensureURL=function(){},e}(_t),Ht=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=Q(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!ht&&!1!==t.fallback,this.fallback&&(e="hash"),K||(e="abstract"),this.mode=e,e){case"history":this.history=new St(this,t.base);break;case"hash":this.history=new Lt(this,t.base,this.fallback);break;case"abstract":this.history=new Mt(this,t.base)}},Nt={currentRoute:{configurable:!0}};function Ft(t,e){return t.push(e),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}return Ht.prototype.match=function(t,e,r){return this.matcher.match(t,e,r)},Nt.currentRoute.get=function(){return this.history&&this.history.current},Ht.prototype.init=function(t){var e=this;if(this.apps.push(t),t.$once("hook:destroyed",(function(){var r=e.apps.indexOf(t);r>-1&&e.apps.splice(r,1),e.app===t&&(e.app=e.apps[0]||null),e.app||e.history.teardown()})),!this.app){this.app=t;var r=this.history;if(r instanceof St||r instanceof Lt){var n=function(t){r.setupListeners(),function(t){var n=r.current,o=e.options.scrollBehavior;ht&&o&&"fullPath"in t&&nt(e,t,n,!1)}(t)};r.transitionTo(r.getCurrentLocation(),n,n)}r.listen((function(t){e.apps.forEach((function(e){e._route=t}))}))}},Ht.prototype.beforeEach=function(t){return Ft(this.beforeHooks,t)},Ht.prototype.beforeResolve=function(t){return Ft(this.resolveHooks,t)},Ht.prototype.afterEach=function(t){return Ft(this.afterHooks,t)},Ht.prototype.onReady=function(t,e){this.history.onReady(t,e)},Ht.prototype.onError=function(t){this.history.onError(t)},Ht.prototype.push=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise((function(e,r){n.history.push(t,e,r)}));this.history.push(t,e,r)},Ht.prototype.replace=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise((function(e,r){n.history.replace(t,e,r)}));this.history.replace(t,e,r)},Ht.prototype.go=function(t){this.history.go(t)},Ht.prototype.back=function(){this.go(-1)},Ht.prototype.forward=function(){this.go(1)},Ht.prototype.getMatchedComponents=function(t){var e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map((function(t){return Object.keys(t.components).map((function(e){return t.components[e]}))}))):[]},Ht.prototype.resolve=function(t,e,r){var n=H(t,e=e||this.history.current,r,this),o=this.match(n,e),i=o.redirectedFrom||o.fullPath;return{location:n,route:o,href:function(t,e,r){var n="hash"===r?"#"+e:e;return t?x(t+"/"+n):n}(this.history.base,i,this.mode),normalizedTo:n,resolved:o}},Ht.prototype.getRoutes=function(){return this.matcher.getRoutes()},Ht.prototype.addRoute=function(t,e){this.matcher.addRoute(t,e),this.history.current!==h&&this.history.transitionTo(this.history.getCurrentLocation())},Ht.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==h&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(Ht.prototype,Nt),Ht.install=function t(e){if(!t.installed||N!==e){t.installed=!0,N=e;var r=function(t){return void 0!==t},n=function(t,e){var n=t.$options._parentKnode;r(n)&&r(n=n.data)&&r(n=n.registerRouteInstance)&&n(t,e)};e.mixin({beforeCreate:function(){r(this.$options.router)?(this._routerRoot=this,this._router=this.$options.router,this._router.init(this),e.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,n(this,this)},destroyed:function(){n(this)}}),Object.defineProperty(e.prototype,"$router",{get:function(){return this._routerRoot._router}}),Object.defineProperty(e.prototype,"$route",{get:function(){return this._routerRoot._route}}),e.component("RouterView",g),e.component("RouterLink",V);var o=e.config.optionMergeStrategies;o.beforeRouteEnter=o.beforeRouteLeave=o.beforeRouteUpdate=o.created}},Ht.version="3.5.4",Ht.isNavigationFailure=Rt,Ht.NavigationFailureType=yt,Ht.START_LOCATION=h,K&&window.Kdu&&window.Kdu.use(Ht),Ht},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).KduRouter=e();
|
package/src/components/link.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import { createRoute, isSameRoute, isIncludedRoute } from '../util/route'
|
|
4
|
-
import { extend } from '../util/misc'
|
|
5
|
-
import { normalizeLocation } from '../util/location'
|
|
6
|
-
import { warn } from '../util/warn'
|
|
7
|
-
|
|
8
|
-
// work around weird flow bug
|
|
9
|
-
const toTypes: Array<Function> = [String, Object]
|
|
10
|
-
const eventTypes: Array<Function> = [String, Array]
|
|
11
|
-
|
|
12
|
-
const noop = () => {}
|
|
13
|
-
|
|
14
|
-
let warnedCustomSlot
|
|
15
|
-
let warnedTagProp
|
|
16
|
-
let warnedEventProp
|
|
17
|
-
|
|
18
|
-
export default {
|
|
19
|
-
name: 'RouterLink',
|
|
20
|
-
props: {
|
|
21
|
-
to: {
|
|
22
|
-
type: toTypes,
|
|
23
|
-
required: true
|
|
24
|
-
},
|
|
25
|
-
tag: {
|
|
26
|
-
type: String,
|
|
27
|
-
default: 'a'
|
|
28
|
-
},
|
|
29
|
-
custom: Boolean,
|
|
30
|
-
exact: Boolean,
|
|
31
|
-
exactPath: Boolean,
|
|
32
|
-
append: Boolean,
|
|
33
|
-
replace: Boolean,
|
|
34
|
-
activeClass: String,
|
|
35
|
-
exactActiveClass: String,
|
|
36
|
-
ariaCurrentValue: {
|
|
37
|
-
type: String,
|
|
38
|
-
default: 'page'
|
|
39
|
-
},
|
|
40
|
-
event: {
|
|
41
|
-
type: eventTypes,
|
|
42
|
-
default: 'click'
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
render (h: Function) {
|
|
46
|
-
const router = this.$router
|
|
47
|
-
const current = this.$route
|
|
48
|
-
const { location, route, href } = router.resolve(
|
|
49
|
-
this.to,
|
|
50
|
-
current,
|
|
51
|
-
this.append
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
const classes = {}
|
|
55
|
-
const globalActiveClass = router.options.linkActiveClass
|
|
56
|
-
const globalExactActiveClass = router.options.linkExactActiveClass
|
|
57
|
-
// Support global empty active class
|
|
58
|
-
const activeClassFallback =
|
|
59
|
-
globalActiveClass == null ? 'router-link-active' : globalActiveClass
|
|
60
|
-
const exactActiveClassFallback =
|
|
61
|
-
globalExactActiveClass == null
|
|
62
|
-
? 'router-link-exact-active'
|
|
63
|
-
: globalExactActiveClass
|
|
64
|
-
const activeClass =
|
|
65
|
-
this.activeClass == null ? activeClassFallback : this.activeClass
|
|
66
|
-
const exactActiveClass =
|
|
67
|
-
this.exactActiveClass == null
|
|
68
|
-
? exactActiveClassFallback
|
|
69
|
-
: this.exactActiveClass
|
|
70
|
-
|
|
71
|
-
const compareTarget = route.redirectedFrom
|
|
72
|
-
? createRoute(null, normalizeLocation(route.redirectedFrom), null, router)
|
|
73
|
-
: route
|
|
74
|
-
|
|
75
|
-
classes[exactActiveClass] = isSameRoute(current, compareTarget, this.exactPath)
|
|
76
|
-
classes[activeClass] = this.exact || this.exactPath
|
|
77
|
-
? classes[exactActiveClass]
|
|
78
|
-
: isIncludedRoute(current, compareTarget)
|
|
79
|
-
|
|
80
|
-
const ariaCurrentValue = classes[exactActiveClass] ? this.ariaCurrentValue : null
|
|
81
|
-
|
|
82
|
-
const handler = e => {
|
|
83
|
-
if (guardEvent(e)) {
|
|
84
|
-
if (this.replace) {
|
|
85
|
-
router.replace(location, noop)
|
|
86
|
-
} else {
|
|
87
|
-
router.push(location, noop)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const on = { click: guardEvent }
|
|
93
|
-
if (Array.isArray(this.event)) {
|
|
94
|
-
this.event.forEach(e => {
|
|
95
|
-
on[e] = handler
|
|
96
|
-
})
|
|
97
|
-
} else {
|
|
98
|
-
on[this.event] = handler
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const data: any = { class: classes }
|
|
102
|
-
|
|
103
|
-
const scopedSlot =
|
|
104
|
-
!this.$scopedSlots.$hasNormal &&
|
|
105
|
-
this.$scopedSlots.default &&
|
|
106
|
-
this.$scopedSlots.default({
|
|
107
|
-
href,
|
|
108
|
-
route,
|
|
109
|
-
navigate: handler,
|
|
110
|
-
isActive: classes[activeClass],
|
|
111
|
-
isExactActive: classes[exactActiveClass]
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
if (scopedSlot) {
|
|
115
|
-
if (process.env.NODE_ENV !== 'production' && !this.custom) {
|
|
116
|
-
!warnedCustomSlot && warn(false, 'In Kdu Router 4, the k-slot API will by default wrap its content with an <a> element. Use the custom prop to remove this warning:\n<router-link k-slot="{ navigate, href }" custom></router-link>\n')
|
|
117
|
-
warnedCustomSlot = true
|
|
118
|
-
}
|
|
119
|
-
if (scopedSlot.length === 1) {
|
|
120
|
-
return scopedSlot[0]
|
|
121
|
-
} else if (scopedSlot.length > 1 || !scopedSlot.length) {
|
|
122
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
123
|
-
warn(
|
|
124
|
-
false,
|
|
125
|
-
`<router-link> with to="${
|
|
126
|
-
this.to
|
|
127
|
-
}" is trying to use a scoped slot but it didn't provide exactly one child. Wrapping the content with a span element.`
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
return scopedSlot.length === 0 ? h() : h('span', {}, scopedSlot)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
135
|
-
if ('tag' in this.$options.propsData && !warnedTagProp) {
|
|
136
|
-
warn(
|
|
137
|
-
false,
|
|
138
|
-
`<router-link>'s tag prop is deprecated and has been removed in Kdu Router 4. Use the k-slot API to remove this warning: https://kdujs-router.web.app/guide/migration/#removal-of-event-and-tag-props-in-router-link.`
|
|
139
|
-
)
|
|
140
|
-
warnedTagProp = true
|
|
141
|
-
}
|
|
142
|
-
if ('event' in this.$options.propsData && !warnedEventProp) {
|
|
143
|
-
warn(
|
|
144
|
-
false,
|
|
145
|
-
`<router-link>'s event prop is deprecated and has been removed in Kdu Router 4. Use the k-slot API to remove this warning: https://kdujs-router.web.app/guide/migration/#removal-of-event-and-tag-props-in-router-link.`
|
|
146
|
-
)
|
|
147
|
-
warnedEventProp = true
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (this.tag === 'a') {
|
|
152
|
-
data.on = on
|
|
153
|
-
data.attrs = { href, 'aria-current': ariaCurrentValue }
|
|
154
|
-
} else {
|
|
155
|
-
// find the first <a> child and apply listener and href
|
|
156
|
-
const a = findAnchor(this.$slots.default)
|
|
157
|
-
if (a) {
|
|
158
|
-
// in case the <a> is a static node
|
|
159
|
-
a.isStatic = false
|
|
160
|
-
const aData = (a.data = extend({}, a.data))
|
|
161
|
-
aData.on = aData.on || {}
|
|
162
|
-
// transform existing events in both objects into arrays so we can push later
|
|
163
|
-
for (const event in aData.on) {
|
|
164
|
-
const handler = aData.on[event]
|
|
165
|
-
if (event in on) {
|
|
166
|
-
aData.on[event] = Array.isArray(handler) ? handler : [handler]
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
// append new listeners for router-link
|
|
170
|
-
for (const event in on) {
|
|
171
|
-
if (event in aData.on) {
|
|
172
|
-
// on[event] is always a function
|
|
173
|
-
aData.on[event].push(on[event])
|
|
174
|
-
} else {
|
|
175
|
-
aData.on[event] = handler
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const aAttrs = (a.data.attrs = extend({}, a.data.attrs))
|
|
180
|
-
aAttrs.href = href
|
|
181
|
-
aAttrs['aria-current'] = ariaCurrentValue
|
|
182
|
-
} else {
|
|
183
|
-
// doesn't have <a> child, apply listener to self
|
|
184
|
-
data.on = on
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return h(this.tag, data, this.$slots.default)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function guardEvent (e) {
|
|
193
|
-
// don't redirect with control keys
|
|
194
|
-
if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return
|
|
195
|
-
// don't redirect when preventDefault called
|
|
196
|
-
if (e.defaultPrevented) return
|
|
197
|
-
// don't redirect on right click
|
|
198
|
-
if (e.button !== undefined && e.button !== 0) return
|
|
199
|
-
// don't redirect if `target="_blank"`
|
|
200
|
-
if (e.currentTarget && e.currentTarget.getAttribute) {
|
|
201
|
-
const target = e.currentTarget.getAttribute('target')
|
|
202
|
-
if (/\b_blank\b/i.test(target)) return
|
|
203
|
-
}
|
|
204
|
-
// this may be a Weex event which doesn't have this method
|
|
205
|
-
if (e.preventDefault) {
|
|
206
|
-
e.preventDefault()
|
|
207
|
-
}
|
|
208
|
-
return true
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function findAnchor (children) {
|
|
212
|
-
if (children) {
|
|
213
|
-
let child
|
|
214
|
-
for (let i = 0; i < children.length; i++) {
|
|
215
|
-
child = children[i]
|
|
216
|
-
if (child.tag === 'a') {
|
|
217
|
-
return child
|
|
218
|
-
}
|
|
219
|
-
if (child.children && (child = findAnchor(child.children))) {
|
|
220
|
-
return child
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
package/src/components/view.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { warn } from '../util/warn'
|
|
2
|
-
import { extend } from '../util/misc'
|
|
3
|
-
import { handleRouteEntered } from '../util/route'
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
name: 'RouterView',
|
|
7
|
-
functional: true,
|
|
8
|
-
props: {
|
|
9
|
-
name: {
|
|
10
|
-
type: String,
|
|
11
|
-
default: 'default'
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
render (_, { props, children, parent, data }) {
|
|
15
|
-
// used by devtools to display a router-view badge
|
|
16
|
-
data.routerView = true
|
|
17
|
-
|
|
18
|
-
// directly use parent context's createElement() function
|
|
19
|
-
// so that components rendered by router-view can resolve named slots
|
|
20
|
-
const h = parent.$createElement
|
|
21
|
-
const name = props.name
|
|
22
|
-
const route = parent.$route
|
|
23
|
-
const cache = parent._routerViewCache || (parent._routerViewCache = {})
|
|
24
|
-
|
|
25
|
-
// determine current view depth, also check to see if the tree
|
|
26
|
-
// has been toggled inactive but kept-alive.
|
|
27
|
-
let depth = 0
|
|
28
|
-
let inactive = false
|
|
29
|
-
while (parent && parent._routerRoot !== parent) {
|
|
30
|
-
const knodeData = parent.$knode ? parent.$knode.data : {}
|
|
31
|
-
if (knodeData.routerView) {
|
|
32
|
-
depth++
|
|
33
|
-
}
|
|
34
|
-
if (knodeData.keepAlive && parent._directInactive && parent._inactive) {
|
|
35
|
-
inactive = true
|
|
36
|
-
}
|
|
37
|
-
parent = parent.$parent
|
|
38
|
-
}
|
|
39
|
-
data.routerViewDepth = depth
|
|
40
|
-
|
|
41
|
-
// render previous view if the tree is inactive and kept-alive
|
|
42
|
-
if (inactive) {
|
|
43
|
-
const cachedData = cache[name]
|
|
44
|
-
const cachedComponent = cachedData && cachedData.component
|
|
45
|
-
if (cachedComponent) {
|
|
46
|
-
// #2301
|
|
47
|
-
// pass props
|
|
48
|
-
if (cachedData.configProps) {
|
|
49
|
-
fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps)
|
|
50
|
-
}
|
|
51
|
-
return h(cachedComponent, data, children)
|
|
52
|
-
} else {
|
|
53
|
-
// render previous empty view
|
|
54
|
-
return h()
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const matched = route.matched[depth]
|
|
59
|
-
const component = matched && matched.components[name]
|
|
60
|
-
|
|
61
|
-
// render empty node if no matched route or no config component
|
|
62
|
-
if (!matched || !component) {
|
|
63
|
-
cache[name] = null
|
|
64
|
-
return h()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// cache component
|
|
68
|
-
cache[name] = { component }
|
|
69
|
-
|
|
70
|
-
// attach instance registration hook
|
|
71
|
-
// this will be called in the instance's injected lifecycle hooks
|
|
72
|
-
data.registerRouteInstance = (vm, val) => {
|
|
73
|
-
// val could be undefined for unregistration
|
|
74
|
-
const current = matched.instances[name]
|
|
75
|
-
if (
|
|
76
|
-
(val && current !== vm) ||
|
|
77
|
-
(!val && current === vm)
|
|
78
|
-
) {
|
|
79
|
-
matched.instances[name] = val
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// also register instance in prepatch hook
|
|
84
|
-
// in case the same component instance is reused across different routes
|
|
85
|
-
;(data.hook || (data.hook = {})).prepatch = (_, knode) => {
|
|
86
|
-
matched.instances[name] = knode.componentInstance
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// register instance in init hook
|
|
90
|
-
// in case kept-alive component be actived when routes changed
|
|
91
|
-
data.hook.init = (knode) => {
|
|
92
|
-
if (knode.data.keepAlive &&
|
|
93
|
-
knode.componentInstance &&
|
|
94
|
-
knode.componentInstance !== matched.instances[name]
|
|
95
|
-
) {
|
|
96
|
-
matched.instances[name] = knode.componentInstance
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// if the route transition has already been confirmed then we weren't
|
|
100
|
-
// able to call the cbs during confirmation as the component was not
|
|
101
|
-
// registered yet, so we call it here.
|
|
102
|
-
handleRouteEntered(route)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const configProps = matched.props && matched.props[name]
|
|
106
|
-
// save route and configProps in cache
|
|
107
|
-
if (configProps) {
|
|
108
|
-
extend(cache[name], {
|
|
109
|
-
route,
|
|
110
|
-
configProps
|
|
111
|
-
})
|
|
112
|
-
fillPropsinData(component, data, route, configProps)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return h(component, data, children)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function fillPropsinData (component, data, route, configProps) {
|
|
120
|
-
// resolve props
|
|
121
|
-
let propsToPass = data.props = resolveProps(route, configProps)
|
|
122
|
-
if (propsToPass) {
|
|
123
|
-
// clone to prevent mutation
|
|
124
|
-
propsToPass = data.props = extend({}, propsToPass)
|
|
125
|
-
// pass non-declared props as attrs
|
|
126
|
-
const attrs = data.attrs = data.attrs || {}
|
|
127
|
-
for (const key in propsToPass) {
|
|
128
|
-
if (!component.props || !(key in component.props)) {
|
|
129
|
-
attrs[key] = propsToPass[key]
|
|
130
|
-
delete propsToPass[key]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function resolveProps (route, config) {
|
|
137
|
-
switch (typeof config) {
|
|
138
|
-
case 'undefined':
|
|
139
|
-
return
|
|
140
|
-
case 'object':
|
|
141
|
-
return config
|
|
142
|
-
case 'function':
|
|
143
|
-
return config(route)
|
|
144
|
-
case 'boolean':
|
|
145
|
-
return config ? route.params : undefined
|
|
146
|
-
default:
|
|
147
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
148
|
-
warn(
|
|
149
|
-
false,
|
|
150
|
-
`props in "${route.path}" is a ${typeof config}, ` +
|
|
151
|
-
`expecting an object, function or boolean.`
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
package/src/create-matcher.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import type KduRouter from './index'
|
|
4
|
-
import { resolvePath } from './util/path'
|
|
5
|
-
import { assert, warn } from './util/warn'
|
|
6
|
-
import { createRoute } from './util/route'
|
|
7
|
-
import { fillParams } from './util/params'
|
|
8
|
-
import { createRouteMap } from './create-route-map'
|
|
9
|
-
import { normalizeLocation } from './util/location'
|
|
10
|
-
import { decode } from './util/query'
|
|
11
|
-
|
|
12
|
-
export type Matcher = {
|
|
13
|
-
match: (raw: RawLocation, current?: Route, redirectedFrom?: Location) => Route;
|
|
14
|
-
addRoutes: (routes: Array<RouteConfig>) => void;
|
|
15
|
-
addRoute: (parentNameOrRoute: string | RouteConfig, route?: RouteConfig) => void;
|
|
16
|
-
getRoutes: () => Array<RouteRecord>;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function createMatcher (
|
|
20
|
-
routes: Array<RouteConfig>,
|
|
21
|
-
router: KduRouter
|
|
22
|
-
): Matcher {
|
|
23
|
-
const { pathList, pathMap, nameMap } = createRouteMap(routes)
|
|
24
|
-
|
|
25
|
-
function addRoutes (routes) {
|
|
26
|
-
createRouteMap(routes, pathList, pathMap, nameMap)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function addRoute (parentOrRoute, route) {
|
|
30
|
-
const parent = (typeof parentOrRoute !== 'object') ? nameMap[parentOrRoute] : undefined
|
|
31
|
-
// $flow-disable-line
|
|
32
|
-
createRouteMap([route || parentOrRoute], pathList, pathMap, nameMap, parent)
|
|
33
|
-
|
|
34
|
-
// add aliases of parent
|
|
35
|
-
if (parent && parent.alias.length) {
|
|
36
|
-
createRouteMap(
|
|
37
|
-
// $flow-disable-line route is defined if parent is
|
|
38
|
-
parent.alias.map(alias => ({ path: alias, children: [route] })),
|
|
39
|
-
pathList,
|
|
40
|
-
pathMap,
|
|
41
|
-
nameMap,
|
|
42
|
-
parent
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getRoutes () {
|
|
48
|
-
return pathList.map(path => pathMap[path])
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function match (
|
|
52
|
-
raw: RawLocation,
|
|
53
|
-
currentRoute?: Route,
|
|
54
|
-
redirectedFrom?: Location
|
|
55
|
-
): Route {
|
|
56
|
-
const location = normalizeLocation(raw, currentRoute, false, router)
|
|
57
|
-
const { name } = location
|
|
58
|
-
|
|
59
|
-
if (name) {
|
|
60
|
-
const record = nameMap[name]
|
|
61
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
62
|
-
warn(record, `Route with name '${name}' does not exist`)
|
|
63
|
-
}
|
|
64
|
-
if (!record) return _createRoute(null, location)
|
|
65
|
-
const paramNames = record.regex.keys
|
|
66
|
-
.filter(key => !key.optional)
|
|
67
|
-
.map(key => key.name)
|
|
68
|
-
|
|
69
|
-
if (typeof location.params !== 'object') {
|
|
70
|
-
location.params = {}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (currentRoute && typeof currentRoute.params === 'object') {
|
|
74
|
-
for (const key in currentRoute.params) {
|
|
75
|
-
if (!(key in location.params) && paramNames.indexOf(key) > -1) {
|
|
76
|
-
location.params[key] = currentRoute.params[key]
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
location.path = fillParams(record.path, location.params, `named route "${name}"`)
|
|
82
|
-
return _createRoute(record, location, redirectedFrom)
|
|
83
|
-
} else if (location.path) {
|
|
84
|
-
location.params = {}
|
|
85
|
-
for (let i = 0; i < pathList.length; i++) {
|
|
86
|
-
const path = pathList[i]
|
|
87
|
-
const record = pathMap[path]
|
|
88
|
-
if (matchRoute(record.regex, location.path, location.params)) {
|
|
89
|
-
return _createRoute(record, location, redirectedFrom)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// no match
|
|
94
|
-
return _createRoute(null, location)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function redirect (
|
|
98
|
-
record: RouteRecord,
|
|
99
|
-
location: Location
|
|
100
|
-
): Route {
|
|
101
|
-
const originalRedirect = record.redirect
|
|
102
|
-
let redirect = typeof originalRedirect === 'function'
|
|
103
|
-
? originalRedirect(createRoute(record, location, null, router))
|
|
104
|
-
: originalRedirect
|
|
105
|
-
|
|
106
|
-
if (typeof redirect === 'string') {
|
|
107
|
-
redirect = { path: redirect }
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!redirect || typeof redirect !== 'object') {
|
|
111
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
112
|
-
warn(
|
|
113
|
-
false, `invalid redirect option: ${JSON.stringify(redirect)}`
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
return _createRoute(null, location)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const re: Object = redirect
|
|
120
|
-
const { name, path } = re
|
|
121
|
-
let { query, hash, params } = location
|
|
122
|
-
query = re.hasOwnProperty('query') ? re.query : query
|
|
123
|
-
hash = re.hasOwnProperty('hash') ? re.hash : hash
|
|
124
|
-
params = re.hasOwnProperty('params') ? re.params : params
|
|
125
|
-
|
|
126
|
-
if (name) {
|
|
127
|
-
// resolved named direct
|
|
128
|
-
const targetRecord = nameMap[name]
|
|
129
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
130
|
-
assert(targetRecord, `redirect failed: named route "${name}" not found.`)
|
|
131
|
-
}
|
|
132
|
-
return match({
|
|
133
|
-
_normalized: true,
|
|
134
|
-
name,
|
|
135
|
-
query,
|
|
136
|
-
hash,
|
|
137
|
-
params
|
|
138
|
-
}, undefined, location)
|
|
139
|
-
} else if (path) {
|
|
140
|
-
// 1. resolve relative redirect
|
|
141
|
-
const rawPath = resolveRecordPath(path, record)
|
|
142
|
-
// 2. resolve params
|
|
143
|
-
const resolvedPath = fillParams(rawPath, params, `redirect route with path "${rawPath}"`)
|
|
144
|
-
// 3. rematch with existing query and hash
|
|
145
|
-
return match({
|
|
146
|
-
_normalized: true,
|
|
147
|
-
path: resolvedPath,
|
|
148
|
-
query,
|
|
149
|
-
hash
|
|
150
|
-
}, undefined, location)
|
|
151
|
-
} else {
|
|
152
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
153
|
-
warn(false, `invalid redirect option: ${JSON.stringify(redirect)}`)
|
|
154
|
-
}
|
|
155
|
-
return _createRoute(null, location)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function alias (
|
|
160
|
-
record: RouteRecord,
|
|
161
|
-
location: Location,
|
|
162
|
-
matchAs: string
|
|
163
|
-
): Route {
|
|
164
|
-
const aliasedPath = fillParams(matchAs, location.params, `aliased route with path "${matchAs}"`)
|
|
165
|
-
const aliasedMatch = match({
|
|
166
|
-
_normalized: true,
|
|
167
|
-
path: aliasedPath
|
|
168
|
-
})
|
|
169
|
-
if (aliasedMatch) {
|
|
170
|
-
const matched = aliasedMatch.matched
|
|
171
|
-
const aliasedRecord = matched[matched.length - 1]
|
|
172
|
-
location.params = aliasedMatch.params
|
|
173
|
-
return _createRoute(aliasedRecord, location)
|
|
174
|
-
}
|
|
175
|
-
return _createRoute(null, location)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function _createRoute (
|
|
179
|
-
record: ?RouteRecord,
|
|
180
|
-
location: Location,
|
|
181
|
-
redirectedFrom?: Location
|
|
182
|
-
): Route {
|
|
183
|
-
if (record && record.redirect) {
|
|
184
|
-
return redirect(record, redirectedFrom || location)
|
|
185
|
-
}
|
|
186
|
-
if (record && record.matchAs) {
|
|
187
|
-
return alias(record, location, record.matchAs)
|
|
188
|
-
}
|
|
189
|
-
return createRoute(record, location, redirectedFrom, router)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return {
|
|
193
|
-
match,
|
|
194
|
-
addRoute,
|
|
195
|
-
getRoutes,
|
|
196
|
-
addRoutes
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function matchRoute (
|
|
201
|
-
regex: RouteRegExp,
|
|
202
|
-
path: string,
|
|
203
|
-
params: Object
|
|
204
|
-
): boolean {
|
|
205
|
-
const m = path.match(regex)
|
|
206
|
-
|
|
207
|
-
if (!m) {
|
|
208
|
-
return false
|
|
209
|
-
} else if (!params) {
|
|
210
|
-
return true
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
for (let i = 1, len = m.length; i < len; ++i) {
|
|
214
|
-
const key = regex.keys[i - 1]
|
|
215
|
-
if (key) {
|
|
216
|
-
// Fix #1994: using * with props: true generates a param named 0
|
|
217
|
-
params[key.name || 'pathMatch'] = typeof m[i] === 'string' ? decode(m[i]) : m[i]
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return true
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function resolveRecordPath (path: string, record: RouteRecord): string {
|
|
225
|
-
return resolvePath(path, record.parent ? record.parent.path : '/', true)
|
|
226
|
-
}
|