@reformer/core 3.0.0 → 4.0.0
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.js +26 -19
- package/dist/core/behavior/behavior-context.d.ts +26 -12
- 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 +39 -19
- 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 +25 -21
- 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 +26 -26
- package/dist/core/types/form-proxy.d.ts +2 -32
- package/dist/core/types/index.d.ts +51 -5
- 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 +1 -18
- package/dist/core/utils/error-handler.d.ts +1 -18
- package/dist/core/utils/field-path-navigator.d.ts +1 -1
- package/dist/core/utils/field-path.d.ts +23 -11
- 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 +9 -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 +0 -6
- 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 +58 -42
- 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 +1 -1
- package/dist/hooks/useArrayLength.d.ts +31 -0
- package/dist/hooks/useFormControl.d.ts +4 -4
- package/dist/hooks/useFormControlValue.d.ts +2 -2
- package/dist/hooks/useHiddenCondition.d.ts +25 -0
- package/dist/hooks/useSignalSubscription.d.ts +1 -1
- package/dist/index-D25LsbRm.js +73 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1171 -786
- 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.js +54 -29
- package/llms.txt +7878 -311
- package/package.json +83 -9
- package/dist/behaviors-DzYL8kY_.js +0 -499
- package/dist/core/behavior/create-field-path.d.ts +0 -7
- package/dist/core/context/form-context-impl.d.ts +0 -29
- package/dist/core/utils/debounce.d.ts +0 -160
- package/dist/core/utils/resources.d.ts +0 -41
- package/dist/core/validation/field-path.d.ts +0 -7
- package/dist/core/validation/validators/date.d.ts +0 -38
- package/dist/registry-helpers-BRxAr6nG.js +0 -490
- package/dist/validators-gXoHPdqM.js +0 -418
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function c() {
|
|
2
|
+
return _("");
|
|
3
|
+
}
|
|
4
|
+
function _(t) {
|
|
5
|
+
return new Proxy({}, {
|
|
6
|
+
get(r, i) {
|
|
7
|
+
if (typeof i == "symbol")
|
|
8
|
+
return;
|
|
9
|
+
if (i === "__path" || i === "__fieldPath")
|
|
10
|
+
return t || i;
|
|
11
|
+
if (i === "__key") {
|
|
12
|
+
const n = t.split(".");
|
|
13
|
+
return n[n.length - 1] || i;
|
|
14
|
+
}
|
|
15
|
+
if (i === "then" || i === "catch" || i === "finally" || i === "constructor" || i === "toString" || i === "valueOf" || i === "toJSON")
|
|
16
|
+
return;
|
|
17
|
+
const f = t ? `${t}.${i}` : i, a = {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
__key: i,
|
|
20
|
+
__path: f,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
__formType: void 0,
|
|
23
|
+
__fieldType: void 0
|
|
24
|
+
};
|
|
25
|
+
return new Proxy(a, {
|
|
26
|
+
get(n, e) {
|
|
27
|
+
if (typeof e != "symbol") {
|
|
28
|
+
if (e === "__path" || e === "__fieldPath") return f;
|
|
29
|
+
if (e === "__key") return i;
|
|
30
|
+
if (e !== "__formType" && e !== "__fieldType" && !(e === "then" || e === "catch" || e === "finally" || e === "constructor" || e === "toString" || e === "valueOf" || e === "toJSON"))
|
|
31
|
+
return _(`${f}.${e}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function u(t) {
|
|
39
|
+
if (typeof t == "string")
|
|
40
|
+
return t;
|
|
41
|
+
if (t && typeof t == "object") {
|
|
42
|
+
const r = t.__path;
|
|
43
|
+
if (typeof r == "string")
|
|
44
|
+
return r;
|
|
45
|
+
}
|
|
46
|
+
throw new Error("Invalid field path node: " + JSON.stringify(t));
|
|
47
|
+
}
|
|
48
|
+
function y(t) {
|
|
49
|
+
const r = u(t);
|
|
50
|
+
return _(r);
|
|
51
|
+
}
|
|
52
|
+
function l(t) {
|
|
53
|
+
if (t && typeof t == "object" && "__key" in t)
|
|
54
|
+
return t.__key;
|
|
55
|
+
if (typeof t == "string") {
|
|
56
|
+
const r = t.split(".");
|
|
57
|
+
return r[r.length - 1];
|
|
58
|
+
}
|
|
59
|
+
throw new Error("Invalid field path node");
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
l as a,
|
|
63
|
+
c,
|
|
64
|
+
u as e,
|
|
65
|
+
y as t
|
|
66
|
+
};
|
package/dist/hooks/types.d.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ArrayNode } from '../core/nodes/array-node';
|
|
2
|
+
import { FormFields } from '../core/types';
|
|
3
|
+
/**
|
|
4
|
+
* React-хук для подписки только на длину массива.
|
|
5
|
+
*
|
|
6
|
+
* Оптимизированная версия {@link useFormControl} для ArrayNode, которая
|
|
7
|
+
* подписывается только на сигнал `length`. Компонент не будет ре-рендериться
|
|
8
|
+
* при изменении значений вложенных полей.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - Тип элемента массива
|
|
11
|
+
* @param control - ArrayNode для подписки
|
|
12
|
+
* @returns Текущая длина массива
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function ArrayRenderer({ arrayNode }) {
|
|
17
|
+
* const length = useArrayLength(arrayNode);
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* {arrayNode.map((item, index) => (
|
|
22
|
+
* <ItemRenderer key={item.id} item={item} />
|
|
23
|
+
* ))}
|
|
24
|
+
* </div>
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @group React Hooks
|
|
30
|
+
*/
|
|
31
|
+
export declare function useArrayLength<T extends FormFields>(control: ArrayNode<T>): number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { FieldNode } from '../core/nodes/field-node';
|
|
2
|
+
import { ArrayNode } from '../core/nodes/array-node';
|
|
3
|
+
import { FormValue, FormFields } from '../core/types';
|
|
4
|
+
import { FieldControlState, ArrayControlState } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* React-хук для подписки на состояние {@link ArrayNode}.
|
|
7
7
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { FieldNode } from '../core/nodes/field-node';
|
|
2
|
+
import { FormValue } from '../core/types';
|
|
3
3
|
/**
|
|
4
4
|
* React-хук для подписки только на значение поля.
|
|
5
5
|
*
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FormProxy, FieldPath } from '../core/types';
|
|
2
|
+
type HiddenFn<T> = (form: FormProxy<T>, path: FieldPath<T>) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Хук для реактивной оценки функции hidden.
|
|
5
|
+
*
|
|
6
|
+
* Подписывается на изменения формы через сигналы и возвращает текущее
|
|
7
|
+
* значение hidden-условия.
|
|
8
|
+
*
|
|
9
|
+
* @param hiddenFn - Функция, определяющая скрытие.
|
|
10
|
+
* @param form - {@link FormProxy} формы.
|
|
11
|
+
* @param path - Текущий {@link FieldPath}.
|
|
12
|
+
* @returns `true`, если элемент должен быть скрыт.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { useHiddenCondition } from '@reformer/core';
|
|
17
|
+
*
|
|
18
|
+
* function MaybeHidden({ form, path, children }) {
|
|
19
|
+
* const hidden = useHiddenCondition((f) => !f.subscribeNewsletter.value, form, path);
|
|
20
|
+
* return hidden ? null : <>{children}</>;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function useHiddenCondition<T>(hiddenFn: HiddenFn<T> | undefined, form: FormProxy<T>, path: FieldPath<T>): boolean;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { c as f } from "./field-path-DuKdGcIE.js";
|
|
2
|
+
import { watchField as m } from "./behaviors/watch-field.js";
|
|
3
|
+
import { a as l, B as c } from "./registry-helpers-Bv_BJ1s-.js";
|
|
4
|
+
import { copyFrom as h } from "./behaviors/copy-from.js";
|
|
5
|
+
import { disableWhen as u, enableWhen as p } from "./behaviors/enable-when.js";
|
|
6
|
+
import { computeFrom as y } from "./behaviors/compute-from.js";
|
|
7
|
+
import { revalidateWhen as d } from "./behaviors/revalidate-when.js";
|
|
8
|
+
import { syncFields as _ } from "./behaviors/sync-fields.js";
|
|
9
|
+
import { resetWhen as P } from "./behaviors/reset-when.js";
|
|
10
|
+
import { createTransformer as b, transformValue as v, transformers as g } from "./behaviors/transform-value.js";
|
|
11
|
+
function s(r) {
|
|
12
|
+
if (!r)
|
|
13
|
+
return f();
|
|
14
|
+
const e = r.__path;
|
|
15
|
+
return A(e);
|
|
16
|
+
}
|
|
17
|
+
function A(r) {
|
|
18
|
+
return new Proxy({}, {
|
|
19
|
+
get(e, t) {
|
|
20
|
+
return typeof t == "symbol" ? void 0 : {
|
|
21
|
+
__path: r ? `${r}.${t}` : t,
|
|
22
|
+
__key: t
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function B(r, e) {
|
|
28
|
+
const t = (Array.isArray(r) ? r : [r]).filter(Boolean), o = Array.isArray(e) ? e : [e];
|
|
29
|
+
for (const a of t) {
|
|
30
|
+
const i = s(a);
|
|
31
|
+
for (const n of o)
|
|
32
|
+
n(i);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function F(r, e, t) {
|
|
36
|
+
if (!r) return;
|
|
37
|
+
let o = !1;
|
|
38
|
+
m(
|
|
39
|
+
r,
|
|
40
|
+
(a, i) => {
|
|
41
|
+
if (!o && e(a)) {
|
|
42
|
+
const n = f();
|
|
43
|
+
t(n), o = !0;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{ immediate: !0 }
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
50
|
+
__proto__: null,
|
|
51
|
+
BehaviorContextImpl: l,
|
|
52
|
+
BehaviorRegistry: c,
|
|
53
|
+
apply: B,
|
|
54
|
+
applyWhen: F,
|
|
55
|
+
computeFrom: y,
|
|
56
|
+
copyFrom: h,
|
|
57
|
+
createTransformer: b,
|
|
58
|
+
disableWhen: u,
|
|
59
|
+
enableWhen: p,
|
|
60
|
+
resetWhen: P,
|
|
61
|
+
revalidateWhen: d,
|
|
62
|
+
syncFields: _,
|
|
63
|
+
toBehaviorFieldPath: s,
|
|
64
|
+
transformValue: v,
|
|
65
|
+
transformers: g,
|
|
66
|
+
watchField: m
|
|
67
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
68
|
+
export {
|
|
69
|
+
B as a,
|
|
70
|
+
F as b,
|
|
71
|
+
z as i,
|
|
72
|
+
s as t
|
|
73
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { ArrayNode } from './core/nodes/array-node';
|
|
|
8
8
|
export type { SetValueOptions } from './core/nodes/form-node';
|
|
9
9
|
export { useFormControl } from './hooks/useFormControl';
|
|
10
10
|
export { useFormControlValue } from './hooks/useFormControlValue';
|
|
11
|
+
export { useArrayLength } from './hooks/useArrayLength';
|
|
12
|
+
export { useHiddenCondition } from './hooks/useHiddenCondition';
|
|
11
13
|
export type { FieldControlState, ArrayControlState } from './hooks/types';
|
|
12
14
|
export type { BehaviorSchemaFn } from './core/behavior/types';
|
|
13
15
|
export { validateForm } from './core/validation/validate-form';
|