@reformer/core 10.0.0-beta.3 → 10.0.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/form/form-submitter.d.ts +0 -4
- package/dist/form/hooks/types.d.ts +3 -3
- package/dist/form/index.d.ts +0 -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/validators.d.ts +8 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +429 -617
- package/dist/runtime-token.d.ts +23 -0
- 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 +144 -1557
- package/package.json +33 -10
package/dist/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { c as
|
|
3
|
-
import { i as
|
|
4
|
-
import { m as Ye, u as
|
|
1
|
+
import { c as Le } from "./form-model-DYCzGGKF.js";
|
|
2
|
+
import { c as $e, a as Ge, r as je, b as Ue, d as Be, e as We, f as qe, s as Ke, t as He, w as ze } from "./behaviors-value-C7dSEhCc.js";
|
|
3
|
+
import { i as $ } from "./derived-registry-CluZCQ7U.js";
|
|
4
|
+
import { m as Ye, u as Qe } from "./derived-registry-CluZCQ7U.js";
|
|
5
5
|
import { S as I } from "./subscription-manager-705bls97.js";
|
|
6
|
-
import {
|
|
7
|
-
import { signal as g, computed as c, effect as E, batch as X, Signal as $ } from "@preact/signals-core";
|
|
6
|
+
import { signal as g, computed as f, effect as _, batch as X, Signal as G } from "@preact/signals-core";
|
|
8
7
|
import { r as Z } from "./signal-node-registry-tiwel-TV.js";
|
|
9
|
-
import { g as
|
|
10
|
-
import { d as
|
|
11
|
-
import
|
|
8
|
+
import { g as Ze } from "./signal-node-registry-tiwel-TV.js";
|
|
9
|
+
import { d as tt, e as st } from "./behaviors-node-DGEFMTQu.js";
|
|
10
|
+
import H, { useRef as V, useCallback as b, useMemo as ee, useEffect as te } from "react";
|
|
12
11
|
import { createFormValidation as se } from "./validation.js";
|
|
13
12
|
class M {
|
|
14
13
|
// ============================================================================
|
|
@@ -36,33 +35,21 @@ class M {
|
|
|
36
35
|
* Пользователь взаимодействовал с узлом (touched)
|
|
37
36
|
* Computed из _touched для предоставления readonly интерфейса
|
|
38
37
|
*/
|
|
39
|
-
touched =
|
|
40
|
-
/**
|
|
41
|
-
* Пользователь не взаимодействовал с узлом (untouched)
|
|
42
|
-
*/
|
|
43
|
-
untouched = c(() => !this._touched.value);
|
|
38
|
+
touched = f(() => this._touched.value);
|
|
44
39
|
/**
|
|
45
40
|
* Значение узла было изменено (dirty)
|
|
46
41
|
* Computed из _dirty для предоставления readonly интерфейса
|
|
47
42
|
*/
|
|
48
|
-
dirty =
|
|
49
|
-
/**
|
|
50
|
-
* Значение узла не было изменено (pristine)
|
|
51
|
-
*/
|
|
52
|
-
pristine = c(() => !this._dirty.value);
|
|
43
|
+
dirty = f(() => this._dirty.value);
|
|
53
44
|
/**
|
|
54
45
|
* Текущий статус узла
|
|
55
46
|
* Computed из _status для предоставления readonly интерфейса
|
|
56
47
|
*/
|
|
57
|
-
status =
|
|
48
|
+
status = f(() => this._status.value);
|
|
58
49
|
/**
|
|
59
50
|
* Узел отключен (disabled)
|
|
60
51
|
*/
|
|
61
|
-
disabled =
|
|
62
|
-
/**
|
|
63
|
-
* Узел включен (enabled)
|
|
64
|
-
*/
|
|
65
|
-
enabled = c(() => this._status.value !== "disabled");
|
|
52
|
+
disabled = f(() => this._status.value === "disabled");
|
|
66
53
|
/**
|
|
67
54
|
* Получить ошибки валидации с фильтрацией
|
|
68
55
|
*
|
|
@@ -110,8 +97,8 @@ class M {
|
|
|
110
97
|
if (e.params !== void 0) {
|
|
111
98
|
if (!s.params)
|
|
112
99
|
return !1;
|
|
113
|
-
for (const [
|
|
114
|
-
if (s.params[
|
|
100
|
+
for (const [r, n] of Object.entries(e.params))
|
|
101
|
+
if (s.params[r] !== n)
|
|
115
102
|
return !1;
|
|
116
103
|
}
|
|
117
104
|
return !(e.predicate !== void 0 && !e.predicate(s));
|
|
@@ -287,7 +274,7 @@ class M {
|
|
|
287
274
|
onEnable() {
|
|
288
275
|
}
|
|
289
276
|
}
|
|
290
|
-
const
|
|
277
|
+
const O = {
|
|
291
278
|
/** FieldNode.watch() */
|
|
292
279
|
Watch: "watch",
|
|
293
280
|
/** FieldNode.computeFrom() */
|
|
@@ -295,20 +282,16 @@ const w = {
|
|
|
295
282
|
/** GroupNode.linkFields() */
|
|
296
283
|
LinkFields: "linkFields",
|
|
297
284
|
/** GroupNode.watchField() */
|
|
298
|
-
WatchField: "watchField"
|
|
299
|
-
/** ArrayNode.watchItems() */
|
|
300
|
-
WatchItems: "watchItems",
|
|
301
|
-
/** ArrayNode.watchLength() */
|
|
302
|
-
WatchLength: "watchLength"
|
|
285
|
+
WatchField: "watchField"
|
|
303
286
|
};
|
|
304
|
-
let
|
|
305
|
-
function
|
|
306
|
-
return `${
|
|
287
|
+
let re = 0;
|
|
288
|
+
function N(i) {
|
|
289
|
+
return `${i}-${++re}`;
|
|
307
290
|
}
|
|
308
|
-
var A = /* @__PURE__ */ ((
|
|
309
|
-
class
|
|
291
|
+
var A = /* @__PURE__ */ ((i) => (i.THROW = "throw", i.LOG = "log", i.CONVERT = "convert", i))(A || {});
|
|
292
|
+
class k {
|
|
310
293
|
static handle(e, t, s = "throw") {
|
|
311
|
-
const
|
|
294
|
+
const r = this.extractMessage(e);
|
|
312
295
|
switch (process.env.NODE_ENV !== "production" && console.error(`[${t}]`, e), s) {
|
|
313
296
|
case "throw":
|
|
314
297
|
throw e;
|
|
@@ -317,7 +300,7 @@ class F {
|
|
|
317
300
|
case "convert":
|
|
318
301
|
return {
|
|
319
302
|
code: "validator_error",
|
|
320
|
-
message:
|
|
303
|
+
message: r,
|
|
321
304
|
params: { field: t }
|
|
322
305
|
};
|
|
323
306
|
}
|
|
@@ -399,7 +382,7 @@ class F {
|
|
|
399
382
|
return typeof e == "object" && e !== null && "code" in e && "message" in e && typeof e.code == "string" && typeof e.message == "string";
|
|
400
383
|
}
|
|
401
384
|
}
|
|
402
|
-
class
|
|
385
|
+
class ie {
|
|
403
386
|
/** Внутренний сигнал статуса */
|
|
404
387
|
_status;
|
|
405
388
|
/** Публичный read-only сигнал статуса */
|
|
@@ -416,7 +399,7 @@ class re {
|
|
|
416
399
|
* @param initial - Начальный статус (по умолчанию 'valid')
|
|
417
400
|
*/
|
|
418
401
|
constructor(e = "valid") {
|
|
419
|
-
this._status = g(e), this.status =
|
|
402
|
+
this._status = g(e), this.status = f(() => this._status.value), this.valid = f(() => this._status.value === "valid"), this.invalid = f(() => this._status.value === "invalid"), this.pending = f(() => this._status.value === "pending"), this.disabled = f(() => this._status.value === "disabled");
|
|
420
403
|
}
|
|
421
404
|
/**
|
|
422
405
|
* Начать валидацию
|
|
@@ -498,53 +481,8 @@ class re {
|
|
|
498
481
|
enable(e = !1) {
|
|
499
482
|
this._status.value = e ? "invalid" : "valid";
|
|
500
483
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Обработать событие (альтернативный API)
|
|
503
|
-
*
|
|
504
|
-
* @param event - Событие для обработки
|
|
505
|
-
*
|
|
506
|
-
* @example
|
|
507
|
-
* ```typescript
|
|
508
|
-
* statusMachine.dispatch({ type: 'START_VALIDATION' });
|
|
509
|
-
* statusMachine.dispatch({ type: 'VALIDATION_FAILURE' });
|
|
510
|
-
* ```
|
|
511
|
-
*/
|
|
512
|
-
dispatch(e) {
|
|
513
|
-
switch (e.type) {
|
|
514
|
-
case "START_VALIDATION":
|
|
515
|
-
this.startValidation();
|
|
516
|
-
break;
|
|
517
|
-
case "VALIDATION_SUCCESS":
|
|
518
|
-
this.completeValidation(!1);
|
|
519
|
-
break;
|
|
520
|
-
case "VALIDATION_FAILURE":
|
|
521
|
-
this.completeValidation(!0);
|
|
522
|
-
break;
|
|
523
|
-
case "DISABLE":
|
|
524
|
-
this.disable();
|
|
525
|
-
break;
|
|
526
|
-
case "ENABLE":
|
|
527
|
-
this.enable(e.hasErrors);
|
|
528
|
-
break;
|
|
529
|
-
case "SET_ERRORS":
|
|
530
|
-
this.setErrors(e.hasErrors);
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Получить текущий статус
|
|
536
|
-
*/
|
|
537
|
-
getStatus() {
|
|
538
|
-
return this._status.value;
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Проверить, можно ли начать валидацию
|
|
542
|
-
*/
|
|
543
|
-
canValidate() {
|
|
544
|
-
return this._status.value !== "disabled";
|
|
545
|
-
}
|
|
546
484
|
}
|
|
547
|
-
class
|
|
485
|
+
class ne extends M {
|
|
548
486
|
// ============================================================================
|
|
549
487
|
// Приватные сигналы
|
|
550
488
|
// ============================================================================
|
|
@@ -602,7 +540,7 @@ class ae extends M {
|
|
|
602
540
|
// Конструктор
|
|
603
541
|
// ============================================================================
|
|
604
542
|
constructor(e) {
|
|
605
|
-
super(), this.validators = e.validators || [], this.asyncValidators = e.asyncValidators || [], this.updateOn = e.updateOn || "blur", this.debounceMs = e.debounce || 0, this.component = e.component, this._value = e.valueSignal ?? g(e.value), this.initialValue = this._value.peek(), this._errors = g([]), this._componentProps = g(e.componentProps || {}), this.statusMachine = new
|
|
543
|
+
super(), this.validators = e.validators || [], this.asyncValidators = e.asyncValidators || [], this.updateOn = e.updateOn || "blur", this.debounceMs = e.debounce || 0, this.component = e.component, this._value = e.valueSignal ?? g(e.value), this.initialValue = this._value.peek(), this._errors = g([]), this._componentProps = g(e.componentProps || {}), this.statusMachine = new ie(e.disabled ? "disabled" : "valid"), this.value = f(() => this._value.value), this.valid = f(() => this.statusMachine.valid.value), this.invalid = f(() => this.statusMachine.invalid.value), this.pending = f(() => this.statusMachine.pending.value), this.status = f(() => this.statusMachine.status.value), this.disabled = f(() => this.statusMachine.disabled.value), this.errors = f(() => this._errors.value), this.componentProps = f(() => this._componentProps.value), this.shouldShowError = f(
|
|
606
544
|
() => this.statusMachine.invalid.value && (this._touched.value || this._dirty.value)
|
|
607
545
|
);
|
|
608
546
|
}
|
|
@@ -615,12 +553,12 @@ class ae extends M {
|
|
|
615
553
|
setValue(e, t) {
|
|
616
554
|
if (this._value.value = e, this._dirty.value = !0, t?.emitEvent === !1)
|
|
617
555
|
return;
|
|
618
|
-
const s = this.validators.length > 0 || this.asyncValidators.length > 0,
|
|
556
|
+
const s = this.validators.length > 0 || this.asyncValidators.length > 0, r = this._errors.value.length > 0;
|
|
619
557
|
if (this.updateOn === "change") {
|
|
620
558
|
this.validate();
|
|
621
559
|
return;
|
|
622
560
|
}
|
|
623
|
-
|
|
561
|
+
r && s && this.validate();
|
|
624
562
|
}
|
|
625
563
|
patchValue(e) {
|
|
626
564
|
this.setValue(e);
|
|
@@ -714,19 +652,19 @@ class ae extends M {
|
|
|
714
652
|
if (this.cancelPendingValidation(), t <= 0 || this.asyncValidators.length === 0)
|
|
715
653
|
return this.validateImmediate();
|
|
716
654
|
const s = new AbortController();
|
|
717
|
-
return new Promise((
|
|
718
|
-
this.pendingValidation = { resolve:
|
|
655
|
+
return new Promise((r) => {
|
|
656
|
+
this.pendingValidation = { resolve: r, abortController: s }, this.validateDebounceTimer = setTimeout(async () => {
|
|
719
657
|
if (this.validateDebounceTimer = void 0, s.signal.aborted) {
|
|
720
|
-
|
|
658
|
+
r(!1);
|
|
721
659
|
return;
|
|
722
660
|
}
|
|
723
661
|
this.pendingValidation = void 0;
|
|
724
|
-
const
|
|
725
|
-
|
|
662
|
+
const n = await this.validateImmediate(s);
|
|
663
|
+
r(n);
|
|
726
664
|
}, t), s.signal.addEventListener(
|
|
727
665
|
"abort",
|
|
728
666
|
() => {
|
|
729
|
-
this.validateDebounceTimer && (clearTimeout(this.validateDebounceTimer), this.validateDebounceTimer = void 0),
|
|
667
|
+
this.validateDebounceTimer && (clearTimeout(this.validateDebounceTimer), this.validateDebounceTimer = void 0), r(!1);
|
|
730
668
|
},
|
|
731
669
|
{ once: !0 }
|
|
732
670
|
);
|
|
@@ -745,17 +683,17 @@ class ae extends M {
|
|
|
745
683
|
async validateImmediate(e) {
|
|
746
684
|
const t = e ?? new AbortController();
|
|
747
685
|
e || this.currentAbortController?.abort(), this.currentAbortController = t;
|
|
748
|
-
const { signal: s } = t,
|
|
749
|
-
for (const
|
|
750
|
-
const l =
|
|
751
|
-
l &&
|
|
686
|
+
const { signal: s } = t, r = [];
|
|
687
|
+
for (const a of this.validators) {
|
|
688
|
+
const l = a(this._value.value);
|
|
689
|
+
l && r.push(l);
|
|
752
690
|
}
|
|
753
691
|
if (s.aborted)
|
|
754
692
|
return !1;
|
|
755
|
-
if (
|
|
756
|
-
this._errors.value =
|
|
757
|
-
const
|
|
758
|
-
if (this.statusMachine.setErrors(
|
|
693
|
+
if (r.length > 0) {
|
|
694
|
+
this._errors.value = r;
|
|
695
|
+
const a = r.some((l) => l.severity !== "warning");
|
|
696
|
+
if (this.statusMachine.setErrors(a), a)
|
|
759
697
|
return !1;
|
|
760
698
|
}
|
|
761
699
|
if (this.asyncValidators.length > 0) {
|
|
@@ -763,7 +701,7 @@ class ae extends M {
|
|
|
763
701
|
return !1;
|
|
764
702
|
this.statusMachine.startValidation();
|
|
765
703
|
try {
|
|
766
|
-
const
|
|
704
|
+
const a = await Promise.all(
|
|
767
705
|
this.asyncValidators.map(async (d) => {
|
|
768
706
|
if (s.aborted)
|
|
769
707
|
throw new DOMException("Validation aborted", "AbortError");
|
|
@@ -775,7 +713,7 @@ class ae extends M {
|
|
|
775
713
|
} catch (u) {
|
|
776
714
|
if (u instanceof DOMException && u.name === "AbortError")
|
|
777
715
|
throw u;
|
|
778
|
-
return
|
|
716
|
+
return k.handle(
|
|
779
717
|
u,
|
|
780
718
|
"FieldNode AsyncValidator",
|
|
781
719
|
A.CONVERT
|
|
@@ -785,20 +723,20 @@ class ae extends M {
|
|
|
785
723
|
);
|
|
786
724
|
if (s.aborted)
|
|
787
725
|
return !1;
|
|
788
|
-
const l =
|
|
726
|
+
const l = a.filter((d) => d !== null);
|
|
789
727
|
if (l.length > 0) {
|
|
790
728
|
this._errors.value = l;
|
|
791
729
|
const d = l.some((u) => u.severity !== "warning");
|
|
792
730
|
if (this.statusMachine.completeValidation(d), d)
|
|
793
731
|
return !1;
|
|
794
732
|
}
|
|
795
|
-
} catch (
|
|
796
|
-
if (
|
|
733
|
+
} catch (a) {
|
|
734
|
+
if (a instanceof DOMException && a.name === "AbortError")
|
|
797
735
|
return !1;
|
|
798
|
-
throw
|
|
736
|
+
throw a;
|
|
799
737
|
}
|
|
800
738
|
}
|
|
801
|
-
return s.aborted ? !1 : ((this.validators.length > 0 || this.asyncValidators.length > 0) && (this._errors.value = [], this.statusMachine.completeValidation(!1)), !this._errors.value.some((
|
|
739
|
+
return s.aborted ? !1 : ((this.validators.length > 0 || this.asyncValidators.length > 0) && (this._errors.value = [], this.statusMachine.completeValidation(!1)), !this._errors.value.some((a) => a.severity !== "warning"));
|
|
802
740
|
}
|
|
803
741
|
setErrors(e) {
|
|
804
742
|
this._errors.value = e;
|
|
@@ -919,11 +857,11 @@ class ae extends M {
|
|
|
919
857
|
* ```
|
|
920
858
|
*/
|
|
921
859
|
watch(e) {
|
|
922
|
-
const t = new AbortController(), s =
|
|
923
|
-
const
|
|
924
|
-
e(
|
|
925
|
-
}),
|
|
926
|
-
return this.disposers.add(
|
|
860
|
+
const t = new AbortController(), s = _(() => {
|
|
861
|
+
const n = this.value.value;
|
|
862
|
+
e(n, t.signal);
|
|
863
|
+
}), r = N(O.Watch);
|
|
864
|
+
return this.disposers.add(r, () => {
|
|
927
865
|
t.abort(), s();
|
|
928
866
|
});
|
|
929
867
|
}
|
|
@@ -950,11 +888,11 @@ class ae extends M {
|
|
|
950
888
|
* ```
|
|
951
889
|
*/
|
|
952
890
|
computeFrom(e, t) {
|
|
953
|
-
const s =
|
|
954
|
-
const
|
|
955
|
-
this.setValue(
|
|
956
|
-
}),
|
|
957
|
-
return this.disposers.add(
|
|
891
|
+
const s = _(() => {
|
|
892
|
+
const n = e.map((l) => l.value), a = t(...n);
|
|
893
|
+
this.setValue(a, { emitEvent: !1 });
|
|
894
|
+
}), r = N(O.ComputeFrom);
|
|
895
|
+
return this.disposers.add(r, s);
|
|
958
896
|
}
|
|
959
897
|
/**
|
|
960
898
|
* Очистить все ресурсы и таймеры
|
|
@@ -984,56 +922,56 @@ class ae extends M {
|
|
|
984
922
|
}
|
|
985
923
|
}
|
|
986
924
|
}
|
|
987
|
-
function L(
|
|
988
|
-
const { getChildren: e, ownErrors: t, disabled: s } =
|
|
925
|
+
function L(i) {
|
|
926
|
+
const { getChildren: e, ownErrors: t, disabled: s } = i, r = f(() => t.value.length > 0 ? !1 : e().every((o) => o.disabled.value || o.valid.value)), n = f(() => !r.value), a = f(() => e().some((o) => o.pending.value)), l = f(() => e().some((o) => o.touched.value)), d = f(() => e().some((o) => o.dirty.value)), u = f(() => {
|
|
989
927
|
const o = [...t.value];
|
|
990
|
-
for (const
|
|
991
|
-
o.push(...
|
|
928
|
+
for (const m of e())
|
|
929
|
+
o.push(...m.errors.value);
|
|
992
930
|
return o;
|
|
993
|
-
}), v =
|
|
931
|
+
}), v = f(() => s?.value ? "disabled" : a.value ? "pending" : n.value ? "invalid" : "valid");
|
|
994
932
|
return {
|
|
995
|
-
valid:
|
|
996
|
-
invalid:
|
|
997
|
-
pending:
|
|
933
|
+
valid: r,
|
|
934
|
+
invalid: n,
|
|
935
|
+
pending: a,
|
|
998
936
|
touched: l,
|
|
999
937
|
dirty: d,
|
|
1000
938
|
errors: u,
|
|
1001
939
|
status: v
|
|
1002
940
|
};
|
|
1003
941
|
}
|
|
1004
|
-
function
|
|
1005
|
-
return typeof
|
|
942
|
+
function j(i) {
|
|
943
|
+
return typeof i == "object" && i !== null && "getProxy" in i && typeof i.getProxy == "function";
|
|
1006
944
|
}
|
|
1007
|
-
const
|
|
1008
|
-
function
|
|
945
|
+
const U = "$";
|
|
946
|
+
function ae(i, e) {
|
|
1009
947
|
let t;
|
|
1010
948
|
const s = () => {
|
|
1011
949
|
if (!t) {
|
|
1012
|
-
const
|
|
1013
|
-
e.forEach((
|
|
1014
|
-
|
|
1015
|
-
}), t =
|
|
950
|
+
const r = {};
|
|
951
|
+
e.forEach((n, a) => {
|
|
952
|
+
r[a] = n && j(n) ? n.getProxy() : n;
|
|
953
|
+
}), t = r;
|
|
1016
954
|
}
|
|
1017
955
|
return t;
|
|
1018
956
|
};
|
|
1019
|
-
return new Proxy(
|
|
1020
|
-
get: (
|
|
1021
|
-
if (
|
|
957
|
+
return new Proxy(i, {
|
|
958
|
+
get: (r, n) => {
|
|
959
|
+
if (n === U)
|
|
1022
960
|
return s();
|
|
1023
|
-
if (
|
|
1024
|
-
return
|
|
1025
|
-
if (typeof
|
|
1026
|
-
const
|
|
1027
|
-
return
|
|
961
|
+
if (n in r)
|
|
962
|
+
return r[n];
|
|
963
|
+
if (typeof n == "string" && e.has(n)) {
|
|
964
|
+
const a = e.get(n);
|
|
965
|
+
return a && j(a) ? a.getProxy() : a;
|
|
1028
966
|
}
|
|
1029
967
|
},
|
|
1030
|
-
set: (
|
|
1031
|
-
has: (
|
|
1032
|
-
ownKeys: (
|
|
1033
|
-
const
|
|
1034
|
-
return [.../* @__PURE__ */ new Set([...
|
|
968
|
+
set: (r, n, a) => typeof n == "string" && e.has(n) ? !1 : (r[n] = a, !0),
|
|
969
|
+
has: (r, n) => n === U || typeof n == "string" && e.has(n) ? !0 : n in r,
|
|
970
|
+
ownKeys: (r) => {
|
|
971
|
+
const n = Reflect.ownKeys(r), a = Array.from(e.keys());
|
|
972
|
+
return [.../* @__PURE__ */ new Set([...n, ...a])];
|
|
1035
973
|
},
|
|
1036
|
-
getOwnPropertyDescriptor: (
|
|
974
|
+
getOwnPropertyDescriptor: (r, n) => typeof n == "string" && e.has(n) ? { enumerable: !0, configurable: !0 } : Reflect.getOwnPropertyDescriptor(r, n)
|
|
1037
975
|
});
|
|
1038
976
|
}
|
|
1039
977
|
class oe {
|
|
@@ -1046,7 +984,7 @@ class oe {
|
|
|
1046
984
|
/** Внутренний сигнал состояния отправки */
|
|
1047
985
|
_submitting = g(!1);
|
|
1048
986
|
/** Публичный read-only сигнал состояния отправки */
|
|
1049
|
-
submitting =
|
|
987
|
+
submitting = f(() => this._submitting.value);
|
|
1050
988
|
/**
|
|
1051
989
|
* Отправить форму
|
|
1052
990
|
*
|
|
@@ -1081,8 +1019,8 @@ class oe {
|
|
|
1081
1019
|
* ```
|
|
1082
1020
|
*/
|
|
1083
1021
|
async submit(e, t) {
|
|
1084
|
-
const { skipValidation: s = !1, skipTouch:
|
|
1085
|
-
if (
|
|
1022
|
+
const { skipValidation: s = !1, skipTouch: r = !1 } = t || {};
|
|
1023
|
+
if (r || this.form.markAsTouched(), !s && !await this.form.validate())
|
|
1086
1024
|
return null;
|
|
1087
1025
|
this._submitting.value = !0;
|
|
1088
1026
|
try {
|
|
@@ -1116,32 +1054,26 @@ class oe {
|
|
|
1116
1054
|
* ```
|
|
1117
1055
|
*/
|
|
1118
1056
|
async submitWithResult(e, t) {
|
|
1119
|
-
const { skipValidation: s = !1, skipTouch:
|
|
1120
|
-
if (
|
|
1057
|
+
const { skipValidation: s = !1, skipTouch: r = !1 } = t || {};
|
|
1058
|
+
if (r || this.form.markAsTouched(), !s && !await this.form.validate())
|
|
1121
1059
|
return { success: !1, data: null };
|
|
1122
1060
|
this._submitting.value = !0;
|
|
1123
1061
|
try {
|
|
1124
1062
|
return { success: !0, data: await e(this.form.getValue()) };
|
|
1125
|
-
} catch (
|
|
1063
|
+
} catch (n) {
|
|
1126
1064
|
return {
|
|
1127
1065
|
success: !1,
|
|
1128
1066
|
data: null,
|
|
1129
|
-
error:
|
|
1067
|
+
error: n instanceof Error ? n : new Error(String(n))
|
|
1130
1068
|
};
|
|
1131
1069
|
} finally {
|
|
1132
1070
|
this._submitting.value = !1;
|
|
1133
1071
|
}
|
|
1134
1072
|
}
|
|
1135
|
-
/**
|
|
1136
|
-
* Проверить, идет ли отправка формы
|
|
1137
|
-
*/
|
|
1138
|
-
isSubmitting() {
|
|
1139
|
-
return this._submitting.value;
|
|
1140
|
-
}
|
|
1141
1073
|
}
|
|
1142
|
-
function le(
|
|
1074
|
+
function le(i) {
|
|
1143
1075
|
const e = [];
|
|
1144
|
-
for (const t of
|
|
1076
|
+
for (const t of i.split(".")) {
|
|
1145
1077
|
const s = /^([^[\]]+)(?:\[(\d+)\])?$/.exec(t);
|
|
1146
1078
|
if (!s) return [];
|
|
1147
1079
|
e.push(s[2] !== void 0 ? { key: s[1], index: Number(s[2]) } : { key: s[1] });
|
|
@@ -1205,23 +1137,23 @@ class S extends M {
|
|
|
1205
1137
|
submitting;
|
|
1206
1138
|
constructor(e) {
|
|
1207
1139
|
super(), this.formSubmitter = new oe(this);
|
|
1208
|
-
const t = e.form, s = t != null && typeof t == "object" && ("valueSignal" in t || "value" in t),
|
|
1209
|
-
for (const [l, d] of Object.entries(
|
|
1140
|
+
const t = e.form, s = t != null && typeof t == "object" && ("valueSignal" in t || "value" in t), n = "form" in e && !s ? e.form : e;
|
|
1141
|
+
for (const [l, d] of Object.entries(n)) {
|
|
1210
1142
|
const u = this.createNode(d);
|
|
1211
1143
|
this._fields.set(l, u);
|
|
1212
1144
|
}
|
|
1213
|
-
this.value =
|
|
1145
|
+
this.value = f(() => {
|
|
1214
1146
|
const l = {};
|
|
1215
1147
|
return this._fields.forEach((d, u) => {
|
|
1216
1148
|
l[u] = d.value.value;
|
|
1217
1149
|
}), l;
|
|
1218
1150
|
});
|
|
1219
|
-
const
|
|
1151
|
+
const a = L({
|
|
1220
1152
|
getChildren: () => Array.from(this._fields.values()),
|
|
1221
1153
|
ownErrors: this._formErrors,
|
|
1222
1154
|
disabled: this._disabled
|
|
1223
1155
|
});
|
|
1224
|
-
this.valid =
|
|
1156
|
+
this.valid = a.valid, this.invalid = a.invalid, this.pending = a.pending, this.touched = a.touched, this.dirty = a.dirty, this.errors = a.errors, this.status = a.status, this.submitting = this.formSubmitter.submitting;
|
|
1225
1157
|
}
|
|
1226
1158
|
// ============================================================================
|
|
1227
1159
|
// Приватный метод для создания Proxy
|
|
@@ -1231,7 +1163,7 @@ class S extends M {
|
|
|
1231
1163
|
* @see buildFormProxy
|
|
1232
1164
|
*/
|
|
1233
1165
|
buildProxy() {
|
|
1234
|
-
return
|
|
1166
|
+
return ae(this, this._fields);
|
|
1235
1167
|
}
|
|
1236
1168
|
// ============================================================================
|
|
1237
1169
|
// Реализация абстрактных методов FormNode
|
|
@@ -1243,23 +1175,23 @@ class S extends M {
|
|
|
1243
1175
|
}), e;
|
|
1244
1176
|
}
|
|
1245
1177
|
setValue(e, t) {
|
|
1246
|
-
for (const [s,
|
|
1247
|
-
const
|
|
1248
|
-
if (
|
|
1249
|
-
const
|
|
1250
|
-
if (
|
|
1251
|
-
|
|
1178
|
+
for (const [s, r] of Object.entries(e)) {
|
|
1179
|
+
const n = this._fields.get(s);
|
|
1180
|
+
if (n) {
|
|
1181
|
+
const a = this._fieldSignals.get(n) ?? n.value;
|
|
1182
|
+
if ($(a)) continue;
|
|
1183
|
+
n.setValue(r, t);
|
|
1252
1184
|
}
|
|
1253
1185
|
}
|
|
1254
1186
|
}
|
|
1255
1187
|
patchValue(e) {
|
|
1256
1188
|
X(() => {
|
|
1257
1189
|
for (const [t, s] of Object.entries(e)) {
|
|
1258
|
-
const
|
|
1259
|
-
if (
|
|
1260
|
-
const
|
|
1261
|
-
if (
|
|
1262
|
-
|
|
1190
|
+
const r = this._fields.get(t);
|
|
1191
|
+
if (r && s !== void 0) {
|
|
1192
|
+
const n = this._fieldSignals.get(r) ?? r.value;
|
|
1193
|
+
if ($(n)) continue;
|
|
1194
|
+
r.setValue(s, { emitEvent: !1 });
|
|
1263
1195
|
}
|
|
1264
1196
|
}
|
|
1265
1197
|
});
|
|
@@ -1283,8 +1215,8 @@ class S extends M {
|
|
|
1283
1215
|
*/
|
|
1284
1216
|
reset(e) {
|
|
1285
1217
|
this._formErrors.value = [], this._fields.forEach((t, s) => {
|
|
1286
|
-
const
|
|
1287
|
-
t.reset(
|
|
1218
|
+
const r = e?.[s];
|
|
1219
|
+
t.reset(r);
|
|
1288
1220
|
});
|
|
1289
1221
|
}
|
|
1290
1222
|
/**
|
|
@@ -1331,10 +1263,6 @@ class S extends M {
|
|
|
1331
1263
|
* - form.email вместо form.fields.get('email')
|
|
1332
1264
|
* - form.address.city вместо form.fields.get('address').fields.get('city')
|
|
1333
1265
|
*
|
|
1334
|
-
* Используется в:
|
|
1335
|
-
* - BehaviorApplicator для доступа к полям в behavior functions
|
|
1336
|
-
* - ValidationApplicator для доступа к форме в tree validators
|
|
1337
|
-
*
|
|
1338
1266
|
* @returns Proxy-инстанс с типобезопасным доступом к полям или сама форма, если proxy не доступен
|
|
1339
1267
|
*
|
|
1340
1268
|
* @example
|
|
@@ -1436,13 +1364,13 @@ class S extends M {
|
|
|
1436
1364
|
if (t.length === 0)
|
|
1437
1365
|
return;
|
|
1438
1366
|
let s = this;
|
|
1439
|
-
for (const
|
|
1440
|
-
if (!(s instanceof S) || (s = s.getField(
|
|
1441
|
-
if (
|
|
1367
|
+
for (const r of t) {
|
|
1368
|
+
if (!(s instanceof S) || (s = s.getField(r.key), !s)) return;
|
|
1369
|
+
if (r.index !== void 0)
|
|
1442
1370
|
if ("at" in s && "length" in s && typeof s.at == "function") {
|
|
1443
|
-
const
|
|
1444
|
-
if (!
|
|
1445
|
-
s =
|
|
1371
|
+
const n = s.at(r.index);
|
|
1372
|
+
if (!n) return;
|
|
1373
|
+
s = n;
|
|
1446
1374
|
} else
|
|
1447
1375
|
return;
|
|
1448
1376
|
}
|
|
@@ -1476,16 +1404,16 @@ class S extends M {
|
|
|
1476
1404
|
* Связывает два поля: при изменении source автоматически обновляется target
|
|
1477
1405
|
*/
|
|
1478
1406
|
linkFields(e, t, s) {
|
|
1479
|
-
const
|
|
1480
|
-
if (!
|
|
1481
|
-
const d =
|
|
1407
|
+
const r = this._fields.get(e), n = this._fields.get(t);
|
|
1408
|
+
if (!r || !n) {
|
|
1409
|
+
const d = r ? t : e;
|
|
1482
1410
|
throw new Error(`GroupNode.linkFields: field "${String(d)}" not found`);
|
|
1483
1411
|
}
|
|
1484
|
-
const
|
|
1485
|
-
const d =
|
|
1486
|
-
|
|
1487
|
-
}), l =
|
|
1488
|
-
return this.disposers.add(l,
|
|
1412
|
+
const a = _(() => {
|
|
1413
|
+
const d = r.value.value, u = s ? s(d) : d;
|
|
1414
|
+
n.setValue(u, { emitEvent: !1 });
|
|
1415
|
+
}), l = N(O.LinkFields);
|
|
1416
|
+
return this.disposers.add(l, a);
|
|
1489
1417
|
}
|
|
1490
1418
|
/**
|
|
1491
1419
|
* Подписка на изменения вложенного поля по строковому пути
|
|
@@ -1519,10 +1447,10 @@ class S extends M {
|
|
|
1519
1447
|
const s = this.getFieldByPath(e);
|
|
1520
1448
|
if (!s)
|
|
1521
1449
|
throw new Error(`GroupNode.watchField: field "${e}" not found`);
|
|
1522
|
-
const
|
|
1450
|
+
const r = _(() => {
|
|
1523
1451
|
t(s.value.value);
|
|
1524
|
-
}),
|
|
1525
|
-
return this.disposers.add(
|
|
1452
|
+
}), n = N(O.WatchField);
|
|
1453
|
+
return this.disposers.add(n, r);
|
|
1526
1454
|
}
|
|
1527
1455
|
/**
|
|
1528
1456
|
* Подписка на вложенное поле по строковому пути ("address.city").
|
|
@@ -1532,10 +1460,10 @@ class S extends M {
|
|
|
1532
1460
|
const s = this.getFieldByPath(e);
|
|
1533
1461
|
if (!s)
|
|
1534
1462
|
throw new Error(`GroupNode.watchFieldByPath: field "${e}" not found`);
|
|
1535
|
-
const
|
|
1463
|
+
const r = _(() => {
|
|
1536
1464
|
t(s.value.value);
|
|
1537
|
-
}),
|
|
1538
|
-
return this.disposers.add(
|
|
1465
|
+
}), n = N(O.WatchField);
|
|
1466
|
+
return this.disposers.add(n, r);
|
|
1539
1467
|
}
|
|
1540
1468
|
/**
|
|
1541
1469
|
* Hook: вызывается после disable()
|
|
@@ -1574,7 +1502,7 @@ class S extends M {
|
|
|
1574
1502
|
});
|
|
1575
1503
|
}
|
|
1576
1504
|
}
|
|
1577
|
-
class
|
|
1505
|
+
class B extends M {
|
|
1578
1506
|
// ============================================================================
|
|
1579
1507
|
// Приватные поля
|
|
1580
1508
|
// ============================================================================
|
|
@@ -1589,11 +1517,6 @@ class U extends M {
|
|
|
1589
1517
|
/** Array-level validation errors (e.g., "минимум 1 элемент") */
|
|
1590
1518
|
_arrayErrors = g([]);
|
|
1591
1519
|
// ============================================================================
|
|
1592
|
-
// Приватные поля для сохранения схем
|
|
1593
|
-
// ============================================================================
|
|
1594
|
-
validationSchemaFn;
|
|
1595
|
-
behaviorSchemaFn;
|
|
1596
|
-
// ============================================================================
|
|
1597
1520
|
// Публичные computed signals
|
|
1598
1521
|
// ============================================================================
|
|
1599
1522
|
value;
|
|
@@ -1610,9 +1533,9 @@ class U extends M {
|
|
|
1610
1533
|
// ============================================================================
|
|
1611
1534
|
constructor(e, t = []) {
|
|
1612
1535
|
super(), this.itemSchema = e, this.initialItems = t, this.items = g([]);
|
|
1613
|
-
for (const
|
|
1614
|
-
this.push(
|
|
1615
|
-
this.length =
|
|
1536
|
+
for (const r of t)
|
|
1537
|
+
this.push(r);
|
|
1538
|
+
this.length = f(() => this.items.value.length), this.value = f(() => this.items.value.map((r) => r.value.value));
|
|
1616
1539
|
const s = L({
|
|
1617
1540
|
getChildren: () => this.items.value,
|
|
1618
1541
|
ownErrors: this._arrayErrors
|
|
@@ -1639,7 +1562,7 @@ class U extends M {
|
|
|
1639
1562
|
*/
|
|
1640
1563
|
removeAt(e) {
|
|
1641
1564
|
if (e < 0 || e >= this.items.value.length) {
|
|
1642
|
-
|
|
1565
|
+
k.handle(
|
|
1643
1566
|
new Error(
|
|
1644
1567
|
`ArrayNode.removeAt: index ${e} out of bounds (length: ${this.items.value.length})`
|
|
1645
1568
|
),
|
|
@@ -1649,7 +1572,7 @@ class U extends M {
|
|
|
1649
1572
|
return;
|
|
1650
1573
|
}
|
|
1651
1574
|
const t = this.items.value[e];
|
|
1652
|
-
this.items.value = this.items.value.filter((s,
|
|
1575
|
+
this.items.value = this.items.value.filter((s, r) => r !== e), t && "dispose" in t && typeof t.dispose == "function" && t.dispose();
|
|
1653
1576
|
}
|
|
1654
1577
|
/**
|
|
1655
1578
|
* Вставить элемент в массив
|
|
@@ -1658,7 +1581,7 @@ class U extends M {
|
|
|
1658
1581
|
*/
|
|
1659
1582
|
insert(e, t) {
|
|
1660
1583
|
if (e < 0 || e > this.items.value.length) {
|
|
1661
|
-
|
|
1584
|
+
k.handle(
|
|
1662
1585
|
new Error(
|
|
1663
1586
|
`ArrayNode.insert: index ${e} out of bounds (length: ${this.items.value.length})`
|
|
1664
1587
|
),
|
|
@@ -1667,8 +1590,8 @@ class U extends M {
|
|
|
1667
1590
|
);
|
|
1668
1591
|
return;
|
|
1669
1592
|
}
|
|
1670
|
-
const s = this.createItem(t),
|
|
1671
|
-
|
|
1593
|
+
const s = this.createItem(t), r = [...this.items.value];
|
|
1594
|
+
r.splice(e, 0, s), this.items.value = r;
|
|
1672
1595
|
}
|
|
1673
1596
|
/**
|
|
1674
1597
|
* Переместить элемент массива с позиции `from` на позицию `to`
|
|
@@ -1689,7 +1612,7 @@ class U extends M {
|
|
|
1689
1612
|
move(e, t) {
|
|
1690
1613
|
const s = this.items.value.length;
|
|
1691
1614
|
if (e < 0 || e >= s || t < 0 || t >= s) {
|
|
1692
|
-
|
|
1615
|
+
k.handle(
|
|
1693
1616
|
new Error(`ArrayNode.move: index out of bounds (from=${e}, to=${t}, length=${s})`),
|
|
1694
1617
|
"ArrayNode.move",
|
|
1695
1618
|
A.LOG
|
|
@@ -1697,8 +1620,8 @@ class U extends M {
|
|
|
1697
1620
|
return;
|
|
1698
1621
|
}
|
|
1699
1622
|
if (e === t) return;
|
|
1700
|
-
const
|
|
1701
|
-
|
|
1623
|
+
const r = [...this.items.value], [n] = r.splice(e, 1);
|
|
1624
|
+
r.splice(t, 0, n), this.items.value = r;
|
|
1702
1625
|
}
|
|
1703
1626
|
/**
|
|
1704
1627
|
* Поменять местами два элемента массива
|
|
@@ -1717,7 +1640,7 @@ class U extends M {
|
|
|
1717
1640
|
swap(e, t) {
|
|
1718
1641
|
const s = this.items.value.length;
|
|
1719
1642
|
if (e < 0 || e >= s || t < 0 || t >= s) {
|
|
1720
|
-
|
|
1643
|
+
k.handle(
|
|
1721
1644
|
new Error(`ArrayNode.swap: index out of bounds (a=${e}, b=${t}, length=${s})`),
|
|
1722
1645
|
"ArrayNode.swap",
|
|
1723
1646
|
A.LOG
|
|
@@ -1725,8 +1648,8 @@ class U extends M {
|
|
|
1725
1648
|
return;
|
|
1726
1649
|
}
|
|
1727
1650
|
if (e === t) return;
|
|
1728
|
-
const
|
|
1729
|
-
[
|
|
1651
|
+
const r = [...this.items.value];
|
|
1652
|
+
[r[e], r[t]] = [r[t], r[e]], this.items.value = r;
|
|
1730
1653
|
}
|
|
1731
1654
|
/**
|
|
1732
1655
|
* Удалить все элементы массива
|
|
@@ -1758,7 +1681,7 @@ class U extends M {
|
|
|
1758
1681
|
}
|
|
1759
1682
|
setValue(e, t) {
|
|
1760
1683
|
this.clear(), e.forEach((s) => this.push(s)), t?.emitEvent !== !1 && this.validate().catch((s) => {
|
|
1761
|
-
|
|
1684
|
+
k.handle(s, "ArrayNode.setValue", A.LOG);
|
|
1762
1685
|
});
|
|
1763
1686
|
}
|
|
1764
1687
|
patchValue(e) {
|
|
@@ -1892,8 +1815,8 @@ class U extends M {
|
|
|
1892
1815
|
*/
|
|
1893
1816
|
forEach(e) {
|
|
1894
1817
|
this.items.value.forEach((t, s) => {
|
|
1895
|
-
const
|
|
1896
|
-
e(
|
|
1818
|
+
const r = t.getProxy();
|
|
1819
|
+
e(r, s);
|
|
1897
1820
|
});
|
|
1898
1821
|
}
|
|
1899
1822
|
/**
|
|
@@ -1903,8 +1826,8 @@ class U extends M {
|
|
|
1903
1826
|
*/
|
|
1904
1827
|
map(e) {
|
|
1905
1828
|
return this.items.value.map((t, s) => {
|
|
1906
|
-
const
|
|
1907
|
-
return e(
|
|
1829
|
+
const r = t.getProxy();
|
|
1830
|
+
return e(r, s);
|
|
1908
1831
|
});
|
|
1909
1832
|
}
|
|
1910
1833
|
// ============================================================================
|
|
@@ -1917,7 +1840,7 @@ class U extends M {
|
|
|
1917
1840
|
createItem(e) {
|
|
1918
1841
|
if (this.isGroupSchema(this.itemSchema)) {
|
|
1919
1842
|
const t = new S(this.itemSchema);
|
|
1920
|
-
return e && t.patchValue(e),
|
|
1843
|
+
return e && t.patchValue(e), t;
|
|
1921
1844
|
}
|
|
1922
1845
|
throw new Error(
|
|
1923
1846
|
"ArrayNode поддерживает только GroupNode элементы. Для массива примитивов используйте обычное поле с типом массива."
|
|
@@ -1931,116 +1854,8 @@ class U extends M {
|
|
|
1931
1854
|
return typeof e == "object" && e !== null && !("component" in e) && !Array.isArray(e);
|
|
1932
1855
|
}
|
|
1933
1856
|
// ============================================================================
|
|
1934
|
-
// Validation Schema
|
|
1935
|
-
// ============================================================================
|
|
1936
|
-
/**
|
|
1937
|
-
* Применить validation schema ко всем элементам массива
|
|
1938
|
-
*
|
|
1939
|
-
* Validation schema будет применена к:
|
|
1940
|
-
* - Всем существующим элементам
|
|
1941
|
-
* - Всем новым элементам, добавляемым через push/insert
|
|
1942
|
-
*
|
|
1943
|
-
* @param schemaFn - Функция валидации для элемента массива
|
|
1944
|
-
*
|
|
1945
|
-
* @example
|
|
1946
|
-
* ```typescript
|
|
1947
|
-
* import { propertyValidation } from './validation/property-validation';
|
|
1948
|
-
*
|
|
1949
|
-
* form.properties.applyValidationSchema(propertyValidation);
|
|
1950
|
-
* ```
|
|
1951
|
-
*/
|
|
1952
|
-
applyValidationSchema(e) {
|
|
1953
|
-
this.validationSchemaFn = e, this.items.value.forEach((t) => {
|
|
1954
|
-
"applyValidationSchema" in t && typeof t.applyValidationSchema == "function" && t.applyValidationSchema(e);
|
|
1955
|
-
});
|
|
1956
|
-
}
|
|
1957
|
-
/**
|
|
1958
|
-
* Применить behavior schema ко всем элементам ArrayNode
|
|
1959
|
-
*
|
|
1960
|
-
* Автоматически применяется к новым элементам при push/insert.
|
|
1961
|
-
*
|
|
1962
|
-
* @param schemaFn - Behavior schema функция
|
|
1963
|
-
*
|
|
1964
|
-
* @example
|
|
1965
|
-
* ```typescript
|
|
1966
|
-
* import { addressBehavior } from './behaviors/address-behavior';
|
|
1967
|
-
*
|
|
1968
|
-
* form.addresses.applyBehaviorSchema(addressBehavior);
|
|
1969
|
-
* ```
|
|
1970
|
-
*/
|
|
1971
|
-
applyBehaviorSchema(e) {
|
|
1972
|
-
this.behaviorSchemaFn = e, this.items.value.forEach((t) => {
|
|
1973
|
-
"applyBehaviorSchema" in t && typeof t.applyBehaviorSchema == "function" && t.applyBehaviorSchema(e);
|
|
1974
|
-
});
|
|
1975
|
-
}
|
|
1976
|
-
// ============================================================================
|
|
1977
1857
|
// Методы-помощники для реактивности (Фаза 1)
|
|
1978
1858
|
// ============================================================================
|
|
1979
|
-
/**
|
|
1980
|
-
* Подписка на изменения конкретного поля во всех элементах массива
|
|
1981
|
-
* Срабатывает при изменении значения поля в любом элементе
|
|
1982
|
-
*
|
|
1983
|
-
* @param fieldKey - Ключ поля для отслеживания
|
|
1984
|
-
* @param callback - Функция, вызываемая при изменении, получает массив всех значений и индекс измененного элемента
|
|
1985
|
-
* @returns Функция отписки для cleanup
|
|
1986
|
-
*
|
|
1987
|
-
* @example
|
|
1988
|
-
* ```typescript
|
|
1989
|
-
* // Автоматический пересчет общей стоимости при изменении цен
|
|
1990
|
-
* const dispose = form.existingLoans.watchItems(
|
|
1991
|
-
* 'remainingAmount',
|
|
1992
|
-
* (amounts) => {
|
|
1993
|
-
* const totalDebt = amounts.reduce((sum, amount) => sum + (amount || 0), 0);
|
|
1994
|
-
* form.totalDebt.setValue(totalDebt);
|
|
1995
|
-
* }
|
|
1996
|
-
* );
|
|
1997
|
-
*
|
|
1998
|
-
* // При изменении любого remainingAmount → пересчитается totalDebt
|
|
1999
|
-
* form.existingLoans.at(0)?.remainingAmount.setValue(500000);
|
|
2000
|
-
*
|
|
2001
|
-
* // Cleanup
|
|
2002
|
-
* useEffect(() => dispose, []);
|
|
2003
|
-
* ```
|
|
2004
|
-
*/
|
|
2005
|
-
watchItems(e, t) {
|
|
2006
|
-
const s = E(() => {
|
|
2007
|
-
const a = this.items.value.map((n) => {
|
|
2008
|
-
if (n instanceof S)
|
|
2009
|
-
return n.getFieldByPath(e)?.value.value;
|
|
2010
|
-
});
|
|
2011
|
-
t(a);
|
|
2012
|
-
}), i = V(w.WatchItems);
|
|
2013
|
-
return this.disposers.add(i, s);
|
|
2014
|
-
}
|
|
2015
|
-
/**
|
|
2016
|
-
* Подписка на изменение длины массива
|
|
2017
|
-
* Срабатывает при добавлении/удалении элементов
|
|
2018
|
-
*
|
|
2019
|
-
* @param callback - Функция, вызываемая при изменении длины, получает новую длину
|
|
2020
|
-
* @returns Функция отписки для cleanup
|
|
2021
|
-
*
|
|
2022
|
-
* @example
|
|
2023
|
-
* ```typescript
|
|
2024
|
-
* // Обновление счетчика элементов в UI
|
|
2025
|
-
* const dispose = form.properties.watchLength((length) => {
|
|
2026
|
-
* console.log(`Количество объектов недвижимости: ${length}`);
|
|
2027
|
-
* form.propertyCount.setValue(length);
|
|
2028
|
-
* });
|
|
2029
|
-
*
|
|
2030
|
-
* form.properties.push({ title: 'Квартира', value: 5000000 });
|
|
2031
|
-
* // Выведет: "Количество объектов недвижимости: 1"
|
|
2032
|
-
*
|
|
2033
|
-
* // Cleanup
|
|
2034
|
-
* useEffect(() => dispose, []);
|
|
2035
|
-
* ```
|
|
2036
|
-
*/
|
|
2037
|
-
watchLength(e) {
|
|
2038
|
-
const t = E(() => {
|
|
2039
|
-
const i = this.length.value;
|
|
2040
|
-
e(i);
|
|
2041
|
-
}), s = V(w.WatchLength);
|
|
2042
|
-
return this.disposers.add(s, t);
|
|
2043
|
-
}
|
|
2044
1859
|
/**
|
|
2045
1860
|
* Очистить все ресурсы узла
|
|
2046
1861
|
* Рекурсивно очищает все subscriptions и элементы массива
|
|
@@ -2152,9 +1967,9 @@ class ue {
|
|
|
2152
1967
|
if (Array.isArray(e) && e.length >= 1)
|
|
2153
1968
|
return this.createArrayNodeFromArray(e);
|
|
2154
1969
|
if (this.isFieldConfig(e))
|
|
2155
|
-
return new
|
|
1970
|
+
return new ne(e);
|
|
2156
1971
|
if (this.isArrayConfig(e))
|
|
2157
|
-
return new
|
|
1972
|
+
return new B(
|
|
2158
1973
|
e.schema,
|
|
2159
1974
|
e.initialItems
|
|
2160
1975
|
);
|
|
@@ -2193,11 +2008,11 @@ class ue {
|
|
|
2193
2008
|
*/
|
|
2194
2009
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2195
2010
|
createArrayNodeFromArray(e) {
|
|
2196
|
-
const [t, ...s] = e,
|
|
2197
|
-
this.isGroupConfig(t) &&
|
|
2198
|
-
for (const
|
|
2199
|
-
this.isGroupConfig(
|
|
2200
|
-
return new
|
|
2011
|
+
const [t, ...s] = e, r = [];
|
|
2012
|
+
this.isGroupConfig(t) && r.push(this.extractValues(t));
|
|
2013
|
+
for (const n of s)
|
|
2014
|
+
this.isGroupConfig(n) ? r.push(this.extractValues(n)) : r.push(n);
|
|
2015
|
+
return new B(t, r);
|
|
2201
2016
|
}
|
|
2202
2017
|
/**
|
|
2203
2018
|
* Извлечь значения из схемы (рекурсивно)
|
|
@@ -2235,8 +2050,8 @@ class ue {
|
|
|
2235
2050
|
return e.map((t) => this.extractValues(t));
|
|
2236
2051
|
if (this.isGroupConfig(e)) {
|
|
2237
2052
|
const t = {};
|
|
2238
|
-
for (const [s,
|
|
2239
|
-
t[s] = this.extractValues(
|
|
2053
|
+
for (const [s, r] of Object.entries(e))
|
|
2054
|
+
t[s] = this.extractValues(r);
|
|
2240
2055
|
return t;
|
|
2241
2056
|
}
|
|
2242
2057
|
return e;
|
|
@@ -2323,22 +2138,22 @@ class de extends M {
|
|
|
2323
2138
|
* импорта с `create-form`). Обычно `(item) => createForm({ model: item, schema: itemSchema(item) })`.
|
|
2324
2139
|
*/
|
|
2325
2140
|
constructor(e, t) {
|
|
2326
|
-
super(), this.control = e, this.buildItem = t, this.initial = e.toArray(), this.disposeSync =
|
|
2327
|
-
const
|
|
2328
|
-
for (let u = 0; u <
|
|
2141
|
+
super(), this.control = e, this.buildItem = t, this.initial = e.toArray(), this.disposeSync = _(() => {
|
|
2142
|
+
const r = e.length, n = [], a = [];
|
|
2143
|
+
for (let u = 0; u < r; u++) {
|
|
2329
2144
|
const v = e.at(u);
|
|
2330
2145
|
if (!v) continue;
|
|
2331
2146
|
let o = this.cache.get(v);
|
|
2332
|
-
o || (o = t(v), this.cache.set(v, o)),
|
|
2147
|
+
o || (o = t(v), this.cache.set(v, o)), n.push(v), a.push(o);
|
|
2333
2148
|
}
|
|
2334
|
-
const l = new Set(
|
|
2149
|
+
const l = new Set(n), d = [];
|
|
2335
2150
|
for (const u of this.mountedModels) {
|
|
2336
2151
|
if (l.has(u)) continue;
|
|
2337
2152
|
const v = this.cache.get(u);
|
|
2338
2153
|
this.cache.delete(u), v && d.push(v);
|
|
2339
2154
|
}
|
|
2340
|
-
this.mountedModels =
|
|
2341
|
-
}), this.length =
|
|
2155
|
+
this.mountedModels = n, this.itemNodes.value = a, d.forEach((u) => this.disposeItemNode(u));
|
|
2156
|
+
}), this.length = f(() => this.itemNodes.value.length), this.value = f(() => this.itemNodes.value.map((r) => r.value.value));
|
|
2342
2157
|
const s = L({
|
|
2343
2158
|
getChildren: () => this.itemNodes.value,
|
|
2344
2159
|
ownErrors: this._arrayErrors
|
|
@@ -2478,230 +2293,228 @@ class de extends M {
|
|
|
2478
2293
|
this.disposeSync(), this.itemNodes.value.forEach((e) => this.disposeItemNode(e)), this.mountedModels = [];
|
|
2479
2294
|
}
|
|
2480
2295
|
}
|
|
2481
|
-
const
|
|
2482
|
-
function D(
|
|
2483
|
-
if (
|
|
2484
|
-
if (Array.isArray(
|
|
2485
|
-
for (const
|
|
2296
|
+
const z = (i) => i !== null && typeof i == "object" && !Array.isArray(i) && !(i instanceof Date) && !(typeof Blob < "u" && i instanceof Blob) && !(typeof File < "u" && i instanceof File);
|
|
2297
|
+
function D(i, e, t) {
|
|
2298
|
+
if (i == null || typeof i != "object" || i instanceof G) return;
|
|
2299
|
+
if (Array.isArray(i)) {
|
|
2300
|
+
for (const n of i) D(n, e, t);
|
|
2486
2301
|
return;
|
|
2487
2302
|
}
|
|
2488
|
-
const s =
|
|
2489
|
-
if (
|
|
2490
|
-
t.set(
|
|
2303
|
+
const s = i, r = s.array;
|
|
2304
|
+
if (r && typeof r.__path == "string" && typeof s.item == "function") {
|
|
2305
|
+
t.set(r.__path, s.item);
|
|
2491
2306
|
return;
|
|
2492
2307
|
}
|
|
2493
|
-
s.value instanceof
|
|
2308
|
+
s.value instanceof G ? e.set(s.value, {
|
|
2494
2309
|
component: s.component,
|
|
2495
2310
|
componentProps: s.componentProps,
|
|
2496
|
-
validators: s.validators,
|
|
2497
|
-
asyncValidators: s.asyncValidators,
|
|
2498
2311
|
updateOn: s.updateOn,
|
|
2499
2312
|
disabled: s.disabled,
|
|
2500
2313
|
debounce: s.debounce
|
|
2501
2314
|
}) : process.env.NODE_ENV !== "production" && s.component !== void 0 && ("valueSignal" in s || s.value != null) && console.warn(
|
|
2502
2315
|
"[reformer] createForm({ schema }): узел с `component` не распознан как поле — `value` не является сигналом модели. Ожидается `value: model.$.<path>`; проверьте, что не передан `value: model.<path>` (value-прокси) или `valueSignal:`."
|
|
2503
2316
|
);
|
|
2504
|
-
for (const [
|
|
2505
|
-
|
|
2317
|
+
for (const [n, a] of Object.entries(s))
|
|
2318
|
+
n !== "value" && D(a, e, t);
|
|
2506
2319
|
}
|
|
2507
|
-
function
|
|
2508
|
-
const
|
|
2509
|
-
for (const [
|
|
2510
|
-
const l = t === "" ?
|
|
2511
|
-
if (Array.isArray(
|
|
2320
|
+
function J(i, e, t, s) {
|
|
2321
|
+
const r = {};
|
|
2322
|
+
for (const [n, a] of Object.entries(e)) {
|
|
2323
|
+
const l = t === "" ? n : `${t}.${n}`;
|
|
2324
|
+
if (Array.isArray(a))
|
|
2512
2325
|
continue;
|
|
2513
|
-
if (
|
|
2514
|
-
|
|
2326
|
+
if (z(a)) {
|
|
2327
|
+
r[n] = J(i, a, l, s);
|
|
2515
2328
|
continue;
|
|
2516
2329
|
}
|
|
2517
|
-
const d =
|
|
2330
|
+
const d = i.signalAt(l);
|
|
2518
2331
|
if (!d) throw new Error(`createForm({ model }): не найден сигнал для пути "${l}"`);
|
|
2519
|
-
const u = s.get(d) ?? {}
|
|
2520
|
-
|
|
2332
|
+
const u = s.get(d) ?? {};
|
|
2333
|
+
r[n] = { ...u, valueSignal: d };
|
|
2521
2334
|
}
|
|
2522
|
-
return
|
|
2335
|
+
return r;
|
|
2523
2336
|
}
|
|
2524
|
-
function
|
|
2525
|
-
for (const [s,
|
|
2526
|
-
const
|
|
2527
|
-
Array.isArray(
|
|
2337
|
+
function Y(i, e, t) {
|
|
2338
|
+
for (const [s, r] of Object.entries(i)) {
|
|
2339
|
+
const n = e === "" ? s : `${e}.${s}`;
|
|
2340
|
+
Array.isArray(r) || (z(r) ? Y(r, n, t) : t.push(n));
|
|
2528
2341
|
}
|
|
2529
2342
|
}
|
|
2530
|
-
function Q(
|
|
2531
|
-
const { model: e, schema: t, behavior: s } =
|
|
2532
|
-
t !== void 0 && D(t,
|
|
2533
|
-
const
|
|
2534
|
-
for (const [o,
|
|
2535
|
-
if (!Array.isArray(
|
|
2536
|
-
const
|
|
2537
|
-
if (!
|
|
2538
|
-
const
|
|
2539
|
-
l.fields.set(o,
|
|
2343
|
+
function Q(i) {
|
|
2344
|
+
const { model: e, schema: t, behavior: s } = i, r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
2345
|
+
t !== void 0 && D(t, r, n);
|
|
2346
|
+
const a = J(e, e.get(), "", r), l = new S(a), d = e.get();
|
|
2347
|
+
for (const [o, m] of Object.entries(d)) {
|
|
2348
|
+
if (!Array.isArray(m)) continue;
|
|
2349
|
+
const c = n.get(o);
|
|
2350
|
+
if (!c) continue;
|
|
2351
|
+
const h = e[o], p = (y) => Q({ model: y, schema: c(y) }), E = new de(h, p);
|
|
2352
|
+
l.fields.set(o, E);
|
|
2540
2353
|
}
|
|
2541
2354
|
const u = l.getProxy(), v = [];
|
|
2542
|
-
|
|
2355
|
+
Y(e.get(), "", v);
|
|
2543
2356
|
for (const o of v) {
|
|
2544
|
-
const
|
|
2545
|
-
if (
|
|
2546
|
-
Z(
|
|
2547
|
-
const
|
|
2548
|
-
|
|
2357
|
+
const m = e.signalAt(o), c = l.getFieldByPath(o);
|
|
2358
|
+
if (m && c) {
|
|
2359
|
+
Z(m, c);
|
|
2360
|
+
const h = o.lastIndexOf("."), p = h === -1 ? l : l.getFieldByPath(o.slice(0, h));
|
|
2361
|
+
p instanceof S && p.registerFieldSignal(c, m);
|
|
2549
2362
|
}
|
|
2550
2363
|
}
|
|
2551
2364
|
return s && l.attachBehaviorCleanup(s.__run(e, u)), u;
|
|
2552
2365
|
}
|
|
2553
|
-
const
|
|
2554
|
-
function
|
|
2555
|
-
return
|
|
2366
|
+
const ce = (i) => i != null && typeof i == "object" && "model" in i && typeof i.model?.signalAt == "function";
|
|
2367
|
+
function Ne(i) {
|
|
2368
|
+
return ce(i) ? Q(i) : new S(i).getProxy();
|
|
2556
2369
|
}
|
|
2557
|
-
function x(
|
|
2558
|
-
return
|
|
2370
|
+
function x(i) {
|
|
2371
|
+
return i == null ? !1 : typeof i == "object" && "value" in i && "setValue" in i && "getValue" in i && "validate" in i;
|
|
2559
2372
|
}
|
|
2560
|
-
function
|
|
2561
|
-
return
|
|
2373
|
+
function he(i) {
|
|
2374
|
+
return x(i) && "validators" in i && "asyncValidators" in i && // FieldNode имеет markAsTouched метод
|
|
2562
2375
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2563
|
-
typeof
|
|
2564
|
-
!("fields" in
|
|
2376
|
+
typeof i.markAsTouched == "function" && // У FieldNode нет fields или items
|
|
2377
|
+
!("fields" in i) && !("items" in i);
|
|
2565
2378
|
}
|
|
2566
|
-
function fe(
|
|
2567
|
-
return
|
|
2568
|
-
!("items" in
|
|
2379
|
+
function fe(i) {
|
|
2380
|
+
return x(i) && "getFieldByPath" in i && "fields" in i && // GroupNode НЕ имеет items/push/removeAt (это ArrayNode/ModelArrayNode)
|
|
2381
|
+
!("items" in i) && !("push" in i) && !("removeAt" in i);
|
|
2569
2382
|
}
|
|
2570
|
-
function ve(
|
|
2571
|
-
return
|
|
2572
|
-
typeof
|
|
2573
|
-
typeof
|
|
2383
|
+
function ve(i) {
|
|
2384
|
+
return x(i) && "items" in i && "length" in i && "push" in i && "removeAt" in i && "at" in i && // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2385
|
+
typeof i.push == "function" && // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2386
|
+
typeof i.removeAt == "function";
|
|
2574
2387
|
}
|
|
2575
|
-
function
|
|
2576
|
-
return
|
|
2388
|
+
function Fe(i) {
|
|
2389
|
+
return he(i) ? "FieldNode" : fe(i) ? "GroupNode" : ve(i) ? "ArrayNode" : x(i) ? "FormNode" : "Unknown";
|
|
2577
2390
|
}
|
|
2578
|
-
var
|
|
2391
|
+
var F = { exports: {} }, P = {};
|
|
2579
2392
|
var W;
|
|
2580
|
-
function
|
|
2393
|
+
function me() {
|
|
2581
2394
|
if (W) return P;
|
|
2582
2395
|
W = 1;
|
|
2583
|
-
var
|
|
2584
|
-
function e(o,
|
|
2585
|
-
return o ===
|
|
2586
|
-
}
|
|
2587
|
-
var t = typeof Object.is == "function" ? Object.is : e, s =
|
|
2588
|
-
function l(o,
|
|
2589
|
-
var
|
|
2590
|
-
return
|
|
2396
|
+
var i = H;
|
|
2397
|
+
function e(o, m) {
|
|
2398
|
+
return o === m && (o !== 0 || 1 / o === 1 / m) || o !== o && m !== m;
|
|
2399
|
+
}
|
|
2400
|
+
var t = typeof Object.is == "function" ? Object.is : e, s = i.useState, r = i.useEffect, n = i.useLayoutEffect, a = i.useDebugValue;
|
|
2401
|
+
function l(o, m) {
|
|
2402
|
+
var c = m(), h = s({ inst: { value: c, getSnapshot: m } }), p = h[0].inst, E = h[1];
|
|
2403
|
+
return n(
|
|
2591
2404
|
function() {
|
|
2592
|
-
|
|
2405
|
+
p.value = c, p.getSnapshot = m, d(p) && E({ inst: p });
|
|
2593
2406
|
},
|
|
2594
|
-
[o,
|
|
2595
|
-
),
|
|
2407
|
+
[o, c, m]
|
|
2408
|
+
), r(
|
|
2596
2409
|
function() {
|
|
2597
|
-
return d(
|
|
2598
|
-
d(
|
|
2410
|
+
return d(p) && E({ inst: p }), o(function() {
|
|
2411
|
+
d(p) && E({ inst: p });
|
|
2599
2412
|
});
|
|
2600
2413
|
},
|
|
2601
2414
|
[o]
|
|
2602
|
-
),
|
|
2415
|
+
), a(c), c;
|
|
2603
2416
|
}
|
|
2604
2417
|
function d(o) {
|
|
2605
|
-
var
|
|
2418
|
+
var m = o.getSnapshot;
|
|
2606
2419
|
o = o.value;
|
|
2607
2420
|
try {
|
|
2608
|
-
var
|
|
2609
|
-
return !t(o,
|
|
2421
|
+
var c = m();
|
|
2422
|
+
return !t(o, c);
|
|
2610
2423
|
} catch {
|
|
2611
2424
|
return !0;
|
|
2612
2425
|
}
|
|
2613
2426
|
}
|
|
2614
|
-
function u(o,
|
|
2615
|
-
return
|
|
2427
|
+
function u(o, m) {
|
|
2428
|
+
return m();
|
|
2616
2429
|
}
|
|
2617
2430
|
var v = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? u : l;
|
|
2618
|
-
return P.useSyncExternalStore =
|
|
2431
|
+
return P.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : v, P;
|
|
2619
2432
|
}
|
|
2620
2433
|
var T = {};
|
|
2621
2434
|
var q;
|
|
2622
|
-
function
|
|
2435
|
+
function pe() {
|
|
2623
2436
|
return q || (q = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
2624
|
-
function
|
|
2625
|
-
return
|
|
2437
|
+
function i(c, h) {
|
|
2438
|
+
return c === h && (c !== 0 || 1 / c === 1 / h) || c !== c && h !== h;
|
|
2626
2439
|
}
|
|
2627
|
-
function e(
|
|
2628
|
-
v ||
|
|
2440
|
+
function e(c, h) {
|
|
2441
|
+
v || r.startTransition === void 0 || (v = !0, console.error(
|
|
2629
2442
|
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
2630
2443
|
));
|
|
2631
|
-
var
|
|
2444
|
+
var p = h();
|
|
2632
2445
|
if (!o) {
|
|
2633
|
-
var
|
|
2634
|
-
|
|
2446
|
+
var E = h();
|
|
2447
|
+
n(p, E) || (console.error(
|
|
2635
2448
|
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
2636
2449
|
), o = !0);
|
|
2637
2450
|
}
|
|
2638
|
-
|
|
2639
|
-
inst: { value:
|
|
2451
|
+
E = a({
|
|
2452
|
+
inst: { value: p, getSnapshot: h }
|
|
2640
2453
|
});
|
|
2641
|
-
var y =
|
|
2454
|
+
var y = E[0].inst, w = E[1];
|
|
2642
2455
|
return d(
|
|
2643
2456
|
function() {
|
|
2644
|
-
y.value =
|
|
2457
|
+
y.value = p, y.getSnapshot = h, t(y) && w({ inst: y });
|
|
2645
2458
|
},
|
|
2646
|
-
[
|
|
2459
|
+
[c, p, h]
|
|
2647
2460
|
), l(
|
|
2648
2461
|
function() {
|
|
2649
|
-
return t(y) &&
|
|
2650
|
-
t(y) &&
|
|
2462
|
+
return t(y) && w({ inst: y }), c(function() {
|
|
2463
|
+
t(y) && w({ inst: y });
|
|
2651
2464
|
});
|
|
2652
2465
|
},
|
|
2653
|
-
[
|
|
2654
|
-
), u(
|
|
2466
|
+
[c]
|
|
2467
|
+
), u(p), p;
|
|
2655
2468
|
}
|
|
2656
|
-
function t(
|
|
2657
|
-
var
|
|
2658
|
-
|
|
2469
|
+
function t(c) {
|
|
2470
|
+
var h = c.getSnapshot;
|
|
2471
|
+
c = c.value;
|
|
2659
2472
|
try {
|
|
2660
|
-
var
|
|
2661
|
-
return !
|
|
2473
|
+
var p = h();
|
|
2474
|
+
return !n(c, p);
|
|
2662
2475
|
} catch {
|
|
2663
2476
|
return !0;
|
|
2664
2477
|
}
|
|
2665
2478
|
}
|
|
2666
|
-
function s(
|
|
2667
|
-
return
|
|
2479
|
+
function s(c, h) {
|
|
2480
|
+
return h();
|
|
2668
2481
|
}
|
|
2669
2482
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
2670
|
-
var
|
|
2671
|
-
T.useSyncExternalStore =
|
|
2483
|
+
var r = H, n = typeof Object.is == "function" ? Object.is : i, a = r.useState, l = r.useEffect, d = r.useLayoutEffect, u = r.useDebugValue, v = !1, o = !1, m = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? s : e;
|
|
2484
|
+
T.useSyncExternalStore = r.useSyncExternalStore !== void 0 ? r.useSyncExternalStore : m, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
2672
2485
|
})()), T;
|
|
2673
2486
|
}
|
|
2674
|
-
var
|
|
2487
|
+
var K;
|
|
2675
2488
|
function ye() {
|
|
2676
|
-
return
|
|
2489
|
+
return K || (K = 1, process.env.NODE_ENV === "production" ? F.exports = me() : F.exports = pe()), F.exports;
|
|
2677
2490
|
}
|
|
2678
2491
|
var C = ye();
|
|
2679
|
-
function ge(
|
|
2680
|
-
if (
|
|
2681
|
-
if (
|
|
2682
|
-
for (let t = 0; t <
|
|
2683
|
-
if (
|
|
2492
|
+
function ge(i, e) {
|
|
2493
|
+
if (i === e) return !0;
|
|
2494
|
+
if (i.length !== e.length) return !1;
|
|
2495
|
+
for (let t = 0; t < i.length; t++)
|
|
2496
|
+
if (i[t] !== e[t]) return !1;
|
|
2684
2497
|
return !0;
|
|
2685
2498
|
}
|
|
2686
|
-
function R(
|
|
2687
|
-
const
|
|
2688
|
-
|
|
2689
|
-
const
|
|
2690
|
-
|
|
2691
|
-
const l =
|
|
2692
|
-
if (l.current = t,
|
|
2499
|
+
function R(i, e, t, s) {
|
|
2500
|
+
const r = V(null), n = V(i);
|
|
2501
|
+
n.current = i;
|
|
2502
|
+
const a = V(e);
|
|
2503
|
+
a.current = e;
|
|
2504
|
+
const l = V(t);
|
|
2505
|
+
if (l.current = t, r.current === null) {
|
|
2693
2506
|
const v = {};
|
|
2694
|
-
for (const o in
|
|
2695
|
-
v[o] =
|
|
2696
|
-
|
|
2507
|
+
for (const o in i)
|
|
2508
|
+
v[o] = i[o].value;
|
|
2509
|
+
r.current = { ...v, __snapshot: null };
|
|
2697
2510
|
}
|
|
2698
|
-
const d =
|
|
2511
|
+
const d = b(
|
|
2699
2512
|
(v) => {
|
|
2700
2513
|
let o = !0;
|
|
2701
|
-
return
|
|
2702
|
-
const
|
|
2703
|
-
for (const
|
|
2704
|
-
h
|
|
2514
|
+
return _(() => {
|
|
2515
|
+
const c = n.current;
|
|
2516
|
+
for (const h in c)
|
|
2517
|
+
c[h].value;
|
|
2705
2518
|
if (o) {
|
|
2706
2519
|
o = !1;
|
|
2707
2520
|
return;
|
|
@@ -2710,43 +2523,43 @@ function R(r, e, t, s) {
|
|
|
2710
2523
|
});
|
|
2711
2524
|
},
|
|
2712
2525
|
[s]
|
|
2713
|
-
), u =
|
|
2714
|
-
const v =
|
|
2715
|
-
for (const
|
|
2716
|
-
|
|
2717
|
-
let
|
|
2718
|
-
for (const
|
|
2719
|
-
const { key:
|
|
2720
|
-
if (
|
|
2721
|
-
if (!ge(
|
|
2722
|
-
|
|
2526
|
+
), u = b(() => {
|
|
2527
|
+
const v = r.current, o = n.current, m = {};
|
|
2528
|
+
for (const h in o)
|
|
2529
|
+
m[h] = o[h].value;
|
|
2530
|
+
let c = !1;
|
|
2531
|
+
for (const h of a.current) {
|
|
2532
|
+
const { key: p, useShallowArrayEqual: E } = h, y = m[p], w = v[p];
|
|
2533
|
+
if (E) {
|
|
2534
|
+
if (!ge(w, y)) {
|
|
2535
|
+
c = !0;
|
|
2723
2536
|
break;
|
|
2724
2537
|
}
|
|
2725
|
-
} else if (
|
|
2726
|
-
|
|
2538
|
+
} else if (w !== y) {
|
|
2539
|
+
c = !0;
|
|
2727
2540
|
break;
|
|
2728
2541
|
}
|
|
2729
2542
|
}
|
|
2730
|
-
if (!
|
|
2543
|
+
if (!c && v.__snapshot)
|
|
2731
2544
|
return v.__snapshot;
|
|
2732
|
-
for (const
|
|
2733
|
-
v[
|
|
2734
|
-
return v.__snapshot = l.current(
|
|
2545
|
+
for (const h in o)
|
|
2546
|
+
v[h] = m[h];
|
|
2547
|
+
return v.__snapshot = l.current(m), v.__snapshot;
|
|
2735
2548
|
}, [s]);
|
|
2736
2549
|
return C.useSyncExternalStore(d, u, u);
|
|
2737
2550
|
}
|
|
2738
|
-
function
|
|
2551
|
+
function Ee(i) {
|
|
2739
2552
|
const e = {
|
|
2740
|
-
value:
|
|
2741
|
-
disabled:
|
|
2742
|
-
errors:
|
|
2743
|
-
pending:
|
|
2744
|
-
valid:
|
|
2745
|
-
invalid:
|
|
2746
|
-
touched:
|
|
2747
|
-
dirty:
|
|
2748
|
-
shouldShowError:
|
|
2749
|
-
componentProps:
|
|
2553
|
+
value: i.value,
|
|
2554
|
+
disabled: i.disabled,
|
|
2555
|
+
errors: i.errors,
|
|
2556
|
+
pending: i.pending,
|
|
2557
|
+
valid: i.valid,
|
|
2558
|
+
invalid: i.invalid,
|
|
2559
|
+
touched: i.touched,
|
|
2560
|
+
dirty: i.dirty,
|
|
2561
|
+
shouldShowError: i.shouldShowError,
|
|
2562
|
+
componentProps: i.componentProps
|
|
2750
2563
|
}, t = [
|
|
2751
2564
|
{ key: "value" },
|
|
2752
2565
|
{ key: "disabled" },
|
|
@@ -2758,34 +2571,34 @@ function be(r) {
|
|
|
2758
2571
|
{ key: "dirty" },
|
|
2759
2572
|
{ key: "shouldShowError" },
|
|
2760
2573
|
{ key: "componentProps" }
|
|
2761
|
-
], s =
|
|
2762
|
-
(
|
|
2763
|
-
value:
|
|
2764
|
-
pending:
|
|
2765
|
-
disabled:
|
|
2766
|
-
errors:
|
|
2767
|
-
valid:
|
|
2768
|
-
invalid:
|
|
2769
|
-
touched:
|
|
2770
|
-
dirty:
|
|
2771
|
-
shouldShowError:
|
|
2772
|
-
componentProps:
|
|
2574
|
+
], s = b(
|
|
2575
|
+
(r) => ({
|
|
2576
|
+
value: r.value,
|
|
2577
|
+
pending: r.pending,
|
|
2578
|
+
disabled: r.disabled,
|
|
2579
|
+
errors: r.errors,
|
|
2580
|
+
valid: r.valid,
|
|
2581
|
+
invalid: r.invalid,
|
|
2582
|
+
touched: r.touched,
|
|
2583
|
+
dirty: r.dirty,
|
|
2584
|
+
shouldShowError: r.shouldShowError,
|
|
2585
|
+
componentProps: r.componentProps
|
|
2773
2586
|
}),
|
|
2774
2587
|
[]
|
|
2775
2588
|
);
|
|
2776
|
-
return R(e, t, s,
|
|
2589
|
+
return R(e, t, s, i);
|
|
2777
2590
|
}
|
|
2778
|
-
function
|
|
2591
|
+
function be(i) {
|
|
2779
2592
|
const e = {
|
|
2780
|
-
value:
|
|
2781
|
-
length:
|
|
2782
|
-
errors:
|
|
2783
|
-
pending:
|
|
2784
|
-
valid:
|
|
2785
|
-
invalid:
|
|
2786
|
-
touched:
|
|
2787
|
-
dirty:
|
|
2788
|
-
disabled:
|
|
2593
|
+
value: i.value,
|
|
2594
|
+
length: i.length,
|
|
2595
|
+
errors: i.errors,
|
|
2596
|
+
pending: i.pending,
|
|
2597
|
+
valid: i.valid,
|
|
2598
|
+
invalid: i.invalid,
|
|
2599
|
+
touched: i.touched,
|
|
2600
|
+
dirty: i.dirty,
|
|
2601
|
+
disabled: i.disabled
|
|
2789
2602
|
}, t = [
|
|
2790
2603
|
{ key: "value" },
|
|
2791
2604
|
{ key: "length" },
|
|
@@ -2796,24 +2609,24 @@ function Ee(r) {
|
|
|
2796
2609
|
{ key: "touched" },
|
|
2797
2610
|
{ key: "dirty" },
|
|
2798
2611
|
{ key: "disabled" }
|
|
2799
|
-
], s =
|
|
2800
|
-
(
|
|
2801
|
-
value:
|
|
2802
|
-
length:
|
|
2803
|
-
pending:
|
|
2804
|
-
errors:
|
|
2805
|
-
valid:
|
|
2806
|
-
invalid:
|
|
2807
|
-
touched:
|
|
2808
|
-
dirty:
|
|
2809
|
-
disabled:
|
|
2612
|
+
], s = b(
|
|
2613
|
+
(r) => ({
|
|
2614
|
+
value: r.value,
|
|
2615
|
+
length: r.length,
|
|
2616
|
+
pending: r.pending,
|
|
2617
|
+
errors: r.errors,
|
|
2618
|
+
valid: r.valid,
|
|
2619
|
+
invalid: r.invalid,
|
|
2620
|
+
touched: r.touched,
|
|
2621
|
+
dirty: r.dirty,
|
|
2622
|
+
disabled: r.disabled
|
|
2810
2623
|
}),
|
|
2811
2624
|
[]
|
|
2812
2625
|
);
|
|
2813
|
-
return R(e, t, s,
|
|
2626
|
+
return R(e, t, s, i);
|
|
2814
2627
|
}
|
|
2815
2628
|
function _e() {
|
|
2816
|
-
const
|
|
2629
|
+
const i = b(
|
|
2817
2630
|
() => ({
|
|
2818
2631
|
value: [],
|
|
2819
2632
|
length: 0,
|
|
@@ -2827,105 +2640,104 @@ function _e() {
|
|
|
2827
2640
|
}),
|
|
2828
2641
|
[]
|
|
2829
2642
|
);
|
|
2830
|
-
return R({}, [],
|
|
2643
|
+
return R({}, [], i);
|
|
2831
2644
|
}
|
|
2832
|
-
function Me(
|
|
2833
|
-
const e =
|
|
2834
|
-
return
|
|
2645
|
+
function Me(i) {
|
|
2646
|
+
const e = i && "length" in i && "map" in i;
|
|
2647
|
+
return i ? e ? be(i) : Ee(i) : _e();
|
|
2835
2648
|
}
|
|
2836
|
-
function xe(
|
|
2837
|
-
const e =
|
|
2838
|
-
(
|
|
2839
|
-
let
|
|
2840
|
-
return
|
|
2841
|
-
if (
|
|
2842
|
-
|
|
2649
|
+
function xe(i) {
|
|
2650
|
+
const e = V({ value: i.value.value }), t = b(
|
|
2651
|
+
(r) => {
|
|
2652
|
+
let n = !0;
|
|
2653
|
+
return _(() => {
|
|
2654
|
+
if (i.value.value, n) {
|
|
2655
|
+
n = !1;
|
|
2843
2656
|
return;
|
|
2844
2657
|
}
|
|
2845
|
-
|
|
2658
|
+
r();
|
|
2846
2659
|
});
|
|
2847
2660
|
},
|
|
2848
|
-
[
|
|
2849
|
-
), s =
|
|
2850
|
-
const
|
|
2851
|
-
return e.current.value ===
|
|
2852
|
-
}, [
|
|
2661
|
+
[i]
|
|
2662
|
+
), s = b(() => {
|
|
2663
|
+
const r = i.value.value;
|
|
2664
|
+
return e.current.value === r ? e.current.value : (e.current.value = r, r);
|
|
2665
|
+
}, [i]);
|
|
2853
2666
|
return C.useSyncExternalStore(t, s, s);
|
|
2854
2667
|
}
|
|
2855
|
-
function Ce(
|
|
2856
|
-
const e =
|
|
2857
|
-
(
|
|
2858
|
-
let
|
|
2859
|
-
return
|
|
2860
|
-
if (
|
|
2861
|
-
|
|
2668
|
+
function Ce(i) {
|
|
2669
|
+
const e = V({ length: i.length.value }), t = b(
|
|
2670
|
+
(r) => {
|
|
2671
|
+
let n = !0;
|
|
2672
|
+
return _(() => {
|
|
2673
|
+
if (i.length.value, n) {
|
|
2674
|
+
n = !1;
|
|
2862
2675
|
return;
|
|
2863
2676
|
}
|
|
2864
|
-
|
|
2677
|
+
r();
|
|
2865
2678
|
});
|
|
2866
2679
|
},
|
|
2867
|
-
[
|
|
2868
|
-
), s =
|
|
2869
|
-
const
|
|
2870
|
-
return e.current.length ===
|
|
2871
|
-
}, [
|
|
2680
|
+
[i]
|
|
2681
|
+
), s = b(() => {
|
|
2682
|
+
const r = i.length.value;
|
|
2683
|
+
return e.current.length === r ? e.current.length : (e.current.length = r, r);
|
|
2684
|
+
}, [i]);
|
|
2872
2685
|
return C.useSyncExternalStore(t, s, s);
|
|
2873
2686
|
}
|
|
2874
|
-
function Pe(
|
|
2875
|
-
const { model: e, schema: t, strategy: s, debounce:
|
|
2876
|
-
() => se(e, t, { strategy: s, debounce:
|
|
2877
|
-
[e, t, s,
|
|
2687
|
+
function Pe(i) {
|
|
2688
|
+
const { model: e, schema: t, strategy: s, debounce: r, liveAfterSubmit: n } = i, a = ee(
|
|
2689
|
+
() => se(e, t, { strategy: s, debounce: r, liveAfterSubmit: n }),
|
|
2690
|
+
[e, t, s, r, n]
|
|
2878
2691
|
);
|
|
2879
|
-
te(() =>
|
|
2692
|
+
te(() => a.start(), [a]);
|
|
2880
2693
|
const l = C.useSyncExternalStore(
|
|
2881
|
-
|
|
2882
|
-
() =>
|
|
2694
|
+
b((u) => a.validating.subscribe(u), [a]),
|
|
2695
|
+
() => a.validating.peek(),
|
|
2883
2696
|
() => !1
|
|
2884
2697
|
// SSR: прогон не идёт
|
|
2885
|
-
), d =
|
|
2698
|
+
), d = b(() => a.validate(), [a]);
|
|
2886
2699
|
return { submit: d, validate: d, isValidating: l };
|
|
2887
2700
|
}
|
|
2701
|
+
const Te = Object.freeze({ runtime: "reformer-core", v: 1 });
|
|
2888
2702
|
export {
|
|
2889
|
-
|
|
2703
|
+
B as ArrayNode,
|
|
2704
|
+
Te as CORE_RUNTIME_TOKEN,
|
|
2890
2705
|
A as ErrorStrategy,
|
|
2891
|
-
|
|
2892
|
-
|
|
2706
|
+
ne as FieldNode,
|
|
2707
|
+
k as FormErrorHandler,
|
|
2893
2708
|
M as FormNode,
|
|
2894
|
-
re as FormStatusMachine,
|
|
2895
2709
|
oe as FormSubmitter,
|
|
2896
2710
|
S as GroupNode,
|
|
2897
2711
|
de as ModelArrayNode,
|
|
2898
2712
|
ue as NodeFactory,
|
|
2899
2713
|
I as SubscriptionManager,
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2714
|
+
$e as computeFrom,
|
|
2715
|
+
Ge as copyFrom,
|
|
2716
|
+
Ne as createForm,
|
|
2903
2717
|
Q as createFormFromModel,
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2718
|
+
Le as createModel,
|
|
2719
|
+
tt as disableWhen,
|
|
2720
|
+
st as enableWhen,
|
|
2721
|
+
Ze as getNodeForSignal,
|
|
2722
|
+
Fe as getNodeType,
|
|
2909
2723
|
ve as isArrayNode,
|
|
2910
|
-
|
|
2911
|
-
|
|
2724
|
+
$ as isDerived,
|
|
2725
|
+
he as isFieldNode,
|
|
2912
2726
|
x as isFormNode,
|
|
2913
2727
|
fe as isGroupNode,
|
|
2914
2728
|
Ye as markDerived,
|
|
2915
2729
|
Z as registerSignalNode,
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2730
|
+
je as resetWhen,
|
|
2731
|
+
Ue as revalidateWhen,
|
|
2732
|
+
Be as runOutsideEffect,
|
|
2733
|
+
We as safeCallback,
|
|
2734
|
+
qe as safeDebouncedCallback,
|
|
2735
|
+
Ke as syncFields,
|
|
2922
2736
|
He as transformValue,
|
|
2923
|
-
|
|
2924
|
-
ze as unmarkDerived,
|
|
2737
|
+
Qe as unmarkDerived,
|
|
2925
2738
|
Ce as useArrayLength,
|
|
2926
2739
|
Me as useFormControl,
|
|
2927
2740
|
xe as useFormControlValue,
|
|
2928
2741
|
Pe as useFormValidation,
|
|
2929
|
-
|
|
2930
|
-
Ke as watchField
|
|
2742
|
+
ze as watchField
|
|
2931
2743
|
};
|