@middag-io/react 0.38.0 → 0.39.1

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 (39) hide show
  1. package/dist-lib/{FormField-B4_ub94_.js → FormField-DnDEEbyM.js} +858 -781
  2. package/dist-lib/FormPanelBlock-C2AneajG.js +1425 -0
  3. package/dist-lib/base/blocks/DenseTableBlock.d.ts.map +1 -1
  4. package/dist-lib/base/shell/partials/EditablePanelContext.d.ts +53 -0
  5. package/dist-lib/base/shell/partials/EditablePanelContext.d.ts.map +1 -0
  6. package/dist-lib/base/shell/partials/EditablePanelContext.js +19 -0
  7. package/dist-lib/base/shell/partials/EditablePanelProvider.d.ts +20 -0
  8. package/dist-lib/base/shell/partials/EditablePanelProvider.d.ts.map +1 -0
  9. package/dist-lib/base/shell/partials/EditablePanelProvider.js +83 -0
  10. package/dist-lib/base/shell/partials/InlineEditablePanel.d.ts +13 -0
  11. package/dist-lib/base/shell/partials/InlineEditablePanel.d.ts.map +1 -0
  12. package/dist-lib/base/shell/partials/InlineEditablePanel.js +1420 -0
  13. package/dist-lib/base/shell/partials/PageActionButton.js +0 -1
  14. package/dist-lib/base/utils/icon-registry.d.ts.map +1 -1
  15. package/dist-lib/base/utils/icon-registry.js +13 -10
  16. package/dist-lib/chunks/subpath--GXsYu-v.js +122 -0
  17. package/dist-lib/chunks/subpath-55YUOrvG.js +22 -0
  18. package/dist-lib/chunks/subpath-7b9-j7in.js +68 -0
  19. package/dist-lib/chunks/subpath-B30yU5uo.js +25 -0
  20. package/dist-lib/chunks/subpath-BhcZoWUz.js +221 -0
  21. package/dist-lib/chunks/{subpath-DLFO_UGQ.js → subpath-C0XqfmBB.js} +2 -0
  22. package/dist-lib/contracts/generated/contract-schema.d.ts +1 -1
  23. package/dist-lib/contracts/generated/contract-types.d.ts +10 -2
  24. package/dist-lib/contracts/generated/contract-types.d.ts.map +1 -1
  25. package/dist-lib/contracts/generated/index.d.ts +1 -1
  26. package/dist-lib/i18n/I18nProvider.js +1 -1
  27. package/dist-lib/i18n/instance.js +1 -1
  28. package/dist-lib/i18n/locales/en/ui.json +1 -0
  29. package/dist-lib/i18n/locales/pt-BR/ui.json +1 -0
  30. package/dist-lib/i18n/register-strings.js +1 -1
  31. package/dist-lib/index.d.ts +3 -0
  32. package/dist-lib/index.d.ts.map +1 -1
  33. package/dist-lib/lib/actions/resolve-action-target.d.ts +5 -2
  34. package/dist-lib/lib/actions/resolve-action-target.d.ts.map +1 -1
  35. package/dist-lib/lib/actions/resolve-action-target.js +6 -0
  36. package/dist-lib/middag-react.css +1 -1
  37. package/dist-lib/middag-react.js +7820 -7556
  38. package/package.json +1 -1
  39. package/dist-lib/FormPanelBlock-3fH3TyZX.js +0 -1499
@@ -0,0 +1,1420 @@
1
+ "use client";
2
+ import { cn as e } from "../../../lib/utils.js";
3
+ import { Button as t } from "../../../primitives/reui/button.js";
4
+ import { Avatar as n, AvatarFallback as r, AvatarImage as i } from "../../../primitives/reui/avatar.js";
5
+ import { Badge as a } from "../../../primitives/reui/badge.js";
6
+ import { Checkbox as o } from "../../../primitives/reui/checkbox.js";
7
+ import { Input as s } from "../../../primitives/reui/input.js";
8
+ import { Textarea as c } from "../../../primitives/reui/textarea.js";
9
+ import { InputGroup as l, InputGroupAddon as u, InputGroupInput as d, InputGroupText as f } from "../../../primitives/reui/input-group.js";
10
+ import { Combobox as p, ComboboxContent as m, ComboboxEmpty as h, ComboboxInput as g, ComboboxItem as _, ComboboxList as v } from "../../../primitives/reui/combobox.js";
11
+ import { Select as y, SelectContent as b, SelectItem as x, SelectTrigger as S, SelectValue as C } from "../../../primitives/reui/select.js";
12
+ import { Skeleton as w } from "../../../primitives/reui/skeleton.js";
13
+ import { Label as T } from "../../../primitives/reui/label.js";
14
+ import { Switch as E } from "../../../primitives/reui/switch.js";
15
+ import { InputOTP as D, InputOTPGroup as O, InputOTPSeparator as k, InputOTPSlot as A } from "../../../primitives/reui/input-otp.js";
16
+ import { NativeSelect as j, NativeSelectOption as M } from "../../../primitives/reui/native-select.js";
17
+ import { NumberField as ee, NumberFieldDecrement as N, NumberFieldGroup as P, NumberFieldIncrement as F, NumberFieldInput as I } from "../../../primitives/reui/number-field.js";
18
+ import { RadioGroup as L, RadioGroupItem as te } from "../../../primitives/reui/radio-group.js";
19
+ import { Rating as ne } from "../../../primitives/reui/rating.js";
20
+ import { Slider as re } from "../../../primitives/reui/slider.js";
21
+ import { useTranslation as R } from "../../../i18n/useTranslation.js";
22
+ import { useEditablePanel as ie } from "./EditablePanelContext.js";
23
+ import { evaluateCondition as z } from "../../utils/conditions.js";
24
+ import { formatBytes as B, useFileUpload as ae } from "../../../lib/hooks/use-file-upload.js";
25
+ import { Fragment as oe, Suspense as V, lazy as H, useCallback as U, useEffect as se, useId as ce, useMemo as W, useRef as le, useState as G } from "react";
26
+ import { Fragment as ue, jsx as K, jsxs as q } from "react/jsx-runtime";
27
+ import { HugeiconsIcon as J } from "@hugeicons/react";
28
+ import { Cancel01Icon as de, FileEmpty02Icon as fe, Upload01Icon as pe, ViewIcon as me, ViewOffIcon as he } from "@hugeicons/core-free-icons";
29
+ import { REGEXP_ONLY_DIGITS as ge, REGEXP_ONLY_DIGITS_AND_CHARS as _e } from "input-otp";
30
+ import { z as Y } from "zod";
31
+ //#region src/base/form/form-utils.ts
32
+ function ve(e) {
33
+ let t = [];
34
+ for (let n of e) n.kind === "field" ? t.push(n) : (n.kind === "section" || n.kind === "group") && t.push(...ve(n.children));
35
+ return t;
36
+ }
37
+ function ye(e, t) {
38
+ if (e.component === "header") return !0;
39
+ let { props: n } = e;
40
+ return !(n.hidden_when && z(n.hidden_when, t) || n.visible_when && !z(n.visible_when, t));
41
+ }
42
+ function be(e, t) {
43
+ if (e.component === "header") return !1;
44
+ let { props: n } = e;
45
+ return !!(n.disabled || n.disabled_when && z(n.disabled_when, t));
46
+ }
47
+ function xe(e, t) {
48
+ if (e.component === "header" || be(e, t)) return !1;
49
+ let { props: n } = e;
50
+ return !!(n.required || n.required_when && z(n.required_when, t));
51
+ }
52
+ //#endregion
53
+ //#region src/base/form/form-schema-builder.ts
54
+ function Se(e, t, n) {
55
+ let { component: r, props: i } = e, a = i.validation, o = n;
56
+ switch (r) {
57
+ case "text":
58
+ case "textarea":
59
+ case "password":
60
+ case "slug":
61
+ case "color": {
62
+ let e = Y.string();
63
+ return o && (e = e.min(1, t("middag.ui.validation.required"))), a?.minLength && (e = e.min(a.minLength, t("middag.ui.validation.min_length", { min: a.minLength }))), a?.maxLength && (e = e.max(a.maxLength, t("middag.ui.validation.max_length", { max: a.maxLength }))), a?.pattern && (e = e.regex(new RegExp(a.pattern), a.patternMessage ?? t("middag.ui.validation.pattern"))), o ? e : e.or(Y.literal(""));
64
+ }
65
+ case "email": {
66
+ let e = Y.string();
67
+ if (o) e = e.min(1, t("middag.ui.validation.required")).email(t("middag.ui.validation.email"));
68
+ else return e.email(t("middag.ui.validation.email")).or(Y.literal(""));
69
+ return e;
70
+ }
71
+ case "url": {
72
+ let e = Y.string();
73
+ if (o) e = e.min(1, t("middag.ui.validation.required")).url(t("middag.ui.validation.url"));
74
+ else return e.url(t("middag.ui.validation.url")).or(Y.literal(""));
75
+ return e;
76
+ }
77
+ case "int": {
78
+ let e = Y.number({ message: t("middag.ui.validation.integer") }).int(t("middag.ui.validation.integer"));
79
+ return i.min != null && (e = e.min(i.min, t("middag.ui.validation.min_value", { min: i.min }))), i.max != null && (e = e.max(i.max, t("middag.ui.validation.max_value", { max: i.max }))), o ? e : e.nullable();
80
+ }
81
+ case "float": {
82
+ let e = Y.number();
83
+ return i.min != null && (e = e.min(i.min, t("middag.ui.validation.min_value", { min: i.min }))), i.max != null && (e = e.max(i.max, t("middag.ui.validation.max_value", { max: i.max }))), o ? e : e.nullable();
84
+ }
85
+ case "currency": {
86
+ let e = Y.number();
87
+ return o ? e : e.nullable();
88
+ }
89
+ case "select":
90
+ case "radio":
91
+ case "entity_picker": {
92
+ let e = Y.string();
93
+ return o ? e.min(1, t("middag.ui.validation.required")) : e;
94
+ }
95
+ case "multiselect":
96
+ case "tags": {
97
+ let e = Y.array(Y.string());
98
+ return o ? e.min(1, t("middag.ui.validation.required")) : e;
99
+ }
100
+ case "checkbox":
101
+ case "switch": return Y.boolean();
102
+ case "date":
103
+ case "datetime": {
104
+ let e = Y.string();
105
+ return o ? e.min(1, t("middag.ui.validation.required")) : e;
106
+ }
107
+ case "phone": {
108
+ let e = Y.string();
109
+ return o ? e.min(1, t("middag.ui.validation.required")) : e;
110
+ }
111
+ case "document": {
112
+ let e = i.documentType ?? "generic", n = i.documentScope ?? "any", r = Y.string(), a = async (t) => {
113
+ let { isValidDocument: r } = await import("../../../chunks/subpath-7b9-j7in.js");
114
+ return r(t, e, n);
115
+ };
116
+ return o ? r.min(1, t("middag.ui.validation.required")).refine(a, t("middag.ui.validation.document_invalid")) : r.refine(async (e) => e === "" || await a(e), t("middag.ui.validation.document_invalid"));
117
+ }
118
+ default: return Y.any();
119
+ }
120
+ }
121
+ function Ce(e, t, n) {
122
+ let r = ve(e), i = {};
123
+ for (let e of r) e.component === "header" || e.component === "hidden" || e.component === "static" || ye(e, t) && (i[e.key] = Se(e, n, xe(e, t)));
124
+ return Y.object(i);
125
+ }
126
+ //#endregion
127
+ //#region src/base/form/fields/CheckboxField.tsx
128
+ function we({ id: e, value: t, onChange: n, label: r, disabled: i, required: a, error: s, helpTextId: c, errorId: l }) {
129
+ let u = [s ? l : void 0, c].filter(Boolean).join(" ") || void 0;
130
+ return /* @__PURE__ */ q("div", {
131
+ className: "flex items-center gap-2",
132
+ children: [/* @__PURE__ */ K(o, {
133
+ id: e,
134
+ checked: !!t,
135
+ onCheckedChange: (e) => n(e === !0),
136
+ disabled: i,
137
+ "aria-invalid": s ? !0 : void 0,
138
+ "aria-required": a || void 0,
139
+ "aria-describedby": u
140
+ }), r && /* @__PURE__ */ K(T, {
141
+ htmlFor: e,
142
+ className: "text-sm font-normal",
143
+ children: r
144
+ })]
145
+ });
146
+ }
147
+ //#endregion
148
+ //#region src/base/form/fields/ColorField.tsx
149
+ function Te({ id: e, value: t, onChange: n, placeholder: r, disabled: i, required: a, error: o, helpTextId: c, errorId: l }) {
150
+ let u = [o ? l : void 0, c].filter(Boolean).join(" ") || void 0, d = U((e) => {
151
+ n(e.target.value);
152
+ }, [n]), f = U((e) => {
153
+ n(e.target.value);
154
+ }, [n]);
155
+ return /* @__PURE__ */ q("div", {
156
+ className: "flex items-center gap-2",
157
+ children: [/* @__PURE__ */ K("input", {
158
+ type: "color",
159
+ value: t || "#000000",
160
+ onChange: f,
161
+ disabled: i,
162
+ className: "border-input h-9 w-9 shrink-0 cursor-pointer rounded-md border p-0.5",
163
+ "aria-label": "Color picker"
164
+ }), /* @__PURE__ */ K(s, {
165
+ id: e,
166
+ type: "text",
167
+ value: t ?? "",
168
+ onChange: d,
169
+ placeholder: r ?? "#000000",
170
+ disabled: i,
171
+ maxLength: 7,
172
+ "aria-invalid": o ? !0 : void 0,
173
+ "aria-required": a || void 0,
174
+ "aria-describedby": u,
175
+ className: "font-mono"
176
+ })]
177
+ });
178
+ }
179
+ //#endregion
180
+ //#region src/base/form/fields/CurrencyField.tsx
181
+ var Ee = {
182
+ BRL: "R$",
183
+ USD: "$",
184
+ EUR: "€",
185
+ GBP: "£",
186
+ JPY: "¥",
187
+ CNY: "¥",
188
+ KRW: "₩",
189
+ INR: "₹",
190
+ MXN: "$",
191
+ ARS: "$",
192
+ CLP: "$",
193
+ COP: "$",
194
+ PEN: "S/"
195
+ };
196
+ function De({ id: e, value: t, onChange: n, currency: r = "BRL", placeholder: i, disabled: a, required: o, error: s, helpTextId: c, errorId: p, min: m, max: h }) {
197
+ let { t: g, formatCurrency: _ } = R(), [v, y] = G(!1), [b, x] = G(""), S = [s ? p : void 0, c].filter(Boolean).join(" ") || void 0, C = v ? b : t == null ? "" : _(t, r), w = Ee[r] ?? r, T = U(() => {
198
+ y(!0), x(t == null ? "" : String(t));
199
+ }, [t]), E = U(() => {
200
+ y(!1);
201
+ let e = parseFloat(b.replace(/,/g, "."));
202
+ n(Number.isNaN(e) ? null : Math.round((m !== void 0 && e < m ? m : h !== void 0 && e > h ? h : e) * 100) / 100);
203
+ }, [
204
+ b,
205
+ n,
206
+ m,
207
+ h
208
+ ]), D = U((e) => {
209
+ x(e.target.value);
210
+ }, []);
211
+ return /* @__PURE__ */ q(l, {
212
+ "data-disabled": a || void 0,
213
+ children: [/* @__PURE__ */ K(u, {
214
+ align: "inline-start",
215
+ children: /* @__PURE__ */ K(f, { children: w })
216
+ }), /* @__PURE__ */ K(d, {
217
+ id: e,
218
+ inputMode: "decimal",
219
+ value: v ? b : t == null ? "" : C.replace(w, "").trim(),
220
+ onChange: D,
221
+ onFocus: T,
222
+ onBlur: E,
223
+ placeholder: i ?? g("middag.ui.form.currency_placeholder"),
224
+ disabled: a,
225
+ "aria-invalid": s ? !0 : void 0,
226
+ "aria-required": o || void 0,
227
+ "aria-describedby": S
228
+ })]
229
+ });
230
+ }
231
+ //#endregion
232
+ //#region src/base/form/fields/EntityPickerField.tsx
233
+ function Oe(e) {
234
+ return e.split(/\s+/).slice(0, 2).map((e) => e[0]?.toUpperCase() ?? "").join("");
235
+ }
236
+ function ke({ id: e, value: t, onChange: a, options: o, initialOption: s, autocompleteHref: c, autocompleteMinChars: l = 2, entityAvatarField: u, entitySubtitleField: d, placeholder: f, disabled: y, required: b, error: x, helpTextId: S, errorId: C }) {
237
+ let { t: w } = R(), [T, E] = G(s && t && s.value === t ? s.label : ""), [D, O] = G([]), [k, A] = G(!1), j = le(void 0), M = !!c, ee = [x ? C : void 0, S].filter(Boolean).join(" ") || void 0, N = W(() => [], []), P = W(() => o ?? N, [o, N]);
238
+ se(() => {
239
+ if (M) return j.current && clearTimeout(j.current), T.length < l ? (j.current = setTimeout(() => O([]), 0), () => {
240
+ j.current && clearTimeout(j.current);
241
+ }) : (j.current = setTimeout(async () => {
242
+ A(!0);
243
+ try {
244
+ let e = new URL(c, window.location.origin);
245
+ e.searchParams.set("q", T);
246
+ let t = await fetch(e.toString());
247
+ if (t.ok) {
248
+ let e = await t.json();
249
+ O((e.items ?? e.data ?? e).map((e) => ({
250
+ value: String(e.value ?? e.id),
251
+ label: String(e.label ?? e.name ?? e.title ?? ""),
252
+ subtitle: d ? String(e[d] ?? "") : void 0,
253
+ avatarUrl: u ? String(e[u] ?? "") : void 0
254
+ })));
255
+ }
256
+ } catch {} finally {
257
+ A(!1);
258
+ }
259
+ }, 300), () => {
260
+ j.current && clearTimeout(j.current);
261
+ });
262
+ }, [
263
+ T,
264
+ M,
265
+ c,
266
+ l,
267
+ d,
268
+ u
269
+ ]);
270
+ let F = M ? D : P, I = W(() => s && t && s.value === t && !F.some((e) => e.value === t) ? [s, ...F] : F, [
271
+ F,
272
+ s,
273
+ t
274
+ ]), L = W(() => {
275
+ if (M || !T) return I;
276
+ let e = T.toLowerCase();
277
+ return I.filter((t) => t.label.toLowerCase().includes(e) || t.subtitle?.toLowerCase().includes(e));
278
+ }, [
279
+ I,
280
+ T,
281
+ M
282
+ ]), te = U((e) => {
283
+ a(e ?? "");
284
+ }, [a]), ne = k ? w("middag.ui.form.entity_loading") : T.length < l && M ? w("middag.ui.form.entity_min_chars").replace("{min}", String(l)) : w("middag.ui.form.entity_no_results"), re = !!u || I.some((e) => e.avatarUrl);
285
+ return /* @__PURE__ */ q(p, {
286
+ items: L,
287
+ value: t || null,
288
+ onValueChange: te,
289
+ children: [/* @__PURE__ */ K(g, {
290
+ id: e,
291
+ placeholder: f ?? w("middag.ui.form.entity_search"),
292
+ disabled: y,
293
+ "aria-invalid": x ? !0 : void 0,
294
+ "aria-required": b || void 0,
295
+ "aria-describedby": ee,
296
+ showClear: !!t,
297
+ showTrigger: !0,
298
+ value: T,
299
+ onChange: (e) => E(e.target.value)
300
+ }), /* @__PURE__ */ q(m, { children: [/* @__PURE__ */ K(h, {
301
+ className: "px-4 py-3 text-sm",
302
+ children: ne
303
+ }), /* @__PURE__ */ K(v, { children: L.map((e) => /* @__PURE__ */ q(_, {
304
+ value: e.value,
305
+ className: "flex items-center gap-2.5 px-3 py-2",
306
+ children: [re && /* @__PURE__ */ q(n, {
307
+ className: "h-7 w-7 shrink-0",
308
+ children: [e.avatarUrl && /* @__PURE__ */ K(i, {
309
+ src: e.avatarUrl,
310
+ alt: e.label
311
+ }), /* @__PURE__ */ K(r, {
312
+ className: "text-[10px]",
313
+ children: Oe(e.label)
314
+ })]
315
+ }), /* @__PURE__ */ q("div", {
316
+ className: "min-w-0 flex-1",
317
+ children: [/* @__PURE__ */ K("div", {
318
+ className: "truncate text-sm",
319
+ children: e.label
320
+ }), e.subtitle && /* @__PURE__ */ K("div", {
321
+ className: "text-muted-foreground truncate text-xs",
322
+ children: e.subtitle
323
+ })]
324
+ })]
325
+ }, e.value)) })] })]
326
+ });
327
+ }
328
+ //#endregion
329
+ //#region src/base/form/fields/FileUploadField.tsx
330
+ function Ae(e) {
331
+ let t = e.split(/[?#]/)[0], n = t.split("/");
332
+ return n[n.length - 1] || t;
333
+ }
334
+ function je(e) {
335
+ if (e == null || e === "") return null;
336
+ if (typeof e == "string") return {
337
+ name: Ae(e),
338
+ size: 0,
339
+ type: "",
340
+ url: e,
341
+ id: e
342
+ };
343
+ if (typeof e == "object" && !(e instanceof File)) {
344
+ let t = e, n = typeof t.url == "string" ? t.url : "", r = typeof t.name == "string" ? t.name : n ? Ae(n) : "";
345
+ return !n && !r ? null : {
346
+ name: r,
347
+ size: typeof t.size == "number" ? t.size : 0,
348
+ type: typeof t.type == "string" ? t.type : "",
349
+ url: n,
350
+ id: typeof t.id == "string" && t.id ? t.id : n || r
351
+ };
352
+ }
353
+ return null;
354
+ }
355
+ function Me(e) {
356
+ return (Array.isArray(e) ? e : [e]).map(je).filter((e) => e !== null);
357
+ }
358
+ function Ne({ id: n, value: r, onChange: i, accept: a = "*", multiple: o = !1, maxFiles: s = 10, maxSize: c = 10 * 1024 * 1024, disabled: l, required: u, error: d, helpTextId: f, errorId: p }) {
359
+ let { t: m } = R(), [h] = G(() => Me(r)), [{ files: g, isDragging: _, errors: v }, { removeFile: y, handleDragEnter: b, handleDragLeave: x, handleDragOver: S, handleDrop: C, openFileDialog: w, getInputProps: T }] = ae({
360
+ maxFiles: o ? s : 1,
361
+ maxSize: c,
362
+ accept: a,
363
+ multiple: o,
364
+ initialFiles: h,
365
+ onFilesChange: (e) => {
366
+ let t = e.map((e) => e.file).filter((e) => e instanceof File);
367
+ i(o ? t : t[0] ?? null);
368
+ }
369
+ }), E = [d ? p : void 0, f].filter(Boolean).join(" ") || void 0, D = (e) => e.type.startsWith("image/");
370
+ return /* @__PURE__ */ q("div", { children: [/* @__PURE__ */ q("div", {
371
+ className: e("rounded-lg border border-dashed p-4 transition-colors", _ ? "border-primary bg-primary/5" : "border-muted-foreground/25 hover:border-muted-foreground/50", l && "pointer-events-none opacity-50"),
372
+ onDragEnter: b,
373
+ onDragLeave: x,
374
+ onDragOver: S,
375
+ onDrop: C,
376
+ children: [/* @__PURE__ */ K("input", {
377
+ ...T(),
378
+ id: n,
379
+ className: "sr-only",
380
+ disabled: l,
381
+ "aria-invalid": d ? !0 : void 0,
382
+ "aria-required": u || void 0,
383
+ "aria-describedby": E
384
+ }), g.length === 0 ? /* @__PURE__ */ q("div", {
385
+ className: "flex flex-col items-center gap-2 py-4",
386
+ children: [
387
+ /* @__PURE__ */ K(J, {
388
+ icon: pe,
389
+ className: e("size-8", _ ? "text-primary" : "text-muted-foreground")
390
+ }),
391
+ /* @__PURE__ */ K("p", {
392
+ className: "text-muted-foreground text-sm",
393
+ children: m("middag.ui.form.file_drop_hint")
394
+ }),
395
+ /* @__PURE__ */ K(t, {
396
+ type: "button",
397
+ variant: "outline",
398
+ size: "sm",
399
+ onClick: w,
400
+ disabled: l,
401
+ children: m("middag.ui.form.file_browse")
402
+ }),
403
+ /* @__PURE__ */ q("p", {
404
+ className: "text-muted-foreground text-xs",
405
+ children: [
406
+ m("middag.ui.form.file_max_size"),
407
+ " ",
408
+ B(c)
409
+ ]
410
+ })
411
+ ]
412
+ }) : /* @__PURE__ */ q("div", {
413
+ className: "space-y-2",
414
+ children: [g.map((e) => /* @__PURE__ */ q("div", {
415
+ className: "bg-muted/50 flex items-center gap-3 rounded-md px-3 py-2",
416
+ children: [
417
+ D(e.file) && e.preview ? /* @__PURE__ */ K("img", {
418
+ src: e.preview,
419
+ alt: e.file.name,
420
+ className: "size-10 shrink-0 rounded border object-cover"
421
+ }) : /* @__PURE__ */ K("div", {
422
+ className: "bg-muted flex size-10 shrink-0 items-center justify-center rounded border",
423
+ children: /* @__PURE__ */ K(J, {
424
+ icon: fe,
425
+ className: "text-muted-foreground size-5"
426
+ })
427
+ }),
428
+ /* @__PURE__ */ q("div", {
429
+ className: "min-w-0 flex-1",
430
+ children: [/* @__PURE__ */ K("p", {
431
+ className: "truncate text-sm font-medium",
432
+ children: e.file.name
433
+ }), /* @__PURE__ */ K("p", {
434
+ className: "text-muted-foreground text-xs",
435
+ children: B(e.file.size)
436
+ })]
437
+ }),
438
+ /* @__PURE__ */ K(t, {
439
+ type: "button",
440
+ variant: "ghost",
441
+ size: "icon-xs",
442
+ onClick: () => y(e.id),
443
+ disabled: l,
444
+ children: /* @__PURE__ */ K(J, {
445
+ icon: de,
446
+ className: "size-3.5"
447
+ })
448
+ })
449
+ ]
450
+ }, e.id)), o && g.length < s && /* @__PURE__ */ K(t, {
451
+ type: "button",
452
+ variant: "outline",
453
+ size: "sm",
454
+ onClick: w,
455
+ disabled: l,
456
+ children: m("middag.ui.form.file_add_more")
457
+ })]
458
+ })]
459
+ }), v.length > 0 && /* @__PURE__ */ K("div", {
460
+ className: "mt-1.5 space-y-0.5",
461
+ children: v.map((e, t) => /* @__PURE__ */ K("p", {
462
+ className: "text-destructive text-xs",
463
+ children: e
464
+ }, t))
465
+ })] });
466
+ }
467
+ //#endregion
468
+ //#region src/base/form/fields/MultiSelectField.tsx
469
+ var Pe = 8;
470
+ function Fe({ id: e, value: t, onChange: n, options: r, placeholder: i, disabled: a, required: o, error: s, helpTextId: c, errorId: l, variant: u = "auto" }) {
471
+ let { t: d } = R(), f = t ?? [], p = [s ? l : void 0, c].filter(Boolean).join(" ") || void 0;
472
+ return u === "checkbox" || u === "auto" && r.length <= Pe ? /* @__PURE__ */ K(Ie, {
473
+ id: e,
474
+ options: r,
475
+ selected: f,
476
+ onChange: n,
477
+ disabled: a,
478
+ required: o,
479
+ error: s,
480
+ describedBy: p,
481
+ t: d
482
+ }) : /* @__PURE__ */ K(Le, {
483
+ id: e,
484
+ options: r,
485
+ selected: f,
486
+ onChange: n,
487
+ placeholder: i,
488
+ disabled: a,
489
+ required: o,
490
+ error: s,
491
+ describedBy: p,
492
+ t: d
493
+ });
494
+ }
495
+ function Ie({ id: e, options: t, selected: n, onChange: r, disabled: i, required: a, error: s, describedBy: c, t: l }) {
496
+ let u = (e) => {
497
+ n.includes(e) ? r(n.filter((t) => t !== e)) : r([...n, e]);
498
+ };
499
+ return /* @__PURE__ */ q("div", {
500
+ id: e,
501
+ role: "group",
502
+ "aria-invalid": s ? !0 : void 0,
503
+ "aria-required": a || void 0,
504
+ "aria-describedby": c,
505
+ className: "border-input max-h-48 space-y-2 overflow-y-auto rounded-md border p-3",
506
+ children: [t.map((t) => /* @__PURE__ */ q("div", {
507
+ className: "flex items-center gap-2",
508
+ children: [/* @__PURE__ */ K(o, {
509
+ id: `${e}-${t.value}`,
510
+ checked: n.includes(t.value),
511
+ onCheckedChange: () => u(t.value),
512
+ disabled: i
513
+ }), /* @__PURE__ */ K(T, {
514
+ htmlFor: `${e}-${t.value}`,
515
+ className: "text-sm font-normal",
516
+ children: t.label
517
+ })]
518
+ }, t.value)), t.length === 0 && /* @__PURE__ */ K("p", {
519
+ className: "text-muted-foreground text-sm",
520
+ children: l("middag.ui.multiselect.no_options")
521
+ })]
522
+ });
523
+ }
524
+ function Le({ id: e, options: t, selected: n, onChange: r, placeholder: i, disabled: s, required: c, error: l, describedBy: u, t: d }) {
525
+ let [f, y] = G(""), b = W(() => {
526
+ if (!f) return t;
527
+ let e = f.toLowerCase();
528
+ return t.filter((t) => t.label.toLowerCase().includes(e));
529
+ }, [t, f]), x = W(() => {
530
+ let e = new Map(t.map((e) => [e.value, e.label]));
531
+ return n.map((t) => ({
532
+ value: t,
533
+ label: e.get(t) ?? t
534
+ }));
535
+ }, [n, t]), S = U((e) => {
536
+ r(n.filter((t) => t !== e));
537
+ }, [n, r]), C = U((e) => {
538
+ e && (n.includes(e) ? r(n.filter((t) => t !== e)) : r([...n, e]));
539
+ }, [n, r]);
540
+ return /* @__PURE__ */ q("div", {
541
+ id: e,
542
+ "aria-invalid": l ? !0 : void 0,
543
+ "aria-required": c || void 0,
544
+ "aria-describedby": u,
545
+ className: "space-y-2",
546
+ children: [x.length > 0 && /* @__PURE__ */ K("div", {
547
+ className: "flex flex-wrap gap-1.5",
548
+ children: x.map((e) => /* @__PURE__ */ q(a, {
549
+ variant: "secondary",
550
+ className: "gap-1 pr-1",
551
+ children: [e.label, /* @__PURE__ */ K("button", {
552
+ type: "button",
553
+ onClick: () => S(e.value),
554
+ className: "text-muted-foreground hover:text-foreground ml-0.5 rounded-full",
555
+ "aria-label": d("middag.ui.form.multiselect_remove", { label: e.label }),
556
+ children: /* @__PURE__ */ q("svg", {
557
+ viewBox: "0 0 24 24",
558
+ fill: "none",
559
+ stroke: "currentColor",
560
+ strokeWidth: 2,
561
+ className: "h-3 w-3",
562
+ children: [/* @__PURE__ */ K("line", {
563
+ x1: "18",
564
+ y1: "6",
565
+ x2: "6",
566
+ y2: "18"
567
+ }), /* @__PURE__ */ K("line", {
568
+ x1: "6",
569
+ y1: "6",
570
+ x2: "18",
571
+ y2: "18"
572
+ })]
573
+ })
574
+ })]
575
+ }, e.value))
576
+ }), /* @__PURE__ */ q(p, {
577
+ items: b,
578
+ value: null,
579
+ onValueChange: C,
580
+ filter: null,
581
+ children: [/* @__PURE__ */ K(g, {
582
+ placeholder: i ?? d("middag.ui.form.multiselect_search"),
583
+ disabled: s,
584
+ showTrigger: !0,
585
+ value: f,
586
+ onChange: (e) => y(e.target.value)
587
+ }), /* @__PURE__ */ q(m, { children: [/* @__PURE__ */ K(h, {
588
+ className: "px-4 py-3 text-sm",
589
+ children: d("middag.ui.form.entity_no_results")
590
+ }), /* @__PURE__ */ K(v, { children: b.map((e) => /* @__PURE__ */ q(_, {
591
+ value: e.value,
592
+ className: "flex items-center gap-2",
593
+ children: [/* @__PURE__ */ K(o, {
594
+ checked: n.includes(e.value),
595
+ tabIndex: -1,
596
+ className: "pointer-events-none"
597
+ }), /* @__PURE__ */ K("span", {
598
+ className: "text-sm",
599
+ children: e.label
600
+ })]
601
+ }, e.value)) })] })]
602
+ })]
603
+ });
604
+ }
605
+ //#endregion
606
+ //#region src/base/form/fields/NativeSelectField.tsx
607
+ function Re({ id: e, value: t, onChange: n, options: r, placeholder: i, disabled: a, required: o, error: s, helpTextId: c, errorId: l }) {
608
+ let { t: u } = R(), d = [s ? l : void 0, c].filter(Boolean).join(" ") || void 0;
609
+ return /* @__PURE__ */ K("div", {
610
+ className: "w-full [&>div]:w-full",
611
+ children: /* @__PURE__ */ q(j, {
612
+ id: e,
613
+ value: t ?? "",
614
+ onChange: (e) => n(e.target.value),
615
+ disabled: a,
616
+ required: o,
617
+ "aria-required": o || void 0,
618
+ "aria-invalid": s ? !0 : void 0,
619
+ "aria-describedby": d,
620
+ children: [/* @__PURE__ */ K(M, {
621
+ value: "",
622
+ disabled: o,
623
+ children: i ?? u("middag.ui.form.select_placeholder")
624
+ }), r.map((e) => /* @__PURE__ */ K(M, {
625
+ value: e.value,
626
+ children: e.label
627
+ }, e.value))]
628
+ })
629
+ });
630
+ }
631
+ //#endregion
632
+ //#region src/base/form/fields/NumberField.tsx
633
+ function X({ id: e, value: t, onChange: n, min: r, max: i, step: a = 1, disabled: o, required: s, error: c, helpTextId: l, errorId: u }) {
634
+ let d = [c ? u : void 0, l].filter(Boolean).join(" ") || void 0;
635
+ return /* @__PURE__ */ K(ee, {
636
+ id: e,
637
+ value: t ?? void 0,
638
+ onValueChange: (e) => n(e ?? null),
639
+ min: r,
640
+ max: i,
641
+ step: a,
642
+ disabled: o,
643
+ "aria-invalid": c ? !0 : void 0,
644
+ "aria-required": s || void 0,
645
+ "aria-describedby": d,
646
+ children: /* @__PURE__ */ q(P, { children: [
647
+ /* @__PURE__ */ K(N, {}),
648
+ /* @__PURE__ */ K(I, {}),
649
+ /* @__PURE__ */ K(F, {})
650
+ ] })
651
+ });
652
+ }
653
+ //#endregion
654
+ //#region src/base/form/fields/OtpField.tsx
655
+ function ze(e, t) {
656
+ if (!t || t >= e) return [Array.from({ length: e }, (e, t) => t)];
657
+ let n = [];
658
+ for (let r = 0; r < e; r += t) n.push(Array.from({ length: Math.min(t, e - r) }, (e, t) => r + t));
659
+ return n;
660
+ }
661
+ function Be({ id: e, value: t, onChange: n, maxLength: r = 6, pattern: i = "digits", groupSize: a, disabled: o, required: s, error: c, helpTextId: l, errorId: u }) {
662
+ let d = [c ? u : void 0, l].filter(Boolean).join(" ") || void 0, f = i === "alphanumeric" ? _e : ge, p = ze(r, a);
663
+ return /* @__PURE__ */ K(D, {
664
+ id: e,
665
+ maxLength: r,
666
+ value: t ?? "",
667
+ onChange: n,
668
+ pattern: f,
669
+ disabled: o,
670
+ "aria-invalid": c ? !0 : void 0,
671
+ "aria-required": s || void 0,
672
+ "aria-describedby": d,
673
+ children: p.map((e, t) => /* @__PURE__ */ q(oe, { children: [/* @__PURE__ */ K(O, { children: e.map((e) => /* @__PURE__ */ K(A, {
674
+ index: e,
675
+ "aria-invalid": c ? !0 : void 0
676
+ }, e)) }), t < p.length - 1 && /* @__PURE__ */ K(k, {})] }, e[0]))
677
+ });
678
+ }
679
+ //#endregion
680
+ //#region src/base/form/fields/PasswordField.tsx
681
+ function Ve({ id: e, value: n, onChange: r, placeholder: i, disabled: a, required: o, error: c, helpTextId: l, errorId: u }) {
682
+ let [d, f] = G(!1), p = [c ? u : void 0, l].filter(Boolean).join(" ") || void 0;
683
+ return /* @__PURE__ */ q("div", {
684
+ className: "relative",
685
+ children: [/* @__PURE__ */ K(s, {
686
+ id: e,
687
+ type: d ? "text" : "password",
688
+ value: n ?? "",
689
+ onChange: (e) => r(e.target.value),
690
+ placeholder: i,
691
+ disabled: a,
692
+ className: "pr-10",
693
+ "aria-invalid": c ? !0 : void 0,
694
+ "aria-required": o || void 0,
695
+ "aria-describedby": p
696
+ }), /* @__PURE__ */ K(t, {
697
+ type: "button",
698
+ variant: "ghost",
699
+ size: "icon",
700
+ className: "text-muted-foreground hover:text-foreground absolute top-0 right-0 h-full px-2.5",
701
+ onClick: () => f(!d),
702
+ tabIndex: -1,
703
+ "aria-label": d ? "Hide password" : "Show password",
704
+ children: /* @__PURE__ */ K(J, {
705
+ icon: d ? he : me,
706
+ size: 16,
707
+ strokeWidth: 2
708
+ })
709
+ })]
710
+ });
711
+ }
712
+ //#endregion
713
+ //#region src/base/form/fields/RadioField.tsx
714
+ function He({ id: e, value: t, onChange: n, options: r, disabled: i, required: a, error: o, helpTextId: s, errorId: c }) {
715
+ let l = [o ? c : void 0, s].filter(Boolean).join(" ") || void 0;
716
+ return /* @__PURE__ */ K(L, {
717
+ id: e,
718
+ value: t ?? "",
719
+ onValueChange: n,
720
+ disabled: i,
721
+ "aria-invalid": o ? !0 : void 0,
722
+ "aria-required": a || void 0,
723
+ "aria-describedby": l,
724
+ children: r.map((t) => {
725
+ let n = `${e}-${t.value}`;
726
+ return /* @__PURE__ */ q("div", {
727
+ className: "flex items-center gap-2",
728
+ children: [/* @__PURE__ */ K(te, {
729
+ value: t.value,
730
+ id: n
731
+ }), /* @__PURE__ */ K(T, {
732
+ htmlFor: n,
733
+ className: "text-sm font-normal",
734
+ children: t.label
735
+ })]
736
+ }, t.value);
737
+ })
738
+ });
739
+ }
740
+ //#endregion
741
+ //#region src/base/form/fields/RatingField.tsx
742
+ function Ue({ id: e, value: t, onChange: n, maxRating: r = 5, disabled: i, required: a, error: o, helpTextId: s, errorId: c }) {
743
+ let l = [o ? c : void 0, s].filter(Boolean).join(" ") || void 0;
744
+ return /* @__PURE__ */ K("div", {
745
+ id: e,
746
+ role: "radiogroup",
747
+ "aria-required": a || void 0,
748
+ "aria-invalid": o ? !0 : void 0,
749
+ "aria-describedby": l,
750
+ children: /* @__PURE__ */ K(ne, {
751
+ rating: t ?? 0,
752
+ maxRating: r,
753
+ editable: !i,
754
+ showValue: !0,
755
+ onRatingChange: n
756
+ })
757
+ });
758
+ }
759
+ //#endregion
760
+ //#region src/base/form/fields/SelectField.tsx
761
+ function We({ id: e, value: t, onChange: n, options: r, placeholder: i, disabled: a, required: o, error: s, helpTextId: c, errorId: l }) {
762
+ let { t: u } = R(), d = [s ? l : void 0, c].filter(Boolean).join(" ") || void 0;
763
+ return /* @__PURE__ */ q(y, {
764
+ value: t ?? "",
765
+ onValueChange: n,
766
+ disabled: a,
767
+ required: o,
768
+ children: [/* @__PURE__ */ K(S, {
769
+ id: e,
770
+ className: "w-full",
771
+ "aria-invalid": s ? !0 : void 0,
772
+ "aria-required": o || void 0,
773
+ "aria-describedby": d,
774
+ children: /* @__PURE__ */ K(C, { placeholder: i ?? u("middag.ui.form.select_placeholder") })
775
+ }), /* @__PURE__ */ K(b, { children: r.map((e) => /* @__PURE__ */ K(x, {
776
+ value: e.value,
777
+ children: e.label
778
+ }, e.value)) })]
779
+ });
780
+ }
781
+ //#endregion
782
+ //#region src/base/form/fields/SliderField.tsx
783
+ function Ge({ id: e, value: t, onChange: n, min: r = 0, max: i = 100, step: a = 1, multiple: o = !1, disabled: s, required: c, error: l, helpTextId: u, errorId: d }) {
784
+ let f = [l ? d : void 0, u].filter(Boolean).join(" ") || void 0, p = Array.isArray(t) ? t : t == null ? o ? [r, i] : [r] : [t], m = o ? p.join(" – ") : String(p[0] ?? r);
785
+ return /* @__PURE__ */ q("div", {
786
+ className: "flex items-center gap-4",
787
+ children: [/* @__PURE__ */ K(re, {
788
+ id: e,
789
+ value: p,
790
+ min: r,
791
+ max: i,
792
+ step: a,
793
+ disabled: s,
794
+ onValueChange: (e) => n(o ? e : e[0] ?? r),
795
+ "aria-invalid": l ? !0 : void 0,
796
+ "aria-required": c || void 0,
797
+ "aria-describedby": f
798
+ }), /* @__PURE__ */ K("span", {
799
+ "aria-hidden": "true",
800
+ className: "text-muted-foreground min-w-12 text-right text-sm tabular-nums",
801
+ children: m
802
+ })]
803
+ });
804
+ }
805
+ //#endregion
806
+ //#region src/base/form/fields/SlugField.tsx
807
+ function Ke(e) {
808
+ return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").replace(/-{2,}/g, "-");
809
+ }
810
+ function qe({ id: e, value: t, onChange: n, sourceValue: r, placeholder: i, disabled: a, required: o, error: s, helpTextId: c, errorId: p, prefix: m }) {
811
+ let [h, g] = G(!1), _ = [s ? p : void 0, c].filter(Boolean).join(" ") || void 0;
812
+ se(() => {
813
+ if (!h && r !== void 0) {
814
+ let e = Ke(r);
815
+ e !== t && n(e);
816
+ }
817
+ }, [
818
+ r,
819
+ h,
820
+ n,
821
+ t
822
+ ]);
823
+ let v = U((e) => {
824
+ g(!0), n(Ke(e.target.value));
825
+ }, [n]);
826
+ return m ? /* @__PURE__ */ q(l, {
827
+ "data-disabled": a || void 0,
828
+ children: [/* @__PURE__ */ K(u, {
829
+ align: "inline-start",
830
+ children: /* @__PURE__ */ K(f, { children: m })
831
+ }), /* @__PURE__ */ K(d, {
832
+ id: e,
833
+ type: "text",
834
+ value: t ?? "",
835
+ onChange: v,
836
+ placeholder: i ?? "url-friendly-slug",
837
+ disabled: a,
838
+ "aria-invalid": s ? !0 : void 0,
839
+ "aria-required": o || void 0,
840
+ "aria-describedby": _
841
+ })]
842
+ }) : /* @__PURE__ */ K(l, {
843
+ "data-disabled": a || void 0,
844
+ children: /* @__PURE__ */ K(d, {
845
+ id: e,
846
+ type: "text",
847
+ value: t ?? "",
848
+ onChange: v,
849
+ placeholder: i ?? "url-friendly-slug",
850
+ disabled: a,
851
+ "aria-invalid": s ? !0 : void 0,
852
+ "aria-required": o || void 0,
853
+ "aria-describedby": _
854
+ })
855
+ });
856
+ }
857
+ //#endregion
858
+ //#region src/base/form/fields/StaticField.tsx
859
+ function Je({ id: e, value: t }) {
860
+ return /* @__PURE__ */ K("p", {
861
+ id: e,
862
+ className: "border-input bg-muted/50 text-foreground rounded-md border px-3 py-2 text-sm",
863
+ children: t == null ? "—" : String(t)
864
+ });
865
+ }
866
+ //#endregion
867
+ //#region src/base/form/fields/SwitchField.tsx
868
+ function Ye({ id: e, value: t, onChange: n, label: r, disabled: i, required: a, error: o, helpTextId: s, errorId: c }) {
869
+ let l = [o ? c : void 0, s].filter(Boolean).join(" ") || void 0;
870
+ return /* @__PURE__ */ q("div", {
871
+ className: "flex items-center gap-2",
872
+ children: [/* @__PURE__ */ K(E, {
873
+ id: e,
874
+ checked: !!t,
875
+ onCheckedChange: n,
876
+ disabled: i,
877
+ "aria-invalid": o ? !0 : void 0,
878
+ "aria-required": a || void 0,
879
+ "aria-describedby": l
880
+ }), r && /* @__PURE__ */ K(T, {
881
+ htmlFor: e,
882
+ className: "text-sm font-normal",
883
+ children: r
884
+ })]
885
+ });
886
+ }
887
+ //#endregion
888
+ //#region src/base/form/fields/TagsField.tsx
889
+ function Xe({ id: e, value: t, onChange: n, placeholder: r, disabled: i, required: a, error: o, helpTextId: s, errorId: c, maxTags: l }) {
890
+ let { t: u } = R(), [d, f] = G(""), p = le(null), m = W(() => t ?? [], [t]), h = [o ? c : void 0, s].filter(Boolean).join(" ") || void 0, g = U((e) => {
891
+ let t = e.trim();
892
+ t && (m.includes(t) || l && m.length >= l || (n([...m, t]), f("")));
893
+ }, [
894
+ m,
895
+ n,
896
+ l
897
+ ]), _ = U((e) => {
898
+ n(m.filter((t, n) => n !== e));
899
+ }, [m, n]), v = U((e) => {
900
+ e.key === "Enter" || e.key === "," ? (e.preventDefault(), g(d)) : e.key === "Backspace" && !d && m.length > 0 && _(m.length - 1);
901
+ }, [
902
+ d,
903
+ m,
904
+ g,
905
+ _
906
+ ]);
907
+ return /* @__PURE__ */ q("div", {
908
+ className: `focus-within:ring-ring flex min-h-9 w-full flex-wrap items-center gap-1.5 rounded-md border px-2 py-1.5 text-sm transition-colors focus-within:ring-1 ${o ? "border-destructive" : "border-input"} ${i ? "opacity-50" : ""}`,
909
+ onClick: () => p.current?.focus(),
910
+ children: [m.map((e, t) => /* @__PURE__ */ q("span", {
911
+ className: "bg-secondary text-secondary-foreground inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs font-medium",
912
+ children: [e, !i && /* @__PURE__ */ K("button", {
913
+ type: "button",
914
+ onClick: (e) => {
915
+ e.stopPropagation(), _(t);
916
+ },
917
+ className: "text-muted-foreground hover:text-foreground ml-0.5",
918
+ "aria-label": `${u("middag.ui.form.tags_remove")} ${e}`,
919
+ children: "×"
920
+ })]
921
+ }, `${e}-${t}`)), /* @__PURE__ */ K("input", {
922
+ ref: p,
923
+ id: e,
924
+ type: "text",
925
+ value: d,
926
+ onChange: (e) => f(e.target.value),
927
+ onKeyDown: v,
928
+ onBlur: () => g(d),
929
+ placeholder: m.length === 0 ? r ?? u("middag.ui.form.tags_placeholder") : "",
930
+ disabled: i,
931
+ "aria-invalid": o ? !0 : void 0,
932
+ "aria-required": a || void 0,
933
+ "aria-describedby": h,
934
+ className: "placeholder:text-muted-foreground min-w-[80px] flex-1 bg-transparent outline-none"
935
+ })]
936
+ });
937
+ }
938
+ //#endregion
939
+ //#region src/base/form/fields/TextareaField.tsx
940
+ function Ze({ id: e, value: t, onChange: n, placeholder: r, rows: i = 4, disabled: a, readOnly: o, required: s, error: l, helpTextId: u, errorId: d }) {
941
+ let f = [l ? d : void 0, u].filter(Boolean).join(" ") || void 0;
942
+ return /* @__PURE__ */ K(c, {
943
+ id: e,
944
+ value: t ?? "",
945
+ onChange: (e) => n(e.target.value),
946
+ placeholder: r,
947
+ rows: i,
948
+ disabled: a,
949
+ readOnly: o,
950
+ "aria-invalid": l ? !0 : void 0,
951
+ "aria-required": s || void 0,
952
+ "aria-describedby": f
953
+ });
954
+ }
955
+ //#endregion
956
+ //#region src/base/form/fields/TextField.tsx
957
+ function Z({ id: e, value: t, onChange: n, type: r = "text", placeholder: i, disabled: a, readOnly: o, required: c, error: l, helpTextId: u, errorId: d }) {
958
+ let f = [l ? d : void 0, u].filter(Boolean).join(" ") || void 0;
959
+ return /* @__PURE__ */ K(s, {
960
+ id: e,
961
+ type: r,
962
+ value: t ?? "",
963
+ onChange: (e) => n(e.target.value),
964
+ placeholder: i,
965
+ disabled: a,
966
+ readOnly: o,
967
+ "aria-invalid": l ? !0 : void 0,
968
+ "aria-required": c || void 0,
969
+ "aria-describedby": f
970
+ });
971
+ }
972
+ //#endregion
973
+ //#region src/base/form/FormField.tsx
974
+ var Qe = H(() => import("../../../chunks/subpath-55YUOrvG.js").then((e) => ({ default: e.PhoneField }))), $e = H(() => import("../../../chunks/subpath--GXsYu-v.js").then((e) => ({ default: e.DateField }))), et = H(() => import("../../../chunks/subpath-BhcZoWUz.js").then((e) => ({ default: e.DocumentField }))), tt = H(() => import("../../../chunks/subpath-B30yU5uo.js").then((e) => ({ default: e.DateRangeField })));
975
+ function Q() {
976
+ return /* @__PURE__ */ K(w, { className: "h-9 w-full rounded-md" });
977
+ }
978
+ function nt({ label: e }) {
979
+ return /* @__PURE__ */ K("div", {
980
+ className: "pt-4 pb-1",
981
+ children: /* @__PURE__ */ K("h4", {
982
+ className: "text-foreground text-sm font-semibold",
983
+ children: e
984
+ })
985
+ });
986
+ }
987
+ function rt({ id: e, value: t }) {
988
+ return /* @__PURE__ */ K("input", {
989
+ type: "hidden",
990
+ id: e,
991
+ value: String(t ?? "")
992
+ });
993
+ }
994
+ function it({ field: e, value: t, onChange: n, error: r, sourceValues: i = {} }) {
995
+ let { t: a } = R(), o = ce(), s = `field-${e.key}-${o}`, c = `${s}-help`, l = `${s}-error`, { component: u, props: d } = e;
996
+ if (u === "header") return /* @__PURE__ */ K(nt, { label: d.label });
997
+ if (u === "hidden") return /* @__PURE__ */ K(rt, {
998
+ id: s,
999
+ value: t
1000
+ });
1001
+ let f = be(e, i), p = xe(e, i), m = u === "checkbox" || u === "switch", h = at(u, s, t, n, d, r, c, l, a, i, f, p);
1002
+ return /* @__PURE__ */ q("div", {
1003
+ className: "space-y-1.5",
1004
+ children: [
1005
+ !m && /* @__PURE__ */ q(T, {
1006
+ htmlFor: s,
1007
+ children: [d.label, p && /* @__PURE__ */ K("span", {
1008
+ className: "text-destructive ml-0.5",
1009
+ children: "*"
1010
+ })]
1011
+ }),
1012
+ d.helpText && /* @__PURE__ */ K("p", {
1013
+ id: c,
1014
+ className: "text-muted-foreground text-xs",
1015
+ children: d.helpText
1016
+ }),
1017
+ h,
1018
+ r && /* @__PURE__ */ K("p", {
1019
+ id: l,
1020
+ className: "text-destructive text-xs",
1021
+ "aria-live": "polite",
1022
+ children: r
1023
+ })
1024
+ ]
1025
+ });
1026
+ }
1027
+ function at(e, t, n, r, i, a, o, s, c, l, u, d) {
1028
+ let f = {
1029
+ id: t,
1030
+ error: a,
1031
+ helpTextId: o,
1032
+ errorId: s,
1033
+ disabled: u,
1034
+ required: d
1035
+ };
1036
+ switch (e) {
1037
+ case "text": return /* @__PURE__ */ K(Z, {
1038
+ ...f,
1039
+ type: "text",
1040
+ value: n,
1041
+ onChange: r,
1042
+ placeholder: i.placeholder,
1043
+ readOnly: i.readOnly
1044
+ });
1045
+ case "email": return /* @__PURE__ */ K(Z, {
1046
+ ...f,
1047
+ type: "email",
1048
+ value: n,
1049
+ onChange: r,
1050
+ placeholder: i.placeholder,
1051
+ readOnly: i.readOnly
1052
+ });
1053
+ case "url": return /* @__PURE__ */ K(Z, {
1054
+ ...f,
1055
+ type: "url",
1056
+ value: n,
1057
+ onChange: r,
1058
+ placeholder: i.placeholder,
1059
+ readOnly: i.readOnly
1060
+ });
1061
+ case "textarea": return /* @__PURE__ */ K(Ze, {
1062
+ ...f,
1063
+ value: n,
1064
+ onChange: r,
1065
+ placeholder: i.placeholder,
1066
+ rows: i.rows,
1067
+ readOnly: i.readOnly
1068
+ });
1069
+ case "password": return /* @__PURE__ */ K(Ve, {
1070
+ ...f,
1071
+ value: n,
1072
+ onChange: r,
1073
+ placeholder: i.placeholder
1074
+ });
1075
+ case "otp": return /* @__PURE__ */ K(Be, {
1076
+ ...f,
1077
+ value: n,
1078
+ onChange: r,
1079
+ maxLength: i.maxLength,
1080
+ pattern: i.pattern,
1081
+ groupSize: i.groupSize
1082
+ });
1083
+ case "select": return /* @__PURE__ */ K(We, {
1084
+ ...f,
1085
+ value: n,
1086
+ onChange: r,
1087
+ options: i.options ?? [],
1088
+ placeholder: i.placeholder
1089
+ });
1090
+ case "native_select": return /* @__PURE__ */ K(Re, {
1091
+ ...f,
1092
+ value: n,
1093
+ onChange: r,
1094
+ options: i.options ?? [],
1095
+ placeholder: i.placeholder
1096
+ });
1097
+ case "multiselect": return /* @__PURE__ */ K(Fe, {
1098
+ ...f,
1099
+ value: n,
1100
+ onChange: r,
1101
+ options: i.options ?? [],
1102
+ placeholder: i.placeholder,
1103
+ variant: i.variant
1104
+ });
1105
+ case "radio": return /* @__PURE__ */ K(He, {
1106
+ ...f,
1107
+ value: n,
1108
+ onChange: r,
1109
+ options: i.options ?? []
1110
+ });
1111
+ case "int": return /* @__PURE__ */ K(X, {
1112
+ ...f,
1113
+ value: n,
1114
+ onChange: r,
1115
+ min: i.min,
1116
+ max: i.max,
1117
+ step: 1
1118
+ });
1119
+ case "float": return /* @__PURE__ */ K(X, {
1120
+ ...f,
1121
+ value: n,
1122
+ onChange: r,
1123
+ min: i.min,
1124
+ max: i.max,
1125
+ step: i.step ?? .1
1126
+ });
1127
+ case "slider": return /* @__PURE__ */ K(Ge, {
1128
+ ...f,
1129
+ value: n,
1130
+ onChange: r,
1131
+ min: i.min,
1132
+ max: i.max,
1133
+ step: i.step,
1134
+ multiple: i.multiple
1135
+ });
1136
+ case "checkbox": return /* @__PURE__ */ K(we, {
1137
+ ...f,
1138
+ value: n,
1139
+ onChange: r,
1140
+ label: i.label
1141
+ });
1142
+ case "switch": return /* @__PURE__ */ K(Ye, {
1143
+ ...f,
1144
+ value: n,
1145
+ onChange: r,
1146
+ label: i.label
1147
+ });
1148
+ case "date": return /* @__PURE__ */ K(V, {
1149
+ fallback: /* @__PURE__ */ K(Q, {}),
1150
+ children: /* @__PURE__ */ K($e, {
1151
+ ...f,
1152
+ mode: "date",
1153
+ value: n,
1154
+ onChange: r,
1155
+ placeholder: i.placeholder
1156
+ })
1157
+ });
1158
+ case "datetime": return /* @__PURE__ */ K(V, {
1159
+ fallback: /* @__PURE__ */ K(Q, {}),
1160
+ children: /* @__PURE__ */ K($e, {
1161
+ ...f,
1162
+ mode: "datetime",
1163
+ value: n,
1164
+ onChange: r,
1165
+ placeholder: i.placeholder
1166
+ })
1167
+ });
1168
+ case "file": return /* @__PURE__ */ K(Ne, {
1169
+ ...f,
1170
+ value: n,
1171
+ onChange: r,
1172
+ accept: i.accept,
1173
+ multiple: i.multiple,
1174
+ maxFiles: i.maxFiles,
1175
+ maxSize: i.maxSize
1176
+ });
1177
+ case "entity_picker": return /* @__PURE__ */ K(ke, {
1178
+ ...f,
1179
+ value: n,
1180
+ onChange: r,
1181
+ options: i.options,
1182
+ autocompleteHref: i.autocompleteHref,
1183
+ autocompleteMinChars: i.autocompleteMinChars,
1184
+ initialOption: i.initialOption,
1185
+ entityAvatarField: i.entityAvatarField,
1186
+ entitySubtitleField: i.entitySubtitleField,
1187
+ placeholder: i.placeholder
1188
+ });
1189
+ case "static": return /* @__PURE__ */ K(Je, {
1190
+ id: t,
1191
+ value: n
1192
+ });
1193
+ case "phone": return /* @__PURE__ */ K(V, {
1194
+ fallback: /* @__PURE__ */ K(Q, {}),
1195
+ children: /* @__PURE__ */ K(Qe, {
1196
+ ...f,
1197
+ value: n,
1198
+ onChange: r,
1199
+ placeholder: i.placeholder,
1200
+ defaultCountry: i.defaultCountry,
1201
+ fixedCountry: i.fixedCountry
1202
+ })
1203
+ });
1204
+ case "document": return /* @__PURE__ */ K(V, {
1205
+ fallback: /* @__PURE__ */ K(Q, {}),
1206
+ children: /* @__PURE__ */ K(et, {
1207
+ ...f,
1208
+ value: n,
1209
+ onChange: r,
1210
+ documentType: i.documentType,
1211
+ documentScope: i.documentScope,
1212
+ documentMasks: i.documentMasks,
1213
+ placeholder: i.placeholder
1214
+ })
1215
+ });
1216
+ case "currency": return /* @__PURE__ */ K(De, {
1217
+ ...f,
1218
+ value: n,
1219
+ onChange: r,
1220
+ currency: i.currency,
1221
+ placeholder: i.placeholder,
1222
+ min: i.min,
1223
+ max: i.max
1224
+ });
1225
+ case "color": return /* @__PURE__ */ K(Te, {
1226
+ ...f,
1227
+ value: n,
1228
+ onChange: r,
1229
+ placeholder: i.placeholder
1230
+ });
1231
+ case "slug": return /* @__PURE__ */ K(qe, {
1232
+ ...f,
1233
+ value: n,
1234
+ onChange: r,
1235
+ sourceValue: i.sourceField === void 0 ? void 0 : String(l[i.sourceField] ?? ""),
1236
+ prefix: i.prefix,
1237
+ placeholder: i.placeholder
1238
+ });
1239
+ case "tags": return /* @__PURE__ */ K(Xe, {
1240
+ ...f,
1241
+ value: n,
1242
+ onChange: r,
1243
+ placeholder: i.placeholder,
1244
+ maxTags: i.maxTags
1245
+ });
1246
+ case "date_range": return /* @__PURE__ */ K(V, {
1247
+ fallback: /* @__PURE__ */ K(Q, {}),
1248
+ children: /* @__PURE__ */ K(tt, {
1249
+ ...f,
1250
+ value: n,
1251
+ onChange: r,
1252
+ operator: i.operator
1253
+ })
1254
+ });
1255
+ case "rating": return /* @__PURE__ */ K(Ue, {
1256
+ ...f,
1257
+ value: n,
1258
+ onChange: r,
1259
+ maxRating: i.maxRating
1260
+ });
1261
+ default: return /* @__PURE__ */ q("p", {
1262
+ className: "text-destructive text-xs",
1263
+ children: ["Unknown field component: ", e]
1264
+ });
1265
+ }
1266
+ }
1267
+ //#endregion
1268
+ //#region src/base/shell/partials/InlineEditablePanel.tsx
1269
+ function ot(e) {
1270
+ switch (e.component) {
1271
+ case "int":
1272
+ case "float":
1273
+ case "currency":
1274
+ case "slider":
1275
+ case "rating": return null;
1276
+ case "checkbox":
1277
+ case "switch": return !1;
1278
+ case "multiselect":
1279
+ case "tags": return [];
1280
+ default: return "";
1281
+ }
1282
+ }
1283
+ function st(e, t) {
1284
+ return Object.prototype.hasOwnProperty.call(t, e.key) ? t[e.key] : ot(e);
1285
+ }
1286
+ function $(t, n, r, i) {
1287
+ return t.map((t, a) => {
1288
+ switch (t.kind) {
1289
+ case "field": return ye(t, n) ? /* @__PURE__ */ K(it, {
1290
+ field: t,
1291
+ value: st(t, n),
1292
+ onChange: (e) => i(t.key, e),
1293
+ error: r[t.key],
1294
+ sourceValues: n
1295
+ }, t.key) : null;
1296
+ case "header": return /* @__PURE__ */ K("h4", {
1297
+ className: "text-foreground pt-2 text-sm font-semibold",
1298
+ children: t.label
1299
+ }, `header-${a}`);
1300
+ case "section": return /* @__PURE__ */ q("section", {
1301
+ className: "space-y-3",
1302
+ children: [/* @__PURE__ */ K("div", {
1303
+ className: "text-muted-foreground text-[11px] font-medium tracking-[0.04em] uppercase",
1304
+ children: t.label
1305
+ }), $(t.children, n, r, i)]
1306
+ }, t.id);
1307
+ case "group": return /* @__PURE__ */ K("div", {
1308
+ className: e(t.columns === 2 ? "grid grid-cols-2 gap-3" : "space-y-3"),
1309
+ children: $(t.children, n, r, i)
1310
+ }, t.id);
1311
+ default: return null;
1312
+ }
1313
+ });
1314
+ }
1315
+ function ct() {
1316
+ let { t: e } = R(), { enabled: n, selectedId: r, descriptor: i, loading: a, saving: o, submit: s, close: c, width: l } = ie(), [u, d] = G(() => i?.values ? { ...i.values } : {}), [f, p] = G({}), [m, h] = G(i);
1317
+ i !== m && (h(i), d(i?.values ? { ...i.values } : {}), p({}));
1318
+ let [g, _] = G(null), v = g ?? l, y = W(() => (e, t) => {
1319
+ d((n) => ({
1320
+ ...n,
1321
+ [e]: t
1322
+ })), p((t) => {
1323
+ if (!t[e]) return t;
1324
+ let n = { ...t };
1325
+ return delete n[e], n;
1326
+ });
1327
+ }, []);
1328
+ if (!n || r === null) return null;
1329
+ let b = (e) => {
1330
+ e.preventDefault();
1331
+ let t = e.clientX, n = v, r = (e) => {
1332
+ _(Math.min(720, Math.max(320, n + (t - e.clientX))));
1333
+ }, i = () => {
1334
+ window.removeEventListener("pointermove", r), window.removeEventListener("pointerup", i);
1335
+ };
1336
+ window.addEventListener("pointermove", r), window.addEventListener("pointerup", i);
1337
+ }, x = () => {
1338
+ if (!i) return;
1339
+ let t = Ce(i.schema, u, e).safeParse(u);
1340
+ if (!t.success) {
1341
+ let e = {};
1342
+ for (let n of t.error.issues) {
1343
+ let t = String(n.path[0] ?? "");
1344
+ t && !e[t] && (e[t] = n.message);
1345
+ }
1346
+ p(e);
1347
+ return;
1348
+ }
1349
+ s(t.data);
1350
+ };
1351
+ return /* @__PURE__ */ q(ue, { children: [/* @__PURE__ */ K("div", {
1352
+ className: "fixed inset-0 z-40 bg-black/40",
1353
+ onClick: c,
1354
+ "aria-hidden": !0
1355
+ }), /* @__PURE__ */ q("div", {
1356
+ role: "dialog",
1357
+ "aria-modal": "true",
1358
+ className: "bg-background fixed top-0 right-0 bottom-0 z-50 flex flex-col overflow-hidden border-l shadow-2xl",
1359
+ style: { width: v },
1360
+ children: [
1361
+ /* @__PURE__ */ K("div", {
1362
+ onPointerDown: b,
1363
+ className: "hover:bg-primary/30 absolute top-0 bottom-0 left-0 z-10 w-1.5 cursor-col-resize",
1364
+ "aria-hidden": !0
1365
+ }),
1366
+ /* @__PURE__ */ q("div", {
1367
+ className: "border-border/60 flex items-start gap-2 border-b px-4 pt-3 pb-2.5",
1368
+ children: [/* @__PURE__ */ q("div", {
1369
+ className: "min-w-0 flex-1",
1370
+ children: [i?.subtitle && /* @__PURE__ */ K("div", {
1371
+ className: "text-muted-foreground mb-0.5 font-mono text-[11px] font-semibold tracking-wide uppercase",
1372
+ children: i.subtitle
1373
+ }), /* @__PURE__ */ K("h3", {
1374
+ className: "text-foreground truncate text-base leading-snug font-semibold",
1375
+ children: i?.title ?? e("middag.ui.loading")
1376
+ })]
1377
+ }), /* @__PURE__ */ K("button", {
1378
+ type: "button",
1379
+ onClick: c,
1380
+ "aria-label": e("middag.ui.editable_panel.close"),
1381
+ className: "text-muted-foreground hover:text-foreground hover:bg-muted rounded p-1 transition-colors",
1382
+ children: /* @__PURE__ */ K("span", {
1383
+ "aria-hidden": !0,
1384
+ className: "text-sm leading-none",
1385
+ children: "✕"
1386
+ })
1387
+ })]
1388
+ }),
1389
+ /* @__PURE__ */ K("div", {
1390
+ className: "min-h-0 flex-1 overflow-y-auto p-4",
1391
+ children: a || !i ? /* @__PURE__ */ K("div", {
1392
+ className: "flex items-center justify-center p-8",
1393
+ children: /* @__PURE__ */ K("div", { className: "border-primary h-6 w-6 animate-spin rounded-full border-2 border-t-transparent" })
1394
+ }) : /* @__PURE__ */ K("div", {
1395
+ className: "space-y-3.5",
1396
+ children: $(i.schema, u, f, y)
1397
+ })
1398
+ }),
1399
+ i && !a && /* @__PURE__ */ q("div", {
1400
+ className: "flex justify-end gap-2 border-t p-3",
1401
+ children: [/* @__PURE__ */ K(t, {
1402
+ type: "button",
1403
+ variant: "outline",
1404
+ size: "sm",
1405
+ onClick: c,
1406
+ disabled: o,
1407
+ children: i.cancelLabel ?? e("middag.ui.cancel")
1408
+ }), /* @__PURE__ */ K(t, {
1409
+ type: "button",
1410
+ size: "sm",
1411
+ onClick: x,
1412
+ disabled: o,
1413
+ children: i.submitLabel ?? e("middag.ui.form.save")
1414
+ })]
1415
+ })
1416
+ ]
1417
+ })] });
1418
+ }
1419
+ //#endregion
1420
+ export { ct as InlineEditablePanel };