atomic-router
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -1,1 +0,1 @@ | ||
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{attach as Y,createEffect as Z,createEvent as S,createStore as T,sample as w,split as z}from"effector";var q={ROUTE:Symbol()};var A=(e={})=>{let t=Z(async({params:n,query:u})=>({params:n||{},query:u||{}})),r=Y({effect:t,mapParams:n=>({params:n||{},query:{}})}),p=T(!1),i=T({}),o=T({}),c=S(),l=S(),P=S(),y=S();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),z({source:t.doneData,match:p.map(n=>n?"updated":"opened"),cases:{opened:c,updated:l}}),w({clock:y,target:P}),e.filter){let n=e.filter;z({source:w({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:r,kind:q.ROUTE,settings:{derived:Boolean(e.filter)}}};import{match as ee,compile as te}from"path-to-regexp";var ae=e=>{if(e.match(/^[a-z0-9]+\:\/\//i))return e;let t=new URL(`http://_${e}`);return[t.pathname,t.hash].join("")},re=e=>e.replace("://","\\://");function M({pathCreator:e,params:t,query:r}){let p=te(e)(t),i=Object.keys(r).length?`?${new URLSearchParams(r)}`:"";return`${p}${i}`}function B({pathCreator:e,actualPath:t}){let r=ee(re(e))(ae(t));return r?{matches:!0,params:r.params}:{matches:!1}}import{attach as j,createEffect as U,guard as v,sample as k,createStore as C,createEvent as N,scopeBind as oe,restore as ne}from"effector";var F=(e,t)=>{if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let r in e)if(`${e[r]}`!=`${t[r]}`)return!1;return!0};var se=U(e=>{if(!e.history)throw new Error("[Routing] No history provided");return e.history[e.method](e.path,{}),e}),ce=(e,t="")=>{let r=[];for(let o of e)Array.isArray(o.route)?r.push(...o.route.map(c=>({...o,route:c}))):r.push(o);r=r.map(o=>({...o,path:`${t}${o.path}`}));let p=[],i=[];for(let o of r)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},Ie=e=>{let t=ce(e.routes,e.base),r=N(),p=N(),i=C({}),o=C(""),c=C([],{serialize:"ignore"}),l=C(!1),P=C(null,{serialize:"ignore"});P.on(r,(a,s)=>s);let y=j({source:{history:P},effect:se,mapParams:(a,{history:s})=>({history:s,...a})}),$=U(({route:a,params:s,query:R})=>({path:M({pathCreator:a.path,params:s,query:R}),params:s,query:R,method:"push"})),n=U(({path:a,query:s,hash:R})=>{let h=[],d=[];for(let g of t){let m=g.path.includes("#")?`${a}${R}`:`${a}`,{matches:f,params:Q}=B({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,(a,{params:{path:s}})=>s),i.on(n.done,(a,{params:{query:s}})=>s),c.on(n.doneData,(a,{opened:s})=>s.map(R=>R.route.route)),k({clock:$.doneData,target:y}),v({clock:n.doneData,filter:({opened:a})=>a.length===0,target:p});let u=n.doneData.map(({opened:a})=>a),O=n.doneData.map(({closed:a})=>a);for(let a of t){let s=C(!1),R=a.route.navigate.done;k({clock:R,fn:({result:{params:m,query:f}})=>({route:a,params:m,query:f}),target:$});let h=m=>{let f=m.find(Q=>Q.route.route===a.route);if(!!f)return{params:f.params,query:f.query}},d={opened:v({clock:u.filterMap(h),filter:a.route.$isOpened.map(m=>!m)}),updated:v({clock:u.filterMap(h),filter:a.route.$isOpened}),closed:v({clock:O.filterMap(h),filter:a.route.$isOpened})};s.on(R,()=>!0);let g=v({clock:d.updated,filter:s.map(m=>!m)});k({source:ne(g,null),clock:v({clock:g,source:[a.route.$params,a.route.$query],filter:([m,f],Q)=>!F(m,Q.params)||!F(f,Q.query)}),fn:m=>m,target:a.route.updated}),v({clock:d.opened,filter:s.map(m=>!m),target:a.route.opened}),k({clock:d.closed,target:a.route.closed}),s.reset(k({clock:u}))}let I=j({source:{history:P},effect:async({history:a})=>{let[s,R,h]=[a.location.pathname,Object.fromEntries(new URLSearchParams(a.location.search)),a.location.hash];return{path:s,query:R,hash:h}}});k({source:I.doneData,target:n});let _=j({source:{history:P},effect:async({history:a})=>{let s=I;try{s=oe(I)}catch{}return a.listen(()=>{s()}),!0}});e.hydrate||k({clock:_.doneData,target:I}),k({clock:P,target:_}),l.on(n.doneData,()=>!0).reset(P);let J=k({clock:v({clock:l,filter:Boolean}),source:{activeRoutes:c,path:o,query:i}});return{$path:o,$query:i,$activeRoutes:c,$history:P,setHistory:r,push:y,routes:t,initialized:J,routeNotFound:p}};var K=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===q.ROUTE;import{createEvent as ue,createStore as me,is as ie,sample as L}from"effector";var He=e=>{let t=e.clock?L({clock:e.clock}):ue(),r=W(e.params||{}),p=W(e.query||{});return L({clock:t,source:{params:r,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},W=e=>ie.store(e)?e:me(e);import{is as V,guard as pe,merge as X,sample as E,combine as D,createStore as G,createEvent as H,attach as Pe}from"effector";var le=e=>{if(K(e))return{route:e,chainedRoute:A(),beforeOpen:H(),openOn:X([e.opened,e.closed]),cancelOn:X([H()])};let t={...e};if(V.unit(t.beforeOpen)||(t.beforeOpen=Pe(t.beforeOpen)),V.effect(t.beforeOpen))return{route:t.route,chainedRoute:t.chainedRoute||A(),beforeOpen:t.beforeOpen,openOn:"openOn"in t?t.openOn:t.beforeOpen.doneData,cancelOn:"cancelOn"in t?t.cancelOn:t.beforeOpen.failData};let r=e;return{route:r.route,chainedRoute:r.chainedRoute||A(),beforeOpen:r.beforeOpen,openOn:E({clock:r.openOn}),cancelOn:E({clock:r.cancelOn||H()})}};function Ve(e){let{route:t,chainedRoute:r,beforeOpen:p,openOn:i,cancelOn:o}=le(e),c=G({}),l=G({}),P=D(D([t.$params,t.$query]),D([c,l]),(u,O)=>u[0]===O[0]&&u[1]===O[1]),y=E({clock:[t.opened,t.updated]});E({clock:y,target:p}),c.on(y,(u,{params:O})=>O),l.on(y,(u,{query:O})=>O);let $=pe({clock:i,source:{params:c,query:l},filter:P});E({clock:$,target:r.navigate});let n=X([t.closed,o]);return c.reset(n),l.reset(n),E({clock:n,target:r.closed}),r}export{q as Kind,M as buildPath,Ve as chainRoute,Ie as createHistoryRouter,A as createRoute,K as isRoute,B as matchPath,He as redirect}; |
@@ -1,1 +0,1 @@ | ||
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}); | ||
"use strict";var A=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var r in t)A(e,r,{get:t[r],enumerable:!0})},B=(e,t,r,P)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of w(t))!z.call(e,m)&&m!==r&&A(e,m,{get:()=>t[m],enumerable:!(P=_(t,m))||P.enumerable});return e};var N=e=>B(A({},"__esModule",{value:!0}),e);var ee={};M(ee,{Kind:()=>$,buildPath:()=>T,chainRoute:()=>Z,createHistoryRouter:()=>G,createRoute:()=>I,isRoute:()=>U,matchPath:()=>F,redirect:()=>J});module.exports=N(ee);var l=require("effector");var $={ROUTE:Symbol()};var I=(e={})=>{let t=(0,l.createEffect)(async({params:c,query:p})=>({params:c||{},query:p||{}})),r=(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:r,kind:$.ROUTE,settings:{derived:Boolean(e.filter)}}};var S=require("path-to-regexp"),K=e=>{if(e.match(/^[a-z0-9]+\:\/\//i))return e;let t=new URL(`http://_${e}`);return[t.pathname,t.hash].join("")},L=e=>e.replace("://","\\://");function T({pathCreator:e,params:t,query:r}){let P=(0,S.compile)(e)(t),m=Object.keys(r).length?`?${new URLSearchParams(r)}`:"";return`${P}${m}`}function F({pathCreator:e,actualPath:t}){let r=(0,S.match)(L(e))(K(t));return r?{matches:!0,params:r.params}:{matches:!1}}var a=require("effector");var j=(e,t)=>{if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let r in e)if(`${e[r]}`!=`${t[r]}`)return!1;return!0};var W=(0,a.createEffect)(e=>{if(!e.history)throw new Error("[Routing] No history provided");return e.history[e.method](e.path,{}),e}),V=(e,t="")=>{let r=[];for(let s of e)Array.isArray(s.route)?r.push(...s.route.map(i=>({...s,route:i}))):r.push(s);r=r.map(s=>({...s,path:`${t}${s.path}`}));let P=[],m=[];for(let s of r)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},G=e=>{let t=V(e.routes,e.base),r=(0,a.createEvent)(),P=(0,a.createEvent)(),m=(0,a.createStore)({}),s=(0,a.createStore)(""),i=(0,a.createStore)([],{serialize:"ignore"}),f=(0,a.createStore)(!1),d=(0,a.createStore)(null,{serialize:"ignore"});d.on(r,(o,u)=>u);let O=(0,a.attach)({source:{history:d},effect:W,mapParams:(o,{history:u})=>({history:u,...o})}),E=(0,a.createEffect)(({route:o,params:u,query:y})=>({path:T({pathCreator:o.path,params:u,query:y}),params:u,query:y,method:"push"})),c=(0,a.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}=F({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,a.sample)({clock:E.doneData,target:O}),(0,a.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,a.createStore)(!1),y=o.route.navigate.done;(0,a.sample)({clock:y,fn:({result:{params:R,query:k}})=>({route:o,params:R,query:k}),target:E});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,a.guard)({clock:p.filterMap(g),filter:o.route.$isOpened.map(R=>!R)}),updated:(0,a.guard)({clock:p.filterMap(g),filter:o.route.$isOpened}),closed:(0,a.guard)({clock:b.filterMap(g),filter:o.route.$isOpened})};u.on(y,()=>!0);let v=(0,a.guard)({clock:h.updated,filter:u.map(R=>!R)});(0,a.sample)({source:(0,a.restore)(v,null),clock:(0,a.guard)({clock:v,source:[o.route.$params,o.route.$query],filter:([R,k],C)=>!j(R,C.params)||!j(k,C.query)}),fn:R=>R,target:o.route.updated}),(0,a.guard)({clock:h.opened,filter:u.map(R=>!R),target:o.route.opened}),(0,a.sample)({clock:h.closed,target:o.route.closed}),u.reset((0,a.sample)({clock:p}))}let q=(0,a.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,a.sample)({source:q.doneData,target:c});let D=(0,a.attach)({source:{history:d},effect:async({history:o})=>{let u=q;try{u=(0,a.scopeBind)(q)}catch{}return o.listen(()=>{u()}),!0}});e.hydrate||(0,a.sample)({clock:D.doneData,target:q}),(0,a.sample)({clock:d,target:D}),f.on(c.doneData,()=>!0).reset(d);let X=(0,a.sample)({clock:(0,a.guard)({clock:f,filter:Boolean}),source:{activeRoutes:i,path:s,query:m}});return{$path:s,$query:m,$activeRoutes:i,$history:d,setHistory:r,push:O,routes:t,initialized:X,routeNotFound:P}};var U=e=>typeof e=="object"&&e!==null&&"kind"in e&&e.kind===$.ROUTE;var x=require("effector"),J=e=>{let t=e.clock?(0,x.sample)({clock:e.clock}):(0,x.createEvent)(),r=H(e.params||{}),P=H(e.query||{});return(0,x.sample)({clock:t,source:{params:r,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},H=e=>x.is.store(e)?e:(0,x.createStore)(e);var n=require("effector");var Y=e=>{if(U(e))return{route:e,chainedRoute:I(),beforeOpen:(0,n.createEvent)(),openOn:(0,n.merge)([e.opened,e.closed]),cancelOn:(0,n.merge)([(0,n.createEvent)()])};let t={...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||I(),beforeOpen:t.beforeOpen,openOn:"openOn"in t?t.openOn:t.beforeOpen.doneData,cancelOn:"cancelOn"in t?t.cancelOn:t.beforeOpen.failData};let r=e;return{route:r.route,chainedRoute:r.chainedRoute||I(),beforeOpen:r.beforeOpen,openOn:(0,n.sample)({clock:r.openOn}),cancelOn:(0,n.sample)({clock:r.cancelOn||(0,n.createEvent)()})}};function Z(e){let{route:t,chainedRoute:r,beforeOpen:P,openOn:m,cancelOn:s}=Y(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 E=(0,n.guard)({clock:m,source:{params:i,query:f},filter:d});(0,n.sample)({clock:E,target:r.navigate});let c=(0,n.merge)([t.closed,s]);return i.reset(c),f.reset(c),(0,n.sample)({clock:c,target:r.closed}),r}0&&(module.exports={Kind,buildPath,chainRoute,createHistoryRouter,createRoute,isRoute,matchPath,redirect}); |
{ | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -12,7 +12,5 @@ # Atomic Router | ||
## View-library bindings | ||
### Read the docs: [atomic-router.github.io](https://atomic-router.github.io) | ||
- [**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) | ||
### Get view-library bindings: [**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) | ||
@@ -19,0 +17,0 @@ ## Installation |
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
48044
969
169