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