@bolttech/form-engine 3.0.0-beta.25 → 3.0.0-beta.27

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 CHANGED
@@ -310,7 +310,6 @@ And this will give you the following properties in addition to the native ones o
310
310
  | masks | TSchemaMasks | Allows you to display the value of the masked component by events |
311
311
  | clearFields | TSchemaClearFields | Will clear target fields in case they do not pass with the specified validations |
312
312
  | api | TSchemaApi | Allows you to make api calls using events emitted by the component. |
313
- | errorMessages | TErrorMessages | Field error messages in case any validation fails |
314
313
  | filter | TSchemaValidation | Filters the component value based on a validation. |
315
314
  | formatters | TSchemaFormatters | Allows you to format the value that the field will receive for each event issuance |
316
315
  | visibilityConditions | TSchemaVisibilityConditions | Allows you to specify the conditions a given field will be visible what will run when this field meets the specified life-cycle |
@@ -355,16 +354,14 @@ In the following example `asFormField` hooks are used to create `Component` fiel
355
354
  ]
356
355
  }
357
356
  validations={{
358
- config: {
357
+ methods: {
359
358
  callback: (data) => {
360
- return {
361
- fail: data === '10/10/1000',
362
- };
363
- },
359
+ return data === '10/10/1000';
360
+ }
364
361
  },
365
- events: ['ON_FIELD_BLUR']
362
+ eventMessages: { ON_FIELD_BLUR: [ 'callback' ] },
363
+ messages: { callback: 'ERRRO' }
366
364
  }}
367
- errorMessages={{ callback: 'ERRRO' }}
368
365
  />
369
366
  </FormGroupContextProvider>;
370
367
  }
package/index.esm.js CHANGED
@@ -2387,9 +2387,11 @@ const eventsMapping = {
2387
2387
  */
2388
2388
  const useForm = _a => {
2389
2389
  var {
2390
- id
2390
+ id,
2391
+ onData,
2392
+ onSubmit
2391
2393
  } = _a,
2392
- rest = __rest(_a, ["id"]);
2394
+ rest = __rest(_a, ["id", "onData", "onSubmit"]);
2393
2395
  const {
2394
2396
  formGroupInstance
2395
2397
  } = useFormGroupContext({});
@@ -2400,6 +2402,16 @@ const useForm = _a => {
2400
2402
  useEffect(() => {
2401
2403
  callbackRefs.current = rest;
2402
2404
  }, [rest]);
2405
+ const formValuesCallbackRefs = useRef({
2406
+ onData,
2407
+ onSubmit
2408
+ });
2409
+ useEffect(() => {
2410
+ formValuesCallbackRefs.current = {
2411
+ onData,
2412
+ onSubmit
2413
+ };
2414
+ }, [onData, onSubmit]);
2403
2415
  /**
2404
2416
  * handle function call after the debounce occurs on the form instance field event
2405
2417
  * subject in order to call the most updated function with the updated function
@@ -2421,6 +2433,31 @@ const useForm = _a => {
2421
2433
  });
2422
2434
  return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
2423
2435
  }, []);
2436
+ useEffect(() => {
2437
+ var _a, _b;
2438
+ const dataCallback = payload => {
2439
+ var _a, _b;
2440
+ if (formValuesCallbackRefs.current.onData) {
2441
+ (_b = (_a = formValuesCallbackRefs.current).onData) === null || _b === void 0 ? void 0 : _b.call(_a, payload);
2442
+ }
2443
+ };
2444
+ const dataSub = (_a = formGroupInstance.getForm({
2445
+ key: id
2446
+ })) === null || _a === void 0 ? void 0 : _a.subscribeData(dataCallback);
2447
+ const submitCallback = payload => {
2448
+ var _a, _b;
2449
+ if (formValuesCallbackRefs.current.onSubmit) {
2450
+ (_b = (_a = formValuesCallbackRefs.current).onSubmit) === null || _b === void 0 ? void 0 : _b.call(_a, payload);
2451
+ }
2452
+ };
2453
+ const submitSub = (_b = formGroupInstance.getForm({
2454
+ key: id
2455
+ })) === null || _b === void 0 ? void 0 : _b.subscribeOnSubmit(submitCallback);
2456
+ return () => {
2457
+ dataSub === null || dataSub === void 0 ? void 0 : dataSub.unsubscribe();
2458
+ submitSub === null || submitSub === void 0 ? void 0 : submitSub.unsubscribe();
2459
+ };
2460
+ }, []);
2424
2461
  return;
2425
2462
  };
2426
2463
 
@@ -2471,8 +2508,6 @@ const Form = ({
2471
2508
  action: action || (schema === null || schema === void 0 ? void 0 : schema.action),
2472
2509
  method: method || (schema === null || schema === void 0 ? void 0 : schema.method),
2473
2510
  index: schemaIndex,
2474
- onSubmit,
2475
- onData,
2476
2511
  mappers
2477
2512
  });
2478
2513
  addForm({
@@ -2550,7 +2585,9 @@ const Form = ({
2550
2585
  onFocus,
2551
2586
  onKeyDown,
2552
2587
  onKeyUp,
2553
- onMount
2588
+ onMount,
2589
+ onSubmit,
2590
+ onData
2554
2591
  });
2555
2592
  /*
2556
2593
  @TODO move this logic inside form-core, add action and method onto form element,
@@ -2865,4 +2902,46 @@ const AsFormFieldBuilder = props => {
2865
2902
  }) : jsx(Fragment, {});
2866
2903
  };
2867
2904
 
2868
- export { AsFormField, AsFormFieldBuilder, Form, FormGroupContext, FormGroupContextProvider, useFormGroupContext };
2905
+ // @TODO implement onSubmitGroup
2906
+ const useFormGroup = ({
2907
+ ids,
2908
+ onData
2909
+ // onSubmit,
2910
+ }) => {
2911
+ const {
2912
+ formGroupInstance
2913
+ } = useFormGroupContext({});
2914
+ const onDataCallbackRef = useRef(onData);
2915
+ // const onSubmitCallbackRef = useRef(onSubmit);
2916
+ useEffect(() => {
2917
+ onDataCallbackRef.current = onData;
2918
+ }, [onData]);
2919
+ // useEffect(() => {
2920
+ // onSubmitCallbackRef.current = onSubmit;
2921
+ // }, [onSubmit]);
2922
+ useEffect(() => {
2923
+ const onDataCallback = payload => {
2924
+ var _a;
2925
+ if (onDataCallbackRef.current) {
2926
+ (_a = onDataCallbackRef.current) === null || _a === void 0 ? void 0 : _a.call(onDataCallbackRef, payload);
2927
+ }
2928
+ };
2929
+ const onDataSub = formGroupInstance.onDataSubscription({
2930
+ ids,
2931
+ callback: onDataCallback
2932
+ });
2933
+ // const onSubmitCallback = (
2934
+ // payload: TFormValues<Record<string, unknown>>
2935
+ // ) => {
2936
+ // if (onSubmitCallbackRef.current) {
2937
+ // onSubmitCallbackRef.current?.(payload);
2938
+ // }
2939
+ // };
2940
+ return () => {
2941
+ onDataSub.unsubscribe();
2942
+ };
2943
+ }, []);
2944
+ return;
2945
+ };
2946
+
2947
+ export { AsFormField, AsFormFieldBuilder, Form, FormGroupContext, FormGroupContextProvider, useForm, useFormGroup, useFormGroupContext };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine",
3
- "version": "3.0.0-beta.25",
3
+ "version": "3.0.0-beta.27",
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.16",
9
+ "@bolttech/form-engine-core": "0.0.1-beta.18",
10
10
  "react": "18.2.0"
11
11
  },
12
12
  "peerDependencies": {}
@@ -1,4 +1,4 @@
1
- import { FormCore, TFormCore, TFormGroup, TFormValues, TMapper } from '@bolttech/form-engine-core';
1
+ import { FormCore, TFormCore, TFormGroup, TMapper } from '@bolttech/form-engine-core';
2
2
  import { ElementType } from 'react';
3
3
  /**
4
4
  * Represents the context for managing forms within a form group.
@@ -29,7 +29,7 @@ type TFormContext = {
29
29
  formGroupInstance: TFormGroup;
30
30
  mappers?: TMapper<ElementType>[];
31
31
  printFormGroupInstance: () => void;
32
- submitMultipleFormsByIndex: <T>(indexes: string[]) => TFormValues<T>;
32
+ submitMultipleFormsByIndex: <T>(indexes: string[]) => void;
33
33
  debugMode: boolean;
34
34
  active: boolean;
35
35
  };
@@ -0,0 +1,2 @@
1
+ export { default as useForm } from './useForm/useForm';
2
+ export { default as useFormGroup } from './useFormGroup/useFormGroup';
@@ -2,5 +2,5 @@ import { TUseFormProps } from './useForm.type';
2
2
  /**
3
3
  * Hook to register events callback functions
4
4
  */
5
- declare const useForm: ({ id, ...rest }: TUseFormProps) => void;
5
+ declare const useForm: ({ id, onData, onSubmit, ...rest }: TUseFormProps) => void;
6
6
  export default useForm;
@@ -1,4 +1,4 @@
1
- import { TEventsCallbackProps } from '../types';
1
+ import { TEventsCallbackProps } from '../../types';
2
2
  /**
3
3
  * Represents the properties for the useForm hook, including an ID and event callback properties.
4
4
  *
@@ -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,4 @@
1
1
  export * from './components';
2
+ export * from './hooks';
2
3
  export * from './context/FormGroupContext';
3
4
  export * from './types';
@@ -1,4 +1,4 @@
1
- import { TFieldEvent } from '@bolttech/form-engine-core';
1
+ import { TFieldEvent, TFormValues } from '@bolttech/form-engine-core';
2
2
  /**
3
3
  * Represents a field wrapper containing the name of the field and its index in the form.
4
4
  *
@@ -12,9 +12,15 @@ type TFieldWrapper = {
12
12
  /**
13
13
  * Represents the possible event properties for form fields callbacks.
14
14
  */
15
- type TEventProps = 'onChange' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'onMount' | 'onApiResponse' | 'onClick' | 'onSubmit';
15
+ type TEventProps = 'onChange' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'onMount' | 'onApiResponse' | 'onClick';
16
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>>;
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
+ onData?: (payload: {
21
+ field: string;
22
+ data: TFormValues<Record<string, unknown>>;
23
+ }) => void;
24
+ onSubmit?: (payload: TFormValues<Record<string, unknown>>) => void;
25
+ };
20
26
  export { TFieldWrapper, TEventProps, TEventsCallbackProps };