@object-ui/plugin-form 0.5.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,409 +1,1514 @@
1
- import re, { useState as A, useEffect as I, useCallback as Q } from "react";
2
- import { ComponentRegistry as oe } from "@object-ui/core";
3
- import { SchemaRenderer as ie } from "@object-ui/react";
4
- import { buildValidationRules as ae, mapFieldTypeToFormType as le, formatFileSize as se, evaluateCondition as ue } from "@object-ui/fields";
5
- var D = { exports: {} }, P = {};
6
- var Z;
7
- function ce() {
8
- if (Z) return P;
9
- Z = 1;
10
- var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), c = /* @__PURE__ */ Symbol.for("react.fragment");
11
- function f(_, m, b) {
1
+ import J, { useState as g, useCallback as k, useMemo as Q, useEffect as W } from "react";
2
+ import { ComponentRegistry as ue } from "@object-ui/core";
3
+ import { SchemaRenderer as M } from "@object-ui/react";
4
+ import { buildValidationRules as Y, mapFieldTypeToFormType as U, formatFileSize as ye, evaluateCondition as xe } from "@object-ui/fields";
5
+ import { cn as V, Tabs as je, TabsList as ge, TabsTrigger as we, TabsContent as ve, Button as K, ResizablePanelGroup as Ne, ResizablePanel as se, ResizableHandle as Se, Sheet as Te, SheetContent as Ce, SheetHeader as Ee, SheetTitle as Oe, SheetDescription as _e, Dialog as Re, DialogContent as De, DialogHeader as Fe, DialogTitle as ke, DialogDescription as Ie } from "@object-ui/components";
6
+ import { ChevronRight as pe, ChevronDown as ze, Check as Pe, ChevronLeft as Le } from "lucide-react";
7
+ var ee = { exports: {} }, B = {};
8
+ var ae;
9
+ function Ae() {
10
+ if (ae) return B;
11
+ ae = 1;
12
+ var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), l = /* @__PURE__ */ Symbol.for("react.fragment");
13
+ function f(d, w, b) {
12
14
  var T = null;
13
- if (b !== void 0 && (T = "" + b), m.key !== void 0 && (T = "" + m.key), "key" in m) {
15
+ if (b !== void 0 && (T = "" + b), w.key !== void 0 && (T = "" + w.key), "key" in w) {
14
16
  b = {};
15
- for (var y in m)
16
- y !== "key" && (b[y] = m[y]);
17
- } else b = m;
18
- return m = b.ref, {
19
- $$typeof: r,
20
- type: _,
17
+ for (var E in w)
18
+ E !== "key" && (b[E] = w[E]);
19
+ } else b = w;
20
+ return w = b.ref, {
21
+ $$typeof: e,
22
+ type: d,
21
23
  key: T,
22
- ref: m !== void 0 ? m : null,
24
+ ref: w !== void 0 ? w : null,
23
25
  props: b
24
26
  };
25
27
  }
26
- return P.Fragment = c, P.jsx = f, P.jsxs = f, P;
28
+ return B.Fragment = l, B.jsx = f, B.jsxs = f, B;
27
29
  }
28
- var F = {};
29
- var K;
30
- function fe() {
31
- return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
32
- function r(e) {
33
- if (e == null) return null;
34
- if (typeof e == "function")
35
- return e.$$typeof === O ? null : e.displayName || e.name || null;
36
- if (typeof e == "string") return e;
37
- switch (e) {
38
- case N:
30
+ var X = {};
31
+ var de;
32
+ function he() {
33
+ return de || (de = 1, process.env.NODE_ENV !== "production" && (function() {
34
+ function e(r) {
35
+ if (r == null) return null;
36
+ if (typeof r == "function")
37
+ return r.$$typeof === $ ? null : r.displayName || r.name || null;
38
+ if (typeof r == "string") return r;
39
+ switch (r) {
40
+ case F:
39
41
  return "Fragment";
40
- case a:
42
+ case q:
41
43
  return "Profiler";
42
- case $:
44
+ case _:
43
45
  return "StrictMode";
44
- case x:
46
+ case o:
45
47
  return "Suspense";
46
- case t:
48
+ case a:
47
49
  return "SuspenseList";
48
- case o:
50
+ case v:
49
51
  return "Activity";
50
52
  }
51
- if (typeof e == "object")
52
- switch (typeof e.tag == "number" && console.error(
53
+ if (typeof r == "object")
54
+ switch (typeof r.tag == "number" && console.error(
53
55
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
54
- ), e.$$typeof) {
55
- case W:
56
+ ), r.$$typeof) {
57
+ case h:
56
58
  return "Portal";
57
- case p:
58
- return e.displayName || "Context";
59
- case l:
60
- return (e._context.displayName || "Context") + ".Consumer";
61
- case j:
62
- var n = e.render;
63
- return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
64
- case V:
65
- return n = e.displayName || null, n !== null ? n : r(e.type) || "Memo";
66
- case g:
67
- n = e._payload, e = e._init;
59
+ case s:
60
+ return r.displayName || "Context";
61
+ case u:
62
+ return (r._context.displayName || "Context") + ".Consumer";
63
+ case n:
64
+ var m = r.render;
65
+ return r = r.displayName, r || (r = m.displayName || m.name || "", r = r !== "" ? "ForwardRef(" + r + ")" : "ForwardRef"), r;
66
+ case c:
67
+ return m = r.displayName || null, m !== null ? m : e(r.type) || "Memo";
68
+ case i:
69
+ m = r._payload, r = r._init;
68
70
  try {
69
- return r(e(n));
71
+ return e(r(m));
70
72
  } catch {
71
73
  }
72
74
  }
73
75
  return null;
74
76
  }
75
- function c(e) {
76
- return "" + e;
77
+ function l(r) {
78
+ return "" + r;
77
79
  }
78
- function f(e) {
80
+ function f(r) {
79
81
  try {
80
- c(e);
81
- var n = !1;
82
+ l(r);
83
+ var m = !1;
82
84
  } catch {
83
- n = !0;
85
+ m = !0;
84
86
  }
85
- if (n) {
86
- n = console;
87
- var i = n.error, s = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
88
- return i.call(
89
- n,
87
+ if (m) {
88
+ m = console;
89
+ var O = m.error, I = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
90
+ return O.call(
91
+ m,
90
92
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
91
- s
92
- ), c(e);
93
+ I
94
+ ), l(r);
93
95
  }
94
96
  }
95
- function _(e) {
96
- if (e === N) return "<>";
97
- if (typeof e == "object" && e !== null && e.$$typeof === g)
97
+ function d(r) {
98
+ if (r === F) return "<>";
99
+ if (typeof r == "object" && r !== null && r.$$typeof === i)
98
100
  return "<...>";
99
101
  try {
100
- var n = r(e);
101
- return n ? "<" + n + ">" : "<...>";
102
+ var m = e(r);
103
+ return m ? "<" + m + ">" : "<...>";
102
104
  } catch {
103
105
  return "<...>";
104
106
  }
105
107
  }
106
- function m() {
107
- var e = L.A;
108
- return e === null ? null : e.getOwner();
108
+ function w() {
109
+ var r = p.A;
110
+ return r === null ? null : r.getOwner();
109
111
  }
110
112
  function b() {
111
113
  return Error("react-stack-top-frame");
112
114
  }
113
- function T(e) {
114
- if (U.call(e, "key")) {
115
- var n = Object.getOwnPropertyDescriptor(e, "key").get;
116
- if (n && n.isReactWarning) return !1;
115
+ function T(r) {
116
+ if (x.call(r, "key")) {
117
+ var m = Object.getOwnPropertyDescriptor(r, "key").get;
118
+ if (m && m.isReactWarning) return !1;
117
119
  }
118
- return e.key !== void 0;
120
+ return r.key !== void 0;
119
121
  }
120
- function y(e, n) {
121
- function i() {
122
- J || (J = !0, console.error(
122
+ function E(r, m) {
123
+ function O() {
124
+ A || (A = !0, console.error(
123
125
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
124
- n
126
+ m
125
127
  ));
126
128
  }
127
- i.isReactWarning = !0, Object.defineProperty(e, "key", {
128
- get: i,
129
+ O.isReactWarning = !0, Object.defineProperty(r, "key", {
130
+ get: O,
129
131
  configurable: !0
130
132
  });
131
133
  }
132
- function Y() {
133
- var e = r(this.type);
134
- return G[e] || (G[e] = !0, console.error(
134
+ function S() {
135
+ var r = e(this.type);
136
+ return le[r] || (le[r] = !0, console.error(
135
137
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
136
- )), e = this.props.ref, e !== void 0 ? e : null;
137
- }
138
- function v(e, n, i, s, C, q) {
139
- var u = i.ref;
140
- return e = {
141
- $$typeof: h,
142
- type: e,
143
- key: n,
144
- props: i,
145
- _owner: s
146
- }, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
138
+ )), r = this.props.ref, r !== void 0 ? r : null;
139
+ }
140
+ function C(r, m, O, I, Z, te) {
141
+ var z = O.ref;
142
+ return r = {
143
+ $$typeof: P,
144
+ type: r,
145
+ key: m,
146
+ props: O,
147
+ _owner: I
148
+ }, (z !== void 0 ? z : null) !== null ? Object.defineProperty(r, "ref", {
147
149
  enumerable: !1,
148
- get: Y
149
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
150
+ get: S
151
+ }) : Object.defineProperty(r, "ref", { enumerable: !1, value: null }), r._store = {}, Object.defineProperty(r._store, "validated", {
150
152
  configurable: !1,
151
153
  enumerable: !1,
152
154
  writable: !0,
153
155
  value: 0
154
- }), Object.defineProperty(e, "_debugInfo", {
156
+ }), Object.defineProperty(r, "_debugInfo", {
155
157
  configurable: !1,
156
158
  enumerable: !1,
157
159
  writable: !0,
158
160
  value: null
159
- }), Object.defineProperty(e, "_debugStack", {
161
+ }), Object.defineProperty(r, "_debugStack", {
160
162
  configurable: !1,
161
163
  enumerable: !1,
162
164
  writable: !0,
163
- value: C
164
- }), Object.defineProperty(e, "_debugTask", {
165
+ value: Z
166
+ }), Object.defineProperty(r, "_debugTask", {
165
167
  configurable: !1,
166
168
  enumerable: !1,
167
169
  writable: !0,
168
- value: q
169
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
170
- }
171
- function S(e, n, i, s, C, q) {
172
- var u = n.children;
173
- if (u !== void 0)
174
- if (s)
175
- if (te(u)) {
176
- for (s = 0; s < u.length; s++)
177
- R(u[s]);
178
- Object.freeze && Object.freeze(u);
170
+ value: te
171
+ }), Object.freeze && (Object.freeze(r.props), Object.freeze(r)), r;
172
+ }
173
+ function j(r, m, O, I, Z, te) {
174
+ var z = m.children;
175
+ if (z !== void 0)
176
+ if (I)
177
+ if (R(z)) {
178
+ for (I = 0; I < z.length; I++)
179
+ y(z[I]);
180
+ Object.freeze && Object.freeze(z);
179
181
  } else
180
182
  console.error(
181
183
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
182
184
  );
183
- else R(u);
184
- if (U.call(n, "key")) {
185
- u = r(e);
186
- var k = Object.keys(n).filter(function(ne) {
187
- return ne !== "key";
185
+ else y(z);
186
+ if (x.call(m, "key")) {
187
+ z = e(r);
188
+ var H = Object.keys(m).filter(function(me) {
189
+ return me !== "key";
188
190
  });
189
- s = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", B[u + s] || (k = 0 < k.length ? "{" + k.join(": ..., ") + ": ...}" : "{}", console.error(
191
+ I = 0 < H.length ? "{key: someKey, " + H.join(": ..., ") + ": ...}" : "{key: someKey}", oe[z + I] || (H = 0 < H.length ? "{" + H.join(": ..., ") + ": ...}" : "{}", console.error(
190
192
  `A props object containing a "key" prop is being spread into JSX:
191
193
  let props = %s;
192
194
  <%s {...props} />
193
195
  React keys must be passed directly to JSX without using spread:
194
196
  let props = %s;
195
197
  <%s key={someKey} {...props} />`,
196
- s,
197
- u,
198
- k,
199
- u
200
- ), B[u + s] = !0);
201
- }
202
- if (u = null, i !== void 0 && (f(i), u = "" + i), T(n) && (f(n.key), u = "" + n.key), "key" in n) {
203
- i = {};
204
- for (var z in n)
205
- z !== "key" && (i[z] = n[z]);
206
- } else i = n;
207
- return u && y(
208
- i,
209
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
210
- ), v(
211
- e,
212
- u,
213
- i,
214
- m(),
215
- C,
216
- q
198
+ I,
199
+ z,
200
+ H,
201
+ z
202
+ ), oe[z + I] = !0);
203
+ }
204
+ if (z = null, O !== void 0 && (f(O), z = "" + O), T(m) && (f(m.key), z = "" + m.key), "key" in m) {
205
+ O = {};
206
+ for (var re in m)
207
+ re !== "key" && (O[re] = m[re]);
208
+ } else O = m;
209
+ return z && E(
210
+ O,
211
+ typeof r == "function" ? r.displayName || r.name || "Unknown" : r
212
+ ), C(
213
+ r,
214
+ z,
215
+ O,
216
+ w(),
217
+ Z,
218
+ te
217
219
  );
218
220
  }
219
- function R(e) {
220
- d(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === g && (e._payload.status === "fulfilled" ? d(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
221
+ function y(r) {
222
+ N(r) ? r._store && (r._store.validated = 1) : typeof r == "object" && r !== null && r.$$typeof === i && (r._payload.status === "fulfilled" ? N(r._payload.value) && r._payload.value._store && (r._payload.value._store.validated = 1) : r._store && (r._store.validated = 1));
221
223
  }
222
- function d(e) {
223
- return typeof e == "object" && e !== null && e.$$typeof === h;
224
+ function N(r) {
225
+ return typeof r == "object" && r !== null && r.$$typeof === P;
224
226
  }
225
- var w = re, h = /* @__PURE__ */ Symbol.for("react.transitional.element"), W = /* @__PURE__ */ Symbol.for("react.portal"), N = /* @__PURE__ */ Symbol.for("react.fragment"), $ = /* @__PURE__ */ Symbol.for("react.strict_mode"), a = /* @__PURE__ */ Symbol.for("react.profiler"), l = /* @__PURE__ */ Symbol.for("react.consumer"), p = /* @__PURE__ */ Symbol.for("react.context"), j = /* @__PURE__ */ Symbol.for("react.forward_ref"), x = /* @__PURE__ */ Symbol.for("react.suspense"), t = /* @__PURE__ */ Symbol.for("react.suspense_list"), V = /* @__PURE__ */ Symbol.for("react.memo"), g = /* @__PURE__ */ Symbol.for("react.lazy"), o = /* @__PURE__ */ Symbol.for("react.activity"), O = /* @__PURE__ */ Symbol.for("react.client.reference"), L = w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, U = Object.prototype.hasOwnProperty, te = Array.isArray, M = console.createTask ? console.createTask : function() {
227
+ var D = J, P = /* @__PURE__ */ Symbol.for("react.transitional.element"), h = /* @__PURE__ */ Symbol.for("react.portal"), F = /* @__PURE__ */ Symbol.for("react.fragment"), _ = /* @__PURE__ */ Symbol.for("react.strict_mode"), q = /* @__PURE__ */ Symbol.for("react.profiler"), u = /* @__PURE__ */ Symbol.for("react.consumer"), s = /* @__PURE__ */ Symbol.for("react.context"), n = /* @__PURE__ */ Symbol.for("react.forward_ref"), o = /* @__PURE__ */ Symbol.for("react.suspense"), a = /* @__PURE__ */ Symbol.for("react.suspense_list"), c = /* @__PURE__ */ Symbol.for("react.memo"), i = /* @__PURE__ */ Symbol.for("react.lazy"), v = /* @__PURE__ */ Symbol.for("react.activity"), $ = /* @__PURE__ */ Symbol.for("react.client.reference"), p = D.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, x = Object.prototype.hasOwnProperty, R = Array.isArray, L = console.createTask ? console.createTask : function() {
226
228
  return null;
227
229
  };
228
- w = {
229
- react_stack_bottom_frame: function(e) {
230
- return e();
230
+ D = {
231
+ react_stack_bottom_frame: function(r) {
232
+ return r();
231
233
  }
232
234
  };
233
- var J, G = {}, X = w.react_stack_bottom_frame.bind(
234
- w,
235
+ var A, le = {}, ne = D.react_stack_bottom_frame.bind(
236
+ D,
235
237
  b
236
- )(), H = M(_(b)), B = {};
237
- F.Fragment = N, F.jsx = function(e, n, i) {
238
- var s = 1e4 > L.recentlyCreatedOwnerStacks++;
239
- return S(
240
- e,
241
- n,
242
- i,
238
+ )(), ie = L(d(b)), oe = {};
239
+ X.Fragment = F, X.jsx = function(r, m, O) {
240
+ var I = 1e4 > p.recentlyCreatedOwnerStacks++;
241
+ return j(
242
+ r,
243
+ m,
244
+ O,
243
245
  !1,
244
- s ? Error("react-stack-top-frame") : X,
245
- s ? M(_(e)) : H
246
+ I ? Error("react-stack-top-frame") : ne,
247
+ I ? L(d(r)) : ie
246
248
  );
247
- }, F.jsxs = function(e, n, i) {
248
- var s = 1e4 > L.recentlyCreatedOwnerStacks++;
249
- return S(
250
- e,
251
- n,
252
- i,
249
+ }, X.jsxs = function(r, m, O) {
250
+ var I = 1e4 > p.recentlyCreatedOwnerStacks++;
251
+ return j(
252
+ r,
253
+ m,
254
+ O,
253
255
  !0,
254
- s ? Error("react-stack-top-frame") : X,
255
- s ? M(_(e)) : H
256
+ I ? Error("react-stack-top-frame") : ne,
257
+ I ? L(d(r)) : ie
256
258
  );
257
259
  };
258
- })()), F;
260
+ })()), X;
259
261
  }
260
- var ee;
261
- function de() {
262
- return ee || (ee = 1, process.env.NODE_ENV === "production" ? D.exports = ce() : D.exports = fe()), D.exports;
262
+ var ce;
263
+ function Ve() {
264
+ return ce || (ce = 1, process.env.NODE_ENV === "production" ? ee.exports = Ae() : ee.exports = he()), ee.exports;
263
265
  }
264
- var E = de();
265
- const pe = ({
266
- schema: r,
267
- dataSource: c
266
+ var t = Ve();
267
+ const G = ({
268
+ label: e,
269
+ description: l,
270
+ collapsible: f = !1,
271
+ collapsed: d = !1,
272
+ columns: w = 1,
273
+ children: b,
274
+ className: T
275
+ }) => {
276
+ const [E, S] = g(d), C = {
277
+ 1: "grid-cols-1",
278
+ 2: "grid-cols-1 md:grid-cols-2",
279
+ 3: "grid-cols-1 md:grid-cols-2 lg:grid-cols-3",
280
+ 4: "grid-cols-1 md:grid-cols-2 lg:grid-cols-4"
281
+ }, j = () => {
282
+ f && S(!E);
283
+ };
284
+ return /* @__PURE__ */ t.jsxs("div", { className: V("form-section", T), children: [
285
+ (e || l) && /* @__PURE__ */ t.jsxs(
286
+ "div",
287
+ {
288
+ className: V(
289
+ "flex items-start gap-2 mb-4",
290
+ f && "cursor-pointer select-none"
291
+ ),
292
+ onClick: j,
293
+ role: f ? "button" : void 0,
294
+ "aria-expanded": f ? !E : void 0,
295
+ children: [
296
+ f && /* @__PURE__ */ t.jsx("span", { className: "mt-0.5 text-muted-foreground", children: E ? /* @__PURE__ */ t.jsx(pe, { className: "h-4 w-4" }) : /* @__PURE__ */ t.jsx(ze, { className: "h-4 w-4" }) }),
297
+ /* @__PURE__ */ t.jsxs("div", { className: "flex-1", children: [
298
+ e && /* @__PURE__ */ t.jsx("h3", { className: "text-base font-semibold text-foreground", children: e }),
299
+ l && /* @__PURE__ */ t.jsx("p", { className: "text-sm text-muted-foreground mt-0.5", children: l })
300
+ ] })
301
+ ]
302
+ }
303
+ ),
304
+ !E && /* @__PURE__ */ t.jsx("div", { className: V("grid gap-4", C[w]), children: b })
305
+ ] });
306
+ }, qe = ({
307
+ schema: e,
308
+ dataSource: l,
309
+ className: f
310
+ }) => {
311
+ const [d, w] = g(null), [b, T] = g({}), [E, S] = g(!0), [C, j] = g(null), [y, N] = g(
312
+ e.defaultTab || e.sections[0]?.name || e.sections[0]?.label || "tab-0"
313
+ );
314
+ J.useEffect(() => {
315
+ (async () => {
316
+ if (!l) {
317
+ S(!1);
318
+ return;
319
+ }
320
+ try {
321
+ const n = await l.getObjectSchema(e.objectName);
322
+ w(n);
323
+ } catch (n) {
324
+ j(n);
325
+ }
326
+ })();
327
+ }, [e.objectName, l]), J.useEffect(() => {
328
+ (d || !l) && (async () => {
329
+ if (e.mode === "create" || !e.recordId || !l) {
330
+ T(e.initialData || e.initialValues || {}), S(!1);
331
+ return;
332
+ }
333
+ try {
334
+ const n = await l.findOne(e.objectName, e.recordId);
335
+ T(n || {});
336
+ } catch (n) {
337
+ j(n);
338
+ } finally {
339
+ S(!1);
340
+ }
341
+ })();
342
+ }, [d, e.mode, e.recordId, e.initialData, e.initialValues, l, e.objectName]);
343
+ const D = k((s) => {
344
+ const n = [];
345
+ for (const o of s.fields) {
346
+ const a = typeof o == "string" ? o : o.name;
347
+ if (typeof o == "object")
348
+ n.push(o);
349
+ else if (d?.fields?.[a]) {
350
+ const c = d.fields[a];
351
+ n.push({
352
+ name: a,
353
+ label: c.label || a,
354
+ type: U(c.type),
355
+ required: c.required || !1,
356
+ disabled: e.readOnly || e.mode === "view" || c.readonly,
357
+ placeholder: c.placeholder,
358
+ description: c.help || c.description,
359
+ validation: Y(c),
360
+ field: c,
361
+ options: c.options,
362
+ multiple: c.multiple
363
+ });
364
+ } else
365
+ n.push({
366
+ name: a,
367
+ label: a,
368
+ type: "input"
369
+ });
370
+ }
371
+ return n;
372
+ }, [d, e.readOnly, e.mode]), P = k(async (s) => {
373
+ if (!l)
374
+ return e.onSuccess && await e.onSuccess(s), s;
375
+ try {
376
+ let n;
377
+ return e.mode === "create" ? n = await l.create(e.objectName, s) : e.mode === "edit" && e.recordId && (n = await l.update(e.objectName, e.recordId, s)), e.onSuccess && await e.onSuccess(n), n;
378
+ } catch (n) {
379
+ throw e.onError && e.onError(n), n;
380
+ }
381
+ }, [e, l]), h = k(() => {
382
+ e.onCancel && e.onCancel();
383
+ }, [e]), F = (s, n) => s.name || s.label || `tab-${n}`;
384
+ if (C)
385
+ return /* @__PURE__ */ t.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
386
+ /* @__PURE__ */ t.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading form" }),
387
+ /* @__PURE__ */ t.jsx("p", { className: "text-red-600 text-sm mt-1", children: C.message })
388
+ ] });
389
+ if (E)
390
+ return /* @__PURE__ */ t.jsxs("div", { className: "p-8 text-center", children: [
391
+ /* @__PURE__ */ t.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
392
+ /* @__PURE__ */ t.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading form..." })
393
+ ] });
394
+ const q = {
395
+ type: "form",
396
+ fields: e.sections.flatMap((s) => D(s)),
397
+ layout: "vertical",
398
+ defaultValues: b,
399
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
400
+ cancelLabel: e.cancelText,
401
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
402
+ showCancel: e.showCancel !== !1,
403
+ onSubmit: P,
404
+ onCancel: h
405
+ }, u = e.tabPosition === "left" || e.tabPosition === "right";
406
+ return /* @__PURE__ */ t.jsx("div", { className: V("w-full", f, e.className), children: /* @__PURE__ */ t.jsxs(
407
+ je,
408
+ {
409
+ value: y,
410
+ onValueChange: N,
411
+ orientation: u ? "vertical" : "horizontal",
412
+ className: V(u && "flex gap-4"),
413
+ children: [
414
+ /* @__PURE__ */ t.jsx(ge, { className: V(
415
+ u ? "flex-col h-auto" : "",
416
+ e.tabPosition === "bottom" && "order-last",
417
+ e.tabPosition === "right" && "order-last"
418
+ ), children: e.sections.map((s, n) => /* @__PURE__ */ t.jsx(
419
+ we,
420
+ {
421
+ value: F(s, n),
422
+ className: u ? "w-full justify-start" : "",
423
+ children: s.label || `Tab ${n + 1}`
424
+ },
425
+ F(s, n)
426
+ )) }),
427
+ /* @__PURE__ */ t.jsx("div", { className: "flex-1", children: e.sections.map((s, n) => /* @__PURE__ */ t.jsx(
428
+ ve,
429
+ {
430
+ value: F(s, n),
431
+ className: "mt-0",
432
+ children: /* @__PURE__ */ t.jsx(
433
+ G,
434
+ {
435
+ description: s.description,
436
+ columns: s.columns || 1,
437
+ children: /* @__PURE__ */ t.jsx(
438
+ M,
439
+ {
440
+ schema: {
441
+ ...q,
442
+ fields: D(s),
443
+ // Only show buttons on the last tab or always visible
444
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
445
+ showCancel: e.showCancel !== !1
446
+ }
447
+ }
448
+ )
449
+ }
450
+ )
451
+ },
452
+ F(s, n)
453
+ )) })
454
+ ]
455
+ }
456
+ ) });
457
+ }, We = ({
458
+ schema: e,
459
+ dataSource: l,
460
+ className: f
461
+ }) => {
462
+ const [d, w] = g(null), [b, T] = g({}), [E, S] = g(!0), [C, j] = g(null), [y, N] = g(0), [D, P] = g(/* @__PURE__ */ new Set()), [h, F] = g(!1), _ = e.sections.length, q = y === 0, u = y === _ - 1;
463
+ J.useEffect(() => {
464
+ (async () => {
465
+ if (!l) {
466
+ S(!1);
467
+ return;
468
+ }
469
+ try {
470
+ const x = await l.getObjectSchema(e.objectName);
471
+ w(x);
472
+ } catch (x) {
473
+ j(x);
474
+ }
475
+ })();
476
+ }, [e.objectName, l]), J.useEffect(() => {
477
+ (d || !l) && (async () => {
478
+ if (e.mode === "create" || !e.recordId || !l) {
479
+ T(e.initialData || e.initialValues || {}), S(!1);
480
+ return;
481
+ }
482
+ try {
483
+ const x = await l.findOne(e.objectName, e.recordId);
484
+ T(x || {});
485
+ } catch (x) {
486
+ j(x);
487
+ } finally {
488
+ S(!1);
489
+ }
490
+ })();
491
+ }, [d, e.mode, e.recordId, e.initialData, e.initialValues, l, e.objectName]);
492
+ const s = k((p) => {
493
+ const x = [];
494
+ for (const R of p.fields) {
495
+ const L = typeof R == "string" ? R : R.name;
496
+ if (typeof R == "object")
497
+ x.push(R);
498
+ else if (d?.fields?.[L]) {
499
+ const A = d.fields[L];
500
+ x.push({
501
+ name: L,
502
+ label: A.label || L,
503
+ type: U(A.type),
504
+ required: A.required || !1,
505
+ disabled: e.readOnly || e.mode === "view" || A.readonly,
506
+ placeholder: A.placeholder,
507
+ description: A.help || A.description,
508
+ validation: Y(A),
509
+ field: A,
510
+ options: A.options,
511
+ multiple: A.multiple
512
+ });
513
+ } else
514
+ x.push({
515
+ name: L,
516
+ label: L,
517
+ type: "input"
518
+ });
519
+ }
520
+ return x;
521
+ }, [d, e.readOnly, e.mode]), n = Q(() => y >= 0 && y < _ ? s(e.sections[y]) : [], [y, _, e.sections, s]), o = k(async (p) => {
522
+ const x = { ...b, ...p };
523
+ if (T(x), P((R) => new Set(R).add(y)), u) {
524
+ F(!0);
525
+ try {
526
+ if (!l)
527
+ return e.onSuccess && await e.onSuccess(x), x;
528
+ let R;
529
+ return e.mode === "create" ? R = await l.create(e.objectName, x) : e.mode === "edit" && e.recordId && (R = await l.update(e.objectName, e.recordId, x)), e.onSuccess && await e.onSuccess(R), R;
530
+ } catch (R) {
531
+ throw e.onError && e.onError(R), R;
532
+ } finally {
533
+ F(!1);
534
+ }
535
+ } else
536
+ a(y + 1);
537
+ }, [b, y, u, e, l]), a = k((p) => {
538
+ p >= 0 && p < _ && (N(p), e.onStepChange && e.onStepChange(p));
539
+ }, [_, e]), c = k(() => {
540
+ a(y - 1);
541
+ }, [y, a]), i = k(() => {
542
+ e.onCancel && e.onCancel();
543
+ }, [e]), v = k((p) => {
544
+ (e.allowSkip || D.has(p) || p <= y) && a(p);
545
+ }, [e.allowSkip, D, y, a]);
546
+ if (C)
547
+ return /* @__PURE__ */ t.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
548
+ /* @__PURE__ */ t.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading form" }),
549
+ /* @__PURE__ */ t.jsx("p", { className: "text-red-600 text-sm mt-1", children: C.message })
550
+ ] });
551
+ if (E)
552
+ return /* @__PURE__ */ t.jsxs("div", { className: "p-8 text-center", children: [
553
+ /* @__PURE__ */ t.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
554
+ /* @__PURE__ */ t.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading form..." })
555
+ ] });
556
+ const $ = e.sections[y];
557
+ return /* @__PURE__ */ t.jsxs("div", { className: V("w-full", f, e.className), children: [
558
+ e.showStepIndicator !== !1 && /* @__PURE__ */ t.jsx("nav", { "aria-label": "Progress", className: "mb-8", children: /* @__PURE__ */ t.jsx("ol", { className: "flex items-center", children: e.sections.map((p, x) => {
559
+ const R = x === y, L = D.has(x), A = e.allowSkip || L || x <= y;
560
+ return /* @__PURE__ */ t.jsxs(
561
+ "li",
562
+ {
563
+ className: V(
564
+ "relative flex-1",
565
+ x !== _ - 1 && "pr-8 sm:pr-12"
566
+ ),
567
+ children: [
568
+ x !== _ - 1 && /* @__PURE__ */ t.jsx(
569
+ "div",
570
+ {
571
+ className: "absolute top-4 left-8 -right-4 sm:left-10 sm:-right-2 h-0.5",
572
+ "aria-hidden": "true",
573
+ children: /* @__PURE__ */ t.jsx(
574
+ "div",
575
+ {
576
+ className: V(
577
+ "h-full",
578
+ L ? "bg-primary" : "bg-muted"
579
+ )
580
+ }
581
+ )
582
+ }
583
+ ),
584
+ /* @__PURE__ */ t.jsxs(
585
+ "button",
586
+ {
587
+ type: "button",
588
+ className: V(
589
+ "group relative flex items-center",
590
+ A ? "cursor-pointer" : "cursor-not-allowed"
591
+ ),
592
+ onClick: () => v(x),
593
+ disabled: !A,
594
+ children: [
595
+ /* @__PURE__ */ t.jsx(
596
+ "span",
597
+ {
598
+ className: V(
599
+ "flex h-8 w-8 items-center justify-center rounded-full text-sm font-medium transition-colors",
600
+ L && "bg-primary text-primary-foreground",
601
+ R && !L && "border-2 border-primary bg-background text-primary",
602
+ !R && !L && "border-2 border-muted bg-background text-muted-foreground"
603
+ ),
604
+ children: L ? /* @__PURE__ */ t.jsx(Pe, { className: "h-4 w-4" }) : x + 1
605
+ }
606
+ ),
607
+ /* @__PURE__ */ t.jsx("span", { className: "ml-3 text-sm font-medium hidden sm:block", children: /* @__PURE__ */ t.jsx(
608
+ "span",
609
+ {
610
+ className: V(
611
+ R ? "text-foreground" : "text-muted-foreground"
612
+ ),
613
+ children: p.label || `Step ${x + 1}`
614
+ }
615
+ ) })
616
+ ]
617
+ }
618
+ )
619
+ ]
620
+ },
621
+ x
622
+ );
623
+ }) }) }),
624
+ /* @__PURE__ */ t.jsx("div", { className: "min-h-[200px]", children: $ && /* @__PURE__ */ t.jsx(
625
+ G,
626
+ {
627
+ label: $.label,
628
+ description: $.description,
629
+ columns: $.columns || 1,
630
+ children: n.length > 0 ? /* @__PURE__ */ t.jsx(
631
+ M,
632
+ {
633
+ schema: {
634
+ type: "form",
635
+ fields: n,
636
+ layout: "vertical",
637
+ defaultValues: b,
638
+ showSubmit: !1,
639
+ showCancel: !1,
640
+ onSubmit: o
641
+ }
642
+ }
643
+ ) : /* @__PURE__ */ t.jsx("div", { className: "text-center py-8 text-muted-foreground", children: "No fields configured for this step" })
644
+ }
645
+ ) }),
646
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center justify-between mt-6 pt-4 border-t", children: [
647
+ /* @__PURE__ */ t.jsx("div", { children: e.showCancel !== !1 && /* @__PURE__ */ t.jsx(
648
+ K,
649
+ {
650
+ variant: "ghost",
651
+ onClick: i,
652
+ children: e.cancelText || "Cancel"
653
+ }
654
+ ) }),
655
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-2", children: [
656
+ /* @__PURE__ */ t.jsxs("span", { className: "text-sm text-muted-foreground mr-2", children: [
657
+ "Step ",
658
+ y + 1,
659
+ " of ",
660
+ _
661
+ ] }),
662
+ !q && /* @__PURE__ */ t.jsxs(
663
+ K,
664
+ {
665
+ variant: "outline",
666
+ onClick: c,
667
+ children: [
668
+ /* @__PURE__ */ t.jsx(Le, { className: "h-4 w-4 mr-1" }),
669
+ e.prevText || "Back"
670
+ ]
671
+ }
672
+ ),
673
+ u ? /* @__PURE__ */ t.jsx(
674
+ K,
675
+ {
676
+ onClick: () => o(b),
677
+ disabled: h || e.mode === "view",
678
+ children: h ? "Submitting..." : e.submitText || (e.mode === "create" ? "Create" : "Update")
679
+ }
680
+ ) : /* @__PURE__ */ t.jsxs(
681
+ K,
682
+ {
683
+ onClick: () => o(b),
684
+ children: [
685
+ e.nextText || "Next",
686
+ /* @__PURE__ */ t.jsx(pe, { className: "h-4 w-4 ml-1" })
687
+ ]
688
+ }
689
+ )
690
+ ] })
691
+ ] })
692
+ ] });
693
+ }, $e = ({
694
+ schema: e,
695
+ dataSource: l,
696
+ className: f
697
+ }) => {
698
+ const [d, w] = g(null), [b, T] = g({}), [E, S] = g(!0), [C, j] = g(null);
699
+ W(() => {
700
+ (async () => {
701
+ if (!l) {
702
+ S(!1);
703
+ return;
704
+ }
705
+ try {
706
+ const n = await l.getObjectSchema(e.objectName);
707
+ w(n);
708
+ } catch (n) {
709
+ j(n), S(!1);
710
+ }
711
+ })();
712
+ }, [e.objectName, l]), W(() => {
713
+ (d || !l) && (async () => {
714
+ if (e.mode === "create" || !e.recordId) {
715
+ T(e.initialData || e.initialValues || {}), S(!1);
716
+ return;
717
+ }
718
+ if (!l) {
719
+ T(e.initialData || e.initialValues || {}), S(!1);
720
+ return;
721
+ }
722
+ try {
723
+ const n = await l.findOne(e.objectName, e.recordId);
724
+ T(n || {});
725
+ } catch (n) {
726
+ j(n);
727
+ } finally {
728
+ S(!1);
729
+ }
730
+ })();
731
+ }, [d, e.mode, e.recordId, e.initialData, e.initialValues, l, e.objectName]);
732
+ const y = k((s) => {
733
+ const n = [];
734
+ for (const o of s.fields) {
735
+ const a = typeof o == "string" ? o : o.name;
736
+ if (typeof o == "object")
737
+ n.push(o);
738
+ else if (d?.fields?.[a]) {
739
+ const c = d.fields[a];
740
+ n.push({
741
+ name: a,
742
+ label: c.label || a,
743
+ type: U(c.type),
744
+ required: c.required || !1,
745
+ disabled: e.readOnly || e.mode === "view" || c.readonly,
746
+ placeholder: c.placeholder,
747
+ description: c.help || c.description,
748
+ validation: Y(c),
749
+ field: c,
750
+ options: c.options,
751
+ multiple: c.multiple
752
+ });
753
+ } else
754
+ n.push({
755
+ name: a,
756
+ label: a,
757
+ type: "input"
758
+ });
759
+ }
760
+ return n;
761
+ }, [d, e.readOnly, e.mode]), N = k(async (s) => {
762
+ if (!l)
763
+ return e.onSuccess && await e.onSuccess(s), s;
764
+ try {
765
+ let n;
766
+ return e.mode === "create" ? n = await l.create(e.objectName, s) : e.mode === "edit" && e.recordId && (n = await l.update(e.objectName, e.recordId, s)), e.onSuccess && await e.onSuccess(n), n;
767
+ } catch (n) {
768
+ throw e.onError && e.onError(n), n;
769
+ }
770
+ }, [e, l]), D = k(() => {
771
+ e.onCancel && e.onCancel();
772
+ }, [e]), P = Q(() => e.sections.slice(0, 1), [e.sections]), h = Q(() => e.sections.slice(1), [e.sections]);
773
+ Q(
774
+ () => e.sections.flatMap((s) => y(s)),
775
+ [e.sections, y]
776
+ );
777
+ const F = e.splitDirection || "horizontal", _ = e.splitSize || 50;
778
+ if (C)
779
+ return /* @__PURE__ */ t.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
780
+ /* @__PURE__ */ t.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading form" }),
781
+ /* @__PURE__ */ t.jsx("p", { className: "text-red-600 text-sm mt-1", children: C.message })
782
+ ] });
783
+ if (E)
784
+ return /* @__PURE__ */ t.jsxs("div", { className: "p-8 text-center", children: [
785
+ /* @__PURE__ */ t.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
786
+ /* @__PURE__ */ t.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading form..." })
787
+ ] });
788
+ const q = {
789
+ type: "form",
790
+ layout: "vertical",
791
+ defaultValues: b,
792
+ onSubmit: N,
793
+ onCancel: D
794
+ }, u = (s, n) => /* @__PURE__ */ t.jsx("div", { className: "space-y-4 p-4", children: s.map((o, a) => /* @__PURE__ */ t.jsx(
795
+ G,
796
+ {
797
+ label: o.label,
798
+ description: o.description,
799
+ columns: o.columns || 1,
800
+ children: /* @__PURE__ */ t.jsx(
801
+ M,
802
+ {
803
+ schema: {
804
+ ...q,
805
+ fields: y(o),
806
+ showSubmit: n && e.showSubmit !== !1 && e.mode !== "view",
807
+ showCancel: n && e.showCancel !== !1,
808
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
809
+ cancelLabel: e.cancelText
810
+ }
811
+ }
812
+ )
813
+ },
814
+ o.name || o.label || a
815
+ )) });
816
+ return /* @__PURE__ */ t.jsx("div", { className: V("w-full", f, e.className), children: /* @__PURE__ */ t.jsxs(Ne, { orientation: F, className: "min-h-[300px] rounded-lg border", children: [
817
+ /* @__PURE__ */ t.jsx(se, { defaultSize: _, minSize: 20, children: u(P, h.length === 0) }),
818
+ h.length > 0 && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
819
+ /* @__PURE__ */ t.jsx(Se, { withHandle: e.splitResizable !== !1 }),
820
+ /* @__PURE__ */ t.jsx(se, { defaultSize: 100 - _, minSize: 20, children: u(h, !0) })
821
+ ] })
822
+ ] }) });
823
+ }, Me = ({
824
+ schema: e,
825
+ dataSource: l,
826
+ className: f
268
827
  }) => {
269
- const [f, _] = A(null), [m, b] = A([]), [T, y] = A(null), [Y, v] = A(!0), [S, R] = A(null), d = r.customFields && r.customFields.length > 0;
270
- I(() => {
271
- d && (y(r.initialData || r.initialValues || {}), v(!1));
272
- }, [d, r.initialData, r.initialValues]), I(() => {
273
- const a = async () => {
828
+ const [d, w] = g(null), [b, T] = g([]), [E, S] = g({}), [C, j] = g(!0), [y, N] = g(null), D = e.open !== !1, P = e.drawerSide || "right";
829
+ W(() => {
830
+ (async () => {
831
+ if (!l) {
832
+ j(!1);
833
+ return;
834
+ }
835
+ try {
836
+ const a = await l.getObjectSchema(e.objectName);
837
+ w(a);
838
+ } catch (a) {
839
+ N(a), j(!1);
840
+ }
841
+ })();
842
+ }, [e.objectName, l]), W(() => {
843
+ (d || !l) && (async () => {
844
+ if (e.mode === "create" || !e.recordId) {
845
+ S(e.initialData || e.initialValues || {}), j(!1);
846
+ return;
847
+ }
848
+ if (!l) {
849
+ S(e.initialData || e.initialValues || {}), j(!1);
850
+ return;
851
+ }
274
852
  try {
275
- if (!c)
853
+ const a = await l.findOne(e.objectName, e.recordId);
854
+ S(a || {});
855
+ } catch (a) {
856
+ N(a);
857
+ } finally {
858
+ j(!1);
859
+ }
860
+ })();
861
+ }, [d, e.mode, e.recordId, e.initialData, e.initialValues, l, e.objectName]);
862
+ const h = k((o) => {
863
+ const a = [];
864
+ for (const c of o.fields) {
865
+ const i = typeof c == "string" ? c : c.name;
866
+ if (typeof c == "object")
867
+ a.push(c);
868
+ else if (d?.fields?.[i]) {
869
+ const v = d.fields[i];
870
+ a.push({
871
+ name: i,
872
+ label: v.label || i,
873
+ type: U(v.type),
874
+ required: v.required || !1,
875
+ disabled: e.readOnly || e.mode === "view" || v.readonly,
876
+ placeholder: v.placeholder,
877
+ description: v.help || v.description,
878
+ validation: Y(v),
879
+ field: v,
880
+ options: v.options,
881
+ multiple: v.multiple
882
+ });
883
+ } else
884
+ a.push({
885
+ name: i,
886
+ label: i,
887
+ type: "input"
888
+ });
889
+ }
890
+ return a;
891
+ }, [d, e.readOnly, e.mode]);
892
+ W(() => {
893
+ if (!d && l) return;
894
+ if (e.customFields?.length) {
895
+ T(e.customFields), j(!1);
896
+ return;
897
+ }
898
+ if (e.sections?.length) {
899
+ j(!1);
900
+ return;
901
+ }
902
+ if (!d) return;
903
+ const o = e.fields || Object.keys(d.fields || {}), a = [];
904
+ for (const c of o) {
905
+ const i = typeof c == "string" ? c : c.name;
906
+ if (!i) continue;
907
+ const v = d.fields?.[i];
908
+ v && a.push({
909
+ name: i,
910
+ label: v.label || i,
911
+ type: U(v.type),
912
+ required: v.required || !1,
913
+ disabled: e.readOnly || e.mode === "view" || v.readonly,
914
+ placeholder: v.placeholder,
915
+ description: v.help || v.description,
916
+ validation: Y(v),
917
+ field: v,
918
+ options: v.options,
919
+ multiple: v.multiple
920
+ });
921
+ }
922
+ T(a), j(!1);
923
+ }, [d, e.fields, e.customFields, e.sections, e.readOnly, e.mode, l]);
924
+ const F = k(async (o) => {
925
+ if (!l)
926
+ return e.onSuccess && await e.onSuccess(o), e.onOpenChange?.(!1), o;
927
+ try {
928
+ let a;
929
+ return e.mode === "create" ? a = await l.create(e.objectName, o) : e.mode === "edit" && e.recordId && (a = await l.update(e.objectName, e.recordId, o)), e.onSuccess && await e.onSuccess(a), e.onOpenChange?.(!1), a;
930
+ } catch (a) {
931
+ throw e.onError && e.onError(a), a;
932
+ }
933
+ }, [e, l]), _ = k(() => {
934
+ e.onCancel && e.onCancel(), e.onOpenChange?.(!1);
935
+ }, [e]), q = Q(() => e.drawerWidth ? P === "left" || P === "right" ? { width: e.drawerWidth, maxWidth: e.drawerWidth } : { height: e.drawerWidth, maxHeight: e.drawerWidth } : void 0, [e.drawerWidth, P]), s = {
936
+ type: "form",
937
+ layout: e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical",
938
+ defaultValues: E,
939
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
940
+ cancelLabel: e.cancelText,
941
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
942
+ showCancel: e.showCancel !== !1,
943
+ onSubmit: F,
944
+ onCancel: _
945
+ }, n = () => y ? /* @__PURE__ */ t.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
946
+ /* @__PURE__ */ t.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading form" }),
947
+ /* @__PURE__ */ t.jsx("p", { className: "text-red-600 text-sm mt-1", children: y.message })
948
+ ] }) : C ? /* @__PURE__ */ t.jsxs("div", { className: "p-8 text-center", children: [
949
+ /* @__PURE__ */ t.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
950
+ /* @__PURE__ */ t.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading form..." })
951
+ ] }) : e.sections?.length ? /* @__PURE__ */ t.jsx("div", { className: "space-y-6", children: e.sections.map((o, a) => /* @__PURE__ */ t.jsx(
952
+ G,
953
+ {
954
+ label: o.label,
955
+ description: o.description,
956
+ columns: o.columns || 1,
957
+ children: /* @__PURE__ */ t.jsx(
958
+ M,
959
+ {
960
+ schema: {
961
+ ...s,
962
+ fields: h(o),
963
+ showSubmit: a === e.sections.length - 1 && s.showSubmit,
964
+ showCancel: a === e.sections.length - 1 && s.showCancel
965
+ }
966
+ }
967
+ )
968
+ },
969
+ o.name || o.label || a
970
+ )) }) : /* @__PURE__ */ t.jsx(
971
+ M,
972
+ {
973
+ schema: {
974
+ ...s,
975
+ fields: b,
976
+ columns: e.columns
977
+ }
978
+ }
979
+ );
980
+ return /* @__PURE__ */ t.jsx(Te, { open: D, onOpenChange: e.onOpenChange, children: /* @__PURE__ */ t.jsxs(
981
+ Ce,
982
+ {
983
+ side: P,
984
+ className: V("overflow-y-auto", f, e.className),
985
+ style: q,
986
+ children: [
987
+ (e.title || e.description) && /* @__PURE__ */ t.jsxs(Ee, { children: [
988
+ e.title && /* @__PURE__ */ t.jsx(Oe, { children: e.title }),
989
+ e.description && /* @__PURE__ */ t.jsx(_e, { children: e.description })
990
+ ] }),
991
+ /* @__PURE__ */ t.jsx("div", { className: "py-4", children: n() })
992
+ ]
993
+ }
994
+ ) });
995
+ }, fe = {
996
+ sm: "max-w-sm",
997
+ default: "max-w-lg",
998
+ lg: "max-w-2xl",
999
+ xl: "max-w-4xl",
1000
+ full: "max-w-[95vw] w-full"
1001
+ }, Ye = ({
1002
+ schema: e,
1003
+ dataSource: l,
1004
+ className: f
1005
+ }) => {
1006
+ const [d, w] = g(null), [b, T] = g([]), [E, S] = g({}), [C, j] = g(!0), [y, N] = g(null), D = e.open !== !1, P = fe[e.modalSize || "default"] || fe.default;
1007
+ W(() => {
1008
+ (async () => {
1009
+ if (!l) {
1010
+ j(!1);
1011
+ return;
1012
+ }
1013
+ try {
1014
+ const o = await l.getObjectSchema(e.objectName);
1015
+ w(o);
1016
+ } catch (o) {
1017
+ N(o), j(!1);
1018
+ }
1019
+ })();
1020
+ }, [e.objectName, l]), W(() => {
1021
+ (d || !l) && (async () => {
1022
+ if (e.mode === "create" || !e.recordId) {
1023
+ S(e.initialData || e.initialValues || {}), j(!1);
1024
+ return;
1025
+ }
1026
+ if (!l) {
1027
+ S(e.initialData || e.initialValues || {}), j(!1);
1028
+ return;
1029
+ }
1030
+ try {
1031
+ const o = await l.findOne(e.objectName, e.recordId);
1032
+ S(o || {});
1033
+ } catch (o) {
1034
+ N(o);
1035
+ } finally {
1036
+ j(!1);
1037
+ }
1038
+ })();
1039
+ }, [d, e.mode, e.recordId, e.initialData, e.initialValues, l, e.objectName]);
1040
+ const h = k((n) => {
1041
+ const o = [];
1042
+ for (const a of n.fields) {
1043
+ const c = typeof a == "string" ? a : a.name;
1044
+ if (typeof a == "object")
1045
+ o.push(a);
1046
+ else if (d?.fields?.[c]) {
1047
+ const i = d.fields[c];
1048
+ o.push({
1049
+ name: c,
1050
+ label: i.label || c,
1051
+ type: U(i.type),
1052
+ required: i.required || !1,
1053
+ disabled: e.readOnly || e.mode === "view" || i.readonly,
1054
+ placeholder: i.placeholder,
1055
+ description: i.help || i.description,
1056
+ validation: Y(i),
1057
+ field: i,
1058
+ options: i.options,
1059
+ multiple: i.multiple
1060
+ });
1061
+ } else
1062
+ o.push({
1063
+ name: c,
1064
+ label: c,
1065
+ type: "input"
1066
+ });
1067
+ }
1068
+ return o;
1069
+ }, [d, e.readOnly, e.mode]);
1070
+ W(() => {
1071
+ if (!d && l) return;
1072
+ if (e.customFields?.length) {
1073
+ T(e.customFields), j(!1);
1074
+ return;
1075
+ }
1076
+ if (e.sections?.length) {
1077
+ j(!1);
1078
+ return;
1079
+ }
1080
+ if (!d) return;
1081
+ const n = e.fields || Object.keys(d.fields || {}), o = [];
1082
+ for (const a of n) {
1083
+ const c = typeof a == "string" ? a : a.name;
1084
+ if (!c) continue;
1085
+ const i = d.fields?.[c];
1086
+ i && o.push({
1087
+ name: c,
1088
+ label: i.label || c,
1089
+ type: U(i.type),
1090
+ required: i.required || !1,
1091
+ disabled: e.readOnly || e.mode === "view" || i.readonly,
1092
+ placeholder: i.placeholder,
1093
+ description: i.help || i.description,
1094
+ validation: Y(i),
1095
+ field: i,
1096
+ options: i.options,
1097
+ multiple: i.multiple
1098
+ });
1099
+ }
1100
+ T(o), j(!1);
1101
+ }, [d, e.fields, e.customFields, e.sections, e.readOnly, e.mode, l]);
1102
+ const F = k(async (n) => {
1103
+ if (!l)
1104
+ return e.onSuccess && await e.onSuccess(n), e.onOpenChange?.(!1), n;
1105
+ try {
1106
+ let o;
1107
+ return e.mode === "create" ? o = await l.create(e.objectName, n) : e.mode === "edit" && e.recordId && (o = await l.update(e.objectName, e.recordId, n)), e.onSuccess && await e.onSuccess(o), e.onOpenChange?.(!1), o;
1108
+ } catch (o) {
1109
+ throw e.onError && e.onError(o), o;
1110
+ }
1111
+ }, [e, l]), _ = k(() => {
1112
+ e.onCancel && e.onCancel(), e.onOpenChange?.(!1);
1113
+ }, [e]), u = {
1114
+ type: "form",
1115
+ layout: e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical",
1116
+ defaultValues: E,
1117
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
1118
+ cancelLabel: e.cancelText,
1119
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
1120
+ showCancel: e.showCancel !== !1,
1121
+ onSubmit: F,
1122
+ onCancel: _
1123
+ }, s = () => y ? /* @__PURE__ */ t.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
1124
+ /* @__PURE__ */ t.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading form" }),
1125
+ /* @__PURE__ */ t.jsx("p", { className: "text-red-600 text-sm mt-1", children: y.message })
1126
+ ] }) : C ? /* @__PURE__ */ t.jsxs("div", { className: "p-8 text-center", children: [
1127
+ /* @__PURE__ */ t.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
1128
+ /* @__PURE__ */ t.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading form..." })
1129
+ ] }) : e.sections?.length ? /* @__PURE__ */ t.jsx("div", { className: "space-y-6", children: e.sections.map((n, o) => /* @__PURE__ */ t.jsx(
1130
+ G,
1131
+ {
1132
+ label: n.label,
1133
+ description: n.description,
1134
+ columns: n.columns || 1,
1135
+ children: /* @__PURE__ */ t.jsx(
1136
+ M,
1137
+ {
1138
+ schema: {
1139
+ ...u,
1140
+ fields: h(n),
1141
+ showSubmit: o === e.sections.length - 1 && u.showSubmit,
1142
+ showCancel: o === e.sections.length - 1 && u.showCancel
1143
+ }
1144
+ }
1145
+ )
1146
+ },
1147
+ n.name || n.label || o
1148
+ )) }) : /* @__PURE__ */ t.jsx(
1149
+ M,
1150
+ {
1151
+ schema: {
1152
+ ...u,
1153
+ fields: b,
1154
+ columns: e.columns
1155
+ }
1156
+ }
1157
+ );
1158
+ return /* @__PURE__ */ t.jsx(Re, { open: D, onOpenChange: e.onOpenChange, children: /* @__PURE__ */ t.jsxs(De, { className: V(P, "max-h-[90vh] overflow-y-auto", f, e.className), children: [
1159
+ (e.title || e.description) && /* @__PURE__ */ t.jsxs(Fe, { children: [
1160
+ e.title && /* @__PURE__ */ t.jsx(ke, { children: e.title }),
1161
+ e.description && /* @__PURE__ */ t.jsx(Ie, { children: e.description })
1162
+ ] }),
1163
+ /* @__PURE__ */ t.jsx("div", { className: "py-2", children: s() })
1164
+ ] }) });
1165
+ }, Ue = ({
1166
+ schema: e,
1167
+ dataSource: l
1168
+ }) => {
1169
+ if (e.formType === "tabbed" && e.sections?.length)
1170
+ return /* @__PURE__ */ t.jsx(
1171
+ qe,
1172
+ {
1173
+ schema: {
1174
+ ...e,
1175
+ formType: "tabbed",
1176
+ sections: e.sections.map((f) => ({
1177
+ name: f.name,
1178
+ label: f.label,
1179
+ description: f.description,
1180
+ columns: f.columns,
1181
+ fields: f.fields
1182
+ })),
1183
+ defaultTab: e.defaultTab,
1184
+ tabPosition: e.tabPosition
1185
+ },
1186
+ dataSource: l,
1187
+ className: e.className
1188
+ }
1189
+ );
1190
+ if (e.formType === "wizard" && e.sections?.length)
1191
+ return /* @__PURE__ */ t.jsx(
1192
+ We,
1193
+ {
1194
+ schema: {
1195
+ ...e,
1196
+ formType: "wizard",
1197
+ sections: e.sections.map((f) => ({
1198
+ name: f.name,
1199
+ label: f.label,
1200
+ description: f.description,
1201
+ columns: f.columns,
1202
+ fields: f.fields
1203
+ })),
1204
+ allowSkip: e.allowSkip,
1205
+ showStepIndicator: e.showStepIndicator,
1206
+ nextText: e.nextText,
1207
+ prevText: e.prevText,
1208
+ onStepChange: e.onStepChange
1209
+ },
1210
+ dataSource: l,
1211
+ className: e.className
1212
+ }
1213
+ );
1214
+ if (e.formType === "split" && e.sections?.length)
1215
+ return /* @__PURE__ */ t.jsx(
1216
+ $e,
1217
+ {
1218
+ schema: {
1219
+ ...e,
1220
+ formType: "split",
1221
+ sections: e.sections.map((f) => ({
1222
+ name: f.name,
1223
+ label: f.label,
1224
+ description: f.description,
1225
+ columns: f.columns,
1226
+ fields: f.fields
1227
+ })),
1228
+ splitDirection: e.splitDirection,
1229
+ splitSize: e.splitSize,
1230
+ splitResizable: e.splitResizable
1231
+ },
1232
+ dataSource: l,
1233
+ className: e.className
1234
+ }
1235
+ );
1236
+ if (e.formType === "drawer") {
1237
+ const { layout: f, ...d } = e, w = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : void 0;
1238
+ return /* @__PURE__ */ t.jsx(
1239
+ Me,
1240
+ {
1241
+ schema: {
1242
+ ...d,
1243
+ layout: w,
1244
+ formType: "drawer",
1245
+ sections: e.sections?.map((b) => ({
1246
+ name: b.name,
1247
+ label: b.label,
1248
+ description: b.description,
1249
+ columns: b.columns,
1250
+ fields: b.fields
1251
+ })),
1252
+ open: e.open,
1253
+ onOpenChange: e.onOpenChange,
1254
+ drawerSide: e.drawerSide,
1255
+ drawerWidth: e.drawerWidth
1256
+ },
1257
+ dataSource: l,
1258
+ className: e.className
1259
+ }
1260
+ );
1261
+ }
1262
+ if (e.formType === "modal") {
1263
+ const { layout: f, ...d } = e, w = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : void 0;
1264
+ return /* @__PURE__ */ t.jsx(
1265
+ Ye,
1266
+ {
1267
+ schema: {
1268
+ ...d,
1269
+ layout: w,
1270
+ formType: "modal",
1271
+ sections: e.sections?.map((b) => ({
1272
+ name: b.name,
1273
+ label: b.label,
1274
+ description: b.description,
1275
+ columns: b.columns,
1276
+ fields: b.fields
1277
+ })),
1278
+ open: e.open,
1279
+ onOpenChange: e.onOpenChange,
1280
+ modalSize: e.modalSize,
1281
+ modalCloseButton: e.modalCloseButton
1282
+ },
1283
+ dataSource: l,
1284
+ className: e.className
1285
+ }
1286
+ );
1287
+ }
1288
+ return /* @__PURE__ */ t.jsx(He, { schema: e, dataSource: l });
1289
+ }, He = ({
1290
+ schema: e,
1291
+ dataSource: l
1292
+ }) => {
1293
+ const [f, d] = g(null), [w, b] = g([]), [T, E] = g(null), [S, C] = g(!0), [j, y] = g(null), N = e.customFields && e.customFields.length > 0;
1294
+ W(() => {
1295
+ N && (E(e.initialData || e.initialValues || {}), C(!1));
1296
+ }, [N, e.initialData, e.initialValues]), W(() => {
1297
+ const u = async () => {
1298
+ try {
1299
+ if (!l)
276
1300
  throw new Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");
277
- const l = await c.getObjectSchema(r.objectName);
278
- _(l);
279
- } catch (l) {
280
- console.error("Failed to fetch object schema:", l), R(l);
1301
+ const s = await l.getObjectSchema(e.objectName);
1302
+ if (!s)
1303
+ throw new Error(`No schema found for object "${e.objectName}"`);
1304
+ d(s);
1305
+ } catch (s) {
1306
+ y(s), C(!1);
281
1307
  }
282
1308
  };
283
- d ? _({
284
- name: r.objectName,
1309
+ N ? d({
1310
+ name: e.objectName,
285
1311
  fields: {}
286
- }) : r.objectName && c && a();
287
- }, [r.objectName, c, d]), I(() => {
288
- f && !d && (async () => {
289
- if (!r.recordId || r.mode === "create") {
290
- y(r.initialData || r.initialValues || {}), v(!1);
1312
+ }) : e.objectName && l ? u() : N || C(!1);
1313
+ }, [e.objectName, l, N]), W(() => {
1314
+ f && !N && (async () => {
1315
+ if (!e.recordId || e.mode === "create") {
1316
+ E(e.initialData || e.initialValues || {}), C(!1);
291
1317
  return;
292
1318
  }
293
- if (!d) {
294
- if (!c) {
295
- R(new Error("DataSource is required for fetching record data (inline data not provided)")), v(!1);
1319
+ if (!N) {
1320
+ if (!l) {
1321
+ y(new Error("DataSource is required for fetching record data (inline data not provided)")), C(!1);
296
1322
  return;
297
1323
  }
298
- v(!0);
1324
+ C(!0);
299
1325
  try {
300
- const l = await c.findOne(r.objectName, r.recordId);
301
- y(l);
302
- } catch (l) {
303
- console.error("Failed to fetch record:", l), R(l);
1326
+ const s = await l.findOne(e.objectName, e.recordId);
1327
+ E(s);
1328
+ } catch (s) {
1329
+ console.error("Failed to fetch record:", s), y(s);
304
1330
  } finally {
305
- v(!1);
1331
+ C(!1);
306
1332
  }
307
1333
  }
308
1334
  })();
309
- }, [r.objectName, r.recordId, r.mode, r.initialValues, r.initialData, c, f, d]), I(() => {
310
- if (d && r.customFields) {
311
- b(r.customFields), v(!1);
1335
+ }, [e.objectName, e.recordId, e.mode, e.initialValues, e.initialData, l, f, N]), W(() => {
1336
+ if (N && e.customFields) {
1337
+ b(e.customFields), C(!1);
312
1338
  return;
313
1339
  }
314
1340
  if (!f) return;
315
- const a = [], l = r.fields || Object.keys(f.fields || {});
316
- (Array.isArray(l) ? l : Object.keys(l)).forEach((j) => {
317
- const x = typeof j == "string" ? j : j.name;
318
- if (!x) return;
319
- const t = f.fields?.[x];
320
- if (!t && !d) return;
321
- const V = !t?.permissions || t?.permissions.write !== !1;
322
- if (r.mode !== "view" && !V) return;
323
- const g = r.customFields?.find((o) => o.name === x);
324
- if (g)
325
- a.push(g);
326
- else if (t) {
327
- const o = {
328
- name: x,
329
- label: t.label || j,
330
- type: le(t.type),
331
- required: t.required || !1,
332
- disabled: r.readOnly || r.mode === "view" || t.readonly,
333
- placeholder: t.placeholder,
334
- description: t.help || t.description,
335
- validation: ae(t),
1341
+ const u = [], s = e.fields || Object.keys(f.fields || {});
1342
+ (Array.isArray(s) ? s : Object.keys(s)).forEach((a) => {
1343
+ const c = typeof a == "string" ? a : a.name;
1344
+ if (!c) return;
1345
+ const i = f.fields?.[c];
1346
+ if (!i && !N) return;
1347
+ const v = !i?.permissions || i?.permissions.write !== !1;
1348
+ if (e.mode !== "view" && !v) return;
1349
+ const $ = e.customFields?.find((p) => p.name === c);
1350
+ if ($)
1351
+ u.push($);
1352
+ else if (i) {
1353
+ const p = {
1354
+ name: c,
1355
+ label: i.label || a,
1356
+ type: U(i.type),
1357
+ required: i.required || !1,
1358
+ disabled: e.readOnly || e.mode === "view" || i.readonly,
1359
+ placeholder: i.placeholder,
1360
+ description: i.help || i.description,
1361
+ validation: Y(i),
336
1362
  // Important: Pass the original field metadata so widgets can access properties like precision, currency, etc.
337
- field: t
1363
+ field: i
338
1364
  };
339
- if ((t.type === "select" || t.type === "lookup" || t.type === "master_detail") && (o.options = t.options || [], o.multiple = t.multiple), (t.type === "number" || t.type === "currency" || t.type === "percent") && (o.inputType = "number", o.min = t.min, o.max = t.max, o.step = t.precision ? Math.pow(10, -t.precision) : void 0), t.type === "date" && (o.inputType = "date"), t.type === "datetime" && (o.inputType = "datetime-local"), (t.type === "text" || t.type === "textarea" || t.type === "markdown" || t.type === "html") && (o.maxLength = t.max_length, o.minLength = t.min_length), (t.type === "file" || t.type === "image") && (o.inputType = "file", o.multiple = t.multiple, o.accept = t.accept ? t.accept.join(",") : void 0, t.max_size)) {
340
- const O = `Max size: ${se(t.max_size)}`;
341
- o.description = o.description ? `${o.description} (${O})` : O;
1365
+ if ((i.type === "select" || i.type === "lookup" || i.type === "master_detail") && (p.options = i.options || [], p.multiple = i.multiple), (i.type === "number" || i.type === "currency" || i.type === "percent") && (p.inputType = "number", p.min = i.min, p.max = i.max, p.step = i.precision ? Math.pow(10, -i.precision) : void 0), i.type === "date" && (p.inputType = "date"), i.type === "datetime" && (p.inputType = "datetime-local"), (i.type === "text" || i.type === "textarea" || i.type === "markdown" || i.type === "html") && (p.maxLength = i.max_length, p.minLength = i.min_length), (i.type === "file" || i.type === "image") && (p.inputType = "file", p.multiple = i.multiple, p.accept = i.accept ? i.accept.join(",") : void 0, i.max_size)) {
1366
+ const x = `Max size: ${ye(i.max_size)}`;
1367
+ p.description = p.description ? `${p.description} (${x})` : x;
342
1368
  }
343
- t.type === "email" && (o.inputType = "email"), t.type === "phone" && (o.inputType = "tel"), t.type === "url" && (o.inputType = "url"), t.type === "password" && (o.inputType = "password"), t.type === "time" && (o.inputType = "time"), (t.type === "formula" || t.type === "summary" || t.type === "auto_number") && (o.disabled = !0), t.visible_on && (o.visible = (O) => ue(t.visible_on, O)), a.push(o);
344
- }
345
- }), b(a), v(!1);
346
- }, [f, r.fields, r.customFields, r.readOnly, r.mode, d]);
347
- const w = Q(async (a, l) => {
348
- if (a && (a.nativeEvent || a._reactName === "onSubmit") && (console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."), l === void 0 && (l = a, a = {})), d && !c)
349
- return r.onSuccess && await r.onSuccess(a), a;
350
- if (!c)
1369
+ i.type === "email" && (p.inputType = "email"), i.type === "phone" && (p.inputType = "tel"), i.type === "url" && (p.inputType = "url"), i.type === "password" && (p.inputType = "password"), i.type === "time" && (p.inputType = "time"), (i.type === "formula" || i.type === "summary" || i.type === "auto_number") && (p.disabled = !0), i.visible_on && (p.visible = (x) => xe(i.visible_on, x)), u.push(p);
1370
+ }
1371
+ }), b(u), !N && e.recordId && e.mode !== "create" && l || C(!1);
1372
+ }, [f, e.fields, e.customFields, e.readOnly, e.mode, N, e.recordId, l]);
1373
+ const D = k(async (u, s) => {
1374
+ if (u && (u.nativeEvent || u._reactName === "onSubmit") && (console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."), s === void 0 && (s = u, u = {})), N && !l)
1375
+ return e.onSuccess && await e.onSuccess(u), u;
1376
+ if (!l)
351
1377
  throw new Error("DataSource is required for form submission (inline mode not configured)");
352
1378
  try {
353
- let p;
354
- if (r.mode === "create")
355
- p = await c.create(r.objectName, a);
356
- else if (r.mode === "edit" && r.recordId)
357
- p = await c.update(r.objectName, r.recordId, a);
1379
+ let n;
1380
+ if (e.mode === "create")
1381
+ n = await l.create(e.objectName, u);
1382
+ else if (e.mode === "edit" && e.recordId)
1383
+ n = await l.update(e.objectName, e.recordId, u);
358
1384
  else
359
1385
  throw new Error("Invalid form mode or missing record ID");
360
- return r.onSuccess && await r.onSuccess(p), p;
361
- } catch (p) {
362
- throw console.error("Failed to submit form:", p), r.onError && r.onError(p), p;
363
- }
364
- }, [r, c, d]), h = Q(() => {
365
- r.onCancel && r.onCancel();
366
- }, [r]), N = {
367
- ...re.useMemo(() => {
1386
+ return e.onSuccess && await e.onSuccess(n), n;
1387
+ } catch (n) {
1388
+ throw console.error("Failed to submit form:", n), e.onError && e.onError(n), n;
1389
+ }
1390
+ }, [e, l, N]), P = k(() => {
1391
+ e.onCancel && e.onCancel();
1392
+ }, [e]), F = {
1393
+ ...J.useMemo(() => {
368
1394
  if (!f?.fields) return {};
369
- const a = {};
370
- return Object.keys(f.fields).forEach((l) => {
371
- const p = f.fields[l];
372
- p.defaultValue !== void 0 && (a[l] = p.defaultValue);
373
- }), a;
1395
+ const u = {};
1396
+ return Object.keys(f.fields).forEach((s) => {
1397
+ const n = f.fields[s];
1398
+ n.defaultValue !== void 0 && (u[s] = n.defaultValue);
1399
+ }), u;
374
1400
  }, [f]),
375
1401
  ...T
376
1402
  };
377
- if (S)
378
- return /* @__PURE__ */ E.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
379
- /* @__PURE__ */ E.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading form" }),
380
- /* @__PURE__ */ E.jsx("p", { className: "text-red-600 text-sm mt-1", children: S.message })
1403
+ if (j)
1404
+ return /* @__PURE__ */ t.jsxs("div", { className: "p-4 border border-red-300 bg-red-50 rounded-md", children: [
1405
+ /* @__PURE__ */ t.jsx("h3", { className: "text-red-800 font-semibold", children: "Error loading form" }),
1406
+ /* @__PURE__ */ t.jsx("p", { className: "text-red-600 text-sm mt-1", children: j.message })
381
1407
  ] });
382
- if (Y)
383
- return /* @__PURE__ */ E.jsxs("div", { className: "p-8 text-center", children: [
384
- /* @__PURE__ */ E.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
385
- /* @__PURE__ */ E.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading form..." })
1408
+ if (S)
1409
+ return /* @__PURE__ */ t.jsxs("div", { className: "p-8 text-center", children: [
1410
+ /* @__PURE__ */ t.jsx("div", { className: "inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }),
1411
+ /* @__PURE__ */ t.jsx("p", { className: "mt-2 text-sm text-gray-600", children: "Loading form..." })
386
1412
  ] });
387
- const $ = {
1413
+ const _ = e.layout === "vertical" || e.layout === "horizontal" ? e.layout : "vertical";
1414
+ if (e.sections?.length && (!e.formType || e.formType === "simple"))
1415
+ return /* @__PURE__ */ t.jsx("div", { className: "w-full space-y-6", children: e.sections.map((u, s) => {
1416
+ const n = u.fields.map((a) => typeof a == "string" ? a : a.name), o = w.filter((a) => n.includes(a.name));
1417
+ return /* @__PURE__ */ t.jsx(
1418
+ G,
1419
+ {
1420
+ label: u.label,
1421
+ description: u.description,
1422
+ collapsible: u.collapsible,
1423
+ collapsed: u.collapsed,
1424
+ columns: u.columns,
1425
+ children: /* @__PURE__ */ t.jsx(
1426
+ M,
1427
+ {
1428
+ schema: {
1429
+ type: "form",
1430
+ fields: o,
1431
+ layout: _,
1432
+ defaultValues: F,
1433
+ // Only show action buttons after the last section
1434
+ showSubmit: s === e.sections.length - 1 && e.showSubmit !== !1 && e.mode !== "view",
1435
+ showCancel: s === e.sections.length - 1 && e.showCancel !== !1,
1436
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
1437
+ cancelLabel: e.cancelText,
1438
+ onSubmit: D,
1439
+ onCancel: P
1440
+ }
1441
+ }
1442
+ )
1443
+ },
1444
+ u.name || u.label || s
1445
+ );
1446
+ }) });
1447
+ const q = {
388
1448
  type: "form",
389
- fields: m,
390
- layout: r.layout === "vertical" || r.layout === "horizontal" ? r.layout : "vertical",
391
- columns: r.columns,
392
- submitLabel: r.submitText || (r.mode === "create" ? "Create" : "Update"),
393
- cancelLabel: r.cancelText,
394
- showSubmit: r.showSubmit !== !1 && r.mode !== "view",
395
- showCancel: r.showCancel !== !1,
396
- resetOnSubmit: r.showReset,
397
- defaultValues: N,
398
- onSubmit: w,
399
- onCancel: h,
400
- className: r.className
1449
+ fields: w,
1450
+ layout: _,
1451
+ columns: e.columns,
1452
+ submitLabel: e.submitText || (e.mode === "create" ? "Create" : "Update"),
1453
+ cancelLabel: e.cancelText,
1454
+ showSubmit: e.showSubmit !== !1 && e.mode !== "view",
1455
+ showCancel: e.showCancel !== !1,
1456
+ resetOnSubmit: e.showReset,
1457
+ defaultValues: F,
1458
+ onSubmit: D,
1459
+ onCancel: P,
1460
+ className: e.className
401
1461
  };
402
- return /* @__PURE__ */ E.jsx("div", { className: "w-full", children: /* @__PURE__ */ E.jsx(ie, { schema: $ }) });
403
- }, me = ({ schema: r }) => /* @__PURE__ */ E.jsx(pe, { schema: r });
404
- oe.register("object-form", me, {
405
- namespace: "plugin-form"
1462
+ return /* @__PURE__ */ t.jsx("div", { className: "w-full", children: /* @__PURE__ */ t.jsx(M, { schema: q }) });
1463
+ }, be = ({ schema: e }) => /* @__PURE__ */ t.jsx(Ue, { schema: e });
1464
+ ue.register("object-form", be, {
1465
+ namespace: "plugin-form",
1466
+ label: "Object Form",
1467
+ category: "plugin",
1468
+ inputs: [
1469
+ { name: "objectName", type: "string", label: "Object Name", required: !0 },
1470
+ { name: "fields", type: "array", label: "Fields" },
1471
+ { name: "mode", type: "enum", label: "Mode", enum: ["create", "edit", "view"] },
1472
+ { name: "formType", type: "enum", label: "Form Type", enum: ["simple", "tabbed", "wizard", "split", "drawer", "modal"] },
1473
+ { name: "sections", type: "array", label: "Sections" },
1474
+ { name: "title", type: "string", label: "Title" },
1475
+ { name: "description", type: "string", label: "Description" },
1476
+ { name: "layout", type: "enum", label: "Layout", enum: ["vertical", "horizontal", "inline", "grid"] },
1477
+ { name: "columns", type: "number", label: "Columns" },
1478
+ // Tabbed
1479
+ { name: "defaultTab", type: "string", label: "Default Tab" },
1480
+ { name: "tabPosition", type: "enum", label: "Tab Position", enum: ["top", "bottom", "left", "right"] },
1481
+ // Wizard
1482
+ { name: "allowSkip", type: "boolean", label: "Allow Skip Steps" },
1483
+ { name: "showStepIndicator", type: "boolean", label: "Show Step Indicator" },
1484
+ // Split
1485
+ { name: "splitDirection", type: "enum", label: "Split Direction", enum: ["horizontal", "vertical"] },
1486
+ { name: "splitSize", type: "number", label: "Split Panel Size (%)" },
1487
+ { name: "splitResizable", type: "boolean", label: "Split Resizable" },
1488
+ // Drawer
1489
+ { name: "drawerSide", type: "enum", label: "Drawer Side", enum: ["top", "bottom", "left", "right"] },
1490
+ { name: "drawerWidth", type: "string", label: "Drawer Width" },
1491
+ // Modal
1492
+ { name: "modalSize", type: "enum", label: "Modal Size", enum: ["sm", "default", "lg", "xl", "full"] }
1493
+ ]
1494
+ });
1495
+ ue.register("form", be, {
1496
+ namespace: "view",
1497
+ skipFallback: !0,
1498
+ label: "Data Form View",
1499
+ category: "view",
1500
+ inputs: [
1501
+ { name: "objectName", type: "string", label: "Object Name", required: !0 },
1502
+ { name: "fields", type: "array", label: "Fields" },
1503
+ { name: "mode", type: "enum", label: "Mode", enum: ["create", "edit", "view"] }
1504
+ ]
406
1505
  });
407
1506
  export {
408
- pe as ObjectForm
1507
+ Me as DrawerForm,
1508
+ G as FormSection,
1509
+ Ye as ModalForm,
1510
+ Ue as ObjectForm,
1511
+ $e as SplitForm,
1512
+ qe as TabbedForm,
1513
+ We as WizardForm
409
1514
  };