mobx-formkit 1.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.
Files changed (256) hide show
  1. package/AGENTS.md +761 -0
  2. package/LICENSE +21 -0
  3. package/README.md +214 -0
  4. package/lib/ArrayMap.d.ts +50 -0
  5. package/lib/ArrayMap.d.ts.map +1 -0
  6. package/lib/ArrayMap.js +151 -0
  7. package/lib/ArrayMap.js.map +1 -0
  8. package/lib/Base.d.ts +237 -0
  9. package/lib/Base.d.ts.map +1 -0
  10. package/lib/Base.js +872 -0
  11. package/lib/Base.js.map +1 -0
  12. package/lib/Bindings.d.ts +28 -0
  13. package/lib/Bindings.d.ts.map +1 -0
  14. package/lib/Bindings.js +73 -0
  15. package/lib/Bindings.js.map +1 -0
  16. package/lib/Field.d.ts +195 -0
  17. package/lib/Field.d.ts.map +1 -0
  18. package/lib/Field.js +734 -0
  19. package/lib/Field.js.map +1 -0
  20. package/lib/Form.d.ts +75 -0
  21. package/lib/Form.d.ts.map +1 -0
  22. package/lib/Form.js +199 -0
  23. package/lib/Form.js.map +1 -0
  24. package/lib/Options.d.ts +9 -0
  25. package/lib/Options.d.ts.map +1 -0
  26. package/lib/Options.js +85 -0
  27. package/lib/Options.js.map +1 -0
  28. package/lib/State.d.ts +43 -0
  29. package/lib/State.d.ts.map +1 -0
  30. package/lib/State.js +147 -0
  31. package/lib/State.js.map +1 -0
  32. package/lib/Validator.d.ts +25 -0
  33. package/lib/Validator.d.ts.map +1 -0
  34. package/lib/Validator.js +143 -0
  35. package/lib/Validator.js.map +1 -0
  36. package/lib/compat.d.ts +29 -0
  37. package/lib/compat.d.ts.map +1 -0
  38. package/lib/compat.js +117 -0
  39. package/lib/compat.js.map +1 -0
  40. package/lib/composer.d.ts +26 -0
  41. package/lib/composer.d.ts.map +1 -0
  42. package/lib/composer.js +65 -0
  43. package/lib/composer.js.map +1 -0
  44. package/lib/esm/ArrayMap.js +146 -0
  45. package/lib/esm/ArrayMap.js.map +1 -0
  46. package/lib/esm/Base.js +868 -0
  47. package/lib/esm/Base.js.map +1 -0
  48. package/lib/esm/Bindings.js +69 -0
  49. package/lib/esm/Bindings.js.map +1 -0
  50. package/lib/esm/Field.js +730 -0
  51. package/lib/esm/Field.js.map +1 -0
  52. package/lib/esm/Form.js +195 -0
  53. package/lib/esm/Form.js.map +1 -0
  54. package/lib/esm/Options.js +81 -0
  55. package/lib/esm/Options.js.map +1 -0
  56. package/lib/esm/State.js +143 -0
  57. package/lib/esm/State.js.map +1 -0
  58. package/lib/esm/Validator.js +139 -0
  59. package/lib/esm/Validator.js.map +1 -0
  60. package/lib/esm/compat.js +96 -0
  61. package/lib/esm/compat.js.map +1 -0
  62. package/lib/esm/composer.js +63 -0
  63. package/lib/esm/composer.js.map +1 -0
  64. package/lib/esm/index.js +8 -0
  65. package/lib/esm/index.js.map +1 -0
  66. package/lib/esm/models/FieldProps.js +116 -0
  67. package/lib/esm/models/FieldProps.js.map +1 -0
  68. package/lib/esm/models/OptionsModel.js +51 -0
  69. package/lib/esm/models/OptionsModel.js.map +1 -0
  70. package/lib/esm/models/StateInterface.js +9 -0
  71. package/lib/esm/models/StateInterface.js.map +1 -0
  72. package/lib/esm/models/ValidatorInterface.js +8 -0
  73. package/lib/esm/models/ValidatorInterface.js.map +1 -0
  74. package/lib/esm/parser.js +235 -0
  75. package/lib/esm/parser.js.map +1 -0
  76. package/lib/esm/props.js +118 -0
  77. package/lib/esm/props.js.map +1 -0
  78. package/lib/esm/utils.js +156 -0
  79. package/lib/esm/utils.js.map +1 -0
  80. package/lib/esm/validators/AJV.js +105 -0
  81. package/lib/esm/validators/AJV.js.map +1 -0
  82. package/lib/esm/validators/DVR.js +104 -0
  83. package/lib/esm/validators/DVR.js.map +1 -0
  84. package/lib/esm/validators/JOI.js +54 -0
  85. package/lib/esm/validators/JOI.js.map +1 -0
  86. package/lib/esm/validators/VALIBOT.js +50 -0
  87. package/lib/esm/validators/VALIBOT.js.map +1 -0
  88. package/lib/esm/validators/VINEJS.js +60 -0
  89. package/lib/esm/validators/VINEJS.js.map +1 -0
  90. package/lib/esm/validators/VJF.js +88 -0
  91. package/lib/esm/validators/VJF.js.map +1 -0
  92. package/lib/esm/validators/YUP.js +69 -0
  93. package/lib/esm/validators/YUP.js.map +1 -0
  94. package/lib/esm/validators/ZOD.js +43 -0
  95. package/lib/esm/validators/ZOD.js.map +1 -0
  96. package/lib/index.d.ts +7 -0
  97. package/lib/index.d.ts.map +1 -0
  98. package/lib/index.js +15 -0
  99. package/lib/index.js.map +1 -0
  100. package/lib/models/BaseInterface.d.ts +40 -0
  101. package/lib/models/BaseInterface.d.ts.map +1 -0
  102. package/lib/models/BindingsInterface.d.ts +18 -0
  103. package/lib/models/BindingsInterface.d.ts.map +1 -0
  104. package/lib/models/FieldInterface.d.ts +88 -0
  105. package/lib/models/FieldInterface.d.ts.map +1 -0
  106. package/lib/models/FieldProps.d.ts +111 -0
  107. package/lib/models/FieldProps.d.ts.map +1 -0
  108. package/lib/models/FieldProps.js +116 -0
  109. package/lib/models/FieldProps.js.map +1 -0
  110. package/lib/models/FormInterface.d.ts +184 -0
  111. package/lib/models/FormInterface.d.ts.map +1 -0
  112. package/lib/models/OptionsInterface.d.ts +8 -0
  113. package/lib/models/OptionsInterface.d.ts.map +1 -0
  114. package/lib/models/OptionsModel.d.ts +99 -0
  115. package/lib/models/OptionsModel.d.ts.map +1 -0
  116. package/lib/models/OptionsModel.js +51 -0
  117. package/lib/models/OptionsModel.js.map +1 -0
  118. package/lib/models/SharedActionsInterface.d.ts +27 -0
  119. package/lib/models/SharedActionsInterface.d.ts.map +1 -0
  120. package/lib/models/SharedEventsInterface.d.ts +8 -0
  121. package/lib/models/SharedEventsInterface.d.ts.map +1 -0
  122. package/lib/models/SharedHelpersInterface.d.ts +26 -0
  123. package/lib/models/SharedHelpersInterface.d.ts.map +1 -0
  124. package/lib/models/SharedInitializerInterface.d.ts +6 -0
  125. package/lib/models/SharedInitializerInterface.d.ts.map +1 -0
  126. package/lib/models/SharedUtilsInterface.d.ts +10 -0
  127. package/lib/models/SharedUtilsInterface.d.ts.map +1 -0
  128. package/lib/models/StateInterface.d.ts +37 -0
  129. package/lib/models/StateInterface.d.ts.map +1 -0
  130. package/lib/models/StateInterface.js +9 -0
  131. package/lib/models/StateInterface.js.map +1 -0
  132. package/lib/models/ValidatorInterface.d.ts +74 -0
  133. package/lib/models/ValidatorInterface.d.ts.map +1 -0
  134. package/lib/models/ValidatorInterface.js +8 -0
  135. package/lib/models/ValidatorInterface.js.map +1 -0
  136. package/lib/parser.d.ts +13 -0
  137. package/lib/parser.d.ts.map +1 -0
  138. package/lib/parser.js +247 -0
  139. package/lib/parser.js.map +1 -0
  140. package/lib/props.d.ts +14 -0
  141. package/lib/props.d.ts.map +1 -0
  142. package/lib/props.js +120 -0
  143. package/lib/props.js.map +1 -0
  144. package/lib/utils.d.ts +34 -0
  145. package/lib/utils.d.ts.map +1 -0
  146. package/lib/utils.js +182 -0
  147. package/lib/utils.js.map +1 -0
  148. package/lib/validators/AJV.d.ts +4 -0
  149. package/lib/validators/AJV.d.ts.map +1 -0
  150. package/lib/validators/AJV.js +109 -0
  151. package/lib/validators/AJV.js.map +1 -0
  152. package/lib/validators/DVR.d.ts +4 -0
  153. package/lib/validators/DVR.d.ts.map +1 -0
  154. package/lib/validators/DVR.js +108 -0
  155. package/lib/validators/DVR.js.map +1 -0
  156. package/lib/validators/JOI.d.ts +4 -0
  157. package/lib/validators/JOI.d.ts.map +1 -0
  158. package/lib/validators/JOI.js +58 -0
  159. package/lib/validators/JOI.js.map +1 -0
  160. package/lib/validators/VALIBOT.d.ts +4 -0
  161. package/lib/validators/VALIBOT.d.ts.map +1 -0
  162. package/lib/validators/VALIBOT.js +73 -0
  163. package/lib/validators/VALIBOT.js.map +1 -0
  164. package/lib/validators/VINEJS.d.ts +4 -0
  165. package/lib/validators/VINEJS.d.ts.map +1 -0
  166. package/lib/validators/VINEJS.js +64 -0
  167. package/lib/validators/VINEJS.js.map +1 -0
  168. package/lib/validators/VJF.d.ts +4 -0
  169. package/lib/validators/VJF.d.ts.map +1 -0
  170. package/lib/validators/VJF.js +92 -0
  171. package/lib/validators/VJF.js.map +1 -0
  172. package/lib/validators/YUP.d.ts +4 -0
  173. package/lib/validators/YUP.d.ts.map +1 -0
  174. package/lib/validators/YUP.js +73 -0
  175. package/lib/validators/YUP.js.map +1 -0
  176. package/lib/validators/ZOD.d.ts +4 -0
  177. package/lib/validators/ZOD.d.ts.map +1 -0
  178. package/lib/validators/ZOD.js +47 -0
  179. package/lib/validators/ZOD.js.map +1 -0
  180. package/package.json +183 -0
  181. package/src/ArrayMap.ts +165 -0
  182. package/src/Base.ts +1229 -0
  183. package/src/Bindings.ts +85 -0
  184. package/src/Field.ts +1034 -0
  185. package/src/Form.ts +264 -0
  186. package/src/Options.ts +91 -0
  187. package/src/State.ts +183 -0
  188. package/src/Validator.ts +177 -0
  189. package/src/compat.ts +104 -0
  190. package/src/composer.ts +82 -0
  191. package/src/index.ts +7 -0
  192. package/src/models/BaseInterface.ts +45 -0
  193. package/src/models/BindingsInterface.ts +25 -0
  194. package/src/models/FieldInterface.ts +97 -0
  195. package/src/models/FieldProps.ts +116 -0
  196. package/src/models/FormInterface.ts +203 -0
  197. package/src/models/OptionsInterface.ts +9 -0
  198. package/src/models/OptionsModel.ts +100 -0
  199. package/src/models/SharedActionsInterface.ts +30 -0
  200. package/src/models/SharedEventsInterface.ts +8 -0
  201. package/src/models/SharedHelpersInterface.ts +12 -0
  202. package/src/models/SharedInitializerInterface.ts +6 -0
  203. package/src/models/SharedUtilsInterface.ts +10 -0
  204. package/src/models/StateInterface.ts +44 -0
  205. package/src/models/ValidatorInterface.ts +88 -0
  206. package/src/parser.ts +327 -0
  207. package/src/props.ts +127 -0
  208. package/src/utils.ts +218 -0
  209. package/src/validators/AJV.ts +140 -0
  210. package/src/validators/DVR.ts +145 -0
  211. package/src/validators/JOI.ts +79 -0
  212. package/src/validators/VALIBOT.ts +70 -0
  213. package/src/validators/VINEJS.ts +83 -0
  214. package/src/validators/VJF.ts +123 -0
  215. package/src/validators/YUP.ts +90 -0
  216. package/src/validators/ZOD.ts +66 -0
  217. package/umd/MobxFormkit.umd.js +3093 -0
  218. package/umd/MobxFormkit.umd.js.map +1 -0
  219. package/umd/MobxFormkit.umd.min.js +2 -0
  220. package/umd/MobxFormkit.umd.min.js.map +1 -0
  221. package/umd/MobxFormkitComposer.umd.js +183 -0
  222. package/umd/MobxFormkitComposer.umd.js.map +1 -0
  223. package/umd/MobxFormkitComposer.umd.min.js +2 -0
  224. package/umd/MobxFormkitComposer.umd.min.js.map +1 -0
  225. package/umd/MobxFormkitValidatorAJV.umd.js +113 -0
  226. package/umd/MobxFormkitValidatorAJV.umd.js.map +1 -0
  227. package/umd/MobxFormkitValidatorAJV.umd.min.js +2 -0
  228. package/umd/MobxFormkitValidatorAJV.umd.min.js.map +1 -0
  229. package/umd/MobxFormkitValidatorDVR.umd.js +110 -0
  230. package/umd/MobxFormkitValidatorDVR.umd.js.map +1 -0
  231. package/umd/MobxFormkitValidatorDVR.umd.min.js +2 -0
  232. package/umd/MobxFormkitValidatorDVR.umd.min.js.map +1 -0
  233. package/umd/MobxFormkitValidatorJOI.umd.js +62 -0
  234. package/umd/MobxFormkitValidatorJOI.umd.js.map +1 -0
  235. package/umd/MobxFormkitValidatorJOI.umd.min.js +2 -0
  236. package/umd/MobxFormkitValidatorJOI.umd.min.js.map +1 -0
  237. package/umd/MobxFormkitValidatorVALIBOT.umd.js +8032 -0
  238. package/umd/MobxFormkitValidatorVALIBOT.umd.js.map +1 -0
  239. package/umd/MobxFormkitValidatorVALIBOT.umd.min.js +2 -0
  240. package/umd/MobxFormkitValidatorVALIBOT.umd.min.js.map +1 -0
  241. package/umd/MobxFormkitValidatorVINEJS.umd.js +11737 -0
  242. package/umd/MobxFormkitValidatorVINEJS.umd.js.map +1 -0
  243. package/umd/MobxFormkitValidatorVINEJS.umd.min.js +2 -0
  244. package/umd/MobxFormkitValidatorVINEJS.umd.min.js.map +1 -0
  245. package/umd/MobxFormkitValidatorVJF.umd.js +96 -0
  246. package/umd/MobxFormkitValidatorVJF.umd.js.map +1 -0
  247. package/umd/MobxFormkitValidatorVJF.umd.min.js +2 -0
  248. package/umd/MobxFormkitValidatorVJF.umd.min.js.map +1 -0
  249. package/umd/MobxFormkitValidatorYUP.umd.js +77 -0
  250. package/umd/MobxFormkitValidatorYUP.umd.js.map +1 -0
  251. package/umd/MobxFormkitValidatorYUP.umd.min.js +2 -0
  252. package/umd/MobxFormkitValidatorYUP.umd.min.js.map +1 -0
  253. package/umd/MobxFormkitValidatorZOD.umd.js +49 -0
  254. package/umd/MobxFormkitValidatorZOD.umd.js.map +1 -0
  255. package/umd/MobxFormkitValidatorZOD.umd.min.js +2 -0
  256. package/umd/MobxFormkitValidatorZOD.umd.min.js.map +1 -0
package/src/compat.ts ADDED
@@ -0,0 +1,104 @@
1
+ import * as mobx from "mobx";
2
+
3
+ // `decorate` was removed in MobX 7 and `makeObservable` does not exist in
4
+ // MobX 5. Resolve both lazily through the module namespace so a static
5
+ // named import never fails at link time (MISSING_EXPORT) with MobX 7.
6
+ const M = mobx as any;
7
+
8
+ type Annotations = Record<string, any>;
9
+
10
+ /**
11
+ * `makeObservable` with MobX 5 / 6 / 7 compatibility.
12
+ *
13
+ * MobX 6/7: delegates to the native `makeObservable`.
14
+ * MobX 5: `makeObservable` does not exist (introduced in 6.0). The fallback
15
+ * below re-implements the same semantics with the MobX 5 primitives:
16
+ *
17
+ * 1. every annotated member is materialized as an OWN property of the
18
+ * instance first (getters/setters are copied down from the prototype
19
+ * chain — e.g. `changed`/`submitted` live on `Base`, not on `Form`),
20
+ * 2. a single `decorate(instance, ...)` pass applies the corresponding
21
+ * `observable` / `computed` / `action` decorators.
22
+ *
23
+ * Decorating the instance (instead of the prototype) is required: MobX 5's
24
+ * `decorate` is lazy (`mobxPendingDecorators`) and its initializer accessors
25
+ * recurse infinitely when decorated members live on the prototype, while a
26
+ * computed needs the getter to be an OWN property of the decorated target.
27
+ * `extendObservable` is avoided too — passing `ComputedValue` instances as
28
+ * initial values is no longer supported in 5.15+.
29
+ *
30
+ * All other APIs used across the source (`action`, `set`, `toJS`, `observe`,
31
+ * `intercept`, `reaction`, `autorun`, `runInAction`, `untracked`,
32
+ * `configure`/`enforceActions`, `extendObservable`) exist unchanged in
33
+ * MobX 5.x, 6.x and 7.x, so no other shims are required.
34
+ */
35
+ export const makeObservable = (target: any, annotations: Annotations): any => {
36
+ if (typeof M.makeObservable === "function") {
37
+ return M.makeObservable(target, annotations);
38
+ }
39
+
40
+ return fallbackMakeObservable(target, annotations);
41
+ };
42
+
43
+ /* istanbul ignore next -- MobX 5 only: no makeObservable in 5.x and no decorate in 6/7, not runnable on the MobX 6/7 test matrix */
44
+ function fallbackMakeObservable(target: any, annotations: Annotations): any {
45
+ const members = Object.entries(annotations).filter(([key]) =>
46
+ key in target
47
+ );
48
+ // call sites pass the mobx exports themselves (e.g. `computed`, `action`,
49
+ // `observable`) — compare by value, not by string
50
+ const isComputed = (annotation: any) =>
51
+ annotation === M.computed || annotation === "computed";
52
+ const isAction = (annotation: any) =>
53
+ annotation === M.action || annotation === "action";
54
+
55
+ const descriptorFromChain = (key: string) => {
56
+ let currentProto = Object.getPrototypeOf(target);
57
+ let descriptor: PropertyDescriptor | undefined;
58
+ while (currentProto && descriptor === undefined) {
59
+ descriptor = Object.getOwnPropertyDescriptor(currentProto, key);
60
+ currentProto = Object.getPrototypeOf(currentProto);
61
+ }
62
+ return descriptor;
63
+ };
64
+
65
+ members.forEach(([key, annotation]) => {
66
+ if (isComputed(annotation)) {
67
+ const own = Object.getOwnPropertyDescriptor(target, key);
68
+ if (!own || typeof own.get !== "function") {
69
+ const chain = descriptorFromChain(key);
70
+ const chainGet =
71
+ chain && typeof chain.get === "function" ? chain.get : null;
72
+ const chainSet =
73
+ chain && typeof chain.set === "function" ? chain.set : null;
74
+ Object.defineProperty(target, key, {
75
+ configurable: true,
76
+ enumerable: chain ? chain.enumerable : false,
77
+ get: chainGet ? () => chainGet.call(target) : () => undefined,
78
+ set: chainSet ? (value: any) => chainSet.call(target, value) : undefined,
79
+ });
80
+ }
81
+ } else if (isAction(annotation)) {
82
+ const value = target[key];
83
+ if (typeof value === "function" &&
84
+ !Object.prototype.hasOwnProperty.call(target, key)) {
85
+ Object.defineProperty(target, key, {
86
+ configurable: true,
87
+ writable: true,
88
+ enumerable: false,
89
+ value,
90
+ });
91
+ }
92
+ }
93
+ });
94
+
95
+ const decorators: Record<string, any> = {};
96
+ members.forEach(([key, annotation]) => {
97
+ if (isComputed(annotation)) decorators[key] = M.computed;
98
+ else if (isAction(annotation)) decorators[key] = M.action;
99
+ else decorators[key] = M.observable;
100
+ });
101
+
102
+ M.decorate(target, decorators);
103
+ return target;
104
+ };
@@ -0,0 +1,82 @@
1
+ import { FieldPropsEnum } from "./models/FieldProps";
2
+ import { FormInterface } from "./models/FormInterface";
3
+
4
+ export const composer = (forms: { [key in string]: FormInterface }) => {
5
+
6
+ const instances = (): { [key in string]: FormInterface } => forms;
7
+
8
+ const select = (key: string): FormInterface => forms[key];
9
+
10
+ const check = (prop: string): any => Object
11
+ .entries(forms)
12
+ .reduce((acc: Record<string, any>, entry: any) =>
13
+ Object.assign(acc, {
14
+ [entry[0]]: (entry[1] as FormInterface).check(prop)
15
+ }), {} as Record<string, any>);
16
+
17
+ const get = (prop: string): any => Object
18
+ .entries(forms)
19
+ .reduce((acc: Record<string, any>, entry: any) =>
20
+ Object.assign(acc, {
21
+ [entry[0]]: (entry[1] as FormInterface).get(prop)
22
+ }), {} as Record<string, any>);
23
+
24
+ const valid = () => (Object.values(check(FieldPropsEnum.isValid)) as boolean[])
25
+ .every((val: boolean) => val === true);
26
+
27
+ const error = () => (Object.values(check(FieldPropsEnum.hasError)) as boolean[])
28
+ .some((val: boolean) => val === true);
29
+
30
+ const clear = ({ deep = true, execHook = false }
31
+ : { deep?: boolean, execHook?: boolean } = {
32
+ deep: true, execHook: false,
33
+ }): void[] => Object.values(forms).map((form: FormInterface) => form.clear(deep, execHook));
34
+
35
+ const reset = ({ deep = true, execHook = false }
36
+ : { deep?: boolean, execHook?: boolean } = {
37
+ deep: true, execHook: false,
38
+ }): void[] => Object.values(forms).map((form: FormInterface) => form.reset(deep, execHook));
39
+
40
+ const validate = ({ showErrors = true }
41
+ : { showErrors?: boolean } = {
42
+ showErrors: true,
43
+ }): Promise<any> =>
44
+ Promise.all(Object.values(forms)
45
+ .map((form: FormInterface) => form.validate({ showErrors })))
46
+ .then(() => ({
47
+ composer: composer(forms),
48
+ valid: valid(),
49
+ error: error(),
50
+ errors: get('error'),
51
+ values: get('value'),
52
+ }));
53
+
54
+ const submit = ({ validate = true, execOnSubmitHook = false, execValidationHooks = false }
55
+ : { validate?: boolean, execOnSubmitHook?: boolean, execValidationHooks?: boolean } = {
56
+ validate: true, execOnSubmitHook: false, execValidationHooks: false,
57
+ }): Promise<any> =>
58
+ Promise.all(Object.values(forms)
59
+ .map((form: FormInterface) => form.submit({},
60
+ { execOnSubmitHook, execValidationHooks , validate }
61
+ )))
62
+ .then(() => ({
63
+ composer: composer(forms),
64
+ valid: valid(),
65
+ error: error(),
66
+ errors: get('error'),
67
+ values: get('value'),
68
+ }));
69
+
70
+ return {
71
+ instances,
72
+ select,
73
+ check,
74
+ get,
75
+ valid,
76
+ error,
77
+ validate,
78
+ submit,
79
+ clear,
80
+ reset,
81
+ }
82
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ import Form from "./Form";
2
+ import Field from "./Field";
3
+ import ArrayMap from "./ArrayMap";
4
+
5
+ export default Form;
6
+ export { Form, Field, ArrayMap };
7
+ export type { PathsOf, FieldDefinition } from "./models/FormInterface";
@@ -0,0 +1,45 @@
1
+ import { SharedActionsInterface } from "./SharedActionsInterface";
2
+ import { SharedEventsInterface } from "./SharedEventsInterface";
3
+ import { SharedHelpersInterface } from "./SharedHelpersInterface";
4
+ import { SharedInitializerInterface } from "./SharedInitializerInterface";
5
+ import { SharedUtilsInferface } from "./SharedUtilsInterface";
6
+ import { StateInterface } from "./StateInterface";
7
+ import ArrayMap from "../ArrayMap";
8
+ export interface BaseInterface<F extends Record<string, any> = Record<string, any>>
9
+ extends SharedInitializerInterface,
10
+ SharedActionsInterface,
11
+ SharedEventsInterface,
12
+ SharedUtilsInferface,
13
+ SharedHelpersInterface<F> {
14
+ state: StateInterface;
15
+ fields: ArrayMap;
16
+ path: string | undefined | null;
17
+ $hooks: any;
18
+ $handlers: any;
19
+ $submitted: number;
20
+ $submitting: boolean;
21
+ $validated: number;
22
+ $validating: boolean;
23
+ $touched: boolean;
24
+ $changed: number;
25
+ changed: number;
26
+ submitted: number;
27
+ submitting: boolean;
28
+ validated: number;
29
+ validating: boolean;
30
+ hasIncrementalKeys: boolean;
31
+ hasNestedFields: boolean;
32
+ size: number;
33
+ execHook(name: string, fallback?: any, ...args: any[]): any;
34
+ execHandler(name: string, args: any, fallback?: any): any;
35
+ intercept(opt: any): any;
36
+ observe(opt: any): any;
37
+ onClear(args: any): any;
38
+ onReset(args: any): any;
39
+ onSubmit(args: any): any;
40
+ onAdd(args: any): any;
41
+ onDel(args: any): any;
42
+ firstError(): string | null;
43
+ }
44
+
45
+ export default BaseInterface;
@@ -0,0 +1,25 @@
1
+ import Bindings from "../Bindings";
2
+ import { FieldPropsEnum, FieldPropsType } from "./FieldProps";
3
+
4
+ export interface BindingsInterface {
5
+ templates: {
6
+ [index: string]: {
7
+ [key: string]: ({ field, props, keys }: any) => any;
8
+ };
9
+ };
10
+ rewriters: {
11
+ [index: string]: {
12
+ [key: string]: FieldPropsEnum;
13
+ };
14
+ };
15
+
16
+ load: (
17
+ field: any,
18
+ name: string,
19
+ props: FieldPropsType
20
+ ) => FieldPropsType;
21
+
22
+ register: (bindings: FieldPropsType) => Bindings;
23
+ }
24
+
25
+ export default BindingsInterface;
@@ -0,0 +1,97 @@
1
+ import {BaseInterface} from "./BaseInterface";
2
+ import {OptionsModel} from "./OptionsModel";
3
+ import {StateInterface} from "./StateInterface";
4
+ export interface FieldInterface<T = any> extends BaseInterface {
5
+ incremental: boolean;
6
+ hasInitialNestedFields: boolean;
7
+ id: string | undefined;
8
+ key: string | undefined;
9
+ name: string | undefined;
10
+ options: OptionsModel | undefined;
11
+ type: string | undefined;
12
+ label: string | undefined;
13
+ placeholder: string | undefined;
14
+ extra: Record<string, any>;
15
+ errorSync: string | null;
16
+ errorAsync: string | null;
17
+ validationErrorStack: string[];
18
+ validationFunctionsData: any[];
19
+ validationAsyncData: { valid: boolean, message: string | null };
20
+ debouncedValidation: any;
21
+ autoFocus: boolean;
22
+ inputMode: string;
23
+ ref: any;
24
+ showError: boolean;
25
+ checkValidationErrors: boolean;
26
+ checked: T | undefined;
27
+ value: T;
28
+ initial: T;
29
+ default: T;
30
+ actionRunning: boolean;
31
+ bindings: any;
32
+ disabled: boolean;
33
+ related: string[] | undefined;
34
+ rules: string[] | undefined;
35
+ validators: any[] | undefined;
36
+ validatedValue: any;
37
+ error: string | null;
38
+ hasError: boolean;
39
+ isValid: boolean;
40
+ isDefault: boolean;
41
+ isDirty: boolean;
42
+ isPristine: boolean;
43
+ isEmpty: boolean;
44
+ resetting: boolean;
45
+ clearing: boolean;
46
+ focused: boolean;
47
+ blurred: boolean;
48
+ touched: boolean;
49
+ deleted: boolean;
50
+ // handlers
51
+ onSync(args: any): any;
52
+ onChange(args: any): any;
53
+ onToggle(args: any): any;
54
+ onBlur(args: any): any;
55
+ onFocus(args: any): any;
56
+ onDrop(args: any): any;
57
+ onKeyDown(args: any): any;
58
+ onKeyUp(args: any): any;
59
+
60
+ // methods: {
61
+ setupField(
62
+ key: string,
63
+ path: string | undefined | null,
64
+ struct: string | undefined | null,
65
+ data: any,
66
+ props: any,
67
+ update: boolean
68
+ ): void;
69
+ getComputedProp(key: any): any;
70
+ // checkValidationPlugins(): void;
71
+ initNestedFields(field: any, update: boolean): void;
72
+ invalidate(message?: string, deep?: boolean, async?: boolean): void;
73
+ setValidationAsyncData(valid: boolean, message?: string|null): void;
74
+ resetValidation(deep: boolean): void;
75
+ clear(deep?: boolean): void;
76
+ reset(deep?: boolean): void;
77
+ focus(): void;
78
+ showErrors(show?: boolean, deep?: boolean): void;
79
+ observeValidationOnBlur(): void;
80
+ observeValidationOnChange(): void;
81
+ disposeValidationOnBlur(): void;
82
+ disposeValidationOnChange(): void;
83
+ initMOBXEvent(type: string): void;
84
+ bind(props?: any): any;
85
+ }
86
+
87
+ export interface FieldConstructor {
88
+ key: string;
89
+ path?: string;
90
+ struct?: string;
91
+ data?: any;
92
+ props?: any;
93
+ update?: boolean;
94
+ state: StateInterface;
95
+ }
96
+
97
+ export default FieldInterface;
@@ -0,0 +1,116 @@
1
+ export enum FieldPropsEnum {
2
+ key = "key",
3
+ id = "id",
4
+ path = "path",
5
+ name = "name",
6
+ fields = "fields",
7
+ ref= "ref",
8
+ type = "type",
9
+ computed = "computed",
10
+ value = "value",
11
+ initial = "initial",
12
+ default = "default",
13
+ checked = "checked",
14
+ label = "label",
15
+ placeholder = "placeholder",
16
+ error = "error",
17
+ validatedWith = "validatedWith",
18
+ validators = "validators",
19
+ rules = "rules",
20
+ related = "related",
21
+ options = "options",
22
+ extra = "extra",
23
+ bindings = "bindings",
24
+ hooks = "hooks",
25
+ handlers = "handlers",
26
+ converter="converter",
27
+ input="input",
28
+ output="output",
29
+ interceptors = "interceptors",
30
+ observers = "observers",
31
+ // computed
32
+ disabled = "disabled",
33
+ deleted = "deleted",
34
+ blurred = "blurred",
35
+ validating = "validating",
36
+ submitting = "submitting",
37
+ clearing = "clearing",
38
+ resetting = "resetting",
39
+ changed = "changed",
40
+ touched = "touched",
41
+ focused = "focused",
42
+ isEmpty = "isEmpty",
43
+ isDefault = "isDefault",
44
+ isPristine = "isPristine",
45
+ isDirty = "isDirty",
46
+ isValid = "isValid",
47
+ hasError = "hasError",
48
+ // handlers
49
+ onInit = "onInit",
50
+ onSync = "onSync",
51
+ onChange = "onChange",
52
+ onBlur = "onBlur",
53
+ onFocus = "onFocus",
54
+ onToggle = "onToggle",
55
+ onDrop = "onDrop",
56
+ onSubmit = "onSubmit",
57
+ onReset = "onReset",
58
+ onClear = "onClear",
59
+ onAdd = "onAdd",
60
+ onDel = "onDel",
61
+ autoFocus = "autoFocus",
62
+ inputMode = "inputMode",
63
+ onKeyDown = "onKeyDown",
64
+ onKeyUp = 'onKeyUp',
65
+ class = "class",
66
+ nullable = "nullable",
67
+ autoComplete = "autoComplete",
68
+ }
69
+
70
+ export type FieldPropsType = {
71
+ [key in FieldPropsEnum]?: any;
72
+ }
73
+
74
+ export enum AllowedFieldPropsTypes {
75
+ computed = 'computed',
76
+ observable = 'observable',
77
+ editable = 'editable',
78
+ all = 'all',
79
+ }
80
+
81
+ export enum FieldPropsOccurrence {
82
+ some = 'some',
83
+ every = 'every',
84
+ }
85
+
86
+ export enum SeparatedPropsMode {
87
+ computed = 'computed',
88
+ values = 'values',
89
+ labels = 'labels',
90
+ placeholders = 'placeholders',
91
+ defaults = 'defaults',
92
+ initials = 'initials',
93
+ disabled = 'disabled',
94
+ deleted = 'deleted',
95
+ types = 'types',
96
+ related = 'related',
97
+ rules = 'rules',
98
+ options = 'options',
99
+ bindings = 'bindings',
100
+ extra = 'extra',
101
+ hooks = 'hooks',
102
+ handlers = 'handlers',
103
+ validatedWith = 'validatedWith',
104
+ validators = 'validators',
105
+ observers = 'observers',
106
+ interceptors = 'interceptors',
107
+ converters = 'converters',
108
+ input = 'input',
109
+ output = 'output',
110
+ autoFocus = 'autoFocus',
111
+ inputMode = 'inputMode',
112
+ refs = 'refs',
113
+ classes = 'classes',
114
+ nullable = 'nullable',
115
+ autoComplete = 'autoComplete',
116
+ }
@@ -0,0 +1,203 @@
1
+ import Field from "../Field";
2
+ import { BaseInterface } from "./BaseInterface";
3
+ import { FieldInterface, FieldConstructor } from "./FieldInterface";
4
+ import { OptionsModel } from "./OptionsModel";
5
+ import { ValidatorInterface, ValidationPlugins } from "./ValidatorInterface";
6
+ /**
7
+ * Recursively derives all possible field paths from a form values type `T`.
8
+ * Supports nested objects, arrays (with `[]` suffix), and dot-separated paths.
9
+ * Excludes built-in non-plain objects like Date, File, Blob, etc.
10
+ *
11
+ * @example
12
+ * // --- Basic usage ---
13
+ * type Profile = {
14
+ * username: string;
15
+ * email: string;
16
+ * };
17
+ * // PathsOf<Profile> = "username" | "email"
18
+ *
19
+ * @example
20
+ * // --- Nested objects ---
21
+ * type NestedClubFields = {
22
+ * club: { name: string; city: string };
23
+ * members: { firstname: string; lastname: string; hobbies: string[] }[];
24
+ * };
25
+ * // PathsOf<NestedClubFields> = "club" | "members" | "club.name" | "club.city"
26
+ * // | "members[].firstname" | "members[].lastname" | "members[].hobbies"
27
+ *
28
+ * @example
29
+ * // --- Usage with form.$() or form.select() ---
30
+ * const form = new Form<{ profile: { name: string; age: number } }>({ });
31
+ *
32
+ * // Top-level keys get autocomplete directly from keyof F:
33
+ * form.$('profile'); // ✓ autocomplete, returns Field<{ name: string; age: number }>
34
+ *
35
+ * // For nested paths, use PathsOf in a helper function:
36
+ * import { PathsOf } from 'mobx-formkit';
37
+ *
38
+ * function getField(form: Form<{ profile: { name: string; age: number } }>, path: PathsOf<{ profile: { name: string; age: number } }>) {
39
+ * return form.$(path).value;
40
+ * // ^— path autocompletes to: "profile" | "profile.name" | "profile.age"
41
+ * }
42
+ * getField(form, 'profile.name'); // ✓ returns string
43
+ */
44
+ export type PathsOf<T> = T extends (infer U)[]
45
+ ? PathsOf<U>
46
+ : T extends Date | File | Blob | RegExp | Map<any, any> | Set<any> | Promise<any>
47
+ ? never
48
+ : T extends object
49
+ ? { [K in keyof T & string]:
50
+ T[K] extends (infer U)[]
51
+ ? K | `${K}[].${PathsOf<U>}`
52
+ : T[K] extends object
53
+ ? K | `${K}.${PathsOf<T[K]>}`
54
+ : K
55
+ }[keyof T & string]
56
+ : never;
57
+
58
+ export interface FormInterface<F extends Record<string, any> = Record<string, any>> extends BaseInterface<F> {
59
+ name: string;
60
+ extra: Record<string, any>;
61
+ validator: ValidatorInterface;
62
+ debouncedValidation: any;
63
+ // getters
64
+ flatMapValues: Record<string, any>;
65
+ clearing: boolean;
66
+ resetting: boolean;
67
+ error: string | null;
68
+ hasError: boolean;
69
+ isValid: boolean;
70
+ isPristine: boolean;
71
+ isDirty: boolean;
72
+ isDefault: boolean;
73
+ isEmpty: boolean;
74
+ focused: boolean;
75
+ touched: boolean;
76
+ disabled: boolean;
77
+ // methods
78
+ // init($fields: any): void;
79
+ invalidate(message?: string | null, deep?: boolean): void;
80
+ showErrors(show?: boolean): void;
81
+ clear(deep?: boolean, execHook?: boolean): void;
82
+ reset(deep?: boolean, execHook?: boolean): void;
83
+
84
+ makeField(data: FieldConstructor, FieldClass?: typeof Field): FieldInterface;
85
+
86
+ $(key: keyof F | PathsOf<F>): Field<F[keyof F]>;
87
+ }
88
+
89
+ export interface FieldDefinition {
90
+ /** Field value */
91
+ value?: any;
92
+ /** Field label */
93
+ label?: string;
94
+ /** Field placeholder */
95
+ placeholder?: string;
96
+ /** Validation rules string (e.g. "required|string|min:3") */
97
+ rules?: string;
98
+ /** Field type (e.g. "text", "checkbox", "password", "file", etc.) */
99
+ type?: string;
100
+ /** Whether the field is disabled */
101
+ disabled?: boolean;
102
+ /** Related field paths */
103
+ related?: string[];
104
+ /** Default value */
105
+ default?: any;
106
+ /** Initial value */
107
+ initial?: any;
108
+ /** Nested sub-fields definition */
109
+ fields?: any;
110
+ /** Binding name for the UI component */
111
+ bindings?: string;
112
+ /** Extra metadata */
113
+ extra?: Record<string, any>;
114
+ /** Field-level options */
115
+ options?: OptionsModel;
116
+ /** Field hooks */
117
+ hooks?: Record<string, any>;
118
+ /** Field handlers */
119
+ handlers?: Record<string, any>;
120
+ /** Custom validation functions */
121
+ validators?: any[];
122
+ /** Which field prop to use for validation output */
123
+ validatedWith?: string;
124
+ /** MobX observers */
125
+ observers?: any[];
126
+ /** MobX interceptors */
127
+ interceptors?: any[];
128
+ /** Ref callback/object */
129
+ ref?: any;
130
+ /** Whether the field is nullable */
131
+ nullable?: boolean;
132
+ /** Auto-focus on mount */
133
+ autoFocus?: boolean;
134
+ /** Input mode for mobile keyboards */
135
+ inputMode?: string;
136
+ /** Autocomplete attribute */
137
+ autoComplete?: string;
138
+ /** Input converter function */
139
+ input?: Function;
140
+ /** Output converter function */
141
+ output?: Function;
142
+ /** Value converter function */
143
+ converter?: Function;
144
+ /** Multiple converters */
145
+ converters?: Function[];
146
+ /** Computed value */
147
+ computed?: any;
148
+ /** Field name (overrides the key) */
149
+ name?: string;
150
+ /** Custom Field class */
151
+ class?: any;
152
+ }
153
+
154
+ export interface FieldsDefinitions {
155
+ struct?: string[];
156
+ /**
157
+ * Field definitions.
158
+ * - For autocomplete on field props, use `Record<string, FieldDefinition>`
159
+ * (e.g. `const fields: Record<string, FieldDefinition> = { ... }`)
160
+ * - Or pass an array of field path strings for struct/separated mode.
161
+ */
162
+ fields?: any;
163
+ computed?: any;
164
+ values?: any;
165
+ labels?: any;
166
+ placeholders?: any;
167
+ defaults?: any;
168
+ initials?: any;
169
+ disabled?: any;
170
+ deleted?: any;
171
+ types?: any;
172
+ related?: any;
173
+ rules?: any;
174
+ options?: any;
175
+ bindings?: any;
176
+ extra?: any;
177
+ hooks?: any;
178
+ handlers?: any;
179
+ validatedWith?: any;
180
+ validators?: any;
181
+ observers?: any;
182
+ interceptors?: any;
183
+ input?: any;
184
+ output?: any;
185
+ autoFocus?: any;
186
+ inputMode?: any;
187
+ refs?: any;
188
+ classes?: Record<string, any>;
189
+ nullable?: any;
190
+ converters?: any;
191
+ }
192
+
193
+ export interface FormConfig {
194
+ name?: string;
195
+ options?: OptionsModel;
196
+ plugins?: ValidationPlugins;
197
+ bindings?: Record<string, any>;
198
+ hooks?: Record<string, any>;
199
+ handlers?: Record<string, any>;
200
+ extra?: Record<string, any>;
201
+ }
202
+
203
+ export default FormInterface;
@@ -0,0 +1,9 @@
1
+ import {OptionsModel} from "./OptionsModel";
2
+
3
+ export interface OptionsInterface {
4
+ options: OptionsModel;
5
+ get: (key: string, instance?: any) => any;
6
+ set: (options: OptionsModel) => void;
7
+ }
8
+
9
+ export default OptionsInterface;