@argon-router/core 0.4.0 → 0.5.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/dist/index.cjs +1 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +718 -638
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("effector"),ye=require("patronum");function W(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?W(Object(r),!0).forEach(function(n){he(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):W(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function he(e,t,r){return(t=ge(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ge(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=u.createEffect(()=>{var h;return(h=t)===null||h===void 0?void 0:h()},{name:"waitForAsyncBundleFx",sid:"tw7mq7"}),n=u.createEffect(async()=>{for(const A of(h=e.beforeOpen)!==null&&h!==void 0?h:[]){var h;await A()}},{name:"beforeOpenFx",sid:"ls74w9"}),a=u.createEffect(async h=>{await r(),await n();const A=e.parent;return A&&await A.internal.openFx(B(B({},h??{params:{}}),{},{historyIgnore:!0})),h},{name:"openFx",sid:"-hz9h5i"}),f=u.createStore({},{name:"$params",sid:"rstqrf"}),c=u.createStore(!1,{name:"$isOpened",sid:"-zgx6q9"}),l=a.pending,S=u.createEvent({name:"open",sid:"-cby6lj"}),D=u.createEvent({name:"close",sid:"7uwhl1"}),j=u.createEvent({name:"opened",sid:"44ryfn"}),v=u.createEvent({name:"openedOnServer",sid:"-prk6y1"}),P=u.createEvent({name:"openedOnClient",sid:"-fw2mlz"}),$=u.createEvent({name:"closed",sid:"10jxi5"});u.sample({and:[{clock:S,target:a}],or:{sid:"t7vx9v"}});const E={};return u.sample({and:[{clock:a.doneData,fn:h=>h&&"params"in h?B({},h.params):E,target:f}],or:{sid:"tna5vz"}}),u.split({and:[{source:a.doneData,match:()=>typeof window>"u"?"server":"client",cases:{server:v,client:P}}],or:{sid:"u5fdgw"}}),u.sample({and:[{clock:[P,v],target:j}],or:{sid:"ylqojg"}}),u.sample({and:[{clock:j,fn:()=>!0,target:c}],or:{sid:"yohni9"}}),u.sample({and:[{clock:D,target:$}],or:{sid:"z3c3j0"}}),u.sample({and:[{clock:$,fn:()=>!1,target:c}],or:{sid:"z632ht"}}),{$params:f,$isOpened:c,$isPending:l,open:S,closed:$,opened:j,openedOnClient:P,openedOnServer:v,internal:B({close:D,openFx:a,setAsyncImport:h=>t=h},e),"@@unitShape":()=>({params:f,isPending:l,isOpened:c,onOpen:S})}}var T={},G;function xe(){if(G)return T;G=1,Object.defineProperty(T,"__esModule",{value:!0}),T.TokenData=void 0,T.parse=v,T.compile=P,T.match=h,T.pathToRegexp=A,T.stringify=O;const e="/",t=i=>i,r=/^[$_\p{ID_Start}]$/u,n=/^[$\u200c\u200d\p{ID_Continue}]$/u,a="https://git.new/pathToRegexpError",f={"{":"{","}":"}","(":"(",")":")","[":"[","]":"]","+":"+","?":"?","!":"!"};function c(i){return i.replace(/[{}()\[\]+?!:*]/g,"\\$&")}function l(i){return i.replace(/[.+*?^${}()[\]|/\\]/g,"\\$&")}function*S(i){const o=[...i];let s=0;function m(){let d="";if(r.test(o[++s]))for(d+=o[s];n.test(o[++s]);)d+=o[s];else if(o[s]==='"'){let p=s;for(;s<o.length;){if(o[++s]==='"'){s++,p=0;break}o[s]==="\\"?d+=o[++s]:d+=o[s]}if(p)throw new TypeError(`Unterminated quote at ${p}: ${a}`)}if(!d)throw new TypeError(`Missing parameter name at ${s}: ${a}`);return d}for(;s<o.length;){const d=o[s],p=f[d];if(p)yield{type:p,index:s++,value:d};else if(d==="\\")yield{type:"ESCAPED",index:s++,value:o[s++]};else if(d===":"){const x=m();yield{type:"PARAM",index:s,value:x}}else if(d==="*"){const x=m();yield{type:"WILDCARD",index:s,value:x}}else yield{type:"CHAR",index:s,value:o[s++]}}return{type:"END",index:s,value:""}}class D{constructor(o){this.tokens=o}peek(){if(!this._peek){const o=this.tokens.next();this._peek=o.value}return this._peek}tryConsume(o){const s=this.peek();if(s.type===o)return this._peek=void 0,s.value}consume(o){const s=this.tryConsume(o);if(s!==void 0)return s;const{type:m,index:d}=this.peek();throw new TypeError(`Unexpected ${m} at ${d}, expected ${o}: ${a}`)}text(){let o="",s;for(;s=this.tryConsume("CHAR")||this.tryConsume("ESCAPED");)o+=s;return o}}class j{constructor(o){this.tokens=o}}T.TokenData=j;function v(i,o={}){const{encodePath:s=t}=o,m=new D(S(i));function d(x){const g=[];for(;;){const k=m.text();k&&g.push({type:"text",value:s(k)});const N=m.tryConsume("PARAM");if(N){g.push({type:"param",name:N});continue}const L=m.tryConsume("WILDCARD");if(L){g.push({type:"wildcard",name:L});continue}if(m.tryConsume("{")){g.push({type:"group",tokens:d("}")});continue}return m.consume(x),g}}const p=d("END");return new j(p)}function P(i,o={}){const{encode:s=encodeURIComponent,delimiter:m=e}=o,d=i instanceof j?i:v(i,o),p=$(d.tokens,m,s);return function(g={}){const[k,...N]=p(g);if(N.length)throw new TypeError(`Missing parameters: ${N.join(", ")}`);return k}}function $(i,o,s){const m=i.map(d=>E(d,o,s));return d=>{const p=[""];for(const x of m){const[g,...k]=x(d);p[0]+=g,p.push(...k)}return p}}function E(i,o,s){if(i.type==="text")return()=>[i.value];if(i.type==="group"){const d=$(i.tokens,o,s);return p=>{const[x,...g]=d(p);return g.length?[""]:[x]}}const m=s||t;return i.type==="wildcard"&&s!==!1?d=>{const p=d[i.name];if(p==null)return["",i.name];if(!Array.isArray(p)||p.length===0)throw new TypeError(`Expected "${i.name}" to be a non-empty array`);return[p.map((x,g)=>{if(typeof x!="string")throw new TypeError(`Expected "${i.name}/${g}" to be a string`);return m(x)}).join(o)]}:d=>{const p=d[i.name];if(p==null)return["",i.name];if(typeof p!="string")throw new TypeError(`Expected "${i.name}" to be a string`);return[m(p)]}}function h(i,o={}){const{decode:s=decodeURIComponent,delimiter:m=e}=o,{regexp:d,keys:p}=A(i,o),x=p.map(g=>s===!1?t:g.type==="param"?s:k=>k.split(m).map(s));return function(k){const N=d.exec(k);if(!N)return!1;const L=N[0],_=Object.create(null);for(let q=1;q<N.length;q++){if(N[q]===void 0)continue;const M=p[q-1],z=x[q-1];_[M.name]=z(N[q])}return{path:L,params:_}}}function A(i,o={}){const{delimiter:s=e,end:m=!0,sensitive:d=!1,trailing:p=!0}=o,x=[],g=[],k=d?"":"i",L=(Array.isArray(i)?i:[i]).map(M=>M instanceof j?M:v(M,o));for(const{tokens:M}of L)for(const z of b(M,0,[])){const me=w(z,s,x);g.push(me)}let _=`^(?:${g.join("|")})`;return p&&(_+=`(?:${l(s)}$)?`),_+=m?"$":`(?=${l(s)}|$)`,{regexp:new RegExp(_,k),keys:x}}function*b(i,o,s){if(o===i.length)return yield s;const m=i[o];if(m.type==="group"){const d=s.slice();for(const p of b(m.tokens,0,d))yield*b(i,o+1,p)}else s.push(m);yield*b(i,o+1,s)}function w(i,o,s){let m="",d="",p=!0;for(let x=0;x<i.length;x++){const g=i[x];if(g.type==="text"){m+=l(g.value),d+=g.value,p||(p=g.value.includes(o));continue}if(g.type==="param"||g.type==="wildcard"){if(!p&&!d)throw new TypeError(`Missing text after "${g.name}": ${a}`);g.type==="param"?m+=`(${y(o,p?"":d)}+)`:m+="([\\s\\S]+)",s.push(g),d="",p=!1;continue}}return m}function y(i,o){return o.length<2?i.length<2?`[^${l(i+o)}]`:`(?:(?!${l(i)})[^${l(o)}])`:i.length<2?`(?:(?!${l(o)})[^${l(i)}])`:`(?:(?!${l(o)}|${l(i)})[\\s\\S])`}function O(i){return i.tokens.map(function o(s,m,d){if(s.type==="text")return c(s.value);if(s.type==="group")return`{${s.tokens.map(o).join("")}}`;const x=U(s.name)&&I(d[m+1])?s.name:JSON.stringify(s.name);if(s.type==="param")return`:${x}`;if(s.type==="wildcard")return`*${x}`;throw new TypeError(`Unexpected token: ${s}`)}).join("")}function U(i){const[o,...s]=i;return r.test(o)?s.every(m=>n.test(m)):!1}function I(i){return(i==null?void 0:i.type)!=="text"?!0:!n.test(i.value[0])}return T}var X=xe();const Oe=Symbol("any"),Fe=Symbol("number"),Se=Symbol("string"),$e=Symbol("array"),Ee=Symbol("boolean"),R={any:Oe,number:Fe,string:Se,array:$e,boolean:Ee};function Y(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 R.any:{if(!e[r])return!1;break}case R.string:{if(!e[r]||Array.isArray(e[r]))return!1;break}case R.array:{if(!e[r]||!Array.isArray(e[r]))return!1;break}case R.number:{if(!e[r]||Array.isArray(e[r])||isNaN(parseInt(e[r]))&&isNaN(parseFloat(e[r])))return!1;break}case R.boolean:{if(!e[r]||Array.isArray(e[r])||!["0","1","false","true"].includes(e[r]))return!1;break}}}return!0}function je(e,t){const r={};for(const n in t){const a=t[n],f=e[n];if(Array.isArray(a)){const c=e[n];r[n]=c;continue}switch(typeof a){case"number":{r[n]=isNaN(parseInt(f))?parseFloat(f):parseInt(f);break}case"object":{r[n]=JSON.parse(f);break}case"string":r[n]=f;case"boolean":{r[n]=f==="1"||f==="true";break}}switch(a){case R.any:case R.string:case R.array:{r[n]=e[n];break}case R.number:{const c=e[n];r[n]=isNaN(parseInt(c))?parseFloat(c):parseInt(c);break}case R.boolean:{const c=e[n];r[n]=c==="1"||c==="true";break}}}return r}function ve(e){let{$activeRoutes:t,$path:r,$query:n,navigateFx:a}=e;return f=>{const{parameters:c,forRoutes:l}=f,S=u.createStore(!1,{name:"$entered",sid:"jh7pkx"}),D=u.createEvent({name:"entered",sid:"-savym4"}),j=u.createEvent({name:"exited",sid:"m5ggn3"}),v=u.createEvent({name:"exit",sid:"-bgcxp1"}),P=u.createEvent({name:"changeEntered",sid:"-2ei1v0"});return u.sample({and:[{clock:P,target:S}],or:{sid:"-hckvl5"}}),u.sample({and:[{source:{activeRoutes:t,query:n},filter:$=>{let{activeRoutes:E,query:h}=$;return(!l||Y(l,E))&&Z(h,c)},fn:$=>{let{query:E}=$;return je(E,c)},target:[D,P.prepend(()=>!0)]}],or:{sid:"-h9twmc"}}),u.sample({and:[{source:{activeRoutes:t,query:n,entered:S},filter:$=>{let{activeRoutes:E,query:h,entered:A}=$;return A&&!((!l||Y(l,E))&&Z(h,c))},target:[j.prepend(()=>{}),P.prepend(()=>!1)]}],or:{sid:"-gtc2ti"}}),u.sample({and:[{clock:v,source:{path:r,query:n},fn:($,E)=>{let{path:h,query:A}=$;if(E&&E.ignoreParams){const b={};for(const w of E.ignoreParams)A[w]&&(b[w]=A[w]);return{query:b,path:h}}return{query:{},path:h}},target:a}],or:{sid:"-fyjlla"}}),{entered:D,exited:j,exit:v}}}const se="%[a-f0-9]{2}",ee=new RegExp("("+se+")|([^%]+?)","gi"),re=new RegExp("("+se+")+","gi");function V(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([],V(r),V(n))}function Pe(e){try{return decodeURIComponent(e)}catch{let t=e.match(ee)||[];for(let r=1;r<t.length;r++)e=V(t,r).join(""),t=e.match(ee)||[];return e}}function Ae(e){const t={"%FE%FF":"��","%FF%FE":"��"};let r=re.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=re.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 Ne(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 f=e[n];t(n,f,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 Re=e=>e==null,De=e=>encodeURIComponent(e).replaceAll(/[!'()*]/g,t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`),K=Symbol("encodeFragmentIdentifier");function Ie(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,[F(t,e),"[",a,"]"].join("")]:[...r,[F(t,e),"[",F(a,e),"]=",F(n,e)].join("")]};case"bracket":return t=>(r,n)=>n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,[F(t,e),"[]"].join("")]:[...r,[F(t,e),"[]=",F(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,[F(t,e),":list="].join("")]:[...r,[F(t,e),":list=",F(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?[[F(r,e),t,F(a,e)].join("")]:[[n,F(a,e)].join(e.arrayFormatSeparator)])}default:return t=>(r,n)=>n===void 0||e.skipNull&&n===null||e.skipEmptyString&&n===""?r:n===null?[...r,F(t,e)]:[...r,[F(t,e),"=",F(n,e)].join("")]}}function Te(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 f=typeof n=="string"&&n.includes(e.arrayFormatSeparator),c=typeof n=="string"&&!f&&C(n,e).includes(e.arrayFormatSeparator);n=c?C(n,e):n;const l=f||c?n.split(e.arrayFormatSeparator).map(S=>C(S,e)):n===null?n:C(n,e);a[r]=l};case"bracket-separator":return(r,n,a)=>{const f=/(\[])$/.test(r);if(r=r.replace(/\[]$/,""),!f){a[r]=n&&C(n,e);return}const c=n===null?[]:C(n,e).split(e.arrayFormatSeparator);if(a[r]===void 0){a[r]=c;return}a[r]=[...a[r],...c]};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 F(e,t){return t.encode?t.strict?De(e):encodeURIComponent(e):e}function C(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 Ce(e){let t="";const r=e.indexOf("#");return r!==-1&&(t=e.slice(r)),t}function te(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 J(e){e=fe(e);const t=e.indexOf("?");return t===-1?"":e.slice(t+1)}function Q(e,t){t={decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1,types:Object.create(null),...t},ie(t.arrayFormatSeparator);const r=Te(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 f=t.decode?a.replaceAll("+"," "):a;let[c,l]=oe(f,"=");c===void 0&&(c=f),l=l===void 0?null:["comma","separator","bracket-separator"].includes(t.arrayFormat)?l:C(l,t),r(C(c,t),l,n)}for(const[a,f]of Object.entries(n))if(typeof f=="object"&&f!==null&&t.types[a]!=="string")for(const[c,l]of Object.entries(f)){const S=t.types[a]?t.types[a].replace("[]",""):void 0;f[c]=te(l,t,S)}else typeof f=="object"&&f!==null&&t.types[a]==="string"?n[a]=Object.values(f).join(t.arrayFormatSeparator):n[a]=te(f,t,t.types[a]);return t.sort===!1?n:(t.sort===!0?Object.keys(n).sort():Object.keys(n).sort(t.sort)).reduce((a,f)=>{const c=n[f];return a[f]=c&&typeof c=="object"&&!Array.isArray(c)?ce(c):c,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=c=>t.skipNull&&Re(e[c])||t.skipEmptyString&&e[c]==="",n=Ie(t),a={};for(const[c,l]of Object.entries(e))r(c)||(a[c]=l);const f=Object.keys(a);return t.sort!==!1&&f.sort(t.sort),f.map(c=>{const l=e[c];return l===void 0?"":l===null?F(c,t):Array.isArray(l)?l.length===0&&t.arrayFormat==="bracket-separator"?F(c,t)+"[]":l.reduce(n(c),[]).join("&"):F(c,t)+"="+F(l,t)}).filter(c=>c.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:Q(J(e),t),...t&&t.parseFragmentIdentifier&&n?{fragmentIdentifier:C(n,t)}:{}}}function de(e,t){t={encode:!0,strict:!0,[K]:!0,...t};const r=fe(e.url).split("?")[0]||"",n=J(e.url),a={...Q(n,{sort:!1}),...e.query};let f=ue(a,t);f&&(f=`?${f}`);let c=Ce(e.url);if(typeof e.fragmentIdentifier=="string"){const l=new URL(r);l.hash=e.fragmentIdentifier,c=t[K]?l.hash:`#${e.fragmentIdentifier}`}return`${r}${f}${c}`}function pe(e,t,r){r={parseFragmentIdentifier:!0,[K]:!1,...r};const{url:n,query:a,fragmentIdentifier:f}=le(e,r);return de({url:n,query:Ne(a,t),fragmentIdentifier:f},r)}function Ue(e,t,r){const n=Array.isArray(t)?a=>!t.includes(a):(a,f)=>!t(a,f);return pe(e,n,r)}const H=Object.freeze(Object.defineProperty({__proto__:null,exclude:Ue,extract:J,parse:Q,parseUrl:le,pick:pe,stringify:ue,stringifyUrl:de},Symbol.toStringTag,{value:"Module"}));function ne(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 ae(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?ne(Object(r),!0).forEach(function(n){_e(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ne(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function _e(e,t,r){return(t=qe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function qe(e){var t=Me(e,"string");return typeof t=="symbol"?t:t+""}function Me(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 Le(e){const{base:t="/",routes:r}=e,n=u.createStore({skipUpdate:!1},{name:"$meta",sid:"ku65ys"}),a=u.createStore(null,{and:{serialize:"ignore"},name:"$history",sid:"23j1rc"}),f=u.createStore({},{name:"$query",sid:"3deub8"}),c=u.createStore(null,{name:"$path",sid:"ld3nhr"}),l=u.createEvent({name:"setHistory",sid:"hzl7xm"}),S=u.createEvent({name:"navigate",sid:"-82vbjo"}),D=u.createEvent({name:"back",sid:"-icnnoo"}),j=u.createEvent({name:"forward",sid:"-72o1my"}),v=u.createEvent({name:"locationUpdated",sid:"d8lu52"}),P=r.map(b=>{let w=b;const y=[];for(y.unshift(w.internal.path);w.internal.parent;)w=w.internal.parent,w.internal.path!=="/"&&y.unshift(w.internal.path);const O=t==="/"?y.join(""):[t,...y].join("");return{route:b,path:O,toPath:X.compile(O),fromPath:X.match(O)}}),$=c.map(b=>{const w=[];for(const{route:y,fromPath:O}of P)O(b)&&w.push(y);return w}),E=u.attach({and:{source:{history:a,meta:n},effect:async(b,w)=>{let{history:y,meta:O}=b,{path:U,query:I,replace:i}=w;if(!y)throw new Error("history not found");if(O.skipUpdate){O.skipUpdate=!1;return}const o={pathname:U,search:"?".concat(H.stringify(I))};i?y.replace(o):y.push(o,{skipUpdate:!0})}},or:{name:"navigateFx",sid:"sry1hc"}}),h=u.attach({and:{source:n,effect:(b,w)=>{var y;const O=u.scopeBind(v);if(O({pathname:w.location.pathname,query:ae({},H.parse(w.location.search)),state:(y=w.location.state)!==null&&y!==void 0?y:{}}),!w)throw new Error;w.listen(U=>{var I;let{location:i}=U;const o=(I=i.state)!==null&&I!==void 0?I:{};o.skipUpdate&&(b.skipUpdate=!0),O({pathname:i.pathname,query:ae({},H.parse(i.search)),state:o})})}},or:{name:"subscribeHistoryFx",sid:"-9srjw2"}}),A=u.attach({and:{source:{query:f,path:c},effect:async b=>{let{query:w,path:y}=b;for(const{route:O,fromPath:U}of P){const I=U(y);if(I)await O.internal.openFx({query:w,params:I.params,historyIgnore:!0});else{O.internal.close();continue}}}},or:{name:"openRoutesByPathFx",sid:"-ro72fe"}});for(const{route:b,toPath:w}of P)u.sample({and:[{clock:b.opened,filter:y=>!(y!=null&&y.historyIgnore),fn:y=>{var O;return{path:w(y&&"params"in y?y.params:void 0),query:(O=y==null?void 0:y.query)!==null&&O!==void 0?O:{},replace:y==null?void 0:y.replace}},target:S}],or:{sid:"gfvtvu"}});return u.sample({and:[{clock:l,target:a}],or:{sid:"hbrw92"}}),u.sample({and:[{clock:a,filter:Boolean,target:h}],or:{sid:"heiv7v"}}),u.sample({and:[{clock:v,fn:b=>({path:b.pathname,query:b.query}),target:u.withFactory({sid:"-f70n8p",fn:()=>ye.spread({targets:{path:c,query:f}}),name:"target",method:"spread"})}],or:{sid:"htdb8m"}}),u.sample({and:[{clock:v,fn:b=>({path:b.pathname,query:b.query}),target:A}],or:{sid:"icm409"}}),u.sample({and:[{clock:S,target:E}],or:{sid:"sr2036"}}),u.sample({and:[{clock:[f,c],source:{query:f,path:c},fn:b=>b,target:S}],or:{sid:"t5cnik"}}),{$query:f,$path:c,$activeRoutes:$,back:D,forward:j,navigate:S,routes:r,setHistory:l,mappedRoutes:P,trackQuery:ve({$activeRoutes:$,$path:c,$query:f,navigateFx:E}),"@@unitShape":()=>({query:f,path:c,activeRoutes:$,onBack:D,onForward:j,onNavigate:S})}}exports.createRoute=we;exports.createRouter=Le;exports.parameters=R;
|
|
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;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { History as History_2 } from 'history';
|
|
|
5
5
|
import { MatchFunction } from 'path-to-regexp';
|
|
6
6
|
import { ParseUrlParams } from 'typed-url-params';
|
|
7
7
|
import { Store } from 'effector';
|
|
8
|
+
import { StoreWritable } from 'effector';
|
|
9
|
+
import { Unit } from 'effector';
|
|
8
10
|
|
|
9
11
|
declare type AnyParameter = typeof anySymbol;
|
|
10
12
|
|
|
@@ -14,10 +16,21 @@ declare type ArrayParameter = typeof arraySymbol;
|
|
|
14
16
|
|
|
15
17
|
declare const arraySymbol: unique symbol;
|
|
16
18
|
|
|
19
|
+
declare type BeforeOpenUnit<T> = EventCallable<RouteOpenedPayload<T>> | Effect<RouteOpenedPayload<T>, any>;
|
|
20
|
+
|
|
17
21
|
declare type BooleanParameter = typeof booleanSymbol;
|
|
18
22
|
|
|
19
23
|
declare const booleanSymbol: unique symbol;
|
|
20
24
|
|
|
25
|
+
export declare function chainRoute<T>(props: ChainRouteProps<T>): VirtualRoute<T>;
|
|
26
|
+
|
|
27
|
+
declare interface ChainRouteProps<T> {
|
|
28
|
+
route: Route<T>;
|
|
29
|
+
beforeOpen: BeforeOpenUnit<T> | BeforeOpenUnit<T>[];
|
|
30
|
+
openOn?: Unit<any> | Unit<any>[];
|
|
31
|
+
cancelOn?: Unit<any> | Unit<any>[];
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
declare interface Config<T> {
|
|
22
35
|
path: T;
|
|
23
36
|
parent?: Route<any>;
|
|
@@ -29,8 +42,8 @@ export declare function createRoute<T extends string, Params = SafeParams<ParseU
|
|
|
29
42
|
export declare function createRouter(config: RouterConfig): Router;
|
|
30
43
|
|
|
31
44
|
export declare type NavigatePayload = {
|
|
32
|
-
path: string;
|
|
33
45
|
query: Query;
|
|
46
|
+
path?: string;
|
|
34
47
|
replace?: boolean;
|
|
35
48
|
};
|
|
36
49
|
|
|
@@ -134,4 +147,9 @@ declare const stringSymbol: unique symbol;
|
|
|
134
147
|
|
|
135
148
|
declare type SupportedPrimitive = string | number | Date | boolean;
|
|
136
149
|
|
|
150
|
+
export declare interface VirtualRoute<T = any> extends Route<T> {
|
|
151
|
+
$params: StoreWritable<T>;
|
|
152
|
+
close: EventCallable<void>;
|
|
153
|
+
}
|
|
154
|
+
|
|
137
155
|
export { }
|