@alepha/ui 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +12 -0
  2. package/components.json +20 -0
  3. package/package.json +85 -0
  4. package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
  5. package/src/components/admin/admin-audits.tsx +247 -0
  6. package/src/components/admin/admin-files.tsx +346 -0
  7. package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
  8. package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
  9. package/src/components/admin/admin-jobs.tsx +294 -0
  10. package/src/components/admin/admin-keys.tsx +162 -0
  11. package/src/components/admin/admin-notifications.tsx +130 -0
  12. package/src/components/admin/admin-page.tsx +24 -0
  13. package/src/components/admin/admin-parameters.tsx +864 -0
  14. package/src/components/admin/admin-payments.tsx +93 -0
  15. package/src/components/admin/admin-sessions.tsx +174 -0
  16. package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
  17. package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
  18. package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
  19. package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
  20. package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
  21. package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
  22. package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
  23. package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
  24. package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
  25. package/src/components/admin/admin-user-detail.tsx +606 -0
  26. package/src/components/admin/admin-users-roles-picker.tsx +126 -0
  27. package/src/components/admin/admin-users-status-filter.tsx +51 -0
  28. package/src/components/admin/admin-users.tsx +518 -0
  29. package/src/components/admin/diff-lines.spec.ts +58 -0
  30. package/src/components/admin/diff-lines.ts +58 -0
  31. package/src/components/admin/parameter-diff-dialog.tsx +119 -0
  32. package/src/components/admin/parameter-history-item.tsx +252 -0
  33. package/src/components/admin/parameter-json-dialog.tsx +93 -0
  34. package/src/components/admin/parameter-save-dialog.tsx +126 -0
  35. package/src/components/admin/use-confirmed-action.tsx +93 -0
  36. package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
  37. package/src/components/alepha-table/alepha-table.tsx +1158 -0
  38. package/src/components/alepha-table/use-table-selection.ts +95 -0
  39. package/src/components/app-shell/app-shell.tsx +568 -0
  40. package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
  41. package/src/components/auth/auth-login.tsx +382 -0
  42. package/src/components/auth/auth-register.tsx +786 -0
  43. package/src/components/auth/auth-reset-password.tsx +349 -0
  44. package/src/components/auth/auth-router.tsx +126 -0
  45. package/src/components/auth/auth-verify-email.tsx +179 -0
  46. package/src/components/auto-form/auto-form.tsx +867 -0
  47. package/src/components/brand-icon/brand-icon.tsx +104 -0
  48. package/src/components/button-dark/button-dark.tsx +78 -0
  49. package/src/components/button-language/button-language.tsx +98 -0
  50. package/src/components/button-theme/button-theme.tsx +148 -0
  51. package/src/components/button-user/button-user.tsx +214 -0
  52. package/src/components/captcha/turnstile-widget.tsx +157 -0
  53. package/src/components/control/control.tsx +735 -0
  54. package/src/components/control-array/control-array.tsx +700 -0
  55. package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
  56. package/src/components/control-base/field-i18n.ts +60 -0
  57. package/src/components/control-base/form-field.tsx +275 -0
  58. package/src/components/control-base/grid.tsx +59 -0
  59. package/src/components/control-base/icon-hint.tsx +64 -0
  60. package/src/components/control-date/control-date.tsx +190 -0
  61. package/src/components/control-number/control-number.tsx +136 -0
  62. package/src/components/control-object/control-object.tsx +200 -0
  63. package/src/components/control-select/control-select.tsx +774 -0
  64. package/src/components/control-upload/control-upload.tsx +475 -0
  65. package/src/components/file-image/file-image.tsx +52 -0
  66. package/src/components/language-toggle/language-toggle.tsx +66 -0
  67. package/src/components/markdown-view/markdown-view.css +114 -0
  68. package/src/components/markdown-view/markdown-view.tsx +92 -0
  69. package/src/components/nav-shell/nav-page.tsx +56 -0
  70. package/src/components/nav-shell/nav-shell.tsx +72 -0
  71. package/src/components/nav-shell/nav-tree-util.ts +62 -0
  72. package/src/components/nav-shell/spotlight.tsx +163 -0
  73. package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
  74. package/src/components/nav-shell/use-nav-entries.ts +101 -0
  75. package/src/components/nav-shell/use-nav-tree.ts +61 -0
  76. package/src/components/ui/accordion.tsx +77 -0
  77. package/src/components/ui/alert-dialog.tsx +186 -0
  78. package/src/components/ui/alert.tsx +75 -0
  79. package/src/components/ui/aspect-ratio.tsx +22 -0
  80. package/src/components/ui/avatar.tsx +106 -0
  81. package/src/components/ui/badge.tsx +51 -0
  82. package/src/components/ui/breadcrumb.tsx +121 -0
  83. package/src/components/ui/button-group.tsx +86 -0
  84. package/src/components/ui/button.tsx +83 -0
  85. package/src/components/ui/calendar.tsx +235 -0
  86. package/src/components/ui/card.tsx +102 -0
  87. package/src/components/ui/carousel.tsx +241 -0
  88. package/src/components/ui/chart.tsx +370 -0
  89. package/src/components/ui/checkbox.tsx +27 -0
  90. package/src/components/ui/collapsible.tsx +19 -0
  91. package/src/components/ui/combobox.tsx +298 -0
  92. package/src/components/ui/command.tsx +196 -0
  93. package/src/components/ui/context-menu.tsx +271 -0
  94. package/src/components/ui/dialog.tsx +153 -0
  95. package/src/components/ui/direction.tsx +4 -0
  96. package/src/components/ui/drawer.tsx +130 -0
  97. package/src/components/ui/dropdown-menu.tsx +269 -0
  98. package/src/components/ui/empty.tsx +100 -0
  99. package/src/components/ui/hover-card.tsx +50 -0
  100. package/src/components/ui/input-group.tsx +157 -0
  101. package/src/components/ui/input-otp.tsx +83 -0
  102. package/src/components/ui/input.tsx +19 -0
  103. package/src/components/ui/item.tsx +200 -0
  104. package/src/components/ui/kbd.tsx +26 -0
  105. package/src/components/ui/label.tsx +19 -0
  106. package/src/components/ui/menubar.tsx +283 -0
  107. package/src/components/ui/navigation-menu.tsx +170 -0
  108. package/src/components/ui/pagination.tsx +133 -0
  109. package/src/components/ui/popover.tsx +87 -0
  110. package/src/components/ui/progress.tsx +82 -0
  111. package/src/components/ui/radio-group.tsx +35 -0
  112. package/src/components/ui/resizable.tsx +49 -0
  113. package/src/components/ui/scroll-area.tsx +51 -0
  114. package/src/components/ui/segmented.tsx +232 -0
  115. package/src/components/ui/select.tsx +201 -0
  116. package/src/components/ui/separator.tsx +22 -0
  117. package/src/components/ui/sheet.tsx +133 -0
  118. package/src/components/ui/sidebar.tsx +723 -0
  119. package/src/components/ui/skeleton.tsx +13 -0
  120. package/src/components/ui/slider.tsx +51 -0
  121. package/src/components/ui/sonner.tsx +46 -0
  122. package/src/components/ui/spinner.tsx +15 -0
  123. package/src/components/ui/switch.tsx +29 -0
  124. package/src/components/ui/table.tsx +115 -0
  125. package/src/components/ui/tabs.tsx +79 -0
  126. package/src/components/ui/textarea.tsx +17 -0
  127. package/src/components/ui/toggle-group.tsx +86 -0
  128. package/src/components/ui/toggle.tsx +44 -0
  129. package/src/components/ui/tooltip.tsx +63 -0
  130. package/src/components/use-dialog/use-dialog.tsx +244 -0
  131. package/src/components/use-toast/use-toast.tsx +89 -0
  132. package/src/hooks/use-mobile.ts +21 -0
  133. package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
  134. package/src/lib/i18n-fr.ts +500 -0
  135. package/src/lib/utils.ts +6 -0
  136. package/src/styles.css +129 -0
@@ -0,0 +1,475 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { FormField } from "@alepha/ui/components/control-base/form-field";
6
+ import { Button } from "@alepha/ui/components/ui/button";
7
+ import {
8
+ Dialog,
9
+ DialogContent,
10
+ DialogDescription,
11
+ DialogHeader,
12
+ DialogTitle,
13
+ } from "@alepha/ui/components/ui/dialog";
14
+ import {
15
+ Tooltip,
16
+ TooltipContent,
17
+ TooltipTrigger,
18
+ } from "@alepha/ui/components/ui/tooltip";
19
+ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
20
+ import type { FileController } from "alepha/api/files";
21
+ import { useClient } from "alepha/react";
22
+ import {
23
+ type BaseInputField,
24
+ parseField,
25
+ useFieldValue,
26
+ useFormState,
27
+ } from "alepha/react/form";
28
+ import { useI18n } from "alepha/react/i18n";
29
+ import { File as FileIcon, Loader2, Upload, X } from "lucide-react";
30
+ import {
31
+ type ChangeEvent,
32
+ type DragEvent,
33
+ useEffect,
34
+ useId,
35
+ useRef,
36
+ useState,
37
+ } from "react";
38
+
39
+ export interface ControlUploadProps {
40
+ /**
41
+ * Bound `InputField` from `useForm`. Stores the uploaded file ID(s).
42
+ */
43
+ input: BaseInputField;
44
+ /**
45
+ * Field label. Falls back to schema `title`.
46
+ */
47
+ label?: string;
48
+ /**
49
+ * Helper text shown below the dropzone.
50
+ */
51
+ description?: string;
52
+ /**
53
+ * Multi-file mode. The form value becomes an `Array<string>` of file
54
+ * IDs. Single mode (default) stores a bare UUID string.
55
+ */
56
+ multi?: boolean;
57
+ /**
58
+ * HTML `accept` filter on the file picker (e.g. `"image/*"`,
59
+ * `".pdf,.docx"`).
60
+ */
61
+ accept?: string;
62
+ /**
63
+ * Max size per file (bytes). Files over the limit are rejected.
64
+ */
65
+ maxSize?: number;
66
+ /**
67
+ * Bucket name passed to the upload endpoint.
68
+ */
69
+ bucket?: string;
70
+ /**
71
+ * Disable the dropzone.
72
+ */
73
+ disabled?: boolean;
74
+ }
75
+
76
+ interface UploadedFileMeta {
77
+ id: string;
78
+ name: string;
79
+ mimeType?: string;
80
+ size?: number;
81
+ /**
82
+ * Object URL for image preview, when applicable.
83
+ */
84
+ previewUrl?: string;
85
+ }
86
+
87
+ /**
88
+ * File upload control. Wraps `FileController.uploadFile`, stores the
89
+ * resulting file ID(s) in the form, and renders a thumbnail preview for
90
+ * images and a chip-style summary for everything else.
91
+ *
92
+ * Single-file: form value is a uuid string.
93
+ * Multi-file: form value is an array of uuid strings.
94
+ */
95
+ export function ControlUpload(props: ControlUploadProps) {
96
+ const form = useFormState(props.input, ["error"]);
97
+ const [value, setValue] = useFieldValue(props.input);
98
+ const client = useClient<FileController>();
99
+ const { tr } = useI18n();
100
+ const toast = useToast();
101
+ const inputId = useId();
102
+ const fileInputRef = useRef<HTMLInputElement>(null);
103
+ const [uploading, setUploading] = useState(false);
104
+ const [progress, setProgress] = useState(0);
105
+ const [meta, setMeta] = useState<Map<string, UploadedFileMeta>>(new Map());
106
+ const [dragOver, setDragOver] = useState(false);
107
+ const [previewId, setPreviewId] = useState<string | null>(null);
108
+
109
+ /**
110
+ * Backfill `meta` for ids that arrived from form state (e.g. after a page
111
+ * reload) so the renderer can show a thumbnail / chip instead of the raw
112
+ * uuid. We can't infer the real mime type without an extra request, so we
113
+ * fall back to a stub entry pointing at `/api/files/:id` and let the
114
+ * `<img>` `onError` swap to the generic file chip.
115
+ */
116
+ useEffect(() => {
117
+ const ids: string[] = props.multi
118
+ ? Array.isArray(value)
119
+ ? (value as string[])
120
+ : []
121
+ : value
122
+ ? [value as string]
123
+ : [];
124
+ setMeta((current) => {
125
+ let changed = false;
126
+ const next = new Map(current);
127
+ for (const id of ids) {
128
+ if (!next.has(id)) {
129
+ next.set(id, {
130
+ id,
131
+ name: id,
132
+ previewUrl: `/api/files/${id}`,
133
+ });
134
+ changed = true;
135
+ }
136
+ }
137
+ return changed ? next : current;
138
+ });
139
+ }, [Array.isArray(value) ? value.join(",") : value, props.multi]);
140
+
141
+ if (!props.input?.props) return null;
142
+
143
+ const fieldMeta = parseField(props.input, {
144
+ label: props.label,
145
+ description: props.description,
146
+ error: form.error,
147
+ });
148
+
149
+ const ids: string[] = props.multi
150
+ ? Array.isArray(value)
151
+ ? (value as string[])
152
+ : []
153
+ : value
154
+ ? [value as string]
155
+ : [];
156
+
157
+ const handleFiles = async (files: FileList) => {
158
+ if (!files.length) return;
159
+ if (!props.multi && files.length > 1) {
160
+ toast.error(
161
+ tr("controlUpload.singleOnly", { default: "Only one file allowed" }),
162
+ );
163
+ return;
164
+ }
165
+
166
+ setUploading(true);
167
+ setProgress(0);
168
+ const next = new Map(meta);
169
+ const newIds: string[] = [];
170
+
171
+ try {
172
+ for (let i = 0; i < files.length; i++) {
173
+ const file = files[i];
174
+
175
+ if (props.maxSize && file.size > props.maxSize) {
176
+ toast.error(
177
+ tr("controlUpload.tooBig", {
178
+ default: `${file.name} exceeds ${formatBytes(props.maxSize)}`,
179
+ args: [file.name, formatBytes(props.maxSize)],
180
+ }),
181
+ );
182
+ continue;
183
+ }
184
+
185
+ const resource = await client.uploadFile({
186
+ body: { file },
187
+ query: props.bucket ? { bucket: props.bucket } : ({} as never),
188
+ });
189
+
190
+ const previewUrl = file.type.startsWith("image/")
191
+ ? URL.createObjectURL(file)
192
+ : undefined;
193
+
194
+ next.set(resource.id, {
195
+ id: resource.id,
196
+ name: resource.name ?? file.name,
197
+ mimeType: resource.mimeType ?? file.type,
198
+ size: resource.size ?? file.size,
199
+ previewUrl,
200
+ });
201
+ newIds.push(resource.id);
202
+ setProgress(Math.round(((i + 1) / files.length) * 100));
203
+ }
204
+
205
+ setMeta(next);
206
+ if (props.multi) {
207
+ setValue([...ids, ...newIds]);
208
+ } else if (newIds[0]) {
209
+ setValue(newIds[0]);
210
+ }
211
+ if (newIds.length) {
212
+ toast.success(
213
+ newIds.length === 1
214
+ ? tr("controlUpload.uploadedOne", { default: "File uploaded" })
215
+ : tr("controlUpload.uploadedMany", {
216
+ default: `${newIds.length} files uploaded`,
217
+ args: [String(newIds.length)],
218
+ }),
219
+ );
220
+ }
221
+ } catch (e) {
222
+ const msg = (e as Error).message;
223
+ toast.error(
224
+ tr("controlUpload.failed", {
225
+ default: `Upload failed: ${msg}`,
226
+ args: [msg],
227
+ }),
228
+ );
229
+ } finally {
230
+ setUploading(false);
231
+ setProgress(0);
232
+ if (fileInputRef.current) fileInputRef.current.value = "";
233
+ }
234
+ };
235
+
236
+ const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
237
+ if (e.target.files) handleFiles(e.target.files);
238
+ };
239
+
240
+ const handleDrop = (e: DragEvent) => {
241
+ e.preventDefault();
242
+ setDragOver(false);
243
+ if (props.disabled) return;
244
+ if (e.dataTransfer.files) handleFiles(e.dataTransfer.files);
245
+ };
246
+
247
+ const removeOne = (id: string) => {
248
+ const next = new Map(meta);
249
+ const item = next.get(id);
250
+ if (item?.previewUrl) URL.revokeObjectURL(item.previewUrl);
251
+ next.delete(id);
252
+ setMeta(next);
253
+
254
+ if (props.multi) {
255
+ setValue(ids.filter((it) => it !== id));
256
+ } else {
257
+ setValue(undefined);
258
+ }
259
+ };
260
+
261
+ const renderItem = (id: string) => {
262
+ const item = meta.get(id);
263
+ const acceptsImage = (props.accept ?? "").includes("image");
264
+ const mimeIsImage = item?.mimeType?.startsWith("image/");
265
+ const isImage =
266
+ mimeIsImage || (acceptsImage && !!item?.previewUrl && !item?.mimeType);
267
+
268
+ const canClear = !props.disabled && !fieldMeta.required;
269
+
270
+ return (
271
+ <div
272
+ key={id}
273
+ className={`relative flex h-9 cursor-zoom-in items-center rounded-md border border-input bg-transparent pl-1 dark:bg-input/30 ${canClear ? "pr-9" : "pr-2"}`}
274
+ onClick={() => setPreviewId(id)}
275
+ onKeyDown={(e) => {
276
+ if (e.key === "Enter" || e.key === " ") {
277
+ e.preventDefault();
278
+ setPreviewId(id);
279
+ }
280
+ }}
281
+ role="button"
282
+ tabIndex={0}
283
+ >
284
+ {isImage && item?.previewUrl ? (
285
+ <ItemThumb url={item.previewUrl} alt={item.name ?? id} />
286
+ ) : (
287
+ <div className="bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded">
288
+ <FileIcon className="size-4" />
289
+ </div>
290
+ )}
291
+ {canClear && (
292
+ <button
293
+ type="button"
294
+ onClick={(e) => {
295
+ e.stopPropagation();
296
+ removeOne(id);
297
+ }}
298
+ aria-label={tr("controlUpload.remove", { default: "Remove" })}
299
+ className="text-muted-foreground hover:text-foreground absolute top-1/2 right-2 -translate-y-1/2 p-1"
300
+ >
301
+ <X className="size-3.5" />
302
+ </button>
303
+ )}
304
+ </div>
305
+ );
306
+ };
307
+
308
+ const previewItem = previewId ? meta.get(previewId) : undefined;
309
+ const previewIsImage = previewItem
310
+ ? previewItem.mimeType?.startsWith("image/") ||
311
+ ((props.accept ?? "").includes("image") &&
312
+ !!previewItem.previewUrl &&
313
+ !previewItem.mimeType)
314
+ : false;
315
+ const previewHasName =
316
+ !!previewItem?.name && previewItem.name !== previewItem.id;
317
+
318
+ const dragDropHint =
319
+ tr("controlUpload.dragDrop", { default: "Upload or drag and drop here" }) +
320
+ (props.maxSize
321
+ ? ` · ${tr("controlUpload.max", {
322
+ default: `max ${formatBytes(props.maxSize)}`,
323
+ args: [formatBytes(props.maxSize)],
324
+ })}`
325
+ : "");
326
+
327
+ const dropZone = (
328
+ <Tooltip>
329
+ <TooltipTrigger
330
+ render={
331
+ <Button
332
+ type="button"
333
+ variant="outline"
334
+ size="sm"
335
+ disabled={props.disabled || uploading}
336
+ onClick={() => fileInputRef.current?.click()}
337
+ onDragOver={(e) => {
338
+ e.preventDefault();
339
+ setDragOver(true);
340
+ }}
341
+ onDragLeave={() => setDragOver(false)}
342
+ onDrop={handleDrop}
343
+ className={dragOver ? "border-primary bg-primary/5" : ""}
344
+ />
345
+ }
346
+ >
347
+ {uploading ? (
348
+ <>
349
+ <Loader2 className="size-4 mr-1 animate-spin" />
350
+ {tr("controlUpload.uploading", { default: "Uploading…" })}
351
+ </>
352
+ ) : (
353
+ <>
354
+ <Upload className="size-4 mr-1" />
355
+ {props.multi
356
+ ? tr("controlUpload.chooseFiles", { default: "Choose files" })
357
+ : tr("controlUpload.chooseFile", { default: "Choose a file" })}
358
+ </>
359
+ )}
360
+ </TooltipTrigger>
361
+ <TooltipContent>{dragDropHint}</TooltipContent>
362
+ </Tooltip>
363
+ );
364
+
365
+ return (
366
+ <FormField
367
+ id={inputId}
368
+ label={fieldMeta.label}
369
+ description={fieldMeta.description}
370
+ error={fieldMeta.error}
371
+ required={fieldMeta.required}
372
+ >
373
+ <input
374
+ ref={fileInputRef}
375
+ type="file"
376
+ id={inputId}
377
+ name={props.input.props.name}
378
+ className="hidden"
379
+ accept={props.accept}
380
+ multiple={props.multi}
381
+ disabled={props.disabled}
382
+ onChange={handleInputChange}
383
+ />
384
+
385
+ <div className="flex flex-col gap-2">
386
+ {ids.length > 0 && (
387
+ <div className="flex flex-col gap-2">{ids.map(renderItem)}</div>
388
+ )}
389
+ {(props.multi || ids.length === 0) && dropZone}
390
+ {uploading && (
391
+ <div className="bg-muted h-1 w-full overflow-hidden rounded">
392
+ <div
393
+ className="bg-primary h-full transition-all"
394
+ style={{ width: `${progress}%` }}
395
+ />
396
+ </div>
397
+ )}
398
+ </div>
399
+
400
+ <Dialog
401
+ open={previewId !== null}
402
+ onOpenChange={(o) => !o && setPreviewId(null)}
403
+ >
404
+ <DialogContent className="w-fit max-w-fit p-0">
405
+ <DialogHeader className="sr-only">
406
+ <DialogTitle>
407
+ {previewHasName
408
+ ? previewItem?.name
409
+ : tr("controlUpload.savedFile", { default: "Saved file" })}
410
+ </DialogTitle>
411
+ <DialogDescription>
412
+ {previewItem?.mimeType ?? "uploaded"}
413
+ </DialogDescription>
414
+ </DialogHeader>
415
+ <div className="p-4">
416
+ {previewIsImage && previewItem?.previewUrl ? (
417
+ <img
418
+ src={previewItem.previewUrl}
419
+ alt={previewItem.name ?? ""}
420
+ className="size-72 rounded object-contain"
421
+ />
422
+ ) : (
423
+ <div className="bg-muted text-muted-foreground flex size-72 items-center justify-center rounded">
424
+ <FileIcon className="size-16" />
425
+ </div>
426
+ )}
427
+ </div>
428
+ {(previewHasName || previewItem?.mimeType) && (
429
+ <div className="flex flex-col gap-0 border-t bg-muted/30 px-4 py-2">
430
+ {previewHasName && (
431
+ <span className="truncate text-sm font-medium">
432
+ {previewItem?.name}
433
+ </span>
434
+ )}
435
+ {previewItem?.mimeType && (
436
+ <span className="text-muted-foreground truncate text-xs">
437
+ {previewItem.mimeType}
438
+ </span>
439
+ )}
440
+ </div>
441
+ )}
442
+ </DialogContent>
443
+ </Dialog>
444
+ </FormField>
445
+ );
446
+ }
447
+
448
+ function ItemThumb(props: { url: string; alt: string }) {
449
+ const [broken, setBroken] = useState(false);
450
+ if (broken) {
451
+ return (
452
+ <div className="bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded">
453
+ <FileIcon className="size-4" />
454
+ </div>
455
+ );
456
+ }
457
+ return (
458
+ <img
459
+ src={props.url}
460
+ alt={props.alt}
461
+ className="size-7 shrink-0 rounded object-cover"
462
+ onError={() => setBroken(true)}
463
+ />
464
+ );
465
+ }
466
+
467
+ const formatBytes = (n: number): string => {
468
+ if (!n) return "0 B";
469
+ const units = ["B", "KB", "MB", "GB"];
470
+ const i = Math.min(
471
+ units.length - 1,
472
+ Math.floor(Math.log(n) / Math.log(1024)),
473
+ );
474
+ return `${(n / 1024 ** i).toFixed(1)} ${units[i]}`;
475
+ };
@@ -0,0 +1,52 @@
1
+ import { type ComponentProps, type ReactNode, useState } from "react";
2
+
3
+ export interface FileImageProps
4
+ extends Omit<ComponentProps<"img">, "src" | "id"> {
5
+ /**
6
+ * File id (uuid) served by the Alepha files module. Absent → renders
7
+ * `fallback`. (Repurposes the `id` slot — the raw HTML `id` attribute
8
+ * isn't forwarded.)
9
+ */
10
+ id?: string | null;
11
+ /**
12
+ * Serve via the anonymous, edge-cacheable `/api/public/files/:id` route
13
+ * instead of the authenticated `/api/files/:id`. Only valid for files the
14
+ * server opts into (`FileAccessProvider.assertPublic`). Default:
15
+ * authenticated.
16
+ */
17
+ public?: boolean;
18
+ /**
19
+ * Rendered when `id` is missing OR the image fails to load (deleted, 404,
20
+ * forbidden) — a placeholder icon/initials instead of a broken-image glyph.
21
+ */
22
+ fallback?: ReactNode;
23
+ }
24
+
25
+ /**
26
+ * `<img>` for a file served by the Alepha files module, addressed by uuid.
27
+ *
28
+ * Resolves the src from `id` (`public` picks the anonymous edge-cacheable
29
+ * route vs the authenticated one), lazy-loads, and renders `fallback` when
30
+ * the id is missing or the image fails to load — so a deleted/forbidden
31
+ * file shows a placeholder instead of a broken-image glyph.
32
+ */
33
+ export const FileImage = (props: FileImageProps) => {
34
+ const { id, public: isPublic, fallback = null, ...imgProps } = props;
35
+ // Track the id that failed so a later id change re-attempts the load.
36
+ const [erroredId, setErroredId] = useState<string | null>(null);
37
+
38
+ if (!id || erroredId === id) {
39
+ return <>{fallback}</>;
40
+ }
41
+
42
+ const src = isPublic ? `/api/public/files/${id}` : `/api/files/${id}`;
43
+ return (
44
+ <img
45
+ alt=""
46
+ src={src}
47
+ loading="lazy"
48
+ onError={() => setErroredId(id)}
49
+ {...imgProps}
50
+ />
51
+ );
52
+ };
@@ -0,0 +1,66 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Button } from "@alepha/ui/components/ui/button";
6
+ import {
7
+ DropdownMenu,
8
+ DropdownMenuCheckboxItem,
9
+ DropdownMenuContent,
10
+ DropdownMenuTrigger,
11
+ } from "@alepha/ui/components/ui/dropdown-menu";
12
+ import { useI18n } from "alepha/react/i18n";
13
+ import { Languages } from "lucide-react";
14
+
15
+ const LABELS: Record<string, string> = {
16
+ en: "English",
17
+ fr: "Français",
18
+ es: "Español",
19
+ de: "Deutsch",
20
+ it: "Italiano",
21
+ pt: "Português",
22
+ ja: "日本語",
23
+ zh: "中文",
24
+ };
25
+
26
+ const labelFor = (code: string) =>
27
+ LABELS[code] ?? LABELS[code.split("-")[0]] ?? code.toUpperCase();
28
+
29
+ /**
30
+ * Dropdown that lists every language registered via `$dictionary` and lets the
31
+ * user switch. Reads the active language and the registered list directly from
32
+ * `useI18n()`, so it stays in sync without extra wiring.
33
+ */
34
+ export function LanguageToggle() {
35
+ const i18n = useI18n();
36
+ const languages = i18n.languages;
37
+
38
+ if (languages.length <= 1) {
39
+ return null;
40
+ }
41
+
42
+ return (
43
+ <DropdownMenu>
44
+ <DropdownMenuTrigger
45
+ render={
46
+ <Button variant="ghost" size="icon" aria-label="Switch language" />
47
+ }
48
+ >
49
+ <Languages className="size-4" />
50
+ </DropdownMenuTrigger>
51
+ <DropdownMenuContent align="end">
52
+ {languages.map((code) => (
53
+ <DropdownMenuCheckboxItem
54
+ key={code}
55
+ checked={i18n.lang === code}
56
+ onCheckedChange={() => {
57
+ void i18n.setLang(code);
58
+ }}
59
+ >
60
+ {labelFor(code)}
61
+ </DropdownMenuCheckboxItem>
62
+ ))}
63
+ </DropdownMenuContent>
64
+ </DropdownMenu>
65
+ );
66
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Theme-aware syntax highlighting for highlight.js.
3
+ * Light palette is GitHub Light; dark palette (under `.dark` ancestor) is GitHub Dark.
4
+ * Backgrounds are intentionally transparent so the code block inherits its container bg.
5
+ */
6
+
7
+ .hljs {
8
+ display: block;
9
+ overflow-x: auto;
10
+ background: transparent;
11
+ color: var(--hljs-fg);
12
+ }
13
+
14
+ .hljs-comment,
15
+ .hljs-quote {
16
+ color: var(--hljs-comment);
17
+ font-style: italic;
18
+ }
19
+
20
+ .hljs-keyword,
21
+ .hljs-selector-tag,
22
+ .hljs-subst {
23
+ color: var(--hljs-keyword);
24
+ }
25
+
26
+ .hljs-number,
27
+ .hljs-literal,
28
+ .hljs-variable,
29
+ .hljs-template-variable,
30
+ .hljs-tag .hljs-attr {
31
+ color: var(--hljs-number);
32
+ }
33
+
34
+ .hljs-string,
35
+ .hljs-doctag,
36
+ .hljs-regexp,
37
+ .hljs-link {
38
+ color: var(--hljs-string);
39
+ }
40
+
41
+ .hljs-title,
42
+ .hljs-section,
43
+ .hljs-selector-id,
44
+ .hljs-type,
45
+ .hljs-class .hljs-title {
46
+ color: var(--hljs-title);
47
+ }
48
+
49
+ .hljs-tag,
50
+ .hljs-name,
51
+ .hljs-attribute {
52
+ color: var(--hljs-tag);
53
+ }
54
+
55
+ .hljs-symbol,
56
+ .hljs-bullet {
57
+ color: var(--hljs-symbol);
58
+ }
59
+
60
+ .hljs-built_in,
61
+ .hljs-builtin-name,
62
+ .hljs-params {
63
+ color: var(--hljs-builtin);
64
+ }
65
+
66
+ .hljs-meta {
67
+ color: var(--hljs-meta);
68
+ }
69
+
70
+ .hljs-deletion {
71
+ background: var(--hljs-deletion);
72
+ }
73
+
74
+ .hljs-addition {
75
+ background: var(--hljs-addition);
76
+ }
77
+
78
+ .hljs-emphasis {
79
+ font-style: italic;
80
+ }
81
+
82
+ .hljs-strong {
83
+ font-weight: bold;
84
+ }
85
+
86
+ :root {
87
+ --hljs-fg: #24292e;
88
+ --hljs-comment: #6a737d;
89
+ --hljs-keyword: #d73a49;
90
+ --hljs-number: #005cc5;
91
+ --hljs-string: #032f62;
92
+ --hljs-title: #6f42c1;
93
+ --hljs-tag: #22863a;
94
+ --hljs-symbol: #e36209;
95
+ --hljs-builtin: #005cc5;
96
+ --hljs-meta: #6a737d;
97
+ --hljs-deletion: #ffeef0;
98
+ --hljs-addition: #f0fff4;
99
+ }
100
+
101
+ .dark {
102
+ --hljs-fg: #c9d1d9;
103
+ --hljs-comment: #8b949e;
104
+ --hljs-keyword: #ff7b72;
105
+ --hljs-number: #79c0ff;
106
+ --hljs-string: #a5d6ff;
107
+ --hljs-title: #d2a8ff;
108
+ --hljs-tag: #7ee787;
109
+ --hljs-symbol: #ffa657;
110
+ --hljs-builtin: #79c0ff;
111
+ --hljs-meta: #8b949e;
112
+ --hljs-deletion: #67060c;
113
+ --hljs-addition: #033a16;
114
+ }