@argon-router/core 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +134 -8
- package/dist/index.js +710 -797
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Router without a headache
|
|
4
4
|
|
|
5
5
|
> [!WARNING]
|
|
6
|
-
> argon-router is
|
|
6
|
+
> argon-router is not production ready yet and still may have bugs and unstable API. If you found bug — please report it on GitHub.
|
|
7
7
|
|
|
8
8
|
## Documentation
|
|
9
9
|
|
|
@@ -13,6 +13,7 @@ For additional information, guides and api reference visit [documentation site](
|
|
|
13
13
|
|
|
14
14
|
- [@argon-router/core](https://www.npmjs.com/package/@argon-router/core)
|
|
15
15
|
- [@argon-router/react](https://www.npmjs.com/package/@argon-router/react)
|
|
16
|
+
- [@argon-router/paths](https://www.npmjs.com/package/@argon-router/paths)
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
18
19
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("effector"),ye=require("patronum");function G(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),r.push.apply(r,n)}return r}function B(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?G(Object(r),!0).forEach(function(n){ge(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):G(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function ge(e,t,r){return(t=he(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function he(e){var t=be(e,"string");return typeof t=="symbol"?t:t+""}function be(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function we(e){let t;const r=c.createEffect(()=>{var d;return(d=t)===null||d===void 0?void 0:d()},{name:"waitForAsyncBundleFx",sid:"tw7mq7"}),n=c.createEffect(async()=>{for(const g of(d=e.beforeOpen)!==null&&d!==void 0?d:[]){var d;await g()}},{name:"beforeOpenFx",sid:"ls74w9"}),a=c.createEffect(async d=>{await r(),await n();const g=e.parent;return g&&await g.internal.openFx(B(B({},d??{params:{}}),{},{navigate:!1})),d},{name:"openFx",sid:"-hz9h5i"}),i=c.createStore({},{name:"$params",sid:"rstqrf"}),o=c.createStore(!1,{name:"$isOpened",sid:"-zgx6q9"}),l=a.pending,O=c.createEvent({name:"open",sid:"-cby6lj"}),j=c.createEvent({name:"close",sid:"7uwhl1"}),$=c.createEvent({name:"opened",sid:"44ryfn"}),F=c.createEvent({name:"openedOnServer",sid:"-prk6y1"}),v=c.createEvent({name:"openedOnClient",sid:"-fw2mlz"}),S=c.createEvent({name:"navigated",sid:"d2ciwc"}),P=c.createEvent({name:"closed",sid:"1yn6aj"});c.sample({and:[{clock:O,target:a}],or:{sid:"t8zigl"}});const A={};return c.sample({and:[{clock:S,fn:d=>d&&"params"in d?B({},d.params):A,target:i}],or:{sid:"todr2p"}}),c.split({and:[{source:S,match:()=>typeof window>"u"?"server":"client",cases:{server:F,client:v}}],or:{sid:"u6iynm"}}),c.sample({and:[{clock:[v,F],target:$}],or:{sid:"ymu9q6"}}),c.sample({and:[{clock:j,target:P}],or:{sid:"z14x5k"}}),c.sample({and:[{clock:[$.map(()=>!0),P.map(()=>!1)],target:o}],or:{sid:"z3vw4d"}}),{$params:i,$isOpened:o,$isPending:l,open:O,closed:P,opened:$,openedOnClient:v,openedOnServer:F,internal:B({navigated:S,close:j,openFx:a,setAsyncImport:d=>t=d},e),"@@unitShape":()=>({params:i,isPending:l,isOpened:o,onOpen:O})}}var C={},X;function Oe(){if(X)return C;X=1,Object.defineProperty(C,"__esModule",{value:!0}),C.TokenData=void 0,C.parse=F,C.compile=v,C.match=A,C.pathToRegexp=d,C.stringify=q;const e="/",t=f=>f,r=/^[$_\p{ID_Start}]$/u,n=/^[$\u200c\u200d\p{ID_Continue}]$/u,a="https://git.new/pathToRegexpError",i={"{":"{","}":"}","(":"(",")":")","[":"[","]":"]","+":"+","?":"?","!":"!"};function o(f){return f.replace(/[{}()\[\]+?!:*]/g,"\\$&")}function l(f){return f.replace(/[.+*?^${}()[\]|/\\]/g,"\\$&")}function*O(f){const u=[...f];let s=0;function y(){let p="";if(r.test(u[++s]))for(p+=u[s];n.test(u[++s]);)p+=u[s];else if(u[s]==='"'){let m=s;for(;s<u.length;){if(u[++s]==='"'){s++,m=0;break}u[s]==="\\"?p+=u[++s]:p+=u[s]}if(m)throw new TypeError(`Unterminated quote at ${m}: ${a}`)}if(!p)throw new TypeError(`Missing parameter name at ${s}: ${a}`);return p}for(;s<u.length;){const p=u[s],m=i[p];if(m)yield{type:m,index:s++,value:p};else if(p==="\\")yield{type:"ESCAPED",index:s++,value:u[s++]};else if(p===":"){const w=y();yield{type:"PARAM",index:s,value:w}}else if(p==="*"){const w=y();yield{type:"WILDCARD",index:s,value:w}}else yield{type:"CHAR",index:s,value:u[s++]}}return{type:"END",index:s,value:""}}class j{constructor(u){this.tokens=u}peek(){if(!this._peek){const u=this.tokens.next();this._peek=u.value}return this._peek}tryConsume(u){const s=this.peek();if(s.type===u)return this._peek=void 0,s.value}consume(u){const s=this.tryConsume(u);if(s!==void 0)return s;const{type:y,index:p}=this.peek();throw new TypeError(`Unexpected ${y} at ${p}, expected ${u}: ${a}`)}text(){let u="",s;for(;s=this.tryConsume("CHAR")||this.tryConsume("ESCAPED");)u+=s;return u}}class ${constructor(u){this.tokens=u}}C.TokenData=$;function F(f,u={}){const{encodePath:s=t}=u,y=new j(O(f));function p(w){const h=[];for(;;){const k=y.text();k&&h.push({type:"text",value:s(k)});const R=y.tryConsume("PARAM");if(R){h.push({type:"param",name:R});continue}const z=y.tryConsume("WILDCARD");if(z){h.push({type:"wildcard",name:z});continue}if(y.tryConsume("{")){h.push({type:"group",tokens:p("}")});continue}return y.consume(w),h}}const m=p("END");return new $(m)}function v(f,u={}){const{encode:s=encodeURIComponent,delimiter:y=e}=u,p=f instanceof $?f:F(f,u),m=S(p.tokens,y,s);return function(h={}){const[k,...R]=m(h);if(R.length)throw new TypeError(`Missing parameters: ${R.join(", ")}`);return k}}function S(f,u,s){const y=f.map(p=>P(p,u,s));return p=>{const m=[""];for(const w of y){const[h,...k]=w(p);m[0]+=h,m.push(...k)}return m}}function P(f,u,s){if(f.type==="text")return()=>[f.value];if(f.type==="group"){const p=S(f.tokens,u,s);return m=>{const[w,...h]=p(m);return h.length?[""]:[w]}}const y=s||t;return f.type==="wildcard"&&s!==!1?p=>{const m=p[f.name];if(m==null)return["",f.name];if(!Array.isArray(m)||m.length===0)throw new TypeError(`Expected "${f.name}" to be a non-empty array`);return[m.map((w,h)=>{if(typeof w!="string")throw new TypeError(`Expected "${f.name}/${h}" to be a string`);return y(w)}).join(u)]}:p=>{const m=p[f.name];if(m==null)return["",f.name];if(typeof m!="string")throw new TypeError(`Expected "${f.name}" to be a string`);return[y(m)]}}function A(f,u={}){const{decode:s=decodeURIComponent,delimiter:y=e}=u,{regexp:p,keys:m}=d(f,u),w=m.map(h=>s===!1?t:h.type==="param"?s:k=>k.split(y).map(s));return function(k){const R=p.exec(k);if(!R)return!1;const z=R[0],T=Object.create(null);for(let _=1;_<R.length;_++){if(R[_]===void 0)continue;const U=m[_-1],L=w[_-1];T[U.name]=L(R[_])}return{path:z,params:T}}}function d(f,u={}){const{delimiter:s=e,end:y=!0,sensitive:p=!1,trailing:m=!0}=u,w=[],h=[],k=p?"":"i",z=(Array.isArray(f)?f:[f]).map(U=>U instanceof $?U:F(U,u));for(const{tokens:U}of z)for(const L of g(U,0,[])){const me=b(L,s,w);h.push(me)}let T=`^(?:${h.join("|")})`;return m&&(T+=`(?:${l(s)}$)?`),T+=y?"$":`(?=${l(s)}|$)`,{regexp:new RegExp(T,k),keys:w}}function*g(f,u,s){if(u===f.length)return yield s;const y=f[u];if(y.type==="group"){const p=s.slice();for(const m of g(y.tokens,0,p))yield*g(f,u+1,m)}else s.push(y);yield*g(f,u+1,s)}function b(f,u,s){let y="",p="",m=!0;for(let w=0;w<f.length;w++){const h=f[w];if(h.type==="text"){y+=l(h.value),p+=h.value,m||(m=h.value.includes(u));continue}if(h.type==="param"||h.type==="wildcard"){if(!m&&!p)throw new TypeError(`Missing text after "${h.name}": ${a}`);h.type==="param"?y+=`(${E(u,m?"":p)}+)`:y+="([\\s\\S]+)",s.push(h),p="",m=!1;continue}}return y}function E(f,u){return u.length<2?f.length<2?`[^${l(f+u)}]`:`(?:(?!${l(f)})[^${l(u)}])`:f.length<2?`(?:(?!${l(u)})[^${l(f)}])`:`(?:(?!${l(u)}|${l(f)})[\\s\\S])`}function q(f){return f.tokens.map(function u(s,y,p){if(s.type==="text")return o(s.value);if(s.type==="group")return`{${s.tokens.map(u).join("")}}`;const w=I(s.name)&&M(p[y+1])?s.name:JSON.stringify(s.name);if(s.type==="param")return`:${w}`;if(s.type==="wildcard")return`*${w}`;throw new TypeError(`Unexpected token: ${s}`)}).join("")}function I(f){const[u,...s]=f;return r.test(u)?s.every(y=>n.test(y)):!1}function M(f){return(f==null?void 0:f.type)!=="text"?!0:!n.test(f.value[0])}return C}var Y=Oe();const xe=Symbol("any"),Ee=Symbol("number"),ve=Symbol("string"),Se=Symbol("array"),Fe=Symbol("boolean"),N={any:xe,number:Ee,string:ve,array:Se,boolean:Fe};function Z(e,t){for(const r of e)if(t.includes(r))return!0;return!1}function ee(e,t){for(const r in t){const n=t[r];if(Array.isArray(n)&&(!e[r]||JSON.stringify(n)!==e[r]))return!1;switch(typeof n){case"number":{if(!e[r]||n.toString()!==e[r])return!1;break}case"object":{if(!e[r]||JSON.stringify(n)!==e[r])return!1;break}case"string":{if(!e[r]||n!==e[r])return!1;break}case"boolean":{if(!e[r]||!["0","1","false","true"].includes(e[r]))return!1;break}}switch(n){case N.any:{if(!e[r])return!1;break}case N.string:{if(!e[r]||Array.isArray(e[r]))return!1;break}case N.array:{if(!e[r]||!Array.isArray(e[r]))return!1;break}case N.number:{if(!e[r]||Array.isArray(e[r])||isNaN(parseInt(e[r]))&&isNaN(parseFloat(e[r])))return!1;break}case N.boolean:{if(!e[r]||Array.isArray(e[r])||!["0","1","false","true"].includes(e[r]))return!1;break}}}return!0}function $e(e,t){const r={};for(const n in t){const a=t[n],i=e[n];if(Array.isArray(a)){const o=e[n];r[n]=o;continue}switch(typeof a){case"number":{r[n]=isNaN(parseInt(i))?parseFloat(i):parseInt(i);break}case"object":{r[n]=JSON.parse(i);break}case"string":r[n]=i;case"boolean":{r[n]=i==="1"||i==="true";break}}switch(a){case N.any:case N.string:case N.array:{r[n]=e[n];break}case N.number:{const o=e[n];r[n]=isNaN(parseInt(o))?parseFloat(o):parseInt(o);break}case N.boolean:{const o=e[n];r[n]=o==="1"||o==="true";break}}}return r}function je(e){let{$activeRoutes:t,$query:r,navigate:n}=e;return a=>{const{parameters:i,forRoutes:o}=a,l=c.createStore(!1,{name:"$entered",sid:"vsdvtz"}),O=c.createEvent({name:"entered",sid:"-fzpsd2"}),j=c.createEvent({name:"exited",sid:"ygmmw5"}),$=c.createEvent({name:"exit",sid:"-934tq2"}),F=c.createEvent({name:"changeEntered",sid:"-19xw1"});return c.sample({and:[{clock:F,target:l}],or:{sid:"-h9twmc"}}),c.sample({and:[{source:{activeRoutes:t,query:r},filter:v=>{let{activeRoutes:S,query:P}=v;return(!o||Z(o,S))&&ee(P,i)},fn:v=>{let{query:S}=v;return $e(S,i)},target:[O,F.prepend(()=>!0)]}],or:{sid:"-gvj96y"}}),c.sample({and:[{source:{activeRoutes:t,query:r,entered:l},filter:v=>{let{activeRoutes:S,query:P,entered:A}=v;return A&&!((!o||Z(o,S))&&ee(P,i))},target:[j.prepend(()=>{}),F.prepend(()=>!1)]}],or:{sid:"-gf1fe4"}}),c.sample({and:[{clock:$,source:r,fn:(v,S)=>{if(S&&S.ignoreParams){const P={};for(const A of S.ignoreParams)v[A]&&(P[A]=v[A]);return{query:P}}return{query:{}}},target:n}],or:{sid:"-fvsmmh"}}),{entered:O,exited:j,exit:$}}}const se="%[a-f0-9]{2}",re=new RegExp("("+se+")|([^%]+?)","gi"),te=new RegExp("("+se+")+","gi");function K(e,t){try{return[decodeURIComponent(e.join(""))]}catch{}if(e.length===1)return e;t=t||1;const r=e.slice(0,t),n=e.slice(t);return Array.prototype.concat.call([],K(r),K(n))}function Pe(e){try{return decodeURIComponent(e)}catch{let t=e.match(re)||[];for(let r=1;r<t.length;r++)e=K(t,r).join(""),t=e.match(re)||[];return e}}function Ae(e){const t={"%FE%FF":"��","%FF%FE":"��"};let r=te.exec(e);for(;r;){try{t[r[0]]=decodeURIComponent(r[0])}catch{const a=Pe(r[0]);a!==r[0]&&(t[r[0]]=a)}r=te.exec(e)}t["%C2"]="�";const n=Object.keys(t);for(const a of n)e=e.replace(new RegExp(a,"g"),t[a]);return e}function ke(e){if(typeof e!="string")throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof e+"`");try{return decodeURIComponent(e)}catch{return Ae(e)}}function Re(e,t){const r={};if(Array.isArray(t))for(const n of t){const a=Object.getOwnPropertyDescriptor(e,n);a!=null&&a.enumerable&&Object.defineProperty(r,n,a)}else for(const n of Reflect.ownKeys(e)){const a=Object.getOwnPropertyDescriptor(e,n);if(a.enumerable){const i=e[n];t(n,i,e)&&Object.defineProperty(r,n,a)}}return r}function oe(e,t){if(!(typeof e=="string"&&typeof t=="string"))throw new TypeError("Expected the arguments to be of type `string`");if(e===""||t==="")return[];const r=e.indexOf(t);return r===-1?[]:[e.slice(0,r),e.slice(r+t.length)]}const Ne=e=>e==null,Ce=e=>encodeURIComponent(e).replaceAll(/[!'()*]/g,t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`),J=Symbol("encodeFragmentIdentifier");function De(e){switch(e.arrayFormat){case"index":return t=>(r,n)=>{const a=r.length;return n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,[x(t,e),"[",a,"]"].join("")]:[...r,[x(t,e),"[",x(a,e),"]=",x(n,e)].join("")]};case"bracket":return t=>(r,n)=>n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,[x(t,e),"[]"].join("")]:[...r,[x(t,e),"[]=",x(n,e)].join("")];case"colon-list-separator":return t=>(r,n)=>n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,[x(t,e),":list="].join("")]:[...r,[x(t,e),":list=",x(n,e)].join("")];case"comma":case"separator":case"bracket-separator":{const t=e.arrayFormat==="bracket-separator"?"[]=":"=";return r=>(n,a)=>a===void 0||e.skipNull&&a===null||e.skipEmptyString&&a===""?n:(a=a===null?"":a,n.length===0?[[x(r,e),t,x(a,e)].join("")]:[[n,x(a,e)].join(e.arrayFormatSeparator)])}default:return t=>(r,n)=>n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,x(t,e)]:[...r,[x(t,e),"=",x(n,e)].join("")]}}function Ie(e){let t;switch(e.arrayFormat){case"index":return(r,n,a)=>{if(t=/\[(\d*)]$/.exec(r),r=r.replace(/\[\d*]$/,""),!t){a[r]=n;return}a[r]===void 0&&(a[r]={}),a[r][t[1]]=n};case"bracket":return(r,n,a)=>{if(t=/(\[])$/.exec(r),r=r.replace(/\[]$/,""),!t){a[r]=n;return}if(a[r]===void 0){a[r]=[n];return}a[r]=[...a[r],n]};case"colon-list-separator":return(r,n,a)=>{if(t=/(:list)$/.exec(r),r=r.replace(/:list$/,""),!t){a[r]=n;return}if(a[r]===void 0){a[r]=[n];return}a[r]=[...a[r],n]};case"comma":case"separator":return(r,n,a)=>{const i=typeof n=="string"&&n.includes(e.arrayFormatSeparator),o=typeof n=="string"&&!i&&D(n,e).includes(e.arrayFormatSeparator);n=o?D(n,e):n;const l=i||o?n.split(e.arrayFormatSeparator).map(O=>D(O,e)):n===null?n:D(n,e);a[r]=l};case"bracket-separator":return(r,n,a)=>{const i=/(\[])$/.test(r);if(r=r.replace(/\[]$/,""),!i){a[r]=n&&D(n,e);return}const o=n===null?[]:D(n,e).split(e.arrayFormatSeparator);if(a[r]===void 0){a[r]=o;return}a[r]=[...a[r],...o]};default:return(r,n,a)=>{if(a[r]===void 0){a[r]=n;return}a[r]=[...[a[r]].flat(),n]}}}function ie(e){if(typeof e!="string"||e.length!==1)throw new TypeError("arrayFormatSeparator must be single character string")}function x(e,t){return t.encode?t.strict?Ce(e):encodeURIComponent(e):e}function D(e,t){return t.decode?ke(e):e}function ce(e){return Array.isArray(e)?e.sort():typeof e=="object"?ce(Object.keys(e)).sort((t,r)=>Number(t)-Number(r)).map(t=>e[t]):e}function fe(e){const t=e.indexOf("#");return t!==-1&&(e=e.slice(0,t)),e}function Te(e){let t="";const r=e.indexOf("#");return r!==-1&&(t=e.slice(r)),t}function ne(e,t,r){return r==="string"&&typeof e=="string"?e:typeof r=="function"&&typeof e=="string"?r(e):t.parseBooleans&&e!==null&&(e.toLowerCase()==="true"||e.toLowerCase()==="false")?e.toLowerCase()==="true":r==="number"&&!Number.isNaN(Number(e))&&typeof e=="string"&&e.trim()!==""||t.parseNumbers&&!Number.isNaN(Number(e))&&typeof e=="string"&&e.trim()!==""?Number(e):e}function Q(e){e=fe(e);const t=e.indexOf("?");return t===-1?"":e.slice(t+1)}function W(e,t){t={decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1,types:Object.create(null),...t},ie(t.arrayFormatSeparator);const r=Ie(t),n=Object.create(null);if(typeof e!="string"||(e=e.trim().replace(/^[?#&]/,""),!e))return n;for(const a of e.split("&")){if(a==="")continue;const i=t.decode?a.replaceAll("+"," "):a;let[o,l]=oe(i,"=");o===void 0&&(o=i),l=l===void 0?null:["comma","separator","bracket-separator"].includes(t.arrayFormat)?l:D(l,t),r(D(o,t),l,n)}for(const[a,i]of Object.entries(n))if(typeof i=="object"&&i!==null&&t.types[a]!=="string")for(const[o,l]of Object.entries(i)){const O=t.types[a]?t.types[a].replace("[]",""):void 0;i[o]=ne(l,t,O)}else typeof i=="object"&&i!==null&&t.types[a]==="string"?n[a]=Object.values(i).join(t.arrayFormatSeparator):n[a]=ne(i,t,t.types[a]);return t.sort===!1?n:(t.sort===!0?Object.keys(n).sort():Object.keys(n).sort(t.sort)).reduce((a,i)=>{const o=n[i];return a[i]=o&&typeof o=="object"&&!Array.isArray(o)?ce(o):o,a},Object.create(null))}function ue(e,t){if(!e)return"";t={encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:",",...t},ie(t.arrayFormatSeparator);const r=o=>t.skipNull&&Ne(e[o])||t.skipEmptyString&&e[o]==="",n=De(t),a={};for(const[o,l]of Object.entries(e))r(o)||(a[o]=l);const i=Object.keys(a);return t.sort!==!1&&i.sort(t.sort),i.map(o=>{const l=e[o];return l===void 0?"":l===null?x(o,t):Array.isArray(l)?l.length===0&&t.arrayFormat==="bracket-separator"?x(o,t)+"[]":l.reduce(n(o),[]).join("&"):x(o,t)+"="+x(l,t)}).filter(o=>o.length>0).join("&")}function le(e,t){var a;t={decode:!0,...t};let[r,n]=oe(e,"#");return r===void 0&&(r=e),{url:((a=r==null?void 0:r.split("?"))==null?void 0:a[0])??"",query:W(Q(e),t),...t&&t.parseFragmentIdentifier&&n?{fragmentIdentifier:D(n,t)}:{}}}function de(e,t){t={encode:!0,strict:!0,[J]:!0,...t};const r=fe(e.url).split("?")[0]||"",n=Q(e.url),a={...W(n,{sort:!1}),...e.query};let i=ue(a,t);i&&(i=`?${i}`);let o=Te(e.url);if(typeof e.fragmentIdentifier=="string"){const l=new URL(r);l.hash=e.fragmentIdentifier,o=t[J]?l.hash:`#${e.fragmentIdentifier}`}return`${r}${i}${o}`}function pe(e,t,r){r={parseFragmentIdentifier:!0,[J]:!1,...r};const{url:n,query:a,fragmentIdentifier:i}=le(e,r);return de({url:n,query:Re(a,t),fragmentIdentifier:i},r)}function _e(e,t,r){const n=Array.isArray(t)?a=>!t.includes(a):(a,i)=>!t(a,i);return pe(e,n,r)}const H=Object.freeze(Object.defineProperty({__proto__:null,exclude:_e,extract:Q,parse:W,parseUrl:le,pick:pe,stringify:ue,stringifyUrl:de},Symbol.toStringTag,{value:"Module"}));function ae(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),r.push.apply(r,n)}return r}function V(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?ae(Object(r),!0).forEach(function(n){Ue(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ae(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ue(e,t,r){return(t=ze(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ze(e){var t=qe(e,"string");return typeof t=="symbol"?t:t+""}function qe(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Be(e){const{base:t="/",routes:r}=e,n=c.createStore(null,{and:{serialize:"ignore"},name:"$history",sid:"31majq"}),a=c.createStore({},{name:"$query",sid:"4bi33m"}),i=c.createStore(null,{name:"$path",sid:"mb6wa5"}),o=c.createEvent({name:"setHistory",sid:"svmj03"}),l=c.createEvent({name:"navigate",sid:"-74s2ra"}),O=c.createEvent({name:"back",sid:"-hekewa"}),j=c.createEvent({name:"forward",sid:"-64ksuk"}),$=c.createEvent({name:"locationUpdated",sid:"e6p2xg"}),F=r.map(d=>{let g=d;const b=[];for(b.unshift(g.internal.path);g.internal.parent;)g=g.internal.parent,g.internal.path!=="/"&&b.unshift(g.internal.path);const E=t==="/"?b.join(""):[t,...b].join("");return{route:d,path:E,toPath:Y.compile(E),fromPath:Y.match(E)}}),v=i.map(d=>{const g=[];for(const{route:b,fromPath:E}of F)E(d)&&g.push(b);return g}),S=c.attach({and:{source:n,effect:(d,g)=>{let{path:b,query:E,replace:q}=g;if(!d)throw new Error("history not found");const I={pathname:b,search:"?".concat(H.stringify(E))};q?d.replace(I):d.push(I)}},or:{name:"navigateFx",sid:"t8znvj"}}),P=c.createEffect(d=>{const g=c.scopeBind($);if(g({pathname:d.location.pathname,query:V({},H.parse(d.location.search))}),!d)throw new Error;d.listen(b=>{let{location:E}=b;g({pathname:E.pathname,query:V({},H.parse(E.search))})})},{name:"subscribeHistoryFx",sid:"hmilkw"}),A=c.attach({and:{source:{query:a,path:i},effect:async d=>{let{query:g,path:b}=d;for(const{route:E,fromPath:q}of F){const I=q(b),[M,f]=[c.scopeBind(E.internal.close),c.scopeBind(E.internal.navigated)];I?f({query:g,params:I.params}):M()}}},or:{name:"openRoutesByPathFx",sid:"eh61hv"}});for(const{route:d,toPath:g}of F)c.sample({and:[{clock:d.internal.openFx.doneData,filter:b=>(b==null?void 0:b.navigate)!==!1,fn:b=>{var E;return{path:g(b&&"params"in b?b.params:void 0),query:(E=b==null?void 0:b.query)!==null&&E!==void 0?E:{},replace:b==null?void 0:b.replace}},target:l}],or:{sid:"fuznc4"}});return c.sample({and:[{clock:o,target:n}],or:{sid:"gfc18r"}}),c.sample({and:[{clock:n,filter:Boolean,target:P}],or:{sid:"gtmoo5"}}),c.sample({and:[{clock:$,fn:d=>({path:d.pathname,query:d.query}),target:c.withFactory({sid:"rwfpgy",fn:()=>ye.spread({targets:{path:i,query:a}}),name:"target",method:"spread"})}],or:{sid:"gwxg8b"}}),c.sample({and:[{clock:$,fn:d=>({path:d.pathname,query:d.query}),target:A}],or:{sid:"hrpxgj"}}),c.sample({and:[{clock:l,source:i,fn:(d,g)=>V({path:d},g),target:S}],or:{sid:"i87r9d"}}),{$query:a,$path:i,$activeRoutes:v,back:O,forward:j,navigate:l,routes:r,setHistory:o,mappedRoutes:F,trackQuery:je({$activeRoutes:v,$query:a,navigate:l}),"@@unitShape":()=>({query:a,path:i,activeRoutes:v,onBack:O,onForward:j,onNavigate:l})}}function Me(e){const t=c.createStore(null,{name:"$params",sid:"-ui6zqo"}),r=c.createStore(!1,{name:"$isOpened",sid:"p6gokr"}),n=e,a=c.createEvent({name:"open",sid:"55xtzu"}),i=c.createEvent({name:"opened",sid:"tidivr"}),o=c.createEvent({name:"openedOnServer",sid:"8drh93"}),l=c.createEvent({name:"openedOnClient",sid:"-pj4ssy"}),O=c.createEvent({name:"close",sid:"-9osjjv"}),j=c.createEvent({name:"closed",sid:"hnb5jj"});return c.sample({and:[{clock:a,target:i}],or:{sid:"-v1zz6f"}}),c.split({and:[{source:i,match:()=>typeof window>"u"?"server":"client",cases:{server:o,client:l}}],or:{sid:"-unpbr1"}}),c.sample({and:[{clock:O,target:j}],or:{sid:"-u77hy7"}}),c.sample({and:[{clock:[i.map(()=>!0),j.map(()=>!1)],target:r}],or:{sid:"-u4gize"}}),{$params:t,$isOpened:r,$isPending:n,open:a,opened:i,openedOnClient:l,openedOnServer:o,close:O,closed:j,"@@unitShape":()=>({params:t,isOpened:r,isPending:n,onOpen:a})}}function Le(e){const{route:t,beforeOpen:r,openOn:n,cancelOn:a}=e,i=c.createEffect(async l=>{for(const O of[].concat(r))await O(l)},{name:"openFx",sid:"14ykg2"}),o=Me(i.pending);return c.sample({and:[{clock:t.open,target:i}],or:{sid:"-s8ttzz"}}),c.sample({and:[{clock:t.opened,fn:l=>l&&"params"in l?l.params:null,target:o.$params}],or:{sid:"-1t3nrm"}}),n&&c.sample({and:[{clock:n,source:{params:o.$params},fn:l=>{let{params:O}=l;return{params:O}},target:o.open}],or:{sid:"-1cltx2"}}),a&&c.sample({and:[{clock:[t.closed].concat(a),target:o.close}],or:{sid:"-w4048"}}),o}exports.chainRoute=Le;exports.createRoute=we;exports.createRouter=Be;exports.parameters=N;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("effector");function D(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),r.push.apply(r,n)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?D(Object(r),!0).forEach(function(n){ee(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):D(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function ee(e,t,r){return(t=re(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function re(e){var t=te(e,"string");return typeof t=="symbol"?t:t+""}function te(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function ne(e){let t;const r=i.createEffect(()=>{var b;return(b=t)===null||b===void 0?void 0:b()},{name:"waitForAsyncBundleFx",sid:"-au0m0h"}),n=i.createEffect(async()=>{for(const f of(b=e.beforeOpen)!==null&&b!==void 0?b:[]){var b;await f()}},{name:"beforeOpenFx",sid:"-iy13uf"}),a=i.createEffect(async b=>{await r(),await n();const f=e.parent;return f&&await f.internal.openFx(E(E({},b??{params:{}}),{},{navigate:!1})),b},{name:"openFx",sid:"cbmc2y"}),o=i.createStore({},{name:"$params",sid:"-cxehz9"}),s=i.createStore(!1,{name:"$isOpened",sid:"-561dht"}),c=a.pending,u=i.createEvent({name:"open",sid:"hyxmmx"}),m=i.createEvent({name:"close",sid:"-wvbr5n"}),O=i.createEvent({name:"opened",sid:"-qni80y"}),l=i.createEvent({name:"openedOnServer",sid:"eh9oki"}),h=i.createEvent({name:"openedOnClient",sid:"eet6mh"}),d=i.createEvent({name:"navigated",sid:"-rnvpuc"}),j=i.createEvent({name:"closed",sid:"w9iziz"});i.sample({and:[{clock:u,target:a}],or:{sid:"u86cfp"}});const S={};return i.sample({and:[{clock:d,fn:b=>b&&"params"in b?E({},b.params):S,target:o}],or:{sid:"ymu9q6"}}),i.split({and:[{source:d,match:()=>typeof window>"u"?"server":"client",cases:{server:l,client:h}}],or:{sid:"z4zhb3"}}),i.sample({and:[{clock:[h,l],target:O}],or:{sid:"-zf2y9u"}}),i.sample({and:[{clock:m,target:j}],or:{sid:"-z0saug"}}),i.sample({and:[{clock:[O.map(()=>!0),j.map(()=>!1)],target:s}],or:{sid:"-yy1bvn"}}),E(E({$params:o,$isOpened:s,$isPending:c,open:u,closed:j,opened:O,openedOnClient:h,openedOnServer:l},e),{},{internal:{navigated:d,close:m,openFx:a,setAsyncImport:b=>t=b},"@@unitShape":()=>({params:o,isPending:c,isOpened:s,onOpen:u})})}const ae=Symbol("any"),oe=Symbol("number"),se=Symbol("string"),ie=Symbol("array"),ce=Symbol("boolean"),F={any:ae,number:oe,string:se,array:ie,boolean:ce};function C(e,t){for(const r of e)if(t.includes(r))return!0;return!1}function z(e,t){for(const r in t){const n=t[r];if(Array.isArray(n)&&(!e[r]||JSON.stringify(n)!==e[r]))return!1;switch(typeof n){case"number":{if(!e[r]||n.toString()!==e[r])return!1;break}case"object":{if(!e[r]||JSON.stringify(n)!==e[r])return!1;break}case"string":{if(!e[r]||n!==e[r])return!1;break}case"boolean":{if(!e[r]||!["0","1","false","true"].includes(e[r]))return!1;break}}switch(n){case F.any:{if(!e[r])return!1;break}case F.string:{if(!e[r]||Array.isArray(e[r]))return!1;break}case F.array:{if(!e[r]||!Array.isArray(e[r]))return!1;break}case F.number:{if(!e[r]||Array.isArray(e[r])||isNaN(parseInt(e[r]))&&isNaN(parseFloat(e[r])))return!1;break}case F.boolean:{if(!e[r]||Array.isArray(e[r])||!["0","1","false","true"].includes(e[r]))return!1;break}}}return!0}function ue(e,t){const r={};for(const n in t){const a=t[n],o=e[n];if(Array.isArray(a)){const s=e[n];r[n]=s;continue}switch(typeof a){case"number":{r[n]=isNaN(parseInt(o))?parseFloat(o):parseInt(o);break}case"object":{r[n]=JSON.parse(o);break}case"string":r[n]=o;case"boolean":{r[n]=o==="1"||o==="true";break}}switch(a){case F.any:case F.string:case F.array:{r[n]=e[n];break}case F.number:{const s=e[n];r[n]=isNaN(parseInt(s))?parseFloat(s):parseInt(s);break}case F.boolean:{const s=e[n];r[n]=s==="1"||s==="true";break}}}return r}function fe(e){let{$activeRoutes:t,$query:r,navigate:n}=e;return a=>{const{parameters:o,forRoutes:s}=a,c=i.createStore(!1,{name:"$entered",sid:"lde75p"}),u=i.createEvent({name:"entered",sid:"-ggrer9"}),m=i.createEvent({name:"exited",sid:"xzl0hy"}),O=i.createEvent({name:"exit",sid:"-9k6g49"}),l=i.createEvent({name:"changeEntered",sid:"-ibka8"});return i.sample({and:[{clock:l,target:c}],or:{sid:"-hadp7p"}}),i.sample({and:[{source:{activeRoutes:t,query:r},filter:h=>{let{activeRoutes:d,query:j}=h;return(!s||C(s,d))&&z(j,o)},fn:h=>{let{query:d}=h;return ue(d,o)},target:[u,l.prepend(()=>!0)]}],or:{sid:"-gw31sb"}}),i.sample({and:[{source:{activeRoutes:t,query:r,entered:c},filter:h=>{let{activeRoutes:d,query:j,entered:S}=h;return S&&!((!s||C(s,d))&&z(j,o))},target:[m.prepend(()=>{}),l.prepend(()=>!1)]}],or:{sid:"-gfl7zh"}}),i.sample({and:[{clock:O,source:r,fn:(h,d)=>{if(d&&d.ignoreParams){const j={};for(const S of d.ignoreParams)h[S]&&(j[S]=h[S]);return{query:j}}return{query:{}}},target:n}],or:{sid:"-fwcf7u"}}),{entered:u,exited:m,exit:O}}}const V="%[a-f0-9]{2}",U=new RegExp("("+V+")|([^%]+?)","gi"),B=new RegExp("("+V+")+","gi");function $(e,t){try{return[decodeURIComponent(e.join(""))]}catch{}if(e.length===1)return e;t=t||1;const r=e.slice(0,t),n=e.slice(t);return Array.prototype.concat.call([],$(r),$(n))}function le(e){try{return decodeURIComponent(e)}catch{let t=e.match(U)||[];for(let r=1;r<t.length;r++)e=$(t,r).join(""),t=e.match(U)||[];return e}}function de(e){const t={"%FE%FF":"��","%FF%FE":"��"};let r=B.exec(e);for(;r;){try{t[r[0]]=decodeURIComponent(r[0])}catch{const a=le(r[0]);a!==r[0]&&(t[r[0]]=a)}r=B.exec(e)}t["%C2"]="�";const n=Object.keys(t);for(const a of n)e=e.replace(new RegExp(a,"g"),t[a]);return e}function pe(e){if(typeof e!="string")throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof e+"`");try{return decodeURIComponent(e)}catch{return de(e)}}function me(e,t){const r={};if(Array.isArray(t))for(const n of t){const a=Object.getOwnPropertyDescriptor(e,n);a!=null&&a.enumerable&&Object.defineProperty(r,n,a)}else for(const n of Reflect.ownKeys(e)){const a=Object.getOwnPropertyDescriptor(e,n);if(a.enumerable){const o=e[n];t(n,o,e)&&Object.defineProperty(r,n,a)}}return r}function K(e,t){if(!(typeof e=="string"&&typeof t=="string"))throw new TypeError("Expected the arguments to be of type `string`");if(e===""||t==="")return[];const r=e.indexOf(t);return r===-1?[]:[e.slice(0,r),e.slice(r+t.length)]}const ye=e=>e==null,be=e=>encodeURIComponent(e).replaceAll(/[!'()*]/g,t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`),A=Symbol("encodeFragmentIdentifier");function ge(e){switch(e.arrayFormat){case"index":return t=>(r,n)=>{const a=r.length;return n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,[g(t,e),"[",a,"]"].join("")]:[...r,[g(t,e),"[",g(a,e),"]=",g(n,e)].join("")]};case"bracket":return t=>(r,n)=>n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,[g(t,e),"[]"].join("")]:[...r,[g(t,e),"[]=",g(n,e)].join("")];case"colon-list-separator":return t=>(r,n)=>n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,[g(t,e),":list="].join("")]:[...r,[g(t,e),":list=",g(n,e)].join("")];case"comma":case"separator":case"bracket-separator":{const t=e.arrayFormat==="bracket-separator"?"[]=":"=";return r=>(n,a)=>a===void 0||e.skipNull&&a===null||e.skipEmptyString&&a===""?n:(a=a===null?"":a,n.length===0?[[g(r,e),t,g(a,e)].join("")]:[[n,g(a,e)].join(e.arrayFormatSeparator)])}default:return t=>(r,n)=>n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,g(t,e)]:[...r,[g(t,e),"=",g(n,e)].join("")]}}function he(e){let t;switch(e.arrayFormat){case"index":return(r,n,a)=>{if(t=/\[(\d*)]$/.exec(r),r=r.replace(/\[\d*]$/,""),!t){a[r]=n;return}a[r]===void 0&&(a[r]={}),a[r][t[1]]=n};case"bracket":return(r,n,a)=>{if(t=/(\[])$/.exec(r),r=r.replace(/\[]$/,""),!t){a[r]=n;return}if(a[r]===void 0){a[r]=[n];return}a[r]=[...a[r],n]};case"colon-list-separator":return(r,n,a)=>{if(t=/(:list)$/.exec(r),r=r.replace(/:list$/,""),!t){a[r]=n;return}if(a[r]===void 0){a[r]=[n];return}a[r]=[...a[r],n]};case"comma":case"separator":return(r,n,a)=>{const o=typeof n=="string"&&n.includes(e.arrayFormatSeparator),s=typeof n=="string"&&!o&&v(n,e).includes(e.arrayFormatSeparator);n=s?v(n,e):n;const c=o||s?n.split(e.arrayFormatSeparator).map(u=>v(u,e)):n===null?n:v(n,e);a[r]=c};case"bracket-separator":return(r,n,a)=>{const o=/(\[])$/.test(r);if(r=r.replace(/\[]$/,""),!o){a[r]=n&&v(n,e);return}const s=n===null?[]:v(n,e).split(e.arrayFormatSeparator);if(a[r]===void 0){a[r]=s;return}a[r]=[...a[r],...s]};default:return(r,n,a)=>{if(a[r]===void 0){a[r]=n;return}a[r]=[...[a[r]].flat(),n]}}}function L(e){if(typeof e!="string"||e.length!==1)throw new TypeError("arrayFormatSeparator must be single character string")}function g(e,t){return t.encode?t.strict?be(e):encodeURIComponent(e):e}function v(e,t){return t.decode?pe(e):e}function M(e){return Array.isArray(e)?e.sort():typeof e=="object"?M(Object.keys(e)).sort((t,r)=>Number(t)-Number(r)).map(t=>e[t]):e}function J(e){const t=e.indexOf("#");return t!==-1&&(e=e.slice(0,t)),e}function Oe(e){let t="";const r=e.indexOf("#");return r!==-1&&(t=e.slice(r)),t}function q(e,t,r){return r==="string"&&typeof e=="string"?e:typeof r=="function"&&typeof e=="string"?r(e):t.parseBooleans&&e!==null&&(e.toLowerCase()==="true"||e.toLowerCase()==="false")?e.toLowerCase()==="true":r==="number"&&!Number.isNaN(Number(e))&&typeof e=="string"&&e.trim()!==""||t.parseNumbers&&!Number.isNaN(Number(e))&&typeof e=="string"&&e.trim()!==""?Number(e):e}function R(e){e=J(e);const t=e.indexOf("?");return t===-1?"":e.slice(t+1)}function I(e,t){t={decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1,types:Object.create(null),...t},L(t.arrayFormatSeparator);const r=he(t),n=Object.create(null);if(typeof e!="string"||(e=e.trim().replace(/^[?#&]/,""),!e))return n;for(const a of e.split("&")){if(a==="")continue;const o=t.decode?a.replaceAll("+"," "):a;let[s,c]=K(o,"=");s===void 0&&(s=o),c=c===void 0?null:["comma","separator","bracket-separator"].includes(t.arrayFormat)?c:v(c,t),r(v(s,t),c,n)}for(const[a,o]of Object.entries(n))if(typeof o=="object"&&o!==null&&t.types[a]!=="string")for(const[s,c]of Object.entries(o)){const u=t.types[a]?t.types[a].replace("[]",""):void 0;o[s]=q(c,t,u)}else typeof o=="object"&&o!==null&&t.types[a]==="string"?n[a]=Object.values(o).join(t.arrayFormatSeparator):n[a]=q(o,t,t.types[a]);return t.sort===!1?n:(t.sort===!0?Object.keys(n).sort():Object.keys(n).sort(t.sort)).reduce((a,o)=>{const s=n[o];return a[o]=s&&typeof s=="object"&&!Array.isArray(s)?M(s):s,a},Object.create(null))}function Q(e,t){if(!e)return"";t={encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:",",...t},L(t.arrayFormatSeparator);const r=s=>t.skipNull&&ye(e[s])||t.skipEmptyString&&e[s]==="",n=ge(t),a={};for(const[s,c]of Object.entries(e))r(s)||(a[s]=c);const o=Object.keys(a);return t.sort!==!1&&o.sort(t.sort),o.map(s=>{const c=e[s];return c===void 0?"":c===null?g(s,t):Array.isArray(c)?c.length===0&&t.arrayFormat==="bracket-separator"?g(s,t)+"[]":c.reduce(n(s),[]).join("&"):g(s,t)+"="+g(c,t)}).filter(s=>s.length>0).join("&")}function G(e,t){var a;t={decode:!0,...t};let[r,n]=K(e,"#");return r===void 0&&(r=e),{url:((a=r==null?void 0:r.split("?"))==null?void 0:a[0])??"",query:I(R(e),t),...t&&t.parseFragmentIdentifier&&n?{fragmentIdentifier:v(n,t)}:{}}}function W(e,t){t={encode:!0,strict:!0,[A]:!0,...t};const r=J(e.url).split("?")[0]||"",n=R(e.url),a={...I(n,{sort:!1}),...e.query};let o=Q(a,t);o&&(o=`?${o}`);let s=Oe(e.url);if(typeof e.fragmentIdentifier=="string"){const c=new URL(r);c.hash=e.fragmentIdentifier,s=t[A]?c.hash:`#${e.fragmentIdentifier}`}return`${r}${o}${s}`}function X(e,t,r){r={parseFragmentIdentifier:!0,[A]:!1,...r};const{url:n,query:a,fragmentIdentifier:o}=G(e,r);return W({url:n,query:me(a,t),fragmentIdentifier:o},r)}function we(e,t,r){const n=Array.isArray(t)?a=>!t.includes(a):(a,o)=>!t(a,o);return X(e,n,r)}const x=Object.freeze(Object.defineProperty({__proto__:null,exclude:we,extract:R,parse:I,parseUrl:G,pick:X,stringify:Q,stringifyUrl:W},Symbol.toStringTag,{value:"Module"}));function je(e){return t=>{const r=t.split("/").filter(Boolean);let n=null;function a(c,u){n||(n={}),n[c]=u}if(e.length===0)return r.length===0?{path:t,params:null}:null;for(let c=0;c<e.length;c++){let u=r[c];const m=e[c];switch(m.type){case"const":{if(u!==m.name)return null;continue}case"parameter":{const{arrayProps:O,genericProps:l,required:h}=m.payload;if(O){var o;const d=[];for(;u&&d.length<((s=O.max)!==null&&s!==void 0?s:1/0);){var s;switch(l==null?void 0:l.type){case"number":{if(isNaN(+u))return null;d.push(+u);break}case"union":{if(!l.items.includes(u))return null;d.push(u);break}default:{d.push(u);break}}u=r[c+d.length]}if(d.length<((o=O.min)!==null&&o!==void 0?o:0)||r[c+d.length]&&!e[c+1])return null;a(m.name,d);break}if(h&&!u)return null;if(!u){a(m.name,void 0);continue}switch(l==null?void 0:l.type){case"number":{if(isNaN(+u))return null;a(m.name,+u);break}case"union":{if(!l.items.includes(u))return null;a(m.name,u);break}default:{a(m.name,u);break}}}}}return{path:t,params:n}}}function Fe(e){if(!e)return null;const t=e[1];let r,n,a;for(const o of e.slice(2))if(o){if(o.includes("<")){r=o.replace("<","").replace(">","");continue}if(o.includes("{")&&(n=o.replace("{","").replace("}","").split(",").map(s=>parseInt(s))),["*","?","+"].includes(o)){a=o;continue}}return{name:t,genericProps:r,arrayProps:n,modificator:a}}function Se(e){return t=>{const r=[];if(e.length===0)return"/";for(const n of e)switch(n.type){case"const":{r.push(n.name);break}case"parameter":{if(!t[n.name])continue;if(Array.isArray(t[n.name]))for(const a of t[n.name])r.push(a.toString());else r.push(t[n.name].toString());break}}return"/".concat(r.join("/"))}}function _(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),r.push.apply(r,n)}return r}function T(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?_(Object(r),!0).forEach(function(n){ve(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):_(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function ve(e,t,r){return(t=Pe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Pe(e){var t=ke(e,"string");return typeof t=="symbol"?t:t+""}function ke(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Ee(e){const t=[],r=/:(\w+)(<[\w|]+>)?({\d+\,\d+})?([+*?])?/,n=e.split("/").filter(Boolean);for(let a=0;a<n.length;a++){const o=n[a];if(!o)continue;const s=Fe(o.match(r));if(!s){t.push({type:"const",name:o,payload:void 0});continue}const{arrayProps:c,genericProps:u,modificator:m,name:O}=s;if(!O)throw new Error('Invalid path: "'.concat(e,'". Name for argument must be provided'));const l={type:"parameter",name:O,payload:{required:!0}};switch(u&&u==="number"&&(l.payload.genericProps={type:"number"}),u&&u.includes("|")&&(l.payload.genericProps={type:"union",items:u.split("|")}),m){case"*":{l.payload.arrayProps={};break}case"+":{l.payload.arrayProps={min:1};break}case"?":{l.payload.required=!1;break}}c&&(l.payload.arrayProps=T(T({},l.payload.arrayProps),{},{min:c[0],max:c[1]})),t.push(l)}return{parse:je(t),build:Se(t)}}function H(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),r.push.apply(r,n)}return r}function N(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?H(Object(r),!0).forEach(function(n){xe(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):H(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function xe(e,t,r){return(t=Ne(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ne(e){var t=$e(e,"string");return typeof t=="symbol"?t:t+""}function $e(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Ae(e){const{base:t="/",routes:r}=e,n=i.createStore(null,{and:{serialize:"ignore"},name:"$history",sid:"-c46cwg"}),a=i.createStore({query:{},path:null},{name:"$locationState",sid:"-xif7zo"}),o=a.map(f=>f.query),s=a.map(f=>f.path),c=i.createEvent({name:"setHistory",sid:"5o2aum"}),u=i.createEvent({name:"navigate",sid:"-kee8mo"}),m=i.createEvent({name:"back",sid:"-uo6kro"}),O=i.createEvent({name:"forward",sid:"-je6ypy"}),l=i.createEvent({name:"locationUpdated",sid:"x2x22"}),h=r.map(f=>{let y=f;const p=[];for(p.unshift(y.path);y.parent;)y=y.parent,y.path!=="/"&&p.unshift(y.path);const w=t==="/"?p.join(""):[t,...p].join(""),{build:k,parse:P}=Ee(w);return{route:f,path:w,build:k,parse:P}}),d=s.map(f=>{const y=[];if(!f)return y;for(const{route:p,parse:w}of h)w(f)&&y.push(p);return y}),j=i.attach({and:{source:n,effect:(f,y)=>{let{path:p,query:w,replace:k}=y;if(!f)throw new Error("history not found");const P={pathname:p,search:"?".concat(x.stringify(w))};k?f.replace(P):f.push(P)}},or:{name:"navigateFx",sid:"9h4a5f"}}),S=i.createEffect(f=>{const y=i.scopeBind(l);if(y({pathname:f.location.pathname,query:N({},x.parse(f.location.search))}),!f)throw new Error;f.listen(p=>{let{location:w}=p;y({pathname:w.pathname,query:N({},x.parse(w.search))})})},{name:"subscribeHistoryFx",sid:"-o0gyju"}),b=i.attach({and:{source:{query:o,path:s},effect:async f=>{let{query:y,path:p}=f;for(const{route:w,parse:k}of h){const P=k(p),[Y,Z]=[i.scopeBind(w.internal.close),i.scopeBind(w.internal.navigated)];P?Z({query:y,params:P.params}):Y()}}},or:{name:"openRoutesByPathFx",sid:"dzro9q"}});for(const{route:f,build:y}of h)i.sample({and:[{clock:f.internal.openFx.doneData,filter:p=>(p==null?void 0:p.navigate)!==!1,fn:p=>{var w;return{path:y(p&&"params"in p?p.params:void 0),query:(w=p==null?void 0:p.query)!==null&&w!==void 0?w:{},replace:p==null?void 0:p.replace}},target:u}],or:{sid:"htdbac"}});return i.sample({and:[{clock:c,target:n}],or:{sid:"sn7fxn"}}),i.sample({and:[{clock:n,filter:Boolean,target:S}],or:{sid:"spyewg"}}),i.sample({and:[{clock:l,fn:f=>({path:f.pathname,query:f.query}),target:a}],or:{sid:"t4sux7"}}),i.sample({and:[{clock:l,fn:f=>({path:f.pathname,query:f.query}),target:b}],or:{sid:"tlaoq1"}}),i.sample({and:[{clock:u,source:s,fn:(f,y)=>N({path:f},y),target:j}],or:{sid:"u1siiv"}}),{$query:o,$path:s,$activeRoutes:d,back:m,forward:O,navigate:u,routes:r,setHistory:c,mappedRoutes:h,trackQuery:fe({$activeRoutes:d,$query:o,navigate:u}),"@@unitShape":()=>({query:o,path:s,activeRoutes:d,onBack:m,onForward:O,onNavigate:u})}}function Re(e){const t=i.createStore(null,{name:"$params",sid:"-ui6zqo"}),r=i.createStore(!1,{name:"$isOpened",sid:"p6gokr"}),n=e,a=i.createEvent({name:"open",sid:"55xtzu"}),o=i.createEvent({name:"opened",sid:"tidivr"}),s=i.createEvent({name:"openedOnServer",sid:"8drh93"}),c=i.createEvent({name:"openedOnClient",sid:"-pj4ssy"}),u=i.createEvent({name:"close",sid:"-9osjjv"}),m=i.createEvent({name:"closed",sid:"hnb5jj"});return i.sample({and:[{clock:a,target:o}],or:{sid:"-v1zz6f"}}),i.split({and:[{source:o,match:()=>typeof window>"u"?"server":"client",cases:{server:s,client:c}}],or:{sid:"-unpbr1"}}),i.sample({and:[{clock:u,target:m}],or:{sid:"-u77hy7"}}),i.sample({and:[{clock:[o.map(()=>!0),m.map(()=>!1)],target:r}],or:{sid:"-u4gize"}}),{$params:t,$isOpened:r,$isPending:n,open:a,opened:o,openedOnClient:c,openedOnServer:s,close:u,closed:m,path:null,"@@unitShape":()=>({params:t,isOpened:r,isPending:n,onOpen:a})}}function Ie(e){const{route:t,beforeOpen:r,openOn:n,cancelOn:a}=e,o=i.createEffect(async c=>{for(const u of[].concat(r))await u(c)},{name:"openFx",sid:"x22os2"}),s=Re(o.pending);return i.sample({and:[{clock:t.open,target:o}],or:{sid:"2j17t"}}),i.sample({and:[{clock:t.opened,fn:c=>c&&"params"in c?c.params:null,target:s.$params}],or:{sid:"5a06m"}}),n&&i.sample({and:[{clock:n,source:{params:s.$params},fn:c=>{let{params:u}=c;return{params:u}},target:s.open}],or:{sid:"lru16"}}),a&&i.sample({and:[{clock:[t.closed].concat(a),target:s.close}],or:{sid:"129nu0"}}),s}exports.chainRoute=Ie;exports.createRoute=ne;exports.createRouter=Ae;exports.parameters=F;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Builder } from '@argon-router/paths';
|
|
1
2
|
import { Effect } from 'effector';
|
|
2
3
|
import { Event as Event_2 } from 'effector';
|
|
3
4
|
import { EventCallable } from 'effector';
|
|
4
5
|
import { History as History_2 } from 'history';
|
|
5
|
-
import {
|
|
6
|
-
import { ParseUrlParams } from '
|
|
6
|
+
import { Parser } from '@argon-router/paths';
|
|
7
|
+
import { ParseUrlParams } from '@argon-router/paths';
|
|
7
8
|
import { Store } from 'effector';
|
|
8
9
|
import { StoreWritable } from 'effector';
|
|
9
10
|
import { Unit } from 'effector';
|
|
@@ -22,6 +23,47 @@ declare type BooleanParameter = typeof booleanSymbol;
|
|
|
22
23
|
|
|
23
24
|
declare const booleanSymbol: unique symbol;
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @link https://movpushmov.dev/argon-router/core/chain-route.html
|
|
28
|
+
* @param props Chain route props
|
|
29
|
+
* @returns `Virtual route`
|
|
30
|
+
* @example ```ts
|
|
31
|
+
* import { createRoute, chainRoute } from '@argon-router/core';
|
|
32
|
+
* import { createEvent, createEffect } from 'effector';
|
|
33
|
+
*
|
|
34
|
+
* // base example
|
|
35
|
+
* const route = createRoute({ path: '/profile' });
|
|
36
|
+
*
|
|
37
|
+
* const authorized = createEvent();
|
|
38
|
+
* const rejected = createEvent();
|
|
39
|
+
*
|
|
40
|
+
* const checkAuthorizationFx = createEffect(async ({ params }) => {
|
|
41
|
+
* // some logic
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* sample({
|
|
45
|
+
* clock: checkAuthorizationFx.doneData,
|
|
46
|
+
* target: authorized,
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* sample({
|
|
50
|
+
* clock: checkAuthorizationFx.failData,
|
|
51
|
+
* target: rejected,
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* const virtual = chainRoute({
|
|
55
|
+
* route,
|
|
56
|
+
* beforeOpen: checkAuthorizationFx,
|
|
57
|
+
* openOn: authorized,
|
|
58
|
+
* cancelOn: rejected,
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* // chain already chained routes
|
|
62
|
+
* const postRoute = createRoute({ path: '/post/:id' });
|
|
63
|
+
* const authorizedRoute = chainRoute({ route: postRoute, ... });
|
|
64
|
+
* const postLoadedRoute = chainRoute({ route: authorizedRoute, ... });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
25
67
|
export declare function chainRoute<T>(props: ChainRouteProps<T>): VirtualRoute<T>;
|
|
26
68
|
|
|
27
69
|
declare interface ChainRouteProps<T> {
|
|
@@ -37,8 +79,66 @@ declare interface Config<T> {
|
|
|
37
79
|
beforeOpen?: Effect<void, any, any>[];
|
|
38
80
|
}
|
|
39
81
|
|
|
40
|
-
|
|
41
|
-
|
|
82
|
+
/**
|
|
83
|
+
* @description Creates argon route
|
|
84
|
+
* @param config Route config
|
|
85
|
+
* @returns `Route\<Params\>`
|
|
86
|
+
* @link https://movpushmov.dev/argon-router/core/create-route.html
|
|
87
|
+
* @example ```ts
|
|
88
|
+
* import { createRoute } from '@argon-router/core';
|
|
89
|
+
*
|
|
90
|
+
* // basic
|
|
91
|
+
* const route = createRoute({ path: '/route' });
|
|
92
|
+
* route.open();
|
|
93
|
+
*
|
|
94
|
+
* // with params
|
|
95
|
+
* const postRoute = createRoute({ path: '/post/:id' });
|
|
96
|
+
* // ^--- Route<{ id: string }>
|
|
97
|
+
*
|
|
98
|
+
* // with parent
|
|
99
|
+
* const profile = createRoute({ path: '/profile/:id' });
|
|
100
|
+
*
|
|
101
|
+
* const friends = createRoute({ path: '/friends', parent: profile });
|
|
102
|
+
* const posts = createRoute({ path: '/posts', parent: profile });
|
|
103
|
+
*
|
|
104
|
+
* posts.open(); // profile.$isOpened -> true, posts.$isOpened -> true
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function createRoute<T extends string, Params = ParseUrlParams<T>>(config: Config<T>): Route<Params>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @description Creates argon router
|
|
111
|
+
* @param config Router config
|
|
112
|
+
* @returns `Router`
|
|
113
|
+
* @link https://movpushmov.dev/argon-router/core/create-router.html
|
|
114
|
+
*
|
|
115
|
+
* `be careful! router need to be initialzed with setHistory event,
|
|
116
|
+
* which requires memory or browser history from history package.`
|
|
117
|
+
*
|
|
118
|
+
* @example ```ts
|
|
119
|
+
* import { createRouter } from '@argon-router/core';
|
|
120
|
+
* import { routes } from './routes';
|
|
121
|
+
*
|
|
122
|
+
* // create router
|
|
123
|
+
* const router = createRouter({
|
|
124
|
+
* routes: [routes.route1, routes.route2],
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* // override path or query
|
|
128
|
+
* sample({
|
|
129
|
+
* clock: goToPage,
|
|
130
|
+
* fn: () => ({ path: '/page' }),
|
|
131
|
+
* target: router.navigate,
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* sample({
|
|
135
|
+
* clock: addQuery,
|
|
136
|
+
* fn: () => ({ query: { param1: 'hello', params2: [1, 2] } }),
|
|
137
|
+
* target: router.navigate,
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
42
142
|
export declare function createRouter(config: RouterConfig): Router;
|
|
43
143
|
|
|
44
144
|
export declare type NavigatePayload = {
|
|
@@ -96,6 +196,9 @@ export declare interface Route<T = void> {
|
|
|
96
196
|
openedOnServer: Event_2<RouteOpenedPayload<T>>;
|
|
97
197
|
openedOnClient: Event_2<RouteOpenedPayload<T>>;
|
|
98
198
|
closed: Event_2<void>;
|
|
199
|
+
path: string;
|
|
200
|
+
parent?: Route<any>;
|
|
201
|
+
beforeOpen?: Effect<any, any, any>[];
|
|
99
202
|
'@@unitShape': () => {
|
|
100
203
|
params: Store<T>;
|
|
101
204
|
isOpened: Store<boolean>;
|
|
@@ -117,12 +220,37 @@ export declare interface Router {
|
|
|
117
220
|
navigate: EventCallable<NavigatePayload>;
|
|
118
221
|
setHistory: EventCallable<History_2>;
|
|
119
222
|
routes: Route<any>[];
|
|
223
|
+
/**
|
|
224
|
+
* @description Creates query params tracker
|
|
225
|
+
* @param config Query tacker config
|
|
226
|
+
* @link https://movpushmov.dev/argon-router/core/track-query.html
|
|
227
|
+
* @example ```ts
|
|
228
|
+
* import { parameters } from '@argon-router/core';
|
|
229
|
+
* import { router } from '@shared/router';
|
|
230
|
+
* import { createDialog } from '...';
|
|
231
|
+
*
|
|
232
|
+
* const dialog = createDialog();
|
|
233
|
+
* const tracker = router.trackQuery({
|
|
234
|
+
* dialog: 'team-member',
|
|
235
|
+
* id: parameters.number,
|
|
236
|
+
* });
|
|
237
|
+
*
|
|
238
|
+
* // triggered for:
|
|
239
|
+
* // /team?dialog=team-member&id=1
|
|
240
|
+
* // /team?dialog=team-member&id=10000
|
|
241
|
+
*
|
|
242
|
+
* // not triggered for:
|
|
243
|
+
* // /team?dialog=team&id=1
|
|
244
|
+
* // /team?id=10000
|
|
245
|
+
* // /team?dialog=team&id=not_number
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
120
248
|
trackQuery: <ParametersConfig extends RawConfig>(config: QueryTrackerConfig<ParametersConfig>) => QueryTracker<ParametersConfig>;
|
|
121
249
|
mappedRoutes: {
|
|
122
250
|
route: Route<any>;
|
|
123
251
|
path: string;
|
|
124
|
-
|
|
125
|
-
|
|
252
|
+
build: Builder<any>;
|
|
253
|
+
parse: Parser<any>;
|
|
126
254
|
}[];
|
|
127
255
|
'@@unitShape': () => {
|
|
128
256
|
query: Store<Query>;
|
|
@@ -139,8 +267,6 @@ declare interface RouterConfig {
|
|
|
139
267
|
routes: Route<any>[];
|
|
140
268
|
}
|
|
141
269
|
|
|
142
|
-
declare type SafeParams<T> = T extends Record<string, never> ? void : T;
|
|
143
|
-
|
|
144
270
|
declare type StringParameter = typeof stringSymbol;
|
|
145
271
|
|
|
146
272
|
declare const stringSymbol: unique symbol;
|