@ram_28/kf-ai-sdk 2.0.1 → 2.0.3

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 (193) hide show
  1. package/README.md +36 -39
  2. package/dist/BaseField-B6da88U7.js +40 -0
  3. package/dist/BaseField-Drp0-OxL.cjs +1 -0
  4. package/dist/api/client.d.ts +7 -0
  5. package/dist/api/client.d.ts.map +1 -1
  6. package/dist/api/index.d.ts +1 -1
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/metadata.d.ts +26 -22
  9. package/dist/api/metadata.d.ts.map +1 -1
  10. package/dist/api.cjs +1 -1
  11. package/dist/api.mjs +3 -3
  12. package/dist/auth.cjs +1 -1
  13. package/dist/auth.mjs +2 -2
  14. package/dist/base-types.d.ts +1 -1
  15. package/dist/base-types.d.ts.map +1 -1
  16. package/dist/bdo/core/BaseBdo.d.ts +12 -20
  17. package/dist/bdo/core/BaseBdo.d.ts.map +1 -1
  18. package/dist/bdo/core/Item.d.ts +8 -44
  19. package/dist/bdo/core/Item.d.ts.map +1 -1
  20. package/dist/bdo/core/types.d.ts +124 -41
  21. package/dist/bdo/core/types.d.ts.map +1 -1
  22. package/dist/bdo/fields/ArrayField.d.ts +5 -4
  23. package/dist/bdo/fields/ArrayField.d.ts.map +1 -1
  24. package/dist/bdo/fields/BaseField.d.ts +14 -19
  25. package/dist/bdo/fields/BaseField.d.ts.map +1 -1
  26. package/dist/bdo/fields/BooleanField.d.ts +3 -4
  27. package/dist/bdo/fields/BooleanField.d.ts.map +1 -1
  28. package/dist/bdo/fields/DateField.d.ts +3 -4
  29. package/dist/bdo/fields/DateField.d.ts.map +1 -1
  30. package/dist/bdo/fields/DateTimeField.d.ts +5 -4
  31. package/dist/bdo/fields/DateTimeField.d.ts.map +1 -1
  32. package/dist/bdo/fields/FileField.d.ts +18 -0
  33. package/dist/bdo/fields/FileField.d.ts.map +1 -0
  34. package/dist/bdo/fields/NumberField.d.ts +6 -4
  35. package/dist/bdo/fields/NumberField.d.ts.map +1 -1
  36. package/dist/bdo/fields/ObjectField.d.ts +5 -4
  37. package/dist/bdo/fields/ObjectField.d.ts.map +1 -1
  38. package/dist/bdo/fields/ReferenceField.d.ts +13 -14
  39. package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
  40. package/dist/bdo/fields/SelectField.d.ts +9 -16
  41. package/dist/bdo/fields/SelectField.d.ts.map +1 -1
  42. package/dist/bdo/fields/StringField.d.ts +6 -4
  43. package/dist/bdo/fields/StringField.d.ts.map +1 -1
  44. package/dist/bdo/fields/TextAreaField.d.ts +1 -18
  45. package/dist/bdo/fields/TextAreaField.d.ts.map +1 -1
  46. package/dist/bdo/fields/TextField.d.ts +22 -0
  47. package/dist/bdo/fields/TextField.d.ts.map +1 -0
  48. package/dist/bdo/fields/UserField.d.ts +20 -0
  49. package/dist/bdo/fields/UserField.d.ts.map +1 -0
  50. package/dist/bdo/fields/index.d.ts +5 -2
  51. package/dist/bdo/fields/index.d.ts.map +1 -1
  52. package/dist/bdo/index.d.ts +2 -2
  53. package/dist/bdo/index.d.ts.map +1 -1
  54. package/dist/bdo.cjs +1 -1
  55. package/dist/bdo.d.ts +1 -5
  56. package/dist/bdo.d.ts.map +1 -1
  57. package/dist/bdo.mjs +286 -243
  58. package/dist/bdo.types.d.ts +2 -3
  59. package/dist/bdo.types.d.ts.map +1 -1
  60. package/dist/{client-BIkaIr2y.js → client-BULEEaCP.js} +84 -79
  61. package/dist/client-DtPpfJc1.cjs +1 -0
  62. package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
  63. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +1 -1
  64. package/dist/components/hooks/useForm/createResolver.d.ts +12 -2
  65. package/dist/components/hooks/useForm/createResolver.d.ts.map +1 -1
  66. package/dist/components/hooks/useForm/index.d.ts +1 -1
  67. package/dist/components/hooks/useForm/index.d.ts.map +1 -1
  68. package/dist/components/hooks/useForm/types.d.ts +77 -8
  69. package/dist/components/hooks/useForm/types.d.ts.map +1 -1
  70. package/dist/components/hooks/useForm/useDraftInteraction.d.ts +26 -0
  71. package/dist/components/hooks/useForm/useDraftInteraction.d.ts.map +1 -0
  72. package/dist/components/hooks/useForm/useForm.d.ts +2 -27
  73. package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
  74. package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
  75. package/dist/{constants-DaX7GLgl.js → constants-BQrBcCON.js} +37 -13
  76. package/dist/constants-D0J69if5.cjs +1 -0
  77. package/dist/error-handling-CAoD0Kwb.cjs +1 -0
  78. package/dist/error-handling-CrhTtD88.js +14 -0
  79. package/dist/filter.cjs +1 -1
  80. package/dist/filter.mjs +2 -2
  81. package/dist/form.cjs +1 -1
  82. package/dist/form.d.ts +1 -1
  83. package/dist/form.d.ts.map +1 -1
  84. package/dist/form.mjs +333 -1142
  85. package/dist/form.types.d.ts +1 -1
  86. package/dist/form.types.d.ts.map +1 -1
  87. package/dist/index.d.ts +2 -1
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.esm-Cj63v5ny.js +1014 -0
  90. package/dist/index.esm-DuwT11sx.cjs +1 -0
  91. package/dist/{metadata-Bz8zJqC1.cjs → metadata-BJWukIqS.cjs} +1 -1
  92. package/dist/{metadata-VbQzyD2C.js → metadata-CJuFxytC.js} +1 -1
  93. package/dist/table.cjs +1 -1
  94. package/dist/table.mjs +116 -122
  95. package/dist/types/base-fields.d.ts +24 -59
  96. package/dist/types/base-fields.d.ts.map +1 -1
  97. package/dist/types/constants.d.ts +2 -2
  98. package/dist/types/constants.d.ts.map +1 -1
  99. package/dist/useFilter-Bg0jvIL6.cjs +1 -0
  100. package/dist/useFilter-DPNLKY3H.js +118 -0
  101. package/dist/utils/formatting.d.ts +10 -1
  102. package/dist/utils/formatting.d.ts.map +1 -1
  103. package/dist/workflow/Activity.d.ts +85 -0
  104. package/dist/workflow/Activity.d.ts.map +1 -0
  105. package/dist/workflow/ActivityInstance.d.ts +96 -0
  106. package/dist/workflow/ActivityInstance.d.ts.map +1 -0
  107. package/dist/workflow/client.d.ts +39 -0
  108. package/dist/workflow/client.d.ts.map +1 -0
  109. package/dist/workflow/components/useActivityForm/createActivityItemProxy.d.ts +16 -0
  110. package/dist/workflow/components/useActivityForm/createActivityItemProxy.d.ts.map +1 -0
  111. package/dist/workflow/components/useActivityForm/createActivityResolver.d.ts +22 -0
  112. package/dist/workflow/components/useActivityForm/createActivityResolver.d.ts.map +1 -0
  113. package/dist/workflow/components/useActivityForm/index.d.ts +3 -0
  114. package/dist/workflow/components/useActivityForm/index.d.ts.map +1 -0
  115. package/dist/workflow/components/useActivityForm/types.d.ts +80 -0
  116. package/dist/workflow/components/useActivityForm/types.d.ts.map +1 -0
  117. package/dist/workflow/components/useActivityForm/useActivityForm.d.ts +4 -0
  118. package/dist/workflow/components/useActivityForm/useActivityForm.d.ts.map +1 -0
  119. package/dist/workflow/index.d.ts +8 -0
  120. package/dist/workflow/index.d.ts.map +1 -0
  121. package/dist/workflow/types.d.ts +53 -0
  122. package/dist/workflow/types.d.ts.map +1 -0
  123. package/dist/workflow.cjs +1 -0
  124. package/dist/workflow.d.ts +8 -0
  125. package/dist/workflow.d.ts.map +1 -0
  126. package/dist/workflow.mjs +565 -0
  127. package/dist/workflow.types.cjs +1 -0
  128. package/dist/workflow.types.d.ts +2 -0
  129. package/dist/workflow.types.d.ts.map +1 -0
  130. package/dist/workflow.types.mjs +1 -0
  131. package/docs/api.md +140 -572
  132. package/docs/bdo.md +742 -0
  133. package/docs/useAuth.md +10 -4
  134. package/docs/useFilter.md +40 -40
  135. package/docs/useForm.md +91 -62
  136. package/docs/useTable.md +38 -38
  137. package/docs/workflow.md +703 -0
  138. package/package.json +21 -1
  139. package/sdk/api/client.ts +77 -57
  140. package/sdk/api/index.ts +1 -0
  141. package/sdk/api/metadata.ts +22 -20
  142. package/sdk/base-types.ts +5 -9
  143. package/sdk/bdo/core/BaseBdo.ts +23 -38
  144. package/sdk/bdo/core/Item.ts +34 -56
  145. package/sdk/bdo/core/types.ts +147 -45
  146. package/sdk/bdo/fields/ArrayField.ts +9 -5
  147. package/sdk/bdo/fields/BaseField.ts +19 -29
  148. package/sdk/bdo/fields/BooleanField.ts +4 -5
  149. package/sdk/bdo/fields/DateField.ts +4 -5
  150. package/sdk/bdo/fields/DateTimeField.ts +9 -5
  151. package/sdk/bdo/fields/FileField.ts +39 -0
  152. package/sdk/bdo/fields/NumberField.ts +8 -5
  153. package/sdk/bdo/fields/ObjectField.ts +9 -5
  154. package/sdk/bdo/fields/ReferenceField.ts +22 -28
  155. package/sdk/bdo/fields/SelectField.ts +13 -26
  156. package/sdk/bdo/fields/StringField.ts +10 -5
  157. package/sdk/bdo/fields/TextAreaField.ts +3 -32
  158. package/sdk/bdo/fields/TextField.ts +42 -0
  159. package/sdk/bdo/fields/UserField.ts +52 -0
  160. package/sdk/bdo/fields/index.ts +5 -2
  161. package/sdk/bdo/index.ts +19 -4
  162. package/sdk/bdo.ts +4 -31
  163. package/sdk/bdo.types.ts +26 -21
  164. package/sdk/components/hooks/useFilter/useFilter.ts +13 -30
  165. package/sdk/components/hooks/useForm/createItemProxy.ts +47 -11
  166. package/sdk/components/hooks/useForm/createResolver.ts +65 -6
  167. package/sdk/components/hooks/useForm/index.ts +4 -0
  168. package/sdk/components/hooks/useForm/types.ts +92 -9
  169. package/sdk/components/hooks/useForm/useDraftInteraction.ts +251 -0
  170. package/sdk/components/hooks/useForm/useForm.ts +132 -60
  171. package/sdk/components/hooks/useTable/useTable.ts +10 -2
  172. package/sdk/form.ts +1 -12
  173. package/sdk/form.types.ts +1 -0
  174. package/sdk/index.ts +9 -3
  175. package/sdk/types/base-fields.ts +28 -72
  176. package/sdk/types/constants.ts +2 -2
  177. package/sdk/utils/formatting.ts +13 -1
  178. package/sdk/workflow/Activity.ts +181 -0
  179. package/sdk/workflow/ActivityInstance.ts +339 -0
  180. package/sdk/workflow/client.ts +208 -0
  181. package/sdk/workflow/components/useActivityForm/createActivityItemProxy.ts +126 -0
  182. package/sdk/workflow/components/useActivityForm/createActivityResolver.ts +61 -0
  183. package/sdk/workflow/components/useActivityForm/index.ts +5 -0
  184. package/sdk/workflow/components/useActivityForm/types.ts +166 -0
  185. package/sdk/workflow/components/useActivityForm/useActivityForm.ts +386 -0
  186. package/sdk/workflow/index.ts +20 -0
  187. package/sdk/workflow/types.ts +84 -0
  188. package/sdk/workflow.ts +25 -0
  189. package/sdk/workflow.types.ts +11 -0
  190. package/dist/client-DxjRcEtN.cjs +0 -1
  191. package/dist/constants-C49b9Exc.cjs +0 -1
  192. package/dist/useFilter-DzpP_ag0.cjs +0 -1
  193. package/dist/useFilter-H5bgAZQF.js +0 -120
package/dist/form.mjs CHANGED
@@ -1,1199 +1,390 @@
1
- import j, { useMemo as Je, useEffect as xt, useCallback as Ke } from "react";
2
- import { useQuery as $e } from "@tanstack/react-query";
3
- import { g as wt } from "./metadata-VbQzyD2C.js";
4
- var he = (e) => e.type === "checkbox", le = (e) => e instanceof Date, W = (e) => e == null;
5
- const at = (e) => typeof e == "object";
6
- var O = (e) => !W(e) && !Array.isArray(e) && at(e) && !le(e), At = (e) => O(e) && e.target ? he(e.target) ? e.target.checked : e.target.value : e, Dt = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, St = (e, s) => e.has(Dt(s)), kt = (e) => {
7
- const s = e.constructor && e.constructor.prototype;
8
- return O(s) && s.hasOwnProperty("isPrototypeOf");
9
- }, Ee = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
10
- function L(e) {
11
- if (e instanceof Date)
12
- return new Date(e);
13
- const s = typeof FileList < "u" && e instanceof FileList;
14
- if (Ee && (e instanceof Blob || s))
15
- return e;
16
- const r = Array.isArray(e);
17
- if (!r && !(O(e) && kt(e)))
18
- return e;
19
- const a = r ? [] : Object.create(Object.getPrototypeOf(e));
20
- for (const u in e)
21
- Object.prototype.hasOwnProperty.call(e, u) && (a[u] = L(e[u]));
22
- return a;
23
- }
24
- var _e = (e) => /^\w*$/.test(e), k = (e) => e === void 0, Oe = (e) => Array.isArray(e) ? e.filter(Boolean) : [], Te = (e) => Oe(e.replace(/["|']|\]/g, "").split(/\.|\[/)), g = (e, s, r) => {
25
- if (!s || !O(e))
26
- return r;
27
- const a = (_e(s) ? [s] : Te(s)).reduce((u, l) => W(u) ? u : u[l], e);
28
- return k(a) || a === e ? k(e[s]) ? r : e[s] : a;
29
- }, p = (e) => typeof e == "boolean", X = (e) => typeof e == "function", S = (e, s, r) => {
30
- let a = -1;
31
- const u = _e(s) ? [s] : Te(s), l = u.length, d = l - 1;
32
- for (; ++a < l; ) {
33
- const f = u[a];
34
- let A = r;
35
- if (a !== d) {
36
- const C = e[f];
37
- A = O(C) || Array.isArray(C) ? C : isNaN(+u[a + 1]) ? {} : [];
38
- }
39
- if (f === "__proto__" || f === "constructor" || f === "prototype")
40
- return;
41
- e[f] = A, e = e[f];
42
- }
43
- };
44
- const ze = {
45
- BLUR: "blur",
46
- FOCUS_OUT: "focusout"
47
- }, Z = {
48
- onBlur: "onBlur",
49
- onChange: "onChange",
50
- onSubmit: "onSubmit",
51
- onTouched: "onTouched",
52
- all: "all"
53
- }, te = {
54
- max: "max",
55
- min: "min",
56
- maxLength: "maxLength",
57
- minLength: "minLength",
58
- pattern: "pattern",
59
- required: "required",
60
- validate: "validate"
61
- }, Et = j.createContext(null);
62
- Et.displayName = "HookFormContext";
63
- var Ot = (e, s, r, a = !0) => {
64
- const u = {
65
- defaultValues: s._defaultValues
66
- };
67
- for (const l in e)
68
- Object.defineProperty(u, l, {
69
- get: () => {
70
- const d = l;
71
- return s._proxyFormState[d] !== Z.all && (s._proxyFormState[d] = !a || Z.all), e[d];
72
- }
73
- });
74
- return u;
75
- };
76
- const Tt = typeof window < "u" ? j.useLayoutEffect : j.useEffect;
77
- var J = (e) => typeof e == "string", Lt = (e, s, r, a, u) => J(e) ? (a && s.watch.add(e), g(r, e, u)) : Array.isArray(e) ? e.map((l) => (a && s.watch.add(l), g(r, l))) : (a && (s.watchAll = !0), r), Se = (e) => W(e) || !at(e);
78
- function ie(e, s, r = /* @__PURE__ */ new WeakSet()) {
79
- if (Se(e) || Se(s))
80
- return Object.is(e, s);
81
- if (le(e) && le(s))
82
- return Object.is(e.getTime(), s.getTime());
83
- const a = Object.keys(e), u = Object.keys(s);
84
- if (a.length !== u.length)
85
- return !1;
86
- if (r.has(e) || r.has(s))
87
- return !0;
88
- r.add(e), r.add(s);
89
- for (const l of a) {
90
- const d = e[l];
91
- if (!u.includes(l))
92
- return !1;
93
- if (l !== "ref") {
94
- const f = s[l];
95
- if (le(d) && le(f) || O(d) && O(f) || Array.isArray(d) && Array.isArray(f) ? !ie(d, f, r) : !Object.is(d, f))
96
- return !1;
97
- }
98
- }
99
- return !0;
100
- }
101
- var Rt = (e, s, r, a, u) => s ? {
102
- ...r[e],
103
- types: {
104
- ...r[e] && r[e].types ? r[e].types : {},
105
- [a]: u || !0
106
- }
107
- } : {}, ye = (e) => Array.isArray(e) ? e : [e], Qe = () => {
108
- let e = [];
109
- return {
110
- get observers() {
111
- return e;
112
- },
113
- next: (u) => {
114
- for (const l of e)
115
- l.next && l.next(u);
116
- },
117
- subscribe: (u) => (e.push(u), {
118
- unsubscribe: () => {
119
- e = e.filter((l) => l !== u);
120
- }
121
- }),
122
- unsubscribe: () => {
123
- e = [];
124
- }
125
- };
126
- };
127
- function lt(e, s) {
128
- const r = {};
129
- for (const a in e)
130
- if (e.hasOwnProperty(a)) {
131
- const u = e[a], l = s[a];
132
- if (u && O(u) && l) {
133
- const d = lt(u, l);
134
- O(d) && (r[a] = d);
135
- } else e[a] && (r[a] = l);
136
- }
137
- return r;
138
- }
139
- var B = (e) => O(e) && !Object.keys(e).length, Le = (e) => e.type === "file", be = (e) => {
140
- if (!Ee)
141
- return !1;
142
- const s = e ? e.ownerDocument : 0;
143
- return e instanceof (s && s.defaultView ? s.defaultView.HTMLElement : HTMLElement);
144
- }, nt = (e) => e.type === "select-multiple", Re = (e) => e.type === "radio", Ct = (e) => Re(e) || he(e), De = (e) => be(e) && e.isConnected;
145
- function Mt(e, s) {
146
- const r = s.slice(0, -1).length;
147
- let a = 0;
148
- for (; a < r; )
149
- e = k(e) ? a++ : e[s[a++]];
150
- return e;
151
- }
152
- function Ut(e) {
153
- for (const s in e)
154
- if (e.hasOwnProperty(s) && !k(e[s]))
155
- return !1;
156
- return !0;
157
- }
158
- function E(e, s) {
159
- const r = Array.isArray(s) ? s : _e(s) ? [s] : Te(s), a = r.length === 1 ? e : Mt(e, r), u = r.length - 1, l = r[u];
160
- return a && delete a[l], u !== 0 && (O(a) && B(a) || Array.isArray(a) && Ut(a)) && E(e, r.slice(0, -1)), e;
161
- }
162
- var It = (e) => {
163
- for (const s in e)
164
- if (X(e[s]))
165
- return !0;
166
- return !1;
167
- };
168
- function ut(e) {
169
- return Array.isArray(e) || O(e) && !It(e);
170
- }
171
- function ke(e, s = {}) {
172
- for (const r in e) {
173
- const a = e[r];
174
- ut(a) ? (s[r] = Array.isArray(a) ? [] : {}, ke(a, s[r])) : k(a) || (s[r] = !0);
175
- }
176
- return s;
177
- }
178
- function ue(e, s, r) {
179
- r || (r = ke(s));
180
- for (const a in e) {
181
- const u = e[a];
182
- if (ut(u))
183
- k(s) || Se(r[a]) ? r[a] = ke(u, Array.isArray(u) ? [] : {}) : ue(u, W(s) ? {} : s[a], r[a]);
184
- else {
185
- const l = s[a];
186
- r[a] = !ie(u, l);
187
- }
188
- }
189
- return r;
190
- }
191
- const Ye = {
192
- value: !1,
193
- isValid: !1
194
- }, Xe = { value: !0, isValid: !0 };
195
- var ot = (e) => {
196
- if (Array.isArray(e)) {
197
- if (e.length > 1) {
198
- const s = e.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
199
- return { value: s, isValid: !!s.length };
200
- }
201
- return e[0].checked && !e[0].disabled ? (
202
- // @ts-expect-error expected to work in the browser
203
- e[0].attributes && !k(e[0].attributes.value) ? k(e[0].value) || e[0].value === "" ? Xe : { value: e[0].value, isValid: !0 } : Xe
204
- ) : Ye;
205
- }
206
- return Ye;
207
- }, dt = (e, { valueAsNumber: s, valueAsDate: r, setValueAs: a }) => k(e) ? e : s ? e === "" ? NaN : e && +e : r && J(e) ? new Date(e) : a ? a(e) : e;
208
- const Ze = {
209
- isValid: !1,
210
- value: null
211
- };
212
- var ft = (e) => Array.isArray(e) ? e.reduce((s, r) => r && r.checked && !r.disabled ? {
213
- isValid: !0,
214
- value: r.value
215
- } : s, Ze) : Ze;
216
- function Ge(e) {
217
- const s = e.ref;
218
- return Le(s) ? s.files : Re(s) ? ft(e.refs).value : nt(s) ? [...s.selectedOptions].map(({ value: r }) => r) : he(s) ? ot(e.refs).value : dt(k(s.value) ? e.ref.value : s.value, e);
219
- }
220
- var Nt = (e, s, r, a) => {
221
- const u = {};
222
- for (const l of e) {
223
- const d = g(s, l);
224
- d && S(u, l, d._f);
225
- }
226
- return {
227
- criteriaMode: r,
228
- names: [...e],
229
- fields: u,
230
- shouldUseNativeValidation: a
231
- };
232
- }, Ve = (e) => e instanceof RegExp, ce = (e) => k(e) ? e : Ve(e) ? e.source : O(e) ? Ve(e.value) ? e.value.source : e.value : e, pe = (e) => ({
233
- isOnSubmit: !e || e === Z.onSubmit,
234
- isOnBlur: e === Z.onBlur,
235
- isOnChange: e === Z.onChange,
236
- isOnAll: e === Z.all,
237
- isOnTouch: e === Z.onTouched
238
- });
239
- const et = "AsyncFunction";
240
- var Bt = (e) => !!e && !!e.validate && !!(X(e.validate) && e.validate.constructor.name === et || O(e.validate) && Object.values(e.validate).find((s) => s.constructor.name === et)), Pt = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), tt = (e, s, r) => !r && (s.watchAll || s.watch.has(e) || [...s.watch].some((a) => e.startsWith(a) && /^\.\w+/.test(e.slice(a.length))));
241
- const ge = (e, s, r, a) => {
242
- for (const u of r || Object.keys(e)) {
243
- const l = g(e, u);
244
- if (l) {
245
- const { _f: d, ...f } = l;
246
- if (d) {
247
- if (d.refs && d.refs[0] && s(d.refs[0], u) && !a)
248
- return !0;
249
- if (d.ref && s(d.ref, d.name) && !a)
250
- return !0;
251
- if (ge(f, s))
252
- break;
253
- } else if (O(f) && ge(f, s))
254
- break;
255
- }
256
- }
257
- };
258
- function rt(e, s, r) {
259
- const a = g(e, r);
260
- if (a || _e(r))
261
- return {
262
- error: a,
263
- name: r
264
- };
265
- const u = r.split(".");
266
- for (; u.length; ) {
267
- const l = u.join("."), d = g(s, l), f = g(e, l);
268
- if (d && !Array.isArray(d) && r !== l)
269
- return { name: r };
270
- if (f && f.type)
271
- return {
272
- name: l,
273
- error: f
274
- };
275
- if (f && f.root && f.root.type)
276
- return {
277
- name: `${l}.root`,
278
- error: f.root
279
- };
280
- u.pop();
1
+ import { F as it, I as st, V as lt } from "./constants-BQrBcCON.js";
2
+ import { useState as E, useRef as N, useEffect as P, useCallback as j, useMemo as z } from "react";
3
+ import { u as U } from "./index.esm-Cj63v5ny.js";
4
+ import { useQuery as K } from "@tanstack/react-query";
5
+ import { g as G } from "./metadata-CJuFxytC.js";
6
+ function L(i, e) {
7
+ const n = [];
8
+ if (i.required && (e == null || e === ""))
9
+ return n.push(`${i.label} is required`), { valid: !1, errors: n };
10
+ if (e == null || e === "")
11
+ return { valid: !0, errors: [] };
12
+ if ("length" in i && typeof i.length == "number" && typeof e == "string" && e.length > i.length && n.push(`${i.label} must be at most ${i.length} characters`), "integerPart" in i && typeof e == "number") {
13
+ const g = Math.floor(Math.abs(e)), c = i.integerPart ?? 9;
14
+ g.toString().length > c && n.push(`${i.label} integer part must be at most ${c} digits`);
15
+ const t = i.fractionPart;
16
+ t !== void 0 && (e.toString().split(".")[1] ?? "").length > t && n.push(`${i.label} can have at most ${t} decimal places`);
281
17
  }
282
- return {
283
- name: r
284
- };
18
+ return n.length > 0 ? { valid: !1, errors: n } : { valid: !0, errors: [] };
285
19
  }
286
- var qt = (e, s, r, a) => {
287
- r(e);
288
- const { name: u, ...l } = e;
289
- return B(l) || Object.keys(l).length >= Object.keys(s).length || Object.keys(l).find((d) => s[d] === (!a || Z.all));
290
- }, Wt = (e, s, r) => !e || !s || e === s || ye(e).some((a) => a && (r ? a === s : a.startsWith(s) || s.startsWith(a))), Ht = (e, s, r, a, u) => u.isOnAll ? !1 : !r && u.isOnTouch ? !(s || e) : (r ? a.isOnBlur : u.isOnBlur) ? !e : (r ? a.isOnChange : u.isOnChange) ? e : !0, jt = (e, s) => !Oe(g(e, s)).length && E(e, s), Jt = (e, s, r) => {
291
- const a = ye(g(e, r));
292
- return S(a, "root", s[r]), S(e, r, a), e;
293
- };
294
- function st(e, s, r = "validate") {
295
- if (J(e) || Array.isArray(e) && e.every(J) || p(e) && !e)
296
- return {
297
- type: r,
298
- message: J(e) ? e : "",
299
- ref: s
300
- };
301
- }
302
- var ne = (e) => O(e) && !Ve(e) ? e : {
303
- value: e,
304
- message: ""
305
- }, it = async (e, s, r, a, u, l) => {
306
- const { ref: d, refs: f, required: A, maxLength: C, minLength: K, min: _, max: F, pattern: h, validate: $, name: M, valueAsNumber: z, mount: P } = e._f, b = g(r, M);
307
- if (!P || s.has(M))
308
- return {};
309
- const R = f ? f[0] : d, U = (V) => {
310
- u && R.reportValidity && (R.setCustomValidity(p(V) ? "" : V || ""), R.reportValidity());
311
- }, D = {}, re = Re(d), G = he(d), Q = re || G, ee = (z || Le(d)) && k(d.value) && k(b) || be(d) && d.value === "" || b === "" || Array.isArray(b) && !b.length, q = Rt.bind(null, M, a, D), ve = (V, m, T, I = te.maxLength, Y = te.minLength) => {
312
- const H = V ? m : T;
313
- D[M] = {
314
- type: V ? I : Y,
315
- message: H,
316
- ref: d,
317
- ...q(V ? I : Y, H)
318
- };
319
- };
320
- if (l ? !Array.isArray(b) || !b.length : A && (!Q && (ee || W(b)) || p(b) && !b || G && !ot(f).isValid || re && !ft(f).isValid)) {
321
- const { value: V, message: m } = J(A) ? { value: !!A, message: A } : ne(A);
322
- if (V && (D[M] = {
323
- type: te.required,
324
- message: m,
325
- ref: R,
326
- ...q(te.required, m)
327
- }, !a))
328
- return U(m), D;
329
- }
330
- if (!ee && (!W(_) || !W(F))) {
331
- let V, m;
332
- const T = ne(F), I = ne(_);
333
- if (!W(b) && !isNaN(b)) {
334
- const Y = d.valueAsNumber || b && +b;
335
- W(T.value) || (V = Y > T.value), W(I.value) || (m = Y < I.value);
336
- } else {
337
- const Y = d.valueAsDate || new Date(b), H = (fe) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + fe), oe = d.type == "time", de = d.type == "week";
338
- J(T.value) && b && (V = oe ? H(b) > H(T.value) : de ? b > T.value : Y > new Date(T.value)), J(I.value) && b && (m = oe ? H(b) < H(I.value) : de ? b < I.value : Y < new Date(I.value));
339
- }
340
- if ((V || m) && (ve(!!V, T.message, I.message, te.max, te.min), !a))
341
- return U(D[M].message), D;
342
- }
343
- if ((C || K) && !ee && (J(b) || l && Array.isArray(b))) {
344
- const V = ne(C), m = ne(K), T = !W(V.value) && b.length > +V.value, I = !W(m.value) && b.length < +m.value;
345
- if ((T || I) && (ve(T, V.message, m.message), !a))
346
- return U(D[M].message), D;
347
- }
348
- if (h && !ee && J(b)) {
349
- const { value: V, message: m } = ne(h);
350
- if (Ve(V) && !b.match(V) && (D[M] = {
351
- type: te.pattern,
352
- message: m,
353
- ref: d,
354
- ...q(te.pattern, m)
355
- }, !a))
356
- return U(m), D;
357
- }
358
- if ($) {
359
- if (X($)) {
360
- const V = await $(b, r), m = st(V, R);
361
- if (m && (D[M] = {
362
- ...m,
363
- ...q(te.validate, m.message)
364
- }, !a))
365
- return U(m.message), D;
366
- } else if (O($)) {
367
- let V = {};
368
- for (const m in $) {
369
- if (!B(V) && !a)
370
- break;
371
- const T = st(await $[m](b, r), R, m);
372
- T && (V = {
373
- ...T,
374
- ...q(m, T.message)
375
- }, U(T.message), a && (D[M] = V));
376
- }
377
- if (!B(V) && (D[M] = {
378
- ref: R,
379
- ...V
380
- }, !a))
381
- return D;
382
- }
383
- }
384
- return U(!0), D;
385
- };
386
- const Kt = {
387
- mode: Z.onSubmit,
388
- reValidateMode: Z.onChange,
389
- shouldFocusError: !0
390
- };
391
- function $t(e = {}) {
392
- let s = {
393
- ...Kt,
394
- ...e
395
- }, r = {
396
- submitCount: 0,
397
- isDirty: !1,
398
- isReady: !1,
399
- isLoading: X(s.defaultValues),
400
- isValidating: !1,
401
- isSubmitted: !1,
402
- isSubmitting: !1,
403
- isSubmitSuccessful: !1,
404
- isValid: !1,
405
- touchedFields: {},
406
- dirtyFields: {},
407
- validatingFields: {},
408
- errors: s.errors || {},
409
- disabled: s.disabled || !1
410
- }, a = {}, u = O(s.defaultValues) || O(s.values) ? L(s.defaultValues || s.values) || {} : {}, l = s.shouldUnregister ? {} : L(u), d = {
411
- action: !1,
412
- mount: !1,
413
- watch: !1,
414
- keepIsValid: !1
415
- }, f = {
416
- mount: /* @__PURE__ */ new Set(),
417
- disabled: /* @__PURE__ */ new Set(),
418
- unMount: /* @__PURE__ */ new Set(),
419
- array: /* @__PURE__ */ new Set(),
420
- watch: /* @__PURE__ */ new Set()
421
- }, A, C = 0;
422
- const K = {
423
- isDirty: !1,
424
- dirtyFields: !1,
425
- validatingFields: !1,
426
- touchedFields: !1,
427
- isValidating: !1,
428
- isValid: !1,
429
- errors: !1
430
- }, _ = {
431
- ...K
432
- };
433
- let F = {
434
- ..._
435
- };
436
- const h = {
437
- array: Qe(),
438
- state: Qe()
439
- }, $ = s.criteriaMode === Z.all, M = (t) => (i) => {
440
- clearTimeout(C), C = setTimeout(t, i);
441
- }, z = async (t) => {
442
- if (!d.keepIsValid && !s.disabled && (_.isValid || F.isValid || t)) {
443
- let i;
444
- s.resolver ? (i = B((await Q()).errors), P()) : i = await q(a, !0), i !== r.isValid && h.state.next({
445
- isValid: i
446
- });
447
- }
448
- }, P = (t, i) => {
449
- !s.disabled && (_.isValidating || _.validatingFields || F.isValidating || F.validatingFields) && ((t || Array.from(f.mount)).forEach((n) => {
450
- n && (i ? S(r.validatingFields, n, i) : E(r.validatingFields, n));
451
- }), h.state.next({
452
- validatingFields: r.validatingFields,
453
- isValidating: !B(r.validatingFields)
454
- }));
455
- }, b = (t, i = [], n, y, c = !0, o = !0) => {
456
- if (y && n && !s.disabled) {
457
- if (d.action = !0, o && Array.isArray(g(a, t))) {
458
- const v = n(g(a, t), y.argA, y.argB);
459
- c && S(a, t, v);
460
- }
461
- if (o && Array.isArray(g(r.errors, t))) {
462
- const v = n(g(r.errors, t), y.argA, y.argB);
463
- c && S(r.errors, t, v), jt(r.errors, t);
464
- }
465
- if ((_.touchedFields || F.touchedFields) && o && Array.isArray(g(r.touchedFields, t))) {
466
- const v = n(g(r.touchedFields, t), y.argA, y.argB);
467
- c && S(r.touchedFields, t, v);
468
- }
469
- (_.dirtyFields || F.dirtyFields) && (r.dirtyFields = ue(u, l)), h.state.next({
470
- name: t,
471
- isDirty: V(t, i),
472
- dirtyFields: r.dirtyFields,
473
- errors: r.errors,
474
- isValid: r.isValid
475
- });
476
- } else
477
- S(l, t, i);
478
- }, R = (t, i) => {
479
- S(r.errors, t, i), h.state.next({
480
- errors: r.errors
481
- });
482
- }, U = (t) => {
483
- r.errors = t, h.state.next({
484
- errors: r.errors,
485
- isValid: !1
486
- });
487
- }, D = (t, i, n, y) => {
488
- const c = g(a, t);
489
- if (c) {
490
- const o = g(l, t, k(n) ? g(u, t) : n);
491
- k(o) || y && y.defaultChecked || i ? S(l, t, i ? o : Ge(c._f)) : I(t, o), d.mount && !d.action && z();
492
- }
493
- }, re = (t, i, n, y, c) => {
494
- let o = !1, v = !1;
495
- const x = {
496
- name: t
497
- };
498
- if (!s.disabled) {
499
- if (!n || y) {
500
- (_.isDirty || F.isDirty) && (v = r.isDirty, r.isDirty = x.isDirty = V(), o = v !== x.isDirty);
501
- const w = ie(g(u, t), i);
502
- v = !!g(r.dirtyFields, t), w ? E(r.dirtyFields, t) : S(r.dirtyFields, t, !0), x.dirtyFields = r.dirtyFields, o = o || (_.dirtyFields || F.dirtyFields) && v !== !w;
503
- }
504
- if (n) {
505
- const w = g(r.touchedFields, t);
506
- w || (S(r.touchedFields, t, n), x.touchedFields = r.touchedFields, o = o || (_.touchedFields || F.touchedFields) && w !== n);
507
- }
508
- o && c && h.state.next(x);
509
- }
510
- return o ? x : {};
511
- }, G = (t, i, n, y) => {
512
- const c = g(r.errors, t), o = (_.isValid || F.isValid) && p(i) && r.isValid !== i;
513
- if (s.delayError && n ? (A = M(() => R(t, n)), A(s.delayError)) : (clearTimeout(C), A = null, n ? S(r.errors, t, n) : E(r.errors, t)), (n ? !ie(c, n) : c) || !B(y) || o) {
514
- const v = {
515
- ...y,
516
- ...o && p(i) ? { isValid: i } : {},
517
- errors: r.errors,
518
- name: t
519
- };
520
- r = {
521
- ...r,
522
- ...v
523
- }, h.state.next(v);
524
- }
525
- }, Q = async (t) => (P(t, !0), await s.resolver(l, s.context, Nt(t || f.mount, a, s.criteriaMode, s.shouldUseNativeValidation))), ee = async (t) => {
526
- const { errors: i } = await Q(t);
527
- if (P(t), t)
528
- for (const n of t) {
529
- const y = g(i, n);
530
- y ? S(r.errors, n, y) : E(r.errors, n);
531
- }
532
- else
533
- r.errors = i;
534
- return i;
535
- }, q = async (t, i, n = {
536
- valid: !0
537
- }) => {
538
- for (const y in t) {
539
- const c = t[y];
540
- if (c) {
541
- const { _f: o, ...v } = c;
542
- if (o) {
543
- const x = f.array.has(o.name), w = c._f && Bt(c._f);
544
- w && _.validatingFields && P([o.name], !0);
545
- const N = await it(c, f.disabled, l, $, s.shouldUseNativeValidation && !i, x);
546
- if (w && _.validatingFields && P([o.name]), N[o.name] && (n.valid = !1, i || e.shouldUseNativeValidation))
547
- break;
548
- !i && (g(N, o.name) ? x ? Jt(r.errors, N, o.name) : S(r.errors, o.name, N[o.name]) : E(r.errors, o.name));
549
- }
550
- !B(v) && await q(v, i, n);
551
- }
552
- }
553
- return n.valid;
554
- }, ve = () => {
555
- for (const t of f.unMount) {
556
- const i = g(a, t);
557
- i && (i._f.refs ? i._f.refs.every((n) => !De(n)) : !De(i._f.ref)) && me(t);
558
- }
559
- f.unMount = /* @__PURE__ */ new Set();
560
- }, V = (t, i) => !s.disabled && (t && i && S(l, t, i), !ie(Ce(), u)), m = (t, i, n) => Lt(t, f, {
561
- ...d.mount ? l : k(i) ? u : J(t) ? { [t]: i } : i
562
- }, n, i), T = (t) => Oe(g(d.mount ? l : u, t, s.shouldUnregister ? g(u, t, []) : [])), I = (t, i, n = {}) => {
563
- const y = g(a, t);
564
- let c = i;
565
- if (y) {
566
- const o = y._f;
567
- o && (!o.disabled && S(l, t, dt(i, o)), c = be(o.ref) && W(i) ? "" : i, nt(o.ref) ? [...o.ref.options].forEach((v) => v.selected = c.includes(v.value)) : o.refs ? he(o.ref) ? o.refs.forEach((v) => {
568
- (!v.defaultChecked || !v.disabled) && (Array.isArray(c) ? v.checked = !!c.find((x) => x === v.value) : v.checked = c === v.value || !!c);
569
- }) : o.refs.forEach((v) => v.checked = v.value === c) : Le(o.ref) ? o.ref.value = "" : (o.ref.value = c, o.ref.type || h.state.next({
570
- name: t,
571
- values: L(l)
572
- })));
573
- }
574
- (n.shouldDirty || n.shouldTouch) && re(t, c, n.shouldTouch, n.shouldDirty, !0), n.shouldValidate && fe(t);
575
- }, Y = (t, i, n) => {
576
- for (const y in i) {
577
- if (!i.hasOwnProperty(y))
578
- return;
579
- const c = i[y], o = t + "." + y, v = g(a, o);
580
- (f.array.has(t) || O(c) || v && !v._f) && !le(c) ? Y(o, c, n) : I(o, c, n);
581
- }
582
- }, H = (t, i, n = {}) => {
583
- const y = g(a, t), c = f.array.has(t), o = L(i);
584
- S(l, t, o), c ? (h.array.next({
585
- name: t,
586
- values: L(l)
587
- }), (_.isDirty || _.dirtyFields || F.isDirty || F.dirtyFields) && n.shouldDirty && h.state.next({
588
- name: t,
589
- dirtyFields: ue(u, l),
590
- isDirty: V(t, o)
591
- })) : y && !y._f && !W(o) ? Y(t, o, n) : I(t, o, n), tt(t, f) ? h.state.next({
592
- ...r,
593
- name: t,
594
- values: L(l)
595
- }) : h.state.next({
596
- name: d.mount ? t : void 0,
597
- values: L(l)
598
- });
599
- }, oe = async (t) => {
600
- d.mount = !0;
601
- const i = t.target;
602
- let n = i.name, y = !0;
603
- const c = g(a, n), o = (w) => {
604
- y = Number.isNaN(w) || le(w) && isNaN(w.getTime()) || ie(w, g(l, n, w));
605
- }, v = pe(s.mode), x = pe(s.reValidateMode);
606
- if (c) {
607
- let w, N;
608
- const ae = i.type ? Ge(c._f) : At(t), se = t.type === ze.BLUR || t.type === ze.FOCUS_OUT, _t = !Pt(c._f) && !s.resolver && !g(r.errors, n) && !c._f.deps || Ht(se, g(r.touchedFields, n), r.isSubmitted, x, v), we = tt(n, f, se);
609
- S(l, n, ae), se ? (!i || !i.readOnly) && (c._f.onBlur && c._f.onBlur(t), A && A(0)) : c._f.onChange && c._f.onChange(t);
610
- const Ae = re(n, ae, se), mt = !B(Ae) || we;
611
- if (!se && h.state.next({
612
- name: n,
613
- type: t.type,
614
- values: L(l)
615
- }), _t)
616
- return (_.isValid || F.isValid) && (s.mode === "onBlur" ? se && z() : se || z()), mt && h.state.next({ name: n, ...we ? {} : Ae });
617
- if (!se && we && h.state.next({ ...r }), s.resolver) {
618
- const { errors: He } = await Q([n]);
619
- if (P([n]), o(ae), y) {
620
- const Ft = rt(r.errors, a, n), je = rt(He, a, Ft.name || n);
621
- w = je.error, n = je.name, N = B(He);
622
- }
623
- } else
624
- P([n], !0), w = (await it(c, f.disabled, l, $, s.shouldUseNativeValidation))[n], P([n]), o(ae), y && (w ? N = !1 : (_.isValid || F.isValid) && (N = await q(a, !0)));
625
- y && (c._f.deps && (!Array.isArray(c._f.deps) || c._f.deps.length > 0) && fe(c._f.deps), G(n, N, w, Ae));
626
- }
627
- }, de = (t, i) => {
628
- if (g(r.errors, i) && t.focus)
629
- return t.focus(), 1;
630
- }, fe = async (t, i = {}) => {
631
- let n, y;
632
- const c = ye(t);
633
- if (s.resolver) {
634
- const o = await ee(k(t) ? t : c);
635
- n = B(o), y = t ? !c.some((v) => g(o, v)) : n;
636
- } else t ? (y = (await Promise.all(c.map(async (o) => {
637
- const v = g(a, o);
638
- return await q(v && v._f ? { [o]: v } : v);
639
- }))).every(Boolean), !(!y && !r.isValid) && z()) : y = n = await q(a);
640
- return h.state.next({
641
- ...!J(t) || (_.isValid || F.isValid) && n !== r.isValid ? {} : { name: t },
642
- ...s.resolver || !t ? { isValid: n } : {},
643
- errors: r.errors
644
- }), i.shouldFocus && !y && ge(a, de, t ? c : f.mount), y;
645
- }, Ce = (t, i) => {
646
- let n = {
647
- ...d.mount ? l : u
648
- };
649
- return i && (n = lt(i.dirtyFields ? r.dirtyFields : r.touchedFields, n)), k(t) ? n : J(t) ? g(n, t) : t.map((y) => g(n, y));
650
- }, Me = (t, i) => ({
651
- invalid: !!g((i || r).errors, t),
652
- isDirty: !!g((i || r).dirtyFields, t),
653
- error: g((i || r).errors, t),
654
- isValidating: !!g(r.validatingFields, t),
655
- isTouched: !!g((i || r).touchedFields, t)
656
- }), ct = (t) => {
657
- t && ye(t).forEach((i) => E(r.errors, i)), h.state.next({
658
- errors: t ? r.errors : {}
659
- });
660
- }, Ue = (t, i, n) => {
661
- const y = (g(a, t, { _f: {} })._f || {}).ref, c = g(r.errors, t) || {}, { ref: o, message: v, type: x, ...w } = c;
662
- S(r.errors, t, {
663
- ...w,
664
- ...i,
665
- ref: y
666
- }), h.state.next({
667
- name: t,
668
- errors: r.errors,
669
- isValid: !1
670
- }), n && n.shouldFocus && y && y.focus && y.focus();
671
- }, yt = (t, i) => X(t) ? h.state.subscribe({
672
- next: (n) => "values" in n && t(m(void 0, i), n)
673
- }) : m(t, i, !0), Ie = (t) => h.state.subscribe({
674
- next: (i) => {
675
- Wt(t.name, i.name, t.exact) && qt(i, t.formState || _, Vt, t.reRenderRoot) && t.callback({
676
- values: { ...l },
677
- ...r,
678
- ...i,
679
- defaultValues: u
680
- });
681
- }
682
- }).unsubscribe, gt = (t) => (d.mount = !0, F = {
683
- ...F,
684
- ...t.formState
685
- }, Ie({
686
- ...t,
687
- formState: {
688
- ...K,
689
- ...t.formState
690
- }
691
- })), me = (t, i = {}) => {
692
- for (const n of t ? ye(t) : f.mount)
693
- f.mount.delete(n), f.array.delete(n), i.keepValue || (E(a, n), E(l, n)), !i.keepError && E(r.errors, n), !i.keepDirty && E(r.dirtyFields, n), !i.keepTouched && E(r.touchedFields, n), !i.keepIsValidating && E(r.validatingFields, n), !s.shouldUnregister && !i.keepDefaultValue && E(u, n);
694
- h.state.next({
695
- values: L(l)
696
- }), h.state.next({
697
- ...r,
698
- ...i.keepDirty ? { isDirty: V() } : {}
699
- }), !i.keepIsValid && z();
700
- }, Ne = ({ disabled: t, name: i }) => {
701
- (p(t) && d.mount || t || f.disabled.has(i)) && (t ? f.disabled.add(i) : f.disabled.delete(i));
702
- }, Fe = (t, i = {}) => {
703
- let n = g(a, t);
704
- const y = p(i.disabled) || p(s.disabled);
705
- return S(a, t, {
706
- ...n || {},
707
- _f: {
708
- ...n && n._f ? n._f : { ref: { name: t } },
709
- name: t,
710
- mount: !0,
711
- ...i
712
- }
713
- }), f.mount.add(t), n ? Ne({
714
- disabled: p(i.disabled) ? i.disabled : s.disabled,
715
- name: t
716
- }) : D(t, !0, i.value), {
717
- ...y ? { disabled: i.disabled || s.disabled } : {},
718
- ...s.progressive ? {
719
- required: !!i.required,
720
- min: ce(i.min),
721
- max: ce(i.max),
722
- minLength: ce(i.minLength),
723
- maxLength: ce(i.maxLength),
724
- pattern: ce(i.pattern)
725
- } : {},
726
- name: t,
727
- onChange: oe,
728
- onBlur: oe,
729
- ref: (c) => {
730
- if (c) {
731
- Fe(t, i), n = g(a, t);
732
- const o = k(c.value) && c.querySelectorAll && c.querySelectorAll("input,select,textarea")[0] || c, v = Ct(o), x = n._f.refs || [];
733
- if (v ? x.find((w) => w === o) : o === n._f.ref)
734
- return;
735
- S(a, t, {
736
- _f: {
737
- ...n._f,
738
- ...v ? {
739
- refs: [
740
- ...x.filter(De),
741
- o,
742
- ...Array.isArray(g(u, t)) ? [{}] : []
743
- ],
744
- ref: { type: o.type, name: t }
745
- } : { ref: o }
746
- }
747
- }), D(t, !1, void 0, o);
748
- } else
749
- n = g(a, t, {}), n._f && (n._f.mount = !1), (s.shouldUnregister || i.shouldUnregister) && !(St(f.array, t) && d.action) && f.unMount.add(t);
750
- }
751
- };
752
- }, xe = () => s.shouldFocusError && ge(a, de, f.mount), ht = (t) => {
753
- p(t) && (h.state.next({ disabled: t }), ge(a, (i, n) => {
754
- const y = g(a, n);
755
- y && (i.disabled = y._f.disabled || t, Array.isArray(y._f.refs) && y._f.refs.forEach((c) => {
756
- c.disabled = y._f.disabled || t;
757
- }));
758
- }, 0, !1));
759
- }, Be = (t, i) => async (n) => {
760
- let y;
761
- n && (n.preventDefault && n.preventDefault(), n.persist && n.persist());
762
- let c = L(l);
763
- if (h.state.next({
764
- isSubmitting: !0
765
- }), s.resolver) {
766
- const { errors: o, values: v } = await Q();
767
- P(), r.errors = o, c = L(v);
768
- } else
769
- await q(a);
770
- if (f.disabled.size)
771
- for (const o of f.disabled)
772
- E(c, o);
773
- if (E(r.errors, "root"), B(r.errors)) {
774
- h.state.next({
775
- errors: {}
776
- });
777
- try {
778
- await t(c, n);
779
- } catch (o) {
780
- y = o;
781
- }
782
- } else
783
- i && await i({ ...r.errors }, n), xe(), setTimeout(xe);
784
- if (h.state.next({
785
- isSubmitted: !0,
786
- isSubmitting: !1,
787
- isSubmitSuccessful: B(r.errors) && !y,
788
- submitCount: r.submitCount + 1,
789
- errors: r.errors
790
- }), y)
791
- throw y;
792
- }, vt = (t, i = {}) => {
793
- g(a, t) && (k(i.defaultValue) ? H(t, L(g(u, t))) : (H(t, i.defaultValue), S(u, t, L(i.defaultValue))), i.keepTouched || E(r.touchedFields, t), i.keepDirty || (E(r.dirtyFields, t), r.isDirty = i.defaultValue ? V(t, L(g(u, t))) : V()), i.keepError || (E(r.errors, t), _.isValid && z()), h.state.next({ ...r }));
794
- }, Pe = (t, i = {}) => {
795
- const n = t ? L(t) : u, y = L(n), c = B(t), o = c ? u : y;
796
- if (i.keepDefaultValues || (u = n), !i.keepValues) {
797
- if (i.keepDirtyValues) {
798
- const v = /* @__PURE__ */ new Set([
799
- ...f.mount,
800
- ...Object.keys(ue(u, l))
801
- ]);
802
- for (const x of Array.from(v)) {
803
- const w = g(r.dirtyFields, x), N = g(l, x), ae = g(o, x);
804
- w && !k(N) ? S(o, x, N) : !w && !k(ae) && H(x, ae);
805
- }
806
- } else {
807
- if (Ee && k(t))
808
- for (const v of f.mount) {
809
- const x = g(a, v);
810
- if (x && x._f) {
811
- const w = Array.isArray(x._f.refs) ? x._f.refs[0] : x._f.ref;
812
- if (be(w)) {
813
- const N = w.closest("form");
814
- if (N) {
815
- N.reset();
816
- break;
817
- }
818
- }
819
- }
820
- }
821
- if (i.keepFieldsRef)
822
- for (const v of f.mount)
823
- H(v, g(o, v));
824
- else
825
- a = {};
826
- }
827
- l = s.shouldUnregister ? i.keepDefaultValues ? L(u) : {} : L(o), h.array.next({
828
- values: { ...o }
829
- }), h.state.next({
830
- values: { ...o }
831
- });
832
- }
833
- f = {
834
- mount: i.keepDirtyValues ? f.mount : /* @__PURE__ */ new Set(),
835
- unMount: /* @__PURE__ */ new Set(),
836
- array: /* @__PURE__ */ new Set(),
837
- disabled: /* @__PURE__ */ new Set(),
838
- watch: /* @__PURE__ */ new Set(),
839
- watchAll: !1,
840
- focus: ""
841
- }, d.mount = !_.isValid || !!i.keepIsValid || !!i.keepDirtyValues || !s.shouldUnregister && !B(o), d.watch = !!s.shouldUnregister, d.keepIsValid = !!i.keepIsValid, d.action = !1, i.keepErrors || (r.errors = {}), h.state.next({
842
- submitCount: i.keepSubmitCount ? r.submitCount : 0,
843
- isDirty: c ? !1 : i.keepDirty ? r.isDirty : !!(i.keepDefaultValues && !ie(t, u)),
844
- isSubmitted: i.keepIsSubmitted ? r.isSubmitted : !1,
845
- dirtyFields: c ? {} : i.keepDirtyValues ? i.keepDefaultValues && l ? ue(u, l) : r.dirtyFields : i.keepDefaultValues && t ? ue(u, t) : i.keepDirty ? r.dirtyFields : {},
846
- touchedFields: i.keepTouched ? r.touchedFields : {},
847
- errors: i.keepErrors ? r.errors : {},
848
- isSubmitSuccessful: i.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
849
- isSubmitting: !1,
850
- defaultValues: u
851
- });
852
- }, qe = (t, i) => Pe(X(t) ? t(l) : t, { ...s.resetOptions, ...i }), bt = (t, i = {}) => {
853
- const n = g(a, t), y = n && n._f;
854
- if (y) {
855
- const c = y.refs ? y.refs[0] : y.ref;
856
- c.focus && setTimeout(() => {
857
- c.focus(), i.shouldSelect && X(c.select) && c.select();
858
- });
859
- }
860
- }, Vt = (t) => {
861
- r = {
862
- ...r,
863
- ...t
864
- };
865
- }, We = {
866
- control: {
867
- register: Fe,
868
- unregister: me,
869
- getFieldState: Me,
870
- handleSubmit: Be,
871
- setError: Ue,
872
- _subscribe: Ie,
873
- _runSchema: Q,
874
- _updateIsValidating: P,
875
- _focusError: xe,
876
- _getWatch: m,
877
- _getDirty: V,
878
- _setValid: z,
879
- _setFieldArray: b,
880
- _setDisabledField: Ne,
881
- _setErrors: U,
882
- _getFieldArray: T,
883
- _reset: Pe,
884
- _resetDefaultValues: () => X(s.defaultValues) && s.defaultValues().then((t) => {
885
- qe(t, s.resetOptions), h.state.next({
886
- isLoading: !1
887
- });
888
- }),
889
- _removeUnmounted: ve,
890
- _disableForm: ht,
891
- _subjects: h,
892
- _proxyFormState: _,
893
- get _fields() {
894
- return a;
895
- },
896
- get _formValues() {
897
- return l;
898
- },
899
- get _state() {
900
- return d;
901
- },
902
- set _state(t) {
903
- d = t;
904
- },
905
- get _defaultValues() {
906
- return u;
907
- },
908
- get _names() {
909
- return f;
910
- },
911
- set _names(t) {
912
- f = t;
913
- },
914
- get _formState() {
915
- return r;
916
- },
917
- get _options() {
918
- return s;
919
- },
920
- set _options(t) {
921
- s = {
922
- ...s,
923
- ...t
924
- };
925
- }
926
- },
927
- subscribe: gt,
928
- trigger: fe,
929
- register: Fe,
930
- handleSubmit: Be,
931
- watch: yt,
932
- setValue: H,
933
- getValues: Ce,
934
- reset: qe,
935
- resetField: vt,
936
- clearErrors: ct,
937
- unregister: me,
938
- setError: Ue,
939
- setFocus: bt,
940
- getFieldState: Me
941
- };
942
- return {
943
- ...We,
944
- formControl: We
945
- };
946
- }
947
- function zt(e = {}) {
948
- const s = j.useRef(void 0), r = j.useRef(void 0), [a, u] = j.useState({
949
- isDirty: !1,
950
- isValidating: !1,
951
- isLoading: X(e.defaultValues),
952
- isSubmitted: !1,
953
- isSubmitting: !1,
954
- isSubmitSuccessful: !1,
955
- isValid: !1,
956
- submitCount: 0,
957
- dirtyFields: {},
958
- touchedFields: {},
959
- validatingFields: {},
960
- errors: e.errors || {},
961
- disabled: e.disabled || !1,
962
- isReady: !1,
963
- defaultValues: X(e.defaultValues) ? void 0 : e.defaultValues
964
- });
965
- if (!s.current)
966
- if (e.formControl)
967
- s.current = {
968
- ...e.formControl,
969
- formState: a
970
- }, e.defaultValues && !X(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
971
- else {
972
- const { formControl: d, ...f } = $t(e);
973
- s.current = {
974
- ...f,
975
- formState: a
976
- };
977
- }
978
- const l = s.current.control;
979
- return l._options = e, Tt(() => {
980
- const d = l._subscribe({
981
- formState: l._proxyFormState,
982
- callback: () => u({ ...l._formState }),
983
- reRenderRoot: !0
984
- });
985
- return u((f) => ({
986
- ...f,
987
- isReady: !0
988
- })), l._formState.isReady = !0, d;
989
- }, [l]), j.useEffect(() => l._disableForm(e.disabled), [l, e.disabled]), j.useEffect(() => {
990
- e.mode && (l._options.mode = e.mode), e.reValidateMode && (l._options.reValidateMode = e.reValidateMode);
991
- }, [l, e.mode, e.reValidateMode]), j.useEffect(() => {
992
- e.errors && (l._setErrors(e.errors), l._focusError());
993
- }, [l, e.errors]), j.useEffect(() => {
994
- e.shouldUnregister && l._subjects.state.next({
995
- values: l._getWatch()
996
- });
997
- }, [l, e.shouldUnregister]), j.useEffect(() => {
998
- if (l._proxyFormState.isDirty) {
999
- const d = l._getDirty();
1000
- d !== a.isDirty && l._subjects.state.next({
1001
- isDirty: d
1002
- });
1003
- }
1004
- }, [l, a.isDirty]), j.useEffect(() => {
1005
- var d;
1006
- e.values && !ie(e.values, r.current) ? (l._reset(e.values, {
1007
- keepFieldsRef: !0,
1008
- ...l._options.resetOptions
1009
- }), !((d = l._options.resetOptions) === null || d === void 0) && d.keepIsValid || l._setValid(), r.current = e.values, u((f) => ({ ...f }))) : l._resetDefaultValues();
1010
- }, [l, e.values]), j.useEffect(() => {
1011
- l._state.mount || (l._setValid(), l._state.mount = !0), l._state.watch && (l._state.watch = !1, l._subjects.state.next({ ...l._formState })), l._removeUnmounted();
1012
- }), s.current.formState = Ot(a, l), s.current;
1013
- }
1014
- function Qt(e) {
1015
- return async (s, r, a) => {
1016
- var f;
1017
- const u = {}, l = e.getFields(), d = (a == null ? void 0 : a.names) ?? Object.keys(l);
1018
- for (const A of d) {
1019
- if (A === "_id" || !((f = l[A]) != null && f.meta.isEditable)) continue;
1020
- const C = l[A];
1021
- if (!C) continue;
1022
- const K = s[A], _ = C.validate(K);
1023
- if (!_.valid && _.errors.length > 0) {
1024
- u[A] = {
20
+ function H(i, e) {
21
+ return async (n, g, c) => {
22
+ var R;
23
+ const t = {}, r = i.getFields(), V = (c == null ? void 0 : c.names) ?? Object.keys(r);
24
+ for (const u of V) {
25
+ if (u === "_id" || (R = r[u]) != null && R.readOnly) continue;
26
+ const I = r[u];
27
+ if (!I) continue;
28
+ const s = n[u], l = I.validate(s);
29
+ if (!l.valid && l.errors.length > 0) {
30
+ t[u] = {
1025
31
  type: "validate",
1026
- message: _.errors[0] || `${A} is invalid`
32
+ message: l.errors[0] || `${u} is invalid`
1027
33
  };
1028
34
  continue;
1029
35
  }
1030
- if (e.hasMetadata()) {
1031
- const F = e.validateFieldExpression(
1032
- A,
1033
- K,
1034
- s
36
+ if ((e == null ? void 0 : e.enableConstraintValidation) !== !1) {
37
+ const o = L(I, s);
38
+ if (!o.valid && o.errors.length > 0) {
39
+ t[u] = {
40
+ type: "constraint",
41
+ message: o.errors[0]
42
+ };
43
+ continue;
44
+ }
45
+ }
46
+ if (i.hasMetadata()) {
47
+ const o = i.validateFieldExpression(
48
+ u,
49
+ s,
50
+ n
1035
51
  );
1036
- !F.valid && F.errors.length > 0 && (u[A] = {
52
+ !o.valid && o.errors.length > 0 && (t[u] = {
1037
53
  type: "validate",
1038
- message: F.errors[0]
54
+ message: o.errors[0]
1039
55
  });
1040
56
  }
1041
57
  }
1042
- return Object.keys(u).length === 0 ? { values: s, errors: {} } : { values: {}, errors: u };
58
+ return Object.keys(t).length === 0 ? { values: n, errors: {} } : { values: {}, errors: t };
1043
59
  };
1044
60
  }
1045
- function Yt(e, s) {
1046
- const r = e.getFields();
61
+ function W(i, e) {
62
+ const n = i.getFields(), g = /* @__PURE__ */ new Map();
1047
63
  return new Proxy({}, {
1048
- get(a, u) {
1049
- if (typeof u == "symbol")
64
+ get(c, t) {
65
+ if (typeof t == "symbol")
1050
66
  return;
1051
- if (u === "_id")
1052
- return s.getValues("_id");
1053
- if (u === "toJSON")
1054
- return () => s.getValues();
1055
- if (u === "validate")
1056
- return () => s.trigger();
1057
- const l = r[u], d = (l == null ? void 0 : l.meta) ?? {
1058
- id: u,
1059
- label: u,
1060
- isEditable: !0
1061
- }, f = d.isEditable, A = () => l ? l.validate(s.getValues(u)) : { valid: !0, errors: [] };
1062
- return f ? {
1063
- meta: d,
1064
- get: () => s.getValues(u),
1065
- set: (_) => {
1066
- s.setValue(u, _, {
1067
- shouldDirty: !0,
1068
- shouldTouch: !0,
1069
- shouldValidate: !1
1070
- // Let mode control validation timing
1071
- });
1072
- },
1073
- validate: A
1074
- } : {
1075
- meta: d,
1076
- get: () => s.getValues(u),
1077
- validate: A
67
+ if (t === "_id")
68
+ return e.getValues("_id");
69
+ if (t === "toJSON")
70
+ return () => e.getValues();
71
+ if (t === "validate")
72
+ return () => e.trigger();
73
+ if (g.has(t))
74
+ return g.get(t);
75
+ const r = n[t], V = (r == null ? void 0 : r.meta) ?? {
76
+ _id: t,
77
+ Name: t,
78
+ Type: "String"
79
+ }, R = (r == null ? void 0 : r.readOnly) ?? !1, u = () => {
80
+ if (!r) return { valid: !0, errors: [] };
81
+ const s = e.getValues(t), l = r.validate(s);
82
+ if (!l.valid) return l;
83
+ const o = L(r, s);
84
+ if (!o.valid) return o;
85
+ if (i.hasMetadata()) {
86
+ const v = i.validateFieldExpression(
87
+ t,
88
+ s,
89
+ e.getValues()
90
+ );
91
+ if (!v.valid) return v;
92
+ }
93
+ return { valid: !0, errors: [] };
94
+ };
95
+ if (!R) {
96
+ const s = {
97
+ label: (r == null ? void 0 : r.label) ?? t,
98
+ required: (r == null ? void 0 : r.required) ?? !1,
99
+ readOnly: !1,
100
+ defaultValue: r == null ? void 0 : r.defaultValue,
101
+ meta: V,
102
+ get: () => e.getValues(t),
103
+ set: (l) => {
104
+ e.setValue(t, l, {
105
+ shouldDirty: !0,
106
+ shouldTouch: !0,
107
+ shouldValidate: !1
108
+ // Let mode control validation timing
109
+ });
110
+ },
111
+ validate: u
112
+ };
113
+ return g.set(t, s), s;
114
+ }
115
+ const I = {
116
+ label: (r == null ? void 0 : r.label) ?? t,
117
+ required: (r == null ? void 0 : r.required) ?? !1,
118
+ readOnly: !0,
119
+ defaultValue: r == null ? void 0 : r.defaultValue,
120
+ meta: V,
121
+ get: () => e.getValues(t),
122
+ validate: u
1078
123
  };
124
+ return g.set(t, I), I;
1079
125
  },
1080
- has(a, u) {
1081
- return typeof u == "symbol" ? !1 : u === "_id" || u === "toJSON" || u === "validate" ? !0 : u in r;
126
+ has(c, t) {
127
+ return typeof t == "symbol" ? !1 : t === "_id" || t === "toJSON" || t === "validate" ? !0 : t in n;
1082
128
  },
1083
- ownKeys(a) {
1084
- return [...Object.keys(r), "_id", "toJSON", "validate"];
129
+ ownKeys(c) {
130
+ return [...Object.keys(n), "_id", "toJSON", "validate"];
1085
131
  },
1086
- getOwnPropertyDescriptor(a, u) {
1087
- if (typeof u != "symbol")
132
+ getOwnPropertyDescriptor(c, t) {
133
+ if (typeof t != "symbol")
1088
134
  return {
1089
135
  configurable: !0,
1090
- enumerable: u !== "toJSON" && u !== "validate"
136
+ enumerable: t !== "toJSON" && t !== "validate"
1091
137
  };
1092
138
  }
1093
139
  });
1094
140
  }
1095
- function er(e) {
141
+ const X = 300;
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) {
1096
228
  const {
1097
- bdo: s,
1098
- recordId: r,
1099
- operation: a,
1100
- defaultValues: u,
1101
- mode: l = "onBlur",
1102
- enableDraft: d = !1
1103
- } = e, f = a ?? (r ? "update" : "create"), A = Je(() => Qt(s), [s]), {
1104
- data: C,
1105
- isLoading: K,
1106
- error: _
1107
- } = $e({
1108
- queryKey: ["form-record", s.meta._id, r],
1109
- queryFn: async () => (await s.get(r)).toJSON(),
1110
- enabled: f === "update" && !!r,
229
+ bdo: e,
230
+ recordId: n,
231
+ operation: g,
232
+ defaultValues: c,
233
+ mode: t = "onBlur",
234
+ enableDraft: r,
235
+ enableConstraintValidation: V,
236
+ enableExpressionValidation: R
237
+ } = i, s = (i.interactionMode ?? (r === !0 ? "interactive" : r === !1 ? "non-interactive" : "interactive")) === "interactive", l = g ?? (n ? "update" : "create"), o = z(
238
+ () => H(e, { enableConstraintValidation: V }),
239
+ [e, V]
240
+ ), {
241
+ data: v,
242
+ isLoading: q,
243
+ isFetching: C,
244
+ error: $
245
+ } = K({
246
+ queryKey: ["form-record", e.meta._id, n],
247
+ queryFn: async () => (await e.get(n)).toJSON(),
248
+ enabled: l === "update" && !!n,
1111
249
  staleTime: 0
1112
250
  // Always fetch fresh data for forms
1113
- }), { data: F } = $e({
1114
- queryKey: ["form-schema", s.meta._id],
1115
- queryFn: () => wt(s.meta._id),
251
+ }), { data: O } = K({
252
+ queryKey: ["form-schema", e.meta._id],
253
+ queryFn: () => G(e.meta._id),
1116
254
  staleTime: 30 * 60 * 1e3,
1117
255
  // Cache for 30 minutes
1118
- gcTime: 60 * 60 * 1e3
256
+ gcTime: 60 * 60 * 1e3,
1119
257
  // Keep in cache for 1 hour
258
+ enabled: R !== !1
1120
259
  });
1121
- xt(() => {
1122
- F != null && F.BOBlob && s.loadMetadata(F.BOBlob);
1123
- }, [F, s]);
1124
- const h = zt({
1125
- mode: l,
260
+ P(() => {
261
+ O != null && O.BOBlob && e.loadMetadata(O.BOBlob);
262
+ }, [O, e]);
263
+ const a = U({
264
+ mode: t,
1126
265
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1127
- resolver: A,
266
+ resolver: o,
1128
267
  // Validation integrated here!
1129
- defaultValues: u,
268
+ defaultValues: c,
1130
269
  // `values` prop reactively updates form when record loads
1131
- values: f === "update" && C ? C : void 0
1132
- }), $ = Je(
1133
- () => Yt(s, h),
1134
- [s, h]
1135
- ), M = s.getFields(), z = Ke(
1136
- (b, R) => {
1137
- var D;
1138
- const U = h.register(b, R);
1139
- return (D = M[b]) != null && D.meta.isEditable ? U : { ...U, disabled: !0 };
270
+ values: l === "update" && v ? v : void 0
271
+ }), m = e.getFields(), {
272
+ draftId: d,
273
+ isInitializingDraft: D,
274
+ isInteracting: h,
275
+ interactionError: M,
276
+ triggerInteraction: f,
277
+ commitDraft: x
278
+ } = Y({
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;
1140
303
  },
1141
- [h, M]
1142
- ), P = Ke(
1143
- (b, R) => h.handleSubmit(
304
+ [a, m, s, t, f]
305
+ );
306
+ P(() => {
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(
1144
315
  // onValid - validation passed, make API call
1145
- async (U, D) => {
1146
- var re;
316
+ async (y, T) => {
1147
317
  try {
1148
- const G = {};
1149
- for (const [ee, q] of Object.entries(U))
1150
- (re = M[ee]) != null && re.meta.isEditable && (G[ee] = q);
1151
- let Q;
1152
- f === "create" ? Q = await s.create(G) : Q = await s.update(r, G), b == null || b(Q, D);
1153
- } catch (G) {
1154
- R == null || R(G, D);
318
+ const S = {};
319
+ let k;
320
+ if (s && l === "create") {
321
+ const B = a.formState.dirtyFields;
322
+ for (const [b, J] of Object.entries(y))
323
+ m[b] && !m[b].readOnly && B[b] && (S[b] = J);
324
+ k = await x(S);
325
+ } else if (l === "create") {
326
+ for (const [B, b] of Object.entries(y))
327
+ m[B] && !m[B].readOnly && (S[B] = b);
328
+ k = await e.create(S);
329
+ } else {
330
+ const B = a.formState.dirtyFields;
331
+ for (const [b, J] of Object.entries(y))
332
+ m[b] && !m[b].readOnly && B[b] && (S[b] = J);
333
+ k = await e.update(n, S);
334
+ }
335
+ _ == null || _(k, T);
336
+ } catch (S) {
337
+ w == null || w(S, T);
1155
338
  }
1156
339
  },
1157
340
  // onInvalid - validation failed
1158
- (U, D) => {
1159
- R == null || R(U, D);
341
+ (y, T) => {
342
+ w == null || w(y, T);
1160
343
  }
1161
344
  ),
1162
- [h, s, f, r]
345
+ [a, e, l, n, m, s, x]
1163
346
  );
1164
347
  return {
1165
348
  // Item - synced with form
1166
- item: $,
349
+ item: F,
1167
350
  // BDO reference
1168
- bdo: s,
1169
- operation: f,
1170
- recordId: r,
351
+ bdo: e,
352
+ operation: l,
353
+ recordId: n,
1171
354
  // Smart register (auto-disables readonly fields)
1172
- register: z,
355
+ register: A,
1173
356
  // Custom handleSubmit (handles API call + filters payload)
1174
- handleSubmit: P,
357
+ handleSubmit: Q,
1175
358
  // RHF methods (spread, but handleSubmit is overridden above)
1176
- watch: h.watch,
1177
- setValue: h.setValue,
1178
- getValues: h.getValues,
1179
- reset: h.reset,
1180
- trigger: h.trigger,
1181
- control: h.control,
1182
- formState: h.formState,
359
+ watch: a.watch,
360
+ setValue: a.setValue,
361
+ getValues: a.getValues,
362
+ reset: a.reset,
363
+ trigger: a.trigger,
364
+ control: a.control,
365
+ formState: a.formState,
1183
366
  // Flattened state for convenience
1184
- errors: h.formState.errors,
1185
- isDirty: h.formState.isDirty,
1186
- isValid: h.formState.isValid,
1187
- isSubmitting: h.formState.isSubmitting,
1188
- isSubmitSuccessful: h.formState.isSubmitSuccessful,
1189
- dirtyFields: h.formState.dirtyFields,
367
+ errors: a.formState.errors,
368
+ isDirty: a.formState.isDirty,
369
+ isValid: a.formState.isValid,
370
+ isSubmitting: a.formState.isSubmitting,
371
+ isSubmitSuccessful: a.formState.isSubmitSuccessful,
372
+ dirtyFields: a.formState.dirtyFields,
1190
373
  // Loading states
1191
- isLoading: K,
1192
- isFetching: K,
374
+ isLoading: q || D,
375
+ isFetching: C,
1193
376
  // Error
1194
- loadError: _
377
+ loadError: $,
378
+ // Draft / Interactive mode
379
+ draftId: d,
380
+ isInitializingDraft: D,
381
+ isInteracting: h,
382
+ interactionError: M
1195
383
  };
1196
384
  }
1197
385
  export {
1198
- er as useForm
386
+ it as FormOperation,
387
+ st as InteractionMode,
388
+ lt as ValidationMode,
389
+ rt as useForm
1199
390
  };