@object-ui/plugin-form 4.4.0 → 4.5.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 +21 -0
- package/dist/index.js +263 -251
- package/dist/index.umd.cjs +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @object-ui/plugin-form
|
|
2
2
|
|
|
3
|
+
## 4.5.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6b6afd1: ModalForm / SplitForm / WizardForm now honor field-level `visibleOn` (CEL
|
|
8
|
+
expression on inline fields) and `visible_on` (object schema mirror) inside
|
|
9
|
+
their section-mode rendering. Previously only flat-field forms via ObjectForm
|
|
10
|
+
respected the expression; section-mode dropped it so conditional fields
|
|
11
|
+
always rendered.
|
|
12
|
+
- Updated dependencies [ab5e281]
|
|
13
|
+
- Updated dependencies [d714e85]
|
|
14
|
+
- Updated dependencies [6b6afd1]
|
|
15
|
+
- Updated dependencies [aa7855f]
|
|
16
|
+
- Updated dependencies [170d89f]
|
|
17
|
+
- @object-ui/types@4.5.0
|
|
18
|
+
- @object-ui/fields@4.5.0
|
|
19
|
+
- @object-ui/components@4.5.0
|
|
20
|
+
- @object-ui/core@4.5.0
|
|
21
|
+
- @object-ui/permissions@4.5.0
|
|
22
|
+
- @object-ui/react@4.5.0
|
|
23
|
+
|
|
3
24
|
## 4.4.0
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import { SchemaRenderer as s, useSafeFieldLabel as c } from "@object-ui/react";
|
|
|
4
4
|
import { buildValidationRules as l, evaluateCondition as u, formatFileSize as d, mapFieldTypeToFormType as f } from "@object-ui/fields";
|
|
5
5
|
import { Button as p, Card as m, CardContent as h, CardDescription as g, CardHeader as _, CardTitle as v, Dialog as y, DialogDescription as b, DialogHeader as x, DialogTitle as S, MobileDialogContent as C, ResizableHandle as w, ResizablePanel as T, ResizablePanelGroup as E, Sheet as D, SheetContent as O, SheetDescription as k, SheetHeader as A, SheetTitle as j, Skeleton as M, Tabs as N, TabsContent as P, TabsList as F, TabsTrigger as I, cn as L, useIsMobile as R } from "@object-ui/components";
|
|
6
6
|
import { usePermissions as z } from "@object-ui/permissions";
|
|
7
|
-
import { Check as B, ChevronDown as
|
|
8
|
-
import { Fragment as
|
|
7
|
+
import { Check as B, ChevronDown as V, ChevronLeft as H, ChevronRight as U, Loader2 as ee } from "lucide-react";
|
|
8
|
+
import { Fragment as te, jsx as W, jsxs as G } from "react/jsx-runtime";
|
|
9
9
|
//#region src/FormSection.tsx
|
|
10
10
|
var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, columns: i = 1, children: o, className: s, gridClassName: c }) => {
|
|
11
11
|
let [l, u] = a(r);
|
|
@@ -20,7 +20,7 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
20
20
|
"aria-expanded": n ? !l : void 0,
|
|
21
21
|
children: [n && /* @__PURE__ */ W("span", {
|
|
22
22
|
className: "mt-0.5 text-muted-foreground",
|
|
23
|
-
children: W(l ?
|
|
23
|
+
children: W(l ? U : V, { className: "h-4 w-4" })
|
|
24
24
|
}), /* @__PURE__ */ G("div", {
|
|
25
25
|
className: "flex-1",
|
|
26
26
|
children: [e && /* @__PURE__ */ W("h3", {
|
|
@@ -183,35 +183,35 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
183
183
|
})
|
|
184
184
|
});
|
|
185
185
|
}, J = ({ schema: n, dataSource: r, className: o }) => {
|
|
186
|
-
let { fieldLabel:
|
|
186
|
+
let { fieldLabel: d } = c(), [m, h] = a(null), [g, _] = a({}), [v, y] = a(!0), [b, x] = a(null), [S, C] = a(0), [w, T] = a(/* @__PURE__ */ new Set()), [E, D] = a(!1), O = n.sections.length, k = S === 0, A = S === O - 1;
|
|
187
187
|
e.useEffect(() => {
|
|
188
188
|
(async () => {
|
|
189
189
|
if (!r) {
|
|
190
|
-
|
|
190
|
+
y(!1);
|
|
191
191
|
return;
|
|
192
192
|
}
|
|
193
193
|
try {
|
|
194
|
-
|
|
194
|
+
h(await r.getObjectSchema(n.objectName));
|
|
195
195
|
} catch (e) {
|
|
196
|
-
|
|
196
|
+
x(e);
|
|
197
197
|
}
|
|
198
198
|
})();
|
|
199
199
|
}, [n.objectName, r]), e.useEffect(() => {
|
|
200
|
-
(
|
|
200
|
+
(m || !r) && (async () => {
|
|
201
201
|
if (n.mode === "create" || !n.recordId || !r) {
|
|
202
|
-
|
|
202
|
+
_(n.initialData || n.initialValues || {}), y(!1);
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
205
205
|
try {
|
|
206
|
-
|
|
206
|
+
_(await r.findOne(n.objectName, n.recordId) || {});
|
|
207
207
|
} catch (e) {
|
|
208
|
-
|
|
208
|
+
x(e);
|
|
209
209
|
} finally {
|
|
210
|
-
|
|
210
|
+
y(!1);
|
|
211
211
|
}
|
|
212
212
|
})();
|
|
213
213
|
}, [
|
|
214
|
-
|
|
214
|
+
m,
|
|
215
215
|
n.mode,
|
|
216
216
|
n.recordId,
|
|
217
217
|
n.initialData,
|
|
@@ -219,26 +219,29 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
219
219
|
r,
|
|
220
220
|
n.objectName
|
|
221
221
|
]);
|
|
222
|
-
let
|
|
223
|
-
let t = []
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
222
|
+
let j = t((e) => {
|
|
223
|
+
let t = [], r = (e, t) => typeof t == "string" && t.trim() ? {
|
|
224
|
+
...e,
|
|
225
|
+
visible: (e) => u(t, e)
|
|
226
|
+
} : e;
|
|
227
|
+
for (let i of e.fields) {
|
|
228
|
+
let e = typeof i == "string" ? i : i.name;
|
|
229
|
+
if (typeof i == "object") t.push(r(i, i.visibleOn));
|
|
230
|
+
else if (m?.fields?.[e]) {
|
|
231
|
+
let i = m.fields[e];
|
|
232
|
+
t.push(r({
|
|
230
233
|
name: e,
|
|
231
|
-
label:
|
|
232
|
-
type: f(
|
|
233
|
-
required:
|
|
234
|
-
disabled: n.readOnly || n.mode === "view" ||
|
|
235
|
-
placeholder:
|
|
236
|
-
description:
|
|
237
|
-
validation: l(
|
|
238
|
-
field:
|
|
239
|
-
options:
|
|
240
|
-
multiple:
|
|
241
|
-
});
|
|
234
|
+
label: d(n.objectName, e, i.label || e),
|
|
235
|
+
type: f(i.type),
|
|
236
|
+
required: i.required || !1,
|
|
237
|
+
disabled: n.readOnly || n.mode === "view" || i.readonly,
|
|
238
|
+
placeholder: i.placeholder,
|
|
239
|
+
description: i.help || i.description,
|
|
240
|
+
validation: l(i),
|
|
241
|
+
field: i,
|
|
242
|
+
options: i.options,
|
|
243
|
+
multiple: i.multiple
|
|
244
|
+
}, i.visible_on ?? i.visibleOn));
|
|
242
245
|
} else t.push({
|
|
243
246
|
name: e,
|
|
244
247
|
label: e,
|
|
@@ -247,21 +250,22 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
247
250
|
}
|
|
248
251
|
return t;
|
|
249
252
|
}, [
|
|
250
|
-
|
|
253
|
+
m,
|
|
251
254
|
n.readOnly,
|
|
252
|
-
n.mode
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
255
|
+
n.mode,
|
|
256
|
+
n.objectName
|
|
257
|
+
]), M = i(() => S >= 0 && S < O ? j(n.sections[S]) : [], [
|
|
258
|
+
S,
|
|
259
|
+
O,
|
|
256
260
|
n.sections,
|
|
257
|
-
|
|
258
|
-
]),
|
|
261
|
+
j
|
|
262
|
+
]), N = t(async (e) => {
|
|
259
263
|
let t = {
|
|
260
|
-
...
|
|
264
|
+
...g,
|
|
261
265
|
...e
|
|
262
266
|
};
|
|
263
|
-
if (
|
|
264
|
-
|
|
267
|
+
if (_(t), T((e) => new Set(e).add(S)), A) {
|
|
268
|
+
D(!0);
|
|
265
269
|
try {
|
|
266
270
|
if (!r) return n.onSuccess && await n.onSuccess(t), t;
|
|
267
271
|
let e;
|
|
@@ -269,47 +273,47 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
269
273
|
} catch (e) {
|
|
270
274
|
throw n.onError && n.onError(e), e;
|
|
271
275
|
} finally {
|
|
272
|
-
|
|
276
|
+
D(!1);
|
|
273
277
|
}
|
|
274
|
-
} else
|
|
278
|
+
} else P(S + 1);
|
|
275
279
|
}, [
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
280
|
+
g,
|
|
281
|
+
S,
|
|
282
|
+
A,
|
|
279
283
|
n,
|
|
280
284
|
r
|
|
281
|
-
]),
|
|
282
|
-
e >= 0 && e <
|
|
283
|
-
}, [
|
|
284
|
-
|
|
285
|
-
}, [
|
|
285
|
+
]), P = t((e) => {
|
|
286
|
+
e >= 0 && e < O && (C(e), n.onStepChange && n.onStepChange(e));
|
|
287
|
+
}, [O, n]), F = t(() => {
|
|
288
|
+
P(S - 1);
|
|
289
|
+
}, [S, P]), I = t(() => {
|
|
286
290
|
n.onCancel && n.onCancel();
|
|
287
|
-
}, [n]),
|
|
288
|
-
(n.allowSkip ||
|
|
291
|
+
}, [n]), R = t((e) => {
|
|
292
|
+
(n.allowSkip || w.has(e) || e <= S) && P(e);
|
|
289
293
|
}, [
|
|
290
294
|
n.allowSkip,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
295
|
+
w,
|
|
296
|
+
S,
|
|
297
|
+
P
|
|
294
298
|
]);
|
|
295
|
-
if (
|
|
299
|
+
if (b) return /* @__PURE__ */ G("div", {
|
|
296
300
|
className: "p-4 border border-red-300 bg-red-50 rounded-md",
|
|
297
301
|
children: [/* @__PURE__ */ W("h3", {
|
|
298
302
|
className: "text-red-800 font-semibold",
|
|
299
303
|
children: "Error loading form"
|
|
300
304
|
}), /* @__PURE__ */ W("p", {
|
|
301
305
|
className: "text-red-600 text-sm mt-1",
|
|
302
|
-
children:
|
|
306
|
+
children: b.message
|
|
303
307
|
})]
|
|
304
308
|
});
|
|
305
|
-
if (
|
|
309
|
+
if (v) return /* @__PURE__ */ G("div", {
|
|
306
310
|
className: "p-8 text-center",
|
|
307
311
|
children: [/* @__PURE__ */ W("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ W("p", {
|
|
308
312
|
className: "mt-2 text-sm text-gray-600",
|
|
309
313
|
children: "Loading form..."
|
|
310
314
|
})]
|
|
311
315
|
});
|
|
312
|
-
let
|
|
316
|
+
let z = n.sections[S];
|
|
313
317
|
return /* @__PURE__ */ G("div", {
|
|
314
318
|
className: L("w-full", o, n.className),
|
|
315
319
|
children: [
|
|
@@ -319,17 +323,17 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
319
323
|
children: /* @__PURE__ */ W("ol", {
|
|
320
324
|
className: "flex items-center",
|
|
321
325
|
children: n.sections.map((e, t) => {
|
|
322
|
-
let r = t ===
|
|
326
|
+
let r = t === S, i = w.has(t), a = n.allowSkip || i || t <= S;
|
|
323
327
|
return /* @__PURE__ */ G("li", {
|
|
324
|
-
className: L("relative flex-1", t !==
|
|
325
|
-
children: [t !==
|
|
328
|
+
className: L("relative flex-1", t !== O - 1 && "pr-8 sm:pr-12"),
|
|
329
|
+
children: [t !== O - 1 && /* @__PURE__ */ W("div", {
|
|
326
330
|
className: "absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5",
|
|
327
331
|
"aria-hidden": "true",
|
|
328
332
|
children: /* @__PURE__ */ W("div", { className: L("h-full", i ? "bg-primary" : "bg-muted") })
|
|
329
333
|
}), /* @__PURE__ */ G("button", {
|
|
330
334
|
type: "button",
|
|
331
335
|
className: L("group relative flex items-center", a ? "cursor-pointer" : "cursor-not-allowed"),
|
|
332
|
-
onClick: () =>
|
|
336
|
+
onClick: () => R(t),
|
|
333
337
|
disabled: !a,
|
|
334
338
|
children: [/* @__PURE__ */ W("span", {
|
|
335
339
|
className: L("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"),
|
|
@@ -348,18 +352,18 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
348
352
|
}),
|
|
349
353
|
/* @__PURE__ */ W("div", {
|
|
350
354
|
className: "min-h-[200px]",
|
|
351
|
-
children:
|
|
352
|
-
label:
|
|
353
|
-
description:
|
|
354
|
-
columns:
|
|
355
|
-
children:
|
|
355
|
+
children: z && /* @__PURE__ */ W(K, {
|
|
356
|
+
label: z.label,
|
|
357
|
+
description: z.description,
|
|
358
|
+
columns: z.columns || 1,
|
|
359
|
+
children: M.length > 0 ? /* @__PURE__ */ W(s, { schema: {
|
|
356
360
|
type: "form",
|
|
357
|
-
fields:
|
|
361
|
+
fields: M,
|
|
358
362
|
layout: "vertical",
|
|
359
|
-
defaultValues:
|
|
363
|
+
defaultValues: g,
|
|
360
364
|
showSubmit: !1,
|
|
361
365
|
showCancel: !1,
|
|
362
|
-
onSubmit:
|
|
366
|
+
onSubmit: N
|
|
363
367
|
} }) : /* @__PURE__ */ W("div", {
|
|
364
368
|
className: "text-center py-8 text-muted-foreground",
|
|
365
369
|
children: "No fields configured for this step"
|
|
@@ -370,7 +374,7 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
370
374
|
className: "flex items-center justify-between mt-6 pt-4 border-t",
|
|
371
375
|
children: [/* @__PURE__ */ W("div", { children: n.showCancel !== !1 && /* @__PURE__ */ W(p, {
|
|
372
376
|
variant: "ghost",
|
|
373
|
-
onClick:
|
|
377
|
+
onClick: I,
|
|
374
378
|
children: n.cancelText || "Cancel"
|
|
375
379
|
}) }), /* @__PURE__ */ G("div", {
|
|
376
380
|
className: "flex items-center gap-2",
|
|
@@ -379,23 +383,23 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
379
383
|
className: "text-sm text-muted-foreground mr-2",
|
|
380
384
|
children: [
|
|
381
385
|
"Step ",
|
|
382
|
-
|
|
386
|
+
S + 1,
|
|
383
387
|
" of ",
|
|
384
|
-
|
|
388
|
+
O
|
|
385
389
|
]
|
|
386
390
|
}),
|
|
387
|
-
!
|
|
391
|
+
!k && /* @__PURE__ */ G(p, {
|
|
388
392
|
variant: "outline",
|
|
389
|
-
onClick:
|
|
390
|
-
children: [/* @__PURE__ */ W(
|
|
393
|
+
onClick: F,
|
|
394
|
+
children: [/* @__PURE__ */ W(H, { className: "h-4 w-4 mr-1" }), n.prevText || "Back"]
|
|
391
395
|
}),
|
|
392
|
-
|
|
393
|
-
onClick: () =>
|
|
394
|
-
disabled:
|
|
395
|
-
children:
|
|
396
|
+
A ? /* @__PURE__ */ W(p, {
|
|
397
|
+
onClick: () => N(g),
|
|
398
|
+
disabled: E || n.mode === "view",
|
|
399
|
+
children: E ? "Submitting..." : n.submitText || (n.mode === "create" ? "Create" : "Update")
|
|
396
400
|
}) : /* @__PURE__ */ G(p, {
|
|
397
|
-
onClick: () =>
|
|
398
|
-
children: [n.nextText || "Next", /* @__PURE__ */ W(
|
|
401
|
+
onClick: () => N(g),
|
|
402
|
+
children: [n.nextText || "Next", /* @__PURE__ */ W(U, { className: "h-4 w-4 ml-1" })]
|
|
399
403
|
})
|
|
400
404
|
]
|
|
401
405
|
})]
|
|
@@ -403,39 +407,39 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
403
407
|
]
|
|
404
408
|
});
|
|
405
409
|
}, Y = ({ schema: e, dataSource: r, className: o }) => {
|
|
406
|
-
let { fieldLabel:
|
|
410
|
+
let { fieldLabel: d } = c(), [p, m] = a(null), [h, g] = a({}), [_, v] = a(!0), [y, b] = a(null);
|
|
407
411
|
n(() => {
|
|
408
412
|
(async () => {
|
|
409
413
|
if (!r) {
|
|
410
|
-
|
|
414
|
+
v(!1);
|
|
411
415
|
return;
|
|
412
416
|
}
|
|
413
417
|
try {
|
|
414
|
-
|
|
418
|
+
m(await r.getObjectSchema(e.objectName));
|
|
415
419
|
} catch (e) {
|
|
416
|
-
|
|
420
|
+
b(e), v(!1);
|
|
417
421
|
}
|
|
418
422
|
})();
|
|
419
423
|
}, [e.objectName, r]), n(() => {
|
|
420
|
-
(
|
|
424
|
+
(p || !r) && (async () => {
|
|
421
425
|
if (e.mode === "create" || !e.recordId) {
|
|
422
|
-
|
|
426
|
+
g(e.initialData || e.initialValues || {}), v(!1);
|
|
423
427
|
return;
|
|
424
428
|
}
|
|
425
429
|
if (!r) {
|
|
426
|
-
|
|
430
|
+
g(e.initialData || e.initialValues || {}), v(!1);
|
|
427
431
|
return;
|
|
428
432
|
}
|
|
429
433
|
try {
|
|
430
|
-
|
|
434
|
+
g(await r.findOne(e.objectName, e.recordId) || {});
|
|
431
435
|
} catch (e) {
|
|
432
|
-
|
|
436
|
+
b(e);
|
|
433
437
|
} finally {
|
|
434
|
-
|
|
438
|
+
v(!1);
|
|
435
439
|
}
|
|
436
440
|
})();
|
|
437
441
|
}, [
|
|
438
|
-
|
|
442
|
+
p,
|
|
439
443
|
e.mode,
|
|
440
444
|
e.recordId,
|
|
441
445
|
e.initialData,
|
|
@@ -443,26 +447,29 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
443
447
|
r,
|
|
444
448
|
e.objectName
|
|
445
449
|
]);
|
|
446
|
-
let
|
|
447
|
-
let n = []
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
450
|
+
let x = t((t) => {
|
|
451
|
+
let n = [], r = (e, t) => typeof t == "string" && t.trim() ? {
|
|
452
|
+
...e,
|
|
453
|
+
visible: (e) => u(t, e)
|
|
454
|
+
} : e;
|
|
455
|
+
for (let i of t.fields) {
|
|
456
|
+
let t = typeof i == "string" ? i : i.name;
|
|
457
|
+
if (typeof i == "object") n.push(r(i, i.visibleOn));
|
|
458
|
+
else if (p?.fields?.[t]) {
|
|
459
|
+
let i = p.fields[t];
|
|
460
|
+
n.push(r({
|
|
454
461
|
name: t,
|
|
455
|
-
label:
|
|
456
|
-
type: f(
|
|
457
|
-
required:
|
|
458
|
-
disabled: e.readOnly || e.mode === "view" ||
|
|
459
|
-
placeholder:
|
|
460
|
-
description:
|
|
461
|
-
validation: l(
|
|
462
|
-
field:
|
|
463
|
-
options:
|
|
464
|
-
multiple:
|
|
465
|
-
});
|
|
462
|
+
label: d(e.objectName, t, i.label || t),
|
|
463
|
+
type: f(i.type),
|
|
464
|
+
required: i.required || !1,
|
|
465
|
+
disabled: e.readOnly || e.mode === "view" || i.readonly,
|
|
466
|
+
placeholder: i.placeholder,
|
|
467
|
+
description: i.help || i.description,
|
|
468
|
+
validation: l(i),
|
|
469
|
+
field: i,
|
|
470
|
+
options: i.options,
|
|
471
|
+
multiple: i.multiple
|
|
472
|
+
}, i.visible_on ?? i.visibleOn));
|
|
466
473
|
} else n.push({
|
|
467
474
|
name: t,
|
|
468
475
|
label: t,
|
|
@@ -471,10 +478,11 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
471
478
|
}
|
|
472
479
|
return n;
|
|
473
480
|
}, [
|
|
474
|
-
|
|
481
|
+
p,
|
|
475
482
|
e.readOnly,
|
|
476
|
-
e.mode
|
|
477
|
-
|
|
483
|
+
e.mode,
|
|
484
|
+
e.objectName
|
|
485
|
+
]), S = t(async (t) => {
|
|
478
486
|
if (!r) return e.onSuccess && await e.onSuccess(t), t;
|
|
479
487
|
try {
|
|
480
488
|
let n;
|
|
@@ -482,43 +490,43 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
482
490
|
} catch (t) {
|
|
483
491
|
throw e.onError && e.onError(t), t;
|
|
484
492
|
}
|
|
485
|
-
}, [e, r]),
|
|
493
|
+
}, [e, r]), C = t(() => {
|
|
486
494
|
e.onCancel && e.onCancel();
|
|
487
|
-
}, [e]),
|
|
488
|
-
i(() => e.sections.flatMap((e) =>
|
|
489
|
-
let
|
|
490
|
-
if (
|
|
495
|
+
}, [e]), D = i(() => e.sections.slice(0, 1), [e.sections]), O = i(() => e.sections.slice(1), [e.sections]);
|
|
496
|
+
i(() => e.sections.flatMap((e) => x(e)), [e.sections, x]);
|
|
497
|
+
let k = e.splitDirection || "horizontal", A = e.splitSize || 50;
|
|
498
|
+
if (y) return /* @__PURE__ */ G("div", {
|
|
491
499
|
className: "p-4 border border-red-300 bg-red-50 rounded-md",
|
|
492
500
|
children: [/* @__PURE__ */ W("h3", {
|
|
493
501
|
className: "text-red-800 font-semibold",
|
|
494
502
|
children: "Error loading form"
|
|
495
503
|
}), /* @__PURE__ */ W("p", {
|
|
496
504
|
className: "text-red-600 text-sm mt-1",
|
|
497
|
-
children:
|
|
505
|
+
children: y.message
|
|
498
506
|
})]
|
|
499
507
|
});
|
|
500
|
-
if (
|
|
508
|
+
if (_) return /* @__PURE__ */ G("div", {
|
|
501
509
|
className: "p-8 text-center",
|
|
502
510
|
children: [/* @__PURE__ */ W("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ W("p", {
|
|
503
511
|
className: "mt-2 text-sm text-gray-600",
|
|
504
512
|
children: "Loading form..."
|
|
505
513
|
})]
|
|
506
514
|
});
|
|
507
|
-
let
|
|
515
|
+
let j = {
|
|
508
516
|
type: "form",
|
|
509
517
|
layout: "vertical",
|
|
510
|
-
defaultValues:
|
|
511
|
-
onSubmit:
|
|
512
|
-
onCancel:
|
|
513
|
-
},
|
|
518
|
+
defaultValues: h,
|
|
519
|
+
onSubmit: S,
|
|
520
|
+
onCancel: C
|
|
521
|
+
}, M = (t, n) => /* @__PURE__ */ W("div", {
|
|
514
522
|
className: "space-y-4 p-4",
|
|
515
523
|
children: t.map((t, r) => /* @__PURE__ */ W(K, {
|
|
516
524
|
label: t.label,
|
|
517
525
|
description: t.description,
|
|
518
526
|
columns: t.columns || 1,
|
|
519
527
|
children: /* @__PURE__ */ W(s, { schema: {
|
|
520
|
-
...
|
|
521
|
-
fields:
|
|
528
|
+
...j,
|
|
529
|
+
fields: x(t),
|
|
522
530
|
showSubmit: n && e.showSubmit !== !1 && e.mode !== "view",
|
|
523
531
|
showCancel: n && e.showCancel !== !1,
|
|
524
532
|
submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
|
|
@@ -529,16 +537,16 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
529
537
|
return /* @__PURE__ */ W("div", {
|
|
530
538
|
className: L("w-full", o, e.className),
|
|
531
539
|
children: /* @__PURE__ */ G(E, {
|
|
532
|
-
orientation:
|
|
540
|
+
orientation: k,
|
|
533
541
|
className: "min-h-[300px] rounded-lg border",
|
|
534
542
|
children: [/* @__PURE__ */ W(T, {
|
|
535
|
-
defaultSize:
|
|
543
|
+
defaultSize: A,
|
|
536
544
|
minSize: 20,
|
|
537
|
-
children:
|
|
538
|
-
}),
|
|
539
|
-
defaultSize: 100 -
|
|
545
|
+
children: M(D, O.length === 0)
|
|
546
|
+
}), O.length > 0 && /* @__PURE__ */ G(te, { children: [/* @__PURE__ */ W(w, { withHandle: e.splitResizable !== !1 }), /* @__PURE__ */ W(T, {
|
|
547
|
+
defaultSize: 100 - A,
|
|
540
548
|
minSize: 20,
|
|
541
|
-
children:
|
|
549
|
+
children: M(O, !0)
|
|
542
550
|
})] })]
|
|
543
551
|
})
|
|
544
552
|
});
|
|
@@ -547,7 +555,7 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
547
555
|
"field:summary",
|
|
548
556
|
"field:auto_number",
|
|
549
557
|
"field:autonumber"
|
|
550
|
-
]),
|
|
558
|
+
]), Z = new Set([
|
|
551
559
|
"field:textarea",
|
|
552
560
|
"field:markdown",
|
|
553
561
|
"field:html",
|
|
@@ -558,23 +566,23 @@ var K = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
|
|
|
558
566
|
"html",
|
|
559
567
|
"grid",
|
|
560
568
|
"rich-text"
|
|
561
|
-
]),
|
|
569
|
+
]), ne = new Set([
|
|
562
570
|
"formula",
|
|
563
571
|
"summary",
|
|
564
572
|
"auto_number",
|
|
565
573
|
"autonumber"
|
|
566
574
|
]);
|
|
567
|
-
function
|
|
568
|
-
return
|
|
575
|
+
function Q(e) {
|
|
576
|
+
return Z.has(e);
|
|
569
577
|
}
|
|
570
|
-
function
|
|
571
|
-
return
|
|
578
|
+
function re(e) {
|
|
579
|
+
return ne.has(e);
|
|
572
580
|
}
|
|
573
|
-
function
|
|
581
|
+
function ie(e) {
|
|
574
582
|
return e <= 3 ? 1 : 2;
|
|
575
583
|
}
|
|
576
|
-
function
|
|
577
|
-
return t <= 1 ? e : e.map((e) => e.colSpan === void 0 && e.type &&
|
|
584
|
+
function ae(e, t) {
|
|
585
|
+
return t <= 1 ? e : e.map((e) => e.colSpan === void 0 && e.type && Q(e.type) ? {
|
|
578
586
|
...e,
|
|
579
587
|
colSpan: t
|
|
580
588
|
} : e);
|
|
@@ -614,14 +622,14 @@ function ce(e, t) {
|
|
|
614
622
|
if (oe.has(e.name) || e.type && X.has(e.type)) return !1;
|
|
615
623
|
if (!t?.fields) return !0;
|
|
616
624
|
let n = t.fields[e.name];
|
|
617
|
-
return n ? n.readonly === !0 ? !1 : !
|
|
625
|
+
return n ? n.readonly === !0 ? !1 : !re(n.type) : !0;
|
|
618
626
|
});
|
|
619
627
|
}
|
|
620
628
|
function le(e, t) {
|
|
621
629
|
return e.filter((e) => {
|
|
622
630
|
if (e.type && X.has(e.type)) return !1;
|
|
623
631
|
let n = t?.fields?.[e.name];
|
|
624
|
-
return n ? !
|
|
632
|
+
return n ? !re(n.type) : !0;
|
|
625
633
|
});
|
|
626
634
|
}
|
|
627
635
|
function ue(e) {
|
|
@@ -629,12 +637,12 @@ function ue(e) {
|
|
|
629
637
|
}
|
|
630
638
|
function $(e, t, n, r) {
|
|
631
639
|
let i = [...e];
|
|
632
|
-
if (i = se(i, t), r === "create" && (i = le(i, t)), n !== void 0) return i =
|
|
640
|
+
if (i = se(i, t), r === "create" && (i = le(i, t)), n !== void 0) return i = ae(i, n), {
|
|
633
641
|
fields: i,
|
|
634
642
|
columns: n
|
|
635
643
|
};
|
|
636
|
-
let a =
|
|
637
|
-
return i =
|
|
644
|
+
let a = ie(i.length);
|
|
645
|
+
return i = ae(i, a), {
|
|
638
646
|
fields: i,
|
|
639
647
|
columns: a
|
|
640
648
|
};
|
|
@@ -906,16 +914,16 @@ var me = {
|
|
|
906
914
|
2: "grid gap-4 grid-cols-1 @md:grid-cols-2",
|
|
907
915
|
3: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",
|
|
908
916
|
4: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"
|
|
909
|
-
}, ve = ({ schema: e, dataSource: o, className:
|
|
910
|
-
let { fieldLabel:
|
|
911
|
-
if (!
|
|
917
|
+
}, ve = ({ schema: e, dataSource: o, className: d }) => {
|
|
918
|
+
let { fieldLabel: m } = c(), h = z(), g = t((t) => {
|
|
919
|
+
if (!h?.isLoaded) return t;
|
|
912
920
|
let n = [];
|
|
913
921
|
for (let r of t) {
|
|
914
922
|
if (!r?.name) {
|
|
915
923
|
n.push(r);
|
|
916
924
|
continue;
|
|
917
925
|
}
|
|
918
|
-
|
|
926
|
+
h.checkField(e.objectName, r.name, "read") && (!h.checkField(e.objectName, r.name, "write") && e.mode !== "view" ? n.push({
|
|
919
927
|
...r,
|
|
920
928
|
readOnly: !0,
|
|
921
929
|
disabled: !0
|
|
@@ -923,19 +931,19 @@ var me = {
|
|
|
923
931
|
}
|
|
924
932
|
return n;
|
|
925
933
|
}, [
|
|
926
|
-
|
|
934
|
+
h,
|
|
927
935
|
e.objectName,
|
|
928
936
|
e.mode
|
|
929
|
-
]), [
|
|
930
|
-
|
|
931
|
-
|
|
937
|
+
]), [_, v] = a(null), [w, T] = a([]), [E, D] = a({}), [O, k] = a(!0), [A, j] = a(null), [N, P] = a(!1), F = e.open !== !1, I = r(), R = i(() => e.sections?.length || e.customFields?.length ? null : $(w, _, e.columns, e.mode), [
|
|
938
|
+
w,
|
|
939
|
+
_,
|
|
932
940
|
e.columns,
|
|
933
941
|
e.mode,
|
|
934
942
|
e.sections,
|
|
935
943
|
e.customFields
|
|
936
|
-
]),
|
|
944
|
+
]), B = ge[i(() => {
|
|
937
945
|
if (e.modalSize) return e.modalSize;
|
|
938
|
-
if (
|
|
946
|
+
if (R?.columns && R.columns > 1) return ue(R.columns);
|
|
939
947
|
if (e.sections?.length) {
|
|
940
948
|
let t = Math.max(...e.sections.map((e) => Number(e.columns) || 1));
|
|
941
949
|
if (t > 1) return ue(t);
|
|
@@ -943,41 +951,41 @@ var me = {
|
|
|
943
951
|
return "default";
|
|
944
952
|
}, [
|
|
945
953
|
e.modalSize,
|
|
946
|
-
|
|
954
|
+
R,
|
|
947
955
|
e.sections
|
|
948
956
|
])] || ge.default;
|
|
949
957
|
n(() => {
|
|
950
958
|
(async () => {
|
|
951
959
|
if (!o) {
|
|
952
|
-
|
|
960
|
+
k(!1);
|
|
953
961
|
return;
|
|
954
962
|
}
|
|
955
963
|
try {
|
|
956
|
-
|
|
964
|
+
v(await o.getObjectSchema(e.objectName));
|
|
957
965
|
} catch (e) {
|
|
958
|
-
|
|
966
|
+
j(e), k(!1);
|
|
959
967
|
}
|
|
960
968
|
})();
|
|
961
969
|
}, [e.objectName, o]), n(() => {
|
|
962
|
-
(
|
|
970
|
+
(_ || !o) && (async () => {
|
|
963
971
|
if (e.mode === "create" || !e.recordId) {
|
|
964
|
-
|
|
972
|
+
D(e.initialData || e.initialValues || {}), k(!1);
|
|
965
973
|
return;
|
|
966
974
|
}
|
|
967
975
|
if (!o) {
|
|
968
|
-
|
|
976
|
+
D(e.initialData || e.initialValues || {}), k(!1);
|
|
969
977
|
return;
|
|
970
978
|
}
|
|
971
979
|
try {
|
|
972
|
-
|
|
980
|
+
D(await o.findOne(e.objectName, e.recordId) || {});
|
|
973
981
|
} catch (e) {
|
|
974
|
-
|
|
982
|
+
j(e);
|
|
975
983
|
} finally {
|
|
976
|
-
|
|
984
|
+
k(!1);
|
|
977
985
|
}
|
|
978
986
|
})();
|
|
979
987
|
}, [
|
|
980
|
-
|
|
988
|
+
_,
|
|
981
989
|
e.mode,
|
|
982
990
|
e.recordId,
|
|
983
991
|
e.initialData,
|
|
@@ -985,26 +993,29 @@ var me = {
|
|
|
985
993
|
o,
|
|
986
994
|
e.objectName
|
|
987
995
|
]);
|
|
988
|
-
let
|
|
989
|
-
let n = []
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
+
let V = t((t) => {
|
|
997
|
+
let n = [], r = (e, t) => typeof t == "string" && t.trim() ? {
|
|
998
|
+
...e,
|
|
999
|
+
visible: (e) => u(t, e)
|
|
1000
|
+
} : e;
|
|
1001
|
+
for (let i of t.fields) {
|
|
1002
|
+
let t = typeof i == "string" ? i : i.name;
|
|
1003
|
+
if (typeof i == "object") n.push(r(i, i.visibleOn));
|
|
1004
|
+
else if (_?.fields?.[t]) {
|
|
1005
|
+
let i = _.fields[t];
|
|
1006
|
+
n.push(r({
|
|
996
1007
|
name: t,
|
|
997
|
-
label:
|
|
998
|
-
type: f(
|
|
999
|
-
required:
|
|
1000
|
-
disabled: e.readOnly || e.mode === "view" ||
|
|
1001
|
-
placeholder:
|
|
1002
|
-
description:
|
|
1003
|
-
validation: l(
|
|
1004
|
-
field:
|
|
1005
|
-
options:
|
|
1006
|
-
multiple:
|
|
1007
|
-
});
|
|
1008
|
+
label: m(e.objectName, t, i.label || t),
|
|
1009
|
+
type: f(i.type),
|
|
1010
|
+
required: i.required || !1,
|
|
1011
|
+
disabled: e.readOnly || e.mode === "view" || i.readonly,
|
|
1012
|
+
placeholder: i.placeholder,
|
|
1013
|
+
description: i.help || i.description,
|
|
1014
|
+
validation: l(i),
|
|
1015
|
+
field: i,
|
|
1016
|
+
options: i.options,
|
|
1017
|
+
multiple: i.multiple
|
|
1018
|
+
}, i.visible_on ?? i.visibleOn));
|
|
1008
1019
|
} else n.push({
|
|
1009
1020
|
name: t,
|
|
1010
1021
|
label: t,
|
|
@@ -1013,29 +1024,30 @@ var me = {
|
|
|
1013
1024
|
}
|
|
1014
1025
|
return n;
|
|
1015
1026
|
}, [
|
|
1016
|
-
|
|
1027
|
+
_,
|
|
1017
1028
|
e.readOnly,
|
|
1018
|
-
e.mode
|
|
1029
|
+
e.mode,
|
|
1030
|
+
e.objectName
|
|
1019
1031
|
]);
|
|
1020
1032
|
n(() => {
|
|
1021
|
-
if (!
|
|
1033
|
+
if (!_ && o) return;
|
|
1022
1034
|
if (e.customFields?.length) {
|
|
1023
|
-
|
|
1035
|
+
T(e.customFields), k(!1);
|
|
1024
1036
|
return;
|
|
1025
1037
|
}
|
|
1026
1038
|
if (e.sections?.length) {
|
|
1027
|
-
|
|
1039
|
+
k(!1);
|
|
1028
1040
|
return;
|
|
1029
1041
|
}
|
|
1030
|
-
if (!
|
|
1031
|
-
let t = e.fields || Object.keys(
|
|
1042
|
+
if (!_) return;
|
|
1043
|
+
let t = e.fields || Object.keys(_.fields || {}), n = [];
|
|
1032
1044
|
for (let r of t) {
|
|
1033
1045
|
let t = typeof r == "string" ? r : r.name;
|
|
1034
1046
|
if (!t) continue;
|
|
1035
|
-
let i =
|
|
1047
|
+
let i = _.fields?.[t];
|
|
1036
1048
|
i && n.push({
|
|
1037
1049
|
name: t,
|
|
1038
|
-
label:
|
|
1050
|
+
label: m(e.objectName, t, i.label || t),
|
|
1039
1051
|
type: f(i.type),
|
|
1040
1052
|
required: i.required || !1,
|
|
1041
1053
|
disabled: e.readOnly || e.mode === "view" || i.readonly,
|
|
@@ -1047,9 +1059,9 @@ var me = {
|
|
|
1047
1059
|
multiple: i.multiple
|
|
1048
1060
|
});
|
|
1049
1061
|
}
|
|
1050
|
-
|
|
1062
|
+
T(n), k(!1);
|
|
1051
1063
|
}, [
|
|
1052
|
-
|
|
1064
|
+
_,
|
|
1053
1065
|
e.fields,
|
|
1054
1066
|
e.customFields,
|
|
1055
1067
|
e.sections,
|
|
@@ -1057,53 +1069,53 @@ var me = {
|
|
|
1057
1069
|
e.mode,
|
|
1058
1070
|
o
|
|
1059
1071
|
]);
|
|
1060
|
-
let
|
|
1061
|
-
|
|
1072
|
+
let H = t(async (t) => {
|
|
1073
|
+
P(!0);
|
|
1062
1074
|
try {
|
|
1063
1075
|
if (!o) return e.onSuccess && await e.onSuccess(t), e.onOpenChange?.(!1), t;
|
|
1064
|
-
let n, r = pe(t,
|
|
1065
|
-
if (
|
|
1076
|
+
let n, r = pe(t, _);
|
|
1077
|
+
if (h?.isLoaded) {
|
|
1066
1078
|
let t = {};
|
|
1067
|
-
for (let n of Object.keys(r))
|
|
1079
|
+
for (let n of Object.keys(r)) h.checkField(e.objectName, n, "write") && (t[n] = r[n]);
|
|
1068
1080
|
r = t;
|
|
1069
1081
|
}
|
|
1070
1082
|
return e.mode === "create" ? n = await o.create(e.objectName, r) : e.mode === "edit" && e.recordId && (n = await o.update(e.objectName, e.recordId, r)), e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
|
|
1071
1083
|
} catch (t) {
|
|
1072
1084
|
throw e.onError && e.onError(t), t;
|
|
1073
1085
|
} finally {
|
|
1074
|
-
|
|
1086
|
+
P(!1);
|
|
1075
1087
|
}
|
|
1076
1088
|
}, [
|
|
1077
1089
|
e,
|
|
1078
1090
|
o,
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
]),
|
|
1091
|
+
_,
|
|
1092
|
+
h
|
|
1093
|
+
]), U = t(() => {
|
|
1082
1094
|
e.onCancel && e.onCancel(), e.onOpenChange?.(!1);
|
|
1083
|
-
}, [e]),
|
|
1095
|
+
}, [e]), te = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical", q = e.showSubmit !== !1 && e.mode !== "view", J = e.showCancel !== !1, Y = e.submitText || (e.mode === "create" ? "Create" : "Update"), X = e.cancelText || "Cancel", Z = {
|
|
1084
1096
|
type: "form",
|
|
1085
|
-
layout:
|
|
1086
|
-
defaultValues:
|
|
1087
|
-
submitLabel:
|
|
1088
|
-
cancelLabel:
|
|
1089
|
-
showSubmit:
|
|
1090
|
-
showCancel:
|
|
1091
|
-
onSubmit:
|
|
1092
|
-
onCancel:
|
|
1097
|
+
layout: te,
|
|
1098
|
+
defaultValues: E,
|
|
1099
|
+
submitLabel: Y,
|
|
1100
|
+
cancelLabel: X,
|
|
1101
|
+
showSubmit: q,
|
|
1102
|
+
showCancel: J,
|
|
1103
|
+
onSubmit: H,
|
|
1104
|
+
onCancel: U,
|
|
1093
1105
|
showActions: !1,
|
|
1094
|
-
id:
|
|
1106
|
+
id: I
|
|
1095
1107
|
}, ne = () => {
|
|
1096
|
-
if (
|
|
1108
|
+
if (A) return /* @__PURE__ */ G("div", {
|
|
1097
1109
|
className: "p-4 border border-red-300 bg-red-50 rounded-md",
|
|
1098
1110
|
children: [/* @__PURE__ */ W("h3", {
|
|
1099
1111
|
className: "text-red-800 font-semibold",
|
|
1100
1112
|
children: "Error loading form"
|
|
1101
1113
|
}), /* @__PURE__ */ W("p", {
|
|
1102
1114
|
className: "text-red-600 text-sm mt-1",
|
|
1103
|
-
children:
|
|
1115
|
+
children: A.message
|
|
1104
1116
|
})]
|
|
1105
1117
|
});
|
|
1106
|
-
if (
|
|
1118
|
+
if (O) return /* @__PURE__ */ W("div", {
|
|
1107
1119
|
className: "space-y-4",
|
|
1108
1120
|
"data-testid": "modal-form-skeleton",
|
|
1109
1121
|
children: [
|
|
@@ -1125,25 +1137,25 @@ var me = {
|
|
|
1125
1137
|
columns: n,
|
|
1126
1138
|
gridClassName: _e[n],
|
|
1127
1139
|
children: /* @__PURE__ */ W(s, { schema: {
|
|
1128
|
-
...
|
|
1129
|
-
fields:
|
|
1140
|
+
...Z,
|
|
1141
|
+
fields: g(V(e))
|
|
1130
1142
|
} })
|
|
1131
1143
|
}, e.name || e.label || t);
|
|
1132
1144
|
})
|
|
1133
1145
|
});
|
|
1134
|
-
let t =
|
|
1146
|
+
let t = R ?? $(w, _, e.columns, e.mode), n = _e[t.columns || 1];
|
|
1135
1147
|
return /* @__PURE__ */ W(s, { schema: {
|
|
1136
|
-
...
|
|
1137
|
-
fields:
|
|
1148
|
+
...Z,
|
|
1149
|
+
fields: g(t.fields),
|
|
1138
1150
|
columns: t.columns,
|
|
1139
1151
|
...n ? { fieldContainerClass: n } : {}
|
|
1140
1152
|
} });
|
|
1141
|
-
},
|
|
1153
|
+
}, Q = !O && !A && (q || J);
|
|
1142
1154
|
return /* @__PURE__ */ W(y, {
|
|
1143
|
-
open:
|
|
1155
|
+
open: F,
|
|
1144
1156
|
onOpenChange: e.onOpenChange,
|
|
1145
1157
|
children: /* @__PURE__ */ G(C, {
|
|
1146
|
-
className: L(
|
|
1158
|
+
className: L(B, "flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0", d, e.className),
|
|
1147
1159
|
children: [
|
|
1148
1160
|
(e.title || e.description) && /* @__PURE__ */ G(x, {
|
|
1149
1161
|
className: "shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b",
|
|
@@ -1153,24 +1165,24 @@ var me = {
|
|
|
1153
1165
|
className: "@container flex-1 overflow-y-auto px-4 sm:px-6 py-4",
|
|
1154
1166
|
children: ne()
|
|
1155
1167
|
}),
|
|
1156
|
-
|
|
1168
|
+
Q && /* @__PURE__ */ W("div", {
|
|
1157
1169
|
className: "shrink-0 border-t px-4 sm:px-6 py-3 bg-background",
|
|
1158
1170
|
"data-testid": "modal-form-footer",
|
|
1159
1171
|
children: /* @__PURE__ */ G("div", {
|
|
1160
1172
|
className: "flex flex-col sm:flex-row gap-2 sm:justify-end",
|
|
1161
|
-
children: [
|
|
1173
|
+
children: [J && /* @__PURE__ */ W(p, {
|
|
1162
1174
|
type: "button",
|
|
1163
1175
|
variant: "outline",
|
|
1164
|
-
onClick:
|
|
1165
|
-
disabled:
|
|
1176
|
+
onClick: U,
|
|
1177
|
+
disabled: N,
|
|
1166
1178
|
className: "w-full sm:w-auto",
|
|
1167
|
-
children:
|
|
1168
|
-
}),
|
|
1179
|
+
children: X
|
|
1180
|
+
}), q && /* @__PURE__ */ G(p, {
|
|
1169
1181
|
type: "submit",
|
|
1170
|
-
form:
|
|
1171
|
-
disabled:
|
|
1182
|
+
form: I,
|
|
1183
|
+
disabled: N,
|
|
1172
1184
|
className: "w-full sm:w-auto",
|
|
1173
|
-
children: [
|
|
1185
|
+
children: [N && /* @__PURE__ */ W(ee, { className: "mr-2 h-4 w-4 animate-spin" }), Y]
|
|
1174
1186
|
})]
|
|
1175
1187
|
})
|
|
1176
1188
|
})
|
|
@@ -1512,14 +1524,14 @@ var me = {
|
|
|
1512
1524
|
...e,
|
|
1513
1525
|
mobile_fullscreen: !0
|
|
1514
1526
|
} : e;
|
|
1515
|
-
}) : F.fields, B = I?.stepper,
|
|
1516
|
-
if (!r.formType && !N && L.length >= 2 && (B === !0 || B === "auto" && m && L.length >=
|
|
1527
|
+
}) : F.fields, B = I?.stepper, V = I?.stepperMinFields ?? 8, H = Math.max(1, I?.stepperFieldsPerStep ?? 1);
|
|
1528
|
+
if (!r.formType && !N && L.length >= 2 && (B === !0 || B === "auto" && m && L.length >= V)) {
|
|
1517
1529
|
let e = L, t = [];
|
|
1518
|
-
for (let n = 0; n < e.length; n +=
|
|
1519
|
-
let r = e.slice(n, n +
|
|
1530
|
+
for (let n = 0; n < e.length; n += H) {
|
|
1531
|
+
let r = e.slice(n, n + H);
|
|
1520
1532
|
t.push({
|
|
1521
|
-
name: `step-${Math.floor(n /
|
|
1522
|
-
label: r[0]?.label || r[0]?.name || `Step ${Math.floor(n /
|
|
1533
|
+
name: `step-${Math.floor(n / H) + 1}`,
|
|
1534
|
+
label: r[0]?.label || r[0]?.name || `Step ${Math.floor(n / H) + 1}`,
|
|
1523
1535
|
fields: r
|
|
1524
1536
|
});
|
|
1525
1537
|
}
|
|
@@ -1534,7 +1546,7 @@ var me = {
|
|
|
1534
1546
|
className: r.className
|
|
1535
1547
|
});
|
|
1536
1548
|
}
|
|
1537
|
-
let
|
|
1549
|
+
let U = {
|
|
1538
1550
|
type: "form",
|
|
1539
1551
|
fields: L,
|
|
1540
1552
|
layout: M,
|
|
@@ -1553,7 +1565,7 @@ var me = {
|
|
|
1553
1565
|
return /* @__PURE__ */ W("div", {
|
|
1554
1566
|
className: I?.stickyActions ? "w-full pb-20 md:pb-0" : "w-full",
|
|
1555
1567
|
"data-mobile-form": I ? "true" : void 0,
|
|
1556
|
-
children: /* @__PURE__ */ W(s, { schema:
|
|
1568
|
+
children: /* @__PURE__ */ W(s, { schema: U })
|
|
1557
1569
|
});
|
|
1558
1570
|
}, xe = ({ config: e, dataSource: n, prefillParams: r, className: o }) => {
|
|
1559
1571
|
let [s, c] = a(!1), [l, u] = a(!1), [d, f] = a(null), p = i(() => {
|
|
@@ -2010,4 +2022,4 @@ o.register("object-form", we, {
|
|
|
2010
2022
|
]
|
|
2011
2023
|
});
|
|
2012
2024
|
//#endregion
|
|
2013
|
-
export { he as DrawerForm, xe as EmbeddableForm, Ce as FormAnalytics, K as FormSection, ve as ModalForm, ye as ObjectForm, Y as SplitForm, q as TabbedForm, J as WizardForm,
|
|
2025
|
+
export { he as DrawerForm, xe as EmbeddableForm, Ce as FormAnalytics, K as FormSection, ve as ModalForm, ye as ObjectForm, Y as SplitForm, q as TabbedForm, J as WizardForm, ae as applyAutoColSpan, $ as applyAutoLayout, le as filterAutoGeneratedFields, ce as filterCreateModeFields, se as filterSystemFields, ie as inferColumns, ue as inferModalSize, re as isAutoGeneratedFieldType, Q as isWideFieldType };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@object-ui/core`),require(`@object-ui/react`),require(`@object-ui/fields`),require(`@object-ui/components`),require(`@object-ui/permissions`),require(`lucide-react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`@object-ui/permissions`,`lucide-react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginForm={},e.React,e._object_ui_core,e._object_ui_react,e._object_ui_fields,e._object_ui_components,e._object_ui_permissions,e.lucide_react,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var g=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:o=1,children:l,className:u,gridClassName:d})=>{let[f,p]=(0,t.useState)(i);return(0,c.jsxs)(`div`,{className:(0,a.cn)(`form-section`,u),children:[(e||n)&&(0,c.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2 mb-4`,r&&`cursor-pointer select-none`),onClick:()=>{r&&p(!f)},role:r?`button`:void 0,"aria-expanded":r?!f:void 0,children:[r&&(0,c.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:f?(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4`}):(0,c.jsx)(s.ChevronDown,{className:`h-4 w-4`})}),(0,c.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,c.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}),!f&&(0,c.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,d||{1:`grid-cols-1`,2:`grid-cols-1 md:grid-cols-2`,3:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`,4:`grid-cols-1 md:grid-cols-2 lg:grid-cols-4`}[o]),children:l})]})},_=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,_]=(0,t.useState)(null),[v,y]=(0,t.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);t.default.useEffect(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){_(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){f(e.initialData||e.initialValues||{}),m(!1);return}try{f(await n.findOne(e.objectName,e.recordId)||{})}catch(e){_(e)}finally{m(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let b=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(l?.fields?.[t]){let r=l.fields[t];n.push({name:t,label:s(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode]),x=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;return e.mode===`create`?r=await n.create(e.objectName,t):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,t)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n]),S=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),C=(e,t)=>e.name||e.label||`tab-${t}`;if(h)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let w={type:`form`,fields:e.sections.flatMap(e=>b(e)),layout:`vertical`,defaultValues:d,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:x,onCancel:S},T=e.tabPosition===`left`||e.tabPosition===`right`;return(0,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,c.jsxs)(a.Tabs,{value:v,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,c.jsx)(a.TabsList,{className:(0,a.cn)(T?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,c.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,c.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,c.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,c.jsx)(g,{description:t.description,columns:t.columns||1,children:(0,c.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},v=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),[m,h]=(0,t.useState)(!0),[_,v]=(0,t.useState)(null),[y,b]=(0,t.useState)(0),[x,S]=(0,t.useState)(new Set),[C,w]=(0,t.useState)(!1),T=e.sections.length,E=y===0,D=y===T-1;t.default.useEffect(()=>{(async()=>{if(!n){h(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){v(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){p(e.initialData||e.initialValues||{}),h(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{h(!1)}})()},[u,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let O=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(u?.fields?.[t]){let r=u.fields[t];n.push({name:t,label:l(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[u,e.readOnly,e.mode]),k=(0,t.useMemo)(()=>y>=0&&y<T?O(e.sections[y]):[],[y,T,e.sections,O]),A=(0,t.useCallback)(async t=>{let r={...f,...t};if(p(r),S(e=>new Set(e).add(y)),D){w(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(r),r;let t;return e.mode===`create`?t=await n.create(e.objectName,r):e.mode===`edit`&&e.recordId&&(t=await n.update(e.objectName,e.recordId,r)),e.onSuccess&&await e.onSuccess(t),t}catch(t){throw e.onError&&e.onError(t),t}finally{w(!1)}}else j(y+1)},[f,y,D,e,n]),j=(0,t.useCallback)(t=>{t>=0&&t<T&&(b(t),e.onStepChange&&e.onStepChange(t))},[T,e]),M=(0,t.useCallback)(()=>{j(y-1)},[y,j]),N=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),P=(0,t.useCallback)(t=>{(e.allowSkip||x.has(t)||t<=y)&&j(t)},[e.allowSkip,x,y,j]);if(_)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,c.jsxs)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:[e.showStepIndicator!==!1&&(0,c.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,c.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),o=e.allowSkip||i||n<=y;return(0,c.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,c.jsx)(`div`,{className:`absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5`,"aria-hidden":`true`,children:(0,c.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,c.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,o?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!o,children:[(0,c.jsx)(`span`,{className:(0,a.cn)(`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`),children:i?(0,c.jsx)(s.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,c.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,c.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,c.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,c.jsx)(g,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:f,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,c.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,c.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,c.jsx)(`div`,{children:e.showCancel!==!1&&(0,c.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,c.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,c.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,c.jsx)(s.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,c.jsx)(a.Button,{onClick:()=>A(f),disabled:C||e.mode===`view`,children:C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,c.jsxs)(a.Button,{onClick:()=>A(f),children:[e.nextText||`Next`,(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},y=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,_]=(0,t.useState)(null);(0,t.useEffect)(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){_(e),m(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){f(e.initialData||e.initialValues||{}),m(!1);return}if(!n){f(e.initialData||e.initialValues||{}),m(!1);return}try{f(await n.findOne(e.objectName,e.recordId)||{})}catch(e){_(e)}finally{m(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let v=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(l?.fields?.[t]){let r=l.fields[t];n.push({name:t,label:s(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode]),y=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;return e.mode===`create`?r=await n.create(e.objectName,t):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,t)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n]),b=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),x=(0,t.useMemo)(()=>e.sections.slice(0,1),[e.sections]),S=(0,t.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,t.useMemo)(()=>e.sections.flatMap(e=>v(e)),[e.sections,v]);let C=e.splitDirection||`horizontal`,w=e.splitSize||50;if(h)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let T={type:`form`,layout:`vertical`,defaultValues:d,onSubmit:y,onCancel:b},E=(t,n)=>(0,c.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,c.jsx)(g,{label:t.label,description:t.description,columns:t.columns||1,children:(0,c.jsx)(r.SchemaRenderer,{schema:{...T,fields:v(t),showSubmit:n&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText}})},t.name||t.label||i))});return(0,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,c.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,c.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,c.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},b=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),x=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),S=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function C(e){return x.has(e)}function w(e){return S.has(e)}function T(e){return e<=3?1:2}function E(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&C(e.type)?{...e,colSpan:t}:e)}var D=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`last_modified_at`,`lastModifiedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`last_modified_by`,`lastModifiedBy`,`organization_id`,`organizationId`,`org_id`,`orgId`,`tenant_id`,`tenantId`,`owner`,`owner_id`,`_version`,`_rev`]);function O(e,t){return e.filter(e=>!(D.has(e.name)||t?.fields?.[e.name]?.readonly===!0))}function k(e,t){return e.filter(e=>{if(D.has(e.name)||e.type&&b.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!w(n.type):!0})}function A(e,t){return e.filter(e=>{if(e.type&&b.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!w(n.type):!0})}function j(e){return e<=1?`default`:e===2?`xl`:`full`}function M(e,t,n,r){let i=[...e];if(i=O(i,t),r===`create`&&(i=A(i,t)),n!==void 0)return i=E(i,n),{fields:i,columns:n};let a=T(i.length);return i=E(i,a),{fields:i,columns:a}}var N=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),P=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function F(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!N.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(P.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var I={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},L=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)([]),[p,m]=(0,t.useState)({}),[h,g]=(0,t.useState)(!0),[_,v]=(0,t.useState)(null),y=e.open!==!1,b=e.drawerSide||`right`,[x,S]=(0,t.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,t.useEffect)(()=>{(async()=>{if(!n){g(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){v(e),g(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){m(e.initialData||e.initialValues||{}),g(!1);return}if(!n){m(e.initialData||e.initialValues||{}),g(!1);return}try{m(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{g(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let C=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(l?.fields?.[t]){let r=l.fields[t];n.push({name:t,label:s(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode]);(0,t.useEffect)(()=>{if(!l&&n)return;if(e.customFields?.length){f(e.customFields),g(!1);return}if(e.sections?.length){g(!1);return}if(!l)return;let t=e.fields||Object.keys(l.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=l.fields?.[t];a&&r.push({name:t,label:s(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple})}f(r),g(!1)},[l,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let w=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;try{let r,i=F(t,l);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}catch(t){throw e.onError&&e.onError(t),t}},[e,n,l]),T=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),E=(0,t.useMemo)(()=>{if(e.drawerWidth)return b===`left`||b===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,b]),D={type:`form`,layout:e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,defaultValues:p,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:w,onCancel:T};return(0,c.jsx)(a.Sheet,{open:y,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.SheetContent,{side:b,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:E,children:[(e.title||e.description)&&(0,c.jsxs)(a.SheetHeader,{children:[e.title&&(0,c.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,c.jsx)(a.SheetDescription,{children:e.description})]}),(0,c.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(_)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length){let t=[];return e.sections.forEach((e,n)=>{let r=e.name||String(n),i=x[r]??e.collapsed??!1;t.push({name:`__section_${r}`,label:e.label||``,type:`section-divider`,colSpan:4,collapsible:e.collapsible,collapsed:i,onToggle:e.collapsible?()=>S(e=>({...e,[r]:!i})):void 0});let a=C(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,c.jsx)(r.SchemaRenderer,{schema:{...D,fields:t}})}let t=M(d,l,e.columns,e.mode),n=I[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...D,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},R={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},z={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},B=({schema:e,dataSource:n,className:l})=>{let{fieldLabel:u}=(0,r.useSafeFieldLabel)(),d=(0,o.usePermissions)(),f=(0,t.useCallback)(t=>{if(!d?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}d.checkField(e.objectName,r.name,`read`)&&(!d.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[d,e.objectName,e.mode]),[p,m]=(0,t.useState)(null),[h,_]=(0,t.useState)([]),[v,y]=(0,t.useState)({}),[b,x]=(0,t.useState)(!0),[S,C]=(0,t.useState)(null),[w,T]=(0,t.useState)(!1),E=e.open!==!1,D=(0,t.useId)(),O=(0,t.useMemo)(()=>e.sections?.length||e.customFields?.length?null:M(h,p,e.columns,e.mode),[h,p,e.columns,e.mode,e.sections,e.customFields]),k=R[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(O?.columns&&O.columns>1)return j(O.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return j(t)}return`default`},[e.modalSize,O,e.sections])]||R.default;(0,t.useEffect)(()=>{(async()=>{if(!n){x(!1);return}try{m(await n.getObjectSchema(e.objectName))}catch(e){C(e),x(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(p||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){y(e.initialData||e.initialValues||{}),x(!1);return}if(!n){y(e.initialData||e.initialValues||{}),x(!1);return}try{y(await n.findOne(e.objectName,e.recordId)||{})}catch(e){C(e)}finally{x(!1)}})()},[p,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let A=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(p?.fields?.[t]){let r=p.fields[t];n.push({name:t,label:u(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[p,e.readOnly,e.mode]);(0,t.useEffect)(()=>{if(!p&&n)return;if(e.customFields?.length){_(e.customFields),x(!1);return}if(e.sections?.length){x(!1);return}if(!p)return;let t=e.fields||Object.keys(p.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=p.fields?.[t];a&&r.push({name:t,label:u(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple})}_(r),x(!1)},[p,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let N=(0,t.useCallback)(async t=>{T(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=F(t,p);if(d?.isLoaded){let t={};for(let n of Object.keys(i))d.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}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}catch(t){throw e.onError&&e.onError(t),t}finally{T(!1)}},[e,n,p,d]),P=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),I=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,L=e.showSubmit!==!1&&e.mode!==`view`,B=e.showCancel!==!1,V=e.submitText||(e.mode===`create`?`Create`:`Update`),H=e.cancelText||`Cancel`,U={type:`form`,layout:I,defaultValues:v,submitLabel:V,cancelLabel:H,showSubmit:L,showCancel:B,onSubmit:N,onCancel:P,showActions:!1,id:D},W=()=>{if(S)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:S.message})]});if(b)return(0,c.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,c.jsxs)(`div`,{className:`space-y-2`,children:[(0,c.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,c.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,c.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,c.jsx)(g,{label:e.label,description:e.description,columns:n,gridClassName:z[n],children:(0,c.jsx)(r.SchemaRenderer,{schema:{...U,fields:f(A(e))}})},e.name||e.label||t)})});let t=O??M(h,p,e.columns,e.mode),n=z[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...U,fields:f(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},G=!b&&!S&&(L||B);return(0,c.jsx)(a.Dialog,{open:E,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(k,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,l,e.className),children:[(e.title||e.description)&&(0,c.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,c.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,c.jsx)(a.DialogDescription,{children:e.description})]}),(0,c.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:W()}),G&&(0,c.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,c.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[B&&(0,c.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:P,disabled:w,className:`w-full sm:w-auto`,children:H}),L&&(0,c.jsxs)(a.Button,{type:`submit`,form:D,disabled:w,className:`w-full sm:w-auto`,children:[w&&(0,c.jsx)(s.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),V]})]})})]})})},V=({schema:e,dataSource:n})=>{let i=(0,o.usePermissions)(),a=(0,t.useMemo)(()=>{if(!i?.isLoaded)return e;let t=t=>t?.name?i.checkField(e.objectName,t.name,`read`)?!i.checkField(e.objectName,t.name,`write`)&&e.mode!==`view`?{...t,readOnly:!0,disabled:!0}:t:null:t,n=e=>Array.isArray(e)?e.map(t).filter(Boolean):e;return{...e,fields:n(e.fields),sections:e.sections?.map(e=>({...e,fields:n(e.fields)}))}},[e,i]),{sectionLabel:s}=(0,r.useSafeFieldLabel)(),l=e=>e?.name?s(a.objectName,e.name,e.label||e.name):e?.label;if(a.formType===`tabbed`&&a.sections?.length)return(0,c.jsx)(_,{schema:{...a,formType:`tabbed`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),defaultTab:a.defaultTab,tabPosition:a.tabPosition},dataSource:n,className:a.className});if(a.formType===`wizard`&&a.sections?.length)return(0,c.jsx)(v,{schema:{...a,formType:`wizard`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),allowSkip:a.allowSkip,showStepIndicator:a.showStepIndicator,nextText:a.nextText,prevText:a.prevText,onStepChange:a.onStepChange},dataSource:n,className:a.className});if(a.formType===`split`&&a.sections?.length)return(0,c.jsx)(y,{schema:{...a,formType:`split`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),splitDirection:a.splitDirection,splitSize:a.splitSize,splitResizable:a.splitResizable},dataSource:n,className:a.className});if(a.formType===`drawer`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,c.jsx)(L,{schema:{...t,layout:r,formType:`drawer`,sections:a.sections?.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:a.open,onOpenChange:a.onOpenChange,drawerSide:a.drawerSide,drawerWidth:a.drawerWidth},dataSource:n,className:a.className})}if(a.formType===`modal`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,c.jsx)(B,{schema:{...t,layout:r,formType:`modal`,sections:a.sections?.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),open:a.open,onOpenChange:a.onOpenChange,modalSize:a.modalSize,modalCloseButton:a.modalCloseButton},dataSource:n,className:a.className})}return(0,c.jsx)(H,{schema:a,dataSource:n})},H=({schema:e,dataSource:n})=>{let{fieldLabel:s,sectionLabel:l}=(0,r.useSafeFieldLabel)(),u=(0,a.useIsMobile)(),d=(0,o.usePermissions)(),f=(0,t.useCallback)(t=>{if(!d?.isLoaded)return t;let n=[];for(let r of t)d.checkField(e.objectName,r.name,`read`)&&(!d.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0,description:r.description??`You do not have edit access to this field.`}):n.push(r));return n},[d,e.objectName,e.mode]),[p,m]=(0,t.useState)(null),[h,_]=(0,t.useState)([]),[y,b]=(0,t.useState)(null),[x,S]=(0,t.useState)(!0),[C,w]=(0,t.useState)(null),T=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{T&&(b(e.initialData||e.initialValues||{}),S(!1))},[T,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{T?m({name:e.objectName,fields:{}}):e.objectName&&n?(async()=>{try{if(!n)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let t=await n.getObjectSchema(e.objectName);if(!t)throw Error(`No schema found for object "${e.objectName}"`);m(t)}catch(e){w(e),S(!1)}})():T||S(!1)},[e.objectName,n,T]),(0,t.useEffect)(()=>{p&&!T&&(async()=>{if(!e.recordId||e.mode===`create`){b(e.initialData||e.initialValues||{}),S(!1);return}if(!T){if(!n){w(Error(`DataSource is required for fetching record data (inline data not provided)`)),S(!1);return}S(!0);try{b(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),w(e)}finally{S(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,p,T]);let E=(0,t.useCallback)(e=>{if(!e||typeof e.visible==`function`)return e;let t=e.visibleOn;return typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e},[]);(0,t.useEffect)(()=>{if(T&&e.customFields){_(e.customFields.map(E)),S(!1);return}if(!p)return;let t=[],r=e.fields||Object.keys(p.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let a=p.fields?.[r];if(!a&&!T)return;let o=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!o)return;let c=e.customFields?.find(e=>e.name===r);if(c)t.push(E(c));else if(a){let o={name:r,label:s(e.objectName,r,a.label||n),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly||p?.managedBy&&p.managedBy!==`platform`,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a};if((a.type===`select`||a.type===`lookup`||a.type===`master_detail`)&&(o.options=a.options||[],o.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(o.inputType=`number`,o.min=a.min,o.max=a.max,o.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(o.inputType=`date`),a.type===`datetime`&&(o.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(o.maxLength=a.max_length,o.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(o.inputType=`file`,o.multiple=a.multiple,o.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${(0,i.formatFileSize)(a.max_size)}`;o.description=o.description?`${o.description} (${e})`:e}a.type===`email`&&(o.inputType=`email`),a.type===`phone`&&(o.inputType=`tel`),a.type===`url`&&(o.inputType=`url`),a.type===`password`&&(o.inputType=`password`),a.type===`time`&&(o.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(o.disabled=!0),a.visible_on&&(o.visible=e=>(0,i.evaluateCondition)(a.visible_on,e)),t.push(o)}}),_(t),!T&&e.recordId&&e.mode!==`create`&&n||S(!1)},[p,e.fields,e.customFields,e.readOnly,e.mode,T,e.recordId,n]);let D=(0,t.useCallback)(async(t,r)=>{if(t&&(t.nativeEvent||t._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),r===void 0&&(r=t,t={})),T&&!n)return e.onSuccess&&await e.onSuccess(t),t;if(!n)throw Error(`DataSource is required for form submission (inline mode not configured)`);let i=t;if(d?.isLoaded&&t&&typeof t==`object`){i={};for(let n of Object.keys(t))d.checkField(e.objectName,n,`write`)&&(i[n]=t[n])}try{let t;if(e.mode===`create`)t=await n.create(e.objectName,i);else if(e.mode===`edit`&&e.recordId)t=await n.update(e.objectName,e.recordId,i);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(t),t}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,n,T,d]),O=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),k={...t.default.useMemo(()=>{if(!p?.fields)return{};let e={};return Object.keys(p.fields).forEach(t=>{let n=p.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[p]),...y};if(C)return(0,c.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:C.message})]});if(x)return(0,c.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let A=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,c.jsx)(`div`,{className:`w-full space-y-6`,children:e.sections.map((t,n)=>{let i=t.fields.map(e=>typeof e==`string`?e:e.name),a=f(h.filter(e=>i.includes(e.name)));return(0,c.jsx)(g,{label:t.name?l(e.objectName,t.name,t.label||t.name):t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:A,defaultValues:k,showSubmit:n===e.sections.length-1&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n===e.sections.length-1&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:D,onCancel:O}})},t.name||t.label||n)})});let j=e.sections?.length,N=f(h),P=j?{fields:N,columns:e.columns}:M(N,p,e.columns,e.mode),F=e.mobile,I=F?.fullscreenLongText?P.fields.map(e=>{let t=e.type;return t===`textarea`||t===`field:textarea`||t===`string-multiline`||t===`field:markdown`||t===`field:html`?{...e,mobile_fullscreen:!0}:e}):P.fields,L=F?.stepper,R=F?.stepperMinFields??8,z=Math.max(1,F?.stepperFieldsPerStep??1);if(!e.formType&&!j&&I.length>=2&&(L===!0||L===`auto`&&u&&I.length>=R)){let t=I,r=[];for(let e=0;e<t.length;e+=z){let n=t.slice(e,e+z);r.push({name:`step-${Math.floor(e/z)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/z)+1}`,fields:n})}return(0,c.jsx)(v,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let B={type:`form`,fields:I,layout:A,columns:P.columns,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset,defaultValues:k,onSubmit:D,onCancel:O,className:e.className,mobileStickyActions:!!F?.stickyActions};return(0,c.jsx)(`div`,{className:F?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":F?`true`:void 0,children:(0,c.jsx)(r.SchemaRenderer,{schema:B})})},U=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[a,o]=(0,t.useState)(!1),[s,l]=(0,t.useState)(!1),[u,d]=(0,t.useState)(null),f=(0,t.useMemo)(()=>{let e={};if(r)for(let[t,n]of Object.entries(r))e[t]=n;return typeof window<`u`&&new URLSearchParams(window.location.search).forEach((t,n)=>{n in e||(e[n]=t)}),Object.keys(e).length>0?e:void 0},[r]),p=(0,t.useCallback)(async t=>{l(!0),d(null);try{if(n&&await n.create(e.objectName,t),o(!0),e.thankYouPage?.redirectUrl){let t=e.thankYouPage.redirectDelay??3e3;setTimeout(()=>{window.location.href=e.thankYouPage.redirectUrl},t)}}catch(e){d(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{l(!1)}},[n,e]),m=(0,t.useCallback)(()=>{o(!1),d(null)},[]),h=(0,t.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(a){let t=e.thankYouPage;return(0,c.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,c.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,c.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,c.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,c.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,c.jsx)(`button`,{onClick:m,className:`mt-4 px-4 py-2 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors`,children:`Submit Another Response`}),t?.redirectUrl&&(0,c.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,c.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,c.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,c.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,c.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,c.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,c.jsxs)(`div`,{className:`p-6`,children:[u&&(0,c.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:u}),(0,c.jsx)(V,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:f,onSuccess:p,submitLabel:s?`Submitting...`:`Submit`},dataSource:n})]}),(0,c.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function W(e){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`}var G=({formId:e,formTitle:n,metrics:r,className:i})=>{let o=(0,t.useMemo)(()=>{if(!r.abandonedSubmissions)return 100;let e=r.totalSubmissions+r.abandonedSubmissions;return e===0?0:Math.round(r.totalSubmissions/e*100)},[r.totalSubmissions,r.abandonedSubmissions]),s=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,c.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,c.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,c.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,c.jsx)(a.Card,{children:(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,c.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,c.jsxs)(a.Card,{children:[(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,c.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,c.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,c.jsx)(a.Card,{children:(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,c.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?W(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,c.jsxs)(a.Card,{children:[(0,c.jsx)(a.CardHeader,{children:(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,c.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,c.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/s*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,c.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),r.fieldDropOff&&r.fieldDropOff.length>0&&(0,c.jsxs)(a.Card,{children:[(0,c.jsxs)(a.CardHeader,{children:[(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,c.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,c.jsxs)(`div`,{className:`space-y-1`,children:[(0,c.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,c.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,c.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,c.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,c.jsx)(`div`,{className:`rounded-full h-1.5 transition-all ${e.completionRate>=80?`bg-green-500`:e.completionRate>=50?`bg-yellow-500`:`bg-destructive`}`,style:{width:`${e.completionRate}%`}})})]},t))})})]})]})},K=({schema:e})=>(0,c.jsx)(V,{schema:e});n.ComponentRegistry.register(`object-form`,K,{namespace:`plugin-form`,label:`Object Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]},{name:`formType`,type:`enum`,label:`Form Type`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]},{name:`sections`,type:`array`,label:`Sections`},{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`vertical`,`horizontal`,`inline`,`grid`]},{name:`columns`,type:`number`,label:`Columns`},{name:`defaultTab`,type:`string`,label:`Default Tab`},{name:`tabPosition`,type:`enum`,label:`Tab Position`,enum:[`top`,`bottom`,`left`,`right`]},{name:`allowSkip`,type:`boolean`,label:`Allow Skip Steps`},{name:`showStepIndicator`,type:`boolean`,label:`Show Step Indicator`},{name:`splitDirection`,type:`enum`,label:`Split Direction`,enum:[`horizontal`,`vertical`]},{name:`splitSize`,type:`number`,label:`Split Panel Size (%)`},{name:`splitResizable`,type:`boolean`,label:`Split Resizable`},{name:`drawerSide`,type:`enum`,label:`Drawer Side`,enum:[`top`,`bottom`,`left`,`right`]},{name:`drawerWidth`,type:`string`,label:`Drawer Width`},{name:`modalSize`,type:`enum`,label:`Modal Size`,enum:[`sm`,`default`,`lg`,`xl`,`full`]}]}),n.ComponentRegistry.register(`form`,K,{namespace:`view`,skipFallback:!0,label:`Data Form View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]}]}),n.ComponentRegistry.register(`embeddable-form`,({schema:e})=>(0,c.jsx)(U,{config:e}),{namespace:`plugin-form`,label:`Embeddable Form`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Form Title`},{name:`description`,type:`string`,label:`Description`},{name:`fields`,type:`array`,label:`Fields`},{name:`allowMultiple`,type:`boolean`,label:`Allow Multiple Submissions`}]}),n.ComponentRegistry.register(`form-analytics`,({schema:e})=>(0,c.jsx)(G,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}}),{namespace:`plugin-form`,label:`Form Analytics`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`formTitle`,type:`string`,label:`Form Title`},{name:`metrics`,type:`object`,label:`Submission Metrics`}]}),e.DrawerForm=L,e.EmbeddableForm=U,e.FormAnalytics=G,e.FormSection=g,e.ModalForm=B,e.ObjectForm=V,e.SplitForm=y,e.TabbedForm=_,e.WizardForm=v,e.applyAutoColSpan=E,e.applyAutoLayout=M,e.filterAutoGeneratedFields=A,e.filterCreateModeFields=k,e.filterSystemFields=O,e.inferColumns=T,e.inferModalSize=j,e.isAutoGeneratedFieldType=w,e.isWideFieldType=C});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@object-ui/core`),require(`@object-ui/react`),require(`@object-ui/fields`),require(`@object-ui/components`),require(`@object-ui/permissions`),require(`lucide-react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`@object-ui/permissions`,`lucide-react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginForm={},e.React,e._object_ui_core,e._object_ui_react,e._object_ui_fields,e._object_ui_components,e._object_ui_permissions,e.lucide_react,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var g=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:o=1,children:l,className:u,gridClassName:d})=>{let[f,p]=(0,t.useState)(i);return(0,c.jsxs)(`div`,{className:(0,a.cn)(`form-section`,u),children:[(e||n)&&(0,c.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2 mb-4`,r&&`cursor-pointer select-none`),onClick:()=>{r&&p(!f)},role:r?`button`:void 0,"aria-expanded":r?!f:void 0,children:[r&&(0,c.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:f?(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4`}):(0,c.jsx)(s.ChevronDown,{className:`h-4 w-4`})}),(0,c.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,c.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}),!f&&(0,c.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,d||{1:`grid-cols-1`,2:`grid-cols-1 md:grid-cols-2`,3:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`,4:`grid-cols-1 md:grid-cols-2 lg:grid-cols-4`}[o]),children:l})]})},_=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,_]=(0,t.useState)(null),[v,y]=(0,t.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);t.default.useEffect(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){_(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){f(e.initialData||e.initialValues||{}),m(!1);return}try{f(await n.findOne(e.objectName,e.recordId)||{})}catch(e){_(e)}finally{m(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let b=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(l?.fields?.[t]){let r=l.fields[t];n.push({name:t,label:s(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode]),x=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;return e.mode===`create`?r=await n.create(e.objectName,t):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,t)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n]),S=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),C=(e,t)=>e.name||e.label||`tab-${t}`;if(h)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let w={type:`form`,fields:e.sections.flatMap(e=>b(e)),layout:`vertical`,defaultValues:d,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:x,onCancel:S},T=e.tabPosition===`left`||e.tabPosition===`right`;return(0,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,c.jsxs)(a.Tabs,{value:v,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,c.jsx)(a.TabsList,{className:(0,a.cn)(T?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,c.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,c.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,c.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,c.jsx)(g,{description:t.description,columns:t.columns||1,children:(0,c.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},v=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),[m,h]=(0,t.useState)(!0),[_,v]=(0,t.useState)(null),[y,b]=(0,t.useState)(0),[x,S]=(0,t.useState)(new Set),[C,w]=(0,t.useState)(!1),T=e.sections.length,E=y===0,D=y===T-1;t.default.useEffect(()=>{(async()=>{if(!n){h(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){v(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){p(e.initialData||e.initialValues||{}),h(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{h(!1)}})()},[u,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let O=(0,t.useCallback)(t=>{let n=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(u?.fields?.[t]){let a=u.fields[t];n.push(r({name:t,label:l(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[u,e.readOnly,e.mode,e.objectName]),k=(0,t.useMemo)(()=>y>=0&&y<T?O(e.sections[y]):[],[y,T,e.sections,O]),A=(0,t.useCallback)(async t=>{let r={...f,...t};if(p(r),S(e=>new Set(e).add(y)),D){w(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(r),r;let t;return e.mode===`create`?t=await n.create(e.objectName,r):e.mode===`edit`&&e.recordId&&(t=await n.update(e.objectName,e.recordId,r)),e.onSuccess&&await e.onSuccess(t),t}catch(t){throw e.onError&&e.onError(t),t}finally{w(!1)}}else j(y+1)},[f,y,D,e,n]),j=(0,t.useCallback)(t=>{t>=0&&t<T&&(b(t),e.onStepChange&&e.onStepChange(t))},[T,e]),M=(0,t.useCallback)(()=>{j(y-1)},[y,j]),N=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),P=(0,t.useCallback)(t=>{(e.allowSkip||x.has(t)||t<=y)&&j(t)},[e.allowSkip,x,y,j]);if(_)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,c.jsxs)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:[e.showStepIndicator!==!1&&(0,c.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,c.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),o=e.allowSkip||i||n<=y;return(0,c.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,c.jsx)(`div`,{className:`absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5`,"aria-hidden":`true`,children:(0,c.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,c.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,o?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!o,children:[(0,c.jsx)(`span`,{className:(0,a.cn)(`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`),children:i?(0,c.jsx)(s.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,c.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,c.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,c.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,c.jsx)(g,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:f,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,c.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,c.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,c.jsx)(`div`,{children:e.showCancel!==!1&&(0,c.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,c.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,c.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,c.jsx)(s.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,c.jsx)(a.Button,{onClick:()=>A(f),disabled:C||e.mode===`view`,children:C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,c.jsxs)(a.Button,{onClick:()=>A(f),children:[e.nextText||`Next`,(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},y=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,_]=(0,t.useState)(null);(0,t.useEffect)(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){_(e),m(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){f(e.initialData||e.initialValues||{}),m(!1);return}if(!n){f(e.initialData||e.initialValues||{}),m(!1);return}try{f(await n.findOne(e.objectName,e.recordId)||{})}catch(e){_(e)}finally{m(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let v=(0,t.useCallback)(t=>{let n=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(l?.fields?.[t]){let a=l.fields[t];n.push(r({name:t,label:s(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode,e.objectName]),y=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;return e.mode===`create`?r=await n.create(e.objectName,t):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,t)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n]),b=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),x=(0,t.useMemo)(()=>e.sections.slice(0,1),[e.sections]),S=(0,t.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,t.useMemo)(()=>e.sections.flatMap(e=>v(e)),[e.sections,v]);let C=e.splitDirection||`horizontal`,w=e.splitSize||50;if(h)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let T={type:`form`,layout:`vertical`,defaultValues:d,onSubmit:y,onCancel:b},E=(t,n)=>(0,c.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,c.jsx)(g,{label:t.label,description:t.description,columns:t.columns||1,children:(0,c.jsx)(r.SchemaRenderer,{schema:{...T,fields:v(t),showSubmit:n&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText}})},t.name||t.label||i))});return(0,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,c.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,c.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,c.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},b=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),x=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),S=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function C(e){return x.has(e)}function w(e){return S.has(e)}function T(e){return e<=3?1:2}function E(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&C(e.type)?{...e,colSpan:t}:e)}var D=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`last_modified_at`,`lastModifiedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`last_modified_by`,`lastModifiedBy`,`organization_id`,`organizationId`,`org_id`,`orgId`,`tenant_id`,`tenantId`,`owner`,`owner_id`,`_version`,`_rev`]);function O(e,t){return e.filter(e=>!(D.has(e.name)||t?.fields?.[e.name]?.readonly===!0))}function k(e,t){return e.filter(e=>{if(D.has(e.name)||e.type&&b.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!w(n.type):!0})}function A(e,t){return e.filter(e=>{if(e.type&&b.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!w(n.type):!0})}function j(e){return e<=1?`default`:e===2?`xl`:`full`}function M(e,t,n,r){let i=[...e];if(i=O(i,t),r===`create`&&(i=A(i,t)),n!==void 0)return i=E(i,n),{fields:i,columns:n};let a=T(i.length);return i=E(i,a),{fields:i,columns:a}}var N=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),P=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function F(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!N.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(P.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var I={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},L=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)([]),[p,m]=(0,t.useState)({}),[h,g]=(0,t.useState)(!0),[_,v]=(0,t.useState)(null),y=e.open!==!1,b=e.drawerSide||`right`,[x,S]=(0,t.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,t.useEffect)(()=>{(async()=>{if(!n){g(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){v(e),g(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){m(e.initialData||e.initialValues||{}),g(!1);return}if(!n){m(e.initialData||e.initialValues||{}),g(!1);return}try{m(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{g(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let C=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(l?.fields?.[t]){let r=l.fields[t];n.push({name:t,label:s(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode]);(0,t.useEffect)(()=>{if(!l&&n)return;if(e.customFields?.length){f(e.customFields),g(!1);return}if(e.sections?.length){g(!1);return}if(!l)return;let t=e.fields||Object.keys(l.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=l.fields?.[t];a&&r.push({name:t,label:s(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple})}f(r),g(!1)},[l,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let w=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;try{let r,i=F(t,l);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}catch(t){throw e.onError&&e.onError(t),t}},[e,n,l]),T=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),E=(0,t.useMemo)(()=>{if(e.drawerWidth)return b===`left`||b===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,b]),D={type:`form`,layout:e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,defaultValues:p,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:w,onCancel:T};return(0,c.jsx)(a.Sheet,{open:y,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.SheetContent,{side:b,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:E,children:[(e.title||e.description)&&(0,c.jsxs)(a.SheetHeader,{children:[e.title&&(0,c.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,c.jsx)(a.SheetDescription,{children:e.description})]}),(0,c.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(_)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length){let t=[];return e.sections.forEach((e,n)=>{let r=e.name||String(n),i=x[r]??e.collapsed??!1;t.push({name:`__section_${r}`,label:e.label||``,type:`section-divider`,colSpan:4,collapsible:e.collapsible,collapsed:i,onToggle:e.collapsible?()=>S(e=>({...e,[r]:!i})):void 0});let a=C(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,c.jsx)(r.SchemaRenderer,{schema:{...D,fields:t}})}let t=M(d,l,e.columns,e.mode),n=I[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...D,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},R={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},z={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},B=({schema:e,dataSource:n,className:l})=>{let{fieldLabel:u}=(0,r.useSafeFieldLabel)(),d=(0,o.usePermissions)(),f=(0,t.useCallback)(t=>{if(!d?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}d.checkField(e.objectName,r.name,`read`)&&(!d.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[d,e.objectName,e.mode]),[p,m]=(0,t.useState)(null),[h,_]=(0,t.useState)([]),[v,y]=(0,t.useState)({}),[b,x]=(0,t.useState)(!0),[S,C]=(0,t.useState)(null),[w,T]=(0,t.useState)(!1),E=e.open!==!1,D=(0,t.useId)(),O=(0,t.useMemo)(()=>e.sections?.length||e.customFields?.length?null:M(h,p,e.columns,e.mode),[h,p,e.columns,e.mode,e.sections,e.customFields]),k=R[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(O?.columns&&O.columns>1)return j(O.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return j(t)}return`default`},[e.modalSize,O,e.sections])]||R.default;(0,t.useEffect)(()=>{(async()=>{if(!n){x(!1);return}try{m(await n.getObjectSchema(e.objectName))}catch(e){C(e),x(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(p||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){y(e.initialData||e.initialValues||{}),x(!1);return}if(!n){y(e.initialData||e.initialValues||{}),x(!1);return}try{y(await n.findOne(e.objectName,e.recordId)||{})}catch(e){C(e)}finally{x(!1)}})()},[p,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let A=(0,t.useCallback)(t=>{let n=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(p?.fields?.[t]){let a=p.fields[t];n.push(r({name:t,label:u(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[p,e.readOnly,e.mode,e.objectName]);(0,t.useEffect)(()=>{if(!p&&n)return;if(e.customFields?.length){_(e.customFields),x(!1);return}if(e.sections?.length){x(!1);return}if(!p)return;let t=e.fields||Object.keys(p.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=p.fields?.[t];a&&r.push({name:t,label:u(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple})}_(r),x(!1)},[p,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let N=(0,t.useCallback)(async t=>{T(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=F(t,p);if(d?.isLoaded){let t={};for(let n of Object.keys(i))d.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}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}catch(t){throw e.onError&&e.onError(t),t}finally{T(!1)}},[e,n,p,d]),P=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),I=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,L=e.showSubmit!==!1&&e.mode!==`view`,B=e.showCancel!==!1,V=e.submitText||(e.mode===`create`?`Create`:`Update`),H=e.cancelText||`Cancel`,U={type:`form`,layout:I,defaultValues:v,submitLabel:V,cancelLabel:H,showSubmit:L,showCancel:B,onSubmit:N,onCancel:P,showActions:!1,id:D},W=()=>{if(S)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:S.message})]});if(b)return(0,c.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,c.jsxs)(`div`,{className:`space-y-2`,children:[(0,c.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,c.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,c.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,c.jsx)(g,{label:e.label,description:e.description,columns:n,gridClassName:z[n],children:(0,c.jsx)(r.SchemaRenderer,{schema:{...U,fields:f(A(e))}})},e.name||e.label||t)})});let t=O??M(h,p,e.columns,e.mode),n=z[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...U,fields:f(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},G=!b&&!S&&(L||B);return(0,c.jsx)(a.Dialog,{open:E,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(k,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,l,e.className),children:[(e.title||e.description)&&(0,c.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,c.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,c.jsx)(a.DialogDescription,{children:e.description})]}),(0,c.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:W()}),G&&(0,c.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,c.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[B&&(0,c.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:P,disabled:w,className:`w-full sm:w-auto`,children:H}),L&&(0,c.jsxs)(a.Button,{type:`submit`,form:D,disabled:w,className:`w-full sm:w-auto`,children:[w&&(0,c.jsx)(s.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),V]})]})})]})})},V=({schema:e,dataSource:n})=>{let i=(0,o.usePermissions)(),a=(0,t.useMemo)(()=>{if(!i?.isLoaded)return e;let t=t=>t?.name?i.checkField(e.objectName,t.name,`read`)?!i.checkField(e.objectName,t.name,`write`)&&e.mode!==`view`?{...t,readOnly:!0,disabled:!0}:t:null:t,n=e=>Array.isArray(e)?e.map(t).filter(Boolean):e;return{...e,fields:n(e.fields),sections:e.sections?.map(e=>({...e,fields:n(e.fields)}))}},[e,i]),{sectionLabel:s}=(0,r.useSafeFieldLabel)(),l=e=>e?.name?s(a.objectName,e.name,e.label||e.name):e?.label;if(a.formType===`tabbed`&&a.sections?.length)return(0,c.jsx)(_,{schema:{...a,formType:`tabbed`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),defaultTab:a.defaultTab,tabPosition:a.tabPosition},dataSource:n,className:a.className});if(a.formType===`wizard`&&a.sections?.length)return(0,c.jsx)(v,{schema:{...a,formType:`wizard`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),allowSkip:a.allowSkip,showStepIndicator:a.showStepIndicator,nextText:a.nextText,prevText:a.prevText,onStepChange:a.onStepChange},dataSource:n,className:a.className});if(a.formType===`split`&&a.sections?.length)return(0,c.jsx)(y,{schema:{...a,formType:`split`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),splitDirection:a.splitDirection,splitSize:a.splitSize,splitResizable:a.splitResizable},dataSource:n,className:a.className});if(a.formType===`drawer`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,c.jsx)(L,{schema:{...t,layout:r,formType:`drawer`,sections:a.sections?.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:a.open,onOpenChange:a.onOpenChange,drawerSide:a.drawerSide,drawerWidth:a.drawerWidth},dataSource:n,className:a.className})}if(a.formType===`modal`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,c.jsx)(B,{schema:{...t,layout:r,formType:`modal`,sections:a.sections?.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),open:a.open,onOpenChange:a.onOpenChange,modalSize:a.modalSize,modalCloseButton:a.modalCloseButton},dataSource:n,className:a.className})}return(0,c.jsx)(H,{schema:a,dataSource:n})},H=({schema:e,dataSource:n})=>{let{fieldLabel:s,sectionLabel:l}=(0,r.useSafeFieldLabel)(),u=(0,a.useIsMobile)(),d=(0,o.usePermissions)(),f=(0,t.useCallback)(t=>{if(!d?.isLoaded)return t;let n=[];for(let r of t)d.checkField(e.objectName,r.name,`read`)&&(!d.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0,description:r.description??`You do not have edit access to this field.`}):n.push(r));return n},[d,e.objectName,e.mode]),[p,m]=(0,t.useState)(null),[h,_]=(0,t.useState)([]),[y,b]=(0,t.useState)(null),[x,S]=(0,t.useState)(!0),[C,w]=(0,t.useState)(null),T=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{T&&(b(e.initialData||e.initialValues||{}),S(!1))},[T,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{T?m({name:e.objectName,fields:{}}):e.objectName&&n?(async()=>{try{if(!n)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let t=await n.getObjectSchema(e.objectName);if(!t)throw Error(`No schema found for object "${e.objectName}"`);m(t)}catch(e){w(e),S(!1)}})():T||S(!1)},[e.objectName,n,T]),(0,t.useEffect)(()=>{p&&!T&&(async()=>{if(!e.recordId||e.mode===`create`){b(e.initialData||e.initialValues||{}),S(!1);return}if(!T){if(!n){w(Error(`DataSource is required for fetching record data (inline data not provided)`)),S(!1);return}S(!0);try{b(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),w(e)}finally{S(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,p,T]);let E=(0,t.useCallback)(e=>{if(!e||typeof e.visible==`function`)return e;let t=e.visibleOn;return typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e},[]);(0,t.useEffect)(()=>{if(T&&e.customFields){_(e.customFields.map(E)),S(!1);return}if(!p)return;let t=[],r=e.fields||Object.keys(p.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let a=p.fields?.[r];if(!a&&!T)return;let o=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!o)return;let c=e.customFields?.find(e=>e.name===r);if(c)t.push(E(c));else if(a){let o={name:r,label:s(e.objectName,r,a.label||n),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly||p?.managedBy&&p.managedBy!==`platform`,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a};if((a.type===`select`||a.type===`lookup`||a.type===`master_detail`)&&(o.options=a.options||[],o.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(o.inputType=`number`,o.min=a.min,o.max=a.max,o.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(o.inputType=`date`),a.type===`datetime`&&(o.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(o.maxLength=a.max_length,o.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(o.inputType=`file`,o.multiple=a.multiple,o.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${(0,i.formatFileSize)(a.max_size)}`;o.description=o.description?`${o.description} (${e})`:e}a.type===`email`&&(o.inputType=`email`),a.type===`phone`&&(o.inputType=`tel`),a.type===`url`&&(o.inputType=`url`),a.type===`password`&&(o.inputType=`password`),a.type===`time`&&(o.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(o.disabled=!0),a.visible_on&&(o.visible=e=>(0,i.evaluateCondition)(a.visible_on,e)),t.push(o)}}),_(t),!T&&e.recordId&&e.mode!==`create`&&n||S(!1)},[p,e.fields,e.customFields,e.readOnly,e.mode,T,e.recordId,n]);let D=(0,t.useCallback)(async(t,r)=>{if(t&&(t.nativeEvent||t._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),r===void 0&&(r=t,t={})),T&&!n)return e.onSuccess&&await e.onSuccess(t),t;if(!n)throw Error(`DataSource is required for form submission (inline mode not configured)`);let i=t;if(d?.isLoaded&&t&&typeof t==`object`){i={};for(let n of Object.keys(t))d.checkField(e.objectName,n,`write`)&&(i[n]=t[n])}try{let t;if(e.mode===`create`)t=await n.create(e.objectName,i);else if(e.mode===`edit`&&e.recordId)t=await n.update(e.objectName,e.recordId,i);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(t),t}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,n,T,d]),O=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),k={...t.default.useMemo(()=>{if(!p?.fields)return{};let e={};return Object.keys(p.fields).forEach(t=>{let n=p.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[p]),...y};if(C)return(0,c.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:C.message})]});if(x)return(0,c.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let A=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,c.jsx)(`div`,{className:`w-full space-y-6`,children:e.sections.map((t,n)=>{let i=t.fields.map(e=>typeof e==`string`?e:e.name),a=f(h.filter(e=>i.includes(e.name)));return(0,c.jsx)(g,{label:t.name?l(e.objectName,t.name,t.label||t.name):t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:A,defaultValues:k,showSubmit:n===e.sections.length-1&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n===e.sections.length-1&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:D,onCancel:O}})},t.name||t.label||n)})});let j=e.sections?.length,N=f(h),P=j?{fields:N,columns:e.columns}:M(N,p,e.columns,e.mode),F=e.mobile,I=F?.fullscreenLongText?P.fields.map(e=>{let t=e.type;return t===`textarea`||t===`field:textarea`||t===`string-multiline`||t===`field:markdown`||t===`field:html`?{...e,mobile_fullscreen:!0}:e}):P.fields,L=F?.stepper,R=F?.stepperMinFields??8,z=Math.max(1,F?.stepperFieldsPerStep??1);if(!e.formType&&!j&&I.length>=2&&(L===!0||L===`auto`&&u&&I.length>=R)){let t=I,r=[];for(let e=0;e<t.length;e+=z){let n=t.slice(e,e+z);r.push({name:`step-${Math.floor(e/z)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/z)+1}`,fields:n})}return(0,c.jsx)(v,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let B={type:`form`,fields:I,layout:A,columns:P.columns,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset,defaultValues:k,onSubmit:D,onCancel:O,className:e.className,mobileStickyActions:!!F?.stickyActions};return(0,c.jsx)(`div`,{className:F?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":F?`true`:void 0,children:(0,c.jsx)(r.SchemaRenderer,{schema:B})})},U=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[a,o]=(0,t.useState)(!1),[s,l]=(0,t.useState)(!1),[u,d]=(0,t.useState)(null),f=(0,t.useMemo)(()=>{let e={};if(r)for(let[t,n]of Object.entries(r))e[t]=n;return typeof window<`u`&&new URLSearchParams(window.location.search).forEach((t,n)=>{n in e||(e[n]=t)}),Object.keys(e).length>0?e:void 0},[r]),p=(0,t.useCallback)(async t=>{l(!0),d(null);try{if(n&&await n.create(e.objectName,t),o(!0),e.thankYouPage?.redirectUrl){let t=e.thankYouPage.redirectDelay??3e3;setTimeout(()=>{window.location.href=e.thankYouPage.redirectUrl},t)}}catch(e){d(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{l(!1)}},[n,e]),m=(0,t.useCallback)(()=>{o(!1),d(null)},[]),h=(0,t.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(a){let t=e.thankYouPage;return(0,c.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,c.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,c.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,c.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,c.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,c.jsx)(`button`,{onClick:m,className:`mt-4 px-4 py-2 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors`,children:`Submit Another Response`}),t?.redirectUrl&&(0,c.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,c.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,c.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,c.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,c.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,c.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,c.jsxs)(`div`,{className:`p-6`,children:[u&&(0,c.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:u}),(0,c.jsx)(V,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:f,onSuccess:p,submitLabel:s?`Submitting...`:`Submit`},dataSource:n})]}),(0,c.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function W(e){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`}var G=({formId:e,formTitle:n,metrics:r,className:i})=>{let o=(0,t.useMemo)(()=>{if(!r.abandonedSubmissions)return 100;let e=r.totalSubmissions+r.abandonedSubmissions;return e===0?0:Math.round(r.totalSubmissions/e*100)},[r.totalSubmissions,r.abandonedSubmissions]),s=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,c.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,c.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,c.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,c.jsx)(a.Card,{children:(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,c.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,c.jsxs)(a.Card,{children:[(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,c.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,c.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,c.jsx)(a.Card,{children:(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,c.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?W(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,c.jsxs)(a.Card,{children:[(0,c.jsx)(a.CardHeader,{children:(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,c.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,c.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/s*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,c.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),r.fieldDropOff&&r.fieldDropOff.length>0&&(0,c.jsxs)(a.Card,{children:[(0,c.jsxs)(a.CardHeader,{children:[(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,c.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,c.jsxs)(`div`,{className:`space-y-1`,children:[(0,c.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,c.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,c.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,c.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,c.jsx)(`div`,{className:`rounded-full h-1.5 transition-all ${e.completionRate>=80?`bg-green-500`:e.completionRate>=50?`bg-yellow-500`:`bg-destructive`}`,style:{width:`${e.completionRate}%`}})})]},t))})})]})]})},K=({schema:e})=>(0,c.jsx)(V,{schema:e});n.ComponentRegistry.register(`object-form`,K,{namespace:`plugin-form`,label:`Object Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]},{name:`formType`,type:`enum`,label:`Form Type`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]},{name:`sections`,type:`array`,label:`Sections`},{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`vertical`,`horizontal`,`inline`,`grid`]},{name:`columns`,type:`number`,label:`Columns`},{name:`defaultTab`,type:`string`,label:`Default Tab`},{name:`tabPosition`,type:`enum`,label:`Tab Position`,enum:[`top`,`bottom`,`left`,`right`]},{name:`allowSkip`,type:`boolean`,label:`Allow Skip Steps`},{name:`showStepIndicator`,type:`boolean`,label:`Show Step Indicator`},{name:`splitDirection`,type:`enum`,label:`Split Direction`,enum:[`horizontal`,`vertical`]},{name:`splitSize`,type:`number`,label:`Split Panel Size (%)`},{name:`splitResizable`,type:`boolean`,label:`Split Resizable`},{name:`drawerSide`,type:`enum`,label:`Drawer Side`,enum:[`top`,`bottom`,`left`,`right`]},{name:`drawerWidth`,type:`string`,label:`Drawer Width`},{name:`modalSize`,type:`enum`,label:`Modal Size`,enum:[`sm`,`default`,`lg`,`xl`,`full`]}]}),n.ComponentRegistry.register(`form`,K,{namespace:`view`,skipFallback:!0,label:`Data Form View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]}]}),n.ComponentRegistry.register(`embeddable-form`,({schema:e})=>(0,c.jsx)(U,{config:e}),{namespace:`plugin-form`,label:`Embeddable Form`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Form Title`},{name:`description`,type:`string`,label:`Description`},{name:`fields`,type:`array`,label:`Fields`},{name:`allowMultiple`,type:`boolean`,label:`Allow Multiple Submissions`}]}),n.ComponentRegistry.register(`form-analytics`,({schema:e})=>(0,c.jsx)(G,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}}),{namespace:`plugin-form`,label:`Form Analytics`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`formTitle`,type:`string`,label:`Form Title`},{name:`metrics`,type:`object`,label:`Submission Metrics`}]}),e.DrawerForm=L,e.EmbeddableForm=U,e.FormAnalytics=G,e.FormSection=g,e.ModalForm=B,e.ObjectForm=V,e.SplitForm=y,e.TabbedForm=_,e.WizardForm=v,e.applyAutoColSpan=E,e.applyAutoLayout=M,e.filterAutoGeneratedFields=A,e.filterCreateModeFields=k,e.filterSystemFields=O,e.inferColumns=T,e.inferModalSize=j,e.isAutoGeneratedFieldType=w,e.isWideFieldType=C});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-form",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Form plugin for Object UI",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"lucide-react": "^1.16.0",
|
|
19
|
-
"@object-ui/components": "4.
|
|
20
|
-
"@object-ui/core": "4.
|
|
21
|
-
"@object-ui/fields": "4.
|
|
22
|
-
"@object-ui/permissions": "4.
|
|
23
|
-
"@object-ui/react": "4.
|
|
24
|
-
"@object-ui/types": "4.
|
|
19
|
+
"@object-ui/components": "4.5.0",
|
|
20
|
+
"@object-ui/core": "4.5.0",
|
|
21
|
+
"@object-ui/fields": "4.5.0",
|
|
22
|
+
"@object-ui/permissions": "4.5.0",
|
|
23
|
+
"@object-ui/react": "4.5.0",
|
|
24
|
+
"@object-ui/types": "4.5.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typescript": "^6.0.3",
|
|
34
34
|
"vite": "^8.0.13",
|
|
35
35
|
"vite-plugin-dts": "^5.0.0",
|
|
36
|
-
"@object-ui/data-objectstack": "4.
|
|
36
|
+
"@object-ui/data-objectstack": "4.5.0"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"objectui",
|