@arielgonzaguer/michi-router 3.3.0 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/protected.js +2 -2
- package/dist/protected.mjs +2 -2
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var v=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var E=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},F=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of b(e))!A.call(t,o)&&o!==n&&v(t,o,{get:()=>e[o],enumerable:!(r=O(e,o))||r.enumerable});return t};var U=t=>F(v({},"__esModule",{value:!0}),t);var q={};E(q,{Link:()=>I,RouterProvider:()=>k,useLocation:()=>z,useNavigate:()=>N,useParams:()=>B});module.exports=U(q);var c=require("react");var M="https://michi-router.local",W=new Set(["http:","https:"]),_=t=>t.startsWith("/")?t:`/${t}`,f=t=>{let e=t.trim();if(!e)return"/";let n=_(e);return(n.length>1?n.replace(/\/+$/,""):n)||"/"},L=t=>t?f(t):"/",D=(t,e)=>e==="/"?!0:t===e||t.startsWith(`${e}/`),H=(t,e)=>e==="/"?t:t===e?"/":t.startsWith(`${e}/`)?t.slice(e.length)||"/":t,j=(t,e)=>t==="/"?e:e==="/"?t:`${t}${e}`,y=t=>{try{return decodeURIComponent(t)}catch{return t}},w=(t,e="/")=>{if(typeof t!="string")return null;let n=t.trim();if(!n||Array.from(n).some(p=>p<=""||p==="\x7F"))return null;let r=L(e),o=typeof window<"u"?window.location.origin:M,i=r==="/"?`${o}/`:`${o}${r}/`,s;try{s=new URL(n,i)}catch{return null}if(!W.has(s.protocol)||typeof window<"u"&&s.origin!==window.location.origin)return null;let a=f(s.pathname),u=D(a,r)?f(H(a,r)):a,l=f(j(r,u)),g=s.search||"",m=s.hash||"",h=`${u}${g}${m}`,d=`${l}${g}${m}`;return{pathname:u,search:g,hash:m,fullPath:h,browserPath:d}},C=(t,e)=>{let n=f(t),r=f(e);if(n==="*")return{"*":r==="/"?"":r.slice(1)};let o=n==="/"?[]:n.slice(1).split("/"),i=r==="/"?[]:r.slice(1).split("/"),s={},a=0,u=0;for(;a<o.length&&u<i.length;){let l=o[a];if(l==="*"){if(a!==o.length-1)return null;s["*"]=i.slice(u).map(y).join("/"),u=i.length,a=o.length;break}let g=i[u];if(l.startsWith(":")){let m=l.slice(1);if(!m)return null;s[m]=y(g)}else if(l!==g)return null;a+=1,u+=1}return a<o.length&&o[a]==="*"&&a===o.length-1&&(s["*"]="",a+=1),a!==o.length||u!==i.length?null:s};var R=require("react/jsx-runtime"),x=typeof window<"u",T={pathname:"/",search:"",hash:"",fullPath:"/"},S=t=>{if(!x)return T;let e=`${window.location.pathname}${window.location.search}${window.location.hash}`,n=w(e,t);if(n)return{pathname:n.pathname,search:n.search,hash:n.hash,fullPath:n.fullPath};let r=f(window.location.pathname);return{pathname:r,search:window.location.search,hash:window.location.hash,fullPath:`${r}${window.location.search}${window.location.hash}`}},P=(0,c.createContext)({path:"/",location:T,params:{},basename:"/",navigate:()=>{console.warn("RouterContext usado fuera de RouterProvider")}});function k({routes:t,children:e,notFound:n,basename:r,layout:o}){let i=(0,c.useMemo)(()=>L(r),[r]),[s,a]=(0,c.useState)(()=>S(i));(0,c.useEffect)(()=>{if(!x)return;let h=()=>a(S(i));return window.addEventListener("popstate",h),()=>window.removeEventListener("popstate",h)},[i]);let u=(0,c.useCallback)((h,d)=>{let p=w(h,i);if(!p){console.warn(`MichiRouter: navegaci\xF3n bloqueada. URL interna no v\xE1lida: "${h}"`);return}let $={pathname:p.pathname,search:p.search,hash:p.hash,fullPath:p.fullPath};if(!x){a($);return}d?.replace?window.history.replaceState(d?.state??null,"",p.browserPath):window.history.pushState(d?.state??null,"",p.browserPath),a($)},[i]),l=(0,c.useMemo)(()=>{for(let h of t){let d=C(h.path,s.pathname);if(d)return{route:h,params:d}}return null},[s.pathname,t]),g=l?.params??{},m=l?l.route.component:n??e;return(0,R.jsx)(P.Provider,{value:{path:s.pathname,location:s,params:g,basename:i,navigate:u},children:o?(0,R.jsx)(o,{children:m}):m})}var I=({to:t,children:e,className:n,onClick:r,...o})=>{let{navigate:i,basename:s}=(0,c.useContext)(P),a=w(t,s),u=a?a.browserPath:"#";return(0,R.jsx)("a",{href:u,className:n,onClick:l=>{r?.(l),!l.defaultPrevented&&(l.preventDefault(),i(t))},...o,children:e})},N=()=>(0,c.useContext)(P).navigate,z=()=>(0,c.useContext)(P).location,B=()=>(0,c.useContext)(P).params;0&&(module.exports={Link,RouterProvider,useLocation,useNavigate,useParams});
|
package/dist/core.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback as b,createContext as
|
|
1
|
+
import{useCallback as b,createContext as A,useContext as w,useEffect as E,useMemo as C,useState as F}from"react";var k="https://michi-router.local",I=new Set(["http:","https:"]),N=t=>t.startsWith("/")?t:`/${t}`,d=t=>{let e=t.trim();if(!e)return"/";let n=N(e);return(n.length>1?n.replace(/\/+$/,""):n)||"/"},R=t=>t?d(t):"/",z=(t,e)=>e==="/"?!0:t===e||t.startsWith(`${e}/`),B=(t,e)=>e==="/"?t:t===e?"/":t.startsWith(`${e}/`)?t.slice(e.length)||"/":t,O=(t,e)=>t==="/"?e:e==="/"?t:`${t}${e}`,$=t=>{try{return decodeURIComponent(t)}catch{return t}},P=(t,e="/")=>{if(typeof t!="string")return null;let n=t.trim();if(!n||Array.from(n).some(h=>h<=""||h==="\x7F"))return null;let o=R(e),s=typeof window<"u"?window.location.origin:k,i=o==="/"?`${s}/`:`${s}${o}/`,a;try{a=new URL(n,i)}catch{return null}if(!I.has(a.protocol)||typeof window<"u"&&a.origin!==window.location.origin)return null;let r=d(a.pathname),c=z(r,o)?d(B(r,o)):r,u=d(O(o,c)),m=a.search||"",p=a.hash||"",l=`${c}${m}${p}`,g=`${u}${m}${p}`;return{pathname:c,search:m,hash:p,fullPath:l,browserPath:g}},y=(t,e)=>{let n=d(t),o=d(e);if(n==="*")return{"*":o==="/"?"":o.slice(1)};let s=n==="/"?[]:n.slice(1).split("/"),i=o==="/"?[]:o.slice(1).split("/"),a={},r=0,c=0;for(;r<s.length&&c<i.length;){let u=s[r];if(u==="*"){if(r!==s.length-1)return null;a["*"]=i.slice(c).map($).join("/"),c=i.length,r=s.length;break}let m=i[c];if(u.startsWith(":")){let p=u.slice(1);if(!p)return null;a[p]=$(m)}else if(u!==m)return null;r+=1,c+=1}return r<s.length&&s[r]==="*"&&r===s.length-1&&(a["*"]="",r+=1),r!==s.length||c!==i.length?null:a};import{jsx as L}from"react/jsx-runtime";var v=typeof window<"u",T={pathname:"/",search:"",hash:"",fullPath:"/"},S=t=>{if(!v)return T;let e=`${window.location.pathname}${window.location.search}${window.location.hash}`,n=P(e,t);if(n)return{pathname:n.pathname,search:n.search,hash:n.hash,fullPath:n.fullPath};let o=d(window.location.pathname);return{pathname:o,search:window.location.search,hash:window.location.hash,fullPath:`${o}${window.location.search}${window.location.hash}`}},f=A({path:"/",location:T,params:{},basename:"/",navigate:()=>{console.warn("RouterContext usado fuera de RouterProvider")}});function U({routes:t,children:e,notFound:n,basename:o,layout:s}){let i=C(()=>R(o),[o]),[a,r]=F(()=>S(i));E(()=>{if(!v)return;let l=()=>r(S(i));return window.addEventListener("popstate",l),()=>window.removeEventListener("popstate",l)},[i]);let c=b((l,g)=>{let h=P(l,i);if(!h){console.warn(`MichiRouter: navegaci\xF3n bloqueada. URL interna no v\xE1lida: "${l}"`);return}let x={pathname:h.pathname,search:h.search,hash:h.hash,fullPath:h.fullPath};if(!v){r(x);return}g?.replace?window.history.replaceState(g?.state??null,"",h.browserPath):window.history.pushState(g?.state??null,"",h.browserPath),r(x)},[i]),u=C(()=>{for(let l of t){let g=y(l.path,a.pathname);if(g)return{route:l,params:g}}return null},[a.pathname,t]),m=u?.params??{},p=u?u.route.component:n??e;return L(f.Provider,{value:{path:a.pathname,location:a,params:m,basename:i,navigate:c},children:s?L(s,{children:p}):p})}var M=({to:t,children:e,className:n,onClick:o,...s})=>{let{navigate:i,basename:a}=w(f),r=P(t,a),c=r?r.browserPath:"#";return L("a",{href:c,className:n,onClick:u=>{o?.(u),!u.defaultPrevented&&(u.preventDefault(),i(t))},...s,children:e})},W=()=>w(f).navigate,_=()=>w(f).location,D=()=>w(f).params;export{M as Link,U as RouterProvider,_ as useLocation,W as useNavigate,D as useParams};
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var C=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var O=(t,e)=>{for(var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var O=(t,e)=>{for(var n in e)C(t,n,{get:e[n],enumerable:!0})},W=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of b(e))!F.call(t,o)&&o!==n&&C(t,o,{get:()=>e[o],enumerable:!(r=U(e,o))||r.enumerable});return t};var _=t=>W(C({},"__esModule",{value:!0}),t);var V={};O(V,{Link:()=>z,Protected:()=>x,RouterProvider:()=>I,useLocation:()=>A,useNavigate:()=>L,useParams:()=>B});module.exports=_(V);var l=require("react");var q="https://michi-router.local",D=new Set(["http:","https:"]),H=t=>t.startsWith("/")?t:`/${t}`,g=t=>{let e=t.trim();if(!e)return"/";let n=H(e);return(n.length>1?n.replace(/\/+$/,""):n)||"/"},y=t=>t?g(t):"/",G=(t,e)=>e==="/"?!0:t===e||t.startsWith(`${e}/`),K=(t,e)=>e==="/"?t:t===e?"/":t.startsWith(`${e}/`)?t.slice(e.length)||"/":t,J=(t,e)=>t==="/"?e:e==="/"?t:`${t}${e}`,T=t=>{try{return decodeURIComponent(t)}catch{return t}},w=(t,e="/")=>{if(typeof t!="string")return null;let n=t.trim();if(!n||Array.from(n).some(d=>d<=""||d==="\x7F"))return null;let r=y(e),o=typeof window<"u"?window.location.origin:q,i=r==="/"?`${o}/`:`${o}${r}/`,a;try{a=new URL(n,i)}catch{return null}if(!D.has(a.protocol)||typeof window<"u"&&a.origin!==window.location.origin)return null;let s=g(a.pathname),c=G(s,r)?g(K(s,r)):s,u=g(J(r,c)),f=a.search||"",p=a.hash||"",h=`${c}${f}${p}`,m=`${u}${f}${p}`;return{pathname:c,search:f,hash:p,fullPath:h,browserPath:m}},k=(t,e)=>{let n=g(t),r=g(e);if(n==="*")return{"*":r==="/"?"":r.slice(1)};let o=n==="/"?[]:n.slice(1).split("/"),i=r==="/"?[]:r.slice(1).split("/"),a={},s=0,c=0;for(;s<o.length&&c<i.length;){let u=o[s];if(u==="*"){if(s!==o.length-1)return null;a["*"]=i.slice(c).map(T).join("/"),c=i.length,s=o.length;break}let f=i[c];if(u.startsWith(":")){let p=u.slice(1);if(!p)return null;a[p]=T(f)}else if(u!==f)return null;s+=1,c+=1}return s<o.length&&o[s]==="*"&&s===o.length-1&&(a["*"]="",s+=1),s!==o.length||c!==i.length?null:a};var v=require("react/jsx-runtime"),$=typeof window<"u",E={pathname:"/",search:"",hash:"",fullPath:"/"},N=t=>{if(!$)return E;let e=`${window.location.pathname}${window.location.search}${window.location.hash}`,n=w(e,t);if(n)return{pathname:n.pathname,search:n.search,hash:n.hash,fullPath:n.fullPath};let r=g(window.location.pathname);return{pathname:r,search:window.location.search,hash:window.location.hash,fullPath:`${r}${window.location.search}${window.location.hash}`}},R=(0,l.createContext)({path:"/",location:E,params:{},basename:"/",navigate:()=>{console.warn("RouterContext usado fuera de RouterProvider")}});function I({routes:t,children:e,notFound:n,basename:r,layout:o}){let i=(0,l.useMemo)(()=>y(r),[r]),[a,s]=(0,l.useState)(()=>N(i));(0,l.useEffect)(()=>{if(!$)return;let h=()=>s(N(i));return window.addEventListener("popstate",h),()=>window.removeEventListener("popstate",h)},[i]);let c=(0,l.useCallback)((h,m)=>{let d=w(h,i);if(!d){console.warn(`MichiRouter: navegaci\xF3n bloqueada. URL interna no v\xE1lida: "${h}"`);return}let S={pathname:d.pathname,search:d.search,hash:d.hash,fullPath:d.fullPath};if(!$){s(S);return}m?.replace?window.history.replaceState(m?.state??null,"",d.browserPath):window.history.pushState(m?.state??null,"",d.browserPath),s(S)},[i]),u=(0,l.useMemo)(()=>{for(let h of t){let m=k(h.path,a.pathname);if(m)return{route:h,params:m}}return null},[a.pathname,t]),f=u?.params??{},p=u?u.route.component:n??e;return(0,v.jsx)(R.Provider,{value:{path:a.pathname,location:a,params:f,basename:i,navigate:c},children:o?(0,v.jsx)(o,{children:p}):p})}var z=({to:t,children:e,className:n,onClick:r,...o})=>{let{navigate:i,basename:a}=(0,l.useContext)(R),s=w(t,a),c=s?s.browserPath:"#";return(0,v.jsx)("a",{href:c,className:n,onClick:u=>{r?.(u),!u.defaultPrevented&&(u.preventDefault(),i(t))},...o,children:e})},L=()=>(0,l.useContext)(R).navigate,A=()=>(0,l.useContext)(R).location,B=()=>(0,l.useContext)(R).params;var M=require("react");var P=require("react/jsx-runtime"),Q=t=>{let e=w(t,"/");return e?e.fullPath:"/"};function x({children:t,configObject:e}){let n=L(),r={states:e?.states||{user:null,isLoading:!1},redirectionPath:e?.redirectionPath||"/",loadingComponent:e?.loadingComponent||null,defaultMessage:e?.defaultMessage||void 0},o=Q(r.redirectionPath),{user:i,isLoading:a}=r.states;return(0,M.useEffect)(()=>{!a&&!i&&(o!==r.redirectionPath&&console.warn(`Protected: redirectionPath inseguro bloqueado ("${r.redirectionPath}"). Se usa "/" como fallback.`),n(o,{replace:!0}))},[a,i,n,o,r.redirectionPath]),e?.states?a?r.loadingComponent?(0,P.jsx)(P.Fragment,{children:r.loadingComponent}):r.defaultMessage?(0,P.jsx)(P.Fragment,{children:r.defaultMessage}):null:i?(0,P.jsx)(P.Fragment,{children:t}):null:(console.error(`Componente Protected: El objeto de configuraci\xF3n es inv\xE1lido. Este es el formato esperado:
|
|
2
2
|
{
|
|
3
3
|
states: { user: any; isLoading: boolean };
|
|
4
4
|
redirectionPath: string;
|
|
5
5
|
loadingComponent?: React.ReactNode;
|
|
6
6
|
defaultMessage?: string;
|
|
7
|
-
}`),null
|
|
7
|
+
}`),null)}0&&(module.exports={Link,Protected,RouterProvider,useLocation,useNavigate,useParams});
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{useCallback as F,createContext as O,useContext as w,useEffect as W,useMemo as N,useState as _}from"react";var z="https://michi-router.local",
|
|
1
|
+
import{useCallback as F,createContext as O,useContext as w,useEffect as W,useMemo as N,useState as _}from"react";var z="https://michi-router.local",A=new Set(["http:","https:"]),B=t=>t.startsWith("/")?t:`/${t}`,m=t=>{let e=t.trim();if(!e)return"/";let n=B(e);return(n.length>1?n.replace(/\/+$/,""):n)||"/"},R=t=>t?m(t):"/",M=(t,e)=>e==="/"?!0:t===e||t.startsWith(`${e}/`),U=(t,e)=>e==="/"?t:t===e?"/":t.startsWith(`${e}/`)?t.slice(e.length)||"/":t,b=(t,e)=>t==="/"?e:e==="/"?t:`${t}${e}`,T=t=>{try{return decodeURIComponent(t)}catch{return t}},g=(t,e="/")=>{if(typeof t!="string")return null;let n=t.trim();if(!n||Array.from(n).some(h=>h<=""||h==="\x7F"))return null;let r=R(e),s=typeof window<"u"?window.location.origin:z,i=r==="/"?`${s}/`:`${s}${r}/`,o;try{o=new URL(n,i)}catch{return null}if(!A.has(o.protocol)||typeof window<"u"&&o.origin!==window.location.origin)return null;let a=m(o.pathname),l=M(a,r)?m(U(a,r)):a,c=m(b(r,l)),p=o.search||"",d=o.hash||"",u=`${l}${p}${d}`,f=`${c}${p}${d}`;return{pathname:l,search:p,hash:d,fullPath:u,browserPath:f}},k=(t,e)=>{let n=m(t),r=m(e);if(n==="*")return{"*":r==="/"?"":r.slice(1)};let s=n==="/"?[]:n.slice(1).split("/"),i=r==="/"?[]:r.slice(1).split("/"),o={},a=0,l=0;for(;a<s.length&&l<i.length;){let c=s[a];if(c==="*"){if(a!==s.length-1)return null;o["*"]=i.slice(l).map(T).join("/"),l=i.length,a=s.length;break}let p=i[l];if(c.startsWith(":")){let d=c.slice(1);if(!d)return null;o[d]=T(p)}else if(c!==p)return null;a+=1,l+=1}return a<s.length&&s[a]==="*"&&a===s.length-1&&(o["*"]="",a+=1),a!==s.length||l!==i.length?null:o};import{jsx as L}from"react/jsx-runtime";var v=typeof window<"u",I={pathname:"/",search:"",hash:"",fullPath:"/"},E=t=>{if(!v)return I;let e=`${window.location.pathname}${window.location.search}${window.location.hash}`,n=g(e,t);if(n)return{pathname:n.pathname,search:n.search,hash:n.hash,fullPath:n.fullPath};let r=m(window.location.pathname);return{pathname:r,search:window.location.search,hash:window.location.hash,fullPath:`${r}${window.location.search}${window.location.hash}`}},P=O({path:"/",location:I,params:{},basename:"/",navigate:()=>{console.warn("RouterContext usado fuera de RouterProvider")}});function q({routes:t,children:e,notFound:n,basename:r,layout:s}){let i=N(()=>R(r),[r]),[o,a]=_(()=>E(i));W(()=>{if(!v)return;let u=()=>a(E(i));return window.addEventListener("popstate",u),()=>window.removeEventListener("popstate",u)},[i]);let l=F((u,f)=>{let h=g(u,i);if(!h){console.warn(`MichiRouter: navegaci\xF3n bloqueada. URL interna no v\xE1lida: "${u}"`);return}let S={pathname:h.pathname,search:h.search,hash:h.hash,fullPath:h.fullPath};if(!v){a(S);return}f?.replace?window.history.replaceState(f?.state??null,"",h.browserPath):window.history.pushState(f?.state??null,"",h.browserPath),a(S)},[i]),c=N(()=>{for(let u of t){let f=k(u.path,o.pathname);if(f)return{route:u,params:f}}return null},[o.pathname,t]),p=c?.params??{},d=c?c.route.component:n??e;return L(P.Provider,{value:{path:o.pathname,location:o,params:p,basename:i,navigate:l},children:s?L(s,{children:d}):d})}var D=({to:t,children:e,className:n,onClick:r,...s})=>{let{navigate:i,basename:o}=w(P),a=g(t,o),l=a?a.browserPath:"#";return L("a",{href:l,className:n,onClick:c=>{r?.(c),!c.defaultPrevented&&(c.preventDefault(),i(t))},...s,children:e})},x=()=>w(P).navigate,H=()=>w(P).location,G=()=>w(P).params;import{useEffect as K}from"react";import{Fragment as C,jsx as y}from"react/jsx-runtime";var J=t=>{let e=g(t,"/");return e?e.fullPath:"/"};function $({children:t,configObject:e}){let n=x(),r={states:e?.states||{user:null,isLoading:!1},redirectionPath:e?.redirectionPath||"/",loadingComponent:e?.loadingComponent||null,defaultMessage:e?.defaultMessage||void 0},s=J(r.redirectionPath),{user:i,isLoading:o}=r.states;return K(()=>{!o&&!i&&(s!==r.redirectionPath&&console.warn(`Protected: redirectionPath inseguro bloqueado ("${r.redirectionPath}"). Se usa "/" como fallback.`),n(s,{replace:!0}))},[o,i,n,s,r.redirectionPath]),e?.states?o?r.loadingComponent?y(C,{children:r.loadingComponent}):r.defaultMessage?y(C,{children:r.defaultMessage}):null:i?y(C,{children:t}):null:(console.error(`Componente Protected: El objeto de configuraci\xF3n es inv\xE1lido. Este es el formato esperado:
|
|
2
2
|
{
|
|
3
3
|
states: { user: any; isLoading: boolean };
|
|
4
4
|
redirectionPath: string;
|
|
5
5
|
loadingComponent?: React.ReactNode;
|
|
6
6
|
defaultMessage?: string;
|
|
7
|
-
}`),null
|
|
7
|
+
}`),null)}export{D as Link,$ as Protected,q as RouterProvider,H as useLocation,x as useNavigate,G as useParams};
|
package/dist/protected.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var S=(t,e)=>{for(var r in e)p(t,r,{get:e[r],enumerable:!0})},T=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!y.call(t,o)&&o!==r&&p(t,o,{get:()=>e[o],enumerable:!(n=x(e,o))||n.enumerable});return t};var E=t=>T(p({},"__esModule",{value:!0}),t);var O={};S(O,{Protected:()=>g});module.exports=E(O);var R=require("react");var s=require("react");var I="https://michi-router.local",k=new Set(["http:","https:"]),z=t=>t.startsWith("/")?t:`/${t}`,c=t=>{let e=t.trim();if(!e)return"/";let r=z(e);return(r.length>1?r.replace(/\/+$/,""):r)||"/"},B=t=>t?c(t):"/",M=(t,e)=>e==="/"?!0:t===e||t.startsWith(`${e}/`),N=(t,e)=>e==="/"?t:t===e?"/":t.startsWith(`${e}/`)?t.slice(e.length)||"/":t,A=(t,e)=>t==="/"?e:e==="/"?t:`${t}${e}`;var P=(t,e="/")=>{if(typeof t!="string")return null;let r=t.trim();if(!r||Array.from(r).some(m=>m<=""||m==="\x7F"))return null;let n=B(e),o=typeof window<"u"?window.location.origin:I,l=n==="/"?`${o}/`:`${o}${n}/`,a;try{a=new URL(r,l)}catch{return null}if(!k.has(a.protocol)||typeof window<"u"&&a.origin!==window.location.origin)return null;let u=c(a.pathname),h=M(u,n)?c(N(u,n)):u,v=c(A(n,h)),d=a.search||"",f=a.hash||"",L=`${h}${d}${f}`,C=`${v}${d}${f}`;return{pathname:h,search:d,hash:f,fullPath:L,browserPath:C}};var F=require("react/jsx-runtime");var U={pathname:"/",search:"",hash:"",fullPath:"/"};var b=(0,s.createContext)({path:"/",location:U,params:{},basename:"/",navigate:()=>{console.warn("RouterContext usado fuera de RouterProvider")}});var w=()=>(0,s.useContext)(b).navigate;var i=require("react/jsx-runtime"),W=t=>{let e=P(t,"/");return e?e.fullPath:"/"};function g({children:t,configObject:e}){let r=w(),n={states:e?.states||{user:null,isLoading:!1},redirectionPath:e?.redirectionPath||"/",loadingComponent:e?.loadingComponent||null,defaultMessage:e?.defaultMessage||void 0},o=W(n.redirectionPath),{user:l,isLoading:a}=n.states;return(0,R.useEffect)(()=>{!a&&!l&&(o!==n.redirectionPath&&console.warn(`Protected: redirectionPath inseguro bloqueado ("${n.redirectionPath}"). Se usa "/" como fallback.`),r(o,{replace:!0}))},[a,l,r,o,n.redirectionPath]),e?.states?a?n.loadingComponent?(0,i.jsx)(i.Fragment,{children:n.loadingComponent}):n.defaultMessage?(0,i.jsx)(i.Fragment,{children:n.defaultMessage}):null:l?(0,i.jsx)(i.Fragment,{children:t}):null:(console.error(`Componente Protected: El objeto de configuraci\xF3n es inv\xE1lido. Este es el formato esperado:
|
|
2
2
|
{
|
|
3
3
|
states: { user: any; isLoading: boolean };
|
|
4
4
|
redirectionPath: string;
|
|
5
5
|
loadingComponent?: React.ReactNode;
|
|
6
6
|
defaultMessage?: string;
|
|
7
|
-
}`),null
|
|
7
|
+
}`),null)}0&&(module.exports={Protected});
|
package/dist/protected.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{useEffect as
|
|
1
|
+
import{useEffect as B}from"react";import{useCallback as b,createContext as E,useContext as I,useEffect as F,useMemo as W,useState as O}from"react";var L="https://michi-router.local",C=new Set(["http:","https:"]),x=t=>t.startsWith("/")?t:`/${t}`,i=t=>{let e=t.trim();if(!e)return"/";let r=x(e);return(r.length>1?r.replace(/\/+$/,""):r)||"/"},$=t=>t?i(t):"/",y=(t,e)=>e==="/"?!0:t===e||t.startsWith(`${e}/`),S=(t,e)=>e==="/"?t:t===e?"/":t.startsWith(`${e}/`)?t.slice(e.length)||"/":t,T=(t,e)=>t==="/"?e:e==="/"?t:`${t}${e}`;var g=(t,e="/")=>{if(typeof t!="string")return null;let r=t.trim();if(!r||Array.from(r).some(p=>p<=""||p==="\x7F"))return null;let n=$(e),a=typeof window<"u"?window.location.origin:L,s=n==="/"?`${a}/`:`${a}${n}/`,o;try{o=new URL(r,s)}catch{return null}if(!C.has(o.protocol)||typeof window<"u"&&o.origin!==window.location.origin)return null;let l=i(o.pathname),c=y(l,n)?i(S(l,n)):l,w=i(T(n,c)),u=o.search||"",h=o.hash||"",R=`${c}${u}${h}`,v=`${w}${u}${h}`;return{pathname:c,search:u,hash:h,fullPath:R,browserPath:v}};import{jsx as q}from"react/jsx-runtime";var k={pathname:"/",search:"",hash:"",fullPath:"/"};var z=E({path:"/",location:k,params:{},basename:"/",navigate:()=>{console.warn("RouterContext usado fuera de RouterProvider")}});var m=()=>I(z).navigate;import{Fragment as d,jsx as f}from"react/jsx-runtime";var M=t=>{let e=g(t,"/");return e?e.fullPath:"/"};function P({children:t,configObject:e}){let r=m(),n={states:e?.states||{user:null,isLoading:!1},redirectionPath:e?.redirectionPath||"/",loadingComponent:e?.loadingComponent||null,defaultMessage:e?.defaultMessage||void 0},a=M(n.redirectionPath),{user:s,isLoading:o}=n.states;return B(()=>{!o&&!s&&(a!==n.redirectionPath&&console.warn(`Protected: redirectionPath inseguro bloqueado ("${n.redirectionPath}"). Se usa "/" como fallback.`),r(a,{replace:!0}))},[o,s,r,a,n.redirectionPath]),e?.states?o?n.loadingComponent?f(d,{children:n.loadingComponent}):n.defaultMessage?f(d,{children:n.defaultMessage}):null:s?f(d,{children:t}):null:(console.error(`Componente Protected: El objeto de configuraci\xF3n es inv\xE1lido. Este es el formato esperado:
|
|
2
2
|
{
|
|
3
3
|
states: { user: any; isLoading: boolean };
|
|
4
4
|
redirectionPath: string;
|
|
5
5
|
loadingComponent?: React.ReactNode;
|
|
6
6
|
defaultMessage?: string;
|
|
7
|
-
}`),null
|
|
7
|
+
}`),null)}export{P as Protected};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arielgonzaguer/michi-router",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.2",
|
|
5
5
|
"description": "El router minimalista y simple para React.\nEl objetivo principal de esta herramienta es proporcionar la funcionalidad básica de enrutamiento.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|