@reformer/core 1.1.0-beta.7 → 1.1.0-beta.8

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.
Files changed (80) hide show
  1. package/dist/behaviors-BRaiR-UY.js +528 -0
  2. package/dist/behaviors.d.ts +6 -2
  3. package/dist/behaviors.js +18 -227
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +3380 -10
  6. package/dist/validators-DjXtDVoE.js +455 -0
  7. package/dist/validators.d.ts +6 -2
  8. package/dist/validators.js +29 -281
  9. package/package.json +1 -1
  10. package/dist/core/behavior/behavior-applicator.js +0 -92
  11. package/dist/core/behavior/behavior-context.js +0 -43
  12. package/dist/core/behavior/behavior-registry.js +0 -198
  13. package/dist/core/behavior/behaviors/compute-from.js +0 -84
  14. package/dist/core/behavior/behaviors/copy-from.js +0 -64
  15. package/dist/core/behavior/behaviors/enable-when.js +0 -81
  16. package/dist/core/behavior/behaviors/index.js +0 -11
  17. package/dist/core/behavior/behaviors/reset-when.js +0 -63
  18. package/dist/core/behavior/behaviors/revalidate-when.js +0 -51
  19. package/dist/core/behavior/behaviors/sync-fields.js +0 -66
  20. package/dist/core/behavior/behaviors/transform-value.js +0 -110
  21. package/dist/core/behavior/behaviors/watch-field.js +0 -56
  22. package/dist/core/behavior/compose-behavior.js +0 -166
  23. package/dist/core/behavior/create-field-path.js +0 -69
  24. package/dist/core/behavior/index.js +0 -17
  25. package/dist/core/behavior/types.js +0 -7
  26. package/dist/core/context/form-context-impl.js +0 -37
  27. package/dist/core/factories/index.js +0 -6
  28. package/dist/core/factories/node-factory.js +0 -281
  29. package/dist/core/nodes/array-node.js +0 -534
  30. package/dist/core/nodes/field-node.js +0 -510
  31. package/dist/core/nodes/form-node.js +0 -343
  32. package/dist/core/nodes/group-node/field-registry.js +0 -215
  33. package/dist/core/nodes/group-node/index.js +0 -11
  34. package/dist/core/nodes/group-node/proxy-builder.js +0 -161
  35. package/dist/core/nodes/group-node/state-manager.js +0 -265
  36. package/dist/core/nodes/group-node.js +0 -770
  37. package/dist/core/types/deep-schema.js +0 -11
  38. package/dist/core/types/field-path.js +0 -4
  39. package/dist/core/types/form-context.js +0 -25
  40. package/dist/core/types/group-node-proxy.js +0 -31
  41. package/dist/core/types/index.js +0 -4
  42. package/dist/core/types/validation-schema.js +0 -10
  43. package/dist/core/utils/create-form.js +0 -24
  44. package/dist/core/utils/debounce.js +0 -197
  45. package/dist/core/utils/error-handler.js +0 -226
  46. package/dist/core/utils/field-path-navigator.js +0 -374
  47. package/dist/core/utils/index.js +0 -14
  48. package/dist/core/utils/registry-helpers.js +0 -79
  49. package/dist/core/utils/registry-stack.js +0 -86
  50. package/dist/core/utils/resources.js +0 -69
  51. package/dist/core/utils/subscription-manager.js +0 -214
  52. package/dist/core/utils/type-guards.js +0 -169
  53. package/dist/core/validation/core/apply-when.js +0 -41
  54. package/dist/core/validation/core/apply.js +0 -38
  55. package/dist/core/validation/core/index.js +0 -8
  56. package/dist/core/validation/core/validate-async.js +0 -45
  57. package/dist/core/validation/core/validate-tree.js +0 -43
  58. package/dist/core/validation/core/validate.js +0 -38
  59. package/dist/core/validation/field-path.js +0 -147
  60. package/dist/core/validation/index.js +0 -33
  61. package/dist/core/validation/validate-form.js +0 -152
  62. package/dist/core/validation/validation-applicator.js +0 -217
  63. package/dist/core/validation/validation-context.js +0 -75
  64. package/dist/core/validation/validation-registry.js +0 -298
  65. package/dist/core/validation/validators/array-validators.js +0 -86
  66. package/dist/core/validation/validators/date.js +0 -117
  67. package/dist/core/validation/validators/email.js +0 -60
  68. package/dist/core/validation/validators/index.js +0 -14
  69. package/dist/core/validation/validators/max-length.js +0 -60
  70. package/dist/core/validation/validators/max.js +0 -60
  71. package/dist/core/validation/validators/min-length.js +0 -60
  72. package/dist/core/validation/validators/min.js +0 -60
  73. package/dist/core/validation/validators/number.js +0 -90
  74. package/dist/core/validation/validators/pattern.js +0 -62
  75. package/dist/core/validation/validators/phone.js +0 -58
  76. package/dist/core/validation/validators/required.js +0 -69
  77. package/dist/core/validation/validators/url.js +0 -55
  78. package/dist/create-field-path-nXfTtl55.js +0 -283
  79. package/dist/hooks/useFormControl.js +0 -298
  80. package/dist/validation-context-cWXmh_Ho.js +0 -156
@@ -1,283 +0,0 @@
1
- var k = Symbol.for("preact-signals");
2
- function y() {
3
- if (v > 1)
4
- v--;
5
- else {
6
- for (var t, i = !1; d !== void 0; ) {
7
- var o = d;
8
- for (d = void 0, l++; o !== void 0; ) {
9
- var r = o.o;
10
- if (o.o = void 0, o.f &= -3, !(8 & o.f) && S(o)) try {
11
- o.c();
12
- } catch (f) {
13
- i || (t = f, i = !0);
14
- }
15
- o = r;
16
- }
17
- }
18
- if (l = 0, v--, i) throw t;
19
- }
20
- }
21
- var n = void 0;
22
- function _(t) {
23
- var i = n;
24
- n = void 0;
25
- try {
26
- return t();
27
- } finally {
28
- n = i;
29
- }
30
- }
31
- var d = void 0, v = 0, l = 0, a = 0;
32
- function w(t) {
33
- if (n !== void 0) {
34
- var i = t.n;
35
- if (i === void 0 || i.t !== n)
36
- return i = { i: 0, S: t, p: n.s, n: void 0, t: n, e: void 0, x: void 0, r: i }, n.s !== void 0 && (n.s.n = i), n.s = i, t.n = i, 32 & n.f && t.S(i), i;
37
- if (i.i === -1)
38
- return i.i = 0, i.n !== void 0 && (i.n.p = i.p, i.p !== void 0 && (i.p.n = i.n), i.p = n.s, i.n = void 0, n.s.n = i, n.s = i), i;
39
- }
40
- }
41
- function e(t, i) {
42
- this.v = t, this.i = 0, this.n = void 0, this.t = void 0, this.W = i?.watched, this.Z = i?.unwatched, this.name = i?.name;
43
- }
44
- e.prototype.brand = k;
45
- e.prototype.h = function() {
46
- return !0;
47
- };
48
- e.prototype.S = function(t) {
49
- var i = this, o = this.t;
50
- o !== t && t.e === void 0 && (t.x = o, this.t = t, o !== void 0 ? o.e = t : _(function() {
51
- var r;
52
- (r = i.W) == null || r.call(i);
53
- }));
54
- };
55
- e.prototype.U = function(t) {
56
- var i = this;
57
- if (this.t !== void 0) {
58
- var o = t.e, r = t.x;
59
- o !== void 0 && (o.x = r, t.e = void 0), r !== void 0 && (r.e = o, t.x = void 0), t === this.t && (this.t = r, r === void 0 && _(function() {
60
- var f;
61
- (f = i.Z) == null || f.call(i);
62
- }));
63
- }
64
- };
65
- e.prototype.subscribe = function(t) {
66
- var i = this;
67
- return N(function() {
68
- var o = i.value, r = n;
69
- n = void 0;
70
- try {
71
- t(o);
72
- } finally {
73
- n = r;
74
- }
75
- }, { name: "sub" });
76
- };
77
- e.prototype.valueOf = function() {
78
- return this.value;
79
- };
80
- e.prototype.toString = function() {
81
- return this.value + "";
82
- };
83
- e.prototype.toJSON = function() {
84
- return this.value;
85
- };
86
- e.prototype.peek = function() {
87
- var t = n;
88
- n = void 0;
89
- try {
90
- return this.value;
91
- } finally {
92
- n = t;
93
- }
94
- };
95
- Object.defineProperty(e.prototype, "value", { get: function() {
96
- var t = w(this);
97
- return t !== void 0 && (t.i = this.i), this.v;
98
- }, set: function(t) {
99
- if (t !== this.v) {
100
- if (l > 100) throw new Error("Cycle detected");
101
- this.v = t, this.i++, a++, v++;
102
- try {
103
- for (var i = this.t; i !== void 0; i = i.x) i.t.N();
104
- } finally {
105
- y();
106
- }
107
- }
108
- } });
109
- function O(t, i) {
110
- return new e(t, i);
111
- }
112
- function S(t) {
113
- for (var i = t.s; i !== void 0; i = i.n) if (i.S.i !== i.i || !i.S.h() || i.S.i !== i.i) return !0;
114
- return !1;
115
- }
116
- function x(t) {
117
- for (var i = t.s; i !== void 0; i = i.n) {
118
- var o = i.S.n;
119
- if (o !== void 0 && (i.r = o), i.S.n = i, i.i = -1, i.n === void 0) {
120
- t.s = i;
121
- break;
122
- }
123
- }
124
- }
125
- function g(t) {
126
- for (var i = t.s, o = void 0; i !== void 0; ) {
127
- var r = i.p;
128
- i.i === -1 ? (i.S.U(i), r !== void 0 && (r.n = i.n), i.n !== void 0 && (i.n.p = r)) : o = i, i.S.n = i.r, i.r !== void 0 && (i.r = void 0), i = r;
129
- }
130
- t.s = o;
131
- }
132
- function s(t, i) {
133
- e.call(this, void 0), this.x = t, this.s = void 0, this.g = a - 1, this.f = 4, this.W = i?.watched, this.Z = i?.unwatched, this.name = i?.name;
134
- }
135
- s.prototype = new e();
136
- s.prototype.h = function() {
137
- if (this.f &= -3, 1 & this.f) return !1;
138
- if ((36 & this.f) == 32 || (this.f &= -5, this.g === a)) return !0;
139
- if (this.g = a, this.f |= 1, this.i > 0 && !S(this))
140
- return this.f &= -2, !0;
141
- var t = n;
142
- try {
143
- x(this), n = this;
144
- var i = this.x();
145
- (16 & this.f || this.v !== i || this.i === 0) && (this.v = i, this.f &= -17, this.i++);
146
- } catch (o) {
147
- this.v = o, this.f |= 16, this.i++;
148
- }
149
- return n = t, g(this), this.f &= -2, !0;
150
- };
151
- s.prototype.S = function(t) {
152
- if (this.t === void 0) {
153
- this.f |= 36;
154
- for (var i = this.s; i !== void 0; i = i.n) i.S.S(i);
155
- }
156
- e.prototype.S.call(this, t);
157
- };
158
- s.prototype.U = function(t) {
159
- if (this.t !== void 0 && (e.prototype.U.call(this, t), this.t === void 0)) {
160
- this.f &= -33;
161
- for (var i = this.s; i !== void 0; i = i.n) i.S.U(i);
162
- }
163
- };
164
- s.prototype.N = function() {
165
- if (!(2 & this.f)) {
166
- this.f |= 6;
167
- for (var t = this.t; t !== void 0; t = t.x) t.t.N();
168
- }
169
- };
170
- Object.defineProperty(s.prototype, "value", { get: function() {
171
- if (1 & this.f) throw new Error("Cycle detected");
172
- var t = w(this);
173
- if (this.h(), t !== void 0 && (t.i = this.i), 16 & this.f) throw this.v;
174
- return this.v;
175
- } });
176
- function T(t, i) {
177
- return new s(t, i);
178
- }
179
- function b(t) {
180
- var i = t.u;
181
- if (t.u = void 0, typeof i == "function") {
182
- v++;
183
- var o = n;
184
- n = void 0;
185
- try {
186
- i();
187
- } catch (r) {
188
- throw t.f &= -2, t.f |= 8, p(t), r;
189
- } finally {
190
- n = o, y();
191
- }
192
- }
193
- }
194
- function p(t) {
195
- for (var i = t.s; i !== void 0; i = i.n) i.S.U(i);
196
- t.x = void 0, t.s = void 0, b(t);
197
- }
198
- function E(t) {
199
- if (n !== this) throw new Error("Out-of-order effect");
200
- g(this), n = t, this.f &= -2, 8 & this.f && p(this), y();
201
- }
202
- function u(t, i) {
203
- this.x = t, this.u = void 0, this.s = void 0, this.o = void 0, this.f = 32, this.name = i?.name;
204
- }
205
- u.prototype.c = function() {
206
- var t = this.S();
207
- try {
208
- if (8 & this.f || this.x === void 0) return;
209
- var i = this.x();
210
- typeof i == "function" && (this.u = i);
211
- } finally {
212
- t();
213
- }
214
- };
215
- u.prototype.S = function() {
216
- if (1 & this.f) throw new Error("Cycle detected");
217
- this.f |= 1, this.f &= -9, b(this), x(this), v++;
218
- var t = n;
219
- return n = this, E.bind(this, t);
220
- };
221
- u.prototype.N = function() {
222
- 2 & this.f || (this.f |= 2, this.o = d, d = this);
223
- };
224
- u.prototype.d = function() {
225
- this.f |= 8, 1 & this.f || p(this);
226
- };
227
- u.prototype.dispose = function() {
228
- this.d();
229
- };
230
- function N(t, i) {
231
- var o = new u(t, i);
232
- try {
233
- o.c();
234
- } catch (f) {
235
- throw o.d(), f;
236
- }
237
- var r = o.d.bind(o);
238
- return r[Symbol.dispose] = r, r;
239
- }
240
- function $() {
241
- return m("");
242
- }
243
- function m(t) {
244
- return new Proxy(
245
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
246
- {},
247
- {
248
- get(i, o) {
249
- if (o === "__path" || o === "__fieldPath")
250
- return t || o;
251
- if (o === "__key") {
252
- const c = t.split(".");
253
- return c[c.length - 1] || o;
254
- }
255
- const r = t ? `${t}.${o}` : o, f = {
256
- __path: r,
257
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
258
- __key: o,
259
- __formType: void 0,
260
- __fieldType: void 0
261
- };
262
- return new Proxy(f, {
263
- get(c, h) {
264
- if (h === "__path" || h === "__fieldPath")
265
- return r;
266
- if (h === "__key")
267
- return o;
268
- if (h === "__formType" || h === "__fieldType")
269
- return;
270
- const U = `${r}.${h}`;
271
- return m(U);
272
- }
273
- });
274
- }
275
- }
276
- );
277
- }
278
- export {
279
- N as E,
280
- $ as c,
281
- O as d,
282
- T as w
283
- };
@@ -1,298 +0,0 @@
1
- import { useSyncExternalStore, useCallback, useRef } from 'react';
2
- import { effect } from '@preact/signals-core';
3
- // ============================================================================
4
- // Утилиты для сравнения
5
- // ============================================================================
6
- /**
7
- * Shallow сравнение массивов по содержимому
8
- * Возвращает true если массивы равны (одинаковые элементы в том же порядке)
9
- * @internal
10
- */
11
- function shallowArrayEqual(a, b) {
12
- if (a === b)
13
- return true;
14
- if (a.length !== b.length)
15
- return false;
16
- for (let i = 0; i < a.length; i++) {
17
- if (a[i] !== b[i])
18
- return false;
19
- }
20
- return true;
21
- }
22
- // ============================================================================
23
- // Внутренние хуки для каждого типа контрола
24
- // ============================================================================
25
- /**
26
- * Внутренний хук для FieldNode с использованием useSyncExternalStore
27
- * @internal
28
- */
29
- function useFieldControl(control) {
30
- // Кеш для предотвращения лишних ре-рендеров
31
- const cacheRef = useRef({
32
- snapshot: null,
33
- value: control.value.value,
34
- errors: control.errors.value,
35
- componentProps: control.componentProps.value,
36
- disabled: control.disabled.value,
37
- pending: control.pending.value,
38
- valid: control.valid.value,
39
- invalid: control.invalid.value,
40
- touched: control.touched.value,
41
- shouldShowError: control.shouldShowError.value,
42
- });
43
- // Функция подписки - использует effect для отслеживания всех сигналов
44
- const subscribe = useCallback((onStoreChange) => {
45
- // Используем effect который автоматически отслеживает все читаемые сигналы
46
- // effect НЕ вызывает callback сразу, только при изменениях
47
- let isFirstRun = true;
48
- const dispose = effect(() => {
49
- // Читаем все сигналы чтобы effect их отслеживал
50
- control.value.value;
51
- control.disabled.value;
52
- control.errors.value;
53
- control.pending.value;
54
- control.valid.value;
55
- control.invalid.value;
56
- control.touched.value;
57
- control.shouldShowError.value;
58
- control.componentProps.value;
59
- // Пропускаем первый вызов (при создании effect)
60
- if (isFirstRun) {
61
- isFirstRun = false;
62
- return;
63
- }
64
- // Уведомляем React об изменении
65
- onStoreChange();
66
- });
67
- return dispose;
68
- }, [control]);
69
- // Функция получения текущего состояния
70
- const getSnapshot = useCallback(() => {
71
- const cache = cacheRef.current;
72
- // Получаем текущие значения из сигналов
73
- const currentValue = control.value.value;
74
- const currentErrors = control.errors.value;
75
- const currentComponentProps = control.componentProps.value;
76
- const currentDisabled = control.disabled.value;
77
- const currentPending = control.pending.value;
78
- const currentValid = control.valid.value;
79
- const currentInvalid = control.invalid.value;
80
- const currentTouched = control.touched.value;
81
- const currentShouldShowError = control.shouldShowError.value;
82
- // Проверяем, изменилось ли что-то
83
- // Используем shallowArrayEqual для errors т.к. валидация может создавать новые массивы
84
- const hasChanged = cache.value !== currentValue ||
85
- !shallowArrayEqual(cache.errors, currentErrors) ||
86
- cache.componentProps !== currentComponentProps ||
87
- cache.disabled !== currentDisabled ||
88
- cache.pending !== currentPending ||
89
- cache.valid !== currentValid ||
90
- cache.invalid !== currentInvalid ||
91
- cache.touched !== currentTouched ||
92
- cache.shouldShowError !== currentShouldShowError;
93
- // Если ничего не изменилось, возвращаем кешированный snapshot
94
- if (!hasChanged && cache.snapshot) {
95
- return cache.snapshot;
96
- }
97
- // Обновляем кеш
98
- cache.value = currentValue;
99
- cache.errors = currentErrors;
100
- cache.componentProps = currentComponentProps;
101
- cache.disabled = currentDisabled;
102
- cache.pending = currentPending;
103
- cache.valid = currentValid;
104
- cache.invalid = currentInvalid;
105
- cache.touched = currentTouched;
106
- cache.shouldShowError = currentShouldShowError;
107
- // Создаём новый snapshot
108
- cache.snapshot = {
109
- value: currentValue,
110
- pending: currentPending,
111
- disabled: currentDisabled,
112
- errors: currentErrors,
113
- valid: currentValid,
114
- invalid: currentInvalid,
115
- touched: currentTouched,
116
- shouldShowError: currentShouldShowError,
117
- componentProps: currentComponentProps,
118
- };
119
- return cache.snapshot;
120
- }, [control]);
121
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
122
- }
123
- /**
124
- * Внутренний хук для ArrayNode с использованием useSyncExternalStore
125
- * @internal
126
- */
127
- function useArrayControl(control) {
128
- // Кеш для предотвращения лишних ре-рендеров
129
- const cacheRef = useRef({
130
- snapshot: null,
131
- value: control.value.value,
132
- length: control.length.value,
133
- errors: control.errors.value,
134
- pending: control.pending.value,
135
- valid: control.valid.value,
136
- invalid: control.invalid.value,
137
- touched: control.touched.value,
138
- dirty: control.dirty.value,
139
- });
140
- // Функция подписки
141
- const subscribe = useCallback((onStoreChange) => {
142
- let isFirstRun = true;
143
- const dispose = effect(() => {
144
- // Читаем все сигналы
145
- control.value.value;
146
- control.length.value;
147
- control.errors.value;
148
- control.pending.value;
149
- control.valid.value;
150
- control.invalid.value;
151
- control.touched.value;
152
- control.dirty.value;
153
- if (isFirstRun) {
154
- isFirstRun = false;
155
- return;
156
- }
157
- onStoreChange();
158
- });
159
- return dispose;
160
- }, [control]);
161
- // Функция получения текущего состояния
162
- const getSnapshot = useCallback(() => {
163
- const cache = cacheRef.current;
164
- const currentValue = control.value.value;
165
- const currentLength = control.length.value;
166
- const currentErrors = control.errors.value;
167
- const currentPending = control.pending.value;
168
- const currentValid = control.valid.value;
169
- const currentInvalid = control.invalid.value;
170
- const currentTouched = control.touched.value;
171
- const currentDirty = control.dirty.value;
172
- const hasChanged = cache.value !== currentValue ||
173
- cache.length !== currentLength ||
174
- !shallowArrayEqual(cache.errors, currentErrors) ||
175
- cache.pending !== currentPending ||
176
- cache.valid !== currentValid ||
177
- cache.invalid !== currentInvalid ||
178
- cache.touched !== currentTouched ||
179
- cache.dirty !== currentDirty;
180
- if (!hasChanged && cache.snapshot) {
181
- return cache.snapshot;
182
- }
183
- cache.value = currentValue;
184
- cache.length = currentLength;
185
- cache.errors = currentErrors;
186
- cache.pending = currentPending;
187
- cache.valid = currentValid;
188
- cache.invalid = currentInvalid;
189
- cache.touched = currentTouched;
190
- cache.dirty = currentDirty;
191
- cache.snapshot = {
192
- value: currentValue,
193
- length: currentLength,
194
- pending: currentPending,
195
- errors: currentErrors,
196
- valid: currentValid,
197
- invalid: currentInvalid,
198
- touched: currentTouched,
199
- dirty: currentDirty,
200
- };
201
- return cache.snapshot;
202
- }, [control]);
203
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
204
- }
205
- // ============================================================================
206
- // Хук для получения только значения (без подписки на другие сигналы)
207
- // ============================================================================
208
- /**
209
- * Хук для получения только значения поля без подписки на errors, valid и т.д.
210
- * Используйте когда нужно только значение для условного рендеринга.
211
- *
212
- * @group React Hooks
213
- */
214
- export function useFormControlValue(control) {
215
- const cacheRef = useRef({
216
- value: control.value.value,
217
- snapshot: control.value.value,
218
- });
219
- const subscribe = useCallback((onStoreChange) => {
220
- let isFirstRun = true;
221
- const dispose = effect(() => {
222
- control.value.value; // Подписываемся ТОЛЬКО на value
223
- if (isFirstRun) {
224
- isFirstRun = false;
225
- return;
226
- }
227
- onStoreChange();
228
- });
229
- return dispose;
230
- }, [control]);
231
- const getSnapshot = useCallback(() => {
232
- const currentValue = control.value.value;
233
- if (cacheRef.current.value === currentValue) {
234
- return cacheRef.current.snapshot;
235
- }
236
- cacheRef.current.value = currentValue;
237
- cacheRef.current.snapshot = currentValue;
238
- return currentValue;
239
- }, [control]);
240
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
241
- }
242
- /**
243
- * Хук для работы с FieldNode или ArrayNode - возвращает состояние с подписками на сигналы
244
- *
245
- * Использует useSyncExternalStore для оптимальной интеграции с React 18+.
246
- * Компонент ре-рендерится только когда реально изменились данные контрола.
247
- *
248
- * @group React Hooks
249
- *
250
- * @example FieldNode
251
- * ```tsx
252
- * const { value, errors, componentProps } = useFormControl(control);
253
- *
254
- * return (
255
- * <div>
256
- * <input value={value} onChange={e => control.setValue(e.target.value)} />
257
- * {errors.length > 0 && <span>{errors[0].message}</span>}
258
- * </div>
259
- * );
260
- * ```
261
- *
262
- * @example ArrayNode
263
- * ```tsx
264
- * const { length } = useFormControl(arrayControl);
265
- *
266
- * return (
267
- * <div>
268
- * {arrayControl.map((item, index) => (
269
- * <ItemComponent key={item.id || index} control={item} />
270
- * ))}
271
- * {length === 0 && <span>Список пуст</span>}
272
- * </div>
273
- * );
274
- * ```
275
- */
276
- export function useFormControl(control) {
277
- // Определяем тип контрола по наличию специфичных свойств
278
- const isArrayNode = control && 'length' in control && 'map' in control;
279
- // Для undefined контрола возвращаем дефолтное состояние
280
- if (!control) {
281
- return {
282
- value: [],
283
- length: 0,
284
- pending: false,
285
- errors: [],
286
- valid: true,
287
- invalid: false,
288
- touched: false,
289
- dirty: false,
290
- };
291
- }
292
- if (isArrayNode) {
293
- // eslint-disable-next-line react-hooks/rules-of-hooks
294
- return useArrayControl(control);
295
- }
296
- // eslint-disable-next-line react-hooks/rules-of-hooks
297
- return useFieldControl(control);
298
- }