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