@bitux/review-layer-react 0.1.0
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 +130 -0
- package/dist/CommentModal.d.ts +16 -0
- package/dist/CommentPin.d.ts +14 -0
- package/dist/ElementHighlight.d.ts +11 -0
- package/dist/Overlay.d.ts +13 -0
- package/dist/ReviewProvider.d.ts +22 -0
- package/dist/hooks/useReviewMode.d.ts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/review-layer-react.js +1658 -0
- package/dist/review-layer-react.js.map +1 -0
- package/dist/review-layer-react.umd.cjs +31 -0
- package/dist/review-layer-react.umd.cjs.map +1 -0
- package/dist/utils/api.d.ts +52 -0
- package/dist/utils/api.test.d.ts +1 -0
- package/dist/utils/cache.d.ts +12 -0
- package/dist/utils/positioning.d.ts +28 -0
- package/dist/utils/selector.d.ts +5 -0
- package/dist/utils/selector.test.d.ts +1 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @bitux/review-layer-react
|
|
2
|
+
|
|
3
|
+
SDK de React para dejar comentarios de revisión (QA, UX, PM) directamente sobre la UI en entornos de staging. Se conecta a la API [review-layer-api](https://github.com/bitux/review-layer-api).
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bitux/review-layer-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requiere React 18+ y la API backend desplegada.
|
|
12
|
+
|
|
13
|
+
## Uso
|
|
14
|
+
|
|
15
|
+
Envuelve tu aplicación con `ReviewProvider` y configura la URL de la API y el API key del proyecto:
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { ReviewProvider } from "@bitux/review-layer-react";
|
|
19
|
+
|
|
20
|
+
<ReviewProvider
|
|
21
|
+
enabled={true}
|
|
22
|
+
apiUrl="http://localhost:8000/api"
|
|
23
|
+
apiKey="dev_test_key_123"
|
|
24
|
+
>
|
|
25
|
+
<App />
|
|
26
|
+
</ReviewProvider>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- **enabled**: activa o desactiva el SDK (p. ej. `import.meta.env.DEV` o `import.meta.env.VITE_REVIEW_ENABLED`).
|
|
30
|
+
- **apiUrl**: base URL de la API (sin barra final), p. ej. `https://review-api.example.com/api`.
|
|
31
|
+
- **apiKey**: API key del proyecto (generado en el backend por equipo/proyecto).
|
|
32
|
+
|
|
33
|
+
## Atajos
|
|
34
|
+
|
|
35
|
+
- **Shift + R**: activar/desactivar modo revisión.
|
|
36
|
+
|
|
37
|
+
En modo revisión:
|
|
38
|
+
|
|
39
|
+
- El cursor pasa a cruz.
|
|
40
|
+
- Al pasar el ratón sobre un elemento se resalta con un borde.
|
|
41
|
+
- Al hacer clic en un elemento se abre el modal para escribir un comentario y asignar revisor.
|
|
42
|
+
- Los comentarios existentes se muestran como pins en la página; al hacer clic en un pin se ve el texto.
|
|
43
|
+
|
|
44
|
+
## Variables de entorno (ejemplo)
|
|
45
|
+
|
|
46
|
+
En tu app de staging (Vite):
|
|
47
|
+
|
|
48
|
+
```env
|
|
49
|
+
VITE_REVIEW_API_URL=http://localhost:8000/api
|
|
50
|
+
VITE_REVIEW_API_KEY=rl_xxx
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
<ReviewProvider
|
|
55
|
+
enabled={import.meta.env.DEV}
|
|
56
|
+
apiUrl={import.meta.env.VITE_REVIEW_API_URL ?? ""}
|
|
57
|
+
apiKey={import.meta.env.VITE_REVIEW_API_KEY ?? ""}
|
|
58
|
+
>
|
|
59
|
+
<App />
|
|
60
|
+
</ReviewProvider>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Navegación SPA (React Router, etc.)
|
|
64
|
+
|
|
65
|
+
Si usas rutas del lado cliente, al cambiar de ruta conviene volver a cargar los comentarios de la página actual. Usa el hook `useReview` y llama a `loadComments()` cuando cambie la ruta:
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import { useReview } from "@bitux/review-layer-react";
|
|
69
|
+
import { useLocation } from "react-router-dom";
|
|
70
|
+
|
|
71
|
+
function AppWithReview() {
|
|
72
|
+
const { loadComments } = useReview();
|
|
73
|
+
const location = useLocation();
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
loadComments();
|
|
77
|
+
}, [location.pathname, loadComments]);
|
|
78
|
+
|
|
79
|
+
return <Outlet />;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Probar antes de publicar
|
|
84
|
+
|
|
85
|
+
### Tests unitarios
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm run test
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Se ejecutan pruebas de `selector` y de la capa `api` (con `fetch` mockeado).
|
|
92
|
+
|
|
93
|
+
### Demo local contra la API
|
|
94
|
+
|
|
95
|
+
1. Arranca la API (en el repo `review-layer-api`):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
php artisan serve
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
2. En este repo, levanta la demo (usa el código fuente del SDK, sin publicar):
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npm run demo
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Se abre http://localhost:5174 con una miniapp envuelta en `ReviewProvider`. Por defecto usa `apiUrl=http://127.0.0.1:8000/api` y `apiKey=dev_test_key_123`. Puedes sobreescribirlos con un `.env` en la raíz o en `demo/`:
|
|
108
|
+
|
|
109
|
+
```env
|
|
110
|
+
VITE_REVIEW_API_URL=http://127.0.0.1:8000/api
|
|
111
|
+
VITE_REVIEW_API_KEY=dev_test_key_123
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
3. En la demo: **Shift + R** para activar modo revisión, haz clic en un elemento y envía un comentario. Comprueba que los pins aparecen y que en la API se crean los comentarios.
|
|
115
|
+
|
|
116
|
+
## Publicar en npm
|
|
117
|
+
|
|
118
|
+
1. **Cuenta npm**: crea una en [npmjs.com](https://www.npmjs.com/) si no tienes. Para un paquete con scope (`@bitux/review-layer-react`) la primera vez debes publicar como público (en `package.json` ya está `"publishConfig": { "access": "public" }`).
|
|
119
|
+
|
|
120
|
+
2. **Repository**: la URL del repo en `package.json` apunta a `github.com/bitux/review-layer-react`. Ajusta si el nombre del repo es otro.
|
|
121
|
+
|
|
122
|
+
3. **Build y publicar**:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npm run build
|
|
126
|
+
npm login
|
|
127
|
+
npm publish
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Las versiones siguientes: cambia `version` en `package.json` (o usa `npm version patch`) y vuelve a `npm run build` y `npm publish`.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Reviewer, CreateCommentPayload } from './utils/api';
|
|
2
|
+
|
|
3
|
+
interface CommentModalProps {
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
apiKey: string;
|
|
6
|
+
reviewers: Reviewer[];
|
|
7
|
+
position: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
payload: Omit<CreateCommentPayload, "message" | "reviewerId">;
|
|
12
|
+
onClose: () => void;
|
|
13
|
+
onSuccess: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function CommentModal({ apiUrl, apiKey, reviewers, position, payload, onClose, onSuccess, }: CommentModalProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Comment } from './utils/api';
|
|
2
|
+
|
|
3
|
+
export interface CommentPinProps {
|
|
4
|
+
comment: Comment;
|
|
5
|
+
/** Desplazamiento para no solaparse con otros pins en el mismo punto */
|
|
6
|
+
offset?: {
|
|
7
|
+
dx: number;
|
|
8
|
+
dy: number;
|
|
9
|
+
};
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
onStatusChange: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function CommentPin({ comment, offset, apiUrl, apiKey, onStatusChange, }: CommentPinProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ElementHighlightProps {
|
|
2
|
+
/** CSS selector for the element to highlight */
|
|
3
|
+
selector: string | null;
|
|
4
|
+
/** When false, render nothing */
|
|
5
|
+
active: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Finds the element by selector, tracks its bounding rect, and renders
|
|
9
|
+
* a persistent highlight overlay. Updates on scroll and resize.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ElementHighlight({ selector, active }: ElementHighlightProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Reviewer, Comment } from './utils/api';
|
|
2
|
+
|
|
3
|
+
interface OverlayProps {
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
apiKey: string;
|
|
6
|
+
reviewMode: boolean;
|
|
7
|
+
reviewers: Reviewer[];
|
|
8
|
+
comments: Comment[];
|
|
9
|
+
loadComments: () => void;
|
|
10
|
+
commentsLoadFailed?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function Overlay({ apiUrl, apiKey, reviewMode, reviewers, comments, loadComments, commentsLoadFailed, }: OverlayProps): import('react').ReactPortal | null;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Reviewer, Comment } from './utils/api';
|
|
2
|
+
|
|
3
|
+
interface ReviewContextValue {
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
apiKey: string;
|
|
6
|
+
reviewMode: boolean;
|
|
7
|
+
setReviewMode: (value: boolean) => void;
|
|
8
|
+
reviewers: Reviewer[];
|
|
9
|
+
comments: Comment[];
|
|
10
|
+
loadComments: () => void;
|
|
11
|
+
/** true si la última carga de comentarios falló (ej. backend dormido en Render) */
|
|
12
|
+
commentsLoadFailed: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function useReview(): ReviewContextValue;
|
|
15
|
+
export interface ReviewProviderProps {
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
apiUrl: string;
|
|
19
|
+
apiKey: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function ReviewProvider({ children, enabled, apiUrl, apiKey, }: ReviewProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export {};
|
package/dist/index.d.ts
ADDED