@argon-router/core 0.1.0 → 0.1.2

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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("effector"),H=require("patronum");function L(t){let n;const e=c.createEffect(()=>n==null?void 0:n(),{name:"waitForAsyncBundleFx",sid:"sy4dxt"}),r=c.createEffect(async v=>(await e(),t.parent&&await t.parent.internal.openFx(v),v),{name:"openFx",sid:"-vpkil5"}),s=c.createStore({},{name:"$params",sid:"c7nw5"}),a=c.createStore(!1,{name:"$isOpened",sid:"83ksdl"}),o=r.pending,i=c.createEvent({name:"open",sid:"v8jsib"}),l=c.createEvent({name:"close",sid:"-9nrj06"}),u=c.createEvent({name:"opened",sid:"-ddw25k"}),f=c.createEvent({name:"openedOnServer",sid:"rqvufw"}),d=c.createEvent({name:"openedOnClient",sid:"rofchv"}),h=c.createEvent({name:"closed",sid:"-qg25d5"});return c.sample({and:[{clock:i,target:r}],or:{sid:"sbzuux"}}),c.split({and:[{source:r.doneData,match:()=>typeof window>"u"?"server":"client",cases:{server:f,client:d}}],or:{sid:"sqaiab"}}),c.sample({and:[{clock:[d,f],target:u}],or:{sid:"t6sc35"}}),c.sample({and:[{clock:u,fn:()=>!0,target:a}],or:{sid:"t9jb1y"}}),c.sample({and:[{clock:h,fn:()=>!1,target:a}],or:{sid:"todr2p"}}),{$params:s,$isOpened:a,$isPending:o,open:i,closed:h,opened:u,openedOnClient:d,openedOnServer:f,internal:{index:!1,close:l,openFx:r,setAsyncImport:v=>n=v,...t},"@@unitShape":()=>({params:s,isPending:o,isOpened:a,onOpen:i})}}var E={};Object.defineProperty(E,"__esModule",{value:!0});E.TokenData=void 0;E.parse=O;var M=E.compile=W,B=E.match=G;E.pathToRegexp=U;E.stringify=Y;const F="/",N=t=>t,I=/^[$_\p{ID_Start}]$/u,P=/^[$\u200c\u200d\p{ID_Continue}]$/u,R="https://git.new/pathToRegexpError",q={"{":"{","}":"}","(":"(",")":")","[":"[","]":"]","+":"+","?":"?","!":"!"};function J(t){return t.replace(/[{}()\[\]+?!:*]/g,"\\$&")}function b(t){return t.replace(/[.+*?^${}()[\]|/\\]/g,"\\$&")}function*V(t){const n=[...t];let e=0;function r(){let s="";if(I.test(n[++e]))for(s+=n[e];P.test(n[++e]);)s+=n[e];else if(n[e]==='"'){let a=e;for(;e<n.length;){if(n[++e]==='"'){e++,a=0;break}n[e]==="\\"?s+=n[++e]:s+=n[e]}if(a)throw new TypeError(`Unterminated quote at ${a}: ${R}`)}if(!s)throw new TypeError(`Missing parameter name at ${e}: ${R}`);return s}for(;e<n.length;){const s=n[e],a=q[s];if(a)yield{type:a,index:e++,value:s};else if(s==="\\")yield{type:"ESCAPED",index:e++,value:n[e++]};else if(s===":"){const o=r();yield{type:"PARAM",index:e,value:o}}else if(s==="*"){const o=r();yield{type:"WILDCARD",index:e,value:o}}else yield{type:"CHAR",index:e,value:n[e++]}}return{type:"END",index:e,value:""}}class Q{constructor(n){this.tokens=n}peek(){if(!this._peek){const n=this.tokens.next();this._peek=n.value}return this._peek}tryConsume(n){const e=this.peek();if(e.type===n)return this._peek=void 0,e.value}consume(n){const e=this.tryConsume(n);if(e!==void 0)return e;const{type:r,index:s}=this.peek();throw new TypeError(`Unexpected ${r} at ${s}, expected ${n}: ${R}`)}text(){let n="",e;for(;e=this.tryConsume("CHAR")||this.tryConsume("ESCAPED");)n+=e;return n}}class A{constructor(n){this.tokens=n}}E.TokenData=A;function O(t,n={}){const{encodePath:e=N}=n,r=new Q(V(t));function s(o){const i=[];for(;;){const l=r.text();l&&i.push({type:"text",value:e(l)});const u=r.tryConsume("PARAM");if(u){i.push({type:"param",name:u});continue}const f=r.tryConsume("WILDCARD");if(f){i.push({type:"wildcard",name:f});continue}if(r.tryConsume("{")){i.push({type:"group",tokens:s("}")});continue}return r.consume(o),i}}const a=s("END");return new A(a)}function W(t,n={}){const{encode:e=encodeURIComponent,delimiter:r=F}=n,s=t instanceof A?t:O(t,n),a=_(s.tokens,r,e);return function(i={}){const[l,...u]=a(i);if(u.length)throw new TypeError(`Missing parameters: ${u.join(", ")}`);return l}}function _(t,n,e){const r=t.map(s=>z(s,n,e));return s=>{const a=[""];for(const o of r){const[i,...l]=o(s);a[0]+=i,a.push(...l)}return a}}function z(t,n,e){if(t.type==="text")return()=>[t.value];if(t.type==="group"){const s=_(t.tokens,n,e);return a=>{const[o,...i]=s(a);return i.length?[""]:[o]}}const r=e||N;return t.type==="wildcard"&&e!==!1?s=>{const a=s[t.name];if(a==null)return["",t.name];if(!Array.isArray(a)||a.length===0)throw new TypeError(`Expected "${t.name}" to be a non-empty array`);return[a.map((o,i)=>{if(typeof o!="string")throw new TypeError(`Expected "${t.name}/${i}" to be a string`);return r(o)}).join(n)]}:s=>{const a=s[t.name];if(a==null)return["",t.name];if(typeof a!="string")throw new TypeError(`Expected "${t.name}" to be a string`);return[r(a)]}}function G(t,n={}){const{decode:e=decodeURIComponent,delimiter:r=F}=n,{regexp:s,keys:a}=U(t,n),o=a.map(i=>e===!1?N:i.type==="param"?e:l=>l.split(r).map(e));return function(l){const u=s.exec(l);if(!u)return!1;const f=u[0],d=Object.create(null);for(let h=1;h<u.length;h++){if(u[h]===void 0)continue;const v=a[h-1],k=o[h-1];d[v.name]=k(u[h])}return{path:f,params:d}}}function U(t,n={}){const{delimiter:e=F,end:r=!0,sensitive:s=!1,trailing:a=!0}=n,o=[],i=[],l=s?"":"i",f=(Array.isArray(t)?t:[t]).map(v=>v instanceof A?v:O(v,n));for(const{tokens:v}of f)for(const k of S(v,0,[])){const T=K(k,e,o);i.push(T)}let d=`^(?:${i.join("|")})`;return a&&(d+=`(?:${b(e)}$)?`),d+=r?"$":`(?=${b(e)}|$)`,{regexp:new RegExp(d,l),keys:o}}function*S(t,n,e){if(n===t.length)return yield e;const r=t[n];if(r.type==="group"){const s=e.slice();for(const a of S(r.tokens,0,s))yield*S(t,n+1,a)}else e.push(r);yield*S(t,n+1,e)}function K(t,n,e){let r="",s="",a=!0;for(let o=0;o<t.length;o++){const i=t[o];if(i.type==="text"){r+=b(i.value),s+=i.value,a||(a=i.value.includes(n));continue}if(i.type==="param"||i.type==="wildcard"){if(!a&&!s)throw new TypeError(`Missing text after "${i.name}": ${R}`);i.type==="param"?r+=`(${X(n,a?"":s)}+)`:r+="([\\s\\S]+)",e.push(i),s="",a=!1;continue}}return r}function X(t,n){return n.length<2?t.length<2?`[^${b(t+n)}]`:`(?:(?!${b(t)})[^${b(n)}])`:t.length<2?`(?:(?!${b(n)})[^${b(t)}])`:`(?:(?!${b(n)}|${b(t)})[\\s\\S])`}function Y(t){return t.tokens.map(function n(e,r,s){if(e.type==="text")return J(e.value);if(e.type==="group")return`{${e.tokens.map(n).join("")}}`;const o=Z(e.name)&&ee(s[r+1])?e.name:JSON.stringify(e.name);if(e.type==="param")return`:${o}`;if(e.type==="wildcard")return`*${o}`;throw new TypeError(`Unexpected token: ${e}`)}).join("")}function Z(t){const[n,...e]=t;return I.test(n)?e.every(r=>P.test(r)):!1}function ee(t){return(t==null?void 0:t.type)!=="text"?!0:!P.test(t.value[0])}const te=Symbol("any"),ne=Symbol("number"),re=Symbol("string"),se=Symbol("array"),$={any:te,number:ne,string:re,array:se};function C(t,n){for(const e of t)if(!n.includes(e))return!1;return!0}function D(t,n){for(const e in n){const r=n[e];if(Array.isArray(r)&&(!t[e]||JSON.stringify(r)!==t[e]))return!1;switch(typeof r){case"number":{if(!t[e]||r.toString()!==t[e])return!1;break}case"object":{if(!t[e]||JSON.stringify(r)!==t[e])return!1;break}case"string":{if(!t[e]||r!==t[e])return!1;break}case"boolean":{if(!t[e]||!["0","1","false","true"].includes(t[e]))return!1;break}}switch(r){case $.any:{if(!t[e])return!1;break}case $.string:{if(!t[e]||Array.isArray(t[e]))return!1;break}case $.array:{if(!t[e]||!Array.isArray(t[e]))return!1;break}case $.number:{if(!t[e]||Array.isArray(t[e])||isNaN(parseInt(t[e]))&&isNaN(parseFloat(t[e])))return!1;break}}}return!0}function ae(t,n){const e={};for(const r in n){const s=n[r],a=t[r];if(Array.isArray(s)){e[r]=a==="1"||a==="true";continue}switch(typeof s){case"number":{const o=t[r];e[r]=isNaN(parseInt(o))?parseFloat(o):parseInt(o);break}case"object":{e[r]=JSON.parse(a);break}case"string":e[r]=t[r];case"boolean":{const o=t[r];e[r]=o==="0"?parseFloat(o):parseInt(o);break}}switch(s){case $.any:case $.string:case $.array:{e[r]=t[r];break}case $.number:{const o=t[r];e[r]=isNaN(parseInt(o))?parseFloat(o):parseInt(o);break}}}return e}function oe(t,n){return e=>{const{parameters:r,forRoutes:s}=e,a=c.createEvent({name:"entered",sid:"-d3obu6"}),o=c.createEvent({name:"exited",sid:"-xofyk3"}),i=c.createEvent({name:"exit",sid:"-673d76"});return c.sample({and:[{source:{activeRoutes:t,query:n},filter:l=>{let{activeRoutes:u,query:f}=l;return(!s||C(s,u))&&D(f,r)},fn:l=>{let{query:u}=l;return ae(u,r)}}],or:{sid:"-so0f9q"}}),c.sample({and:[{source:{activeRoutes:t,query:n},filter:l=>{let{activeRoutes:u,query:f}=l;return!((!s||C(s,u))&&D(f,r))},target:o}],or:{sid:"-s82e29"}}),{entered:a,exited:o,exit:i,getPayload:l=>Object.entries(l).reduce((u,f)=>{let[d,h]=f;return typeof r[d]=="symbol"?u[d]=h:u[d]=r[d],u},{})}}}function ie(t){const{base:n="/",history:e,routes:r}=t,s=c.createStore({},{name:"$query",sid:"2wd7x1"}),a=c.createStore(e??null,{name:"$history",sid:"31majq"}),o=c.createStore("/",{name:"$path",sid:"ld3nhr"}),i=c.createStore([],{name:"$activeRoutes",sid:"mrug12"}),l=c.createEvent({name:"setHistory",sid:"sekwlw"}),u=c.createEvent({name:"back",sid:"-icnnoo"}),f=c.createEvent({name:"forward",sid:"-72o1my"}),d=c.createEvent({name:"locationUpdated",sid:"d8lu52"}),h=r.map(m=>{let g=m;const p=[];for(p.unshift(g.internal.path);g.internal.parent;)g=g.internal.parent,p.unshift(g.internal.path);const y=(n==="/"?p:[n,...p]).join("");return{route:m,path:y,toPath:M(y),fromPath:B(y)}}),v=c.attach({and:{source:{history:a},effect:async(m,g)=>{let{history:p}=m,{path:y,query:x,replace:w}=g;if(!p)throw new Error("history not found");const j={pathname:y,query:x};w?p.replace(j):p.push(j)}},or:{name:"updateHistoryFx",sid:"h74tsu"}});for(const{route:m,toPath:g}of h)c.sample({and:[{clock:m.opened,source:i,fn:p=>[...p,m],target:i}],or:{sid:"-px1r6l"}}),c.sample({and:[{clock:m.opened,fn:p=>{let{params:y,query:x,replace:w}=p;return{path:g(y),query:x??{},replace:w}},target:v}],or:{sid:"-phnikh"}}),c.sample({and:[{clock:m.closed,source:i,fn:p=>p.filter(y=>y!==m),target:i}],or:{sid:"e0gjjf"}});c.sample({and:[{clock:l,target:a}],or:{sid:"egekp6"}});const k=c.createEffect(m=>{const g=c.scopeBind(d);if(!m)throw new Error;m.listen(p=>{let{location:y}=p;g(y)})},{name:"subscribeHistoryFx",sid:"5cocq6"}),T=c.attach({and:{source:{query:s,path:o},effect:async m=>{let{query:g,path:p}=m;for(const{route:y,fromPath:x}of h){const w=x(p);if(w)await y.internal.openFx({query:g,params:w.params});else continue}}},or:{name:"openRoutesByPathFx",sid:"tmly43"}});return c.sample({and:[{clock:a,filter:Boolean,target:k}],or:{sid:"fwn12h"}}),c.sample({and:[{clock:d,fn:m=>{let{pathname:g,search:p}=m;const y=new URLSearchParams(p);return{path:g,query:[...y.keys()].reduce((x,w)=>(x[w]?x[w]=y.getAll(w):x[w]=y.get(w),x),{})}},target:c.withFactory({sid:"f47wtp",fn:()=>H.spread({targets:{path:o,query:s}}),name:"target",method:"spread"})}],or:{sid:"gbhh38"}}),c.sample({and:[{clock:o,target:T}],or:{sid:"hcvhfs"}}),{$query:s,$path:o,$activeRoutes:i,back:u,forward:f,routes:r,setHistory:l,mappedRoutes:h,trackQuery:oe(i,s),"@@unitShape":()=>({query:s,path:o,activeRoutes:i,onBack:u,onForward:f})}}exports.createRoute=L;exports.createRouter=ie;exports.parameters=$;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("effector"),D=require("patronum");function N(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable})),e.push.apply(e,r)}return e}function j(t){for(var n=1;n<arguments.length;n++){var e=arguments[n]!=null?arguments[n]:{};n%2?N(Object(e),!0).forEach(function(r){M(t,r,e[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):N(Object(e)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))})}return t}function M(t,n,e){return(n=z(n))in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}function z(t){var n=q(t,"string");return typeof n=="symbol"?n:n+""}function q(t,n){if(typeof t!="object"||!t)return t;var e=t[Symbol.toPrimitive];if(e!==void 0){var r=e.call(t,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function J(t){let n;const e=i.createEffect(()=>{var y;return(y=n)===null||y===void 0?void 0:y()},{name:"waitForAsyncBundleFx",sid:"hl1gh5"}),r=i.createEffect(async()=>{for(const p of(y=t.beforeOpen)!==null&&y!==void 0?y:[]){var y;await p()}},{name:"beforeOpenFx",sid:"jez0xa"}),a=i.createEffect(async y=>(await e(),await r(),t.parent&&await t.parent.internal.openFx(j(j({},y),{},{historyIgnore:!0})),y),{name:"openFx",sid:"-uafnek"}),s=i.createStore({},{name:"$params",sid:"dlh2xl"}),o=i.createStore(!1,{name:"$isOpened",sid:"lcu7f1"}),c=a.pending,l=i.createEvent({name:"open",sid:"-qjaufd"}),u=i.createEvent({name:"close",sid:"-6cg68t"}),m=i.createEvent({name:"opened",sid:"-a2kpe7"}),d=i.createEvent({name:"openedOnServer",sid:"-u0yshs"}),g=i.createEvent({name:"openedOnClient",sid:"-u3faft"}),b=i.createEvent({name:"closed",sid:"-d6sqbp"});return i.sample({and:[{clock:l,target:a}],or:{sid:"sre3h1"}}),i.split({and:[{source:a.doneData,match:()=>typeof window>"u"?"server":"client",cases:{server:d,client:g}}],or:{sid:"t5oqwf"}}),i.sample({and:[{clock:[g,d],target:m}],or:{sid:"tamw8o"}}),i.sample({and:[{clock:m,fn:()=>!0,target:o}],or:{sid:"toxjo2"}}),i.sample({and:[{clock:u,target:b}],or:{sid:"u3rzot"}}),i.sample({and:[{clock:b,fn:()=>!1,target:o}],or:{sid:"u6iynm"}}),{$params:s,$isOpened:o,$isPending:c,open:l,closed:b,opened:m,openedOnClient:g,openedOnServer:d,internal:j({index:!1,close:u,openFx:a,setAsyncImport:y=>n=y},t),"@@unitShape":()=>({params:s,isPending:c,isOpened:o,onOpen:l})}}var E={};Object.defineProperty(E,"__esModule",{value:!0});E.TokenData=void 0;E.parse=F;var K=E.compile=Y,V=E.match=ee;E.pathToRegexp=H;E.stringify=re;const R="/",A=t=>t,L=/^[$_\p{ID_Start}]$/u,T=/^[$\u200c\u200d\p{ID_Continue}]$/u,O="https://git.new/pathToRegexpError",Q={"{":"{","}":"}","(":"(",")":")","[":"[","]":"]","+":"+","?":"?","!":"!"};function W(t){return t.replace(/[{}()\[\]+?!:*]/g,"\\$&")}function w(t){return t.replace(/[.+*?^${}()[\]|/\\]/g,"\\$&")}function*G(t){const n=[...t];let e=0;function r(){let a="";if(L.test(n[++e]))for(a+=n[e];T.test(n[++e]);)a+=n[e];else if(n[e]==='"'){let s=e;for(;e<n.length;){if(n[++e]==='"'){e++,s=0;break}n[e]==="\\"?a+=n[++e]:a+=n[e]}if(s)throw new TypeError(`Unterminated quote at ${s}: ${O}`)}if(!a)throw new TypeError(`Missing parameter name at ${e}: ${O}`);return a}for(;e<n.length;){const a=n[e],s=Q[a];if(s)yield{type:s,index:e++,value:a};else if(a==="\\")yield{type:"ESCAPED",index:e++,value:n[e++]};else if(a===":"){const o=r();yield{type:"PARAM",index:e,value:o}}else if(a==="*"){const o=r();yield{type:"WILDCARD",index:e,value:o}}else yield{type:"CHAR",index:e,value:n[e++]}}return{type:"END",index:e,value:""}}class X{constructor(n){this.tokens=n}peek(){if(!this._peek){const n=this.tokens.next();this._peek=n.value}return this._peek}tryConsume(n){const e=this.peek();if(e.type===n)return this._peek=void 0,e.value}consume(n){const e=this.tryConsume(n);if(e!==void 0)return e;const{type:r,index:a}=this.peek();throw new TypeError(`Unexpected ${r} at ${a}, expected ${n}: ${O}`)}text(){let n="",e;for(;e=this.tryConsume("CHAR")||this.tryConsume("ESCAPED");)n+=e;return n}}class P{constructor(n){this.tokens=n}}E.TokenData=P;function F(t,n={}){const{encodePath:e=A}=n,r=new X(G(t));function a(o){const c=[];for(;;){const l=r.text();l&&c.push({type:"text",value:e(l)});const u=r.tryConsume("PARAM");if(u){c.push({type:"param",name:u});continue}const m=r.tryConsume("WILDCARD");if(m){c.push({type:"wildcard",name:m});continue}if(r.tryConsume("{")){c.push({type:"group",tokens:a("}")});continue}return r.consume(o),c}}const s=a("END");return new P(s)}function Y(t,n={}){const{encode:e=encodeURIComponent,delimiter:r=R}=n,a=t instanceof P?t:F(t,n),s=B(a.tokens,r,e);return function(c={}){const[l,...u]=s(c);if(u.length)throw new TypeError(`Missing parameters: ${u.join(", ")}`);return l}}function B(t,n,e){const r=t.map(a=>Z(a,n,e));return a=>{const s=[""];for(const o of r){const[c,...l]=o(a);s[0]+=c,s.push(...l)}return s}}function Z(t,n,e){if(t.type==="text")return()=>[t.value];if(t.type==="group"){const a=B(t.tokens,n,e);return s=>{const[o,...c]=a(s);return c.length?[""]:[o]}}const r=e||A;return t.type==="wildcard"&&e!==!1?a=>{const s=a[t.name];if(s==null)return["",t.name];if(!Array.isArray(s)||s.length===0)throw new TypeError(`Expected "${t.name}" to be a non-empty array`);return[s.map((o,c)=>{if(typeof o!="string")throw new TypeError(`Expected "${t.name}/${c}" to be a string`);return r(o)}).join(n)]}:a=>{const s=a[t.name];if(s==null)return["",t.name];if(typeof s!="string")throw new TypeError(`Expected "${t.name}" to be a string`);return[r(s)]}}function ee(t,n={}){const{decode:e=decodeURIComponent,delimiter:r=R}=n,{regexp:a,keys:s}=H(t,n),o=s.map(c=>e===!1?A:c.type==="param"?e:l=>l.split(r).map(e));return function(l){const u=a.exec(l);if(!u)return!1;const m=u[0],d=Object.create(null);for(let g=1;g<u.length;g++){if(u[g]===void 0)continue;const b=s[g-1],y=o[g-1];d[b.name]=y(u[g])}return{path:m,params:d}}}function H(t,n={}){const{delimiter:e=R,end:r=!0,sensitive:a=!1,trailing:s=!0}=n,o=[],c=[],l=a?"":"i",m=(Array.isArray(t)?t:[t]).map(b=>b instanceof P?b:F(b,n));for(const{tokens:b}of m)for(const y of S(b,0,[])){const p=te(y,e,o);c.push(p)}let d=`^(?:${c.join("|")})`;return s&&(d+=`(?:${w(e)}$)?`),d+=r?"$":`(?=${w(e)}|$)`,{regexp:new RegExp(d,l),keys:o}}function*S(t,n,e){if(n===t.length)return yield e;const r=t[n];if(r.type==="group"){const a=e.slice();for(const s of S(r.tokens,0,a))yield*S(t,n+1,s)}else e.push(r);yield*S(t,n+1,e)}function te(t,n,e){let r="",a="",s=!0;for(let o=0;o<t.length;o++){const c=t[o];if(c.type==="text"){r+=w(c.value),a+=c.value,s||(s=c.value.includes(n));continue}if(c.type==="param"||c.type==="wildcard"){if(!s&&!a)throw new TypeError(`Missing text after "${c.name}": ${O}`);c.type==="param"?r+=`(${ne(n,s?"":a)}+)`:r+="([\\s\\S]+)",e.push(c),a="",s=!1;continue}}return r}function ne(t,n){return n.length<2?t.length<2?`[^${w(t+n)}]`:`(?:(?!${w(t)})[^${w(n)}])`:t.length<2?`(?:(?!${w(n)})[^${w(t)}])`:`(?:(?!${w(n)}|${w(t)})[\\s\\S])`}function re(t){return t.tokens.map(function n(e,r,a){if(e.type==="text")return W(e.value);if(e.type==="group")return`{${e.tokens.map(n).join("")}}`;const o=ae(e.name)&&se(a[r+1])?e.name:JSON.stringify(e.name);if(e.type==="param")return`:${o}`;if(e.type==="wildcard")return`*${o}`;throw new TypeError(`Unexpected token: ${e}`)}).join("")}function ae(t){const[n,...e]=t;return L.test(n)?e.every(r=>T.test(r)):!1}function se(t){return(t==null?void 0:t.type)!=="text"?!0:!T.test(t.value[0])}const oe=Symbol("any"),ie=Symbol("number"),ce=Symbol("string"),ue=Symbol("array"),x={any:oe,number:ie,string:ce,array:ue};function _(t,n){for(const e of t)if(!n.includes(e))return!1;return!0}function C(t,n){for(const e in n){const r=n[e];if(Array.isArray(r)&&(!t[e]||JSON.stringify(r)!==t[e]))return!1;switch(typeof r){case"number":{if(!t[e]||r.toString()!==t[e])return!1;break}case"object":{if(!t[e]||JSON.stringify(r)!==t[e])return!1;break}case"string":{if(!t[e]||r!==t[e])return!1;break}case"boolean":{if(!t[e]||!["0","1","false","true"].includes(t[e]))return!1;break}}switch(r){case x.any:{if(!t[e])return!1;break}case x.string:{if(!t[e]||Array.isArray(t[e]))return!1;break}case x.array:{if(!t[e]||!Array.isArray(t[e]))return!1;break}case x.number:{if(!t[e]||Array.isArray(t[e])||isNaN(parseInt(t[e]))&&isNaN(parseFloat(t[e])))return!1;break}}}return!0}function le(t,n){const e={};for(const r in n){const a=n[r],s=t[r];if(Array.isArray(a)){e[r]=s==="1"||s==="true";continue}switch(typeof a){case"number":{const o=t[r];e[r]=isNaN(parseInt(o))?parseFloat(o):parseInt(o);break}case"object":{e[r]=JSON.parse(s);break}case"string":e[r]=t[r];case"boolean":{const o=t[r];e[r]=o==="0"?parseFloat(o):parseInt(o);break}}switch(a){case x.any:case x.string:case x.array:{e[r]=t[r];break}case x.number:{const o=t[r];e[r]=isNaN(parseInt(o))?parseFloat(o):parseInt(o);break}}}return e}function pe(t,n){return e=>{const{parameters:r,forRoutes:a}=e,s=i.createEvent({name:"entered",sid:"-d3obu6"}),o=i.createEvent({name:"exited",sid:"-xofyk3"}),c=i.createEvent({name:"exit",sid:"-673d76"});return i.sample({and:[{source:{activeRoutes:t,query:n},filter:l=>{let{activeRoutes:u,query:m}=l;return(!a||_(a,u))&&C(m,r)},fn:l=>{let{query:u}=l;return le(u,r)}}],or:{sid:"-so0f9q"}}),i.sample({and:[{source:{activeRoutes:t,query:n},filter:l=>{let{activeRoutes:u,query:m}=l;return!((!a||_(a,u))&&C(m,r))},target:o}],or:{sid:"-s82e29"}}),{entered:s,exited:o,exit:c,getPayload:l=>Object.entries(l).reduce((u,m)=>{let[d,g]=m;return typeof r[d]=="symbol"?u[d]=g:u[d]=r[d],u},{})}}}function U(t){const n=new URLSearchParams(t.search);return{path:t.pathname,query:[...n.keys()].reduce((e,r)=>(e[r]?e[r]=n.getAll(r):e[r]=n.get(r),e),{})}}function fe(t){const{base:n="/",routes:e}=t,r=i.createStore({},{name:"$query",sid:"uczasb"}),a=i.createStore(null,{name:"$history",sid:"ui8df0"}),s=i.createStore(null,{name:"$path",sid:"-m7ebm3"}),o=i.createStore([],{name:"$activeRoutes",sid:"-ksnj2s"}),c=i.createEvent({name:"setHistory",sid:"-p3v4s1"}),l=i.createEvent({name:"back",sid:"-tzn3h"}),u=i.createEvent({name:"forward",sid:"afzyy9"}),m=i.createEvent({name:"locationUpdated",sid:"-ubw4ys"}),d=e.map(p=>{let v=p;const f=[];for(f.unshift(v.internal.path);v.internal.parent;)v=v.internal.parent,v.internal.path!=="/"&&f.unshift(v.internal.path);const h=n==="/"?f.join(""):[n,...f].join("");return{route:p,path:h,toPath:K(h),fromPath:V(h)}}),g=i.attach({and:{source:{history:a},effect:async(p,v)=>{let{history:f}=p,{path:h,query:$,replace:k}=v;if(!f)throw new Error("history not found");const I={pathname:h,query:$};k?f.replace(I):f.push(I.pathname)}},or:{name:"updateHistoryFx",sid:"-oy8a4f"}});for(const{route:p,toPath:v}of d)i.sample({and:[{clock:p.opened,source:o,filter:f=>!f.includes(p),fn:f=>[...f,p],target:o}],or:{sid:"e1k4q5"}}),i.sample({and:[{clock:p.opened,filter:f=>!f.historyIgnore,fn:function(){let{params:f,query:h,replace:$}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{params:{}};return{path:v(f),query:h??{},replace:$}},target:g}],or:{sid:"ehi5xm"}}),i.sample({and:[{clock:p.closed,source:o,fn:f=>f.filter(h=>h!==p),target:o}],or:{sid:"ez3kx6"}});i.sample({and:[{clock:c,target:a}],or:{sid:"ff1m2x"}});const b=i.createEffect(p=>{const v=i.scopeBind(m);if(!p)throw new Error;p.listen(f=>{let{location:h}=f;v(h)})},{name:"subscribeHistoryFx",sid:"z6ijkf"}),y=i.attach({and:{source:{query:r,path:s},effect:async p=>{let{query:v,path:f}=p;for(const{route:h,fromPath:$}of d){const k=$(f);if(k)await h.internal.openFx({query:v,params:k.params});else{h.internal.close();continue}}}},or:{name:"openRoutesByPathFx",sid:"-1mpuqp"}});return i.sample({and:[{clock:a,filter:Boolean,target:b}],or:{sid:"gvtv1l"}}),i.sample({and:[{clock:a,filter:Boolean,fn:p=>U(p.location),target:i.withFactory({sid:"suiy9c",fn:()=>D.spread({targets:{path:s,query:r}}),name:"target",method:"spread"})}],or:{sid:"haob2c"}}),i.sample({and:[{clock:[m],fn:p=>U(p),target:i.withFactory({sid:"-r1573k",fn:()=>D.spread({targets:{path:s,query:r}}),name:"target",method:"spread"})}],or:{sid:"hstin9"}}),i.sample({and:[{clock:s,target:y}],or:{sid:"iaexmt"}}),{$query:r,$path:s,$activeRoutes:o,back:l,forward:u,routes:e,setHistory:c,mappedRoutes:d,trackQuery:pe(o,r),"@@unitShape":()=>({query:r,path:s,activeRoutes:o,onBack:l,onForward:u})}}exports.createRoute=J;exports.createRouter=fe;exports.parameters=x;
package/dist/index.d.ts CHANGED
@@ -17,8 +17,7 @@ declare const arraySymbol: unique symbol;
17
17
  declare interface Config<T> {
18
18
  path: T;
19
19
  parent?: Route<any>;
20
- index?: boolean;
21
- beforeOpen?: Effect<any, any, any>[];
20
+ beforeOpen?: Effect<void, any, any>[];
22
21
  }
23
22
 
24
23
  export declare function createRoute<T extends string, Params = ParseUrlParams<T>>(config: Config<T>): Route<Params>;
@@ -109,7 +108,6 @@ export declare interface Router {
109
108
 
110
109
  declare interface RouterConfig {
111
110
  base?: string;
112
- history?: History_2;
113
111
  routes: Route<any>[];
114
112
  }
115
113
 
package/dist/index.js CHANGED
@@ -1,118 +1,176 @@
1
- import { createEffect as P, createStore as S, createEvent as x, sample as w, split as J, attach as _, scopeBind as V, withFactory as q } from "effector";
2
- import { spread as Q } from "patronum";
3
- function me(t) {
1
+ import { createEffect as P, createStore as O, createEvent as w, sample as g, split as V, attach as C, scopeBind as Q, withFactory as U } from "effector";
2
+ import { spread as L } from "patronum";
3
+ function B(t, n) {
4
+ var e = Object.keys(t);
5
+ if (Object.getOwnPropertySymbols) {
6
+ var r = Object.getOwnPropertySymbols(t);
7
+ n && (r = r.filter(function(s) {
8
+ return Object.getOwnPropertyDescriptor(t, s).enumerable;
9
+ })), e.push.apply(e, r);
10
+ }
11
+ return e;
12
+ }
13
+ function T(t) {
14
+ for (var n = 1; n < arguments.length; n++) {
15
+ var e = arguments[n] != null ? arguments[n] : {};
16
+ n % 2 ? B(Object(e), !0).forEach(function(r) {
17
+ W(t, r, e[r]);
18
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(e)) : B(Object(e)).forEach(function(r) {
19
+ Object.defineProperty(t, r, Object.getOwnPropertyDescriptor(e, r));
20
+ });
21
+ }
22
+ return t;
23
+ }
24
+ function W(t, n, e) {
25
+ return (n = G(n)) in t ? Object.defineProperty(t, n, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : t[n] = e, t;
26
+ }
27
+ function G(t) {
28
+ var n = X(t, "string");
29
+ return typeof n == "symbol" ? n : n + "";
30
+ }
31
+ function X(t, n) {
32
+ if (typeof t != "object" || !t) return t;
33
+ var e = t[Symbol.toPrimitive];
34
+ if (e !== void 0) {
35
+ var r = e.call(t, n || "default");
36
+ if (typeof r != "object") return r;
37
+ throw new TypeError("@@toPrimitive must return a primitive value.");
38
+ }
39
+ return (n === "string" ? String : Number)(t);
40
+ }
41
+ function we(t) {
4
42
  let n;
5
- const e = P(() => n == null ? void 0 : n(), {
43
+ const e = P(() => {
44
+ var y;
45
+ return (y = n) === null || y === void 0 ? void 0 : y();
46
+ }, {
6
47
  name: "waitForAsyncBundleFx",
7
- sid: "sy4dxt"
8
- }), r = P(async (g) => (await e(), t.parent && await t.parent.internal.openFx(g), g), {
48
+ sid: "hl1gh5"
49
+ }), r = P(async () => {
50
+ for (const l of (y = t.beforeOpen) !== null && y !== void 0 ? y : []) {
51
+ var y;
52
+ await l();
53
+ }
54
+ }, {
55
+ name: "beforeOpenFx",
56
+ sid: "jez0xa"
57
+ }), s = P(async (y) => (await e(), await r(), t.parent && await t.parent.internal.openFx(T(T({}, y), {}, {
58
+ historyIgnore: !0
59
+ })), y), {
9
60
  name: "openFx",
10
- sid: "-vpkil5"
11
- }), s = S({}, {
61
+ sid: "-uafnek"
62
+ }), o = O({}, {
12
63
  name: "$params",
13
- sid: "c7nw5"
14
- }), a = S(!1, {
64
+ sid: "dlh2xl"
65
+ }), a = O(!1, {
15
66
  name: "$isOpened",
16
- sid: "83ksdl"
17
- }), o = r.pending, i = x({
67
+ sid: "lcu7f1"
68
+ }), i = s.pending, u = w({
18
69
  name: "open",
19
- sid: "v8jsib"
20
- }), u = x({
70
+ sid: "-qjaufd"
71
+ }), c = w({
21
72
  name: "close",
22
- sid: "-9nrj06"
23
- }), c = x({
73
+ sid: "-6cg68t"
74
+ }), d = w({
24
75
  name: "opened",
25
- sid: "-ddw25k"
26
- }), p = x({
76
+ sid: "-a2kpe7"
77
+ }), p = w({
27
78
  name: "openedOnServer",
28
- sid: "rqvufw"
29
- }), f = x({
79
+ sid: "-u0yshs"
80
+ }), h = w({
30
81
  name: "openedOnClient",
31
- sid: "rofchv"
32
- }), m = x({
82
+ sid: "-u3faft"
83
+ }), v = w({
33
84
  name: "closed",
34
- sid: "-qg25d5"
85
+ sid: "-d6sqbp"
35
86
  });
36
- return w({
87
+ return g({
37
88
  and: [{
38
- clock: i,
39
- target: r
89
+ clock: u,
90
+ target: s
40
91
  }],
41
92
  or: {
42
- sid: "sbzuux"
93
+ sid: "sre3h1"
43
94
  }
44
- }), J({
95
+ }), V({
45
96
  and: [{
46
- source: r.doneData,
97
+ source: s.doneData,
47
98
  match: () => typeof window > "u" ? "server" : "client",
48
99
  cases: {
49
100
  server: p,
50
- client: f
101
+ client: h
51
102
  }
52
103
  }],
53
104
  or: {
54
- sid: "sqaiab"
105
+ sid: "t5oqwf"
55
106
  }
56
- }), w({
107
+ }), g({
57
108
  and: [{
58
- clock: [f, p],
59
- target: c
109
+ clock: [h, p],
110
+ target: d
60
111
  }],
61
112
  or: {
62
- sid: "t6sc35"
113
+ sid: "tamw8o"
63
114
  }
64
- }), w({
115
+ }), g({
65
116
  and: [{
66
- clock: c,
117
+ clock: d,
67
118
  fn: () => !0,
68
119
  target: a
69
120
  }],
70
121
  or: {
71
- sid: "t9jb1y"
122
+ sid: "toxjo2"
123
+ }
124
+ }), g({
125
+ and: [{
126
+ clock: c,
127
+ target: v
128
+ }],
129
+ or: {
130
+ sid: "u3rzot"
72
131
  }
73
- }), w({
132
+ }), g({
74
133
  and: [{
75
- clock: m,
134
+ clock: v,
76
135
  fn: () => !1,
77
136
  target: a
78
137
  }],
79
138
  or: {
80
- sid: "todr2p"
139
+ sid: "u6iynm"
81
140
  }
82
141
  }), {
83
- $params: s,
142
+ $params: o,
84
143
  $isOpened: a,
85
- $isPending: o,
86
- open: i,
87
- closed: m,
88
- opened: c,
89
- openedOnClient: f,
144
+ $isPending: i,
145
+ open: u,
146
+ closed: v,
147
+ opened: d,
148
+ openedOnClient: h,
90
149
  openedOnServer: p,
91
- internal: {
150
+ internal: T({
92
151
  index: !1,
93
- close: u,
94
- openFx: r,
95
- setAsyncImport: (g) => n = g,
96
- ...t
97
- },
152
+ close: c,
153
+ openFx: s,
154
+ setAsyncImport: (y) => n = y
155
+ }, t),
98
156
  "@@unitShape": () => ({
99
- params: s,
100
- isPending: o,
157
+ params: o,
158
+ isPending: i,
101
159
  isOpened: a,
102
- onOpen: i
160
+ onOpen: u
103
161
  })
104
162
  };
105
163
  }
106
- var E = {};
107
- Object.defineProperty(E, "__esModule", {
164
+ var k = {};
165
+ Object.defineProperty(k, "__esModule", {
108
166
  value: !0
109
167
  });
110
- E.TokenData = void 0;
111
- E.parse = O;
112
- var W = E.compile = Z, z = E.match = te;
113
- E.pathToRegexp = M;
114
- E.stringify = se;
115
- const C = "/", D = (t) => t, L = /^[$_\p{ID_Start}]$/u, I = /^[$\u200c\u200d\p{ID_Continue}]$/u, T = "https://git.new/pathToRegexpError", G = {
168
+ k.TokenData = void 0;
169
+ k.parse = N;
170
+ var Y = k.compile = se, Z = k.match = ae;
171
+ k.pathToRegexp = K;
172
+ k.stringify = ue;
173
+ const F = "/", I = (t) => t, J = /^[$_\p{ID_Start}]$/u, D = /^[$\u200c\u200d\p{ID_Continue}]$/u, A = "https://git.new/pathToRegexpError", ee = {
116
174
  // Groups.
117
175
  "{": "{",
118
176
  "}": "}",
@@ -125,41 +183,41 @@ const C = "/", D = (t) => t, L = /^[$_\p{ID_Start}]$/u, I = /^[$\u200c\u200d\p{I
125
183
  "?": "?",
126
184
  "!": "!"
127
185
  };
128
- function K(t) {
186
+ function te(t) {
129
187
  return t.replace(/[{}()\[\]+?!:*]/g, "\\$&");
130
188
  }
131
- function v(t) {
189
+ function x(t) {
132
190
  return t.replace(/[.+*?^${}()[\]|/\\]/g, "\\$&");
133
191
  }
134
- function* X(t) {
192
+ function* ne(t) {
135
193
  const n = [...t];
136
194
  let e = 0;
137
195
  function r() {
138
196
  let s = "";
139
- if (L.test(n[++e]))
140
- for (s += n[e]; I.test(n[++e]); )
197
+ if (J.test(n[++e]))
198
+ for (s += n[e]; D.test(n[++e]); )
141
199
  s += n[e];
142
200
  else if (n[e] === '"') {
143
- let a = e;
201
+ let o = e;
144
202
  for (; e < n.length; ) {
145
203
  if (n[++e] === '"') {
146
- e++, a = 0;
204
+ e++, o = 0;
147
205
  break;
148
206
  }
149
207
  n[e] === "\\" ? s += n[++e] : s += n[e];
150
208
  }
151
- if (a)
152
- throw new TypeError(`Unterminated quote at ${a}: ${T}`);
209
+ if (o)
210
+ throw new TypeError(`Unterminated quote at ${o}: ${A}`);
153
211
  }
154
212
  if (!s)
155
- throw new TypeError(`Missing parameter name at ${e}: ${T}`);
213
+ throw new TypeError(`Missing parameter name at ${e}: ${A}`);
156
214
  return s;
157
215
  }
158
216
  for (; e < n.length; ) {
159
- const s = n[e], a = G[s];
160
- if (a)
217
+ const s = n[e], o = ee[s];
218
+ if (o)
161
219
  yield {
162
- type: a,
220
+ type: o,
163
221
  index: e++,
164
222
  value: s
165
223
  };
@@ -170,18 +228,18 @@ function* X(t) {
170
228
  value: n[e++]
171
229
  };
172
230
  else if (s === ":") {
173
- const o = r();
231
+ const a = r();
174
232
  yield {
175
233
  type: "PARAM",
176
234
  index: e,
177
- value: o
235
+ value: a
178
236
  };
179
237
  } else if (s === "*") {
180
- const o = r();
238
+ const a = r();
181
239
  yield {
182
240
  type: "WILDCARD",
183
241
  index: e,
184
- value: o
242
+ value: a
185
243
  };
186
244
  } else
187
245
  yield {
@@ -196,7 +254,7 @@ function* X(t) {
196
254
  value: ""
197
255
  };
198
256
  }
199
- class Y {
257
+ class re {
200
258
  constructor(n) {
201
259
  this.tokens = n;
202
260
  }
@@ -219,7 +277,7 @@ class Y {
219
277
  type: r,
220
278
  index: s
221
279
  } = this.peek();
222
- throw new TypeError(`Unexpected ${r} at ${s}, expected ${n}: ${T}`);
280
+ throw new TypeError(`Unexpected ${r} at ${s}, expected ${n}: ${A}`);
223
281
  }
224
282
  text() {
225
283
  let n = "", e;
@@ -228,17 +286,17 @@ class Y {
228
286
  return n;
229
287
  }
230
288
  }
231
- class F {
289
+ class R {
232
290
  constructor(n) {
233
291
  this.tokens = n;
234
292
  }
235
293
  }
236
- E.TokenData = F;
237
- function O(t, n = {}) {
294
+ k.TokenData = R;
295
+ function N(t, n = {}) {
238
296
  const {
239
- encodePath: e = D
240
- } = n, r = new Y(X(t));
241
- function s(o) {
297
+ encodePath: e = I
298
+ } = n, r = new re(ne(t));
299
+ function s(a) {
242
300
  const i = [];
243
301
  for (; ; ) {
244
302
  const u = r.text();
@@ -254,11 +312,11 @@ function O(t, n = {}) {
254
312
  });
255
313
  continue;
256
314
  }
257
- const p = r.tryConsume("WILDCARD");
258
- if (p) {
315
+ const d = r.tryConsume("WILDCARD");
316
+ if (d) {
259
317
  i.push({
260
318
  type: "wildcard",
261
- name: p
319
+ name: d
262
320
  });
263
321
  continue;
264
322
  }
@@ -269,169 +327,169 @@ function O(t, n = {}) {
269
327
  });
270
328
  continue;
271
329
  }
272
- return r.consume(o), i;
330
+ return r.consume(a), i;
273
331
  }
274
332
  }
275
- const a = s("END");
276
- return new F(a);
333
+ const o = s("END");
334
+ return new R(o);
277
335
  }
278
- function Z(t, n = {}) {
336
+ function se(t, n = {}) {
279
337
  const {
280
338
  encode: e = encodeURIComponent,
281
- delimiter: r = C
282
- } = n, s = t instanceof F ? t : O(t, n), a = B(s.tokens, r, e);
339
+ delimiter: r = F
340
+ } = n, s = t instanceof R ? t : N(t, n), o = q(s.tokens, r, e);
283
341
  return function(i = {}) {
284
- const [u, ...c] = a(i);
342
+ const [u, ...c] = o(i);
285
343
  if (c.length)
286
344
  throw new TypeError(`Missing parameters: ${c.join(", ")}`);
287
345
  return u;
288
346
  };
289
347
  }
290
- function B(t, n, e) {
291
- const r = t.map((s) => ee(s, n, e));
348
+ function q(t, n, e) {
349
+ const r = t.map((s) => oe(s, n, e));
292
350
  return (s) => {
293
- const a = [""];
294
- for (const o of r) {
295
- const [i, ...u] = o(s);
296
- a[0] += i, a.push(...u);
351
+ const o = [""];
352
+ for (const a of r) {
353
+ const [i, ...u] = a(s);
354
+ o[0] += i, o.push(...u);
297
355
  }
298
- return a;
356
+ return o;
299
357
  };
300
358
  }
301
- function ee(t, n, e) {
359
+ function oe(t, n, e) {
302
360
  if (t.type === "text") return () => [t.value];
303
361
  if (t.type === "group") {
304
- const s = B(t.tokens, n, e);
305
- return (a) => {
306
- const [o, ...i] = s(a);
307
- return i.length ? [""] : [o];
362
+ const s = q(t.tokens, n, e);
363
+ return (o) => {
364
+ const [a, ...i] = s(o);
365
+ return i.length ? [""] : [a];
308
366
  };
309
367
  }
310
- const r = e || D;
368
+ const r = e || I;
311
369
  return t.type === "wildcard" && e !== !1 ? (s) => {
312
- const a = s[t.name];
313
- if (a == null) return ["", t.name];
314
- if (!Array.isArray(a) || a.length === 0)
370
+ const o = s[t.name];
371
+ if (o == null) return ["", t.name];
372
+ if (!Array.isArray(o) || o.length === 0)
315
373
  throw new TypeError(`Expected "${t.name}" to be a non-empty array`);
316
- return [a.map((o, i) => {
317
- if (typeof o != "string")
374
+ return [o.map((a, i) => {
375
+ if (typeof a != "string")
318
376
  throw new TypeError(`Expected "${t.name}/${i}" to be a string`);
319
- return r(o);
377
+ return r(a);
320
378
  }).join(n)];
321
379
  } : (s) => {
322
- const a = s[t.name];
323
- if (a == null) return ["", t.name];
324
- if (typeof a != "string")
380
+ const o = s[t.name];
381
+ if (o == null) return ["", t.name];
382
+ if (typeof o != "string")
325
383
  throw new TypeError(`Expected "${t.name}" to be a string`);
326
- return [r(a)];
384
+ return [r(o)];
327
385
  };
328
386
  }
329
- function te(t, n = {}) {
387
+ function ae(t, n = {}) {
330
388
  const {
331
389
  decode: e = decodeURIComponent,
332
- delimiter: r = C
390
+ delimiter: r = F
333
391
  } = n, {
334
392
  regexp: s,
335
- keys: a
336
- } = M(t, n), o = a.map((i) => e === !1 ? D : i.type === "param" ? e : (u) => u.split(r).map(e));
393
+ keys: o
394
+ } = K(t, n), a = o.map((i) => e === !1 ? I : i.type === "param" ? e : (u) => u.split(r).map(e));
337
395
  return function(u) {
338
396
  const c = s.exec(u);
339
397
  if (!c) return !1;
340
- const p = c[0], f = /* @__PURE__ */ Object.create(null);
341
- for (let m = 1; m < c.length; m++) {
342
- if (c[m] === void 0) continue;
343
- const g = a[m - 1], A = o[m - 1];
344
- f[g.name] = A(c[m]);
398
+ const d = c[0], p = /* @__PURE__ */ Object.create(null);
399
+ for (let h = 1; h < c.length; h++) {
400
+ if (c[h] === void 0) continue;
401
+ const v = o[h - 1], y = a[h - 1];
402
+ p[v.name] = y(c[h]);
345
403
  }
346
404
  return {
347
- path: p,
348
- params: f
405
+ path: d,
406
+ params: p
349
407
  };
350
408
  };
351
409
  }
352
- function M(t, n = {}) {
410
+ function K(t, n = {}) {
353
411
  const {
354
- delimiter: e = C,
412
+ delimiter: e = F,
355
413
  end: r = !0,
356
414
  sensitive: s = !1,
357
- trailing: a = !0
358
- } = n, o = [], i = [], u = s ? "" : "i", p = (Array.isArray(t) ? t : [t]).map((g) => g instanceof F ? g : O(g, n));
415
+ trailing: o = !0
416
+ } = n, a = [], i = [], u = s ? "" : "i", d = (Array.isArray(t) ? t : [t]).map((v) => v instanceof R ? v : N(v, n));
359
417
  for (const {
360
- tokens: g
361
- } of p)
362
- for (const A of R(g, 0, [])) {
363
- const N = ne(A, e, o);
364
- i.push(N);
418
+ tokens: v
419
+ } of d)
420
+ for (const y of j(v, 0, [])) {
421
+ const l = ie(y, e, a);
422
+ i.push(l);
365
423
  }
366
- let f = `^(?:${i.join("|")})`;
367
- return a && (f += `(?:${v(e)}$)?`), f += r ? "$" : `(?=${v(e)}|$)`, {
368
- regexp: new RegExp(f, u),
369
- keys: o
424
+ let p = `^(?:${i.join("|")})`;
425
+ return o && (p += `(?:${x(e)}$)?`), p += r ? "$" : `(?=${x(e)}|$)`, {
426
+ regexp: new RegExp(p, u),
427
+ keys: a
370
428
  };
371
429
  }
372
- function* R(t, n, e) {
430
+ function* j(t, n, e) {
373
431
  if (n === t.length)
374
432
  return yield e;
375
433
  const r = t[n];
376
434
  if (r.type === "group") {
377
435
  const s = e.slice();
378
- for (const a of R(r.tokens, 0, s))
379
- yield* R(t, n + 1, a);
436
+ for (const o of j(r.tokens, 0, s))
437
+ yield* j(t, n + 1, o);
380
438
  } else
381
439
  e.push(r);
382
- yield* R(t, n + 1, e);
440
+ yield* j(t, n + 1, e);
383
441
  }
384
- function ne(t, n, e) {
385
- let r = "", s = "", a = !0;
386
- for (let o = 0; o < t.length; o++) {
387
- const i = t[o];
442
+ function ie(t, n, e) {
443
+ let r = "", s = "", o = !0;
444
+ for (let a = 0; a < t.length; a++) {
445
+ const i = t[a];
388
446
  if (i.type === "text") {
389
- r += v(i.value), s += i.value, a || (a = i.value.includes(n));
447
+ r += x(i.value), s += i.value, o || (o = i.value.includes(n));
390
448
  continue;
391
449
  }
392
450
  if (i.type === "param" || i.type === "wildcard") {
393
- if (!a && !s)
394
- throw new TypeError(`Missing text after "${i.name}": ${T}`);
395
- i.type === "param" ? r += `(${re(n, a ? "" : s)}+)` : r += "([\\s\\S]+)", e.push(i), s = "", a = !1;
451
+ if (!o && !s)
452
+ throw new TypeError(`Missing text after "${i.name}": ${A}`);
453
+ i.type === "param" ? r += `(${ce(n, o ? "" : s)}+)` : r += "([\\s\\S]+)", e.push(i), s = "", o = !1;
396
454
  continue;
397
455
  }
398
456
  }
399
457
  return r;
400
458
  }
401
- function re(t, n) {
402
- return n.length < 2 ? t.length < 2 ? `[^${v(t + n)}]` : `(?:(?!${v(t)})[^${v(n)}])` : t.length < 2 ? `(?:(?!${v(n)})[^${v(t)}])` : `(?:(?!${v(n)}|${v(t)})[\\s\\S])`;
459
+ function ce(t, n) {
460
+ return n.length < 2 ? t.length < 2 ? `[^${x(t + n)}]` : `(?:(?!${x(t)})[^${x(n)}])` : t.length < 2 ? `(?:(?!${x(n)})[^${x(t)}])` : `(?:(?!${x(n)}|${x(t)})[\\s\\S])`;
403
461
  }
404
- function se(t) {
462
+ function ue(t) {
405
463
  return t.tokens.map(function n(e, r, s) {
406
- if (e.type === "text") return K(e.value);
464
+ if (e.type === "text") return te(e.value);
407
465
  if (e.type === "group")
408
466
  return `{${e.tokens.map(n).join("")}}`;
409
- const o = ae(e.name) && oe(s[r + 1]) ? e.name : JSON.stringify(e.name);
410
- if (e.type === "param") return `:${o}`;
411
- if (e.type === "wildcard") return `*${o}`;
467
+ const a = le(e.name) && fe(s[r + 1]) ? e.name : JSON.stringify(e.name);
468
+ if (e.type === "param") return `:${a}`;
469
+ if (e.type === "wildcard") return `*${a}`;
412
470
  throw new TypeError(`Unexpected token: ${e}`);
413
471
  }).join("");
414
472
  }
415
- function ae(t) {
473
+ function le(t) {
416
474
  const [n, ...e] = t;
417
- return L.test(n) ? e.every((r) => I.test(r)) : !1;
475
+ return J.test(n) ? e.every((r) => D.test(r)) : !1;
418
476
  }
419
- function oe(t) {
420
- return (t == null ? void 0 : t.type) !== "text" ? !0 : !I.test(t.value[0]);
477
+ function fe(t) {
478
+ return (t == null ? void 0 : t.type) !== "text" ? !0 : !D.test(t.value[0]);
421
479
  }
422
- const ie = Symbol("any"), ce = Symbol("number"), ue = Symbol("string"), le = Symbol("array"), k = {
423
- any: ie,
424
- number: ce,
425
- string: ue,
426
- array: le
480
+ const pe = Symbol("any"), de = Symbol("number"), ye = Symbol("string"), me = Symbol("array"), $ = {
481
+ any: pe,
482
+ number: de,
483
+ string: ye,
484
+ array: me
427
485
  };
428
- function U(t, n) {
486
+ function H(t, n) {
429
487
  for (const e of t)
430
488
  if (!n.includes(e))
431
489
  return !1;
432
490
  return !0;
433
491
  }
434
- function H(t, n) {
492
+ function M(t, n) {
435
493
  for (const e in n) {
436
494
  const r = n[e];
437
495
  if (Array.isArray(r) && (!t[e] || JSON.stringify(r) !== t[e]))
@@ -459,22 +517,22 @@ function H(t, n) {
459
517
  }
460
518
  }
461
519
  switch (r) {
462
- case k.any: {
520
+ case $.any: {
463
521
  if (!t[e])
464
522
  return !1;
465
523
  break;
466
524
  }
467
- case k.string: {
525
+ case $.string: {
468
526
  if (!t[e] || Array.isArray(t[e]))
469
527
  return !1;
470
528
  break;
471
529
  }
472
- case k.array: {
530
+ case $.array: {
473
531
  if (!t[e] || !Array.isArray(t[e]))
474
532
  return !1;
475
533
  break;
476
534
  }
477
- case k.number: {
535
+ case $.number: {
478
536
  if (!t[e] || Array.isArray(t[e]) || isNaN(parseInt(t[e])) && isNaN(parseFloat(t[e])))
479
537
  return !1;
480
538
  break;
@@ -483,64 +541,64 @@ function H(t, n) {
483
541
  }
484
542
  return !0;
485
543
  }
486
- function pe(t, n) {
544
+ function he(t, n) {
487
545
  const e = {};
488
546
  for (const r in n) {
489
- const s = n[r], a = t[r];
547
+ const s = n[r], o = t[r];
490
548
  if (Array.isArray(s)) {
491
- e[r] = a === "1" || a === "true";
549
+ e[r] = o === "1" || o === "true";
492
550
  continue;
493
551
  }
494
552
  switch (typeof s) {
495
553
  case "number": {
496
- const o = t[r];
497
- e[r] = isNaN(parseInt(o)) ? parseFloat(o) : parseInt(o);
554
+ const a = t[r];
555
+ e[r] = isNaN(parseInt(a)) ? parseFloat(a) : parseInt(a);
498
556
  break;
499
557
  }
500
558
  case "object": {
501
- e[r] = JSON.parse(a);
559
+ e[r] = JSON.parse(o);
502
560
  break;
503
561
  }
504
562
  case "string":
505
563
  e[r] = t[r];
506
564
  case "boolean": {
507
- const o = t[r];
508
- e[r] = o === "0" ? parseFloat(o) : parseInt(o);
565
+ const a = t[r];
566
+ e[r] = a === "0" ? parseFloat(a) : parseInt(a);
509
567
  break;
510
568
  }
511
569
  }
512
570
  switch (s) {
513
- case k.any:
514
- case k.string:
515
- case k.array: {
571
+ case $.any:
572
+ case $.string:
573
+ case $.array: {
516
574
  e[r] = t[r];
517
575
  break;
518
576
  }
519
- case k.number: {
520
- const o = t[r];
521
- e[r] = isNaN(parseInt(o)) ? parseFloat(o) : parseInt(o);
577
+ case $.number: {
578
+ const a = t[r];
579
+ e[r] = isNaN(parseInt(a)) ? parseFloat(a) : parseInt(a);
522
580
  break;
523
581
  }
524
582
  }
525
583
  }
526
584
  return e;
527
585
  }
528
- function fe(t, n) {
586
+ function ge(t, n) {
529
587
  return (e) => {
530
588
  const {
531
589
  parameters: r,
532
590
  forRoutes: s
533
- } = e, a = x({
591
+ } = e, o = w({
534
592
  name: "entered",
535
593
  sid: "-d3obu6"
536
- }), o = x({
594
+ }), a = w({
537
595
  name: "exited",
538
596
  sid: "-xofyk3"
539
- }), i = x({
597
+ }), i = w({
540
598
  name: "exit",
541
599
  sid: "-673d76"
542
600
  });
543
- return w({
601
+ return g({
544
602
  and: [{
545
603
  source: {
546
604
  activeRoutes: t,
@@ -549,21 +607,21 @@ function fe(t, n) {
549
607
  filter: (u) => {
550
608
  let {
551
609
  activeRoutes: c,
552
- query: p
610
+ query: d
553
611
  } = u;
554
- return (!s || U(s, c)) && H(p, r);
612
+ return (!s || H(s, c)) && M(d, r);
555
613
  },
556
614
  fn: (u) => {
557
615
  let {
558
616
  query: c
559
617
  } = u;
560
- return pe(c, r);
618
+ return he(c, r);
561
619
  }
562
620
  }],
563
621
  or: {
564
622
  sid: "-so0f9q"
565
623
  }
566
- }), w({
624
+ }), g({
567
625
  and: [{
568
626
  source: {
569
627
  activeRoutes: t,
@@ -572,221 +630,243 @@ function fe(t, n) {
572
630
  filter: (u) => {
573
631
  let {
574
632
  activeRoutes: c,
575
- query: p
633
+ query: d
576
634
  } = u;
577
- return !((!s || U(s, c)) && H(p, r));
635
+ return !((!s || H(s, c)) && M(d, r));
578
636
  },
579
- target: o
637
+ target: a
580
638
  }],
581
639
  or: {
582
640
  sid: "-s82e29"
583
641
  }
584
642
  }), {
585
- entered: a,
586
- exited: o,
643
+ entered: o,
644
+ exited: a,
587
645
  exit: i,
588
- getPayload: (u) => Object.entries(u).reduce((c, p) => {
589
- let [f, m] = p;
590
- return typeof r[f] == "symbol" ? c[f] = m : c[f] = r[f], c;
646
+ getPayload: (u) => Object.entries(u).reduce((c, d) => {
647
+ let [p, h] = d;
648
+ return typeof r[p] == "symbol" ? c[p] = h : c[p] = r[p], c;
591
649
  }, {})
592
650
  };
593
651
  };
594
652
  }
595
- function he(t) {
653
+ function z(t) {
654
+ const n = new URLSearchParams(t.search);
655
+ return {
656
+ path: t.pathname,
657
+ query: [...n.keys()].reduce((e, r) => (e[r] ? e[r] = n.getAll(r) : e[r] = n.get(r), e), {})
658
+ };
659
+ }
660
+ function xe(t) {
596
661
  const {
597
662
  base: n = "/",
598
- history: e,
599
- routes: r
600
- } = t, s = S({}, {
663
+ routes: e
664
+ } = t, r = O({}, {
601
665
  name: "$query",
602
- sid: "2wd7x1"
603
- }), a = S(e ?? null, {
666
+ sid: "uczasb"
667
+ }), s = O(null, {
604
668
  name: "$history",
605
- sid: "31majq"
606
- }), o = S("/", {
669
+ sid: "ui8df0"
670
+ }), o = O(null, {
607
671
  name: "$path",
608
- sid: "ld3nhr"
609
- }), i = S([], {
672
+ sid: "-m7ebm3"
673
+ }), a = O([], {
610
674
  name: "$activeRoutes",
611
- sid: "mrug12"
612
- }), u = x({
675
+ sid: "-ksnj2s"
676
+ }), i = w({
613
677
  name: "setHistory",
614
- sid: "sekwlw"
615
- }), c = x({
678
+ sid: "-p3v4s1"
679
+ }), u = w({
616
680
  name: "back",
617
- sid: "-icnnoo"
618
- }), p = x({
681
+ sid: "-tzn3h"
682
+ }), c = w({
619
683
  name: "forward",
620
- sid: "-72o1my"
621
- }), f = x({
684
+ sid: "afzyy9"
685
+ }), d = w({
622
686
  name: "locationUpdated",
623
- sid: "d8lu52"
624
- }), m = r.map((d) => {
625
- let h = d;
626
- const l = [];
627
- for (l.unshift(h.internal.path); h.internal.parent; )
628
- h = h.internal.parent, l.unshift(h.internal.path);
629
- const y = (n === "/" ? l : [n, ...l]).join("");
687
+ sid: "-ubw4ys"
688
+ }), p = e.map((l) => {
689
+ let b = l;
690
+ const f = [];
691
+ for (f.unshift(b.internal.path); b.internal.parent; )
692
+ b = b.internal.parent, b.internal.path !== "/" && f.unshift(b.internal.path);
693
+ const m = n === "/" ? f.join("") : [n, ...f].join("");
630
694
  return {
631
- route: d,
632
- path: y,
633
- toPath: W(y),
634
- fromPath: z(y)
695
+ route: l,
696
+ path: m,
697
+ toPath: Y(m),
698
+ fromPath: Z(m)
635
699
  };
636
- }), g = _({
700
+ }), h = C({
637
701
  and: {
638
702
  source: {
639
- history: a
703
+ history: s
640
704
  },
641
- effect: async (d, h) => {
705
+ effect: async (l, b) => {
642
706
  let {
643
- history: l
644
- } = d, {
645
- path: y,
646
- query: b,
647
- replace: $
648
- } = h;
649
- if (!l)
707
+ history: f
708
+ } = l, {
709
+ path: m,
710
+ query: S,
711
+ replace: E
712
+ } = b;
713
+ if (!f)
650
714
  throw new Error("history not found");
651
- const j = {
652
- pathname: y,
653
- query: b
715
+ const _ = {
716
+ pathname: m,
717
+ query: S
654
718
  };
655
- $ ? l.replace(j) : l.push(j);
719
+ E ? f.replace(_) : f.push(_.pathname);
656
720
  }
657
721
  },
658
722
  or: {
659
723
  name: "updateHistoryFx",
660
- sid: "h74tsu"
724
+ sid: "-oy8a4f"
661
725
  }
662
726
  });
663
727
  for (const {
664
- route: d,
665
- toPath: h
666
- } of m)
667
- w({
728
+ route: l,
729
+ toPath: b
730
+ } of p)
731
+ g({
668
732
  and: [{
669
- clock: d.opened,
670
- source: i,
671
- fn: (l) => [...l, d],
672
- target: i
733
+ clock: l.opened,
734
+ source: a,
735
+ filter: (f) => !f.includes(l),
736
+ fn: (f) => [...f, l],
737
+ target: a
673
738
  }],
674
739
  or: {
675
- sid: "-px1r6l"
740
+ sid: "e1k4q5"
676
741
  }
677
- }), w({
742
+ }), g({
678
743
  and: [{
679
- clock: d.opened,
680
- fn: (l) => {
744
+ clock: l.opened,
745
+ filter: (f) => !f.historyIgnore,
746
+ fn: function() {
681
747
  let {
682
- params: y,
683
- query: b,
684
- replace: $
685
- } = l;
748
+ params: f,
749
+ query: m,
750
+ replace: S
751
+ } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
752
+ params: {}
753
+ };
686
754
  return {
687
- path: h(y),
688
- query: b ?? {},
689
- replace: $
755
+ path: b(f),
756
+ query: m ?? {},
757
+ replace: S
690
758
  };
691
759
  },
692
- target: g
760
+ target: h
693
761
  }],
694
762
  or: {
695
- sid: "-phnikh"
763
+ sid: "ehi5xm"
696
764
  }
697
- }), w({
765
+ }), g({
698
766
  and: [{
699
- clock: d.closed,
700
- source: i,
701
- fn: (l) => l.filter((y) => y !== d),
702
- target: i
767
+ clock: l.closed,
768
+ source: a,
769
+ fn: (f) => f.filter((m) => m !== l),
770
+ target: a
703
771
  }],
704
772
  or: {
705
- sid: "e0gjjf"
773
+ sid: "ez3kx6"
706
774
  }
707
775
  });
708
- w({
776
+ g({
709
777
  and: [{
710
- clock: u,
711
- target: a
778
+ clock: i,
779
+ target: s
712
780
  }],
713
781
  or: {
714
- sid: "egekp6"
782
+ sid: "ff1m2x"
715
783
  }
716
784
  });
717
- const A = P((d) => {
718
- const h = V(f);
719
- if (!d)
785
+ const v = P((l) => {
786
+ const b = Q(d);
787
+ if (!l)
720
788
  throw new Error();
721
- d.listen((l) => {
789
+ l.listen((f) => {
722
790
  let {
723
- location: y
724
- } = l;
725
- h(y);
791
+ location: m
792
+ } = f;
793
+ b(m);
726
794
  });
727
795
  }, {
728
796
  name: "subscribeHistoryFx",
729
- sid: "5cocq6"
730
- }), N = _({
797
+ sid: "z6ijkf"
798
+ }), y = C({
731
799
  and: {
732
800
  source: {
733
- query: s,
801
+ query: r,
734
802
  path: o
735
803
  },
736
- effect: async (d) => {
804
+ effect: async (l) => {
737
805
  let {
738
- query: h,
739
- path: l
740
- } = d;
806
+ query: b,
807
+ path: f
808
+ } = l;
741
809
  for (const {
742
- route: y,
743
- fromPath: b
744
- } of m) {
745
- const $ = b(l);
746
- if ($)
747
- await y.internal.openFx({
748
- query: h,
749
- params: $.params
810
+ route: m,
811
+ fromPath: S
812
+ } of p) {
813
+ const E = S(f);
814
+ if (E)
815
+ await m.internal.openFx({
816
+ query: b,
817
+ params: E.params
750
818
  });
751
- else
819
+ else {
820
+ m.internal.close();
752
821
  continue;
822
+ }
753
823
  }
754
824
  }
755
825
  },
756
826
  or: {
757
827
  name: "openRoutesByPathFx",
758
- sid: "tmly43"
828
+ sid: "-1mpuqp"
759
829
  }
760
830
  });
761
- return w({
831
+ return g({
762
832
  and: [{
763
- clock: a,
833
+ clock: s,
764
834
  filter: Boolean,
765
- target: A
835
+ target: v
766
836
  }],
767
837
  or: {
768
- sid: "fwn12h"
838
+ sid: "gvtv1l"
769
839
  }
770
- }), w({
840
+ }), g({
771
841
  and: [{
772
- clock: f,
773
- fn: (d) => {
774
- let {
775
- pathname: h,
776
- search: l
777
- } = d;
778
- const y = new URLSearchParams(l);
779
- return {
780
- path: h,
781
- query: [...y.keys()].reduce((b, $) => (b[$] ? b[$] = y.getAll($) : b[$] = y.get($), b), {})
782
- };
783
- },
784
- target: q({
785
- sid: "f47wtp",
786
- fn: () => Q({
842
+ clock: s,
843
+ filter: Boolean,
844
+ fn: (l) => z(l.location),
845
+ target: U({
846
+ sid: "suiy9c",
847
+ fn: () => L({
848
+ targets: {
849
+ path: o,
850
+ query: r
851
+ }
852
+ }),
853
+ name: "target",
854
+ method: "spread"
855
+ })
856
+ }],
857
+ or: {
858
+ sid: "haob2c"
859
+ }
860
+ }), g({
861
+ and: [{
862
+ clock: [d],
863
+ fn: (l) => z(l),
864
+ target: U({
865
+ sid: "-r1573k",
866
+ fn: () => L({
787
867
  targets: {
788
868
  path: o,
789
- query: s
869
+ query: r
790
870
  }
791
871
  }),
792
872
  name: "target",
@@ -794,37 +874,37 @@ function he(t) {
794
874
  })
795
875
  }],
796
876
  or: {
797
- sid: "gbhh38"
877
+ sid: "hstin9"
798
878
  }
799
- }), w({
879
+ }), g({
800
880
  and: [{
801
881
  clock: o,
802
- target: N
882
+ target: y
803
883
  }],
804
884
  or: {
805
- sid: "hcvhfs"
885
+ sid: "iaexmt"
806
886
  }
807
887
  }), {
808
- $query: s,
888
+ $query: r,
809
889
  $path: o,
810
- $activeRoutes: i,
811
- back: c,
812
- forward: p,
813
- routes: r,
814
- setHistory: u,
815
- mappedRoutes: m,
816
- trackQuery: fe(i, s),
890
+ $activeRoutes: a,
891
+ back: u,
892
+ forward: c,
893
+ routes: e,
894
+ setHistory: i,
895
+ mappedRoutes: p,
896
+ trackQuery: ge(a, r),
817
897
  "@@unitShape": () => ({
818
- query: s,
898
+ query: r,
819
899
  path: o,
820
- activeRoutes: i,
821
- onBack: c,
822
- onForward: p
900
+ activeRoutes: a,
901
+ onBack: u,
902
+ onForward: c
823
903
  })
824
904
  };
825
905
  }
826
906
  export {
827
- me as createRoute,
828
- he as createRouter,
829
- k as parameters
907
+ we as createRoute,
908
+ xe as createRouter,
909
+ $ as parameters
830
910
  };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "registry": "https://registry.npmjs.org/"
6
6
  },
7
7
  "private": false,
8
- "version": "0.1.0",
8
+ "version": "0.1.2",
9
9
  "description": "Router with power of effector",
10
10
  "keywords": [
11
11
  "effector",
@@ -55,5 +55,5 @@
55
55
  "path-to-regexp": "^8.2.0",
56
56
  "typed-url-params": "^1.0.1"
57
57
  },
58
- "gitHead": "59ab2eda9dffd095ffe5c4625b6a40cd71487410"
58
+ "gitHead": "c5ab346d7c4ed17a58dba0e133895193c93f76d5"
59
59
  }