kdu-router 3.4.0-beta.0 → 4.0.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.
Files changed (45) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +8 -6
  3. package/dist/kdu-router.cjs.js +2848 -0
  4. package/dist/kdu-router.cjs.prod.js +2610 -0
  5. package/dist/kdu-router.d.ts +1255 -0
  6. package/dist/kdu-router.esm-browser.js +3332 -0
  7. package/dist/kdu-router.esm-bundler.js +3343 -0
  8. package/dist/kdu-router.global.js +3354 -0
  9. package/dist/kdu-router.global.prod.js +6 -0
  10. package/ketur/attributes.json +8 -14
  11. package/ketur/tags.json +2 -12
  12. package/package.json +64 -92
  13. package/dist/kdu-router.common.js +0 -3040
  14. package/dist/kdu-router.esm.browser.js +0 -3005
  15. package/dist/kdu-router.esm.browser.min.js +0 -11
  16. package/dist/kdu-router.esm.js +0 -3038
  17. package/dist/kdu-router.js +0 -3046
  18. package/dist/kdu-router.min.js +0 -11
  19. package/src/components/link.js +0 -197
  20. package/src/components/view.js +0 -149
  21. package/src/create-matcher.js +0 -200
  22. package/src/create-route-map.js +0 -205
  23. package/src/history/abstract.js +0 -68
  24. package/src/history/base.js +0 -400
  25. package/src/history/hash.js +0 -163
  26. package/src/history/html5.js +0 -94
  27. package/src/index.js +0 -277
  28. package/src/install.js +0 -52
  29. package/src/util/async.js +0 -18
  30. package/src/util/dom.js +0 -3
  31. package/src/util/errors.js +0 -85
  32. package/src/util/location.js +0 -69
  33. package/src/util/misc.js +0 -6
  34. package/src/util/params.js +0 -37
  35. package/src/util/path.js +0 -74
  36. package/src/util/push-state.js +0 -46
  37. package/src/util/query.js +0 -96
  38. package/src/util/resolve-components.js +0 -109
  39. package/src/util/route.js +0 -132
  40. package/src/util/scroll.js +0 -165
  41. package/src/util/state-key.js +0 -22
  42. package/src/util/warn.js +0 -14
  43. package/types/index.d.ts +0 -17
  44. package/types/kdu.d.ts +0 -22
  45. package/types/router.d.ts +0 -170
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * kdu-router v4.0.0
3
+ * (c) 2021 NKDuy
4
+ * @license MIT
5
+ */
6
+ var KduRouter=function(e,t){"use strict";const n="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,r=e=>n?Symbol(e):"_kr_"+e,o=r("rvlm"),a=r("rvd"),c=r("r"),i=r("rl"),s=r("rvl"),l="undefined"!=typeof window;const u=Object.assign;function f(e,t){const n={};for(const r in t){const o=t[r];n[r]=Array.isArray(o)?o.map(e):e(o)}return n}let p=()=>{};const h=/\/$/;function d(e,t,n="/"){let r,o={},a="",c="";const i=t.indexOf("?"),s=t.indexOf("#",i>-1?i:0);return i>-1&&(r=t.slice(0,i),a=t.slice(i+1,s>-1?s:t.length),o=e(a)),s>-1&&(r=r||t.slice(0,s),c=t.slice(s,t.length)),r=function(e,t){if(e.startsWith("/"))return e;if(!e)return t;const n=t.split("/"),r=e.split("/");let o,a,c=n.length-1;for(o=0;o<r.length;o++)if(a=r[o],1!==c&&"."!==a){if(".."!==a)break;c--}return n.slice(0,c).join("/")+"/"+r.slice(o-(o===r.length?1:0)).join("/")}(null!=r?r:t,n),{fullPath:r+(a&&"?")+a+c,path:r,query:o,hash:c}}function m(e,t){return!t||e.toLowerCase().indexOf(t.toLowerCase())?e:e.slice(t.length)||"/"}function g(e,t){return(e.aliasOf||e)===(t.aliasOf||t)}function v(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(!y(e[n],t[n]))return!1;return!0}function y(e,t){return Array.isArray(e)?b(e,t):Array.isArray(t)?b(t,e):e===t}function b(e,t){return Array.isArray(t)?e.length===t.length&&e.every(((e,n)=>e===t[n])):1===e.length&&e[0]===t}var w,E;!function(e){e.pop="pop",e.push="push"}(w||(w={})),function(e){e.back="back",e.forward="forward",e.unknown=""}(E||(E={}));function R(e){if(!e)if(l){const t=document.querySelector("base");e=(e=t&&t.getAttribute("href")||"/").replace(/^\w+:\/\/[^\/]+/,"")}else e="/";return"/"!==e[0]&&"#"!==e[0]&&(e="/"+e),e.replace(h,"")}const O=/^[^#]+#/;function k(e,t){return e.replace(O,"#")+t}const A=()=>({left:window.pageXOffset,top:window.pageYOffset});function x(e){let t;if("el"in e){let n=e.el;const r="string"==typeof n&&n.startsWith("#"),o="string"==typeof n?r?document.getElementById(n.slice(1)):document.querySelector(n):n;if(!o)return;t=function(e,t){const n=document.documentElement.getBoundingClientRect(),r=e.getBoundingClientRect();return{behavior:t.behavior,left:r.left-n.left-(t.left||0),top:r.top-n.top-(t.top||0)}}(o,e)}else t=e;"scrollBehavior"in document.documentElement.style?window.scrollTo(t):window.scrollTo(null!=t.left?t.left:window.pageXOffset,null!=t.top?t.top:window.pageYOffset)}function P(e,t){return(history.state?history.state.position-t:-1)+e}const j=new Map;let C=()=>location.protocol+"//"+location.host;function $(e,t){const{pathname:n,search:r,hash:o}=t;if(e.indexOf("#")>-1){let e=o.slice(1);return"/"!==e[0]&&(e="/"+e),m(e,"")}return m(n,e)+r+o}function S(e,t,n,r=!1,o=!1){return{back:e,current:t,forward:n,replaced:r,position:window.history.length,scroll:o?A():null}}function L(e){const t=function(e){const{history:t,location:n}=window;let r={value:$(e,n)},o={value:t.state};function a(r,a,c){const i=e.indexOf("#"),s=i>-1?e.slice(i)+r:C()+e+r;try{t[c?"replaceState":"pushState"](a,"",s),o.value=a}catch(e){console.error(e),n[c?"replace":"assign"](s)}}return o.value||a(r.value,{back:null,current:r.value,forward:null,position:t.length-1,replaced:!0,scroll:null},!0),{location:r,state:o,push:function(e,n){const c=u({},o.value,t.state,{forward:e,scroll:A()});a(c.current,c,!0),a(e,u({},S(r.value,e,null),{position:c.position+1},n),!1),r.value=e},replace:function(e,n){a(e,u({},t.state,S(o.value.back,e,o.value.forward,!0),n,{position:o.value.position}),!0),r.value=e}}}(e=R(e)),n=function(e,t,n,r){let o=[],a=[],c=null;const i=({state:a})=>{const i=$(e,location),s=n.value,l=t.value;let u=0;if(a){if(n.value=i,t.value=a,c&&c===s)return void(c=null);u=l?a.position-l.position:0}else r(i);o.forEach((e=>{e(n.value,s,{delta:u,type:w.pop,direction:u?u>0?E.forward:E.back:E.unknown})}))};function s(){const{history:e}=window;e.state&&e.replaceState(u({},e.state,{scroll:A()}),"")}return window.addEventListener("popstate",i),window.addEventListener("beforeunload",s),{pauseListeners:function(){c=n.value},listen:function(e){o.push(e);const t=()=>{const t=o.indexOf(e);t>-1&&o.splice(t,1)};return a.push(t),t},destroy:function(){for(const e of a)e();a=[],window.removeEventListener("popstate",i),window.removeEventListener("beforeunload",s)}}}(e,t.state,t.location,t.replace);const r=u({location:"",base:e,go:function(e,t=!0){t||n.pauseListeners(),history.go(e)},createHref:k.bind(null,e)},t,n);return Object.defineProperty(r,"location",{get:()=>t.location.value}),Object.defineProperty(r,"state",{get:()=>t.state.value}),r}function q(e){return"string"==typeof e||"symbol"==typeof e}const M={path:"/",name:void 0,params:{},query:{},hash:"",fullPath:"/",matched:[],meta:{},redirectedFrom:void 0},T=r("nf");var _;function B(e,t){return u(new Error,{type:e,[T]:!0},t)}function K(e,t){return e instanceof Error&&T in e&&(null==t||!!(e.type&t))}(_=e.NavigationFailureType||(e.NavigationFailureType={}))[_.aborted=4]="aborted",_[_.cancelled=8]="cancelled",_[_.duplicated=16]="duplicated";const G="[^/]+?",F={sensitive:!1,strict:!1,start:!0,end:!0},I=/[.+*?^${}()[\]/\\]/g;function U(e,t){let n=0;for(;n<e.length&&n<t.length;){const r=t[n]-e[n];if(r)return r;n++}return e.length<t.length?1===e.length&&80===e[0]?-1:1:e.length>t.length?1===t.length&&80===t[0]?1:-1:0}function H(e,t){let n=0;const r=e.score,o=t.score;for(;n<r.length&&n<o.length;){const e=U(r[n],o[n]);if(e)return e;n++}return o.length-r.length}const D={type:0,value:""},W=/[a-zA-Z0-9_]/;function V(e,t,n){const r=function(e,t){const n=u({},F,t);let r=[],o=n.start?"^":"";const a=[];for(const t of e){const e=t.length?[]:[90];n.strict&&!t.length&&(o+="/");for(let r=0;r<t.length;r++){const c=t[r];let i=40+(n.sensitive?.25:0);if(0===c.type)r||(o+="/"),o+=c.value.replace(I,"\\$&"),i+=40;else if(1===c.type){const{value:e,repeatable:t,optional:n,regexp:s}=c;a.push({name:e,repeatable:t,optional:n});const l=s||G;if(l!==G){i+=10;try{new RegExp(`(${l})`)}catch(t){throw new Error(`Invalid custom RegExp for param "${e}" (${l}): `+t.message)}}let u=t?`((?:${l})(?:/(?:${l}))*)`:`(${l})`;r||(u=n?`(?:/${u})`:"/"+u),n&&(u+="?"),o+=u,i+=20,n&&(i+=-8),t&&(i+=-20),".*"===l&&(i+=-50)}e.push(i)}r.push(e)}if(n.strict&&n.end){const e=r.length-1;r[e][r[e].length-1]+=.7000000000000001}n.strict||(o+="/?"),n.end?o+="$":n.strict&&(o+="(?:/|$)");const c=new RegExp(o,n.sensitive?"":"i");return{re:c,score:r,keys:a,parse:function(e){const t=e.match(c),n={};if(!t)return null;for(let e=1;e<t.length;e++){const r=t[e]||"",o=a[e-1];n[o.name]=r&&o.repeatable?r.split("/"):r}return n},stringify:function(t){let n="",r=!1;for(const o of e){r&&n.endsWith("/")||(n+="/"),r=!1;for(const e of o)if(0===e.type)n+=e.value;else if(1===e.type){const{value:o,repeatable:a,optional:c}=e,i=o in t?t[o]:"";if(Array.isArray(i)&&!a)throw new Error(`Provided param "${o}" is an array but it is not repeatable (* or + modifiers)`);const s=Array.isArray(i)?i.join("/"):i;if(!s){if(!c)throw new Error(`Missing required param "${o}"`);n.endsWith("/")?n=n.slice(0,-1):r=!0}n+=s}}return n}}}(function(e){if(!e)return[[]];if("/"===e)return[[D]];if(!e.startsWith("/"))throw new Error(`Invalid path "${e}"`);function t(e){throw new Error(`ERR (${n})/"${l}": ${e}`)}let n=0,r=n;const o=[];let a;function c(){a&&o.push(a),a=[]}let i,s=0,l="",u="";function f(){l&&(0===n?a.push({type:0,value:l}):1===n||2===n||3===n?(a.length>1&&("*"===i||"+"===i)&&t(`A repeatable param (${l}) must be alone in its segment. eg: '/:ids+.`),a.push({type:1,value:l,regexp:u,repeatable:"*"===i||"+"===i,optional:"*"===i||"?"===i})):t("Invalid state to consume buffer"),l="")}function p(){l+=i}for(;s<e.length;)if(i=e[s++],"\\"!==i||2===n)switch(n){case 0:"/"===i?(l&&f(),c()):":"===i?(f(),n=1):p();break;case 4:p(),n=r;break;case 1:"("===i?(n=2,u=""):W.test(i)?p():(f(),n=0,"*"!==i&&"?"!==i&&"+"!==i&&s--);break;case 2:")"===i?"\\"==u[u.length-1]?u=u.slice(0,-1)+i:n=3:u+=i;break;case 3:f(),n=0,"*"!==i&&"?"!==i&&"+"!==i&&s--;break;default:t("Unknown state")}else r=n,n=4;return 2===n&&t(`Unfinished custom RegExp for param "${l}"`),f(),c(),o}(e.path),n),o=u(r,{record:e,parent:t,children:[],alias:[]});return t&&!o.record.aliasOf==!t.record.aliasOf&&t.children.push(o),o}function N(e,t){const n=[],r=new Map;function o(e,n,r){let i=!r,s=function(e){return{path:e.path,redirect:e.redirect,name:e.name,meta:e.meta||{},aliasOf:void 0,beforeEnter:e.beforeEnter,props:Q(e),children:e.children||[],instances:{},leaveGuards:new Set,updateGuards:new Set,enterCallbacks:{},components:"components"in e?e.components||{}:{default:e.component}}}(e);s.aliasOf=r&&r.record;const l=Y(t,e),f=[s];if("alias"in e){const t="string"==typeof e.alias?[e.alias]:e.alias;for(const e of t)f.push(u({},s,{components:r?r.record.components:s.components,path:e,aliasOf:r?r.record:s}))}let h,d;for(const t of f){let{path:u}=t;if(n&&"/"!==u[0]){let e=n.record.path,r="/"===e[e.length-1]?"":"/";t.path=n.record.path+(u&&r+u)}if(h=V(t,n,l),r?r.alias.push(h):(d=d||h,d!==h&&d.alias.push(h),i&&e.name&&!z(h)&&a(e.name)),"children"in s){let e=s.children;for(let t=0;t<e.length;t++)o(e[t],h,r&&r.children[t])}r=r||h,c(h)}return d?()=>{a(d)}:p}function a(e){if(q(e)){const t=r.get(e);t&&(r.delete(e),n.splice(n.indexOf(t),1),t.children.forEach(a),t.alias.forEach(a))}else{let t=n.indexOf(e);t>-1&&(n.splice(t,1),e.record.name&&r.delete(e.record.name),e.children.forEach(a),e.alias.forEach(a))}}function c(e){let t=0;for(;t<n.length&&H(e,n[t])>=0;)t++;n.splice(t,0,e),e.record.name&&!z(e)&&r.set(e.record.name,e)}return t=Y({strict:!1,end:!0,sensitive:!1},t),e.forEach((e=>o(e))),{addRoute:o,resolve:function(e,t){let o,a,c,i={};if("name"in e&&e.name){if(o=r.get(e.name),!o)throw B(1,{location:e});c=o.record.name,i=u(function(e,t){let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}(t.params,o.keys.filter((e=>!e.optional)).map((e=>e.name))),e.params),a=o.stringify(i)}else if("path"in e)a=e.path,o=n.find((e=>e.re.test(a))),o&&(i=o.parse(a),c=o.record.name);else{if(o=t.name?r.get(t.name):n.find((e=>e.re.test(t.path))),!o)throw B(1,{location:e,currentLocation:t});c=o.record.name,i=u({},t.params,e.params),a=o.stringify(i)}const s=[];let l=o;for(;l;)s.unshift(l.record),l=l.parent;return{name:c,path:a,params:i,matched:s,meta:X(s)}},removeRoute:a,getRoutes:function(){return n},getRecordMatcher:function(e){return r.get(e)}}}function Q(e){const t={},n=e.props||!1;if("component"in e)t.default=n;else for(let r in e.components)t[r]="boolean"==typeof n?n:n[r];return t}function z(e){for(;e;){if(e.record.aliasOf)return!0;e=e.parent}return!1}function X(e){return e.reduce(((e,t)=>u(e,t.meta)),{})}function Y(e,t){let n={};for(let r in e)n[r]=r in t?t[r]:e[r];return n}const Z=/#/g,J=/&/g,ee=/\//g,te=/=/g,ne=/\?/g,re=/\+/g,oe=/%5B/g,ae=/%5D/g,ce=/%5E/g,ie=/%60/g,se=/%7B/g,le=/%7C/g,ue=/%7D/g,fe=/%20/g;function pe(e){return encodeURI(""+e).replace(le,"|").replace(oe,"[").replace(ae,"]")}function he(e){return pe(e).replace(re,"%2B").replace(fe,"+").replace(Z,"%23").replace(J,"%26").replace(ie,"`").replace(se,"{").replace(ue,"}").replace(ce,"^")}function de(e){return function(e){return pe(e).replace(Z,"%23").replace(ne,"%3F")}(e).replace(ee,"%2F")}function me(e){try{return decodeURIComponent(""+e)}catch(e){}return""+e}function ge(e){const t={};if(""===e||"?"===e)return t;const n=("?"===e[0]?e.slice(1):e).split("&");for(let e=0;e<n.length;++e){const r=n[e].replace(re," ");let o=r.indexOf("="),a=me(o<0?r:r.slice(0,o)),c=o<0?null:me(r.slice(o+1));if(a in t){let e=t[a];Array.isArray(e)||(e=t[a]=[e]),e.push(c)}else t[a]=c}return t}function ve(e){let t="";for(let n in e){t.length&&(t+="&");const r=e[n];if(n=he(n).replace(te,"%3D"),null==r){void 0!==r&&(t+=n);continue}let o=Array.isArray(r)?r.map((e=>e&&he(e))):[r&&he(r)];for(let e=0;e<o.length;e++)t+=(e?"&":"")+n,null!=o[e]&&(t+="="+o[e])}return t}function ye(e){const t={};for(let n in e){let r=e[n];void 0!==r&&(t[n]=Array.isArray(r)?r.map((e=>null==e?null:""+e)):null==r?r:""+r)}return t}function be(){let e=[];return{add:function(t){return e.push(t),()=>{const n=e.indexOf(t);n>-1&&e.splice(n,1)}},list:()=>e,reset:function(){e=[]}}}function we(e,n,r){const o=()=>{e[n].delete(r)};t.onUnmounted(o),t.onDeactivated(o),t.onActivated((()=>{e[n].add(r)})),e[n].add(r)}function Ee(e,t,n,r,o){const a=r&&(r.enterCallbacks[o]=r.enterCallbacks[o]||[]);return()=>new Promise(((c,i)=>{const s=e=>{var s;!1===e?i(B(4,{from:n,to:t})):e instanceof Error?i(e):"string"==typeof(s=e)||s&&"object"==typeof s?i(B(2,{from:t,to:e})):(a&&r.enterCallbacks[o]===a&&"function"==typeof e&&a.push(e),c())},l=e.call(r&&r.instances[o],t,n,s);let u=Promise.resolve(l);e.length<3&&(u=u.then(s)),u.catch((e=>i(e)))}))}function Re(e,t,r,o){const a=[];for(const i of e)for(const e in i.components){let s=i.components[e];if("beforeRouteEnter"===t||i.instances[e])if("object"==typeof(c=s)||"displayName"in c||"props"in c||"__vccOpts"in c){const n=(s.__vccOpts||s)[t];n&&a.push(Ee(n,r,o,i,e))}else{let c=s();c=c.catch(console.error),a.push((()=>c.then((a=>{if(!a)return Promise.reject(new Error(`Couldn't resolve component "${e}" at "${i.path}"`));const c=(s=a).__esModule||n&&"Module"===s[Symbol.toStringTag]?a.default:a;var s;i.components[e]=c;const l=c[t];return l&&Ee(l,r,o,i,e)()}))))}}var c;return a}function Oe(e){const n=t.inject(c),r=t.inject(i),o=t.computed((()=>n.resolve(t.unref(e.to)))),a=t.computed((()=>{let{matched:e}=o.value,{length:t}=e;const n=e[t-1];let a=r.matched;if(!n||!a.length)return-1;let c=a.findIndex(g.bind(null,n));if(c>-1)return c;let i=Ae(e[t-2]);return t>1&&Ae(n)===i&&a[a.length-1].path!==i?a.findIndex(g.bind(null,e[t-2])):c})),s=t.computed((()=>a.value>-1&&function(e,t){for(let n in t){let r=t[n],o=e[n];if("string"==typeof r){if(r!==o)return!1}else if(!Array.isArray(o)||o.length!==r.length||r.some(((e,t)=>e!==o[t])))return!1}return!0}(r.params,o.value.params))),l=t.computed((()=>a.value>-1&&a.value===r.matched.length-1&&v(r.params,o.value.params)));return{route:o,href:t.computed((()=>o.value.href)),isActive:s,isExactActive:l,navigate:function(r={}){return function(e){if(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)return;if(e.defaultPrevented)return;if(void 0!==e.button&&0!==e.button)return;if(e.currentTarget&&e.currentTarget.getAttribute){const t=e.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(t))return}e.preventDefault&&e.preventDefault();return!0}(r)?n[t.unref(e.replace)?"replace":"push"](t.unref(e.to)):Promise.resolve()}}}const ke=t.defineComponent({name:"RouterLink",props:{to:{type:[String,Object],required:!0},activeClass:String,exactActiveClass:String,custom:Boolean,ariaCurrentValue:{type:String,default:"page"}},setup(e,{slots:n,attrs:r}){const o=t.reactive(Oe(e)),{options:a}=t.inject(c),i=t.computed((()=>({[xe(e.activeClass,a.linkActiveClass,"router-link-active")]:o.isActive,[xe(e.exactActiveClass,a.linkExactActiveClass,"router-link-exact-active")]:o.isExactActive})));return()=>{const a=n.default&&n.default(o);return e.custom?a:t.h("a",u({"aria-current":o.isExactActive?e.ariaCurrentValue:null,onClick:o.navigate,href:o.href},r,{class:i.value}),a)}}});function Ae(e){return e?e.aliasOf?e.aliasOf.path:e.path:""}const xe=(e,t,n)=>null!=e?e:null!=t?t:n;function Pe(e,t){if(!e)return null;const n=e(t);return 1===n.length?n[0]:n}const je=t.defineComponent({name:"RouterView",props:{name:{type:String,default:"default"},route:Object},setup(e,{attrs:n,slots:r}){const c=t.inject(s),i=t.computed((()=>e.route||c.value)),l=t.inject(a,0),f=t.computed((()=>i.value.matched[l]));t.provide(a,l+1),t.provide(o,f),t.provide(s,i);const p=t.ref();return t.watch((()=>[p.value,f.value,e.name]),(([e,t,n],[r,o,a])=>{t&&(t.instances[n]=e,o&&o!==t&&e&&e===r&&(t.leaveGuards=o.leaveGuards,t.updateGuards=o.updateGuards)),!e||!t||o&&g(t,o)&&r||(t.enterCallbacks[n]||[]).forEach((t=>t(e)))}),{flush:"post"}),()=>{const o=i.value,a=f.value,c=a&&a.components[e.name],s=e.name;if(!c)return Pe(r.default,{Component:c,route:o});const l=a.props[e.name],h=l?!0===l?o.params:"function"==typeof l?l(o):l:null,d=t.h(c,u({},h,n,{onKnodeUnmounted:e=>{e.component.isUnmounted&&(a.instances[s]=null)},ref:p}));return Pe(r.default,{Component:d,route:o})||d}}});function Ce(e){return e.reduce(((e,t)=>e.then((()=>t()))),Promise.resolve())}return e.RouterLink=ke,e.RouterView=je,e.START_LOCATION=M,e.createMemoryHistory=function(e=""){let t=[],n=[""],r=0;function o(e){r++,r===n.length||n.splice(r),n.push(e)}const a={location:"",state:{},base:e,createHref:k.bind(null,e),replace(e){n.splice(r--,1),o(e)},push(e,t){o(e)},listen:e=>(t.push(e),()=>{const n=t.indexOf(e);n>-1&&t.splice(n,1)}),destroy(){t=[]},go(e,o=!0){const a=this.location,c=e<0?E.back:E.forward;r=Math.max(0,Math.min(r+e,n.length-1)),o&&function(e,n,{direction:r,delta:o}){const a={direction:r,delta:o,type:w.pop};for(let r of t)r(e,n,a)}(this.location,a,{direction:c,delta:e})}};return Object.defineProperty(a,"location",{get:()=>n[r]}),a},e.createRouter=function(e){const n=N(e.routes,e);let r=e.parseQuery||ge,o=e.stringifyQuery||ve,a=e.history;const h=be(),m=be(),y=be(),b=t.shallowRef(M);let w=M;l&&e.scrollBehavior&&"scrollRestoration"in history&&(history.scrollRestoration="manual");const E=f.bind(null,(e=>""+e)),R=f.bind(null,de),O=f.bind(null,me);function k(e,t){if(t=u({},t||b.value),"string"==typeof e){let o=d(r,e,t.path),c=n.resolve({path:o.path},t),i=a.createHref(o.fullPath);return u(o,c,{params:O(c.params),hash:me(o.hash),redirectedFrom:void 0,href:i})}let c;"path"in e?c=u({},e,{path:d(r,e.path,t.path).path}):(c=u({},e,{params:R(e.params)}),t.params=R(t.params));let i=n.resolve(c,t);const s=e.hash||"";i.params=E(O(i.params));const l=function(e,t){let n=t.query?e(t.query):"";return t.path+(n&&"?")+n+(t.hash||"")}(o,u({},e,{hash:(f=s,pe(f).replace(se,"{").replace(ue,"}").replace(ce,"^")),path:i.path}));var f;let p=a.createHref(l);return u({fullPath:l,hash:s,query:o===ve?ye(e.query):e.query},i,{redirectedFrom:void 0,href:p})}function C(e){return"string"==typeof e?{path:e}:u({},e)}function $(e,t){if(w!==e)return B(8,{from:t,to:e})}function S(e){return T(e)}function L(e){const t=e.matched[e.matched.length-1];if(t&&t.redirect){const{redirect:n}=t;let r=C("function"==typeof n?n(e):n);return u({query:e.query,hash:e.hash,params:e.params},r)}}function T(e,t){const n=w=k(e),r=b.value,a=e.state,c=e.force,i=!0===e.replace,s=L(n);if(s)return T(u(s,{state:a,force:c,replace:i}),t||n);const l=n;let f;return l.redirectedFrom=t,!c&&function(e,t,n){let r=t.matched.length-1,o=n.matched.length-1;return r>-1&&r===o&&g(t.matched[r],n.matched[o])&&v(t.params,n.params)&&e(t.query)===e(n.query)&&t.hash===n.hash}(o,r,n)&&(f=B(16,{to:l,from:r}),X(r,r,!0,!1)),(f?Promise.resolve(f):G(l,r)).catch((e=>K(e)?e:Q(e))).then((e=>{if(e){if(K(e,2))return T(u(C(e.to),{state:a,force:c,replace:i}),t||l)}else e=I(l,r,!0,i,a);return F(l,r,e),e}))}function _(e,t){const n=$(e,t);return n?Promise.reject(n):Promise.resolve()}function G(e,t){let n;const[r,o,a]=function(e,t){const n=[],r=[],o=[],a=Math.max(t.matched.length,e.matched.length);for(let c=0;c<a;c++){const a=t.matched[c];a&&(e.matched.indexOf(a)<0?n.push(a):r.push(a));const i=e.matched[c];i&&t.matched.indexOf(i)<0&&o.push(i)}return[n,r,o]}(e,t);n=Re(r.reverse(),"beforeRouteLeave",e,t);for(const o of r)o.leaveGuards.forEach((r=>{n.push(Ee(r,e,t))}));const c=_.bind(null,e,t);return n.push(c),Ce(n).then((()=>{n=[];for(const r of h.list())n.push(Ee(r,e,t));return n.push(c),Ce(n)})).then((()=>{n=Re(o,"beforeRouteUpdate",e,t);for(const r of o)r.updateGuards.forEach((r=>{n.push(Ee(r,e,t))}));return n.push(c),Ce(n)})).then((()=>{n=[];for(const r of e.matched)if(r.beforeEnter&&t.matched.indexOf(r)<0)if(Array.isArray(r.beforeEnter))for(const o of r.beforeEnter)n.push(Ee(o,e,t));else n.push(Ee(r.beforeEnter,e,t));return n.push(c),Ce(n)})).then((()=>(e.matched.forEach((e=>e.enterCallbacks={})),n=Re(a,"beforeRouteEnter",e,t),n.push(c),Ce(n)))).then((()=>{n=[];for(const r of m.list())n.push(Ee(r,e,t));return n.push(c),Ce(n)})).catch((e=>K(e,8)?e:Promise.reject(e)))}function F(e,t,n){for(const r of y.list())r(e,t,n)}function I(e,t,n,r,o){const c=$(e,t);if(c)return c;const i=t===M,s=l?history.state:{};n&&(r||i?a.replace(e.fullPath,u({scroll:i&&s&&s.scroll},o)):a.push(e.fullPath,o)),b.value=e,X(e,t,n,i),z()}let U;function H(){U=a.listen(((e,t,n)=>{let r=k(e);const o=L(r);if(o)return void T(u(o,{replace:!0}),r).catch(p);w=r;const c=b.value;var i,s;l&&(i=P(c.fullPath,n.delta),s=A(),j.set(i,s)),G(r,c).catch((e=>K(e,12)?e:K(e,2)?(n.delta&&a.go(-n.delta,!1),T(e.to,r).catch(p),Promise.reject()):(n.delta&&a.go(-n.delta,!1),Q(e)))).then((e=>{(e=e||I(r,c,!1))&&n.delta&&a.go(-n.delta,!1),F(r,c,e)})).catch(p)}))}let D,W=be(),V=be();function Q(e){return z(e),V.list().forEach((t=>t(e))),Promise.reject(e)}function z(e){D||(D=!0,H(),W.list().forEach((([t,n])=>e?n(e):t())),W.reset())}function X(n,r,o,a){const{scrollBehavior:c}=e;if(!l||!c)return Promise.resolve();let i=!o&&function(e){const t=j.get(e);return j.delete(e),t}(P(n.fullPath,0))||(a||!o)&&history.state&&history.state.scroll||null;return t.nextTick().then((()=>c(n,r,i))).then((e=>e&&x(e))).catch(Q)}const Y=e=>a.go(e);let Z;const J=new Set;return{currentRoute:b,addRoute:function(e,t){let r,o;return q(e)?(r=n.getRecordMatcher(e),o=t):o=e,n.addRoute(o,r)},removeRoute:function(e){let t=n.getRecordMatcher(e);t&&n.removeRoute(t)},hasRoute:function(e){return!!n.getRecordMatcher(e)},getRoutes:function(){return n.getRoutes().map((e=>e.record))},resolve:k,options:e,push:S,replace:function(e){return S(u(C(e),{replace:!0}))},go:Y,back:()=>Y(-1),forward:()=>Y(1),beforeEach:h.add,beforeResolve:m.add,afterEach:y.add,onError:V.add,isReady:function(){return D&&b.value!==M?Promise.resolve():new Promise(((e,t)=>{W.add([e,t])}))},install(e){e.component("RouterLink",ke),e.component("RouterView",je),e.config.globalProperties.$router=this,Object.defineProperty(e.config.globalProperties,"$route",{get:()=>t.unref(b)}),l&&!Z&&b.value===M&&(Z=!0,S(a.location).catch((e=>{})));const n={};for(let e in M)n[e]=t.computed((()=>b.value[e]));e.provide(c,this),e.provide(i,t.reactive(n)),e.provide(s,b);let r=e.unmount;J.add(e),e.unmount=function(){J.delete(e),J.size<1&&(U(),b.value=M,Z=!1,D=!1),r.call(this,arguments)}}}},e.createRouterMatcher=N,e.createWebHashHistory=function(e){return(e=location.host?e||location.pathname:"").indexOf("#")<0&&(e+="#"),L(e)},e.createWebHistory=L,e.isNavigationFailure=K,e.matchedRouteKey=o,e.onBeforeRouteLeave=function(e){const n=t.inject(o,{}).value;n&&we(n,"leaveGuards",e)},e.onBeforeRouteUpdate=function(e){const n=t.inject(o,{}).value;n&&we(n,"updateGuards",e)},e.parseQuery=ge,e.routeLocationKey=i,e.routerKey=c,e.routerViewLocationKey=s,e.stringifyQuery=ve,e.useLink=Oe,e.useRoute=function(){return t.inject(i)},e.useRouter=function(){return t.inject(c)},e.viewDepthKey=a,Object.defineProperty(e,"__esModule",{value:!0}),e}({},Kdu);
@@ -1,27 +1,21 @@
1
1
  {
2
2
  "name": {
3
- "type": "string",
3
+ "type": "string | symbol",
4
4
  "description": "When a `<router-view>` has a `name` prop, it will render the component with the corresponding name in the matched route record's components option."
5
5
  },
6
+ "route": {
7
+ "description": "When a `<router-view>` has a `route` prop, it will use that resolved Route Location instead of the current location."
8
+ },
6
9
  "to": {
7
10
  "description": "Denotes the target route of the link. When clicked, the value of the `to` prop will be internally passed to `router.push()`, so the value can be either a string or a location descriptor object."
8
11
  },
9
- "append": {
10
- "type": "boolean",
11
- "description": "Setting the append prop always appends the relative path to the current path. For example, assuming we are navigating from /a to a relative link b, without append we will end up at /b, but with append we will end up at /a/b."
12
- },
13
- "tag": {
14
- "description": "Specify which tag to render to, and it will still listen to click events for navigation. By default, an `a` tag is rendered."
15
- },
16
- "event": {
17
- "description": "Specify the event(s) that can trigger the link navigation. By default, the `click` event triggers a navigation."
18
- },
19
12
  "replace": {
20
13
  "type": "boolean",
21
- "description": "Call `router.replace()` instead of `router.push()` when the link is clicked, so the navigation replaces the current history entry."
14
+ "description": "Setting replace prop will call `router.replace()` instead of `router.push()` when clicked, so the navigation will replace the current history entry."
22
15
  },
23
- "exact": {
24
- "description": "The default active class matching behavior is inclusive match. For example, `<router-link to=\"/a\">` will get this class applied as long as the current path starts with /a/ or is /a.\nOne consequence of this is that `<router-link to=\"/\">` will be active for every route! To force the link into \"exact match mode\", use the exact prop: `<router-link to=\"/\" exact>`"
16
+ "custom": {
17
+ "type": "boolean",
18
+ "description": "Whether `<router-link>` should not wrap its content in an `<a>` tag."
25
19
  },
26
20
  "active-class": {
27
21
  "type": "string",
package/ketur/tags.json CHANGED
@@ -1,20 +1,10 @@
1
1
  {
2
2
  "router-view": {
3
- "attributes": ["name"],
3
+ "attributes": ["name", "route"],
4
4
  "description": "Component that renders the matched component for the current location. Components rendered by `<router-view>` can also contain their own `<router-view>` to render nested routes."
5
5
  },
6
6
  "router-link": {
7
- "attributes": [
8
- "to",
9
- "replace",
10
- "append",
11
- "tag",
12
- "active-class",
13
- "exact",
14
- "event",
15
- "exact-active-class",
16
- "aria-current-value"
17
- ],
7
+ "attributes": ["to", "replace", "custom", "active-class","exact-active-class", "aria-current-value"],
18
8
  "description": "Component that renders an `<a>` with the correct `href` attribute and click listeners to trigger a local navigation when clicked. Can also customize its rendering by providing the `custom` prop and using its `k-slot` API."
19
9
  }
20
10
  }
package/package.json CHANGED
@@ -1,111 +1,83 @@
1
1
  {
2
2
  "name": "kdu-router",
3
- "version": "3.4.0-beta.0",
4
- "description": "Official router for Kdu.js 2",
5
- "author": "NKDuy",
6
- "license": "MIT",
7
- "main": "dist/kdu-router.common.js",
8
- "module": "dist/kdu-router.esm.js",
9
- "unpkg": "dist/kdu-router.js",
10
- "jsdelivr": "dist/kdu-router.js",
3
+ "version": "4.0.0",
4
+ "main": "dist/kdu-router.cjs.js",
5
+ "unpkg": "dist/kdu-router.global.js",
6
+ "jsdelivr": "dist/kdu-router.global.js",
7
+ "module": "dist/kdu-router.esm-bundler.js",
8
+ "types": "dist/kdu-router.d.ts",
11
9
  "sideEffects": false,
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/kdujs/kdu-router.git"
15
- },
16
- "typings": "types/index.d.ts",
10
+ "license": "MIT",
17
11
  "files": [
18
- "src",
19
12
  "dist/*.js",
20
- "types/*.d.ts",
13
+ "dist/kdu-router.d.ts",
21
14
  "ketur/tags.json",
22
- "ketur/attributes.json"
23
- ],
24
- "ketur": {
25
- "tags": "ketur/tags.json",
26
- "attributes": "ketur/attributes.json"
27
- },
28
- "keywords": [
29
- "kdu",
30
- "router",
31
- "routing"
15
+ "ketur/attributes.json",
16
+ "README.md"
32
17
  ],
33
18
  "scripts": {
34
- "dev": "node examples/server.js",
35
- "dev:dist": "rollup -wm -c build/rollup.dev.config.js",
36
- "build": "node build/build.js",
37
- "lint": "eslint src examples test",
38
- "test": "npm run lint && npm run flow && npm run test:unit && npm run test:e2e && npm run test:types",
39
- "flow": "flow check",
40
- "test:unit": "jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
41
- "test:e2e": "node test/e2e/runner.js",
42
- "test:e2e:ci": "node test/e2e/runner.js --local -e ie,android44 -c test/e2e/nightwatch.browserstack.js test/e2e/specs/active-links.js",
43
- "test:e2e:ff": "node test/e2e/runner.js -e firefox -c test/e2e/nightwatch.config.js",
44
- "test:e2e:ie9": "node test/e2e/runner.js --local -e ie9 -c test/e2e/nightwatch.browserstack.js --skiptags history,ie9-fail",
45
- "test:types": "tsc -p types/test",
46
- "docs": "kdupress dev docs",
47
- "docs:build": "kdupress build docs",
48
- "changelog": "conventional-changelog -p angular -r 2 -i CHANGELOG.md -s",
49
- "release": "bash scripts/release.sh"
19
+ "build": "rollup -c rollup.config.js",
20
+ "build:dts": "api-extractor run --local --verbose && tail -n +7 src/globalExtensions.ts >> dist/kdu-router.d.ts",
21
+ "release": "bash scripts/release.sh",
22
+ "build:size": "yarn run build && rollup -c size-checks/rollup.config.js",
23
+ "lint": "prettier -c --parser typescript \"src/**/*.[jt]s?(x)\"",
24
+ "lint:fix": "yarn run lint --write"
50
25
  },
51
26
  "gitHooks": {
52
27
  "pre-commit": "lint-staged",
53
- "commit-msg": "node scripts/verifyCommitMsg.js"
28
+ "commit-msg": "node scripts/verifyCommit.js"
54
29
  },
55
30
  "lint-staged": {
56
- "*.{js,kdu}": [
57
- "eslint --fix",
58
- "git add"
31
+ "*.js": [
32
+ "prettier --write"
33
+ ],
34
+ "*.ts?(x)": [
35
+ "prettier --parser=typescript --write"
59
36
  ]
60
37
  },
38
+ "peerDependencies": {
39
+ "kdu": "^3.0.0"
40
+ },
41
+ "ketur": {
42
+ "tags": "ketur/tags.json",
43
+ "attributes": "ketur/attributes.json"
44
+ },
61
45
  "devDependencies": {
62
- "axios": "^0.19.0",
63
- "babel-core": "^6.24.1",
64
- "babel-eslint": "^10.0.2",
65
- "babel-loader": "^7.1.3",
66
- "babel-plugin-syntax-dynamic-import": "^6.18.0",
67
- "babel-preset-env": "^1.6.1",
68
- "babel-preset-flow-kdu": "^1.0.0",
69
- "browserstack-local": "^1.4.0",
70
- "buble": "^0.19.8",
71
- "chromedriver": "^83.0.0",
72
- "conventional-changelog-cli": "^2.0.11",
73
- "cross-spawn": "^6.0.5",
74
- "css-loader": "^2.1.1",
75
- "dotenv": "^8.0.0",
76
- "es6-promise": "^4.2.8",
77
- "eslint": "^4.19.1",
78
- "eslint-plugin-flowtype": "^2.46.1",
79
- "eslint-plugin-jasmine": "^2.10.1",
80
- "eslint-plugin-kdu-libs": "^3.0.0",
81
- "express": "^4.17.1",
82
- "express-urlrewrite": "^1.2.0",
83
- "flow-bin": "^0.66.0",
84
- "geckodriver": "^1.19.1",
85
- "jasmine": "2.8.0",
86
- "kdu": "^2.5.16-alpha.0",
87
- "kdu-loader": "^15.2.1-beta.0",
88
- "kdu-template-compiler": "^2.5.16-alpha.0",
89
- "lint-staged": "^8.2.0",
90
- "nightwatch": "^1.3.6",
91
- "nightwatch-helpers": "^1.0.0",
92
- "path-to-regexp": "^1.8.0",
93
- "rollup": "^1.20.1",
94
- "rollup-plugin-buble": "^0.19.8",
95
- "rollup-plugin-commonjs": "^10.0.2",
96
- "rollup-plugin-flow-no-whitespace": "^1.0.0",
97
- "rollup-plugin-node-resolve": "^5.2.0",
98
- "rollup-plugin-replace": "^2.0.0",
99
- "rollup-watch": "^4.0.0",
46
+ "@kdujs/compiler-sfc": "3.0.0",
47
+ "@kdujs/devtools-api": "6.0.0-beta.8",
48
+ "@kdujs/server-renderer": "^3.0.0",
49
+ "@microsoft/api-extractor": "7.8.1",
50
+ "@rollup/plugin-alias": "^3.1.1",
51
+ "@rollup/plugin-commonjs": "^17.0.0",
52
+ "@rollup/plugin-node-resolve": "^11.0.0",
53
+ "@rollup/plugin-replace": "^2.3.4",
54
+ "@types/jest": "^26.0.16",
55
+ "@types/jsdom": "^16.2.3",
56
+ "@types/webpack": "^4.41.25",
57
+ "@types/webpack-env": "^1.16.0",
58
+ "axios": "^0.21.0",
59
+ "brotli": "^1.3.2",
60
+ "browserstack-local": "^1.4.5",
61
+ "chalk": "^4.1.0",
62
+ "chromedriver": "^87.0.2",
63
+ "codecov": "^3.8.0",
64
+ "css-loader": "^5.0.1",
65
+ "dotenv": "^8.2.0",
66
+ "faked-promise": "^2.2.2",
67
+ "html-webpack-plugin": "^4.5.0",
68
+ "kdu": "3.0.0",
69
+ "kdu-loader": "16.1.0",
70
+ "lint-staged": "^10.5.3",
71
+ "prettier": "^2.2.1",
72
+ "rollup": "^2.34.0",
73
+ "rollup-plugin-terser": "^7.0.2",
74
+ "rollup-plugin-typescript2": "^0.29.0",
100
75
  "selenium-server": "^3.141.59",
101
- "terser": "^4.2.0",
102
- "typescript": "^3.5.2",
103
- "webpack": "^4.35.2",
104
- "webpack-dev-middleware": "^3.7.0",
76
+ "serve-handler": "^6.1.3",
77
+ "style-loader": "^2.0.0",
78
+ "ts-loader": "^8.0.11",
79
+ "ts-node": "^9.0.0",
80
+ "typescript": "^4.1.2",
105
81
  "yorkie": "^2.0.0"
106
- },
107
- "bugs": {
108
- "url": "https://github.com/kdujs/kdu-router/issues"
109
- },
110
- "homepage": "https://github.com/kdujs/kdu-router#readme"
82
+ }
111
83
  }