@object-ui/plugin-form 16.1.0 → 17.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +604 -1
  2. package/README.md +106 -0
  3. package/dist/DrawerForm.d.ts +1 -0
  4. package/dist/DrawerForm.d.ts.map +1 -0
  5. package/dist/EmbeddableForm.d.ts +1 -0
  6. package/dist/EmbeddableForm.d.ts.map +1 -0
  7. package/dist/FormAnalytics.d.ts +1 -0
  8. package/dist/FormAnalytics.d.ts.map +1 -0
  9. package/dist/FormSection.d.ts +1 -0
  10. package/dist/FormSection.d.ts.map +1 -0
  11. package/dist/LineItemsPanel.d.ts +1 -0
  12. package/dist/LineItemsPanel.d.ts.map +1 -0
  13. package/dist/MasterDetailForm.d.ts +9 -1
  14. package/dist/MasterDetailForm.d.ts.map +1 -0
  15. package/dist/ModalForm.d.ts +7 -2
  16. package/dist/ModalForm.d.ts.map +1 -0
  17. package/dist/ObjectForm.d.ts +1 -0
  18. package/dist/ObjectForm.d.ts.map +1 -0
  19. package/dist/SplitForm.d.ts +22 -2
  20. package/dist/SplitForm.d.ts.map +1 -0
  21. package/dist/TabbedForm.d.ts +13 -1
  22. package/dist/TabbedForm.d.ts.map +1 -0
  23. package/dist/WizardForm.d.ts +14 -1
  24. package/dist/WizardForm.d.ts.map +1 -0
  25. package/dist/autoLayout.d.ts +1 -0
  26. package/dist/autoLayout.d.ts.map +1 -0
  27. package/dist/deriveMasterDetail.d.ts +1 -0
  28. package/dist/deriveMasterDetail.d.ts.map +1 -0
  29. package/dist/fieldGroups.d.ts +1 -0
  30. package/dist/fieldGroups.d.ts.map +1 -0
  31. package/dist/index.d.ts +1 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +1561 -1281
  34. package/dist/index.umd.cjs +1 -1
  35. package/dist/masterDetailTx.d.ts +1 -0
  36. package/dist/masterDetailTx.d.ts.map +1 -0
  37. package/dist/occSave.d.ts +78 -0
  38. package/dist/occSave.d.ts.map +1 -0
  39. package/dist/sanitize.d.ts +1 -0
  40. package/dist/sanitize.d.ts.map +1 -0
  41. package/dist/sectionFields.d.ts +10 -2
  42. package/dist/sectionFields.d.ts.map +1 -0
  43. package/dist/successBehavior.d.ts +1 -0
  44. package/dist/successBehavior.d.ts.map +1 -0
  45. package/package.json +12 -11
package/dist/index.js CHANGED
@@ -1,100 +1,60 @@
1
- import e, { useCallback as t, useContext as n, useEffect as r, useId as i, useMemo as a, useRef as o, useState as s } from "react";
2
- import { ComponentRegistry as c, resolveCrudAffordances as l, runBatchTransaction as u } from "@object-ui/core";
3
- import { SchemaRenderer as d, SchemaRendererContext as f, usePreviewMode as p, useRecordContext as m, useSafeFieldLabel as h, useSchemaContext as g } from "@object-ui/react";
4
- import { LineItemsField as _, buildValidationRules as v, formatFileSize as y, mapFieldTypeToFormType as b } from "@object-ui/fields";
5
- import { AlertDialog as x, AlertDialogAction as S, AlertDialogCancel as C, AlertDialogContent as w, AlertDialogDescription as T, AlertDialogFooter as E, AlertDialogHeader as D, AlertDialogTitle as O, Button as k, Card as A, CardContent as j, CardDescription as M, CardHeader as N, CardTitle as P, Dialog as F, DialogDescription as I, DialogHeader as L, DialogTitle as ee, MobileDialogContent as R, ResizableHandle as z, ResizablePanel as B, ResizablePanelGroup as V, Sheet as H, SheetContent as U, SheetDescription as W, SheetHeader as te, SheetTitle as ne, Skeleton as re, Tabs as ie, TabsContent as ae, TabsList as oe, TabsTrigger as se, cn as G, toast as K, useIsMobile as ce } from "@object-ui/components";
6
- import { usePermissions as le } from "@object-ui/permissions";
7
- import { Check as q, CheckCircle2 as ue, ChevronDown as de, ChevronLeft as fe, ChevronRight as pe, Loader2 as me, Lock as J, ShieldCheck as Y } from "lucide-react";
8
- import { Fragment as he, jsx as X, jsxs as Z } from "react/jsx-runtime";
9
- import { createSafeTranslation as ge } from "@object-ui/i18n";
10
- import { deriveFieldGroupLayout as _e } from "@objectstack/spec/data";
1
+ import * as e from "react";
2
+ import t, { useCallback as n, useContext as r, useEffect as i, useId as a, useMemo as o, useRef as s, useState as c } from "react";
3
+ import { ComponentRegistry as l, evalFieldPredicate as u, resolveCrudAffordances as d, resolveFieldRuleState as f, runBatchTransaction as p } from "@object-ui/core";
4
+ import { SchemaRenderer as m, SchemaRendererContext as h, usePreviewMode as g, useRecordContext as _, useSafeFieldLabel as v, useSchemaContext as y } from "@object-ui/react";
5
+ import { LineItemsField as b, buildValidationRules as x, formatFileSize as S, mapFieldTypeToFormType as C } from "@object-ui/fields";
6
+ import { AlertDialog as w, AlertDialogAction as T, AlertDialogCancel as E, AlertDialogContent as D, AlertDialogDescription as O, AlertDialogFooter as k, AlertDialogHeader as A, AlertDialogTitle as j, Button as M, Card as N, CardContent as P, CardDescription as F, CardHeader as I, CardTitle as L, Dialog as R, DialogDescription as z, DialogHeader as B, DialogTitle as V, MobileDialogContent as H, Sheet as ee, SheetContent as U, SheetDescription as W, SheetHeader as G, SheetTitle as te, Skeleton as ne, buttonVariants as K, cn as q, toast as J, useIsMobile as re } from "@object-ui/components";
7
+ import { usePermissions as Y } from "@object-ui/permissions";
8
+ import { AlertCircle as ie, AlertTriangle as ae, Check as oe, CheckCircle2 as se, ChevronDown as ce, ChevronLeft as le, ChevronRight as X, Loader2 as ue, Lock as de, ShieldCheck as fe } from "lucide-react";
9
+ import { createSafeTranslation as pe } from "@object-ui/i18n";
10
+ import { Fragment as me, jsx as Z, jsxs as Q } from "react/jsx-runtime";
11
+ import { deriveFieldGroupLayout as he } from "@objectstack/spec/data";
11
12
  //#region src/successBehavior.ts
12
- function Q(e) {
13
+ function $(e) {
13
14
  try {
14
15
  return typeof window > "u" ? !1 : new URL(e, window.location.href).origin === window.location.origin;
15
16
  } catch {
16
17
  return !1;
17
18
  }
18
19
  }
19
- function ve(e, t) {
20
+ function ge(e, t) {
20
21
  if (!e) return null;
21
22
  let n = t?.id ?? t?.recordId ?? t?._id;
22
23
  if (n == null || n === "") return null;
23
24
  let r = e.replace(/\{(?:id|recordId)\}/g, String(n));
24
- return Q(r) ? r : null;
25
+ return $(r) ? r : null;
25
26
  }
26
27
  //#endregion
27
- //#region src/FormSection.tsx
28
- var $ = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, columns: i = 1, children: a, className: o, gridClassName: c, showBorder: l }) => {
29
- let [u, d] = s(r), f = {
30
- 1: "grid-cols-1",
31
- 2: "grid-cols-1 md:grid-cols-2",
32
- 3: "grid-cols-1 md:grid-cols-2 lg:grid-cols-3",
33
- 4: "grid-cols-1 md:grid-cols-2 lg:grid-cols-4"
34
- }, p = () => {
35
- n && d(!u);
36
- }, m = l ?? !!e, h = e || t ? /* @__PURE__ */ Z("div", {
37
- className: G("flex items-start gap-2", !m && "mb-4", n && "cursor-pointer select-none"),
38
- onClick: p,
39
- role: n ? "button" : void 0,
40
- "aria-expanded": n ? !u : void 0,
41
- children: [n && /* @__PURE__ */ X("span", {
42
- className: "mt-0.5 text-muted-foreground",
43
- children: X(u ? pe : de, { className: "h-4 w-4" })
44
- }), /* @__PURE__ */ Z("div", {
45
- className: "flex-1",
46
- children: [e && /* @__PURE__ */ X("h3", {
47
- className: "text-sm font-semibold text-foreground",
48
- children: e
49
- }), t && /* @__PURE__ */ X("p", {
50
- className: "text-sm text-muted-foreground mt-0.5",
51
- children: t
52
- })]
53
- })]
54
- }) : null, g = u ? null : /* @__PURE__ */ X("div", {
55
- className: G("grid gap-4", c || f[i]),
56
- children: a
57
- });
58
- return m ? /* @__PURE__ */ Z(A, {
59
- className: G("form-section bg-muted/40 shadow-none", o),
60
- children: [h && /* @__PURE__ */ X(N, {
61
- className: "border-b border-border pb-3",
62
- children: h
63
- }), g && /* @__PURE__ */ X(j, {
64
- className: "pt-4",
65
- children: g
66
- })]
67
- }) : /* @__PURE__ */ Z("div", {
68
- className: G("form-section", o),
69
- children: [h, g]
70
- });
71
- };
72
- //#endregion
73
28
  //#region src/sectionFields.ts
74
- function ye(e, t) {
29
+ function _e(e, t) {
75
30
  return typeof t == "string" && t.trim() || typeof t == "object" && t && typeof t.source == "string" && t.source.trim() ? {
76
31
  ...e,
77
32
  visibleOn: t
78
33
  } : e;
79
34
  }
35
+ var ve = /* @__PURE__ */ new Set();
36
+ function ye(e, t) {
37
+ if (typeof e.name != "string" || e.name === e.field) return;
38
+ let n = `${t}:${e.field}:${e.name}`;
39
+ ve.has(n) || (ve.add(n), console.warn(`[object-ui] section field { field: '${e.field}' } also carries name: '${e.name}' — mixed form-field vocabularies. The spec key wins (the runtime name becomes '${e.field}'); drop \`name\` from authored form views.`));
40
+ }
80
41
  function be(e, t) {
81
42
  let n = t.objectSchema?.fields?.[e];
82
43
  return n ? {
83
44
  name: e,
84
45
  label: t.fieldLabel(t.objectName, e, n.label || e),
85
- type: b(n.type),
46
+ type: C(n.type),
86
47
  required: n.required || !1,
87
48
  disabled: t.readOnly || t.mode === "view" || n.readonly,
88
49
  placeholder: n.placeholder,
89
50
  description: n.help || n.description,
90
- validation: v(n),
51
+ validation: x(n),
91
52
  field: n,
92
53
  options: n.options,
93
54
  multiple: n.multiple,
94
55
  visibleWhen: n.visibleWhen,
95
56
  readonlyWhen: n.readonlyWhen,
96
- requiredWhen: n.requiredWhen,
97
- conditionalRequired: n.conditionalRequired
57
+ requiredWhen: n.requiredWhen
98
58
  } : {
99
59
  name: e,
100
60
  label: e,
@@ -104,14 +64,15 @@ function be(e, t) {
104
64
  function xe(e, t) {
105
65
  if (typeof e == "string") {
106
66
  let n = t.objectSchema?.fields?.[e];
107
- return ye(be(e, t), n?.visible_on ?? n?.visibleOn);
67
+ return _e(be(e, t), n?.visible_on ?? n?.visibleOn);
108
68
  }
109
69
  let n = e;
110
- if (typeof n.field != "string") return ye(n, n.visibleOn);
70
+ if (typeof n.field != "string") return _e(n, n.visibleOn);
71
+ ye(n, t.objectName);
111
72
  let r = n.field, i = be(r, t);
112
- n.type != null && (i.type = b(n.type)), n.widget != null && (i.widget = n.widget), n.label != null && (i.label = n.label), n.placeholder != null && (i.placeholder = n.placeholder), n.helpText != null && (i.description = n.helpText), n.required != null && (i.required = n.required), n.readonly != null && (i.disabled = n.readonly || i.disabled), n.immutable != null && (i.immutable = n.immutable), n.hidden != null && (i.hidden = n.hidden), n.colSpan != null && (i.colSpan = n.colSpan), n.span != null && (i.span = n.span), n.options != null && (i.options = n.options), n.multiple != null && (i.multiple = n.multiple);
73
+ n.type != null && (i.type = C(n.type)), n.widget != null && (i.widget = n.widget), n.label != null && (i.label = n.label), n.placeholder != null && (i.placeholder = n.placeholder), n.helpText != null && (i.description = n.helpText), n.required != null && (i.required = n.required), n.readonly != null && (i.disabled = n.readonly || i.disabled), n.immutable != null && (i.immutable = n.immutable), n.hidden != null && (i.hidden = n.hidden), n.colSpan != null && (i.colSpan = n.colSpan), n.span != null && (i.span = n.span), n.options != null && (i.options = n.options), n.multiple != null && (i.multiple = n.multiple);
113
74
  let a = n.reference ?? n.reference_to;
114
- return a != null && (i.reference = a, i.reference_to = a), n.maxLength != null && (i.maxLength = n.maxLength), n.minLength != null && (i.minLength = n.minLength), n.min != null && (i.min = n.min), n.max != null && (i.max = n.max), n.precision != null && (i.precision = n.precision), n.scale != null && (i.scale = n.scale), n.language != null && (i.language = n.language), Array.isArray(n.fields) && (i.fields = n.fields), ye(i, n.visibleOn);
75
+ return a != null && (i.reference = a, i.reference_to = a), n.maxLength != null && (i.maxLength = n.maxLength), n.minLength != null && (i.minLength = n.minLength), n.min != null && (i.min = n.min), n.max != null && (i.max = n.max), n.precision != null && (i.precision = n.precision), n.scale != null && (i.scale = n.scale), n.language != null && (i.language = n.language), Array.isArray(n.fields) && (i.fields = n.fields), n.dependsOn != null && (i.dependsOn = n.dependsOn), n.keyField != null && (i.keyField = n.keyField), n.disclosure != null && (i.disclosure = n.disclosure), _e(i, n.visibleWhen ?? n.visibleOn);
115
76
  }
116
77
  function Se(e, t) {
117
78
  return (e.fields ?? []).map((e) => xe(e, t));
@@ -228,18 +189,10 @@ var Ie = {
228
189
  function Le(e) {
229
190
  return Ie[e && e > 0 ? Math.min(Math.floor(e), 4) : 1];
230
191
  }
231
- function Re(e, t) {
232
- let n = t && t > 1 ? Math.min(Math.floor(t), 4) : 1, r = n > 1 ? je(e, n) : e, i = Le(n);
233
- return {
234
- fields: r,
235
- columns: n,
236
- ...i ? { fieldContainerClass: i } : {}
237
- };
238
- }
239
- function ze(e) {
192
+ function Re(e) {
240
193
  return e <= 1 ? "default" : e === 2 ? "xl" : "full";
241
194
  }
242
- function Be(e, t, n, r) {
195
+ function ze(e, t, n, r) {
243
196
  let i = [...e];
244
197
  if (i = Ne(i, t), r === "create" && (i = Fe(i, t)), n !== void 0) return i = je(i, n), {
245
198
  fields: i,
@@ -252,509 +205,736 @@ function Be(e, t, n, r) {
252
205
  };
253
206
  }
254
207
  //#endregion
208
+ //#region src/occSave.tsx
209
+ var Be = pe({
210
+ "form.conflictTitle": "Save conflict",
211
+ "form.conflictMessage": "This record was changed by someone else while you were editing. Overwriting will replace their changes with yours.",
212
+ "form.conflictLatestVersion": "Their save: {{time}}",
213
+ "form.conflictOverwrite": "Overwrite",
214
+ "form.keepEditing": "Keep editing"
215
+ }, "form.conflictTitle");
216
+ function Ve(e) {
217
+ let t = e?.updated_at;
218
+ return typeof t == "string" && t.length > 0 ? t : void 0;
219
+ }
220
+ function He(e) {
221
+ if (!e || typeof e != "object") return !1;
222
+ let t = e;
223
+ return t.code === "CONCURRENT_UPDATE" || t.name === "ConcurrentUpdateError";
224
+ }
225
+ function Ue(e) {
226
+ if (!e) return null;
227
+ let t = /\d{4}-\d{2}-\d{2}[ T]/.test(e) ? e.replace(" ", "T") : e, n = new Date(t);
228
+ return Number.isNaN(n.getTime()) ? null : n.toLocaleString();
229
+ }
230
+ function We() {
231
+ let { t } = Be(), [n, r] = e.useState(null), i = e.useRef(null), a = e.useCallback((e) => {
232
+ i.current?.(e), i.current = null, r(null);
233
+ }, []);
234
+ e.useEffect(() => () => i.current?.(!1), []);
235
+ let o = e.useCallback(async ({ dataSource: e, objectName: t, recordId: n, payload: a, baseRecord: o }) => {
236
+ let s = Ve(o);
237
+ try {
238
+ return {
239
+ status: "saved",
240
+ result: await e.update(t, n, a, s ? { ifMatch: s } : void 0)
241
+ };
242
+ } catch (o) {
243
+ if (!He(o)) throw o;
244
+ let s = o.currentVersion;
245
+ if (!await new Promise((e) => {
246
+ i.current = e, r({ currentVersion: typeof s == "string" ? s : void 0 });
247
+ })) return { status: "cancelled" };
248
+ let c = typeof s == "string" && s.length > 0 ? s : void 0;
249
+ return {
250
+ status: "saved",
251
+ result: await e.update(t, n, a, c ? { ifMatch: c } : void 0)
252
+ };
253
+ }
254
+ }, []), s = Ue(n?.currentVersion);
255
+ return {
256
+ saveWithOcc: o,
257
+ conflictDialog: /* @__PURE__ */ Z(w, {
258
+ open: !!n,
259
+ onOpenChange: (e) => {
260
+ e || a(!1);
261
+ },
262
+ children: /* @__PURE__ */ Q(D, { children: [/* @__PURE__ */ Q(A, { children: [/* @__PURE__ */ Q(j, {
263
+ className: "flex items-center gap-2",
264
+ children: [/* @__PURE__ */ Z(ae, {
265
+ className: "h-5 w-5 text-amber-500",
266
+ "aria-hidden": !0
267
+ }), t("form.conflictTitle")]
268
+ }), /* @__PURE__ */ Q(O, { children: [t("form.conflictMessage"), s && /* @__PURE__ */ Z("span", {
269
+ className: "mt-2 block text-xs text-muted-foreground",
270
+ children: t("form.conflictLatestVersion", { time: s })
271
+ })] })] }), /* @__PURE__ */ Q(k, { children: [/* @__PURE__ */ Z("button", {
272
+ type: "button",
273
+ className: q(K({ variant: "outline" })),
274
+ onClick: () => a(!1),
275
+ children: t("form.keepEditing")
276
+ }), /* @__PURE__ */ Z("button", {
277
+ type: "button",
278
+ className: q(K({ variant: "destructive" })),
279
+ onClick: () => a(!0),
280
+ children: t("form.conflictOverwrite")
281
+ })] })] })
282
+ })
283
+ };
284
+ }
285
+ //#endregion
255
286
  //#region src/TabbedForm.tsx
256
- var Ve = ({ schema: n, dataSource: r, className: i }) => {
257
- let { fieldLabel: a } = h(), [o, c] = s(null), [l, u] = s({}), [f, p] = s(!0), [m, g] = s(null), [_, v] = s(n.defaultTab || n.sections[0]?.name || n.sections[0]?.label || "tab-0");
258
- e.useEffect(() => {
287
+ var Ge = ({ schema: e, dataSource: r, className: i }) => {
288
+ let { fieldLabel: a } = v(), [o, l] = c(null), [u, d] = c({}), { saveWithOcc: f, conflictDialog: p } = We(), [h, g] = c(!0), [_, y] = c(null), b = e.defaultTab || e.sections[0]?.name || e.sections[0]?.label || "tab-0";
289
+ t.useEffect(() => {
259
290
  (async () => {
260
291
  if (!r) {
261
- p(!1);
292
+ g(!1);
262
293
  return;
263
294
  }
264
295
  try {
265
- let e = await r.getObjectSchema(n.objectName);
266
- c(e);
296
+ let t = await r.getObjectSchema(e.objectName);
297
+ l(t);
267
298
  } catch (e) {
268
- g(e);
299
+ y(e);
269
300
  }
270
301
  })();
271
- }, [n.objectName, r]), e.useEffect(() => {
272
- (o || !r) && (async () => {
273
- if (n.mode === "create" || !n.recordId || !r) {
274
- u(n.initialData || n.initialValues || {}), p(!1);
302
+ }, [e.objectName, r]);
303
+ let x = s(void 0);
304
+ t.useEffect(() => {
305
+ let t = !1;
306
+ return (o || !r) && (async () => {
307
+ if (e.mode === "create" || !e.recordId || !r) {
308
+ d(e.initialData || e.initialValues || {}), g(!1);
275
309
  return;
276
310
  }
311
+ x.current !== e.recordId && g(!0);
277
312
  try {
278
- let e = await r.findOne(n.objectName, n.recordId);
279
- u(e || {});
313
+ let n = await r.findOne(e.objectName, e.recordId);
314
+ if (t) return;
315
+ x.current = e.recordId, d(n || {});
280
316
  } catch (e) {
281
- g(e);
317
+ if (t) return;
318
+ y(e);
282
319
  } finally {
283
- p(!1);
320
+ t || g(!1);
284
321
  }
285
- })();
322
+ })(), () => {
323
+ t = !0;
324
+ };
286
325
  }, [
287
326
  o,
288
- n.mode,
289
- n.recordId,
290
- n.initialData,
291
- n.initialValues,
327
+ e.mode,
328
+ e.recordId,
329
+ e.initialData,
330
+ e.initialValues,
292
331
  r,
293
- n.objectName
332
+ e.objectName
294
333
  ]);
295
- let y = t((e) => Se(e, {
334
+ let S = n((t) => Se(t, {
296
335
  objectSchema: o,
297
- objectName: n.objectName,
298
- readOnly: n.readOnly,
299
- mode: n.mode,
336
+ objectName: e.objectName,
337
+ readOnly: e.readOnly,
338
+ mode: e.mode,
300
339
  fieldLabel: a
301
340
  }), [
302
341
  o,
303
- n.readOnly,
304
- n.mode,
305
- n.objectName,
342
+ e.readOnly,
343
+ e.mode,
344
+ e.objectName,
306
345
  a
307
- ]), b = t(async (e) => {
308
- if (!r) return n.onSuccess && await n.onSuccess(e), e;
346
+ ]), C = n(async (t) => {
347
+ if (!r) return e.onSuccess && await e.onSuccess(t), t;
309
348
  try {
310
- let t;
311
- return n.mode === "create" ? t = await r.create(n.objectName, e) : n.mode === "edit" && n.recordId && (t = await r.update(n.objectName, n.recordId, e)), n.onSuccess && await n.onSuccess(t), t;
312
- } catch (e) {
313
- throw n.onError && n.onError(e), e;
349
+ let n;
350
+ if (e.mode === "create") n = await r.create(e.objectName, t);
351
+ else if (e.mode === "edit" && e.recordId) {
352
+ let i = await f({
353
+ dataSource: r,
354
+ objectName: e.objectName,
355
+ recordId: e.recordId,
356
+ payload: t,
357
+ baseRecord: u
358
+ });
359
+ if (i.status === "cancelled") return;
360
+ n = i.result;
361
+ }
362
+ return e.onSuccess && await e.onSuccess(n), n;
363
+ } catch (t) {
364
+ throw e.onError && e.onError(t), t;
314
365
  }
315
- }, [n, r]), x = t(() => {
316
- n.onCancel && n.onCancel();
317
- }, [n]), S = (e, t) => e.name || e.label || `tab-${t}`;
318
- if (m) return /* @__PURE__ */ Z("div", {
366
+ }, [
367
+ e,
368
+ r,
369
+ f,
370
+ u
371
+ ]), w = n(() => {
372
+ e.onCancel && e.onCancel();
373
+ }, [e]), T = (e, t) => e.name || e.label || `tab-${t}`;
374
+ if (_) return /* @__PURE__ */ Q("div", {
319
375
  className: "p-4 border border-red-300 bg-red-50 rounded-md",
320
- children: [/* @__PURE__ */ X("h3", {
376
+ children: [/* @__PURE__ */ Z("h3", {
321
377
  className: "text-red-800 font-semibold",
322
378
  children: "Error loading form"
323
- }), /* @__PURE__ */ X("p", {
379
+ }), /* @__PURE__ */ Z("p", {
324
380
  className: "text-red-600 text-sm mt-1",
325
- children: m.message
381
+ children: _.message
326
382
  })]
327
383
  });
328
- if (f) return /* @__PURE__ */ Z("div", {
384
+ if (h) return /* @__PURE__ */ Q("div", {
329
385
  className: "p-8 text-center",
330
- children: [/* @__PURE__ */ X("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ X("p", {
386
+ children: [/* @__PURE__ */ Z("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ Z("p", {
331
387
  className: "mt-2 text-sm text-gray-600",
332
388
  children: "Loading form..."
333
389
  })]
334
390
  });
335
- let C = {
336
- type: "form",
337
- fields: n.sections.flatMap((e) => y(e)),
338
- layout: "vertical",
339
- defaultValues: l,
340
- submitLabel: n.submitText || (n.mode === "create" ? "Create" : "Update"),
341
- cancelLabel: n.cancelText,
342
- showSubmit: n.showSubmit !== !1 && n.mode !== "view",
343
- showCancel: n.showCancel !== !1,
344
- onSubmit: b,
345
- onCancel: x
346
- }, w = n.tabPosition === "left" || n.tabPosition === "right";
347
- return /* @__PURE__ */ X("div", {
348
- className: G("w-full", i, n.className),
349
- children: /* @__PURE__ */ Z(ie, {
350
- value: _,
351
- onValueChange: v,
352
- orientation: w ? "vertical" : "horizontal",
353
- className: G(w && "flex gap-4"),
354
- children: [/* @__PURE__ */ X(oe, {
355
- className: G(w ? "flex-col h-auto" : "", n.tabPosition === "bottom" && "order-last", n.tabPosition === "right" && "order-last"),
356
- children: n.sections.map((e, t) => /* @__PURE__ */ X(se, {
357
- value: S(e, t),
358
- className: w ? "w-full justify-start" : "",
359
- children: e.label || `Tab ${t + 1}`
360
- }, S(e, t)))
361
- }), /* @__PURE__ */ X("div", {
362
- className: "flex-1",
363
- children: n.sections.map((e, t) => /* @__PURE__ */ X(ae, {
364
- value: S(e, t),
365
- className: "mt-0",
366
- children: /* @__PURE__ */ X($, {
367
- description: e.description,
368
- columns: 1,
369
- className: e.className,
370
- gridClassName: e.gridClassName,
371
- children: /* @__PURE__ */ X(d, { schema: {
372
- ...C,
373
- ...Re(y(e), e.columns || 1),
374
- showSubmit: n.showSubmit !== !1 && n.mode !== "view",
375
- showCancel: n.showCancel !== !1
376
- } })
377
- })
378
- }, S(e, t)))
391
+ let E = (e) => typeof e == "number" && e > 0 ? Math.min(Math.floor(e), 4) : void 0, D = e.sections.map((e) => E(e.columns)).filter((e) => e != null), O = E(e.columns) ?? (D.length ? Math.max(...D) : 1), k = Le(O), A = e.sections.map((e, t) => {
392
+ let n = S(e);
393
+ return {
394
+ key: T(e, t),
395
+ label: e.label || `Tab ${t + 1}`,
396
+ description: e.description,
397
+ containerClass: e.gridClassName,
398
+ fields: O > 1 ? je(n, O, E(e.columns)) : n
399
+ };
400
+ }), j = A.flatMap((e) => e.fields);
401
+ return /* @__PURE__ */ Q("div", {
402
+ className: q("w-full @container", i, e.className),
403
+ children: [/* @__PURE__ */ Z(m, { schema: {
404
+ type: "form",
405
+ objectName: e.objectName,
406
+ fields: j,
407
+ columns: O,
408
+ ...k ? { fieldContainerClass: k } : {},
409
+ layout: "vertical",
410
+ defaultValues: u,
411
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
412
+ cancelLabel: e.cancelText,
413
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
414
+ showCancel: e.showCancel !== !1,
415
+ onSubmit: C,
416
+ onCancel: w,
417
+ fieldTabs: A.map((e) => ({
418
+ key: e.key,
419
+ label: e.label,
420
+ description: e.description,
421
+ fields: e.fields.map((e) => e.name),
422
+ containerClass: e.containerClass
423
+ })),
424
+ defaultFieldTab: b,
425
+ fieldTabsPosition: e.tabPosition || "top"
426
+ } }), p]
427
+ });
428
+ }, Ke = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, columns: i = 1, children: a, className: o, gridClassName: s, showBorder: l }) => {
429
+ let [u, d] = c(r), f = {
430
+ 1: "grid-cols-1",
431
+ 2: "grid-cols-1 md:grid-cols-2",
432
+ 3: "grid-cols-1 md:grid-cols-2 lg:grid-cols-3",
433
+ 4: "grid-cols-1 md:grid-cols-2 lg:grid-cols-4"
434
+ }, p = () => {
435
+ n && d(!u);
436
+ }, m = l ?? !!e, h = e || t ? /* @__PURE__ */ Q("div", {
437
+ className: q("flex items-start gap-2", !m && "mb-4", n && "cursor-pointer select-none"),
438
+ onClick: p,
439
+ role: n ? "button" : void 0,
440
+ "aria-expanded": n ? !u : void 0,
441
+ children: [n && /* @__PURE__ */ Z("span", {
442
+ className: "mt-0.5 text-muted-foreground",
443
+ children: Z(u ? X : ce, { className: "h-4 w-4" })
444
+ }), /* @__PURE__ */ Q("div", {
445
+ className: "flex-1",
446
+ children: [e && /* @__PURE__ */ Z("h3", {
447
+ className: "text-sm font-semibold text-foreground",
448
+ children: e
449
+ }), t && /* @__PURE__ */ Z("p", {
450
+ className: "text-sm text-muted-foreground mt-0.5",
451
+ children: t
379
452
  })]
380
- })
453
+ })]
454
+ }) : null, g = u ? null : /* @__PURE__ */ Z("div", {
455
+ className: q("grid gap-4", s || f[i]),
456
+ children: a
381
457
  });
382
- }, He = ({ schema: n, dataSource: r, className: i }) => {
383
- let { fieldLabel: o } = h(), [c, l] = s(null), [u, f] = s({}), [p, m] = s(!0), [g, _] = s(null), [v, y] = s(0), [b, x] = s(/* @__PURE__ */ new Set()), [S, C] = s(!1), [w, T] = s(null), E = e.useId(), [D, O] = s(0), A = e.useRef(!1), j = n.sections.length, M = v === 0, N = v === j - 1;
384
- e.useEffect(() => {
458
+ return m ? /* @__PURE__ */ Q(N, {
459
+ className: q("form-section bg-muted/40 shadow-none", o),
460
+ children: [h && /* @__PURE__ */ Z(I, {
461
+ className: "border-b border-border pb-3",
462
+ children: h
463
+ }), g && /* @__PURE__ */ Z(P, {
464
+ className: "pt-4",
465
+ children: g
466
+ })]
467
+ }) : /* @__PURE__ */ Q("div", {
468
+ className: q("form-section", o),
469
+ children: [h, g]
470
+ });
471
+ }, qe = pe({ "wizard.missingRequired": "Please complete the required fields: {{fields}}" }, "wizard.missingRequired"), Je = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0, Ye = ({ schema: e, dataSource: r, className: i }) => {
472
+ let { fieldLabel: a } = v(), { t: s } = qe(), [l, d] = c(null), [p, h] = c({}), { saveWithOcc: g, conflictDialog: _ } = We(), [y, b] = c(!0), [x, S] = c(null), [C, w] = c(0), [T, E] = c(/* @__PURE__ */ new Set()), [D, O] = c(!1), [k, A] = c(/* @__PURE__ */ new Set()), [j, N] = c(null), P = t.useId(), [F, I] = c(0), L = t.useRef(!1), R = e.sections.length, z = C === 0, B = C === R - 1;
473
+ t.useEffect(() => {
385
474
  (async () => {
386
475
  if (!r) {
387
- m(!1);
476
+ b(!1);
388
477
  return;
389
478
  }
390
479
  try {
391
- let e = await r.getObjectSchema(n.objectName);
392
- l(e);
480
+ let t = await r.getObjectSchema(e.objectName);
481
+ d(t);
393
482
  } catch (e) {
394
- _(e);
483
+ S(e);
395
484
  }
396
485
  })();
397
- }, [n.objectName, r]), e.useEffect(() => {
398
- (c || !r) && (async () => {
399
- if (n.mode === "create" || !n.recordId || !r) {
400
- A.current ||= (f(n.initialData || n.initialValues || {}), !0), m(!1);
486
+ }, [e.objectName, r]), t.useEffect(() => {
487
+ (l || !r) && (async () => {
488
+ if (e.mode === "create" || !e.recordId || !r) {
489
+ L.current ||= (h(e.initialData || e.initialValues || {}), !0), b(!1);
401
490
  return;
402
491
  }
403
492
  try {
404
- let e = await r.findOne(n.objectName, n.recordId);
405
- f(e || {});
493
+ let t = await r.findOne(e.objectName, e.recordId);
494
+ h(t || {});
406
495
  } catch (e) {
407
- _(e);
496
+ S(e);
408
497
  } finally {
409
- m(!1);
498
+ b(!1);
410
499
  }
411
500
  })();
412
501
  }, [
413
- c,
414
- n.mode,
415
- n.recordId,
416
- n.initialData,
417
- n.initialValues,
502
+ l,
503
+ e.mode,
504
+ e.recordId,
505
+ e.initialData,
506
+ e.initialValues,
418
507
  r,
419
- n.objectName
508
+ e.objectName
420
509
  ]);
421
- let P = t((e) => Se(e, {
422
- objectSchema: c,
423
- objectName: n.objectName,
424
- readOnly: n.readOnly,
425
- mode: n.mode,
426
- fieldLabel: o
510
+ let V = n((t) => Se(t, {
511
+ objectSchema: l,
512
+ objectName: e.objectName,
513
+ readOnly: e.readOnly,
514
+ mode: e.mode,
515
+ fieldLabel: a
427
516
  }), [
428
- c,
429
- n.readOnly,
430
- n.mode,
431
- n.objectName,
432
- o
433
- ]), F = a(() => v >= 0 && v < j ? P(n.sections[v]) : [], [
434
- v,
435
- j,
436
- n.sections,
437
- P
438
- ]), I = t(async (e) => {
439
- let t = {
440
- ...u,
441
- ...e
517
+ l,
518
+ e.readOnly,
519
+ e.mode,
520
+ e.objectName,
521
+ a
522
+ ]), H = o(() => C >= 0 && C < R ? V(e.sections[C]) : [], [
523
+ C,
524
+ R,
525
+ e.sections,
526
+ V
527
+ ]), ee = n((t) => {
528
+ let n = /* @__PURE__ */ new Map();
529
+ return e.sections.forEach((e, r) => {
530
+ for (let i of V(e)) {
531
+ let e = i?.name;
532
+ if (!e || i.hidden === !0) continue;
533
+ let a = f({
534
+ visibleWhen: i.visibleWhen,
535
+ readonlyWhen: i.readonlyWhen,
536
+ requiredWhen: i.requiredWhen
537
+ }, t, {
538
+ required: !!i.required,
539
+ readonly: i.readonly === !0
540
+ });
541
+ !(i.visibleOn == null || u(i.visibleOn, t, !0)) || !a.visible || a.readonly || !a.required || Je(t[e]) && n.set(r, [...n.get(r) ?? [], i.label || e]);
542
+ }
543
+ }), n;
544
+ }, [e.sections, V]), U = n(async (t) => {
545
+ let n = {
546
+ ...p,
547
+ ...t
442
548
  };
443
- if (f(t), x((e) => new Set(e).add(v)), N) {
444
- C(!0);
549
+ if (h(n), E((e) => new Set(e).add(C)), A((e) => {
550
+ if (!e.has(C)) return e;
551
+ let t = new Set(e);
552
+ return t.delete(C), t;
553
+ }), B) {
554
+ let t = ee(n);
555
+ if (t.size > 0) {
556
+ A(new Set(t.keys()));
557
+ let e = [...t.values()].flat();
558
+ J.error(s("wizard.missingRequired", { fields: e.slice(0, 3).join(", ") + (e.length > 3 ? "…" : "") })), W(Math.min(...t.keys()));
559
+ return;
560
+ }
561
+ A(/* @__PURE__ */ new Set()), O(!0);
445
562
  try {
446
- if (!r) return n.onSuccess && await n.onSuccess(t), t;
447
- let e;
448
- if (n.mode === "create" ? e = await r.create(n.objectName, t) : n.mode === "edit" && n.recordId && (e = await r.update(n.objectName, n.recordId, t)), n.onSuccess) await n.onSuccess(e);
449
- else if (n.submitBehavior) {
450
- let e = n.submitBehavior;
451
- switch (e.kind) {
563
+ if (!r) return e.onSuccess && await e.onSuccess(n), n;
564
+ let t;
565
+ if (e.mode === "create") t = await r.create(e.objectName, n);
566
+ else if (e.mode === "edit" && e.recordId) {
567
+ let i = await g({
568
+ dataSource: r,
569
+ objectName: e.objectName,
570
+ recordId: e.recordId,
571
+ payload: n,
572
+ baseRecord: p
573
+ });
574
+ if (i.status === "cancelled") return;
575
+ t = i.result;
576
+ }
577
+ if (e.onSuccess) await e.onSuccess(t);
578
+ else if (e.submitBehavior) {
579
+ let t = e.submitBehavior;
580
+ switch (t.kind) {
452
581
  case "redirect":
453
- Q(e.url) && setTimeout(() => window.location.assign(e.url), e.delayMs ?? 0);
582
+ $(t.url) && setTimeout(() => window.location.assign(t.url), t.delayMs ?? 0);
454
583
  break;
455
584
  case "continue":
456
- f({}), x(/* @__PURE__ */ new Set()), y(0), O((e) => e + 1);
585
+ h({}), E(/* @__PURE__ */ new Set()), w(0), I((e) => e + 1);
457
586
  break;
458
587
  default: {
459
- let t = e.kind === "thank-you" && e.message ? e.message : n.successMessage || (n.mode === "create" ? "Created" : "Saved");
460
- K.success(t), T({
461
- title: e.kind === "thank-you" ? e.title : void 0,
462
- message: t
588
+ let n = t.kind === "thank-you" && t.message ? t.message : e.successMessage || (e.mode === "create" ? "Created" : "Saved");
589
+ J.success(n), N({
590
+ title: t.kind === "thank-you" ? t.title : void 0,
591
+ message: n
463
592
  });
464
593
  break;
465
594
  }
466
595
  }
467
596
  } else {
468
- let t = ve(n.navigateOnSuccess, e);
469
- if (t) return window.location.assign(t), e;
470
- K.success(n.successMessage || (n.mode === "create" ? "Created" : "Saved")), n.resetOnSuccess && n.mode === "create" && (f({}), x(/* @__PURE__ */ new Set()), y(0), O((e) => e + 1));
597
+ let n = ge(e.navigateOnSuccess, t);
598
+ if (n) return window.location.assign(n), t;
599
+ J.success(e.successMessage || (e.mode === "create" ? "Created" : "Saved")), e.resetOnSuccess && e.mode === "create" && (h({}), E(/* @__PURE__ */ new Set()), w(0), I((e) => e + 1));
471
600
  }
472
- return e;
473
- } catch (e) {
474
- throw n.onError && n.onError(e), e;
601
+ return t;
602
+ } catch (t) {
603
+ throw e.onError && e.onError(t), t;
475
604
  } finally {
476
- C(!1);
605
+ O(!1);
477
606
  }
478
- } else L(v + 1);
607
+ } else W(C + 1);
479
608
  }, [
480
- u,
481
- v,
482
- N,
483
- n,
484
- r
485
- ]), L = t((e) => {
486
- e >= 0 && e < j && (y(e), n.onStepChange && n.onStepChange(e));
487
- }, [j, n]), ee = t(() => {
488
- L(v - 1);
489
- }, [v, L]), R = t(() => {
490
- n.onCancel && n.onCancel();
491
- }, [n]), z = t((e) => {
492
- (n.allowSkip || b.has(e) || e <= v) && L(e);
609
+ p,
610
+ C,
611
+ B,
612
+ e,
613
+ r,
614
+ ee,
615
+ s,
616
+ g
617
+ ]), W = n((t) => {
618
+ t >= 0 && t < R && (w(t), e.onStepChange && e.onStepChange(t));
619
+ }, [R, e]), G = n(() => {
620
+ W(C - 1);
621
+ }, [C, W]), te = n(() => {
622
+ e.onCancel && e.onCancel();
623
+ }, [e]), ne = n((t) => {
624
+ (e.allowSkip || T.has(t) || t <= C) && W(t);
493
625
  }, [
494
- n.allowSkip,
495
- b,
496
- v,
497
- L
626
+ e.allowSkip,
627
+ T,
628
+ C,
629
+ W
498
630
  ]);
499
- if (g) return /* @__PURE__ */ Z("div", {
631
+ if (x) return /* @__PURE__ */ Q("div", {
500
632
  className: "p-4 border border-red-300 bg-red-50 rounded-md",
501
- children: [/* @__PURE__ */ X("h3", {
633
+ children: [/* @__PURE__ */ Z("h3", {
502
634
  className: "text-red-800 font-semibold",
503
635
  children: "Error loading form"
504
- }), /* @__PURE__ */ X("p", {
636
+ }), /* @__PURE__ */ Z("p", {
505
637
  className: "text-red-600 text-sm mt-1",
506
- children: g.message
638
+ children: x.message
507
639
  })]
508
640
  });
509
- if (p) return /* @__PURE__ */ Z("div", {
641
+ if (y) return /* @__PURE__ */ Q("div", {
510
642
  className: "p-8 text-center",
511
- children: [/* @__PURE__ */ X("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ X("p", {
643
+ children: [/* @__PURE__ */ Z("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ Z("p", {
512
644
  className: "mt-2 text-sm text-gray-600",
513
645
  children: "Loading form..."
514
646
  })]
515
647
  });
516
- if (w) return /* @__PURE__ */ X("div", {
517
- className: G("w-full", i, n.className),
518
- children: /* @__PURE__ */ Z("div", {
648
+ if (j) return /* @__PURE__ */ Z("div", {
649
+ className: q("w-full", i, e.className),
650
+ children: /* @__PURE__ */ Q("div", {
519
651
  className: "rounded-md border bg-card p-8 text-center",
520
- children: [/* @__PURE__ */ X("h3", {
652
+ children: [/* @__PURE__ */ Z("h3", {
521
653
  className: "text-lg font-semibold",
522
- children: w.title ?? "Thanks!"
523
- }), w.message && /* @__PURE__ */ X("p", {
654
+ children: j.title ?? "Thanks!"
655
+ }), j.message && /* @__PURE__ */ Z("p", {
524
656
  className: "mt-2 text-sm text-muted-foreground",
525
- children: w.message
657
+ children: j.message
526
658
  })]
527
659
  })
528
660
  });
529
- let B = n.sections[v];
530
- return /* @__PURE__ */ Z("div", {
531
- className: G("w-full", i, n.className),
661
+ let K = e.sections[C], re = (e) => typeof e == "number" && e > 0 ? Math.min(Math.floor(e), 4) : void 0, Y = re(e.columns) ?? re(K?.columns) ?? 1, ae = Le(Y);
662
+ return /* @__PURE__ */ Q("div", {
663
+ className: q("w-full @container", i, e.className),
532
664
  children: [
533
- n.showStepIndicator !== !1 && /* @__PURE__ */ X("nav", {
665
+ e.showStepIndicator !== !1 && /* @__PURE__ */ Z("nav", {
534
666
  "aria-label": "Progress",
535
667
  className: "mb-8",
536
- children: /* @__PURE__ */ X("ol", {
668
+ children: /* @__PURE__ */ Z("ol", {
537
669
  className: "flex items-center",
538
- children: n.sections.map((e, t) => {
539
- let r = t === v, i = b.has(t), a = n.allowSkip || i || t <= v;
540
- return /* @__PURE__ */ Z("li", {
541
- className: G("relative flex-1", t !== j - 1 && "pr-8 sm:pr-12"),
542
- children: [t !== j - 1 && /* @__PURE__ */ X("div", {
670
+ children: e.sections.map((t, n) => {
671
+ let r = n === C, i = T.has(n), a = e.allowSkip || i || n <= C, o = k.has(n);
672
+ return /* @__PURE__ */ Q("li", {
673
+ className: q("relative flex-1", n !== R - 1 && "pr-8 sm:pr-12"),
674
+ children: [n !== R - 1 && /* @__PURE__ */ Z("div", {
543
675
  className: "absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5",
544
676
  "aria-hidden": "true",
545
- children: /* @__PURE__ */ X("div", { className: G("h-full", i ? "bg-primary" : "bg-muted") })
546
- }), /* @__PURE__ */ Z("button", {
677
+ children: /* @__PURE__ */ Z("div", { className: q("h-full", i ? "bg-primary" : "bg-muted") })
678
+ }), /* @__PURE__ */ Q("button", {
547
679
  type: "button",
548
- className: G("group relative flex items-center", a ? "cursor-pointer" : "cursor-not-allowed"),
549
- onClick: () => z(t),
680
+ className: q("group relative flex items-center", a ? "cursor-pointer" : "cursor-not-allowed"),
681
+ onClick: () => ne(n),
550
682
  disabled: !a,
551
- children: [/* @__PURE__ */ X("span", {
552
- className: G("flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors", i && "bg-primary text-primary-foreground", r && !i && "border-2 border-primary bg-background text-primary", !r && !i && "border-2 border-muted bg-background text-muted-foreground"),
553
- children: i ? /* @__PURE__ */ X(q, { className: "h-3 w-3 sm:h-4 sm:w-4" }) : t + 1
554
- }), /* @__PURE__ */ X("span", {
683
+ "data-testid": `wizard-step:${t.name || n}`,
684
+ "data-error": o || void 0,
685
+ children: [/* @__PURE__ */ Z("span", {
686
+ className: q("flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors", o && "border-2 border-destructive bg-background text-destructive", !o && i && "bg-primary text-primary-foreground", !o && r && !i && "border-2 border-primary bg-background text-primary", !o && !r && !i && "border-2 border-muted bg-background text-muted-foreground"),
687
+ children: o ? /* @__PURE__ */ Z(ie, {
688
+ className: "h-3 w-3 sm:h-4 sm:w-4",
689
+ "aria-hidden": !0
690
+ }) : i ? /* @__PURE__ */ Z(oe, { className: "h-3 w-3 sm:h-4 sm:w-4" }) : n + 1
691
+ }), /* @__PURE__ */ Z("span", {
555
692
  className: "ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block",
556
- children: /* @__PURE__ */ X("span", {
557
- className: G(r ? "text-foreground" : "text-muted-foreground"),
558
- children: e.label || `Step ${t + 1}`
693
+ children: /* @__PURE__ */ Z("span", {
694
+ className: q(o ? "text-destructive" : r ? "text-foreground" : "text-muted-foreground"),
695
+ children: t.label || `Step ${n + 1}`
559
696
  })
560
697
  })]
561
698
  })]
562
- }, t);
699
+ }, n);
563
700
  })
564
701
  })
565
702
  }),
566
- /* @__PURE__ */ X("div", {
703
+ /* @__PURE__ */ Z("div", {
567
704
  className: "min-h-[200px]",
568
- children: B && /* @__PURE__ */ X($, {
569
- label: B.label,
570
- description: B.description,
705
+ children: K && /* @__PURE__ */ Z(Ke, {
706
+ label: K.label,
707
+ description: K.description,
571
708
  columns: 1,
572
- className: B.className,
573
- gridClassName: B.gridClassName,
574
- children: F.length > 0 ? /* @__PURE__ */ X(d, { schema: {
709
+ className: K.className,
710
+ gridClassName: K.gridClassName,
711
+ children: H.length > 0 ? /* @__PURE__ */ Z(m, { schema: {
575
712
  type: "form",
576
- objectName: n.objectName,
577
- id: E,
578
- ...Re(F, B.columns || 1),
713
+ objectName: e.objectName,
714
+ id: P,
715
+ fields: Y > 1 ? je(H, Y, re(K.columns)) : H,
716
+ columns: Y,
717
+ ...ae ? { fieldContainerClass: ae } : {},
579
718
  layout: "vertical",
580
- defaultValues: u,
719
+ defaultValues: p,
581
720
  showSubmit: !1,
582
721
  showCancel: !1,
583
- onSubmit: I
584
- } }, D) : /* @__PURE__ */ X("div", {
585
- className: "text-center py-8 text-muted-foreground",
586
- children: "No fields configured for this step"
722
+ onSubmit: U
723
+ } }, F) : /* @__PURE__ */ Z("form", {
724
+ id: P,
725
+ onSubmit: (e) => {
726
+ e.preventDefault(), U({});
727
+ },
728
+ children: /* @__PURE__ */ Z("div", {
729
+ className: "text-center py-8 text-muted-foreground",
730
+ children: "No fields configured for this step"
731
+ })
587
732
  })
588
733
  })
589
734
  }),
590
- /* @__PURE__ */ Z("div", {
735
+ /* @__PURE__ */ Q("div", {
591
736
  className: "flex items-center justify-between mt-6 pt-4 border-t",
592
- children: [/* @__PURE__ */ X("div", { children: n.showCancel !== !1 && /* @__PURE__ */ X(k, {
737
+ children: [/* @__PURE__ */ Z("div", { children: e.showCancel !== !1 && /* @__PURE__ */ Z(M, {
593
738
  variant: "ghost",
594
- onClick: R,
595
- children: n.cancelText || "Cancel"
596
- }) }), /* @__PURE__ */ Z("div", {
739
+ onClick: te,
740
+ children: e.cancelText || "Cancel"
741
+ }) }), /* @__PURE__ */ Q("div", {
597
742
  className: "flex items-center gap-2",
598
743
  children: [
599
- /* @__PURE__ */ Z("span", {
744
+ /* @__PURE__ */ Q("span", {
600
745
  className: "text-sm text-muted-foreground mr-2",
601
746
  children: [
602
747
  "Step ",
603
- v + 1,
748
+ C + 1,
604
749
  " of ",
605
- j
750
+ R
606
751
  ]
607
752
  }),
608
- !M && /* @__PURE__ */ Z(k, {
753
+ !z && /* @__PURE__ */ Q(M, {
609
754
  variant: "outline",
610
- onClick: ee,
611
- children: [/* @__PURE__ */ X(fe, { className: "h-4 w-4 mr-1" }), n.prevText || "Back"]
755
+ onClick: G,
756
+ children: [/* @__PURE__ */ Z(le, { className: "h-4 w-4 mr-1" }), e.prevText || "Back"]
612
757
  }),
613
- N ? /* @__PURE__ */ Z(k, {
758
+ B ? /* @__PURE__ */ Q(M, {
614
759
  type: "submit",
615
- form: E,
616
- disabled: S || n.mode === "view",
617
- children: [S && /* @__PURE__ */ X(me, {
760
+ form: P,
761
+ disabled: D || e.mode === "view",
762
+ children: [D && /* @__PURE__ */ Z(ue, {
618
763
  className: "mr-2 h-4 w-4 animate-spin",
619
764
  "aria-hidden": !0
620
- }), S ? "Submitting..." : n.submitText || (n.mode === "create" ? "Create" : "Update")]
621
- }) : /* @__PURE__ */ Z(k, {
765
+ }), D ? "Submitting..." : e.submitText || (e.mode === "create" ? "Create" : "Update")]
766
+ }) : /* @__PURE__ */ Q(M, {
622
767
  type: "submit",
623
- form: E,
624
- children: [n.nextText || "Next", /* @__PURE__ */ X(pe, { className: "h-4 w-4 ml-1" })]
768
+ form: P,
769
+ children: [e.nextText || "Next", /* @__PURE__ */ Z(X, { className: "h-4 w-4 ml-1" })]
625
770
  })
626
771
  ]
627
772
  })]
628
- })
773
+ }),
774
+ _
629
775
  ]
630
776
  });
631
- }, Ue = ({ schema: e, dataSource: n, className: i }) => {
632
- let { fieldLabel: o } = h(), [c, l] = s(null), [u, f] = s({}), [p, m] = s(!0), [g, _] = s(null);
633
- r(() => {
777
+ }, Xe = ({ schema: e, dataSource: t, className: r }) => {
778
+ let { fieldLabel: a } = v(), [l, u] = c(null), [d, f] = c({}), { saveWithOcc: p, conflictDialog: h } = We(), [g, _] = c(!0), [y, b] = c(null);
779
+ i(() => {
634
780
  (async () => {
635
- if (!n) {
636
- m(!1);
781
+ if (!t) {
782
+ _(!1);
637
783
  return;
638
784
  }
639
785
  try {
640
- let t = await n.getObjectSchema(e.objectName);
641
- l(t);
786
+ let n = await t.getObjectSchema(e.objectName);
787
+ u(n);
642
788
  } catch (e) {
643
- _(e), m(!1);
789
+ b(e), _(!1);
644
790
  }
645
791
  })();
646
- }, [e.objectName, n]), r(() => {
647
- (c || !n) && (async () => {
792
+ }, [e.objectName, t]);
793
+ let x = s(void 0);
794
+ i(() => {
795
+ let n = !1;
796
+ return (l || !t) && (async () => {
648
797
  if (e.mode === "create" || !e.recordId) {
649
- f(e.initialData || e.initialValues || {}), m(!1);
798
+ f(e.initialData || e.initialValues || {}), _(!1);
650
799
  return;
651
800
  }
652
- if (!n) {
653
- f(e.initialData || e.initialValues || {}), m(!1);
801
+ if (!t) {
802
+ f(e.initialData || e.initialValues || {}), _(!1);
654
803
  return;
655
804
  }
805
+ x.current !== e.recordId && _(!0);
656
806
  try {
657
- let t = await n.findOne(e.objectName, e.recordId);
658
- f(t || {});
807
+ let r = await t.findOne(e.objectName, e.recordId);
808
+ if (n) return;
809
+ x.current = e.recordId, f(r || {});
659
810
  } catch (e) {
660
- _(e);
811
+ if (n) return;
812
+ b(e);
661
813
  } finally {
662
- m(!1);
814
+ n || _(!1);
663
815
  }
664
- })();
816
+ })(), () => {
817
+ n = !0;
818
+ };
665
819
  }, [
666
- c,
820
+ l,
667
821
  e.mode,
668
822
  e.recordId,
669
823
  e.initialData,
670
824
  e.initialValues,
671
- n,
825
+ t,
672
826
  e.objectName
673
827
  ]);
674
- let v = t((t) => Se(t, {
675
- objectSchema: c,
828
+ let S = n((t) => Se(t, {
829
+ objectSchema: l,
676
830
  objectName: e.objectName,
677
831
  readOnly: e.readOnly,
678
832
  mode: e.mode,
679
- fieldLabel: o
833
+ fieldLabel: a
680
834
  }), [
681
- c,
835
+ l,
682
836
  e.readOnly,
683
837
  e.mode,
684
838
  e.objectName,
685
- o
686
- ]), y = t(async (t) => {
687
- if (!n) return e.onSuccess && await e.onSuccess(t), t;
839
+ a
840
+ ]), C = n(async (n) => {
841
+ if (!t) return e.onSuccess && await e.onSuccess(n), n;
688
842
  try {
689
843
  let r;
690
- return e.mode === "create" ? r = await n.create(e.objectName, t) : e.mode === "edit" && e.recordId && (r = await n.update(e.objectName, e.recordId, t)), e.onSuccess && await e.onSuccess(r), r;
844
+ if (e.mode === "create") r = await t.create(e.objectName, n);
845
+ else if (e.mode === "edit" && e.recordId) {
846
+ let i = await p({
847
+ dataSource: t,
848
+ objectName: e.objectName,
849
+ recordId: e.recordId,
850
+ payload: n,
851
+ baseRecord: d
852
+ });
853
+ if (i.status === "cancelled") return;
854
+ r = i.result;
855
+ }
856
+ return e.onSuccess && await e.onSuccess(r), r;
691
857
  } catch (t) {
692
858
  throw e.onError && e.onError(t), t;
693
859
  }
694
- }, [e, n]), b = t(() => {
860
+ }, [
861
+ e,
862
+ t,
863
+ p,
864
+ d
865
+ ]), w = n(() => {
695
866
  e.onCancel && e.onCancel();
696
- }, [e]), x = a(() => e.sections.slice(0, 1), [e.sections]), S = a(() => e.sections.slice(1), [e.sections]);
697
- a(() => e.sections.flatMap((e) => v(e)), [e.sections, v]);
698
- let C = e.splitDirection || "horizontal", w = e.splitSize || 50;
699
- if (g) return /* @__PURE__ */ Z("div", {
867
+ }, [e]), T = (e, t) => e.pane === "primary" || e.pane === "secondary" ? e.pane : t === 0 ? "primary" : "secondary", E = o(() => e.sections.filter((e, t) => T(e, t) === "primary"), [e.sections]), D = o(() => e.sections.filter((e, t) => T(e, t) === "secondary"), [e.sections]), O = e.splitDirection || "horizontal", k = e.splitSize || 50;
868
+ if (y) return /* @__PURE__ */ Q("div", {
700
869
  className: "p-4 border border-red-300 bg-red-50 rounded-md",
701
- children: [/* @__PURE__ */ X("h3", {
870
+ children: [/* @__PURE__ */ Z("h3", {
702
871
  className: "text-red-800 font-semibold",
703
872
  children: "Error loading form"
704
- }), /* @__PURE__ */ X("p", {
873
+ }), /* @__PURE__ */ Z("p", {
705
874
  className: "text-red-600 text-sm mt-1",
706
- children: g.message
875
+ children: y.message
707
876
  })]
708
877
  });
709
- if (p) return /* @__PURE__ */ Z("div", {
878
+ if (g) return /* @__PURE__ */ Q("div", {
710
879
  className: "p-8 text-center",
711
- children: [/* @__PURE__ */ X("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ X("p", {
880
+ children: [/* @__PURE__ */ Z("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ Z("p", {
712
881
  className: "mt-2 text-sm text-gray-600",
713
882
  children: "Loading form..."
714
883
  })]
715
884
  });
716
- let T = {
717
- type: "form",
718
- objectName: e.objectName,
719
- layout: "vertical",
720
- defaultValues: u,
721
- onSubmit: y,
722
- onCancel: b
723
- }, E = (t, n) => /* @__PURE__ */ X("div", {
724
- className: "space-y-6 p-4",
725
- children: t.map((t, r) => /* @__PURE__ */ X($, {
726
- label: t.label,
727
- description: t.description,
728
- columns: 1,
729
- className: t.className,
730
- gridClassName: t.gridClassName,
731
- children: /* @__PURE__ */ X(d, { schema: {
732
- ...T,
733
- ...Re(v(t), t.columns || 1),
734
- showSubmit: n && e.showSubmit !== !1 && e.mode !== "view",
735
- showCancel: n && e.showCancel !== !1,
736
- submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
737
- cancelLabel: e.cancelText
738
- } })
739
- }, t.name || t.label || r))
740
- });
741
- return /* @__PURE__ */ X("div", {
742
- className: G("w-full", i, e.className),
743
- children: /* @__PURE__ */ Z(V, {
744
- orientation: C,
745
- className: "min-h-[300px] rounded-lg border",
746
- children: [/* @__PURE__ */ X(B, {
747
- defaultSize: w,
748
- minSize: 20,
749
- children: E(x, S.length === 0)
750
- }), S.length > 0 && /* @__PURE__ */ Z(he, { children: [/* @__PURE__ */ X(z, { withHandle: e.splitResizable !== !1 }), /* @__PURE__ */ X(B, {
751
- defaultSize: 100 - w,
752
- minSize: 20,
753
- children: E(S, !0)
754
- })] })]
755
- })
885
+ let A = (e) => typeof e == "number" && e > 0 ? Math.min(Math.floor(e), 4) : void 0, j = e.sections.map((e) => A(e.columns)).filter((e) => e != null), M = A(e.columns) ?? (j.length ? Math.max(...j) : 1), N = Le(M), P = (e, t) => {
886
+ let n = [];
887
+ return e.forEach((e, r) => {
888
+ let i = S(e);
889
+ i.length && ((e.label || e.description) && n.push({
890
+ name: `__section_${e.name || `${t}_${r}`}`,
891
+ label: e.label,
892
+ description: e.description,
893
+ type: "section-divider",
894
+ colSpan: 4,
895
+ className: e.className
896
+ }), n.push(...M > 1 ? je(i, M, A(e.columns)) : i));
897
+ }), n;
898
+ }, F = [{
899
+ key: "primary",
900
+ sections: E,
901
+ defaultSize: k
902
+ }, {
903
+ key: "secondary",
904
+ sections: D,
905
+ defaultSize: 100 - k
906
+ }].map((e) => ({
907
+ ...e,
908
+ fields: P(e.sections, e.key),
909
+ containerClass: e.sections.length === 1 ? e.sections[0].gridClassName : void 0
910
+ })).filter((e) => e.fields.length > 0);
911
+ return /* @__PURE__ */ Q("div", {
912
+ className: q("w-full @container", r, e.className),
913
+ children: [/* @__PURE__ */ Z(m, { schema: {
914
+ type: "form",
915
+ objectName: e.objectName,
916
+ fields: F.flatMap((e) => e.fields),
917
+ columns: M,
918
+ ...N ? { fieldContainerClass: N } : {},
919
+ layout: "vertical",
920
+ defaultValues: d,
921
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
922
+ cancelLabel: e.cancelText,
923
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
924
+ showCancel: e.showCancel !== !1,
925
+ onSubmit: C,
926
+ onCancel: w,
927
+ fieldPanes: F.map((e) => ({
928
+ key: e.key,
929
+ fields: e.fields.map((e) => e.name),
930
+ defaultSize: e.defaultSize,
931
+ ...e.containerClass ? { containerClass: e.containerClass } : {}
932
+ })),
933
+ fieldPanesOrientation: O,
934
+ fieldPanesResizable: e.splitResizable !== !1
935
+ } }), h]
756
936
  });
757
- }, We = /* @__PURE__ */ new Set([
937
+ }, Ze = /* @__PURE__ */ new Set([
758
938
  "id",
759
939
  "_id",
760
940
  "created_at",
@@ -763,7 +943,7 @@ var Ve = ({ schema: n, dataSource: r, className: i }) => {
763
943
  "updatedAt",
764
944
  "organization_id",
765
945
  "organizationId"
766
- ]), Ge = /* @__PURE__ */ new Set([
946
+ ]), Qe = /* @__PURE__ */ new Set([
767
947
  "formula",
768
948
  "summary",
769
949
  "rollup",
@@ -772,15 +952,15 @@ var Ve = ({ schema: n, dataSource: r, className: i }) => {
772
952
  "autonumber",
773
953
  "computed"
774
954
  ]);
775
- function Ke(e, t) {
955
+ function $e(e, t) {
776
956
  if (!e || typeof e != "object") return e;
777
957
  let n = {}, r = t?.fields;
778
- for (let [t, i] of Object.entries(e)) if (!We.has(t)) {
958
+ for (let [t, i] of Object.entries(e)) if (!Ze.has(t)) {
779
959
  if (r) {
780
960
  let e = r[t];
781
961
  if (!e) continue;
782
962
  let n = String(e.type || "").toLowerCase();
783
- if (Ge.has(n) || e.computed === !0 || e.formula || e.readOnly === !0 || e.readonly === !0) continue;
963
+ if (Qe.has(n) || e.computed === !0 || e.formula || e.readOnly === !0 || e.readonly === !0) continue;
784
964
  }
785
965
  n[t] = i;
786
966
  }
@@ -788,31 +968,31 @@ function Ke(e, t) {
788
968
  }
789
969
  //#endregion
790
970
  //#region src/masterDetailTx.ts
791
- var qe = (e) => e == null ? void 0 : e.id ?? e._id ?? e.recordId, Je = (e, t) => t ? Ke(e, t) : e, Ye = /* @__PURE__ */ new Set([
971
+ var et = (e) => e == null ? void 0 : e.id ?? e._id ?? e.recordId, tt = (e, t) => t ? $e(e, t) : e, nt = /* @__PURE__ */ new Set([
792
972
  "id",
793
973
  "_id",
794
974
  "recordId"
795
975
  ]);
796
- function Xe(e, t) {
797
- return !e || Object.entries(e).every(([e, n]) => e === t || Ye.has(e) ? !0 : n == null || n === "");
976
+ function rt(e, t) {
977
+ return !e || Object.entries(e).every(([e, n]) => e === t || nt.has(e) ? !0 : n == null || n === "");
798
978
  }
799
- function Ze(e, t, n) {
979
+ function it(e, t, n) {
800
980
  let r = [{
801
981
  object: e,
802
982
  action: "create",
803
983
  data: t
804
984
  }];
805
- for (let e of n) for (let t of e.rows) Xe(t, e.relationshipField) || r.push({
985
+ for (let e of n) for (let t of e.rows) rt(t, e.relationshipField) || r.push({
806
986
  object: e.childObject,
807
987
  action: "create",
808
988
  data: {
809
- ...Je(t, e.childSchema),
989
+ ...tt(t, e.childSchema),
810
990
  [e.relationshipField]: { $ref: 0 }
811
991
  }
812
992
  });
813
993
  return r;
814
994
  }
815
- function Qe(e, t, n, r) {
995
+ function at(e, t, n, r) {
816
996
  let i = [{
817
997
  object: e,
818
998
  action: "update",
@@ -823,21 +1003,21 @@ function Qe(e, t, n, r) {
823
1003
  let n = (e.rows || []).map((n) => ({
824
1004
  ...n,
825
1005
  [e.relationshipField]: t
826
- })), { toCreate: r, toUpdate: a, toDelete: o } = $e(e.original || [], n);
1006
+ })), { toCreate: r, toUpdate: a, toDelete: o } = ot(e.original || [], n);
827
1007
  for (let t of r) {
828
- if (Xe(t, e.relationshipField)) continue;
1008
+ if (rt(t, e.relationshipField)) continue;
829
1009
  let { id: n, _id: r, recordId: a, ...o } = t;
830
1010
  i.push({
831
1011
  object: e.childObject,
832
1012
  action: "create",
833
- data: Je(o, e.childSchema)
1013
+ data: tt(o, e.childSchema)
834
1014
  });
835
1015
  }
836
1016
  for (let t of a) i.push({
837
1017
  object: e.childObject,
838
1018
  action: "update",
839
- id: qe(t),
840
- data: Je(t, e.childSchema)
1019
+ id: et(t),
1020
+ data: tt(t, e.childSchema)
841
1021
  });
842
1022
  for (let t of o) i.push({
843
1023
  object: e.childObject,
@@ -847,15 +1027,15 @@ function Qe(e, t, n, r) {
847
1027
  }
848
1028
  return i;
849
1029
  }
850
- function $e(e, t) {
851
- let n = new Set(t.map(qe).filter(Boolean));
1030
+ function ot(e, t) {
1031
+ let n = new Set(t.map(et).filter(Boolean));
852
1032
  return {
853
- toCreate: t.filter((e) => !qe(e)),
854
- toUpdate: t.filter((e) => qe(e)),
855
- toDelete: (e || []).map(qe).filter((e) => !!e && !n.has(e))
1033
+ toCreate: t.filter((e) => !et(e)),
1034
+ toUpdate: t.filter((e) => et(e)),
1035
+ toDelete: (e || []).map(et).filter((e) => !!e && !n.has(e))
856
1036
  };
857
1037
  }
858
- function et(e, t) {
1038
+ function st(e, t) {
859
1039
  return Array.isArray(e) ? e.reduce((e, n) => {
860
1040
  let r = Number(n?.[t]);
861
1041
  return e + (Number.isFinite(r) ? r : 0);
@@ -863,7 +1043,7 @@ function et(e, t) {
863
1043
  }
864
1044
  //#endregion
865
1045
  //#region src/deriveMasterDetail.ts
866
- var tt = /* @__PURE__ */ new Set([
1046
+ var ct = /* @__PURE__ */ new Set([
867
1047
  "id",
868
1048
  "_id",
869
1049
  "recordId",
@@ -879,14 +1059,14 @@ var tt = /* @__PURE__ */ new Set([
879
1059
  "tenant_id",
880
1060
  "space",
881
1061
  "owner"
882
- ]), nt = /* @__PURE__ */ new Set([
1062
+ ]), lt = /* @__PURE__ */ new Set([
883
1063
  "position",
884
1064
  "sort_order",
885
1065
  "sequence",
886
1066
  "line_no",
887
1067
  "line_number",
888
1068
  "sort"
889
- ]), rt = /* @__PURE__ */ new Set([
1069
+ ]), ut = /* @__PURE__ */ new Set([
890
1070
  "formula",
891
1071
  "summary",
892
1072
  "rollup",
@@ -902,7 +1082,7 @@ var tt = /* @__PURE__ */ new Set([
902
1082
  "markdown",
903
1083
  "richtext"
904
1084
  ]);
905
- function it(e) {
1085
+ function dt(e) {
906
1086
  switch (e) {
907
1087
  case "number":
908
1088
  case "percent":
@@ -925,11 +1105,11 @@ function it(e) {
925
1105
  default: return "text";
926
1106
  }
927
1107
  }
928
- var at = /* @__PURE__ */ new Set(["image", "avatar"]);
929
- function ot(e, t) {
930
- e.multiple == null && t?.multiple && (e.multiple = !0), e.accept ?? (Array.isArray(t?.accept) && t.accept.length > 0 ? e.accept = t.accept : at.has(t?.type) && (e.accept = ["image/*"]));
1108
+ var ft = /* @__PURE__ */ new Set(["image", "avatar"]);
1109
+ function pt(e, t) {
1110
+ e.multiple == null && t?.multiple && (e.multiple = !0), e.accept ?? (Array.isArray(t?.accept) && t.accept.length > 0 ? e.accept = t.accept : ft.has(t?.type) && (e.accept = ["image/*"]));
931
1111
  }
932
- function st(e) {
1112
+ function mt(e) {
933
1113
  if (e?.type === "boolean" || e?.type === "toggle") return [{
934
1114
  label: "Yes",
935
1115
  value: "true"
@@ -946,7 +1126,7 @@ function st(e) {
946
1126
  value: String(e)
947
1127
  });
948
1128
  }
949
- function ct(e, t) {
1129
+ function ht(e, t) {
950
1130
  let n = e?.fields;
951
1131
  if (!n || typeof n != "object") return;
952
1132
  let r;
@@ -959,7 +1139,7 @@ function ct(e, t) {
959
1139
  }
960
1140
  return r;
961
1141
  }
962
- var lt = [
1142
+ var gt = [
963
1143
  "name",
964
1144
  "title",
965
1145
  "subject",
@@ -967,7 +1147,7 @@ var lt = [
967
1147
  "full_name",
968
1148
  "display_name",
969
1149
  "code"
970
- ], ut = {
1150
+ ], _t = {
971
1151
  select: 0,
972
1152
  currency: 1,
973
1153
  number: 1,
@@ -975,15 +1155,18 @@ var lt = [
975
1155
  date: 3,
976
1156
  text: 4
977
1157
  };
978
- function dt(e, t) {
1158
+ function vt(e) {
1159
+ return (e.type ? _t[e.type] : void 0) ?? 5;
1160
+ }
1161
+ function yt(e, t) {
979
1162
  if (t <= 0 || e.length <= t) return e;
980
- let n = /* @__PURE__ */ new Set(), r = e.find((e) => lt.includes(e.field)) ?? e[0];
1163
+ let n = /* @__PURE__ */ new Set(), r = e.find((e) => gt.includes(e.field)) ?? e[0];
981
1164
  r && n.add(r.field);
982
1165
  for (let t of e) t.required && n.add(t.field);
983
1166
  let i = e.map((e, t) => ({
984
1167
  c: e,
985
1168
  i: t
986
- })).filter(({ c: e }) => !n.has(e.field)).sort((e, t) => (ut[e.c.type] ?? 5) - (ut[t.c.type] ?? 5) || e.i - t.i);
1169
+ })).filter(({ c: e }) => !n.has(e.field)).sort((e, t) => vt(e.c) - vt(t.c) || e.i - t.i);
987
1170
  for (let { c: e } of i) {
988
1171
  if (n.size >= t) break;
989
1172
  n.add(e.field);
@@ -993,60 +1176,60 @@ function dt(e, t) {
993
1176
  defaultHidden: !0
994
1177
  });
995
1178
  }
996
- function ft(e, t = {}) {
1179
+ function bt(e, t = {}) {
997
1180
  let n = e?.fields;
998
1181
  if (!n || typeof n != "object") return [];
999
1182
  let r = /* @__PURE__ */ new Set([...t.exclude ?? [], ...t.relationshipField ? [t.relationshipField] : []]), i = [];
1000
1183
  for (let [e, t] of Object.entries(n)) {
1001
1184
  let n = t;
1002
- if (tt.has(e) || r.has(e) || nt.has(e) || n?.system || n?.readonly || n?.hidden || rt.has(n?.type)) continue;
1185
+ if (ct.has(e) || r.has(e) || lt.has(e) || n?.system || n?.readonly || n?.hidden || ut.has(n?.type)) continue;
1003
1186
  let a = {
1004
1187
  field: e,
1005
1188
  label: n?.label || e,
1006
- type: it(n?.type),
1189
+ type: dt(n?.type),
1007
1190
  required: !!n?.required
1008
- }, o = st(n);
1009
- a.type === "select" && o && (a.options = o), a.type === "lookup" && (a.reference = n?.reference, a.displayField = n?.display_field || n?.reference_field), a.type === "file" && ot(a, n), n?.readonlyWhen && (a.readonlyWhen = n.readonlyWhen), (n?.requiredWhen ?? n?.conditionalRequired) && (a.requiredWhen = n.requiredWhen ?? n.conditionalRequired);
1191
+ }, o = mt(n);
1192
+ a.type === "select" && o && (a.options = o), a.type === "lookup" && (a.reference = n?.reference, a.displayField = n?.display_field || n?.reference_field), a.type === "file" && pt(a, n), n?.readonlyWhen && (a.readonlyWhen = n.readonlyWhen), n?.requiredWhen && (a.requiredWhen = n.requiredWhen);
1010
1193
  let s = typeof n?.expression == "string" ? n.expression : n?.expression?.source;
1011
1194
  s && typeof s == "string" && (a.computed = !0, a.expr = s, a.required = !1, typeof n?.scale == "number" && (a.scale = n.scale)), i.push(a);
1012
1195
  }
1013
- return dt(i, t.maxColumns ?? 6);
1196
+ return yt(i, t.maxColumns ?? 6);
1014
1197
  }
1015
- function pt(e, t) {
1198
+ function xt(e, t) {
1016
1199
  let n = e ?? [], r = t?.fields;
1017
1200
  return !n.length || !r || typeof r != "object" ? n : n.map((e) => {
1018
1201
  if (e.type) return e;
1019
1202
  let t = r[e.field];
1020
1203
  if (!t) return e;
1021
- let n = it(t?.type), i = {
1204
+ let n = dt(t?.type), i = {
1022
1205
  ...e,
1023
1206
  type: n
1024
1207
  };
1025
1208
  i.label ??= t?.label || e.field, i.required ??= !!t?.required;
1026
- let a = st(t);
1027
- n === "select" && a && !i.options && (i.options = a), n === "lookup" && (i.reference ??= t?.reference, i.displayField ??= t?.display_field || t?.reference_field), n === "file" && ot(i, t), i.readonlyWhen == null && t?.readonlyWhen && (i.readonlyWhen = t.readonlyWhen), i.requiredWhen == null && (t?.requiredWhen ?? t?.conditionalRequired) && (i.requiredWhen = t.requiredWhen ?? t.conditionalRequired);
1209
+ let a = mt(t);
1210
+ n === "select" && a && !i.options && (i.options = a), n === "lookup" && (i.reference ??= t?.reference, i.displayField ??= t?.display_field || t?.reference_field), n === "file" && pt(i, t), i.readonlyWhen == null && t?.readonlyWhen && (i.readonlyWhen = t.readonlyWhen), i.requiredWhen == null && t?.requiredWhen && (i.requiredWhen = t.requiredWhen);
1028
1211
  let o = typeof t?.expression == "string" ? t.expression : t?.expression?.source;
1029
1212
  return !i.computed && o && typeof o == "string" && (i.computed = !0, i.expr = o, i.required = !1, typeof t?.scale == "number" && (i.scale = t.scale)), i;
1030
1213
  });
1031
1214
  }
1032
- var mt = /* @__PURE__ */ new Set([
1215
+ var St = /* @__PURE__ */ new Set([
1033
1216
  "formula",
1034
1217
  "summary",
1035
1218
  "rollup",
1036
1219
  "autonumber",
1037
1220
  "auto_number"
1038
1221
  ]);
1039
- function ht(e, t = {}) {
1222
+ function Ct(e, t = {}) {
1040
1223
  let n = e?.fields;
1041
1224
  if (!n || typeof n != "object") return [];
1042
1225
  let r = /* @__PURE__ */ new Set([...t.exclude ?? [], ...t.relationshipField ? [t.relationshipField] : []]), i = [];
1043
1226
  for (let [e, t] of Object.entries(n)) {
1044
1227
  let n = t;
1045
- tt.has(e) || r.has(e) || nt.has(e) || n?.system || n?.hidden || mt.has(n?.type) || i.push(e);
1228
+ ct.has(e) || r.has(e) || lt.has(e) || n?.system || n?.hidden || St.has(n?.type) || i.push(e);
1046
1229
  }
1047
1230
  return i;
1048
1231
  }
1049
- var gt = /* @__PURE__ */ new Set([
1232
+ var wt = /* @__PURE__ */ new Set([
1050
1233
  "textarea",
1051
1234
  "richtext",
1052
1235
  "html",
@@ -1055,17 +1238,17 @@ var gt = /* @__PURE__ */ new Set([
1055
1238
  "json",
1056
1239
  "location",
1057
1240
  "address"
1058
- ]), _t = /* @__PURE__ */ new Set([
1241
+ ]), Tt = /* @__PURE__ */ new Set([
1059
1242
  "file",
1060
1243
  "image",
1061
1244
  "avatar"
1062
1245
  ]);
1063
- function vt(e, t, n = {}) {
1246
+ function Et(e, t, n = {}) {
1064
1247
  if (t === "grid" || t === "form") return t;
1065
- let r = e?.fields ?? {}, i = ht(e, { relationshipField: n.relationshipField });
1066
- return i.some((e) => gt.has(r[e]?.type)) || i.filter((e) => _t.has(r[e]?.type)).length >= 2 || i.length > 8 ? "form" : "grid";
1248
+ let r = e?.fields ?? {}, i = Ct(e, { relationshipField: n.relationshipField });
1249
+ return i.some((e) => wt.has(r[e]?.type)) || i.filter((e) => Tt.has(r[e]?.type)).length >= 2 || i.length > 8 ? "form" : "grid";
1067
1250
  }
1068
- var yt = [
1251
+ var Dt = [
1069
1252
  "amount",
1070
1253
  "total",
1071
1254
  "subtotal",
@@ -1073,33 +1256,33 @@ var yt = [
1073
1256
  "line_amount",
1074
1257
  "net_amount"
1075
1258
  ];
1076
- function bt(e) {
1259
+ function Ot(e) {
1077
1260
  let t = e.filter((e) => e.type === "number" || e.type === "currency");
1078
1261
  if (t.length === 0) return;
1079
1262
  let n = t.find((e) => e.computed);
1080
1263
  if (n) return n.field;
1081
- let r = t.find((e) => yt.includes(e.field));
1264
+ let r = t.find((e) => Dt.includes(e.field));
1082
1265
  if (r) return r.field;
1083
1266
  let i = [...t].reverse().find((e) => e.type === "currency");
1084
1267
  return i ? i.field : t[t.length - 1].field;
1085
1268
  }
1086
- function xt(e, t, n, r = {}) {
1087
- let i = r.relationshipField || ct(t, n);
1269
+ function kt(e, t, n, r = {}) {
1270
+ let i = r.relationshipField || ht(t, n);
1088
1271
  if (!i) throw Error(`MasterDetailForm: could not find a lookup/master_detail field on "${e}" referencing "${n}". Set relationshipField explicitly.`);
1089
- let a = r.columns?.length ? pt(r.columns, t) : ft(t, { relationshipField: i }), o = r.amountField || bt(a);
1272
+ let a = r.columns?.length ? xt(r.columns, t) : bt(t, { relationshipField: i }), o = r.amountField || Ot(a);
1090
1273
  return {
1091
1274
  childObject: e,
1092
1275
  relationshipField: i,
1093
1276
  columns: a,
1094
- formFields: ht(t, { relationshipField: i }),
1095
- mode: vt(t, r.inlineEdit ?? (t?.fields)?.[i]?.inlineEdit, { relationshipField: i }),
1277
+ formFields: Ct(t, { relationshipField: i }),
1278
+ mode: Et(t, r.inlineEdit ?? (t?.fields)?.[i]?.inlineEdit, { relationshipField: i }),
1096
1279
  amountField: o,
1097
- sortField: Object.keys(t?.fields ?? {}).find((e) => nt.has(e))
1280
+ sortField: Object.keys(t?.fields ?? {}).find((e) => lt.has(e))
1098
1281
  };
1099
1282
  }
1100
1283
  //#endregion
1101
1284
  //#region src/MasterDetailForm.tsx
1102
- function St(e) {
1285
+ function At(e) {
1103
1286
  if (!e) return {};
1104
1287
  let t = {};
1105
1288
  return e.querySelectorAll("[name]").forEach((e) => {
@@ -1131,13 +1314,13 @@ function St(e) {
1131
1314
  }
1132
1315
  }), t;
1133
1316
  }
1134
- var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, formKey: c, onRowExpand: l, onAddViaForm: u }) => {
1135
- let [d, f] = s({}), p = o("");
1136
- r(() => {
1137
- let e = i.current;
1317
+ var jt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, formKey: o, onRowExpand: l, onAddViaForm: u }) => {
1318
+ let [d, f] = c({}), p = s("");
1319
+ i(() => {
1320
+ let e = r.current;
1138
1321
  if (!e) return;
1139
1322
  let t = () => {
1140
- let t = St(e), n;
1323
+ let t = At(e), n;
1141
1324
  try {
1142
1325
  n = JSON.stringify(t);
1143
1326
  } catch {
@@ -1148,29 +1331,29 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1148
1331
  t();
1149
1332
  let n = () => t();
1150
1333
  e.addEventListener("input", n), e.addEventListener("change", n);
1151
- let r = [
1334
+ let i = [
1152
1335
  120,
1153
1336
  360,
1154
1337
  800
1155
1338
  ].map((e) => setTimeout(t, e));
1156
1339
  return () => {
1157
- e.removeEventListener("input", n), e.removeEventListener("change", n), r.forEach(clearTimeout);
1340
+ e.removeEventListener("input", n), e.removeEventListener("change", n), i.forEach(clearTimeout);
1158
1341
  };
1159
1342
  }, [
1160
- i,
1161
- c,
1343
+ r,
1344
+ o,
1162
1345
  e.length
1163
1346
  ]);
1164
- let m = d[a], h = m === void 0 ? null : Number.isFinite(Number(m)) ? Number(m) : 0, g = e.reduce((e, n, r) => e + et(t[r]?.rows ?? [], n.amountField || "amount"), 0), v = h !== null && e.some((e) => !!e.amountField), y = h ?? 0, b = y / 100 * g, x = g + b, S = (e) => `¥${e.toLocaleString(void 0, {
1347
+ let m = d[a], h = m === void 0 ? null : Number.isFinite(Number(m)) ? Number(m) : 0, g = e.reduce((e, n, r) => e + st(t[r]?.rows ?? [], n.amountField || "amount"), 0), _ = h !== null && e.some((e) => !!e.amountField), v = h ?? 0, y = v / 100 * g, x = g + y, S = (e) => `¥${e.toLocaleString(void 0, {
1165
1348
  minimumFractionDigits: 2,
1166
1349
  maximumFractionDigits: 2
1167
1350
  })}`;
1168
- return /* @__PURE__ */ Z(he, { children: [e.map((e, r) => /* @__PURE__ */ Z("section", {
1351
+ return /* @__PURE__ */ Q(me, { children: [e.map((e, r) => /* @__PURE__ */ Q("section", {
1169
1352
  className: "space-y-2",
1170
- children: [/* @__PURE__ */ X("h3", {
1353
+ children: [/* @__PURE__ */ Z("h3", {
1171
1354
  className: "text-sm font-medium text-foreground",
1172
1355
  children: e.title || "Line Items"
1173
- }), e.columns?.length ? /* @__PURE__ */ X(_, {
1356
+ }), e.columns?.length ? /* @__PURE__ */ Z(b, {
1174
1357
  value: t[r]?.rows ?? [],
1175
1358
  onChange: (e) => n(r, e),
1176
1359
  contextRecord: d,
@@ -1179,51 +1362,51 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1179
1362
  ...e.inlineMode === "form" ? { onAdd: () => u(r) } : {},
1180
1363
  field: {
1181
1364
  columns: e.columns,
1182
- total_field: v ? void 0 : e.amountField || (e.totalField ? "amount" : void 0),
1365
+ total_field: _ ? void 0 : e.amountField || (e.totalField ? "amount" : void 0),
1183
1366
  sort_field: e.sortField,
1184
1367
  min_rows: e.minRows,
1185
1368
  max_rows: e.maxRows,
1186
1369
  add_label: e.inlineMode === "form" ? e.addLabel || "Add" : e.addLabel
1187
1370
  }
1188
- }) : /* @__PURE__ */ X("p", {
1371
+ }) : /* @__PURE__ */ Z("p", {
1189
1372
  className: "py-4 text-sm text-muted-foreground",
1190
1373
  children: "Loading columns…"
1191
1374
  })]
1192
- }, `${e.childObject}-${r}`)), v && /* @__PURE__ */ X("div", {
1375
+ }, `${e.childObject}-${r}`)), _ && /* @__PURE__ */ Z("div", {
1193
1376
  className: "flex justify-end",
1194
- children: /* @__PURE__ */ Z("dl", {
1377
+ children: /* @__PURE__ */ Q("dl", {
1195
1378
  className: "w-64 space-y-1.5 text-sm",
1196
1379
  "data-testid": "md-totals",
1197
1380
  children: [
1198
- /* @__PURE__ */ Z("div", {
1381
+ /* @__PURE__ */ Q("div", {
1199
1382
  className: "flex items-center justify-between",
1200
- children: [/* @__PURE__ */ X("dt", {
1383
+ children: [/* @__PURE__ */ Z("dt", {
1201
1384
  className: "text-muted-foreground",
1202
1385
  children: "Subtotal"
1203
- }), /* @__PURE__ */ X("dd", {
1386
+ }), /* @__PURE__ */ Z("dd", {
1204
1387
  className: "tabular-nums",
1205
1388
  "data-testid": "md-subtotal",
1206
1389
  children: S(g)
1207
1390
  })]
1208
1391
  }),
1209
- /* @__PURE__ */ Z("div", {
1392
+ /* @__PURE__ */ Q("div", {
1210
1393
  className: "flex items-center justify-between",
1211
- children: [/* @__PURE__ */ Z("dt", {
1394
+ children: [/* @__PURE__ */ Q("dt", {
1212
1395
  className: "text-muted-foreground",
1213
1396
  children: [
1214
1397
  "Tax (",
1215
- y,
1398
+ v,
1216
1399
  "%)"
1217
1400
  ]
1218
- }), /* @__PURE__ */ X("dd", {
1401
+ }), /* @__PURE__ */ Z("dd", {
1219
1402
  className: "tabular-nums",
1220
1403
  "data-testid": "md-tax",
1221
- children: S(b)
1404
+ children: S(y)
1222
1405
  })]
1223
1406
  }),
1224
- /* @__PURE__ */ Z("div", {
1407
+ /* @__PURE__ */ Q("div", {
1225
1408
  className: "flex items-center justify-between border-t border-border pt-1.5 text-base font-semibold",
1226
- children: [/* @__PURE__ */ X("dt", { children: "Total" }), /* @__PURE__ */ X("dd", {
1409
+ children: [/* @__PURE__ */ Z("dt", { children: "Total" }), /* @__PURE__ */ Z("dd", {
1227
1410
  className: "tabular-nums",
1228
1411
  "data-testid": "md-grand-total",
1229
1412
  children: S(x)
@@ -1232,96 +1415,96 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1232
1415
  ]
1233
1416
  })
1234
1417
  })] });
1235
- }, wt = ({ schema: e, dataSource: n, className: i }) => {
1236
- let c = e.details || [], l = e.mode === "edit" && !!e.recordId, d = c.some((e) => !e.relationshipField || !e.columns?.length || e.columns.some((e) => !e.type)), [f, p] = s(d ? null : c), m = f ?? c;
1237
- r(() => {
1238
- if (!d) {
1239
- p(c);
1418
+ }, Mt = ({ schema: e, dataSource: t, className: r }) => {
1419
+ let a = e.details || [], l = e.mode === "edit" && !!e.recordId, u = a.some((e) => !e.relationshipField || !e.columns?.length || e.columns.some((e) => !e.type)), [d, f] = c(u ? null : a), m = d ?? a;
1420
+ i(() => {
1421
+ if (!u) {
1422
+ f(a);
1240
1423
  return;
1241
1424
  }
1242
- if (!n || typeof n.getObjectSchema != "function") return;
1243
- let t = !1;
1425
+ if (!t || typeof t.getObjectSchema != "function") return;
1426
+ let n = !1;
1244
1427
  return (async () => {
1245
- let r = await Promise.all(c.map(async (t) => {
1246
- let r = t.columns?.length ? t.columns.every((e) => !!e.type) : !1;
1247
- if (t.relationshipField && r) return t;
1428
+ let r = await Promise.all(a.map(async (n) => {
1429
+ let r = n.columns?.length ? n.columns.every((e) => !!e.type) : !1;
1430
+ if (n.relationshipField && r) return n;
1248
1431
  try {
1249
- let r = await n.getObjectSchema(t.childObject);
1250
- if (t.relationshipField && t.columns?.length) return {
1251
- ...t,
1252
- columns: pt(t.columns, r)
1432
+ let r = await t.getObjectSchema(n.childObject);
1433
+ if (n.relationshipField && n.columns?.length) return {
1434
+ ...n,
1435
+ columns: xt(n.columns, r)
1253
1436
  };
1254
- let i = xt(t.childObject, r, e.objectName, {
1255
- relationshipField: t.relationshipField,
1256
- columns: t.columns,
1257
- amountField: t.amountField
1437
+ let i = kt(n.childObject, r, e.objectName, {
1438
+ relationshipField: n.relationshipField,
1439
+ columns: n.columns,
1440
+ amountField: n.amountField
1258
1441
  });
1259
1442
  return {
1260
- ...t,
1443
+ ...n,
1261
1444
  relationshipField: i.relationshipField,
1262
1445
  columns: i.columns,
1263
- formFields: t.formFields ?? i.formFields,
1264
- inlineMode: t.inlineMode ?? i.mode,
1265
- amountField: t.amountField ?? i.amountField,
1266
- sortField: t.sortField ?? i.sortField
1446
+ formFields: n.formFields ?? i.formFields,
1447
+ inlineMode: n.inlineMode ?? i.mode,
1448
+ amountField: n.amountField ?? i.amountField,
1449
+ sortField: n.sortField ?? i.sortField
1267
1450
  };
1268
1451
  } catch {
1269
- return t;
1452
+ return n;
1270
1453
  }
1271
1454
  }));
1272
- t || p(r);
1455
+ n || f(r);
1273
1456
  })(), () => {
1274
- t = !0;
1457
+ n = !0;
1275
1458
  };
1276
1459
  }, [
1277
- n,
1460
+ t,
1278
1461
  e.objectName,
1279
1462
  e.details
1280
1463
  ]);
1281
- let [h, g] = s(() => c.map(() => ({
1464
+ let [h, g] = c(() => a.map(() => ({
1282
1465
  rows: [],
1283
1466
  original: []
1284
- }))), _ = o(h);
1467
+ }))), _ = s(h);
1285
1468
  _.current = h;
1286
- let v = o({});
1287
- r(() => {
1288
- let e = n;
1469
+ let v = s({});
1470
+ i(() => {
1471
+ let e = t;
1289
1472
  if (!e || typeof e.getObjectSchema != "function") return;
1290
- let t = !1, r = Array.from(new Set(c.map((e) => e.childObject).filter(Boolean)));
1473
+ let n = !1, r = Array.from(new Set(a.map((e) => e.childObject).filter(Boolean)));
1291
1474
  return (async () => {
1292
- let n = await Promise.all(r.map(async (t) => {
1475
+ let t = await Promise.all(r.map(async (t) => {
1293
1476
  try {
1294
1477
  return [t, await e.getObjectSchema(t)];
1295
1478
  } catch {
1296
1479
  return [t, null];
1297
1480
  }
1298
1481
  }));
1299
- if (t) return;
1482
+ if (n) return;
1300
1483
  let i = {};
1301
- for (let [e, t] of n) t && (i[e] = t);
1484
+ for (let [e, n] of t) n && (i[e] = n);
1302
1485
  v.current = i;
1303
1486
  })(), () => {
1304
- t = !0;
1487
+ n = !0;
1305
1488
  };
1306
1489
  }, [
1307
- n,
1490
+ t,
1308
1491
  e.objectName,
1309
1492
  e.details
1310
1493
  ]);
1311
- let [y, b] = s(0), [x, S] = s(!1), C = o(!1), w = o(null), T = t(() => {
1494
+ let [y, b] = c(0), [x, S] = c(!1), C = s(!1), w = s(null), T = n(() => {
1312
1495
  C.current = !1, S(!1), w.current &&= (clearTimeout(w.current), null);
1313
1496
  }, []);
1314
- r(() => {
1315
- let t = !1;
1316
- if (!(!l || !n)) return (async () => {
1317
- let r = await Promise.all(m.map(async (t) => {
1318
- if (!t.relationshipField) return {
1497
+ i(() => {
1498
+ let n = !1;
1499
+ if (!(!l || !t)) return (async () => {
1500
+ let r = await Promise.all(m.map(async (n) => {
1501
+ if (!n.relationshipField) return {
1319
1502
  rows: [],
1320
1503
  original: []
1321
1504
  };
1322
1505
  try {
1323
- let r = (await n.find(t.childObject, {
1324
- $filter: { [t.relationshipField]: e.recordId },
1506
+ let r = (await t.find(n.childObject, {
1507
+ $filter: { [n.relationshipField]: e.recordId },
1325
1508
  $top: 500
1326
1509
  }))?.data ?? [];
1327
1510
  return {
@@ -1335,22 +1518,22 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1335
1518
  };
1336
1519
  }
1337
1520
  }));
1338
- t || g(r);
1521
+ n || g(r);
1339
1522
  })(), () => {
1340
- t = !0;
1523
+ n = !0;
1341
1524
  };
1342
1525
  }, [
1343
1526
  l,
1344
- n,
1527
+ t,
1345
1528
  e.recordId,
1346
- f
1529
+ d
1347
1530
  ]);
1348
- let E = t((e, t) => {
1531
+ let E = n((e, t) => {
1349
1532
  g((n) => n.map((n, r) => r === e ? {
1350
1533
  ...n,
1351
1534
  rows: t
1352
1535
  } : n));
1353
- }, []), D = e.taxRateField || "tax_rate", [O, M] = s(null), F = O ? h[O.detailIdx]?.rows?.[O.rowIdx] : void 0, I = O ? m[O.detailIdx] : void 0, L = t((e, t, n) => {
1536
+ }, []), D = e.taxRateField || "tax_rate", [O, k] = c(null), A = O ? h[O.detailIdx]?.rows?.[O.rowIdx] : void 0, j = O ? m[O.detailIdx] : void 0, F = n((e, t, n) => {
1354
1537
  g((r) => r.map((r, i) => i === e ? {
1355
1538
  ...r,
1356
1539
  rows: r.rows.map((e, r) => r === t ? {
@@ -1358,25 +1541,25 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1358
1541
  ...n
1359
1542
  } : e)
1360
1543
  } : r));
1361
- }, []), ee = t((e) => {
1544
+ }, []), R = n((e) => {
1362
1545
  g((t) => {
1363
1546
  let n = t.map((t, n) => n === e ? {
1364
1547
  ...t,
1365
1548
  rows: [...t.rows, {}]
1366
1549
  } : t), r = n[e].rows.length - 1;
1367
- return M({
1550
+ return k({
1368
1551
  detailIdx: e,
1369
1552
  rowIdx: r,
1370
1553
  isNew: !0
1371
1554
  }), n;
1372
1555
  });
1373
- }, []), R = t(() => {
1374
- M((e) => (e?.isNew && g((t) => t.map((t, n) => n === e.detailIdx ? {
1556
+ }, []), z = n(() => {
1557
+ k((e) => (e?.isNew && g((t) => t.map((t, n) => n === e.detailIdx ? {
1375
1558
  ...t,
1376
1559
  rows: t.rows.filter((t, n) => n !== e.rowIdx)
1377
1560
  } : t)), null));
1378
- }, []), z = t(async (t) => {
1379
- T(), e.onSuccess || K.success(l ? e.title ? `${e.title} saved` : "Saved" : "Created"), l || (g(m.map(() => ({
1561
+ }, []), B = n(async (t) => {
1562
+ T(), e.onSuccess || J.success(l ? e.title ? `${e.title} saved` : "Saved" : "Created"), l || (g(m.map(() => ({
1380
1563
  rows: [],
1381
1564
  original: []
1382
1565
  }))), b((e) => e + 1)), await e.onSuccess?.(t);
@@ -1386,20 +1569,20 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1386
1569
  e.title,
1387
1570
  m.length,
1388
1571
  T
1389
- ]), B = t((t) => {
1390
- T(), K.error(t?.message || "Save failed"), e.onError?.(t);
1391
- }, [e, T]), V = t(async (t) => {
1392
- if (!n) throw Error("MasterDetailForm: dataSource is required");
1393
- let r = { ...t };
1572
+ ]), V = n((t) => {
1573
+ T(), J.error(t?.message || "Save failed"), e.onError?.(t);
1574
+ }, [e, T]), H = n(async (n) => {
1575
+ if (!t) throw Error("MasterDetailForm: dataSource is required");
1576
+ let r = { ...n };
1394
1577
  return m.forEach((e, t) => {
1395
- e.totalField && (r[e.totalField] = et(_.current[t]?.rows ?? [], e.amountField || "amount"));
1396
- }), (await u(n, l ? Qe(e.objectName, e.recordId, r, m.filter((e) => e.relationshipField).map((e, t) => ({
1578
+ e.totalField && (r[e.totalField] = st(_.current[t]?.rows ?? [], e.amountField || "amount"));
1579
+ }), (await p(t, l ? at(e.objectName, String(e.recordId), r, m.filter((e) => e.relationshipField).map((e, t) => ({
1397
1580
  childObject: e.childObject,
1398
1581
  relationshipField: e.relationshipField,
1399
1582
  rows: _.current[t]?.rows ?? [],
1400
1583
  original: _.current[t]?.original ?? [],
1401
1584
  childSchema: v.current[e.childObject]
1402
- }))) : Ze(e.objectName, r, m.filter((e) => e.relationshipField).map((e, t) => ({
1585
+ }))) : it(e.objectName, r, m.filter((e) => e.relationshipField).map((e, t) => ({
1403
1586
  childObject: e.childObject,
1404
1587
  relationshipField: e.relationshipField,
1405
1588
  rows: _.current[t]?.rows ?? [],
@@ -1409,12 +1592,12 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1409
1592
  id: e.recordId
1410
1593
  };
1411
1594
  }, [
1412
- n,
1595
+ t,
1413
1596
  m,
1414
1597
  e.objectName,
1415
1598
  e.recordId,
1416
1599
  l
1417
- ]), H = a(() => ({
1600
+ ]), ee = o(() => ({
1418
1601
  type: "object-form",
1419
1602
  objectName: e.objectName,
1420
1603
  mode: e.mode ?? "create",
@@ -1427,273 +1610,307 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1427
1610
  title: e.title,
1428
1611
  showSubmit: !1,
1429
1612
  showCancel: !1,
1430
- submitHandler: V,
1431
- onSuccess: z,
1432
- onError: B
1613
+ submitHandler: H,
1614
+ onSuccess: B,
1615
+ onError: V
1433
1616
  }), [
1434
1617
  e,
1435
- V,
1436
- z,
1437
- B
1438
- ]), U = o(null), W = e.submitText ?? (l ? "Save" : "Create"), te = t(() => {
1618
+ H,
1619
+ B,
1620
+ V
1621
+ ]), U = s(null), W = e.submitText ?? (l ? "Save" : "Create"), G = n(() => {
1439
1622
  C.current || U.current?.querySelector("form") && (C.current = !0, S(!0), setTimeout(() => {
1440
1623
  (U.current?.querySelector("form"))?.requestSubmit();
1441
1624
  }, 0), w.current = setTimeout(() => T(), 1500));
1442
1625
  }, [T]);
1443
- return r(() => () => {
1626
+ return i(() => () => {
1444
1627
  w.current && clearTimeout(w.current);
1445
- }, []), /* @__PURE__ */ Z("div", {
1446
- className: G("space-y-6", i, e.className),
1628
+ }, []), /* @__PURE__ */ Q("div", {
1629
+ className: q("space-y-6", r, e.className),
1447
1630
  children: [
1448
- /* @__PURE__ */ X("div", {
1631
+ /* @__PURE__ */ Z("div", {
1449
1632
  ref: U,
1450
- children: /* @__PURE__ */ X(Mt, {
1451
- schema: H,
1452
- dataSource: n
1633
+ children: /* @__PURE__ */ Z(Vt, {
1634
+ schema: ee,
1635
+ dataSource: t
1453
1636
  }, y)
1454
1637
  }),
1455
- /* @__PURE__ */ X(Ct, {
1638
+ /* @__PURE__ */ Z(jt, {
1456
1639
  details: m,
1457
1640
  state: h,
1458
1641
  setRows: E,
1459
1642
  formHostRef: U,
1460
1643
  taxRateField: D,
1461
1644
  formKey: y,
1462
- onRowExpand: (e, t) => M({
1645
+ onRowExpand: (e, t) => k({
1463
1646
  detailIdx: e,
1464
1647
  rowIdx: t
1465
1648
  }),
1466
- onAddViaForm: ee
1649
+ onAddViaForm: R
1467
1650
  }),
1468
- O && I && /* @__PURE__ */ Z(A, {
1651
+ O && j && /* @__PURE__ */ Q(N, {
1469
1652
  className: "border-primary/40 shadow-none ring-1 ring-primary/10",
1470
1653
  "data-testid": "md-row-form",
1471
- children: [/* @__PURE__ */ Z(N, {
1654
+ children: [/* @__PURE__ */ Q(I, {
1472
1655
  className: "pb-2 flex flex-row items-center justify-between gap-2 space-y-0",
1473
- children: [/* @__PURE__ */ Z(P, {
1656
+ children: [/* @__PURE__ */ Q(L, {
1474
1657
  className: "text-sm font-medium",
1475
1658
  children: [
1476
- I.title || "Line item",
1659
+ j.title || "Line item",
1477
1660
  " — row ",
1478
1661
  O.rowIdx + 1
1479
1662
  ]
1480
- }), /* @__PURE__ */ X(k, {
1663
+ }), /* @__PURE__ */ Z(M, {
1481
1664
  type: "button",
1482
1665
  variant: "ghost",
1483
1666
  size: "sm",
1484
1667
  className: "h-7 text-xs text-muted-foreground",
1485
- onClick: R,
1668
+ onClick: z,
1486
1669
  children: "Close"
1487
1670
  })]
1488
- }), /* @__PURE__ */ X(j, { children: /* @__PURE__ */ X(Mt, {
1671
+ }), /* @__PURE__ */ Z(P, { children: /* @__PURE__ */ Z(Vt, {
1489
1672
  schema: {
1490
1673
  type: "object-form",
1491
- objectName: I.childObject,
1674
+ objectName: j.childObject,
1492
1675
  mode: "edit",
1493
- initialData: F ?? {},
1494
- ...I.formFields?.length ? { fields: I.formFields } : {},
1676
+ initialData: A ?? {},
1677
+ ...j.formFields?.length ? { fields: j.formFields } : {},
1495
1678
  submitText: "Apply",
1496
1679
  submitHandler: async (e) => e,
1497
1680
  onSuccess: (e) => {
1498
- L(O.detailIdx, O.rowIdx, e), M(null);
1681
+ F(O.detailIdx, O.rowIdx, e), k(null);
1499
1682
  },
1500
- onCancel: R
1683
+ onCancel: z
1501
1684
  },
1502
- dataSource: n
1685
+ dataSource: t
1503
1686
  }, `row-${O.detailIdx}-${O.rowIdx}`) })]
1504
1687
  }),
1505
- e.showSubmit !== !1 && /* @__PURE__ */ Z("div", {
1688
+ e.showSubmit !== !1 && /* @__PURE__ */ Q("div", {
1506
1689
  className: "flex items-center justify-end gap-2 border-t border-border pt-4",
1507
- children: [e.onCancel && /* @__PURE__ */ X(k, {
1690
+ children: [e.onCancel && /* @__PURE__ */ Z(M, {
1508
1691
  type: "button",
1509
1692
  variant: "outline",
1510
1693
  onClick: e.onCancel,
1511
1694
  disabled: x,
1512
1695
  "data-testid": "md-form-cancel",
1513
1696
  children: e.cancelText ?? "Cancel"
1514
- }), /* @__PURE__ */ X(k, {
1697
+ }), /* @__PURE__ */ Z(M, {
1515
1698
  type: "button",
1516
- onClick: te,
1517
- disabled: x || d && !f,
1699
+ onClick: G,
1700
+ disabled: x || u && !d,
1518
1701
  "data-testid": "md-form-submit",
1519
1702
  children: x ? "Saving…" : W
1520
1703
  })]
1521
1704
  })
1522
1705
  ]
1523
1706
  });
1524
- }, Tt = {
1707
+ }, Nt = {
1525
1708
  1: void 0,
1526
1709
  2: "grid gap-4 grid-cols-1 @md:grid-cols-2",
1527
1710
  3: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",
1528
1711
  4: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"
1529
- }, Et = ge({
1712
+ }, Pt = pe({
1530
1713
  "form.discardTitle": "Discard changes?",
1531
1714
  "form.discardMessage": "You have unsaved changes. If you close this form now, your edits will be lost.",
1532
1715
  "form.keepEditing": "Keep editing",
1533
1716
  "form.discard": "Discard"
1534
- }, "form.discardTitle"), Dt = ({ schema: e, dataSource: n, className: c }) => {
1535
- let { fieldLabel: l } = h(), { t: u } = Et(), f = p(), [m, g] = s(null), [_, y] = s([]), [A, j] = s({}), [M, N] = s(!0), [P, F] = s(null), [I, L] = s(!1), [ee, R] = s(!1), [z, B] = s(!1), V = o(!1), re = e.confirmOnDiscard !== !1, ie = e.open !== !1, ae = e.drawerSide || "right", oe = i(), [se, K] = s(() => {
1717
+ }, "form.discardTitle"), Ft = ({ schema: e, dataSource: t, className: r }) => {
1718
+ let { fieldLabel: l } = v(), { t: u } = Pt(), d = g(), [f, p] = c(null), [h, _] = c([]), [y, b] = c({}), [S, N] = c(!0), [P, F] = c(null), [I, L] = c(!1), [R, z] = c(!1), { saveWithOcc: B, conflictDialog: V } = We(), [H, ne] = c(!1), K = s(!1), J = e.confirmOnDiscard !== !1, re = e.open !== !1, Y = e.drawerSide || "right", ie = a(), [ae, oe] = c(() => {
1536
1719
  let t = {};
1537
1720
  return e.sections?.forEach((e, n) => {
1538
1721
  let r = e.name || String(n);
1539
1722
  e.collapsed && (t[r] = !0);
1540
1723
  }), t;
1541
1724
  });
1542
- r(() => {
1725
+ i(() => {
1543
1726
  (async () => {
1544
- if (!n) {
1727
+ if (!t) {
1545
1728
  N(!1);
1546
1729
  return;
1547
1730
  }
1548
1731
  try {
1549
- let t = await n.getObjectSchema(e.objectName);
1550
- g(t);
1732
+ let n = await t.getObjectSchema(e.objectName);
1733
+ p(n);
1551
1734
  } catch (e) {
1552
1735
  F(e), N(!1);
1553
1736
  }
1554
1737
  })();
1555
- }, [e.objectName, n]), r(() => {
1556
- (m || !n) && (async () => {
1738
+ }, [e.objectName, t]);
1739
+ let se = s(void 0);
1740
+ i(() => {
1741
+ let n = !1;
1742
+ return (f || !t) && (async () => {
1557
1743
  if (e.mode === "create" || !e.recordId) {
1558
- j(e.initialData || e.initialValues || {}), N(!1);
1744
+ b(e.initialData || e.initialValues || {}), N(!1);
1559
1745
  return;
1560
1746
  }
1561
- if (!n) {
1562
- j(e.initialData || e.initialValues || {}), N(!1);
1747
+ if (!t) {
1748
+ b(e.initialData || e.initialValues || {}), N(!1);
1563
1749
  return;
1564
1750
  }
1751
+ se.current !== e.recordId && (N(!0), L(!1));
1565
1752
  try {
1566
- let t = await n.findOne(e.objectName, e.recordId);
1567
- j(t || {});
1753
+ let r = await t.findOne(e.objectName, e.recordId);
1754
+ if (n) return;
1755
+ se.current = e.recordId, b(r || {});
1568
1756
  } catch (e) {
1757
+ if (n) return;
1569
1758
  F(e);
1570
1759
  } finally {
1571
- N(!1);
1760
+ n || N(!1);
1572
1761
  }
1573
- })();
1762
+ })(), () => {
1763
+ n = !0;
1764
+ };
1574
1765
  }, [
1575
- m,
1766
+ f,
1576
1767
  e.mode,
1577
1768
  e.recordId,
1578
1769
  e.initialData,
1579
1770
  e.initialValues,
1580
- n,
1771
+ t,
1581
1772
  e.objectName
1582
1773
  ]);
1583
- let ce = t((t) => Se(t, {
1584
- objectSchema: m,
1774
+ let ce = n((t) => Se(t, {
1775
+ objectSchema: f,
1585
1776
  objectName: e.objectName,
1586
1777
  readOnly: e.readOnly,
1587
1778
  mode: e.mode,
1588
1779
  fieldLabel: l
1589
1780
  }), [
1590
- m,
1781
+ f,
1591
1782
  e.readOnly,
1592
1783
  e.mode,
1593
1784
  e.objectName,
1594
1785
  l
1595
1786
  ]);
1596
- r(() => {
1597
- if (!m && n) return;
1787
+ i(() => {
1788
+ if (!f && t) return;
1598
1789
  if (e.customFields?.length) {
1599
- y(e.customFields), N(!1);
1790
+ _(e.customFields), N(!1);
1600
1791
  return;
1601
1792
  }
1602
1793
  if (e.sections?.length) {
1603
1794
  N(!1);
1604
1795
  return;
1605
1796
  }
1606
- if (!m) return;
1607
- let t = e.fields || Object.keys(m.fields || {}), r = [];
1608
- for (let n of t) {
1609
- let t = typeof n == "string" ? n : n.name;
1610
- if (!t) continue;
1611
- let i = m.fields?.[t];
1797
+ if (!f) return;
1798
+ let n = e.fields || Object.keys(f.fields || {}), r = [];
1799
+ for (let t of n) {
1800
+ let n = typeof t == "string" ? t : t.name;
1801
+ if (!n) continue;
1802
+ let i = f.fields?.[n];
1612
1803
  i && r.push({
1613
- name: t,
1614
- label: l(e.objectName, t, i.label || t),
1615
- type: b(i.type),
1804
+ name: n,
1805
+ label: l(e.objectName, n, i.label || n),
1806
+ type: C(i.type),
1616
1807
  required: i.required || !1,
1617
1808
  disabled: e.readOnly || e.mode === "view" || i.readonly,
1618
1809
  placeholder: i.placeholder,
1619
1810
  description: i.help || i.description,
1620
- validation: v(i),
1811
+ validation: x(i),
1621
1812
  field: i,
1622
1813
  options: i.options,
1623
1814
  multiple: i.multiple
1624
1815
  });
1625
1816
  }
1626
- y(r), N(!1);
1817
+ _(r), N(!1);
1627
1818
  }, [
1628
- m,
1819
+ f,
1629
1820
  e.fields,
1630
1821
  e.customFields,
1631
1822
  e.sections,
1632
1823
  e.readOnly,
1633
1824
  e.mode,
1634
- n
1825
+ t
1635
1826
  ]);
1636
- let le = t(async (t) => {
1637
- B(!0);
1827
+ let le = n(async (n) => {
1828
+ ne(!0);
1638
1829
  try {
1639
- if (!n) return e.onSuccess && await e.onSuccess(t), e.onOpenChange?.(!1), t;
1640
- let r, i = Ke(t, m);
1641
- return e.mode === "create" ? r = await n.create(e.objectName, i) : e.mode === "edit" && e.recordId && (r = await n.update(e.objectName, e.recordId, i)), e.onSuccess && await e.onSuccess(r), e.onOpenChange?.(!1), r;
1830
+ if (!t) return e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
1831
+ let r, i = $e(n, f);
1832
+ if (e.mode === "create") r = await t.create(e.objectName, i);
1833
+ else if (e.mode === "edit" && e.recordId) {
1834
+ let n = await B({
1835
+ dataSource: t,
1836
+ objectName: e.objectName,
1837
+ recordId: e.recordId,
1838
+ payload: i,
1839
+ baseRecord: y
1840
+ });
1841
+ if (n.status === "cancelled") return;
1842
+ r = n.result;
1843
+ }
1844
+ return e.onSuccess && await e.onSuccess(r), e.onOpenChange?.(!1), r;
1642
1845
  } catch (t) {
1643
1846
  throw e.onError && e.onError(t), t;
1644
1847
  } finally {
1645
- B(!1);
1848
+ ne(!1);
1646
1849
  }
1647
1850
  }, [
1648
1851
  e,
1649
- n,
1650
- m
1651
- ]), q = t(() => {
1652
- R(!1), V.current && (V.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
1653
- }, [e]), ue = t((e) => {
1654
- V.current = e, re && I ? R(!0) : q();
1852
+ t,
1853
+ f,
1854
+ B,
1855
+ y
1856
+ ]), X = n(() => {
1857
+ z(!1), K.current && (K.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
1858
+ }, [e]), de = n((e) => {
1859
+ K.current = e, J && I ? z(!0) : X();
1860
+ }, [
1861
+ J,
1862
+ I,
1863
+ X
1864
+ ]);
1865
+ i(() => {
1866
+ if (!re || !I || !J) return;
1867
+ let e = (e) => {
1868
+ e.preventDefault(), e.returnValue = "";
1869
+ };
1870
+ return window.addEventListener("beforeunload", e), () => window.removeEventListener("beforeunload", e);
1655
1871
  }, [
1656
1872
  re,
1657
1873
  I,
1658
- q
1659
- ]), de = t(() => {
1660
- V.current = !0, q();
1661
- }, [q]), fe = a(() => {
1662
- if (e.drawerWidth) return ae === "left" || ae === "right" ? {
1874
+ J
1875
+ ]);
1876
+ let fe = n(() => {
1877
+ K.current = !0, X();
1878
+ }, [X]), pe = o(() => {
1879
+ if (e.drawerWidth) return Y === "left" || Y === "right" ? {
1663
1880
  width: e.drawerWidth,
1664
1881
  maxWidth: e.drawerWidth
1665
1882
  } : {
1666
1883
  height: e.drawerWidth,
1667
1884
  maxHeight: e.drawerWidth
1668
1885
  };
1669
- }, [e.drawerWidth, ae]), pe = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical", J = e.showSubmit !== !1 && e.mode !== "view", Y = e.showCancel !== !1, he = e.submitText || (e.mode === "create" ? "Create" : "Update"), ge = e.cancelText || "Cancel", _e = {
1886
+ }, [e.drawerWidth, Y]), me = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical", he = e.showSubmit !== !1 && e.mode !== "view", $ = e.showCancel !== !1, ge = e.submitText || (e.mode === "create" ? "Create" : "Update"), _e = e.cancelText || "Cancel", ve = {
1670
1887
  type: "form",
1671
1888
  objectName: e.objectName,
1672
- layout: pe,
1673
- defaultValues: A,
1674
- submitLabel: he,
1675
- cancelLabel: ge,
1676
- showSubmit: J,
1677
- showCancel: Y,
1889
+ layout: me,
1890
+ defaultValues: y,
1891
+ submitLabel: ge,
1892
+ cancelLabel: _e,
1893
+ showSubmit: he,
1894
+ showCancel: $,
1678
1895
  onSubmit: le,
1679
- onCancel: de,
1896
+ onCancel: fe,
1680
1897
  onDirtyChange: L,
1681
1898
  showActions: !1,
1682
- id: oe
1683
- }, Q = () => {
1684
- if (P) return /* @__PURE__ */ Z("div", {
1899
+ id: ie
1900
+ }, ye = () => {
1901
+ if (P) return /* @__PURE__ */ Q("div", {
1685
1902
  className: "p-4 border border-red-300 bg-red-50 rounded-md",
1686
- children: [/* @__PURE__ */ X("h3", {
1903
+ children: [/* @__PURE__ */ Z("h3", {
1687
1904
  className: "text-red-800 font-semibold",
1688
1905
  children: "Error loading form"
1689
- }), /* @__PURE__ */ X("p", {
1906
+ }), /* @__PURE__ */ Z("p", {
1690
1907
  className: "text-red-600 text-sm mt-1",
1691
1908
  children: P.message
1692
1909
  })]
1693
1910
  });
1694
- if (M) return /* @__PURE__ */ Z("div", {
1911
+ if (S) return /* @__PURE__ */ Q("div", {
1695
1912
  className: "p-8 text-center",
1696
- children: [/* @__PURE__ */ X("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ X("p", {
1913
+ children: [/* @__PURE__ */ Z("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ Z("p", {
1697
1914
  className: "mt-2 text-sm text-gray-600",
1698
1915
  children: "Loading form..."
1699
1916
  })]
@@ -1701,7 +1918,7 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1701
1918
  if (e.sections?.length) {
1702
1919
  let t = [];
1703
1920
  return e.sections.forEach((e, n) => {
1704
- let r = e.name || String(n), i = se[r] ?? e.collapsed ?? !1;
1921
+ let r = e.name || String(n), i = ae[r] ?? e.collapsed ?? !1;
1705
1922
  t.push({
1706
1923
  name: `__section_${r}`,
1707
1924
  label: e.label || "",
@@ -1709,7 +1926,7 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1709
1926
  colSpan: 4,
1710
1927
  collapsible: e.collapsible,
1711
1928
  collapsed: i,
1712
- onToggle: e.collapsible ? () => K((e) => ({
1929
+ onToggle: e.collapsible ? () => oe((e) => ({
1713
1930
  ...e,
1714
1931
  [r]: !i
1715
1932
  })) : void 0,
@@ -1720,19 +1937,19 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1720
1937
  ...e,
1721
1938
  hidden: !0
1722
1939
  }))) : t.push(...a);
1723
- }), /* @__PURE__ */ X(d, { schema: {
1724
- ..._e,
1940
+ }), /* @__PURE__ */ Z(m, { schema: {
1941
+ ...ve,
1725
1942
  fields: t
1726
1943
  } });
1727
1944
  }
1728
- let t = Be(_, m, e.columns, e.mode), n = Tt[t.columns || 1];
1729
- return /* @__PURE__ */ X(d, { schema: {
1730
- ..._e,
1945
+ let t = ze(h, f, e.columns, e.mode), n = Nt[t.columns || 1];
1946
+ return /* @__PURE__ */ Z(m, { schema: {
1947
+ ...ve,
1731
1948
  fields: t.fields,
1732
1949
  columns: t.columns,
1733
1950
  ...n ? { fieldContainerClass: n } : {}
1734
1951
  } });
1735
- }, ve = e.subforms, $ = ve?.length && e.mode !== "view" ? /* @__PURE__ */ X(wt, {
1952
+ }, be = e.subforms, xe = be?.length && e.mode !== "view" ? /* @__PURE__ */ Z(Mt, {
1736
1953
  schema: {
1737
1954
  type: "object-master-detail-form",
1738
1955
  objectName: e.objectName,
@@ -1741,92 +1958,93 @@ var Ct = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
1741
1958
  fields: e.fields,
1742
1959
  sections: e.sections,
1743
1960
  submitText: e.submitText,
1744
- cancelText: ge,
1745
- details: ve,
1961
+ cancelText: _e,
1962
+ details: be,
1746
1963
  onSuccess: async (t) => {
1747
1964
  await e.onSuccess?.(t), e.onOpenChange?.(!1);
1748
1965
  },
1749
1966
  onError: e.onError,
1750
1967
  onCancel: () => e.onOpenChange?.(!1)
1751
1968
  },
1752
- dataSource: n
1753
- }) : Q();
1754
- return f ? /* @__PURE__ */ Z("div", {
1969
+ dataSource: t
1970
+ }) : ye();
1971
+ return d ? /* @__PURE__ */ Q("div", {
1755
1972
  className: "@container rounded-md border bg-card p-4",
1756
- children: [(e.title || e.description) && /* @__PURE__ */ Z("div", {
1973
+ children: [(e.title || e.description) && /* @__PURE__ */ Q("div", {
1757
1974
  className: "mb-3 space-y-0.5",
1758
- children: [e.title && /* @__PURE__ */ X("div", {
1975
+ children: [e.title && /* @__PURE__ */ Z("div", {
1759
1976
  className: "text-sm font-semibold",
1760
1977
  children: e.title
1761
- }), e.description && /* @__PURE__ */ X("p", {
1978
+ }), e.description && /* @__PURE__ */ Z("p", {
1762
1979
  className: "text-xs text-muted-foreground",
1763
1980
  children: e.description
1764
1981
  })]
1765
- }), $]
1766
- }) : /* @__PURE__ */ X(H, {
1767
- open: ie,
1982
+ }), xe]
1983
+ }) : /* @__PURE__ */ Z(ee, {
1984
+ open: re,
1768
1985
  onOpenChange: (t) => {
1769
1986
  if (t) {
1770
1987
  e.onOpenChange?.(!0);
1771
1988
  return;
1772
1989
  }
1773
- ue(!1);
1990
+ de(!1);
1774
1991
  },
1775
- children: /* @__PURE__ */ Z(U, {
1776
- side: ae,
1777
- className: G("overflow-y-auto", c, e.className),
1778
- style: fe,
1992
+ children: /* @__PURE__ */ Q(U, {
1993
+ side: Y,
1994
+ className: q("overflow-y-auto", r, e.className),
1995
+ style: pe,
1779
1996
  children: [
1780
- (e.title || e.description) && /* @__PURE__ */ Z(te, { children: [e.title && /* @__PURE__ */ X(ne, { children: e.title }), e.description ? /* @__PURE__ */ X(W, { children: e.description }) : /* @__PURE__ */ X(W, {
1997
+ (e.title || e.description) && /* @__PURE__ */ Q(G, { children: [e.title && /* @__PURE__ */ Z(te, { children: e.title }), e.description ? /* @__PURE__ */ Z(W, { children: e.description }) : /* @__PURE__ */ Z(W, {
1781
1998
  className: "sr-only",
1782
1999
  children: "Complete the form fields, then submit or cancel."
1783
2000
  })] }),
1784
- /* @__PURE__ */ X("div", {
2001
+ /* @__PURE__ */ Z("div", {
1785
2002
  className: "@container py-4",
1786
- children: $
2003
+ children: xe
1787
2004
  }),
1788
- !P && !M && !(ve?.length && e.mode !== "view") && (J || Y) && /* @__PURE__ */ X("div", {
2005
+ !P && !S && !(be?.length && e.mode !== "view") && (he || $) && /* @__PURE__ */ Z("div", {
1789
2006
  className: "shrink-0 border-t px-4 py-3 bg-background",
1790
2007
  "data-testid": "drawer-form-footer",
1791
- children: /* @__PURE__ */ Z("div", {
2008
+ children: /* @__PURE__ */ Q("div", {
1792
2009
  className: "flex flex-col sm:flex-row gap-2 sm:justify-end",
1793
- children: [Y && /* @__PURE__ */ X(k, {
2010
+ children: [$ && /* @__PURE__ */ Z(M, {
1794
2011
  type: "button",
1795
2012
  variant: "outline",
1796
- onClick: de,
1797
- disabled: z,
2013
+ onClick: fe,
2014
+ disabled: H,
1798
2015
  className: "w-full sm:w-auto",
1799
- children: ge
1800
- }), J && /* @__PURE__ */ Z(k, {
2016
+ children: _e
2017
+ }), he && /* @__PURE__ */ Q(M, {
1801
2018
  type: "submit",
1802
- form: oe,
1803
- disabled: z,
2019
+ form: ie,
2020
+ disabled: H,
1804
2021
  className: "w-full sm:w-auto",
1805
- children: [z && /* @__PURE__ */ X(me, { className: "mr-2 h-4 w-4 animate-spin" }), he]
2022
+ children: [H && /* @__PURE__ */ Z(ue, { className: "mr-2 h-4 w-4 animate-spin" }), ge]
1806
2023
  })]
1807
2024
  })
1808
2025
  }),
1809
- /* @__PURE__ */ X(x, {
1810
- open: ee,
1811
- onOpenChange: R,
1812
- children: /* @__PURE__ */ Z(w, { children: [/* @__PURE__ */ Z(D, { children: [/* @__PURE__ */ X(O, { children: u("form.discardTitle") }), /* @__PURE__ */ X(T, { children: u("form.discardMessage") })] }), /* @__PURE__ */ Z(E, { children: [/* @__PURE__ */ X(C, {
2026
+ /* @__PURE__ */ Z(w, {
2027
+ open: R,
2028
+ onOpenChange: z,
2029
+ children: /* @__PURE__ */ Q(D, { children: [/* @__PURE__ */ Q(A, { children: [/* @__PURE__ */ Z(j, { children: u("form.discardTitle") }), /* @__PURE__ */ Z(O, { children: u("form.discardMessage") })] }), /* @__PURE__ */ Q(k, { children: [/* @__PURE__ */ Z(E, {
1813
2030
  onClick: () => {
1814
- V.current = !1;
2031
+ K.current = !1;
1815
2032
  },
1816
2033
  children: u("form.keepEditing")
1817
- }), /* @__PURE__ */ X(S, {
1818
- onClick: q,
2034
+ }), /* @__PURE__ */ Z(T, {
2035
+ onClick: X,
1819
2036
  children: u("form.discard")
1820
2037
  })] })] })
1821
- })
2038
+ }),
2039
+ V
1822
2040
  ]
1823
2041
  })
1824
2042
  });
1825
2043
  };
1826
2044
  //#endregion
1827
2045
  //#region src/fieldGroups.ts
1828
- function Ot(e, t) {
1829
- let n = _e({
2046
+ function It(e, t) {
2047
+ let n = he({
1830
2048
  fieldGroups: t,
1831
2049
  fields: Object.fromEntries(e.map((e) => [e.name, { group: e.group }]))
1832
2050
  });
@@ -1846,27 +2064,27 @@ function Ot(e, t) {
1846
2064
  }
1847
2065
  //#endregion
1848
2066
  //#region src/ModalForm.tsx
1849
- var kt = ge({
2067
+ var Lt = pe({
1850
2068
  "form.discardTitle": "Discard changes?",
1851
2069
  "form.discardMessage": "You have unsaved changes. If you close this form now, your edits will be lost.",
1852
2070
  "form.keepEditing": "Keep editing",
1853
2071
  "form.discard": "Discard"
1854
- }, "form.discardTitle"), At = {
2072
+ }, "form.discardTitle"), Rt = {
1855
2073
  sm: "sm:max-w-sm",
1856
2074
  default: "sm:max-w-lg",
1857
2075
  lg: "sm:max-w-2xl",
1858
2076
  xl: "sm:max-w-5xl",
1859
2077
  full: "sm:max-w-[95vw] sm:w-full"
1860
- }, jt = ({ schema: e, dataSource: n, className: c }) => {
1861
- let { fieldLabel: l, sectionLabel: u } = h(), { t: f } = kt(), m = p(), g = le(), _ = t((t) => {
1862
- if (!g?.isLoaded) return t;
2078
+ }, zt = ({ schema: e, dataSource: t, className: r }) => {
2079
+ let { fieldLabel: l, sectionLabel: u } = v(), { t: d } = Lt(), f = g(), p = Y(), h = n((t) => {
2080
+ if (!p?.isLoaded) return t;
1863
2081
  let n = [];
1864
2082
  for (let r of t) {
1865
2083
  if (!r?.name) {
1866
2084
  n.push(r);
1867
2085
  continue;
1868
2086
  }
1869
- g.checkField(e.objectName, r.name, "read") && (!g.checkField(e.objectName, r.name, "write") && e.mode !== "view" ? n.push({
2087
+ p.checkField(e.objectName, r.name, "read") && (!p.checkField(e.objectName, r.name, "write") && e.mode !== "view" ? n.push({
1870
2088
  ...r,
1871
2089
  readOnly: !0,
1872
2090
  disabled: !0
@@ -1874,14 +2092,14 @@ var kt = ge({
1874
2092
  }
1875
2093
  return n;
1876
2094
  }, [
1877
- g,
2095
+ p,
1878
2096
  e.objectName,
1879
2097
  e.mode
1880
- ]), [y, A] = s(null), [j, M] = s([]), [N, P] = s({}), [z, B] = s(!0), [V, H] = s(null), [U, W] = s(!1), [te, ne] = s(!1), [K, ce] = s(!1), q = o(!1), ue = e.confirmOnDiscard !== !1, de = e.open !== !1, fe = i(), pe = a(() => {
2098
+ ]), [_, y] = c(null), [b, S] = c([]), [N, P] = c({}), [F, I] = c(!0), [L, ee] = c(null), [U, W] = c(!1), [G, te] = c(!1), [K, J] = c(!1), { saveWithOcc: re, conflictDialog: ie } = We(), ae = s(!1), oe = e.confirmOnDiscard !== !1, se = e.open !== !1, ce = a(), le = o(() => {
1881
2099
  if (e.sections?.length || e.customFields?.length) return null;
1882
- let t = Ne(j, y);
1883
- e.mode === "create" && (t = Fe(t, y));
1884
- let n = Ot(t, y?.fieldGroups);
2100
+ let t = Ne(b, _);
2101
+ e.mode === "create" && (t = Fe(t, _));
2102
+ let n = It(t, _?.fieldGroups);
1885
2103
  if (!n) return null;
1886
2104
  let r = e.columns && e.columns > 0 ? Math.min(Math.floor(e.columns), 4) : Oe(t.length);
1887
2105
  return n.map((e) => ({
@@ -1893,137 +2111,157 @@ var kt = ge({
1893
2111
  e.customFields,
1894
2112
  e.columns,
1895
2113
  e.mode,
1896
- j,
1897
- y
1898
- ]), J = e.sections?.length ? e.sections : pe ?? void 0, Y = a(() => J?.length || e.customFields?.length ? null : Be(j, y, e.columns, e.mode), [
1899
- j,
1900
- y,
2114
+ b,
2115
+ _
2116
+ ]), X = e.sections?.length ? e.sections : le ?? void 0, de = o(() => X?.length || e.customFields?.length ? null : ze(b, _, e.columns, e.mode), [
2117
+ b,
2118
+ _,
1901
2119
  e.columns,
1902
2120
  e.mode,
1903
- J,
2121
+ X,
1904
2122
  e.customFields
1905
- ]), he = At[a(() => {
2123
+ ]), fe = Rt[o(() => {
1906
2124
  if (e.modalSize) return e.modalSize;
1907
- if (Y?.columns && Y.columns > 1) return ze(Y.columns);
1908
- if (J?.length) {
1909
- let e = Math.max(...J.map((e) => Number(e.columns) || 1));
1910
- if (e > 1) return ze(e);
2125
+ if (de?.columns && de.columns > 1) return Re(de.columns);
2126
+ if (X?.length) {
2127
+ let e = Math.max(...X.map((e) => Number(e.columns) || 1));
2128
+ if (e > 1) return Re(e);
1911
2129
  }
1912
2130
  return "default";
1913
2131
  }, [
1914
2132
  e.modalSize,
1915
- Y,
1916
- J
1917
- ])] || At.default;
1918
- r(() => {
2133
+ de,
2134
+ X
2135
+ ])] || Rt.default;
2136
+ i(() => {
1919
2137
  (async () => {
1920
- if (!n) {
1921
- B(!1);
2138
+ if (!t) {
2139
+ I(!1);
1922
2140
  return;
1923
2141
  }
1924
2142
  try {
1925
- let t = await n.getObjectSchema(e.objectName);
1926
- A(t);
2143
+ let n = await t.getObjectSchema(e.objectName);
2144
+ y(n);
1927
2145
  } catch (e) {
1928
- H(e), B(!1);
2146
+ ee(e), I(!1);
1929
2147
  }
1930
2148
  })();
1931
- }, [e.objectName, n]), r(() => {
1932
- (y || !n) && (async () => {
2149
+ }, [e.objectName, t]);
2150
+ let pe = s(void 0);
2151
+ i(() => {
2152
+ let n = !1;
2153
+ return (_ || !t) && (async () => {
1933
2154
  if (e.mode === "create" || !e.recordId) {
1934
- P(e.initialData || e.initialValues || {}), B(!1);
2155
+ P(e.initialData || e.initialValues || {}), I(!1);
1935
2156
  return;
1936
2157
  }
1937
- if (!n) {
1938
- P(e.initialData || e.initialValues || {}), B(!1);
2158
+ if (!t) {
2159
+ P(e.initialData || e.initialValues || {}), I(!1);
1939
2160
  return;
1940
2161
  }
2162
+ pe.current !== e.recordId && (I(!0), te(!1));
1941
2163
  try {
1942
- let t = await n.findOne(e.objectName, e.recordId);
1943
- P(t || {});
2164
+ let r = await t.findOne(e.objectName, e.recordId);
2165
+ if (n) return;
2166
+ pe.current = e.recordId, P(r || {});
1944
2167
  } catch (e) {
1945
- H(e);
2168
+ if (n) return;
2169
+ ee(e);
1946
2170
  } finally {
1947
- B(!1);
2171
+ n || I(!1);
1948
2172
  }
1949
- })();
2173
+ })(), () => {
2174
+ n = !0;
2175
+ };
1950
2176
  }, [
1951
- y,
2177
+ _,
1952
2178
  e.mode,
1953
2179
  e.recordId,
1954
2180
  e.initialData,
1955
2181
  e.initialValues,
1956
- n,
2182
+ t,
1957
2183
  e.objectName
1958
2184
  ]);
1959
- let ge = t((t) => Se(t, {
1960
- objectSchema: y,
2185
+ let me = n((t) => Se(t, {
2186
+ objectSchema: _,
1961
2187
  objectName: e.objectName,
1962
2188
  readOnly: e.readOnly,
1963
2189
  mode: e.mode,
1964
2190
  fieldLabel: l
1965
2191
  }), [
1966
- y,
2192
+ _,
1967
2193
  e.readOnly,
1968
2194
  e.mode,
1969
2195
  e.objectName,
1970
2196
  l
1971
2197
  ]);
1972
- r(() => {
1973
- if (!y && n) return;
2198
+ i(() => {
2199
+ if (!_ && t) return;
1974
2200
  if (e.customFields?.length) {
1975
- M(e.customFields), B(!1);
2201
+ S(e.customFields), I(!1);
1976
2202
  return;
1977
2203
  }
1978
2204
  if (e.sections?.length) {
1979
- B(!1);
2205
+ I(!1);
1980
2206
  return;
1981
2207
  }
1982
- if (!y) return;
1983
- let t = e.fields || Object.keys(y.fields || {}), r = [];
1984
- for (let n of t) {
1985
- let t = typeof n == "string" ? n : n.name;
1986
- if (!t) continue;
1987
- let i = y.fields?.[t];
2208
+ if (!_) return;
2209
+ let n = e.fields || Object.keys(_.fields || {}), r = [];
2210
+ for (let t of n) {
2211
+ let n = typeof t == "string" ? t : t.name;
2212
+ if (!n) continue;
2213
+ let i = _.fields?.[n];
1988
2214
  i && r.push({
1989
- name: t,
1990
- label: l(e.objectName, t, i.label || t),
1991
- type: b(i.type),
2215
+ name: n,
2216
+ label: l(e.objectName, n, i.label || n),
2217
+ type: C(i.type),
1992
2218
  required: i.required || !1,
1993
2219
  disabled: e.readOnly || e.mode === "view" || i.readonly,
1994
2220
  placeholder: i.placeholder,
1995
2221
  description: i.help || i.description,
1996
- validation: v(i),
2222
+ validation: x(i),
1997
2223
  field: i,
1998
2224
  options: i.options,
1999
2225
  multiple: i.multiple,
2000
2226
  visibleWhen: i.visibleWhen,
2001
2227
  readonlyWhen: i.readonlyWhen,
2002
- requiredWhen: i.requiredWhen ?? i.conditionalRequired,
2228
+ requiredWhen: i.requiredWhen,
2003
2229
  group: i.group
2004
2230
  });
2005
2231
  }
2006
- M(r), B(!1);
2232
+ S(r), I(!1);
2007
2233
  }, [
2008
- y,
2234
+ _,
2009
2235
  e.fields,
2010
2236
  e.customFields,
2011
2237
  e.sections,
2012
2238
  e.readOnly,
2013
2239
  e.mode,
2014
- n
2240
+ t
2015
2241
  ]);
2016
- let _e = t(async (t) => {
2242
+ let he = n(async (n) => {
2017
2243
  W(!0);
2018
2244
  try {
2019
- if (!n) return e.onSuccess && await e.onSuccess(t), e.onOpenChange?.(!1), t;
2020
- let r, i = Ke(t, y);
2021
- if (g?.isLoaded) {
2245
+ if (!t) return e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
2246
+ let r, i = $e(n, _);
2247
+ if (p?.isLoaded) {
2022
2248
  let t = {};
2023
- for (let n of Object.keys(i)) g.checkField(e.objectName, n, "write") && (t[n] = i[n]);
2249
+ for (let n of Object.keys(i)) p.checkField(e.objectName, n, "write") && (t[n] = i[n]);
2024
2250
  i = t;
2025
2251
  }
2026
- return e.mode === "create" ? r = await n.create(e.objectName, i) : e.mode === "edit" && e.recordId && (r = await n.update(e.objectName, e.recordId, i)), e.onSuccess && await e.onSuccess(r), e.onOpenChange?.(!1), r;
2252
+ if (e.mode === "create") r = await t.create(e.objectName, i);
2253
+ else if (e.mode === "edit" && e.recordId) {
2254
+ let n = await re({
2255
+ dataSource: t,
2256
+ objectName: e.objectName,
2257
+ recordId: e.recordId,
2258
+ payload: i,
2259
+ baseRecord: N
2260
+ });
2261
+ if (n.status === "cancelled") return;
2262
+ r = n.result;
2263
+ }
2264
+ return e.onSuccess && await e.onSuccess(r), e.onOpenChange?.(!1), r;
2027
2265
  } catch (t) {
2028
2266
  throw e.onError && e.onError(t), t;
2029
2267
  } finally {
@@ -2031,96 +2269,116 @@ var kt = ge({
2031
2269
  }
2032
2270
  }, [
2033
2271
  e,
2034
- n,
2035
- y,
2036
- g
2037
- ]), Q = t(() => {
2038
- ce(!1), q.current && (q.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
2039
- }, [e]), ve = t((e) => {
2040
- q.current = e, ue && te ? ce(!0) : Q();
2272
+ t,
2273
+ _,
2274
+ p,
2275
+ re,
2276
+ N
2277
+ ]), $ = n(() => {
2278
+ J(!1), ae.current && (ae.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
2279
+ }, [e]), ge = n((e) => {
2280
+ ae.current = e, oe && G ? J(!0) : $();
2041
2281
  }, [
2042
- ue,
2043
- te,
2044
- Q
2045
- ]), ye = t(() => {
2046
- q.current = !0, Q();
2047
- }, [Q]), be = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical", xe = e.showSubmit !== !1 && e.mode !== "view", Ce = e.showCancel !== !1, we = e.submitText || (e.mode === "create" ? "Create" : "Update"), Te = e.cancelText || "Cancel", Ee = {
2282
+ oe,
2283
+ G,
2284
+ $
2285
+ ]);
2286
+ i(() => {
2287
+ if (!se || !G || !oe) return;
2288
+ let e = (e) => {
2289
+ e.preventDefault(), e.returnValue = "";
2290
+ };
2291
+ return window.addEventListener("beforeunload", e), () => window.removeEventListener("beforeunload", e);
2292
+ }, [
2293
+ se,
2294
+ G,
2295
+ oe
2296
+ ]);
2297
+ let _e = n(() => {
2298
+ ae.current = !0, $();
2299
+ }, [$]), ve = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical", ye = e.showSubmit !== !1 && e.mode !== "view", be = e.showCancel !== !1, xe = e.submitText || (e.mode === "create" ? "Create" : "Update"), Ce = e.cancelText || "Cancel", we = {
2048
2300
  type: "form",
2049
2301
  objectName: e.objectName,
2050
- layout: be,
2302
+ layout: ve,
2051
2303
  defaultValues: N,
2052
- submitLabel: we,
2053
- cancelLabel: Te,
2054
- showSubmit: xe,
2055
- showCancel: Ce,
2056
- onSubmit: _e,
2057
- onCancel: ye,
2058
- onDirtyChange: ne,
2304
+ submitLabel: xe,
2305
+ cancelLabel: Ce,
2306
+ showSubmit: ye,
2307
+ showCancel: be,
2308
+ onSubmit: he,
2309
+ onCancel: _e,
2310
+ onDirtyChange: te,
2059
2311
  showActions: !1,
2060
- id: fe
2061
- }, De = () => {
2062
- if (V) return /* @__PURE__ */ Z("div", {
2312
+ id: ce
2313
+ }, Te = () => {
2314
+ if (L) return /* @__PURE__ */ Q("div", {
2063
2315
  className: "p-4 border border-red-300 bg-red-50 rounded-md",
2064
- children: [/* @__PURE__ */ X("h3", {
2316
+ children: [/* @__PURE__ */ Z("h3", {
2065
2317
  className: "text-red-800 font-semibold",
2066
2318
  children: "Error loading form"
2067
- }), /* @__PURE__ */ X("p", {
2319
+ }), /* @__PURE__ */ Z("p", {
2068
2320
  className: "text-red-600 text-sm mt-1",
2069
- children: V.message
2321
+ children: L.message
2070
2322
  })]
2071
2323
  });
2072
- if (z) return /* @__PURE__ */ X("div", {
2324
+ if (F) return /* @__PURE__ */ Z("div", {
2073
2325
  className: "space-y-4",
2074
2326
  "data-testid": "modal-form-skeleton",
2075
2327
  children: [
2076
2328
  1,
2077
2329
  2,
2078
2330
  3
2079
- ].map((e) => /* @__PURE__ */ Z("div", {
2331
+ ].map((e) => /* @__PURE__ */ Q("div", {
2080
2332
  className: "space-y-2",
2081
- children: [/* @__PURE__ */ X(re, { className: "h-4 w-24" }), /* @__PURE__ */ X(re, { className: "h-10 w-full" })]
2333
+ children: [/* @__PURE__ */ Z(ne, { className: "h-4 w-24" }), /* @__PURE__ */ Z(ne, { className: "h-10 w-full" })]
2082
2334
  }, e))
2083
2335
  });
2084
2336
  if (e.sections?.length) {
2085
- let t = e.sections, n = (e, t) => e.name || e.label || String(t), r = (t) => t.name ? u(e.objectName, t.name, t.label || t.name) : t.label, i = (e) => /* @__PURE__ */ X(d, { schema: {
2086
- ...Ee,
2087
- ...Re(_(ge(e)), e.columns || 1)
2088
- } });
2089
- return e.contentLayout === "tabbed" && t.length > 1 ? /* @__PURE__ */ Z(ie, {
2090
- defaultValue: n(t[0], 0),
2091
- className: "w-full",
2092
- children: [/* @__PURE__ */ X(oe, {
2093
- className: "mb-4",
2094
- children: t.map((e, t) => /* @__PURE__ */ X(se, {
2095
- value: n(e, t),
2096
- children: r(e) || `Section ${t + 1}`
2097
- }, n(e, t)))
2098
- }), t.map((e, t) => /* @__PURE__ */ X(ae, {
2099
- value: n(e, t),
2100
- children: /* @__PURE__ */ X($, {
2101
- description: e.description,
2102
- columns: 1,
2103
- className: e.className,
2104
- gridClassName: e.gridClassName,
2105
- children: i(e)
2106
- })
2107
- }, n(e, t)))]
2108
- }) : /* @__PURE__ */ X("div", {
2109
- className: "space-y-6",
2110
- children: t.map((e, t) => /* @__PURE__ */ X($, {
2111
- label: r(e),
2337
+ let t = e.sections, n = (e, t) => e.name || e.label || String(t), r = (t) => t.name ? u(e.objectName, t.name, t.label || t.name) : t.label, i = (e) => typeof e == "number" && e > 0 ? Math.min(Math.floor(e), 4) : void 0, a = t.map((e) => i(e.columns)).filter((e) => e != null), o = i(e.columns) ?? (a.length ? Math.max(...a) : 1), s = Ie[o], c = t.map((e, t) => {
2338
+ let a = h(me(e));
2339
+ return {
2340
+ key: n(e, t),
2341
+ title: r(e),
2112
2342
  description: e.description,
2113
- columns: 1,
2114
2343
  className: e.className,
2115
2344
  gridClassName: e.gridClassName,
2116
- children: i(e)
2117
- }, n(e, t)))
2118
- });
2345
+ fields: o > 1 ? je(a, o, i(e.columns)) : a
2346
+ };
2347
+ }).filter((e) => e.fields.length > 0), l = {
2348
+ ...we,
2349
+ columns: o,
2350
+ ...s ? { fieldContainerClass: s } : {}
2351
+ };
2352
+ if (e.contentLayout === "tabbed" && c.length > 1) return /* @__PURE__ */ Z(m, { schema: {
2353
+ ...l,
2354
+ fields: c.flatMap((e) => e.fields),
2355
+ fieldTabs: c.map((e, t) => ({
2356
+ key: e.key,
2357
+ label: e.title || `Section ${t + 1}`,
2358
+ description: e.description,
2359
+ fields: e.fields.map((e) => e.name),
2360
+ containerClass: e.gridClassName
2361
+ }))
2362
+ } });
2363
+ let d = [];
2364
+ return c.forEach((e) => {
2365
+ (e.title || e.description) && d.push({
2366
+ name: `__section_${e.key}`,
2367
+ label: e.title,
2368
+ description: e.description,
2369
+ type: "section-divider",
2370
+ colSpan: 4,
2371
+ className: e.className
2372
+ }), d.push(...e.fields);
2373
+ }), /* @__PURE__ */ Z(m, { schema: {
2374
+ ...l,
2375
+ fields: d
2376
+ } });
2119
2377
  }
2120
- if (pe?.length) {
2121
- let t = Number(pe[0]?.columns) || 1, n = [];
2122
- pe.forEach((r, i) => {
2123
- let a = _(ge(r));
2378
+ if (le?.length) {
2379
+ let t = Number(le[0]?.columns) || 1, n = [];
2380
+ le.forEach((r, i) => {
2381
+ let a = h(me(r));
2124
2382
  if (!a.length) return;
2125
2383
  let o = r.name ? u(e.objectName, r.name, r.label || r.name) : r.label;
2126
2384
  o && n.push({
@@ -2130,48 +2388,48 @@ var kt = ge({
2130
2388
  }), n.push(...t > 1 ? je(a, t) : a);
2131
2389
  });
2132
2390
  let r = Ie[t];
2133
- return /* @__PURE__ */ X(d, { schema: {
2134
- ...Ee,
2391
+ return /* @__PURE__ */ Z(m, { schema: {
2392
+ ...we,
2135
2393
  fields: n,
2136
2394
  columns: t,
2137
2395
  ...r ? { fieldContainerClass: r } : {}
2138
2396
  } });
2139
2397
  }
2140
- let t = Y ?? Be(j, y, e.columns, e.mode), n = Ie[t.columns || 1];
2141
- return /* @__PURE__ */ X(d, { schema: {
2142
- ...Ee,
2143
- fields: _(t.fields),
2398
+ let t = de ?? ze(b, _, e.columns, e.mode), n = Ie[t.columns || 1];
2399
+ return /* @__PURE__ */ Z(m, { schema: {
2400
+ ...we,
2401
+ fields: h(t.fields),
2144
2402
  columns: t.columns,
2145
2403
  ...n ? { fieldContainerClass: n } : {}
2146
2404
  } });
2147
- }, ke = e.subforms;
2148
- if (m) return /* @__PURE__ */ Z("div", {
2405
+ }, Ee = e.subforms;
2406
+ if (f) return /* @__PURE__ */ Q("div", {
2149
2407
  className: "@container rounded-md border bg-card p-4",
2150
- children: [(e.title || e.description) && /* @__PURE__ */ Z("div", {
2408
+ children: [(e.title || e.description) && /* @__PURE__ */ Q("div", {
2151
2409
  className: "mb-3 space-y-0.5",
2152
- children: [e.title && /* @__PURE__ */ X("div", {
2410
+ children: [e.title && /* @__PURE__ */ Z("div", {
2153
2411
  className: "text-sm font-semibold",
2154
2412
  children: e.title
2155
- }), e.description && /* @__PURE__ */ X("p", {
2413
+ }), e.description && /* @__PURE__ */ Z("p", {
2156
2414
  className: "text-xs text-muted-foreground",
2157
2415
  children: e.description
2158
2416
  })]
2159
- }), De()]
2417
+ }), Te()]
2160
2418
  });
2161
- if (ke?.length && e.mode !== "view") return /* @__PURE__ */ X(F, {
2162
- open: de,
2419
+ if (Ee?.length && e.mode !== "view") return /* @__PURE__ */ Z(R, {
2420
+ open: se,
2163
2421
  onOpenChange: e.onOpenChange,
2164
- children: /* @__PURE__ */ Z(R, {
2165
- className: G(he, "flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0", c, e.className),
2166
- children: [(e.title || e.description) && /* @__PURE__ */ Z(L, {
2422
+ children: /* @__PURE__ */ Q(H, {
2423
+ className: q(fe, "flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0", r, e.className),
2424
+ children: [(e.title || e.description) && /* @__PURE__ */ Q(B, {
2167
2425
  className: "shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b",
2168
- children: [e.title && /* @__PURE__ */ X(ee, { children: e.title }), e.description ? /* @__PURE__ */ X(I, { children: e.description }) : /* @__PURE__ */ X(I, {
2426
+ children: [e.title && /* @__PURE__ */ Z(V, { children: e.title }), e.description ? /* @__PURE__ */ Z(z, { children: e.description }) : /* @__PURE__ */ Z(z, {
2169
2427
  className: "sr-only",
2170
2428
  children: "Enter the record and its line items, then save."
2171
2429
  })]
2172
- }), /* @__PURE__ */ X("div", {
2430
+ }), /* @__PURE__ */ Z("div", {
2173
2431
  className: "@container flex-1 overflow-y-auto px-4 sm:px-6 py-4",
2174
- children: /* @__PURE__ */ X(wt, {
2432
+ children: /* @__PURE__ */ Z(Mt, {
2175
2433
  schema: {
2176
2434
  type: "object-master-detail-form",
2177
2435
  objectName: e.objectName,
@@ -2181,109 +2439,119 @@ var kt = ge({
2181
2439
  sections: e.sections,
2182
2440
  initialValues: e.initialValues,
2183
2441
  initialData: e.initialData,
2184
- submitText: we,
2185
- cancelText: Te,
2186
- details: ke,
2442
+ submitText: xe,
2443
+ cancelText: Ce,
2444
+ details: Ee,
2187
2445
  onSuccess: async (t) => {
2188
2446
  await e.onSuccess?.(t), e.onOpenChange?.(!1);
2189
2447
  },
2190
2448
  onError: e.onError,
2191
2449
  onCancel: () => e.onOpenChange?.(!1)
2192
2450
  },
2193
- dataSource: n
2451
+ dataSource: t
2194
2452
  })
2195
2453
  })]
2196
2454
  })
2197
2455
  });
2198
- let Ae = !z && !V && (xe || Ce);
2199
- return /* @__PURE__ */ X(F, {
2200
- open: de,
2456
+ let De = !F && !L && (ye || be);
2457
+ return /* @__PURE__ */ Z(R, {
2458
+ open: se,
2201
2459
  onOpenChange: (t) => {
2202
2460
  if (t) {
2203
2461
  e.onOpenChange?.(!0);
2204
2462
  return;
2205
2463
  }
2206
- ve(!1);
2464
+ ge(!1);
2207
2465
  },
2208
- children: /* @__PURE__ */ Z(R, {
2209
- className: G(he, "flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0", c, e.className),
2466
+ children: /* @__PURE__ */ Q(H, {
2467
+ className: q(fe, "flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0", r, e.className),
2210
2468
  children: [
2211
- (e.title || e.description) && /* @__PURE__ */ Z(L, {
2469
+ (e.title || e.description) && /* @__PURE__ */ Q(B, {
2212
2470
  className: "shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b",
2213
- children: [e.title && /* @__PURE__ */ X(ee, { children: e.title }), e.description ? /* @__PURE__ */ X(I, { children: e.description }) : /* @__PURE__ */ X(I, {
2471
+ children: [e.title && /* @__PURE__ */ Z(V, { children: e.title }), e.description ? /* @__PURE__ */ Z(z, { children: e.description }) : /* @__PURE__ */ Z(z, {
2214
2472
  className: "sr-only",
2215
2473
  children: "Complete the form fields, then submit or cancel."
2216
2474
  })]
2217
2475
  }),
2218
- /* @__PURE__ */ X("div", {
2476
+ /* @__PURE__ */ Z("div", {
2219
2477
  className: "@container flex-1 overflow-y-auto px-4 sm:px-6 py-4",
2220
- children: De()
2478
+ children: Te()
2221
2479
  }),
2222
- Ae && /* @__PURE__ */ X("div", {
2480
+ De && /* @__PURE__ */ Z("div", {
2223
2481
  className: "shrink-0 border-t px-4 sm:px-6 py-3 bg-background",
2224
2482
  "data-testid": "modal-form-footer",
2225
- children: /* @__PURE__ */ Z("div", {
2483
+ children: /* @__PURE__ */ Q("div", {
2226
2484
  className: "flex flex-col sm:flex-row gap-2 sm:justify-end",
2227
- children: [Ce && /* @__PURE__ */ X(k, {
2485
+ children: [be && /* @__PURE__ */ Z(M, {
2228
2486
  type: "button",
2229
2487
  variant: "outline",
2230
- onClick: ye,
2488
+ onClick: _e,
2231
2489
  disabled: U,
2232
2490
  className: "w-full sm:w-auto",
2233
- children: Te
2234
- }), xe && /* @__PURE__ */ Z(k, {
2491
+ children: Ce
2492
+ }), ye && /* @__PURE__ */ Q(M, {
2235
2493
  type: "submit",
2236
- form: fe,
2494
+ form: ce,
2237
2495
  disabled: U,
2238
2496
  className: "w-full sm:w-auto",
2239
- children: [U && /* @__PURE__ */ X(me, { className: "mr-2 h-4 w-4 animate-spin" }), we]
2497
+ children: [U && /* @__PURE__ */ Z(ue, { className: "mr-2 h-4 w-4 animate-spin" }), xe]
2240
2498
  })]
2241
2499
  })
2242
2500
  }),
2243
- /* @__PURE__ */ X(x, {
2501
+ /* @__PURE__ */ Z(w, {
2244
2502
  open: K,
2245
- onOpenChange: ce,
2246
- children: /* @__PURE__ */ Z(w, { children: [/* @__PURE__ */ Z(D, { children: [/* @__PURE__ */ X(O, { children: f("form.discardTitle") }), /* @__PURE__ */ X(T, { children: f("form.discardMessage") })] }), /* @__PURE__ */ Z(E, { children: [/* @__PURE__ */ X(C, {
2503
+ onOpenChange: J,
2504
+ children: /* @__PURE__ */ Q(D, { children: [/* @__PURE__ */ Q(A, { children: [/* @__PURE__ */ Z(j, { children: d("form.discardTitle") }), /* @__PURE__ */ Z(O, { children: d("form.discardMessage") })] }), /* @__PURE__ */ Q(k, { children: [/* @__PURE__ */ Z(E, {
2247
2505
  onClick: () => {
2248
- q.current = !1;
2506
+ ae.current = !1;
2249
2507
  },
2250
- children: f("form.keepEditing")
2251
- }), /* @__PURE__ */ X(S, {
2252
- onClick: Q,
2253
- children: f("form.discard")
2508
+ children: d("form.keepEditing")
2509
+ }), /* @__PURE__ */ Z(T, {
2510
+ onClick: $,
2511
+ children: d("form.discard")
2254
2512
  })] })] })
2255
- })
2513
+ }),
2514
+ ie
2256
2515
  ]
2257
2516
  })
2258
2517
  });
2259
- }, Mt = ({ schema: e, dataSource: t }) => {
2260
- let n = le(), r = a(() => {
2261
- let t = e.groups, r = !e.sections?.length && Array.isArray(t) && t.length ? {
2262
- ...e,
2263
- sections: t.map((e) => ({
2518
+ };
2519
+ //#endregion
2520
+ //#region src/ObjectForm.tsx
2521
+ function Bt(e) {
2522
+ let t = e.buttons, n = e.defaults;
2523
+ if (!t && !n) return e;
2524
+ let r = e, i = { ...r };
2525
+ return t?.submit?.show !== void 0 && r.showSubmit === void 0 && (i.showSubmit = t.submit.show), t?.submit?.label != null && r.submitText === void 0 && (i.submitText = t.submit.label), t?.cancel?.show !== void 0 && r.showCancel === void 0 && (i.showCancel = t.cancel.show), t?.cancel?.label != null && r.cancelText === void 0 && (i.cancelText = t.cancel.label), t?.reset?.show !== void 0 && r.showReset === void 0 && (i.showReset = t.reset.show), n && r.initialValues === void 0 && (i.initialValues = n), i;
2526
+ }
2527
+ var Vt = ({ schema: e, dataSource: t }) => {
2528
+ let n = Y(), r = o(() => {
2529
+ let t = Bt(e), r = t.groups, i = !t.sections?.length && Array.isArray(r) && r.length ? {
2530
+ ...t,
2531
+ sections: r.map((e) => ({
2264
2532
  label: e.title ?? e.label,
2265
2533
  description: e.description,
2266
2534
  collapsible: e.collapsible,
2267
2535
  collapsed: e.defaultCollapsed ?? e.collapsed,
2268
2536
  fields: e.fields ?? []
2269
2537
  }))
2270
- } : e;
2271
- if (!n?.isLoaded) return r;
2272
- let i = (e) => e?.name ? n.checkField(r.objectName, e.name, "read") ? !n.checkField(r.objectName, e.name, "write") && r.mode !== "view" ? {
2538
+ } : t;
2539
+ if (!n?.isLoaded) return i;
2540
+ let a = (e) => e?.name ? n.checkField(i.objectName, e.name, "read") ? !n.checkField(i.objectName, e.name, "write") && i.mode !== "view" ? {
2273
2541
  ...e,
2274
2542
  readOnly: !0,
2275
2543
  disabled: !0
2276
- } : e : null : e, a = (e) => Array.isArray(e) ? e.map(i).filter(Boolean) : e;
2544
+ } : e : null : e, o = (e) => Array.isArray(e) ? e.map(a).filter(Boolean) : e;
2277
2545
  return {
2278
- ...r,
2279
- fields: a(r.fields),
2280
- sections: r.sections?.map((e) => ({
2546
+ ...i,
2547
+ fields: o(i.fields),
2548
+ sections: i.sections?.map((e) => ({
2281
2549
  ...e,
2282
- fields: a(e.fields)
2550
+ fields: o(e.fields)
2283
2551
  }))
2284
2552
  };
2285
- }, [e, n]), { sectionLabel: i } = h(), o = (e) => e?.name ? i(r.objectName, e.name, e.label || e.name) : e?.label;
2286
- if (r.subforms?.length && r.mode !== "view" && r.formType !== "drawer" && r.formType !== "modal") return /* @__PURE__ */ X(wt, {
2553
+ }, [e, n]), { sectionLabel: i } = v(), a = (e) => e?.name ? i(r.objectName, e.name, e.label || e.name) : e?.label;
2554
+ if (r.subforms?.length && r.mode !== "view" && r.formType !== "drawer" && r.formType !== "modal") return /* @__PURE__ */ Z(Mt, {
2287
2555
  schema: {
2288
2556
  type: "object-master-detail-form",
2289
2557
  objectName: r.objectName,
@@ -2306,13 +2574,13 @@ var kt = ge({
2306
2574
  },
2307
2575
  dataSource: t
2308
2576
  });
2309
- if (r.formType === "tabbed" && r.sections?.length) return /* @__PURE__ */ X(Ve, {
2577
+ if (r.formType === "tabbed" && r.sections?.length) return /* @__PURE__ */ Z(Ge, {
2310
2578
  schema: {
2311
2579
  ...r,
2312
2580
  formType: "tabbed",
2313
2581
  sections: r.sections.map((e) => ({
2314
2582
  name: e.name,
2315
- label: o(e),
2583
+ label: a(e),
2316
2584
  description: e.description,
2317
2585
  columns: e.columns,
2318
2586
  fields: e.fields,
@@ -2325,13 +2593,13 @@ var kt = ge({
2325
2593
  dataSource: t,
2326
2594
  className: r.className
2327
2595
  });
2328
- if (r.formType === "wizard" && r.sections?.length) return /* @__PURE__ */ X(He, {
2596
+ if (r.formType === "wizard" && r.sections?.length) return /* @__PURE__ */ Z(Ye, {
2329
2597
  schema: {
2330
2598
  ...r,
2331
2599
  formType: "wizard",
2332
2600
  sections: r.sections.map((e) => ({
2333
2601
  name: e.name,
2334
- label: o(e),
2602
+ label: a(e),
2335
2603
  description: e.description,
2336
2604
  columns: e.columns,
2337
2605
  fields: e.fields,
@@ -2347,16 +2615,17 @@ var kt = ge({
2347
2615
  dataSource: t,
2348
2616
  className: r.className
2349
2617
  });
2350
- if (r.formType === "split" && r.sections?.length) return /* @__PURE__ */ X(Ue, {
2618
+ if (r.formType === "split" && r.sections?.length) return /* @__PURE__ */ Z(Xe, {
2351
2619
  schema: {
2352
2620
  ...r,
2353
2621
  formType: "split",
2354
2622
  sections: r.sections.map((e) => ({
2355
2623
  name: e.name,
2356
- label: o(e),
2624
+ label: a(e),
2357
2625
  description: e.description,
2358
2626
  columns: e.columns,
2359
2627
  fields: e.fields,
2628
+ pane: e.pane,
2360
2629
  className: e.className,
2361
2630
  gridClassName: e.gridClassName
2362
2631
  })),
@@ -2369,14 +2638,14 @@ var kt = ge({
2369
2638
  });
2370
2639
  if (r.formType === "drawer") {
2371
2640
  let { layout: e, ...n } = r, i = r.layout === "vertical" || r.layout === "horizontal" ? r.layout : void 0;
2372
- return /* @__PURE__ */ X(Dt, {
2641
+ return /* @__PURE__ */ Z(Ft, {
2373
2642
  schema: {
2374
2643
  ...n,
2375
2644
  layout: i,
2376
2645
  formType: "drawer",
2377
2646
  sections: r.sections?.map((e) => ({
2378
2647
  name: e.name,
2379
- label: o(e),
2648
+ label: a(e),
2380
2649
  description: e.description,
2381
2650
  columns: e.columns,
2382
2651
  fields: e.fields,
@@ -2395,14 +2664,14 @@ var kt = ge({
2395
2664
  }
2396
2665
  if (r.formType === "modal") {
2397
2666
  let { layout: e, ...n } = r, i = r.layout === "vertical" || r.layout === "horizontal" ? r.layout : void 0;
2398
- return /* @__PURE__ */ X(jt, {
2667
+ return /* @__PURE__ */ Z(zt, {
2399
2668
  schema: {
2400
2669
  ...n,
2401
2670
  layout: i,
2402
2671
  formType: "modal",
2403
2672
  sections: r.sections?.map((e) => ({
2404
2673
  name: e.name,
2405
- label: o(e),
2674
+ label: a(e),
2406
2675
  description: e.description,
2407
2676
  columns: e.columns,
2408
2677
  fields: e.fields,
@@ -2418,65 +2687,65 @@ var kt = ge({
2418
2687
  className: r.className
2419
2688
  });
2420
2689
  }
2421
- return /* @__PURE__ */ X(Nt, {
2690
+ return /* @__PURE__ */ Z(Ht, {
2422
2691
  schema: r,
2423
2692
  dataSource: t
2424
2693
  });
2425
- }, Nt = ({ schema: n, dataSource: i }) => {
2426
- let { fieldLabel: a, sectionLabel: o } = h(), c = ce(), u = le(), f = t((e) => {
2427
- if (!u?.isLoaded) return e;
2428
- let t = [];
2429
- for (let r of e) u.checkField(n.objectName, r.name, "read") && (!u.checkField(n.objectName, r.name, "write") && n.mode !== "view" ? t.push({
2694
+ }, Ht = ({ schema: e, dataSource: r }) => {
2695
+ let { fieldLabel: a, sectionLabel: o } = v(), s = re(), l = Y(), u = n((t) => {
2696
+ if (!l?.isLoaded) return t;
2697
+ let n = [];
2698
+ for (let r of t) l.checkField(e.objectName, r.name, "read") && (!l.checkField(e.objectName, r.name, "write") && e.mode !== "view" ? n.push({
2430
2699
  ...r,
2431
2700
  readOnly: !0,
2432
2701
  disabled: !0,
2433
2702
  description: r.description ?? "You do not have edit access to this field."
2434
- }) : t.push(r));
2435
- return t;
2703
+ }) : n.push(r));
2704
+ return n;
2436
2705
  }, [
2437
- u,
2438
- n.objectName,
2439
- n.mode
2440
- ]), [p, m] = s(null), [g, _] = s([]), [x, S] = s(null), [C, w] = s(!0), [T, E] = s(null), [D, O] = s(null), k = n.customFields && n.customFields.length > 0;
2441
- r(() => {
2442
- k && (S(n.initialData || n.initialValues || {}), w(!1));
2706
+ l,
2707
+ e.objectName,
2708
+ e.mode
2709
+ ]), [f, p] = c(null), [h, g] = c([]), [_, y] = c(null), [b, w] = c(!0), [T, E] = c(null), [D, O] = c(null), { saveWithOcc: k, conflictDialog: A } = We(), j = e.customFields && e.customFields.length > 0;
2710
+ i(() => {
2711
+ j && (y(e.initialData || e.initialValues || {}), w(!1));
2443
2712
  }, [
2444
- k,
2445
- n.initialData,
2446
- n.initialValues
2447
- ]), r(() => {
2448
- k ? m({
2449
- name: n.objectName,
2713
+ j,
2714
+ e.initialData,
2715
+ e.initialValues
2716
+ ]), i(() => {
2717
+ j ? p({
2718
+ name: e.objectName,
2450
2719
  fields: {}
2451
- }) : n.objectName && i ? (async () => {
2720
+ }) : e.objectName && r ? (async () => {
2452
2721
  try {
2453
- if (!i) throw Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");
2454
- let e = await i.getObjectSchema(n.objectName);
2455
- if (!e) throw Error(`No schema found for object "${n.objectName}"`);
2456
- m(e);
2722
+ if (!r) throw Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");
2723
+ let t = await r.getObjectSchema(e.objectName);
2724
+ if (!t) throw Error(`No schema found for object "${e.objectName}"`);
2725
+ p(t);
2457
2726
  } catch (e) {
2458
2727
  E(e), w(!1);
2459
2728
  }
2460
- })() : k || w(!1);
2729
+ })() : j || w(!1);
2461
2730
  }, [
2462
- n.objectName,
2463
- i,
2464
- k
2465
- ]), r(() => {
2466
- p && !k && (async () => {
2467
- if (!n.recordId || n.mode === "create") {
2468
- S(n.initialData || n.initialValues || {}), w(!1);
2731
+ e.objectName,
2732
+ r,
2733
+ j
2734
+ ]), i(() => {
2735
+ f && !j && (async () => {
2736
+ if (!e.recordId || e.mode === "create") {
2737
+ y(e.initialData || e.initialValues || {}), w(!1);
2469
2738
  return;
2470
2739
  }
2471
- if (!k) {
2472
- if (!i) {
2740
+ if (!j) {
2741
+ if (!r) {
2473
2742
  E(/* @__PURE__ */ Error("DataSource is required for fetching record data (inline data not provided)")), w(!1);
2474
2743
  return;
2475
2744
  }
2476
2745
  w(!0);
2477
2746
  try {
2478
- let e = await i.findOne(n.objectName, n.recordId);
2479
- S(e);
2747
+ let t = await r.findOne(e.objectName, e.recordId);
2748
+ y(t);
2480
2749
  } catch (e) {
2481
2750
  console.error("Failed to fetch record:", e), E(e);
2482
2751
  } finally {
@@ -2485,269 +2754,280 @@ var kt = ge({
2485
2754
  }
2486
2755
  })();
2487
2756
  }, [
2488
- n.objectName,
2489
- n.recordId,
2490
- n.mode,
2491
- n.initialValues,
2492
- n.initialData,
2493
- i,
2494
- p,
2495
- k
2757
+ e.objectName,
2758
+ e.recordId,
2759
+ e.mode,
2760
+ e.initialValues,
2761
+ e.initialData,
2762
+ r,
2763
+ f,
2764
+ j
2496
2765
  ]);
2497
- let A = t((e) => e, []);
2498
- r(() => {
2499
- if (k && n.customFields) {
2500
- _(n.customFields.map(A)), w(!1);
2766
+ let M = n((e) => e, []);
2767
+ i(() => {
2768
+ if (j && e.customFields) {
2769
+ g(e.customFields.map(M)), w(!1);
2501
2770
  return;
2502
2771
  }
2503
- if (!p) return;
2504
- let e = [], t = l(p), r = !(n.mode === "edit" ? t.edit : n.mode !== "create" || t.create), o = n.fields || Object.keys(p.fields || {});
2505
- (Array.isArray(o) ? o : Object.keys(o)).forEach((t) => {
2506
- let i = typeof t == "string" ? t : t.name;
2507
- if (!i) return;
2508
- let o = p.fields?.[i];
2509
- if (!o && !k) return;
2510
- let s = !o?.permissions || o?.permissions.write !== !1;
2511
- if (n.mode !== "view" && !s) return;
2512
- let c = n.customFields?.find((e) => e.name === i);
2513
- if (c) e.push(A(c));
2772
+ if (!f) return;
2773
+ let t = [], n = d(f, l?.getObjectApiOperations?.(e.objectName)), i = !(e.mode === "edit" ? n.edit : e.mode !== "create" || n.create), o = e.fields || Object.keys(f.fields || {});
2774
+ (Array.isArray(o) ? o : Object.keys(o)).forEach((n) => {
2775
+ let r = typeof n == "string" ? n : n.name;
2776
+ if (!r) return;
2777
+ let o = f.fields?.[r];
2778
+ if (!o && !j) return;
2779
+ let s = e.customFields?.find((e) => e.name === r);
2780
+ if (s) t.push(M(s));
2514
2781
  else if (o) {
2515
2782
  let s = {
2516
- name: i,
2517
- label: a(n.objectName, i, o.label || t),
2518
- type: b(o.type),
2783
+ name: r,
2784
+ label: a(e.objectName, r, o.label || n),
2785
+ type: C(o.type),
2519
2786
  required: o.required || !1,
2520
- disabled: n.readOnly || n.mode === "view" || o.readonly || r,
2787
+ disabled: e.readOnly || e.mode === "view" || o.readonly || i,
2521
2788
  placeholder: o.placeholder,
2522
2789
  description: o.help || o.description,
2523
- validation: v(o),
2790
+ validation: x(o),
2524
2791
  visibleWhen: o.visibleWhen,
2525
2792
  readonlyWhen: o.readonlyWhen,
2526
- requiredWhen: o.requiredWhen ?? o.conditionalRequired,
2793
+ requiredWhen: o.requiredWhen,
2527
2794
  group: o.group,
2528
2795
  field: o,
2529
2796
  widget: o.widget
2530
2797
  };
2531
- if ((o.type === "select" || o.type === "lookup" || o.type === "master_detail") && (s.options = o.options || [], s.multiple = o.multiple), (o.type === "number" || o.type === "currency" || o.type === "percent") && (s.inputType = "number", s.min = o.min, s.max = o.max, s.step = o.precision ? 10 ** -o.precision : void 0), o.type === "date" && (s.inputType = "date"), o.type === "datetime" && (s.inputType = "datetime-local"), (o.type === "text" || o.type === "textarea" || o.type === "markdown" || o.type === "html") && (s.maxLength = o.max_length, s.minLength = o.min_length), (o.type === "file" || o.type === "image") && (s.inputType = "file", s.multiple = o.multiple, s.accept = o.accept ? o.accept.join(",") : void 0, o.max_size)) {
2532
- let e = `Max size: ${y(o.max_size)}`;
2798
+ if ((o.type === "select" || o.type === "lookup" || o.type === "master_detail") && (s.options = o.options || [], s.multiple = o.multiple), (o.type === "number" || o.type === "currency" || o.type === "percent") && (s.inputType = "number", s.min = o.min, s.max = o.max, s.step = o.precision ? 10 ** -o.precision : void 0), o.type === "date" && (s.inputType = "date"), o.type === "datetime" && (s.inputType = "datetime-local"), (o.type === "text" || o.type === "textarea" || o.type === "markdown" || o.type === "html") && (s.maxLength = o.maxLength ?? o.max_length, s.minLength = o.minLength ?? o.min_length), (o.type === "file" || o.type === "image") && (s.inputType = "file", s.multiple = o.multiple, s.accept = o.accept ? o.accept.join(",") : void 0, o.max_size)) {
2799
+ let e = `Max size: ${S(o.max_size)}`;
2533
2800
  s.description = s.description ? `${s.description} (${e})` : e;
2534
2801
  }
2535
- o.type === "email" && (s.inputType = "email"), o.type === "phone" && (s.inputType = "tel"), o.type === "url" && (s.inputType = "url"), o.type === "password" && (s.inputType = "password"), o.type === "time" && (s.inputType = "time"), (o.type === "formula" || o.type === "summary" || o.type === "auto_number") && (s.disabled = !0), o.visible_on && (s.visibleOn = o.visible_on), e.push(s);
2802
+ o.type === "email" && (s.inputType = "email"), o.type === "phone" && (s.inputType = "tel"), o.type === "url" && (s.inputType = "url"), o.type === "password" && (s.inputType = "password"), o.type === "time" && (s.inputType = "time"), (o.type === "formula" || o.type === "summary" || o.type === "auto_number") && (s.disabled = !0), o.visible_on && (s.visibleOn = o.visible_on), t.push(s);
2536
2803
  }
2537
- }), _(e), !k && n.recordId && n.mode !== "create" && i || w(!1);
2804
+ }), g(t), !j && e.recordId && e.mode !== "create" && r || w(!1);
2538
2805
  }, [
2539
- p,
2540
- n.fields,
2541
- n.customFields,
2542
- n.readOnly,
2543
- n.mode,
2544
- k,
2545
- n.recordId,
2546
- i
2806
+ f,
2807
+ e.fields,
2808
+ e.customFields,
2809
+ e.readOnly,
2810
+ e.mode,
2811
+ e.objectName,
2812
+ j,
2813
+ e.recordId,
2814
+ r,
2815
+ l
2547
2816
  ]);
2548
- let j = t(async (e, t) => {
2549
- if (e && (e.nativeEvent || e._reactName === "onSubmit") && (console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."), t === void 0 && (e = {})), k && !i) return n.onSuccess && await n.onSuccess(e), e;
2550
- if (!i) throw Error("DataSource is required for form submission (inline mode not configured)");
2551
- let r = Ke(e, k ? null : p);
2552
- if (u?.isLoaded && r && typeof r == "object") {
2553
- let e = {};
2554
- for (let t of Object.keys(r)) u.checkField(n.objectName, t, "write") && (e[t] = r[t]);
2555
- r = e;
2817
+ let N = n(async (t, n) => {
2818
+ if (t && (t.nativeEvent || t._reactName === "onSubmit") && (console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."), n === void 0 && (t = {})), j && !r) return e.onSuccess && await e.onSuccess(t), t;
2819
+ if (!r) throw Error("DataSource is required for form submission (inline mode not configured)");
2820
+ let i = $e(t, j ? null : f);
2821
+ if (l?.isLoaded && i && typeof i == "object") {
2822
+ let t = {};
2823
+ for (let n of Object.keys(i)) l.checkField(e.objectName, n, "write") && (t[n] = i[n]);
2824
+ i = t;
2556
2825
  }
2557
2826
  try {
2558
- let e;
2559
- if (n.submitHandler) e = await n.submitHandler(r);
2560
- else if (n.mode === "create") e = await i.create(n.objectName, r);
2561
- else if (n.mode === "edit" && n.recordId) e = await i.update(n.objectName, n.recordId, r);
2562
- else throw Error("Invalid form mode or missing record ID");
2563
- if (n.onSuccess) await n.onSuccess(e);
2564
- else if (!n.submitHandler && n.submitBehavior) {
2565
- let e = n.submitBehavior;
2566
- switch (e.kind) {
2827
+ let t;
2828
+ if (e.submitHandler) t = await e.submitHandler(i);
2829
+ else if (e.mode === "create") t = await r.create(e.objectName, i);
2830
+ else if (e.mode === "edit" && e.recordId) {
2831
+ let n = await k({
2832
+ dataSource: r,
2833
+ objectName: e.objectName,
2834
+ recordId: e.recordId,
2835
+ payload: i,
2836
+ baseRecord: _
2837
+ });
2838
+ if (n.status === "cancelled") return;
2839
+ t = n.result;
2840
+ } else throw Error("Invalid form mode or missing record ID");
2841
+ if (e.onSuccess) await e.onSuccess(t);
2842
+ else if (!e.submitHandler && e.submitBehavior) {
2843
+ let t = e.submitBehavior;
2844
+ switch (t.kind) {
2567
2845
  case "redirect":
2568
- Q(e.url) && setTimeout(() => window.location.assign(e.url), e.delayMs ?? 0);
2846
+ $(t.url) && setTimeout(() => window.location.assign(t.url), t.delayMs ?? 0);
2569
2847
  break;
2570
2848
  case "continue": break;
2571
2849
  default: {
2572
- let t = e.kind === "thank-you" && e.message ? e.message : n.successMessage || (n.mode === "create" ? "Created" : "Saved");
2573
- K.success(t), O({
2574
- title: e.kind === "thank-you" ? e.title : void 0,
2575
- message: t
2850
+ let n = t.kind === "thank-you" && t.message ? t.message : e.successMessage || (e.mode === "create" ? "Created" : "Saved");
2851
+ J.success(n), O({
2852
+ title: t.kind === "thank-you" ? t.title : void 0,
2853
+ message: n
2576
2854
  });
2577
2855
  break;
2578
2856
  }
2579
2857
  }
2580
- } else if (!n.submitHandler) {
2581
- let t = ve(n.navigateOnSuccess, e);
2582
- if (t) return window.location.assign(t), e;
2583
- K.success(n.successMessage || (n.mode === "create" ? "Created" : "Saved"));
2858
+ } else if (!e.submitHandler) {
2859
+ let n = ge(e.navigateOnSuccess, t);
2860
+ if (n) return window.location.assign(n), t;
2861
+ J.success(e.successMessage || (e.mode === "create" ? "Created" : "Saved"));
2584
2862
  }
2585
- return e;
2586
- } catch (e) {
2587
- throw console.error("Failed to submit form:", e), n.onError && n.onError(e), e;
2863
+ return t;
2864
+ } catch (t) {
2865
+ throw console.error("Failed to submit form:", t), e.onError && e.onError(t), t;
2588
2866
  }
2589
2867
  }, [
2590
- n,
2591
- i,
2868
+ e,
2869
+ r,
2870
+ j,
2871
+ l,
2872
+ f,
2592
2873
  k,
2593
- u,
2594
- p
2595
- ]), M = t(() => {
2596
- n.onCancel && n.onCancel();
2597
- }, [n]), N = {
2598
- ...e.useMemo(() => {
2599
- if (!p?.fields) return {};
2874
+ _
2875
+ ]), P = n(() => {
2876
+ e.onCancel && e.onCancel();
2877
+ }, [e]), F = {
2878
+ ...t.useMemo(() => {
2879
+ if (!f?.fields) return {};
2600
2880
  let e = {};
2601
- return Object.keys(p.fields).forEach((t) => {
2602
- let n = p.fields[t];
2881
+ return Object.keys(f.fields).forEach((t) => {
2882
+ let n = f.fields[t];
2603
2883
  n.defaultValue !== void 0 && (e[t] = n.defaultValue);
2604
2884
  }), e;
2605
- }, [p]),
2606
- ...x
2607
- }, P = e.useMemo(() => {
2608
- let e = Ne(g, p);
2609
- return n.mode === "create" && (e = Fe(e, p)), e;
2885
+ }, [f]),
2886
+ ..._
2887
+ }, I = t.useMemo(() => {
2888
+ let t = Ne(h, f);
2889
+ return e.mode === "create" && (t = Fe(t, f)), t;
2610
2890
  }, [
2611
- g,
2612
- p,
2613
- n.mode
2614
- ]), F = e.useMemo(() => n.sections?.length ? null : Ot(P, p?.fieldGroups), [
2615
- n.sections,
2616
- P,
2617
- p
2618
- ]), I = n.sections?.length ? n.sections : F, [L, ee] = s({});
2619
- if (T) return /* @__PURE__ */ Z("div", {
2891
+ h,
2892
+ f,
2893
+ e.mode
2894
+ ]), L = t.useMemo(() => e.sections?.length ? null : It(I, f?.fieldGroups), [
2895
+ e.sections,
2896
+ I,
2897
+ f
2898
+ ]), R = e.sections?.length ? e.sections : L, [z, B] = c({});
2899
+ if (T) return /* @__PURE__ */ Q("div", {
2620
2900
  className: "p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",
2621
- children: [/* @__PURE__ */ X("h3", {
2901
+ children: [/* @__PURE__ */ Z("h3", {
2622
2902
  className: "text-red-800 font-semibold",
2623
2903
  children: "Error loading form"
2624
- }), /* @__PURE__ */ X("p", {
2904
+ }), /* @__PURE__ */ Z("p", {
2625
2905
  className: "text-red-600 text-sm mt-1",
2626
2906
  children: T.message
2627
2907
  })]
2628
2908
  });
2629
- if (C) return /* @__PURE__ */ Z("div", {
2909
+ if (b) return /* @__PURE__ */ Q("div", {
2630
2910
  className: "p-4 sm:p-8 text-center",
2631
- children: [/* @__PURE__ */ X("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ X("p", {
2911
+ children: [/* @__PURE__ */ Z("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ Z("p", {
2632
2912
  className: "mt-2 text-sm text-gray-600",
2633
2913
  children: "Loading form..."
2634
2914
  })]
2635
2915
  });
2636
- if (D) return /* @__PURE__ */ Z("div", {
2916
+ if (D) return /* @__PURE__ */ Q("div", {
2637
2917
  className: "rounded-md border bg-card p-6 sm:p-8 text-center",
2638
- children: [/* @__PURE__ */ X("h3", {
2918
+ children: [/* @__PURE__ */ Z("h3", {
2639
2919
  className: "text-lg font-semibold",
2640
2920
  children: D.title ?? "Thanks!"
2641
- }), D.message && /* @__PURE__ */ X("p", {
2921
+ }), D.message && /* @__PURE__ */ Z("p", {
2642
2922
  className: "mt-2 text-sm text-muted-foreground",
2643
2923
  children: D.message
2644
2924
  })]
2645
2925
  });
2646
- let R = n.layout === "vertical" || n.layout === "horizontal" ? n.layout : "vertical";
2647
- if (I?.length && (!n.formType || n.formType === "simple")) {
2648
- let e = F ? P : g, t = (e) => typeof e == "number" && e > 0 ? Math.min(Math.floor(e), 4) : void 0, r = I.map((e) => t(e.columns)).filter((e) => e != null), i = I.reduce((e, t) => e + (Array.isArray(t.fields) ? t.fields.length : 0), 0), a = t(n.columns) ?? (r.length ? Math.max(...r) : Oe(i)), s = [];
2649
- I.forEach((r, i) => {
2650
- let c = new Map(r.fields.map((e) => [typeof e == "string" ? e : e.field ?? e.name, e])), l = Array.from(c.keys()), u = f(e.filter((e) => l.includes(e.name))).map((e) => {
2926
+ let V = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical";
2927
+ if (R?.length && (!e.formType || e.formType === "simple")) {
2928
+ let t = L ? I : h, n = (e) => typeof e == "number" && e > 0 ? Math.min(Math.floor(e), 4) : void 0, r = R.map((e) => n(e.columns)).filter((e) => e != null), i = R.reduce((e, t) => e + (Array.isArray(t.fields) ? t.fields.length : 0), 0), a = n(e.columns) ?? (r.length ? Math.max(...r) : Oe(i)), s = [];
2929
+ R.forEach((r, i) => {
2930
+ let c = new Map(r.fields.map((e) => [typeof e == "string" ? e : e.field ?? e.name, e])), l = Array.from(c.keys()), d = u(t.filter((e) => l.includes(e.name))).map((e) => {
2651
2931
  let t = c.get(e.name);
2652
2932
  if (!t || typeof t != "object") return e;
2653
2933
  let n = t, r = { ...e };
2654
2934
  return n.visibleOn != null && (r.visibleOn = n.visibleOn), n.colSpan != null && (r.colSpan = n.colSpan), n.span != null && (r.span = n.span), r;
2655
2935
  });
2656
- if (u.length === 0) return;
2657
- let d = r.name || r.label || String(i), p = r.name ? o(n.objectName, r.name, r.label || r.name) : r.label, m = L[d] ?? r.collapsed ?? !1;
2936
+ if (d.length === 0) return;
2937
+ let f = r.name || r.label || String(i), p = r.name ? o(e.objectName, r.name, r.label || r.name) : r.label, m = z[f] ?? r.collapsed ?? !1;
2658
2938
  p && s.push({
2659
- name: `__section_${d}`,
2939
+ name: `__section_${f}`,
2660
2940
  label: p,
2661
2941
  type: "section-divider",
2662
2942
  colSpan: 4,
2663
2943
  collapsible: r.collapsible,
2664
2944
  collapsed: m,
2665
- onToggle: r.collapsible ? () => ee((e) => ({
2945
+ onToggle: r.collapsible ? () => B((e) => ({
2666
2946
  ...e,
2667
- [d]: !m
2947
+ [f]: !m
2668
2948
  })) : void 0,
2669
2949
  className: r.className
2670
2950
  });
2671
- let h = t(r.columns), g = a > 1 ? je(u, a, h) : u;
2951
+ let h = n(r.columns), g = a > 1 ? je(d, a, h) : d;
2672
2952
  p && m ? s.push(...g.map((e) => ({
2673
2953
  ...e,
2674
2954
  hidden: !0
2675
2955
  }))) : s.push(...g);
2676
2956
  });
2677
2957
  let c = s, l = Le(a);
2678
- return /* @__PURE__ */ X("div", {
2958
+ return /* @__PURE__ */ Q("div", {
2679
2959
  className: "w-full @container",
2680
- children: /* @__PURE__ */ X(d, { schema: {
2960
+ children: [/* @__PURE__ */ Z(m, { schema: {
2681
2961
  type: "form",
2682
- objectName: n.objectName,
2962
+ objectName: e.objectName,
2683
2963
  fields: c,
2684
- layout: R,
2964
+ layout: V,
2685
2965
  columns: a,
2686
2966
  ...l ? { fieldContainerClass: l } : {},
2687
- defaultValues: N,
2688
- showSubmit: n.showSubmit !== !1 && n.mode !== "view",
2689
- showCancel: n.showCancel !== !1,
2690
- submitLabel: n.submitText || (n.mode === "create" ? "Create" : "Update"),
2691
- cancelLabel: n.cancelText,
2692
- onSubmit: j,
2693
- onCancel: M
2694
- } })
2967
+ defaultValues: F,
2968
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
2969
+ showCancel: e.showCancel !== !1,
2970
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
2971
+ cancelLabel: e.cancelText,
2972
+ onSubmit: N,
2973
+ onCancel: P
2974
+ } }), A]
2695
2975
  });
2696
2976
  }
2697
- let z = n.sections?.length, B = f(g), V = z ? {
2698
- fields: B,
2699
- columns: n.columns
2700
- } : Be(B, p, n.columns, n.mode), H = n.mobile, U = H?.fullscreenLongText ? V.fields.map((e) => {
2977
+ let H = e.sections?.length, ee = u(h), U = H ? {
2978
+ fields: ee,
2979
+ columns: e.columns
2980
+ } : ze(ee, f, e.columns, e.mode), W = e.mobile, G = W?.fullscreenLongText ? U.fields.map((e) => {
2701
2981
  let t = e.type;
2702
2982
  return t === "textarea" || t === "field:textarea" || t === "string-multiline" || t === "field:markdown" || t === "field:html" ? {
2703
2983
  ...e,
2704
2984
  mobile_fullscreen: !0
2705
2985
  } : e;
2706
- }) : V.fields, W = H?.stepper, te = H?.stepperMinFields ?? 8, ne = Math.max(1, H?.stepperFieldsPerStep ?? 1);
2707
- if (!n.formType && !z && U.length >= 2 && (W === !0 || W === "auto" && c && U.length >= te)) {
2708
- let e = U, t = [];
2709
- for (let n = 0; n < e.length; n += ne) {
2710
- let r = e.slice(n, n + ne);
2711
- t.push({
2712
- name: `step-${Math.floor(n / ne) + 1}`,
2713
- label: r[0]?.label || r[0]?.name || `Step ${Math.floor(n / ne) + 1}`,
2986
+ }) : U.fields, te = W?.stepper, ne = W?.stepperMinFields ?? 8, K = Math.max(1, W?.stepperFieldsPerStep ?? 1);
2987
+ if (!e.formType && !H && G.length >= 2 && (te === !0 || te === "auto" && s && G.length >= ne)) {
2988
+ let t = G, n = [];
2989
+ for (let e = 0; e < t.length; e += K) {
2990
+ let r = t.slice(e, e + K);
2991
+ n.push({
2992
+ name: `step-${Math.floor(e / K) + 1}`,
2993
+ label: r[0]?.label || r[0]?.name || `Step ${Math.floor(e / K) + 1}`,
2714
2994
  fields: r
2715
2995
  });
2716
2996
  }
2717
- return /* @__PURE__ */ X(He, {
2997
+ return /* @__PURE__ */ Z(Ye, {
2718
2998
  schema: {
2719
- ...n,
2999
+ ...e,
2720
3000
  formType: "wizard",
2721
- sections: t,
3001
+ sections: n,
2722
3002
  showStepIndicator: !0
2723
3003
  },
2724
- dataSource: i,
2725
- className: n.className
3004
+ dataSource: r,
3005
+ className: e.className
2726
3006
  });
2727
3007
  }
2728
- let re = {
3008
+ let q = {
2729
3009
  type: "form",
2730
- objectName: n.objectName,
2731
- fields: U,
2732
- layout: R,
2733
- columns: V.columns,
2734
- submitLabel: n.submitText || (n.mode === "create" ? "Create" : "Update"),
2735
- cancelLabel: n.cancelText,
2736
- showSubmit: n.showSubmit !== !1 && n.mode !== "view",
2737
- showCancel: n.showCancel !== !1,
2738
- resetOnSubmit: n.showReset || n.submitBehavior?.kind === "continue" || !n.submitBehavior && n.resetOnSuccess && n.mode === "create",
2739
- defaultValues: N,
2740
- onSubmit: j,
2741
- onCancel: M,
2742
- className: n.className,
2743
- mobileStickyActions: !!H?.stickyActions
3010
+ objectName: e.objectName,
3011
+ fields: G,
3012
+ layout: V,
3013
+ columns: U.columns,
3014
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
3015
+ cancelLabel: e.cancelText,
3016
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
3017
+ showCancel: e.showCancel !== !1,
3018
+ resetOnSubmit: e.showReset || e.submitBehavior?.kind === "continue" || !e.submitBehavior && e.resetOnSuccess && e.mode === "create",
3019
+ defaultValues: F,
3020
+ onSubmit: N,
3021
+ onCancel: P,
3022
+ className: e.className,
3023
+ mobileStickyActions: !!W?.stickyActions
2744
3024
  };
2745
- return /* @__PURE__ */ X("div", {
2746
- className: H?.stickyActions ? "w-full pb-20 md:pb-0" : "w-full",
2747
- "data-mobile-form": H ? "true" : void 0,
2748
- children: /* @__PURE__ */ X(d, { schema: re })
3025
+ return /* @__PURE__ */ Q("div", {
3026
+ className: W?.stickyActions ? "w-full pb-20 md:pb-0" : "w-full",
3027
+ "data-mobile-form": W ? "true" : void 0,
3028
+ children: [/* @__PURE__ */ Z(m, { schema: q }), A]
2749
3029
  });
2750
- }, Pt = {
3030
+ }, Ut = {
2751
3031
  text: 200,
2752
3032
  email: 254,
2753
3033
  url: 2048,
@@ -2755,8 +3035,8 @@ var kt = ge({
2755
3035
  textarea: 5e3,
2756
3036
  markdown: 5e3,
2757
3037
  html: 5e3
2758
- }, Ft = "_company_website_2", It = 1500;
2759
- function Lt(e, t = []) {
3038
+ }, Wt = "_company_website_2", Gt = 1500;
3039
+ function Kt(e, t = []) {
2760
3040
  try {
2761
3041
  let n = new URL(e, typeof window < "u" ? window.location.href : "http://localhost");
2762
3042
  return typeof window < "u" && n.origin === window.location.origin ? !0 : n.protocol !== "https:" && n.protocol !== "http:" ? !1 : t.some((e) => {
@@ -2771,36 +3051,36 @@ function Lt(e, t = []) {
2771
3051
  return !1;
2772
3052
  }
2773
3053
  }
2774
- function Rt(e) {
3054
+ function qt(e) {
2775
3055
  return e && e.map((e) => {
2776
- let t = Pt[String(e.type || "").toLowerCase()];
3056
+ let t = Ut[String(e.type || "").toLowerCase()];
2777
3057
  return !t || (e.maxLength ?? e.max_length) ? e : {
2778
3058
  ...e,
2779
3059
  maxLength: t
2780
3060
  };
2781
3061
  });
2782
3062
  }
2783
- var zt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
2784
- let [l, u] = s(!1), [d, f] = s(!1), [p, m] = s(null), [h, g] = s(!(e.consent?.required ?? !!e.consent)), [_, v] = s(null), y = o(null), b = o(0);
2785
- r(() => {
3063
+ var Jt = ({ config: e, dataSource: t, prefillParams: r, className: a }) => {
3064
+ let [l, u] = c(!1), [d, f] = c(!1), [p, m] = c(null), [h, g] = c(!(e.consent?.required ?? !!e.consent)), [_, v] = c(null), y = s(null), b = s(0);
3065
+ i(() => {
2786
3066
  l || (b.current = Date.now());
2787
3067
  }, [l]);
2788
- let x = e.honeypot === !1 ? null : e.honeypot || Ft, S = e.minFillTime ?? It, C = a(() => Rt(e.customFields), [e.customFields]), w = a(() => {
2789
- if (!n || C && C.length > 0 || !e.fields || e.fields.length === 0) return;
2790
- let t = async (e, t) => t;
3068
+ let x = e.honeypot === !1 ? null : e.honeypot || Wt, S = e.minFillTime ?? Gt, C = o(() => qt(e.customFields), [e.customFields]), w = o(() => {
3069
+ if (!t || C && C.length > 0 || !e.fields || e.fields.length === 0) return;
3070
+ let n = async (e, t) => t;
2791
3071
  return {
2792
- ...n,
2793
- create: t,
3072
+ ...t,
3073
+ create: n,
2794
3074
  update: (e, t, n) => Promise.resolve(n),
2795
3075
  delete: () => Promise.reject(/* @__PURE__ */ Error("Not permitted on public form"))
2796
3076
  };
2797
3077
  }, [
2798
- n,
3078
+ t,
2799
3079
  C,
2800
3080
  e.fields
2801
- ]), T = a(() => {
3081
+ ]), T = o(() => {
2802
3082
  let t = {};
2803
- if (i) for (let [e, n] of Object.entries(i)) t[e] = n;
3083
+ if (r) for (let [e, n] of Object.entries(r)) t[e] = n;
2804
3084
  if (typeof window < "u" && e.allowedPrefillFields?.length) {
2805
3085
  let n = new Set(e.allowedPrefillFields);
2806
3086
  new URLSearchParams(window.location.search).forEach((e, r) => {
@@ -2808,7 +3088,7 @@ var zt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
2808
3088
  });
2809
3089
  }
2810
3090
  return Object.keys(t).length > 0 ? t : void 0;
2811
- }, [i, e.allowedPrefillFields]), E = t(async (t) => {
3091
+ }, [r, e.allowedPrefillFields]), E = n(async (n) => {
2812
3092
  if (e.consent?.required && !h) {
2813
3093
  v(e.texts?.consentRequired ?? "Please accept the privacy policy to continue.");
2814
3094
  return;
@@ -2821,65 +3101,65 @@ var zt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
2821
3101
  m(e.texts?.rateLimited ?? "Please take a moment to review your answers before submitting.");
2822
3102
  return;
2823
3103
  }
2824
- let r = { ...t };
3104
+ let r = { ...n };
2825
3105
  x && delete r[x], e.captchaToken && (r._captcha = e.captchaToken), f(!0), m(null);
2826
3106
  try {
2827
- n && await n.create(e.objectName, r), u(!0);
2828
- let t = e.thankYouPage?.redirectUrl;
2829
- if (t) if (Lt(t, e.allowedRedirectHosts)) {
2830
- let n = e.thankYouPage?.redirectDelay ?? 3e3;
3107
+ t && await t.create(e.objectName, r), u(!0);
3108
+ let n = e.thankYouPage?.redirectUrl;
3109
+ if (n) if (Kt(n, e.allowedRedirectHosts)) {
3110
+ let t = e.thankYouPage?.redirectDelay ?? 3e3;
2831
3111
  setTimeout(() => {
2832
- window.location.href = t;
2833
- }, n);
2834
- } else console.warn("[EmbeddableForm] Blocked unsafe redirect target:", t), m(e.texts?.redirectBlocked ?? null);
3112
+ window.location.href = n;
3113
+ }, t);
3114
+ } else console.warn("[EmbeddableForm] Blocked unsafe redirect target:", n), m(e.texts?.redirectBlocked ?? null);
2835
3115
  } catch (e) {
2836
3116
  m(e instanceof Error ? e.message : "Failed to submit form. Please try again.");
2837
3117
  } finally {
2838
3118
  f(!1);
2839
3119
  }
2840
3120
  }, [
2841
- n,
3121
+ t,
2842
3122
  e,
2843
3123
  h,
2844
3124
  x,
2845
3125
  S
2846
- ]), D = t(() => {
3126
+ ]), D = n(() => {
2847
3127
  u(!1), m(null);
2848
- }, []), O = a(() => {
3128
+ }, []), O = o(() => {
2849
3129
  let t = {};
2850
3130
  return e.branding?.backgroundColor && (t.backgroundColor = e.branding.backgroundColor), t;
2851
3131
  }, [e.branding]);
2852
3132
  if (l) {
2853
3133
  let t = e.thankYouPage, n = e.texts ?? {}, r = Math.ceil((t?.redirectDelay ?? 3e3) / 1e3), i = (n.redirecting ?? "Redirecting in {{seconds}} seconds…").replace("{{seconds}}", String(r));
2854
- return /* @__PURE__ */ X("div", {
2855
- className: `min-h-screen flex items-center justify-center p-4 bg-gradient-to-b from-muted/40 via-background to-background ${c || ""}`,
3134
+ return /* @__PURE__ */ Z("div", {
3135
+ className: `min-h-screen flex items-center justify-center p-4 bg-gradient-to-b from-muted/40 via-background to-background ${a || ""}`,
2856
3136
  style: O,
2857
- children: /* @__PURE__ */ Z("div", {
3137
+ children: /* @__PURE__ */ Q("div", {
2858
3138
  className: "max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4",
2859
3139
  children: [
2860
- /* @__PURE__ */ X("div", {
3140
+ /* @__PURE__ */ Z("div", {
2861
3141
  className: "mx-auto inline-flex h-14 w-14 items-center justify-center rounded-full bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400",
2862
- children: /* @__PURE__ */ X(ue, {
3142
+ children: /* @__PURE__ */ Z(se, {
2863
3143
  className: "h-8 w-8",
2864
3144
  "aria-hidden": "true"
2865
3145
  })
2866
3146
  }),
2867
- /* @__PURE__ */ X("h2", {
3147
+ /* @__PURE__ */ Z("h2", {
2868
3148
  className: "text-xl font-semibold text-foreground",
2869
3149
  children: t?.title || n.thankYouTitle || "Thank You!"
2870
3150
  }),
2871
- /* @__PURE__ */ X("p", {
3151
+ /* @__PURE__ */ Z("p", {
2872
3152
  className: "text-sm text-muted-foreground",
2873
3153
  children: t?.message || n.thankYouMessage || "Your submission has been received successfully."
2874
3154
  }),
2875
- e.allowMultiple && /* @__PURE__ */ X(k, {
3155
+ e.allowMultiple && /* @__PURE__ */ Z(M, {
2876
3156
  variant: "outline",
2877
3157
  size: "sm",
2878
3158
  onClick: D,
2879
3159
  className: "mt-2",
2880
3160
  children: n.submitAnother ?? "Submit Another Response"
2881
3161
  }),
2882
- t?.redirectUrl && /* @__PURE__ */ X("p", {
3162
+ t?.redirectUrl && /* @__PURE__ */ Z("p", {
2883
3163
  className: "text-xs text-muted-foreground",
2884
3164
  children: i
2885
3165
  })
@@ -2887,52 +3167,52 @@ var zt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
2887
3167
  })
2888
3168
  });
2889
3169
  }
2890
- let A = e.texts ?? {}, j = !!e.consent?.required, M = `${e.formId}-consent`;
2891
- return /* @__PURE__ */ X("div", {
2892
- className: `min-h-screen flex items-center justify-center p-4 sm:p-6 bg-gradient-to-b from-muted/40 via-background to-background ${c || ""}`,
3170
+ let k = e.texts ?? {}, A = !!e.consent?.required, j = `${e.formId}-consent`;
3171
+ return /* @__PURE__ */ Z("div", {
3172
+ className: `min-h-screen flex items-center justify-center p-4 sm:p-6 bg-gradient-to-b from-muted/40 via-background to-background ${a || ""}`,
2893
3173
  style: O,
2894
- children: /* @__PURE__ */ Z("div", {
3174
+ children: /* @__PURE__ */ Q("div", {
2895
3175
  className: "max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden",
2896
3176
  children: [
2897
- e.branding?.coverImage && /* @__PURE__ */ X("div", {
3177
+ e.branding?.coverImage && /* @__PURE__ */ Z("div", {
2898
3178
  className: "h-28 sm:h-32 w-full bg-cover bg-center",
2899
3179
  style: { backgroundImage: `url(${JSON.stringify(e.branding.coverImage)})` },
2900
3180
  role: "presentation"
2901
3181
  }),
2902
- /* @__PURE__ */ Z("div", {
3182
+ /* @__PURE__ */ Q("div", {
2903
3183
  className: "px-6 sm:px-8 pt-7 pb-5 border-b bg-muted/20",
2904
3184
  style: e.branding?.primaryColor ? { borderBottomColor: e.branding.primaryColor } : void 0,
2905
3185
  children: [
2906
- e.branding?.logo && /* @__PURE__ */ X("img", {
3186
+ e.branding?.logo && /* @__PURE__ */ Z("img", {
2907
3187
  src: e.branding.logo,
2908
3188
  alt: "",
2909
3189
  className: "h-8 mb-4"
2910
3190
  }),
2911
- e.title && /* @__PURE__ */ X("h1", {
3191
+ e.title && /* @__PURE__ */ Z("h1", {
2912
3192
  className: "text-2xl font-semibold tracking-tight text-foreground",
2913
3193
  children: e.title
2914
3194
  }),
2915
- e.description && /* @__PURE__ */ X("p", {
3195
+ e.description && /* @__PURE__ */ Z("p", {
2916
3196
  className: "text-sm text-muted-foreground mt-2 leading-relaxed",
2917
3197
  children: e.description
2918
3198
  }),
2919
- /* @__PURE__ */ X("p", {
3199
+ /* @__PURE__ */ Z("p", {
2920
3200
  className: "text-[11px] text-muted-foreground/70 mt-3",
2921
3201
  "aria-hidden": "true",
2922
- children: A.requiredHint ?? "* Required field"
3202
+ children: k.requiredHint ?? "* Required field"
2923
3203
  })
2924
3204
  ]
2925
3205
  }),
2926
- /* @__PURE__ */ Z("div", {
3206
+ /* @__PURE__ */ Q("div", {
2927
3207
  className: "relative px-6 sm:px-8 py-6",
2928
3208
  children: [
2929
- p && /* @__PURE__ */ X("div", {
3209
+ p && /* @__PURE__ */ Z("div", {
2930
3210
  role: "alert",
2931
3211
  "aria-live": "assertive",
2932
3212
  className: "mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive",
2933
3213
  children: p
2934
3214
  }),
2935
- /* @__PURE__ */ X(Mt, {
3215
+ /* @__PURE__ */ Z(Vt, {
2936
3216
  schema: {
2937
3217
  type: "object-form",
2938
3218
  objectName: e.objectName,
@@ -2941,17 +3221,17 @@ var zt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
2941
3221
  customFields: C,
2942
3222
  initialData: T,
2943
3223
  onSuccess: E,
2944
- submitText: d ? A.submitting ?? "Submitting..." : A.submit ?? "Submit"
3224
+ submitText: d ? k.submitting ?? "Submitting..." : k.submit ?? "Submit"
2945
3225
  },
2946
3226
  dataSource: w
2947
3227
  }),
2948
- x && /* @__PURE__ */ Z("div", {
3228
+ x && /* @__PURE__ */ Q("div", {
2949
3229
  "aria-hidden": "true",
2950
3230
  className: "absolute left-[-10000px] top-auto h-px w-px overflow-hidden",
2951
- children: [/* @__PURE__ */ X("label", {
3231
+ children: [/* @__PURE__ */ Z("label", {
2952
3232
  htmlFor: `${e.formId}-${x}`,
2953
3233
  children: "Do not fill this field"
2954
- }), /* @__PURE__ */ X("input", {
3234
+ }), /* @__PURE__ */ Z("input", {
2955
3235
  ref: y,
2956
3236
  id: `${e.formId}-${x}`,
2957
3237
  type: "text",
@@ -2961,75 +3241,75 @@ var zt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
2961
3241
  defaultValue: ""
2962
3242
  })]
2963
3243
  }),
2964
- e.consent && /* @__PURE__ */ Z("div", {
3244
+ e.consent && /* @__PURE__ */ Q("div", {
2965
3245
  className: "mt-4",
2966
- children: [/* @__PURE__ */ Z("label", {
3246
+ children: [/* @__PURE__ */ Q("label", {
2967
3247
  className: "flex items-start gap-2 text-sm text-foreground cursor-pointer select-none",
2968
- children: [/* @__PURE__ */ X("input", {
3248
+ children: [/* @__PURE__ */ Z("input", {
2969
3249
  type: "checkbox",
2970
- id: M,
3250
+ id: j,
2971
3251
  checked: h,
2972
3252
  onChange: (e) => {
2973
3253
  g(e.target.checked), e.target.checked && v(null);
2974
3254
  },
2975
- "aria-required": j || void 0,
3255
+ "aria-required": A || void 0,
2976
3256
  "aria-invalid": _ ? "true" : void 0,
2977
- "aria-describedby": _ ? `${M}-error` : void 0,
3257
+ "aria-describedby": _ ? `${j}-error` : void 0,
2978
3258
  className: "mt-0.5 h-4 w-4 rounded border-input accent-primary"
2979
- }), /* @__PURE__ */ Z("span", {
3259
+ }), /* @__PURE__ */ Q("span", {
2980
3260
  className: "leading-relaxed",
2981
3261
  children: [
2982
- e.consent.label ?? A.consentLabelDefault ?? "I agree to the privacy policy.",
2983
- j && /* @__PURE__ */ X("span", {
3262
+ e.consent.label ?? k.consentLabelDefault ?? "I agree to the privacy policy.",
3263
+ A && /* @__PURE__ */ Z("span", {
2984
3264
  "aria-hidden": "true",
2985
3265
  className: "text-destructive ml-0.5",
2986
3266
  children: "*"
2987
3267
  }),
2988
- e.consent.privacyUrl && /* @__PURE__ */ Z(he, { children: [" ", /* @__PURE__ */ X("a", {
3268
+ e.consent.privacyUrl && /* @__PURE__ */ Q(me, { children: [" ", /* @__PURE__ */ Z("a", {
2989
3269
  href: e.consent.privacyUrl,
2990
3270
  target: "_blank",
2991
3271
  rel: "noopener noreferrer",
2992
3272
  className: "underline text-primary hover:opacity-80",
2993
- children: A.consentLink ?? "Privacy policy"
3273
+ children: k.consentLink ?? "Privacy policy"
2994
3274
  })] })
2995
3275
  ]
2996
3276
  })]
2997
- }), _ && /* @__PURE__ */ X("p", {
2998
- id: `${M}-error`,
3277
+ }), _ && /* @__PURE__ */ Z("p", {
3278
+ id: `${j}-error`,
2999
3279
  role: "alert",
3000
3280
  className: "mt-1.5 text-xs text-destructive",
3001
3281
  children: _
3002
3282
  })]
3003
3283
  }),
3004
- d && /* @__PURE__ */ Z("div", {
3284
+ d && /* @__PURE__ */ Q("div", {
3005
3285
  className: "mt-3 flex items-center gap-2 text-xs text-muted-foreground",
3006
- children: [/* @__PURE__ */ X(me, {
3286
+ children: [/* @__PURE__ */ Z(ue, {
3007
3287
  className: "h-3.5 w-3.5 animate-spin",
3008
3288
  "aria-hidden": "true"
3009
- }), /* @__PURE__ */ X("span", { children: A.submitting ?? "Submitting…" })]
3289
+ }), /* @__PURE__ */ Z("span", { children: k.submitting ?? "Submitting…" })]
3010
3290
  })
3011
3291
  ]
3012
3292
  }),
3013
- /* @__PURE__ */ Z("div", {
3293
+ /* @__PURE__ */ Q("div", {
3014
3294
  className: "px-6 sm:px-8 py-4 border-t bg-muted/20 flex flex-col sm:flex-row items-center justify-between gap-2",
3015
- children: [/* @__PURE__ */ Z("p", {
3295
+ children: [/* @__PURE__ */ Q("p", {
3016
3296
  className: "inline-flex items-center gap-1.5 text-xs text-muted-foreground",
3017
- children: [/* @__PURE__ */ X(J, {
3297
+ children: [/* @__PURE__ */ Z(de, {
3018
3298
  className: "h-3 w-3",
3019
3299
  "aria-hidden": "true"
3020
- }), /* @__PURE__ */ X("span", { children: A.secureNotice ?? "Your information is transmitted securely and only used to respond to your request." })]
3021
- }), /* @__PURE__ */ Z("div", {
3300
+ }), /* @__PURE__ */ Z("span", { children: k.secureNotice ?? "Your information is transmitted securely and only used to respond to your request." })]
3301
+ }), /* @__PURE__ */ Q("div", {
3022
3302
  className: "flex items-center gap-3 text-xs text-muted-foreground/80",
3023
- children: [e.privacyPolicyUrl && /* @__PURE__ */ Z("a", {
3303
+ children: [e.privacyPolicyUrl && /* @__PURE__ */ Q("a", {
3024
3304
  href: e.privacyPolicyUrl,
3025
3305
  target: "_blank",
3026
3306
  rel: "noopener noreferrer",
3027
3307
  className: "inline-flex items-center gap-1 underline hover:text-foreground",
3028
- children: [/* @__PURE__ */ X(Y, {
3308
+ children: [/* @__PURE__ */ Z(fe, {
3029
3309
  className: "h-3 w-3",
3030
3310
  "aria-hidden": "true"
3031
- }), A.consentLink ?? "Privacy policy"]
3032
- }), /* @__PURE__ */ X("span", { children: A.poweredBy ?? "Powered by ObjectStack" })]
3311
+ }), k.consentLink ?? "Privacy policy"]
3312
+ }), /* @__PURE__ */ Z("span", { children: k.poweredBy ?? "Powered by ObjectStack" })]
3033
3313
  })]
3034
3314
  })
3035
3315
  ]
@@ -3038,96 +3318,96 @@ var zt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
3038
3318
  };
3039
3319
  //#endregion
3040
3320
  //#region src/FormAnalytics.tsx
3041
- function Bt(e) {
3321
+ function Yt(e) {
3042
3322
  return e < 60 ? `${Math.round(e)}s` : e < 3600 ? `${Math.floor(e / 60)}m ${Math.round(e % 60)}s` : `${Math.floor(e / 3600)}h ${Math.floor(e % 3600 / 60)}m`;
3043
3323
  }
3044
- var Vt = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
3045
- let i = a(() => {
3324
+ var Xt = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
3325
+ let i = o(() => {
3046
3326
  if (!n.abandonedSubmissions) return 100;
3047
3327
  let e = n.totalSubmissions + n.abandonedSubmissions;
3048
3328
  return e === 0 ? 0 : Math.round(n.totalSubmissions / e * 100);
3049
- }, [n.totalSubmissions, n.abandonedSubmissions]), o = a(() => n.dailySubmissions?.length ? Math.max(...n.dailySubmissions.map((e) => e.count), 1) : 1, [n.dailySubmissions]);
3050
- return /* @__PURE__ */ Z("div", {
3329
+ }, [n.totalSubmissions, n.abandonedSubmissions]), a = o(() => n.dailySubmissions?.length ? Math.max(...n.dailySubmissions.map((e) => e.count), 1) : 1, [n.dailySubmissions]);
3330
+ return /* @__PURE__ */ Q("div", {
3051
3331
  className: `space-y-4 ${r || ""}`,
3052
3332
  children: [
3053
- /* @__PURE__ */ Z("div", { children: [/* @__PURE__ */ X("h2", {
3333
+ /* @__PURE__ */ Q("div", { children: [/* @__PURE__ */ Z("h2", {
3054
3334
  className: "text-lg font-semibold text-foreground",
3055
3335
  children: t || "Form Analytics"
3056
- }), /* @__PURE__ */ Z("p", {
3336
+ }), /* @__PURE__ */ Q("p", {
3057
3337
  className: "text-sm text-muted-foreground",
3058
3338
  children: ["Form ID: ", e]
3059
3339
  })] }),
3060
- /* @__PURE__ */ Z("div", {
3340
+ /* @__PURE__ */ Q("div", {
3061
3341
  className: "grid grid-cols-1 sm:grid-cols-3 gap-4",
3062
3342
  children: [
3063
- /* @__PURE__ */ X(A, { children: /* @__PURE__ */ Z(N, {
3343
+ /* @__PURE__ */ Z(N, { children: /* @__PURE__ */ Q(I, {
3064
3344
  className: "pb-2",
3065
- children: [/* @__PURE__ */ X(M, { children: "Total Submissions" }), /* @__PURE__ */ X(P, {
3345
+ children: [/* @__PURE__ */ Z(F, { children: "Total Submissions" }), /* @__PURE__ */ Z(L, {
3066
3346
  className: "text-2xl",
3067
3347
  children: n.totalSubmissions.toLocaleString()
3068
3348
  })]
3069
3349
  }) }),
3070
- /* @__PURE__ */ Z(A, { children: [/* @__PURE__ */ Z(N, {
3350
+ /* @__PURE__ */ Q(N, { children: [/* @__PURE__ */ Q(I, {
3071
3351
  className: "pb-2",
3072
- children: [/* @__PURE__ */ X(M, { children: "Fill Rate" }), /* @__PURE__ */ Z(P, {
3352
+ children: [/* @__PURE__ */ Z(F, { children: "Fill Rate" }), /* @__PURE__ */ Q(L, {
3073
3353
  className: "text-2xl",
3074
3354
  children: [i, "%"]
3075
3355
  })]
3076
- }), /* @__PURE__ */ X(j, { children: /* @__PURE__ */ X("div", {
3356
+ }), /* @__PURE__ */ Z(P, { children: /* @__PURE__ */ Z("div", {
3077
3357
  className: "w-full bg-muted rounded-full h-2",
3078
- children: /* @__PURE__ */ X("div", {
3358
+ children: /* @__PURE__ */ Z("div", {
3079
3359
  className: "bg-primary rounded-full h-2 transition-all",
3080
3360
  style: { width: `${i}%` }
3081
3361
  })
3082
3362
  }) })] }),
3083
- /* @__PURE__ */ X(A, { children: /* @__PURE__ */ Z(N, {
3363
+ /* @__PURE__ */ Z(N, { children: /* @__PURE__ */ Q(I, {
3084
3364
  className: "pb-2",
3085
- children: [/* @__PURE__ */ X(M, { children: "Avg. Completion Time" }), /* @__PURE__ */ X(P, {
3365
+ children: [/* @__PURE__ */ Z(F, { children: "Avg. Completion Time" }), /* @__PURE__ */ Z(L, {
3086
3366
  className: "text-2xl",
3087
- children: n.avgCompletionTime ? Bt(n.avgCompletionTime) : "—"
3367
+ children: n.avgCompletionTime ? Yt(n.avgCompletionTime) : "—"
3088
3368
  })]
3089
3369
  }) })
3090
3370
  ]
3091
3371
  }),
3092
- n.dailySubmissions && n.dailySubmissions.length > 0 && /* @__PURE__ */ Z(A, { children: [/* @__PURE__ */ X(N, { children: /* @__PURE__ */ X(P, {
3372
+ n.dailySubmissions && n.dailySubmissions.length > 0 && /* @__PURE__ */ Q(N, { children: [/* @__PURE__ */ Z(I, { children: /* @__PURE__ */ Z(L, {
3093
3373
  className: "text-sm font-medium",
3094
3374
  children: "Daily Submissions"
3095
- }) }), /* @__PURE__ */ X(j, { children: /* @__PURE__ */ X("div", {
3375
+ }) }), /* @__PURE__ */ Z(P, { children: /* @__PURE__ */ Z("div", {
3096
3376
  className: "flex items-end gap-1 h-32",
3097
- children: n.dailySubmissions.map((e, t) => /* @__PURE__ */ Z("div", {
3377
+ children: n.dailySubmissions.map((e, t) => /* @__PURE__ */ Q("div", {
3098
3378
  className: "flex-1 flex flex-col items-center gap-1",
3099
- children: [/* @__PURE__ */ X("div", {
3379
+ children: [/* @__PURE__ */ Z("div", {
3100
3380
  className: "w-full bg-primary/80 rounded-t transition-all hover:bg-primary",
3101
3381
  style: {
3102
- height: `${e.count / o * 100}%`,
3382
+ height: `${e.count / a * 100}%`,
3103
3383
  minHeight: e.count > 0 ? "4px" : "0"
3104
3384
  },
3105
3385
  title: `${e.date}: ${e.count} submissions`
3106
- }), /* @__PURE__ */ X("span", {
3386
+ }), /* @__PURE__ */ Z("span", {
3107
3387
  className: "text-[10px] text-muted-foreground truncate w-full text-center",
3108
3388
  children: e.date.slice(-5)
3109
3389
  })]
3110
3390
  }, t))
3111
3391
  }) })] }),
3112
- n.fieldDropOff && n.fieldDropOff.length > 0 && /* @__PURE__ */ Z(A, { children: [/* @__PURE__ */ Z(N, { children: [/* @__PURE__ */ X(P, {
3392
+ n.fieldDropOff && n.fieldDropOff.length > 0 && /* @__PURE__ */ Q(N, { children: [/* @__PURE__ */ Q(I, { children: [/* @__PURE__ */ Z(L, {
3113
3393
  className: "text-sm font-medium",
3114
3394
  children: "Field Completion Rates"
3115
- }), /* @__PURE__ */ X(M, { children: "Percentage of users who completed each field" })] }), /* @__PURE__ */ X(j, { children: /* @__PURE__ */ X("div", {
3395
+ }), /* @__PURE__ */ Z(F, { children: "Percentage of users who completed each field" })] }), /* @__PURE__ */ Z(P, { children: /* @__PURE__ */ Z("div", {
3116
3396
  className: "space-y-3",
3117
- children: n.fieldDropOff.map((e, t) => /* @__PURE__ */ Z("div", {
3397
+ children: n.fieldDropOff.map((e, t) => /* @__PURE__ */ Q("div", {
3118
3398
  className: "space-y-1",
3119
- children: [/* @__PURE__ */ Z("div", {
3399
+ children: [/* @__PURE__ */ Q("div", {
3120
3400
  className: "flex justify-between text-sm",
3121
- children: [/* @__PURE__ */ X("span", {
3401
+ children: [/* @__PURE__ */ Z("span", {
3122
3402
  className: "text-foreground",
3123
3403
  children: e.label
3124
- }), /* @__PURE__ */ Z("span", {
3404
+ }), /* @__PURE__ */ Q("span", {
3125
3405
  className: "text-muted-foreground",
3126
3406
  children: [e.completionRate, "%"]
3127
3407
  })]
3128
- }), /* @__PURE__ */ X("div", {
3408
+ }), /* @__PURE__ */ Z("div", {
3129
3409
  className: "w-full bg-muted rounded-full h-1.5",
3130
- children: /* @__PURE__ */ X("div", {
3410
+ children: /* @__PURE__ */ Z("div", {
3131
3411
  className: `rounded-full h-1.5 transition-all ${e.completionRate >= 80 ? "bg-green-500" : e.completionRate >= 50 ? "bg-yellow-500" : "bg-destructive"}`,
3132
3412
  style: { width: `${e.completionRate}%` }
3133
3413
  })
@@ -3136,76 +3416,76 @@ var Vt = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
3136
3416
  }) })] })
3137
3417
  ]
3138
3418
  });
3139
- }, Ht = ({ schema: e }) => {
3140
- let n = g()?.dataSource, i = m(), o = e.parentObject || i?.objectName, c = e.parentId || e.recordId || i?.recordId, [l, d] = s([]), [f, p] = s([]), [h, v] = s(!0), [y, b] = s(!1), [x, S] = s(!1), [C, w] = s(null), [T, E] = s(null);
3141
- r(() => {
3142
- let t = n;
3143
- if (!t || typeof t.getObjectSchema != "function") return;
3419
+ }, Zt = ({ schema: e }) => {
3420
+ let t = y()?.dataSource, r = _(), a = e.parentObject || r?.objectName, s = e.parentId || e.recordId || r?.recordId, [l, u] = c([]), [d, f] = c([]), [m, h] = c(!0), [g, v] = c(!1), [x, S] = c(!1), [C, w] = c(null), [T, E] = c(null);
3421
+ i(() => {
3422
+ let n = t;
3423
+ if (!n || typeof n.getObjectSchema != "function") return;
3144
3424
  let r = !1;
3145
- return t.getObjectSchema(e.childObject).then((e) => {
3425
+ return n.getObjectSchema(e.childObject).then((e) => {
3146
3426
  r || E(e ?? null);
3147
3427
  }).catch(() => {
3148
3428
  r || E(null);
3149
3429
  }), () => {
3150
3430
  r = !0;
3151
3431
  };
3152
- }, [n, e.childObject]);
3153
- let D = t(async () => {
3154
- if (!n || !c) {
3155
- v(!1);
3432
+ }, [t, e.childObject]);
3433
+ let D = n(async () => {
3434
+ if (!t || !s) {
3435
+ h(!1);
3156
3436
  return;
3157
3437
  }
3158
- v(!0);
3438
+ h(!0);
3159
3439
  try {
3160
- let t = (await n.find(e.childObject, {
3161
- $filter: { [e.relationshipField]: c },
3440
+ let n = (await t.find(e.childObject, {
3441
+ $filter: { [e.relationshipField]: s },
3162
3442
  $top: 500
3163
3443
  }))?.data ?? [];
3164
- d(t.map((e) => ({ ...e }))), p(t.map((e) => ({ ...e }))), S(!1);
3444
+ u(n.map((e) => ({ ...e }))), f(n.map((e) => ({ ...e }))), S(!1);
3165
3445
  } catch (e) {
3166
3446
  w(e?.message || "Failed to load line items");
3167
3447
  } finally {
3168
- v(!1);
3448
+ h(!1);
3169
3449
  }
3170
3450
  }, [
3171
- n,
3172
- c,
3451
+ t,
3452
+ s,
3173
3453
  e.childObject,
3174
3454
  e.relationshipField
3175
3455
  ]);
3176
- r(() => {
3456
+ i(() => {
3177
3457
  D();
3178
3458
  }, [D]);
3179
- let O = t((e) => {
3180
- d(e), S(!0);
3181
- }, []), M = t(async () => {
3182
- if (!(!n || !c)) {
3183
- b(!0), w(null);
3459
+ let O = n((e) => {
3460
+ u(e), S(!0);
3461
+ }, []), k = n(async () => {
3462
+ if (!(!t || !s)) {
3463
+ v(!0), w(null);
3184
3464
  try {
3185
- let t = !!(o && e.totalField), r = t ? { [e.totalField]: et(l, e.amountField || "amount") } : {}, i = Qe(o ?? "", c, r, [{
3465
+ let n = !!(a && e.totalField), r = n ? { [e.totalField]: st(l, e.amountField || "amount") } : {}, i = at(a ?? "", s, r, [{
3186
3466
  childObject: e.childObject,
3187
3467
  relationshipField: e.relationshipField,
3188
3468
  rows: l,
3189
- original: f,
3469
+ original: d,
3190
3470
  childSchema: T
3191
3471
  }]);
3192
- t || (i = i.slice(1)), i.length && await u(n, i), await D();
3472
+ n || (i = i.slice(1)), i.length && await p(t, i), await D();
3193
3473
  } catch (e) {
3194
3474
  w(e?.message || "Failed to save line items");
3195
3475
  } finally {
3196
- b(!1);
3476
+ v(!1);
3197
3477
  }
3198
3478
  }
3199
3479
  }, [
3200
- n,
3201
- c,
3480
+ t,
3481
+ s,
3202
3482
  l,
3203
- f,
3483
+ d,
3204
3484
  e,
3205
- o,
3485
+ a,
3206
3486
  D,
3207
3487
  T
3208
- ]), F = a(() => ({
3488
+ ]), A = o(() => ({
3209
3489
  columns: e.columns,
3210
3490
  total_field: e.totalField ? e.amountField || "amount" : void 0,
3211
3491
  min_rows: e.minRows,
@@ -3213,41 +3493,41 @@ var Vt = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
3213
3493
  allow_add: !e.readonly,
3214
3494
  allow_delete: !e.readonly
3215
3495
  }), [e]);
3216
- return /* @__PURE__ */ Z(A, {
3217
- className: G("shadow-none"),
3218
- children: [/* @__PURE__ */ Z(N, {
3496
+ return /* @__PURE__ */ Q(N, {
3497
+ className: q("shadow-none"),
3498
+ children: [/* @__PURE__ */ Q(I, {
3219
3499
  className: "flex-row items-center justify-between gap-2 pb-2",
3220
- children: [/* @__PURE__ */ X(P, {
3500
+ children: [/* @__PURE__ */ Z(L, {
3221
3501
  className: "text-sm font-medium",
3222
3502
  children: e.title || "Line Items"
3223
- }), !e.readonly && /* @__PURE__ */ X(k, {
3503
+ }), !e.readonly && /* @__PURE__ */ Z(M, {
3224
3504
  type: "button",
3225
3505
  size: "sm",
3226
- onClick: M,
3227
- disabled: y || h || !x || !c,
3228
- children: y ? "Saving…" : "Save"
3506
+ onClick: k,
3507
+ disabled: g || m || !x || !s,
3508
+ children: g ? "Saving…" : "Save"
3229
3509
  })]
3230
- }), /* @__PURE__ */ Z(j, { children: [C && /* @__PURE__ */ X("p", {
3510
+ }), /* @__PURE__ */ Q(P, { children: [C && /* @__PURE__ */ Z("p", {
3231
3511
  className: "mb-2 text-sm text-destructive",
3232
3512
  children: C
3233
- }), h ? /* @__PURE__ */ X("p", {
3513
+ }), m ? /* @__PURE__ */ Z("p", {
3234
3514
  className: "py-6 text-center text-sm text-muted-foreground",
3235
3515
  children: "Loading…"
3236
- }) : c ? /* @__PURE__ */ X(_, {
3516
+ }) : s ? /* @__PURE__ */ Z(b, {
3237
3517
  value: l,
3238
3518
  onChange: O,
3239
- field: F,
3519
+ field: A,
3240
3520
  readonly: e.readonly
3241
- }) : /* @__PURE__ */ X("p", {
3521
+ }) : /* @__PURE__ */ Z("p", {
3242
3522
  className: "py-6 text-center text-sm text-muted-foreground",
3243
3523
  children: "Save the record first to add line items."
3244
3524
  })] })]
3245
3525
  });
3246
- }, Ut = ({ schema: e }) => /* @__PURE__ */ X(Mt, {
3526
+ }, Qt = ({ schema: e }) => /* @__PURE__ */ Z(Vt, {
3247
3527
  schema: e,
3248
- dataSource: n(f)?.dataSource ?? void 0
3528
+ dataSource: r(h)?.dataSource ?? void 0
3249
3529
  });
3250
- c.register("object-form", Ut, {
3530
+ l.register("object-form", Qt, {
3251
3531
  namespace: "plugin-form",
3252
3532
  label: "Object Form",
3253
3533
  category: "plugin",
@@ -3388,7 +3668,7 @@ c.register("object-form", Ut, {
3388
3668
  ]
3389
3669
  }
3390
3670
  ]
3391
- }), c.register("form", Ut, {
3671
+ }), l.register("form", Qt, {
3392
3672
  namespace: "view",
3393
3673
  skipFallback: !0,
3394
3674
  label: "Data Form View",
@@ -3416,7 +3696,7 @@ c.register("object-form", Ut, {
3416
3696
  ]
3417
3697
  }
3418
3698
  ]
3419
- }), c.register("embeddable-form", ({ schema: e }) => /* @__PURE__ */ X(zt, { config: e }), {
3699
+ }), l.register("embeddable-form", ({ schema: e }) => /* @__PURE__ */ Z(Jt, { config: e }), {
3420
3700
  namespace: "plugin-form",
3421
3701
  label: "Embeddable Form",
3422
3702
  category: "plugin",
@@ -3454,7 +3734,7 @@ c.register("object-form", Ut, {
3454
3734
  label: "Allow Multiple Submissions"
3455
3735
  }
3456
3736
  ]
3457
- }), c.register("form-analytics", ({ schema: e }) => /* @__PURE__ */ X(Vt, {
3737
+ }), l.register("form-analytics", ({ schema: e }) => /* @__PURE__ */ Z(Xt, {
3458
3738
  formId: e.formId,
3459
3739
  formTitle: e.formTitle,
3460
3740
  metrics: e.metrics || { totalSubmissions: 0 }
@@ -3480,9 +3760,9 @@ c.register("object-form", Ut, {
3480
3760
  label: "Submission Metrics"
3481
3761
  }
3482
3762
  ]
3483
- }), c.register("object-master-detail-form", ({ schema: e }) => /* @__PURE__ */ X(wt, {
3763
+ }), l.register("object-master-detail-form", ({ schema: e }) => /* @__PURE__ */ Z(Mt, {
3484
3764
  schema: e,
3485
- dataSource: n(f)?.dataSource ?? void 0
3765
+ dataSource: r(h)?.dataSource ?? void 0
3486
3766
  }), {
3487
3767
  namespace: "plugin-form",
3488
3768
  label: "Master-Detail Form",
@@ -3512,7 +3792,7 @@ c.register("object-form", Ut, {
3512
3792
  required: !0
3513
3793
  }
3514
3794
  ]
3515
- }), c.register("line_items", ({ schema: e }) => /* @__PURE__ */ X(Ht, { schema: e }), {
3795
+ }), l.register("line_items", ({ schema: e }) => /* @__PURE__ */ Z(Zt, { schema: e }), {
3516
3796
  namespace: "record",
3517
3797
  skipFallback: !0,
3518
3798
  label: "Line Items",
@@ -3549,4 +3829,4 @@ c.register("object-form", Ut, {
3549
3829
  ]
3550
3830
  });
3551
3831
  //#endregion
3552
- export { Dt as DrawerForm, zt as EmbeddableForm, Vt as FormAnalytics, $ as FormSection, Ht as LineItemsPanel, wt as MasterDetailForm, jt as ModalForm, Mt as ObjectForm, Ue as SplitForm, Ve as TabbedForm, He as WizardForm, je as applyAutoColSpan, Be as applyAutoLayout, Le as containerGridColsFor, ft as deriveColumns, xt as deriveDetail, ht as deriveFormFields, Fe as filterAutoGeneratedFields, Pe as filterCreateModeFields, Ne as filterSystemFields, ct as findRelationshipField, Oe as inferColumns, ze as inferModalSize, De as isAutoGeneratedFieldType, Ee as isWideFieldType, vt as resolveInlineMode };
3832
+ export { Ft as DrawerForm, Jt as EmbeddableForm, Xt as FormAnalytics, Ke as FormSection, Zt as LineItemsPanel, Mt as MasterDetailForm, zt as ModalForm, Vt as ObjectForm, Xe as SplitForm, Ge as TabbedForm, Ye as WizardForm, je as applyAutoColSpan, ze as applyAutoLayout, Le as containerGridColsFor, bt as deriveColumns, kt as deriveDetail, Ct as deriveFormFields, Fe as filterAutoGeneratedFields, Pe as filterCreateModeFields, Ne as filterSystemFields, ht as findRelationshipField, Oe as inferColumns, Re as inferModalSize, De as isAutoGeneratedFieldType, Ee as isWideFieldType, Et as resolveInlineMode };