@object-ui/plugin-form 17.1.0 → 17.3.0

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