@bolttech/form-engine 3.1.2-beta.5 → 3.2.0-beta.0
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 +39 -29
- package/index.esm.js +60 -48
- package/package.json +3 -2
- package/src/components/AsFormField/AsFormField.type.d.ts +1 -1
- package/src/components/AsFormFieldBuilder/AsFormFieldBuilder.type.d.ts +1 -1
- package/src/components/Form/Form.d.ts +2 -2
- package/src/components/Form/Form.type.d.ts +2 -2
- package/src/context/FormGroupContext.type.d.ts +31 -1
- package/src/helpers/helpers.d.ts +1 -2
- package/src/hooks/useForm/useForm.d.ts +1 -1
- package/src/hooks/useForm/useForm.type.d.ts +8 -3
- package/src/types/index.d.ts +13 -13
package/README.md
CHANGED
|
@@ -422,33 +422,40 @@ After configuring the provider, `<Form />` components lets you render a form
|
|
|
422
422
|
|
|
423
423
|
### Props
|
|
424
424
|
|
|
425
|
-
| Prop | Type | Description
|
|
426
|
-
| ----------------------------------- | ---------------------------------------------------------------------------------- |
|
|
427
|
-
| [DEPRECIATED] disable | boolean | Disable all form inputs. It will use the default htm disable attribute
|
|
425
|
+
| Prop | Type | Description |
|
|
426
|
+
| ----------------------------------- | ---------------------------------------------------------------------------------- | ------------ |
|
|
427
|
+
| [DEPRECIATED] disable | boolean | Disable all form inputs. It will use the default htm disable attribute |
|
|
428
428
|
| [DEPRECIATED] group | string | Form group identifier. Used be able to group several forms and then get data with useGroupForm. One will be generated as default if omitted |
|
|
429
|
-
| index | string | Form identified. One will be generated as default if omitted
|
|
430
|
-
| [DEPRECIATED] hooks | THooks | Provide functions to run on certain life-cycle events
|
|
431
|
-
| iVars | Object | One object with internal variables to be used in form with data binding
|
|
432
|
-
| initialValues | Object | Object with form initial values that will map to a field.
|
|
433
|
-
| Schema | TSchema | Form Schema
|
|
434
|
-
| [DEPRECIATED] autoComplete | string | HTML autocomplete
|
|
435
|
-
| className | string | Allow to style form
|
|
436
|
-
| onSubmit | callback(TFormValues) | Will be called when there is a submit action in the form
|
|
437
|
-
| onData | callback(TFormData) | Will be called when any field data change. The arguments will let you know which field changed and the field configuration
|
|
438
|
-
| onBlur | callback(TFieldEvent) | Will be called when any field blured. The arguments will let you know which field blured and the field configuration
|
|
439
|
-
| onFocus | callback(TFieldEvent) | Will be called when any field focused change. The arguments will let you know which field focused and the field configuration
|
|
440
|
-
| onMount | callback(TFormValues,TComponent, TField) | Will be called when some field mounted. Its called with the field that information that mounted.
|
|
441
|
-
| [DEPRECIATED] onStep | callback(TFormValues) | Called when a form step changed
|
|
442
|
-
| [DEPRECIATED] onLog | callback(TLoggingEvent) | Called on each log, if the logging is enabled
|
|
443
|
-
| [DEPRECIATED] onScopeChange | onScopeChange?(scope: TScope, namespace: string, key: string): void; | Called everything scope change with the changing information (namespace and key) and the changed scope
|
|
444
|
-
| onClick | onClick(TFieldEvent) | Callback function that runs on each component click
|
|
445
|
-
| onApiResponse | onApiResponse(TFieldEvent) | Callback function that runs on each component after api call.
|
|
446
|
-
| [DEPRECIATED] onFieldRehydrate | onFieldRehydrate?(values: TFormValues, component: TComponent, field: TField): void | This callback is called whenever some form field was rehydrated
|
|
447
|
-
| [DEPRECIATED] renderLoading | renderLoading?(): ReactElement; | Component to render while the schema has not rendered
|
|
448
|
-
| [DEPRECIATED] onFormMount | onFormMount?(values: TFormValues): void; | Called when the form finished mounted
|
|
449
|
-
| [DEPRECIATED] formattedDataDefaults | Object | Some default data to fields when they are undefined
|
|
450
|
-
| [DEPRECIATED] submitOnValidOnly | boolean | Boolean indicating if form can be submitted even if it is invalid
|
|
451
|
-
| [DEPRECIATED] renderFieldWrapper | renderFieldWrapper(component: TComponent, children: ReactElement[]) | Function that allows to insert a wrapper in place of a component or wrapping the component
|
|
429
|
+
| index | string | Form identified. One will be generated as default if omitted |
|
|
430
|
+
| [DEPRECIATED] hooks | THooks | Provide functions to run on certain life-cycle events |
|
|
431
|
+
| iVars | Object | One object with internal variables to be used in form with data binding |
|
|
432
|
+
| initialValues | Object | Object with form initial values that will map to a field. |
|
|
433
|
+
| Schema | TSchema | Form Schema |
|
|
434
|
+
| [DEPRECIATED] autoComplete | string | HTML autocomplete |
|
|
435
|
+
| className | string | Allow to style form |
|
|
436
|
+
| onSubmit | callback(TFormValues) | Will be called when there is a submit action in the form |
|
|
437
|
+
| onData | callback(TFormData) | Will be called when any field data change. The arguments will let you know which field changed and the field configuration |
|
|
438
|
+
| onBlur | callback(TFieldEvent) | Will be called when any field blured. The arguments will let you know which field blured and the field configuration |
|
|
439
|
+
| onFocus | callback(TFieldEvent) | Will be called when any field focused change. The arguments will let you know which field focused and the field configuration |
|
|
440
|
+
| onMount | callback(TFormValues,TComponent, TField) | Will be called when some field mounted. Its called with the field that information that mounted. |
|
|
441
|
+
| [DEPRECIATED] onStep | callback(TFormValues) | Called when a form step changed |
|
|
442
|
+
| [DEPRECIATED] onLog | callback(TLoggingEvent) | Called on each log, if the logging is enabled |
|
|
443
|
+
| [DEPRECIATED] onScopeChange | onScopeChange?(scope: TScope, namespace: string, key: string): void; | Called everything scope change with the changing information (namespace and key) and the changed scope |
|
|
444
|
+
| onClick | onClick(TFieldEvent) | Callback function that runs on each component click |
|
|
445
|
+
| onApiResponse | onApiResponse(TFieldEvent) | Callback function that runs on each component after api call. |
|
|
446
|
+
| [DEPRECIATED] onFieldRehydrate | onFieldRehydrate?(values: TFormValues, component: TComponent, field: TField): void | This callback is called whenever some form field was rehydrated |
|
|
447
|
+
| [DEPRECIATED] renderLoading | renderLoading?(): ReactElement; | Component to render while the schema has not rendered |
|
|
448
|
+
| [DEPRECIATED] onFormMount | onFormMount?(values: TFormValues): void; | Called when the form finished mounted |
|
|
449
|
+
| [DEPRECIATED] formattedDataDefaults | Object | Some default data to fields when they are undefined |
|
|
450
|
+
| [DEPRECIATED] submitOnValidOnly | boolean | Boolean indicating if form can be submitted even if it is invalid |
|
|
451
|
+
| [DEPRECIATED] renderFieldWrapper | renderFieldWrapper(component: TComponent, children: ReactElement[]) | Function that allows to insert a wrapper in place of a component or wrapping the component |
|
|
452
|
+
| onApiRequest | onApiRequest(TFieldEvent) | Callback function that runs when an api call starts |
|
|
453
|
+
| onChange | onFieldChange(TFieldEvent) | Callback function that runs on each component value changes
|
|
454
|
+
| onKeyDown | onKeyDown(TFieldEvent) | Callback function that runs on each key down event |
|
|
455
|
+
| onKeyUp | onKeyUp(TFieldEvent) | Callback function that runs on each key up event |
|
|
456
|
+
| onCleared | onCleared(TFieldEvent) | Callback function that runs on a value that has been changed by resetValues event |
|
|
457
|
+
| onUnmount | onUnmount(TFieldEvent) | Callback function that runs when a field is unmounted or hidden by a visibility condition rule (use with caution) |
|
|
458
|
+
|
|
452
459
|
|
|
453
460
|
### Example
|
|
454
461
|
|
|
@@ -914,7 +921,7 @@ resetValues lets you change input values with the same rules as validations
|
|
|
914
921
|
| events | Partial<TEvents>[] | events that will trigger the validation |
|
|
915
922
|
| resettledValue | unknown[] or unknown | value or values to be set on the specified fields |
|
|
916
923
|
|
|
917
|
-
|
|
924
|
+
if the event occurs and all the validations returns `true` the resettled value will trigger and the `fields` specified will be filled with the `resettledValue` values, also, the event ON_FIELD_CLEARED is triggered on the fields that gets the resettled value instead of ON_FIELD_CHANGE.
|
|
918
925
|
|
|
919
926
|
### from v2 to v3
|
|
920
927
|
|
|
@@ -1134,9 +1141,12 @@ The avalialbe callback methods are:
|
|
|
1134
1141
|
| onFocus | TFieldEvent | same as above |
|
|
1135
1142
|
| onKeyDown | TFieldEvent | same as above |
|
|
1136
1143
|
| onKeyUp | TFieldEvent | same as above |
|
|
1137
|
-
| onMount | TFieldEvent | same as above |
|
|
1138
|
-
| onApiResponse | TFieldEvent | same as above |
|
|
1139
1144
|
| onClick | TFieldEvent | same as above |
|
|
1145
|
+
| onApiResponse | TFieldEvent | event occuring when a api response is ready |
|
|
1146
|
+
| onApiRequest | TFieldEvent | event occuring when a api resquest is started |
|
|
1147
|
+
| onMount | TFieldEvent | event occuring when a field is mounted or set visible |
|
|
1148
|
+
| onUnmount | TFieldEvent | event occuring when a field is unmounted or hidden |
|
|
1149
|
+
| onCleared | TFieldEvent | event occuring when the field value is set with resetValues |
|
|
1140
1150
|
| onFormMount | TFormValues<T> | event occuring on form mount |
|
|
1141
1151
|
| onData | TFormData<T> | event occuring when a value is changing via input or logic |
|
|
1142
1152
|
| onSubmit | TFormValues<T> | event occuring when pressing the submit button defined on the form |
|
package/index.esm.js
CHANGED
|
@@ -2111,7 +2111,8 @@ const eventsMapping = {
|
|
|
2111
2111
|
ON_API_FIELD_REQUEST: 'onApiRequest',
|
|
2112
2112
|
ON_API_FIELD_RESPONSE: 'onApiResponse',
|
|
2113
2113
|
ON_FIELD_CLICK: 'onClick',
|
|
2114
|
-
ON_FIELD_CLEARED: '
|
|
2114
|
+
ON_FIELD_CLEARED: 'onCleared',
|
|
2115
|
+
ON_FIELD_UNMOUNT: 'onUnmount'
|
|
2115
2116
|
};
|
|
2116
2117
|
const uniqueIdGen = () => {
|
|
2117
2118
|
const timestamp = +new Date();
|
|
@@ -2129,15 +2130,56 @@ const uniqueIdGen = () => {
|
|
|
2129
2130
|
function useForm(_a, deps) {
|
|
2130
2131
|
var {
|
|
2131
2132
|
id,
|
|
2133
|
+
index,
|
|
2132
2134
|
onData,
|
|
2133
2135
|
onSubmit,
|
|
2134
2136
|
onFormMount,
|
|
2135
|
-
onValid
|
|
2137
|
+
onValid,
|
|
2138
|
+
iVars,
|
|
2139
|
+
initialValues,
|
|
2140
|
+
stopEventsOnSubmit
|
|
2136
2141
|
} = _a,
|
|
2137
|
-
rest = __rest(_a, ["id", "onData", "onSubmit", "onFormMount", "onValid"]);
|
|
2142
|
+
rest = __rest(_a, ["id", "index", "onData", "onSubmit", "onFormMount", "onValid", "iVars", "initialValues", "stopEventsOnSubmit"]);
|
|
2138
2143
|
const {
|
|
2139
2144
|
formGroupInstance
|
|
2140
2145
|
} = useFormGroupContext({});
|
|
2146
|
+
const useFormIndex = index || id;
|
|
2147
|
+
if (!useFormIndex) {
|
|
2148
|
+
throw new Error('useForm hook must have an id or an index');
|
|
2149
|
+
}
|
|
2150
|
+
useEffect(() => {
|
|
2151
|
+
if (!formGroupInstance.forms.has(useFormIndex)) {
|
|
2152
|
+
console.log('failed to set stopEventsOnSubmit due to no form instance');
|
|
2153
|
+
return;
|
|
2154
|
+
}
|
|
2155
|
+
if (typeof stopEventsOnSubmit === 'boolean') {
|
|
2156
|
+
formGroupInstance.getForm({
|
|
2157
|
+
key: useFormIndex
|
|
2158
|
+
}).stopEventsOnSubmit = stopEventsOnSubmit;
|
|
2159
|
+
}
|
|
2160
|
+
}, []);
|
|
2161
|
+
/**
|
|
2162
|
+
* iVars change tracker to update iVars onto form instance
|
|
2163
|
+
*/
|
|
2164
|
+
useEffect(() => {
|
|
2165
|
+
if (!formGroupInstance.forms.has(useFormIndex)) {
|
|
2166
|
+
console.log('failed to add iVars due to no form instance');
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
if (iVars) formGroupInstance.forms.get(useFormIndex).iVars = iVars;
|
|
2170
|
+
// if (iVars) formInstance.current.iVars = iVars;
|
|
2171
|
+
}, [iVars]);
|
|
2172
|
+
/**
|
|
2173
|
+
* initialValues setter for async initialValues
|
|
2174
|
+
*/
|
|
2175
|
+
useEffect(() => {
|
|
2176
|
+
if (!formGroupInstance.forms.has(useFormIndex)) {
|
|
2177
|
+
console.log('failed to add initialValues due to no form instance');
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
if (initialValues) formGroupInstance.forms.get(useFormIndex).initialValues = initialValues;
|
|
2181
|
+
// if (initialValues) formInstance.current.initialValues = initialValues;
|
|
2182
|
+
}, [initialValues]);
|
|
2141
2183
|
/**
|
|
2142
2184
|
* reference to store all updated callback functions rerendered by props change
|
|
2143
2185
|
*/
|
|
@@ -2174,7 +2216,7 @@ function useForm(_a, deps) {
|
|
|
2174
2216
|
}
|
|
2175
2217
|
};
|
|
2176
2218
|
const sub = (_a = formGroupInstance.getForm({
|
|
2177
|
-
key:
|
|
2219
|
+
key: useFormIndex
|
|
2178
2220
|
})) === null || _a === void 0 ? void 0 : _a.subscribeFieldEvent({
|
|
2179
2221
|
callback
|
|
2180
2222
|
});
|
|
@@ -2185,7 +2227,7 @@ function useForm(_a, deps) {
|
|
|
2185
2227
|
}
|
|
2186
2228
|
};
|
|
2187
2229
|
const mountSub = (_b = formGroupInstance.getForm({
|
|
2188
|
-
key:
|
|
2230
|
+
key: useFormIndex
|
|
2189
2231
|
})) === null || _b === void 0 ? void 0 : _b.subscribeOnMount(mountCallback);
|
|
2190
2232
|
const dataCallback = payload => {
|
|
2191
2233
|
var _a, _b;
|
|
@@ -2194,7 +2236,7 @@ function useForm(_a, deps) {
|
|
|
2194
2236
|
}
|
|
2195
2237
|
};
|
|
2196
2238
|
const dataSub = (_c = formGroupInstance.getForm({
|
|
2197
|
-
key:
|
|
2239
|
+
key: useFormIndex
|
|
2198
2240
|
})) === null || _c === void 0 ? void 0 : _c.subscribeData(dataCallback);
|
|
2199
2241
|
const validationCallback = payload => {
|
|
2200
2242
|
if (formValuesCallbackRefs.current.onValid) {
|
|
@@ -2202,7 +2244,7 @@ function useForm(_a, deps) {
|
|
|
2202
2244
|
}
|
|
2203
2245
|
};
|
|
2204
2246
|
const validSub = (_d = formGroupInstance.getForm({
|
|
2205
|
-
key:
|
|
2247
|
+
key: useFormIndex
|
|
2206
2248
|
})) === null || _d === void 0 ? void 0 : _d.subscribeFormValidation(validationCallback);
|
|
2207
2249
|
const submitCallback = payload => {
|
|
2208
2250
|
var _a, _b;
|
|
@@ -2211,7 +2253,7 @@ function useForm(_a, deps) {
|
|
|
2211
2253
|
}
|
|
2212
2254
|
};
|
|
2213
2255
|
const submitSub = (_e = formGroupInstance.getForm({
|
|
2214
|
-
key:
|
|
2256
|
+
key: useFormIndex
|
|
2215
2257
|
})) === null || _e === void 0 ? void 0 : _e.subscribeOnSubmit(submitCallback);
|
|
2216
2258
|
return () => {
|
|
2217
2259
|
sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
@@ -2249,6 +2291,7 @@ function Form({
|
|
|
2249
2291
|
onKeyUp,
|
|
2250
2292
|
onMount,
|
|
2251
2293
|
onValid,
|
|
2294
|
+
stopEventsOnSubmit,
|
|
2252
2295
|
children
|
|
2253
2296
|
}) {
|
|
2254
2297
|
const {
|
|
@@ -2264,13 +2307,13 @@ function Form({
|
|
|
2264
2307
|
* effect to create the form instance and notify the recursive generated fields of it's mounted status
|
|
2265
2308
|
*/
|
|
2266
2309
|
useEffect(() => {
|
|
2267
|
-
if (mountedRef.current
|
|
2310
|
+
if (mountedRef.current || formGroupInstance.getForm({
|
|
2311
|
+
key: schemaIndex
|
|
2312
|
+
})) return;
|
|
2268
2313
|
formGroupInstance.addForm({
|
|
2269
2314
|
key: schemaIndex,
|
|
2270
2315
|
params: {
|
|
2271
2316
|
schema,
|
|
2272
|
-
initialValues: initialValues || (schema === null || schema === void 0 ? void 0 : schema.initialValues),
|
|
2273
|
-
iVars: iVars || (schema === null || schema === void 0 ? void 0 : schema.iVars),
|
|
2274
2317
|
action: action || (schema === null || schema === void 0 ? void 0 : schema.action),
|
|
2275
2318
|
method: method || (schema === null || schema === void 0 ? void 0 : schema.method),
|
|
2276
2319
|
index: schemaIndex,
|
|
@@ -2282,33 +2325,14 @@ function Form({
|
|
|
2282
2325
|
mountedRef.current = true;
|
|
2283
2326
|
// }
|
|
2284
2327
|
}, []);
|
|
2285
|
-
/**
|
|
2286
|
-
* iVars change tracker to update iVars onto form instance
|
|
2287
|
-
*/
|
|
2288
|
-
useEffect(() => {
|
|
2289
|
-
if (!formGroupInstance.forms.has(schemaIndex)) {
|
|
2290
|
-
console.log('failed to add iVars due to no form instance');
|
|
2291
|
-
return;
|
|
2292
|
-
}
|
|
2293
|
-
if (iVars && mounted) formGroupInstance.forms.get(schemaIndex).iVars = iVars;
|
|
2294
|
-
// if (iVars) formInstance.current.iVars = iVars;
|
|
2295
|
-
}, [iVars, mounted]);
|
|
2296
|
-
/**
|
|
2297
|
-
* initialValues setter for async initialValues
|
|
2298
|
-
*/
|
|
2299
|
-
useEffect(() => {
|
|
2300
|
-
if (!formGroupInstance.forms.has(schemaIndex)) {
|
|
2301
|
-
console.log('failed to add initialValues due to no form instance');
|
|
2302
|
-
return;
|
|
2303
|
-
}
|
|
2304
|
-
if (initialValues && mounted) formGroupInstance.forms.get(schemaIndex).initialValues = initialValues;
|
|
2305
|
-
// if (initialValues) formInstance.current.initialValues = initialValues;
|
|
2306
|
-
}, [initialValues, mounted]);
|
|
2307
2328
|
/**
|
|
2308
2329
|
* hook usage to keep event bindings updated on callback functions passed as props
|
|
2309
2330
|
*/
|
|
2310
2331
|
useForm({
|
|
2311
|
-
|
|
2332
|
+
index: schemaIndex,
|
|
2333
|
+
initialValues,
|
|
2334
|
+
iVars,
|
|
2335
|
+
stopEventsOnSubmit,
|
|
2312
2336
|
onApiResponse,
|
|
2313
2337
|
onBlur,
|
|
2314
2338
|
onChange,
|
|
@@ -2436,7 +2460,7 @@ const FieldWrapper = ({
|
|
|
2436
2460
|
visibility,
|
|
2437
2461
|
component
|
|
2438
2462
|
}) => {
|
|
2439
|
-
var _a, _b, _c
|
|
2463
|
+
var _a, _b, _c;
|
|
2440
2464
|
const localContext = useFormGroupContext({});
|
|
2441
2465
|
const fieldMapper = mapper || ((_a = localContext.mappers) === null || _a === void 0 ? void 0 : _a.find(mapper => mapper.componentName === component));
|
|
2442
2466
|
/**
|
|
@@ -2550,24 +2574,12 @@ const FieldWrapper = ({
|
|
|
2550
2574
|
margin: '0px'
|
|
2551
2575
|
},
|
|
2552
2576
|
children: ["name:", name]
|
|
2553
|
-
}), jsxs("b", {
|
|
2554
|
-
style: {
|
|
2555
|
-
padding: '0px',
|
|
2556
|
-
margin: '0px'
|
|
2557
|
-
},
|
|
2558
|
-
children: ["order:", (_c = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.originalSchema) === null || _c === void 0 ? void 0 : _c.order]
|
|
2559
|
-
}), jsxs("b", {
|
|
2560
|
-
style: {
|
|
2561
|
-
padding: '0px',
|
|
2562
|
-
margin: '0px'
|
|
2563
|
-
},
|
|
2564
|
-
children: ["path:", fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.path]
|
|
2565
2577
|
}), jsx("br", {}), jsx("hr", {})]
|
|
2566
2578
|
}), jsx(FieldWrapperComponentRender, {
|
|
2567
2579
|
props: Object.assign(Object.assign(Object.assign(Object.assign({}, mapProps), state.props), state.errors), valueState),
|
|
2568
2580
|
fieldInstance: fieldInstance,
|
|
2569
2581
|
mapper: fieldMapper,
|
|
2570
|
-
children: children ? children : ((
|
|
2582
|
+
children: children ? children : ((_c = state === null || state === void 0 ? void 0 : state.props) === null || _c === void 0 ? void 0 : _c.children) ? state === null || state === void 0 ? void 0 : state.props.children : null
|
|
2571
2583
|
})]
|
|
2572
2584
|
}) : jsx(Fragment, {});
|
|
2573
2585
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0-beta.0",
|
|
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": "1.0
|
|
9
|
+
"@bolttech/form-engine-core": "1.1.0-beta.0",
|
|
10
|
+
"@storybook/blocks": "7.6.20",
|
|
10
11
|
"react": "18.2.0"
|
|
11
12
|
},
|
|
12
13
|
"peerDependencies": {}
|
|
@@ -3,7 +3,7 @@ import { ElementType, PropsWithChildren } from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* AsFormField props, inherits all schema field implementation except the children
|
|
5
5
|
* property and has mappers property to pass a custom component, that will be a ReactNode
|
|
6
|
-
* @see {@link
|
|
6
|
+
* @see {@link IComponentSchemaAsFormField}
|
|
7
7
|
*/
|
|
8
8
|
type TAsFormFieldProps = PropsWithChildren<Omit<IComponentSchemaAsFormField<ElementType>, 'children'>>;
|
|
9
9
|
export type { TAsFormFieldProps };
|
|
@@ -12,9 +12,9 @@ import { OneOf } from '@bolttech/form-engine-core/src/types/utility';
|
|
|
12
12
|
* @see {@link TMapper}
|
|
13
13
|
* @see {@link IComponentSchema}
|
|
14
14
|
* @see {@link TFieldWrapper}
|
|
15
|
+
* @interface
|
|
15
16
|
*/
|
|
16
17
|
type TAsFormFieldBuilderProps = PropsWithChildren<Omit<IComponentSchema, 'component' | 'children' | 'name'> & Required<TFieldWrapper> & {
|
|
17
|
-
visibility?: boolean;
|
|
18
18
|
onSelected?: (data: TFieldEvent) => void;
|
|
19
19
|
formMounted?: boolean;
|
|
20
20
|
} & OneOf<{
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
1
|
+
import { PropsWithChildren, ReactElement } from 'react';
|
|
2
2
|
import { TFormProps } from './Form.type';
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
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, config, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, onValid, children, }: TFormProps<T
|
|
8
|
+
declare function Form<T>({ schema, index, initialValues, iVars, action, method, config, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, onValid, stopEventsOnSubmit, children, }: PropsWithChildren<TFormProps<T>>): ReactElement;
|
|
9
9
|
export default Form;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TFormEntry } from '@bolttech/form-engine-core';
|
|
2
|
-
import { PropsWithChildren } from 'react';
|
|
3
2
|
import { TEventsCallbackProps } from '../../types';
|
|
4
3
|
/**
|
|
5
4
|
* Form props, inherits the form instance constructor implementation except the mapper
|
|
6
5
|
* along with all event callback register props shared with other implementations
|
|
7
6
|
* @see {@link TFormEntry}
|
|
8
7
|
* @see {@link TEventsCallbackProps}
|
|
8
|
+
* @interface
|
|
9
9
|
*/
|
|
10
|
-
type TFormProps<T> =
|
|
10
|
+
type TFormProps<T> = Omit<TFormEntry, 'mappers' | 'dataSubject$' | 'formValidSubject$' | 'submitSubject$'> & TEventsCallbackProps<T>;
|
|
11
11
|
export type { TFormProps };
|
|
@@ -12,7 +12,27 @@ import { ElementType } from 'react';
|
|
|
12
12
|
* @property {function(): void} printFormGroupInstance - Prints the form group instance.
|
|
13
13
|
* @property {function(string[]): TFormValues} submitMultipleFormsByIndex - Submits multiple forms by their indexes and returns the form values.
|
|
14
14
|
* @property {boolean} debugMode - Indicates if debug mode is active.
|
|
15
|
-
* @property {boolean} active - Indicates if the form context is active.
|
|
15
|
+
* @property {boolean} active - Indicates if the form context is active (if the context provider is defined above).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import React from 'react';
|
|
20
|
+
* import { useFormGroupContext } from '@bolttech/form-engine';
|
|
21
|
+
*
|
|
22
|
+
* const FormComponent = (): React.ReactElement => {
|
|
23
|
+
* const {
|
|
24
|
+
* addForm,
|
|
25
|
+
* removeForm,
|
|
26
|
+
* getForm,
|
|
27
|
+
* printFormGroupInstance,
|
|
28
|
+
* submitMultipleFormsByIndex,
|
|
29
|
+
* debugMode
|
|
30
|
+
* } = useFormGroupContext();
|
|
31
|
+
*
|
|
32
|
+
* // (...)
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
16
36
|
*/
|
|
17
37
|
type TFormContext = {
|
|
18
38
|
addFormWithIndex: (index: string) => void;
|
|
@@ -39,6 +59,16 @@ type TFormContext = {
|
|
|
39
59
|
*
|
|
40
60
|
* @property {TMapper<ElementType>[]} [mappers] - Optional array of mappers for elements.
|
|
41
61
|
* @property {boolean} [debugMode] - Optional flag indicating if debug mode should be enabled.
|
|
62
|
+
* @property {TSchemaFormConfig} config - Optional config settings for debounce times and client logging
|
|
63
|
+
*
|
|
64
|
+
* * @example
|
|
65
|
+
* ```tsx
|
|
66
|
+
* import { FormGroupContextProvider } from '@bolttech/form-engine';
|
|
67
|
+
*
|
|
68
|
+
* <FormGroupContextProvider mappers={mappers} debugMode={true}>
|
|
69
|
+
* {children}
|
|
70
|
+
* </FormGroupContextProvider>
|
|
71
|
+
* ```
|
|
42
72
|
*/
|
|
43
73
|
type TFormContextProvider = {
|
|
44
74
|
mappers?: TMapper<ElementType>[];
|
package/src/helpers/helpers.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import { TUseFormProps } from './useForm.type';
|
|
|
3
3
|
/**
|
|
4
4
|
* Hook to register events callback functions
|
|
5
5
|
*/
|
|
6
|
-
declare function useForm<T>({ id, onData, onSubmit, onFormMount, onValid, ...rest }: TUseFormProps<T>, deps?: React.DependencyList): void;
|
|
6
|
+
declare function useForm<T>({ id, index, onData, onSubmit, onFormMount, onValid, iVars, initialValues, stopEventsOnSubmit, ...rest }: TUseFormProps<T>, deps?: React.DependencyList): void;
|
|
7
7
|
export default useForm;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import { TFormEntry } from '@bolttech/form-engine-core';
|
|
1
2
|
import { TEventsCallbackProps } from '../../types';
|
|
3
|
+
import { OneOf } from '@bolttech/form-engine-core/src/types/utility';
|
|
2
4
|
/**
|
|
3
5
|
* Represents the properties for the useForm hook, including an ID and event callback properties.
|
|
4
6
|
*
|
|
5
|
-
* @property {string} id - The unique identifier for the form.
|
|
7
|
+
* @property {string} id - The unique identifier for the form. Deprecated, use 'index' instead
|
|
8
|
+
* @property {string} index - The unique identifier for the form.
|
|
6
9
|
*
|
|
7
10
|
* @see {@link TEventsCallbackProps}
|
|
11
|
+
* @interface
|
|
8
12
|
*/
|
|
9
|
-
type TUseFormProps<T> = {
|
|
13
|
+
type TUseFormProps<T> = Pick<TFormEntry, 'index' | 'initialValues' | 'iVars' | 'stopEventsOnSubmit'> & TEventsCallbackProps<T> & OneOf<{
|
|
10
14
|
id: string;
|
|
11
|
-
|
|
15
|
+
index: string;
|
|
16
|
+
}>;
|
|
12
17
|
export type { TUseFormProps };
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TFieldEvent, TFormValidationPayload, TFormValues } from '@bolttech/form-engine-core';
|
|
1
|
+
import { TEventProps, TFieldEvent, TFormValidationPayload, TFormValues, TEventDataProps } 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
|
*
|
|
@@ -9,10 +9,6 @@ type TFieldWrapper = {
|
|
|
9
9
|
name: string;
|
|
10
10
|
formIndex: string;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
13
|
-
* Represents the possible event properties for form fields callbacks.
|
|
14
|
-
*/
|
|
15
|
-
type TEventProps = 'onChange' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'onMount' | 'onApiResponse' | 'onApiRequest' | 'onClick' | 'onFieldCleared';
|
|
16
12
|
/**
|
|
17
13
|
* Represents the content inside onData payload action.
|
|
18
14
|
*/
|
|
@@ -21,12 +17,16 @@ type TFormData<T> = {
|
|
|
21
17
|
data: TFormValues<T>;
|
|
22
18
|
};
|
|
23
19
|
/**
|
|
24
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* @property {(payload: TFormValues<T>) => void} onFormMount - triggered when form mounts
|
|
22
|
+
* @property {(payload: TFormValues<T>) => void} onData - triggered when any field change value
|
|
23
|
+
* @property {(payload: TFormValues<T>) => void} onSubmit - triggered when submit button is pressed
|
|
24
|
+
* @property {(payload: TFormValues<T>) => void} onValid - triggered when form valid status changes
|
|
25
|
+
* @interface
|
|
26
|
+
*
|
|
25
27
|
*/
|
|
26
|
-
type TEventsCallbackProps<T> = Partial<Record<TEventProps, ((payload: TFieldEvent) => void) | null | undefined>> & {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
export { TFieldWrapper, TEventProps, TEventsCallbackProps, TFormData };
|
|
28
|
+
type TEventsCallbackProps<T> = Partial<Record<TEventProps, ((payload: TFieldEvent) => void) | null | undefined>> & Partial<Record<Extract<TEventDataProps, 'onFormMount' | 'onSubmit'>, (payload: TFormValues<T>) => void>> & Partial<Record<Extract<TEventDataProps, 'onData'>, (payload: {
|
|
29
|
+
field: string;
|
|
30
|
+
data: TFormValues<T>;
|
|
31
|
+
}) => void>> & Partial<Record<Extract<TEventDataProps, 'onValid'>, (payload: TFormValidationPayload) => void>>;
|
|
32
|
+
export { TFieldWrapper, TEventsCallbackProps, TFormData };
|