@reformer/core 1.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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/behaviors.d.ts +2 -0
- package/dist/behaviors.js +230 -0
- package/dist/core/behavior/behavior-applicator.d.ts +71 -0
- package/dist/core/behavior/behavior-applicator.js +92 -0
- package/dist/core/behavior/behavior-context.d.ts +29 -0
- package/dist/core/behavior/behavior-context.js +38 -0
- package/dist/core/behavior/behavior-registry.d.ts +97 -0
- package/dist/core/behavior/behavior-registry.js +198 -0
- package/dist/core/behavior/behaviors/compute-from.d.ts +41 -0
- package/dist/core/behavior/behaviors/compute-from.js +84 -0
- package/dist/core/behavior/behaviors/copy-from.d.ts +31 -0
- package/dist/core/behavior/behaviors/copy-from.js +64 -0
- package/dist/core/behavior/behaviors/enable-when.d.ts +49 -0
- package/dist/core/behavior/behaviors/enable-when.js +81 -0
- package/dist/core/behavior/behaviors/index.d.ts +11 -0
- package/dist/core/behavior/behaviors/index.js +11 -0
- package/dist/core/behavior/behaviors/reset-when.d.ts +51 -0
- package/dist/core/behavior/behaviors/reset-when.js +63 -0
- package/dist/core/behavior/behaviors/revalidate-when.d.ts +30 -0
- package/dist/core/behavior/behaviors/revalidate-when.js +51 -0
- package/dist/core/behavior/behaviors/sync-fields.d.ts +28 -0
- package/dist/core/behavior/behaviors/sync-fields.js +66 -0
- package/dist/core/behavior/behaviors/transform-value.d.ts +120 -0
- package/dist/core/behavior/behaviors/transform-value.js +110 -0
- package/dist/core/behavior/behaviors/watch-field.d.ts +35 -0
- package/dist/core/behavior/behaviors/watch-field.js +56 -0
- package/dist/core/behavior/compose-behavior.d.ts +106 -0
- package/dist/core/behavior/compose-behavior.js +166 -0
- package/dist/core/behavior/create-field-path.d.ts +20 -0
- package/dist/core/behavior/create-field-path.js +69 -0
- package/dist/core/behavior/index.d.ts +12 -0
- package/dist/core/behavior/index.js +17 -0
- package/dist/core/behavior/types.d.ts +152 -0
- package/dist/core/behavior/types.js +7 -0
- package/dist/core/context/form-context-impl.d.ts +29 -0
- package/dist/core/context/form-context-impl.js +37 -0
- package/dist/core/factories/index.d.ts +6 -0
- package/dist/core/factories/index.js +6 -0
- package/dist/core/factories/node-factory.d.ts +209 -0
- package/dist/core/factories/node-factory.js +281 -0
- package/dist/core/nodes/array-node.d.ts +308 -0
- package/dist/core/nodes/array-node.js +534 -0
- package/dist/core/nodes/field-node.d.ts +269 -0
- package/dist/core/nodes/field-node.js +510 -0
- package/dist/core/nodes/form-node.d.ts +342 -0
- package/dist/core/nodes/form-node.js +343 -0
- package/dist/core/nodes/group-node/field-registry.d.ts +191 -0
- package/dist/core/nodes/group-node/field-registry.js +215 -0
- package/dist/core/nodes/group-node/index.d.ts +11 -0
- package/dist/core/nodes/group-node/index.js +11 -0
- package/dist/core/nodes/group-node/proxy-builder.d.ts +71 -0
- package/dist/core/nodes/group-node/proxy-builder.js +161 -0
- package/dist/core/nodes/group-node/state-manager.d.ts +184 -0
- package/dist/core/nodes/group-node/state-manager.js +265 -0
- package/dist/core/nodes/group-node.d.ts +494 -0
- package/dist/core/nodes/group-node.js +770 -0
- package/dist/core/types/deep-schema.d.ts +78 -0
- package/dist/core/types/deep-schema.js +11 -0
- package/dist/core/types/field-path.d.ts +42 -0
- package/dist/core/types/field-path.js +4 -0
- package/dist/core/types/form-context.d.ts +83 -0
- package/dist/core/types/form-context.js +25 -0
- package/dist/core/types/group-node-proxy.d.ts +135 -0
- package/dist/core/types/group-node-proxy.js +31 -0
- package/dist/core/types/index.d.ts +163 -0
- package/dist/core/types/index.js +4 -0
- package/dist/core/types/validation-schema.d.ts +104 -0
- package/dist/core/types/validation-schema.js +10 -0
- package/dist/core/utils/create-form.d.ts +61 -0
- package/dist/core/utils/create-form.js +24 -0
- package/dist/core/utils/debounce.d.ts +160 -0
- package/dist/core/utils/debounce.js +197 -0
- package/dist/core/utils/error-handler.d.ts +180 -0
- package/dist/core/utils/error-handler.js +226 -0
- package/dist/core/utils/field-path-navigator.d.ts +240 -0
- package/dist/core/utils/field-path-navigator.js +374 -0
- package/dist/core/utils/index.d.ts +14 -0
- package/dist/core/utils/index.js +14 -0
- package/dist/core/utils/registry-helpers.d.ts +50 -0
- package/dist/core/utils/registry-helpers.js +79 -0
- package/dist/core/utils/registry-stack.d.ts +69 -0
- package/dist/core/utils/registry-stack.js +86 -0
- package/dist/core/utils/resources.d.ts +41 -0
- package/dist/core/utils/resources.js +69 -0
- package/dist/core/utils/subscription-manager.d.ts +180 -0
- package/dist/core/utils/subscription-manager.js +214 -0
- package/dist/core/utils/type-guards.d.ts +116 -0
- package/dist/core/utils/type-guards.js +169 -0
- package/dist/core/validation/core/apply-when.d.ts +28 -0
- package/dist/core/validation/core/apply-when.js +41 -0
- package/dist/core/validation/core/apply.d.ts +63 -0
- package/dist/core/validation/core/apply.js +38 -0
- package/dist/core/validation/core/index.d.ts +8 -0
- package/dist/core/validation/core/index.js +8 -0
- package/dist/core/validation/core/validate-async.d.ts +42 -0
- package/dist/core/validation/core/validate-async.js +45 -0
- package/dist/core/validation/core/validate-tree.d.ts +35 -0
- package/dist/core/validation/core/validate-tree.js +37 -0
- package/dist/core/validation/core/validate.d.ts +32 -0
- package/dist/core/validation/core/validate.js +38 -0
- package/dist/core/validation/field-path.d.ts +43 -0
- package/dist/core/validation/field-path.js +147 -0
- package/dist/core/validation/index.d.ts +21 -0
- package/dist/core/validation/index.js +33 -0
- package/dist/core/validation/validate-form.d.ts +85 -0
- package/dist/core/validation/validate-form.js +152 -0
- package/dist/core/validation/validation-applicator.d.ts +89 -0
- package/dist/core/validation/validation-applicator.js +217 -0
- package/dist/core/validation/validation-context.d.ts +47 -0
- package/dist/core/validation/validation-context.js +75 -0
- package/dist/core/validation/validation-registry.d.ts +156 -0
- package/dist/core/validation/validation-registry.js +298 -0
- package/dist/core/validation/validators/array-validators.d.ts +63 -0
- package/dist/core/validation/validators/array-validators.js +86 -0
- package/dist/core/validation/validators/date.d.ts +38 -0
- package/dist/core/validation/validators/date.js +117 -0
- package/dist/core/validation/validators/email.d.ts +44 -0
- package/dist/core/validation/validators/email.js +60 -0
- package/dist/core/validation/validators/index.d.ts +14 -0
- package/dist/core/validation/validators/index.js +14 -0
- package/dist/core/validation/validators/max-length.d.ts +45 -0
- package/dist/core/validation/validators/max-length.js +60 -0
- package/dist/core/validation/validators/max.d.ts +45 -0
- package/dist/core/validation/validators/max.js +60 -0
- package/dist/core/validation/validators/min-length.d.ts +45 -0
- package/dist/core/validation/validators/min-length.js +60 -0
- package/dist/core/validation/validators/min.d.ts +45 -0
- package/dist/core/validation/validators/min.js +60 -0
- package/dist/core/validation/validators/number.d.ts +38 -0
- package/dist/core/validation/validators/number.js +90 -0
- package/dist/core/validation/validators/pattern.d.ts +47 -0
- package/dist/core/validation/validators/pattern.js +62 -0
- package/dist/core/validation/validators/phone.d.ts +34 -0
- package/dist/core/validation/validators/phone.js +58 -0
- package/dist/core/validation/validators/required.d.ts +48 -0
- package/dist/core/validation/validators/required.js +69 -0
- package/dist/core/validation/validators/url.d.ts +29 -0
- package/dist/core/validation/validators/url.js +55 -0
- package/dist/create-field-path-CdPF3lIK.js +704 -0
- package/dist/hooks/useFormControl.d.ts +48 -0
- package/dist/hooks/useFormControl.js +298 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/node-factory-D7DOnSSN.js +3200 -0
- package/dist/validators.d.ts +2 -0
- package/dist/validators.js +298 -0
- package/llms.txt +847 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Alexandr Bukhtatyy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @reformer/core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@reformer/core)
|
|
4
|
+
[](https://www.npmjs.com/package/@reformer/core)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
Reactive form state management library for React with signals-based architecture.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @reformer/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- Signals-based reactive state management
|
|
18
|
+
- Declarative form validation
|
|
19
|
+
- Dynamic form behaviors
|
|
20
|
+
- TypeScript support
|
|
21
|
+
- Tree-shakeable exports
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { createForm, useFormControl } from '@reformer/core';
|
|
27
|
+
|
|
28
|
+
const form = createForm({
|
|
29
|
+
schema: {
|
|
30
|
+
name: { initialValue: '' },
|
|
31
|
+
email: { initialValue: '' }
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function MyForm() {
|
|
36
|
+
const name = useFormControl(form.controls.name);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<input
|
|
40
|
+
value={name.value}
|
|
41
|
+
onChange={(e) => name.setValue(e.target.value)}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
Full documentation is available at [https://alexandrbukhtatyy.github.io/ReFormer/](https://alexandrbukhtatyy.github.io/ReFormer/)
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { a as y, E as p, c as b } from "./create-field-path-CdPF3lIK.js";
|
|
2
|
+
import { b as M, B as T } from "./create-field-path-CdPF3lIK.js";
|
|
3
|
+
function v(e, t, r) {
|
|
4
|
+
const { debounce: a, immediate: s = !1 } = r || {}, l = (u, i, c) => {
|
|
5
|
+
const o = u.getFieldByPath(e.__path);
|
|
6
|
+
if (!o) return null;
|
|
7
|
+
if (s) {
|
|
8
|
+
const n = o.value.value;
|
|
9
|
+
t(n, i);
|
|
10
|
+
}
|
|
11
|
+
return p(() => {
|
|
12
|
+
const n = o.value.value;
|
|
13
|
+
c(() => {
|
|
14
|
+
t(n, i);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
y().register(l, { debounce: a });
|
|
19
|
+
}
|
|
20
|
+
function A(e, t, r) {
|
|
21
|
+
const { when: a, fields: s = "all", transform: l, debounce: u } = r || {};
|
|
22
|
+
v(
|
|
23
|
+
e,
|
|
24
|
+
(i, c) => {
|
|
25
|
+
if (a) {
|
|
26
|
+
const f = c.form.getValue();
|
|
27
|
+
if (!a(f)) return;
|
|
28
|
+
}
|
|
29
|
+
const o = l ? l(i) : i, n = c.form.getFieldByPath(t.__path);
|
|
30
|
+
if (n)
|
|
31
|
+
if (s === "all" || !s)
|
|
32
|
+
n.setValue(o, { emitEvent: !1 });
|
|
33
|
+
else {
|
|
34
|
+
const f = {};
|
|
35
|
+
s.forEach((d) => {
|
|
36
|
+
i && typeof i == "object" && (f[d] = i[d]);
|
|
37
|
+
}), "patchValue" in n && n.patchValue(f);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{ debounce: u }
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function V(e, t, r) {
|
|
44
|
+
const { debounce: a, resetOnDisable: s = !1 } = r || {}, l = (u, i, c) => {
|
|
45
|
+
const o = u.getFieldByPath(e.__path);
|
|
46
|
+
return o ? p(() => {
|
|
47
|
+
const n = u.value.value;
|
|
48
|
+
c(() => {
|
|
49
|
+
t(n) ? o.enable() : (o.disable(), s && o.reset());
|
|
50
|
+
});
|
|
51
|
+
}) : null;
|
|
52
|
+
};
|
|
53
|
+
y().register(l, { debounce: a });
|
|
54
|
+
}
|
|
55
|
+
function C(e, t, r) {
|
|
56
|
+
V(e, (a) => !t(a), r);
|
|
57
|
+
}
|
|
58
|
+
function R(e, t, r, a) {
|
|
59
|
+
const { debounce: s, condition: l } = a || {}, u = (i, c, o) => {
|
|
60
|
+
const n = i.getFieldByPath(t.__path);
|
|
61
|
+
if (!n) return null;
|
|
62
|
+
const f = e.map((d) => i.getFieldByPath(d.__path)).filter((d) => d !== void 0);
|
|
63
|
+
return f.length === 0 ? null : p(() => {
|
|
64
|
+
const d = f.map((g) => g.value.value);
|
|
65
|
+
o(() => {
|
|
66
|
+
if (l) {
|
|
67
|
+
const m = i.getValue();
|
|
68
|
+
if (!l(m)) return;
|
|
69
|
+
}
|
|
70
|
+
const g = {};
|
|
71
|
+
e.forEach((m, P) => {
|
|
72
|
+
const B = m.__path.split(".").pop() || m.__path;
|
|
73
|
+
g[B] = d[P];
|
|
74
|
+
});
|
|
75
|
+
const _ = r(g);
|
|
76
|
+
n.setValue(_, { emitEvent: !1 });
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
y().register(u, { debounce: s });
|
|
81
|
+
}
|
|
82
|
+
function U(e, t, r) {
|
|
83
|
+
const { debounce: a } = r || {}, s = (l, u, i) => {
|
|
84
|
+
const c = l.getFieldByPath(e.__path);
|
|
85
|
+
if (!c) return null;
|
|
86
|
+
const o = t.map((n) => l.getFieldByPath(n.__path)).filter((n) => n !== void 0);
|
|
87
|
+
return o.length === 0 ? null : p(() => {
|
|
88
|
+
o.forEach((n) => n.value.value), i(() => {
|
|
89
|
+
c.validate();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
y().register(s, { debounce: a });
|
|
94
|
+
}
|
|
95
|
+
function W(e, t, r) {
|
|
96
|
+
const { debounce: a, transform: s } = r || {}, l = (u, i, c) => {
|
|
97
|
+
const o = u.getFieldByPath(e.__path), n = u.getFieldByPath(t.__path);
|
|
98
|
+
if (!o || !n) return null;
|
|
99
|
+
let f = !1;
|
|
100
|
+
const d = p(() => {
|
|
101
|
+
const _ = o.value.value;
|
|
102
|
+
f || c(() => {
|
|
103
|
+
f = !0;
|
|
104
|
+
const m = s ? s(_) : _;
|
|
105
|
+
n.setValue(m, { emitEvent: !1 }), f = !1;
|
|
106
|
+
});
|
|
107
|
+
}), g = p(() => {
|
|
108
|
+
const _ = n.value.value;
|
|
109
|
+
f || c(() => {
|
|
110
|
+
f = !0, o.setValue(_, { emitEvent: !1 }), f = !1;
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return () => {
|
|
114
|
+
d(), g();
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
y().register(l, { debounce: a });
|
|
118
|
+
}
|
|
119
|
+
function w(e, t, r) {
|
|
120
|
+
const { debounce: a, resetValue: s = null, onlyIfDirty: l = !1 } = r || {}, u = (i, c, o) => {
|
|
121
|
+
const n = i.getFieldByPath(e.__path);
|
|
122
|
+
return n ? p(() => {
|
|
123
|
+
const f = i.value.value;
|
|
124
|
+
o(() => {
|
|
125
|
+
if (t(f)) {
|
|
126
|
+
if (l && !n.dirty.value)
|
|
127
|
+
return;
|
|
128
|
+
n.setValue(s), n.markAsPristine(), n.markAsUntouched();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}) : null;
|
|
132
|
+
};
|
|
133
|
+
y().register(u, { debounce: a });
|
|
134
|
+
}
|
|
135
|
+
function F(e, t, r) {
|
|
136
|
+
const { onUserChangeOnly: a = !1, emitEvent: s = !0, debounce: l } = r || {};
|
|
137
|
+
v(
|
|
138
|
+
e,
|
|
139
|
+
(u, i) => {
|
|
140
|
+
const c = i.form.getFieldByPath(e.__path);
|
|
141
|
+
if (!c || a && !c.touched.value)
|
|
142
|
+
return;
|
|
143
|
+
const o = t(u);
|
|
144
|
+
o !== u && c.setValue(o, { emitEvent: s });
|
|
145
|
+
},
|
|
146
|
+
{ debounce: l }
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
function h(e, t) {
|
|
150
|
+
return (r, a) => {
|
|
151
|
+
F(r, e, { ...t, ...a });
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const O = {
|
|
155
|
+
/** Перевести в верхний регистр */
|
|
156
|
+
toUpperCase: h((e) => e?.toUpperCase()),
|
|
157
|
+
/** Перевести в нижний регистр */
|
|
158
|
+
toLowerCase: h((e) => e?.toLowerCase()),
|
|
159
|
+
/** Удалить пробелы с краев */
|
|
160
|
+
trim: h((e) => e?.trim()),
|
|
161
|
+
/** Удалить все пробелы */
|
|
162
|
+
removeSpaces: h((e) => e?.replace(/\s/g, "")),
|
|
163
|
+
/** Оставить только цифры */
|
|
164
|
+
digitsOnly: h((e) => e?.replace(/\D/g, "")),
|
|
165
|
+
/** Округлить число */
|
|
166
|
+
round: h(
|
|
167
|
+
(e) => typeof e == "number" ? Math.round(e) : e
|
|
168
|
+
),
|
|
169
|
+
/** Округлить до 2 знаков после запятой */
|
|
170
|
+
roundTo2: h(
|
|
171
|
+
(e) => typeof e == "number" ? Math.round(e * 100) / 100 : e
|
|
172
|
+
)
|
|
173
|
+
};
|
|
174
|
+
function N(e) {
|
|
175
|
+
if (!e)
|
|
176
|
+
return b();
|
|
177
|
+
const t = e.__path;
|
|
178
|
+
return E(t);
|
|
179
|
+
}
|
|
180
|
+
function E(e) {
|
|
181
|
+
return new Proxy({}, {
|
|
182
|
+
get(t, r) {
|
|
183
|
+
return typeof r == "symbol" ? void 0 : {
|
|
184
|
+
__path: e ? `${e}.${r}` : r,
|
|
185
|
+
__key: r
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function j(e, t) {
|
|
191
|
+
const r = (Array.isArray(e) ? e : [e]).filter(Boolean), a = Array.isArray(t) ? t : [t];
|
|
192
|
+
for (const s of r) {
|
|
193
|
+
const l = N(s);
|
|
194
|
+
for (const u of a)
|
|
195
|
+
u(l);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function D(e, t, r) {
|
|
199
|
+
if (!e) return;
|
|
200
|
+
let a = !1;
|
|
201
|
+
v(
|
|
202
|
+
e,
|
|
203
|
+
(s, l) => {
|
|
204
|
+
if (!a && t(s)) {
|
|
205
|
+
const u = b();
|
|
206
|
+
r(u), a = !0;
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{ immediate: !0 }
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
export {
|
|
213
|
+
M as BehaviorContextImpl,
|
|
214
|
+
T as BehaviorRegistry,
|
|
215
|
+
j as apply,
|
|
216
|
+
D as applyWhen,
|
|
217
|
+
R as computeFrom,
|
|
218
|
+
A as copyFrom,
|
|
219
|
+
b as createFieldPath,
|
|
220
|
+
h as createTransformer,
|
|
221
|
+
C as disableWhen,
|
|
222
|
+
V as enableWhen,
|
|
223
|
+
w as resetWhen,
|
|
224
|
+
U as revalidateWhen,
|
|
225
|
+
W as syncFields,
|
|
226
|
+
N as toBehaviorFieldPath,
|
|
227
|
+
F as transformValue,
|
|
228
|
+
O as transformers,
|
|
229
|
+
v as watchField
|
|
230
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Применение behavior схемы к форме
|
|
3
|
+
*
|
|
4
|
+
* Извлечено из GroupNode для соблюдения SRP (Single Responsibility Principle).
|
|
5
|
+
* Управляет процессом регистрации и применения behaviors.
|
|
6
|
+
*
|
|
7
|
+
* @template T Тип формы
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* class GroupNode {
|
|
12
|
+
* private readonly behaviorApplicator = new BehaviorApplicator(this);
|
|
13
|
+
*
|
|
14
|
+
* applyBehaviorSchema(schemaFn: BehaviorSchemaFn<T>): () => void {
|
|
15
|
+
* return this.behaviorApplicator.apply(schemaFn);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { GroupNode } from '../nodes/group-node';
|
|
21
|
+
import type { BehaviorSchemaFn } from './types';
|
|
22
|
+
import { BehaviorRegistry } from './behavior-registry';
|
|
23
|
+
/**
|
|
24
|
+
* Класс для применения behavior схемы к форме
|
|
25
|
+
*
|
|
26
|
+
* Выполняет:
|
|
27
|
+
* 1. Начало регистрации behaviors (beginRegistration)
|
|
28
|
+
* 2. Выполнение схемы (регистрация behaviors)
|
|
29
|
+
* 3. Завершение регистрации (endRegistration) - применение behaviors
|
|
30
|
+
* 4. Возврат функции cleanup для отписки
|
|
31
|
+
*
|
|
32
|
+
* @template T Тип формы (объект)
|
|
33
|
+
*/
|
|
34
|
+
export declare class BehaviorApplicator<T> {
|
|
35
|
+
private readonly form;
|
|
36
|
+
private readonly behaviorRegistry;
|
|
37
|
+
constructor(form: GroupNode<T>, behaviorRegistry: BehaviorRegistry);
|
|
38
|
+
/**
|
|
39
|
+
* Применить behavior схему к форме
|
|
40
|
+
*
|
|
41
|
+
* Этапы:
|
|
42
|
+
* 1. Начать регистрацию (beginRegistration)
|
|
43
|
+
* 2. Выполнить схему (регистрация behaviors)
|
|
44
|
+
* 3. Завершить регистрацию (endRegistration) - применить behaviors
|
|
45
|
+
* 4. Вернуть функцию cleanup для отписки
|
|
46
|
+
*
|
|
47
|
+
* @param schemaFn Функция-схема behavior
|
|
48
|
+
* @returns Функция отписки от всех behaviors
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const cleanup = behaviorApplicator.apply((path) => {
|
|
53
|
+
* copyFrom(path.residenceAddress, path.registrationAddress, {
|
|
54
|
+
* when: (form) => form.sameAsRegistration === true
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* enableWhen(path.propertyValue, (form) => form.loanType === 'mortgage');
|
|
58
|
+
*
|
|
59
|
+
* computeFrom(
|
|
60
|
+
* path.initialPayment,
|
|
61
|
+
* [path.propertyValue],
|
|
62
|
+
* (propertyValue) => propertyValue ? propertyValue * 0.2 : null
|
|
63
|
+
* );
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Cleanup при unmount
|
|
67
|
+
* useEffect(() => cleanup, []);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
apply(schemaFn: BehaviorSchemaFn<T>): () => void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Применение behavior схемы к форме
|
|
3
|
+
*
|
|
4
|
+
* Извлечено из GroupNode для соблюдения SRP (Single Responsibility Principle).
|
|
5
|
+
* Управляет процессом регистрации и применения behaviors.
|
|
6
|
+
*
|
|
7
|
+
* @template T Тип формы
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* class GroupNode {
|
|
12
|
+
* private readonly behaviorApplicator = new BehaviorApplicator(this);
|
|
13
|
+
*
|
|
14
|
+
* applyBehaviorSchema(schemaFn: BehaviorSchemaFn<T>): () => void {
|
|
15
|
+
* return this.behaviorApplicator.apply(schemaFn);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import { createFieldPath as createBehaviorFieldPath } from './create-field-path';
|
|
21
|
+
import { FormErrorHandler, ErrorStrategy } from '../utils/error-handler';
|
|
22
|
+
/**
|
|
23
|
+
* Класс для применения behavior схемы к форме
|
|
24
|
+
*
|
|
25
|
+
* Выполняет:
|
|
26
|
+
* 1. Начало регистрации behaviors (beginRegistration)
|
|
27
|
+
* 2. Выполнение схемы (регистрация behaviors)
|
|
28
|
+
* 3. Завершение регистрации (endRegistration) - применение behaviors
|
|
29
|
+
* 4. Возврат функции cleanup для отписки
|
|
30
|
+
*
|
|
31
|
+
* @template T Тип формы (объект)
|
|
32
|
+
*/
|
|
33
|
+
export class BehaviorApplicator {
|
|
34
|
+
form;
|
|
35
|
+
behaviorRegistry;
|
|
36
|
+
constructor(form, behaviorRegistry) {
|
|
37
|
+
this.form = form;
|
|
38
|
+
this.behaviorRegistry = behaviorRegistry;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Применить behavior схему к форме
|
|
42
|
+
*
|
|
43
|
+
* Этапы:
|
|
44
|
+
* 1. Начать регистрацию (beginRegistration)
|
|
45
|
+
* 2. Выполнить схему (регистрация behaviors)
|
|
46
|
+
* 3. Завершить регистрацию (endRegistration) - применить behaviors
|
|
47
|
+
* 4. Вернуть функцию cleanup для отписки
|
|
48
|
+
*
|
|
49
|
+
* @param schemaFn Функция-схема behavior
|
|
50
|
+
* @returns Функция отписки от всех behaviors
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const cleanup = behaviorApplicator.apply((path) => {
|
|
55
|
+
* copyFrom(path.residenceAddress, path.registrationAddress, {
|
|
56
|
+
* when: (form) => form.sameAsRegistration === true
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* enableWhen(path.propertyValue, (form) => form.loanType === 'mortgage');
|
|
60
|
+
*
|
|
61
|
+
* computeFrom(
|
|
62
|
+
* path.initialPayment,
|
|
63
|
+
* [path.propertyValue],
|
|
64
|
+
* (propertyValue) => propertyValue ? propertyValue * 0.2 : null
|
|
65
|
+
* );
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* // Cleanup при unmount
|
|
69
|
+
* useEffect(() => cleanup, []);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
apply(schemaFn) {
|
|
73
|
+
this.behaviorRegistry.beginRegistration();
|
|
74
|
+
try {
|
|
75
|
+
// 1. Создать field path для type-safe доступа к полям
|
|
76
|
+
const path = createBehaviorFieldPath();
|
|
77
|
+
// 2. Выполнить схему (регистрация behaviors)
|
|
78
|
+
schemaFn(path);
|
|
79
|
+
// 3. Завершить регистрацию и применить behaviors
|
|
80
|
+
// Используем публичный метод getProxy() для получения proxy-инстанса
|
|
81
|
+
const formToUse = this.form.getProxy();
|
|
82
|
+
const result = this.behaviorRegistry.endRegistration(formToUse);
|
|
83
|
+
// 4. Вернуть функцию cleanup
|
|
84
|
+
return result.cleanup;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
FormErrorHandler.handle(error, 'BehaviorApplicator', ErrorStrategy.THROW);
|
|
88
|
+
// TypeScript требует return, но код никогда не дойдет сюда
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BehaviorContext - контекст для behavior callback функций
|
|
3
|
+
*
|
|
4
|
+
* Реализует FormContext для behavior схем
|
|
5
|
+
*/
|
|
6
|
+
import type { GroupNode } from '../nodes/group-node';
|
|
7
|
+
import type { GroupNodeWithControls } from '../types/group-node-proxy';
|
|
8
|
+
import type { FormContext } from '../types/form-context';
|
|
9
|
+
/**
|
|
10
|
+
* Реализация BehaviorContext (FormContext)
|
|
11
|
+
*
|
|
12
|
+
* Предоставляет:
|
|
13
|
+
* - `form` - прямой типизированный доступ к форме
|
|
14
|
+
* - `setFieldValue` - безопасная установка значения (emitEvent: false)
|
|
15
|
+
*/
|
|
16
|
+
export declare class BehaviorContextImpl<TForm> implements FormContext<TForm> {
|
|
17
|
+
/**
|
|
18
|
+
* Форма с типизированным Proxy-доступом к полям
|
|
19
|
+
*/
|
|
20
|
+
readonly form: GroupNodeWithControls<TForm>;
|
|
21
|
+
private _form;
|
|
22
|
+
constructor(form: GroupNode<TForm>);
|
|
23
|
+
/**
|
|
24
|
+
* Безопасно установить значение поля по строковому пути
|
|
25
|
+
*
|
|
26
|
+
* Автоматически использует emitEvent: false для предотвращения циклов
|
|
27
|
+
*/
|
|
28
|
+
setFieldValue(path: string, value: unknown): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BehaviorContext - контекст для behavior callback функций
|
|
3
|
+
*
|
|
4
|
+
* Реализует FormContext для behavior схем
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Реализация BehaviorContext (FormContext)
|
|
8
|
+
*
|
|
9
|
+
* Предоставляет:
|
|
10
|
+
* - `form` - прямой типизированный доступ к форме
|
|
11
|
+
* - `setFieldValue` - безопасная установка значения (emitEvent: false)
|
|
12
|
+
*/
|
|
13
|
+
export class BehaviorContextImpl {
|
|
14
|
+
/**
|
|
15
|
+
* Форма с типизированным Proxy-доступом к полям
|
|
16
|
+
*/
|
|
17
|
+
form;
|
|
18
|
+
_form;
|
|
19
|
+
constructor(form) {
|
|
20
|
+
this._form = form;
|
|
21
|
+
// Используем _proxyInstance если доступен, иначе fallback на form
|
|
22
|
+
const proxy = (form
|
|
23
|
+
._proxyInstance || form);
|
|
24
|
+
this.form = proxy;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Безопасно установить значение поля по строковому пути
|
|
28
|
+
*
|
|
29
|
+
* Автоматически использует emitEvent: false для предотвращения циклов
|
|
30
|
+
*/
|
|
31
|
+
setFieldValue(path, value) {
|
|
32
|
+
const node = this._form.getFieldByPath(path);
|
|
33
|
+
if (node) {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
node.setValue(value, { emitEvent: false });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BehaviorRegistry - регистрация и управление behavior схемами
|
|
3
|
+
*
|
|
4
|
+
* Аналогично ValidationRegistry, но для реактивного поведения форм
|
|
5
|
+
*/
|
|
6
|
+
import type { GroupNode } from '../nodes/group-node';
|
|
7
|
+
import type { BehaviorHandlerFn, BehaviorOptions } from './types';
|
|
8
|
+
import { FormFields } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* Реестр behaviors для формы
|
|
11
|
+
*
|
|
12
|
+
* Каждый экземпляр GroupNode создает собственный реестр (композиция).
|
|
13
|
+
* Устраняет race conditions и изолирует формы друг от друга.
|
|
14
|
+
*
|
|
15
|
+
* Context stack используется для tracking текущего активного реестра:
|
|
16
|
+
* - beginRegistration() помещает this в stack
|
|
17
|
+
* - endRegistration() извлекает из stack
|
|
18
|
+
* - getCurrent() возвращает текущий активный реестр
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class GroupNode {
|
|
23
|
+
* private readonly behaviorRegistry = new BehaviorRegistry();
|
|
24
|
+
*
|
|
25
|
+
* applyBehaviorSchema(schemaFn) {
|
|
26
|
+
* this.behaviorRegistry.beginRegistration(); // Pushes this to stack
|
|
27
|
+
* schemaFn(createBehaviorFieldPath(this)); // Uses getCurrent()
|
|
28
|
+
* return this.behaviorRegistry.endRegistration(this); // Pops from stack
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class BehaviorRegistry {
|
|
34
|
+
/**
|
|
35
|
+
* Stack активных контекстов регистрации
|
|
36
|
+
* Используется для изоляции форм друг от друга
|
|
37
|
+
*/
|
|
38
|
+
private static contextStack;
|
|
39
|
+
private registrations;
|
|
40
|
+
private isRegistering;
|
|
41
|
+
/**
|
|
42
|
+
* Получить текущий активный реестр из context stack
|
|
43
|
+
*
|
|
44
|
+
* @returns Текущий активный реестр или null
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // В schema-behaviors.ts
|
|
49
|
+
* export function copyFrom(...) {
|
|
50
|
+
* const registry = BehaviorRegistry.getCurrent();
|
|
51
|
+
* if (registry) {
|
|
52
|
+
* registry.register({ ... });
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
static getCurrent(): BehaviorRegistry | null;
|
|
58
|
+
/**
|
|
59
|
+
* Начать регистрацию behaviors
|
|
60
|
+
* Вызывается перед применением схемы
|
|
61
|
+
*
|
|
62
|
+
* Помещает this в context stack для изоляции форм
|
|
63
|
+
*/
|
|
64
|
+
beginRegistration(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Зарегистрировать behavior handler
|
|
67
|
+
* Вызывается функциями из schema-behaviors.ts
|
|
68
|
+
*
|
|
69
|
+
* @param handler - BehaviorHandlerFn функция
|
|
70
|
+
* @param options - Опции behavior (debounce)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const handler = createCopyBehavior(target, source, { when: ... });
|
|
75
|
+
* registry.register(handler, { debounce: 300 });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
register<T extends FormFields>(handler: BehaviorHandlerFn<T>, options?: BehaviorOptions): void;
|
|
79
|
+
/**
|
|
80
|
+
* Завершить регистрацию и применить behaviors к форме
|
|
81
|
+
* Создает effect подписки для всех зарегистрированных behaviors
|
|
82
|
+
*
|
|
83
|
+
* Извлекает this из context stack
|
|
84
|
+
*
|
|
85
|
+
* @param form - GroupNode формы
|
|
86
|
+
* @returns Количество зарегистрированных behaviors и функция cleanup
|
|
87
|
+
*/
|
|
88
|
+
endRegistration<T extends FormFields>(form: GroupNode<T>): {
|
|
89
|
+
count: number;
|
|
90
|
+
cleanup: () => void;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Создать effect подписку для behavior
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
private createEffect;
|
|
97
|
+
}
|