@reformer/core 10.1.0 → 11.0.0-beta.1
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-node-DUrqAqp1.js → behaviors-node-DGEFMTQu.js} +1 -1
- package/dist/{behaviors-value-lCpqicfa.js → behaviors-value-C7dSEhCc.js} +43 -57
- package/dist/behaviors.js +108 -107
- package/dist/derived-registry-CluZCQ7U.js +16 -0
- package/dist/form/form-submitter.d.ts +0 -4
- package/dist/form/hooks/types.d.ts +3 -3
- package/dist/form/hooks/use-form-validation.d.ts +48 -0
- package/dist/form/index.d.ts +2 -3
- package/dist/form/nodes/array-node.d.ts +0 -84
- package/dist/form/nodes/form-node.d.ts +0 -14
- package/dist/form/nodes/group-node.d.ts +0 -4
- package/dist/form/status-machine.d.ts +0 -38
- package/dist/form/types/contracts.d.ts +0 -6
- package/dist/form/types/deep-schema.d.ts +0 -9
- package/dist/form/types/index.d.ts +4 -38
- package/dist/form/types/schema-node.d.ts +13 -16
- package/dist/form/types/validation-schema.d.ts +0 -25
- package/dist/form/unique-id.d.ts +3 -11
- package/dist/form/validation-schema.d.ts +16 -3
- package/dist/form/validation-strategy.d.ts +55 -0
- package/dist/form/validators.d.ts +8 -3
- package/dist/form-model-DYCzGGKF.js +286 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +477 -648
- package/dist/runtime-token.d.ts +23 -0
- package/dist/state/form-model.d.ts +12 -1
- package/dist/state.js +17 -15
- package/dist/subscription-manager-705bls97.js +171 -0
- package/dist/validation.js +133 -81
- package/dist/validators.d.ts +0 -4
- package/dist/validators.js +88 -122
- package/docs/llms/01-api-reference.md +63 -0
- package/docs/llms/02-quick-start.md +143 -0
- package/docs/llms/03-api-signatures.md +273 -0
- package/docs/llms/04-common-patterns.md +202 -0
- package/docs/llms/05-common-mistakes.md +167 -0
- package/docs/llms/06-troubleshooting.md +11 -0
- package/docs/llms/07-complete-import.md +99 -0
- package/docs/llms/08-form-types.md +47 -0
- package/docs/llms/09-formschema.md +143 -0
- package/docs/llms/10-arrays.md +161 -0
- package/docs/llms/11-async-watchfield.md +53 -0
- package/docs/llms/12-array-cleanup.md +31 -0
- package/docs/llms/13-multi-step.md +91 -0
- package/docs/llms/14-extended-mistakes.md +98 -0
- package/docs/llms/15-project-structure.md +125 -0
- package/docs/llms/16-ui-components.md +189 -0
- package/docs/llms/17-nonexistent-api.md +93 -0
- package/docs/llms/18-conditional-fields.md +183 -0
- package/docs/llms/19-reading-values.md +59 -0
- package/docs/llms/20-compute-vs-watch.md +138 -0
- package/docs/llms/21-array-operations.md +113 -0
- package/docs/llms/22-cycle-detection.md +86 -0
- package/docs/llms/23-copy-from.md +141 -0
- package/docs/llms/24-sync-fields.md +114 -0
- package/docs/llms/25-reset-when.md +115 -0
- package/docs/llms/26-transform-value.md +136 -0
- package/docs/llms/27-revalidate-when.md +132 -0
- package/docs/llms/28-submit-and-reset.md +259 -0
- package/docs/llms/29-async-preload.md +193 -0
- package/docs/llms/30-type-safety-recipes.md +159 -0
- package/docs/llms/31-async-validator-debounce.md +135 -0
- package/docs/llms/32-async-options-loading.md +108 -0
- package/docs/llms/33-validation-strategy.md +193 -0
- package/llms.txt +435 -1580
- package/package.json +33 -10
- package/dist/form-model-C8Fi83k4.js +0 -439
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { effect as i } from "@preact/signals-core";
|
|
2
2
|
import { g as s } from "./signal-node-registry-tiwel-TV.js";
|
|
3
|
-
import { d as f } from "./behaviors-value-
|
|
3
|
+
import { d as f } from "./behaviors-value-C7dSEhCc.js";
|
|
4
4
|
function a(n, r, t) {
|
|
5
5
|
return i(() => {
|
|
6
6
|
const o = r(), e = s(n);
|
|
@@ -1,57 +1,46 @@
|
|
|
1
1
|
import { effect as f } from "@preact/signals-core";
|
|
2
|
-
const
|
|
3
|
-
function
|
|
4
|
-
a.set(e, (a.get(e) ?? 0) + 1);
|
|
5
|
-
}
|
|
6
|
-
function y(e) {
|
|
7
|
-
const n = a.get(e);
|
|
8
|
-
n !== void 0 && (n <= 1 ? a.delete(e) : a.set(e, n - 1));
|
|
9
|
-
}
|
|
10
|
-
function E(e) {
|
|
11
|
-
return a.has(e);
|
|
12
|
-
}
|
|
13
|
-
const m = "runOutsideEffect";
|
|
14
|
-
function v(e, n) {
|
|
2
|
+
const d = "runOutsideEffect";
|
|
3
|
+
function i(e, n) {
|
|
15
4
|
process.env.NODE_ENV !== "production" && console.error(`[${n}]`, e);
|
|
16
5
|
}
|
|
17
|
-
function
|
|
6
|
+
function m(e) {
|
|
18
7
|
return typeof e == "object" && e !== null && typeof e.then == "function";
|
|
19
8
|
}
|
|
20
|
-
function
|
|
9
|
+
function v(e, n) {
|
|
21
10
|
try {
|
|
22
11
|
const t = e();
|
|
23
|
-
|
|
12
|
+
m(t) && t.then(void 0, (r) => i(r, n));
|
|
24
13
|
} catch (t) {
|
|
25
|
-
|
|
14
|
+
i(t, n);
|
|
26
15
|
}
|
|
27
16
|
}
|
|
28
|
-
function
|
|
17
|
+
function y(e) {
|
|
29
18
|
return (...n) => {
|
|
30
|
-
|
|
19
|
+
a(() => e(...n));
|
|
31
20
|
};
|
|
32
21
|
}
|
|
33
|
-
function
|
|
22
|
+
function a(e) {
|
|
34
23
|
let n = !1;
|
|
35
24
|
return queueMicrotask(() => {
|
|
36
|
-
n ||
|
|
25
|
+
n || v(e, d);
|
|
37
26
|
}), () => {
|
|
38
27
|
n = !0;
|
|
39
28
|
};
|
|
40
29
|
}
|
|
41
|
-
function
|
|
30
|
+
function h(e, n) {
|
|
42
31
|
return () => {
|
|
43
|
-
n(() =>
|
|
32
|
+
n(() => v(e, "safeDebouncedCallback"));
|
|
44
33
|
};
|
|
45
34
|
}
|
|
46
|
-
function
|
|
35
|
+
function k(e, n, t, r) {
|
|
47
36
|
return f(() => {
|
|
48
37
|
const u = e.map((c) => c.value);
|
|
49
38
|
if (r?.when && !r.when(...u)) return;
|
|
50
|
-
const
|
|
51
|
-
n.peek() !==
|
|
39
|
+
const s = t(...u);
|
|
40
|
+
n.peek() !== s && (n.value = s);
|
|
52
41
|
});
|
|
53
42
|
}
|
|
54
|
-
function
|
|
43
|
+
function E(e, n, t) {
|
|
55
44
|
return f(() => {
|
|
56
45
|
const r = e.value;
|
|
57
46
|
if (t?.when && !t.when()) return;
|
|
@@ -59,18 +48,18 @@ function F(e, n, t) {
|
|
|
59
48
|
n.peek() !== u && (n.value = u);
|
|
60
49
|
});
|
|
61
50
|
}
|
|
62
|
-
function
|
|
51
|
+
function w(e, n, t) {
|
|
63
52
|
let r = !0;
|
|
64
53
|
return f(() => {
|
|
65
54
|
const u = e.value;
|
|
66
55
|
r && (r = !1, !t?.immediate) || n(u);
|
|
67
56
|
});
|
|
68
57
|
}
|
|
69
|
-
function
|
|
58
|
+
function b(e, n) {
|
|
70
59
|
let t = !1;
|
|
71
60
|
return f(() => {
|
|
72
61
|
const r = e.value;
|
|
73
|
-
t ||
|
|
62
|
+
t || a(() => {
|
|
74
63
|
const u = n(r);
|
|
75
64
|
if (e.peek() !== u) {
|
|
76
65
|
t = !0;
|
|
@@ -83,66 +72,63 @@ function C(e, n) {
|
|
|
83
72
|
});
|
|
84
73
|
});
|
|
85
74
|
}
|
|
86
|
-
function
|
|
75
|
+
function D(e, n, t) {
|
|
87
76
|
const r = t?.resetValue ?? null;
|
|
88
77
|
return f(() => {
|
|
89
78
|
const u = n();
|
|
90
|
-
|
|
79
|
+
a(() => {
|
|
91
80
|
u && e.peek() !== r && (e.value = r);
|
|
92
81
|
});
|
|
93
82
|
});
|
|
94
83
|
}
|
|
95
|
-
function
|
|
84
|
+
function F(e, n, t) {
|
|
96
85
|
const r = t?.transform;
|
|
97
86
|
let u = !1;
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
u ||
|
|
87
|
+
const s = f(() => {
|
|
88
|
+
const l = e.value;
|
|
89
|
+
u || a(() => {
|
|
101
90
|
u = !0;
|
|
102
91
|
try {
|
|
103
|
-
const
|
|
104
|
-
n.peek() !==
|
|
92
|
+
const o = r ? r(l) : l;
|
|
93
|
+
n.peek() !== o && (n.value = o);
|
|
105
94
|
} finally {
|
|
106
95
|
u = !1;
|
|
107
96
|
}
|
|
108
97
|
});
|
|
109
98
|
}), c = f(() => {
|
|
110
|
-
const
|
|
111
|
-
u ||
|
|
99
|
+
const l = n.value;
|
|
100
|
+
u || a(() => {
|
|
112
101
|
u = !0;
|
|
113
102
|
try {
|
|
114
|
-
e.peek() !==
|
|
103
|
+
e.peek() !== l && (e.value = l);
|
|
115
104
|
} finally {
|
|
116
105
|
u = !1;
|
|
117
106
|
}
|
|
118
107
|
});
|
|
119
108
|
});
|
|
120
109
|
return () => {
|
|
121
|
-
|
|
110
|
+
s(), c();
|
|
122
111
|
};
|
|
123
112
|
}
|
|
124
|
-
function
|
|
113
|
+
function x(e, n) {
|
|
125
114
|
let t = !0;
|
|
126
115
|
return f(() => {
|
|
127
116
|
if (e.forEach((r) => r.value), t) {
|
|
128
117
|
t = !1;
|
|
129
118
|
return;
|
|
130
119
|
}
|
|
131
|
-
|
|
120
|
+
a(() => n());
|
|
132
121
|
});
|
|
133
122
|
}
|
|
134
123
|
export {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
C as t,
|
|
146
|
-
y as u,
|
|
147
|
-
x as w
|
|
124
|
+
E as a,
|
|
125
|
+
x as b,
|
|
126
|
+
k as c,
|
|
127
|
+
a as d,
|
|
128
|
+
y as e,
|
|
129
|
+
h as f,
|
|
130
|
+
D as r,
|
|
131
|
+
F as s,
|
|
132
|
+
b as t,
|
|
133
|
+
w
|
|
148
134
|
};
|
package/dist/behaviors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { effect as O } from "@preact/signals-core";
|
|
2
|
-
import { d as $,
|
|
3
|
-
import {
|
|
2
|
+
import { d as $, a as S, w as F, t as A, r as C, s as D, b as M } from "./behaviors-value-C7dSEhCc.js";
|
|
3
|
+
import { m as k, u as x } from "./derived-registry-CluZCQ7U.js";
|
|
4
|
+
import { e as G } from "./behaviors-node-DGEFMTQu.js";
|
|
4
5
|
let p = null;
|
|
5
6
|
function P(e) {
|
|
6
7
|
if (!p)
|
|
@@ -18,11 +19,11 @@ function y() {
|
|
|
18
19
|
}
|
|
19
20
|
function T(e) {
|
|
20
21
|
return {
|
|
21
|
-
__run(
|
|
22
|
-
const o = { cleanups: [], model:
|
|
22
|
+
__run(n, t) {
|
|
23
|
+
const o = { cleanups: [], model: n, form: t }, r = p;
|
|
23
24
|
p = o;
|
|
24
25
|
try {
|
|
25
|
-
e({ model:
|
|
26
|
+
e({ model: n, form: t });
|
|
26
27
|
} finally {
|
|
27
28
|
p = r;
|
|
28
29
|
}
|
|
@@ -32,112 +33,112 @@ function T(e) {
|
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
+
function h(e) {
|
|
36
37
|
s(O(e));
|
|
37
38
|
}
|
|
38
39
|
function _(e) {
|
|
39
40
|
$(e);
|
|
40
41
|
}
|
|
41
|
-
const
|
|
42
|
+
const m = (e) => typeof e == "object" && e !== null && typeof e.peek == "function", B = (e) => Array.isArray(e) ? e : [e];
|
|
42
43
|
function E(e) {
|
|
43
|
-
const
|
|
44
|
-
for (const
|
|
45
|
-
const o = e[
|
|
46
|
-
t
|
|
44
|
+
const n = {};
|
|
45
|
+
for (const t of Object.keys(e)) {
|
|
46
|
+
const o = e[t];
|
|
47
|
+
n[t] = m(o) ? o.value : E(o);
|
|
47
48
|
}
|
|
48
|
-
return
|
|
49
|
+
return n;
|
|
49
50
|
}
|
|
50
|
-
function W(e,
|
|
51
|
-
for (const
|
|
52
|
-
const o = e[
|
|
53
|
-
|
|
51
|
+
function W(e, n) {
|
|
52
|
+
for (const t of Object.keys(e)) {
|
|
53
|
+
const o = e[t];
|
|
54
|
+
m(o) ? o.value = n?.[t] : W(o, n?.[t] ?? {});
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
function I(e) {
|
|
57
58
|
if (!e) return;
|
|
58
|
-
const { form:
|
|
59
|
-
return
|
|
59
|
+
const { form: n } = y();
|
|
60
|
+
return n.getFieldByPath(e);
|
|
60
61
|
}
|
|
61
62
|
function V(e) {
|
|
62
63
|
return new Proxy(
|
|
63
64
|
{},
|
|
64
65
|
{
|
|
65
|
-
get: (
|
|
66
|
-
if (
|
|
67
|
-
if (typeof
|
|
68
|
-
const o = e[
|
|
66
|
+
get: (n, t) => {
|
|
67
|
+
if (t === "$") return e;
|
|
68
|
+
if (typeof t != "string") return;
|
|
69
|
+
const o = e[t];
|
|
69
70
|
if (o != null)
|
|
70
|
-
return
|
|
71
|
+
return m(o) ? o.value : V(o);
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
);
|
|
74
75
|
}
|
|
75
76
|
function j(e) {
|
|
76
|
-
return (
|
|
77
|
+
return (n) => {
|
|
77
78
|
try {
|
|
78
|
-
|
|
79
|
-
} catch (
|
|
80
|
-
if (
|
|
79
|
+
n();
|
|
80
|
+
} catch (t) {
|
|
81
|
+
if (t instanceof Error && /cycle detected/i.test(t.message)) {
|
|
81
82
|
const o = e.__path ?? "?";
|
|
82
83
|
throw new Error(
|
|
83
84
|
`[@reformer/core/behaviors] compute("${o}"): расходящийся цикл пересчёта — взаимные compute/computeFrom без стабилизации. Проверьте зависимости или добавьте стабилизирующее условие (when) / разорвите цикл через peek.`
|
|
84
85
|
);
|
|
85
86
|
}
|
|
86
|
-
throw
|
|
87
|
+
throw t;
|
|
87
88
|
}
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
|
-
function
|
|
91
|
+
function U(e, n, t) {
|
|
91
92
|
k(e), s(() => x(e));
|
|
92
93
|
const o = j(e);
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
const r =
|
|
94
|
+
h(() => {
|
|
95
|
+
if (t?.when && !t.when()) return;
|
|
96
|
+
const r = n();
|
|
96
97
|
e.peek() !== r && o(() => {
|
|
97
98
|
e.value = r;
|
|
98
99
|
});
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
|
-
function
|
|
102
|
-
k(
|
|
103
|
-
const r = j(
|
|
104
|
-
|
|
102
|
+
function X(e, n, t, o) {
|
|
103
|
+
k(n), s(() => x(n));
|
|
104
|
+
const r = j(n);
|
|
105
|
+
h(() => {
|
|
105
106
|
const c = e.map((f) => f.value);
|
|
106
107
|
if (o?.when && !o.when(...c)) return;
|
|
107
|
-
const i =
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const i = t(...c);
|
|
109
|
+
n.peek() !== i && r(() => {
|
|
110
|
+
n.value = i;
|
|
110
111
|
});
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
|
-
function
|
|
114
|
-
if (
|
|
115
|
-
s(S(e,
|
|
114
|
+
function Y(e, n, t) {
|
|
115
|
+
if (m(e) && m(n)) {
|
|
116
|
+
s(S(e, n, t));
|
|
116
117
|
return;
|
|
117
118
|
}
|
|
118
|
-
const o = e, r =
|
|
119
|
-
|
|
119
|
+
const o = e, r = n;
|
|
120
|
+
h(() => {
|
|
120
121
|
const c = E(o);
|
|
121
|
-
|
|
122
|
+
t?.when && !t.when() || _(() => W(r, c));
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
|
-
function R(e,
|
|
125
|
+
function R(e, n, t) {
|
|
125
126
|
let o;
|
|
126
127
|
const r = (c) => {
|
|
127
128
|
o?.abort(), o = new AbortController();
|
|
128
129
|
const { signal: i } = o;
|
|
129
|
-
$(() =>
|
|
130
|
+
$(() => n(c, { signal: i }));
|
|
130
131
|
};
|
|
131
|
-
if (!
|
|
132
|
-
s(F(e, r, { immediate:
|
|
132
|
+
if (!t?.debounce)
|
|
133
|
+
s(F(e, r, { immediate: t?.immediate }));
|
|
133
134
|
else {
|
|
134
135
|
let c;
|
|
135
136
|
const i = F(
|
|
136
137
|
e,
|
|
137
138
|
(f) => {
|
|
138
|
-
c && clearTimeout(c), c = setTimeout(() => r(f),
|
|
139
|
+
c && clearTimeout(c), c = setTimeout(() => r(f), t.debounce);
|
|
139
140
|
},
|
|
140
|
-
{ immediate:
|
|
141
|
+
{ immediate: t?.immediate }
|
|
141
142
|
);
|
|
142
143
|
s(() => {
|
|
143
144
|
c && clearTimeout(c), i();
|
|
@@ -145,67 +146,67 @@ function R(e, t, n) {
|
|
|
145
146
|
}
|
|
146
147
|
s(() => o?.abort());
|
|
147
148
|
}
|
|
148
|
-
function q(e,
|
|
149
|
+
function q(e, n, t) {
|
|
149
150
|
for (const o of B(e))
|
|
150
|
-
|
|
151
|
+
m(o) ? s(G(o, n, t)) : z(o, n, t);
|
|
151
152
|
}
|
|
152
|
-
function
|
|
153
|
-
q(e, () => !
|
|
153
|
+
function Z(e, n, t) {
|
|
154
|
+
q(e, () => !n(), t);
|
|
154
155
|
}
|
|
155
|
-
function z(e,
|
|
156
|
+
function z(e, n, t) {
|
|
156
157
|
const o = I(e.__path);
|
|
157
|
-
o &&
|
|
158
|
-
const r =
|
|
158
|
+
o && h(() => {
|
|
159
|
+
const r = n();
|
|
159
160
|
_(() => {
|
|
160
|
-
r ? o.enable() : (o.disable(),
|
|
161
|
+
r ? o.enable() : (o.disable(), t?.resetOnDisable && o.reset());
|
|
161
162
|
});
|
|
162
163
|
});
|
|
163
164
|
}
|
|
164
|
-
function
|
|
165
|
-
s(A(e,
|
|
165
|
+
function ee(e, n) {
|
|
166
|
+
s(A(e, n));
|
|
166
167
|
}
|
|
167
|
-
function
|
|
168
|
-
s(C(e,
|
|
168
|
+
function te(e, n, t) {
|
|
169
|
+
s(C(e, n, t));
|
|
169
170
|
}
|
|
170
|
-
function ne(e,
|
|
171
|
-
s(D(e,
|
|
171
|
+
function ne(e, n, t) {
|
|
172
|
+
s(D(e, n, t));
|
|
172
173
|
}
|
|
173
|
-
function
|
|
174
|
-
s(M(e,
|
|
174
|
+
function oe(e, n) {
|
|
175
|
+
s(M(e, n));
|
|
175
176
|
}
|
|
176
|
-
function g(e,
|
|
177
|
-
return
|
|
177
|
+
function g(e, n) {
|
|
178
|
+
return n.split(".").reduce((t, o) => t?.[o], e);
|
|
178
179
|
}
|
|
179
180
|
function N(e) {
|
|
180
181
|
return new Proxy(
|
|
181
182
|
{},
|
|
182
183
|
{
|
|
183
|
-
get(
|
|
184
|
-
if (!(typeof
|
|
184
|
+
get(n, t) {
|
|
185
|
+
if (!(typeof t == "symbol" || t === "then"))
|
|
185
186
|
throw new Error(
|
|
186
187
|
`[@reformer/core/behaviors] applyEach: форма строки массива "${e}" недоступна (form.${String(
|
|
187
|
-
|
|
188
|
+
t
|
|
188
189
|
)}) — массив не материализован в схеме формы. Per-row node-операции (enableWhen/updateComponentProps/reset) требуют узла { array, item } в схеме; value-операции (row.$.*: compute/copyFrom/transformValue) работают и без материализации.`
|
|
189
190
|
);
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
);
|
|
193
194
|
}
|
|
194
|
-
function H(e,
|
|
195
|
-
const { model:
|
|
195
|
+
function H(e, n) {
|
|
196
|
+
const { model: t, form: o } = y(), r = e.__path;
|
|
196
197
|
if (!r) return;
|
|
197
|
-
const c = g(
|
|
198
|
+
const c = g(t, r);
|
|
198
199
|
if (!c) return;
|
|
199
200
|
const i = o.getFieldByPath(
|
|
200
201
|
r
|
|
201
202
|
), f = i?.length, u = /* @__PURE__ */ new Map();
|
|
202
|
-
|
|
203
|
+
h(() => {
|
|
203
204
|
const d = f ? f.value : c.length, w = /* @__PURE__ */ new Set();
|
|
204
205
|
for (let a = 0; a < d; a++) {
|
|
205
206
|
const l = c.at(a);
|
|
206
207
|
if (l != null && (w.add(l), !u.has(l))) {
|
|
207
208
|
const b = i?.at?.(a) ?? N(r);
|
|
208
|
-
u.set(l,
|
|
209
|
+
u.set(l, n.__run(l, b));
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
for (const [a, l] of u)
|
|
@@ -217,27 +218,27 @@ function H(e, t) {
|
|
|
217
218
|
}
|
|
218
219
|
function v(e) {
|
|
219
220
|
if (e == null || typeof e != "object") return;
|
|
220
|
-
const
|
|
221
|
-
if (typeof
|
|
222
|
-
const
|
|
223
|
-
for (let o = 0; o <
|
|
221
|
+
const n = e;
|
|
222
|
+
if (typeof n.at == "function" && typeof n.length == "number") {
|
|
223
|
+
const t = n.length;
|
|
224
|
+
for (let o = 0; o < t; o++) v(n.at(o));
|
|
224
225
|
return;
|
|
225
226
|
}
|
|
226
|
-
for (const
|
|
227
|
+
for (const t of Object.keys(e)) v(e[t]);
|
|
227
228
|
}
|
|
228
|
-
function
|
|
229
|
-
const { model:
|
|
229
|
+
function re(e, n) {
|
|
230
|
+
const { model: t } = y(), o = e.__path;
|
|
230
231
|
if (!o) return;
|
|
231
|
-
const r = g(
|
|
232
|
+
const r = g(t, o);
|
|
232
233
|
r && H(
|
|
233
234
|
e,
|
|
234
235
|
T(({ model: c }) => {
|
|
235
|
-
R(
|
|
236
|
+
R(n(c), (i) => {
|
|
236
237
|
if (i)
|
|
237
238
|
for (let f = 0; f < r.length; f++) {
|
|
238
239
|
const u = r.at(f);
|
|
239
240
|
if (u && u !== c) {
|
|
240
|
-
const d =
|
|
241
|
+
const d = n(u);
|
|
241
242
|
d.peek() && (d.value = !1);
|
|
242
243
|
}
|
|
243
244
|
}
|
|
@@ -245,16 +246,16 @@ function oe(e, t) {
|
|
|
245
246
|
})
|
|
246
247
|
);
|
|
247
248
|
}
|
|
248
|
-
function
|
|
249
|
-
const { model:
|
|
249
|
+
function ce(e, n) {
|
|
250
|
+
const { model: t } = y(), o = e.__path;
|
|
250
251
|
if (!o) return;
|
|
251
|
-
const r = g(
|
|
252
|
+
const r = g(t, o);
|
|
252
253
|
if (!r) return;
|
|
253
254
|
let c = !1, i = 0;
|
|
254
|
-
|
|
255
|
+
h(() => {
|
|
255
256
|
v(r), !c && (c = !0, _(() => {
|
|
256
257
|
c = !1;
|
|
257
|
-
const f =
|
|
258
|
+
const f = n(r.toArray());
|
|
258
259
|
let u = !1;
|
|
259
260
|
for (const { index: d, patch: w } of f) {
|
|
260
261
|
const a = r.at(d);
|
|
@@ -269,33 +270,33 @@ function re(e, t) {
|
|
|
269
270
|
}));
|
|
270
271
|
});
|
|
271
272
|
}
|
|
272
|
-
function
|
|
273
|
-
const { form:
|
|
273
|
+
function ie(e, n) {
|
|
274
|
+
const { form: t } = y();
|
|
274
275
|
for (const o of B(e)) {
|
|
275
276
|
const r = o, c = r.__path;
|
|
276
277
|
if (!c) continue;
|
|
277
|
-
const i =
|
|
278
|
-
s(
|
|
278
|
+
const i = t ? t.getFieldByPath(c) : void 0, f = i ? i.getProxy?.() ?? i : void 0;
|
|
279
|
+
s(n.__run(V(r), f));
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
282
|
export {
|
|
282
|
-
|
|
283
|
-
|
|
283
|
+
ce as aggregateInto,
|
|
284
|
+
ie as apply,
|
|
284
285
|
H as applyEach,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
U as compute,
|
|
287
|
+
X as computeFrom,
|
|
288
|
+
Y as copyFrom,
|
|
288
289
|
_ as defer,
|
|
289
290
|
T as defineFormBehavior,
|
|
290
|
-
|
|
291
|
-
|
|
291
|
+
Z as disableWhen,
|
|
292
|
+
h as effect,
|
|
292
293
|
q as enableWhen,
|
|
293
|
-
|
|
294
|
+
re as exclusiveFlag,
|
|
294
295
|
y as getScope,
|
|
295
296
|
R as onChange,
|
|
296
297
|
s as onDispose,
|
|
297
|
-
|
|
298
|
-
|
|
298
|
+
te as resetWhen,
|
|
299
|
+
oe as revalidateWhen,
|
|
299
300
|
ne as syncFields,
|
|
300
|
-
|
|
301
|
+
ee as transformValue
|
|
301
302
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const t = /* @__PURE__ */ new WeakMap();
|
|
2
|
+
function n(e) {
|
|
3
|
+
t.set(e, (t.get(e) ?? 0) + 1);
|
|
4
|
+
}
|
|
5
|
+
function i(e) {
|
|
6
|
+
const r = t.get(e);
|
|
7
|
+
r !== void 0 && (r <= 1 ? t.delete(e) : t.set(e, r - 1));
|
|
8
|
+
}
|
|
9
|
+
function o(e) {
|
|
10
|
+
return t.has(e);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
o as i,
|
|
14
|
+
n as m,
|
|
15
|
+
i as u
|
|
16
|
+
};
|
|
@@ -118,8 +118,4 @@ export declare class FormSubmitter<T extends object> {
|
|
|
118
118
|
* ```
|
|
119
119
|
*/
|
|
120
120
|
submitWithResult<R>(onSubmit: (values: T) => Promise<R> | R, options?: SubmitOptions): Promise<SubmitResult<R>>;
|
|
121
|
-
/**
|
|
122
|
-
* Проверить, идет ли отправка формы
|
|
123
|
-
*/
|
|
124
|
-
isSubmitting(): boolean;
|
|
125
121
|
}
|
|
@@ -166,12 +166,12 @@ export interface FieldControlState<T> {
|
|
|
166
166
|
shouldShowError: boolean;
|
|
167
167
|
/**
|
|
168
168
|
* Пользовательские props для передачи в UI-компоненты.
|
|
169
|
-
* Устанавливаются через {@link FieldNode.
|
|
169
|
+
* Устанавливаются через {@link FieldNode.updateComponentProps}.
|
|
170
170
|
*
|
|
171
171
|
* @example
|
|
172
172
|
* ```tsx
|
|
173
173
|
* // Установка props
|
|
174
|
-
* field.
|
|
174
|
+
* field.updateComponentProps({
|
|
175
175
|
* placeholder: 'Enter email...',
|
|
176
176
|
* maxLength: 100,
|
|
177
177
|
* autoComplete: 'email'
|
|
@@ -234,7 +234,7 @@ export interface FieldControlState<T> {
|
|
|
234
234
|
* <PhoneItem
|
|
235
235
|
* key={item.id}
|
|
236
236
|
* control={item}
|
|
237
|
-
* onRemove={() => control.
|
|
237
|
+
* onRemove={() => control.removeAt(index)}
|
|
238
238
|
* />
|
|
239
239
|
* ))}
|
|
240
240
|
*
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FormModel } from '../../index';
|
|
2
|
+
import { ValidationSchema } from '../validation-schema';
|
|
3
|
+
import { ValidationStrategyKind } from '../validation-strategy';
|
|
4
|
+
export interface UseFormValidationArgs<T> {
|
|
5
|
+
/** Модель данных формы. */
|
|
6
|
+
model: FormModel<T>;
|
|
7
|
+
/** Схема валидации. **Стабильная ссылка** (module-level `const` / `useMemo`) — иначе ломается дедуп раннера. */
|
|
8
|
+
schema: ValidationSchema<T>;
|
|
9
|
+
/** Стратегия запуска. Default `'submit'`. */
|
|
10
|
+
strategy?: ValidationStrategyKind;
|
|
11
|
+
/** Debounce (мс) для live-фаз (`change` / live-часть `afterFirstSubmit`). */
|
|
12
|
+
debounce?: number;
|
|
13
|
+
/** Режим live-фазы для `afterFirstSubmit`. Default `'change'`. */
|
|
14
|
+
liveAfterSubmit?: 'change' | 'blur';
|
|
15
|
+
}
|
|
16
|
+
export interface UseFormValidationResult {
|
|
17
|
+
/** Полный прогон + раскрытие ошибок (`touch:true`); для `onSubmit`. Стабильная ссылка. */
|
|
18
|
+
submit: () => Promise<boolean>;
|
|
19
|
+
/** Алиас `submit` для не-submit сценариев. */
|
|
20
|
+
validate: () => Promise<boolean>;
|
|
21
|
+
/** Идёт ли прогон (submit или live) — для блокировки кнопки. */
|
|
22
|
+
isValidating: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Декларативный выбор стратегии валидации формы: одна точка вместо ручной разводки
|
|
26
|
+
* `validateModel`/`revalidateWhen`. Собирает стабильный {@link createFormValidation}-контроллер,
|
|
27
|
+
* армит реактивную стратегию на клиенте (`useEffect` → SSR-safe) и отдаёт `submit`/`isValidating`.
|
|
28
|
+
*
|
|
29
|
+
* Схема-валидации — **стабильная ссылка** (обязанность вызывающего): контроллер мемоизируется по
|
|
30
|
+
* `[model, schema, strategy, debounce, liveAfterSubmit]`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const validation = defineValidationSchema<Form>(({ model }) => { ... }); // module-level
|
|
35
|
+
*
|
|
36
|
+
* function MyForm() {
|
|
37
|
+
* const { submit, isValidating } = useFormValidation({
|
|
38
|
+
* model, schema: validation, strategy: 'afterFirstSubmit', debounce: 300,
|
|
39
|
+
* });
|
|
40
|
+
* const onSubmit = async (e: React.FormEvent) => {
|
|
41
|
+
* e.preventDefault();
|
|
42
|
+
* if (await submit()) await api.save(model.get());
|
|
43
|
+
* };
|
|
44
|
+
* return <form onSubmit={onSubmit}>{ ... }<button disabled={isValidating}>Отправить</button></form>;
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function useFormValidation<T>(args: UseFormValidationArgs<T>): UseFormValidationResult;
|