@reformer/core 1.1.0 → 2.0.0-beta.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.
- package/dist/behaviors-DzYL8kY_.js +499 -0
- package/dist/behaviors.d.ts +6 -2
- package/dist/behaviors.js +19 -227
- package/dist/core/behavior/behavior-context.d.ts +6 -2
- package/dist/core/behavior/create-field-path.d.ts +3 -16
- package/dist/core/nodes/group-node.d.ts +14 -193
- package/dist/core/types/form-context.d.ts +10 -4
- package/dist/core/utils/field-path.d.ts +48 -0
- package/dist/core/utils/index.d.ts +1 -0
- package/dist/core/validation/core/validate-tree.d.ts +10 -4
- package/dist/core/validation/field-path.d.ts +3 -39
- package/dist/core/validation/validation-context.d.ts +23 -0
- package/dist/hooks/types.d.ts +328 -0
- package/dist/hooks/useFormControl.d.ts +13 -37
- package/dist/hooks/useFormControlValue.d.ts +167 -0
- package/dist/hooks/useSignalSubscription.d.ts +17 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +2886 -8
- package/dist/{create-field-path-CdPF3lIK.js → registry-helpers-BRxAr6nG.js} +133 -347
- package/dist/validators-gXoHPdqM.js +418 -0
- package/dist/validators.d.ts +6 -2
- package/dist/validators.js +29 -296
- package/llms.txt +1283 -22
- package/package.json +8 -4
- package/dist/core/behavior/behavior-applicator.d.ts +0 -71
- package/dist/core/behavior/behavior-applicator.js +0 -92
- package/dist/core/behavior/behavior-context.js +0 -38
- package/dist/core/behavior/behavior-registry.js +0 -198
- package/dist/core/behavior/behaviors/compute-from.js +0 -84
- package/dist/core/behavior/behaviors/copy-from.js +0 -64
- package/dist/core/behavior/behaviors/enable-when.js +0 -81
- package/dist/core/behavior/behaviors/index.js +0 -11
- package/dist/core/behavior/behaviors/reset-when.js +0 -63
- package/dist/core/behavior/behaviors/revalidate-when.js +0 -51
- package/dist/core/behavior/behaviors/sync-fields.js +0 -66
- package/dist/core/behavior/behaviors/transform-value.js +0 -110
- package/dist/core/behavior/behaviors/watch-field.js +0 -56
- package/dist/core/behavior/compose-behavior.js +0 -166
- package/dist/core/behavior/create-field-path.js +0 -69
- package/dist/core/behavior/index.js +0 -17
- package/dist/core/behavior/types.js +0 -7
- package/dist/core/context/form-context-impl.js +0 -37
- package/dist/core/factories/index.js +0 -6
- package/dist/core/factories/node-factory.js +0 -281
- package/dist/core/nodes/array-node.js +0 -534
- package/dist/core/nodes/field-node.js +0 -510
- package/dist/core/nodes/form-node.js +0 -343
- package/dist/core/nodes/group-node/field-registry.d.ts +0 -191
- package/dist/core/nodes/group-node/field-registry.js +0 -215
- package/dist/core/nodes/group-node/index.d.ts +0 -11
- package/dist/core/nodes/group-node/index.js +0 -11
- package/dist/core/nodes/group-node/proxy-builder.d.ts +0 -71
- package/dist/core/nodes/group-node/proxy-builder.js +0 -161
- package/dist/core/nodes/group-node/state-manager.d.ts +0 -184
- package/dist/core/nodes/group-node/state-manager.js +0 -265
- package/dist/core/nodes/group-node.js +0 -770
- package/dist/core/types/deep-schema.js +0 -11
- package/dist/core/types/field-path.js +0 -4
- package/dist/core/types/form-context.js +0 -25
- package/dist/core/types/group-node-proxy.js +0 -31
- package/dist/core/types/index.js +0 -4
- package/dist/core/types/validation-schema.js +0 -10
- package/dist/core/utils/create-form.js +0 -24
- package/dist/core/utils/debounce.js +0 -197
- package/dist/core/utils/error-handler.js +0 -226
- package/dist/core/utils/field-path-navigator.js +0 -374
- package/dist/core/utils/index.js +0 -14
- package/dist/core/utils/registry-helpers.js +0 -79
- package/dist/core/utils/registry-stack.js +0 -86
- package/dist/core/utils/resources.js +0 -69
- package/dist/core/utils/subscription-manager.js +0 -214
- package/dist/core/utils/type-guards.js +0 -169
- package/dist/core/validation/core/apply-when.js +0 -41
- package/dist/core/validation/core/apply.js +0 -38
- package/dist/core/validation/core/index.js +0 -8
- package/dist/core/validation/core/validate-async.js +0 -45
- package/dist/core/validation/core/validate-tree.js +0 -37
- package/dist/core/validation/core/validate.js +0 -38
- package/dist/core/validation/field-path.js +0 -147
- package/dist/core/validation/index.js +0 -33
- package/dist/core/validation/validate-form.js +0 -152
- package/dist/core/validation/validation-applicator.js +0 -217
- package/dist/core/validation/validation-context.js +0 -75
- package/dist/core/validation/validation-registry.js +0 -298
- package/dist/core/validation/validators/array-validators.js +0 -86
- package/dist/core/validation/validators/date.js +0 -117
- package/dist/core/validation/validators/email.js +0 -60
- package/dist/core/validation/validators/index.js +0 -14
- package/dist/core/validation/validators/max-length.js +0 -60
- package/dist/core/validation/validators/max.js +0 -60
- package/dist/core/validation/validators/min-length.js +0 -60
- package/dist/core/validation/validators/min.js +0 -60
- package/dist/core/validation/validators/number.js +0 -90
- package/dist/core/validation/validators/pattern.js +0 -62
- package/dist/core/validation/validators/phone.js +0 -58
- package/dist/core/validation/validators/required.js +0 -69
- package/dist/core/validation/validators/url.js +0 -55
- package/dist/hooks/useFormControl.js +0 -298
- package/dist/node-factory-D7DOnSSN.js +0 -3200
|
@@ -1,243 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (d > 1)
|
|
4
|
-
d--;
|
|
5
|
-
else {
|
|
6
|
-
for (var i, t = !1; l !== void 0; ) {
|
|
7
|
-
var e = l;
|
|
8
|
-
for (l = void 0, x++; e !== void 0; ) {
|
|
9
|
-
var n = e.o;
|
|
10
|
-
if (e.o = void 0, e.f &= -3, !(8 & e.f) && _(e)) try {
|
|
11
|
-
e.c();
|
|
12
|
-
} catch (o) {
|
|
13
|
-
t || (i = o, t = !0);
|
|
14
|
-
}
|
|
15
|
-
e = n;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (x = 0, d--, t) throw i;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
var r = void 0;
|
|
22
|
-
function C(i) {
|
|
23
|
-
var t = r;
|
|
24
|
-
r = void 0;
|
|
25
|
-
try {
|
|
26
|
-
return i();
|
|
27
|
-
} finally {
|
|
28
|
-
r = t;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
var l = void 0, d = 0, x = 0, y = 0;
|
|
32
|
-
function k(i) {
|
|
33
|
-
if (r !== void 0) {
|
|
34
|
-
var t = i.n;
|
|
35
|
-
if (t === void 0 || t.t !== r)
|
|
36
|
-
return t = { i: 0, S: i, p: r.s, n: void 0, t: r, e: void 0, x: void 0, r: t }, r.s !== void 0 && (r.s.n = t), r.s = t, i.n = t, 32 & r.f && i.S(t), t;
|
|
37
|
-
if (t.i === -1)
|
|
38
|
-
return t.i = 0, t.n !== void 0 && (t.n.p = t.p, t.p !== void 0 && (t.p.n = t.n), t.p = r.s, t.n = void 0, r.s.n = t, r.s = t), t;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function c(i, t) {
|
|
42
|
-
this.v = i, this.i = 0, this.n = void 0, this.t = void 0, this.W = t?.watched, this.Z = t?.unwatched, this.name = t?.name;
|
|
43
|
-
}
|
|
44
|
-
c.prototype.brand = P;
|
|
45
|
-
c.prototype.h = function() {
|
|
46
|
-
return !0;
|
|
47
|
-
};
|
|
48
|
-
c.prototype.S = function(i) {
|
|
49
|
-
var t = this, e = this.t;
|
|
50
|
-
e !== i && i.e === void 0 && (i.x = e, this.t = i, e !== void 0 ? e.e = i : C(function() {
|
|
51
|
-
var n;
|
|
52
|
-
(n = t.W) == null || n.call(t);
|
|
53
|
-
}));
|
|
54
|
-
};
|
|
55
|
-
c.prototype.U = function(i) {
|
|
56
|
-
var t = this;
|
|
57
|
-
if (this.t !== void 0) {
|
|
58
|
-
var e = i.e, n = i.x;
|
|
59
|
-
e !== void 0 && (e.x = n, i.e = void 0), n !== void 0 && (n.e = e, i.x = void 0), i === this.t && (this.t = n, n === void 0 && C(function() {
|
|
60
|
-
var o;
|
|
61
|
-
(o = t.Z) == null || o.call(t);
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
c.prototype.subscribe = function(i) {
|
|
66
|
-
var t = this;
|
|
67
|
-
return F(function() {
|
|
68
|
-
var e = t.value, n = r;
|
|
69
|
-
r = void 0;
|
|
70
|
-
try {
|
|
71
|
-
i(e);
|
|
72
|
-
} finally {
|
|
73
|
-
r = n;
|
|
74
|
-
}
|
|
75
|
-
}, { name: "sub" });
|
|
76
|
-
};
|
|
77
|
-
c.prototype.valueOf = function() {
|
|
78
|
-
return this.value;
|
|
79
|
-
};
|
|
80
|
-
c.prototype.toString = function() {
|
|
81
|
-
return this.value + "";
|
|
82
|
-
};
|
|
83
|
-
c.prototype.toJSON = function() {
|
|
84
|
-
return this.value;
|
|
85
|
-
};
|
|
86
|
-
c.prototype.peek = function() {
|
|
87
|
-
var i = r;
|
|
88
|
-
r = void 0;
|
|
89
|
-
try {
|
|
90
|
-
return this.value;
|
|
91
|
-
} finally {
|
|
92
|
-
r = i;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
Object.defineProperty(c.prototype, "value", { get: function() {
|
|
96
|
-
var i = k(this);
|
|
97
|
-
return i !== void 0 && (i.i = this.i), this.v;
|
|
98
|
-
}, set: function(i) {
|
|
99
|
-
if (i !== this.v) {
|
|
100
|
-
if (x > 100) throw new Error("Cycle detected");
|
|
101
|
-
this.v = i, this.i++, y++, d++;
|
|
102
|
-
try {
|
|
103
|
-
for (var t = this.t; t !== void 0; t = t.x) t.t.N();
|
|
104
|
-
} finally {
|
|
105
|
-
w();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
} });
|
|
109
|
-
function O(i, t) {
|
|
110
|
-
return new c(i, t);
|
|
111
|
-
}
|
|
112
|
-
function _(i) {
|
|
113
|
-
for (var t = i.s; t !== void 0; t = t.n) if (t.S.i !== t.i || !t.S.h() || t.S.i !== t.i) return !0;
|
|
114
|
-
return !1;
|
|
1
|
+
function k() {
|
|
2
|
+
return h("");
|
|
115
3
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
4
|
+
function h(i) {
|
|
5
|
+
return new Proxy({}, {
|
|
6
|
+
get(t, e) {
|
|
7
|
+
if (typeof e == "symbol")
|
|
8
|
+
return;
|
|
9
|
+
if (e === "__path" || e === "__fieldPath")
|
|
10
|
+
return i || e;
|
|
11
|
+
if (e === "__key") {
|
|
12
|
+
const a = i.split(".");
|
|
13
|
+
return a[a.length - 1] || e;
|
|
14
|
+
}
|
|
15
|
+
if (e === "then" || e === "catch" || e === "finally" || e === "constructor" || e === "toString" || e === "valueOf" || e === "toJSON")
|
|
16
|
+
return;
|
|
17
|
+
const r = i ? `${i}.${e}` : e, s = {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
__key: e,
|
|
20
|
+
__path: r,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
__formType: void 0,
|
|
23
|
+
__fieldType: void 0
|
|
24
|
+
};
|
|
25
|
+
return new Proxy(s, {
|
|
26
|
+
get(a, n) {
|
|
27
|
+
if (typeof n != "symbol") {
|
|
28
|
+
if (n === "__path" || n === "__fieldPath") return r;
|
|
29
|
+
if (n === "__key") return e;
|
|
30
|
+
if (n !== "__formType" && n !== "__fieldType" && !(n === "then" || n === "catch" || n === "finally" || n === "constructor" || n === "toString" || n === "valueOf" || n === "toJSON"))
|
|
31
|
+
return h(`${r}.${n}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
122
35
|
}
|
|
123
|
-
}
|
|
36
|
+
});
|
|
124
37
|
}
|
|
125
|
-
function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
38
|
+
function y(i) {
|
|
39
|
+
if (typeof i == "string")
|
|
40
|
+
return i;
|
|
41
|
+
if (i && typeof i == "object") {
|
|
42
|
+
const t = i.__path;
|
|
43
|
+
if (typeof t == "string")
|
|
44
|
+
return t;
|
|
45
|
+
}
|
|
46
|
+
throw new Error("Invalid field path node: " + JSON.stringify(i));
|
|
131
47
|
}
|
|
132
|
-
function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
h.prototype = new c();
|
|
136
|
-
h.prototype.h = function() {
|
|
137
|
-
if (this.f &= -3, 1 & this.f) return !1;
|
|
138
|
-
if ((36 & this.f) == 32 || (this.f &= -5, this.g === y)) return !0;
|
|
139
|
-
if (this.g = y, this.f |= 1, this.i > 0 && !_(this))
|
|
140
|
-
return this.f &= -2, !0;
|
|
141
|
-
var i = r;
|
|
142
|
-
try {
|
|
143
|
-
b(this), r = this;
|
|
144
|
-
var t = this.x();
|
|
145
|
-
(16 & this.f || this.v !== t || this.i === 0) && (this.v = t, this.f &= -17, this.i++);
|
|
146
|
-
} catch (e) {
|
|
147
|
-
this.v = e, this.f |= 16, this.i++;
|
|
148
|
-
}
|
|
149
|
-
return r = i, V(this), this.f &= -2, !0;
|
|
150
|
-
};
|
|
151
|
-
h.prototype.S = function(i) {
|
|
152
|
-
if (this.t === void 0) {
|
|
153
|
-
this.f |= 36;
|
|
154
|
-
for (var t = this.s; t !== void 0; t = t.n) t.S.S(t);
|
|
155
|
-
}
|
|
156
|
-
c.prototype.S.call(this, i);
|
|
157
|
-
};
|
|
158
|
-
h.prototype.U = function(i) {
|
|
159
|
-
if (this.t !== void 0 && (c.prototype.U.call(this, i), this.t === void 0)) {
|
|
160
|
-
this.f &= -33;
|
|
161
|
-
for (var t = this.s; t !== void 0; t = t.n) t.S.U(t);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
h.prototype.N = function() {
|
|
165
|
-
if (!(2 & this.f)) {
|
|
166
|
-
this.f |= 6;
|
|
167
|
-
for (var i = this.t; i !== void 0; i = i.x) i.t.N();
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
Object.defineProperty(h.prototype, "value", { get: function() {
|
|
171
|
-
if (1 & this.f) throw new Error("Cycle detected");
|
|
172
|
-
var i = k(this);
|
|
173
|
-
if (this.h(), i !== void 0 && (i.i = this.i), 16 & this.f) throw this.v;
|
|
174
|
-
return this.v;
|
|
175
|
-
} });
|
|
176
|
-
function B(i, t) {
|
|
177
|
-
return new h(i, t);
|
|
178
|
-
}
|
|
179
|
-
function E(i) {
|
|
180
|
-
var t = i.u;
|
|
181
|
-
if (i.u = void 0, typeof t == "function") {
|
|
182
|
-
d++;
|
|
183
|
-
var e = r;
|
|
184
|
-
r = void 0;
|
|
185
|
-
try {
|
|
186
|
-
t();
|
|
187
|
-
} catch (n) {
|
|
188
|
-
throw i.f &= -2, i.f |= 8, S(i), n;
|
|
189
|
-
} finally {
|
|
190
|
-
r = e, w();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
48
|
+
function C(i) {
|
|
49
|
+
const t = y(i);
|
|
50
|
+
return h(t);
|
|
193
51
|
}
|
|
194
52
|
function S(i) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
V(this), r = i, this.f &= -2, 8 & this.f && S(this), w();
|
|
201
|
-
}
|
|
202
|
-
function u(i, t) {
|
|
203
|
-
this.x = i, this.u = void 0, this.s = void 0, this.o = void 0, this.f = 32, this.name = t?.name;
|
|
204
|
-
}
|
|
205
|
-
u.prototype.c = function() {
|
|
206
|
-
var i = this.S();
|
|
207
|
-
try {
|
|
208
|
-
if (8 & this.f || this.x === void 0) return;
|
|
209
|
-
var t = this.x();
|
|
210
|
-
typeof t == "function" && (this.u = t);
|
|
211
|
-
} finally {
|
|
212
|
-
i();
|
|
53
|
+
if (i && typeof i == "object" && "__key" in i)
|
|
54
|
+
return i.__key;
|
|
55
|
+
if (typeof i == "string") {
|
|
56
|
+
const t = i.split(".");
|
|
57
|
+
return t[t.length - 1];
|
|
213
58
|
}
|
|
214
|
-
|
|
215
|
-
u.prototype.S = function() {
|
|
216
|
-
if (1 & this.f) throw new Error("Cycle detected");
|
|
217
|
-
this.f |= 1, this.f &= -9, E(this), b(this), d++;
|
|
218
|
-
var i = r;
|
|
219
|
-
return r = this, A.bind(this, i);
|
|
220
|
-
};
|
|
221
|
-
u.prototype.N = function() {
|
|
222
|
-
2 & this.f || (this.f |= 2, this.o = l, l = this);
|
|
223
|
-
};
|
|
224
|
-
u.prototype.d = function() {
|
|
225
|
-
this.f |= 8, 1 & this.f || S(this);
|
|
226
|
-
};
|
|
227
|
-
u.prototype.dispose = function() {
|
|
228
|
-
this.d();
|
|
229
|
-
};
|
|
230
|
-
function F(i, t) {
|
|
231
|
-
var e = new u(i, t);
|
|
232
|
-
try {
|
|
233
|
-
e.c();
|
|
234
|
-
} catch (o) {
|
|
235
|
-
throw e.d(), o;
|
|
236
|
-
}
|
|
237
|
-
var n = e.d.bind(e);
|
|
238
|
-
return n[Symbol.dispose] = n, n;
|
|
59
|
+
throw new Error("Invalid field path node");
|
|
239
60
|
}
|
|
240
|
-
class
|
|
61
|
+
class d {
|
|
241
62
|
stack = [];
|
|
242
63
|
/**
|
|
243
64
|
* Добавить элемент в стек
|
|
@@ -291,7 +112,7 @@ class R {
|
|
|
291
112
|
this.stack = [];
|
|
292
113
|
}
|
|
293
114
|
}
|
|
294
|
-
class
|
|
115
|
+
class x {
|
|
295
116
|
validators = [];
|
|
296
117
|
conditionStack = [];
|
|
297
118
|
/**
|
|
@@ -323,12 +144,12 @@ class I {
|
|
|
323
144
|
return this.validators;
|
|
324
145
|
}
|
|
325
146
|
}
|
|
326
|
-
class
|
|
147
|
+
class o {
|
|
327
148
|
/**
|
|
328
149
|
* Global stack активных реестров
|
|
329
150
|
* Используется для изоляции форм друг от друга
|
|
330
151
|
*/
|
|
331
|
-
static registryStack = new
|
|
152
|
+
static registryStack = new d();
|
|
332
153
|
contextStack = [];
|
|
333
154
|
validators = [];
|
|
334
155
|
/**
|
|
@@ -348,7 +169,7 @@ class f {
|
|
|
348
169
|
* ```
|
|
349
170
|
*/
|
|
350
171
|
static getCurrent() {
|
|
351
|
-
return
|
|
172
|
+
return o.registryStack.getCurrent();
|
|
352
173
|
}
|
|
353
174
|
/**
|
|
354
175
|
* Начать регистрацию валидаторов для формы
|
|
@@ -356,8 +177,8 @@ class f {
|
|
|
356
177
|
* Помещает this в global stack для изоляции форм
|
|
357
178
|
*/
|
|
358
179
|
beginRegistration() {
|
|
359
|
-
const t = new
|
|
360
|
-
return this.contextStack.push(t),
|
|
180
|
+
const t = new x();
|
|
181
|
+
return this.contextStack.push(t), o.registryStack.push(this), t;
|
|
361
182
|
}
|
|
362
183
|
/**
|
|
363
184
|
* Завершить регистрацию и применить валидаторы к GroupNode
|
|
@@ -370,7 +191,7 @@ class f {
|
|
|
370
191
|
const e = this.contextStack.pop();
|
|
371
192
|
if (!e)
|
|
372
193
|
throw new Error("No active registration context");
|
|
373
|
-
|
|
194
|
+
o.registryStack.verify(this, "ValidationRegistry"), this.validators = e.getValidators(), this.applyValidators(t, this.validators), this.applyArrayItemValidators(t, this.validators);
|
|
374
195
|
}
|
|
375
196
|
/**
|
|
376
197
|
* Отменить регистрацию без применения валидаторов
|
|
@@ -381,7 +202,7 @@ class f {
|
|
|
381
202
|
cancelRegistration() {
|
|
382
203
|
if (!this.contextStack.pop())
|
|
383
204
|
throw new Error("No active registration context to cancel");
|
|
384
|
-
|
|
205
|
+
o.registryStack.verify(this, "ValidationRegistry");
|
|
385
206
|
}
|
|
386
207
|
/**
|
|
387
208
|
* Получить текущий контекст регистрации
|
|
@@ -392,39 +213,39 @@ class f {
|
|
|
392
213
|
/**
|
|
393
214
|
* Зарегистрировать синхронный валидатор
|
|
394
215
|
*/
|
|
395
|
-
registerSync(t, e,
|
|
396
|
-
const
|
|
397
|
-
if (!
|
|
216
|
+
registerSync(t, e, r) {
|
|
217
|
+
const s = this.getCurrentContext();
|
|
218
|
+
if (!s)
|
|
398
219
|
throw new Error("Validators can only be registered inside a validation schema function");
|
|
399
|
-
|
|
220
|
+
s.addValidator({
|
|
400
221
|
fieldPath: t,
|
|
401
222
|
type: "sync",
|
|
402
223
|
validator: e,
|
|
403
|
-
options:
|
|
224
|
+
options: r
|
|
404
225
|
});
|
|
405
226
|
}
|
|
406
227
|
/**
|
|
407
228
|
* Зарегистрировать асинхронный валидатор
|
|
408
229
|
*/
|
|
409
|
-
registerAsync(t, e,
|
|
410
|
-
const
|
|
411
|
-
if (!
|
|
230
|
+
registerAsync(t, e, r) {
|
|
231
|
+
const s = this.getCurrentContext();
|
|
232
|
+
if (!s)
|
|
412
233
|
throw new Error("Validators can only be registered inside a validation schema function");
|
|
413
|
-
|
|
234
|
+
s.addValidator({
|
|
414
235
|
fieldPath: t,
|
|
415
236
|
type: "async",
|
|
416
237
|
validator: e,
|
|
417
|
-
options:
|
|
238
|
+
options: r
|
|
418
239
|
});
|
|
419
240
|
}
|
|
420
241
|
/**
|
|
421
242
|
* Зарегистрировать tree валидатор
|
|
422
243
|
*/
|
|
423
244
|
registerTree(t, e) {
|
|
424
|
-
const
|
|
425
|
-
if (!
|
|
245
|
+
const r = this.getCurrentContext();
|
|
246
|
+
if (!r)
|
|
426
247
|
throw new Error("Validators can only be registered inside a validation schema function");
|
|
427
|
-
|
|
248
|
+
r.addValidator({
|
|
428
249
|
fieldPath: e?.targetField || "__tree__",
|
|
429
250
|
type: "tree",
|
|
430
251
|
validator: t,
|
|
@@ -435,10 +256,10 @@ class f {
|
|
|
435
256
|
* Войти в условный блок
|
|
436
257
|
*/
|
|
437
258
|
enterCondition(t, e) {
|
|
438
|
-
const
|
|
439
|
-
if (!
|
|
259
|
+
const r = this.getCurrentContext();
|
|
260
|
+
if (!r)
|
|
440
261
|
throw new Error("Conditions can only be used inside a validation schema function");
|
|
441
|
-
|
|
262
|
+
r.enterCondition(t, e);
|
|
442
263
|
}
|
|
443
264
|
/**
|
|
444
265
|
* Выйти из условного блока
|
|
@@ -459,12 +280,12 @@ class f {
|
|
|
459
280
|
* @param itemSchemaFn - Validation schema для элемента массива
|
|
460
281
|
*/
|
|
461
282
|
registerArrayItemValidation(t, e) {
|
|
462
|
-
const
|
|
463
|
-
if (!
|
|
283
|
+
const r = this.getCurrentContext();
|
|
284
|
+
if (!r)
|
|
464
285
|
throw new Error(
|
|
465
286
|
"Array item validators can only be registered inside a validation schema function"
|
|
466
287
|
);
|
|
467
|
-
|
|
288
|
+
r.addValidator({
|
|
468
289
|
fieldPath: t,
|
|
469
290
|
type: "array-items",
|
|
470
291
|
validator: e,
|
|
@@ -485,12 +306,12 @@ class f {
|
|
|
485
306
|
* @private
|
|
486
307
|
*/
|
|
487
308
|
applyValidators(t, e) {
|
|
488
|
-
const
|
|
489
|
-
for (const
|
|
490
|
-
if (
|
|
309
|
+
const r = /* @__PURE__ */ new Map();
|
|
310
|
+
for (const s of e) {
|
|
311
|
+
if (s.type === "tree" || s.type === "array-items")
|
|
491
312
|
continue;
|
|
492
|
-
const a =
|
|
493
|
-
a.push(
|
|
313
|
+
const a = r.get(s.fieldPath) || [];
|
|
314
|
+
a.push(s), r.set(s.fieldPath, a);
|
|
494
315
|
}
|
|
495
316
|
}
|
|
496
317
|
/**
|
|
@@ -498,18 +319,18 @@ class f {
|
|
|
498
319
|
* @private
|
|
499
320
|
*/
|
|
500
321
|
applyArrayItemValidators(t, e) {
|
|
501
|
-
const
|
|
502
|
-
if (
|
|
503
|
-
for (const
|
|
504
|
-
const a = t[
|
|
322
|
+
const r = e.filter((s) => s.type === "array-items");
|
|
323
|
+
if (r.length !== 0)
|
|
324
|
+
for (const s of r) {
|
|
325
|
+
const a = t[s.fieldPath.split(".")[0]];
|
|
505
326
|
if (a && "applyValidationSchema" in a) {
|
|
506
|
-
const
|
|
507
|
-
a.applyValidationSchema(
|
|
327
|
+
const n = s.validator;
|
|
328
|
+
a.applyValidationSchema(n);
|
|
508
329
|
}
|
|
509
330
|
}
|
|
510
331
|
}
|
|
511
332
|
}
|
|
512
|
-
class
|
|
333
|
+
class v {
|
|
513
334
|
/**
|
|
514
335
|
* Форма с типизированным Proxy-доступом к полям
|
|
515
336
|
*/
|
|
@@ -521,21 +342,24 @@ class U {
|
|
|
521
342
|
this.form = e;
|
|
522
343
|
}
|
|
523
344
|
/**
|
|
524
|
-
* Безопасно установить значение поля по строковому пути
|
|
345
|
+
* Безопасно установить значение поля по строковому пути или FieldPath
|
|
525
346
|
*
|
|
526
347
|
* Автоматически использует emitEvent: false для предотвращения циклов
|
|
348
|
+
*
|
|
349
|
+
* @param path - Строковый путь к полю или FieldPath объект
|
|
350
|
+
* @param value - Новое значение
|
|
527
351
|
*/
|
|
528
352
|
setFieldValue(t, e) {
|
|
529
|
-
const
|
|
530
|
-
|
|
353
|
+
const r = typeof t == "string" ? t : t.toString(), s = this._form.getFieldByPath(r);
|
|
354
|
+
s && s.setValue(e, { emitEvent: !1 });
|
|
531
355
|
}
|
|
532
356
|
}
|
|
533
|
-
class
|
|
357
|
+
class c {
|
|
534
358
|
/**
|
|
535
359
|
* Stack активных контекстов регистрации
|
|
536
360
|
* Используется для изоляции форм друг от друга
|
|
537
361
|
*/
|
|
538
|
-
static contextStack = new
|
|
362
|
+
static contextStack = new d();
|
|
539
363
|
registrations = [];
|
|
540
364
|
isRegistering = !1;
|
|
541
365
|
/**
|
|
@@ -555,7 +379,7 @@ class v {
|
|
|
555
379
|
* ```
|
|
556
380
|
*/
|
|
557
381
|
static getCurrent() {
|
|
558
|
-
return
|
|
382
|
+
return c.contextStack.getCurrent();
|
|
559
383
|
}
|
|
560
384
|
/**
|
|
561
385
|
* Начать регистрацию behaviors
|
|
@@ -564,7 +388,7 @@ class v {
|
|
|
564
388
|
* Помещает this в context stack для изоляции форм
|
|
565
389
|
*/
|
|
566
390
|
beginRegistration() {
|
|
567
|
-
this.isRegistering = !0, this.registrations = [],
|
|
391
|
+
this.isRegistering = !0, this.registrations = [], c.contextStack.push(this);
|
|
568
392
|
}
|
|
569
393
|
/**
|
|
570
394
|
* Зарегистрировать behavior handler
|
|
@@ -597,39 +421,39 @@ class v {
|
|
|
597
421
|
* @returns Количество зарегистрированных behaviors и функция cleanup
|
|
598
422
|
*/
|
|
599
423
|
endRegistration(t) {
|
|
600
|
-
this.isRegistering = !1,
|
|
601
|
-
const e = new
|
|
424
|
+
this.isRegistering = !1, c.contextStack.verify(this, "BehaviorRegistry");
|
|
425
|
+
const e = new v(t), r = [];
|
|
602
426
|
for (const a of this.registrations) {
|
|
603
|
-
const
|
|
604
|
-
|
|
427
|
+
const n = this.createEffect(a, t, e);
|
|
428
|
+
n && r.push(n);
|
|
605
429
|
}
|
|
606
|
-
const
|
|
607
|
-
|
|
430
|
+
const s = () => {
|
|
431
|
+
r.forEach((a) => a());
|
|
608
432
|
};
|
|
609
433
|
return {
|
|
610
434
|
count: this.registrations.length,
|
|
611
|
-
cleanup:
|
|
435
|
+
cleanup: s
|
|
612
436
|
};
|
|
613
437
|
}
|
|
614
438
|
/**
|
|
615
439
|
* Создать effect подписку для behavior
|
|
616
440
|
* @private
|
|
617
441
|
*/
|
|
618
|
-
createEffect(t, e,
|
|
619
|
-
const { handler:
|
|
620
|
-
let
|
|
621
|
-
const
|
|
622
|
-
a > 0 ? (
|
|
623
|
-
},
|
|
624
|
-
|
|
625
|
-
},
|
|
626
|
-
return
|
|
627
|
-
|
|
442
|
+
createEffect(t, e, r) {
|
|
443
|
+
const { handler: s, debounce: a = 0 } = t;
|
|
444
|
+
let n = null;
|
|
445
|
+
const f = (u) => {
|
|
446
|
+
a > 0 ? (n && clearTimeout(n), n = setTimeout(u, a)) : u();
|
|
447
|
+
}, g = () => {
|
|
448
|
+
n && (clearTimeout(n), n = null);
|
|
449
|
+
}, l = s(e, r, f);
|
|
450
|
+
return l ? () => {
|
|
451
|
+
g(), l && l();
|
|
628
452
|
} : null;
|
|
629
453
|
}
|
|
630
454
|
}
|
|
631
|
-
function
|
|
632
|
-
const i =
|
|
455
|
+
function _() {
|
|
456
|
+
const i = o.getCurrent();
|
|
633
457
|
return i || {
|
|
634
458
|
registerSync: () => {
|
|
635
459
|
},
|
|
@@ -645,60 +469,22 @@ function $() {
|
|
|
645
469
|
}
|
|
646
470
|
};
|
|
647
471
|
}
|
|
648
|
-
function
|
|
649
|
-
const i =
|
|
472
|
+
function m() {
|
|
473
|
+
const i = c.getCurrent();
|
|
650
474
|
return i || {
|
|
651
475
|
register: () => {
|
|
652
476
|
}
|
|
653
477
|
};
|
|
654
478
|
}
|
|
655
|
-
function W() {
|
|
656
|
-
return T("");
|
|
657
|
-
}
|
|
658
|
-
function T(i) {
|
|
659
|
-
return new Proxy(
|
|
660
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
661
|
-
{},
|
|
662
|
-
{
|
|
663
|
-
get(t, e) {
|
|
664
|
-
if (e === "__path" || e === "__fieldPath")
|
|
665
|
-
return i || e;
|
|
666
|
-
if (e === "__key") {
|
|
667
|
-
const a = i.split(".");
|
|
668
|
-
return a[a.length - 1] || e;
|
|
669
|
-
}
|
|
670
|
-
const n = i ? `${i}.${e}` : e, o = {
|
|
671
|
-
__path: n,
|
|
672
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
673
|
-
__key: e,
|
|
674
|
-
__formType: void 0,
|
|
675
|
-
__fieldType: void 0
|
|
676
|
-
};
|
|
677
|
-
return new Proxy(o, {
|
|
678
|
-
get(a, s) {
|
|
679
|
-
if (s === "__path" || s === "__fieldPath")
|
|
680
|
-
return n;
|
|
681
|
-
if (s === "__key")
|
|
682
|
-
return e;
|
|
683
|
-
if (s === "__formType" || s === "__fieldType")
|
|
684
|
-
return;
|
|
685
|
-
const p = `${n}.${s}`;
|
|
686
|
-
return T(p);
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
);
|
|
692
|
-
}
|
|
693
479
|
export {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
480
|
+
c as B,
|
|
481
|
+
d as R,
|
|
482
|
+
o as V,
|
|
483
|
+
S as a,
|
|
484
|
+
m as b,
|
|
485
|
+
k as c,
|
|
486
|
+
v as d,
|
|
487
|
+
y as e,
|
|
488
|
+
_ as g,
|
|
489
|
+
C as t
|
|
704
490
|
};
|