@bolttech/form-engine 3.0.0-beta.4 → 3.0.0-beta.40

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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine",
3
- "version": "3.0.0-beta.4",
3
+ "version": "3.0.0-beta.40",
4
4
  "description": "A react adapter for bolttech form engine",
5
- "dependencies": {
6
- "rxjs": "^7.8.1",
7
- "react": "18.2.0"
8
- },
9
5
  "module": "./index.esm.js",
10
6
  "type": "module",
11
7
  "main": "./index.esm.js",
8
+ "dependencies": {
9
+ "@bolttech/form-engine-core": "0.0.1-beta.28",
10
+ "react": "18.2.0"
11
+ },
12
12
  "peerDependencies": {}
13
13
  }
@@ -1,4 +1,13 @@
1
- import { IComponentSchema } from '../../core/index.d';
2
- import { PropsWithChildren, ReactElement } from 'react';
3
- declare const AsFormField: (props: PropsWithChildren<Omit<IComponentSchema, 'children'>>) => ReactElement;
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 { PropsWithChildren, ReactElement } from 'react';
2
- import { TFieldWrapper } from '../../types';
3
- declare const FieldWrapper: ({ index, Component, formKey, children, events, }: PropsWithChildren<TFieldWrapper>) => ReactElement;
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 { TFormEntry } from '../../core/index.d';
2
- import { PropsWithChildren } from 'react';
3
- declare const Form: ({ schema, index, initialValues, iVars, action, method, onSubmit, onData, children, }: PropsWithChildren<Omit<TFormEntry, 'mappers'>>) => import("react/jsx-runtime").JSX.Element;
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 * from './Form/Form';
2
- export * from './AsFormField/AsFormField';
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 { FormCore, TFormCore, TFormGroup, TFormValues, TMapper } from '../core/index.d';
2
- import { ElementType, PropsWithChildren, ReactElement } from 'react';
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
- declare const useFormGroupContext: () => TFormContext;
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, 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[]) => void;
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, IComponentSchema } from '../core/index.d';
3
- declare const BuildTree: ({ fields, prevPath, formKey, }: {
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
- formKey: string;
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
- }) => IComponentSchema[] | null | undefined;
25
+ }) => IComponentSchemaAsFormField<ElementType>[] | null | undefined;
11
26
  export { BuildTree, BuildAsFormFieldTree };
@@ -0,0 +1,7 @@
1
+ import { TEvents } from '@bolttech/form-engine-core';
2
+ import { TEventProps } from '../types';
3
+ /**
4
+ * events mapping to aid function callback binding
5
+ */
6
+ declare const eventsMapping: Partial<Record<TEvents, TEventProps>>;
7
+ export { eventsMapping };
@@ -0,0 +1,7 @@
1
+ import { TValueChangeEvent } from '@bolttech/form-engine-core';
2
+ declare const defaultChangeEvent: TValueChangeEvent;
3
+ declare const checkedChangeEvent: TValueChangeEvent;
4
+ declare const valueChangeEvent: TValueChangeEvent;
5
+ declare const datepickerChangeEvent: TValueChangeEvent;
6
+ declare const dropdownChangeEvent: TValueChangeEvent;
7
+ export { defaultChangeEvent, checkedChangeEvent, valueChangeEvent, datepickerChangeEvent, dropdownChangeEvent, };
@@ -0,0 +1,2 @@
1
+ export { default as useForm } from './useForm/useForm';
2
+ export { default as useFormGroup } from './useFormGroup/useFormGroup';
@@ -0,0 +1,6 @@
1
+ import { TUseFormProps } from './useForm.type';
2
+ /**
3
+ * Hook to register events callback functions
4
+ */
5
+ declare const useForm: ({ id, onData, onSubmit, ...rest }: TUseFormProps) => void;
6
+ export default useForm;
@@ -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 };
@@ -0,0 +1,10 @@
1
+ import { TFormValues } from '@bolttech/form-engine-core';
2
+ declare const useFormGroup: ({ ids, onData, }: {
3
+ ids: string[];
4
+ onData: (payload: Record<string, {
5
+ formId: string;
6
+ formField: string;
7
+ values?: TFormValues<Record<string, unknown>>;
8
+ }>) => void;
9
+ }) => void;
10
+ export default useFormGroup;
package/src/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './components';
2
+ export * from './hooks';
2
3
  export * from './context/FormGroupContext';
3
4
  export * from './types';
5
+ export * from './helpers/mapper';
@@ -1,47 +1,30 @@
1
- import { TComponentPropsMapping } from '../core/index.d';
2
- import { ElementType } from 'react';
1
+ import { TFieldEvent, TFormValues } from '@bolttech/form-engine-core';
3
2
  /**
4
- * @type TFieldWrapper
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} index - The index of the field in the form.
9
- * @property {ElementType} Component - The component to be rendered.
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
- index: string;
43
- Component: ElementType;
44
- formKey: string;
45
- events?: TComponentPropsMapping;
9
+ name: string;
10
+ formIndex: string;
11
+ };
12
+ /**
13
+ * Represents the possible event properties for form fields callbacks.
14
+ */
15
+ type TEventProps = 'onChange' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'onMount' | 'onApiResponse' | 'onClick';
16
+ /**
17
+ * Represents the content inside onData payload action.
18
+ */
19
+ type TFormData<T> = {
20
+ field: string;
21
+ data: TFormValues<T>;
22
+ };
23
+ /**
24
+ * Represents a mapping of event properties to their corresponding callback functions.
25
+ */
26
+ type TEventsCallbackProps = Partial<Record<TEventProps, ((payload: TFieldEvent) => void) | null | undefined>> & {
27
+ onData?: <T>(payload: TFormData<T>) => void;
28
+ onSubmit?: <T>(payload: TFormValues<T>) => void;
46
29
  };
47
- export { TFieldWrapper };
30
+ export { TFieldWrapper, TEventProps, TEventsCallbackProps, TFormData };