@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.
- package/README.md +12 -0
- package/components.json +20 -0
- package/package.json +85 -0
- package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
- package/src/components/admin/admin-audits.tsx +247 -0
- package/src/components/admin/admin-files.tsx +346 -0
- package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
- package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
- package/src/components/admin/admin-jobs.tsx +294 -0
- package/src/components/admin/admin-keys.tsx +162 -0
- package/src/components/admin/admin-notifications.tsx +130 -0
- package/src/components/admin/admin-page.tsx +24 -0
- package/src/components/admin/admin-parameters.tsx +864 -0
- package/src/components/admin/admin-payments.tsx +93 -0
- package/src/components/admin/admin-sessions.tsx +174 -0
- package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
- package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
- package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
- package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
- package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
- package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
- package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
- package/src/components/admin/admin-user-detail.tsx +606 -0
- package/src/components/admin/admin-users-roles-picker.tsx +126 -0
- package/src/components/admin/admin-users-status-filter.tsx +51 -0
- package/src/components/admin/admin-users.tsx +518 -0
- package/src/components/admin/diff-lines.spec.ts +58 -0
- package/src/components/admin/diff-lines.ts +58 -0
- package/src/components/admin/parameter-diff-dialog.tsx +119 -0
- package/src/components/admin/parameter-history-item.tsx +252 -0
- package/src/components/admin/parameter-json-dialog.tsx +93 -0
- package/src/components/admin/parameter-save-dialog.tsx +126 -0
- package/src/components/admin/use-confirmed-action.tsx +93 -0
- package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
- package/src/components/alepha-table/alepha-table.tsx +1158 -0
- package/src/components/alepha-table/use-table-selection.ts +95 -0
- package/src/components/app-shell/app-shell.tsx +568 -0
- package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
- package/src/components/auth/auth-login.tsx +382 -0
- package/src/components/auth/auth-register.tsx +786 -0
- package/src/components/auth/auth-reset-password.tsx +349 -0
- package/src/components/auth/auth-router.tsx +126 -0
- package/src/components/auth/auth-verify-email.tsx +179 -0
- package/src/components/auto-form/auto-form.tsx +867 -0
- package/src/components/brand-icon/brand-icon.tsx +104 -0
- package/src/components/button-dark/button-dark.tsx +78 -0
- package/src/components/button-language/button-language.tsx +98 -0
- package/src/components/button-theme/button-theme.tsx +148 -0
- package/src/components/button-user/button-user.tsx +214 -0
- package/src/components/captcha/turnstile-widget.tsx +157 -0
- package/src/components/control/control.tsx +735 -0
- package/src/components/control-array/control-array.tsx +700 -0
- package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
- package/src/components/control-base/field-i18n.ts +60 -0
- package/src/components/control-base/form-field.tsx +275 -0
- package/src/components/control-base/grid.tsx +59 -0
- package/src/components/control-base/icon-hint.tsx +64 -0
- package/src/components/control-date/control-date.tsx +190 -0
- package/src/components/control-number/control-number.tsx +136 -0
- package/src/components/control-object/control-object.tsx +200 -0
- package/src/components/control-select/control-select.tsx +774 -0
- package/src/components/control-upload/control-upload.tsx +475 -0
- package/src/components/file-image/file-image.tsx +52 -0
- package/src/components/language-toggle/language-toggle.tsx +66 -0
- package/src/components/markdown-view/markdown-view.css +114 -0
- package/src/components/markdown-view/markdown-view.tsx +92 -0
- package/src/components/nav-shell/nav-page.tsx +56 -0
- package/src/components/nav-shell/nav-shell.tsx +72 -0
- package/src/components/nav-shell/nav-tree-util.ts +62 -0
- package/src/components/nav-shell/spotlight.tsx +163 -0
- package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
- package/src/components/nav-shell/use-nav-entries.ts +101 -0
- package/src/components/nav-shell/use-nav-tree.ts +61 -0
- package/src/components/ui/accordion.tsx +77 -0
- package/src/components/ui/alert-dialog.tsx +186 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +121 -0
- package/src/components/ui/button-group.tsx +86 -0
- package/src/components/ui/button.tsx +83 -0
- package/src/components/ui/calendar.tsx +235 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +241 -0
- package/src/components/ui/chart.tsx +370 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +19 -0
- package/src/components/ui/combobox.tsx +298 -0
- package/src/components/ui/command.tsx +196 -0
- package/src/components/ui/context-menu.tsx +271 -0
- package/src/components/ui/dialog.tsx +153 -0
- package/src/components/ui/direction.tsx +4 -0
- package/src/components/ui/drawer.tsx +130 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +100 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +157 -0
- package/src/components/ui/input-otp.tsx +83 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +200 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/menubar.tsx +283 -0
- package/src/components/ui/navigation-menu.tsx +170 -0
- package/src/components/ui/pagination.tsx +133 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/radio-group.tsx +35 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +51 -0
- package/src/components/ui/segmented.tsx +232 -0
- package/src/components/ui/select.tsx +201 -0
- package/src/components/ui/separator.tsx +22 -0
- package/src/components/ui/sheet.tsx +133 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/sonner.tsx +46 -0
- package/src/components/ui/spinner.tsx +15 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toggle-group.tsx +86 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +63 -0
- package/src/components/use-dialog/use-dialog.tsx +244 -0
- package/src/components/use-toast/use-toast.tsx +89 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
- package/src/lib/i18n-fr.ts +500 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles.css +129 -0
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
ControlArray,
|
|
7
|
+
type ControlArrayProps,
|
|
8
|
+
} from "@alepha/ui/components/control-array/control-array";
|
|
9
|
+
import {
|
|
10
|
+
FormField,
|
|
11
|
+
formFieldAriaProps,
|
|
12
|
+
useFormFieldAutoSave,
|
|
13
|
+
} from "@alepha/ui/components/control-base/form-field";
|
|
14
|
+
import {
|
|
15
|
+
type IconComponent,
|
|
16
|
+
iconFor,
|
|
17
|
+
} from "@alepha/ui/components/control-base/icon-hint";
|
|
18
|
+
import { ControlDate } from "@alepha/ui/components/control-date/control-date";
|
|
19
|
+
import { ControlNumber } from "@alepha/ui/components/control-number/control-number";
|
|
20
|
+
import { ControlObject } from "@alepha/ui/components/control-object/control-object";
|
|
21
|
+
import {
|
|
22
|
+
ControlSelect,
|
|
23
|
+
type SelectOption,
|
|
24
|
+
} from "@alepha/ui/components/control-select/control-select";
|
|
25
|
+
import {
|
|
26
|
+
ControlUpload,
|
|
27
|
+
type ControlUploadProps,
|
|
28
|
+
} from "@alepha/ui/components/control-upload/control-upload";
|
|
29
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
30
|
+
import { Input } from "@alepha/ui/components/ui/input";
|
|
31
|
+
import { Switch } from "@alepha/ui/components/ui/switch";
|
|
32
|
+
import { Textarea } from "@alepha/ui/components/ui/textarea";
|
|
33
|
+
import { z } from "alepha";
|
|
34
|
+
import { useAlepha } from "alepha/react";
|
|
35
|
+
import {
|
|
36
|
+
type BaseInputField,
|
|
37
|
+
parseField,
|
|
38
|
+
useFieldValue,
|
|
39
|
+
useFormState,
|
|
40
|
+
} from "alepha/react/form";
|
|
41
|
+
import { resolveSchemaControl, type SchemaControl } from "alepha/react/ui";
|
|
42
|
+
import { Check, Eye, EyeOff, X } from "lucide-react";
|
|
43
|
+
import {
|
|
44
|
+
type ComponentType,
|
|
45
|
+
type HTMLAttributes,
|
|
46
|
+
type ReactNode,
|
|
47
|
+
useEffect,
|
|
48
|
+
useState,
|
|
49
|
+
} from "react";
|
|
50
|
+
|
|
51
|
+
export interface ControlProps {
|
|
52
|
+
/**
|
|
53
|
+
* Bound `InputField` from `useForm`. Carries value, schema, and error state.
|
|
54
|
+
*/
|
|
55
|
+
input: BaseInputField;
|
|
56
|
+
/**
|
|
57
|
+
* Field label. Falls back to schema `title` or the field name.
|
|
58
|
+
*/
|
|
59
|
+
label?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Helper text shown below the control. Falls back to schema `description`.
|
|
62
|
+
*/
|
|
63
|
+
description?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Force a specific input variant — renders a single-line text input.
|
|
66
|
+
*/
|
|
67
|
+
text?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Force a textarea.
|
|
70
|
+
*/
|
|
71
|
+
area?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Force a masked password input.
|
|
74
|
+
*/
|
|
75
|
+
password?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Force a `<Switch>` (boolean toggle).
|
|
78
|
+
*/
|
|
79
|
+
switch?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Force a numeric input.
|
|
82
|
+
*/
|
|
83
|
+
number?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Force the file-upload control (alias for `upload`).
|
|
86
|
+
*/
|
|
87
|
+
file?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Force a date picker.
|
|
90
|
+
*/
|
|
91
|
+
date?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Force a date-time picker.
|
|
94
|
+
*/
|
|
95
|
+
datetime?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Force a time picker.
|
|
98
|
+
*/
|
|
99
|
+
time?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Force a `<Select>`.
|
|
102
|
+
*/
|
|
103
|
+
select?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Force a combobox (searchable select).
|
|
106
|
+
*/
|
|
107
|
+
combobox?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Force a `<Segmented>` control (one option visible at a time).
|
|
110
|
+
*/
|
|
111
|
+
segmented?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Force a slider (numeric only).
|
|
114
|
+
*/
|
|
115
|
+
slider?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Force a nested `<ControlObject>` for object-typed schemas.
|
|
118
|
+
*/
|
|
119
|
+
object?: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Force a nested `<ControlArray>` for array-typed schemas.
|
|
122
|
+
*/
|
|
123
|
+
array?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Props forwarded to the nested `<ControlObject>`, keyed by child field name.
|
|
126
|
+
* This is the only way to reach INSIDE an object field — without it a caller
|
|
127
|
+
* can style/override the object as a whole but never one of its children
|
|
128
|
+
* (e.g. attaching a `custom` widget to `payg.zoneFareCents`).
|
|
129
|
+
*/
|
|
130
|
+
/**
|
|
131
|
+
* Dictionary prefix for schema-generated labels/help: this field reads
|
|
132
|
+
* `<prefix>.<name>` and `<prefix>.<name>.desc`, and passes the extended
|
|
133
|
+
* prefix down into nested objects and array items.
|
|
134
|
+
*/
|
|
135
|
+
i18nPrefix?: string;
|
|
136
|
+
objectProps?: {
|
|
137
|
+
controlProps?: Record<string, Partial<Omit<ControlProps, "input">>>;
|
|
138
|
+
variant?: "fieldset" | "plain";
|
|
139
|
+
defaultExpanded?: boolean;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Custom render component receiving `{value, onChange}`.
|
|
143
|
+
*/
|
|
144
|
+
custom?: ComponentType<{ value: unknown; onChange: (v: unknown) => void }>;
|
|
145
|
+
/**
|
|
146
|
+
* Override icon — pass `null` to remove the schema-inferred icon.
|
|
147
|
+
*/
|
|
148
|
+
icon?: IconComponent | string | null;
|
|
149
|
+
/**
|
|
150
|
+
* Disable the control.
|
|
151
|
+
*/
|
|
152
|
+
disabled?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Render slot before the control.
|
|
155
|
+
*/
|
|
156
|
+
top?: ReactNode;
|
|
157
|
+
/**
|
|
158
|
+
* Render slot after the control.
|
|
159
|
+
*/
|
|
160
|
+
bottom?: ReactNode;
|
|
161
|
+
/**
|
|
162
|
+
* Width slot inside an `<AutoForm>` group (mapped to a CSS grid column
|
|
163
|
+
* span). Read by the parent group; ignored when rendering standalone.
|
|
164
|
+
*/
|
|
165
|
+
width?: 100 | 75 | 66 | 50 | 33 | 25;
|
|
166
|
+
/**
|
|
167
|
+
* HTML `autocomplete` hint passed to the underlying input.
|
|
168
|
+
*/
|
|
169
|
+
autoComplete?: string;
|
|
170
|
+
/**
|
|
171
|
+
* HTML `placeholder` passed to the underlying input.
|
|
172
|
+
*/
|
|
173
|
+
placeholder?: string;
|
|
174
|
+
/**
|
|
175
|
+
* Autofocus the control on mount. Forwarded to the text input,
|
|
176
|
+
* textarea, or password input the control renders.
|
|
177
|
+
*/
|
|
178
|
+
autoFocus?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Visible row count for the textarea variant. Overrides the value
|
|
181
|
+
* auto-derived from the schema's `maxLength`. Ignored by other variants.
|
|
182
|
+
*/
|
|
183
|
+
rows?: number;
|
|
184
|
+
/**
|
|
185
|
+
* Escape hatch — extra native attributes (event handlers, `className`,
|
|
186
|
+
* `aria-*`, `style`, …) forwarded to whichever element the control
|
|
187
|
+
* actually renders (text input / textarea / password input). The form
|
|
188
|
+
* bindings (`value`, `onChange`, `id`, `name`) always win and cannot be
|
|
189
|
+
* overridden here.
|
|
190
|
+
*/
|
|
191
|
+
inputProps?: HTMLAttributes<HTMLElement>;
|
|
192
|
+
/**
|
|
193
|
+
* Allow user to create new entries in select / multi-select.
|
|
194
|
+
*/
|
|
195
|
+
createNewEntry?: boolean | ((query: string) => unknown);
|
|
196
|
+
/**
|
|
197
|
+
* Inline option list for select / combobox controls. Infer array or
|
|
198
|
+
* async loader. Overrides schema-derived `enum` when present.
|
|
199
|
+
*/
|
|
200
|
+
items?:
|
|
201
|
+
| SelectOption[]
|
|
202
|
+
| ((query: string) => SelectOption[] | Promise<SelectOption[]>);
|
|
203
|
+
/**
|
|
204
|
+
* Forwarded to `ControlSelect` — adds a synthetic "none" row that
|
|
205
|
+
* resets the field to `undefined`. Use for optional filter chips.
|
|
206
|
+
*/
|
|
207
|
+
clearable?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Forwarded to `ControlSelect` — label of the `clearable` row, also
|
|
210
|
+
* used as the empty-state trigger placeholder. Defaults to "None".
|
|
211
|
+
*/
|
|
212
|
+
clearLabel?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Forwarded to `ControlSelect` — extra className on the trigger.
|
|
215
|
+
* Useful for sizing filter chips inline.
|
|
216
|
+
*/
|
|
217
|
+
triggerClassName?: string;
|
|
218
|
+
/**
|
|
219
|
+
* Render a managed upload control (image preview, multi, drag-drop)
|
|
220
|
+
* that calls `FileController.uploadFile` and stores the file ID(s) in
|
|
221
|
+
* the form value. Pass `true` for defaults or an options object.
|
|
222
|
+
*/
|
|
223
|
+
upload?:
|
|
224
|
+
| boolean
|
|
225
|
+
| Pick<ControlUploadProps, "multi" | "accept" | "maxSize" | "bucket">;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Schema-driven form field renderer. Inspects the bound `InputField` from
|
|
230
|
+
* `useForm`, evaluates `schema.$control` (object or function), merges the
|
|
231
|
+
* result with explicit props, and dispatches to the right sub-control.
|
|
232
|
+
*/
|
|
233
|
+
export function Control(props: ControlProps) {
|
|
234
|
+
const form = useFormState(props.input, ["error", "dirty"]);
|
|
235
|
+
const autoSaveEnabled = useFormFieldAutoSave();
|
|
236
|
+
const [value, setValue] = useFieldValue(props.input);
|
|
237
|
+
|
|
238
|
+
// Function-form `$control` reads other fields → re-render on any
|
|
239
|
+
// change. Infer `$control` (object) does not need this subscription.
|
|
240
|
+
useDynamicControlRefresh(props.input);
|
|
241
|
+
|
|
242
|
+
if (!props.input?.props) return null;
|
|
243
|
+
|
|
244
|
+
const meta = parseField(props.input, {
|
|
245
|
+
label: props.label,
|
|
246
|
+
description: props.description,
|
|
247
|
+
error: form.error,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// ── Resolve $control (object | function | false) ─────────────────
|
|
251
|
+
const resolved = resolveSchemaControl(meta.control, {
|
|
252
|
+
form: props.input.form,
|
|
253
|
+
value,
|
|
254
|
+
});
|
|
255
|
+
if (resolved === null) return null;
|
|
256
|
+
|
|
257
|
+
const merged = {
|
|
258
|
+
...props,
|
|
259
|
+
...(resolved as Partial<ControlProps>),
|
|
260
|
+
} as ControlProps & Partial<SchemaControl>;
|
|
261
|
+
|
|
262
|
+
// ── Custom escape hatch ──────────────────────────────────────────
|
|
263
|
+
if (merged.custom) {
|
|
264
|
+
const Custom = merged.custom;
|
|
265
|
+
return wrapWithSlots(
|
|
266
|
+
merged,
|
|
267
|
+
<FormField
|
|
268
|
+
id={meta.id}
|
|
269
|
+
label={merged.label ?? meta.label}
|
|
270
|
+
description={merged.description ?? meta.description}
|
|
271
|
+
error={meta.error}
|
|
272
|
+
required={meta.required}
|
|
273
|
+
>
|
|
274
|
+
<Custom value={value} onChange={(v) => setValue(v)} />
|
|
275
|
+
</FormField>,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// ── Recursive: object / array of objects ─────────────────────────
|
|
280
|
+
if (merged.object || meta.isObject) {
|
|
281
|
+
return wrapWithSlots(
|
|
282
|
+
merged,
|
|
283
|
+
<ControlObject
|
|
284
|
+
input={props.input}
|
|
285
|
+
label={merged.label ?? props.label}
|
|
286
|
+
description={merged.description ?? props.description}
|
|
287
|
+
disabled={merged.disabled}
|
|
288
|
+
i18nPrefix={merged.i18nPrefix}
|
|
289
|
+
controlProps={merged.objectProps?.controlProps}
|
|
290
|
+
variant={merged.objectProps?.variant}
|
|
291
|
+
defaultExpanded={merged.objectProps?.defaultExpanded}
|
|
292
|
+
/>,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (merged.array || meta.isArrayOfObjects) {
|
|
296
|
+
const arrayProps = (merged as { arrayProps?: Record<string, unknown> })
|
|
297
|
+
.arrayProps;
|
|
298
|
+
return wrapWithSlots(
|
|
299
|
+
merged,
|
|
300
|
+
<ControlArray
|
|
301
|
+
input={props.input}
|
|
302
|
+
i18nPrefix={merged.i18nPrefix}
|
|
303
|
+
label={merged.label ?? props.label}
|
|
304
|
+
description={merged.description ?? props.description}
|
|
305
|
+
disabled={merged.disabled}
|
|
306
|
+
confirmDelete={
|
|
307
|
+
arrayProps?.confirmDelete as ControlArrayProps["confirmDelete"]
|
|
308
|
+
}
|
|
309
|
+
renderTabName={
|
|
310
|
+
arrayProps?.renderTabName as ControlArrayProps["renderTabName"]
|
|
311
|
+
}
|
|
312
|
+
forceTabs={arrayProps?.forceTabs as boolean | undefined}
|
|
313
|
+
/>,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ── File: managed upload (image preview, multi, drag-drop) ──────
|
|
318
|
+
// Checked early so it wins over the array→combobox branch below
|
|
319
|
+
// when the schema is `z.array(z.string())` with $control.upload.
|
|
320
|
+
if (merged.upload) {
|
|
321
|
+
const uploadOpts =
|
|
322
|
+
typeof merged.upload === "object"
|
|
323
|
+
? (merged.upload as Partial<ControlUploadProps>)
|
|
324
|
+
: {};
|
|
325
|
+
return wrapWithSlots(
|
|
326
|
+
merged,
|
|
327
|
+
<ControlUpload
|
|
328
|
+
input={props.input}
|
|
329
|
+
label={merged.label ?? props.label}
|
|
330
|
+
description={merged.description ?? props.description}
|
|
331
|
+
disabled={merged.disabled}
|
|
332
|
+
{...uploadOpts}
|
|
333
|
+
/>,
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ── Number / slider ──────────────────────────────────────────────
|
|
338
|
+
if (
|
|
339
|
+
merged.slider ||
|
|
340
|
+
merged.number ||
|
|
341
|
+
(!merged.select &&
|
|
342
|
+
!merged.segmented &&
|
|
343
|
+
!merged.combobox &&
|
|
344
|
+
(meta.type === "number" || meta.type === "integer"))
|
|
345
|
+
) {
|
|
346
|
+
return wrapWithSlots(
|
|
347
|
+
merged,
|
|
348
|
+
<ControlNumber
|
|
349
|
+
input={props.input}
|
|
350
|
+
label={merged.label ?? props.label}
|
|
351
|
+
description={merged.description ?? props.description}
|
|
352
|
+
slider={merged.slider}
|
|
353
|
+
disabled={merged.disabled}
|
|
354
|
+
/>,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// ── Items provided → select / multi / combobox ───────────────────
|
|
359
|
+
const items = (merged as Record<string, unknown>).items as
|
|
360
|
+
| undefined
|
|
361
|
+
| unknown[]
|
|
362
|
+
| ((q: string) => unknown);
|
|
363
|
+
if (
|
|
364
|
+
merged.select ||
|
|
365
|
+
merged.combobox ||
|
|
366
|
+
merged.segmented ||
|
|
367
|
+
meta.isEnum ||
|
|
368
|
+
(meta.isArray && !meta.isArrayOfObjects) ||
|
|
369
|
+
items != null
|
|
370
|
+
) {
|
|
371
|
+
return wrapWithSlots(
|
|
372
|
+
merged,
|
|
373
|
+
<ControlSelect
|
|
374
|
+
input={props.input}
|
|
375
|
+
label={merged.label ?? props.label}
|
|
376
|
+
description={merged.description ?? props.description}
|
|
377
|
+
segmented={merged.segmented}
|
|
378
|
+
combobox={merged.combobox}
|
|
379
|
+
items={items as never}
|
|
380
|
+
icon={resolveIcon(merged.icon)}
|
|
381
|
+
disabled={merged.disabled}
|
|
382
|
+
createNewEntry={
|
|
383
|
+
merged.createNewEntry as boolean | ((q: string) => never) | undefined
|
|
384
|
+
}
|
|
385
|
+
clearable={merged.clearable}
|
|
386
|
+
clearLabel={merged.clearLabel}
|
|
387
|
+
triggerClassName={merged.triggerClassName}
|
|
388
|
+
/>,
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// ── Boolean → switch ─────────────────────────────────────────────
|
|
393
|
+
if (meta.type === "boolean" && merged.switch !== false) {
|
|
394
|
+
return wrapWithSlots(
|
|
395
|
+
merged,
|
|
396
|
+
<FormField
|
|
397
|
+
id={meta.id}
|
|
398
|
+
label={merged.label ?? meta.label}
|
|
399
|
+
description={merged.description ?? meta.description}
|
|
400
|
+
error={meta.error}
|
|
401
|
+
required={meta.required}
|
|
402
|
+
>
|
|
403
|
+
<div className="flex h-9 items-center">
|
|
404
|
+
<Switch
|
|
405
|
+
id={meta.id}
|
|
406
|
+
// Same omission as the numeric control had: without a name the
|
|
407
|
+
// toggle is invisible to `[name="…"]` lookups, including
|
|
408
|
+
// `AutoForm`'s scroll-to-first-error.
|
|
409
|
+
name={props.input.props.name}
|
|
410
|
+
disabled={merged.disabled}
|
|
411
|
+
checked={Boolean(value)}
|
|
412
|
+
onCheckedChange={(v) => setValue(v)}
|
|
413
|
+
/>
|
|
414
|
+
</div>
|
|
415
|
+
</FormField>,
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// ── Date / time ──────────────────────────────────────────────────
|
|
420
|
+
if (
|
|
421
|
+
merged.date ||
|
|
422
|
+
merged.datetime ||
|
|
423
|
+
merged.time ||
|
|
424
|
+
meta.format === "date" ||
|
|
425
|
+
meta.format === "date-time" ||
|
|
426
|
+
meta.format === "time"
|
|
427
|
+
) {
|
|
428
|
+
return wrapWithSlots(
|
|
429
|
+
merged,
|
|
430
|
+
<ControlDate
|
|
431
|
+
input={props.input}
|
|
432
|
+
label={merged.label ?? props.label}
|
|
433
|
+
description={merged.description ?? props.description}
|
|
434
|
+
date={merged.date}
|
|
435
|
+
datetime={merged.datetime}
|
|
436
|
+
time={merged.time}
|
|
437
|
+
disabled={merged.disabled}
|
|
438
|
+
/>,
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// ── File (raw) ───────────────────────────────────────────────────
|
|
443
|
+
if (merged.file) {
|
|
444
|
+
return wrapWithSlots(
|
|
445
|
+
merged,
|
|
446
|
+
<FormField
|
|
447
|
+
id={meta.id}
|
|
448
|
+
label={merged.label ?? meta.label}
|
|
449
|
+
description={merged.description ?? meta.description}
|
|
450
|
+
error={meta.error}
|
|
451
|
+
required={meta.required}
|
|
452
|
+
>
|
|
453
|
+
<Input
|
|
454
|
+
id={meta.id}
|
|
455
|
+
name={props.input.props.name}
|
|
456
|
+
type="file"
|
|
457
|
+
disabled={merged.disabled}
|
|
458
|
+
onChange={(e) => setValue(e.target.files?.[0])}
|
|
459
|
+
/>
|
|
460
|
+
</FormField>,
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// ── Auto-textarea: explicit `area` or maxLength > 256 ────────────
|
|
465
|
+
const maxLength = meta.constraints.maxLength ?? 0;
|
|
466
|
+
if (merged.area || maxLength > 256) {
|
|
467
|
+
const rows =
|
|
468
|
+
merged.rows ?? (maxLength > 1024 ? 6 : maxLength > 512 ? 4 : 2);
|
|
469
|
+
return wrapWithSlots(
|
|
470
|
+
merged,
|
|
471
|
+
<FormField
|
|
472
|
+
id={meta.id}
|
|
473
|
+
label={merged.label ?? meta.label}
|
|
474
|
+
description={merged.description ?? meta.description}
|
|
475
|
+
error={meta.error}
|
|
476
|
+
required={meta.required}
|
|
477
|
+
>
|
|
478
|
+
<Textarea
|
|
479
|
+
{...merged.inputProps}
|
|
480
|
+
{...formFieldAriaProps({
|
|
481
|
+
id: meta.id,
|
|
482
|
+
error: meta.error,
|
|
483
|
+
description: merged.description ?? meta.description,
|
|
484
|
+
})}
|
|
485
|
+
id={meta.id}
|
|
486
|
+
name={props.input.props.name}
|
|
487
|
+
rows={rows}
|
|
488
|
+
disabled={merged.disabled}
|
|
489
|
+
maxLength={maxLength || undefined}
|
|
490
|
+
autoComplete={merged.autoComplete}
|
|
491
|
+
autoFocus={merged.autoFocus}
|
|
492
|
+
placeholder={merged.placeholder}
|
|
493
|
+
value={String(value ?? "")}
|
|
494
|
+
onChange={(e) => setValue(e.target.value)}
|
|
495
|
+
/>
|
|
496
|
+
</FormField>,
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// ── Password ─────────────────────────────────────────────────────
|
|
501
|
+
const isPassword =
|
|
502
|
+
merged.password ||
|
|
503
|
+
meta.iconHint === "password" ||
|
|
504
|
+
meta.format === "password";
|
|
505
|
+
if (isPassword) {
|
|
506
|
+
return wrapWithSlots(
|
|
507
|
+
merged,
|
|
508
|
+
<PasswordControl
|
|
509
|
+
id={meta.id}
|
|
510
|
+
name={props.input.props.name}
|
|
511
|
+
label={merged.label ?? meta.label}
|
|
512
|
+
description={merged.description ?? meta.description}
|
|
513
|
+
error={meta.error}
|
|
514
|
+
required={meta.required}
|
|
515
|
+
disabled={merged.disabled}
|
|
516
|
+
autoComplete={merged.autoComplete}
|
|
517
|
+
autoFocus={merged.autoFocus}
|
|
518
|
+
inputProps={merged.inputProps}
|
|
519
|
+
icon={resolveIcon(merged.icon, "password")}
|
|
520
|
+
value={String(value ?? "")}
|
|
521
|
+
onChange={(v) => setValue(v)}
|
|
522
|
+
/>,
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// ── Default text input with format-driven HTML5 type + icon ──────
|
|
527
|
+
const Icon = resolveIcon(merged.icon, meta.iconHint);
|
|
528
|
+
const htmlType =
|
|
529
|
+
meta.format === "email"
|
|
530
|
+
? "email"
|
|
531
|
+
: meta.format === "url" || meta.format === "uri"
|
|
532
|
+
? "url"
|
|
533
|
+
: meta.format === "tel" || meta.format === "phone"
|
|
534
|
+
? "tel"
|
|
535
|
+
: "text";
|
|
536
|
+
|
|
537
|
+
// Derive a sensible HTML `autocomplete` hint from the schema format so
|
|
538
|
+
// password managers and browser autofill behave correctly out of the box.
|
|
539
|
+
// Explicit `autoComplete` prop always wins.
|
|
540
|
+
const autoCompleteFromFormat =
|
|
541
|
+
meta.format === "email"
|
|
542
|
+
? "email"
|
|
543
|
+
: meta.format === "tel" || meta.format === "phone"
|
|
544
|
+
? "tel"
|
|
545
|
+
: meta.format === "url" || meta.format === "uri"
|
|
546
|
+
? "url"
|
|
547
|
+
: undefined;
|
|
548
|
+
const autoComplete = merged.autoComplete ?? autoCompleteFromFormat;
|
|
549
|
+
|
|
550
|
+
// ── Right-side affordance: tick (when dirty) or clear (when nullable) ─
|
|
551
|
+
// Tick only renders inside an `<AutoForm autoSave>` tree (or any caller
|
|
552
|
+
// that explicitly wraps with `<FormFieldAutoSaveProvider value>`).
|
|
553
|
+
const showSave = autoSaveEnabled && !!form.dirty && !merged.disabled;
|
|
554
|
+
const isNullable =
|
|
555
|
+
!meta.required && value != null && value !== "" && !merged.disabled;
|
|
556
|
+
const showClear = !showSave && isNullable;
|
|
557
|
+
// Reserve a fixed right gutter for any editable field so the tick/clear
|
|
558
|
+
// can swap in without nudging the input width.
|
|
559
|
+
const reserveGutter = !merged.disabled;
|
|
560
|
+
|
|
561
|
+
return wrapWithSlots(
|
|
562
|
+
merged,
|
|
563
|
+
<FormField
|
|
564
|
+
id={meta.id}
|
|
565
|
+
label={merged.label ?? meta.label}
|
|
566
|
+
description={merged.description ?? meta.description}
|
|
567
|
+
error={meta.error}
|
|
568
|
+
required={meta.required}
|
|
569
|
+
>
|
|
570
|
+
<div className="relative">
|
|
571
|
+
{Icon && (
|
|
572
|
+
<Icon className="text-muted-foreground absolute top-1/2 left-3 size-4 -translate-y-1/2 pointer-events-none" />
|
|
573
|
+
)}
|
|
574
|
+
<Input
|
|
575
|
+
{...merged.inputProps}
|
|
576
|
+
{...formFieldAriaProps({
|
|
577
|
+
id: meta.id,
|
|
578
|
+
error: meta.error,
|
|
579
|
+
description: merged.description ?? meta.description,
|
|
580
|
+
})}
|
|
581
|
+
id={meta.id}
|
|
582
|
+
name={props.input.props.name}
|
|
583
|
+
type={htmlType}
|
|
584
|
+
disabled={merged.disabled}
|
|
585
|
+
autoComplete={autoComplete}
|
|
586
|
+
autoFocus={merged.autoFocus}
|
|
587
|
+
placeholder={merged.placeholder}
|
|
588
|
+
value={String(value ?? "")}
|
|
589
|
+
minLength={meta.constraints.minLength}
|
|
590
|
+
maxLength={meta.constraints.maxLength}
|
|
591
|
+
pattern={meta.constraints.pattern}
|
|
592
|
+
className={[
|
|
593
|
+
merged.inputProps?.className,
|
|
594
|
+
(Icon ? "pl-9" : "") + (reserveGutter ? " pr-9" : ""),
|
|
595
|
+
]
|
|
596
|
+
.filter(Boolean)
|
|
597
|
+
.join(" ")}
|
|
598
|
+
onChange={(e) => setValue(e.target.value)}
|
|
599
|
+
/>
|
|
600
|
+
{showSave && (
|
|
601
|
+
<button
|
|
602
|
+
type="button"
|
|
603
|
+
onClick={() => props.input.form.submit()}
|
|
604
|
+
aria-label="Save"
|
|
605
|
+
className="text-primary hover:text-primary/80 absolute top-1/2 right-2 -translate-y-1/2 p-1"
|
|
606
|
+
>
|
|
607
|
+
<Check className="size-3.5" />
|
|
608
|
+
</button>
|
|
609
|
+
)}
|
|
610
|
+
{showClear && (
|
|
611
|
+
<button
|
|
612
|
+
type="button"
|
|
613
|
+
onClick={() => setValue(undefined)}
|
|
614
|
+
aria-label="Clear"
|
|
615
|
+
className="text-muted-foreground hover:text-foreground absolute top-1/2 right-2 -translate-y-1/2 p-1"
|
|
616
|
+
>
|
|
617
|
+
<X className="size-3.5" />
|
|
618
|
+
</button>
|
|
619
|
+
)}
|
|
620
|
+
</div>
|
|
621
|
+
</FormField>,
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const useDynamicControlRefresh = (input: BaseInputField | undefined) => {
|
|
626
|
+
const alepha = useAlepha();
|
|
627
|
+
const [, bump] = useState(0);
|
|
628
|
+
// Function-form `$control` rides on zod's `.meta()` registry (not a plain
|
|
629
|
+
// schema property), and the field may be wrapped (optional/nullable), so peel
|
|
630
|
+
// to the inner schema before reading its meta to detect the dynamic case.
|
|
631
|
+
const base = input?.schema ? z.schema.unwrap(input.schema) : undefined;
|
|
632
|
+
const rawControl = (
|
|
633
|
+
base as { meta?: () => { $control?: unknown } } | undefined
|
|
634
|
+
)?.meta?.()?.$control;
|
|
635
|
+
const isDynamic = typeof rawControl === "function";
|
|
636
|
+
useEffect(() => {
|
|
637
|
+
if (!isDynamic || !input?.form) return;
|
|
638
|
+
const formId = input.form.id;
|
|
639
|
+
return alepha.events.on("form:change", (e) => {
|
|
640
|
+
if (e.id === formId && e.path !== input.path) bump((n) => n + 1);
|
|
641
|
+
});
|
|
642
|
+
}, [alepha, input?.form, input?.path, isDynamic]);
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
const resolveIcon = (
|
|
646
|
+
icon: ControlProps["icon"],
|
|
647
|
+
fallback?: string | null,
|
|
648
|
+
): IconComponent | undefined => {
|
|
649
|
+
if (icon === null) return undefined;
|
|
650
|
+
if (typeof icon === "string") return iconFor(icon);
|
|
651
|
+
if (icon) return icon;
|
|
652
|
+
return iconFor(fallback);
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
const wrapWithSlots = (
|
|
656
|
+
props: ControlProps & Partial<SchemaControl>,
|
|
657
|
+
body: ReactNode,
|
|
658
|
+
): ReactNode => {
|
|
659
|
+
const top = (props.top as ReactNode) ?? null;
|
|
660
|
+
const bottom = (props.bottom as ReactNode) ?? null;
|
|
661
|
+
if (!top && !bottom) return body;
|
|
662
|
+
return (
|
|
663
|
+
<div className="flex flex-col gap-1">
|
|
664
|
+
{top}
|
|
665
|
+
{body}
|
|
666
|
+
{bottom}
|
|
667
|
+
</div>
|
|
668
|
+
);
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
interface PasswordControlProps {
|
|
672
|
+
id?: string;
|
|
673
|
+
name?: string;
|
|
674
|
+
label?: string;
|
|
675
|
+
description?: string;
|
|
676
|
+
error?: string;
|
|
677
|
+
required?: boolean;
|
|
678
|
+
disabled?: boolean;
|
|
679
|
+
autoComplete?: string;
|
|
680
|
+
autoFocus?: boolean;
|
|
681
|
+
inputProps?: HTMLAttributes<HTMLElement>;
|
|
682
|
+
icon?: IconComponent;
|
|
683
|
+
value: string;
|
|
684
|
+
onChange: (v: string) => void;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function PasswordControl(props: PasswordControlProps) {
|
|
688
|
+
const [reveal, setReveal] = useState(false);
|
|
689
|
+
const Icon = props.icon;
|
|
690
|
+
return (
|
|
691
|
+
<FormField
|
|
692
|
+
id={props.id}
|
|
693
|
+
label={props.label}
|
|
694
|
+
description={props.description}
|
|
695
|
+
error={props.error}
|
|
696
|
+
required={props.required}
|
|
697
|
+
>
|
|
698
|
+
<div className="relative">
|
|
699
|
+
{Icon && (
|
|
700
|
+
<Icon className="text-muted-foreground absolute top-1/2 left-3 size-4 -translate-y-1/2 pointer-events-none" />
|
|
701
|
+
)}
|
|
702
|
+
<Input
|
|
703
|
+
{...props.inputProps}
|
|
704
|
+
{...formFieldAriaProps({
|
|
705
|
+
id: props.id,
|
|
706
|
+
error: props.error,
|
|
707
|
+
description: props.description,
|
|
708
|
+
})}
|
|
709
|
+
id={props.id}
|
|
710
|
+
name={props.name}
|
|
711
|
+
type={reveal ? "text" : "password"}
|
|
712
|
+
autoComplete={props.autoComplete ?? "current-password"}
|
|
713
|
+
autoFocus={props.autoFocus}
|
|
714
|
+
disabled={props.disabled}
|
|
715
|
+
value={props.value}
|
|
716
|
+
onChange={(e) => props.onChange(e.target.value)}
|
|
717
|
+
className={[props.inputProps?.className, Icon ? "pr-9 pl-9" : "pr-9"]
|
|
718
|
+
.filter(Boolean)
|
|
719
|
+
.join(" ")}
|
|
720
|
+
/>
|
|
721
|
+
<Button
|
|
722
|
+
type="button"
|
|
723
|
+
variant="ghost"
|
|
724
|
+
size="icon"
|
|
725
|
+
disabled={props.disabled}
|
|
726
|
+
onClick={() => setReveal((r) => !r)}
|
|
727
|
+
aria-label={reveal ? "Hide password" : "Show password"}
|
|
728
|
+
className="text-muted-foreground hover:text-foreground absolute top-1/2 right-1 size-7 -translate-y-1/2"
|
|
729
|
+
>
|
|
730
|
+
{reveal ? <EyeOff className="size-4" /> : <Eye className="size-4" />}
|
|
731
|
+
</Button>
|
|
732
|
+
</div>
|
|
733
|
+
</FormField>
|
|
734
|
+
);
|
|
735
|
+
}
|