@object-ui/plugin-form 17.2.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
@@ -3,9 +3,9 @@ import t, { useCallback as n, useContext as r, useEffect as i, useId as a, useMe
3
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
4
  import { SchemaRenderer as h, SchemaRendererContext as g, usePreviewMode as _, useRecordContext as v, useSafeFieldLabel as y, useSchemaContext as b } from "@object-ui/react";
5
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 V, DialogTitle as H, MobileDialogContent as ee, Sheet as U, SheetContent as W, SheetDescription as G, SheetHeader as te, SheetTitle as ne, Skeleton as K, buttonVariants as q, cn as J, toast as Y, useIsMobile as X } from "@object-ui/components";
7
- import { usePermissions as re } from "@object-ui/permissions";
8
- import { AlertCircle as ie, AlertTriangle as ae, 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";
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
10
  import { Fragment as me, jsx as Q, jsxs as $ } from "react/jsx-runtime";
11
11
  import { deriveFieldGroupLayout as he } from "@objectstack/spec/data";
@@ -162,7 +162,7 @@ function Pe(e, t) {
162
162
  return e.filter((e) => {
163
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
168
  function Fe(e, t) {
@@ -261,7 +261,7 @@ function Ge() {
261
261
  },
262
262
  children: /* @__PURE__ */ $(O, { children: [/* @__PURE__ */ $(j, { children: [/* @__PURE__ */ $(M, {
263
263
  className: "flex items-center gap-2",
264
- children: [/* @__PURE__ */ Q(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")]
@@ -270,12 +270,12 @@ function Ge() {
270
270
  children: t("form.conflictLatestVersion", { time: s })
271
271
  })] })] }), /* @__PURE__ */ $(A, { children: [/* @__PURE__ */ Q("button", {
272
272
  type: "button",
273
- className: J(q({ variant: "outline" })),
273
+ className: q(K({ variant: "outline" })),
274
274
  onClick: () => a(!1),
275
275
  children: t("form.keepEditing")
276
276
  }), /* @__PURE__ */ Q("button", {
277
277
  type: "button",
278
- className: J(q({ variant: "destructive" })),
278
+ className: q(K({ variant: "destructive" })),
279
279
  onClick: () => a(!0),
280
280
  children: t("form.conflictOverwrite")
281
281
  })] })] })
@@ -399,7 +399,7 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
399
399
  };
400
400
  }), j = A.flatMap((e) => e.fields);
401
401
  return /* @__PURE__ */ $("div", {
402
- className: J("w-full @container", i, e.className),
402
+ className: q("w-full @container", i, e.className),
403
403
  children: [/* @__PURE__ */ Q(h, { schema: {
404
404
  type: "form",
405
405
  objectName: e.objectName,
@@ -408,6 +408,7 @@ var Ke = ({ 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",
@@ -434,7 +435,7 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
434
435
  }, p = () => {
435
436
  n && d(!u);
436
437
  }, m = l ?? !!e, h = e || t ? /* @__PURE__ */ $("div", {
437
- className: J("flex items-start gap-2", !m && "mb-4", n && "cursor-pointer select-none"),
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,
@@ -452,11 +453,11 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
452
453
  })]
453
454
  })]
454
455
  }) : null, g = u ? null : /* @__PURE__ */ Q("div", {
455
- className: J("grid gap-4", s || f[i]),
456
+ className: q("grid gap-4", s || f[i]),
456
457
  children: a
457
458
  });
458
459
  return m ? /* @__PURE__ */ $(P, {
459
- className: J("form-section bg-muted/40 shadow-none", o),
460
+ className: q("form-section bg-muted/40 shadow-none", o),
460
461
  children: [h && /* @__PURE__ */ Q(L, {
461
462
  className: "border-b border-border pb-3",
462
463
  children: h
@@ -465,37 +466,37 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
465
466
  children: g
466
467
  })]
467
468
  }) : /* @__PURE__ */ $("div", {
468
- className: J("form-section", o),
469
+ className: q("form-section", o),
469
470
  children: [h, g]
470
471
  });
471
472
  }, Je = pe({ "wizard.missingRequired": "Please complete the required fields: {{fields}}" }, "wizard.missingRequired"), Ye = d, Xe = ({ schema: e, dataSource: r, className: i }) => {
472
- let { fieldLabel: a } = y(), { t: s } = Je(), [l, d] = c(null), [f, m] = c({}), { saveWithOcc: g, conflictDialog: _ } = Ge(), [v, 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, M] = c(null), P = t.useId(), [F, I] = c(0), L = t.useRef(!1), R = e.sections.length, z = C === 0, B = C === R - 1;
473
+ 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 ||= (m(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
- m(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 Ke = ({ schema: e, dataSource: r, className: i }) => {
507
508
  r,
508
509
  e.objectName
509
510
  ]);
510
- let V = n((t) => Ce(t, {
511
+ let H = n((t) => Ce(t, {
511
512
  objectSchema: l,
512
513
  objectName: e.objectName,
513
514
  readOnly: e.readOnly,
@@ -519,15 +520,15 @@ var Ke = ({ 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
534
  let a = p({
@@ -537,34 +538,34 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
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 || Ye(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
547
  ...f,
547
548
  ...t
548
549
  };
549
- if (m(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
- Y.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,
@@ -582,11 +583,11 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
582
583
  ge(t.url) && setTimeout(() => window.location.assign(t.url), t.delayMs ?? 0);
583
584
  break;
584
585
  case "continue":
585
- m({}), 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
- Y.success(n), M({
590
+ J.success(n), F({
590
591
  title: t.kind === "thank-you" ? t.title : void 0,
591
592
  message: n
592
593
  });
@@ -596,71 +597,72 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
596
597
  } else {
597
598
  let n = _e(e.navigateOnSuccess, t);
598
599
  if (n) return window.location.assign(n), t;
599
- Y.success(e.successMessage || (e.mode === "create" ? "Created" : "Saved")), e.resetOnSuccess && e.mode === "create" && (m({}), 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
611
  f,
610
- C,
611
- B,
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__ */ $("div", {
633
+ if (C) return /* @__PURE__ */ $("div", {
632
634
  className: "p-4 border border-red-300 bg-red-50 rounded-md",
633
635
  children: [/* @__PURE__ */ Q("h3", {
634
636
  className: "text-red-800 font-semibold",
635
637
  children: "Error loading form"
636
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 (v) return /* @__PURE__ */ $("div", {
643
+ if (x) return /* @__PURE__ */ $("div", {
642
644
  className: "p-8 text-center",
643
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__ */ Q("div", {
649
- className: J("w-full", i, e.className),
650
+ if (P) return /* @__PURE__ */ Q("div", {
651
+ className: q("w-full", i, e.className),
650
652
  children: /* @__PURE__ */ $("div", {
651
653
  className: "rounded-md border bg-card p-8 text-center",
652
654
  children: [/* @__PURE__ */ Q("h3", {
653
655
  className: "text-lg font-semibold",
654
- children: j.title ?? "Thanks!"
655
- }), j.message && /* @__PURE__ */ Q("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], q = (e) => typeof e == "number" && e > 0 ? Math.min(Math.floor(e), 4) : void 0, X = q(e.columns) ?? q(K?.columns) ?? 1, re = Re(X);
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);
662
664
  return /* @__PURE__ */ $("div", {
663
- className: J("w-full @container", i, e.className),
665
+ className: q("w-full @container", i, e.className),
664
666
  children: [
665
667
  e.showStepIndicator !== !1 && /* @__PURE__ */ Q("nav", {
666
668
  "aria-label": "Progress",
@@ -668,30 +670,30 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
668
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);
673
+ let r = n === T, i = D.has(n), a = e.allowSkip || i || n <= T, o = j.has(n);
672
674
  return /* @__PURE__ */ $("li", {
673
- className: J("relative flex-1", n !== R - 1 && "pr-8 sm:pr-12"),
674
- children: [n !== R - 1 && /* @__PURE__ */ Q("div", {
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__ */ Q("div", { className: J("h-full", i ? "bg-primary" : "bg-muted") })
679
+ children: /* @__PURE__ */ Q("div", { className: q("h-full", i ? "bg-primary" : "bg-muted") })
678
680
  }), /* @__PURE__ */ $("button", {
679
681
  type: "button",
680
- className: J("group relative flex items-center", a ? "cursor-pointer" : "cursor-not-allowed"),
681
- onClick: () => ne(n),
682
+ className: q("group relative flex items-center", a ? "cursor-pointer" : "cursor-not-allowed"),
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
687
  children: [/* @__PURE__ */ Q("span", {
686
- className: J("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__ */ Q(ie, {
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"),
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
692
  }) : i ? /* @__PURE__ */ Q(oe, { className: "h-3 w-3 sm:h-4 sm:w-4" }) : n + 1
691
693
  }), /* @__PURE__ */ Q("span", {
692
694
  className: "ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block",
693
695
  children: /* @__PURE__ */ Q("span", {
694
- className: J(o ? "text-destructive" : r ? "text-foreground" : "text-muted-foreground"),
696
+ className: q(o ? "text-destructive" : r ? "text-foreground" : "text-muted-foreground"),
695
697
  children: t.label || `Step ${n + 1}`
696
698
  })
697
699
  })]
@@ -702,28 +704,29 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
702
704
  }),
703
705
  /* @__PURE__ */ Q("div", {
704
706
  className: "min-h-[200px]",
705
- children: K && /* @__PURE__ */ Q(qe, {
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__ */ Q(h, { 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: X > 1 ? Me(H, X, q(K.columns)) : H,
716
+ id: I,
717
+ fields: X > 1 ? Me(U, X, ie(Y.columns)) : U,
716
718
  columns: X,
717
- ...re ? { fieldContainerClass: re } : {},
719
+ ...se ? { fieldContainerClass: se } : {},
718
720
  layout: "vertical",
719
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__ */ Q("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
731
  children: /* @__PURE__ */ Q("div", {
729
732
  className: "text-center py-8 text-muted-foreground",
@@ -736,7 +739,7 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
736
739
  className: "flex items-center justify-between mt-6 pt-4 border-t",
737
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
744
  }) }), /* @__PURE__ */ $("div", {
742
745
  className: "flex items-center gap-2",
@@ -745,33 +748,33 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
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__ */ $(N, {
756
+ !ee && /* @__PURE__ */ $(N, {
754
757
  variant: "outline",
755
- onClick: G,
758
+ onClick: ne,
756
759
  children: [/* @__PURE__ */ Q(Z, { className: "h-4 w-4 mr-1" }), e.prevText || "Back"]
757
760
  }),
758
- B ? /* @__PURE__ */ $(N, {
761
+ V ? /* @__PURE__ */ $(N, {
759
762
  type: "submit",
760
- form: P,
761
- disabled: D || e.mode === "view",
762
- children: [D && /* @__PURE__ */ Q(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")]
768
+ }), k ? "Submitting..." : e.submitText || (e.mode === "create" ? "Create" : "Update")]
766
769
  }) : /* @__PURE__ */ $(N, {
767
770
  type: "submit",
768
- form: P,
771
+ form: I,
769
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
780
  }, Ze = ({ schema: e, dataSource: t, className: r }) => {
@@ -909,7 +912,7 @@ var Ke = ({ schema: e, dataSource: r, className: i }) => {
909
912
  containerClass: e.sections.length === 1 ? e.sections[0].gridClassName : void 0
910
913
  })).filter((e) => e.fields.length > 0);
911
914
  return /* @__PURE__ */ $("div", {
912
- className: J("w-full @container", r, e.className),
915
+ className: q("w-full @container", r, e.className),
913
916
  children: [/* @__PURE__ */ Q(h, { schema: {
914
917
  type: "form",
915
918
  objectName: e.objectName,
@@ -918,6 +921,7 @@ var Ke = ({ 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",
@@ -1559,7 +1563,7 @@ var Mt = ({ 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 || Y.success(l ? e.title ? `${e.title} saved` : "Saved" : "Created"), l || (g(p.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);
@@ -1569,14 +1573,15 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1569
1573
  e.title,
1570
1574
  p.length,
1571
1575
  T
1572
- ]), V = n((t) => {
1573
- T(), Y.error(t?.message || "Save failed"), e.onError?.(t);
1574
- }, [e, T]), H = n(async (n) => {
1576
+ ]), ee = n((t) => {
1577
+ T(), J.error(t?.message || "Save failed"), e.onError?.(t);
1578
+ }, [e, T]), V = n(async (n) => {
1575
1579
  if (!t) throw Error("MasterDetailForm: dataSource is required");
1576
1580
  let r = { ...n };
1577
- return p.forEach((e, t) => {
1581
+ p.forEach((e, t) => {
1578
1582
  e.totalField && (r[e.totalField] = ct(_.current[t]?.rows ?? [], e.amountField || "amount"));
1579
- }), (await m(t, l ? ot(e.objectName, String(e.recordId), r, p.filter((e) => e.relationshipField).map((e, t) => ({
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 ?? [],
@@ -1587,7 +1592,8 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
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
  };
@@ -1597,7 +1603,7 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
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,15 +1616,15 @@ var Mt = ({ 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));
@@ -1626,12 +1632,12 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1626
1632
  return i(() => () => {
1627
1633
  w.current && clearTimeout(w.current);
1628
1634
  }, []), /* @__PURE__ */ $("div", {
1629
- className: J("space-y-6", r, e.className),
1635
+ className: q("space-y-6", r, e.className),
1630
1636
  children: [
1631
1637
  /* @__PURE__ */ Q("div", {
1632
1638
  ref: U,
1633
1639
  children: /* @__PURE__ */ Q(Ht, {
1634
- schema: ee,
1640
+ schema: H,
1635
1641
  dataSource: t
1636
1642
  }, y)
1637
1643
  }),
@@ -1696,10 +1702,10 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1696
1702
  children: e.cancelText ?? "Cancel"
1697
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
  ]
@@ -1715,7 +1721,7 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1715
1721
  "form.keepEditing": "Keep editing",
1716
1722
  "form.discard": "Discard"
1717
1723
  }, "form.discardTitle"), It = ({ schema: e, dataSource: t, className: r }) => {
1718
- 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: V } = Ge(), [H, ee] = c(!1), K = s(!1), q = e.confirmOnDiscard !== !1, Y = e.open !== !1, X = e.drawerSide || "right", re = a(), [ie, ae] = c(() => {
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);
@@ -1825,7 +1831,7 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1825
1831
  t
1826
1832
  ]);
1827
1833
  let ce = n(async (n) => {
1828
- ee(!0);
1834
+ H(!0);
1829
1835
  try {
1830
1836
  if (!t) return e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
1831
1837
  let r, i = et(n, f);
@@ -1845,7 +1851,7 @@ var Mt = ({ 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
- ee(!1);
1854
+ H(!1);
1849
1855
  }
1850
1856
  }, [
1851
1857
  e,
@@ -1854,40 +1860,41 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1854
1860
  B,
1855
1861
  v
1856
1862
  ]), Z = n(() => {
1857
- z(!1), K.current && (K.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
1863
+ z(!1), re.current && (re.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
1858
1864
  }, [e]), le = n((e) => {
1859
- K.current = e, q && I ? z(!0) : Z();
1865
+ re.current = e, K && I ? z(!0) : Z();
1860
1866
  }, [
1861
- q,
1867
+ K,
1862
1868
  I,
1863
1869
  Z
1864
1870
  ]);
1865
1871
  i(() => {
1866
- if (!Y || !I || !q) 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
- Y,
1878
+ J,
1873
1879
  I,
1874
- q
1880
+ K
1875
1881
  ]);
1876
1882
  let de = n(() => {
1877
- K.current = !0, Z();
1883
+ re.current = !0, Z();
1878
1884
  }, [Z]), fe = o(() => {
1879
- if (e.drawerWidth) return X === "left" || X === "right" ? {
1885
+ if (e.drawerWidth) return Y === "left" || Y === "right" ? {
1880
1886
  width: e.drawerWidth,
1881
1887
  maxWidth: e.drawerWidth
1882
1888
  } : {
1883
1889
  height: e.drawerWidth,
1884
1890
  maxHeight: e.drawerWidth
1885
1891
  };
1886
- }, [e.drawerWidth, X]), 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 = {
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
1895
  layout: pe,
1890
1896
  defaultValues: v,
1897
+ previousValues: e.mode === "edit" && e.recordId ? v : void 0,
1891
1898
  submitLabel: ge,
1892
1899
  cancelLabel: _e,
1893
1900
  showSubmit: me,
@@ -1896,7 +1903,7 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1896
1903
  onCancel: de,
1897
1904
  onDirtyChange: L,
1898
1905
  showActions: !1,
1899
- id: re
1906
+ id: ie
1900
1907
  }, ye = () => {
1901
1908
  if (P) return /* @__PURE__ */ $("div", {
1902
1909
  className: "p-4 border border-red-300 bg-red-50 rounded-md",
@@ -1918,7 +1925,7 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1918
1925
  if (e.sections?.length) {
1919
1926
  let t = [];
1920
1927
  return e.sections.forEach((e, n) => {
1921
- let r = e.name || String(n), i = ie[r] ?? e.collapsed ?? !1;
1928
+ let r = e.name || String(n), i = ae[r] ?? e.collapsed ?? !1;
1922
1929
  t.push({
1923
1930
  name: `__section_${r}`,
1924
1931
  label: e.label || "",
@@ -1926,7 +1933,7 @@ var Mt = ({ 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 ? () => ae((e) => ({
1936
+ onToggle: e.collapsible ? () => X((e) => ({
1930
1937
  ...e,
1931
1938
  [r]: !i
1932
1939
  })) : void 0,
@@ -1981,7 +1988,7 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1981
1988
  })]
1982
1989
  }), xe]
1983
1990
  }) : /* @__PURE__ */ Q(U, {
1984
- open: Y,
1991
+ open: J,
1985
1992
  onOpenChange: (t) => {
1986
1993
  if (t) {
1987
1994
  e.onOpenChange?.(!0);
@@ -1989,12 +1996,12 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
1989
1996
  }
1990
1997
  le(!1);
1991
1998
  },
1992
- children: /* @__PURE__ */ $(W, {
1993
- side: X,
1994
- className: J("overflow-y-auto", r, e.className),
1999
+ children: /* @__PURE__ */ $(te, {
2000
+ side: Y,
2001
+ className: q("overflow-y-auto", r, e.className),
1995
2002
  style: fe,
1996
2003
  children: [
1997
- (e.title || e.description) && /* @__PURE__ */ $(te, { children: [e.title && /* @__PURE__ */ Q(ne, { children: e.title }), e.description ? /* @__PURE__ */ Q(G, { children: e.description }) : /* @__PURE__ */ Q(G, {
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
  })] }),
@@ -2011,15 +2018,15 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
2011
2018
  type: "button",
2012
2019
  variant: "outline",
2013
2020
  onClick: de,
2014
- disabled: H,
2021
+ disabled: V,
2015
2022
  className: "w-full sm:w-auto",
2016
2023
  children: _e
2017
2024
  }), me && /* @__PURE__ */ $(N, {
2018
2025
  type: "submit",
2019
- form: re,
2020
- disabled: H,
2026
+ form: ie,
2027
+ disabled: V,
2021
2028
  className: "w-full sm:w-auto",
2022
- children: [H && /* @__PURE__ */ Q(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
  }),
@@ -2028,7 +2035,7 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
2028
2035
  onOpenChange: z,
2029
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
2041
  }), /* @__PURE__ */ Q(E, {
@@ -2036,7 +2043,7 @@ var Mt = ({ details: e, state: t, setRows: n, formHostRef: r, taxRateField: a, f
2036
2043
  children: u("form.discard")
2037
2044
  })] })] })
2038
2045
  }),
2039
- V
2046
+ ee
2040
2047
  ]
2041
2048
  })
2042
2049
  });
@@ -2076,7 +2083,7 @@ var Rt = pe({
2076
2083
  xl: "sm:max-w-5xl",
2077
2084
  full: "sm:max-w-[95vw] sm:w-full"
2078
2085
  }, Bt = ({ schema: e, dataSource: t, className: r }) => {
2079
- let { fieldLabel: l, sectionLabel: u } = y(), { t: d } = Rt(), f = _(), p = re(), m = n((t) => {
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,7 +2102,7 @@ var Rt = pe({
2095
2102
  p,
2096
2103
  e.objectName,
2097
2104
  e.mode
2098
- ]), [g, v] = c(null), [b, x] = c([]), [C, P] = c({}), [F, I] = c(!0), [L, R] = c(null), [U, W] = c(!1), [G, te] = c(!1), [ne, q] = c(!1), { saveWithOcc: Y, conflictDialog: X } = Ge(), ie = s(!1), ae = e.confirmOnDiscard !== !1, oe = e.open !== !1, se = a(), ce = 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
2107
  let t = Pe(b, g);
2101
2108
  e.mode === "create" && (t = Ie(t, g));
@@ -2159,7 +2166,7 @@ var Rt = pe({
2159
2166
  P(e.initialData || e.initialValues || {}), I(!1);
2160
2167
  return;
2161
2168
  }
2162
- fe.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;
@@ -2240,7 +2247,7 @@ var Rt = pe({
2240
2247
  t
2241
2248
  ]);
2242
2249
  let me = n(async (n) => {
2243
- W(!0);
2250
+ te(!0);
2244
2251
  try {
2245
2252
  if (!t) return e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
2246
2253
  let r, i = et(n, g);
@@ -2251,7 +2258,7 @@ var Rt = 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 Y({
2261
+ let n = await J({
2255
2262
  dataSource: t,
2256
2263
  objectName: e.objectName,
2257
2264
  recordId: e.recordId,
@@ -2265,49 +2272,50 @@ var Rt = 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
- Y,
2282
+ J,
2276
2283
  C
2277
2284
  ]), he = n(() => {
2278
- q(!1), ie.current && (ie.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
2285
+ K(!1), ae.current && (ae.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
2279
2286
  }, [e]), ge = n((e) => {
2280
- ie.current = e, ae && G ? q(!0) : he();
2287
+ ae.current = e, X && W ? K(!0) : he();
2281
2288
  }, [
2282
- ae,
2283
- G,
2289
+ X,
2290
+ W,
2284
2291
  he
2285
2292
  ]);
2286
2293
  i(() => {
2287
- if (!oe || !G || !ae) 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
2300
  oe,
2294
- G,
2295
- ae
2301
+ W,
2302
+ X
2296
2303
  ]);
2297
2304
  let _e = n(() => {
2298
- ie.current = !0, he();
2305
+ ae.current = !0, he();
2299
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
2310
  defaultValues: C,
2311
+ previousValues: e.mode === "edit" && e.recordId ? C : void 0,
2304
2312
  submitLabel: xe,
2305
2313
  cancelLabel: Se,
2306
2314
  showSubmit: ye,
2307
2315
  showCancel: be,
2308
2316
  onSubmit: me,
2309
2317
  onCancel: _e,
2310
- onDirtyChange: te,
2318
+ onDirtyChange: G,
2311
2319
  showActions: !1,
2312
2320
  id: se
2313
2321
  }, Te = () => {
@@ -2330,7 +2338,7 @@ var Rt = pe({
2330
2338
  3
2331
2339
  ].map((e) => /* @__PURE__ */ $("div", {
2332
2340
  className: "space-y-2",
2333
- children: [/* @__PURE__ */ Q(K, { className: "h-4 w-24" }), /* @__PURE__ */ Q(K, { 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) {
@@ -2419,11 +2427,11 @@ var Rt = pe({
2419
2427
  if (Ee?.length && e.mode !== "view") return /* @__PURE__ */ Q(z, {
2420
2428
  open: oe,
2421
2429
  onOpenChange: e.onOpenChange,
2422
- children: /* @__PURE__ */ $(ee, {
2423
- className: J(de, "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__ */ $(V, {
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__ */ Q(H, { children: e.title }), e.description ? /* @__PURE__ */ Q(B, { children: e.description }) : /* @__PURE__ */ Q(B, {
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
  })]
@@ -2463,12 +2471,12 @@ var Rt = pe({
2463
2471
  }
2464
2472
  ge(!1);
2465
2473
  },
2466
- children: /* @__PURE__ */ $(ee, {
2467
- className: J(de, "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__ */ $(V, {
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__ */ Q(H, { children: e.title }), e.description ? /* @__PURE__ */ Q(B, { children: e.description }) : /* @__PURE__ */ Q(B, {
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
  })]
@@ -2500,10 +2508,10 @@ var Rt = pe({
2500
2508
  }),
2501
2509
  /* @__PURE__ */ Q(T, {
2502
2510
  open: ne,
2503
- onOpenChange: q,
2511
+ onOpenChange: K,
2504
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
- ie.current = !1;
2514
+ ae.current = !1;
2507
2515
  },
2508
2516
  children: d("form.keepEditing")
2509
2517
  }), /* @__PURE__ */ Q(E, {
@@ -2511,7 +2519,7 @@ var Rt = pe({
2511
2519
  children: d("form.discard")
2512
2520
  })] })] })
2513
2521
  }),
2514
- X
2522
+ Y
2515
2523
  ]
2516
2524
  })
2517
2525
  });
@@ -2525,7 +2533,7 @@ function Vt(e) {
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
2535
  var Ht = ({ schema: e, dataSource: t }) => {
2528
- let n = re(), r = o(() => {
2536
+ let n = ie(), r = o(() => {
2529
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) => ({
@@ -2692,7 +2700,7 @@ var Ht = ({ schema: e, dataSource: t }) => {
2692
2700
  dataSource: t
2693
2701
  });
2694
2702
  }, Ut = ({ schema: e, dataSource: r }) => {
2695
- let { fieldLabel: a, sectionLabel: o } = y(), s = X(), l = re(), u = n((t) => {
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({
@@ -2848,7 +2856,7 @@ var Ht = ({ schema: e, dataSource: t }) => {
2848
2856
  case "continue": break;
2849
2857
  default: {
2850
2858
  let n = t.kind === "thank-you" && t.message ? t.message : e.successMessage || (e.mode === "create" ? "Created" : "Saved");
2851
- Y.success(n), O({
2859
+ J.success(n), O({
2852
2860
  title: t.kind === "thank-you" ? t.title : void 0,
2853
2861
  message: n
2854
2862
  });
@@ -2858,7 +2866,7 @@ var Ht = ({ schema: e, dataSource: t }) => {
2858
2866
  } else if (!e.submitHandler) {
2859
2867
  let n = _e(e.navigateOnSuccess, t);
2860
2868
  if (n) return window.location.assign(n), t;
2861
- Y.success(e.successMessage || (e.mode === "create" ? "Created" : "Saved"));
2869
+ J.success(e.successMessage || (e.mode === "create" ? "Created" : "Saved"));
2862
2870
  }
2863
2871
  return t;
2864
2872
  } catch (t) {
@@ -2884,18 +2892,18 @@ var Ht = ({ schema: e, dataSource: t }) => {
2884
2892
  }), e;
2885
2893
  }, [d]),
2886
2894
  ..._
2887
- }, I = t.useMemo(() => {
2895
+ }, I = e.mode === "edit" && e.recordId && _ && typeof _ == "object" ? _ : void 0, L = t.useMemo(() => {
2888
2896
  let t = Pe(m, d);
2889
2897
  return e.mode === "create" && (t = Ie(t, d)), t;
2890
2898
  }, [
2891
2899
  m,
2892
2900
  d,
2893
2901
  e.mode
2894
- ]), L = t.useMemo(() => e.sections?.length ? null : Lt(I, d?.fieldGroups), [
2902
+ ]), R = t.useMemo(() => e.sections?.length ? null : Lt(L, d?.fieldGroups), [
2895
2903
  e.sections,
2896
- I,
2904
+ L,
2897
2905
  d
2898
- ]), R = e.sections?.length ? e.sections : L, [z, B] = c({});
2906
+ ]), z = e.sections?.length ? e.sections : R, [B, ee] = c({});
2899
2907
  if (T) return /* @__PURE__ */ $("div", {
2900
2908
  className: "p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",
2901
2909
  children: [/* @__PURE__ */ Q("h3", {
@@ -2924,9 +2932,9 @@ var Ht = ({ schema: e, dataSource: t }) => {
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 : m, 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) : ke(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 Ht = ({ 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,7 +2950,7 @@ var Ht = ({ 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,
@@ -2965,6 +2973,7 @@ var Ht = ({ 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 Ht = ({ schema: e, dataSource: t }) => {
2974
2983
  } }), A]
2975
2984
  });
2976
2985
  }
2977
- let H = e.sections?.length, ee = u(m), 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
- } : Be(ee, d, 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);
@@ -3010,13 +3025,14 @@ var Ht = ({ 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,
@@ -3494,7 +3510,7 @@ var Zt = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
3494
3510
  allow_delete: !e.readonly
3495
3511
  }), [e]);
3496
3512
  return /* @__PURE__ */ $(P, {
3497
- className: J("shadow-none"),
3513
+ className: q("shadow-none"),
3498
3514
  children: [/* @__PURE__ */ $(L, {
3499
3515
  className: "flex-row items-center justify-between gap-2 pb-2",
3500
3516
  children: [/* @__PURE__ */ Q(R, {
@@ -3523,10 +3539,13 @@ var Zt = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
3523
3539
  children: "Save the record first to add line items."
3524
3540
  })] })]
3525
3541
  });
3526
- }, $t = ({ schema: e }) => /* @__PURE__ */ Q(Ht, {
3527
- schema: e,
3528
- dataSource: r(g)?.dataSource ?? void 0
3529
- });
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
+ };
3530
3549
  l.register("object-form", $t, {
3531
3550
  namespace: "plugin-form",
3532
3551
  label: "Object Form",
@@ -3696,10 +3715,13 @@ l.register("object-form", $t, {
3696
3715
  ]
3697
3716
  }
3698
3717
  ]
3699
- }), l.register("embeddable-form", ({ schema: e }) => /* @__PURE__ */ Q(Yt, {
3700
- config: e,
3701
- dataSource: r(g)?.dataSource
3702
- }), {
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
+ }, {
3703
3725
  namespace: "plugin-form",
3704
3726
  label: "Embeddable Form",
3705
3727
  category: "plugin",
@@ -3763,10 +3785,13 @@ l.register("object-form", $t, {
3763
3785
  label: "Submission Metrics"
3764
3786
  }
3765
3787
  ]
3766
- }), l.register("object-master-detail-form", ({ schema: e }) => /* @__PURE__ */ Q(Nt, {
3767
- schema: e,
3768
- dataSource: r(g)?.dataSource ?? void 0
3769
- }), {
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
+ }, {
3770
3795
  namespace: "plugin-form",
3771
3796
  label: "Master-Detail Form",
3772
3797
  category: "plugin",