@bolttech/form-engine 3.0.1-beta.7 → 3.0.2-beta.10
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
|
@@ -24,6 +24,7 @@ This is an adapter to be used with the bolttech form engine. Compatible with Nex
|
|
|
24
24
|
- 6.6 [api](#api)
|
|
25
25
|
- 6.7 [resetValues](#resetvalues)
|
|
26
26
|
- 6.8 [visibilityConditions](#visibilityconditions)
|
|
27
|
+
- 6.9 [resetPropertyValues](#resetpropertyvalues)
|
|
27
28
|
|
|
28
29
|
7. [templating](#templating)
|
|
29
30
|
|
|
@@ -36,6 +37,7 @@ This is an adapter to be used with the bolttech form engine. Compatible with Nex
|
|
|
36
37
|
10. [AsFormFieldBuilder](#asformfieldbuilder)
|
|
37
38
|
|
|
38
39
|
<a id="sample"></a>
|
|
40
|
+
|
|
39
41
|
## **Sample**
|
|
40
42
|
|
|
41
43
|
```typescript
|
|
@@ -110,6 +112,7 @@ const Sample = () => {
|
|
|
110
112
|
);
|
|
111
113
|
};
|
|
112
114
|
```
|
|
115
|
+
|
|
113
116
|
<a id="mappers"></a>
|
|
114
117
|
|
|
115
118
|
## **Mappers**
|
|
@@ -119,7 +122,7 @@ Mappers are the configuration that needs to be provided in order to use componen
|
|
|
119
122
|
The mapper configuration goes as it follows:
|
|
120
123
|
|
|
121
124
|
| Prop | Type | Description |
|
|
122
|
-
|
|
125
|
+
|------------------|------------------------|--------------------------------------------------------------------------------------------------------------------------|
|
|
123
126
|
| componentName | string | name to be used onto schema to identify the component to be rendered on a field |
|
|
124
127
|
| events | TComponentPropsMapping | events mapping that will reference the component prop with the respective form-engine prop that will handle it's content |
|
|
125
128
|
| valueChangeEvent | TValueChangeEvent | component handle function to define how the value is extracted from the 'onChange' event of the component |
|
|
@@ -128,17 +131,18 @@ The mapper configuration goes as it follows:
|
|
|
128
131
|
|
|
129
132
|
`events` are optional and will reference component props that will provide it's dynamic behaviour:
|
|
130
133
|
|
|
131
|
-
| Prop | Type | Description
|
|
132
|
-
|
|
133
|
-
| getValue | string | component property that will contain the value
|
|
134
|
-
| setValue | string | component property that handles onChange events triggered by the component
|
|
135
|
-
| onBlur | string | component property that handles onBlur events triggered by the component
|
|
136
|
-
| onClick | string | component property that handles onClick events triggered by the component
|
|
137
|
-
|
|
|
138
|
-
|
|
|
139
|
-
|
|
|
140
|
-
|
|
|
141
|
-
|
|
|
134
|
+
| Prop | Type | Description |
|
|
135
|
+
|-----------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
136
|
+
| getValue | string | component property that will contain the value |
|
|
137
|
+
| setValue | string | component property that handles onChange events triggered by the component |
|
|
138
|
+
| onBlur | string | component property that handles onBlur events triggered by the component |
|
|
139
|
+
| onClick | string | component property that handles onClick events triggered by the component |
|
|
140
|
+
| onSubmit | string | component property that handles form submission event triggered by the component (a way to submit a form using AsFormFieldBuilder, if used with AsFormField and Form will trigger submission twice) |
|
|
141
|
+
| onFocus | string | component property that handles onFocus events triggered by the component |
|
|
142
|
+
| onKeyUp | string | component property that handles onKeyUp events triggered by the component |
|
|
143
|
+
| onKeyDown | string | component property that handles onKeyDown events triggered by the component |
|
|
144
|
+
| setErrorMessage | string | component property that receives the errors of the field as string |
|
|
145
|
+
| setErrorState | string | component property that receives the error status of the field as boolean (not implemented) |
|
|
142
146
|
|
|
143
147
|
### component and asynccomponent
|
|
144
148
|
|
|
@@ -245,7 +249,7 @@ const mapper = [
|
|
|
245
249
|
|
|
246
250
|
<a id="form-group-context"></a>
|
|
247
251
|
|
|
248
|
-
## **Form Group Context**
|
|
252
|
+
## **Form Group Context**
|
|
249
253
|
|
|
250
254
|
<a id="formgroupcontextprovider"></a>
|
|
251
255
|
|
|
@@ -406,6 +410,7 @@ const FormComponent = (): React.ReactElement => {
|
|
|
406
410
|
|
|
407
411
|
export default FormComponent;
|
|
408
412
|
```
|
|
413
|
+
|
|
409
414
|
<a id="form"></a>
|
|
410
415
|
|
|
411
416
|
## **Form**
|
|
@@ -449,6 +454,7 @@ A simple example of rendering a basic form
|
|
|
449
454
|
```javascript
|
|
450
455
|
<Form schema={schema} />
|
|
451
456
|
```
|
|
457
|
+
|
|
452
458
|
<a id="submit-form"></a>
|
|
453
459
|
|
|
454
460
|
## **Submit Form**
|
|
@@ -621,6 +627,7 @@ Schema components contains the information of the component that will be rendere
|
|
|
621
627
|
}]
|
|
622
628
|
}
|
|
623
629
|
```
|
|
630
|
+
|
|
624
631
|
<a id="formatters"></a>
|
|
625
632
|
|
|
626
633
|
## **formatters**
|
|
@@ -659,6 +666,7 @@ const formatters = {
|
|
|
659
666
|
upperCase: true,
|
|
660
667
|
};
|
|
661
668
|
```
|
|
669
|
+
|
|
662
670
|
<a id="nametosubmit"></a>
|
|
663
671
|
|
|
664
672
|
## **nameToSubmit**
|
|
@@ -686,6 +694,7 @@ when calling the `onSubmit` or `onData` the field section of this field will out
|
|
|
686
694
|
}
|
|
687
695
|
}
|
|
688
696
|
```
|
|
697
|
+
|
|
689
698
|
<a id="props"></a>
|
|
690
699
|
|
|
691
700
|
## **props**
|
|
@@ -813,6 +822,7 @@ Each config you opt to use, needs to be filled with an API configuration, the co
|
|
|
813
822
|
| url | string | Request url ex: http://mockapi.org |
|
|
814
823
|
| body? | Record<string, unknown> | Request body (only POST requests) |
|
|
815
824
|
| headers? | OutgoingHttpHeaders | Avaliable HTTP headers |
|
|
825
|
+
| queryParams? | Record<string,string> | url query params (to be appended to the already existing ones) |
|
|
816
826
|
| resultPath? | string | response dot notation path to the value needed from the response |
|
|
817
827
|
| fallbackValue? | unknown | default value to return if the API returns error |
|
|
818
828
|
| preConditions? | TSchemaValidation | validations to occur before the request is made (check validations section) |
|
|
@@ -904,6 +914,7 @@ const resetValues = [
|
|
|
904
914
|
},
|
|
905
915
|
];
|
|
906
916
|
```
|
|
917
|
+
|
|
907
918
|
<a id="visibilityconditions"></a>
|
|
908
919
|
|
|
909
920
|
## **visibilityConditions**
|
|
@@ -952,6 +963,46 @@ const visibilityConditions = [
|
|
|
952
963
|
];
|
|
953
964
|
```
|
|
954
965
|
|
|
966
|
+
<a id="resetpropertyvalues"></a>
|
|
967
|
+
|
|
968
|
+
## **resetPropertyValues**
|
|
969
|
+
|
|
970
|
+
resetPropertyValues will change a property value based on validation rules
|
|
971
|
+
|
|
972
|
+
> WARNING: do not rely on this to make mutations on your properties, templating already is a powerful tool and with this you can destroy some schema configurations accidentaly, this is a last resort schema manipulation tool to solve some edge cases with API requests callbacks handling
|
|
973
|
+
|
|
974
|
+
| Prop | Type | Description |
|
|
975
|
+
| -------------- | -------------------------------------------- | -------------------------------------------------------------- |
|
|
976
|
+
| property | typeof ALLOWED_RESET_PROPS_MUTATIONS[number] | property to be changed, ex: api, resetValues, etc.. |
|
|
977
|
+
| path | string | path where the property to be changed is located |
|
|
978
|
+
| field | string | field that will recieve the property change |
|
|
979
|
+
| resettledValue | unknown | value to be replaced onto the property |
|
|
980
|
+
| validations | TSchemaValidation | validations rules to be validated to change the property value |
|
|
981
|
+
| events | Partial<TEvents>[] | events to listen to apply this change |
|
|
982
|
+
|
|
983
|
+
example:
|
|
984
|
+
|
|
985
|
+
this will change the `api.named.chuck` property onto field `postalCode` when the `ON_FIELD_CHANGE` event occurs,
|
|
986
|
+
will change the content to: `{ status: null, response: ''}`
|
|
987
|
+
|
|
988
|
+
```typescript
|
|
989
|
+
resetPropertyValues: [
|
|
990
|
+
{
|
|
991
|
+
property: 'api',
|
|
992
|
+
path: 'named.chuck',
|
|
993
|
+
events: ['ON_FIELD_CHANGE'],
|
|
994
|
+
field: 'postalCode',
|
|
995
|
+
resettledValue: {
|
|
996
|
+
status: null,
|
|
997
|
+
response: '',
|
|
998
|
+
},
|
|
999
|
+
validations: {
|
|
1000
|
+
bool: false,
|
|
1001
|
+
},
|
|
1002
|
+
},
|
|
1003
|
+
],
|
|
1004
|
+
```
|
|
1005
|
+
|
|
955
1006
|
<a id="templating"></a>
|
|
956
1007
|
|
|
957
1008
|
## **templating**
|
|
@@ -1057,10 +1108,11 @@ useFormGroup({ ids: ['form1', 'form2'], onData: (payload) => console.log(payload
|
|
|
1057
1108
|
|
|
1058
1109
|
As `useForm`, `useFormGroup` serves the same purpose, but the difference is that it handles multiple forms and has limited callback functions to set:
|
|
1059
1110
|
|
|
1060
|
-
| method
|
|
1061
|
-
|
|
1062
|
-
| onData
|
|
1063
|
-
| onValid
|
|
1111
|
+
| method | payload | description |
|
|
1112
|
+
|----------|-----------------------------------|-------------------------------------------------------------|
|
|
1113
|
+
| onData | TFormGroupOnDataEventPayload<T> | event occurring when a value is changing via input or logic |
|
|
1114
|
+
| onValid | TFormGroupOnValidEventPayload | event occurring when validation status changes on the form |
|
|
1115
|
+
| onSubmit | TFormGroupOnSubmitEventPayload<T> | event occurring when form submission is trigger |
|
|
1064
1116
|
|
|
1065
1117
|
<a id="asformfield"></a>
|
|
1066
1118
|
|
package/index.esm.js
CHANGED
|
@@ -2207,6 +2207,7 @@ const FieldWrapper = ({
|
|
|
2207
2207
|
if (events === null || events === void 0 ? void 0 : events.getValue) props[events.getValue] = handleChange;
|
|
2208
2208
|
if (events === null || events === void 0 ? void 0 : events.onFocus) props[events.onFocus] = () => handleEvent('ON_FIELD_FOCUS');
|
|
2209
2209
|
if (events === null || events === void 0 ? void 0 : events.onClick) props[events.onClick] = () => handleEvent('ON_FIELD_CLICK');
|
|
2210
|
+
if (events === null || events === void 0 ? void 0 : events.onSubmit) props[events.onSubmit] = () => handleEvent('ON_FORM_SUBMIT');
|
|
2210
2211
|
if (events === null || events === void 0 ? void 0 : events.onKeyUp) props[events.onKeyUp] = () => handleEvent('ON_FIELD_KEYUP');
|
|
2211
2212
|
if (events === null || events === void 0 ? void 0 : events.onKeyDown) props[events.onKeyDown] = () => handleEvent('ON_FIELD_KEYDOWN');
|
|
2212
2213
|
return props;
|
|
@@ -2499,6 +2500,7 @@ function Form({
|
|
|
2499
2500
|
iVars,
|
|
2500
2501
|
action,
|
|
2501
2502
|
method,
|
|
2503
|
+
config,
|
|
2502
2504
|
onSubmit,
|
|
2503
2505
|
onFormMount,
|
|
2504
2506
|
onData,
|
|
@@ -2518,7 +2520,8 @@ function Form({
|
|
|
2518
2520
|
removeForm,
|
|
2519
2521
|
getForm,
|
|
2520
2522
|
mappers,
|
|
2521
|
-
debugMode
|
|
2523
|
+
debugMode,
|
|
2524
|
+
formGroupInstance
|
|
2522
2525
|
} = useFormGroupContext({});
|
|
2523
2526
|
const [tree, setTree] = useState();
|
|
2524
2527
|
const schemaIndex = useMemo(() => index || (schema === null || schema === void 0 ? void 0 : schema.index) || 'defaultChange', [index, schema]);
|
|
@@ -2536,7 +2539,8 @@ function Form({
|
|
|
2536
2539
|
action: action || (schema === null || schema === void 0 ? void 0 : schema.action),
|
|
2537
2540
|
method: method || (schema === null || schema === void 0 ? void 0 : schema.method),
|
|
2538
2541
|
index: schemaIndex,
|
|
2539
|
-
mappers
|
|
2542
|
+
mappers,
|
|
2543
|
+
config: config || formGroupInstance.config
|
|
2540
2544
|
});
|
|
2541
2545
|
addForm({
|
|
2542
2546
|
key: schemaIndex,
|
|
@@ -2594,18 +2598,9 @@ function Form({
|
|
|
2594
2598
|
* initialValues setter for async initialValues
|
|
2595
2599
|
*/
|
|
2596
2600
|
useEffect(() => {
|
|
2597
|
-
|
|
2601
|
+
if (initialValues) getForm({
|
|
2598
2602
|
key: schemaIndex
|
|
2599
|
-
});
|
|
2600
|
-
if (initialValues && form) {
|
|
2601
|
-
Object.keys(initialValues).forEach(fieldName => {
|
|
2602
|
-
var _a;
|
|
2603
|
-
(_a = form.fields.get(fieldName)) === null || _a === void 0 ? void 0 : _a.emitValue({
|
|
2604
|
-
event: 'ON_FIELD_MOUNT',
|
|
2605
|
-
value: initialValues[fieldName]
|
|
2606
|
-
});
|
|
2607
|
-
});
|
|
2608
|
-
}
|
|
2603
|
+
}).setInitialValues(initialValues);
|
|
2609
2604
|
}, [initialValues]);
|
|
2610
2605
|
/**
|
|
2611
2606
|
* hook usage to keep event bindings updated on callback functions passed as props
|
|
@@ -2960,27 +2955,27 @@ const AsFormFieldBuilder = props => {
|
|
|
2960
2955
|
}) : jsx(Fragment, {});
|
|
2961
2956
|
};
|
|
2962
2957
|
|
|
2963
|
-
|
|
2964
|
-
const useFormGroup = ({
|
|
2958
|
+
function useFormGroup({
|
|
2965
2959
|
ids,
|
|
2966
2960
|
onData,
|
|
2967
|
-
onValid
|
|
2968
|
-
|
|
2961
|
+
onValid,
|
|
2962
|
+
onSubmit
|
|
2963
|
+
}, deps) {
|
|
2969
2964
|
const {
|
|
2970
2965
|
formGroupInstance
|
|
2971
2966
|
} = useFormGroupContext({});
|
|
2972
2967
|
const onDataCallbackRef = useRef(onData);
|
|
2973
2968
|
const onValidCallbackRef = useRef(onValid);
|
|
2974
|
-
|
|
2969
|
+
const onSubmitCallbackRef = useRef(onSubmit);
|
|
2975
2970
|
useEffect(() => {
|
|
2976
2971
|
onDataCallbackRef.current = onData;
|
|
2977
2972
|
}, [onData]);
|
|
2978
2973
|
useEffect(() => {
|
|
2979
2974
|
onValidCallbackRef.current = onValid;
|
|
2980
2975
|
}, [onValid]);
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2976
|
+
useEffect(() => {
|
|
2977
|
+
onSubmitCallbackRef.current = onSubmit;
|
|
2978
|
+
}, [onSubmit]);
|
|
2984
2979
|
useEffect(() => {
|
|
2985
2980
|
const onDataCallback = payload => {
|
|
2986
2981
|
var _a;
|
|
@@ -3001,20 +2996,24 @@ const useFormGroup = ({
|
|
|
3001
2996
|
ids,
|
|
3002
2997
|
callback: onValidCallback
|
|
3003
2998
|
});
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
2999
|
+
const onSubmitCallback = payload => {
|
|
3000
|
+
var _a;
|
|
3001
|
+
if (onSubmitCallbackRef.current) {
|
|
3002
|
+
(_a = onSubmitCallbackRef.current) === null || _a === void 0 ? void 0 : _a.call(onSubmitCallbackRef, payload);
|
|
3003
|
+
}
|
|
3004
|
+
};
|
|
3005
|
+
const onSubmitSub = formGroupInstance.onSubmitSubscription({
|
|
3006
|
+
ids,
|
|
3007
|
+
callback: onSubmitCallback
|
|
3008
|
+
});
|
|
3011
3009
|
return () => {
|
|
3012
3010
|
onDataSub.unsubscribe();
|
|
3013
3011
|
onValidSub.unsubscribe();
|
|
3012
|
+
onSubmitSub.unsubscribe();
|
|
3014
3013
|
};
|
|
3015
3014
|
}, [deps]);
|
|
3016
3015
|
return;
|
|
3017
|
-
}
|
|
3016
|
+
}
|
|
3018
3017
|
|
|
3019
3018
|
const defaultChangeEvent = event => {
|
|
3020
3019
|
return event.currentTarget.value;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2-beta.10",
|
|
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.
|
|
9
|
+
"@bolttech/form-engine-core": "0.0.3-beta.9",
|
|
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, onValid, children, }: TFormProps<T>): ReactElement;
|
|
8
|
+
declare function Form<T>({ schema, index, initialValues, iVars, action, method, config, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, onValid, children, }: TFormProps<T>): ReactElement;
|
|
9
9
|
export default Form;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
onData?: ((payload: TFormGroupOnDataEventPayload<Record<string, unknown>>) => void) | undefined;
|
|
5
|
-
onValid?: ((payload: TFormGroupOnValidEventPayload) => void) | undefined;
|
|
6
|
-
}, deps?: React.DependencyList) => void;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TUseFormGroup } from './useFormGroup.type';
|
|
3
|
+
declare function useFormGroup<T>({ ids, onData, onValid, onSubmit }: TUseFormGroup<T>, deps?: React.DependencyList): void;
|
|
7
4
|
export default useFormGroup;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload } from '@bolttech/form-engine-core';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the properties for the useFormGroup hook, including a list of ID's and event callback properties.
|
|
4
|
+
*
|
|
5
|
+
* @property {string} ids - The unique identifier for the forms.
|
|
6
|
+
* @property {payload: TFormGroupOnDataEventPayload<T>} onData - callback event occurring when a value is changing via input or logic.
|
|
7
|
+
* @property {payload: TFormGroupOnValidEventPayload} onData - callback event occurring when validation status changes on the form.
|
|
8
|
+
* @property {payload: TFormGroupOnSubmitEventPayload<T>} onData - event occurring when form submission is trigger.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
type TUseFormGroup<T> = {
|
|
12
|
+
ids: string[];
|
|
13
|
+
onData?: (payload: TFormGroupOnDataEventPayload<T>) => void;
|
|
14
|
+
onValid?: (payload: TFormGroupOnValidEventPayload) => void;
|
|
15
|
+
onSubmit?: (payload: TFormGroupOnSubmitEventPayload<T>) => void;
|
|
16
|
+
};
|
|
17
|
+
export type { TUseFormGroup };
|