@ram_28/kf-ai-sdk 2.0.14 → 2.0.15

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 (119) hide show
  1. package/README.md +2 -1
  2. package/dist/FileField-BWrSHNRq.js +296 -0
  3. package/dist/FileField-eDeuzln8.cjs +1 -0
  4. package/dist/api.cjs +1 -1
  5. package/dist/api.mjs +2 -2
  6. package/dist/auth.cjs +1 -1
  7. package/dist/auth.mjs +1 -1
  8. package/dist/bdo.cjs +1 -1
  9. package/dist/bdo.mjs +228 -472
  10. package/dist/{client-DnO2KKrw.cjs → client-D5k4SYuw.cjs} +1 -1
  11. package/dist/{client-iQTqFDNI.js → client-_ayziI1d.js} +33 -32
  12. package/dist/components/hooks/index.d.ts +9 -3
  13. package/dist/components/hooks/index.d.ts.map +1 -1
  14. package/dist/{workflow/components → components/hooks}/useActivityForm/createActivityItemProxy.d.ts +9 -5
  15. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -0
  16. package/dist/components/hooks/useActivityForm/createActivityResolver.d.ts +23 -0
  17. package/dist/components/hooks/useActivityForm/createActivityResolver.d.ts.map +1 -0
  18. package/dist/components/hooks/useActivityForm/index.d.ts.map +1 -0
  19. package/dist/{workflow/components → components/hooks}/useActivityForm/types.d.ts +11 -7
  20. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -0
  21. package/dist/{workflow/components → components/hooks}/useActivityForm/useActivityForm.d.ts +2 -2
  22. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -0
  23. package/dist/components/hooks/useActivityTable/index.d.ts +4 -0
  24. package/dist/components/hooks/useActivityTable/index.d.ts.map +1 -0
  25. package/dist/components/hooks/useActivityTable/types.d.ts +36 -0
  26. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -0
  27. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +4 -0
  28. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -0
  29. package/dist/components/hooks/useBDOTable/index.d.ts +3 -0
  30. package/dist/components/hooks/useBDOTable/index.d.ts.map +1 -0
  31. package/dist/components/hooks/useBDOTable/types.d.ts +26 -0
  32. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -0
  33. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +3 -0
  34. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -0
  35. package/dist/components/hooks/useTable/index.d.ts +2 -2
  36. package/dist/components/hooks/useTable/index.d.ts.map +1 -1
  37. package/dist/components/hooks/useTable/types.d.ts +11 -10
  38. package/dist/components/hooks/useTable/types.d.ts.map +1 -1
  39. package/dist/components/hooks/useTable/useTable.d.ts +1 -1
  40. package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
  41. package/dist/createResolver-AIgUwoS6.cjs +1 -0
  42. package/dist/createResolver-ZHXQ7QMa.js +1078 -0
  43. package/dist/form.cjs +1 -1
  44. package/dist/form.mjs +252 -314
  45. package/dist/{metadata-DpfI3zRN.js → metadata-Cc1mBcLS.js} +1 -1
  46. package/dist/{metadata-DgLSJkF5.cjs → metadata-DWXQPDav.cjs} +1 -1
  47. package/dist/table.cjs +1 -1
  48. package/dist/table.d.ts +1 -0
  49. package/dist/table.d.ts.map +1 -1
  50. package/dist/table.mjs +16 -192
  51. package/dist/table.types.d.ts +2 -1
  52. package/dist/table.types.d.ts.map +1 -1
  53. package/dist/types/base-fields.d.ts +4 -4
  54. package/dist/types/base-fields.d.ts.map +1 -1
  55. package/dist/useTable-CeRklbdT.cjs +1 -0
  56. package/dist/useTable-DS0-WInw.js +203 -0
  57. package/dist/workflow/Activity.d.ts +9 -9
  58. package/dist/workflow/Activity.d.ts.map +1 -1
  59. package/dist/workflow/client.d.ts.map +1 -1
  60. package/dist/workflow/createFieldFromMeta.d.ts +29 -0
  61. package/dist/workflow/createFieldFromMeta.d.ts.map +1 -0
  62. package/dist/workflow/index.d.ts +1 -2
  63. package/dist/workflow/index.d.ts.map +1 -1
  64. package/dist/workflow/types.d.ts +12 -12
  65. package/dist/workflow/types.d.ts.map +1 -1
  66. package/dist/workflow.cjs +1 -1
  67. package/dist/workflow.d.ts +5 -2
  68. package/dist/workflow.d.ts.map +1 -1
  69. package/dist/workflow.mjs +716 -338
  70. package/dist/workflow.types.d.ts +1 -0
  71. package/dist/workflow.types.d.ts.map +1 -1
  72. package/docs/gaps.md +410 -0
  73. package/docs/useActivityTable.md +481 -0
  74. package/docs/useBDOTable.md +317 -0
  75. package/docs/workflow.md +143 -34
  76. package/package.json +1 -1
  77. package/sdk/bdo/fields/UserField.ts +1 -1
  78. package/sdk/components/hooks/index.ts +28 -5
  79. package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +400 -0
  80. package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +87 -0
  81. package/sdk/{workflow/components → components/hooks}/useActivityForm/types.ts +21 -8
  82. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +628 -0
  83. package/sdk/components/hooks/useActivityTable/index.ts +8 -0
  84. package/sdk/components/hooks/useActivityTable/types.ts +45 -0
  85. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +71 -0
  86. package/sdk/components/hooks/useBDOTable/index.ts +2 -0
  87. package/sdk/components/hooks/useBDOTable/types.ts +24 -0
  88. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +15 -0
  89. package/sdk/components/hooks/useTable/index.ts +3 -3
  90. package/sdk/components/hooks/useTable/types.ts +16 -12
  91. package/sdk/components/hooks/useTable/useTable.ts +56 -49
  92. package/sdk/table.ts +4 -1
  93. package/sdk/table.types.ts +7 -4
  94. package/sdk/types/base-fields.ts +4 -4
  95. package/sdk/workflow/Activity.ts +14 -13
  96. package/sdk/workflow/client.ts +21 -8
  97. package/sdk/workflow/createFieldFromMeta.ts +110 -0
  98. package/sdk/workflow/index.ts +1 -6
  99. package/sdk/workflow/types.ts +13 -12
  100. package/sdk/workflow.ts +11 -2
  101. package/sdk/workflow.types.ts +7 -0
  102. package/dist/BaseField-B6da88U7.js +0 -40
  103. package/dist/BaseField-Drp0-OxL.cjs +0 -1
  104. package/dist/error-handling-CAoD0Kwb.cjs +0 -1
  105. package/dist/error-handling-CrhTtD88.js +0 -14
  106. package/dist/index.esm-Cj63v5ny.js +0 -1014
  107. package/dist/index.esm-DuwT11sx.cjs +0 -1
  108. package/dist/workflow/components/useActivityForm/createActivityItemProxy.d.ts.map +0 -1
  109. package/dist/workflow/components/useActivityForm/createActivityResolver.d.ts +0 -22
  110. package/dist/workflow/components/useActivityForm/createActivityResolver.d.ts.map +0 -1
  111. package/dist/workflow/components/useActivityForm/index.d.ts.map +0 -1
  112. package/dist/workflow/components/useActivityForm/types.d.ts.map +0 -1
  113. package/dist/workflow/components/useActivityForm/useActivityForm.d.ts.map +0 -1
  114. package/docs/useTable.md +0 -369
  115. package/sdk/workflow/components/useActivityForm/createActivityItemProxy.ts +0 -130
  116. package/sdk/workflow/components/useActivityForm/createActivityResolver.ts +0 -61
  117. package/sdk/workflow/components/useActivityForm/useActivityForm.ts +0 -386
  118. /package/dist/{workflow/components → components/hooks}/useActivityForm/index.d.ts +0 -0
  119. /package/sdk/{workflow/components → components/hooks}/useActivityForm/index.ts +0 -0
package/dist/form.mjs CHANGED
@@ -1,83 +1,21 @@
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 === "")
13
- return { valid: !0, errors: [] };
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`);
19
- }
20
- return i.length > 0 ? { valid: !1, errors: i } : { valid: !0, errors: [] };
21
- }
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] = {
40
- type: "validate",
41
- message: P.errors[0] || `${e} is invalid`
42
- };
43
- continue;
44
- }
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] = {
49
- type: "constraint",
50
- message: b.errors[0]
51
- };
52
- continue;
53
- }
54
- }
55
- if (o.hasMetadata()) {
56
- const b = o.validateFieldExpression(
57
- e,
58
- l,
59
- i
60
- );
61
- !b.valid && b.errors.length > 0 && (f[e] = {
62
- type: "validate",
63
- message: b.errors[0]
64
- });
65
- }
66
- }
67
- return Object.keys(f).length === 0 ? { values: i, errors: {} } : { values: {}, errors: f };
68
- };
69
- }
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);
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;
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);
78
16
  }
79
17
  return new Proxy({}, {
80
- get(I, e) {
18
+ get(F, e) {
81
19
  if (typeof e == "symbol")
82
20
  return;
83
21
  if (e === "_id")
@@ -87,172 +25,172 @@ function H(o, t) {
87
25
  if (e === "validate")
88
26
  return () => t.trigger();
89
27
  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) ?? {
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) ?? {
94
32
  _id: e,
95
33
  Name: e,
96
34
  Type: "String"
97
- }, P = (r == null ? void 0 : r.readOnly) ?? !1, b = () => {
35
+ }, z = (r == null ? void 0 : r.readOnly) ?? !1, C = () => {
98
36
  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 }));
37
+ let l = t.getValues(e);
38
+ if ("integerPart" in r && typeof l == "string" && l !== "") {
39
+ const o = Number(l);
40
+ isNaN(o) || (l = o, t.setValue(e, o, { shouldDirty: !1 }));
103
41
  }
104
- if (!r.required && (u == null || u === "" || Array.isArray(u) && u.length === 0))
42
+ if (!r.required && (l == null || l === "" || Array.isArray(l) && l.length === 0))
105
43
  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(
44
+ const i = r.validate(l);
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(
112
50
  e,
113
- u,
51
+ l,
114
52
  t.getValues()
115
53
  );
116
- if (!d.valid) return d;
54
+ if (!o.valid) return o;
117
55
  }
118
56
  return { valid: !0, errors: [] };
119
- }, M = (u) => {
120
- const s = t.getValues(e);
121
- return s ?? u;
57
+ }, P = (l) => {
58
+ const i = t.getValues(e);
59
+ return i ?? l;
122
60
  };
123
- if (!P) {
124
- const u = () => {
125
- const n = t.getValues(e);
126
- return l.Type === "File" ? n ?? [] : n;
127
- }, s = {
61
+ if (!z) {
62
+ const l = () => {
63
+ const a = t.getValues(e);
64
+ return h.Type === "File" ? a ?? [] : a;
65
+ }, i = {
128
66
  label: (r == null ? void 0 : r.label) ?? e,
129
67
  required: (r == null ? void 0 : r.required) ?? !1,
130
68
  readOnly: !1,
131
69
  defaultValue: r == null ? void 0 : r.defaultValue,
132
- meta: l,
133
- get: u,
134
- getOrDefault: M,
135
- set: (n) => {
136
- t.setValue(e, n, {
70
+ meta: h,
71
+ get: l,
72
+ getOrDefault: P,
73
+ set: (a) => {
74
+ t.setValue(e, a, {
137
75
  shouldDirty: !0,
138
76
  shouldTouch: !0,
139
77
  shouldValidate: !1
140
78
  // Let mode control validation timing
141
79
  });
142
80
  },
143
- validate: b
81
+ validate: C
144
82
  };
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;
83
+ if (h.Type === "Image" || h.Type === "File") {
84
+ const a = D, o = () => {
85
+ const n = t.getValues("_id");
86
+ if (!n) throw new Error("Save the record before attachment operations");
87
+ return n;
150
88
  };
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) }
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) }
155
93
  ]);
156
- await fetch(h.UploadUrl.URL, {
94
+ await fetch(f.UploadUrl.URL, {
157
95
  method: "PUT",
158
- headers: { "Content-Type": h.ContentType },
159
- body: a
96
+ headers: { "Content-Type": f.ContentType },
97
+ body: n
160
98
  });
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
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
168
106
  };
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, {
107
+ return t.setValue(e, c, { shouldDirty: !0 }), c;
108
+ }, i.deleteAttachment = async () => {
109
+ const n = t.getValues(e), s = o();
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 });
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);
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, {
186
124
  method: "PUT",
187
- headers: { "Content-Type": m[_].ContentType },
188
- body: V
125
+ headers: { "Content-Type": c[y].ContentType },
126
+ body: g
189
127
  }), {
190
- _id: m[_]._id,
191
- _name: m[_]._name,
192
- FileName: m[_].FileName,
193
- FileExtension: m[_].FileExtension,
194
- Size: m[_].Size,
195
- ContentType: m[_].ContentType
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
196
134
  }))
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(
135
+ ), w = t.getValues(e) ?? [];
136
+ return t.setValue(e, [...w, ...E], { shouldDirty: !0 }), E;
137
+ }, i.deleteAttachment = async (n) => {
138
+ const s = t.getValues(e) ?? [], f = o();
139
+ await _(a).deleteAttachment(f, e, n), t.setValue(
202
140
  e,
203
- c.filter((m) => m._id !== a),
141
+ s.filter((c) => c._id !== n),
204
142
  { shouldDirty: !0 }
205
143
  );
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);
144
+ }, i.getDownloadUrl = async (n, s) => {
145
+ const f = o();
146
+ return _(a).getDownloadUrl(f, e, n, s);
147
+ }, i.getDownloadUrls = async (n) => {
148
+ const s = o();
149
+ return _(a).getDownloadUrls(s, e, n);
212
150
  });
213
151
  }
214
- return g.set(e, s), s;
152
+ return m.set(e, i), i;
215
153
  }
216
- const y = () => {
217
- const u = t.getValues(e);
218
- return l.Type === "File" ? u ?? [] : u;
219
- }, U = {
154
+ const u = () => {
155
+ const l = t.getValues(e);
156
+ return h.Type === "File" ? l ?? [] : l;
157
+ }, O = {
220
158
  label: (r == null ? void 0 : r.label) ?? e,
221
159
  required: (r == null ? void 0 : r.required) ?? !1,
222
160
  readOnly: !0,
223
161
  defaultValue: r == null ? void 0 : r.defaultValue,
224
- meta: l,
225
- get: y,
226
- getOrDefault: M,
227
- validate: b
162
+ meta: h,
163
+ get: u,
164
+ getOrDefault: P,
165
+ validate: C
228
166
  };
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;
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;
234
172
  };
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);
173
+ h.Type === "Image" ? O.getDownloadUrl = async (a) => {
174
+ const o = t.getValues(e), n = i();
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) => {
178
+ const n = i();
179
+ return _(l).getDownloadUrl(n, e, a, o);
180
+ }, O.getDownloadUrls = async (a) => {
181
+ const o = i();
182
+ return _(l).getDownloadUrls(o, e, a);
245
183
  });
246
184
  }
247
- return g.set(e, U), U;
185
+ return m.set(e, O), O;
248
186
  },
249
- has(I, e) {
250
- return typeof e == "symbol" ? !1 : e === "_id" || e === "toJSON" || e === "validate" || e === "_hasDraft" ? !0 : e in i;
187
+ has(F, e) {
188
+ return typeof e == "symbol" ? !1 : e === "_id" || e === "toJSON" || e === "validate" || e === "_hasDraft" ? !0 : e in d;
251
189
  },
252
- ownKeys(I) {
253
- return [...Object.keys(i), "_id", "toJSON", "validate"];
190
+ ownKeys(F) {
191
+ return [...Object.keys(d), "_id", "toJSON", "validate"];
254
192
  },
255
- getOwnPropertyDescriptor(I, e) {
193
+ getOwnPropertyDescriptor(F, e) {
256
194
  if (typeof e != "symbol")
257
195
  return {
258
196
  configurable: !0,
@@ -261,175 +199,175 @@ function H(o, t) {
261
199
  }
262
200
  });
263
201
  }
264
- function k(o, t) {
265
- const i = o.meta.Type;
266
- if (typeof t == "string" && i === "Number")
202
+ function k(T, t) {
203
+ const d = T.meta.Type;
204
+ if (typeof t == "string" && d === "Number")
267
205
  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";
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";
272
210
  }
273
211
  return t;
274
212
  }
275
213
  }
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;
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;
282
220
  }
283
- function ae(o) {
221
+ function re(T) {
284
222
  const {
285
223
  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]
224
+ recordId: d,
225
+ operation: m,
226
+ defaultValues: D,
227
+ mode: V = "onBlur",
228
+ enableDraft: I = !1,
229
+ enableConstraintValidation: R,
230
+ enableExpressionValidation: F
231
+ } = T, e = m ?? (d ? "update" : "create"), r = j(
232
+ () => G(t, { enableConstraintValidation: R }),
233
+ [t, R]
296
234
  ), {
297
- data: l,
298
- isLoading: P,
299
- isFetching: b,
300
- error: M
301
- } = A({
302
- queryKey: ["form-record", t.meta._id, i],
235
+ data: h,
236
+ isLoading: z,
237
+ isFetching: C,
238
+ error: P
239
+ } = B({
240
+ queryKey: ["form-record", t.meta._id, d],
303
241
  queryFn: async () => {
304
- const D = await t.get(i);
305
- return X(t, D.toJSON());
242
+ const w = await t.get(d);
243
+ return X(t, w.toJSON());
306
244
  },
307
- enabled: e === "update" && !!i,
245
+ enabled: e === "update" && !!d,
308
246
  staleTime: 0
309
247
  }), {
310
- data: y,
311
- isLoading: U,
312
- error: u
313
- } = A({
248
+ data: u,
249
+ isLoading: O,
250
+ error: l
251
+ } = B({
314
252
  queryKey: ["form-draft", t.meta._id],
315
- queryFn: async () => T(t.meta._id).draftInteraction({}),
253
+ queryFn: async () => _(t.meta._id).draftInteraction({}),
316
254
  enabled: e === "create",
317
255
  staleTime: 1 / 0,
318
256
  gcTime: 0,
319
257
  retry: 1
320
- }), { data: s } = A({
258
+ }), { data: i } = B({
321
259
  queryKey: ["form-schema", t.meta._id],
322
- queryFn: () => W(t.meta._id),
260
+ queryFn: () => Q(t.meta._id),
323
261
  staleTime: 30 * 60 * 1e3,
324
262
  gcTime: 60 * 60 * 1e3,
325
- enabled: I !== !1
263
+ enabled: F !== !1
326
264
  });
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,
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,
332
270
  resolver: r,
333
- defaultValues: w
271
+ defaultValues: D
334
272
  // NOTE: Don't use `values` prop — it continuously syncs and overrides
335
273
  // setValue() calls for unregistered fields (Image/File attachments).
336
274
  // 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 } : _;
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;
351
289
  },
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)
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)
362
300
  try {
363
- await T(t.meta._id).draftInteraction({ _id: y._id, ...x });
301
+ await _(t.meta._id).draftInteraction({ _id: u._id, ...U });
364
302
  } catch {
365
303
  }
366
304
  }, 800));
367
305
  });
368
306
  return () => {
369
- D.unsubscribe(), m.current && clearTimeout(m.current);
307
+ w.unsubscribe(), c.current && clearTimeout(c.current);
370
308
  };
371
- }, [n, e, y, c, t]);
372
- const $ = j(
373
- (D, V) => n.handleSubmit(
374
- async (_, F) => {
309
+ }, [a, e, u, s, t]);
310
+ const E = L(
311
+ (w, g) => a.handleSubmit(
312
+ async (y, S) => {
375
313
  try {
376
- const v = {}, x = n.getValues();
314
+ const b = {}, U = a.getValues();
377
315
  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));
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));
382
320
  }
383
321
  else {
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);
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, $);
389
327
  }
390
328
  }
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);
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);
395
333
  }
396
334
  },
397
- (_, F) => {
398
- V == null || V(_, F);
335
+ (y, S) => {
336
+ g == null || g(y, S);
399
337
  }
400
338
  ),
401
- [n, t, e, i, c, y]
339
+ [a, t, e, d, s, u]
402
340
  );
403
341
  return {
404
- item: a,
342
+ item: n,
405
343
  bdo: t,
406
344
  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
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
428
366
  };
429
367
  }
430
368
  export {
431
369
  le as FormOperation,
432
370
  oe as InteractionMode,
433
- ce as ValidationMode,
434
- ae as useForm
371
+ ue as ValidationMode,
372
+ re as useForm
435
373
  };