@object-ui/plugin-form 11.0.0 → 11.2.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 +27 -0
- package/dist/DrawerForm.d.ts +9 -0
- package/dist/ModalForm.d.ts +9 -0
- package/dist/index.js +598 -502
- package/dist/index.umd.cjs +1 -1
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -2,28 +2,29 @@ import e, { useCallback as t, useContext as n, useEffect as r, useId as i, useMe
|
|
|
2
2
|
import { ComponentRegistry as c } from "@object-ui/core";
|
|
3
3
|
import { SchemaRenderer as l, SchemaRendererContext as u, usePreviewMode as d, useRecordContext as f, useSafeFieldLabel as p, useSchemaContext as m } from "@object-ui/react";
|
|
4
4
|
import { LineItemsField as h, buildValidationRules as g, evaluateCondition as _, formatFileSize as v, mapFieldTypeToFormType as y } from "@object-ui/fields";
|
|
5
|
-
import {
|
|
6
|
-
import { usePermissions as
|
|
7
|
-
import { Check as
|
|
8
|
-
import { Fragment as
|
|
5
|
+
import { AlertDialog as b, AlertDialogAction as x, AlertDialogCancel as S, AlertDialogContent as C, AlertDialogDescription as w, AlertDialogFooter as T, AlertDialogHeader as E, AlertDialogTitle as D, Button as O, Card as k, CardContent as A, CardDescription as j, CardHeader as M, CardTitle as N, Dialog as P, DialogDescription as F, DialogHeader as I, DialogTitle as L, MobileDialogContent as R, ResizableHandle as z, ResizablePanel as B, ResizablePanelGroup as V, Sheet as ee, SheetContent as te, SheetDescription as H, SheetHeader as U, SheetTitle as ne, Skeleton as W, Tabs as re, TabsContent as ie, TabsList as ae, TabsTrigger as oe, cn as G, toast as se, useIsMobile as ce } from "@object-ui/components";
|
|
6
|
+
import { usePermissions as le } from "@object-ui/permissions";
|
|
7
|
+
import { Check as K, CheckCircle2 as q, ChevronDown as ue, ChevronLeft as de, ChevronRight as J, Loader2 as fe, Lock as pe, ShieldCheck as me } from "lucide-react";
|
|
8
|
+
import { Fragment as Y, jsx as X, jsxs as Z } from "react/jsx-runtime";
|
|
9
|
+
import { createSafeTranslation as Q } from "@object-ui/i18n";
|
|
9
10
|
//#region src/successBehavior.ts
|
|
10
|
-
function
|
|
11
|
+
function he(e) {
|
|
11
12
|
try {
|
|
12
13
|
return typeof window > "u" ? !1 : new URL(e, window.location.href).origin === window.location.origin;
|
|
13
14
|
} catch {
|
|
14
15
|
return !1;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
+
function ge(e, t) {
|
|
18
19
|
if (!e) return null;
|
|
19
20
|
let n = t?.id ?? t?.recordId ?? t?._id;
|
|
20
21
|
if (n == null || n === "") return null;
|
|
21
22
|
let r = e.replace(/\{(?:id|recordId)\}/g, String(n));
|
|
22
|
-
return
|
|
23
|
+
return he(r) ? r : null;
|
|
23
24
|
}
|
|
24
25
|
//#endregion
|
|
25
26
|
//#region src/FormSection.tsx
|
|
26
|
-
var
|
|
27
|
+
var _e = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, columns: i = 1, children: a, className: o, gridClassName: c, showBorder: l }) => {
|
|
27
28
|
let [u, d] = s(r), f = {
|
|
28
29
|
1: "grid-cols-1",
|
|
29
30
|
2: "grid-cols-1 md:grid-cols-2",
|
|
@@ -32,13 +33,13 @@ var Q = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
32
33
|
}, p = () => {
|
|
33
34
|
n && d(!u);
|
|
34
35
|
}, m = l ?? !!e, h = e || t ? /* @__PURE__ */ Z("div", {
|
|
35
|
-
className:
|
|
36
|
+
className: G("flex items-start gap-2", !m && "mb-4", n && "cursor-pointer select-none"),
|
|
36
37
|
onClick: p,
|
|
37
38
|
role: n ? "button" : void 0,
|
|
38
39
|
"aria-expanded": n ? !u : void 0,
|
|
39
40
|
children: [n && /* @__PURE__ */ X("span", {
|
|
40
41
|
className: "mt-0.5 text-muted-foreground",
|
|
41
|
-
children: X(u ?
|
|
42
|
+
children: X(u ? J : ue, { className: "h-4 w-4" })
|
|
42
43
|
}), /* @__PURE__ */ Z("div", {
|
|
43
44
|
className: "flex-1",
|
|
44
45
|
children: [e && /* @__PURE__ */ X("h3", {
|
|
@@ -50,43 +51,43 @@ var Q = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
50
51
|
})]
|
|
51
52
|
})]
|
|
52
53
|
}) : null, g = u ? null : /* @__PURE__ */ X("div", {
|
|
53
|
-
className:
|
|
54
|
+
className: G("grid gap-4", c || f[i]),
|
|
54
55
|
children: a
|
|
55
56
|
});
|
|
56
|
-
return m ? /* @__PURE__ */ Z(
|
|
57
|
-
className:
|
|
58
|
-
children: [h && /* @__PURE__ */ Z(
|
|
57
|
+
return m ? /* @__PURE__ */ Z(k, {
|
|
58
|
+
className: G("form-section", o),
|
|
59
|
+
children: [h && /* @__PURE__ */ Z(M, {
|
|
59
60
|
className: "pb-3",
|
|
60
61
|
children: [
|
|
61
|
-
e && /* @__PURE__ */ X(
|
|
62
|
+
e && /* @__PURE__ */ X(N, {
|
|
62
63
|
className: "text-base",
|
|
63
64
|
children: e
|
|
64
65
|
}),
|
|
65
|
-
t && /* @__PURE__ */ X(
|
|
66
|
+
t && /* @__PURE__ */ X(j, { children: t }),
|
|
66
67
|
n && /* @__PURE__ */ X("button", {
|
|
67
68
|
type: "button",
|
|
68
69
|
className: "absolute right-4 top-4 text-muted-foreground",
|
|
69
70
|
onClick: p,
|
|
70
71
|
"aria-expanded": !u,
|
|
71
72
|
"aria-label": u ? "Expand section" : "Collapse section",
|
|
72
|
-
children: X(u ?
|
|
73
|
+
children: X(u ? J : ue, { className: "h-4 w-4" })
|
|
73
74
|
})
|
|
74
75
|
]
|
|
75
|
-
}), g && /* @__PURE__ */ X(
|
|
76
|
+
}), g && /* @__PURE__ */ X(A, { children: g })]
|
|
76
77
|
}) : /* @__PURE__ */ Z("div", {
|
|
77
|
-
className:
|
|
78
|
+
className: G("form-section", o),
|
|
78
79
|
children: [h, g]
|
|
79
80
|
});
|
|
80
81
|
};
|
|
81
82
|
//#endregion
|
|
82
83
|
//#region src/sectionFields.ts
|
|
83
|
-
function
|
|
84
|
+
function ve(e, t) {
|
|
84
85
|
return typeof t == "string" && t.trim() ? {
|
|
85
86
|
...e,
|
|
86
87
|
visible: (e) => _(t, e)
|
|
87
88
|
} : e;
|
|
88
89
|
}
|
|
89
|
-
function
|
|
90
|
+
function ye(e, t) {
|
|
90
91
|
let n = t.objectSchema?.fields?.[e];
|
|
91
92
|
return n ? {
|
|
92
93
|
name: e,
|
|
@@ -106,22 +107,22 @@ function ue(e, t) {
|
|
|
106
107
|
type: "input"
|
|
107
108
|
};
|
|
108
109
|
}
|
|
109
|
-
function
|
|
110
|
+
function be(e, t) {
|
|
110
111
|
if (typeof e == "string") {
|
|
111
112
|
let n = t.objectSchema?.fields?.[e];
|
|
112
|
-
return
|
|
113
|
+
return ve(ye(e, t), n?.visible_on ?? n?.visibleOn);
|
|
113
114
|
}
|
|
114
115
|
let n = e;
|
|
115
|
-
if (typeof n.field != "string") return
|
|
116
|
-
let r = n.field, i =
|
|
117
|
-
return n.type != null && (i.type = y(n.type)), n.widget != null && (i.widget = n.widget), n.label != null && (i.label = n.label), n.placeholder != null && (i.placeholder = n.placeholder), n.helpText != null && (i.description = n.helpText), n.required != null && (i.required = n.required), n.readonly != null && (i.disabled = n.readonly || i.disabled), n.immutable != null && (i.immutable = n.immutable), n.hidden != null && (i.hidden = n.hidden), n.colSpan != null && (i.colSpan = n.colSpan), n.options != null && (i.options = n.options), n.multiple != null && (i.multiple = n.multiple), n.reference != null && (i.reference = n.reference), n.maxLength != null && (i.maxLength = n.maxLength), n.minLength != null && (i.minLength = n.minLength), n.min != null && (i.min = n.min), n.max != null && (i.max = n.max), n.precision != null && (i.precision = n.precision), n.scale != null && (i.scale = n.scale), n.language != null && (i.language = n.language), Array.isArray(n.fields) && (i.fields = n.fields),
|
|
116
|
+
if (typeof n.field != "string") return ve(n, n.visibleOn);
|
|
117
|
+
let r = n.field, i = ye(r, t);
|
|
118
|
+
return n.type != null && (i.type = y(n.type)), n.widget != null && (i.widget = n.widget), n.label != null && (i.label = n.label), n.placeholder != null && (i.placeholder = n.placeholder), n.helpText != null && (i.description = n.helpText), n.required != null && (i.required = n.required), n.readonly != null && (i.disabled = n.readonly || i.disabled), n.immutable != null && (i.immutable = n.immutable), n.hidden != null && (i.hidden = n.hidden), n.colSpan != null && (i.colSpan = n.colSpan), n.options != null && (i.options = n.options), n.multiple != null && (i.multiple = n.multiple), n.reference != null && (i.reference = n.reference), n.maxLength != null && (i.maxLength = n.maxLength), n.minLength != null && (i.minLength = n.minLength), n.min != null && (i.min = n.min), n.max != null && (i.max = n.max), n.precision != null && (i.precision = n.precision), n.scale != null && (i.scale = n.scale), n.language != null && (i.language = n.language), Array.isArray(n.fields) && (i.fields = n.fields), ve(i, n.visibleOn);
|
|
118
119
|
}
|
|
119
|
-
function
|
|
120
|
-
return (e.fields ?? []).map((e) =>
|
|
120
|
+
function xe(e, t) {
|
|
121
|
+
return (e.fields ?? []).map((e) => be(e, t));
|
|
121
122
|
}
|
|
122
123
|
//#endregion
|
|
123
124
|
//#region src/TabbedForm.tsx
|
|
124
|
-
var
|
|
125
|
+
var Se = ({ schema: n, dataSource: r, className: i }) => {
|
|
125
126
|
let { fieldLabel: a } = p(), [o, c] = s(null), [u, d] = s({}), [f, m] = s(!0), [h, g] = s(null), [_, v] = s(n.defaultTab || n.sections[0]?.name || n.sections[0]?.label || "tab-0");
|
|
126
127
|
e.useEffect(() => {
|
|
127
128
|
(async () => {
|
|
@@ -158,7 +159,7 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
158
159
|
r,
|
|
159
160
|
n.objectName
|
|
160
161
|
]);
|
|
161
|
-
let y = t((e) =>
|
|
162
|
+
let y = t((e) => xe(e, {
|
|
162
163
|
objectSchema: o,
|
|
163
164
|
objectName: n.objectName,
|
|
164
165
|
readOnly: n.readOnly,
|
|
@@ -211,25 +212,25 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
211
212
|
onCancel: x
|
|
212
213
|
}, w = n.tabPosition === "left" || n.tabPosition === "right";
|
|
213
214
|
return /* @__PURE__ */ X("div", {
|
|
214
|
-
className:
|
|
215
|
-
children: /* @__PURE__ */ Z(
|
|
215
|
+
className: G("w-full", i, n.className),
|
|
216
|
+
children: /* @__PURE__ */ Z(re, {
|
|
216
217
|
value: _,
|
|
217
218
|
onValueChange: v,
|
|
218
219
|
orientation: w ? "vertical" : "horizontal",
|
|
219
|
-
className:
|
|
220
|
-
children: [/* @__PURE__ */ X(
|
|
221
|
-
className:
|
|
222
|
-
children: n.sections.map((e, t) => /* @__PURE__ */ X(
|
|
220
|
+
className: G(w && "flex gap-4"),
|
|
221
|
+
children: [/* @__PURE__ */ X(ae, {
|
|
222
|
+
className: G(w ? "flex-col h-auto" : "", n.tabPosition === "bottom" && "order-last", n.tabPosition === "right" && "order-last"),
|
|
223
|
+
children: n.sections.map((e, t) => /* @__PURE__ */ X(oe, {
|
|
223
224
|
value: S(e, t),
|
|
224
225
|
className: w ? "w-full justify-start" : "",
|
|
225
226
|
children: e.label || `Tab ${t + 1}`
|
|
226
227
|
}, S(e, t)))
|
|
227
228
|
}), /* @__PURE__ */ X("div", {
|
|
228
229
|
className: "flex-1",
|
|
229
|
-
children: n.sections.map((e, t) => /* @__PURE__ */ X(
|
|
230
|
+
children: n.sections.map((e, t) => /* @__PURE__ */ X(ie, {
|
|
230
231
|
value: S(e, t),
|
|
231
232
|
className: "mt-0",
|
|
232
|
-
children: /* @__PURE__ */ X(
|
|
233
|
+
children: /* @__PURE__ */ X(_e, {
|
|
233
234
|
description: e.description,
|
|
234
235
|
columns: e.columns || 1,
|
|
235
236
|
children: /* @__PURE__ */ X(l, { schema: {
|
|
@@ -243,8 +244,8 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
243
244
|
})]
|
|
244
245
|
})
|
|
245
246
|
});
|
|
246
|
-
},
|
|
247
|
-
let { fieldLabel: o } = p(), [c, u] = s(null), [d, f] = s({}), [m, h] = s(!0), [g, _] = s(null), [v, y] = s(0), [
|
|
247
|
+
}, Ce = ({ schema: n, dataSource: r, className: i }) => {
|
|
248
|
+
let { fieldLabel: o } = p(), [c, u] = s(null), [d, f] = s({}), [m, h] = s(!0), [g, _] = s(null), [v, y] = s(0), [b, x] = s(/* @__PURE__ */ new Set()), [S, C] = s(!1), w = e.useId(), [T, E] = s(0), D = e.useRef(!1), k = n.sections.length, A = v === 0, j = v === k - 1;
|
|
248
249
|
e.useEffect(() => {
|
|
249
250
|
(async () => {
|
|
250
251
|
if (!r) {
|
|
@@ -260,7 +261,7 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
260
261
|
}, [n.objectName, r]), e.useEffect(() => {
|
|
261
262
|
(c || !r) && (async () => {
|
|
262
263
|
if (n.mode === "create" || !n.recordId || !r) {
|
|
263
|
-
|
|
264
|
+
D.current ||= (f(n.initialData || n.initialValues || {}), !0), h(!1);
|
|
264
265
|
return;
|
|
265
266
|
}
|
|
266
267
|
try {
|
|
@@ -280,7 +281,7 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
280
281
|
r,
|
|
281
282
|
n.objectName
|
|
282
283
|
]);
|
|
283
|
-
let M = t((e) =>
|
|
284
|
+
let M = t((e) => xe(e, {
|
|
284
285
|
objectSchema: c,
|
|
285
286
|
objectName: n.objectName,
|
|
286
287
|
readOnly: n.readOnly,
|
|
@@ -302,22 +303,22 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
302
303
|
...d,
|
|
303
304
|
...e
|
|
304
305
|
};
|
|
305
|
-
if (f(t),
|
|
306
|
-
|
|
306
|
+
if (f(t), x((e) => new Set(e).add(v)), j) {
|
|
307
|
+
C(!0);
|
|
307
308
|
try {
|
|
308
309
|
if (!r) return n.onSuccess && await n.onSuccess(t), t;
|
|
309
310
|
let e;
|
|
310
311
|
if (n.mode === "create" ? e = await r.create(n.objectName, t) : n.mode === "edit" && n.recordId && (e = await r.update(n.objectName, n.recordId, t)), n.onSuccess) await n.onSuccess(e);
|
|
311
312
|
else {
|
|
312
|
-
let t =
|
|
313
|
+
let t = ge(n.navigateOnSuccess, e);
|
|
313
314
|
if (t) return window.location.assign(t), e;
|
|
314
|
-
|
|
315
|
+
se.success(n.successMessage || (n.mode === "create" ? "Created" : "Saved")), n.resetOnSuccess && n.mode === "create" && (f({}), x(/* @__PURE__ */ new Set()), y(0), E((e) => e + 1));
|
|
315
316
|
}
|
|
316
317
|
return e;
|
|
317
318
|
} catch (e) {
|
|
318
319
|
throw n.onError && n.onError(e), e;
|
|
319
320
|
} finally {
|
|
320
|
-
|
|
321
|
+
C(!1);
|
|
321
322
|
}
|
|
322
323
|
} else F(v + 1);
|
|
323
324
|
}, [
|
|
@@ -333,10 +334,10 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
333
334
|
}, [v, F]), L = t(() => {
|
|
334
335
|
n.onCancel && n.onCancel();
|
|
335
336
|
}, [n]), R = t((e) => {
|
|
336
|
-
(n.allowSkip ||
|
|
337
|
+
(n.allowSkip || b.has(e) || e <= v) && F(e);
|
|
337
338
|
}, [
|
|
338
339
|
n.allowSkip,
|
|
339
|
-
|
|
340
|
+
b,
|
|
340
341
|
v,
|
|
341
342
|
F
|
|
342
343
|
]);
|
|
@@ -359,7 +360,7 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
359
360
|
});
|
|
360
361
|
let z = n.sections[v];
|
|
361
362
|
return /* @__PURE__ */ Z("div", {
|
|
362
|
-
className:
|
|
363
|
+
className: G("w-full", i, n.className),
|
|
363
364
|
children: [
|
|
364
365
|
n.showStepIndicator !== !1 && /* @__PURE__ */ X("nav", {
|
|
365
366
|
"aria-label": "Progress",
|
|
@@ -367,25 +368,25 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
367
368
|
children: /* @__PURE__ */ X("ol", {
|
|
368
369
|
className: "flex items-center",
|
|
369
370
|
children: n.sections.map((e, t) => {
|
|
370
|
-
let r = t === v, i =
|
|
371
|
+
let r = t === v, i = b.has(t), a = n.allowSkip || i || t <= v;
|
|
371
372
|
return /* @__PURE__ */ Z("li", {
|
|
372
|
-
className:
|
|
373
|
+
className: G("relative flex-1", t !== k - 1 && "pr-8 sm:pr-12"),
|
|
373
374
|
children: [t !== k - 1 && /* @__PURE__ */ X("div", {
|
|
374
375
|
className: "absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5",
|
|
375
376
|
"aria-hidden": "true",
|
|
376
|
-
children: /* @__PURE__ */ X("div", { className:
|
|
377
|
+
children: /* @__PURE__ */ X("div", { className: G("h-full", i ? "bg-primary" : "bg-muted") })
|
|
377
378
|
}), /* @__PURE__ */ Z("button", {
|
|
378
379
|
type: "button",
|
|
379
|
-
className:
|
|
380
|
+
className: G("group relative flex items-center", a ? "cursor-pointer" : "cursor-not-allowed"),
|
|
380
381
|
onClick: () => R(t),
|
|
381
382
|
disabled: !a,
|
|
382
383
|
children: [/* @__PURE__ */ X("span", {
|
|
383
|
-
className:
|
|
384
|
-
children: i ? /* @__PURE__ */ X(
|
|
384
|
+
className: G("flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors", i && "bg-primary text-primary-foreground", r && !i && "border-2 border-primary bg-background text-primary", !r && !i && "border-2 border-muted bg-background text-muted-foreground"),
|
|
385
|
+
children: i ? /* @__PURE__ */ X(K, { className: "h-3 w-3 sm:h-4 sm:w-4" }) : t + 1
|
|
385
386
|
}), /* @__PURE__ */ X("span", {
|
|
386
387
|
className: "ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block",
|
|
387
388
|
children: /* @__PURE__ */ X("span", {
|
|
388
|
-
className:
|
|
389
|
+
className: G(r ? "text-foreground" : "text-muted-foreground"),
|
|
389
390
|
children: e.label || `Step ${t + 1}`
|
|
390
391
|
})
|
|
391
392
|
})]
|
|
@@ -396,21 +397,21 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
396
397
|
}),
|
|
397
398
|
/* @__PURE__ */ X("div", {
|
|
398
399
|
className: "min-h-[200px]",
|
|
399
|
-
children: z && /* @__PURE__ */ X(
|
|
400
|
+
children: z && /* @__PURE__ */ X(_e, {
|
|
400
401
|
label: z.label,
|
|
401
402
|
description: z.description,
|
|
402
403
|
columns: z.columns || 1,
|
|
403
404
|
children: N.length > 0 ? /* @__PURE__ */ X(l, { schema: {
|
|
404
405
|
type: "form",
|
|
405
406
|
objectName: n.objectName,
|
|
406
|
-
id:
|
|
407
|
+
id: w,
|
|
407
408
|
fields: N,
|
|
408
409
|
layout: "vertical",
|
|
409
410
|
defaultValues: d,
|
|
410
411
|
showSubmit: !1,
|
|
411
412
|
showCancel: !1,
|
|
412
413
|
onSubmit: P
|
|
413
|
-
} },
|
|
414
|
+
} }, T) : /* @__PURE__ */ X("div", {
|
|
414
415
|
className: "text-center py-8 text-muted-foreground",
|
|
415
416
|
children: "No fields configured for this step"
|
|
416
417
|
})
|
|
@@ -418,7 +419,7 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
418
419
|
}),
|
|
419
420
|
/* @__PURE__ */ Z("div", {
|
|
420
421
|
className: "flex items-center justify-between mt-6 pt-4 border-t",
|
|
421
|
-
children: [/* @__PURE__ */ X("div", { children: n.showCancel !== !1 && /* @__PURE__ */ X(
|
|
422
|
+
children: [/* @__PURE__ */ X("div", { children: n.showCancel !== !1 && /* @__PURE__ */ X(O, {
|
|
422
423
|
variant: "ghost",
|
|
423
424
|
onClick: L,
|
|
424
425
|
children: n.cancelText || "Cancel"
|
|
@@ -434,30 +435,30 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
434
435
|
k
|
|
435
436
|
]
|
|
436
437
|
}),
|
|
437
|
-
!A && /* @__PURE__ */ Z(
|
|
438
|
+
!A && /* @__PURE__ */ Z(O, {
|
|
438
439
|
variant: "outline",
|
|
439
440
|
onClick: I,
|
|
440
|
-
children: [/* @__PURE__ */ X(
|
|
441
|
+
children: [/* @__PURE__ */ X(de, { className: "h-4 w-4 mr-1" }), n.prevText || "Back"]
|
|
441
442
|
}),
|
|
442
|
-
j ? /* @__PURE__ */ Z(
|
|
443
|
+
j ? /* @__PURE__ */ Z(O, {
|
|
443
444
|
type: "submit",
|
|
444
|
-
form:
|
|
445
|
-
disabled:
|
|
446
|
-
children: [
|
|
445
|
+
form: w,
|
|
446
|
+
disabled: S || n.mode === "view",
|
|
447
|
+
children: [S && /* @__PURE__ */ X(fe, {
|
|
447
448
|
className: "mr-2 h-4 w-4 animate-spin",
|
|
448
449
|
"aria-hidden": !0
|
|
449
|
-
}),
|
|
450
|
-
}) : /* @__PURE__ */ Z(
|
|
450
|
+
}), S ? "Submitting..." : n.submitText || (n.mode === "create" ? "Create" : "Update")]
|
|
451
|
+
}) : /* @__PURE__ */ Z(O, {
|
|
451
452
|
type: "submit",
|
|
452
|
-
form:
|
|
453
|
-
children: [n.nextText || "Next", /* @__PURE__ */ X(
|
|
453
|
+
form: w,
|
|
454
|
+
children: [n.nextText || "Next", /* @__PURE__ */ X(J, { className: "h-4 w-4 ml-1" })]
|
|
454
455
|
})
|
|
455
456
|
]
|
|
456
457
|
})]
|
|
457
458
|
})
|
|
458
459
|
]
|
|
459
460
|
});
|
|
460
|
-
},
|
|
461
|
+
}, we = ({ schema: e, dataSource: n, className: i }) => {
|
|
461
462
|
let { fieldLabel: o } = p(), [c, u] = s(null), [d, f] = s({}), [m, h] = s(!0), [g, _] = s(null);
|
|
462
463
|
r(() => {
|
|
463
464
|
(async () => {
|
|
@@ -498,7 +499,7 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
498
499
|
n,
|
|
499
500
|
e.objectName
|
|
500
501
|
]);
|
|
501
|
-
let v = t((t) =>
|
|
502
|
+
let v = t((t) => xe(t, {
|
|
502
503
|
objectSchema: c,
|
|
503
504
|
objectName: e.objectName,
|
|
504
505
|
readOnly: e.readOnly,
|
|
@@ -549,7 +550,7 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
549
550
|
onCancel: b
|
|
550
551
|
}, E = (t, n) => /* @__PURE__ */ X("div", {
|
|
551
552
|
className: "space-y-4 p-4",
|
|
552
|
-
children: t.map((t, r) => /* @__PURE__ */ X(
|
|
553
|
+
children: t.map((t, r) => /* @__PURE__ */ X(_e, {
|
|
553
554
|
label: t.label,
|
|
554
555
|
description: t.description,
|
|
555
556
|
columns: t.columns || 1,
|
|
@@ -564,36 +565,36 @@ var pe = ({ schema: n, dataSource: r, className: i }) => {
|
|
|
564
565
|
}, t.name || t.label || r))
|
|
565
566
|
});
|
|
566
567
|
return /* @__PURE__ */ X("div", {
|
|
567
|
-
className:
|
|
568
|
-
children: /* @__PURE__ */ Z(
|
|
568
|
+
className: G("w-full", i, e.className),
|
|
569
|
+
children: /* @__PURE__ */ Z(V, {
|
|
569
570
|
orientation: C,
|
|
570
571
|
className: "min-h-[300px] rounded-lg border",
|
|
571
|
-
children: [/* @__PURE__ */ X(
|
|
572
|
+
children: [/* @__PURE__ */ X(B, {
|
|
572
573
|
defaultSize: w,
|
|
573
574
|
minSize: 20,
|
|
574
575
|
children: E(x, S.length === 0)
|
|
575
|
-
}), S.length > 0 && /* @__PURE__ */ Z(
|
|
576
|
+
}), S.length > 0 && /* @__PURE__ */ Z(Y, { children: [/* @__PURE__ */ X(z, { withHandle: e.splitResizable !== !1 }), /* @__PURE__ */ X(B, {
|
|
576
577
|
defaultSize: 100 - w,
|
|
577
578
|
minSize: 20,
|
|
578
579
|
children: E(S, !0)
|
|
579
580
|
})] })]
|
|
580
581
|
})
|
|
581
582
|
});
|
|
582
|
-
}, $ = (e) => e == null ? void 0 : e.id ?? e._id ?? e.recordId,
|
|
583
|
+
}, $ = (e) => e == null ? void 0 : e.id ?? e._id ?? e.recordId, Te = new Set([
|
|
583
584
|
"id",
|
|
584
585
|
"_id",
|
|
585
586
|
"recordId"
|
|
586
587
|
]);
|
|
587
|
-
function
|
|
588
|
-
return e ? Object.entries(e).every(([e, n]) => e === t ||
|
|
588
|
+
function Ee(e, t) {
|
|
589
|
+
return e ? Object.entries(e).every(([e, n]) => e === t || Te.has(e) ? !0 : n == null || n === "") : !0;
|
|
589
590
|
}
|
|
590
|
-
function
|
|
591
|
+
function De(e, t, n) {
|
|
591
592
|
let r = [{
|
|
592
593
|
object: e,
|
|
593
594
|
action: "create",
|
|
594
595
|
data: t
|
|
595
596
|
}];
|
|
596
|
-
for (let e of n) for (let t of e.rows)
|
|
597
|
+
for (let e of n) for (let t of e.rows) Ee(t, e.relationshipField) || r.push({
|
|
597
598
|
object: e.childObject,
|
|
598
599
|
action: "create",
|
|
599
600
|
data: {
|
|
@@ -603,7 +604,7 @@ function ve(e, t, n) {
|
|
|
603
604
|
});
|
|
604
605
|
return r;
|
|
605
606
|
}
|
|
606
|
-
function
|
|
607
|
+
function Oe(e, t, n, r) {
|
|
607
608
|
let i = [{
|
|
608
609
|
object: e,
|
|
609
610
|
action: "update",
|
|
@@ -614,9 +615,9 @@ function ye(e, t, n, r) {
|
|
|
614
615
|
let n = (e.rows || []).map((n) => ({
|
|
615
616
|
...n,
|
|
616
617
|
[e.relationshipField]: t
|
|
617
|
-
})), { toCreate: r, toUpdate: a, toDelete: o } =
|
|
618
|
+
})), { toCreate: r, toUpdate: a, toDelete: o } = ke(e.original || [], n);
|
|
618
619
|
for (let t of r) {
|
|
619
|
-
if (
|
|
620
|
+
if (Ee(t, e.relationshipField)) continue;
|
|
620
621
|
let { id: n, _id: r, recordId: a, ...o } = t;
|
|
621
622
|
i.push({
|
|
622
623
|
object: e.childObject,
|
|
@@ -638,7 +639,7 @@ function ye(e, t, n, r) {
|
|
|
638
639
|
}
|
|
639
640
|
return i;
|
|
640
641
|
}
|
|
641
|
-
function
|
|
642
|
+
function ke(e, t) {
|
|
642
643
|
let n = new Set(t.map($).filter(Boolean));
|
|
643
644
|
return {
|
|
644
645
|
toCreate: t.filter((e) => !$(e)),
|
|
@@ -646,25 +647,25 @@ function be(e, t) {
|
|
|
646
647
|
toDelete: (e || []).map($).filter((e) => !!e && !n.has(e))
|
|
647
648
|
};
|
|
648
649
|
}
|
|
649
|
-
function
|
|
650
|
+
function Ae(e, t) {
|
|
650
651
|
return Array.isArray(e) ? e.reduce((e, n) => {
|
|
651
652
|
let r = Number(n?.[t]);
|
|
652
653
|
return e + (Number.isFinite(r) ? r : 0);
|
|
653
654
|
}, 0) : 0;
|
|
654
655
|
}
|
|
655
|
-
function
|
|
656
|
+
function je(e) {
|
|
656
657
|
return Array.isArray(e) ? e : e && Array.isArray(e.records) ? e.records : e && Array.isArray(e.data) ? e.data : e && (e.id || e._id) ? [e] : [];
|
|
657
658
|
}
|
|
658
|
-
async function
|
|
659
|
-
return n.length === 0 ? [] : typeof e.bulk == "function" ?
|
|
659
|
+
async function Me(e, t, n) {
|
|
660
|
+
return n.length === 0 ? [] : typeof e.bulk == "function" ? je(await e.bulk(t, "create", n)) : je(await Promise.all(n.map((n) => e.create(t, n))));
|
|
660
661
|
}
|
|
661
|
-
async function
|
|
662
|
-
let i = [], a = r.rows.filter((e) => $(e) || !
|
|
662
|
+
async function Ne(e, t, n, r) {
|
|
663
|
+
let i = [], a = r.rows.filter((e) => $(e) || !Ee(e, r.relationshipField)).map((e) => ({
|
|
663
664
|
...e,
|
|
664
665
|
[r.relationshipField]: n
|
|
665
666
|
}));
|
|
666
667
|
if (r.original !== void 0) {
|
|
667
|
-
let { toCreate: t, toUpdate: n, toDelete: o } =
|
|
668
|
+
let { toCreate: t, toUpdate: n, toDelete: o } = ke(r.original, a), s = await Me(e, r.childObject, t);
|
|
668
669
|
for (let e of s) {
|
|
669
670
|
let t = $(e);
|
|
670
671
|
t && i.push({
|
|
@@ -674,7 +675,7 @@ async function we(e, t, n, r) {
|
|
|
674
675
|
}
|
|
675
676
|
await Promise.all(n.map((t) => e.update(r.childObject, $(t), t))), await Promise.all(o.map((t) => e.delete(r.childObject, t)));
|
|
676
677
|
} else {
|
|
677
|
-
let t = await
|
|
678
|
+
let t = await Me(e, r.childObject, a);
|
|
678
679
|
for (let e of t) {
|
|
679
680
|
let t = $(e);
|
|
680
681
|
t && i.push({
|
|
@@ -684,14 +685,14 @@ async function we(e, t, n, r) {
|
|
|
684
685
|
}
|
|
685
686
|
}
|
|
686
687
|
if (r.totalField) {
|
|
687
|
-
let i =
|
|
688
|
+
let i = Ae(r.rows, r.amountField || "amount");
|
|
688
689
|
await e.update(t, n, { [r.totalField]: i });
|
|
689
690
|
}
|
|
690
691
|
return { created: i };
|
|
691
692
|
}
|
|
692
693
|
//#endregion
|
|
693
694
|
//#region src/deriveMasterDetail.ts
|
|
694
|
-
var
|
|
695
|
+
var Pe = new Set([
|
|
695
696
|
"id",
|
|
696
697
|
"_id",
|
|
697
698
|
"recordId",
|
|
@@ -707,14 +708,14 @@ var Te = new Set([
|
|
|
707
708
|
"tenant_id",
|
|
708
709
|
"space",
|
|
709
710
|
"owner"
|
|
710
|
-
]),
|
|
711
|
+
]), Fe = new Set([
|
|
711
712
|
"position",
|
|
712
713
|
"sort_order",
|
|
713
714
|
"sequence",
|
|
714
715
|
"line_no",
|
|
715
716
|
"line_number",
|
|
716
717
|
"sort"
|
|
717
|
-
]),
|
|
718
|
+
]), Ie = new Set([
|
|
718
719
|
"formula",
|
|
719
720
|
"summary",
|
|
720
721
|
"rollup",
|
|
@@ -733,7 +734,7 @@ var Te = new Set([
|
|
|
733
734
|
"markdown",
|
|
734
735
|
"richtext"
|
|
735
736
|
]);
|
|
736
|
-
function
|
|
737
|
+
function Le(e) {
|
|
737
738
|
switch (e) {
|
|
738
739
|
case "number":
|
|
739
740
|
case "percent":
|
|
@@ -753,7 +754,7 @@ function Oe(e) {
|
|
|
753
754
|
default: return "text";
|
|
754
755
|
}
|
|
755
756
|
}
|
|
756
|
-
function
|
|
757
|
+
function Re(e) {
|
|
757
758
|
if (e?.type === "boolean" || e?.type === "toggle") return [{
|
|
758
759
|
label: "Yes",
|
|
759
760
|
value: "true"
|
|
@@ -770,7 +771,7 @@ function ke(e) {
|
|
|
770
771
|
value: String(e)
|
|
771
772
|
});
|
|
772
773
|
}
|
|
773
|
-
function
|
|
774
|
+
function ze(e, t) {
|
|
774
775
|
let n = e?.fields;
|
|
775
776
|
if (!n || typeof n != "object") return;
|
|
776
777
|
let r;
|
|
@@ -783,7 +784,7 @@ function Ae(e, t) {
|
|
|
783
784
|
}
|
|
784
785
|
return r;
|
|
785
786
|
}
|
|
786
|
-
var
|
|
787
|
+
var Be = [
|
|
787
788
|
"name",
|
|
788
789
|
"title",
|
|
789
790
|
"subject",
|
|
@@ -791,7 +792,7 @@ var je = [
|
|
|
791
792
|
"full_name",
|
|
792
793
|
"display_name",
|
|
793
794
|
"code"
|
|
794
|
-
],
|
|
795
|
+
], Ve = {
|
|
795
796
|
select: 0,
|
|
796
797
|
currency: 1,
|
|
797
798
|
number: 1,
|
|
@@ -799,15 +800,15 @@ var je = [
|
|
|
799
800
|
date: 3,
|
|
800
801
|
text: 4
|
|
801
802
|
};
|
|
802
|
-
function
|
|
803
|
+
function He(e, t) {
|
|
803
804
|
if (t <= 0 || e.length <= t) return e;
|
|
804
|
-
let n = /* @__PURE__ */ new Set(), r = e.find((e) =>
|
|
805
|
+
let n = /* @__PURE__ */ new Set(), r = e.find((e) => Be.includes(e.field)) ?? e[0];
|
|
805
806
|
r && n.add(r.field);
|
|
806
807
|
for (let t of e) t.required && n.add(t.field);
|
|
807
808
|
let i = e.map((e, t) => ({
|
|
808
809
|
c: e,
|
|
809
810
|
i: t
|
|
810
|
-
})).filter(({ c: e }) => !n.has(e.field)).sort((e, t) => (
|
|
811
|
+
})).filter(({ c: e }) => !n.has(e.field)).sort((e, t) => (Ve[e.c.type] ?? 5) - (Ve[t.c.type] ?? 5) || e.i - t.i);
|
|
811
812
|
for (let { c: e } of i) {
|
|
812
813
|
if (n.size >= t) break;
|
|
813
814
|
n.add(e.field);
|
|
@@ -817,43 +818,43 @@ function Ne(e, t) {
|
|
|
817
818
|
defaultHidden: !0
|
|
818
819
|
});
|
|
819
820
|
}
|
|
820
|
-
function
|
|
821
|
+
function Ue(e, t = {}) {
|
|
821
822
|
let n = e?.fields;
|
|
822
823
|
if (!n || typeof n != "object") return [];
|
|
823
824
|
let r = new Set([...t.exclude ?? [], ...t.relationshipField ? [t.relationshipField] : []]), i = [];
|
|
824
825
|
for (let [e, t] of Object.entries(n)) {
|
|
825
826
|
let n = t;
|
|
826
|
-
if (
|
|
827
|
+
if (Pe.has(e) || r.has(e) || Fe.has(e) || n?.system || n?.readonly || n?.hidden || Ie.has(n?.type)) continue;
|
|
827
828
|
let a = {
|
|
828
829
|
field: e,
|
|
829
830
|
label: n?.label || e,
|
|
830
|
-
type:
|
|
831
|
+
type: Le(n?.type),
|
|
831
832
|
required: !!n?.required
|
|
832
|
-
}, o =
|
|
833
|
+
}, o = Re(n);
|
|
833
834
|
a.type === "select" && o && (a.options = o), a.type === "lookup" && (a.reference = n?.reference, a.displayField = n?.display_field || n?.reference_field), n?.readonlyWhen && (a.readonlyWhen = n.readonlyWhen), (n?.requiredWhen ?? n?.conditionalRequired) && (a.requiredWhen = n.requiredWhen ?? n.conditionalRequired);
|
|
834
835
|
let s = typeof n?.expression == "string" ? n.expression : n?.expression?.source;
|
|
835
836
|
s && typeof s == "string" && (a.computed = !0, a.expr = s, a.required = !1, typeof n?.scale == "number" && (a.scale = n.scale)), i.push(a);
|
|
836
837
|
}
|
|
837
|
-
return
|
|
838
|
+
return He(i, t.maxColumns ?? 6);
|
|
838
839
|
}
|
|
839
|
-
var
|
|
840
|
+
var We = new Set([
|
|
840
841
|
"formula",
|
|
841
842
|
"summary",
|
|
842
843
|
"rollup",
|
|
843
844
|
"autonumber",
|
|
844
845
|
"auto_number"
|
|
845
846
|
]);
|
|
846
|
-
function
|
|
847
|
+
function Ge(e, t = {}) {
|
|
847
848
|
let n = e?.fields;
|
|
848
849
|
if (!n || typeof n != "object") return [];
|
|
849
850
|
let r = new Set([...t.exclude ?? [], ...t.relationshipField ? [t.relationshipField] : []]), i = [];
|
|
850
851
|
for (let [e, t] of Object.entries(n)) {
|
|
851
852
|
let n = t;
|
|
852
|
-
|
|
853
|
+
Pe.has(e) || r.has(e) || Fe.has(e) || n?.system || n?.hidden || We.has(n?.type) || i.push(e);
|
|
853
854
|
}
|
|
854
855
|
return i;
|
|
855
856
|
}
|
|
856
|
-
var
|
|
857
|
+
var Ke = new Set([
|
|
857
858
|
"textarea",
|
|
858
859
|
"richtext",
|
|
859
860
|
"html",
|
|
@@ -867,12 +868,12 @@ var Le = new Set([
|
|
|
867
868
|
"location",
|
|
868
869
|
"address"
|
|
869
870
|
]);
|
|
870
|
-
function
|
|
871
|
+
function qe(e, t, n = {}) {
|
|
871
872
|
if (t === "grid" || t === "form") return t;
|
|
872
|
-
let r = e?.fields ?? {}, i =
|
|
873
|
-
return i.some((e) =>
|
|
873
|
+
let r = e?.fields ?? {}, i = Ge(e, { relationshipField: n.relationshipField });
|
|
874
|
+
return i.some((e) => Ke.has(r[e]?.type)) || i.length > 8 ? "form" : "grid";
|
|
874
875
|
}
|
|
875
|
-
var
|
|
876
|
+
var Je = [
|
|
876
877
|
"amount",
|
|
877
878
|
"total",
|
|
878
879
|
"subtotal",
|
|
@@ -880,33 +881,33 @@ var ze = [
|
|
|
880
881
|
"line_amount",
|
|
881
882
|
"net_amount"
|
|
882
883
|
];
|
|
883
|
-
function
|
|
884
|
+
function Ye(e) {
|
|
884
885
|
let t = e.filter((e) => e.type === "number" || e.type === "currency");
|
|
885
886
|
if (t.length === 0) return;
|
|
886
887
|
let n = t.find((e) => e.computed);
|
|
887
888
|
if (n) return n.field;
|
|
888
|
-
let r = t.find((e) =>
|
|
889
|
+
let r = t.find((e) => Je.includes(e.field));
|
|
889
890
|
if (r) return r.field;
|
|
890
891
|
let i = [...t].reverse().find((e) => e.type === "currency");
|
|
891
892
|
return i ? i.field : t[t.length - 1].field;
|
|
892
893
|
}
|
|
893
|
-
function
|
|
894
|
-
let i = r.relationshipField ||
|
|
894
|
+
function Xe(e, t, n, r = {}) {
|
|
895
|
+
let i = r.relationshipField || ze(t, n);
|
|
895
896
|
if (!i) throw Error(`MasterDetailForm: could not find a lookup/master_detail field on "${e}" referencing "${n}". Set relationshipField explicitly.`);
|
|
896
|
-
let a = r.columns?.length ? r.columns :
|
|
897
|
+
let a = r.columns?.length ? r.columns : Ue(t, { relationshipField: i }), o = r.amountField || Ye(a);
|
|
897
898
|
return {
|
|
898
899
|
childObject: e,
|
|
899
900
|
relationshipField: i,
|
|
900
901
|
columns: a,
|
|
901
|
-
formFields:
|
|
902
|
-
mode:
|
|
902
|
+
formFields: Ge(t, { relationshipField: i }),
|
|
903
|
+
mode: qe(t, r.inlineEdit ?? (t?.fields)?.[i]?.inlineEdit, { relationshipField: i }),
|
|
903
904
|
amountField: o,
|
|
904
|
-
sortField: Object.keys(t?.fields ?? {}).find((e) =>
|
|
905
|
+
sortField: Object.keys(t?.fields ?? {}).find((e) => Fe.has(e))
|
|
905
906
|
};
|
|
906
907
|
}
|
|
907
908
|
//#endregion
|
|
908
909
|
//#region src/MasterDetailForm.tsx
|
|
909
|
-
function
|
|
910
|
+
function Ze(e) {
|
|
910
911
|
if (!e) return {};
|
|
911
912
|
let t = {};
|
|
912
913
|
return e.querySelectorAll("[name]").forEach((e) => {
|
|
@@ -938,13 +939,13 @@ function He(e) {
|
|
|
938
939
|
}
|
|
939
940
|
}), t;
|
|
940
941
|
}
|
|
941
|
-
var
|
|
942
|
+
var Qe = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, formKey: c, onRowExpand: l, onAddViaForm: u }) => {
|
|
942
943
|
let [d, f] = s({}), p = o("");
|
|
943
944
|
r(() => {
|
|
944
945
|
let e = i.current;
|
|
945
946
|
if (!e) return;
|
|
946
947
|
let t = () => {
|
|
947
|
-
let t =
|
|
948
|
+
let t = Ze(e), n;
|
|
948
949
|
try {
|
|
949
950
|
n = JSON.stringify(t);
|
|
950
951
|
} catch {
|
|
@@ -968,11 +969,11 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
968
969
|
c,
|
|
969
970
|
e.length
|
|
970
971
|
]);
|
|
971
|
-
let m = d[a], g = m === void 0 ? null : Number.isFinite(Number(m)) ? Number(m) : 0, _ = e.reduce((e, n, r) => e +
|
|
972
|
+
let m = d[a], g = m === void 0 ? null : Number.isFinite(Number(m)) ? Number(m) : 0, _ = e.reduce((e, n, r) => e + Ae(t[r]?.rows ?? [], n.amountField || "amount"), 0), v = g !== null && e.some((e) => !!e.amountField), y = g ?? 0, b = y / 100 * _, x = _ + b, S = (e) => `¥${e.toLocaleString(void 0, {
|
|
972
973
|
minimumFractionDigits: 2,
|
|
973
974
|
maximumFractionDigits: 2
|
|
974
975
|
})}`;
|
|
975
|
-
return /* @__PURE__ */ Z(
|
|
976
|
+
return /* @__PURE__ */ Z(Y, { children: [e.map((e, r) => /* @__PURE__ */ Z("section", {
|
|
976
977
|
className: "space-y-2",
|
|
977
978
|
children: [/* @__PURE__ */ X("h3", {
|
|
978
979
|
className: "text-sm font-medium text-foreground",
|
|
@@ -1039,7 +1040,7 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1039
1040
|
]
|
|
1040
1041
|
})
|
|
1041
1042
|
})] });
|
|
1042
|
-
},
|
|
1043
|
+
}, $e = ({ schema: e, dataSource: n, className: i }) => {
|
|
1043
1044
|
let c = e.details || [], l = e.mode === "edit" && !!e.recordId, u = c.some((e) => !e.relationshipField || !e.columns?.length), [d, f] = s(u ? null : c), p = d ?? c;
|
|
1044
1045
|
r(() => {
|
|
1045
1046
|
if (!u) {
|
|
@@ -1052,7 +1053,7 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1052
1053
|
let r = await Promise.all(c.map(async (t) => {
|
|
1053
1054
|
if (t.relationshipField && t.columns?.length) return t;
|
|
1054
1055
|
try {
|
|
1055
|
-
let r = await n.getObjectSchema(t.childObject), i =
|
|
1056
|
+
let r = await n.getObjectSchema(t.childObject), i = Xe(t.childObject, r, e.objectName, {
|
|
1056
1057
|
relationshipField: t.relationshipField,
|
|
1057
1058
|
columns: t.columns,
|
|
1058
1059
|
amountField: t.amountField
|
|
@@ -1084,8 +1085,8 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1084
1085
|
original: []
|
|
1085
1086
|
}))), g = o(m);
|
|
1086
1087
|
g.current = m;
|
|
1087
|
-
let [_, v] = s(0), [y,
|
|
1088
|
-
|
|
1088
|
+
let [_, v] = s(0), [y, b] = s(!1), x = o(!1), S = o(null), C = t(() => {
|
|
1089
|
+
x.current = !1, b(!1), S.current &&= (clearTimeout(S.current), null);
|
|
1089
1090
|
}, []);
|
|
1090
1091
|
r(() => {
|
|
1091
1092
|
let t = !1;
|
|
@@ -1121,12 +1122,12 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1121
1122
|
e.recordId,
|
|
1122
1123
|
d
|
|
1123
1124
|
]);
|
|
1124
|
-
let
|
|
1125
|
+
let w = t((e, t) => {
|
|
1125
1126
|
h((n) => n.map((n, r) => r === e ? {
|
|
1126
1127
|
...n,
|
|
1127
1128
|
rows: t
|
|
1128
1129
|
} : n));
|
|
1129
|
-
}, []),
|
|
1130
|
+
}, []), T = e.taxRateField || "tax_rate", [E, D] = s(null), j = E ? m[E.detailIdx]?.rows?.[E.rowIdx] : void 0, P = E ? p[E.detailIdx] : void 0, F = t((e, t, n) => {
|
|
1130
1131
|
h((r) => r.map((r, i) => i === e ? {
|
|
1131
1132
|
...r,
|
|
1132
1133
|
rows: r.rows.map((e, r) => r === t ? {
|
|
@@ -1140,19 +1141,19 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1140
1141
|
...t,
|
|
1141
1142
|
rows: [...t.rows, {}]
|
|
1142
1143
|
} : t);
|
|
1143
|
-
return
|
|
1144
|
+
return D({
|
|
1144
1145
|
detailIdx: e,
|
|
1145
1146
|
rowIdx: n[e].rows.length - 1,
|
|
1146
1147
|
isNew: !0
|
|
1147
1148
|
}), n;
|
|
1148
1149
|
});
|
|
1149
1150
|
}, []), L = t(() => {
|
|
1150
|
-
|
|
1151
|
+
D((e) => (e?.isNew && h((t) => t.map((t, n) => n === e.detailIdx ? {
|
|
1151
1152
|
...t,
|
|
1152
1153
|
rows: t.rows.filter((t, n) => n !== e.rowIdx)
|
|
1153
1154
|
} : t)), null));
|
|
1154
1155
|
}, []), R = t(async (t) => {
|
|
1155
|
-
|
|
1156
|
+
C(), se.success(l ? e.title ? `${e.title} saved` : "Saved" : "Created"), l || (h(p.map(() => ({
|
|
1156
1157
|
rows: [],
|
|
1157
1158
|
original: []
|
|
1158
1159
|
}))), v((e) => e + 1)), await e.onSuccess?.(t);
|
|
@@ -1161,15 +1162,15 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1161
1162
|
e.onSuccess,
|
|
1162
1163
|
e.title,
|
|
1163
1164
|
p.length,
|
|
1164
|
-
|
|
1165
|
+
C
|
|
1165
1166
|
]), z = t((t) => {
|
|
1166
|
-
|
|
1167
|
-
}, [e,
|
|
1167
|
+
C(), se.error(t?.message || "Save failed"), e.onError?.(t);
|
|
1168
|
+
}, [e, C]), B = t(async (t) => {
|
|
1168
1169
|
let r = [];
|
|
1169
1170
|
for (let i = 0; i < p.length; i++) {
|
|
1170
1171
|
let a = p[i], { rows: o, original: s } = g.current[i];
|
|
1171
1172
|
if (!a.relationshipField) continue;
|
|
1172
|
-
let { created: c } = await
|
|
1173
|
+
let { created: c } = await Ne(n, e.objectName, t, {
|
|
1173
1174
|
childObject: a.childObject,
|
|
1174
1175
|
relationshipField: a.relationshipField,
|
|
1175
1176
|
rows: o,
|
|
@@ -1202,17 +1203,17 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1202
1203
|
B,
|
|
1203
1204
|
e,
|
|
1204
1205
|
R
|
|
1205
|
-
]),
|
|
1206
|
+
]), ee = typeof n?.batchTransaction == "function", te = t(async (t) => {
|
|
1206
1207
|
let r = n, i = { ...t };
|
|
1207
1208
|
p.forEach((e, t) => {
|
|
1208
|
-
e.totalField && (i[e.totalField] =
|
|
1209
|
+
e.totalField && (i[e.totalField] = Ae(g.current[t]?.rows ?? [], e.amountField || "amount"));
|
|
1209
1210
|
});
|
|
1210
|
-
let a = l ?
|
|
1211
|
+
let a = l ? Oe(e.objectName, e.recordId, i, p.filter((e) => e.relationshipField).map((e, t) => ({
|
|
1211
1212
|
childObject: e.childObject,
|
|
1212
1213
|
relationshipField: e.relationshipField,
|
|
1213
1214
|
rows: g.current[t]?.rows ?? [],
|
|
1214
1215
|
original: g.current[t]?.original ?? []
|
|
1215
|
-
}))) :
|
|
1216
|
+
}))) : De(e.objectName, i, p.filter((e) => e.relationshipField).map((e, t) => ({
|
|
1216
1217
|
childObject: e.childObject,
|
|
1217
1218
|
relationshipField: e.relationshipField,
|
|
1218
1219
|
rows: g.current[t]?.rows ?? []
|
|
@@ -1227,7 +1228,7 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1227
1228
|
e.objectName,
|
|
1228
1229
|
e.recordId,
|
|
1229
1230
|
l
|
|
1230
|
-
]),
|
|
1231
|
+
]), H = a(() => ({
|
|
1231
1232
|
type: "object-form",
|
|
1232
1233
|
objectName: e.objectName,
|
|
1233
1234
|
mode: e.mode ?? "create",
|
|
@@ -1240,61 +1241,61 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1240
1241
|
title: e.title,
|
|
1241
1242
|
showSubmit: !1,
|
|
1242
1243
|
showCancel: !1,
|
|
1243
|
-
...
|
|
1244
|
-
submitHandler:
|
|
1244
|
+
...ee ? {
|
|
1245
|
+
submitHandler: te,
|
|
1245
1246
|
onSuccess: R
|
|
1246
1247
|
} : { onSuccess: V },
|
|
1247
1248
|
onError: z
|
|
1248
1249
|
}), [
|
|
1249
1250
|
e,
|
|
1250
1251
|
V,
|
|
1251
|
-
|
|
1252
|
-
|
|
1252
|
+
ee,
|
|
1253
|
+
te,
|
|
1253
1254
|
R,
|
|
1254
1255
|
z
|
|
1255
|
-
]),
|
|
1256
|
-
|
|
1257
|
-
(
|
|
1258
|
-
}, 0),
|
|
1259
|
-
}, [
|
|
1256
|
+
]), U = o(null), ne = e.submitText ?? (l ? "Save" : "Create"), W = t(() => {
|
|
1257
|
+
x.current || U.current?.querySelector("form") && (x.current = !0, b(!0), setTimeout(() => {
|
|
1258
|
+
(U.current?.querySelector("form"))?.requestSubmit();
|
|
1259
|
+
}, 0), S.current = setTimeout(() => C(), 1500));
|
|
1260
|
+
}, [C]);
|
|
1260
1261
|
return r(() => () => {
|
|
1261
|
-
|
|
1262
|
+
S.current && clearTimeout(S.current);
|
|
1262
1263
|
}, []), /* @__PURE__ */ Z("div", {
|
|
1263
|
-
className:
|
|
1264
|
+
className: G("space-y-6", i, e.className),
|
|
1264
1265
|
children: [
|
|
1265
1266
|
/* @__PURE__ */ X("div", {
|
|
1266
|
-
ref:
|
|
1267
|
-
children: /* @__PURE__ */ X(
|
|
1268
|
-
schema:
|
|
1267
|
+
ref: U,
|
|
1268
|
+
children: /* @__PURE__ */ X(Tt, {
|
|
1269
|
+
schema: H,
|
|
1269
1270
|
dataSource: n
|
|
1270
1271
|
}, _)
|
|
1271
1272
|
}),
|
|
1272
|
-
/* @__PURE__ */ X(
|
|
1273
|
+
/* @__PURE__ */ X(Qe, {
|
|
1273
1274
|
details: p,
|
|
1274
1275
|
state: m,
|
|
1275
|
-
setRows:
|
|
1276
|
-
formHostRef:
|
|
1277
|
-
taxRateField:
|
|
1276
|
+
setRows: w,
|
|
1277
|
+
formHostRef: U,
|
|
1278
|
+
taxRateField: T,
|
|
1278
1279
|
formKey: _,
|
|
1279
|
-
onRowExpand: (e, t) =>
|
|
1280
|
+
onRowExpand: (e, t) => D({
|
|
1280
1281
|
detailIdx: e,
|
|
1281
1282
|
rowIdx: t
|
|
1282
1283
|
}),
|
|
1283
1284
|
onAddViaForm: I
|
|
1284
1285
|
}),
|
|
1285
|
-
|
|
1286
|
+
E && P && /* @__PURE__ */ Z(k, {
|
|
1286
1287
|
className: "border-primary/40 shadow-none ring-1 ring-primary/10",
|
|
1287
1288
|
"data-testid": "md-row-form",
|
|
1288
|
-
children: [/* @__PURE__ */ Z(
|
|
1289
|
+
children: [/* @__PURE__ */ Z(M, {
|
|
1289
1290
|
className: "pb-2 flex flex-row items-center justify-between gap-2 space-y-0",
|
|
1290
|
-
children: [/* @__PURE__ */ Z(
|
|
1291
|
+
children: [/* @__PURE__ */ Z(N, {
|
|
1291
1292
|
className: "text-sm font-medium",
|
|
1292
1293
|
children: [
|
|
1293
1294
|
P.title || "Line item",
|
|
1294
1295
|
" — row ",
|
|
1295
|
-
|
|
1296
|
+
E.rowIdx + 1
|
|
1296
1297
|
]
|
|
1297
|
-
}), /* @__PURE__ */ X(
|
|
1298
|
+
}), /* @__PURE__ */ X(O, {
|
|
1298
1299
|
type: "button",
|
|
1299
1300
|
variant: "ghost",
|
|
1300
1301
|
size: "sm",
|
|
@@ -1302,48 +1303,48 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1302
1303
|
onClick: L,
|
|
1303
1304
|
children: "Close"
|
|
1304
1305
|
})]
|
|
1305
|
-
}), /* @__PURE__ */ X(
|
|
1306
|
+
}), /* @__PURE__ */ X(A, { children: /* @__PURE__ */ X(Tt, {
|
|
1306
1307
|
schema: {
|
|
1307
1308
|
type: "object-form",
|
|
1308
1309
|
objectName: P.childObject,
|
|
1309
1310
|
mode: "edit",
|
|
1310
|
-
initialData:
|
|
1311
|
+
initialData: j ?? {},
|
|
1311
1312
|
...P.formFields?.length ? { fields: P.formFields } : {},
|
|
1312
1313
|
submitText: "Apply",
|
|
1313
1314
|
submitHandler: async (e) => e,
|
|
1314
1315
|
onSuccess: (e) => {
|
|
1315
|
-
F(
|
|
1316
|
+
F(E.detailIdx, E.rowIdx, e), D(null);
|
|
1316
1317
|
},
|
|
1317
1318
|
onCancel: L
|
|
1318
1319
|
},
|
|
1319
1320
|
dataSource: n
|
|
1320
|
-
}, `row-${
|
|
1321
|
+
}, `row-${E.detailIdx}-${E.rowIdx}`) })]
|
|
1321
1322
|
}),
|
|
1322
1323
|
e.showSubmit !== !1 && /* @__PURE__ */ Z("div", {
|
|
1323
1324
|
className: "flex items-center justify-end gap-2 border-t border-border pt-4",
|
|
1324
|
-
children: [e.onCancel && /* @__PURE__ */ X(
|
|
1325
|
+
children: [e.onCancel && /* @__PURE__ */ X(O, {
|
|
1325
1326
|
type: "button",
|
|
1326
1327
|
variant: "outline",
|
|
1327
1328
|
onClick: e.onCancel,
|
|
1328
1329
|
disabled: y,
|
|
1329
1330
|
"data-testid": "md-form-cancel",
|
|
1330
1331
|
children: "Cancel"
|
|
1331
|
-
}), /* @__PURE__ */ X(
|
|
1332
|
+
}), /* @__PURE__ */ X(O, {
|
|
1332
1333
|
type: "button",
|
|
1333
|
-
onClick:
|
|
1334
|
+
onClick: W,
|
|
1334
1335
|
disabled: y || u && !d,
|
|
1335
1336
|
"data-testid": "md-form-submit",
|
|
1336
|
-
children: y ? "Saving…" :
|
|
1337
|
+
children: y ? "Saving…" : ne
|
|
1337
1338
|
})]
|
|
1338
1339
|
})
|
|
1339
1340
|
]
|
|
1340
1341
|
});
|
|
1341
|
-
},
|
|
1342
|
+
}, et = new Set([
|
|
1342
1343
|
"field:formula",
|
|
1343
1344
|
"field:summary",
|
|
1344
1345
|
"field:auto_number",
|
|
1345
1346
|
"field:autonumber"
|
|
1346
|
-
]),
|
|
1347
|
+
]), tt = new Set([
|
|
1347
1348
|
"field:textarea",
|
|
1348
1349
|
"field:markdown",
|
|
1349
1350
|
"field:html",
|
|
@@ -1354,28 +1355,28 @@ var Ue = ({ details: e, state: t, setRows: n, formHostRef: i, taxRateField: a, f
|
|
|
1354
1355
|
"html",
|
|
1355
1356
|
"grid",
|
|
1356
1357
|
"rich-text"
|
|
1357
|
-
]),
|
|
1358
|
+
]), nt = new Set([
|
|
1358
1359
|
"formula",
|
|
1359
1360
|
"summary",
|
|
1360
1361
|
"auto_number",
|
|
1361
1362
|
"autonumber"
|
|
1362
1363
|
]);
|
|
1363
|
-
function
|
|
1364
|
-
return
|
|
1364
|
+
function rt(e) {
|
|
1365
|
+
return tt.has(e);
|
|
1365
1366
|
}
|
|
1366
|
-
function
|
|
1367
|
-
return
|
|
1367
|
+
function it(e) {
|
|
1368
|
+
return nt.has(e);
|
|
1368
1369
|
}
|
|
1369
|
-
function
|
|
1370
|
+
function at(e) {
|
|
1370
1371
|
return e <= 3 ? 1 : 2;
|
|
1371
1372
|
}
|
|
1372
|
-
function
|
|
1373
|
-
return t <= 1 ? e : e.map((e) => e.colSpan === void 0 && e.type &&
|
|
1373
|
+
function ot(e, t) {
|
|
1374
|
+
return t <= 1 ? e : e.map((e) => e.colSpan === void 0 && e.type && rt(e.type) ? {
|
|
1374
1375
|
...e,
|
|
1375
1376
|
colSpan: t
|
|
1376
1377
|
} : e);
|
|
1377
1378
|
}
|
|
1378
|
-
var
|
|
1379
|
+
var st = new Set([
|
|
1379
1380
|
"id",
|
|
1380
1381
|
"created_at",
|
|
1381
1382
|
"createdAt",
|
|
@@ -1402,46 +1403,46 @@ var Qe = new Set([
|
|
|
1402
1403
|
"_version",
|
|
1403
1404
|
"_rev"
|
|
1404
1405
|
]);
|
|
1405
|
-
function
|
|
1406
|
+
function ct(e, t) {
|
|
1406
1407
|
return e.filter((e) => {
|
|
1407
|
-
if (
|
|
1408
|
+
if (st.has(e.name)) return !1;
|
|
1408
1409
|
let n = t?.fields?.[e.name];
|
|
1409
1410
|
return !(n?.hidden === !0 || n?.readonly === !0);
|
|
1410
1411
|
});
|
|
1411
1412
|
}
|
|
1412
|
-
function
|
|
1413
|
+
function lt(e, t) {
|
|
1413
1414
|
return e.filter((e) => {
|
|
1414
|
-
if (
|
|
1415
|
+
if (st.has(e.name) || e.type && et.has(e.type)) return !1;
|
|
1415
1416
|
if (!t?.fields) return !0;
|
|
1416
1417
|
let n = t.fields[e.name];
|
|
1417
|
-
return n ? n.readonly === !0 ? !1 : !
|
|
1418
|
+
return n ? n.readonly === !0 ? !1 : !it(n.type) : !0;
|
|
1418
1419
|
});
|
|
1419
1420
|
}
|
|
1420
|
-
function
|
|
1421
|
+
function ut(e, t) {
|
|
1421
1422
|
return e.filter((e) => {
|
|
1422
|
-
if (e.type &&
|
|
1423
|
+
if (e.type && et.has(e.type)) return !1;
|
|
1423
1424
|
let n = t?.fields?.[e.name];
|
|
1424
|
-
return n ? !
|
|
1425
|
+
return n ? !it(n.type) : !0;
|
|
1425
1426
|
});
|
|
1426
1427
|
}
|
|
1427
|
-
function
|
|
1428
|
+
function dt(e) {
|
|
1428
1429
|
return e <= 1 ? "default" : e === 2 ? "xl" : "full";
|
|
1429
1430
|
}
|
|
1430
|
-
function
|
|
1431
|
+
function ft(e, t, n, r) {
|
|
1431
1432
|
let i = [...e];
|
|
1432
|
-
if (i =
|
|
1433
|
+
if (i = ct(i, t), r === "create" && (i = ut(i, t)), n !== void 0) return i = ot(i, n), {
|
|
1433
1434
|
fields: i,
|
|
1434
1435
|
columns: n
|
|
1435
1436
|
};
|
|
1436
|
-
let a =
|
|
1437
|
-
return i =
|
|
1437
|
+
let a = at(i.length);
|
|
1438
|
+
return i = ot(i, a), {
|
|
1438
1439
|
fields: i,
|
|
1439
1440
|
columns: a
|
|
1440
1441
|
};
|
|
1441
1442
|
}
|
|
1442
1443
|
//#endregion
|
|
1443
1444
|
//#region src/sanitize.ts
|
|
1444
|
-
var
|
|
1445
|
+
var pt = new Set([
|
|
1445
1446
|
"id",
|
|
1446
1447
|
"_id",
|
|
1447
1448
|
"created_at",
|
|
@@ -1450,7 +1451,7 @@ var it = new Set([
|
|
|
1450
1451
|
"updatedAt",
|
|
1451
1452
|
"organization_id",
|
|
1452
1453
|
"organizationId"
|
|
1453
|
-
]),
|
|
1454
|
+
]), mt = new Set([
|
|
1454
1455
|
"formula",
|
|
1455
1456
|
"rollup",
|
|
1456
1457
|
"lookup_value",
|
|
@@ -1458,15 +1459,15 @@ var it = new Set([
|
|
|
1458
1459
|
"autonumber",
|
|
1459
1460
|
"computed"
|
|
1460
1461
|
]);
|
|
1461
|
-
function
|
|
1462
|
+
function ht(e, t) {
|
|
1462
1463
|
if (!e || typeof e != "object") return e;
|
|
1463
1464
|
let n = {}, r = t?.fields;
|
|
1464
|
-
for (let [t, i] of Object.entries(e)) if (!
|
|
1465
|
+
for (let [t, i] of Object.entries(e)) if (!pt.has(t)) {
|
|
1465
1466
|
if (r) {
|
|
1466
1467
|
let e = r[t];
|
|
1467
1468
|
if (!e) continue;
|
|
1468
1469
|
let n = String(e.type || "").toLowerCase();
|
|
1469
|
-
if (
|
|
1470
|
+
if (mt.has(n) || e.computed === !0 || e.formula || e.readOnly === !0 || e.readonly === !0) continue;
|
|
1470
1471
|
}
|
|
1471
1472
|
n[t] = i;
|
|
1472
1473
|
}
|
|
@@ -1474,13 +1475,18 @@ function ot(e, t) {
|
|
|
1474
1475
|
}
|
|
1475
1476
|
//#endregion
|
|
1476
1477
|
//#region src/DrawerForm.tsx
|
|
1477
|
-
var
|
|
1478
|
+
var gt = {
|
|
1478
1479
|
1: void 0,
|
|
1479
1480
|
2: "grid gap-4 grid-cols-1 @md:grid-cols-2",
|
|
1480
1481
|
3: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",
|
|
1481
1482
|
4: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"
|
|
1482
|
-
},
|
|
1483
|
-
|
|
1483
|
+
}, _t = Q({
|
|
1484
|
+
"form.discardTitle": "Discard changes?",
|
|
1485
|
+
"form.discardMessage": "You have unsaved changes. If you close this form now, your edits will be lost.",
|
|
1486
|
+
"form.keepEditing": "Keep editing",
|
|
1487
|
+
"form.discard": "Discard"
|
|
1488
|
+
}, "form.discardTitle"), vt = ({ schema: e, dataSource: n, className: c }) => {
|
|
1489
|
+
let { fieldLabel: u } = p(), { t: f } = _t(), m = d(), [h, _] = s(null), [v, k] = s([]), [A, j] = s({}), [M, N] = s(!0), [P, F] = s(null), [I, L] = s(!1), [R, z] = s(!1), [B, V] = s(!1), W = o(!1), re = e.confirmOnDiscard !== !1, ie = e.open !== !1, ae = e.drawerSide || "right", oe = i(), [se, ce] = s(() => {
|
|
1484
1490
|
let t = {};
|
|
1485
1491
|
return e.sections?.forEach((e, n) => {
|
|
1486
1492
|
let r = e.name || String(n);
|
|
@@ -1490,35 +1496,35 @@ var st = {
|
|
|
1490
1496
|
r(() => {
|
|
1491
1497
|
(async () => {
|
|
1492
1498
|
if (!n) {
|
|
1493
|
-
|
|
1499
|
+
N(!1);
|
|
1494
1500
|
return;
|
|
1495
1501
|
}
|
|
1496
1502
|
try {
|
|
1497
|
-
|
|
1503
|
+
_(await n.getObjectSchema(e.objectName));
|
|
1498
1504
|
} catch (e) {
|
|
1499
|
-
|
|
1505
|
+
F(e), N(!1);
|
|
1500
1506
|
}
|
|
1501
1507
|
})();
|
|
1502
1508
|
}, [e.objectName, n]), r(() => {
|
|
1503
|
-
(
|
|
1509
|
+
(h || !n) && (async () => {
|
|
1504
1510
|
if (e.mode === "create" || !e.recordId) {
|
|
1505
|
-
|
|
1511
|
+
j(e.initialData || e.initialValues || {}), N(!1);
|
|
1506
1512
|
return;
|
|
1507
1513
|
}
|
|
1508
1514
|
if (!n) {
|
|
1509
|
-
|
|
1515
|
+
j(e.initialData || e.initialValues || {}), N(!1);
|
|
1510
1516
|
return;
|
|
1511
1517
|
}
|
|
1512
1518
|
try {
|
|
1513
|
-
|
|
1519
|
+
j(await n.findOne(e.objectName, e.recordId) || {});
|
|
1514
1520
|
} catch (e) {
|
|
1515
|
-
|
|
1521
|
+
F(e);
|
|
1516
1522
|
} finally {
|
|
1517
|
-
|
|
1523
|
+
N(!1);
|
|
1518
1524
|
}
|
|
1519
1525
|
})();
|
|
1520
1526
|
}, [
|
|
1521
|
-
|
|
1527
|
+
h,
|
|
1522
1528
|
e.mode,
|
|
1523
1529
|
e.recordId,
|
|
1524
1530
|
e.initialData,
|
|
@@ -1526,38 +1532,38 @@ var st = {
|
|
|
1526
1532
|
n,
|
|
1527
1533
|
e.objectName
|
|
1528
1534
|
]);
|
|
1529
|
-
let
|
|
1530
|
-
objectSchema:
|
|
1535
|
+
let le = t((t) => xe(t, {
|
|
1536
|
+
objectSchema: h,
|
|
1531
1537
|
objectName: e.objectName,
|
|
1532
1538
|
readOnly: e.readOnly,
|
|
1533
1539
|
mode: e.mode,
|
|
1534
|
-
fieldLabel:
|
|
1540
|
+
fieldLabel: u
|
|
1535
1541
|
}), [
|
|
1536
|
-
|
|
1542
|
+
h,
|
|
1537
1543
|
e.readOnly,
|
|
1538
1544
|
e.mode,
|
|
1539
1545
|
e.objectName,
|
|
1540
|
-
|
|
1546
|
+
u
|
|
1541
1547
|
]);
|
|
1542
1548
|
r(() => {
|
|
1543
|
-
if (!
|
|
1549
|
+
if (!h && n) return;
|
|
1544
1550
|
if (e.customFields?.length) {
|
|
1545
|
-
|
|
1551
|
+
k(e.customFields), N(!1);
|
|
1546
1552
|
return;
|
|
1547
1553
|
}
|
|
1548
1554
|
if (e.sections?.length) {
|
|
1549
|
-
|
|
1555
|
+
N(!1);
|
|
1550
1556
|
return;
|
|
1551
1557
|
}
|
|
1552
|
-
if (!
|
|
1553
|
-
let t = e.fields || Object.keys(
|
|
1558
|
+
if (!h) return;
|
|
1559
|
+
let t = e.fields || Object.keys(h.fields || {}), r = [];
|
|
1554
1560
|
for (let n of t) {
|
|
1555
1561
|
let t = typeof n == "string" ? n : n.name;
|
|
1556
1562
|
if (!t) continue;
|
|
1557
|
-
let i =
|
|
1563
|
+
let i = h.fields?.[t];
|
|
1558
1564
|
i && r.push({
|
|
1559
1565
|
name: t,
|
|
1560
|
-
label:
|
|
1566
|
+
label: u(e.objectName, t, i.label || t),
|
|
1561
1567
|
type: y(i.type),
|
|
1562
1568
|
required: i.required || !1,
|
|
1563
1569
|
disabled: e.readOnly || e.mode === "view" || i.readonly,
|
|
@@ -1569,9 +1575,9 @@ var st = {
|
|
|
1569
1575
|
multiple: i.multiple
|
|
1570
1576
|
});
|
|
1571
1577
|
}
|
|
1572
|
-
|
|
1578
|
+
k(r), N(!1);
|
|
1573
1579
|
}, [
|
|
1574
|
-
|
|
1580
|
+
h,
|
|
1575
1581
|
e.fields,
|
|
1576
1582
|
e.customFields,
|
|
1577
1583
|
e.sections,
|
|
@@ -1579,51 +1585,65 @@ var st = {
|
|
|
1579
1585
|
e.mode,
|
|
1580
1586
|
n
|
|
1581
1587
|
]);
|
|
1582
|
-
let
|
|
1583
|
-
|
|
1588
|
+
let K = t(async (t) => {
|
|
1589
|
+
V(!0);
|
|
1584
1590
|
try {
|
|
1585
|
-
|
|
1591
|
+
if (!n) return e.onSuccess && await e.onSuccess(t), e.onOpenChange?.(!1), t;
|
|
1592
|
+
let r, i = ht(t, h);
|
|
1586
1593
|
return e.mode === "create" ? r = await n.create(e.objectName, i) : e.mode === "edit" && e.recordId && (r = await n.update(e.objectName, e.recordId, i)), e.onSuccess && await e.onSuccess(r), e.onOpenChange?.(!1), r;
|
|
1587
1594
|
} catch (t) {
|
|
1588
1595
|
throw e.onError && e.onError(t), t;
|
|
1596
|
+
} finally {
|
|
1597
|
+
V(!1);
|
|
1589
1598
|
}
|
|
1590
1599
|
}, [
|
|
1591
1600
|
e,
|
|
1592
1601
|
n,
|
|
1593
|
-
|
|
1594
|
-
]),
|
|
1595
|
-
|
|
1596
|
-
}, [e]),
|
|
1597
|
-
|
|
1602
|
+
h
|
|
1603
|
+
]), q = t(() => {
|
|
1604
|
+
z(!1), W.current && (W.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
|
|
1605
|
+
}, [e]), ue = t((e) => {
|
|
1606
|
+
W.current = e, re && I ? z(!0) : q();
|
|
1607
|
+
}, [
|
|
1608
|
+
re,
|
|
1609
|
+
I,
|
|
1610
|
+
q
|
|
1611
|
+
]), de = t(() => {
|
|
1612
|
+
W.current = !0, q();
|
|
1613
|
+
}, [q]), J = a(() => {
|
|
1614
|
+
if (e.drawerWidth) return ae === "left" || ae === "right" ? {
|
|
1598
1615
|
width: e.drawerWidth,
|
|
1599
1616
|
maxWidth: e.drawerWidth
|
|
1600
1617
|
} : {
|
|
1601
1618
|
height: e.drawerWidth,
|
|
1602
1619
|
maxHeight: e.drawerWidth
|
|
1603
1620
|
};
|
|
1604
|
-
}, [e.drawerWidth,
|
|
1621
|
+
}, [e.drawerWidth, ae]), pe = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical", me = e.showSubmit !== !1 && e.mode !== "view", Y = e.showCancel !== !1, Q = e.submitText || (e.mode === "create" ? "Create" : "Update"), he = e.cancelText || "Cancel", ge = {
|
|
1605
1622
|
type: "form",
|
|
1606
1623
|
objectName: e.objectName,
|
|
1607
|
-
layout:
|
|
1608
|
-
defaultValues:
|
|
1609
|
-
submitLabel:
|
|
1610
|
-
cancelLabel:
|
|
1611
|
-
showSubmit:
|
|
1612
|
-
showCancel:
|
|
1613
|
-
onSubmit:
|
|
1614
|
-
onCancel:
|
|
1615
|
-
|
|
1616
|
-
|
|
1624
|
+
layout: pe,
|
|
1625
|
+
defaultValues: A,
|
|
1626
|
+
submitLabel: Q,
|
|
1627
|
+
cancelLabel: he,
|
|
1628
|
+
showSubmit: me,
|
|
1629
|
+
showCancel: Y,
|
|
1630
|
+
onSubmit: K,
|
|
1631
|
+
onCancel: de,
|
|
1632
|
+
onDirtyChange: L,
|
|
1633
|
+
showActions: !1,
|
|
1634
|
+
id: oe
|
|
1635
|
+
}, _e = () => {
|
|
1636
|
+
if (P) return /* @__PURE__ */ Z("div", {
|
|
1617
1637
|
className: "p-4 border border-red-300 bg-red-50 rounded-md",
|
|
1618
1638
|
children: [/* @__PURE__ */ X("h3", {
|
|
1619
1639
|
className: "text-red-800 font-semibold",
|
|
1620
1640
|
children: "Error loading form"
|
|
1621
1641
|
}), /* @__PURE__ */ X("p", {
|
|
1622
1642
|
className: "text-red-600 text-sm mt-1",
|
|
1623
|
-
children:
|
|
1643
|
+
children: P.message
|
|
1624
1644
|
})]
|
|
1625
1645
|
});
|
|
1626
|
-
if (
|
|
1646
|
+
if (M) return /* @__PURE__ */ Z("div", {
|
|
1627
1647
|
className: "p-8 text-center",
|
|
1628
1648
|
children: [/* @__PURE__ */ X("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ X("p", {
|
|
1629
1649
|
className: "mt-2 text-sm text-gray-600",
|
|
@@ -1633,7 +1653,7 @@ var st = {
|
|
|
1633
1653
|
if (e.sections?.length) {
|
|
1634
1654
|
let t = [];
|
|
1635
1655
|
return e.sections.forEach((e, n) => {
|
|
1636
|
-
let r = e.name || String(n), i =
|
|
1656
|
+
let r = e.name || String(n), i = se[r] ?? e.collapsed ?? !1;
|
|
1637
1657
|
t.push({
|
|
1638
1658
|
name: `__section_${r}`,
|
|
1639
1659
|
label: e.label || "",
|
|
@@ -1641,29 +1661,29 @@ var st = {
|
|
|
1641
1661
|
colSpan: 4,
|
|
1642
1662
|
collapsible: e.collapsible,
|
|
1643
1663
|
collapsed: i,
|
|
1644
|
-
onToggle: e.collapsible ? () =>
|
|
1664
|
+
onToggle: e.collapsible ? () => ce((e) => ({
|
|
1645
1665
|
...e,
|
|
1646
1666
|
[r]: !i
|
|
1647
1667
|
})) : void 0
|
|
1648
1668
|
});
|
|
1649
|
-
let a =
|
|
1669
|
+
let a = le(e);
|
|
1650
1670
|
i ? t.push(...a.map((e) => ({
|
|
1651
1671
|
...e,
|
|
1652
1672
|
hidden: !0
|
|
1653
1673
|
}))) : t.push(...a);
|
|
1654
1674
|
}), /* @__PURE__ */ X(l, { schema: {
|
|
1655
|
-
...
|
|
1675
|
+
...ge,
|
|
1656
1676
|
fields: t
|
|
1657
1677
|
} });
|
|
1658
1678
|
}
|
|
1659
|
-
let t =
|
|
1679
|
+
let t = ft(v, h, e.columns, e.mode), n = gt[t.columns || 1];
|
|
1660
1680
|
return /* @__PURE__ */ X(l, { schema: {
|
|
1661
|
-
...
|
|
1681
|
+
...ge,
|
|
1662
1682
|
fields: t.fields,
|
|
1663
1683
|
columns: t.columns,
|
|
1664
1684
|
...n ? { fieldContainerClass: n } : {}
|
|
1665
1685
|
} });
|
|
1666
|
-
},
|
|
1686
|
+
}, ve = e.subforms, ye = ve?.length && e.mode !== "view" ? /* @__PURE__ */ X($e, {
|
|
1667
1687
|
schema: {
|
|
1668
1688
|
type: "object-master-detail-form",
|
|
1669
1689
|
objectName: e.objectName,
|
|
@@ -1672,7 +1692,7 @@ var st = {
|
|
|
1672
1692
|
fields: e.fields,
|
|
1673
1693
|
sections: e.sections,
|
|
1674
1694
|
submitText: e.submitText,
|
|
1675
|
-
details:
|
|
1695
|
+
details: ve,
|
|
1676
1696
|
onSuccess: async (t) => {
|
|
1677
1697
|
await e.onSuccess?.(t), e.onOpenChange?.(!1);
|
|
1678
1698
|
},
|
|
@@ -1680,8 +1700,8 @@ var st = {
|
|
|
1680
1700
|
onCancel: () => e.onOpenChange?.(!1)
|
|
1681
1701
|
},
|
|
1682
1702
|
dataSource: n
|
|
1683
|
-
}) :
|
|
1684
|
-
return
|
|
1703
|
+
}) : _e();
|
|
1704
|
+
return m ? /* @__PURE__ */ Z("div", {
|
|
1685
1705
|
className: "@container rounded-md border bg-card p-4",
|
|
1686
1706
|
children: [(e.title || e.description) && /* @__PURE__ */ Z("div", {
|
|
1687
1707
|
className: "mb-3 space-y-0.5",
|
|
@@ -1692,44 +1712,92 @@ var st = {
|
|
|
1692
1712
|
className: "text-xs text-muted-foreground",
|
|
1693
1713
|
children: e.description
|
|
1694
1714
|
})]
|
|
1695
|
-
}),
|
|
1696
|
-
}) : /* @__PURE__ */ X(
|
|
1697
|
-
open:
|
|
1698
|
-
onOpenChange:
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1715
|
+
}), ye]
|
|
1716
|
+
}) : /* @__PURE__ */ X(ee, {
|
|
1717
|
+
open: ie,
|
|
1718
|
+
onOpenChange: (t) => {
|
|
1719
|
+
if (t) {
|
|
1720
|
+
e.onOpenChange?.(!0);
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
ue(!1);
|
|
1724
|
+
},
|
|
1725
|
+
children: /* @__PURE__ */ Z(te, {
|
|
1726
|
+
side: ae,
|
|
1727
|
+
className: G("overflow-y-auto", c, e.className),
|
|
1728
|
+
style: J,
|
|
1729
|
+
children: [
|
|
1730
|
+
(e.title || e.description) && /* @__PURE__ */ Z(U, { children: [e.title && /* @__PURE__ */ X(ne, { children: e.title }), e.description ? /* @__PURE__ */ X(H, { children: e.description }) : /* @__PURE__ */ X(H, {
|
|
1731
|
+
className: "sr-only",
|
|
1732
|
+
children: "Complete the form fields, then submit or cancel."
|
|
1733
|
+
})] }),
|
|
1734
|
+
/* @__PURE__ */ X("div", {
|
|
1735
|
+
className: "@container py-4",
|
|
1736
|
+
children: ye
|
|
1737
|
+
}),
|
|
1738
|
+
!P && !M && !(ve?.length && e.mode !== "view") && (me || Y) && /* @__PURE__ */ X("div", {
|
|
1739
|
+
className: "shrink-0 border-t px-4 py-3 bg-background",
|
|
1740
|
+
"data-testid": "drawer-form-footer",
|
|
1741
|
+
children: /* @__PURE__ */ Z("div", {
|
|
1742
|
+
className: "flex flex-col sm:flex-row gap-2 sm:justify-end",
|
|
1743
|
+
children: [Y && /* @__PURE__ */ X(O, {
|
|
1744
|
+
type: "button",
|
|
1745
|
+
variant: "outline",
|
|
1746
|
+
onClick: de,
|
|
1747
|
+
disabled: B,
|
|
1748
|
+
className: "w-full sm:w-auto",
|
|
1749
|
+
children: he
|
|
1750
|
+
}), me && /* @__PURE__ */ Z(O, {
|
|
1751
|
+
type: "submit",
|
|
1752
|
+
form: oe,
|
|
1753
|
+
disabled: B,
|
|
1754
|
+
className: "w-full sm:w-auto",
|
|
1755
|
+
children: [B && /* @__PURE__ */ X(fe, { className: "mr-2 h-4 w-4 animate-spin" }), Q]
|
|
1756
|
+
})]
|
|
1757
|
+
})
|
|
1758
|
+
}),
|
|
1759
|
+
/* @__PURE__ */ X(b, {
|
|
1760
|
+
open: R,
|
|
1761
|
+
onOpenChange: z,
|
|
1762
|
+
children: /* @__PURE__ */ Z(C, { children: [/* @__PURE__ */ Z(E, { children: [/* @__PURE__ */ X(D, { children: f("form.discardTitle") }), /* @__PURE__ */ X(w, { children: f("form.discardMessage") })] }), /* @__PURE__ */ Z(T, { children: [/* @__PURE__ */ X(S, {
|
|
1763
|
+
onClick: () => {
|
|
1764
|
+
W.current = !1;
|
|
1765
|
+
},
|
|
1766
|
+
children: f("form.keepEditing")
|
|
1767
|
+
}), /* @__PURE__ */ X(x, {
|
|
1768
|
+
onClick: q,
|
|
1769
|
+
children: f("form.discard")
|
|
1770
|
+
})] })] })
|
|
1771
|
+
})
|
|
1772
|
+
]
|
|
1710
1773
|
})
|
|
1711
1774
|
});
|
|
1712
|
-
},
|
|
1775
|
+
}, yt = Q({
|
|
1776
|
+
"form.discardTitle": "Discard changes?",
|
|
1777
|
+
"form.discardMessage": "You have unsaved changes. If you close this form now, your edits will be lost.",
|
|
1778
|
+
"form.keepEditing": "Keep editing",
|
|
1779
|
+
"form.discard": "Discard"
|
|
1780
|
+
}, "form.discardTitle"), bt = {
|
|
1713
1781
|
sm: "sm:max-w-sm",
|
|
1714
1782
|
default: "sm:max-w-lg",
|
|
1715
1783
|
lg: "sm:max-w-2xl",
|
|
1716
1784
|
xl: "sm:max-w-5xl",
|
|
1717
1785
|
full: "sm:max-w-[95vw] sm:w-full"
|
|
1718
|
-
},
|
|
1786
|
+
}, xt = {
|
|
1719
1787
|
1: void 0,
|
|
1720
1788
|
2: "grid gap-4 grid-cols-1 @md:grid-cols-2",
|
|
1721
1789
|
3: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",
|
|
1722
1790
|
4: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"
|
|
1723
|
-
},
|
|
1724
|
-
let { fieldLabel:
|
|
1725
|
-
if (!
|
|
1791
|
+
}, St = ({ schema: e, dataSource: n, className: c }) => {
|
|
1792
|
+
let { fieldLabel: u } = p(), { t: f } = yt(), m = d(), h = le(), _ = t((t) => {
|
|
1793
|
+
if (!h?.isLoaded) return t;
|
|
1726
1794
|
let n = [];
|
|
1727
1795
|
for (let r of t) {
|
|
1728
1796
|
if (!r?.name) {
|
|
1729
1797
|
n.push(r);
|
|
1730
1798
|
continue;
|
|
1731
1799
|
}
|
|
1732
|
-
|
|
1800
|
+
h.checkField(e.objectName, r.name, "read") && (!h.checkField(e.objectName, r.name, "write") && e.mode !== "view" ? n.push({
|
|
1733
1801
|
...r,
|
|
1734
1802
|
readOnly: !0,
|
|
1735
1803
|
disabled: !0
|
|
@@ -1737,61 +1805,61 @@ var st = {
|
|
|
1737
1805
|
}
|
|
1738
1806
|
return n;
|
|
1739
1807
|
}, [
|
|
1740
|
-
|
|
1808
|
+
h,
|
|
1741
1809
|
e.objectName,
|
|
1742
1810
|
e.mode
|
|
1743
|
-
]), [
|
|
1811
|
+
]), [v, k] = s(null), [A, j] = s([]), [M, N] = s({}), [z, B] = s(!0), [V, ee] = s(null), [te, H] = s(!1), [U, ne] = s(!1), [se, ce] = s(!1), K = o(!1), q = e.confirmOnDiscard !== !1, ue = e.open !== !1, de = i(), J = a(() => e.sections?.length || e.customFields?.length ? null : ft(A, v, e.columns, e.mode), [
|
|
1812
|
+
A,
|
|
1744
1813
|
v,
|
|
1745
|
-
h,
|
|
1746
1814
|
e.columns,
|
|
1747
1815
|
e.mode,
|
|
1748
1816
|
e.sections,
|
|
1749
1817
|
e.customFields
|
|
1750
|
-
]),
|
|
1818
|
+
]), pe = bt[a(() => {
|
|
1751
1819
|
if (e.modalSize) return e.modalSize;
|
|
1752
|
-
if (
|
|
1820
|
+
if (J?.columns && J.columns > 1) return dt(J.columns);
|
|
1753
1821
|
if (e.sections?.length) {
|
|
1754
1822
|
let t = Math.max(...e.sections.map((e) => Number(e.columns) || 1));
|
|
1755
|
-
if (t > 1) return
|
|
1823
|
+
if (t > 1) return dt(t);
|
|
1756
1824
|
}
|
|
1757
1825
|
return "default";
|
|
1758
1826
|
}, [
|
|
1759
1827
|
e.modalSize,
|
|
1760
|
-
|
|
1828
|
+
J,
|
|
1761
1829
|
e.sections
|
|
1762
|
-
])] ||
|
|
1830
|
+
])] || bt.default;
|
|
1763
1831
|
r(() => {
|
|
1764
1832
|
(async () => {
|
|
1765
1833
|
if (!n) {
|
|
1766
|
-
|
|
1834
|
+
B(!1);
|
|
1767
1835
|
return;
|
|
1768
1836
|
}
|
|
1769
1837
|
try {
|
|
1770
|
-
|
|
1838
|
+
k(await n.getObjectSchema(e.objectName));
|
|
1771
1839
|
} catch (e) {
|
|
1772
|
-
|
|
1840
|
+
ee(e), B(!1);
|
|
1773
1841
|
}
|
|
1774
1842
|
})();
|
|
1775
1843
|
}, [e.objectName, n]), r(() => {
|
|
1776
|
-
(
|
|
1844
|
+
(v || !n) && (async () => {
|
|
1777
1845
|
if (e.mode === "create" || !e.recordId) {
|
|
1778
|
-
|
|
1846
|
+
N(e.initialData || e.initialValues || {}), B(!1);
|
|
1779
1847
|
return;
|
|
1780
1848
|
}
|
|
1781
1849
|
if (!n) {
|
|
1782
|
-
|
|
1850
|
+
N(e.initialData || e.initialValues || {}), B(!1);
|
|
1783
1851
|
return;
|
|
1784
1852
|
}
|
|
1785
1853
|
try {
|
|
1786
|
-
|
|
1854
|
+
N(await n.findOne(e.objectName, e.recordId) || {});
|
|
1787
1855
|
} catch (e) {
|
|
1788
|
-
|
|
1856
|
+
ee(e);
|
|
1789
1857
|
} finally {
|
|
1790
|
-
|
|
1858
|
+
B(!1);
|
|
1791
1859
|
}
|
|
1792
1860
|
})();
|
|
1793
1861
|
}, [
|
|
1794
|
-
|
|
1862
|
+
v,
|
|
1795
1863
|
e.mode,
|
|
1796
1864
|
e.recordId,
|
|
1797
1865
|
e.initialData,
|
|
@@ -1799,38 +1867,38 @@ var st = {
|
|
|
1799
1867
|
n,
|
|
1800
1868
|
e.objectName
|
|
1801
1869
|
]);
|
|
1802
|
-
let
|
|
1803
|
-
objectSchema:
|
|
1870
|
+
let me = t((t) => xe(t, {
|
|
1871
|
+
objectSchema: v,
|
|
1804
1872
|
objectName: e.objectName,
|
|
1805
1873
|
readOnly: e.readOnly,
|
|
1806
1874
|
mode: e.mode,
|
|
1807
|
-
fieldLabel:
|
|
1875
|
+
fieldLabel: u
|
|
1808
1876
|
}), [
|
|
1809
|
-
|
|
1877
|
+
v,
|
|
1810
1878
|
e.readOnly,
|
|
1811
1879
|
e.mode,
|
|
1812
1880
|
e.objectName,
|
|
1813
|
-
|
|
1881
|
+
u
|
|
1814
1882
|
]);
|
|
1815
1883
|
r(() => {
|
|
1816
|
-
if (!
|
|
1884
|
+
if (!v && n) return;
|
|
1817
1885
|
if (e.customFields?.length) {
|
|
1818
|
-
|
|
1886
|
+
j(e.customFields), B(!1);
|
|
1819
1887
|
return;
|
|
1820
1888
|
}
|
|
1821
1889
|
if (e.sections?.length) {
|
|
1822
|
-
|
|
1890
|
+
B(!1);
|
|
1823
1891
|
return;
|
|
1824
1892
|
}
|
|
1825
|
-
if (!
|
|
1826
|
-
let t = e.fields || Object.keys(
|
|
1893
|
+
if (!v) return;
|
|
1894
|
+
let t = e.fields || Object.keys(v.fields || {}), r = [];
|
|
1827
1895
|
for (let n of t) {
|
|
1828
1896
|
let t = typeof n == "string" ? n : n.name;
|
|
1829
1897
|
if (!t) continue;
|
|
1830
|
-
let i =
|
|
1898
|
+
let i = v.fields?.[t];
|
|
1831
1899
|
i && r.push({
|
|
1832
1900
|
name: t,
|
|
1833
|
-
label:
|
|
1901
|
+
label: u(e.objectName, t, i.label || t),
|
|
1834
1902
|
type: y(i.type),
|
|
1835
1903
|
required: i.required || !1,
|
|
1836
1904
|
disabled: e.readOnly || e.mode === "view" || i.readonly,
|
|
@@ -1842,9 +1910,9 @@ var st = {
|
|
|
1842
1910
|
multiple: i.multiple
|
|
1843
1911
|
});
|
|
1844
1912
|
}
|
|
1845
|
-
|
|
1913
|
+
j(r), B(!1);
|
|
1846
1914
|
}, [
|
|
1847
|
-
|
|
1915
|
+
v,
|
|
1848
1916
|
e.fields,
|
|
1849
1917
|
e.customFields,
|
|
1850
1918
|
e.sections,
|
|
@@ -1852,54 +1920,63 @@ var st = {
|
|
|
1852
1920
|
e.mode,
|
|
1853
1921
|
n
|
|
1854
1922
|
]);
|
|
1855
|
-
let
|
|
1856
|
-
|
|
1923
|
+
let Y = t(async (t) => {
|
|
1924
|
+
H(!0);
|
|
1857
1925
|
try {
|
|
1858
1926
|
if (!n) return e.onSuccess && await e.onSuccess(t), e.onOpenChange?.(!1), t;
|
|
1859
|
-
let r, i =
|
|
1860
|
-
if (
|
|
1927
|
+
let r, i = ht(t, v);
|
|
1928
|
+
if (h?.isLoaded) {
|
|
1861
1929
|
let t = {};
|
|
1862
|
-
for (let n of Object.keys(i))
|
|
1930
|
+
for (let n of Object.keys(i)) h.checkField(e.objectName, n, "write") && (t[n] = i[n]);
|
|
1863
1931
|
i = t;
|
|
1864
1932
|
}
|
|
1865
1933
|
return e.mode === "create" ? r = await n.create(e.objectName, i) : e.mode === "edit" && e.recordId && (r = await n.update(e.objectName, e.recordId, i)), e.onSuccess && await e.onSuccess(r), e.onOpenChange?.(!1), r;
|
|
1866
1934
|
} catch (t) {
|
|
1867
1935
|
throw e.onError && e.onError(t), t;
|
|
1868
1936
|
} finally {
|
|
1869
|
-
|
|
1937
|
+
H(!1);
|
|
1870
1938
|
}
|
|
1871
1939
|
}, [
|
|
1872
1940
|
e,
|
|
1873
1941
|
n,
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
]),
|
|
1877
|
-
|
|
1878
|
-
}, [e]),
|
|
1942
|
+
v,
|
|
1943
|
+
h
|
|
1944
|
+
]), Q = t(() => {
|
|
1945
|
+
ce(!1), K.current && (K.current = !1, e.onCancel?.()), e.onOpenChange?.(!1);
|
|
1946
|
+
}, [e]), he = t((e) => {
|
|
1947
|
+
K.current = e, q && U ? ce(!0) : Q();
|
|
1948
|
+
}, [
|
|
1949
|
+
q,
|
|
1950
|
+
U,
|
|
1951
|
+
Q
|
|
1952
|
+
]), ge = t(() => {
|
|
1953
|
+
K.current = !0, Q();
|
|
1954
|
+
}, [Q]), ve = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical", ye = e.showSubmit !== !1 && e.mode !== "view", be = e.showCancel !== !1, Se = e.submitText || (e.mode === "create" ? "Create" : "Update"), Ce = e.cancelText || "Cancel", we = {
|
|
1879
1955
|
type: "form",
|
|
1880
1956
|
objectName: e.objectName,
|
|
1881
|
-
layout:
|
|
1882
|
-
defaultValues:
|
|
1883
|
-
submitLabel:
|
|
1884
|
-
cancelLabel:
|
|
1885
|
-
showSubmit:
|
|
1886
|
-
showCancel:
|
|
1887
|
-
onSubmit:
|
|
1888
|
-
onCancel:
|
|
1957
|
+
layout: ve,
|
|
1958
|
+
defaultValues: M,
|
|
1959
|
+
submitLabel: Se,
|
|
1960
|
+
cancelLabel: Ce,
|
|
1961
|
+
showSubmit: ye,
|
|
1962
|
+
showCancel: be,
|
|
1963
|
+
onSubmit: Y,
|
|
1964
|
+
onCancel: ge,
|
|
1965
|
+
onDirtyChange: ne,
|
|
1889
1966
|
showActions: !1,
|
|
1890
|
-
id:
|
|
1891
|
-
},
|
|
1892
|
-
if (
|
|
1967
|
+
id: de
|
|
1968
|
+
}, $ = () => {
|
|
1969
|
+
if (V) return /* @__PURE__ */ Z("div", {
|
|
1893
1970
|
className: "p-4 border border-red-300 bg-red-50 rounded-md",
|
|
1894
1971
|
children: [/* @__PURE__ */ X("h3", {
|
|
1895
1972
|
className: "text-red-800 font-semibold",
|
|
1896
1973
|
children: "Error loading form"
|
|
1897
1974
|
}), /* @__PURE__ */ X("p", {
|
|
1898
1975
|
className: "text-red-600 text-sm mt-1",
|
|
1899
|
-
children:
|
|
1976
|
+
children: V.message
|
|
1900
1977
|
})]
|
|
1901
1978
|
});
|
|
1902
|
-
if (
|
|
1979
|
+
if (z) return /* @__PURE__ */ X("div", {
|
|
1903
1980
|
className: "space-y-4",
|
|
1904
1981
|
"data-testid": "modal-form-skeleton",
|
|
1905
1982
|
children: [
|
|
@@ -1908,52 +1985,52 @@ var st = {
|
|
|
1908
1985
|
3
|
|
1909
1986
|
].map((e) => /* @__PURE__ */ Z("div", {
|
|
1910
1987
|
className: "space-y-2",
|
|
1911
|
-
children: [/* @__PURE__ */ X(
|
|
1988
|
+
children: [/* @__PURE__ */ X(W, { className: "h-4 w-24" }), /* @__PURE__ */ X(W, { className: "h-10 w-full" })]
|
|
1912
1989
|
}, e))
|
|
1913
1990
|
});
|
|
1914
1991
|
if (e.sections?.length) {
|
|
1915
1992
|
let t = e.sections, n = (e, t) => e.name || e.label || String(t), r = (e) => /* @__PURE__ */ X(l, { schema: {
|
|
1916
|
-
...
|
|
1917
|
-
fields:
|
|
1993
|
+
...we,
|
|
1994
|
+
fields: _(me(e))
|
|
1918
1995
|
} });
|
|
1919
|
-
return e.contentLayout === "tabbed" && t.length > 1 ? /* @__PURE__ */ Z(
|
|
1996
|
+
return e.contentLayout === "tabbed" && t.length > 1 ? /* @__PURE__ */ Z(re, {
|
|
1920
1997
|
defaultValue: n(t[0], 0),
|
|
1921
1998
|
className: "w-full",
|
|
1922
|
-
children: [/* @__PURE__ */ X(
|
|
1999
|
+
children: [/* @__PURE__ */ X(ae, {
|
|
1923
2000
|
className: "mb-4",
|
|
1924
|
-
children: t.map((e, t) => /* @__PURE__ */ X(
|
|
2001
|
+
children: t.map((e, t) => /* @__PURE__ */ X(oe, {
|
|
1925
2002
|
value: n(e, t),
|
|
1926
2003
|
children: e.label || `Section ${t + 1}`
|
|
1927
2004
|
}, n(e, t)))
|
|
1928
|
-
}), t.map((e, t) => /* @__PURE__ */ X(
|
|
2005
|
+
}), t.map((e, t) => /* @__PURE__ */ X(ie, {
|
|
1929
2006
|
value: n(e, t),
|
|
1930
|
-
children: /* @__PURE__ */ X(
|
|
2007
|
+
children: /* @__PURE__ */ X(_e, {
|
|
1931
2008
|
description: e.description,
|
|
1932
2009
|
columns: e.columns || 1,
|
|
1933
|
-
gridClassName:
|
|
2010
|
+
gridClassName: xt[e.columns || 1],
|
|
1934
2011
|
children: r(e)
|
|
1935
2012
|
})
|
|
1936
2013
|
}, n(e, t)))]
|
|
1937
2014
|
}) : /* @__PURE__ */ X("div", {
|
|
1938
2015
|
className: "space-y-6",
|
|
1939
|
-
children: t.map((e, t) => /* @__PURE__ */ X(
|
|
2016
|
+
children: t.map((e, t) => /* @__PURE__ */ X(_e, {
|
|
1940
2017
|
label: e.label,
|
|
1941
2018
|
description: e.description,
|
|
1942
2019
|
columns: e.columns || 1,
|
|
1943
|
-
gridClassName:
|
|
2020
|
+
gridClassName: xt[e.columns || 1],
|
|
1944
2021
|
children: r(e)
|
|
1945
2022
|
}, n(e, t)))
|
|
1946
2023
|
});
|
|
1947
2024
|
}
|
|
1948
|
-
let t =
|
|
2025
|
+
let t = J ?? ft(A, v, e.columns, e.mode), n = xt[t.columns || 1];
|
|
1949
2026
|
return /* @__PURE__ */ X(l, { schema: {
|
|
1950
|
-
...
|
|
1951
|
-
fields:
|
|
2027
|
+
...we,
|
|
2028
|
+
fields: _(t.fields),
|
|
1952
2029
|
columns: t.columns,
|
|
1953
2030
|
...n ? { fieldContainerClass: n } : {}
|
|
1954
2031
|
} });
|
|
1955
|
-
},
|
|
1956
|
-
if (
|
|
2032
|
+
}, Te = e.subforms;
|
|
2033
|
+
if (m) return /* @__PURE__ */ Z("div", {
|
|
1957
2034
|
className: "@container rounded-md border bg-card p-4",
|
|
1958
2035
|
children: [(e.title || e.description) && /* @__PURE__ */ Z("div", {
|
|
1959
2036
|
className: "mb-3 space-y-0.5",
|
|
@@ -1964,22 +2041,22 @@ var st = {
|
|
|
1964
2041
|
className: "text-xs text-muted-foreground",
|
|
1965
2042
|
children: e.description
|
|
1966
2043
|
})]
|
|
1967
|
-
}),
|
|
2044
|
+
}), $()]
|
|
1968
2045
|
});
|
|
1969
|
-
if (
|
|
1970
|
-
open:
|
|
2046
|
+
if (Te?.length && e.mode !== "view") return /* @__PURE__ */ X(P, {
|
|
2047
|
+
open: ue,
|
|
1971
2048
|
onOpenChange: e.onOpenChange,
|
|
1972
|
-
children: /* @__PURE__ */ Z(
|
|
1973
|
-
className:
|
|
1974
|
-
children: [(e.title || e.description) && /* @__PURE__ */ Z(
|
|
2049
|
+
children: /* @__PURE__ */ Z(R, {
|
|
2050
|
+
className: G(pe, "flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0", c, e.className),
|
|
2051
|
+
children: [(e.title || e.description) && /* @__PURE__ */ Z(I, {
|
|
1975
2052
|
className: "shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b",
|
|
1976
|
-
children: [e.title && /* @__PURE__ */ X(
|
|
2053
|
+
children: [e.title && /* @__PURE__ */ X(L, { children: e.title }), e.description ? /* @__PURE__ */ X(F, { children: e.description }) : /* @__PURE__ */ X(F, {
|
|
1977
2054
|
className: "sr-only",
|
|
1978
2055
|
children: "Enter the record and its line items, then save."
|
|
1979
2056
|
})]
|
|
1980
2057
|
}), /* @__PURE__ */ X("div", {
|
|
1981
2058
|
className: "@container flex-1 overflow-y-auto px-4 sm:px-6 py-4",
|
|
1982
|
-
children: /* @__PURE__ */ X(
|
|
2059
|
+
children: /* @__PURE__ */ X($e, {
|
|
1983
2060
|
schema: {
|
|
1984
2061
|
type: "object-master-detail-form",
|
|
1985
2062
|
objectName: e.objectName,
|
|
@@ -1987,8 +2064,8 @@ var st = {
|
|
|
1987
2064
|
recordId: e.recordId,
|
|
1988
2065
|
fields: e.fields,
|
|
1989
2066
|
sections: e.sections,
|
|
1990
|
-
submitText:
|
|
1991
|
-
details:
|
|
2067
|
+
submitText: Se,
|
|
2068
|
+
details: Te,
|
|
1992
2069
|
onSuccess: async (t) => {
|
|
1993
2070
|
await e.onSuccess?.(t), e.onOpenChange?.(!1);
|
|
1994
2071
|
},
|
|
@@ -2000,44 +2077,63 @@ var st = {
|
|
|
2000
2077
|
})]
|
|
2001
2078
|
})
|
|
2002
2079
|
});
|
|
2003
|
-
let
|
|
2004
|
-
return /* @__PURE__ */ X(
|
|
2005
|
-
open:
|
|
2006
|
-
onOpenChange:
|
|
2007
|
-
|
|
2008
|
-
|
|
2080
|
+
let Ee = !z && !V && (ye || be);
|
|
2081
|
+
return /* @__PURE__ */ X(P, {
|
|
2082
|
+
open: ue,
|
|
2083
|
+
onOpenChange: (t) => {
|
|
2084
|
+
if (t) {
|
|
2085
|
+
e.onOpenChange?.(!0);
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
he(!1);
|
|
2089
|
+
},
|
|
2090
|
+
children: /* @__PURE__ */ Z(R, {
|
|
2091
|
+
className: G(pe, "flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0", c, e.className),
|
|
2009
2092
|
children: [
|
|
2010
|
-
(e.title || e.description) && /* @__PURE__ */ Z(
|
|
2093
|
+
(e.title || e.description) && /* @__PURE__ */ Z(I, {
|
|
2011
2094
|
className: "shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b",
|
|
2012
|
-
children: [e.title && /* @__PURE__ */ X(
|
|
2095
|
+
children: [e.title && /* @__PURE__ */ X(L, { children: e.title }), e.description ? /* @__PURE__ */ X(F, { children: e.description }) : /* @__PURE__ */ X(F, {
|
|
2013
2096
|
className: "sr-only",
|
|
2014
2097
|
children: "Complete the form fields, then submit or cancel."
|
|
2015
2098
|
})]
|
|
2016
2099
|
}),
|
|
2017
2100
|
/* @__PURE__ */ X("div", {
|
|
2018
2101
|
className: "@container flex-1 overflow-y-auto px-4 sm:px-6 py-4",
|
|
2019
|
-
children:
|
|
2102
|
+
children: $()
|
|
2020
2103
|
}),
|
|
2021
|
-
|
|
2104
|
+
Ee && /* @__PURE__ */ X("div", {
|
|
2022
2105
|
className: "shrink-0 border-t px-4 sm:px-6 py-3 bg-background",
|
|
2023
2106
|
"data-testid": "modal-form-footer",
|
|
2024
2107
|
children: /* @__PURE__ */ Z("div", {
|
|
2025
2108
|
className: "flex flex-col sm:flex-row gap-2 sm:justify-end",
|
|
2026
|
-
children: [
|
|
2109
|
+
children: [be && /* @__PURE__ */ X(O, {
|
|
2027
2110
|
type: "button",
|
|
2028
2111
|
variant: "outline",
|
|
2029
|
-
onClick:
|
|
2030
|
-
disabled:
|
|
2112
|
+
onClick: ge,
|
|
2113
|
+
disabled: te,
|
|
2031
2114
|
className: "w-full sm:w-auto",
|
|
2032
|
-
children:
|
|
2033
|
-
}),
|
|
2115
|
+
children: Ce
|
|
2116
|
+
}), ye && /* @__PURE__ */ Z(O, {
|
|
2034
2117
|
type: "submit",
|
|
2035
|
-
form:
|
|
2036
|
-
disabled:
|
|
2118
|
+
form: de,
|
|
2119
|
+
disabled: te,
|
|
2037
2120
|
className: "w-full sm:w-auto",
|
|
2038
|
-
children: [
|
|
2121
|
+
children: [te && /* @__PURE__ */ X(fe, { className: "mr-2 h-4 w-4 animate-spin" }), Se]
|
|
2039
2122
|
})]
|
|
2040
2123
|
})
|
|
2124
|
+
}),
|
|
2125
|
+
/* @__PURE__ */ X(b, {
|
|
2126
|
+
open: se,
|
|
2127
|
+
onOpenChange: ce,
|
|
2128
|
+
children: /* @__PURE__ */ Z(C, { children: [/* @__PURE__ */ Z(E, { children: [/* @__PURE__ */ X(D, { children: f("form.discardTitle") }), /* @__PURE__ */ X(w, { children: f("form.discardMessage") })] }), /* @__PURE__ */ Z(T, { children: [/* @__PURE__ */ X(S, {
|
|
2129
|
+
onClick: () => {
|
|
2130
|
+
K.current = !1;
|
|
2131
|
+
},
|
|
2132
|
+
children: f("form.keepEditing")
|
|
2133
|
+
}), /* @__PURE__ */ X(x, {
|
|
2134
|
+
onClick: Q,
|
|
2135
|
+
children: f("form.discard")
|
|
2136
|
+
})] })] })
|
|
2041
2137
|
})
|
|
2042
2138
|
]
|
|
2043
2139
|
})
|
|
@@ -2045,7 +2141,7 @@ var st = {
|
|
|
2045
2141
|
};
|
|
2046
2142
|
//#endregion
|
|
2047
2143
|
//#region src/fieldGroups.ts
|
|
2048
|
-
function
|
|
2144
|
+
function Ct(e) {
|
|
2049
2145
|
return Array.isArray(e) ? e.filter((e) => !!e && typeof e == "object").map((e) => ({
|
|
2050
2146
|
key: typeof e.key == "string" ? e.key : "",
|
|
2051
2147
|
label: typeof e.label == "string" ? e.label : void 0,
|
|
@@ -2053,8 +2149,8 @@ function ft(e) {
|
|
|
2053
2149
|
collapsed: typeof e.collapsed == "boolean" ? e.collapsed : void 0
|
|
2054
2150
|
})).filter((e) => e.key) : [];
|
|
2055
2151
|
}
|
|
2056
|
-
function
|
|
2057
|
-
let n =
|
|
2152
|
+
function wt(e, t) {
|
|
2153
|
+
let n = Ct(t);
|
|
2058
2154
|
if (n.length === 0) return null;
|
|
2059
2155
|
let r = new Set(n.map((e) => e.key)), i = (e) => {
|
|
2060
2156
|
let t = e.group;
|
|
@@ -2083,8 +2179,8 @@ function pt(e, t) {
|
|
|
2083
2179
|
}
|
|
2084
2180
|
//#endregion
|
|
2085
2181
|
//#region src/ObjectForm.tsx
|
|
2086
|
-
var
|
|
2087
|
-
let n =
|
|
2182
|
+
var Tt = ({ schema: e, dataSource: t }) => {
|
|
2183
|
+
let n = le(), r = a(() => {
|
|
2088
2184
|
if (!n?.isLoaded) return e;
|
|
2089
2185
|
let t = (t) => t?.name ? n.checkField(e.objectName, t.name, "read") ? !n.checkField(e.objectName, t.name, "write") && e.mode !== "view" ? {
|
|
2090
2186
|
...t,
|
|
@@ -2100,7 +2196,7 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2100
2196
|
}))
|
|
2101
2197
|
};
|
|
2102
2198
|
}, [e, n]), { sectionLabel: i } = p(), o = (e) => e?.name ? i(r.objectName, e.name, e.label || e.name) : e?.label;
|
|
2103
|
-
if (r.subforms?.length && r.mode !== "view" && r.formType !== "drawer" && r.formType !== "modal") return /* @__PURE__ */ X(
|
|
2199
|
+
if (r.subforms?.length && r.mode !== "view" && r.formType !== "drawer" && r.formType !== "modal") return /* @__PURE__ */ X($e, {
|
|
2104
2200
|
schema: {
|
|
2105
2201
|
type: "object-master-detail-form",
|
|
2106
2202
|
objectName: r.objectName,
|
|
@@ -2122,7 +2218,7 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2122
2218
|
},
|
|
2123
2219
|
dataSource: t
|
|
2124
2220
|
});
|
|
2125
|
-
if (r.formType === "tabbed" && r.sections?.length) return /* @__PURE__ */ X(
|
|
2221
|
+
if (r.formType === "tabbed" && r.sections?.length) return /* @__PURE__ */ X(Se, {
|
|
2126
2222
|
schema: {
|
|
2127
2223
|
...r,
|
|
2128
2224
|
formType: "tabbed",
|
|
@@ -2139,7 +2235,7 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2139
2235
|
dataSource: t,
|
|
2140
2236
|
className: r.className
|
|
2141
2237
|
});
|
|
2142
|
-
if (r.formType === "wizard" && r.sections?.length) return /* @__PURE__ */ X(
|
|
2238
|
+
if (r.formType === "wizard" && r.sections?.length) return /* @__PURE__ */ X(Ce, {
|
|
2143
2239
|
schema: {
|
|
2144
2240
|
...r,
|
|
2145
2241
|
formType: "wizard",
|
|
@@ -2159,7 +2255,7 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2159
2255
|
dataSource: t,
|
|
2160
2256
|
className: r.className
|
|
2161
2257
|
});
|
|
2162
|
-
if (r.formType === "split" && r.sections?.length) return /* @__PURE__ */ X(
|
|
2258
|
+
if (r.formType === "split" && r.sections?.length) return /* @__PURE__ */ X(we, {
|
|
2163
2259
|
schema: {
|
|
2164
2260
|
...r,
|
|
2165
2261
|
formType: "split",
|
|
@@ -2179,7 +2275,7 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2179
2275
|
});
|
|
2180
2276
|
if (r.formType === "drawer") {
|
|
2181
2277
|
let { layout: e, ...n } = r, i = r.layout === "vertical" || r.layout === "horizontal" ? r.layout : void 0;
|
|
2182
|
-
return /* @__PURE__ */ X(
|
|
2278
|
+
return /* @__PURE__ */ X(vt, {
|
|
2183
2279
|
schema: {
|
|
2184
2280
|
...n,
|
|
2185
2281
|
layout: i,
|
|
@@ -2204,7 +2300,7 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2204
2300
|
}
|
|
2205
2301
|
if (r.formType === "modal") {
|
|
2206
2302
|
let { layout: e, ...n } = r, i = r.layout === "vertical" || r.layout === "horizontal" ? r.layout : void 0;
|
|
2207
|
-
return /* @__PURE__ */ X(
|
|
2303
|
+
return /* @__PURE__ */ X(St, {
|
|
2208
2304
|
schema: {
|
|
2209
2305
|
...n,
|
|
2210
2306
|
layout: i,
|
|
@@ -2225,12 +2321,12 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2225
2321
|
className: r.className
|
|
2226
2322
|
});
|
|
2227
2323
|
}
|
|
2228
|
-
return /* @__PURE__ */ X(
|
|
2324
|
+
return /* @__PURE__ */ X(Et, {
|
|
2229
2325
|
schema: r,
|
|
2230
2326
|
dataSource: t
|
|
2231
2327
|
});
|
|
2232
|
-
},
|
|
2233
|
-
let { fieldLabel: a, sectionLabel: o } = p(), c =
|
|
2328
|
+
}, Et = ({ schema: n, dataSource: i }) => {
|
|
2329
|
+
let { fieldLabel: a, sectionLabel: o } = p(), c = ce(), u = le(), d = t((e) => {
|
|
2234
2330
|
if (!u?.isLoaded) return e;
|
|
2235
2331
|
let t = [];
|
|
2236
2332
|
for (let r of e) u.checkField(n.objectName, r.name, "read") && (!u.checkField(n.objectName, r.name, "write") && n.mode !== "view" ? t.push({
|
|
@@ -2373,9 +2469,9 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2373
2469
|
else throw Error("Invalid form mode or missing record ID");
|
|
2374
2470
|
if (n.onSuccess) await n.onSuccess(e);
|
|
2375
2471
|
else if (!n.submitHandler) {
|
|
2376
|
-
let t =
|
|
2472
|
+
let t = ge(n.navigateOnSuccess, e);
|
|
2377
2473
|
if (t) return window.location.assign(t), e;
|
|
2378
|
-
|
|
2474
|
+
se.success(n.successMessage || (n.mode === "create" ? "Created" : "Saved"));
|
|
2379
2475
|
}
|
|
2380
2476
|
return e;
|
|
2381
2477
|
} catch (e) {
|
|
@@ -2398,7 +2494,7 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2398
2494
|
}), e;
|
|
2399
2495
|
}, [f]),
|
|
2400
2496
|
...x
|
|
2401
|
-
}, M = e.useMemo(() => n.sections?.length ? null :
|
|
2497
|
+
}, M = e.useMemo(() => n.sections?.length ? null : wt(h, f?.fieldGroups), [
|
|
2402
2498
|
n.sections,
|
|
2403
2499
|
h,
|
|
2404
2500
|
f
|
|
@@ -2462,24 +2558,24 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2462
2558
|
let L = n.sections?.length, R = d(h), z = L ? {
|
|
2463
2559
|
fields: R,
|
|
2464
2560
|
columns: n.columns
|
|
2465
|
-
} :
|
|
2561
|
+
} : ft(R, f, n.columns, n.mode), B = n.mobile, V = B?.fullscreenLongText ? z.fields.map((e) => {
|
|
2466
2562
|
let t = e.type;
|
|
2467
2563
|
return t === "textarea" || t === "field:textarea" || t === "string-multiline" || t === "field:markdown" || t === "field:html" ? {
|
|
2468
2564
|
...e,
|
|
2469
2565
|
mobile_fullscreen: !0
|
|
2470
2566
|
} : e;
|
|
2471
|
-
}) : z.fields,
|
|
2472
|
-
if (!n.formType && !L && V.length >= 2 && (
|
|
2567
|
+
}) : z.fields, ee = B?.stepper, te = B?.stepperMinFields ?? 8, H = Math.max(1, B?.stepperFieldsPerStep ?? 1);
|
|
2568
|
+
if (!n.formType && !L && V.length >= 2 && (ee === !0 || ee === "auto" && c && V.length >= te)) {
|
|
2473
2569
|
let e = V, t = [];
|
|
2474
|
-
for (let n = 0; n < e.length; n +=
|
|
2475
|
-
let r = e.slice(n, n +
|
|
2570
|
+
for (let n = 0; n < e.length; n += H) {
|
|
2571
|
+
let r = e.slice(n, n + H);
|
|
2476
2572
|
t.push({
|
|
2477
|
-
name: `step-${Math.floor(n /
|
|
2478
|
-
label: r[0]?.label || r[0]?.name || `Step ${Math.floor(n /
|
|
2573
|
+
name: `step-${Math.floor(n / H) + 1}`,
|
|
2574
|
+
label: r[0]?.label || r[0]?.name || `Step ${Math.floor(n / H) + 1}`,
|
|
2479
2575
|
fields: r
|
|
2480
2576
|
});
|
|
2481
2577
|
}
|
|
2482
|
-
return /* @__PURE__ */ X(
|
|
2578
|
+
return /* @__PURE__ */ X(Ce, {
|
|
2483
2579
|
schema: {
|
|
2484
2580
|
...n,
|
|
2485
2581
|
formType: "wizard",
|
|
@@ -2490,7 +2586,7 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2490
2586
|
className: n.className
|
|
2491
2587
|
});
|
|
2492
2588
|
}
|
|
2493
|
-
let
|
|
2589
|
+
let U = {
|
|
2494
2590
|
type: "form",
|
|
2495
2591
|
objectName: n.objectName,
|
|
2496
2592
|
fields: V,
|
|
@@ -2510,9 +2606,9 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2510
2606
|
return /* @__PURE__ */ X("div", {
|
|
2511
2607
|
className: B?.stickyActions ? "w-full pb-20 md:pb-0" : "w-full",
|
|
2512
2608
|
"data-mobile-form": B ? "true" : void 0,
|
|
2513
|
-
children: /* @__PURE__ */ X(l, { schema:
|
|
2609
|
+
children: /* @__PURE__ */ X(l, { schema: U })
|
|
2514
2610
|
});
|
|
2515
|
-
},
|
|
2611
|
+
}, Dt = {
|
|
2516
2612
|
text: 200,
|
|
2517
2613
|
email: 254,
|
|
2518
2614
|
url: 2048,
|
|
@@ -2520,8 +2616,8 @@ var mt = ({ schema: e, dataSource: t }) => {
|
|
|
2520
2616
|
textarea: 5e3,
|
|
2521
2617
|
markdown: 5e3,
|
|
2522
2618
|
html: 5e3
|
|
2523
|
-
},
|
|
2524
|
-
function
|
|
2619
|
+
}, Ot = "_company_website_2", kt = 1500;
|
|
2620
|
+
function At(e, t = []) {
|
|
2525
2621
|
try {
|
|
2526
2622
|
let n = new URL(e, typeof window < "u" ? window.location.href : "http://localhost");
|
|
2527
2623
|
return typeof window < "u" && n.origin === window.location.origin ? !0 : n.protocol !== "https:" && n.protocol !== "http:" ? !1 : t.some((e) => {
|
|
@@ -2536,22 +2632,22 @@ function yt(e, t = []) {
|
|
|
2536
2632
|
return !1;
|
|
2537
2633
|
}
|
|
2538
2634
|
}
|
|
2539
|
-
function
|
|
2635
|
+
function jt(e) {
|
|
2540
2636
|
return e && e.map((e) => {
|
|
2541
|
-
let t =
|
|
2637
|
+
let t = Dt[String(e.type || "").toLowerCase()];
|
|
2542
2638
|
return !t || (e.maxLength ?? e.max_length) ? e : {
|
|
2543
2639
|
...e,
|
|
2544
2640
|
maxLength: t
|
|
2545
2641
|
};
|
|
2546
2642
|
});
|
|
2547
2643
|
}
|
|
2548
|
-
var
|
|
2549
|
-
let [l, u] = s(!1), [d, f] = s(!1), [p, m] = s(null), [h, g] = s(!(e.consent?.required ?? !!e.consent)), [_, v] = s(null), y = o(null),
|
|
2644
|
+
var Mt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
2645
|
+
let [l, u] = s(!1), [d, f] = s(!1), [p, m] = s(null), [h, g] = s(!(e.consent?.required ?? !!e.consent)), [_, v] = s(null), y = o(null), b = o(0);
|
|
2550
2646
|
r(() => {
|
|
2551
|
-
l || (
|
|
2647
|
+
l || (b.current = Date.now());
|
|
2552
2648
|
}, [l]);
|
|
2553
|
-
let
|
|
2554
|
-
if (!n ||
|
|
2649
|
+
let x = e.honeypot === !1 ? null : e.honeypot || Ot, S = e.minFillTime ?? kt, C = a(() => jt(e.customFields), [e.customFields]), w = a(() => {
|
|
2650
|
+
if (!n || C && C.length > 0 || !e.fields || e.fields.length === 0) return;
|
|
2555
2651
|
let t = async (e, t) => t;
|
|
2556
2652
|
return {
|
|
2557
2653
|
...n,
|
|
@@ -2561,9 +2657,9 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2561
2657
|
};
|
|
2562
2658
|
}, [
|
|
2563
2659
|
n,
|
|
2564
|
-
|
|
2660
|
+
C,
|
|
2565
2661
|
e.fields
|
|
2566
|
-
]),
|
|
2662
|
+
]), T = a(() => {
|
|
2567
2663
|
let t = {};
|
|
2568
2664
|
if (i) for (let [e, n] of Object.entries(i)) t[e] = n;
|
|
2569
2665
|
if (typeof window < "u" && e.allowedPrefillFields?.length) {
|
|
@@ -2573,25 +2669,25 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2573
2669
|
});
|
|
2574
2670
|
}
|
|
2575
2671
|
return Object.keys(t).length > 0 ? t : void 0;
|
|
2576
|
-
}, [i, e.allowedPrefillFields]),
|
|
2672
|
+
}, [i, e.allowedPrefillFields]), E = t(async (t) => {
|
|
2577
2673
|
if (e.consent?.required && !h) {
|
|
2578
2674
|
v(e.texts?.consentRequired ?? "Please accept the privacy policy to continue.");
|
|
2579
2675
|
return;
|
|
2580
2676
|
}
|
|
2581
|
-
if (v(null),
|
|
2677
|
+
if (v(null), x && y.current?.value) {
|
|
2582
2678
|
u(!0);
|
|
2583
2679
|
return;
|
|
2584
2680
|
}
|
|
2585
|
-
if (
|
|
2681
|
+
if (S > 0 && Date.now() - b.current < S) {
|
|
2586
2682
|
m(e.texts?.rateLimited ?? "Please take a moment to review your answers before submitting.");
|
|
2587
2683
|
return;
|
|
2588
2684
|
}
|
|
2589
2685
|
let r = { ...t };
|
|
2590
|
-
|
|
2686
|
+
x && delete r[x], e.captchaToken && (r._captcha = e.captchaToken), f(!0), m(null);
|
|
2591
2687
|
try {
|
|
2592
2688
|
n && await n.create(e.objectName, r), u(!0);
|
|
2593
2689
|
let t = e.thankYouPage?.redirectUrl;
|
|
2594
|
-
if (t) if (
|
|
2690
|
+
if (t) if (At(t, e.allowedRedirectHosts)) {
|
|
2595
2691
|
let n = e.thankYouPage?.redirectDelay ?? 3e3;
|
|
2596
2692
|
setTimeout(() => {
|
|
2597
2693
|
window.location.href = t;
|
|
@@ -2606,9 +2702,9 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2606
2702
|
n,
|
|
2607
2703
|
e,
|
|
2608
2704
|
h,
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
]),
|
|
2705
|
+
x,
|
|
2706
|
+
S
|
|
2707
|
+
]), D = t(() => {
|
|
2612
2708
|
u(!1), m(null);
|
|
2613
2709
|
}, []), k = a(() => {
|
|
2614
2710
|
let t = {};
|
|
@@ -2624,7 +2720,7 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2624
2720
|
children: [
|
|
2625
2721
|
/* @__PURE__ */ X("div", {
|
|
2626
2722
|
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",
|
|
2627
|
-
children: /* @__PURE__ */ X(
|
|
2723
|
+
children: /* @__PURE__ */ X(q, {
|
|
2628
2724
|
className: "h-8 w-8",
|
|
2629
2725
|
"aria-hidden": "true"
|
|
2630
2726
|
})
|
|
@@ -2637,10 +2733,10 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2637
2733
|
className: "text-sm text-muted-foreground",
|
|
2638
2734
|
children: t?.message || n.thankYouMessage || "Your submission has been received successfully."
|
|
2639
2735
|
}),
|
|
2640
|
-
e.allowMultiple && /* @__PURE__ */ X(
|
|
2736
|
+
e.allowMultiple && /* @__PURE__ */ X(O, {
|
|
2641
2737
|
variant: "outline",
|
|
2642
2738
|
size: "sm",
|
|
2643
|
-
onClick:
|
|
2739
|
+
onClick: D,
|
|
2644
2740
|
className: "mt-2",
|
|
2645
2741
|
children: n.submitAnother ?? "Submit Another Response"
|
|
2646
2742
|
}),
|
|
@@ -2697,30 +2793,30 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2697
2793
|
className: "mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive",
|
|
2698
2794
|
children: p
|
|
2699
2795
|
}),
|
|
2700
|
-
/* @__PURE__ */ X(
|
|
2796
|
+
/* @__PURE__ */ X(Tt, {
|
|
2701
2797
|
schema: {
|
|
2702
2798
|
type: "object-form",
|
|
2703
2799
|
objectName: e.objectName,
|
|
2704
2800
|
mode: "create",
|
|
2705
2801
|
fields: e.fields,
|
|
2706
|
-
customFields:
|
|
2707
|
-
initialData:
|
|
2708
|
-
onSuccess:
|
|
2802
|
+
customFields: C,
|
|
2803
|
+
initialData: T,
|
|
2804
|
+
onSuccess: E,
|
|
2709
2805
|
submitText: d ? A.submitting ?? "Submitting..." : A.submit ?? "Submit"
|
|
2710
2806
|
},
|
|
2711
|
-
dataSource:
|
|
2807
|
+
dataSource: w
|
|
2712
2808
|
}),
|
|
2713
|
-
|
|
2809
|
+
x && /* @__PURE__ */ Z("div", {
|
|
2714
2810
|
"aria-hidden": "true",
|
|
2715
2811
|
className: "absolute left-[-10000px] top-auto h-px w-px overflow-hidden",
|
|
2716
2812
|
children: [/* @__PURE__ */ X("label", {
|
|
2717
|
-
htmlFor: `${e.formId}-${
|
|
2813
|
+
htmlFor: `${e.formId}-${x}`,
|
|
2718
2814
|
children: "Do not fill this field"
|
|
2719
2815
|
}), /* @__PURE__ */ X("input", {
|
|
2720
2816
|
ref: y,
|
|
2721
|
-
id: `${e.formId}-${
|
|
2817
|
+
id: `${e.formId}-${x}`,
|
|
2722
2818
|
type: "text",
|
|
2723
|
-
name:
|
|
2819
|
+
name: x,
|
|
2724
2820
|
tabIndex: -1,
|
|
2725
2821
|
autoComplete: "off",
|
|
2726
2822
|
defaultValue: ""
|
|
@@ -2750,7 +2846,7 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2750
2846
|
className: "text-destructive ml-0.5",
|
|
2751
2847
|
children: "*"
|
|
2752
2848
|
}),
|
|
2753
|
-
e.consent.privacyUrl && /* @__PURE__ */ Z(
|
|
2849
|
+
e.consent.privacyUrl && /* @__PURE__ */ Z(Y, { children: [" ", /* @__PURE__ */ X("a", {
|
|
2754
2850
|
href: e.consent.privacyUrl,
|
|
2755
2851
|
target: "_blank",
|
|
2756
2852
|
rel: "noopener noreferrer",
|
|
@@ -2768,7 +2864,7 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2768
2864
|
}),
|
|
2769
2865
|
d && /* @__PURE__ */ Z("div", {
|
|
2770
2866
|
className: "mt-3 flex items-center gap-2 text-xs text-muted-foreground",
|
|
2771
|
-
children: [/* @__PURE__ */ X(
|
|
2867
|
+
children: [/* @__PURE__ */ X(fe, {
|
|
2772
2868
|
className: "h-3.5 w-3.5 animate-spin",
|
|
2773
2869
|
"aria-hidden": "true"
|
|
2774
2870
|
}), /* @__PURE__ */ X("span", { children: A.submitting ?? "Submitting…" })]
|
|
@@ -2779,7 +2875,7 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2779
2875
|
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",
|
|
2780
2876
|
children: [/* @__PURE__ */ Z("p", {
|
|
2781
2877
|
className: "inline-flex items-center gap-1.5 text-xs text-muted-foreground",
|
|
2782
|
-
children: [/* @__PURE__ */ X(
|
|
2878
|
+
children: [/* @__PURE__ */ X(pe, {
|
|
2783
2879
|
className: "h-3 w-3",
|
|
2784
2880
|
"aria-hidden": "true"
|
|
2785
2881
|
}), /* @__PURE__ */ X("span", { children: A.secureNotice ?? "Your information is transmitted securely and only used to respond to your request." })]
|
|
@@ -2790,7 +2886,7 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2790
2886
|
target: "_blank",
|
|
2791
2887
|
rel: "noopener noreferrer",
|
|
2792
2888
|
className: "inline-flex items-center gap-1 underline hover:text-foreground",
|
|
2793
|
-
children: [/* @__PURE__ */ X(
|
|
2889
|
+
children: [/* @__PURE__ */ X(me, {
|
|
2794
2890
|
className: "h-3 w-3",
|
|
2795
2891
|
"aria-hidden": "true"
|
|
2796
2892
|
}), A.consentLink ?? "Privacy policy"]
|
|
@@ -2803,10 +2899,10 @@ var xt = ({ config: e, dataSource: n, prefillParams: i, className: c }) => {
|
|
|
2803
2899
|
};
|
|
2804
2900
|
//#endregion
|
|
2805
2901
|
//#region src/FormAnalytics.tsx
|
|
2806
|
-
function
|
|
2902
|
+
function Nt(e) {
|
|
2807
2903
|
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`;
|
|
2808
2904
|
}
|
|
2809
|
-
var
|
|
2905
|
+
var Pt = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
|
|
2810
2906
|
let i = a(() => {
|
|
2811
2907
|
if (!n.abandonedSubmissions) return 100;
|
|
2812
2908
|
let e = n.totalSubmissions + n.abandonedSubmissions;
|
|
@@ -2825,39 +2921,39 @@ var Ct = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
|
|
|
2825
2921
|
/* @__PURE__ */ Z("div", {
|
|
2826
2922
|
className: "grid grid-cols-1 sm:grid-cols-3 gap-4",
|
|
2827
2923
|
children: [
|
|
2828
|
-
/* @__PURE__ */ X(
|
|
2924
|
+
/* @__PURE__ */ X(k, { children: /* @__PURE__ */ Z(M, {
|
|
2829
2925
|
className: "pb-2",
|
|
2830
|
-
children: [/* @__PURE__ */ X(
|
|
2926
|
+
children: [/* @__PURE__ */ X(j, { children: "Total Submissions" }), /* @__PURE__ */ X(N, {
|
|
2831
2927
|
className: "text-2xl",
|
|
2832
2928
|
children: n.totalSubmissions.toLocaleString()
|
|
2833
2929
|
})]
|
|
2834
2930
|
}) }),
|
|
2835
|
-
/* @__PURE__ */ Z(
|
|
2931
|
+
/* @__PURE__ */ Z(k, { children: [/* @__PURE__ */ Z(M, {
|
|
2836
2932
|
className: "pb-2",
|
|
2837
|
-
children: [/* @__PURE__ */ X(
|
|
2933
|
+
children: [/* @__PURE__ */ X(j, { children: "Fill Rate" }), /* @__PURE__ */ Z(N, {
|
|
2838
2934
|
className: "text-2xl",
|
|
2839
2935
|
children: [i, "%"]
|
|
2840
2936
|
})]
|
|
2841
|
-
}), /* @__PURE__ */ X(
|
|
2937
|
+
}), /* @__PURE__ */ X(A, { children: /* @__PURE__ */ X("div", {
|
|
2842
2938
|
className: "w-full bg-muted rounded-full h-2",
|
|
2843
2939
|
children: /* @__PURE__ */ X("div", {
|
|
2844
2940
|
className: "bg-primary rounded-full h-2 transition-all",
|
|
2845
2941
|
style: { width: `${i}%` }
|
|
2846
2942
|
})
|
|
2847
2943
|
}) })] }),
|
|
2848
|
-
/* @__PURE__ */ X(
|
|
2944
|
+
/* @__PURE__ */ X(k, { children: /* @__PURE__ */ Z(M, {
|
|
2849
2945
|
className: "pb-2",
|
|
2850
|
-
children: [/* @__PURE__ */ X(
|
|
2946
|
+
children: [/* @__PURE__ */ X(j, { children: "Avg. Completion Time" }), /* @__PURE__ */ X(N, {
|
|
2851
2947
|
className: "text-2xl",
|
|
2852
|
-
children: n.avgCompletionTime ?
|
|
2948
|
+
children: n.avgCompletionTime ? Nt(n.avgCompletionTime) : "—"
|
|
2853
2949
|
})]
|
|
2854
2950
|
}) })
|
|
2855
2951
|
]
|
|
2856
2952
|
}),
|
|
2857
|
-
n.dailySubmissions && n.dailySubmissions.length > 0 && /* @__PURE__ */ Z(
|
|
2953
|
+
n.dailySubmissions && n.dailySubmissions.length > 0 && /* @__PURE__ */ Z(k, { children: [/* @__PURE__ */ X(M, { children: /* @__PURE__ */ X(N, {
|
|
2858
2954
|
className: "text-sm font-medium",
|
|
2859
2955
|
children: "Daily Submissions"
|
|
2860
|
-
}) }), /* @__PURE__ */ X(
|
|
2956
|
+
}) }), /* @__PURE__ */ X(A, { children: /* @__PURE__ */ X("div", {
|
|
2861
2957
|
className: "flex items-end gap-1 h-32",
|
|
2862
2958
|
children: n.dailySubmissions.map((e, t) => /* @__PURE__ */ Z("div", {
|
|
2863
2959
|
className: "flex-1 flex flex-col items-center gap-1",
|
|
@@ -2874,10 +2970,10 @@ var Ct = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
|
|
|
2874
2970
|
})]
|
|
2875
2971
|
}, t))
|
|
2876
2972
|
}) })] }),
|
|
2877
|
-
n.fieldDropOff && n.fieldDropOff.length > 0 && /* @__PURE__ */ Z(
|
|
2973
|
+
n.fieldDropOff && n.fieldDropOff.length > 0 && /* @__PURE__ */ Z(k, { children: [/* @__PURE__ */ Z(M, { children: [/* @__PURE__ */ X(N, {
|
|
2878
2974
|
className: "text-sm font-medium",
|
|
2879
2975
|
children: "Field Completion Rates"
|
|
2880
|
-
}), /* @__PURE__ */ X(
|
|
2976
|
+
}), /* @__PURE__ */ X(j, { children: "Percentage of users who completed each field" })] }), /* @__PURE__ */ X(A, { children: /* @__PURE__ */ X("div", {
|
|
2881
2977
|
className: "space-y-3",
|
|
2882
2978
|
children: n.fieldDropOff.map((e, t) => /* @__PURE__ */ Z("div", {
|
|
2883
2979
|
className: "space-y-1",
|
|
@@ -2901,8 +2997,8 @@ var Ct = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
|
|
|
2901
2997
|
}) })] })
|
|
2902
2998
|
]
|
|
2903
2999
|
});
|
|
2904
|
-
},
|
|
2905
|
-
let n = m()?.dataSource, i = f(), o = e.parentObject || i?.objectName, c = e.parentId || e.recordId || i?.recordId, [l, u] = s([]), [d, p] = s([]), [g, _] = s(!0), [v, y] = s(!1), [
|
|
3000
|
+
}, Ft = ({ schema: e }) => {
|
|
3001
|
+
let n = m()?.dataSource, i = f(), o = e.parentObject || i?.objectName, c = e.parentId || e.recordId || i?.recordId, [l, u] = s([]), [d, p] = s([]), [g, _] = s(!0), [v, y] = s(!1), [b, x] = s(!1), [S, C] = s(null), w = t(async () => {
|
|
2906
3002
|
if (!n || !c) {
|
|
2907
3003
|
_(!1);
|
|
2908
3004
|
return;
|
|
@@ -2913,9 +3009,9 @@ var Ct = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
|
|
|
2913
3009
|
$filter: { [e.relationshipField]: c },
|
|
2914
3010
|
$top: 500
|
|
2915
3011
|
}))?.data ?? [];
|
|
2916
|
-
u(t.map((e) => ({ ...e }))), p(t.map((e) => ({ ...e }))),
|
|
3012
|
+
u(t.map((e) => ({ ...e }))), p(t.map((e) => ({ ...e }))), x(!1);
|
|
2917
3013
|
} catch (e) {
|
|
2918
|
-
|
|
3014
|
+
C(e?.message || "Failed to load line items");
|
|
2919
3015
|
} finally {
|
|
2920
3016
|
_(!1);
|
|
2921
3017
|
}
|
|
@@ -2926,24 +3022,24 @@ var Ct = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
|
|
|
2926
3022
|
e.relationshipField
|
|
2927
3023
|
]);
|
|
2928
3024
|
r(() => {
|
|
2929
|
-
|
|
2930
|
-
}, [
|
|
2931
|
-
let
|
|
2932
|
-
u(e),
|
|
2933
|
-
}, []),
|
|
3025
|
+
w();
|
|
3026
|
+
}, [w]);
|
|
3027
|
+
let T = t((e) => {
|
|
3028
|
+
u(e), x(!0);
|
|
3029
|
+
}, []), E = t(async () => {
|
|
2934
3030
|
if (!(!n || !c)) {
|
|
2935
|
-
y(!0),
|
|
3031
|
+
y(!0), C(null);
|
|
2936
3032
|
try {
|
|
2937
|
-
await
|
|
3033
|
+
await Ne(n, o || e.childObject, c, {
|
|
2938
3034
|
childObject: e.childObject,
|
|
2939
3035
|
relationshipField: e.relationshipField,
|
|
2940
3036
|
rows: l,
|
|
2941
3037
|
original: d,
|
|
2942
3038
|
amountField: e.amountField,
|
|
2943
3039
|
totalField: o ? e.totalField : void 0
|
|
2944
|
-
}), await
|
|
3040
|
+
}), await w();
|
|
2945
3041
|
} catch (e) {
|
|
2946
|
-
|
|
3042
|
+
C(e?.message || "Failed to save line items");
|
|
2947
3043
|
} finally {
|
|
2948
3044
|
y(!1);
|
|
2949
3045
|
}
|
|
@@ -2955,8 +3051,8 @@ var Ct = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
|
|
|
2955
3051
|
d,
|
|
2956
3052
|
e,
|
|
2957
3053
|
o,
|
|
2958
|
-
|
|
2959
|
-
]),
|
|
3054
|
+
w
|
|
3055
|
+
]), D = a(() => ({
|
|
2960
3056
|
columns: e.columns,
|
|
2961
3057
|
total_field: e.totalField ? e.amountField || "amount" : void 0,
|
|
2962
3058
|
min_rows: e.minRows,
|
|
@@ -2964,41 +3060,41 @@ var Ct = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
|
|
|
2964
3060
|
allow_add: !e.readonly,
|
|
2965
3061
|
allow_delete: !e.readonly
|
|
2966
3062
|
}), [e]);
|
|
2967
|
-
return /* @__PURE__ */ Z(
|
|
2968
|
-
className:
|
|
2969
|
-
children: [/* @__PURE__ */ Z(
|
|
3063
|
+
return /* @__PURE__ */ Z(k, {
|
|
3064
|
+
className: G("shadow-none"),
|
|
3065
|
+
children: [/* @__PURE__ */ Z(M, {
|
|
2970
3066
|
className: "flex-row items-center justify-between gap-2 pb-2",
|
|
2971
|
-
children: [/* @__PURE__ */ X(
|
|
3067
|
+
children: [/* @__PURE__ */ X(N, {
|
|
2972
3068
|
className: "text-sm font-medium",
|
|
2973
3069
|
children: e.title || "Line Items"
|
|
2974
|
-
}), !e.readonly && /* @__PURE__ */ X(
|
|
3070
|
+
}), !e.readonly && /* @__PURE__ */ X(O, {
|
|
2975
3071
|
type: "button",
|
|
2976
3072
|
size: "sm",
|
|
2977
|
-
onClick:
|
|
2978
|
-
disabled: v || g || !
|
|
3073
|
+
onClick: E,
|
|
3074
|
+
disabled: v || g || !b || !c,
|
|
2979
3075
|
children: v ? "Saving…" : "Save"
|
|
2980
3076
|
})]
|
|
2981
|
-
}), /* @__PURE__ */ Z(
|
|
3077
|
+
}), /* @__PURE__ */ Z(A, { children: [S && /* @__PURE__ */ X("p", {
|
|
2982
3078
|
className: "mb-2 text-sm text-destructive",
|
|
2983
|
-
children:
|
|
3079
|
+
children: S
|
|
2984
3080
|
}), g ? /* @__PURE__ */ X("p", {
|
|
2985
3081
|
className: "py-6 text-center text-sm text-muted-foreground",
|
|
2986
3082
|
children: "Loading…"
|
|
2987
3083
|
}) : c ? /* @__PURE__ */ X(h, {
|
|
2988
3084
|
value: l,
|
|
2989
|
-
onChange:
|
|
2990
|
-
field:
|
|
3085
|
+
onChange: T,
|
|
3086
|
+
field: D,
|
|
2991
3087
|
readonly: e.readonly
|
|
2992
3088
|
}) : /* @__PURE__ */ X("p", {
|
|
2993
3089
|
className: "py-6 text-center text-sm text-muted-foreground",
|
|
2994
3090
|
children: "Save the record first to add line items."
|
|
2995
3091
|
})] })]
|
|
2996
3092
|
});
|
|
2997
|
-
},
|
|
3093
|
+
}, It = ({ schema: e }) => /* @__PURE__ */ X(Tt, {
|
|
2998
3094
|
schema: e,
|
|
2999
3095
|
dataSource: n(u)?.dataSource ?? void 0
|
|
3000
3096
|
});
|
|
3001
|
-
c.register("object-form",
|
|
3097
|
+
c.register("object-form", It, {
|
|
3002
3098
|
namespace: "plugin-form",
|
|
3003
3099
|
label: "Object Form",
|
|
3004
3100
|
category: "plugin",
|
|
@@ -3139,7 +3235,7 @@ c.register("object-form", Tt, {
|
|
|
3139
3235
|
]
|
|
3140
3236
|
}
|
|
3141
3237
|
]
|
|
3142
|
-
}), c.register("form",
|
|
3238
|
+
}), c.register("form", It, {
|
|
3143
3239
|
namespace: "view",
|
|
3144
3240
|
skipFallback: !0,
|
|
3145
3241
|
label: "Data Form View",
|
|
@@ -3167,7 +3263,7 @@ c.register("object-form", Tt, {
|
|
|
3167
3263
|
]
|
|
3168
3264
|
}
|
|
3169
3265
|
]
|
|
3170
|
-
}), c.register("embeddable-form", ({ schema: e }) => /* @__PURE__ */ X(
|
|
3266
|
+
}), c.register("embeddable-form", ({ schema: e }) => /* @__PURE__ */ X(Mt, { config: e }), {
|
|
3171
3267
|
namespace: "plugin-form",
|
|
3172
3268
|
label: "Embeddable Form",
|
|
3173
3269
|
category: "plugin",
|
|
@@ -3205,7 +3301,7 @@ c.register("object-form", Tt, {
|
|
|
3205
3301
|
label: "Allow Multiple Submissions"
|
|
3206
3302
|
}
|
|
3207
3303
|
]
|
|
3208
|
-
}), c.register("form-analytics", ({ schema: e }) => /* @__PURE__ */ X(
|
|
3304
|
+
}), c.register("form-analytics", ({ schema: e }) => /* @__PURE__ */ X(Pt, {
|
|
3209
3305
|
formId: e.formId,
|
|
3210
3306
|
formTitle: e.formTitle,
|
|
3211
3307
|
metrics: e.metrics || { totalSubmissions: 0 }
|
|
@@ -3231,7 +3327,7 @@ c.register("object-form", Tt, {
|
|
|
3231
3327
|
label: "Submission Metrics"
|
|
3232
3328
|
}
|
|
3233
3329
|
]
|
|
3234
|
-
}), c.register("object-master-detail-form", ({ schema: e }) => /* @__PURE__ */ X(
|
|
3330
|
+
}), c.register("object-master-detail-form", ({ schema: e }) => /* @__PURE__ */ X($e, {
|
|
3235
3331
|
schema: e,
|
|
3236
3332
|
dataSource: n(u)?.dataSource ?? void 0
|
|
3237
3333
|
}), {
|
|
@@ -3263,7 +3359,7 @@ c.register("object-form", Tt, {
|
|
|
3263
3359
|
required: !0
|
|
3264
3360
|
}
|
|
3265
3361
|
]
|
|
3266
|
-
}), c.register("line_items", ({ schema: e }) => /* @__PURE__ */ X(
|
|
3362
|
+
}), c.register("line_items", ({ schema: e }) => /* @__PURE__ */ X(Ft, { schema: e }), {
|
|
3267
3363
|
namespace: "record",
|
|
3268
3364
|
skipFallback: !0,
|
|
3269
3365
|
label: "Line Items",
|
|
@@ -3300,4 +3396,4 @@ c.register("object-form", Tt, {
|
|
|
3300
3396
|
]
|
|
3301
3397
|
});
|
|
3302
3398
|
//#endregion
|
|
3303
|
-
export {
|
|
3399
|
+
export { vt as DrawerForm, Mt as EmbeddableForm, Pt as FormAnalytics, _e as FormSection, Ft as LineItemsPanel, $e as MasterDetailForm, St as ModalForm, Tt as ObjectForm, we as SplitForm, Se as TabbedForm, Ce as WizardForm, ot as applyAutoColSpan, ft as applyAutoLayout, Ue as deriveColumns, Xe as deriveDetail, Ge as deriveFormFields, ut as filterAutoGeneratedFields, lt as filterCreateModeFields, ct as filterSystemFields, ze as findRelationshipField, at as inferColumns, dt as inferModalSize, it as isAutoGeneratedFieldType, rt as isWideFieldType, qe as resolveInlineMode };
|