@reformer/core 11.0.0-beta.7 → 11.0.0-beta.9

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 (226) hide show
  1. package/README.md +90 -68
  2. package/dist/behaviors-value-HA_Q03hc.js +108 -0
  3. package/dist/behaviors.js +382 -217
  4. package/dist/create-model-BvcbNPgL.js +30 -0
  5. package/dist/date-utils-90-qZbse.js +43 -0
  6. package/dist/{en-CjAqn7h0.js → en-HP8XEych.js} +6 -3
  7. package/dist/form/aggregate-signals.d.ts +21 -63
  8. package/dist/form/behaviors/collections.d.ts +42 -8
  9. package/dist/form/behaviors/context.d.ts +37 -4
  10. package/dist/form/behaviors/index.d.ts +6 -4
  11. package/dist/form/behaviors/internals.d.ts +9 -3
  12. package/dist/form/behaviors/node.d.ts +25 -2
  13. package/dist/form/behaviors/operators.d.ts +17 -9
  14. package/dist/form/behaviors/schema-operators.d.ts +78 -0
  15. package/dist/form/behaviors/types.d.ts +25 -5
  16. package/dist/form/create-form.d.ts +57 -70
  17. package/dist/form/flow/flow.d.ts +87 -0
  18. package/dist/form/form-bundle.d.ts +153 -0
  19. package/dist/form/form-config-base.d.ts +46 -0
  20. package/dist/form/form-level.d.ts +121 -0
  21. package/dist/form/form-proxy-builder.d.ts +6 -22
  22. package/dist/form/index.d.ts +20 -20
  23. package/dist/form/nodes/form-array-node.d.ts +100 -0
  24. package/dist/form/nodes/form-control-node.d.ts +73 -0
  25. package/dist/form/nodes/form-group-node.d.ts +66 -0
  26. package/dist/form/nodes/node-kind.d.ts +29 -0
  27. package/dist/form/nodes/state/availability.d.ts +6 -0
  28. package/dist/form/nodes/state/component.d.ts +6 -0
  29. package/dist/form/nodes/state/index.d.ts +12 -0
  30. package/dist/form/nodes/state/interaction.d.ts +13 -0
  31. package/dist/form/nodes/state/issues.d.ts +9 -0
  32. package/dist/form/nodes/state/pending.d.ts +6 -0
  33. package/dist/form/schema/compile.d.ts +59 -0
  34. package/dist/form/schema/compiled.d.ts +143 -0
  35. package/dist/form/schema/row-key.d.ts +11 -0
  36. package/dist/form/schema-controller.d.ts +153 -0
  37. package/dist/form/schema-subtree.d.ts +28 -0
  38. package/dist/form/signal-node-registry.d.ts +27 -22
  39. package/dist/form/submission.d.ts +93 -0
  40. package/dist/form/type-guards.d.ts +14 -73
  41. package/dist/form/types/contracts.d.ts +19 -92
  42. package/dist/form/types/field-config.d.ts +27 -0
  43. package/dist/form/types/index.d.ts +5 -57
  44. package/dist/form/types/nodes.d.ts +159 -0
  45. package/dist/form/types/schema-node.d.ts +147 -46
  46. package/dist/form/types/validation-schema.d.ts +23 -27
  47. package/dist/form/validation/context.d.ts +46 -6
  48. package/dist/form/validation/index.d.ts +9 -8
  49. package/dist/form/validation/operators.d.ts +71 -17
  50. package/dist/form/validation/run.d.ts +93 -18
  51. package/dist/form/validation/strategy.d.ts +41 -13
  52. package/dist/form/validation/types.d.ts +74 -19
  53. package/dist/form/validators/date-utils.d.ts +13 -1
  54. package/dist/form/validators/email.d.ts +8 -7
  55. package/dist/form/validators/file-type.d.ts +8 -7
  56. package/dist/form/validators/file-utils.d.ts +2 -1
  57. package/dist/form/validators/future-date.d.ts +8 -7
  58. package/dist/form/validators/index.d.ts +1 -1
  59. package/dist/form/validators/integer.d.ts +8 -7
  60. package/dist/form/validators/is-date.d.ts +11 -9
  61. package/dist/form/validators/is-number.d.ts +11 -9
  62. package/dist/form/validators/max-age.d.ts +13 -9
  63. package/dist/form/validators/max-date.d.ts +8 -7
  64. package/dist/form/validators/max-file-size.d.ts +8 -7
  65. package/dist/form/validators/max-files.d.ts +8 -7
  66. package/dist/form/validators/max-length.d.ts +14 -7
  67. package/dist/form/validators/max-total-file-size.d.ts +8 -7
  68. package/dist/form/validators/max.d.ts +10 -8
  69. package/dist/form/validators/min-age.d.ts +12 -9
  70. package/dist/form/validators/min-date.d.ts +8 -7
  71. package/dist/form/validators/min-file-size.d.ts +8 -7
  72. package/dist/form/validators/min-files.d.ts +11 -9
  73. package/dist/form/validators/min-length.d.ts +14 -7
  74. package/dist/form/validators/min.d.ts +10 -8
  75. package/dist/form/validators/multiple-of.d.ts +10 -8
  76. package/dist/form/validators/non-negative.d.ts +8 -7
  77. package/dist/form/validators/non-zero.d.ts +8 -7
  78. package/dist/form/validators/past-date.d.ts +8 -7
  79. package/dist/form/validators/pattern.d.ts +9 -8
  80. package/dist/form/validators/phone.d.ts +8 -7
  81. package/dist/form/validators/required.d.ts +11 -9
  82. package/dist/form/validators/url.d.ts +20 -13
  83. package/dist/form/validators/validation-issue.d.ts +8 -0
  84. package/dist/i18n/descriptor.d.ts +1 -1
  85. package/dist/i18n/en.json.d.ts +5 -1
  86. package/dist/i18n/locale-store.d.ts +7 -0
  87. package/dist/i18n/message-format.d.ts +24 -4
  88. package/dist/i18n/ru.json.d.ts +5 -1
  89. package/dist/i18n/translator.d.ts +11 -0
  90. package/dist/i18n/validation-message.d.ts +42 -7
  91. package/dist/i18n.d.ts +7 -12
  92. package/dist/i18n.js +66 -283
  93. package/dist/index.d.ts +16 -7
  94. package/dist/index.js +958 -2798
  95. package/dist/loader-BWkigpVe.js +52 -0
  96. package/dist/locale/en.js +1 -1
  97. package/dist/locale/en.json +4 -1
  98. package/dist/locale/ru.js +4 -1
  99. package/dist/locale/ru.json +4 -1
  100. package/dist/locale-CG54AU2Q.js +219 -0
  101. package/dist/locale.js +1 -1
  102. package/dist/model/behaviors-value.d.ts +24 -6
  103. package/dist/model/create-model.d.ts +2 -2
  104. package/dist/model/derived-registry.d.ts +1 -1
  105. package/dist/model/index.d.ts +16 -5
  106. package/dist/model/model-nodes.d.ts +138 -8
  107. package/dist/model/model-signals-proxy.d.ts +11 -5
  108. package/dist/model/model-value-proxy.d.ts +84 -3
  109. package/dist/model/safe-effect.d.ts +33 -1
  110. package/dist/model/types.d.ts +70 -17
  111. package/dist/model.js +21 -17
  112. package/dist/node-kind-C-r6ZMdo.js +15 -0
  113. package/dist/platforms/react/field-binding/field-adapter.d.ts +1 -1
  114. package/dist/platforms/react/field-binding/field-handle.d.ts +5 -2
  115. package/dist/platforms/react/form-bundle-context.d.ts +27 -0
  116. package/dist/platforms/react/hooks/types.d.ts +57 -38
  117. package/dist/platforms/react/hooks/use-form-bundle.d.ts +19 -4
  118. package/dist/platforms/react/hooks/use-form-flow.d.ts +40 -0
  119. package/dist/platforms/react/hooks/use-form-validation.d.ts +12 -6
  120. package/dist/platforms/react/hooks/useArrayLength.d.ts +6 -6
  121. package/dist/platforms/react/hooks/useFormControl.d.ts +7 -9
  122. package/dist/platforms/react/hooks/useFormControlValue.d.ts +18 -19
  123. package/dist/platforms/react/hooks/useSignalSubscription.d.ts +9 -1
  124. package/dist/platforms/react/i18n/context.d.ts +6 -1
  125. package/dist/platforms/react/i18n/hooks.d.ts +16 -10
  126. package/dist/platforms/react/i18n/provider.d.ts +9 -2
  127. package/dist/platforms/react/index.d.ts +7 -4
  128. package/dist/react.d.ts +22 -0
  129. package/dist/react.js +505 -0
  130. package/dist/runtime-token.d.ts +1 -2
  131. package/dist/safe-effect-BbtX3KuN.js +643 -0
  132. package/dist/schema-controller-CpiO2JoK.js +143 -0
  133. package/dist/signals.d.ts +15 -9
  134. package/dist/signals.js +11 -6
  135. package/dist/strategy-CoFSemuP.js +375 -0
  136. package/dist/type-guards-D-N_5Ddh.js +19 -0
  137. package/dist/validation-issue-B9mjI8jz.js +7 -0
  138. package/dist/validation-message-Ced9MGxs.js +194 -0
  139. package/dist/validation.js +9 -8
  140. package/dist/validators/email.js +5 -5
  141. package/dist/validators/future-date.js +8 -8
  142. package/dist/validators/integer.js +3 -3
  143. package/dist/validators/is-date.js +4 -4
  144. package/dist/validators/is-number.js +4 -4
  145. package/dist/validators/max-age.js +8 -9
  146. package/dist/validators/max-date.js +8 -8
  147. package/dist/validators/max-length.js +7 -7
  148. package/dist/validators/max.js +4 -4
  149. package/dist/validators/min-age.js +10 -8
  150. package/dist/validators/min-date.js +3 -3
  151. package/dist/validators/min-length.js +5 -5
  152. package/dist/validators/min.js +4 -4
  153. package/dist/validators/multiple-of.js +11 -7
  154. package/dist/validators/non-negative.js +3 -3
  155. package/dist/validators/non-zero.js +3 -3
  156. package/dist/validators/past-date.js +8 -8
  157. package/dist/validators/pattern.js +5 -5
  158. package/dist/validators/phone.js +11 -9
  159. package/dist/validators/required.js +2 -2
  160. package/dist/validators/url.js +48 -12
  161. package/dist/validators.js +17 -17
  162. package/docs/llms/01-api-reference.md +60 -34
  163. package/docs/llms/02-quick-start.md +111 -80
  164. package/docs/llms/03-api-signatures.md +368 -153
  165. package/docs/llms/04-common-patterns.md +58 -56
  166. package/docs/llms/05-common-mistakes.md +69 -44
  167. package/docs/llms/06-troubleshooting.md +14 -9
  168. package/docs/llms/07-complete-import.md +74 -43
  169. package/docs/llms/08-form-types.md +11 -4
  170. package/docs/llms/09-formschema.md +131 -83
  171. package/docs/llms/10-arrays.md +119 -69
  172. package/docs/llms/11-async-watchfield.md +2 -2
  173. package/docs/llms/13-multi-step.md +134 -63
  174. package/docs/llms/14-extended-mistakes.md +20 -17
  175. package/docs/llms/15-project-structure.md +221 -74
  176. package/docs/llms/16-ui-components.md +55 -42
  177. package/docs/llms/17-nonexistent-api.md +199 -32
  178. package/docs/llms/18-conditional-fields.md +66 -32
  179. package/docs/llms/19-reading-values.md +15 -3
  180. package/docs/llms/20-compute-vs-watch.md +16 -10
  181. package/docs/llms/21-array-operations.md +76 -26
  182. package/docs/llms/22-cycle-detection.md +1 -1
  183. package/docs/llms/23-copy-from.md +2 -2
  184. package/docs/llms/24-sync-fields.md +6 -5
  185. package/docs/llms/25-reset-when.md +14 -7
  186. package/docs/llms/26-transform-value.md +4 -4
  187. package/docs/llms/27-revalidate-when.md +16 -15
  188. package/docs/llms/28-submit-and-reset.md +276 -128
  189. package/docs/llms/29-async-preload.md +40 -30
  190. package/docs/llms/30-type-safety-recipes.md +105 -51
  191. package/docs/llms/31-async-validator-debounce.md +96 -53
  192. package/docs/llms/33-validation-strategy.md +178 -66
  193. package/docs/llms/34-i18n.md +69 -43
  194. package/docs/llms/35-unified-contract.md +307 -0
  195. package/docs/llms/36-issue-messages.md +284 -0
  196. package/docs/llms/37-compiled-schema.md +332 -0
  197. package/docs/llms/38-form-flow.md +397 -0
  198. package/llms-index.json +1 -1
  199. package/llms.txt +6968 -3278
  200. package/package.json +23 -4
  201. package/dist/behaviors-value-C7dSEhCc.js +0 -134
  202. package/dist/create-model-B8U-COv-.js +0 -103
  203. package/dist/date-utils-dTT_x_Be.js +0 -31
  204. package/dist/form/create-core-form.d.ts +0 -70
  205. package/dist/form/factories/index.d.ts +0 -6
  206. package/dist/form/factories/node-factory.d.ts +0 -189
  207. package/dist/form/form-submitter.d.ts +0 -121
  208. package/dist/form/nodes/array-node.d.ts +0 -276
  209. package/dist/form/nodes/field-node.d.ts +0 -297
  210. package/dist/form/nodes/form-node.d.ts +0 -326
  211. package/dist/form/nodes/group-node.d.ts +0 -284
  212. package/dist/form/nodes/model-array-node.d.ts +0 -121
  213. package/dist/form/nodes/subscription-manager.d.ts +0 -180
  214. package/dist/form/status-machine.d.ts +0 -115
  215. package/dist/form/types/deep-schema.d.ts +0 -107
  216. package/dist/form/types/form-proxy.d.ts +0 -141
  217. package/dist/form/unique-id.d.ts +0 -45
  218. package/dist/form/validation/config.d.ts +0 -73
  219. package/dist/form/validation/error-handler.d.ts +0 -166
  220. package/dist/form/validators/validation-error.d.ts +0 -8
  221. package/dist/index-BrNkQj1y.js +0 -105
  222. package/dist/loader-Dv_Hl7JC.js +0 -216
  223. package/dist/model-signals-proxy-2vqS243J.js +0 -250
  224. package/dist/node-DGEFMTQu.js +0 -18
  225. package/dist/strategy-BXS_gBfz.js +0 -170
  226. package/dist/validation-error-B-U3RsV0.js +0 -11
@@ -3,43 +3,58 @@
3
3
  One form is one module folder. **Default layout — flat minimalist:** every concern is a single
4
4
  file at the module root, and the whole form (entry + all wizard steps inline) lives in one
5
5
  `index.tsx`. Naming rule: **`form.<role>` is a form artefact, the suffix names its role** —
6
- `form.schema.*` (layout), `form.behavior.ts` (model behavior), `form.render.ts` (render-layer
7
- behavior, renderer targets only), `form.validation.ts` (validation rules); every other file has
8
- no prefix. A wizard may instead keep each
9
- step's code in `steps/<slug>/` (same file names inside) with a `steps/index.ts` aggregator. The old
10
- `renderer.schema.*` / `renderer.behavior.ts` / `renderer.wizard.tsx` / `validation.ts` names still
11
- work with a warning. No `lib/` / `schema/` / `components/` nesting until the form grows (see "Scaling up" below). Arrays are declared in `form.schema.ts`
12
- and rendered with `FormArraySection` — no per-step component files.
6
+ `form.schema.*` (layout), `form.behavior.ts` (form behavior: model operators AND schema-node rules
7
+ such as `hideWhen` / `onComponentEvent`), `form.validation.ts` (validation rules), and the optional
8
+ `form.flow.ts` (the steps of a wizard) and `form.messages.ts` (the issue-message dictionary); every
9
+ other file has no prefix. There is one behavior per form:
10
+ the former render-layer file `form.render.ts` (and `renderer.behavior.ts`) is retired — its node
11
+ rules move into `form.behavior.ts`. The old `renderer.schema.*` / `validation.ts` names, and the
12
+ retired `form.render.ts` / `wizard.tsx` / `renderer.wizard.tsx`, are accepted with a warning. No
13
+ folders until the form grows (see "Scaling up" below). Arrays are declared in `form.schema.ts` and
14
+ rendered with `FieldArray` / `FieldArraySection` — no per-step component files.
13
15
 
14
16
  ```
15
17
  src/
16
- ├── components/ui/ # App-wide reusable UI (FormField, FormArraySection, ...)
18
+ ├── components/ui/ # App-wide reusable UI (FormField, FieldArraySection, ...)
17
19
  │
18
20
  ├── forms/
19
21
  │ └── [form-name]/ # Form module — flat, one file per concern
20
- │ ├── index.tsx # entry + whole form: ONE createCoreForm call → <FormWizard> with all steps inline; arrays via FormArraySection
21
- │ ├── types.ts # form type + enums + { value, label } option type + constant dictionaries
22
- │ ├── model.ts # createModel + initial values + empty-array-element factories
23
- │ ├── form.schema.ts # FormSchema: { value: model.$.x, component, componentProps }
24
- │ ├── form.behavior.ts # defineFormBehavior: compute / enableWhen / hideWhen / copyFrom / onChange
25
- │ ├── form.validation.ts # ALL validation → { validateStep, validateAll }
22
+ │ ├── index.tsx # entry + whole form: ONE createForm call → <FormWizard flow={bundle.flow}> with all steps inline
23
+ │ ├── types.ts # form type (interface or type) + enums + { value, label } option type + constant dictionaries
24
+ │ ├── model.ts # createModel + initial values + arrayOf(blank) templates of array rows
25
+ │ ├── form.schema.ts # schema builder (model) => node tree: { model: model.$.x, component, componentProps }
26
+ │ ├── form.behavior.ts # defineFormBehavior: compute / enableWhen / copyFrom / onChange + hideWhen / onComponentEvent
27
+ │ ├── form.validation.ts # rules of each step (exported) + extras
28
+ │ ├── form.flow.ts # optional, wizard: flow { steps: [{ id, rules }] }
29
+ │ ├── form.messages.ts # optional: defineIssueMessages dictionary (issue texts by code)
26
30
  │ ├── data-sources.ts # options + async loaders (dataSources)
27
31
  │ └── api.ts # submit + prefill/load
28
32
  ```
29
33
 
34
+ Optionally a wizard may keep its steps in folders: `steps/index.ts` (step order) and one
35
+ `steps/<slug>/` folder per step (`<slug>` — kebab-case of the step title, no number) with the same
36
+ file names — `form.schema.ts`, `form.validation.ts`, `form.behavior.ts` — for the step only;
37
+ everything that crosses steps stays in the root files.
38
+
30
39
  Rule of thumb: **one concern → one file at the module root; the whole component tree (all steps) →
31
- `index.tsx`; validation is a single `form.validation.ts`.** This is the working default for
40
+ `index.tsx`; validation rules are a single `form.validation.ts`, the steps — `form.flow.ts`.** This is the working default for
32
41
  almost every form — reach for folders only when a file stops fitting on a screen.
33
42
 
34
43
  ### Key Files
35
44
 
36
45
  ```typescript
37
- // forms/credit-application/types.ts
38
- export type CreditApplicationForm = {
46
+ // forms/credit-application/types.ts — `interface` and `type` both work
47
+ export interface CreditApplication {
39
48
  loanType: LoanType;
40
- loanAmount: number | null;
49
+ loanAmount: number | null; // an empty number input is `null`
41
50
  // ...
42
- };
51
+ }
52
+ // computed fields (targets of `compute`) — a separate type; the form is the intersection
53
+ export interface CreditApplicationDerived {
54
+ monthlyPayment: number;
55
+ // ...
56
+ }
57
+ export type CreditApplicationForm = CreditApplication & CreditApplicationDerived;
43
58
 
44
59
  // forms/credit-application/model.ts
45
60
  import { createModel, type FormModel } from '@reformer/core';
@@ -47,86 +62,218 @@ export const createCreditApplicationModel = (): FormModel<CreditApplicationForm>
47
62
  createModel<CreditApplicationForm>(createInitialCreditApplication());
48
63
 
49
64
  // forms/credit-application/form.schema.ts
50
- import type { FormModel } from '@reformer/core';
51
- export const creditApplicationSchema = (model: FormModel<CreditApplicationForm>) => ({
52
- loanType: { value: model.$.loanType, component: SelectAsync, componentProps: { /* ... */ } },
53
- personalData: personalDataNodes(model.$.personalData),
54
- properties: { array: model.properties, item: propertyItem },
65
+ import type { FormModel, FormSchemaNode } from '@reformer/core';
66
+ export const creditApplicationSchema = (
67
+ model: FormModel<CreditApplicationForm>
68
+ ): FormSchemaNode => ({
69
+ // Nested nodes live in `children` only — not in componentProps, not under arbitrary keys.
70
+ children: [
71
+ { model: model.$.loanType, component: SelectAsync, componentProps: { /* ... */ } }, // field
72
+ { model: model.$.registrationAddress, part: address }, // sub-form: group + part
73
+ { model: model.$.properties, component: FieldArray, item: propertyRow }, // array of sub-forms
74
+ ],
55
75
  });
56
76
 
57
- // forms/credit-application/form.behavior.ts
58
- import { defineFormBehavior, compute, enableWhen } from '@reformer/core/behaviors';
59
- export const creditApplicationBehavior = defineFormBehavior<CreditApplicationForm>(({ model }) => {
60
- compute(model.$.monthlyPayment, () => computeMonthlyPayment(model));
61
- enableWhen([model.$.propertyValue], () => model.loanType === 'mortgage', { resetOnDisable: true });
77
+ // forms/credit-application/form.behavior.ts — ONE behavior: model operators and node rules
78
+ import { defineFormBehavior, compute, enableWhen, hideWhen } from '@reformer/core/behaviors';
79
+ export const creditApplicationBehavior = defineFormBehavior<CreditApplicationForm>(
80
+ ({ model, schema }) => {
81
+ compute(model.$.monthlyPayment, () => computeMonthlyPayment(model));
82
+ enableWhen([model.$.propertyValue], () => model.loanType === 'mortgage', { resetOnDisable: true });
83
+ hideWhen(schema.node('mortgage'), () => model.loanType !== 'mortgage'); // executed by the renderer
84
+ }
85
+ );
86
+
87
+ // forms/credit-application/form.validation.ts — step rules (exported) and the extras
88
+ import type { FormValidation } from '@reformer/core';
89
+ import { defineValidation } from '@reformer/core/validation';
90
+ export const loanRules = defineValidation<CreditApplicationForm>(({ model }) => { /* ... */ });
91
+ export const contactsRules = defineValidation<CreditApplicationForm>(({ model }) => { /* ... */ });
92
+ export const creditApplicationValidation: FormValidation<CreditApplicationForm> = {
93
+ extras: crossStepRules, // checked only as a whole (submit)
94
+ };
95
+
96
+ // forms/credit-application/form.flow.ts — the steps of the wizard
97
+ import type { FormFlowConfig } from '@reformer/core';
98
+ import { loanRules, contactsRules } from './form.validation';
99
+ export const creditApplicationFlow: FormFlowConfig<CreditApplicationForm> = {
100
+ steps: [
101
+ { id: 'loan', rules: loanRules }, // id = selector of the step node in form.schema.ts
102
+ { id: 'contacts', rules: contactsRules },
103
+ ],
104
+ };
105
+
106
+ // forms/credit-application/form.messages.ts — the issue texts by code
107
+ import { defineIssueMessages } from '@reformer/core/i18n';
108
+ export const creditApplicationMessages = defineIssueMessages({
109
+ 'loanAmount.required': 'Укажите сумму кредита',
62
110
  });
63
111
 
64
112
  // forms/credit-application/index.tsx — entry: assembles the form, renders <FormWizard> with all steps inline
65
- import { createCoreForm } from '@reformer/core';
66
- // ONE call: model + form + behavior + validation. In the page: useFormBundle(createCreditApplicationForm).
113
+ import { createForm } from '@reformer/core';
114
+ // ONE call: model + form + behavior + validation + flow. In the page: useFormBundle(createCreditApplicationForm).
67
115
  export const createCreditApplicationForm = () =>
68
- createCoreForm({
116
+ createForm<CreditApplicationForm>({
69
117
  model: createCreditApplicationModel(),
70
118
  schema: creditApplicationSchema, // builder (model) => tree
71
119
  behavior: creditApplicationBehavior,
72
- validation: creditApplicationValidation, // { steps, extras } → bundle.validation
120
+ validation: creditApplicationValidation, // { extras } — rules outside the steps
121
+ flow: creditApplicationFlow, // steps → bundle.flow, bundle.validateStep(id)
73
122
  });
123
+ // The page: <ValidationMessagesProvider messages={creditApplicationMessages}> around the form,
124
+ // <FormWizard form={bundle.form} flow={bundle.flow} … onSubmit={() => bundle.submission.submit(api.send)} />.
74
125
  ```
75
126
 
76
127
  ### Scaling up: folders (large forms)
77
128
 
78
- When the flat module gets unwieldy — steps you want in their own files, sub-forms reused across
79
- steps, calc/validators that outgrow one file — promote it to a three-folder module: `lib/`
80
- (domain raw material), `schema/` (the form definition), `components/` (React layout), plus the
81
- entry component and `index.ts`. Keep the module root to just the entry + `index.ts`; everything
82
- else lives in a folder.
129
+ When the flat module gets unwieldy — a multi-step wizard, sub-forms reused across steps, rules
130
+ that outgrow one file — split it by **concern**, one folder per layer. Each layer answers one
131
+ question about the form:
132
+
133
+ | Folder | Question it answers |
134
+ | -------------- | ------------------------------------------------------- |
135
+ | `model/` | What data does the form hold, and what does it start as |
136
+ | `schema/` | How is the form laid out |
137
+ | `validation/` | What is a valid value |
138
+ | `behavior/` | How do values and field state react to each other |
139
+ | `flow/` | Which steps does the user walk through, in what order |
140
+ | `application/` | How is the form assembled, loaded and submitted |
83
141
 
84
142
  ```
85
143
  forms/
86
- └── [form-name]/ # Form module — folders (scale-up)
87
- ├── [FormName]Form.tsx # Entry: builds model+form, renders FormWizard + step components
88
- ├── index.ts # Public re-exports of the module
144
+ └── [form-name]/
145
+ ├── [FormName]Form.tsx # Entry: builds the form, renders FormWizard + step components
146
+ │
147
+ ├── model/
148
+ │ ├── model.ts # create[FormName]Model — the reactive model
149
+ │ ├── initial-value.ts # initial values; arrays via arrayOf(blank)
150
+ │ ├── predicates.ts # conditions shared by behavior, validation and JSX
151
+ │ └── factories/ # blank values of sub-forms and array rows
152
+ │ ├── address.ts
153
+ │ └── property.ts
154
+ │
155
+ ├── schema/
156
+ │ ├── form.ts # the tree: loading → wizard → steps taken from the flow
157
+ │ ├── steps/ # content of each step (an array of nodes)
158
+ │ │ ├── loan.ts
159
+ │ │ └── contacts.ts
160
+ │ └── sections/ # sections, sub-forms (part) and array rows (item)
161
+ │ ├── address.ts
162
+ │ └── property.ts
163
+ │
164
+ ├── validation/
165
+ │ ├── form.ts # FormValidation: { extras } — rules outside the steps
166
+ │ ├── messages.ts # defineIssueMessages: issue code → text
167
+ │ ├── common/ # shared rule sets, rules of sub-forms and array rows
168
+ │ │ ├── rules.ts
169
+ │ │ └── address.ts
170
+ │ ├── loan.ts # rules of one step — one file per step
171
+ │ ├── contacts.ts
172
+ │ └── cross-step.ts # rules of the whole form (checked on submit)
89
173
  │
90
- ├── lib/ # Domain helpers (target-agnostic)
91
- │ ├── types.ts # Form interface + field enums + { value, label } option type
92
- │ ├── constants.ts # Option dictionaries (LOAN_TYPES, GENDERS, ...)
93
- │ ├── calc.ts # Pure fns for derived fields (age, monthlyPayment, ...)
94
- │ ├── custom-validators.ts # Reusable validator factories
95
- │ └── api.ts # Data sources + submit
174
+ ├── behavior/
175
+ │ ├── index.ts # the form behavior, composed of the parts below
176
+ │ ├── derived.ts # computed fields
177
+ │ ├── conditions.ts # enabling fields and hiding sections
178
+ │ ├── synchronization.ts # copies, clearing lists
179
+ │ ├── dynamic-options.ts # options and limits that depend on values
180
+ │ └── operators.ts # custom operators built on the built-in ones
96
181
  │
97
- ├── schema/ # The form definition
98
- │ ├── model.ts # createModel factory + initial values + array-element factories
99
- │ ├── form.schema.ts # schema builder (model) => tree ({ value: model.$.x, component })
100
- │ ├── form.validation.ts # defineValidationSchema + validateModel config ({ validateStep, validateAll })
101
- │ ├── form.behavior.ts # defineFormBehavior(...)
102
- │ └── create-form.ts # Assembly: createCoreForm({ model, schema, behavior, validation })
182
+ ├── flow/
183
+ │ └── [form-name]-flow.ts # the list of steps: selector, title, icon, content, rules
184
+ │ # + FormFlowConfig { steps: [{ id, rules }] } for createForm
103
185
  │
104
- └── components/
105
- ├── steps/ # One component per wizard step
106
- ├── nested-forms/ # Reusable sub-forms (Address, PersonalData, ...)
107
- └── ui/ # Form-specific helper blocks (summary, warnings, sections)
186
+ ├── application/
187
+ │ ├── create.ts # ONE createForm call shared by every way of rendering
188
+ │ ├── load.ts # network: fetch the entity and dictionaries
189
+ │ ├── mapping.ts # server response → model (model.patch + captureInitial)
190
+ │ ├── payload.ts # form values → request body: drops the computed fields
191
+ │ ├── submit.ts # sending and reporting the outcome (handler of bundle.submission.submit)
192
+ │ └── renderer.ts # node rules for the renderer: loading, submit, navigation (setup)
193
+ │
194
+ ├── components/ # React layout: steps/, nested-forms/, ui/
195
+ ├── api/ # HTTP calls
196
+ └── types/ constants/ utils/ # form type, option dictionaries, pure calculations
197
+ ```
198
+
199
+ Dependencies point one way: `application → flow → schema/steps, validation/<step>`;
200
+ `application → behavior → model`. Nothing below `application/` knows the entity id, the network or
201
+ the wizard — the behavior is static and reusable.
202
+
203
+ **The flow is the single place a step is declared.** One entry carries the step's `selector`,
204
+ title, icon, content and rules, so the step nodes of the schema, the `flow` of the assembly and
205
+ the wizard steps of a hand-written React page are all derived from the same list — there is
206
+ nowhere to pair the layout of one step with the rules of another:
207
+
208
+ ```typescript
209
+ // flow/credit-application-flow.ts
210
+ export const creditApplicationFlow = [
211
+ { selector: 'loan', title: 'Loan', icon: '💰', content: loanStep, rules: loanRules },
212
+ { selector: 'contacts', title: 'Contacts', icon: '📞', content: contactsStep, rules: contactsRules },
213
+ ] as const satisfies readonly FlowStep[];
214
+
215
+ // the same list → the flow of createForm; the step id is the step selector
216
+ export const creditApplicationFlowSteps: FormFlowConfig<CreditApplicationForm> = {
217
+ steps: creditApplicationFlow.map((step) => ({ id: step.selector, rules: step.rules })),
218
+ };
219
+
220
+ // schema/form.ts — step nodes come from the flow
221
+ children: creditApplicationFlow.map((step) => ({
222
+ selector: step.selector,
223
+ component: Step,
224
+ componentProps: { title: step.title, icon: step.icon },
225
+ children: step.content(model),
226
+ })),
227
+
228
+ // validation/form.ts — only the rules outside the steps
229
+ export const creditApplicationValidation: FormValidation<CreditApplicationForm> = {
230
+ extras: crossStepRules,
231
+ };
232
+
233
+ // application/create.ts
234
+ createForm<CreditApplicationForm>({
235
+ model: createCreditApplicationModel(),
236
+ schema: creditApplicationSchema,
237
+ behavior: creditApplicationBehavior,
238
+ validation: creditApplicationValidation,
239
+ flow: creditApplicationFlowSteps,
240
+ });
108
241
  ```
109
242
 
110
- Rule of thumb for this layout: **domain raw material → `lib/`; anything describing the form →
111
- `schema/`; React layout → `components/`; root = entry + `index.ts`.** In very large forms you
112
- may co-locate each step's `form.schema.ts` / `form.validation.ts` / `form.behavior.ts` inside its
113
- `steps/[Step]/` folder, keeping only the shared `model` and cross-step rules in `schema/` — see
114
- the guide below.
243
+ **Texts of the issues live in `validation/messages.ts`.** Rules carry codes
244
+ (`required({ code: 'loanAmount.required' })`), the dictionary maps a code to its text, and every
245
+ way of rendering wraps the form in `<ValidationMessagesProvider messages={…}>` from
246
+ `@reformer/cdk` — the texts are the same in hand-written React, renderer-react and renderer-json.
247
+
248
+ **Conditions live in `model/predicates.ts`** as pure functions over values
249
+ (`isMortgage(loanType)`). Behavior (`enableWhen`, `hideWhen`), validation (`validateWhen`) and the
250
+ JSX of a step call the same function — a condition is written once.
251
+
252
+ **Loading and submitting are not behavior.** They belong to `application/`: the page (or, for the
253
+ renderer, `application/renderer.ts` passed as `setup`) calls `load`, hands the response to
254
+ `mapping`, and sends through `bundle.submission.submit(handler)` — one run of all the rules, the
255
+ handler is called only when the form is valid. Written into the model with `model.patch` followed
256
+ by `model.captureInitial()`, the loaded values become the form's starting point: the form is not
257
+ dirty, and `model.reset()` returns to them. The handler receives `model.get()` — the whole model,
258
+ disabled fields included; `application/payload.ts` drops the fields the server does not expect
259
+ (computed ones) before the request.
260
+
261
+ Rule of thumb for this layout: **one folder per question; a step is declared once, in the flow;
262
+ the root holds only the entry component.**
115
263
 
116
264
  ### Scaling
117
265
 
118
266
  | Complexity | Structure |
119
267
  | ---------- | --------------------------------------------------------------------------------------- |
120
268
  | Simple | Single file: `index.tsx` (model + schema + behavior + component) |
121
- | **Minimalist (flat)** | **Default.** One file per concern at the module root (`types` / `model` / `form.schema` / `form.behavior` / `validation` / `data-sources` / `api`) + `index.tsx` with all steps inline |
122
- | Folders (`lib/` + `schema/` + `components/`) | Large forms: split concerns into folders, one component per step, reusable `nested-forms/` |
123
-
124
- > The leading layout is configurable: set `REFORMER_FORM_LAYOUT` (`minimalist` | `folders`)
125
- > when registering the MCP server to choose which structure the generators lead with. Default
126
- > is `minimalist`.
127
-
128
- > Cross-target variants (renderer-react `form.schema.ts` + `form.render.ts` /
129
- > renderer-json `form.schema.ts` + `form.render.ts` + `registry.ts`, plus an optional
130
- > `wizard.tsx` shim), the `.tsx` / `.json` schema variants, the centralized-vs-co-located
131
- > choice, and the full reuse map live in the **form-directory-layout** guide (`@reformer/mcp`) —
132
- > `find_recipe directory-layout`.
269
+ | **Minimalist (flat)** | **Default.** One file per concern at the module root (`types` / `model` / `form.schema` / `form.behavior` / `form.validation` / `data-sources` / `api`) + `index.tsx` with all steps inline |
270
+ | Folders (`model/` + `schema/` + `validation/` + `behavior/` + `flow/` + `application/`) | Large forms: one folder per layer, a step declared once in the flow, reusable sections and rules |
271
+
272
+ > The leading layout of the MCP generators is configurable: set `REFORMER_FORM_LAYOUT`
273
+ > (`minimalist` | `folders`) when registering the MCP server. Default is `minimalist`.
274
+
275
+ > The MCP layout check (`validate_form` with `kind: "layout"`) verifies the flat layout file names
276
+ > (and the optional `steps/<slug>/` folders); the folders layout is recognized by its top-level
277
+ > folders only. Cross-target variants (renderer-react: the same files; renderer-json: plus
278
+ > `registry.ts`, and `form.schema.ts` holds the JSON-DSL document) are described in the
279
+ > **form-directory-layout** guide (`find_recipe directory-layout`).
@@ -18,44 +18,48 @@
18
18
  ### Default — FormField из ui-kit (canonical)
19
19
 
20
20
  ```tsx
21
- import { useMemo } from 'react';
22
- import { createModel, createForm } from '@reformer/core';
21
+ import { createForm, type FormModel, type FormSchemaNode } from '@reformer/core';
22
+ import { useFormBundle } from '@reformer/core/react';
23
23
  import { FormField, Input, SelectAsync, CheckboxWithLabel, Button } from '@reformer/ui-kit';
24
24
 
25
- type RegistrationForm = {
25
+ interface RegistrationForm {
26
26
  email: string;
27
27
  country: string;
28
28
  agree: boolean;
29
- };
29
+ }
30
30
 
31
31
  function RegistrationPage() {
32
- const form = useMemo(() => {
33
- const model = createModel<RegistrationForm>({ email: '', country: 'ru', agree: false });
34
- const schema = {
35
- email: {
36
- value: model.$.email,
37
- component: Input,
38
- componentProps: { label: 'Email', type: 'email', placeholder: 'you@example.com' },
39
- },
40
- country: {
41
- value: model.$.country,
42
- component: SelectAsync,
43
- componentProps: {
44
- label: 'Country',
45
- options: [
46
- { value: 'ru', label: 'Россия' },
47
- { value: 'by', label: 'Беларусь' },
48
- ],
49
- },
50
- },
51
- agree: {
52
- value: model.$.agree,
53
- component: CheckboxWithLabel,
54
- componentProps: { label: 'I agree to terms' },
55
- },
56
- };
57
- return createForm<RegistrationForm>({ model, schema });
58
- }, []);
32
+ // useFormBundle вызывает фабрику ровно один раз и держит сборку стабильной между рендерами
33
+ const { form } = useFormBundle(() =>
34
+ createForm<RegistrationForm>({
35
+ initial: { email: '', country: 'ru', agree: false },
36
+ schema: (model: FormModel<RegistrationForm>): FormSchemaNode => ({
37
+ children: [
38
+ {
39
+ model: model.$.email,
40
+ component: Input,
41
+ componentProps: { label: 'Email', type: 'email', placeholder: 'you@example.com' },
42
+ },
43
+ {
44
+ model: model.$.country,
45
+ component: SelectAsync,
46
+ componentProps: {
47
+ label: 'Country',
48
+ options: [
49
+ { value: 'ru', label: 'Россия' },
50
+ { value: 'by', label: 'Беларусь' },
51
+ ],
52
+ },
53
+ },
54
+ {
55
+ model: model.$.agree,
56
+ component: CheckboxWithLabel,
57
+ componentProps: { label: 'I agree to terms' },
58
+ },
59
+ ],
60
+ }),
61
+ })
62
+ );
59
63
 
60
64
  return (
61
65
  <form>
@@ -70,7 +74,8 @@ function RegistrationPage() {
70
74
 
71
75
  `FormField` сам читает `componentProps.label`, `componentProps.placeholder`,
72
76
  `componentProps.options` через `useFormControl(...).componentProps` и применяет
73
- их к нужному `<input>`/`<select>`/etc. Error rendering, `pending` для async-валидаций,
77
+ их к нужному `<input>`/`<select>`/etc. Текст замечания (по коду — словарь формы из
78
+ `ValidationMessagesProvider messages`, затем локаль), `pending` для async-валидаций,
74
79
  `data-testid` для e2e — всё из коробки.
75
80
 
76
81
  ### Anti-patterns (не делай так)
@@ -93,7 +98,7 @@ function RegistrationPage() {
93
98
  ✅ Всё это в схеме:
94
99
 
95
100
  ```ts
96
- { email: { component: Input, componentProps: { label: 'Email' } } }
101
+ { model: model.$.email, component: Input, componentProps: { label: 'Email' } }
97
102
  ```
98
103
 
99
104
  ```tsx
@@ -124,13 +129,15 @@ props (`value`, `onChange`, `onBlur`, `aria-invalid`) — в диалекте р
124
129
  из `componentProps`, не из JSX-props.
125
130
 
126
131
  ```tsx
127
- import type { FieldNode } from '@reformer/core';
128
- import { useFormControl } from '@reformer/core';
132
+ import type { FormControl } from '@reformer/core';
133
+ import { useFormControl, useIssueMessage } from '@reformer/core/react';
134
+ import { formMessages } from './form.validation'; // defineIssueMessages — константа модуля
129
135
 
130
- type MyFormFieldProps<T> = { control: FieldNode<T> }; // ← ОДИН prop
136
+ type MyFormFieldProps<T> = { control: FormControl<T> }; // ← ОДИН prop
131
137
 
132
138
  function MyFormField<T>({ control }: MyFormFieldProps<T>) {
133
- const { value, errors, disabled, shouldShowError, componentProps } = useFormControl(control);
139
+ const { value, issues, disabled, shouldShowIssues, componentProps } = useFormControl(control);
140
+ const message = useIssueMessage(formMessages); // текст замечания по коду
134
141
  // componentProps = { label, placeholder, type, options, ... } — из СХЕМЫ
135
142
  const cp = (componentProps ?? {}) as Record<string, unknown>;
136
143
 
@@ -145,19 +152,24 @@ function MyFormField<T>({ control }: MyFormFieldProps<T>) {
145
152
  onChange={(e) => (control.setValue as (v: unknown) => void)(e.target.value)}
146
153
  onBlur={() => control.markAsTouched()}
147
154
  />
148
- {shouldShowError && errors[0] && <span>{errors[0].message}</span>}
155
+ {/* shouldShowIssues — ошибки и предупреждения; shouldShowError — для aria-invalid */}
156
+ {shouldShowIssues && issues[0] && <span>{message(issues[0])}</span>}
149
157
  </label>
150
158
  );
151
159
  }
152
160
  ```
153
161
 
162
+ Внутри дерева с `ValidationMessagesProvider` (cdk) вместо `useIssueMessage(formMessages)` берут
163
+ `useIssueMessageResolver()` из `@reformer/cdk` — он учитывает словари всех провайдеров выше. См.
164
+ `36-issue-messages.md`.
165
+
154
166
  Использование — как у `FormField`:
155
167
 
156
168
  ```tsx
157
169
  <MyFormField control={form.email} /> // ← без label-prop
158
170
  ```
159
171
 
160
- ### Связывание поля с контролом — `FieldAdapter` (`@reformer/core`)
172
+ ### Связывание поля с контролом — `FieldAdapter` (`@reformer/core/react`)
161
173
 
162
174
  Контролы говорят на разных диалектах (`checked` + `onCheckedChange`, `onValueChange`, DOM-событие
163
175
  в `onChange`), форма — на value-based seam (`value` + `onChange(value)` + `onBlur`). Перевод
@@ -197,8 +209,9 @@ function MyFormField<T>({ control }: MyFormFieldProps<T>) {
197
209
  import { Input } from '@/components/ui/input';
198
210
  import { Label } from '@/components/ui/label';
199
211
 
200
- function ShadcnFormField({ control }: { control: FieldNode<string> }) {
201
- const { value, errors, disabled, componentProps } = useFormControl(control);
212
+ function ShadcnFormField({ control }: { control: FormControl<string> }) {
213
+ const { value, issues, disabled, shouldShowIssues, componentProps } = useFormControl(control);
214
+ const message = useIssueMessage(formMessages);
202
215
  const cp = (componentProps ?? {}) as Record<string, unknown>;
203
216
 
204
217
  return (
@@ -209,7 +222,7 @@ function ShadcnFormField({ control }: { control: FieldNode<string> }) {
209
222
  onChange={(e) => control.setValue(e.target.value)}
210
223
  disabled={disabled}
211
224
  />
212
- {errors[0] && <p className="text-red-500">{errors[0].message}</p>}
225
+ {shouldShowIssues && issues[0] && <p className="text-red-500">{message(issues[0])}</p>}
213
226
  </div>
214
227
  );
215
228
  }