@bolttech/form-engine 3.0.0-beta.43 → 3.0.0-beta.46
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 +34 -15
- package/package.json +4 -3
- package/src/components/Form/Form.d.ts +1 -1
- package/src/components/Form/Form.type.d.ts +1 -1
- package/src/context/FormGroupContext.type.d.ts +1 -1
- package/src/hooks/useForm/useForm.d.ts +1 -1
- package/src/hooks/useForm/useForm.type.d.ts +2 -2
- package/src/types/index.d.ts +4 -3
package/index.esm.js
CHANGED
|
@@ -2383,13 +2383,14 @@ const eventsMapping = {
|
|
|
2383
2383
|
/**
|
|
2384
2384
|
* Hook to register events callback functions
|
|
2385
2385
|
*/
|
|
2386
|
-
|
|
2386
|
+
function useForm(_a) {
|
|
2387
2387
|
var {
|
|
2388
2388
|
id,
|
|
2389
2389
|
onData,
|
|
2390
|
-
onSubmit
|
|
2390
|
+
onSubmit,
|
|
2391
|
+
onMount
|
|
2391
2392
|
} = _a,
|
|
2392
|
-
rest = __rest(_a, ["id", "onData", "onSubmit"]);
|
|
2393
|
+
rest = __rest(_a, ["id", "onData", "onSubmit", "onMount"]);
|
|
2393
2394
|
const {
|
|
2394
2395
|
formGroupInstance
|
|
2395
2396
|
} = useFormGroupContext({});
|
|
@@ -2402,14 +2403,16 @@ const useForm = _a => {
|
|
|
2402
2403
|
}, [rest]);
|
|
2403
2404
|
const formValuesCallbackRefs = useRef({
|
|
2404
2405
|
onData,
|
|
2405
|
-
onSubmit
|
|
2406
|
+
onSubmit,
|
|
2407
|
+
onMount
|
|
2406
2408
|
});
|
|
2407
2409
|
useEffect(() => {
|
|
2408
2410
|
formValuesCallbackRefs.current = {
|
|
2409
2411
|
onData,
|
|
2410
|
-
onSubmit
|
|
2412
|
+
onSubmit,
|
|
2413
|
+
onMount
|
|
2411
2414
|
};
|
|
2412
|
-
}, [onData, onSubmit]);
|
|
2415
|
+
}, [onData, onSubmit, onMount]);
|
|
2413
2416
|
/**
|
|
2414
2417
|
* handle function call after the debounce occurs on the form instance field event
|
|
2415
2418
|
* subject in order to call the most updated function with the updated function
|
|
@@ -2432,39 +2435,49 @@ const useForm = _a => {
|
|
|
2432
2435
|
return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
2433
2436
|
}, []);
|
|
2434
2437
|
useEffect(() => {
|
|
2435
|
-
var _a, _b;
|
|
2438
|
+
var _a, _b, _c;
|
|
2439
|
+
const mountCallback = payload => {
|
|
2440
|
+
var _a, _b;
|
|
2441
|
+
if (formValuesCallbackRefs.current.onMount) {
|
|
2442
|
+
(_b = (_a = formValuesCallbackRefs.current).onMount) === null || _b === void 0 ? void 0 : _b.call(_a, payload);
|
|
2443
|
+
}
|
|
2444
|
+
};
|
|
2445
|
+
const mountSub = (_a = formGroupInstance.getForm({
|
|
2446
|
+
key: id
|
|
2447
|
+
})) === null || _a === void 0 ? void 0 : _a.subscribeOnMount(mountCallback);
|
|
2436
2448
|
const dataCallback = payload => {
|
|
2437
2449
|
var _a, _b;
|
|
2438
2450
|
if (formValuesCallbackRefs.current.onData) {
|
|
2439
2451
|
(_b = (_a = formValuesCallbackRefs.current).onData) === null || _b === void 0 ? void 0 : _b.call(_a, payload);
|
|
2440
2452
|
}
|
|
2441
2453
|
};
|
|
2442
|
-
const dataSub = (
|
|
2454
|
+
const dataSub = (_b = formGroupInstance.getForm({
|
|
2443
2455
|
key: id
|
|
2444
|
-
})) === null ||
|
|
2456
|
+
})) === null || _b === void 0 ? void 0 : _b.subscribeData(dataCallback);
|
|
2445
2457
|
const submitCallback = payload => {
|
|
2446
2458
|
var _a, _b;
|
|
2447
2459
|
if (formValuesCallbackRefs.current.onSubmit) {
|
|
2448
2460
|
(_b = (_a = formValuesCallbackRefs.current).onSubmit) === null || _b === void 0 ? void 0 : _b.call(_a, payload);
|
|
2449
2461
|
}
|
|
2450
2462
|
};
|
|
2451
|
-
const submitSub = (
|
|
2463
|
+
const submitSub = (_c = formGroupInstance.getForm({
|
|
2452
2464
|
key: id
|
|
2453
|
-
})) === null ||
|
|
2465
|
+
})) === null || _c === void 0 ? void 0 : _c.subscribeOnSubmit(submitCallback);
|
|
2454
2466
|
return () => {
|
|
2467
|
+
mountSub === null || mountSub === void 0 ? void 0 : mountSub.unsubscribe();
|
|
2455
2468
|
dataSub === null || dataSub === void 0 ? void 0 : dataSub.unsubscribe();
|
|
2456
2469
|
submitSub === null || submitSub === void 0 ? void 0 : submitSub.unsubscribe();
|
|
2457
2470
|
};
|
|
2458
2471
|
}, []);
|
|
2459
2472
|
return;
|
|
2460
|
-
}
|
|
2473
|
+
}
|
|
2461
2474
|
|
|
2462
2475
|
/**
|
|
2463
2476
|
*
|
|
2464
2477
|
* @param {TFormProps} param form properties initializor
|
|
2465
2478
|
* @returns {ReactElement}
|
|
2466
2479
|
*/
|
|
2467
|
-
|
|
2480
|
+
function Form({
|
|
2468
2481
|
schema,
|
|
2469
2482
|
index,
|
|
2470
2483
|
initialValues,
|
|
@@ -2482,7 +2495,7 @@ const Form = ({
|
|
|
2482
2495
|
onKeyUp,
|
|
2483
2496
|
onMount,
|
|
2484
2497
|
children
|
|
2485
|
-
})
|
|
2498
|
+
}) {
|
|
2486
2499
|
const {
|
|
2487
2500
|
addForm,
|
|
2488
2501
|
removeForm,
|
|
@@ -2512,11 +2525,17 @@ const Form = ({
|
|
|
2512
2525
|
key: schemaIndex,
|
|
2513
2526
|
formInstance
|
|
2514
2527
|
});
|
|
2528
|
+
let subMounted;
|
|
2529
|
+
if (onMount) {
|
|
2530
|
+
subMounted = formInstance.subscribeOnMount(onMount);
|
|
2531
|
+
}
|
|
2532
|
+
formInstance === null || formInstance === void 0 ? void 0 : formInstance.mounted();
|
|
2515
2533
|
/*
|
|
2516
2534
|
@TODO check if form instance is killed each time it is unmounted
|
|
2517
2535
|
the management of multiple forms needs to be planned
|
|
2518
2536
|
*/
|
|
2519
2537
|
return () => {
|
|
2538
|
+
subMounted === null || subMounted === void 0 ? void 0 : subMounted.unsubscribe();
|
|
2520
2539
|
removeForm({
|
|
2521
2540
|
key: schemaIndex
|
|
2522
2541
|
});
|
|
@@ -2636,7 +2655,7 @@ const Form = ({
|
|
|
2636
2655
|
children: tree && tree
|
|
2637
2656
|
})]
|
|
2638
2657
|
});
|
|
2639
|
-
}
|
|
2658
|
+
}
|
|
2640
2659
|
|
|
2641
2660
|
/**
|
|
2642
2661
|
* Component wrapper to aid building schemas with react without writting a JSON schema
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.46",
|
|
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.
|
|
10
|
-
"react": "18.2.0"
|
|
9
|
+
"@bolttech/form-engine-core": "0.0.1-beta.33",
|
|
10
|
+
"react": "18.2.0",
|
|
11
|
+
"rxjs": "7.8.1"
|
|
11
12
|
},
|
|
12
13
|
"peerDependencies": {}
|
|
13
14
|
}
|
|
@@ -5,5 +5,5 @@ import { TFormProps } from './Form.type';
|
|
|
5
5
|
* @param {TFormProps} param form properties initializor
|
|
6
6
|
* @returns {ReactElement}
|
|
7
7
|
*/
|
|
8
|
-
declare
|
|
8
|
+
declare function Form<T>({ schema, index, initialValues, iVars, action, method, onSubmit, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, children, }: TFormProps<T>): ReactElement;
|
|
9
9
|
export default Form;
|
|
@@ -7,5 +7,5 @@ import { TEventsCallbackProps } from '../../types';
|
|
|
7
7
|
* @see {@link TFormEntry}
|
|
8
8
|
* @see {@link TEventsCallbackProps}
|
|
9
9
|
*/
|
|
10
|
-
type TFormProps = PropsWithChildren<Omit<TFormEntry, 'mappers'> & TEventsCallbackProps
|
|
10
|
+
type TFormProps<T> = PropsWithChildren<Omit<TFormEntry, 'mappers'> & TEventsCallbackProps<T>>;
|
|
11
11
|
export type { TFormProps };
|
|
@@ -29,7 +29,7 @@ type TFormContext = {
|
|
|
29
29
|
formGroupInstance: TFormGroup;
|
|
30
30
|
mappers?: TMapper<ElementType>[];
|
|
31
31
|
printFormGroupInstance: () => void;
|
|
32
|
-
submitMultipleFormsByIndex:
|
|
32
|
+
submitMultipleFormsByIndex: (indexes: string[]) => void;
|
|
33
33
|
debugMode: boolean;
|
|
34
34
|
active: boolean;
|
|
35
35
|
};
|
|
@@ -2,5 +2,5 @@ import { TUseFormProps } from './useForm.type';
|
|
|
2
2
|
/**
|
|
3
3
|
* Hook to register events callback functions
|
|
4
4
|
*/
|
|
5
|
-
declare
|
|
5
|
+
declare function useForm<T>({ id, onData, onSubmit, onMount, ...rest }: TUseFormProps<T>): void;
|
|
6
6
|
export default useForm;
|
package/src/types/index.d.ts
CHANGED
|
@@ -23,8 +23,9 @@ type TFormData<T> = {
|
|
|
23
23
|
/**
|
|
24
24
|
* Represents a mapping of event properties to their corresponding callback functions.
|
|
25
25
|
*/
|
|
26
|
-
type TEventsCallbackProps = Partial<Record<TEventProps, ((payload: TFieldEvent) => void) | null | undefined>> & {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
type TEventsCallbackProps<T> = Partial<Record<TEventProps, ((payload: TFieldEvent) => void) | null | undefined>> & {
|
|
27
|
+
onMount?: (payload: TFormValues<T>) => void;
|
|
28
|
+
onData?: (payload: TFormData<T>) => void;
|
|
29
|
+
onSubmit?: (payload: TFormValues<T>) => void;
|
|
29
30
|
};
|
|
30
31
|
export { TFieldWrapper, TEventProps, TEventsCallbackProps, TFormData };
|