Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

atomic-router

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atomic-router - npm Package Compare versions

Comparing version 0.5.0-dev.22 to 0.5.0

2

dist/esm/index.js

@@ -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},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};
var ae=Object.defineProperty,re=Object.defineProperties;var oe=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var B=(e,t,a)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,C=(e,t)=>{for(var a in t||(t={}))ne.call(t,a)&&B(e,a,t[a]);if(M)for(var a of M(t))se.call(t,a)&&B(e,a,t[a]);return e},F=(e,t)=>re(e,oe(t));import{attach as ce,createEffect as ue,createEvent as A,createStore as j,sample as N,split as K}from"effector";var S={ROUTE:Symbol()};var T=(e={})=>{let t=ue(async({params:n,query:u})=>({params:n||{},query:u||{}})),a=ce({effect:t,mapParams:n=>({params:n||{},query:{}})}),p=j(!1),i=j({}),o=j({}),c=A(),l=A(),P=A(),y=A();if(p.on(c,()=>!0).on(P,()=>!1),i.on(c,(n,{params:u})=>u).on(l,(n,{params:u})=>u),o.on(c,(n,{query:u})=>u).on(l,(n,{query:u})=>u),K({source:t.doneData,match:p.map(n=>n?"updated":"opened"),cases:{opened:c,updated:l}}),N({clock:y,target:P}),e.filter){let n=e.filter;K({source:N({clock:n}),match:u=>u?"true":"false",cases:{true:c,false:y}})}return{$isOpened:p,$params:i,$query:o,opened:c,updated:l,closed:y,left:P,navigate:t,open:a,kind:S.ROUTE,settings:{derived:Boolean(e.filter)}}};import{match as me,compile as ie}from"path-to-regexp";var pe=e=>{if(e.match(/^[a-z0-9]+\:\/\//i))return e;let t=new URL(`http://_${e}`);return[t.pathname,t.hash].join("")},Pe=e=>e.replace("://","\\://");function L({pathCreator:e,params:t,query:a}){let p=ie(e)(t),i=Object.keys(a).length?`?${new URLSearchParams(a)}`:"";return`${p}${i}`}function W({pathCreator:e,actualPath:t}){let a=me(Pe(e))(pe(t));return a?{matches:!0,params:a.params}:{matches:!1}}import{attach as D,createEffect as H,guard as v,sample as k,createStore as E,createEvent as V,scopeBind as le,restore as Re}from"effector";var U=(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=H(e=>{if(!e.history)throw new Error("[Routing] No history provided");return e.history[e.method](e.path,{}),e}),fe=(e,t="")=>{let a=[];for(let o of e)Array.isArray(o.route)?a.push(...o.route.map(c=>F(C({},o),{route:c}))):a.push(o);a=a.map(o=>F(C({},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},Xe=e=>{let t=fe(e.routes,e.base),a=V(),p=V(),i=E({}),o=E(""),c=E([],{serialize:"ignore"}),l=E(!1),P=E(null,{serialize:"ignore"});P.on(a,(r,s)=>s);let y=D({source:{history:P},effect:de,mapParams:(r,{history:s})=>C({history:s},r)}),I=H(({route:r,params:s,query:R})=>({path:L({pathCreator:r.path,params:s,query:R}),params:s,query:R,method:"push"})),n=H(({path:r,query:s,hash:R})=>{let h=[],d=[];for(let g of t){let m=g.path.includes("#")?`${r}${R}`:`${r}`,{matches:f,params:Q}=W({pathCreator:`${g.path}`,actualPath:m});(f?h:d).push({route:g,params:Q,query:s})}for(let g in d){let m=g;h.some(f=>f.route.route===d[m].route.route)&&(d[m]=null)}return d=d.filter(Boolean),{opened:h,closed:d}});o.on(n.done,(r,{params:{path:s}})=>s),i.on(n.done,(r,{params:{query:s}})=>s),c.on(n.doneData,(r,{opened:s})=>s.map(R=>R.route.route)),k({clock:I.doneData,target:y}),v({clock:n.doneData,filter:({opened:r})=>r.length===0,target:p});let u=n.doneData.map(({opened:r})=>r),O=n.doneData.map(({closed:r})=>r);for(let r of t){let s=E(!1),R=r.route.navigate.done;k({clock:R,fn:({result:{params:m,query:f}})=>({route:r,params:m,query:f}),target:I});let h=m=>{let f=m.find(Q=>Q.route.route===r.route);if(!!f)return{params:f.params,query:f.query}},d={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})};s.on(R,()=>!0);let g=v({clock:d.updated,filter:s.map(m=>!m)});k({source:Re(g,null),clock:v({clock:g,source:[r.route.$params,r.route.$query],filter:([m,f],Q)=>!U(m,Q.params)||!U(f,Q.query)}),fn:m=>m,target:r.route.updated}),v({clock:d.opened,filter:s.map(m=>!m),target:r.route.opened}),k({clock:d.closed,target:r.route.closed}),s.reset(k({clock:u}))}let q=D({source:{history:P},effect:async({history:r})=>{let[s,R,h]=[r.location.pathname,Object.fromEntries(new URLSearchParams(r.location.search)),r.location.hash];return{path:s,query:R,hash:h}}});k({source:q.doneData,target:n});let z=D({source:{history:P},effect:async({history:r})=>{let s=q;try{s=le(q)}catch{}return r.listen(()=>{s()}),!0}});e.hydrate||k({clock:z.doneData,target:q}),k({clock:P,target:z}),l.on(n.doneData,()=>!0).reset(P);let te=k({clock:v({clock:l,filter:Boolean}),source:{activeRoutes:c,path:o,query:i}});return{$path:o,$query:i,$activeRoutes:c,$history:P,setHistory:a,push:y,routes:t,initialized:te,routeNotFound:p}};var G=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===S.ROUTE;import{createEvent as ye,createStore as he,is as ke,sample as J}from"effector";var We=e=>{let t=e.clock?J({clock:e.clock}):ye(),a=Y(e.params||{}),p=Y(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},Y=e=>ke.store(e)?e:he(e);import{is as Z,guard as Oe,merge as w,sample as $,combine as X,createStore as ee,createEvent as _,attach as ge}from"effector";var xe=e=>{if(G(e))return{route:e,chainedRoute:T(),beforeOpen:_(),openOn:w([e.opened,e.closed]),cancelOn:w([_()])};let t=C({},e);if(Z.unit(t.beforeOpen)||(t.beforeOpen=ge(t.beforeOpen)),Z.effect(t.beforeOpen))return{route:t.route,chainedRoute:t.chainedRoute||T(),beforeOpen:t.beforeOpen,openOn:"openOn"in t?t.openOn:t.beforeOpen.doneData,cancelOn:"cancelOn"in t?t.cancelOn:t.beforeOpen.failData};let a=e;return{route:a.route,chainedRoute:a.chainedRoute||T(),beforeOpen:a.beforeOpen,openOn:$({clock:a.openOn}),cancelOn:$({clock:a.cancelOn||_()})}};function nt(e){let{route:t,chainedRoute:a,beforeOpen:p,openOn:i,cancelOn:o}=xe(e),c=ee({}),l=ee({}),P=X(X([t.$params,t.$query]),X([c,l]),(u,O)=>u[0]===O[0]&&u[1]===O[1]),y=$({clock:[t.opened,t.updated]});$({clock:y,target:p}),c.on(y,(u,{params:O})=>O),l.on(y,(u,{query:O})=>O);let I=Oe({clock:i,source:{params:c,query:l},filter:P});$({clock:I,target:a.navigate});let n=w([t.closed,o]);return c.reset(n),l.reset(n),$({clock:n,target:a.closed}),a}export{S as Kind,L as buildPath,nt as chainRoute,Xe as createHistoryRouter,T as createRoute,G as isRoute,W as matchPath,We as redirect};
import * as effector from 'effector';
import { Store, Event, Effect, Clock } from 'effector';
import { Store, Event, Effect, Clock, NoInfer, EffectParams } from 'effector';
import { History } from 'history';

@@ -113,2 +113,15 @@

declare type ChainRouteParamsInternalAttach<Params, FX extends Effect<any, any, any>> = {
route: RouteInstance<Params>;
chainedRoute?: RouteInstance<Params>;
beforeOpen: {
effect: FX;
mapParams: ({ params, query, }: {
params: Params;
query: RouteQuery;
}) => NoInfer<EffectParams<FX>>;
};
openOn?: Clock<any>;
cancelOn?: Clock<any>;
};
declare type ChainRouteParamsWithEffect<Params> = {

@@ -126,15 +139,7 @@ route: RouteInstance<Params>;

};
declare type chainRouteParams<Params> = RouteInstance<Params> | ChainRouteParamsWithEffect<Params> | ChainRouteParamsAdvanced<Params>;
/**
* Creates chained route
* @link https://github.com/Kelin2025/atomic-router/issues/10
* @param {RouteInstance<any>} params.route - Route to listen
* @param {RouteInstance<any>} [params.chainedRoute] - Route to be created
* @param {Clock<any>} params.beforeOpen - Will be triggered when `params.route` open
* @param {Clock<any>} params.enterOn - Will open `chainedRoute` if `params.route` is still opened
* @param {Clock<any>} params.cancelOn - Cancels chain
* @returns {RouteInstance<any>} `chainedRoute`
*/
declare const chainRoute: <Params>(params: chainRouteParams<Params>) => RouteInstance<Params>;
declare function chainRoute<Params>(instance: RouteInstance<Params>): RouteInstance<Params>;
declare function chainRoute<Params>(config: ChainRouteParamsWithEffect<Params>): RouteInstance<Params>;
declare function chainRoute<Params>(config: ChainRouteParamsAdvanced<Params>): RouteInstance<Params>;
declare function chainRoute<Params, FX extends Effect<any, any, any>>(config: ChainRouteParamsInternalAttach<Params, FX>): RouteInstance<Params>;
export { Kind, PathCreator, RouteInstance, RouteParams, RouteParamsAndQuery, RouteQuery, buildPath, chainRoute, createHistoryRouter, createRoute, isRoute, matchPath, redirect };

@@ -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,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});
var A=Object.defineProperty,N=Object.defineProperties,K=Object.getOwnPropertyDescriptor,L=Object.getOwnPropertyDescriptors,W=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var w=(e,t,a)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,E=(e,t)=>{for(var a in t||(t={}))z.call(t,a)&&w(e,a,t[a]);if(_)for(var a of _(t))V.call(t,a)&&w(e,a,t[a]);return e},F=(e,t)=>N(e,L(t));var G=(e,t)=>{for(var a in t)A(e,a,{get:t[a],enumerable:!0})},J=(e,t,a,P)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of W(t))!z.call(e,m)&&m!==a&&A(e,m,{get:()=>t[m],enumerable:!(P=K(t,m))||P.enumerable});return e};var Y=e=>J(A({},"__esModule",{value:!0}),e);var ce={};G(ce,{Kind:()=>I,buildPath:()=>j,chainRoute:()=>se,createHistoryRouter:()=>re,createRoute:()=>q,isRoute:()=>H,matchPath:()=>U,redirect:()=>oe});module.exports=Y(ce);var l=require("effector");var I={ROUTE:Symbol()};var q=(e={})=>{let t=(0,l.createEffect)(async({params:c,query:p})=>({params:c||{},query:p||{}})),a=(0,l.attach)({effect:t,mapParams:c=>({params:c||{},query:{}})}),P=(0,l.createStore)(!1),m=(0,l.createStore)({}),s=(0,l.createStore)({}),i=(0,l.createEvent)(),f=(0,l.createEvent)(),d=(0,l.createEvent)(),O=(0,l.createEvent)();if(P.on(i,()=>!0).on(d,()=>!1),m.on(i,(c,{params:p})=>p).on(f,(c,{params:p})=>p),s.on(i,(c,{query:p})=>p).on(f,(c,{query:p})=>p),(0,l.split)({source:t.doneData,match:P.map(c=>c?"updated":"opened"),cases:{opened:i,updated:f}}),(0,l.sample)({clock:O,target:d}),e.filter){let c=e.filter;(0,l.split)({source:(0,l.sample)({clock:c}),match:p=>p?"true":"false",cases:{true:i,false:O}})}return{$isOpened:P,$params:m,$query:s,opened:i,updated:f,closed:O,left:d,navigate:t,open:a,kind:I.ROUTE,settings:{derived:Boolean(e.filter)}}};var T=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 j({pathCreator:e,params:t,query:a}){let P=(0,T.compile)(e)(t),m=Object.keys(a).length?`?${new URLSearchParams(a)}`:"";return`${P}${m}`}function U({pathCreator:e,actualPath:t}){let a=(0,T.match)(ee(e))(Z(t));return a?{matches:!0,params:a.params}:{matches:!1}}var r=require("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 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=>F(E({},s),{route:i}))):a.push(s);a=a.map(s=>F(E({},s),{path:`${t}${s.path}`}));let P=[],m=[];for(let s of a)s.route.settings.derived?P.push(s):m.push(s);if(P.length)for(let s of P)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)(),P=(0,r.createEvent)(),m=(0,r.createStore)({}),s=(0,r.createStore)(""),i=(0,r.createStore)([],{serialize:"ignore"}),f=(0,r.createStore)(!1),d=(0,r.createStore)(null,{serialize:"ignore"});d.on(a,(o,u)=>u);let O=(0,r.attach)({source:{history:d},effect:te,mapParams:(o,{history:u})=>E({history:u},o)}),$=(0,r.createEffect)(({route:o,params:u,query:y})=>({path:j({pathCreator:o.path,params:u,query:y}),params:u,query:y,method:"push"})),c=(0,r.createEffect)(({path:o,query:u,hash:y})=>{let g=[],h=[];for(let v of t){let R=v.path.includes("#")?`${o}${y}`:`${o}`,{matches:k,params:C}=U({pathCreator:`${v.path}`,actualPath:R});(k?g:h).push({route:v,params:C,query:u})}for(let v in h){let R=v;g.some(k=>k.route.route===h[R].route.route)&&(h[R]=null)}return h=h.filter(Boolean),{opened:g,closed:h}});s.on(c.done,(o,{params:{path:u}})=>u),m.on(c.done,(o,{params:{query:u}})=>u),i.on(c.doneData,(o,{opened:u})=>u.map(y=>y.route.route)),(0,r.sample)({clock:$.doneData,target:O}),(0,r.guard)({clock:c.doneData,filter:({opened:o})=>o.length===0,target:P});let p=c.doneData.map(({opened:o})=>o),b=c.doneData.map(({closed:o})=>o);for(let o of t){let u=(0,r.createStore)(!1),y=o.route.navigate.done;(0,r.sample)({clock:y,fn:({result:{params:R,query:k}})=>({route:o,params:R,query:k}),target:$});let g=R=>{let k=R.find(C=>C.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(R=>!R)}),updated:(0,r.guard)({clock:p.filterMap(g),filter:o.route.$isOpened}),closed:(0,r.guard)({clock:b.filterMap(g),filter:o.route.$isOpened})};u.on(y,()=>!0);let v=(0,r.guard)({clock:h.updated,filter:u.map(R=>!R)});(0,r.sample)({source:(0,r.restore)(v,null),clock:(0,r.guard)({clock:v,source:[o.route.$params,o.route.$query],filter:([R,k],C)=>!D(R,C.params)||!D(k,C.query)}),fn:R=>R,target:o.route.updated}),(0,r.guard)({clock:h.opened,filter:u.map(R=>!R),target:o.route.opened}),(0,r.sample)({clock:h.closed,target:o.route.closed}),u.reset((0,r.sample)({clock:p}))}let S=(0,r.attach)({source:{history:d},effect:async({history:o})=>{let[u,y,g]=[o.location.pathname,Object.fromEntries(new URLSearchParams(o.location.search)),o.location.hash];return{path:u,query:y,hash:g}}});(0,r.sample)({source:S.doneData,target:c});let X=(0,r.attach)({source:{history:d},effect:async({history:o})=>{let u=S;try{u=(0,r.scopeBind)(S)}catch{}return o.listen(()=>{u()}),!0}});e.hydrate||(0,r.sample)({clock:X.doneData,target:S}),(0,r.sample)({clock:d,target:X}),f.on(c.doneData,()=>!0).reset(d);let B=(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:d,setHistory:a,push:O,routes:t,initialized:B,routeNotFound:P}};var H=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===I.ROUTE;var x=require("effector"),oe=e=>{let t=e.clock?(0,x.sample)({clock:e.clock}):(0,x.createEvent)(),a=M(e.params||{}),P=M(e.query||{});return(0,x.sample)({clock:t,source:{params:a,query:P},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},M=e=>x.is.store(e)?e:(0,x.createStore)(e);var n=require("effector");var ne=e=>{if(H(e))return{route:e,chainedRoute:q(),beforeOpen:(0,n.createEvent)(),openOn:(0,n.merge)([e.opened,e.closed]),cancelOn:(0,n.merge)([(0,n.createEvent)()])};let t=E({},e);if(n.is.unit(t.beforeOpen)||(t.beforeOpen=(0,n.attach)(t.beforeOpen)),n.is.effect(t.beforeOpen))return{route:t.route,chainedRoute:t.chainedRoute||q(),beforeOpen:t.beforeOpen,openOn:"openOn"in t?t.openOn:t.beforeOpen.doneData,cancelOn:"cancelOn"in t?t.cancelOn:t.beforeOpen.failData};let a=e;return{route:a.route,chainedRoute:a.chainedRoute||q(),beforeOpen:a.beforeOpen,openOn:(0,n.sample)({clock:a.openOn}),cancelOn:(0,n.sample)({clock:a.cancelOn||(0,n.createEvent)()})}};function se(e){let{route:t,chainedRoute:a,beforeOpen:P,openOn:m,cancelOn:s}=ne(e),i=(0,n.createStore)({}),f=(0,n.createStore)({}),d=(0,n.combine)((0,n.combine)([t.$params,t.$query]),(0,n.combine)([i,f]),(p,b)=>p[0]===b[0]&&p[1]===b[1]),O=(0,n.sample)({clock:[t.opened,t.updated]});(0,n.sample)({clock:O,target:P}),i.on(O,(p,{params:b})=>b),f.on(O,(p,{query:b})=>b);let $=(0,n.guard)({clock:m,source:{params:i,query:f},filter:d});(0,n.sample)({clock:$,target:a.navigate});let c=(0,n.merge)([t.closed,s]);return i.reset(c),f.reset(c),(0,n.sample)({clock:c,target:a.closed}),a}0&&(module.exports={Kind,buildPath,chainRoute,createHistoryRouter,createRoute,isRoute,matchPath,redirect});
{
"version": "0.5.0-dev.22",
"version": "0.5.0",
"license": "MIT",

@@ -52,2 +52,2 @@ "main": "dist/index.js",

}
}
}

@@ -15,2 +15,4 @@ # Atomic Router

- [**React**](https://github.com/kelin2025/atomic-router-react)
- [**Forest**](https://github.com/sergeysova/atomic-router-forest)
- [**Solid**](https://www.npmjs.com/package/atomic-router-solid)

@@ -17,0 +19,0 @@ ## Installation

@@ -13,9 +13,32 @@ import {

createEvent,
NoInfer,
EffectParams,
attach,
} from 'effector';
import { createRoute } from '../create-route';
import { RouteInstance, RouteParamsAndQuery } from '../types';
import { RouteInstance, RouteParamsAndQuery, RouteQuery } from '../types';
import { isRoute } from './is-route';
type ChainRouteParamsInternalAttach<
Params,
FX extends Effect<any, any, any>
> = {
route: RouteInstance<Params>;
chainedRoute?: RouteInstance<Params>;
beforeOpen: {
effect: FX;
mapParams: ({
params,
query,
}: {
params: Params;
query: RouteQuery;
}) => NoInfer<EffectParams<FX>>;
};
openOn?: Clock<any>;
cancelOn?: Clock<any>;
};
type ChainRouteParamsWithEffect<Params> = {

@@ -43,9 +66,10 @@ route: RouteInstance<Params>;

type chainRouteParams<Params> =
type chainRouteParams<Params, FX extends Effect<any, any, any>> =
| RouteInstance<Params>
| ChainRouteParamsWithEffect<Params>
| ChainRouteParamsAdvanced<Params>;
| ChainRouteParamsAdvanced<Params>
| ChainRouteParamsInternalAttach<Params, FX>;
const normalizeChainRouteParams = <Params>(
params: chainRouteParams<Params>
const normalizeChainRouteParams = <Params, FX extends Effect<any, any, any>>(
params: chainRouteParams<Params, FX>
): ChainRouteParamsNormalized<Params> => {

@@ -57,8 +81,11 @@ if (isRoute(params)) {

beforeOpen: createEvent(),
openOn: [params.opened, params.closed],
cancelOn: [createEvent()],
openOn: merge([params.opened, params.closed]),
cancelOn: merge([createEvent()]),
};
}
const effectParams = params as ChainRouteParamsWithEffect<Params>;
if (!('enterOn' in effectParams) && is.effect(effectParams.beforeOpen)) {
const effectParams = { ...params } as ChainRouteParamsWithEffect<Params>;
if (!is.unit(effectParams.beforeOpen)) {
effectParams.beforeOpen = attach(effectParams.beforeOpen);
}
if (is.effect(effectParams.beforeOpen)) {
return {

@@ -68,4 +95,12 @@ route: effectParams.route,

beforeOpen: effectParams.beforeOpen,
openOn: effectParams.beforeOpen.doneData,
cancelOn: effectParams.beforeOpen.failData,
openOn:
'openOn' in effectParams
? // @ts-expect-error
effectParams.openOn
: effectParams.beforeOpen.doneData,
cancelOn:
'cancelOn' in effectParams
? // @ts-expect-error
effectParams.cancelOn
: effectParams.beforeOpen.failData,
};

@@ -85,2 +120,18 @@ }

function chainRoute<Params>(
instance: RouteInstance<Params>
): RouteInstance<Params>;
function chainRoute<Params>(
config: ChainRouteParamsWithEffect<Params>
): RouteInstance<Params>;
function chainRoute<Params>(
config: ChainRouteParamsAdvanced<Params>
): RouteInstance<Params>;
function chainRoute<Params, FX extends Effect<any, any, any>>(
config: ChainRouteParamsInternalAttach<Params, FX>
): RouteInstance<Params>;
/**

@@ -96,3 +147,5 @@ * Creates chained route

*/
export const chainRoute = <Params>(params: chainRouteParams<Params>) => {
function chainRoute<Params, FX extends Effect<any, any, any>>(
params: chainRouteParams<Params, FX>
) {
const { route, chainedRoute, beforeOpen, openOn, cancelOn } =

@@ -139,2 +192,4 @@ normalizeChainRouteParams(params);

return chainedRoute;
};
}
export { chainRoute };
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc