@seip/bluebird-js 0.1.7 → 0.2.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/AGENTS.md +727 -620
- package/README.md +670 -607
- package/app/models/user.js +19 -0
- package/app/resources/html/home.html +137 -0
- package/app/resources/html/layouts/main.html +55 -0
- package/app/resources/html/notFound.html +14 -0
- package/app/resources/html/table.html +15 -0
- package/app/resources/html/terms.html +46 -0
- package/app/resources/index.html +27 -0
- package/app/resources/layouts/AppLayout.jsx +92 -0
- package/app/resources/main.jsx +18 -0
- package/app/resources/pages/Dashboard.jsx +93 -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/pages/TableDemo.jsx +85 -0
- package/app/resources/routes.jsx +59 -0
- package/app/resources/spa.js +73 -0
- package/app/resources/styles.css +9 -0
- package/app/routes/api.js +129 -50
- package/app/routes/auth.js +209 -0
- package/app/routes/web.js +89 -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 +239 -0
- package/core/react/client/auth.js +236 -0
- package/core/react/client/components.js +1321 -0
- package/core/react/client/datatable.js +595 -0
- package/core/react/client/i18n.js +440 -0
- package/core/react/client/index.d.ts +314 -0
- package/core/react/client/index.js +50 -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 +1886 -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,1886 @@
|
|
|
1
|
+
(function (global) {
|
|
2
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
3
|
+
if (global.Bluebird && global.Bluebird.__loaded) return;
|
|
4
|
+
|
|
5
|
+
const THEME_STORAGE_KEY = "bb-theme";
|
|
6
|
+
const TONES = ["info", "success", "warning", "error"];
|
|
7
|
+
/**
|
|
8
|
+
* Built-in UI strings (kept identical to `core/react/client/i18n.js`). Missing keys fall back to English.
|
|
9
|
+
* @type {Record<string, Record<string, string>>}
|
|
10
|
+
*/
|
|
11
|
+
const MESSAGES = {
|
|
12
|
+
"en": {
|
|
13
|
+
"toast.info": "Info",
|
|
14
|
+
"toast.success": "Success",
|
|
15
|
+
"toast.warning": "Warning",
|
|
16
|
+
"toast.error": "Error",
|
|
17
|
+
"toast.danger": "Alert",
|
|
18
|
+
"toast.region": "Notifications",
|
|
19
|
+
"toast.dismiss": "Dismiss notification",
|
|
20
|
+
"theme.toLight": "Switch to light theme",
|
|
21
|
+
"theme.toDark": "Switch to dark theme",
|
|
22
|
+
"theme.light": "Light",
|
|
23
|
+
"theme.dark": "Dark",
|
|
24
|
+
"dialog.close": "Close",
|
|
25
|
+
"dialog.label": "Dialog",
|
|
26
|
+
"drawer.label": "Panel",
|
|
27
|
+
"carousel.label": "Featured showcase",
|
|
28
|
+
"carousel.role": "carousel",
|
|
29
|
+
"carousel.slide": "slide",
|
|
30
|
+
"carousel.slides": "Slides",
|
|
31
|
+
"carousel.choose": "Choose a slide",
|
|
32
|
+
"carousel.prev": "Previous slide",
|
|
33
|
+
"carousel.next": "Next slide",
|
|
34
|
+
"carousel.prevShort": "Prev",
|
|
35
|
+
"carousel.nextShort": "Next",
|
|
36
|
+
"carousel.goTo": "Go to slide {n}",
|
|
37
|
+
"carousel.position": "{n} of {total}",
|
|
38
|
+
"carousel.status": "Slide {n} of {total}",
|
|
39
|
+
"loading": "Loading...",
|
|
40
|
+
"request.failed": "Request failed",
|
|
41
|
+
"request.network": "Network error",
|
|
42
|
+
"form.invalid": "Please check this field.",
|
|
43
|
+
"form.validation": "Validation error",
|
|
44
|
+
"value.invalid": "Invalid value",
|
|
45
|
+
"copy.done": "Copied to clipboard",
|
|
46
|
+
"auth.deniedTitle": "Access denied",
|
|
47
|
+
"auth.deniedText": "You do not have permission to view this section.",
|
|
48
|
+
"table.search": "Search...",
|
|
49
|
+
"table.empty": "No results",
|
|
50
|
+
"table.rowsPerPage": "Rows per page",
|
|
51
|
+
"table.range": "{from}-{to} of {total}",
|
|
52
|
+
"table.prev": "Previous page",
|
|
53
|
+
"table.next": "Next page",
|
|
54
|
+
"table.page": "Page {n} of {total}",
|
|
55
|
+
"table.actions": "Actions",
|
|
56
|
+
"table.view": "View",
|
|
57
|
+
"table.edit": "Edit",
|
|
58
|
+
"table.delete": "Delete",
|
|
59
|
+
"table.confirmTitle": "Delete this record?",
|
|
60
|
+
"table.confirmText": "This action cannot be undone.",
|
|
61
|
+
"table.cancel": "Cancel",
|
|
62
|
+
"table.more": "Show details",
|
|
63
|
+
"table.less": "Hide details",
|
|
64
|
+
"table.sortBy": "Sort by {column}"
|
|
65
|
+
},
|
|
66
|
+
"es": {
|
|
67
|
+
"toast.info": "Info",
|
|
68
|
+
"toast.success": "Correcto",
|
|
69
|
+
"toast.warning": "Cuidado",
|
|
70
|
+
"toast.error": "Error",
|
|
71
|
+
"toast.danger": "Alerta",
|
|
72
|
+
"toast.region": "Notificaciones",
|
|
73
|
+
"toast.dismiss": "Cerrar notificación",
|
|
74
|
+
"theme.toLight": "Cambiar a tema claro",
|
|
75
|
+
"theme.toDark": "Cambiar a tema oscuro",
|
|
76
|
+
"theme.light": "Claro",
|
|
77
|
+
"theme.dark": "Oscuro",
|
|
78
|
+
"dialog.close": "Cerrar",
|
|
79
|
+
"dialog.label": "Diálogo",
|
|
80
|
+
"drawer.label": "Panel",
|
|
81
|
+
"carousel.label": "Destacados",
|
|
82
|
+
"carousel.role": "carrusel",
|
|
83
|
+
"carousel.slide": "diapositiva",
|
|
84
|
+
"carousel.slides": "Diapositivas",
|
|
85
|
+
"carousel.choose": "Elegir diapositiva",
|
|
86
|
+
"carousel.prev": "Diapositiva anterior",
|
|
87
|
+
"carousel.next": "Diapositiva siguiente",
|
|
88
|
+
"carousel.prevShort": "Anterior",
|
|
89
|
+
"carousel.nextShort": "Siguiente",
|
|
90
|
+
"carousel.goTo": "Ir a la diapositiva {n}",
|
|
91
|
+
"carousel.position": "{n} de {total}",
|
|
92
|
+
"carousel.status": "Diapositiva {n} de {total}",
|
|
93
|
+
"loading": "Cargando...",
|
|
94
|
+
"request.failed": "La solicitud falló",
|
|
95
|
+
"request.network": "Error de red",
|
|
96
|
+
"form.invalid": "Revisa este campo.",
|
|
97
|
+
"form.validation": "Error de validación",
|
|
98
|
+
"value.invalid": "Valor inválido",
|
|
99
|
+
"copy.done": "Copiado al portapapeles",
|
|
100
|
+
"auth.deniedTitle": "Acceso denegado",
|
|
101
|
+
"auth.deniedText": "No tienes permiso para ver esta sección.",
|
|
102
|
+
"table.search": "Buscar...",
|
|
103
|
+
"table.empty": "Sin resultados",
|
|
104
|
+
"table.rowsPerPage": "Filas por página",
|
|
105
|
+
"table.range": "{from}-{to} de {total}",
|
|
106
|
+
"table.prev": "Página anterior",
|
|
107
|
+
"table.next": "Página siguiente",
|
|
108
|
+
"table.page": "Página {n} de {total}",
|
|
109
|
+
"table.actions": "Acciones",
|
|
110
|
+
"table.view": "Ver",
|
|
111
|
+
"table.edit": "Editar",
|
|
112
|
+
"table.delete": "Eliminar",
|
|
113
|
+
"table.confirmTitle": "¿Eliminar este registro?",
|
|
114
|
+
"table.confirmText": "Esta acción no se puede deshacer.",
|
|
115
|
+
"table.cancel": "Cancelar",
|
|
116
|
+
"table.more": "Ver detalles",
|
|
117
|
+
"table.less": "Ocultar detalles",
|
|
118
|
+
"table.sortBy": "Ordenar por {column}"
|
|
119
|
+
},
|
|
120
|
+
"pt": {
|
|
121
|
+
"toast.info": "Info",
|
|
122
|
+
"toast.success": "Sucesso",
|
|
123
|
+
"toast.warning": "Atenção",
|
|
124
|
+
"toast.error": "Erro",
|
|
125
|
+
"toast.danger": "Alerta",
|
|
126
|
+
"toast.region": "Notificações",
|
|
127
|
+
"toast.dismiss": "Fechar notificação",
|
|
128
|
+
"theme.toLight": "Mudar para o tema claro",
|
|
129
|
+
"theme.toDark": "Mudar para o tema escuro",
|
|
130
|
+
"theme.light": "Claro",
|
|
131
|
+
"theme.dark": "Escuro",
|
|
132
|
+
"dialog.close": "Fechar",
|
|
133
|
+
"dialog.label": "Diálogo",
|
|
134
|
+
"drawer.label": "Painel",
|
|
135
|
+
"carousel.label": "Destaques",
|
|
136
|
+
"carousel.role": "carrossel",
|
|
137
|
+
"carousel.slide": "slide",
|
|
138
|
+
"carousel.slides": "Slides",
|
|
139
|
+
"carousel.choose": "Escolher slide",
|
|
140
|
+
"carousel.prev": "Slide anterior",
|
|
141
|
+
"carousel.next": "Próximo slide",
|
|
142
|
+
"carousel.prevShort": "Anterior",
|
|
143
|
+
"carousel.nextShort": "Próximo",
|
|
144
|
+
"carousel.goTo": "Ir para o slide {n}",
|
|
145
|
+
"carousel.position": "{n} de {total}",
|
|
146
|
+
"carousel.status": "Slide {n} de {total}",
|
|
147
|
+
"loading": "Carregando...",
|
|
148
|
+
"request.failed": "A solicitação falhou",
|
|
149
|
+
"request.network": "Erro de rede",
|
|
150
|
+
"form.invalid": "Verifique este campo.",
|
|
151
|
+
"form.validation": "Erro de validação",
|
|
152
|
+
"value.invalid": "Valor inválido",
|
|
153
|
+
"copy.done": "Copiado para a área de transferência",
|
|
154
|
+
"auth.deniedTitle": "Acesso negado",
|
|
155
|
+
"auth.deniedText": "Você não tem permissão para ver esta seção.",
|
|
156
|
+
"table.search": "Pesquisar...",
|
|
157
|
+
"table.empty": "Nenhum resultado",
|
|
158
|
+
"table.rowsPerPage": "Linhas por página",
|
|
159
|
+
"table.range": "{from}-{to} de {total}",
|
|
160
|
+
"table.prev": "Página anterior",
|
|
161
|
+
"table.next": "Próxima página",
|
|
162
|
+
"table.page": "Página {n} de {total}",
|
|
163
|
+
"table.actions": "Ações",
|
|
164
|
+
"table.view": "Ver",
|
|
165
|
+
"table.edit": "Editar",
|
|
166
|
+
"table.delete": "Excluir",
|
|
167
|
+
"table.confirmTitle": "Excluir este registro?",
|
|
168
|
+
"table.confirmText": "Esta ação não pode ser desfeita.",
|
|
169
|
+
"table.cancel": "Cancelar",
|
|
170
|
+
"table.more": "Ver detalhes",
|
|
171
|
+
"table.less": "Ocultar detalhes",
|
|
172
|
+
"table.sortBy": "Ordenar por {column}"
|
|
173
|
+
},
|
|
174
|
+
"fr": {
|
|
175
|
+
"toast.info": "Info",
|
|
176
|
+
"toast.success": "Succès",
|
|
177
|
+
"toast.warning": "Attention",
|
|
178
|
+
"toast.error": "Erreur",
|
|
179
|
+
"toast.danger": "Alerte",
|
|
180
|
+
"toast.region": "Notifications",
|
|
181
|
+
"toast.dismiss": "Fermer la notification",
|
|
182
|
+
"theme.toLight": "Passer au thème clair",
|
|
183
|
+
"theme.toDark": "Passer au thème sombre",
|
|
184
|
+
"theme.light": "Clair",
|
|
185
|
+
"theme.dark": "Sombre",
|
|
186
|
+
"dialog.close": "Fermer",
|
|
187
|
+
"dialog.label": "Boîte de dialogue",
|
|
188
|
+
"drawer.label": "Panneau",
|
|
189
|
+
"carousel.label": "À la une",
|
|
190
|
+
"carousel.role": "carrousel",
|
|
191
|
+
"carousel.slide": "diapositive",
|
|
192
|
+
"carousel.slides": "Diapositives",
|
|
193
|
+
"carousel.choose": "Choisir une diapositive",
|
|
194
|
+
"carousel.prev": "Diapositive précédente",
|
|
195
|
+
"carousel.next": "Diapositive suivante",
|
|
196
|
+
"carousel.prevShort": "Préc.",
|
|
197
|
+
"carousel.nextShort": "Suiv.",
|
|
198
|
+
"carousel.goTo": "Aller à la diapositive {n}",
|
|
199
|
+
"carousel.position": "{n} sur {total}",
|
|
200
|
+
"carousel.status": "Diapositive {n} sur {total}",
|
|
201
|
+
"loading": "Chargement...",
|
|
202
|
+
"request.failed": "La requête a échoué",
|
|
203
|
+
"request.network": "Erreur réseau",
|
|
204
|
+
"form.invalid": "Vérifiez ce champ.",
|
|
205
|
+
"form.validation": "Erreur de validation",
|
|
206
|
+
"value.invalid": "Valeur invalide",
|
|
207
|
+
"copy.done": "Copié dans le presse-papiers",
|
|
208
|
+
"auth.deniedTitle": "Accès refusé",
|
|
209
|
+
"auth.deniedText": "Vous n'avez pas l'autorisation de voir cette section.",
|
|
210
|
+
"table.search": "Rechercher...",
|
|
211
|
+
"table.empty": "Aucun résultat",
|
|
212
|
+
"table.rowsPerPage": "Lignes par page",
|
|
213
|
+
"table.range": "{from}-{to} sur {total}",
|
|
214
|
+
"table.prev": "Page précédente",
|
|
215
|
+
"table.next": "Page suivante",
|
|
216
|
+
"table.page": "Page {n} sur {total}",
|
|
217
|
+
"table.actions": "Actions",
|
|
218
|
+
"table.view": "Voir",
|
|
219
|
+
"table.edit": "Modifier",
|
|
220
|
+
"table.delete": "Supprimer",
|
|
221
|
+
"table.confirmTitle": "Supprimer cet enregistrement ?",
|
|
222
|
+
"table.confirmText": "Cette action est irréversible.",
|
|
223
|
+
"table.cancel": "Annuler",
|
|
224
|
+
"table.more": "Voir les détails",
|
|
225
|
+
"table.less": "Masquer les détails",
|
|
226
|
+
"table.sortBy": "Trier par {column}"
|
|
227
|
+
},
|
|
228
|
+
"de": {
|
|
229
|
+
"toast.info": "Info",
|
|
230
|
+
"toast.success": "Erfolg",
|
|
231
|
+
"toast.warning": "Achtung",
|
|
232
|
+
"toast.error": "Fehler",
|
|
233
|
+
"toast.danger": "Warnung",
|
|
234
|
+
"toast.region": "Benachrichtigungen",
|
|
235
|
+
"toast.dismiss": "Benachrichtigung schließen",
|
|
236
|
+
"theme.toLight": "Zum hellen Design wechseln",
|
|
237
|
+
"theme.toDark": "Zum dunklen Design wechseln",
|
|
238
|
+
"theme.light": "Hell",
|
|
239
|
+
"theme.dark": "Dunkel",
|
|
240
|
+
"dialog.close": "Schließen",
|
|
241
|
+
"dialog.label": "Dialog",
|
|
242
|
+
"drawer.label": "Seitenleiste",
|
|
243
|
+
"carousel.label": "Highlights",
|
|
244
|
+
"carousel.role": "Karussell",
|
|
245
|
+
"carousel.slide": "Folie",
|
|
246
|
+
"carousel.slides": "Folien",
|
|
247
|
+
"carousel.choose": "Folie auswählen",
|
|
248
|
+
"carousel.prev": "Vorherige Folie",
|
|
249
|
+
"carousel.next": "Nächste Folie",
|
|
250
|
+
"carousel.prevShort": "Zurück",
|
|
251
|
+
"carousel.nextShort": "Weiter",
|
|
252
|
+
"carousel.goTo": "Zu Folie {n}",
|
|
253
|
+
"carousel.position": "{n} von {total}",
|
|
254
|
+
"carousel.status": "Folie {n} von {total}",
|
|
255
|
+
"loading": "Wird geladen...",
|
|
256
|
+
"request.failed": "Anfrage fehlgeschlagen",
|
|
257
|
+
"request.network": "Netzwerkfehler",
|
|
258
|
+
"form.invalid": "Bitte überprüfe dieses Feld.",
|
|
259
|
+
"form.validation": "Validierungsfehler",
|
|
260
|
+
"value.invalid": "Ungültiger Wert",
|
|
261
|
+
"copy.done": "In die Zwischenablage kopiert",
|
|
262
|
+
"auth.deniedTitle": "Zugriff verweigert",
|
|
263
|
+
"auth.deniedText": "Du hast keine Berechtigung, diesen Bereich zu sehen.",
|
|
264
|
+
"table.search": "Suchen...",
|
|
265
|
+
"table.empty": "Keine Ergebnisse",
|
|
266
|
+
"table.rowsPerPage": "Zeilen pro Seite",
|
|
267
|
+
"table.range": "{from}-{to} von {total}",
|
|
268
|
+
"table.prev": "Vorherige Seite",
|
|
269
|
+
"table.next": "Nächste Seite",
|
|
270
|
+
"table.page": "Seite {n} von {total}",
|
|
271
|
+
"table.actions": "Aktionen",
|
|
272
|
+
"table.view": "Ansehen",
|
|
273
|
+
"table.edit": "Bearbeiten",
|
|
274
|
+
"table.delete": "Löschen",
|
|
275
|
+
"table.confirmTitle": "Diesen Eintrag löschen?",
|
|
276
|
+
"table.confirmText": "Diese Aktion kann nicht rückgängig gemacht werden.",
|
|
277
|
+
"table.cancel": "Abbrechen",
|
|
278
|
+
"table.more": "Details anzeigen",
|
|
279
|
+
"table.less": "Details ausblenden",
|
|
280
|
+
"table.sortBy": "Nach {column} sortieren"
|
|
281
|
+
},
|
|
282
|
+
"it": {
|
|
283
|
+
"toast.info": "Info",
|
|
284
|
+
"toast.success": "Fatto",
|
|
285
|
+
"toast.warning": "Attenzione",
|
|
286
|
+
"toast.error": "Errore",
|
|
287
|
+
"toast.danger": "Avviso",
|
|
288
|
+
"toast.region": "Notifiche",
|
|
289
|
+
"toast.dismiss": "Chiudi notifica",
|
|
290
|
+
"theme.toLight": "Passa al tema chiaro",
|
|
291
|
+
"theme.toDark": "Passa al tema scuro",
|
|
292
|
+
"theme.light": "Chiaro",
|
|
293
|
+
"theme.dark": "Scuro",
|
|
294
|
+
"dialog.close": "Chiudi",
|
|
295
|
+
"dialog.label": "Finestra di dialogo",
|
|
296
|
+
"drawer.label": "Pannello",
|
|
297
|
+
"carousel.label": "In evidenza",
|
|
298
|
+
"carousel.role": "carosello",
|
|
299
|
+
"carousel.slide": "slide",
|
|
300
|
+
"carousel.slides": "Slide",
|
|
301
|
+
"carousel.choose": "Scegli una slide",
|
|
302
|
+
"carousel.prev": "Slide precedente",
|
|
303
|
+
"carousel.next": "Slide successiva",
|
|
304
|
+
"carousel.prevShort": "Prec.",
|
|
305
|
+
"carousel.nextShort": "Succ.",
|
|
306
|
+
"carousel.goTo": "Vai alla slide {n}",
|
|
307
|
+
"carousel.position": "{n} di {total}",
|
|
308
|
+
"carousel.status": "Slide {n} di {total}",
|
|
309
|
+
"loading": "Caricamento...",
|
|
310
|
+
"request.failed": "Richiesta non riuscita",
|
|
311
|
+
"request.network": "Errore di rete",
|
|
312
|
+
"form.invalid": "Controlla questo campo.",
|
|
313
|
+
"form.validation": "Errore di convalida",
|
|
314
|
+
"value.invalid": "Valore non valido",
|
|
315
|
+
"copy.done": "Copiato negli appunti",
|
|
316
|
+
"auth.deniedTitle": "Accesso negato",
|
|
317
|
+
"auth.deniedText": "Non hai il permesso di vedere questa sezione.",
|
|
318
|
+
"table.search": "Cerca...",
|
|
319
|
+
"table.empty": "Nessun risultato",
|
|
320
|
+
"table.rowsPerPage": "Righe per pagina",
|
|
321
|
+
"table.range": "{from}-{to} di {total}",
|
|
322
|
+
"table.prev": "Pagina precedente",
|
|
323
|
+
"table.next": "Pagina successiva",
|
|
324
|
+
"table.page": "Pagina {n} di {total}",
|
|
325
|
+
"table.actions": "Azioni",
|
|
326
|
+
"table.view": "Vedi",
|
|
327
|
+
"table.edit": "Modifica",
|
|
328
|
+
"table.delete": "Elimina",
|
|
329
|
+
"table.confirmTitle": "Eliminare questo record?",
|
|
330
|
+
"table.confirmText": "Questa azione non può essere annullata.",
|
|
331
|
+
"table.cancel": "Annulla",
|
|
332
|
+
"table.more": "Mostra dettagli",
|
|
333
|
+
"table.less": "Nascondi dettagli",
|
|
334
|
+
"table.sortBy": "Ordina per {column}"
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const customMessages = {};
|
|
338
|
+
let forcedLocale = null;
|
|
339
|
+
let toastSeq = 0;
|
|
340
|
+
let toastRoot = null;
|
|
341
|
+
let toastLive = null;
|
|
342
|
+
let stylesInjected = false;
|
|
343
|
+
let cachedDisplayTransitionSupport;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Returns the active UI locale: `Bluebird.i18n.setLocale()` override, then `<html lang>`, then the browser language.
|
|
347
|
+
* @returns {string}
|
|
348
|
+
*/
|
|
349
|
+
function getLocale() {
|
|
350
|
+
return forcedLocale || document.documentElement.lang || navigator.language || "en";
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Translates a UI string key for the active locale (exact tag, base language, then English), replacing `{name}` placeholders.
|
|
355
|
+
* @param {string} key
|
|
356
|
+
* @param {Record<string, string|number>} [params]
|
|
357
|
+
* @returns {string}
|
|
358
|
+
*/
|
|
359
|
+
function t(key, params) {
|
|
360
|
+
const full = String(getLocale()).toLowerCase();
|
|
361
|
+
let message;
|
|
362
|
+
for (const tag of [full, full.split("-")[0], "en"]) {
|
|
363
|
+
message = customMessages[tag]?.[key] ?? MESSAGES[tag]?.[key];
|
|
364
|
+
if (message !== undefined) break;
|
|
365
|
+
}
|
|
366
|
+
message = message ?? key;
|
|
367
|
+
if (!params) return message;
|
|
368
|
+
return message.replace(/\{(\w+)\}/g, (match, name) => (params[name] !== undefined ? String(params[name]) : match));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Adds or overrides UI strings for a language.
|
|
373
|
+
* @param {string} locale
|
|
374
|
+
* @param {Record<string, string>} messages
|
|
375
|
+
*/
|
|
376
|
+
function addMessages(locale, messages) {
|
|
377
|
+
const key = String(locale).toLowerCase();
|
|
378
|
+
customMessages[key] = Object.assign({}, customMessages[key], messages);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Forces the UI locale (`null` returns to `<html lang>` detection).
|
|
383
|
+
* @param {string|null} locale
|
|
384
|
+
*/
|
|
385
|
+
function setLocale(locale) {
|
|
386
|
+
forcedLocale = locale ? String(locale) : null;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Injects minimal self-contained styles for toasts, native `<dialog>` modals, and scroll-snap carousels.
|
|
391
|
+
*/
|
|
392
|
+
function ensureStyles() {
|
|
393
|
+
if (stylesInjected || !document.head) return;
|
|
394
|
+
stylesInjected = true;
|
|
395
|
+
const style = document.createElement("style");
|
|
396
|
+
style.setAttribute("data-bb-ui", "true");
|
|
397
|
+
style.textContent = [
|
|
398
|
+
".bb-vh:where(:not(:focus-within,:active)){position:absolute!important;clip-path:inset(50%)!important;overflow:hidden!important;width:1px!important;height:1px!important;margin:-1px!important;padding:0!important;border:0!important;white-space:nowrap!important}",
|
|
399
|
+
".bb-toast-stack{position:fixed;bottom:1rem;right:1rem;inset:auto 1rem 1rem auto;z-index:9999;margin:0;padding:0;border:0;background:transparent;overflow:visible;display:flex;flex-direction:column;gap:.625rem;width:22rem;max-width:calc(100vw - 2rem);pointer-events:none}",
|
|
400
|
+
".bb-toast-stack[popover]:not(:is(:popover-open,.\\:popover-open)){display:none}",
|
|
401
|
+
".bb-toast{pointer-events:auto;display:flex;flex-direction:column;gap:.35rem;padding:.875rem 1rem;border-radius:1rem;border:1px solid var(--border,rgba(161,161,170,.3));background:color-mix(in oklab,var(--popover,#fff) 90%,transparent);color:var(--popover-foreground,#18181b);box-shadow:inset 0 1px 0 0 rgba(255,255,255,.5),0 2px 6px rgba(0,0,0,.05),0 18px 40px -14px rgba(0,0,0,.2);-webkit-backdrop-filter:blur(20px) saturate(1.5);backdrop-filter:blur(20px) saturate(1.5);font-family:inherit;font-size:.875rem;line-height:1.45;opacity:1;transition:opacity .22s,transform .22s;transition-timing-function:cubic-bezier(.22,1,.36,1)}",
|
|
402
|
+
"@media (prefers-reduced-motion:no-preference){@starting-style{.bb-toast{opacity:0;transform:translateY(.5rem) scale(.98)}}}",
|
|
403
|
+
"@media (prefers-reduced-motion:reduce){.bb-toast{transition-duration:.08s}}",
|
|
404
|
+
"html.dark .bb-toast,html[data-theme='dark'] .bb-toast{background:color-mix(in oklab,var(--popover,#18181b) 90%,transparent);color:var(--popover-foreground,#fafafa);box-shadow:inset 0 1px 0 0 rgba(255,255,255,.06),0 4px 12px rgba(0,0,0,.35),0 20px 44px -14px rgba(0,0,0,.7)}",
|
|
405
|
+
".bb-toast-head{display:flex;align-items:center;justify-content:space-between;gap:.5rem}",
|
|
406
|
+
".bb-toast-badge{display:inline-flex;align-items:center;gap:.375rem;border-radius:9999px;padding:.125rem .5rem;font-size:.6875rem;font-weight:500;line-height:1.25;border:1px solid color-mix(in oklab,var(--info,#0284c7) 30%,transparent);background:color-mix(in oklab,var(--info,#0284c7) 12%,transparent);color:color-mix(in oklab,var(--info,#0284c7) 85%,var(--foreground,#18181b))}",
|
|
407
|
+
".bb-toast-dot{width:.375rem;height:.375rem;border-radius:9999px;flex-shrink:0;background:var(--info,#0284c7)}",
|
|
408
|
+
".bb-toast[data-type='success'] .bb-toast-badge{border-color:color-mix(in oklab,var(--success,#16a34a) 32%,transparent);background:color-mix(in oklab,var(--success,#16a34a) 13%,transparent);color:color-mix(in oklab,var(--success,#16a34a) 82%,var(--foreground,#18181b))}",
|
|
409
|
+
".bb-toast[data-type='success'] .bb-toast-dot{background:var(--success,#16a34a)}",
|
|
410
|
+
".bb-toast[data-type='warning'] .bb-toast-badge{border-color:color-mix(in oklab,var(--warning,#d97706) 35%,transparent);background:color-mix(in oklab,var(--warning,#d97706) 15%,transparent);color:color-mix(in oklab,var(--warning,#d97706) 75%,var(--foreground,#18181b))}",
|
|
411
|
+
".bb-toast[data-type='warning'] .bb-toast-dot{background:var(--warning,#d97706)}",
|
|
412
|
+
".bb-toast[data-type='error'] .bb-toast-badge{border-color:color-mix(in oklab,var(--destructive,#dc2626) 32%,transparent);background:color-mix(in oklab,var(--destructive,#dc2626) 12%,transparent);color:var(--destructive,#dc2626)}",
|
|
413
|
+
".bb-toast[data-type='error'] .bb-toast-dot{background:var(--destructive,#dc2626)}",
|
|
414
|
+
".bb-toast-title{font-weight:600;margin:.125rem 0 0;color:var(--popover-foreground,#18181b)}",
|
|
415
|
+
"html.dark .bb-toast-title,html[data-theme='dark'] .bb-toast-title{color:var(--popover-foreground,#fafafa)}",
|
|
416
|
+
".bb-toast-desc{margin:0;color:var(--muted-foreground,#71717a);font-size:.8125rem;line-height:1.45}",
|
|
417
|
+
".bb-toast-close{display:inline-flex;align-items:center;justify-content:center;width:1.75rem;height:1.75rem;border:none;background:transparent;color:var(--muted-foreground,#71717a);cursor:pointer;margin:-.25rem -.25rem 0 0;border-radius:.5rem;font-size:.75rem;line-height:1;transition:background-color .15s,color .15s}",
|
|
418
|
+
".bb-toast-close:hover{background:var(--accent,rgba(161,161,170,.16));color:var(--foreground,#18181b)}",
|
|
419
|
+
"html.dark .bb-toast-close:hover,html[data-theme='dark'] .bb-toast-close:hover{color:var(--foreground,#fafafa)}",
|
|
420
|
+
"[data-carousel]{position:relative;overflow:hidden}",
|
|
421
|
+
"[data-carousel-track]{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;overscroll-behavior-x:contain;scrollbar-width:none;touch-action:manipulation}",
|
|
422
|
+
"[data-carousel-track]::-webkit-scrollbar{display:none}",
|
|
423
|
+
"@media (prefers-reduced-motion:no-preference){[data-carousel-track]{scroll-behavior:smooth}}",
|
|
424
|
+
"[data-carousel-slide]{width:100%;flex:0 0 100%;min-width:0;scroll-snap-align:center;box-sizing:border-box}",
|
|
425
|
+
"[data-carousel-dot]{display:inline-flex;align-items:center;justify-content:center;min-width:24px;min-height:24px;padding:6px;background:transparent;border:0;cursor:pointer;touch-action:manipulation}",
|
|
426
|
+
"[data-carousel-dot]::before{content:'';display:block;height:6px;width:6px;border-radius:9999px;background:color-mix(in oklab,var(--muted-foreground,#71717a) 35%,transparent);transition:width .25s,background-color .25s}",
|
|
427
|
+
"[data-carousel-dot][aria-current='true']::before{width:24px;background:var(--foreground,#18181b)}",
|
|
428
|
+
"html.dark [data-carousel-dot][aria-current='true']::before,html[data-theme='dark'] [data-carousel-dot][aria-current='true']::before{background:var(--foreground,#fafafa)}",
|
|
429
|
+
"dialog[data-modal]:modal{overscroll-behavior:contain}",
|
|
430
|
+
"dialog[data-modal]{opacity:0;transition-property:opacity,transform,display,overlay;transition-duration:.22s;transition-timing-function:cubic-bezier(.22,1,.36,1);transition-behavior:allow-discrete}",
|
|
431
|
+
"@media (prefers-reduced-motion:no-preference){dialog[data-modal]{transform:scale(.96) translateY(.5rem)}}",
|
|
432
|
+
"dialog[data-modal]::backdrop{overflow:hidden;overscroll-behavior:contain;background-color:rgba(0,0,0,0);backdrop-filter:blur(0);transition-property:background-color,backdrop-filter,display,overlay;transition-duration:.22s;transition-timing-function:ease-out;transition-behavior:allow-discrete}",
|
|
433
|
+
"dialog[data-modal][open]:where(:not([data-closing])){opacity:1}",
|
|
434
|
+
"@starting-style{dialog[data-modal][open]:where(:not([data-closing])){opacity:0}}",
|
|
435
|
+
"@media (prefers-reduced-motion:no-preference){dialog[data-modal][open]:where(:not([data-closing])){transform:scale(1) translateY(0)}@starting-style{dialog[data-modal][open]:where(:not([data-closing])){transform:scale(.96) translateY(.5rem)}}}",
|
|
436
|
+
"dialog[data-modal][open]:where(:not([data-closing]))::backdrop{background-color:rgba(9,9,11,.45);backdrop-filter:blur(5px)}",
|
|
437
|
+
"@starting-style{dialog[data-modal][open]:where(:not([data-closing]))::backdrop{background-color:rgba(0,0,0,0);backdrop-filter:blur(0)}}",
|
|
438
|
+
"@media (prefers-reduced-motion:reduce){dialog[data-modal],dialog[data-modal]::backdrop{transition-duration:.08s}}",
|
|
439
|
+
].join("");
|
|
440
|
+
document.head.appendChild(style);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Detects whether discrete `display` transitions are genuinely supported.
|
|
445
|
+
* @returns {boolean}
|
|
446
|
+
*/
|
|
447
|
+
function canTransitionDisplay() {
|
|
448
|
+
if (cachedDisplayTransitionSupport !== undefined) return cachedDisplayTransitionSupport;
|
|
449
|
+
if (!window.CSS?.supports?.("transition-behavior", "allow-discrete") || !document.body) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
const probe = document.createElement("div");
|
|
453
|
+
probe.style.cssText = "transition: display 1s allow-discrete !important; display: block;";
|
|
454
|
+
document.body.appendChild(probe);
|
|
455
|
+
window.getComputedStyle(probe).display;
|
|
456
|
+
probe.style.display = "none";
|
|
457
|
+
cachedDisplayTransitionSupport = window.getComputedStyle(probe).display === "block";
|
|
458
|
+
probe.remove();
|
|
459
|
+
return cachedDisplayTransitionSupport;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Checks whether native top-layer exit transitions (`overlay` + discrete `display`) are supported.
|
|
464
|
+
* @returns {boolean}
|
|
465
|
+
*/
|
|
466
|
+
function supportsTopLayerExit() {
|
|
467
|
+
return Boolean(window.CSS?.supports?.("overlay", "auto")) && canTransitionDisplay();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Animates a `<dialog>` out of the top layer when exit transitions require a closing attribute, then closes it.
|
|
472
|
+
* @param {HTMLDialogElement} dialog
|
|
473
|
+
*/
|
|
474
|
+
async function closeTopLayerDialog(dialog) {
|
|
475
|
+
if (!dialog || !dialog.open) return;
|
|
476
|
+
if (!supportsTopLayerExit()) {
|
|
477
|
+
dialog.setAttribute("data-closing", "");
|
|
478
|
+
const animations = dialog.getAnimations ? dialog.getAnimations({ subtree: true }) : [];
|
|
479
|
+
if (animations.length > 0) {
|
|
480
|
+
await Promise.race([
|
|
481
|
+
Promise.allSettled(animations.map((a) => a.finished)),
|
|
482
|
+
new Promise((r) => setTimeout(r, 400)),
|
|
483
|
+
]);
|
|
484
|
+
}
|
|
485
|
+
if (!dialog.hasAttribute("data-closing")) return;
|
|
486
|
+
dialog.removeAttribute("data-closing");
|
|
487
|
+
}
|
|
488
|
+
if (dialog.open) dialog.close();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Reads the `_csrf` cookie value for XHR/fetch double-submit CSRF headers.
|
|
493
|
+
* @returns {string}
|
|
494
|
+
*/
|
|
495
|
+
function getCsrfToken() {
|
|
496
|
+
const match = document.cookie.match(/(?:^|;\s*)_csrf=([^;]*)/);
|
|
497
|
+
if (!match || !match[1]) return "";
|
|
498
|
+
try {
|
|
499
|
+
return decodeURIComponent(match[1]);
|
|
500
|
+
} catch {
|
|
501
|
+
return match[1];
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Returns the system preferred color scheme (`"dark"` or `"light"`).
|
|
507
|
+
* @returns {"dark"|"light"}
|
|
508
|
+
*/
|
|
509
|
+
function getSystemTheme() {
|
|
510
|
+
return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Applies theme classes, `<meta name="color-scheme">`, labels, and sync events.
|
|
515
|
+
* @param {"dark"|"light"} resolved
|
|
516
|
+
* @param {string|null} storedOverride
|
|
517
|
+
*/
|
|
518
|
+
function applyDocumentTheme(resolved, storedOverride) {
|
|
519
|
+
const root = document.documentElement;
|
|
520
|
+
root.classList.toggle("dark", resolved === "dark");
|
|
521
|
+
root.setAttribute("data-theme", resolved);
|
|
522
|
+
const meta = document.querySelector('meta[name="color-scheme"]');
|
|
523
|
+
if (meta) {
|
|
524
|
+
meta.setAttribute("content", storedOverride === "light" || storedOverride === "dark" ? storedOverride : "light dark");
|
|
525
|
+
}
|
|
526
|
+
document.querySelectorAll("[data-theme-label]").forEach((el) => {
|
|
527
|
+
el.textContent = t(resolved === "dark" ? "theme.light" : "theme.dark");
|
|
528
|
+
});
|
|
529
|
+
window.dispatchEvent(new CustomEvent("bluebird:theme", { detail: { theme: resolved, stored: storedOverride } }));
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Resolves and sets an explicit dark/light theme preference.
|
|
534
|
+
* @param {"dark"|"light"} mode
|
|
535
|
+
* @returns {"dark"|"light"}
|
|
536
|
+
*/
|
|
537
|
+
function setTheme(mode) {
|
|
538
|
+
const resolved = mode === "light" ? "light" : "dark";
|
|
539
|
+
try {
|
|
540
|
+
window.localStorage.setItem(THEME_STORAGE_KEY, resolved);
|
|
541
|
+
} catch {}
|
|
542
|
+
applyDocumentTheme(resolved, resolved);
|
|
543
|
+
return resolved;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Returns the active theme name (`"dark"` or `"light"`).
|
|
548
|
+
* @returns {"dark"|"light"}
|
|
549
|
+
*/
|
|
550
|
+
function getTheme() {
|
|
551
|
+
try {
|
|
552
|
+
const saved = window.localStorage.getItem(THEME_STORAGE_KEY);
|
|
553
|
+
if (saved === "light" || saved === "dark") return saved;
|
|
554
|
+
} catch {}
|
|
555
|
+
if (document.documentElement.classList.contains("dark")) return "dark";
|
|
556
|
+
if (document.documentElement.getAttribute("data-theme") === "light") return "light";
|
|
557
|
+
return getSystemTheme();
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Toggles between light and dark themes, removing stored override when reverting to system default.
|
|
562
|
+
* @returns {"dark"|"light"}
|
|
563
|
+
*/
|
|
564
|
+
function toggleTheme() {
|
|
565
|
+
const next = getTheme() === "dark" ? "light" : "dark";
|
|
566
|
+
const sys = getSystemTheme();
|
|
567
|
+
let stored = next;
|
|
568
|
+
try {
|
|
569
|
+
if (next === sys) {
|
|
570
|
+
window.localStorage.removeItem(THEME_STORAGE_KEY);
|
|
571
|
+
stored = null;
|
|
572
|
+
} else {
|
|
573
|
+
window.localStorage.setItem(THEME_STORAGE_KEY, next);
|
|
574
|
+
}
|
|
575
|
+
} catch {}
|
|
576
|
+
applyDocumentTheme(next, stored);
|
|
577
|
+
return next;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Announces toast messages cleanly via `navigator.ariaNotify` or a hidden polite live region.
|
|
582
|
+
* @param {string} text
|
|
583
|
+
*/
|
|
584
|
+
function announceToast(text) {
|
|
585
|
+
if (!text) return;
|
|
586
|
+
if (typeof navigator !== "undefined" && typeof navigator.ariaNotify === "function") {
|
|
587
|
+
navigator.ariaNotify(text);
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (!toastLive || !document.body.contains(toastLive)) {
|
|
591
|
+
toastLive = document.createElement("p");
|
|
592
|
+
toastLive.className = "bb-vh";
|
|
593
|
+
toastLive.setAttribute("aria-live", "polite");
|
|
594
|
+
document.body.appendChild(toastLive);
|
|
595
|
+
}
|
|
596
|
+
toastLive.textContent = "";
|
|
597
|
+
window.setTimeout(() => {
|
|
598
|
+
if (toastLive) toastLive.textContent = text;
|
|
599
|
+
}, 30);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Displays a frosted glass toast notification with a compact color-coded type badge inside a top-layer `popover="manual"` region.
|
|
604
|
+
* @param {string|{title?: string, description?: string, badge?: string, type?: "info"|"success"|"warning"|"error", duration?: number}} input
|
|
605
|
+
* @returns {number}
|
|
606
|
+
*/
|
|
607
|
+
function toast(input) {
|
|
608
|
+
ensureStyles();
|
|
609
|
+
const opts = typeof input === "string" ? { title: input } : input || {};
|
|
610
|
+
const type = TONES.includes(opts.type) ? opts.type : "info";
|
|
611
|
+
const duration = opts.duration !== undefined ? Number(opts.duration) : 4500;
|
|
612
|
+
const triggerEl = document.activeElement;
|
|
613
|
+
|
|
614
|
+
if (!toastRoot || !document.body.contains(toastRoot)) {
|
|
615
|
+
toastRoot = document.createElement("div");
|
|
616
|
+
toastRoot.className = "bb-toast-stack";
|
|
617
|
+
toastRoot.setAttribute("role", "region");
|
|
618
|
+
toastRoot.setAttribute("aria-label", t("toast.region"));
|
|
619
|
+
if (Object.hasOwn(HTMLElement.prototype, "popover") || typeof toastRoot.showPopover === "function") {
|
|
620
|
+
toastRoot.setAttribute("popover", "manual");
|
|
621
|
+
}
|
|
622
|
+
document.body.appendChild(toastRoot);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
if (typeof toastRoot.showPopover === "function") {
|
|
626
|
+
try {
|
|
627
|
+
if (!toastRoot.matches(":popover-open")) toastRoot.showPopover();
|
|
628
|
+
} catch {}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const id = ++toastSeq;
|
|
632
|
+
const item = document.createElement("div");
|
|
633
|
+
item.className = "bb-toast";
|
|
634
|
+
item.setAttribute("data-type", type);
|
|
635
|
+
item.setAttribute("data-toast-id", String(id));
|
|
636
|
+
|
|
637
|
+
const head = document.createElement("div");
|
|
638
|
+
head.className = "bb-toast-head";
|
|
639
|
+
|
|
640
|
+
const badge = document.createElement("span");
|
|
641
|
+
badge.className = "bb-toast-badge";
|
|
642
|
+
const dot = document.createElement("span");
|
|
643
|
+
dot.className = "bb-toast-dot";
|
|
644
|
+
dot.setAttribute("aria-hidden", "true");
|
|
645
|
+
badge.appendChild(dot);
|
|
646
|
+
badge.appendChild(document.createTextNode(opts.badge || t("toast." + type)));
|
|
647
|
+
head.appendChild(badge);
|
|
648
|
+
|
|
649
|
+
const closeBtn = document.createElement("button");
|
|
650
|
+
closeBtn.type = "button";
|
|
651
|
+
closeBtn.className = "bb-toast-close";
|
|
652
|
+
closeBtn.setAttribute("aria-label", t("toast.dismiss"));
|
|
653
|
+
closeBtn.textContent = "\u2715";
|
|
654
|
+
head.appendChild(closeBtn);
|
|
655
|
+
item.appendChild(head);
|
|
656
|
+
|
|
657
|
+
if (opts.title) {
|
|
658
|
+
const titleEl = document.createElement("p");
|
|
659
|
+
titleEl.className = "bb-toast-title";
|
|
660
|
+
titleEl.textContent = String(opts.title);
|
|
661
|
+
item.appendChild(titleEl);
|
|
662
|
+
}
|
|
663
|
+
if (opts.description) {
|
|
664
|
+
const descEl = document.createElement("p");
|
|
665
|
+
descEl.className = "bb-toast-desc";
|
|
666
|
+
descEl.textContent = String(opts.description);
|
|
667
|
+
item.appendChild(descEl);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
let timer = null;
|
|
671
|
+
let remaining = duration;
|
|
672
|
+
let startedAt = Date.now();
|
|
673
|
+
let paused = false;
|
|
674
|
+
|
|
675
|
+
const removeToast = (fromKeyboard) => {
|
|
676
|
+
if (timer) clearTimeout(timer);
|
|
677
|
+
const siblings = toastRoot ? Array.from(toastRoot.querySelectorAll(".bb-toast-close")) : [];
|
|
678
|
+
const closeIndex = siblings.indexOf(closeBtn);
|
|
679
|
+
if (item.parentNode) item.parentNode.removeChild(item);
|
|
680
|
+
if (toastRoot && toastRoot.children.length === 0 && typeof toastRoot.hidePopover === "function") {
|
|
681
|
+
try {
|
|
682
|
+
if (toastRoot.matches(":popover-open")) toastRoot.hidePopover();
|
|
683
|
+
} catch {}
|
|
684
|
+
}
|
|
685
|
+
if (fromKeyboard) {
|
|
686
|
+
const nextBtns = toastRoot ? toastRoot.querySelectorAll(".bb-toast-close") : [];
|
|
687
|
+
if (nextBtns.length > 0) {
|
|
688
|
+
const target = nextBtns[Math.min(closeIndex, nextBtns.length - 1)];
|
|
689
|
+
target?.focus?.();
|
|
690
|
+
} else if (triggerEl?.isConnected) {
|
|
691
|
+
triggerEl.focus?.();
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const pause = () => {
|
|
697
|
+
if (duration <= 0 || paused) return;
|
|
698
|
+
clearTimeout(timer);
|
|
699
|
+
remaining = Math.max(0, remaining - (Date.now() - startedAt));
|
|
700
|
+
paused = true;
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const resume = () => {
|
|
704
|
+
if (duration <= 0 || !paused || remaining <= 0) return;
|
|
705
|
+
paused = false;
|
|
706
|
+
startedAt = Date.now();
|
|
707
|
+
timer = setTimeout(() => removeToast(false), remaining);
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
closeBtn.addEventListener("click", (e) => removeToast(e.detail === 0));
|
|
711
|
+
item.addEventListener("pointerenter", pause);
|
|
712
|
+
item.addEventListener("pointerleave", resume);
|
|
713
|
+
item.addEventListener("focusin", pause);
|
|
714
|
+
item.addEventListener("focusout", (e) => {
|
|
715
|
+
if (!item.contains(e.relatedTarget)) resume();
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
toastRoot.appendChild(item);
|
|
719
|
+
announceToast([opts.title, opts.description].filter(Boolean).join(". "));
|
|
720
|
+
|
|
721
|
+
if (duration > 0) {
|
|
722
|
+
startedAt = Date.now();
|
|
723
|
+
timer = setTimeout(() => removeToast(false), duration);
|
|
724
|
+
}
|
|
725
|
+
return id;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
toast.success = (title, description) => toast({ type: "success", title, description });
|
|
729
|
+
toast.error = (title, description) => toast({ type: "error", title, description });
|
|
730
|
+
toast.info = (title, description) => toast({ type: "info", title, description });
|
|
731
|
+
toast.warning = (title, description) => toast({ type: "warning", title, description });
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Initializes a native scroll-snap `[data-carousel]` element with controls, pill dots, autoplay, and polite live status.
|
|
735
|
+
* @param {HTMLElement} el
|
|
736
|
+
*/
|
|
737
|
+
function initCarousel(el) {
|
|
738
|
+
if (!el || el.dataset.bbCarouselInit === "1") return;
|
|
739
|
+
const track = el.querySelector("[data-carousel-track]");
|
|
740
|
+
const slides = Array.from(el.querySelectorAll("[data-carousel-slide]"));
|
|
741
|
+
if (!track || slides.length === 0) return;
|
|
742
|
+
el.dataset.bbCarouselInit = "1";
|
|
743
|
+
|
|
744
|
+
if (!el.hasAttribute("role")) el.setAttribute("role", "region");
|
|
745
|
+
if (!el.hasAttribute("aria-roledescription")) el.setAttribute("aria-roledescription", t("carousel.role"));
|
|
746
|
+
if (!el.hasAttribute("aria-label")) el.setAttribute("aria-label", t("carousel.label"));
|
|
747
|
+
if (!track.hasAttribute("tabindex")) track.setAttribute("tabindex", "0");
|
|
748
|
+
if (!track.hasAttribute("role")) track.setAttribute("role", "group");
|
|
749
|
+
if (!track.hasAttribute("aria-label")) track.setAttribute("aria-label", t("carousel.slides"));
|
|
750
|
+
|
|
751
|
+
slides.forEach((slide, idx) => {
|
|
752
|
+
if (!slide.hasAttribute("role")) slide.setAttribute("role", "group");
|
|
753
|
+
if (!slide.hasAttribute("aria-roledescription")) slide.setAttribute("aria-roledescription", t("carousel.slide"));
|
|
754
|
+
if (!slide.hasAttribute("aria-label")) slide.setAttribute("aria-label", t("carousel.position", { n: idx + 1, total: slides.length }));
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
let statusEl = el.querySelector("[data-carousel-status]");
|
|
758
|
+
if (!statusEl) {
|
|
759
|
+
statusEl = document.createElement("p");
|
|
760
|
+
statusEl.className = "bb-vh";
|
|
761
|
+
statusEl.setAttribute("data-carousel-status", "");
|
|
762
|
+
statusEl.setAttribute("role", "status");
|
|
763
|
+
statusEl.setAttribute("aria-live", "polite");
|
|
764
|
+
el.appendChild(statusEl);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
let current = Math.max(0, Number(el.dataset.index || 0)) % slides.length;
|
|
768
|
+
let settledIndex = current;
|
|
769
|
+
let pendingTarget = null;
|
|
770
|
+
let userInitiated = false;
|
|
771
|
+
let rafId = null;
|
|
772
|
+
let debounceTimer = null;
|
|
773
|
+
const loop = el.dataset.loop !== "false";
|
|
774
|
+
const autoplayMs = Number(el.dataset.autoplay || 0);
|
|
775
|
+
const dotsContainer = el.querySelector("[data-carousel-dots]");
|
|
776
|
+
const prevButton = el.querySelector("[data-carousel-prev]");
|
|
777
|
+
const nextButton = el.querySelector("[data-carousel-next]");
|
|
778
|
+
let timer = null;
|
|
779
|
+
|
|
780
|
+
if (dotsContainer && dotsContainer.children.length === 0) {
|
|
781
|
+
slides.forEach((_, idx) => {
|
|
782
|
+
const dot = document.createElement("button");
|
|
783
|
+
dot.type = "button";
|
|
784
|
+
dot.setAttribute("data-carousel-dot", String(idx));
|
|
785
|
+
dot.setAttribute("aria-label", t("carousel.goTo", { n: idx + 1 }));
|
|
786
|
+
dotsContainer.appendChild(dot);
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const syncDots = (idx) => {
|
|
791
|
+
el.dataset.index = String(idx);
|
|
792
|
+
el.querySelectorAll("[data-carousel-dot]").forEach((dot, i) => {
|
|
793
|
+
const active = i === idx;
|
|
794
|
+
dot.setAttribute("data-active", active ? "true" : "false");
|
|
795
|
+
dot.setAttribute("aria-current", active ? "true" : "false");
|
|
796
|
+
});
|
|
797
|
+
if (!loop && slides.length > 1) {
|
|
798
|
+
if (prevButton) {
|
|
799
|
+
const prevDisabled = idx === 0;
|
|
800
|
+
if (prevDisabled && document.activeElement === prevButton) nextButton?.focus();
|
|
801
|
+
prevButton.disabled = prevDisabled;
|
|
802
|
+
}
|
|
803
|
+
if (nextButton) {
|
|
804
|
+
const nextDisabled = idx === slides.length - 1;
|
|
805
|
+
if (nextDisabled && document.activeElement === nextButton) prevButton?.focus();
|
|
806
|
+
nextButton.disabled = nextDisabled;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const getNearestSlide = () => {
|
|
812
|
+
const center = track.scrollLeft + track.clientWidth / 2;
|
|
813
|
+
let best = 0;
|
|
814
|
+
let bestDist = Infinity;
|
|
815
|
+
slides.forEach((slide, i) => {
|
|
816
|
+
const slideCenter = slide.offsetLeft + slide.offsetWidth / 2;
|
|
817
|
+
const dist = Math.abs(slideCenter - center);
|
|
818
|
+
if (dist < bestDist) {
|
|
819
|
+
bestDist = dist;
|
|
820
|
+
best = i;
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
return best;
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
const goTo = (rawIdx, initiatedByUser) => {
|
|
827
|
+
const target = loop
|
|
828
|
+
? ((rawIdx % slides.length) + slides.length) % slides.length
|
|
829
|
+
: Math.max(0, Math.min(slides.length - 1, rawIdx));
|
|
830
|
+
if (initiatedByUser) userInitiated = true;
|
|
831
|
+
pendingTarget = target;
|
|
832
|
+
current = target;
|
|
833
|
+
syncDots(target);
|
|
834
|
+
const slide = slides[target];
|
|
835
|
+
if (!slide) return;
|
|
836
|
+
const targetLeft = Math.max(0, slide.offsetLeft - (track.clientWidth - slide.offsetWidth) / 2);
|
|
837
|
+
if (Math.abs(track.scrollLeft - targetLeft) < 1) {
|
|
838
|
+
pendingTarget = null;
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const reduced = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
842
|
+
track.scrollTo({ left: targetLeft, behavior: reduced ? "auto" : "smooth" });
|
|
843
|
+
};
|
|
844
|
+
|
|
845
|
+
const onSettle = () => {
|
|
846
|
+
const nearest = getNearestSlide();
|
|
847
|
+
pendingTarget = null;
|
|
848
|
+
current = nearest;
|
|
849
|
+
syncDots(nearest);
|
|
850
|
+
if (userInitiated && nearest !== settledIndex) {
|
|
851
|
+
statusEl.textContent = t("carousel.status", { n: nearest + 1, total: slides.length });
|
|
852
|
+
}
|
|
853
|
+
settledIndex = nearest;
|
|
854
|
+
userInitiated = false;
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
el.addEventListener("click", (e) => {
|
|
858
|
+
const base = pendingTarget !== null ? pendingTarget : current;
|
|
859
|
+
const prevBtn = e.target.closest("[data-carousel-prev]");
|
|
860
|
+
if (prevBtn) return goTo(base - 1, true);
|
|
861
|
+
const nextBtn = e.target.closest("[data-carousel-next]");
|
|
862
|
+
if (nextBtn) return goTo(base + 1, true);
|
|
863
|
+
const dotBtn = e.target.closest("[data-carousel-dot]");
|
|
864
|
+
if (dotBtn) return goTo(Number(dotBtn.getAttribute("data-carousel-dot")), true);
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
const supportsScrollEnd = "onscrollend" in window;
|
|
868
|
+
track.addEventListener("scroll", () => {
|
|
869
|
+
if (pendingTarget === null && !rafId) {
|
|
870
|
+
rafId = window.requestAnimationFrame(() => {
|
|
871
|
+
rafId = null;
|
|
872
|
+
const live = getNearestSlide();
|
|
873
|
+
if (live !== current) {
|
|
874
|
+
current = live;
|
|
875
|
+
syncDots(live);
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
if (!supportsScrollEnd) {
|
|
880
|
+
clearTimeout(debounceTimer);
|
|
881
|
+
debounceTimer = setTimeout(onSettle, 140);
|
|
882
|
+
}
|
|
883
|
+
}, { passive: true });
|
|
884
|
+
if (supportsScrollEnd) track.addEventListener("scrollend", onSettle);
|
|
885
|
+
|
|
886
|
+
const startAuto = () => {
|
|
887
|
+
if (autoplayMs > 0 && slides.length > 1) {
|
|
888
|
+
stopAuto();
|
|
889
|
+
timer = setInterval(() => {
|
|
890
|
+
const base = pendingTarget !== null ? pendingTarget : current;
|
|
891
|
+
goTo(base + 1, false);
|
|
892
|
+
}, autoplayMs);
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
const stopAuto = () => {
|
|
896
|
+
if (timer) {
|
|
897
|
+
clearInterval(timer);
|
|
898
|
+
timer = null;
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
el.addEventListener("mouseenter", stopAuto);
|
|
903
|
+
el.addEventListener("mouseleave", startAuto);
|
|
904
|
+
el.addEventListener("focusin", stopAuto);
|
|
905
|
+
el.addEventListener("focusout", (e) => {
|
|
906
|
+
if (!el.contains(e.relatedTarget)) startAuto();
|
|
907
|
+
});
|
|
908
|
+
syncDots(current);
|
|
909
|
+
startAuto();
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Attaches light-dismiss fallback (`closedby="any"`) and animated `cancel` interception to native `<dialog data-modal>`.
|
|
914
|
+
* @param {HTMLDialogElement} dialog
|
|
915
|
+
*/
|
|
916
|
+
function initModalDialog(dialog) {
|
|
917
|
+
if (!dialog || dialog.tagName !== "DIALOG" || dialog.dataset.bbDialogInit === "1") return;
|
|
918
|
+
dialog.dataset.bbDialogInit = "1";
|
|
919
|
+
if (!dialog.hasAttribute("closedby")) dialog.setAttribute("closedby", "any");
|
|
920
|
+
|
|
921
|
+
dialog.addEventListener("cancel", (e) => {
|
|
922
|
+
if (e.cancelable) {
|
|
923
|
+
e.preventDefault();
|
|
924
|
+
closeTopLayerDialog(dialog);
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
if (typeof HTMLDialogElement !== "undefined" && !("closedBy" in HTMLDialogElement.prototype)) {
|
|
929
|
+
const outside = (e) => {
|
|
930
|
+
const r = dialog.getBoundingClientRect();
|
|
931
|
+
return e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom;
|
|
932
|
+
};
|
|
933
|
+
let pressedOutside = false;
|
|
934
|
+
dialog.addEventListener("pointerdown", (e) => {
|
|
935
|
+
pressedOutside = outside(e);
|
|
936
|
+
});
|
|
937
|
+
dialog.addEventListener("pointerup", (e) => {
|
|
938
|
+
if (pressedOutside && outside(e) && dialog.getAttribute("closedby") === "any") {
|
|
939
|
+
closeTopLayerDialog(dialog);
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Opens or closes a `[data-modal]` element by id using native `<dialog>` when available.
|
|
947
|
+
* @param {string} id
|
|
948
|
+
* @param {boolean} open
|
|
949
|
+
*/
|
|
950
|
+
function setModal(id, open) {
|
|
951
|
+
const modal = document.querySelector('[data-modal="' + CSS.escape(id) + '"]') || document.getElementById(id);
|
|
952
|
+
if (!modal) return;
|
|
953
|
+
if (typeof modal.showModal === "function") {
|
|
954
|
+
initModalDialog(modal);
|
|
955
|
+
if (open && !modal.open) {
|
|
956
|
+
modal.removeAttribute("data-closing");
|
|
957
|
+
modal.showModal();
|
|
958
|
+
} else if (!open && modal.open) {
|
|
959
|
+
closeTopLayerDialog(modal);
|
|
960
|
+
}
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
modal.classList.toggle("hidden", !open);
|
|
964
|
+
modal.setAttribute("aria-hidden", open ? "false" : "true");
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Submits a `[data-form]` HTML form via fetch with CSRF header, loading state, and inline field errors.
|
|
969
|
+
* @param {HTMLFormElement} form
|
|
970
|
+
*/
|
|
971
|
+
async function submitDeclarativeForm(form) {
|
|
972
|
+
const url = form.getAttribute("action") || window.location.pathname;
|
|
973
|
+
const method = (form.getAttribute("method") || "POST").toUpperCase();
|
|
974
|
+
const submits = Array.from(form.querySelectorAll('button[type="submit"], input[type="submit"]'));
|
|
975
|
+
submits.forEach((btn) => {
|
|
976
|
+
btn.disabled = true;
|
|
977
|
+
btn.setAttribute("aria-busy", "true");
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
form.querySelectorAll("[data-error-for]").forEach((el) => {
|
|
981
|
+
el.textContent = "";
|
|
982
|
+
el.classList.add("hidden");
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
try {
|
|
986
|
+
const formData = new FormData(form);
|
|
987
|
+
const hasFiles = Array.from(form.elements).some((el) => el.type === "file" && el.files && el.files.length > 0);
|
|
988
|
+
const headers = { Accept: "application/json" };
|
|
989
|
+
const csrf = getCsrfToken();
|
|
990
|
+
if (csrf) headers["X-CSRF-Token"] = csrf;
|
|
991
|
+
|
|
992
|
+
let body;
|
|
993
|
+
if (hasFiles || form.dataset.formMode === "multipart") {
|
|
994
|
+
body = formData;
|
|
995
|
+
} else {
|
|
996
|
+
headers["Content-Type"] = "application/json";
|
|
997
|
+
const obj = {};
|
|
998
|
+
formData.forEach((val, key) => {
|
|
999
|
+
if (key in obj) obj[key] = [].concat(obj[key], val);
|
|
1000
|
+
else obj[key] = val;
|
|
1001
|
+
});
|
|
1002
|
+
body = JSON.stringify(obj);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
const res = await fetch(url, {
|
|
1006
|
+
method,
|
|
1007
|
+
credentials: "same-origin",
|
|
1008
|
+
headers,
|
|
1009
|
+
body: method === "GET" || method === "HEAD" ? undefined : body,
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
const payload = (res.headers.get("Content-Type") || "").includes("application/json") ? await res.json() : {};
|
|
1013
|
+
if (!res.ok || payload?.status === "error") {
|
|
1014
|
+
const rawErrs = payload?.errors;
|
|
1015
|
+
if (Array.isArray(rawErrs)) {
|
|
1016
|
+
rawErrs.forEach((item) => {
|
|
1017
|
+
if (!item?.field) return;
|
|
1018
|
+
const target = form.querySelector('[data-error-for="' + CSS.escape(item.field) + '"]');
|
|
1019
|
+
if (target) {
|
|
1020
|
+
target.textContent = item.message || t("value.invalid");
|
|
1021
|
+
target.classList.remove("hidden");
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
} else if (rawErrs && typeof rawErrs === "object") {
|
|
1025
|
+
Object.entries(rawErrs).forEach(([field, msg]) => {
|
|
1026
|
+
const target = form.querySelector('[data-error-for="' + CSS.escape(field) + '"]');
|
|
1027
|
+
if (target) {
|
|
1028
|
+
target.textContent = String(msg);
|
|
1029
|
+
target.classList.remove("hidden");
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
const msg = Array.isArray(payload?.message) ? payload.message.join(", ") : payload?.message;
|
|
1034
|
+
toast.error(t("form.validation"), msg || t("request.failed"));
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
if (form.dataset.toastSuccess) {
|
|
1039
|
+
toast.success(form.dataset.toastSuccess);
|
|
1040
|
+
} else if (payload?.message) {
|
|
1041
|
+
toast.success(payload.message);
|
|
1042
|
+
}
|
|
1043
|
+
if (form.dataset.reset !== "false") {
|
|
1044
|
+
form.reset();
|
|
1045
|
+
}
|
|
1046
|
+
if (payload?.redirect) {
|
|
1047
|
+
window.location.href = payload.redirect;
|
|
1048
|
+
}
|
|
1049
|
+
} catch (err) {
|
|
1050
|
+
toast.error(t("request.failed"), err?.message || t("request.network"));
|
|
1051
|
+
} finally {
|
|
1052
|
+
submits.forEach((btn) => {
|
|
1053
|
+
btn.disabled = false;
|
|
1054
|
+
btn.removeAttribute("aria-busy");
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
const DT_ICONS = {
|
|
1060
|
+
search: '<path d="m21 21-4.34-4.34"/><path d="M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16Z"/>',
|
|
1061
|
+
view: '<path d="M2.06 12.35a1 1 0 0 1 0-.7 10.75 10.75 0 0 1 19.88 0 1 1 0 0 1 0 .7 10.75 10.75 0 0 1-19.88 0"/><path d="M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/>',
|
|
1062
|
+
edit: '<path d="M21.17 6.81a1 1 0 0 0-3.99-3.99L3.84 16.17a2 2 0 0 0-.5.83l-1.32 4.35a.5.5 0 0 0 .62.62l4.35-1.32a2 2 0 0 0 .83-.5Z"/><path d="m15 5 4 4"/>',
|
|
1063
|
+
delete: '<path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><path d="M10 11v6"/><path d="M14 11v6"/>',
|
|
1064
|
+
prev: '<path d="m15 18-6-6 6-6"/>',
|
|
1065
|
+
next: '<path d="m9 18 6-6-6-6"/>',
|
|
1066
|
+
sortNone: '<path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/>',
|
|
1067
|
+
sortAsc: '<path d="m5 12 7-7 7 7"/><path d="M12 19V5"/>',
|
|
1068
|
+
sortDesc: '<path d="M12 5v14"/><path d="m19 12-7 7-7-7"/>',
|
|
1069
|
+
chevron: '<path d="m6 9 6 6 6-6"/>',
|
|
1070
|
+
};
|
|
1071
|
+
const DT_TONES = { info: "var(--info,#0284c7)", success: "var(--success,#16a34a)", warning: "var(--warning,#d97706)", danger: "var(--destructive,#dc2626)", error: "var(--destructive,#dc2626)" };
|
|
1072
|
+
let dtStylesInjected = false;
|
|
1073
|
+
|
|
1074
|
+
/**
|
|
1075
|
+
* Injects the self-contained DataTable styles (theme tokens with fallbacks, container-query responsive layout).
|
|
1076
|
+
*/
|
|
1077
|
+
function ensureDataTableStyles() {
|
|
1078
|
+
if (dtStylesInjected || !document.head) return;
|
|
1079
|
+
dtStylesInjected = true;
|
|
1080
|
+
const style = document.createElement("style");
|
|
1081
|
+
style.setAttribute("data-bb-datatable", "true");
|
|
1082
|
+
style.textContent = [
|
|
1083
|
+
".bb-dt{container-type:inline-size;overflow:hidden;border:1px solid var(--border,#e4e4e7);border-radius:1rem;background:var(--card,#fff);color:var(--card-foreground,#18181b);box-shadow:0 1px 2px rgba(0,0,0,.04);font-size:.875rem}",
|
|
1084
|
+
".bb-dt svg{width:1rem;height:1rem;flex-shrink:0;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}",
|
|
1085
|
+
".bb-dt-bar{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:.75rem;padding:.75rem;border-bottom:1px solid var(--border,#e4e4e7)}",
|
|
1086
|
+
".bb-dt-search{position:relative;width:100%;max-width:18rem}.bb-dt-search svg{position:absolute;left:.75rem;top:50%;transform:translateY(-50%);color:var(--muted-foreground,#71717a);pointer-events:none}.bb-dt-search input{height:2.25rem;padding-left:2.25rem}",
|
|
1087
|
+
".bb-dt-table{display:none;overflow-x:auto}.bb-dt table{width:100%;border-collapse:collapse}",
|
|
1088
|
+
"@container (min-width:42rem){.bb-dt-table{display:block}.bb-dt-cards{display:none}}",
|
|
1089
|
+
".bb-dt th{height:2.5rem;padding:0 1rem;text-align:left;white-space:nowrap;font-size:.75rem;font-weight:500;color:var(--muted-foreground,#71717a);background:color-mix(in oklab,var(--muted,#f4f4f5) 40%,transparent);border-bottom:1px solid var(--border,#e4e4e7)}",
|
|
1090
|
+
".bb-dt td{padding:.75rem 1rem;vertical-align:middle;border-top:1px solid color-mix(in oklab,var(--border,#e4e4e7) 70%,transparent)}.bb-dt tbody tr:first-child td{border-top:0}",
|
|
1091
|
+
".bb-dt tbody tr{transition:background-color .15s}.bb-dt tbody tr:hover{background:color-mix(in oklab,var(--accent,#f4f4f5) 40%,transparent)}",
|
|
1092
|
+
".bb-dt .bb-dt-right{text-align:right}.bb-dt .bb-dt-center{text-align:center}.bb-dt .bb-dt-num{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-variant-numeric:tabular-nums}.bb-dt .bb-dt-primary{font-weight:500}",
|
|
1093
|
+
".bb-dt-sort{display:inline-flex;align-items:center;gap:.25rem;margin:0 -.5rem;padding:.25rem .5rem;border:0;border-radius:.375rem;background:transparent;color:inherit;font:inherit;cursor:pointer}.bb-dt-sort:hover,.bb-dt-sort[data-active]{color:var(--foreground,#18181b)}.bb-dt-sort:hover{background:var(--accent,#f4f4f5)}.bb-dt-sort svg{width:.875rem;height:.875rem}.bb-dt-sort:not([data-active]) svg{opacity:.4}",
|
|
1094
|
+
".bb-dt-actions{display:flex;align-items:center;justify-content:flex-end;gap:.125rem}.bb-dt-actions .btn{color:var(--muted-foreground,#71717a)}.bb-dt-actions .btn:hover{color:var(--foreground,#18181b)}.bb-dt-actions .bb-dt-danger,.bb-dt-actions .bb-dt-danger:hover{color:var(--destructive,#dc2626)}",
|
|
1095
|
+
".bb-dt-cards{list-style:none;margin:0;padding:0}.bb-dt-cards>li{padding:1rem;border-top:1px solid color-mix(in oklab,var(--border,#e4e4e7) 70%,transparent)}.bb-dt-cards>li:first-child{border-top:0}",
|
|
1096
|
+
".bb-dt-card-head{display:flex;align-items:flex-start;justify-content:space-between;gap:.75rem}.bb-dt-card-title{min-width:0;flex:1;font-weight:500}.bb-dt-card-head .bb-dt-actions{margin:-.25rem -.5rem 0 0}",
|
|
1097
|
+
".bb-dt dl{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:.75rem 1rem;margin:.75rem 0 0}.bb-dt dt{font-size:.75rem;color:var(--muted-foreground,#71717a)}.bb-dt dd{margin:.125rem 0 0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
1098
|
+
".bb-dt-details{border-top:1px solid color-mix(in oklab,var(--border,#e4e4e7) 70%,transparent);padding-top:.75rem}",
|
|
1099
|
+
".bb-dt-toggle{display:inline-flex;align-items:center;gap:.25rem;margin-top:.75rem;padding:0;border:0;background:transparent;color:var(--muted-foreground,#71717a);font:inherit;font-size:.75rem;font-weight:500;cursor:pointer}.bb-dt-toggle:hover{color:var(--foreground,#18181b)}.bb-dt-toggle svg{width:.875rem;height:.875rem;transition:transform .2s}.bb-dt-toggle[aria-expanded=true] svg{transform:rotate(180deg)}",
|
|
1100
|
+
".bb-dt-foot{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:.75rem;padding:.625rem 1rem;border-top:1px solid var(--border,#e4e4e7);font-size:.75rem;color:var(--muted-foreground,#71717a);font-variant-numeric:tabular-nums}.bb-dt-foot>div{display:flex;align-items:center;gap:.75rem}.bb-dt-foot label{display:inline-flex;align-items:center;gap:.5rem}.bb-dt-foot select{height:2rem;width:auto;padding-top:0;padding-bottom:0;font-size:.75rem}.bb-dt-foot .btn{width:2rem;height:2rem}.bb-dt-foot[hidden]{display:none}",
|
|
1101
|
+
".bb-dt-empty{padding:3rem 1.5rem;text-align:center;color:var(--muted-foreground,#71717a)}",
|
|
1102
|
+
".bb-dt-badge{display:inline-flex;align-items:center;gap:.375rem;border:1px solid color-mix(in oklab,var(--border,#e4e4e7) 80%,transparent);border-radius:9999px;padding:.125rem .625rem;background:color-mix(in oklab,var(--secondary,#f4f4f5) 75%,transparent);font-size:.75rem;font-weight:500}.bb-dt-badge i{width:.375rem;height:.375rem;border-radius:9999px}",
|
|
1103
|
+
".bb-dt[aria-busy=true] tbody,.bb-dt[aria-busy=true] .bb-dt-cards{opacity:.6;transition:opacity .15s}",
|
|
1104
|
+
".bb-dt-sk{display:block;height:.875rem;width:75%;border-radius:.375rem;background:var(--muted,#f4f4f5);animation:bb-dt-pulse 1.5s ease-in-out infinite}@keyframes bb-dt-pulse{50%{opacity:.45}}",
|
|
1105
|
+
"dialog.bb-dt-dialog{width:calc(100% - 2rem);max-width:24rem;margin:auto;padding:1.5rem;border:1px solid var(--border,#e4e4e7);border-radius:1rem;background:var(--popover,#fff);color:var(--popover-foreground,#18181b);box-shadow:0 24px 48px -12px rgba(0,0,0,.35)}",
|
|
1106
|
+
"dialog.bb-dt-dialog h2{margin:0;font-size:1.0625rem;font-weight:600}dialog.bb-dt-dialog p{margin:.25rem 0 0;font-size:.875rem;color:var(--muted-foreground,#71717a)}dialog.bb-dt-dialog .bb-dt-dialog-actions{display:flex;justify-content:flex-end;gap:.5rem;margin-top:1.5rem}",
|
|
1107
|
+
].join("");
|
|
1108
|
+
document.head.appendChild(style);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Creates an inline SVG icon element.
|
|
1113
|
+
* @param {keyof typeof DT_ICONS} name
|
|
1114
|
+
* @returns {SVGSVGElement}
|
|
1115
|
+
*/
|
|
1116
|
+
function dtIcon(name) {
|
|
1117
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1118
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
1119
|
+
svg.setAttribute("aria-hidden", "true");
|
|
1120
|
+
svg.innerHTML = DT_ICONS[name];
|
|
1121
|
+
return svg;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Creates an element with a class name and optional text content.
|
|
1126
|
+
* @param {string} tag
|
|
1127
|
+
* @param {string} [className]
|
|
1128
|
+
* @param {string} [text]
|
|
1129
|
+
* @returns {HTMLElement}
|
|
1130
|
+
*/
|
|
1131
|
+
function dtEl(tag, className, text) {
|
|
1132
|
+
const el = document.createElement(tag);
|
|
1133
|
+
if (className) el.className = className;
|
|
1134
|
+
if (text !== undefined && text !== null) el.textContent = String(text);
|
|
1135
|
+
return el;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* Builds a link from a pattern such as `/users/:id` or `/users/{id}/edit`.
|
|
1140
|
+
* @param {string|Function} pattern
|
|
1141
|
+
* @param {Record<string, any>} row
|
|
1142
|
+
* @returns {string}
|
|
1143
|
+
*/
|
|
1144
|
+
function dtHref(pattern, row) {
|
|
1145
|
+
if (typeof pattern === "function") return pattern(row);
|
|
1146
|
+
return String(pattern).replace(/:(\w+)|\{(\w+)\}/g, (_, a, b) => encodeURIComponent(String(row?.[a || b] ?? "")));
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* Reads a (dotted) column value from a row.
|
|
1151
|
+
* @param {Record<string, any>} row
|
|
1152
|
+
* @param {{ key: string, value?: Function }} column
|
|
1153
|
+
*/
|
|
1154
|
+
function dtValue(row, column) {
|
|
1155
|
+
if (typeof column.value === "function") return column.value(row);
|
|
1156
|
+
return String(column.key).split(".").reduce((acc, part) => (acc == null ? acc : acc[part]), row);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* Renders a cell into a node: `render(row)` (string or Node), or a declarative `format`
|
|
1161
|
+
* (`badge`, `number`, `currency`, `date`, `datetime`, `boolean`). Values are always inserted as text.
|
|
1162
|
+
* @param {Record<string, any>} row
|
|
1163
|
+
* @param {Object} column
|
|
1164
|
+
* @returns {Node}
|
|
1165
|
+
*/
|
|
1166
|
+
function dtCell(row, column) {
|
|
1167
|
+
if (typeof column.render === "function") {
|
|
1168
|
+
const out = column.render(row);
|
|
1169
|
+
return out instanceof Node ? out : document.createTextNode(out == null ? "" : String(out));
|
|
1170
|
+
}
|
|
1171
|
+
const value = dtValue(row, column);
|
|
1172
|
+
if (value === null || value === undefined || value === "") {
|
|
1173
|
+
const dash = dtEl("span", "", "—");
|
|
1174
|
+
dash.style.color = "var(--muted-foreground,#71717a)";
|
|
1175
|
+
return dash;
|
|
1176
|
+
}
|
|
1177
|
+
const lang = getLocale();
|
|
1178
|
+
switch (column.format) {
|
|
1179
|
+
case "badge": {
|
|
1180
|
+
const badge = dtEl("span", "bb-dt-badge");
|
|
1181
|
+
const tone = column.tones?.[value];
|
|
1182
|
+
if (tone && DT_TONES[tone]) {
|
|
1183
|
+
const dot = dtEl("i");
|
|
1184
|
+
dot.style.background = DT_TONES[tone];
|
|
1185
|
+
badge.appendChild(dot);
|
|
1186
|
+
}
|
|
1187
|
+
badge.appendChild(document.createTextNode(String(value)));
|
|
1188
|
+
return badge;
|
|
1189
|
+
}
|
|
1190
|
+
case "number":
|
|
1191
|
+
return document.createTextNode(Number(value).toLocaleString(lang));
|
|
1192
|
+
case "currency":
|
|
1193
|
+
return document.createTextNode(Number(value).toLocaleString(lang, { style: "currency", currency: column.currency || "USD" }));
|
|
1194
|
+
case "date":
|
|
1195
|
+
case "datetime": {
|
|
1196
|
+
const dateOnly = typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value);
|
|
1197
|
+
const date = dateOnly ? new Date(Number(value.slice(0, 4)), Number(value.slice(5, 7)) - 1, Number(value.slice(8, 10))) : new Date(value);
|
|
1198
|
+
if (Number.isNaN(date.getTime())) return document.createTextNode(String(value));
|
|
1199
|
+
return document.createTextNode(column.format === "date" ? date.toLocaleDateString(lang) : date.toLocaleString(lang));
|
|
1200
|
+
}
|
|
1201
|
+
case "boolean":
|
|
1202
|
+
return document.createTextNode(value ? "✓" : "—");
|
|
1203
|
+
default:
|
|
1204
|
+
return document.createTextNode(String(value));
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Normalizes a server response (`res.paginate()`, `res.ok(Model.paginate())`, or an array) into rows and total.
|
|
1210
|
+
* @param {any} body
|
|
1211
|
+
* @returns {{ rows: any[], total: number }}
|
|
1212
|
+
*/
|
|
1213
|
+
function dtNormalize(body) {
|
|
1214
|
+
if (Array.isArray(body)) return { rows: body, total: body.length };
|
|
1215
|
+
const data = body?.data;
|
|
1216
|
+
if (Array.isArray(data)) return { rows: data, total: Number(body.pagination?.total ?? body.total ?? data.length) };
|
|
1217
|
+
if (data && Array.isArray(data.data)) return { rows: data.data, total: Number(data.total ?? data.pagination?.total ?? data.data.length) };
|
|
1218
|
+
return { rows: [], total: 0 };
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Opens a native confirmation `<dialog>` and resolves `true` when confirmed.
|
|
1223
|
+
* @param {{ title: string, text: string, confirmLabel: string, danger?: boolean }} options
|
|
1224
|
+
* @returns {Promise<boolean>}
|
|
1225
|
+
*/
|
|
1226
|
+
function dtConfirm({ title, text, confirmLabel, danger }) {
|
|
1227
|
+
if (typeof HTMLDialogElement === "undefined") return Promise.resolve(window.confirm(title));
|
|
1228
|
+
return new Promise((resolve) => {
|
|
1229
|
+
const dialog = dtEl("dialog", "bb-dt-dialog");
|
|
1230
|
+
dialog.setAttribute("data-modal", "");
|
|
1231
|
+
dialog.setAttribute("aria-labelledby", "bb-dt-dialog-title");
|
|
1232
|
+
const heading = dtEl("h2", "", title);
|
|
1233
|
+
heading.id = "bb-dt-dialog-title";
|
|
1234
|
+
const actions = dtEl("div", "bb-dt-dialog-actions");
|
|
1235
|
+
const cancel = dtEl("button", "btn btn-outline", t("table.cancel"));
|
|
1236
|
+
cancel.type = "button";
|
|
1237
|
+
const ok = dtEl("button", danger ? "btn btn-danger" : "btn btn-primary", confirmLabel);
|
|
1238
|
+
ok.type = "button";
|
|
1239
|
+
actions.append(cancel, ok);
|
|
1240
|
+
dialog.append(heading, dtEl("p", "", text), actions);
|
|
1241
|
+
document.body.appendChild(dialog);
|
|
1242
|
+
let result = false;
|
|
1243
|
+
dialog.addEventListener("close", () => {
|
|
1244
|
+
dialog.remove();
|
|
1245
|
+
resolve(result);
|
|
1246
|
+
});
|
|
1247
|
+
cancel.addEventListener("click", () => closeTopLayerDialog(dialog));
|
|
1248
|
+
ok.addEventListener("click", () => {
|
|
1249
|
+
result = true;
|
|
1250
|
+
closeTopLayerDialog(dialog);
|
|
1251
|
+
});
|
|
1252
|
+
initModalDialog(dialog);
|
|
1253
|
+
dialog.showModal();
|
|
1254
|
+
cancel.focus();
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Creates a responsive DataTable inside `el`: search, sortable columns, pagination with page sizes, view/edit/delete
|
|
1260
|
+
* and custom actions (delete asks in a native dialog), and cards with expandable details in narrow containers.
|
|
1261
|
+
* Data comes from `rows` or a server `url` (`?page&limit&search&sort&order`, answered with `res.paginate()`).
|
|
1262
|
+
* Every action also dispatches a bubbling `bluebird:datatable` event with `{ action, row }`.
|
|
1263
|
+
* @param {HTMLElement|string} target
|
|
1264
|
+
* @param {Object} options
|
|
1265
|
+
* @returns {{ reload: () => Promise<void>, setRows: (rows: any[]) => void, destroy: () => void }}
|
|
1266
|
+
*/
|
|
1267
|
+
function dataTable(target, options = {}) {
|
|
1268
|
+
const el = typeof target === "string" ? document.querySelector(target) : target;
|
|
1269
|
+
if (!el) throw new Error("Bluebird.dataTable: element not found");
|
|
1270
|
+
if (el.__bbDataTable) return el.__bbDataTable;
|
|
1271
|
+
ensureStyles();
|
|
1272
|
+
ensureDataTableStyles();
|
|
1273
|
+
|
|
1274
|
+
const columns = Array.isArray(options.columns) ? options.columns : [];
|
|
1275
|
+
const url = options.url || null;
|
|
1276
|
+
const pageSizes = Array.isArray(options.pageSizes) ? options.pageSizes : [10, 25, 50];
|
|
1277
|
+
const state = {
|
|
1278
|
+
rows: Array.isArray(options.rows) ? options.rows : [],
|
|
1279
|
+
total: 0,
|
|
1280
|
+
page: 1,
|
|
1281
|
+
limit: Number(options.pageSize) || 10,
|
|
1282
|
+
query: "",
|
|
1283
|
+
sort: options.defaultSort?.key ? { key: options.defaultSort.key, dir: options.defaultSort.dir === "desc" ? -1 : 1 } : { key: null, dir: 1 },
|
|
1284
|
+
loading: Boolean(url),
|
|
1285
|
+
expanded: new Set(),
|
|
1286
|
+
};
|
|
1287
|
+
let requestSeq = 0;
|
|
1288
|
+
let searchTimer = null;
|
|
1289
|
+
|
|
1290
|
+
const actionList = [];
|
|
1291
|
+
const pushBuiltIn = (name, label, value, extra = {}) => {
|
|
1292
|
+
if (!value) return;
|
|
1293
|
+
actionList.push({ action: name, label, icon: name, ...(typeof value === "string" ? { href: value } : typeof value === "function" ? { onClick: value } : value), ...extra });
|
|
1294
|
+
};
|
|
1295
|
+
pushBuiltIn("view", t("table.view"), options.onView);
|
|
1296
|
+
pushBuiltIn("edit", t("table.edit"), options.onEdit);
|
|
1297
|
+
(options.actions || []).forEach((a) => {
|
|
1298
|
+
if (a.action === "view" || a.action === "edit" || a.action === "delete") {
|
|
1299
|
+
actionList.push({ icon: a.action, label: t("table." + a.action), ...(a.action === "delete" ? { variant: "danger", confirm: true } : {}), ...a });
|
|
1300
|
+
} else {
|
|
1301
|
+
actionList.push(a);
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
pushBuiltIn("delete", t("table.delete"), options.onDelete, { variant: "danger", confirm: options.deleteConfirm === false ? false : options.deleteConfirm || true });
|
|
1305
|
+
|
|
1306
|
+
const primary = columns.find((c) => c.primary) || columns[0];
|
|
1307
|
+
const mobileCols = columns.filter((c) => c !== primary && c.mobile !== false);
|
|
1308
|
+
const summaryCols = mobileCols.filter((c) => c.mobile !== "details").slice(0, 4);
|
|
1309
|
+
const detailCols = mobileCols.filter((c) => !summaryCols.includes(c));
|
|
1310
|
+
const alignClass = (c) => (c.align === "right" || c.numeric || c.format === "number" || c.format === "currency" ? "bb-dt-right" : c.align === "center" ? "bb-dt-center" : "");
|
|
1311
|
+
|
|
1312
|
+
el.innerHTML = "";
|
|
1313
|
+
const root = dtEl("div", "bb-dt");
|
|
1314
|
+
const bar = dtEl("div", "bb-dt-bar");
|
|
1315
|
+
const searchWrap = dtEl("div", "bb-dt-search");
|
|
1316
|
+
const search = dtEl("input", "field");
|
|
1317
|
+
search.type = "search";
|
|
1318
|
+
search.placeholder = options.searchPlaceholder || t("table.search");
|
|
1319
|
+
search.setAttribute("aria-label", search.placeholder);
|
|
1320
|
+
searchWrap.append(dtIcon("search"), search);
|
|
1321
|
+
if (options.searchable !== false) bar.appendChild(searchWrap);
|
|
1322
|
+
const tableWrap = dtEl("div", "bb-dt-table");
|
|
1323
|
+
const table = dtEl("table");
|
|
1324
|
+
if (options.caption) table.appendChild(Object.assign(dtEl("caption", "bb-vh"), { textContent: options.caption }));
|
|
1325
|
+
const thead = dtEl("thead");
|
|
1326
|
+
const tbody = dtEl("tbody");
|
|
1327
|
+
table.append(thead, tbody);
|
|
1328
|
+
tableWrap.appendChild(table);
|
|
1329
|
+
const cards = dtEl("ul", "bb-dt-cards");
|
|
1330
|
+
const foot = dtEl("div", "bb-dt-foot");
|
|
1331
|
+
if (bar.children.length) root.appendChild(bar);
|
|
1332
|
+
root.append(tableWrap, cards, foot);
|
|
1333
|
+
el.appendChild(root);
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* Rows visible on the current page plus the total after search and sort.
|
|
1337
|
+
* @returns {{ rows: any[], total: number }}
|
|
1338
|
+
*/
|
|
1339
|
+
const view = () => {
|
|
1340
|
+
if (url) return { rows: state.rows, total: state.total };
|
|
1341
|
+
const q = state.query.trim().toLowerCase();
|
|
1342
|
+
let list = q
|
|
1343
|
+
? state.rows.filter((row) => columns.some((c) => c.searchable !== false && String(dtValue(row, c) ?? "").toLowerCase().includes(q)))
|
|
1344
|
+
: state.rows;
|
|
1345
|
+
if (state.sort.key) {
|
|
1346
|
+
const col = columns.find((c) => c.key === state.sort.key) || { key: state.sort.key };
|
|
1347
|
+
list = [...list].sort((a, b) => {
|
|
1348
|
+
const x = dtValue(a, col);
|
|
1349
|
+
const y = dtValue(b, col);
|
|
1350
|
+
if (x === y) return 0;
|
|
1351
|
+
if (x == null || x === "") return 1;
|
|
1352
|
+
if (y == null || y === "") return -1;
|
|
1353
|
+
const cmp = typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y), undefined, { numeric: true, sensitivity: "base" });
|
|
1354
|
+
return cmp * state.sort.dir;
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
const pages = Math.max(1, Math.ceil(list.length / state.limit));
|
|
1358
|
+
if (state.page > pages) state.page = pages;
|
|
1359
|
+
return { rows: list.slice((state.page - 1) * state.limit, state.page * state.limit), total: list.length };
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* Runs an action: navigation, confirmation, handler, declarative request, event, and reload.
|
|
1364
|
+
* @param {Object} action
|
|
1365
|
+
* @param {Record<string, any>} row
|
|
1366
|
+
*/
|
|
1367
|
+
const runAction = async (action, row) => {
|
|
1368
|
+
if (action.confirm) {
|
|
1369
|
+
const ok = await dtConfirm({
|
|
1370
|
+
title: action.action === "delete" ? t("table.confirmTitle") : action.label,
|
|
1371
|
+
text: typeof action.confirm === "string" ? action.confirm : t("table.confirmText"),
|
|
1372
|
+
confirmLabel: action.label,
|
|
1373
|
+
danger: action.variant === "danger",
|
|
1374
|
+
});
|
|
1375
|
+
if (!ok) return;
|
|
1376
|
+
}
|
|
1377
|
+
el.dispatchEvent(new CustomEvent("bluebird:datatable", { bubbles: true, detail: { action: action.action || action.label, row } }));
|
|
1378
|
+
try {
|
|
1379
|
+
if (typeof action.onClick === "function") await action.onClick(row);
|
|
1380
|
+
if (action.url) {
|
|
1381
|
+
const headers = { Accept: "application/json" };
|
|
1382
|
+
const csrf = getCsrfToken();
|
|
1383
|
+
if (csrf) headers["X-CSRF-Token"] = csrf;
|
|
1384
|
+
const res = await fetch(dtHref(action.url, row), { method: (action.method || (action.action === "delete" ? "DELETE" : "POST")).toUpperCase(), credentials: "same-origin", headers });
|
|
1385
|
+
const payload = (res.headers.get("Content-Type") || "").includes("application/json") ? await res.json() : {};
|
|
1386
|
+
if (!res.ok || payload?.status === "error") throw new Error(payload?.message || t("request.failed"));
|
|
1387
|
+
if (payload?.message) toast.success(payload.message);
|
|
1388
|
+
}
|
|
1389
|
+
if (!url && action.action === "delete") {
|
|
1390
|
+
const key = options.rowKey || "id";
|
|
1391
|
+
state.rows = state.rows.filter((r) => r[key] !== row[key]);
|
|
1392
|
+
}
|
|
1393
|
+
if (url && (action.url || action.action === "delete" || action.reload)) await load();
|
|
1394
|
+
else render();
|
|
1395
|
+
} catch (err) {
|
|
1396
|
+
toast.error(err?.message || t("request.failed"));
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* Renders the action buttons for a row.
|
|
1402
|
+
* @param {Record<string, any>} row
|
|
1403
|
+
* @returns {HTMLElement|null}
|
|
1404
|
+
*/
|
|
1405
|
+
const actionsFor = (row) => {
|
|
1406
|
+
const list = actionList.filter((a) => !(typeof a.hidden === "function" && a.hidden(row)) && !(a.when && String(row[a.when.key]) !== String(a.when.value)));
|
|
1407
|
+
if (!list.length) return null;
|
|
1408
|
+
const wrap = dtEl("div", "bb-dt-actions");
|
|
1409
|
+
list.forEach((a) => {
|
|
1410
|
+
const withIcon = Boolean(a.icon && DT_ICONS[a.icon]);
|
|
1411
|
+
const cls = "btn btn-ghost btn-sm" + (withIcon ? " btn-icon" : "") + (a.variant === "danger" ? " bb-dt-danger" : "");
|
|
1412
|
+
const node = a.href ? dtEl("a", cls) : dtEl("button", cls);
|
|
1413
|
+
if (a.href) node.href = dtHref(a.href, row);
|
|
1414
|
+
else node.type = "button";
|
|
1415
|
+
node.setAttribute("aria-label", a.label);
|
|
1416
|
+
node.title = a.label;
|
|
1417
|
+
if (withIcon) node.appendChild(dtIcon(a.icon));
|
|
1418
|
+
else node.textContent = a.label;
|
|
1419
|
+
node.addEventListener("click", (e) => {
|
|
1420
|
+
e.stopPropagation();
|
|
1421
|
+
if (a.href) return;
|
|
1422
|
+
runAction(a, row);
|
|
1423
|
+
});
|
|
1424
|
+
wrap.appendChild(node);
|
|
1425
|
+
});
|
|
1426
|
+
return wrap;
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* Renders the header, rows, cards, and footer.
|
|
1431
|
+
*/
|
|
1432
|
+
const render = () => {
|
|
1433
|
+
const { rows, total } = view();
|
|
1434
|
+
const hasActions = actionList.length > 0;
|
|
1435
|
+
root.setAttribute("aria-busy", state.loading && state.rows.length ? "true" : "false");
|
|
1436
|
+
|
|
1437
|
+
const headRow = dtEl("tr");
|
|
1438
|
+
columns.forEach((c) => {
|
|
1439
|
+
const th = dtEl("th", alignClass(c));
|
|
1440
|
+
th.scope = "col";
|
|
1441
|
+
if (state.sort.key === c.key) th.setAttribute("aria-sort", state.sort.dir === 1 ? "ascending" : "descending");
|
|
1442
|
+
if (c.sortable) {
|
|
1443
|
+
const btn = dtEl("button", "bb-dt-sort", c.label);
|
|
1444
|
+
btn.type = "button";
|
|
1445
|
+
btn.title = t("table.sortBy", { column: c.label });
|
|
1446
|
+
if (state.sort.key === c.key) btn.setAttribute("data-active", "");
|
|
1447
|
+
btn.appendChild(dtIcon(state.sort.key !== c.key ? "sortNone" : state.sort.dir === 1 ? "sortAsc" : "sortDesc"));
|
|
1448
|
+
btn.addEventListener("click", () => {
|
|
1449
|
+
state.sort = state.sort.key !== c.key ? { key: c.key, dir: 1 } : state.sort.dir === 1 ? { key: c.key, dir: -1 } : { key: null, dir: 1 };
|
|
1450
|
+
state.page = 1;
|
|
1451
|
+
url ? load() : render();
|
|
1452
|
+
});
|
|
1453
|
+
th.appendChild(btn);
|
|
1454
|
+
} else {
|
|
1455
|
+
th.textContent = c.label;
|
|
1456
|
+
}
|
|
1457
|
+
headRow.appendChild(th);
|
|
1458
|
+
});
|
|
1459
|
+
if (hasActions) {
|
|
1460
|
+
const th = dtEl("th", "bb-dt-right");
|
|
1461
|
+
th.appendChild(dtEl("span", "bb-vh", t("table.actions")));
|
|
1462
|
+
headRow.appendChild(th);
|
|
1463
|
+
}
|
|
1464
|
+
thead.replaceChildren(headRow);
|
|
1465
|
+
|
|
1466
|
+
const showSkeleton = state.loading && !state.rows.length;
|
|
1467
|
+
tbody.replaceChildren();
|
|
1468
|
+
cards.replaceChildren();
|
|
1469
|
+
if (showSkeleton) {
|
|
1470
|
+
for (let i = 0; i < Math.min(5, state.limit); i++) {
|
|
1471
|
+
const tr = dtEl("tr");
|
|
1472
|
+
columns.concat(hasActions ? [{}] : []).forEach(() => {
|
|
1473
|
+
const td = dtEl("td");
|
|
1474
|
+
td.appendChild(dtEl("span", "bb-dt-sk"));
|
|
1475
|
+
tr.appendChild(td);
|
|
1476
|
+
});
|
|
1477
|
+
tbody.appendChild(tr);
|
|
1478
|
+
const li = dtEl("li");
|
|
1479
|
+
li.appendChild(dtEl("span", "bb-dt-sk"));
|
|
1480
|
+
cards.appendChild(li);
|
|
1481
|
+
}
|
|
1482
|
+
} else if (!rows.length) {
|
|
1483
|
+
const td = dtEl("td", "bb-dt-empty", options.empty || t("table.empty"));
|
|
1484
|
+
td.colSpan = columns.length + (hasActions ? 1 : 0);
|
|
1485
|
+
const tr = dtEl("tr");
|
|
1486
|
+
tr.appendChild(td);
|
|
1487
|
+
tbody.appendChild(tr);
|
|
1488
|
+
cards.appendChild(dtEl("li", "bb-dt-empty", options.empty || t("table.empty")));
|
|
1489
|
+
} else {
|
|
1490
|
+
rows.forEach((row, index) => {
|
|
1491
|
+
const tr = dtEl("tr");
|
|
1492
|
+
if (typeof options.onRowClick === "function") {
|
|
1493
|
+
tr.style.cursor = "pointer";
|
|
1494
|
+
tr.addEventListener("click", () => options.onRowClick(row));
|
|
1495
|
+
}
|
|
1496
|
+
columns.forEach((c) => {
|
|
1497
|
+
const td = dtEl("td", [alignClass(c), c.numeric ? "bb-dt-num" : "", c === primary ? "bb-dt-primary" : ""].filter(Boolean).join(" "));
|
|
1498
|
+
td.appendChild(dtCell(row, c));
|
|
1499
|
+
tr.appendChild(td);
|
|
1500
|
+
});
|
|
1501
|
+
if (hasActions) {
|
|
1502
|
+
const td = dtEl("td", "bb-dt-right");
|
|
1503
|
+
td.style.padding = ".375rem .5rem";
|
|
1504
|
+
const acts = actionsFor(row);
|
|
1505
|
+
if (acts) td.appendChild(acts);
|
|
1506
|
+
tr.appendChild(td);
|
|
1507
|
+
}
|
|
1508
|
+
tbody.appendChild(tr);
|
|
1509
|
+
|
|
1510
|
+
const key = row?.[options.rowKey || "id"] ?? `${state.page}-${index}`;
|
|
1511
|
+
const li = dtEl("li");
|
|
1512
|
+
const head = dtEl("div", "bb-dt-card-head");
|
|
1513
|
+
const title = dtEl("div", "bb-dt-card-title");
|
|
1514
|
+
if (primary) title.appendChild(dtCell(row, primary));
|
|
1515
|
+
head.appendChild(title);
|
|
1516
|
+
const acts = actionsFor(row);
|
|
1517
|
+
if (acts) head.appendChild(acts);
|
|
1518
|
+
li.appendChild(head);
|
|
1519
|
+
const field = (c) => {
|
|
1520
|
+
const box = dtEl("div");
|
|
1521
|
+
const dd = dtEl("dd", c.numeric ? "bb-dt-num" : "");
|
|
1522
|
+
dd.appendChild(dtCell(row, c));
|
|
1523
|
+
box.append(dtEl("dt", "", c.label), dd);
|
|
1524
|
+
return box;
|
|
1525
|
+
};
|
|
1526
|
+
if (summaryCols.length) {
|
|
1527
|
+
const dl = dtEl("dl");
|
|
1528
|
+
summaryCols.forEach((c) => dl.appendChild(field(c)));
|
|
1529
|
+
li.appendChild(dl);
|
|
1530
|
+
}
|
|
1531
|
+
if (detailCols.length) {
|
|
1532
|
+
const open = state.expanded.has(key);
|
|
1533
|
+
if (open) {
|
|
1534
|
+
const dl = dtEl("dl", "bb-dt-details");
|
|
1535
|
+
detailCols.forEach((c) => dl.appendChild(field(c)));
|
|
1536
|
+
li.appendChild(dl);
|
|
1537
|
+
}
|
|
1538
|
+
const toggle = dtEl("button", "bb-dt-toggle", t(open ? "table.less" : "table.more"));
|
|
1539
|
+
toggle.type = "button";
|
|
1540
|
+
toggle.setAttribute("aria-expanded", open ? "true" : "false");
|
|
1541
|
+
toggle.appendChild(dtIcon("chevron"));
|
|
1542
|
+
toggle.addEventListener("click", () => {
|
|
1543
|
+
if (state.expanded.has(key)) state.expanded.delete(key);
|
|
1544
|
+
else state.expanded.add(key);
|
|
1545
|
+
render();
|
|
1546
|
+
});
|
|
1547
|
+
li.appendChild(toggle);
|
|
1548
|
+
}
|
|
1549
|
+
cards.appendChild(li);
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
foot.replaceChildren();
|
|
1554
|
+
foot.hidden = showSkeleton || total === 0;
|
|
1555
|
+
if (!foot.hidden) {
|
|
1556
|
+
const pages = Math.max(1, Math.ceil(total / state.limit));
|
|
1557
|
+
const from = (state.page - 1) * state.limit + 1;
|
|
1558
|
+
const to = Math.min(total, state.page * state.limit);
|
|
1559
|
+
foot.appendChild(dtEl("span", "", t("table.range", { from, to, total })));
|
|
1560
|
+
const right = dtEl("div");
|
|
1561
|
+
if (pageSizes.length > 1) {
|
|
1562
|
+
const label = dtEl("label", "", t("table.rowsPerPage"));
|
|
1563
|
+
const select = dtEl("select", "field");
|
|
1564
|
+
[...new Set([...pageSizes, state.limit])].sort((a, b) => a - b).forEach((n) => {
|
|
1565
|
+
const opt = dtEl("option", "", n);
|
|
1566
|
+
opt.value = String(n);
|
|
1567
|
+
if (n === state.limit) opt.selected = true;
|
|
1568
|
+
select.appendChild(opt);
|
|
1569
|
+
});
|
|
1570
|
+
select.addEventListener("change", () => {
|
|
1571
|
+
state.limit = Number(select.value);
|
|
1572
|
+
state.page = 1;
|
|
1573
|
+
url ? load() : render();
|
|
1574
|
+
});
|
|
1575
|
+
label.appendChild(select);
|
|
1576
|
+
right.appendChild(label);
|
|
1577
|
+
}
|
|
1578
|
+
right.appendChild(dtEl("span", "", t("table.page", { n: state.page, total: pages })));
|
|
1579
|
+
const nav = dtEl("div");
|
|
1580
|
+
nav.style.display = "flex";
|
|
1581
|
+
nav.style.gap = ".25rem";
|
|
1582
|
+
[["prev", state.page <= 1, -1], ["next", state.page >= pages, 1]].forEach(([name, disabled, step]) => {
|
|
1583
|
+
const btn = dtEl("button", "btn btn-outline btn-icon btn-sm");
|
|
1584
|
+
btn.type = "button";
|
|
1585
|
+
btn.disabled = disabled;
|
|
1586
|
+
btn.setAttribute("aria-label", t("table." + name));
|
|
1587
|
+
btn.appendChild(dtIcon(name));
|
|
1588
|
+
btn.addEventListener("click", () => {
|
|
1589
|
+
state.page += step;
|
|
1590
|
+
url ? load() : render();
|
|
1591
|
+
});
|
|
1592
|
+
nav.appendChild(btn);
|
|
1593
|
+
});
|
|
1594
|
+
right.appendChild(nav);
|
|
1595
|
+
foot.appendChild(right);
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
/**
|
|
1600
|
+
* Fetches the current page from the server (`url` mode).
|
|
1601
|
+
* @returns {Promise<void>}
|
|
1602
|
+
*/
|
|
1603
|
+
const load = async () => {
|
|
1604
|
+
if (!url) return render();
|
|
1605
|
+
const seq = ++requestSeq;
|
|
1606
|
+
state.loading = true;
|
|
1607
|
+
render();
|
|
1608
|
+
const qs = new URLSearchParams({ ...(options.params || {}), page: String(state.page), limit: String(state.limit) });
|
|
1609
|
+
if (state.query.trim()) qs.set("search", state.query.trim());
|
|
1610
|
+
if (state.sort.key) {
|
|
1611
|
+
qs.set("sort", state.sort.key);
|
|
1612
|
+
qs.set("order", state.sort.dir === -1 ? "desc" : "asc");
|
|
1613
|
+
}
|
|
1614
|
+
try {
|
|
1615
|
+
const res = await fetch(url + (url.includes("?") ? "&" : "?") + qs.toString(), { credentials: "same-origin", headers: { Accept: "application/json" } });
|
|
1616
|
+
const body = await res.json().catch(() => ({}));
|
|
1617
|
+
if (!res.ok || body?.status === "error") throw new Error(body?.message || t("request.failed"));
|
|
1618
|
+
if (seq !== requestSeq) return;
|
|
1619
|
+
const result = dtNormalize(body);
|
|
1620
|
+
state.rows = result.rows;
|
|
1621
|
+
state.total = result.total;
|
|
1622
|
+
} catch (err) {
|
|
1623
|
+
if (seq === requestSeq) toast.error(err?.message || t("request.failed"));
|
|
1624
|
+
} finally {
|
|
1625
|
+
if (seq === requestSeq) {
|
|
1626
|
+
state.loading = false;
|
|
1627
|
+
render();
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
|
|
1632
|
+
search.addEventListener("input", () => {
|
|
1633
|
+
state.query = search.value;
|
|
1634
|
+
state.page = 1;
|
|
1635
|
+
if (!url) return render();
|
|
1636
|
+
clearTimeout(searchTimer);
|
|
1637
|
+
searchTimer = setTimeout(load, 300);
|
|
1638
|
+
});
|
|
1639
|
+
|
|
1640
|
+
const api = {
|
|
1641
|
+
reload: load,
|
|
1642
|
+
setRows: (rows) => {
|
|
1643
|
+
state.rows = Array.isArray(rows) ? rows : [];
|
|
1644
|
+
render();
|
|
1645
|
+
},
|
|
1646
|
+
destroy: () => {
|
|
1647
|
+
clearTimeout(searchTimer);
|
|
1648
|
+
el.innerHTML = "";
|
|
1649
|
+
delete el.__bbDataTable;
|
|
1650
|
+
},
|
|
1651
|
+
};
|
|
1652
|
+
el.__bbDataTable = api;
|
|
1653
|
+
el.dataset.bbDatatableInit = "1";
|
|
1654
|
+
url ? load() : render();
|
|
1655
|
+
return api;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* Initializes a declarative `[data-datatable]` element. Options come from a child
|
|
1660
|
+
* `<script type="application/json">` (use `safeJson()` on the server) plus `data-url`, `data-page-size`, and `data-search="false"`.
|
|
1661
|
+
* @param {HTMLElement} el
|
|
1662
|
+
*/
|
|
1663
|
+
function initDataTable(el) {
|
|
1664
|
+
if (!el || el.dataset.bbDatatableInit === "1") return;
|
|
1665
|
+
let config = {};
|
|
1666
|
+
const script = el.querySelector('script[type="application/json"]');
|
|
1667
|
+
if (script) {
|
|
1668
|
+
try {
|
|
1669
|
+
config = JSON.parse(script.textContent || "{}");
|
|
1670
|
+
} catch (err) {
|
|
1671
|
+
console.error("[Bluebird] Invalid data-datatable JSON config", err);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
if (el.dataset.url) config.url = el.dataset.url;
|
|
1675
|
+
if (el.dataset.pageSize) config.pageSize = Number(el.dataset.pageSize);
|
|
1676
|
+
if (el.dataset.search === "false") config.searchable = false;
|
|
1677
|
+
dataTable(el, config);
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
/**
|
|
1681
|
+
* Marks navigation links pointing at the active pathname with `aria-current="page"`.
|
|
1682
|
+
*/
|
|
1683
|
+
function syncActiveNavLinks() {
|
|
1684
|
+
const here = window.location.pathname.replace(/\/+$/, "") || "/";
|
|
1685
|
+
document.querySelectorAll("header nav a.nav-link[href]").forEach((link) => {
|
|
1686
|
+
try {
|
|
1687
|
+
const url = new URL(link.getAttribute("href"), window.location.origin);
|
|
1688
|
+
const linkPath = url.pathname.replace(/\/+$/, "") || "/";
|
|
1689
|
+
if (url.origin === window.location.origin && linkPath === here && !link.hasAttribute("aria-current")) {
|
|
1690
|
+
link.setAttribute("aria-current", "page");
|
|
1691
|
+
}
|
|
1692
|
+
} catch {}
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/**
|
|
1697
|
+
* Initializes carousels, native modal dialogs, active nav state, and initial theme sync.
|
|
1698
|
+
*/
|
|
1699
|
+
function initAll() {
|
|
1700
|
+
ensureStyles();
|
|
1701
|
+
let stored = null;
|
|
1702
|
+
try {
|
|
1703
|
+
const s = window.localStorage.getItem(THEME_STORAGE_KEY);
|
|
1704
|
+
if (s === "light" || s === "dark") stored = s;
|
|
1705
|
+
} catch {}
|
|
1706
|
+
applyDocumentTheme(getTheme(), stored);
|
|
1707
|
+
syncActiveNavLinks();
|
|
1708
|
+
document.querySelectorAll("[data-carousel]").forEach(initCarousel);
|
|
1709
|
+
document.querySelectorAll("dialog[data-modal]").forEach(initModalDialog);
|
|
1710
|
+
document.querySelectorAll("[data-datatable]").forEach(initDataTable);
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
window.addEventListener("storage", (e) => {
|
|
1714
|
+
if (e.key !== THEME_STORAGE_KEY) return;
|
|
1715
|
+
const stored = e.newValue === "light" || e.newValue === "dark" ? e.newValue : null;
|
|
1716
|
+
applyDocumentTheme(stored || getSystemTheme(), stored);
|
|
1717
|
+
});
|
|
1718
|
+
|
|
1719
|
+
if (window.matchMedia) {
|
|
1720
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1721
|
+
mq.addEventListener?.("change", () => {
|
|
1722
|
+
let saved = null;
|
|
1723
|
+
try {
|
|
1724
|
+
saved = window.localStorage.getItem(THEME_STORAGE_KEY);
|
|
1725
|
+
} catch {}
|
|
1726
|
+
if (saved !== "light" && saved !== "dark") {
|
|
1727
|
+
applyDocumentTheme(mq.matches ? "dark" : "light", null);
|
|
1728
|
+
}
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
document.addEventListener("click", (e) => {
|
|
1733
|
+
const confirmTarget = e.target.closest("[data-confirm]");
|
|
1734
|
+
if (confirmTarget && !window.confirm(confirmTarget.getAttribute("data-confirm"))) {
|
|
1735
|
+
e.preventDefault();
|
|
1736
|
+
e.stopImmediatePropagation();
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
const themeBtn = e.target.closest("[data-theme-toggle]");
|
|
1741
|
+
if (themeBtn) {
|
|
1742
|
+
e.preventDefault();
|
|
1743
|
+
toggleTheme();
|
|
1744
|
+
return;
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
const toastBtn = e.target.closest("[data-toast]");
|
|
1748
|
+
if (toastBtn) {
|
|
1749
|
+
toast({
|
|
1750
|
+
title: toastBtn.getAttribute("data-toast"),
|
|
1751
|
+
description: toastBtn.getAttribute("data-toast-description") || undefined,
|
|
1752
|
+
badge: toastBtn.getAttribute("data-toast-badge") || undefined,
|
|
1753
|
+
type: toastBtn.getAttribute("data-toast-type") || "info",
|
|
1754
|
+
duration: toastBtn.hasAttribute("data-toast-duration")
|
|
1755
|
+
? Number(toastBtn.getAttribute("data-toast-duration"))
|
|
1756
|
+
: 4500,
|
|
1757
|
+
});
|
|
1758
|
+
return;
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
const openModalBtn = e.target.closest("[data-modal-open]");
|
|
1762
|
+
if (openModalBtn) {
|
|
1763
|
+
e.preventDefault();
|
|
1764
|
+
setModal(openModalBtn.getAttribute("data-modal-open"), true);
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
const closeModalBtn = e.target.closest("[data-modal-close]");
|
|
1769
|
+
if (closeModalBtn) {
|
|
1770
|
+
const targetId = closeModalBtn.getAttribute("data-modal-close");
|
|
1771
|
+
if (targetId) {
|
|
1772
|
+
setModal(targetId, false);
|
|
1773
|
+
} else {
|
|
1774
|
+
const parentModal = closeModalBtn.closest("[data-modal]");
|
|
1775
|
+
if (parentModal) setModal(parentModal.getAttribute("data-modal") || parentModal.id, false);
|
|
1776
|
+
}
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
const modalBackdrop = e.target.matches("[data-modal]") && e.target.tagName !== "DIALOG" ? e.target : null;
|
|
1781
|
+
if (modalBackdrop) {
|
|
1782
|
+
setModal(modalBackdrop.getAttribute("data-modal") || modalBackdrop.id, false);
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
const ddTrigger = e.target.closest("[data-dropdown-trigger]");
|
|
1787
|
+
if (ddTrigger) {
|
|
1788
|
+
e.preventDefault();
|
|
1789
|
+
const dd = ddTrigger.closest("[data-dropdown]");
|
|
1790
|
+
const menu = dd?.querySelector("[data-dropdown-menu]");
|
|
1791
|
+
if (menu) {
|
|
1792
|
+
const willOpen = menu.classList.contains("hidden");
|
|
1793
|
+
document.querySelectorAll("[data-dropdown-menu]").forEach((m) => m.classList.add("hidden"));
|
|
1794
|
+
menu.classList.toggle("hidden", !willOpen);
|
|
1795
|
+
ddTrigger.setAttribute("aria-expanded", willOpen ? "true" : "false");
|
|
1796
|
+
}
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
if (!e.target.closest("[data-dropdown]")) {
|
|
1801
|
+
document.querySelectorAll("[data-dropdown-menu]").forEach((m) => m.classList.add("hidden"));
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
const tabBtn = e.target.closest("[data-tab]");
|
|
1805
|
+
if (tabBtn) {
|
|
1806
|
+
const container = tabBtn.closest("[data-tabs]");
|
|
1807
|
+
const name = tabBtn.getAttribute("data-tab");
|
|
1808
|
+
if (container && name) {
|
|
1809
|
+
container.querySelectorAll("[data-tab]").forEach((btn) => {
|
|
1810
|
+
const active = btn.getAttribute("data-tab") === name;
|
|
1811
|
+
btn.setAttribute("data-active", active ? "true" : "false");
|
|
1812
|
+
btn.setAttribute("aria-selected", active ? "true" : "false");
|
|
1813
|
+
});
|
|
1814
|
+
container.querySelectorAll("[data-tab-panel]").forEach((panel) => {
|
|
1815
|
+
panel.classList.toggle("hidden", panel.getAttribute("data-tab-panel") !== name);
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
const copyBtn = e.target.closest("[data-copy]");
|
|
1822
|
+
if (copyBtn && navigator.clipboard) {
|
|
1823
|
+
const text = copyBtn.getAttribute("data-copy");
|
|
1824
|
+
navigator.clipboard.writeText(text || "").then(() => {
|
|
1825
|
+
toast.success(copyBtn.getAttribute("data-copy-message") || t("copy.done"));
|
|
1826
|
+
});
|
|
1827
|
+
return;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
const pwBtn = e.target.closest("[data-password-toggle]");
|
|
1831
|
+
if (pwBtn) {
|
|
1832
|
+
const input = document.getElementById(pwBtn.getAttribute("data-password-toggle"));
|
|
1833
|
+
if (input) input.type = input.type === "password" ? "text" : "password";
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
|
|
1837
|
+
document.addEventListener("keydown", (e) => {
|
|
1838
|
+
if (e.key === "Escape") {
|
|
1839
|
+
document.querySelectorAll("[data-dropdown-menu]").forEach((m) => m.classList.add("hidden"));
|
|
1840
|
+
document.querySelectorAll("[data-modal]").forEach((m) => {
|
|
1841
|
+
if (m.tagName !== "DIALOG" && !m.classList.contains("hidden")) {
|
|
1842
|
+
setModal(m.getAttribute("data-modal") || m.id, false);
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
});
|
|
1847
|
+
|
|
1848
|
+
document.addEventListener("submit", (e) => {
|
|
1849
|
+
const form = e.target.closest("form[data-form]");
|
|
1850
|
+
if (!form) return;
|
|
1851
|
+
e.preventDefault();
|
|
1852
|
+
submitDeclarativeForm(form);
|
|
1853
|
+
});
|
|
1854
|
+
|
|
1855
|
+
if (document.readyState === "loading") {
|
|
1856
|
+
document.addEventListener("DOMContentLoaded", initAll);
|
|
1857
|
+
} else {
|
|
1858
|
+
initAll();
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
if (typeof MutationObserver !== "undefined" && document.documentElement) {
|
|
1862
|
+
let scanQueued = false;
|
|
1863
|
+
const observer = new MutationObserver(() => {
|
|
1864
|
+
if (scanQueued) return;
|
|
1865
|
+
scanQueued = true;
|
|
1866
|
+
window.requestAnimationFrame(() => {
|
|
1867
|
+
scanQueued = false;
|
|
1868
|
+
document.querySelectorAll("[data-carousel]:not([data-bb-carousel-init='1'])").forEach(initCarousel);
|
|
1869
|
+
document.querySelectorAll("dialog[data-modal]:not([data-bb-dialog-init='1'])").forEach(initModalDialog);
|
|
1870
|
+
document.querySelectorAll("[data-datatable]:not([data-bb-datatable-init='1'])").forEach(initDataTable);
|
|
1871
|
+
});
|
|
1872
|
+
});
|
|
1873
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
global.Bluebird = {
|
|
1877
|
+
__loaded: true,
|
|
1878
|
+
toast,
|
|
1879
|
+
dataTable,
|
|
1880
|
+
i18n: { t, getLocale, setLocale, addMessages, messages: MESSAGES },
|
|
1881
|
+
csrf: getCsrfToken,
|
|
1882
|
+
theme: { get: getTheme, set: setTheme, toggle: toggleTheme },
|
|
1883
|
+
modal: { open: (id) => setModal(id, true), close: (id) => setModal(id, false) },
|
|
1884
|
+
init: initAll,
|
|
1885
|
+
};
|
|
1886
|
+
})(window);
|