@inl0re/blnk 1.0.0
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/LICENSE +21 -0
- package/README.md +148 -0
- package/README.ru.md +476 -0
- package/dist/core/createFormControl.d.ts +3 -0
- package/dist/core/createFormControl.d.ts.map +1 -0
- package/dist/core/fieldArrayState.d.ts +23 -0
- package/dist/core/fieldArrayState.d.ts.map +1 -0
- package/dist/core/fieldRegistry.d.ts +9 -0
- package/dist/core/fieldRegistry.d.ts.map +1 -0
- package/dist/core/formState.d.ts +13 -0
- package/dist/core/formState.d.ts.map +1 -0
- package/dist/core/store.d.ts +4 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/subscriptionManager.d.ts +8 -0
- package/dist/core/subscriptionManager.d.ts.map +1 -0
- package/dist/core/transactionManager.d.ts +11 -0
- package/dist/core/transactionManager.d.ts.map +1 -0
- package/dist/core/validationEngine.d.ts +5 -0
- package/dist/core/validationEngine.d.ts.map +1 -0
- package/dist/hooks/Controller.d.ts +8 -0
- package/dist/hooks/Controller.d.ts.map +1 -0
- package/dist/hooks/useController.d.ts +23 -0
- package/dist/hooks/useController.d.ts.map +1 -0
- package/dist/hooks/useField.d.ts +4 -0
- package/dist/hooks/useField.d.ts.map +1 -0
- package/dist/hooks/useFieldArray.d.ts +23 -0
- package/dist/hooks/useFieldArray.d.ts.map +1 -0
- package/dist/hooks/useForm.d.ts +3 -0
- package/dist/hooks/useForm.d.ts.map +1 -0
- package/dist/hooks/useFormState.d.ts +9 -0
- package/dist/hooks/useFormState.d.ts.map +1 -0
- package/dist/hooks/useWatch.d.ts +22 -0
- package/dist/hooks/useWatch.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +669 -0
- package/dist/index.mjs.map +1 -0
- package/dist/resolvers/yupResolver.d.ts +4 -0
- package/dist/resolvers/yupResolver.d.ts.map +1 -0
- package/dist/resolvers/zodResolver.d.ts +4 -0
- package/dist/resolvers/zodResolver.d.ts.map +1 -0
- package/dist/types/form.d.ts +94 -0
- package/dist/types/form.d.ts.map +1 -0
- package/dist/types/path.d.ts +9 -0
- package/dist/types/path.d.ts.map +1 -0
- package/dist/types/resolver.d.ts +7 -0
- package/dist/types/resolver.d.ts.map +1 -0
- package/dist/utils/clone.d.ts +2 -0
- package/dist/utils/clone.d.ts.map +1 -0
- package/dist/utils/get.d.ts +2 -0
- package/dist/utils/get.d.ts.map +1 -0
- package/dist/utils/getInputValue.d.ts +7 -0
- package/dist/utils/getInputValue.d.ts.map +1 -0
- package/dist/utils/isEqual.d.ts +2 -0
- package/dist/utils/isEqual.d.ts.map +1 -0
- package/dist/utils/path.d.ts +3 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/set.d.ts +2 -0
- package/dist/utils/set.d.ts.map +1 -0
- package/dist/utils/unset.d.ts +2 -0
- package/dist/utils/unset.d.ts.map +1 -0
- package/package.json +86 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
import { useRef as I, useCallback as T, useSyncExternalStore as K, useMemo as k, useState as W, useEffect as _, useReducer as Y } from "react";
|
|
2
|
+
function C(e) {
|
|
3
|
+
return e.split(".").filter(Boolean);
|
|
4
|
+
}
|
|
5
|
+
function Z(e) {
|
|
6
|
+
return /^(0|[1-9]\d*)$/.test(e);
|
|
7
|
+
}
|
|
8
|
+
function b(e, t, r) {
|
|
9
|
+
if (!t)
|
|
10
|
+
return e;
|
|
11
|
+
let s = e;
|
|
12
|
+
for (const i of C(t)) {
|
|
13
|
+
if (s == null)
|
|
14
|
+
return r;
|
|
15
|
+
s = s[i];
|
|
16
|
+
}
|
|
17
|
+
return s === void 0 ? r : s;
|
|
18
|
+
}
|
|
19
|
+
function O(e, t) {
|
|
20
|
+
return {
|
|
21
|
+
value: e.getValue(t),
|
|
22
|
+
error: b(e.formState.errors, t),
|
|
23
|
+
isDirty: !!b(e.formState.dirtyFields, t),
|
|
24
|
+
isTouched: !!b(e.formState.touchedFields, t),
|
|
25
|
+
isValidating: !!b(e.formState.validatingFields, t)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function ee(e, t) {
|
|
29
|
+
const r = I(0), s = T(() => r.current, []), i = T(
|
|
30
|
+
(u) => {
|
|
31
|
+
const l = () => {
|
|
32
|
+
r.current += 1, u();
|
|
33
|
+
}, d = e.subscribe(t, l), f = e.subscribeFormState(
|
|
34
|
+
(a) => ({
|
|
35
|
+
error: b(a.errors, t),
|
|
36
|
+
dirty: b(a.dirtyFields, t),
|
|
37
|
+
touched: b(a.touchedFields, t),
|
|
38
|
+
validating: b(a.validatingFields, t)
|
|
39
|
+
}),
|
|
40
|
+
l
|
|
41
|
+
);
|
|
42
|
+
return () => {
|
|
43
|
+
d(), f();
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
[e, t]
|
|
47
|
+
);
|
|
48
|
+
return K(i, s, s), O(e, t);
|
|
49
|
+
}
|
|
50
|
+
function te(e) {
|
|
51
|
+
return Array.isArray(e);
|
|
52
|
+
}
|
|
53
|
+
function re(e) {
|
|
54
|
+
return te(e) ? Array.from(e) : e;
|
|
55
|
+
}
|
|
56
|
+
function P(e, t, r) {
|
|
57
|
+
if (Array.isArray(t))
|
|
58
|
+
return t.map((u, l) => {
|
|
59
|
+
const d = e.getValue(u);
|
|
60
|
+
return d === void 0 && Array.isArray(r) ? r[l] : d;
|
|
61
|
+
});
|
|
62
|
+
if (t) {
|
|
63
|
+
const i = e.getValue(t);
|
|
64
|
+
return i === void 0 ? r : i;
|
|
65
|
+
}
|
|
66
|
+
const s = e.getValues();
|
|
67
|
+
return Object.keys(s).length === 0 && r !== void 0 ? r : s;
|
|
68
|
+
}
|
|
69
|
+
function se({
|
|
70
|
+
control: e,
|
|
71
|
+
name: t,
|
|
72
|
+
defaultValue: r
|
|
73
|
+
}) {
|
|
74
|
+
const s = k(() => re(t), [t]), i = Array.isArray(s) ? s.join("\0") : s ?? "", [u, l] = W(() => P(e, s, r));
|
|
75
|
+
return _(() => {
|
|
76
|
+
const d = () => {
|
|
77
|
+
l(P(e, s, r));
|
|
78
|
+
};
|
|
79
|
+
if (Array.isArray(s)) {
|
|
80
|
+
const a = s.map(
|
|
81
|
+
(m) => e.subscribe(m, d)
|
|
82
|
+
);
|
|
83
|
+
return () => {
|
|
84
|
+
for (const m of a)
|
|
85
|
+
m();
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return s ? e.subscribe(s, d) : e.subscribeFormState(
|
|
89
|
+
() => e.getValues(),
|
|
90
|
+
() => {
|
|
91
|
+
d();
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}, [e, r, s, i]), u;
|
|
95
|
+
}
|
|
96
|
+
function ie({
|
|
97
|
+
control: e,
|
|
98
|
+
name: t,
|
|
99
|
+
rules: r,
|
|
100
|
+
defaultValue: s
|
|
101
|
+
}) {
|
|
102
|
+
const i = k(() => e.register(t, r), [e, t, r]), u = se({ control: e, name: t, defaultValue: s }), l = ee(e, t);
|
|
103
|
+
return {
|
|
104
|
+
field: {
|
|
105
|
+
...i,
|
|
106
|
+
value: u
|
|
107
|
+
},
|
|
108
|
+
fieldState: {
|
|
109
|
+
error: l.error,
|
|
110
|
+
isDirty: l.isDirty,
|
|
111
|
+
isTouched: l.isTouched,
|
|
112
|
+
isValidating: l.isValidating
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function me({
|
|
117
|
+
render: e,
|
|
118
|
+
...t
|
|
119
|
+
}) {
|
|
120
|
+
return e(ie(t));
|
|
121
|
+
}
|
|
122
|
+
const x = /* @__PURE__ */ new WeakMap();
|
|
123
|
+
let z = 0;
|
|
124
|
+
function $() {
|
|
125
|
+
return z += 1, `field-array-${z}`;
|
|
126
|
+
}
|
|
127
|
+
function U(e) {
|
|
128
|
+
let t = x.get(e);
|
|
129
|
+
return t || (t = /* @__PURE__ */ new Map(), x.set(e, t)), t;
|
|
130
|
+
}
|
|
131
|
+
function M(e, t, r) {
|
|
132
|
+
const s = U(e), i = s.get(t) ?? [];
|
|
133
|
+
for (; i.length < r; )
|
|
134
|
+
i.push($());
|
|
135
|
+
return i.length > r && (i.length = r), s.set(t, i), i;
|
|
136
|
+
}
|
|
137
|
+
function ne(e, t, r) {
|
|
138
|
+
U(e).set(t, r);
|
|
139
|
+
}
|
|
140
|
+
function j() {
|
|
141
|
+
return $();
|
|
142
|
+
}
|
|
143
|
+
function v(e) {
|
|
144
|
+
if (e == null || typeof e != "object")
|
|
145
|
+
return e;
|
|
146
|
+
if (e instanceof Date)
|
|
147
|
+
return new Date(e.getTime());
|
|
148
|
+
if (Array.isArray(e))
|
|
149
|
+
return e.map((r) => v(r));
|
|
150
|
+
const t = {};
|
|
151
|
+
for (const r of Object.keys(e))
|
|
152
|
+
t[r] = v(e[r]);
|
|
153
|
+
return t;
|
|
154
|
+
}
|
|
155
|
+
function D(e, t) {
|
|
156
|
+
const r = e.getValue(t);
|
|
157
|
+
return Array.isArray(r) ? v(r) : [];
|
|
158
|
+
}
|
|
159
|
+
function ue({
|
|
160
|
+
control: e,
|
|
161
|
+
name: t
|
|
162
|
+
}) {
|
|
163
|
+
const r = t;
|
|
164
|
+
function s(i, u, l) {
|
|
165
|
+
var f;
|
|
166
|
+
ne(e, r, u);
|
|
167
|
+
const d = e;
|
|
168
|
+
(f = d._updateFieldArrayMetadata) == null || f.call(d, r, l), e.setValue(t, i, {
|
|
169
|
+
shouldDirty: !0,
|
|
170
|
+
shouldValidate: !0
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
get fields() {
|
|
175
|
+
const i = D(e, t), u = M(e, r, i.length);
|
|
176
|
+
return i.map(
|
|
177
|
+
(l, d) => Object.assign({}, l, { id: u[d] })
|
|
178
|
+
);
|
|
179
|
+
},
|
|
180
|
+
append(i) {
|
|
181
|
+
const u = D(e, t), l = M(e, r, u.length);
|
|
182
|
+
s([...u, i], [...l, j()], { type: "append" });
|
|
183
|
+
},
|
|
184
|
+
remove(i) {
|
|
185
|
+
const u = D(e, t), l = M(e, r, u.length);
|
|
186
|
+
i < 0 || i >= u.length || (u.splice(i, 1), l.splice(i, 1), s(u, l, { type: "remove", index: i }));
|
|
187
|
+
},
|
|
188
|
+
insert(i, u) {
|
|
189
|
+
const l = D(e, t), d = M(e, r, l.length);
|
|
190
|
+
l.splice(i, 0, u), d.splice(i, 0, j()), s(l, d, { type: "insert", index: i });
|
|
191
|
+
},
|
|
192
|
+
move(i, u) {
|
|
193
|
+
const l = D(e, t), d = M(e, r, l.length), [f] = l.splice(i, 1), [a] = d.splice(i, 1);
|
|
194
|
+
l.splice(u, 0, f), d.splice(u, 0, a), s(l, d, { type: "move", from: i, to: u });
|
|
195
|
+
},
|
|
196
|
+
swap(i, u) {
|
|
197
|
+
const l = D(e, t), d = M(e, r, l.length);
|
|
198
|
+
[l[i], l[u]] = [l[u], l[i]], [d[i], d[u]] = [d[u], d[i]], s(l, d, { type: "swap", left: i, right: u });
|
|
199
|
+
},
|
|
200
|
+
replace(i) {
|
|
201
|
+
s(
|
|
202
|
+
v(i),
|
|
203
|
+
i.map(() => j()),
|
|
204
|
+
{ type: "replace" }
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function Ve(e) {
|
|
210
|
+
const { control: t, name: r } = e, [, s] = Y((u) => u + 1, 0), i = k(() => ue({ control: t, name: r }), [t, r]);
|
|
211
|
+
return _(() => t.subscribe(r, () => {
|
|
212
|
+
s();
|
|
213
|
+
}), [t, r]), i;
|
|
214
|
+
}
|
|
215
|
+
function B(e, t) {
|
|
216
|
+
if (Object.is(e, t))
|
|
217
|
+
return !0;
|
|
218
|
+
if (typeof e != typeof t || e == null || t == null || typeof e != "object" || Array.isArray(e) !== Array.isArray(t))
|
|
219
|
+
return !1;
|
|
220
|
+
const r = e, s = t, i = Object.keys(r), u = Object.keys(s);
|
|
221
|
+
return i.length !== u.length ? !1 : i.every((l) => B(r[l], s[l]));
|
|
222
|
+
}
|
|
223
|
+
function ae(e) {
|
|
224
|
+
return typeof e == "boolean" ? { valueAsNumber: e } : e ?? {};
|
|
225
|
+
}
|
|
226
|
+
function oe(e, t) {
|
|
227
|
+
const r = ae(t), s = e, i = s == null ? void 0 : s.target;
|
|
228
|
+
if (!i)
|
|
229
|
+
return r.setValueAs ? r.setValueAs(e) : e;
|
|
230
|
+
let u;
|
|
231
|
+
if (i.type === "checkbox")
|
|
232
|
+
u = !!i.checked;
|
|
233
|
+
else if (i.type === "file")
|
|
234
|
+
u = i.files;
|
|
235
|
+
else if (i.type === "select-multiple" || i.multiple)
|
|
236
|
+
u = Array.from(i.selectedOptions ?? []).map((l) => l.value);
|
|
237
|
+
else if (r.valueAsDate)
|
|
238
|
+
u = i.value ? new Date(String(i.value)) : void 0;
|
|
239
|
+
else if (r.valueAsNumber || i.type === "number" || i.type === "range")
|
|
240
|
+
if (i.value === "" || i.value == null)
|
|
241
|
+
u = void 0;
|
|
242
|
+
else {
|
|
243
|
+
const l = Number(i.value);
|
|
244
|
+
u = Number.isNaN(l) ? void 0 : l;
|
|
245
|
+
}
|
|
246
|
+
else
|
|
247
|
+
u = i.value;
|
|
248
|
+
return r.setValueAs ? r.setValueAs(u) : u;
|
|
249
|
+
}
|
|
250
|
+
function p(e, t, r) {
|
|
251
|
+
const s = C(t);
|
|
252
|
+
if (s.length === 0)
|
|
253
|
+
return;
|
|
254
|
+
let i = e;
|
|
255
|
+
for (let u = 0; u < s.length - 1; u += 1) {
|
|
256
|
+
const l = s[u], d = s[u + 1], f = i;
|
|
257
|
+
(f[l] == null || typeof f[l] != "object") && (f[l] = Z(d) ? [] : {}), i = f[l];
|
|
258
|
+
}
|
|
259
|
+
i[s[s.length - 1]] = r;
|
|
260
|
+
}
|
|
261
|
+
function h(e, t) {
|
|
262
|
+
const r = C(t);
|
|
263
|
+
if (r.length === 0)
|
|
264
|
+
return;
|
|
265
|
+
let s = e;
|
|
266
|
+
for (const u of r.slice(0, -1))
|
|
267
|
+
if (s = s == null ? void 0 : s[u], s == null)
|
|
268
|
+
return;
|
|
269
|
+
const i = r[r.length - 1];
|
|
270
|
+
if (Array.isArray(s)) {
|
|
271
|
+
s.splice(Number(i), 1);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
s == null || delete s[i];
|
|
275
|
+
}
|
|
276
|
+
class le {
|
|
277
|
+
constructor() {
|
|
278
|
+
this.fieldSubscribers = /* @__PURE__ */ new Map();
|
|
279
|
+
}
|
|
280
|
+
subscribe(t, r) {
|
|
281
|
+
const s = this.fieldSubscribers.get(t) ?? /* @__PURE__ */ new Set();
|
|
282
|
+
return s.add(r), this.fieldSubscribers.set(t, s), () => {
|
|
283
|
+
s.delete(r), s.size === 0 && this.fieldSubscribers.delete(t);
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
notify(t, r) {
|
|
287
|
+
const s = this.fieldSubscribers.get(t);
|
|
288
|
+
if (s)
|
|
289
|
+
for (const i of Array.from(s))
|
|
290
|
+
i(r, t);
|
|
291
|
+
}
|
|
292
|
+
clear() {
|
|
293
|
+
this.fieldSubscribers.clear();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function F(e) {
|
|
297
|
+
return e == null ? !1 : typeof e != "object" || "type" in e ? !0 : Array.isArray(e) ? e.some((t) => F(t)) : Object.keys(e).some(
|
|
298
|
+
(t) => F(e[t])
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
function ce(e) {
|
|
302
|
+
return {
|
|
303
|
+
errors: e.errors,
|
|
304
|
+
touchedFields: e.touchedFields,
|
|
305
|
+
dirtyFields: e.dirtyFields,
|
|
306
|
+
isDirty: F(e.dirtyFields),
|
|
307
|
+
isValid: !F(e.errors),
|
|
308
|
+
isValidating: F(e.validatingFields),
|
|
309
|
+
isSubmitting: e.isSubmitting,
|
|
310
|
+
isSubmitted: e.isSubmitted,
|
|
311
|
+
submitCount: e.submitCount,
|
|
312
|
+
validatingFields: e.validatingFields
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function de() {
|
|
316
|
+
let e = 0, t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
|
|
317
|
+
return {
|
|
318
|
+
begin() {
|
|
319
|
+
e += 1;
|
|
320
|
+
},
|
|
321
|
+
commit() {
|
|
322
|
+
if (e === 0 || (e -= 1, e > 0))
|
|
323
|
+
return;
|
|
324
|
+
const s = {
|
|
325
|
+
notifications: t,
|
|
326
|
+
validations: r
|
|
327
|
+
};
|
|
328
|
+
return t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s;
|
|
329
|
+
},
|
|
330
|
+
queueNotification(s) {
|
|
331
|
+
return e === 0 ? !1 : (t.add(s), !0);
|
|
332
|
+
},
|
|
333
|
+
queueValidation(s) {
|
|
334
|
+
return e === 0 ? !1 : (r.add(s), !0);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function fe(e, t, r, s, i) {
|
|
339
|
+
const u = r;
|
|
340
|
+
t.set(u, s), e.set(u, { ref: s, options: i });
|
|
341
|
+
}
|
|
342
|
+
function ye(e, t, r) {
|
|
343
|
+
const s = r;
|
|
344
|
+
t.delete(s), e.delete(s);
|
|
345
|
+
}
|
|
346
|
+
function N(e) {
|
|
347
|
+
return v(e ?? {});
|
|
348
|
+
}
|
|
349
|
+
function be(e, t, r, s) {
|
|
350
|
+
const i = b(t, s), u = b(r, s);
|
|
351
|
+
B(i, u) ? h(e, s) : p(e, s, !0);
|
|
352
|
+
}
|
|
353
|
+
function ge(e) {
|
|
354
|
+
const t = e;
|
|
355
|
+
return async (r) => {
|
|
356
|
+
var s;
|
|
357
|
+
try {
|
|
358
|
+
return { values: await t.validate(r, { abortEarly: !1 }), errors: {} };
|
|
359
|
+
} catch (i) {
|
|
360
|
+
const u = i, l = {}, d = (s = u.inner) != null && s.length ? u.inner : [u];
|
|
361
|
+
for (const f of d)
|
|
362
|
+
f.path && p(l, f.path, {
|
|
363
|
+
type: f.type ?? "yup",
|
|
364
|
+
message: f.message
|
|
365
|
+
});
|
|
366
|
+
return { values: {}, errors: l };
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function ve(e) {
|
|
371
|
+
const t = e;
|
|
372
|
+
return async (r) => {
|
|
373
|
+
var u, l;
|
|
374
|
+
const s = t.safeParseAsync ? await t.safeParseAsync(r) : (u = t.safeParse) == null ? void 0 : u.call(t, r);
|
|
375
|
+
if (!s)
|
|
376
|
+
return { values: r, errors: {} };
|
|
377
|
+
if (s.success)
|
|
378
|
+
return { values: s.data, errors: {} };
|
|
379
|
+
const i = {};
|
|
380
|
+
for (const d of ((l = s.error) == null ? void 0 : l.issues) ?? [])
|
|
381
|
+
p(i, d.path.join("."), {
|
|
382
|
+
type: d.code ?? "zod",
|
|
383
|
+
message: d.message
|
|
384
|
+
});
|
|
385
|
+
return { values: {}, errors: i };
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function E(e) {
|
|
389
|
+
return typeof e == "string" ? { type: "validate", message: e } : e;
|
|
390
|
+
}
|
|
391
|
+
function pe(e) {
|
|
392
|
+
const t = e;
|
|
393
|
+
if (t) {
|
|
394
|
+
if (typeof t.safeParseAsync == "function" || typeof t.safeParse == "function")
|
|
395
|
+
return ve(e);
|
|
396
|
+
if (typeof t.validate == "function")
|
|
397
|
+
return ge(e);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function he(e) {
|
|
401
|
+
var r;
|
|
402
|
+
const t = e;
|
|
403
|
+
(r = t == null ? void 0 : t.preventDefault) == null || r.call(t);
|
|
404
|
+
}
|
|
405
|
+
function Fe(e, t) {
|
|
406
|
+
const r = [...e];
|
|
407
|
+
if (t.type === "remove")
|
|
408
|
+
r.splice(t.index, 1);
|
|
409
|
+
else if (t.type === "insert")
|
|
410
|
+
r.splice(t.index, 0, void 0);
|
|
411
|
+
else if (t.type === "move") {
|
|
412
|
+
const [s] = r.splice(t.from, 1);
|
|
413
|
+
r.splice(t.to, 0, s);
|
|
414
|
+
} else if (t.type === "swap")
|
|
415
|
+
[r[t.left], r[t.right]] = [r[t.right], r[t.left]];
|
|
416
|
+
else if (t.type === "replace")
|
|
417
|
+
return [];
|
|
418
|
+
for (; r.length > 0 && r[r.length - 1] === void 0; )
|
|
419
|
+
r.pop();
|
|
420
|
+
return r;
|
|
421
|
+
}
|
|
422
|
+
function Se(e = {}) {
|
|
423
|
+
const t = e.resolver ?? pe(e.schema), r = e.mode ?? "onSubmit", s = e.reValidateMode ?? "onChange", i = new le(), u = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = de(), a = {
|
|
424
|
+
values: N(e.defaultValues),
|
|
425
|
+
defaultValues: N(e.defaultValues),
|
|
426
|
+
errors: {},
|
|
427
|
+
touchedFields: {},
|
|
428
|
+
dirtyFields: {},
|
|
429
|
+
validatingFields: {},
|
|
430
|
+
registeredFields: /* @__PURE__ */ new Map(),
|
|
431
|
+
refs: /* @__PURE__ */ new Map(),
|
|
432
|
+
isSubmitting: !1,
|
|
433
|
+
isSubmitted: !1,
|
|
434
|
+
submitCount: 0
|
|
435
|
+
};
|
|
436
|
+
function m() {
|
|
437
|
+
return ce(a);
|
|
438
|
+
}
|
|
439
|
+
function V() {
|
|
440
|
+
const n = m();
|
|
441
|
+
for (const o of Array.from(u)) {
|
|
442
|
+
const c = o.selector(n);
|
|
443
|
+
B(c, o.last) || (o.last = v(c), o.callback(c));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function S(n) {
|
|
447
|
+
f.queueNotification(n) || (i.notify(n, b(a.values, n)), V());
|
|
448
|
+
}
|
|
449
|
+
function G(n) {
|
|
450
|
+
be(a.dirtyFields, a.values, a.defaultValues, n);
|
|
451
|
+
}
|
|
452
|
+
function q(n, o) {
|
|
453
|
+
o ? p(a.validatingFields, n, !0) : h(a.validatingFields, n), V();
|
|
454
|
+
}
|
|
455
|
+
async function H(n, o) {
|
|
456
|
+
if (o <= 0)
|
|
457
|
+
return;
|
|
458
|
+
const c = d.get(n);
|
|
459
|
+
c && clearTimeout(c), await new Promise((y) => {
|
|
460
|
+
const w = setTimeout(() => {
|
|
461
|
+
d.delete(n), y();
|
|
462
|
+
}, o);
|
|
463
|
+
d.set(n, w);
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
async function J(n) {
|
|
467
|
+
var R;
|
|
468
|
+
const o = a.registeredFields.get(n), c = o == null ? void 0 : o.options, y = b(a.values, n);
|
|
469
|
+
if (c != null && c.disabled)
|
|
470
|
+
return;
|
|
471
|
+
if (c != null && c.required && (y == null || y === "" || Array.isArray(y) && y.length === 0 || y === !1))
|
|
472
|
+
return {
|
|
473
|
+
type: "required",
|
|
474
|
+
message: typeof c.required == "string" ? c.required : "This field is required"
|
|
475
|
+
};
|
|
476
|
+
if (c != null && c.validate) {
|
|
477
|
+
const A = await c.validate(y, a.values);
|
|
478
|
+
if (A !== !0 && A != null)
|
|
479
|
+
return E(A);
|
|
480
|
+
}
|
|
481
|
+
const w = (R = e.asyncValidators) == null ? void 0 : R[n];
|
|
482
|
+
if (w) {
|
|
483
|
+
await H(n, (c == null ? void 0 : c.debounceMs) ?? e.asyncValidatorDebounceMs ?? 0);
|
|
484
|
+
const A = await w(y, a.values);
|
|
485
|
+
if (A !== !0 && A != null)
|
|
486
|
+
return E(A);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function L(n) {
|
|
490
|
+
return r === "onChange" || !!b(a.errors, n) && s === "onChange";
|
|
491
|
+
}
|
|
492
|
+
function Q(n) {
|
|
493
|
+
return r === "onBlur" || !!b(a.errors, n) && s === "onBlur";
|
|
494
|
+
}
|
|
495
|
+
function X(n, o) {
|
|
496
|
+
for (const c of [a.errors, a.touchedFields, a.dirtyFields]) {
|
|
497
|
+
const y = b(c, n);
|
|
498
|
+
if (Array.isArray(y)) {
|
|
499
|
+
const w = Fe(y, o);
|
|
500
|
+
w.length === 0 ? h(c, n) : p(c, n, w);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const g = {
|
|
505
|
+
get formState() {
|
|
506
|
+
return m();
|
|
507
|
+
},
|
|
508
|
+
getValue(n) {
|
|
509
|
+
return b(a.values, n);
|
|
510
|
+
},
|
|
511
|
+
getValues() {
|
|
512
|
+
return v(a.values);
|
|
513
|
+
},
|
|
514
|
+
setValue(n, o, c = {}) {
|
|
515
|
+
p(a.values, n, o), (c.shouldDirty ?? !0) && G(n), c.shouldTouch && p(a.touchedFields, n, !0), c.shouldValidate && (f.queueValidation(n) || g.validateField(n)), S(n);
|
|
516
|
+
},
|
|
517
|
+
setError(n, o) {
|
|
518
|
+
p(a.errors, n, o), S(n);
|
|
519
|
+
},
|
|
520
|
+
clearError(n) {
|
|
521
|
+
h(a.errors, n), S(n);
|
|
522
|
+
},
|
|
523
|
+
register(n, o) {
|
|
524
|
+
return a.registeredFields.set(n, {
|
|
525
|
+
ref: a.refs.get(n),
|
|
526
|
+
options: o
|
|
527
|
+
}), {
|
|
528
|
+
name: n,
|
|
529
|
+
ref: (c) => {
|
|
530
|
+
g.registerField(n, c, o);
|
|
531
|
+
},
|
|
532
|
+
onChange: (c) => {
|
|
533
|
+
if (o != null && o.disabled)
|
|
534
|
+
return;
|
|
535
|
+
const y = oe(c, o);
|
|
536
|
+
g.setValue(n, y, {
|
|
537
|
+
shouldDirty: !0,
|
|
538
|
+
shouldValidate: L(n)
|
|
539
|
+
});
|
|
540
|
+
},
|
|
541
|
+
onBlur: () => {
|
|
542
|
+
o != null && o.disabled || (p(a.touchedFields, n, !0), Q(n) && (f.queueValidation(n) || g.validateField(n)), S(n));
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
},
|
|
546
|
+
registerField(n, o, c) {
|
|
547
|
+
fe(a.registeredFields, a.refs, n, o, c);
|
|
548
|
+
},
|
|
549
|
+
unregisterField(n) {
|
|
550
|
+
ye(a.registeredFields, a.refs, n), e.shouldUnregister && (h(a.values, n), h(a.errors, n), h(a.touchedFields, n), h(a.dirtyFields, n), S(n));
|
|
551
|
+
},
|
|
552
|
+
subscribe(n, o) {
|
|
553
|
+
return i.subscribe(n, o);
|
|
554
|
+
},
|
|
555
|
+
subscribeFormState(n, o) {
|
|
556
|
+
const c = {
|
|
557
|
+
selector: n,
|
|
558
|
+
callback: o,
|
|
559
|
+
last: v(n(m()))
|
|
560
|
+
};
|
|
561
|
+
return u.add(c), () => {
|
|
562
|
+
u.delete(c);
|
|
563
|
+
};
|
|
564
|
+
},
|
|
565
|
+
notify(n) {
|
|
566
|
+
S(n);
|
|
567
|
+
},
|
|
568
|
+
reset(n) {
|
|
569
|
+
a.defaultValues = N(n ?? e.defaultValues), a.values = N(n ?? e.defaultValues), a.errors = {}, a.touchedFields = {}, a.dirtyFields = {}, a.validatingFields = {}, a.isSubmitting = !1, a.isSubmitted = !1, a.submitCount = 0;
|
|
570
|
+
const o = new Set(a.registeredFields.keys());
|
|
571
|
+
for (const c of o)
|
|
572
|
+
S(c);
|
|
573
|
+
V();
|
|
574
|
+
},
|
|
575
|
+
async validateField(n) {
|
|
576
|
+
const o = n, c = (l.get(o) ?? 0) + 1;
|
|
577
|
+
l.set(o, c), q(o, !0);
|
|
578
|
+
try {
|
|
579
|
+
const y = await J(o);
|
|
580
|
+
return l.get(o) !== c ? !F(b(a.errors, o)) : (y ? p(a.errors, o, y) : h(a.errors, o), S(o), !y);
|
|
581
|
+
} finally {
|
|
582
|
+
l.get(o) === c && q(o, !1);
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
async validateForm() {
|
|
586
|
+
let n = !0;
|
|
587
|
+
if (t) {
|
|
588
|
+
const o = await t(v(a.values));
|
|
589
|
+
a.errors = v(o.errors), !F(o.errors) && Object.keys(o.values).length > 0 && (a.values = v(o.values)), n = !F(a.errors);
|
|
590
|
+
}
|
|
591
|
+
for (const o of Array.from(a.registeredFields.keys()))
|
|
592
|
+
n = await g.validateField(o) && n;
|
|
593
|
+
return V(), n && !F(a.errors);
|
|
594
|
+
},
|
|
595
|
+
handleSubmit(n, o) {
|
|
596
|
+
return async (c) => {
|
|
597
|
+
he(c), a.isSubmitting = !0, V();
|
|
598
|
+
try {
|
|
599
|
+
await g.validateForm() ? await n(g.getValues(), c) : await (o == null ? void 0 : o(a.errors, c)), a.isSubmitted = !0, a.submitCount += 1;
|
|
600
|
+
} finally {
|
|
601
|
+
a.isSubmitting = !1, V();
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
},
|
|
605
|
+
watch: (n, o) => typeof n == "string" && o ? i.subscribe(n, o) : typeof n == "string" ? b(a.values, n) : g.getValues(),
|
|
606
|
+
beginTransaction() {
|
|
607
|
+
f.begin();
|
|
608
|
+
},
|
|
609
|
+
commitTransaction() {
|
|
610
|
+
const n = f.commit();
|
|
611
|
+
if (n) {
|
|
612
|
+
for (const o of n.validations)
|
|
613
|
+
g.validateField(o);
|
|
614
|
+
for (const o of n.notifications)
|
|
615
|
+
i.notify(o, b(a.values, o));
|
|
616
|
+
V();
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
transaction(n) {
|
|
620
|
+
g.beginTransaction();
|
|
621
|
+
try {
|
|
622
|
+
n();
|
|
623
|
+
} finally {
|
|
624
|
+
g.commitTransaction();
|
|
625
|
+
}
|
|
626
|
+
},
|
|
627
|
+
_updateFieldArrayMetadata: X
|
|
628
|
+
};
|
|
629
|
+
return g;
|
|
630
|
+
}
|
|
631
|
+
function we(e = {}) {
|
|
632
|
+
const [t] = W(() => {
|
|
633
|
+
const r = Se(e);
|
|
634
|
+
return Object.assign(r, { control: r });
|
|
635
|
+
});
|
|
636
|
+
return t;
|
|
637
|
+
}
|
|
638
|
+
function Me({
|
|
639
|
+
control: e,
|
|
640
|
+
selector: t
|
|
641
|
+
}) {
|
|
642
|
+
const r = I(0), s = T(() => r.current, []), i = T(
|
|
643
|
+
(u) => e.subscribeFormState(t, () => {
|
|
644
|
+
r.current += 1, u();
|
|
645
|
+
}),
|
|
646
|
+
[e, t]
|
|
647
|
+
);
|
|
648
|
+
return K(i, s, s), t(e.formState);
|
|
649
|
+
}
|
|
650
|
+
export {
|
|
651
|
+
me as Controller,
|
|
652
|
+
le as SubscriptionManager,
|
|
653
|
+
ue as createFieldArray,
|
|
654
|
+
Se as createFormControl,
|
|
655
|
+
b as get,
|
|
656
|
+
oe as getInputValue,
|
|
657
|
+
B as isEqual,
|
|
658
|
+
p as set,
|
|
659
|
+
h as unset,
|
|
660
|
+
ie as useController,
|
|
661
|
+
ee as useField,
|
|
662
|
+
Ve as useFieldArray,
|
|
663
|
+
we as useForm,
|
|
664
|
+
Me as useFormState,
|
|
665
|
+
se as useWatch,
|
|
666
|
+
ge as yupResolver,
|
|
667
|
+
ve as zodResolver
|
|
668
|
+
};
|
|
669
|
+
//# sourceMappingURL=index.mjs.map
|