@reformer/core 1.1.0 → 2.0.0-beta.11
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/compute-from.d.ts +2 -0
- package/dist/behaviors/compute-from.js +31 -0
- package/dist/behaviors/copy-from.d.ts +2 -0
- package/dist/behaviors/copy-from.js +29 -0
- package/dist/behaviors/enable-when.d.ts +2 -0
- package/dist/behaviors/enable-when.js +25 -0
- package/dist/behaviors/reset-when.d.ts +2 -0
- package/dist/behaviors/reset-when.js +24 -0
- package/dist/behaviors/revalidate-when.d.ts +2 -0
- package/dist/behaviors/revalidate-when.js +18 -0
- package/dist/behaviors/sync-fields.d.ts +2 -0
- package/dist/behaviors/sync-fields.js +41 -0
- package/dist/behaviors/transform-value.d.ts +2 -0
- package/dist/behaviors/transform-value.js +45 -0
- package/dist/behaviors/watch-field.d.ts +2 -0
- package/dist/behaviors/watch-field.js +21 -0
- package/dist/behaviors.d.ts +6 -2
- package/dist/behaviors.js +27 -228
- package/dist/core/behavior/behavior-context.d.ts +32 -14
- package/dist/core/behavior/behavior-registry.d.ts +15 -27
- package/dist/core/behavior/behaviors/compute-from.d.ts +50 -21
- package/dist/core/behavior/behaviors/copy-from.d.ts +39 -14
- package/dist/core/behavior/behaviors/enable-when.d.ts +88 -19
- package/dist/core/behavior/behaviors/reset-when.d.ts +31 -18
- package/dist/core/behavior/behaviors/revalidate-when.d.ts +40 -17
- package/dist/core/behavior/behaviors/sync-fields.d.ts +34 -14
- package/dist/core/behavior/behaviors/transform-value.d.ts +116 -44
- package/dist/core/behavior/behaviors/watch-field.d.ts +66 -21
- package/dist/core/behavior/compose-behavior.d.ts +2 -12
- package/dist/core/behavior/index.d.ts +0 -1
- package/dist/core/behavior/types.d.ts +2 -8
- package/dist/core/factories/node-factory.d.ts +6 -29
- package/dist/core/nodes/array-node.d.ts +42 -22
- package/dist/core/nodes/field-node.d.ts +51 -26
- package/dist/core/nodes/form-node.d.ts +18 -20
- package/dist/core/nodes/group-node.d.ts +37 -212
- package/dist/core/types/deep-schema.d.ts +2 -12
- package/dist/core/types/field-path.d.ts +1 -1
- package/dist/core/types/form-context.d.ts +36 -30
- package/dist/core/types/{group-node-proxy.d.ts → form-proxy.d.ts} +12 -42
- package/dist/core/types/index.d.ts +52 -6
- package/dist/core/types/validation-schema.d.ts +3 -12
- package/dist/core/utils/abstract-registry.d.ts +74 -0
- package/dist/core/utils/aggregate-signals.d.ts +71 -0
- package/dist/core/utils/create-form.d.ts +3 -20
- package/dist/core/utils/error-handler.d.ts +1 -18
- package/dist/core/utils/field-path-navigator.d.ts +1 -1
- package/dist/core/{validation → utils}/field-path.d.ts +23 -6
- package/dist/core/utils/form-observer.d.ts +176 -0
- package/dist/core/utils/form-proxy-builder.d.ts +25 -0
- package/dist/core/utils/form-submitter.d.ts +121 -0
- package/dist/core/utils/index.d.ts +10 -2
- package/dist/core/utils/registry-helpers.d.ts +0 -7
- package/dist/core/utils/safe-effect.d.ts +73 -0
- package/dist/core/utils/status-machine.d.ts +153 -0
- package/dist/core/utils/type-guards.d.ts +5 -23
- package/dist/core/utils/unique-id.d.ts +53 -0
- package/dist/core/validation/core/apply-when.d.ts +3 -9
- package/dist/core/validation/core/apply.d.ts +2 -13
- package/dist/core/validation/core/validate-async.d.ts +2 -8
- package/dist/core/validation/core/validate-tree.d.ts +10 -10
- package/dist/core/validation/core/validate.d.ts +1 -7
- package/dist/core/validation/index.d.ts +8 -2
- package/dist/core/validation/validate-form.d.ts +1 -38
- package/dist/core/validation/validation-applicator.d.ts +2 -21
- package/dist/core/validation/validation-context.d.ts +67 -28
- package/dist/core/validation/validation-registry.d.ts +11 -25
- package/dist/core/validation/validators/array-validators.d.ts +2 -12
- package/dist/core/validation/validators/date-utils.d.ts +26 -0
- package/dist/core/validation/validators/email.d.ts +2 -9
- package/dist/core/validation/validators/future-date.d.ts +35 -0
- package/dist/core/validation/validators/index.d.ts +7 -1
- package/dist/core/validation/validators/is-date.d.ts +36 -0
- package/dist/core/validation/validators/max-age.d.ts +36 -0
- package/dist/core/validation/validators/max-date.d.ts +36 -0
- package/dist/core/validation/validators/max-length.d.ts +3 -10
- package/dist/core/validation/validators/max.d.ts +3 -10
- package/dist/core/validation/validators/min-age.d.ts +36 -0
- package/dist/core/validation/validators/min-date.d.ts +36 -0
- package/dist/core/validation/validators/min-length.d.ts +3 -10
- package/dist/core/validation/validators/min.d.ts +3 -10
- package/dist/core/validation/validators/number.d.ts +2 -9
- package/dist/core/validation/validators/past-date.d.ts +35 -0
- package/dist/core/validation/validators/pattern.d.ts +2 -9
- package/dist/core/validation/validators/phone.d.ts +2 -9
- package/dist/core/validation/validators/required.d.ts +2 -9
- package/dist/core/validation/validators/url.d.ts +2 -9
- package/dist/date-utils-xUWFslTj.js +29 -0
- package/dist/field-path-DuKdGcIE.js +66 -0
- package/dist/hooks/types.d.ts +328 -0
- package/dist/hooks/useArrayLength.d.ts +31 -0
- package/dist/hooks/useFormControl.d.ts +15 -39
- package/dist/hooks/useFormControlValue.d.ts +167 -0
- package/dist/hooks/useHiddenCondition.d.ts +25 -0
- package/dist/hooks/useSignalSubscription.d.ts +17 -0
- package/dist/index-D25LsbRm.js +73 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +3271 -8
- package/dist/registry-helpers-Bv_BJ1s-.js +615 -0
- package/dist/safe-effect-Dh8uw81c.js +20 -0
- package/dist/validate-C3XiA_zf.js +10 -0
- package/dist/validators/email.d.ts +2 -0
- package/dist/validators/email.js +13 -0
- package/dist/validators/future-date.d.ts +2 -0
- package/dist/validators/future-date.js +20 -0
- package/dist/validators/is-date.d.ts +2 -0
- package/dist/validators/is-date.js +12 -0
- package/dist/validators/max-age.d.ts +2 -0
- package/dist/validators/max-age.js +20 -0
- package/dist/validators/max-date.d.ts +2 -0
- package/dist/validators/max-date.js +20 -0
- package/dist/validators/max-length.d.ts +2 -0
- package/dist/validators/max-length.js +11 -0
- package/dist/validators/max.d.ts +2 -0
- package/dist/validators/max.js +11 -0
- package/dist/validators/min-age.d.ts +2 -0
- package/dist/validators/min-age.js +20 -0
- package/dist/validators/min-date.d.ts +2 -0
- package/dist/validators/min-date.js +20 -0
- package/dist/validators/min-length.d.ts +2 -0
- package/dist/validators/min-length.js +11 -0
- package/dist/validators/min.d.ts +2 -0
- package/dist/validators/min.js +11 -0
- package/dist/validators/number.d.ts +2 -0
- package/dist/validators/number.js +35 -0
- package/dist/validators/past-date.d.ts +2 -0
- package/dist/validators/past-date.js +20 -0
- package/dist/validators/pattern.d.ts +2 -0
- package/dist/validators/pattern.js +11 -0
- package/dist/validators/phone.d.ts +2 -0
- package/dist/validators/phone.js +35 -0
- package/dist/validators/required.d.ts +2 -0
- package/dist/validators/required.js +15 -0
- package/dist/validators/url.d.ts +2 -0
- package/dist/validators/url.js +19 -0
- package/dist/validators-BGsNOgT1.js +207 -0
- package/dist/validators.d.ts +6 -2
- package/dist/validators.js +54 -296
- package/llms.txt +8887 -59
- package/package.json +87 -8
- package/dist/core/behavior/behavior-applicator.d.ts +0 -71
- package/dist/core/behavior/behavior-applicator.js +0 -92
- package/dist/core/behavior/behavior-context.js +0 -38
- package/dist/core/behavior/behavior-registry.js +0 -198
- package/dist/core/behavior/behaviors/compute-from.js +0 -84
- package/dist/core/behavior/behaviors/copy-from.js +0 -64
- package/dist/core/behavior/behaviors/enable-when.js +0 -81
- package/dist/core/behavior/behaviors/index.js +0 -11
- package/dist/core/behavior/behaviors/reset-when.js +0 -63
- package/dist/core/behavior/behaviors/revalidate-when.js +0 -51
- package/dist/core/behavior/behaviors/sync-fields.js +0 -66
- package/dist/core/behavior/behaviors/transform-value.js +0 -110
- package/dist/core/behavior/behaviors/watch-field.js +0 -56
- package/dist/core/behavior/compose-behavior.js +0 -166
- package/dist/core/behavior/create-field-path.d.ts +0 -20
- package/dist/core/behavior/create-field-path.js +0 -69
- package/dist/core/behavior/index.js +0 -17
- package/dist/core/behavior/types.js +0 -7
- package/dist/core/context/form-context-impl.d.ts +0 -29
- package/dist/core/context/form-context-impl.js +0 -37
- package/dist/core/factories/index.js +0 -6
- package/dist/core/factories/node-factory.js +0 -281
- package/dist/core/nodes/array-node.js +0 -534
- package/dist/core/nodes/field-node.js +0 -510
- package/dist/core/nodes/form-node.js +0 -343
- package/dist/core/nodes/group-node/field-registry.d.ts +0 -191
- package/dist/core/nodes/group-node/field-registry.js +0 -215
- package/dist/core/nodes/group-node/index.d.ts +0 -11
- package/dist/core/nodes/group-node/index.js +0 -11
- package/dist/core/nodes/group-node/proxy-builder.d.ts +0 -71
- package/dist/core/nodes/group-node/proxy-builder.js +0 -161
- package/dist/core/nodes/group-node/state-manager.d.ts +0 -184
- package/dist/core/nodes/group-node/state-manager.js +0 -265
- package/dist/core/nodes/group-node.js +0 -770
- package/dist/core/types/deep-schema.js +0 -11
- package/dist/core/types/field-path.js +0 -4
- package/dist/core/types/form-context.js +0 -25
- package/dist/core/types/group-node-proxy.js +0 -31
- package/dist/core/types/index.js +0 -4
- package/dist/core/types/validation-schema.js +0 -10
- package/dist/core/utils/create-form.js +0 -24
- package/dist/core/utils/debounce.d.ts +0 -160
- package/dist/core/utils/debounce.js +0 -197
- package/dist/core/utils/error-handler.js +0 -226
- package/dist/core/utils/field-path-navigator.js +0 -374
- package/dist/core/utils/index.js +0 -14
- package/dist/core/utils/registry-helpers.js +0 -79
- package/dist/core/utils/registry-stack.js +0 -86
- package/dist/core/utils/resources.d.ts +0 -41
- package/dist/core/utils/resources.js +0 -69
- package/dist/core/utils/subscription-manager.js +0 -214
- package/dist/core/utils/type-guards.js +0 -169
- package/dist/core/validation/core/apply-when.js +0 -41
- package/dist/core/validation/core/apply.js +0 -38
- package/dist/core/validation/core/index.js +0 -8
- package/dist/core/validation/core/validate-async.js +0 -45
- package/dist/core/validation/core/validate-tree.js +0 -37
- package/dist/core/validation/core/validate.js +0 -38
- package/dist/core/validation/field-path.js +0 -147
- package/dist/core/validation/index.js +0 -33
- package/dist/core/validation/validate-form.js +0 -152
- package/dist/core/validation/validation-applicator.js +0 -217
- package/dist/core/validation/validation-context.js +0 -75
- package/dist/core/validation/validation-registry.js +0 -298
- package/dist/core/validation/validators/array-validators.js +0 -86
- package/dist/core/validation/validators/date.d.ts +0 -38
- package/dist/core/validation/validators/date.js +0 -117
- package/dist/core/validation/validators/email.js +0 -60
- package/dist/core/validation/validators/index.js +0 -14
- package/dist/core/validation/validators/max-length.js +0 -60
- package/dist/core/validation/validators/max.js +0 -60
- package/dist/core/validation/validators/min-length.js +0 -60
- package/dist/core/validation/validators/min.js +0 -60
- package/dist/core/validation/validators/number.js +0 -90
- package/dist/core/validation/validators/pattern.js +0 -62
- package/dist/core/validation/validators/phone.js +0 -58
- package/dist/core/validation/validators/required.js +0 -69
- package/dist/core/validation/validators/url.js +0 -55
- package/dist/create-field-path-CdPF3lIK.js +0 -704
- package/dist/hooks/useFormControl.js +0 -298
- package/dist/node-factory-D7DOnSSN.js +0 -3200
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { effect as _ } from "@preact/signals-core";
|
|
2
|
+
import { b as v } from "../registry-helpers-Bv_BJ1s-.js";
|
|
3
|
+
import { r as V } from "../safe-effect-Dh8uw81c.js";
|
|
4
|
+
function N(n, i, s, f) {
|
|
5
|
+
const { debounce: p, condition: u } = f || {}, h = (r, E, m) => {
|
|
6
|
+
const a = r.getFieldByPath(i.__path);
|
|
7
|
+
if (!a) return null;
|
|
8
|
+
const o = n.map((e) => r.getFieldByPath(e.__path)).filter((e) => e !== void 0);
|
|
9
|
+
return o.length === 0 ? null : _(() => {
|
|
10
|
+
o.forEach((e) => e.value.value), m(() => {
|
|
11
|
+
if (u) {
|
|
12
|
+
const t = r.getValue();
|
|
13
|
+
if (!u(t)) return;
|
|
14
|
+
}
|
|
15
|
+
const e = o.map((t) => t.value.value), l = {};
|
|
16
|
+
n.forEach((t, d) => {
|
|
17
|
+
const g = t.__path.split(".").pop() || t.__path;
|
|
18
|
+
l[g] = e[d];
|
|
19
|
+
});
|
|
20
|
+
const c = s(l);
|
|
21
|
+
a.value.peek() !== c && V(() => {
|
|
22
|
+
a.setValue(c, { emitEvent: !1 });
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
v().register(h, { debounce: p });
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
N as computeFrom
|
|
31
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { r as s } from "../safe-effect-Dh8uw81c.js";
|
|
2
|
+
import { watchField as d } from "./watch-field.js";
|
|
3
|
+
function E(l, c, m) {
|
|
4
|
+
const { when: a, fields: o = "all", transform: i, debounce: p } = m || {};
|
|
5
|
+
d(
|
|
6
|
+
l,
|
|
7
|
+
(t, n) => {
|
|
8
|
+
if (a) {
|
|
9
|
+
const f = n.form.getValue();
|
|
10
|
+
if (!a(f)) return;
|
|
11
|
+
}
|
|
12
|
+
const h = i ? i(t) : t, e = n.form.getFieldByPath(c.__path);
|
|
13
|
+
e && s(() => {
|
|
14
|
+
if (o === "all" || !o)
|
|
15
|
+
e.setValue(h, { emitEvent: !1 });
|
|
16
|
+
else {
|
|
17
|
+
const f = {};
|
|
18
|
+
o.forEach((r) => {
|
|
19
|
+
t && typeof t == "object" && (f[r] = t[r]);
|
|
20
|
+
}), "patchValue" in e && e.patchValue(f);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
{ debounce: p }
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
E as copyFrom
|
|
29
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { effect as c } from "@preact/signals-core";
|
|
2
|
+
import { b } from "../registry-helpers-Bv_BJ1s-.js";
|
|
3
|
+
import { r as d } from "../safe-effect-Dh8uw81c.js";
|
|
4
|
+
function h(t, n, r) {
|
|
5
|
+
const { debounce: o, resetOnDisable: a = !1 } = r || {}, i = (s, m, l) => {
|
|
6
|
+
const e = s.getFieldByPath(t.__path);
|
|
7
|
+
return e ? c(() => {
|
|
8
|
+
const f = s.value.value;
|
|
9
|
+
l(() => {
|
|
10
|
+
const u = n(f);
|
|
11
|
+
d(() => {
|
|
12
|
+
u ? e.enable() : (e.disable(), a && e.reset());
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}) : null;
|
|
16
|
+
};
|
|
17
|
+
b().register(i, { debounce: o });
|
|
18
|
+
}
|
|
19
|
+
function _(t, n, r) {
|
|
20
|
+
h(t, (o) => !n(o), r);
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
_ as disableWhen,
|
|
24
|
+
h as enableWhen
|
|
25
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { effect as c } from "@preact/signals-core";
|
|
2
|
+
import { b as d } from "../registry-helpers-Bv_BJ1s-.js";
|
|
3
|
+
import { r as h } from "../safe-effect-Dh8uw81c.js";
|
|
4
|
+
function R(r, n, o) {
|
|
5
|
+
const { debounce: s, resetValue: u = null, onlyIfDirty: a = !1 } = o || {}, i = (t, m, l) => {
|
|
6
|
+
const e = t.getFieldByPath(r.__path);
|
|
7
|
+
return e ? c(() => {
|
|
8
|
+
const f = t.value.value;
|
|
9
|
+
l(() => {
|
|
10
|
+
if (n(f)) {
|
|
11
|
+
if (a && !e.dirty.value)
|
|
12
|
+
return;
|
|
13
|
+
h(() => {
|
|
14
|
+
e.setValue(u), e.markAsPristine(), e.markAsUntouched();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}) : null;
|
|
19
|
+
};
|
|
20
|
+
d().register(i, { debounce: s });
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
R as resetWhen
|
|
24
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { effect as d } from "@preact/signals-core";
|
|
2
|
+
import { b as h } from "../registry-helpers-Bv_BJ1s-.js";
|
|
3
|
+
function p(o, a, i) {
|
|
4
|
+
const { debounce: l } = i || {}, u = (t, s, c) => {
|
|
5
|
+
const r = t.getFieldByPath(o.__path);
|
|
6
|
+
if (!r) return null;
|
|
7
|
+
const n = a.map((e) => t.getFieldByPath(e.__path)).filter((e) => e !== void 0);
|
|
8
|
+
return n.length === 0 ? null : d(() => {
|
|
9
|
+
n.forEach((e) => e.value.value), c(() => {
|
|
10
|
+
r.validate();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
h().register(u, { debounce: l });
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
p as revalidateWhen
|
|
18
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { effect as o } from "@preact/signals-core";
|
|
2
|
+
import { b as v } from "../registry-helpers-Bv_BJ1s-.js";
|
|
3
|
+
import { r as i } from "../safe-effect-Dh8uw81c.js";
|
|
4
|
+
function E(u, f, c) {
|
|
5
|
+
const { debounce: d, transform: a } = c || {}, p = (n, h, l) => {
|
|
6
|
+
const r = n.getFieldByPath(u.__path), s = n.getFieldByPath(f.__path);
|
|
7
|
+
if (!r || !s) return null;
|
|
8
|
+
let e = !1;
|
|
9
|
+
const g = o(() => {
|
|
10
|
+
const t = r.value.value;
|
|
11
|
+
e || l(() => {
|
|
12
|
+
e = !0, i(() => {
|
|
13
|
+
try {
|
|
14
|
+
const y = a ? a(t) : t;
|
|
15
|
+
s.setValue(y, { emitEvent: !1 });
|
|
16
|
+
} finally {
|
|
17
|
+
e = !1;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}), m = o(() => {
|
|
22
|
+
const t = s.value.value;
|
|
23
|
+
e || l(() => {
|
|
24
|
+
e = !0, i(() => {
|
|
25
|
+
try {
|
|
26
|
+
r.setValue(t, { emitEvent: !1 });
|
|
27
|
+
} finally {
|
|
28
|
+
e = !1;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
g(), m();
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
v().register(p, { debounce: d });
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
E as syncFields
|
|
41
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { watchField as p } from "./watch-field.js";
|
|
2
|
+
function u(e, t, o) {
|
|
3
|
+
const { onUserChangeOnly: n = !1, emitEvent: m = !0, debounce: c } = o || {};
|
|
4
|
+
p(
|
|
5
|
+
e,
|
|
6
|
+
(s, i) => {
|
|
7
|
+
const a = i.form.getFieldByPath(e.__path);
|
|
8
|
+
if (!a || n && !a.touched.value)
|
|
9
|
+
return;
|
|
10
|
+
const f = t(s);
|
|
11
|
+
f !== s && a.setValue(f, { emitEvent: m });
|
|
12
|
+
},
|
|
13
|
+
{ debounce: c }
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function r(e, t) {
|
|
17
|
+
return (o, n) => {
|
|
18
|
+
u(o, e, { ...t, ...n });
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const h = {
|
|
22
|
+
/** Перевести в верхний регистр */
|
|
23
|
+
toUpperCase: r((e) => e?.toUpperCase()),
|
|
24
|
+
/** Перевести в нижний регистр */
|
|
25
|
+
toLowerCase: r((e) => e?.toLowerCase()),
|
|
26
|
+
/** Удалить пробелы с краев */
|
|
27
|
+
trim: r((e) => e?.trim()),
|
|
28
|
+
/** Удалить все пробелы */
|
|
29
|
+
removeSpaces: r((e) => e?.replace(/\s/g, "")),
|
|
30
|
+
/** Оставить только цифры */
|
|
31
|
+
digitsOnly: r((e) => e?.replace(/\D/g, "")),
|
|
32
|
+
/** Округлить число */
|
|
33
|
+
round: r(
|
|
34
|
+
(e) => typeof e == "number" ? Math.round(e) : e
|
|
35
|
+
),
|
|
36
|
+
/** Округлить до 2 знаков после запятой */
|
|
37
|
+
roundTo2: r(
|
|
38
|
+
(e) => typeof e == "number" ? Math.round(e * 100) / 100 : e
|
|
39
|
+
)
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
r as createTransformer,
|
|
43
|
+
u as transformValue,
|
|
44
|
+
h as transformers
|
|
45
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { effect as c } from "@preact/signals-core";
|
|
2
|
+
import { b as d } from "../registry-helpers-Bv_BJ1s-.js";
|
|
3
|
+
import { r as i } from "../safe-effect-Dh8uw81c.js";
|
|
4
|
+
function g(n, r, u) {
|
|
5
|
+
const { debounce: a, immediate: f = !1 } = u || {}, s = (l, o, m) => {
|
|
6
|
+
const e = l.getFieldByPath(n.__path);
|
|
7
|
+
return e ? (f && i(() => {
|
|
8
|
+
const t = e.value.value;
|
|
9
|
+
r(t, o);
|
|
10
|
+
}), c(() => {
|
|
11
|
+
const t = e.value.value;
|
|
12
|
+
m(() => {
|
|
13
|
+
i(() => r(t, o));
|
|
14
|
+
});
|
|
15
|
+
})) : null;
|
|
16
|
+
};
|
|
17
|
+
d().register(s, { debounce: a });
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
g as watchField
|
|
21
|
+
};
|
package/dist/behaviors.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
/**
|
|
2
|
+
* Re-export behaviors from the main index to ensure single module instance.
|
|
3
|
+
* This prevents static registry isolation issues when consuming the library.
|
|
4
|
+
*/
|
|
5
|
+
export { behaviors as default } from './index';
|
|
6
|
+
export * from './core/behavior';
|
package/dist/behaviors.js
CHANGED
|
@@ -1,230 +1,29 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return p(() => {
|
|
12
|
-
const n = o.value.value;
|
|
13
|
-
c(() => {
|
|
14
|
-
t(n, i);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
y().register(l, { debounce: a });
|
|
19
|
-
}
|
|
20
|
-
function A(e, t, r) {
|
|
21
|
-
const { when: a, fields: s = "all", transform: l, debounce: u } = r || {};
|
|
22
|
-
v(
|
|
23
|
-
e,
|
|
24
|
-
(i, c) => {
|
|
25
|
-
if (a) {
|
|
26
|
-
const f = c.form.getValue();
|
|
27
|
-
if (!a(f)) return;
|
|
28
|
-
}
|
|
29
|
-
const o = l ? l(i) : i, n = c.form.getFieldByPath(t.__path);
|
|
30
|
-
if (n)
|
|
31
|
-
if (s === "all" || !s)
|
|
32
|
-
n.setValue(o, { emitEvent: !1 });
|
|
33
|
-
else {
|
|
34
|
-
const f = {};
|
|
35
|
-
s.forEach((d) => {
|
|
36
|
-
i && typeof i == "object" && (f[d] = i[d]);
|
|
37
|
-
}), "patchValue" in n && n.patchValue(f);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
{ debounce: u }
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
function V(e, t, r) {
|
|
44
|
-
const { debounce: a, resetOnDisable: s = !1 } = r || {}, l = (u, i, c) => {
|
|
45
|
-
const o = u.getFieldByPath(e.__path);
|
|
46
|
-
return o ? p(() => {
|
|
47
|
-
const n = u.value.value;
|
|
48
|
-
c(() => {
|
|
49
|
-
t(n) ? o.enable() : (o.disable(), s && o.reset());
|
|
50
|
-
});
|
|
51
|
-
}) : null;
|
|
52
|
-
};
|
|
53
|
-
y().register(l, { debounce: a });
|
|
54
|
-
}
|
|
55
|
-
function C(e, t, r) {
|
|
56
|
-
V(e, (a) => !t(a), r);
|
|
57
|
-
}
|
|
58
|
-
function R(e, t, r, a) {
|
|
59
|
-
const { debounce: s, condition: l } = a || {}, u = (i, c, o) => {
|
|
60
|
-
const n = i.getFieldByPath(t.__path);
|
|
61
|
-
if (!n) return null;
|
|
62
|
-
const f = e.map((d) => i.getFieldByPath(d.__path)).filter((d) => d !== void 0);
|
|
63
|
-
return f.length === 0 ? null : p(() => {
|
|
64
|
-
const d = f.map((g) => g.value.value);
|
|
65
|
-
o(() => {
|
|
66
|
-
if (l) {
|
|
67
|
-
const m = i.getValue();
|
|
68
|
-
if (!l(m)) return;
|
|
69
|
-
}
|
|
70
|
-
const g = {};
|
|
71
|
-
e.forEach((m, P) => {
|
|
72
|
-
const B = m.__path.split(".").pop() || m.__path;
|
|
73
|
-
g[B] = d[P];
|
|
74
|
-
});
|
|
75
|
-
const _ = r(g);
|
|
76
|
-
n.setValue(_, { emitEvent: !1 });
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
y().register(u, { debounce: s });
|
|
81
|
-
}
|
|
82
|
-
function U(e, t, r) {
|
|
83
|
-
const { debounce: a } = r || {}, s = (l, u, i) => {
|
|
84
|
-
const c = l.getFieldByPath(e.__path);
|
|
85
|
-
if (!c) return null;
|
|
86
|
-
const o = t.map((n) => l.getFieldByPath(n.__path)).filter((n) => n !== void 0);
|
|
87
|
-
return o.length === 0 ? null : p(() => {
|
|
88
|
-
o.forEach((n) => n.value.value), i(() => {
|
|
89
|
-
c.validate();
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
y().register(s, { debounce: a });
|
|
94
|
-
}
|
|
95
|
-
function W(e, t, r) {
|
|
96
|
-
const { debounce: a, transform: s } = r || {}, l = (u, i, c) => {
|
|
97
|
-
const o = u.getFieldByPath(e.__path), n = u.getFieldByPath(t.__path);
|
|
98
|
-
if (!o || !n) return null;
|
|
99
|
-
let f = !1;
|
|
100
|
-
const d = p(() => {
|
|
101
|
-
const _ = o.value.value;
|
|
102
|
-
f || c(() => {
|
|
103
|
-
f = !0;
|
|
104
|
-
const m = s ? s(_) : _;
|
|
105
|
-
n.setValue(m, { emitEvent: !1 }), f = !1;
|
|
106
|
-
});
|
|
107
|
-
}), g = p(() => {
|
|
108
|
-
const _ = n.value.value;
|
|
109
|
-
f || c(() => {
|
|
110
|
-
f = !0, o.setValue(_, { emitEvent: !1 }), f = !1;
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
return () => {
|
|
114
|
-
d(), g();
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
y().register(l, { debounce: a });
|
|
118
|
-
}
|
|
119
|
-
function w(e, t, r) {
|
|
120
|
-
const { debounce: a, resetValue: s = null, onlyIfDirty: l = !1 } = r || {}, u = (i, c, o) => {
|
|
121
|
-
const n = i.getFieldByPath(e.__path);
|
|
122
|
-
return n ? p(() => {
|
|
123
|
-
const f = i.value.value;
|
|
124
|
-
o(() => {
|
|
125
|
-
if (t(f)) {
|
|
126
|
-
if (l && !n.dirty.value)
|
|
127
|
-
return;
|
|
128
|
-
n.setValue(s), n.markAsPristine(), n.markAsUntouched();
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}) : null;
|
|
132
|
-
};
|
|
133
|
-
y().register(u, { debounce: a });
|
|
134
|
-
}
|
|
135
|
-
function F(e, t, r) {
|
|
136
|
-
const { onUserChangeOnly: a = !1, emitEvent: s = !0, debounce: l } = r || {};
|
|
137
|
-
v(
|
|
138
|
-
e,
|
|
139
|
-
(u, i) => {
|
|
140
|
-
const c = i.form.getFieldByPath(e.__path);
|
|
141
|
-
if (!c || a && !c.touched.value)
|
|
142
|
-
return;
|
|
143
|
-
const o = t(u);
|
|
144
|
-
o !== u && c.setValue(o, { emitEvent: s });
|
|
145
|
-
},
|
|
146
|
-
{ debounce: l }
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
function h(e, t) {
|
|
150
|
-
return (r, a) => {
|
|
151
|
-
F(r, e, { ...t, ...a });
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
const O = {
|
|
155
|
-
/** Перевести в верхний регистр */
|
|
156
|
-
toUpperCase: h((e) => e?.toUpperCase()),
|
|
157
|
-
/** Перевести в нижний регистр */
|
|
158
|
-
toLowerCase: h((e) => e?.toLowerCase()),
|
|
159
|
-
/** Удалить пробелы с краев */
|
|
160
|
-
trim: h((e) => e?.trim()),
|
|
161
|
-
/** Удалить все пробелы */
|
|
162
|
-
removeSpaces: h((e) => e?.replace(/\s/g, "")),
|
|
163
|
-
/** Оставить только цифры */
|
|
164
|
-
digitsOnly: h((e) => e?.replace(/\D/g, "")),
|
|
165
|
-
/** Округлить число */
|
|
166
|
-
round: h(
|
|
167
|
-
(e) => typeof e == "number" ? Math.round(e) : e
|
|
168
|
-
),
|
|
169
|
-
/** Округлить до 2 знаков после запятой */
|
|
170
|
-
roundTo2: h(
|
|
171
|
-
(e) => typeof e == "number" ? Math.round(e * 100) / 100 : e
|
|
172
|
-
)
|
|
173
|
-
};
|
|
174
|
-
function N(e) {
|
|
175
|
-
if (!e)
|
|
176
|
-
return b();
|
|
177
|
-
const t = e.__path;
|
|
178
|
-
return E(t);
|
|
179
|
-
}
|
|
180
|
-
function E(e) {
|
|
181
|
-
return new Proxy({}, {
|
|
182
|
-
get(t, r) {
|
|
183
|
-
return typeof r == "symbol" ? void 0 : {
|
|
184
|
-
__path: e ? `${e}.${r}` : r,
|
|
185
|
-
__key: r
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
function j(e, t) {
|
|
191
|
-
const r = (Array.isArray(e) ? e : [e]).filter(Boolean), a = Array.isArray(t) ? t : [t];
|
|
192
|
-
for (const s of r) {
|
|
193
|
-
const l = N(s);
|
|
194
|
-
for (const u of a)
|
|
195
|
-
u(l);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function D(e, t, r) {
|
|
199
|
-
if (!e) return;
|
|
200
|
-
let a = !1;
|
|
201
|
-
v(
|
|
202
|
-
e,
|
|
203
|
-
(s, l) => {
|
|
204
|
-
if (!a && t(s)) {
|
|
205
|
-
const u = b();
|
|
206
|
-
r(u), a = !0;
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
{ immediate: !0 }
|
|
210
|
-
);
|
|
211
|
-
}
|
|
1
|
+
import { a as o, b as a, i as t, t as m } from "./index-D25LsbRm.js";
|
|
2
|
+
import { a as s, B as f } from "./registry-helpers-Bv_BJ1s-.js";
|
|
3
|
+
import { copyFrom as n } from "./behaviors/copy-from.js";
|
|
4
|
+
import { disableWhen as h, enableWhen as i } from "./behaviors/enable-when.js";
|
|
5
|
+
import { computeFrom as c } from "./behaviors/compute-from.js";
|
|
6
|
+
import { watchField as F } from "./behaviors/watch-field.js";
|
|
7
|
+
import { revalidateWhen as v } from "./behaviors/revalidate-when.js";
|
|
8
|
+
import { syncFields as b } from "./behaviors/sync-fields.js";
|
|
9
|
+
import { resetWhen as g } from "./behaviors/reset-when.js";
|
|
10
|
+
import { createTransformer as C, transformValue as I, transformers as P } from "./behaviors/transform-value.js";
|
|
212
11
|
export {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
12
|
+
s as BehaviorContextImpl,
|
|
13
|
+
f as BehaviorRegistry,
|
|
14
|
+
o as apply,
|
|
15
|
+
a as applyWhen,
|
|
16
|
+
c as computeFrom,
|
|
17
|
+
n as copyFrom,
|
|
18
|
+
C as createTransformer,
|
|
19
|
+
t as default,
|
|
20
|
+
h as disableWhen,
|
|
21
|
+
i as enableWhen,
|
|
22
|
+
g as resetWhen,
|
|
23
|
+
v as revalidateWhen,
|
|
24
|
+
b as syncFields,
|
|
25
|
+
m as toBehaviorFieldPath,
|
|
26
|
+
I as transformValue,
|
|
27
|
+
P as transformers,
|
|
28
|
+
F as watchField
|
|
230
29
|
};
|
|
@@ -1,29 +1,47 @@
|
|
|
1
|
+
import { GroupNode } from '../nodes/group-node';
|
|
2
|
+
import { FormProxy } from '../types/form-proxy';
|
|
3
|
+
import { FormContext } from '../types/form-context';
|
|
4
|
+
import { FieldPathNode } from '../types/field-path';
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
6
|
+
* Реализация {@link FormContext} для behaviors. Создаётся фреймворком и передаётся
|
|
7
|
+
* в callback'и behaviors (`watchField`, `computeFrom`, …) — напрямую инстанцировать
|
|
8
|
+
* не нужно.
|
|
3
9
|
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import type { GroupNodeWithControls } from '../types/group-node-proxy';
|
|
8
|
-
import type { FormContext } from '../types/form-context';
|
|
9
|
-
/**
|
|
10
|
-
* Реализация BehaviorContext (FormContext)
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { watchField } from '@reformer/core/behaviors/watch-field';
|
|
11
13
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* watchField(path.country, (value, ctx) => {
|
|
15
|
+
* // ctx — экземпляр BehaviorContextImpl
|
|
16
|
+
* ctx.setFieldValue(path.city, '');
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
15
19
|
*/
|
|
16
20
|
export declare class BehaviorContextImpl<TForm> implements FormContext<TForm> {
|
|
17
21
|
/**
|
|
18
22
|
* Форма с типизированным Proxy-доступом к полям
|
|
19
23
|
*/
|
|
20
|
-
readonly form:
|
|
24
|
+
readonly form: FormProxy<TForm>;
|
|
21
25
|
private _form;
|
|
22
26
|
constructor(form: GroupNode<TForm>);
|
|
23
27
|
/**
|
|
24
|
-
* Безопасно установить значение поля по строковому пути
|
|
28
|
+
* Безопасно установить значение поля по строковому пути или FieldPath
|
|
25
29
|
*
|
|
26
30
|
* Автоматически использует emitEvent: false для предотвращения циклов
|
|
31
|
+
*
|
|
32
|
+
* @param path - Строковый путь к полю или FieldPath объект
|
|
33
|
+
* @param value - Новое значение
|
|
34
|
+
*/
|
|
35
|
+
setFieldValue(path: string | FieldPathNode<TForm, unknown>, value: unknown): void;
|
|
36
|
+
/**
|
|
37
|
+
* Получить поле формы по строковому пути
|
|
38
|
+
*
|
|
39
|
+
* Используется для динамического доступа к вложенным полям, например:
|
|
40
|
+
* - `ctx.getFieldByPath('address.city')` -> FieldNode
|
|
41
|
+
* - `ctx.getFieldByPath(path.city.__path)` -> FieldNode (для nested behaviors)
|
|
42
|
+
*
|
|
43
|
+
* @param path - Строковый путь к полю (например "address.city")
|
|
44
|
+
* @returns FieldNode или undefined если поле не найдено
|
|
27
45
|
*/
|
|
28
|
-
|
|
46
|
+
getFieldByPath(path: string): import('../..').FormNode<import('../types').FormValue> | undefined;
|
|
29
47
|
}
|