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