atomic-router
Advanced tools
Comparing version 0.5.0-dev.20 to 0.5.0-dev.21
@@ -1,1 +0,1 @@ | ||
var ee=Object.defineProperty,te=Object.defineProperties;var ae=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var B=(e,t,a)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,S=(e,t)=>{for(var a in t||(t={}))re.call(t,a)&&B(e,a,t[a]);if(M)for(var a of M(t))oe.call(t,a)&&B(e,a,t[a]);return e},T=(e,t)=>te(e,ae(t));import{attach as se,createEffect as ne,createEvent as A,createStore as U,sample as K,split as L}from"effector";var I={ROUTE:Symbol()};var j=(e={})=>{let t=ne(async({params:s,query:u})=>({params:s||{},query:u||{}})),a=se({effect:t,mapParams:s=>({params:s||{},query:{}})}),p=U(!1),i=U({}),o=U({}),c=A(),d=A(),l=A(),y=A();if(p.on(c,()=>!0).on(l,()=>!1),i.on(c,(s,{params:u})=>u).on(d,(s,{params:u})=>u),o.on(c,(s,{query:u})=>u).on(d,(s,{query:u})=>u),L({source:t.doneData,match:p.map(s=>s?"updated":"opened"),cases:{opened:c,updated:d}}),K({clock:y,target:l}),e.filter){let s=e.filter;L({source:K({clock:s}),match:u=>u?"true":"false",cases:{true:c,false:y}})}return{$isOpened:p,$params:i,$query:o,opened:c,updated:d,closed:y,left:l,navigate:t,open:a,kind:I.ROUTE,settings:{derived:Boolean(e.filter)}}};import{match as ce,compile as ue}from"path-to-regexp";var me=e=>{if(e.match(/^[a-z0-9]+\:\/\//i))return e;let t=new URL(`http://_${e}`);return[t.pathname,t.hash].join("")},ie=e=>e.replace("://","\\://");function N({pathCreator:e,params:t,query:a}){let p=ue(e)(t),i=Object.keys(a).length?`?${new URLSearchParams(a)}`:"";return`${p}${i}`}function V({pathCreator:e,actualPath:t}){let a=ce(ie(e))(me(t));return a?{matches:!0,params:a.params}:{matches:!1}}import{attach as H,createEffect as _,guard as v,sample as k,createStore as Q,createEvent as W,scopeBind as pe,restore as le}from"effector";var D=(e,t)=>{if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let a in e)if(`${e[a]}`!=`${t[a]}`)return!1;return!0};var de=_(e=>{if(!e.history)throw new Error("[Routing] No history provided");return e.history[e.method](e.path,{}),e}),Pe=(e,t="")=>{let a=[];for(let o of e)Array.isArray(o.route)?a.push(...o.route.map(c=>T(S({},o),{route:c}))):a.push(o);a=a.map(o=>T(S({},o),{path:`${t}${o.path}`}));let p=[],i=[];for(let o of a)o.route.settings.derived?p.push(o):i.push(o);if(p.length)for(let o of p)console.error(`createHistoryRouter: ${o.path} uses derived route. This won't work`);return i},_e=e=>{let t=Pe(e.routes,e.base),a=W(),p=W(),i=Q({}),o=Q(""),c=Q([],{serialize:"ignore"}),d=Q(!1),l=Q(null,{serialize:"ignore"});l.on(a,(r,n)=>n);let y=H({source:{history:l},effect:de,mapParams:(r,{history:n})=>S({history:n},r)}),E=_(({route:r,params:n,query:P})=>({path:N({pathCreator:r.path,params:n,query:P}),params:n,query:P,method:"push"})),s=_(({path:r,query:n,hash:P})=>{let h=[],R=[];for(let g of t){let m=g.path.includes("#")?`${r}${P}`:`${r}`,{matches:f,params:$}=V({pathCreator:`${g.path}`,actualPath:m});(f?h:R).push({route:g,params:$,query:n})}for(let g in R){let m=g;h.some(f=>f.route.route===R[m].route.route)&&(R[m]=null)}return R=R.filter(Boolean),{opened:h,closed:R}});o.on(s.done,(r,{params:{path:n}})=>n),i.on(s.done,(r,{params:{query:n}})=>n),c.on(s.doneData,(r,{opened:n})=>n.map(P=>P.route.route)),k({clock:E.doneData,target:y}),v({clock:s.doneData,filter:({opened:r})=>r.length===0,target:p});let u=s.doneData.map(({opened:r})=>r),O=s.doneData.map(({closed:r})=>r);for(let r of t){let n=Q(!1),P=r.route.navigate.done;k({clock:P,fn:({result:{params:m,query:f}})=>({route:r,params:m,query:f}),target:E});let h=m=>{let f=m.find($=>$.route.route===r.route);if(!!f)return{params:f.params,query:f.query}},R={opened:v({clock:u.filterMap(h),filter:r.route.$isOpened.map(m=>!m)}),updated:v({clock:u.filterMap(h),filter:r.route.$isOpened}),closed:v({clock:O.filterMap(h),filter:r.route.$isOpened})};n.on(P,()=>!0);let g=v({clock:R.updated,filter:n.map(m=>!m)});k({source:le(g,null),clock:v({clock:g,source:[r.route.$params,r.route.$query],filter:([m,f],$)=>!D(m,$.params)||!D(f,$.query)}),fn:m=>m,target:r.route.updated}),v({clock:R.opened,filter:n.map(m=>!m),target:r.route.opened}),k({clock:R.closed,target:r.route.closed}),n.reset(k({clock:u}))}let q=H({source:{history:l},effect:async({history:r})=>{let[n,P,h]=[r.location.pathname,Object.fromEntries(new URLSearchParams(r.location.search)),r.location.hash];return{path:n,query:P,hash:h}}});k({source:q.doneData,target:s});let z=H({source:{history:l},effect:async({history:r})=>{let n=q;try{n=pe(q)}catch{}return r.listen(()=>{n()}),!0}});e.hydrate||k({clock:z.doneData,target:q}),k({clock:l,target:z}),d.on(s.doneData,()=>!0).reset(l);let Z=k({clock:v({clock:d,filter:Boolean}),source:{activeRoutes:c,path:o,query:i}});return{$path:o,$query:i,$activeRoutes:c,$history:l,setHistory:a,push:y,routes:t,initialized:Z,routeNotFound:p}};var G=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===I.ROUTE;import{createEvent as Re,createStore as fe,is as ye,sample as J}from"effector";var Ve=e=>{let t=e.clock?J({clock:e.clock}):Re(),a=X(e.params||{}),p=X(e.query||{});return J({clock:t,source:{params:a,query:p},fn:({params:i,query:o},c)=>({params:typeof i=="function"?i(c):i,query:typeof o=="function"?o(c):o}),target:e.route.navigate}),t},X=e=>ye.store(e)?e:fe(e);import{is as he,guard as ke,merge as Oe,sample as C,combine as F,createStore as Y,createEvent as w}from"effector";var ge=e=>{if(G(e))return{route:e,chainedRoute:j(),beforeOpen:w(),openOn:[e.opened,e.closed],cancelOn:[w()]};let t=e;if(!("enterOn"in t)&&he.effect(t.beforeOpen))return{route:t.route,chainedRoute:t.chainedRoute||j(),beforeOpen:t.beforeOpen,openOn:t.beforeOpen.doneData,cancelOn:t.beforeOpen.failData};let a=e;return{route:a.route,chainedRoute:a.chainedRoute||j(),beforeOpen:a.beforeOpen,openOn:C({clock:a.openOn}),cancelOn:C({clock:a.cancelOn||w()})}},at=e=>{let{route:t,chainedRoute:a,beforeOpen:p,openOn:i,cancelOn:o}=ge(e),c=Y({}),d=Y({}),l=F(F([t.$params,t.$query]),F([c,d]),(u,O)=>u[0]===O[0]&&u[1]===O[1]),y=C({clock:[t.opened,t.updated]});C({clock:y,target:p}),c.on(y,(u,{params:O})=>O),d.on(y,(u,{query:O})=>O);let E=ke({clock:i,source:{params:c,query:d},filter:l});C({clock:E,target:a.navigate});let s=Oe([t.closed,o]);return c.reset(s),d.reset(s),C({clock:s,target:a.closed}),a};export{I as Kind,N as buildPath,at as chainRoute,_e as createHistoryRouter,j as createRoute,G as isRoute,V as matchPath,Ve as redirect}; | ||
var ee=Object.defineProperty,te=Object.defineProperties;var ae=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var B=(e,t,a)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,S=(e,t)=>{for(var a in t||(t={}))re.call(t,a)&&B(e,a,t[a]);if(M)for(var a of M(t))oe.call(t,a)&&B(e,a,t[a]);return e},j=(e,t)=>te(e,ae(t));import{attach as se,createEffect as ne,createEvent as T,createStore as U,sample as K,split as L}from"effector";var I={ROUTE:Symbol()};var A=(e={})=>{let t=ne(async({params:s,query:u})=>({params:s||{},query:u||{}})),a=se({effect:t,mapParams:s=>({params:s||{},query:{}})}),p=U(!1),i=U({}),o=U({}),c=T(),P=T(),l=T(),f=T();if(p.on(c,()=>!0).on(l,()=>!1),i.on(c,(s,{params:u})=>u).on(P,(s,{params:u})=>u),o.on(c,(s,{query:u})=>u).on(P,(s,{query:u})=>u),L({source:t.doneData,match:p.map(s=>s?"updated":"opened"),cases:{opened:c,updated:P}}),K({clock:f,target:l}),e.filter){let s=e.filter;L({source:K({clock:s}),match:u=>u?"true":"false",cases:{true:c,false:f}})}return{$isOpened:p,$params:i,$query:o,opened:c,updated:P,closed:f,left:l,navigate:t,open:a,kind:I.ROUTE,settings:{derived:Boolean(e.filter)}}};import{match as ce,compile as ue}from"path-to-regexp";var me=e=>{if(e.match(/^[a-z0-9]+\:\/\//i))return e;let t=new URL(`http://_${e}`);return[t.pathname,t.hash].join("")},ie=e=>e.replace("://","\\://");function N({pathCreator:e,params:t,query:a}){let p=ue(e)(t),i=Object.keys(a).length?`?${new URLSearchParams(a)}`:"";return`${p}${i}`}function V({pathCreator:e,actualPath:t}){let a=ce(ie(e))(me(t));return a?{matches:!0,params:a.params}:{matches:!1}}import{attach as H,createEffect as _,guard as v,sample as k,createStore as $,createEvent as W,scopeBind as pe,restore as le}from"effector";var D=(e,t)=>{if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let a in e)if(`${e[a]}`!=`${t[a]}`)return!1;return!0};var Pe=_(e=>{if(!e.history)throw new Error("[Routing] No history provided");return e.history[e.method](e.path,{}),e}),de=(e,t="")=>{let a=[];for(let o of e)Array.isArray(o.route)?a.push(...o.route.map(c=>j(S({},o),{route:c}))):a.push(o);a=a.map(o=>j(S({},o),{path:`${t}${o.path}`}));let p=[],i=[];for(let o of a)o.route.settings.derived?p.push(o):i.push(o);if(p.length)for(let o of p)console.error(`createHistoryRouter: ${o.path} uses derived route. This won't work`);return i},_e=e=>{let t=de(e.routes,e.base),a=W(),p=W(),i=$({}),o=$(""),c=$([],{serialize:"ignore"}),P=$(!1),l=$(null,{serialize:"ignore"});l.on(a,(r,n)=>n);let f=H({source:{history:l},effect:Pe,mapParams:(r,{history:n})=>S({history:n},r)}),E=_(({route:r,params:n,query:d})=>({path:N({pathCreator:r.path,params:n,query:d}),params:n,query:d,method:"push"})),s=_(({path:r,query:n,hash:d})=>{let h=[],R=[];for(let g of t){let m=g.path.includes("#")?`${r}${d}`:`${r}`,{matches:y,params:Q}=V({pathCreator:`${g.path}`,actualPath:m});(y?h:R).push({route:g,params:Q,query:n})}for(let g in R){let m=g;h.some(y=>y.route.route===R[m].route.route)&&(R[m]=null)}return R=R.filter(Boolean),{opened:h,closed:R}});o.on(s.done,(r,{params:{path:n}})=>n),i.on(s.done,(r,{params:{query:n}})=>n),c.on(s.doneData,(r,{opened:n})=>n.map(d=>d.route.route)),k({clock:E.doneData,target:f}),v({clock:s.doneData,filter:({opened:r})=>r.length===0,target:p});let u=s.doneData.map(({opened:r})=>r),O=s.doneData.map(({closed:r})=>r);for(let r of t){let n=$(!1),d=r.route.navigate.done;k({clock:d,fn:({result:{params:m,query:y}})=>({route:r,params:m,query:y}),target:E});let h=m=>{let y=m.find(Q=>Q.route.route===r.route);if(!!y)return{params:y.params,query:y.query}},R={opened:v({clock:u.filterMap(h),filter:r.route.$isOpened.map(m=>!m)}),updated:v({clock:u.filterMap(h),filter:r.route.$isOpened}),closed:v({clock:O.filterMap(h),filter:r.route.$isOpened})};n.on(d,()=>!0);let g=v({clock:R.updated,filter:n.map(m=>!m)});k({source:le(g,null),clock:v({clock:g,source:[r.route.$params,r.route.$query],filter:([m,y],Q)=>!D(m,Q.params)||!D(y,Q.query)}),fn:m=>m,target:r.route.updated}),v({clock:R.opened,filter:n.map(m=>!m),target:r.route.opened}),k({clock:R.closed,target:r.route.closed}),n.reset(k({clock:u}))}let q=H({source:{history:l},effect:async({history:r})=>{let[n,d,h]=[r.location.pathname,Object.fromEntries(new URLSearchParams(r.location.search)),r.location.hash];return{path:n,query:d,hash:h}}});k({source:q.doneData,target:s});let z=H({source:{history:l},effect:async({history:r})=>{let n=q;try{n=pe(q)}catch{}return r.listen(()=>{n()}),!0}});e.hydrate||k({clock:z.doneData,target:q}),k({clock:l,target:z}),P.on(s.doneData,()=>!0).reset(l);let Z=k({clock:v({clock:P,filter:Boolean}),source:{activeRoutes:c,path:o,query:i}});return{$path:o,$query:i,$activeRoutes:c,$history:l,setHistory:a,push:f,routes:t,initialized:Z,routeNotFound:p}};var G=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===I.ROUTE;import{createEvent as Re,createStore as ye,is as fe,sample as J}from"effector";var Ve=e=>{let t=e.clock?J({clock:e.clock}):Re(),a=X(e.params||{}),p=X(e.query||{});return J({clock:t,source:{params:a,query:p},fn:({params:i,query:o},c)=>({params:typeof i=="function"?i(c):i,query:typeof o=="function"?o(c):o}),target:e.route.navigate}),t},X=e=>fe.store(e)?e:ye(e);import{is as he,guard as ke,merge as Oe,sample as C,combine as F,createStore as Y,createEvent as w}from"effector";var ge=e=>{if(G(e))return{route:e,chainedRoute:A(),beforeOpen:w(),openOn:[e.opened,e.closed],cancelOn:[w()]};let t=e;if(!("enterOn"in t)&&he.effect(t.beforeOpen))return{route:t.route,chainedRoute:t.chainedRoute||A(),beforeOpen:t.beforeOpen,openOn:t.beforeOpen.doneData,cancelOn:t.beforeOpen.failData};let a=e;return{route:a.route,chainedRoute:a.chainedRoute||A(),beforeOpen:a.beforeOpen,openOn:C({clock:a.openOn}),cancelOn:C({clock:a.cancelOn||w()})}},at=e=>{let{route:t,chainedRoute:a,beforeOpen:p,openOn:i,cancelOn:o}=ge(e),c=Y({}),P=Y({}),l=F(F([t.$params,t.$query]),F([c,P]),(u,O)=>u[0]===O[0]&&u[1]===O[1]),f=C({clock:[t.opened,t.updated]});C({clock:f,target:p}),c.on(f,(u,{params:O})=>O),P.on(f,(u,{query:O})=>O);let E=ke({clock:i,source:{params:c,query:P},filter:l});C({clock:E,target:a.navigate});let s=Oe([t.closed,o]);return c.reset(s),P.reset(s),C({clock:s,target:a.closed}),a};export{I as Kind,N as buildPath,at as chainRoute,_e as createHistoryRouter,A as createRoute,G as isRoute,V as matchPath,Ve as redirect}; |
@@ -57,4 +57,4 @@ import * as effector from 'effector'; | ||
$activeRoutes: effector.Store<RouteInstance<any>[]>; | ||
$history: effector.Store<History>; | ||
setHistory: effector.Event<History>; | ||
$history: effector.Store<History<unknown>>; | ||
setHistory: effector.Event<History<unknown>>; | ||
push: effector.Effect<Omit<HistoryPushParams, "history">, HistoryPushParams, Error>; | ||
@@ -91,5 +91,19 @@ routes: RouteObject<any>[]; | ||
declare type RedirectParams<T, Params> = { | ||
declare type RedirectParams<T, Params> = Params extends { | ||
[key in string]: never; | ||
} ? { | ||
clock?: Clock<T>; | ||
route: RouteInstance<Params>; | ||
query?: ((clock: T) => RouteQuery) | Store<RouteQuery> | RouteQuery; | ||
} : { | ||
clock?: Clock<T>; | ||
route: RouteInstance<Params>; | ||
params: ((clock: T) => Params) | Store<Params> | Params; | ||
query?: ((clock: T) => RouteQuery) | Store<RouteQuery> | RouteQuery; | ||
} | { | ||
clock?: Clock<{ | ||
params: Params; | ||
query?: RouteQuery; | ||
}>; | ||
route: RouteInstance<Params>; | ||
params?: ((clock: T) => Params) | Store<Params> | Params; | ||
@@ -96,0 +110,0 @@ query?: ((clock: T) => RouteQuery) | Store<RouteQuery> | RouteQuery; |
@@ -1,1 +0,1 @@ | ||
var I=Object.defineProperty,L=Object.defineProperties,N=Object.getOwnPropertyDescriptor,V=Object.getOwnPropertyDescriptors,W=Object.getOwnPropertyNames,w=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var z=(e,t,a)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,A=(e,t)=>{for(var a in t||(t={}))M.call(t,a)&&z(e,a,t[a]);if(w)for(var a of w(t))G.call(t,a)&&z(e,a,t[a]);return e},T=(e,t)=>L(e,V(t));var J=(e,t)=>{for(var a in t)I(e,a,{get:t[a],enumerable:!0})},X=(e,t,a,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of W(t))!M.call(e,m)&&m!==a&&I(e,m,{get:()=>t[m],enumerable:!(l=N(t,m))||l.enumerable});return e};var Y=e=>X(I({},"__esModule",{value:!0}),e);var ce={};J(ce,{Kind:()=>E,buildPath:()=>U,chainRoute:()=>ne,createHistoryRouter:()=>re,createRoute:()=>q,isRoute:()=>_,matchPath:()=>D,redirect:()=>oe});module.exports=Y(ce);var d=require("effector");var E={ROUTE:Symbol()};var q=(e={})=>{let t=(0,d.createEffect)(async({params:n,query:p})=>({params:n||{},query:p||{}})),a=(0,d.attach)({effect:t,mapParams:n=>({params:n||{},query:{}})}),l=(0,d.createStore)(!1),m=(0,d.createStore)({}),s=(0,d.createStore)({}),i=(0,d.createEvent)(),f=(0,d.createEvent)(),R=(0,d.createEvent)(),O=(0,d.createEvent)();if(l.on(i,()=>!0).on(R,()=>!1),m.on(i,(n,{params:p})=>p).on(f,(n,{params:p})=>p),s.on(i,(n,{query:p})=>p).on(f,(n,{query:p})=>p),(0,d.split)({source:t.doneData,match:l.map(n=>n?"updated":"opened"),cases:{opened:i,updated:f}}),(0,d.sample)({clock:O,target:R}),e.filter){let n=e.filter;(0,d.split)({source:(0,d.sample)({clock:n}),match:p=>p?"true":"false",cases:{true:i,false:O}})}return{$isOpened:l,$params:m,$query:s,opened:i,updated:f,closed:O,left:R,navigate:t,open:a,kind:E.ROUTE,settings:{derived:Boolean(e.filter)}}};var j=require("path-to-regexp"),Z=e=>{if(e.match(/^[a-z0-9]+\:\/\//i))return e;let t=new URL(`http://_${e}`);return[t.pathname,t.hash].join("")},ee=e=>e.replace("://","\\://");function U({pathCreator:e,params:t,query:a}){let l=(0,j.compile)(e)(t),m=Object.keys(a).length?`?${new URLSearchParams(a)}`:"";return`${l}${m}`}function D({pathCreator:e,actualPath:t}){let a=(0,j.match)(ee(e))(Z(t));return a?{matches:!0,params:a.params}:{matches:!1}}var r=require("effector");var H=(e,t)=>{if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let a in e)if(`${e[a]}`!=`${t[a]}`)return!1;return!0};var te=(0,r.createEffect)(e=>{if(!e.history)throw new Error("[Routing] No history provided");return e.history[e.method](e.path,{}),e}),ae=(e,t="")=>{let a=[];for(let s of e)Array.isArray(s.route)?a.push(...s.route.map(i=>T(A({},s),{route:i}))):a.push(s);a=a.map(s=>T(A({},s),{path:`${t}${s.path}`}));let l=[],m=[];for(let s of a)s.route.settings.derived?l.push(s):m.push(s);if(l.length)for(let s of l)console.error(`createHistoryRouter: ${s.path} uses derived route. This won't work`);return m},re=e=>{let t=ae(e.routes,e.base),a=(0,r.createEvent)(),l=(0,r.createEvent)(),m=(0,r.createStore)({}),s=(0,r.createStore)(""),i=(0,r.createStore)([],{serialize:"ignore"}),f=(0,r.createStore)(!1),R=(0,r.createStore)(null,{serialize:"ignore"});R.on(a,(o,c)=>c);let O=(0,r.attach)({source:{history:R},effect:te,mapParams:(o,{history:c})=>A({history:c},o)}),C=(0,r.createEffect)(({route:o,params:c,query:y})=>({path:U({pathCreator:o.path,params:c,query:y}),params:c,query:y,method:"push"})),n=(0,r.createEffect)(({path:o,query:c,hash:y})=>{let g=[],h=[];for(let v of t){let P=v.path.includes("#")?`${o}${y}`:`${o}`,{matches:k,params:Q}=D({pathCreator:`${v.path}`,actualPath:P});(k?g:h).push({route:v,params:Q,query:c})}for(let v in h){let P=v;g.some(k=>k.route.route===h[P].route.route)&&(h[P]=null)}return h=h.filter(Boolean),{opened:g,closed:h}});s.on(n.done,(o,{params:{path:c}})=>c),m.on(n.done,(o,{params:{query:c}})=>c),i.on(n.doneData,(o,{opened:c})=>c.map(y=>y.route.route)),(0,r.sample)({clock:C.doneData,target:O}),(0,r.guard)({clock:n.doneData,filter:({opened:o})=>o.length===0,target:l});let p=n.doneData.map(({opened:o})=>o),x=n.doneData.map(({closed:o})=>o);for(let o of t){let c=(0,r.createStore)(!1),y=o.route.navigate.done;(0,r.sample)({clock:y,fn:({result:{params:P,query:k}})=>({route:o,params:P,query:k}),target:C});let g=P=>{let k=P.find(Q=>Q.route.route===o.route);if(!!k)return{params:k.params,query:k.query}},h={opened:(0,r.guard)({clock:p.filterMap(g),filter:o.route.$isOpened.map(P=>!P)}),updated:(0,r.guard)({clock:p.filterMap(g),filter:o.route.$isOpened}),closed:(0,r.guard)({clock:x.filterMap(g),filter:o.route.$isOpened})};c.on(y,()=>!0);let v=(0,r.guard)({clock:h.updated,filter:c.map(P=>!P)});(0,r.sample)({source:(0,r.restore)(v,null),clock:(0,r.guard)({clock:v,source:[o.route.$params,o.route.$query],filter:([P,k],Q)=>!H(P,Q.params)||!H(k,Q.query)}),fn:P=>P,target:o.route.updated}),(0,r.guard)({clock:h.opened,filter:c.map(P=>!P),target:o.route.opened}),(0,r.sample)({clock:h.closed,target:o.route.closed}),c.reset((0,r.sample)({clock:p}))}let S=(0,r.attach)({source:{history:R},effect:async({history:o})=>{let[c,y,g]=[o.location.pathname,Object.fromEntries(new URLSearchParams(o.location.search)),o.location.hash];return{path:c,query:y,hash:g}}});(0,r.sample)({source:S.doneData,target:n});let F=(0,r.attach)({source:{history:R},effect:async({history:o})=>{let c=S;try{c=(0,r.scopeBind)(S)}catch{}return o.listen(()=>{c()}),!0}});e.hydrate||(0,r.sample)({clock:F.doneData,target:S}),(0,r.sample)({clock:R,target:F}),f.on(n.doneData,()=>!0).reset(R);let K=(0,r.sample)({clock:(0,r.guard)({clock:f,filter:Boolean}),source:{activeRoutes:i,path:s,query:m}});return{$path:s,$query:m,$activeRoutes:i,$history:R,setHistory:a,push:O,routes:t,initialized:K,routeNotFound:l}};var _=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===E.ROUTE;var b=require("effector"),oe=e=>{let t=e.clock?(0,b.sample)({clock:e.clock}):(0,b.createEvent)(),a=B(e.params||{}),l=B(e.query||{});return(0,b.sample)({clock:t,source:{params:a,query:l},fn:({params:m,query:s},i)=>({params:typeof m=="function"?m(i):m,query:typeof s=="function"?s(i):s}),target:e.route.navigate}),t},B=e=>b.is.store(e)?e:(0,b.createStore)(e);var u=require("effector");var se=e=>{if(_(e))return{route:e,chainedRoute:q(),beforeOpen:(0,u.createEvent)(),openOn:[e.opened,e.closed],cancelOn:[(0,u.createEvent)()]};let t=e;if(!("enterOn"in t)&&u.is.effect(t.beforeOpen))return{route:t.route,chainedRoute:t.chainedRoute||q(),beforeOpen:t.beforeOpen,openOn:t.beforeOpen.doneData,cancelOn:t.beforeOpen.failData};let a=e;return{route:a.route,chainedRoute:a.chainedRoute||q(),beforeOpen:a.beforeOpen,openOn:(0,u.sample)({clock:a.openOn}),cancelOn:(0,u.sample)({clock:a.cancelOn||(0,u.createEvent)()})}},ne=e=>{let{route:t,chainedRoute:a,beforeOpen:l,openOn:m,cancelOn:s}=se(e),i=(0,u.createStore)({}),f=(0,u.createStore)({}),R=(0,u.combine)((0,u.combine)([t.$params,t.$query]),(0,u.combine)([i,f]),(p,x)=>p[0]===x[0]&&p[1]===x[1]),O=(0,u.sample)({clock:[t.opened,t.updated]});(0,u.sample)({clock:O,target:l}),i.on(O,(p,{params:x})=>x),f.on(O,(p,{query:x})=>x);let C=(0,u.guard)({clock:m,source:{params:i,query:f},filter:R});(0,u.sample)({clock:C,target:a.navigate});let n=(0,u.merge)([t.closed,s]);return i.reset(n),f.reset(n),(0,u.sample)({clock:n,target:a.closed}),a};0&&(module.exports={Kind,buildPath,chainRoute,createHistoryRouter,createRoute,isRoute,matchPath,redirect}); | ||
var I=Object.defineProperty,L=Object.defineProperties,N=Object.getOwnPropertyDescriptor,V=Object.getOwnPropertyDescriptors,W=Object.getOwnPropertyNames,w=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var z=(e,t,a)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,T=(e,t)=>{for(var a in t||(t={}))M.call(t,a)&&z(e,a,t[a]);if(w)for(var a of w(t))G.call(t,a)&&z(e,a,t[a]);return e},j=(e,t)=>L(e,V(t));var J=(e,t)=>{for(var a in t)I(e,a,{get:t[a],enumerable:!0})},X=(e,t,a,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of W(t))!M.call(e,m)&&m!==a&&I(e,m,{get:()=>t[m],enumerable:!(l=N(t,m))||l.enumerable});return e};var Y=e=>X(I({},"__esModule",{value:!0}),e);var ce={};J(ce,{Kind:()=>E,buildPath:()=>U,chainRoute:()=>ne,createHistoryRouter:()=>re,createRoute:()=>q,isRoute:()=>_,matchPath:()=>D,redirect:()=>oe});module.exports=Y(ce);var P=require("effector");var E={ROUTE:Symbol()};var q=(e={})=>{let t=(0,P.createEffect)(async({params:n,query:p})=>({params:n||{},query:p||{}})),a=(0,P.attach)({effect:t,mapParams:n=>({params:n||{},query:{}})}),l=(0,P.createStore)(!1),m=(0,P.createStore)({}),s=(0,P.createStore)({}),i=(0,P.createEvent)(),y=(0,P.createEvent)(),R=(0,P.createEvent)(),O=(0,P.createEvent)();if(l.on(i,()=>!0).on(R,()=>!1),m.on(i,(n,{params:p})=>p).on(y,(n,{params:p})=>p),s.on(i,(n,{query:p})=>p).on(y,(n,{query:p})=>p),(0,P.split)({source:t.doneData,match:l.map(n=>n?"updated":"opened"),cases:{opened:i,updated:y}}),(0,P.sample)({clock:O,target:R}),e.filter){let n=e.filter;(0,P.split)({source:(0,P.sample)({clock:n}),match:p=>p?"true":"false",cases:{true:i,false:O}})}return{$isOpened:l,$params:m,$query:s,opened:i,updated:y,closed:O,left:R,navigate:t,open:a,kind:E.ROUTE,settings:{derived:Boolean(e.filter)}}};var A=require("path-to-regexp"),Z=e=>{if(e.match(/^[a-z0-9]+\:\/\//i))return e;let t=new URL(`http://_${e}`);return[t.pathname,t.hash].join("")},ee=e=>e.replace("://","\\://");function U({pathCreator:e,params:t,query:a}){let l=(0,A.compile)(e)(t),m=Object.keys(a).length?`?${new URLSearchParams(a)}`:"";return`${l}${m}`}function D({pathCreator:e,actualPath:t}){let a=(0,A.match)(ee(e))(Z(t));return a?{matches:!0,params:a.params}:{matches:!1}}var r=require("effector");var H=(e,t)=>{if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let a in e)if(`${e[a]}`!=`${t[a]}`)return!1;return!0};var te=(0,r.createEffect)(e=>{if(!e.history)throw new Error("[Routing] No history provided");return e.history[e.method](e.path,{}),e}),ae=(e,t="")=>{let a=[];for(let s of e)Array.isArray(s.route)?a.push(...s.route.map(i=>j(T({},s),{route:i}))):a.push(s);a=a.map(s=>j(T({},s),{path:`${t}${s.path}`}));let l=[],m=[];for(let s of a)s.route.settings.derived?l.push(s):m.push(s);if(l.length)for(let s of l)console.error(`createHistoryRouter: ${s.path} uses derived route. This won't work`);return m},re=e=>{let t=ae(e.routes,e.base),a=(0,r.createEvent)(),l=(0,r.createEvent)(),m=(0,r.createStore)({}),s=(0,r.createStore)(""),i=(0,r.createStore)([],{serialize:"ignore"}),y=(0,r.createStore)(!1),R=(0,r.createStore)(null,{serialize:"ignore"});R.on(a,(o,c)=>c);let O=(0,r.attach)({source:{history:R},effect:te,mapParams:(o,{history:c})=>T({history:c},o)}),C=(0,r.createEffect)(({route:o,params:c,query:f})=>({path:U({pathCreator:o.path,params:c,query:f}),params:c,query:f,method:"push"})),n=(0,r.createEffect)(({path:o,query:c,hash:f})=>{let g=[],h=[];for(let v of t){let d=v.path.includes("#")?`${o}${f}`:`${o}`,{matches:k,params:$}=D({pathCreator:`${v.path}`,actualPath:d});(k?g:h).push({route:v,params:$,query:c})}for(let v in h){let d=v;g.some(k=>k.route.route===h[d].route.route)&&(h[d]=null)}return h=h.filter(Boolean),{opened:g,closed:h}});s.on(n.done,(o,{params:{path:c}})=>c),m.on(n.done,(o,{params:{query:c}})=>c),i.on(n.doneData,(o,{opened:c})=>c.map(f=>f.route.route)),(0,r.sample)({clock:C.doneData,target:O}),(0,r.guard)({clock:n.doneData,filter:({opened:o})=>o.length===0,target:l});let p=n.doneData.map(({opened:o})=>o),b=n.doneData.map(({closed:o})=>o);for(let o of t){let c=(0,r.createStore)(!1),f=o.route.navigate.done;(0,r.sample)({clock:f,fn:({result:{params:d,query:k}})=>({route:o,params:d,query:k}),target:C});let g=d=>{let k=d.find($=>$.route.route===o.route);if(!!k)return{params:k.params,query:k.query}},h={opened:(0,r.guard)({clock:p.filterMap(g),filter:o.route.$isOpened.map(d=>!d)}),updated:(0,r.guard)({clock:p.filterMap(g),filter:o.route.$isOpened}),closed:(0,r.guard)({clock:b.filterMap(g),filter:o.route.$isOpened})};c.on(f,()=>!0);let v=(0,r.guard)({clock:h.updated,filter:c.map(d=>!d)});(0,r.sample)({source:(0,r.restore)(v,null),clock:(0,r.guard)({clock:v,source:[o.route.$params,o.route.$query],filter:([d,k],$)=>!H(d,$.params)||!H(k,$.query)}),fn:d=>d,target:o.route.updated}),(0,r.guard)({clock:h.opened,filter:c.map(d=>!d),target:o.route.opened}),(0,r.sample)({clock:h.closed,target:o.route.closed}),c.reset((0,r.sample)({clock:p}))}let S=(0,r.attach)({source:{history:R},effect:async({history:o})=>{let[c,f,g]=[o.location.pathname,Object.fromEntries(new URLSearchParams(o.location.search)),o.location.hash];return{path:c,query:f,hash:g}}});(0,r.sample)({source:S.doneData,target:n});let F=(0,r.attach)({source:{history:R},effect:async({history:o})=>{let c=S;try{c=(0,r.scopeBind)(S)}catch{}return o.listen(()=>{c()}),!0}});e.hydrate||(0,r.sample)({clock:F.doneData,target:S}),(0,r.sample)({clock:R,target:F}),y.on(n.doneData,()=>!0).reset(R);let K=(0,r.sample)({clock:(0,r.guard)({clock:y,filter:Boolean}),source:{activeRoutes:i,path:s,query:m}});return{$path:s,$query:m,$activeRoutes:i,$history:R,setHistory:a,push:O,routes:t,initialized:K,routeNotFound:l}};var _=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===E.ROUTE;var x=require("effector"),oe=e=>{let t=e.clock?(0,x.sample)({clock:e.clock}):(0,x.createEvent)(),a=B(e.params||{}),l=B(e.query||{});return(0,x.sample)({clock:t,source:{params:a,query:l},fn:({params:m,query:s},i)=>({params:typeof m=="function"?m(i):m,query:typeof s=="function"?s(i):s}),target:e.route.navigate}),t},B=e=>x.is.store(e)?e:(0,x.createStore)(e);var u=require("effector");var se=e=>{if(_(e))return{route:e,chainedRoute:q(),beforeOpen:(0,u.createEvent)(),openOn:[e.opened,e.closed],cancelOn:[(0,u.createEvent)()]};let t=e;if(!("enterOn"in t)&&u.is.effect(t.beforeOpen))return{route:t.route,chainedRoute:t.chainedRoute||q(),beforeOpen:t.beforeOpen,openOn:t.beforeOpen.doneData,cancelOn:t.beforeOpen.failData};let a=e;return{route:a.route,chainedRoute:a.chainedRoute||q(),beforeOpen:a.beforeOpen,openOn:(0,u.sample)({clock:a.openOn}),cancelOn:(0,u.sample)({clock:a.cancelOn||(0,u.createEvent)()})}},ne=e=>{let{route:t,chainedRoute:a,beforeOpen:l,openOn:m,cancelOn:s}=se(e),i=(0,u.createStore)({}),y=(0,u.createStore)({}),R=(0,u.combine)((0,u.combine)([t.$params,t.$query]),(0,u.combine)([i,y]),(p,b)=>p[0]===b[0]&&p[1]===b[1]),O=(0,u.sample)({clock:[t.opened,t.updated]});(0,u.sample)({clock:O,target:l}),i.on(O,(p,{params:b})=>b),y.on(O,(p,{query:b})=>b);let C=(0,u.guard)({clock:m,source:{params:i,query:y},filter:R});(0,u.sample)({clock:C,target:a.navigate});let n=(0,u.merge)([t.closed,s]);return i.reset(n),y.reset(n),(0,u.sample)({clock:n,target:a.closed}),a};0&&(module.exports={Kind,buildPath,chainRoute,createHistoryRouter,createRoute,isRoute,matchPath,redirect}); |
{ | ||
"version": "0.5.0-dev.20", | ||
"version": "0.5.0-dev.21", | ||
"license": "MIT", | ||
@@ -23,9 +23,11 @@ "main": "dist/index.js", | ||
"effector": "^22", | ||
"history": "^5" | ||
"history": "^4.10.1" | ||
}, | ||
"devDependencies": { | ||
"@types/history": "^4.7.11", | ||
"@types/jest": "^27.5.0", | ||
"effector": "^22", | ||
"history": "^5", | ||
"history": "^4.10.1", | ||
"jest": "^28.1.0", | ||
"jest-environment-jsdom": "^28.1.0", | ||
"ts-jest": "^28.0.1", | ||
@@ -39,7 +41,2 @@ "tslib": "^2.4.0", | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
} | ||
}, | ||
"prettier": { | ||
@@ -46,0 +43,0 @@ "printWidth": 80, |
@@ -12,8 +12,24 @@ import { | ||
type RedirectParams<T, Params> = { | ||
clock?: Clock<T>; | ||
route: RouteInstance<Params>; | ||
params?: ((clock: T) => Params) | Store<Params> | Params; | ||
query?: ((clock: T) => RouteQuery) | Store<RouteQuery> | RouteQuery; | ||
}; | ||
type RedirectParams<T, Params> = Params extends { [key in string]: never } | ||
? { | ||
clock?: Clock<T>; | ||
route: RouteInstance<Params>; | ||
query?: ((clock: T) => RouteQuery) | Store<RouteQuery> | RouteQuery; | ||
} | ||
: | ||
| { | ||
clock?: Clock<T>; | ||
route: RouteInstance<Params>; | ||
params: ((clock: T) => Params) | Store<Params> | Params; | ||
query?: ((clock: T) => RouteQuery) | Store<RouteQuery> | RouteQuery; | ||
} | ||
| { | ||
clock?: Clock<{ | ||
params: Params; | ||
query?: RouteQuery; | ||
}>; | ||
route: RouteInstance<Params>; | ||
params?: ((clock: T) => Params) | Store<Params> | Params; | ||
query?: ((clock: T) => RouteQuery) | Store<RouteQuery> | RouteQuery; | ||
}; | ||
@@ -25,2 +41,3 @@ /** Opens passed `route` upon `clock` trigger */ | ||
: createEvent<T>(); | ||
// @ts-expect-error | ||
let params = toStore(options.params || {}); | ||
@@ -27,0 +44,0 @@ let query = toStore(options.query || {}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46987
917
10