@seip/bluebird-js 0.1.7 → 0.2.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/AGENTS.md +726 -620
- package/README.md +615 -607
- package/app/models/user.js +19 -0
- package/app/resources/html/home.html +137 -0
- package/app/resources/html/layouts/main.html +54 -0
- package/app/resources/html/notFound.html +14 -0
- package/app/resources/html/terms.html +46 -0
- package/app/resources/index.html +27 -0
- package/app/resources/layouts/AppLayout.jsx +89 -0
- package/app/resources/main.jsx +18 -0
- package/app/resources/pages/Dashboard.jsx +98 -0
- package/app/resources/pages/Home.jsx +140 -0
- package/app/resources/pages/Login.jsx +35 -0
- package/app/resources/pages/NotFound.jsx +16 -0
- package/app/resources/pages/Register.jsx +55 -0
- package/app/resources/routes.jsx +54 -0
- package/app/resources/spa.js +67 -0
- package/app/resources/styles.css +9 -0
- package/app/routes/api.js +85 -50
- package/app/routes/auth.js +209 -0
- package/app/routes/web.js +59 -47
- package/core/ai.js +30 -10
- package/core/app.d.ts +2 -18
- package/core/app.js +987 -801
- package/core/auth.d.ts +2 -13
- package/core/auth.js +444 -326
- package/core/cli/build.js +37 -0
- package/core/cli/dev.js +155 -0
- package/core/cli/doctor.js +37 -2
- package/core/cli/export.js +191 -0
- package/core/cli/init.js +91 -322
- package/core/cli/nginx.js +1 -1
- package/core/cli/templates.js +139 -0
- package/core/cli/view.js +98 -161
- package/core/config.js +44 -2
- package/core/csrf.js +156 -24
- package/core/database.js +1184 -1131
- package/core/debug.js +1 -1
- package/core/html.js +8 -1
- package/core/index.d.ts +126 -310
- package/core/paths.js +55 -0
- package/core/ratelimit.js +10 -1
- package/core/react/client/api.js +237 -0
- package/core/react/client/auth.js +236 -0
- package/core/react/client/components.js +1321 -0
- package/core/react/client/i18n.js +338 -0
- package/core/react/client/index.d.ts +249 -0
- package/core/react/client/index.js +49 -0
- package/core/react/client/router.js +26 -0
- package/core/react/client/theme.css +512 -0
- package/core/render-cache.js +250 -212
- package/core/render.d.ts +25 -21
- package/core/render.js +738 -736
- package/core/router.d.ts +2 -3
- package/core/router.js +171 -171
- package/core/seo.js +10 -0
- package/core/spa.js +599 -0
- package/core/view-loader.js +155 -613
- package/core/vite-plugin.d.ts +18 -0
- package/core/vite-plugin.js +162 -0
- package/core/vite.js +250 -145
- package/index.js +22 -18
- package/jsconfig.json +5 -3
- package/package.json +114 -92
- package/production.md +8 -3
- package/public/js/bluebird.js +1160 -0
- package/templates/_auth/app/database.js +19 -0
- package/templates/_auth/app/models/user.js +22 -0
- package/templates/_auth/app/routes/auth-router.js +304 -0
- package/templates/_base/app/resources/html/layouts/main.html +55 -0
- package/templates/_base/app/resources/html/notFound.html +14 -0
- package/templates/_base/app/resources/index.html +27 -0
- package/templates/_base/app/resources/styles.css +9 -0
- package/templates/api/app/models/note.js +18 -0
- package/templates/api/app/routes/api.js +82 -0
- package/templates/api/app/routes/auth.js +11 -0
- package/templates/api/index.js +19 -0
- package/templates/api/template.json +13 -0
- package/templates/auth/app/mail.js +11 -0
- package/templates/auth/app/models/password_reset.js +18 -0
- package/templates/auth/app/resources/html/home.html +21 -0
- package/templates/auth/app/resources/html/partials/nav.html +2 -0
- package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
- package/templates/auth/app/resources/main.jsx +18 -0
- package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
- package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
- package/templates/auth/app/resources/pages/Login.jsx +36 -0
- package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
- package/templates/auth/app/resources/pages/Profile.jsx +99 -0
- package/templates/auth/app/resources/pages/Register.jsx +50 -0
- package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
- package/templates/auth/app/resources/routes.jsx +54 -0
- package/templates/auth/app/resources/spa.js +29 -0
- package/templates/auth/app/routes/api.js +17 -0
- package/templates/auth/app/routes/auth.js +13 -0
- package/templates/auth/app/routes/web.js +21 -0
- package/templates/auth/index.js +19 -0
- package/templates/auth/template.json +15 -0
- package/templates/blank/app/models/.gitkeep +0 -0
- package/templates/blank/app/resources/html/home.html +27 -0
- package/templates/blank/app/resources/html/partials/nav.html +1 -0
- package/templates/blank/app/resources/main.jsx +16 -0
- package/templates/blank/app/resources/pages/Home.jsx +42 -0
- package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
- package/templates/blank/app/resources/routes.jsx +15 -0
- package/templates/blank/app/resources/spa.js +24 -0
- package/templates/blank/app/routes/api.js +11 -0
- package/templates/blank/app/routes/web.js +21 -0
- package/templates/blank/index.js +13 -0
- package/templates/blank/template.json +12 -0
- package/templates/blog/app/lib/blog.js +149 -0
- package/templates/blog/app/models/post.js +22 -0
- package/templates/blog/app/resources/html/home.html +28 -0
- package/templates/blog/app/resources/html/not-found.html +5 -0
- package/templates/blog/app/resources/html/partials/nav.html +2 -0
- package/templates/blog/app/resources/html/partials/post-card.html +9 -0
- package/templates/blog/app/resources/html/post.html +8 -0
- package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
- package/templates/blog/app/resources/main.jsx +18 -0
- package/templates/blog/app/resources/pages/Login.jsx +31 -0
- package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
- package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
- package/templates/blog/app/resources/pages/Posts.jsx +83 -0
- package/templates/blog/app/resources/pages/Register.jsx +43 -0
- package/templates/blog/app/resources/routes.jsx +51 -0
- package/templates/blog/app/resources/spa.js +25 -0
- package/templates/blog/app/resources/styles.css +40 -0
- package/templates/blog/app/routes/api.js +77 -0
- package/templates/blog/app/routes/auth.js +10 -0
- package/templates/blog/app/routes/web.js +114 -0
- package/templates/blog/index.js +21 -0
- package/templates/blog/template.json +14 -0
- package/vite.config.js +11 -0
- package/app/views/components/Header.jsx +0 -42
- package/app/views/components/LiveCounter.jsx +0 -67
- package/app/views/layouts/main/view.jsx +0 -201
- package/app/views/legal/terms.html +0 -29
- package/app/views/pages/about.jsx +0 -98
- package/app/views/pages/dashboard.jsx +0 -278
- package/app/views/pages/index.jsx +0 -123
- package/app/views/pages/login.jsx +0 -141
- package/core/actions.d.ts +0 -4
- package/core/actions.js +0 -355
- package/core/jsx.d.ts +0 -38
- package/core/jsx.js +0 -1597
- package/core/vite.d.ts +0 -3
- package/public/js/bluebird-client.js +0 -3265
- package/public/js/tailwind.js +0 -8
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Built-in UI strings for the React components (kept identical to `public/js/bluebird.js`).
|
|
5
|
+
* Keys missing in a language fall back to English.
|
|
6
|
+
* @type {Record<string, Record<string, string>>}
|
|
7
|
+
*/
|
|
8
|
+
export const MESSAGES = {
|
|
9
|
+
en: {
|
|
10
|
+
"toast.info": "Info",
|
|
11
|
+
"toast.success": "Success",
|
|
12
|
+
"toast.warning": "Warning",
|
|
13
|
+
"toast.error": "Error",
|
|
14
|
+
"toast.danger": "Alert",
|
|
15
|
+
"toast.region": "Notifications",
|
|
16
|
+
"toast.dismiss": "Dismiss notification",
|
|
17
|
+
"theme.toLight": "Switch to light theme",
|
|
18
|
+
"theme.toDark": "Switch to dark theme",
|
|
19
|
+
"theme.light": "Light",
|
|
20
|
+
"theme.dark": "Dark",
|
|
21
|
+
"dialog.close": "Close",
|
|
22
|
+
"dialog.label": "Dialog",
|
|
23
|
+
"drawer.label": "Panel",
|
|
24
|
+
"carousel.label": "Featured showcase",
|
|
25
|
+
"carousel.role": "carousel",
|
|
26
|
+
"carousel.slide": "slide",
|
|
27
|
+
"carousel.slides": "Slides",
|
|
28
|
+
"carousel.choose": "Choose a slide",
|
|
29
|
+
"carousel.prev": "Previous slide",
|
|
30
|
+
"carousel.next": "Next slide",
|
|
31
|
+
"carousel.prevShort": "Prev",
|
|
32
|
+
"carousel.nextShort": "Next",
|
|
33
|
+
"carousel.goTo": "Go to slide {n}",
|
|
34
|
+
"carousel.position": "{n} of {total}",
|
|
35
|
+
"carousel.status": "Slide {n} of {total}",
|
|
36
|
+
"loading": "Loading...",
|
|
37
|
+
"request.failed": "Request failed",
|
|
38
|
+
"request.network": "Network error",
|
|
39
|
+
"form.invalid": "Please check this field.",
|
|
40
|
+
"form.validation": "Validation error",
|
|
41
|
+
"value.invalid": "Invalid value",
|
|
42
|
+
"copy.done": "Copied to clipboard",
|
|
43
|
+
"auth.deniedTitle": "Access denied",
|
|
44
|
+
"auth.deniedText": "You do not have permission to view this section.",
|
|
45
|
+
},
|
|
46
|
+
es: {
|
|
47
|
+
"toast.info": "Info",
|
|
48
|
+
"toast.success": "Correcto",
|
|
49
|
+
"toast.warning": "Cuidado",
|
|
50
|
+
"toast.error": "Error",
|
|
51
|
+
"toast.danger": "Alerta",
|
|
52
|
+
"toast.region": "Notificaciones",
|
|
53
|
+
"toast.dismiss": "Cerrar notificación",
|
|
54
|
+
"theme.toLight": "Cambiar a tema claro",
|
|
55
|
+
"theme.toDark": "Cambiar a tema oscuro",
|
|
56
|
+
"theme.light": "Claro",
|
|
57
|
+
"theme.dark": "Oscuro",
|
|
58
|
+
"dialog.close": "Cerrar",
|
|
59
|
+
"dialog.label": "Diálogo",
|
|
60
|
+
"drawer.label": "Panel",
|
|
61
|
+
"carousel.label": "Destacados",
|
|
62
|
+
"carousel.role": "carrusel",
|
|
63
|
+
"carousel.slide": "diapositiva",
|
|
64
|
+
"carousel.slides": "Diapositivas",
|
|
65
|
+
"carousel.choose": "Elegir diapositiva",
|
|
66
|
+
"carousel.prev": "Diapositiva anterior",
|
|
67
|
+
"carousel.next": "Diapositiva siguiente",
|
|
68
|
+
"carousel.prevShort": "Anterior",
|
|
69
|
+
"carousel.nextShort": "Siguiente",
|
|
70
|
+
"carousel.goTo": "Ir a la diapositiva {n}",
|
|
71
|
+
"carousel.position": "{n} de {total}",
|
|
72
|
+
"carousel.status": "Diapositiva {n} de {total}",
|
|
73
|
+
"loading": "Cargando...",
|
|
74
|
+
"request.failed": "La solicitud falló",
|
|
75
|
+
"request.network": "Error de red",
|
|
76
|
+
"form.invalid": "Revisa este campo.",
|
|
77
|
+
"form.validation": "Error de validación",
|
|
78
|
+
"value.invalid": "Valor inválido",
|
|
79
|
+
"copy.done": "Copiado al portapapeles",
|
|
80
|
+
"auth.deniedTitle": "Acceso denegado",
|
|
81
|
+
"auth.deniedText": "No tienes permiso para ver esta sección.",
|
|
82
|
+
},
|
|
83
|
+
pt: {
|
|
84
|
+
"toast.info": "Info",
|
|
85
|
+
"toast.success": "Sucesso",
|
|
86
|
+
"toast.warning": "Atenção",
|
|
87
|
+
"toast.error": "Erro",
|
|
88
|
+
"toast.danger": "Alerta",
|
|
89
|
+
"toast.region": "Notificações",
|
|
90
|
+
"toast.dismiss": "Fechar notificação",
|
|
91
|
+
"theme.toLight": "Mudar para o tema claro",
|
|
92
|
+
"theme.toDark": "Mudar para o tema escuro",
|
|
93
|
+
"theme.light": "Claro",
|
|
94
|
+
"theme.dark": "Escuro",
|
|
95
|
+
"dialog.close": "Fechar",
|
|
96
|
+
"dialog.label": "Diálogo",
|
|
97
|
+
"drawer.label": "Painel",
|
|
98
|
+
"carousel.label": "Destaques",
|
|
99
|
+
"carousel.role": "carrossel",
|
|
100
|
+
"carousel.slide": "slide",
|
|
101
|
+
"carousel.slides": "Slides",
|
|
102
|
+
"carousel.choose": "Escolher slide",
|
|
103
|
+
"carousel.prev": "Slide anterior",
|
|
104
|
+
"carousel.next": "Próximo slide",
|
|
105
|
+
"carousel.prevShort": "Anterior",
|
|
106
|
+
"carousel.nextShort": "Próximo",
|
|
107
|
+
"carousel.goTo": "Ir para o slide {n}",
|
|
108
|
+
"carousel.position": "{n} de {total}",
|
|
109
|
+
"carousel.status": "Slide {n} de {total}",
|
|
110
|
+
"loading": "Carregando...",
|
|
111
|
+
"request.failed": "A solicitação falhou",
|
|
112
|
+
"request.network": "Erro de rede",
|
|
113
|
+
"form.invalid": "Verifique este campo.",
|
|
114
|
+
"form.validation": "Erro de validação",
|
|
115
|
+
"value.invalid": "Valor inválido",
|
|
116
|
+
"copy.done": "Copiado para a área de transferência",
|
|
117
|
+
"auth.deniedTitle": "Acesso negado",
|
|
118
|
+
"auth.deniedText": "Você não tem permissão para ver esta seção.",
|
|
119
|
+
},
|
|
120
|
+
fr: {
|
|
121
|
+
"toast.info": "Info",
|
|
122
|
+
"toast.success": "Succès",
|
|
123
|
+
"toast.warning": "Attention",
|
|
124
|
+
"toast.error": "Erreur",
|
|
125
|
+
"toast.danger": "Alerte",
|
|
126
|
+
"toast.region": "Notifications",
|
|
127
|
+
"toast.dismiss": "Fermer la notification",
|
|
128
|
+
"theme.toLight": "Passer au thème clair",
|
|
129
|
+
"theme.toDark": "Passer au thème sombre",
|
|
130
|
+
"theme.light": "Clair",
|
|
131
|
+
"theme.dark": "Sombre",
|
|
132
|
+
"dialog.close": "Fermer",
|
|
133
|
+
"dialog.label": "Boîte de dialogue",
|
|
134
|
+
"drawer.label": "Panneau",
|
|
135
|
+
"carousel.label": "À la une",
|
|
136
|
+
"carousel.role": "carrousel",
|
|
137
|
+
"carousel.slide": "diapositive",
|
|
138
|
+
"carousel.slides": "Diapositives",
|
|
139
|
+
"carousel.choose": "Choisir une diapositive",
|
|
140
|
+
"carousel.prev": "Diapositive précédente",
|
|
141
|
+
"carousel.next": "Diapositive suivante",
|
|
142
|
+
"carousel.prevShort": "Préc.",
|
|
143
|
+
"carousel.nextShort": "Suiv.",
|
|
144
|
+
"carousel.goTo": "Aller à la diapositive {n}",
|
|
145
|
+
"carousel.position": "{n} sur {total}",
|
|
146
|
+
"carousel.status": "Diapositive {n} sur {total}",
|
|
147
|
+
"loading": "Chargement...",
|
|
148
|
+
"request.failed": "La requête a échoué",
|
|
149
|
+
"request.network": "Erreur réseau",
|
|
150
|
+
"form.invalid": "Vérifiez ce champ.",
|
|
151
|
+
"form.validation": "Erreur de validation",
|
|
152
|
+
"value.invalid": "Valeur invalide",
|
|
153
|
+
"copy.done": "Copié dans le presse-papiers",
|
|
154
|
+
"auth.deniedTitle": "Accès refusé",
|
|
155
|
+
"auth.deniedText": "Vous n'avez pas l'autorisation de voir cette section.",
|
|
156
|
+
},
|
|
157
|
+
de: {
|
|
158
|
+
"toast.info": "Info",
|
|
159
|
+
"toast.success": "Erfolg",
|
|
160
|
+
"toast.warning": "Achtung",
|
|
161
|
+
"toast.error": "Fehler",
|
|
162
|
+
"toast.danger": "Warnung",
|
|
163
|
+
"toast.region": "Benachrichtigungen",
|
|
164
|
+
"toast.dismiss": "Benachrichtigung schließen",
|
|
165
|
+
"theme.toLight": "Zum hellen Design wechseln",
|
|
166
|
+
"theme.toDark": "Zum dunklen Design wechseln",
|
|
167
|
+
"theme.light": "Hell",
|
|
168
|
+
"theme.dark": "Dunkel",
|
|
169
|
+
"dialog.close": "Schließen",
|
|
170
|
+
"dialog.label": "Dialog",
|
|
171
|
+
"drawer.label": "Seitenleiste",
|
|
172
|
+
"carousel.label": "Highlights",
|
|
173
|
+
"carousel.role": "Karussell",
|
|
174
|
+
"carousel.slide": "Folie",
|
|
175
|
+
"carousel.slides": "Folien",
|
|
176
|
+
"carousel.choose": "Folie auswählen",
|
|
177
|
+
"carousel.prev": "Vorherige Folie",
|
|
178
|
+
"carousel.next": "Nächste Folie",
|
|
179
|
+
"carousel.prevShort": "Zurück",
|
|
180
|
+
"carousel.nextShort": "Weiter",
|
|
181
|
+
"carousel.goTo": "Zu Folie {n}",
|
|
182
|
+
"carousel.position": "{n} von {total}",
|
|
183
|
+
"carousel.status": "Folie {n} von {total}",
|
|
184
|
+
"loading": "Wird geladen...",
|
|
185
|
+
"request.failed": "Anfrage fehlgeschlagen",
|
|
186
|
+
"request.network": "Netzwerkfehler",
|
|
187
|
+
"form.invalid": "Bitte überprüfe dieses Feld.",
|
|
188
|
+
"form.validation": "Validierungsfehler",
|
|
189
|
+
"value.invalid": "Ungültiger Wert",
|
|
190
|
+
"copy.done": "In die Zwischenablage kopiert",
|
|
191
|
+
"auth.deniedTitle": "Zugriff verweigert",
|
|
192
|
+
"auth.deniedText": "Du hast keine Berechtigung, diesen Bereich zu sehen.",
|
|
193
|
+
},
|
|
194
|
+
it: {
|
|
195
|
+
"toast.info": "Info",
|
|
196
|
+
"toast.success": "Fatto",
|
|
197
|
+
"toast.warning": "Attenzione",
|
|
198
|
+
"toast.error": "Errore",
|
|
199
|
+
"toast.danger": "Avviso",
|
|
200
|
+
"toast.region": "Notifiche",
|
|
201
|
+
"toast.dismiss": "Chiudi notifica",
|
|
202
|
+
"theme.toLight": "Passa al tema chiaro",
|
|
203
|
+
"theme.toDark": "Passa al tema scuro",
|
|
204
|
+
"theme.light": "Chiaro",
|
|
205
|
+
"theme.dark": "Scuro",
|
|
206
|
+
"dialog.close": "Chiudi",
|
|
207
|
+
"dialog.label": "Finestra di dialogo",
|
|
208
|
+
"drawer.label": "Pannello",
|
|
209
|
+
"carousel.label": "In evidenza",
|
|
210
|
+
"carousel.role": "carosello",
|
|
211
|
+
"carousel.slide": "slide",
|
|
212
|
+
"carousel.slides": "Slide",
|
|
213
|
+
"carousel.choose": "Scegli una slide",
|
|
214
|
+
"carousel.prev": "Slide precedente",
|
|
215
|
+
"carousel.next": "Slide successiva",
|
|
216
|
+
"carousel.prevShort": "Prec.",
|
|
217
|
+
"carousel.nextShort": "Succ.",
|
|
218
|
+
"carousel.goTo": "Vai alla slide {n}",
|
|
219
|
+
"carousel.position": "{n} di {total}",
|
|
220
|
+
"carousel.status": "Slide {n} di {total}",
|
|
221
|
+
"loading": "Caricamento...",
|
|
222
|
+
"request.failed": "Richiesta non riuscita",
|
|
223
|
+
"request.network": "Errore di rete",
|
|
224
|
+
"form.invalid": "Controlla questo campo.",
|
|
225
|
+
"form.validation": "Errore di convalida",
|
|
226
|
+
"value.invalid": "Valore non valido",
|
|
227
|
+
"copy.done": "Copiato negli appunti",
|
|
228
|
+
"auth.deniedTitle": "Accesso negato",
|
|
229
|
+
"auth.deniedText": "Non hai il permesso di vedere questa sezione.",
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/** @type {Record<string, Record<string, string>>} */
|
|
234
|
+
const custom = {};
|
|
235
|
+
/** @type {string|null} */
|
|
236
|
+
let forcedLocale = null;
|
|
237
|
+
let version = 0;
|
|
238
|
+
const listeners = new Set();
|
|
239
|
+
let observer = null;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Notifies subscribed components that the locale or messages changed.
|
|
243
|
+
*/
|
|
244
|
+
function emit() {
|
|
245
|
+
version++;
|
|
246
|
+
for (const fn of listeners) fn();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Returns the active UI locale: `setLocale()` override, then `<html lang>`, then the browser language, then `"en"`.
|
|
251
|
+
* @returns {string}
|
|
252
|
+
*/
|
|
253
|
+
export function getLocale() {
|
|
254
|
+
if (forcedLocale) return forcedLocale;
|
|
255
|
+
if (typeof document !== "undefined" && document.documentElement?.lang) return document.documentElement.lang;
|
|
256
|
+
if (typeof navigator !== "undefined" && navigator.language) return navigator.language;
|
|
257
|
+
return "en";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Forces the UI locale for all components (`null` returns to `<html lang>` detection).
|
|
262
|
+
* @param {string|null} locale
|
|
263
|
+
*/
|
|
264
|
+
export function setLocale(locale) {
|
|
265
|
+
forcedLocale = locale ? String(locale) : null;
|
|
266
|
+
emit();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Adds or overrides UI strings for a language, e.g. `addMessages("es", { "toast.warning": "Atención" })`
|
|
271
|
+
* or a new language such as `addMessages("ja", { ... })`.
|
|
272
|
+
* @param {string} locale
|
|
273
|
+
* @param {Record<string, string>} messages
|
|
274
|
+
*/
|
|
275
|
+
export function addMessages(locale, messages) {
|
|
276
|
+
const key = String(locale).toLowerCase();
|
|
277
|
+
custom[key] = { ...(custom[key] || {}), ...messages };
|
|
278
|
+
emit();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Resolves a message for a locale: exact tag (`pt-br`), then base language (`pt`), then English.
|
|
283
|
+
* @param {string} key
|
|
284
|
+
* @param {string} locale
|
|
285
|
+
* @returns {string|undefined}
|
|
286
|
+
*/
|
|
287
|
+
function lookup(key, locale) {
|
|
288
|
+
const full = String(locale || "en").toLowerCase();
|
|
289
|
+
const base = full.split("-")[0];
|
|
290
|
+
for (const tag of [full, base]) {
|
|
291
|
+
if (custom[tag]?.[key] !== undefined) return custom[tag][key];
|
|
292
|
+
if (MESSAGES[tag]?.[key] !== undefined) return MESSAGES[tag][key];
|
|
293
|
+
}
|
|
294
|
+
return custom.en?.[key] ?? MESSAGES.en[key];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Translates a UI string key for the active locale, replacing `{name}` placeholders.
|
|
299
|
+
* @param {string} key
|
|
300
|
+
* @param {Record<string, string|number>} [params]
|
|
301
|
+
* @param {string} [locale]
|
|
302
|
+
* @returns {string}
|
|
303
|
+
*/
|
|
304
|
+
export function t(key, params, locale) {
|
|
305
|
+
const message = lookup(key, locale || getLocale()) ?? key;
|
|
306
|
+
if (!params) return message;
|
|
307
|
+
return message.replace(/\{(\w+)\}/g, (match, name) => (params[name] !== undefined ? String(params[name]) : match));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Subscribes to locale changes, including direct changes to `<html lang>`.
|
|
312
|
+
* @param {Function} fn
|
|
313
|
+
* @returns {Function}
|
|
314
|
+
*/
|
|
315
|
+
function subscribe(fn) {
|
|
316
|
+
listeners.add(fn);
|
|
317
|
+
if (!observer && typeof MutationObserver !== "undefined" && typeof document !== "undefined") {
|
|
318
|
+
observer = new MutationObserver(emit);
|
|
319
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] });
|
|
320
|
+
}
|
|
321
|
+
return () => {
|
|
322
|
+
listeners.delete(fn);
|
|
323
|
+
if (listeners.size === 0 && observer) {
|
|
324
|
+
observer.disconnect();
|
|
325
|
+
observer = null;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* React hook returning the active locale and a bound `t()`; re-renders when the locale or messages change.
|
|
332
|
+
* @returns {{ locale: string, t: (key: string, params?: Record<string, string|number>) => string, setLocale: typeof setLocale }}
|
|
333
|
+
*/
|
|
334
|
+
export function useLocale() {
|
|
335
|
+
useSyncExternalStore(subscribe, () => version, () => 0);
|
|
336
|
+
const locale = getLocale();
|
|
337
|
+
return { locale, t: (key, params) => t(key, params, locale), setLocale };
|
|
338
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnchorHTMLAttributes,
|
|
3
|
+
ButtonHTMLAttributes,
|
|
4
|
+
ComponentType,
|
|
5
|
+
FormHTMLAttributes,
|
|
6
|
+
InputHTMLAttributes,
|
|
7
|
+
ReactNode,
|
|
8
|
+
SelectHTMLAttributes,
|
|
9
|
+
TextareaHTMLAttributes,
|
|
10
|
+
} from "react";
|
|
11
|
+
|
|
12
|
+
export function setApiBaseUrl(baseUrl: string): void;
|
|
13
|
+
export function getApiBaseUrl(): string;
|
|
14
|
+
export function getCsrfToken(): string;
|
|
15
|
+
|
|
16
|
+
export interface BluebirdExportConfig {
|
|
17
|
+
apiUrl?: string;
|
|
18
|
+
router?: "hash" | "browser" | "memory";
|
|
19
|
+
basename?: string;
|
|
20
|
+
auth?: "token" | "cookie";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getExportConfig(): BluebirdExportConfig | null;
|
|
24
|
+
export function isExported(): boolean;
|
|
25
|
+
export function configureApi(options?: { baseUrl?: string; auth?: "cookie" | "token" }): void;
|
|
26
|
+
export function getAuthMode(): "cookie" | "token";
|
|
27
|
+
export function getAuthToken(): string;
|
|
28
|
+
export function setAuthToken(token: string | null): void;
|
|
29
|
+
|
|
30
|
+
export function createRouter(
|
|
31
|
+
routes: import("react-router").RouteObject[],
|
|
32
|
+
options?: { basename?: string; mode?: "browser" | "hash" | "memory"; [key: string]: any }
|
|
33
|
+
): ReturnType<typeof import("react-router").createBrowserRouter>;
|
|
34
|
+
|
|
35
|
+
export class ApiError extends Error {
|
|
36
|
+
status: number;
|
|
37
|
+
data: any;
|
|
38
|
+
errors: Record<string, string | string[]> | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ApiRequestOptions {
|
|
42
|
+
method?: string;
|
|
43
|
+
body?: any;
|
|
44
|
+
headers?: Record<string, string>;
|
|
45
|
+
credentials?: RequestCredentials;
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ApiClient {
|
|
50
|
+
<T = any>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
51
|
+
get<T = any>(url: string, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
|
|
52
|
+
post<T = any>(url: string, body?: any, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
|
|
53
|
+
put<T = any>(url: string, body?: any, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
|
|
54
|
+
patch<T = any>(url: string, body?: any, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
|
|
55
|
+
delete<T = any>(url: string, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const api: ApiClient;
|
|
59
|
+
export const request: ApiClient;
|
|
60
|
+
|
|
61
|
+
export interface AuthUser {
|
|
62
|
+
id: number | string;
|
|
63
|
+
name: string;
|
|
64
|
+
email: string;
|
|
65
|
+
role?: string;
|
|
66
|
+
roles?: string[];
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AuthEndpoints {
|
|
71
|
+
me?: string;
|
|
72
|
+
login?: string;
|
|
73
|
+
register?: string;
|
|
74
|
+
logout?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface AuthContextValue {
|
|
78
|
+
user: AuthUser | null;
|
|
79
|
+
loading: boolean;
|
|
80
|
+
authenticated: boolean;
|
|
81
|
+
registerEnabled: boolean;
|
|
82
|
+
login: (credentials: Record<string, any>) => Promise<AuthUser | null>;
|
|
83
|
+
register: (payload: Record<string, any>) => Promise<AuthUser | null>;
|
|
84
|
+
logout: () => Promise<void>;
|
|
85
|
+
refresh: (signal?: AbortSignal) => Promise<AuthUser | null>;
|
|
86
|
+
setUser: (user: AuthUser | null) => void;
|
|
87
|
+
hasRole: (roles?: string | string[] | null) => boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function matchUserRole(user: AuthUser | null | undefined, roles?: string | string[] | null): boolean;
|
|
91
|
+
export function AuthProvider(props: {
|
|
92
|
+
endpoints?: AuthEndpoints;
|
|
93
|
+
initialUser?: AuthUser | null;
|
|
94
|
+
children?: ReactNode;
|
|
95
|
+
}): ReactNode;
|
|
96
|
+
export function useAuth(): AuthContextValue;
|
|
97
|
+
export function RequireAuth(props?: {
|
|
98
|
+
roles?: string | string[];
|
|
99
|
+
redirectTo?: string;
|
|
100
|
+
forbiddenRedirect?: string;
|
|
101
|
+
fallback?: ReactNode;
|
|
102
|
+
forbidden?: ReactNode;
|
|
103
|
+
children?: ReactNode;
|
|
104
|
+
}): ReactNode;
|
|
105
|
+
export function GuestOnly(props?: {
|
|
106
|
+
redirectTo?: string;
|
|
107
|
+
fallback?: ReactNode;
|
|
108
|
+
children?: ReactNode;
|
|
109
|
+
}): ReactNode;
|
|
110
|
+
|
|
111
|
+
/** Built-in UI strings by language (`en`, `es`, `pt`, `fr`, `de`, `it`). */
|
|
112
|
+
export const MESSAGES: Record<string, Record<string, string>>;
|
|
113
|
+
/** Active UI locale: `setLocale()` override, then `<html lang>`, then the browser language. */
|
|
114
|
+
export function getLocale(): string;
|
|
115
|
+
/** Forces the UI locale for all components (`null` returns to `<html lang>` detection). */
|
|
116
|
+
export function setLocale(locale: string | null): void;
|
|
117
|
+
/** Adds or overrides UI strings for a language, e.g. `addMessages("es", { "toast.warning": "Atención" })`. */
|
|
118
|
+
export function addMessages(locale: string, messages: Record<string, string>): void;
|
|
119
|
+
/** Translates a UI string key, replacing `{name}` placeholders. */
|
|
120
|
+
export function t(key: string, params?: Record<string, string | number>, locale?: string): string;
|
|
121
|
+
/** Hook that re-renders when the locale or messages change. */
|
|
122
|
+
export function useLocale(): {
|
|
123
|
+
locale: string;
|
|
124
|
+
t: (key: string, params?: Record<string, string | number>) => string;
|
|
125
|
+
setLocale: (locale: string | null) => void;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export function cn(...parts: any[]): string;
|
|
129
|
+
export function useTheme(): {
|
|
130
|
+
theme: "dark" | "light";
|
|
131
|
+
isDark: boolean;
|
|
132
|
+
setTheme: (mode: "dark" | "light") => void;
|
|
133
|
+
toggleTheme: () => void;
|
|
134
|
+
};
|
|
135
|
+
export function ThemeToggle(props?: { className?: string }): ReactNode;
|
|
136
|
+
|
|
137
|
+
export interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
|
|
138
|
+
href?: string;
|
|
139
|
+
to?: string;
|
|
140
|
+
activeClassName?: string;
|
|
141
|
+
inactiveClassName?: string;
|
|
142
|
+
exact?: boolean;
|
|
143
|
+
replace?: boolean;
|
|
144
|
+
}
|
|
145
|
+
export const Link: ComponentType<LinkProps>;
|
|
146
|
+
|
|
147
|
+
export type ButtonVariant = "primary" | "secondary" | "outline" | "ghost" | "danger" | "link";
|
|
148
|
+
export type ButtonSize = "sm" | "md" | "lg" | "icon";
|
|
149
|
+
/** Button classes (`btn btn-<variant> btn-<size>`) to style links or other elements like a Button. */
|
|
150
|
+
export function buttonVariants(options?: { variant?: ButtonVariant; size?: ButtonSize; className?: string }): string;
|
|
151
|
+
|
|
152
|
+
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
153
|
+
variant?: ButtonVariant;
|
|
154
|
+
size?: ButtonSize;
|
|
155
|
+
loading?: boolean;
|
|
156
|
+
loadingText?: ReactNode;
|
|
157
|
+
url?: string;
|
|
158
|
+
method?: string;
|
|
159
|
+
payload?: Record<string, any>;
|
|
160
|
+
confirm?: string;
|
|
161
|
+
onSuccess?: (data: any) => void;
|
|
162
|
+
onError?: (error: ApiError) => void;
|
|
163
|
+
}
|
|
164
|
+
export const Button: ComponentType<ButtonProps>;
|
|
165
|
+
export function SubmitButton(props: ButtonProps): ReactNode;
|
|
166
|
+
export function useFormState(): { errors: Record<string, string | string[]>; pending: boolean };
|
|
167
|
+
|
|
168
|
+
export interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, "action" | "onError"> {
|
|
169
|
+
url?: string;
|
|
170
|
+
method?: string;
|
|
171
|
+
data?: Record<string, any> | ((values: Record<string, any>) => Record<string, any>);
|
|
172
|
+
onSubmitRequest?: (values: Record<string, any> | FormData) => Promise<any>;
|
|
173
|
+
onBefore?: (values: Record<string, any>) => boolean | void;
|
|
174
|
+
onSuccess?: (data: any, values: Record<string, any>) => void;
|
|
175
|
+
onError?: (error: ApiError) => void;
|
|
176
|
+
resetOnSuccess?: boolean;
|
|
177
|
+
successMessage?: string;
|
|
178
|
+
}
|
|
179
|
+
export function Form(props: FormProps): ReactNode;
|
|
180
|
+
|
|
181
|
+
interface FieldProps {
|
|
182
|
+
label?: ReactNode;
|
|
183
|
+
hint?: ReactNode;
|
|
184
|
+
error?: string;
|
|
185
|
+
wrapperClassName?: string;
|
|
186
|
+
}
|
|
187
|
+
export const Input: ComponentType<InputHTMLAttributes<HTMLInputElement> & FieldProps>;
|
|
188
|
+
export const Textarea: ComponentType<TextareaHTMLAttributes<HTMLTextAreaElement> & FieldProps>;
|
|
189
|
+
export const Select: ComponentType<SelectHTMLAttributes<HTMLSelectElement> & FieldProps>;
|
|
190
|
+
|
|
191
|
+
export function Card(props: {
|
|
192
|
+
title?: ReactNode;
|
|
193
|
+
description?: ReactNode;
|
|
194
|
+
footer?: ReactNode;
|
|
195
|
+
variant?: "default" | "glass";
|
|
196
|
+
className?: string;
|
|
197
|
+
children?: ReactNode;
|
|
198
|
+
}): ReactNode;
|
|
199
|
+
export function Badge(props: {
|
|
200
|
+
tone?: "default" | "info" | "success" | "warning" | "danger" | "error";
|
|
201
|
+
soft?: boolean;
|
|
202
|
+
className?: string;
|
|
203
|
+
children?: ReactNode;
|
|
204
|
+
}): ReactNode;
|
|
205
|
+
export function Carousel(props: {
|
|
206
|
+
slides: Array<{ title?: ReactNode; description?: ReactNode; badge?: ReactNode; content?: ReactNode }>;
|
|
207
|
+
autoPlayMs?: number;
|
|
208
|
+
loop?: boolean;
|
|
209
|
+
label?: string;
|
|
210
|
+
className?: string;
|
|
211
|
+
}): ReactNode;
|
|
212
|
+
export function Modal(props: {
|
|
213
|
+
open: boolean;
|
|
214
|
+
onClose: () => void;
|
|
215
|
+
title?: ReactNode;
|
|
216
|
+
description?: ReactNode;
|
|
217
|
+
footer?: ReactNode;
|
|
218
|
+
size?: "sm" | "md" | "lg" | "xl";
|
|
219
|
+
className?: string;
|
|
220
|
+
children?: ReactNode;
|
|
221
|
+
}): ReactNode;
|
|
222
|
+
export function Drawer(props: {
|
|
223
|
+
open: boolean;
|
|
224
|
+
onClose: () => void;
|
|
225
|
+
side?: "left" | "right" | "top" | "bottom";
|
|
226
|
+
title?: ReactNode;
|
|
227
|
+
className?: string;
|
|
228
|
+
children?: ReactNode;
|
|
229
|
+
}): ReactNode;
|
|
230
|
+
export function Skeleton(props?: { className?: string; style?: Record<string, any> }): ReactNode;
|
|
231
|
+
export function PageSkeleton(): ReactNode;
|
|
232
|
+
export function ProgressBar(props?: { active?: boolean }): ReactNode;
|
|
233
|
+
export function Spinner(props?: { className?: string }): ReactNode;
|
|
234
|
+
export function Toaster(): ReactNode;
|
|
235
|
+
|
|
236
|
+
export interface ToastOptions {
|
|
237
|
+
title?: string;
|
|
238
|
+
description?: string;
|
|
239
|
+
badge?: string;
|
|
240
|
+
type?: "info" | "success" | "error" | "warning";
|
|
241
|
+
duration?: number;
|
|
242
|
+
}
|
|
243
|
+
export const toast: ((input: string | ToastOptions) => number) & {
|
|
244
|
+
success(title: string, description?: string): number;
|
|
245
|
+
error(title: string, description?: string): number;
|
|
246
|
+
info(title: string, description?: string): number;
|
|
247
|
+
warning(title: string, description?: string): number;
|
|
248
|
+
};
|
|
249
|
+
export function dismissToast(id: number): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ApiError,
|
|
3
|
+
api,
|
|
4
|
+
configureApi,
|
|
5
|
+
getApiBaseUrl,
|
|
6
|
+
getAuthMode,
|
|
7
|
+
getAuthToken,
|
|
8
|
+
getCsrfToken,
|
|
9
|
+
getExportConfig,
|
|
10
|
+
isExported,
|
|
11
|
+
request,
|
|
12
|
+
setApiBaseUrl,
|
|
13
|
+
setAuthToken,
|
|
14
|
+
} from "./api.js";
|
|
15
|
+
export { createRouter } from "./router.js";
|
|
16
|
+
export { MESSAGES, addMessages, getLocale, setLocale, t, useLocale } from "./i18n.js";
|
|
17
|
+
export {
|
|
18
|
+
AuthProvider,
|
|
19
|
+
GuestOnly,
|
|
20
|
+
RequireAuth,
|
|
21
|
+
matchUserRole,
|
|
22
|
+
useAuth,
|
|
23
|
+
} from "./auth.js";
|
|
24
|
+
export {
|
|
25
|
+
Badge,
|
|
26
|
+
Button,
|
|
27
|
+
buttonVariants,
|
|
28
|
+
Card,
|
|
29
|
+
Carousel,
|
|
30
|
+
Drawer,
|
|
31
|
+
Form,
|
|
32
|
+
Input,
|
|
33
|
+
Link,
|
|
34
|
+
Modal,
|
|
35
|
+
PageSkeleton,
|
|
36
|
+
ProgressBar,
|
|
37
|
+
Select,
|
|
38
|
+
Skeleton,
|
|
39
|
+
Spinner,
|
|
40
|
+
SubmitButton,
|
|
41
|
+
Textarea,
|
|
42
|
+
ThemeToggle,
|
|
43
|
+
Toaster,
|
|
44
|
+
cn,
|
|
45
|
+
dismissToast,
|
|
46
|
+
toast,
|
|
47
|
+
useFormState,
|
|
48
|
+
useTheme,
|
|
49
|
+
} from "./components.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createBrowserRouter, createHashRouter, createMemoryRouter } from "react-router";
|
|
2
|
+
import { getExportConfig } from "./api.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a React Router data router that works on the Bluebird server and in static exports.
|
|
6
|
+
* - Served by `router.spa()`: `createBrowserRouter` with `basename` (e.g. `"/app"`).
|
|
7
|
+
* - Static export (`npx bluebird-js export`) or `file://` (Electron `loadFile`): `createHashRouter`.
|
|
8
|
+
* - `mode` forces `"browser"`, `"hash"`, or `"memory"`.
|
|
9
|
+
* @param {import('react-router').RouteObject[]} routes
|
|
10
|
+
* @param {Object} [options={}]
|
|
11
|
+
* @param {string} [options.basename] - Mount path on the server (ignored by hash and memory routers).
|
|
12
|
+
* @param {"browser"|"hash"|"memory"} [options.mode]
|
|
13
|
+
* @returns {ReturnType<typeof createBrowserRouter>}
|
|
14
|
+
*/
|
|
15
|
+
export function createRouter(routes, options = {}) {
|
|
16
|
+
const { mode: requested, basename, ...rest } = options;
|
|
17
|
+
const exported = getExportConfig();
|
|
18
|
+
const isFileProtocol = typeof window !== "undefined" && window.location?.protocol === "file:";
|
|
19
|
+
const mode = requested || exported?.router || (isFileProtocol ? "hash" : "browser");
|
|
20
|
+
|
|
21
|
+
if (mode === "hash") return createHashRouter(routes, rest);
|
|
22
|
+
if (mode === "memory") return createMemoryRouter(routes, rest);
|
|
23
|
+
|
|
24
|
+
const base = exported ? exported.basename || "/" : basename;
|
|
25
|
+
return createBrowserRouter(routes, base && base !== "/" ? { ...rest, basename: base } : rest);
|
|
26
|
+
}
|