@arielgonzaguer/michi-router 2.0.0 → 2.1.1
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/README.md +10 -8
- package/dist/index.d.ts +13 -11
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,23 +4,25 @@
|
|
|
4
4
|

|
|
5
5
|

|
|
6
6
|
|
|
7
|
-

|
|
10
8
|
|
|
11
9
|
El router minimalista y simple para React.
|
|
12
10
|
El objetivo principal de esta herramienta es proporcionar la funcionalidad básica de enrutamiento.
|
|
13
11
|
No requiere de ninguna dependencia externa, ideal para proyectos pequeños.
|
|
14
12
|
Creado con TypeScript.
|
|
15
13
|
|
|
16
|
-
##
|
|
14
|
+
## 🚀 Características
|
|
17
15
|
|
|
18
|
-
-
|
|
16
|
+
- ✅ **Minimalista**: Solo las funcionalidades esenciales de enrutamiento
|
|
17
|
+
- ✅ **TypeScript**: Completamente tipado para mejor experiencia de desarrollo
|
|
18
|
+
- ✅ **Zero dependencias**: No requiere librerías externas
|
|
19
|
+
- ✅ **Liviano**: Bundle pequeño y optimizado
|
|
20
|
+
- ✅ **Componente Protected**: Control de acceso integrado
|
|
21
|
+
- ✅ **SSR Compatible**: Funciona con Next.js y otras soluciones SSR
|
|
19
22
|
|
|
20
|
-
## Instalación
|
|
23
|
+
## 📦 Instalación
|
|
21
24
|
|
|
22
25
|
```bash
|
|
23
26
|
npm install @arielgonzaguer/michi-router
|
|
24
27
|
```
|
|
25
|
-
|
|
26
|
-
Visite la [Documentación oficial](https://michirouter.vercel.app/) para más detalles.
|
|
28
|
+
Para ver la documentación completa, visite [la página de documentación](https://michirouter.vercel.app/).
|
package/dist/index.d.ts
CHANGED
|
@@ -27,17 +27,19 @@ interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
|
27
27
|
children: ReactNode;
|
|
28
28
|
className?: string;
|
|
29
29
|
}
|
|
30
|
-
interface
|
|
30
|
+
interface AuthState<TUser = any> {
|
|
31
|
+
user: TUser | null;
|
|
32
|
+
isLoading: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface ProtectedConfig<TUser = any> {
|
|
35
|
+
states: AuthState<TUser>;
|
|
36
|
+
redirectionPath: string;
|
|
37
|
+
loadingComponent?: ReactNode;
|
|
38
|
+
defaultMessage?: string;
|
|
39
|
+
}
|
|
40
|
+
interface ProtectedProps<TUser = any> {
|
|
31
41
|
children: JSX.Element;
|
|
32
|
-
configObject:
|
|
33
|
-
states: {
|
|
34
|
-
user: any;
|
|
35
|
-
isLoading: boolean;
|
|
36
|
-
};
|
|
37
|
-
redirectionPath: string;
|
|
38
|
-
loadingComponent?: ReactNode;
|
|
39
|
-
defaultMessage?: string | undefined;
|
|
40
|
-
};
|
|
42
|
+
configObject: ProtectedConfig<TUser>;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -68,6 +70,6 @@ declare const useNavigate: () => (to: string) => void;
|
|
|
68
70
|
* @param {React.ReactNode} props.children - Los nodos React a renderizar si el usuario está autenticado.
|
|
69
71
|
* @returns {JSX.Element|null} Los hijos si está autenticado, de lo contrario loader.
|
|
70
72
|
*/
|
|
71
|
-
declare function Protected({ children, configObject }: ProtectedProps): JSX.Element | null;
|
|
73
|
+
declare function Protected<TUser = any>({ children, configObject }: ProtectedProps<TUser>): JSX.Element | null;
|
|
72
74
|
|
|
73
75
|
export { type LayoutProps, Link, type LinkProps, Protected, type ProtectedProps, type Route, type RouterContextType, RouterProvider, type RouterProviderProps, useNavigate };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var a in e)l(t,a,{get:e[a],enumerable:!0})},E=(t,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!y.call(t,r)&&r!==a&&l(t,r,{get:()=>e[r],enumerable:!(o=w(e,r))||o.enumerable});return t};var M=t=>E(l({},"__esModule",{value:!0}),t);var T={};L(T,{Link:()=>C,Protected:()=>P,RouterProvider:()=>R,useNavigate:()=>d});module.exports=M(T);var s=require("react"),u=require("react/jsx-runtime"),c=typeof window<"u",v=()=>c?window.location.pathname:"/",f=(0,s.createContext)({path:v(),navigate:()=>{console.warn("RouterContext usado fuera de RouterProvider")}});function R({routes:t,children:e,layout:a}){let[o,r]=(0,s.useState)(v());(0,s.useEffect)(()=>{if(!c)return;let n=()=>r(window.location.pathname);return window.addEventListener("popstate",n),()=>window.removeEventListener("popstate",n)},[]);let i=(0,s.useCallback)(n=>{if(!c){r(n);return}if(typeof n!="string"||n.includes("javascript:")||n.includes("data:")){console.warn("MichiRouter: URL potencialmente insegura bloqueada:",n);return}window.history.pushState({},"",n),r(n)},[]),m=t.find(n=>n.path===o),g=m?m.component:e;try{return(0,u.jsx)(f.Provider,{value:{path:o,navigate:i},children:a?(0,u.jsx)(a,{children:g}):g})}catch(n){return console.error("Error en RouterProvider:",n),(0,u.jsx)("div",{children:"Error en el enrutador. Consulta la consola para m\xE1s detalles."})}}var C=({to:t,children:e,className:a,...o})=>{let{navigate:r}=(0,s.useContext)(f);return(0,u.jsx)("a",{href:t,className:a,onClick:i=>{i.preventDefault(),r(t)},...o,children:e})},d=()=>{let{navigate:t}=(0,s.useContext)(f);return t};var h=require("react");var p=require("react/jsx-runtime");function P({children:t,configObject:e}){let a=d(),o={states:e?.states||{user:null,isLoading:!1},redirectionPath:e?.redirectionPath||"/",loadingComponent:e?.loadingComponent||null,defaultMessage:e?.defaultMessage||void 0};if(!e?.states)return 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;let{user:r,isLoading:i}=o.states;return(0,
|
|
7
|
+
}`),null;let{user:r,isLoading:i}=o.states;return(0,h.useEffect)(()=>{!i&&!r&&a(o.redirectionPath)},[i,r,a,o.redirectionPath]),i?o.loadingComponent?o.loadingComponent:o.defaultMessage?(0,p.jsx)(p.Fragment,{children:o.defaultMessage}):null:r?t:null}0&&(module.exports={Link,Protected,RouterProvider,useNavigate});
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as g,createContext as v,useContext as f,useState as R,useEffect as C}from"react";import{jsx as i}from"react/jsx-runtime";var u=typeof window<"u",P=()=>u?window.location.pathname:"/",d=v({path:P(),navigate:()=>{console.warn("RouterContext usado fuera de RouterProvider")}});function h({routes:n,children:o,layout:a}){let[t,r]=R(P());C(()=>{if(!u)return;let e=()=>r(window.location.pathname);return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]);let s=g(e=>{if(!u){r(e);return}if(typeof e!="string"||e.includes("javascript:")||e.includes("data:")){console.warn("MichiRouter: URL potencialmente insegura bloqueada:",e);return}window.history.pushState({},"",e),r(e)},[]),l=n.find(e=>e.path===t),c=l?l.component:o;try{return i(d.Provider,{value:{path:t,navigate:s},children:a?i(a,{children:c}):c})}catch(e){return console.error("Error en RouterProvider:",e),i("div",{children:"Error en el enrutador. Consulta la consola para m\xE1s detalles."})}}var w=({to:n,children:o,className:a,...t})=>{let{navigate:r}=f(d);return i("a",{href:n,className:a,onClick:s=>{s.preventDefault(),r(n)},...t,children:o})},p=()=>{let{navigate:n}=f(d);return n};import{useEffect as x}from"react";import{Fragment as y,jsx as L}from"react/jsx-runtime";function m({children:n,configObject:o}){let a=p(),t={states:o?.states||{user:null,isLoading:!1},redirectionPath:o?.redirectionPath||"/",loadingComponent:o?.loadingComponent||null,defaultMessage:o?.defaultMessage||void 0};if(!o?.states)return 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;let{user:
|
|
7
|
+
}`),null;let{user:r,isLoading:s}=t.states;return x(()=>{!s&&!r&&a(t.redirectionPath)},[s,r,a,t.redirectionPath]),s?t.loadingComponent?t.loadingComponent:t.defaultMessage?L(y,{children:t.defaultMessage}):null:r?n:null}export{w as Link,m as Protected,h as RouterProvider,p as useNavigate};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arielgonzaguer/michi-router",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.1",
|
|
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",
|