@ram_28/kf-ai-sdk 2.0.12 → 2.0.13

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.
Files changed (69) hide show
  1. package/dist/api/client.d.ts.map +1 -1
  2. package/dist/api.cjs +1 -1
  3. package/dist/api.mjs +2 -2
  4. package/dist/attachment-constants-B5jlqoKI.cjs +1 -0
  5. package/dist/attachment-constants-C2UHWxmp.js +63 -0
  6. package/dist/auth.cjs +1 -1
  7. package/dist/auth.mjs +1 -1
  8. package/dist/bdo/core/types.d.ts +4 -0
  9. package/dist/bdo/core/types.d.ts.map +1 -1
  10. package/dist/bdo/fields/NumberField.d.ts.map +1 -1
  11. package/dist/bdo/fields/ReferenceField.d.ts +3 -2
  12. package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
  13. package/dist/bdo/fields/SelectField.d.ts +1 -1
  14. package/dist/bdo/fields/SelectField.d.ts.map +1 -1
  15. package/dist/bdo/fields/UserField.d.ts +5 -0
  16. package/dist/bdo/fields/UserField.d.ts.map +1 -1
  17. package/dist/bdo.cjs +1 -1
  18. package/dist/bdo.mjs +107 -153
  19. package/dist/client-DnO2KKrw.cjs +1 -0
  20. package/dist/{client-CMERmrC-.js → client-iQTqFDNI.js} +34 -30
  21. package/dist/components/hooks/useForm/createItemProxy.d.ts +4 -0
  22. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +1 -1
  23. package/dist/components/hooks/useForm/createResolver.d.ts.map +1 -1
  24. package/dist/components/hooks/useForm/useForm.d.ts +1 -0
  25. package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
  26. package/dist/form.cjs +1 -1
  27. package/dist/form.mjs +368 -203
  28. package/dist/{metadata-BfJtHz84.cjs → metadata-DgLSJkF5.cjs} +1 -1
  29. package/dist/{metadata-CwAo6a8e.js → metadata-DpfI3zRN.js} +1 -1
  30. package/dist/table.cjs +1 -1
  31. package/dist/table.mjs +1 -1
  32. package/dist/workflow/types.d.ts +3 -2
  33. package/dist/workflow/types.d.ts.map +1 -1
  34. package/dist/workflow.cjs +1 -1
  35. package/dist/workflow.d.ts +0 -2
  36. package/dist/workflow.d.ts.map +1 -1
  37. package/dist/workflow.mjs +204 -274
  38. package/dist/workflow.types.d.ts +0 -1
  39. package/dist/workflow.types.d.ts.map +1 -1
  40. package/docs/api.md +45 -253
  41. package/docs/bdo.md +130 -711
  42. package/docs/useAuth.md +42 -104
  43. package/docs/useFilter.md +117 -1591
  44. package/docs/useForm.md +263 -861
  45. package/docs/useTable.md +255 -1096
  46. package/docs/workflow.md +10 -155
  47. package/package.json +1 -1
  48. package/sdk/api/client.ts +18 -4
  49. package/sdk/bdo/core/types.ts +1 -0
  50. package/sdk/bdo/fields/NumberField.ts +2 -1
  51. package/sdk/bdo/fields/ReferenceField.ts +4 -3
  52. package/sdk/bdo/fields/SelectField.ts +2 -2
  53. package/sdk/bdo/fields/UserField.ts +14 -0
  54. package/sdk/components/hooks/useForm/createItemProxy.ts +221 -4
  55. package/sdk/components/hooks/useForm/createResolver.ts +16 -1
  56. package/sdk/components/hooks/useForm/useForm.ts +151 -50
  57. package/sdk/workflow/types.ts +3 -2
  58. package/sdk/workflow.ts +0 -7
  59. package/sdk/workflow.types.ts +0 -7
  60. package/dist/client-BnVxSHAm.cjs +0 -1
  61. package/dist/workflow/components/useActivityTable/index.d.ts +0 -4
  62. package/dist/workflow/components/useActivityTable/index.d.ts.map +0 -1
  63. package/dist/workflow/components/useActivityTable/types.d.ts +0 -53
  64. package/dist/workflow/components/useActivityTable/types.d.ts.map +0 -1
  65. package/dist/workflow/components/useActivityTable/useActivityTable.d.ts +0 -4
  66. package/dist/workflow/components/useActivityTable/useActivityTable.d.ts.map +0 -1
  67. package/sdk/workflow/components/useActivityTable/index.ts +0 -8
  68. package/sdk/workflow/components/useActivityTable/types.ts +0 -67
  69. package/sdk/workflow/components/useActivityTable/useActivityTable.ts +0 -145
package/dist/form.mjs CHANGED
@@ -1,270 +1,435 @@
1
- import { F as H, I as U, V as W } from "./constants-ConHc1oS.js";
2
- import { useMemo as D, useEffect as T, useCallback as q } from "react";
3
- import { u as j } from "./index.esm-Cj63v5ny.js";
4
- import { useQuery as w } from "@tanstack/react-query";
5
- import { g as C } from "./metadata-CwAo6a8e.js";
6
- function $(s, e) {
7
- const r = [];
8
- if (s.required && (e == null || e === "" || Array.isArray(e) && e.length === 0))
9
- return r.push(`${s.label} is required`), { valid: !1, errors: r };
10
- if (e == null || e === "")
1
+ import { F as le, I as oe, V as ce } from "./constants-ConHc1oS.js";
2
+ import { useMemo as z, useEffect as E, useRef as B, useCallback as j } from "react";
3
+ import { u as G } from "./index.esm-Cj63v5ny.js";
4
+ import { useQuery as A } from "@tanstack/react-query";
5
+ import { a as T } from "./client-iQTqFDNI.js";
6
+ import { v as L, e as J } from "./attachment-constants-C2UHWxmp.js";
7
+ import { g as W } from "./metadata-DpfI3zRN.js";
8
+ function K(o, t) {
9
+ const i = [];
10
+ if (o.required && (t == null || t === "" || Array.isArray(t) && t.length === 0))
11
+ return i.push(`${o.label} is required`), { valid: !1, errors: i };
12
+ if (t == null || t === "")
11
13
  return { valid: !0, errors: [] };
12
- if ("length" in s && typeof s.length == "number" && typeof e == "string" && e.length > s.length && r.push(`${s.label} must be at most ${s.length} characters`), "integerPart" in s && typeof e == "number") {
13
- const f = Math.floor(Math.abs(e)), o = s.integerPart ?? 9;
14
- f.toString().length > o && r.push(`${s.label} integer part must be at most ${o} digits`);
15
- const t = s.fractionPart;
16
- t !== void 0 && (e.toString().split(".")[1] ?? "").length > t && r.push(`${s.label} can have at most ${t} decimal places`);
14
+ if ("length" in o && typeof o.length == "number" && typeof t == "string" && t.length > o.length && i.push(`${o.label} must be at most ${o.length} characters`), "integerPart" in o && typeof t == "number") {
15
+ const g = Math.floor(Math.abs(t)), w = o.integerPart ?? 9;
16
+ g.toString().length > w && i.push(`${o.label} integer part must be at most ${w} digits`);
17
+ const f = o.fractionPart;
18
+ f !== void 0 && (t.toString().split(".")[1] ?? "").length > f && i.push(`${o.label} can have at most ${f} decimal places`);
17
19
  }
18
- return r.length > 0 ? { valid: !1, errors: r } : { valid: !0, errors: [] };
20
+ return i.length > 0 ? { valid: !1, errors: i } : { valid: !0, errors: [] };
19
21
  }
20
- function J(s, e) {
21
- return async (r, f, o) => {
22
- var S;
23
- const t = {}, a = s.getFields(), y = (o == null ? void 0 : o.names) ?? Object.keys(a);
24
- for (const n of y) {
25
- if (n === "_id" || (S = a[n]) != null && S.readOnly) continue;
26
- const g = a[n];
27
- if (!g) continue;
28
- const d = r[n], u = g.validate(d);
29
- if (!u.valid && u.errors.length > 0) {
30
- t[n] = {
22
+ function Q(o, t) {
23
+ return async (i, g, w) => {
24
+ var I;
25
+ const f = {}, S = o.getFields(), q = (w == null ? void 0 : w.names) ?? Object.keys(S);
26
+ for (const e of q) {
27
+ if (e === "_id" || (I = S[e]) != null && I.readOnly) continue;
28
+ const r = S[e];
29
+ if (!r) continue;
30
+ let l = i[e];
31
+ if ("integerPart" in r && typeof l == "string" && l !== "") {
32
+ const b = Number(l);
33
+ isNaN(b) || (l = b, i[e] = b);
34
+ }
35
+ if (!r.required && (l == null || l === "" || Array.isArray(l) && l.length === 0))
36
+ continue;
37
+ const P = r.validate(l);
38
+ if (!P.valid && P.errors.length > 0) {
39
+ f[e] = {
31
40
  type: "validate",
32
- message: u.errors[0] || `${n} is invalid`
41
+ message: P.errors[0] || `${e} is invalid`
33
42
  };
34
43
  continue;
35
44
  }
36
- if ((e == null ? void 0 : e.enableConstraintValidation) !== !1) {
37
- const l = $(g, d);
38
- if (!l.valid && l.errors.length > 0) {
39
- t[n] = {
45
+ if ((t == null ? void 0 : t.enableConstraintValidation) !== !1) {
46
+ const b = K(r, l);
47
+ if (!b.valid && b.errors.length > 0) {
48
+ f[e] = {
40
49
  type: "constraint",
41
- message: l.errors[0]
50
+ message: b.errors[0]
42
51
  };
43
52
  continue;
44
53
  }
45
54
  }
46
- if (s.hasMetadata()) {
47
- const l = s.validateFieldExpression(
48
- n,
49
- d,
50
- r
55
+ if (o.hasMetadata()) {
56
+ const b = o.validateFieldExpression(
57
+ e,
58
+ l,
59
+ i
51
60
  );
52
- !l.valid && l.errors.length > 0 && (t[n] = {
61
+ !b.valid && b.errors.length > 0 && (f[e] = {
53
62
  type: "validate",
54
- message: l.errors[0]
63
+ message: b.errors[0]
55
64
  });
56
65
  }
57
66
  }
58
- return Object.keys(t).length === 0 ? { values: r, errors: {} } : { values: {}, errors: t };
67
+ return Object.keys(f).length === 0 ? { values: i, errors: {} } : { values: {}, errors: f };
59
68
  };
60
69
  }
61
- function I(s, e) {
62
- const r = s.getFields(), f = /* @__PURE__ */ new Map();
70
+ function H(o, t) {
71
+ const i = o.getFields(), g = /* @__PURE__ */ new Map(), w = o.getBoId();
72
+ let f = null, S = null;
73
+ async function q() {
74
+ const I = t.getValues("_id");
75
+ return I || f || (S || (S = T(w).draftInteraction({}).then((e) => (f = e._id, t.setValue("_id", f, { shouldDirty: !1 }), f)).catch((e) => {
76
+ throw S = null, e;
77
+ })), S);
78
+ }
63
79
  return new Proxy({}, {
64
- get(o, t) {
65
- if (typeof t == "symbol")
80
+ get(I, e) {
81
+ if (typeof e == "symbol")
66
82
  return;
67
- if (t === "_id")
68
- return e.getValues("_id");
69
- if (t === "toJSON")
70
- return () => e.getValues();
71
- if (t === "validate")
72
- return () => e.trigger();
73
- if (f.has(t))
74
- return f.get(t);
75
- const a = r[t], y = (a == null ? void 0 : a.meta) ?? {
76
- _id: t,
77
- Name: t,
83
+ if (e === "_id")
84
+ return t.getValues("_id");
85
+ if (e === "toJSON")
86
+ return () => t.getValues();
87
+ if (e === "validate")
88
+ return () => t.trigger();
89
+ if (e === "_hasDraft")
90
+ return () => !!f;
91
+ if (g.has(e))
92
+ return g.get(e);
93
+ const r = i[e], l = (r == null ? void 0 : r.meta) ?? {
94
+ _id: e,
95
+ Name: e,
78
96
  Type: "String"
79
- }, S = (a == null ? void 0 : a.readOnly) ?? !1, n = () => {
80
- if (!a) return { valid: !0, errors: [] };
81
- const u = e.getValues(t), l = a.validate(u);
82
- if (!l.valid) return l;
83
- const x = $(a, u);
84
- if (!x.valid) return x;
85
- if (s.hasMetadata()) {
86
- const c = s.validateFieldExpression(
87
- t,
97
+ }, P = (r == null ? void 0 : r.readOnly) ?? !1, b = () => {
98
+ if (!r) return { valid: !0, errors: [] };
99
+ let u = t.getValues(e);
100
+ if ("integerPart" in r && typeof u == "string" && u !== "") {
101
+ const d = Number(u);
102
+ isNaN(d) || (u = d, t.setValue(e, d, { shouldDirty: !1 }));
103
+ }
104
+ if (!r.required && (u == null || u === "" || Array.isArray(u) && u.length === 0))
105
+ return { valid: !0, errors: [] };
106
+ const s = r.validate(u);
107
+ if (!s.valid) return s;
108
+ const n = K(r, u);
109
+ if (!n.valid) return n;
110
+ if (o.hasMetadata()) {
111
+ const d = o.validateFieldExpression(
112
+ e,
88
113
  u,
89
- e.getValues()
114
+ t.getValues()
90
115
  );
91
- if (!c.valid) return c;
116
+ if (!d.valid) return d;
92
117
  }
93
118
  return { valid: !0, errors: [] };
94
- }, g = (u) => {
95
- const l = e.getValues(t);
96
- return l ?? u;
119
+ }, M = (u) => {
120
+ const s = t.getValues(e);
121
+ return s ?? u;
97
122
  };
98
- if (!S) {
99
- const u = {
100
- label: (a == null ? void 0 : a.label) ?? t,
101
- required: (a == null ? void 0 : a.required) ?? !1,
123
+ if (!P) {
124
+ const u = () => {
125
+ const n = t.getValues(e);
126
+ return l.Type === "File" ? n ?? [] : n;
127
+ }, s = {
128
+ label: (r == null ? void 0 : r.label) ?? e,
129
+ required: (r == null ? void 0 : r.required) ?? !1,
102
130
  readOnly: !1,
103
- defaultValue: a == null ? void 0 : a.defaultValue,
104
- meta: y,
105
- get: () => e.getValues(t),
106
- getOrDefault: g,
107
- set: (l) => {
108
- e.setValue(t, l, {
131
+ defaultValue: r == null ? void 0 : r.defaultValue,
132
+ meta: l,
133
+ get: u,
134
+ getOrDefault: M,
135
+ set: (n) => {
136
+ t.setValue(e, n, {
109
137
  shouldDirty: !0,
110
138
  shouldTouch: !0,
111
139
  shouldValidate: !1
112
140
  // Let mode control validation timing
113
141
  });
114
142
  },
115
- validate: n
143
+ validate: b
116
144
  };
117
- return f.set(t, u), u;
145
+ if (l.Type === "Image" || l.Type === "File") {
146
+ const n = w, d = () => {
147
+ const a = t.getValues("_id");
148
+ if (!a) throw new Error("Save the record before attachment operations");
149
+ return a;
150
+ };
151
+ l.Type === "Image" ? (s.upload = async (a) => {
152
+ L(a.name, "Image");
153
+ const c = await q(), [h] = await T(n).getUploadUrl(c, e, [
154
+ { FileName: a.name, Size: a.size, FileExtension: J(a.name) }
155
+ ]);
156
+ await fetch(h.UploadUrl.URL, {
157
+ method: "PUT",
158
+ headers: { "Content-Type": h.ContentType },
159
+ body: a
160
+ });
161
+ const m = {
162
+ _id: h._id,
163
+ _name: h._name,
164
+ FileName: h.FileName,
165
+ FileExtension: h.FileExtension,
166
+ Size: h.Size,
167
+ ContentType: h.ContentType
168
+ };
169
+ return t.setValue(e, m, { shouldDirty: !0 }), m;
170
+ }, s.deleteAttachment = async () => {
171
+ const a = t.getValues(e), c = d();
172
+ if (!(a != null && a._id)) throw new Error(`${e} has no image to delete`);
173
+ await T(n).deleteAttachment(c, e, a._id), t.setValue(e, null, { shouldDirty: !0 });
174
+ }, s.getDownloadUrl = async (a) => {
175
+ const c = t.getValues(e), h = d();
176
+ if (!(c != null && c._id)) throw new Error(`${e} has no image`);
177
+ return T(n).getDownloadUrl(h, e, c._id, a);
178
+ }) : (s.upload = async (a) => {
179
+ for (const V of a) L(V.name, "File");
180
+ const c = await q(), h = a.map((V) => ({
181
+ FileName: V.name,
182
+ Size: V.size,
183
+ FileExtension: J(V.name)
184
+ })), m = await T(n).getUploadUrl(c, e, h), $ = await Promise.all(
185
+ a.map(async (V, _) => (await fetch(m[_].UploadUrl.URL, {
186
+ method: "PUT",
187
+ headers: { "Content-Type": m[_].ContentType },
188
+ body: V
189
+ }), {
190
+ _id: m[_]._id,
191
+ _name: m[_]._name,
192
+ FileName: m[_].FileName,
193
+ FileExtension: m[_].FileExtension,
194
+ Size: m[_].Size,
195
+ ContentType: m[_].ContentType
196
+ }))
197
+ ), D = t.getValues(e) ?? [];
198
+ return t.setValue(e, [...D, ...$], { shouldDirty: !0 }), $;
199
+ }, s.deleteAttachment = async (a) => {
200
+ const c = t.getValues(e) ?? [], h = d();
201
+ await T(n).deleteAttachment(h, e, a), t.setValue(
202
+ e,
203
+ c.filter((m) => m._id !== a),
204
+ { shouldDirty: !0 }
205
+ );
206
+ }, s.getDownloadUrl = async (a, c) => {
207
+ const h = d();
208
+ return T(n).getDownloadUrl(h, e, a, c);
209
+ }, s.getDownloadUrls = async (a) => {
210
+ const c = d();
211
+ return T(n).getDownloadUrls(c, e, a);
212
+ });
213
+ }
214
+ return g.set(e, s), s;
118
215
  }
119
- const d = {
120
- label: (a == null ? void 0 : a.label) ?? t,
121
- required: (a == null ? void 0 : a.required) ?? !1,
216
+ const y = () => {
217
+ const u = t.getValues(e);
218
+ return l.Type === "File" ? u ?? [] : u;
219
+ }, U = {
220
+ label: (r == null ? void 0 : r.label) ?? e,
221
+ required: (r == null ? void 0 : r.required) ?? !1,
122
222
  readOnly: !0,
123
- defaultValue: a == null ? void 0 : a.defaultValue,
124
- meta: y,
125
- get: () => e.getValues(t),
126
- getOrDefault: g,
127
- validate: n
223
+ defaultValue: r == null ? void 0 : r.defaultValue,
224
+ meta: l,
225
+ get: y,
226
+ getOrDefault: M,
227
+ validate: b
128
228
  };
129
- return f.set(t, d), d;
229
+ if (l.Type === "Image" || l.Type === "File") {
230
+ const u = w, s = () => {
231
+ const n = t.getValues("_id");
232
+ if (!n) throw new Error("Cannot perform attachment operation: item has no _id. Save the item first.");
233
+ return n;
234
+ };
235
+ l.Type === "Image" ? U.getDownloadUrl = async (n) => {
236
+ const d = t.getValues(e), a = s();
237
+ if (!(d != null && d._id)) throw new Error(`${e} has no image to download`);
238
+ return T(u).getDownloadUrl(a, e, d._id, n);
239
+ } : (U.getDownloadUrl = async (n, d) => {
240
+ const a = s();
241
+ return T(u).getDownloadUrl(a, e, n, d);
242
+ }, U.getDownloadUrls = async (n) => {
243
+ const d = s();
244
+ return T(u).getDownloadUrls(d, e, n);
245
+ });
246
+ }
247
+ return g.set(e, U), U;
130
248
  },
131
- has(o, t) {
132
- return typeof t == "symbol" ? !1 : t === "_id" || t === "toJSON" || t === "validate" ? !0 : t in r;
249
+ has(I, e) {
250
+ return typeof e == "symbol" ? !1 : e === "_id" || e === "toJSON" || e === "validate" || e === "_hasDraft" ? !0 : e in i;
133
251
  },
134
- ownKeys(o) {
135
- return [...Object.keys(r), "_id", "toJSON", "validate"];
252
+ ownKeys(I) {
253
+ return [...Object.keys(i), "_id", "toJSON", "validate"];
136
254
  },
137
- getOwnPropertyDescriptor(o, t) {
138
- if (typeof t != "symbol")
255
+ getOwnPropertyDescriptor(I, e) {
256
+ if (typeof e != "symbol")
139
257
  return {
140
258
  configurable: !0,
141
- enumerable: t !== "toJSON" && t !== "validate"
259
+ enumerable: e !== "toJSON" && e !== "validate" && e !== "_hasDraft"
142
260
  };
143
261
  }
144
262
  });
145
263
  }
146
- function Q(s) {
264
+ function k(o, t) {
265
+ const i = o.meta.Type;
266
+ if (typeof t == "string" && i === "Number")
267
+ return t === "" ? void 0 : Number(t);
268
+ if (!(typeof t == "string" && t === "" && (i === "Date" || i === "DateTime"))) {
269
+ if (typeof t == "string" && t !== "" && i === "DateTime") {
270
+ let g = t;
271
+ return g.endsWith("Z") && (g = g.slice(0, -1)), ((g.split("T")[1] || "").match(/:/g) || []).length === 1 && (g += ":00"), g + "Z";
272
+ }
273
+ return t;
274
+ }
275
+ }
276
+ function X(o, t) {
277
+ var w;
278
+ const i = o.getFields(), g = { ...t };
279
+ for (const [f, S] of Object.entries(g))
280
+ typeof S == "string" && ((w = i[f]) == null ? void 0 : w.meta.Type) === "DateTime" && S.endsWith("Z") && (g[f] = S.slice(0, -1));
281
+ return g;
282
+ }
283
+ function ae(o) {
147
284
  const {
148
- bdo: e,
149
- recordId: r,
150
- operation: f,
151
- defaultValues: o,
152
- mode: t = "onBlur",
153
- enableDraft: a = !1,
154
- enableConstraintValidation: y,
155
- enableExpressionValidation: S
156
- } = s, n = f ?? (r ? "update" : "create"), g = D(
157
- () => J(e, { enableConstraintValidation: y }),
158
- [e, y]
285
+ bdo: t,
286
+ recordId: i,
287
+ operation: g,
288
+ defaultValues: w,
289
+ mode: f = "onBlur",
290
+ enableDraft: S = !1,
291
+ enableConstraintValidation: q,
292
+ enableExpressionValidation: I
293
+ } = o, e = g ?? (i ? "update" : "create"), r = z(
294
+ () => Q(t, { enableConstraintValidation: q }),
295
+ [t, q]
159
296
  ), {
160
- data: d,
161
- isLoading: u,
162
- isFetching: l,
163
- error: x
164
- } = w({
165
- queryKey: ["form-record", e.meta._id, r],
166
- queryFn: async () => (await e.get(r)).toJSON(),
167
- enabled: n === "update" && !!r,
297
+ data: l,
298
+ isLoading: P,
299
+ isFetching: b,
300
+ error: M
301
+ } = A({
302
+ queryKey: ["form-record", t.meta._id, i],
303
+ queryFn: async () => {
304
+ const D = await t.get(i);
305
+ return X(t, D.toJSON());
306
+ },
307
+ enabled: e === "update" && !!i,
168
308
  staleTime: 0
169
- // Always fetch fresh data for forms
170
- }), { data: c } = w({
171
- queryKey: ["form-schema", e.meta._id],
172
- queryFn: () => C(e.meta._id),
309
+ }), {
310
+ data: y,
311
+ isLoading: U,
312
+ error: u
313
+ } = A({
314
+ queryKey: ["form-draft", t.meta._id],
315
+ queryFn: async () => T(t.meta._id).draftInteraction({}),
316
+ enabled: e === "create",
317
+ staleTime: 1 / 0,
318
+ gcTime: 0,
319
+ retry: 1
320
+ }), { data: s } = A({
321
+ queryKey: ["form-schema", t.meta._id],
322
+ queryFn: () => W(t.meta._id),
173
323
  staleTime: 30 * 60 * 1e3,
174
- // Cache for 30 minutes
175
324
  gcTime: 60 * 60 * 1e3,
176
- // Keep in cache for 1 hour
177
- enabled: S !== !1
325
+ enabled: I !== !1
178
326
  });
179
- T(() => {
180
- c != null && c.BDOBlob ? e.loadMetadata(c.BDOBlob) : c != null && c.MetaBlob && e.loadMetadata(c.MetaBlob);
181
- }, [c, e]);
182
- const i = j({
183
- mode: t,
184
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
185
- resolver: g,
186
- // Validation integrated here!
187
- defaultValues: o,
188
- // `values` prop reactively updates form when record loads
189
- values: n === "update" && d ? d : void 0
190
- }), B = D(
191
- () => I(e, i),
192
- [e, i]
193
- ), h = e.getFields(), P = q(
194
- (V, m) => {
195
- var v;
196
- const b = i.register(V, m);
197
- return (v = h[V]) != null && v.readOnly ? { ...b, disabled: !0 } : b;
327
+ E(() => {
328
+ s != null && s.BDOBlob ? t.loadMetadata(s.BDOBlob) : s != null && s.MetaBlob && t.loadMetadata(s.MetaBlob);
329
+ }, [s, t]);
330
+ const n = G({
331
+ mode: f,
332
+ resolver: r,
333
+ defaultValues: w
334
+ // NOTE: Don't use `values` prop — it continuously syncs and overrides
335
+ // setValue() calls for unregistered fields (Image/File attachments).
336
+ // Instead, we reset once when record arrives (see useEffect below).
337
+ }), d = B(null);
338
+ E(() => {
339
+ e === "update" && l && l !== d.current && (n.reset(l), d.current = l);
340
+ }, [l, e, n]), E(() => {
341
+ y != null && y._id && n.setValue("_id", y._id);
342
+ }, [y, n]);
343
+ const a = z(
344
+ () => H(t, n),
345
+ [t, n]
346
+ ), c = t.getFields(), h = j(
347
+ (D, V) => {
348
+ var F;
349
+ const _ = n.register(D, V);
350
+ return (F = c[D]) != null && F.readOnly ? { ..._, disabled: !0 } : _;
198
351
  },
199
- [i, h]
200
- ), N = q(
201
- (V, m) => i.handleSubmit(
202
- // onValid - validation passed, make API call
203
- async (b, v) => {
352
+ [n, c]
353
+ ), m = B(null);
354
+ E(() => {
355
+ if (e !== "create" || !(y != null && y._id)) return;
356
+ const D = n.watch((V, { type: _ }) => {
357
+ _ === "change" && (m.current && clearTimeout(m.current), m.current = setTimeout(async () => {
358
+ const F = n.getValues(), v = n.formState.dirtyFields, x = {};
359
+ for (const [O, N] of Object.entries(F))
360
+ c[O] && !c[O].readOnly && v[O] && (x[O] = k(c[O], N));
361
+ if (Object.keys(x).length > 0)
362
+ try {
363
+ await T(t.meta._id).draftInteraction({ _id: y._id, ...x });
364
+ } catch {
365
+ }
366
+ }, 800));
367
+ });
368
+ return () => {
369
+ D.unsubscribe(), m.current && clearTimeout(m.current);
370
+ };
371
+ }, [n, e, y, c, t]);
372
+ const $ = j(
373
+ (D, V) => n.handleSubmit(
374
+ async (_, F) => {
204
375
  try {
205
- const O = {};
206
- if (n === "create")
207
- for (const [M, _] of Object.entries(b))
208
- h[M] && !h[M].readOnly && (O[M] = _);
376
+ const v = {}, x = n.getValues();
377
+ if (e === "create")
378
+ for (const [N, R] of Object.entries(c)) {
379
+ if (R.readOnly) continue;
380
+ const C = x[N] !== void 0 ? x[N] : _[N];
381
+ C !== void 0 && (v[N] = k(R, C));
382
+ }
209
383
  else {
210
- const M = i.formState.dirtyFields;
211
- for (const [_, k] of Object.entries(b))
212
- h[_] && !h[_].readOnly && M[_] && (O[_] = k);
384
+ const N = n.formState.dirtyFields;
385
+ for (const [R, C] of Object.entries(c)) {
386
+ if (C.readOnly || !N[R]) continue;
387
+ const Z = x[R] !== void 0 ? x[R] : _[R];
388
+ v[R] = k(C, Z);
389
+ }
213
390
  }
214
- let R;
215
- n === "create" ? R = await e.create(
216
- O
217
- ) : R = await e.update(
218
- r,
219
- O
220
- ), V == null || V(R, v);
221
- } catch (O) {
222
- m == null || m(O, v);
391
+ let O;
392
+ e === "create" ? (v._id = y == null ? void 0 : y._id, O = await T(t.meta._id).draft(v)) : O = await T(t.meta._id).update(i, v), D == null || D(O, F);
393
+ } catch (v) {
394
+ V == null || V(v, F);
223
395
  }
224
396
  },
225
- // onInvalid - validation failed
226
- (b, v) => {
227
- m == null || m(b, v);
397
+ (_, F) => {
398
+ V == null || V(_, F);
228
399
  }
229
400
  ),
230
- [i, e, n, r, h]
401
+ [n, t, e, i, c, y]
231
402
  );
232
403
  return {
233
- // Item - synced with form
234
- item: B,
235
- // BDO reference
236
- bdo: e,
237
- operation: n,
238
- recordId: r,
239
- // Smart register (auto-disables readonly fields)
240
- register: P,
241
- // Custom handleSubmit (handles API call + filters payload)
242
- handleSubmit: N,
243
- // RHF methods (spread, but handleSubmit is overridden above)
244
- watch: i.watch,
245
- setValue: i.setValue,
246
- getValues: i.getValues,
247
- reset: i.reset,
248
- trigger: i.trigger,
249
- control: i.control,
250
- formState: i.formState,
251
- // Flattened state for convenience
252
- errors: i.formState.errors,
253
- isDirty: i.formState.isDirty,
254
- isValid: i.formState.isValid,
255
- isSubmitting: i.formState.isSubmitting,
256
- isSubmitSuccessful: i.formState.isSubmitSuccessful,
257
- dirtyFields: i.formState.dirtyFields,
258
- // Loading states
259
- isLoading: u,
260
- isFetching: l,
261
- // Error
262
- loadError: x
404
+ item: a,
405
+ bdo: t,
406
+ operation: e,
407
+ recordId: i,
408
+ register: h,
409
+ handleSubmit: $,
410
+ watch: n.watch,
411
+ setValue: n.setValue,
412
+ getValues: n.getValues,
413
+ reset: n.reset,
414
+ trigger: n.trigger,
415
+ control: n.control,
416
+ formState: n.formState,
417
+ errors: n.formState.errors,
418
+ isDirty: n.formState.isDirty,
419
+ isValid: n.formState.isValid,
420
+ isSubmitting: n.formState.isSubmitting,
421
+ isSubmitSuccessful: n.formState.isSubmitSuccessful,
422
+ dirtyFields: n.formState.dirtyFields,
423
+ isLoading: P || U,
424
+ isFetching: b,
425
+ loadError: M ?? u,
426
+ draftId: y == null ? void 0 : y._id,
427
+ isCreatingDraft: U
263
428
  };
264
429
  }
265
430
  export {
266
- H as FormOperation,
267
- U as InteractionMode,
268
- W as ValidationMode,
269
- Q as useForm
431
+ le as FormOperation,
432
+ oe as InteractionMode,
433
+ ce as ValidationMode,
434
+ ae as useForm
270
435
  };
@@ -1 +1 @@
1
- "use strict";const o=require("./client-BnVxSHAm.cjs");async function c(e){try{const r=o.getApiBaseUrl(),s=o.getDefaultHeaders(),a=await fetch(`${r}/api/app/meta/bdo/${e}`,{method:"GET",headers:s});if(!a.ok)throw new Error(`Failed to fetch schema for ${e}: ${a.statusText}`);const t=await a.json();if(!t||typeof t!="object")throw new Error(`Invalid BDO schema response for ${e}`);return t}catch(r){throw console.error(`Schema fetch error for ${e}:`,r),new Error(`Failed to load BDO schema: ${r instanceof Error?r.message:"Unknown error"}`)}}async function n(e){try{const r=o.getApiBaseUrl(),s=o.getDefaultHeaders(),a=e!=null&&e.Filter||e!=null&&e.Sort?"POST":"GET",t=await fetch(`${r}/api/app/metadata/list`,{method:a,headers:s,...a==="POST"&&e&&{body:JSON.stringify(e)}});if(!t.ok)throw new Error(`Failed to list metadata: ${t.statusText}`);return await t.json()}catch(r){throw console.error("Metadata list error:",r),new Error(`Failed to list metadata: ${r instanceof Error?r.message:"Unknown error"}`)}}exports.getBdoSchema=c;exports.listMetadata=n;
1
+ "use strict";const o=require("./client-DnO2KKrw.cjs");async function c(e){try{const r=o.getApiBaseUrl(),s=o.getDefaultHeaders(),a=await fetch(`${r}/api/app/meta/bdo/${e}`,{method:"GET",headers:s});if(!a.ok)throw new Error(`Failed to fetch schema for ${e}: ${a.statusText}`);const t=await a.json();if(!t||typeof t!="object")throw new Error(`Invalid BDO schema response for ${e}`);return t}catch(r){throw console.error(`Schema fetch error for ${e}:`,r),new Error(`Failed to load BDO schema: ${r instanceof Error?r.message:"Unknown error"}`)}}async function n(e){try{const r=o.getApiBaseUrl(),s=o.getDefaultHeaders(),a=e!=null&&e.Filter||e!=null&&e.Sort?"POST":"GET",t=await fetch(`${r}/api/app/metadata/list`,{method:a,headers:s,...a==="POST"&&e&&{body:JSON.stringify(e)}});if(!t.ok)throw new Error(`Failed to list metadata: ${t.statusText}`);return await t.json()}catch(r){throw console.error("Metadata list error:",r),new Error(`Failed to list metadata: ${r instanceof Error?r.message:"Unknown error"}`)}}exports.getBdoSchema=c;exports.listMetadata=n;
@@ -1,4 +1,4 @@
1
- import { c as s, g as c } from "./client-CMERmrC-.js";
1
+ import { c as s, g as c } from "./client-iQTqFDNI.js";
2
2
  async function l(r) {
3
3
  try {
4
4
  const e = s(), o = c(), a = await fetch(`${e}/api/app/meta/bdo/${r}`, {