@ram_28/kf-ai-sdk 2.0.15 → 2.0.16

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 (83) hide show
  1. package/README.md +8 -8
  2. package/dist/bdo/core/BaseBdo.d.ts +1 -1
  3. package/dist/bdo.mjs +2 -2
  4. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts +1 -1
  5. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
  6. package/dist/components/hooks/useActivityForm/types.d.ts +2 -2
  7. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  8. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  9. package/dist/components/hooks/useActivityTable/types.d.ts +4 -4
  10. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  11. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +1 -1
  12. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  13. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -0
  14. package/dist/components/hooks/useBDOForm/createResolver.d.ts.map +1 -0
  15. package/dist/components/hooks/useBDOForm/index.d.ts +6 -0
  16. package/dist/components/hooks/useBDOForm/index.d.ts.map +1 -0
  17. package/dist/components/hooks/useBDOForm/shared.d.ts +50 -0
  18. package/dist/components/hooks/useBDOForm/shared.d.ts.map +1 -0
  19. package/dist/components/hooks/{useForm → useBDOForm}/types.d.ts +6 -6
  20. package/dist/components/hooks/useBDOForm/types.d.ts.map +1 -0
  21. package/dist/components/hooks/{useForm/useForm.d.ts → useBDOForm/useBDOForm.d.ts} +4 -4
  22. package/dist/components/hooks/useBDOForm/useBDOForm.d.ts.map +1 -0
  23. package/dist/components/hooks/useBDOTable/types.d.ts +1 -3
  24. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  25. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  26. package/dist/form.cjs +1 -1
  27. package/dist/form.d.ts +1 -1
  28. package/dist/form.d.ts.map +1 -1
  29. package/dist/form.mjs +250 -253
  30. package/dist/form.types.d.ts +1 -1
  31. package/dist/form.types.d.ts.map +1 -1
  32. package/dist/shared-5a7UkED1.js +1180 -0
  33. package/dist/shared-nnmlRVs7.cjs +1 -0
  34. package/dist/table.cjs +1 -1
  35. package/dist/table.mjs +12 -11
  36. package/dist/types/constants.d.ts +3 -3
  37. package/dist/workflow/Activity.d.ts +15 -3
  38. package/dist/workflow/Activity.d.ts.map +1 -1
  39. package/dist/workflow/client.d.ts +2 -2
  40. package/dist/workflow/client.d.ts.map +1 -1
  41. package/dist/workflow/types.d.ts +7 -3
  42. package/dist/workflow/types.d.ts.map +1 -1
  43. package/dist/workflow.cjs +1 -1
  44. package/dist/workflow.mjs +503 -546
  45. package/docs/bdo.md +1 -1
  46. package/docs/gaps.md +14 -64
  47. package/docs/useActivityForm.md +393 -0
  48. package/docs/useActivityTable.md +42 -105
  49. package/docs/{useForm.md → useBDOForm.md} +24 -24
  50. package/docs/useBDOTable.md +6 -39
  51. package/docs/workflow.md +43 -301
  52. package/package.json +2 -2
  53. package/sdk/bdo/core/BaseBdo.ts +2 -2
  54. package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +1 -1
  55. package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +1 -1
  56. package/sdk/components/hooks/useActivityForm/types.ts +4 -4
  57. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +44 -194
  58. package/sdk/components/hooks/useActivityTable/types.ts +4 -2
  59. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +8 -39
  60. package/sdk/components/hooks/{useForm → useBDOForm}/index.ts +4 -3
  61. package/sdk/components/hooks/useBDOForm/shared.ts +250 -0
  62. package/sdk/components/hooks/{useForm → useBDOForm}/types.ts +9 -9
  63. package/sdk/components/hooks/{useForm/useForm.ts → useBDOForm/useBDOForm.ts} +70 -96
  64. package/sdk/components/hooks/useBDOTable/types.ts +1 -3
  65. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +3 -2
  66. package/sdk/form.ts +2 -2
  67. package/sdk/form.types.ts +4 -4
  68. package/sdk/types/constants.ts +3 -3
  69. package/sdk/workflow/Activity.ts +29 -6
  70. package/sdk/workflow/client.ts +65 -25
  71. package/sdk/workflow/types.ts +10 -2
  72. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +0 -1
  73. package/dist/components/hooks/useForm/createResolver.d.ts.map +0 -1
  74. package/dist/components/hooks/useForm/index.d.ts +0 -5
  75. package/dist/components/hooks/useForm/index.d.ts.map +0 -1
  76. package/dist/components/hooks/useForm/types.d.ts.map +0 -1
  77. package/dist/components/hooks/useForm/useForm.d.ts.map +0 -1
  78. package/dist/createResolver-AIgUwoS6.cjs +0 -1
  79. package/dist/createResolver-ZHXQ7QMa.js +0 -1078
  80. /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
  81. /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
  82. /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
  83. /package/sdk/components/hooks/{useForm → useBDOForm}/createResolver.ts +0 -0
package/dist/form.mjs CHANGED
@@ -1,194 +1,194 @@
1
- import { F as le, I as oe, V as ue } from "./constants-ConHc1oS.js";
2
- import { useMemo as j, useEffect as M, useRef as A, useCallback as L } from "react";
3
- import { v as Z, c as G, u as W } from "./createResolver-ZHXQ7QMa.js";
4
- import { useQuery as B } from "@tanstack/react-query";
5
- import { a as _ } from "./client-_ayziI1d.js";
6
- import { v as J, e as K } from "./attachment-constants-C2UHWxmp.js";
7
- import { g as Q } from "./metadata-Cc1mBcLS.js";
8
- function H(T, t) {
9
- const d = T.getFields(), m = /* @__PURE__ */ new Map(), D = T.getBoId();
10
- let V = null, I = null;
1
+ import { F as he, I as _e, V as we } from "./constants-ConHc1oS.js";
2
+ import { useMemo as b, useEffect as k, useRef as j, useCallback as K } from "react";
3
+ import { v as Z, c as p, a as ee, u as te, b as ae, d as ne, e as se, f as $ } from "./shared-5a7UkED1.js";
4
+ import { useQuery as J } from "@tanstack/react-query";
5
+ import { a as y } from "./client-_ayziI1d.js";
6
+ import { v as G, e as Q } from "./attachment-constants-C2UHWxmp.js";
7
+ import { g as ie } from "./metadata-Cc1mBcLS.js";
8
+ function re(D, a) {
9
+ const g = D.getFields(), T = /* @__PURE__ */ new Map(), C = D.getBoId();
10
+ let m = null, x = null;
11
11
  async function R() {
12
- const F = t.getValues("_id");
13
- return F || V || (I || (I = _(D).draftInteraction({}).then((e) => (V = e._id, t.setValue("_id", V, { shouldDirty: !1 }), V)).catch((e) => {
14
- throw I = null, e;
15
- })), I);
12
+ const F = a.getValues("_id");
13
+ return F || m || (x || (x = y(C).draftInteraction({}).then((e) => (m = e._id, a.setValue("_id", m, { shouldDirty: !1 }), m)).catch((e) => {
14
+ throw x = null, e;
15
+ })), x);
16
16
  }
17
17
  return new Proxy({}, {
18
18
  get(F, e) {
19
19
  if (typeof e == "symbol")
20
20
  return;
21
21
  if (e === "_id")
22
- return t.getValues("_id");
22
+ return a.getValues("_id");
23
23
  if (e === "toJSON")
24
- return () => t.getValues();
24
+ return () => a.getValues();
25
25
  if (e === "validate")
26
- return () => t.trigger();
26
+ return () => a.trigger();
27
27
  if (e === "_hasDraft")
28
- return () => !!V;
29
- if (m.has(e))
30
- return m.get(e);
31
- const r = d[e], h = (r == null ? void 0 : r.meta) ?? {
28
+ return () => !!m;
29
+ if (T.has(e))
30
+ return T.get(e);
31
+ const s = g[e], c = (s == null ? void 0 : s.meta) ?? {
32
32
  _id: e,
33
33
  Name: e,
34
34
  Type: "String"
35
- }, z = (r == null ? void 0 : r.readOnly) ?? !1, C = () => {
36
- if (!r) return { valid: !0, errors: [] };
37
- let l = t.getValues(e);
38
- if ("integerPart" in r && typeof l == "string" && l !== "") {
35
+ }, A = (s == null ? void 0 : s.readOnly) ?? !1, B = () => {
36
+ if (!s) return { valid: !0, errors: [] };
37
+ let l = a.getValues(e);
38
+ if ("integerPart" in s && typeof l == "string" && l !== "") {
39
39
  const o = Number(l);
40
- isNaN(o) || (l = o, t.setValue(e, o, { shouldDirty: !1 }));
40
+ isNaN(o) || (l = o, a.setValue(e, o, { shouldDirty: !1 }));
41
41
  }
42
- if (!r.required && (l == null || l === "" || Array.isArray(l) && l.length === 0))
42
+ if (!s.required && (l == null || l === "" || Array.isArray(l) && l.length === 0))
43
43
  return { valid: !0, errors: [] };
44
- const i = r.validate(l);
44
+ const i = s.validate(l);
45
45
  if (!i.valid) return i;
46
- const a = Z(r, l);
47
- if (!a.valid) return a;
48
- if (T.hasMetadata()) {
49
- const o = T.validateFieldExpression(
46
+ const t = Z(s, l);
47
+ if (!t.valid) return t;
48
+ if (D.hasMetadata()) {
49
+ const o = D.validateFieldExpression(
50
50
  e,
51
51
  l,
52
- t.getValues()
52
+ a.getValues()
53
53
  );
54
54
  if (!o.valid) return o;
55
55
  }
56
56
  return { valid: !0, errors: [] };
57
- }, P = (l) => {
58
- const i = t.getValues(e);
57
+ }, E = (l) => {
58
+ const i = a.getValues(e);
59
59
  return i ?? l;
60
60
  };
61
- if (!z) {
61
+ if (!A) {
62
62
  const l = () => {
63
- const a = t.getValues(e);
64
- return h.Type === "File" ? a ?? [] : a;
63
+ const t = a.getValues(e);
64
+ return c.Type === "File" ? t ?? [] : t;
65
65
  }, i = {
66
- label: (r == null ? void 0 : r.label) ?? e,
67
- required: (r == null ? void 0 : r.required) ?? !1,
66
+ label: (s == null ? void 0 : s.label) ?? e,
67
+ required: (s == null ? void 0 : s.required) ?? !1,
68
68
  readOnly: !1,
69
- defaultValue: r == null ? void 0 : r.defaultValue,
70
- meta: h,
69
+ defaultValue: s == null ? void 0 : s.defaultValue,
70
+ meta: c,
71
71
  get: l,
72
- getOrDefault: P,
73
- set: (a) => {
74
- t.setValue(e, a, {
72
+ getOrDefault: E,
73
+ set: (t) => {
74
+ a.setValue(e, t, {
75
75
  shouldDirty: !0,
76
76
  shouldTouch: !0,
77
77
  shouldValidate: !1
78
78
  // Let mode control validation timing
79
79
  });
80
80
  },
81
- validate: C
81
+ validate: B
82
82
  };
83
- if (h.Type === "Image" || h.Type === "File") {
84
- const a = D, o = () => {
85
- const n = t.getValues("_id");
83
+ if (c.Type === "Image" || c.Type === "File") {
84
+ const t = C, o = () => {
85
+ const n = a.getValues("_id");
86
86
  if (!n) throw new Error("Save the record before attachment operations");
87
87
  return n;
88
88
  };
89
- h.Type === "Image" ? (i.upload = async (n) => {
90
- J(n.name, "Image");
91
- const s = await R(), [f] = await _(a).getUploadUrl(s, e, [
92
- { FileName: n.name, Size: n.size, FileExtension: K(n.name) }
89
+ c.Type === "Image" ? (i.upload = async (n) => {
90
+ G(n.name, "Image");
91
+ const r = await R(), [u] = await y(t).getUploadUrl(r, e, [
92
+ { FileName: n.name, Size: n.size, FileExtension: Q(n.name) }
93
93
  ]);
94
- await fetch(f.UploadUrl.URL, {
94
+ await fetch(u.UploadUrl.URL, {
95
95
  method: "PUT",
96
- headers: { "Content-Type": f.ContentType },
96
+ headers: { "Content-Type": u.ContentType },
97
97
  body: n
98
98
  });
99
- const c = {
100
- _id: f._id,
101
- _name: f._name,
102
- FileName: f.FileName,
103
- FileExtension: f.FileExtension,
104
- Size: f.Size,
105
- ContentType: f.ContentType
99
+ const f = {
100
+ _id: u._id,
101
+ _name: u._name,
102
+ FileName: u.FileName,
103
+ FileExtension: u.FileExtension,
104
+ Size: u.Size,
105
+ ContentType: u.ContentType
106
106
  };
107
- return t.setValue(e, c, { shouldDirty: !0 }), c;
107
+ return a.setValue(e, f, { shouldDirty: !0 }), f;
108
108
  }, i.deleteAttachment = async () => {
109
- const n = t.getValues(e), s = o();
109
+ const n = a.getValues(e), r = o();
110
110
  if (!(n != null && n._id)) throw new Error(`${e} has no image to delete`);
111
- await _(a).deleteAttachment(s, e, n._id), t.setValue(e, null, { shouldDirty: !0 });
111
+ await y(t).deleteAttachment(r, e, n._id), a.setValue(e, null, { shouldDirty: !0 });
112
112
  }, i.getDownloadUrl = async (n) => {
113
- const s = t.getValues(e), f = o();
114
- if (!(s != null && s._id)) throw new Error(`${e} has no image`);
115
- return _(a).getDownloadUrl(f, e, s._id, n);
113
+ const r = a.getValues(e), u = o();
114
+ if (!(r != null && r._id)) throw new Error(`${e} has no image`);
115
+ return y(t).getDownloadUrl(u, e, r._id, n);
116
116
  }) : (i.upload = async (n) => {
117
- for (const g of n) J(g.name, "File");
118
- const s = await R(), f = n.map((g) => ({
119
- FileName: g.name,
120
- Size: g.size,
121
- FileExtension: K(g.name)
122
- })), c = await _(a).getUploadUrl(s, e, f), E = await Promise.all(
123
- n.map(async (g, y) => (await fetch(c[y].UploadUrl.URL, {
117
+ for (const _ of n) G(_.name, "File");
118
+ const r = await R(), u = n.map((_) => ({
119
+ FileName: _.name,
120
+ Size: _.size,
121
+ FileExtension: Q(_.name)
122
+ })), f = await y(t).getUploadUrl(r, e, u), N = await Promise.all(
123
+ n.map(async (_, h) => (await fetch(f[h].UploadUrl.URL, {
124
124
  method: "PUT",
125
- headers: { "Content-Type": c[y].ContentType },
126
- body: g
125
+ headers: { "Content-Type": f[h].ContentType },
126
+ body: _
127
127
  }), {
128
- _id: c[y]._id,
129
- _name: c[y]._name,
130
- FileName: c[y].FileName,
131
- FileExtension: c[y].FileExtension,
132
- Size: c[y].Size,
133
- ContentType: c[y].ContentType
128
+ _id: f[h]._id,
129
+ _name: f[h]._name,
130
+ FileName: f[h].FileName,
131
+ FileExtension: f[h].FileExtension,
132
+ Size: f[h].Size,
133
+ ContentType: f[h].ContentType
134
134
  }))
135
- ), w = t.getValues(e) ?? [];
136
- return t.setValue(e, [...w, ...E], { shouldDirty: !0 }), E;
135
+ ), O = a.getValues(e) ?? [];
136
+ return a.setValue(e, [...O, ...N], { shouldDirty: !0 }), N;
137
137
  }, i.deleteAttachment = async (n) => {
138
- const s = t.getValues(e) ?? [], f = o();
139
- await _(a).deleteAttachment(f, e, n), t.setValue(
138
+ const r = a.getValues(e) ?? [], u = o();
139
+ await y(t).deleteAttachment(u, e, n), a.setValue(
140
140
  e,
141
- s.filter((c) => c._id !== n),
141
+ r.filter((f) => f._id !== n),
142
142
  { shouldDirty: !0 }
143
143
  );
144
- }, i.getDownloadUrl = async (n, s) => {
145
- const f = o();
146
- return _(a).getDownloadUrl(f, e, n, s);
144
+ }, i.getDownloadUrl = async (n, r) => {
145
+ const u = o();
146
+ return y(t).getDownloadUrl(u, e, n, r);
147
147
  }, i.getDownloadUrls = async (n) => {
148
- const s = o();
149
- return _(a).getDownloadUrls(s, e, n);
148
+ const r = o();
149
+ return y(t).getDownloadUrls(r, e, n);
150
150
  });
151
151
  }
152
- return m.set(e, i), i;
152
+ return T.set(e, i), i;
153
153
  }
154
- const u = () => {
155
- const l = t.getValues(e);
156
- return h.Type === "File" ? l ?? [] : l;
157
- }, O = {
158
- label: (r == null ? void 0 : r.label) ?? e,
159
- required: (r == null ? void 0 : r.required) ?? !1,
154
+ const d = () => {
155
+ const l = a.getValues(e);
156
+ return c.Type === "File" ? l ?? [] : l;
157
+ }, I = {
158
+ label: (s == null ? void 0 : s.label) ?? e,
159
+ required: (s == null ? void 0 : s.required) ?? !1,
160
160
  readOnly: !0,
161
- defaultValue: r == null ? void 0 : r.defaultValue,
162
- meta: h,
163
- get: u,
164
- getOrDefault: P,
165
- validate: C
161
+ defaultValue: s == null ? void 0 : s.defaultValue,
162
+ meta: c,
163
+ get: d,
164
+ getOrDefault: E,
165
+ validate: B
166
166
  };
167
- if (h.Type === "Image" || h.Type === "File") {
168
- const l = D, i = () => {
169
- const a = t.getValues("_id");
170
- if (!a) throw new Error("Cannot perform attachment operation: item has no _id. Save the item first.");
171
- return a;
167
+ if (c.Type === "Image" || c.Type === "File") {
168
+ const l = C, i = () => {
169
+ const t = a.getValues("_id");
170
+ if (!t) throw new Error("Cannot perform attachment operation: item has no _id. Save the item first.");
171
+ return t;
172
172
  };
173
- h.Type === "Image" ? O.getDownloadUrl = async (a) => {
174
- const o = t.getValues(e), n = i();
173
+ c.Type === "Image" ? I.getDownloadUrl = async (t) => {
174
+ const o = a.getValues(e), n = i();
175
175
  if (!(o != null && o._id)) throw new Error(`${e} has no image to download`);
176
- return _(l).getDownloadUrl(n, e, o._id, a);
177
- } : (O.getDownloadUrl = async (a, o) => {
176
+ return y(l).getDownloadUrl(n, e, o._id, t);
177
+ } : (I.getDownloadUrl = async (t, o) => {
178
178
  const n = i();
179
- return _(l).getDownloadUrl(n, e, a, o);
180
- }, O.getDownloadUrls = async (a) => {
179
+ return y(l).getDownloadUrl(n, e, t, o);
180
+ }, I.getDownloadUrls = async (t) => {
181
181
  const o = i();
182
- return _(l).getDownloadUrls(o, e, a);
182
+ return y(l).getDownloadUrls(o, e, t);
183
183
  });
184
184
  }
185
- return m.set(e, O), O;
185
+ return T.set(e, I), I;
186
186
  },
187
187
  has(F, e) {
188
- return typeof e == "symbol" ? !1 : e === "_id" || e === "toJSON" || e === "validate" || e === "_hasDraft" ? !0 : e in d;
188
+ return typeof e == "symbol" ? !1 : e === "_id" || e === "toJSON" || e === "validate" || e === "_hasDraft" ? !0 : e in g;
189
189
  },
190
190
  ownKeys(F) {
191
- return [...Object.keys(d), "_id", "toJSON", "validate"];
191
+ return [...Object.keys(g), "_id", "toJSON", "validate"];
192
192
  },
193
193
  getOwnPropertyDescriptor(F, e) {
194
194
  if (typeof e != "symbol")
@@ -199,175 +199,172 @@ function H(T, t) {
199
199
  }
200
200
  });
201
201
  }
202
- function k(T, t) {
203
- const d = T.meta.Type;
204
- if (typeof t == "string" && d === "Number")
205
- return t === "" ? void 0 : Number(t);
206
- if (!(typeof t == "string" && t === "" && (d === "Date" || d === "DateTime"))) {
207
- if (typeof t == "string" && t !== "" && d === "DateTime") {
208
- let m = t;
209
- return m.endsWith("Z") && (m = m.slice(0, -1)), ((m.split("T")[1] || "").match(/:/g) || []).length === 1 && (m += ":00"), m + "Z";
210
- }
211
- return t;
212
- }
213
- }
214
- function X(T, t) {
215
- var D;
216
- const d = T.getFields(), m = { ...t };
217
- for (const [V, I] of Object.entries(m))
218
- typeof I == "string" && ((D = d[V]) == null ? void 0 : D.meta.Type) === "DateTime" && I.endsWith("Z") && (m[V] = I.slice(0, -1));
219
- return m;
220
- }
221
- function re(T) {
202
+ function ye(D) {
222
203
  const {
223
- bdo: t,
224
- recordId: d,
225
- operation: m,
226
- defaultValues: D,
227
- mode: V = "onBlur",
228
- enableDraft: I = !1,
204
+ bdo: a,
205
+ recordId: g,
206
+ operation: T,
207
+ defaultValues: C,
208
+ mode: m = "onBlur",
209
+ enableDraft: x = !1,
229
210
  enableConstraintValidation: R,
230
211
  enableExpressionValidation: F
231
- } = T, e = m ?? (d ? "update" : "create"), r = j(
232
- () => G(t, { enableConstraintValidation: R }),
233
- [t, R]
212
+ } = D, e = T ?? (g ? "update" : "create"), s = b(
213
+ () => p(a, { enableConstraintValidation: R }),
214
+ [a, R]
234
215
  ), {
235
- data: h,
236
- isLoading: z,
237
- isFetching: C,
238
- error: P
239
- } = B({
240
- queryKey: ["form-record", t.meta._id, d],
216
+ data: c,
217
+ isLoading: A,
218
+ isFetching: B,
219
+ error: E
220
+ } = J({
221
+ queryKey: ["form-record", a.meta._id, g],
241
222
  queryFn: async () => {
242
- const w = await t.get(d);
243
- return X(t, w.toJSON());
223
+ const w = await a.get(g);
224
+ return ee(a.getFields(), w.toJSON());
244
225
  },
245
- enabled: e === "update" && !!d,
226
+ enabled: e === "update" && !!g,
246
227
  staleTime: 0
247
228
  }), {
248
- data: u,
249
- isLoading: O,
229
+ data: d,
230
+ isLoading: I,
250
231
  error: l
251
- } = B({
252
- queryKey: ["form-draft", t.meta._id],
253
- queryFn: async () => _(t.meta._id).draftInteraction({}),
232
+ } = J({
233
+ queryKey: ["form-draft", a.meta._id],
234
+ queryFn: async () => y(a.meta._id).draftInteraction({}),
254
235
  enabled: e === "create",
255
236
  staleTime: 1 / 0,
256
237
  gcTime: 0,
257
238
  retry: 1
258
- }), { data: i } = B({
259
- queryKey: ["form-schema", t.meta._id],
260
- queryFn: () => Q(t.meta._id),
239
+ }), { data: i } = J({
240
+ queryKey: ["form-schema", a.meta._id],
241
+ queryFn: () => ie(a.meta._id),
261
242
  staleTime: 30 * 60 * 1e3,
262
243
  gcTime: 60 * 60 * 1e3,
263
244
  enabled: F !== !1
264
245
  });
265
- M(() => {
266
- i != null && i.BDOBlob ? t.loadMetadata(i.BDOBlob) : i != null && i.MetaBlob && t.loadMetadata(i.MetaBlob);
267
- }, [i, t]);
268
- const a = W({
269
- mode: V,
270
- resolver: r,
271
- defaultValues: D
246
+ k(() => {
247
+ i != null && i.BDOBlob ? a.loadMetadata(i.BDOBlob) : i != null && i.MetaBlob && a.loadMetadata(i.MetaBlob);
248
+ }, [i, a]);
249
+ const t = te({
250
+ mode: m,
251
+ resolver: s,
252
+ defaultValues: C
272
253
  // NOTE: Don't use `values` prop — it continuously syncs and overrides
273
254
  // setValue() calls for unregistered fields (Image/File attachments).
274
255
  // Instead, we reset once when record arrives (see useEffect below).
275
- }), o = A(null);
276
- M(() => {
277
- e === "update" && h && h !== o.current && (a.reset(h), o.current = h);
278
- }, [h, e, a]), M(() => {
279
- u != null && u._id && a.setValue("_id", u._id);
280
- }, [u, a]);
281
- const n = j(
282
- () => H(t, a),
283
- [t, a]
284
- ), s = t.getFields(), f = L(
285
- (w, g) => {
286
- var S;
287
- const y = a.register(w, g);
288
- return (S = s[w]) != null && S.readOnly ? { ...y, disabled: !0 } : y;
256
+ }), o = j(null);
257
+ k(() => {
258
+ e === "update" && c && c !== o.current && (t.reset(c), o.current = c);
259
+ }, [c, e, t]), k(() => {
260
+ d != null && d._id && t.setValue("_id", d._id);
261
+ }, [d, t]);
262
+ const n = b(
263
+ () => re(a, t),
264
+ [a, t]
265
+ ), r = a.getFields(), u = j(!1), f = b(
266
+ () => Object.keys(r).filter((w) => r[w].readOnly),
267
+ [r]
268
+ ), N = K(
269
+ async (w, V) => {
270
+ if (e === "create" && (d != null && d._id))
271
+ return y(a.meta._id).draftInteraction({
272
+ _id: d._id,
273
+ [w]: V
274
+ });
275
+ if (e === "update" && g)
276
+ return y(a.meta._id).update(g, {
277
+ [w]: V
278
+ });
289
279
  },
290
- [a, s]
291
- ), c = A(null);
292
- M(() => {
293
- if (e !== "create" || !(u != null && u._id)) return;
294
- const w = a.watch((g, { type: y }) => {
295
- y === "change" && (c.current && clearTimeout(c.current), c.current = setTimeout(async () => {
296
- const S = a.getValues(), b = a.formState.dirtyFields, U = {};
297
- for (const [v, x] of Object.entries(S))
298
- s[v] && !s[v].readOnly && b[v] && (U[v] = k(s[v], x));
299
- if (Object.keys(U).length > 0)
300
- try {
301
- await _(t.meta._id).draftInteraction({ _id: u._id, ...U });
302
- } catch {
303
- }
304
- }, 800));
305
- });
306
- return () => {
307
- w.unsubscribe(), c.current && clearTimeout(c.current);
308
- };
309
- }, [a, e, u, s, t]);
310
- const E = L(
311
- (w, g) => a.handleSubmit(
312
- async (y, S) => {
280
+ [e, d, g, a]
281
+ ), O = b(
282
+ () => ae({
283
+ apiFn: N,
284
+ allFields: r,
285
+ readonlyFieldNames: f,
286
+ rhf: t,
287
+ isComputingRef: u
288
+ }),
289
+ [N, r, f, t]
290
+ ), _ = m === "onChange" || m === "all", h = m === "onBlur" || m === "onTouched" || m === "all", H = b(
291
+ () => ne({
292
+ rhf: t,
293
+ allFields: r,
294
+ syncField: O,
295
+ syncOnBlur: h,
296
+ syncOnChange: _
297
+ }),
298
+ [t, r, O, h, _]
299
+ ), W = b(
300
+ () => se({
301
+ control: t.control,
302
+ syncField: O,
303
+ syncOnBlur: h,
304
+ syncOnChange: _
305
+ }),
306
+ [t.control, O, h, _]
307
+ ), X = K(
308
+ (w, V) => t.handleSubmit(
309
+ async (M, z) => {
313
310
  try {
314
- const b = {}, U = a.getValues();
311
+ const v = {}, P = t.getValues();
315
312
  if (e === "create")
316
- for (const [x, N] of Object.entries(s)) {
317
- if (N.readOnly) continue;
318
- const q = U[x] !== void 0 ? U[x] : y[x];
319
- q !== void 0 && (b[x] = k(N, q));
313
+ for (const [U, S] of Object.entries(r)) {
314
+ if (S.readOnly) continue;
315
+ const q = P[U] !== void 0 ? P[U] : M[U];
316
+ q !== void 0 && (v[U] = $(S, q));
320
317
  }
321
318
  else {
322
- const x = a.formState.dirtyFields;
323
- for (const [N, q] of Object.entries(s)) {
324
- if (q.readOnly || !x[N]) continue;
325
- const $ = U[N] !== void 0 ? U[N] : y[N];
326
- b[N] = k(q, $);
319
+ const U = t.formState.dirtyFields;
320
+ for (const [S, q] of Object.entries(r)) {
321
+ if (q.readOnly || !U[S]) continue;
322
+ const Y = P[S] !== void 0 ? P[S] : M[S];
323
+ v[S] = $(q, Y);
327
324
  }
328
325
  }
329
- let v;
330
- e === "create" ? (b._id = u == null ? void 0 : u._id, v = await _(t.meta._id).draft(b)) : v = await _(t.meta._id).update(d, b), w == null || w(v, S);
331
- } catch (b) {
332
- g == null || g(b, S);
326
+ let L;
327
+ e === "create" ? (v._id = d == null ? void 0 : d._id, L = await y(a.meta._id).draft(v)) : L = await y(a.meta._id).update(g, v), w == null || w(L, z);
328
+ } catch (v) {
329
+ V == null || V(v, z);
333
330
  }
334
331
  },
335
- (y, S) => {
336
- g == null || g(y, S);
332
+ (M, z) => {
333
+ V == null || V(M, z);
337
334
  }
338
335
  ),
339
- [a, t, e, d, s, u]
336
+ [t, a, e, g, r, d]
340
337
  );
341
338
  return {
342
339
  item: n,
343
- bdo: t,
340
+ bdo: a,
344
341
  operation: e,
345
- recordId: d,
346
- register: f,
347
- handleSubmit: E,
348
- watch: a.watch,
349
- setValue: a.setValue,
350
- getValues: a.getValues,
351
- reset: a.reset,
352
- trigger: a.trigger,
353
- control: a.control,
354
- formState: a.formState,
355
- errors: a.formState.errors,
356
- isDirty: a.formState.isDirty,
357
- isValid: a.formState.isValid,
358
- isSubmitting: a.formState.isSubmitting,
359
- isSubmitSuccessful: a.formState.isSubmitSuccessful,
360
- dirtyFields: a.formState.dirtyFields,
361
- isLoading: z || O,
362
- isFetching: C,
363
- loadError: P ?? l,
364
- draftId: u == null ? void 0 : u._id,
365
- isCreatingDraft: O
342
+ recordId: g,
343
+ register: H,
344
+ handleSubmit: X,
345
+ watch: t.watch,
346
+ setValue: t.setValue,
347
+ getValues: t.getValues,
348
+ reset: t.reset,
349
+ trigger: t.trigger,
350
+ control: W,
351
+ formState: t.formState,
352
+ errors: t.formState.errors,
353
+ isDirty: t.formState.isDirty,
354
+ isValid: t.formState.isValid,
355
+ isSubmitting: t.formState.isSubmitting,
356
+ isSubmitSuccessful: t.formState.isSubmitSuccessful,
357
+ dirtyFields: t.formState.dirtyFields,
358
+ isLoading: A || I,
359
+ isFetching: B,
360
+ loadError: E ?? l,
361
+ draftId: d == null ? void 0 : d._id,
362
+ isCreatingDraft: I
366
363
  };
367
364
  }
368
365
  export {
369
- le as FormOperation,
370
- oe as InteractionMode,
371
- ue as ValidationMode,
372
- re as useForm
366
+ he as FormOperation,
367
+ _e as InteractionMode,
368
+ we as ValidationMode,
369
+ ye as useBDOForm
373
370
  };
@@ -1,2 +1,2 @@
1
- export type { UseFormOptionsType, UseFormReturnType, FormItemType, EditableFormFieldAccessorType, ReadonlyFormFieldAccessorType, FormRegisterType, HandleSubmitType, ExtractEditableType, ExtractReadonlyType, AllFieldsType, } from "./components/hooks/useForm";
1
+ export type { UseBDOFormOptionsType, UseBDOFormReturnType, FormItemType, EditableFormFieldAccessorType, ReadonlyFormFieldAccessorType, FormRegisterType, HandleSubmitType, ExtractEditableType, ExtractReadonlyType, AllFieldsType, } from "./components/hooks/useBDOForm";
2
2
  //# sourceMappingURL=form.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.types.d.ts","sourceRoot":"","sources":["../sdk/form.types.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,6BAA6B,EAC7B,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,GACd,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"form.types.d.ts","sourceRoot":"","sources":["../sdk/form.types.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,6BAA6B,EAC7B,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,GACd,MAAM,+BAA+B,CAAC"}