@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.
- package/README.md +0 -12
- package/dist/cjs/components/FormBuilder.js +1 -1
- package/dist/cjs/components/FormCustom.d.ts +4 -5
- package/dist/cjs/components/FormCustom.d.ts.map +1 -1
- package/dist/cjs/components/FormCustom.js +1 -1
- package/dist/cjs/components/FormEntry.d.ts +2 -2
- package/dist/cjs/components/FormEntry.d.ts.map +1 -1
- package/dist/cjs/components/FormEntry.js +9 -8
- package/dist/cjs/components/FormRow.d.ts +4 -5
- package/dist/cjs/components/FormRow.d.ts.map +1 -1
- package/dist/cjs/components/FormRow.js +1 -1
- package/dist/cjs/components/FormSection.d.ts +4 -5
- package/dist/cjs/components/FormSection.d.ts.map +1 -1
- package/dist/cjs/components/FormSection.js +1 -1
- package/dist/cjs/guard/index.d.ts +5 -5
- package/dist/cjs/guard/index.d.ts.map +1 -1
- package/dist/cjs/guard/index.js +13 -15
- package/dist/cjs/hook/useFormValidations.d.ts +2 -2
- package/dist/cjs/hook/useFormValidations.d.ts.map +1 -1
- package/dist/cjs/hook/useFormValidations.js +1 -3
- package/dist/cjs/type/config.d.ts +8 -8
- package/dist/cjs/type/config.d.ts.map +1 -1
- package/dist/cjs/type/field.d.ts +2 -6
- package/dist/cjs/type/field.d.ts.map +1 -1
- package/dist/cjs/type/form.d.ts +4 -4
- package/dist/cjs/type/form.d.ts.map +1 -1
- package/dist/cjs/type/test.d.ts +14 -0
- package/dist/cjs/type/test.d.ts.map +1 -0
- package/dist/cjs/type/test.js +14 -0
- package/dist/cjs/util/index.d.ts +5 -5
- package/dist/cjs/util/index.d.ts.map +1 -1
- package/dist/cjs/util/index.js +16 -22
- package/dist/cjs/validation/index.d.ts +2 -2
- package/dist/cjs/validation/index.d.ts.map +1 -1
- package/dist/cjs/validation/index.js +6 -7
- package/dist/es/components/FormBuilder.js +1 -1
- package/dist/es/components/FormCustom.d.ts +4 -5
- package/dist/es/components/FormCustom.d.ts.map +1 -1
- package/dist/es/components/FormCustom.js +1 -1
- package/dist/es/components/FormEntry.d.ts +2 -2
- package/dist/es/components/FormEntry.d.ts.map +1 -1
- package/dist/es/components/FormEntry.js +9 -8
- package/dist/es/components/FormRow.d.ts +4 -5
- package/dist/es/components/FormRow.d.ts.map +1 -1
- package/dist/es/components/FormRow.js +1 -1
- package/dist/es/components/FormSection.d.ts +4 -5
- package/dist/es/components/FormSection.d.ts.map +1 -1
- package/dist/es/components/FormSection.js +1 -1
- package/dist/es/guard/index.d.ts +5 -5
- package/dist/es/guard/index.d.ts.map +1 -1
- package/dist/es/guard/index.js +13 -15
- package/dist/es/hook/useFormValidations.d.ts +2 -2
- package/dist/es/hook/useFormValidations.d.ts.map +1 -1
- package/dist/es/hook/useFormValidations.js +1 -3
- package/dist/es/type/config.d.ts +8 -8
- package/dist/es/type/config.d.ts.map +1 -1
- package/dist/es/type/field.d.ts +2 -6
- package/dist/es/type/field.d.ts.map +1 -1
- package/dist/es/type/form.d.ts +4 -4
- package/dist/es/type/form.d.ts.map +1 -1
- package/dist/es/type/test.d.ts +14 -0
- package/dist/es/type/test.d.ts.map +1 -0
- package/dist/es/type/test.js +14 -0
- package/dist/es/util/index.d.ts +5 -5
- package/dist/es/util/index.d.ts.map +1 -1
- package/dist/es/util/index.js +16 -22
- package/dist/es/validation/index.d.ts +2 -2
- package/dist/es/validation/index.d.ts.map +1 -1
- package/dist/es/validation/index.js +6 -7
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
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:
|
|
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,
|
|
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 (
|
|
17
|
-
case
|
|
18
|
-
case
|
|
19
|
-
case
|
|
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 (
|
|
36
|
-
case
|
|
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
|
|
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
|
|
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
|
|
2
|
-
|
|
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:
|
|
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,
|
|
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
|
|
2
|
-
|
|
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:
|
|
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,
|
|
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.`);
|
package/dist/es/guard/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FormCustomConfig, FormEntryConfig,
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
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,
|
|
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"}
|
package/dist/es/guard/index.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
return
|
|
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.
|
|
8
|
-
const
|
|
9
|
-
return
|
|
7
|
+
exports.isFormRowConfig = isFormRowConfig;
|
|
8
|
+
const isFormSectionConfig = (config) => {
|
|
9
|
+
return config && config.type === "section";
|
|
10
10
|
};
|
|
11
|
-
exports.
|
|
12
|
-
const
|
|
13
|
-
return
|
|
11
|
+
exports.isFormSectionConfig = isFormSectionConfig;
|
|
12
|
+
const isFormCustomConfig = (config) => {
|
|
13
|
+
return config && config.type === "custom";
|
|
14
14
|
};
|
|
15
|
-
exports.
|
|
16
|
-
const
|
|
17
|
-
|
|
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.
|
|
19
|
+
exports.isFormFieldConfig = isFormFieldConfig;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FormConfig, FormError, FormErrors,
|
|
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:
|
|
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,
|
|
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);
|
package/dist/es/type/config.d.ts
CHANGED
|
@@ -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 |
|
|
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;
|
|
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"}
|
package/dist/es/type/field.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;
|
|
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,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAQxE,MAAM,WAAW,eAAe,CAC5B,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,WAAW,GAAG,OAAO,EACrB,YAAY,GAAG,GAAG;IAElB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;IAC5C,WAAW,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC;IAClC,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,WAAW,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;CACjD;AAED,MAAM,MAAM,mBAAmB,CAAC,WAAW,GAAG,OAAO,IAC/C,WAAW,GACX,CAAC,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,KAAK,WAAW,CAAC,CAAC;AAE/D,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,eAAe,IAAI,CAAC,SAAS;IACtE,WAAW,EAAE,MAAM,CAAC,CAAC;CACxB,GACK,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAC7B,KAAK,GACL,CAAC,GAAG;IAAE,WAAW,EAAE,CAAC,CAAA;CAAE,GAC1B,KAAK,CAAC"}
|
package/dist/es/type/form.d.ts
CHANGED
|
@@ -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:
|
|
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,EAAE,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;
|
|
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,EAAE,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);
|
package/dist/es/util/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { FormConfig, FormData, FormEntryConfig,
|
|
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
|
|
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
|
|
9
|
-
export declare const reduceFieldConfigs: <T extends Record<string | number, unknown>>(entries: readonly FormEntryConfig[], callbackFn: <F extends
|
|
10
|
-
export declare const someFieldConfigs: (entries: readonly FormEntryConfig[], callbackFn: <T extends
|
|
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":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../util/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,UAAU,EACV,QAAQ,EACR,eAAe,EACf,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;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"}
|
package/dist/es/util/index.js
CHANGED
|
@@ -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 (
|
|
55
|
-
case
|
|
56
|
-
case
|
|
57
|
-
case
|
|
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 {
|
|
59
57
|
...entry,
|
|
60
58
|
content: (0, exports.mapFieldConfigs)(entry.content, callbackFn),
|
|
@@ -65,14 +63,12 @@ callbackFn) => {
|
|
|
65
63
|
});
|
|
66
64
|
};
|
|
67
65
|
exports.mapFieldConfigs = mapFieldConfigs;
|
|
68
|
-
const reduceFieldConfigs = (entries,
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
-
callbackFn) => {
|
|
66
|
+
const reduceFieldConfigs = (entries, callbackFn) => {
|
|
71
67
|
return entries.reduce((acc, entry, index) => {
|
|
72
|
-
switch (
|
|
73
|
-
case
|
|
74
|
-
case
|
|
75
|
-
case
|
|
68
|
+
switch (true) {
|
|
69
|
+
case (0, guard_1.isFormRowConfig)(entry):
|
|
70
|
+
case (0, guard_1.isFormSectionConfig)(entry):
|
|
71
|
+
case (0, guard_1.isFormCustomConfig)(entry):
|
|
76
72
|
acc = { ...acc, ...(0, exports.reduceFieldConfigs)(entry.content, callbackFn) };
|
|
77
73
|
break;
|
|
78
74
|
default:
|
|
@@ -83,14 +79,12 @@ callbackFn) => {
|
|
|
83
79
|
}, {});
|
|
84
80
|
};
|
|
85
81
|
exports.reduceFieldConfigs = reduceFieldConfigs;
|
|
86
|
-
const someFieldConfigs = (entries,
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
-
callbackFn) => {
|
|
82
|
+
const someFieldConfigs = (entries, callbackFn) => {
|
|
89
83
|
return entries.some((entry, index) => {
|
|
90
|
-
switch (
|
|
91
|
-
case
|
|
92
|
-
case
|
|
93
|
-
case
|
|
84
|
+
switch (true) {
|
|
85
|
+
case (0, guard_1.isFormRowConfig)(entry):
|
|
86
|
+
case (0, guard_1.isFormSectionConfig)(entry):
|
|
87
|
+
case (0, guard_1.isFormCustomConfig)(entry):
|
|
94
88
|
return (0, exports.someFieldConfigs)(entry.content, callbackFn);
|
|
95
89
|
default:
|
|
96
90
|
return callbackFn(entry, index);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormConfig, FormData, FormErrors,
|
|
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 }:
|
|
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":"
|
|
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 (
|
|
18
|
-
case
|
|
19
|
-
case
|
|
20
|
-
case
|
|
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 };
|