@becklyn/forms 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +281 -0
- package/dist/cjs/components/FormBuilder.d.ts +3 -0
- package/dist/cjs/components/FormBuilder.d.ts.map +1 -0
- package/dist/cjs/components/FormBuilder.js +22 -0
- package/dist/cjs/components/FormCustom.d.ts +10 -0
- package/dist/cjs/components/FormCustom.d.ts.map +1 -0
- package/dist/cjs/components/FormCustom.js +13 -0
- package/dist/cjs/components/FormEntry.d.ts +10 -0
- package/dist/cjs/components/FormEntry.d.ts.map +1 -0
- package/dist/cjs/components/FormEntry.js +46 -0
- package/dist/cjs/components/FormField.d.ts +10 -0
- package/dist/cjs/components/FormField.d.ts.map +1 -0
- package/dist/cjs/components/FormField.js +79 -0
- package/dist/cjs/components/FormRow.d.ts +10 -0
- package/dist/cjs/components/FormRow.d.ts.map +1 -0
- package/dist/cjs/components/FormRow.js +13 -0
- package/dist/cjs/components/FormSection.d.ts +10 -0
- package/dist/cjs/components/FormSection.d.ts.map +1 -0
- package/dist/cjs/components/FormSection.js +13 -0
- package/dist/cjs/components/FormWatch.d.ts +8 -0
- package/dist/cjs/components/FormWatch.d.ts.map +1 -0
- package/dist/cjs/components/FormWatch.js +14 -0
- package/dist/cjs/condition/index.d.ts +3 -0
- package/dist/cjs/condition/index.d.ts.map +1 -0
- package/dist/cjs/condition/index.js +29 -0
- package/dist/cjs/context/FormProvider.d.ts +7 -0
- package/dist/cjs/context/FormProvider.d.ts.map +1 -0
- package/dist/cjs/context/FormProvider.js +24 -0
- package/dist/cjs/context/context.d.ts +15 -0
- package/dist/cjs/context/context.d.ts.map +1 -0
- package/dist/cjs/context/context.js +7 -0
- package/dist/cjs/context/data/FormDataProvider.d.ts +19 -0
- package/dist/cjs/context/data/FormDataProvider.d.ts.map +1 -0
- package/dist/cjs/context/data/FormDataProvider.js +39 -0
- package/dist/cjs/context/data/context.d.ts +13 -0
- package/dist/cjs/context/data/context.d.ts.map +1 -0
- package/dist/cjs/context/data/context.js +6 -0
- package/dist/cjs/context/data/index.d.ts +2 -0
- package/dist/cjs/context/data/index.d.ts.map +1 -0
- package/dist/cjs/context/data/index.js +2 -0
- package/dist/cjs/context/index.d.ts +4 -0
- package/dist/cjs/context/index.d.ts.map +1 -0
- package/dist/cjs/context/index.js +22 -0
- package/dist/cjs/guard/index.d.ts +6 -0
- package/dist/cjs/guard/index.d.ts.map +1 -0
- package/dist/cjs/guard/index.js +21 -0
- package/dist/cjs/hoc/withForm.d.ts +7 -0
- package/dist/cjs/hoc/withForm.d.ts.map +1 -0
- package/dist/cjs/hoc/withForm.js +14 -0
- package/dist/cjs/hoc/withFormData.d.ts +7 -0
- package/dist/cjs/hoc/withFormData.d.ts.map +1 -0
- package/dist/cjs/hoc/withFormData.js +14 -0
- package/dist/cjs/hook/useFormData.d.ts +5 -0
- package/dist/cjs/hook/useFormData.d.ts.map +1 -0
- package/dist/cjs/hook/useFormData.js +18 -0
- package/dist/cjs/hook/useFormErrors.d.ts +3 -0
- package/dist/cjs/hook/useFormErrors.d.ts.map +1 -0
- package/dist/cjs/hook/useFormErrors.js +14 -0
- package/dist/cjs/hook/useFormStore.d.ts +8 -0
- package/dist/cjs/hook/useFormStore.d.ts.map +1 -0
- package/dist/cjs/hook/useFormStore.js +26 -0
- package/dist/cjs/hook/useFormValidations.d.ts +9 -0
- package/dist/cjs/hook/useFormValidations.d.ts.map +1 -0
- package/dist/cjs/hook/useFormValidations.js +48 -0
- package/dist/cjs/hook/useRefEffect.d.ts +2 -0
- package/dist/cjs/hook/useRefEffect.d.ts.map +1 -0
- package/dist/cjs/hook/useRefEffect.js +10 -0
- package/dist/cjs/style/index.d.ts +7 -0
- package/dist/cjs/style/index.d.ts.map +1 -0
- package/dist/cjs/style/index.js +59 -0
- package/dist/cjs/type/common.d.ts +7 -0
- package/dist/cjs/type/common.d.ts.map +1 -0
- package/dist/cjs/type/common.js +2 -0
- package/dist/cjs/type/condition.d.ts +3 -0
- package/dist/cjs/type/condition.d.ts.map +1 -0
- package/dist/cjs/type/condition.js +2 -0
- package/dist/cjs/type/config.d.ts +18 -0
- package/dist/cjs/type/config.d.ts.map +1 -0
- package/dist/cjs/type/config.js +2 -0
- package/dist/cjs/type/extract.d.ts +25 -0
- package/dist/cjs/type/extract.d.ts.map +1 -0
- package/dist/cjs/type/extract.js +2 -0
- package/dist/cjs/type/field.d.ts +30 -0
- package/dist/cjs/type/field.d.ts.map +1 -0
- package/dist/cjs/type/field.js +2 -0
- package/dist/cjs/type/form.d.ts +30 -0
- package/dist/cjs/type/form.d.ts.map +1 -0
- package/dist/cjs/type/form.js +2 -0
- package/dist/cjs/type/index.d.ts +8 -0
- package/dist/cjs/type/index.d.ts.map +1 -0
- package/dist/cjs/type/index.js +23 -0
- package/dist/cjs/type/validation.d.ts +14 -0
- package/dist/cjs/type/validation.d.ts.map +1 -0
- package/dist/cjs/type/validation.js +2 -0
- package/dist/cjs/util/index.d.ts +11 -0
- package/dist/cjs/util/index.d.ts.map +1 -0
- package/dist/cjs/util/index.js +97 -0
- package/dist/cjs/validation/index.d.ts +4 -0
- package/dist/cjs/validation/index.d.ts.map +1 -0
- package/dist/cjs/validation/index.js +57 -0
- package/dist/es/components/FormBuilder.d.ts +3 -0
- package/dist/es/components/FormBuilder.d.ts.map +1 -0
- package/dist/es/components/FormBuilder.js +22 -0
- package/dist/es/components/FormCustom.d.ts +10 -0
- package/dist/es/components/FormCustom.d.ts.map +1 -0
- package/dist/es/components/FormCustom.js +13 -0
- package/dist/es/components/FormEntry.d.ts +10 -0
- package/dist/es/components/FormEntry.d.ts.map +1 -0
- package/dist/es/components/FormEntry.js +46 -0
- package/dist/es/components/FormField.d.ts +10 -0
- package/dist/es/components/FormField.d.ts.map +1 -0
- package/dist/es/components/FormField.js +78 -0
- package/dist/es/components/FormRow.d.ts +10 -0
- package/dist/es/components/FormRow.d.ts.map +1 -0
- package/dist/es/components/FormRow.js +13 -0
- package/dist/es/components/FormSection.d.ts +10 -0
- package/dist/es/components/FormSection.d.ts.map +1 -0
- package/dist/es/components/FormSection.js +13 -0
- package/dist/es/components/FormWatch.d.ts +8 -0
- package/dist/es/components/FormWatch.d.ts.map +1 -0
- package/dist/es/components/FormWatch.js +14 -0
- package/dist/es/condition/index.d.ts +3 -0
- package/dist/es/condition/index.d.ts.map +1 -0
- package/dist/es/condition/index.js +28 -0
- package/dist/es/context/FormProvider.d.ts +7 -0
- package/dist/es/context/FormProvider.d.ts.map +1 -0
- package/dist/es/context/FormProvider.js +27 -0
- package/dist/es/context/context.d.ts +15 -0
- package/dist/es/context/context.d.ts.map +1 -0
- package/dist/es/context/context.js +7 -0
- package/dist/es/context/data/FormDataProvider.d.ts +19 -0
- package/dist/es/context/data/FormDataProvider.d.ts.map +1 -0
- package/dist/es/context/data/FormDataProvider.js +30 -0
- package/dist/es/context/data/context.d.ts +13 -0
- package/dist/es/context/data/context.d.ts.map +1 -0
- package/dist/es/context/data/context.js +6 -0
- package/dist/es/context/data/index.d.ts +2 -0
- package/dist/es/context/data/index.d.ts.map +1 -0
- package/dist/es/context/data/index.js +2 -0
- package/dist/es/context/index.d.ts +4 -0
- package/dist/es/context/index.d.ts.map +1 -0
- package/dist/es/context/index.js +22 -0
- package/dist/es/guard/index.d.ts +6 -0
- package/dist/es/guard/index.d.ts.map +1 -0
- package/dist/es/guard/index.js +21 -0
- package/dist/es/hoc/withForm.d.ts +7 -0
- package/dist/es/hoc/withForm.d.ts.map +1 -0
- package/dist/es/hoc/withForm.js +14 -0
- package/dist/es/hoc/withFormData.d.ts +7 -0
- package/dist/es/hoc/withFormData.d.ts.map +1 -0
- package/dist/es/hoc/withFormData.js +14 -0
- package/dist/es/hook/useFormData.d.ts +5 -0
- package/dist/es/hook/useFormData.d.ts.map +1 -0
- package/dist/es/hook/useFormData.js +18 -0
- package/dist/es/hook/useFormErrors.d.ts +3 -0
- package/dist/es/hook/useFormErrors.d.ts.map +1 -0
- package/dist/es/hook/useFormErrors.js +14 -0
- package/dist/es/hook/useFormStore.d.ts +8 -0
- package/dist/es/hook/useFormStore.d.ts.map +1 -0
- package/dist/es/hook/useFormStore.js +26 -0
- package/dist/es/hook/useFormValidations.d.ts +9 -0
- package/dist/es/hook/useFormValidations.d.ts.map +1 -0
- package/dist/es/hook/useFormValidations.js +48 -0
- package/dist/es/hook/useRefEffect.d.ts +2 -0
- package/dist/es/hook/useRefEffect.d.ts.map +1 -0
- package/dist/es/hook/useRefEffect.js +10 -0
- package/dist/es/style/index.d.ts +7 -0
- package/dist/es/style/index.d.ts.map +1 -0
- package/dist/es/style/index.js +59 -0
- package/dist/es/type/common.d.ts +7 -0
- package/dist/es/type/common.d.ts.map +1 -0
- package/dist/es/type/common.js +2 -0
- package/dist/es/type/condition.d.ts +3 -0
- package/dist/es/type/condition.d.ts.map +1 -0
- package/dist/es/type/condition.js +2 -0
- package/dist/es/type/config.d.ts +18 -0
- package/dist/es/type/config.d.ts.map +1 -0
- package/dist/es/type/config.js +2 -0
- package/dist/es/type/extract.d.ts +25 -0
- package/dist/es/type/extract.d.ts.map +1 -0
- package/dist/es/type/extract.js +2 -0
- package/dist/es/type/field.d.ts +30 -0
- package/dist/es/type/field.d.ts.map +1 -0
- package/dist/es/type/field.js +2 -0
- package/dist/es/type/form.d.ts +30 -0
- package/dist/es/type/form.d.ts.map +1 -0
- package/dist/es/type/form.js +2 -0
- package/dist/es/type/index.d.ts +8 -0
- package/dist/es/type/index.d.ts.map +1 -0
- package/dist/es/type/index.js +23 -0
- package/dist/es/type/validation.d.ts +14 -0
- package/dist/es/type/validation.d.ts.map +1 -0
- package/dist/es/type/validation.js +2 -0
- package/dist/es/util/index.d.ts +11 -0
- package/dist/es/util/index.d.ts.map +1 -0
- package/dist/es/util/index.js +100 -0
- package/dist/es/validation/index.d.ts +4 -0
- package/dist/es/validation/index.d.ts.map +1 -0
- package/dist/es/validation/index.js +57 -0
- package/package.json +100 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../type/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACrB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACvB,GAAG,OAAO,CAAC;AAEZ,MAAM,MAAM,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,IAAI,MAAM,SAAS;IACxE,IAAI,EAAE,IAAI,CAAC;IACX,YAAY,CAAC,EAAE,MAAM,YAAY,CAAC;CACrC,GACK,YAAY,GACZ,KAAK,CAAC;AAGZ,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAClF,CAAC,EAAE,MAAM,CAAC,KACT,IAAI,GACH,CAAC,GACD,KAAK,CAAC;AAEZ,MAAM,MAAM,SAAS,CAAC,MAAM,SAAS,UAAU,EAAE,GAAG,GAAG,MAAM,IAAI,MAAM,SAAS,SAAS;IACrF,MAAM,KAAK;IACX,GAAG,MAAM,IAAI;CAChB,GACK,KAAK,SAAS;IAAE,OAAO,EAAE,MAAM,OAAO,CAAA;CAAE,GACpC,QAAQ,CACJ,mBAAmB,CACf,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,GAAG,CAAC,GACxC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,GAAG,CAAC,CAChD,CACJ,GACD,KAAK,SAAS;IAAE,IAAI,EAAE,MAAM,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,OAAO,CAAA;CAAE,GAE3E,OAAO,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,KAAK,GACzC,SAAS,CACL,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,EACzB,QAAQ,CACJ,mBAAmB,CACf;KACK,GAAG,IAAI,MAAM,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC;CAC9C,GAAG,GAAG,CACV,CACJ,CACJ,GACD,SAAS,CACL,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,EACzB,QAAQ,CACJ,mBAAmB,CACf;KACK,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC;CACxD,GAAG,GAAG,CACV,CACJ,CACJ,GACL,GAAG,GACT,GAAG,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FormFieldConditions } from "./condition";
|
|
2
|
+
import { FormData, FormInputFunc } from "./form";
|
|
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> {
|
|
9
|
+
type: Type;
|
|
10
|
+
name: string;
|
|
11
|
+
initialValue?: InitialValue;
|
|
12
|
+
conditions?: FormFieldConditions;
|
|
13
|
+
validationStrategy?: FormValidationStrategy;
|
|
14
|
+
validations?: readonly FieldValidations[];
|
|
15
|
+
columns?: number;
|
|
16
|
+
categories?: readonly string[];
|
|
17
|
+
valueFn?: (data: FormData) => any;
|
|
18
|
+
onInput?: FormInputFunc;
|
|
19
|
+
fieldConfig: FormFieldConfigFunc<FieldConfig>;
|
|
20
|
+
}
|
|
21
|
+
export type FormFieldConfigFunc<FieldConfig = unknown> = FieldConfig | ((props: {
|
|
22
|
+
value: any;
|
|
23
|
+
data: FormData;
|
|
24
|
+
}) => FieldConfig);
|
|
25
|
+
export type ResolveFieldConfigFunc<T extends FormFieldBasicConfig<any>> = T extends {
|
|
26
|
+
fieldConfig: infer U;
|
|
27
|
+
} ? U extends (...args: any[]) => any ? never : T & {
|
|
28
|
+
fieldConfig: U;
|
|
29
|
+
} : never;
|
|
30
|
+
//# sourceMappingURL=field.d.ts.map
|
|
@@ -0,0 +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;AAExE,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG,qBAAqB,SAAS;KAAG,CAAC,IAAI,QAAQ,GAAG,MAAM,CAAC;CAAE,GAClF,CAAC,GACD,oBAAoB,CAAC,aAAa,CAAC,CAAC;AAE1C,MAAM,WAAW,oBAAoB,CACjC,IAAI,SAAS,MAAM,EACnB,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,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS;IAChF,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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { JSXElementConstructor, PropsWithChildren, ReactNode } from "react";
|
|
2
|
+
import { FormFieldConfig, ResolveFieldConfigFunc } from "./field";
|
|
3
|
+
import { FormError } from "./validation";
|
|
4
|
+
export type FormData = Record<string, any>;
|
|
5
|
+
export interface FormBuilderComponents {
|
|
6
|
+
BuilderWrapper: JSXElementConstructor<PropsWithChildren>;
|
|
7
|
+
SectionWrapper: JSXElementConstructor<PropsWithChildren>;
|
|
8
|
+
RowWrapper: JSXElementConstructor<PropsWithChildren>;
|
|
9
|
+
FieldWrapper: JSXElementConstructor<PropsWithChildren<{
|
|
10
|
+
columns?: number;
|
|
11
|
+
}>>;
|
|
12
|
+
}
|
|
13
|
+
export interface FormBuilderChildrenProps {
|
|
14
|
+
value: any;
|
|
15
|
+
error: FormError | undefined;
|
|
16
|
+
onInput: (value: any) => void;
|
|
17
|
+
onBlur: () => void;
|
|
18
|
+
field: ResolveFieldConfigFunc<FormFieldConfig>;
|
|
19
|
+
}
|
|
20
|
+
export interface FormBuilderProps {
|
|
21
|
+
Components?: Partial<FormBuilderComponents>;
|
|
22
|
+
children(props: FormBuilderChildrenProps): ReactNode;
|
|
23
|
+
}
|
|
24
|
+
export interface FormInputFuncProps {
|
|
25
|
+
value: any;
|
|
26
|
+
field: FormFieldConfig;
|
|
27
|
+
previousData: FormData;
|
|
28
|
+
}
|
|
29
|
+
export type FormInputFunc = (props: FormInputFuncProps) => FormData;
|
|
30
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +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;IAC/B,KAAK,EAAE,GAAG,CAAC;IACX,KAAK,EAAE,eAAe,CAAC;IACvB,YAAY,EAAE,QAAQ,CAAC;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../type/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./condition"), exports);
|
|
19
|
+
__exportStar(require("./config"), exports);
|
|
20
|
+
__exportStar(require("./extract"), exports);
|
|
21
|
+
__exportStar(require("./field"), exports);
|
|
22
|
+
__exportStar(require("./form"), exports);
|
|
23
|
+
__exportStar(require("./validation"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FormData } from "./form";
|
|
2
|
+
export type FormValidationStrategy = "blur" | "input" | "manual";
|
|
3
|
+
export type FormError = string | boolean;
|
|
4
|
+
export type FormErrors = Record<string, FormError>;
|
|
5
|
+
export type FormFieldValidationFunction = (props: {
|
|
6
|
+
value: any;
|
|
7
|
+
data: FormData;
|
|
8
|
+
}) => boolean;
|
|
9
|
+
export type FormFieldValidation = boolean | RegExp | FormFieldValidationFunction;
|
|
10
|
+
export interface FieldValidations {
|
|
11
|
+
validation: FormFieldValidation;
|
|
12
|
+
message?: string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../type/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEjE,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAGnD,MAAM,MAAM,2BAA2B,GAAG,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,KAAK,OAAO,CAAC;AAE7F,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,MAAM,GAAG,2BAA2B,CAAC;AAEjF,MAAM,WAAW,gBAAgB;IAC7B,UAAU,EAAE,mBAAmB,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormConfig, FormData, FormEntryConfig, FormFieldBasicConfig, FormFieldConfig, ResolveFieldConfigFunc } from "../type";
|
|
2
|
+
export declare function eitherOr<const T>(config: T | false | undefined | null | 0 | ""): T;
|
|
3
|
+
export declare function eitherOr<const Either, const Or>(condition: boolean, either: Either, or: Or): Either | Or;
|
|
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"];
|
|
6
|
+
export declare const fieldsFromConfig: (config: FormConfig) => Record<string, FormFieldConfig>;
|
|
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;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,CAAC;AAEF,eAAO,MAAM,uBAAuB,WAAY,UAAU,KAAG,QAe5D,CAAC;AAEF,eAAO,MAAM,eAAe,YACf,UAAU,cAEP,CAAC,CAAC,SAAS,oBAAoB,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,KAChF,UAkBF,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,WAChE,SAAS,eAAe,EAAE,cAEvB,CAAC,CAAC,SAAS,oBAAoB,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,KACxF,CAeF,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAChB,SAAS,eAAe,EAAE,cAEvB,CAAC,CAAC,SAAS,oBAAoB,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,KACtF,OAWF,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.someFieldConfigs = exports.reduceFieldConfigs = exports.mapFieldConfigs = exports.initialValuesFromConfig = exports.fieldsFromConfig = exports.fieldConfigFromFormField = exports.createFormConfig = void 0;
|
|
7
|
+
exports.eitherOr = eitherOr;
|
|
8
|
+
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
9
|
+
function eitherOr(configOrCondition, either, or) {
|
|
10
|
+
if (typeof configOrCondition === "boolean") {
|
|
11
|
+
return configOrCondition ? either : or;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return configOrCondition;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const createFormConfig = (config) => (0, exports.mapFieldConfigs)(config, entry => entry);
|
|
18
|
+
exports.createFormConfig = createFormConfig;
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
const fieldConfigFromFormField = ({ name, fieldConfig }, data) => {
|
|
21
|
+
return typeof fieldConfig === "function"
|
|
22
|
+
? fieldConfig({ value: data[name], data })
|
|
23
|
+
: fieldConfig;
|
|
24
|
+
};
|
|
25
|
+
exports.fieldConfigFromFormField = fieldConfigFromFormField;
|
|
26
|
+
const fieldsFromConfig = (config) => {
|
|
27
|
+
return (0, exports.reduceFieldConfigs)(config, (acc, field) => {
|
|
28
|
+
acc[field.name] = field;
|
|
29
|
+
return acc;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.fieldsFromConfig = fieldsFromConfig;
|
|
33
|
+
const initialValuesFromConfig = (config) => {
|
|
34
|
+
return (0, exports.reduceFieldConfigs)(config, (acc, field) => {
|
|
35
|
+
if (field.initialValue !== undefined) {
|
|
36
|
+
if (field.onInput) {
|
|
37
|
+
acc = (0, lodash_merge_1.default)(acc, field.onInput({ field, value: field.initialValue, previousData: acc }));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
acc[field.name] = field.initialValue;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return acc;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
exports.initialValuesFromConfig = initialValuesFromConfig;
|
|
47
|
+
const mapFieldConfigs = (entries,
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
callbackFn) => {
|
|
50
|
+
return entries.flatMap((entry, index) => {
|
|
51
|
+
if (!entry) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
switch (entry.type) {
|
|
55
|
+
case "custom":
|
|
56
|
+
case "section":
|
|
57
|
+
case "row":
|
|
58
|
+
return Object.assign(Object.assign({}, entry), { content: (0, exports.mapFieldConfigs)(entry.content, callbackFn) });
|
|
59
|
+
default:
|
|
60
|
+
return callbackFn(entry, index);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
exports.mapFieldConfigs = mapFieldConfigs;
|
|
65
|
+
const reduceFieldConfigs = (entries,
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
callbackFn) => {
|
|
68
|
+
return entries.reduce((acc, entry, index) => {
|
|
69
|
+
switch (entry.type) {
|
|
70
|
+
case "custom":
|
|
71
|
+
case "section":
|
|
72
|
+
case "row":
|
|
73
|
+
acc = Object.assign(Object.assign({}, acc), (0, exports.reduceFieldConfigs)(entry.content, callbackFn));
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
callbackFn(acc, entry, index);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
return acc;
|
|
80
|
+
}, {});
|
|
81
|
+
};
|
|
82
|
+
exports.reduceFieldConfigs = reduceFieldConfigs;
|
|
83
|
+
const someFieldConfigs = (entries,
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
+
callbackFn) => {
|
|
86
|
+
return entries.some((entry, index) => {
|
|
87
|
+
switch (entry.type) {
|
|
88
|
+
case "custom":
|
|
89
|
+
case "section":
|
|
90
|
+
case "row":
|
|
91
|
+
return (0, exports.someFieldConfigs)(entry.content, callbackFn);
|
|
92
|
+
default:
|
|
93
|
+
return callbackFn(entry, index);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
exports.someFieldConfigs = someFieldConfigs;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FormConfig, FormData, FormErrors, FormFieldBasicConfig, FormFieldConfig } from "../type";
|
|
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;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleValidateField = exports.handleValidateConfig = void 0;
|
|
4
|
+
const condition_1 = require("../condition");
|
|
5
|
+
const handleValidateConfig = (config, fieldConfigs, data) => {
|
|
6
|
+
const errors = {};
|
|
7
|
+
config.forEach(entry => {
|
|
8
|
+
const entryErrors = handleValidateEntry(entry, fieldConfigs, data);
|
|
9
|
+
if (entryErrors && Object.keys(entryErrors).length) {
|
|
10
|
+
Object.assign(errors, entryErrors);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return errors;
|
|
14
|
+
};
|
|
15
|
+
exports.handleValidateConfig = handleValidateConfig;
|
|
16
|
+
const handleValidateEntry = (entry, fieldConfigs, data) => {
|
|
17
|
+
switch (entry.type) {
|
|
18
|
+
case "custom":
|
|
19
|
+
case "section":
|
|
20
|
+
case "row":
|
|
21
|
+
return (0, exports.handleValidateConfig)(entry.content, fieldConfigs, data);
|
|
22
|
+
default:
|
|
23
|
+
return (0, exports.handleValidateField)(entry, fieldConfigs, data);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const handleValidateField = (
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
{ name, validations, conditions, valueFn }, fieldConfigs, data) => {
|
|
29
|
+
if (!validations ||
|
|
30
|
+
(conditions && !(0, condition_1.fieldFulfillsConditions)({ conditions }, fieldConfigs, data))) {
|
|
31
|
+
return { [name]: false };
|
|
32
|
+
}
|
|
33
|
+
const value = valueFn ? valueFn(data) : data[name];
|
|
34
|
+
const error = validations.find(({ validation }) => {
|
|
35
|
+
switch (typeof validation) {
|
|
36
|
+
case "function":
|
|
37
|
+
return !validation({ value, data });
|
|
38
|
+
case "string":
|
|
39
|
+
return !new RegExp(validation).test(value);
|
|
40
|
+
default:
|
|
41
|
+
if (validation instanceof RegExp) {
|
|
42
|
+
return !validation.test(value);
|
|
43
|
+
}
|
|
44
|
+
else if (Array.isArray(value)) {
|
|
45
|
+
return value.length === 0;
|
|
46
|
+
}
|
|
47
|
+
else if (typeof value === "number") {
|
|
48
|
+
return isNaN(value);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return !value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return { [name]: error && error.message ? error.message : !!error };
|
|
56
|
+
};
|
|
57
|
+
exports.handleValidateField = handleValidateField;
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormBuilder = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const context_1 = require("../context/data/context");
|
|
7
|
+
const guard_1 = require("../guard");
|
|
8
|
+
const style_1 = require("../style");
|
|
9
|
+
const FormEntry_1 = require("./FormEntry");
|
|
10
|
+
const DefaultComponents = {
|
|
11
|
+
BuilderWrapper: style_1.DefaultBuilderWrapper,
|
|
12
|
+
SectionWrapper: style_1.DefaultSectionWrapper,
|
|
13
|
+
RowWrapper: style_1.DefaultRowWrapper,
|
|
14
|
+
FieldWrapper: style_1.DefaultFieldWrapper,
|
|
15
|
+
};
|
|
16
|
+
exports.FormBuilder = (0, react_1.memo)(({ Components = DefaultComponents, children }) => {
|
|
17
|
+
const { BuilderWrapper } = Components;
|
|
18
|
+
const { config } = (0, react_1.useContext)(context_1.FormConfigContext);
|
|
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 : "")))) }));
|
|
21
|
+
});
|
|
22
|
+
exports.FormBuilder.displayName = "FormBuilder";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FormBuilderComponents, FormBuilderProps, FormCustomConfig } from "../type";
|
|
3
|
+
interface FormCustomProps {
|
|
4
|
+
Components: FormBuilderComponents;
|
|
5
|
+
custom: FormCustomConfig;
|
|
6
|
+
children: FormBuilderProps["children"];
|
|
7
|
+
}
|
|
8
|
+
export declare const FormCustom: React.FC<FormCustomProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=FormCustom.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FormCustom = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const FormEntry_1 = require("./FormEntry");
|
|
10
|
+
const FormCustom = ({ Components, custom, children }) => {
|
|
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
|
+
};
|
|
13
|
+
exports.FormCustom = FormCustom;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FormBuilderComponents, FormBuilderProps, FormEntryConfig } from "../type";
|
|
3
|
+
interface FormEntryProps {
|
|
4
|
+
Components: FormBuilderComponents;
|
|
5
|
+
entry: FormEntryConfig;
|
|
6
|
+
children: FormBuilderProps["children"];
|
|
7
|
+
}
|
|
8
|
+
export declare const FormEntry: React.FC<FormEntryProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=FormEntry.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormEntry = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const condition_1 = require("../condition");
|
|
7
|
+
const context_1 = require("../context");
|
|
8
|
+
const util_1 = require("../util");
|
|
9
|
+
const FormCustom_1 = require("./FormCustom");
|
|
10
|
+
const FormField_1 = require("./FormField");
|
|
11
|
+
const FormRow_1 = require("./FormRow");
|
|
12
|
+
const FormSection_1 = require("./FormSection");
|
|
13
|
+
const FormEntry = ({ Components, entry, children }) => {
|
|
14
|
+
const { data, fieldConfigs } = (0, context_1.useForm)();
|
|
15
|
+
const getHasChildren = (0, react_1.useCallback)((formData) => {
|
|
16
|
+
switch (entry.type) {
|
|
17
|
+
case "custom":
|
|
18
|
+
case "section":
|
|
19
|
+
case "row":
|
|
20
|
+
return (0, util_1.someFieldConfigs)([entry], field => (0, condition_1.fieldFulfillsConditions)(field, fieldConfigs, formData));
|
|
21
|
+
default:
|
|
22
|
+
return (0, condition_1.fieldFulfillsConditions)(entry, fieldConfigs, formData);
|
|
23
|
+
}
|
|
24
|
+
}, [entry, fieldConfigs]);
|
|
25
|
+
const [hasChildren, setHasChildren] = (0, react_1.useState)(getHasChildren(data.get()));
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
const remove = data.subscribe(() => {
|
|
28
|
+
setHasChildren(getHasChildren(data.get()));
|
|
29
|
+
});
|
|
30
|
+
return () => remove();
|
|
31
|
+
}, [getHasChildren, data]);
|
|
32
|
+
if (!hasChildren) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
switch (entry.type) {
|
|
36
|
+
case "custom":
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)(FormCustom_1.FormCustom, { custom: entry, Components: Components, children: children }));
|
|
38
|
+
case "section":
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)(FormSection_1.FormSection, { section: entry, Components: Components, children: children }));
|
|
40
|
+
case "row":
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(FormRow_1.FormRow, { row: entry, Components: Components, children: children }));
|
|
42
|
+
default:
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(FormField_1.FormField, { field: entry, Components: Components, children: children }));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.FormEntry = FormEntry;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FormBuilderComponents, FormBuilderProps, FormFieldConfig } from "../type";
|
|
3
|
+
interface FormFieldProps {
|
|
4
|
+
Components: FormBuilderComponents;
|
|
5
|
+
field: FormFieldConfig;
|
|
6
|
+
children: FormBuilderProps["children"];
|
|
7
|
+
}
|
|
8
|
+
export declare const FormField: React.FC<FormFieldProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=FormField.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormField = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const context_1 = require("../context");
|
|
7
|
+
const useFormData_1 = require("../hook/useFormData");
|
|
8
|
+
const useFormErrors_1 = require("../hook/useFormErrors");
|
|
9
|
+
const FormField = ({ Components, field, children }) => {
|
|
10
|
+
const { editData, validationStrategy: contextValidationStrategy, validateField, onInput, } = (0, context_1.useForm)();
|
|
11
|
+
const { name, columns, conditions, validations, valueFn, validationStrategy: fieldValidationStrategy, onInput: onFieldInput, fieldConfig: fieldConfigFunc, } = field;
|
|
12
|
+
const validationStrategy = (0, react_1.useMemo)(() => [fieldValidationStrategy, contextValidationStrategy], [fieldValidationStrategy, contextValidationStrategy]);
|
|
13
|
+
const hasValueFn = !!valueFn;
|
|
14
|
+
const hasConditions = !!conditions && Object.keys(conditions).length > 0;
|
|
15
|
+
const hasFieldConfigFunc = typeof fieldConfigFunc === "function";
|
|
16
|
+
const hasValidationFunc = !!validations && validations.some(({ validation }) => typeof validation === "function");
|
|
17
|
+
const rerenderWithData = hasValueFn || hasConditions || hasFieldConfigFunc || hasValidationFunc;
|
|
18
|
+
const [data, setStore, getStore] = (0, useFormData_1.useFormData)(rerenderWithData ? store => store : store => store[name]);
|
|
19
|
+
const [fieldError] = (0, useFormErrors_1.useFormErrors)(store => store[name]);
|
|
20
|
+
const value = rerenderWithData ? data[name] : data;
|
|
21
|
+
const normalizedValue = valueFn ? valueFn(data) : value;
|
|
22
|
+
const fieldConfig = hasFieldConfigFunc
|
|
23
|
+
? fieldConfigFunc({ value: normalizedValue, data })
|
|
24
|
+
: fieldConfigFunc;
|
|
25
|
+
const handleInput = (0, react_1.useCallback)(value => {
|
|
26
|
+
let normalizedValue;
|
|
27
|
+
if (onFieldInput) {
|
|
28
|
+
normalizedValue = onFieldInput({
|
|
29
|
+
value,
|
|
30
|
+
field,
|
|
31
|
+
previousData: getStore(),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else if (onInput) {
|
|
35
|
+
normalizedValue = onInput({
|
|
36
|
+
value,
|
|
37
|
+
field,
|
|
38
|
+
previousData: getStore(),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
normalizedValue = { [field.name]: value };
|
|
43
|
+
}
|
|
44
|
+
editData.set(normalizedValue);
|
|
45
|
+
setStore(normalizedValue);
|
|
46
|
+
},
|
|
47
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
|
+
[field, setStore, getStore, onFieldInput, onInput]);
|
|
49
|
+
const handleBlur = (0, react_1.useCallback)(() => {
|
|
50
|
+
if (!validations || !validationStrategy.includes("blur")) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
validateField(field);
|
|
54
|
+
}, [field, validations, validationStrategy, validateField]);
|
|
55
|
+
const fieldInputError = (() => {
|
|
56
|
+
if (!validations || !validationStrategy.includes("input")) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const editValue = editData.get()[field.name];
|
|
60
|
+
if (editValue === undefined) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
return validateField(field) ?? undefined;
|
|
64
|
+
})();
|
|
65
|
+
const childrenProps = {
|
|
66
|
+
value: normalizedValue,
|
|
67
|
+
error: fieldError || fieldInputError,
|
|
68
|
+
onInput: handleInput,
|
|
69
|
+
onBlur: handleBlur,
|
|
70
|
+
field: { ...field, fieldConfig },
|
|
71
|
+
};
|
|
72
|
+
const { FieldWrapper } = Components;
|
|
73
|
+
if (!FieldWrapper) {
|
|
74
|
+
throw new Error("No field component found");
|
|
75
|
+
}
|
|
76
|
+
return (0, jsx_runtime_1.jsx)(FieldWrapper, { columns: columns, children: children(childrenProps) });
|
|
77
|
+
};
|
|
78
|
+
exports.FormField = FormField;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FormBuilderComponents, FormBuilderProps, FormRowConfig } from "../type";
|
|
3
|
+
interface FormRowProps {
|
|
4
|
+
Components: FormBuilderComponents;
|
|
5
|
+
row: FormRowConfig;
|
|
6
|
+
children: FormBuilderProps["children"];
|
|
7
|
+
}
|
|
8
|
+
export declare const FormRow: React.FC<FormRowProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=FormRow.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormRow = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const FormEntry_1 = require("./FormEntry");
|
|
6
|
+
const FormRow = ({ Components, row, children }) => {
|
|
7
|
+
const { RowWrapper } = Components;
|
|
8
|
+
if (!RowWrapper) {
|
|
9
|
+
throw new Error(`No row component found.`);
|
|
10
|
+
}
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(RowWrapper, { children: row.content.map((entry, index) => ((0, jsx_runtime_1.jsx)(FormEntry_1.FormEntry, { entry: entry, Components: Components, children: children }, index))) }));
|
|
12
|
+
};
|
|
13
|
+
exports.FormRow = FormRow;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FormBuilderComponents, FormBuilderProps, FormSectionConfig } from "../type";
|
|
3
|
+
interface FormSectionProps {
|
|
4
|
+
Components: FormBuilderComponents;
|
|
5
|
+
section: FormSectionConfig;
|
|
6
|
+
children: FormBuilderProps["children"];
|
|
7
|
+
}
|
|
8
|
+
export declare const FormSection: React.FC<FormSectionProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=FormSection.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormSection = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const FormEntry_1 = require("./FormEntry");
|
|
6
|
+
const FormSection = ({ Components, section, children }) => {
|
|
7
|
+
const { SectionWrapper } = Components;
|
|
8
|
+
if (!SectionWrapper) {
|
|
9
|
+
throw new Error(`No section component found.`);
|
|
10
|
+
}
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(SectionWrapper, { children: section.content.map((entry, index) => ((0, jsx_runtime_1.jsx)(FormEntry_1.FormEntry, { entry: entry, Components: Components, children: children }, index))) }));
|
|
12
|
+
};
|
|
13
|
+
exports.FormSection = FormSection;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormWatch.d.ts","sourceRoot":"","sources":["../../../components/FormWatch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGzC,UAAU,mBAAmB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,SAAS,CAAC;CACvC;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAInD,CAAC"}
|