@bolttech/form-engine 3.0.0-beta.2 → 3.0.0-beta.20
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 +264 -212
- package/index.esm.js +1471 -312
- package/package.json +6 -30
- package/src/components/AsFormField/AsFormField.d.ts +12 -3
- package/src/components/AsFormField/AsFormField.type.d.ts +9 -0
- package/src/components/AsFormFieldBuilder/AsFormFieldBuilder.d.ts +11 -0
- package/src/components/AsFormFieldBuilder/AsFormFieldBuilder.type.d.ts +16 -0
- package/src/components/FieldWrapper/FieldWrapper.d.ts +10 -3
- package/src/components/FieldWrapper/FieldWrapper.type.d.ts +28 -0
- package/src/components/Form/Form.d.ts +8 -3
- package/src/components/Form/Form.type.d.ts +11 -0
- package/src/components/index.d.ts +3 -2
- package/src/context/FormGroupContext.d.ts +16 -24
- package/src/context/FormGroupContext.type.d.ts +46 -0
- package/src/generators/formBuilder.d.ts +20 -5
- package/src/helpers/helpers.d.ts +7 -0
- package/src/hooks/useForm.d.ts +6 -0
- package/src/hooks/useForm.type.d.ts +12 -0
- package/src/types/index.d.ts +15 -42
package/package.json
CHANGED
|
@@ -1,37 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.20",
|
|
4
4
|
"description": "A react adapter for bolttech form engine",
|
|
5
|
+
"module": "./index.esm.js",
|
|
5
6
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
".": {
|
|
8
|
-
"types": "./src/index.esm.d.ts",
|
|
9
|
-
"import": "./index.esm.js",
|
|
10
|
-
"require": "./index.esm.js",
|
|
11
|
-
"default": "./index.esm.js"
|
|
12
|
-
},
|
|
13
|
-
"./types": "./types.js"
|
|
14
|
-
},
|
|
15
|
-
"typesVersions": {
|
|
16
|
-
"*": {
|
|
17
|
-
"@bolttech/form-engine/*": [
|
|
18
|
-
"./src/**/*"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
},
|
|
7
|
+
"main": "./index.esm.js",
|
|
22
8
|
"dependencies": {
|
|
23
|
-
"@
|
|
9
|
+
"@bolttech/form-engine-core": "0.0.1-beta.11",
|
|
10
|
+
"react": "18.2.0"
|
|
24
11
|
},
|
|
25
|
-
"
|
|
26
|
-
"bolttech",
|
|
27
|
-
"edirect",
|
|
28
|
-
"form-builder",
|
|
29
|
-
"react",
|
|
30
|
-
"forms",
|
|
31
|
-
"low-code"
|
|
32
|
-
],
|
|
33
|
-
"author": "bolttech",
|
|
34
|
-
"license": "ISC",
|
|
35
|
-
"module": "./index.esm.js",
|
|
36
|
-
"main": "./index.esm.js"
|
|
12
|
+
"peerDependencies": {}
|
|
37
13
|
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { TAsFormFieldProps } from './AsFormField.type';
|
|
3
|
+
/**
|
|
4
|
+
* Component wrapper to aid building schemas with react without writting a JSON schema
|
|
5
|
+
* along with BuildAsFormFieldTree inside a Form component, FieldWrapper gets this props
|
|
6
|
+
* to build the component as it does with a JSON schema, this component only works inside
|
|
7
|
+
* the Form component
|
|
8
|
+
*
|
|
9
|
+
* @param {TAsFormFieldProps} props JSON schema props
|
|
10
|
+
* @returns {ReactNode}
|
|
11
|
+
*/
|
|
12
|
+
declare const AsFormField: (props: TAsFormFieldProps) => ReactNode;
|
|
4
13
|
export default AsFormField;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IComponentSchemaAsFormField } from '@bolttech/form-engine-core';
|
|
2
|
+
import { ElementType, PropsWithChildren } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* AsFormField props, inherits all schema field implementation except the children
|
|
5
|
+
* property and has mappers property to pass a custom component, that will be a ReactNode
|
|
6
|
+
* @see {@link IComponentSchemaWithMapper}
|
|
7
|
+
*/
|
|
8
|
+
type TAsFormFieldProps = PropsWithChildren<Omit<IComponentSchemaAsFormField<ElementType>, 'children'>>;
|
|
9
|
+
export type { TAsFormFieldProps };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { TAsFormFieldBuilderProps } from './AsFormFieldBuilder.type';
|
|
3
|
+
/**
|
|
4
|
+
* Component Wrapper to render form fields without the Form component, gets additional formId and mapper since
|
|
5
|
+
* it won't rely on them and needs to be manually declared
|
|
6
|
+
*
|
|
7
|
+
* @param {TAsFormFieldBuilderProps} props JSON schema props along with FieldWrapper props and mapper props
|
|
8
|
+
* @returns {ReactElement}
|
|
9
|
+
*/
|
|
10
|
+
declare const AsFormFieldBuilder: (props: TAsFormFieldBuilderProps) => ReactElement;
|
|
11
|
+
export default AsFormFieldBuilder;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IComponentSchema, TMapper } from '@bolttech/form-engine-core';
|
|
2
|
+
import { ElementType, PropsWithChildren } from 'react';
|
|
3
|
+
import { TFieldWrapper } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* AsFormField props, inherits all schema field implementation except the children
|
|
6
|
+
* property, that will be a ReactNode
|
|
7
|
+
* also gets the formIndex for form identification and the mapper to build the component
|
|
8
|
+
* @property {TMapper} mapper element mapper to use
|
|
9
|
+
* @see {@link TMapper}
|
|
10
|
+
* @see {@link IComponentSchema}
|
|
11
|
+
* @see {@link TFieldWrapper}
|
|
12
|
+
*/
|
|
13
|
+
type TAsFormFieldBuilderProps = PropsWithChildren<Omit<IComponentSchema, 'children' | 'component' | 'name'> & Required<TFieldWrapper> & {
|
|
14
|
+
mapper: TMapper<ElementType>;
|
|
15
|
+
}>;
|
|
16
|
+
export type { TAsFormFieldBuilderProps };
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { TFieldWrapperProps } from './FieldWrapper.type';
|
|
3
|
+
/**
|
|
4
|
+
* Base field Wrapper to render the component with the necessary configurations from the schema
|
|
5
|
+
* and mapper configuration
|
|
6
|
+
*
|
|
7
|
+
* @param {TFieldWrapperProps} param FieldWrapper params
|
|
8
|
+
* @returns {ReactElement}
|
|
9
|
+
*/
|
|
10
|
+
declare const FieldWrapper: ({ name, formIndex, children, props, context, }: TFieldWrapperProps) => ReactElement;
|
|
4
11
|
export default FieldWrapper;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { TFieldWrapper } from '../../types';
|
|
3
|
+
import { TFormContext } from '../../context/FormGroupContext';
|
|
4
|
+
import { FormField } from '@bolttech/form-engine-core';
|
|
5
|
+
/**
|
|
6
|
+
* Represents the props for a field wrapper component, including children.
|
|
7
|
+
*
|
|
8
|
+
* @property {Record<string, unknown>} [props] - Additional properties for the field.
|
|
9
|
+
* @property {TFormContext | null} [context] - The context of the form, which may be null.
|
|
10
|
+
* @property {React.ReactNode} children - The child elements of the component.
|
|
11
|
+
* @see {@link TFieldWrapper}
|
|
12
|
+
*/
|
|
13
|
+
type TFieldWrapperProps = PropsWithChildren<TFieldWrapper & {
|
|
14
|
+
props?: Record<string, unknown>;
|
|
15
|
+
context?: TFormContext | null;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Represents the props for rendering a field wrapper component, including children.
|
|
19
|
+
*
|
|
20
|
+
* @property {Record<string, unknown>} props - Additional properties for the field.
|
|
21
|
+
* @property {FormField} [fieldInstance] - The instance of the form field, which may be undefined.
|
|
22
|
+
* @property {React.ReactNode} children - The child elements of the component.
|
|
23
|
+
*/
|
|
24
|
+
type TFieldWrapperComponentRenderProps = PropsWithChildren<{
|
|
25
|
+
props: Record<string, unknown>;
|
|
26
|
+
fieldInstance?: FormField;
|
|
27
|
+
}>;
|
|
28
|
+
export type { TFieldWrapperProps, TFieldWrapperComponentRenderProps };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { TFormProps } from './Form.type';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {TFormProps} param form properties initializor
|
|
6
|
+
* @returns {ReactElement}
|
|
7
|
+
*/
|
|
8
|
+
declare const Form: ({ schema, index, initialValues, iVars, action, method, onSubmit, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, children, }: TFormProps) => ReactElement;
|
|
4
9
|
export default Form;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TFormEntry } from '@bolttech/form-engine-core';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
import { TEventsCallbackProps } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Form props, inherits the form instance constructor implementation except the mapper
|
|
6
|
+
* along with all event callback register props shared with other implementations
|
|
7
|
+
* @see {@link TFormEntry}
|
|
8
|
+
* @see {@link TEventsCallbackProps}
|
|
9
|
+
*/
|
|
10
|
+
type TFormProps = PropsWithChildren<Omit<TFormEntry, 'mappers'> & TEventsCallbackProps>;
|
|
11
|
+
export type { TFormProps };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { default as Form } from './Form/Form';
|
|
2
|
+
export { default as AsFormField } from './AsFormField/AsFormField';
|
|
3
|
+
export { default as AsFormFieldBuilder } from './AsFormFieldBuilder/AsFormFieldBuilder';
|
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
type TFormContext = {
|
|
4
|
-
addForm: (payload: {
|
|
5
|
-
key: string;
|
|
6
|
-
formInstance: TFormCore;
|
|
7
|
-
}) => void;
|
|
8
|
-
getForm: (payload: {
|
|
9
|
-
key: string;
|
|
10
|
-
}) => FormCore | undefined;
|
|
11
|
-
removeForm: (payload: {
|
|
12
|
-
key: string;
|
|
13
|
-
}) => void;
|
|
14
|
-
formGroupInstance: TFormGroup;
|
|
15
|
-
mappers: TMapper<ElementType>[];
|
|
16
|
-
printFormGroupInstance: () => void;
|
|
17
|
-
submitMultipleFormsByIndex: (indexes: string[]) => TFormValues;
|
|
18
|
-
debugMode: boolean;
|
|
19
|
-
};
|
|
20
|
-
type TFormContextProvider = {
|
|
21
|
-
mappers: TMapper<ElementType>[];
|
|
22
|
-
debugMode?: boolean;
|
|
23
|
-
};
|
|
1
|
+
import { PropsWithChildren, ReactElement } from 'react';
|
|
2
|
+
import { TFormContext, TFormContextProvider } from './FormGroupContext.type';
|
|
24
3
|
declare const FormGroupContext: import("react").Context<TFormContext>;
|
|
4
|
+
/**
|
|
5
|
+
* context provider to wrap form-engine adapter elements
|
|
6
|
+
*
|
|
7
|
+
* @param {PropsWithChildren<TFormContextProvider>} param context parameters
|
|
8
|
+
* @returns {ReactElement}
|
|
9
|
+
*/
|
|
25
10
|
declare const FormGroupContextProvider: ({ children, mappers, debugMode, }: PropsWithChildren<TFormContextProvider>) => ReactElement;
|
|
26
|
-
|
|
11
|
+
/**
|
|
12
|
+
* FormGroup context hook to handle context or isolated context implementations
|
|
13
|
+
*
|
|
14
|
+
* @param {TFormContextProvider} props form group context parameters
|
|
15
|
+
* @returns {TFormContext}
|
|
16
|
+
*/
|
|
17
|
+
declare const useFormGroupContext: (props?: TFormContextProvider) => TFormContext;
|
|
27
18
|
export { FormGroupContext, FormGroupContextProvider, useFormGroupContext };
|
|
19
|
+
export type { TFormContext };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FormCore, TFormCore, TFormGroup, TFormValues, TMapper } from '@bolttech/form-engine-core';
|
|
2
|
+
import { ElementType } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the context for managing forms within a form group.
|
|
5
|
+
*
|
|
6
|
+
* @property {function(string): void} addFormWithIndex - Adds a form to the form group by its index.
|
|
7
|
+
* @property {function({ key: string, formInstance: TFormCore }): void} addForm - Adds a form to the form group using a payload containing the key and form instance.
|
|
8
|
+
* @property {function({ key: string }): (FormCore | undefined)} getForm - Retrieves a form from the form group using a payload containing the key.
|
|
9
|
+
* @property {function({ key: string }): void} removeForm - Removes a form from the form group using a payload containing the key.
|
|
10
|
+
* @property {TFormGroup} formGroupInstance - The instance of the form group.
|
|
11
|
+
* @property {TMapper<ElementType>[]} [mappers] - Optional array of mappers for elements.
|
|
12
|
+
* @property {function(): void} printFormGroupInstance - Prints the form group instance.
|
|
13
|
+
* @property {function(string[]): TFormValues} submitMultipleFormsByIndex - Submits multiple forms by their indexes and returns the form values.
|
|
14
|
+
* @property {boolean} debugMode - Indicates if debug mode is active.
|
|
15
|
+
* @property {boolean} active - Indicates if the form context is active.
|
|
16
|
+
*/
|
|
17
|
+
type TFormContext = {
|
|
18
|
+
addFormWithIndex: (index: string) => void;
|
|
19
|
+
addForm: (payload: {
|
|
20
|
+
key: string;
|
|
21
|
+
formInstance: TFormCore;
|
|
22
|
+
}) => void;
|
|
23
|
+
getForm: (payload: {
|
|
24
|
+
key: string;
|
|
25
|
+
}) => FormCore | undefined;
|
|
26
|
+
removeForm: (payload: {
|
|
27
|
+
key: string;
|
|
28
|
+
}) => void;
|
|
29
|
+
formGroupInstance: TFormGroup;
|
|
30
|
+
mappers?: TMapper<ElementType>[];
|
|
31
|
+
printFormGroupInstance: () => void;
|
|
32
|
+
submitMultipleFormsByIndex: <T>(indexes: string[]) => TFormValues<T>;
|
|
33
|
+
debugMode: boolean;
|
|
34
|
+
active: boolean;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Represents the props for a form context provider.
|
|
38
|
+
*
|
|
39
|
+
* @property {TMapper<ElementType>[]} [mappers] - Optional array of mappers for elements.
|
|
40
|
+
* @property {boolean} [debugMode] - Optional flag indicating if debug mode should be enabled.
|
|
41
|
+
*/
|
|
42
|
+
type TFormContextProvider = {
|
|
43
|
+
mappers?: TMapper<ElementType>[];
|
|
44
|
+
debugMode?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type { TFormContext, TFormContextProvider };
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { IFormField,
|
|
3
|
-
|
|
1
|
+
import { ElementType, ReactNode } from 'react';
|
|
2
|
+
import { IFormField, IComponentSchemaAsFormField } from '@bolttech/form-engine-core';
|
|
3
|
+
/**
|
|
4
|
+
* recursive function to transform form fields from a form instance into
|
|
5
|
+
* a react component tree
|
|
6
|
+
*
|
|
7
|
+
* @param {Map<string,IFormField>} param.fields form instance field Map
|
|
8
|
+
* @param {string} param.prevPath previous field path to track the tree branch creation
|
|
9
|
+
* @param {string} param.formIndex form index to aid field identification onto the FieldWrapper
|
|
10
|
+
* @returns {ReactNode}
|
|
11
|
+
*/
|
|
12
|
+
declare const BuildTree: ({ fields, prevPath, formIndex, }: {
|
|
4
13
|
fields: Map<string, IFormField>;
|
|
5
14
|
prevPath?: string | undefined;
|
|
6
|
-
|
|
15
|
+
formIndex: string;
|
|
7
16
|
}) => ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* function to transform AsFormField elements onto a JSON schema
|
|
19
|
+
*
|
|
20
|
+
* @param param.children ReactNode children elements
|
|
21
|
+
* @returns {IComponentSchema[] | null | undefined}
|
|
22
|
+
*/
|
|
8
23
|
declare const BuildAsFormFieldTree: ({ children, }: {
|
|
9
24
|
children?: ReactNode;
|
|
10
|
-
}) =>
|
|
25
|
+
}) => IComponentSchemaAsFormField<ElementType>[] | null | undefined;
|
|
11
26
|
export { BuildTree, BuildAsFormFieldTree };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TEventsCallbackProps } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the properties for the useForm hook, including an ID and event callback properties.
|
|
4
|
+
*
|
|
5
|
+
* @property {string} id - The unique identifier for the form.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link TEventsCallbackProps}
|
|
8
|
+
*/
|
|
9
|
+
type TUseFormProps = {
|
|
10
|
+
id: string;
|
|
11
|
+
} & TEventsCallbackProps;
|
|
12
|
+
export type { TUseFormProps };
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,47 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ElementType } from 'react';
|
|
1
|
+
import { TFieldEvent } from '@bolttech/form-engine-core';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
* Represents the wrapper for a form field, including the component,
|
|
6
|
-
* event handlers, and other properties related to form management.
|
|
3
|
+
* Represents a field wrapper containing the name of the field and its index in the form.
|
|
7
4
|
*
|
|
8
|
-
* @property {string}
|
|
9
|
-
* @property {
|
|
10
|
-
* @property {(event: unknown) => unknown} [valueChangeEvent] - Function to handle value change events.
|
|
11
|
-
* @property {string} formKey - The key of the form.
|
|
12
|
-
* @property {string} [onBlur] - Function to handle the blur event.
|
|
13
|
-
* @property {string} [onChange] - Function to handle the change event.
|
|
14
|
-
* @property {string} [onFocus] - Function to handle the focus event.
|
|
15
|
-
* @property {string} [onClick] - Function to handle the click event.
|
|
16
|
-
* @property {string} [onKeyUp] - Function to handle the keyup event.
|
|
17
|
-
* @property {string} [onKeyDown] - Function to handle the keydown event.
|
|
18
|
-
* @property {unknown} [onValue] - The current value of the field.
|
|
19
|
-
* @property {string} [onErrorMessage] - error message prop name to set message string
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const fieldWrapper: TFieldWrapper = {
|
|
24
|
-
* index: '1',
|
|
25
|
-
* Component: MyComponent,
|
|
26
|
-
* valueChangeEvent: (event) => {
|
|
27
|
-
* const newValue = (event as React.ChangeEvent<HTMLInputElement>).target.value;
|
|
28
|
-
* return newValue;
|
|
29
|
-
* },
|
|
30
|
-
* formKey: 'myForm',
|
|
31
|
-
* onBlur: 'handleBlur',
|
|
32
|
-
* onChange: 'handleChange',
|
|
33
|
-
* onFocus: 'handleFocus',
|
|
34
|
-
* onClick: 'handleClick',
|
|
35
|
-
* onKeyUp: 'handleKeyUp',
|
|
36
|
-
* onKeyDown: 'handleKeyDown',
|
|
37
|
-
* onValue: 'value'
|
|
38
|
-
* };
|
|
39
|
-
* ```
|
|
5
|
+
* @property {string} name - The name of the field.
|
|
6
|
+
* @property {string} formIndex - The index of the field within the form.
|
|
40
7
|
*/
|
|
41
8
|
type TFieldWrapper = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
formKey: string;
|
|
45
|
-
events?: TComponentPropsMapping;
|
|
9
|
+
name: string;
|
|
10
|
+
formIndex: string;
|
|
46
11
|
};
|
|
47
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Represents the possible event properties for form fields callbacks.
|
|
14
|
+
*/
|
|
15
|
+
type TEventProps = 'onChange' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'onMount' | 'onApiResponse' | 'onClick' | 'onSubmit';
|
|
16
|
+
/**
|
|
17
|
+
* Represents a mapping of event properties to their corresponding callback functions.
|
|
18
|
+
*/
|
|
19
|
+
type TEventsCallbackProps = Partial<Record<TEventProps, ((payload: TFieldEvent) => void) | null | undefined>>;
|
|
20
|
+
export { TFieldWrapper, TEventProps, TEventsCallbackProps };
|