@ram_28/kf-ai-sdk 2.0.4 → 2.0.6
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.mjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo/core/Item.d.ts.map +1 -1
- package/dist/bdo/core/types.d.ts +1 -0
- package/dist/bdo/core/types.d.ts.map +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +91 -86
- package/dist/components/hooks/useForm/createItemProxy.d.ts.map +1 -1
- package/dist/components/hooks/useForm/index.d.ts +1 -1
- package/dist/components/hooks/useForm/index.d.ts.map +1 -1
- package/dist/components/hooks/useForm/types.d.ts +6 -16
- package/dist/components/hooks/useForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useForm/useForm.d.ts +0 -1
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
- package/dist/components/hooks/useTable/types.d.ts +2 -2
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
- package/dist/{constants-BQrBcCON.js → constants-CYJih7y4.js} +2 -2
- package/dist/filter.mjs +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +158 -283
- package/dist/form.types.d.ts +1 -1
- package/dist/form.types.d.ts.map +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +65 -65
- package/dist/types/constants.d.ts +11 -11
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/utils/api/buildListOptions.d.ts +1 -1
- package/dist/utils/api/buildListOptions.d.ts.map +1 -1
- package/dist/workflow/Activity.d.ts +14 -5
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/ActivityInstance.d.ts +1 -1
- package/dist/workflow/ActivityInstance.d.ts.map +1 -1
- package/dist/workflow/client.d.ts +14 -4
- package/dist/workflow/client.d.ts.map +1 -1
- package/dist/workflow/components/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
- package/dist/workflow/types.d.ts +26 -9
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.mjs +296 -240
- package/docs/bdo.md +63 -0
- package/docs/useAuth.md +27 -0
- package/docs/useFilter.md +67 -0
- package/docs/useForm.md +59 -0
- package/docs/useTable.md +106 -13
- package/docs/workflow.md +93 -49
- package/package.json +2 -2
- package/sdk/bdo/core/Item.ts +8 -0
- package/sdk/bdo/core/types.ts +1 -0
- package/sdk/components/hooks/useForm/createItemProxy.ts +8 -0
- package/sdk/components/hooks/useForm/index.ts +0 -1
- package/sdk/components/hooks/useForm/types.ts +7 -18
- package/sdk/components/hooks/useForm/useForm.ts +23 -109
- package/sdk/components/hooks/useTable/types.ts +2 -2
- package/sdk/components/hooks/useTable/useTable.llm.txt +7 -7
- package/sdk/components/hooks/useTable/useTable.ts +9 -8
- package/sdk/form.types.ts +0 -1
- package/sdk/types/constants.ts +11 -11
- package/sdk/utils/api/buildListOptions.ts +2 -3
- package/sdk/workflow/Activity.ts +31 -10
- package/sdk/workflow/ActivityInstance.ts +1 -1
- package/sdk/workflow/client.ts +73 -10
- package/sdk/workflow/components/useActivityForm/createActivityItemProxy.ts +4 -0
- package/sdk/workflow/types.ts +22 -9
- package/dist/components/hooks/useForm/useDraftInteraction.d.ts +0 -26
- package/dist/components/hooks/useForm/useDraftInteraction.d.ts.map +0 -1
- package/sdk/components/hooks/useForm/useDraftInteraction.ts +0 -251
package/dist/form.mjs
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { F as
|
|
2
|
-
import {
|
|
3
|
-
import { u as
|
|
4
|
-
import { useQuery as
|
|
5
|
-
import { g as
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
1
|
+
import { F as H, I as U, V as W } from "./constants-CYJih7y4.js";
|
|
2
|
+
import { useMemo as q, useEffect as T, useCallback as M } 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-CJuFxytC.js";
|
|
6
|
+
function $(s, e) {
|
|
7
|
+
const r = [];
|
|
8
|
+
if (s.required && (e == null || e === ""))
|
|
9
|
+
return r.push(`${s.label} is required`), { valid: !1, errors: r };
|
|
10
10
|
if (e == null || e === "")
|
|
11
11
|
return { valid: !0, errors: [] };
|
|
12
|
-
if ("length" in
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const t =
|
|
16
|
-
t !== void 0 && (e.toString().split(".")[1] ?? "").length > t &&
|
|
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 o = Math.floor(Math.abs(e)), c = s.integerPart ?? 9;
|
|
14
|
+
o.toString().length > c && r.push(`${s.label} integer part must be at most ${c} 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`);
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return r.length > 0 ? { valid: !1, errors: r } : { valid: !0, errors: [] };
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
return async (
|
|
22
|
-
var
|
|
23
|
-
const t = {},
|
|
24
|
-
for (const
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
const
|
|
29
|
-
if (!
|
|
30
|
-
t[
|
|
20
|
+
function J(s, e) {
|
|
21
|
+
return async (r, o, c) => {
|
|
22
|
+
var b;
|
|
23
|
+
const t = {}, a = s.getFields(), y = (c == null ? void 0 : c.names) ?? Object.keys(a);
|
|
24
|
+
for (const n of y) {
|
|
25
|
+
if (n === "_id" || (b = a[n]) != null && b.readOnly) continue;
|
|
26
|
+
const d = a[n];
|
|
27
|
+
if (!d) continue;
|
|
28
|
+
const f = r[n], u = d.validate(f);
|
|
29
|
+
if (!u.valid && u.errors.length > 0) {
|
|
30
|
+
t[n] = {
|
|
31
31
|
type: "validate",
|
|
32
|
-
message:
|
|
32
|
+
message: u.errors[0] || `${n} is invalid`
|
|
33
33
|
};
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
36
|
if ((e == null ? void 0 : e.enableConstraintValidation) !== !1) {
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
t[
|
|
37
|
+
const l = $(d, f);
|
|
38
|
+
if (!l.valid && l.errors.length > 0) {
|
|
39
|
+
t[n] = {
|
|
40
40
|
type: "constraint",
|
|
41
|
-
message:
|
|
41
|
+
message: l.errors[0]
|
|
42
42
|
};
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (s.hasMetadata()) {
|
|
47
|
+
const l = s.validateFieldExpression(
|
|
48
|
+
n,
|
|
49
|
+
f,
|
|
50
|
+
r
|
|
51
51
|
);
|
|
52
|
-
!
|
|
52
|
+
!l.valid && l.errors.length > 0 && (t[n] = {
|
|
53
53
|
type: "validate",
|
|
54
|
-
message:
|
|
54
|
+
message: l.errors[0]
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
return Object.keys(t).length === 0 ? { values:
|
|
58
|
+
return Object.keys(t).length === 0 ? { values: r, errors: {} } : { values: {}, errors: t };
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
const
|
|
61
|
+
function I(s, e) {
|
|
62
|
+
const r = s.getFields(), o = /* @__PURE__ */ new Map();
|
|
63
63
|
return new Proxy({}, {
|
|
64
64
|
get(c, t) {
|
|
65
65
|
if (typeof t == "symbol")
|
|
@@ -70,36 +70,40 @@ function W(i, e) {
|
|
|
70
70
|
return () => e.getValues();
|
|
71
71
|
if (t === "validate")
|
|
72
72
|
return () => e.trigger();
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
75
|
-
const
|
|
73
|
+
if (o.has(t))
|
|
74
|
+
return o.get(t);
|
|
75
|
+
const a = r[t], y = (a == null ? void 0 : a.meta) ?? {
|
|
76
76
|
_id: t,
|
|
77
77
|
Name: t,
|
|
78
78
|
Type: "String"
|
|
79
|
-
},
|
|
80
|
-
if (!
|
|
81
|
-
const
|
|
79
|
+
}, b = (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
82
|
if (!l.valid) return l;
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
83
|
+
const R = $(a, u);
|
|
84
|
+
if (!R.valid) return R;
|
|
85
|
+
if (s.hasMetadata()) {
|
|
86
|
+
const g = s.validateFieldExpression(
|
|
87
87
|
t,
|
|
88
|
-
|
|
88
|
+
u,
|
|
89
89
|
e.getValues()
|
|
90
90
|
);
|
|
91
|
-
if (!
|
|
91
|
+
if (!g.valid) return g;
|
|
92
92
|
}
|
|
93
93
|
return { valid: !0, errors: [] };
|
|
94
|
+
}, d = (u) => {
|
|
95
|
+
const l = e.getValues(t);
|
|
96
|
+
return l ?? u;
|
|
94
97
|
};
|
|
95
|
-
if (!
|
|
96
|
-
const
|
|
97
|
-
label: (
|
|
98
|
-
required: (
|
|
98
|
+
if (!b) {
|
|
99
|
+
const u = {
|
|
100
|
+
label: (a == null ? void 0 : a.label) ?? t,
|
|
101
|
+
required: (a == null ? void 0 : a.required) ?? !1,
|
|
99
102
|
readOnly: !1,
|
|
100
|
-
defaultValue:
|
|
101
|
-
meta:
|
|
103
|
+
defaultValue: a == null ? void 0 : a.defaultValue,
|
|
104
|
+
meta: y,
|
|
102
105
|
get: () => e.getValues(t),
|
|
106
|
+
getOrDefault: d,
|
|
103
107
|
set: (l) => {
|
|
104
108
|
e.setValue(t, l, {
|
|
105
109
|
shouldDirty: !0,
|
|
@@ -108,26 +112,27 @@ function W(i, e) {
|
|
|
108
112
|
// Let mode control validation timing
|
|
109
113
|
});
|
|
110
114
|
},
|
|
111
|
-
validate:
|
|
115
|
+
validate: n
|
|
112
116
|
};
|
|
113
|
-
return
|
|
117
|
+
return o.set(t, u), u;
|
|
114
118
|
}
|
|
115
|
-
const
|
|
116
|
-
label: (
|
|
117
|
-
required: (
|
|
119
|
+
const f = {
|
|
120
|
+
label: (a == null ? void 0 : a.label) ?? t,
|
|
121
|
+
required: (a == null ? void 0 : a.required) ?? !1,
|
|
118
122
|
readOnly: !0,
|
|
119
|
-
defaultValue:
|
|
120
|
-
meta:
|
|
123
|
+
defaultValue: a == null ? void 0 : a.defaultValue,
|
|
124
|
+
meta: y,
|
|
121
125
|
get: () => e.getValues(t),
|
|
122
|
-
|
|
126
|
+
getOrDefault: d,
|
|
127
|
+
validate: n
|
|
123
128
|
};
|
|
124
|
-
return
|
|
129
|
+
return o.set(t, f), f;
|
|
125
130
|
},
|
|
126
131
|
has(c, t) {
|
|
127
|
-
return typeof t == "symbol" ? !1 : t === "_id" || t === "toJSON" || t === "validate" ? !0 : t in
|
|
132
|
+
return typeof t == "symbol" ? !1 : t === "_id" || t === "toJSON" || t === "validate" ? !0 : t in r;
|
|
128
133
|
},
|
|
129
134
|
ownKeys(c) {
|
|
130
|
-
return [...Object.keys(
|
|
135
|
+
return [...Object.keys(r), "_id", "toJSON", "validate"];
|
|
131
136
|
},
|
|
132
137
|
getOwnPropertyDescriptor(c, t) {
|
|
133
138
|
if (typeof t != "symbol")
|
|
@@ -138,258 +143,128 @@ function W(i, e) {
|
|
|
138
143
|
}
|
|
139
144
|
});
|
|
140
145
|
}
|
|
141
|
-
|
|
142
|
-
function Y(i) {
|
|
143
|
-
const { bdo: e, form: n, mode: g, fields: c, enabled: t } = i, [r, V] = E(void 0), [R, u] = E(!1), [I, s] = E(!1), [l, o] = E(null), v = N(0), q = N(!1), C = N(null), $ = N(null);
|
|
144
|
-
P(() => {
|
|
145
|
-
if (!t) return;
|
|
146
|
-
let d = !1;
|
|
147
|
-
u(!0);
|
|
148
|
-
const D = new AbortController();
|
|
149
|
-
return $.current = D, e.draftInteraction({}).then((h) => {
|
|
150
|
-
if (d || D.signal.aborted) return;
|
|
151
|
-
const M = h._id;
|
|
152
|
-
V(M), n.setValue("_id", M, { shouldDirty: !1 }), o(null);
|
|
153
|
-
}).catch((h) => {
|
|
154
|
-
d || D.signal.aborted || o(h instanceof Error ? h : new Error(String(h)));
|
|
155
|
-
}).finally(() => {
|
|
156
|
-
d || u(!1);
|
|
157
|
-
}), () => {
|
|
158
|
-
d = !0, D.abort();
|
|
159
|
-
};
|
|
160
|
-
}, [t, e, n]);
|
|
161
|
-
const O = j(async () => {
|
|
162
|
-
if (!t || !r || q.current) return;
|
|
163
|
-
const d = n.formState.dirtyFields, D = n.getValues(), h = {};
|
|
164
|
-
for (const [f, x] of Object.entries(d))
|
|
165
|
-
x && c[f] && !c[f].readOnly && (h[f] = D[f]);
|
|
166
|
-
if (Object.keys(h).length === 0) return;
|
|
167
|
-
const M = ++v.current;
|
|
168
|
-
s(!0);
|
|
169
|
-
try {
|
|
170
|
-
const f = await e.draftInteraction({
|
|
171
|
-
_id: r,
|
|
172
|
-
...h
|
|
173
|
-
});
|
|
174
|
-
if (M !== v.current) return;
|
|
175
|
-
q.current = !0;
|
|
176
|
-
try {
|
|
177
|
-
for (const [x, F] of Object.entries(f))
|
|
178
|
-
x !== "_id" && (d[x] || n.setValue(x, F, {
|
|
179
|
-
shouldDirty: !1,
|
|
180
|
-
shouldValidate: !1
|
|
181
|
-
}));
|
|
182
|
-
} finally {
|
|
183
|
-
setTimeout(() => {
|
|
184
|
-
q.current = !1;
|
|
185
|
-
}, 0);
|
|
186
|
-
}
|
|
187
|
-
o(null);
|
|
188
|
-
} catch (f) {
|
|
189
|
-
if (M !== v.current) return;
|
|
190
|
-
o(f instanceof Error ? f : new Error(String(f)));
|
|
191
|
-
} finally {
|
|
192
|
-
M === v.current && s(!1);
|
|
193
|
-
}
|
|
194
|
-
}, [t, r, n, c, e]), a = j(() => {
|
|
195
|
-
t && (g === "onChange" || g === "all" ? (C.current && clearTimeout(C.current), C.current = setTimeout(() => {
|
|
196
|
-
O();
|
|
197
|
-
}, X)) : O());
|
|
198
|
-
}, [t, g, O]), m = j(
|
|
199
|
-
async (d) => e.draft({
|
|
200
|
-
_id: r,
|
|
201
|
-
...d
|
|
202
|
-
}),
|
|
203
|
-
[e, r]
|
|
204
|
-
);
|
|
205
|
-
return P(() => () => {
|
|
206
|
-
var d;
|
|
207
|
-
C.current && clearTimeout(C.current), (d = $.current) == null || d.abort();
|
|
208
|
-
}, []), t ? {
|
|
209
|
-
draftId: r,
|
|
210
|
-
isInitializingDraft: R,
|
|
211
|
-
isInteracting: I,
|
|
212
|
-
interactionError: l,
|
|
213
|
-
triggerInteraction: a,
|
|
214
|
-
commitDraft: m
|
|
215
|
-
} : {
|
|
216
|
-
draftId: void 0,
|
|
217
|
-
isInitializingDraft: !1,
|
|
218
|
-
isInteracting: !1,
|
|
219
|
-
interactionError: null,
|
|
220
|
-
triggerInteraction: () => {
|
|
221
|
-
},
|
|
222
|
-
commitDraft: async () => {
|
|
223
|
-
throw new Error("Draft interaction is not enabled");
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
function rt(i) {
|
|
146
|
+
function z(s) {
|
|
228
147
|
const {
|
|
229
148
|
bdo: e,
|
|
230
|
-
recordId:
|
|
231
|
-
operation:
|
|
149
|
+
recordId: r,
|
|
150
|
+
operation: o,
|
|
232
151
|
defaultValues: c,
|
|
233
152
|
mode: t = "onBlur",
|
|
234
|
-
enableDraft:
|
|
235
|
-
enableConstraintValidation:
|
|
236
|
-
enableExpressionValidation:
|
|
237
|
-
} =
|
|
238
|
-
() =>
|
|
239
|
-
[e,
|
|
153
|
+
enableDraft: a = !1,
|
|
154
|
+
enableConstraintValidation: y,
|
|
155
|
+
enableExpressionValidation: b
|
|
156
|
+
} = s, n = o ?? (r ? "update" : "create"), d = q(
|
|
157
|
+
() => J(e, { enableConstraintValidation: y }),
|
|
158
|
+
[e, y]
|
|
240
159
|
), {
|
|
241
|
-
data:
|
|
242
|
-
isLoading:
|
|
243
|
-
isFetching:
|
|
244
|
-
error:
|
|
245
|
-
} =
|
|
246
|
-
queryKey: ["form-record", e.meta._id,
|
|
247
|
-
queryFn: async () => (await e.get(
|
|
248
|
-
enabled:
|
|
160
|
+
data: f,
|
|
161
|
+
isLoading: u,
|
|
162
|
+
isFetching: l,
|
|
163
|
+
error: R
|
|
164
|
+
} = w({
|
|
165
|
+
queryKey: ["form-record", e.meta._id, r],
|
|
166
|
+
queryFn: async () => (await e.get(r)).toJSON(),
|
|
167
|
+
enabled: n === "update" && !!r,
|
|
249
168
|
staleTime: 0
|
|
250
169
|
// Always fetch fresh data for forms
|
|
251
|
-
}), { data:
|
|
170
|
+
}), { data: g } = w({
|
|
252
171
|
queryKey: ["form-schema", e.meta._id],
|
|
253
|
-
queryFn: () =>
|
|
172
|
+
queryFn: () => C(e.meta._id),
|
|
254
173
|
staleTime: 30 * 60 * 1e3,
|
|
255
174
|
// Cache for 30 minutes
|
|
256
175
|
gcTime: 60 * 60 * 1e3,
|
|
257
176
|
// Keep in cache for 1 hour
|
|
258
|
-
enabled:
|
|
177
|
+
enabled: b !== !1
|
|
259
178
|
});
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}, [
|
|
263
|
-
const
|
|
179
|
+
T(() => {
|
|
180
|
+
g != null && g.BDOBlob && e.loadMetadata(g.BDOBlob);
|
|
181
|
+
}, [g, e]);
|
|
182
|
+
const i = j({
|
|
264
183
|
mode: t,
|
|
265
184
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
266
|
-
resolver:
|
|
185
|
+
resolver: d,
|
|
267
186
|
// Validation integrated here!
|
|
268
187
|
defaultValues: c,
|
|
269
188
|
// `values` prop reactively updates form when record loads
|
|
270
|
-
values:
|
|
271
|
-
}),
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
bdo: e,
|
|
280
|
-
form: a,
|
|
281
|
-
mode: t,
|
|
282
|
-
fields: m,
|
|
283
|
-
enabled: s && l === "create"
|
|
284
|
-
}), F = z(
|
|
285
|
-
() => W(e, a),
|
|
286
|
-
[e, a]
|
|
287
|
-
), A = j(
|
|
288
|
-
(_, w) => {
|
|
289
|
-
var T;
|
|
290
|
-
const y = a.register(_, w);
|
|
291
|
-
if ((T = m[_]) != null && T.readOnly)
|
|
292
|
-
return { ...y, disabled: !0 };
|
|
293
|
-
if (s && (t === "onBlur" || t === "onTouched" || t === "all")) {
|
|
294
|
-
const S = y.onBlur;
|
|
295
|
-
return {
|
|
296
|
-
...y,
|
|
297
|
-
onBlur: async (k) => {
|
|
298
|
-
await S(k), f();
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
return y;
|
|
189
|
+
values: n === "update" && f ? f : void 0
|
|
190
|
+
}), P = q(
|
|
191
|
+
() => I(e, i),
|
|
192
|
+
[e, i]
|
|
193
|
+
), h = e.getFields(), N = M(
|
|
194
|
+
(v, m) => {
|
|
195
|
+
var S;
|
|
196
|
+
const V = i.register(v, m);
|
|
197
|
+
return (S = h[v]) != null && S.readOnly ? { ...V, disabled: !0 } : V;
|
|
303
198
|
},
|
|
304
|
-
[
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
if (!s || t !== "onChange" && t !== "all") return;
|
|
308
|
-
const _ = a.watch((w, { type: y }) => {
|
|
309
|
-
y === "change" && f();
|
|
310
|
-
});
|
|
311
|
-
return () => _.unsubscribe();
|
|
312
|
-
}, [s, t, a, f]);
|
|
313
|
-
const Q = j(
|
|
314
|
-
(_, w) => a.handleSubmit(
|
|
199
|
+
[i, h]
|
|
200
|
+
), k = M(
|
|
201
|
+
(v, m) => i.handleSubmit(
|
|
315
202
|
// onValid - validation passed, make API call
|
|
316
|
-
async (
|
|
203
|
+
async (V, S) => {
|
|
317
204
|
try {
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
for (const [B, b] of Object.entries(y))
|
|
327
|
-
m[B] && !m[B].readOnly && (S[B] = b);
|
|
328
|
-
k = await e.create(
|
|
329
|
-
S
|
|
330
|
-
);
|
|
331
|
-
} else {
|
|
332
|
-
const B = a.formState.dirtyFields;
|
|
333
|
-
for (const [b, J] of Object.entries(y))
|
|
334
|
-
m[b] && !m[b].readOnly && B[b] && (S[b] = J);
|
|
335
|
-
k = await e.update(
|
|
336
|
-
n,
|
|
337
|
-
S
|
|
338
|
-
);
|
|
205
|
+
const O = {};
|
|
206
|
+
if (n === "create")
|
|
207
|
+
for (const [x, _] of Object.entries(V))
|
|
208
|
+
h[x] && !h[x].readOnly && (O[x] = _);
|
|
209
|
+
else {
|
|
210
|
+
const x = i.formState.dirtyFields;
|
|
211
|
+
for (const [_, B] of Object.entries(V))
|
|
212
|
+
h[_] && !h[_].readOnly && x[_] && (O[_] = B);
|
|
339
213
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
214
|
+
let D;
|
|
215
|
+
n === "create" ? D = await e.create(
|
|
216
|
+
O
|
|
217
|
+
) : D = await e.update(
|
|
218
|
+
r,
|
|
219
|
+
O
|
|
220
|
+
), v == null || v(D, S);
|
|
221
|
+
} catch (O) {
|
|
222
|
+
m == null || m(O, S);
|
|
343
223
|
}
|
|
344
224
|
},
|
|
345
225
|
// onInvalid - validation failed
|
|
346
|
-
(
|
|
347
|
-
|
|
226
|
+
(V, S) => {
|
|
227
|
+
m == null || m(V, S);
|
|
348
228
|
}
|
|
349
229
|
),
|
|
350
|
-
[
|
|
230
|
+
[i, e, n, r, h]
|
|
351
231
|
);
|
|
352
232
|
return {
|
|
353
233
|
// Item - synced with form
|
|
354
|
-
item:
|
|
234
|
+
item: P,
|
|
355
235
|
// BDO reference
|
|
356
236
|
bdo: e,
|
|
357
|
-
operation:
|
|
358
|
-
recordId:
|
|
237
|
+
operation: n,
|
|
238
|
+
recordId: r,
|
|
359
239
|
// Smart register (auto-disables readonly fields)
|
|
360
|
-
register:
|
|
240
|
+
register: N,
|
|
361
241
|
// Custom handleSubmit (handles API call + filters payload)
|
|
362
|
-
handleSubmit:
|
|
242
|
+
handleSubmit: k,
|
|
363
243
|
// RHF methods (spread, but handleSubmit is overridden above)
|
|
364
|
-
watch:
|
|
365
|
-
setValue:
|
|
366
|
-
getValues:
|
|
367
|
-
reset:
|
|
368
|
-
trigger:
|
|
369
|
-
control:
|
|
370
|
-
formState:
|
|
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,
|
|
371
251
|
// Flattened state for convenience
|
|
372
|
-
errors:
|
|
373
|
-
isDirty:
|
|
374
|
-
isValid:
|
|
375
|
-
isSubmitting:
|
|
376
|
-
isSubmitSuccessful:
|
|
377
|
-
dirtyFields:
|
|
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,
|
|
378
258
|
// Loading states
|
|
379
|
-
isLoading:
|
|
380
|
-
isFetching:
|
|
259
|
+
isLoading: u,
|
|
260
|
+
isFetching: l,
|
|
381
261
|
// Error
|
|
382
|
-
loadError:
|
|
383
|
-
// Draft / Interactive mode
|
|
384
|
-
draftId: d,
|
|
385
|
-
isInitializingDraft: D,
|
|
386
|
-
isInteracting: h,
|
|
387
|
-
interactionError: M
|
|
262
|
+
loadError: R
|
|
388
263
|
};
|
|
389
264
|
}
|
|
390
265
|
export {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
266
|
+
H as FormOperation,
|
|
267
|
+
U as InteractionMode,
|
|
268
|
+
W as ValidationMode,
|
|
269
|
+
z as useForm
|
|
395
270
|
};
|
package/dist/form.types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { UseFormOptionsType, UseFormReturnType, FormItemType, EditableFormFieldAccessorType, ReadonlyFormFieldAccessorType, FormRegisterType, HandleSubmitType, ExtractEditableType, ExtractReadonlyType, AllFieldsType,
|
|
1
|
+
export type { UseFormOptionsType, UseFormReturnType, FormItemType, EditableFormFieldAccessorType, ReadonlyFormFieldAccessorType, FormRegisterType, HandleSubmitType, ExtractEditableType, ExtractReadonlyType, AllFieldsType, } from "./components/hooks/useForm";
|
|
2
2
|
//# sourceMappingURL=form.types.d.ts.map
|
package/dist/form.types.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/table.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),L=require("@tanstack/react-query"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),L=require("@tanstack/react-query"),G=require("./client-DtPpfJc1.cjs"),C=require("./error-handling-CAoD0Kwb.cjs"),oe=require("./useFilter-Bg0jvIL6.cjs"),l=require("./constants-D0J69if5.cjs");function ne(o){var A,D,R,z,M,P,Q,w;const[a,h]=r.useState({query:"",debouncedQuery:"",field:null}),c=r.useRef(null),j=300,I=()=>{var t,n;const e=(t=o.initialState)==null?void 0:t.sort;if(e&&e.length>0){const H=e[0],x=Object.keys(H)[0],T=(n=H[x])==null?void 0:n.toUpperCase();return{field:x,direction:T==="ASC"||T==="DESC"?T:"ASC"}}return{field:null,direction:null}},[s,b]=r.useState(I),[i,u]=r.useState({pageNo:((D=(A=o.initialState)==null?void 0:A.pagination)==null?void 0:D.pageNo)||1,pageSize:((z=(R=o.initialState)==null?void 0:R.pagination)==null?void 0:z.pageSize)||10}),d=oe.useFilter({conditions:(P=(M=o.initialState)==null?void 0:M.filter)==null?void 0:P.conditions,operator:((w=(Q=o.initialState)==null?void 0:Q.filter)==null?void 0:w.operator)||"And"});r.useEffect(()=>{u(e=>({...e,pageNo:1}))},[d.payload]);const g=r.useMemo(()=>{const e={};let t=d.payload;if(a.debouncedQuery&&a.field){const n={LHSField:a.field,Operator:"Contains",RHSValue:a.debouncedQuery,RHSType:"Constant"};t?t.Operator==="And"?t={...t,Condition:[...t.Condition||[],n]}:t={Operator:"And",Condition:[t,n]}:t={Operator:"And",Condition:[n]}}return t&&(e.Filter=t),e},[a.debouncedQuery,a.field,d.payload]),E=r.useMemo(()=>{const e={...g};return s.field&&s.direction&&(e.Sort=[{[String(s.field)]:s.direction}]),e.Page=i.pageNo,e.PageSize=i.pageSize,e},[g,s,i]),{data:f,isLoading:K,isFetching:U,error:q,refetch:O}=L.useQuery({queryKey:["table",o.source,E],queryFn:async()=>{try{const e=await G.api(o.source).list(E);return o.onSuccess&&o.onSuccess(e.Data),e}catch(e){throw o.onError&&o.onError(C.toError(e)),e}},staleTime:0,gcTime:30*1e3}),{data:S,isLoading:_,isFetching:B,error:F,refetch:k}=L.useQuery({queryKey:["table-count",o.source,g],queryFn:async()=>{try{return await G.api(o.source).count(g)}catch(e){throw o.onError&&o.onError(C.toError(e)),e}},staleTime:0,gcTime:30*1e3}),V=r.useMemo(()=>(f==null?void 0:f.Data)||[],[f]),p=r.useMemo(()=>(S==null?void 0:S.Count)||0,[S]),y=r.useMemo(()=>Math.ceil(p/i.pageSize),[p,i.pageSize]),J=r.useCallback(e=>{b(t=>{if(t.field===e){if(t.direction==="ASC")return{field:e,direction:"DESC"};if(t.direction==="DESC")return{field:null,direction:null}}return{field:e,direction:"ASC"}})},[]),W=r.useCallback(()=>{b({field:null,direction:null})},[]),X=r.useCallback((e,t)=>{b({field:e,direction:t})},[]),Y=r.useCallback((e,t)=>{if(t.length>255){console.warn("Search query exceeds maximum length of 255 characters");return}h(n=>({...n,query:t,field:e})),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{h(n=>({...n,debouncedQuery:t})),u(n=>({...n,pageNo:1}))},j)},[]),Z=r.useCallback(()=>{c.current&&clearTimeout(c.current),h({query:"",debouncedQuery:"",field:null}),u(e=>({...e,pageNo:1}))},[]);r.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const m=i.pageNo<y,N=i.pageNo>1,$=r.useCallback(()=>{m&&u(e=>({...e,pageNo:e.pageNo+1}))},[m]),v=r.useCallback(()=>{N&&u(e=>({...e,pageNo:e.pageNo-1}))},[N]),ee=r.useCallback(e=>{const t=Math.max(1,Math.min(e,y));u(n=>({...n,pageNo:t}))},[y]),te=r.useCallback(e=>{u(t=>({...t,pageSize:e,pageNo:1}))},[]),re=r.useCallback(async()=>{const[e]=await Promise.all([O(),k()]);return e.data||{Data:[]}},[O,k]);return{rows:V,totalItems:p,isLoading:K||_,isFetching:U||B,error:q?C.toError(q):F?C.toError(F):null,search:{query:a.query,field:a.field,set:Y,clear:Z},sort:{field:s.field,direction:s.direction,toggle:J,clear:W,set:X},filter:d,pagination:{pageNo:i.pageNo,pageSize:i.pageSize,totalPages:y,totalItems:p,canGoNext:m,canGoPrevious:N,goToNext:$,goToPrevious:v,goToPage:ee,setPageSize:te},refetch:re}}exports.ConditionOperator=l.ConditionOperator;exports.GroupOperator=l.GroupOperator;exports.RHSType=l.RHSType;exports.SortDirection=l.SortDirection;exports.TableDefaults=l.Defaults;exports.useTable=ne;
|