@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.
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api.cjs +1 -1
- package/dist/api.mjs +2 -2
- package/dist/attachment-constants-B5jlqoKI.cjs +1 -0
- package/dist/attachment-constants-C2UHWxmp.js +63 -0
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo/core/types.d.ts +4 -0
- package/dist/bdo/core/types.d.ts.map +1 -1
- package/dist/bdo/fields/NumberField.d.ts.map +1 -1
- package/dist/bdo/fields/ReferenceField.d.ts +3 -2
- package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
- package/dist/bdo/fields/SelectField.d.ts +1 -1
- package/dist/bdo/fields/SelectField.d.ts.map +1 -1
- package/dist/bdo/fields/UserField.d.ts +5 -0
- package/dist/bdo/fields/UserField.d.ts.map +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +107 -153
- package/dist/client-DnO2KKrw.cjs +1 -0
- package/dist/{client-CMERmrC-.js → client-iQTqFDNI.js} +34 -30
- package/dist/components/hooks/useForm/createItemProxy.d.ts +4 -0
- package/dist/components/hooks/useForm/createItemProxy.d.ts.map +1 -1
- package/dist/components/hooks/useForm/createResolver.d.ts.map +1 -1
- package/dist/components/hooks/useForm/useForm.d.ts +1 -0
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +368 -203
- package/dist/{metadata-BfJtHz84.cjs → metadata-DgLSJkF5.cjs} +1 -1
- package/dist/{metadata-CwAo6a8e.js → metadata-DpfI3zRN.js} +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +1 -1
- package/dist/workflow/types.d.ts +3 -2
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.d.ts +0 -2
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.mjs +204 -274
- package/dist/workflow.types.d.ts +0 -1
- package/dist/workflow.types.d.ts.map +1 -1
- package/docs/api.md +45 -253
- package/docs/bdo.md +130 -711
- package/docs/useAuth.md +42 -104
- package/docs/useFilter.md +117 -1591
- package/docs/useForm.md +263 -861
- package/docs/useTable.md +255 -1096
- package/docs/workflow.md +10 -155
- package/package.json +1 -1
- package/sdk/api/client.ts +18 -4
- package/sdk/bdo/core/types.ts +1 -0
- package/sdk/bdo/fields/NumberField.ts +2 -1
- package/sdk/bdo/fields/ReferenceField.ts +4 -3
- package/sdk/bdo/fields/SelectField.ts +2 -2
- package/sdk/bdo/fields/UserField.ts +14 -0
- package/sdk/components/hooks/useForm/createItemProxy.ts +221 -4
- package/sdk/components/hooks/useForm/createResolver.ts +16 -1
- package/sdk/components/hooks/useForm/useForm.ts +151 -50
- package/sdk/workflow/types.ts +3 -2
- package/sdk/workflow.ts +0 -7
- package/sdk/workflow.types.ts +0 -7
- package/dist/client-BnVxSHAm.cjs +0 -1
- package/dist/workflow/components/useActivityTable/index.d.ts +0 -4
- package/dist/workflow/components/useActivityTable/index.d.ts.map +0 -1
- package/dist/workflow/components/useActivityTable/types.d.ts +0 -53
- package/dist/workflow/components/useActivityTable/types.d.ts.map +0 -1
- package/dist/workflow/components/useActivityTable/useActivityTable.d.ts +0 -4
- package/dist/workflow/components/useActivityTable/useActivityTable.d.ts.map +0 -1
- package/sdk/workflow/components/useActivityTable/index.ts +0 -8
- package/sdk/workflow/components/useActivityTable/types.ts +0 -67
- package/sdk/workflow/components/useActivityTable/useActivityTable.ts +0 -145
package/dist/form.mjs
CHANGED
|
@@ -1,270 +1,435 @@
|
|
|
1
|
-
import { F as
|
|
2
|
-
import { useMemo as
|
|
3
|
-
import { u as
|
|
4
|
-
import { useQuery as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
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
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
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
|
|
20
|
+
return i.length > 0 ? { valid: !1, errors: i } : { valid: !0, errors: [] };
|
|
19
21
|
}
|
|
20
|
-
function
|
|
21
|
-
return async (
|
|
22
|
-
var
|
|
23
|
-
const
|
|
24
|
-
for (const
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
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:
|
|
41
|
+
message: P.errors[0] || `${e} is invalid`
|
|
33
42
|
};
|
|
34
43
|
continue;
|
|
35
44
|
}
|
|
36
|
-
if ((
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
|
|
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:
|
|
50
|
+
message: b.errors[0]
|
|
42
51
|
};
|
|
43
52
|
continue;
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
if (o.hasMetadata()) {
|
|
56
|
+
const b = o.validateFieldExpression(
|
|
57
|
+
e,
|
|
58
|
+
l,
|
|
59
|
+
i
|
|
51
60
|
);
|
|
52
|
-
!
|
|
61
|
+
!b.valid && b.errors.length > 0 && (f[e] = {
|
|
53
62
|
type: "validate",
|
|
54
|
-
message:
|
|
63
|
+
message: b.errors[0]
|
|
55
64
|
});
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
|
-
return Object.keys(
|
|
67
|
+
return Object.keys(f).length === 0 ? { values: i, errors: {} } : { values: {}, errors: f };
|
|
59
68
|
};
|
|
60
69
|
}
|
|
61
|
-
function
|
|
62
|
-
const
|
|
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(
|
|
65
|
-
if (typeof
|
|
80
|
+
get(I, e) {
|
|
81
|
+
if (typeof e == "symbol")
|
|
66
82
|
return;
|
|
67
|
-
if (
|
|
68
|
-
return
|
|
69
|
-
if (
|
|
70
|
-
return () =>
|
|
71
|
-
if (
|
|
72
|
-
return () =>
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
},
|
|
80
|
-
if (!
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
114
|
+
t.getValues()
|
|
90
115
|
);
|
|
91
|
-
if (!
|
|
116
|
+
if (!d.valid) return d;
|
|
92
117
|
}
|
|
93
118
|
return { valid: !0, errors: [] };
|
|
94
|
-
},
|
|
95
|
-
const
|
|
96
|
-
return
|
|
119
|
+
}, M = (u) => {
|
|
120
|
+
const s = t.getValues(e);
|
|
121
|
+
return s ?? u;
|
|
97
122
|
};
|
|
98
|
-
if (!
|
|
99
|
-
const u = {
|
|
100
|
-
|
|
101
|
-
|
|
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:
|
|
104
|
-
meta:
|
|
105
|
-
get:
|
|
106
|
-
getOrDefault:
|
|
107
|
-
set: (
|
|
108
|
-
|
|
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:
|
|
143
|
+
validate: b
|
|
116
144
|
};
|
|
117
|
-
|
|
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
|
|
120
|
-
|
|
121
|
-
|
|
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:
|
|
124
|
-
meta:
|
|
125
|
-
get:
|
|
126
|
-
getOrDefault:
|
|
127
|
-
validate:
|
|
223
|
+
defaultValue: r == null ? void 0 : r.defaultValue,
|
|
224
|
+
meta: l,
|
|
225
|
+
get: y,
|
|
226
|
+
getOrDefault: M,
|
|
227
|
+
validate: b
|
|
128
228
|
};
|
|
129
|
-
|
|
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(
|
|
132
|
-
return typeof
|
|
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(
|
|
135
|
-
return [...Object.keys(
|
|
252
|
+
ownKeys(I) {
|
|
253
|
+
return [...Object.keys(i), "_id", "toJSON", "validate"];
|
|
136
254
|
},
|
|
137
|
-
getOwnPropertyDescriptor(
|
|
138
|
-
if (typeof
|
|
255
|
+
getOwnPropertyDescriptor(I, e) {
|
|
256
|
+
if (typeof e != "symbol")
|
|
139
257
|
return {
|
|
140
258
|
configurable: !0,
|
|
141
|
-
enumerable:
|
|
259
|
+
enumerable: e !== "toJSON" && e !== "validate" && e !== "_hasDraft"
|
|
142
260
|
};
|
|
143
261
|
}
|
|
144
262
|
});
|
|
145
263
|
}
|
|
146
|
-
function
|
|
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:
|
|
149
|
-
recordId:
|
|
150
|
-
operation:
|
|
151
|
-
defaultValues:
|
|
152
|
-
mode:
|
|
153
|
-
enableDraft:
|
|
154
|
-
enableConstraintValidation:
|
|
155
|
-
enableExpressionValidation:
|
|
156
|
-
} =
|
|
157
|
-
() =>
|
|
158
|
-
[
|
|
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:
|
|
161
|
-
isLoading:
|
|
162
|
-
isFetching:
|
|
163
|
-
error:
|
|
164
|
-
} =
|
|
165
|
-
queryKey: ["form-record",
|
|
166
|
-
queryFn: async () =>
|
|
167
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
177
|
-
enabled: S !== !1
|
|
325
|
+
enabled: I !== !1
|
|
178
326
|
});
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}, [
|
|
182
|
-
const
|
|
183
|
-
mode:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
[
|
|
200
|
-
),
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
|
206
|
-
if (
|
|
207
|
-
for (const [
|
|
208
|
-
|
|
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
|
|
211
|
-
for (const [
|
|
212
|
-
|
|
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
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
m == null || m(b, v);
|
|
397
|
+
(_, F) => {
|
|
398
|
+
V == null || V(_, F);
|
|
228
399
|
}
|
|
229
400
|
),
|
|
230
|
-
[
|
|
401
|
+
[n, t, e, i, c, y]
|
|
231
402
|
);
|
|
232
403
|
return {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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-
|
|
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;
|