@becklyn/forms 2.0.1 → 2.0.3

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 (128) hide show
  1. package/README.md +31 -7
  2. package/dist/cjs/components/FormBuilder.d.ts +2 -2
  3. package/dist/cjs/components/FormBuilder.d.ts.map +1 -1
  4. package/dist/cjs/components/FormBuilder.js +9 -2
  5. package/dist/cjs/components/FormCustom.d.ts +3 -3
  6. package/dist/cjs/components/FormCustom.d.ts.map +1 -1
  7. package/dist/cjs/components/FormCustom.js +1 -0
  8. package/dist/cjs/components/FormEntry.d.ts +5 -6
  9. package/dist/cjs/components/FormEntry.d.ts.map +1 -1
  10. package/dist/cjs/components/FormEntry.js +3 -2
  11. package/dist/cjs/components/FormField.d.ts +4 -5
  12. package/dist/cjs/components/FormField.d.ts.map +1 -1
  13. package/dist/cjs/components/FormField.js +2 -1
  14. package/dist/cjs/components/FormRow.d.ts +3 -3
  15. package/dist/cjs/components/FormRow.d.ts.map +1 -1
  16. package/dist/cjs/components/FormRow.js +1 -0
  17. package/dist/cjs/components/FormSection.d.ts +3 -3
  18. package/dist/cjs/components/FormSection.d.ts.map +1 -1
  19. package/dist/cjs/components/FormSection.js +1 -0
  20. package/dist/cjs/condition/index.d.ts +1 -1
  21. package/dist/cjs/condition/index.d.ts.map +1 -1
  22. package/dist/cjs/context/FormProvider.d.ts +2 -1
  23. package/dist/cjs/context/FormProvider.d.ts.map +1 -1
  24. package/dist/cjs/context/FormProvider.js +1 -0
  25. package/dist/cjs/context/context.d.ts +7 -5
  26. package/dist/cjs/context/context.d.ts.map +1 -1
  27. package/dist/cjs/context/context.js +1 -0
  28. package/dist/cjs/context/data/FormDataProvider.d.ts +10 -10
  29. package/dist/cjs/context/data/FormDataProvider.d.ts.map +1 -1
  30. package/dist/cjs/context/data/FormDataProvider.js +1 -0
  31. package/dist/cjs/context/data/context.d.ts +8 -8
  32. package/dist/cjs/context/data/context.d.ts.map +1 -1
  33. package/dist/cjs/context/data/context.js +1 -0
  34. package/dist/cjs/guard/index.d.ts +4 -4
  35. package/dist/cjs/guard/index.d.ts.map +1 -1
  36. package/dist/cjs/hoc/withForm.d.ts +3 -2
  37. package/dist/cjs/hoc/withForm.d.ts.map +1 -1
  38. package/dist/cjs/hoc/withForm.js +4 -1
  39. package/dist/cjs/hoc/withFormData.d.ts +3 -2
  40. package/dist/cjs/hoc/withFormData.d.ts.map +1 -1
  41. package/dist/cjs/hoc/withFormData.js +1 -0
  42. package/dist/cjs/hook/useFormData.d.ts +2 -2
  43. package/dist/cjs/hook/useFormData.d.ts.map +1 -1
  44. package/dist/cjs/hook/useFormData.js +1 -0
  45. package/dist/cjs/hook/useFormValidations.d.ts +3 -3
  46. package/dist/cjs/hook/useFormValidations.d.ts.map +1 -1
  47. package/dist/cjs/hook/useFormValidations.js +1 -0
  48. package/dist/cjs/type/config.d.ts +5 -5
  49. package/dist/cjs/type/config.d.ts.map +1 -1
  50. package/dist/cjs/type/extract.d.ts +5 -8
  51. package/dist/cjs/type/extract.d.ts.map +1 -1
  52. package/dist/cjs/type/field.d.ts +9 -8
  53. package/dist/cjs/type/field.d.ts.map +1 -1
  54. package/dist/cjs/type/form.d.ts +13 -11
  55. package/dist/cjs/type/form.d.ts.map +1 -1
  56. package/dist/cjs/type/form.js +9 -0
  57. package/dist/cjs/type/validation.d.ts +6 -5
  58. package/dist/cjs/type/validation.d.ts.map +1 -1
  59. package/dist/cjs/util/index.d.ts +10 -8
  60. package/dist/cjs/util/index.d.ts.map +1 -1
  61. package/dist/cjs/util/index.js +3 -1
  62. package/dist/cjs/validation/index.d.ts +2 -2
  63. package/dist/cjs/validation/index.d.ts.map +1 -1
  64. package/dist/cjs/validation/index.js +2 -1
  65. package/dist/es/components/FormBuilder.d.ts +2 -2
  66. package/dist/es/components/FormBuilder.d.ts.map +1 -1
  67. package/dist/es/components/FormBuilder.js +9 -2
  68. package/dist/es/components/FormCustom.d.ts +3 -3
  69. package/dist/es/components/FormCustom.d.ts.map +1 -1
  70. package/dist/es/components/FormCustom.js +1 -0
  71. package/dist/es/components/FormEntry.d.ts +5 -6
  72. package/dist/es/components/FormEntry.d.ts.map +1 -1
  73. package/dist/es/components/FormEntry.js +3 -2
  74. package/dist/es/components/FormField.d.ts +4 -5
  75. package/dist/es/components/FormField.d.ts.map +1 -1
  76. package/dist/es/components/FormField.js +2 -1
  77. package/dist/es/components/FormRow.d.ts +3 -3
  78. package/dist/es/components/FormRow.d.ts.map +1 -1
  79. package/dist/es/components/FormRow.js +1 -0
  80. package/dist/es/components/FormSection.d.ts +3 -3
  81. package/dist/es/components/FormSection.d.ts.map +1 -1
  82. package/dist/es/components/FormSection.js +1 -0
  83. package/dist/es/condition/index.d.ts +1 -1
  84. package/dist/es/condition/index.d.ts.map +1 -1
  85. package/dist/es/context/FormProvider.d.ts +2 -1
  86. package/dist/es/context/FormProvider.d.ts.map +1 -1
  87. package/dist/es/context/FormProvider.js +1 -0
  88. package/dist/es/context/context.d.ts +7 -5
  89. package/dist/es/context/context.d.ts.map +1 -1
  90. package/dist/es/context/context.js +1 -0
  91. package/dist/es/context/data/FormDataProvider.d.ts +10 -10
  92. package/dist/es/context/data/FormDataProvider.d.ts.map +1 -1
  93. package/dist/es/context/data/FormDataProvider.js +1 -0
  94. package/dist/es/context/data/context.d.ts +8 -8
  95. package/dist/es/context/data/context.d.ts.map +1 -1
  96. package/dist/es/context/data/context.js +1 -0
  97. package/dist/es/guard/index.d.ts +4 -4
  98. package/dist/es/guard/index.d.ts.map +1 -1
  99. package/dist/es/hoc/withForm.d.ts +3 -2
  100. package/dist/es/hoc/withForm.d.ts.map +1 -1
  101. package/dist/es/hoc/withForm.js +4 -1
  102. package/dist/es/hoc/withFormData.d.ts +3 -2
  103. package/dist/es/hoc/withFormData.d.ts.map +1 -1
  104. package/dist/es/hoc/withFormData.js +1 -0
  105. package/dist/es/hook/useFormData.d.ts +2 -2
  106. package/dist/es/hook/useFormData.d.ts.map +1 -1
  107. package/dist/es/hook/useFormData.js +1 -0
  108. package/dist/es/hook/useFormValidations.d.ts +3 -3
  109. package/dist/es/hook/useFormValidations.d.ts.map +1 -1
  110. package/dist/es/hook/useFormValidations.js +1 -0
  111. package/dist/es/type/config.d.ts +5 -5
  112. package/dist/es/type/config.d.ts.map +1 -1
  113. package/dist/es/type/extract.d.ts +5 -8
  114. package/dist/es/type/extract.d.ts.map +1 -1
  115. package/dist/es/type/field.d.ts +9 -8
  116. package/dist/es/type/field.d.ts.map +1 -1
  117. package/dist/es/type/form.d.ts +13 -11
  118. package/dist/es/type/form.d.ts.map +1 -1
  119. package/dist/es/type/form.js +9 -0
  120. package/dist/es/type/validation.d.ts +6 -5
  121. package/dist/es/type/validation.d.ts.map +1 -1
  122. package/dist/es/util/index.d.ts +10 -8
  123. package/dist/es/util/index.d.ts.map +1 -1
  124. package/dist/es/util/index.js +3 -1
  125. package/dist/es/validation/index.d.ts +2 -2
  126. package/dist/es/validation/index.d.ts.map +1 -1
  127. package/dist/es/validation/index.js +2 -1
  128. package/package.json +1 -1
package/README.md CHANGED
@@ -51,7 +51,7 @@ npm i --save @becklyn/forms
51
51
  Create a single component to handle rendering all of your different input components. It will be called by the `FormBuilder` including the respective field's props.
52
52
 
53
53
  ```tsx
54
- export const FieldComponent: React.FC<FormBuilderChildrenProps> = ({
54
+ export const FieldComponent: React.FC<FormBuilderChildrenProps<FieldTypes>> = ({
55
55
  value,
56
56
  error,
57
57
  field,
@@ -116,8 +116,9 @@ export const forgotPasswordFormConfig = createFormConfig([
116
116
  To render your form config the FormBuilder needs to be a descendant of `FormProvider` (or a component using `withForm`). An implementation could look something like this where the majority can easily be abstracted.
117
117
 
118
118
  ```tsx
119
+ // the form renderer can be reused to render all kinds of forms
119
120
  export const FormRenderer: React.FC = () => {
120
- return <FormBuilder>{props => <WizardField {...props} />}</FormBuilder>;
121
+ return <FormBuilder>{props => <FieldComponent {...props} />}</FormBuilder>;
121
122
  };
122
123
 
123
124
  export const LoginFormHandler = withForm(() => {
@@ -168,11 +169,26 @@ export interface TextFieldConfig {
168
169
  Create an intermediate type that forms can consume:
169
170
 
170
171
  ```typescript
171
- export type FormFieldText = FormFieldBasicConfig<"text", TextFieldConfig>;
172
+ export type FormFieldText = FormFieldConfig<"text", TextFieldConfig, string>;
172
173
  ```
173
174
 
174
175
  The first parameter specifies to which field the fieldConfig will be applied. Here `"text"` means that in your config, if you add `type: "text"`, the `fieldConfig` will expect props specified in `TextFieldConfig`.
175
176
 
177
+ The third generic parameter in `FormFieldConfig` is the type of allowed values this field can handle.
178
+
179
+ Its useful to build a type that unifies all your fields:
180
+
181
+ ```typescript
182
+ export type FormFieldText = FormFieldConfig<"text", TextFieldConfig, string>;
183
+ export type FormFieldNumber = FormFieldConfig<"number", NumberFieldConfig, number>;
184
+ export type FormFieldSelect = FormFieldConfig<
185
+ "select",
186
+ SelectFieldConfig,
187
+ { id: string; value: string }
188
+ >;
189
+ export type FormField = FormFieldText | FormFieldNumber | FormFieldSelect;
190
+ ```
191
+
176
192
  ### Infer form config
177
193
 
178
194
  To be able to infer a form config's type <ins>it must be readonly</ins>. You can use the following helper to infer your config:
@@ -191,7 +207,7 @@ While this is true using `createFormConfig`, parts of your config that are rende
191
207
 
192
208
  ```typescript
193
209
  useMemo(() => {
194
- return createFormConfig([
210
+ return createFormConfig<FormField>([
195
211
  // Render a or b
196
212
  eitherOr(
197
213
  someCondition,
@@ -224,6 +240,14 @@ useMemo(() => {
224
240
  }, [someCondition]);
225
241
  ```
226
242
 
243
+ The `FormBuilder` is generic, too:
244
+
245
+ ```typescript
246
+ export const FormRenderer: React.FC = () => {
247
+ return <FormBuilder<FieldTypes>>{props => <FieldComponent {...props} />}</FormBuilder>;
248
+ };
249
+ ```
250
+
227
251
  ## Guides
228
252
 
229
253
  ### Multistep
@@ -232,8 +256,8 @@ Multistep can be achieved easily and abstracted into a custom component. The con
232
256
  While this lib handles the data, validations etc., you must still handle the multistep logic yourself.
233
257
 
234
258
  ```tsx
235
- const Step = withForm(() => {
236
- const { validateForm } = useForm();
259
+ const Step = withForm<FormField>(() => {
260
+ const { validateForm } = useForm<FormField>();
237
261
 
238
262
  const handleSubmit = (e: React.FormEvent) => {
239
263
  e.preventDefault();
@@ -253,7 +277,7 @@ const Step = withForm(() => {
253
277
  );
254
278
  });
255
279
 
256
- const MultiStep = withForm(() => {
280
+ const MultiStep = withForm<FormField>(() => {
257
281
  // your custom hook
258
282
  const { step } = useMultiStep();
259
283
 
@@ -1,3 +1,3 @@
1
- import { FormBuilderProps } from "../type";
2
- export declare const FormBuilder: import("react").NamedExoticComponent<FormBuilderProps>;
1
+ import { FormBuilderProps, FormFieldConfig } from "../type";
2
+ export declare const FormBuilder: <T extends FormFieldConfig<string, any, any>>({ Components, children, }: FormBuilderProps<T>) => import("react/jsx-runtime").JSX.Element;
3
3
  //# sourceMappingURL=FormBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormBuilder.d.ts","sourceRoot":"","sources":["../../../components/FormBuilder.tsx"],"names":[],"mappings":"AASA,OAAO,EAAyB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAUlE,eAAO,MAAM,WAAW,wDAoBvB,CAAC"}
1
+ {"version":3,"file":"FormBuilder.d.ts","sourceRoot":"","sources":["../../../components/FormBuilder.tsx"],"names":[],"mappings":"AASA,OAAO,EAAyB,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAWnF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,6BAGpE,gBAAgB,CAAC,CAAC,CAAC,4CAErB,CAAC"}
@@ -13,10 +13,17 @@ const DefaultComponents = {
13
13
  RowWrapper: style_1.DefaultRowWrapper,
14
14
  FieldWrapper: style_1.DefaultFieldWrapper,
15
15
  };
16
- exports.FormBuilder = (0, react_1.memo)(({ Components = DefaultComponents, children }) => {
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ const FormBuilder = ({ Components = DefaultComponents, children, }) => {
18
+ return (0, jsx_runtime_1.jsx)(FormBuilderComponent, { Components: Components, children: children });
19
+ };
20
+ exports.FormBuilder = FormBuilder;
21
+ const FormBuilderComponent = (0, react_1.memo)(
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ ({ Components = DefaultComponents, children, }) => {
17
24
  const { BuilderWrapper } = Components;
18
25
  const { config } = (0, react_1.useContext)(context_1.FormConfigContext);
19
26
  const Wrapper = BuilderWrapper !== null && BuilderWrapper !== void 0 ? BuilderWrapper : style_1.DefaultBuilderWrapper;
20
27
  return ((0, jsx_runtime_1.jsx)(Wrapper, { children: config.map((entry, index) => ((0, jsx_runtime_1.jsx)(FormEntry_1.FormEntry, { entry: entry, Components: Object.assign(Object.assign({}, DefaultComponents), Components), children: children }, index + ((0, guard_1.isFormFieldConfig)(entry) ? entry.name : "")))) }));
21
28
  });
22
- exports.FormBuilder.displayName = "FormBuilder";
29
+ FormBuilderComponent.displayName = "FormBuilderComponent";
@@ -1,9 +1,9 @@
1
1
  import { FormBuilderComponents, FormBuilderProps, FormCustomConfig, FormFieldConfig } from "../type";
2
- interface FormCustomProps<T extends FormFieldConfig> {
2
+ interface FormCustomProps<T extends FormFieldConfig<string, any, any>> {
3
3
  Components: FormBuilderComponents;
4
4
  custom: FormCustomConfig<T>;
5
- children: FormBuilderProps["children"];
5
+ children: FormBuilderProps<T>["children"];
6
6
  }
7
- export declare const FormCustom: <T extends FormFieldConfig>({ Components, custom, children, }: FormCustomProps<T>) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const FormCustom: <T extends FormFieldConfig<string, any, any>>({ Components, custom, children, }: FormCustomProps<T>) => import("react/jsx-runtime").JSX.Element;
8
8
  export {};
9
9
  //# sourceMappingURL=FormCustom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormCustom.d.ts","sourceRoot":"","sources":["../../../components/FormCustom.tsx"],"names":[],"mappings":"AACA,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EAClB,MAAM,SAAS,CAAC;AAGjB,UAAU,eAAe,CAAC,CAAC,SAAS,eAAe;IAC/C,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC5B,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,eAAe,qCAIjD,eAAe,CAAC,CAAC,CAAC,4CAYpB,CAAC"}
1
+ {"version":3,"file":"FormCustom.d.ts","sourceRoot":"","sources":["../../../components/FormCustom.tsx"],"names":[],"mappings":"AACA,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EAClB,MAAM,SAAS,CAAC;AAIjB,UAAU,eAAe,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC;IACjE,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC5B,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;CAC7C;AAGD,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,qCAInE,eAAe,CAAC,CAAC,CAAC,4CAYpB,CAAC"}
@@ -7,6 +7,7 @@ exports.FormCustom = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const react_1 = __importDefault(require("react"));
9
9
  const FormEntry_1 = require("./FormEntry");
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
11
  const FormCustom = ({ Components, custom, children, }) => {
11
12
  return ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: custom.wrapper(custom.content.map((entry, index) => ((0, jsx_runtime_1.jsx)(FormEntry_1.FormEntry, { entry: entry, Components: Components, children: children }, index)))) }));
12
13
  };
@@ -1,10 +1,9 @@
1
- import { FC } from "react";
2
- import { FormBuilderComponents, FormBuilderProps, FormEntryConfig } from "../type";
3
- interface FormEntryProps {
1
+ import { FormBuilderComponents, FormBuilderProps, FormEntryConfig, FormFieldConfig } from "../type";
2
+ interface FormEntryProps<T extends FormFieldConfig<string, any, any>> {
4
3
  Components: FormBuilderComponents;
5
- entry: FormEntryConfig;
6
- children: FormBuilderProps["children"];
4
+ entry: FormEntryConfig<T>;
5
+ children: FormBuilderProps<T>["children"];
7
6
  }
8
- export declare const FormEntry: FC<FormEntryProps>;
7
+ export declare const FormEntry: <T extends FormFieldConfig<string, any, any>>({ Components, entry, children, }: FormEntryProps<T>) => import("react/jsx-runtime").JSX.Element | null;
9
8
  export {};
10
9
  //# sourceMappingURL=FormEntry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormEntry.d.ts","sourceRoot":"","sources":["../../../components/FormEntry.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAoC,MAAM,OAAO,CAAC;AAI7D,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAY,eAAe,EAAE,MAAM,SAAS,CAAC;AAO7F,UAAU,cAAc;IACpB,UAAU,EAAE,qBAAqB,CAAC;IAClC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,CA2DxC,CAAC"}
1
+ {"version":3,"file":"FormEntry.d.ts","sourceRoot":"","sources":["../../../components/FormEntry.tsx"],"names":[],"mappings":"AAIA,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAEhB,eAAe,EACf,eAAe,EAClB,MAAM,SAAS,CAAC;AAQjB,UAAU,cAAc,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC;IAChE,UAAU,EAAE,qBAAqB,CAAC;IAClC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IAC1B,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;CAC7C;AAGD,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,oCAIlE,cAAc,CAAC,CAAC,CAAC,mDA2DnB,CAAC"}
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FormEntry = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
- const guard_1 = require("guard");
7
6
  const condition_1 = require("../condition");
8
7
  const context_1 = require("../context");
8
+ const guard_1 = require("../guard");
9
9
  const util_1 = require("../util");
10
10
  const FormCustom_1 = require("./FormCustom");
11
11
  const FormField_1 = require("./FormField");
12
12
  const FormRow_1 = require("./FormRow");
13
13
  const FormSection_1 = require("./FormSection");
14
- const FormEntry = ({ Components, entry, children }) => {
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ const FormEntry = ({ Components, entry, children, }) => {
15
16
  const { data, fieldConfigs } = (0, context_1.useForm)();
16
17
  const getHasChildren = (0, react_1.useCallback)((formData) => {
17
18
  switch (true) {
@@ -1,10 +1,9 @@
1
- import React from "react";
2
1
  import { FormBuilderComponents, FormBuilderProps, FormFieldConfig } from "../type";
3
- interface FormFieldProps {
2
+ interface FormFieldProps<T extends FormFieldConfig<string, any, any>> {
4
3
  Components: FormBuilderComponents;
5
- field: FormFieldConfig;
6
- children: FormBuilderProps["children"];
4
+ field: T;
5
+ children: FormBuilderProps<T>["children"];
7
6
  }
8
- export declare const FormField: React.FC<FormFieldProps>;
7
+ export declare const FormField: <T extends FormFieldConfig<string, any, any>>({ Components, field, children, }: FormFieldProps<T>) => import("react/jsx-runtime").JSX.Element;
9
8
  export {};
10
9
  //# sourceMappingURL=FormField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../components/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+B,MAAM,OAAO,CAAC;AAIpD,OAAO,EAEH,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EAClB,MAAM,SAAS,CAAC;AAEjB,UAAU,cAAc;IACpB,UAAU,EAAE,qBAAqB,CAAC;IAClC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA4G9C,CAAC"}
1
+ {"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../components/FormField.tsx"],"names":[],"mappings":"AAIA,OAAO,EAEH,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EAClB,MAAM,SAAS,CAAC;AAGjB,UAAU,cAAc,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC;IAChE,UAAU,EAAE,qBAAqB,CAAC;IAClC,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;CAC7C;AAGD,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,oCAIlE,cAAc,CAAC,CAAC,CAAC,4CA4GnB,CAAC"}
@@ -6,7 +6,8 @@ const react_1 = require("react");
6
6
  const context_1 = require("../context");
7
7
  const useFormData_1 = require("../hook/useFormData");
8
8
  const useFormErrors_1 = require("../hook/useFormErrors");
9
- const FormField = ({ Components, field, children }) => {
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const FormField = ({ Components, field, children, }) => {
10
11
  const { editData, validationStrategy: contextValidationStrategy, validateField, onInput, } = (0, context_1.useForm)();
11
12
  const { name, columns, conditions, validations, valueFn, validationStrategy: fieldValidationStrategy, onInput: onFieldInput, fieldConfig: fieldConfigFunc, } = field;
12
13
  const validationStrategy = (0, react_1.useMemo)(() => [fieldValidationStrategy, contextValidationStrategy], [fieldValidationStrategy, contextValidationStrategy]);
@@ -1,9 +1,9 @@
1
1
  import { FormBuilderComponents, FormBuilderProps, FormFieldConfig, FormRowConfig } from "../type";
2
- interface FormRowProps<T extends FormFieldConfig> {
2
+ interface FormRowProps<T extends FormFieldConfig<string, any, any>> {
3
3
  Components: FormBuilderComponents;
4
4
  row: FormRowConfig<T>;
5
- children: FormBuilderProps["children"];
5
+ children: FormBuilderProps<T>["children"];
6
6
  }
7
- export declare const FormRow: <T extends FormFieldConfig>({ Components, row, children, }: FormRowProps<T>) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const FormRow: <T extends FormFieldConfig<string, any, any>>({ Components, row, children, }: FormRowProps<T>) => import("react/jsx-runtime").JSX.Element;
8
8
  export {};
9
9
  //# sourceMappingURL=FormRow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormRow.d.ts","sourceRoot":"","sources":["../../../components/FormRow.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGlG,UAAU,YAAY,CAAC,CAAC,SAAS,eAAe;IAC5C,UAAU,EAAE,qBAAqB,CAAC;IAClC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACtB,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,eAAe,kCAI9C,YAAY,CAAC,CAAC,CAAC,4CAgBjB,CAAC"}
1
+ {"version":3,"file":"FormRow.d.ts","sourceRoot":"","sources":["../../../components/FormRow.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIlG,UAAU,YAAY,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC;IAC9D,UAAU,EAAE,qBAAqB,CAAC;IAClC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACtB,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;CAC7C;AAGD,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,kCAIhE,YAAY,CAAC,CAAC,CAAC,4CAgBjB,CAAC"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FormRow = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const FormEntry_1 = require("./FormEntry");
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
7
  const FormRow = ({ Components, row, children, }) => {
7
8
  const { RowWrapper } = Components;
8
9
  if (!RowWrapper) {
@@ -1,9 +1,9 @@
1
1
  import { FormBuilderComponents, FormBuilderProps, FormFieldConfig, FormSectionConfig } from "../type";
2
- interface FormSectionProps<T extends FormFieldConfig> {
2
+ interface FormSectionProps<T extends FormFieldConfig<string, any, any>> {
3
3
  Components: FormBuilderComponents;
4
4
  section: FormSectionConfig<T>;
5
- children: FormBuilderProps["children"];
5
+ children: FormBuilderProps<T>["children"];
6
6
  }
7
- export declare const FormSection: <T extends FormFieldConfig>({ Components, section, children, }: FormSectionProps<T>) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const FormSection: <T extends FormFieldConfig<string, any, any>>({ Components, section, children, }: FormSectionProps<T>) => import("react/jsx-runtime").JSX.Element;
8
8
  export {};
9
9
  //# sourceMappingURL=FormSection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormSection.d.ts","sourceRoot":"","sources":["../../../components/FormSection.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACpB,MAAM,SAAS,CAAC;AAGjB,UAAU,gBAAgB,CAAC,CAAC,SAAS,eAAe;IAChD,UAAU,EAAE,qBAAqB,CAAC;IAClC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,sCAIlD,gBAAgB,CAAC,CAAC,CAAC,4CAgBrB,CAAC"}
1
+ {"version":3,"file":"FormSection.d.ts","sourceRoot":"","sources":["../../../components/FormSection.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACpB,MAAM,SAAS,CAAC;AAIjB,UAAU,gBAAgB,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC;IAClE,UAAU,EAAE,qBAAqB,CAAC;IAClC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9B,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;CAC7C;AAGD,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,sCAIpE,gBAAgB,CAAC,CAAC,CAAC,4CAgBrB,CAAC"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FormSection = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const FormEntry_1 = require("./FormEntry");
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
7
  const FormSection = ({ Components, section, children, }) => {
7
8
  const { SectionWrapper } = Components;
8
9
  if (!SectionWrapper) {
@@ -1,3 +1,3 @@
1
1
  import { FormData, FormFieldConfig } from "../type";
2
- export declare const fieldFulfillsConditions: ({ conditions }: Pick<FormFieldConfig, "conditions">, fieldConfigs: Record<string, FormFieldConfig>, data: FormData) => boolean;
2
+ export declare const fieldFulfillsConditions: <T extends FormFieldConfig<string, any, any>>({ conditions }: Pick<T, "conditions">, fieldConfigs: Record<string, T>, data: FormData<T>) => boolean;
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../condition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEpE,eAAO,MAAM,uBAAuB,mBAChB,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,gBACrC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,QACvC,QAAQ,KACf,OAUF,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../condition/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEpE,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,kBAC/D,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,gBACvB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,QACzB,QAAQ,CAAC,CAAC,CAAC,KAClB,OAUF,CAAC"}
@@ -1,5 +1,6 @@
1
+ import { FormFieldConfig } from "type";
1
2
  export declare const FormProvider: {
2
- (props: import("./data").FormProviderProps & {
3
+ (props: import("./data").FormProviderProps<FormFieldConfig<string, any, any>> & {
3
4
  children?: import("react").ReactNode | undefined;
4
5
  }): import("react/jsx-runtime").JSX.Element;
5
6
  displayName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"FormProvider.d.ts","sourceRoot":"","sources":["../../../context/FormProvider.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY;;;;;CA2BxB,CAAC"}
1
+ {"version":3,"file":"FormProvider.d.ts","sourceRoot":"","sources":["../../../context/FormProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAQvC,eAAO,MAAM,YAAY;;;;;CA2BxB,CAAC"}
@@ -8,6 +8,7 @@ const useFormValidations_1 = require("../hook/useFormValidations");
8
8
  const util_1 = require("../util");
9
9
  const context_1 = require("./context");
10
10
  const context_2 = require("./data/context");
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
12
  exports.FormProvider = (0, withFormData_1.withFormData)(({ config, validationStrategy = "blur", onInput: internalOnInput, inheritData, children }) => {
12
13
  const externalForm = (0, context_1.useForm)();
13
14
  const { data, editData } = (0, react_1.useContext)(context_2.FormDataContext);
@@ -2,14 +2,16 @@ import { Context } from "react";
2
2
  import { FormStore } from "../hook/useFormStore";
3
3
  import { FormValidations } from "../hook/useFormValidations";
4
4
  import { DeepPartial, FormData, FormFieldConfig, FormInputFunc, FormValidationStrategy } from "../type";
5
- interface FormContext<TData = FormData> extends FormValidations {
5
+ interface FormContextProps<U extends FormFieldConfig<string, any, any>, TData = FormData<U>> extends FormValidations {
6
6
  data: FormStore<TData>;
7
7
  editData: FormStore<DeepPartial<TData>>;
8
- fieldConfigs: Record<string, FormFieldConfig>;
8
+ fieldConfigs: Record<string, U>;
9
9
  validationStrategy: FormValidationStrategy;
10
- onInput?: FormInputFunc;
10
+ onInput?: FormInputFunc<U, U extends {
11
+ initialValue?: infer V;
12
+ } ? V : never>;
11
13
  }
12
- export declare const FormContext: Context<FormContext<FormData>>;
13
- export declare const useForm: <T = FormData>() => FormContext<T>;
14
+ export declare const FormContext: Context<FormContextProps<FormFieldConfig<string, any, any>, FormData<FormFieldConfig<string, any, any>>>>;
15
+ export declare const useForm: <U extends FormFieldConfig<string, any, any>, TData = FormData<U>>() => FormContextProps<U, TData>;
14
16
  export {};
15
17
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../context/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA6B,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EACH,WAAW,EACX,QAAQ,EACR,eAAe,EACf,aAAa,EACb,sBAAsB,EACzB,MAAM,SAAS,CAAC;AAEjB,UAAU,WAAW,CAAC,KAAK,GAAG,QAAQ,CAAE,SAAQ,eAAe;IAC3D,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC9C,kBAAkB,EAAE,sBAAsB,CAAC;IAC3C,OAAO,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED,eAAO,MAAM,WAAW,gCAAkE,CAAC;AAE3F,eAAO,MAAM,OAAO,GAAI,CAAC,gCAAoE,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../context/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAA6B,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EACH,WAAW,EACX,QAAQ,EACR,eAAe,EACf,aAAa,EACb,sBAAsB,EACzB,MAAM,SAAS,CAAC;AAEjB,UAAU,gBAAgB,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CACvF,SAAQ,eAAe;IACvB,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAChC,kBAAkB,EAAE,sBAAsB,CAAC;IAC3C,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;CAChF;AAED,eAAO,MAAM,WAAW,2GAEvB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,+CACG,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useForm = exports.FormContext = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
5
  const react_1 = require("react");
5
6
  exports.FormContext = (0, react_1.createContext)(undefined);
6
7
  const useForm = () => (0, react_1.useContext)(exports.FormContext);
@@ -1,19 +1,19 @@
1
- import React, { PropsWithChildren } from "react";
1
+ import { PropsWithChildren } from "react";
2
2
  import { FormStore } from "../../hook/useFormStore";
3
- import { FormConfig, FormData, FormInputFunc, FormValidationStrategy } from "../../type";
4
- export interface FormProviderProps {
5
- config: FormConfig;
6
- data?: FormStore<FormData>;
7
- errors?: FormStore<FormData>;
8
- editData?: FormStore<FormData>;
9
- initialData?: FormData;
3
+ import { FormConfig, FormData, FormErrors, FormFieldConfig, FormInputFunc, FormValidationStrategy } from "../../type";
4
+ export interface FormProviderProps<T extends FormFieldConfig<string, any, any>> {
5
+ config: FormConfig<T>;
6
+ data?: FormStore<FormData<T>>;
7
+ errors?: FormStore<FormErrors>;
8
+ editData?: FormStore<FormData<T>>;
9
+ initialData?: FormData<T>;
10
10
  inheritData?: boolean;
11
11
  inheritErrors?: boolean;
12
12
  validationStrategy?: FormValidationStrategy;
13
13
  /**
14
14
  * @deprecated Use the field config's 'onInput' callback instead
15
15
  */
16
- onInput?: FormInputFunc;
16
+ onInput?: FormInputFunc<T, any>;
17
17
  }
18
- export declare const FormDataProvider: React.FC<PropsWithChildren<FormProviderProps>>;
18
+ export declare const FormDataProvider: <T extends FormFieldConfig<string, any, any>>({ config, initialData, children, ...props }: PropsWithChildren<FormProviderProps<T>>) => import("react/jsx-runtime").JSX.Element;
19
19
  //# sourceMappingURL=FormDataProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormDataProvider.d.ts","sourceRoot":"","sources":["../../../../context/data/FormDataProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAsB,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,SAAS,EAAgB,MAAM,yBAAyB,CAAC;AAClE,OAAO,EACH,UAAU,EACV,QAAQ,EAER,aAAa,EACb,sBAAsB,EACzB,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC/B,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;IAC5C;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAsB3E,CAAC"}
1
+ {"version":3,"file":"FormDataProvider.d.ts","sourceRoot":"","sources":["../../../../context/data/FormDataProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAsB,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAgB,MAAM,yBAAyB,CAAC;AAClE,OAAO,EACH,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,EACb,sBAAsB,EACzB,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC;IAC1E,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,WAAW,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;IAC5C;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;CACnC;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,+CAKzE,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,4CAiBzC,CAAC"}
@@ -13,6 +13,7 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.FormDataProvider = void 0;
15
15
  const jsx_runtime_1 = require("react/jsx-runtime");
16
+ /* eslint-disable @typescript-eslint/no-explicit-any */
16
17
  const react_1 = require("react");
17
18
  const useFormStore_1 = require("../../hook/useFormStore");
18
19
  const util_1 = require("../../util");
@@ -1,13 +1,13 @@
1
1
  import { FormStore } from "../../hook/useFormStore";
2
- import { FormConfig, FormData, FormErrors } from "../../type";
3
- export type FormConfigContext = {
4
- config: FormConfig;
2
+ import { FormConfig, FormData, FormErrors, FormFieldConfig } from "../../type";
3
+ export type FormConfigContextProps<T extends FormFieldConfig<string, any, any>> = {
4
+ config: FormConfig<T>;
5
5
  };
6
- export declare const FormConfigContext: import("react").Context<FormConfigContext>;
7
- export interface FormDataContext {
8
- data: FormStore<FormData>;
9
- editData: FormStore<FormData>;
6
+ export declare const FormConfigContext: import("react").Context<FormConfigContextProps<FormFieldConfig<string, any, any>>>;
7
+ export interface FormDataContext<T extends FormFieldConfig<string, any, any>> {
8
+ data: FormStore<FormData<T>>;
9
+ editData: FormStore<FormData<T>>;
10
10
  errors: FormStore<FormErrors>;
11
11
  }
12
- export declare const FormDataContext: import("react").Context<FormDataContext>;
12
+ export declare const FormDataContext: import("react").Context<FormDataContext<FormFieldConfig<string, any, any>>>;
13
13
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../context/data/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,MAAM,iBAAiB,GAAG;IAC5B,MAAM,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,iBAAiB,4CAE7B,CAAC;AAEF,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1B,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;CACjC;AAED,eAAO,MAAM,eAAe,0CAE3B,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../context/data/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE/E,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI;IAC9E,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,oFAEsD,CAAC;AAErF,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC;IACxE,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;CACjC;AAED,eAAO,MAAM,eAAe,6EAE3B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FormDataContext = exports.FormConfigContext = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
5
  const react_1 = require("react");
5
6
  exports.FormConfigContext = (0, react_1.createContext)(undefined);
6
7
  exports.FormDataContext = (0, react_1.createContext)(undefined);
@@ -1,6 +1,6 @@
1
1
  import { FormCustomConfig, FormEntryConfig, FormFieldConfig, FormRowConfig, FormSectionConfig } from "../type";
2
- export declare const isFormRowConfig: <T extends FormFieldConfig>(config: FormEntryConfig<T>) => config is FormRowConfig<T>;
3
- export declare const isFormSectionConfig: <T extends FormFieldConfig>(config: FormEntryConfig<T>) => config is FormSectionConfig<T>;
4
- export declare const isFormCustomConfig: <T extends FormFieldConfig>(config: FormEntryConfig<T>) => config is FormCustomConfig<T>;
5
- export declare const isFormFieldConfig: <T extends FormFieldConfig>(config: FormEntryConfig<T>) => config is T;
2
+ export declare const isFormRowConfig: <T extends FormFieldConfig<string, any, any>>(config: FormEntryConfig<T>) => config is FormRowConfig<T>;
3
+ export declare const isFormSectionConfig: <T extends FormFieldConfig<string, any, any>>(config: FormEntryConfig<T>) => config is FormSectionConfig<T>;
4
+ export declare const isFormCustomConfig: <T extends FormFieldConfig<string, any, any>>(config: FormEntryConfig<T>) => config is FormCustomConfig<T>;
5
+ export declare const isFormFieldConfig: <T extends FormFieldConfig<string, any, any>>(config: FormEntryConfig<T>) => config is T;
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../guard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,aAAa,EACb,iBAAiB,EACpB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,eAAe,UAC7C,eAAe,CAAC,CAAC,CAAC,KAC3B,MAAM,IAAI,aAAa,CAAC,CAAC,CAE3B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,eAAe,UACjD,eAAe,CAAC,CAAC,CAAC,KAC3B,MAAM,IAAI,iBAAiB,CAAC,CAAC,CAE/B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,eAAe,UAChD,eAAe,CAAC,CAAC,CAAC,KAC3B,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAE9B,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,eAAe,UAC/C,eAAe,CAAC,CAAC,CAAC,KAC3B,MAAM,IAAI,CAEZ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../guard/index.ts"],"names":[],"mappings":"AACA,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,aAAa,EACb,iBAAiB,EACpB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,UAC/D,eAAe,CAAC,CAAC,CAAC,KAC3B,MAAM,IAAI,aAAa,CAAC,CAAC,CAE3B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,UACnE,eAAe,CAAC,CAAC,CAAC,KAC3B,MAAM,IAAI,iBAAiB,CAAC,CAAC,CAE/B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,UAClE,eAAe,CAAC,CAAC,CAAC,KAC3B,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAE9B,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,UACjE,eAAe,CAAC,CAAC,CAAC,KAC3B,MAAM,IAAI,CAEZ,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
+ import { FormFieldConfig } from "type";
2
3
  import { FormProviderProps } from "../context/data/FormDataProvider";
3
- export declare const withForm: <T>(WrappedComponent: React.ComponentType<FormProviderProps & T>) => {
4
- (props: FormProviderProps & T): import("react/jsx-runtime").JSX.Element;
4
+ export declare const withForm: <U extends FormFieldConfig<string, any, any>, T>(WrappedComponent: React.ComponentType<FormProviderProps<U> & T>) => {
5
+ (props: FormProviderProps<U> & T): import("react/jsx-runtime").JSX.Element;
5
6
  displayName: string;
6
7
  };
7
8
  //# sourceMappingURL=withForm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withForm.d.ts","sourceRoot":"","sources":["../../../hoc/withForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,eAAO,MAAM,QAAQ,GAAI,CAAC,oBAAqB,KAAK,CAAC,aAAa,CAAC,iBAAiB,GAAG,CAAC,CAAC;YAG/C,iBAAiB,GAAG,CAAC;;CAW9D,CAAC"}
1
+ {"version":3,"file":"withForm.d.ts","sourceRoot":"","sources":["../../../hoc/withForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGrE,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,oBACjD,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAIzB,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC;;CAYjE,CAAC"}
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withForm = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const context_1 = require("../context");
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
7
  const withForm = (WrappedComponent) => {
7
8
  const displayName = WrappedComponent.displayName || WrappedComponent.name || "Component";
8
9
  const ComponentWithProvider = (props) => {
9
- return ((0, jsx_runtime_1.jsx)(context_1.FormProvider, Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(WrappedComponent, Object.assign({}, props)) })));
10
+ return (
11
+ // @ts-expect-error: ts does not understand this
12
+ (0, jsx_runtime_1.jsx)(context_1.FormProvider, Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(WrappedComponent, Object.assign({}, props)) })));
10
13
  };
11
14
  ComponentWithProvider.displayName = `withForm(${displayName})`;
12
15
  return ComponentWithProvider;
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
+ import { FormFieldConfig } from "type";
2
3
  import { FormProviderProps } from "../context/data/FormDataProvider";
3
- export declare const withFormData: <T>(WrappedComponent: React.ComponentType<FormProviderProps & T>) => {
4
- (props: FormProviderProps & T): import("react/jsx-runtime").JSX.Element;
4
+ export declare const withFormData: <U extends FormFieldConfig<string, any, any>, T>(WrappedComponent: React.ComponentType<FormProviderProps<U> & T>) => {
5
+ (props: FormProviderProps<U> & T): import("react/jsx-runtime").JSX.Element;
5
6
  displayName: string;
6
7
  };
7
8
  //# sourceMappingURL=withFormData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withFormData.d.ts","sourceRoot":"","sources":["../../../hoc/withFormData.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAoB,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAEvF,eAAO,MAAM,YAAY,GAAI,CAAC,oBAAqB,KAAK,CAAC,aAAa,CAAC,iBAAiB,GAAG,CAAC,CAAC;YAGnD,iBAAiB,GAAG,CAAC;;CAW9D,CAAC"}
1
+ {"version":3,"file":"withFormData.d.ts","sourceRoot":"","sources":["../../../hoc/withFormData.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAoB,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGvF,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,oBACrD,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAIzB,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC;;CAWjE,CAAC"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withFormData = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const FormDataProvider_1 = require("../context/data/FormDataProvider");
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
7
  const withFormData = (WrappedComponent) => {
7
8
  const displayName = WrappedComponent.displayName || WrappedComponent.name || "Component";
8
9
  const ComponentWithProvider = (props) => {
@@ -1,5 +1,5 @@
1
- import { FormData } from "../type";
1
+ import { FormData, FormFieldConfig } from "../type";
2
2
  import { FormStore } from "./useFormStore";
3
- export declare const useFormData: <SelectorOutput>(selector: (store: FormData) => SelectorOutput) => [SelectorOutput, (value: Partial<FormData>) => void, () => FormData];
3
+ export declare const useFormData: <SelectorOutput, T extends FormFieldConfig<string, any, any>>(selector: (store: FormData<T>) => SelectorOutput) => [SelectorOutput, (value: Partial<FormData<T>>) => void, () => FormData<T>];
4
4
  export declare const useData: <Store, SelectorOutput>(data: FormStore<Store>, selector: (store: Store) => SelectorOutput) => [SelectorOutput, (value: Partial<Store>) => void, () => Store];
5
5
  //# sourceMappingURL=useFormData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFormData.d.ts","sourceRoot":"","sources":["../../../hook/useFormData.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,eAAO,MAAM,WAAW,GAAI,cAAc,YAC5B,CAAC,KAAK,EAAE,QAAQ,KAAK,cAAc,KAC9C,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,MAAM,QAAQ,CAQrE,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,KAAK,EAAE,cAAc,QACnC,SAAS,CAAC,KAAK,CAAC,YACZ,CAAC,KAAK,EAAE,KAAK,KAAK,cAAc,KAC3C,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,MAAM,KAAK,CAQ/D,CAAC"}
1
+ {"version":3,"file":"useFormData.d.ts","sourceRoot":"","sources":["../../../hook/useFormData.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,eAAO,MAAM,WAAW,GAAI,cAAc,EAAE,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,YACzE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,cAAc,KACjD,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,CAQ3E,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,KAAK,EAAE,cAAc,QACnC,SAAS,CAAC,KAAK,CAAC,YACZ,CAAC,KAAK,EAAE,KAAK,KAAK,cAAc,KAC3C,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,MAAM,KAAK,CAQ/D,CAAC"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useData = exports.useFormData = void 0;
4
4
  const react_1 = require("react");
5
5
  const context_1 = require("../context/data/context");
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
7
  const useFormData = (selector) => {
7
8
  const { data } = (0, react_1.useContext)(context_1.FormDataContext);
8
9
  if (!data) {
@@ -1,9 +1,9 @@
1
1
  import { FormConfig, FormError, FormErrors, FormFieldConfig } from "../type";
2
2
  export type FormValidations = ReturnType<typeof useFormValidations>;
3
- export declare const useFormValidations: (config: FormConfig, fieldConfigs: Record<string, FormFieldConfig>) => {
3
+ export declare const useFormValidations: <T extends FormFieldConfig<string, any, any>>(config: FormConfig<T>, fieldConfigs: Record<string, T>) => {
4
4
  errors: import("./useFormStore").FormStore<FormErrors>;
5
- validateField: (field: FormFieldConfig, skipUpdate?: boolean) => FormError | null;
5
+ validateField: (field: T, skipUpdate?: boolean) => FormError | null;
6
6
  validateCategory: (category: string) => FormErrors;
7
- validateForm: (input?: FormConfig, skipUpdate?: boolean) => FormErrors | null;
7
+ validateForm: (input?: FormConfig<T>, skipUpdate?: boolean) => FormErrors | null;
8
8
  };
9
9
  //# sourceMappingURL=useFormValidations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFormValidations.d.ts","sourceRoot":"","sources":["../../../hook/useFormValidations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI7E,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,eAAO,MAAM,kBAAkB,WACnB,UAAU,gBACJ,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;;2BAqDjC,eAAe,eAAe,OAAO,KAAG,SAAS,GAAG,IAAI;iCAvBrD,MAAM;2BAvBT,UAAU,eAAmC,OAAO,KAAG,UAAU,GAAG,IAAI;CA2DvF,CAAC"}
1
+ {"version":3,"file":"useFormValidations.d.ts","sourceRoot":"","sources":["../../../hook/useFormValidations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI7E,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAGpE,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,UAClE,UAAU,CAAC,CAAC,CAAC,gBACP,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;;2BAqDnB,CAAC,eAAe,OAAO,KAAG,SAAS,GAAG,IAAI;iCAvBvC,MAAM;2BAvBT,UAAU,CAAC,CAAC,CAAC,eAAmC,OAAO,KAAG,UAAU,GAAG,IAAI;CA2D1F,CAAC"}
@@ -5,6 +5,7 @@ const react_1 = require("react");
5
5
  const context_1 = require("../context/data/context");
6
6
  const validation_1 = require("../validation");
7
7
  const useRefEffect_1 = require("./useRefEffect");
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
9
  const useFormValidations = (config, fieldConfigs) => {
9
10
  const configRef = (0, useRefEffect_1.useRefEffect)(config);
10
11
  const fieldConfigsRef = (0, useRefEffect_1.useRefEffect)(fieldConfigs);