@object-ui/plugin-form 4.0.6 → 4.0.8

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @object-ui/plugin-form
2
2
 
3
+ ## 4.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - @object-ui/components@4.0.8
8
+ - @object-ui/fields@4.0.8
9
+ - @object-ui/react@4.0.8
10
+ - @object-ui/types@4.0.8
11
+ - @object-ui/core@4.0.8
12
+
13
+ ## 4.0.7
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [7c9b85c]
18
+ - @object-ui/core@4.0.7
19
+ - @object-ui/react@4.0.7
20
+ - @object-ui/components@4.0.7
21
+ - @object-ui/fields@4.0.7
22
+ - @object-ui/types@4.0.7
23
+
3
24
  ## 4.0.6
4
25
 
5
26
  ### Patch Changes
package/dist/index.js CHANGED
@@ -619,13 +619,46 @@ function Z(e, t, n, r) {
619
619
  };
620
620
  }
621
621
  //#endregion
622
+ //#region src/sanitize.ts
623
+ var ue = new Set([
624
+ "id",
625
+ "_id",
626
+ "created_at",
627
+ "updated_at",
628
+ "createdAt",
629
+ "updatedAt",
630
+ "organization_id",
631
+ "organizationId"
632
+ ]), de = new Set([
633
+ "formula",
634
+ "rollup",
635
+ "lookup_value",
636
+ "auto_number",
637
+ "autonumber",
638
+ "computed"
639
+ ]);
640
+ function fe(e, t) {
641
+ if (!e || typeof e != "object") return e;
642
+ let n = {}, r = t?.fields;
643
+ for (let [t, i] of Object.entries(e)) if (!ue.has(t)) {
644
+ if (r) {
645
+ let e = r[t];
646
+ if (!e) continue;
647
+ let n = String(e.type || "").toLowerCase();
648
+ if (de.has(n) || e.computed === !0 || e.formula || e.readOnly === !0 || e.readonly === !0) continue;
649
+ }
650
+ n[t] = i;
651
+ }
652
+ return n;
653
+ }
654
+ //#endregion
622
655
  //#region src/DrawerForm.tsx
623
- var ue = {
656
+ var pe = {
624
657
  1: void 0,
625
658
  2: "grid gap-4 grid-cols-1 @md:grid-cols-2",
626
659
  3: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",
627
660
  4: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"
628
- }, Q = ({ schema: e, dataSource: r, className: o }) => {
661
+ }, me = ({ schema: e, dataSource: r, className: o }) => {
629
662
  let { fieldLabel: u } = c(), [d, p] = a(null), [m, h] = a([]), [g, _] = a({}), [v, y] = a(!0), [b, x] = a(null), S = e.open !== !1, C = e.drawerSide || "right", [w, T] = a(() => {
630
663
  let t = {};
631
664
  return e.sections?.forEach((e, n) => {
@@ -747,12 +780,16 @@ var ue = {
747
780
  let M = t(async (t) => {
748
781
  if (!r) return e.onSuccess && await e.onSuccess(t), e.onOpenChange?.(!1), t;
749
782
  try {
750
- let n;
751
- return e.mode === "create" ? n = await r.create(e.objectName, t) : e.mode === "edit" && e.recordId && (n = await r.update(e.objectName, e.recordId, t)), e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
783
+ let n, i = fe(t, d);
784
+ return e.mode === "create" ? n = await r.create(e.objectName, i) : e.mode === "edit" && e.recordId && (n = await r.update(e.objectName, e.recordId, i)), e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
752
785
  } catch (t) {
753
786
  throw e.onError && e.onError(t), t;
754
787
  }
755
- }, [e, r]), N = t(() => {
788
+ }, [
789
+ e,
790
+ r,
791
+ d
792
+ ]), N = t(() => {
756
793
  e.onCancel && e.onCancel(), e.onOpenChange?.(!1);
757
794
  }, [e]), P = i(() => {
758
795
  if (e.drawerWidth) return C === "left" || C === "right" ? {
@@ -826,7 +863,7 @@ var ue = {
826
863
  fields: t
827
864
  } });
828
865
  }
829
- let t = Z(m, d, e.columns, e.mode), n = ue[t.columns || 1];
866
+ let t = Z(m, d, e.columns, e.mode), n = pe[t.columns || 1];
830
867
  return /* @__PURE__ */ U(s, { schema: {
831
868
  ...F,
832
869
  fields: t.fields,
@@ -837,18 +874,18 @@ var ue = {
837
874
  })]
838
875
  })
839
876
  });
840
- }, de = {
877
+ }, Q = {
841
878
  sm: "sm:max-w-sm",
842
879
  default: "sm:max-w-lg",
843
880
  lg: "sm:max-w-2xl",
844
881
  xl: "sm:max-w-5xl",
845
882
  full: "sm:max-w-[95vw] sm:w-full"
846
- }, fe = {
883
+ }, he = {
847
884
  1: void 0,
848
885
  2: "grid gap-4 grid-cols-1 @md:grid-cols-2",
849
886
  3: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",
850
887
  4: "grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"
851
- }, pe = ({ schema: e, dataSource: o, className: u }) => {
888
+ }, ge = ({ schema: e, dataSource: o, className: u }) => {
852
889
  let { fieldLabel: d } = c(), [m, h] = a(null), [g, _] = a([]), [v, w] = a({}), [T, E] = a(!0), [D, O] = a(null), [k, A] = a(!1), j = e.open !== !1, N = r(), P = i(() => e.sections?.length || e.customFields?.length ? null : Z(g, m, e.columns, e.mode), [
853
890
  g,
854
891
  m,
@@ -856,7 +893,7 @@ var ue = {
856
893
  e.mode,
857
894
  e.sections,
858
895
  e.customFields
859
- ]), F = de[i(() => {
896
+ ]), F = Q[i(() => {
860
897
  if (e.modalSize) return e.modalSize;
861
898
  if (P?.columns && P.columns > 1) return X(P.columns);
862
899
  if (e.sections?.length) {
@@ -868,7 +905,7 @@ var ue = {
868
905
  e.modalSize,
869
906
  P,
870
907
  e.sections
871
- ])] || de.default;
908
+ ])] || Q.default;
872
909
  n(() => {
873
910
  (async () => {
874
911
  if (!o) {
@@ -984,14 +1021,18 @@ var ue = {
984
1021
  A(!0);
985
1022
  try {
986
1023
  if (!o) return e.onSuccess && await e.onSuccess(t), e.onOpenChange?.(!1), t;
987
- let n;
988
- return e.mode === "create" ? n = await o.create(e.objectName, t) : e.mode === "edit" && e.recordId && (n = await o.update(e.objectName, e.recordId, t)), e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
1024
+ let n, r = fe(t, m);
1025
+ 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;
989
1026
  } catch (t) {
990
1027
  throw e.onError && e.onError(t), t;
991
1028
  } finally {
992
1029
  A(!1);
993
1030
  }
994
- }, [e, o]), z = t(() => {
1031
+ }, [
1032
+ e,
1033
+ o,
1034
+ m
1035
+ ]), z = t(() => {
995
1036
  e.onCancel && e.onCancel(), e.onOpenChange?.(!1);
996
1037
  }, [e]), ee = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical", B = e.showSubmit !== !1 && e.mode !== "view", V = e.showCancel !== !1, H = e.submitText || (e.mode === "create" ? "Create" : "Update"), K = e.cancelText || "Cancel", q = {
997
1038
  type: "form",
@@ -1036,7 +1077,7 @@ var ue = {
1036
1077
  label: e.label,
1037
1078
  description: e.description,
1038
1079
  columns: n,
1039
- gridClassName: fe[n],
1080
+ gridClassName: he[n],
1040
1081
  children: /* @__PURE__ */ U(s, { schema: {
1041
1082
  ...q,
1042
1083
  fields: I(e)
@@ -1044,7 +1085,7 @@ var ue = {
1044
1085
  }, e.name || e.label || t);
1045
1086
  })
1046
1087
  });
1047
- let t = P ?? Z(g, m, e.columns, e.mode), n = fe[t.columns || 1];
1088
+ let t = P ?? Z(g, m, e.columns, e.mode), n = he[t.columns || 1];
1048
1089
  return /* @__PURE__ */ U(s, { schema: {
1049
1090
  ...q,
1050
1091
  fields: t.fields,
@@ -1091,13 +1132,14 @@ var ue = {
1091
1132
  })
1092
1133
  });
1093
1134
  }, $ = ({ schema: e, dataSource: t }) => {
1135
+ let { sectionLabel: n } = c(), r = (t) => t?.name ? n(e.objectName, t.name, t.label || t.name) : t?.label;
1094
1136
  if (e.formType === "tabbed" && e.sections?.length) return /* @__PURE__ */ U(K, {
1095
1137
  schema: {
1096
1138
  ...e,
1097
1139
  formType: "tabbed",
1098
1140
  sections: e.sections.map((e) => ({
1099
1141
  name: e.name,
1100
- label: e.label,
1142
+ label: r(e),
1101
1143
  description: e.description,
1102
1144
  columns: e.columns,
1103
1145
  fields: e.fields
@@ -1114,7 +1156,7 @@ var ue = {
1114
1156
  formType: "wizard",
1115
1157
  sections: e.sections.map((e) => ({
1116
1158
  name: e.name,
1117
- label: e.label,
1159
+ label: r(e),
1118
1160
  description: e.description,
1119
1161
  columns: e.columns,
1120
1162
  fields: e.fields
@@ -1134,7 +1176,7 @@ var ue = {
1134
1176
  formType: "split",
1135
1177
  sections: e.sections.map((e) => ({
1136
1178
  name: e.name,
1137
- label: e.label,
1179
+ label: r(e),
1138
1180
  description: e.description,
1139
1181
  columns: e.columns,
1140
1182
  fields: e.fields
@@ -1147,15 +1189,15 @@ var ue = {
1147
1189
  className: e.className
1148
1190
  });
1149
1191
  if (e.formType === "drawer") {
1150
- let { layout: n, ...r } = e, i = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : void 0;
1151
- return /* @__PURE__ */ U(Q, {
1192
+ let { layout: n, ...i } = e, a = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : void 0;
1193
+ return /* @__PURE__ */ U(me, {
1152
1194
  schema: {
1153
- ...r,
1154
- layout: i,
1195
+ ...i,
1196
+ layout: a,
1155
1197
  formType: "drawer",
1156
1198
  sections: e.sections?.map((e) => ({
1157
1199
  name: e.name,
1158
- label: e.label,
1200
+ label: r(e),
1159
1201
  description: e.description,
1160
1202
  columns: e.columns,
1161
1203
  fields: e.fields,
@@ -1172,15 +1214,15 @@ var ue = {
1172
1214
  });
1173
1215
  }
1174
1216
  if (e.formType === "modal") {
1175
- let { layout: n, ...r } = e, i = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : void 0;
1176
- return /* @__PURE__ */ U(pe, {
1217
+ let { layout: n, ...i } = e, a = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : void 0;
1218
+ return /* @__PURE__ */ U(ge, {
1177
1219
  schema: {
1178
- ...r,
1179
- layout: i,
1220
+ ...i,
1221
+ layout: a,
1180
1222
  formType: "modal",
1181
1223
  sections: e.sections?.map((e) => ({
1182
1224
  name: e.name,
1183
- label: e.label,
1225
+ label: r(e),
1184
1226
  description: e.description,
1185
1227
  columns: e.columns,
1186
1228
  fields: e.fields
@@ -1194,20 +1236,20 @@ var ue = {
1194
1236
  className: e.className
1195
1237
  });
1196
1238
  }
1197
- return /* @__PURE__ */ U(me, {
1239
+ return /* @__PURE__ */ U(_e, {
1198
1240
  schema: e,
1199
1241
  dataSource: t
1200
1242
  });
1201
- }, me = ({ schema: r, dataSource: i }) => {
1202
- let { fieldLabel: o } = c(), p = R(), [m, h] = a(null), [g, _] = a([]), [v, y] = a(null), [b, x] = a(!0), [S, C] = a(null), w = r.customFields && r.customFields.length > 0;
1243
+ }, _e = ({ schema: r, dataSource: i }) => {
1244
+ let { fieldLabel: o, sectionLabel: p } = c(), m = R(), [h, g] = a(null), [_, v] = a([]), [y, b] = a(null), [x, S] = a(!0), [C, w] = a(null), T = r.customFields && r.customFields.length > 0;
1203
1245
  n(() => {
1204
- w && (y(r.initialData || r.initialValues || {}), x(!1));
1246
+ T && (b(r.initialData || r.initialValues || {}), S(!1));
1205
1247
  }, [
1206
- w,
1248
+ T,
1207
1249
  r.initialData,
1208
1250
  r.initialValues
1209
1251
  ]), n(() => {
1210
- w ? h({
1252
+ T ? g({
1211
1253
  name: r.objectName,
1212
1254
  fields: {}
1213
1255
  }) : r.objectName && i ? (async () => {
@@ -1215,33 +1257,33 @@ var ue = {
1215
1257
  if (!i) throw Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");
1216
1258
  let e = await i.getObjectSchema(r.objectName);
1217
1259
  if (!e) throw Error(`No schema found for object "${r.objectName}"`);
1218
- h(e);
1260
+ g(e);
1219
1261
  } catch (e) {
1220
- C(e), x(!1);
1262
+ w(e), S(!1);
1221
1263
  }
1222
- })() : w || x(!1);
1264
+ })() : T || S(!1);
1223
1265
  }, [
1224
1266
  r.objectName,
1225
1267
  i,
1226
- w
1268
+ T
1227
1269
  ]), n(() => {
1228
- m && !w && (async () => {
1270
+ h && !T && (async () => {
1229
1271
  if (!r.recordId || r.mode === "create") {
1230
- y(r.initialData || r.initialValues || {}), x(!1);
1272
+ b(r.initialData || r.initialValues || {}), S(!1);
1231
1273
  return;
1232
1274
  }
1233
- if (!w) {
1275
+ if (!T) {
1234
1276
  if (!i) {
1235
- C(/* @__PURE__ */ Error("DataSource is required for fetching record data (inline data not provided)")), x(!1);
1277
+ w(/* @__PURE__ */ Error("DataSource is required for fetching record data (inline data not provided)")), S(!1);
1236
1278
  return;
1237
1279
  }
1238
- x(!0);
1280
+ S(!0);
1239
1281
  try {
1240
- y(await i.findOne(r.objectName, r.recordId));
1282
+ b(await i.findOne(r.objectName, r.recordId));
1241
1283
  } catch (e) {
1242
- console.error("Failed to fetch record:", e), C(e);
1284
+ console.error("Failed to fetch record:", e), w(e);
1243
1285
  } finally {
1244
- x(!1);
1286
+ S(!1);
1245
1287
  }
1246
1288
  }
1247
1289
  })();
@@ -1252,20 +1294,20 @@ var ue = {
1252
1294
  r.initialValues,
1253
1295
  r.initialData,
1254
1296
  i,
1255
- m,
1256
- w
1297
+ h,
1298
+ T
1257
1299
  ]), n(() => {
1258
- if (w && r.customFields) {
1259
- _(r.customFields), x(!1);
1300
+ if (T && r.customFields) {
1301
+ v(r.customFields), S(!1);
1260
1302
  return;
1261
1303
  }
1262
- if (!m) return;
1263
- let e = [], t = r.fields || Object.keys(m.fields || {});
1304
+ if (!h) return;
1305
+ let e = [], t = r.fields || Object.keys(h.fields || {});
1264
1306
  (Array.isArray(t) ? t : Object.keys(t)).forEach((t) => {
1265
1307
  let n = typeof t == "string" ? t : t.name;
1266
1308
  if (!n) return;
1267
- let i = m.fields?.[n];
1268
- if (!i && !w) return;
1309
+ let i = h.fields?.[n];
1310
+ if (!i && !T) return;
1269
1311
  let a = !i?.permissions || i?.permissions.write !== !1;
1270
1312
  if (r.mode !== "view" && !a) return;
1271
1313
  let s = r.customFields?.find((e) => e.name === n);
@@ -1288,19 +1330,19 @@ var ue = {
1288
1330
  }
1289
1331
  i.type === "email" && (a.inputType = "email"), i.type === "phone" && (a.inputType = "tel"), i.type === "url" && (a.inputType = "url"), i.type === "password" && (a.inputType = "password"), i.type === "time" && (a.inputType = "time"), (i.type === "formula" || i.type === "summary" || i.type === "auto_number") && (a.disabled = !0), i.visible_on && (a.visible = (e) => u(i.visible_on, e)), e.push(a);
1290
1332
  }
1291
- }), _(e), !w && r.recordId && r.mode !== "create" && i || x(!1);
1333
+ }), v(e), !T && r.recordId && r.mode !== "create" && i || S(!1);
1292
1334
  }, [
1293
- m,
1335
+ h,
1294
1336
  r.fields,
1295
1337
  r.customFields,
1296
1338
  r.readOnly,
1297
1339
  r.mode,
1298
- w,
1340
+ T,
1299
1341
  r.recordId,
1300
1342
  i
1301
1343
  ]);
1302
- let T = t(async (e, t) => {
1303
- if (e && (e.nativeEvent || e._reactName === "onSubmit") && (console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."), t === void 0 && (t = e, e = {})), w && !i) return r.onSuccess && await r.onSuccess(e), e;
1344
+ let E = t(async (e, t) => {
1345
+ if (e && (e.nativeEvent || e._reactName === "onSubmit") && (console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."), t === void 0 && (t = e, e = {})), T && !i) return r.onSuccess && await r.onSuccess(e), e;
1304
1346
  if (!i) throw Error("DataSource is required for form submission (inline mode not configured)");
1305
1347
  try {
1306
1348
  let t;
@@ -1314,44 +1356,44 @@ var ue = {
1314
1356
  }, [
1315
1357
  r,
1316
1358
  i,
1317
- w
1318
- ]), E = t(() => {
1359
+ T
1360
+ ]), D = t(() => {
1319
1361
  r.onCancel && r.onCancel();
1320
- }, [r]), D = {
1362
+ }, [r]), O = {
1321
1363
  ...e.useMemo(() => {
1322
- if (!m?.fields) return {};
1364
+ if (!h?.fields) return {};
1323
1365
  let e = {};
1324
- return Object.keys(m.fields).forEach((t) => {
1325
- let n = m.fields[t];
1366
+ return Object.keys(h.fields).forEach((t) => {
1367
+ let n = h.fields[t];
1326
1368
  n.defaultValue !== void 0 && (e[t] = n.defaultValue);
1327
1369
  }), e;
1328
- }, [m]),
1329
- ...v
1370
+ }, [h]),
1371
+ ...y
1330
1372
  };
1331
- if (S) return /* @__PURE__ */ W("div", {
1373
+ if (C) return /* @__PURE__ */ W("div", {
1332
1374
  className: "p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",
1333
1375
  children: [/* @__PURE__ */ U("h3", {
1334
1376
  className: "text-red-800 font-semibold",
1335
1377
  children: "Error loading form"
1336
1378
  }), /* @__PURE__ */ U("p", {
1337
1379
  className: "text-red-600 text-sm mt-1",
1338
- children: S.message
1380
+ children: C.message
1339
1381
  })]
1340
1382
  });
1341
- if (b) return /* @__PURE__ */ W("div", {
1383
+ if (x) return /* @__PURE__ */ W("div", {
1342
1384
  className: "p-4 sm:p-8 text-center",
1343
1385
  children: [/* @__PURE__ */ U("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }), /* @__PURE__ */ U("p", {
1344
1386
  className: "mt-2 text-sm text-gray-600",
1345
1387
  children: "Loading form..."
1346
1388
  })]
1347
1389
  });
1348
- let O = r.layout === "vertical" || r.layout === "horizontal" ? r.layout : "vertical";
1390
+ let k = r.layout === "vertical" || r.layout === "horizontal" ? r.layout : "vertical";
1349
1391
  if (r.sections?.length && (!r.formType || r.formType === "simple")) return /* @__PURE__ */ U("div", {
1350
1392
  className: "w-full space-y-6",
1351
1393
  children: r.sections.map((e, t) => {
1352
- let n = e.fields.map((e) => typeof e == "string" ? e : e.name), i = g.filter((e) => n.includes(e.name));
1394
+ let n = e.fields.map((e) => typeof e == "string" ? e : e.name), i = _.filter((e) => n.includes(e.name));
1353
1395
  return /* @__PURE__ */ U(G, {
1354
- label: e.label,
1396
+ label: e.name ? p(r.objectName, e.name, e.label || e.name) : e.label,
1355
1397
  description: e.description,
1356
1398
  collapsible: e.collapsible,
1357
1399
  collapsed: e.collapsed,
@@ -1359,35 +1401,35 @@ var ue = {
1359
1401
  children: /* @__PURE__ */ U(s, { schema: {
1360
1402
  type: "form",
1361
1403
  fields: i,
1362
- layout: O,
1363
- defaultValues: D,
1404
+ layout: k,
1405
+ defaultValues: O,
1364
1406
  showSubmit: t === r.sections.length - 1 && r.showSubmit !== !1 && r.mode !== "view",
1365
1407
  showCancel: t === r.sections.length - 1 && r.showCancel !== !1,
1366
1408
  submitLabel: r.submitText || (r.mode === "create" ? "Create" : "Update"),
1367
1409
  cancelLabel: r.cancelText,
1368
- onSubmit: T,
1369
- onCancel: E
1410
+ onSubmit: E,
1411
+ onCancel: D
1370
1412
  } })
1371
1413
  }, e.name || e.label || t);
1372
1414
  })
1373
1415
  });
1374
- let k = r.sections?.length, A = k ? {
1375
- fields: g,
1416
+ let A = r.sections?.length, j = A ? {
1417
+ fields: _,
1376
1418
  columns: r.columns
1377
- } : Z(g, m, r.columns, r.mode), j = r.mobile, M = j?.fullscreenLongText ? A.fields.map((e) => {
1419
+ } : Z(_, h, r.columns, r.mode), M = r.mobile, N = M?.fullscreenLongText ? j.fields.map((e) => {
1378
1420
  let t = e.type;
1379
1421
  return t === "textarea" || t === "field:textarea" || t === "string-multiline" || t === "field:markdown" || t === "field:html" ? {
1380
1422
  ...e,
1381
1423
  mobile_fullscreen: !0
1382
1424
  } : e;
1383
- }) : A.fields, N = j?.stepper, P = j?.stepperMinFields ?? 8, F = Math.max(1, j?.stepperFieldsPerStep ?? 1);
1384
- if (!r.formType && !k && M.length >= 2 && (N === !0 || N === "auto" && p && M.length >= P)) {
1385
- let e = M, t = [];
1386
- for (let n = 0; n < e.length; n += F) {
1387
- let r = e.slice(n, n + F);
1425
+ }) : j.fields, P = M?.stepper, F = M?.stepperMinFields ?? 8, I = Math.max(1, M?.stepperFieldsPerStep ?? 1);
1426
+ if (!r.formType && !A && N.length >= 2 && (P === !0 || P === "auto" && m && N.length >= F)) {
1427
+ let e = N, t = [];
1428
+ for (let n = 0; n < e.length; n += I) {
1429
+ let r = e.slice(n, n + I);
1388
1430
  t.push({
1389
- name: `step-${Math.floor(n / F) + 1}`,
1390
- label: r[0]?.label || r[0]?.name || `Step ${Math.floor(n / F) + 1}`,
1431
+ name: `step-${Math.floor(n / I) + 1}`,
1432
+ label: r[0]?.label || r[0]?.name || `Step ${Math.floor(n / I) + 1}`,
1391
1433
  fields: r
1392
1434
  });
1393
1435
  }
@@ -1402,28 +1444,28 @@ var ue = {
1402
1444
  className: r.className
1403
1445
  });
1404
1446
  }
1405
- let I = {
1447
+ let L = {
1406
1448
  type: "form",
1407
- fields: M,
1408
- layout: O,
1409
- columns: A.columns,
1449
+ fields: N,
1450
+ layout: k,
1451
+ columns: j.columns,
1410
1452
  submitLabel: r.submitText || (r.mode === "create" ? "Create" : "Update"),
1411
1453
  cancelLabel: r.cancelText,
1412
1454
  showSubmit: r.showSubmit !== !1 && r.mode !== "view",
1413
1455
  showCancel: r.showCancel !== !1,
1414
1456
  resetOnSubmit: r.showReset,
1415
- defaultValues: D,
1416
- onSubmit: T,
1417
- onCancel: E,
1457
+ defaultValues: O,
1458
+ onSubmit: E,
1459
+ onCancel: D,
1418
1460
  className: r.className,
1419
- mobileStickyActions: !!j?.stickyActions
1461
+ mobileStickyActions: !!M?.stickyActions
1420
1462
  };
1421
1463
  return /* @__PURE__ */ U("div", {
1422
- className: j?.stickyActions ? "w-full pb-20 md:pb-0" : "w-full",
1423
- "data-mobile-form": j ? "true" : void 0,
1424
- children: /* @__PURE__ */ U(s, { schema: I })
1464
+ className: M?.stickyActions ? "w-full pb-20 md:pb-0" : "w-full",
1465
+ "data-mobile-form": M ? "true" : void 0,
1466
+ children: /* @__PURE__ */ U(s, { schema: L })
1425
1467
  });
1426
- }, he = ({ config: e, dataSource: n, prefillParams: r, className: o }) => {
1468
+ }, ve = ({ config: e, dataSource: n, prefillParams: r, className: o }) => {
1427
1469
  let [s, c] = a(!1), [l, u] = a(!1), [d, f] = a(null), p = i(() => {
1428
1470
  let e = {};
1429
1471
  if (r) for (let [t, n] of Object.entries(r)) e[t] = n;
@@ -1544,10 +1586,10 @@ var ue = {
1544
1586
  };
1545
1587
  //#endregion
1546
1588
  //#region src/FormAnalytics.tsx
1547
- function ge(e) {
1589
+ function ye(e) {
1548
1590
  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`;
1549
1591
  }
1550
- var _e = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
1592
+ var be = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
1551
1593
  let a = i(() => {
1552
1594
  if (!n.abandonedSubmissions) return 100;
1553
1595
  let e = n.totalSubmissions + n.abandonedSubmissions;
@@ -1590,7 +1632,7 @@ var _e = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
1590
1632
  className: "pb-2",
1591
1633
  children: [/* @__PURE__ */ U(g, { children: "Avg. Completion Time" }), /* @__PURE__ */ U(v, {
1592
1634
  className: "text-2xl",
1593
- children: n.avgCompletionTime ? ge(n.avgCompletionTime) : "—"
1635
+ children: n.avgCompletionTime ? ye(n.avgCompletionTime) : "—"
1594
1636
  })]
1595
1637
  }) })
1596
1638
  ]
@@ -1642,8 +1684,8 @@ var _e = ({ formId: e, formTitle: t, metrics: n, className: r }) => {
1642
1684
  }) })] })
1643
1685
  ]
1644
1686
  });
1645
- }, ve = ({ schema: e }) => /* @__PURE__ */ U($, { schema: e });
1646
- o.register("object-form", ve, {
1687
+ }, xe = ({ schema: e }) => /* @__PURE__ */ U($, { schema: e });
1688
+ o.register("object-form", xe, {
1647
1689
  namespace: "plugin-form",
1648
1690
  label: "Object Form",
1649
1691
  category: "plugin",
@@ -1784,7 +1826,7 @@ o.register("object-form", ve, {
1784
1826
  ]
1785
1827
  }
1786
1828
  ]
1787
- }), o.register("form", ve, {
1829
+ }), o.register("form", xe, {
1788
1830
  namespace: "view",
1789
1831
  skipFallback: !0,
1790
1832
  label: "Data Form View",
@@ -1812,7 +1854,7 @@ o.register("object-form", ve, {
1812
1854
  ]
1813
1855
  }
1814
1856
  ]
1815
- }), o.register("embeddable-form", ({ schema: e }) => /* @__PURE__ */ U(he, { config: e }), {
1857
+ }), o.register("embeddable-form", ({ schema: e }) => /* @__PURE__ */ U(ve, { config: e }), {
1816
1858
  namespace: "plugin-form",
1817
1859
  label: "Embeddable Form",
1818
1860
  category: "plugin",
@@ -1850,7 +1892,7 @@ o.register("object-form", ve, {
1850
1892
  label: "Allow Multiple Submissions"
1851
1893
  }
1852
1894
  ]
1853
- }), o.register("form-analytics", ({ schema: e }) => /* @__PURE__ */ U(_e, {
1895
+ }), o.register("form-analytics", ({ schema: e }) => /* @__PURE__ */ U(be, {
1854
1896
  formId: e.formId,
1855
1897
  formTitle: e.formTitle,
1856
1898
  metrics: e.metrics || { totalSubmissions: 0 }
@@ -1878,4 +1920,4 @@ o.register("object-form", ve, {
1878
1920
  ]
1879
1921
  });
1880
1922
  //#endregion
1881
- export { Q as DrawerForm, he as EmbeddableForm, _e as FormAnalytics, G as FormSection, pe as ModalForm, $ as ObjectForm, J as SplitForm, K as TabbedForm, q as WizardForm, Y as applyAutoColSpan, Z as applyAutoLayout, le as filterCreateModeFields, se as inferColumns, X as inferModalSize, oe as isAutoGeneratedFieldType, ae as isWideFieldType };
1923
+ export { me as DrawerForm, ve as EmbeddableForm, be as FormAnalytics, G as FormSection, ge as ModalForm, $ as ObjectForm, J as SplitForm, K as TabbedForm, q as WizardForm, Y as applyAutoColSpan, Z as applyAutoLayout, le as filterCreateModeFields, se as inferColumns, X as inferModalSize, oe as isAutoGeneratedFieldType, ae as isWideFieldType };
@@ -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(`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`,`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.lucide_react,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=Object.create,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,m=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=d(t),a=0,o=i.length,s;a<o;a++)s=i[a],!p.call(e,s)&&s!==n&&l(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=u(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:c(f(e)),m(t||!e||!e.__esModule?l(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var h=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:c=1,children:l,className:u,gridClassName:d})=>{let[f,p]=(0,t.useState)(i);return(0,s.jsxs)(`div`,{className:(0,a.cn)(`form-section`,u),children:[(e||n)&&(0,s.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,s.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:f?(0,s.jsx)(o.ChevronRight,{className:`h-4 w-4`}):(0,s.jsx)(o.ChevronDown,{className:`h-4 w-4`})}),(0,s.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,s.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}),!f&&(0,s.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`}[c]),children:l})]})},g=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[g,_]=(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:c(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(g)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(p)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.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,s.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,s.jsxs)(a.Tabs,{value:v,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,s.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,s.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,s.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,s.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,s.jsx)(h,{description:t.description,columns:t.columns||1,children:(0,s.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},_=({schema:e,dataSource:n,className:c})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),[m,g]=(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){g(!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||{}),g(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{g(!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,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,s.jsxs)(`div`,{className:(0,a.cn)(`w-full`,c,e.className),children:[e.showStepIndicator!==!1&&(0,s.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,s.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),c=e.allowSkip||i||n<=y;return(0,s.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,s.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,s.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,s.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,c?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!c,children:[(0,s.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,s.jsx)(o.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,s.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,s.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,s.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,s.jsx)(h,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,s.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:f,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,s.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,s.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,s.jsx)(`div`,{children:e.showCancel!==!1&&(0,s.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,s.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,s.jsx)(o.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,s.jsx)(a.Button,{onClick:()=>A(f),disabled:C||e.mode===`view`,children:C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,s.jsxs)(a.Button,{onClick:()=>A(f),children:[e.nextText||`Next`,(0,s.jsx)(o.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},v=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[g,_]=(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:c(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(g)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(p)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.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,s.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,s.jsx)(h,{label:t.label,description:t.description,columns:t.columns||1,children:(0,s.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,s.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,s.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,s.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,s.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},y=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),b=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),x=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function S(e){return b.has(e)}function C(e){return x.has(e)}function w(e){return e<=3?1:2}function T(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&S(e.type)?{...e,colSpan:t}:e)}var E=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`owner`,`owner_id`,`_version`,`_rev`]);function D(e,t){return e.filter(e=>{if(E.has(e.name)||e.type&&y.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!C(n.type):!0})}function O(e){return e<=1?`default`:e===2?`xl`:`full`}function k(e,t,n,r){let i=[...e];if(r===`create`&&(i=D(i,t)),n!==void 0)return i=T(i,n),{fields:i,columns:n};let a=w(i.length);return i=T(i,a),{fields:i,columns:a}}var A={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`},j=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(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:c(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:c(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;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),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n]),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,s.jsx)(a.Sheet,{open:y,onOpenChange:e.onOpenChange,children:(0,s.jsxs)(a.SheetContent,{side:b,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:E,children:[(e.title||e.description)&&(0,s.jsxs)(a.SheetHeader,{children:[e.title&&(0,s.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,s.jsx)(a.SheetDescription,{children:e.description})]}),(0,s.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(_)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.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,s.jsx)(r.SchemaRenderer,{schema:{...D,fields:t}})}let t=k(d,l,e.columns,e.mode),n=A[t.columns||1];return(0,s.jsx)(r.SchemaRenderer,{schema:{...D,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},M={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`},N={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`},P=({schema:e,dataSource:n,className:c})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)([]),[m,g]=(0,t.useState)({}),[_,v]=(0,t.useState)(!0),[y,b]=(0,t.useState)(null),[x,S]=(0,t.useState)(!1),C=e.open!==!1,w=(0,t.useId)(),T=(0,t.useMemo)(()=>e.sections?.length||e.customFields?.length?null:k(f,u,e.columns,e.mode),[f,u,e.columns,e.mode,e.sections,e.customFields]),E=M[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(T?.columns&&T.columns>1)return O(T.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return O(t)}return`default`},[e.modalSize,T,e.sections])]||M.default;(0,t.useEffect)(()=>{(async()=>{if(!n){v(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){b(e),v(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){g(e.initialData||e.initialValues||{}),v(!1);return}if(!n){g(e.initialData||e.initialValues||{}),v(!1);return}try{g(await n.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{v(!1)}})()},[u,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let D=(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]);(0,t.useEffect)(()=>{if(!u&&n)return;if(e.customFields?.length){p(e.customFields),v(!1);return}if(e.sections?.length){v(!1);return}if(!u)return;let t=e.fields||Object.keys(u.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=u.fields?.[t];a&&r.push({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})}p(r),v(!1)},[u,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let A=(0,t.useCallback)(async t=>{S(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;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),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{S(!1)}},[e,n]),j=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),P=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,F=e.showSubmit!==!1&&e.mode!==`view`,I=e.showCancel!==!1,L=e.submitText||(e.mode===`create`?`Create`:`Update`),R=e.cancelText||`Cancel`,z={type:`form`,layout:P,defaultValues:m,submitLabel:L,cancelLabel:R,showSubmit:F,showCancel:I,onSubmit:A,onCancel:j,showActions:!1,id:w},B=()=>{if(y)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(_)return(0,s.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,s.jsxs)(`div`,{className:`space-y-2`,children:[(0,s.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,s.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,s.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,s.jsx)(h,{label:e.label,description:e.description,columns:n,gridClassName:N[n],children:(0,s.jsx)(r.SchemaRenderer,{schema:{...z,fields:D(e)}})},e.name||e.label||t)})});let t=T??k(f,u,e.columns,e.mode),n=N[t.columns||1];return(0,s.jsx)(r.SchemaRenderer,{schema:{...z,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},V=!_&&!y&&(F||I);return(0,s.jsx)(a.Dialog,{open:C,onOpenChange:e.onOpenChange,children:(0,s.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(E,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,c,e.className),children:[(e.title||e.description)&&(0,s.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,s.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,s.jsx)(a.DialogDescription,{children:e.description})]}),(0,s.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:B()}),V&&(0,s.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[I&&(0,s.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:j,disabled:x,className:`w-full sm:w-auto`,children:R}),F&&(0,s.jsxs)(a.Button,{type:`submit`,form:w,disabled:x,className:`w-full sm:w-auto`,children:[x&&(0,s.jsx)(o.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),L]})]})})]})})},F=({schema:e,dataSource:t})=>{if(e.formType===`tabbed`&&e.sections?.length)return(0,s.jsx)(g,{schema:{...e,formType:`tabbed`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:t,className:e.className});if(e.formType===`wizard`&&e.sections?.length)return(0,s.jsx)(_,{schema:{...e,formType:`wizard`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:t,className:e.className});if(e.formType===`split`&&e.sections?.length)return(0,s.jsx)(v,{schema:{...e,formType:`split`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:t,className:e.className});if(e.formType===`drawer`){let{layout:n,...r}=e,i=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,s.jsx)(j,{schema:{...r,layout:i,formType:`drawer`,sections:e.sections?.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:t,className:e.className})}if(e.formType===`modal`){let{layout:n,...r}=e,i=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,s.jsx)(P,{schema:{...r,layout:i,formType:`modal`,sections:e.sections?.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:t,className:e.className})}return(0,s.jsx)(I,{schema:e,dataSource:t})},I=({schema:e,dataSource:n})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),c=(0,a.useIsMobile)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)([]),[p,m]=(0,t.useState)(null),[g,v]=(0,t.useState)(!0),[y,b]=(0,t.useState)(null),x=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{x&&(m(e.initialData||e.initialValues||{}),v(!1))},[x,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{x?u({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}"`);u(t)}catch(e){b(e),v(!1)}})():x||v(!1)},[e.objectName,n,x]),(0,t.useEffect)(()=>{l&&!x&&(async()=>{if(!e.recordId||e.mode===`create`){m(e.initialData||e.initialValues||{}),v(!1);return}if(!x){if(!n){b(Error(`DataSource is required for fetching record data (inline data not provided)`)),v(!1);return}v(!0);try{m(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),b(e)}finally{v(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,l,x]),(0,t.useEffect)(()=>{if(x&&e.customFields){f(e.customFields),v(!1);return}if(!l)return;let t=[],r=e.fields||Object.keys(l.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let a=l.fields?.[r];if(!a&&!x)return;let s=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!s)return;let c=e.customFields?.find(e=>e.name===r);if(c)t.push(c);else if(a){let s={name:r,label:o(e.objectName,r,a.label||n),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};if((a.type===`select`||a.type===`lookup`||a.type===`master_detail`)&&(s.options=a.options||[],s.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(s.inputType=`number`,s.min=a.min,s.max=a.max,s.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(s.inputType=`date`),a.type===`datetime`&&(s.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(s.maxLength=a.max_length,s.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(s.inputType=`file`,s.multiple=a.multiple,s.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${(0,i.formatFileSize)(a.max_size)}`;s.description=s.description?`${s.description} (${e})`:e}a.type===`email`&&(s.inputType=`email`),a.type===`phone`&&(s.inputType=`tel`),a.type===`url`&&(s.inputType=`url`),a.type===`password`&&(s.inputType=`password`),a.type===`time`&&(s.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(s.disabled=!0),a.visible_on&&(s.visible=e=>(0,i.evaluateCondition)(a.visible_on,e)),t.push(s)}}),f(t),!x&&e.recordId&&e.mode!==`create`&&n||v(!1)},[l,e.fields,e.customFields,e.readOnly,e.mode,x,e.recordId,n]);let S=(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={})),x&&!n)return e.onSuccess&&await e.onSuccess(t),t;if(!n)throw Error(`DataSource is required for form submission (inline mode not configured)`);try{let r;if(e.mode===`create`)r=await n.create(e.objectName,t);else if(e.mode===`edit`&&e.recordId)r=await n.update(e.objectName,e.recordId,t);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,n,x]),C=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),w={...t.default.useMemo(()=>{if(!l?.fields)return{};let e={};return Object.keys(l.fields).forEach(t=>{let n=l.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[l]),...p};if(y)return(0,s.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(g)return(0,s.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let T=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,s.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=d.filter(e=>i.includes(e.name));return(0,s.jsx)(h,{label:t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,s.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:T,defaultValues:w,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:S,onCancel:C}})},t.name||t.label||n)})});let E=e.sections?.length,D=E?{fields:d,columns:e.columns}:k(d,l,e.columns,e.mode),O=e.mobile,A=O?.fullscreenLongText?D.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}):D.fields,j=O?.stepper,M=O?.stepperMinFields??8,N=Math.max(1,O?.stepperFieldsPerStep??1);if(!e.formType&&!E&&A.length>=2&&(j===!0||j===`auto`&&c&&A.length>=M)){let t=A,r=[];for(let e=0;e<t.length;e+=N){let n=t.slice(e,e+N);r.push({name:`step-${Math.floor(e/N)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/N)+1}`,fields:n})}return(0,s.jsx)(_,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let P={type:`form`,fields:A,layout:T,columns:D.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:w,onSubmit:S,onCancel:C,className:e.className,mobileStickyActions:!!O?.stickyActions};return(0,s.jsx)(`div`,{className:O?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":O?`true`:void 0,children:(0,s.jsx)(r.SchemaRenderer,{schema:P})})},L=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[a,o]=(0,t.useState)(!1),[c,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,s.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,s.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,s.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,s.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,s.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,s.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,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,s.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,s.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,s.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,s.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,s.jsxs)(`div`,{className:`p-6`,children:[u&&(0,s.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:u}),(0,s.jsx)(F,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:f,onSuccess:p,submitLabel:c?`Submitting...`:`Submit`},dataSource:n})]}),(0,s.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function R(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 z=({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]),c=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,s.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,s.jsx)(a.Card,{children:(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,s.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,s.jsxs)(a.Card,{children:[(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,s.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,s.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,s.jsx)(a.Card,{children:(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,s.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?R(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,s.jsxs)(a.Card,{children:[(0,s.jsx)(a.CardHeader,{children:(0,s.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,s.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/c*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,s.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,s.jsxs)(a.Card,{children:[(0,s.jsxs)(a.CardHeader,{children:[(0,s.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,s.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,s.jsxs)(`div`,{className:`space-y-1`,children:[(0,s.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,s.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,s.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,s.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,s.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))})})]})]})},B=({schema:e})=>(0,s.jsx)(F,{schema:e});n.ComponentRegistry.register(`object-form`,B,{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`,B,{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,s.jsx)(L,{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,s.jsx)(z,{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=j,e.EmbeddableForm=L,e.FormAnalytics=z,e.FormSection=h,e.ModalForm=P,e.ObjectForm=F,e.SplitForm=v,e.TabbedForm=g,e.WizardForm=_,e.applyAutoColSpan=T,e.applyAutoLayout=k,e.filterCreateModeFields=D,e.inferColumns=w,e.inferModalSize=O,e.isAutoGeneratedFieldType=C,e.isWideFieldType=S});
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(`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`,`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.lucide_react,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=Object.create,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,m=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=d(t),a=0,o=i.length,s;a<o;a++)s=i[a],!p.call(e,s)&&s!==n&&l(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=u(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:c(f(e)),m(t||!e||!e.__esModule?l(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var h=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:c=1,children:l,className:u,gridClassName:d})=>{let[f,p]=(0,t.useState)(i);return(0,s.jsxs)(`div`,{className:(0,a.cn)(`form-section`,u),children:[(e||n)&&(0,s.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,s.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:f?(0,s.jsx)(o.ChevronRight,{className:`h-4 w-4`}):(0,s.jsx)(o.ChevronDown,{className:`h-4 w-4`})}),(0,s.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,s.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}),!f&&(0,s.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`}[c]),children:l})]})},g=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[g,_]=(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:c(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(g)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(p)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.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,s.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,s.jsxs)(a.Tabs,{value:v,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,s.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,s.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,s.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,s.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,s.jsx)(h,{description:t.description,columns:t.columns||1,children:(0,s.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},_=({schema:e,dataSource:n,className:c})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),[m,g]=(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){g(!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||{}),g(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{g(!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,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,s.jsxs)(`div`,{className:(0,a.cn)(`w-full`,c,e.className),children:[e.showStepIndicator!==!1&&(0,s.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,s.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),c=e.allowSkip||i||n<=y;return(0,s.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,s.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,s.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,s.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,c?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!c,children:[(0,s.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,s.jsx)(o.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,s.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,s.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,s.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,s.jsx)(h,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,s.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:f,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,s.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,s.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,s.jsx)(`div`,{children:e.showCancel!==!1&&(0,s.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,s.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,s.jsx)(o.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,s.jsx)(a.Button,{onClick:()=>A(f),disabled:C||e.mode===`view`,children:C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,s.jsxs)(a.Button,{onClick:()=>A(f),children:[e.nextText||`Next`,(0,s.jsx)(o.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},v=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[g,_]=(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:c(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(g)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(p)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.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,s.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,s.jsx)(h,{label:t.label,description:t.description,columns:t.columns||1,children:(0,s.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,s.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,s.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,s.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,s.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},y=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),b=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),x=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function S(e){return b.has(e)}function C(e){return x.has(e)}function w(e){return e<=3?1:2}function T(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&S(e.type)?{...e,colSpan:t}:e)}var E=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`owner`,`owner_id`,`_version`,`_rev`]);function D(e,t){return e.filter(e=>{if(E.has(e.name)||e.type&&y.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!C(n.type):!0})}function O(e){return e<=1?`default`:e===2?`xl`:`full`}function k(e,t,n,r){let i=[...e];if(r===`create`&&(i=D(i,t)),n!==void 0)return i=T(i,n),{fields:i,columns:n};let a=w(i.length);return i=T(i,a),{fields:i,columns:a}}var A=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),j=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function M(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!A.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(j.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var N={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`},P=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(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:c(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:c(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=M(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,s.jsx)(a.Sheet,{open:y,onOpenChange:e.onOpenChange,children:(0,s.jsxs)(a.SheetContent,{side:b,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:E,children:[(e.title||e.description)&&(0,s.jsxs)(a.SheetHeader,{children:[e.title&&(0,s.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,s.jsx)(a.SheetDescription,{children:e.description})]}),(0,s.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(_)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.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,s.jsx)(r.SchemaRenderer,{schema:{...D,fields:t}})}let t=k(d,l,e.columns,e.mode),n=N[t.columns||1];return(0,s.jsx)(r.SchemaRenderer,{schema:{...D,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},F={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`},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:c})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)([]),[m,g]=(0,t.useState)({}),[_,v]=(0,t.useState)(!0),[y,b]=(0,t.useState)(null),[x,S]=(0,t.useState)(!1),C=e.open!==!1,w=(0,t.useId)(),T=(0,t.useMemo)(()=>e.sections?.length||e.customFields?.length?null:k(f,u,e.columns,e.mode),[f,u,e.columns,e.mode,e.sections,e.customFields]),E=F[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(T?.columns&&T.columns>1)return O(T.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return O(t)}return`default`},[e.modalSize,T,e.sections])]||F.default;(0,t.useEffect)(()=>{(async()=>{if(!n){v(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){b(e),v(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){g(e.initialData||e.initialValues||{}),v(!1);return}if(!n){g(e.initialData||e.initialValues||{}),v(!1);return}try{g(await n.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{v(!1)}})()},[u,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let D=(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]);(0,t.useEffect)(()=>{if(!u&&n)return;if(e.customFields?.length){p(e.customFields),v(!1);return}if(e.sections?.length){v(!1);return}if(!u)return;let t=e.fields||Object.keys(u.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=u.fields?.[t];a&&r.push({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})}p(r),v(!1)},[u,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let A=(0,t.useCallback)(async t=>{S(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=M(t,u);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{S(!1)}},[e,n,u]),j=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),N=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,P=e.showSubmit!==!1&&e.mode!==`view`,L=e.showCancel!==!1,R=e.submitText||(e.mode===`create`?`Create`:`Update`),z=e.cancelText||`Cancel`,B={type:`form`,layout:N,defaultValues:m,submitLabel:R,cancelLabel:z,showSubmit:P,showCancel:L,onSubmit:A,onCancel:j,showActions:!1,id:w},V=()=>{if(y)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(_)return(0,s.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,s.jsxs)(`div`,{className:`space-y-2`,children:[(0,s.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,s.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,s.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,s.jsx)(h,{label:e.label,description:e.description,columns:n,gridClassName:I[n],children:(0,s.jsx)(r.SchemaRenderer,{schema:{...B,fields:D(e)}})},e.name||e.label||t)})});let t=T??k(f,u,e.columns,e.mode),n=I[t.columns||1];return(0,s.jsx)(r.SchemaRenderer,{schema:{...B,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},H=!_&&!y&&(P||L);return(0,s.jsx)(a.Dialog,{open:C,onOpenChange:e.onOpenChange,children:(0,s.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(E,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,c,e.className),children:[(e.title||e.description)&&(0,s.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,s.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,s.jsx)(a.DialogDescription,{children:e.description})]}),(0,s.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:V()}),H&&(0,s.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[L&&(0,s.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:j,disabled:x,className:`w-full sm:w-auto`,children:z}),P&&(0,s.jsxs)(a.Button,{type:`submit`,form:w,disabled:x,className:`w-full sm:w-auto`,children:[x&&(0,s.jsx)(o.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),R]})]})})]})})},R=({schema:e,dataSource:t})=>{let{sectionLabel:n}=(0,r.useSafeFieldLabel)(),i=t=>t?.name?n(e.objectName,t.name,t.label||t.name):t?.label;if(e.formType===`tabbed`&&e.sections?.length)return(0,s.jsx)(g,{schema:{...e,formType:`tabbed`,sections:e.sections.map(e=>({name:e.name,label:i(e),description:e.description,columns:e.columns,fields:e.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:t,className:e.className});if(e.formType===`wizard`&&e.sections?.length)return(0,s.jsx)(_,{schema:{...e,formType:`wizard`,sections:e.sections.map(e=>({name:e.name,label:i(e),description:e.description,columns:e.columns,fields:e.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:t,className:e.className});if(e.formType===`split`&&e.sections?.length)return(0,s.jsx)(v,{schema:{...e,formType:`split`,sections:e.sections.map(e=>({name:e.name,label:i(e),description:e.description,columns:e.columns,fields:e.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:t,className:e.className});if(e.formType===`drawer`){let{layout:n,...r}=e,a=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,s.jsx)(P,{schema:{...r,layout:a,formType:`drawer`,sections:e.sections?.map(e=>({name:e.name,label:i(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:t,className:e.className})}if(e.formType===`modal`){let{layout:n,...r}=e,a=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,s.jsx)(L,{schema:{...r,layout:a,formType:`modal`,sections:e.sections?.map(e=>({name:e.name,label:i(e),description:e.description,columns:e.columns,fields:e.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:t,className:e.className})}return(0,s.jsx)(z,{schema:e,dataSource:t})},z=({schema:e,dataSource:n})=>{let{fieldLabel:o,sectionLabel:c}=(0,r.useSafeFieldLabel)(),l=(0,a.useIsMobile)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)([]),[m,g]=(0,t.useState)(null),[v,y]=(0,t.useState)(!0),[b,x]=(0,t.useState)(null),S=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{S&&(g(e.initialData||e.initialValues||{}),y(!1))},[S,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{S?d({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}"`);d(t)}catch(e){x(e),y(!1)}})():S||y(!1)},[e.objectName,n,S]),(0,t.useEffect)(()=>{u&&!S&&(async()=>{if(!e.recordId||e.mode===`create`){g(e.initialData||e.initialValues||{}),y(!1);return}if(!S){if(!n){x(Error(`DataSource is required for fetching record data (inline data not provided)`)),y(!1);return}y(!0);try{g(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),x(e)}finally{y(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,u,S]),(0,t.useEffect)(()=>{if(S&&e.customFields){p(e.customFields),y(!1);return}if(!u)return;let t=[],r=e.fields||Object.keys(u.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let a=u.fields?.[r];if(!a&&!S)return;let s=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!s)return;let c=e.customFields?.find(e=>e.name===r);if(c)t.push(c);else if(a){let s={name:r,label:o(e.objectName,r,a.label||n),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};if((a.type===`select`||a.type===`lookup`||a.type===`master_detail`)&&(s.options=a.options||[],s.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(s.inputType=`number`,s.min=a.min,s.max=a.max,s.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(s.inputType=`date`),a.type===`datetime`&&(s.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(s.maxLength=a.max_length,s.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(s.inputType=`file`,s.multiple=a.multiple,s.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${(0,i.formatFileSize)(a.max_size)}`;s.description=s.description?`${s.description} (${e})`:e}a.type===`email`&&(s.inputType=`email`),a.type===`phone`&&(s.inputType=`tel`),a.type===`url`&&(s.inputType=`url`),a.type===`password`&&(s.inputType=`password`),a.type===`time`&&(s.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(s.disabled=!0),a.visible_on&&(s.visible=e=>(0,i.evaluateCondition)(a.visible_on,e)),t.push(s)}}),p(t),!S&&e.recordId&&e.mode!==`create`&&n||y(!1)},[u,e.fields,e.customFields,e.readOnly,e.mode,S,e.recordId,n]);let C=(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={})),S&&!n)return e.onSuccess&&await e.onSuccess(t),t;if(!n)throw Error(`DataSource is required for form submission (inline mode not configured)`);try{let r;if(e.mode===`create`)r=await n.create(e.objectName,t);else if(e.mode===`edit`&&e.recordId)r=await n.update(e.objectName,e.recordId,t);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,n,S]),w=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),T={...t.default.useMemo(()=>{if(!u?.fields)return{};let e={};return Object.keys(u.fields).forEach(t=>{let n=u.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[u]),...m};if(b)return(0,s.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:b.message})]});if(v)return(0,s.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let E=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,s.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.filter(e=>i.includes(e.name));return(0,s.jsx)(h,{label:t.name?c(e.objectName,t.name,t.label||t.name):t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,s.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:E,defaultValues:T,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:C,onCancel:w}})},t.name||t.label||n)})});let D=e.sections?.length,O=D?{fields:f,columns:e.columns}:k(f,u,e.columns,e.mode),A=e.mobile,j=A?.fullscreenLongText?O.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}):O.fields,M=A?.stepper,N=A?.stepperMinFields??8,P=Math.max(1,A?.stepperFieldsPerStep??1);if(!e.formType&&!D&&j.length>=2&&(M===!0||M===`auto`&&l&&j.length>=N)){let t=j,r=[];for(let e=0;e<t.length;e+=P){let n=t.slice(e,e+P);r.push({name:`step-${Math.floor(e/P)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/P)+1}`,fields:n})}return(0,s.jsx)(_,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let F={type:`form`,fields:j,layout:E,columns:O.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:T,onSubmit:C,onCancel:w,className:e.className,mobileStickyActions:!!A?.stickyActions};return(0,s.jsx)(`div`,{className:A?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":A?`true`:void 0,children:(0,s.jsx)(r.SchemaRenderer,{schema:F})})},B=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[a,o]=(0,t.useState)(!1),[c,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,s.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,s.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,s.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,s.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,s.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,s.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,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,s.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,s.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,s.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,s.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,s.jsxs)(`div`,{className:`p-6`,children:[u&&(0,s.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:u}),(0,s.jsx)(R,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:f,onSuccess:p,submitLabel:c?`Submitting...`:`Submit`},dataSource:n})]}),(0,s.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function V(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 H=({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]),c=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,s.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,s.jsx)(a.Card,{children:(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,s.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,s.jsxs)(a.Card,{children:[(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,s.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,s.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,s.jsx)(a.Card,{children:(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,s.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?V(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,s.jsxs)(a.Card,{children:[(0,s.jsx)(a.CardHeader,{children:(0,s.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,s.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/c*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,s.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,s.jsxs)(a.Card,{children:[(0,s.jsxs)(a.CardHeader,{children:[(0,s.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,s.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,s.jsxs)(`div`,{className:`space-y-1`,children:[(0,s.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,s.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,s.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,s.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,s.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))})})]})]})},U=({schema:e})=>(0,s.jsx)(R,{schema:e});n.ComponentRegistry.register(`object-form`,U,{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`,U,{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,s.jsx)(B,{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,s.jsx)(H,{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=P,e.EmbeddableForm=B,e.FormAnalytics=H,e.FormSection=h,e.ModalForm=L,e.ObjectForm=R,e.SplitForm=v,e.TabbedForm=g,e.WizardForm=_,e.applyAutoColSpan=T,e.applyAutoLayout=k,e.filterCreateModeFields=D,e.inferColumns=w,e.inferModalSize=O,e.isAutoGeneratedFieldType=C,e.isWideFieldType=S});
@@ -0,0 +1,22 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * Strip server-managed and computed fields from a form payload before sending
10
+ * it to `dataSource.create()` / `dataSource.update()`.
11
+ *
12
+ * - Drops well-known server-owned keys (id, created_at, organization_id, …).
13
+ * - When `objectSchema` is provided, drops fields that are flagged as
14
+ * `computed` / `formula` / `readOnly` or whose type is in
15
+ * {@link COMPUTED_FIELD_TYPES}.
16
+ * - When `objectSchema` is provided, also drops keys that don't appear in
17
+ * `objectSchema.fields` at all (these are typically server-projected
18
+ * relationships or flattened lookups like `full_name`).
19
+ */
20
+ export declare function sanitizeFormData(data: Record<string, any>, objectSchema?: {
21
+ fields?: Record<string, any>;
22
+ } | null): Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-form",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Form plugin for Object UI",
@@ -16,11 +16,11 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "lucide-react": "^1.14.0",
19
- "@object-ui/components": "4.0.6",
20
- "@object-ui/core": "4.0.6",
21
- "@object-ui/fields": "4.0.6",
22
- "@object-ui/react": "4.0.6",
23
- "@object-ui/types": "4.0.6"
19
+ "@object-ui/components": "4.0.8",
20
+ "@object-ui/core": "4.0.8",
21
+ "@object-ui/fields": "4.0.8",
22
+ "@object-ui/react": "4.0.8",
23
+ "@object-ui/types": "4.0.8"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^18.0.0 || ^19.0.0",
@@ -28,11 +28,11 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@vitejs/plugin-react": "^6.0.1",
31
- "msw": "^2.14.2",
31
+ "msw": "^2.14.6",
32
32
  "typescript": "^6.0.3",
33
- "vite": "^8.0.10",
33
+ "vite": "^8.0.12",
34
34
  "vite-plugin-dts": "^5.0.0",
35
- "@object-ui/data-objectstack": "4.0.6"
35
+ "@object-ui/data-objectstack": "4.0.8"
36
36
  },
37
37
  "keywords": [
38
38
  "objectui",