@bolttech/form-engine 3.0.1-beta.5 → 3.0.1-beta.6
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 +878 -172
- package/index.esm.js +59 -68
- package/package.json +2 -2
- package/src/components/Form/Form.d.ts +1 -1
- package/src/context/FormGroupContext.d.ts +1 -1
- package/src/context/FormGroupContext.type.d.ts +3 -1
- package/src/hooks/useForm/useForm.d.ts +2 -1
- package/src/hooks/useFormGroup/useFormGroup.d.ts +5 -8
- package/src/types/index.d.ts +2 -1
package/index.esm.js
CHANGED
|
@@ -1996,9 +1996,12 @@ const FormGroupContext = /*#__PURE__*/createContext({});
|
|
|
1996
1996
|
*/
|
|
1997
1997
|
const IsolatedContext = ({
|
|
1998
1998
|
debugMode: _debugMode = false,
|
|
1999
|
-
mappers
|
|
1999
|
+
mappers,
|
|
2000
|
+
config
|
|
2000
2001
|
}) => {
|
|
2001
|
-
const formGroupInstance = useRef(new FormGroup(
|
|
2002
|
+
const formGroupInstance = useRef(new FormGroup({
|
|
2003
|
+
config
|
|
2004
|
+
}));
|
|
2002
2005
|
const addFormWithIndex = index => {
|
|
2003
2006
|
formGroupInstance.current.createFormWithIndex({
|
|
2004
2007
|
index,
|
|
@@ -2054,14 +2057,17 @@ const IsolatedContext = ({
|
|
|
2054
2057
|
const FormGroupContextProvider = ({
|
|
2055
2058
|
children,
|
|
2056
2059
|
mappers,
|
|
2057
|
-
debugMode: _debugMode2 = false
|
|
2060
|
+
debugMode: _debugMode2 = false,
|
|
2061
|
+
config
|
|
2058
2062
|
}) => {
|
|
2059
2063
|
const contextValue = IsolatedContext({
|
|
2060
2064
|
mappers,
|
|
2061
|
-
debugMode: _debugMode2
|
|
2065
|
+
debugMode: _debugMode2,
|
|
2066
|
+
config
|
|
2062
2067
|
});
|
|
2063
2068
|
contextValue.debugMode = _debugMode2;
|
|
2064
2069
|
contextValue.active = true;
|
|
2070
|
+
contextValue.config = config;
|
|
2065
2071
|
return jsxs(FormGroupContext.Provider, {
|
|
2066
2072
|
value: contextValue,
|
|
2067
2073
|
children: [_debugMode2 && jsxs(Fragment, {
|
|
@@ -2383,14 +2389,15 @@ const eventsMapping = {
|
|
|
2383
2389
|
/**
|
|
2384
2390
|
* Hook to register events callback functions
|
|
2385
2391
|
*/
|
|
2386
|
-
function useForm(_a) {
|
|
2392
|
+
function useForm(_a, deps) {
|
|
2387
2393
|
var {
|
|
2388
2394
|
id,
|
|
2389
2395
|
onData,
|
|
2390
2396
|
onSubmit,
|
|
2391
|
-
onFormMount
|
|
2397
|
+
onFormMount,
|
|
2398
|
+
onValid
|
|
2392
2399
|
} = _a,
|
|
2393
|
-
rest = __rest(_a, ["id", "onData", "onSubmit", "onFormMount"]);
|
|
2400
|
+
rest = __rest(_a, ["id", "onData", "onSubmit", "onFormMount", "onValid"]);
|
|
2394
2401
|
const {
|
|
2395
2402
|
formGroupInstance
|
|
2396
2403
|
} = useFormGroupContext({});
|
|
@@ -2404,22 +2411,24 @@ function useForm(_a) {
|
|
|
2404
2411
|
const formValuesCallbackRefs = useRef({
|
|
2405
2412
|
onData,
|
|
2406
2413
|
onSubmit,
|
|
2407
|
-
onFormMount
|
|
2414
|
+
onFormMount,
|
|
2415
|
+
onValid
|
|
2408
2416
|
});
|
|
2409
2417
|
useEffect(() => {
|
|
2410
2418
|
formValuesCallbackRefs.current = {
|
|
2411
2419
|
onData,
|
|
2412
2420
|
onSubmit,
|
|
2413
|
-
onFormMount
|
|
2421
|
+
onFormMount,
|
|
2422
|
+
onValid
|
|
2414
2423
|
};
|
|
2415
|
-
}, [onData, onSubmit, onFormMount]);
|
|
2424
|
+
}, [onData, onSubmit, onFormMount, onValid]);
|
|
2416
2425
|
/**
|
|
2417
2426
|
* handle function call after the debounce occurs on the form instance field event
|
|
2418
2427
|
* subject in order to call the most updated function with the updated function
|
|
2419
2428
|
* reference to avoid events get outdated values
|
|
2420
2429
|
*/
|
|
2421
2430
|
useEffect(() => {
|
|
2422
|
-
var _a;
|
|
2431
|
+
var _a, _b, _c, _d, _e;
|
|
2423
2432
|
const callback = payload => {
|
|
2424
2433
|
var _a, _b;
|
|
2425
2434
|
const eventMapping = eventsMapping[payload.event];
|
|
@@ -2432,43 +2441,49 @@ function useForm(_a) {
|
|
|
2432
2441
|
})) === null || _a === void 0 ? void 0 : _a.subscribeFieldEvent({
|
|
2433
2442
|
callback
|
|
2434
2443
|
});
|
|
2435
|
-
return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
2436
|
-
}, []);
|
|
2437
|
-
useEffect(() => {
|
|
2438
|
-
var _a, _b, _c;
|
|
2439
2444
|
const mountCallback = payload => {
|
|
2440
2445
|
var _a, _b;
|
|
2441
2446
|
if (formValuesCallbackRefs.current.onMount) {
|
|
2442
2447
|
(_b = (_a = formValuesCallbackRefs.current).onFormMount) === null || _b === void 0 ? void 0 : _b.call(_a, payload);
|
|
2443
2448
|
}
|
|
2444
2449
|
};
|
|
2445
|
-
const mountSub = (
|
|
2450
|
+
const mountSub = (_b = formGroupInstance.getForm({
|
|
2446
2451
|
key: id
|
|
2447
|
-
})) === null ||
|
|
2452
|
+
})) === null || _b === void 0 ? void 0 : _b.subscribeOnMount(mountCallback);
|
|
2448
2453
|
const dataCallback = payload => {
|
|
2449
2454
|
var _a, _b;
|
|
2450
2455
|
if (formValuesCallbackRefs.current.onData) {
|
|
2451
2456
|
(_b = (_a = formValuesCallbackRefs.current).onData) === null || _b === void 0 ? void 0 : _b.call(_a, payload);
|
|
2452
2457
|
}
|
|
2453
2458
|
};
|
|
2454
|
-
const dataSub = (
|
|
2459
|
+
const dataSub = (_c = formGroupInstance.getForm({
|
|
2460
|
+
key: id
|
|
2461
|
+
})) === null || _c === void 0 ? void 0 : _c.subscribeData(dataCallback);
|
|
2462
|
+
const validationCallback = payload => {
|
|
2463
|
+
if (formValuesCallbackRefs.current.onValid) {
|
|
2464
|
+
formValuesCallbackRefs.current.onValid(payload);
|
|
2465
|
+
}
|
|
2466
|
+
};
|
|
2467
|
+
const validSub = (_d = formGroupInstance.getForm({
|
|
2455
2468
|
key: id
|
|
2456
|
-
})) === null ||
|
|
2469
|
+
})) === null || _d === void 0 ? void 0 : _d.subscribeFormValidation(validationCallback);
|
|
2457
2470
|
const submitCallback = payload => {
|
|
2458
2471
|
var _a, _b;
|
|
2459
2472
|
if (formValuesCallbackRefs.current.onSubmit) {
|
|
2460
2473
|
(_b = (_a = formValuesCallbackRefs.current).onSubmit) === null || _b === void 0 ? void 0 : _b.call(_a, payload);
|
|
2461
2474
|
}
|
|
2462
2475
|
};
|
|
2463
|
-
const submitSub = (
|
|
2476
|
+
const submitSub = (_e = formGroupInstance.getForm({
|
|
2464
2477
|
key: id
|
|
2465
|
-
})) === null ||
|
|
2478
|
+
})) === null || _e === void 0 ? void 0 : _e.subscribeOnSubmit(submitCallback);
|
|
2466
2479
|
return () => {
|
|
2480
|
+
sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
2467
2481
|
mountSub === null || mountSub === void 0 ? void 0 : mountSub.unsubscribe();
|
|
2468
2482
|
dataSub === null || dataSub === void 0 ? void 0 : dataSub.unsubscribe();
|
|
2483
|
+
validSub === null || validSub === void 0 ? void 0 : validSub.unsubscribe();
|
|
2469
2484
|
submitSub === null || submitSub === void 0 ? void 0 : submitSub.unsubscribe();
|
|
2470
2485
|
};
|
|
2471
|
-
}, []);
|
|
2486
|
+
}, [deps]);
|
|
2472
2487
|
return;
|
|
2473
2488
|
}
|
|
2474
2489
|
|
|
@@ -2495,6 +2510,7 @@ function Form({
|
|
|
2495
2510
|
onKeyDown,
|
|
2496
2511
|
onKeyUp,
|
|
2497
2512
|
onMount,
|
|
2513
|
+
onValid,
|
|
2498
2514
|
children
|
|
2499
2515
|
}) {
|
|
2500
2516
|
const {
|
|
@@ -2606,7 +2622,8 @@ function Form({
|
|
|
2606
2622
|
onMount,
|
|
2607
2623
|
onSubmit,
|
|
2608
2624
|
onFormMount,
|
|
2609
|
-
onData
|
|
2625
|
+
onData,
|
|
2626
|
+
onValid
|
|
2610
2627
|
});
|
|
2611
2628
|
/*
|
|
2612
2629
|
@TODO move this logic inside form-core, add action and method onto form element,
|
|
@@ -2860,7 +2877,6 @@ $({ target: 'RegExp', proto: true, forced: /./.exec !== exec }, {
|
|
|
2860
2877
|
* @returns {ReactElement}
|
|
2861
2878
|
*/
|
|
2862
2879
|
const AsFormFieldBuilder = props => {
|
|
2863
|
-
var _a, _b;
|
|
2864
2880
|
const context = useFormGroupContext({});
|
|
2865
2881
|
/**
|
|
2866
2882
|
* state to track the field instance creation process
|
|
@@ -2872,7 +2888,7 @@ const AsFormFieldBuilder = props => {
|
|
|
2872
2888
|
* Also has the logic to remove it once this element is removed
|
|
2873
2889
|
*/
|
|
2874
2890
|
useEffect(() => {
|
|
2875
|
-
var _a
|
|
2891
|
+
var _a;
|
|
2876
2892
|
if (!((_a = context.formGroupInstance) === null || _a === void 0 ? void 0 : _a.forms.has(props.formIndex))) {
|
|
2877
2893
|
context.addFormWithIndex(props.formIndex);
|
|
2878
2894
|
}
|
|
@@ -2888,20 +2904,6 @@ const AsFormFieldBuilder = props => {
|
|
|
2888
2904
|
const field = formInstance === null || formInstance === void 0 ? void 0 : formInstance.getField({
|
|
2889
2905
|
key: props.name
|
|
2890
2906
|
});
|
|
2891
|
-
/* This line is only for scenario that we have value by the component props */
|
|
2892
|
-
if (((_b = props.mapper.events) === null || _b === void 0 ? void 0 : _b.setValue) && props.props) {
|
|
2893
|
-
field === null || field === void 0 ? void 0 : field.emitValue({
|
|
2894
|
-
value: props.props[props.mapper.events.setValue],
|
|
2895
|
-
event: 'ON_FIELD_MOUNT'
|
|
2896
|
-
});
|
|
2897
|
-
}
|
|
2898
|
-
/* This line is only for scenario that we have value by the instanced form (initialValues) */
|
|
2899
|
-
if ((_c = formInstance === null || formInstance === void 0 ? void 0 : formInstance.initialValues) === null || _c === void 0 ? void 0 : _c[props.nameToSubmit || props.name]) {
|
|
2900
|
-
field === null || field === void 0 ? void 0 : field.emitValue({
|
|
2901
|
-
value: (_d = formInstance.initialValues) === null || _d === void 0 ? void 0 : _d[props.nameToSubmit || props.name],
|
|
2902
|
-
event: 'ON_FIELD_MOUNT'
|
|
2903
|
-
});
|
|
2904
|
-
}
|
|
2905
2907
|
if (typeof (props === null || props === void 0 ? void 0 : props.visibility) !== 'undefined' && field) {
|
|
2906
2908
|
field.visibility = props.visibility;
|
|
2907
2909
|
}
|
|
@@ -2949,31 +2951,6 @@ const AsFormFieldBuilder = props => {
|
|
|
2949
2951
|
});
|
|
2950
2952
|
return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
2951
2953
|
}, [props.onSelected]);
|
|
2952
|
-
/**
|
|
2953
|
-
* allows to control field visibility as a controlled component
|
|
2954
|
-
*/
|
|
2955
|
-
useEffect(() => {
|
|
2956
|
-
var _a;
|
|
2957
|
-
if (!mounted) return;
|
|
2958
|
-
const field = (_a = context.formGroupInstance.forms.get(props.formIndex)) === null || _a === void 0 ? void 0 : _a.fields.get(props.name);
|
|
2959
|
-
if (typeof (props === null || props === void 0 ? void 0 : props.visibility) !== 'undefined' && field) {
|
|
2960
|
-
field.visibility = props.visibility;
|
|
2961
|
-
}
|
|
2962
|
-
}, [mounted, props.visibility]);
|
|
2963
|
-
/**
|
|
2964
|
-
* allows to control field value as a controlled component
|
|
2965
|
-
*/
|
|
2966
|
-
useEffect(() => {
|
|
2967
|
-
var _a, _b, _c, _d;
|
|
2968
|
-
if (!mounted) return;
|
|
2969
|
-
const field = (_a = context.formGroupInstance.forms.get(props.formIndex)) === null || _a === void 0 ? void 0 : _a.fields.get(props.name);
|
|
2970
|
-
if (((_b = props.mapper.events) === null || _b === void 0 ? void 0 : _b.setValue) && ((_c = props.props) === null || _c === void 0 ? void 0 : _c[props.mapper.events.setValue]) && field) {
|
|
2971
|
-
field === null || field === void 0 ? void 0 : field.emitValue({
|
|
2972
|
-
value: (_d = props.props) === null || _d === void 0 ? void 0 : _d[props.mapper.events.setValue],
|
|
2973
|
-
event: 'ON_FIELD_CHANGE'
|
|
2974
|
-
});
|
|
2975
|
-
}
|
|
2976
|
-
}, [mounted, (_a = props.props) === null || _a === void 0 ? void 0 : _a[((_b = props.mapper.events) === null || _b === void 0 ? void 0 : _b.setValue) || 'value']]);
|
|
2977
2954
|
return mounted ? jsx(FieldWrapper, {
|
|
2978
2955
|
formIndex: props.formIndex,
|
|
2979
2956
|
name: props.name,
|
|
@@ -2986,17 +2963,21 @@ const AsFormFieldBuilder = props => {
|
|
|
2986
2963
|
// @TODO implement onSubmitGroup
|
|
2987
2964
|
const useFormGroup = ({
|
|
2988
2965
|
ids,
|
|
2989
|
-
onData
|
|
2990
|
-
|
|
2991
|
-
}) => {
|
|
2966
|
+
onData,
|
|
2967
|
+
onValid
|
|
2968
|
+
}, deps) => {
|
|
2992
2969
|
const {
|
|
2993
2970
|
formGroupInstance
|
|
2994
2971
|
} = useFormGroupContext({});
|
|
2995
2972
|
const onDataCallbackRef = useRef(onData);
|
|
2973
|
+
const onValidCallbackRef = useRef(onValid);
|
|
2996
2974
|
// const onSubmitCallbackRef = useRef(onSubmit);
|
|
2997
2975
|
useEffect(() => {
|
|
2998
2976
|
onDataCallbackRef.current = onData;
|
|
2999
2977
|
}, [onData]);
|
|
2978
|
+
useEffect(() => {
|
|
2979
|
+
onValidCallbackRef.current = onValid;
|
|
2980
|
+
}, [onValid]);
|
|
3000
2981
|
// useEffect(() => {
|
|
3001
2982
|
// onSubmitCallbackRef.current = onSubmit;
|
|
3002
2983
|
// }, [onSubmit]);
|
|
@@ -3011,6 +2992,15 @@ const useFormGroup = ({
|
|
|
3011
2992
|
ids,
|
|
3012
2993
|
callback: onDataCallback
|
|
3013
2994
|
});
|
|
2995
|
+
const onValidCallback = payload => {
|
|
2996
|
+
if (onValidCallbackRef.current) {
|
|
2997
|
+
onValidCallbackRef.current(payload);
|
|
2998
|
+
}
|
|
2999
|
+
};
|
|
3000
|
+
const onValidSub = formGroupInstance.onValidSubscription({
|
|
3001
|
+
ids,
|
|
3002
|
+
callback: onValidCallback
|
|
3003
|
+
});
|
|
3014
3004
|
// const onSubmitCallback = (
|
|
3015
3005
|
// payload: TFormValues<Record<string, unknown>>
|
|
3016
3006
|
// ) => {
|
|
@@ -3020,8 +3010,9 @@ const useFormGroup = ({
|
|
|
3020
3010
|
// };
|
|
3021
3011
|
return () => {
|
|
3022
3012
|
onDataSub.unsubscribe();
|
|
3013
|
+
onValidSub.unsubscribe();
|
|
3023
3014
|
};
|
|
3024
|
-
}, []);
|
|
3015
|
+
}, [deps]);
|
|
3025
3016
|
return;
|
|
3026
3017
|
};
|
|
3027
3018
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine",
|
|
3
|
-
"version": "3.0.1-beta.
|
|
3
|
+
"version": "3.0.1-beta.6",
|
|
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.2-beta.
|
|
9
|
+
"@bolttech/form-engine-core": "0.0.2-beta.6",
|
|
10
10
|
"react": "18.2.0",
|
|
11
11
|
"rxjs": "7.8.1"
|
|
12
12
|
},
|
|
@@ -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 function Form<T>({ schema, index, initialValues, iVars, action, method, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, children, }: TFormProps<T>): ReactElement;
|
|
8
|
+
declare function Form<T>({ schema, index, initialValues, iVars, action, method, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, onValid, children, }: TFormProps<T>): ReactElement;
|
|
9
9
|
export default Form;
|
|
@@ -7,7 +7,7 @@ declare const FormGroupContext: import("react").Context<TFormContext>;
|
|
|
7
7
|
* @param {PropsWithChildren<TFormContextProvider>} param context parameters
|
|
8
8
|
* @returns {ReactElement}
|
|
9
9
|
*/
|
|
10
|
-
declare const FormGroupContextProvider: ({ children, mappers, debugMode, }: PropsWithChildren<TFormContextProvider>) => ReactElement;
|
|
10
|
+
declare const FormGroupContextProvider: ({ children, mappers, debugMode, config, }: PropsWithChildren<TFormContextProvider>) => ReactElement;
|
|
11
11
|
/**
|
|
12
12
|
* FormGroup context hook to handle context or isolated context implementations
|
|
13
13
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormCore, TFormCore, TFormGroup, TMapper } from '@bolttech/form-engine-core';
|
|
1
|
+
import { FormCore, TFormCore, TFormGroup, TMapper, TSchemaFormConfig } 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.
|
|
@@ -32,6 +32,7 @@ type TFormContext = {
|
|
|
32
32
|
submitMultipleFormsByIndex: (indexes: string[]) => void;
|
|
33
33
|
debugMode: boolean;
|
|
34
34
|
active: boolean;
|
|
35
|
+
config?: TSchemaFormConfig;
|
|
35
36
|
};
|
|
36
37
|
/**
|
|
37
38
|
* Represents the props for a form context provider.
|
|
@@ -42,5 +43,6 @@ type TFormContext = {
|
|
|
42
43
|
type TFormContextProvider = {
|
|
43
44
|
mappers?: TMapper<ElementType>[];
|
|
44
45
|
debugMode?: boolean;
|
|
46
|
+
config?: TSchemaFormConfig;
|
|
45
47
|
};
|
|
46
48
|
export type { TFormContext, TFormContextProvider };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { TUseFormProps } from './useForm.type';
|
|
2
3
|
/**
|
|
3
4
|
* Hook to register events callback functions
|
|
4
5
|
*/
|
|
5
|
-
declare function useForm<T>({ id, onData, onSubmit, onFormMount, ...rest }: TUseFormProps<T
|
|
6
|
+
declare function useForm<T>({ id, onData, onSubmit, onFormMount, onValid, ...rest }: TUseFormProps<T>, deps?: React.DependencyList): void;
|
|
6
7
|
export default useForm;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const useFormGroup: ({ ids, onData, }: {
|
|
1
|
+
import { TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload } from '@bolttech/form-engine-core';
|
|
2
|
+
declare const useFormGroup: ({ ids, onData, onValid, }: {
|
|
3
3
|
ids: string[];
|
|
4
|
-
onData
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
values?: TFormValues<Record<string, unknown>>;
|
|
8
|
-
}>) => void;
|
|
9
|
-
}) => void;
|
|
4
|
+
onData?: ((payload: TFormGroupOnDataEventPayload<Record<string, unknown>>) => void) | undefined;
|
|
5
|
+
onValid?: ((payload: TFormGroupOnValidEventPayload) => void) | undefined;
|
|
6
|
+
}, deps?: React.DependencyList) => void;
|
|
10
7
|
export default useFormGroup;
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TFieldEvent, TFormValues } from '@bolttech/form-engine-core';
|
|
1
|
+
import { TFieldEvent, TFormValidationPayload, 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
|
*
|
|
@@ -27,5 +27,6 @@ type TEventsCallbackProps<T> = Partial<Record<TEventProps, ((payload: TFieldEven
|
|
|
27
27
|
onFormMount?: (payload: TFormValues<T>) => void;
|
|
28
28
|
onData?: (payload: TFormData<T>) => void;
|
|
29
29
|
onSubmit?: (payload: TFormValues<T>) => void;
|
|
30
|
+
onValid?: (payload: TFormValidationPayload) => void;
|
|
30
31
|
};
|
|
31
32
|
export { TFieldWrapper, TEventProps, TEventsCallbackProps, TFormData };
|