@reformer/core 1.1.0 → 2.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/dist/behaviors/compute-from.d.ts +2 -0
  2. package/dist/behaviors/compute-from.js +31 -0
  3. package/dist/behaviors/copy-from.d.ts +2 -0
  4. package/dist/behaviors/copy-from.js +29 -0
  5. package/dist/behaviors/enable-when.d.ts +2 -0
  6. package/dist/behaviors/enable-when.js +25 -0
  7. package/dist/behaviors/reset-when.d.ts +2 -0
  8. package/dist/behaviors/reset-when.js +24 -0
  9. package/dist/behaviors/revalidate-when.d.ts +2 -0
  10. package/dist/behaviors/revalidate-when.js +18 -0
  11. package/dist/behaviors/sync-fields.d.ts +2 -0
  12. package/dist/behaviors/sync-fields.js +41 -0
  13. package/dist/behaviors/transform-value.d.ts +2 -0
  14. package/dist/behaviors/transform-value.js +45 -0
  15. package/dist/behaviors/watch-field.d.ts +2 -0
  16. package/dist/behaviors/watch-field.js +21 -0
  17. package/dist/behaviors.d.ts +6 -2
  18. package/dist/behaviors.js +27 -228
  19. package/dist/core/behavior/behavior-context.d.ts +32 -14
  20. package/dist/core/behavior/behavior-registry.d.ts +15 -27
  21. package/dist/core/behavior/behaviors/compute-from.d.ts +50 -21
  22. package/dist/core/behavior/behaviors/copy-from.d.ts +39 -14
  23. package/dist/core/behavior/behaviors/enable-when.d.ts +88 -19
  24. package/dist/core/behavior/behaviors/reset-when.d.ts +31 -18
  25. package/dist/core/behavior/behaviors/revalidate-when.d.ts +40 -17
  26. package/dist/core/behavior/behaviors/sync-fields.d.ts +34 -14
  27. package/dist/core/behavior/behaviors/transform-value.d.ts +116 -44
  28. package/dist/core/behavior/behaviors/watch-field.d.ts +66 -21
  29. package/dist/core/behavior/compose-behavior.d.ts +2 -12
  30. package/dist/core/behavior/index.d.ts +0 -1
  31. package/dist/core/behavior/types.d.ts +2 -8
  32. package/dist/core/factories/node-factory.d.ts +6 -29
  33. package/dist/core/nodes/array-node.d.ts +42 -22
  34. package/dist/core/nodes/field-node.d.ts +51 -26
  35. package/dist/core/nodes/form-node.d.ts +18 -20
  36. package/dist/core/nodes/group-node.d.ts +37 -212
  37. package/dist/core/types/deep-schema.d.ts +2 -12
  38. package/dist/core/types/field-path.d.ts +1 -1
  39. package/dist/core/types/form-context.d.ts +36 -30
  40. package/dist/core/types/{group-node-proxy.d.ts → form-proxy.d.ts} +12 -42
  41. package/dist/core/types/index.d.ts +52 -6
  42. package/dist/core/types/validation-schema.d.ts +3 -12
  43. package/dist/core/utils/abstract-registry.d.ts +74 -0
  44. package/dist/core/utils/aggregate-signals.d.ts +71 -0
  45. package/dist/core/utils/create-form.d.ts +3 -20
  46. package/dist/core/utils/error-handler.d.ts +1 -18
  47. package/dist/core/utils/field-path-navigator.d.ts +1 -1
  48. package/dist/core/{validation → utils}/field-path.d.ts +23 -6
  49. package/dist/core/utils/form-observer.d.ts +176 -0
  50. package/dist/core/utils/form-proxy-builder.d.ts +25 -0
  51. package/dist/core/utils/form-submitter.d.ts +121 -0
  52. package/dist/core/utils/index.d.ts +10 -2
  53. package/dist/core/utils/registry-helpers.d.ts +0 -7
  54. package/dist/core/utils/safe-effect.d.ts +73 -0
  55. package/dist/core/utils/status-machine.d.ts +153 -0
  56. package/dist/core/utils/type-guards.d.ts +5 -23
  57. package/dist/core/utils/unique-id.d.ts +53 -0
  58. package/dist/core/validation/core/apply-when.d.ts +3 -9
  59. package/dist/core/validation/core/apply.d.ts +2 -13
  60. package/dist/core/validation/core/validate-async.d.ts +2 -8
  61. package/dist/core/validation/core/validate-tree.d.ts +10 -10
  62. package/dist/core/validation/core/validate.d.ts +1 -7
  63. package/dist/core/validation/index.d.ts +8 -2
  64. package/dist/core/validation/validate-form.d.ts +1 -38
  65. package/dist/core/validation/validation-applicator.d.ts +2 -21
  66. package/dist/core/validation/validation-context.d.ts +67 -28
  67. package/dist/core/validation/validation-registry.d.ts +11 -25
  68. package/dist/core/validation/validators/array-validators.d.ts +2 -12
  69. package/dist/core/validation/validators/date-utils.d.ts +26 -0
  70. package/dist/core/validation/validators/email.d.ts +2 -9
  71. package/dist/core/validation/validators/future-date.d.ts +35 -0
  72. package/dist/core/validation/validators/index.d.ts +7 -1
  73. package/dist/core/validation/validators/is-date.d.ts +36 -0
  74. package/dist/core/validation/validators/max-age.d.ts +36 -0
  75. package/dist/core/validation/validators/max-date.d.ts +36 -0
  76. package/dist/core/validation/validators/max-length.d.ts +3 -10
  77. package/dist/core/validation/validators/max.d.ts +3 -10
  78. package/dist/core/validation/validators/min-age.d.ts +36 -0
  79. package/dist/core/validation/validators/min-date.d.ts +36 -0
  80. package/dist/core/validation/validators/min-length.d.ts +3 -10
  81. package/dist/core/validation/validators/min.d.ts +3 -10
  82. package/dist/core/validation/validators/number.d.ts +2 -9
  83. package/dist/core/validation/validators/past-date.d.ts +35 -0
  84. package/dist/core/validation/validators/pattern.d.ts +2 -9
  85. package/dist/core/validation/validators/phone.d.ts +2 -9
  86. package/dist/core/validation/validators/required.d.ts +2 -9
  87. package/dist/core/validation/validators/url.d.ts +2 -9
  88. package/dist/date-utils-xUWFslTj.js +29 -0
  89. package/dist/field-path-DuKdGcIE.js +66 -0
  90. package/dist/hooks/types.d.ts +328 -0
  91. package/dist/hooks/useArrayLength.d.ts +31 -0
  92. package/dist/hooks/useFormControl.d.ts +15 -39
  93. package/dist/hooks/useFormControlValue.d.ts +167 -0
  94. package/dist/hooks/useHiddenCondition.d.ts +25 -0
  95. package/dist/hooks/useSignalSubscription.d.ts +17 -0
  96. package/dist/index-D25LsbRm.js +73 -0
  97. package/dist/index.d.ts +8 -1
  98. package/dist/index.js +3271 -8
  99. package/dist/registry-helpers-Bv_BJ1s-.js +615 -0
  100. package/dist/safe-effect-Dh8uw81c.js +20 -0
  101. package/dist/validate-C3XiA_zf.js +10 -0
  102. package/dist/validators/email.d.ts +2 -0
  103. package/dist/validators/email.js +13 -0
  104. package/dist/validators/future-date.d.ts +2 -0
  105. package/dist/validators/future-date.js +20 -0
  106. package/dist/validators/is-date.d.ts +2 -0
  107. package/dist/validators/is-date.js +12 -0
  108. package/dist/validators/max-age.d.ts +2 -0
  109. package/dist/validators/max-age.js +20 -0
  110. package/dist/validators/max-date.d.ts +2 -0
  111. package/dist/validators/max-date.js +20 -0
  112. package/dist/validators/max-length.d.ts +2 -0
  113. package/dist/validators/max-length.js +11 -0
  114. package/dist/validators/max.d.ts +2 -0
  115. package/dist/validators/max.js +11 -0
  116. package/dist/validators/min-age.d.ts +2 -0
  117. package/dist/validators/min-age.js +20 -0
  118. package/dist/validators/min-date.d.ts +2 -0
  119. package/dist/validators/min-date.js +20 -0
  120. package/dist/validators/min-length.d.ts +2 -0
  121. package/dist/validators/min-length.js +11 -0
  122. package/dist/validators/min.d.ts +2 -0
  123. package/dist/validators/min.js +11 -0
  124. package/dist/validators/number.d.ts +2 -0
  125. package/dist/validators/number.js +35 -0
  126. package/dist/validators/past-date.d.ts +2 -0
  127. package/dist/validators/past-date.js +20 -0
  128. package/dist/validators/pattern.d.ts +2 -0
  129. package/dist/validators/pattern.js +11 -0
  130. package/dist/validators/phone.d.ts +2 -0
  131. package/dist/validators/phone.js +35 -0
  132. package/dist/validators/required.d.ts +2 -0
  133. package/dist/validators/required.js +15 -0
  134. package/dist/validators/url.d.ts +2 -0
  135. package/dist/validators/url.js +19 -0
  136. package/dist/validators-BGsNOgT1.js +207 -0
  137. package/dist/validators.d.ts +6 -2
  138. package/dist/validators.js +54 -296
  139. package/llms.txt +8887 -59
  140. package/package.json +87 -8
  141. package/dist/core/behavior/behavior-applicator.d.ts +0 -71
  142. package/dist/core/behavior/behavior-applicator.js +0 -92
  143. package/dist/core/behavior/behavior-context.js +0 -38
  144. package/dist/core/behavior/behavior-registry.js +0 -198
  145. package/dist/core/behavior/behaviors/compute-from.js +0 -84
  146. package/dist/core/behavior/behaviors/copy-from.js +0 -64
  147. package/dist/core/behavior/behaviors/enable-when.js +0 -81
  148. package/dist/core/behavior/behaviors/index.js +0 -11
  149. package/dist/core/behavior/behaviors/reset-when.js +0 -63
  150. package/dist/core/behavior/behaviors/revalidate-when.js +0 -51
  151. package/dist/core/behavior/behaviors/sync-fields.js +0 -66
  152. package/dist/core/behavior/behaviors/transform-value.js +0 -110
  153. package/dist/core/behavior/behaviors/watch-field.js +0 -56
  154. package/dist/core/behavior/compose-behavior.js +0 -166
  155. package/dist/core/behavior/create-field-path.d.ts +0 -20
  156. package/dist/core/behavior/create-field-path.js +0 -69
  157. package/dist/core/behavior/index.js +0 -17
  158. package/dist/core/behavior/types.js +0 -7
  159. package/dist/core/context/form-context-impl.d.ts +0 -29
  160. package/dist/core/context/form-context-impl.js +0 -37
  161. package/dist/core/factories/index.js +0 -6
  162. package/dist/core/factories/node-factory.js +0 -281
  163. package/dist/core/nodes/array-node.js +0 -534
  164. package/dist/core/nodes/field-node.js +0 -510
  165. package/dist/core/nodes/form-node.js +0 -343
  166. package/dist/core/nodes/group-node/field-registry.d.ts +0 -191
  167. package/dist/core/nodes/group-node/field-registry.js +0 -215
  168. package/dist/core/nodes/group-node/index.d.ts +0 -11
  169. package/dist/core/nodes/group-node/index.js +0 -11
  170. package/dist/core/nodes/group-node/proxy-builder.d.ts +0 -71
  171. package/dist/core/nodes/group-node/proxy-builder.js +0 -161
  172. package/dist/core/nodes/group-node/state-manager.d.ts +0 -184
  173. package/dist/core/nodes/group-node/state-manager.js +0 -265
  174. package/dist/core/nodes/group-node.js +0 -770
  175. package/dist/core/types/deep-schema.js +0 -11
  176. package/dist/core/types/field-path.js +0 -4
  177. package/dist/core/types/form-context.js +0 -25
  178. package/dist/core/types/group-node-proxy.js +0 -31
  179. package/dist/core/types/index.js +0 -4
  180. package/dist/core/types/validation-schema.js +0 -10
  181. package/dist/core/utils/create-form.js +0 -24
  182. package/dist/core/utils/debounce.d.ts +0 -160
  183. package/dist/core/utils/debounce.js +0 -197
  184. package/dist/core/utils/error-handler.js +0 -226
  185. package/dist/core/utils/field-path-navigator.js +0 -374
  186. package/dist/core/utils/index.js +0 -14
  187. package/dist/core/utils/registry-helpers.js +0 -79
  188. package/dist/core/utils/registry-stack.js +0 -86
  189. package/dist/core/utils/resources.d.ts +0 -41
  190. package/dist/core/utils/resources.js +0 -69
  191. package/dist/core/utils/subscription-manager.js +0 -214
  192. package/dist/core/utils/type-guards.js +0 -169
  193. package/dist/core/validation/core/apply-when.js +0 -41
  194. package/dist/core/validation/core/apply.js +0 -38
  195. package/dist/core/validation/core/index.js +0 -8
  196. package/dist/core/validation/core/validate-async.js +0 -45
  197. package/dist/core/validation/core/validate-tree.js +0 -37
  198. package/dist/core/validation/core/validate.js +0 -38
  199. package/dist/core/validation/field-path.js +0 -147
  200. package/dist/core/validation/index.js +0 -33
  201. package/dist/core/validation/validate-form.js +0 -152
  202. package/dist/core/validation/validation-applicator.js +0 -217
  203. package/dist/core/validation/validation-context.js +0 -75
  204. package/dist/core/validation/validation-registry.js +0 -298
  205. package/dist/core/validation/validators/array-validators.js +0 -86
  206. package/dist/core/validation/validators/date.d.ts +0 -38
  207. package/dist/core/validation/validators/date.js +0 -117
  208. package/dist/core/validation/validators/email.js +0 -60
  209. package/dist/core/validation/validators/index.js +0 -14
  210. package/dist/core/validation/validators/max-length.js +0 -60
  211. package/dist/core/validation/validators/max.js +0 -60
  212. package/dist/core/validation/validators/min-length.js +0 -60
  213. package/dist/core/validation/validators/min.js +0 -60
  214. package/dist/core/validation/validators/number.js +0 -90
  215. package/dist/core/validation/validators/pattern.js +0 -62
  216. package/dist/core/validation/validators/phone.js +0 -58
  217. package/dist/core/validation/validators/required.js +0 -69
  218. package/dist/core/validation/validators/url.js +0 -55
  219. package/dist/create-field-path-CdPF3lIK.js +0 -704
  220. package/dist/hooks/useFormControl.js +0 -298
  221. package/dist/node-factory-D7DOnSSN.js +0 -3200
@@ -0,0 +1,2 @@
1
+ export * from '../core/behavior/behaviors/compute-from'
2
+ export {}
@@ -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,2 @@
1
+ export * from '../core/behavior/behaviors/copy-from'
2
+ export {}
@@ -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,2 @@
1
+ export * from '../core/behavior/behaviors/enable-when'
2
+ export {}
@@ -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,2 @@
1
+ export * from '../core/behavior/behaviors/reset-when'
2
+ export {}
@@ -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,2 @@
1
+ export * from '../core/behavior/behaviors/revalidate-when'
2
+ export {}
@@ -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,2 @@
1
+ export * from '../core/behavior/behaviors/sync-fields'
2
+ export {}
@@ -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,2 @@
1
+ export * from '../core/behavior/behaviors/transform-value'
2
+ export {}
@@ -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,2 @@
1
+ export * from '../core/behavior/behaviors/watch-field'
2
+ export {}
@@ -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
+ };
@@ -1,2 +1,6 @@
1
- export * from './core/behavior/index'
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 y, E as p, c as b } from "./create-field-path-CdPF3lIK.js";
2
- import { b as M, B as T } from "./create-field-path-CdPF3lIK.js";
3
- function v(e, t, r) {
4
- const { debounce: a, immediate: s = !1 } = r || {}, l = (u, i, c) => {
5
- const o = u.getFieldByPath(e.__path);
6
- if (!o) return null;
7
- if (s) {
8
- const n = o.value.value;
9
- t(n, i);
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
- M as BehaviorContextImpl,
214
- T as BehaviorRegistry,
215
- j as apply,
216
- D as applyWhen,
217
- R as computeFrom,
218
- A as copyFrom,
219
- b as createFieldPath,
220
- h as createTransformer,
221
- C as disableWhen,
222
- V as enableWhen,
223
- w as resetWhen,
224
- U as revalidateWhen,
225
- W as syncFields,
226
- N as toBehaviorFieldPath,
227
- F as transformValue,
228
- O as transformers,
229
- v as watchField
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
- * BehaviorContext - контекст для behavior callback функций
6
+ * Реализация {@link FormContext} для behaviors. Создаётся фреймворком и передаётся
7
+ * в callback'и behaviors (`watchField`, `computeFrom`, …) — напрямую инстанцировать
8
+ * не нужно.
3
9
  *
4
- * Реализует FormContext для behavior схем
5
- */
6
- import type { GroupNode } from '../nodes/group-node';
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
- * - `form` - прямой типизированный доступ к форме
14
- * - `setFieldValue` - безопасная установка значения (emitEvent: false)
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: GroupNodeWithControls<TForm>;
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
- setFieldValue(path: string, value: unknown): void;
46
+ getFieldByPath(path: string): import('../..').FormNode<import('../types').FormValue> | undefined;
29
47
  }