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