@bolttech/form-engine 3.0.0-beta.16 → 3.0.0-beta.18

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/index.esm.js CHANGED
@@ -1616,8 +1616,13 @@ $$1({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign }
1616
1616
  assign: assign
1617
1617
  });
1618
1618
 
1619
- let context;
1620
1619
  const FormGroupContext = /*#__PURE__*/createContext({});
1620
+ /**
1621
+ * context interface to be used isolated or with the context provider
1622
+ *
1623
+ * @param {TFormContextProvider} param context parameters
1624
+ * @returns {TFormContext}
1625
+ */
1621
1626
  const IsolatedContext = ({
1622
1627
  debugMode: _debugMode = false,
1623
1628
  mappers
@@ -1653,10 +1658,10 @@ const IsolatedContext = ({
1653
1658
  const printFormGroupInstance = () => {
1654
1659
  console.log(formGroupInstance.current.printFormGroupInstance());
1655
1660
  };
1656
- const submitMultipleFormsByIndex = indexes => {
1661
+ function submitMultipleFormsByIndex(indexes) {
1657
1662
  return formGroupInstance.current.submitMultipleFormsByIndex(indexes);
1658
- };
1659
- const contextValue = {
1663
+ }
1664
+ return {
1660
1665
  addFormWithIndex,
1661
1666
  addForm,
1662
1667
  getForm,
@@ -1668,8 +1673,13 @@ const IsolatedContext = ({
1668
1673
  debugMode: _debugMode,
1669
1674
  active: false
1670
1675
  };
1671
- return contextValue;
1672
1676
  };
1677
+ /**
1678
+ * context provider to wrap form-engine adapter elements
1679
+ *
1680
+ * @param {PropsWithChildren<TFormContextProvider>} param context parameters
1681
+ * @returns {ReactElement}
1682
+ */
1673
1683
  const FormGroupContextProvider = ({
1674
1684
  children,
1675
1685
  mappers,
@@ -1691,9 +1701,15 @@ const FormGroupContextProvider = ({
1691
1701
  }), children]
1692
1702
  });
1693
1703
  };
1704
+ /**
1705
+ * FormGroup context hook to handle context or isolated context implementations
1706
+ *
1707
+ * @param {TFormContextProvider} props form group context parameters
1708
+ * @returns {TFormContext}
1709
+ */
1694
1710
  const useFormGroupContext = props => {
1695
- context = useContext(FormGroupContext);
1696
- if (Object.keys(context).length === 0) {
1711
+ const context = useContext(FormGroupContext);
1712
+ if (Object.keys(context).length === 0 && props) {
1697
1713
  return IsolatedContext({
1698
1714
  debugMode: props.debugMode,
1699
1715
  mappers: props.mappers
@@ -1702,6 +1718,12 @@ const useFormGroupContext = props => {
1702
1718
  return context;
1703
1719
  };
1704
1720
 
1721
+ /**
1722
+ * Renders the React element defined on the mappers configuration
1723
+ *
1724
+ * @param param component props, field instance and children to render
1725
+ * @returns
1726
+ */
1705
1727
  const FieldWrapperComponentRender = ({
1706
1728
  props,
1707
1729
  fieldInstance,
@@ -1722,6 +1744,13 @@ const FieldWrapperComponentRender = ({
1722
1744
  children: `failed to render field ${fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.name} with componentName:${(_c = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _c === void 0 ? void 0 : _c.componentName}, please check mappers`
1723
1745
  });
1724
1746
  };
1747
+ /**
1748
+ * Base field Wrapper to render the component with the necessary configurations from the schema
1749
+ * and mapper configuration
1750
+ *
1751
+ * @param {TFieldWrapperProps} param FieldWrapper params
1752
+ * @returns {ReactElement}
1753
+ */
1725
1754
  const FieldWrapper = ({
1726
1755
  name,
1727
1756
  formIndex,
@@ -1731,37 +1760,40 @@ const FieldWrapper = ({
1731
1760
  }) => {
1732
1761
  var _a;
1733
1762
  const localContext = useFormGroupContext({});
1763
+ /**
1764
+ * picks the right context prioritizing the context passed as prop
1765
+ */
1734
1766
  const {
1735
1767
  formGroupInstance,
1736
1768
  debugMode
1737
1769
  } = useMemo(() => context ? context : localContext, [context, localContext]);
1738
- const fieldInstance = (_a = formGroupInstance.getForm({
1770
+ const fieldInstance = useRef((_a = formGroupInstance.getForm({
1739
1771
  key: formIndex
1740
1772
  })) === null || _a === void 0 ? void 0 : _a.getField({
1741
1773
  key: name
1742
- });
1743
- const [valueState, setValueState] = useState(fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.stateValue);
1774
+ })).current;
1775
+ const [valueState, setValueState] = useState((fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.stateValue) || {});
1744
1776
  const [state, setState] = useState({
1745
1777
  visibility: (fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.visibility) || true,
1746
- props: (fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.props) || props,
1747
- apiResponse: fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.api
1778
+ props: (fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.props) || props
1748
1779
  });
1780
+ /**
1781
+ * handles the mounting and unmounting logic onto the field instance
1782
+ */
1749
1783
  useEffect(() => {
1750
1784
  fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mountField({
1751
1785
  valueSubscription: value => {
1752
1786
  setValueState(value);
1753
1787
  },
1754
1788
  propsSubscription: ({
1755
- errors,
1756
1789
  visibility,
1757
- apiResponse,
1758
- props
1790
+ props,
1791
+ errors
1759
1792
  }) => {
1760
1793
  setState(prev => Object.assign(Object.assign({}, prev), {
1761
- errors,
1762
1794
  visibility,
1763
- apiResponse,
1764
- props
1795
+ props,
1796
+ errors
1765
1797
  }));
1766
1798
  }
1767
1799
  });
@@ -1769,17 +1801,27 @@ const FieldWrapper = ({
1769
1801
  fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.destroyField();
1770
1802
  };
1771
1803
  }, []);
1804
+ /**
1805
+ * handles the value change onto the field instance
1806
+ */
1772
1807
  const handleChange = useCallback(event => {
1773
1808
  fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.emitValue({
1774
1809
  value: event,
1775
1810
  event: 'ON_FIELD_CHANGE'
1776
1811
  });
1777
1812
  }, []);
1813
+ /**
1814
+ * handles the event emission onto the field instance
1815
+ */
1778
1816
  const handleEvent = useCallback(event => {
1779
1817
  fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.emitEvents({
1780
1818
  event
1781
1819
  });
1782
1820
  }, []);
1821
+ /**
1822
+ * handles the mappers configuration to bind the event submission callback
1823
+ * to the corresponding prop defined on the mappers
1824
+ */
1783
1825
  const mapProps = useMemo(() => {
1784
1826
  var _a;
1785
1827
  const events = (_a = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _a === void 0 ? void 0 : _a.events;
@@ -1792,13 +1834,6 @@ const FieldWrapper = ({
1792
1834
  if (events === null || events === void 0 ? void 0 : events.onKeyDown) props[events.onKeyDown] = () => handleEvent('ON_FIELD_KEYDOWN');
1793
1835
  return props;
1794
1836
  }, []);
1795
- const mapValue = useMemo(() => {
1796
- var _a;
1797
- const events = (_a = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _a === void 0 ? void 0 : _a.events;
1798
- return (events === null || events === void 0 ? void 0 : events.setValue) ? {
1799
- [events.setValue]: valueState
1800
- } : {};
1801
- }, [valueState]);
1802
1837
  return (state === null || state === void 0 ? void 0 : state.visibility) ? jsxs(Fragment, {
1803
1838
  children: [debugMode && jsxs(Fragment, {
1804
1839
  children: [jsx("b", {
@@ -1809,13 +1844,22 @@ const FieldWrapper = ({
1809
1844
  children: name
1810
1845
  }), jsx("br", {}), jsx("hr", {})]
1811
1846
  }), jsx(FieldWrapperComponentRender, {
1812
- props: Object.assign(Object.assign(Object.assign({}, mapProps), state.props), mapValue),
1847
+ props: Object.assign(Object.assign(Object.assign(Object.assign({}, mapProps), state.props), state.errors), valueState),
1813
1848
  fieldInstance: fieldInstance,
1814
1849
  children: children && children
1815
1850
  })]
1816
1851
  }) : jsx(Fragment, {});
1817
1852
  };
1818
1853
 
1854
+ /**
1855
+ * recursive function to transform form fields from a form instance into
1856
+ * a react component tree
1857
+ *
1858
+ * @param {Map<string,IFormField>} param.fields form instance field Map
1859
+ * @param {string} param.prevPath previous field path to track the tree branch creation
1860
+ * @param {string} param.formIndex form index to aid field identification onto the FieldWrapper
1861
+ * @returns {ReactNode}
1862
+ */
1819
1863
  const BuildTree = ({
1820
1864
  fields,
1821
1865
  prevPath,
@@ -1838,6 +1882,12 @@ const BuildTree = ({
1838
1882
  }, fieldName);
1839
1883
  });
1840
1884
  };
1885
+ /**
1886
+ * function to transform AsFormField elements onto a JSON schema
1887
+ *
1888
+ * @param param.children ReactNode children elements
1889
+ * @returns {IComponentSchema[] | null | undefined}
1890
+ */
1841
1891
  const BuildAsFormFieldTree = ({
1842
1892
  children
1843
1893
  }) => {
@@ -1890,6 +1940,9 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1890
1940
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1891
1941
  };
1892
1942
 
1943
+ /**
1944
+ * events mapping to aid function callback binding
1945
+ */
1893
1946
  const eventsMapping = {
1894
1947
  ON_FIELD_CHANGE: 'onChange',
1895
1948
  ON_FIELD_BLUR: 'onBlur',
@@ -1901,6 +1954,9 @@ const eventsMapping = {
1901
1954
  ON_FIELD_CLICK: 'onClick'
1902
1955
  };
1903
1956
 
1957
+ /**
1958
+ * Hook to register events callback functions
1959
+ */
1904
1960
  const useForm = _a => {
1905
1961
  var {
1906
1962
  id
@@ -1909,10 +1965,18 @@ const useForm = _a => {
1909
1965
  const {
1910
1966
  formGroupInstance
1911
1967
  } = useFormGroupContext({});
1968
+ /**
1969
+ * reference to store all updated callback functions rerendered by props change
1970
+ */
1912
1971
  const callbackRefs = useRef(rest);
1913
1972
  useEffect(() => {
1914
1973
  callbackRefs.current = rest;
1915
1974
  }, [rest]);
1975
+ /**
1976
+ * handle function call after the debounce occurs on the form instance field event
1977
+ * subject in order to call the most updated function with the updated function
1978
+ * reference to avoid events get outdated values
1979
+ */
1916
1980
  useEffect(() => {
1917
1981
  var _a;
1918
1982
  const callback = payload => {
@@ -1932,6 +1996,11 @@ const useForm = _a => {
1932
1996
  return;
1933
1997
  };
1934
1998
 
1999
+ /**
2000
+ *
2001
+ * @param {TFormProps} param form properties initializor
2002
+ * @returns {ReactElement}
2003
+ */
1935
2004
  const Form = ({
1936
2005
  schema,
1937
2006
  index,
@@ -1960,6 +2029,9 @@ const Form = ({
1960
2029
  } = useFormGroupContext({});
1961
2030
  const [tree, setTree] = useState();
1962
2031
  const schemaIndex = useMemo(() => index || (schema === null || schema === void 0 ? void 0 : schema.index) || 'defaultChange', [index, schema]);
2032
+ /**
2033
+ * logic to initialize the form instance and it's removal
2034
+ */
1963
2035
  useEffect(() => {
1964
2036
  if (schemaIndex === 'defaultChange') {
1965
2037
  console.warn('please, add an unique id to the form, otherwise multiple forms will break');
@@ -1988,6 +2060,11 @@ const Form = ({
1988
2060
  });
1989
2061
  };
1990
2062
  }, []);
2063
+ /**
2064
+ * logic to transform AsFormFields onto JSON schema
2065
+ * and JSON schema onto FieldWrappers, refreshes when
2066
+ * the react tree changes it's children
2067
+ */
1991
2068
  useEffect(() => {
1992
2069
  var _a;
1993
2070
  const schema = BuildAsFormFieldTree({
@@ -2007,11 +2084,17 @@ const Form = ({
2007
2084
  setTree(buildTree);
2008
2085
  }
2009
2086
  }, [children]);
2087
+ /**
2088
+ * iVars change tracker to update iVars onto form instance
2089
+ */
2010
2090
  useEffect(() => {
2011
2091
  if (iVars) getForm({
2012
2092
  key: index
2013
2093
  }).iVars = iVars;
2014
2094
  }, [iVars]);
2095
+ /**
2096
+ * hook usage to keep event bindings updated on callback functions passed as props
2097
+ */
2015
2098
  useForm({
2016
2099
  id: schemaIndex,
2017
2100
  onApiResponse,
@@ -2066,10 +2149,17 @@ const Form = ({
2066
2149
  });
2067
2150
  };
2068
2151
 
2152
+ /**
2153
+ * Component wrapper to aid building schemas with react without writting a JSON schema
2154
+ * along with BuildAsFormFieldTree inside a Form component, FieldWrapper gets this props
2155
+ * to build the component as it does with a JSON schema, this component only works inside
2156
+ * the Form component
2157
+ *
2158
+ * @param {TAsFormFieldProps} props JSON schema props
2159
+ * @returns {ReactNode}
2160
+ */
2069
2161
  const AsFormField = props => {
2070
- return jsx(Fragment, {
2071
- children: props.children
2072
- });
2162
+ return props.children;
2073
2163
  };
2074
2164
 
2075
2165
  var wellKnownSymbol$1 = wellKnownSymbol$8;
@@ -2318,9 +2408,24 @@ $({ target: 'RegExp', proto: true, forced: /./.exec !== exec }, {
2318
2408
  exec: exec
2319
2409
  });
2320
2410
 
2411
+ /**
2412
+ * Component Wrapper to render form fields without the Form component, gets additional formId and mapper since
2413
+ * it won't rely on them and needs to be manually declared
2414
+ *
2415
+ * @param {TAsFormFieldBuilderProps} props JSON schema props along with FieldWrapper props and mapper props
2416
+ * @returns {ReactElement}
2417
+ */
2321
2418
  const AsFormFieldBuilder = props => {
2322
2419
  const context = useFormGroupContext({});
2420
+ /**
2421
+ * state to track the field instance creation process
2422
+ */
2323
2423
  const [mounted, setMounted] = useState(false);
2424
+ /**
2425
+ * initializer to create or add a form instance to the formGroup by it's formId
2426
+ * and add the field to the form instance
2427
+ * Also has the logic to remove it once this element is removed
2428
+ */
2324
2429
  useEffect(() => {
2325
2430
  var _a;
2326
2431
  if (!((_a = context.formGroupInstance) === null || _a === void 0 ? void 0 : _a.forms.has(props.formIndex))) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine",
3
- "version": "3.0.0-beta.16",
3
+ "version": "3.0.0-beta.18",
4
4
  "description": "A react adapter for bolttech form engine",
5
5
  "module": "./index.esm.js",
6
6
  "type": "module",
7
7
  "main": "./index.esm.js",
8
8
  "dependencies": {
9
- "@bolttech/form-engine-core": "0.0.1-beta.7",
9
+ "@bolttech/form-engine-core": "0.0.1-beta.9",
10
10
  "react": "18.2.0"
11
11
  },
12
12
  "peerDependencies": {}
@@ -1,4 +1,13 @@
1
- import { IComponentSchema } from '@bolttech/form-engine-core';
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 { IComponentSchema } from '@bolttech/form-engine-core';
2
+ import { PropsWithChildren } from 'react';
3
+ /**
4
+ * AsFormField props, inherits all schema field implementation except the children
5
+ * property, that will be a ReactNode
6
+ * @see {@link IComponentSchema}
7
+ */
8
+ type TAsFormFieldProps = PropsWithChildren<Omit<IComponentSchema, 'children'>>;
9
+ export type { TAsFormFieldProps };
@@ -1,7 +1,11 @@
1
- import { IComponentSchema, TMapper } from '@bolttech/form-engine-core';
2
- import { ElementType, PropsWithChildren, ReactElement } from 'react';
3
- import { TFieldWrapper } from '../../types';
4
- declare const AsFormFieldBuilder: (props: PropsWithChildren<Omit<IComponentSchema, 'children' | 'component'> & Required<TFieldWrapper> & {
5
- mapper: TMapper<ElementType>;
6
- }>) => ReactElement;
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;
7
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,9 +1,11 @@
1
- import { PropsWithChildren, ReactElement } from 'react';
2
- import { TFormContext } from '../../context/FormGroupContext';
3
- import { TFieldWrapper } from '../../types';
4
- declare const FieldWrapper: ({ name, formIndex, children, props, context, }: PropsWithChildren<TFieldWrapper & {
5
- name: string;
6
- props?: Record<string, unknown> | undefined;
7
- context?: TFormContext | null | undefined;
8
- }>) => 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;
9
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,5 +1,9 @@
1
- import { TFormEntry } from '@bolttech/form-engine-core';
2
- import { PropsWithChildren } from 'react';
3
- import { TEventsCallbackProps } from '../../types';
4
- declare const Form: ({ schema, index, initialValues, iVars, action, method, onSubmit, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, children, }: PropsWithChildren<Omit<TFormEntry, 'mappers'> & TEventsCallbackProps>) => 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;
5
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,30 +1,19 @@
1
- import { FormCore, TFormCore, TFormGroup, TFormValues, TMapper } from '@bolttech/form-engine-core';
2
- import { ElementType, PropsWithChildren, ReactElement } from 'react';
3
- type TFormContext = {
4
- addFormWithIndex: (index: string) => void;
5
- addForm: (payload: {
6
- key: string;
7
- formInstance: TFormCore;
8
- }) => void;
9
- getForm: (payload: {
10
- key: string;
11
- }) => FormCore | undefined;
12
- removeForm: (payload: {
13
- key: string;
14
- }) => void;
15
- formGroupInstance: TFormGroup;
16
- mappers?: TMapper<ElementType>[];
17
- printFormGroupInstance: () => void;
18
- submitMultipleFormsByIndex: (indexes: string[]) => TFormValues;
19
- debugMode: boolean;
20
- active: boolean;
21
- };
22
- type TFormContextProvider = {
23
- mappers?: TMapper<ElementType>[];
24
- debugMode?: boolean;
25
- };
1
+ import { PropsWithChildren, ReactElement } from 'react';
2
+ import { TFormContext, TFormContextProvider } from './FormGroupContext.type';
26
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
+ */
27
10
  declare const FormGroupContextProvider: ({ children, mappers, debugMode, }: PropsWithChildren<TFormContextProvider>) => ReactElement;
28
- declare const useFormGroupContext: (props: TFormContextProvider) => 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;
29
18
  export { FormGroupContext, FormGroupContextProvider, useFormGroupContext };
30
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,10 +1,25 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { IFormField, IComponentSchema } 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
+ */
3
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
  }) => IComponentSchema[] | null | undefined;
@@ -1,4 +1,7 @@
1
1
  import { TEvents } from '@bolttech/form-engine-core';
2
- import { eventProps } from '../types';
3
- declare const eventsMapping: Partial<Record<TEvents, eventProps>>;
2
+ import { TEventProps } from '../types';
3
+ /**
4
+ * events mapping to aid function callback binding
5
+ */
6
+ declare const eventsMapping: Partial<Record<TEvents, TEventProps>>;
4
7
  export { eventsMapping };
@@ -1,6 +1,6 @@
1
- import { TEventsCallbackProps } from '../types';
2
- import { TFieldEvent } from '@bolttech/form-engine-core';
3
- declare const useForm: ({ id, ...rest }: {
4
- id: string;
5
- } & Partial<Record<import("../types").eventProps, ((payload: TFieldEvent) => void) | null | undefined>>) => void;
1
+ import { TUseFormProps } from './useForm.type';
2
+ /**
3
+ * Hook to register events callback functions
4
+ */
5
+ declare const useForm: ({ id, ...rest }: TUseFormProps) => void;
6
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 };