@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.
Files changed (104) hide show
  1. package/package.json +4 -5
  2. package/src/components/account/__tests__/account-router.spec.ts +201 -0
  3. package/src/components/account/account-connections.tsx +103 -0
  4. package/src/components/account/account-delete-dialog.tsx +184 -0
  5. package/src/components/account/account-header.tsx +57 -0
  6. package/src/components/account/account-keys.tsx +221 -0
  7. package/src/components/account/account-layout.tsx +63 -0
  8. package/src/components/account/account-password-dialog.tsx +152 -0
  9. package/src/components/account/account-profile.tsx +229 -0
  10. package/src/components/account/account-router-options.tsx +74 -0
  11. package/src/components/account/account-router-page.tsx +69 -0
  12. package/src/components/account/account-router.tsx +214 -0
  13. package/src/components/account/account-security.tsx +150 -0
  14. package/src/components/account/account-sessions.tsx +140 -0
  15. package/src/components/admin/__tests__/admin-keys-token-dialog.browser.spec.tsx +62 -0
  16. package/src/components/admin/__tests__/admin-layout.browser.spec.tsx +82 -0
  17. package/src/components/admin/__tests__/admin-router-page.spec.ts +54 -0
  18. package/src/components/admin/__tests__/admin-router.spec.ts +208 -0
  19. package/src/components/admin/__tests__/admin-user-cell.browser.spec.tsx +99 -0
  20. package/src/components/admin/__tests__/admin-user-detail.spec.ts +29 -0
  21. package/src/components/admin/admin-analytics-query-panel.tsx +149 -0
  22. package/src/components/admin/admin-analytics-results.tsx +95 -0
  23. package/src/components/admin/admin-analytics.tsx +104 -0
  24. package/src/components/admin/admin-audits.tsx +12 -15
  25. package/src/components/admin/admin-files.tsx +10 -18
  26. package/src/components/admin/admin-jobs-executions-panel.tsx +2 -1
  27. package/src/components/admin/admin-jobs.tsx +3 -1
  28. package/src/components/admin/admin-keys-token-dialog.tsx +123 -0
  29. package/src/components/admin/admin-keys.tsx +54 -3
  30. package/src/components/admin/admin-layout.tsx +107 -0
  31. package/src/components/admin/admin-payments.tsx +4 -5
  32. package/src/components/admin/admin-router-options.tsx +130 -0
  33. package/src/components/admin/admin-router-page.tsx +74 -0
  34. package/src/components/admin/admin-router.tsx +379 -0
  35. package/src/components/admin/admin-sessions.tsx +2 -16
  36. package/src/components/admin/admin-user-cell.tsx +70 -0
  37. package/src/components/admin/admin-user-detail-overview-tab.tsx +28 -0
  38. package/src/components/admin/admin-user-detail-profile-policy.spec.ts +146 -0
  39. package/src/components/admin/admin-user-detail-profile-policy.ts +147 -0
  40. package/src/components/admin/admin-user-detail-security-tab.tsx +1 -1
  41. package/src/components/admin/admin-user-detail.tsx +76 -32
  42. package/src/components/admin/admin-users-status-filter.tsx +2 -0
  43. package/src/components/admin/admin-workflows-execution-sheet.tsx +277 -0
  44. package/src/components/admin/admin-workflows-executions-panel.tsx +170 -0
  45. package/src/components/admin/admin-workflows-status-badge.tsx +40 -0
  46. package/src/components/admin/admin-workflows.tsx +207 -0
  47. package/src/components/alepha-table/alepha-table.tsx +73 -17
  48. package/src/components/app-actions/__tests__/app-actions.browser.spec.tsx +79 -0
  49. package/src/components/app-actions/app-actions.tsx +113 -0
  50. package/src/components/app-shell/app-shell.tsx +122 -0
  51. package/src/components/auth/auth-reset-password.tsx +81 -8
  52. package/src/components/button-user/button-user.tsx +58 -1
  53. package/src/components/control/control.tsx +14 -71
  54. package/src/components/control-password/control-password.tsx +87 -0
  55. package/src/components/control-select/__tests__/control-select-clear-label.browser.spec.tsx +101 -0
  56. package/src/components/control-select/__tests__/control-select-deselect.browser.spec.tsx +126 -0
  57. package/src/components/control-select/__tests__/control-select-searchable.browser.spec.tsx +142 -0
  58. package/src/components/control-select/control-select.tsx +133 -111
  59. package/src/components/control-upload/control-upload.tsx +27 -1
  60. package/src/components/markdown-view/markdown-view.tsx +6 -0
  61. package/src/components/nav-shell/nav-page.tsx +3 -3
  62. package/src/components/settings/__tests__/settings-nav.browser.spec.tsx +123 -0
  63. package/src/components/settings/__tests__/settings-section.browser.spec.tsx +130 -0
  64. package/src/components/settings/settings-danger-section.tsx +59 -0
  65. package/src/components/settings/settings-layout.tsx +56 -0
  66. package/src/components/settings/settings-nav.tsx +131 -0
  67. package/src/components/settings/settings-row.tsx +81 -0
  68. package/src/components/settings/settings-section.tsx +64 -0
  69. package/src/components/ui/alert-dialog.tsx +1 -1
  70. package/src/components/ui/avatar.tsx +2 -0
  71. package/src/components/ui/breadcrumb.tsx +1 -1
  72. package/src/components/ui/calendar.tsx +11 -6
  73. package/src/components/ui/card.tsx +5 -5
  74. package/src/components/ui/carousel.tsx +4 -4
  75. package/src/components/ui/chart.tsx +2 -0
  76. package/src/components/ui/collapsible.tsx +2 -0
  77. package/src/components/ui/combobox.tsx +3 -1
  78. package/src/components/ui/context-menu.tsx +3 -3
  79. package/src/components/ui/dialog.tsx +6 -1
  80. package/src/components/ui/direction.tsx +2 -0
  81. package/src/components/ui/drawer.tsx +134 -37
  82. package/src/components/ui/dropdown-menu.tsx +13 -3
  83. package/src/components/ui/empty.tsx +4 -1
  84. package/src/components/ui/input-otp.tsx +2 -0
  85. package/src/components/ui/menubar.tsx +2 -2
  86. package/src/components/ui/pagination.tsx +2 -2
  87. package/src/components/ui/popover.tsx +2 -0
  88. package/src/components/ui/radio-group.tsx +2 -0
  89. package/src/components/ui/scroll-area.tsx +2 -0
  90. package/src/components/ui/select.tsx +1 -1
  91. package/src/components/ui/separator.tsx +2 -0
  92. package/src/components/ui/sheet.tsx +4 -1
  93. package/src/components/ui/sidebar.tsx +1 -1
  94. package/src/components/ui/spinner.tsx +1 -0
  95. package/src/components/ui/switch.tsx +2 -0
  96. package/src/components/ui/tabs.tsx +2 -0
  97. package/src/components/ui/toggle-group.tsx +2 -0
  98. package/src/components/ui/tooltip.tsx +2 -0
  99. package/src/lib/__tests__/rehype-safe-img.spec.ts +121 -0
  100. package/src/lib/i18n-fr.ts +68 -0
  101. package/src/lib/rehype-safe-img.ts +150 -0
  102. package/src/lib/resize-image.ts +135 -0
  103. package/src/styles.css +126 -1
  104. /package/src/components/{admin/admin-user-detail-provider-labels.ts → auth/provider-labels.ts} +0 -0
@@ -18,14 +18,6 @@ import {
18
18
  useComboboxAnchor,
19
19
  } from "@alepha/ui/components/ui/combobox";
20
20
  import { Segmented } from "@alepha/ui/components/ui/segmented";
21
- import {
22
- Select,
23
- SelectContent,
24
- SelectItem,
25
- SelectSeparator,
26
- SelectTrigger,
27
- SelectValue,
28
- } from "@alepha/ui/components/ui/select";
29
21
  import { cn } from "@alepha/ui/lib/utils";
30
22
  import type { Async } from "alepha";
31
23
  import { useAction } from "alepha/react";
@@ -85,9 +77,18 @@ export interface ControlSelectProps {
85
77
  */
86
78
  segmented?: boolean;
87
79
  /**
88
- * Render as a searchable combobox instead of a native select.
80
+ * Force the search input on. Kept as the historical name for
81
+ * `searchable: true` — every select is a combobox now, the flag only
82
+ * decides whether it carries a search field.
89
83
  */
90
84
  combobox?: boolean;
85
+ /**
86
+ * Whether the dropdown carries a search input. Defaults to "auto": on for
87
+ * multi-select, for a long-mode `loader`, and for static lists longer than
88
+ * `SEARCH_THRESHOLD`. Set explicitly to search a short list or to drop the
89
+ * search field from a long one.
90
+ */
91
+ searchable?: boolean;
91
92
  /**
92
93
  * Async option loader. Triggers long-mode (server-side search) above `loaderThreshold` options.
93
94
  */
@@ -166,6 +167,13 @@ export interface ControlSelectProps {
166
167
  */
167
168
  const CLEAR_VALUE = "__alepha_clear__";
168
169
 
170
+ /**
171
+ * Static option count above which the dropdown grows a search input. Below it
172
+ * the very same combobox renders without one — the threshold decides whether
173
+ * you can type, never which control you get.
174
+ */
175
+ const SEARCH_THRESHOLD = 20;
176
+
169
177
  const optValue = (o: SelectOption) => (typeof o === "string" ? o : o.value);
170
178
  const optLabel = (o: SelectOption) => (typeof o === "string" ? o : o.label);
171
179
  const optDesc = (o: SelectOption) =>
@@ -286,48 +294,20 @@ export function ControlSelect(props: ControlSelectProps) {
286
294
  );
287
295
  }
288
296
 
289
- // Async loader, multi-select, explicit combobox, or many items → Combobox
290
- if (isArray || props.combobox || mode === "long" || data.length > 20) {
291
- return (
292
- <FormField
293
- id={meta.id}
294
- label={meta.label}
295
- description={meta.description}
296
- error={meta.error}
297
- required={meta.required}
298
- >
299
- <Combobox
300
- id={meta.id}
301
- data={data}
302
- loading={loading}
303
- multi={isArray}
304
- disabled={props.disabled}
305
- value={value}
306
- onChange={(v) => setValue(v)}
307
- coerce={coerce}
308
- onSearch={mode === "long" ? search.run : undefined}
309
- createNewEntry={props.createNewEntry}
310
- icon={props.icon}
311
- placeholder={
312
- props.clearable
313
- ? (props.clearLabel ??
314
- tr("controlSelect.none", { default: "None" }))
315
- : undefined
316
- }
317
- />
318
- </FormField>
319
- );
320
- }
321
-
322
- // Infer / short — native Select
323
297
  const clearLabel =
324
298
  props.clearLabel ?? tr("controlSelect.none", { default: "None" });
325
- const labelFor = (raw: string) => {
326
- const found = data.find((o) => optValue(o) === raw);
327
- return found ? optLabel(found) : raw;
328
- };
329
- const selectedValue =
330
- value != null ? String(value) : props.clearable ? CLEAR_VALUE : undefined;
299
+
300
+ // One control for every list. The option count decides whether the popup
301
+ // carries a search field — it no longer decides which primitive renders.
302
+ // The native `Select` path this replaced silently dropped `description`,
303
+ // `tag`, per-option `disabled` and `deselectable`, and styled its trigger
304
+ // differently, purely because a list happened to be short.
305
+ // Multi-select is never search-less: the chips input IS its trigger.
306
+ const searchable =
307
+ isArray ||
308
+ (props.searchable ??
309
+ (props.combobox || mode === "long" || data.length > SEARCH_THRESHOLD));
310
+
331
311
  return (
332
312
  <FormField
333
313
  id={meta.id}
@@ -336,62 +316,35 @@ export function ControlSelect(props: ControlSelectProps) {
336
316
  error={meta.error}
337
317
  required={meta.required}
338
318
  >
339
- <Select
340
- value={selectedValue}
341
- onValueChange={(v) => {
342
- if (v === CLEAR_VALUE) {
343
- setValue(undefined);
344
- return;
345
- }
346
- setValue(coerce(v ?? ""));
347
- }}
319
+ <Combobox
320
+ id={meta.id}
321
+ data={data}
322
+ loading={loading}
323
+ multi={isArray}
324
+ searchable={searchable}
348
325
  disabled={props.disabled}
349
- >
350
- <SelectTrigger
351
- id={meta.id}
352
- className={cn("w-full", props.triggerClassName)}
353
- >
354
- {props.icon && (
355
- <props.icon className="text-muted-foreground size-4 shrink-0" />
356
- )}
357
- <SelectValue
358
- placeholder={
359
- props.clearable
360
- ? clearLabel
361
- : tr("controlSelect.select", { default: "Select…" })
362
- }
363
- >
364
- {selectedValue === CLEAR_VALUE
365
- ? clearLabel
366
- : selectedValue != null
367
- ? labelFor(selectedValue)
368
- : undefined}
369
- </SelectValue>
370
- </SelectTrigger>
371
- <SelectContent>
372
- {props.clearable && (
373
- <>
374
- <SelectItem value={CLEAR_VALUE}>{clearLabel}</SelectItem>
375
- <SelectSeparator />
376
- </>
377
- )}
378
- {data.map((o) => {
379
- const icon = optIcon(o);
380
- return (
381
- <SelectItem key={optValue(o)} value={optValue(o)}>
382
- {icon ? (
383
- <span className="flex items-center gap-2">
384
- <span className="flex shrink-0 items-center">{icon}</span>
385
- <span>{optLabel(o)}</span>
386
- </span>
387
- ) : (
388
- optLabel(o)
389
- )}
390
- </SelectItem>
391
- );
392
- })}
393
- </SelectContent>
394
- </Select>
326
+ value={value}
327
+ onChange={(v) => setValue(v)}
328
+ coerce={coerce}
329
+ onSearch={mode === "long" ? search.run : undefined}
330
+ createNewEntry={props.createNewEntry}
331
+ icon={props.icon}
332
+ // Used to be dropped on this path, so a filter chip sized `w-40` lost
333
+ // its width as soon as its list crossed the threshold.
334
+ triggerClassName={props.triggerClassName}
335
+ // `clearable` used to reach this path as a placeholder and nothing
336
+ // else, so a filter chip that had switched to the combobox (>20
337
+ // options) could be set but never put back to "All …".
338
+ clearable={props.clearable}
339
+ clearLabel={clearLabel}
340
+ // An optional field must also be able to go back to empty without a
341
+ // dedicated row: Base UI never emits `null`, so re-pressing the
342
+ // selected row deselects (see `handleSingle`). A required field keeps
343
+ // its value — clearing it would only produce a validation error the
344
+ // user cannot see yet.
345
+ deselectable={props.clearable || !meta.required}
346
+ placeholder={props.clearable ? clearLabel : undefined}
347
+ />
395
348
  </FormField>
396
349
  );
397
350
  }
@@ -401,6 +354,12 @@ interface ComboboxProps {
401
354
  data: SelectOption[];
402
355
  loading: boolean;
403
356
  multi: boolean;
357
+ /**
358
+ * Render the search input. When false the popup is the list alone — the
359
+ * shape a short static list gets. Multi-select ignores it: its input is the
360
+ * chips box itself, and it is the only way to open and type.
361
+ */
362
+ searchable: boolean;
404
363
  disabled?: boolean;
405
364
  value: unknown;
406
365
  onChange: (v: unknown) => void;
@@ -408,12 +367,27 @@ interface ComboboxProps {
408
367
  onSearch?: (q: string) => void;
409
368
  createNewEntry?: ControlSelectProps["createNewEntry"];
410
369
  icon?: IconComponent;
370
+ triggerClassName?: string;
411
371
  /**
412
372
  * Trigger text when nothing is selected. Mirrors the native-Select path,
413
373
  * where a `clearable` field shows its `clearLabel` (e.g. "All zones") as the
414
374
  * empty placeholder. Defaults to "Select…".
415
375
  */
416
376
  placeholder?: string;
377
+ /**
378
+ * Prepend a row that resets the field to `undefined` — the combobox
379
+ * equivalent of the native `Select`'s clear row.
380
+ */
381
+ clearable?: boolean;
382
+ /**
383
+ * Label of the `clearable` row (e.g. "All zones").
384
+ */
385
+ clearLabel?: string;
386
+ /**
387
+ * Allow the single-select value to be unset by pressing the row that is
388
+ * already selected. Set for optional (and `clearable`) fields only.
389
+ */
390
+ deselectable?: boolean;
417
391
  }
418
392
 
419
393
  /**
@@ -433,6 +407,10 @@ interface ComboOption {
433
407
  * Marks the synthetic "create new" row injected by `createNewEntry`.
434
408
  */
435
409
  create?: boolean;
410
+ /**
411
+ * Marks the synthetic "clear" row injected by `clearable`.
412
+ */
413
+ clear?: boolean;
436
414
  /**
437
415
  * The raw query that produced a `create` row (used as the new entry's label).
438
416
  */
@@ -514,9 +492,26 @@ function Combobox(props: ComboboxProps) {
514
492
  })()
515
493
  : undefined;
516
494
 
517
- const items: ComboOption[] = createOption
518
- ? [...filtered, createOption]
519
- : filtered;
495
+ // The synthetic "no selection" row — "All zones", "All tags", "None". Only
496
+ // meaningful for a single select: the multi path clears by removing chips.
497
+ const clearRow: ComboOption | undefined =
498
+ props.clearable && !props.multi
499
+ ? {
500
+ value: CLEAR_VALUE,
501
+ label:
502
+ props.clearLabel ?? tr("controlSelect.none", { default: "None" }),
503
+ clear: true,
504
+ }
505
+ : undefined;
506
+ // Filtered on its own label like any other row, so searching "zone" doesn't
507
+ // leave "All zones" stranded at the top of a list it doesn't match.
508
+ const showClear = clearRow && clearRow.label.toLowerCase().includes(q);
509
+
510
+ const items: ComboOption[] = [
511
+ ...(showClear && clearRow ? [clearRow] : []),
512
+ ...filtered,
513
+ ...(createOption ? [createOption] : []),
514
+ ];
520
515
 
521
516
  // Reconstruct option objects for the controlled value. Base UI matches them
522
517
  // back to list items via `isItemEqualToValue` (by `value`), so identity
@@ -531,7 +526,9 @@ function Combobox(props: ComboboxProps) {
531
526
  ? selected.map(toValueObject)
532
527
  : selected[0]
533
528
  ? toValueObject(selected[0])
534
- : null;
529
+ : // Empty + clearable reads as "the clear row is what's selected", so it
530
+ // carries the check mark — same as the native `Select` path.
531
+ (clearRow ?? null);
535
532
 
536
533
  const remember = (o: ComboOption) => {
537
534
  if (o.create) labelCache.current.set(o.value, o.query ?? o.value);
@@ -539,8 +536,19 @@ function Combobox(props: ComboboxProps) {
539
536
  };
540
537
 
541
538
  const handleSingle = (o: ComboOption | null) => {
542
- if (!o) {
539
+ if (!o || o.clear) {
540
+ props.onChange(undefined);
541
+ setQuery("");
542
+ return;
543
+ }
544
+ // Base UI's single-select `Combobox` re-selects on every item press — its
545
+ // `handleSelection` calls `setSelectedValue(itemValue)` unconditionally and
546
+ // never emits `null` — so pressing the checked row was a no-op and an
547
+ // optional field had no way back to empty. Toggle it off here, the way the
548
+ // multi path already does via its chips.
549
+ if (props.deselectable && !o.create && selected[0] === o.value) {
543
550
  props.onChange(undefined);
551
+ setQuery("");
544
552
  return;
545
553
  }
546
554
  remember(o);
@@ -648,6 +656,7 @@ function Combobox(props: ComboboxProps) {
648
656
  className={cn(
649
657
  "w-full",
650
658
  props.disabled && "pointer-events-none opacity-50",
659
+ props.triggerClassName,
651
660
  )}
652
661
  >
653
662
  {props.icon && (
@@ -677,7 +686,18 @@ function Combobox(props: ComboboxProps) {
677
686
  disabled={props.disabled}
678
687
  className={cn(
679
688
  "flex h-8 w-full items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/30 dark:hover:bg-input/50",
680
- selected.length === 0 && "text-muted-foreground",
689
+ // Muted means "nothing chosen yet", which is only true without
690
+ // a clear row. WITH one, empty is a selected value — the popup
691
+ // already puts the check mark on it (see `cbValue`), and the
692
+ // native `Select` path renders the same state in full contrast
693
+ // because it makes the clear label a genuine `selectedValue`.
694
+ // Muting here made one `clearable` filter look unset and its
695
+ // neighbour look set for the same meaning, purely because the
696
+ // option count crossed the 20 that picks between the two paths.
697
+ selected.length === 0 &&
698
+ !props.clearable &&
699
+ "text-muted-foreground",
700
+ props.triggerClassName,
681
701
  )}
682
702
  >
683
703
  <span className="flex min-w-0 items-center gap-2">
@@ -688,7 +708,9 @@ function Combobox(props: ComboboxProps) {
688
708
  </span>
689
709
  </ComboboxTrigger>
690
710
  <ComboboxContent>
691
- <ComboboxInput showTrigger={false} placeholder="Search…" />
711
+ {props.searchable && (
712
+ <ComboboxInput showTrigger={false} placeholder="Search…" />
713
+ )}
692
714
  {popupBody}
693
715
  </ComboboxContent>
694
716
  </>
@@ -35,6 +35,10 @@ import {
35
35
  useRef,
36
36
  useState,
37
37
  } from "react";
38
+ import {
39
+ type ResizeImageOptions,
40
+ resizeImage,
41
+ } from "../../lib/resize-image.ts";
38
42
 
39
43
  export interface ControlUploadProps {
40
44
  /**
@@ -63,6 +67,24 @@ export interface ControlUploadProps {
63
67
  * Max size per file (bytes). Files over the limit are rejected.
64
68
  */
65
69
  maxSize?: number;
70
+ /**
71
+ * Downscale images to these bounds before uploading.
72
+ *
73
+ * Set it wherever the result is rendered small — the bytes never leave the
74
+ * machine, so it speeds up the upload as well as every later fetch. Applied
75
+ * before {@link maxSize}, so a photo that would have been rejected for being
76
+ * too large is resized and accepted instead.
77
+ *
78
+ * Best-effort by design: a browser without `OffscreenCanvas`, an SVG, or an
79
+ * image the decoder chokes on is uploaded as-is, and the storage's own
80
+ * `maxSize` remains what actually bounds it. That trade is deliberate — a
81
+ * server-side codec able to close the gap costs more bundle than the case is
82
+ * worth on an edge runtime, and encodes worse (see `files:beforeUpload` in
83
+ * `alepha/api/files` for where it would attach if you want it anyway).
84
+ *
85
+ * @example { maxWidth: 256 }
86
+ */
87
+ image?: ResizeImageOptions;
66
88
  /**
67
89
  * Bucket name passed to the upload endpoint.
68
90
  */
@@ -170,7 +192,11 @@ export function ControlUpload(props: ControlUploadProps) {
170
192
 
171
193
  try {
172
194
  for (let i = 0; i < files.length; i++) {
173
- const file = files[i];
195
+ // Ahead of the size check on purpose: a 4 MB photo destined for a 32px
196
+ // avatar should become a few kilobytes, not an error.
197
+ const file = props.image
198
+ ? await resizeImage(files[i], props.image)
199
+ : files[i];
174
200
 
175
201
  if (props.maxSize && file.size > props.maxSize) {
176
202
  toast.error(
@@ -6,6 +6,7 @@ import "./markdown-view.css";
6
6
  import ReactMarkdown from "react-markdown";
7
7
  import rehypeHighlight from "rehype-highlight";
8
8
  import remarkGfm from "remark-gfm";
9
+ import { rehypeSafeImg } from "../../lib/rehype-safe-img.ts";
9
10
 
10
11
  export interface MarkdownViewProps {
11
12
  content: string;
@@ -18,6 +19,11 @@ export const MarkdownView = (props: MarkdownViewProps) => {
18
19
  remarkPlugins={[remarkGfm]}
19
20
  rehypePlugins={[
20
21
  [rehypeHighlight, { detect: true, ignoreMissing: true }],
22
+ // Promotes ONLY `<img …>` raw HTML to a real element — what
23
+ // MDXEditor emits for a resized image. Every other raw node keeps
24
+ // react-markdown's default, which is to escape it to text. See
25
+ // `rehype-safe-img.ts` for why this is not `rehype-raw`.
26
+ rehypeSafeImg,
21
27
  ]}
22
28
  components={{
23
29
  h1: ({ children }) => (
@@ -8,7 +8,7 @@ import {
8
8
  } from "alepha/react/router";
9
9
  import { $secure } from "alepha/security";
10
10
 
11
- export interface NavPageOptions<
11
+ export interface PageNavOptions<
12
12
  TConfig extends PageConfigSchema = PageConfigSchema,
13
13
  TProps extends object = TPropsDefault,
14
14
  TPropsParent extends object = TPropsParentDefault,
@@ -34,12 +34,12 @@ export interface NavPageOptions<
34
34
  * Pages declared this way are picked up by {@link useNavTree} /
35
35
  * {@link NavShell} purely from their `nav` field — no separate nav list.
36
36
  */
37
- export const navPage = <
37
+ export const $pageNav = <
38
38
  TConfig extends PageConfigSchema = PageConfigSchema,
39
39
  TProps extends object = TPropsDefault,
40
40
  TPropsParent extends object = TPropsParentDefault,
41
41
  >(
42
- options: NavPageOptions<TConfig, TProps, TPropsParent>,
42
+ options: PageNavOptions<TConfig, TProps, TPropsParent>,
43
43
  ): PagePrimitive<TConfig, TProps, TPropsParent> => {
44
44
  const { permission, use, nav, ...rest } = options;
45
45
  const permissions = permission
@@ -0,0 +1,123 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { Alepha } from "alepha";
3
+ import { AlephaContext } from "alepha/react";
4
+ import { AlephaReactRouter } from "alepha/react/router";
5
+ import { setupJsdomMocks } from "alepha/react/testing";
6
+ import { afterEach, beforeAll, describe, expect, it } from "vitest";
7
+ import { SettingsNav, type SettingsNavItem } from "../settings-nav.tsx";
8
+
9
+ /**
10
+ * The rail's contract is narrow but easy to break silently: it must group by
11
+ * first appearance rather than alphabetically (the caller has already sorted),
12
+ * it must render hrefs verbatim (the reason it takes resolved items at all),
13
+ * and a disabled entry must stop being a link rather than merely look muted.
14
+ */
15
+ describe("SettingsNav", () => {
16
+ let alepha: Alepha | undefined;
17
+
18
+ beforeAll(() => {
19
+ setupJsdomMocks();
20
+ });
21
+
22
+ afterEach(async () => {
23
+ await alepha?.stop();
24
+ alepha = undefined;
25
+ });
26
+
27
+ const mount = async (items: SettingsNavItem[]) => {
28
+ alepha = Alepha.create().with(AlephaReactRouter);
29
+ await alepha.start();
30
+ return render(
31
+ <AlephaContext.Provider value={alepha}>
32
+ <SettingsNav items={items} />
33
+ </AlephaContext.Provider>,
34
+ );
35
+ };
36
+
37
+ const item = (over: Partial<SettingsNavItem> = {}): SettingsNavItem => ({
38
+ name: "profile",
39
+ href: "/account",
40
+ label: "Profile",
41
+ active: false,
42
+ ...over,
43
+ });
44
+
45
+ it("renders each entry as a link to its resolved href", async () => {
46
+ await mount([
47
+ item(),
48
+ item({ name: "sessions", href: "/account/sessions", label: "Sessions" }),
49
+ ]);
50
+
51
+ expect(
52
+ screen.getByRole("link", { name: "Profile" }).getAttribute("href"),
53
+ ).toBe("/account");
54
+ expect(
55
+ screen.getByRole("link", { name: "Sessions" }).getAttribute("href"),
56
+ ).toBe("/account/sessions");
57
+ });
58
+
59
+ it("passes hrefs through untouched instead of resolving them", async () => {
60
+ // The whole reason the component takes resolved items: it must not try to
61
+ // be clever about a pattern it was handed. Garbage in, same garbage out —
62
+ // visible to the caller rather than silently half-substituted.
63
+ await mount([item({ href: "/:projectSlug/settings" })]);
64
+
65
+ expect(
66
+ screen.getByRole("link", { name: "Profile" }).getAttribute("href"),
67
+ ).toBe("/:projectSlug/settings");
68
+ });
69
+
70
+ it("groups by first appearance, not alphabetically", async () => {
71
+ await mount([
72
+ item({ name: "profile", group: "Account" }),
73
+ item({
74
+ name: "sessions",
75
+ href: "/a/s",
76
+ label: "Sessions",
77
+ group: "Security",
78
+ }),
79
+ item({ name: "keys", href: "/a/k", label: "Keys", group: "Security" }),
80
+ ]);
81
+
82
+ const headings = screen
83
+ .getAllByText(/^(Account|Security)$/)
84
+ .map((el) => el.textContent);
85
+ expect(headings).toEqual(["Account", "Security"]);
86
+ });
87
+
88
+ it("renders ungrouped entries without a heading", async () => {
89
+ const { container } = await mount([
90
+ item(),
91
+ item({ name: "b", label: "B" }),
92
+ ]);
93
+
94
+ expect(container.querySelectorAll("nav > div")).toHaveLength(1);
95
+ expect(screen.getAllByRole("link")).toHaveLength(2);
96
+ });
97
+
98
+ it("marks the active entry with aria-current", async () => {
99
+ await mount([
100
+ item({ active: true }),
101
+ item({ name: "sessions", href: "/account/sessions", label: "Sessions" }),
102
+ ]);
103
+
104
+ expect(
105
+ screen
106
+ .getByRole("link", { name: "Profile" })
107
+ .getAttribute("aria-current"),
108
+ ).toBe("page");
109
+ expect(
110
+ screen
111
+ .getByRole("link", { name: "Sessions" })
112
+ .getAttribute("aria-current"),
113
+ ).toBeNull();
114
+ });
115
+
116
+ it("renders a disabled entry as inert text, not a link", async () => {
117
+ await mount([item({ disabled: true })]);
118
+
119
+ expect(screen.queryByRole("link")).toBeNull();
120
+ const entry = screen.getByText("Profile");
121
+ expect(entry.getAttribute("aria-disabled")).toBe("true");
122
+ });
123
+ });