@alepha/ui 0.25.1 → 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 (74) hide show
  1. package/package.json +3 -3
  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-searchable.browser.spec.tsx +142 -0
  57. package/src/components/control-select/control-select.tsx +78 -111
  58. package/src/components/control-upload/control-upload.tsx +27 -1
  59. package/src/components/markdown-view/markdown-view.tsx +6 -0
  60. package/src/components/nav-shell/nav-page.tsx +3 -3
  61. package/src/components/settings/__tests__/settings-nav.browser.spec.tsx +123 -0
  62. package/src/components/settings/__tests__/settings-section.browser.spec.tsx +130 -0
  63. package/src/components/settings/settings-danger-section.tsx +59 -0
  64. package/src/components/settings/settings-layout.tsx +56 -0
  65. package/src/components/settings/settings-nav.tsx +131 -0
  66. package/src/components/settings/settings-row.tsx +81 -0
  67. package/src/components/settings/settings-section.tsx +64 -0
  68. package/src/components/ui/dropdown-menu.tsx +9 -1
  69. package/src/lib/__tests__/rehype-safe-img.spec.ts +121 -0
  70. package/src/lib/i18n-fr.ts +68 -0
  71. package/src/lib/rehype-safe-img.ts +150 -0
  72. package/src/lib/resize-image.ts +135 -0
  73. package/src/styles.css +126 -1
  74. /package/src/components/{admin/admin-user-detail-provider-labels.ts → auth/provider-labels.ts} +0 -0
@@ -0,0 +1,87 @@
1
+ import {
2
+ FormField,
3
+ formFieldAriaProps,
4
+ } from "@alepha/ui/components/control-base/form-field";
5
+ import type { IconComponent } from "@alepha/ui/components/control-base/icon-hint";
6
+ import { Button } from "@alepha/ui/components/ui/button";
7
+ import { Input } from "@alepha/ui/components/ui/input";
8
+ import { Eye, EyeOff } from "lucide-react";
9
+ import { type HTMLAttributes, useState } from "react";
10
+
11
+ export interface ControlPasswordProps {
12
+ id?: string;
13
+ name?: string;
14
+ label?: string;
15
+ description?: string;
16
+ error?: string;
17
+ required?: boolean;
18
+ disabled?: boolean;
19
+ autoComplete?: string;
20
+ autoFocus?: boolean;
21
+ minLength?: number;
22
+ maxLength?: number;
23
+ inputProps?: HTMLAttributes<HTMLElement>;
24
+ icon?: IconComponent;
25
+ value: string;
26
+ onChange: (v: string) => void;
27
+ }
28
+
29
+ /**
30
+ * Masked password field with a reveal toggle.
31
+ *
32
+ * Lives outside `Control` so a hand-built form — a dialog that is not driven by
33
+ * a schema — gets the same field the schema path renders, rather than pairing a
34
+ * bare `<Input type="password">` with no way to check what was typed.
35
+ */
36
+ export const ControlPassword = (props: ControlPasswordProps) => {
37
+ const [reveal, setReveal] = useState(false);
38
+ const Icon = props.icon;
39
+ return (
40
+ <FormField
41
+ id={props.id}
42
+ label={props.label}
43
+ description={props.description}
44
+ error={props.error}
45
+ required={props.required}
46
+ >
47
+ <div className="relative">
48
+ {Icon && (
49
+ <Icon className="text-muted-foreground absolute top-1/2 left-3 size-4 -translate-y-1/2 pointer-events-none" />
50
+ )}
51
+ <Input
52
+ {...props.inputProps}
53
+ {...formFieldAriaProps({
54
+ id: props.id,
55
+ error: props.error,
56
+ description: props.description,
57
+ })}
58
+ id={props.id}
59
+ name={props.name}
60
+ type={reveal ? "text" : "password"}
61
+ autoComplete={props.autoComplete ?? "current-password"}
62
+ autoFocus={props.autoFocus}
63
+ disabled={props.disabled}
64
+ required={props.required}
65
+ minLength={props.minLength}
66
+ maxLength={props.maxLength}
67
+ value={props.value}
68
+ onChange={(e) => props.onChange(e.target.value)}
69
+ className={[props.inputProps?.className, Icon ? "pr-9 pl-9" : "pr-9"]
70
+ .filter(Boolean)
71
+ .join(" ")}
72
+ />
73
+ <Button
74
+ type="button"
75
+ variant="ghost"
76
+ size="icon"
77
+ disabled={props.disabled}
78
+ onClick={() => setReveal((r) => !r)}
79
+ aria-label={reveal ? "Hide password" : "Show password"}
80
+ className="text-muted-foreground hover:text-foreground absolute top-1/2 right-1 size-7 -translate-y-1/2"
81
+ >
82
+ {reveal ? <EyeOff className="size-4" /> : <Eye className="size-4" />}
83
+ </Button>
84
+ </div>
85
+ </FormField>
86
+ );
87
+ };
@@ -0,0 +1,101 @@
1
+ import { render } from "@testing-library/react";
2
+ import { Alepha, z } from "alepha";
3
+ import { AlephaLogger } from "alepha/logger";
4
+ import { AlephaContext } from "alepha/react";
5
+ import { useForm } from "alepha/react/form";
6
+ import { AlephaReactI18n } from "alepha/react/i18n";
7
+ import type { ReactNode } from "react";
8
+ import { describe, expect, it } from "vitest";
9
+ import { ControlSelect } from "../control-select.tsx";
10
+
11
+ /**
12
+ * `ControlSelect` picks between a native `Select` and a `Combobox` on option
13
+ * count (>20 → combobox). The two paths disagreed about what the `clearable`
14
+ * row's label *is*: the Select path made it a genuine selected value, the
15
+ * combobox passed it through as a placeholder and muted the trigger. So the
16
+ * same filter, meaning the same thing, changed colour the day its option list
17
+ * grew past 20 — which is exactly what happened to the quests board, where
18
+ * "All status" and "All areas" read as set and "All tags" read as unset.
19
+ *
20
+ * These assert on the render path rather than the colour of one of them: what
21
+ * matters is that the two agree, so a future change to either has to move both.
22
+ */
23
+ describe("ControlSelect clear label", () => {
24
+ const mount = (alepha: Alepha, ui: ReactNode) =>
25
+ render(
26
+ <AlephaContext.Provider value={alepha}>{ui}</AlephaContext.Provider>,
27
+ );
28
+
29
+ const start = async () => {
30
+ const alepha = Alepha.create().with(AlephaLogger).with(AlephaReactI18n);
31
+ await alepha.start();
32
+ return alepha;
33
+ };
34
+
35
+ const items = (count: number) =>
36
+ Array.from({ length: count }, (_, i) => `tag-${i}`);
37
+
38
+ const Probe = (props: { count: number; clearable?: boolean }) => {
39
+ const form = useForm({
40
+ schema: z.object({ tag: z.text().optional() as never }),
41
+ handler: () => {},
42
+ });
43
+ return (
44
+ <ControlSelect
45
+ input={form.input.tag}
46
+ label="Tag"
47
+ clearable={props.clearable}
48
+ clearLabel="All tags"
49
+ items={items(props.count)}
50
+ />
51
+ );
52
+ };
53
+
54
+ /**
55
+ * Both paths render their trigger as the field's only `combobox` role — the
56
+ * shadcn `SelectTrigger` and the Base UI `ComboboxTrigger` alike — so one
57
+ * query reaches whichever one the option count selected.
58
+ */
59
+ const trigger = (ui: ReturnType<typeof render>) =>
60
+ ui.getByRole("combobox") as HTMLElement;
61
+
62
+ /**
63
+ * "Reads as greyed", asked in the one way that covers both paths. The two
64
+ * arrive there by different mechanisms and no stylesheet runs under jsdom to
65
+ * flatten them: the combobox trigger takes `text-muted-foreground` outright,
66
+ * while `SelectTrigger` always carries the conditional
67
+ * `data-placeholder:text-muted-foreground` and only greys once Base UI
68
+ * stamps `data-placeholder` on it — which it does exactly when `SelectValue`
69
+ * falls back to its placeholder instead of rendering a chosen value.
70
+ */
71
+ const readsAsPlaceholder = (el: HTMLElement) =>
72
+ el.hasAttribute("data-placeholder") ||
73
+ el.className.split(/\s+/).includes("text-muted-foreground");
74
+
75
+ it("renders the clear label as a value on the Select path", async () => {
76
+ const alepha = await start();
77
+ const ui = mount(alepha, <Probe count={5} clearable />);
78
+
79
+ expect(trigger(ui).textContent).toContain("All tags");
80
+ expect(readsAsPlaceholder(trigger(ui))).toBe(false);
81
+ });
82
+
83
+ it("renders the clear label the same way past the 20-option threshold", async () => {
84
+ const alepha = await start();
85
+ const ui = mount(alepha, <Probe count={25} clearable />);
86
+
87
+ expect(trigger(ui).textContent).toContain("All tags");
88
+ expect(readsAsPlaceholder(trigger(ui))).toBe(false);
89
+ });
90
+
91
+ it("still reads as a placeholder when there is no clear row", async () => {
92
+ const alepha = await start();
93
+
94
+ const short = mount(alepha, <Probe count={5} />);
95
+ expect(readsAsPlaceholder(trigger(short))).toBe(true);
96
+ short.unmount();
97
+
98
+ const long = mount(alepha, <Probe count={25} />);
99
+ expect(readsAsPlaceholder(trigger(long))).toBe(true);
100
+ });
101
+ });
@@ -0,0 +1,142 @@
1
+ import { fireEvent, render, waitFor } from "@testing-library/react";
2
+ import { Alepha, z } from "alepha";
3
+ import { AlephaLogger } from "alepha/logger";
4
+ import { AlephaContext } from "alepha/react";
5
+ import { type BaseInputField, useFieldValue, useForm } from "alepha/react/form";
6
+ import { AlephaReactI18n } from "alepha/react/i18n";
7
+ import type { ReactNode } from "react";
8
+ import { describe, expect, it } from "vitest";
9
+ import { ControlSelect } from "../control-select.tsx";
10
+
11
+ /**
12
+ * ControlSelect used to pick a *primitive* by option count: a native `Select`
13
+ * below ~20 options, a `Combobox` above. That made per-option `description`,
14
+ * `tag` and `disabled` — plus `triggerClassName` and deselection — appear or
15
+ * vanish depending on how many siblings an option happened to have. Now a
16
+ * single Combobox renders every list and the count only decides whether the
17
+ * popup carries a search field.
18
+ */
19
+ describe("ControlSelect searchable", () => {
20
+ const mount = (alepha: Alepha, ui: ReactNode) =>
21
+ render(
22
+ <AlephaContext.Provider value={alepha}>{ui}</AlephaContext.Provider>,
23
+ );
24
+
25
+ const start = async () => {
26
+ const alepha = Alepha.create().with(AlephaLogger).with(AlephaReactI18n);
27
+ await alepha.start();
28
+ return alepha;
29
+ };
30
+
31
+ const SHORT = [
32
+ { value: "user", label: "User", description: "Everyone", disabled: true },
33
+ { value: "editor", label: "Editor", tag: "write" },
34
+ ];
35
+
36
+ const LONG = Array.from({ length: 30 }, (_, i) => `opt-${i}`);
37
+
38
+ const Probe = (props: {
39
+ searchable?: boolean;
40
+ items?: (typeof SHORT)[number][] | string[];
41
+ }) => {
42
+ const form = useForm({
43
+ schema: z.object({ role: z.text().optional() as never }),
44
+ handler: () => {},
45
+ });
46
+ return (
47
+ <>
48
+ <ControlSelect
49
+ input={form.input.role}
50
+ label="Role"
51
+ searchable={props.searchable}
52
+ items={(props.items ?? SHORT) as never}
53
+ />
54
+ <Reporter input={form.input.role} />
55
+ </>
56
+ );
57
+ };
58
+
59
+ /**
60
+ * Reads the bound value rather than the trigger label, which falls back to
61
+ * the placeholder and would pass for the wrong reason.
62
+ */
63
+ const Reporter = (props: { input: BaseInputField }) => {
64
+ const [value] = useFieldValue(props.input);
65
+ return (
66
+ <span data-testid="value">
67
+ {value === undefined ? "∅" : String(value)}
68
+ </span>
69
+ );
70
+ };
71
+
72
+ const openPopup = (ui: ReturnType<typeof render>) => {
73
+ fireEvent.keyDown(ui.getByRole("combobox"), { key: "ArrowDown" });
74
+ };
75
+
76
+ const searchInput = (ui: ReturnType<typeof render>) =>
77
+ ui.queryByPlaceholderText("Search…");
78
+
79
+ it("omits the search field on a short list", async () => {
80
+ const alepha = await start();
81
+ const ui = mount(alepha, <Probe />);
82
+
83
+ openPopup(ui);
84
+ await ui.findByRole("option", { name: /Editor/ });
85
+ expect(searchInput(ui)).toBeNull();
86
+ });
87
+
88
+ it("adds the search field above the threshold", async () => {
89
+ const alepha = await start();
90
+ const ui = mount(alepha, <Probe items={LONG} />);
91
+
92
+ openPopup(ui);
93
+ await ui.findByRole("option", { name: "opt-0" });
94
+ expect(searchInput(ui)).not.toBeNull();
95
+ });
96
+
97
+ it("honors an explicit `searchable` in both directions", async () => {
98
+ const alepha = await start();
99
+
100
+ const forcedOn = mount(alepha, <Probe searchable />);
101
+ openPopup(forcedOn);
102
+ await forcedOn.findByRole("option", { name: /Editor/ });
103
+ expect(forcedOn.queryByPlaceholderText("Search…")).not.toBeNull();
104
+ forcedOn.unmount();
105
+
106
+ const forcedOff = mount(alepha, <Probe searchable={false} items={LONG} />);
107
+ openPopup(forcedOff);
108
+ await forcedOff.findByRole("option", { name: "opt-0" });
109
+ expect(forcedOff.queryByPlaceholderText("Search…")).toBeNull();
110
+ });
111
+
112
+ it("still renders description and tag on a short list", async () => {
113
+ const alepha = await start();
114
+ const ui = mount(alepha, <Probe />);
115
+
116
+ openPopup(ui);
117
+ // Both were silently dropped by the native-`Select` path.
118
+ expect(await ui.findByText("Everyone")).toBeTruthy();
119
+ expect(await ui.findByText("write")).toBeTruthy();
120
+ });
121
+
122
+ it("selects without a search field, and refuses a disabled row", async () => {
123
+ const alepha = await start();
124
+ const ui = mount(alepha, <Probe />);
125
+
126
+ openPopup(ui);
127
+ fireEvent.click(await ui.findByRole("option", { name: /Editor/ }));
128
+ await waitFor(() => {
129
+ expect(ui.getByTestId("value").textContent).toBe("editor");
130
+ });
131
+
132
+ // Pressed second, so "still editor" proves the row is inert rather than
133
+ // matching the state the field started in. `disabled` reached the row only
134
+ // on the combobox path, so a mandatory option used to be selectable as
135
+ // soon as its list was short enough.
136
+ openPopup(ui);
137
+ fireEvent.click(await ui.findByRole("option", { name: /User/ }));
138
+ await waitFor(() => {
139
+ expect(ui.getByTestId("value").textContent).toBe("editor");
140
+ });
141
+ });
142
+ });
@@ -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) =>
@@ -289,52 +297,17 @@ export function ControlSelect(props: ControlSelectProps) {
289
297
  const clearLabel =
290
298
  props.clearLabel ?? tr("controlSelect.none", { default: "None" });
291
299
 
292
- // Async loader, multi-select, explicit combobox, or many items → Combobox
293
- if (isArray || props.combobox || mode === "long" || data.length > 20) {
294
- return (
295
- <FormField
296
- id={meta.id}
297
- label={meta.label}
298
- description={meta.description}
299
- error={meta.error}
300
- required={meta.required}
301
- >
302
- <Combobox
303
- id={meta.id}
304
- data={data}
305
- loading={loading}
306
- multi={isArray}
307
- disabled={props.disabled}
308
- value={value}
309
- onChange={(v) => setValue(v)}
310
- coerce={coerce}
311
- onSearch={mode === "long" ? search.run : undefined}
312
- createNewEntry={props.createNewEntry}
313
- icon={props.icon}
314
- // `clearable` used to reach this path as a placeholder and nothing
315
- // else, so a filter chip that had switched to the combobox (>20
316
- // options) could be set but never put back to "All …".
317
- clearable={props.clearable}
318
- clearLabel={clearLabel}
319
- // An optional field must also be able to go back to empty without a
320
- // dedicated row: Base UI never emits `null`, so re-pressing the
321
- // selected row deselects (see `handleSingle`). A required field keeps
322
- // its value — clearing it would only produce a validation error the
323
- // user cannot see yet.
324
- deselectable={props.clearable || !meta.required}
325
- placeholder={props.clearable ? clearLabel : undefined}
326
- />
327
- </FormField>
328
- );
329
- }
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));
330
310
 
331
- // Infer / short — native Select
332
- const labelFor = (raw: string) => {
333
- const found = data.find((o) => optValue(o) === raw);
334
- return found ? optLabel(found) : raw;
335
- };
336
- const selectedValue =
337
- value != null ? String(value) : props.clearable ? CLEAR_VALUE : undefined;
338
311
  return (
339
312
  <FormField
340
313
  id={meta.id}
@@ -343,62 +316,35 @@ export function ControlSelect(props: ControlSelectProps) {
343
316
  error={meta.error}
344
317
  required={meta.required}
345
318
  >
346
- <Select
347
- value={selectedValue}
348
- onValueChange={(v) => {
349
- if (v === CLEAR_VALUE) {
350
- setValue(undefined);
351
- return;
352
- }
353
- setValue(coerce(v ?? ""));
354
- }}
319
+ <Combobox
320
+ id={meta.id}
321
+ data={data}
322
+ loading={loading}
323
+ multi={isArray}
324
+ searchable={searchable}
355
325
  disabled={props.disabled}
356
- >
357
- <SelectTrigger
358
- id={meta.id}
359
- className={cn("w-full", props.triggerClassName)}
360
- >
361
- {props.icon && (
362
- <props.icon className="text-muted-foreground size-4 shrink-0" />
363
- )}
364
- <SelectValue
365
- placeholder={
366
- props.clearable
367
- ? clearLabel
368
- : tr("controlSelect.select", { default: "Select…" })
369
- }
370
- >
371
- {selectedValue === CLEAR_VALUE
372
- ? clearLabel
373
- : selectedValue != null
374
- ? labelFor(selectedValue)
375
- : undefined}
376
- </SelectValue>
377
- </SelectTrigger>
378
- <SelectContent>
379
- {props.clearable && (
380
- <>
381
- <SelectItem value={CLEAR_VALUE}>{clearLabel}</SelectItem>
382
- <SelectSeparator />
383
- </>
384
- )}
385
- {data.map((o) => {
386
- const icon = optIcon(o);
387
- return (
388
- <SelectItem key={optValue(o)} value={optValue(o)}>
389
- {icon ? (
390
- <span className="flex items-center gap-2">
391
- <span className="flex shrink-0 items-center">{icon}</span>
392
- <span>{optLabel(o)}</span>
393
- </span>
394
- ) : (
395
- optLabel(o)
396
- )}
397
- </SelectItem>
398
- );
399
- })}
400
- </SelectContent>
401
- </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
+ />
402
348
  </FormField>
403
349
  );
404
350
  }
@@ -408,6 +354,12 @@ interface ComboboxProps {
408
354
  data: SelectOption[];
409
355
  loading: boolean;
410
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;
411
363
  disabled?: boolean;
412
364
  value: unknown;
413
365
  onChange: (v: unknown) => void;
@@ -415,6 +367,7 @@ interface ComboboxProps {
415
367
  onSearch?: (q: string) => void;
416
368
  createNewEntry?: ControlSelectProps["createNewEntry"];
417
369
  icon?: IconComponent;
370
+ triggerClassName?: string;
418
371
  /**
419
372
  * Trigger text when nothing is selected. Mirrors the native-Select path,
420
373
  * where a `clearable` field shows its `clearLabel` (e.g. "All zones") as the
@@ -703,6 +656,7 @@ function Combobox(props: ComboboxProps) {
703
656
  className={cn(
704
657
  "w-full",
705
658
  props.disabled && "pointer-events-none opacity-50",
659
+ props.triggerClassName,
706
660
  )}
707
661
  >
708
662
  {props.icon && (
@@ -732,7 +686,18 @@ function Combobox(props: ComboboxProps) {
732
686
  disabled={props.disabled}
733
687
  className={cn(
734
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",
735
- 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,
736
701
  )}
737
702
  >
738
703
  <span className="flex min-w-0 items-center gap-2">
@@ -743,7 +708,9 @@ function Combobox(props: ComboboxProps) {
743
708
  </span>
744
709
  </ComboboxTrigger>
745
710
  <ComboboxContent>
746
- <ComboboxInput showTrigger={false} placeholder="Search…" />
711
+ {props.searchable && (
712
+ <ComboboxInput showTrigger={false} placeholder="Search…" />
713
+ )}
747
714
  {popupBody}
748
715
  </ComboboxContent>
749
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 }) => (