@becklyn/forms 1.0.0 → 2.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 (70) hide show
  1. package/README.md +0 -12
  2. package/dist/cjs/components/FormBuilder.js +1 -1
  3. package/dist/cjs/components/FormCustom.d.ts +4 -5
  4. package/dist/cjs/components/FormCustom.d.ts.map +1 -1
  5. package/dist/cjs/components/FormCustom.js +1 -1
  6. package/dist/cjs/components/FormEntry.d.ts +2 -2
  7. package/dist/cjs/components/FormEntry.d.ts.map +1 -1
  8. package/dist/cjs/components/FormEntry.js +9 -8
  9. package/dist/cjs/components/FormRow.d.ts +4 -5
  10. package/dist/cjs/components/FormRow.d.ts.map +1 -1
  11. package/dist/cjs/components/FormRow.js +1 -1
  12. package/dist/cjs/components/FormSection.d.ts +4 -5
  13. package/dist/cjs/components/FormSection.d.ts.map +1 -1
  14. package/dist/cjs/components/FormSection.js +1 -1
  15. package/dist/cjs/guard/index.d.ts +5 -5
  16. package/dist/cjs/guard/index.d.ts.map +1 -1
  17. package/dist/cjs/guard/index.js +13 -15
  18. package/dist/cjs/hook/useFormValidations.d.ts +2 -2
  19. package/dist/cjs/hook/useFormValidations.d.ts.map +1 -1
  20. package/dist/cjs/hook/useFormValidations.js +1 -3
  21. package/dist/cjs/type/config.d.ts +8 -8
  22. package/dist/cjs/type/config.d.ts.map +1 -1
  23. package/dist/cjs/type/field.d.ts +2 -6
  24. package/dist/cjs/type/field.d.ts.map +1 -1
  25. package/dist/cjs/type/form.d.ts +4 -4
  26. package/dist/cjs/type/form.d.ts.map +1 -1
  27. package/dist/cjs/type/test.d.ts +14 -0
  28. package/dist/cjs/type/test.d.ts.map +1 -0
  29. package/dist/cjs/type/test.js +14 -0
  30. package/dist/cjs/util/index.d.ts +5 -5
  31. package/dist/cjs/util/index.d.ts.map +1 -1
  32. package/dist/cjs/util/index.js +16 -22
  33. package/dist/cjs/validation/index.d.ts +2 -2
  34. package/dist/cjs/validation/index.d.ts.map +1 -1
  35. package/dist/cjs/validation/index.js +6 -7
  36. package/dist/es/components/FormBuilder.js +1 -1
  37. package/dist/es/components/FormCustom.d.ts +4 -5
  38. package/dist/es/components/FormCustom.d.ts.map +1 -1
  39. package/dist/es/components/FormCustom.js +1 -1
  40. package/dist/es/components/FormEntry.d.ts +2 -2
  41. package/dist/es/components/FormEntry.d.ts.map +1 -1
  42. package/dist/es/components/FormEntry.js +9 -8
  43. package/dist/es/components/FormRow.d.ts +4 -5
  44. package/dist/es/components/FormRow.d.ts.map +1 -1
  45. package/dist/es/components/FormRow.js +1 -1
  46. package/dist/es/components/FormSection.d.ts +4 -5
  47. package/dist/es/components/FormSection.d.ts.map +1 -1
  48. package/dist/es/components/FormSection.js +1 -1
  49. package/dist/es/guard/index.d.ts +5 -5
  50. package/dist/es/guard/index.d.ts.map +1 -1
  51. package/dist/es/guard/index.js +13 -15
  52. package/dist/es/hook/useFormValidations.d.ts +2 -2
  53. package/dist/es/hook/useFormValidations.d.ts.map +1 -1
  54. package/dist/es/hook/useFormValidations.js +1 -3
  55. package/dist/es/type/config.d.ts +8 -8
  56. package/dist/es/type/config.d.ts.map +1 -1
  57. package/dist/es/type/field.d.ts +2 -6
  58. package/dist/es/type/field.d.ts.map +1 -1
  59. package/dist/es/type/form.d.ts +4 -4
  60. package/dist/es/type/form.d.ts.map +1 -1
  61. package/dist/es/type/test.d.ts +14 -0
  62. package/dist/es/type/test.d.ts.map +1 -0
  63. package/dist/es/type/test.js +14 -0
  64. package/dist/es/util/index.d.ts +5 -5
  65. package/dist/es/util/index.d.ts.map +1 -1
  66. package/dist/es/util/index.js +16 -22
  67. package/dist/es/validation/index.d.ts +2 -2
  68. package/dist/es/validation/index.d.ts.map +1 -1
  69. package/dist/es/validation/index.js +6 -7
  70. package/package.json +1 -1
package/README.md CHANGED
@@ -173,18 +173,6 @@ export type FormFieldText = FormFieldBasicConfig<"text", TextFieldConfig>;
173
173
 
174
174
  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
175
 
176
- #### 3. Patch form fields
177
-
178
- To overwrite the `FormFieldConfig` you can patch the interface using module augmentation:
179
-
180
- ```typescript
181
- declare module "@becklyn/forms" {
182
- interface CustomFormFieldConfig {
183
- fields: FormFieldText | FormFieldNumber;
184
- }
185
- }
186
- ```
187
-
188
176
  ### Infer form config
189
177
 
190
178
  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:
@@ -17,6 +17,6 @@ exports.FormBuilder = (0, react_1.memo)(({ Components = DefaultComponents, child
17
17
  const { BuilderWrapper } = Components;
18
18
  const { config } = (0, react_1.useContext)(context_1.FormConfigContext);
19
19
  const Wrapper = BuilderWrapper !== null && BuilderWrapper !== void 0 ? BuilderWrapper : style_1.DefaultBuilderWrapper;
20
- 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.entryIsField)(entry) ? entry.name : "")))) }));
20
+ 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
21
  });
22
22
  exports.FormBuilder.displayName = "FormBuilder";
@@ -1,10 +1,9 @@
1
- import React from "react";
2
- import { FormBuilderComponents, FormBuilderProps, FormCustomConfig } from "../type";
3
- interface FormCustomProps {
1
+ import { FormBuilderComponents, FormBuilderProps, FormCustomConfig, FormFieldConfig } from "../type";
2
+ interface FormCustomProps<T extends FormFieldConfig> {
4
3
  Components: FormBuilderComponents;
5
- custom: FormCustomConfig;
4
+ custom: FormCustomConfig<T>;
6
5
  children: FormBuilderProps["children"];
7
6
  }
8
- export declare const FormCustom: React.FC<FormCustomProps>;
7
+ export declare const FormCustom: <T extends FormFieldConfig>({ Components, custom, children, }: FormCustomProps<T>) => import("react/jsx-runtime").JSX.Element;
9
8
  export {};
10
9
  //# sourceMappingURL=FormCustom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormCustom.d.ts","sourceRoot":"","sources":["../../../components/FormCustom.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGpF,UAAU,eAAe;IACrB,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAYhD,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;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"}
@@ -7,7 +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
- const FormCustom = ({ Components, custom, children }) => {
10
+ const FormCustom = ({ Components, custom, children, }) => {
11
11
  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
12
  };
13
13
  exports.FormCustom = FormCustom;
@@ -1,10 +1,10 @@
1
- import React from "react";
1
+ import { FC } from "react";
2
2
  import { FormBuilderComponents, FormBuilderProps, FormEntryConfig } from "../type";
3
3
  interface FormEntryProps {
4
4
  Components: FormBuilderComponents;
5
5
  entry: FormEntryConfig;
6
6
  children: FormBuilderProps["children"];
7
7
  }
8
- export declare const FormEntry: React.FC<FormEntryProps>;
8
+ export declare const FormEntry: FC<FormEntryProps>;
9
9
  export {};
10
10
  //# sourceMappingURL=FormEntry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormEntry.d.ts","sourceRoot":"","sources":["../../../components/FormEntry.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAGhE,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,KAAK,CAAC,EAAE,CAAC,cAAc,CA2D9C,CAAC"}
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"}
@@ -3,6 +3,7 @@ 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");
6
7
  const condition_1 = require("../condition");
7
8
  const context_1 = require("../context");
8
9
  const util_1 = require("../util");
@@ -13,10 +14,10 @@ const FormSection_1 = require("./FormSection");
13
14
  const FormEntry = ({ Components, entry, children }) => {
14
15
  const { data, fieldConfigs } = (0, context_1.useForm)();
15
16
  const getHasChildren = (0, react_1.useCallback)((formData) => {
16
- switch (entry.type) {
17
- case "custom":
18
- case "section":
19
- case "row":
17
+ switch (true) {
18
+ case (0, guard_1.isFormRowConfig)(entry):
19
+ case (0, guard_1.isFormSectionConfig)(entry):
20
+ case (0, guard_1.isFormCustomConfig)(entry):
20
21
  return (0, util_1.someFieldConfigs)([entry], field => (0, condition_1.fieldFulfillsConditions)(field, fieldConfigs, formData));
21
22
  default:
22
23
  return (0, condition_1.fieldFulfillsConditions)(entry, fieldConfigs, formData);
@@ -32,12 +33,12 @@ const FormEntry = ({ Components, entry, children }) => {
32
33
  if (!hasChildren) {
33
34
  return null;
34
35
  }
35
- switch (entry.type) {
36
- case "custom":
36
+ switch (true) {
37
+ case (0, guard_1.isFormCustomConfig)(entry):
37
38
  return ((0, jsx_runtime_1.jsx)(FormCustom_1.FormCustom, { custom: entry, Components: Components, children: children }));
38
- case "section":
39
+ case (0, guard_1.isFormSectionConfig)(entry):
39
40
  return ((0, jsx_runtime_1.jsx)(FormSection_1.FormSection, { section: entry, Components: Components, children: children }));
40
- case "row":
41
+ case (0, guard_1.isFormRowConfig)(entry):
41
42
  return ((0, jsx_runtime_1.jsx)(FormRow_1.FormRow, { row: entry, Components: Components, children: children }));
42
43
  default:
43
44
  return ((0, jsx_runtime_1.jsx)(FormField_1.FormField, { field: entry, Components: Components, children: children }));
@@ -1,10 +1,9 @@
1
- import React from "react";
2
- import { FormBuilderComponents, FormBuilderProps, FormRowConfig } from "../type";
3
- interface FormRowProps {
1
+ import { FormBuilderComponents, FormBuilderProps, FormFieldConfig, FormRowConfig } from "../type";
2
+ interface FormRowProps<T extends FormFieldConfig> {
4
3
  Components: FormBuilderComponents;
5
- row: FormRowConfig;
4
+ row: FormRowConfig<T>;
6
5
  children: FormBuilderProps["children"];
7
6
  }
8
- export declare const FormRow: React.FC<FormRowProps>;
7
+ export declare const FormRow: <T extends FormFieldConfig>({ Components, row, children, }: FormRowProps<T>) => import("react/jsx-runtime").JSX.Element;
9
8
  export {};
10
9
  //# sourceMappingURL=FormRow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormRow.d.ts","sourceRoot":"","sources":["../../../components/FormRow.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGjF,UAAU,YAAY;IAClB,UAAU,EAAE,qBAAqB,CAAC;IAClC,GAAG,EAAE,aAAa,CAAC;IACnB,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAgB1C,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;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"}
@@ -3,7 +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
- const FormRow = ({ Components, row, children }) => {
6
+ const FormRow = ({ Components, row, children, }) => {
7
7
  const { RowWrapper } = Components;
8
8
  if (!RowWrapper) {
9
9
  throw new Error(`No row component found.`);
@@ -1,10 +1,9 @@
1
- import React from "react";
2
- import { FormBuilderComponents, FormBuilderProps, FormSectionConfig } from "../type";
3
- interface FormSectionProps {
1
+ import { FormBuilderComponents, FormBuilderProps, FormFieldConfig, FormSectionConfig } from "../type";
2
+ interface FormSectionProps<T extends FormFieldConfig> {
4
3
  Components: FormBuilderComponents;
5
- section: FormSectionConfig;
4
+ section: FormSectionConfig<T>;
6
5
  children: FormBuilderProps["children"];
7
6
  }
8
- export declare const FormSection: React.FC<FormSectionProps>;
7
+ export declare const FormSection: <T extends FormFieldConfig>({ Components, section, children, }: FormSectionProps<T>) => import("react/jsx-runtime").JSX.Element;
9
8
  export {};
10
9
  //# sourceMappingURL=FormSection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormSection.d.ts","sourceRoot":"","sources":["../../../components/FormSection.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGrF,UAAU,gBAAgB;IACtB,UAAU,EAAE,qBAAqB,CAAC;IAClC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAgBlD,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;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"}
@@ -3,7 +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
- const FormSection = ({ Components, section, children }) => {
6
+ const FormSection = ({ Components, section, children, }) => {
7
7
  const { SectionWrapper } = Components;
8
8
  if (!SectionWrapper) {
9
9
  throw new Error(`No section component found.`);
@@ -1,6 +1,6 @@
1
- import { FormCustomConfig, FormEntryConfig, FormFieldBasicConfig, FormRowConfig, FormSectionConfig } from "../type";
2
- export declare const entryIsSection: (entry: Pick<FormEntryConfig, "type">) => entry is FormSectionConfig;
3
- export declare const entryIsRow: (entry: Pick<FormEntryConfig, "type">) => entry is FormRowConfig;
4
- export declare const entryIsCustom: (entry: Pick<FormEntryConfig, "type">) => entry is FormCustomConfig;
5
- export declare const entryIsField: (entry: Pick<FormEntryConfig, "type">) => entry is FormFieldBasicConfig<any>;
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;
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,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACpB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,cAAc,UAChB,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,KACrC,KAAK,IAAI,iBAEX,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,KAAG,KAAK,IAAI,aAE1E,CAAC;AAEF,eAAO,MAAM,aAAa,UAAW,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,KAAG,KAAK,IAAI,gBAE7E,CAAC;AAEF,eAAO,MAAM,YAAY,UACd,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,KAErC,KAAK,IAAI,oBAAoB,CAAC,GAAG,CAEnC,CAAC"}
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,21 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.entryIsField = exports.entryIsCustom = exports.entryIsRow = exports.entryIsSection = void 0;
4
- const entryIsSection = (entry) => {
5
- return entry.type === "section";
3
+ exports.isFormFieldConfig = exports.isFormCustomConfig = exports.isFormSectionConfig = exports.isFormRowConfig = void 0;
4
+ const isFormRowConfig = (config) => {
5
+ return config && config.type === "row";
6
6
  };
7
- exports.entryIsSection = entryIsSection;
8
- const entryIsRow = (entry) => {
9
- return entry.type === "row";
7
+ exports.isFormRowConfig = isFormRowConfig;
8
+ const isFormSectionConfig = (config) => {
9
+ return config && config.type === "section";
10
10
  };
11
- exports.entryIsRow = entryIsRow;
12
- const entryIsCustom = (entry) => {
13
- return entry.type === "custom";
11
+ exports.isFormSectionConfig = isFormSectionConfig;
12
+ const isFormCustomConfig = (config) => {
13
+ return config && config.type === "custom";
14
14
  };
15
- exports.entryIsCustom = entryIsCustom;
16
- const entryIsField = (entry
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- ) => {
19
- return !(0, exports.entryIsSection)(entry) && !(0, exports.entryIsRow)(entry) && !(0, exports.entryIsCustom)(entry);
15
+ exports.isFormCustomConfig = isFormCustomConfig;
16
+ const isFormFieldConfig = (config) => {
17
+ return !(0, exports.isFormRowConfig)(config) && !(0, exports.isFormSectionConfig)(config) && !(0, exports.isFormCustomConfig)(config);
20
18
  };
21
- exports.entryIsField = entryIsField;
19
+ exports.isFormFieldConfig = isFormFieldConfig;
@@ -1,8 +1,8 @@
1
- import { FormConfig, FormError, FormErrors, FormFieldBasicConfig, FormFieldConfig } from "../type";
1
+ import { FormConfig, FormError, FormErrors, FormFieldConfig } from "../type";
2
2
  export type FormValidations = ReturnType<typeof useFormValidations>;
3
3
  export declare const useFormValidations: (config: FormConfig, fieldConfigs: Record<string, FormFieldConfig>) => {
4
4
  errors: import("./useFormStore").FormStore<FormErrors>;
5
- validateField: (field: FormFieldBasicConfig<any>, skipUpdate?: boolean) => FormError | null;
5
+ validateField: (field: FormFieldConfig, skipUpdate?: boolean) => FormError | null;
6
6
  validateCategory: (category: string) => FormErrors;
7
7
  validateForm: (input?: FormConfig, skipUpdate?: boolean) => FormErrors | null;
8
8
  };
@@ -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,oBAAoB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAInG,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,eAAO,MAAM,kBAAkB,WACnB,UAAU,gBACJ,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;;2BAsDjC,oBAAoB,CAAC,GAAG,CAAC,eAAe,OAAO,KAAG,SAAS,GAAG,IAAI;iCAxB/D,MAAM;2BAvBT,UAAU,eAAmC,OAAO,KAAG,UAAU,GAAG,IAAI;CA4DvF,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;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"}
@@ -34,9 +34,7 @@ const useFormValidations = (config, fieldConfigs) => {
34
34
  errors.set(formErrors);
35
35
  return formErrors;
36
36
  }, [fieldConfigsRef, data, errors]);
37
- const validateField = (0, react_1.useCallback)(
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- (field, skipUpdate) => {
37
+ const validateField = (0, react_1.useCallback)((field, skipUpdate) => {
40
38
  const formErrors = (0, validation_1.handleValidateField)(field, fieldConfigsRef.current, data.get());
41
39
  if (!skipUpdate) {
42
40
  errors.set(formErrors);
@@ -1,18 +1,18 @@
1
1
  import { ReactNode } from "react";
2
2
  import { FormFieldConfig } from "./field";
3
- export interface FormRowConfig {
3
+ export interface FormRowConfig<T extends FormFieldConfig> {
4
4
  type: "row";
5
- content: readonly FormEntryConfig[];
5
+ content: readonly FormEntryConfig<T>[];
6
6
  }
7
- export interface FormSectionConfig {
7
+ export interface FormSectionConfig<T extends FormFieldConfig> {
8
8
  type: "section";
9
- content: readonly FormEntryConfig[];
9
+ content: readonly FormEntryConfig<T>[];
10
10
  }
11
- export interface FormCustomConfig {
11
+ export interface FormCustomConfig<T extends FormFieldConfig> {
12
12
  type: "custom";
13
13
  wrapper: (children: ReactNode) => ReactNode;
14
- content: readonly FormEntryConfig[];
14
+ content: readonly FormEntryConfig<T>[];
15
15
  }
16
- export type FormEntryConfig = FormCustomConfig | FormSectionConfig | FormRowConfig | FormFieldConfig;
17
- export type FormConfig = readonly FormEntryConfig[];
16
+ export type FormEntryConfig<T extends FormFieldConfig = FormFieldConfig> = FormCustomConfig<T> | FormSectionConfig<T> | FormRowConfig<T> | T;
17
+ export type FormConfig<T extends FormFieldConfig = FormFieldConfig> = readonly FormEntryConfig<T>[];
18
18
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../type/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,SAAS,CAAC;IAC5C,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;CACvC;AAED,MAAM,MAAM,eAAe,GACrB,gBAAgB,GAChB,iBAAiB,GACjB,aAAa,GACb,eAAe,CAAC;AAEtB,MAAM,MAAM,UAAU,GAAG,SAAS,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../type/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,eAAe;IACpD,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,eAAe;IACxD,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,eAAe;IACvD,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,SAAS,CAAC;IAC5C,OAAO,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;CAC1C;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IACjE,gBAAgB,CAAC,CAAC,CAAC,GACnB,iBAAiB,CAAC,CAAC,CAAC,GACpB,aAAa,CAAC,CAAC,CAAC,GAChB,CAAC,CAAC;AAER,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC"}
@@ -1,11 +1,7 @@
1
1
  import { FormFieldConditions } from "./condition";
2
2
  import { FormData, FormInputFunc } from "./form";
3
3
  import { FieldValidations, FormValidationStrategy } from "./validation";
4
- export type CustomFormFieldConfig = object;
5
- export type FormFieldConfig = CustomFormFieldConfig extends {
6
- [P in "fields"]: infer U;
7
- } ? U : FormFieldBasicConfig<"placeholder">;
8
- export interface FormFieldBasicConfig<Type extends string, FieldConfig = unknown, InitialValue = any> {
4
+ export interface FormFieldConfig<Type extends string = string, FieldConfig = unknown, InitialValue = any> {
9
5
  type: Type;
10
6
  name: string;
11
7
  initialValue?: InitialValue;
@@ -22,7 +18,7 @@ export type FormFieldConfigFunc<FieldConfig = unknown> = FieldConfig | ((props:
22
18
  value: any;
23
19
  data: FormData;
24
20
  }) => FieldConfig);
25
- export type ResolveFieldConfigFunc<T extends FormFieldBasicConfig<any>> = T extends {
21
+ export type ResolveFieldConfigFunc<T extends FormFieldConfig> = T extends {
26
22
  fieldConfig: infer U;
27
23
  } ? U extends (...args: any[]) => any ? never : T & {
28
24
  fieldConfig: U;
@@ -1 +1 @@
1
- {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../type/field.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,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G,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAC7B,KAAK,GACL,CAAC,GAAG;IAAE,WAAW,EAAE,CAAC,CAAA;CAAE,GAC1B,KAAK,CAAC"}
@@ -21,10 +21,10 @@ export interface FormBuilderProps {
21
21
  Components?: Partial<FormBuilderComponents>;
22
22
  children(props: FormBuilderChildrenProps): ReactNode;
23
23
  }
24
- export interface FormInputFuncProps {
25
- value: any;
26
- field: FormFieldConfig;
24
+ export interface FormInputFuncProps<T extends FormFieldConfig> {
25
+ value: T extends FormFieldConfig<any, any, infer V> ? V : any;
26
+ field: T;
27
27
  previousData: FormData;
28
28
  }
29
- export type FormInputFunc = (props: FormInputFuncProps) => FormData;
29
+ export type FormInputFunc = <T extends FormFieldConfig>(props: FormInputFuncProps<T>) => FormData;
30
30
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../type/form.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE3C,MAAM,WAAW,qBAAqB;IAClC,cAAc,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;IACzD,cAAc,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;IACzD,UAAU,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;IACrD,YAAY,EAAE,qBAAqB,CAAC,iBAAiB,CAAC;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CAChF;AAED,MAAM,WAAW,wBAAwB;IACrC,KAAK,EAAE,GAAG,CAAC;IACX,KAAK,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AE,SAAS,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC9B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,sBAAsB,CAAC,eAAe,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,gBAAgB;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,wBAAwB,GAAG,SAAS,CAAC;CACxD;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,eAAe;IACzD,KAAK,EAAE,CAAC,SAAS,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAC9D,KAAK,EAAE,CAAC,CAAC;IACT,YAAY,EAAE,QAAQ,CAAC;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export interface TextConfigProps {
2
+ type: "text";
3
+ placeholder: string;
4
+ label?: string;
5
+ editLabel?: string;
6
+ maxLength?: number;
7
+ info?: string;
8
+ suffix?: string;
9
+ hideValidation?: boolean;
10
+ hasCapsLockDetection?: boolean;
11
+ isSecret?: boolean;
12
+ disabled?: boolean;
13
+ }
14
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../../type/test.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const configAllFields = [
4
+ {
5
+ type: "button",
6
+ name: "text",
7
+ validations: [{ validation: true }],
8
+ fieldConfig: {
9
+ placeholder: "text",
10
+ type: "text",
11
+ },
12
+ },
13
+ ];
14
+ console.log(configAllFields);
@@ -1,11 +1,11 @@
1
- import { FormConfig, FormData, FormEntryConfig, FormFieldBasicConfig, FormFieldConfig, ResolveFieldConfigFunc } from "../type";
1
+ import { FormConfig, FormData, FormEntryConfig, FormFieldConfig, ResolveFieldConfigFunc } from "../type";
2
2
  export declare function eitherOr<const T>(config: T | false | undefined | null | 0 | ""): T;
3
3
  export declare function eitherOr<const Either, const Or>(condition: boolean, either: Either, or: Or): Either | Or;
4
4
  export declare const createFormConfig: <const T extends FormConfig>(config: T) => T;
5
- export declare const fieldConfigFromFormField: <T extends FormFieldBasicConfig<any>>({ name, fieldConfig }: T, data: FormData) => ResolveFieldConfigFunc<T>["fieldConfig"];
5
+ export declare const fieldConfigFromFormField: <T extends FormFieldConfig>({ name, fieldConfig }: T, data: FormData) => ResolveFieldConfigFunc<T>["fieldConfig"];
6
6
  export declare const fieldsFromConfig: (config: FormConfig) => Record<string, FormFieldConfig>;
7
7
  export declare const initialValuesFromConfig: (config: FormConfig) => FormData;
8
- export declare const mapFieldConfigs: (entries: FormConfig, callbackFn: <T extends FormFieldBasicConfig<any>>(field: T, index: number) => T) => FormConfig;
9
- export declare const reduceFieldConfigs: <T extends Record<string | number, unknown>>(entries: readonly FormEntryConfig[], callbackFn: <F extends FormFieldBasicConfig<any>>(acc: T, field: F, index: number) => T) => T;
10
- export declare const someFieldConfigs: (entries: readonly FormEntryConfig[], callbackFn: <T extends FormFieldBasicConfig<any>>(field: T, index: number) => boolean) => boolean;
8
+ export declare const mapFieldConfigs: (entries: FormConfig, callbackFn: <T extends FormFieldConfig>(field: T, index: number) => T) => FormConfig;
9
+ export declare const reduceFieldConfigs: <T extends Record<string | number, unknown>>(entries: readonly FormEntryConfig[], callbackFn: <F extends FormFieldConfig>(acc: T, field: F, index: number) => T) => T;
10
+ export declare const someFieldConfigs: (entries: readonly FormEntryConfig[], callbackFn: <T extends FormFieldConfig>(field: T, index: number) => boolean) => boolean;
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../util/index.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,EACV,QAAQ,EACR,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,sBAAsB,EACzB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,KAAK,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACpF,wBAAgB,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAC3C,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,EAAE,GACP,MAAM,GAAG,EAAE,CAAC;AAaf,eAAO,MAAM,gBAAgB,SAAU,CAAC,SAAS,UAAU,UAAU,CAAC,KACZ,CAAC,CAAC;AAG5D,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,oBAAoB,CAAC,GAAG,CAAC,yBACjD,CAAC,QAClB,QAAQ,KACf,sBAAsB,CAAC,CAAC,CAAC,CAAC,aAAa,CAIzC,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAAY,UAAU,KAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAKnF,CA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AC,CAAC;AAE5D,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,eAAe,yBACvC,CAAC,QAClB,QAAQ,KACf,sBAAsB,CAAC,CAAC,CAAC,CAAC,aAAa,CAIzC,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAAY,UAAU,KAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAKnF,CAAC;AAEF,eAAO,MAAM,uBAAuB,WAAY,UAAU,KAAG,QAe5D,CAAC;AAEF,eAAO,MAAM,eAAe,YACf,UAAU,cACP,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,KACtE,UAkBF,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,WAChE,SAAS,eAAe,EAAE,cACvB,CAAC,CAAC,SAAS,eAAe,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,KAC9E,CAeF,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAChB,SAAS,eAAe,EAAE,cACvB,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,KAC5E,OAWF,CAAC"}
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.someFieldConfigs = exports.reduceFieldConfigs = exports.mapFieldConfigs = exports.initialValuesFromConfig = exports.fieldsFromConfig = exports.fieldConfigFromFormField = exports.createFormConfig = void 0;
7
7
  exports.eitherOr = eitherOr;
8
+ const guard_1 = require("guard");
8
9
  const lodash_merge_1 = __importDefault(require("lodash.merge"));
9
10
  function eitherOr(configOrCondition, either, or) {
10
11
  if (typeof configOrCondition === "boolean") {
@@ -16,7 +17,6 @@ function eitherOr(configOrCondition, either, or) {
16
17
  }
17
18
  const createFormConfig = (config) => (0, exports.mapFieldConfigs)(config, entry => entry);
18
19
  exports.createFormConfig = createFormConfig;
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
20
  const fieldConfigFromFormField = ({ name, fieldConfig }, data) => {
21
21
  return typeof fieldConfig === "function"
22
22
  ? fieldConfig({ value: data[name], data })
@@ -44,17 +44,15 @@ const initialValuesFromConfig = (config) => {
44
44
  });
45
45
  };
46
46
  exports.initialValuesFromConfig = initialValuesFromConfig;
47
- const mapFieldConfigs = (entries,
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- callbackFn) => {
47
+ const mapFieldConfigs = (entries, callbackFn) => {
50
48
  return entries.flatMap((entry, index) => {
51
49
  if (!entry) {
52
50
  return [];
53
51
  }
54
- switch (entry.type) {
55
- case "custom":
56
- case "section":
57
- case "row":
52
+ switch (true) {
53
+ case (0, guard_1.isFormRowConfig)(entry):
54
+ case (0, guard_1.isFormSectionConfig)(entry):
55
+ case (0, guard_1.isFormCustomConfig)(entry):
58
56
  return Object.assign(Object.assign({}, entry), { content: (0, exports.mapFieldConfigs)(entry.content, callbackFn) });
59
57
  default:
60
58
  return callbackFn(entry, index);
@@ -62,14 +60,12 @@ callbackFn) => {
62
60
  });
63
61
  };
64
62
  exports.mapFieldConfigs = mapFieldConfigs;
65
- const reduceFieldConfigs = (entries,
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- callbackFn) => {
63
+ const reduceFieldConfigs = (entries, callbackFn) => {
68
64
  return entries.reduce((acc, entry, index) => {
69
- switch (entry.type) {
70
- case "custom":
71
- case "section":
72
- case "row":
65
+ switch (true) {
66
+ case (0, guard_1.isFormRowConfig)(entry):
67
+ case (0, guard_1.isFormSectionConfig)(entry):
68
+ case (0, guard_1.isFormCustomConfig)(entry):
73
69
  acc = Object.assign(Object.assign({}, acc), (0, exports.reduceFieldConfigs)(entry.content, callbackFn));
74
70
  break;
75
71
  default:
@@ -80,14 +76,12 @@ callbackFn) => {
80
76
  }, {});
81
77
  };
82
78
  exports.reduceFieldConfigs = reduceFieldConfigs;
83
- const someFieldConfigs = (entries,
84
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
- callbackFn) => {
79
+ const someFieldConfigs = (entries, callbackFn) => {
86
80
  return entries.some((entry, index) => {
87
- switch (entry.type) {
88
- case "custom":
89
- case "section":
90
- case "row":
81
+ switch (true) {
82
+ case (0, guard_1.isFormRowConfig)(entry):
83
+ case (0, guard_1.isFormSectionConfig)(entry):
84
+ case (0, guard_1.isFormCustomConfig)(entry):
91
85
  return (0, exports.someFieldConfigs)(entry.content, callbackFn);
92
86
  default:
93
87
  return callbackFn(entry, index);
@@ -1,4 +1,4 @@
1
- import { FormConfig, FormData, FormErrors, FormFieldBasicConfig, FormFieldConfig } from "../type";
1
+ import { FormConfig, FormData, FormErrors, FormFieldConfig } from "../type";
2
2
  export declare const handleValidateConfig: (config: FormConfig, fieldConfigs: Record<string, FormFieldConfig>, data: FormData) => FormErrors;
3
- export declare const handleValidateField: ({ name, validations, conditions, valueFn }: FormFieldBasicConfig<any>, fieldConfigs: Record<string, FormFieldConfig>, data: FormData) => FormErrors;
3
+ export declare const handleValidateField: ({ name, validations, conditions, valueFn }: FormFieldConfig, fieldConfigs: Record<string, FormFieldConfig>, data: FormData) => FormErrors;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../validation/index.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,EACV,QAAQ,EAER,UAAU,EACV,oBAAoB,EACpB,eAAe,EAClB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,oBAAoB,WACrB,UAAU,gBACJ,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,QACvC,QAAQ,KACf,UAYF,CAAC;AAiBF,eAAO,MAAM,mBAAmB,+CAEgB,oBAAoB,CAAC,GAAG,CAAC,gBACvD,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,QACvC,QAAQ,KACf,UA8BF,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../validation/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAmB,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE7F,eAAO,MAAM,oBAAoB,WACrB,UAAU,gBACJ,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,QACvC,QAAQ,KACf,UAYF,CAAC;AAiBF,eAAO,MAAM,mBAAmB,+CACgB,eAAe,gBAC7C,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,QACvC,QAAQ,KACf,UA8BF,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleValidateField = exports.handleValidateConfig = void 0;
4
+ const guard_1 = require("guard");
4
5
  const condition_1 = require("../condition");
5
6
  const handleValidateConfig = (config, fieldConfigs, data) => {
6
7
  const errors = {};
@@ -14,18 +15,16 @@ const handleValidateConfig = (config, fieldConfigs, data) => {
14
15
  };
15
16
  exports.handleValidateConfig = handleValidateConfig;
16
17
  const handleValidateEntry = (entry, fieldConfigs, data) => {
17
- switch (entry.type) {
18
- case "custom":
19
- case "section":
20
- case "row":
18
+ switch (true) {
19
+ case (0, guard_1.isFormRowConfig)(entry):
20
+ case (0, guard_1.isFormSectionConfig)(entry):
21
+ case (0, guard_1.isFormCustomConfig)(entry):
21
22
  return (0, exports.handleValidateConfig)(entry.content, fieldConfigs, data);
22
23
  default:
23
24
  return (0, exports.handleValidateField)(entry, fieldConfigs, data);
24
25
  }
25
26
  };
26
- const handleValidateField = (
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- { name, validations, conditions, valueFn }, fieldConfigs, data) => {
27
+ const handleValidateField = ({ name, validations, conditions, valueFn }, fieldConfigs, data) => {
29
28
  if (!validations ||
30
29
  (conditions && !(0, condition_1.fieldFulfillsConditions)({ conditions }, fieldConfigs, data))) {
31
30
  return { [name]: false };
@@ -17,6 +17,6 @@ exports.FormBuilder = (0, react_1.memo)(({ Components = DefaultComponents, child
17
17
  const { BuilderWrapper } = Components;
18
18
  const { config } = (0, react_1.useContext)(context_1.FormConfigContext);
19
19
  const Wrapper = BuilderWrapper ?? style_1.DefaultBuilderWrapper;
20
- return ((0, jsx_runtime_1.jsx)(Wrapper, { children: config.map((entry, index) => ((0, jsx_runtime_1.jsx)(FormEntry_1.FormEntry, { entry: entry, Components: { ...DefaultComponents, ...Components }, children: children }, index + ((0, guard_1.entryIsField)(entry) ? entry.name : "")))) }));
20
+ return ((0, jsx_runtime_1.jsx)(Wrapper, { children: config.map((entry, index) => ((0, jsx_runtime_1.jsx)(FormEntry_1.FormEntry, { entry: entry, Components: { ...DefaultComponents, ...Components }, children: children }, index + ((0, guard_1.isFormFieldConfig)(entry) ? entry.name : "")))) }));
21
21
  });
22
22
  exports.FormBuilder.displayName = "FormBuilder";
@@ -1,10 +1,9 @@
1
- import React from "react";
2
- import { FormBuilderComponents, FormBuilderProps, FormCustomConfig } from "../type";
3
- interface FormCustomProps {
1
+ import { FormBuilderComponents, FormBuilderProps, FormCustomConfig, FormFieldConfig } from "../type";
2
+ interface FormCustomProps<T extends FormFieldConfig> {
4
3
  Components: FormBuilderComponents;
5
- custom: FormCustomConfig;
4
+ custom: FormCustomConfig<T>;
6
5
  children: FormBuilderProps["children"];
7
6
  }
8
- export declare const FormCustom: React.FC<FormCustomProps>;
7
+ export declare const FormCustom: <T extends FormFieldConfig>({ Components, custom, children, }: FormCustomProps<T>) => import("react/jsx-runtime").JSX.Element;
9
8
  export {};
10
9
  //# sourceMappingURL=FormCustom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormCustom.d.ts","sourceRoot":"","sources":["../../../components/FormCustom.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGpF,UAAU,eAAe;IACrB,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAYhD,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;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"}
@@ -7,7 +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
- const FormCustom = ({ Components, custom, children }) => {
10
+ const FormCustom = ({ Components, custom, children, }) => {
11
11
  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
12
  };
13
13
  exports.FormCustom = FormCustom;