@reformer/core 1.1.0-beta.3 → 1.1.0-beta.4
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.js +2 -2
- package/dist/core/behavior/behavior-context.d.ts +6 -2
- package/dist/core/behavior/behavior-context.js +7 -2
- package/dist/core/types/form-context.d.ts +10 -4
- package/dist/{create-field-path-CdPF3lIK.js → create-field-path-DcXDTWil.js} +61 -58
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/{node-factory-D7DOnSSN.js → node-factory-DYXIgJmW.js} +106 -89
- package/dist/validators.js +104 -119
- package/llms.txt +241 -2
- package/package.json +1 -1
package/dist/behaviors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as y, E as p, c as b } from "./create-field-path-
|
|
2
|
-
import { b as M, B as T } from "./create-field-path-
|
|
1
|
+
import { a as y, E as p, c as b } from "./create-field-path-DcXDTWil.js";
|
|
2
|
+
import { b as M, B as T } from "./create-field-path-DcXDTWil.js";
|
|
3
3
|
function v(e, t, r) {
|
|
4
4
|
const { debounce: a, immediate: s = !1 } = r || {}, l = (u, i, c) => {
|
|
5
5
|
const o = u.getFieldByPath(e.__path);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import type { GroupNode } from '../nodes/group-node';
|
|
7
7
|
import type { GroupNodeWithControls } from '../types/group-node-proxy';
|
|
8
8
|
import type { FormContext } from '../types/form-context';
|
|
9
|
+
import type { FieldPathNode } from '../types/field-path';
|
|
9
10
|
/**
|
|
10
11
|
* Реализация BehaviorContext (FormContext)
|
|
11
12
|
*
|
|
@@ -21,9 +22,12 @@ export declare class BehaviorContextImpl<TForm> implements FormContext<TForm> {
|
|
|
21
22
|
private _form;
|
|
22
23
|
constructor(form: GroupNode<TForm>);
|
|
23
24
|
/**
|
|
24
|
-
* Безопасно установить значение поля по строковому пути
|
|
25
|
+
* Безопасно установить значение поля по строковому пути или FieldPath
|
|
25
26
|
*
|
|
26
27
|
* Автоматически использует emitEvent: false для предотвращения циклов
|
|
28
|
+
*
|
|
29
|
+
* @param path - Строковый путь к полю или FieldPath объект
|
|
30
|
+
* @param value - Новое значение
|
|
27
31
|
*/
|
|
28
|
-
setFieldValue(path: string, value: unknown): void;
|
|
32
|
+
setFieldValue(path: string | FieldPathNode<TForm, unknown>, value: unknown): void;
|
|
29
33
|
}
|
|
@@ -24,12 +24,17 @@ export class BehaviorContextImpl {
|
|
|
24
24
|
this.form = proxy;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Безопасно установить значение поля по строковому пути
|
|
27
|
+
* Безопасно установить значение поля по строковому пути или FieldPath
|
|
28
28
|
*
|
|
29
29
|
* Автоматически использует emitEvent: false для предотвращения циклов
|
|
30
|
+
*
|
|
31
|
+
* @param path - Строковый путь к полю или FieldPath объект
|
|
32
|
+
* @param value - Новое значение
|
|
30
33
|
*/
|
|
31
34
|
setFieldValue(path, value) {
|
|
32
|
-
|
|
35
|
+
// Преобразуем FieldPath в строку если необходимо
|
|
36
|
+
const pathStr = typeof path === 'string' ? path : path.toString();
|
|
37
|
+
const node = this._form.getFieldByPath(pathStr);
|
|
33
38
|
if (node) {
|
|
34
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
40
|
node.setValue(value, { emitEvent: false });
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
import type { GroupNodeWithControls } from './group-node-proxy';
|
|
26
|
+
import type { FieldPathNode } from './field-path';
|
|
26
27
|
/**
|
|
27
28
|
* Единый контекст для работы с формой
|
|
28
29
|
*
|
|
@@ -63,21 +64,26 @@ export interface FormContext<TForm> {
|
|
|
63
64
|
*/
|
|
64
65
|
readonly form: GroupNodeWithControls<TForm>;
|
|
65
66
|
/**
|
|
66
|
-
* Безопасно установить значение поля по строковому пути
|
|
67
|
+
* Безопасно установить значение поля по строковому пути или FieldPath
|
|
67
68
|
*
|
|
68
69
|
* Автоматически использует `emitEvent: false` для предотвращения
|
|
69
70
|
* бесконечных циклов в behavior схемах.
|
|
70
71
|
*
|
|
71
|
-
* @param path - Путь к полю (
|
|
72
|
+
* @param path - Путь к полю (строка или FieldPath)
|
|
72
73
|
* @param value - Новое значение
|
|
73
74
|
*
|
|
74
75
|
* @example
|
|
75
76
|
* ```typescript
|
|
76
|
-
* // Сброс города при смене страны
|
|
77
|
+
* // Сброс города при смене страны (строковый путь)
|
|
77
78
|
* watchField(path.country, (country, ctx) => {
|
|
78
79
|
* ctx.setFieldValue('city', null);
|
|
79
80
|
* });
|
|
81
|
+
*
|
|
82
|
+
* // Использование FieldPath напрямую (более типобезопасно)
|
|
83
|
+
* watchField(path.country, (country, ctx) => {
|
|
84
|
+
* ctx.setFieldValue(path.city, null);
|
|
85
|
+
* });
|
|
80
86
|
* ```
|
|
81
87
|
*/
|
|
82
|
-
setFieldValue(path: string, value: unknown): void;
|
|
88
|
+
setFieldValue(path: string | FieldPathNode<TForm, unknown>, value: unknown): void;
|
|
83
89
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var P = Symbol.for("preact-signals");
|
|
2
|
-
function
|
|
2
|
+
function S() {
|
|
3
3
|
if (d > 1)
|
|
4
4
|
d--;
|
|
5
5
|
else {
|
|
@@ -9,8 +9,8 @@ function w() {
|
|
|
9
9
|
var n = e.o;
|
|
10
10
|
if (e.o = void 0, e.f &= -3, !(8 & e.f) && _(e)) try {
|
|
11
11
|
e.c();
|
|
12
|
-
} catch (
|
|
13
|
-
t || (i =
|
|
12
|
+
} catch (r) {
|
|
13
|
+
t || (i = r, t = !0);
|
|
14
14
|
}
|
|
15
15
|
e = n;
|
|
16
16
|
}
|
|
@@ -18,24 +18,24 @@ function w() {
|
|
|
18
18
|
if (x = 0, d--, t) throw i;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
var
|
|
21
|
+
var o = void 0;
|
|
22
22
|
function C(i) {
|
|
23
|
-
var t =
|
|
24
|
-
|
|
23
|
+
var t = o;
|
|
24
|
+
o = void 0;
|
|
25
25
|
try {
|
|
26
26
|
return i();
|
|
27
27
|
} finally {
|
|
28
|
-
|
|
28
|
+
o = t;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
var l = void 0, d = 0, x = 0, y = 0;
|
|
32
32
|
function k(i) {
|
|
33
|
-
if (
|
|
33
|
+
if (o !== void 0) {
|
|
34
34
|
var t = i.n;
|
|
35
|
-
if (t === void 0 || t.t !==
|
|
36
|
-
return t = { i: 0, S: i, p:
|
|
35
|
+
if (t === void 0 || t.t !== o)
|
|
36
|
+
return t = { i: 0, S: i, p: o.s, n: void 0, t: o, e: void 0, x: void 0, r: t }, o.s !== void 0 && (o.s.n = t), o.s = t, i.n = t, 32 & o.f && i.S(t), t;
|
|
37
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 =
|
|
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 = o.s, t.n = void 0, o.s.n = t, o.s = t), t;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
function c(i, t) {
|
|
@@ -57,20 +57,20 @@ c.prototype.U = function(i) {
|
|
|
57
57
|
if (this.t !== void 0) {
|
|
58
58
|
var e = i.e, n = i.x;
|
|
59
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
|
|
61
|
-
(
|
|
60
|
+
var r;
|
|
61
|
+
(r = t.Z) == null || r.call(t);
|
|
62
62
|
}));
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
c.prototype.subscribe = function(i) {
|
|
66
66
|
var t = this;
|
|
67
67
|
return F(function() {
|
|
68
|
-
var e = t.value, n =
|
|
69
|
-
|
|
68
|
+
var e = t.value, n = o;
|
|
69
|
+
o = void 0;
|
|
70
70
|
try {
|
|
71
71
|
i(e);
|
|
72
72
|
} finally {
|
|
73
|
-
|
|
73
|
+
o = n;
|
|
74
74
|
}
|
|
75
75
|
}, { name: "sub" });
|
|
76
76
|
};
|
|
@@ -84,12 +84,12 @@ c.prototype.toJSON = function() {
|
|
|
84
84
|
return this.value;
|
|
85
85
|
};
|
|
86
86
|
c.prototype.peek = function() {
|
|
87
|
-
var i =
|
|
88
|
-
|
|
87
|
+
var i = o;
|
|
88
|
+
o = void 0;
|
|
89
89
|
try {
|
|
90
90
|
return this.value;
|
|
91
91
|
} finally {
|
|
92
|
-
|
|
92
|
+
o = i;
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
Object.defineProperty(c.prototype, "value", { get: function() {
|
|
@@ -102,7 +102,7 @@ Object.defineProperty(c.prototype, "value", { get: function() {
|
|
|
102
102
|
try {
|
|
103
103
|
for (var t = this.t; t !== void 0; t = t.x) t.t.N();
|
|
104
104
|
} finally {
|
|
105
|
-
|
|
105
|
+
S();
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
} });
|
|
@@ -138,15 +138,15 @@ h.prototype.h = function() {
|
|
|
138
138
|
if ((36 & this.f) == 32 || (this.f &= -5, this.g === y)) return !0;
|
|
139
139
|
if (this.g = y, this.f |= 1, this.i > 0 && !_(this))
|
|
140
140
|
return this.f &= -2, !0;
|
|
141
|
-
var i =
|
|
141
|
+
var i = o;
|
|
142
142
|
try {
|
|
143
|
-
b(this),
|
|
143
|
+
b(this), o = this;
|
|
144
144
|
var t = this.x();
|
|
145
145
|
(16 & this.f || this.v !== t || this.i === 0) && (this.v = t, this.f &= -17, this.i++);
|
|
146
146
|
} catch (e) {
|
|
147
147
|
this.v = e, this.f |= 16, this.i++;
|
|
148
148
|
}
|
|
149
|
-
return
|
|
149
|
+
return o = i, V(this), this.f &= -2, !0;
|
|
150
150
|
};
|
|
151
151
|
h.prototype.S = function(i) {
|
|
152
152
|
if (this.t === void 0) {
|
|
@@ -180,24 +180,24 @@ function E(i) {
|
|
|
180
180
|
var t = i.u;
|
|
181
181
|
if (i.u = void 0, typeof t == "function") {
|
|
182
182
|
d++;
|
|
183
|
-
var e =
|
|
184
|
-
|
|
183
|
+
var e = o;
|
|
184
|
+
o = void 0;
|
|
185
185
|
try {
|
|
186
186
|
t();
|
|
187
187
|
} catch (n) {
|
|
188
|
-
throw i.f &= -2, i.f |= 8,
|
|
188
|
+
throw i.f &= -2, i.f |= 8, w(i), n;
|
|
189
189
|
} finally {
|
|
190
|
-
|
|
190
|
+
o = e, S();
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function w(i) {
|
|
195
195
|
for (var t = i.s; t !== void 0; t = t.n) t.S.U(t);
|
|
196
196
|
i.x = void 0, i.s = void 0, E(i);
|
|
197
197
|
}
|
|
198
198
|
function A(i) {
|
|
199
|
-
if (
|
|
200
|
-
V(this),
|
|
199
|
+
if (o !== this) throw new Error("Out-of-order effect");
|
|
200
|
+
V(this), o = i, this.f &= -2, 8 & this.f && w(this), S();
|
|
201
201
|
}
|
|
202
202
|
function u(i, t) {
|
|
203
203
|
this.x = i, this.u = void 0, this.s = void 0, this.o = void 0, this.f = 32, this.name = t?.name;
|
|
@@ -215,14 +215,14 @@ u.prototype.c = function() {
|
|
|
215
215
|
u.prototype.S = function() {
|
|
216
216
|
if (1 & this.f) throw new Error("Cycle detected");
|
|
217
217
|
this.f |= 1, this.f &= -9, E(this), b(this), d++;
|
|
218
|
-
var i =
|
|
219
|
-
return
|
|
218
|
+
var i = o;
|
|
219
|
+
return o = this, A.bind(this, i);
|
|
220
220
|
};
|
|
221
221
|
u.prototype.N = function() {
|
|
222
222
|
2 & this.f || (this.f |= 2, this.o = l, l = this);
|
|
223
223
|
};
|
|
224
224
|
u.prototype.d = function() {
|
|
225
|
-
this.f |= 8, 1 & this.f ||
|
|
225
|
+
this.f |= 8, 1 & this.f || w(this);
|
|
226
226
|
};
|
|
227
227
|
u.prototype.dispose = function() {
|
|
228
228
|
this.d();
|
|
@@ -231,8 +231,8 @@ function F(i, t) {
|
|
|
231
231
|
var e = new u(i, t);
|
|
232
232
|
try {
|
|
233
233
|
e.c();
|
|
234
|
-
} catch (
|
|
235
|
-
throw e.d(),
|
|
234
|
+
} catch (r) {
|
|
235
|
+
throw e.d(), r;
|
|
236
236
|
}
|
|
237
237
|
var n = e.d.bind(e);
|
|
238
238
|
return n[Symbol.dispose] = n, n;
|
|
@@ -393,10 +393,10 @@ class f {
|
|
|
393
393
|
* Зарегистрировать синхронный валидатор
|
|
394
394
|
*/
|
|
395
395
|
registerSync(t, e, n) {
|
|
396
|
-
const
|
|
397
|
-
if (!
|
|
396
|
+
const r = this.getCurrentContext();
|
|
397
|
+
if (!r)
|
|
398
398
|
throw new Error("Validators can only be registered inside a validation schema function");
|
|
399
|
-
|
|
399
|
+
r.addValidator({
|
|
400
400
|
fieldPath: t,
|
|
401
401
|
type: "sync",
|
|
402
402
|
validator: e,
|
|
@@ -407,10 +407,10 @@ class f {
|
|
|
407
407
|
* Зарегистрировать асинхронный валидатор
|
|
408
408
|
*/
|
|
409
409
|
registerAsync(t, e, n) {
|
|
410
|
-
const
|
|
411
|
-
if (!
|
|
410
|
+
const r = this.getCurrentContext();
|
|
411
|
+
if (!r)
|
|
412
412
|
throw new Error("Validators can only be registered inside a validation schema function");
|
|
413
|
-
|
|
413
|
+
r.addValidator({
|
|
414
414
|
fieldPath: t,
|
|
415
415
|
type: "async",
|
|
416
416
|
validator: e,
|
|
@@ -486,11 +486,11 @@ class f {
|
|
|
486
486
|
*/
|
|
487
487
|
applyValidators(t, e) {
|
|
488
488
|
const n = /* @__PURE__ */ new Map();
|
|
489
|
-
for (const
|
|
490
|
-
if (
|
|
489
|
+
for (const r of e) {
|
|
490
|
+
if (r.type === "tree" || r.type === "array-items")
|
|
491
491
|
continue;
|
|
492
|
-
const a = n.get(
|
|
493
|
-
a.push(
|
|
492
|
+
const a = n.get(r.fieldPath) || [];
|
|
493
|
+
a.push(r), n.set(r.fieldPath, a);
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
/**
|
|
@@ -498,12 +498,12 @@ class f {
|
|
|
498
498
|
* @private
|
|
499
499
|
*/
|
|
500
500
|
applyArrayItemValidators(t, e) {
|
|
501
|
-
const n = e.filter((
|
|
501
|
+
const n = e.filter((r) => r.type === "array-items");
|
|
502
502
|
if (n.length !== 0)
|
|
503
|
-
for (const
|
|
504
|
-
const a = t[
|
|
503
|
+
for (const r of n) {
|
|
504
|
+
const a = t[r.fieldPath.split(".")[0]];
|
|
505
505
|
if (a && "applyValidationSchema" in a) {
|
|
506
|
-
const s =
|
|
506
|
+
const s = r.validator;
|
|
507
507
|
a.applyValidationSchema(s);
|
|
508
508
|
}
|
|
509
509
|
}
|
|
@@ -521,13 +521,16 @@ class U {
|
|
|
521
521
|
this.form = e;
|
|
522
522
|
}
|
|
523
523
|
/**
|
|
524
|
-
* Безопасно установить значение поля по строковому пути
|
|
524
|
+
* Безопасно установить значение поля по строковому пути или FieldPath
|
|
525
525
|
*
|
|
526
526
|
* Автоматически использует emitEvent: false для предотвращения циклов
|
|
527
|
+
*
|
|
528
|
+
* @param path - Строковый путь к полю или FieldPath объект
|
|
529
|
+
* @param value - Новое значение
|
|
527
530
|
*/
|
|
528
531
|
setFieldValue(t, e) {
|
|
529
|
-
const n = this._form.getFieldByPath(
|
|
530
|
-
|
|
532
|
+
const n = typeof t == "string" ? t : t.toString(), r = this._form.getFieldByPath(n);
|
|
533
|
+
r && r.setValue(e, { emitEvent: !1 });
|
|
531
534
|
}
|
|
532
535
|
}
|
|
533
536
|
class v {
|
|
@@ -603,12 +606,12 @@ class v {
|
|
|
603
606
|
const s = this.createEffect(a, t, e);
|
|
604
607
|
s && n.push(s);
|
|
605
608
|
}
|
|
606
|
-
const
|
|
609
|
+
const r = () => {
|
|
607
610
|
n.forEach((a) => a());
|
|
608
611
|
};
|
|
609
612
|
return {
|
|
610
613
|
count: this.registrations.length,
|
|
611
|
-
cleanup:
|
|
614
|
+
cleanup: r
|
|
612
615
|
};
|
|
613
616
|
}
|
|
614
617
|
/**
|
|
@@ -616,13 +619,13 @@ class v {
|
|
|
616
619
|
* @private
|
|
617
620
|
*/
|
|
618
621
|
createEffect(t, e, n) {
|
|
619
|
-
const { handler:
|
|
622
|
+
const { handler: r, debounce: a = 0 } = t;
|
|
620
623
|
let s = null;
|
|
621
624
|
const p = (m) => {
|
|
622
625
|
a > 0 ? (s && clearTimeout(s), s = setTimeout(m, a)) : m();
|
|
623
626
|
}, N = () => {
|
|
624
627
|
s && (clearTimeout(s), s = null);
|
|
625
|
-
}, g =
|
|
628
|
+
}, g = r(e, n, p);
|
|
626
629
|
return g ? () => {
|
|
627
630
|
N(), g && g();
|
|
628
631
|
} : null;
|
|
@@ -667,14 +670,14 @@ function T(i) {
|
|
|
667
670
|
const a = i.split(".");
|
|
668
671
|
return a[a.length - 1] || e;
|
|
669
672
|
}
|
|
670
|
-
const n = i ? `${i}.${e}` : e,
|
|
673
|
+
const n = i ? `${i}.${e}` : e, r = {
|
|
671
674
|
__path: n,
|
|
672
675
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
673
676
|
__key: e,
|
|
674
677
|
__formType: void 0,
|
|
675
678
|
__fieldType: void 0
|
|
676
679
|
};
|
|
677
|
-
return new Proxy(
|
|
680
|
+
return new Proxy(r, {
|
|
678
681
|
get(a, s) {
|
|
679
682
|
if (s === "__path" || s === "__fieldPath")
|
|
680
683
|
return n;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export { ArrayNode } from './core/nodes/array-node';
|
|
|
8
8
|
export type { SetValueOptions } from './core/nodes/form-node';
|
|
9
9
|
export { useFormControl, useFormControlValue } from './hooks/useFormControl';
|
|
10
10
|
export type { BehaviorSchemaFn } from './core/behavior/types';
|
|
11
|
+
export { validateForm } from './core/validation/validate-form';
|
package/dist/index.js
CHANGED
|
@@ -6,3 +6,5 @@ export { FieldNode } from './core/nodes/field-node';
|
|
|
6
6
|
export { GroupNode } from './core/nodes/group-node';
|
|
7
7
|
export { ArrayNode } from './core/nodes/array-node';
|
|
8
8
|
export { useFormControl, useFormControlValue } from './hooks/useFormControl';
|
|
9
|
+
// Utility for multi-step form validation
|
|
10
|
+
export { validateForm } from './core/validation/validate-form';
|