@alepha/ui 0.25.0 → 0.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -5
- package/src/components/account/__tests__/account-router.spec.ts +201 -0
- package/src/components/account/account-connections.tsx +103 -0
- package/src/components/account/account-delete-dialog.tsx +184 -0
- package/src/components/account/account-header.tsx +57 -0
- package/src/components/account/account-keys.tsx +221 -0
- package/src/components/account/account-layout.tsx +63 -0
- package/src/components/account/account-password-dialog.tsx +152 -0
- package/src/components/account/account-profile.tsx +229 -0
- package/src/components/account/account-router-options.tsx +74 -0
- package/src/components/account/account-router-page.tsx +69 -0
- package/src/components/account/account-router.tsx +214 -0
- package/src/components/account/account-security.tsx +150 -0
- package/src/components/account/account-sessions.tsx +140 -0
- package/src/components/admin/__tests__/admin-keys-token-dialog.browser.spec.tsx +62 -0
- package/src/components/admin/__tests__/admin-layout.browser.spec.tsx +82 -0
- package/src/components/admin/__tests__/admin-router-page.spec.ts +54 -0
- package/src/components/admin/__tests__/admin-router.spec.ts +208 -0
- package/src/components/admin/__tests__/admin-user-cell.browser.spec.tsx +99 -0
- package/src/components/admin/__tests__/admin-user-detail.spec.ts +29 -0
- package/src/components/admin/admin-analytics-query-panel.tsx +149 -0
- package/src/components/admin/admin-analytics-results.tsx +95 -0
- package/src/components/admin/admin-analytics.tsx +104 -0
- package/src/components/admin/admin-audits.tsx +12 -15
- package/src/components/admin/admin-files.tsx +10 -18
- package/src/components/admin/admin-jobs-executions-panel.tsx +2 -1
- package/src/components/admin/admin-jobs.tsx +3 -1
- package/src/components/admin/admin-keys-token-dialog.tsx +123 -0
- package/src/components/admin/admin-keys.tsx +54 -3
- package/src/components/admin/admin-layout.tsx +107 -0
- package/src/components/admin/admin-payments.tsx +4 -5
- package/src/components/admin/admin-router-options.tsx +130 -0
- package/src/components/admin/admin-router-page.tsx +74 -0
- package/src/components/admin/admin-router.tsx +379 -0
- package/src/components/admin/admin-sessions.tsx +2 -16
- package/src/components/admin/admin-user-cell.tsx +70 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +28 -0
- package/src/components/admin/admin-user-detail-profile-policy.spec.ts +146 -0
- package/src/components/admin/admin-user-detail-profile-policy.ts +147 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +1 -1
- package/src/components/admin/admin-user-detail.tsx +76 -32
- package/src/components/admin/admin-users-status-filter.tsx +2 -0
- package/src/components/admin/admin-workflows-execution-sheet.tsx +277 -0
- package/src/components/admin/admin-workflows-executions-panel.tsx +170 -0
- package/src/components/admin/admin-workflows-status-badge.tsx +40 -0
- package/src/components/admin/admin-workflows.tsx +207 -0
- package/src/components/alepha-table/alepha-table.tsx +73 -17
- package/src/components/app-actions/__tests__/app-actions.browser.spec.tsx +79 -0
- package/src/components/app-actions/app-actions.tsx +113 -0
- package/src/components/app-shell/app-shell.tsx +122 -0
- package/src/components/auth/auth-reset-password.tsx +81 -8
- package/src/components/button-user/button-user.tsx +58 -1
- package/src/components/control/control.tsx +14 -71
- package/src/components/control-password/control-password.tsx +87 -0
- package/src/components/control-select/__tests__/control-select-clear-label.browser.spec.tsx +101 -0
- package/src/components/control-select/__tests__/control-select-deselect.browser.spec.tsx +126 -0
- package/src/components/control-select/__tests__/control-select-searchable.browser.spec.tsx +142 -0
- package/src/components/control-select/control-select.tsx +133 -111
- package/src/components/control-upload/control-upload.tsx +27 -1
- package/src/components/markdown-view/markdown-view.tsx +6 -0
- package/src/components/nav-shell/nav-page.tsx +3 -3
- package/src/components/settings/__tests__/settings-nav.browser.spec.tsx +123 -0
- package/src/components/settings/__tests__/settings-section.browser.spec.tsx +130 -0
- package/src/components/settings/settings-danger-section.tsx +59 -0
- package/src/components/settings/settings-layout.tsx +56 -0
- package/src/components/settings/settings-nav.tsx +131 -0
- package/src/components/settings/settings-row.tsx +81 -0
- package/src/components/settings/settings-section.tsx +64 -0
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/avatar.tsx +2 -0
- package/src/components/ui/breadcrumb.tsx +1 -1
- package/src/components/ui/calendar.tsx +11 -6
- package/src/components/ui/card.tsx +5 -5
- package/src/components/ui/carousel.tsx +4 -4
- package/src/components/ui/chart.tsx +2 -0
- package/src/components/ui/collapsible.tsx +2 -0
- package/src/components/ui/combobox.tsx +3 -1
- package/src/components/ui/context-menu.tsx +3 -3
- package/src/components/ui/dialog.tsx +6 -1
- package/src/components/ui/direction.tsx +2 -0
- package/src/components/ui/drawer.tsx +134 -37
- package/src/components/ui/dropdown-menu.tsx +13 -3
- package/src/components/ui/empty.tsx +4 -1
- package/src/components/ui/input-otp.tsx +2 -0
- package/src/components/ui/menubar.tsx +2 -2
- package/src/components/ui/pagination.tsx +2 -2
- package/src/components/ui/popover.tsx +2 -0
- package/src/components/ui/radio-group.tsx +2 -0
- package/src/components/ui/scroll-area.tsx +2 -0
- package/src/components/ui/select.tsx +1 -1
- package/src/components/ui/separator.tsx +2 -0
- package/src/components/ui/sheet.tsx +4 -1
- package/src/components/ui/sidebar.tsx +1 -1
- package/src/components/ui/spinner.tsx +1 -0
- package/src/components/ui/switch.tsx +2 -0
- package/src/components/ui/tabs.tsx +2 -0
- package/src/components/ui/toggle-group.tsx +2 -0
- package/src/components/ui/tooltip.tsx +2 -0
- package/src/lib/__tests__/rehype-safe-img.spec.ts +121 -0
- package/src/lib/i18n-fr.ts +68 -0
- package/src/lib/rehype-safe-img.ts +150 -0
- package/src/lib/resize-image.ts +135 -0
- package/src/styles.css +126 -1
- /package/src/components/{admin/admin-user-detail-provider-labels.ts → auth/provider-labels.ts} +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { parseSafeImg } from "../rehype-safe-img.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This is the whole XSS surface of the markdown reader, so it is tested
|
|
6
|
+
* directly rather than through a render.
|
|
7
|
+
*
|
|
8
|
+
* The reader deliberately does NOT use `rehype-raw`: folio content is
|
|
9
|
+
* user-authored, and this codebase escapes raw HTML everywhere else on
|
|
10
|
+
* purpose. `parseSafeImg` is the single exception carved out for `<img>`,
|
|
11
|
+
* which is what MDXEditor emits once an image has been resized — so what it
|
|
12
|
+
* accepts, and only that, becomes renderable markup.
|
|
13
|
+
*/
|
|
14
|
+
describe("parseSafeImg", () => {
|
|
15
|
+
describe("accepts", () => {
|
|
16
|
+
it("a relative assets/ image", () => {
|
|
17
|
+
expect(parseSafeImg('<img src="assets/photo.webp" />')).toEqual({
|
|
18
|
+
src: "assets/photo.webp",
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("a same-origin file URL", () => {
|
|
23
|
+
expect(parseSafeImg('<img src="/api/files/abc" />')).toEqual({
|
|
24
|
+
src: "/api/files/abc",
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("the allowlisted attributes", () => {
|
|
29
|
+
expect(
|
|
30
|
+
parseSafeImg(
|
|
31
|
+
'<img src="assets/a.png" alt="A cat" title="Tip" width="600" height="400">',
|
|
32
|
+
),
|
|
33
|
+
).toEqual({
|
|
34
|
+
src: "assets/a.png",
|
|
35
|
+
alt: "A cat",
|
|
36
|
+
title: "Tip",
|
|
37
|
+
width: "600",
|
|
38
|
+
height: "400",
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("single-quoted and unquoted attribute values", () => {
|
|
43
|
+
expect(parseSafeImg("<img src='assets/a.png' width=600>")).toEqual({
|
|
44
|
+
src: "assets/a.png",
|
|
45
|
+
width: "600",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("drops attributes outside the allowlist", () => {
|
|
51
|
+
it("an inline event handler", () => {
|
|
52
|
+
expect(
|
|
53
|
+
parseSafeImg('<img src="assets/a.png" onerror="alert(1)">'),
|
|
54
|
+
).toEqual({ src: "assets/a.png" });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("onload, style, class and srcset", () => {
|
|
58
|
+
expect(
|
|
59
|
+
parseSafeImg(
|
|
60
|
+
'<img src="assets/a.png" onload="x()" style="position:fixed" class="evil" srcset="https://evil.test/a 1x">',
|
|
61
|
+
),
|
|
62
|
+
).toEqual({ src: "assets/a.png" });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("a non-numeric width", () => {
|
|
66
|
+
// Width reaches a DOM attribute, so anything but digits is refused
|
|
67
|
+
// rather than passed along to be interpreted.
|
|
68
|
+
expect(parseSafeImg('<img src="assets/a.png" width="600px">')).toEqual({
|
|
69
|
+
src: "assets/a.png",
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("refuses the whole element", () => {
|
|
75
|
+
const rejected = [
|
|
76
|
+
["a javascript: src", '<img src="javascript:alert(1)">'],
|
|
77
|
+
["an uppercase JavaScript: src", '<img src="JaVaScRiPt:alert(1)">'],
|
|
78
|
+
[
|
|
79
|
+
"a javascript: src with an embedded newline",
|
|
80
|
+
'<img src="java\nscript:alert(1)">',
|
|
81
|
+
],
|
|
82
|
+
["a data: src", '<img src="data:image/svg+xml;base64,PHN2Zz4=">'],
|
|
83
|
+
["a remote http src", '<img src="http://evil.test/a.png">'],
|
|
84
|
+
["a remote https src", '<img src="https://evil.test/a.png">'],
|
|
85
|
+
["a protocol-relative src", '<img src="//evil.test/a.png">'],
|
|
86
|
+
["a src that escapes the folio", '<img src="../../etc/passwd">'],
|
|
87
|
+
["no src at all", '<img alt="nothing">'],
|
|
88
|
+
["an empty src", '<img src="">'],
|
|
89
|
+
] as const;
|
|
90
|
+
|
|
91
|
+
for (const [label, html] of rejected) {
|
|
92
|
+
it(label, () => {
|
|
93
|
+
expect(parseSafeImg(html)).toBeUndefined();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("refuses anything that is not a lone img", () => {
|
|
99
|
+
const rejected = [
|
|
100
|
+
["a script tag", "<script>alert(1)</script>"],
|
|
101
|
+
["an iframe", '<iframe src="/x"></iframe>'],
|
|
102
|
+
["an svg", '<svg onload="alert(1)"></svg>'],
|
|
103
|
+
[
|
|
104
|
+
"an img followed by a script",
|
|
105
|
+
'<img src="assets/a.png"><script>x</script>',
|
|
106
|
+
],
|
|
107
|
+
["a tag that merely starts with img", '<image src="assets/a.png">'],
|
|
108
|
+
["plain text", "not html at all"],
|
|
109
|
+
[
|
|
110
|
+
"an anchor wrapping an img",
|
|
111
|
+
'<a href="/x"><img src="assets/a.png"></a>',
|
|
112
|
+
],
|
|
113
|
+
] as const;
|
|
114
|
+
|
|
115
|
+
for (const [label, html] of rejected) {
|
|
116
|
+
it(label, () => {
|
|
117
|
+
expect(parseSafeImg(html)).toBeUndefined();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
package/src/lib/i18n-fr.ts
CHANGED
|
@@ -193,6 +193,17 @@ export const uiFr: Record<string, string> = {
|
|
|
193
193
|
|
|
194
194
|
// The `@alepha/ui/admin` back office: users, sessions, API keys, files, jobs,
|
|
195
195
|
// audits, notifications, payments and parameters.
|
|
196
|
+
"admin.analytics.empty": "Aucune donnée pour cette requête.",
|
|
197
|
+
"admin.analytics.estimated": "Estimé (échantillonné ×$1)",
|
|
198
|
+
"admin.analytics.exactSample": "Exact (aucun échantillonnage sur la fenêtre)",
|
|
199
|
+
"admin.analytics.filters": "Filtres",
|
|
200
|
+
"admin.analytics.groupBy": "Grouper par",
|
|
201
|
+
"admin.analytics.noDatasets":
|
|
202
|
+
"Aucun jeu de données analytics n'est déclaré dans cette application.",
|
|
203
|
+
"admin.analytics.pickDataset": "Choisir un jeu de données",
|
|
204
|
+
"admin.analytics.rowCount": "$1 lignes",
|
|
205
|
+
"admin.analytics.run": "Lancer la requête",
|
|
206
|
+
"admin.analytics.since": "Depuis (jour UTC)",
|
|
196
207
|
"admin.audits.actionAll": "Toutes les actions",
|
|
197
208
|
"admin.audits.bulkDelete": "Supprimer la sélection",
|
|
198
209
|
"admin.audits.bulkDeleteConfirm":
|
|
@@ -275,12 +286,26 @@ export const uiFr: Record<string, string> = {
|
|
|
275
286
|
"admin.keys.colOwner": "Propriétaire",
|
|
276
287
|
"admin.keys.colPrefix": "Préfixe",
|
|
277
288
|
"admin.keys.colScopes": "Rôles",
|
|
289
|
+
"admin.keys.copy": "Copier",
|
|
290
|
+
"admin.keys.copyFailed": "Impossible de copier",
|
|
291
|
+
"admin.keys.create": "Ajouter une clé d'API",
|
|
292
|
+
"admin.keys.createConfirm": "Créer",
|
|
293
|
+
"admin.keys.createDescription":
|
|
294
|
+
"La clé est créée pour votre compte et porte vos rôles actuels.",
|
|
295
|
+
"admin.keys.createNameLabel": "Nom",
|
|
296
|
+
"admin.keys.createNamePlaceholder": "ex. pipeline CI",
|
|
297
|
+
"admin.keys.createNameRequired": "Le nom est requis",
|
|
298
|
+
"admin.keys.createTitle": "Ajouter une clé d'API",
|
|
278
299
|
"admin.keys.noneSelected": "Aucune clé active dans la sélection",
|
|
279
300
|
"admin.keys.revoke": "Révoquer",
|
|
280
301
|
"admin.keys.revokeConfirm":
|
|
281
302
|
"Révoquer « $1 » ? Les applications qui utilisent cette clé perdront l'accès.",
|
|
282
303
|
"admin.keys.revokeTitle": "Révoquer la clé d'API",
|
|
283
304
|
"admin.keys.revoked": "Clé d'API révoquée",
|
|
305
|
+
"admin.keys.tokenDescription":
|
|
306
|
+
"Copiez ce jeton maintenant — il n'est affiché qu'une seule fois et ne peut pas être récupéré.",
|
|
307
|
+
"admin.keys.tokenDone": "Terminé",
|
|
308
|
+
"admin.keys.tokenTitle": "Clé d'API créée",
|
|
284
309
|
"admin.notifications.bulkDelete": "Supprimer la sélection",
|
|
285
310
|
"admin.notifications.bulkDeleteConfirm":
|
|
286
311
|
"Supprimer $1 notification(s) ? L'opération est irréversible.",
|
|
@@ -398,6 +423,8 @@ export const uiFr: Record<string, string> = {
|
|
|
398
423
|
"admin.userDetail.disabled": "Utilisateur désactivé",
|
|
399
424
|
"admin.userDetail.disabledBadge": "Désactivé",
|
|
400
425
|
"admin.userDetail.email": "Adresse e-mail",
|
|
426
|
+
"admin.userDetail.emailCannotBeCleared":
|
|
427
|
+
"L'adresse e-mail ne peut pas être supprimée une fois renseignée",
|
|
401
428
|
"admin.userDetail.emailRequired": "L'adresse e-mail est requise",
|
|
402
429
|
"admin.userDetail.emailVerified": "Adresse vérifiée",
|
|
403
430
|
"admin.userDetail.enable": "Réactiver",
|
|
@@ -448,6 +475,8 @@ export const uiFr: Record<string, string> = {
|
|
|
448
475
|
"admin.userDetail.tabSessions": "Sessions",
|
|
449
476
|
"admin.userDetail.thisUser": "cet utilisateur",
|
|
450
477
|
"admin.userDetail.username": "Identifiant",
|
|
478
|
+
"admin.userDetail.usernameCannotBeCleared":
|
|
479
|
+
"L'identifiant ne peut pas être supprimé une fois renseigné",
|
|
451
480
|
"admin.userDetail.usernameRequired": "L'identifiant est requis",
|
|
452
481
|
"admin.userDetail.verified": "Vérifié",
|
|
453
482
|
"admin.users.active": "Actif",
|
|
@@ -497,4 +526,43 @@ export const uiFr: Record<string, string> = {
|
|
|
497
526
|
"admin.users.thisUser": "cet utilisateur",
|
|
498
527
|
"admin.users.verified": "Vérifié",
|
|
499
528
|
"admin.users.viewProfile": "Voir le profil",
|
|
529
|
+
"admin.workflows.cancel": "Annuler",
|
|
530
|
+
"admin.workflows.cancelConfirm":
|
|
531
|
+
"Arrêter cette exécution ? Les étapes restantes ne seront pas exécutées.",
|
|
532
|
+
"admin.workflows.cancelTitle": "Annuler le workflow",
|
|
533
|
+
"admin.workflows.cancelled": "Workflow annulé",
|
|
534
|
+
"admin.workflows.colCreated": "Créé le",
|
|
535
|
+
"admin.workflows.colDuration": "Durée",
|
|
536
|
+
"admin.workflows.colError": "Erreur",
|
|
537
|
+
"admin.workflows.colFailed": "Échecs",
|
|
538
|
+
"admin.workflows.colName": "Nom",
|
|
539
|
+
"admin.workflows.colOnError": "En cas d'erreur",
|
|
540
|
+
"admin.workflows.colPending": "En attente",
|
|
541
|
+
"admin.workflows.colPriority": "Priorité",
|
|
542
|
+
"admin.workflows.colRunning": "En cours",
|
|
543
|
+
"admin.workflows.colStatus": "Statut",
|
|
544
|
+
"admin.workflows.colStep": "Étape",
|
|
545
|
+
"admin.workflows.colSteps": "Étapes",
|
|
546
|
+
"admin.workflows.colTriggeredBy": "Déclenché par",
|
|
547
|
+
"admin.workflows.compensate": "Compenser",
|
|
548
|
+
"admin.workflows.compensateConfirm":
|
|
549
|
+
"Exécuter les fonctions de compensation de chaque étape terminée, en ordre inverse ?",
|
|
550
|
+
"admin.workflows.compensateTitle": "Compenser le workflow",
|
|
551
|
+
"admin.workflows.compensated": "Compensation lancée",
|
|
552
|
+
"admin.workflows.execsDescription": "Exécutions de ce workflow.",
|
|
553
|
+
"admin.workflows.noExecs": "Aucune exécution pour l'instant.",
|
|
554
|
+
"admin.workflows.none": "Aucun workflow enregistré.",
|
|
555
|
+
"admin.workflows.restart": "Redémarrer",
|
|
556
|
+
"admin.workflows.restartConfirm":
|
|
557
|
+
"Démarrer une nouvelle exécution avec la même charge utile ?",
|
|
558
|
+
"admin.workflows.restartTitle": "Redémarrer le workflow",
|
|
559
|
+
"admin.workflows.restarted": "Workflow redémarré",
|
|
560
|
+
"admin.workflows.retried": "Workflow relancé",
|
|
561
|
+
"admin.workflows.retry": "Relancer",
|
|
562
|
+
"admin.workflows.retryConfirm":
|
|
563
|
+
"Reprendre cette exécution à partir de l'étape en échec ?",
|
|
564
|
+
"admin.workflows.retryTitle": "Relancer le workflow",
|
|
565
|
+
"admin.workflows.searchPlaceholder": "Rechercher…",
|
|
566
|
+
"admin.workflows.statusAll": "Tous les statuts",
|
|
567
|
+
"admin.workflows.viewExecutions": "Voir les exécutions",
|
|
500
568
|
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attributes an `<img>` may carry through. Everything else — event
|
|
3
|
+
* handlers, `style`, `class`, `srcset`, `usemap` — is dropped.
|
|
4
|
+
*/
|
|
5
|
+
const ALLOWED = new Set(["src", "alt", "title", "width", "height"]);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One `<img …>` tag and nothing else: optional whitespace, the tag, its
|
|
9
|
+
* attributes, an optional self-closing slash, and the end of the string.
|
|
10
|
+
*
|
|
11
|
+
* Anchored at both ends deliberately. A pattern that merely *found* an
|
|
12
|
+
* `<img>` would accept `<img src="a"><script>…</script>` and promote the
|
|
13
|
+
* whole raw node, carrying the script into the document as markup.
|
|
14
|
+
*/
|
|
15
|
+
const LONE_IMG = /^\s*<img\s+([^>]*?)\/?>\s*$/i;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `name="value"`, `name='value'` or `name=value`.
|
|
19
|
+
*/
|
|
20
|
+
const ATTRIBUTE = /([a-zA-Z-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/g;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A `src` this reader is willing to load.
|
|
24
|
+
*
|
|
25
|
+
* Allowed: a relative `assets/…` path (what folio content stores) and a
|
|
26
|
+
* same-origin absolute path (`/api/files/…`). Nothing else — no `data:`,
|
|
27
|
+
* no `javascript:`, no remote host, and no `//` protocol-relative URL,
|
|
28
|
+
* which is a remote host wearing a local-looking prefix.
|
|
29
|
+
*/
|
|
30
|
+
const isSafeSrc = (src: string): boolean => {
|
|
31
|
+
// Drop every C0 control character and space before looking for a scheme.
|
|
32
|
+
// Browsers ignore them while parsing a URL, so a literal tab or newline
|
|
33
|
+
// inside the attribute would otherwise walk `java\nscript:` past a naive
|
|
34
|
+
// prefix check and still execute.
|
|
35
|
+
//
|
|
36
|
+
// Done by code point rather than by a regex character class: a class
|
|
37
|
+
// spanning control characters is unreadable and linters reject it
|
|
38
|
+
// outright. The bound says what it means.
|
|
39
|
+
let stripped = "";
|
|
40
|
+
for (const character of src) {
|
|
41
|
+
if ((character.codePointAt(0) ?? 0) > 0x20) stripped += character;
|
|
42
|
+
}
|
|
43
|
+
const normalized = stripped.toLowerCase();
|
|
44
|
+
if (!normalized) return false;
|
|
45
|
+
if (normalized.includes(":")) return false;
|
|
46
|
+
if (normalized.startsWith("//")) return false;
|
|
47
|
+
// `..` would address something outside the folio's own assets.
|
|
48
|
+
if (normalized.includes("..")) return false;
|
|
49
|
+
return normalized.startsWith("assets/") || normalized.startsWith("/");
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parse a raw HTML string into the attributes of a safe `<img>`, or
|
|
54
|
+
* `undefined` if it is anything else.
|
|
55
|
+
*
|
|
56
|
+
* Exported and tested directly because this is the entire XSS surface of the
|
|
57
|
+
* markdown reader: `MarkdownView` renders user-authored content and does NOT
|
|
58
|
+
* use `rehype-raw`, so raw HTML is escaped to text everywhere except here.
|
|
59
|
+
*
|
|
60
|
+
* Deliberately string-based rather than `innerHTML`-based: this runs during
|
|
61
|
+
* SSR where there is no DOM, and a parser that only ever produces an
|
|
62
|
+
* allowlisted attribute bag cannot be tricked into producing a different
|
|
63
|
+
* element.
|
|
64
|
+
*/
|
|
65
|
+
export const parseSafeImg = (
|
|
66
|
+
html: string,
|
|
67
|
+
): Record<string, string> | undefined => {
|
|
68
|
+
const match = LONE_IMG.exec(html);
|
|
69
|
+
if (!match) return undefined;
|
|
70
|
+
|
|
71
|
+
const attributes: Record<string, string> = {};
|
|
72
|
+
ATTRIBUTE.lastIndex = 0;
|
|
73
|
+
let found: RegExpExecArray | null = ATTRIBUTE.exec(match[1]);
|
|
74
|
+
while (found) {
|
|
75
|
+
const name = found[1].toLowerCase();
|
|
76
|
+
const value = found[2] ?? found[3] ?? found[4] ?? "";
|
|
77
|
+
if (ALLOWED.has(name)) {
|
|
78
|
+
// `width`/`height` reach a DOM attribute, so only digits pass —
|
|
79
|
+
// anything else is refused rather than handed over to be interpreted.
|
|
80
|
+
if (name === "width" || name === "height") {
|
|
81
|
+
if (/^\d+$/.test(value)) attributes[name] = value;
|
|
82
|
+
} else {
|
|
83
|
+
attributes[name] = value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
found = ATTRIBUTE.exec(match[1]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!attributes.src || !isSafeSrc(attributes.src)) return undefined;
|
|
90
|
+
return attributes;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Minimal shape of the hast nodes this plugin walks. Typed locally rather
|
|
95
|
+
* than pulled from `@types/hast` — the package is not a dependency here, and
|
|
96
|
+
* this is the whole of what the transform touches.
|
|
97
|
+
*/
|
|
98
|
+
interface RawNode {
|
|
99
|
+
type: string;
|
|
100
|
+
value?: string;
|
|
101
|
+
tagName?: string;
|
|
102
|
+
properties?: Record<string, unknown>;
|
|
103
|
+
children?: RawNode[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Promote `<img …>` raw HTML into a real element, and leave every other raw
|
|
108
|
+
* node alone.
|
|
109
|
+
*
|
|
110
|
+
* ## Why not `rehype-raw`
|
|
111
|
+
*
|
|
112
|
+
* `rehype-raw` re-parses ALL raw HTML into elements, which is the correct
|
|
113
|
+
* tool when the markdown is trusted. Folio content is written by users and
|
|
114
|
+
* rendered to other project members, so enabling it would turn every
|
|
115
|
+
* markdown surface in the app into an HTML injection point — against the
|
|
116
|
+
* explicit posture of the rest of this codebase.
|
|
117
|
+
*
|
|
118
|
+
* This plugin is the narrow alternative: exactly one tag, an attribute
|
|
119
|
+
* allowlist, and a `src` scheme check. It exists because MDXEditor
|
|
120
|
+
* serialises a *resized* image as `<img width="600" src="…" />` (an
|
|
121
|
+
* un-resized one stays plain `` markdown), so without it a resize
|
|
122
|
+
* would render as escaped text.
|
|
123
|
+
*
|
|
124
|
+
* React-markdown converts any surviving raw node to a text node, so anything
|
|
125
|
+
* this transform declines keeps the existing, safe behaviour.
|
|
126
|
+
*/
|
|
127
|
+
export const rehypeSafeImg = () => {
|
|
128
|
+
const visit = (node: RawNode): void => {
|
|
129
|
+
const children = node.children;
|
|
130
|
+
if (!children) return;
|
|
131
|
+
for (let i = 0; i < children.length; i++) {
|
|
132
|
+
const child = children[i];
|
|
133
|
+
if (child.type === "raw" && typeof child.value === "string") {
|
|
134
|
+
const attributes = parseSafeImg(child.value);
|
|
135
|
+
if (attributes) {
|
|
136
|
+
children[i] = {
|
|
137
|
+
type: "element",
|
|
138
|
+
tagName: "img",
|
|
139
|
+
properties: attributes,
|
|
140
|
+
children: [],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
visit(child);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return (tree: RawNode): void => visit(tree);
|
|
150
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounds and encoding for a browser-side downscale.
|
|
3
|
+
*/
|
|
4
|
+
export interface ResizeImageOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Widest the result may be, in pixels.
|
|
7
|
+
*/
|
|
8
|
+
maxWidth: number;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Tallest the result may be. Defaults to `maxWidth`.
|
|
12
|
+
*/
|
|
13
|
+
maxHeight?: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Output MIME type. WebP by default: the browser's encoder is **lossy** and
|
|
17
|
+
* keeps the alpha channel, which no wasm build available to the server can
|
|
18
|
+
* do — a transparent logo at 128px is a few kilobytes here and roughly five
|
|
19
|
+
* times that server-side.
|
|
20
|
+
*
|
|
21
|
+
* @default "image/webp"
|
|
22
|
+
*/
|
|
23
|
+
type?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Encoder quality, 0-1.
|
|
27
|
+
*
|
|
28
|
+
* @default 0.82
|
|
29
|
+
*/
|
|
30
|
+
quality?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Downscales an image in the browser before it is uploaded.
|
|
35
|
+
*
|
|
36
|
+
* Worth doing even though the server enforces the same bounds: this is what
|
|
37
|
+
* stops the megabytes leaving the machine at all. Production project icons
|
|
38
|
+
* averaged 667 KB and reached the full 2 MB cap to fill a 32px box, so the
|
|
39
|
+
* upload itself was the slow part of setting one.
|
|
40
|
+
*
|
|
41
|
+
* **Returns the input untouched** when it is not a raster image, when it
|
|
42
|
+
* already fits, or when the browser lacks `OffscreenCanvas`/`createImageBitmap`
|
|
43
|
+
* — including SVG, which has no pixels to resample and would be rasterised into
|
|
44
|
+
* something worse than it started. So this is a best-effort downscale, not a
|
|
45
|
+
* gate: the storage's `maxSize` is what bounds the pathological case.
|
|
46
|
+
*
|
|
47
|
+
* The browser is also the *better* encoder here, which is why the work belongs
|
|
48
|
+
* on this side. `convertToBlob` produces lossy WebP with an alpha channel;
|
|
49
|
+
* the wasm codecs available to an edge runtime offer lossless WebP (roughly
|
|
50
|
+
* five times the bytes) or JPEG, which has no alpha at all and turns a
|
|
51
|
+
* transparent logo's background black.
|
|
52
|
+
*/
|
|
53
|
+
export const resizeImage = async (
|
|
54
|
+
file: File,
|
|
55
|
+
options: ResizeImageOptions,
|
|
56
|
+
): Promise<File> => {
|
|
57
|
+
if (!file.type.startsWith("image/") || file.type === "image/svg+xml") {
|
|
58
|
+
return file;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
typeof createImageBitmap !== "function" ||
|
|
63
|
+
typeof OffscreenCanvas !== "function"
|
|
64
|
+
) {
|
|
65
|
+
return file;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const maxWidth = options.maxWidth;
|
|
69
|
+
const maxHeight = options.maxHeight ?? options.maxWidth;
|
|
70
|
+
const type = options.type ?? "image/webp";
|
|
71
|
+
|
|
72
|
+
let bitmap: ImageBitmap | undefined;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
bitmap = await createImageBitmap(file);
|
|
76
|
+
|
|
77
|
+
const scale = Math.min(
|
|
78
|
+
1,
|
|
79
|
+
maxWidth / bitmap.width,
|
|
80
|
+
maxHeight / bitmap.height,
|
|
81
|
+
);
|
|
82
|
+
if (scale === 1) {
|
|
83
|
+
return file;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// A dimension can round to 0 on an extreme aspect ratio, and a
|
|
87
|
+
// zero-pixel canvas throws.
|
|
88
|
+
const width = Math.max(1, Math.round(bitmap.width * scale));
|
|
89
|
+
const height = Math.max(1, Math.round(bitmap.height * scale));
|
|
90
|
+
|
|
91
|
+
const canvas = new OffscreenCanvas(width, height);
|
|
92
|
+
const context = canvas.getContext("2d");
|
|
93
|
+
if (!context) {
|
|
94
|
+
return file;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
context.imageSmoothingEnabled = true;
|
|
98
|
+
context.imageSmoothingQuality = "high";
|
|
99
|
+
context.drawImage(bitmap, 0, 0, width, height);
|
|
100
|
+
|
|
101
|
+
const blob = await canvas.convertToBlob({
|
|
102
|
+
type,
|
|
103
|
+
quality: options.quality ?? 0.82,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// A browser that does not support the requested encoder silently falls
|
|
107
|
+
// back to PNG, which on a photo is bigger than the JPEG it came from.
|
|
108
|
+
// Handing back the original is the honest outcome.
|
|
109
|
+
if (blob.type !== type || blob.size >= file.size) {
|
|
110
|
+
return file;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return new File([blob], renameFor(file.name, blob.type), {
|
|
114
|
+
type: blob.type,
|
|
115
|
+
lastModified: file.lastModified,
|
|
116
|
+
});
|
|
117
|
+
} catch {
|
|
118
|
+
// A corrupt or unsupported image must not cost the user their upload —
|
|
119
|
+
// let the server have its say about the original.
|
|
120
|
+
return file;
|
|
121
|
+
} finally {
|
|
122
|
+
bitmap?.close();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Swaps the extension so the name matches the bytes. A file still called
|
|
128
|
+
* `.png` that is really WebP confuses everything downstream that trusts it.
|
|
129
|
+
*/
|
|
130
|
+
const renameFor = (name: string, type: string): string => {
|
|
131
|
+
const extension = type.split("/")[1]?.replace("jpeg", "jpg") ?? "bin";
|
|
132
|
+
const dot = name.lastIndexOf(".");
|
|
133
|
+
const stem = dot > 0 ? name.slice(0, dot) : name;
|
|
134
|
+
return `${stem}.${extension}`;
|
|
135
|
+
};
|
package/src/styles.css
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
--color-accent: var(--accent);
|
|
25
25
|
--color-accent-foreground: var(--accent-foreground);
|
|
26
26
|
--color-destructive: var(--destructive);
|
|
27
|
+
--color-destructive-foreground: var(--destructive-foreground);
|
|
27
28
|
--color-border: var(--border);
|
|
28
29
|
--color-input: var(--input);
|
|
29
30
|
--color-ring: var(--ring);
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
--accent: oklch(0.97 0 0);
|
|
67
68
|
--accent-foreground: oklch(0.205 0 0);
|
|
68
69
|
--destructive: oklch(0.577 0.245 27.325);
|
|
70
|
+
--destructive-foreground: oklch(0.985 0 0);
|
|
69
71
|
--border: oklch(0.922 0 0);
|
|
70
72
|
--input: oklch(0.922 0 0);
|
|
71
73
|
--ring: oklch(0.708 0 0);
|
|
@@ -100,6 +102,7 @@
|
|
|
100
102
|
--accent: oklch(0.269 0 0);
|
|
101
103
|
--accent-foreground: oklch(0.985 0 0);
|
|
102
104
|
--destructive: oklch(0.704 0.191 22.216);
|
|
105
|
+
--destructive-foreground: oklch(0.985 0 0);
|
|
103
106
|
--border: oklch(1 0 0 / 10%);
|
|
104
107
|
--input: oklch(1 0 0 / 15%);
|
|
105
108
|
--ring: oklch(0.556 0 0);
|
|
@@ -112,7 +115,7 @@
|
|
|
112
115
|
--sidebar-foreground: oklch(0.985 0 0);
|
|
113
116
|
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
114
117
|
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
115
|
-
--sidebar-accent: oklch(0.
|
|
118
|
+
--sidebar-accent: oklch(0.308 0 0);
|
|
116
119
|
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
117
120
|
--sidebar-border: oklch(1 0 0 / 10%);
|
|
118
121
|
--sidebar-ring: oklch(0.556 0 0);
|
|
@@ -127,3 +130,125 @@
|
|
|
127
130
|
@apply bg-background text-foreground;
|
|
128
131
|
}
|
|
129
132
|
}
|
|
133
|
+
|
|
134
|
+
/* ────────────────────────────────────────────────────────────────────────
|
|
135
|
+
* Interaction state layer — light mode.
|
|
136
|
+
*
|
|
137
|
+
* shadcn spends ABSOLUTE colors on interaction states: `--accent`, `--muted`
|
|
138
|
+
* and `--sidebar-accent` are all `oklch(0.97 0 0)`, i.e. 3% off white. Dark
|
|
139
|
+
* mode gets a 12% step (0.145 → 0.269), which is why only light mode reads as
|
|
140
|
+
* broken — this whole block is scoped to light and leaves dark bit-for-bit.
|
|
141
|
+
*
|
|
142
|
+
* An absolute fill cannot track a surface that varies, so the step shrinks to
|
|
143
|
+
* nothing as the surface darkens: on `--sidebar` (0.985) it is 1.5%, and a
|
|
144
|
+
* `hover:bg-muted` child sitting on a `bg-muted` panel is a 0% step — the
|
|
145
|
+
* state is literally invisible. Below 0.97 it inverts and hovering BRIGHTENS.
|
|
146
|
+
*
|
|
147
|
+
* So the state fill is an ALPHA WASH rather than a color. Alpha composites
|
|
148
|
+
* over whatever it lands on, which turns the step into a constant ratio of the
|
|
149
|
+
* surface instead of a fixed color: the same weight on white, on a card, on
|
|
150
|
+
* the sidebar and on every Lore theme, and never lighter than its own
|
|
151
|
+
* background. Same idiom the stock `secondary` button variant already uses
|
|
152
|
+
* (`color-mix(in oklch, var(--secondary), var(--foreground) 5%)`).
|
|
153
|
+
*
|
|
154
|
+
* ⚠️ This file is the durable place for it. `src/components/ui/` is
|
|
155
|
+
* overwritten wholesale by `yarn w @alepha/ui sync`, so the same fix written
|
|
156
|
+
* into a primitive's classes would not survive the next sync. This file is not
|
|
157
|
+
* sync-managed.
|
|
158
|
+
* ──────────────────────────────────────────────────────────────────────── */
|
|
159
|
+
|
|
160
|
+
:root:not(.dark) {
|
|
161
|
+
--state-layer: color-mix(in oklch, var(--foreground) 10%, transparent);
|
|
162
|
+
--state-layer-weak: color-mix(in oklch, var(--foreground) 5%, transparent);
|
|
163
|
+
|
|
164
|
+
/* `--accent` and `--sidebar-accent` are PURE interaction tokens across this
|
|
165
|
+
* package and apps/lore — every single use is hover/focus/open/selected,
|
|
166
|
+
* never an opaque surface (verified by grep, incl. the bare `bg-accent`
|
|
167
|
+
* selected-state uses). So the wash goes on the token itself and reaches
|
|
168
|
+
* every state variant at once — hover, focus, data-open, data-highlighted,
|
|
169
|
+
* data-active, aria-expanded — with no selector list to keep in sync.
|
|
170
|
+
*
|
|
171
|
+
* This deliberately overrides the per-theme `--accent` values in Lore's
|
|
172
|
+
* main.css: those were hand-tuned per surface, which is exactly the approach
|
|
173
|
+
* that does not scale. Specificity (0,2,0) beats a bare `.theme-*` (0,1,0). */
|
|
174
|
+
--accent: var(--state-layer);
|
|
175
|
+
--sidebar-accent: var(--state-layer);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* `--muted` is the exception: it is BOTH a state fill and an opaque surface
|
|
179
|
+
* (progress track, tabs list, kbd, card footer, slider). It must stay opaque,
|
|
180
|
+
* so its state variants are reached by selector instead of via the token.
|
|
181
|
+
*
|
|
182
|
+
* Unlayered on purpose — Tailwind's utilities live in `@layer utilities`, and
|
|
183
|
+
* unlayered styles beat layered ones whatever the specificity, so this wins
|
|
184
|
+
* without `!important` and without racing selector counts.
|
|
185
|
+
*
|
|
186
|
+
* Every match is `[class~=]`, the exact space-separated token — never
|
|
187
|
+
* `[class*=]`. A substring match looks equivalent and is not: it also matches
|
|
188
|
+
* `dark:hover:bg-muted/50`, so a ghost button rendered in LIGHT mode picked up
|
|
189
|
+
* the weak layer off its dark-mode class and came out at half strength. Exact
|
|
190
|
+
* tokens cannot do that. The cost is that the fractional list below is
|
|
191
|
+
* enumerated rather than wildcarded — a fraction nobody listed keeps today's
|
|
192
|
+
* behaviour, which is a no-op, not a wrong result. */
|
|
193
|
+
:root:not(.dark)
|
|
194
|
+
:is(
|
|
195
|
+
[class~="hover:bg-muted"]:hover,
|
|
196
|
+
[class~="focus:bg-muted"]:focus,
|
|
197
|
+
[class~="aria-expanded:bg-muted"][aria-expanded="true"]
|
|
198
|
+
) {
|
|
199
|
+
background-color: var(--state-layer);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
:root:not(.dark)
|
|
203
|
+
:is(
|
|
204
|
+
[class~="hover:bg-muted/30"]:hover,
|
|
205
|
+
[class~="hover:bg-muted/40"]:hover,
|
|
206
|
+
[class~="hover:bg-muted/50"]:hover,
|
|
207
|
+
[class~="hover:bg-muted/60"]:hover,
|
|
208
|
+
[class~="hover:bg-muted/70"]:hover,
|
|
209
|
+
[class~="data-open:bg-muted/50"][data-open],
|
|
210
|
+
[class~="data-active:bg-muted/50"][data-active],
|
|
211
|
+
[class~="data-popup-open:bg-muted/50"][data-popup-open],
|
|
212
|
+
[class~="aria-expanded:bg-muted/50"][aria-expanded="true"]
|
|
213
|
+
) {
|
|
214
|
+
background-color: var(--state-layer-weak);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/* ────────────────────────────────────────────────────────────────────────
|
|
218
|
+
* Sidebar active item — a left bar, not a heavier fill.
|
|
219
|
+
*
|
|
220
|
+
* The state layer above deliberately gives the active item the SAME weight as
|
|
221
|
+
* a hovered one, because shadcn spends one token on both. That leaves two
|
|
222
|
+
* adjacent rows — the current page and the one under the pointer — rendering
|
|
223
|
+
* as a single merged shape with no way to tell them apart.
|
|
224
|
+
*
|
|
225
|
+
* The bar resolves it without touching the fill. Presence/absence of a shape
|
|
226
|
+
* is not a color distinction, so it survives where two fills never would: low
|
|
227
|
+
* vision, a bad display, or any theme whose surface drifts. Hover stays purely
|
|
228
|
+
* a fill, so the two states never encode the same way.
|
|
229
|
+
*
|
|
230
|
+
* Both modes, unlike the state layer above: the collision it fixes is
|
|
231
|
+
* shadcn's one-token design, which is present in dark too — dark just happens
|
|
232
|
+
* to render both at `oklch(0.308 0 0)` instead of both at a 10% wash.
|
|
233
|
+
*
|
|
234
|
+
* `--sidebar-primary` rather than a fixed color, so every Lore theme carries
|
|
235
|
+
* its own hue with no per-theme values. Lives here rather than in
|
|
236
|
+
* `sidebar.tsx`, which `yarn w @alepha/ui sync` overwrites wholesale.
|
|
237
|
+
* ──────────────────────────────────────────────────────────────────────── */
|
|
238
|
+
|
|
239
|
+
[data-slot="sidebar-menu-button"][data-active],
|
|
240
|
+
[data-slot="sidebar-menu-sub-button"][data-active] {
|
|
241
|
+
position: relative;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
[data-slot="sidebar-menu-button"][data-active]::after,
|
|
245
|
+
[data-slot="sidebar-menu-sub-button"][data-active]::after {
|
|
246
|
+
content: "";
|
|
247
|
+
position: absolute;
|
|
248
|
+
top: 0.25rem;
|
|
249
|
+
bottom: 0.25rem;
|
|
250
|
+
left: 0;
|
|
251
|
+
width: 3px;
|
|
252
|
+
border-radius: 9999px;
|
|
253
|
+
background-color: var(--sidebar-primary);
|
|
254
|
+
}
|
/package/src/components/{admin/admin-user-detail-provider-labels.ts → auth/provider-labels.ts}
RENAMED
|
File without changes
|